OSDN Git Service

dab834154775a2114228f8a534c13b52ed311cbd
[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
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 loading integer registers */
996   2,                                    /* cost of moving MMX register */
997   {6, 6},                               /* cost of loading MMX registers
998                                            in SImode and DImode */
999   {4, 4},                               /* cost of storing MMX registers
1000                                            in SImode and DImode */
1001   2,                                    /* cost of moving SSE register */
1002   {6, 6, 6},                            /* cost of loading SSE registers
1003                                            in SImode, DImode and TImode */
1004   {4, 4, 4},                            /* cost of storing SSE registers
1005                                            in SImode, DImode and TImode */
1006   2,                                    /* MMX or SSE register to integer */
1007   32,                                   /* size of l1 cache.  */
1008   2048,                                 /* size of l2 cache.  */
1009   128,                                  /* size of prefetch block */
1010   8,                                    /* number of parallel prefetches */
1011   3,                                    /* Branch cost */
1012   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
1013   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
1014   COSTS_N_INSNS (32),                   /* cost of FDIV instruction.  */
1015   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
1016   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
1017   COSTS_N_INSNS (58),                   /* cost of FSQRT instruction.  */
1018   {{libcall, {{11, loop}, {-1, rep_prefix_4_byte}}},
1019    {libcall, {{32, loop}, {64, rep_prefix_4_byte},
1020               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1021   {{libcall, {{8, loop}, {15, unrolled_loop},
1022               {2048, rep_prefix_4_byte}, {-1, libcall}}},
1023    {libcall, {{24, loop}, {32, unrolled_loop},
1024               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1025   1,                                    /* scalar_stmt_cost.  */
1026   1,                                    /* scalar load_cost.  */
1027   1,                                    /* scalar_store_cost.  */
1028   1,                                    /* vec_stmt_cost.  */
1029   1,                                    /* vec_to_scalar_cost.  */
1030   1,                                    /* scalar_to_vec_cost.  */
1031   1,                                    /* vec_align_load_cost.  */
1032   2,                                    /* vec_unalign_load_cost.  */
1033   1,                                    /* vec_store_cost.  */
1034   3,                                    /* cond_taken_branch_cost.  */
1035   1,                                    /* cond_not_taken_branch_cost.  */
1036 };
1037
1038 /* Generic64 should produce code tuned for Nocona and K8.  */
1039 static const
1040 struct processor_costs generic64_cost = {
1041   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1042   /* On all chips taken into consideration lea is 2 cycles and more.  With
1043      this cost however our current implementation of synth_mult results in
1044      use of unnecessary temporary registers causing regression on several
1045      SPECfp benchmarks.  */
1046   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1047   COSTS_N_INSNS (1),                    /* variable shift costs */
1048   COSTS_N_INSNS (1),                    /* constant shift costs */
1049   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1050    COSTS_N_INSNS (4),                   /*                               HI */
1051    COSTS_N_INSNS (3),                   /*                               SI */
1052    COSTS_N_INSNS (4),                   /*                               DI */
1053    COSTS_N_INSNS (2)},                  /*                               other */
1054   0,                                    /* cost of multiply per each bit set */
1055   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1056    COSTS_N_INSNS (26),                  /*                          HI */
1057    COSTS_N_INSNS (42),                  /*                          SI */
1058    COSTS_N_INSNS (74),                  /*                          DI */
1059    COSTS_N_INSNS (74)},                 /*                          other */
1060   COSTS_N_INSNS (1),                    /* cost of movsx */
1061   COSTS_N_INSNS (1),                    /* cost of movzx */
1062   8,                                    /* "large" insn */
1063   17,                                   /* MOVE_RATIO */
1064   4,                                    /* cost for loading QImode using movzbl */
1065   {4, 4, 4},                            /* cost of loading integer registers
1066                                            in QImode, HImode and SImode.
1067                                            Relative to reg-reg move (2).  */
1068   {4, 4, 4},                            /* cost of storing integer registers */
1069   4,                                    /* cost of reg,reg fld/fst */
1070   {12, 12, 12},                         /* cost of loading fp registers
1071                                            in SFmode, DFmode and XFmode */
1072   {6, 6, 8},                            /* cost of storing fp registers
1073                                            in SFmode, DFmode and XFmode */
1074   2,                                    /* cost of moving MMX register */
1075   {8, 8},                               /* cost of loading MMX registers
1076                                            in SImode and DImode */
1077   {8, 8},                               /* cost of storing MMX registers
1078                                            in SImode and DImode */
1079   2,                                    /* cost of moving SSE register */
1080   {8, 8, 8},                            /* cost of loading SSE registers
1081                                            in SImode, DImode and TImode */
1082   {8, 8, 8},                            /* cost of storing SSE registers
1083                                            in SImode, DImode and TImode */
1084   5,                                    /* MMX or SSE register to integer */
1085   32,                                   /* size of l1 cache.  */
1086   512,                                  /* size of l2 cache.  */
1087   64,                                   /* size of prefetch block */
1088   6,                                    /* number of parallel prefetches */
1089   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this value
1090      is increased to perhaps more appropriate value of 5.  */
1091   3,                                    /* Branch cost */
1092   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1093   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1094   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1095   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1096   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1097   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1098   {DUMMY_STRINGOP_ALGS,
1099    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1100   {DUMMY_STRINGOP_ALGS,
1101    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1102   1,                                    /* scalar_stmt_cost.  */
1103   1,                                    /* scalar load_cost.  */
1104   1,                                    /* scalar_store_cost.  */
1105   1,                                    /* vec_stmt_cost.  */
1106   1,                                    /* vec_to_scalar_cost.  */
1107   1,                                    /* scalar_to_vec_cost.  */
1108   1,                                    /* vec_align_load_cost.  */
1109   2,                                    /* vec_unalign_load_cost.  */
1110   1,                                    /* vec_store_cost.  */
1111   3,                                    /* cond_taken_branch_cost.  */
1112   1,                                    /* cond_not_taken_branch_cost.  */
1113 };
1114
1115 /* Generic32 should produce code tuned for Athlon, PPro, Pentium4, Nocona and K8.  */
1116 static const
1117 struct processor_costs generic32_cost = {
1118   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1119   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1120   COSTS_N_INSNS (1),                    /* variable shift costs */
1121   COSTS_N_INSNS (1),                    /* constant shift costs */
1122   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1123    COSTS_N_INSNS (4),                   /*                               HI */
1124    COSTS_N_INSNS (3),                   /*                               SI */
1125    COSTS_N_INSNS (4),                   /*                               DI */
1126    COSTS_N_INSNS (2)},                  /*                               other */
1127   0,                                    /* cost of multiply per each bit set */
1128   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1129    COSTS_N_INSNS (26),                  /*                          HI */
1130    COSTS_N_INSNS (42),                  /*                          SI */
1131    COSTS_N_INSNS (74),                  /*                          DI */
1132    COSTS_N_INSNS (74)},                 /*                          other */
1133   COSTS_N_INSNS (1),                    /* cost of movsx */
1134   COSTS_N_INSNS (1),                    /* cost of movzx */
1135   8,                                    /* "large" insn */
1136   17,                                   /* MOVE_RATIO */
1137   4,                                    /* cost for loading QImode using movzbl */
1138   {4, 4, 4},                            /* cost of loading integer registers
1139                                            in QImode, HImode and SImode.
1140                                            Relative to reg-reg move (2).  */
1141   {4, 4, 4},                            /* cost of storing integer registers */
1142   4,                                    /* cost of reg,reg fld/fst */
1143   {12, 12, 12},                         /* cost of loading fp registers
1144                                            in SFmode, DFmode and XFmode */
1145   {6, 6, 8},                            /* cost of storing fp registers
1146                                            in SFmode, DFmode and XFmode */
1147   2,                                    /* cost of moving MMX register */
1148   {8, 8},                               /* cost of loading MMX registers
1149                                            in SImode and DImode */
1150   {8, 8},                               /* cost of storing MMX registers
1151                                            in SImode and DImode */
1152   2,                                    /* cost of moving SSE register */
1153   {8, 8, 8},                            /* cost of loading SSE registers
1154                                            in SImode, DImode and TImode */
1155   {8, 8, 8},                            /* cost of storing SSE registers
1156                                            in SImode, DImode and TImode */
1157   5,                                    /* MMX or SSE register to integer */
1158   32,                                   /* size of l1 cache.  */
1159   256,                                  /* size of l2 cache.  */
1160   64,                                   /* size of prefetch block */
1161   6,                                    /* number of parallel prefetches */
1162   3,                                    /* Branch cost */
1163   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1164   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1165   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1166   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1167   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1168   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1169   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1170    DUMMY_STRINGOP_ALGS},
1171   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1172    DUMMY_STRINGOP_ALGS},
1173   1,                                    /* scalar_stmt_cost.  */
1174   1,                                    /* scalar load_cost.  */
1175   1,                                    /* scalar_store_cost.  */
1176   1,                                    /* vec_stmt_cost.  */
1177   1,                                    /* vec_to_scalar_cost.  */
1178   1,                                    /* scalar_to_vec_cost.  */
1179   1,                                    /* vec_align_load_cost.  */
1180   2,                                    /* vec_unalign_load_cost.  */
1181   1,                                    /* vec_store_cost.  */
1182   3,                                    /* cond_taken_branch_cost.  */
1183   1,                                    /* cond_not_taken_branch_cost.  */
1184 };
1185
1186 const struct processor_costs *ix86_cost = &pentium_cost;
1187
1188 /* Processor feature/optimization bitmasks.  */
1189 #define m_386 (1<<PROCESSOR_I386)
1190 #define m_486 (1<<PROCESSOR_I486)
1191 #define m_PENT (1<<PROCESSOR_PENTIUM)
1192 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
1193 #define m_PENT4  (1<<PROCESSOR_PENTIUM4)
1194 #define m_NOCONA  (1<<PROCESSOR_NOCONA)
1195 #define m_CORE2  (1<<PROCESSOR_CORE2)
1196
1197 #define m_GEODE  (1<<PROCESSOR_GEODE)
1198 #define m_K6  (1<<PROCESSOR_K6)
1199 #define m_K6_GEODE  (m_K6 | m_GEODE)
1200 #define m_K8  (1<<PROCESSOR_K8)
1201 #define m_ATHLON  (1<<PROCESSOR_ATHLON)
1202 #define m_ATHLON_K8  (m_K8 | m_ATHLON)
1203 #define m_AMDFAM10  (1<<PROCESSOR_AMDFAM10)
1204 #define m_AMD_MULTIPLE  (m_K8 | m_ATHLON | m_AMDFAM10)
1205
1206 #define m_GENERIC32 (1<<PROCESSOR_GENERIC32)
1207 #define m_GENERIC64 (1<<PROCESSOR_GENERIC64)
1208
1209 /* Generic instruction choice should be common subset of supported CPUs
1210    (PPro/PENT4/NOCONA/CORE2/Athlon/K8).  */
1211 #define m_GENERIC (m_GENERIC32 | m_GENERIC64)
1212
1213 /* Feature tests against the various tunings.  */
1214 unsigned char ix86_tune_features[X86_TUNE_LAST];
1215
1216 /* Feature tests against the various tunings used to create ix86_tune_features
1217    based on the processor mask.  */
1218 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
1219   /* X86_TUNE_USE_LEAVE: Leave does not affect Nocona SPEC2000 results
1220      negatively, so enabling for Generic64 seems like good code size
1221      tradeoff.  We can't enable it for 32bit generic because it does not
1222      work well with PPro base chips.  */
1223   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_CORE2 | m_GENERIC64,
1224
1225   /* X86_TUNE_PUSH_MEMORY */
1226   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4
1227   | m_NOCONA | m_CORE2 | m_GENERIC,
1228
1229   /* X86_TUNE_ZERO_EXTEND_WITH_AND */
1230   m_486 | m_PENT,
1231
1232   /* X86_TUNE_USE_BIT_TEST */
1233   m_386,
1234
1235   /* X86_TUNE_UNROLL_STRLEN */
1236   m_486 | m_PENT | m_PPRO | m_AMD_MULTIPLE | m_K6 | m_CORE2 | m_GENERIC,
1237
1238   /* X86_TUNE_DEEP_BRANCH_PREDICTION */
1239   m_PPRO | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4 | m_GENERIC,
1240
1241   /* X86_TUNE_BRANCH_PREDICTION_HINTS: Branch hints were put in P4 based
1242      on simulation result. But after P4 was made, no performance benefit
1243      was observed with branch hints.  It also increases the code size.
1244      As a result, icc never generates branch hints.  */
1245   0,
1246
1247   /* X86_TUNE_DOUBLE_WITH_ADD */
1248   ~m_386,
1249
1250   /* X86_TUNE_USE_SAHF */
1251   m_PPRO | m_K6_GEODE | m_K8 | m_AMDFAM10 | m_PENT4
1252   | m_NOCONA | m_CORE2 | m_GENERIC,
1253
1254   /* X86_TUNE_MOVX: Enable to zero extend integer registers to avoid
1255      partial dependencies.  */
1256   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA
1257   | m_CORE2 | m_GENERIC | m_GEODE /* m_386 | m_K6 */,
1258
1259   /* X86_TUNE_PARTIAL_REG_STALL: We probably ought to watch for partial
1260      register stalls on Generic32 compilation setting as well.  However
1261      in current implementation the partial register stalls are not eliminated
1262      very well - they can be introduced via subregs synthesized by combine
1263      and can happen in caller/callee saving sequences.  Because this option
1264      pays back little on PPro based chips and is in conflict with partial reg
1265      dependencies used by Athlon/P4 based chips, it is better to leave it off
1266      for generic32 for now.  */
1267   m_PPRO,
1268
1269   /* X86_TUNE_PARTIAL_FLAG_REG_STALL */
1270   m_CORE2 | m_GENERIC,
1271
1272   /* X86_TUNE_USE_HIMODE_FIOP */
1273   m_386 | m_486 | m_K6_GEODE,
1274
1275   /* X86_TUNE_USE_SIMODE_FIOP */
1276   ~(m_PPRO | m_AMD_MULTIPLE | m_PENT | m_CORE2 | m_GENERIC),
1277
1278   /* X86_TUNE_USE_MOV0 */
1279   m_K6,
1280
1281   /* X86_TUNE_USE_CLTD */
1282   ~(m_PENT | m_K6 | m_CORE2 | m_GENERIC),
1283
1284   /* X86_TUNE_USE_XCHGB: Use xchgb %rh,%rl instead of rolw/rorw $8,rx.  */
1285   m_PENT4,
1286
1287   /* X86_TUNE_SPLIT_LONG_MOVES */
1288   m_PPRO,
1289
1290   /* X86_TUNE_READ_MODIFY_WRITE */
1291   ~m_PENT,
1292
1293   /* X86_TUNE_READ_MODIFY */
1294   ~(m_PENT | m_PPRO),
1295
1296   /* X86_TUNE_PROMOTE_QIMODE */
1297   m_K6_GEODE | m_PENT | m_386 | m_486 | m_AMD_MULTIPLE | m_CORE2
1298   | m_GENERIC /* | m_PENT4 ? */,
1299
1300   /* X86_TUNE_FAST_PREFIX */
1301   ~(m_PENT | m_486 | m_386),
1302
1303   /* X86_TUNE_SINGLE_STRINGOP */
1304   m_386 | m_PENT4 | m_NOCONA,
1305
1306   /* X86_TUNE_QIMODE_MATH */
1307   ~0,
1308
1309   /* X86_TUNE_HIMODE_MATH: On PPro this flag is meant to avoid partial
1310      register stalls.  Just like X86_TUNE_PARTIAL_REG_STALL this option
1311      might be considered for Generic32 if our scheme for avoiding partial
1312      stalls was more effective.  */
1313   ~m_PPRO,
1314
1315   /* X86_TUNE_PROMOTE_QI_REGS */
1316   0,
1317
1318   /* X86_TUNE_PROMOTE_HI_REGS */
1319   m_PPRO,
1320
1321   /* X86_TUNE_ADD_ESP_4: Enable if add/sub is preferred over 1/2 push/pop.  */
1322   m_AMD_MULTIPLE | m_K6_GEODE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1323
1324   /* X86_TUNE_ADD_ESP_8 */
1325   m_AMD_MULTIPLE | m_PPRO | m_K6_GEODE | m_386
1326   | m_486 | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1327
1328   /* X86_TUNE_SUB_ESP_4 */
1329   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1330
1331   /* X86_TUNE_SUB_ESP_8 */
1332   m_AMD_MULTIPLE | m_PPRO | m_386 | m_486
1333   | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1334
1335   /* X86_TUNE_INTEGER_DFMODE_MOVES: Enable if integer moves are preferred
1336      for DFmode copies */
1337   ~(m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2
1338     | m_GENERIC | m_GEODE),
1339
1340   /* X86_TUNE_PARTIAL_REG_DEPENDENCY */
1341   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1342
1343   /* X86_TUNE_SSE_PARTIAL_REG_DEPENDENCY: In the Generic model we have a
1344      conflict here in between PPro/Pentium4 based chips that thread 128bit
1345      SSE registers as single units versus K8 based chips that divide SSE
1346      registers to two 64bit halves.  This knob promotes all store destinations
1347      to be 128bit to allow register renaming on 128bit SSE units, but usually
1348      results in one extra microop on 64bit SSE units.  Experimental results
1349      shows that disabling this option on P4 brings over 20% SPECfp regression,
1350      while enabling it on K8 brings roughly 2.4% regression that can be partly
1351      masked by careful scheduling of moves.  */
1352   m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC | m_AMDFAM10,
1353
1354   /* X86_TUNE_SSE_UNALIGNED_MOVE_OPTIMAL */
1355   m_AMDFAM10,
1356
1357   /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
1358      are resolved on SSE register parts instead of whole registers, so we may
1359      maintain just lower part of scalar values in proper format leaving the
1360      upper part undefined.  */
1361   m_ATHLON_K8,
1362
1363   /* X86_TUNE_SSE_TYPELESS_STORES */
1364   m_AMD_MULTIPLE,
1365
1366   /* X86_TUNE_SSE_LOAD0_BY_PXOR */
1367   m_PPRO | m_PENT4 | m_NOCONA,
1368
1369   /* X86_TUNE_MEMORY_MISMATCH_STALL */
1370   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1371
1372   /* X86_TUNE_PROLOGUE_USING_MOVE */
1373   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1374
1375   /* X86_TUNE_EPILOGUE_USING_MOVE */
1376   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1377
1378   /* X86_TUNE_SHIFT1 */
1379   ~m_486,
1380
1381   /* X86_TUNE_USE_FFREEP */
1382   m_AMD_MULTIPLE,
1383
1384   /* X86_TUNE_INTER_UNIT_MOVES */
1385   ~(m_AMD_MULTIPLE | m_GENERIC),
1386
1387   /* X86_TUNE_INTER_UNIT_CONVERSIONS */
1388   ~(m_AMDFAM10),
1389
1390   /* X86_TUNE_FOUR_JUMP_LIMIT: Some CPU cores are not able to predict more
1391      than 4 branch instructions in the 16 byte window.  */
1392   m_PPRO | m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1393
1394   /* X86_TUNE_SCHEDULE */
1395   m_PPRO | m_AMD_MULTIPLE | m_K6_GEODE | m_PENT | m_CORE2 | m_GENERIC,
1396
1397   /* X86_TUNE_USE_BT */
1398   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1399
1400   /* X86_TUNE_USE_INCDEC */
1401   ~(m_PENT4 | m_NOCONA | m_GENERIC),
1402
1403   /* X86_TUNE_PAD_RETURNS */
1404   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1405
1406   /* X86_TUNE_EXT_80387_CONSTANTS */
1407   m_K6_GEODE | m_ATHLON_K8 | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC,
1408
1409   /* X86_TUNE_SHORTEN_X87_SSE */
1410   ~m_K8,
1411
1412   /* X86_TUNE_AVOID_VECTOR_DECODE */
1413   m_K8 | m_GENERIC64,
1414
1415   /* X86_TUNE_PROMOTE_HIMODE_IMUL: Modern CPUs have same latency for HImode
1416      and SImode multiply, but 386 and 486 do HImode multiply faster.  */
1417   ~(m_386 | m_486),
1418
1419   /* X86_TUNE_SLOW_IMUL_IMM32_MEM: Imul of 32-bit constant and memory is
1420      vector path on AMD machines.  */
1421   m_K8 | m_GENERIC64 | m_AMDFAM10,
1422
1423   /* X86_TUNE_SLOW_IMUL_IMM8: Imul of 8-bit constant is vector path on AMD
1424      machines.  */
1425   m_K8 | m_GENERIC64 | m_AMDFAM10,
1426
1427   /* X86_TUNE_MOVE_M1_VIA_OR: On pentiums, it is faster to load -1 via OR
1428      than a MOV.  */
1429   m_PENT,
1430
1431   /* X86_TUNE_NOT_UNPAIRABLE: NOT is not pairable on Pentium, while XOR is,
1432      but one byte longer.  */
1433   m_PENT,
1434
1435   /* X86_TUNE_NOT_VECTORMODE: On AMD K6, NOT is vector decoded with memory
1436      operand that cannot be represented using a modRM byte.  The XOR
1437      replacement is long decoded, so this split helps here as well.  */
1438   m_K6,
1439
1440   /* X86_TUNE_USE_VECTOR_CONVERTS: Prefer vector packed SSE conversion
1441      from integer to FP. */
1442   m_AMDFAM10,
1443
1444   /* X86_TUNE_FUSE_CMP_AND_BRANCH: Fuse a compare or test instruction
1445      with a subsequent conditional jump instruction into a single
1446      compare-and-branch uop.  */
1447   m_CORE2,
1448 };
1449
1450 /* Feature tests against the various architecture variations.  */
1451 unsigned char ix86_arch_features[X86_ARCH_LAST];
1452
1453 /* Feature tests against the various architecture variations, used to create
1454    ix86_arch_features based on the processor mask.  */
1455 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
1456   /* X86_ARCH_CMOVE: Conditional move was added for pentiumpro.  */
1457   ~(m_386 | m_486 | m_PENT | m_K6),
1458
1459   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
1460   ~m_386,
1461
1462   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
1463   ~(m_386 | m_486),
1464
1465   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
1466   ~m_386,
1467
1468   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
1469   ~m_386,
1470 };
1471
1472 static const unsigned int x86_accumulate_outgoing_args
1473   = m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC;
1474
1475 static const unsigned int x86_arch_always_fancy_math_387
1476   = m_PENT | m_PPRO | m_AMD_MULTIPLE | m_PENT4
1477     | m_NOCONA | m_CORE2 | m_GENERIC;
1478
1479 static enum stringop_alg stringop_alg = no_stringop;
1480
1481 /* In case the average insn count for single function invocation is
1482    lower than this constant, emit fast (but longer) prologue and
1483    epilogue code.  */
1484 #define FAST_PROLOGUE_INSN_COUNT 20
1485
1486 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
1487 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
1488 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
1489 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
1490
1491 /* Array of the smallest class containing reg number REGNO, indexed by
1492    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
1493
1494 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
1495 {
1496   /* ax, dx, cx, bx */
1497   AREG, DREG, CREG, BREG,
1498   /* si, di, bp, sp */
1499   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
1500   /* FP registers */
1501   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
1502   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
1503   /* arg pointer */
1504   NON_Q_REGS,
1505   /* flags, fpsr, fpcr, frame */
1506   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
1507   /* SSE registers */
1508   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1509   SSE_REGS, SSE_REGS,
1510   /* MMX registers */
1511   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
1512   MMX_REGS, MMX_REGS,
1513   /* REX registers */
1514   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1515   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1516   /* SSE REX registers */
1517   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1518   SSE_REGS, SSE_REGS,
1519 };
1520
1521 /* The "default" register map used in 32bit mode.  */
1522
1523 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
1524 {
1525   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
1526   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
1527   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1528   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
1529   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
1530   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1531   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1532 };
1533
1534 static int const x86_64_int_parameter_registers[6] =
1535 {
1536   5 /*RDI*/, 4 /*RSI*/, 1 /*RDX*/, 2 /*RCX*/,
1537   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1538 };
1539
1540 static int const x86_64_ms_abi_int_parameter_registers[4] =
1541 {
1542   2 /*RCX*/, 1 /*RDX*/,
1543   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1544 };
1545
1546 static int const x86_64_int_return_registers[4] =
1547 {
1548   0 /*RAX*/, 1 /*RDX*/, 5 /*RDI*/, 4 /*RSI*/
1549 };
1550
1551 /* The "default" register map used in 64bit mode.  */
1552 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
1553 {
1554   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
1555   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
1556   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1557   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
1558   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
1559   8,9,10,11,12,13,14,15,                /* extended integer registers */
1560   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
1561 };
1562
1563 /* Define the register numbers to be used in Dwarf debugging information.
1564    The SVR4 reference port C compiler uses the following register numbers
1565    in its Dwarf output code:
1566         0 for %eax (gcc regno = 0)
1567         1 for %ecx (gcc regno = 2)
1568         2 for %edx (gcc regno = 1)
1569         3 for %ebx (gcc regno = 3)
1570         4 for %esp (gcc regno = 7)
1571         5 for %ebp (gcc regno = 6)
1572         6 for %esi (gcc regno = 4)
1573         7 for %edi (gcc regno = 5)
1574    The following three DWARF register numbers are never generated by
1575    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
1576    believes these numbers have these meanings.
1577         8  for %eip    (no gcc equivalent)
1578         9  for %eflags (gcc regno = 17)
1579         10 for %trapno (no gcc equivalent)
1580    It is not at all clear how we should number the FP stack registers
1581    for the x86 architecture.  If the version of SDB on x86/svr4 were
1582    a bit less brain dead with respect to floating-point then we would
1583    have a precedent to follow with respect to DWARF register numbers
1584    for x86 FP registers, but the SDB on x86/svr4 is so completely
1585    broken with respect to FP registers that it is hardly worth thinking
1586    of it as something to strive for compatibility with.
1587    The version of x86/svr4 SDB I have at the moment does (partially)
1588    seem to believe that DWARF register number 11 is associated with
1589    the x86 register %st(0), but that's about all.  Higher DWARF
1590    register numbers don't seem to be associated with anything in
1591    particular, and even for DWARF regno 11, SDB only seems to under-
1592    stand that it should say that a variable lives in %st(0) (when
1593    asked via an `=' command) if we said it was in DWARF regno 11,
1594    but SDB still prints garbage when asked for the value of the
1595    variable in question (via a `/' command).
1596    (Also note that the labels SDB prints for various FP stack regs
1597    when doing an `x' command are all wrong.)
1598    Note that these problems generally don't affect the native SVR4
1599    C compiler because it doesn't allow the use of -O with -g and
1600    because when it is *not* optimizing, it allocates a memory
1601    location for each floating-point variable, and the memory
1602    location is what gets described in the DWARF AT_location
1603    attribute for the variable in question.
1604    Regardless of the severe mental illness of the x86/svr4 SDB, we
1605    do something sensible here and we use the following DWARF
1606    register numbers.  Note that these are all stack-top-relative
1607    numbers.
1608         11 for %st(0) (gcc regno = 8)
1609         12 for %st(1) (gcc regno = 9)
1610         13 for %st(2) (gcc regno = 10)
1611         14 for %st(3) (gcc regno = 11)
1612         15 for %st(4) (gcc regno = 12)
1613         16 for %st(5) (gcc regno = 13)
1614         17 for %st(6) (gcc regno = 14)
1615         18 for %st(7) (gcc regno = 15)
1616 */
1617 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
1618 {
1619   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
1620   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
1621   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
1622   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
1623   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
1624   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1625   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1626 };
1627
1628 /* Test and compare insns in i386.md store the information needed to
1629    generate branch and scc insns here.  */
1630
1631 rtx ix86_compare_op0 = NULL_RTX;
1632 rtx ix86_compare_op1 = NULL_RTX;
1633 rtx ix86_compare_emitted = NULL_RTX;
1634
1635 /* Define the structure for the machine field in struct function.  */
1636
1637 struct stack_local_entry GTY(())
1638 {
1639   unsigned short mode;
1640   unsigned short n;
1641   rtx rtl;
1642   struct stack_local_entry *next;
1643 };
1644
1645 /* Structure describing stack frame layout.
1646    Stack grows downward:
1647
1648    [arguments]
1649                                               <- ARG_POINTER
1650    saved pc
1651
1652    saved frame pointer if frame_pointer_needed
1653                                               <- HARD_FRAME_POINTER
1654    [saved regs]
1655
1656    [padding1]          \
1657                         )
1658    [va_arg registers]  (
1659                         > to_allocate         <- FRAME_POINTER
1660    [frame]             (
1661                         )
1662    [padding2]          /
1663   */
1664 struct ix86_frame
1665 {
1666   int nregs;
1667   int padding1;
1668   int va_arg_size;
1669   HOST_WIDE_INT frame;
1670   int padding2;
1671   int outgoing_arguments_size;
1672   int red_zone_size;
1673
1674   HOST_WIDE_INT to_allocate;
1675   /* The offsets relative to ARG_POINTER.  */
1676   HOST_WIDE_INT frame_pointer_offset;
1677   HOST_WIDE_INT hard_frame_pointer_offset;
1678   HOST_WIDE_INT stack_pointer_offset;
1679
1680   /* When save_regs_using_mov is set, emit prologue using
1681      move instead of push instructions.  */
1682   bool save_regs_using_mov;
1683 };
1684
1685 /* Code model option.  */
1686 enum cmodel ix86_cmodel;
1687 /* Asm dialect.  */
1688 enum asm_dialect ix86_asm_dialect = ASM_ATT;
1689 /* TLS dialects.  */
1690 enum tls_dialect ix86_tls_dialect = TLS_DIALECT_GNU;
1691
1692 /* Which unit we are generating floating point math for.  */
1693 enum fpmath_unit ix86_fpmath;
1694
1695 /* Which cpu are we scheduling for.  */
1696 enum processor_type ix86_tune;
1697
1698 /* Which instruction set architecture to use.  */
1699 enum processor_type ix86_arch;
1700
1701 /* true if sse prefetch instruction is not NOOP.  */
1702 int x86_prefetch_sse;
1703
1704 /* ix86_regparm_string as a number */
1705 static int ix86_regparm;
1706
1707 /* -mstackrealign option */
1708 extern int ix86_force_align_arg_pointer;
1709 static const char ix86_force_align_arg_pointer_string[]
1710   = "force_align_arg_pointer";
1711
1712 static rtx (*ix86_gen_leave) (void);
1713 static rtx (*ix86_gen_pop1) (rtx);
1714 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
1715 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
1716 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx);
1717 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
1718 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
1719 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
1720
1721 /* Preferred alignment for stack boundary in bits.  */
1722 unsigned int ix86_preferred_stack_boundary;
1723
1724 /* Alignment for incoming stack boundary in bits specified at
1725    command line.  */
1726 static unsigned int ix86_user_incoming_stack_boundary;
1727
1728 /* Default alignment for incoming stack boundary in bits.  */
1729 static unsigned int ix86_default_incoming_stack_boundary;
1730
1731 /* Alignment for incoming stack boundary in bits.  */
1732 unsigned int ix86_incoming_stack_boundary;
1733
1734 /* Values 1-5: see jump.c */
1735 int ix86_branch_cost;
1736
1737 /* Calling abi specific va_list type nodes.  */
1738 static GTY(()) tree sysv_va_list_type_node;
1739 static GTY(()) tree ms_va_list_type_node;
1740
1741 /* Variables which are this size or smaller are put in the data/bss
1742    or ldata/lbss sections.  */
1743
1744 int ix86_section_threshold = 65536;
1745
1746 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
1747 char internal_label_prefix[16];
1748 int internal_label_prefix_len;
1749
1750 /* Fence to use after loop using movnt.  */
1751 tree x86_mfence;
1752
1753 /* Register class used for passing given 64bit part of the argument.
1754    These represent classes as documented by the PS ABI, with the exception
1755    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
1756    use SF or DFmode move instead of DImode to avoid reformatting penalties.
1757
1758    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
1759    whenever possible (upper half does contain padding).  */
1760 enum x86_64_reg_class
1761   {
1762     X86_64_NO_CLASS,
1763     X86_64_INTEGER_CLASS,
1764     X86_64_INTEGERSI_CLASS,
1765     X86_64_AVX_CLASS,
1766     X86_64_SSE_CLASS,
1767     X86_64_SSESF_CLASS,
1768     X86_64_SSEDF_CLASS,
1769     X86_64_SSEUP_CLASS,
1770     X86_64_X87_CLASS,
1771     X86_64_X87UP_CLASS,
1772     X86_64_COMPLEX_X87_CLASS,
1773     X86_64_MEMORY_CLASS
1774   };
1775 static const char * const x86_64_reg_class_name[] =
1776 {
1777   "no", "integer", "integerSI", "sse", "sseSF", "sseDF",
1778   "sseup", "x87", "x87up", "cplx87", "no"
1779 };
1780
1781 #define MAX_CLASSES 4
1782
1783 /* Table of constants used by fldpi, fldln2, etc....  */
1784 static REAL_VALUE_TYPE ext_80387_constants_table [5];
1785 static bool ext_80387_constants_init = 0;
1786
1787 \f
1788 static struct machine_function * ix86_init_machine_status (void);
1789 static rtx ix86_function_value (const_tree, const_tree, bool);
1790 static int ix86_function_regparm (const_tree, const_tree);
1791 static void ix86_compute_frame_layout (struct ix86_frame *);
1792 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
1793                                                  rtx, rtx, int);
1794 static void ix86_add_new_builtins (int);
1795
1796 enum ix86_function_specific_strings
1797 {
1798   IX86_FUNCTION_SPECIFIC_ARCH,
1799   IX86_FUNCTION_SPECIFIC_TUNE,
1800   IX86_FUNCTION_SPECIFIC_FPMATH,
1801   IX86_FUNCTION_SPECIFIC_MAX
1802 };
1803
1804 static char *ix86_target_string (int, int, const char *, const char *,
1805                                  const char *, bool);
1806 static void ix86_debug_options (void) ATTRIBUTE_UNUSED;
1807 static void ix86_function_specific_save (struct cl_target_option *);
1808 static void ix86_function_specific_restore (struct cl_target_option *);
1809 static void ix86_function_specific_print (FILE *, int,
1810                                           struct cl_target_option *);
1811 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
1812 static bool ix86_valid_target_attribute_inner_p (tree, char *[]);
1813 static bool ix86_can_inline_p (tree, tree);
1814 static void ix86_set_current_function (tree);
1815
1816 \f
1817 /* The svr4 ABI for the i386 says that records and unions are returned
1818    in memory.  */
1819 #ifndef DEFAULT_PCC_STRUCT_RETURN
1820 #define DEFAULT_PCC_STRUCT_RETURN 1
1821 #endif
1822
1823 /* Whether -mtune= or -march= were specified */
1824 static int ix86_tune_defaulted;
1825 static int ix86_arch_specified;
1826
1827 /* Bit flags that specify the ISA we are compiling for.  */
1828 int ix86_isa_flags = TARGET_64BIT_DEFAULT | TARGET_SUBTARGET_ISA_DEFAULT;
1829
1830 /* A mask of ix86_isa_flags that includes bit X if X
1831    was set or cleared on the command line.  */
1832 static int ix86_isa_flags_explicit;
1833
1834 /* Define a set of ISAs which are available when a given ISA is
1835    enabled.  MMX and SSE ISAs are handled separately.  */
1836
1837 #define OPTION_MASK_ISA_MMX_SET OPTION_MASK_ISA_MMX
1838 #define OPTION_MASK_ISA_3DNOW_SET \
1839   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX_SET)
1840
1841 #define OPTION_MASK_ISA_SSE_SET OPTION_MASK_ISA_SSE
1842 #define OPTION_MASK_ISA_SSE2_SET \
1843   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE_SET)
1844 #define OPTION_MASK_ISA_SSE3_SET \
1845   (OPTION_MASK_ISA_SSE3 | OPTION_MASK_ISA_SSE2_SET)
1846 #define OPTION_MASK_ISA_SSSE3_SET \
1847   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE3_SET)
1848 #define OPTION_MASK_ISA_SSE4_1_SET \
1849   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSSE3_SET)
1850 #define OPTION_MASK_ISA_SSE4_2_SET \
1851   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_SSE4_1_SET)
1852 #define OPTION_MASK_ISA_AVX_SET \
1853   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_SSE4_2_SET)
1854 #define OPTION_MASK_ISA_FMA_SET \
1855   (OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_AVX_SET)
1856
1857 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
1858    as -msse4.2.  */
1859 #define OPTION_MASK_ISA_SSE4_SET OPTION_MASK_ISA_SSE4_2_SET
1860
1861 #define OPTION_MASK_ISA_SSE4A_SET \
1862   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE3_SET)
1863 #define OPTION_MASK_ISA_SSE5_SET \
1864   (OPTION_MASK_ISA_SSE5 | OPTION_MASK_ISA_SSE4A_SET)
1865
1866 /* AES and PCLMUL need SSE2 because they use xmm registers */
1867 #define OPTION_MASK_ISA_AES_SET \
1868   (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2_SET)
1869 #define OPTION_MASK_ISA_PCLMUL_SET \
1870   (OPTION_MASK_ISA_PCLMUL | OPTION_MASK_ISA_SSE2_SET)
1871
1872 #define OPTION_MASK_ISA_ABM_SET \
1873   (OPTION_MASK_ISA_ABM | OPTION_MASK_ISA_POPCNT)
1874 #define OPTION_MASK_ISA_POPCNT_SET OPTION_MASK_ISA_POPCNT
1875 #define OPTION_MASK_ISA_CX16_SET OPTION_MASK_ISA_CX16
1876 #define OPTION_MASK_ISA_SAHF_SET OPTION_MASK_ISA_SAHF
1877
1878 /* Define a set of ISAs which aren't available when a given ISA is
1879    disabled.  MMX and SSE ISAs are handled separately.  */
1880
1881 #define OPTION_MASK_ISA_MMX_UNSET \
1882   (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_3DNOW_UNSET)
1883 #define OPTION_MASK_ISA_3DNOW_UNSET \
1884   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_A_UNSET)
1885 #define OPTION_MASK_ISA_3DNOW_A_UNSET OPTION_MASK_ISA_3DNOW_A
1886
1887 #define OPTION_MASK_ISA_SSE_UNSET \
1888   (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_SSE2_UNSET)
1889 #define OPTION_MASK_ISA_SSE2_UNSET \
1890   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3_UNSET)
1891 #define OPTION_MASK_ISA_SSE3_UNSET \
1892   (OPTION_MASK_ISA_SSE3 \
1893    | OPTION_MASK_ISA_SSSE3_UNSET \
1894    | OPTION_MASK_ISA_SSE4A_UNSET )
1895 #define OPTION_MASK_ISA_SSSE3_UNSET \
1896   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE4_1_UNSET)
1897 #define OPTION_MASK_ISA_SSE4_1_UNSET \
1898   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_2_UNSET)
1899 #define OPTION_MASK_ISA_SSE4_2_UNSET \
1900   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_AVX_UNSET )
1901 #define OPTION_MASK_ISA_AVX_UNSET \
1902   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_FMA_UNSET)
1903 #define OPTION_MASK_ISA_FMA_UNSET OPTION_MASK_ISA_FMA
1904
1905 /* SSE4 includes both SSE4.1 and SSE4.2.  -mno-sse4 should the same
1906    as -mno-sse4.1. */
1907 #define OPTION_MASK_ISA_SSE4_UNSET OPTION_MASK_ISA_SSE4_1_UNSET
1908
1909 #define OPTION_MASK_ISA_SSE4A_UNSET \
1910   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE5_UNSET)
1911 #define OPTION_MASK_ISA_SSE5_UNSET OPTION_MASK_ISA_SSE5
1912 #define OPTION_MASK_ISA_AES_UNSET OPTION_MASK_ISA_AES
1913 #define OPTION_MASK_ISA_PCLMUL_UNSET OPTION_MASK_ISA_PCLMUL
1914 #define OPTION_MASK_ISA_ABM_UNSET OPTION_MASK_ISA_ABM
1915 #define OPTION_MASK_ISA_POPCNT_UNSET OPTION_MASK_ISA_POPCNT
1916 #define OPTION_MASK_ISA_CX16_UNSET OPTION_MASK_ISA_CX16
1917 #define OPTION_MASK_ISA_SAHF_UNSET OPTION_MASK_ISA_SAHF
1918
1919 /* Vectorization library interface and handlers.  */
1920 tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL;
1921 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
1922 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
1923
1924 /* Processor target table, indexed by processor number */
1925 struct ptt
1926 {
1927   const struct processor_costs *cost;           /* Processor costs */
1928   const int align_loop;                         /* Default alignments.  */
1929   const int align_loop_max_skip;
1930   const int align_jump;
1931   const int align_jump_max_skip;
1932   const int align_func;
1933 };
1934
1935 static const struct ptt processor_target_table[PROCESSOR_max] =
1936 {
1937   {&i386_cost, 4, 3, 4, 3, 4},
1938   {&i486_cost, 16, 15, 16, 15, 16},
1939   {&pentium_cost, 16, 7, 16, 7, 16},
1940   {&pentiumpro_cost, 16, 15, 16, 10, 16},
1941   {&geode_cost, 0, 0, 0, 0, 0},
1942   {&k6_cost, 32, 7, 32, 7, 32},
1943   {&athlon_cost, 16, 7, 16, 7, 16},
1944   {&pentium4_cost, 0, 0, 0, 0, 0},
1945   {&k8_cost, 16, 7, 16, 7, 16},
1946   {&nocona_cost, 0, 0, 0, 0, 0},
1947   {&core2_cost, 16, 10, 16, 10, 16},
1948   {&generic32_cost, 16, 7, 16, 7, 16},
1949   {&generic64_cost, 16, 10, 16, 10, 16},
1950   {&amdfam10_cost, 32, 24, 32, 7, 32}
1951 };
1952
1953 static const char *const cpu_names[TARGET_CPU_DEFAULT_max] =
1954 {
1955   "generic",
1956   "i386",
1957   "i486",
1958   "pentium",
1959   "pentium-mmx",
1960   "pentiumpro",
1961   "pentium2",
1962   "pentium3",
1963   "pentium4",
1964   "pentium-m",
1965   "prescott",
1966   "nocona",
1967   "core2",
1968   "geode",
1969   "k6",
1970   "k6-2",
1971   "k6-3",
1972   "athlon",
1973   "athlon-4",
1974   "k8",
1975   "amdfam10"
1976 };
1977 \f
1978 /* Implement TARGET_HANDLE_OPTION.  */
1979
1980 static bool
1981 ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value)
1982 {
1983   switch (code)
1984     {
1985     case OPT_mmmx:
1986       if (value)
1987         {
1988           ix86_isa_flags |= OPTION_MASK_ISA_MMX_SET;
1989           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_SET;
1990         }
1991       else
1992         {
1993           ix86_isa_flags &= ~OPTION_MASK_ISA_MMX_UNSET;
1994           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_UNSET;
1995         }
1996       return true;
1997
1998     case OPT_m3dnow:
1999       if (value)
2000         {
2001           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_SET;
2002           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_SET;
2003         }
2004       else
2005         {
2006           ix86_isa_flags &= ~OPTION_MASK_ISA_3DNOW_UNSET;
2007           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_UNSET;
2008         }
2009       return true;
2010
2011     case OPT_m3dnowa:
2012       return false;
2013
2014     case OPT_msse:
2015       if (value)
2016         {
2017           ix86_isa_flags |= OPTION_MASK_ISA_SSE_SET;
2018           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_SET;
2019         }
2020       else
2021         {
2022           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE_UNSET;
2023           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_UNSET;
2024         }
2025       return true;
2026
2027     case OPT_msse2:
2028       if (value)
2029         {
2030           ix86_isa_flags |= OPTION_MASK_ISA_SSE2_SET;
2031           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_SET;
2032         }
2033       else
2034         {
2035           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE2_UNSET;
2036           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_UNSET;
2037         }
2038       return true;
2039
2040     case OPT_msse3:
2041       if (value)
2042         {
2043           ix86_isa_flags |= OPTION_MASK_ISA_SSE3_SET;
2044           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_SET;
2045         }
2046       else
2047         {
2048           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE3_UNSET;
2049           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_UNSET;
2050         }
2051       return true;
2052
2053     case OPT_mssse3:
2054       if (value)
2055         {
2056           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3_SET;
2057           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_SET;
2058         }
2059       else
2060         {
2061           ix86_isa_flags &= ~OPTION_MASK_ISA_SSSE3_UNSET;
2062           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_UNSET;
2063         }
2064       return true;
2065
2066     case OPT_msse4_1:
2067       if (value)
2068         {
2069           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1_SET;
2070           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_SET;
2071         }
2072       else
2073         {
2074           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_1_UNSET;
2075           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_UNSET;
2076         }
2077       return true;
2078
2079     case OPT_msse4_2:
2080       if (value)
2081         {
2082           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2_SET;
2083           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_SET;
2084         }
2085       else
2086         {
2087           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_2_UNSET;
2088           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_UNSET;
2089         }
2090       return true;
2091
2092     case OPT_mavx:
2093       if (value)
2094         {
2095           ix86_isa_flags |= OPTION_MASK_ISA_AVX_SET;
2096           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_SET;
2097         }
2098       else
2099         {
2100           ix86_isa_flags &= ~OPTION_MASK_ISA_AVX_UNSET;
2101           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_UNSET;
2102         }
2103       return true;
2104
2105     case OPT_mfma:
2106       if (value)
2107         {
2108           ix86_isa_flags |= OPTION_MASK_ISA_FMA_SET;
2109           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_SET;
2110         }
2111       else
2112         {
2113           ix86_isa_flags &= ~OPTION_MASK_ISA_FMA_UNSET;
2114           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_UNSET;
2115         }
2116       return true;
2117
2118     case OPT_msse4:
2119       ix86_isa_flags |= OPTION_MASK_ISA_SSE4_SET;
2120       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_SET;
2121       return true;
2122
2123     case OPT_mno_sse4:
2124       ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
2125       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
2126       return true;
2127
2128     case OPT_msse4a:
2129       if (value)
2130         {
2131           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A_SET;
2132           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_SET;
2133         }
2134       else
2135         {
2136           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4A_UNSET;
2137           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_UNSET;
2138         }
2139       return true;
2140
2141     case OPT_msse5:
2142       if (value)
2143         {
2144           ix86_isa_flags |= OPTION_MASK_ISA_SSE5_SET;
2145           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_SET;
2146         }
2147       else
2148         {
2149           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE5_UNSET;
2150           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_UNSET;
2151         }
2152       return true;
2153
2154     case OPT_mabm:
2155       if (value)
2156         {
2157           ix86_isa_flags |= OPTION_MASK_ISA_ABM_SET;
2158           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_SET;
2159         }
2160       else
2161         {
2162           ix86_isa_flags &= ~OPTION_MASK_ISA_ABM_UNSET;
2163           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_UNSET;
2164         }
2165       return true;
2166
2167     case OPT_mpopcnt:
2168       if (value)
2169         {
2170           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT_SET;
2171           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_SET;
2172         }
2173       else
2174         {
2175           ix86_isa_flags &= ~OPTION_MASK_ISA_POPCNT_UNSET;
2176           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_UNSET;
2177         }
2178       return true;
2179
2180     case OPT_msahf:
2181       if (value)
2182         {
2183           ix86_isa_flags |= OPTION_MASK_ISA_SAHF_SET;
2184           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_SET;
2185         }
2186       else
2187         {
2188           ix86_isa_flags &= ~OPTION_MASK_ISA_SAHF_UNSET;
2189           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_UNSET;
2190         }
2191       return true;
2192
2193     case OPT_mcx16:
2194       if (value)
2195         {
2196           ix86_isa_flags |= OPTION_MASK_ISA_CX16_SET;
2197           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_SET;
2198         }
2199       else
2200         {
2201           ix86_isa_flags &= ~OPTION_MASK_ISA_CX16_UNSET;
2202           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_UNSET;
2203         }
2204       return true;
2205
2206     case OPT_maes:
2207       if (value)
2208         {
2209           ix86_isa_flags |= OPTION_MASK_ISA_AES_SET;
2210           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_SET;
2211         }
2212       else
2213         {
2214           ix86_isa_flags &= ~OPTION_MASK_ISA_AES_UNSET;
2215           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_UNSET;
2216         }
2217       return true;
2218
2219     case OPT_mpclmul:
2220       if (value)
2221         {
2222           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL_SET;
2223           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_SET;
2224         }
2225       else
2226         {
2227           ix86_isa_flags &= ~OPTION_MASK_ISA_PCLMUL_UNSET;
2228           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_UNSET;
2229         }
2230       return true;
2231
2232     default:
2233       return true;
2234     }
2235 }
2236 \f
2237 /* Return a string the documents the current -m options.  The caller is
2238    responsible for freeing the string.  */
2239
2240 static char *
2241 ix86_target_string (int isa, int flags, const char *arch, const char *tune,
2242                     const char *fpmath, bool add_nl_p)
2243 {
2244   struct ix86_target_opts
2245   {
2246     const char *option;         /* option string */
2247     int mask;                   /* isa mask options */
2248   };
2249
2250   /* This table is ordered so that options like -msse5 or -msse4.2 that imply
2251      preceding options while match those first.  */
2252   static struct ix86_target_opts isa_opts[] =
2253   {
2254     { "-m64",           OPTION_MASK_ISA_64BIT },
2255     { "-msse5",         OPTION_MASK_ISA_SSE5 },
2256     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2257     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2258     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2259     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2260     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2261     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2262     { "-msse",          OPTION_MASK_ISA_SSE },
2263     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2264     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2265     { "-mmmx",          OPTION_MASK_ISA_MMX },
2266     { "-mabm",          OPTION_MASK_ISA_ABM },
2267     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2268     { "-maes",          OPTION_MASK_ISA_AES },
2269     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2270   };
2271
2272   /* Flag options.  */
2273   static struct ix86_target_opts flag_opts[] =
2274   {
2275     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2276     { "-m80387",                        MASK_80387 },
2277     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2278     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2279     { "-mcld",                          MASK_CLD },
2280     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2281     { "-mieee-fp",                      MASK_IEEE_FP },
2282     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2283     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2284     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2285     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2286     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2287     { "-mno-fused-madd",                MASK_NO_FUSED_MADD },
2288     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2289     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2290     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2291     { "-mrecip",                        MASK_RECIP },
2292     { "-mrtd",                          MASK_RTD },
2293     { "-msseregparm",                   MASK_SSEREGPARM },
2294     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2295     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2296   };
2297
2298   const char *opts[ (sizeof (isa_opts) / sizeof (isa_opts[0])
2299                      + sizeof (flag_opts) / sizeof (flag_opts[0])
2300                      + 6)][2];
2301
2302   char isa_other[40];
2303   char target_other[40];
2304   unsigned num = 0;
2305   unsigned i, j;
2306   char *ret;
2307   char *ptr;
2308   size_t len;
2309   size_t line_len;
2310   size_t sep_len;
2311
2312   memset (opts, '\0', sizeof (opts));
2313
2314   /* Add -march= option.  */
2315   if (arch)
2316     {
2317       opts[num][0] = "-march=";
2318       opts[num++][1] = arch;
2319     }
2320
2321   /* Add -mtune= option.  */
2322   if (tune)
2323     {
2324       opts[num][0] = "-mtune=";
2325       opts[num++][1] = tune;
2326     }
2327
2328   /* Pick out the options in isa options.  */
2329   for (i = 0; i < sizeof (isa_opts) / sizeof (isa_opts[0]); i++)
2330     {
2331       if ((isa & isa_opts[i].mask) != 0)
2332         {
2333           opts[num++][0] = isa_opts[i].option;
2334           isa &= ~ isa_opts[i].mask;
2335         }
2336     }
2337
2338   if (isa && add_nl_p)
2339     {
2340       opts[num++][0] = isa_other;
2341       sprintf (isa_other, "(other isa: 0x%x)", isa);
2342     }
2343
2344   /* Add flag options.  */
2345   for (i = 0; i < sizeof (flag_opts) / sizeof (flag_opts[0]); i++)
2346     {
2347       if ((flags & flag_opts[i].mask) != 0)
2348         {
2349           opts[num++][0] = flag_opts[i].option;
2350           flags &= ~ flag_opts[i].mask;
2351         }
2352     }
2353
2354   if (flags && add_nl_p)
2355     {
2356       opts[num++][0] = target_other;
2357       sprintf (target_other, "(other flags: 0x%x)", isa);
2358     }
2359
2360   /* Add -fpmath= option.  */
2361   if (fpmath)
2362     {
2363       opts[num][0] = "-mfpmath=";
2364       opts[num++][1] = fpmath;
2365     }
2366
2367   /* Any options?  */
2368   if (num == 0)
2369     return NULL;
2370
2371   gcc_assert (num < sizeof (opts) / sizeof (opts[0]));
2372
2373   /* Size the string.  */
2374   len = 0;
2375   sep_len = (add_nl_p) ? 3 : 1;
2376   for (i = 0; i < num; i++)
2377     {
2378       len += sep_len;
2379       for (j = 0; j < 2; j++)
2380         if (opts[i][j])
2381           len += strlen (opts[i][j]);
2382     }
2383
2384   /* Build the string.  */
2385   ret = ptr = (char *) xmalloc (len);
2386   line_len = 0;
2387
2388   for (i = 0; i < num; i++)
2389     {
2390       size_t len2[2];
2391
2392       for (j = 0; j < 2; j++)
2393         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2394
2395       if (i != 0)
2396         {
2397           *ptr++ = ' ';
2398           line_len++;
2399
2400           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2401             {
2402               *ptr++ = '\\';
2403               *ptr++ = '\n';
2404               line_len = 0;
2405             }
2406         }
2407
2408       for (j = 0; j < 2; j++)
2409         if (opts[i][j])
2410           {
2411             memcpy (ptr, opts[i][j], len2[j]);
2412             ptr += len2[j];
2413             line_len += len2[j];
2414           }
2415     }
2416
2417   *ptr = '\0';
2418   gcc_assert (ret + len >= ptr);
2419
2420   return ret;
2421 }
2422
2423 /* Function that is callable from the debugger to print the current
2424    options.  */
2425 void
2426 ix86_debug_options (void)
2427 {
2428   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2429                                    ix86_arch_string, ix86_tune_string,
2430                                    ix86_fpmath_string, true);
2431
2432   if (opts)
2433     {
2434       fprintf (stderr, "%s\n\n", opts);
2435       free (opts);
2436     }
2437   else
2438     fprintf (stderr, "<no options>\n\n");
2439
2440   return;
2441 }
2442 \f
2443 /* Sometimes certain combinations of command options do not make
2444    sense on a particular target machine.  You can define a macro
2445    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
2446    defined, is executed once just after all the command options have
2447    been parsed.
2448
2449    Don't use this macro to turn on various extra optimizations for
2450    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
2451
2452 void
2453 override_options (bool main_args_p)
2454 {
2455   int i;
2456   unsigned int ix86_arch_mask, ix86_tune_mask;
2457   const char *prefix;
2458   const char *suffix;
2459   const char *sw;
2460
2461   /* Comes from final.c -- no real reason to change it.  */
2462 #define MAX_CODE_ALIGN 16
2463
2464   enum pta_flags
2465     {
2466       PTA_SSE = 1 << 0,
2467       PTA_SSE2 = 1 << 1,
2468       PTA_SSE3 = 1 << 2,
2469       PTA_MMX = 1 << 3,
2470       PTA_PREFETCH_SSE = 1 << 4,
2471       PTA_3DNOW = 1 << 5,
2472       PTA_3DNOW_A = 1 << 6,
2473       PTA_64BIT = 1 << 7,
2474       PTA_SSSE3 = 1 << 8,
2475       PTA_CX16 = 1 << 9,
2476       PTA_POPCNT = 1 << 10,
2477       PTA_ABM = 1 << 11,
2478       PTA_SSE4A = 1 << 12,
2479       PTA_NO_SAHF = 1 << 13,
2480       PTA_SSE4_1 = 1 << 14,
2481       PTA_SSE4_2 = 1 << 15,
2482       PTA_SSE5 = 1 << 16,
2483       PTA_AES = 1 << 17,
2484       PTA_PCLMUL = 1 << 18,
2485       PTA_AVX = 1 << 19,
2486       PTA_FMA = 1 << 20 
2487     };
2488
2489   static struct pta
2490     {
2491       const char *const name;           /* processor name or nickname.  */
2492       const enum processor_type processor;
2493       const unsigned /*enum pta_flags*/ flags;
2494     }
2495   const processor_alias_table[] =
2496     {
2497       {"i386", PROCESSOR_I386, 0},
2498       {"i486", PROCESSOR_I486, 0},
2499       {"i586", PROCESSOR_PENTIUM, 0},
2500       {"pentium", PROCESSOR_PENTIUM, 0},
2501       {"pentium-mmx", PROCESSOR_PENTIUM, PTA_MMX},
2502       {"winchip-c6", PROCESSOR_I486, PTA_MMX},
2503       {"winchip2", PROCESSOR_I486, PTA_MMX | PTA_3DNOW},
2504       {"c3", PROCESSOR_I486, PTA_MMX | PTA_3DNOW},
2505       {"c3-2", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2506       {"i686", PROCESSOR_PENTIUMPRO, 0},
2507       {"pentiumpro", PROCESSOR_PENTIUMPRO, 0},
2508       {"pentium2", PROCESSOR_PENTIUMPRO, PTA_MMX},
2509       {"pentium3", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2510       {"pentium3m", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2511       {"pentium-m", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE | PTA_SSE2},
2512       {"pentium4", PROCESSOR_PENTIUM4, PTA_MMX |PTA_SSE | PTA_SSE2},
2513       {"pentium4m", PROCESSOR_PENTIUM4, PTA_MMX | PTA_SSE | PTA_SSE2},
2514       {"prescott", PROCESSOR_NOCONA, PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3},
2515       {"nocona", PROCESSOR_NOCONA, (PTA_64BIT
2516                                     | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2517                                     | PTA_CX16 | PTA_NO_SAHF)},
2518       {"core2", PROCESSOR_CORE2, (PTA_64BIT
2519                                   | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2520                                   | PTA_SSSE3
2521                                   | PTA_CX16)},
2522       {"geode", PROCESSOR_GEODE, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2523                                   |PTA_PREFETCH_SSE)},
2524       {"k6", PROCESSOR_K6, PTA_MMX},
2525       {"k6-2", PROCESSOR_K6, PTA_MMX | PTA_3DNOW},
2526       {"k6-3", PROCESSOR_K6, PTA_MMX | PTA_3DNOW},
2527       {"athlon", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2528                                     | PTA_PREFETCH_SSE)},
2529       {"athlon-tbird", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2530                                           | PTA_PREFETCH_SSE)},
2531       {"athlon-4", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2532                                       | PTA_SSE)},
2533       {"athlon-xp", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2534                                        | PTA_SSE)},
2535       {"athlon-mp", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2536                                        | PTA_SSE)},
2537       {"x86-64", PROCESSOR_K8, (PTA_64BIT
2538                                 | PTA_MMX | PTA_SSE | PTA_SSE2
2539                                 | PTA_NO_SAHF)},
2540       {"k8", PROCESSOR_K8, (PTA_64BIT
2541                             | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2542                             | PTA_SSE | PTA_SSE2
2543                             | PTA_NO_SAHF)},
2544       {"k8-sse3", PROCESSOR_K8, (PTA_64BIT
2545                                  | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2546                                  | PTA_SSE | PTA_SSE2 | PTA_SSE3
2547                                  | PTA_NO_SAHF)},
2548       {"opteron", PROCESSOR_K8, (PTA_64BIT
2549                                  | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2550                                  | PTA_SSE | PTA_SSE2
2551                                  | PTA_NO_SAHF)},
2552       {"opteron-sse3", PROCESSOR_K8, (PTA_64BIT
2553                                       | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2554                                       | PTA_SSE | PTA_SSE2 | PTA_SSE3
2555                                       | PTA_NO_SAHF)},
2556       {"athlon64", PROCESSOR_K8, (PTA_64BIT
2557                                   | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2558                                   | PTA_SSE | PTA_SSE2
2559                                   | PTA_NO_SAHF)},
2560       {"athlon64-sse3", PROCESSOR_K8, (PTA_64BIT
2561                                        | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2562                                        | PTA_SSE | PTA_SSE2 | PTA_SSE3
2563                                        | PTA_NO_SAHF)},
2564       {"athlon-fx", PROCESSOR_K8, (PTA_64BIT
2565                                    | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2566                                    | PTA_SSE | PTA_SSE2
2567                                    | PTA_NO_SAHF)},
2568       {"amdfam10", PROCESSOR_AMDFAM10, (PTA_64BIT
2569                                         | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2570                                         | PTA_SSE | PTA_SSE2 | PTA_SSE3
2571                                         | PTA_SSE4A
2572                                         | PTA_CX16 | PTA_ABM)},
2573       {"barcelona", PROCESSOR_AMDFAM10, (PTA_64BIT
2574                                          | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2575                                          | PTA_SSE | PTA_SSE2 | PTA_SSE3
2576                                          | PTA_SSE4A
2577                                          | PTA_CX16 | PTA_ABM)},
2578       {"generic32", PROCESSOR_GENERIC32, 0 /* flags are only used for -march switch.  */ },
2579       {"generic64", PROCESSOR_GENERIC64, PTA_64BIT /* flags are only used for -march switch.  */ },
2580     };
2581
2582   int const pta_size = ARRAY_SIZE (processor_alias_table);
2583
2584   /* Set up prefix/suffix so the error messages refer to either the command
2585      line argument, or the attribute(target).  */
2586   if (main_args_p)
2587     {
2588       prefix = "-m";
2589       suffix = "";
2590       sw = "switch";
2591     }
2592   else
2593     {
2594       prefix = "option(\"";
2595       suffix = "\")";
2596       sw = "attribute";
2597     }
2598
2599 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2600   SUBTARGET_OVERRIDE_OPTIONS;
2601 #endif
2602
2603 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2604   SUBSUBTARGET_OVERRIDE_OPTIONS;
2605 #endif
2606
2607   /* -fPIC is the default for x86_64.  */
2608   if (TARGET_MACHO && TARGET_64BIT)
2609     flag_pic = 2;
2610
2611   /* Set the default values for switches whose default depends on TARGET_64BIT
2612      in case they weren't overwritten by command line options.  */
2613   if (TARGET_64BIT)
2614     {
2615       /* Mach-O doesn't support omitting the frame pointer for now.  */
2616       if (flag_omit_frame_pointer == 2)
2617         flag_omit_frame_pointer = (TARGET_MACHO ? 0 : 1);
2618       if (flag_asynchronous_unwind_tables == 2)
2619         flag_asynchronous_unwind_tables = 1;
2620       if (flag_pcc_struct_return == 2)
2621         flag_pcc_struct_return = 0;
2622     }
2623   else
2624     {
2625       if (flag_omit_frame_pointer == 2)
2626         flag_omit_frame_pointer = 0;
2627       if (flag_asynchronous_unwind_tables == 2)
2628         flag_asynchronous_unwind_tables = 0;
2629       if (flag_pcc_struct_return == 2)
2630         flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
2631     }
2632
2633   /* Need to check -mtune=generic first.  */
2634   if (ix86_tune_string)
2635     {
2636       if (!strcmp (ix86_tune_string, "generic")
2637           || !strcmp (ix86_tune_string, "i686")
2638           /* As special support for cross compilers we read -mtune=native
2639              as -mtune=generic.  With native compilers we won't see the
2640              -mtune=native, as it was changed by the driver.  */
2641           || !strcmp (ix86_tune_string, "native"))
2642         {
2643           if (TARGET_64BIT)
2644             ix86_tune_string = "generic64";
2645           else
2646             ix86_tune_string = "generic32";
2647         }
2648       /* If this call is for setting the option attribute, allow the
2649          generic32/generic64 that was previously set.  */
2650       else if (!main_args_p
2651                && (!strcmp (ix86_tune_string, "generic32")
2652                    || !strcmp (ix86_tune_string, "generic64")))
2653         ;
2654       else if (!strncmp (ix86_tune_string, "generic", 7))
2655         error ("bad value (%s) for %stune=%s %s",
2656                ix86_tune_string, prefix, suffix, sw);
2657     }
2658   else
2659     {
2660       if (ix86_arch_string)
2661         ix86_tune_string = ix86_arch_string;
2662       if (!ix86_tune_string)
2663         {
2664           ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT];
2665           ix86_tune_defaulted = 1;
2666         }
2667
2668       /* ix86_tune_string is set to ix86_arch_string or defaulted.  We
2669          need to use a sensible tune option.  */
2670       if (!strcmp (ix86_tune_string, "generic")
2671           || !strcmp (ix86_tune_string, "x86-64")
2672           || !strcmp (ix86_tune_string, "i686"))
2673         {
2674           if (TARGET_64BIT)
2675             ix86_tune_string = "generic64";
2676           else
2677             ix86_tune_string = "generic32";
2678         }
2679     }
2680   if (ix86_stringop_string)
2681     {
2682       if (!strcmp (ix86_stringop_string, "rep_byte"))
2683         stringop_alg = rep_prefix_1_byte;
2684       else if (!strcmp (ix86_stringop_string, "libcall"))
2685         stringop_alg = libcall;
2686       else if (!strcmp (ix86_stringop_string, "rep_4byte"))
2687         stringop_alg = rep_prefix_4_byte;
2688       else if (!strcmp (ix86_stringop_string, "rep_8byte"))
2689         stringop_alg = rep_prefix_8_byte;
2690       else if (!strcmp (ix86_stringop_string, "byte_loop"))
2691         stringop_alg = loop_1_byte;
2692       else if (!strcmp (ix86_stringop_string, "loop"))
2693         stringop_alg = loop;
2694       else if (!strcmp (ix86_stringop_string, "unrolled_loop"))
2695         stringop_alg = unrolled_loop;
2696       else
2697         error ("bad value (%s) for %sstringop-strategy=%s %s",
2698                ix86_stringop_string, prefix, suffix, sw);
2699     }
2700   if (!strcmp (ix86_tune_string, "x86-64"))
2701     warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated.  Use "
2702              "%stune=k8%s or %stune=generic%s instead as appropriate.",
2703              prefix, suffix, prefix, suffix, prefix, suffix);
2704
2705   if (!ix86_arch_string)
2706     ix86_arch_string = TARGET_64BIT ? "x86-64" : "i386";
2707   else
2708     ix86_arch_specified = 1;
2709
2710   if (!strcmp (ix86_arch_string, "generic"))
2711     error ("generic CPU can be used only for %stune=%s %s",
2712            prefix, suffix, sw);
2713   if (!strncmp (ix86_arch_string, "generic", 7))
2714     error ("bad value (%s) for %sarch=%s %s",
2715            ix86_arch_string, prefix, suffix, sw);
2716
2717   if (ix86_cmodel_string != 0)
2718     {
2719       if (!strcmp (ix86_cmodel_string, "small"))
2720         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2721       else if (!strcmp (ix86_cmodel_string, "medium"))
2722         ix86_cmodel = flag_pic ? CM_MEDIUM_PIC : CM_MEDIUM;
2723       else if (!strcmp (ix86_cmodel_string, "large"))
2724         ix86_cmodel = flag_pic ? CM_LARGE_PIC : CM_LARGE;
2725       else if (flag_pic)
2726         error ("code model %s does not support PIC mode", ix86_cmodel_string);
2727       else if (!strcmp (ix86_cmodel_string, "32"))
2728         ix86_cmodel = CM_32;
2729       else if (!strcmp (ix86_cmodel_string, "kernel") && !flag_pic)
2730         ix86_cmodel = CM_KERNEL;
2731       else
2732         error ("bad value (%s) for %scmodel=%s %s",
2733                ix86_cmodel_string, prefix, suffix, sw);
2734     }
2735   else
2736     {
2737       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
2738          use of rip-relative addressing.  This eliminates fixups that
2739          would otherwise be needed if this object is to be placed in a
2740          DLL, and is essentially just as efficient as direct addressing.  */
2741       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
2742         ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
2743       else if (TARGET_64BIT)
2744         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2745       else
2746         ix86_cmodel = CM_32;
2747     }
2748   if (ix86_asm_string != 0)
2749     {
2750       if (! TARGET_MACHO
2751           && !strcmp (ix86_asm_string, "intel"))
2752         ix86_asm_dialect = ASM_INTEL;
2753       else if (!strcmp (ix86_asm_string, "att"))
2754         ix86_asm_dialect = ASM_ATT;
2755       else
2756         error ("bad value (%s) for %sasm=%s %s",
2757                ix86_asm_string, prefix, suffix, sw);
2758     }
2759   if ((TARGET_64BIT == 0) != (ix86_cmodel == CM_32))
2760     error ("code model %qs not supported in the %s bit mode",
2761            ix86_cmodel_string, TARGET_64BIT ? "64" : "32");
2762   if ((TARGET_64BIT != 0) != ((ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2763     sorry ("%i-bit mode not compiled in",
2764            (ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2765
2766   for (i = 0; i < pta_size; i++)
2767     if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
2768       {
2769         ix86_arch = processor_alias_table[i].processor;
2770         /* Default cpu tuning to the architecture.  */
2771         ix86_tune = ix86_arch;
2772
2773         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2774           error ("CPU you selected does not support x86-64 "
2775                  "instruction set");
2776
2777         if (processor_alias_table[i].flags & PTA_MMX
2778             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
2779           ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2780         if (processor_alias_table[i].flags & PTA_3DNOW
2781             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
2782           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
2783         if (processor_alias_table[i].flags & PTA_3DNOW_A
2784             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
2785           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
2786         if (processor_alias_table[i].flags & PTA_SSE
2787             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
2788           ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2789         if (processor_alias_table[i].flags & PTA_SSE2
2790             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
2791           ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2792         if (processor_alias_table[i].flags & PTA_SSE3
2793             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
2794           ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2795         if (processor_alias_table[i].flags & PTA_SSSE3
2796             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
2797           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2798         if (processor_alias_table[i].flags & PTA_SSE4_1
2799             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
2800           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2801         if (processor_alias_table[i].flags & PTA_SSE4_2
2802             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
2803           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
2804         if (processor_alias_table[i].flags & PTA_AVX
2805             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
2806           ix86_isa_flags |= OPTION_MASK_ISA_AVX;
2807         if (processor_alias_table[i].flags & PTA_FMA
2808             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
2809           ix86_isa_flags |= OPTION_MASK_ISA_FMA;
2810         if (processor_alias_table[i].flags & PTA_SSE4A
2811             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
2812           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2813         if (processor_alias_table[i].flags & PTA_SSE5
2814             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE5))
2815           ix86_isa_flags |= OPTION_MASK_ISA_SSE5;
2816         if (processor_alias_table[i].flags & PTA_ABM
2817             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
2818           ix86_isa_flags |= OPTION_MASK_ISA_ABM;
2819         if (processor_alias_table[i].flags & PTA_CX16
2820             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
2821           ix86_isa_flags |= OPTION_MASK_ISA_CX16;
2822         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
2823             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
2824           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
2825         if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF))
2826             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
2827           ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
2828         if (processor_alias_table[i].flags & PTA_AES
2829             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
2830           ix86_isa_flags |= OPTION_MASK_ISA_AES;
2831         if (processor_alias_table[i].flags & PTA_PCLMUL
2832             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
2833           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
2834         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
2835           x86_prefetch_sse = true;
2836
2837         break;
2838       }
2839
2840   if (i == pta_size)
2841     error ("bad value (%s) for %sarch=%s %s",
2842            ix86_arch_string, prefix, suffix, sw);
2843
2844   ix86_arch_mask = 1u << ix86_arch;
2845   for (i = 0; i < X86_ARCH_LAST; ++i)
2846     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
2847
2848   for (i = 0; i < pta_size; i++)
2849     if (! strcmp (ix86_tune_string, processor_alias_table[i].name))
2850       {
2851         ix86_tune = processor_alias_table[i].processor;
2852         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2853           {
2854             if (ix86_tune_defaulted)
2855               {
2856                 ix86_tune_string = "x86-64";
2857                 for (i = 0; i < pta_size; i++)
2858                   if (! strcmp (ix86_tune_string,
2859                                 processor_alias_table[i].name))
2860                     break;
2861                 ix86_tune = processor_alias_table[i].processor;
2862               }
2863             else
2864               error ("CPU you selected does not support x86-64 "
2865                      "instruction set");
2866           }
2867         /* Intel CPUs have always interpreted SSE prefetch instructions as
2868            NOPs; so, we can enable SSE prefetch instructions even when
2869            -mtune (rather than -march) points us to a processor that has them.
2870            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
2871            higher processors.  */
2872         if (TARGET_CMOVE
2873             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
2874           x86_prefetch_sse = true;
2875         break;
2876       }
2877   if (i == pta_size)
2878     error ("bad value (%s) for %stune=%s %s",
2879            ix86_tune_string, prefix, suffix, sw);
2880
2881   ix86_tune_mask = 1u << ix86_tune;
2882   for (i = 0; i < X86_TUNE_LAST; ++i)
2883     ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
2884
2885   if (optimize_size)
2886     ix86_cost = &ix86_size_cost;
2887   else
2888     ix86_cost = processor_target_table[ix86_tune].cost;
2889
2890   /* Arrange to set up i386_stack_locals for all functions.  */
2891   init_machine_status = ix86_init_machine_status;
2892
2893   /* Validate -mregparm= value.  */
2894   if (ix86_regparm_string)
2895     {
2896       if (TARGET_64BIT)
2897         warning (0, "%sregparm%s is ignored in 64-bit mode", prefix, suffix);
2898       i = atoi (ix86_regparm_string);
2899       if (i < 0 || i > REGPARM_MAX)
2900         error ("%sregparm=%d%s is not between 0 and %d",
2901                prefix, i, suffix, REGPARM_MAX);
2902       else
2903         ix86_regparm = i;
2904     }
2905   if (TARGET_64BIT)
2906     ix86_regparm = REGPARM_MAX;
2907
2908   /* If the user has provided any of the -malign-* options,
2909      warn and use that value only if -falign-* is not set.
2910      Remove this code in GCC 3.2 or later.  */
2911   if (ix86_align_loops_string)
2912     {
2913       warning (0, "%salign-loops%s is obsolete, use %salign-loops%s",
2914                prefix, suffix, prefix, suffix);
2915       if (align_loops == 0)
2916         {
2917           i = atoi (ix86_align_loops_string);
2918           if (i < 0 || i > MAX_CODE_ALIGN)
2919             error ("%salign-loops=%d%s is not between 0 and %d",
2920                    prefix, i, suffix, MAX_CODE_ALIGN);
2921           else
2922             align_loops = 1 << i;
2923         }
2924     }
2925
2926   if (ix86_align_jumps_string)
2927     {
2928       warning (0, "%salign-jumps%s is obsolete, use %salign-jumps%s",
2929                prefix, suffix, prefix, suffix);
2930       if (align_jumps == 0)
2931         {
2932           i = atoi (ix86_align_jumps_string);
2933           if (i < 0 || i > MAX_CODE_ALIGN)
2934             error ("%salign-loops=%d%s is not between 0 and %d",
2935                    prefix, i, suffix, MAX_CODE_ALIGN);
2936           else
2937             align_jumps = 1 << i;
2938         }
2939     }
2940
2941   if (ix86_align_funcs_string)
2942     {
2943       warning (0, "%salign-functions%s is obsolete, use %salign-functions%s",
2944                prefix, suffix, prefix, suffix);
2945       if (align_functions == 0)
2946         {
2947           i = atoi (ix86_align_funcs_string);
2948           if (i < 0 || i > MAX_CODE_ALIGN)
2949             error ("%salign-loops=%d%s is not between 0 and %d",
2950                    prefix, i, suffix, MAX_CODE_ALIGN);
2951           else
2952             align_functions = 1 << i;
2953         }
2954     }
2955
2956   /* Default align_* from the processor table.  */
2957   if (align_loops == 0)
2958     {
2959       align_loops = processor_target_table[ix86_tune].align_loop;
2960       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
2961     }
2962   if (align_jumps == 0)
2963     {
2964       align_jumps = processor_target_table[ix86_tune].align_jump;
2965       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
2966     }
2967   if (align_functions == 0)
2968     {
2969       align_functions = processor_target_table[ix86_tune].align_func;
2970     }
2971
2972   /* Validate -mbranch-cost= value, or provide default.  */
2973   ix86_branch_cost = ix86_cost->branch_cost;
2974   if (ix86_branch_cost_string)
2975     {
2976       i = atoi (ix86_branch_cost_string);
2977       if (i < 0 || i > 5)
2978         error ("%sbranch-cost=%d%s is not between 0 and 5", prefix, i, suffix);
2979       else
2980         ix86_branch_cost = i;
2981     }
2982   if (ix86_section_threshold_string)
2983     {
2984       i = atoi (ix86_section_threshold_string);
2985       if (i < 0)
2986         error ("%slarge-data-threshold=%d%s is negative", prefix, i, suffix);
2987       else
2988         ix86_section_threshold = i;
2989     }
2990
2991   if (ix86_tls_dialect_string)
2992     {
2993       if (strcmp (ix86_tls_dialect_string, "gnu") == 0)
2994         ix86_tls_dialect = TLS_DIALECT_GNU;
2995       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
2996         ix86_tls_dialect = TLS_DIALECT_GNU2;
2997       else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
2998         ix86_tls_dialect = TLS_DIALECT_SUN;
2999       else
3000         error ("bad value (%s) for %stls-dialect=%s %s",
3001                ix86_tls_dialect_string, prefix, suffix, sw);
3002     }
3003
3004   if (ix87_precision_string)
3005     {
3006       i = atoi (ix87_precision_string);
3007       if (i != 32 && i != 64 && i != 80)
3008         error ("pc%d is not valid precision setting (32, 64 or 80)", i);
3009     }
3010
3011   if (TARGET_64BIT)
3012     {
3013       target_flags |= TARGET_SUBTARGET64_DEFAULT & ~target_flags_explicit;
3014
3015       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3016          explicitly disable any of these.  In particular, disabling SSE and
3017          MMX for kernel code is extremely useful.  */
3018       if (!ix86_arch_specified)
3019       ix86_isa_flags
3020         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3021              | TARGET_SUBTARGET64_ISA_DEFAULT) & ~ix86_isa_flags_explicit);
3022
3023       if (TARGET_RTD)
3024         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3025     }
3026   else
3027     {
3028       target_flags |= TARGET_SUBTARGET32_DEFAULT & ~target_flags_explicit;
3029
3030       if (!ix86_arch_specified)
3031       ix86_isa_flags
3032         |= TARGET_SUBTARGET32_ISA_DEFAULT & ~ix86_isa_flags_explicit;
3033
3034       /* i386 ABI does not specify red zone.  It still makes sense to use it
3035          when programmer takes care to stack from being destroyed.  */
3036       if (!(target_flags_explicit & MASK_NO_RED_ZONE))
3037         target_flags |= MASK_NO_RED_ZONE;
3038     }
3039
3040   /* Keep nonleaf frame pointers.  */
3041   if (flag_omit_frame_pointer)
3042     target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3043   else if (TARGET_OMIT_LEAF_FRAME_POINTER)
3044     flag_omit_frame_pointer = 1;
3045
3046   /* If we're doing fast math, we don't care about comparison order
3047      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3048   if (flag_finite_math_only)
3049     target_flags &= ~MASK_IEEE_FP;
3050
3051   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3052      since the insns won't need emulation.  */
3053   if (x86_arch_always_fancy_math_387 & ix86_arch_mask)
3054     target_flags &= ~MASK_NO_FANCY_MATH_387;
3055
3056   /* Likewise, if the target doesn't have a 387, or we've specified
3057      software floating point, don't use 387 inline intrinsics.  */
3058   if (!TARGET_80387)
3059     target_flags |= MASK_NO_FANCY_MATH_387;
3060
3061   /* Turn on MMX builtins for -msse.  */
3062   if (TARGET_SSE)
3063     {
3064       ix86_isa_flags |= OPTION_MASK_ISA_MMX & ~ix86_isa_flags_explicit;
3065       x86_prefetch_sse = true;
3066     }
3067
3068   /* Turn on popcnt instruction for -msse4.2 or -mabm.  */
3069   if (TARGET_SSE4_2 || TARGET_ABM)
3070     ix86_isa_flags |= OPTION_MASK_ISA_POPCNT & ~ix86_isa_flags_explicit;
3071
3072   /* Validate -mpreferred-stack-boundary= value or default it to
3073      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
3074   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
3075   if (ix86_preferred_stack_boundary_string)
3076     {
3077       i = atoi (ix86_preferred_stack_boundary_string);
3078       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3079         error ("%spreferred-stack-boundary=%d%s is not between %d and 12",
3080                prefix, i, suffix, TARGET_64BIT ? 4 : 2);
3081       else
3082         ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
3083     }
3084
3085   /* Set the default value for -mstackrealign.  */
3086   if (ix86_force_align_arg_pointer == -1)
3087     ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
3088
3089   /* Validate -mincoming-stack-boundary= value or default it to
3090      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
3091   if (ix86_force_align_arg_pointer)
3092     ix86_default_incoming_stack_boundary = MIN_STACK_BOUNDARY;
3093   else
3094     ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
3095   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
3096   if (ix86_incoming_stack_boundary_string)
3097     {
3098       i = atoi (ix86_incoming_stack_boundary_string);
3099       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3100         error ("-mincoming-stack-boundary=%d is not between %d and 12",
3101                i, TARGET_64BIT ? 4 : 2);
3102       else
3103         {
3104           ix86_user_incoming_stack_boundary = (1 << i) * BITS_PER_UNIT;
3105           ix86_incoming_stack_boundary
3106             = ix86_user_incoming_stack_boundary;
3107         }
3108     }
3109
3110   /* Accept -msseregparm only if at least SSE support is enabled.  */
3111   if (TARGET_SSEREGPARM
3112       && ! TARGET_SSE)
3113     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
3114
3115   ix86_fpmath = TARGET_FPMATH_DEFAULT;
3116   if (ix86_fpmath_string != 0)
3117     {
3118       if (! strcmp (ix86_fpmath_string, "387"))
3119         ix86_fpmath = FPMATH_387;
3120       else if (! strcmp (ix86_fpmath_string, "sse"))
3121         {
3122           if (!TARGET_SSE)
3123             {
3124               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3125               ix86_fpmath = FPMATH_387;
3126             }
3127           else
3128             ix86_fpmath = FPMATH_SSE;
3129         }
3130       else if (! strcmp (ix86_fpmath_string, "387,sse")
3131                || ! strcmp (ix86_fpmath_string, "387+sse")
3132                || ! strcmp (ix86_fpmath_string, "sse,387")
3133                || ! strcmp (ix86_fpmath_string, "sse+387")
3134                || ! strcmp (ix86_fpmath_string, "both"))
3135         {
3136           if (!TARGET_SSE)
3137             {
3138               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3139               ix86_fpmath = FPMATH_387;
3140             }
3141           else if (!TARGET_80387)
3142             {
3143               warning (0, "387 instruction set disabled, using SSE arithmetics");
3144               ix86_fpmath = FPMATH_SSE;
3145             }
3146           else
3147             ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
3148         }
3149       else
3150         error ("bad value (%s) for %sfpmath=%s %s",
3151                ix86_fpmath_string, prefix, suffix, sw);
3152     }
3153
3154   /* If the i387 is disabled, then do not return values in it. */
3155   if (!TARGET_80387)
3156     target_flags &= ~MASK_FLOAT_RETURNS;
3157
3158   /* Use external vectorized library in vectorizing intrinsics.  */
3159   if (ix86_veclibabi_string)
3160     {
3161       if (strcmp (ix86_veclibabi_string, "svml") == 0)
3162         ix86_veclib_handler = ix86_veclibabi_svml;
3163       else if (strcmp (ix86_veclibabi_string, "acml") == 0)
3164         ix86_veclib_handler = ix86_veclibabi_acml;
3165       else
3166         error ("unknown vectorization library ABI type (%s) for "
3167                "%sveclibabi=%s %s", ix86_veclibabi_string,
3168                prefix, suffix, sw);
3169     }
3170
3171   if ((x86_accumulate_outgoing_args & ix86_tune_mask)
3172       && !(target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3173       && !optimize_size)
3174     target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3175
3176   /* ??? Unwind info is not correct around the CFG unless either a frame
3177      pointer is present or M_A_O_A is set.  Fixing this requires rewriting
3178      unwind info generation to be aware of the CFG and propagating states
3179      around edges.  */
3180   if ((flag_unwind_tables || flag_asynchronous_unwind_tables
3181        || flag_exceptions || flag_non_call_exceptions)
3182       && flag_omit_frame_pointer
3183       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3184     {
3185       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3186         warning (0, "unwind tables currently require either a frame pointer "
3187                  "or %saccumulate-outgoing-args%s for correctness",
3188                  prefix, suffix);
3189       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3190     }
3191
3192   /* If stack probes are required, the space used for large function
3193      arguments on the stack must also be probed, so enable
3194      -maccumulate-outgoing-args so this happens in the prologue.  */
3195   if (TARGET_STACK_PROBE
3196       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3197     {
3198       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3199         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
3200                  "for correctness", prefix, suffix);
3201       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3202     }
3203
3204   /* For sane SSE instruction set generation we need fcomi instruction.
3205      It is safe to enable all CMOVE instructions.  */
3206   if (TARGET_SSE)
3207     TARGET_CMOVE = 1;
3208
3209   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
3210   {
3211     char *p;
3212     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
3213     p = strchr (internal_label_prefix, 'X');
3214     internal_label_prefix_len = p - internal_label_prefix;
3215     *p = '\0';
3216   }
3217
3218   /* When scheduling description is not available, disable scheduler pass
3219      so it won't slow down the compilation and make x87 code slower.  */
3220   if (!TARGET_SCHEDULE)
3221     flag_schedule_insns_after_reload = flag_schedule_insns = 0;
3222
3223   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
3224     set_param_value ("simultaneous-prefetches",
3225                      ix86_cost->simultaneous_prefetches);
3226   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
3227     set_param_value ("l1-cache-line-size", ix86_cost->prefetch_block);
3228   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
3229     set_param_value ("l1-cache-size", ix86_cost->l1_cache_size);
3230   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
3231     set_param_value ("l2-cache-size", ix86_cost->l2_cache_size);
3232
3233   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
3234      can be optimized to ap = __builtin_next_arg (0).  */
3235   if (!TARGET_64BIT)
3236     targetm.expand_builtin_va_start = NULL;
3237
3238   if (TARGET_64BIT)
3239     {
3240       ix86_gen_leave = gen_leave_rex64;
3241       ix86_gen_pop1 = gen_popdi1;
3242       ix86_gen_add3 = gen_adddi3;
3243       ix86_gen_sub3 = gen_subdi3;
3244       ix86_gen_sub3_carry = gen_subdi3_carry_rex64;
3245       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
3246       ix86_gen_monitor = gen_sse3_monitor64;
3247       ix86_gen_andsp = gen_anddi3;
3248     }
3249   else
3250     {
3251       ix86_gen_leave = gen_leave;
3252       ix86_gen_pop1 = gen_popsi1;
3253       ix86_gen_add3 = gen_addsi3;
3254       ix86_gen_sub3 = gen_subsi3;
3255       ix86_gen_sub3_carry = gen_subsi3_carry;
3256       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
3257       ix86_gen_monitor = gen_sse3_monitor;
3258       ix86_gen_andsp = gen_andsi3;
3259     }
3260
3261 #ifdef USE_IX86_CLD
3262   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
3263   if (!TARGET_64BIT)
3264     target_flags |= MASK_CLD & ~target_flags_explicit;
3265 #endif
3266
3267   /* Save the initial options in case the user does function specific options */
3268   if (main_args_p)
3269     target_option_default_node = target_option_current_node
3270       = build_target_option_node ();
3271 }
3272 \f
3273 /* Save the current options */
3274
3275 static void
3276 ix86_function_specific_save (struct cl_target_option *ptr)
3277 {
3278   gcc_assert (IN_RANGE (ix86_arch, 0, 255));
3279   gcc_assert (IN_RANGE (ix86_tune, 0, 255));
3280   gcc_assert (IN_RANGE (ix86_fpmath, 0, 255));
3281   gcc_assert (IN_RANGE (ix86_branch_cost, 0, 255));
3282
3283   ptr->arch = ix86_arch;
3284   ptr->tune = ix86_tune;
3285   ptr->fpmath = ix86_fpmath;
3286   ptr->branch_cost = ix86_branch_cost;
3287   ptr->tune_defaulted = ix86_tune_defaulted;
3288   ptr->arch_specified = ix86_arch_specified;
3289   ptr->ix86_isa_flags_explicit = ix86_isa_flags_explicit;
3290   ptr->target_flags_explicit = target_flags_explicit;
3291 }
3292
3293 /* Restore the current options */
3294
3295 static void
3296 ix86_function_specific_restore (struct cl_target_option *ptr)
3297 {
3298   enum processor_type old_tune = ix86_tune;
3299   enum processor_type old_arch = ix86_arch;
3300   unsigned int ix86_arch_mask, ix86_tune_mask;
3301   int i;
3302
3303   ix86_arch = ptr->arch;
3304   ix86_tune = ptr->tune;
3305   ix86_fpmath = ptr->fpmath;
3306   ix86_branch_cost = ptr->branch_cost;
3307   ix86_tune_defaulted = ptr->tune_defaulted;
3308   ix86_arch_specified = ptr->arch_specified;
3309   ix86_isa_flags_explicit = ptr->ix86_isa_flags_explicit;
3310   target_flags_explicit = ptr->target_flags_explicit;
3311
3312   /* Recreate the arch feature tests if the arch changed */
3313   if (old_arch != ix86_arch)
3314     {
3315       ix86_arch_mask = 1u << ix86_arch;
3316       for (i = 0; i < X86_ARCH_LAST; ++i)
3317         ix86_arch_features[i]
3318           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3319     }
3320
3321   /* Recreate the tune optimization tests */
3322   if (old_tune != ix86_tune)
3323     {
3324       ix86_tune_mask = 1u << ix86_tune;
3325       for (i = 0; i < X86_TUNE_LAST; ++i)
3326         ix86_tune_features[i]
3327           = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3328     }
3329 }
3330
3331 /* Print the current options */
3332
3333 static void
3334 ix86_function_specific_print (FILE *file, int indent,
3335                               struct cl_target_option *ptr)
3336 {
3337   char *target_string
3338     = ix86_target_string (ptr->ix86_isa_flags, ptr->target_flags,
3339                           NULL, NULL, NULL, false);
3340
3341   fprintf (file, "%*sarch = %d (%s)\n",
3342            indent, "",
3343            ptr->arch,
3344            ((ptr->arch < TARGET_CPU_DEFAULT_max)
3345             ? cpu_names[ptr->arch]
3346             : "<unknown>"));
3347
3348   fprintf (file, "%*stune = %d (%s)\n",
3349            indent, "",
3350            ptr->tune,
3351            ((ptr->tune < TARGET_CPU_DEFAULT_max)
3352             ? cpu_names[ptr->tune]
3353             : "<unknown>"));
3354
3355   fprintf (file, "%*sfpmath = %d%s%s\n", indent, "", ptr->fpmath,
3356            (ptr->fpmath & FPMATH_387) ? ", 387" : "",
3357            (ptr->fpmath & FPMATH_SSE) ? ", sse" : "");
3358   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
3359
3360   if (target_string)
3361     {
3362       fprintf (file, "%*s%s\n", indent, "", target_string);
3363       free (target_string);
3364     }
3365 }
3366
3367 \f
3368 /* Inner function to process the attribute((target(...))), take an argument and
3369    set the current options from the argument. If we have a list, recursively go
3370    over the list.  */
3371
3372 static bool
3373 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[])
3374 {
3375   char *next_optstr;
3376   bool ret = true;
3377
3378 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
3379 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
3380 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
3381 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
3382
3383   enum ix86_opt_type
3384   {
3385     ix86_opt_unknown,
3386     ix86_opt_yes,
3387     ix86_opt_no,
3388     ix86_opt_str,
3389     ix86_opt_isa
3390   };
3391
3392   static const struct
3393   {
3394     const char *string;
3395     size_t len;
3396     enum ix86_opt_type type;
3397     int opt;
3398     int mask;
3399   } attrs[] = {
3400     /* isa options */
3401     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
3402     IX86_ATTR_ISA ("abm",       OPT_mabm),
3403     IX86_ATTR_ISA ("aes",       OPT_maes),
3404     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
3405     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
3406     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
3407     IX86_ATTR_ISA ("sse",       OPT_msse),
3408     IX86_ATTR_ISA ("sse2",      OPT_msse2),
3409     IX86_ATTR_ISA ("sse3",      OPT_msse3),
3410     IX86_ATTR_ISA ("sse4",      OPT_msse4),
3411     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
3412     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
3413     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
3414     IX86_ATTR_ISA ("sse5",      OPT_msse5),
3415     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
3416
3417     /* string options */
3418     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
3419     IX86_ATTR_STR ("fpmath=",   IX86_FUNCTION_SPECIFIC_FPMATH),
3420     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
3421
3422     /* flag options */
3423     IX86_ATTR_YES ("cld",
3424                    OPT_mcld,
3425                    MASK_CLD),
3426
3427     IX86_ATTR_NO ("fancy-math-387",
3428                   OPT_mfancy_math_387,
3429                   MASK_NO_FANCY_MATH_387),
3430
3431     IX86_ATTR_NO ("fused-madd",
3432                   OPT_mfused_madd,
3433                   MASK_NO_FUSED_MADD),
3434
3435     IX86_ATTR_YES ("ieee-fp",
3436                    OPT_mieee_fp,
3437                    MASK_IEEE_FP),
3438
3439     IX86_ATTR_YES ("inline-all-stringops",
3440                    OPT_minline_all_stringops,
3441                    MASK_INLINE_ALL_STRINGOPS),
3442
3443     IX86_ATTR_YES ("inline-stringops-dynamically",
3444                    OPT_minline_stringops_dynamically,
3445                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
3446
3447     IX86_ATTR_NO ("align-stringops",
3448                   OPT_mno_align_stringops,
3449                   MASK_NO_ALIGN_STRINGOPS),
3450
3451     IX86_ATTR_YES ("recip",
3452                    OPT_mrecip,
3453                    MASK_RECIP),
3454
3455   };
3456
3457   /* If this is a list, recurse to get the options.  */
3458   if (TREE_CODE (args) == TREE_LIST)
3459     {
3460       bool ret = true;
3461
3462       for (; args; args = TREE_CHAIN (args))
3463         if (TREE_VALUE (args)
3464             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args), p_strings))
3465           ret = false;
3466
3467       return ret;
3468     }
3469
3470   else if (TREE_CODE (args) != STRING_CST)
3471     gcc_unreachable ();
3472
3473   /* Handle multiple arguments separated by commas.  */
3474   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
3475
3476   while (next_optstr && *next_optstr != '\0')
3477     {
3478       char *p = next_optstr;
3479       char *orig_p = p;
3480       char *comma = strchr (next_optstr, ',');
3481       const char *opt_string;
3482       size_t len, opt_len;
3483       int opt;
3484       bool opt_set_p;
3485       char ch;
3486       unsigned i;
3487       enum ix86_opt_type type = ix86_opt_unknown;
3488       int mask = 0;
3489
3490       if (comma)
3491         {
3492           *comma = '\0';
3493           len = comma - next_optstr;
3494           next_optstr = comma + 1;
3495         }
3496       else
3497         {
3498           len = strlen (p);
3499           next_optstr = NULL;
3500         }
3501
3502       /* Recognize no-xxx.  */
3503       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
3504         {
3505           opt_set_p = false;
3506           p += 3;
3507           len -= 3;
3508         }
3509       else
3510         opt_set_p = true;
3511
3512       /* Find the option.  */
3513       ch = *p;
3514       opt = N_OPTS;
3515       for (i = 0; i < sizeof (attrs) / sizeof (attrs[0]); i++)
3516         {
3517           type = attrs[i].type;
3518           opt_len = attrs[i].len;
3519           if (ch == attrs[i].string[0]
3520               && ((type != ix86_opt_str) ? len == opt_len : len > opt_len)
3521               && memcmp (p, attrs[i].string, opt_len) == 0)
3522             {
3523               opt = attrs[i].opt;
3524               mask = attrs[i].mask;
3525               opt_string = attrs[i].string;
3526               break;
3527             }
3528         }
3529
3530       /* Process the option.  */
3531       if (opt == N_OPTS)
3532         {
3533           error ("attribute(target(\"%s\")) is unknown", orig_p);
3534           ret = false;
3535         }
3536
3537       else if (type == ix86_opt_isa)
3538         ix86_handle_option (opt, p, opt_set_p);
3539
3540       else if (type == ix86_opt_yes || type == ix86_opt_no)
3541         {
3542           if (type == ix86_opt_no)
3543             opt_set_p = !opt_set_p;
3544
3545           if (opt_set_p)
3546             target_flags |= mask;
3547           else
3548             target_flags &= ~mask;
3549         }
3550
3551       else if (type == ix86_opt_str)
3552         {
3553           if (p_strings[opt])
3554             {
3555               error ("option(\"%s\") was already specified", opt_string);
3556               ret = false;
3557             }
3558           else
3559             p_strings[opt] = xstrdup (p + opt_len);
3560         }
3561
3562       else
3563         gcc_unreachable ();
3564     }
3565
3566   return ret;
3567 }
3568
3569 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
3570
3571 tree
3572 ix86_valid_target_attribute_tree (tree args)
3573 {
3574   const char *orig_arch_string = ix86_arch_string;
3575   const char *orig_tune_string = ix86_tune_string;
3576   const char *orig_fpmath_string = ix86_fpmath_string;
3577   int orig_tune_defaulted = ix86_tune_defaulted;
3578   int orig_arch_specified = ix86_arch_specified;
3579   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL, NULL };
3580   tree t = NULL_TREE;
3581   int i;
3582   struct cl_target_option *def
3583     = TREE_TARGET_OPTION (target_option_default_node);
3584
3585   /* Process each of the options on the chain.  */
3586   if (! ix86_valid_target_attribute_inner_p (args, option_strings))
3587     return NULL_TREE;
3588
3589   /* If the changed options are different from the default, rerun override_options,
3590      and then save the options away.  The string options are are attribute options,
3591      and will be undone when we copy the save structure.  */
3592   if (ix86_isa_flags != def->ix86_isa_flags
3593       || target_flags != def->target_flags
3594       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
3595       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
3596       || option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3597     {
3598       /* If we are using the default tune= or arch=, undo the string assigned,
3599          and use the default.  */
3600       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
3601         ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
3602       else if (!orig_arch_specified)
3603         ix86_arch_string = NULL;
3604
3605       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
3606         ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
3607       else if (orig_tune_defaulted)
3608         ix86_tune_string = NULL;
3609
3610       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
3611       if (option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3612         ix86_fpmath_string = option_strings[IX86_FUNCTION_SPECIFIC_FPMATH];
3613       else if (!TARGET_64BIT && TARGET_SSE)
3614         ix86_fpmath_string = "sse,387";
3615
3616       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
3617       override_options (false);
3618
3619       /* Add any builtin functions with the new isa if any.  */
3620       ix86_add_new_builtins (ix86_isa_flags);
3621
3622       /* Save the current options unless we are validating options for
3623          #pragma.  */
3624       t = build_target_option_node ();
3625
3626       ix86_arch_string = orig_arch_string;
3627       ix86_tune_string = orig_tune_string;
3628       ix86_fpmath_string = orig_fpmath_string;
3629
3630       /* Free up memory allocated to hold the strings */
3631       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
3632         if (option_strings[i])
3633           free (option_strings[i]);
3634     }
3635
3636   return t;
3637 }
3638
3639 /* Hook to validate attribute((target("string"))).  */
3640
3641 static bool
3642 ix86_valid_target_attribute_p (tree fndecl,
3643                                tree ARG_UNUSED (name),
3644                                tree args,
3645                                int ARG_UNUSED (flags))
3646 {
3647   struct cl_target_option cur_target;
3648   bool ret = true;
3649   tree old_optimize = build_optimization_node ();
3650   tree new_target, new_optimize;
3651   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
3652
3653   /* If the function changed the optimization levels as well as setting target
3654      options, start with the optimizations specified.  */
3655   if (func_optimize && func_optimize != old_optimize)
3656     cl_optimization_restore (TREE_OPTIMIZATION (func_optimize));
3657
3658   /* The target attributes may also change some optimization flags, so update
3659      the optimization options if necessary.  */
3660   cl_target_option_save (&cur_target);
3661   new_target = ix86_valid_target_attribute_tree (args);
3662   new_optimize = build_optimization_node ();
3663
3664   if (!new_target)
3665     ret = false;
3666
3667   else if (fndecl)
3668     {
3669       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
3670
3671       if (old_optimize != new_optimize)
3672         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
3673     }
3674
3675   cl_target_option_restore (&cur_target);
3676
3677   if (old_optimize != new_optimize)
3678     cl_optimization_restore (TREE_OPTIMIZATION (old_optimize));
3679
3680   return ret;
3681 }
3682
3683 \f
3684 /* Hook to determine if one function can safely inline another.  */
3685
3686 static bool
3687 ix86_can_inline_p (tree caller, tree callee)
3688 {
3689   bool ret = false;
3690   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
3691   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
3692
3693   /* If callee has no option attributes, then it is ok to inline.  */
3694   if (!callee_tree)
3695     ret = true;
3696
3697   /* If caller has no option attributes, but callee does then it is not ok to
3698      inline.  */
3699   else if (!caller_tree)
3700     ret = false;
3701
3702   else
3703     {
3704       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
3705       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
3706
3707       /* Callee's isa options should a subset of the caller's, i.e. a SSE5 function
3708          can inline a SSE2 function but a SSE2 function can't inline a SSE5
3709          function.  */
3710       if ((caller_opts->ix86_isa_flags & callee_opts->ix86_isa_flags)
3711           != callee_opts->ix86_isa_flags)
3712         ret = false;
3713
3714       /* See if we have the same non-isa options.  */
3715       else if (caller_opts->target_flags != callee_opts->target_flags)
3716         ret = false;
3717
3718       /* See if arch, tune, etc. are the same.  */
3719       else if (caller_opts->arch != callee_opts->arch)
3720         ret = false;
3721
3722       else if (caller_opts->tune != callee_opts->tune)
3723         ret = false;
3724
3725       else if (caller_opts->fpmath != callee_opts->fpmath)
3726         ret = false;
3727
3728       else if (caller_opts->branch_cost != callee_opts->branch_cost)
3729         ret = false;
3730
3731       else
3732         ret = true;
3733     }
3734
3735   return ret;
3736 }
3737
3738 \f
3739 /* Remember the last target of ix86_set_current_function.  */
3740 static GTY(()) tree ix86_previous_fndecl;
3741
3742 /* Establish appropriate back-end context for processing the function
3743    FNDECL.  The argument might be NULL to indicate processing at top
3744    level, outside of any function scope.  */
3745 static void
3746 ix86_set_current_function (tree fndecl)
3747 {
3748   /* Only change the context if the function changes.  This hook is called
3749      several times in the course of compiling a function, and we don't want to
3750      slow things down too much or call target_reinit when it isn't safe.  */
3751   if (fndecl && fndecl != ix86_previous_fndecl)
3752     {
3753       tree old_tree = (ix86_previous_fndecl
3754                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
3755                        : NULL_TREE);
3756
3757       tree new_tree = (fndecl
3758                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
3759                        : NULL_TREE);
3760
3761       ix86_previous_fndecl = fndecl;
3762       if (old_tree == new_tree)
3763         ;
3764
3765       else if (new_tree)
3766         {
3767           cl_target_option_restore (TREE_TARGET_OPTION (new_tree));
3768           target_reinit ();
3769         }
3770
3771       else if (old_tree)
3772         {
3773           struct cl_target_option *def
3774             = TREE_TARGET_OPTION (target_option_current_node);
3775
3776           cl_target_option_restore (def);
3777           target_reinit ();
3778         }
3779     }
3780 }
3781
3782 \f
3783 /* Return true if this goes in large data/bss.  */
3784
3785 static bool
3786 ix86_in_large_data_p (tree exp)
3787 {
3788   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
3789     return false;
3790
3791   /* Functions are never large data.  */
3792   if (TREE_CODE (exp) == FUNCTION_DECL)
3793     return false;
3794
3795   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
3796     {
3797       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
3798       if (strcmp (section, ".ldata") == 0
3799           || strcmp (section, ".lbss") == 0)
3800         return true;
3801       return false;
3802     }
3803   else
3804     {
3805       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3806
3807       /* If this is an incomplete type with size 0, then we can't put it
3808          in data because it might be too big when completed.  */
3809       if (!size || size > ix86_section_threshold)
3810         return true;
3811     }
3812
3813   return false;
3814 }
3815
3816 /* Switch to the appropriate section for output of DECL.
3817    DECL is either a `VAR_DECL' node or a constant of some sort.
3818    RELOC indicates whether forming the initial value of DECL requires
3819    link-time relocations.  */
3820
3821 static section * x86_64_elf_select_section (tree, int, unsigned HOST_WIDE_INT)
3822         ATTRIBUTE_UNUSED;
3823
3824 static section *
3825 x86_64_elf_select_section (tree decl, int reloc,
3826                            unsigned HOST_WIDE_INT align)
3827 {
3828   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3829       && ix86_in_large_data_p (decl))
3830     {
3831       const char *sname = NULL;
3832       unsigned int flags = SECTION_WRITE;
3833       switch (categorize_decl_for_section (decl, reloc))
3834         {
3835         case SECCAT_DATA:
3836           sname = ".ldata";
3837           break;
3838         case SECCAT_DATA_REL:
3839           sname = ".ldata.rel";
3840           break;
3841         case SECCAT_DATA_REL_LOCAL:
3842           sname = ".ldata.rel.local";
3843           break;
3844         case SECCAT_DATA_REL_RO:
3845           sname = ".ldata.rel.ro";
3846           break;
3847         case SECCAT_DATA_REL_RO_LOCAL:
3848           sname = ".ldata.rel.ro.local";
3849           break;
3850         case SECCAT_BSS:
3851           sname = ".lbss";
3852           flags |= SECTION_BSS;
3853           break;
3854         case SECCAT_RODATA:
3855         case SECCAT_RODATA_MERGE_STR:
3856         case SECCAT_RODATA_MERGE_STR_INIT:
3857         case SECCAT_RODATA_MERGE_CONST:
3858           sname = ".lrodata";
3859           flags = 0;
3860           break;
3861         case SECCAT_SRODATA:
3862         case SECCAT_SDATA:
3863         case SECCAT_SBSS:
3864           gcc_unreachable ();
3865         case SECCAT_TEXT:
3866         case SECCAT_TDATA:
3867         case SECCAT_TBSS:
3868           /* We don't split these for medium model.  Place them into
3869              default sections and hope for best.  */
3870           break;
3871         case SECCAT_EMUTLS_VAR:
3872         case SECCAT_EMUTLS_TMPL:
3873           gcc_unreachable ();
3874         }
3875       if (sname)
3876         {
3877           /* We might get called with string constants, but get_named_section
3878              doesn't like them as they are not DECLs.  Also, we need to set
3879              flags in that case.  */
3880           if (!DECL_P (decl))
3881             return get_section (sname, flags, NULL);
3882           return get_named_section (decl, sname, reloc);
3883         }
3884     }
3885   return default_elf_select_section (decl, reloc, align);
3886 }
3887
3888 /* Build up a unique section name, expressed as a
3889    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
3890    RELOC indicates whether the initial value of EXP requires
3891    link-time relocations.  */
3892
3893 static void ATTRIBUTE_UNUSED
3894 x86_64_elf_unique_section (tree decl, int reloc)
3895 {
3896   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3897       && ix86_in_large_data_p (decl))
3898     {
3899       const char *prefix = NULL;
3900       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
3901       bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
3902
3903       switch (categorize_decl_for_section (decl, reloc))
3904         {
3905         case SECCAT_DATA:
3906         case SECCAT_DATA_REL:
3907         case SECCAT_DATA_REL_LOCAL:
3908         case SECCAT_DATA_REL_RO:
3909         case SECCAT_DATA_REL_RO_LOCAL:
3910           prefix = one_only ? ".ld" : ".ldata";
3911           break;
3912         case SECCAT_BSS:
3913           prefix = one_only ? ".lb" : ".lbss";
3914           break;
3915         case SECCAT_RODATA:
3916         case SECCAT_RODATA_MERGE_STR:
3917         case SECCAT_RODATA_MERGE_STR_INIT:
3918         case SECCAT_RODATA_MERGE_CONST:
3919           prefix = one_only ? ".lr" : ".lrodata";
3920           break;
3921         case SECCAT_SRODATA:
3922         case SECCAT_SDATA:
3923         case SECCAT_SBSS:
3924           gcc_unreachable ();
3925         case SECCAT_TEXT:
3926         case SECCAT_TDATA:
3927         case SECCAT_TBSS:
3928           /* We don't split these for medium model.  Place them into
3929              default sections and hope for best.  */
3930           break;
3931         case SECCAT_EMUTLS_VAR:
3932           prefix = targetm.emutls.var_section;
3933           break;
3934         case SECCAT_EMUTLS_TMPL:
3935           prefix = targetm.emutls.tmpl_section;
3936           break;
3937         }
3938       if (prefix)
3939         {
3940           const char *name, *linkonce;
3941           char *string;
3942
3943           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
3944           name = targetm.strip_name_encoding (name);
3945           
3946           /* If we're using one_only, then there needs to be a .gnu.linkonce
3947              prefix to the section name.  */
3948           linkonce = one_only ? ".gnu.linkonce" : "";
3949   
3950           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
3951           
3952           DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
3953           return;
3954         }
3955     }
3956   default_unique_section (decl, reloc);
3957 }
3958
3959 #ifdef COMMON_ASM_OP
3960 /* This says how to output assembler code to declare an
3961    uninitialized external linkage data object.
3962
3963    For medium model x86-64 we need to use .largecomm opcode for
3964    large objects.  */
3965 void
3966 x86_elf_aligned_common (FILE *file,
3967                         const char *name, unsigned HOST_WIDE_INT size,
3968                         int align)
3969 {
3970   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3971       && size > (unsigned int)ix86_section_threshold)
3972     fprintf (file, ".largecomm\t");
3973   else
3974     fprintf (file, "%s", COMMON_ASM_OP);
3975   assemble_name (file, name);
3976   fprintf (file, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",
3977            size, align / BITS_PER_UNIT);
3978 }
3979 #endif
3980
3981 /* Utility function for targets to use in implementing
3982    ASM_OUTPUT_ALIGNED_BSS.  */
3983
3984 void
3985 x86_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
3986                         const char *name, unsigned HOST_WIDE_INT size,
3987                         int align)
3988 {
3989   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3990       && size > (unsigned int)ix86_section_threshold)
3991     switch_to_section (get_named_section (decl, ".lbss", 0));
3992   else
3993     switch_to_section (bss_section);
3994   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
3995 #ifdef ASM_DECLARE_OBJECT_NAME
3996   last_assemble_variable_decl = decl;
3997   ASM_DECLARE_OBJECT_NAME (file, name, decl);
3998 #else
3999   /* Standard thing is just output label for the object.  */
4000   ASM_OUTPUT_LABEL (file, name);
4001 #endif /* ASM_DECLARE_OBJECT_NAME */
4002   ASM_OUTPUT_SKIP (file, size ? size : 1);
4003 }
4004 \f
4005 void
4006 optimization_options (int level, int size ATTRIBUTE_UNUSED)
4007 {
4008   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
4009      make the problem with not enough registers even worse.  */
4010 #ifdef INSN_SCHEDULING
4011   if (level > 1)
4012     flag_schedule_insns = 0;
4013 #endif
4014
4015   if (TARGET_MACHO)
4016     /* The Darwin libraries never set errno, so we might as well
4017        avoid calling them when that's the only reason we would.  */
4018     flag_errno_math = 0;
4019
4020   /* The default values of these switches depend on the TARGET_64BIT
4021      that is not known at this moment.  Mark these values with 2 and
4022      let user the to override these.  In case there is no command line option
4023      specifying them, we will set the defaults in override_options.  */
4024   if (optimize >= 1)
4025     flag_omit_frame_pointer = 2;
4026   flag_pcc_struct_return = 2;
4027   flag_asynchronous_unwind_tables = 2;
4028   flag_vect_cost_model = 1;
4029 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
4030   SUBTARGET_OPTIMIZATION_OPTIONS;
4031 #endif
4032 }
4033 \f
4034 /* Decide whether we can make a sibling call to a function.  DECL is the
4035    declaration of the function being targeted by the call and EXP is the
4036    CALL_EXPR representing the call.  */
4037
4038 static bool
4039 ix86_function_ok_for_sibcall (tree decl, tree exp)
4040 {
4041   tree func;
4042   rtx a, b;
4043
4044   /* If we are generating position-independent code, we cannot sibcall
4045      optimize any indirect call, or a direct call to a global function,
4046      as the PLT requires %ebx be live.  */
4047   if (!TARGET_64BIT && flag_pic && (!decl || !targetm.binds_local_p (decl)))
4048     return false;
4049
4050   if (decl)
4051     func = decl;
4052   else
4053     {
4054       func = TREE_TYPE (CALL_EXPR_FN (exp));
4055       if (POINTER_TYPE_P (func))
4056         func = TREE_TYPE (func);
4057     }
4058
4059   /* Check that the return value locations are the same.  Like
4060      if we are returning floats on the 80387 register stack, we cannot
4061      make a sibcall from a function that doesn't return a float to a
4062      function that does or, conversely, from a function that does return
4063      a float to a function that doesn't; the necessary stack adjustment
4064      would not be executed.  This is also the place we notice
4065      differences in the return value ABI.  Note that it is ok for one
4066      of the functions to have void return type as long as the return
4067      value of the other is passed in a register.  */
4068   a = ix86_function_value (TREE_TYPE (exp), func, false);
4069   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
4070                            cfun->decl, false);
4071   if (STACK_REG_P (a) || STACK_REG_P (b))
4072     {
4073       if (!rtx_equal_p (a, b))
4074         return false;
4075     }
4076   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
4077     ;
4078   else if (!rtx_equal_p (a, b))
4079     return false;
4080
4081   /* If this call is indirect, we'll need to be able to use a call-clobbered
4082      register for the address of the target function.  Make sure that all
4083      such registers are not used for passing parameters.  */
4084   if (!decl && !TARGET_64BIT)
4085     {
4086       tree type;
4087
4088       /* We're looking at the CALL_EXPR, we need the type of the function.  */
4089       type = CALL_EXPR_FN (exp);                /* pointer expression */
4090       type = TREE_TYPE (type);                  /* pointer type */
4091       type = TREE_TYPE (type);                  /* function type */
4092
4093       if (ix86_function_regparm (type, NULL) >= 3)
4094         {
4095           /* ??? Need to count the actual number of registers to be used,
4096              not the possible number of registers.  Fix later.  */
4097           return false;
4098         }
4099     }
4100
4101   /* Dllimport'd functions are also called indirectly.  */
4102   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
4103       && !TARGET_64BIT
4104       && decl && DECL_DLLIMPORT_P (decl)
4105       && ix86_function_regparm (TREE_TYPE (decl), NULL) >= 3)
4106     return false;
4107
4108   /* Otherwise okay.  That also includes certain types of indirect calls.  */
4109   return true;
4110 }
4111
4112 /* Handle "cdecl", "stdcall", "fastcall", "regparm" and "sseregparm"
4113    calling convention attributes;
4114    arguments as in struct attribute_spec.handler.  */
4115
4116 static tree
4117 ix86_handle_cconv_attribute (tree *node, tree name,
4118                                    tree args,
4119                                    int flags ATTRIBUTE_UNUSED,
4120                                    bool *no_add_attrs)
4121 {
4122   if (TREE_CODE (*node) != FUNCTION_TYPE
4123       && TREE_CODE (*node) != METHOD_TYPE
4124       && TREE_CODE (*node) != FIELD_DECL
4125       && TREE_CODE (*node) != TYPE_DECL)
4126     {
4127       warning (OPT_Wattributes, "%qs attribute only applies to functions",
4128                IDENTIFIER_POINTER (name));
4129       *no_add_attrs = true;
4130       return NULL_TREE;
4131     }
4132
4133   /* Can combine regparm with all attributes but fastcall.  */
4134   if (is_attribute_p ("regparm", name))
4135     {
4136       tree cst;
4137
4138       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4139         {
4140           error ("fastcall and regparm attributes are not compatible");
4141         }
4142
4143       cst = TREE_VALUE (args);
4144       if (TREE_CODE (cst) != INTEGER_CST)
4145         {
4146           warning (OPT_Wattributes,
4147                    "%qs attribute requires an integer constant argument",
4148                    IDENTIFIER_POINTER (name));
4149           *no_add_attrs = true;
4150         }
4151       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
4152         {
4153           warning (OPT_Wattributes, "argument to %qs attribute larger than %d",
4154                    IDENTIFIER_POINTER (name), REGPARM_MAX);
4155           *no_add_attrs = true;
4156         }
4157
4158       return NULL_TREE;
4159     }
4160
4161   if (TARGET_64BIT)
4162     {
4163       /* Do not warn when emulating the MS ABI.  */
4164       if (TREE_CODE (*node) != FUNCTION_TYPE || ix86_function_type_abi (*node)!=MS_ABI)
4165         warning (OPT_Wattributes, "%qs attribute ignored",
4166                  IDENTIFIER_POINTER (name));
4167       *no_add_attrs = true;
4168       return NULL_TREE;
4169     }
4170
4171   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
4172   if (is_attribute_p ("fastcall", name))
4173     {
4174       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4175         {
4176           error ("fastcall and cdecl attributes are not compatible");
4177         }
4178       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4179         {
4180           error ("fastcall and stdcall attributes are not compatible");
4181         }
4182       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
4183         {
4184           error ("fastcall and regparm attributes are not compatible");
4185         }
4186     }
4187
4188   /* Can combine stdcall with fastcall (redundant), regparm and
4189      sseregparm.  */
4190   else if (is_attribute_p ("stdcall", name))
4191     {
4192       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4193         {
4194           error ("stdcall and cdecl attributes are not compatible");
4195         }
4196       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4197         {
4198           error ("stdcall and fastcall attributes are not compatible");
4199         }
4200     }
4201
4202   /* Can combine cdecl with regparm and sseregparm.  */
4203   else if (is_attribute_p ("cdecl", name))
4204     {
4205       if (lookup_attribute ("stdcall", 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 ("fastcall and cdecl attributes are not compatible");
4212         }
4213     }
4214
4215   /* Can combine sseregparm with all attributes.  */
4216
4217   return NULL_TREE;
4218 }
4219
4220 /* Return 0 if the attributes for two types are incompatible, 1 if they
4221    are compatible, and 2 if they are nearly compatible (which causes a
4222    warning to be generated).  */
4223
4224 static int
4225 ix86_comp_type_attributes (const_tree type1, const_tree type2)
4226 {
4227   /* Check for mismatch of non-default calling convention.  */
4228   const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
4229
4230   if (TREE_CODE (type1) != FUNCTION_TYPE
4231       && TREE_CODE (type1) != METHOD_TYPE)
4232     return 1;
4233
4234   /* Check for mismatched fastcall/regparm types.  */
4235   if ((!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
4236        != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
4237       || (ix86_function_regparm (type1, NULL)
4238           != ix86_function_regparm (type2, NULL)))
4239     return 0;
4240
4241   /* Check for mismatched sseregparm types.  */
4242   if (!lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type1))
4243       != !lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type2)))
4244     return 0;
4245
4246   /* Check for mismatched return types (cdecl vs stdcall).  */
4247   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
4248       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
4249     return 0;
4250
4251   return 1;
4252 }
4253 \f
4254 /* Return the regparm value for a function with the indicated TYPE and DECL.
4255    DECL may be NULL when calling function indirectly
4256    or considering a libcall.  */
4257
4258 static int
4259 ix86_function_regparm (const_tree type, const_tree decl)
4260 {
4261   tree attr;
4262   int regparm = ix86_regparm;
4263
4264   static bool error_issued;
4265
4266   if (TARGET_64BIT)
4267     {
4268       if (ix86_function_type_abi (type) == DEFAULT_ABI)
4269         return regparm;
4270       return DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
4271     }
4272
4273   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
4274   if (attr)
4275     {
4276       regparm
4277         = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
4278
4279       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4280         {
4281           /* We can't use regparm(3) for nested functions because
4282              these pass static chain pointer in %ecx register.  */
4283           if (!error_issued && regparm == 3
4284               && decl_function_context (decl)
4285               && !DECL_NO_STATIC_CHAIN (decl))
4286             {
4287               error ("nested functions are limited to 2 register parameters");
4288               error_issued = true;
4289               return 0;
4290             }
4291         }
4292
4293       return regparm;
4294     }
4295
4296   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4297     return 2;
4298
4299   /* Use register calling convention for local functions when possible.  */
4300   if (decl && TREE_CODE (decl) == FUNCTION_DECL
4301       && !profile_flag)
4302     {
4303       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4304       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4305       if (i && i->local)
4306         {
4307           int local_regparm, globals = 0, regno;
4308           struct function *f;
4309
4310           /* Make sure no regparm register is taken by a
4311              fixed register variable.  */
4312           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4313             if (fixed_regs[local_regparm])
4314               break;
4315
4316           /* We can't use regparm(3) for nested functions as these use
4317              static chain pointer in third argument.  */
4318           if (local_regparm == 3
4319               && decl_function_context (decl)
4320               && !DECL_NO_STATIC_CHAIN (decl))
4321             local_regparm = 2;
4322
4323           /* If the function realigns its stackpointer, the prologue will
4324              clobber %ecx.  If we've already generated code for the callee,
4325              the callee DECL_STRUCT_FUNCTION is gone, so we fall back to
4326              scanning the attributes for the self-realigning property.  */
4327           f = DECL_STRUCT_FUNCTION (decl);
4328           /* Since current internal arg pointer won't conflict with
4329              parameter passing regs, so no need to change stack
4330              realignment and adjust regparm number.
4331
4332              Each fixed register usage increases register pressure,
4333              so less registers should be used for argument passing.
4334              This functionality can be overriden by an explicit
4335              regparm value.  */
4336           for (regno = 0; regno <= DI_REG; regno++)
4337             if (fixed_regs[regno])
4338               globals++;
4339
4340           local_regparm
4341             = globals < local_regparm ? local_regparm - globals : 0;
4342
4343           if (local_regparm > regparm)
4344             regparm = local_regparm;
4345         }
4346     }
4347
4348   return regparm;
4349 }
4350
4351 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
4352    DFmode (2) arguments in SSE registers for a function with the
4353    indicated TYPE and DECL.  DECL may be NULL when calling function
4354    indirectly or considering a libcall.  Otherwise return 0.  */
4355
4356 static int
4357 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
4358 {
4359   gcc_assert (!TARGET_64BIT);
4360
4361   /* Use SSE registers to pass SFmode and DFmode arguments if requested
4362      by the sseregparm attribute.  */
4363   if (TARGET_SSEREGPARM
4364       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
4365     {
4366       if (!TARGET_SSE)
4367         {
4368           if (warn)
4369             {
4370               if (decl)
4371                 error ("Calling %qD with attribute sseregparm without "
4372                        "SSE/SSE2 enabled", decl);
4373               else
4374                 error ("Calling %qT with attribute sseregparm without "
4375                        "SSE/SSE2 enabled", type);
4376             }
4377           return 0;
4378         }
4379
4380       return 2;
4381     }
4382
4383   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4384      (and DFmode for SSE2) arguments in SSE registers.  */
4385   if (decl && TARGET_SSE_MATH && !profile_flag)
4386     {
4387       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4388       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4389       if (i && i->local)
4390         return TARGET_SSE2 ? 2 : 1;
4391     }
4392
4393   return 0;
4394 }
4395
4396 /* Return true if EAX is live at the start of the function.  Used by
4397    ix86_expand_prologue to determine if we need special help before
4398    calling allocate_stack_worker.  */
4399
4400 static bool
4401 ix86_eax_live_at_start_p (void)
4402 {
4403   /* Cheat.  Don't bother working forward from ix86_function_regparm
4404      to the function type to whether an actual argument is located in
4405      eax.  Instead just look at cfg info, which is still close enough
4406      to correct at this point.  This gives false positives for broken
4407      functions that might use uninitialized data that happens to be
4408      allocated in eax, but who cares?  */
4409   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR), 0);
4410 }
4411
4412 /* Value is the number of bytes of arguments automatically
4413    popped when returning from a subroutine call.
4414    FUNDECL is the declaration node of the function (as a tree),
4415    FUNTYPE is the data type of the function (as a tree),
4416    or for a library call it is an identifier node for the subroutine name.
4417    SIZE is the number of bytes of arguments passed on the stack.
4418
4419    On the 80386, the RTD insn may be used to pop them if the number
4420      of args is fixed, but if the number is variable then the caller
4421      must pop them all.  RTD can't be used for library calls now
4422      because the library is compiled with the Unix compiler.
4423    Use of RTD is a selectable option, since it is incompatible with
4424    standard Unix calling sequences.  If the option is not selected,
4425    the caller must always pop the args.
4426
4427    The attribute stdcall is equivalent to RTD on a per module basis.  */
4428
4429 int
4430 ix86_return_pops_args (tree fundecl, tree funtype, int size)
4431 {
4432   int rtd;
4433
4434   /* None of the 64-bit ABIs pop arguments.  */
4435   if (TARGET_64BIT)
4436     return 0;
4437
4438   rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
4439
4440   /* Cdecl functions override -mrtd, and never pop the stack.  */
4441   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
4442     {
4443       /* Stdcall and fastcall functions will pop the stack if not
4444          variable args.  */
4445       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
4446           || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
4447         rtd = 1;
4448
4449       if (rtd && ! stdarg_p (funtype))
4450         return size;
4451     }
4452
4453   /* Lose any fake structure return argument if it is passed on the stack.  */
4454   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
4455       && !KEEP_AGGREGATE_RETURN_POINTER)
4456     {
4457       int nregs = ix86_function_regparm (funtype, fundecl);
4458       if (nregs == 0)
4459         return GET_MODE_SIZE (Pmode);
4460     }
4461
4462   return 0;
4463 }
4464 \f
4465 /* Argument support functions.  */
4466
4467 /* Return true when register may be used to pass function parameters.  */
4468 bool
4469 ix86_function_arg_regno_p (int regno)
4470 {
4471   int i;
4472   const int *parm_regs;
4473
4474   if (!TARGET_64BIT)
4475     {
4476       if (TARGET_MACHO)
4477         return (regno < REGPARM_MAX
4478                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
4479       else
4480         return (regno < REGPARM_MAX
4481                 || (TARGET_MMX && MMX_REGNO_P (regno)
4482                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
4483                 || (TARGET_SSE && SSE_REGNO_P (regno)
4484                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
4485     }
4486
4487   if (TARGET_MACHO)
4488     {
4489       if (SSE_REGNO_P (regno) && TARGET_SSE)
4490         return true;
4491     }
4492   else
4493     {
4494       if (TARGET_SSE && SSE_REGNO_P (regno)
4495           && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
4496         return true;
4497     }
4498
4499   /* TODO: The function should depend on current function ABI but
4500      builtins.c would need updating then. Therefore we use the
4501      default ABI.  */
4502
4503   /* RAX is used as hidden argument to va_arg functions.  */
4504   if (DEFAULT_ABI == SYSV_ABI && regno == AX_REG)
4505     return true;
4506
4507   if (DEFAULT_ABI == MS_ABI)
4508     parm_regs = x86_64_ms_abi_int_parameter_registers;
4509   else
4510     parm_regs = x86_64_int_parameter_registers;
4511   for (i = 0; i < (DEFAULT_ABI == MS_ABI ? X64_REGPARM_MAX
4512                                          : X86_64_REGPARM_MAX); i++)
4513     if (regno == parm_regs[i])
4514       return true;
4515   return false;
4516 }
4517
4518 /* Return if we do not know how to pass TYPE solely in registers.  */
4519
4520 static bool
4521 ix86_must_pass_in_stack (enum machine_mode mode, const_tree type)
4522 {
4523   if (must_pass_in_stack_var_size_or_pad (mode, type))
4524     return true;
4525
4526   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
4527      The layout_type routine is crafty and tries to trick us into passing
4528      currently unsupported vector types on the stack by using TImode.  */
4529   return (!TARGET_64BIT && mode == TImode
4530           && type && TREE_CODE (type) != VECTOR_TYPE);
4531 }
4532
4533 /* It returns the size, in bytes, of the area reserved for arguments passed
4534    in registers for the function represented by fndecl dependent to the used
4535    abi format.  */
4536 int
4537 ix86_reg_parm_stack_space (const_tree fndecl)
4538 {
4539   int call_abi = 0;
4540   /* For libcalls it is possible that there is no fndecl at hand.
4541      Therefore assume for this case the default abi of the target.  */
4542   if (!fndecl)
4543     call_abi = DEFAULT_ABI;
4544   else
4545     call_abi = ix86_function_abi (fndecl);
4546   if (call_abi == 1)
4547     return 32;
4548   return 0;
4549 }
4550
4551 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
4552    call abi used.  */
4553 int
4554 ix86_function_type_abi (const_tree fntype)
4555 {
4556   if (TARGET_64BIT && fntype != NULL)
4557     {
4558       int abi;
4559       if (DEFAULT_ABI == SYSV_ABI)
4560         abi = lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)) ? MS_ABI : SYSV_ABI;
4561       else
4562         abi = lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)) ? SYSV_ABI : MS_ABI;
4563
4564       return abi;
4565     }
4566   return DEFAULT_ABI;
4567 }
4568
4569 int
4570 ix86_function_abi (const_tree fndecl)
4571 {
4572   if (! fndecl)
4573     return DEFAULT_ABI;
4574   return ix86_function_type_abi (TREE_TYPE (fndecl));
4575 }
4576
4577 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
4578    call abi used.  */
4579 int
4580 ix86_cfun_abi (void)
4581 {
4582   if (! cfun || ! TARGET_64BIT)
4583     return DEFAULT_ABI;
4584   return cfun->machine->call_abi;
4585 }
4586
4587 /* regclass.c  */
4588 extern void init_regs (void);
4589
4590 /* Implementation of call abi switching target hook. Specific to FNDECL
4591    the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
4592    for more details.
4593    To prevent redudant calls of costy function init_regs (), it checks not to
4594    reset register usage for default abi.  */
4595 void
4596 ix86_call_abi_override (const_tree fndecl)
4597 {
4598   if (fndecl == NULL_TREE)
4599     cfun->machine->call_abi = DEFAULT_ABI;
4600   else
4601     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
4602   if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
4603     {
4604       if (call_used_regs[4 /*RSI*/] != 0 || call_used_regs[5 /*RDI*/] != 0)
4605         {
4606           call_used_regs[4 /*RSI*/] = 0;
4607           call_used_regs[5 /*RDI*/] = 0;
4608           init_regs ();
4609         }
4610     }
4611   else if (TARGET_64BIT)
4612     {
4613       if (call_used_regs[4 /*RSI*/] != 1 || call_used_regs[5 /*RDI*/] != 1)
4614         {
4615           call_used_regs[4 /*RSI*/] = 1;
4616           call_used_regs[5 /*RDI*/] = 1;
4617           init_regs ();
4618         }
4619     }
4620 }
4621
4622 /* Initialize a variable CUM of type CUMULATIVE_ARGS
4623    for a call to a function whose data type is FNTYPE.
4624    For a library call, FNTYPE is 0.  */
4625
4626 void
4627 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
4628                       tree fntype,      /* tree ptr for function decl */
4629                       rtx libname,      /* SYMBOL_REF of library name or 0 */
4630                       tree fndecl)
4631 {
4632   struct cgraph_local_info *i = fndecl ? cgraph_local_info (fndecl) : NULL;
4633   memset (cum, 0, sizeof (*cum));
4634
4635   cum->call_abi = ix86_function_type_abi (fntype);
4636   /* Set up the number of registers to use for passing arguments.  */
4637   cum->nregs = ix86_regparm;
4638   if (TARGET_64BIT)
4639     {
4640       if (cum->call_abi != DEFAULT_ABI)
4641         cum->nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX
4642                                              : X64_REGPARM_MAX;
4643     }
4644   if (TARGET_SSE)
4645     {
4646       cum->sse_nregs = SSE_REGPARM_MAX;
4647       if (TARGET_64BIT)
4648         {
4649           if (cum->call_abi != DEFAULT_ABI)
4650             cum->sse_nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
4651                                                      : X64_SSE_REGPARM_MAX;
4652         }
4653     }
4654   if (TARGET_MMX)
4655     cum->mmx_nregs = MMX_REGPARM_MAX;
4656   cum->warn_avx = true;
4657   cum->warn_sse = true;
4658   cum->warn_mmx = true;
4659
4660   /* Because type might mismatch in between caller and callee, we need to
4661      use actual type of function for local calls.
4662      FIXME: cgraph_analyze can be told to actually record if function uses
4663      va_start so for local functions maybe_vaarg can be made aggressive
4664      helping K&R code.
4665      FIXME: once typesytem is fixed, we won't need this code anymore.  */
4666   if (i && i->local)
4667     fntype = TREE_TYPE (fndecl);
4668   cum->maybe_vaarg = (fntype
4669                       ? (!prototype_p (fntype) || stdarg_p (fntype))
4670                       : !libname);
4671
4672   if (!TARGET_64BIT)
4673     {
4674       /* If there are variable arguments, then we won't pass anything
4675          in registers in 32-bit mode. */
4676       if (stdarg_p (fntype))
4677         {
4678           cum->nregs = 0;
4679           cum->sse_nregs = 0;
4680           cum->mmx_nregs = 0;
4681           cum->warn_avx = 0;
4682           cum->warn_sse = 0;
4683           cum->warn_mmx = 0;
4684           return;
4685         }
4686
4687       /* Use ecx and edx registers if function has fastcall attribute,
4688          else look for regparm information.  */
4689       if (fntype)
4690         {
4691           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
4692             {
4693               cum->nregs = 2;
4694               cum->fastcall = 1;
4695             }
4696           else
4697             cum->nregs = ix86_function_regparm (fntype, fndecl);
4698         }
4699
4700       /* Set up the number of SSE registers used for passing SFmode
4701          and DFmode arguments.  Warn for mismatching ABI.  */
4702       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
4703     }
4704 }
4705
4706 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
4707    But in the case of vector types, it is some vector mode.
4708
4709    When we have only some of our vector isa extensions enabled, then there
4710    are some modes for which vector_mode_supported_p is false.  For these
4711    modes, the generic vector support in gcc will choose some non-vector mode
4712    in order to implement the type.  By computing the natural mode, we'll
4713    select the proper ABI location for the operand and not depend on whatever
4714    the middle-end decides to do with these vector types.  */
4715
4716 static enum machine_mode
4717 type_natural_mode (const_tree type)
4718 {
4719   enum machine_mode mode = TYPE_MODE (type);
4720
4721   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
4722     {
4723       HOST_WIDE_INT size = int_size_in_bytes (type);
4724       if ((size == 8 || size == 16)
4725           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
4726           && TYPE_VECTOR_SUBPARTS (type) > 1)
4727         {
4728           enum machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
4729
4730           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4731             mode = MIN_MODE_VECTOR_FLOAT;
4732           else
4733             mode = MIN_MODE_VECTOR_INT;
4734
4735           /* Get the mode which has this inner mode and number of units.  */
4736           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
4737             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
4738                 && GET_MODE_INNER (mode) == innermode)
4739               return mode;
4740
4741           gcc_unreachable ();
4742         }
4743     }
4744
4745   return mode;
4746 }
4747
4748 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
4749    this may not agree with the mode that the type system has chosen for the
4750    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
4751    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
4752
4753 static rtx
4754 gen_reg_or_parallel (enum machine_mode mode, enum machine_mode orig_mode,
4755                      unsigned int regno)
4756 {
4757   rtx tmp;
4758
4759   if (orig_mode != BLKmode)
4760     tmp = gen_rtx_REG (orig_mode, regno);
4761   else
4762     {
4763       tmp = gen_rtx_REG (mode, regno);
4764       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
4765       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
4766     }
4767
4768   return tmp;
4769 }
4770
4771 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
4772    of this code is to classify each 8bytes of incoming argument by the register
4773    class and assign registers accordingly.  */
4774
4775 /* Return the union class of CLASS1 and CLASS2.
4776    See the x86-64 PS ABI for details.  */
4777
4778 static enum x86_64_reg_class
4779 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
4780 {
4781   /* Rule #1: If both classes are equal, this is the resulting class.  */
4782   if (class1 == class2)
4783     return class1;
4784
4785   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
4786      the other class.  */
4787   if (class1 == X86_64_NO_CLASS)
4788     return class2;
4789   if (class2 == X86_64_NO_CLASS)
4790     return class1;
4791
4792   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
4793   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
4794     return X86_64_MEMORY_CLASS;
4795
4796   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
4797   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
4798       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
4799     return X86_64_INTEGERSI_CLASS;
4800   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
4801       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
4802     return X86_64_INTEGER_CLASS;
4803
4804   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
4805      MEMORY is used.  */
4806   if (class1 == X86_64_X87_CLASS
4807       || class1 == X86_64_X87UP_CLASS
4808       || class1 == X86_64_COMPLEX_X87_CLASS
4809       || class2 == X86_64_X87_CLASS
4810       || class2 == X86_64_X87UP_CLASS
4811       || class2 == X86_64_COMPLEX_X87_CLASS)
4812     return X86_64_MEMORY_CLASS;
4813
4814   /* Rule #6: Otherwise class SSE is used.  */
4815   return X86_64_SSE_CLASS;
4816 }
4817
4818 /* Classify the argument of type TYPE and mode MODE.
4819    CLASSES will be filled by the register class used to pass each word
4820    of the operand.  The number of words is returned.  In case the parameter
4821    should be passed in memory, 0 is returned. As a special case for zero
4822    sized containers, classes[0] will be NO_CLASS and 1 is returned.
4823
4824    BIT_OFFSET is used internally for handling records and specifies offset
4825    of the offset in bits modulo 256 to avoid overflow cases.
4826
4827    See the x86-64 PS ABI for details.
4828 */
4829
4830 static int
4831 classify_argument (enum machine_mode mode, const_tree type,
4832                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
4833 {
4834   HOST_WIDE_INT bytes =
4835     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
4836   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4837
4838   /* Variable sized entities are always passed/returned in memory.  */
4839   if (bytes < 0)
4840     return 0;
4841
4842   if (mode != VOIDmode
4843       && targetm.calls.must_pass_in_stack (mode, type))
4844     return 0;
4845
4846   if (type && AGGREGATE_TYPE_P (type))
4847     {
4848       int i;
4849       tree field;
4850       enum x86_64_reg_class subclasses[MAX_CLASSES];
4851
4852       /* On x86-64 we pass structures larger than 16 bytes on the stack.  */
4853       if (bytes > 16)
4854         return 0;
4855
4856       for (i = 0; i < words; i++)
4857         classes[i] = X86_64_NO_CLASS;
4858
4859       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
4860          signalize memory class, so handle it as special case.  */
4861       if (!words)
4862         {
4863           classes[0] = X86_64_NO_CLASS;
4864           return 1;
4865         }
4866
4867       /* Classify each field of record and merge classes.  */
4868       switch (TREE_CODE (type))
4869         {
4870         case RECORD_TYPE:
4871           /* And now merge the fields of structure.  */
4872           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4873             {
4874               if (TREE_CODE (field) == FIELD_DECL)
4875                 {
4876                   int num;
4877
4878                   if (TREE_TYPE (field) == error_mark_node)
4879                     continue;
4880
4881                   /* Bitfields are always classified as integer.  Handle them
4882                      early, since later code would consider them to be
4883                      misaligned integers.  */
4884                   if (DECL_BIT_FIELD (field))
4885                     {
4886                       for (i = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4887                            i < ((int_bit_position (field) + (bit_offset % 64))
4888                                 + tree_low_cst (DECL_SIZE (field), 0)
4889                                 + 63) / 8 / 8; i++)
4890                         classes[i] =
4891                           merge_classes (X86_64_INTEGER_CLASS,
4892                                          classes[i]);
4893                     }
4894                   else
4895                     {
4896                       num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4897                                                TREE_TYPE (field), subclasses,
4898                                                (int_bit_position (field)
4899                                                 + bit_offset) % 256);
4900                       if (!num)
4901                         return 0;
4902                       for (i = 0; i < num; i++)
4903                         {
4904                           int pos =
4905                             (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4906                           classes[i + pos] =
4907                             merge_classes (subclasses[i], classes[i + pos]);
4908                         }
4909                     }
4910                 }
4911             }
4912           break;
4913
4914         case ARRAY_TYPE:
4915           /* Arrays are handled as small records.  */
4916           {
4917             int num;
4918             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
4919                                      TREE_TYPE (type), subclasses, bit_offset);
4920             if (!num)
4921               return 0;
4922
4923             /* The partial classes are now full classes.  */
4924             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
4925               subclasses[0] = X86_64_SSE_CLASS;
4926             if (subclasses[0] == X86_64_INTEGERSI_CLASS && bytes != 4)
4927               subclasses[0] = X86_64_INTEGER_CLASS;
4928
4929             for (i = 0; i < words; i++)
4930               classes[i] = subclasses[i % num];
4931
4932             break;
4933           }
4934         case UNION_TYPE:
4935         case QUAL_UNION_TYPE:
4936           /* Unions are similar to RECORD_TYPE but offset is always 0.
4937              */
4938           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4939             {
4940               if (TREE_CODE (field) == FIELD_DECL)
4941                 {
4942                   int num;
4943
4944                   if (TREE_TYPE (field) == error_mark_node)
4945                     continue;
4946
4947                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4948                                            TREE_TYPE (field), subclasses,
4949                                            bit_offset);
4950                   if (!num)
4951                     return 0;
4952                   for (i = 0; i < num; i++)
4953                     classes[i] = merge_classes (subclasses[i], classes[i]);
4954                 }
4955             }
4956           break;
4957
4958         default:
4959           gcc_unreachable ();
4960         }
4961
4962       /* Final merger cleanup.  */
4963       for (i = 0; i < words; i++)
4964         {
4965           /* If one class is MEMORY, everything should be passed in
4966              memory.  */
4967           if (classes[i] == X86_64_MEMORY_CLASS)
4968             return 0;
4969
4970           /* The X86_64_SSEUP_CLASS should be always preceded by
4971              X86_64_SSE_CLASS.  */
4972           if (classes[i] == X86_64_SSEUP_CLASS
4973               && (i == 0 || classes[i - 1] != X86_64_SSE_CLASS))
4974             classes[i] = X86_64_SSE_CLASS;
4975
4976           /*  X86_64_X87UP_CLASS should be preceded by X86_64_X87_CLASS.  */
4977           if (classes[i] == X86_64_X87UP_CLASS
4978               && (i == 0 || classes[i - 1] != X86_64_X87_CLASS))
4979             classes[i] = X86_64_SSE_CLASS;
4980         }
4981       return words;
4982     }
4983
4984   /* Compute alignment needed.  We align all types to natural boundaries with
4985      exception of XFmode that is aligned to 64bits.  */
4986   if (mode != VOIDmode && mode != BLKmode)
4987     {
4988       int mode_alignment = GET_MODE_BITSIZE (mode);
4989
4990       if (mode == XFmode)
4991         mode_alignment = 128;
4992       else if (mode == XCmode)
4993         mode_alignment = 256;
4994       if (COMPLEX_MODE_P (mode))
4995         mode_alignment /= 2;
4996       /* Misaligned fields are always returned in memory.  */
4997       if (bit_offset % mode_alignment)
4998         return 0;
4999     }
5000
5001   /* for V1xx modes, just use the base mode */
5002   if (VECTOR_MODE_P (mode) && mode != V1DImode
5003       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
5004     mode = GET_MODE_INNER (mode);
5005
5006   /* Classification of atomic types.  */
5007   switch (mode)
5008     {
5009     case SDmode:
5010     case DDmode:
5011       classes[0] = X86_64_SSE_CLASS;
5012       return 1;
5013     case TDmode:
5014       classes[0] = X86_64_SSE_CLASS;
5015       classes[1] = X86_64_SSEUP_CLASS;
5016       return 2;
5017     case DImode:
5018     case SImode:
5019     case HImode:
5020     case QImode:
5021     case CSImode:
5022     case CHImode:
5023     case CQImode:
5024       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5025         classes[0] = X86_64_INTEGERSI_CLASS;
5026       else
5027         classes[0] = X86_64_INTEGER_CLASS;
5028       return 1;
5029     case CDImode:
5030     case TImode:
5031       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5032       return 2;
5033     case CTImode:
5034     case COImode:
5035     case OImode:
5036       return 0;
5037     case SFmode:
5038       if (!(bit_offset % 64))
5039         classes[0] = X86_64_SSESF_CLASS;
5040       else
5041         classes[0] = X86_64_SSE_CLASS;
5042       return 1;
5043     case DFmode:
5044       classes[0] = X86_64_SSEDF_CLASS;
5045       return 1;
5046     case XFmode:
5047       classes[0] = X86_64_X87_CLASS;
5048       classes[1] = X86_64_X87UP_CLASS;
5049       return 2;
5050     case TFmode:
5051       classes[0] = X86_64_SSE_CLASS;
5052       classes[1] = X86_64_SSEUP_CLASS;
5053       return 2;
5054     case SCmode:
5055       classes[0] = X86_64_SSE_CLASS;
5056       return 1;
5057     case DCmode:
5058       classes[0] = X86_64_SSEDF_CLASS;
5059       classes[1] = X86_64_SSEDF_CLASS;
5060       return 2;
5061     case XCmode:
5062       classes[0] = X86_64_COMPLEX_X87_CLASS;
5063       return 1;
5064     case TCmode:
5065       /* This modes is larger than 16 bytes.  */
5066       return 0;
5067     case V8SFmode:
5068     case V8SImode:
5069     case V32QImode:
5070     case V16HImode:
5071     case V4DFmode:
5072     case V4DImode:
5073       classes[0] = X86_64_AVX_CLASS;
5074       return 1;
5075     case V4SFmode:
5076     case V4SImode:
5077     case V16QImode:
5078     case V8HImode:
5079     case V2DFmode:
5080     case V2DImode:
5081       classes[0] = X86_64_SSE_CLASS;
5082       classes[1] = X86_64_SSEUP_CLASS;
5083       return 2;
5084     case V1DImode:
5085     case V2SFmode:
5086     case V2SImode:
5087     case V4HImode:
5088     case V8QImode:
5089       classes[0] = X86_64_SSE_CLASS;
5090       return 1;
5091     case BLKmode:
5092     case VOIDmode:
5093       return 0;
5094     default:
5095       gcc_assert (VECTOR_MODE_P (mode));
5096
5097       if (bytes > 16)
5098         return 0;
5099
5100       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
5101
5102       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5103         classes[0] = X86_64_INTEGERSI_CLASS;
5104       else
5105         classes[0] = X86_64_INTEGER_CLASS;
5106       classes[1] = X86_64_INTEGER_CLASS;
5107       return 1 + (bytes > 8);
5108     }
5109 }
5110
5111 /* Examine the argument and return set number of register required in each
5112    class.  Return 0 iff parameter should be passed in memory.  */
5113 static int
5114 examine_argument (enum machine_mode mode, const_tree type, int in_return,
5115                   int *int_nregs, int *sse_nregs)
5116 {
5117   enum x86_64_reg_class regclass[MAX_CLASSES];
5118   int n = classify_argument (mode, type, regclass, 0);
5119
5120   *int_nregs = 0;
5121   *sse_nregs = 0;
5122   if (!n)
5123     return 0;
5124   for (n--; n >= 0; n--)
5125     switch (regclass[n])
5126       {
5127       case X86_64_INTEGER_CLASS:
5128       case X86_64_INTEGERSI_CLASS:
5129         (*int_nregs)++;
5130         break;
5131       case X86_64_AVX_CLASS:
5132       case X86_64_SSE_CLASS:
5133       case X86_64_SSESF_CLASS:
5134       case X86_64_SSEDF_CLASS:
5135         (*sse_nregs)++;
5136         break;
5137       case X86_64_NO_CLASS:
5138       case X86_64_SSEUP_CLASS:
5139         break;
5140       case X86_64_X87_CLASS:
5141       case X86_64_X87UP_CLASS:
5142         if (!in_return)
5143           return 0;
5144         break;
5145       case X86_64_COMPLEX_X87_CLASS:
5146         return in_return ? 2 : 0;
5147       case X86_64_MEMORY_CLASS:
5148         gcc_unreachable ();
5149       }
5150   return 1;
5151 }
5152
5153 /* Construct container for the argument used by GCC interface.  See
5154    FUNCTION_ARG for the detailed description.  */
5155
5156 static rtx
5157 construct_container (enum machine_mode mode, enum machine_mode orig_mode,
5158                      const_tree type, int in_return, int nintregs, int nsseregs,
5159                      const int *intreg, int sse_regno)
5160 {
5161   /* The following variables hold the static issued_error state.  */
5162   static bool issued_sse_arg_error;
5163   static bool issued_sse_ret_error;
5164   static bool issued_x87_ret_error;
5165
5166   enum machine_mode tmpmode;
5167   int bytes =
5168     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
5169   enum x86_64_reg_class regclass[MAX_CLASSES];
5170   int n;
5171   int i;
5172   int nexps = 0;
5173   int needed_sseregs, needed_intregs;
5174   rtx exp[MAX_CLASSES];
5175   rtx ret;
5176
5177   n = classify_argument (mode, type, regclass, 0);
5178   if (!n)
5179     return NULL;
5180   if (!examine_argument (mode, type, in_return, &needed_intregs,
5181                          &needed_sseregs))
5182     return NULL;
5183   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
5184     return NULL;
5185
5186   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
5187      some less clueful developer tries to use floating-point anyway.  */
5188   if (needed_sseregs && !TARGET_SSE)
5189     {
5190       if (in_return)
5191         {
5192           if (!issued_sse_ret_error)
5193             {
5194               error ("SSE register return with SSE disabled");
5195               issued_sse_ret_error = true;
5196             }
5197         }
5198       else if (!issued_sse_arg_error)
5199         {
5200           error ("SSE register argument with SSE disabled");
5201           issued_sse_arg_error = true;
5202         }
5203       return NULL;
5204     }
5205
5206   /* Likewise, error if the ABI requires us to return values in the
5207      x87 registers and the user specified -mno-80387.  */
5208   if (!TARGET_80387 && in_return)
5209     for (i = 0; i < n; i++)
5210       if (regclass[i] == X86_64_X87_CLASS
5211           || regclass[i] == X86_64_X87UP_CLASS
5212           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
5213         {
5214           if (!issued_x87_ret_error)
5215             {
5216               error ("x87 register return with x87 disabled");
5217               issued_x87_ret_error = true;
5218             }
5219           return NULL;
5220         }
5221
5222   /* First construct simple cases.  Avoid SCmode, since we want to use
5223      single register to pass this type.  */
5224   if (n == 1 && mode != SCmode)
5225     switch (regclass[0])
5226       {
5227       case X86_64_INTEGER_CLASS:
5228       case X86_64_INTEGERSI_CLASS:
5229         return gen_rtx_REG (mode, intreg[0]);
5230       case X86_64_AVX_CLASS:
5231       case X86_64_SSE_CLASS:
5232       case X86_64_SSESF_CLASS:
5233       case X86_64_SSEDF_CLASS:
5234         return gen_reg_or_parallel (mode, orig_mode, SSE_REGNO (sse_regno));
5235       case X86_64_X87_CLASS:
5236       case X86_64_COMPLEX_X87_CLASS:
5237         return gen_rtx_REG (mode, FIRST_STACK_REG);
5238       case X86_64_NO_CLASS:
5239         /* Zero sized array, struct or class.  */
5240         return NULL;
5241       default:
5242         gcc_unreachable ();
5243       }
5244   if (n == 2 && regclass[0] == X86_64_SSE_CLASS
5245       && regclass[1] == X86_64_SSEUP_CLASS && mode != BLKmode)
5246     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5247
5248   if (n == 2
5249       && regclass[0] == X86_64_X87_CLASS && regclass[1] == X86_64_X87UP_CLASS)
5250     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
5251   if (n == 2 && regclass[0] == X86_64_INTEGER_CLASS
5252       && regclass[1] == X86_64_INTEGER_CLASS
5253       && (mode == CDImode || mode == TImode || mode == TFmode)
5254       && intreg[0] + 1 == intreg[1])
5255     return gen_rtx_REG (mode, intreg[0]);
5256
5257   /* Otherwise figure out the entries of the PARALLEL.  */
5258   for (i = 0; i < n; i++)
5259     {
5260       switch (regclass[i])
5261         {
5262           case X86_64_NO_CLASS:
5263             break;
5264           case X86_64_INTEGER_CLASS:
5265           case X86_64_INTEGERSI_CLASS:
5266             /* Merge TImodes on aligned occasions here too.  */
5267             if (i * 8 + 8 > bytes)
5268               tmpmode = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
5269             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
5270               tmpmode = SImode;
5271             else
5272               tmpmode = DImode;
5273             /* We've requested 24 bytes we don't have mode for.  Use DImode.  */
5274             if (tmpmode == BLKmode)
5275               tmpmode = DImode;
5276             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5277                                                gen_rtx_REG (tmpmode, *intreg),
5278                                                GEN_INT (i*8));
5279             intreg++;
5280             break;
5281           case X86_64_SSESF_CLASS:
5282             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5283                                                gen_rtx_REG (SFmode,
5284                                                             SSE_REGNO (sse_regno)),
5285                                                GEN_INT (i*8));
5286             sse_regno++;
5287             break;
5288           case X86_64_SSEDF_CLASS:
5289             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5290                                                gen_rtx_REG (DFmode,
5291                                                             SSE_REGNO (sse_regno)),
5292                                                GEN_INT (i*8));
5293             sse_regno++;
5294             break;
5295           case X86_64_SSE_CLASS:
5296             if (i < n - 1 && regclass[i + 1] == X86_64_SSEUP_CLASS)
5297               tmpmode = TImode;
5298             else
5299               tmpmode = DImode;
5300             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5301                                                gen_rtx_REG (tmpmode,
5302                                                             SSE_REGNO (sse_regno)),
5303                                                GEN_INT (i*8));
5304             if (tmpmode == TImode)
5305               i++;
5306             sse_regno++;
5307             break;
5308           default:
5309             gcc_unreachable ();
5310         }
5311     }
5312
5313   /* Empty aligned struct, union or class.  */
5314   if (nexps == 0)
5315     return NULL;
5316
5317   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
5318   for (i = 0; i < nexps; i++)
5319     XVECEXP (ret, 0, i) = exp [i];
5320   return ret;
5321 }
5322
5323 /* Update the data in CUM to advance over an argument of mode MODE
5324    and data type TYPE.  (TYPE is null for libcalls where that information
5325    may not be available.)  */
5326
5327 static void
5328 function_arg_advance_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5329                          tree type, HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5330 {
5331   switch (mode)
5332     {
5333     default:
5334       break;
5335
5336     case BLKmode:
5337       if (bytes < 0)
5338         break;
5339       /* FALLTHRU */
5340
5341     case DImode:
5342     case SImode:
5343     case HImode:
5344     case QImode:
5345       cum->words += words;
5346       cum->nregs -= words;
5347       cum->regno += words;
5348
5349       if (cum->nregs <= 0)
5350         {
5351           cum->nregs = 0;
5352           cum->regno = 0;
5353         }
5354       break;
5355
5356     case DFmode:
5357       if (cum->float_in_sse < 2)
5358         break;
5359     case SFmode:
5360       if (cum->float_in_sse < 1)
5361         break;
5362       /* FALLTHRU */
5363
5364     case OImode:
5365     case V8SFmode:
5366     case V8SImode:
5367     case V32QImode:
5368     case V16HImode:
5369     case V4DFmode:
5370     case V4DImode:
5371     case TImode:
5372     case V16QImode:
5373     case V8HImode:
5374     case V4SImode:
5375     case V2DImode:
5376     case V4SFmode:
5377     case V2DFmode:
5378       if (!type || !AGGREGATE_TYPE_P (type))
5379         {
5380           cum->sse_words += words;
5381           cum->sse_nregs -= 1;
5382           cum->sse_regno += 1;
5383           if (cum->sse_nregs <= 0)
5384             {
5385               cum->sse_nregs = 0;
5386               cum->sse_regno = 0;
5387             }
5388         }
5389       break;
5390
5391     case V8QImode:
5392     case V4HImode:
5393     case V2SImode:
5394     case V2SFmode:
5395     case V1DImode:
5396       if (!type || !AGGREGATE_TYPE_P (type))
5397         {
5398           cum->mmx_words += words;
5399           cum->mmx_nregs -= 1;
5400           cum->mmx_regno += 1;
5401           if (cum->mmx_nregs <= 0)
5402             {
5403               cum->mmx_nregs = 0;
5404               cum->mmx_regno = 0;
5405             }
5406         }
5407       break;
5408     }
5409 }
5410
5411 static void
5412 function_arg_advance_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5413                          tree type, HOST_WIDE_INT words, int named)
5414 {
5415   int int_nregs, sse_nregs;
5416
5417   /* Unnamed 256bit vector mode parameters are passed on stack.  */
5418   if (!named && VALID_AVX256_REG_MODE (mode))
5419     return;
5420
5421   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs))
5422     cum->words += words;
5423   else if (sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
5424     {
5425       cum->nregs -= int_nregs;
5426       cum->sse_nregs -= sse_nregs;
5427       cum->regno += int_nregs;
5428       cum->sse_regno += sse_nregs;
5429     }
5430   else
5431     cum->words += words;
5432 }
5433
5434 static void
5435 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
5436                             HOST_WIDE_INT words)
5437 {
5438   /* Otherwise, this should be passed indirect.  */
5439   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
5440
5441   cum->words += words;
5442   if (cum->nregs > 0)
5443     {
5444       cum->nregs -= 1;
5445       cum->regno += 1;
5446     }
5447 }
5448
5449 void
5450 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5451                       tree type, int named)
5452 {
5453   HOST_WIDE_INT bytes, words;
5454
5455   if (mode == BLKmode)
5456     bytes = int_size_in_bytes (type);
5457   else
5458     bytes = GET_MODE_SIZE (mode);
5459   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5460
5461   if (type)
5462     mode = type_natural_mode (type);
5463
5464   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5465     function_arg_advance_ms_64 (cum, bytes, words);
5466   else if (TARGET_64BIT)
5467     function_arg_advance_64 (cum, mode, type, words, named);
5468   else
5469     function_arg_advance_32 (cum, mode, type, bytes, words);
5470 }
5471
5472 /* Define where to put the arguments to a function.
5473    Value is zero to push the argument on the stack,
5474    or a hard register in which to store the argument.
5475
5476    MODE is the argument's machine mode.
5477    TYPE is the data type of the argument (as a tree).
5478     This is null for libcalls where that information may
5479     not be available.
5480    CUM is a variable of type CUMULATIVE_ARGS which gives info about
5481     the preceding args and about the function being called.
5482    NAMED is nonzero if this argument is a named parameter
5483     (otherwise it is an extra parameter matching an ellipsis).  */
5484
5485 static rtx
5486 function_arg_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5487                  enum machine_mode orig_mode, tree type,
5488                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5489 {
5490   static bool warnedavx, warnedsse, warnedmmx;
5491
5492   /* Avoid the AL settings for the Unix64 ABI.  */
5493   if (mode == VOIDmode)
5494     return constm1_rtx;
5495
5496   switch (mode)
5497     {
5498     default:
5499       break;
5500
5501     case BLKmode:
5502       if (bytes < 0)
5503         break;
5504       /* FALLTHRU */
5505     case DImode:
5506     case SImode:
5507     case HImode:
5508     case QImode:
5509       if (words <= cum->nregs)
5510         {
5511           int regno = cum->regno;
5512
5513           /* Fastcall allocates the first two DWORD (SImode) or
5514             smaller arguments to ECX and EDX if it isn't an
5515             aggregate type .  */
5516           if (cum->fastcall)
5517             {
5518               if (mode == BLKmode
5519                   || mode == DImode
5520                   || (type && AGGREGATE_TYPE_P (type)))
5521                 break;
5522
5523               /* ECX not EAX is the first allocated register.  */
5524               if (regno == AX_REG)
5525                 regno = CX_REG;
5526             }
5527           return gen_rtx_REG (mode, regno);
5528         }
5529       break;
5530
5531     case DFmode:
5532       if (cum->float_in_sse < 2)
5533         break;
5534     case SFmode:
5535       if (cum->float_in_sse < 1)
5536         break;
5537       /* FALLTHRU */
5538     case TImode:
5539       /* In 32bit, we pass TImode in xmm registers.  */
5540     case V16QImode:
5541     case V8HImode:
5542     case V4SImode:
5543     case V2DImode:
5544     case V4SFmode:
5545     case V2DFmode:
5546       if (!type || !AGGREGATE_TYPE_P (type))
5547         {
5548           if (!TARGET_SSE && !warnedsse && cum->warn_sse)
5549             {
5550               warnedsse = true;
5551               warning (0, "SSE vector argument without SSE enabled "
5552                        "changes the ABI");
5553             }
5554           if (cum->sse_nregs)
5555             return gen_reg_or_parallel (mode, orig_mode,
5556                                         cum->sse_regno + FIRST_SSE_REG);
5557         }
5558       break;
5559
5560     case OImode:
5561       /* In 32bit, we pass OImode in ymm registers.  */
5562     case V8SFmode:
5563     case V8SImode:
5564     case V32QImode:
5565     case V16HImode:
5566     case V4DFmode:
5567     case V4DImode:
5568       if (!type || !AGGREGATE_TYPE_P (type))
5569         {
5570           if (!TARGET_AVX && !warnedavx && cum->warn_avx)
5571             {
5572               warnedavx = true;
5573               warning (0, "AVX vector argument without AVX enabled "
5574                        "changes the ABI");
5575             }
5576           if (cum->sse_nregs)
5577             return gen_reg_or_parallel (mode, orig_mode,
5578                                         cum->sse_regno + FIRST_SSE_REG);
5579         }
5580       break;
5581
5582     case V8QImode:
5583     case V4HImode:
5584     case V2SImode:
5585     case V2SFmode:
5586     case V1DImode:
5587       if (!type || !AGGREGATE_TYPE_P (type))
5588         {
5589           if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
5590             {
5591               warnedmmx = true;
5592               warning (0, "MMX vector argument without MMX enabled "
5593                        "changes the ABI");
5594             }
5595           if (cum->mmx_nregs)
5596             return gen_reg_or_parallel (mode, orig_mode,
5597                                         cum->mmx_regno + FIRST_MMX_REG);
5598         }
5599       break;
5600     }
5601
5602   return NULL_RTX;
5603 }
5604
5605 static rtx
5606 function_arg_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5607                  enum machine_mode orig_mode, tree type, int named)
5608 {
5609   static bool warnedavx;
5610
5611   /* Handle a hidden AL argument containing number of registers
5612      for varargs x86-64 functions.  */
5613   if (mode == VOIDmode)
5614     return GEN_INT (cum->maybe_vaarg
5615                     ? (cum->sse_nregs < 0
5616                        ? (cum->call_abi == DEFAULT_ABI
5617                           ? SSE_REGPARM_MAX
5618                           : (DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
5619                                                      : X64_SSE_REGPARM_MAX))
5620                : cum->sse_regno)
5621                     : -1);
5622
5623   switch (mode)
5624     {
5625     default:
5626       break;
5627
5628     case V8SFmode:
5629     case V8SImode:
5630     case V32QImode:
5631     case V16HImode:
5632     case V4DFmode:
5633     case V4DImode:
5634       /* In 64bit, we pass TImode in interger registers and OImode on
5635          stack.  */
5636       if (!type || !AGGREGATE_TYPE_P (type))
5637         {
5638           if (!TARGET_AVX && !warnedavx && cum->warn_avx)
5639             {
5640               warnedavx = true;
5641               warning (0, "AVX vector argument without AVX enabled "
5642                        "changes the ABI");
5643             }
5644         }
5645
5646       /* Unnamed 256bit vector mode parameters are passed on stack.  */
5647       if (!named)
5648         return NULL;
5649       break;
5650     }
5651
5652   return construct_container (mode, orig_mode, type, 0, cum->nregs,
5653                               cum->sse_nregs,
5654                               &x86_64_int_parameter_registers [cum->regno],
5655                               cum->sse_regno);
5656 }
5657
5658 static rtx
5659 function_arg_ms_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5660                     enum machine_mode orig_mode, int named,
5661                     HOST_WIDE_INT bytes)
5662 {
5663   unsigned int regno;
5664
5665   /* Avoid the AL settings for the Unix64 ABI.  */
5666   if (mode == VOIDmode)
5667     return constm1_rtx;
5668
5669   /* If we've run out of registers, it goes on the stack.  */
5670   if (cum->nregs == 0)
5671     return NULL_RTX;
5672
5673   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
5674
5675   /* Only floating point modes are passed in anything but integer regs.  */
5676   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
5677     {
5678       if (named)
5679         regno = cum->regno + FIRST_SSE_REG;
5680       else
5681         {
5682           rtx t1, t2;
5683
5684           /* Unnamed floating parameters are passed in both the
5685              SSE and integer registers.  */
5686           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
5687           t2 = gen_rtx_REG (mode, regno);
5688           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
5689           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
5690           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
5691         }
5692     }
5693   /* Handle aggregated types passed in register.  */
5694   if (orig_mode == BLKmode)
5695     {
5696       if (bytes > 0 && bytes <= 8)
5697         mode = (bytes > 4 ? DImode : SImode);
5698       if (mode == BLKmode)
5699         mode = DImode;
5700     }
5701
5702   return gen_reg_or_parallel (mode, orig_mode, regno);
5703 }
5704
5705 rtx
5706 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
5707               tree type, int named)
5708 {
5709   enum machine_mode mode = omode;
5710   HOST_WIDE_INT bytes, words;
5711
5712   if (mode == BLKmode)
5713     bytes = int_size_in_bytes (type);
5714   else
5715     bytes = GET_MODE_SIZE (mode);
5716   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5717
5718   /* To simplify the code below, represent vector types with a vector mode
5719      even if MMX/SSE are not active.  */
5720   if (type && TREE_CODE (type) == VECTOR_TYPE)
5721     mode = type_natural_mode (type);
5722
5723   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5724     return function_arg_ms_64 (cum, mode, omode, named, bytes);
5725   else if (TARGET_64BIT)
5726     return function_arg_64 (cum, mode, omode, type, named);
5727   else
5728     return function_arg_32 (cum, mode, omode, type, bytes, words);
5729 }
5730
5731 /* A C expression that indicates when an argument must be passed by
5732    reference.  If nonzero for an argument, a copy of that argument is
5733    made in memory and a pointer to the argument is passed instead of
5734    the argument itself.  The pointer is passed in whatever way is
5735    appropriate for passing a pointer to that type.  */
5736
5737 static bool
5738 ix86_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5739                         enum machine_mode mode ATTRIBUTE_UNUSED,
5740                         const_tree type, bool named ATTRIBUTE_UNUSED)
5741 {
5742   /* See Windows x64 Software Convention.  */
5743   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5744     {
5745       int msize = (int) GET_MODE_SIZE (mode);
5746       if (type)
5747         {
5748           /* Arrays are passed by reference.  */
5749           if (TREE_CODE (type) == ARRAY_TYPE)
5750             return true;
5751
5752           if (AGGREGATE_TYPE_P (type))
5753             {
5754               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
5755                  are passed by reference.  */
5756               msize = int_size_in_bytes (type);
5757             }
5758         }
5759
5760       /* __m128 is passed by reference.  */
5761       switch (msize) {
5762       case 1: case 2: case 4: case 8:
5763         break;
5764       default:
5765         return true;
5766       }
5767     }
5768   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
5769     return 1;
5770
5771   return 0;
5772 }
5773
5774 /* Return true when TYPE should be 128bit aligned for 32bit argument passing
5775    ABI.  */
5776 static bool
5777 contains_aligned_value_p (tree type)
5778 {
5779   enum machine_mode mode = TYPE_MODE (type);
5780   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
5781        || mode == TDmode
5782        || mode == TFmode
5783        || mode == TCmode)
5784       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
5785     return true;
5786   if (TYPE_ALIGN (type) < 128)
5787     return false;
5788
5789   if (AGGREGATE_TYPE_P (type))
5790     {
5791       /* Walk the aggregates recursively.  */
5792       switch (TREE_CODE (type))
5793         {
5794         case RECORD_TYPE:
5795         case UNION_TYPE:
5796         case QUAL_UNION_TYPE:
5797           {
5798             tree field;
5799
5800             /* Walk all the structure fields.  */
5801             for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5802               {
5803                 if (TREE_CODE (field) == FIELD_DECL
5804                     && contains_aligned_value_p (TREE_TYPE (field)))
5805                   return true;
5806               }
5807             break;
5808           }
5809
5810         case ARRAY_TYPE:
5811           /* Just for use if some languages passes arrays by value.  */
5812           if (contains_aligned_value_p (TREE_TYPE (type)))
5813             return true;
5814           break;
5815
5816         default:
5817           gcc_unreachable ();
5818         }
5819     }
5820   return false;
5821 }
5822
5823 /* Gives the alignment boundary, in bits, of an argument with the
5824    specified mode and type.  */
5825
5826 int
5827 ix86_function_arg_boundary (enum machine_mode mode, tree type)
5828 {
5829   int align;
5830   if (type)
5831     {
5832       /* Since canonical type is used for call, we convert it to
5833          canonical type if needed.  */
5834       if (!TYPE_STRUCTURAL_EQUALITY_P (type))
5835         type = TYPE_CANONICAL (type);
5836       align = TYPE_ALIGN (type);
5837     }
5838   else
5839     align = GET_MODE_ALIGNMENT (mode);
5840   if (align < PARM_BOUNDARY)
5841     align = PARM_BOUNDARY;
5842   /* In 32bit, only _Decimal128 and __float128 are aligned to their
5843      natural boundaries.  */
5844   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
5845     {
5846       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
5847          make an exception for SSE modes since these require 128bit
5848          alignment.
5849
5850          The handling here differs from field_alignment.  ICC aligns MMX
5851          arguments to 4 byte boundaries, while structure fields are aligned
5852          to 8 byte boundaries.  */
5853       if (!type)
5854         {
5855           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
5856             align = PARM_BOUNDARY;
5857         }
5858       else
5859         {
5860           if (!contains_aligned_value_p (type))
5861             align = PARM_BOUNDARY;
5862         }
5863     }
5864   if (align > BIGGEST_ALIGNMENT)
5865     align = BIGGEST_ALIGNMENT;
5866   return align;
5867 }
5868
5869 /* Return true if N is a possible register number of function value.  */
5870
5871 bool
5872 ix86_function_value_regno_p (int regno)
5873 {
5874   switch (regno)
5875     {
5876     case 0:
5877       return true;
5878
5879     case FIRST_FLOAT_REG:
5880       /* TODO: The function should depend on current function ABI but
5881        builtins.c would need updating then. Therefore we use the
5882        default ABI.  */
5883       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
5884         return false;
5885       return TARGET_FLOAT_RETURNS_IN_80387;
5886
5887     case FIRST_SSE_REG:
5888       return TARGET_SSE;
5889
5890     case FIRST_MMX_REG:
5891       if (TARGET_MACHO || TARGET_64BIT)
5892         return false;
5893       return TARGET_MMX;
5894     }
5895
5896   return false;
5897 }
5898
5899 /* Define how to find the value returned by a function.
5900    VALTYPE is the data type of the value (as a tree).
5901    If the precise function being called is known, FUNC is its FUNCTION_DECL;
5902    otherwise, FUNC is 0.  */
5903
5904 static rtx
5905 function_value_32 (enum machine_mode orig_mode, enum machine_mode mode,
5906                    const_tree fntype, const_tree fn)
5907 {
5908   unsigned int regno;
5909
5910   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
5911      we normally prevent this case when mmx is not available.  However
5912      some ABIs may require the result to be returned like DImode.  */
5913   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
5914     regno = TARGET_MMX ? FIRST_MMX_REG : 0;
5915
5916   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
5917      we prevent this case when sse is not available.  However some ABIs
5918      may require the result to be returned like integer TImode.  */
5919   else if (mode == TImode
5920            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
5921     regno = TARGET_SSE ? FIRST_SSE_REG : 0;
5922
5923   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
5924   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
5925     regno = FIRST_FLOAT_REG;
5926   else
5927     /* Most things go in %eax.  */
5928     regno = AX_REG;
5929
5930   /* Override FP return register with %xmm0 for local functions when
5931      SSE math is enabled or for functions with sseregparm attribute.  */
5932   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
5933     {
5934       int sse_level = ix86_function_sseregparm (fntype, fn, false);
5935       if ((sse_level >= 1 && mode == SFmode)
5936           || (sse_level == 2 && mode == DFmode))
5937         regno = FIRST_SSE_REG;
5938     }
5939
5940   return gen_rtx_REG (orig_mode, regno);
5941 }
5942
5943 static rtx
5944 function_value_64 (enum machine_mode orig_mode, enum machine_mode mode,
5945                    const_tree valtype)
5946 {
5947   rtx ret;
5948
5949   /* Handle libcalls, which don't provide a type node.  */
5950   if (valtype == NULL)
5951     {
5952       switch (mode)
5953         {
5954         case SFmode:
5955         case SCmode:
5956         case DFmode:
5957         case DCmode:
5958         case TFmode:
5959         case SDmode:
5960         case DDmode:
5961         case TDmode:
5962           return gen_rtx_REG (mode, FIRST_SSE_REG);
5963         case XFmode:
5964         case XCmode:
5965           return gen_rtx_REG (mode, FIRST_FLOAT_REG);
5966         case TCmode:
5967           return NULL;
5968         default:
5969           return gen_rtx_REG (mode, AX_REG);
5970         }
5971     }
5972
5973   ret = construct_container (mode, orig_mode, valtype, 1,
5974                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
5975                              x86_64_int_return_registers, 0);
5976
5977   /* For zero sized structures, construct_container returns NULL, but we
5978      need to keep rest of compiler happy by returning meaningful value.  */
5979   if (!ret)
5980     ret = gen_rtx_REG (orig_mode, AX_REG);
5981
5982   return ret;
5983 }
5984
5985 static rtx
5986 function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
5987 {
5988   unsigned int regno = AX_REG;
5989
5990   if (TARGET_SSE)
5991     {
5992       switch (GET_MODE_SIZE (mode))
5993         {
5994         case 16:
5995           if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
5996              && !COMPLEX_MODE_P (mode))
5997             regno = FIRST_SSE_REG;
5998           break;
5999         case 8:
6000         case 4:
6001           if (mode == SFmode || mode == DFmode)
6002             regno = FIRST_SSE_REG;
6003           break;
6004         default:
6005           break;
6006         }
6007     }
6008   return gen_rtx_REG (orig_mode, regno);
6009 }
6010
6011 static rtx
6012 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
6013                        enum machine_mode orig_mode, enum machine_mode mode)
6014 {
6015   const_tree fn, fntype;
6016
6017   fn = NULL_TREE;
6018   if (fntype_or_decl && DECL_P (fntype_or_decl))
6019     fn = fntype_or_decl;
6020   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
6021
6022   if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
6023     return function_value_ms_64 (orig_mode, mode);
6024   else if (TARGET_64BIT)
6025     return function_value_64 (orig_mode, mode, valtype);
6026   else
6027     return function_value_32 (orig_mode, mode, fntype, fn);
6028 }
6029
6030 static rtx
6031 ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
6032                      bool outgoing ATTRIBUTE_UNUSED)
6033 {
6034   enum machine_mode mode, orig_mode;
6035
6036   orig_mode = TYPE_MODE (valtype);
6037   mode = type_natural_mode (valtype);
6038   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
6039 }
6040
6041 rtx
6042 ix86_libcall_value (enum machine_mode mode)
6043 {
6044   return ix86_function_value_1 (NULL, NULL, mode, mode);
6045 }
6046
6047 /* Return true iff type is returned in memory.  */
6048
6049 static int ATTRIBUTE_UNUSED
6050 return_in_memory_32 (const_tree type, enum machine_mode mode)
6051 {
6052   HOST_WIDE_INT size;
6053
6054   if (mode == BLKmode)
6055     return 1;
6056
6057   size = int_size_in_bytes (type);
6058
6059   if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
6060     return 0;
6061
6062   if (VECTOR_MODE_P (mode) || mode == TImode)
6063     {
6064       /* User-created vectors small enough to fit in EAX.  */
6065       if (size < 8)
6066         return 0;
6067
6068       /* MMX/3dNow values are returned in MM0,
6069          except when it doesn't exits.  */
6070       if (size == 8)
6071         return (TARGET_MMX ? 0 : 1);
6072
6073       /* SSE values are returned in XMM0, except when it doesn't exist.  */
6074       if (size == 16)
6075         return (TARGET_SSE ? 0 : 1);
6076     }
6077
6078   if (mode == XFmode)
6079     return 0;
6080
6081   if (size > 12)
6082     return 1;
6083   return 0;
6084 }
6085
6086 static int ATTRIBUTE_UNUSED
6087 return_in_memory_64 (const_tree type, enum machine_mode mode)
6088 {
6089   int needed_intregs, needed_sseregs;
6090   return !examine_argument (mode, type, 1, &needed_intregs, &needed_sseregs);
6091 }
6092
6093 static int ATTRIBUTE_UNUSED
6094 return_in_memory_ms_64 (const_tree type, enum machine_mode mode)
6095 {
6096   HOST_WIDE_INT size = int_size_in_bytes (type);
6097
6098   /* __m128 is returned in xmm0.  */
6099   if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6100       && !COMPLEX_MODE_P (mode) && (GET_MODE_SIZE (mode) == 16 || size == 16))
6101     return 0;
6102
6103   /* Otherwise, the size must be exactly in [1248]. */
6104   return (size != 1 && size != 2 && size != 4 && size != 8);
6105 }
6106
6107 static bool
6108 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6109 {
6110 #ifdef SUBTARGET_RETURN_IN_MEMORY
6111   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
6112 #else
6113    const enum machine_mode mode = type_natural_mode (type);
6114  
6115   if (TARGET_64BIT_MS_ABI)
6116      return return_in_memory_ms_64 (type, mode);
6117    else if (TARGET_64BIT)
6118      return return_in_memory_64 (type, mode);
6119    else
6120      return return_in_memory_32 (type, mode);
6121 #endif
6122 }
6123
6124 /* Return false iff TYPE is returned in memory.  This version is used
6125    on Solaris 10.  It is similar to the generic ix86_return_in_memory,
6126    but differs notably in that when MMX is available, 8-byte vectors
6127    are returned in memory, rather than in MMX registers.  */
6128
6129 bool
6130 ix86_sol10_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6131 {
6132   int size;
6133   enum machine_mode mode = type_natural_mode (type);
6134
6135   if (TARGET_64BIT)
6136     return return_in_memory_64 (type, mode);
6137
6138   if (mode == BLKmode)
6139     return 1;
6140
6141   size = int_size_in_bytes (type);
6142
6143   if (VECTOR_MODE_P (mode))
6144     {
6145       /* Return in memory only if MMX registers *are* available.  This
6146          seems backwards, but it is consistent with the existing
6147          Solaris x86 ABI.  */
6148       if (size == 8)
6149         return TARGET_MMX;
6150       if (size == 16)
6151         return !TARGET_SSE;
6152     }
6153   else if (mode == TImode)
6154     return !TARGET_SSE;
6155   else if (mode == XFmode)
6156     return 0;
6157
6158   return size > 12;
6159 }
6160
6161 /* When returning SSE vector types, we have a choice of either
6162      (1) being abi incompatible with a -march switch, or
6163      (2) generating an error.
6164    Given no good solution, I think the safest thing is one warning.
6165    The user won't be able to use -Werror, but....
6166
6167    Choose the STRUCT_VALUE_RTX hook because that's (at present) only
6168    called in response to actually generating a caller or callee that
6169    uses such a type.  As opposed to TARGET_RETURN_IN_MEMORY, which is called
6170    via aggregate_value_p for general type probing from tree-ssa.  */
6171
6172 static rtx
6173 ix86_struct_value_rtx (tree type, int incoming ATTRIBUTE_UNUSED)
6174 {
6175   static bool warnedsse, warnedmmx;
6176
6177   if (!TARGET_64BIT && type)
6178     {
6179       /* Look at the return type of the function, not the function type.  */
6180       enum machine_mode mode = TYPE_MODE (TREE_TYPE (type));
6181
6182       if (!TARGET_SSE && !warnedsse)
6183         {
6184           if (mode == TImode
6185               || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6186             {
6187               warnedsse = true;
6188               warning (0, "SSE vector return without SSE enabled "
6189                        "changes the ABI");
6190             }
6191         }
6192
6193       if (!TARGET_MMX && !warnedmmx)
6194         {
6195           if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6196             {
6197               warnedmmx = true;
6198               warning (0, "MMX vector return without MMX enabled "
6199                        "changes the ABI");
6200             }
6201         }
6202     }
6203
6204   return NULL;
6205 }
6206
6207 \f
6208 /* Create the va_list data type.  */
6209
6210 /* Returns the calling convention specific va_list date type.
6211    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
6212
6213 static tree
6214 ix86_build_builtin_va_list_abi (enum calling_abi abi)
6215 {
6216   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
6217
6218   /* For i386 we use plain pointer to argument area.  */
6219   if (!TARGET_64BIT || abi == MS_ABI)
6220     return build_pointer_type (char_type_node);
6221
6222   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6223   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6224
6225   f_gpr = build_decl (FIELD_DECL, get_identifier ("gp_offset"),
6226                       unsigned_type_node);
6227   f_fpr = build_decl (FIELD_DECL, get_identifier ("fp_offset"),
6228                       unsigned_type_node);
6229   f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
6230                       ptr_type_node);
6231   f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
6232                       ptr_type_node);
6233
6234   va_list_gpr_counter_field = f_gpr;
6235   va_list_fpr_counter_field = f_fpr;
6236
6237   DECL_FIELD_CONTEXT (f_gpr) = record;
6238   DECL_FIELD_CONTEXT (f_fpr) = record;
6239   DECL_FIELD_CONTEXT (f_ovf) = record;
6240   DECL_FIELD_CONTEXT (f_sav) = record;
6241
6242   TREE_CHAIN (record) = type_decl;
6243   TYPE_NAME (record) = type_decl;
6244   TYPE_FIELDS (record) = f_gpr;
6245   TREE_CHAIN (f_gpr) = f_fpr;
6246   TREE_CHAIN (f_fpr) = f_ovf;
6247   TREE_CHAIN (f_ovf) = f_sav;
6248
6249   layout_type (record);
6250
6251   /* The correct type is an array type of one element.  */
6252   return build_array_type (record, build_index_type (size_zero_node));
6253 }
6254
6255 /* Setup the builtin va_list data type and for 64-bit the additional
6256    calling convention specific va_list data types.  */
6257
6258 static tree
6259 ix86_build_builtin_va_list (void)
6260 {
6261   tree ret = ix86_build_builtin_va_list_abi (DEFAULT_ABI);
6262
6263   /* Initialize abi specific va_list builtin types.  */
6264   if (TARGET_64BIT)
6265     {
6266       tree t;
6267       if (DEFAULT_ABI == MS_ABI)
6268         {
6269           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
6270           if (TREE_CODE (t) != RECORD_TYPE)
6271             t = build_variant_type_copy (t);
6272           sysv_va_list_type_node = t;
6273         }
6274       else
6275         {
6276           t = ret;
6277           if (TREE_CODE (t) != RECORD_TYPE)
6278             t = build_variant_type_copy (t);
6279           sysv_va_list_type_node = t;
6280         }
6281       if (DEFAULT_ABI != MS_ABI)
6282         {
6283           t = ix86_build_builtin_va_list_abi (MS_ABI);
6284           if (TREE_CODE (t) != RECORD_TYPE)
6285             t = build_variant_type_copy (t);
6286           ms_va_list_type_node = t;
6287         }
6288       else
6289         {
6290           t = ret;
6291           if (TREE_CODE (t) != RECORD_TYPE)
6292             t = build_variant_type_copy (t);
6293           ms_va_list_type_node = t;
6294         }
6295     }
6296
6297   return ret;
6298 }
6299
6300 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
6301
6302 static void
6303 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
6304 {
6305   rtx save_area, mem;
6306   rtx label;
6307   rtx label_ref;
6308   rtx tmp_reg;
6309   rtx nsse_reg;
6310   alias_set_type set;
6311   int i;
6312   int regparm = ix86_regparm;
6313
6314   if (cum->call_abi != DEFAULT_ABI)
6315     regparm = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
6316
6317   /* GPR size of varargs save area.  */
6318   if (cfun->va_list_gpr_size)
6319     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
6320   else
6321     ix86_varargs_gpr_size = 0;
6322
6323   /* FPR size of varargs save area.  We don't need it if we don't pass
6324      anything in SSE registers.  */
6325   if (cum->sse_nregs && cfun->va_list_fpr_size)
6326     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
6327   else
6328     ix86_varargs_fpr_size = 0;
6329
6330   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
6331     return;
6332
6333   save_area = frame_pointer_rtx;
6334   set = get_varargs_alias_set ();
6335
6336   for (i = cum->regno;
6337        i < regparm
6338        && i < cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
6339        i++)
6340     {
6341       mem = gen_rtx_MEM (Pmode,
6342                          plus_constant (save_area, i * UNITS_PER_WORD));
6343       MEM_NOTRAP_P (mem) = 1;
6344       set_mem_alias_set (mem, set);
6345       emit_move_insn (mem, gen_rtx_REG (Pmode,
6346                                         x86_64_int_parameter_registers[i]));
6347     }
6348
6349   if (ix86_varargs_fpr_size)
6350     {
6351       /* Now emit code to save SSE registers.  The AX parameter contains number
6352          of SSE parameter registers used to call this function.  We use
6353          sse_prologue_save insn template that produces computed jump across
6354          SSE saves.  We need some preparation work to get this working.  */
6355
6356       label = gen_label_rtx ();
6357       label_ref = gen_rtx_LABEL_REF (Pmode, label);
6358
6359       /* Compute address to jump to :
6360          label - eax*4 + nnamed_sse_arguments*4 Or
6361          label - eax*5 + nnamed_sse_arguments*5 for AVX.  */
6362       tmp_reg = gen_reg_rtx (Pmode);
6363       nsse_reg = gen_reg_rtx (Pmode);
6364       emit_insn (gen_zero_extendqidi2 (nsse_reg, gen_rtx_REG (QImode, AX_REG)));
6365       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6366                               gen_rtx_MULT (Pmode, nsse_reg,
6367                                             GEN_INT (4))));
6368
6369       /* vmovaps is one byte longer than movaps.  */
6370       if (TARGET_AVX)
6371         emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6372                                 gen_rtx_PLUS (Pmode, tmp_reg,
6373                                               nsse_reg)));
6374
6375       if (cum->sse_regno)
6376         emit_move_insn
6377           (nsse_reg,
6378            gen_rtx_CONST (DImode,
6379                           gen_rtx_PLUS (DImode,
6380                                         label_ref,
6381                                         GEN_INT (cum->sse_regno
6382                                                  * (TARGET_AVX ? 5 : 4)))));
6383       else
6384         emit_move_insn (nsse_reg, label_ref);
6385       emit_insn (gen_subdi3 (nsse_reg, nsse_reg, tmp_reg));
6386
6387       /* Compute address of memory block we save into.  We always use pointer
6388          pointing 127 bytes after first byte to store - this is needed to keep
6389          instruction size limited by 4 bytes (5 bytes for AVX) with one
6390          byte displacement.  */
6391       tmp_reg = gen_reg_rtx (Pmode);
6392       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6393                               plus_constant (save_area,
6394                                              ix86_varargs_gpr_size + 127)));
6395       mem = gen_rtx_MEM (BLKmode, plus_constant (tmp_reg, -127));
6396       MEM_NOTRAP_P (mem) = 1;
6397       set_mem_alias_set (mem, set);
6398       set_mem_align (mem, BITS_PER_WORD);
6399
6400       /* And finally do the dirty job!  */
6401       emit_insn (gen_sse_prologue_save (mem, nsse_reg,
6402                                         GEN_INT (cum->sse_regno), label));
6403     }
6404 }
6405
6406 static void
6407 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
6408 {
6409   alias_set_type set = get_varargs_alias_set ();
6410   int i;
6411
6412   for (i = cum->regno; i < X64_REGPARM_MAX; i++)
6413     {
6414       rtx reg, mem;
6415
6416       mem = gen_rtx_MEM (Pmode,
6417                          plus_constant (virtual_incoming_args_rtx,
6418                                         i * UNITS_PER_WORD));
6419       MEM_NOTRAP_P (mem) = 1;
6420       set_mem_alias_set (mem, set);
6421
6422       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
6423       emit_move_insn (mem, reg);
6424     }
6425 }
6426
6427 static void
6428 ix86_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
6429                              tree type, int *pretend_size ATTRIBUTE_UNUSED,
6430                              int no_rtl)
6431 {
6432   CUMULATIVE_ARGS next_cum;
6433   tree fntype;
6434
6435   /* This argument doesn't appear to be used anymore.  Which is good,
6436      because the old code here didn't suppress rtl generation.  */
6437   gcc_assert (!no_rtl);
6438
6439   if (!TARGET_64BIT)
6440     return;
6441
6442   fntype = TREE_TYPE (current_function_decl);
6443
6444   /* For varargs, we do not want to skip the dummy va_dcl argument.
6445      For stdargs, we do want to skip the last named argument.  */
6446   next_cum = *cum;
6447   if (stdarg_p (fntype))
6448     function_arg_advance (&next_cum, mode, type, 1);
6449
6450   if (cum->call_abi == MS_ABI)
6451     setup_incoming_varargs_ms_64 (&next_cum);
6452   else
6453     setup_incoming_varargs_64 (&next_cum);
6454 }
6455
6456 /* Checks if TYPE is of kind va_list char *.  */
6457
6458 static bool
6459 is_va_list_char_pointer (tree type)
6460 {
6461   tree canonic;
6462
6463   /* For 32-bit it is always true.  */
6464   if (!TARGET_64BIT)
6465     return true;
6466   canonic = ix86_canonical_va_list_type (type);
6467   return (canonic == ms_va_list_type_node
6468           || (DEFAULT_ABI == MS_ABI && canonic == va_list_type_node));
6469 }
6470
6471 /* Implement va_start.  */
6472
6473 static void
6474 ix86_va_start (tree valist, rtx nextarg)
6475 {
6476   HOST_WIDE_INT words, n_gpr, n_fpr;
6477   tree f_gpr, f_fpr, f_ovf, f_sav;
6478   tree gpr, fpr, ovf, sav, t;
6479   tree type;
6480
6481   /* Only 64bit target needs something special.  */
6482   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6483     {
6484       std_expand_builtin_va_start (valist, nextarg);
6485       return;
6486     }
6487
6488   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6489   f_fpr = TREE_CHAIN (f_gpr);
6490   f_ovf = TREE_CHAIN (f_fpr);
6491   f_sav = TREE_CHAIN (f_ovf);
6492
6493   valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
6494   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6495   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6496   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6497   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6498
6499   /* Count number of gp and fp argument registers used.  */
6500   words = crtl->args.info.words;
6501   n_gpr = crtl->args.info.regno;
6502   n_fpr = crtl->args.info.sse_regno;
6503
6504   if (cfun->va_list_gpr_size)
6505     {
6506       type = TREE_TYPE (gpr);
6507       t = build2 (MODIFY_EXPR, type,
6508                   gpr, build_int_cst (type, n_gpr * 8));
6509       TREE_SIDE_EFFECTS (t) = 1;
6510       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6511     }
6512
6513   if (TARGET_SSE && cfun->va_list_fpr_size)
6514     {
6515       type = TREE_TYPE (fpr);
6516       t = build2 (MODIFY_EXPR, type, fpr,
6517                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
6518       TREE_SIDE_EFFECTS (t) = 1;
6519       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6520     }
6521
6522   /* Find the overflow area.  */
6523   type = TREE_TYPE (ovf);
6524   t = make_tree (type, crtl->args.internal_arg_pointer);
6525   if (words != 0)
6526     t = build2 (POINTER_PLUS_EXPR, type, t,
6527                 size_int (words * UNITS_PER_WORD));
6528   t = build2 (MODIFY_EXPR, type, ovf, t);
6529   TREE_SIDE_EFFECTS (t) = 1;
6530   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6531
6532   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
6533     {
6534       /* Find the register save area.
6535          Prologue of the function save it right above stack frame.  */
6536       type = TREE_TYPE (sav);
6537       t = make_tree (type, frame_pointer_rtx);
6538       if (!ix86_varargs_gpr_size)
6539         t = build2 (POINTER_PLUS_EXPR, type, t,
6540                     size_int (-8 * X86_64_REGPARM_MAX));
6541       t = build2 (MODIFY_EXPR, type, sav, t);
6542       TREE_SIDE_EFFECTS (t) = 1;
6543       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6544     }
6545 }
6546
6547 /* Implement va_arg.  */
6548
6549 static tree
6550 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
6551                       gimple_seq *post_p)
6552 {
6553   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
6554   tree f_gpr, f_fpr, f_ovf, f_sav;
6555   tree gpr, fpr, ovf, sav, t;
6556   int size, rsize;
6557   tree lab_false, lab_over = NULL_TREE;
6558   tree addr, t2;
6559   rtx container;
6560   int indirect_p = 0;
6561   tree ptrtype;
6562   enum machine_mode nat_mode;
6563   int arg_boundary;
6564
6565   /* Only 64bit target needs something special.  */
6566   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6567     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6568
6569   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6570   f_fpr = TREE_CHAIN (f_gpr);
6571   f_ovf = TREE_CHAIN (f_fpr);
6572   f_sav = TREE_CHAIN (f_ovf);
6573
6574   valist = build_va_arg_indirect_ref (valist);
6575   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6576   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6577   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6578   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6579
6580   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
6581   if (indirect_p)
6582     type = build_pointer_type (type);
6583   size = int_size_in_bytes (type);
6584   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6585
6586   nat_mode = type_natural_mode (type);
6587   switch (nat_mode)
6588     {
6589     case V8SFmode:
6590     case V8SImode:
6591     case V32QImode:
6592     case V16HImode:
6593     case V4DFmode:
6594     case V4DImode:
6595       /* Unnamed 256bit vector mode parameters are passed on stack.  */
6596       if (ix86_cfun_abi () == SYSV_ABI)
6597         {
6598           container = NULL;
6599           break;
6600         }
6601
6602     default:
6603       container = construct_container (nat_mode, TYPE_MODE (type),
6604                                        type, 0, X86_64_REGPARM_MAX,
6605                                        X86_64_SSE_REGPARM_MAX, intreg,
6606                                        0);
6607       break;
6608     }
6609
6610   /* Pull the value out of the saved registers.  */
6611
6612   addr = create_tmp_var (ptr_type_node, "addr");
6613   DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
6614
6615   if (container)
6616     {
6617       int needed_intregs, needed_sseregs;
6618       bool need_temp;
6619       tree int_addr, sse_addr;
6620
6621       lab_false = create_artificial_label ();
6622       lab_over = create_artificial_label ();
6623
6624       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
6625
6626       need_temp = (!REG_P (container)
6627                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
6628                        || TYPE_ALIGN (type) > 128));
6629
6630       /* In case we are passing structure, verify that it is consecutive block
6631          on the register save area.  If not we need to do moves.  */
6632       if (!need_temp && !REG_P (container))
6633         {
6634           /* Verify that all registers are strictly consecutive  */
6635           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
6636             {
6637               int i;
6638
6639               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6640                 {
6641                   rtx slot = XVECEXP (container, 0, i);
6642                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
6643                       || INTVAL (XEXP (slot, 1)) != i * 16)
6644                     need_temp = 1;
6645                 }
6646             }
6647           else
6648             {
6649               int i;
6650
6651               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6652                 {
6653                   rtx slot = XVECEXP (container, 0, i);
6654                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
6655                       || INTVAL (XEXP (slot, 1)) != i * 8)
6656                     need_temp = 1;
6657                 }
6658             }
6659         }
6660       if (!need_temp)
6661         {
6662           int_addr = addr;
6663           sse_addr = addr;
6664         }
6665       else
6666         {
6667           int_addr = create_tmp_var (ptr_type_node, "int_addr");
6668           DECL_POINTER_ALIAS_SET (int_addr) = get_varargs_alias_set ();
6669           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
6670           DECL_POINTER_ALIAS_SET (sse_addr) = get_varargs_alias_set ();
6671         }
6672
6673       /* First ensure that we fit completely in registers.  */
6674       if (needed_intregs)
6675         {
6676           t = build_int_cst (TREE_TYPE (gpr),
6677                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
6678           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
6679           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6680           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6681           gimplify_and_add (t, pre_p);
6682         }
6683       if (needed_sseregs)
6684         {
6685           t = build_int_cst (TREE_TYPE (fpr),
6686                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
6687                              + X86_64_REGPARM_MAX * 8);
6688           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
6689           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6690           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6691           gimplify_and_add (t, pre_p);
6692         }
6693
6694       /* Compute index to start of area used for integer regs.  */
6695       if (needed_intregs)
6696         {
6697           /* int_addr = gpr + sav; */
6698           t = fold_convert (sizetype, gpr);
6699           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6700           gimplify_assign (int_addr, t, pre_p);
6701         }
6702       if (needed_sseregs)
6703         {
6704           /* sse_addr = fpr + sav; */
6705           t = fold_convert (sizetype, fpr);
6706           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6707           gimplify_assign (sse_addr, t, pre_p);
6708         }
6709       if (need_temp)
6710         {
6711           int i;
6712           tree temp = create_tmp_var (type, "va_arg_tmp");
6713
6714           /* addr = &temp; */
6715           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
6716           gimplify_assign (addr, t, pre_p);
6717
6718           for (i = 0; i < XVECLEN (container, 0); i++)
6719             {
6720               rtx slot = XVECEXP (container, 0, i);
6721               rtx reg = XEXP (slot, 0);
6722               enum machine_mode mode = GET_MODE (reg);
6723               tree piece_type = lang_hooks.types.type_for_mode (mode, 1);
6724               tree addr_type = build_pointer_type (piece_type);
6725               tree src_addr, src;
6726               int src_offset;
6727               tree dest_addr, dest;
6728
6729               if (SSE_REGNO_P (REGNO (reg)))
6730                 {
6731                   src_addr = sse_addr;
6732                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
6733                 }
6734               else
6735                 {
6736                   src_addr = int_addr;
6737                   src_offset = REGNO (reg) * 8;
6738                 }
6739               src_addr = fold_convert (addr_type, src_addr);
6740               src_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, src_addr,
6741                                       size_int (src_offset));
6742               src = build_va_arg_indirect_ref (src_addr);
6743
6744               dest_addr = fold_convert (addr_type, addr);
6745               dest_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, dest_addr,
6746                                        size_int (INTVAL (XEXP (slot, 1))));
6747               dest = build_va_arg_indirect_ref (dest_addr);
6748
6749               gimplify_assign (dest, src, pre_p);
6750             }
6751         }
6752
6753       if (needed_intregs)
6754         {
6755           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
6756                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
6757           gimplify_assign (gpr, t, pre_p);
6758         }
6759
6760       if (needed_sseregs)
6761         {
6762           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
6763                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
6764           gimplify_assign (fpr, t, pre_p);
6765         }
6766
6767       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
6768
6769       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
6770     }
6771
6772   /* ... otherwise out of the overflow area.  */
6773
6774   /* When we align parameter on stack for caller, if the parameter
6775      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
6776      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
6777      here with caller.  */
6778   arg_boundary = FUNCTION_ARG_BOUNDARY (VOIDmode, type);
6779   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
6780     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
6781
6782   /* Care for on-stack alignment if needed.  */
6783   if (arg_boundary <= 64
6784       || integer_zerop (TYPE_SIZE (type)))
6785     t = ovf;
6786  else
6787     {
6788       HOST_WIDE_INT align = arg_boundary / 8;
6789       t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovf), ovf,
6790                   size_int (align - 1));
6791       t = fold_convert (sizetype, t);
6792       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
6793                   size_int (-align));
6794       t = fold_convert (TREE_TYPE (ovf), t);
6795     }
6796   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
6797   gimplify_assign (addr, t, pre_p);
6798
6799   t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
6800               size_int (rsize * UNITS_PER_WORD));
6801   gimplify_assign (unshare_expr (ovf), t, pre_p);
6802
6803   if (container)
6804     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
6805
6806   ptrtype = build_pointer_type (type);
6807   addr = fold_convert (ptrtype, addr);
6808
6809   if (indirect_p)
6810     addr = build_va_arg_indirect_ref (addr);
6811   return build_va_arg_indirect_ref (addr);
6812 }
6813 \f
6814 /* Return nonzero if OPNUM's MEM should be matched
6815    in movabs* patterns.  */
6816
6817 int
6818 ix86_check_movabs (rtx insn, int opnum)
6819 {
6820   rtx set, mem;
6821
6822   set = PATTERN (insn);
6823   if (GET_CODE (set) == PARALLEL)
6824     set = XVECEXP (set, 0, 0);
6825   gcc_assert (GET_CODE (set) == SET);
6826   mem = XEXP (set, opnum);
6827   while (GET_CODE (mem) == SUBREG)
6828     mem = SUBREG_REG (mem);
6829   gcc_assert (MEM_P (mem));
6830   return (volatile_ok || !MEM_VOLATILE_P (mem));
6831 }
6832 \f
6833 /* Initialize the table of extra 80387 mathematical constants.  */
6834
6835 static void
6836 init_ext_80387_constants (void)
6837 {
6838   static const char * cst[5] =
6839   {
6840     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
6841     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
6842     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
6843     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
6844     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
6845   };
6846   int i;
6847
6848   for (i = 0; i < 5; i++)
6849     {
6850       real_from_string (&ext_80387_constants_table[i], cst[i]);
6851       /* Ensure each constant is rounded to XFmode precision.  */
6852       real_convert (&ext_80387_constants_table[i],
6853                     XFmode, &ext_80387_constants_table[i]);
6854     }
6855
6856   ext_80387_constants_init = 1;
6857 }
6858
6859 /* Return true if the constant is something that can be loaded with
6860    a special instruction.  */
6861
6862 int
6863 standard_80387_constant_p (rtx x)
6864 {
6865   enum machine_mode mode = GET_MODE (x);
6866
6867   REAL_VALUE_TYPE r;
6868
6869   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
6870     return -1;
6871
6872   if (x == CONST0_RTX (mode))
6873     return 1;
6874   if (x == CONST1_RTX (mode))
6875     return 2;
6876
6877   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
6878
6879   /* For XFmode constants, try to find a special 80387 instruction when
6880      optimizing for size or on those CPUs that benefit from them.  */
6881   if (mode == XFmode
6882       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
6883     {
6884       int i;
6885
6886       if (! ext_80387_constants_init)
6887         init_ext_80387_constants ();
6888
6889       for (i = 0; i < 5; i++)
6890         if (real_identical (&r, &ext_80387_constants_table[i]))
6891           return i + 3;
6892     }
6893
6894   /* Load of the constant -0.0 or -1.0 will be split as
6895      fldz;fchs or fld1;fchs sequence.  */
6896   if (real_isnegzero (&r))
6897     return 8;
6898   if (real_identical (&r, &dconstm1))
6899     return 9;
6900
6901   return 0;
6902 }
6903
6904 /* Return the opcode of the special instruction to be used to load
6905    the constant X.  */
6906
6907 const char *
6908 standard_80387_constant_opcode (rtx x)
6909 {
6910   switch (standard_80387_constant_p (x))
6911     {
6912     case 1:
6913       return "fldz";
6914     case 2:
6915       return "fld1";
6916     case 3:
6917       return "fldlg2";
6918     case 4:
6919       return "fldln2";
6920     case 5:
6921       return "fldl2e";
6922     case 6:
6923       return "fldl2t";
6924     case 7:
6925       return "fldpi";
6926     case 8:
6927     case 9:
6928       return "#";
6929     default:
6930       gcc_unreachable ();
6931     }
6932 }
6933
6934 /* Return the CONST_DOUBLE representing the 80387 constant that is
6935    loaded by the specified special instruction.  The argument IDX
6936    matches the return value from standard_80387_constant_p.  */
6937
6938 rtx
6939 standard_80387_constant_rtx (int idx)
6940 {
6941   int i;
6942
6943   if (! ext_80387_constants_init)
6944     init_ext_80387_constants ();
6945
6946   switch (idx)
6947     {
6948     case 3:
6949     case 4:
6950     case 5:
6951     case 6:
6952     case 7:
6953       i = idx - 3;
6954       break;
6955
6956     default:
6957       gcc_unreachable ();
6958     }
6959
6960   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
6961                                        XFmode);
6962 }
6963
6964 /* Return 1 if mode is a valid mode for sse.  */
6965 static int
6966 standard_sse_mode_p (enum machine_mode mode)
6967 {
6968   switch (mode)
6969     {
6970     case V16QImode:
6971     case V8HImode:
6972     case V4SImode:
6973     case V2DImode:
6974     case V4SFmode:
6975     case V2DFmode:
6976       return 1;
6977
6978     default:
6979       return 0;
6980     }
6981 }
6982
6983 /* Return 1 if X is all 0s.  For all 1s, return 2 if X is in 128bit
6984    SSE modes and SSE2 is enabled,  return 3 if X is in 256bit AVX
6985    modes and AVX is enabled.  */
6986
6987 int
6988 standard_sse_constant_p (rtx x)
6989 {
6990   enum machine_mode mode = GET_MODE (x);
6991
6992   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
6993     return 1;
6994   if (vector_all_ones_operand (x, mode))
6995     {
6996       if (standard_sse_mode_p (mode))
6997         return TARGET_SSE2 ? 2 : -2;
6998       else if (VALID_AVX256_REG_MODE (mode))
6999         return TARGET_AVX ? 3 : -3;
7000     }
7001
7002   return 0;
7003 }
7004
7005 /* Return the opcode of the special instruction to be used to load
7006    the constant X.  */
7007
7008 const char *
7009 standard_sse_constant_opcode (rtx insn, rtx x)
7010 {
7011   switch (standard_sse_constant_p (x))
7012     {
7013     case 1:
7014       switch (get_attr_mode (insn))
7015         {
7016         case MODE_V4SF:
7017           return TARGET_AVX ? "vxorps\t%0, %0, %0" : "xorps\t%0, %0";
7018         case MODE_V2DF:
7019           return TARGET_AVX ? "vxorpd\t%0, %0, %0" : "xorpd\t%0, %0";
7020         case MODE_TI:
7021           return TARGET_AVX ? "vpxor\t%0, %0, %0" : "pxor\t%0, %0";
7022         case MODE_V8SF:
7023           return "vxorps\t%x0, %x0, %x0";
7024         case MODE_V4DF:
7025           return "vxorpd\t%x0, %x0, %x0";
7026         case MODE_OI:
7027           return "vpxor\t%x0, %x0, %x0";
7028         default:
7029           gcc_unreachable ();
7030         }
7031     case 2:
7032       if (TARGET_AVX)
7033         switch (get_attr_mode (insn))
7034           {
7035           case MODE_V4SF:
7036           case MODE_V2DF:
7037           case MODE_TI:
7038             return "vpcmpeqd\t%0, %0, %0";
7039             break;
7040           default:
7041             gcc_unreachable ();
7042         }
7043       else
7044         return "pcmpeqd\t%0, %0";
7045     }
7046   gcc_unreachable ();
7047 }
7048
7049 /* Returns 1 if OP contains a symbol reference */
7050
7051 int
7052 symbolic_reference_mentioned_p (rtx op)
7053 {
7054   const char *fmt;
7055   int i;
7056
7057   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
7058     return 1;
7059
7060   fmt = GET_RTX_FORMAT (GET_CODE (op));
7061   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
7062     {
7063       if (fmt[i] == 'E')
7064         {
7065           int j;
7066
7067           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
7068             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
7069               return 1;
7070         }
7071
7072       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
7073         return 1;
7074     }
7075
7076   return 0;
7077 }
7078
7079 /* Return 1 if it is appropriate to emit `ret' instructions in the
7080    body of a function.  Do this only if the epilogue is simple, needing a
7081    couple of insns.  Prior to reloading, we can't tell how many registers
7082    must be saved, so return 0 then.  Return 0 if there is no frame
7083    marker to de-allocate.  */
7084
7085 int
7086 ix86_can_use_return_insn_p (void)
7087 {
7088   struct ix86_frame frame;
7089
7090   if (! reload_completed || frame_pointer_needed)
7091     return 0;
7092
7093   /* Don't allow more than 32 pop, since that's all we can do
7094      with one instruction.  */
7095   if (crtl->args.pops_args
7096       && crtl->args.size >= 32768)
7097     return 0;
7098
7099   ix86_compute_frame_layout (&frame);
7100   return frame.to_allocate == 0 && frame.nregs == 0;
7101 }
7102 \f
7103 /* Value should be nonzero if functions must have frame pointers.
7104    Zero means the frame pointer need not be set up (and parms may
7105    be accessed via the stack pointer) in functions that seem suitable.  */
7106
7107 int
7108 ix86_frame_pointer_required (void)
7109 {
7110   /* If we accessed previous frames, then the generated code expects
7111      to be able to access the saved ebp value in our frame.  */
7112   if (cfun->machine->accesses_prev_frame)
7113     return 1;
7114
7115   /* Several x86 os'es need a frame pointer for other reasons,
7116      usually pertaining to setjmp.  */
7117   if (SUBTARGET_FRAME_POINTER_REQUIRED)
7118     return 1;
7119
7120   /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
7121      the frame pointer by default.  Turn it back on now if we've not
7122      got a leaf function.  */
7123   if (TARGET_OMIT_LEAF_FRAME_POINTER
7124       && (!current_function_is_leaf
7125           || ix86_current_function_calls_tls_descriptor))
7126     return 1;
7127
7128   if (crtl->profile)
7129     return 1;
7130
7131   return 0;
7132 }
7133
7134 /* Record that the current function accesses previous call frames.  */
7135
7136 void
7137 ix86_setup_frame_addresses (void)
7138 {
7139   cfun->machine->accesses_prev_frame = 1;
7140 }
7141 \f
7142 #if (defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)) || TARGET_MACHO
7143 # define USE_HIDDEN_LINKONCE 1
7144 #else
7145 # define USE_HIDDEN_LINKONCE 0
7146 #endif
7147
7148 static int pic_labels_used;
7149
7150 /* Fills in the label name that should be used for a pc thunk for
7151    the given register.  */
7152
7153 static void
7154 get_pc_thunk_name (char name[32], unsigned int regno)
7155 {
7156   gcc_assert (!TARGET_64BIT);
7157
7158   if (USE_HIDDEN_LINKONCE)
7159     sprintf (name, "__i686.get_pc_thunk.%s", reg_names[regno]);
7160   else
7161     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
7162 }
7163
7164
7165 /* This function generates code for -fpic that loads %ebx with
7166    the return address of the caller and then returns.  */
7167
7168 void
7169 ix86_file_end (void)
7170 {
7171   rtx xops[2];
7172   int regno;
7173
7174   for (regno = 0; regno < 8; ++regno)
7175     {
7176       char name[32];
7177
7178       if (! ((pic_labels_used >> regno) & 1))
7179         continue;
7180
7181       get_pc_thunk_name (name, regno);
7182
7183 #if TARGET_MACHO
7184       if (TARGET_MACHO)
7185         {
7186           switch_to_section (darwin_sections[text_coal_section]);
7187           fputs ("\t.weak_definition\t", asm_out_file);
7188           assemble_name (asm_out_file, name);
7189           fputs ("\n\t.private_extern\t", asm_out_file);
7190           assemble_name (asm_out_file, name);
7191           fputs ("\n", asm_out_file);
7192           ASM_OUTPUT_LABEL (asm_out_file, name);
7193         }
7194       else
7195 #endif
7196       if (USE_HIDDEN_LINKONCE)
7197         {
7198           tree decl;
7199
7200           decl = build_decl (FUNCTION_DECL, get_identifier (name),
7201                              error_mark_node);
7202           TREE_PUBLIC (decl) = 1;
7203           TREE_STATIC (decl) = 1;
7204           DECL_ONE_ONLY (decl) = 1;
7205
7206           (*targetm.asm_out.unique_section) (decl, 0);
7207           switch_to_section (get_named_section (decl, NULL, 0));
7208
7209           (*targetm.asm_out.globalize_label) (asm_out_file, name);
7210           fputs ("\t.hidden\t", asm_out_file);
7211           assemble_name (asm_out_file, name);
7212           fputc ('\n', asm_out_file);
7213           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
7214         }
7215       else
7216         {
7217           switch_to_section (text_section);
7218           ASM_OUTPUT_LABEL (asm_out_file, name);
7219         }
7220
7221       xops[0] = gen_rtx_REG (Pmode, regno);
7222       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
7223       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
7224       output_asm_insn ("ret", xops);
7225     }
7226
7227   if (NEED_INDICATE_EXEC_STACK)
7228     file_end_indicate_exec_stack ();
7229 }
7230
7231 /* Emit code for the SET_GOT patterns.  */
7232
7233 const char *
7234 output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
7235 {
7236   rtx xops[3];
7237
7238   xops[0] = dest;
7239
7240   if (TARGET_VXWORKS_RTP && flag_pic)
7241     {
7242       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
7243       xops[2] = gen_rtx_MEM (Pmode,
7244                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
7245       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
7246
7247       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
7248          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
7249          an unadorned address.  */
7250       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7251       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
7252       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
7253       return "";
7254     }
7255
7256   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
7257
7258   if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
7259     {
7260       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
7261
7262       if (!flag_pic)
7263         output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
7264       else
7265         output_asm_insn ("call\t%a2", xops);
7266
7267 #if TARGET_MACHO
7268       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7269          is what will be referenced by the Mach-O PIC subsystem.  */
7270       if (!label)
7271         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7272 #endif
7273
7274       (*targetm.asm_out.internal_label) (asm_out_file, "L",
7275                                  CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
7276
7277       if (flag_pic)
7278         output_asm_insn ("pop%z0\t%0", xops);
7279     }
7280   else
7281     {
7282       char name[32];
7283       get_pc_thunk_name (name, REGNO (dest));
7284       pic_labels_used |= 1 << REGNO (dest);
7285
7286       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
7287       xops[2] = gen_rtx_MEM (QImode, xops[2]);
7288       output_asm_insn ("call\t%X2", xops);
7289       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7290          is what will be referenced by the Mach-O PIC subsystem.  */
7291 #if TARGET_MACHO
7292       if (!label)
7293         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7294       else
7295         targetm.asm_out.internal_label (asm_out_file, "L",
7296                                            CODE_LABEL_NUMBER (label));
7297 #endif
7298     }
7299
7300   if (TARGET_MACHO)
7301     return "";
7302
7303   if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
7304     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
7305   else
7306     output_asm_insn ("add%z0\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
7307
7308   return "";
7309 }
7310
7311 /* Generate an "push" pattern for input ARG.  */
7312
7313 static rtx
7314 gen_push (rtx arg)
7315 {
7316   return gen_rtx_SET (VOIDmode,
7317                       gen_rtx_MEM (Pmode,
7318                                    gen_rtx_PRE_DEC (Pmode,
7319                                                     stack_pointer_rtx)),
7320                       arg);
7321 }
7322
7323 /* Return >= 0 if there is an unused call-clobbered register available
7324    for the entire function.  */
7325
7326 static unsigned int
7327 ix86_select_alt_pic_regnum (void)
7328 {
7329   if (current_function_is_leaf && !crtl->profile
7330       && !ix86_current_function_calls_tls_descriptor)
7331     {
7332       int i, drap;
7333       /* Can't use the same register for both PIC and DRAP.  */
7334       if (crtl->drap_reg)
7335         drap = REGNO (crtl->drap_reg);
7336       else
7337         drap = -1;
7338       for (i = 2; i >= 0; --i)
7339         if (i != drap && !df_regs_ever_live_p (i))
7340           return i;
7341     }
7342
7343   return INVALID_REGNUM;
7344 }
7345
7346 /* Return 1 if we need to save REGNO.  */
7347 static int
7348 ix86_save_reg (unsigned int regno, int maybe_eh_return)
7349 {
7350   if (pic_offset_table_rtx
7351       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
7352       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
7353           || crtl->profile
7354           || crtl->calls_eh_return
7355           || crtl->uses_const_pool))
7356     {
7357       if (ix86_select_alt_pic_regnum () != INVALID_REGNUM)
7358         return 0;
7359       return 1;
7360     }
7361
7362   if (crtl->calls_eh_return && maybe_eh_return)
7363     {
7364       unsigned i;
7365       for (i = 0; ; i++)
7366         {
7367           unsigned test = EH_RETURN_DATA_REGNO (i);
7368           if (test == INVALID_REGNUM)
7369             break;
7370           if (test == regno)
7371             return 1;
7372         }
7373     }
7374
7375   if (crtl->drap_reg
7376       && regno == REGNO (crtl->drap_reg))
7377     return 1;
7378
7379   return (df_regs_ever_live_p (regno)
7380           && !call_used_regs[regno]
7381           && !fixed_regs[regno]
7382           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
7383 }
7384
7385 /* Return number of registers to be saved on the stack.  */
7386
7387 static int
7388 ix86_nsaved_regs (void)
7389 {
7390   int nregs = 0;
7391   int regno;
7392
7393   for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
7394     if (ix86_save_reg (regno, true))
7395       nregs++;
7396   return nregs;
7397 }
7398
7399 /* Given FROM and TO register numbers, say whether this elimination is
7400    allowed.  If stack alignment is needed, we can only replace argument
7401    pointer with hard frame pointer, or replace frame pointer with stack
7402    pointer.  Otherwise, frame pointer elimination is automatically
7403    handled and all other eliminations are valid.  */
7404
7405 int
7406 ix86_can_eliminate (int from, int to)
7407 {
7408   if (stack_realign_fp)
7409     return ((from == ARG_POINTER_REGNUM
7410              && to == HARD_FRAME_POINTER_REGNUM)
7411             || (from == FRAME_POINTER_REGNUM
7412                 && to == STACK_POINTER_REGNUM));
7413   else
7414     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : 1;
7415 }
7416
7417 /* Return the offset between two registers, one to be eliminated, and the other
7418    its replacement, at the start of a routine.  */
7419
7420 HOST_WIDE_INT
7421 ix86_initial_elimination_offset (int from, int to)
7422 {
7423   struct ix86_frame frame;
7424   ix86_compute_frame_layout (&frame);
7425
7426   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
7427     return frame.hard_frame_pointer_offset;
7428   else if (from == FRAME_POINTER_REGNUM
7429            && to == HARD_FRAME_POINTER_REGNUM)
7430     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
7431   else
7432     {
7433       gcc_assert (to == STACK_POINTER_REGNUM);
7434
7435       if (from == ARG_POINTER_REGNUM)
7436         return frame.stack_pointer_offset;
7437
7438       gcc_assert (from == FRAME_POINTER_REGNUM);
7439       return frame.stack_pointer_offset - frame.frame_pointer_offset;
7440     }
7441 }
7442
7443 /* Fill structure ix86_frame about frame of currently computed function.  */
7444
7445 static void
7446 ix86_compute_frame_layout (struct ix86_frame *frame)
7447 {
7448   HOST_WIDE_INT total_size;
7449   unsigned int stack_alignment_needed;
7450   HOST_WIDE_INT offset;
7451   unsigned int preferred_alignment;
7452   HOST_WIDE_INT size = get_frame_size ();
7453
7454   frame->nregs = ix86_nsaved_regs ();
7455   total_size = size;
7456
7457   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
7458   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
7459
7460   gcc_assert (!size || stack_alignment_needed);
7461   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
7462   gcc_assert (preferred_alignment <= stack_alignment_needed);
7463
7464   /* During reload iteration the amount of registers saved can change.
7465      Recompute the value as needed.  Do not recompute when amount of registers
7466      didn't change as reload does multiple calls to the function and does not
7467      expect the decision to change within single iteration.  */
7468   if (!optimize_function_for_size_p (cfun)
7469       && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
7470     {
7471       int count = frame->nregs;
7472
7473       cfun->machine->use_fast_prologue_epilogue_nregs = count;
7474       /* The fast prologue uses move instead of push to save registers.  This
7475          is significantly longer, but also executes faster as modern hardware
7476          can execute the moves in parallel, but can't do that for push/pop.
7477
7478          Be careful about choosing what prologue to emit:  When function takes
7479          many instructions to execute we may use slow version as well as in
7480          case function is known to be outside hot spot (this is known with
7481          feedback only).  Weight the size of function by number of registers
7482          to save as it is cheap to use one or two push instructions but very
7483          slow to use many of them.  */
7484       if (count)
7485         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7486       if (cfun->function_frequency < FUNCTION_FREQUENCY_NORMAL
7487           || (flag_branch_probabilities
7488               && cfun->function_frequency < FUNCTION_FREQUENCY_HOT))
7489         cfun->machine->use_fast_prologue_epilogue = false;
7490       else
7491         cfun->machine->use_fast_prologue_epilogue
7492            = !expensive_function_p (count);
7493     }
7494   if (TARGET_PROLOGUE_USING_MOVE
7495       && cfun->machine->use_fast_prologue_epilogue)
7496     frame->save_regs_using_mov = true;
7497   else
7498     frame->save_regs_using_mov = false;
7499
7500
7501   /* Skip return address and saved base pointer.  */
7502   offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
7503
7504   frame->hard_frame_pointer_offset = offset;
7505
7506   /* Set offset to aligned because the realigned frame starts from
7507      here.  */
7508   if (stack_realign_fp)
7509     offset = (offset + stack_alignment_needed -1) & -stack_alignment_needed;
7510
7511   /* Register save area */
7512   offset += frame->nregs * UNITS_PER_WORD;
7513
7514   /* Va-arg area */
7515   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
7516   offset += frame->va_arg_size;
7517
7518   /* Align start of frame for local function.  */
7519   frame->padding1 = ((offset + stack_alignment_needed - 1)
7520                      & -stack_alignment_needed) - offset;
7521
7522   offset += frame->padding1;
7523
7524   /* Frame pointer points here.  */
7525   frame->frame_pointer_offset = offset;
7526
7527   offset += size;
7528
7529   /* Add outgoing arguments area.  Can be skipped if we eliminated
7530      all the function calls as dead code.
7531      Skipping is however impossible when function calls alloca.  Alloca
7532      expander assumes that last crtl->outgoing_args_size
7533      of stack frame are unused.  */
7534   if (ACCUMULATE_OUTGOING_ARGS
7535       && (!current_function_is_leaf || cfun->calls_alloca
7536           || ix86_current_function_calls_tls_descriptor))
7537     {
7538       offset += crtl->outgoing_args_size;
7539       frame->outgoing_arguments_size = crtl->outgoing_args_size;
7540     }
7541   else
7542     frame->outgoing_arguments_size = 0;
7543
7544   /* Align stack boundary.  Only needed if we're calling another function
7545      or using alloca.  */
7546   if (!current_function_is_leaf || cfun->calls_alloca
7547       || ix86_current_function_calls_tls_descriptor)
7548     frame->padding2 = ((offset + preferred_alignment - 1)
7549                        & -preferred_alignment) - offset;
7550   else
7551     frame->padding2 = 0;
7552
7553   offset += frame->padding2;
7554
7555   /* We've reached end of stack frame.  */
7556   frame->stack_pointer_offset = offset;
7557
7558   /* Size prologue needs to allocate.  */
7559   frame->to_allocate =
7560     (size + frame->padding1 + frame->padding2
7561      + frame->outgoing_arguments_size + frame->va_arg_size);
7562
7563   if ((!frame->to_allocate && frame->nregs <= 1)
7564       || (TARGET_64BIT && frame->to_allocate >= (HOST_WIDE_INT) 0x80000000))
7565     frame->save_regs_using_mov = false;
7566
7567   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && current_function_sp_is_unchanging
7568       && current_function_is_leaf
7569       && !ix86_current_function_calls_tls_descriptor)
7570     {
7571       frame->red_zone_size = frame->to_allocate;
7572       if (frame->save_regs_using_mov)
7573         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7574       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7575         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
7576     }
7577   else
7578     frame->red_zone_size = 0;
7579   frame->to_allocate -= frame->red_zone_size;
7580   frame->stack_pointer_offset -= frame->red_zone_size;
7581 #if 0
7582   fprintf (stderr, "\n");
7583   fprintf (stderr, "nregs: %ld\n", (long)frame->nregs);
7584   fprintf (stderr, "size: %ld\n", (long)size);
7585   fprintf (stderr, "alignment1: %ld\n", (long)stack_alignment_needed);
7586   fprintf (stderr, "padding1: %ld\n", (long)frame->padding1);
7587   fprintf (stderr, "va_arg: %ld\n", (long)frame->va_arg_size);
7588   fprintf (stderr, "padding2: %ld\n", (long)frame->padding2);
7589   fprintf (stderr, "to_allocate: %ld\n", (long)frame->to_allocate);
7590   fprintf (stderr, "red_zone_size: %ld\n", (long)frame->red_zone_size);
7591   fprintf (stderr, "frame_pointer_offset: %ld\n", (long)frame->frame_pointer_offset);
7592   fprintf (stderr, "hard_frame_pointer_offset: %ld\n",
7593            (long)frame->hard_frame_pointer_offset);
7594   fprintf (stderr, "stack_pointer_offset: %ld\n", (long)frame->stack_pointer_offset);
7595   fprintf (stderr, "current_function_is_leaf: %ld\n", (long)current_function_is_leaf);
7596   fprintf (stderr, "cfun->calls_alloca: %ld\n", (long)cfun->calls_alloca);
7597   fprintf (stderr, "x86_current_function_calls_tls_descriptor: %ld\n", (long)ix86_current_function_calls_tls_descriptor);
7598 #endif
7599 }
7600
7601 /* Emit code to save registers in the prologue.  */
7602
7603 static void
7604 ix86_emit_save_regs (void)
7605 {
7606   unsigned int regno;
7607   rtx insn;
7608
7609   for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0; )
7610     if (ix86_save_reg (regno, true))
7611       {
7612         insn = emit_insn (gen_push (gen_rtx_REG (Pmode, regno)));
7613         RTX_FRAME_RELATED_P (insn) = 1;
7614       }
7615 }
7616
7617 /* Emit code to save registers using MOV insns.  First register
7618    is restored from POINTER + OFFSET.  */
7619 static void
7620 ix86_emit_save_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7621 {
7622   unsigned int regno;
7623   rtx insn;
7624
7625   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7626     if (ix86_save_reg (regno, true))
7627       {
7628         insn = emit_move_insn (adjust_address (gen_rtx_MEM (Pmode, pointer),
7629                                                Pmode, offset),
7630                                gen_rtx_REG (Pmode, regno));
7631         RTX_FRAME_RELATED_P (insn) = 1;
7632         offset += UNITS_PER_WORD;
7633       }
7634 }
7635
7636 /* Expand prologue or epilogue stack adjustment.
7637    The pattern exist to put a dependency on all ebp-based memory accesses.
7638    STYLE should be negative if instructions should be marked as frame related,
7639    zero if %r11 register is live and cannot be freely used and positive
7640    otherwise.  */
7641
7642 static void
7643 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset, int style)
7644 {
7645   rtx insn;
7646
7647   if (! TARGET_64BIT)
7648     insn = emit_insn (gen_pro_epilogue_adjust_stack_1 (dest, src, offset));
7649   else if (x86_64_immediate_operand (offset, DImode))
7650     insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64 (dest, src, offset));
7651   else
7652     {
7653       rtx r11;
7654       /* r11 is used by indirect sibcall return as well, set before the
7655          epilogue and used after the epilogue.  ATM indirect sibcall
7656          shouldn't be used together with huge frame sizes in one
7657          function because of the frame_size check in sibcall.c.  */
7658       gcc_assert (style);
7659       r11 = gen_rtx_REG (DImode, R11_REG);
7660       insn = emit_insn (gen_rtx_SET (DImode, r11, offset));
7661       if (style < 0)
7662         RTX_FRAME_RELATED_P (insn) = 1;
7663       insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64_2 (dest, src, r11,
7664                                                                offset));
7665     }
7666   if (style < 0)
7667     RTX_FRAME_RELATED_P (insn) = 1;
7668 }
7669
7670 /* Find an available register to be used as dynamic realign argument
7671    pointer regsiter.  Such a register will be written in prologue and
7672    used in begin of body, so it must not be
7673         1. parameter passing register.
7674         2. GOT pointer.
7675    We reuse static-chain register if it is available.  Otherwise, we
7676    use DI for i386 and R13 for x86-64.  We chose R13 since it has
7677    shorter encoding.
7678
7679    Return: the regno of chosen register.  */
7680
7681 static unsigned int 
7682 find_drap_reg (void)
7683 {
7684   tree decl = cfun->decl;
7685
7686   if (TARGET_64BIT)
7687     {
7688       /* Use R13 for nested function or function need static chain.
7689          Since function with tail call may use any caller-saved
7690          registers in epilogue, DRAP must not use caller-saved
7691          register in such case.  */
7692       if ((decl_function_context (decl)
7693            && !DECL_NO_STATIC_CHAIN (decl))
7694           || crtl->tail_call_emit)
7695         return R13_REG;
7696
7697       return R10_REG;
7698     }
7699   else
7700     {
7701       /* Use DI for nested function or function need static chain.
7702          Since function with tail call may use any caller-saved
7703          registers in epilogue, DRAP must not use caller-saved
7704          register in such case.  */
7705       if ((decl_function_context (decl)
7706            && !DECL_NO_STATIC_CHAIN (decl))
7707           || crtl->tail_call_emit)
7708         return DI_REG;
7709     
7710       /* Reuse static chain register if it isn't used for parameter
7711          passing.  */
7712       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2
7713           && !lookup_attribute ("fastcall",
7714                                 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
7715         return CX_REG;
7716       else
7717         return DI_REG;
7718     }
7719 }
7720
7721 /* Update incoming stack boundary and estimated stack alignment.  */
7722
7723 static void
7724 ix86_update_stack_boundary (void)
7725 {
7726   /* Prefer the one specified at command line. */
7727   ix86_incoming_stack_boundary 
7728     = (ix86_user_incoming_stack_boundary
7729        ? ix86_user_incoming_stack_boundary
7730        : ix86_default_incoming_stack_boundary);
7731
7732   /* Incoming stack alignment can be changed on individual functions
7733      via force_align_arg_pointer attribute.  We use the smallest
7734      incoming stack boundary.  */
7735   if (ix86_incoming_stack_boundary > MIN_STACK_BOUNDARY
7736       && lookup_attribute (ix86_force_align_arg_pointer_string,
7737                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
7738     ix86_incoming_stack_boundary = MIN_STACK_BOUNDARY;
7739
7740   /* Stack at entrance of main is aligned by runtime.  We use the
7741      smallest incoming stack boundary. */
7742   if (ix86_incoming_stack_boundary > MAIN_STACK_BOUNDARY
7743       && DECL_NAME (current_function_decl)
7744       && MAIN_NAME_P (DECL_NAME (current_function_decl))
7745       && DECL_FILE_SCOPE_P (current_function_decl))
7746     ix86_incoming_stack_boundary = MAIN_STACK_BOUNDARY;
7747
7748   /* x86_64 vararg needs 16byte stack alignment for register save
7749      area.  */
7750   if (TARGET_64BIT
7751       && cfun->stdarg
7752       && crtl->stack_alignment_estimated < 128)
7753     crtl->stack_alignment_estimated = 128;
7754 }
7755
7756 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
7757    needed or an rtx for DRAP otherwise.  */
7758
7759 static rtx
7760 ix86_get_drap_rtx (void)
7761 {
7762   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
7763     crtl->need_drap = true;
7764
7765   if (stack_realign_drap)
7766     {
7767       /* Assign DRAP to vDRAP and returns vDRAP */
7768       unsigned int regno = find_drap_reg ();
7769       rtx drap_vreg;
7770       rtx arg_ptr;
7771       rtx seq, insn;
7772
7773       arg_ptr = gen_rtx_REG (Pmode, regno);
7774       crtl->drap_reg = arg_ptr;
7775
7776       start_sequence ();
7777       drap_vreg = copy_to_reg (arg_ptr);
7778       seq = get_insns ();
7779       end_sequence ();
7780       
7781       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
7782       RTX_FRAME_RELATED_P (insn) = 1;
7783       return drap_vreg;
7784     }
7785   else
7786     return NULL;
7787 }
7788
7789 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
7790
7791 static rtx
7792 ix86_internal_arg_pointer (void)
7793 {
7794   return virtual_incoming_args_rtx;
7795 }
7796
7797 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
7798    This is called from dwarf2out.c to emit call frame instructions
7799    for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
7800 static void
7801 ix86_dwarf_handle_frame_unspec (const char *label, rtx pattern, int index)
7802 {
7803   rtx unspec = SET_SRC (pattern);
7804   gcc_assert (GET_CODE (unspec) == UNSPEC);
7805
7806   switch (index)
7807     {
7808     case UNSPEC_REG_SAVE:
7809       dwarf2out_reg_save_reg (label, XVECEXP (unspec, 0, 0),
7810                               SET_DEST (pattern));
7811       break;
7812     case UNSPEC_DEF_CFA:
7813       dwarf2out_def_cfa (label, REGNO (SET_DEST (pattern)),
7814                          INTVAL (XVECEXP (unspec, 0, 0)));
7815       break;
7816     default:
7817       gcc_unreachable ();
7818     }
7819 }
7820
7821 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
7822    to be generated in correct form.  */
7823 static void 
7824 ix86_finalize_stack_realign_flags (void)
7825 {
7826   /* Check if stack realign is really needed after reload, and 
7827      stores result in cfun */
7828   unsigned int incoming_stack_boundary
7829     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
7830        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
7831   unsigned int stack_realign = (incoming_stack_boundary
7832                                 < (current_function_is_leaf
7833                                    ? crtl->max_used_stack_slot_alignment
7834                                    : crtl->stack_alignment_needed));
7835
7836   if (crtl->stack_realign_finalized)
7837     {
7838       /* After stack_realign_needed is finalized, we can't no longer
7839          change it.  */
7840       gcc_assert (crtl->stack_realign_needed == stack_realign);
7841     }
7842   else
7843     {
7844       crtl->stack_realign_needed = stack_realign;
7845       crtl->stack_realign_finalized = true;
7846     }
7847 }
7848
7849 /* Expand the prologue into a bunch of separate insns.  */
7850
7851 void
7852 ix86_expand_prologue (void)
7853 {
7854   rtx insn;
7855   bool pic_reg_used;
7856   struct ix86_frame frame;
7857   HOST_WIDE_INT allocate;
7858
7859   ix86_finalize_stack_realign_flags ();
7860
7861   /* DRAP should not coexist with stack_realign_fp */
7862   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
7863
7864   ix86_compute_frame_layout (&frame);
7865
7866   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
7867      of DRAP is needed and stack realignment is really needed after reload */
7868   if (crtl->drap_reg && crtl->stack_realign_needed)
7869     {
7870       rtx x, y;
7871       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
7872       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
7873                               ? 0 : UNITS_PER_WORD);
7874
7875       gcc_assert (stack_realign_drap);
7876
7877       /* Grab the argument pointer.  */
7878       x = plus_constant (stack_pointer_rtx, 
7879                          (UNITS_PER_WORD + param_ptr_offset));
7880       y = crtl->drap_reg;
7881
7882       /* Only need to push parameter pointer reg if it is caller
7883          saved reg */
7884       if (!call_used_regs[REGNO (crtl->drap_reg)])
7885         {
7886           /* Push arg pointer reg */
7887           insn = emit_insn (gen_push (y));
7888           RTX_FRAME_RELATED_P (insn) = 1;
7889         }
7890
7891       insn = emit_insn (gen_rtx_SET (VOIDmode, y, x));
7892       RTX_FRAME_RELATED_P (insn) = 1; 
7893
7894       /* Align the stack.  */
7895       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
7896                                            stack_pointer_rtx,
7897                                            GEN_INT (-align_bytes)));
7898       RTX_FRAME_RELATED_P (insn) = 1;
7899
7900       /* Replicate the return address on the stack so that return
7901          address can be reached via (argp - 1) slot.  This is needed
7902          to implement macro RETURN_ADDR_RTX and intrinsic function
7903          expand_builtin_return_addr etc.  */
7904       x = crtl->drap_reg;
7905       x = gen_frame_mem (Pmode,
7906                          plus_constant (x, -UNITS_PER_WORD));
7907       insn = emit_insn (gen_push (x));
7908       RTX_FRAME_RELATED_P (insn) = 1;
7909     }
7910
7911   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
7912      slower on all targets.  Also sdb doesn't like it.  */
7913
7914   if (frame_pointer_needed)
7915     {
7916       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
7917       RTX_FRAME_RELATED_P (insn) = 1;
7918
7919       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
7920       RTX_FRAME_RELATED_P (insn) = 1;
7921     }
7922
7923   if (stack_realign_fp)
7924     {
7925       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
7926       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
7927
7928       /* Align the stack.  */
7929       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
7930                                            stack_pointer_rtx,
7931                                            GEN_INT (-align_bytes)));
7932       RTX_FRAME_RELATED_P (insn) = 1;
7933     }
7934
7935   allocate = frame.to_allocate;
7936
7937   if (!frame.save_regs_using_mov)
7938     ix86_emit_save_regs ();
7939   else
7940     allocate += frame.nregs * UNITS_PER_WORD;
7941
7942   /* When using red zone we may start register saving before allocating
7943      the stack frame saving one cycle of the prologue. However I will
7944      avoid doing this if I am going to have to probe the stack since
7945      at least on x86_64 the stack probe can turn into a call that clobbers
7946      a red zone location */
7947   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && frame.save_regs_using_mov
7948       && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT))
7949     ix86_emit_save_regs_using_mov ((frame_pointer_needed
7950                                      && !crtl->stack_realign_needed) 
7951                                    ? hard_frame_pointer_rtx
7952                                    : stack_pointer_rtx,
7953                                    -frame.nregs * UNITS_PER_WORD);
7954
7955   if (allocate == 0)
7956     ;
7957   else if (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)
7958     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
7959                                GEN_INT (-allocate), -1);
7960   else
7961     {
7962       /* Only valid for Win32.  */
7963       rtx eax = gen_rtx_REG (Pmode, AX_REG);
7964       bool eax_live;
7965       rtx t;
7966
7967       gcc_assert (!TARGET_64BIT || cfun->machine->call_abi == MS_ABI);
7968
7969       if (cfun->machine->call_abi == MS_ABI)
7970         eax_live = false;
7971       else
7972         eax_live = ix86_eax_live_at_start_p ();
7973
7974       if (eax_live)
7975         {
7976           emit_insn (gen_push (eax));
7977           allocate -= UNITS_PER_WORD;
7978         }
7979
7980       emit_move_insn (eax, GEN_INT (allocate));
7981
7982       if (TARGET_64BIT)
7983         insn = gen_allocate_stack_worker_64 (eax);
7984       else
7985         insn = gen_allocate_stack_worker_32 (eax);
7986       insn = emit_insn (insn);
7987       RTX_FRAME_RELATED_P (insn) = 1;
7988       t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (-allocate));
7989       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
7990       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7991                                             t, REG_NOTES (insn));
7992
7993       if (eax_live)
7994         {
7995           if (frame_pointer_needed)
7996             t = plus_constant (hard_frame_pointer_rtx,
7997                                allocate
7998                                - frame.to_allocate
7999                                - frame.nregs * UNITS_PER_WORD);
8000           else
8001             t = plus_constant (stack_pointer_rtx, allocate);
8002           emit_move_insn (eax, gen_rtx_MEM (Pmode, t));
8003         }
8004     }
8005
8006   if (frame.save_regs_using_mov
8007       && !(!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
8008          && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)))
8009     {
8010       if (!frame_pointer_needed
8011           || !frame.to_allocate
8012           || crtl->stack_realign_needed)
8013         ix86_emit_save_regs_using_mov (stack_pointer_rtx,
8014                                        frame.to_allocate);
8015       else
8016         ix86_emit_save_regs_using_mov (hard_frame_pointer_rtx,
8017                                        -frame.nregs * UNITS_PER_WORD);
8018     }
8019
8020   pic_reg_used = false;
8021   if (pic_offset_table_rtx
8022       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
8023           || crtl->profile))
8024     {
8025       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
8026
8027       if (alt_pic_reg_used != INVALID_REGNUM)
8028         SET_REGNO (pic_offset_table_rtx, alt_pic_reg_used);
8029
8030       pic_reg_used = true;
8031     }
8032
8033   if (pic_reg_used)
8034     {
8035       if (TARGET_64BIT)
8036         {
8037           if (ix86_cmodel == CM_LARGE_PIC)
8038             {
8039               rtx tmp_reg = gen_rtx_REG (DImode, R11_REG);
8040               rtx label = gen_label_rtx ();
8041               emit_label (label);
8042               LABEL_PRESERVE_P (label) = 1;
8043               gcc_assert (REGNO (pic_offset_table_rtx) != REGNO (tmp_reg));
8044               insn = emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, label));
8045               insn = emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
8046               insn = emit_insn (gen_adddi3 (pic_offset_table_rtx,
8047                                             pic_offset_table_rtx, tmp_reg));
8048             }
8049           else
8050             insn = emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
8051         }
8052       else
8053         insn = emit_insn (gen_set_got (pic_offset_table_rtx));
8054     }
8055
8056   /* Prevent function calls from being scheduled before the call to mcount.
8057      In the pic_reg_used case, make sure that the got load isn't deleted.  */
8058   if (crtl->profile)
8059     {
8060       if (pic_reg_used)
8061         emit_insn (gen_prologue_use (pic_offset_table_rtx));
8062       emit_insn (gen_blockage ());
8063     }
8064
8065   if (crtl->drap_reg && !crtl->stack_realign_needed)
8066     {
8067       /* vDRAP is setup but after reload it turns out stack realign
8068          isn't necessary, here we will emit prologue to setup DRAP
8069          without stack realign adjustment */
8070       int drap_bp_offset = UNITS_PER_WORD * 2;
8071       rtx x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
8072       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, x));
8073     }
8074
8075   /* Emit cld instruction if stringops are used in the function.  */
8076   if (TARGET_CLD && ix86_current_function_needs_cld)
8077     emit_insn (gen_cld ());
8078 }
8079
8080 /* Emit code to restore saved registers using MOV insns.  First register
8081    is restored from POINTER + OFFSET.  */
8082 static void
8083 ix86_emit_restore_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8084                                   int maybe_eh_return)
8085 {
8086   int regno;
8087   rtx base_address = gen_rtx_MEM (Pmode, pointer);
8088
8089   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8090     if (ix86_save_reg (regno, maybe_eh_return))
8091       {
8092         /* Ensure that adjust_address won't be forced to produce pointer
8093            out of range allowed by x86-64 instruction set.  */
8094         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8095           {
8096             rtx r11;
8097
8098             r11 = gen_rtx_REG (DImode, R11_REG);
8099             emit_move_insn (r11, GEN_INT (offset));
8100             emit_insn (gen_adddi3 (r11, r11, pointer));
8101             base_address = gen_rtx_MEM (Pmode, r11);
8102             offset = 0;
8103           }
8104         emit_move_insn (gen_rtx_REG (Pmode, regno),
8105                         adjust_address (base_address, Pmode, offset));
8106         offset += UNITS_PER_WORD;
8107       }
8108 }
8109
8110 /* Restore function stack, frame, and registers.  */
8111
8112 void
8113 ix86_expand_epilogue (int style)
8114 {
8115   int regno;
8116   int sp_valid;
8117   struct ix86_frame frame;
8118   HOST_WIDE_INT offset;
8119
8120   ix86_finalize_stack_realign_flags ();
8121
8122  /* When stack is realigned, SP must be valid.  */
8123   sp_valid = (!frame_pointer_needed
8124               || current_function_sp_is_unchanging
8125               || stack_realign_fp);
8126
8127   ix86_compute_frame_layout (&frame);
8128
8129   /* Calculate start of saved registers relative to ebp.  Special care
8130      must be taken for the normal return case of a function using
8131      eh_return: the eax and edx registers are marked as saved, but not
8132      restored along this path.  */
8133   offset = frame.nregs;
8134   if (crtl->calls_eh_return && style != 2)
8135     offset -= 2;
8136   offset *= -UNITS_PER_WORD;
8137
8138   /* If we're only restoring one register and sp is not valid then
8139      using a move instruction to restore the register since it's
8140      less work than reloading sp and popping the register.
8141
8142      The default code result in stack adjustment using add/lea instruction,
8143      while this code results in LEAVE instruction (or discrete equivalent),
8144      so it is profitable in some other cases as well.  Especially when there
8145      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
8146      and there is exactly one register to pop. This heuristic may need some
8147      tuning in future.  */
8148   if ((!sp_valid && frame.nregs <= 1)
8149       || (TARGET_EPILOGUE_USING_MOVE
8150           && cfun->machine->use_fast_prologue_epilogue
8151           && (frame.nregs > 1 || frame.to_allocate))
8152       || (frame_pointer_needed && !frame.nregs && frame.to_allocate)
8153       || (frame_pointer_needed && TARGET_USE_LEAVE
8154           && cfun->machine->use_fast_prologue_epilogue
8155           && frame.nregs == 1)
8156       || crtl->calls_eh_return)
8157     {
8158       /* Restore registers.  We can use ebp or esp to address the memory
8159          locations.  If both are available, default to ebp, since offsets
8160          are known to be small.  Only exception is esp pointing directly
8161          to the end of block of saved registers, where we may simplify
8162          addressing mode.  
8163
8164          If we are realigning stack with bp and sp, regs restore can't
8165          be addressed by bp. sp must be used instead.  */
8166
8167       if (!frame_pointer_needed
8168           || (sp_valid && !frame.to_allocate) 
8169           || stack_realign_fp)
8170         ix86_emit_restore_regs_using_mov (stack_pointer_rtx,
8171                                           frame.to_allocate, style == 2);
8172       else
8173         ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx,
8174                                           offset, style == 2);
8175
8176       /* eh_return epilogues need %ecx added to the stack pointer.  */
8177       if (style == 2)
8178         {
8179           rtx tmp, sa = EH_RETURN_STACKADJ_RTX;
8180
8181           /* Stack align doesn't work with eh_return.  */
8182           gcc_assert (!crtl->stack_realign_needed);
8183
8184           if (frame_pointer_needed)
8185             {
8186               tmp = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
8187               tmp = plus_constant (tmp, UNITS_PER_WORD);
8188               emit_insn (gen_rtx_SET (VOIDmode, sa, tmp));
8189
8190               tmp = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
8191               emit_move_insn (hard_frame_pointer_rtx, tmp);
8192
8193               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
8194                                          const0_rtx, style);
8195             }
8196           else
8197             {
8198               tmp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
8199               tmp = plus_constant (tmp, (frame.to_allocate
8200                                          + frame.nregs * UNITS_PER_WORD));
8201               emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp));
8202             }
8203         }
8204       else if (!frame_pointer_needed)
8205         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8206                                    GEN_INT (frame.to_allocate
8207                                             + frame.nregs * UNITS_PER_WORD),
8208                                    style);
8209       /* If not an i386, mov & pop is faster than "leave".  */
8210       else if (TARGET_USE_LEAVE || optimize_function_for_size_p (cfun)
8211                || !cfun->machine->use_fast_prologue_epilogue)
8212         emit_insn ((*ix86_gen_leave) ());
8213       else
8214         {
8215           pro_epilogue_adjust_stack (stack_pointer_rtx,
8216                                      hard_frame_pointer_rtx,
8217                                      const0_rtx, style);
8218
8219           emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8220         }
8221     }
8222   else
8223     {
8224       /* First step is to deallocate the stack frame so that we can
8225          pop the registers.
8226
8227          If we realign stack with frame pointer, then stack pointer
8228          won't be able to recover via lea $offset(%bp), %sp, because
8229          there is a padding area between bp and sp for realign. 
8230          "add $to_allocate, %sp" must be used instead.  */
8231       if (!sp_valid)
8232         {
8233           gcc_assert (frame_pointer_needed);
8234           gcc_assert (!stack_realign_fp);
8235           pro_epilogue_adjust_stack (stack_pointer_rtx,
8236                                      hard_frame_pointer_rtx,
8237                                      GEN_INT (offset), style);
8238         }
8239       else if (frame.to_allocate)
8240         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8241                                    GEN_INT (frame.to_allocate), style);
8242
8243       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8244         if (ix86_save_reg (regno, false))
8245           emit_insn ((*ix86_gen_pop1) (gen_rtx_REG (Pmode, regno)));
8246       if (frame_pointer_needed)
8247         {
8248           /* Leave results in shorter dependency chains on CPUs that are
8249              able to grok it fast.  */
8250           if (TARGET_USE_LEAVE)
8251             emit_insn ((*ix86_gen_leave) ());
8252           else
8253             {
8254               /* For stack realigned really happens, recover stack 
8255                  pointer to hard frame pointer is a must, if not using 
8256                  leave.  */
8257               if (stack_realign_fp)
8258                 pro_epilogue_adjust_stack (stack_pointer_rtx,
8259                                            hard_frame_pointer_rtx,
8260                                            const0_rtx, style);
8261               emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8262             }
8263         }
8264     }
8265
8266   if (crtl->drap_reg && crtl->stack_realign_needed)
8267     {
8268       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8269                               ? 0 : UNITS_PER_WORD);
8270       gcc_assert (stack_realign_drap);
8271       emit_insn ((*ix86_gen_add3) (stack_pointer_rtx,
8272                                    crtl->drap_reg,
8273                                    GEN_INT (-(UNITS_PER_WORD
8274                                               + param_ptr_offset))));
8275       if (!call_used_regs[REGNO (crtl->drap_reg)])
8276         emit_insn ((*ix86_gen_pop1) (crtl->drap_reg));
8277       
8278     }
8279
8280   /* Sibcall epilogues don't want a return instruction.  */
8281   if (style == 0)
8282     return;
8283
8284   if (crtl->args.pops_args && crtl->args.size)
8285     {
8286       rtx popc = GEN_INT (crtl->args.pops_args);
8287
8288       /* i386 can only pop 64K bytes.  If asked to pop more, pop
8289          return address, do explicit add, and jump indirectly to the
8290          caller.  */
8291
8292       if (crtl->args.pops_args >= 65536)
8293         {
8294           rtx ecx = gen_rtx_REG (SImode, CX_REG);
8295
8296           /* There is no "pascal" calling convention in any 64bit ABI.  */
8297           gcc_assert (!TARGET_64BIT);
8298
8299           emit_insn (gen_popsi1 (ecx));
8300           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc));
8301           emit_jump_insn (gen_return_indirect_internal (ecx));
8302         }
8303       else
8304         emit_jump_insn (gen_return_pop_internal (popc));
8305     }
8306   else
8307     emit_jump_insn (gen_return_internal ());
8308 }
8309
8310 /* Reset from the function's potential modifications.  */
8311
8312 static void
8313 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
8314                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
8315 {
8316   if (pic_offset_table_rtx)
8317     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
8318 #if TARGET_MACHO
8319   /* Mach-O doesn't support labels at the end of objects, so if
8320      it looks like we might want one, insert a NOP.  */
8321   {
8322     rtx insn = get_last_insn ();
8323     while (insn
8324            && NOTE_P (insn)
8325            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
8326       insn = PREV_INSN (insn);
8327     if (insn
8328         && (LABEL_P (insn)
8329             || (NOTE_P (insn)
8330                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
8331       fputs ("\tnop\n", file);
8332   }
8333 #endif
8334
8335 }
8336 \f
8337 /* Extract the parts of an RTL expression that is a valid memory address
8338    for an instruction.  Return 0 if the structure of the address is
8339    grossly off.  Return -1 if the address contains ASHIFT, so it is not
8340    strictly valid, but still used for computing length of lea instruction.  */
8341
8342 int
8343 ix86_decompose_address (rtx addr, struct ix86_address *out)
8344 {
8345   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
8346   rtx base_reg, index_reg;
8347   HOST_WIDE_INT scale = 1;
8348   rtx scale_rtx = NULL_RTX;
8349   int retval = 1;
8350   enum ix86_address_seg seg = SEG_DEFAULT;
8351
8352   if (REG_P (addr) || GET_CODE (addr) == SUBREG)
8353     base = addr;
8354   else if (GET_CODE (addr) == PLUS)
8355     {
8356       rtx addends[4], op;
8357       int n = 0, i;
8358
8359       op = addr;
8360       do
8361         {
8362           if (n >= 4)
8363             return 0;
8364           addends[n++] = XEXP (op, 1);
8365           op = XEXP (op, 0);
8366         }
8367       while (GET_CODE (op) == PLUS);
8368       if (n >= 4)
8369         return 0;
8370       addends[n] = op;
8371
8372       for (i = n; i >= 0; --i)
8373         {
8374           op = addends[i];
8375           switch (GET_CODE (op))
8376             {
8377             case MULT:
8378               if (index)
8379                 return 0;
8380               index = XEXP (op, 0);
8381               scale_rtx = XEXP (op, 1);
8382               break;
8383
8384             case UNSPEC:
8385               if (XINT (op, 1) == UNSPEC_TP
8386                   && TARGET_TLS_DIRECT_SEG_REFS
8387                   && seg == SEG_DEFAULT)
8388                 seg = TARGET_64BIT ? SEG_FS : SEG_GS;
8389               else
8390                 return 0;
8391               break;
8392
8393             case REG:
8394             case SUBREG:
8395               if (!base)
8396                 base = op;
8397               else if (!index)
8398                 index = op;
8399               else
8400                 return 0;
8401               break;
8402
8403             case CONST:
8404             case CONST_INT:
8405             case SYMBOL_REF:
8406             case LABEL_REF:
8407               if (disp)
8408                 return 0;
8409               disp = op;
8410               break;
8411
8412             default:
8413               return 0;
8414             }
8415         }
8416     }
8417   else if (GET_CODE (addr) == MULT)
8418     {
8419       index = XEXP (addr, 0);           /* index*scale */
8420       scale_rtx = XEXP (addr, 1);
8421     }
8422   else if (GET_CODE (addr) == ASHIFT)
8423     {
8424       rtx tmp;
8425
8426       /* We're called for lea too, which implements ashift on occasion.  */
8427       index = XEXP (addr, 0);
8428       tmp = XEXP (addr, 1);
8429       if (!CONST_INT_P (tmp))
8430         return 0;
8431       scale = INTVAL (tmp);
8432       if ((unsigned HOST_WIDE_INT) scale > 3)
8433         return 0;
8434       scale = 1 << scale;
8435       retval = -1;
8436     }
8437   else
8438     disp = addr;                        /* displacement */
8439
8440   /* Extract the integral value of scale.  */
8441   if (scale_rtx)
8442     {
8443       if (!CONST_INT_P (scale_rtx))
8444         return 0;
8445       scale = INTVAL (scale_rtx);
8446     }
8447
8448   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
8449   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
8450
8451   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
8452   if (base_reg && index_reg && scale == 1
8453       && (index_reg == arg_pointer_rtx
8454           || index_reg == frame_pointer_rtx
8455           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
8456     {
8457       rtx tmp;
8458       tmp = base, base = index, index = tmp;
8459       tmp = base_reg, base_reg = index_reg, index_reg = tmp;
8460     }
8461
8462   /* Special case: %ebp cannot be encoded as a base without a displacement.  */
8463   if ((base_reg == hard_frame_pointer_rtx
8464        || base_reg == frame_pointer_rtx
8465        || base_reg == arg_pointer_rtx) && !disp)
8466     disp = const0_rtx;
8467
8468   /* Special case: on K6, [%esi] makes the instruction vector decoded.
8469      Avoid this by transforming to [%esi+0].
8470      Reload calls address legitimization without cfun defined, so we need
8471      to test cfun for being non-NULL. */
8472   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
8473       && base_reg && !index_reg && !disp
8474       && REG_P (base_reg)
8475       && REGNO_REG_CLASS (REGNO (base_reg)) == SIREG)
8476     disp = const0_rtx;
8477
8478   /* Special case: encode reg+reg instead of reg*2.  */
8479   if (!base && index && scale && scale == 2)
8480     base = index, base_reg = index_reg, scale = 1;
8481
8482   /* Special case: scaling cannot be encoded without base or displacement.  */
8483   if (!base && !disp && index && scale != 1)
8484     disp = const0_rtx;
8485
8486   out->base = base;
8487   out->index = index;
8488   out->disp = disp;
8489   out->scale = scale;
8490   out->seg = seg;
8491
8492   return retval;
8493 }
8494 \f
8495 /* Return cost of the memory address x.
8496    For i386, it is better to use a complex address than let gcc copy
8497    the address into a reg and make a new pseudo.  But not if the address
8498    requires to two regs - that would mean more pseudos with longer
8499    lifetimes.  */
8500 static int
8501 ix86_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
8502 {
8503   struct ix86_address parts;
8504   int cost = 1;
8505   int ok = ix86_decompose_address (x, &parts);
8506
8507   gcc_assert (ok);
8508
8509   if (parts.base && GET_CODE (parts.base) == SUBREG)
8510     parts.base = SUBREG_REG (parts.base);
8511   if (parts.index && GET_CODE (parts.index) == SUBREG)
8512     parts.index = SUBREG_REG (parts.index);
8513
8514   /* Attempt to minimize number of registers in the address.  */
8515   if ((parts.base
8516        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
8517       || (parts.index
8518           && (!REG_P (parts.index)
8519               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
8520     cost++;
8521
8522   if (parts.base
8523       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
8524       && parts.index
8525       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
8526       && parts.base != parts.index)
8527     cost++;
8528
8529   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
8530      since it's predecode logic can't detect the length of instructions
8531      and it degenerates to vector decoded.  Increase cost of such
8532      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
8533      to split such addresses or even refuse such addresses at all.
8534
8535      Following addressing modes are affected:
8536       [base+scale*index]
8537       [scale*index+disp]
8538       [base+index]
8539
8540      The first and last case  may be avoidable by explicitly coding the zero in
8541      memory address, but I don't have AMD-K6 machine handy to check this
8542      theory.  */
8543
8544   if (TARGET_K6
8545       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
8546           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
8547           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
8548     cost += 10;
8549
8550   return cost;
8551 }
8552 \f
8553 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
8554    this is used for to form addresses to local data when -fPIC is in
8555    use.  */
8556
8557 static bool
8558 darwin_local_data_pic (rtx disp)
8559 {
8560   return (GET_CODE (disp) == UNSPEC
8561           && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
8562 }
8563
8564 /* Determine if a given RTX is a valid constant.  We already know this
8565    satisfies CONSTANT_P.  */
8566
8567 bool
8568 legitimate_constant_p (rtx x)
8569 {
8570   switch (GET_CODE (x))
8571     {
8572     case CONST:
8573       x = XEXP (x, 0);
8574
8575       if (GET_CODE (x) == PLUS)
8576         {
8577           if (!CONST_INT_P (XEXP (x, 1)))
8578             return false;
8579           x = XEXP (x, 0);
8580         }
8581
8582       if (TARGET_MACHO && darwin_local_data_pic (x))
8583         return true;
8584
8585       /* Only some unspecs are valid as "constants".  */
8586       if (GET_CODE (x) == UNSPEC)
8587         switch (XINT (x, 1))
8588           {
8589           case UNSPEC_GOT:
8590           case UNSPEC_GOTOFF:
8591           case UNSPEC_PLTOFF:
8592             return TARGET_64BIT;
8593           case UNSPEC_TPOFF:
8594           case UNSPEC_NTPOFF:
8595             x = XVECEXP (x, 0, 0);
8596             return (GET_CODE (x) == SYMBOL_REF
8597                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8598           case UNSPEC_DTPOFF:
8599             x = XVECEXP (x, 0, 0);
8600             return (GET_CODE (x) == SYMBOL_REF
8601                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
8602           default:
8603             return false;
8604           }
8605
8606       /* We must have drilled down to a symbol.  */
8607       if (GET_CODE (x) == LABEL_REF)
8608         return true;
8609       if (GET_CODE (x) != SYMBOL_REF)
8610         return false;
8611       /* FALLTHRU */
8612
8613     case SYMBOL_REF:
8614       /* TLS symbols are never valid.  */
8615       if (SYMBOL_REF_TLS_MODEL (x))
8616         return false;
8617
8618       /* DLLIMPORT symbols are never valid.  */
8619       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8620           && SYMBOL_REF_DLLIMPORT_P (x))
8621         return false;
8622       break;
8623
8624     case CONST_DOUBLE:
8625       if (GET_MODE (x) == TImode
8626           && x != CONST0_RTX (TImode)
8627           && !TARGET_64BIT)
8628         return false;
8629       break;
8630
8631     case CONST_VECTOR:
8632       if (x == CONST0_RTX (GET_MODE (x)))
8633         return true;
8634       return false;
8635
8636     default:
8637       break;
8638     }
8639
8640   /* Otherwise we handle everything else in the move patterns.  */
8641   return true;
8642 }
8643
8644 /* Determine if it's legal to put X into the constant pool.  This
8645    is not possible for the address of thread-local symbols, which
8646    is checked above.  */
8647
8648 static bool
8649 ix86_cannot_force_const_mem (rtx x)
8650 {
8651   /* We can always put integral constants and vectors in memory.  */
8652   switch (GET_CODE (x))
8653     {
8654     case CONST_INT:
8655     case CONST_DOUBLE:
8656     case CONST_VECTOR:
8657       return false;
8658
8659     default:
8660       break;
8661     }
8662   return !legitimate_constant_p (x);
8663 }
8664
8665 /* Determine if a given RTX is a valid constant address.  */
8666
8667 bool
8668 constant_address_p (rtx x)
8669 {
8670   return CONSTANT_P (x) && legitimate_address_p (Pmode, x, 1);
8671 }
8672
8673 /* Nonzero if the constant value X is a legitimate general operand
8674    when generating PIC code.  It is given that flag_pic is on and
8675    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
8676
8677 bool
8678 legitimate_pic_operand_p (rtx x)
8679 {
8680   rtx inner;
8681
8682   switch (GET_CODE (x))
8683     {
8684     case CONST:
8685       inner = XEXP (x, 0);
8686       if (GET_CODE (inner) == PLUS
8687           && CONST_INT_P (XEXP (inner, 1)))
8688         inner = XEXP (inner, 0);
8689
8690       /* Only some unspecs are valid as "constants".  */
8691       if (GET_CODE (inner) == UNSPEC)
8692         switch (XINT (inner, 1))
8693           {
8694           case UNSPEC_GOT:
8695           case UNSPEC_GOTOFF:
8696           case UNSPEC_PLTOFF:
8697             return TARGET_64BIT;
8698           case UNSPEC_TPOFF:
8699             x = XVECEXP (inner, 0, 0);
8700             return (GET_CODE (x) == SYMBOL_REF
8701                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8702           case UNSPEC_MACHOPIC_OFFSET:
8703             return legitimate_pic_address_disp_p (x);
8704           default:
8705             return false;
8706           }
8707       /* FALLTHRU */
8708
8709     case SYMBOL_REF:
8710     case LABEL_REF:
8711       return legitimate_pic_address_disp_p (x);
8712
8713     default:
8714       return true;
8715     }
8716 }
8717
8718 /* Determine if a given CONST RTX is a valid memory displacement
8719    in PIC mode.  */
8720
8721 int
8722 legitimate_pic_address_disp_p (rtx disp)
8723 {
8724   bool saw_plus;
8725
8726   /* In 64bit mode we can allow direct addresses of symbols and labels
8727      when they are not dynamic symbols.  */
8728   if (TARGET_64BIT)
8729     {
8730       rtx op0 = disp, op1;
8731
8732       switch (GET_CODE (disp))
8733         {
8734         case LABEL_REF:
8735           return true;
8736
8737         case CONST:
8738           if (GET_CODE (XEXP (disp, 0)) != PLUS)
8739             break;
8740           op0 = XEXP (XEXP (disp, 0), 0);
8741           op1 = XEXP (XEXP (disp, 0), 1);
8742           if (!CONST_INT_P (op1)
8743               || INTVAL (op1) >= 16*1024*1024
8744               || INTVAL (op1) < -16*1024*1024)
8745             break;
8746           if (GET_CODE (op0) == LABEL_REF)
8747             return true;
8748           if (GET_CODE (op0) != SYMBOL_REF)
8749             break;
8750           /* FALLTHRU */
8751
8752         case SYMBOL_REF:
8753           /* TLS references should always be enclosed in UNSPEC.  */
8754           if (SYMBOL_REF_TLS_MODEL (op0))
8755             return false;
8756           if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0)
8757               && ix86_cmodel != CM_LARGE_PIC)
8758             return true;
8759           break;
8760
8761         default:
8762           break;
8763         }
8764     }
8765   if (GET_CODE (disp) != CONST)
8766     return 0;
8767   disp = XEXP (disp, 0);
8768
8769   if (TARGET_64BIT)
8770     {
8771       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
8772          of GOT tables.  We should not need these anyway.  */
8773       if (GET_CODE (disp) != UNSPEC
8774           || (XINT (disp, 1) != UNSPEC_GOTPCREL
8775               && XINT (disp, 1) != UNSPEC_GOTOFF
8776               && XINT (disp, 1) != UNSPEC_PLTOFF))
8777         return 0;
8778
8779       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
8780           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
8781         return 0;
8782       return 1;
8783     }
8784
8785   saw_plus = false;
8786   if (GET_CODE (disp) == PLUS)
8787     {
8788       if (!CONST_INT_P (XEXP (disp, 1)))
8789         return 0;
8790       disp = XEXP (disp, 0);
8791       saw_plus = true;
8792     }
8793
8794   if (TARGET_MACHO && darwin_local_data_pic (disp))
8795     return 1;
8796
8797   if (GET_CODE (disp) != UNSPEC)
8798     return 0;
8799
8800   switch (XINT (disp, 1))
8801     {
8802     case UNSPEC_GOT:
8803       if (saw_plus)
8804         return false;
8805       /* We need to check for both symbols and labels because VxWorks loads
8806          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
8807          details.  */
8808       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
8809               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
8810     case UNSPEC_GOTOFF:
8811       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
8812          While ABI specify also 32bit relocation but we don't produce it in
8813          small PIC model at all.  */
8814       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
8815            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
8816           && !TARGET_64BIT)
8817         return gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
8818       return false;
8819     case UNSPEC_GOTTPOFF:
8820     case UNSPEC_GOTNTPOFF:
8821     case UNSPEC_INDNTPOFF:
8822       if (saw_plus)
8823         return false;
8824       disp = XVECEXP (disp, 0, 0);
8825       return (GET_CODE (disp) == SYMBOL_REF
8826               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
8827     case UNSPEC_NTPOFF:
8828       disp = XVECEXP (disp, 0, 0);
8829       return (GET_CODE (disp) == SYMBOL_REF
8830               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
8831     case UNSPEC_DTPOFF:
8832       disp = XVECEXP (disp, 0, 0);
8833       return (GET_CODE (disp) == SYMBOL_REF
8834               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
8835     }
8836
8837   return 0;
8838 }
8839
8840 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid
8841    memory address for an instruction.  The MODE argument is the machine mode
8842    for the MEM expression that wants to use this address.
8843
8844    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
8845    convert common non-canonical forms to canonical form so that they will
8846    be recognized.  */
8847
8848 int
8849 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
8850                       rtx addr, int strict)
8851 {
8852   struct ix86_address parts;
8853   rtx base, index, disp;
8854   HOST_WIDE_INT scale;
8855   const char *reason = NULL;
8856   rtx reason_rtx = NULL_RTX;
8857
8858   if (ix86_decompose_address (addr, &parts) <= 0)
8859     {
8860       reason = "decomposition failed";
8861       goto report_error;
8862     }
8863
8864   base = parts.base;
8865   index = parts.index;
8866   disp = parts.disp;
8867   scale = parts.scale;
8868
8869   /* Validate base register.
8870
8871      Don't allow SUBREG's that span more than a word here.  It can lead to spill
8872      failures when the base is one word out of a two word structure, which is
8873      represented internally as a DImode int.  */
8874
8875   if (base)
8876     {
8877       rtx reg;
8878       reason_rtx = base;
8879
8880       if (REG_P (base))
8881         reg = base;
8882       else if (GET_CODE (base) == SUBREG
8883                && REG_P (SUBREG_REG (base))
8884                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (base)))
8885                   <= UNITS_PER_WORD)
8886         reg = SUBREG_REG (base);
8887       else
8888         {
8889           reason = "base is not a register";
8890           goto report_error;
8891         }
8892
8893       if (GET_MODE (base) != Pmode)
8894         {
8895           reason = "base is not in Pmode";
8896           goto report_error;
8897         }
8898
8899       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
8900           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
8901         {
8902           reason = "base is not valid";
8903           goto report_error;
8904         }
8905     }
8906
8907   /* Validate index register.
8908
8909      Don't allow SUBREG's that span more than a word here -- same as above.  */
8910
8911   if (index)
8912     {
8913       rtx reg;
8914       reason_rtx = index;
8915
8916       if (REG_P (index))
8917         reg = index;
8918       else if (GET_CODE (index) == SUBREG
8919                && REG_P (SUBREG_REG (index))
8920                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (index)))
8921                   <= UNITS_PER_WORD)
8922         reg = SUBREG_REG (index);
8923       else
8924         {
8925           reason = "index is not a register";
8926           goto report_error;
8927         }
8928
8929       if (GET_MODE (index) != Pmode)
8930         {
8931           reason = "index is not in Pmode";
8932           goto report_error;
8933         }
8934
8935       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
8936           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
8937         {
8938           reason = "index is not valid";
8939           goto report_error;
8940         }
8941     }
8942
8943   /* Validate scale factor.  */
8944   if (scale != 1)
8945     {
8946       reason_rtx = GEN_INT (scale);
8947       if (!index)
8948         {
8949           reason = "scale without index";
8950           goto report_error;
8951         }
8952
8953       if (scale != 2 && scale != 4 && scale != 8)
8954         {
8955           reason = "scale is not a valid multiplier";
8956           goto report_error;
8957         }
8958     }
8959
8960   /* Validate displacement.  */
8961   if (disp)
8962     {
8963       reason_rtx = disp;
8964
8965       if (GET_CODE (disp) == CONST
8966           && GET_CODE (XEXP (disp, 0)) == UNSPEC
8967           && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
8968         switch (XINT (XEXP (disp, 0), 1))
8969           {
8970           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
8971              used.  While ABI specify also 32bit relocations, we don't produce
8972              them at all and use IP relative instead.  */
8973           case UNSPEC_GOT:
8974           case UNSPEC_GOTOFF:
8975             gcc_assert (flag_pic);
8976             if (!TARGET_64BIT)
8977               goto is_legitimate_pic;
8978             reason = "64bit address unspec";
8979             goto report_error;
8980
8981           case UNSPEC_GOTPCREL:
8982             gcc_assert (flag_pic);
8983             goto is_legitimate_pic;
8984
8985           case UNSPEC_GOTTPOFF:
8986           case UNSPEC_GOTNTPOFF:
8987           case UNSPEC_INDNTPOFF:
8988           case UNSPEC_NTPOFF:
8989           case UNSPEC_DTPOFF:
8990             break;
8991
8992           default:
8993             reason = "invalid address unspec";
8994             goto report_error;
8995           }
8996
8997       else if (SYMBOLIC_CONST (disp)
8998                && (flag_pic
8999                    || (TARGET_MACHO
9000 #if TARGET_MACHO
9001                        && MACHOPIC_INDIRECT
9002                        && !machopic_operand_p (disp)
9003 #endif
9004                )))
9005         {
9006
9007         is_legitimate_pic:
9008           if (TARGET_64BIT && (index || base))
9009             {
9010               /* foo@dtpoff(%rX) is ok.  */
9011               if (GET_CODE (disp) != CONST
9012                   || GET_CODE (XEXP (disp, 0)) != PLUS
9013                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
9014                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
9015                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
9016                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
9017                 {
9018                   reason = "non-constant pic memory reference";
9019                   goto report_error;
9020                 }
9021             }
9022           else if (! legitimate_pic_address_disp_p (disp))
9023             {
9024               reason = "displacement is an invalid pic construct";
9025               goto report_error;
9026             }
9027
9028           /* This code used to verify that a symbolic pic displacement
9029              includes the pic_offset_table_rtx register.
9030
9031              While this is good idea, unfortunately these constructs may
9032              be created by "adds using lea" optimization for incorrect
9033              code like:
9034
9035              int a;
9036              int foo(int i)
9037                {
9038                  return *(&a+i);
9039                }
9040
9041              This code is nonsensical, but results in addressing
9042              GOT table with pic_offset_table_rtx base.  We can't
9043              just refuse it easily, since it gets matched by
9044              "addsi3" pattern, that later gets split to lea in the
9045              case output register differs from input.  While this
9046              can be handled by separate addsi pattern for this case
9047              that never results in lea, this seems to be easier and
9048              correct fix for crash to disable this test.  */
9049         }
9050       else if (GET_CODE (disp) != LABEL_REF
9051                && !CONST_INT_P (disp)
9052                && (GET_CODE (disp) != CONST
9053                    || !legitimate_constant_p (disp))
9054                && (GET_CODE (disp) != SYMBOL_REF
9055                    || !legitimate_constant_p (disp)))
9056         {
9057           reason = "displacement is not constant";
9058           goto report_error;
9059         }
9060       else if (TARGET_64BIT
9061                && !x86_64_immediate_operand (disp, VOIDmode))
9062         {
9063           reason = "displacement is out of range";
9064           goto report_error;
9065         }
9066     }
9067
9068   /* Everything looks valid.  */
9069   return TRUE;
9070
9071  report_error:
9072   return FALSE;
9073 }
9074 \f
9075 /* Return a unique alias set for the GOT.  */
9076
9077 static alias_set_type
9078 ix86_GOT_alias_set (void)
9079 {
9080   static alias_set_type set = -1;
9081   if (set == -1)
9082     set = new_alias_set ();
9083   return set;
9084 }
9085
9086 /* Return a legitimate reference for ORIG (an address) using the
9087    register REG.  If REG is 0, a new pseudo is generated.
9088
9089    There are two types of references that must be handled:
9090
9091    1. Global data references must load the address from the GOT, via
9092       the PIC reg.  An insn is emitted to do this load, and the reg is
9093       returned.
9094
9095    2. Static data references, constant pool addresses, and code labels
9096       compute the address as an offset from the GOT, whose base is in
9097       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
9098       differentiate them from global data objects.  The returned
9099       address is the PIC reg + an unspec constant.
9100
9101    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
9102    reg also appears in the address.  */
9103
9104 static rtx
9105 legitimize_pic_address (rtx orig, rtx reg)
9106 {
9107   rtx addr = orig;
9108   rtx new_rtx = orig;
9109   rtx base;
9110
9111 #if TARGET_MACHO
9112   if (TARGET_MACHO && !TARGET_64BIT)
9113     {
9114       if (reg == 0)
9115         reg = gen_reg_rtx (Pmode);
9116       /* Use the generic Mach-O PIC machinery.  */
9117       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
9118     }
9119 #endif
9120
9121   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
9122     new_rtx = addr;
9123   else if (TARGET_64BIT
9124            && ix86_cmodel != CM_SMALL_PIC
9125            && gotoff_operand (addr, Pmode))
9126     {
9127       rtx tmpreg;
9128       /* This symbol may be referenced via a displacement from the PIC
9129          base address (@GOTOFF).  */
9130
9131       if (reload_in_progress)
9132         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9133       if (GET_CODE (addr) == CONST)
9134         addr = XEXP (addr, 0);
9135       if (GET_CODE (addr) == PLUS)
9136           {
9137             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9138                                       UNSPEC_GOTOFF);
9139             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9140           }
9141         else
9142           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9143       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9144       if (!reg)
9145         tmpreg = gen_reg_rtx (Pmode);
9146       else
9147         tmpreg = reg;
9148       emit_move_insn (tmpreg, new_rtx);
9149
9150       if (reg != 0)
9151         {
9152           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
9153                                          tmpreg, 1, OPTAB_DIRECT);
9154           new_rtx = reg;
9155         }
9156       else new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
9157     }
9158   else if (!TARGET_64BIT && gotoff_operand (addr, Pmode))
9159     {
9160       /* This symbol may be referenced via a displacement from the PIC
9161          base address (@GOTOFF).  */
9162
9163       if (reload_in_progress)
9164         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9165       if (GET_CODE (addr) == CONST)
9166         addr = XEXP (addr, 0);
9167       if (GET_CODE (addr) == PLUS)
9168           {
9169             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9170                                       UNSPEC_GOTOFF);
9171             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9172           }
9173         else
9174           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9175       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9176       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9177
9178       if (reg != 0)
9179         {
9180           emit_move_insn (reg, new_rtx);
9181           new_rtx = reg;
9182         }
9183     }
9184   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
9185            /* We can't use @GOTOFF for text labels on VxWorks;
9186               see gotoff_operand.  */
9187            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
9188     {
9189       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9190         {
9191           if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
9192             return legitimize_dllimport_symbol (addr, true);
9193           if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
9194               && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
9195               && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
9196             {
9197               rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), true);
9198               return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
9199             }
9200         }
9201
9202       if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
9203         {
9204           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
9205           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9206           new_rtx = gen_const_mem (Pmode, new_rtx);
9207           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9208
9209           if (reg == 0)
9210             reg = gen_reg_rtx (Pmode);
9211           /* Use directly gen_movsi, otherwise the address is loaded
9212              into register for CSE.  We don't want to CSE this addresses,
9213              instead we CSE addresses from the GOT table, so skip this.  */
9214           emit_insn (gen_movsi (reg, new_rtx));
9215           new_rtx = reg;
9216         }
9217       else
9218         {
9219           /* This symbol must be referenced via a load from the
9220              Global Offset Table (@GOT).  */
9221
9222           if (reload_in_progress)
9223             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9224           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
9225           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9226           if (TARGET_64BIT)
9227             new_rtx = force_reg (Pmode, new_rtx);
9228           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9229           new_rtx = gen_const_mem (Pmode, new_rtx);
9230           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9231
9232           if (reg == 0)
9233             reg = gen_reg_rtx (Pmode);
9234           emit_move_insn (reg, new_rtx);
9235           new_rtx = reg;
9236         }
9237     }
9238   else
9239     {
9240       if (CONST_INT_P (addr)
9241           && !x86_64_immediate_operand (addr, VOIDmode))
9242         {
9243           if (reg)
9244             {
9245               emit_move_insn (reg, addr);
9246               new_rtx = reg;
9247             }
9248           else
9249             new_rtx = force_reg (Pmode, addr);
9250         }
9251       else if (GET_CODE (addr) == CONST)
9252         {
9253           addr = XEXP (addr, 0);
9254
9255           /* We must match stuff we generate before.  Assume the only
9256              unspecs that can get here are ours.  Not that we could do
9257              anything with them anyway....  */
9258           if (GET_CODE (addr) == UNSPEC
9259               || (GET_CODE (addr) == PLUS
9260                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
9261             return orig;
9262           gcc_assert (GET_CODE (addr) == PLUS);
9263         }
9264       if (GET_CODE (addr) == PLUS)
9265         {
9266           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
9267
9268           /* Check first to see if this is a constant offset from a @GOTOFF
9269              symbol reference.  */
9270           if (gotoff_operand (op0, Pmode)
9271               && CONST_INT_P (op1))
9272             {
9273               if (!TARGET_64BIT)
9274                 {
9275                   if (reload_in_progress)
9276                     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9277                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
9278                                             UNSPEC_GOTOFF);
9279                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
9280                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9281                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9282
9283                   if (reg != 0)
9284                     {
9285                       emit_move_insn (reg, new_rtx);
9286                       new_rtx = reg;
9287                     }
9288                 }
9289               else
9290                 {
9291                   if (INTVAL (op1) < -16*1024*1024
9292                       || INTVAL (op1) >= 16*1024*1024)
9293                     {
9294                       if (!x86_64_immediate_operand (op1, Pmode))
9295                         op1 = force_reg (Pmode, op1);
9296                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
9297                     }
9298                 }
9299             }
9300           else
9301             {
9302               base = legitimize_pic_address (XEXP (addr, 0), reg);
9303               new_rtx  = legitimize_pic_address (XEXP (addr, 1),
9304                                                  base == reg ? NULL_RTX : reg);
9305
9306               if (CONST_INT_P (new_rtx))
9307                 new_rtx = plus_constant (base, INTVAL (new_rtx));
9308               else
9309                 {
9310                   if (GET_CODE (new_rtx) == PLUS && CONSTANT_P (XEXP (new_rtx, 1)))
9311                     {
9312                       base = gen_rtx_PLUS (Pmode, base, XEXP (new_rtx, 0));
9313                       new_rtx = XEXP (new_rtx, 1);
9314                     }
9315                   new_rtx = gen_rtx_PLUS (Pmode, base, new_rtx);
9316                 }
9317             }
9318         }
9319     }
9320   return new_rtx;
9321 }
9322 \f
9323 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
9324
9325 static rtx
9326 get_thread_pointer (int to_reg)
9327 {
9328   rtx tp, reg, insn;
9329
9330   tp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
9331   if (!to_reg)
9332     return tp;
9333
9334   reg = gen_reg_rtx (Pmode);
9335   insn = gen_rtx_SET (VOIDmode, reg, tp);
9336   insn = emit_insn (insn);
9337
9338   return reg;
9339 }
9340
9341 /* A subroutine of legitimize_address and ix86_expand_move.  FOR_MOV is
9342    false if we expect this to be used for a memory address and true if
9343    we expect to load the address into a register.  */
9344
9345 static rtx
9346 legitimize_tls_address (rtx x, enum tls_model model, int for_mov)
9347 {
9348   rtx dest, base, off, pic, tp;
9349   int type;
9350
9351   switch (model)
9352     {
9353     case TLS_MODEL_GLOBAL_DYNAMIC:
9354       dest = gen_reg_rtx (Pmode);
9355       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9356
9357       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9358         {
9359           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns;
9360
9361           start_sequence ();
9362           emit_call_insn (gen_tls_global_dynamic_64 (rax, x));
9363           insns = get_insns ();
9364           end_sequence ();
9365
9366           RTL_CONST_CALL_P (insns) = 1;
9367           emit_libcall_block (insns, dest, rax, x);
9368         }
9369       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9370         emit_insn (gen_tls_global_dynamic_64 (dest, x));
9371       else
9372         emit_insn (gen_tls_global_dynamic_32 (dest, x));
9373
9374       if (TARGET_GNU2_TLS)
9375         {
9376           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
9377
9378           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9379         }
9380       break;
9381
9382     case TLS_MODEL_LOCAL_DYNAMIC:
9383       base = gen_reg_rtx (Pmode);
9384       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9385
9386       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9387         {
9388           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns, note;
9389
9390           start_sequence ();
9391           emit_call_insn (gen_tls_local_dynamic_base_64 (rax));
9392           insns = get_insns ();
9393           end_sequence ();
9394
9395           note = gen_rtx_EXPR_LIST (VOIDmode, const0_rtx, NULL);
9396           note = gen_rtx_EXPR_LIST (VOIDmode, ix86_tls_get_addr (), note);
9397           RTL_CONST_CALL_P (insns) = 1;
9398           emit_libcall_block (insns, base, rax, note);
9399         }
9400       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9401         emit_insn (gen_tls_local_dynamic_base_64 (base));
9402       else
9403         emit_insn (gen_tls_local_dynamic_base_32 (base));
9404
9405       if (TARGET_GNU2_TLS)
9406         {
9407           rtx x = ix86_tls_module_base ();
9408
9409           set_unique_reg_note (get_last_insn (), REG_EQUIV,
9410                                gen_rtx_MINUS (Pmode, x, tp));
9411         }
9412
9413       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
9414       off = gen_rtx_CONST (Pmode, off);
9415
9416       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
9417
9418       if (TARGET_GNU2_TLS)
9419         {
9420           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
9421
9422           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9423         }
9424
9425       break;
9426
9427     case TLS_MODEL_INITIAL_EXEC:
9428       if (TARGET_64BIT)
9429         {
9430           pic = NULL;
9431           type = UNSPEC_GOTNTPOFF;
9432         }
9433       else if (flag_pic)
9434         {
9435           if (reload_in_progress)
9436             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9437           pic = pic_offset_table_rtx;
9438           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
9439         }
9440       else if (!TARGET_ANY_GNU_TLS)
9441         {
9442           pic = gen_reg_rtx (Pmode);
9443           emit_insn (gen_set_got (pic));
9444           type = UNSPEC_GOTTPOFF;
9445         }
9446       else
9447         {
9448           pic = NULL;
9449           type = UNSPEC_INDNTPOFF;
9450         }
9451
9452       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), type);
9453       off = gen_rtx_CONST (Pmode, off);
9454       if (pic)
9455         off = gen_rtx_PLUS (Pmode, pic, off);
9456       off = gen_const_mem (Pmode, off);
9457       set_mem_alias_set (off, ix86_GOT_alias_set ());
9458
9459       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9460         {
9461           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9462           off = force_reg (Pmode, off);
9463           return gen_rtx_PLUS (Pmode, base, off);
9464         }
9465       else
9466         {
9467           base = get_thread_pointer (true);
9468           dest = gen_reg_rtx (Pmode);
9469           emit_insn (gen_subsi3 (dest, base, off));
9470         }
9471       break;
9472
9473     case TLS_MODEL_LOCAL_EXEC:
9474       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
9475                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9476                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
9477       off = gen_rtx_CONST (Pmode, off);
9478
9479       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9480         {
9481           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9482           return gen_rtx_PLUS (Pmode, base, off);
9483         }
9484       else
9485         {
9486           base = get_thread_pointer (true);
9487           dest = gen_reg_rtx (Pmode);
9488           emit_insn (gen_subsi3 (dest, base, off));
9489         }
9490       break;
9491
9492     default:
9493       gcc_unreachable ();
9494     }
9495
9496   return dest;
9497 }
9498
9499 /* Create or return the unique __imp_DECL dllimport symbol corresponding
9500    to symbol DECL.  */
9501
9502 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
9503   htab_t dllimport_map;
9504
9505 static tree
9506 get_dllimport_decl (tree decl)
9507 {
9508   struct tree_map *h, in;
9509   void **loc;
9510   const char *name;
9511   const char *prefix;
9512   size_t namelen, prefixlen;
9513   char *imp_name;
9514   tree to;
9515   rtx rtl;
9516
9517   if (!dllimport_map)
9518     dllimport_map = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
9519
9520   in.hash = htab_hash_pointer (decl);
9521   in.base.from = decl;
9522   loc = htab_find_slot_with_hash (dllimport_map, &in, in.hash, INSERT);
9523   h = (struct tree_map *) *loc;
9524   if (h)
9525     return h->to;
9526
9527   *loc = h = GGC_NEW (struct tree_map);
9528   h->hash = in.hash;
9529   h->base.from = decl;
9530   h->to = to = build_decl (VAR_DECL, NULL, ptr_type_node);
9531   DECL_ARTIFICIAL (to) = 1;
9532   DECL_IGNORED_P (to) = 1;
9533   DECL_EXTERNAL (to) = 1;
9534   TREE_READONLY (to) = 1;
9535
9536   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9537   name = targetm.strip_name_encoding (name);
9538   prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
9539     ? "*__imp_" : "*__imp__";
9540   namelen = strlen (name);
9541   prefixlen = strlen (prefix);
9542   imp_name = (char *) alloca (namelen + prefixlen + 1);
9543   memcpy (imp_name, prefix, prefixlen);
9544   memcpy (imp_name + prefixlen, name, namelen + 1);
9545
9546   name = ggc_alloc_string (imp_name, namelen + prefixlen);
9547   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
9548   SET_SYMBOL_REF_DECL (rtl, to);
9549   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL;
9550
9551   rtl = gen_const_mem (Pmode, rtl);
9552   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
9553
9554   SET_DECL_RTL (to, rtl);
9555   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
9556
9557   return to;
9558 }
9559
9560 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
9561    true if we require the result be a register.  */
9562
9563 static rtx
9564 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
9565 {
9566   tree imp_decl;
9567   rtx x;
9568
9569   gcc_assert (SYMBOL_REF_DECL (symbol));
9570   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol));
9571
9572   x = DECL_RTL (imp_decl);
9573   if (want_reg)
9574     x = force_reg (Pmode, x);
9575   return x;
9576 }
9577
9578 /* Try machine-dependent ways of modifying an illegitimate address
9579    to be legitimate.  If we find one, return the new, valid address.
9580    This macro is used in only one place: `memory_address' in explow.c.
9581
9582    OLDX is the address as it was before break_out_memory_refs was called.
9583    In some cases it is useful to look at this to decide what needs to be done.
9584
9585    MODE and WIN are passed so that this macro can use
9586    GO_IF_LEGITIMATE_ADDRESS.
9587
9588    It is always safe for this macro to do nothing.  It exists to recognize
9589    opportunities to optimize the output.
9590
9591    For the 80386, we handle X+REG by loading X into a register R and
9592    using R+REG.  R will go in a general reg and indexing will be used.
9593    However, if REG is a broken-out memory address or multiplication,
9594    nothing needs to be done because REG can certainly go in a general reg.
9595
9596    When -fpic is used, special handling is needed for symbolic references.
9597    See comments by legitimize_pic_address in i386.c for details.  */
9598
9599 rtx
9600 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
9601 {
9602   int changed = 0;
9603   unsigned log;
9604
9605   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
9606   if (log)
9607     return legitimize_tls_address (x, (enum tls_model) log, false);
9608   if (GET_CODE (x) == CONST
9609       && GET_CODE (XEXP (x, 0)) == PLUS
9610       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9611       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
9612     {
9613       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
9614                                       (enum tls_model) log, false);
9615       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9616     }
9617
9618   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9619     {
9620       if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (x))
9621         return legitimize_dllimport_symbol (x, true);
9622       if (GET_CODE (x) == CONST
9623           && GET_CODE (XEXP (x, 0)) == PLUS
9624           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9625           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (x, 0), 0)))
9626         {
9627           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (x, 0), 0), true);
9628           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9629         }
9630     }
9631
9632   if (flag_pic && SYMBOLIC_CONST (x))
9633     return legitimize_pic_address (x, 0);
9634
9635   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
9636   if (GET_CODE (x) == ASHIFT
9637       && CONST_INT_P (XEXP (x, 1))
9638       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
9639     {
9640       changed = 1;
9641       log = INTVAL (XEXP (x, 1));
9642       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
9643                         GEN_INT (1 << log));
9644     }
9645
9646   if (GET_CODE (x) == PLUS)
9647     {
9648       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
9649
9650       if (GET_CODE (XEXP (x, 0)) == ASHIFT
9651           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
9652           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
9653         {
9654           changed = 1;
9655           log = INTVAL (XEXP (XEXP (x, 0), 1));
9656           XEXP (x, 0) = gen_rtx_MULT (Pmode,
9657                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
9658                                       GEN_INT (1 << log));
9659         }
9660
9661       if (GET_CODE (XEXP (x, 1)) == ASHIFT
9662           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
9663           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
9664         {
9665           changed = 1;
9666           log = INTVAL (XEXP (XEXP (x, 1), 1));
9667           XEXP (x, 1) = gen_rtx_MULT (Pmode,
9668                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
9669                                       GEN_INT (1 << log));
9670         }
9671
9672       /* Put multiply first if it isn't already.  */
9673       if (GET_CODE (XEXP (x, 1)) == MULT)
9674         {
9675           rtx tmp = XEXP (x, 0);
9676           XEXP (x, 0) = XEXP (x, 1);
9677           XEXP (x, 1) = tmp;
9678           changed = 1;
9679         }
9680
9681       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
9682          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
9683          created by virtual register instantiation, register elimination, and
9684          similar optimizations.  */
9685       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
9686         {
9687           changed = 1;
9688           x = gen_rtx_PLUS (Pmode,
9689                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
9690                                           XEXP (XEXP (x, 1), 0)),
9691                             XEXP (XEXP (x, 1), 1));
9692         }
9693
9694       /* Canonicalize
9695          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
9696          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
9697       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
9698                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
9699                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
9700                && CONSTANT_P (XEXP (x, 1)))
9701         {
9702           rtx constant;
9703           rtx other = NULL_RTX;
9704
9705           if (CONST_INT_P (XEXP (x, 1)))
9706             {
9707               constant = XEXP (x, 1);
9708               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
9709             }
9710           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
9711             {
9712               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
9713               other = XEXP (x, 1);
9714             }
9715           else
9716             constant = 0;
9717
9718           if (constant)
9719             {
9720               changed = 1;
9721               x = gen_rtx_PLUS (Pmode,
9722                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
9723                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
9724                                 plus_constant (other, INTVAL (constant)));
9725             }
9726         }
9727
9728       if (changed && legitimate_address_p (mode, x, FALSE))
9729         return x;
9730
9731       if (GET_CODE (XEXP (x, 0)) == MULT)
9732         {
9733           changed = 1;
9734           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
9735         }
9736
9737       if (GET_CODE (XEXP (x, 1)) == MULT)
9738         {
9739           changed = 1;
9740           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
9741         }
9742
9743       if (changed
9744           && REG_P (XEXP (x, 1))
9745           && REG_P (XEXP (x, 0)))
9746         return x;
9747
9748       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
9749         {
9750           changed = 1;
9751           x = legitimize_pic_address (x, 0);
9752         }
9753
9754       if (changed && legitimate_address_p (mode, x, FALSE))
9755         return x;
9756
9757       if (REG_P (XEXP (x, 0)))
9758         {
9759           rtx temp = gen_reg_rtx (Pmode);
9760           rtx val  = force_operand (XEXP (x, 1), temp);
9761           if (val != temp)
9762             emit_move_insn (temp, val);
9763
9764           XEXP (x, 1) = temp;
9765           return x;
9766         }
9767
9768       else if (REG_P (XEXP (x, 1)))
9769         {
9770           rtx temp = gen_reg_rtx (Pmode);
9771           rtx val  = force_operand (XEXP (x, 0), temp);
9772           if (val != temp)
9773             emit_move_insn (temp, val);
9774
9775           XEXP (x, 0) = temp;
9776           return x;
9777         }
9778     }
9779
9780   return x;
9781 }
9782 \f
9783 /* Print an integer constant expression in assembler syntax.  Addition
9784    and subtraction are the only arithmetic that may appear in these
9785    expressions.  FILE is the stdio stream to write to, X is the rtx, and
9786    CODE is the operand print code from the output string.  */
9787
9788 static void
9789 output_pic_addr_const (FILE *file, rtx x, int code)
9790 {
9791   char buf[256];
9792
9793   switch (GET_CODE (x))
9794     {
9795     case PC:
9796       gcc_assert (flag_pic);
9797       putc ('.', file);
9798       break;
9799
9800     case SYMBOL_REF:
9801       if (! TARGET_MACHO || TARGET_64BIT)
9802         output_addr_const (file, x);
9803       else
9804         {
9805           const char *name = XSTR (x, 0);
9806
9807           /* Mark the decl as referenced so that cgraph will
9808              output the function.  */
9809           if (SYMBOL_REF_DECL (x))
9810             mark_decl_referenced (SYMBOL_REF_DECL (x));
9811
9812 #if TARGET_MACHO
9813           if (MACHOPIC_INDIRECT
9814               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
9815             name = machopic_indirection_name (x, /*stub_p=*/true);
9816 #endif
9817           assemble_name (file, name);
9818         }
9819       if (!TARGET_MACHO && !(TARGET_64BIT && DEFAULT_ABI == MS_ABI)
9820           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
9821         fputs ("@PLT", file);
9822       break;
9823
9824     case LABEL_REF:
9825       x = XEXP (x, 0);
9826       /* FALLTHRU */
9827     case CODE_LABEL:
9828       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
9829       assemble_name (asm_out_file, buf);
9830       break;
9831
9832     case CONST_INT:
9833       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
9834       break;
9835
9836     case CONST:
9837       /* This used to output parentheses around the expression,
9838          but that does not work on the 386 (either ATT or BSD assembler).  */
9839       output_pic_addr_const (file, XEXP (x, 0), code);
9840       break;
9841
9842     case CONST_DOUBLE:
9843       if (GET_MODE (x) == VOIDmode)
9844         {
9845           /* We can use %d if the number is <32 bits and positive.  */
9846           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
9847             fprintf (file, "0x%lx%08lx",
9848                      (unsigned long) CONST_DOUBLE_HIGH (x),
9849                      (unsigned long) CONST_DOUBLE_LOW (x));
9850           else
9851             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
9852         }
9853       else
9854         /* We can't handle floating point constants;
9855            PRINT_OPERAND must handle them.  */
9856         output_operand_lossage ("floating constant misused");
9857       break;
9858
9859     case PLUS:
9860       /* Some assemblers need integer constants to appear first.  */
9861       if (CONST_INT_P (XEXP (x, 0)))
9862         {
9863           output_pic_addr_const (file, XEXP (x, 0), code);
9864           putc ('+', file);
9865           output_pic_addr_const (file, XEXP (x, 1), code);
9866         }
9867       else
9868         {
9869           gcc_assert (CONST_INT_P (XEXP (x, 1)));
9870           output_pic_addr_const (file, XEXP (x, 1), code);
9871           putc ('+', file);
9872           output_pic_addr_const (file, XEXP (x, 0), code);
9873         }
9874       break;
9875
9876     case MINUS:
9877       if (!TARGET_MACHO)
9878         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
9879       output_pic_addr_const (file, XEXP (x, 0), code);
9880       putc ('-', file);
9881       output_pic_addr_const (file, XEXP (x, 1), code);
9882       if (!TARGET_MACHO)
9883         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
9884       break;
9885
9886      case UNSPEC:
9887        gcc_assert (XVECLEN (x, 0) == 1);
9888        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
9889        switch (XINT (x, 1))
9890         {
9891         case UNSPEC_GOT:
9892           fputs ("@GOT", file);
9893           break;
9894         case UNSPEC_GOTOFF:
9895           fputs ("@GOTOFF", file);
9896           break;
9897         case UNSPEC_PLTOFF:
9898           fputs ("@PLTOFF", file);
9899           break;
9900         case UNSPEC_GOTPCREL:
9901           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
9902                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
9903           break;
9904         case UNSPEC_GOTTPOFF:
9905           /* FIXME: This might be @TPOFF in Sun ld too.  */
9906           fputs ("@GOTTPOFF", file);
9907           break;
9908         case UNSPEC_TPOFF:
9909           fputs ("@TPOFF", file);
9910           break;
9911         case UNSPEC_NTPOFF:
9912           if (TARGET_64BIT)
9913             fputs ("@TPOFF", file);
9914           else
9915             fputs ("@NTPOFF", file);
9916           break;
9917         case UNSPEC_DTPOFF:
9918           fputs ("@DTPOFF", file);
9919           break;
9920         case UNSPEC_GOTNTPOFF:
9921           if (TARGET_64BIT)
9922             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
9923                    "@GOTTPOFF(%rip)": "@GOTTPOFF[rip]", file);
9924           else
9925             fputs ("@GOTNTPOFF", file);
9926           break;
9927         case UNSPEC_INDNTPOFF:
9928           fputs ("@INDNTPOFF", file);
9929           break;
9930 #if TARGET_MACHO
9931         case UNSPEC_MACHOPIC_OFFSET:
9932           putc ('-', file);
9933           machopic_output_function_base_name (file);
9934           break;
9935 #endif
9936         default:
9937           output_operand_lossage ("invalid UNSPEC as operand");
9938           break;
9939         }
9940        break;
9941
9942     default:
9943       output_operand_lossage ("invalid expression as operand");
9944     }
9945 }
9946
9947 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
9948    We need to emit DTP-relative relocations.  */
9949
9950 static void ATTRIBUTE_UNUSED
9951 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
9952 {
9953   fputs (ASM_LONG, file);
9954   output_addr_const (file, x);
9955   fputs ("@DTPOFF", file);
9956   switch (size)
9957     {
9958     case 4:
9959       break;
9960     case 8:
9961       fputs (", 0", file);
9962       break;
9963     default:
9964       gcc_unreachable ();
9965    }
9966 }
9967
9968 /* Return true if X is a representation of the PIC register.  This copes
9969    with calls from ix86_find_base_term, where the register might have
9970    been replaced by a cselib value.  */
9971
9972 static bool
9973 ix86_pic_register_p (rtx x)
9974 {
9975   if (GET_CODE (x) == VALUE)
9976     return (pic_offset_table_rtx
9977             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
9978   else
9979     return REG_P (x) && REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
9980 }
9981
9982 /* In the name of slightly smaller debug output, and to cater to
9983    general assembler lossage, recognize PIC+GOTOFF and turn it back
9984    into a direct symbol reference.
9985
9986    On Darwin, this is necessary to avoid a crash, because Darwin
9987    has a different PIC label for each routine but the DWARF debugging
9988    information is not associated with any particular routine, so it's
9989    necessary to remove references to the PIC label from RTL stored by
9990    the DWARF output code.  */
9991
9992 static rtx
9993 ix86_delegitimize_address (rtx orig_x)
9994 {
9995   rtx x = orig_x;
9996   /* reg_addend is NULL or a multiple of some register.  */
9997   rtx reg_addend = NULL_RTX;
9998   /* const_addend is NULL or a const_int.  */
9999   rtx const_addend = NULL_RTX;
10000   /* This is the result, or NULL.  */
10001   rtx result = NULL_RTX;
10002
10003   if (MEM_P (x))
10004     x = XEXP (x, 0);
10005
10006   if (TARGET_64BIT)
10007     {
10008       if (GET_CODE (x) != CONST
10009           || GET_CODE (XEXP (x, 0)) != UNSPEC
10010           || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL
10011           || !MEM_P (orig_x))
10012         return orig_x;
10013       return XVECEXP (XEXP (x, 0), 0, 0);
10014     }
10015
10016   if (GET_CODE (x) != PLUS
10017       || GET_CODE (XEXP (x, 1)) != CONST)
10018     return orig_x;
10019
10020   if (ix86_pic_register_p (XEXP (x, 0)))
10021     /* %ebx + GOT/GOTOFF */
10022     ;
10023   else if (GET_CODE (XEXP (x, 0)) == PLUS)
10024     {
10025       /* %ebx + %reg * scale + GOT/GOTOFF */
10026       reg_addend = XEXP (x, 0);
10027       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
10028         reg_addend = XEXP (reg_addend, 1);
10029       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
10030         reg_addend = XEXP (reg_addend, 0);
10031       else
10032         return orig_x;
10033       if (!REG_P (reg_addend)
10034           && GET_CODE (reg_addend) != MULT
10035           && GET_CODE (reg_addend) != ASHIFT)
10036         return orig_x;
10037     }
10038   else
10039     return orig_x;
10040
10041   x = XEXP (XEXP (x, 1), 0);
10042   if (GET_CODE (x) == PLUS
10043       && CONST_INT_P (XEXP (x, 1)))
10044     {
10045       const_addend = XEXP (x, 1);
10046       x = XEXP (x, 0);
10047     }
10048
10049   if (GET_CODE (x) == UNSPEC
10050       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x))
10051           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))))
10052     result = XVECEXP (x, 0, 0);
10053
10054   if (TARGET_MACHO && darwin_local_data_pic (x)
10055       && !MEM_P (orig_x))
10056     result = XVECEXP (x, 0, 0);
10057
10058   if (! result)
10059     return orig_x;
10060
10061   if (const_addend)
10062     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
10063   if (reg_addend)
10064     result = gen_rtx_PLUS (Pmode, reg_addend, result);
10065   return result;
10066 }
10067
10068 /* If X is a machine specific address (i.e. a symbol or label being
10069    referenced as a displacement from the GOT implemented using an
10070    UNSPEC), then return the base term.  Otherwise return X.  */
10071
10072 rtx
10073 ix86_find_base_term (rtx x)
10074 {
10075   rtx term;
10076
10077   if (TARGET_64BIT)
10078     {
10079       if (GET_CODE (x) != CONST)
10080         return x;
10081       term = XEXP (x, 0);
10082       if (GET_CODE (term) == PLUS
10083           && (CONST_INT_P (XEXP (term, 1))
10084               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
10085         term = XEXP (term, 0);
10086       if (GET_CODE (term) != UNSPEC
10087           || XINT (term, 1) != UNSPEC_GOTPCREL)
10088         return x;
10089
10090       return XVECEXP (term, 0, 0);
10091     }
10092
10093   return ix86_delegitimize_address (x);
10094 }
10095 \f
10096 static void
10097 put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
10098                     int fp, FILE *file)
10099 {
10100   const char *suffix;
10101
10102   if (mode == CCFPmode || mode == CCFPUmode)
10103     {
10104       enum rtx_code second_code, bypass_code;
10105       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
10106       gcc_assert (bypass_code == UNKNOWN && second_code == UNKNOWN);
10107       code = ix86_fp_compare_code_to_integer (code);
10108       mode = CCmode;
10109     }
10110   if (reverse)
10111     code = reverse_condition (code);
10112
10113   switch (code)
10114     {
10115     case EQ:
10116       switch (mode)
10117         {
10118         case CCAmode:
10119           suffix = "a";
10120           break;
10121
10122         case CCCmode:
10123           suffix = "c";
10124           break;
10125
10126         case CCOmode:
10127           suffix = "o";
10128           break;
10129
10130         case CCSmode:
10131           suffix = "s";
10132           break;
10133
10134         default:
10135           suffix = "e";
10136         }
10137       break;
10138     case NE:
10139       switch (mode)
10140         {
10141         case CCAmode:
10142           suffix = "na";
10143           break;
10144
10145         case CCCmode:
10146           suffix = "nc";
10147           break;
10148
10149         case CCOmode:
10150           suffix = "no";
10151           break;
10152
10153         case CCSmode:
10154           suffix = "ns";
10155           break;
10156
10157         default:
10158           suffix = "ne";
10159         }
10160       break;
10161     case GT:
10162       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
10163       suffix = "g";
10164       break;
10165     case GTU:
10166       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
10167          Those same assemblers have the same but opposite lossage on cmov.  */
10168       if (mode == CCmode)
10169         suffix = fp ? "nbe" : "a";
10170       else if (mode == CCCmode)
10171         suffix = "b";
10172       else
10173         gcc_unreachable ();
10174       break;
10175     case LT:
10176       switch (mode)
10177         {
10178         case CCNOmode:
10179         case CCGOCmode:
10180           suffix = "s";
10181           break;
10182
10183         case CCmode:
10184         case CCGCmode:
10185           suffix = "l";
10186           break;
10187
10188         default:
10189           gcc_unreachable ();
10190         }
10191       break;
10192     case LTU:
10193       gcc_assert (mode == CCmode || mode == CCCmode);
10194       suffix = "b";
10195       break;
10196     case GE:
10197       switch (mode)
10198         {
10199         case CCNOmode:
10200         case CCGOCmode:
10201           suffix = "ns";
10202           break;
10203
10204         case CCmode:
10205         case CCGCmode:
10206           suffix = "ge";
10207           break;
10208
10209         default:
10210           gcc_unreachable ();
10211         }
10212       break;
10213     case GEU:
10214       /* ??? As above.  */
10215       gcc_assert (mode == CCmode || mode == CCCmode);
10216       suffix = fp ? "nb" : "ae";
10217       break;
10218     case LE:
10219       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
10220       suffix = "le";
10221       break;
10222     case LEU:
10223       /* ??? As above.  */
10224       if (mode == CCmode)
10225         suffix = "be";
10226       else if (mode == CCCmode)
10227         suffix = fp ? "nb" : "ae";
10228       else
10229         gcc_unreachable ();
10230       break;
10231     case UNORDERED:
10232       suffix = fp ? "u" : "p";
10233       break;
10234     case ORDERED:
10235       suffix = fp ? "nu" : "np";
10236       break;
10237     default:
10238       gcc_unreachable ();
10239     }
10240   fputs (suffix, file);
10241 }
10242
10243 /* Print the name of register X to FILE based on its machine mode and number.
10244    If CODE is 'w', pretend the mode is HImode.
10245    If CODE is 'b', pretend the mode is QImode.
10246    If CODE is 'k', pretend the mode is SImode.
10247    If CODE is 'q', pretend the mode is DImode.
10248    If CODE is 'x', pretend the mode is V4SFmode.
10249    If CODE is 't', pretend the mode is V8SFmode.
10250    If CODE is 'h', pretend the reg is the 'high' byte register.
10251    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
10252    If CODE is 'd', duplicate the operand for AVX instruction.
10253  */
10254
10255 void
10256 print_reg (rtx x, int code, FILE *file)
10257 {
10258   const char *reg;
10259   bool duplicated = code == 'd' && TARGET_AVX;
10260
10261   gcc_assert (x == pc_rtx
10262               || (REGNO (x) != ARG_POINTER_REGNUM
10263                   && REGNO (x) != FRAME_POINTER_REGNUM
10264                   && REGNO (x) != FLAGS_REG
10265                   && REGNO (x) != FPSR_REG
10266                   && REGNO (x) != FPCR_REG));
10267
10268   if (ASSEMBLER_DIALECT == ASM_ATT)
10269     putc ('%', file);
10270
10271   if (x == pc_rtx)
10272     {
10273       gcc_assert (TARGET_64BIT);
10274       fputs ("rip", file);
10275       return;
10276     }
10277
10278   if (code == 'w' || MMX_REG_P (x))
10279     code = 2;
10280   else if (code == 'b')
10281     code = 1;
10282   else if (code == 'k')
10283     code = 4;
10284   else if (code == 'q')
10285     code = 8;
10286   else if (code == 'y')
10287     code = 3;
10288   else if (code == 'h')
10289     code = 0;
10290   else if (code == 'x')
10291     code = 16;
10292   else if (code == 't')
10293     code = 32;
10294   else
10295     code = GET_MODE_SIZE (GET_MODE (x));
10296
10297   /* Irritatingly, AMD extended registers use different naming convention
10298      from the normal registers.  */
10299   if (REX_INT_REG_P (x))
10300     {
10301       gcc_assert (TARGET_64BIT);
10302       switch (code)
10303         {
10304           case 0:
10305             error ("extended registers have no high halves");
10306             break;
10307           case 1:
10308             fprintf (file, "r%ib", REGNO (x) - FIRST_REX_INT_REG + 8);
10309             break;
10310           case 2:
10311             fprintf (file, "r%iw", REGNO (x) - FIRST_REX_INT_REG + 8);
10312             break;
10313           case 4:
10314             fprintf (file, "r%id", REGNO (x) - FIRST_REX_INT_REG + 8);
10315             break;
10316           case 8:
10317             fprintf (file, "r%i", REGNO (x) - FIRST_REX_INT_REG + 8);
10318             break;
10319           default:
10320             error ("unsupported operand size for extended register");
10321             break;
10322         }
10323       return;
10324     }
10325
10326   reg = NULL;
10327   switch (code)
10328     {
10329     case 3:
10330       if (STACK_TOP_P (x))
10331         {
10332           reg = "st(0)";
10333           break;
10334         }
10335       /* FALLTHRU */
10336     case 8:
10337     case 4:
10338     case 12:
10339       if (! ANY_FP_REG_P (x))
10340         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
10341       /* FALLTHRU */
10342     case 16:
10343     case 2:
10344     normal:
10345       reg = hi_reg_name[REGNO (x)];
10346       break;
10347     case 1:
10348       if (REGNO (x) >= ARRAY_SIZE (qi_reg_name))
10349         goto normal;
10350       reg = qi_reg_name[REGNO (x)];
10351       break;
10352     case 0:
10353       if (REGNO (x) >= ARRAY_SIZE (qi_high_reg_name))
10354         goto normal;
10355       reg = qi_high_reg_name[REGNO (x)];
10356       break;
10357     case 32:
10358       if (SSE_REG_P (x))
10359         {
10360           gcc_assert (!duplicated);
10361           putc ('y', file);
10362           fputs (hi_reg_name[REGNO (x)] + 1, file);
10363           return;
10364         }
10365       break;
10366     default:
10367       gcc_unreachable ();
10368     }
10369
10370   fputs (reg, file);
10371   if (duplicated)
10372     {
10373       if (ASSEMBLER_DIALECT == ASM_ATT)
10374         fprintf (file, ", %%%s", reg);
10375       else
10376         fprintf (file, ", %s", reg);
10377     }
10378 }
10379
10380 /* Locate some local-dynamic symbol still in use by this function
10381    so that we can print its name in some tls_local_dynamic_base
10382    pattern.  */
10383
10384 static int
10385 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
10386 {
10387   rtx x = *px;
10388
10389   if (GET_CODE (x) == SYMBOL_REF
10390       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
10391     {
10392       cfun->machine->some_ld_name = XSTR (x, 0);
10393       return 1;
10394     }
10395
10396   return 0;
10397 }
10398
10399 static const char *
10400 get_some_local_dynamic_name (void)
10401 {
10402   rtx insn;
10403
10404   if (cfun->machine->some_ld_name)
10405     return cfun->machine->some_ld_name;
10406
10407   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
10408     if (INSN_P (insn)
10409         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
10410       return cfun->machine->some_ld_name;
10411
10412   gcc_unreachable ();
10413 }
10414
10415 /* Meaning of CODE:
10416    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
10417    C -- print opcode suffix for set/cmov insn.
10418    c -- like C, but print reversed condition
10419    E,e -- likewise, but for compare-and-branch fused insn.
10420    F,f -- likewise, but for floating-point.
10421    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
10422         otherwise nothing
10423    R -- print the prefix for register names.
10424    z -- print the opcode suffix for the size of the current operand.
10425    * -- print a star (in certain assembler syntax)
10426    A -- print an absolute memory reference.
10427    w -- print the operand as if it's a "word" (HImode) even if it isn't.
10428    s -- print a shift double count, followed by the assemblers argument
10429         delimiter.
10430    b -- print the QImode name of the register for the indicated operand.
10431         %b0 would print %al if operands[0] is reg 0.
10432    w --  likewise, print the HImode name of the register.
10433    k --  likewise, print the SImode name of the register.
10434    q --  likewise, print the DImode name of the register.
10435    x --  likewise, print the V4SFmode name of the register.
10436    t --  likewise, print the V8SFmode name of the register.
10437    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
10438    y -- print "st(0)" instead of "st" as a register.
10439    d -- print duplicated register operand for AVX instruction.
10440    D -- print condition for SSE cmp instruction.
10441    P -- if PIC, print an @PLT suffix.
10442    X -- don't print any sort of PIC '@' suffix for a symbol.
10443    & -- print some in-use local-dynamic symbol name.
10444    H -- print a memory address offset by 8; used for sse high-parts
10445    Y -- print condition for SSE5 com* instruction.
10446    + -- print a branch hint as 'cs' or 'ds' prefix
10447    ; -- print a semicolon (after prefixes due to bug in older gas).
10448  */
10449
10450 void
10451 print_operand (FILE *file, rtx x, int code)
10452 {
10453   if (code)
10454     {
10455       switch (code)
10456         {
10457         case '*':
10458           if (ASSEMBLER_DIALECT == ASM_ATT)
10459             putc ('*', file);
10460           return;
10461
10462         case '&':
10463           assemble_name (file, get_some_local_dynamic_name ());
10464           return;
10465
10466         case 'A':
10467           switch (ASSEMBLER_DIALECT)
10468             {
10469             case ASM_ATT:
10470               putc ('*', file);
10471               break;
10472
10473             case ASM_INTEL:
10474               /* Intel syntax. For absolute addresses, registers should not
10475                  be surrounded by braces.  */
10476               if (!REG_P (x))
10477                 {
10478                   putc ('[', file);
10479                   PRINT_OPERAND (file, x, 0);
10480                   putc (']', file);
10481                   return;
10482                 }
10483               break;
10484
10485             default:
10486               gcc_unreachable ();
10487             }
10488
10489           PRINT_OPERAND (file, x, 0);
10490           return;
10491
10492
10493         case 'L':
10494           if (ASSEMBLER_DIALECT == ASM_ATT)
10495             putc ('l', file);
10496           return;
10497
10498         case 'W':
10499           if (ASSEMBLER_DIALECT == ASM_ATT)
10500             putc ('w', file);
10501           return;
10502
10503         case 'B':
10504           if (ASSEMBLER_DIALECT == ASM_ATT)
10505             putc ('b', file);
10506           return;
10507
10508         case 'Q':
10509           if (ASSEMBLER_DIALECT == ASM_ATT)
10510             putc ('l', file);
10511           return;
10512
10513         case 'S':
10514           if (ASSEMBLER_DIALECT == ASM_ATT)
10515             putc ('s', file);
10516           return;
10517
10518         case 'T':
10519           if (ASSEMBLER_DIALECT == ASM_ATT)
10520             putc ('t', file);
10521           return;
10522
10523         case 'z':
10524           /* 387 opcodes don't get size suffixes if the operands are
10525              registers.  */
10526           if (STACK_REG_P (x))
10527             return;
10528
10529           /* Likewise if using Intel opcodes.  */
10530           if (ASSEMBLER_DIALECT == ASM_INTEL)
10531             return;
10532
10533           /* This is the size of op from size of operand.  */
10534           switch (GET_MODE_SIZE (GET_MODE (x)))
10535             {
10536             case 1:
10537               putc ('b', file);
10538               return;
10539
10540             case 2:
10541               if (MEM_P (x))
10542                 {
10543 #ifdef HAVE_GAS_FILDS_FISTS
10544                   putc ('s', file);
10545 #endif
10546                   return;
10547                 }
10548               else
10549                 putc ('w', file);
10550               return;
10551
10552             case 4:
10553               if (GET_MODE (x) == SFmode)
10554                 {
10555                   putc ('s', file);
10556                   return;
10557                 }
10558               else
10559                 putc ('l', file);
10560               return;
10561
10562             case 12:
10563             case 16:
10564               putc ('t', file);
10565               return;
10566
10567             case 8:
10568               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
10569                 {
10570                   if (MEM_P (x))
10571                     {
10572 #ifdef GAS_MNEMONICS
10573                       putc ('q', file);
10574 #else
10575                       putc ('l', file);
10576                       putc ('l', file);
10577 #endif
10578                     }
10579                   else
10580                     putc ('q', file);
10581                 }
10582               else
10583                 putc ('l', file);
10584               return;
10585
10586             default:
10587               gcc_unreachable ();
10588             }
10589
10590         case 'd':
10591         case 'b':
10592         case 'w':
10593         case 'k':
10594         case 'q':
10595         case 'h':
10596         case 't':
10597         case 'y':
10598         case 'x':
10599         case 'X':
10600         case 'P':
10601           break;
10602
10603         case 's':
10604           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
10605             {
10606               PRINT_OPERAND (file, x, 0);
10607               fputs (", ", file);
10608             }
10609           return;
10610
10611         case 'D':
10612           /* Little bit of braindamage here.  The SSE compare instructions
10613              does use completely different names for the comparisons that the
10614              fp conditional moves.  */
10615           if (TARGET_AVX)
10616             {
10617               switch (GET_CODE (x))
10618                 {
10619                 case EQ:
10620                   fputs ("eq", file);
10621                   break;
10622                 case UNEQ:
10623                   fputs ("eq_us", file);
10624                   break;
10625                 case LT:
10626                   fputs ("lt", file);
10627                   break;
10628                 case UNLT:
10629                   fputs ("nge", file);
10630                   break;
10631                 case LE:
10632                   fputs ("le", file);
10633                   break;
10634                 case UNLE:
10635                   fputs ("ngt", file);
10636                   break;
10637                 case UNORDERED:
10638                   fputs ("unord", file);
10639                   break;
10640                 case NE:
10641                   fputs ("neq", file);
10642                   break;
10643                 case LTGT:
10644                   fputs ("neq_oq", file);
10645                   break;
10646                 case GE:
10647                   fputs ("ge", file);
10648                   break;
10649                 case UNGE:
10650                   fputs ("nlt", file);
10651                   break;
10652                 case GT:
10653                   fputs ("gt", file);
10654                   break;
10655                 case UNGT:
10656                   fputs ("nle", file);
10657                   break;
10658                 case ORDERED:
10659                   fputs ("ord", file);
10660                   break;
10661                 default:
10662                   gcc_unreachable ();
10663                 }
10664             }
10665           else
10666             {
10667               switch (GET_CODE (x))
10668                 {
10669                 case EQ:
10670                 case UNEQ:
10671                   fputs ("eq", file);
10672                   break;
10673                 case LT:
10674                 case UNLT:
10675                   fputs ("lt", file);
10676                   break;
10677                 case LE:
10678                 case UNLE:
10679                   fputs ("le", file);
10680                   break;
10681                 case UNORDERED:
10682                   fputs ("unord", file);
10683                   break;
10684                 case NE:
10685                 case LTGT:
10686                   fputs ("neq", file);
10687                   break;
10688                 case UNGE:
10689                 case GE:
10690                   fputs ("nlt", file);
10691                   break;
10692                 case UNGT:
10693                 case GT:
10694                   fputs ("nle", file);
10695                   break;
10696                 case ORDERED:
10697                   fputs ("ord", file);
10698                   break;
10699                 default:
10700                   gcc_unreachable ();
10701                 }
10702             }
10703           return;
10704         case 'O':
10705 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10706           if (ASSEMBLER_DIALECT == ASM_ATT)
10707             {
10708               switch (GET_MODE (x))
10709                 {
10710                 case HImode: putc ('w', file); break;
10711                 case SImode:
10712                 case SFmode: putc ('l', file); break;
10713                 case DImode:
10714                 case DFmode: putc ('q', file); break;
10715                 default: gcc_unreachable ();
10716                 }
10717               putc ('.', file);
10718             }
10719 #endif
10720           return;
10721         case 'C':
10722           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
10723           return;
10724         case 'F':
10725 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10726           if (ASSEMBLER_DIALECT == ASM_ATT)
10727             putc ('.', file);
10728 #endif
10729           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
10730           return;
10731
10732           /* Like above, but reverse condition */
10733         case 'c':
10734           /* Check to see if argument to %c is really a constant
10735              and not a condition code which needs to be reversed.  */
10736           if (!COMPARISON_P (x))
10737           {
10738             output_operand_lossage ("operand is neither a constant nor a condition code, invalid operand code 'c'");
10739              return;
10740           }
10741           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
10742           return;
10743         case 'f':
10744 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10745           if (ASSEMBLER_DIALECT == ASM_ATT)
10746             putc ('.', file);
10747 #endif
10748           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
10749           return;
10750
10751         case 'E':
10752           put_condition_code (GET_CODE (x), CCmode, 0, 0, file);
10753           return;
10754
10755         case 'e':
10756           put_condition_code (GET_CODE (x), CCmode, 1, 0, file);
10757           return;
10758
10759         case 'H':
10760           /* It doesn't actually matter what mode we use here, as we're
10761              only going to use this for printing.  */
10762           x = adjust_address_nv (x, DImode, 8);
10763           break;
10764
10765         case '+':
10766           {
10767             rtx x;
10768
10769             if (!optimize
10770                 || optimize_function_for_size_p (cfun) || !TARGET_BRANCH_PREDICTION_HINTS)
10771               return;
10772
10773             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
10774             if (x)
10775               {
10776                 int pred_val = INTVAL (XEXP (x, 0));
10777
10778                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
10779                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
10780                   {
10781                     int taken = pred_val > REG_BR_PROB_BASE / 2;
10782                     int cputaken = final_forward_branch_p (current_output_insn) == 0;
10783
10784                     /* Emit hints only in the case default branch prediction
10785                        heuristics would fail.  */
10786                     if (taken != cputaken)
10787                       {
10788                         /* We use 3e (DS) prefix for taken branches and
10789                            2e (CS) prefix for not taken branches.  */
10790                         if (taken)
10791                           fputs ("ds ; ", file);
10792                         else
10793                           fputs ("cs ; ", file);
10794                       }
10795                   }
10796               }
10797             return;
10798           }
10799
10800         case 'Y':
10801           switch (GET_CODE (x))
10802             {
10803             case NE:
10804               fputs ("neq", file);
10805               break;
10806             case EQ:
10807               fputs ("eq", file);
10808               break;
10809             case GE:
10810             case GEU:
10811               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
10812               break;
10813             case GT:
10814             case GTU:
10815               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
10816               break;
10817             case LE:
10818             case LEU:
10819               fputs ("le", file);
10820               break;
10821             case LT:
10822             case LTU:
10823               fputs ("lt", file);
10824               break;
10825             case UNORDERED:
10826               fputs ("unord", file);
10827               break;
10828             case ORDERED:
10829               fputs ("ord", file);
10830               break;
10831             case UNEQ:
10832               fputs ("ueq", file);
10833               break;
10834             case UNGE:
10835               fputs ("nlt", file);
10836               break;
10837             case UNGT:
10838               fputs ("nle", file);
10839               break;
10840             case UNLE:
10841               fputs ("ule", file);
10842               break;
10843             case UNLT:
10844               fputs ("ult", file);
10845               break;
10846             case LTGT:
10847               fputs ("une", file);
10848               break;
10849             default:
10850               gcc_unreachable ();
10851             }
10852           return;
10853
10854         case ';':
10855 #if TARGET_MACHO
10856           fputs (" ; ", file);
10857 #else
10858           fputc (' ', file);
10859 #endif
10860           return;
10861
10862         default:
10863             output_operand_lossage ("invalid operand code '%c'", code);
10864         }
10865     }
10866
10867   if (REG_P (x))
10868     print_reg (x, code, file);
10869
10870   else if (MEM_P (x))
10871     {
10872       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
10873       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
10874           && GET_MODE (x) != BLKmode)
10875         {
10876           const char * size;
10877           switch (GET_MODE_SIZE (GET_MODE (x)))
10878             {
10879             case 1: size = "BYTE"; break;
10880             case 2: size = "WORD"; break;
10881             case 4: size = "DWORD"; break;
10882             case 8: size = "QWORD"; break;
10883             case 12: size = "XWORD"; break;
10884             case 16:
10885               if (GET_MODE (x) == XFmode)
10886                 size = "XWORD";
10887               else
10888                 size = "XMMWORD";
10889               break;
10890             default:
10891               gcc_unreachable ();
10892             }
10893
10894           /* Check for explicit size override (codes 'b', 'w' and 'k')  */
10895           if (code == 'b')
10896             size = "BYTE";
10897           else if (code == 'w')
10898             size = "WORD";
10899           else if (code == 'k')
10900             size = "DWORD";
10901
10902           fputs (size, file);
10903           fputs (" PTR ", file);
10904         }
10905
10906       x = XEXP (x, 0);
10907       /* Avoid (%rip) for call operands.  */
10908       if (CONSTANT_ADDRESS_P (x) && code == 'P'
10909           && !CONST_INT_P (x))
10910         output_addr_const (file, x);
10911       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
10912         output_operand_lossage ("invalid constraints for operand");
10913       else
10914         output_address (x);
10915     }
10916
10917   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
10918     {
10919       REAL_VALUE_TYPE r;
10920       long l;
10921
10922       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
10923       REAL_VALUE_TO_TARGET_SINGLE (r, l);
10924
10925       if (ASSEMBLER_DIALECT == ASM_ATT)
10926         putc ('$', file);
10927       fprintf (file, "0x%08lx", (long unsigned int) l);
10928     }
10929
10930   /* These float cases don't actually occur as immediate operands.  */
10931   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
10932     {
10933       char dstr[30];
10934
10935       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
10936       fprintf (file, "%s", dstr);
10937     }
10938
10939   else if (GET_CODE (x) == CONST_DOUBLE
10940            && GET_MODE (x) == XFmode)
10941     {
10942       char dstr[30];
10943
10944       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
10945       fprintf (file, "%s", dstr);
10946     }
10947
10948   else
10949     {
10950       /* We have patterns that allow zero sets of memory, for instance.
10951          In 64-bit mode, we should probably support all 8-byte vectors,
10952          since we can in fact encode that into an immediate.  */
10953       if (GET_CODE (x) == CONST_VECTOR)
10954         {
10955           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
10956           x = const0_rtx;
10957         }
10958
10959       if (code != 'P')
10960         {
10961           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
10962             {
10963               if (ASSEMBLER_DIALECT == ASM_ATT)
10964                 putc ('$', file);
10965             }
10966           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
10967                    || GET_CODE (x) == LABEL_REF)
10968             {
10969               if (ASSEMBLER_DIALECT == ASM_ATT)
10970                 putc ('$', file);
10971               else
10972                 fputs ("OFFSET FLAT:", file);
10973             }
10974         }
10975       if (CONST_INT_P (x))
10976         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
10977       else if (flag_pic)
10978         output_pic_addr_const (file, x, code);
10979       else
10980         output_addr_const (file, x);
10981     }
10982 }
10983 \f
10984 /* Print a memory operand whose address is ADDR.  */
10985
10986 void
10987 print_operand_address (FILE *file, rtx addr)
10988 {
10989   struct ix86_address parts;
10990   rtx base, index, disp;
10991   int scale;
10992   int ok = ix86_decompose_address (addr, &parts);
10993
10994   gcc_assert (ok);
10995
10996   base = parts.base;
10997   index = parts.index;
10998   disp = parts.disp;
10999   scale = parts.scale;
11000
11001   switch (parts.seg)
11002     {
11003     case SEG_DEFAULT:
11004       break;
11005     case SEG_FS:
11006     case SEG_GS:
11007       if (ASSEMBLER_DIALECT == ASM_ATT)
11008         putc ('%', file);
11009       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
11010       break;
11011     default:
11012       gcc_unreachable ();
11013     }
11014
11015   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
11016   if (TARGET_64BIT && !base && !index)
11017     {
11018       rtx symbol = disp;
11019
11020       if (GET_CODE (disp) == CONST
11021           && GET_CODE (XEXP (disp, 0)) == PLUS
11022           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11023         symbol = XEXP (XEXP (disp, 0), 0);
11024
11025       if (GET_CODE (symbol) == LABEL_REF
11026           || (GET_CODE (symbol) == SYMBOL_REF
11027               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
11028         base = pc_rtx;
11029     }
11030   if (!base && !index)
11031     {
11032       /* Displacement only requires special attention.  */
11033
11034       if (CONST_INT_P (disp))
11035         {
11036           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
11037             fputs ("ds:", file);
11038           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
11039         }
11040       else if (flag_pic)
11041         output_pic_addr_const (file, disp, 0);
11042       else
11043         output_addr_const (file, disp);
11044     }
11045   else
11046     {
11047       if (ASSEMBLER_DIALECT == ASM_ATT)
11048         {
11049           if (disp)
11050             {
11051               if (flag_pic)
11052                 output_pic_addr_const (file, disp, 0);
11053               else if (GET_CODE (disp) == LABEL_REF)
11054                 output_asm_label (disp);
11055               else
11056                 output_addr_const (file, disp);
11057             }
11058
11059           putc ('(', file);
11060           if (base)
11061             print_reg (base, 0, file);
11062           if (index)
11063             {
11064               putc (',', file);
11065               print_reg (index, 0, file);
11066               if (scale != 1)
11067                 fprintf (file, ",%d", scale);
11068             }
11069           putc (')', file);
11070         }
11071       else
11072         {
11073           rtx offset = NULL_RTX;
11074
11075           if (disp)
11076             {
11077               /* Pull out the offset of a symbol; print any symbol itself.  */
11078               if (GET_CODE (disp) == CONST
11079                   && GET_CODE (XEXP (disp, 0)) == PLUS
11080                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11081                 {
11082                   offset = XEXP (XEXP (disp, 0), 1);
11083                   disp = gen_rtx_CONST (VOIDmode,
11084                                         XEXP (XEXP (disp, 0), 0));
11085                 }
11086
11087               if (flag_pic)
11088                 output_pic_addr_const (file, disp, 0);
11089               else if (GET_CODE (disp) == LABEL_REF)
11090                 output_asm_label (disp);
11091               else if (CONST_INT_P (disp))
11092                 offset = disp;
11093               else
11094                 output_addr_const (file, disp);
11095             }
11096
11097           putc ('[', file);
11098           if (base)
11099             {
11100               print_reg (base, 0, file);
11101               if (offset)
11102                 {
11103                   if (INTVAL (offset) >= 0)
11104                     putc ('+', file);
11105                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11106                 }
11107             }
11108           else if (offset)
11109             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11110           else
11111             putc ('0', file);
11112
11113           if (index)
11114             {
11115               putc ('+', file);
11116               print_reg (index, 0, file);
11117               if (scale != 1)
11118                 fprintf (file, "*%d", scale);
11119             }
11120           putc (']', file);
11121         }
11122     }
11123 }
11124
11125 bool
11126 output_addr_const_extra (FILE *file, rtx x)
11127 {
11128   rtx op;
11129
11130   if (GET_CODE (x) != UNSPEC)
11131     return false;
11132
11133   op = XVECEXP (x, 0, 0);
11134   switch (XINT (x, 1))
11135     {
11136     case UNSPEC_GOTTPOFF:
11137       output_addr_const (file, op);
11138       /* FIXME: This might be @TPOFF in Sun ld.  */
11139       fputs ("@GOTTPOFF", file);
11140       break;
11141     case UNSPEC_TPOFF:
11142       output_addr_const (file, op);
11143       fputs ("@TPOFF", file);
11144       break;
11145     case UNSPEC_NTPOFF:
11146       output_addr_const (file, op);
11147       if (TARGET_64BIT)
11148         fputs ("@TPOFF", file);
11149       else
11150         fputs ("@NTPOFF", file);
11151       break;
11152     case UNSPEC_DTPOFF:
11153       output_addr_const (file, op);
11154       fputs ("@DTPOFF", file);
11155       break;
11156     case UNSPEC_GOTNTPOFF:
11157       output_addr_const (file, op);
11158       if (TARGET_64BIT)
11159         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
11160                "@GOTTPOFF(%rip)" : "@GOTTPOFF[rip]", file);
11161       else
11162         fputs ("@GOTNTPOFF", file);
11163       break;
11164     case UNSPEC_INDNTPOFF:
11165       output_addr_const (file, op);
11166       fputs ("@INDNTPOFF", file);
11167       break;
11168 #if TARGET_MACHO
11169     case UNSPEC_MACHOPIC_OFFSET:
11170       output_addr_const (file, op);
11171       putc ('-', file);
11172       machopic_output_function_base_name (file);
11173       break;
11174 #endif
11175
11176     default:
11177       return false;
11178     }
11179
11180   return true;
11181 }
11182 \f
11183 /* Split one or more DImode RTL references into pairs of SImode
11184    references.  The RTL can be REG, offsettable MEM, integer constant, or
11185    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11186    split and "num" is its length.  lo_half and hi_half are output arrays
11187    that parallel "operands".  */
11188
11189 void
11190 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11191 {
11192   while (num--)
11193     {
11194       rtx op = operands[num];
11195
11196       /* simplify_subreg refuse to split volatile memory addresses,
11197          but we still have to handle it.  */
11198       if (MEM_P (op))
11199         {
11200           lo_half[num] = adjust_address (op, SImode, 0);
11201           hi_half[num] = adjust_address (op, SImode, 4);
11202         }
11203       else
11204         {
11205           lo_half[num] = simplify_gen_subreg (SImode, op,
11206                                               GET_MODE (op) == VOIDmode
11207                                               ? DImode : GET_MODE (op), 0);
11208           hi_half[num] = simplify_gen_subreg (SImode, op,
11209                                               GET_MODE (op) == VOIDmode
11210                                               ? DImode : GET_MODE (op), 4);
11211         }
11212     }
11213 }
11214 /* Split one or more TImode RTL references into pairs of DImode
11215    references.  The RTL can be REG, offsettable MEM, integer constant, or
11216    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11217    split and "num" is its length.  lo_half and hi_half are output arrays
11218    that parallel "operands".  */
11219
11220 void
11221 split_ti (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11222 {
11223   while (num--)
11224     {
11225       rtx op = operands[num];
11226
11227       /* simplify_subreg refuse to split volatile memory addresses, but we
11228          still have to handle it.  */
11229       if (MEM_P (op))
11230         {
11231           lo_half[num] = adjust_address (op, DImode, 0);
11232           hi_half[num] = adjust_address (op, DImode, 8);
11233         }
11234       else
11235         {
11236           lo_half[num] = simplify_gen_subreg (DImode, op, TImode, 0);
11237           hi_half[num] = simplify_gen_subreg (DImode, op, TImode, 8);
11238         }
11239     }
11240 }
11241 \f
11242 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
11243    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
11244    is the expression of the binary operation.  The output may either be
11245    emitted here, or returned to the caller, like all output_* functions.
11246
11247    There is no guarantee that the operands are the same mode, as they
11248    might be within FLOAT or FLOAT_EXTEND expressions.  */
11249
11250 #ifndef SYSV386_COMPAT
11251 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
11252    wants to fix the assemblers because that causes incompatibility
11253    with gcc.  No-one wants to fix gcc because that causes
11254    incompatibility with assemblers...  You can use the option of
11255    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
11256 #define SYSV386_COMPAT 1
11257 #endif
11258
11259 const char *
11260 output_387_binary_op (rtx insn, rtx *operands)
11261 {
11262   static char buf[40];
11263   const char *p;
11264   const char *ssep;
11265   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
11266
11267 #ifdef ENABLE_CHECKING
11268   /* Even if we do not want to check the inputs, this documents input
11269      constraints.  Which helps in understanding the following code.  */
11270   if (STACK_REG_P (operands[0])
11271       && ((REG_P (operands[1])
11272            && REGNO (operands[0]) == REGNO (operands[1])
11273            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
11274           || (REG_P (operands[2])
11275               && REGNO (operands[0]) == REGNO (operands[2])
11276               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
11277       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
11278     ; /* ok */
11279   else
11280     gcc_assert (is_sse);
11281 #endif
11282
11283   switch (GET_CODE (operands[3]))
11284     {
11285     case PLUS:
11286       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11287           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11288         p = "fiadd";
11289       else
11290         p = "fadd";
11291       ssep = "vadd";
11292       break;
11293
11294     case MINUS:
11295       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11296           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11297         p = "fisub";
11298       else
11299         p = "fsub";
11300       ssep = "vsub";
11301       break;
11302
11303     case MULT:
11304       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11305           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11306         p = "fimul";
11307       else
11308         p = "fmul";
11309       ssep = "vmul";
11310       break;
11311
11312     case DIV:
11313       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11314           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11315         p = "fidiv";
11316       else
11317         p = "fdiv";
11318       ssep = "vdiv";
11319       break;
11320
11321     default:
11322       gcc_unreachable ();
11323     }
11324
11325   if (is_sse)
11326    {
11327      if (TARGET_AVX)
11328        {
11329          strcpy (buf, ssep);
11330          if (GET_MODE (operands[0]) == SFmode)
11331            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
11332          else
11333            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
11334        }
11335      else
11336        {
11337          strcpy (buf, ssep + 1);
11338          if (GET_MODE (operands[0]) == SFmode)
11339            strcat (buf, "ss\t{%2, %0|%0, %2}");
11340          else
11341            strcat (buf, "sd\t{%2, %0|%0, %2}");
11342        }
11343       return buf;
11344    }
11345   strcpy (buf, p);
11346
11347   switch (GET_CODE (operands[3]))
11348     {
11349     case MULT:
11350     case PLUS:
11351       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
11352         {
11353           rtx temp = operands[2];
11354           operands[2] = operands[1];
11355           operands[1] = temp;
11356         }
11357
11358       /* know operands[0] == operands[1].  */
11359
11360       if (MEM_P (operands[2]))
11361         {
11362           p = "%z2\t%2";
11363           break;
11364         }
11365
11366       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11367         {
11368           if (STACK_TOP_P (operands[0]))
11369             /* How is it that we are storing to a dead operand[2]?
11370                Well, presumably operands[1] is dead too.  We can't
11371                store the result to st(0) as st(0) gets popped on this
11372                instruction.  Instead store to operands[2] (which I
11373                think has to be st(1)).  st(1) will be popped later.
11374                gcc <= 2.8.1 didn't have this check and generated
11375                assembly code that the Unixware assembler rejected.  */
11376             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
11377           else
11378             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11379           break;
11380         }
11381
11382       if (STACK_TOP_P (operands[0]))
11383         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
11384       else
11385         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
11386       break;
11387
11388     case MINUS:
11389     case DIV:
11390       if (MEM_P (operands[1]))
11391         {
11392           p = "r%z1\t%1";
11393           break;
11394         }
11395
11396       if (MEM_P (operands[2]))
11397         {
11398           p = "%z2\t%2";
11399           break;
11400         }
11401
11402       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11403         {
11404 #if SYSV386_COMPAT
11405           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
11406              derived assemblers, confusingly reverse the direction of
11407              the operation for fsub{r} and fdiv{r} when the
11408              destination register is not st(0).  The Intel assembler
11409              doesn't have this brain damage.  Read !SYSV386_COMPAT to
11410              figure out what the hardware really does.  */
11411           if (STACK_TOP_P (operands[0]))
11412             p = "{p\t%0, %2|rp\t%2, %0}";
11413           else
11414             p = "{rp\t%2, %0|p\t%0, %2}";
11415 #else
11416           if (STACK_TOP_P (operands[0]))
11417             /* As above for fmul/fadd, we can't store to st(0).  */
11418             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
11419           else
11420             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11421 #endif
11422           break;
11423         }
11424
11425       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
11426         {
11427 #if SYSV386_COMPAT
11428           if (STACK_TOP_P (operands[0]))
11429             p = "{rp\t%0, %1|p\t%1, %0}";
11430           else
11431             p = "{p\t%1, %0|rp\t%0, %1}";
11432 #else
11433           if (STACK_TOP_P (operands[0]))
11434             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
11435           else
11436             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
11437 #endif
11438           break;
11439         }
11440
11441       if (STACK_TOP_P (operands[0]))
11442         {
11443           if (STACK_TOP_P (operands[1]))
11444             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
11445           else
11446             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
11447           break;
11448         }
11449       else if (STACK_TOP_P (operands[1]))
11450         {
11451 #if SYSV386_COMPAT
11452           p = "{\t%1, %0|r\t%0, %1}";
11453 #else
11454           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
11455 #endif
11456         }
11457       else
11458         {
11459 #if SYSV386_COMPAT
11460           p = "{r\t%2, %0|\t%0, %2}";
11461 #else
11462           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
11463 #endif
11464         }
11465       break;
11466
11467     default:
11468       gcc_unreachable ();
11469     }
11470
11471   strcat (buf, p);
11472   return buf;
11473 }
11474
11475 /* Return needed mode for entity in optimize_mode_switching pass.  */
11476
11477 int
11478 ix86_mode_needed (int entity, rtx insn)
11479 {
11480   enum attr_i387_cw mode;
11481
11482   /* The mode UNINITIALIZED is used to store control word after a
11483      function call or ASM pattern.  The mode ANY specify that function
11484      has no requirements on the control word and make no changes in the
11485      bits we are interested in.  */
11486
11487   if (CALL_P (insn)
11488       || (NONJUMP_INSN_P (insn)
11489           && (asm_noperands (PATTERN (insn)) >= 0
11490               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
11491     return I387_CW_UNINITIALIZED;
11492
11493   if (recog_memoized (insn) < 0)
11494     return I387_CW_ANY;
11495
11496   mode = get_attr_i387_cw (insn);
11497
11498   switch (entity)
11499     {
11500     case I387_TRUNC:
11501       if (mode == I387_CW_TRUNC)
11502         return mode;
11503       break;
11504
11505     case I387_FLOOR:
11506       if (mode == I387_CW_FLOOR)
11507         return mode;
11508       break;
11509
11510     case I387_CEIL:
11511       if (mode == I387_CW_CEIL)
11512         return mode;
11513       break;
11514
11515     case I387_MASK_PM:
11516       if (mode == I387_CW_MASK_PM)
11517         return mode;
11518       break;
11519
11520     default:
11521       gcc_unreachable ();
11522     }
11523
11524   return I387_CW_ANY;
11525 }
11526
11527 /* Output code to initialize control word copies used by trunc?f?i and
11528    rounding patterns.  CURRENT_MODE is set to current control word,
11529    while NEW_MODE is set to new control word.  */
11530
11531 void
11532 emit_i387_cw_initialization (int mode)
11533 {
11534   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
11535   rtx new_mode;
11536
11537   enum ix86_stack_slot slot;
11538
11539   rtx reg = gen_reg_rtx (HImode);
11540
11541   emit_insn (gen_x86_fnstcw_1 (stored_mode));
11542   emit_move_insn (reg, copy_rtx (stored_mode));
11543
11544   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
11545       || optimize_function_for_size_p (cfun))
11546     {
11547       switch (mode)
11548         {
11549         case I387_CW_TRUNC:
11550           /* round toward zero (truncate) */
11551           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
11552           slot = SLOT_CW_TRUNC;
11553           break;
11554
11555         case I387_CW_FLOOR:
11556           /* round down toward -oo */
11557           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11558           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
11559           slot = SLOT_CW_FLOOR;
11560           break;
11561
11562         case I387_CW_CEIL:
11563           /* round up toward +oo */
11564           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11565           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
11566           slot = SLOT_CW_CEIL;
11567           break;
11568
11569         case I387_CW_MASK_PM:
11570           /* mask precision exception for nearbyint() */
11571           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11572           slot = SLOT_CW_MASK_PM;
11573           break;
11574
11575         default:
11576           gcc_unreachable ();
11577         }
11578     }
11579   else
11580     {
11581       switch (mode)
11582         {
11583         case I387_CW_TRUNC:
11584           /* round toward zero (truncate) */
11585           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
11586           slot = SLOT_CW_TRUNC;
11587           break;
11588
11589         case I387_CW_FLOOR:
11590           /* round down toward -oo */
11591           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
11592           slot = SLOT_CW_FLOOR;
11593           break;
11594
11595         case I387_CW_CEIL:
11596           /* round up toward +oo */
11597           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
11598           slot = SLOT_CW_CEIL;
11599           break;
11600
11601         case I387_CW_MASK_PM:
11602           /* mask precision exception for nearbyint() */
11603           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11604           slot = SLOT_CW_MASK_PM;
11605           break;
11606
11607         default:
11608           gcc_unreachable ();
11609         }
11610     }
11611
11612   gcc_assert (slot < MAX_386_STACK_LOCALS);
11613
11614   new_mode = assign_386_stack_local (HImode, slot);
11615   emit_move_insn (new_mode, reg);
11616 }
11617
11618 /* Output code for INSN to convert a float to a signed int.  OPERANDS
11619    are the insn operands.  The output may be [HSD]Imode and the input
11620    operand may be [SDX]Fmode.  */
11621
11622 const char *
11623 output_fix_trunc (rtx insn, rtx *operands, int fisttp)
11624 {
11625   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11626   int dimode_p = GET_MODE (operands[0]) == DImode;
11627   int round_mode = get_attr_i387_cw (insn);
11628
11629   /* Jump through a hoop or two for DImode, since the hardware has no
11630      non-popping instruction.  We used to do this a different way, but
11631      that was somewhat fragile and broke with post-reload splitters.  */
11632   if ((dimode_p || fisttp) && !stack_top_dies)
11633     output_asm_insn ("fld\t%y1", operands);
11634
11635   gcc_assert (STACK_TOP_P (operands[1]));
11636   gcc_assert (MEM_P (operands[0]));
11637   gcc_assert (GET_MODE (operands[1]) != TFmode);
11638
11639   if (fisttp)
11640       output_asm_insn ("fisttp%z0\t%0", operands);
11641   else
11642     {
11643       if (round_mode != I387_CW_ANY)
11644         output_asm_insn ("fldcw\t%3", operands);
11645       if (stack_top_dies || dimode_p)
11646         output_asm_insn ("fistp%z0\t%0", operands);
11647       else
11648         output_asm_insn ("fist%z0\t%0", operands);
11649       if (round_mode != I387_CW_ANY)
11650         output_asm_insn ("fldcw\t%2", operands);
11651     }
11652
11653   return "";
11654 }
11655
11656 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
11657    have the values zero or one, indicates the ffreep insn's operand
11658    from the OPERANDS array.  */
11659
11660 static const char *
11661 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
11662 {
11663   if (TARGET_USE_FFREEP)
11664 #if HAVE_AS_IX86_FFREEP
11665     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
11666 #else
11667     {
11668       static char retval[] = ".word\t0xc_df";
11669       int regno = REGNO (operands[opno]);
11670
11671       gcc_assert (FP_REGNO_P (regno));
11672
11673       retval[9] = '0' + (regno - FIRST_STACK_REG);
11674       return retval;
11675     }
11676 #endif
11677
11678   return opno ? "fstp\t%y1" : "fstp\t%y0";
11679 }
11680
11681
11682 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
11683    should be used.  UNORDERED_P is true when fucom should be used.  */
11684
11685 const char *
11686 output_fp_compare (rtx insn, rtx *operands, int eflags_p, int unordered_p)
11687 {
11688   int stack_top_dies;
11689   rtx cmp_op0, cmp_op1;
11690   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
11691
11692   if (eflags_p)
11693     {
11694       cmp_op0 = operands[0];
11695       cmp_op1 = operands[1];
11696     }
11697   else
11698     {
11699       cmp_op0 = operands[1];
11700       cmp_op1 = operands[2];
11701     }
11702
11703   if (is_sse)
11704     {
11705       static const char ucomiss[] = "vucomiss\t{%1, %0|%0, %1}";
11706       static const char ucomisd[] = "vucomisd\t{%1, %0|%0, %1}";
11707       static const char comiss[] = "vcomiss\t{%1, %0|%0, %1}";
11708       static const char comisd[] = "vcomisd\t{%1, %0|%0, %1}";
11709
11710       if (GET_MODE (operands[0]) == SFmode)
11711         if (unordered_p)
11712           return &ucomiss[TARGET_AVX ? 0 : 1];
11713         else
11714           return &comiss[TARGET_AVX ? 0 : 1];
11715       else
11716         if (unordered_p)
11717           return &ucomisd[TARGET_AVX ? 0 : 1];
11718         else
11719           return &comisd[TARGET_AVX ? 0 : 1];
11720     }
11721
11722   gcc_assert (STACK_TOP_P (cmp_op0));
11723
11724   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11725
11726   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
11727     {
11728       if (stack_top_dies)
11729         {
11730           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
11731           return output_387_ffreep (operands, 1);
11732         }
11733       else
11734         return "ftst\n\tfnstsw\t%0";
11735     }
11736
11737   if (STACK_REG_P (cmp_op1)
11738       && stack_top_dies
11739       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
11740       && REGNO (cmp_op1) != FIRST_STACK_REG)
11741     {
11742       /* If both the top of the 387 stack dies, and the other operand
11743          is also a stack register that dies, then this must be a
11744          `fcompp' float compare */
11745
11746       if (eflags_p)
11747         {
11748           /* There is no double popping fcomi variant.  Fortunately,
11749              eflags is immune from the fstp's cc clobbering.  */
11750           if (unordered_p)
11751             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
11752           else
11753             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
11754           return output_387_ffreep (operands, 0);
11755         }
11756       else
11757         {
11758           if (unordered_p)
11759             return "fucompp\n\tfnstsw\t%0";
11760           else
11761             return "fcompp\n\tfnstsw\t%0";
11762         }
11763     }
11764   else
11765     {
11766       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
11767
11768       static const char * const alt[16] =
11769       {
11770         "fcom%z2\t%y2\n\tfnstsw\t%0",
11771         "fcomp%z2\t%y2\n\tfnstsw\t%0",
11772         "fucom%z2\t%y2\n\tfnstsw\t%0",
11773         "fucomp%z2\t%y2\n\tfnstsw\t%0",
11774
11775         "ficom%z2\t%y2\n\tfnstsw\t%0",
11776         "ficomp%z2\t%y2\n\tfnstsw\t%0",
11777         NULL,
11778         NULL,
11779
11780         "fcomi\t{%y1, %0|%0, %y1}",
11781         "fcomip\t{%y1, %0|%0, %y1}",
11782         "fucomi\t{%y1, %0|%0, %y1}",
11783         "fucomip\t{%y1, %0|%0, %y1}",
11784
11785         NULL,
11786         NULL,
11787         NULL,
11788         NULL
11789       };
11790
11791       int mask;
11792       const char *ret;
11793
11794       mask  = eflags_p << 3;
11795       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
11796       mask |= unordered_p << 1;
11797       mask |= stack_top_dies;
11798
11799       gcc_assert (mask < 16);
11800       ret = alt[mask];
11801       gcc_assert (ret);
11802
11803       return ret;
11804     }
11805 }
11806
11807 void
11808 ix86_output_addr_vec_elt (FILE *file, int value)
11809 {
11810   const char *directive = ASM_LONG;
11811
11812 #ifdef ASM_QUAD
11813   if (TARGET_64BIT)
11814     directive = ASM_QUAD;
11815 #else
11816   gcc_assert (!TARGET_64BIT);
11817 #endif
11818
11819   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
11820 }
11821
11822 void
11823 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
11824 {
11825   const char *directive = ASM_LONG;
11826
11827 #ifdef ASM_QUAD
11828   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
11829     directive = ASM_QUAD;
11830 #else
11831   gcc_assert (!TARGET_64BIT);
11832 #endif
11833   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
11834   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
11835     fprintf (file, "%s%s%d-%s%d\n",
11836              directive, LPREFIX, value, LPREFIX, rel);
11837   else if (HAVE_AS_GOTOFF_IN_DATA)
11838     fprintf (file, "%s%s%d@GOTOFF\n", ASM_LONG, LPREFIX, value);
11839 #if TARGET_MACHO
11840   else if (TARGET_MACHO)
11841     {
11842       fprintf (file, "%s%s%d-", ASM_LONG, LPREFIX, value);
11843       machopic_output_function_base_name (file);
11844       fprintf(file, "\n");
11845     }
11846 #endif
11847   else
11848     asm_fprintf (file, "%s%U%s+[.-%s%d]\n",
11849                  ASM_LONG, GOT_SYMBOL_NAME, LPREFIX, value);
11850 }
11851 \f
11852 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
11853    for the target.  */
11854
11855 void
11856 ix86_expand_clear (rtx dest)
11857 {
11858   rtx tmp;
11859
11860   /* We play register width games, which are only valid after reload.  */
11861   gcc_assert (reload_completed);
11862
11863   /* Avoid HImode and its attendant prefix byte.  */
11864   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
11865     dest = gen_rtx_REG (SImode, REGNO (dest));
11866   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
11867
11868   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
11869   if (reload_completed && (!TARGET_USE_MOV0 || optimize_insn_for_speed_p ()))
11870     {
11871       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
11872       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
11873     }
11874
11875   emit_insn (tmp);
11876 }
11877
11878 /* X is an unchanging MEM.  If it is a constant pool reference, return
11879    the constant pool rtx, else NULL.  */
11880
11881 rtx
11882 maybe_get_pool_constant (rtx x)
11883 {
11884   x = ix86_delegitimize_address (XEXP (x, 0));
11885
11886   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
11887     return get_pool_constant (x);
11888
11889   return NULL_RTX;
11890 }
11891
11892 void
11893 ix86_expand_move (enum machine_mode mode, rtx operands[])
11894 {
11895   rtx op0, op1;
11896   enum tls_model model;
11897
11898   op0 = operands[0];
11899   op1 = operands[1];
11900
11901   if (GET_CODE (op1) == SYMBOL_REF)
11902     {
11903       model = SYMBOL_REF_TLS_MODEL (op1);
11904       if (model)
11905         {
11906           op1 = legitimize_tls_address (op1, model, true);
11907           op1 = force_operand (op1, op0);
11908           if (op1 == op0)
11909             return;
11910         }
11911       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
11912                && SYMBOL_REF_DLLIMPORT_P (op1))
11913         op1 = legitimize_dllimport_symbol (op1, false);
11914     }
11915   else if (GET_CODE (op1) == CONST
11916            && GET_CODE (XEXP (op1, 0)) == PLUS
11917            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
11918     {
11919       rtx addend = XEXP (XEXP (op1, 0), 1);
11920       rtx symbol = XEXP (XEXP (op1, 0), 0);
11921       rtx tmp = NULL;
11922
11923       model = SYMBOL_REF_TLS_MODEL (symbol);
11924       if (model)
11925         tmp = legitimize_tls_address (symbol, model, true);
11926       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
11927                && SYMBOL_REF_DLLIMPORT_P (symbol))
11928         tmp = legitimize_dllimport_symbol (symbol, true);
11929
11930       if (tmp)
11931         {
11932           tmp = force_operand (tmp, NULL);
11933           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
11934                                      op0, 1, OPTAB_DIRECT);
11935           if (tmp == op0)
11936             return;
11937         }
11938     }
11939
11940   if (flag_pic && mode == Pmode && symbolic_operand (op1, Pmode))
11941     {
11942       if (TARGET_MACHO && !TARGET_64BIT)
11943         {
11944 #if TARGET_MACHO
11945           if (MACHOPIC_PURE)
11946             {
11947               rtx temp = ((reload_in_progress
11948                            || ((op0 && REG_P (op0))
11949                                && mode == Pmode))
11950                           ? op0 : gen_reg_rtx (Pmode));
11951               op1 = machopic_indirect_data_reference (op1, temp);
11952               op1 = machopic_legitimize_pic_address (op1, mode,
11953                                                      temp == op1 ? 0 : temp);
11954             }
11955           else if (MACHOPIC_INDIRECT)
11956             op1 = machopic_indirect_data_reference (op1, 0);
11957           if (op0 == op1)
11958             return;
11959 #endif
11960         }
11961       else
11962         {
11963           if (MEM_P (op0))
11964             op1 = force_reg (Pmode, op1);
11965           else if (!TARGET_64BIT || !x86_64_movabs_operand (op1, Pmode))
11966             {
11967               rtx reg = !can_create_pseudo_p () ? op0 : NULL_RTX;
11968               op1 = legitimize_pic_address (op1, reg);
11969               if (op0 == op1)
11970                 return;
11971             }
11972         }
11973     }
11974   else
11975     {
11976       if (MEM_P (op0)
11977           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
11978               || !push_operand (op0, mode))
11979           && MEM_P (op1))
11980         op1 = force_reg (mode, op1);
11981
11982       if (push_operand (op0, mode)
11983           && ! general_no_elim_operand (op1, mode))
11984         op1 = copy_to_mode_reg (mode, op1);
11985
11986       /* Force large constants in 64bit compilation into register
11987          to get them CSEed.  */
11988       if (can_create_pseudo_p ()
11989           && (mode == DImode) && TARGET_64BIT
11990           && immediate_operand (op1, mode)
11991           && !x86_64_zext_immediate_operand (op1, VOIDmode)
11992           && !register_operand (op0, mode)
11993           && optimize)
11994         op1 = copy_to_mode_reg (mode, op1);
11995
11996       if (can_create_pseudo_p ()
11997           && FLOAT_MODE_P (mode)
11998           && GET_CODE (op1) == CONST_DOUBLE)
11999         {
12000           /* If we are loading a floating point constant to a register,
12001              force the value to memory now, since we'll get better code
12002              out the back end.  */
12003
12004           op1 = validize_mem (force_const_mem (mode, op1));
12005           if (!register_operand (op0, mode))
12006             {
12007               rtx temp = gen_reg_rtx (mode);
12008               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
12009               emit_move_insn (op0, temp);
12010               return;
12011             }
12012         }
12013     }
12014
12015   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12016 }
12017
12018 void
12019 ix86_expand_vector_move (enum machine_mode mode, rtx operands[])
12020 {
12021   rtx op0 = operands[0], op1 = operands[1];
12022   unsigned int align = GET_MODE_ALIGNMENT (mode);
12023
12024   /* Force constants other than zero into memory.  We do not know how
12025      the instructions used to build constants modify the upper 64 bits
12026      of the register, once we have that information we may be able
12027      to handle some of them more efficiently.  */
12028   if (can_create_pseudo_p ()
12029       && register_operand (op0, mode)
12030       && (CONSTANT_P (op1)
12031           || (GET_CODE (op1) == SUBREG
12032               && CONSTANT_P (SUBREG_REG (op1))))
12033       && standard_sse_constant_p (op1) <= 0)
12034     op1 = validize_mem (force_const_mem (mode, op1));
12035
12036   /* We need to check memory alignment for SSE mode since attribute
12037      can make operands unaligned.  */
12038   if (can_create_pseudo_p ()
12039       && SSE_REG_MODE_P (mode)
12040       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
12041           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
12042     {
12043       rtx tmp[2];
12044
12045       /* ix86_expand_vector_move_misalign() does not like constants ... */
12046       if (CONSTANT_P (op1)
12047           || (GET_CODE (op1) == SUBREG
12048               && CONSTANT_P (SUBREG_REG (op1))))
12049         op1 = validize_mem (force_const_mem (mode, op1));
12050
12051       /* ... nor both arguments in memory.  */
12052       if (!register_operand (op0, mode)
12053           && !register_operand (op1, mode))
12054         op1 = force_reg (mode, op1);
12055
12056       tmp[0] = op0; tmp[1] = op1;
12057       ix86_expand_vector_move_misalign (mode, tmp);
12058       return;
12059     }
12060
12061   /* Make operand1 a register if it isn't already.  */
12062   if (can_create_pseudo_p ()
12063       && !register_operand (op0, mode)
12064       && !register_operand (op1, mode))
12065     {
12066       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
12067       return;
12068     }
12069
12070   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12071 }
12072
12073 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
12074    straight to ix86_expand_vector_move.  */
12075 /* Code generation for scalar reg-reg moves of single and double precision data:
12076      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
12077        movaps reg, reg
12078      else
12079        movss reg, reg
12080      if (x86_sse_partial_reg_dependency == true)
12081        movapd reg, reg
12082      else
12083        movsd reg, reg
12084
12085    Code generation for scalar loads of double precision data:
12086      if (x86_sse_split_regs == true)
12087        movlpd mem, reg      (gas syntax)
12088      else
12089        movsd mem, reg
12090
12091    Code generation for unaligned packed loads of single precision data
12092    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
12093      if (x86_sse_unaligned_move_optimal)
12094        movups mem, reg
12095
12096      if (x86_sse_partial_reg_dependency == true)
12097        {
12098          xorps  reg, reg
12099          movlps mem, reg
12100          movhps mem+8, reg
12101        }
12102      else
12103        {
12104          movlps mem, reg
12105          movhps mem+8, reg
12106        }
12107
12108    Code generation for unaligned packed loads of double precision data
12109    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
12110      if (x86_sse_unaligned_move_optimal)
12111        movupd mem, reg
12112
12113      if (x86_sse_split_regs == true)
12114        {
12115          movlpd mem, reg
12116          movhpd mem+8, reg
12117        }
12118      else
12119        {
12120          movsd  mem, reg
12121          movhpd mem+8, reg
12122        }
12123  */
12124
12125 void
12126 ix86_expand_vector_move_misalign (enum machine_mode mode, rtx operands[])
12127 {
12128   rtx op0, op1, m;
12129
12130   op0 = operands[0];
12131   op1 = operands[1];
12132
12133   if (TARGET_AVX)
12134     {
12135       switch (GET_MODE_CLASS (mode))
12136         {
12137         case MODE_VECTOR_INT:
12138         case MODE_INT:
12139           switch (GET_MODE_SIZE (mode))
12140             {
12141             case 16:
12142               op0 = gen_lowpart (V16QImode, op0);
12143               op1 = gen_lowpart (V16QImode, op1);
12144               emit_insn (gen_avx_movdqu (op0, op1));
12145               break;
12146             case 32:
12147               op0 = gen_lowpart (V32QImode, op0);
12148               op1 = gen_lowpart (V32QImode, op1);
12149               emit_insn (gen_avx_movdqu256 (op0, op1));
12150               break;
12151             default:
12152               gcc_unreachable ();
12153             }
12154           break;
12155         case MODE_VECTOR_FLOAT:
12156           op0 = gen_lowpart (mode, op0);
12157           op1 = gen_lowpart (mode, op1);
12158
12159           switch (mode)
12160             { 
12161             case V4SFmode:
12162               emit_insn (gen_avx_movups (op0, op1));
12163               break;
12164             case V8SFmode:
12165               emit_insn (gen_avx_movups256 (op0, op1));
12166               break;
12167             case V2DFmode:
12168               emit_insn (gen_avx_movupd (op0, op1));
12169               break;
12170             case V4DFmode:
12171               emit_insn (gen_avx_movupd256 (op0, op1));
12172               break;
12173             default:
12174               gcc_unreachable ();
12175             }
12176           break;
12177
12178         default:
12179           gcc_unreachable ();
12180         }
12181
12182       return;
12183     }
12184
12185   if (MEM_P (op1))
12186     {
12187       /* If we're optimizing for size, movups is the smallest.  */
12188       if (optimize_insn_for_size_p ())
12189         {
12190           op0 = gen_lowpart (V4SFmode, op0);
12191           op1 = gen_lowpart (V4SFmode, op1);
12192           emit_insn (gen_sse_movups (op0, op1));
12193           return;
12194         }
12195
12196       /* ??? If we have typed data, then it would appear that using
12197          movdqu is the only way to get unaligned data loaded with
12198          integer type.  */
12199       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12200         {
12201           op0 = gen_lowpart (V16QImode, op0);
12202           op1 = gen_lowpart (V16QImode, op1);
12203           emit_insn (gen_sse2_movdqu (op0, op1));
12204           return;
12205         }
12206
12207       if (TARGET_SSE2 && mode == V2DFmode)
12208         {
12209           rtx zero;
12210
12211           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12212             {
12213               op0 = gen_lowpart (V2DFmode, op0);
12214               op1 = gen_lowpart (V2DFmode, op1);
12215               emit_insn (gen_sse2_movupd (op0, op1));
12216               return;
12217             }
12218
12219           /* When SSE registers are split into halves, we can avoid
12220              writing to the top half twice.  */
12221           if (TARGET_SSE_SPLIT_REGS)
12222             {
12223               emit_clobber (op0);
12224               zero = op0;
12225             }
12226           else
12227             {
12228               /* ??? Not sure about the best option for the Intel chips.
12229                  The following would seem to satisfy; the register is
12230                  entirely cleared, breaking the dependency chain.  We
12231                  then store to the upper half, with a dependency depth
12232                  of one.  A rumor has it that Intel recommends two movsd
12233                  followed by an unpacklpd, but this is unconfirmed.  And
12234                  given that the dependency depth of the unpacklpd would
12235                  still be one, I'm not sure why this would be better.  */
12236               zero = CONST0_RTX (V2DFmode);
12237             }
12238
12239           m = adjust_address (op1, DFmode, 0);
12240           emit_insn (gen_sse2_loadlpd (op0, zero, m));
12241           m = adjust_address (op1, DFmode, 8);
12242           emit_insn (gen_sse2_loadhpd (op0, op0, m));
12243         }
12244       else
12245         {
12246           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12247             {
12248               op0 = gen_lowpart (V4SFmode, op0);
12249               op1 = gen_lowpart (V4SFmode, op1);
12250               emit_insn (gen_sse_movups (op0, op1));
12251               return;
12252             }
12253
12254           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
12255             emit_move_insn (op0, CONST0_RTX (mode));
12256           else
12257             emit_clobber (op0);
12258
12259           if (mode != V4SFmode)
12260             op0 = gen_lowpart (V4SFmode, op0);
12261           m = adjust_address (op1, V2SFmode, 0);
12262           emit_insn (gen_sse_loadlps (op0, op0, m));
12263           m = adjust_address (op1, V2SFmode, 8);
12264           emit_insn (gen_sse_loadhps (op0, op0, m));
12265         }
12266     }
12267   else if (MEM_P (op0))
12268     {
12269       /* If we're optimizing for size, movups is the smallest.  */
12270       if (optimize_insn_for_size_p ())
12271         {
12272           op0 = gen_lowpart (V4SFmode, op0);
12273           op1 = gen_lowpart (V4SFmode, op1);
12274           emit_insn (gen_sse_movups (op0, op1));
12275           return;
12276         }
12277
12278       /* ??? Similar to above, only less clear because of quote
12279          typeless stores unquote.  */
12280       if (TARGET_SSE2 && !TARGET_SSE_TYPELESS_STORES
12281           && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12282         {
12283           op0 = gen_lowpart (V16QImode, op0);
12284           op1 = gen_lowpart (V16QImode, op1);
12285           emit_insn (gen_sse2_movdqu (op0, op1));
12286           return;
12287         }
12288
12289       if (TARGET_SSE2 && mode == V2DFmode)
12290         {
12291           m = adjust_address (op0, DFmode, 0);
12292           emit_insn (gen_sse2_storelpd (m, op1));
12293           m = adjust_address (op0, DFmode, 8);
12294           emit_insn (gen_sse2_storehpd (m, op1));
12295         }
12296       else
12297         {
12298           if (mode != V4SFmode)
12299             op1 = gen_lowpart (V4SFmode, op1);
12300           m = adjust_address (op0, V2SFmode, 0);
12301           emit_insn (gen_sse_storelps (m, op1));
12302           m = adjust_address (op0, V2SFmode, 8);
12303           emit_insn (gen_sse_storehps (m, op1));
12304         }
12305     }
12306   else
12307     gcc_unreachable ();
12308 }
12309
12310 /* Expand a push in MODE.  This is some mode for which we do not support
12311    proper push instructions, at least from the registers that we expect
12312    the value to live in.  */
12313
12314 void
12315 ix86_expand_push (enum machine_mode mode, rtx x)
12316 {
12317   rtx tmp;
12318
12319   tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
12320                              GEN_INT (-GET_MODE_SIZE (mode)),
12321                              stack_pointer_rtx, 1, OPTAB_DIRECT);
12322   if (tmp != stack_pointer_rtx)
12323     emit_move_insn (stack_pointer_rtx, tmp);
12324
12325   tmp = gen_rtx_MEM (mode, stack_pointer_rtx);
12326   emit_move_insn (tmp, x);
12327 }
12328
12329 /* Helper function of ix86_fixup_binary_operands to canonicalize
12330    operand order.  Returns true if the operands should be swapped.  */
12331
12332 static bool
12333 ix86_swap_binary_operands_p (enum rtx_code code, enum machine_mode mode,
12334                              rtx operands[])
12335 {
12336   rtx dst = operands[0];
12337   rtx src1 = operands[1];
12338   rtx src2 = operands[2];
12339
12340   /* If the operation is not commutative, we can't do anything.  */
12341   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
12342     return false;
12343
12344   /* Highest priority is that src1 should match dst.  */
12345   if (rtx_equal_p (dst, src1))
12346     return false;
12347   if (rtx_equal_p (dst, src2))
12348     return true;
12349
12350   /* Next highest priority is that immediate constants come second.  */
12351   if (immediate_operand (src2, mode))
12352     return false;
12353   if (immediate_operand (src1, mode))
12354     return true;
12355
12356   /* Lowest priority is that memory references should come second.  */
12357   if (MEM_P (src2))
12358     return false;
12359   if (MEM_P (src1))
12360     return true;
12361
12362   return false;
12363 }
12364
12365
12366 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
12367    destination to use for the operation.  If different from the true
12368    destination in operands[0], a copy operation will be required.  */
12369
12370 rtx
12371 ix86_fixup_binary_operands (enum rtx_code code, enum machine_mode mode,
12372                             rtx operands[])
12373 {
12374   rtx dst = operands[0];
12375   rtx src1 = operands[1];
12376   rtx src2 = operands[2];
12377
12378   /* Canonicalize operand order.  */
12379   if (ix86_swap_binary_operands_p (code, mode, operands))
12380     {
12381       rtx temp;
12382
12383       /* It is invalid to swap operands of different modes.  */
12384       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
12385
12386       temp = src1;
12387       src1 = src2;
12388       src2 = temp;
12389     }
12390
12391   /* Both source operands cannot be in memory.  */
12392   if (MEM_P (src1) && MEM_P (src2))
12393     {
12394       /* Optimization: Only read from memory once.  */
12395       if (rtx_equal_p (src1, src2))
12396         {
12397           src2 = force_reg (mode, src2);
12398           src1 = src2;
12399         }
12400       else
12401         src2 = force_reg (mode, src2);
12402     }
12403
12404   /* If the destination is memory, and we do not have matching source
12405      operands, do things in registers.  */
12406   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12407     dst = gen_reg_rtx (mode);
12408
12409   /* Source 1 cannot be a constant.  */
12410   if (CONSTANT_P (src1))
12411     src1 = force_reg (mode, src1);
12412
12413   /* Source 1 cannot be a non-matching memory.  */
12414   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12415     src1 = force_reg (mode, src1);
12416
12417   operands[1] = src1;
12418   operands[2] = src2;
12419   return dst;
12420 }
12421
12422 /* Similarly, but assume that the destination has already been
12423    set up properly.  */
12424
12425 void
12426 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
12427                                     enum machine_mode mode, rtx operands[])
12428 {
12429   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
12430   gcc_assert (dst == operands[0]);
12431 }
12432
12433 /* Attempt to expand a binary operator.  Make the expansion closer to the
12434    actual machine, then just general_operand, which will allow 3 separate
12435    memory references (one output, two input) in a single insn.  */
12436
12437 void
12438 ix86_expand_binary_operator (enum rtx_code code, enum machine_mode mode,
12439                              rtx operands[])
12440 {
12441   rtx src1, src2, dst, op, clob;
12442
12443   dst = ix86_fixup_binary_operands (code, mode, operands);
12444   src1 = operands[1];
12445   src2 = operands[2];
12446
12447  /* Emit the instruction.  */
12448
12449   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
12450   if (reload_in_progress)
12451     {
12452       /* Reload doesn't know about the flags register, and doesn't know that
12453          it doesn't want to clobber it.  We can only do this with PLUS.  */
12454       gcc_assert (code == PLUS);
12455       emit_insn (op);
12456     }
12457   else
12458     {
12459       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12460       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12461     }
12462
12463   /* Fix up the destination if needed.  */
12464   if (dst != operands[0])
12465     emit_move_insn (operands[0], dst);
12466 }
12467
12468 /* Return TRUE or FALSE depending on whether the binary operator meets the
12469    appropriate constraints.  */
12470
12471 int
12472 ix86_binary_operator_ok (enum rtx_code code, enum machine_mode mode,
12473                          rtx operands[3])
12474 {
12475   rtx dst = operands[0];
12476   rtx src1 = operands[1];
12477   rtx src2 = operands[2];
12478
12479   /* Both source operands cannot be in memory.  */
12480   if (MEM_P (src1) && MEM_P (src2))
12481     return 0;
12482
12483   /* Canonicalize operand order for commutative operators.  */
12484   if (ix86_swap_binary_operands_p (code, mode, operands))
12485     {
12486       rtx temp = src1;
12487       src1 = src2;
12488       src2 = temp;
12489     }
12490
12491   /* If the destination is memory, we must have a matching source operand.  */
12492   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12493       return 0;
12494
12495   /* Source 1 cannot be a constant.  */
12496   if (CONSTANT_P (src1))
12497     return 0;
12498
12499   /* Source 1 cannot be a non-matching memory.  */
12500   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12501     return 0;
12502
12503   return 1;
12504 }
12505
12506 /* Attempt to expand a unary operator.  Make the expansion closer to the
12507    actual machine, then just general_operand, which will allow 2 separate
12508    memory references (one output, one input) in a single insn.  */
12509
12510 void
12511 ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode,
12512                             rtx operands[])
12513 {
12514   int matching_memory;
12515   rtx src, dst, op, clob;
12516
12517   dst = operands[0];
12518   src = operands[1];
12519
12520   /* If the destination is memory, and we do not have matching source
12521      operands, do things in registers.  */
12522   matching_memory = 0;
12523   if (MEM_P (dst))
12524     {
12525       if (rtx_equal_p (dst, src))
12526         matching_memory = 1;
12527       else
12528         dst = gen_reg_rtx (mode);
12529     }
12530
12531   /* When source operand is memory, destination must match.  */
12532   if (MEM_P (src) && !matching_memory)
12533     src = force_reg (mode, src);
12534
12535   /* Emit the instruction.  */
12536
12537   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
12538   if (reload_in_progress || code == NOT)
12539     {
12540       /* Reload doesn't know about the flags register, and doesn't know that
12541          it doesn't want to clobber it.  */
12542       gcc_assert (code == NOT);
12543       emit_insn (op);
12544     }
12545   else
12546     {
12547       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12548       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12549     }
12550
12551   /* Fix up the destination if needed.  */
12552   if (dst != operands[0])
12553     emit_move_insn (operands[0], dst);
12554 }
12555
12556 /* Return TRUE or FALSE depending on whether the unary operator meets the
12557    appropriate constraints.  */
12558
12559 int
12560 ix86_unary_operator_ok (enum rtx_code code ATTRIBUTE_UNUSED,
12561                         enum machine_mode mode ATTRIBUTE_UNUSED,
12562                         rtx operands[2] ATTRIBUTE_UNUSED)
12563 {
12564   /* If one of operands is memory, source and destination must match.  */
12565   if ((MEM_P (operands[0])
12566        || MEM_P (operands[1]))
12567       && ! rtx_equal_p (operands[0], operands[1]))
12568     return FALSE;
12569   return TRUE;
12570 }
12571
12572 /* Post-reload splitter for converting an SF or DFmode value in an
12573    SSE register into an unsigned SImode.  */
12574
12575 void
12576 ix86_split_convert_uns_si_sse (rtx operands[])
12577 {
12578   enum machine_mode vecmode;
12579   rtx value, large, zero_or_two31, input, two31, x;
12580
12581   large = operands[1];
12582   zero_or_two31 = operands[2];
12583   input = operands[3];
12584   two31 = operands[4];
12585   vecmode = GET_MODE (large);
12586   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
12587
12588   /* Load up the value into the low element.  We must ensure that the other
12589      elements are valid floats -- zero is the easiest such value.  */
12590   if (MEM_P (input))
12591     {
12592       if (vecmode == V4SFmode)
12593         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
12594       else
12595         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
12596     }
12597   else
12598     {
12599       input = gen_rtx_REG (vecmode, REGNO (input));
12600       emit_move_insn (value, CONST0_RTX (vecmode));
12601       if (vecmode == V4SFmode)
12602         emit_insn (gen_sse_movss (value, value, input));
12603       else
12604         emit_insn (gen_sse2_movsd (value, value, input));
12605     }
12606
12607   emit_move_insn (large, two31);
12608   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
12609
12610   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
12611   emit_insn (gen_rtx_SET (VOIDmode, large, x));
12612
12613   x = gen_rtx_AND (vecmode, zero_or_two31, large);
12614   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
12615
12616   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
12617   emit_insn (gen_rtx_SET (VOIDmode, value, x));
12618
12619   large = gen_rtx_REG (V4SImode, REGNO (large));
12620   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
12621
12622   x = gen_rtx_REG (V4SImode, REGNO (value));
12623   if (vecmode == V4SFmode)
12624     emit_insn (gen_sse2_cvttps2dq (x, value));
12625   else
12626     emit_insn (gen_sse2_cvttpd2dq (x, value));
12627   value = x;
12628
12629   emit_insn (gen_xorv4si3 (value, value, large));
12630 }
12631
12632 /* Convert an unsigned DImode value into a DFmode, using only SSE.
12633    Expects the 64-bit DImode to be supplied in a pair of integral
12634    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
12635    -mfpmath=sse, !optimize_size only.  */
12636
12637 void
12638 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
12639 {
12640   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
12641   rtx int_xmm, fp_xmm;
12642   rtx biases, exponents;
12643   rtx x;
12644
12645   int_xmm = gen_reg_rtx (V4SImode);
12646   if (TARGET_INTER_UNIT_MOVES)
12647     emit_insn (gen_movdi_to_sse (int_xmm, input));
12648   else if (TARGET_SSE_SPLIT_REGS)
12649     {
12650       emit_clobber (int_xmm);
12651       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
12652     }
12653   else
12654     {
12655       x = gen_reg_rtx (V2DImode);
12656       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
12657       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
12658     }
12659
12660   x = gen_rtx_CONST_VECTOR (V4SImode,
12661                             gen_rtvec (4, GEN_INT (0x43300000UL),
12662                                        GEN_INT (0x45300000UL),
12663                                        const0_rtx, const0_rtx));
12664   exponents = validize_mem (force_const_mem (V4SImode, x));
12665
12666   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
12667   emit_insn (gen_sse2_punpckldq (int_xmm, int_xmm, exponents));
12668
12669   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
12670      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
12671      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
12672      (0x1.0p84 + double(fp_value_hi_xmm)).
12673      Note these exponents differ by 32.  */
12674
12675   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
12676
12677   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
12678      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
12679   real_ldexp (&bias_lo_rvt, &dconst1, 52);
12680   real_ldexp (&bias_hi_rvt, &dconst1, 84);
12681   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
12682   x = const_double_from_real_value (bias_hi_rvt, DFmode);
12683   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
12684   biases = validize_mem (force_const_mem (V2DFmode, biases));
12685   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
12686
12687   /* Add the upper and lower DFmode values together.  */
12688   if (TARGET_SSE3)
12689     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
12690   else
12691     {
12692       x = copy_to_mode_reg (V2DFmode, fp_xmm);
12693       emit_insn (gen_sse2_unpckhpd (fp_xmm, fp_xmm, fp_xmm));
12694       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
12695     }
12696
12697   ix86_expand_vector_extract (false, target, fp_xmm, 0);
12698 }
12699
12700 /* Not used, but eases macroization of patterns.  */
12701 void
12702 ix86_expand_convert_uns_sixf_sse (rtx target ATTRIBUTE_UNUSED,
12703                                   rtx input ATTRIBUTE_UNUSED)
12704 {
12705   gcc_unreachable ();
12706 }
12707
12708 /* Convert an unsigned SImode value into a DFmode.  Only currently used
12709    for SSE, but applicable anywhere.  */
12710
12711 void
12712 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
12713 {
12714   REAL_VALUE_TYPE TWO31r;
12715   rtx x, fp;
12716
12717   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
12718                            NULL, 1, OPTAB_DIRECT);
12719
12720   fp = gen_reg_rtx (DFmode);
12721   emit_insn (gen_floatsidf2 (fp, x));
12722
12723   real_ldexp (&TWO31r, &dconst1, 31);
12724   x = const_double_from_real_value (TWO31r, DFmode);
12725
12726   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
12727   if (x != target)
12728     emit_move_insn (target, x);
12729 }
12730
12731 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
12732    32-bit mode; otherwise we have a direct convert instruction.  */
12733
12734 void
12735 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
12736 {
12737   REAL_VALUE_TYPE TWO32r;
12738   rtx fp_lo, fp_hi, x;
12739
12740   fp_lo = gen_reg_rtx (DFmode);
12741   fp_hi = gen_reg_rtx (DFmode);
12742
12743   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
12744
12745   real_ldexp (&TWO32r, &dconst1, 32);
12746   x = const_double_from_real_value (TWO32r, DFmode);
12747   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
12748
12749   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
12750
12751   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
12752                            0, OPTAB_DIRECT);
12753   if (x != target)
12754     emit_move_insn (target, x);
12755 }
12756
12757 /* Convert an unsigned SImode value into a SFmode, using only SSE.
12758    For x86_32, -mfpmath=sse, !optimize_size only.  */
12759 void
12760 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
12761 {
12762   REAL_VALUE_TYPE ONE16r;
12763   rtx fp_hi, fp_lo, int_hi, int_lo, x;
12764
12765   real_ldexp (&ONE16r, &dconst1, 16);
12766   x = const_double_from_real_value (ONE16r, SFmode);
12767   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
12768                                       NULL, 0, OPTAB_DIRECT);
12769   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
12770                                       NULL, 0, OPTAB_DIRECT);
12771   fp_hi = gen_reg_rtx (SFmode);
12772   fp_lo = gen_reg_rtx (SFmode);
12773   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
12774   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
12775   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
12776                                0, OPTAB_DIRECT);
12777   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
12778                                0, OPTAB_DIRECT);
12779   if (!rtx_equal_p (target, fp_hi))
12780     emit_move_insn (target, fp_hi);
12781 }
12782
12783 /* A subroutine of ix86_build_signbit_mask_vector.  If VECT is true,
12784    then replicate the value for all elements of the vector
12785    register.  */
12786
12787 rtx
12788 ix86_build_const_vector (enum machine_mode mode, bool vect, rtx value)
12789 {
12790   rtvec v;
12791   switch (mode)
12792     {
12793     case SImode:
12794       gcc_assert (vect);
12795       v = gen_rtvec (4, value, value, value, value);
12796       return gen_rtx_CONST_VECTOR (V4SImode, v);
12797
12798     case DImode:
12799       gcc_assert (vect);
12800       v = gen_rtvec (2, value, value);
12801       return gen_rtx_CONST_VECTOR (V2DImode, v);
12802
12803     case SFmode:
12804       if (vect)
12805         v = gen_rtvec (4, value, value, value, value);
12806       else
12807         v = gen_rtvec (4, value, CONST0_RTX (SFmode),
12808                        CONST0_RTX (SFmode), CONST0_RTX (SFmode));
12809       return gen_rtx_CONST_VECTOR (V4SFmode, v);
12810
12811     case DFmode:
12812       if (vect)
12813         v = gen_rtvec (2, value, value);
12814       else
12815         v = gen_rtvec (2, value, CONST0_RTX (DFmode));
12816       return gen_rtx_CONST_VECTOR (V2DFmode, v);
12817
12818     default:
12819       gcc_unreachable ();
12820     }
12821 }
12822
12823 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
12824    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
12825    for an SSE register.  If VECT is true, then replicate the mask for
12826    all elements of the vector register.  If INVERT is true, then create
12827    a mask excluding the sign bit.  */
12828
12829 rtx
12830 ix86_build_signbit_mask (enum machine_mode mode, bool vect, bool invert)
12831 {
12832   enum machine_mode vec_mode, imode;
12833   HOST_WIDE_INT hi, lo;
12834   int shift = 63;
12835   rtx v;
12836   rtx mask;
12837
12838   /* Find the sign bit, sign extended to 2*HWI.  */
12839   switch (mode)
12840     {
12841     case SImode:
12842     case SFmode:
12843       imode = SImode;
12844       vec_mode = (mode == SImode) ? V4SImode : V4SFmode;
12845       lo = 0x80000000, hi = lo < 0;
12846       break;
12847
12848     case DImode:
12849     case DFmode:
12850       imode = DImode;
12851       vec_mode = (mode == DImode) ? V2DImode : V2DFmode;
12852       if (HOST_BITS_PER_WIDE_INT >= 64)
12853         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
12854       else
12855         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
12856       break;
12857
12858     case TImode:
12859     case TFmode:
12860       vec_mode = VOIDmode;
12861       if (HOST_BITS_PER_WIDE_INT >= 64)
12862         {
12863           imode = TImode;
12864           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
12865         }
12866       else
12867         {
12868           rtvec vec;
12869
12870           imode = DImode;
12871           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
12872
12873           if (invert)
12874             {
12875               lo = ~lo, hi = ~hi;
12876               v = constm1_rtx;
12877             }
12878           else
12879             v = const0_rtx;
12880
12881           mask = immed_double_const (lo, hi, imode);
12882
12883           vec = gen_rtvec (2, v, mask);
12884           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
12885           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
12886
12887           return v;
12888         }
12889      break;
12890
12891     default:
12892       gcc_unreachable ();
12893     }
12894
12895   if (invert)
12896     lo = ~lo, hi = ~hi;
12897
12898   /* Force this value into the low part of a fp vector constant.  */
12899   mask = immed_double_const (lo, hi, imode);
12900   mask = gen_lowpart (mode, mask);
12901
12902   if (vec_mode == VOIDmode)
12903     return force_reg (mode, mask);
12904
12905   v = ix86_build_const_vector (mode, vect, mask);
12906   return force_reg (vec_mode, v);
12907 }
12908
12909 /* Generate code for floating point ABS or NEG.  */
12910
12911 void
12912 ix86_expand_fp_absneg_operator (enum rtx_code code, enum machine_mode mode,
12913                                 rtx operands[])
12914 {
12915   rtx mask, set, use, clob, dst, src;
12916   bool use_sse = false;
12917   bool vector_mode = VECTOR_MODE_P (mode);
12918   enum machine_mode elt_mode = mode;
12919
12920   if (vector_mode)
12921     {
12922       elt_mode = GET_MODE_INNER (mode);
12923       use_sse = true;
12924     }
12925   else if (mode == TFmode)
12926     use_sse = true;
12927   else if (TARGET_SSE_MATH)
12928     use_sse = SSE_FLOAT_MODE_P (mode);
12929
12930   /* NEG and ABS performed with SSE use bitwise mask operations.
12931      Create the appropriate mask now.  */
12932   if (use_sse)
12933     mask = ix86_build_signbit_mask (elt_mode, vector_mode, code == ABS);
12934   else
12935     mask = NULL_RTX;
12936
12937   dst = operands[0];
12938   src = operands[1];
12939
12940   if (vector_mode)
12941     {
12942       set = gen_rtx_fmt_ee (code == NEG ? XOR : AND, mode, src, mask);
12943       set = gen_rtx_SET (VOIDmode, dst, set);
12944       emit_insn (set);
12945     }
12946   else
12947     {
12948       set = gen_rtx_fmt_e (code, mode, src);
12949       set = gen_rtx_SET (VOIDmode, dst, set);
12950       if (mask)
12951         {
12952           use = gen_rtx_USE (VOIDmode, mask);
12953           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12954           emit_insn (gen_rtx_PARALLEL (VOIDmode,
12955                                        gen_rtvec (3, set, use, clob)));
12956         }
12957       else
12958         emit_insn (set);
12959     }
12960 }
12961
12962 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
12963
12964 void
12965 ix86_expand_copysign (rtx operands[])
12966 {
12967   enum machine_mode mode;
12968   rtx dest, op0, op1, mask, nmask;
12969
12970   dest = operands[0];
12971   op0 = operands[1];
12972   op1 = operands[2];
12973
12974   mode = GET_MODE (dest);
12975
12976   if (GET_CODE (op0) == CONST_DOUBLE)
12977     {
12978       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
12979
12980       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
12981         op0 = simplify_unary_operation (ABS, mode, op0, mode);
12982
12983       if (mode == SFmode || mode == DFmode)
12984         {
12985           enum machine_mode vmode;
12986
12987           vmode = mode == SFmode ? V4SFmode : V2DFmode;
12988
12989           if (op0 == CONST0_RTX (mode))
12990             op0 = CONST0_RTX (vmode);
12991           else
12992             {
12993               rtvec v;
12994
12995               if (mode == SFmode)
12996                 v = gen_rtvec (4, op0, CONST0_RTX (SFmode),
12997                                CONST0_RTX (SFmode), CONST0_RTX (SFmode));
12998               else
12999                 v = gen_rtvec (2, op0, CONST0_RTX (DFmode));
13000
13001               op0 = force_reg (vmode, gen_rtx_CONST_VECTOR (vmode, v));
13002             }
13003         }
13004       else if (op0 != CONST0_RTX (mode))
13005         op0 = force_reg (mode, op0);
13006
13007       mask = ix86_build_signbit_mask (mode, 0, 0);
13008
13009       if (mode == SFmode)
13010         copysign_insn = gen_copysignsf3_const;
13011       else if (mode == DFmode)
13012         copysign_insn = gen_copysigndf3_const;
13013       else
13014         copysign_insn = gen_copysigntf3_const;
13015
13016         emit_insn (copysign_insn (dest, op0, op1, mask));
13017     }
13018   else
13019     {
13020       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
13021
13022       nmask = ix86_build_signbit_mask (mode, 0, 1);
13023       mask = ix86_build_signbit_mask (mode, 0, 0);
13024
13025       if (mode == SFmode)
13026         copysign_insn = gen_copysignsf3_var;
13027       else if (mode == DFmode)
13028         copysign_insn = gen_copysigndf3_var;
13029       else
13030         copysign_insn = gen_copysigntf3_var;
13031
13032       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
13033     }
13034 }
13035
13036 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
13037    be a constant, and so has already been expanded into a vector constant.  */
13038
13039 void
13040 ix86_split_copysign_const (rtx operands[])
13041 {
13042   enum machine_mode mode, vmode;
13043   rtx dest, op0, op1, mask, x;
13044
13045   dest = operands[0];
13046   op0 = operands[1];
13047   op1 = operands[2];
13048   mask = operands[3];
13049
13050   mode = GET_MODE (dest);
13051   vmode = GET_MODE (mask);
13052
13053   dest = simplify_gen_subreg (vmode, dest, mode, 0);
13054   x = gen_rtx_AND (vmode, dest, mask);
13055   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13056
13057   if (op0 != CONST0_RTX (vmode))
13058     {
13059       x = gen_rtx_IOR (vmode, dest, op0);
13060       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13061     }
13062 }
13063
13064 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
13065    so we have to do two masks.  */
13066
13067 void
13068 ix86_split_copysign_var (rtx operands[])
13069 {
13070   enum machine_mode mode, vmode;
13071   rtx dest, scratch, op0, op1, mask, nmask, x;
13072
13073   dest = operands[0];
13074   scratch = operands[1];
13075   op0 = operands[2];
13076   op1 = operands[3];
13077   nmask = operands[4];
13078   mask = operands[5];
13079
13080   mode = GET_MODE (dest);
13081   vmode = GET_MODE (mask);
13082
13083   if (rtx_equal_p (op0, op1))
13084     {
13085       /* Shouldn't happen often (it's useless, obviously), but when it does
13086          we'd generate incorrect code if we continue below.  */
13087       emit_move_insn (dest, op0);
13088       return;
13089     }
13090
13091   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
13092     {
13093       gcc_assert (REGNO (op1) == REGNO (scratch));
13094
13095       x = gen_rtx_AND (vmode, scratch, mask);
13096       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13097
13098       dest = mask;
13099       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13100       x = gen_rtx_NOT (vmode, dest);
13101       x = gen_rtx_AND (vmode, x, op0);
13102       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13103     }
13104   else
13105     {
13106       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
13107         {
13108           x = gen_rtx_AND (vmode, scratch, mask);
13109         }
13110       else                                              /* alternative 2,4 */
13111         {
13112           gcc_assert (REGNO (mask) == REGNO (scratch));
13113           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
13114           x = gen_rtx_AND (vmode, scratch, op1);
13115         }
13116       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13117
13118       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
13119         {
13120           dest = simplify_gen_subreg (vmode, op0, mode, 0);
13121           x = gen_rtx_AND (vmode, dest, nmask);
13122         }
13123       else                                              /* alternative 3,4 */
13124         {
13125           gcc_assert (REGNO (nmask) == REGNO (dest));
13126           dest = nmask;
13127           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13128           x = gen_rtx_AND (vmode, dest, op0);
13129         }
13130       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13131     }
13132
13133   x = gen_rtx_IOR (vmode, dest, scratch);
13134   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13135 }
13136
13137 /* Return TRUE or FALSE depending on whether the first SET in INSN
13138    has source and destination with matching CC modes, and that the
13139    CC mode is at least as constrained as REQ_MODE.  */
13140
13141 int
13142 ix86_match_ccmode (rtx insn, enum machine_mode req_mode)
13143 {
13144   rtx set;
13145   enum machine_mode set_mode;
13146
13147   set = PATTERN (insn);
13148   if (GET_CODE (set) == PARALLEL)
13149     set = XVECEXP (set, 0, 0);
13150   gcc_assert (GET_CODE (set) == SET);
13151   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
13152
13153   set_mode = GET_MODE (SET_DEST (set));
13154   switch (set_mode)
13155     {
13156     case CCNOmode:
13157       if (req_mode != CCNOmode
13158           && (req_mode != CCmode
13159               || XEXP (SET_SRC (set), 1) != const0_rtx))
13160         return 0;
13161       break;
13162     case CCmode:
13163       if (req_mode == CCGCmode)
13164         return 0;
13165       /* FALLTHRU */
13166     case CCGCmode:
13167       if (req_mode == CCGOCmode || req_mode == CCNOmode)
13168         return 0;
13169       /* FALLTHRU */
13170     case CCGOCmode:
13171       if (req_mode == CCZmode)
13172         return 0;
13173       /* FALLTHRU */
13174     case CCAmode:
13175     case CCCmode:
13176     case CCOmode:
13177     case CCSmode:
13178     case CCZmode:
13179       break;
13180
13181     default:
13182       gcc_unreachable ();
13183     }
13184
13185   return (GET_MODE (SET_SRC (set)) == set_mode);
13186 }
13187
13188 /* Generate insn patterns to do an integer compare of OPERANDS.  */
13189
13190 static rtx
13191 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
13192 {
13193   enum machine_mode cmpmode;
13194   rtx tmp, flags;
13195
13196   cmpmode = SELECT_CC_MODE (code, op0, op1);
13197   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
13198
13199   /* This is very simple, but making the interface the same as in the
13200      FP case makes the rest of the code easier.  */
13201   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
13202   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
13203
13204   /* Return the test that should be put into the flags user, i.e.
13205      the bcc, scc, or cmov instruction.  */
13206   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
13207 }
13208
13209 /* Figure out whether to use ordered or unordered fp comparisons.
13210    Return the appropriate mode to use.  */
13211
13212 enum machine_mode
13213 ix86_fp_compare_mode (enum rtx_code code ATTRIBUTE_UNUSED)
13214 {
13215   /* ??? In order to make all comparisons reversible, we do all comparisons
13216      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
13217      all forms trapping and nontrapping comparisons, we can make inequality
13218      comparisons trapping again, since it results in better code when using
13219      FCOM based compares.  */
13220   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
13221 }
13222
13223 enum machine_mode
13224 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
13225 {
13226   enum machine_mode mode = GET_MODE (op0);
13227
13228   if (SCALAR_FLOAT_MODE_P (mode))
13229     {
13230       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
13231       return ix86_fp_compare_mode (code);
13232     }
13233
13234   switch (code)
13235     {
13236       /* Only zero flag is needed.  */
13237     case EQ:                    /* ZF=0 */
13238     case NE:                    /* ZF!=0 */
13239       return CCZmode;
13240       /* Codes needing carry flag.  */
13241     case GEU:                   /* CF=0 */
13242     case LTU:                   /* CF=1 */
13243       /* Detect overflow checks.  They need just the carry flag.  */
13244       if (GET_CODE (op0) == PLUS
13245           && rtx_equal_p (op1, XEXP (op0, 0)))
13246         return CCCmode;
13247       else
13248         return CCmode;
13249     case GTU:                   /* CF=0 & ZF=0 */
13250     case LEU:                   /* CF=1 | ZF=1 */
13251       /* Detect overflow checks.  They need just the carry flag.  */
13252       if (GET_CODE (op0) == MINUS
13253           && rtx_equal_p (op1, XEXP (op0, 0)))
13254         return CCCmode;
13255       else
13256         return CCmode;
13257       /* Codes possibly doable only with sign flag when
13258          comparing against zero.  */
13259     case GE:                    /* SF=OF   or   SF=0 */
13260     case LT:                    /* SF<>OF  or   SF=1 */
13261       if (op1 == const0_rtx)
13262         return CCGOCmode;
13263       else
13264         /* For other cases Carry flag is not required.  */
13265         return CCGCmode;
13266       /* Codes doable only with sign flag when comparing
13267          against zero, but we miss jump instruction for it
13268          so we need to use relational tests against overflow
13269          that thus needs to be zero.  */
13270     case GT:                    /* ZF=0 & SF=OF */
13271     case LE:                    /* ZF=1 | SF<>OF */
13272       if (op1 == const0_rtx)
13273         return CCNOmode;
13274       else
13275         return CCGCmode;
13276       /* strcmp pattern do (use flags) and combine may ask us for proper
13277          mode.  */
13278     case USE:
13279       return CCmode;
13280     default:
13281       gcc_unreachable ();
13282     }
13283 }
13284
13285 /* Return the fixed registers used for condition codes.  */
13286
13287 static bool
13288 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
13289 {
13290   *p1 = FLAGS_REG;
13291   *p2 = FPSR_REG;
13292   return true;
13293 }
13294
13295 /* If two condition code modes are compatible, return a condition code
13296    mode which is compatible with both.  Otherwise, return
13297    VOIDmode.  */
13298
13299 static enum machine_mode
13300 ix86_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
13301 {
13302   if (m1 == m2)
13303     return m1;
13304
13305   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
13306     return VOIDmode;
13307
13308   if ((m1 == CCGCmode && m2 == CCGOCmode)
13309       || (m1 == CCGOCmode && m2 == CCGCmode))
13310     return CCGCmode;
13311
13312   switch (m1)
13313     {
13314     default:
13315       gcc_unreachable ();
13316
13317     case CCmode:
13318     case CCGCmode:
13319     case CCGOCmode:
13320     case CCNOmode:
13321     case CCAmode:
13322     case CCCmode:
13323     case CCOmode:
13324     case CCSmode:
13325     case CCZmode:
13326       switch (m2)
13327         {
13328         default:
13329           return VOIDmode;
13330
13331         case CCmode:
13332         case CCGCmode:
13333         case CCGOCmode:
13334         case CCNOmode:
13335         case CCAmode:
13336         case CCCmode:
13337         case CCOmode:
13338         case CCSmode:
13339         case CCZmode:
13340           return CCmode;
13341         }
13342
13343     case CCFPmode:
13344     case CCFPUmode:
13345       /* These are only compatible with themselves, which we already
13346          checked above.  */
13347       return VOIDmode;
13348     }
13349 }
13350
13351 /* Split comparison code CODE into comparisons we can do using branch
13352    instructions.  BYPASS_CODE is comparison code for branch that will
13353    branch around FIRST_CODE and SECOND_CODE.  If some of branches
13354    is not required, set value to UNKNOWN.
13355    We never require more than two branches.  */
13356
13357 void
13358 ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *bypass_code,
13359                           enum rtx_code *first_code,
13360                           enum rtx_code *second_code)
13361 {
13362   *first_code = code;
13363   *bypass_code = UNKNOWN;
13364   *second_code = UNKNOWN;
13365
13366   /* The fcomi comparison sets flags as follows:
13367
13368      cmp    ZF PF CF
13369      >      0  0  0
13370      <      0  0  1
13371      =      1  0  0
13372      un     1  1  1 */
13373
13374   switch (code)
13375     {
13376     case GT:                    /* GTU - CF=0 & ZF=0 */
13377     case GE:                    /* GEU - CF=0 */
13378     case ORDERED:               /* PF=0 */
13379     case UNORDERED:             /* PF=1 */
13380     case UNEQ:                  /* EQ - ZF=1 */
13381     case UNLT:                  /* LTU - CF=1 */
13382     case UNLE:                  /* LEU - CF=1 | ZF=1 */
13383     case LTGT:                  /* EQ - ZF=0 */
13384       break;
13385     case LT:                    /* LTU - CF=1 - fails on unordered */
13386       *first_code = UNLT;
13387       *bypass_code = UNORDERED;
13388       break;
13389     case LE:                    /* LEU - CF=1 | ZF=1 - fails on unordered */
13390       *first_code = UNLE;
13391       *bypass_code = UNORDERED;
13392       break;
13393     case EQ:                    /* EQ - ZF=1 - fails on unordered */
13394       *first_code = UNEQ;
13395       *bypass_code = UNORDERED;
13396       break;
13397     case NE:                    /* NE - ZF=0 - fails on unordered */
13398       *first_code = LTGT;
13399       *second_code = UNORDERED;
13400       break;
13401     case UNGE:                  /* GEU - CF=0 - fails on unordered */
13402       *first_code = GE;
13403       *second_code = UNORDERED;
13404       break;
13405     case UNGT:                  /* GTU - CF=0 & ZF=0 - fails on unordered */
13406       *first_code = GT;
13407       *second_code = UNORDERED;
13408       break;
13409     default:
13410       gcc_unreachable ();
13411     }
13412   if (!TARGET_IEEE_FP)
13413     {
13414       *second_code = UNKNOWN;
13415       *bypass_code = UNKNOWN;
13416     }
13417 }
13418
13419 /* Return cost of comparison done fcom + arithmetics operations on AX.
13420    All following functions do use number of instructions as a cost metrics.
13421    In future this should be tweaked to compute bytes for optimize_size and
13422    take into account performance of various instructions on various CPUs.  */
13423 static int
13424 ix86_fp_comparison_arithmetics_cost (enum rtx_code code)
13425 {
13426   if (!TARGET_IEEE_FP)
13427     return 4;
13428   /* The cost of code output by ix86_expand_fp_compare.  */
13429   switch (code)
13430     {
13431     case UNLE:
13432     case UNLT:
13433     case LTGT:
13434     case GT:
13435     case GE:
13436     case UNORDERED:
13437     case ORDERED:
13438     case UNEQ:
13439       return 4;
13440       break;
13441     case LT:
13442     case NE:
13443     case EQ:
13444     case UNGE:
13445       return 5;
13446       break;
13447     case LE:
13448     case UNGT:
13449       return 6;
13450       break;
13451     default:
13452       gcc_unreachable ();
13453     }
13454 }
13455
13456 /* Return cost of comparison done using fcomi operation.
13457    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13458 static int
13459 ix86_fp_comparison_fcomi_cost (enum rtx_code code)
13460 {
13461   enum rtx_code bypass_code, first_code, second_code;
13462   /* Return arbitrarily high cost when instruction is not supported - this
13463      prevents gcc from using it.  */
13464   if (!TARGET_CMOVE)
13465     return 1024;
13466   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13467   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 2;
13468 }
13469
13470 /* Return cost of comparison done using sahf operation.
13471    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13472 static int
13473 ix86_fp_comparison_sahf_cost (enum rtx_code code)
13474 {
13475   enum rtx_code bypass_code, first_code, second_code;
13476   /* Return arbitrarily high cost when instruction is not preferred - this
13477      avoids gcc from using it.  */
13478   if (!(TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ())))
13479     return 1024;
13480   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13481   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 3;
13482 }
13483
13484 /* Compute cost of the comparison done using any method.
13485    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13486 static int
13487 ix86_fp_comparison_cost (enum rtx_code code)
13488 {
13489   int fcomi_cost, sahf_cost, arithmetics_cost = 1024;
13490   int min;
13491
13492   fcomi_cost = ix86_fp_comparison_fcomi_cost (code);
13493   sahf_cost = ix86_fp_comparison_sahf_cost (code);
13494
13495   min = arithmetics_cost = ix86_fp_comparison_arithmetics_cost (code);
13496   if (min > sahf_cost)
13497     min = sahf_cost;
13498   if (min > fcomi_cost)
13499     min = fcomi_cost;
13500   return min;
13501 }
13502
13503 /* Return true if we should use an FCOMI instruction for this
13504    fp comparison.  */
13505
13506 int
13507 ix86_use_fcomi_compare (enum rtx_code code ATTRIBUTE_UNUSED)
13508 {
13509   enum rtx_code swapped_code = swap_condition (code);
13510
13511   return ((ix86_fp_comparison_cost (code)
13512            == ix86_fp_comparison_fcomi_cost (code))
13513           || (ix86_fp_comparison_cost (swapped_code)
13514               == ix86_fp_comparison_fcomi_cost (swapped_code)));
13515 }
13516
13517 /* Swap, force into registers, or otherwise massage the two operands
13518    to a fp comparison.  The operands are updated in place; the new
13519    comparison code is returned.  */
13520
13521 static enum rtx_code
13522 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
13523 {
13524   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
13525   rtx op0 = *pop0, op1 = *pop1;
13526   enum machine_mode op_mode = GET_MODE (op0);
13527   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
13528
13529   /* All of the unordered compare instructions only work on registers.
13530      The same is true of the fcomi compare instructions.  The XFmode
13531      compare instructions require registers except when comparing
13532      against zero or when converting operand 1 from fixed point to
13533      floating point.  */
13534
13535   if (!is_sse
13536       && (fpcmp_mode == CCFPUmode
13537           || (op_mode == XFmode
13538               && ! (standard_80387_constant_p (op0) == 1
13539                     || standard_80387_constant_p (op1) == 1)
13540               && GET_CODE (op1) != FLOAT)
13541           || ix86_use_fcomi_compare (code)))
13542     {
13543       op0 = force_reg (op_mode, op0);
13544       op1 = force_reg (op_mode, op1);
13545     }
13546   else
13547     {
13548       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
13549          things around if they appear profitable, otherwise force op0
13550          into a register.  */
13551
13552       if (standard_80387_constant_p (op0) == 0
13553           || (MEM_P (op0)
13554               && ! (standard_80387_constant_p (op1) == 0
13555                     || MEM_P (op1))))
13556         {
13557           rtx tmp;
13558           tmp = op0, op0 = op1, op1 = tmp;
13559           code = swap_condition (code);
13560         }
13561
13562       if (!REG_P (op0))
13563         op0 = force_reg (op_mode, op0);
13564
13565       if (CONSTANT_P (op1))
13566         {
13567           int tmp = standard_80387_constant_p (op1);
13568           if (tmp == 0)
13569             op1 = validize_mem (force_const_mem (op_mode, op1));
13570           else if (tmp == 1)
13571             {
13572               if (TARGET_CMOVE)
13573                 op1 = force_reg (op_mode, op1);
13574             }
13575           else
13576             op1 = force_reg (op_mode, op1);
13577         }
13578     }
13579
13580   /* Try to rearrange the comparison to make it cheaper.  */
13581   if (ix86_fp_comparison_cost (code)
13582       > ix86_fp_comparison_cost (swap_condition (code))
13583       && (REG_P (op1) || can_create_pseudo_p ()))
13584     {
13585       rtx tmp;
13586       tmp = op0, op0 = op1, op1 = tmp;
13587       code = swap_condition (code);
13588       if (!REG_P (op0))
13589         op0 = force_reg (op_mode, op0);
13590     }
13591
13592   *pop0 = op0;
13593   *pop1 = op1;
13594   return code;
13595 }
13596
13597 /* Convert comparison codes we use to represent FP comparison to integer
13598    code that will result in proper branch.  Return UNKNOWN if no such code
13599    is available.  */
13600
13601 enum rtx_code
13602 ix86_fp_compare_code_to_integer (enum rtx_code code)
13603 {
13604   switch (code)
13605     {
13606     case GT:
13607       return GTU;
13608     case GE:
13609       return GEU;
13610     case ORDERED:
13611     case UNORDERED:
13612       return code;
13613       break;
13614     case UNEQ:
13615       return EQ;
13616       break;
13617     case UNLT:
13618       return LTU;
13619       break;
13620     case UNLE:
13621       return LEU;
13622       break;
13623     case LTGT:
13624       return NE;
13625       break;
13626     default:
13627       return UNKNOWN;
13628     }
13629 }
13630
13631 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
13632
13633 static rtx
13634 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch,
13635                         rtx *second_test, rtx *bypass_test)
13636 {
13637   enum machine_mode fpcmp_mode, intcmp_mode;
13638   rtx tmp, tmp2;
13639   int cost = ix86_fp_comparison_cost (code);
13640   enum rtx_code bypass_code, first_code, second_code;
13641
13642   fpcmp_mode = ix86_fp_compare_mode (code);
13643   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
13644
13645   if (second_test)
13646     *second_test = NULL_RTX;
13647   if (bypass_test)
13648     *bypass_test = NULL_RTX;
13649
13650   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13651
13652   /* Do fcomi/sahf based test when profitable.  */
13653   if (ix86_fp_comparison_arithmetics_cost (code) > cost
13654       && (bypass_code == UNKNOWN || bypass_test)
13655       && (second_code == UNKNOWN || second_test))
13656     {
13657       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13658       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
13659                          tmp);
13660       if (TARGET_CMOVE)
13661         emit_insn (tmp);
13662       else
13663         {
13664           gcc_assert (TARGET_SAHF);
13665
13666           if (!scratch)
13667             scratch = gen_reg_rtx (HImode);
13668           tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
13669
13670           emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
13671         }
13672
13673       /* The FP codes work out to act like unsigned.  */
13674       intcmp_mode = fpcmp_mode;
13675       code = first_code;
13676       if (bypass_code != UNKNOWN)
13677         *bypass_test = gen_rtx_fmt_ee (bypass_code, VOIDmode,
13678                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13679                                        const0_rtx);
13680       if (second_code != UNKNOWN)
13681         *second_test = gen_rtx_fmt_ee (second_code, VOIDmode,
13682                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13683                                        const0_rtx);
13684     }
13685   else
13686     {
13687       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
13688       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13689       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
13690       if (!scratch)
13691         scratch = gen_reg_rtx (HImode);
13692       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
13693
13694       /* In the unordered case, we have to check C2 for NaN's, which
13695          doesn't happen to work out to anything nice combination-wise.
13696          So do some bit twiddling on the value we've got in AH to come
13697          up with an appropriate set of condition codes.  */
13698
13699       intcmp_mode = CCNOmode;
13700       switch (code)
13701         {
13702         case GT:
13703         case UNGT:
13704           if (code == GT || !TARGET_IEEE_FP)
13705             {
13706               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
13707               code = EQ;
13708             }
13709           else
13710             {
13711               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13712               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
13713               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
13714               intcmp_mode = CCmode;
13715               code = GEU;
13716             }
13717           break;
13718         case LT:
13719         case UNLT:
13720           if (code == LT && TARGET_IEEE_FP)
13721             {
13722               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13723               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x01)));
13724               intcmp_mode = CCmode;
13725               code = EQ;
13726             }
13727           else
13728             {
13729               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x01)));
13730               code = NE;
13731             }
13732           break;
13733         case GE:
13734         case UNGE:
13735           if (code == GE || !TARGET_IEEE_FP)
13736             {
13737               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
13738               code = EQ;
13739             }
13740           else
13741             {
13742               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13743               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
13744                                              GEN_INT (0x01)));
13745               code = NE;
13746             }
13747           break;
13748         case LE:
13749         case UNLE:
13750           if (code == LE && TARGET_IEEE_FP)
13751             {
13752               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13753               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
13754               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
13755               intcmp_mode = CCmode;
13756               code = LTU;
13757             }
13758           else
13759             {
13760               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
13761               code = NE;
13762             }
13763           break;
13764         case EQ:
13765         case UNEQ:
13766           if (code == EQ && TARGET_IEEE_FP)
13767             {
13768               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13769               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
13770               intcmp_mode = CCmode;
13771               code = EQ;
13772             }
13773           else
13774             {
13775               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
13776               code = NE;
13777               break;
13778             }
13779           break;
13780         case NE:
13781         case LTGT:
13782           if (code == NE && TARGET_IEEE_FP)
13783             {
13784               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13785               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
13786                                              GEN_INT (0x40)));
13787               code = NE;
13788             }
13789           else
13790             {
13791               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
13792               code = EQ;
13793             }
13794           break;
13795
13796         case UNORDERED:
13797           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
13798           code = NE;
13799           break;
13800         case ORDERED:
13801           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
13802           code = EQ;
13803           break;
13804
13805         default:
13806           gcc_unreachable ();
13807         }
13808     }
13809
13810   /* Return the test that should be put into the flags user, i.e.
13811      the bcc, scc, or cmov instruction.  */
13812   return gen_rtx_fmt_ee (code, VOIDmode,
13813                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
13814                          const0_rtx);
13815 }
13816
13817 rtx
13818 ix86_expand_compare (enum rtx_code code, rtx *second_test, rtx *bypass_test)
13819 {
13820   rtx op0, op1, ret;
13821   op0 = ix86_compare_op0;
13822   op1 = ix86_compare_op1;
13823
13824   if (second_test)
13825     *second_test = NULL_RTX;
13826   if (bypass_test)
13827     *bypass_test = NULL_RTX;
13828
13829   if (ix86_compare_emitted)
13830     {
13831       ret = gen_rtx_fmt_ee (code, VOIDmode, ix86_compare_emitted, const0_rtx);
13832       ix86_compare_emitted = NULL_RTX;
13833     }
13834   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
13835     {
13836       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
13837       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
13838                                     second_test, bypass_test);
13839     }
13840   else
13841     ret = ix86_expand_int_compare (code, op0, op1);
13842
13843   return ret;
13844 }
13845
13846 /* Return true if the CODE will result in nontrivial jump sequence.  */
13847 bool
13848 ix86_fp_jump_nontrivial_p (enum rtx_code code)
13849 {
13850   enum rtx_code bypass_code, first_code, second_code;
13851   if (!TARGET_CMOVE)
13852     return true;
13853   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13854   return bypass_code != UNKNOWN || second_code != UNKNOWN;
13855 }
13856
13857 void
13858 ix86_expand_branch (enum rtx_code code, rtx label)
13859 {
13860   rtx tmp;
13861
13862   /* If we have emitted a compare insn, go straight to simple.
13863      ix86_expand_compare won't emit anything if ix86_compare_emitted
13864      is non NULL.  */
13865   if (ix86_compare_emitted)
13866     goto simple;
13867
13868   switch (GET_MODE (ix86_compare_op0))
13869     {
13870     case QImode:
13871     case HImode:
13872     case SImode:
13873       simple:
13874       tmp = ix86_expand_compare (code, NULL, NULL);
13875       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
13876                                   gen_rtx_LABEL_REF (VOIDmode, label),
13877                                   pc_rtx);
13878       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
13879       return;
13880
13881     case SFmode:
13882     case DFmode:
13883     case XFmode:
13884       {
13885         rtvec vec;
13886         int use_fcomi;
13887         enum rtx_code bypass_code, first_code, second_code;
13888
13889         code = ix86_prepare_fp_compare_args (code, &ix86_compare_op0,
13890                                              &ix86_compare_op1);
13891
13892         ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13893
13894         /* Check whether we will use the natural sequence with one jump.  If
13895            so, we can expand jump early.  Otherwise delay expansion by
13896            creating compound insn to not confuse optimizers.  */
13897         if (bypass_code == UNKNOWN && second_code == UNKNOWN)
13898           {
13899             ix86_split_fp_branch (code, ix86_compare_op0, ix86_compare_op1,
13900                                   gen_rtx_LABEL_REF (VOIDmode, label),
13901                                   pc_rtx, NULL_RTX, NULL_RTX);
13902           }
13903         else
13904           {
13905             tmp = gen_rtx_fmt_ee (code, VOIDmode,
13906                                   ix86_compare_op0, ix86_compare_op1);
13907             tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
13908                                         gen_rtx_LABEL_REF (VOIDmode, label),
13909                                         pc_rtx);
13910             tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
13911
13912             use_fcomi = ix86_use_fcomi_compare (code);
13913             vec = rtvec_alloc (3 + !use_fcomi);
13914             RTVEC_ELT (vec, 0) = tmp;
13915             RTVEC_ELT (vec, 1)
13916               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FPSR_REG));
13917             RTVEC_ELT (vec, 2)
13918               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FLAGS_REG));
13919             if (! use_fcomi)
13920               RTVEC_ELT (vec, 3)
13921                 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (HImode));
13922
13923             emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, vec));
13924           }
13925         return;
13926       }
13927
13928     case DImode:
13929       if (TARGET_64BIT)
13930         goto simple;
13931     case TImode:
13932       /* Expand DImode branch into multiple compare+branch.  */
13933       {
13934         rtx lo[2], hi[2], label2;
13935         enum rtx_code code1, code2, code3;
13936         enum machine_mode submode;
13937
13938         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
13939           {
13940             tmp = ix86_compare_op0;
13941             ix86_compare_op0 = ix86_compare_op1;
13942             ix86_compare_op1 = tmp;
13943             code = swap_condition (code);
13944           }
13945         if (GET_MODE (ix86_compare_op0) == DImode)
13946           {
13947             split_di (&ix86_compare_op0, 1, lo+0, hi+0);
13948             split_di (&ix86_compare_op1, 1, lo+1, hi+1);
13949             submode = SImode;
13950           }
13951         else
13952           {
13953             split_ti (&ix86_compare_op0, 1, lo+0, hi+0);
13954             split_ti (&ix86_compare_op1, 1, lo+1, hi+1);
13955             submode = DImode;
13956           }
13957
13958         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
13959            avoid two branches.  This costs one extra insn, so disable when
13960            optimizing for size.  */
13961
13962         if ((code == EQ || code == NE)
13963             && (!optimize_insn_for_size_p ()
13964                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
13965           {
13966             rtx xor0, xor1;
13967
13968             xor1 = hi[0];
13969             if (hi[1] != const0_rtx)
13970               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
13971                                    NULL_RTX, 0, OPTAB_WIDEN);
13972
13973             xor0 = lo[0];
13974             if (lo[1] != const0_rtx)
13975               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
13976                                    NULL_RTX, 0, OPTAB_WIDEN);
13977
13978             tmp = expand_binop (submode, ior_optab, xor1, xor0,
13979                                 NULL_RTX, 0, OPTAB_WIDEN);
13980
13981             ix86_compare_op0 = tmp;
13982             ix86_compare_op1 = const0_rtx;
13983             ix86_expand_branch (code, label);
13984             return;
13985           }
13986
13987         /* Otherwise, if we are doing less-than or greater-or-equal-than,
13988            op1 is a constant and the low word is zero, then we can just
13989            examine the high word.  Similarly for low word -1 and
13990            less-or-equal-than or greater-than.  */
13991
13992         if (CONST_INT_P (hi[1]))
13993           switch (code)
13994             {
13995             case LT: case LTU: case GE: case GEU:
13996               if (lo[1] == const0_rtx)
13997                 {
13998                   ix86_compare_op0 = hi[0];
13999                   ix86_compare_op1 = hi[1];
14000                   ix86_expand_branch (code, label);
14001                   return;
14002                 }
14003               break;
14004             case LE: case LEU: case GT: case GTU:
14005               if (lo[1] == constm1_rtx)
14006                 {
14007                   ix86_compare_op0 = hi[0];
14008                   ix86_compare_op1 = hi[1];
14009                   ix86_expand_branch (code, label);
14010                   return;
14011                 }
14012               break;
14013             default:
14014               break;
14015             }
14016
14017         /* Otherwise, we need two or three jumps.  */
14018
14019         label2 = gen_label_rtx ();
14020
14021         code1 = code;
14022         code2 = swap_condition (code);
14023         code3 = unsigned_condition (code);
14024
14025         switch (code)
14026           {
14027           case LT: case GT: case LTU: case GTU:
14028             break;
14029
14030           case LE:   code1 = LT;  code2 = GT;  break;
14031           case GE:   code1 = GT;  code2 = LT;  break;
14032           case LEU:  code1 = LTU; code2 = GTU; break;
14033           case GEU:  code1 = GTU; code2 = LTU; break;
14034
14035           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
14036           case NE:   code2 = UNKNOWN; break;
14037
14038           default:
14039             gcc_unreachable ();
14040           }
14041
14042         /*
14043          * a < b =>
14044          *    if (hi(a) < hi(b)) goto true;
14045          *    if (hi(a) > hi(b)) goto false;
14046          *    if (lo(a) < lo(b)) goto true;
14047          *  false:
14048          */
14049
14050         ix86_compare_op0 = hi[0];
14051         ix86_compare_op1 = hi[1];
14052
14053         if (code1 != UNKNOWN)
14054           ix86_expand_branch (code1, label);
14055         if (code2 != UNKNOWN)
14056           ix86_expand_branch (code2, label2);
14057
14058         ix86_compare_op0 = lo[0];
14059         ix86_compare_op1 = lo[1];
14060         ix86_expand_branch (code3, label);
14061
14062         if (code2 != UNKNOWN)
14063           emit_label (label2);
14064         return;
14065       }
14066
14067     default:
14068       gcc_unreachable ();
14069     }
14070 }
14071
14072 /* Split branch based on floating point condition.  */
14073 void
14074 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
14075                       rtx target1, rtx target2, rtx tmp, rtx pushed)
14076 {
14077   rtx second, bypass;
14078   rtx label = NULL_RTX;
14079   rtx condition;
14080   int bypass_probability = -1, second_probability = -1, probability = -1;
14081   rtx i;
14082
14083   if (target2 != pc_rtx)
14084     {
14085       rtx tmp = target2;
14086       code = reverse_condition_maybe_unordered (code);
14087       target2 = target1;
14088       target1 = tmp;
14089     }
14090
14091   condition = ix86_expand_fp_compare (code, op1, op2,
14092                                       tmp, &second, &bypass);
14093
14094   /* Remove pushed operand from stack.  */
14095   if (pushed)
14096     ix86_free_from_memory (GET_MODE (pushed));
14097
14098   if (split_branch_probability >= 0)
14099     {
14100       /* Distribute the probabilities across the jumps.
14101          Assume the BYPASS and SECOND to be always test
14102          for UNORDERED.  */
14103       probability = split_branch_probability;
14104
14105       /* Value of 1 is low enough to make no need for probability
14106          to be updated.  Later we may run some experiments and see
14107          if unordered values are more frequent in practice.  */
14108       if (bypass)
14109         bypass_probability = 1;
14110       if (second)
14111         second_probability = 1;
14112     }
14113   if (bypass != NULL_RTX)
14114     {
14115       label = gen_label_rtx ();
14116       i = emit_jump_insn (gen_rtx_SET
14117                           (VOIDmode, pc_rtx,
14118                            gen_rtx_IF_THEN_ELSE (VOIDmode,
14119                                                  bypass,
14120                                                  gen_rtx_LABEL_REF (VOIDmode,
14121                                                                     label),
14122                                                  pc_rtx)));
14123       if (bypass_probability >= 0)
14124         REG_NOTES (i)
14125           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14126                                GEN_INT (bypass_probability),
14127                                REG_NOTES (i));
14128     }
14129   i = emit_jump_insn (gen_rtx_SET
14130                       (VOIDmode, pc_rtx,
14131                        gen_rtx_IF_THEN_ELSE (VOIDmode,
14132                                              condition, target1, target2)));
14133   if (probability >= 0)
14134     REG_NOTES (i)
14135       = gen_rtx_EXPR_LIST (REG_BR_PROB,
14136                            GEN_INT (probability),
14137                            REG_NOTES (i));
14138   if (second != NULL_RTX)
14139     {
14140       i = emit_jump_insn (gen_rtx_SET
14141                           (VOIDmode, pc_rtx,
14142                            gen_rtx_IF_THEN_ELSE (VOIDmode, second, target1,
14143                                                  target2)));
14144       if (second_probability >= 0)
14145         REG_NOTES (i)
14146           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14147                                GEN_INT (second_probability),
14148                                REG_NOTES (i));
14149     }
14150   if (label != NULL_RTX)
14151     emit_label (label);
14152 }
14153
14154 int
14155 ix86_expand_setcc (enum rtx_code code, rtx dest)
14156 {
14157   rtx ret, tmp, tmpreg, equiv;
14158   rtx second_test, bypass_test;
14159
14160   if (GET_MODE (ix86_compare_op0) == (TARGET_64BIT ? TImode : DImode))
14161     return 0; /* FAIL */
14162
14163   gcc_assert (GET_MODE (dest) == QImode);
14164
14165   ret = ix86_expand_compare (code, &second_test, &bypass_test);
14166   PUT_MODE (ret, QImode);
14167
14168   tmp = dest;
14169   tmpreg = dest;
14170
14171   emit_insn (gen_rtx_SET (VOIDmode, tmp, ret));
14172   if (bypass_test || second_test)
14173     {
14174       rtx test = second_test;
14175       int bypass = 0;
14176       rtx tmp2 = gen_reg_rtx (QImode);
14177       if (bypass_test)
14178         {
14179           gcc_assert (!second_test);
14180           test = bypass_test;
14181           bypass = 1;
14182           PUT_CODE (test, reverse_condition_maybe_unordered (GET_CODE (test)));
14183         }
14184       PUT_MODE (test, QImode);
14185       emit_insn (gen_rtx_SET (VOIDmode, tmp2, test));
14186
14187       if (bypass)
14188         emit_insn (gen_andqi3 (tmp, tmpreg, tmp2));
14189       else
14190         emit_insn (gen_iorqi3 (tmp, tmpreg, tmp2));
14191     }
14192
14193   /* Attach a REG_EQUAL note describing the comparison result.  */
14194   if (ix86_compare_op0 && ix86_compare_op1)
14195     {
14196       equiv = simplify_gen_relational (code, QImode,
14197                                        GET_MODE (ix86_compare_op0),
14198                                        ix86_compare_op0, ix86_compare_op1);
14199       set_unique_reg_note (get_last_insn (), REG_EQUAL, equiv);
14200     }
14201
14202   return 1; /* DONE */
14203 }
14204
14205 /* Expand comparison setting or clearing carry flag.  Return true when
14206    successful and set pop for the operation.  */
14207 static bool
14208 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
14209 {
14210   enum machine_mode mode =
14211     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
14212
14213   /* Do not handle DImode compares that go through special path.  */
14214   if (mode == (TARGET_64BIT ? TImode : DImode))
14215     return false;
14216
14217   if (SCALAR_FLOAT_MODE_P (mode))
14218     {
14219       rtx second_test = NULL, bypass_test = NULL;
14220       rtx compare_op, compare_seq;
14221
14222       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
14223
14224       /* Shortcut:  following common codes never translate
14225          into carry flag compares.  */
14226       if (code == EQ || code == NE || code == UNEQ || code == LTGT
14227           || code == ORDERED || code == UNORDERED)
14228         return false;
14229
14230       /* These comparisons require zero flag; swap operands so they won't.  */
14231       if ((code == GT || code == UNLE || code == LE || code == UNGT)
14232           && !TARGET_IEEE_FP)
14233         {
14234           rtx tmp = op0;
14235           op0 = op1;
14236           op1 = tmp;
14237           code = swap_condition (code);
14238         }
14239
14240       /* Try to expand the comparison and verify that we end up with
14241          carry flag based comparison.  This fails to be true only when
14242          we decide to expand comparison using arithmetic that is not
14243          too common scenario.  */
14244       start_sequence ();
14245       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
14246                                            &second_test, &bypass_test);
14247       compare_seq = get_insns ();
14248       end_sequence ();
14249
14250       if (second_test || bypass_test)
14251         return false;
14252
14253       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14254           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14255         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
14256       else
14257         code = GET_CODE (compare_op);
14258
14259       if (code != LTU && code != GEU)
14260         return false;
14261
14262       emit_insn (compare_seq);
14263       *pop = compare_op;
14264       return true;
14265     }
14266
14267   if (!INTEGRAL_MODE_P (mode))
14268     return false;
14269
14270   switch (code)
14271     {
14272     case LTU:
14273     case GEU:
14274       break;
14275
14276     /* Convert a==0 into (unsigned)a<1.  */
14277     case EQ:
14278     case NE:
14279       if (op1 != const0_rtx)
14280         return false;
14281       op1 = const1_rtx;
14282       code = (code == EQ ? LTU : GEU);
14283       break;
14284
14285     /* Convert a>b into b<a or a>=b-1.  */
14286     case GTU:
14287     case LEU:
14288       if (CONST_INT_P (op1))
14289         {
14290           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
14291           /* Bail out on overflow.  We still can swap operands but that
14292              would force loading of the constant into register.  */
14293           if (op1 == const0_rtx
14294               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
14295             return false;
14296           code = (code == GTU ? GEU : LTU);
14297         }
14298       else
14299         {
14300           rtx tmp = op1;
14301           op1 = op0;
14302           op0 = tmp;
14303           code = (code == GTU ? LTU : GEU);
14304         }
14305       break;
14306
14307     /* Convert a>=0 into (unsigned)a<0x80000000.  */
14308     case LT:
14309     case GE:
14310       if (mode == DImode || op1 != const0_rtx)
14311         return false;
14312       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14313       code = (code == LT ? GEU : LTU);
14314       break;
14315     case LE:
14316     case GT:
14317       if (mode == DImode || op1 != constm1_rtx)
14318         return false;
14319       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14320       code = (code == LE ? GEU : LTU);
14321       break;
14322
14323     default:
14324       return false;
14325     }
14326   /* Swapping operands may cause constant to appear as first operand.  */
14327   if (!nonimmediate_operand (op0, VOIDmode))
14328     {
14329       if (!can_create_pseudo_p ())
14330         return false;
14331       op0 = force_reg (mode, op0);
14332     }
14333   ix86_compare_op0 = op0;
14334   ix86_compare_op1 = op1;
14335   *pop = ix86_expand_compare (code, NULL, NULL);
14336   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
14337   return true;
14338 }
14339
14340 int
14341 ix86_expand_int_movcc (rtx operands[])
14342 {
14343   enum rtx_code code = GET_CODE (operands[1]), compare_code;
14344   rtx compare_seq, compare_op;
14345   rtx second_test, bypass_test;
14346   enum machine_mode mode = GET_MODE (operands[0]);
14347   bool sign_bit_compare_p = false;;
14348
14349   start_sequence ();
14350   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
14351   compare_seq = get_insns ();
14352   end_sequence ();
14353
14354   compare_code = GET_CODE (compare_op);
14355
14356   if ((ix86_compare_op1 == const0_rtx && (code == GE || code == LT))
14357       || (ix86_compare_op1 == constm1_rtx && (code == GT || code == LE)))
14358     sign_bit_compare_p = true;
14359
14360   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
14361      HImode insns, we'd be swallowed in word prefix ops.  */
14362
14363   if ((mode != HImode || TARGET_FAST_PREFIX)
14364       && (mode != (TARGET_64BIT ? TImode : DImode))
14365       && CONST_INT_P (operands[2])
14366       && CONST_INT_P (operands[3]))
14367     {
14368       rtx out = operands[0];
14369       HOST_WIDE_INT ct = INTVAL (operands[2]);
14370       HOST_WIDE_INT cf = INTVAL (operands[3]);
14371       HOST_WIDE_INT diff;
14372
14373       diff = ct - cf;
14374       /*  Sign bit compares are better done using shifts than we do by using
14375           sbb.  */
14376       if (sign_bit_compare_p
14377           || ix86_expand_carry_flag_compare (code, ix86_compare_op0,
14378                                              ix86_compare_op1, &compare_op))
14379         {
14380           /* Detect overlap between destination and compare sources.  */
14381           rtx tmp = out;
14382
14383           if (!sign_bit_compare_p)
14384             {
14385               bool fpcmp = false;
14386
14387               compare_code = GET_CODE (compare_op);
14388
14389               if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14390                   || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14391                 {
14392                   fpcmp = true;
14393                   compare_code = ix86_fp_compare_code_to_integer (compare_code);
14394                 }
14395
14396               /* To simplify rest of code, restrict to the GEU case.  */
14397               if (compare_code == LTU)
14398                 {
14399                   HOST_WIDE_INT tmp = ct;
14400                   ct = cf;
14401                   cf = tmp;
14402                   compare_code = reverse_condition (compare_code);
14403                   code = reverse_condition (code);
14404                 }
14405               else
14406                 {
14407                   if (fpcmp)
14408                     PUT_CODE (compare_op,
14409                               reverse_condition_maybe_unordered
14410                                 (GET_CODE (compare_op)));
14411                   else
14412                     PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
14413                 }
14414               diff = ct - cf;
14415
14416               if (reg_overlap_mentioned_p (out, ix86_compare_op0)
14417                   || reg_overlap_mentioned_p (out, ix86_compare_op1))
14418                 tmp = gen_reg_rtx (mode);
14419
14420               if (mode == DImode)
14421                 emit_insn (gen_x86_movdicc_0_m1_rex64 (tmp, compare_op));
14422               else
14423                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp), compare_op));
14424             }
14425           else
14426             {
14427               if (code == GT || code == GE)
14428                 code = reverse_condition (code);
14429               else
14430                 {
14431                   HOST_WIDE_INT tmp = ct;
14432                   ct = cf;
14433                   cf = tmp;
14434                   diff = ct - cf;
14435                 }
14436               tmp = emit_store_flag (tmp, code, ix86_compare_op0,
14437                                      ix86_compare_op1, VOIDmode, 0, -1);
14438             }
14439
14440           if (diff == 1)
14441             {
14442               /*
14443                * cmpl op0,op1
14444                * sbbl dest,dest
14445                * [addl dest, ct]
14446                *
14447                * Size 5 - 8.
14448                */
14449               if (ct)
14450                 tmp = expand_simple_binop (mode, PLUS,
14451                                            tmp, GEN_INT (ct),
14452                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14453             }
14454           else if (cf == -1)
14455             {
14456               /*
14457                * cmpl op0,op1
14458                * sbbl dest,dest
14459                * orl $ct, dest
14460                *
14461                * Size 8.
14462                */
14463               tmp = expand_simple_binop (mode, IOR,
14464                                          tmp, GEN_INT (ct),
14465                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14466             }
14467           else if (diff == -1 && ct)
14468             {
14469               /*
14470                * cmpl op0,op1
14471                * sbbl dest,dest
14472                * notl dest
14473                * [addl dest, cf]
14474                *
14475                * Size 8 - 11.
14476                */
14477               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14478               if (cf)
14479                 tmp = expand_simple_binop (mode, PLUS,
14480                                            copy_rtx (tmp), GEN_INT (cf),
14481                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14482             }
14483           else
14484             {
14485               /*
14486                * cmpl op0,op1
14487                * sbbl dest,dest
14488                * [notl dest]
14489                * andl cf - ct, dest
14490                * [addl dest, ct]
14491                *
14492                * Size 8 - 11.
14493                */
14494
14495               if (cf == 0)
14496                 {
14497                   cf = ct;
14498                   ct = 0;
14499                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14500                 }
14501
14502               tmp = expand_simple_binop (mode, AND,
14503                                          copy_rtx (tmp),
14504                                          gen_int_mode (cf - ct, mode),
14505                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14506               if (ct)
14507                 tmp = expand_simple_binop (mode, PLUS,
14508                                            copy_rtx (tmp), GEN_INT (ct),
14509                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14510             }
14511
14512           if (!rtx_equal_p (tmp, out))
14513             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
14514
14515           return 1; /* DONE */
14516         }
14517
14518       if (diff < 0)
14519         {
14520           enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14521
14522           HOST_WIDE_INT tmp;
14523           tmp = ct, ct = cf, cf = tmp;
14524           diff = -diff;
14525
14526           if (SCALAR_FLOAT_MODE_P (cmp_mode))
14527             {
14528               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14529
14530               /* We may be reversing unordered compare to normal compare, that
14531                  is not valid in general (we may convert non-trapping condition
14532                  to trapping one), however on i386 we currently emit all
14533                  comparisons unordered.  */
14534               compare_code = reverse_condition_maybe_unordered (compare_code);
14535               code = reverse_condition_maybe_unordered (code);
14536             }
14537           else
14538             {
14539               compare_code = reverse_condition (compare_code);
14540               code = reverse_condition (code);
14541             }
14542         }
14543
14544       compare_code = UNKNOWN;
14545       if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_INT
14546           && CONST_INT_P (ix86_compare_op1))
14547         {
14548           if (ix86_compare_op1 == const0_rtx
14549               && (code == LT || code == GE))
14550             compare_code = code;
14551           else if (ix86_compare_op1 == constm1_rtx)
14552             {
14553               if (code == LE)
14554                 compare_code = LT;
14555               else if (code == GT)
14556                 compare_code = GE;
14557             }
14558         }
14559
14560       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
14561       if (compare_code != UNKNOWN
14562           && GET_MODE (ix86_compare_op0) == GET_MODE (out)
14563           && (cf == -1 || ct == -1))
14564         {
14565           /* If lea code below could be used, only optimize
14566              if it results in a 2 insn sequence.  */
14567
14568           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
14569                  || diff == 3 || diff == 5 || diff == 9)
14570               || (compare_code == LT && ct == -1)
14571               || (compare_code == GE && cf == -1))
14572             {
14573               /*
14574                * notl op1       (if necessary)
14575                * sarl $31, op1
14576                * orl cf, op1
14577                */
14578               if (ct != -1)
14579                 {
14580                   cf = ct;
14581                   ct = -1;
14582                   code = reverse_condition (code);
14583                 }
14584
14585               out = emit_store_flag (out, code, ix86_compare_op0,
14586                                      ix86_compare_op1, VOIDmode, 0, -1);
14587
14588               out = expand_simple_binop (mode, IOR,
14589                                          out, GEN_INT (cf),
14590                                          out, 1, OPTAB_DIRECT);
14591               if (out != operands[0])
14592                 emit_move_insn (operands[0], out);
14593
14594               return 1; /* DONE */
14595             }
14596         }
14597
14598
14599       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
14600            || diff == 3 || diff == 5 || diff == 9)
14601           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
14602           && (mode != DImode
14603               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
14604         {
14605           /*
14606            * xorl dest,dest
14607            * cmpl op1,op2
14608            * setcc dest
14609            * lea cf(dest*(ct-cf)),dest
14610            *
14611            * Size 14.
14612            *
14613            * This also catches the degenerate setcc-only case.
14614            */
14615
14616           rtx tmp;
14617           int nops;
14618
14619           out = emit_store_flag (out, code, ix86_compare_op0,
14620                                  ix86_compare_op1, VOIDmode, 0, 1);
14621
14622           nops = 0;
14623           /* On x86_64 the lea instruction operates on Pmode, so we need
14624              to get arithmetics done in proper mode to match.  */
14625           if (diff == 1)
14626             tmp = copy_rtx (out);
14627           else
14628             {
14629               rtx out1;
14630               out1 = copy_rtx (out);
14631               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
14632               nops++;
14633               if (diff & 1)
14634                 {
14635                   tmp = gen_rtx_PLUS (mode, tmp, out1);
14636                   nops++;
14637                 }
14638             }
14639           if (cf != 0)
14640             {
14641               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
14642               nops++;
14643             }
14644           if (!rtx_equal_p (tmp, out))
14645             {
14646               if (nops == 1)
14647                 out = force_operand (tmp, copy_rtx (out));
14648               else
14649                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
14650             }
14651           if (!rtx_equal_p (out, operands[0]))
14652             emit_move_insn (operands[0], copy_rtx (out));
14653
14654           return 1; /* DONE */
14655         }
14656
14657       /*
14658        * General case:                  Jumpful:
14659        *   xorl dest,dest               cmpl op1, op2
14660        *   cmpl op1, op2                movl ct, dest
14661        *   setcc dest                   jcc 1f
14662        *   decl dest                    movl cf, dest
14663        *   andl (cf-ct),dest            1:
14664        *   addl ct,dest
14665        *
14666        * Size 20.                       Size 14.
14667        *
14668        * This is reasonably steep, but branch mispredict costs are
14669        * high on modern cpus, so consider failing only if optimizing
14670        * for space.
14671        */
14672
14673       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14674           && BRANCH_COST (optimize_insn_for_speed_p (),
14675                           false) >= 2)
14676         {
14677           if (cf == 0)
14678             {
14679               enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14680
14681               cf = ct;
14682               ct = 0;
14683
14684               if (SCALAR_FLOAT_MODE_P (cmp_mode))
14685                 {
14686                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14687
14688                   /* We may be reversing unordered compare to normal compare,
14689                      that is not valid in general (we may convert non-trapping
14690                      condition to trapping one), however on i386 we currently
14691                      emit all comparisons unordered.  */
14692                   code = reverse_condition_maybe_unordered (code);
14693                 }
14694               else
14695                 {
14696                   code = reverse_condition (code);
14697                   if (compare_code != UNKNOWN)
14698                     compare_code = reverse_condition (compare_code);
14699                 }
14700             }
14701
14702           if (compare_code != UNKNOWN)
14703             {
14704               /* notl op1       (if needed)
14705                  sarl $31, op1
14706                  andl (cf-ct), op1
14707                  addl ct, op1
14708
14709                  For x < 0 (resp. x <= -1) there will be no notl,
14710                  so if possible swap the constants to get rid of the
14711                  complement.
14712                  True/false will be -1/0 while code below (store flag
14713                  followed by decrement) is 0/-1, so the constants need
14714                  to be exchanged once more.  */
14715
14716               if (compare_code == GE || !cf)
14717                 {
14718                   code = reverse_condition (code);
14719                   compare_code = LT;
14720                 }
14721               else
14722                 {
14723                   HOST_WIDE_INT tmp = cf;
14724                   cf = ct;
14725                   ct = tmp;
14726                 }
14727
14728               out = emit_store_flag (out, code, ix86_compare_op0,
14729                                      ix86_compare_op1, VOIDmode, 0, -1);
14730             }
14731           else
14732             {
14733               out = emit_store_flag (out, code, ix86_compare_op0,
14734                                      ix86_compare_op1, VOIDmode, 0, 1);
14735
14736               out = expand_simple_binop (mode, PLUS, copy_rtx (out), constm1_rtx,
14737                                          copy_rtx (out), 1, OPTAB_DIRECT);
14738             }
14739
14740           out = expand_simple_binop (mode, AND, copy_rtx (out),
14741                                      gen_int_mode (cf - ct, mode),
14742                                      copy_rtx (out), 1, OPTAB_DIRECT);
14743           if (ct)
14744             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
14745                                        copy_rtx (out), 1, OPTAB_DIRECT);
14746           if (!rtx_equal_p (out, operands[0]))
14747             emit_move_insn (operands[0], copy_rtx (out));
14748
14749           return 1; /* DONE */
14750         }
14751     }
14752
14753   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14754     {
14755       /* Try a few things more with specific constants and a variable.  */
14756
14757       optab op;
14758       rtx var, orig_out, out, tmp;
14759
14760       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
14761         return 0; /* FAIL */
14762
14763       /* If one of the two operands is an interesting constant, load a
14764          constant with the above and mask it in with a logical operation.  */
14765
14766       if (CONST_INT_P (operands[2]))
14767         {
14768           var = operands[3];
14769           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
14770             operands[3] = constm1_rtx, op = and_optab;
14771           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
14772             operands[3] = const0_rtx, op = ior_optab;
14773           else
14774             return 0; /* FAIL */
14775         }
14776       else if (CONST_INT_P (operands[3]))
14777         {
14778           var = operands[2];
14779           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
14780             operands[2] = constm1_rtx, op = and_optab;
14781           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
14782             operands[2] = const0_rtx, op = ior_optab;
14783           else
14784             return 0; /* FAIL */
14785         }
14786       else
14787         return 0; /* FAIL */
14788
14789       orig_out = operands[0];
14790       tmp = gen_reg_rtx (mode);
14791       operands[0] = tmp;
14792
14793       /* Recurse to get the constant loaded.  */
14794       if (ix86_expand_int_movcc (operands) == 0)
14795         return 0; /* FAIL */
14796
14797       /* Mask in the interesting variable.  */
14798       out = expand_binop (mode, op, var, tmp, orig_out, 0,
14799                           OPTAB_WIDEN);
14800       if (!rtx_equal_p (out, orig_out))
14801         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
14802
14803       return 1; /* DONE */
14804     }
14805
14806   /*
14807    * For comparison with above,
14808    *
14809    * movl cf,dest
14810    * movl ct,tmp
14811    * cmpl op1,op2
14812    * cmovcc tmp,dest
14813    *
14814    * Size 15.
14815    */
14816
14817   if (! nonimmediate_operand (operands[2], mode))
14818     operands[2] = force_reg (mode, operands[2]);
14819   if (! nonimmediate_operand (operands[3], mode))
14820     operands[3] = force_reg (mode, operands[3]);
14821
14822   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
14823     {
14824       rtx tmp = gen_reg_rtx (mode);
14825       emit_move_insn (tmp, operands[3]);
14826       operands[3] = tmp;
14827     }
14828   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
14829     {
14830       rtx tmp = gen_reg_rtx (mode);
14831       emit_move_insn (tmp, operands[2]);
14832       operands[2] = tmp;
14833     }
14834
14835   if (! register_operand (operands[2], VOIDmode)
14836       && (mode == QImode
14837           || ! register_operand (operands[3], VOIDmode)))
14838     operands[2] = force_reg (mode, operands[2]);
14839
14840   if (mode == QImode
14841       && ! register_operand (operands[3], VOIDmode))
14842     operands[3] = force_reg (mode, operands[3]);
14843
14844   emit_insn (compare_seq);
14845   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
14846                           gen_rtx_IF_THEN_ELSE (mode,
14847                                                 compare_op, operands[2],
14848                                                 operands[3])));
14849   if (bypass_test)
14850     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
14851                             gen_rtx_IF_THEN_ELSE (mode,
14852                                   bypass_test,
14853                                   copy_rtx (operands[3]),
14854                                   copy_rtx (operands[0]))));
14855   if (second_test)
14856     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
14857                             gen_rtx_IF_THEN_ELSE (mode,
14858                                   second_test,
14859                                   copy_rtx (operands[2]),
14860                                   copy_rtx (operands[0]))));
14861
14862   return 1; /* DONE */
14863 }
14864
14865 /* Swap, force into registers, or otherwise massage the two operands
14866    to an sse comparison with a mask result.  Thus we differ a bit from
14867    ix86_prepare_fp_compare_args which expects to produce a flags result.
14868
14869    The DEST operand exists to help determine whether to commute commutative
14870    operators.  The POP0/POP1 operands are updated in place.  The new
14871    comparison code is returned, or UNKNOWN if not implementable.  */
14872
14873 static enum rtx_code
14874 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
14875                                   rtx *pop0, rtx *pop1)
14876 {
14877   rtx tmp;
14878
14879   switch (code)
14880     {
14881     case LTGT:
14882     case UNEQ:
14883       /* We have no LTGT as an operator.  We could implement it with
14884          NE & ORDERED, but this requires an extra temporary.  It's
14885          not clear that it's worth it.  */
14886       return UNKNOWN;
14887
14888     case LT:
14889     case LE:
14890     case UNGT:
14891     case UNGE:
14892       /* These are supported directly.  */
14893       break;
14894
14895     case EQ:
14896     case NE:
14897     case UNORDERED:
14898     case ORDERED:
14899       /* For commutative operators, try to canonicalize the destination
14900          operand to be first in the comparison - this helps reload to
14901          avoid extra moves.  */
14902       if (!dest || !rtx_equal_p (dest, *pop1))
14903         break;
14904       /* FALLTHRU */
14905
14906     case GE:
14907     case GT:
14908     case UNLE:
14909     case UNLT:
14910       /* These are not supported directly.  Swap the comparison operands
14911          to transform into something that is supported.  */
14912       tmp = *pop0;
14913       *pop0 = *pop1;
14914       *pop1 = tmp;
14915       code = swap_condition (code);
14916       break;
14917
14918     default:
14919       gcc_unreachable ();
14920     }
14921
14922   return code;
14923 }
14924
14925 /* Detect conditional moves that exactly match min/max operational
14926    semantics.  Note that this is IEEE safe, as long as we don't
14927    interchange the operands.
14928
14929    Returns FALSE if this conditional move doesn't match a MIN/MAX,
14930    and TRUE if the operation is successful and instructions are emitted.  */
14931
14932 static bool
14933 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
14934                            rtx cmp_op1, rtx if_true, rtx if_false)
14935 {
14936   enum machine_mode mode;
14937   bool is_min;
14938   rtx tmp;
14939
14940   if (code == LT)
14941     ;
14942   else if (code == UNGE)
14943     {
14944       tmp = if_true;
14945       if_true = if_false;
14946       if_false = tmp;
14947     }
14948   else
14949     return false;
14950
14951   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
14952     is_min = true;
14953   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
14954     is_min = false;
14955   else
14956     return false;
14957
14958   mode = GET_MODE (dest);
14959
14960   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
14961      but MODE may be a vector mode and thus not appropriate.  */
14962   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
14963     {
14964       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
14965       rtvec v;
14966
14967       if_true = force_reg (mode, if_true);
14968       v = gen_rtvec (2, if_true, if_false);
14969       tmp = gen_rtx_UNSPEC (mode, v, u);
14970     }
14971   else
14972     {
14973       code = is_min ? SMIN : SMAX;
14974       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
14975     }
14976
14977   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
14978   return true;
14979 }
14980
14981 /* Expand an sse vector comparison.  Return the register with the result.  */
14982
14983 static rtx
14984 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
14985                      rtx op_true, rtx op_false)
14986 {
14987   enum machine_mode mode = GET_MODE (dest);
14988   rtx x;
14989
14990   cmp_op0 = force_reg (mode, cmp_op0);
14991   if (!nonimmediate_operand (cmp_op1, mode))
14992     cmp_op1 = force_reg (mode, cmp_op1);
14993
14994   if (optimize
14995       || reg_overlap_mentioned_p (dest, op_true)
14996       || reg_overlap_mentioned_p (dest, op_false))
14997     dest = gen_reg_rtx (mode);
14998
14999   x = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
15000   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15001
15002   return dest;
15003 }
15004
15005 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
15006    operations.  This is used for both scalar and vector conditional moves.  */
15007
15008 static void
15009 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
15010 {
15011   enum machine_mode mode = GET_MODE (dest);
15012   rtx t2, t3, x;
15013
15014   if (op_false == CONST0_RTX (mode))
15015     {
15016       op_true = force_reg (mode, op_true);
15017       x = gen_rtx_AND (mode, cmp, op_true);
15018       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15019     }
15020   else if (op_true == CONST0_RTX (mode))
15021     {
15022       op_false = force_reg (mode, op_false);
15023       x = gen_rtx_NOT (mode, cmp);
15024       x = gen_rtx_AND (mode, x, op_false);
15025       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15026     }
15027   else if (TARGET_SSE5)
15028     {
15029       rtx pcmov = gen_rtx_SET (mode, dest,
15030                                gen_rtx_IF_THEN_ELSE (mode, cmp,
15031                                                      op_true,
15032                                                      op_false));
15033       emit_insn (pcmov);
15034     }
15035   else
15036     {
15037       op_true = force_reg (mode, op_true);
15038       op_false = force_reg (mode, op_false);
15039
15040       t2 = gen_reg_rtx (mode);
15041       if (optimize)
15042         t3 = gen_reg_rtx (mode);
15043       else
15044         t3 = dest;
15045
15046       x = gen_rtx_AND (mode, op_true, cmp);
15047       emit_insn (gen_rtx_SET (VOIDmode, t2, x));
15048
15049       x = gen_rtx_NOT (mode, cmp);
15050       x = gen_rtx_AND (mode, x, op_false);
15051       emit_insn (gen_rtx_SET (VOIDmode, t3, x));
15052
15053       x = gen_rtx_IOR (mode, t3, t2);
15054       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15055     }
15056 }
15057
15058 /* Expand a floating-point conditional move.  Return true if successful.  */
15059
15060 int
15061 ix86_expand_fp_movcc (rtx operands[])
15062 {
15063   enum machine_mode mode = GET_MODE (operands[0]);
15064   enum rtx_code code = GET_CODE (operands[1]);
15065   rtx tmp, compare_op, second_test, bypass_test;
15066
15067   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
15068     {
15069       enum machine_mode cmode;
15070
15071       /* Since we've no cmove for sse registers, don't force bad register
15072          allocation just to gain access to it.  Deny movcc when the
15073          comparison mode doesn't match the move mode.  */
15074       cmode = GET_MODE (ix86_compare_op0);
15075       if (cmode == VOIDmode)
15076         cmode = GET_MODE (ix86_compare_op1);
15077       if (cmode != mode)
15078         return 0;
15079
15080       code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15081                                                &ix86_compare_op0,
15082                                                &ix86_compare_op1);
15083       if (code == UNKNOWN)
15084         return 0;
15085
15086       if (ix86_expand_sse_fp_minmax (operands[0], code, ix86_compare_op0,
15087                                      ix86_compare_op1, operands[2],
15088                                      operands[3]))
15089         return 1;
15090
15091       tmp = ix86_expand_sse_cmp (operands[0], code, ix86_compare_op0,
15092                                  ix86_compare_op1, operands[2], operands[3]);
15093       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
15094       return 1;
15095     }
15096
15097   /* The floating point conditional move instructions don't directly
15098      support conditions resulting from a signed integer comparison.  */
15099
15100   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
15101
15102   /* The floating point conditional move instructions don't directly
15103      support signed integer comparisons.  */
15104
15105   if (!fcmov_comparison_operator (compare_op, VOIDmode))
15106     {
15107       gcc_assert (!second_test && !bypass_test);
15108       tmp = gen_reg_rtx (QImode);
15109       ix86_expand_setcc (code, tmp);
15110       code = NE;
15111       ix86_compare_op0 = tmp;
15112       ix86_compare_op1 = const0_rtx;
15113       compare_op = ix86_expand_compare (code,  &second_test, &bypass_test);
15114     }
15115   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
15116     {
15117       tmp = gen_reg_rtx (mode);
15118       emit_move_insn (tmp, operands[3]);
15119       operands[3] = tmp;
15120     }
15121   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
15122     {
15123       tmp = gen_reg_rtx (mode);
15124       emit_move_insn (tmp, operands[2]);
15125       operands[2] = tmp;
15126     }
15127
15128   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15129                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
15130                                                 operands[2], operands[3])));
15131   if (bypass_test)
15132     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15133                             gen_rtx_IF_THEN_ELSE (mode, bypass_test,
15134                                                   operands[3], operands[0])));
15135   if (second_test)
15136     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15137                             gen_rtx_IF_THEN_ELSE (mode, second_test,
15138                                                   operands[2], operands[0])));
15139
15140   return 1;
15141 }
15142
15143 /* Expand a floating-point vector conditional move; a vcond operation
15144    rather than a movcc operation.  */
15145
15146 bool
15147 ix86_expand_fp_vcond (rtx operands[])
15148 {
15149   enum rtx_code code = GET_CODE (operands[3]);
15150   rtx cmp;
15151
15152   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15153                                            &operands[4], &operands[5]);
15154   if (code == UNKNOWN)
15155     return false;
15156
15157   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
15158                                  operands[5], operands[1], operands[2]))
15159     return true;
15160
15161   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
15162                              operands[1], operands[2]);
15163   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
15164   return true;
15165 }
15166
15167 /* Expand a signed/unsigned integral vector conditional move.  */
15168
15169 bool
15170 ix86_expand_int_vcond (rtx operands[])
15171 {
15172   enum machine_mode mode = GET_MODE (operands[0]);
15173   enum rtx_code code = GET_CODE (operands[3]);
15174   bool negate = false;
15175   rtx x, cop0, cop1;
15176
15177   cop0 = operands[4];
15178   cop1 = operands[5];
15179
15180   /* SSE5 supports all of the comparisons on all vector int types.  */
15181   if (!TARGET_SSE5)
15182     {
15183       /* Canonicalize the comparison to EQ, GT, GTU.  */
15184       switch (code)
15185         {
15186         case EQ:
15187         case GT:
15188         case GTU:
15189           break;
15190
15191         case NE:
15192         case LE:
15193         case LEU:
15194           code = reverse_condition (code);
15195           negate = true;
15196           break;
15197
15198         case GE:
15199         case GEU:
15200           code = reverse_condition (code);
15201           negate = true;
15202           /* FALLTHRU */
15203
15204         case LT:
15205         case LTU:
15206           code = swap_condition (code);
15207           x = cop0, cop0 = cop1, cop1 = x;
15208           break;
15209
15210         default:
15211           gcc_unreachable ();
15212         }
15213
15214       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
15215       if (mode == V2DImode)
15216         {
15217           switch (code)
15218             {
15219             case EQ:
15220               /* SSE4.1 supports EQ.  */
15221               if (!TARGET_SSE4_1)
15222                 return false;
15223               break;
15224
15225             case GT:
15226             case GTU:
15227               /* SSE4.2 supports GT/GTU.  */
15228               if (!TARGET_SSE4_2)
15229                 return false;
15230               break;
15231
15232             default:
15233               gcc_unreachable ();
15234             }
15235         }
15236
15237       /* Unsigned parallel compare is not supported by the hardware.  Play some
15238          tricks to turn this into a signed comparison against 0.  */
15239       if (code == GTU)
15240         {
15241           cop0 = force_reg (mode, cop0);
15242
15243           switch (mode)
15244             {
15245             case V4SImode:
15246             case V2DImode:
15247               {
15248                 rtx t1, t2, mask;
15249
15250                 /* Perform a parallel modulo subtraction.  */
15251                 t1 = gen_reg_rtx (mode);
15252                 emit_insn ((mode == V4SImode
15253                             ? gen_subv4si3
15254                             : gen_subv2di3) (t1, cop0, cop1));
15255
15256                 /* Extract the original sign bit of op0.  */
15257                 mask = ix86_build_signbit_mask (GET_MODE_INNER (mode),
15258                                                 true, false);
15259                 t2 = gen_reg_rtx (mode);
15260                 emit_insn ((mode == V4SImode
15261                             ? gen_andv4si3
15262                             : gen_andv2di3) (t2, cop0, mask));
15263
15264                 /* XOR it back into the result of the subtraction.  This results
15265                    in the sign bit set iff we saw unsigned underflow.  */
15266                 x = gen_reg_rtx (mode);
15267                 emit_insn ((mode == V4SImode
15268                             ? gen_xorv4si3
15269                             : gen_xorv2di3) (x, t1, t2));
15270
15271                 code = GT;
15272               }
15273               break;
15274
15275             case V16QImode:
15276             case V8HImode:
15277               /* Perform a parallel unsigned saturating subtraction.  */
15278               x = gen_reg_rtx (mode);
15279               emit_insn (gen_rtx_SET (VOIDmode, x,
15280                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
15281
15282               code = EQ;
15283               negate = !negate;
15284               break;
15285
15286             default:
15287               gcc_unreachable ();
15288             }
15289
15290           cop0 = x;
15291           cop1 = CONST0_RTX (mode);
15292         }
15293     }
15294
15295   x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
15296                            operands[1+negate], operands[2-negate]);
15297
15298   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
15299                          operands[2-negate]);
15300   return true;
15301 }
15302
15303 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
15304    true if we should do zero extension, else sign extension.  HIGH_P is
15305    true if we want the N/2 high elements, else the low elements.  */
15306
15307 void
15308 ix86_expand_sse_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15309 {
15310   enum machine_mode imode = GET_MODE (operands[1]);
15311   rtx (*unpack)(rtx, rtx, rtx);
15312   rtx se, dest;
15313
15314   switch (imode)
15315     {
15316     case V16QImode:
15317       if (high_p)
15318         unpack = gen_vec_interleave_highv16qi;
15319       else
15320         unpack = gen_vec_interleave_lowv16qi;
15321       break;
15322     case V8HImode:
15323       if (high_p)
15324         unpack = gen_vec_interleave_highv8hi;
15325       else
15326         unpack = gen_vec_interleave_lowv8hi;
15327       break;
15328     case V4SImode:
15329       if (high_p)
15330         unpack = gen_vec_interleave_highv4si;
15331       else
15332         unpack = gen_vec_interleave_lowv4si;
15333       break;
15334     default:
15335       gcc_unreachable ();
15336     }
15337
15338   dest = gen_lowpart (imode, operands[0]);
15339
15340   if (unsigned_p)
15341     se = force_reg (imode, CONST0_RTX (imode));
15342   else
15343     se = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
15344                               operands[1], pc_rtx, pc_rtx);
15345
15346   emit_insn (unpack (dest, operands[1], se));
15347 }
15348
15349 /* This function performs the same task as ix86_expand_sse_unpack,
15350    but with SSE4.1 instructions.  */
15351
15352 void
15353 ix86_expand_sse4_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15354 {
15355   enum machine_mode imode = GET_MODE (operands[1]);
15356   rtx (*unpack)(rtx, rtx);
15357   rtx src, dest;
15358
15359   switch (imode)
15360     {
15361     case V16QImode:
15362       if (unsigned_p)
15363         unpack = gen_sse4_1_zero_extendv8qiv8hi2;
15364       else
15365         unpack = gen_sse4_1_extendv8qiv8hi2;
15366       break;
15367     case V8HImode:
15368       if (unsigned_p)
15369         unpack = gen_sse4_1_zero_extendv4hiv4si2;
15370       else
15371         unpack = gen_sse4_1_extendv4hiv4si2;
15372       break;
15373     case V4SImode:
15374       if (unsigned_p)
15375         unpack = gen_sse4_1_zero_extendv2siv2di2;
15376       else
15377         unpack = gen_sse4_1_extendv2siv2di2;
15378       break;
15379     default:
15380       gcc_unreachable ();
15381     }
15382
15383   dest = operands[0];
15384   if (high_p)
15385     {
15386       /* Shift higher 8 bytes to lower 8 bytes.  */
15387       src = gen_reg_rtx (imode);
15388       emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, src),
15389                                    gen_lowpart (TImode, operands[1]),
15390                                    GEN_INT (64)));
15391     }
15392   else
15393     src = operands[1];
15394
15395   emit_insn (unpack (dest, src));
15396 }
15397
15398 /* This function performs the same task as ix86_expand_sse_unpack,
15399    but with sse5 instructions.  */
15400
15401 void
15402 ix86_expand_sse5_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15403 {
15404   enum machine_mode imode = GET_MODE (operands[1]);
15405   int pperm_bytes[16];
15406   int i;
15407   int h = (high_p) ? 8 : 0;
15408   int h2;
15409   int sign_extend;
15410   rtvec v = rtvec_alloc (16);
15411   rtvec vs;
15412   rtx x, p;
15413   rtx op0 = operands[0], op1 = operands[1];
15414
15415   switch (imode)
15416     {
15417     case V16QImode:
15418       vs = rtvec_alloc (8);
15419       h2 = (high_p) ? 8 : 0;
15420       for (i = 0; i < 8; i++)
15421         {
15422           pperm_bytes[2*i+0] = PPERM_SRC | PPERM_SRC2 | i | h;
15423           pperm_bytes[2*i+1] = ((unsigned_p)
15424                                 ? PPERM_ZERO
15425                                 : PPERM_SIGN | PPERM_SRC2 | i | h);
15426         }
15427
15428       for (i = 0; i < 16; i++)
15429         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15430
15431       for (i = 0; i < 8; i++)
15432         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15433
15434       p = gen_rtx_PARALLEL (VOIDmode, vs);
15435       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15436       if (unsigned_p)
15437         emit_insn (gen_sse5_pperm_zero_v16qi_v8hi (op0, op1, p, x));
15438       else
15439         emit_insn (gen_sse5_pperm_sign_v16qi_v8hi (op0, op1, p, x));
15440       break;
15441
15442     case V8HImode:
15443       vs = rtvec_alloc (4);
15444       h2 = (high_p) ? 4 : 0;
15445       for (i = 0; i < 4; i++)
15446         {
15447           sign_extend = ((unsigned_p)
15448                          ? PPERM_ZERO
15449                          : PPERM_SIGN | PPERM_SRC2 | ((2*i) + 1 + h));
15450           pperm_bytes[4*i+0] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 0 + h);
15451           pperm_bytes[4*i+1] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 1 + h);
15452           pperm_bytes[4*i+2] = sign_extend;
15453           pperm_bytes[4*i+3] = sign_extend;
15454         }
15455
15456       for (i = 0; i < 16; i++)
15457         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15458
15459       for (i = 0; i < 4; i++)
15460         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15461
15462       p = gen_rtx_PARALLEL (VOIDmode, vs);
15463       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15464       if (unsigned_p)
15465         emit_insn (gen_sse5_pperm_zero_v8hi_v4si (op0, op1, p, x));
15466       else
15467         emit_insn (gen_sse5_pperm_sign_v8hi_v4si (op0, op1, p, x));
15468       break;
15469
15470     case V4SImode:
15471       vs = rtvec_alloc (2);
15472       h2 = (high_p) ? 2 : 0;
15473       for (i = 0; i < 2; i++)
15474         {
15475           sign_extend = ((unsigned_p)
15476                          ? PPERM_ZERO
15477                          : PPERM_SIGN | PPERM_SRC2 | ((4*i) + 3 + h));
15478           pperm_bytes[8*i+0] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 0 + h);
15479           pperm_bytes[8*i+1] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 1 + h);
15480           pperm_bytes[8*i+2] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 2 + h);
15481           pperm_bytes[8*i+3] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 3 + h);
15482           pperm_bytes[8*i+4] = sign_extend;
15483           pperm_bytes[8*i+5] = sign_extend;
15484           pperm_bytes[8*i+6] = sign_extend;
15485           pperm_bytes[8*i+7] = sign_extend;
15486         }
15487
15488       for (i = 0; i < 16; i++)
15489         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15490
15491       for (i = 0; i < 2; i++)
15492         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15493
15494       p = gen_rtx_PARALLEL (VOIDmode, vs);
15495       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15496       if (unsigned_p)
15497         emit_insn (gen_sse5_pperm_zero_v4si_v2di (op0, op1, p, x));
15498       else
15499         emit_insn (gen_sse5_pperm_sign_v4si_v2di (op0, op1, p, x));
15500       break;
15501
15502     default:
15503       gcc_unreachable ();
15504     }
15505
15506   return;
15507 }
15508
15509 /* Pack the high bits from OPERANDS[1] and low bits from OPERANDS[2] into the
15510    next narrower integer vector type */
15511 void
15512 ix86_expand_sse5_pack (rtx operands[3])
15513 {
15514   enum machine_mode imode = GET_MODE (operands[0]);
15515   int pperm_bytes[16];
15516   int i;
15517   rtvec v = rtvec_alloc (16);
15518   rtx x;
15519   rtx op0 = operands[0];
15520   rtx op1 = operands[1];
15521   rtx op2 = operands[2];
15522
15523   switch (imode)
15524     {
15525     case V16QImode:
15526       for (i = 0; i < 8; i++)
15527         {
15528           pperm_bytes[i+0] = PPERM_SRC | PPERM_SRC1 | (i*2);
15529           pperm_bytes[i+8] = PPERM_SRC | PPERM_SRC2 | (i*2);
15530         }
15531
15532       for (i = 0; i < 16; i++)
15533         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15534
15535       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15536       emit_insn (gen_sse5_pperm_pack_v8hi_v16qi (op0, op1, op2, x));
15537       break;
15538
15539     case V8HImode:
15540       for (i = 0; i < 4; i++)
15541         {
15542           pperm_bytes[(2*i)+0] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 0);
15543           pperm_bytes[(2*i)+1] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 1);
15544           pperm_bytes[(2*i)+8] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 0);
15545           pperm_bytes[(2*i)+9] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 1);
15546         }
15547
15548       for (i = 0; i < 16; i++)
15549         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15550
15551       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15552       emit_insn (gen_sse5_pperm_pack_v4si_v8hi (op0, op1, op2, x));
15553       break;
15554
15555     case V4SImode:
15556       for (i = 0; i < 2; i++)
15557         {
15558           pperm_bytes[(4*i)+0]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 0);
15559           pperm_bytes[(4*i)+1]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 1);
15560           pperm_bytes[(4*i)+2]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 2);
15561           pperm_bytes[(4*i)+3]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 3);
15562           pperm_bytes[(4*i)+8]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 0);
15563           pperm_bytes[(4*i)+9]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 1);
15564           pperm_bytes[(4*i)+10] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 2);
15565           pperm_bytes[(4*i)+11] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 3);
15566         }
15567
15568       for (i = 0; i < 16; i++)
15569         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15570
15571       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15572       emit_insn (gen_sse5_pperm_pack_v2di_v4si (op0, op1, op2, x));
15573       break;
15574
15575     default:
15576       gcc_unreachable ();
15577     }
15578
15579   return;
15580 }
15581
15582 /* Expand conditional increment or decrement using adb/sbb instructions.
15583    The default case using setcc followed by the conditional move can be
15584    done by generic code.  */
15585 int
15586 ix86_expand_int_addcc (rtx operands[])
15587 {
15588   enum rtx_code code = GET_CODE (operands[1]);
15589   rtx compare_op;
15590   rtx val = const0_rtx;
15591   bool fpcmp = false;
15592   enum machine_mode mode = GET_MODE (operands[0]);
15593
15594   if (operands[3] != const1_rtx
15595       && operands[3] != constm1_rtx)
15596     return 0;
15597   if (!ix86_expand_carry_flag_compare (code, ix86_compare_op0,
15598                                        ix86_compare_op1, &compare_op))
15599      return 0;
15600   code = GET_CODE (compare_op);
15601
15602   if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
15603       || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
15604     {
15605       fpcmp = true;
15606       code = ix86_fp_compare_code_to_integer (code);
15607     }
15608
15609   if (code != LTU)
15610     {
15611       val = constm1_rtx;
15612       if (fpcmp)
15613         PUT_CODE (compare_op,
15614                   reverse_condition_maybe_unordered
15615                     (GET_CODE (compare_op)));
15616       else
15617         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
15618     }
15619   PUT_MODE (compare_op, mode);
15620
15621   /* Construct either adc or sbb insn.  */
15622   if ((code == LTU) == (operands[3] == constm1_rtx))
15623     {
15624       switch (GET_MODE (operands[0]))
15625         {
15626           case QImode:
15627             emit_insn (gen_subqi3_carry (operands[0], operands[2], val, compare_op));
15628             break;
15629           case HImode:
15630             emit_insn (gen_subhi3_carry (operands[0], operands[2], val, compare_op));
15631             break;
15632           case SImode:
15633             emit_insn (gen_subsi3_carry (operands[0], operands[2], val, compare_op));
15634             break;
15635           case DImode:
15636             emit_insn (gen_subdi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15637             break;
15638           default:
15639             gcc_unreachable ();
15640         }
15641     }
15642   else
15643     {
15644       switch (GET_MODE (operands[0]))
15645         {
15646           case QImode:
15647             emit_insn (gen_addqi3_carry (operands[0], operands[2], val, compare_op));
15648             break;
15649           case HImode:
15650             emit_insn (gen_addhi3_carry (operands[0], operands[2], val, compare_op));
15651             break;
15652           case SImode:
15653             emit_insn (gen_addsi3_carry (operands[0], operands[2], val, compare_op));
15654             break;
15655           case DImode:
15656             emit_insn (gen_adddi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15657             break;
15658           default:
15659             gcc_unreachable ();
15660         }
15661     }
15662   return 1; /* DONE */
15663 }
15664
15665
15666 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
15667    works for floating pointer parameters and nonoffsetable memories.
15668    For pushes, it returns just stack offsets; the values will be saved
15669    in the right order.  Maximally three parts are generated.  */
15670
15671 static int
15672 ix86_split_to_parts (rtx operand, rtx *parts, enum machine_mode mode)
15673 {
15674   int size;
15675
15676   if (!TARGET_64BIT)
15677     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
15678   else
15679     size = (GET_MODE_SIZE (mode) + 4) / 8;
15680
15681   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
15682   gcc_assert (size >= 2 && size <= 4);
15683
15684   /* Optimize constant pool reference to immediates.  This is used by fp
15685      moves, that force all constants to memory to allow combining.  */
15686   if (MEM_P (operand) && MEM_READONLY_P (operand))
15687     {
15688       rtx tmp = maybe_get_pool_constant (operand);
15689       if (tmp)
15690         operand = tmp;
15691     }
15692
15693   if (MEM_P (operand) && !offsettable_memref_p (operand))
15694     {
15695       /* The only non-offsetable memories we handle are pushes.  */
15696       int ok = push_operand (operand, VOIDmode);
15697
15698       gcc_assert (ok);
15699
15700       operand = copy_rtx (operand);
15701       PUT_MODE (operand, Pmode);
15702       parts[0] = parts[1] = parts[2] = parts[3] = operand;
15703       return size;
15704     }
15705
15706   if (GET_CODE (operand) == CONST_VECTOR)
15707     {
15708       enum machine_mode imode = int_mode_for_mode (mode);
15709       /* Caution: if we looked through a constant pool memory above,
15710          the operand may actually have a different mode now.  That's
15711          ok, since we want to pun this all the way back to an integer.  */
15712       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
15713       gcc_assert (operand != NULL);
15714       mode = imode;
15715     }
15716
15717   if (!TARGET_64BIT)
15718     {
15719       if (mode == DImode)
15720         split_di (&operand, 1, &parts[0], &parts[1]);
15721       else
15722         {
15723           int i;
15724
15725           if (REG_P (operand))
15726             {
15727               gcc_assert (reload_completed);
15728               for (i = 0; i < size; i++)
15729                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
15730             }
15731           else if (offsettable_memref_p (operand))
15732             {
15733               operand = adjust_address (operand, SImode, 0);
15734               parts[0] = operand;
15735               for (i = 1; i < size; i++)
15736                 parts[i] = adjust_address (operand, SImode, 4 * i);
15737             }
15738           else if (GET_CODE (operand) == CONST_DOUBLE)
15739             {
15740               REAL_VALUE_TYPE r;
15741               long l[4];
15742
15743               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
15744               switch (mode)
15745                 {
15746                 case TFmode:
15747                   real_to_target (l, &r, mode);
15748                   parts[3] = gen_int_mode (l[3], SImode);
15749                   parts[2] = gen_int_mode (l[2], SImode);
15750                   break;
15751                 case XFmode:
15752                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
15753                   parts[2] = gen_int_mode (l[2], SImode);
15754                   break;
15755                 case DFmode:
15756                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
15757                   break;
15758                 default:
15759                   gcc_unreachable ();
15760                 }
15761               parts[1] = gen_int_mode (l[1], SImode);
15762               parts[0] = gen_int_mode (l[0], SImode);
15763             }
15764           else
15765             gcc_unreachable ();
15766         }
15767     }
15768   else
15769     {
15770       if (mode == TImode)
15771         split_ti (&operand, 1, &parts[0], &parts[1]);
15772       if (mode == XFmode || mode == TFmode)
15773         {
15774           enum machine_mode upper_mode = mode==XFmode ? SImode : DImode;
15775           if (REG_P (operand))
15776             {
15777               gcc_assert (reload_completed);
15778               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
15779               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
15780             }
15781           else if (offsettable_memref_p (operand))
15782             {
15783               operand = adjust_address (operand, DImode, 0);
15784               parts[0] = operand;
15785               parts[1] = adjust_address (operand, upper_mode, 8);
15786             }
15787           else if (GET_CODE (operand) == CONST_DOUBLE)
15788             {
15789               REAL_VALUE_TYPE r;
15790               long l[4];
15791
15792               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
15793               real_to_target (l, &r, mode);
15794
15795               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
15796               if (HOST_BITS_PER_WIDE_INT >= 64)
15797                 parts[0]
15798                   = gen_int_mode
15799                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
15800                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
15801                        DImode);
15802               else
15803                 parts[0] = immed_double_const (l[0], l[1], DImode);
15804
15805               if (upper_mode == SImode)
15806                 parts[1] = gen_int_mode (l[2], SImode);
15807               else if (HOST_BITS_PER_WIDE_INT >= 64)
15808                 parts[1]
15809                   = gen_int_mode
15810                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
15811                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
15812                        DImode);
15813               else
15814                 parts[1] = immed_double_const (l[2], l[3], DImode);
15815             }
15816           else
15817             gcc_unreachable ();
15818         }
15819     }
15820
15821   return size;
15822 }
15823
15824 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
15825    Return false when normal moves are needed; true when all required
15826    insns have been emitted.  Operands 2-4 contain the input values
15827    int the correct order; operands 5-7 contain the output values.  */
15828
15829 void
15830 ix86_split_long_move (rtx operands[])
15831 {
15832   rtx part[2][4];
15833   int nparts, i, j;
15834   int push = 0;
15835   int collisions = 0;
15836   enum machine_mode mode = GET_MODE (operands[0]);
15837   bool collisionparts[4];
15838
15839   /* The DFmode expanders may ask us to move double.
15840      For 64bit target this is single move.  By hiding the fact
15841      here we simplify i386.md splitters.  */
15842   if (GET_MODE_SIZE (GET_MODE (operands[0])) == 8 && TARGET_64BIT)
15843     {
15844       /* Optimize constant pool reference to immediates.  This is used by
15845          fp moves, that force all constants to memory to allow combining.  */
15846
15847       if (MEM_P (operands[1])
15848           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
15849           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
15850         operands[1] = get_pool_constant (XEXP (operands[1], 0));
15851       if (push_operand (operands[0], VOIDmode))
15852         {
15853           operands[0] = copy_rtx (operands[0]);
15854           PUT_MODE (operands[0], Pmode);
15855         }
15856       else
15857         operands[0] = gen_lowpart (DImode, operands[0]);
15858       operands[1] = gen_lowpart (DImode, operands[1]);
15859       emit_move_insn (operands[0], operands[1]);
15860       return;
15861     }
15862
15863   /* The only non-offsettable memory we handle is push.  */
15864   if (push_operand (operands[0], VOIDmode))
15865     push = 1;
15866   else
15867     gcc_assert (!MEM_P (operands[0])
15868                 || offsettable_memref_p (operands[0]));
15869
15870   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
15871   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
15872
15873   /* When emitting push, take care for source operands on the stack.  */
15874   if (push && MEM_P (operands[1])
15875       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
15876     for (i = 0; i < nparts - 1; i++)
15877       part[1][i] = change_address (part[1][i],
15878                                    GET_MODE (part[1][i]),
15879                                    XEXP (part[1][i + 1], 0));
15880
15881   /* We need to do copy in the right order in case an address register
15882      of the source overlaps the destination.  */
15883   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
15884     {
15885       rtx tmp;
15886
15887       for (i = 0; i < nparts; i++)
15888         {
15889           collisionparts[i]
15890             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
15891           if (collisionparts[i])
15892             collisions++;
15893         }
15894
15895       /* Collision in the middle part can be handled by reordering.  */
15896       if (collisions == 1 && nparts == 3 && collisionparts [1])
15897         {
15898           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
15899           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
15900         }
15901       else if (collisions == 1
15902                && nparts == 4
15903                && (collisionparts [1] || collisionparts [2]))
15904         {
15905           if (collisionparts [1])
15906             {
15907               tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
15908               tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
15909             }
15910           else
15911             {
15912               tmp = part[0][2]; part[0][2] = part[0][3]; part[0][3] = tmp;
15913               tmp = part[1][2]; part[1][2] = part[1][3]; part[1][3] = tmp;
15914             }
15915         }
15916
15917       /* If there are more collisions, we can't handle it by reordering.
15918          Do an lea to the last part and use only one colliding move.  */
15919       else if (collisions > 1)
15920         {
15921           rtx base;
15922
15923           collisions = 1;
15924
15925           base = part[0][nparts - 1];
15926
15927           /* Handle the case when the last part isn't valid for lea.
15928              Happens in 64-bit mode storing the 12-byte XFmode.  */
15929           if (GET_MODE (base) != Pmode)
15930             base = gen_rtx_REG (Pmode, REGNO (base));
15931
15932           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
15933           part[1][0] = replace_equiv_address (part[1][0], base);
15934           for (i = 1; i < nparts; i++)
15935             {
15936               tmp = plus_constant (base, UNITS_PER_WORD * i);
15937               part[1][i] = replace_equiv_address (part[1][i], tmp);
15938             }
15939         }
15940     }
15941
15942   if (push)
15943     {
15944       if (!TARGET_64BIT)
15945         {
15946           if (nparts == 3)
15947             {
15948               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
15949                 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-4)));
15950               emit_move_insn (part[0][2], part[1][2]);
15951             }
15952           else if (nparts == 4)
15953             {
15954               emit_move_insn (part[0][3], part[1][3]);
15955               emit_move_insn (part[0][2], part[1][2]);
15956             }
15957         }
15958       else
15959         {
15960           /* In 64bit mode we don't have 32bit push available.  In case this is
15961              register, it is OK - we will just use larger counterpart.  We also
15962              retype memory - these comes from attempt to avoid REX prefix on
15963              moving of second half of TFmode value.  */
15964           if (GET_MODE (part[1][1]) == SImode)
15965             {
15966               switch (GET_CODE (part[1][1]))
15967                 {
15968                 case MEM:
15969                   part[1][1] = adjust_address (part[1][1], DImode, 0);
15970                   break;
15971
15972                 case REG:
15973                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
15974                   break;
15975
15976                 default:
15977                   gcc_unreachable ();
15978                 }
15979
15980               if (GET_MODE (part[1][0]) == SImode)
15981                 part[1][0] = part[1][1];
15982             }
15983         }
15984       emit_move_insn (part[0][1], part[1][1]);
15985       emit_move_insn (part[0][0], part[1][0]);
15986       return;
15987     }
15988
15989   /* Choose correct order to not overwrite the source before it is copied.  */
15990   if ((REG_P (part[0][0])
15991        && REG_P (part[1][1])
15992        && (REGNO (part[0][0]) == REGNO (part[1][1])
15993            || (nparts == 3
15994                && REGNO (part[0][0]) == REGNO (part[1][2]))
15995            || (nparts == 4
15996                && REGNO (part[0][0]) == REGNO (part[1][3]))))
15997       || (collisions > 0
15998           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
15999     {
16000       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
16001         {
16002           operands[2 + i] = part[0][j];
16003           operands[6 + i] = part[1][j];
16004         }
16005     }
16006   else
16007     {
16008       for (i = 0; i < nparts; i++)
16009         {
16010           operands[2 + i] = part[0][i];
16011           operands[6 + i] = part[1][i];
16012         }
16013     }
16014
16015   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
16016   if (optimize_insn_for_size_p ())
16017     {
16018       for (j = 0; j < nparts - 1; j++)
16019         if (CONST_INT_P (operands[6 + j])
16020             && operands[6 + j] != const0_rtx
16021             && REG_P (operands[2 + j]))
16022           for (i = j; i < nparts - 1; i++)
16023             if (CONST_INT_P (operands[7 + i])
16024                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
16025               operands[7 + i] = operands[2 + j];
16026     }
16027
16028   for (i = 0; i < nparts; i++)
16029     emit_move_insn (operands[2 + i], operands[6 + i]);
16030
16031   return;
16032 }
16033
16034 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
16035    left shift by a constant, either using a single shift or
16036    a sequence of add instructions.  */
16037
16038 static void
16039 ix86_expand_ashl_const (rtx operand, int count, enum machine_mode mode)
16040 {
16041   if (count == 1)
16042     {
16043       emit_insn ((mode == DImode
16044                   ? gen_addsi3
16045                   : gen_adddi3) (operand, operand, operand));
16046     }
16047   else if (!optimize_insn_for_size_p ()
16048            && count * ix86_cost->add <= ix86_cost->shift_const)
16049     {
16050       int i;
16051       for (i=0; i<count; i++)
16052         {
16053           emit_insn ((mode == DImode
16054                       ? gen_addsi3
16055                       : gen_adddi3) (operand, operand, operand));
16056         }
16057     }
16058   else
16059     emit_insn ((mode == DImode
16060                 ? gen_ashlsi3
16061                 : gen_ashldi3) (operand, operand, GEN_INT (count)));
16062 }
16063
16064 void
16065 ix86_split_ashl (rtx *operands, rtx scratch, enum machine_mode mode)
16066 {
16067   rtx low[2], high[2];
16068   int count;
16069   const int single_width = mode == DImode ? 32 : 64;
16070
16071   if (CONST_INT_P (operands[2]))
16072     {
16073       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16074       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16075
16076       if (count >= single_width)
16077         {
16078           emit_move_insn (high[0], low[1]);
16079           emit_move_insn (low[0], const0_rtx);
16080
16081           if (count > single_width)
16082             ix86_expand_ashl_const (high[0], count - single_width, mode);
16083         }
16084       else
16085         {
16086           if (!rtx_equal_p (operands[0], operands[1]))
16087             emit_move_insn (operands[0], operands[1]);
16088           emit_insn ((mode == DImode
16089                      ? gen_x86_shld
16090                      : gen_x86_64_shld) (high[0], low[0], GEN_INT (count)));
16091           ix86_expand_ashl_const (low[0], count, mode);
16092         }
16093       return;
16094     }
16095
16096   (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16097
16098   if (operands[1] == const1_rtx)
16099     {
16100       /* Assuming we've chosen a QImode capable registers, then 1 << N
16101          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
16102       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
16103         {
16104           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
16105
16106           ix86_expand_clear (low[0]);
16107           ix86_expand_clear (high[0]);
16108           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (single_width)));
16109
16110           d = gen_lowpart (QImode, low[0]);
16111           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16112           s = gen_rtx_EQ (QImode, flags, const0_rtx);
16113           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16114
16115           d = gen_lowpart (QImode, high[0]);
16116           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16117           s = gen_rtx_NE (QImode, flags, const0_rtx);
16118           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16119         }
16120
16121       /* Otherwise, we can get the same results by manually performing
16122          a bit extract operation on bit 5/6, and then performing the two
16123          shifts.  The two methods of getting 0/1 into low/high are exactly
16124          the same size.  Avoiding the shift in the bit extract case helps
16125          pentium4 a bit; no one else seems to care much either way.  */
16126       else
16127         {
16128           rtx x;
16129
16130           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
16131             x = gen_rtx_ZERO_EXTEND (mode == DImode ? SImode : DImode, operands[2]);
16132           else
16133             x = gen_lowpart (mode == DImode ? SImode : DImode, operands[2]);
16134           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
16135
16136           emit_insn ((mode == DImode
16137                       ? gen_lshrsi3
16138                       : gen_lshrdi3) (high[0], high[0], GEN_INT (mode == DImode ? 5 : 6)));
16139           emit_insn ((mode == DImode
16140                       ? gen_andsi3
16141                       : gen_anddi3) (high[0], high[0], GEN_INT (1)));
16142           emit_move_insn (low[0], high[0]);
16143           emit_insn ((mode == DImode
16144                       ? gen_xorsi3
16145                       : gen_xordi3) (low[0], low[0], GEN_INT (1)));
16146         }
16147
16148       emit_insn ((mode == DImode
16149                     ? gen_ashlsi3
16150                     : gen_ashldi3) (low[0], low[0], operands[2]));
16151       emit_insn ((mode == DImode
16152                     ? gen_ashlsi3
16153                     : gen_ashldi3) (high[0], high[0], operands[2]));
16154       return;
16155     }
16156
16157   if (operands[1] == constm1_rtx)
16158     {
16159       /* For -1 << N, we can avoid the shld instruction, because we
16160          know that we're shifting 0...31/63 ones into a -1.  */
16161       emit_move_insn (low[0], constm1_rtx);
16162       if (optimize_insn_for_size_p ())
16163         emit_move_insn (high[0], low[0]);
16164       else
16165         emit_move_insn (high[0], constm1_rtx);
16166     }
16167   else
16168     {
16169       if (!rtx_equal_p (operands[0], operands[1]))
16170         emit_move_insn (operands[0], operands[1]);
16171
16172       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16173       emit_insn ((mode == DImode
16174                   ? gen_x86_shld
16175                   : gen_x86_64_shld) (high[0], low[0], operands[2]));
16176     }
16177
16178   emit_insn ((mode == DImode ? gen_ashlsi3 : gen_ashldi3) (low[0], low[0], operands[2]));
16179
16180   if (TARGET_CMOVE && scratch)
16181     {
16182       ix86_expand_clear (scratch);
16183       emit_insn ((mode == DImode
16184                   ? gen_x86_shift_adj_1
16185                   : gen_x86_64_shift_adj_1) (high[0], low[0], operands[2],
16186                                              scratch));
16187     }
16188   else
16189     emit_insn ((mode == DImode
16190                 ? gen_x86_shift_adj_2
16191                 : gen_x86_64_shift_adj_2) (high[0], low[0], operands[2]));
16192 }
16193
16194 void
16195 ix86_split_ashr (rtx *operands, rtx scratch, enum machine_mode mode)
16196 {
16197   rtx low[2], high[2];
16198   int count;
16199   const int single_width = mode == DImode ? 32 : 64;
16200
16201   if (CONST_INT_P (operands[2]))
16202     {
16203       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16204       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16205
16206       if (count == single_width * 2 - 1)
16207         {
16208           emit_move_insn (high[0], high[1]);
16209           emit_insn ((mode == DImode
16210                       ? gen_ashrsi3
16211                       : gen_ashrdi3) (high[0], high[0],
16212                                       GEN_INT (single_width - 1)));
16213           emit_move_insn (low[0], high[0]);
16214
16215         }
16216       else if (count >= single_width)
16217         {
16218           emit_move_insn (low[0], high[1]);
16219           emit_move_insn (high[0], low[0]);
16220           emit_insn ((mode == DImode
16221                       ? gen_ashrsi3
16222                       : gen_ashrdi3) (high[0], high[0],
16223                                       GEN_INT (single_width - 1)));
16224           if (count > single_width)
16225             emit_insn ((mode == DImode
16226                         ? gen_ashrsi3
16227                         : gen_ashrdi3) (low[0], low[0],
16228                                         GEN_INT (count - single_width)));
16229         }
16230       else
16231         {
16232           if (!rtx_equal_p (operands[0], operands[1]))
16233             emit_move_insn (operands[0], operands[1]);
16234           emit_insn ((mode == DImode
16235                       ? gen_x86_shrd
16236                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16237           emit_insn ((mode == DImode
16238                       ? gen_ashrsi3
16239                       : gen_ashrdi3) (high[0], high[0], GEN_INT (count)));
16240         }
16241     }
16242   else
16243     {
16244       if (!rtx_equal_p (operands[0], operands[1]))
16245         emit_move_insn (operands[0], operands[1]);
16246
16247       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16248
16249       emit_insn ((mode == DImode
16250                   ? gen_x86_shrd
16251                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16252       emit_insn ((mode == DImode
16253                   ? gen_ashrsi3
16254                   : gen_ashrdi3)  (high[0], high[0], operands[2]));
16255
16256       if (TARGET_CMOVE && scratch)
16257         {
16258           emit_move_insn (scratch, high[0]);
16259           emit_insn ((mode == DImode
16260                       ? gen_ashrsi3
16261                       : gen_ashrdi3) (scratch, scratch,
16262                                       GEN_INT (single_width - 1)));
16263           emit_insn ((mode == DImode
16264                       ? gen_x86_shift_adj_1
16265                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16266                                                  scratch));
16267         }
16268       else
16269         emit_insn ((mode == DImode
16270                     ? gen_x86_shift_adj_3
16271                     : gen_x86_64_shift_adj_3) (low[0], high[0], operands[2]));
16272     }
16273 }
16274
16275 void
16276 ix86_split_lshr (rtx *operands, rtx scratch, enum machine_mode mode)
16277 {
16278   rtx low[2], high[2];
16279   int count;
16280   const int single_width = mode == DImode ? 32 : 64;
16281
16282   if (CONST_INT_P (operands[2]))
16283     {
16284       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16285       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16286
16287       if (count >= single_width)
16288         {
16289           emit_move_insn (low[0], high[1]);
16290           ix86_expand_clear (high[0]);
16291
16292           if (count > single_width)
16293             emit_insn ((mode == DImode
16294                         ? gen_lshrsi3
16295                         : gen_lshrdi3) (low[0], low[0],
16296                                         GEN_INT (count - single_width)));
16297         }
16298       else
16299         {
16300           if (!rtx_equal_p (operands[0], operands[1]))
16301             emit_move_insn (operands[0], operands[1]);
16302           emit_insn ((mode == DImode
16303                       ? gen_x86_shrd
16304                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16305           emit_insn ((mode == DImode
16306                       ? gen_lshrsi3
16307                       : gen_lshrdi3) (high[0], high[0], GEN_INT (count)));
16308         }
16309     }
16310   else
16311     {
16312       if (!rtx_equal_p (operands[0], operands[1]))
16313         emit_move_insn (operands[0], operands[1]);
16314
16315       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16316
16317       emit_insn ((mode == DImode
16318                   ? gen_x86_shrd
16319                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16320       emit_insn ((mode == DImode
16321                   ? gen_lshrsi3
16322                   : gen_lshrdi3) (high[0], high[0], operands[2]));
16323
16324       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
16325       if (TARGET_CMOVE && scratch)
16326         {
16327           ix86_expand_clear (scratch);
16328           emit_insn ((mode == DImode
16329                       ? gen_x86_shift_adj_1
16330                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16331                                                  scratch));
16332         }
16333       else
16334         emit_insn ((mode == DImode
16335                     ? gen_x86_shift_adj_2
16336                     : gen_x86_64_shift_adj_2) (low[0], high[0], operands[2]));
16337     }
16338 }
16339
16340 /* Predict just emitted jump instruction to be taken with probability PROB.  */
16341 static void
16342 predict_jump (int prob)
16343 {
16344   rtx insn = get_last_insn ();
16345   gcc_assert (JUMP_P (insn));
16346   REG_NOTES (insn)
16347     = gen_rtx_EXPR_LIST (REG_BR_PROB,
16348                          GEN_INT (prob),
16349                          REG_NOTES (insn));
16350 }
16351
16352 /* Helper function for the string operations below.  Dest VARIABLE whether
16353    it is aligned to VALUE bytes.  If true, jump to the label.  */
16354 static rtx
16355 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
16356 {
16357   rtx label = gen_label_rtx ();
16358   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
16359   if (GET_MODE (variable) == DImode)
16360     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
16361   else
16362     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
16363   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
16364                            1, label);
16365   if (epilogue)
16366     predict_jump (REG_BR_PROB_BASE * 50 / 100);
16367   else
16368     predict_jump (REG_BR_PROB_BASE * 90 / 100);
16369   return label;
16370 }
16371
16372 /* Adjust COUNTER by the VALUE.  */
16373 static void
16374 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
16375 {
16376   if (GET_MODE (countreg) == DImode)
16377     emit_insn (gen_adddi3 (countreg, countreg, GEN_INT (-value)));
16378   else
16379     emit_insn (gen_addsi3 (countreg, countreg, GEN_INT (-value)));
16380 }
16381
16382 /* Zero extend possibly SImode EXP to Pmode register.  */
16383 rtx
16384 ix86_zero_extend_to_Pmode (rtx exp)
16385 {
16386   rtx r;
16387   if (GET_MODE (exp) == VOIDmode)
16388     return force_reg (Pmode, exp);
16389   if (GET_MODE (exp) == Pmode)
16390     return copy_to_mode_reg (Pmode, exp);
16391   r = gen_reg_rtx (Pmode);
16392   emit_insn (gen_zero_extendsidi2 (r, exp));
16393   return r;
16394 }
16395
16396 /* Divide COUNTREG by SCALE.  */
16397 static rtx
16398 scale_counter (rtx countreg, int scale)
16399 {
16400   rtx sc;
16401   rtx piece_size_mask;
16402
16403   if (scale == 1)
16404     return countreg;
16405   if (CONST_INT_P (countreg))
16406     return GEN_INT (INTVAL (countreg) / scale);
16407   gcc_assert (REG_P (countreg));
16408
16409   piece_size_mask = GEN_INT (scale - 1);
16410   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
16411                             GEN_INT (exact_log2 (scale)),
16412                             NULL, 1, OPTAB_DIRECT);
16413   return sc;
16414 }
16415
16416 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
16417    DImode for constant loop counts.  */
16418
16419 static enum machine_mode
16420 counter_mode (rtx count_exp)
16421 {
16422   if (GET_MODE (count_exp) != VOIDmode)
16423     return GET_MODE (count_exp);
16424   if (GET_CODE (count_exp) != CONST_INT)
16425     return Pmode;
16426   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
16427     return DImode;
16428   return SImode;
16429 }
16430
16431 /* When SRCPTR is non-NULL, output simple loop to move memory
16432    pointer to SRCPTR to DESTPTR via chunks of MODE unrolled UNROLL times,
16433    overall size is COUNT specified in bytes.  When SRCPTR is NULL, output the
16434    equivalent loop to set memory by VALUE (supposed to be in MODE).
16435
16436    The size is rounded down to whole number of chunk size moved at once.
16437    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
16438
16439
16440 static void
16441 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
16442                                rtx destptr, rtx srcptr, rtx value,
16443                                rtx count, enum machine_mode mode, int unroll,
16444                                int expected_size)
16445 {
16446   rtx out_label, top_label, iter, tmp;
16447   enum machine_mode iter_mode = counter_mode (count);
16448   rtx piece_size = GEN_INT (GET_MODE_SIZE (mode) * unroll);
16449   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
16450   rtx size;
16451   rtx x_addr;
16452   rtx y_addr;
16453   int i;
16454
16455   top_label = gen_label_rtx ();
16456   out_label = gen_label_rtx ();
16457   iter = gen_reg_rtx (iter_mode);
16458
16459   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
16460                               NULL, 1, OPTAB_DIRECT);
16461   /* Those two should combine.  */
16462   if (piece_size == const1_rtx)
16463     {
16464       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
16465                                true, out_label);
16466       predict_jump (REG_BR_PROB_BASE * 10 / 100);
16467     }
16468   emit_move_insn (iter, const0_rtx);
16469
16470   emit_label (top_label);
16471
16472   tmp = convert_modes (Pmode, iter_mode, iter, true);
16473   x_addr = gen_rtx_PLUS (Pmode, destptr, tmp);
16474   destmem = change_address (destmem, mode, x_addr);
16475
16476   if (srcmem)
16477     {
16478       y_addr = gen_rtx_PLUS (Pmode, srcptr, copy_rtx (tmp));
16479       srcmem = change_address (srcmem, mode, y_addr);
16480
16481       /* When unrolling for chips that reorder memory reads and writes,
16482          we can save registers by using single temporary.
16483          Also using 4 temporaries is overkill in 32bit mode.  */
16484       if (!TARGET_64BIT && 0)
16485         {
16486           for (i = 0; i < unroll; i++)
16487             {
16488               if (i)
16489                 {
16490                   destmem =
16491                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16492                   srcmem =
16493                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16494                 }
16495               emit_move_insn (destmem, srcmem);
16496             }
16497         }
16498       else
16499         {
16500           rtx tmpreg[4];
16501           gcc_assert (unroll <= 4);
16502           for (i = 0; i < unroll; i++)
16503             {
16504               tmpreg[i] = gen_reg_rtx (mode);
16505               if (i)
16506                 {
16507                   srcmem =
16508                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16509                 }
16510               emit_move_insn (tmpreg[i], srcmem);
16511             }
16512           for (i = 0; i < unroll; i++)
16513             {
16514               if (i)
16515                 {
16516                   destmem =
16517                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16518                 }
16519               emit_move_insn (destmem, tmpreg[i]);
16520             }
16521         }
16522     }
16523   else
16524     for (i = 0; i < unroll; i++)
16525       {
16526         if (i)
16527           destmem =
16528             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16529         emit_move_insn (destmem, value);
16530       }
16531
16532   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
16533                              true, OPTAB_LIB_WIDEN);
16534   if (tmp != iter)
16535     emit_move_insn (iter, tmp);
16536
16537   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
16538                            true, top_label);
16539   if (expected_size != -1)
16540     {
16541       expected_size /= GET_MODE_SIZE (mode) * unroll;
16542       if (expected_size == 0)
16543         predict_jump (0);
16544       else if (expected_size > REG_BR_PROB_BASE)
16545         predict_jump (REG_BR_PROB_BASE - 1);
16546       else
16547         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
16548     }
16549   else
16550     predict_jump (REG_BR_PROB_BASE * 80 / 100);
16551   iter = ix86_zero_extend_to_Pmode (iter);
16552   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
16553                              true, OPTAB_LIB_WIDEN);
16554   if (tmp != destptr)
16555     emit_move_insn (destptr, tmp);
16556   if (srcptr)
16557     {
16558       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
16559                                  true, OPTAB_LIB_WIDEN);
16560       if (tmp != srcptr)
16561         emit_move_insn (srcptr, tmp);
16562     }
16563   emit_label (out_label);
16564 }
16565
16566 /* Output "rep; mov" instruction.
16567    Arguments have same meaning as for previous function */
16568 static void
16569 expand_movmem_via_rep_mov (rtx destmem, rtx srcmem,
16570                            rtx destptr, rtx srcptr,
16571                            rtx count,
16572                            enum machine_mode mode)
16573 {
16574   rtx destexp;
16575   rtx srcexp;
16576   rtx countreg;
16577
16578   /* If the size is known, it is shorter to use rep movs.  */
16579   if (mode == QImode && CONST_INT_P (count)
16580       && !(INTVAL (count) & 3))
16581     mode = SImode;
16582
16583   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16584     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16585   if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
16586     srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
16587   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16588   if (mode != QImode)
16589     {
16590       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16591                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16592       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16593       srcexp = gen_rtx_ASHIFT (Pmode, countreg,
16594                                GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16595       srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
16596     }
16597   else
16598     {
16599       destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16600       srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
16601     }
16602   emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
16603                           destexp, srcexp));
16604 }
16605
16606 /* Output "rep; stos" instruction.
16607    Arguments have same meaning as for previous function */
16608 static void
16609 expand_setmem_via_rep_stos (rtx destmem, rtx destptr, rtx value,
16610                             rtx count,
16611                             enum machine_mode mode)
16612 {
16613   rtx destexp;
16614   rtx countreg;
16615
16616   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16617     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16618   value = force_reg (mode, gen_lowpart (mode, value));
16619   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16620   if (mode != QImode)
16621     {
16622       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16623                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16624       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16625     }
16626   else
16627     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16628   emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
16629 }
16630
16631 static void
16632 emit_strmov (rtx destmem, rtx srcmem,
16633              rtx destptr, rtx srcptr, enum machine_mode mode, int offset)
16634 {
16635   rtx src = adjust_automodify_address_nv (srcmem, mode, srcptr, offset);
16636   rtx dest = adjust_automodify_address_nv (destmem, mode, destptr, offset);
16637   emit_insn (gen_strmov (destptr, dest, srcptr, src));
16638 }
16639
16640 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
16641 static void
16642 expand_movmem_epilogue (rtx destmem, rtx srcmem,
16643                         rtx destptr, rtx srcptr, rtx count, int max_size)
16644 {
16645   rtx src, dest;
16646   if (CONST_INT_P (count))
16647     {
16648       HOST_WIDE_INT countval = INTVAL (count);
16649       int offset = 0;
16650
16651       if ((countval & 0x10) && max_size > 16)
16652         {
16653           if (TARGET_64BIT)
16654             {
16655               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16656               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset + 8);
16657             }
16658           else
16659             gcc_unreachable ();
16660           offset += 16;
16661         }
16662       if ((countval & 0x08) && max_size > 8)
16663         {
16664           if (TARGET_64BIT)
16665             emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16666           else
16667             {
16668               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16669               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset + 4);
16670             }
16671           offset += 8;
16672         }
16673       if ((countval & 0x04) && max_size > 4)
16674         {
16675           emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16676           offset += 4;
16677         }
16678       if ((countval & 0x02) && max_size > 2)
16679         {
16680           emit_strmov (destmem, srcmem, destptr, srcptr, HImode, offset);
16681           offset += 2;
16682         }
16683       if ((countval & 0x01) && max_size > 1)
16684         {
16685           emit_strmov (destmem, srcmem, destptr, srcptr, QImode, offset);
16686           offset += 1;
16687         }
16688       return;
16689     }
16690   if (max_size > 8)
16691     {
16692       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
16693                                     count, 1, OPTAB_DIRECT);
16694       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
16695                                      count, QImode, 1, 4);
16696       return;
16697     }
16698
16699   /* When there are stringops, we can cheaply increase dest and src pointers.
16700      Otherwise we save code size by maintaining offset (zero is readily
16701      available from preceding rep operation) and using x86 addressing modes.
16702    */
16703   if (TARGET_SINGLE_STRINGOP)
16704     {
16705       if (max_size > 4)
16706         {
16707           rtx label = ix86_expand_aligntest (count, 4, true);
16708           src = change_address (srcmem, SImode, srcptr);
16709           dest = change_address (destmem, SImode, destptr);
16710           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16711           emit_label (label);
16712           LABEL_NUSES (label) = 1;
16713         }
16714       if (max_size > 2)
16715         {
16716           rtx label = ix86_expand_aligntest (count, 2, true);
16717           src = change_address (srcmem, HImode, srcptr);
16718           dest = change_address (destmem, HImode, destptr);
16719           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16720           emit_label (label);
16721           LABEL_NUSES (label) = 1;
16722         }
16723       if (max_size > 1)
16724         {
16725           rtx label = ix86_expand_aligntest (count, 1, true);
16726           src = change_address (srcmem, QImode, srcptr);
16727           dest = change_address (destmem, QImode, destptr);
16728           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16729           emit_label (label);
16730           LABEL_NUSES (label) = 1;
16731         }
16732     }
16733   else
16734     {
16735       rtx offset = force_reg (Pmode, const0_rtx);
16736       rtx tmp;
16737
16738       if (max_size > 4)
16739         {
16740           rtx label = ix86_expand_aligntest (count, 4, true);
16741           src = change_address (srcmem, SImode, srcptr);
16742           dest = change_address (destmem, SImode, destptr);
16743           emit_move_insn (dest, src);
16744           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
16745                                      true, OPTAB_LIB_WIDEN);
16746           if (tmp != offset)
16747             emit_move_insn (offset, tmp);
16748           emit_label (label);
16749           LABEL_NUSES (label) = 1;
16750         }
16751       if (max_size > 2)
16752         {
16753           rtx label = ix86_expand_aligntest (count, 2, true);
16754           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
16755           src = change_address (srcmem, HImode, tmp);
16756           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
16757           dest = change_address (destmem, HImode, tmp);
16758           emit_move_insn (dest, src);
16759           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
16760                                      true, OPTAB_LIB_WIDEN);
16761           if (tmp != offset)
16762             emit_move_insn (offset, tmp);
16763           emit_label (label);
16764           LABEL_NUSES (label) = 1;
16765         }
16766       if (max_size > 1)
16767         {
16768           rtx label = ix86_expand_aligntest (count, 1, true);
16769           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
16770           src = change_address (srcmem, QImode, tmp);
16771           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
16772           dest = change_address (destmem, QImode, tmp);
16773           emit_move_insn (dest, src);
16774           emit_label (label);
16775           LABEL_NUSES (label) = 1;
16776         }
16777     }
16778 }
16779
16780 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
16781 static void
16782 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
16783                                  rtx count, int max_size)
16784 {
16785   count =
16786     expand_simple_binop (counter_mode (count), AND, count,
16787                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
16788   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
16789                                  gen_lowpart (QImode, value), count, QImode,
16790                                  1, max_size / 2);
16791 }
16792
16793 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
16794 static void
16795 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx count, int max_size)
16796 {
16797   rtx dest;
16798
16799   if (CONST_INT_P (count))
16800     {
16801       HOST_WIDE_INT countval = INTVAL (count);
16802       int offset = 0;
16803
16804       if ((countval & 0x10) && max_size > 16)
16805         {
16806           if (TARGET_64BIT)
16807             {
16808               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
16809               emit_insn (gen_strset (destptr, dest, value));
16810               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset + 8);
16811               emit_insn (gen_strset (destptr, dest, value));
16812             }
16813           else
16814             gcc_unreachable ();
16815           offset += 16;
16816         }
16817       if ((countval & 0x08) && max_size > 8)
16818         {
16819           if (TARGET_64BIT)
16820             {
16821               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
16822               emit_insn (gen_strset (destptr, dest, value));
16823             }
16824           else
16825             {
16826               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
16827               emit_insn (gen_strset (destptr, dest, value));
16828               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset + 4);
16829               emit_insn (gen_strset (destptr, dest, value));
16830             }
16831           offset += 8;
16832         }
16833       if ((countval & 0x04) && max_size > 4)
16834         {
16835           dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
16836           emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
16837           offset += 4;
16838         }
16839       if ((countval & 0x02) && max_size > 2)
16840         {
16841           dest = adjust_automodify_address_nv (destmem, HImode, destptr, offset);
16842           emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
16843           offset += 2;
16844         }
16845       if ((countval & 0x01) && max_size > 1)
16846         {
16847           dest = adjust_automodify_address_nv (destmem, QImode, destptr, offset);
16848           emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
16849           offset += 1;
16850         }
16851       return;
16852     }
16853   if (max_size > 32)
16854     {
16855       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
16856       return;
16857     }
16858   if (max_size > 16)
16859     {
16860       rtx label = ix86_expand_aligntest (count, 16, true);
16861       if (TARGET_64BIT)
16862         {
16863           dest = change_address (destmem, DImode, destptr);
16864           emit_insn (gen_strset (destptr, dest, value));
16865           emit_insn (gen_strset (destptr, dest, value));
16866         }
16867       else
16868         {
16869           dest = change_address (destmem, SImode, destptr);
16870           emit_insn (gen_strset (destptr, dest, value));
16871           emit_insn (gen_strset (destptr, dest, value));
16872           emit_insn (gen_strset (destptr, dest, value));
16873           emit_insn (gen_strset (destptr, dest, value));
16874         }
16875       emit_label (label);
16876       LABEL_NUSES (label) = 1;
16877     }
16878   if (max_size > 8)
16879     {
16880       rtx label = ix86_expand_aligntest (count, 8, true);
16881       if (TARGET_64BIT)
16882         {
16883           dest = change_address (destmem, DImode, destptr);
16884           emit_insn (gen_strset (destptr, dest, value));
16885         }
16886       else
16887         {
16888           dest = change_address (destmem, SImode, destptr);
16889           emit_insn (gen_strset (destptr, dest, value));
16890           emit_insn (gen_strset (destptr, dest, value));
16891         }
16892       emit_label (label);
16893       LABEL_NUSES (label) = 1;
16894     }
16895   if (max_size > 4)
16896     {
16897       rtx label = ix86_expand_aligntest (count, 4, true);
16898       dest = change_address (destmem, SImode, destptr);
16899       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
16900       emit_label (label);
16901       LABEL_NUSES (label) = 1;
16902     }
16903   if (max_size > 2)
16904     {
16905       rtx label = ix86_expand_aligntest (count, 2, true);
16906       dest = change_address (destmem, HImode, destptr);
16907       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
16908       emit_label (label);
16909       LABEL_NUSES (label) = 1;
16910     }
16911   if (max_size > 1)
16912     {
16913       rtx label = ix86_expand_aligntest (count, 1, true);
16914       dest = change_address (destmem, QImode, destptr);
16915       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
16916       emit_label (label);
16917       LABEL_NUSES (label) = 1;
16918     }
16919 }
16920
16921 /* Copy enough from DEST to SRC to align DEST known to by aligned by ALIGN to
16922    DESIRED_ALIGNMENT.  */
16923 static void
16924 expand_movmem_prologue (rtx destmem, rtx srcmem,
16925                         rtx destptr, rtx srcptr, rtx count,
16926                         int align, int desired_alignment)
16927 {
16928   if (align <= 1 && desired_alignment > 1)
16929     {
16930       rtx label = ix86_expand_aligntest (destptr, 1, false);
16931       srcmem = change_address (srcmem, QImode, srcptr);
16932       destmem = change_address (destmem, QImode, destptr);
16933       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16934       ix86_adjust_counter (count, 1);
16935       emit_label (label);
16936       LABEL_NUSES (label) = 1;
16937     }
16938   if (align <= 2 && desired_alignment > 2)
16939     {
16940       rtx label = ix86_expand_aligntest (destptr, 2, false);
16941       srcmem = change_address (srcmem, HImode, srcptr);
16942       destmem = change_address (destmem, HImode, destptr);
16943       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16944       ix86_adjust_counter (count, 2);
16945       emit_label (label);
16946       LABEL_NUSES (label) = 1;
16947     }
16948   if (align <= 4 && desired_alignment > 4)
16949     {
16950       rtx label = ix86_expand_aligntest (destptr, 4, false);
16951       srcmem = change_address (srcmem, SImode, srcptr);
16952       destmem = change_address (destmem, SImode, destptr);
16953       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16954       ix86_adjust_counter (count, 4);
16955       emit_label (label);
16956       LABEL_NUSES (label) = 1;
16957     }
16958   gcc_assert (desired_alignment <= 8);
16959 }
16960
16961 /* Set enough from DEST to align DEST known to by aligned by ALIGN to
16962    DESIRED_ALIGNMENT.  */
16963 static void
16964 expand_setmem_prologue (rtx destmem, rtx destptr, rtx value, rtx count,
16965                         int align, int desired_alignment)
16966 {
16967   if (align <= 1 && desired_alignment > 1)
16968     {
16969       rtx label = ix86_expand_aligntest (destptr, 1, false);
16970       destmem = change_address (destmem, QImode, destptr);
16971       emit_insn (gen_strset (destptr, destmem, gen_lowpart (QImode, value)));
16972       ix86_adjust_counter (count, 1);
16973       emit_label (label);
16974       LABEL_NUSES (label) = 1;
16975     }
16976   if (align <= 2 && desired_alignment > 2)
16977     {
16978       rtx label = ix86_expand_aligntest (destptr, 2, false);
16979       destmem = change_address (destmem, HImode, destptr);
16980       emit_insn (gen_strset (destptr, destmem, gen_lowpart (HImode, value)));
16981       ix86_adjust_counter (count, 2);
16982       emit_label (label);
16983       LABEL_NUSES (label) = 1;
16984     }
16985   if (align <= 4 && desired_alignment > 4)
16986     {
16987       rtx label = ix86_expand_aligntest (destptr, 4, false);
16988       destmem = change_address (destmem, SImode, destptr);
16989       emit_insn (gen_strset (destptr, destmem, gen_lowpart (SImode, value)));
16990       ix86_adjust_counter (count, 4);
16991       emit_label (label);
16992       LABEL_NUSES (label) = 1;
16993     }
16994   gcc_assert (desired_alignment <= 8);
16995 }
16996
16997 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
16998 static enum stringop_alg
16999 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, bool memset,
17000             int *dynamic_check)
17001 {
17002   const struct stringop_algs * algs;
17003   bool optimize_for_speed;
17004   /* Algorithms using the rep prefix want at least edi and ecx;
17005      additionally, memset wants eax and memcpy wants esi.  Don't
17006      consider such algorithms if the user has appropriated those
17007      registers for their own purposes.  */
17008   bool rep_prefix_usable = !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
17009                              || (memset
17010                                  ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
17011
17012 #define ALG_USABLE_P(alg) (rep_prefix_usable                    \
17013                            || (alg != rep_prefix_1_byte         \
17014                                && alg != rep_prefix_4_byte      \
17015                                && alg != rep_prefix_8_byte))
17016   const struct processor_costs *cost;
17017   
17018   /* Even if the string operation call is cold, we still might spend a lot
17019      of time processing large blocks.  */
17020   if (optimize_function_for_size_p (cfun)
17021       || (optimize_insn_for_size_p ()
17022           && expected_size != -1 && expected_size < 256))
17023     optimize_for_speed = false;
17024   else
17025     optimize_for_speed = true;
17026
17027   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
17028
17029   *dynamic_check = -1;
17030   if (memset)
17031     algs = &cost->memset[TARGET_64BIT != 0];
17032   else
17033     algs = &cost->memcpy[TARGET_64BIT != 0];
17034   if (stringop_alg != no_stringop && ALG_USABLE_P (stringop_alg))
17035     return stringop_alg;
17036   /* rep; movq or rep; movl is the smallest variant.  */
17037   else if (!optimize_for_speed)
17038     {
17039       if (!count || (count & 3))
17040         return rep_prefix_usable ? rep_prefix_1_byte : loop_1_byte;
17041       else
17042         return rep_prefix_usable ? rep_prefix_4_byte : loop;
17043     }
17044   /* Very tiny blocks are best handled via the loop, REP is expensive to setup.
17045    */
17046   else if (expected_size != -1 && expected_size < 4)
17047     return loop_1_byte;
17048   else if (expected_size != -1)
17049     {
17050       unsigned int i;
17051       enum stringop_alg alg = libcall;
17052       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17053         {
17054           /* We get here if the algorithms that were not libcall-based
17055              were rep-prefix based and we are unable to use rep prefixes
17056              based on global register usage.  Break out of the loop and
17057              use the heuristic below.  */
17058           if (algs->size[i].max == 0)
17059             break;
17060           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
17061             {
17062               enum stringop_alg candidate = algs->size[i].alg;
17063
17064               if (candidate != libcall && ALG_USABLE_P (candidate))
17065                 alg = candidate;
17066               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
17067                  last non-libcall inline algorithm.  */
17068               if (TARGET_INLINE_ALL_STRINGOPS)
17069                 {
17070                   /* When the current size is best to be copied by a libcall,
17071                      but we are still forced to inline, run the heuristic below
17072                      that will pick code for medium sized blocks.  */
17073                   if (alg != libcall)
17074                     return alg;
17075                   break;
17076                 }
17077               else if (ALG_USABLE_P (candidate))
17078                 return candidate;
17079             }
17080         }
17081       gcc_assert (TARGET_INLINE_ALL_STRINGOPS || !rep_prefix_usable);
17082     }
17083   /* When asked to inline the call anyway, try to pick meaningful choice.
17084      We look for maximal size of block that is faster to copy by hand and
17085      take blocks of at most of that size guessing that average size will
17086      be roughly half of the block.
17087
17088      If this turns out to be bad, we might simply specify the preferred
17089      choice in ix86_costs.  */
17090   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17091       && (algs->unknown_size == libcall || !ALG_USABLE_P (algs->unknown_size)))
17092     {
17093       int max = -1;
17094       enum stringop_alg alg;
17095       int i;
17096       bool any_alg_usable_p = true;
17097
17098       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17099         {
17100           enum stringop_alg candidate = algs->size[i].alg;
17101           any_alg_usable_p = any_alg_usable_p && ALG_USABLE_P (candidate);
17102
17103           if (candidate != libcall && candidate
17104               && ALG_USABLE_P (candidate))
17105               max = algs->size[i].max;
17106         }
17107       /* If there aren't any usable algorithms, then recursing on
17108          smaller sizes isn't going to find anything.  Just return the
17109          simple byte-at-a-time copy loop.  */
17110       if (!any_alg_usable_p)
17111         {
17112           /* Pick something reasonable.  */
17113           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17114             *dynamic_check = 128;
17115           return loop_1_byte;
17116         }
17117       if (max == -1)
17118         max = 4096;
17119       alg = decide_alg (count, max / 2, memset, dynamic_check);
17120       gcc_assert (*dynamic_check == -1);
17121       gcc_assert (alg != libcall);
17122       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17123         *dynamic_check = max;
17124       return alg;
17125     }
17126   return ALG_USABLE_P (algs->unknown_size) ? algs->unknown_size : libcall;
17127 #undef ALG_USABLE_P
17128 }
17129
17130 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
17131    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
17132 static int
17133 decide_alignment (int align,
17134                   enum stringop_alg alg,
17135                   int expected_size)
17136 {
17137   int desired_align = 0;
17138   switch (alg)
17139     {
17140       case no_stringop:
17141         gcc_unreachable ();
17142       case loop:
17143       case unrolled_loop:
17144         desired_align = GET_MODE_SIZE (Pmode);
17145         break;
17146       case rep_prefix_8_byte:
17147         desired_align = 8;
17148         break;
17149       case rep_prefix_4_byte:
17150         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17151            copying whole cacheline at once.  */
17152         if (TARGET_PENTIUMPRO)
17153           desired_align = 8;
17154         else
17155           desired_align = 4;
17156         break;
17157       case rep_prefix_1_byte:
17158         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17159            copying whole cacheline at once.  */
17160         if (TARGET_PENTIUMPRO)
17161           desired_align = 8;
17162         else
17163           desired_align = 1;
17164         break;
17165       case loop_1_byte:
17166         desired_align = 1;
17167         break;
17168       case libcall:
17169         return 0;
17170     }
17171
17172   if (optimize_size)
17173     desired_align = 1;
17174   if (desired_align < align)
17175     desired_align = align;
17176   if (expected_size != -1 && expected_size < 4)
17177     desired_align = align;
17178   return desired_align;
17179 }
17180
17181 /* Return the smallest power of 2 greater than VAL.  */
17182 static int
17183 smallest_pow2_greater_than (int val)
17184 {
17185   int ret = 1;
17186   while (ret <= val)
17187     ret <<= 1;
17188   return ret;
17189 }
17190
17191 /* Expand string move (memcpy) operation.  Use i386 string operations when
17192    profitable.  expand_setmem contains similar code.  The code depends upon
17193    architecture, block size and alignment, but always has the same
17194    overall structure:
17195
17196    1) Prologue guard: Conditional that jumps up to epilogues for small
17197       blocks that can be handled by epilogue alone.  This is faster but
17198       also needed for correctness, since prologue assume the block is larger
17199       than the desired alignment.
17200
17201       Optional dynamic check for size and libcall for large
17202       blocks is emitted here too, with -minline-stringops-dynamically.
17203
17204    2) Prologue: copy first few bytes in order to get destination aligned
17205       to DESIRED_ALIGN.  It is emitted only when ALIGN is less than
17206       DESIRED_ALIGN and and up to DESIRED_ALIGN - ALIGN bytes can be copied.
17207       We emit either a jump tree on power of two sized blocks, or a byte loop.
17208
17209    3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
17210       with specified algorithm.
17211
17212    4) Epilogue: code copying tail of the block that is too small to be
17213       handled by main body (or up to size guarded by prologue guard).  */
17214
17215 int
17216 ix86_expand_movmem (rtx dst, rtx src, rtx count_exp, rtx align_exp,
17217                     rtx expected_align_exp, rtx expected_size_exp)
17218 {
17219   rtx destreg;
17220   rtx srcreg;
17221   rtx label = NULL;
17222   rtx tmp;
17223   rtx jump_around_label = NULL;
17224   HOST_WIDE_INT align = 1;
17225   unsigned HOST_WIDE_INT count = 0;
17226   HOST_WIDE_INT expected_size = -1;
17227   int size_needed = 0, epilogue_size_needed;
17228   int desired_align = 0;
17229   enum stringop_alg alg;
17230   int dynamic_check;
17231   bool need_zero_guard = false;
17232
17233   if (CONST_INT_P (align_exp))
17234     align = INTVAL (align_exp);
17235   /* i386 can do misaligned access on reasonably increased cost.  */
17236   if (CONST_INT_P (expected_align_exp)
17237       && INTVAL (expected_align_exp) > align)
17238     align = INTVAL (expected_align_exp);
17239   if (CONST_INT_P (count_exp))
17240     count = expected_size = INTVAL (count_exp);
17241   if (CONST_INT_P (expected_size_exp) && count == 0)
17242     expected_size = INTVAL (expected_size_exp);
17243
17244   /* Make sure we don't need to care about overflow later on.  */
17245   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17246     return 0;
17247
17248   /* Step 0: Decide on preferred algorithm, desired alignment and
17249      size of chunks to be copied by main loop.  */
17250
17251   alg = decide_alg (count, expected_size, false, &dynamic_check);
17252   desired_align = decide_alignment (align, alg, expected_size);
17253
17254   if (!TARGET_ALIGN_STRINGOPS)
17255     align = desired_align;
17256
17257   if (alg == libcall)
17258     return 0;
17259   gcc_assert (alg != no_stringop);
17260   if (!count)
17261     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
17262   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17263   srcreg = copy_to_mode_reg (Pmode, XEXP (src, 0));
17264   switch (alg)
17265     {
17266     case libcall:
17267     case no_stringop:
17268       gcc_unreachable ();
17269     case loop:
17270       need_zero_guard = true;
17271       size_needed = GET_MODE_SIZE (Pmode);
17272       break;
17273     case unrolled_loop:
17274       need_zero_guard = true;
17275       size_needed = GET_MODE_SIZE (Pmode) * (TARGET_64BIT ? 4 : 2);
17276       break;
17277     case rep_prefix_8_byte:
17278       size_needed = 8;
17279       break;
17280     case rep_prefix_4_byte:
17281       size_needed = 4;
17282       break;
17283     case rep_prefix_1_byte:
17284       size_needed = 1;
17285       break;
17286     case loop_1_byte:
17287       need_zero_guard = true;
17288       size_needed = 1;
17289       break;
17290     }
17291
17292   epilogue_size_needed = size_needed;
17293
17294   /* Step 1: Prologue guard.  */
17295
17296   /* Alignment code needs count to be in register.  */
17297   if (CONST_INT_P (count_exp) && desired_align > align)
17298     count_exp = force_reg (counter_mode (count_exp), count_exp);
17299   gcc_assert (desired_align >= 1 && align >= 1);
17300
17301   /* Ensure that alignment prologue won't copy past end of block.  */
17302   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
17303     {
17304       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
17305       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
17306          Make sure it is power of 2.  */
17307       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
17308
17309       if (CONST_INT_P (count_exp))
17310         {
17311           if (UINTVAL (count_exp) < (unsigned HOST_WIDE_INT)epilogue_size_needed)
17312             goto epilogue;
17313         }
17314       else
17315         {
17316           label = gen_label_rtx ();
17317           emit_cmp_and_jump_insns (count_exp,
17318                                    GEN_INT (epilogue_size_needed),
17319                                    LTU, 0, counter_mode (count_exp), 1, label);
17320           if (expected_size == -1 || expected_size < epilogue_size_needed)
17321             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17322           else
17323             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17324         }
17325     }
17326
17327   /* Emit code to decide on runtime whether library call or inline should be
17328      used.  */
17329   if (dynamic_check != -1)
17330     {
17331       if (CONST_INT_P (count_exp))
17332         {
17333           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
17334             {
17335               emit_block_move_via_libcall (dst, src, count_exp, false);
17336               count_exp = const0_rtx;
17337               goto epilogue;
17338             }
17339         }
17340       else
17341         {
17342           rtx hot_label = gen_label_rtx ();
17343           jump_around_label = gen_label_rtx ();
17344           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
17345                                    LEU, 0, GET_MODE (count_exp), 1, hot_label);
17346           predict_jump (REG_BR_PROB_BASE * 90 / 100);
17347           emit_block_move_via_libcall (dst, src, count_exp, false);
17348           emit_jump (jump_around_label);
17349           emit_label (hot_label);
17350         }
17351     }
17352
17353   /* Step 2: Alignment prologue.  */
17354
17355   if (desired_align > align)
17356     {
17357       /* Except for the first move in epilogue, we no longer know
17358          constant offset in aliasing info.  It don't seems to worth
17359          the pain to maintain it for the first move, so throw away
17360          the info early.  */
17361       src = change_address (src, BLKmode, srcreg);
17362       dst = change_address (dst, BLKmode, destreg);
17363       expand_movmem_prologue (dst, src, destreg, srcreg, count_exp, align,
17364                               desired_align);
17365       if (need_zero_guard && !count)
17366         {
17367           /* It is possible that we copied enough so the main loop will not
17368              execute.  */
17369           emit_cmp_and_jump_insns (count_exp,
17370                                    GEN_INT (size_needed),
17371                                    LTU, 0, counter_mode (count_exp), 1, label);
17372           if (expected_size == -1
17373               || expected_size < (desired_align - align) / 2 + size_needed)
17374             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17375           else
17376             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17377         }
17378     }
17379   if (label && size_needed == 1)
17380     {
17381       emit_label (label);
17382       LABEL_NUSES (label) = 1;
17383       label = NULL;
17384     }
17385
17386   /* Step 3: Main loop.  */
17387
17388   switch (alg)
17389     {
17390     case libcall:
17391     case no_stringop:
17392       gcc_unreachable ();
17393     case loop_1_byte:
17394       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17395                                      count_exp, QImode, 1, expected_size);
17396       break;
17397     case loop:
17398       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17399                                      count_exp, Pmode, 1, expected_size);
17400       break;
17401     case unrolled_loop:
17402       /* Unroll only by factor of 2 in 32bit mode, since we don't have enough
17403          registers for 4 temporaries anyway.  */
17404       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17405                                      count_exp, Pmode, TARGET_64BIT ? 4 : 2,
17406                                      expected_size);
17407       break;
17408     case rep_prefix_8_byte:
17409       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17410                                  DImode);
17411       break;
17412     case rep_prefix_4_byte:
17413       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17414                                  SImode);
17415       break;
17416     case rep_prefix_1_byte:
17417       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17418                                  QImode);
17419       break;
17420     }
17421   /* Adjust properly the offset of src and dest memory for aliasing.  */
17422   if (CONST_INT_P (count_exp))
17423     {
17424       src = adjust_automodify_address_nv (src, BLKmode, srcreg,
17425                                           (count / size_needed) * size_needed);
17426       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
17427                                           (count / size_needed) * size_needed);
17428     }
17429   else
17430     {
17431       src = change_address (src, BLKmode, srcreg);
17432       dst = change_address (dst, BLKmode, destreg);
17433     }
17434
17435   /* Step 4: Epilogue to copy the remaining bytes.  */
17436  epilogue:
17437   if (label)
17438     {
17439       /* When the main loop is done, COUNT_EXP might hold original count,
17440          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
17441          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
17442          bytes. Compensate if needed.  */
17443
17444       if (size_needed < epilogue_size_needed)
17445         {
17446           tmp =
17447             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
17448                                  GEN_INT (size_needed - 1), count_exp, 1,
17449                                  OPTAB_DIRECT);
17450           if (tmp != count_exp)
17451             emit_move_insn (count_exp, tmp);
17452         }
17453       emit_label (label);
17454       LABEL_NUSES (label) = 1;
17455     }
17456
17457   if (count_exp != const0_rtx && epilogue_size_needed > 1)
17458     expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
17459                             epilogue_size_needed);
17460   if (jump_around_label)
17461     emit_label (jump_around_label);
17462   return 1;
17463 }
17464
17465 /* Helper function for memcpy.  For QImode value 0xXY produce
17466    0xXYXYXYXY of wide specified by MODE.  This is essentially
17467    a * 0x10101010, but we can do slightly better than
17468    synth_mult by unwinding the sequence by hand on CPUs with
17469    slow multiply.  */
17470 static rtx
17471 promote_duplicated_reg (enum machine_mode mode, rtx val)
17472 {
17473   enum machine_mode valmode = GET_MODE (val);
17474   rtx tmp;
17475   int nops = mode == DImode ? 3 : 2;
17476
17477   gcc_assert (mode == SImode || mode == DImode);
17478   if (val == const0_rtx)
17479     return copy_to_mode_reg (mode, const0_rtx);
17480   if (CONST_INT_P (val))
17481     {
17482       HOST_WIDE_INT v = INTVAL (val) & 255;
17483
17484       v |= v << 8;
17485       v |= v << 16;
17486       if (mode == DImode)
17487         v |= (v << 16) << 16;
17488       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
17489     }
17490
17491   if (valmode == VOIDmode)
17492     valmode = QImode;
17493   if (valmode != QImode)
17494     val = gen_lowpart (QImode, val);
17495   if (mode == QImode)
17496     return val;
17497   if (!TARGET_PARTIAL_REG_STALL)
17498     nops--;
17499   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
17500       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
17501       <= (ix86_cost->shift_const + ix86_cost->add) * nops
17502           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
17503     {
17504       rtx reg = convert_modes (mode, QImode, val, true);
17505       tmp = promote_duplicated_reg (mode, const1_rtx);
17506       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
17507                                   OPTAB_DIRECT);
17508     }
17509   else
17510     {
17511       rtx reg = convert_modes (mode, QImode, val, true);
17512
17513       if (!TARGET_PARTIAL_REG_STALL)
17514         if (mode == SImode)
17515           emit_insn (gen_movsi_insv_1 (reg, reg));
17516         else
17517           emit_insn (gen_movdi_insv_1_rex64 (reg, reg));
17518       else
17519         {
17520           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
17521                                      NULL, 1, OPTAB_DIRECT);
17522           reg =
17523             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17524         }
17525       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
17526                                  NULL, 1, OPTAB_DIRECT);
17527       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17528       if (mode == SImode)
17529         return reg;
17530       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
17531                                  NULL, 1, OPTAB_DIRECT);
17532       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17533       return reg;
17534     }
17535 }
17536
17537 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
17538    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
17539    alignment from ALIGN to DESIRED_ALIGN.  */
17540 static rtx
17541 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align, int align)
17542 {
17543   rtx promoted_val;
17544
17545   if (TARGET_64BIT
17546       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
17547     promoted_val = promote_duplicated_reg (DImode, val);
17548   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
17549     promoted_val = promote_duplicated_reg (SImode, val);
17550   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
17551     promoted_val = promote_duplicated_reg (HImode, val);
17552   else
17553     promoted_val = val;
17554
17555   return promoted_val;
17556 }
17557
17558 /* Expand string clear operation (bzero).  Use i386 string operations when
17559    profitable.  See expand_movmem comment for explanation of individual
17560    steps performed.  */
17561 int
17562 ix86_expand_setmem (rtx dst, rtx count_exp, rtx val_exp, rtx align_exp,
17563                     rtx expected_align_exp, rtx expected_size_exp)
17564 {
17565   rtx destreg;
17566   rtx label = NULL;
17567   rtx tmp;
17568   rtx jump_around_label = NULL;
17569   HOST_WIDE_INT align = 1;
17570   unsigned HOST_WIDE_INT count = 0;
17571   HOST_WIDE_INT expected_size = -1;
17572   int size_needed = 0, epilogue_size_needed;
17573   int desired_align = 0;
17574   enum stringop_alg alg;
17575   rtx promoted_val = NULL;
17576   bool force_loopy_epilogue = false;
17577   int dynamic_check;
17578   bool need_zero_guard = false;
17579
17580   if (CONST_INT_P (align_exp))
17581     align = INTVAL (align_exp);
17582   /* i386 can do misaligned access on reasonably increased cost.  */
17583   if (CONST_INT_P (expected_align_exp)
17584       && INTVAL (expected_align_exp) > align)
17585     align = INTVAL (expected_align_exp);
17586   if (CONST_INT_P (count_exp))
17587     count = expected_size = INTVAL (count_exp);
17588   if (CONST_INT_P (expected_size_exp) && count == 0)
17589     expected_size = INTVAL (expected_size_exp);
17590
17591   /* Make sure we don't need to care about overflow later on.  */
17592   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17593     return 0;
17594
17595   /* Step 0: Decide on preferred algorithm, desired alignment and
17596      size of chunks to be copied by main loop.  */
17597
17598   alg = decide_alg (count, expected_size, true, &dynamic_check);
17599   desired_align = decide_alignment (align, alg, expected_size);
17600
17601   if (!TARGET_ALIGN_STRINGOPS)
17602     align = desired_align;
17603
17604   if (alg == libcall)
17605     return 0;
17606   gcc_assert (alg != no_stringop);
17607   if (!count)
17608     count_exp = copy_to_mode_reg (counter_mode (count_exp), count_exp);
17609   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17610   switch (alg)
17611     {
17612     case libcall:
17613     case no_stringop:
17614       gcc_unreachable ();
17615     case loop:
17616       need_zero_guard = true;
17617       size_needed = GET_MODE_SIZE (Pmode);
17618       break;
17619     case unrolled_loop:
17620       need_zero_guard = true;
17621       size_needed = GET_MODE_SIZE (Pmode) * 4;
17622       break;
17623     case rep_prefix_8_byte:
17624       size_needed = 8;
17625       break;
17626     case rep_prefix_4_byte:
17627       size_needed = 4;
17628       break;
17629     case rep_prefix_1_byte:
17630       size_needed = 1;
17631       break;
17632     case loop_1_byte:
17633       need_zero_guard = true;
17634       size_needed = 1;
17635       break;
17636     }
17637   epilogue_size_needed = size_needed;
17638
17639   /* Step 1: Prologue guard.  */
17640
17641   /* Alignment code needs count to be in register.  */
17642   if (CONST_INT_P (count_exp) && desired_align > align)
17643     {
17644       enum machine_mode mode = SImode;
17645       if (TARGET_64BIT && (count & ~0xffffffff))
17646         mode = DImode;
17647       count_exp = force_reg (mode, count_exp);
17648     }
17649   /* Do the cheap promotion to allow better CSE across the
17650      main loop and epilogue (ie one load of the big constant in the
17651      front of all code.  */
17652   if (CONST_INT_P (val_exp))
17653     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
17654                                                    desired_align, align);
17655   /* Ensure that alignment prologue won't copy past end of block.  */
17656   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
17657     {
17658       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
17659       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
17660          Make sure it is power of 2.  */
17661       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
17662
17663       /* To improve performance of small blocks, we jump around the VAL
17664          promoting mode.  This mean that if the promoted VAL is not constant,
17665          we might not use it in the epilogue and have to use byte
17666          loop variant.  */
17667       if (epilogue_size_needed > 2 && !promoted_val)
17668         force_loopy_epilogue = true;
17669       label = gen_label_rtx ();
17670       emit_cmp_and_jump_insns (count_exp,
17671                                GEN_INT (epilogue_size_needed),
17672                                LTU, 0, counter_mode (count_exp), 1, label);
17673       if (GET_CODE (count_exp) == CONST_INT)
17674         ;
17675       else if (expected_size == -1 || expected_size <= epilogue_size_needed)
17676         predict_jump (REG_BR_PROB_BASE * 60 / 100);
17677       else
17678         predict_jump (REG_BR_PROB_BASE * 20 / 100);
17679     }
17680   if (dynamic_check != -1)
17681     {
17682       rtx hot_label = gen_label_rtx ();
17683       jump_around_label = gen_label_rtx ();
17684       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
17685                                LEU, 0, counter_mode (count_exp), 1, hot_label);
17686       predict_jump (REG_BR_PROB_BASE * 90 / 100);
17687       set_storage_via_libcall (dst, count_exp, val_exp, false);
17688       emit_jump (jump_around_label);
17689       emit_label (hot_label);
17690     }
17691
17692   /* Step 2: Alignment prologue.  */
17693
17694   /* Do the expensive promotion once we branched off the small blocks.  */
17695   if (!promoted_val)
17696     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
17697                                                    desired_align, align);
17698   gcc_assert (desired_align >= 1 && align >= 1);
17699
17700   if (desired_align > align)
17701     {
17702       /* Except for the first move in epilogue, we no longer know
17703          constant offset in aliasing info.  It don't seems to worth
17704          the pain to maintain it for the first move, so throw away
17705          the info early.  */
17706       dst = change_address (dst, BLKmode, destreg);
17707       expand_setmem_prologue (dst, destreg, promoted_val, count_exp, align,
17708                               desired_align);
17709       if (need_zero_guard && !count)
17710         {
17711           /* It is possible that we copied enough so the main loop will not
17712              execute.  */
17713           emit_cmp_and_jump_insns (count_exp,
17714                                    GEN_INT (size_needed),
17715                                    LTU, 0, counter_mode (count_exp), 1, label);
17716           if (expected_size == -1
17717               || expected_size < (desired_align - align) / 2 + size_needed)
17718             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17719           else
17720             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17721         }
17722     }
17723   if (label && size_needed == 1)
17724     {
17725       emit_label (label);
17726       LABEL_NUSES (label) = 1;
17727       label = NULL;
17728     }
17729
17730   /* Step 3: Main loop.  */
17731
17732   switch (alg)
17733     {
17734     case libcall:
17735     case no_stringop:
17736       gcc_unreachable ();
17737     case loop_1_byte:
17738       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17739                                      count_exp, QImode, 1, expected_size);
17740       break;
17741     case loop:
17742       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17743                                      count_exp, Pmode, 1, expected_size);
17744       break;
17745     case unrolled_loop:
17746       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17747                                      count_exp, Pmode, 4, expected_size);
17748       break;
17749     case rep_prefix_8_byte:
17750       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17751                                   DImode);
17752       break;
17753     case rep_prefix_4_byte:
17754       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17755                                   SImode);
17756       break;
17757     case rep_prefix_1_byte:
17758       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17759                                   QImode);
17760       break;
17761     }
17762   /* Adjust properly the offset of src and dest memory for aliasing.  */
17763   if (CONST_INT_P (count_exp))
17764     dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
17765                                         (count / size_needed) * size_needed);
17766   else
17767     dst = change_address (dst, BLKmode, destreg);
17768
17769   /* Step 4: Epilogue to copy the remaining bytes.  */
17770
17771   if (label)
17772     {
17773       /* When the main loop is done, COUNT_EXP might hold original count,
17774          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
17775          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
17776          bytes. Compensate if needed.  */
17777
17778       if (size_needed < desired_align - align)
17779         {
17780           tmp =
17781             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
17782                                  GEN_INT (size_needed - 1), count_exp, 1,
17783                                  OPTAB_DIRECT);
17784           size_needed = desired_align - align + 1;
17785           if (tmp != count_exp)
17786             emit_move_insn (count_exp, tmp);
17787         }
17788       emit_label (label);
17789       LABEL_NUSES (label) = 1;
17790     }
17791   if (count_exp != const0_rtx && epilogue_size_needed > 1)
17792     {
17793       if (force_loopy_epilogue)
17794         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
17795                                          size_needed);
17796       else
17797         expand_setmem_epilogue (dst, destreg, promoted_val, count_exp,
17798                                 size_needed);
17799     }
17800   if (jump_around_label)
17801     emit_label (jump_around_label);
17802   return 1;
17803 }
17804
17805 /* Expand the appropriate insns for doing strlen if not just doing
17806    repnz; scasb
17807
17808    out = result, initialized with the start address
17809    align_rtx = alignment of the address.
17810    scratch = scratch register, initialized with the startaddress when
17811         not aligned, otherwise undefined
17812
17813    This is just the body. It needs the initializations mentioned above and
17814    some address computing at the end.  These things are done in i386.md.  */
17815
17816 static void
17817 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
17818 {
17819   int align;
17820   rtx tmp;
17821   rtx align_2_label = NULL_RTX;
17822   rtx align_3_label = NULL_RTX;
17823   rtx align_4_label = gen_label_rtx ();
17824   rtx end_0_label = gen_label_rtx ();
17825   rtx mem;
17826   rtx tmpreg = gen_reg_rtx (SImode);
17827   rtx scratch = gen_reg_rtx (SImode);
17828   rtx cmp;
17829
17830   align = 0;
17831   if (CONST_INT_P (align_rtx))
17832     align = INTVAL (align_rtx);
17833
17834   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
17835
17836   /* Is there a known alignment and is it less than 4?  */
17837   if (align < 4)
17838     {
17839       rtx scratch1 = gen_reg_rtx (Pmode);
17840       emit_move_insn (scratch1, out);
17841       /* Is there a known alignment and is it not 2? */
17842       if (align != 2)
17843         {
17844           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
17845           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
17846
17847           /* Leave just the 3 lower bits.  */
17848           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
17849                                     NULL_RTX, 0, OPTAB_WIDEN);
17850
17851           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
17852                                    Pmode, 1, align_4_label);
17853           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
17854                                    Pmode, 1, align_2_label);
17855           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
17856                                    Pmode, 1, align_3_label);
17857         }
17858       else
17859         {
17860           /* Since the alignment is 2, we have to check 2 or 0 bytes;
17861              check if is aligned to 4 - byte.  */
17862
17863           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
17864                                     NULL_RTX, 0, OPTAB_WIDEN);
17865
17866           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
17867                                    Pmode, 1, align_4_label);
17868         }
17869
17870       mem = change_address (src, QImode, out);
17871
17872       /* Now compare the bytes.  */
17873
17874       /* Compare the first n unaligned byte on a byte per byte basis.  */
17875       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
17876                                QImode, 1, end_0_label);
17877
17878       /* Increment the address.  */
17879       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17880
17881       /* Not needed with an alignment of 2 */
17882       if (align != 2)
17883         {
17884           emit_label (align_2_label);
17885
17886           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
17887                                    end_0_label);
17888
17889           emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17890
17891           emit_label (align_3_label);
17892         }
17893
17894       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
17895                                end_0_label);
17896
17897       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17898     }
17899
17900   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
17901      align this loop.  It gives only huge programs, but does not help to
17902      speed up.  */
17903   emit_label (align_4_label);
17904
17905   mem = change_address (src, SImode, out);
17906   emit_move_insn (scratch, mem);
17907   emit_insn ((*ix86_gen_add3) (out, out, GEN_INT (4)));
17908
17909   /* This formula yields a nonzero result iff one of the bytes is zero.
17910      This saves three branches inside loop and many cycles.  */
17911
17912   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
17913   emit_insn (gen_one_cmplsi2 (scratch, scratch));
17914   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
17915   emit_insn (gen_andsi3 (tmpreg, tmpreg,
17916                          gen_int_mode (0x80808080, SImode)));
17917   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
17918                            align_4_label);
17919
17920   if (TARGET_CMOVE)
17921     {
17922        rtx reg = gen_reg_rtx (SImode);
17923        rtx reg2 = gen_reg_rtx (Pmode);
17924        emit_move_insn (reg, tmpreg);
17925        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
17926
17927        /* If zero is not in the first two bytes, move two bytes forward.  */
17928        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
17929        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17930        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
17931        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
17932                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
17933                                                      reg,
17934                                                      tmpreg)));
17935        /* Emit lea manually to avoid clobbering of flags.  */
17936        emit_insn (gen_rtx_SET (SImode, reg2,
17937                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
17938
17939        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17940        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
17941        emit_insn (gen_rtx_SET (VOIDmode, out,
17942                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
17943                                                      reg2,
17944                                                      out)));
17945
17946     }
17947   else
17948     {
17949        rtx end_2_label = gen_label_rtx ();
17950        /* Is zero in the first two bytes? */
17951
17952        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
17953        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17954        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
17955        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
17956                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
17957                             pc_rtx);
17958        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
17959        JUMP_LABEL (tmp) = end_2_label;
17960
17961        /* Not in the first two.  Move two bytes forward.  */
17962        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
17963        emit_insn ((*ix86_gen_add3) (out, out, const2_rtx));
17964
17965        emit_label (end_2_label);
17966
17967     }
17968
17969   /* Avoid branch in fixing the byte.  */
17970   tmpreg = gen_lowpart (QImode, tmpreg);
17971   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
17972   cmp = gen_rtx_LTU (Pmode, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx);
17973   emit_insn ((*ix86_gen_sub3_carry) (out, out, GEN_INT (3), cmp));
17974
17975   emit_label (end_0_label);
17976 }
17977
17978 /* Expand strlen.  */
17979
17980 int
17981 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
17982 {
17983   rtx addr, scratch1, scratch2, scratch3, scratch4;
17984
17985   /* The generic case of strlen expander is long.  Avoid it's
17986      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
17987
17988   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
17989       && !TARGET_INLINE_ALL_STRINGOPS
17990       && !optimize_insn_for_size_p ()
17991       && (!CONST_INT_P (align) || INTVAL (align) < 4))
17992     return 0;
17993
17994   addr = force_reg (Pmode, XEXP (src, 0));
17995   scratch1 = gen_reg_rtx (Pmode);
17996
17997   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
17998       && !optimize_insn_for_size_p ())
17999     {
18000       /* Well it seems that some optimizer does not combine a call like
18001          foo(strlen(bar), strlen(bar));
18002          when the move and the subtraction is done here.  It does calculate
18003          the length just once when these instructions are done inside of
18004          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
18005          often used and I use one fewer register for the lifetime of
18006          output_strlen_unroll() this is better.  */
18007
18008       emit_move_insn (out, addr);
18009
18010       ix86_expand_strlensi_unroll_1 (out, src, align);
18011
18012       /* strlensi_unroll_1 returns the address of the zero at the end of
18013          the string, like memchr(), so compute the length by subtracting
18014          the start address.  */
18015       emit_insn ((*ix86_gen_sub3) (out, out, addr));
18016     }
18017   else
18018     {
18019       rtx unspec;
18020
18021       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
18022       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
18023         return false;
18024
18025       scratch2 = gen_reg_rtx (Pmode);
18026       scratch3 = gen_reg_rtx (Pmode);
18027       scratch4 = force_reg (Pmode, constm1_rtx);
18028
18029       emit_move_insn (scratch3, addr);
18030       eoschar = force_reg (QImode, eoschar);
18031
18032       src = replace_equiv_address_nv (src, scratch3);
18033
18034       /* If .md starts supporting :P, this can be done in .md.  */
18035       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
18036                                                  scratch4), UNSPEC_SCAS);
18037       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
18038       emit_insn ((*ix86_gen_one_cmpl2) (scratch2, scratch1));
18039       emit_insn ((*ix86_gen_add3) (out, scratch2, constm1_rtx));
18040     }
18041   return 1;
18042 }
18043
18044 /* For given symbol (function) construct code to compute address of it's PLT
18045    entry in large x86-64 PIC model.  */
18046 rtx
18047 construct_plt_address (rtx symbol)
18048 {
18049   rtx tmp = gen_reg_rtx (Pmode);
18050   rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
18051
18052   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
18053   gcc_assert (ix86_cmodel == CM_LARGE_PIC);
18054
18055   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
18056   emit_insn (gen_adddi3 (tmp, tmp, pic_offset_table_rtx));
18057   return tmp;
18058 }
18059
18060 void
18061 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
18062                   rtx callarg2 ATTRIBUTE_UNUSED,
18063                   rtx pop, int sibcall)
18064 {
18065   rtx use = NULL, call;
18066
18067   if (pop == const0_rtx)
18068     pop = NULL;
18069   gcc_assert (!TARGET_64BIT || !pop);
18070
18071   if (TARGET_MACHO && !TARGET_64BIT)
18072     {
18073 #if TARGET_MACHO
18074       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
18075         fnaddr = machopic_indirect_call_target (fnaddr);
18076 #endif
18077     }
18078   else
18079     {
18080       /* Static functions and indirect calls don't need the pic register.  */
18081       if (flag_pic && (!TARGET_64BIT || ix86_cmodel == CM_LARGE_PIC)
18082           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18083           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
18084         use_reg (&use, pic_offset_table_rtx);
18085     }
18086
18087   if (TARGET_64BIT && INTVAL (callarg2) >= 0)
18088     {
18089       rtx al = gen_rtx_REG (QImode, AX_REG);
18090       emit_move_insn (al, callarg2);
18091       use_reg (&use, al);
18092     }
18093
18094   if (ix86_cmodel == CM_LARGE_PIC
18095       && GET_CODE (fnaddr) == MEM
18096       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18097       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
18098     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
18099   else if (! call_insn_operand (XEXP (fnaddr, 0), Pmode))
18100     {
18101       fnaddr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18102       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18103     }
18104   if (sibcall && TARGET_64BIT
18105       && !constant_call_address_operand (XEXP (fnaddr, 0), Pmode))
18106     {
18107       rtx addr;
18108       addr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18109       fnaddr = gen_rtx_REG (Pmode, R11_REG);
18110       emit_move_insn (fnaddr, addr);
18111       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18112     }
18113
18114   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
18115   if (retval)
18116     call = gen_rtx_SET (VOIDmode, retval, call);
18117   if (pop)
18118     {
18119       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
18120       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
18121       call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop));
18122     }
18123
18124   call = emit_call_insn (call);
18125   if (use)
18126     CALL_INSN_FUNCTION_USAGE (call) = use;
18127 }
18128
18129 \f
18130 /* Clear stack slot assignments remembered from previous functions.
18131    This is called from INIT_EXPANDERS once before RTL is emitted for each
18132    function.  */
18133
18134 static struct machine_function *
18135 ix86_init_machine_status (void)
18136 {
18137   struct machine_function *f;
18138
18139   f = GGC_CNEW (struct machine_function);
18140   f->use_fast_prologue_epilogue_nregs = -1;
18141   f->tls_descriptor_call_expanded_p = 0;
18142   f->call_abi = DEFAULT_ABI;
18143
18144   return f;
18145 }
18146
18147 /* Return a MEM corresponding to a stack slot with mode MODE.
18148    Allocate a new slot if necessary.
18149
18150    The RTL for a function can have several slots available: N is
18151    which slot to use.  */
18152
18153 rtx
18154 assign_386_stack_local (enum machine_mode mode, enum ix86_stack_slot n)
18155 {
18156   struct stack_local_entry *s;
18157
18158   gcc_assert (n < MAX_386_STACK_LOCALS);
18159
18160   /* Virtual slot is valid only before vregs are instantiated.  */
18161   gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
18162
18163   for (s = ix86_stack_locals; s; s = s->next)
18164     if (s->mode == mode && s->n == n)
18165       return copy_rtx (s->rtl);
18166
18167   s = (struct stack_local_entry *)
18168     ggc_alloc (sizeof (struct stack_local_entry));
18169   s->n = n;
18170   s->mode = mode;
18171   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
18172
18173   s->next = ix86_stack_locals;
18174   ix86_stack_locals = s;
18175   return s->rtl;
18176 }
18177
18178 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
18179
18180 static GTY(()) rtx ix86_tls_symbol;
18181 rtx
18182 ix86_tls_get_addr (void)
18183 {
18184
18185   if (!ix86_tls_symbol)
18186     {
18187       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode,
18188                                             (TARGET_ANY_GNU_TLS
18189                                              && !TARGET_64BIT)
18190                                             ? "___tls_get_addr"
18191                                             : "__tls_get_addr");
18192     }
18193
18194   return ix86_tls_symbol;
18195 }
18196
18197 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
18198
18199 static GTY(()) rtx ix86_tls_module_base_symbol;
18200 rtx
18201 ix86_tls_module_base (void)
18202 {
18203
18204   if (!ix86_tls_module_base_symbol)
18205     {
18206       ix86_tls_module_base_symbol = gen_rtx_SYMBOL_REF (Pmode,
18207                                                         "_TLS_MODULE_BASE_");
18208       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
18209         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
18210     }
18211
18212   return ix86_tls_module_base_symbol;
18213 }
18214 \f
18215 /* Calculate the length of the memory address in the instruction
18216    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
18217
18218 int
18219 memory_address_length (rtx addr)
18220 {
18221   struct ix86_address parts;
18222   rtx base, index, disp;
18223   int len;
18224   int ok;
18225
18226   if (GET_CODE (addr) == PRE_DEC
18227       || GET_CODE (addr) == POST_INC
18228       || GET_CODE (addr) == PRE_MODIFY
18229       || GET_CODE (addr) == POST_MODIFY)
18230     return 0;
18231
18232   ok = ix86_decompose_address (addr, &parts);
18233   gcc_assert (ok);
18234
18235   if (parts.base && GET_CODE (parts.base) == SUBREG)
18236     parts.base = SUBREG_REG (parts.base);
18237   if (parts.index && GET_CODE (parts.index) == SUBREG)
18238     parts.index = SUBREG_REG (parts.index);
18239
18240   base = parts.base;
18241   index = parts.index;
18242   disp = parts.disp;
18243   len = 0;
18244
18245   /* Rule of thumb:
18246        - esp as the base always wants an index,
18247        - ebp as the base always wants a displacement.  */
18248
18249   /* Register Indirect.  */
18250   if (base && !index && !disp)
18251     {
18252       /* esp (for its index) and ebp (for its displacement) need
18253          the two-byte modrm form.  */
18254       if (addr == stack_pointer_rtx
18255           || addr == arg_pointer_rtx
18256           || addr == frame_pointer_rtx
18257           || addr == hard_frame_pointer_rtx)
18258         len = 1;
18259     }
18260
18261   /* Direct Addressing.  */
18262   else if (disp && !base && !index)
18263     len = 4;
18264
18265   else
18266     {
18267       /* Find the length of the displacement constant.  */
18268       if (disp)
18269         {
18270           if (base && satisfies_constraint_K (disp))
18271             len = 1;
18272           else
18273             len = 4;
18274         }
18275       /* ebp always wants a displacement.  */
18276       else if (base == hard_frame_pointer_rtx)
18277         len = 1;
18278
18279       /* An index requires the two-byte modrm form....  */
18280       if (index
18281           /* ...like esp, which always wants an index.  */
18282           || base == stack_pointer_rtx
18283           || base == arg_pointer_rtx
18284           || base == frame_pointer_rtx)
18285         len += 1;
18286     }
18287
18288   return len;
18289 }
18290
18291 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
18292    is set, expect that insn have 8bit immediate alternative.  */
18293 int
18294 ix86_attr_length_immediate_default (rtx insn, int shortform)
18295 {
18296   int len = 0;
18297   int i;
18298   extract_insn_cached (insn);
18299   for (i = recog_data.n_operands - 1; i >= 0; --i)
18300     if (CONSTANT_P (recog_data.operand[i]))
18301       {
18302         gcc_assert (!len);
18303         if (shortform && satisfies_constraint_K (recog_data.operand[i]))
18304           len = 1;
18305         else
18306           {
18307             switch (get_attr_mode (insn))
18308               {
18309                 case MODE_QI:
18310                   len+=1;
18311                   break;
18312                 case MODE_HI:
18313                   len+=2;
18314                   break;
18315                 case MODE_SI:
18316                   len+=4;
18317                   break;
18318                 /* Immediates for DImode instructions are encoded as 32bit sign extended values.  */
18319                 case MODE_DI:
18320                   len+=4;
18321                   break;
18322                 default:
18323                   fatal_insn ("unknown insn mode", insn);
18324               }
18325           }
18326       }
18327   return len;
18328 }
18329 /* Compute default value for "length_address" attribute.  */
18330 int
18331 ix86_attr_length_address_default (rtx insn)
18332 {
18333   int i;
18334
18335   if (get_attr_type (insn) == TYPE_LEA)
18336     {
18337       rtx set = PATTERN (insn);
18338
18339       if (GET_CODE (set) == PARALLEL)
18340         set = XVECEXP (set, 0, 0);
18341
18342       gcc_assert (GET_CODE (set) == SET);
18343
18344       return memory_address_length (SET_SRC (set));
18345     }
18346
18347   extract_insn_cached (insn);
18348   for (i = recog_data.n_operands - 1; i >= 0; --i)
18349     if (MEM_P (recog_data.operand[i]))
18350       {
18351         return memory_address_length (XEXP (recog_data.operand[i], 0));
18352         break;
18353       }
18354   return 0;
18355 }
18356
18357 /* Compute default value for "length_vex" attribute. It includes
18358    2 or 3 byte VEX prefix and 1 opcode byte.  */
18359
18360 int
18361 ix86_attr_length_vex_default (rtx insn, int has_0f_opcode,
18362                               int has_vex_w)
18363 {
18364   int i;
18365
18366   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
18367      byte VEX prefix.  */
18368   if (!has_0f_opcode || has_vex_w)
18369     return 3 + 1;
18370
18371  /* We can always use 2 byte VEX prefix in 32bit.  */
18372   if (!TARGET_64BIT)
18373     return 2 + 1;
18374
18375   extract_insn_cached (insn);
18376
18377   for (i = recog_data.n_operands - 1; i >= 0; --i)
18378     if (REG_P (recog_data.operand[i]))
18379       {
18380         /* REX.W bit uses 3 byte VEX prefix.  */
18381         if (GET_MODE (recog_data.operand[i]) == DImode)
18382           return 3 + 1;
18383       }
18384     else
18385       {
18386         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
18387         if (MEM_P (recog_data.operand[i])
18388             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
18389           return 3 + 1;
18390       }
18391
18392   return 2 + 1;
18393 }
18394 \f
18395 /* Return the maximum number of instructions a cpu can issue.  */
18396
18397 static int
18398 ix86_issue_rate (void)
18399 {
18400   switch (ix86_tune)
18401     {
18402     case PROCESSOR_PENTIUM:
18403     case PROCESSOR_K6:
18404       return 2;
18405
18406     case PROCESSOR_PENTIUMPRO:
18407     case PROCESSOR_PENTIUM4:
18408     case PROCESSOR_ATHLON:
18409     case PROCESSOR_K8:
18410     case PROCESSOR_AMDFAM10:
18411     case PROCESSOR_NOCONA:
18412     case PROCESSOR_GENERIC32:
18413     case PROCESSOR_GENERIC64:
18414       return 3;
18415
18416     case PROCESSOR_CORE2:
18417       return 4;
18418
18419     default:
18420       return 1;
18421     }
18422 }
18423
18424 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
18425    by DEP_INSN and nothing set by DEP_INSN.  */
18426
18427 static int
18428 ix86_flags_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
18429 {
18430   rtx set, set2;
18431
18432   /* Simplify the test for uninteresting insns.  */
18433   if (insn_type != TYPE_SETCC
18434       && insn_type != TYPE_ICMOV
18435       && insn_type != TYPE_FCMOV
18436       && insn_type != TYPE_IBR)
18437     return 0;
18438
18439   if ((set = single_set (dep_insn)) != 0)
18440     {
18441       set = SET_DEST (set);
18442       set2 = NULL_RTX;
18443     }
18444   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
18445            && XVECLEN (PATTERN (dep_insn), 0) == 2
18446            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
18447            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
18448     {
18449       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
18450       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
18451     }
18452   else
18453     return 0;
18454
18455   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
18456     return 0;
18457
18458   /* This test is true if the dependent insn reads the flags but
18459      not any other potentially set register.  */
18460   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
18461     return 0;
18462
18463   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
18464     return 0;
18465
18466   return 1;
18467 }
18468
18469 /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory
18470    address with operands set by DEP_INSN.  */
18471
18472 static int
18473 ix86_agi_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
18474 {
18475   rtx addr;
18476
18477   if (insn_type == TYPE_LEA
18478       && TARGET_PENTIUM)
18479     {
18480       addr = PATTERN (insn);
18481
18482       if (GET_CODE (addr) == PARALLEL)
18483         addr = XVECEXP (addr, 0, 0);
18484
18485       gcc_assert (GET_CODE (addr) == SET);
18486
18487       addr = SET_SRC (addr);
18488     }
18489   else
18490     {
18491       int i;
18492       extract_insn_cached (insn);
18493       for (i = recog_data.n_operands - 1; i >= 0; --i)
18494         if (MEM_P (recog_data.operand[i]))
18495           {
18496             addr = XEXP (recog_data.operand[i], 0);
18497             goto found;
18498           }
18499       return 0;
18500     found:;
18501     }
18502
18503   return modified_in_p (addr, dep_insn);
18504 }
18505
18506 static int
18507 ix86_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
18508 {
18509   enum attr_type insn_type, dep_insn_type;
18510   enum attr_memory memory;
18511   rtx set, set2;
18512   int dep_insn_code_number;
18513
18514   /* Anti and output dependencies have zero cost on all CPUs.  */
18515   if (REG_NOTE_KIND (link) != 0)
18516     return 0;
18517
18518   dep_insn_code_number = recog_memoized (dep_insn);
18519
18520   /* If we can't recognize the insns, we can't really do anything.  */
18521   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
18522     return cost;
18523
18524   insn_type = get_attr_type (insn);
18525   dep_insn_type = get_attr_type (dep_insn);
18526
18527   switch (ix86_tune)
18528     {
18529     case PROCESSOR_PENTIUM:
18530       /* Address Generation Interlock adds a cycle of latency.  */
18531       if (ix86_agi_dependent (insn, dep_insn, insn_type))
18532         cost += 1;
18533
18534       /* ??? Compares pair with jump/setcc.  */
18535       if (ix86_flags_dependent (insn, dep_insn, insn_type))
18536         cost = 0;
18537
18538       /* Floating point stores require value to be ready one cycle earlier.  */
18539       if (insn_type == TYPE_FMOV
18540           && get_attr_memory (insn) == MEMORY_STORE
18541           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18542         cost += 1;
18543       break;
18544
18545     case PROCESSOR_PENTIUMPRO:
18546       memory = get_attr_memory (insn);
18547
18548       /* INT->FP conversion is expensive.  */
18549       if (get_attr_fp_int_src (dep_insn))
18550         cost += 5;
18551
18552       /* There is one cycle extra latency between an FP op and a store.  */
18553       if (insn_type == TYPE_FMOV
18554           && (set = single_set (dep_insn)) != NULL_RTX
18555           && (set2 = single_set (insn)) != NULL_RTX
18556           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
18557           && MEM_P (SET_DEST (set2)))
18558         cost += 1;
18559
18560       /* Show ability of reorder buffer to hide latency of load by executing
18561          in parallel with previous instruction in case
18562          previous instruction is not needed to compute the address.  */
18563       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18564           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18565         {
18566           /* Claim moves to take one cycle, as core can issue one load
18567              at time and the next load can start cycle later.  */
18568           if (dep_insn_type == TYPE_IMOV
18569               || dep_insn_type == TYPE_FMOV)
18570             cost = 1;
18571           else if (cost > 1)
18572             cost--;
18573         }
18574       break;
18575
18576     case PROCESSOR_K6:
18577       memory = get_attr_memory (insn);
18578
18579       /* The esp dependency is resolved before the instruction is really
18580          finished.  */
18581       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
18582           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
18583         return 1;
18584
18585       /* INT->FP conversion is expensive.  */
18586       if (get_attr_fp_int_src (dep_insn))
18587         cost += 5;
18588
18589       /* Show ability of reorder buffer to hide latency of load by executing
18590          in parallel with previous instruction in case
18591          previous instruction is not needed to compute the address.  */
18592       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18593           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18594         {
18595           /* Claim moves to take one cycle, as core can issue one load
18596              at time and the next load can start cycle later.  */
18597           if (dep_insn_type == TYPE_IMOV
18598               || dep_insn_type == TYPE_FMOV)
18599             cost = 1;
18600           else if (cost > 2)
18601             cost -= 2;
18602           else
18603             cost = 1;
18604         }
18605       break;
18606
18607     case PROCESSOR_ATHLON:
18608     case PROCESSOR_K8:
18609     case PROCESSOR_AMDFAM10:
18610     case PROCESSOR_GENERIC32:
18611     case PROCESSOR_GENERIC64:
18612       memory = get_attr_memory (insn);
18613
18614       /* Show ability of reorder buffer to hide latency of load by executing
18615          in parallel with previous instruction in case
18616          previous instruction is not needed to compute the address.  */
18617       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18618           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18619         {
18620           enum attr_unit unit = get_attr_unit (insn);
18621           int loadcost = 3;
18622
18623           /* Because of the difference between the length of integer and
18624              floating unit pipeline preparation stages, the memory operands
18625              for floating point are cheaper.
18626
18627              ??? For Athlon it the difference is most probably 2.  */
18628           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
18629             loadcost = 3;
18630           else
18631             loadcost = TARGET_ATHLON ? 2 : 0;
18632
18633           if (cost >= loadcost)
18634             cost -= loadcost;
18635           else
18636             cost = 0;
18637         }
18638
18639     default:
18640       break;
18641     }
18642
18643   return cost;
18644 }
18645
18646 /* How many alternative schedules to try.  This should be as wide as the
18647    scheduling freedom in the DFA, but no wider.  Making this value too
18648    large results extra work for the scheduler.  */
18649
18650 static int
18651 ia32_multipass_dfa_lookahead (void)
18652 {
18653   switch (ix86_tune)
18654     {
18655     case PROCESSOR_PENTIUM:
18656       return 2;
18657
18658     case PROCESSOR_PENTIUMPRO:
18659     case PROCESSOR_K6:
18660       return 1;
18661
18662     default:
18663       return 0;
18664     }
18665 }
18666
18667 \f
18668 /* Compute the alignment given to a constant that is being placed in memory.
18669    EXP is the constant and ALIGN is the alignment that the object would
18670    ordinarily have.
18671    The value of this function is used instead of that alignment to align
18672    the object.  */
18673
18674 int
18675 ix86_constant_alignment (tree exp, int align)
18676 {
18677   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
18678       || TREE_CODE (exp) == INTEGER_CST)
18679     {
18680       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
18681         return 64;
18682       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
18683         return 128;
18684     }
18685   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
18686            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
18687     return BITS_PER_WORD;
18688
18689   return align;
18690 }
18691
18692 /* Compute the alignment for a static variable.
18693    TYPE is the data type, and ALIGN is the alignment that
18694    the object would ordinarily have.  The value of this function is used
18695    instead of that alignment to align the object.  */
18696
18697 int
18698 ix86_data_alignment (tree type, int align)
18699 {
18700   int max_align = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
18701
18702   if (AGGREGATE_TYPE_P (type)
18703       && TYPE_SIZE (type)
18704       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18705       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= (unsigned) max_align
18706           || TREE_INT_CST_HIGH (TYPE_SIZE (type)))
18707       && align < max_align)
18708     align = max_align;
18709
18710   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18711      to 16byte boundary.  */
18712   if (TARGET_64BIT)
18713     {
18714       if (AGGREGATE_TYPE_P (type)
18715            && TYPE_SIZE (type)
18716            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18717            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 128
18718                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
18719         return 128;
18720     }
18721
18722   if (TREE_CODE (type) == ARRAY_TYPE)
18723     {
18724       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18725         return 64;
18726       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18727         return 128;
18728     }
18729   else if (TREE_CODE (type) == COMPLEX_TYPE)
18730     {
18731
18732       if (TYPE_MODE (type) == DCmode && align < 64)
18733         return 64;
18734       if ((TYPE_MODE (type) == XCmode
18735            || TYPE_MODE (type) == TCmode) && align < 128)
18736         return 128;
18737     }
18738   else if ((TREE_CODE (type) == RECORD_TYPE
18739             || TREE_CODE (type) == UNION_TYPE
18740             || TREE_CODE (type) == QUAL_UNION_TYPE)
18741            && TYPE_FIELDS (type))
18742     {
18743       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18744         return 64;
18745       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18746         return 128;
18747     }
18748   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
18749            || TREE_CODE (type) == INTEGER_TYPE)
18750     {
18751       if (TYPE_MODE (type) == DFmode && align < 64)
18752         return 64;
18753       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18754         return 128;
18755     }
18756
18757   return align;
18758 }
18759
18760 /* Compute the alignment for a local variable or a stack slot.  TYPE is
18761    the data type, MODE is the widest mode available and ALIGN is the
18762    alignment that the object would ordinarily have.  The value of this
18763    macro is used instead of that alignment to align the object.  */
18764
18765 unsigned int
18766 ix86_local_alignment (tree type, enum machine_mode mode,
18767                       unsigned int align)
18768 {
18769   /* If TYPE is NULL, we are allocating a stack slot for caller-save
18770      register in MODE.  We will return the largest alignment of XF
18771      and DF.  */
18772   if (!type)
18773     {
18774       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
18775         align = GET_MODE_ALIGNMENT (DFmode);
18776       return align;
18777     }
18778
18779   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18780      to 16byte boundary.  */
18781   if (TARGET_64BIT)
18782     {
18783       if (AGGREGATE_TYPE_P (type)
18784            && TYPE_SIZE (type)
18785            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18786            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16
18787                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
18788         return 128;
18789     }
18790   if (TREE_CODE (type) == ARRAY_TYPE)
18791     {
18792       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18793         return 64;
18794       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18795         return 128;
18796     }
18797   else if (TREE_CODE (type) == COMPLEX_TYPE)
18798     {
18799       if (TYPE_MODE (type) == DCmode && align < 64)
18800         return 64;
18801       if ((TYPE_MODE (type) == XCmode
18802            || TYPE_MODE (type) == TCmode) && align < 128)
18803         return 128;
18804     }
18805   else if ((TREE_CODE (type) == RECORD_TYPE
18806             || TREE_CODE (type) == UNION_TYPE
18807             || TREE_CODE (type) == QUAL_UNION_TYPE)
18808            && TYPE_FIELDS (type))
18809     {
18810       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18811         return 64;
18812       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18813         return 128;
18814     }
18815   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
18816            || TREE_CODE (type) == INTEGER_TYPE)
18817     {
18818
18819       if (TYPE_MODE (type) == DFmode && align < 64)
18820         return 64;
18821       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18822         return 128;
18823     }
18824   return align;
18825 }
18826 \f
18827 /* Emit RTL insns to initialize the variable parts of a trampoline.
18828    FNADDR is an RTX for the address of the function's pure code.
18829    CXT is an RTX for the static chain value for the function.  */
18830 void
18831 x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
18832 {
18833   if (!TARGET_64BIT)
18834     {
18835       /* Compute offset from the end of the jmp to the target function.  */
18836       rtx disp = expand_binop (SImode, sub_optab, fnaddr,
18837                                plus_constant (tramp, 10),
18838                                NULL_RTX, 1, OPTAB_DIRECT);
18839       emit_move_insn (gen_rtx_MEM (QImode, tramp),
18840                       gen_int_mode (0xb9, QImode));
18841       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
18842       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
18843                       gen_int_mode (0xe9, QImode));
18844       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
18845     }
18846   else
18847     {
18848       int offset = 0;
18849       /* Try to load address using shorter movl instead of movabs.
18850          We may want to support movq for kernel mode, but kernel does not use
18851          trampolines at the moment.  */
18852       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
18853         {
18854           fnaddr = copy_to_mode_reg (DImode, fnaddr);
18855           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18856                           gen_int_mode (0xbb41, HImode));
18857           emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
18858                           gen_lowpart (SImode, fnaddr));
18859           offset += 6;
18860         }
18861       else
18862         {
18863           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18864                           gen_int_mode (0xbb49, HImode));
18865           emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
18866                           fnaddr);
18867           offset += 10;
18868         }
18869       /* Load static chain using movabs to r10.  */
18870       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18871                       gen_int_mode (0xba49, HImode));
18872       emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
18873                       cxt);
18874       offset += 10;
18875       /* Jump to the r11 */
18876       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18877                       gen_int_mode (0xff49, HImode));
18878       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
18879                       gen_int_mode (0xe3, QImode));
18880       offset += 3;
18881       gcc_assert (offset <= TRAMPOLINE_SIZE);
18882     }
18883
18884 #ifdef ENABLE_EXECUTE_STACK
18885   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
18886                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
18887 #endif
18888 }
18889 \f
18890 /* Codes for all the SSE/MMX builtins.  */
18891 enum ix86_builtins
18892 {
18893   IX86_BUILTIN_ADDPS,
18894   IX86_BUILTIN_ADDSS,
18895   IX86_BUILTIN_DIVPS,
18896   IX86_BUILTIN_DIVSS,
18897   IX86_BUILTIN_MULPS,
18898   IX86_BUILTIN_MULSS,
18899   IX86_BUILTIN_SUBPS,
18900   IX86_BUILTIN_SUBSS,
18901
18902   IX86_BUILTIN_CMPEQPS,
18903   IX86_BUILTIN_CMPLTPS,
18904   IX86_BUILTIN_CMPLEPS,
18905   IX86_BUILTIN_CMPGTPS,
18906   IX86_BUILTIN_CMPGEPS,
18907   IX86_BUILTIN_CMPNEQPS,
18908   IX86_BUILTIN_CMPNLTPS,
18909   IX86_BUILTIN_CMPNLEPS,
18910   IX86_BUILTIN_CMPNGTPS,
18911   IX86_BUILTIN_CMPNGEPS,
18912   IX86_BUILTIN_CMPORDPS,
18913   IX86_BUILTIN_CMPUNORDPS,
18914   IX86_BUILTIN_CMPEQSS,
18915   IX86_BUILTIN_CMPLTSS,
18916   IX86_BUILTIN_CMPLESS,
18917   IX86_BUILTIN_CMPNEQSS,
18918   IX86_BUILTIN_CMPNLTSS,
18919   IX86_BUILTIN_CMPNLESS,
18920   IX86_BUILTIN_CMPNGTSS,
18921   IX86_BUILTIN_CMPNGESS,
18922   IX86_BUILTIN_CMPORDSS,
18923   IX86_BUILTIN_CMPUNORDSS,
18924
18925   IX86_BUILTIN_COMIEQSS,
18926   IX86_BUILTIN_COMILTSS,
18927   IX86_BUILTIN_COMILESS,
18928   IX86_BUILTIN_COMIGTSS,
18929   IX86_BUILTIN_COMIGESS,
18930   IX86_BUILTIN_COMINEQSS,
18931   IX86_BUILTIN_UCOMIEQSS,
18932   IX86_BUILTIN_UCOMILTSS,
18933   IX86_BUILTIN_UCOMILESS,
18934   IX86_BUILTIN_UCOMIGTSS,
18935   IX86_BUILTIN_UCOMIGESS,
18936   IX86_BUILTIN_UCOMINEQSS,
18937
18938   IX86_BUILTIN_CVTPI2PS,
18939   IX86_BUILTIN_CVTPS2PI,
18940   IX86_BUILTIN_CVTSI2SS,
18941   IX86_BUILTIN_CVTSI642SS,
18942   IX86_BUILTIN_CVTSS2SI,
18943   IX86_BUILTIN_CVTSS2SI64,
18944   IX86_BUILTIN_CVTTPS2PI,
18945   IX86_BUILTIN_CVTTSS2SI,
18946   IX86_BUILTIN_CVTTSS2SI64,
18947
18948   IX86_BUILTIN_MAXPS,
18949   IX86_BUILTIN_MAXSS,
18950   IX86_BUILTIN_MINPS,
18951   IX86_BUILTIN_MINSS,
18952
18953   IX86_BUILTIN_LOADUPS,
18954   IX86_BUILTIN_STOREUPS,
18955   IX86_BUILTIN_MOVSS,
18956
18957   IX86_BUILTIN_MOVHLPS,
18958   IX86_BUILTIN_MOVLHPS,
18959   IX86_BUILTIN_LOADHPS,
18960   IX86_BUILTIN_LOADLPS,
18961   IX86_BUILTIN_STOREHPS,
18962   IX86_BUILTIN_STORELPS,
18963
18964   IX86_BUILTIN_MASKMOVQ,
18965   IX86_BUILTIN_MOVMSKPS,
18966   IX86_BUILTIN_PMOVMSKB,
18967
18968   IX86_BUILTIN_MOVNTPS,
18969   IX86_BUILTIN_MOVNTQ,
18970
18971   IX86_BUILTIN_LOADDQU,
18972   IX86_BUILTIN_STOREDQU,
18973
18974   IX86_BUILTIN_PACKSSWB,
18975   IX86_BUILTIN_PACKSSDW,
18976   IX86_BUILTIN_PACKUSWB,
18977
18978   IX86_BUILTIN_PADDB,
18979   IX86_BUILTIN_PADDW,
18980   IX86_BUILTIN_PADDD,
18981   IX86_BUILTIN_PADDQ,
18982   IX86_BUILTIN_PADDSB,
18983   IX86_BUILTIN_PADDSW,
18984   IX86_BUILTIN_PADDUSB,
18985   IX86_BUILTIN_PADDUSW,
18986   IX86_BUILTIN_PSUBB,
18987   IX86_BUILTIN_PSUBW,
18988   IX86_BUILTIN_PSUBD,
18989   IX86_BUILTIN_PSUBQ,
18990   IX86_BUILTIN_PSUBSB,
18991   IX86_BUILTIN_PSUBSW,
18992   IX86_BUILTIN_PSUBUSB,
18993   IX86_BUILTIN_PSUBUSW,
18994
18995   IX86_BUILTIN_PAND,
18996   IX86_BUILTIN_PANDN,
18997   IX86_BUILTIN_POR,
18998   IX86_BUILTIN_PXOR,
18999
19000   IX86_BUILTIN_PAVGB,
19001   IX86_BUILTIN_PAVGW,
19002
19003   IX86_BUILTIN_PCMPEQB,
19004   IX86_BUILTIN_PCMPEQW,
19005   IX86_BUILTIN_PCMPEQD,
19006   IX86_BUILTIN_PCMPGTB,
19007   IX86_BUILTIN_PCMPGTW,
19008   IX86_BUILTIN_PCMPGTD,
19009
19010   IX86_BUILTIN_PMADDWD,
19011
19012   IX86_BUILTIN_PMAXSW,
19013   IX86_BUILTIN_PMAXUB,
19014   IX86_BUILTIN_PMINSW,
19015   IX86_BUILTIN_PMINUB,
19016
19017   IX86_BUILTIN_PMULHUW,
19018   IX86_BUILTIN_PMULHW,
19019   IX86_BUILTIN_PMULLW,
19020
19021   IX86_BUILTIN_PSADBW,
19022   IX86_BUILTIN_PSHUFW,
19023
19024   IX86_BUILTIN_PSLLW,
19025   IX86_BUILTIN_PSLLD,
19026   IX86_BUILTIN_PSLLQ,
19027   IX86_BUILTIN_PSRAW,
19028   IX86_BUILTIN_PSRAD,
19029   IX86_BUILTIN_PSRLW,
19030   IX86_BUILTIN_PSRLD,
19031   IX86_BUILTIN_PSRLQ,
19032   IX86_BUILTIN_PSLLWI,
19033   IX86_BUILTIN_PSLLDI,
19034   IX86_BUILTIN_PSLLQI,
19035   IX86_BUILTIN_PSRAWI,
19036   IX86_BUILTIN_PSRADI,
19037   IX86_BUILTIN_PSRLWI,
19038   IX86_BUILTIN_PSRLDI,
19039   IX86_BUILTIN_PSRLQI,
19040
19041   IX86_BUILTIN_PUNPCKHBW,
19042   IX86_BUILTIN_PUNPCKHWD,
19043   IX86_BUILTIN_PUNPCKHDQ,
19044   IX86_BUILTIN_PUNPCKLBW,
19045   IX86_BUILTIN_PUNPCKLWD,
19046   IX86_BUILTIN_PUNPCKLDQ,
19047
19048   IX86_BUILTIN_SHUFPS,
19049
19050   IX86_BUILTIN_RCPPS,
19051   IX86_BUILTIN_RCPSS,
19052   IX86_BUILTIN_RSQRTPS,
19053   IX86_BUILTIN_RSQRTPS_NR,
19054   IX86_BUILTIN_RSQRTSS,
19055   IX86_BUILTIN_RSQRTF,
19056   IX86_BUILTIN_SQRTPS,
19057   IX86_BUILTIN_SQRTPS_NR,
19058   IX86_BUILTIN_SQRTSS,
19059
19060   IX86_BUILTIN_UNPCKHPS,
19061   IX86_BUILTIN_UNPCKLPS,
19062
19063   IX86_BUILTIN_ANDPS,
19064   IX86_BUILTIN_ANDNPS,
19065   IX86_BUILTIN_ORPS,
19066   IX86_BUILTIN_XORPS,
19067
19068   IX86_BUILTIN_EMMS,
19069   IX86_BUILTIN_LDMXCSR,
19070   IX86_BUILTIN_STMXCSR,
19071   IX86_BUILTIN_SFENCE,
19072
19073   /* 3DNow! Original */
19074   IX86_BUILTIN_FEMMS,
19075   IX86_BUILTIN_PAVGUSB,
19076   IX86_BUILTIN_PF2ID,
19077   IX86_BUILTIN_PFACC,
19078   IX86_BUILTIN_PFADD,
19079   IX86_BUILTIN_PFCMPEQ,
19080   IX86_BUILTIN_PFCMPGE,
19081   IX86_BUILTIN_PFCMPGT,
19082   IX86_BUILTIN_PFMAX,
19083   IX86_BUILTIN_PFMIN,
19084   IX86_BUILTIN_PFMUL,
19085   IX86_BUILTIN_PFRCP,
19086   IX86_BUILTIN_PFRCPIT1,
19087   IX86_BUILTIN_PFRCPIT2,
19088   IX86_BUILTIN_PFRSQIT1,
19089   IX86_BUILTIN_PFRSQRT,
19090   IX86_BUILTIN_PFSUB,
19091   IX86_BUILTIN_PFSUBR,
19092   IX86_BUILTIN_PI2FD,
19093   IX86_BUILTIN_PMULHRW,
19094
19095   /* 3DNow! Athlon Extensions */
19096   IX86_BUILTIN_PF2IW,
19097   IX86_BUILTIN_PFNACC,
19098   IX86_BUILTIN_PFPNACC,
19099   IX86_BUILTIN_PI2FW,
19100   IX86_BUILTIN_PSWAPDSI,
19101   IX86_BUILTIN_PSWAPDSF,
19102
19103   /* SSE2 */
19104   IX86_BUILTIN_ADDPD,
19105   IX86_BUILTIN_ADDSD,
19106   IX86_BUILTIN_DIVPD,
19107   IX86_BUILTIN_DIVSD,
19108   IX86_BUILTIN_MULPD,
19109   IX86_BUILTIN_MULSD,
19110   IX86_BUILTIN_SUBPD,
19111   IX86_BUILTIN_SUBSD,
19112
19113   IX86_BUILTIN_CMPEQPD,
19114   IX86_BUILTIN_CMPLTPD,
19115   IX86_BUILTIN_CMPLEPD,
19116   IX86_BUILTIN_CMPGTPD,
19117   IX86_BUILTIN_CMPGEPD,
19118   IX86_BUILTIN_CMPNEQPD,
19119   IX86_BUILTIN_CMPNLTPD,
19120   IX86_BUILTIN_CMPNLEPD,
19121   IX86_BUILTIN_CMPNGTPD,
19122   IX86_BUILTIN_CMPNGEPD,
19123   IX86_BUILTIN_CMPORDPD,
19124   IX86_BUILTIN_CMPUNORDPD,
19125   IX86_BUILTIN_CMPEQSD,
19126   IX86_BUILTIN_CMPLTSD,
19127   IX86_BUILTIN_CMPLESD,
19128   IX86_BUILTIN_CMPNEQSD,
19129   IX86_BUILTIN_CMPNLTSD,
19130   IX86_BUILTIN_CMPNLESD,
19131   IX86_BUILTIN_CMPORDSD,
19132   IX86_BUILTIN_CMPUNORDSD,
19133
19134   IX86_BUILTIN_COMIEQSD,
19135   IX86_BUILTIN_COMILTSD,
19136   IX86_BUILTIN_COMILESD,
19137   IX86_BUILTIN_COMIGTSD,
19138   IX86_BUILTIN_COMIGESD,
19139   IX86_BUILTIN_COMINEQSD,
19140   IX86_BUILTIN_UCOMIEQSD,
19141   IX86_BUILTIN_UCOMILTSD,
19142   IX86_BUILTIN_UCOMILESD,
19143   IX86_BUILTIN_UCOMIGTSD,
19144   IX86_BUILTIN_UCOMIGESD,
19145   IX86_BUILTIN_UCOMINEQSD,
19146
19147   IX86_BUILTIN_MAXPD,
19148   IX86_BUILTIN_MAXSD,
19149   IX86_BUILTIN_MINPD,
19150   IX86_BUILTIN_MINSD,
19151
19152   IX86_BUILTIN_ANDPD,
19153   IX86_BUILTIN_ANDNPD,
19154   IX86_BUILTIN_ORPD,
19155   IX86_BUILTIN_XORPD,
19156
19157   IX86_BUILTIN_SQRTPD,
19158   IX86_BUILTIN_SQRTSD,
19159
19160   IX86_BUILTIN_UNPCKHPD,
19161   IX86_BUILTIN_UNPCKLPD,
19162
19163   IX86_BUILTIN_SHUFPD,
19164
19165   IX86_BUILTIN_LOADUPD,
19166   IX86_BUILTIN_STOREUPD,
19167   IX86_BUILTIN_MOVSD,
19168
19169   IX86_BUILTIN_LOADHPD,
19170   IX86_BUILTIN_LOADLPD,
19171
19172   IX86_BUILTIN_CVTDQ2PD,
19173   IX86_BUILTIN_CVTDQ2PS,
19174
19175   IX86_BUILTIN_CVTPD2DQ,
19176   IX86_BUILTIN_CVTPD2PI,
19177   IX86_BUILTIN_CVTPD2PS,
19178   IX86_BUILTIN_CVTTPD2DQ,
19179   IX86_BUILTIN_CVTTPD2PI,
19180
19181   IX86_BUILTIN_CVTPI2PD,
19182   IX86_BUILTIN_CVTSI2SD,
19183   IX86_BUILTIN_CVTSI642SD,
19184
19185   IX86_BUILTIN_CVTSD2SI,
19186   IX86_BUILTIN_CVTSD2SI64,
19187   IX86_BUILTIN_CVTSD2SS,
19188   IX86_BUILTIN_CVTSS2SD,
19189   IX86_BUILTIN_CVTTSD2SI,
19190   IX86_BUILTIN_CVTTSD2SI64,
19191
19192   IX86_BUILTIN_CVTPS2DQ,
19193   IX86_BUILTIN_CVTPS2PD,
19194   IX86_BUILTIN_CVTTPS2DQ,
19195
19196   IX86_BUILTIN_MOVNTI,
19197   IX86_BUILTIN_MOVNTPD,
19198   IX86_BUILTIN_MOVNTDQ,
19199
19200   IX86_BUILTIN_MOVQ128,
19201
19202   /* SSE2 MMX */
19203   IX86_BUILTIN_MASKMOVDQU,
19204   IX86_BUILTIN_MOVMSKPD,
19205   IX86_BUILTIN_PMOVMSKB128,
19206
19207   IX86_BUILTIN_PACKSSWB128,
19208   IX86_BUILTIN_PACKSSDW128,
19209   IX86_BUILTIN_PACKUSWB128,
19210
19211   IX86_BUILTIN_PADDB128,
19212   IX86_BUILTIN_PADDW128,
19213   IX86_BUILTIN_PADDD128,
19214   IX86_BUILTIN_PADDQ128,
19215   IX86_BUILTIN_PADDSB128,
19216   IX86_BUILTIN_PADDSW128,
19217   IX86_BUILTIN_PADDUSB128,
19218   IX86_BUILTIN_PADDUSW128,
19219   IX86_BUILTIN_PSUBB128,
19220   IX86_BUILTIN_PSUBW128,
19221   IX86_BUILTIN_PSUBD128,
19222   IX86_BUILTIN_PSUBQ128,
19223   IX86_BUILTIN_PSUBSB128,
19224   IX86_BUILTIN_PSUBSW128,
19225   IX86_BUILTIN_PSUBUSB128,
19226   IX86_BUILTIN_PSUBUSW128,
19227
19228   IX86_BUILTIN_PAND128,
19229   IX86_BUILTIN_PANDN128,
19230   IX86_BUILTIN_POR128,
19231   IX86_BUILTIN_PXOR128,
19232
19233   IX86_BUILTIN_PAVGB128,
19234   IX86_BUILTIN_PAVGW128,
19235
19236   IX86_BUILTIN_PCMPEQB128,
19237   IX86_BUILTIN_PCMPEQW128,
19238   IX86_BUILTIN_PCMPEQD128,
19239   IX86_BUILTIN_PCMPGTB128,
19240   IX86_BUILTIN_PCMPGTW128,
19241   IX86_BUILTIN_PCMPGTD128,
19242
19243   IX86_BUILTIN_PMADDWD128,
19244
19245   IX86_BUILTIN_PMAXSW128,
19246   IX86_BUILTIN_PMAXUB128,
19247   IX86_BUILTIN_PMINSW128,
19248   IX86_BUILTIN_PMINUB128,
19249
19250   IX86_BUILTIN_PMULUDQ,
19251   IX86_BUILTIN_PMULUDQ128,
19252   IX86_BUILTIN_PMULHUW128,
19253   IX86_BUILTIN_PMULHW128,
19254   IX86_BUILTIN_PMULLW128,
19255
19256   IX86_BUILTIN_PSADBW128,
19257   IX86_BUILTIN_PSHUFHW,
19258   IX86_BUILTIN_PSHUFLW,
19259   IX86_BUILTIN_PSHUFD,
19260
19261   IX86_BUILTIN_PSLLDQI128,
19262   IX86_BUILTIN_PSLLWI128,
19263   IX86_BUILTIN_PSLLDI128,
19264   IX86_BUILTIN_PSLLQI128,
19265   IX86_BUILTIN_PSRAWI128,
19266   IX86_BUILTIN_PSRADI128,
19267   IX86_BUILTIN_PSRLDQI128,
19268   IX86_BUILTIN_PSRLWI128,
19269   IX86_BUILTIN_PSRLDI128,
19270   IX86_BUILTIN_PSRLQI128,
19271
19272   IX86_BUILTIN_PSLLDQ128,
19273   IX86_BUILTIN_PSLLW128,
19274   IX86_BUILTIN_PSLLD128,
19275   IX86_BUILTIN_PSLLQ128,
19276   IX86_BUILTIN_PSRAW128,
19277   IX86_BUILTIN_PSRAD128,
19278   IX86_BUILTIN_PSRLW128,
19279   IX86_BUILTIN_PSRLD128,
19280   IX86_BUILTIN_PSRLQ128,
19281
19282   IX86_BUILTIN_PUNPCKHBW128,
19283   IX86_BUILTIN_PUNPCKHWD128,
19284   IX86_BUILTIN_PUNPCKHDQ128,
19285   IX86_BUILTIN_PUNPCKHQDQ128,
19286   IX86_BUILTIN_PUNPCKLBW128,
19287   IX86_BUILTIN_PUNPCKLWD128,
19288   IX86_BUILTIN_PUNPCKLDQ128,
19289   IX86_BUILTIN_PUNPCKLQDQ128,
19290
19291   IX86_BUILTIN_CLFLUSH,
19292   IX86_BUILTIN_MFENCE,
19293   IX86_BUILTIN_LFENCE,
19294
19295   /* SSE3.  */
19296   IX86_BUILTIN_ADDSUBPS,
19297   IX86_BUILTIN_HADDPS,
19298   IX86_BUILTIN_HSUBPS,
19299   IX86_BUILTIN_MOVSHDUP,
19300   IX86_BUILTIN_MOVSLDUP,
19301   IX86_BUILTIN_ADDSUBPD,
19302   IX86_BUILTIN_HADDPD,
19303   IX86_BUILTIN_HSUBPD,
19304   IX86_BUILTIN_LDDQU,
19305
19306   IX86_BUILTIN_MONITOR,
19307   IX86_BUILTIN_MWAIT,
19308
19309   /* SSSE3.  */
19310   IX86_BUILTIN_PHADDW,
19311   IX86_BUILTIN_PHADDD,
19312   IX86_BUILTIN_PHADDSW,
19313   IX86_BUILTIN_PHSUBW,
19314   IX86_BUILTIN_PHSUBD,
19315   IX86_BUILTIN_PHSUBSW,
19316   IX86_BUILTIN_PMADDUBSW,
19317   IX86_BUILTIN_PMULHRSW,
19318   IX86_BUILTIN_PSHUFB,
19319   IX86_BUILTIN_PSIGNB,
19320   IX86_BUILTIN_PSIGNW,
19321   IX86_BUILTIN_PSIGND,
19322   IX86_BUILTIN_PALIGNR,
19323   IX86_BUILTIN_PABSB,
19324   IX86_BUILTIN_PABSW,
19325   IX86_BUILTIN_PABSD,
19326
19327   IX86_BUILTIN_PHADDW128,
19328   IX86_BUILTIN_PHADDD128,
19329   IX86_BUILTIN_PHADDSW128,
19330   IX86_BUILTIN_PHSUBW128,
19331   IX86_BUILTIN_PHSUBD128,
19332   IX86_BUILTIN_PHSUBSW128,
19333   IX86_BUILTIN_PMADDUBSW128,
19334   IX86_BUILTIN_PMULHRSW128,
19335   IX86_BUILTIN_PSHUFB128,
19336   IX86_BUILTIN_PSIGNB128,
19337   IX86_BUILTIN_PSIGNW128,
19338   IX86_BUILTIN_PSIGND128,
19339   IX86_BUILTIN_PALIGNR128,
19340   IX86_BUILTIN_PABSB128,
19341   IX86_BUILTIN_PABSW128,
19342   IX86_BUILTIN_PABSD128,
19343
19344   /* AMDFAM10 - SSE4A New Instructions.  */
19345   IX86_BUILTIN_MOVNTSD,
19346   IX86_BUILTIN_MOVNTSS,
19347   IX86_BUILTIN_EXTRQI,
19348   IX86_BUILTIN_EXTRQ,
19349   IX86_BUILTIN_INSERTQI,
19350   IX86_BUILTIN_INSERTQ,
19351
19352   /* SSE4.1.  */
19353   IX86_BUILTIN_BLENDPD,
19354   IX86_BUILTIN_BLENDPS,
19355   IX86_BUILTIN_BLENDVPD,
19356   IX86_BUILTIN_BLENDVPS,
19357   IX86_BUILTIN_PBLENDVB128,
19358   IX86_BUILTIN_PBLENDW128,
19359
19360   IX86_BUILTIN_DPPD,
19361   IX86_BUILTIN_DPPS,
19362
19363   IX86_BUILTIN_INSERTPS128,
19364
19365   IX86_BUILTIN_MOVNTDQA,
19366   IX86_BUILTIN_MPSADBW128,
19367   IX86_BUILTIN_PACKUSDW128,
19368   IX86_BUILTIN_PCMPEQQ,
19369   IX86_BUILTIN_PHMINPOSUW128,
19370
19371   IX86_BUILTIN_PMAXSB128,
19372   IX86_BUILTIN_PMAXSD128,
19373   IX86_BUILTIN_PMAXUD128,
19374   IX86_BUILTIN_PMAXUW128,
19375
19376   IX86_BUILTIN_PMINSB128,
19377   IX86_BUILTIN_PMINSD128,
19378   IX86_BUILTIN_PMINUD128,
19379   IX86_BUILTIN_PMINUW128,
19380
19381   IX86_BUILTIN_PMOVSXBW128,
19382   IX86_BUILTIN_PMOVSXBD128,
19383   IX86_BUILTIN_PMOVSXBQ128,
19384   IX86_BUILTIN_PMOVSXWD128,
19385   IX86_BUILTIN_PMOVSXWQ128,
19386   IX86_BUILTIN_PMOVSXDQ128,
19387
19388   IX86_BUILTIN_PMOVZXBW128,
19389   IX86_BUILTIN_PMOVZXBD128,
19390   IX86_BUILTIN_PMOVZXBQ128,
19391   IX86_BUILTIN_PMOVZXWD128,
19392   IX86_BUILTIN_PMOVZXWQ128,
19393   IX86_BUILTIN_PMOVZXDQ128,
19394
19395   IX86_BUILTIN_PMULDQ128,
19396   IX86_BUILTIN_PMULLD128,
19397
19398   IX86_BUILTIN_ROUNDPD,
19399   IX86_BUILTIN_ROUNDPS,
19400   IX86_BUILTIN_ROUNDSD,
19401   IX86_BUILTIN_ROUNDSS,
19402
19403   IX86_BUILTIN_PTESTZ,
19404   IX86_BUILTIN_PTESTC,
19405   IX86_BUILTIN_PTESTNZC,
19406
19407   IX86_BUILTIN_VEC_INIT_V2SI,
19408   IX86_BUILTIN_VEC_INIT_V4HI,
19409   IX86_BUILTIN_VEC_INIT_V8QI,
19410   IX86_BUILTIN_VEC_EXT_V2DF,
19411   IX86_BUILTIN_VEC_EXT_V2DI,
19412   IX86_BUILTIN_VEC_EXT_V4SF,
19413   IX86_BUILTIN_VEC_EXT_V4SI,
19414   IX86_BUILTIN_VEC_EXT_V8HI,
19415   IX86_BUILTIN_VEC_EXT_V2SI,
19416   IX86_BUILTIN_VEC_EXT_V4HI,
19417   IX86_BUILTIN_VEC_EXT_V16QI,
19418   IX86_BUILTIN_VEC_SET_V2DI,
19419   IX86_BUILTIN_VEC_SET_V4SF,
19420   IX86_BUILTIN_VEC_SET_V4SI,
19421   IX86_BUILTIN_VEC_SET_V8HI,
19422   IX86_BUILTIN_VEC_SET_V4HI,
19423   IX86_BUILTIN_VEC_SET_V16QI,
19424
19425   IX86_BUILTIN_VEC_PACK_SFIX,
19426
19427   /* SSE4.2.  */
19428   IX86_BUILTIN_CRC32QI,
19429   IX86_BUILTIN_CRC32HI,
19430   IX86_BUILTIN_CRC32SI,
19431   IX86_BUILTIN_CRC32DI,
19432
19433   IX86_BUILTIN_PCMPESTRI128,
19434   IX86_BUILTIN_PCMPESTRM128,
19435   IX86_BUILTIN_PCMPESTRA128,
19436   IX86_BUILTIN_PCMPESTRC128,
19437   IX86_BUILTIN_PCMPESTRO128,
19438   IX86_BUILTIN_PCMPESTRS128,
19439   IX86_BUILTIN_PCMPESTRZ128,
19440   IX86_BUILTIN_PCMPISTRI128,
19441   IX86_BUILTIN_PCMPISTRM128,
19442   IX86_BUILTIN_PCMPISTRA128,
19443   IX86_BUILTIN_PCMPISTRC128,
19444   IX86_BUILTIN_PCMPISTRO128,
19445   IX86_BUILTIN_PCMPISTRS128,
19446   IX86_BUILTIN_PCMPISTRZ128,
19447
19448   IX86_BUILTIN_PCMPGTQ,
19449
19450   /* AES instructions */
19451   IX86_BUILTIN_AESENC128,
19452   IX86_BUILTIN_AESENCLAST128,
19453   IX86_BUILTIN_AESDEC128,
19454   IX86_BUILTIN_AESDECLAST128,
19455   IX86_BUILTIN_AESIMC128,
19456   IX86_BUILTIN_AESKEYGENASSIST128,
19457
19458   /* PCLMUL instruction */
19459   IX86_BUILTIN_PCLMULQDQ128,
19460
19461   /* AVX */
19462   IX86_BUILTIN_ADDPD256,
19463   IX86_BUILTIN_ADDPS256,
19464   IX86_BUILTIN_ADDSUBPD256,
19465   IX86_BUILTIN_ADDSUBPS256,
19466   IX86_BUILTIN_ANDPD256,
19467   IX86_BUILTIN_ANDPS256,
19468   IX86_BUILTIN_ANDNPD256,
19469   IX86_BUILTIN_ANDNPS256,
19470   IX86_BUILTIN_BLENDPD256,
19471   IX86_BUILTIN_BLENDPS256,
19472   IX86_BUILTIN_BLENDVPD256,
19473   IX86_BUILTIN_BLENDVPS256,
19474   IX86_BUILTIN_DIVPD256,
19475   IX86_BUILTIN_DIVPS256,
19476   IX86_BUILTIN_DPPS256,
19477   IX86_BUILTIN_HADDPD256,
19478   IX86_BUILTIN_HADDPS256,
19479   IX86_BUILTIN_HSUBPD256,
19480   IX86_BUILTIN_HSUBPS256,
19481   IX86_BUILTIN_MAXPD256,
19482   IX86_BUILTIN_MAXPS256,
19483   IX86_BUILTIN_MINPD256,
19484   IX86_BUILTIN_MINPS256,
19485   IX86_BUILTIN_MULPD256,
19486   IX86_BUILTIN_MULPS256,
19487   IX86_BUILTIN_ORPD256,
19488   IX86_BUILTIN_ORPS256,
19489   IX86_BUILTIN_SHUFPD256,
19490   IX86_BUILTIN_SHUFPS256,
19491   IX86_BUILTIN_SUBPD256,
19492   IX86_BUILTIN_SUBPS256,
19493   IX86_BUILTIN_XORPD256,
19494   IX86_BUILTIN_XORPS256,
19495   IX86_BUILTIN_CMPSD,
19496   IX86_BUILTIN_CMPSS,
19497   IX86_BUILTIN_CMPPD,
19498   IX86_BUILTIN_CMPPS,
19499   IX86_BUILTIN_CMPPD256,
19500   IX86_BUILTIN_CMPPS256,
19501   IX86_BUILTIN_CVTDQ2PD256,
19502   IX86_BUILTIN_CVTDQ2PS256,
19503   IX86_BUILTIN_CVTPD2PS256,
19504   IX86_BUILTIN_CVTPS2DQ256,
19505   IX86_BUILTIN_CVTPS2PD256,
19506   IX86_BUILTIN_CVTTPD2DQ256,
19507   IX86_BUILTIN_CVTPD2DQ256,
19508   IX86_BUILTIN_CVTTPS2DQ256,
19509   IX86_BUILTIN_EXTRACTF128PD256,
19510   IX86_BUILTIN_EXTRACTF128PS256,
19511   IX86_BUILTIN_EXTRACTF128SI256,
19512   IX86_BUILTIN_VZEROALL,
19513   IX86_BUILTIN_VZEROUPPER,
19514   IX86_BUILTIN_VZEROUPPER_REX64,
19515   IX86_BUILTIN_VPERMILVARPD,
19516   IX86_BUILTIN_VPERMILVARPS,
19517   IX86_BUILTIN_VPERMILVARPD256,
19518   IX86_BUILTIN_VPERMILVARPS256,
19519   IX86_BUILTIN_VPERMILPD,
19520   IX86_BUILTIN_VPERMILPS,
19521   IX86_BUILTIN_VPERMILPD256,
19522   IX86_BUILTIN_VPERMILPS256,
19523   IX86_BUILTIN_VPERMIL2PD,
19524   IX86_BUILTIN_VPERMIL2PS,
19525   IX86_BUILTIN_VPERMIL2PD256,
19526   IX86_BUILTIN_VPERMIL2PS256,
19527   IX86_BUILTIN_VPERM2F128PD256,
19528   IX86_BUILTIN_VPERM2F128PS256,
19529   IX86_BUILTIN_VPERM2F128SI256,
19530   IX86_BUILTIN_VBROADCASTSS,
19531   IX86_BUILTIN_VBROADCASTSD256,
19532   IX86_BUILTIN_VBROADCASTSS256,
19533   IX86_BUILTIN_VBROADCASTPD256,
19534   IX86_BUILTIN_VBROADCASTPS256,
19535   IX86_BUILTIN_VINSERTF128PD256,
19536   IX86_BUILTIN_VINSERTF128PS256,
19537   IX86_BUILTIN_VINSERTF128SI256,
19538   IX86_BUILTIN_LOADUPD256,
19539   IX86_BUILTIN_LOADUPS256,
19540   IX86_BUILTIN_STOREUPD256,
19541   IX86_BUILTIN_STOREUPS256,
19542   IX86_BUILTIN_LDDQU256,
19543   IX86_BUILTIN_LOADDQU256,
19544   IX86_BUILTIN_STOREDQU256,
19545   IX86_BUILTIN_MASKLOADPD,
19546   IX86_BUILTIN_MASKLOADPS,
19547   IX86_BUILTIN_MASKSTOREPD,
19548   IX86_BUILTIN_MASKSTOREPS,
19549   IX86_BUILTIN_MASKLOADPD256,
19550   IX86_BUILTIN_MASKLOADPS256,
19551   IX86_BUILTIN_MASKSTOREPD256,
19552   IX86_BUILTIN_MASKSTOREPS256,
19553   IX86_BUILTIN_MOVSHDUP256,
19554   IX86_BUILTIN_MOVSLDUP256,
19555   IX86_BUILTIN_MOVDDUP256,
19556
19557   IX86_BUILTIN_SQRTPD256,
19558   IX86_BUILTIN_SQRTPS256,
19559   IX86_BUILTIN_SQRTPS_NR256,
19560   IX86_BUILTIN_RSQRTPS256,
19561   IX86_BUILTIN_RSQRTPS_NR256,
19562
19563   IX86_BUILTIN_RCPPS256,
19564
19565   IX86_BUILTIN_ROUNDPD256,
19566   IX86_BUILTIN_ROUNDPS256,
19567
19568   IX86_BUILTIN_UNPCKHPD256,
19569   IX86_BUILTIN_UNPCKLPD256,
19570   IX86_BUILTIN_UNPCKHPS256,
19571   IX86_BUILTIN_UNPCKLPS256,
19572
19573   IX86_BUILTIN_SI256_SI,
19574   IX86_BUILTIN_PS256_PS,
19575   IX86_BUILTIN_PD256_PD,
19576   IX86_BUILTIN_SI_SI256,
19577   IX86_BUILTIN_PS_PS256,
19578   IX86_BUILTIN_PD_PD256,
19579
19580   IX86_BUILTIN_VTESTZPD,
19581   IX86_BUILTIN_VTESTCPD,
19582   IX86_BUILTIN_VTESTNZCPD,
19583   IX86_BUILTIN_VTESTZPS,
19584   IX86_BUILTIN_VTESTCPS,
19585   IX86_BUILTIN_VTESTNZCPS,
19586   IX86_BUILTIN_VTESTZPD256,
19587   IX86_BUILTIN_VTESTCPD256,
19588   IX86_BUILTIN_VTESTNZCPD256,
19589   IX86_BUILTIN_VTESTZPS256,
19590   IX86_BUILTIN_VTESTCPS256,
19591   IX86_BUILTIN_VTESTNZCPS256,
19592   IX86_BUILTIN_PTESTZ256,
19593   IX86_BUILTIN_PTESTC256,
19594   IX86_BUILTIN_PTESTNZC256,
19595
19596   IX86_BUILTIN_MOVMSKPD256,
19597   IX86_BUILTIN_MOVMSKPS256,
19598
19599   /* TFmode support builtins.  */
19600   IX86_BUILTIN_INFQ,
19601   IX86_BUILTIN_FABSQ,
19602   IX86_BUILTIN_COPYSIGNQ,
19603
19604   /* SSE5 instructions */
19605   IX86_BUILTIN_FMADDSS,
19606   IX86_BUILTIN_FMADDSD,
19607   IX86_BUILTIN_FMADDPS,
19608   IX86_BUILTIN_FMADDPD,
19609   IX86_BUILTIN_FMSUBSS,
19610   IX86_BUILTIN_FMSUBSD,
19611   IX86_BUILTIN_FMSUBPS,
19612   IX86_BUILTIN_FMSUBPD,
19613   IX86_BUILTIN_FNMADDSS,
19614   IX86_BUILTIN_FNMADDSD,
19615   IX86_BUILTIN_FNMADDPS,
19616   IX86_BUILTIN_FNMADDPD,
19617   IX86_BUILTIN_FNMSUBSS,
19618   IX86_BUILTIN_FNMSUBSD,
19619   IX86_BUILTIN_FNMSUBPS,
19620   IX86_BUILTIN_FNMSUBPD,
19621   IX86_BUILTIN_PCMOV,
19622   IX86_BUILTIN_PCMOV_V2DI,
19623   IX86_BUILTIN_PCMOV_V4SI,
19624   IX86_BUILTIN_PCMOV_V8HI,
19625   IX86_BUILTIN_PCMOV_V16QI,
19626   IX86_BUILTIN_PCMOV_V4SF,
19627   IX86_BUILTIN_PCMOV_V2DF,
19628   IX86_BUILTIN_PPERM,
19629   IX86_BUILTIN_PERMPS,
19630   IX86_BUILTIN_PERMPD,
19631   IX86_BUILTIN_PMACSSWW,
19632   IX86_BUILTIN_PMACSWW,
19633   IX86_BUILTIN_PMACSSWD,
19634   IX86_BUILTIN_PMACSWD,
19635   IX86_BUILTIN_PMACSSDD,
19636   IX86_BUILTIN_PMACSDD,
19637   IX86_BUILTIN_PMACSSDQL,
19638   IX86_BUILTIN_PMACSSDQH,
19639   IX86_BUILTIN_PMACSDQL,
19640   IX86_BUILTIN_PMACSDQH,
19641   IX86_BUILTIN_PMADCSSWD,
19642   IX86_BUILTIN_PMADCSWD,
19643   IX86_BUILTIN_PHADDBW,
19644   IX86_BUILTIN_PHADDBD,
19645   IX86_BUILTIN_PHADDBQ,
19646   IX86_BUILTIN_PHADDWD,
19647   IX86_BUILTIN_PHADDWQ,
19648   IX86_BUILTIN_PHADDDQ,
19649   IX86_BUILTIN_PHADDUBW,
19650   IX86_BUILTIN_PHADDUBD,
19651   IX86_BUILTIN_PHADDUBQ,
19652   IX86_BUILTIN_PHADDUWD,
19653   IX86_BUILTIN_PHADDUWQ,
19654   IX86_BUILTIN_PHADDUDQ,
19655   IX86_BUILTIN_PHSUBBW,
19656   IX86_BUILTIN_PHSUBWD,
19657   IX86_BUILTIN_PHSUBDQ,
19658   IX86_BUILTIN_PROTB,
19659   IX86_BUILTIN_PROTW,
19660   IX86_BUILTIN_PROTD,
19661   IX86_BUILTIN_PROTQ,
19662   IX86_BUILTIN_PROTB_IMM,
19663   IX86_BUILTIN_PROTW_IMM,
19664   IX86_BUILTIN_PROTD_IMM,
19665   IX86_BUILTIN_PROTQ_IMM,
19666   IX86_BUILTIN_PSHLB,
19667   IX86_BUILTIN_PSHLW,
19668   IX86_BUILTIN_PSHLD,
19669   IX86_BUILTIN_PSHLQ,
19670   IX86_BUILTIN_PSHAB,
19671   IX86_BUILTIN_PSHAW,
19672   IX86_BUILTIN_PSHAD,
19673   IX86_BUILTIN_PSHAQ,
19674   IX86_BUILTIN_FRCZSS,
19675   IX86_BUILTIN_FRCZSD,
19676   IX86_BUILTIN_FRCZPS,
19677   IX86_BUILTIN_FRCZPD,
19678   IX86_BUILTIN_CVTPH2PS,
19679   IX86_BUILTIN_CVTPS2PH,
19680
19681   IX86_BUILTIN_COMEQSS,
19682   IX86_BUILTIN_COMNESS,
19683   IX86_BUILTIN_COMLTSS,
19684   IX86_BUILTIN_COMLESS,
19685   IX86_BUILTIN_COMGTSS,
19686   IX86_BUILTIN_COMGESS,
19687   IX86_BUILTIN_COMUEQSS,
19688   IX86_BUILTIN_COMUNESS,
19689   IX86_BUILTIN_COMULTSS,
19690   IX86_BUILTIN_COMULESS,
19691   IX86_BUILTIN_COMUGTSS,
19692   IX86_BUILTIN_COMUGESS,
19693   IX86_BUILTIN_COMORDSS,
19694   IX86_BUILTIN_COMUNORDSS,
19695   IX86_BUILTIN_COMFALSESS,
19696   IX86_BUILTIN_COMTRUESS,
19697
19698   IX86_BUILTIN_COMEQSD,
19699   IX86_BUILTIN_COMNESD,
19700   IX86_BUILTIN_COMLTSD,
19701   IX86_BUILTIN_COMLESD,
19702   IX86_BUILTIN_COMGTSD,
19703   IX86_BUILTIN_COMGESD,
19704   IX86_BUILTIN_COMUEQSD,
19705   IX86_BUILTIN_COMUNESD,
19706   IX86_BUILTIN_COMULTSD,
19707   IX86_BUILTIN_COMULESD,
19708   IX86_BUILTIN_COMUGTSD,
19709   IX86_BUILTIN_COMUGESD,
19710   IX86_BUILTIN_COMORDSD,
19711   IX86_BUILTIN_COMUNORDSD,
19712   IX86_BUILTIN_COMFALSESD,
19713   IX86_BUILTIN_COMTRUESD,
19714
19715   IX86_BUILTIN_COMEQPS,
19716   IX86_BUILTIN_COMNEPS,
19717   IX86_BUILTIN_COMLTPS,
19718   IX86_BUILTIN_COMLEPS,
19719   IX86_BUILTIN_COMGTPS,
19720   IX86_BUILTIN_COMGEPS,
19721   IX86_BUILTIN_COMUEQPS,
19722   IX86_BUILTIN_COMUNEPS,
19723   IX86_BUILTIN_COMULTPS,
19724   IX86_BUILTIN_COMULEPS,
19725   IX86_BUILTIN_COMUGTPS,
19726   IX86_BUILTIN_COMUGEPS,
19727   IX86_BUILTIN_COMORDPS,
19728   IX86_BUILTIN_COMUNORDPS,
19729   IX86_BUILTIN_COMFALSEPS,
19730   IX86_BUILTIN_COMTRUEPS,
19731
19732   IX86_BUILTIN_COMEQPD,
19733   IX86_BUILTIN_COMNEPD,
19734   IX86_BUILTIN_COMLTPD,
19735   IX86_BUILTIN_COMLEPD,
19736   IX86_BUILTIN_COMGTPD,
19737   IX86_BUILTIN_COMGEPD,
19738   IX86_BUILTIN_COMUEQPD,
19739   IX86_BUILTIN_COMUNEPD,
19740   IX86_BUILTIN_COMULTPD,
19741   IX86_BUILTIN_COMULEPD,
19742   IX86_BUILTIN_COMUGTPD,
19743   IX86_BUILTIN_COMUGEPD,
19744   IX86_BUILTIN_COMORDPD,
19745   IX86_BUILTIN_COMUNORDPD,
19746   IX86_BUILTIN_COMFALSEPD,
19747   IX86_BUILTIN_COMTRUEPD,
19748
19749   IX86_BUILTIN_PCOMEQUB,
19750   IX86_BUILTIN_PCOMNEUB,
19751   IX86_BUILTIN_PCOMLTUB,
19752   IX86_BUILTIN_PCOMLEUB,
19753   IX86_BUILTIN_PCOMGTUB,
19754   IX86_BUILTIN_PCOMGEUB,
19755   IX86_BUILTIN_PCOMFALSEUB,
19756   IX86_BUILTIN_PCOMTRUEUB,
19757   IX86_BUILTIN_PCOMEQUW,
19758   IX86_BUILTIN_PCOMNEUW,
19759   IX86_BUILTIN_PCOMLTUW,
19760   IX86_BUILTIN_PCOMLEUW,
19761   IX86_BUILTIN_PCOMGTUW,
19762   IX86_BUILTIN_PCOMGEUW,
19763   IX86_BUILTIN_PCOMFALSEUW,
19764   IX86_BUILTIN_PCOMTRUEUW,
19765   IX86_BUILTIN_PCOMEQUD,
19766   IX86_BUILTIN_PCOMNEUD,
19767   IX86_BUILTIN_PCOMLTUD,
19768   IX86_BUILTIN_PCOMLEUD,
19769   IX86_BUILTIN_PCOMGTUD,
19770   IX86_BUILTIN_PCOMGEUD,
19771   IX86_BUILTIN_PCOMFALSEUD,
19772   IX86_BUILTIN_PCOMTRUEUD,
19773   IX86_BUILTIN_PCOMEQUQ,
19774   IX86_BUILTIN_PCOMNEUQ,
19775   IX86_BUILTIN_PCOMLTUQ,
19776   IX86_BUILTIN_PCOMLEUQ,
19777   IX86_BUILTIN_PCOMGTUQ,
19778   IX86_BUILTIN_PCOMGEUQ,
19779   IX86_BUILTIN_PCOMFALSEUQ,
19780   IX86_BUILTIN_PCOMTRUEUQ,
19781
19782   IX86_BUILTIN_PCOMEQB,
19783   IX86_BUILTIN_PCOMNEB,
19784   IX86_BUILTIN_PCOMLTB,
19785   IX86_BUILTIN_PCOMLEB,
19786   IX86_BUILTIN_PCOMGTB,
19787   IX86_BUILTIN_PCOMGEB,
19788   IX86_BUILTIN_PCOMFALSEB,
19789   IX86_BUILTIN_PCOMTRUEB,
19790   IX86_BUILTIN_PCOMEQW,
19791   IX86_BUILTIN_PCOMNEW,
19792   IX86_BUILTIN_PCOMLTW,
19793   IX86_BUILTIN_PCOMLEW,
19794   IX86_BUILTIN_PCOMGTW,
19795   IX86_BUILTIN_PCOMGEW,
19796   IX86_BUILTIN_PCOMFALSEW,
19797   IX86_BUILTIN_PCOMTRUEW,
19798   IX86_BUILTIN_PCOMEQD,
19799   IX86_BUILTIN_PCOMNED,
19800   IX86_BUILTIN_PCOMLTD,
19801   IX86_BUILTIN_PCOMLED,
19802   IX86_BUILTIN_PCOMGTD,
19803   IX86_BUILTIN_PCOMGED,
19804   IX86_BUILTIN_PCOMFALSED,
19805   IX86_BUILTIN_PCOMTRUED,
19806   IX86_BUILTIN_PCOMEQQ,
19807   IX86_BUILTIN_PCOMNEQ,
19808   IX86_BUILTIN_PCOMLTQ,
19809   IX86_BUILTIN_PCOMLEQ,
19810   IX86_BUILTIN_PCOMGTQ,
19811   IX86_BUILTIN_PCOMGEQ,
19812   IX86_BUILTIN_PCOMFALSEQ,
19813   IX86_BUILTIN_PCOMTRUEQ,
19814
19815   IX86_BUILTIN_MAX
19816 };
19817
19818 /* Table for the ix86 builtin decls.  */
19819 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
19820
19821 /* Table of all of the builtin functions that are possible with different ISA's
19822    but are waiting to be built until a function is declared to use that
19823    ISA.  */
19824 struct builtin_isa GTY(())
19825 {
19826   tree type;                    /* builtin type to use in the declaration */
19827   const char *name;             /* function name */
19828   int isa;                      /* isa_flags this builtin is defined for */
19829   bool const_p;                 /* true if the declaration is constant */
19830 };
19831
19832 static GTY(()) struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
19833
19834
19835 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
19836  * of which isa_flags to use in the ix86_builtins_isa array.  Stores the
19837  * function decl in the ix86_builtins array.  Returns the function decl or
19838  * NULL_TREE, if the builtin was not added.
19839  *
19840  * If the front end has a special hook for builtin functions, delay adding
19841  * builtin functions that aren't in the current ISA until the ISA is changed
19842  * with function specific optimization.  Doing so, can save about 300K for the
19843  * default compiler.  When the builtin is expanded, check at that time whether
19844  * it is valid.
19845  *
19846  * If the front end doesn't have a special hook, record all builtins, even if
19847  * it isn't an instruction set in the current ISA in case the user uses
19848  * function specific options for a different ISA, so that we don't get scope
19849  * errors if a builtin is added in the middle of a function scope.  */
19850
19851 static inline tree
19852 def_builtin (int mask, const char *name, tree type, enum ix86_builtins code)
19853 {
19854   tree decl = NULL_TREE;
19855
19856   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
19857     {
19858       ix86_builtins_isa[(int) code].isa = mask;
19859
19860       if ((mask & ix86_isa_flags) != 0
19861           || (lang_hooks.builtin_function
19862               == lang_hooks.builtin_function_ext_scope))
19863
19864         {
19865           decl = add_builtin_function (name, type, code, BUILT_IN_MD, NULL,
19866                                        NULL_TREE);
19867           ix86_builtins[(int) code] = decl;
19868           ix86_builtins_isa[(int) code].type = NULL_TREE;
19869         }
19870       else
19871         {
19872           ix86_builtins[(int) code] = NULL_TREE;
19873           ix86_builtins_isa[(int) code].const_p = false;
19874           ix86_builtins_isa[(int) code].type = type;
19875           ix86_builtins_isa[(int) code].name = name;
19876         }
19877     }
19878
19879   return decl;
19880 }
19881
19882 /* Like def_builtin, but also marks the function decl "const".  */
19883
19884 static inline tree
19885 def_builtin_const (int mask, const char *name, tree type,
19886                    enum ix86_builtins code)
19887 {
19888   tree decl = def_builtin (mask, name, type, code);
19889   if (decl)
19890     TREE_READONLY (decl) = 1;
19891   else
19892     ix86_builtins_isa[(int) code].const_p = true;
19893
19894   return decl;
19895 }
19896
19897 /* Add any new builtin functions for a given ISA that may not have been
19898    declared.  This saves a bit of space compared to adding all of the
19899    declarations to the tree, even if we didn't use them.  */
19900
19901 static void
19902 ix86_add_new_builtins (int isa)
19903 {
19904   int i;
19905   tree decl;
19906
19907   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
19908     {
19909       if ((ix86_builtins_isa[i].isa & isa) != 0
19910           && ix86_builtins_isa[i].type != NULL_TREE)
19911         {
19912           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
19913                                                  ix86_builtins_isa[i].type,
19914                                                  i, BUILT_IN_MD, NULL,
19915                                                  NULL_TREE);
19916
19917           ix86_builtins[i] = decl;
19918           ix86_builtins_isa[i].type = NULL_TREE;
19919           if (ix86_builtins_isa[i].const_p)
19920             TREE_READONLY (decl) = 1;
19921         }
19922     }
19923 }
19924
19925 /* Bits for builtin_description.flag.  */
19926
19927 /* Set when we don't support the comparison natively, and should
19928    swap_comparison in order to support it.  */
19929 #define BUILTIN_DESC_SWAP_OPERANDS      1
19930
19931 struct builtin_description
19932 {
19933   const unsigned int mask;
19934   const enum insn_code icode;
19935   const char *const name;
19936   const enum ix86_builtins code;
19937   const enum rtx_code comparison;
19938   const int flag;
19939 };
19940
19941 static const struct builtin_description bdesc_comi[] =
19942 {
19943   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
19944   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
19945   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
19946   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
19947   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
19948   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
19949   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
19950   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
19951   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
19952   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
19953   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
19954   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
19955   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
19956   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
19957   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
19958   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
19959   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
19960   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
19961   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
19962   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
19963   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
19964   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
19965   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
19966   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
19967 };
19968
19969 static const struct builtin_description bdesc_pcmpestr[] =
19970 {
19971   /* SSE4.2 */
19972   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
19973   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
19974   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
19975   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
19976   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
19977   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
19978   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
19979 };
19980
19981 static const struct builtin_description bdesc_pcmpistr[] =
19982 {
19983   /* SSE4.2 */
19984   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
19985   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
19986   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
19987   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
19988   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
19989   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
19990   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
19991 };
19992
19993 /* Special builtin types */
19994 enum ix86_special_builtin_type
19995 {
19996   SPECIAL_FTYPE_UNKNOWN,
19997   VOID_FTYPE_VOID,
19998   V32QI_FTYPE_PCCHAR,
19999   V16QI_FTYPE_PCCHAR,
20000   V8SF_FTYPE_PCV4SF,
20001   V8SF_FTYPE_PCFLOAT,
20002   V4DF_FTYPE_PCV2DF,
20003   V4DF_FTYPE_PCDOUBLE,
20004   V4SF_FTYPE_PCFLOAT,
20005   V2DF_FTYPE_PCDOUBLE,
20006   V8SF_FTYPE_PCV8SF_V8SF,
20007   V4DF_FTYPE_PCV4DF_V4DF,
20008   V4SF_FTYPE_V4SF_PCV2SF,
20009   V4SF_FTYPE_PCV4SF_V4SF,
20010   V2DF_FTYPE_V2DF_PCDOUBLE,
20011   V2DF_FTYPE_PCV2DF_V2DF,
20012   V2DI_FTYPE_PV2DI,
20013   VOID_FTYPE_PV2SF_V4SF,
20014   VOID_FTYPE_PV2DI_V2DI,
20015   VOID_FTYPE_PCHAR_V32QI,
20016   VOID_FTYPE_PCHAR_V16QI,
20017   VOID_FTYPE_PFLOAT_V8SF,
20018   VOID_FTYPE_PFLOAT_V4SF,
20019   VOID_FTYPE_PDOUBLE_V4DF,
20020   VOID_FTYPE_PDOUBLE_V2DF,
20021   VOID_FTYPE_PDI_DI,
20022   VOID_FTYPE_PINT_INT,
20023   VOID_FTYPE_PV8SF_V8SF_V8SF,
20024   VOID_FTYPE_PV4DF_V4DF_V4DF,
20025   VOID_FTYPE_PV4SF_V4SF_V4SF,
20026   VOID_FTYPE_PV2DF_V2DF_V2DF
20027 };
20028
20029 /* Builtin types */
20030 enum ix86_builtin_type
20031 {
20032   FTYPE_UNKNOWN,
20033   FLOAT128_FTYPE_FLOAT128,
20034   FLOAT_FTYPE_FLOAT,
20035   FLOAT128_FTYPE_FLOAT128_FLOAT128,
20036   INT_FTYPE_V8SF_V8SF_PTEST,
20037   INT_FTYPE_V4DI_V4DI_PTEST,
20038   INT_FTYPE_V4DF_V4DF_PTEST,
20039   INT_FTYPE_V4SF_V4SF_PTEST,
20040   INT_FTYPE_V2DI_V2DI_PTEST,
20041   INT_FTYPE_V2DF_V2DF_PTEST,
20042   INT64_FTYPE_V4SF,
20043   INT64_FTYPE_V2DF,
20044   INT_FTYPE_V16QI,
20045   INT_FTYPE_V8QI,
20046   INT_FTYPE_V8SF,
20047   INT_FTYPE_V4DF,
20048   INT_FTYPE_V4SF,
20049   INT_FTYPE_V2DF,
20050   V16QI_FTYPE_V16QI,
20051   V8SI_FTYPE_V8SF,
20052   V8SI_FTYPE_V4SI,
20053   V8HI_FTYPE_V8HI,
20054   V8HI_FTYPE_V16QI,
20055   V8QI_FTYPE_V8QI,
20056   V8SF_FTYPE_V8SF,
20057   V8SF_FTYPE_V8SI,
20058   V8SF_FTYPE_V4SF,
20059   V4SI_FTYPE_V4SI,
20060   V4SI_FTYPE_V16QI,
20061   V4SI_FTYPE_V8SI,
20062   V4SI_FTYPE_V8HI,
20063   V4SI_FTYPE_V4DF,
20064   V4SI_FTYPE_V4SF,
20065   V4SI_FTYPE_V2DF,
20066   V4HI_FTYPE_V4HI,
20067   V4DF_FTYPE_V4DF,
20068   V4DF_FTYPE_V4SI,
20069   V4DF_FTYPE_V4SF,
20070   V4DF_FTYPE_V2DF,
20071   V4SF_FTYPE_V4DF,
20072   V4SF_FTYPE_V4SF,
20073   V4SF_FTYPE_V4SF_VEC_MERGE,
20074   V4SF_FTYPE_V8SF,
20075   V4SF_FTYPE_V4SI,
20076   V4SF_FTYPE_V2DF,
20077   V2DI_FTYPE_V2DI,
20078   V2DI_FTYPE_V16QI,
20079   V2DI_FTYPE_V8HI,
20080   V2DI_FTYPE_V4SI,
20081   V2DF_FTYPE_V2DF,
20082   V2DF_FTYPE_V2DF_VEC_MERGE,
20083   V2DF_FTYPE_V4SI,
20084   V2DF_FTYPE_V4DF,
20085   V2DF_FTYPE_V4SF,
20086   V2DF_FTYPE_V2SI,
20087   V2SI_FTYPE_V2SI,
20088   V2SI_FTYPE_V4SF,
20089   V2SI_FTYPE_V2SF,
20090   V2SI_FTYPE_V2DF,
20091   V2SF_FTYPE_V2SF,
20092   V2SF_FTYPE_V2SI,
20093   V16QI_FTYPE_V16QI_V16QI,
20094   V16QI_FTYPE_V8HI_V8HI,
20095   V8QI_FTYPE_V8QI_V8QI,
20096   V8QI_FTYPE_V4HI_V4HI,
20097   V8HI_FTYPE_V8HI_V8HI,
20098   V8HI_FTYPE_V8HI_V8HI_COUNT,
20099   V8HI_FTYPE_V16QI_V16QI,
20100   V8HI_FTYPE_V4SI_V4SI,
20101   V8HI_FTYPE_V8HI_SI_COUNT,
20102   V8SF_FTYPE_V8SF_V8SF,
20103   V8SF_FTYPE_V8SF_V8SI,
20104   V4SI_FTYPE_V4SI_V4SI,
20105   V4SI_FTYPE_V4SI_V4SI_COUNT,
20106   V4SI_FTYPE_V8HI_V8HI,
20107   V4SI_FTYPE_V4SF_V4SF,
20108   V4SI_FTYPE_V2DF_V2DF,
20109   V4SI_FTYPE_V4SI_SI_COUNT,
20110   V4HI_FTYPE_V4HI_V4HI,
20111   V4HI_FTYPE_V4HI_V4HI_COUNT,
20112   V4HI_FTYPE_V8QI_V8QI,
20113   V4HI_FTYPE_V2SI_V2SI,
20114   V4HI_FTYPE_V4HI_SI_COUNT,
20115   V4DF_FTYPE_V4DF_V4DF,
20116   V4DF_FTYPE_V4DF_V4DI,
20117   V4SF_FTYPE_V4SF_V4SF,
20118   V4SF_FTYPE_V4SF_V4SF_SWAP,
20119   V4SF_FTYPE_V4SF_V4SI,
20120   V4SF_FTYPE_V4SF_V2SI,
20121   V4SF_FTYPE_V4SF_V2DF,
20122   V4SF_FTYPE_V4SF_DI,
20123   V4SF_FTYPE_V4SF_SI,
20124   V2DI_FTYPE_V2DI_V2DI,
20125   V2DI_FTYPE_V2DI_V2DI_COUNT,
20126   V2DI_FTYPE_V16QI_V16QI,
20127   V2DI_FTYPE_V4SI_V4SI,
20128   V2DI_FTYPE_V2DI_V16QI,
20129   V2DI_FTYPE_V2DF_V2DF,
20130   V2DI_FTYPE_V2DI_SI_COUNT,
20131   V2SI_FTYPE_V2SI_V2SI,
20132   V2SI_FTYPE_V2SI_V2SI_COUNT,
20133   V2SI_FTYPE_V4HI_V4HI,
20134   V2SI_FTYPE_V2SF_V2SF,
20135   V2SI_FTYPE_V2SI_SI_COUNT,
20136   V2DF_FTYPE_V2DF_V2DF,
20137   V2DF_FTYPE_V2DF_V2DF_SWAP,
20138   V2DF_FTYPE_V2DF_V4SF,
20139   V2DF_FTYPE_V2DF_V2DI,
20140   V2DF_FTYPE_V2DF_DI,
20141   V2DF_FTYPE_V2DF_SI,
20142   V2SF_FTYPE_V2SF_V2SF,
20143   V1DI_FTYPE_V1DI_V1DI,
20144   V1DI_FTYPE_V1DI_V1DI_COUNT,
20145   V1DI_FTYPE_V8QI_V8QI,
20146   V1DI_FTYPE_V2SI_V2SI,
20147   V1DI_FTYPE_V1DI_SI_COUNT,
20148   UINT64_FTYPE_UINT64_UINT64,
20149   UINT_FTYPE_UINT_UINT,
20150   UINT_FTYPE_UINT_USHORT,
20151   UINT_FTYPE_UINT_UCHAR,
20152   V8HI_FTYPE_V8HI_INT,
20153   V4SI_FTYPE_V4SI_INT,
20154   V4HI_FTYPE_V4HI_INT,
20155   V8SF_FTYPE_V8SF_INT,
20156   V4SI_FTYPE_V8SI_INT,
20157   V4SF_FTYPE_V8SF_INT,
20158   V2DF_FTYPE_V4DF_INT,
20159   V4DF_FTYPE_V4DF_INT,
20160   V4SF_FTYPE_V4SF_INT,
20161   V2DI_FTYPE_V2DI_INT,
20162   V2DI2TI_FTYPE_V2DI_INT,
20163   V2DF_FTYPE_V2DF_INT,
20164   V16QI_FTYPE_V16QI_V16QI_V16QI,
20165   V8SF_FTYPE_V8SF_V8SF_V8SF,
20166   V4DF_FTYPE_V4DF_V4DF_V4DF,
20167   V4SF_FTYPE_V4SF_V4SF_V4SF,
20168   V2DF_FTYPE_V2DF_V2DF_V2DF,
20169   V16QI_FTYPE_V16QI_V16QI_INT,
20170   V8SI_FTYPE_V8SI_V8SI_INT,
20171   V8SI_FTYPE_V8SI_V4SI_INT,
20172   V8HI_FTYPE_V8HI_V8HI_INT,
20173   V8SF_FTYPE_V8SF_V8SF_INT,
20174   V8SF_FTYPE_V8SF_V4SF_INT,
20175   V4SI_FTYPE_V4SI_V4SI_INT,
20176   V4DF_FTYPE_V4DF_V4DF_INT,
20177   V4DF_FTYPE_V4DF_V2DF_INT,
20178   V4SF_FTYPE_V4SF_V4SF_INT,
20179   V2DI_FTYPE_V2DI_V2DI_INT,
20180   V2DI2TI_FTYPE_V2DI_V2DI_INT,
20181   V1DI2DI_FTYPE_V1DI_V1DI_INT,
20182   V2DF_FTYPE_V2DF_V2DF_INT,
20183   V8SF_FTYPE_V8SF_V8SF_V8SI_INT,
20184   V4DF_FTYPE_V4DF_V4DF_V4DI_INT,
20185   V4SF_FTYPE_V4SF_V4SF_V4SI_INT,
20186   V2DF_FTYPE_V2DF_V2DF_V2DI_INT,
20187   V2DI_FTYPE_V2DI_UINT_UINT,
20188   V2DI_FTYPE_V2DI_V2DI_UINT_UINT
20189 };
20190
20191 /* Special builtins with variable number of arguments.  */
20192 static const struct builtin_description bdesc_special_args[] =
20193 {
20194   /* MMX */
20195   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20196
20197   /* 3DNow! */
20198   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20199
20200   /* SSE */
20201   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20202   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20203   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20204
20205   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20206   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20207   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20208   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20209
20210   /* SSE or 3DNow!A  */
20211   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20212   { 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 },
20213
20214   /* SSE2 */
20215   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20216   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20217   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20218   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
20219   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20220   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
20221   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntsi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
20222   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
20223   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20224
20225   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20226   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20227
20228   /* SSE3 */
20229   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20230
20231   /* SSE4.1 */
20232   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
20233
20234   /* SSE4A */
20235   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20236   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20237
20238   /* AVX */
20239   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
20240   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, 0, IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
20241   { OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_64BIT, CODE_FOR_avx_vzeroupper_rex64, 0, IX86_BUILTIN_VZEROUPPER_REX64, UNKNOWN, (int) VOID_FTYPE_VOID },
20242
20243   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20244   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastsd256, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
20245   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss256, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
20246   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_pd256, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
20247   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_ps256, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
20248
20249   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
20250   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
20251   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
20252   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
20253   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
20254   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
20255   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
20256
20257   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF },
20258   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF },
20259   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF },
20260   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF },
20261   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_V2DF },
20262   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_V4SF },
20263   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_V4DF },
20264   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_V8SF },
20265 };
20266
20267 /* Builtins with variable number of arguments.  */
20268 static const struct builtin_description bdesc_args[] =
20269 {
20270   /* MMX */
20271   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20272   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20273   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20274   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20275   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20276   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20277
20278   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20279   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20280   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20281   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20282   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20283   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20284   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20285   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20286
20287   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20288   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20289
20290   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20291   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_nandv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20292   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20293   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20294
20295   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20296   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20297   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20298   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20299   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20300   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20301
20302   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20303   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20304   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20305   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20306   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
20307   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
20308
20309   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
20310   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
20311   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
20312
20313   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
20314
20315   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20316   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20317   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
20318   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20319   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20320   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
20321
20322   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20323   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20324   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
20325   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20326   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20327   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
20328
20329   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20330   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20331   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20332   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20333
20334   /* 3DNow! */
20335   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
20336   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
20337   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20338   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20339
20340   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20341   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20342   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20343   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20344   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20345   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20346   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20347   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20348   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20349   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20350   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20351   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20352   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20353   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20354   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20355
20356   /* 3DNow!A */
20357   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
20358   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
20359   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
20360   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20361   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20362   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20363
20364   /* SSE */
20365   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
20366   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20367   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20368   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20369   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20370   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20371   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
20372   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
20373   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
20374   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
20375   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
20376   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
20377
20378   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20379
20380   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20381   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20382   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20383   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20384   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20385   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20386   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20387   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20388
20389   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
20390   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
20391   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
20392   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20393   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20394   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20395   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
20396   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
20397   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
20398   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20399   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
20400   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20401   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
20402   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
20403   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
20404   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20405   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
20406   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
20407   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
20408   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngtss", IX86_BUILTIN_CMPNGTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20409   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngess", IX86_BUILTIN_CMPNGESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20410   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20411
20412   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20413   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20414   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20415   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20416
20417   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20418   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_nandv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20419   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20420   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20421
20422   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20423   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20424   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20425   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpckhps, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20426   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpcklps, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20427
20428   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
20429   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
20430   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
20431
20432   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
20433
20434   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20435   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20436   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20437
20438   /* SSE MMX or 3Dnow!A */
20439   { 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 },
20440   { 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 },
20441   { 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 },
20442
20443   { 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 },
20444   { 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 },
20445   { 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 },
20446   { 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 },
20447
20448   { 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 },
20449   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
20450
20451   { 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 },
20452
20453   /* SSE2 */
20454   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20455
20456   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
20457   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
20458   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
20459   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
20460   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2ps, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
20461
20462   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
20463   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
20464   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
20465   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
20466   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
20467
20468   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
20469
20470   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
20471   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
20472   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
20473   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
20474
20475   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2dq, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
20476   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
20477   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttps2dq, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
20478
20479   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20480   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20481   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20482   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20483   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20484   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20485   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20486   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20487
20488   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
20489   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
20490   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
20491   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20492   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
20493   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20494   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
20495   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
20496   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
20497   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20498   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20499   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20500   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
20501   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
20502   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
20503   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20504   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
20505   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
20506   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
20507   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20508
20509   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20510   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20511   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20512   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20513
20514   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20515   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_nandv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20516   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20517   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20518
20519   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20520   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpckhpd_exp, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20521   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpcklpd_exp, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20522
20523   { 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 },
20524
20525   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20526   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20527   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20528   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20529   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20530   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20531   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20532   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20533
20534   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20535   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20536   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20537   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20538   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20539   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20540   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20541   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20542
20543   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20544   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
20545
20546   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20547   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_nandv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20548   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20549   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20550
20551   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20552   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20553
20554   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20555   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20556   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
20557   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20558   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20559   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
20560
20561   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20562   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20563   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20564   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20565
20566   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhbw, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20567   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhwd, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
20568   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhdq, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
20569   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhqdq, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20570   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklbw, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20571   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklwd, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20572   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckldq, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20573   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklqdq, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20574
20575   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
20576   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
20577   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
20578
20579   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20580   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
20581
20582   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
20583   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv2siv2di3, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
20584
20585   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
20586
20587   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
20588   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
20589   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
20590   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
20591
20592   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
20593   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
20594   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
20595   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
20596   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
20597   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
20598   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
20599
20600   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
20601   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
20602   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
20603   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
20604   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
20605   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
20606   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
20607
20608   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
20609   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
20610   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
20611   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
20612
20613   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
20614   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
20615   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
20616
20617   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
20618
20619   { OPTION_MASK_ISA_SSE2, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
20620   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
20621
20622   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
20623
20624   /* SSE2 MMX */
20625   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
20626   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
20627
20628   /* SSE3 */
20629   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
20630   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20631
20632   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20633   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20634   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20635   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20636   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20637   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20638
20639   /* SSSE3 */
20640   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
20641   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
20642   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
20643   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
20644   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
20645   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
20646
20647   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20648   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20649   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20650   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20651   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20652   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20653   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20654   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20655   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20656   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20657   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20658   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20659   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
20660   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
20661   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20662   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20663   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20664   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20665   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20666   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20667   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20668   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20669   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20670   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20671
20672   /* SSSE3.  */
20673   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_V2DI_INT },
20674   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI2DI_FTYPE_V1DI_V1DI_INT },
20675
20676   /* SSE4.1 */
20677   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20678   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20679   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
20680   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
20681   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20682   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20683   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20684   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
20685   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
20686   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
20687
20688   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
20689   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
20690   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
20691   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
20692   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
20693   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
20694   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
20695   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
20696   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
20697   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
20698   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
20699   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
20700   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
20701
20702   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
20703   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20704   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20705   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20706   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20707   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20708   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20709   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20710   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20711   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20712   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
20713   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20714
20715   /* SSE4.1 and SSE5 */
20716   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
20717   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
20718   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20719   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20720
20721   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
20722   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
20723   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
20724
20725   /* SSE4.2 */
20726   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20727   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32qi, "__builtin_ia32_crc32qi", IX86_BUILTIN_CRC32QI, UNKNOWN, (int) UINT_FTYPE_UINT_UCHAR },
20728   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32hi, "__builtin_ia32_crc32hi", IX86_BUILTIN_CRC32HI, UNKNOWN, (int) UINT_FTYPE_UINT_USHORT },
20729   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32si, "__builtin_ia32_crc32si", IX86_BUILTIN_CRC32SI, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
20730   { 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 },
20731
20732   /* SSE4A */
20733   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
20734   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
20735   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
20736   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20737
20738   /* AES */
20739   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
20740   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
20741
20742   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20743   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20744   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20745   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20746
20747   /* PCLMUL */
20748   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
20749
20750   /* AVX */
20751   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20752   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20753   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20754   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20755   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20756   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20757   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_nandv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20758   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_nandv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20759   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20760   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20761   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20762   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20763   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20764   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20765   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20766   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20767   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20768   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20769   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20770   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20771   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20772   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20773   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20774   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20775   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20776   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20777
20778   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
20779   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
20780   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
20781   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
20782
20783   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
20784   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20785   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
20786   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
20787   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20788   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
20789   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20790   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpsdv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20791   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpssv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20792   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20793   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20794   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
20795   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20796   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
20797   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
20798   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
20799   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2pd256, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
20800   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2ps256, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
20801   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
20802   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2dq256, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
20803   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
20804   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttpd2dq256, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
20805   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
20806   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttps2dq256, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
20807   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
20808   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20809   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
20810   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
20811   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
20812   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
20813   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
20814   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermil2v2df3,  "__builtin_ia32_vpermil2pd", IX86_BUILTIN_VPERMIL2PD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DI_INT },
20815   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermil2v4sf3,  "__builtin_ia32_vpermil2ps", IX86_BUILTIN_VPERMIL2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SI_INT },
20816   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermil2v4df3,  "__builtin_ia32_vpermil2pd256", IX86_BUILTIN_VPERMIL2PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DI_INT },
20817   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermil2v8sf3,  "__builtin_ia32_vpermil2ps256", IX86_BUILTIN_VPERMIL2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SI_INT },
20818   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
20819   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
20820   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
20821
20822   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20823   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20824   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
20825
20826   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
20827   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20828   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20829   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20830   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20831
20832   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20833
20834   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
20835   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
20836
20837   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20838   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20839   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20840   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20841
20842   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
20843   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
20844   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
20845   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si_si256, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
20846   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps_ps256, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
20847   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd_pd256, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
20848
20849   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
20850   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
20851   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
20852   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
20853   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
20854   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
20855   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
20856   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
20857   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
20858   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
20859   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
20860   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
20861   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
20862   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
20863   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
20864
20865   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
20866   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
20867 };
20868
20869 /* SSE5 */
20870 enum multi_arg_type {
20871   MULTI_ARG_UNKNOWN,
20872   MULTI_ARG_3_SF,
20873   MULTI_ARG_3_DF,
20874   MULTI_ARG_3_DI,
20875   MULTI_ARG_3_SI,
20876   MULTI_ARG_3_SI_DI,
20877   MULTI_ARG_3_HI,
20878   MULTI_ARG_3_HI_SI,
20879   MULTI_ARG_3_QI,
20880   MULTI_ARG_3_PERMPS,
20881   MULTI_ARG_3_PERMPD,
20882   MULTI_ARG_2_SF,
20883   MULTI_ARG_2_DF,
20884   MULTI_ARG_2_DI,
20885   MULTI_ARG_2_SI,
20886   MULTI_ARG_2_HI,
20887   MULTI_ARG_2_QI,
20888   MULTI_ARG_2_DI_IMM,
20889   MULTI_ARG_2_SI_IMM,
20890   MULTI_ARG_2_HI_IMM,
20891   MULTI_ARG_2_QI_IMM,
20892   MULTI_ARG_2_SF_CMP,
20893   MULTI_ARG_2_DF_CMP,
20894   MULTI_ARG_2_DI_CMP,
20895   MULTI_ARG_2_SI_CMP,
20896   MULTI_ARG_2_HI_CMP,
20897   MULTI_ARG_2_QI_CMP,
20898   MULTI_ARG_2_DI_TF,
20899   MULTI_ARG_2_SI_TF,
20900   MULTI_ARG_2_HI_TF,
20901   MULTI_ARG_2_QI_TF,
20902   MULTI_ARG_2_SF_TF,
20903   MULTI_ARG_2_DF_TF,
20904   MULTI_ARG_1_SF,
20905   MULTI_ARG_1_DF,
20906   MULTI_ARG_1_DI,
20907   MULTI_ARG_1_SI,
20908   MULTI_ARG_1_HI,
20909   MULTI_ARG_1_QI,
20910   MULTI_ARG_1_SI_DI,
20911   MULTI_ARG_1_HI_DI,
20912   MULTI_ARG_1_HI_SI,
20913   MULTI_ARG_1_QI_DI,
20914   MULTI_ARG_1_QI_SI,
20915   MULTI_ARG_1_QI_HI,
20916   MULTI_ARG_1_PH2PS,
20917   MULTI_ARG_1_PS2PH
20918 };
20919
20920 static const struct builtin_description bdesc_multi_arg[] =
20921 {
20922   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv4sf4,     "__builtin_ia32_fmaddss",    IX86_BUILTIN_FMADDSS,    0,            (int)MULTI_ARG_3_SF },
20923   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv2df4,     "__builtin_ia32_fmaddsd",    IX86_BUILTIN_FMADDSD,    0,            (int)MULTI_ARG_3_DF },
20924   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv4sf4,       "__builtin_ia32_fmaddps",    IX86_BUILTIN_FMADDPS,    0,            (int)MULTI_ARG_3_SF },
20925   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv2df4,       "__builtin_ia32_fmaddpd",    IX86_BUILTIN_FMADDPD,    0,            (int)MULTI_ARG_3_DF },
20926   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv4sf4,     "__builtin_ia32_fmsubss",    IX86_BUILTIN_FMSUBSS,    0,            (int)MULTI_ARG_3_SF },
20927   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv2df4,     "__builtin_ia32_fmsubsd",    IX86_BUILTIN_FMSUBSD,    0,            (int)MULTI_ARG_3_DF },
20928   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv4sf4,       "__builtin_ia32_fmsubps",    IX86_BUILTIN_FMSUBPS,    0,            (int)MULTI_ARG_3_SF },
20929   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv2df4,       "__builtin_ia32_fmsubpd",    IX86_BUILTIN_FMSUBPD,    0,            (int)MULTI_ARG_3_DF },
20930   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv4sf4,    "__builtin_ia32_fnmaddss",   IX86_BUILTIN_FNMADDSS,   0,            (int)MULTI_ARG_3_SF },
20931   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv2df4,    "__builtin_ia32_fnmaddsd",   IX86_BUILTIN_FNMADDSD,   0,            (int)MULTI_ARG_3_DF },
20932   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv4sf4,      "__builtin_ia32_fnmaddps",   IX86_BUILTIN_FNMADDPS,   0,            (int)MULTI_ARG_3_SF },
20933   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv2df4,      "__builtin_ia32_fnmaddpd",   IX86_BUILTIN_FNMADDPD,   0,            (int)MULTI_ARG_3_DF },
20934   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv4sf4,    "__builtin_ia32_fnmsubss",   IX86_BUILTIN_FNMSUBSS,   0,            (int)MULTI_ARG_3_SF },
20935   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv2df4,    "__builtin_ia32_fnmsubsd",   IX86_BUILTIN_FNMSUBSD,   0,            (int)MULTI_ARG_3_DF },
20936   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv4sf4,      "__builtin_ia32_fnmsubps",   IX86_BUILTIN_FNMSUBPS,   0,            (int)MULTI_ARG_3_SF },
20937   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv2df4,      "__builtin_ia32_fnmsubpd",   IX86_BUILTIN_FNMSUBPD,   0,            (int)MULTI_ARG_3_DF },
20938   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov",      IX86_BUILTIN_PCMOV,      0,            (int)MULTI_ARG_3_DI },
20939   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov_v2di", IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
20940   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4si,        "__builtin_ia32_pcmov_v4si", IX86_BUILTIN_PCMOV_V4SI, 0,            (int)MULTI_ARG_3_SI },
20941   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v8hi,        "__builtin_ia32_pcmov_v8hi", IX86_BUILTIN_PCMOV_V8HI, 0,            (int)MULTI_ARG_3_HI },
20942   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v16qi,       "__builtin_ia32_pcmov_v16qi",IX86_BUILTIN_PCMOV_V16QI,0,            (int)MULTI_ARG_3_QI },
20943   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2df,        "__builtin_ia32_pcmov_v2df", IX86_BUILTIN_PCMOV_V2DF, 0,            (int)MULTI_ARG_3_DF },
20944   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4sf,        "__builtin_ia32_pcmov_v4sf", IX86_BUILTIN_PCMOV_V4SF, 0,            (int)MULTI_ARG_3_SF },
20945   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pperm,             "__builtin_ia32_pperm",      IX86_BUILTIN_PPERM,      0,            (int)MULTI_ARG_3_QI },
20946   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv4sf,          "__builtin_ia32_permps",     IX86_BUILTIN_PERMPS,     0,            (int)MULTI_ARG_3_PERMPS },
20947   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv2df,          "__builtin_ia32_permpd",     IX86_BUILTIN_PERMPD,     0,            (int)MULTI_ARG_3_PERMPD },
20948   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssww,          "__builtin_ia32_pmacssww",   IX86_BUILTIN_PMACSSWW,   0,            (int)MULTI_ARG_3_HI },
20949   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsww,           "__builtin_ia32_pmacsww",    IX86_BUILTIN_PMACSWW,    0,            (int)MULTI_ARG_3_HI },
20950   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsswd,          "__builtin_ia32_pmacsswd",   IX86_BUILTIN_PMACSSWD,   0,            (int)MULTI_ARG_3_HI_SI },
20951   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacswd,           "__builtin_ia32_pmacswd",    IX86_BUILTIN_PMACSWD,    0,            (int)MULTI_ARG_3_HI_SI },
20952   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdd,          "__builtin_ia32_pmacssdd",   IX86_BUILTIN_PMACSSDD,   0,            (int)MULTI_ARG_3_SI },
20953   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdd,           "__builtin_ia32_pmacsdd",    IX86_BUILTIN_PMACSDD,    0,            (int)MULTI_ARG_3_SI },
20954   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdql,         "__builtin_ia32_pmacssdql",  IX86_BUILTIN_PMACSSDQL,  0,            (int)MULTI_ARG_3_SI_DI },
20955   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdqh,         "__builtin_ia32_pmacssdqh",  IX86_BUILTIN_PMACSSDQH,  0,            (int)MULTI_ARG_3_SI_DI },
20956   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdql,          "__builtin_ia32_pmacsdql",   IX86_BUILTIN_PMACSDQL,   0,            (int)MULTI_ARG_3_SI_DI },
20957   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdqh,          "__builtin_ia32_pmacsdqh",   IX86_BUILTIN_PMACSDQH,   0,            (int)MULTI_ARG_3_SI_DI },
20958   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcsswd,         "__builtin_ia32_pmadcsswd",  IX86_BUILTIN_PMADCSSWD,  0,            (int)MULTI_ARG_3_HI_SI },
20959   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcswd,          "__builtin_ia32_pmadcswd",   IX86_BUILTIN_PMADCSWD,   0,            (int)MULTI_ARG_3_HI_SI },
20960   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv2di3,        "__builtin_ia32_protq",      IX86_BUILTIN_PROTQ,      0,            (int)MULTI_ARG_2_DI },
20961   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv4si3,        "__builtin_ia32_protd",      IX86_BUILTIN_PROTD,      0,            (int)MULTI_ARG_2_SI },
20962   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv8hi3,        "__builtin_ia32_protw",      IX86_BUILTIN_PROTW,      0,            (int)MULTI_ARG_2_HI },
20963   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv16qi3,       "__builtin_ia32_protb",      IX86_BUILTIN_PROTB,      0,            (int)MULTI_ARG_2_QI },
20964   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv2di3,         "__builtin_ia32_protqi",     IX86_BUILTIN_PROTQ_IMM,  0,            (int)MULTI_ARG_2_DI_IMM },
20965   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv4si3,         "__builtin_ia32_protdi",     IX86_BUILTIN_PROTD_IMM,  0,            (int)MULTI_ARG_2_SI_IMM },
20966   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv8hi3,         "__builtin_ia32_protwi",     IX86_BUILTIN_PROTW_IMM,  0,            (int)MULTI_ARG_2_HI_IMM },
20967   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv16qi3,        "__builtin_ia32_protbi",     IX86_BUILTIN_PROTB_IMM,  0,            (int)MULTI_ARG_2_QI_IMM },
20968   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv2di3,         "__builtin_ia32_pshaq",      IX86_BUILTIN_PSHAQ,      0,            (int)MULTI_ARG_2_DI },
20969   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv4si3,         "__builtin_ia32_pshad",      IX86_BUILTIN_PSHAD,      0,            (int)MULTI_ARG_2_SI },
20970   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv8hi3,         "__builtin_ia32_pshaw",      IX86_BUILTIN_PSHAW,      0,            (int)MULTI_ARG_2_HI },
20971   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv16qi3,        "__builtin_ia32_pshab",      IX86_BUILTIN_PSHAB,      0,            (int)MULTI_ARG_2_QI },
20972   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv2di3,         "__builtin_ia32_pshlq",      IX86_BUILTIN_PSHLQ,      0,            (int)MULTI_ARG_2_DI },
20973   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv4si3,         "__builtin_ia32_pshld",      IX86_BUILTIN_PSHLD,      0,            (int)MULTI_ARG_2_SI },
20974   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv8hi3,         "__builtin_ia32_pshlw",      IX86_BUILTIN_PSHLW,      0,            (int)MULTI_ARG_2_HI },
20975   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv16qi3,        "__builtin_ia32_pshlb",      IX86_BUILTIN_PSHLB,      0,            (int)MULTI_ARG_2_QI },
20976   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv4sf2,       "__builtin_ia32_frczss",     IX86_BUILTIN_FRCZSS,     0,            (int)MULTI_ARG_2_SF },
20977   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv2df2,       "__builtin_ia32_frczsd",     IX86_BUILTIN_FRCZSD,     0,            (int)MULTI_ARG_2_DF },
20978   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv4sf2,         "__builtin_ia32_frczps",     IX86_BUILTIN_FRCZPS,     0,            (int)MULTI_ARG_1_SF },
20979   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv2df2,         "__builtin_ia32_frczpd",     IX86_BUILTIN_FRCZPD,     0,            (int)MULTI_ARG_1_DF },
20980   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtph2ps,          "__builtin_ia32_cvtph2ps",   IX86_BUILTIN_CVTPH2PS,   0,            (int)MULTI_ARG_1_PH2PS },
20981   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtps2ph,          "__builtin_ia32_cvtps2ph",   IX86_BUILTIN_CVTPS2PH,   0,            (int)MULTI_ARG_1_PS2PH },
20982   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbw,           "__builtin_ia32_phaddbw",    IX86_BUILTIN_PHADDBW,    0,            (int)MULTI_ARG_1_QI_HI },
20983   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbd,           "__builtin_ia32_phaddbd",    IX86_BUILTIN_PHADDBD,    0,            (int)MULTI_ARG_1_QI_SI },
20984   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbq,           "__builtin_ia32_phaddbq",    IX86_BUILTIN_PHADDBQ,    0,            (int)MULTI_ARG_1_QI_DI },
20985   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwd,           "__builtin_ia32_phaddwd",    IX86_BUILTIN_PHADDWD,    0,            (int)MULTI_ARG_1_HI_SI },
20986   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwq,           "__builtin_ia32_phaddwq",    IX86_BUILTIN_PHADDWQ,    0,            (int)MULTI_ARG_1_HI_DI },
20987   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadddq,           "__builtin_ia32_phadddq",    IX86_BUILTIN_PHADDDQ,    0,            (int)MULTI_ARG_1_SI_DI },
20988   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubw,          "__builtin_ia32_phaddubw",   IX86_BUILTIN_PHADDUBW,   0,            (int)MULTI_ARG_1_QI_HI },
20989   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubd,          "__builtin_ia32_phaddubd",   IX86_BUILTIN_PHADDUBD,   0,            (int)MULTI_ARG_1_QI_SI },
20990   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubq,          "__builtin_ia32_phaddubq",   IX86_BUILTIN_PHADDUBQ,   0,            (int)MULTI_ARG_1_QI_DI },
20991   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwd,          "__builtin_ia32_phadduwd",   IX86_BUILTIN_PHADDUWD,   0,            (int)MULTI_ARG_1_HI_SI },
20992   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwq,          "__builtin_ia32_phadduwq",   IX86_BUILTIN_PHADDUWQ,   0,            (int)MULTI_ARG_1_HI_DI },
20993   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddudq,          "__builtin_ia32_phaddudq",   IX86_BUILTIN_PHADDUDQ,   0,            (int)MULTI_ARG_1_SI_DI },
20994   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubbw,           "__builtin_ia32_phsubbw",    IX86_BUILTIN_PHSUBBW,    0,            (int)MULTI_ARG_1_QI_HI },
20995   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubwd,           "__builtin_ia32_phsubwd",    IX86_BUILTIN_PHSUBWD,    0,            (int)MULTI_ARG_1_HI_SI },
20996   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubdq,           "__builtin_ia32_phsubdq",    IX86_BUILTIN_PHSUBDQ,    0,            (int)MULTI_ARG_1_SI_DI },
20997
20998   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comeqss",    IX86_BUILTIN_COMEQSS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
20999   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comness",    IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21000   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comneqss",   IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21001   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comltss",    IX86_BUILTIN_COMLTSS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21002   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comless",    IX86_BUILTIN_COMLESS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21003   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgtss",    IX86_BUILTIN_COMGTSS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21004   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgess",    IX86_BUILTIN_COMGESS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21005   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comueqss",   IX86_BUILTIN_COMUEQSS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21006   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuness",   IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21007   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuneqss",  IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21008   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunltss",  IX86_BUILTIN_COMULTSS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21009   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunless",  IX86_BUILTIN_COMULESS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21010   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungtss",  IX86_BUILTIN_COMUGTSS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21011   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungess",  IX86_BUILTIN_COMUGESS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21012   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comordss",   IX86_BUILTIN_COMORDSS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21013   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunordss", IX86_BUILTIN_COMUNORDSS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21014
21015   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comeqsd",    IX86_BUILTIN_COMEQSD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21016   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comnesd",    IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21017   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comneqsd",   IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21018   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comltsd",    IX86_BUILTIN_COMLTSD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21019   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comlesd",    IX86_BUILTIN_COMLESD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21020   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgtsd",    IX86_BUILTIN_COMGTSD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21021   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgesd",    IX86_BUILTIN_COMGESD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21022   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comueqsd",   IX86_BUILTIN_COMUEQSD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21023   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunesd",   IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21024   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comuneqsd",  IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21025   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunltsd",  IX86_BUILTIN_COMULTSD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21026   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunlesd",  IX86_BUILTIN_COMULESD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21027   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungtsd",  IX86_BUILTIN_COMUGTSD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21028   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungesd",  IX86_BUILTIN_COMUGESD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21029   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comordsd",   IX86_BUILTIN_COMORDSD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21030   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunordsd", IX86_BUILTIN_COMUNORDSD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21031
21032   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comeqps",    IX86_BUILTIN_COMEQPS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
21033   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneps",    IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21034   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneqps",   IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21035   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comltps",    IX86_BUILTIN_COMLTPS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21036   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comleps",    IX86_BUILTIN_COMLEPS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21037   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgtps",    IX86_BUILTIN_COMGTPS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21038   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgeps",    IX86_BUILTIN_COMGEPS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21039   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comueqps",   IX86_BUILTIN_COMUEQPS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21040   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneps",   IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21041   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneqps",  IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21042   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunltps",  IX86_BUILTIN_COMULTPS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21043   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunleps",  IX86_BUILTIN_COMULEPS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21044   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungtps",  IX86_BUILTIN_COMUGTPS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21045   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungeps",  IX86_BUILTIN_COMUGEPS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21046   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comordps",   IX86_BUILTIN_COMORDPS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21047   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunordps", IX86_BUILTIN_COMUNORDPS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21048
21049   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comeqpd",    IX86_BUILTIN_COMEQPD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21050   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comnepd",    IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21051   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comneqpd",   IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21052   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comltpd",    IX86_BUILTIN_COMLTPD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21053   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comlepd",    IX86_BUILTIN_COMLEPD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21054   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgtpd",    IX86_BUILTIN_COMGTPD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21055   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgepd",    IX86_BUILTIN_COMGEPD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21056   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comueqpd",   IX86_BUILTIN_COMUEQPD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21057   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunepd",   IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21058   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comuneqpd",  IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21059   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunltpd",  IX86_BUILTIN_COMULTPD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21060   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunlepd",  IX86_BUILTIN_COMULEPD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21061   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungtpd",  IX86_BUILTIN_COMUGTPD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21062   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungepd",  IX86_BUILTIN_COMUGEPD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21063   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comordpd",   IX86_BUILTIN_COMORDPD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21064   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunordpd", IX86_BUILTIN_COMUNORDPD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21065
21066   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomeqb",    IX86_BUILTIN_PCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
21067   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneb",    IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21068   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneqb",   IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21069   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomltb",    IX86_BUILTIN_PCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
21070   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomleb",    IX86_BUILTIN_PCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
21071   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgtb",    IX86_BUILTIN_PCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
21072   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgeb",    IX86_BUILTIN_PCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
21073
21074   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomeqw",    IX86_BUILTIN_PCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
21075   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomnew",    IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21076   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomneqw",   IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21077   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomltw",    IX86_BUILTIN_PCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
21078   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomlew",    IX86_BUILTIN_PCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
21079   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgtw",    IX86_BUILTIN_PCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
21080   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgew",    IX86_BUILTIN_PCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
21081
21082   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomeqd",    IX86_BUILTIN_PCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
21083   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomned",    IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21084   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomneqd",   IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21085   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomltd",    IX86_BUILTIN_PCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
21086   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomled",    IX86_BUILTIN_PCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
21087   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomgtd",    IX86_BUILTIN_PCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
21088   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomged",    IX86_BUILTIN_PCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
21089
21090   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomeqq",    IX86_BUILTIN_PCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
21091   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneq",    IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21092   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneqq",   IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21093   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomltq",    IX86_BUILTIN_PCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
21094   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomleq",    IX86_BUILTIN_PCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
21095   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgtq",    IX86_BUILTIN_PCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
21096   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgeq",    IX86_BUILTIN_PCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
21097
21098   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomequb",   IX86_BUILTIN_PCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
21099   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomneub",   IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21100   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomnequb",  IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21101   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomltub",   IX86_BUILTIN_PCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
21102   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomleub",   IX86_BUILTIN_PCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
21103   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgtub",   IX86_BUILTIN_PCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
21104   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgeub",   IX86_BUILTIN_PCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
21105
21106   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomequw",   IX86_BUILTIN_PCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
21107   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomneuw",   IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21108   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomnequw",  IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21109   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomltuw",   IX86_BUILTIN_PCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
21110   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomleuw",   IX86_BUILTIN_PCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
21111   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgtuw",   IX86_BUILTIN_PCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
21112   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgeuw",   IX86_BUILTIN_PCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
21113
21114   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomequd",   IX86_BUILTIN_PCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
21115   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomneud",   IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21116   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomnequd",  IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21117   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomltud",   IX86_BUILTIN_PCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
21118   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomleud",   IX86_BUILTIN_PCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
21119   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgtud",   IX86_BUILTIN_PCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
21120   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgeud",   IX86_BUILTIN_PCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
21121
21122   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomequq",   IX86_BUILTIN_PCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
21123   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomneuq",   IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21124   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomnequq",  IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21125   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomltuq",   IX86_BUILTIN_PCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
21126   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomleuq",   IX86_BUILTIN_PCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
21127   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgtuq",   IX86_BUILTIN_PCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
21128   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgeuq",   IX86_BUILTIN_PCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
21129
21130   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalsess", IX86_BUILTIN_COMFALSESS, COM_FALSE_S,  (int)MULTI_ARG_2_SF_TF },
21131   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtruess",  IX86_BUILTIN_COMTRUESS,  COM_TRUE_S,   (int)MULTI_ARG_2_SF_TF },
21132   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalseps", IX86_BUILTIN_COMFALSEPS, COM_FALSE_P,  (int)MULTI_ARG_2_SF_TF },
21133   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtrueps",  IX86_BUILTIN_COMTRUEPS,  COM_TRUE_P,   (int)MULTI_ARG_2_SF_TF },
21134   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsesd", IX86_BUILTIN_COMFALSESD, COM_FALSE_S,  (int)MULTI_ARG_2_DF_TF },
21135   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruesd",  IX86_BUILTIN_COMTRUESD,  COM_TRUE_S,   (int)MULTI_ARG_2_DF_TF },
21136   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsepd", IX86_BUILTIN_COMFALSEPD, COM_FALSE_P,  (int)MULTI_ARG_2_DF_TF },
21137   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruepd",  IX86_BUILTIN_COMTRUEPD,  COM_TRUE_P,   (int)MULTI_ARG_2_DF_TF },
21138
21139   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseb", IX86_BUILTIN_PCOMFALSEB, PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21140   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalsew", IX86_BUILTIN_PCOMFALSEW, PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21141   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalsed", IX86_BUILTIN_PCOMFALSED, PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21142   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseq", IX86_BUILTIN_PCOMFALSEQ, PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21143   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseub",IX86_BUILTIN_PCOMFALSEUB,PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21144   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalseuw",IX86_BUILTIN_PCOMFALSEUW,PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21145   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalseud",IX86_BUILTIN_PCOMFALSEUD,PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21146   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseuq",IX86_BUILTIN_PCOMFALSEUQ,PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21147
21148   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueb",  IX86_BUILTIN_PCOMTRUEB,  PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21149   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtruew",  IX86_BUILTIN_PCOMTRUEW,  PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21150   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrued",  IX86_BUILTIN_PCOMTRUED,  PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21151   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueq",  IX86_BUILTIN_PCOMTRUEQ,  PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21152   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueub", IX86_BUILTIN_PCOMTRUEUB, PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21153   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtrueuw", IX86_BUILTIN_PCOMTRUEUW, PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21154   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrueud", IX86_BUILTIN_PCOMTRUEUD, PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21155   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueuq", IX86_BUILTIN_PCOMTRUEUQ, PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21156 };
21157
21158 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
21159    in the current target ISA to allow the user to compile particular modules
21160    with different target specific options that differ from the command line
21161    options.  */
21162 static void
21163 ix86_init_mmx_sse_builtins (void)
21164 {
21165   const struct builtin_description * d;
21166   size_t i;
21167
21168   tree V16QI_type_node = build_vector_type_for_mode (char_type_node, V16QImode);
21169   tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
21170   tree V1DI_type_node
21171     = build_vector_type_for_mode (long_long_integer_type_node, V1DImode);
21172   tree V2SF_type_node = build_vector_type_for_mode (float_type_node, V2SFmode);
21173   tree V2DI_type_node
21174     = build_vector_type_for_mode (long_long_integer_type_node, V2DImode);
21175   tree V2DF_type_node = build_vector_type_for_mode (double_type_node, V2DFmode);
21176   tree V4SF_type_node = build_vector_type_for_mode (float_type_node, V4SFmode);
21177   tree V4SI_type_node = build_vector_type_for_mode (intSI_type_node, V4SImode);
21178   tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
21179   tree V8QI_type_node = build_vector_type_for_mode (char_type_node, V8QImode);
21180   tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, V8HImode);
21181
21182   tree pchar_type_node = build_pointer_type (char_type_node);
21183   tree pcchar_type_node
21184     = build_pointer_type (build_type_variant (char_type_node, 1, 0));
21185   tree pfloat_type_node = build_pointer_type (float_type_node);
21186   tree pcfloat_type_node
21187     = build_pointer_type (build_type_variant (float_type_node, 1, 0));
21188   tree pv2sf_type_node = build_pointer_type (V2SF_type_node);
21189   tree pcv2sf_type_node
21190     = build_pointer_type (build_type_variant (V2SF_type_node, 1, 0));
21191   tree pv2di_type_node = build_pointer_type (V2DI_type_node);
21192   tree pdi_type_node = build_pointer_type (long_long_unsigned_type_node);
21193
21194   /* Comparisons.  */
21195   tree int_ftype_v4sf_v4sf
21196     = build_function_type_list (integer_type_node,
21197                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21198   tree v4si_ftype_v4sf_v4sf
21199     = build_function_type_list (V4SI_type_node,
21200                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21201   /* MMX/SSE/integer conversions.  */
21202   tree int_ftype_v4sf
21203     = build_function_type_list (integer_type_node,
21204                                 V4SF_type_node, NULL_TREE);
21205   tree int64_ftype_v4sf
21206     = build_function_type_list (long_long_integer_type_node,
21207                                 V4SF_type_node, NULL_TREE);
21208   tree int_ftype_v8qi
21209     = build_function_type_list (integer_type_node, V8QI_type_node, NULL_TREE);
21210   tree v4sf_ftype_v4sf_int
21211     = build_function_type_list (V4SF_type_node,
21212                                 V4SF_type_node, integer_type_node, NULL_TREE);
21213   tree v4sf_ftype_v4sf_int64
21214     = build_function_type_list (V4SF_type_node,
21215                                 V4SF_type_node, long_long_integer_type_node,
21216                                 NULL_TREE);
21217   tree v4sf_ftype_v4sf_v2si
21218     = build_function_type_list (V4SF_type_node,
21219                                 V4SF_type_node, V2SI_type_node, NULL_TREE);
21220
21221   /* Miscellaneous.  */
21222   tree v8qi_ftype_v4hi_v4hi
21223     = build_function_type_list (V8QI_type_node,
21224                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21225   tree v4hi_ftype_v2si_v2si
21226     = build_function_type_list (V4HI_type_node,
21227                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21228   tree v4sf_ftype_v4sf_v4sf_int
21229     = build_function_type_list (V4SF_type_node,
21230                                 V4SF_type_node, V4SF_type_node,
21231                                 integer_type_node, NULL_TREE);
21232   tree v2si_ftype_v4hi_v4hi
21233     = build_function_type_list (V2SI_type_node,
21234                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21235   tree v4hi_ftype_v4hi_int
21236     = build_function_type_list (V4HI_type_node,
21237                                 V4HI_type_node, integer_type_node, NULL_TREE);
21238   tree v2si_ftype_v2si_int
21239     = build_function_type_list (V2SI_type_node,
21240                                 V2SI_type_node, integer_type_node, NULL_TREE);
21241   tree v1di_ftype_v1di_int
21242     = build_function_type_list (V1DI_type_node,
21243                                 V1DI_type_node, integer_type_node, NULL_TREE);
21244
21245   tree void_ftype_void
21246     = build_function_type (void_type_node, void_list_node);
21247   tree void_ftype_unsigned
21248     = build_function_type_list (void_type_node, unsigned_type_node, NULL_TREE);
21249   tree void_ftype_unsigned_unsigned
21250     = build_function_type_list (void_type_node, unsigned_type_node,
21251                                 unsigned_type_node, NULL_TREE);
21252   tree void_ftype_pcvoid_unsigned_unsigned
21253     = build_function_type_list (void_type_node, const_ptr_type_node,
21254                                 unsigned_type_node, unsigned_type_node,
21255                                 NULL_TREE);
21256   tree unsigned_ftype_void
21257     = build_function_type (unsigned_type_node, void_list_node);
21258   tree v2si_ftype_v4sf
21259     = build_function_type_list (V2SI_type_node, V4SF_type_node, NULL_TREE);
21260   /* Loads/stores.  */
21261   tree void_ftype_v8qi_v8qi_pchar
21262     = build_function_type_list (void_type_node,
21263                                 V8QI_type_node, V8QI_type_node,
21264                                 pchar_type_node, NULL_TREE);
21265   tree v4sf_ftype_pcfloat
21266     = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
21267   tree v4sf_ftype_v4sf_pcv2sf
21268     = build_function_type_list (V4SF_type_node,
21269                                 V4SF_type_node, pcv2sf_type_node, NULL_TREE);
21270   tree void_ftype_pv2sf_v4sf
21271     = build_function_type_list (void_type_node,
21272                                 pv2sf_type_node, V4SF_type_node, NULL_TREE);
21273   tree void_ftype_pfloat_v4sf
21274     = build_function_type_list (void_type_node,
21275                                 pfloat_type_node, V4SF_type_node, NULL_TREE);
21276   tree void_ftype_pdi_di
21277     = build_function_type_list (void_type_node,
21278                                 pdi_type_node, long_long_unsigned_type_node,
21279                                 NULL_TREE);
21280   tree void_ftype_pv2di_v2di
21281     = build_function_type_list (void_type_node,
21282                                 pv2di_type_node, V2DI_type_node, NULL_TREE);
21283   /* Normal vector unops.  */
21284   tree v4sf_ftype_v4sf
21285     = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
21286   tree v16qi_ftype_v16qi
21287     = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
21288   tree v8hi_ftype_v8hi
21289     = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
21290   tree v4si_ftype_v4si
21291     = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
21292   tree v8qi_ftype_v8qi
21293     = build_function_type_list (V8QI_type_node, V8QI_type_node, NULL_TREE);
21294   tree v4hi_ftype_v4hi
21295     = build_function_type_list (V4HI_type_node, V4HI_type_node, NULL_TREE);
21296
21297   /* Normal vector binops.  */
21298   tree v4sf_ftype_v4sf_v4sf
21299     = build_function_type_list (V4SF_type_node,
21300                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21301   tree v8qi_ftype_v8qi_v8qi
21302     = build_function_type_list (V8QI_type_node,
21303                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
21304   tree v4hi_ftype_v4hi_v4hi
21305     = build_function_type_list (V4HI_type_node,
21306                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21307   tree v2si_ftype_v2si_v2si
21308     = build_function_type_list (V2SI_type_node,
21309                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21310   tree v1di_ftype_v1di_v1di
21311     = build_function_type_list (V1DI_type_node,
21312                                 V1DI_type_node, V1DI_type_node, NULL_TREE);
21313   tree v1di_ftype_v1di_v1di_int
21314     = build_function_type_list (V1DI_type_node,
21315                                 V1DI_type_node, V1DI_type_node,
21316                                 integer_type_node, NULL_TREE);
21317   tree v2si_ftype_v2sf
21318     = build_function_type_list (V2SI_type_node, V2SF_type_node, NULL_TREE);
21319   tree v2sf_ftype_v2si
21320     = build_function_type_list (V2SF_type_node, V2SI_type_node, NULL_TREE);
21321   tree v2si_ftype_v2si
21322     = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
21323   tree v2sf_ftype_v2sf
21324     = build_function_type_list (V2SF_type_node, V2SF_type_node, NULL_TREE);
21325   tree v2sf_ftype_v2sf_v2sf
21326     = build_function_type_list (V2SF_type_node,
21327                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
21328   tree v2si_ftype_v2sf_v2sf
21329     = build_function_type_list (V2SI_type_node,
21330                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
21331   tree pint_type_node    = build_pointer_type (integer_type_node);
21332   tree pdouble_type_node = build_pointer_type (double_type_node);
21333   tree pcdouble_type_node = build_pointer_type (
21334                                 build_type_variant (double_type_node, 1, 0));
21335   tree int_ftype_v2df_v2df
21336     = build_function_type_list (integer_type_node,
21337                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21338
21339   tree void_ftype_pcvoid
21340     = build_function_type_list (void_type_node, const_ptr_type_node, NULL_TREE);
21341   tree v4sf_ftype_v4si
21342     = build_function_type_list (V4SF_type_node, V4SI_type_node, NULL_TREE);
21343   tree v4si_ftype_v4sf
21344     = build_function_type_list (V4SI_type_node, V4SF_type_node, NULL_TREE);
21345   tree v2df_ftype_v4si
21346     = build_function_type_list (V2DF_type_node, V4SI_type_node, NULL_TREE);
21347   tree v4si_ftype_v2df
21348     = build_function_type_list (V4SI_type_node, V2DF_type_node, NULL_TREE);
21349   tree v4si_ftype_v2df_v2df
21350     = build_function_type_list (V4SI_type_node,
21351                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21352   tree v2si_ftype_v2df
21353     = build_function_type_list (V2SI_type_node, V2DF_type_node, NULL_TREE);
21354   tree v4sf_ftype_v2df
21355     = build_function_type_list (V4SF_type_node, V2DF_type_node, NULL_TREE);
21356   tree v2df_ftype_v2si
21357     = build_function_type_list (V2DF_type_node, V2SI_type_node, NULL_TREE);
21358   tree v2df_ftype_v4sf
21359     = build_function_type_list (V2DF_type_node, V4SF_type_node, NULL_TREE);
21360   tree int_ftype_v2df
21361     = build_function_type_list (integer_type_node, V2DF_type_node, NULL_TREE);
21362   tree int64_ftype_v2df
21363     = build_function_type_list (long_long_integer_type_node,
21364                                 V2DF_type_node, NULL_TREE);
21365   tree v2df_ftype_v2df_int
21366     = build_function_type_list (V2DF_type_node,
21367                                 V2DF_type_node, integer_type_node, NULL_TREE);
21368   tree v2df_ftype_v2df_int64
21369     = build_function_type_list (V2DF_type_node,
21370                                 V2DF_type_node, long_long_integer_type_node,
21371                                 NULL_TREE);
21372   tree v4sf_ftype_v4sf_v2df
21373     = build_function_type_list (V4SF_type_node,
21374                                 V4SF_type_node, V2DF_type_node, NULL_TREE);
21375   tree v2df_ftype_v2df_v4sf
21376     = build_function_type_list (V2DF_type_node,
21377                                 V2DF_type_node, V4SF_type_node, NULL_TREE);
21378   tree v2df_ftype_v2df_v2df_int
21379     = build_function_type_list (V2DF_type_node,
21380                                 V2DF_type_node, V2DF_type_node,
21381                                 integer_type_node,
21382                                 NULL_TREE);
21383   tree v2df_ftype_v2df_pcdouble
21384     = build_function_type_list (V2DF_type_node,
21385                                 V2DF_type_node, pcdouble_type_node, NULL_TREE);
21386   tree void_ftype_pdouble_v2df
21387     = build_function_type_list (void_type_node,
21388                                 pdouble_type_node, V2DF_type_node, NULL_TREE);
21389   tree void_ftype_pint_int
21390     = build_function_type_list (void_type_node,
21391                                 pint_type_node, integer_type_node, NULL_TREE);
21392   tree void_ftype_v16qi_v16qi_pchar
21393     = build_function_type_list (void_type_node,
21394                                 V16QI_type_node, V16QI_type_node,
21395                                 pchar_type_node, NULL_TREE);
21396   tree v2df_ftype_pcdouble
21397     = build_function_type_list (V2DF_type_node, pcdouble_type_node, NULL_TREE);
21398   tree v2df_ftype_v2df_v2df
21399     = build_function_type_list (V2DF_type_node,
21400                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21401   tree v16qi_ftype_v16qi_v16qi
21402     = build_function_type_list (V16QI_type_node,
21403                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
21404   tree v8hi_ftype_v8hi_v8hi
21405     = build_function_type_list (V8HI_type_node,
21406                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
21407   tree v4si_ftype_v4si_v4si
21408     = build_function_type_list (V4SI_type_node,
21409                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
21410   tree v2di_ftype_v2di_v2di
21411     = build_function_type_list (V2DI_type_node,
21412                                 V2DI_type_node, V2DI_type_node, NULL_TREE);
21413   tree v2di_ftype_v2df_v2df
21414     = build_function_type_list (V2DI_type_node,
21415                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21416   tree v2df_ftype_v2df
21417     = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
21418   tree v2di_ftype_v2di_int
21419     = build_function_type_list (V2DI_type_node,
21420                                 V2DI_type_node, integer_type_node, NULL_TREE);
21421   tree v2di_ftype_v2di_v2di_int
21422     = build_function_type_list (V2DI_type_node, V2DI_type_node,
21423                                 V2DI_type_node, integer_type_node, NULL_TREE);
21424   tree v4si_ftype_v4si_int
21425     = build_function_type_list (V4SI_type_node,
21426                                 V4SI_type_node, integer_type_node, NULL_TREE);
21427   tree v8hi_ftype_v8hi_int
21428     = build_function_type_list (V8HI_type_node,
21429                                 V8HI_type_node, integer_type_node, NULL_TREE);
21430   tree v4si_ftype_v8hi_v8hi
21431     = build_function_type_list (V4SI_type_node,
21432                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
21433   tree v1di_ftype_v8qi_v8qi
21434     = build_function_type_list (V1DI_type_node,
21435                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
21436   tree v1di_ftype_v2si_v2si
21437     = build_function_type_list (V1DI_type_node,
21438                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21439   tree v2di_ftype_v16qi_v16qi
21440     = build_function_type_list (V2DI_type_node,
21441                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
21442   tree v2di_ftype_v4si_v4si
21443     = build_function_type_list (V2DI_type_node,
21444                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
21445   tree int_ftype_v16qi
21446     = build_function_type_list (integer_type_node, V16QI_type_node, NULL_TREE);
21447   tree v16qi_ftype_pcchar
21448     = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
21449   tree void_ftype_pchar_v16qi
21450     = build_function_type_list (void_type_node,
21451                                 pchar_type_node, V16QI_type_node, NULL_TREE);
21452
21453   tree v2di_ftype_v2di_unsigned_unsigned
21454     = build_function_type_list (V2DI_type_node, V2DI_type_node,
21455                                 unsigned_type_node, unsigned_type_node,
21456                                 NULL_TREE);
21457   tree v2di_ftype_v2di_v2di_unsigned_unsigned
21458     = build_function_type_list (V2DI_type_node, V2DI_type_node, V2DI_type_node,
21459                                 unsigned_type_node, unsigned_type_node,
21460                                 NULL_TREE);
21461   tree v2di_ftype_v2di_v16qi
21462     = build_function_type_list (V2DI_type_node, V2DI_type_node, V16QI_type_node,
21463                                 NULL_TREE);
21464   tree v2df_ftype_v2df_v2df_v2df
21465     = build_function_type_list (V2DF_type_node,
21466                                 V2DF_type_node, V2DF_type_node,
21467                                 V2DF_type_node, NULL_TREE);
21468   tree v4sf_ftype_v4sf_v4sf_v4sf
21469     = build_function_type_list (V4SF_type_node,
21470                                 V4SF_type_node, V4SF_type_node,
21471                                 V4SF_type_node, NULL_TREE);
21472   tree v8hi_ftype_v16qi
21473     = build_function_type_list (V8HI_type_node, V16QI_type_node,
21474                                 NULL_TREE);
21475   tree v4si_ftype_v16qi
21476     = build_function_type_list (V4SI_type_node, V16QI_type_node,
21477                                 NULL_TREE);
21478   tree v2di_ftype_v16qi
21479     = build_function_type_list (V2DI_type_node, V16QI_type_node,
21480                                 NULL_TREE);
21481   tree v4si_ftype_v8hi
21482     = build_function_type_list (V4SI_type_node, V8HI_type_node,
21483                                 NULL_TREE);
21484   tree v2di_ftype_v8hi
21485     = build_function_type_list (V2DI_type_node, V8HI_type_node,
21486                                 NULL_TREE);
21487   tree v2di_ftype_v4si
21488     = build_function_type_list (V2DI_type_node, V4SI_type_node,
21489                                 NULL_TREE);
21490   tree v2di_ftype_pv2di
21491     = build_function_type_list (V2DI_type_node, pv2di_type_node,
21492                                 NULL_TREE);
21493   tree v16qi_ftype_v16qi_v16qi_int
21494     = build_function_type_list (V16QI_type_node, V16QI_type_node,
21495                                 V16QI_type_node, integer_type_node,
21496                                 NULL_TREE);
21497   tree v16qi_ftype_v16qi_v16qi_v16qi
21498     = build_function_type_list (V16QI_type_node, V16QI_type_node,
21499                                 V16QI_type_node, V16QI_type_node,
21500                                 NULL_TREE);
21501   tree v8hi_ftype_v8hi_v8hi_int
21502     = build_function_type_list (V8HI_type_node, V8HI_type_node,
21503                                 V8HI_type_node, integer_type_node,
21504                                 NULL_TREE);
21505   tree v4si_ftype_v4si_v4si_int
21506     = build_function_type_list (V4SI_type_node, V4SI_type_node,
21507                                 V4SI_type_node, integer_type_node,
21508                                 NULL_TREE);
21509   tree int_ftype_v2di_v2di
21510     = build_function_type_list (integer_type_node,
21511                                 V2DI_type_node, V2DI_type_node,
21512                                 NULL_TREE);
21513   tree int_ftype_v16qi_int_v16qi_int_int
21514     = build_function_type_list (integer_type_node,
21515                                 V16QI_type_node,
21516                                 integer_type_node,
21517                                 V16QI_type_node,
21518                                 integer_type_node,
21519                                 integer_type_node,
21520                                 NULL_TREE);
21521   tree v16qi_ftype_v16qi_int_v16qi_int_int
21522     = build_function_type_list (V16QI_type_node,
21523                                 V16QI_type_node,
21524                                 integer_type_node,
21525                                 V16QI_type_node,
21526                                 integer_type_node,
21527                                 integer_type_node,
21528                                 NULL_TREE);
21529   tree int_ftype_v16qi_v16qi_int
21530     = build_function_type_list (integer_type_node,
21531                                 V16QI_type_node,
21532                                 V16QI_type_node,
21533                                 integer_type_node,
21534                                 NULL_TREE);
21535
21536   /* SSE5 instructions */
21537   tree v2di_ftype_v2di_v2di_v2di
21538     = build_function_type_list (V2DI_type_node,
21539                                 V2DI_type_node,
21540                                 V2DI_type_node,
21541                                 V2DI_type_node,
21542                                 NULL_TREE);
21543
21544   tree v4si_ftype_v4si_v4si_v4si
21545     = build_function_type_list (V4SI_type_node,
21546                                 V4SI_type_node,
21547                                 V4SI_type_node,
21548                                 V4SI_type_node,
21549                                 NULL_TREE);
21550
21551   tree v4si_ftype_v4si_v4si_v2di
21552     = build_function_type_list (V4SI_type_node,
21553                                 V4SI_type_node,
21554                                 V4SI_type_node,
21555                                 V2DI_type_node,
21556                                 NULL_TREE);
21557
21558   tree v8hi_ftype_v8hi_v8hi_v8hi
21559     = build_function_type_list (V8HI_type_node,
21560                                 V8HI_type_node,
21561                                 V8HI_type_node,
21562                                 V8HI_type_node,
21563                                 NULL_TREE);
21564
21565   tree v8hi_ftype_v8hi_v8hi_v4si
21566     = build_function_type_list (V8HI_type_node,
21567                                 V8HI_type_node,
21568                                 V8HI_type_node,
21569                                 V4SI_type_node,
21570                                 NULL_TREE);
21571
21572   tree v2df_ftype_v2df_v2df_v16qi
21573     = build_function_type_list (V2DF_type_node,
21574                                 V2DF_type_node,
21575                                 V2DF_type_node,
21576                                 V16QI_type_node,
21577                                 NULL_TREE);
21578
21579   tree v4sf_ftype_v4sf_v4sf_v16qi
21580     = build_function_type_list (V4SF_type_node,
21581                                 V4SF_type_node,
21582                                 V4SF_type_node,
21583                                 V16QI_type_node,
21584                                 NULL_TREE);
21585
21586   tree v2di_ftype_v2di_si
21587     = build_function_type_list (V2DI_type_node,
21588                                 V2DI_type_node,
21589                                 integer_type_node,
21590                                 NULL_TREE);
21591
21592   tree v4si_ftype_v4si_si
21593     = build_function_type_list (V4SI_type_node,
21594                                 V4SI_type_node,
21595                                 integer_type_node,
21596                                 NULL_TREE);
21597
21598   tree v8hi_ftype_v8hi_si
21599     = build_function_type_list (V8HI_type_node,
21600                                 V8HI_type_node,
21601                                 integer_type_node,
21602                                 NULL_TREE);
21603
21604   tree v16qi_ftype_v16qi_si
21605     = build_function_type_list (V16QI_type_node,
21606                                 V16QI_type_node,
21607                                 integer_type_node,
21608                                 NULL_TREE);
21609   tree v4sf_ftype_v4hi
21610     = build_function_type_list (V4SF_type_node,
21611                                 V4HI_type_node,
21612                                 NULL_TREE);
21613
21614   tree v4hi_ftype_v4sf
21615     = build_function_type_list (V4HI_type_node,
21616                                 V4SF_type_node,
21617                                 NULL_TREE);
21618
21619   tree v2di_ftype_v2di
21620     = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
21621
21622   tree v16qi_ftype_v8hi_v8hi
21623     = build_function_type_list (V16QI_type_node,
21624                                 V8HI_type_node, V8HI_type_node,
21625                                 NULL_TREE);
21626   tree v8hi_ftype_v4si_v4si
21627     = build_function_type_list (V8HI_type_node,
21628                                 V4SI_type_node, V4SI_type_node,
21629                                 NULL_TREE);
21630   tree v8hi_ftype_v16qi_v16qi 
21631     = build_function_type_list (V8HI_type_node,
21632                                 V16QI_type_node, V16QI_type_node,
21633                                 NULL_TREE);
21634   tree v4hi_ftype_v8qi_v8qi 
21635     = build_function_type_list (V4HI_type_node,
21636                                 V8QI_type_node, V8QI_type_node,
21637                                 NULL_TREE);
21638   tree unsigned_ftype_unsigned_uchar
21639     = build_function_type_list (unsigned_type_node,
21640                                 unsigned_type_node,
21641                                 unsigned_char_type_node,
21642                                 NULL_TREE);
21643   tree unsigned_ftype_unsigned_ushort
21644     = build_function_type_list (unsigned_type_node,
21645                                 unsigned_type_node,
21646                                 short_unsigned_type_node,
21647                                 NULL_TREE);
21648   tree unsigned_ftype_unsigned_unsigned
21649     = build_function_type_list (unsigned_type_node,
21650                                 unsigned_type_node,
21651                                 unsigned_type_node,
21652                                 NULL_TREE);
21653   tree uint64_ftype_uint64_uint64
21654     = build_function_type_list (long_long_unsigned_type_node,
21655                                 long_long_unsigned_type_node,
21656                                 long_long_unsigned_type_node,
21657                                 NULL_TREE);
21658   tree float_ftype_float
21659     = build_function_type_list (float_type_node,
21660                                 float_type_node,
21661                                 NULL_TREE);
21662
21663   /* AVX builtins  */
21664   tree V32QI_type_node = build_vector_type_for_mode (char_type_node,
21665                                                      V32QImode);
21666   tree V8SI_type_node = build_vector_type_for_mode (intSI_type_node,
21667                                                     V8SImode);
21668   tree V8SF_type_node = build_vector_type_for_mode (float_type_node,
21669                                                     V8SFmode);
21670   tree V4DI_type_node = build_vector_type_for_mode (long_long_integer_type_node,
21671                                                     V4DImode);
21672   tree V4DF_type_node = build_vector_type_for_mode (double_type_node,
21673                                                     V4DFmode);
21674   tree v8sf_ftype_v8sf
21675     = build_function_type_list (V8SF_type_node,
21676                                 V8SF_type_node,
21677                                 NULL_TREE);
21678   tree v8si_ftype_v8sf
21679     = build_function_type_list (V8SI_type_node,
21680                                 V8SF_type_node,
21681                                 NULL_TREE);
21682   tree v8sf_ftype_v8si
21683     = build_function_type_list (V8SF_type_node,
21684                                 V8SI_type_node,
21685                                 NULL_TREE);
21686   tree v4si_ftype_v4df
21687     = build_function_type_list (V4SI_type_node,
21688                                 V4DF_type_node,
21689                                 NULL_TREE);
21690   tree v4df_ftype_v4df
21691     = build_function_type_list (V4DF_type_node,
21692                                 V4DF_type_node,
21693                                 NULL_TREE);
21694   tree v4df_ftype_v4si
21695     = build_function_type_list (V4DF_type_node,
21696                                 V4SI_type_node,
21697                                 NULL_TREE);
21698   tree v4df_ftype_v4sf
21699     = build_function_type_list (V4DF_type_node,
21700                                 V4SF_type_node,
21701                                 NULL_TREE);
21702   tree v4sf_ftype_v4df
21703     = build_function_type_list (V4SF_type_node,
21704                                 V4DF_type_node,
21705                                 NULL_TREE);
21706   tree v8sf_ftype_v8sf_v8sf
21707     = build_function_type_list (V8SF_type_node,
21708                                 V8SF_type_node, V8SF_type_node,
21709                                 NULL_TREE);
21710   tree v4df_ftype_v4df_v4df
21711     = build_function_type_list (V4DF_type_node,
21712                                 V4DF_type_node, V4DF_type_node,
21713                                 NULL_TREE);
21714   tree v8sf_ftype_v8sf_int
21715     = build_function_type_list (V8SF_type_node,
21716                                 V8SF_type_node, integer_type_node,
21717                                 NULL_TREE);
21718   tree v4si_ftype_v8si_int
21719     = build_function_type_list (V4SI_type_node,
21720                                 V8SI_type_node, integer_type_node,
21721                                 NULL_TREE);
21722   tree v4df_ftype_v4df_int
21723     = build_function_type_list (V4DF_type_node,
21724                                 V4DF_type_node, integer_type_node,
21725                                 NULL_TREE);
21726   tree v4sf_ftype_v8sf_int
21727     = build_function_type_list (V4SF_type_node,
21728                                 V8SF_type_node, integer_type_node,
21729                                 NULL_TREE);
21730   tree v2df_ftype_v4df_int
21731     = build_function_type_list (V2DF_type_node,
21732                                 V4DF_type_node, integer_type_node,
21733                                 NULL_TREE);
21734   tree v8sf_ftype_v8sf_v8sf_int
21735     = build_function_type_list (V8SF_type_node,
21736                                 V8SF_type_node, V8SF_type_node,
21737                                 integer_type_node,
21738                                 NULL_TREE);
21739   tree v8sf_ftype_v8sf_v8sf_v8sf
21740     = build_function_type_list (V8SF_type_node,
21741                                 V8SF_type_node, V8SF_type_node,
21742                                 V8SF_type_node,
21743                                 NULL_TREE);
21744   tree v4df_ftype_v4df_v4df_v4df
21745     = build_function_type_list (V4DF_type_node,
21746                                 V4DF_type_node, V4DF_type_node,
21747                                 V4DF_type_node,
21748                                 NULL_TREE);
21749   tree v8si_ftype_v8si_v8si_int
21750     = build_function_type_list (V8SI_type_node,
21751                                 V8SI_type_node, V8SI_type_node,
21752                                 integer_type_node,
21753                                 NULL_TREE);
21754   tree v4df_ftype_v4df_v4df_int
21755     = build_function_type_list (V4DF_type_node,
21756                                 V4DF_type_node, V4DF_type_node,
21757                                 integer_type_node,
21758                                 NULL_TREE);
21759   tree v8sf_ftype_v8sf_v8sf_v8si_int
21760     = build_function_type_list (V8SF_type_node,
21761                                 V8SF_type_node, V8SF_type_node,
21762                                 V8SI_type_node, integer_type_node,
21763                                 NULL_TREE);
21764   tree v4df_ftype_v4df_v4df_v4di_int
21765     = build_function_type_list (V4DF_type_node,
21766                                 V4DF_type_node, V4DF_type_node,
21767                                 V4DI_type_node, integer_type_node,
21768                                 NULL_TREE);
21769   tree v4sf_ftype_v4sf_v4sf_v4si_int
21770     = build_function_type_list (V4SF_type_node,
21771                                 V4SF_type_node, V4SF_type_node,
21772                                 V4SI_type_node, integer_type_node,
21773                                 NULL_TREE);
21774   tree v2df_ftype_v2df_v2df_v2di_int
21775     = build_function_type_list (V2DF_type_node,
21776                                 V2DF_type_node, V2DF_type_node,
21777                                 V2DI_type_node, integer_type_node,
21778                                 NULL_TREE);
21779   tree v8sf_ftype_pcfloat
21780     = build_function_type_list (V8SF_type_node,
21781                                 pcfloat_type_node,
21782                                 NULL_TREE);
21783   tree v4df_ftype_pcdouble
21784     = build_function_type_list (V4DF_type_node,
21785                                 pcdouble_type_node,
21786                                 NULL_TREE);
21787   tree pcv4sf_type_node
21788     = build_pointer_type (build_type_variant (V4SF_type_node, 1, 0));
21789   tree pcv2df_type_node
21790     = build_pointer_type (build_type_variant (V2DF_type_node, 1, 0));
21791   tree v8sf_ftype_pcv4sf
21792     = build_function_type_list (V8SF_type_node,
21793                                 pcv4sf_type_node,
21794                                 NULL_TREE);
21795   tree v4df_ftype_pcv2df
21796     = build_function_type_list (V4DF_type_node,
21797                                 pcv2df_type_node,
21798                                 NULL_TREE);
21799   tree v32qi_ftype_pcchar
21800     = build_function_type_list (V32QI_type_node,
21801                                 pcchar_type_node,
21802                                 NULL_TREE);
21803   tree void_ftype_pchar_v32qi
21804     = build_function_type_list (void_type_node,
21805                                 pchar_type_node, V32QI_type_node,
21806                                 NULL_TREE);
21807   tree v8si_ftype_v8si_v4si_int
21808     = build_function_type_list (V8SI_type_node,
21809                                 V8SI_type_node, V4SI_type_node,
21810                                 integer_type_node,
21811                                 NULL_TREE);
21812   tree v8sf_ftype_v8sf_v4sf_int
21813     = build_function_type_list (V8SF_type_node,
21814                                 V8SF_type_node, V4SF_type_node,
21815                                 integer_type_node,
21816                                 NULL_TREE);
21817   tree v4df_ftype_v4df_v2df_int
21818     = build_function_type_list (V4DF_type_node,
21819                                 V4DF_type_node, V2DF_type_node,
21820                                 integer_type_node,
21821                                 NULL_TREE);
21822   tree void_ftype_pfloat_v8sf
21823     = build_function_type_list (void_type_node,
21824                                 pfloat_type_node, V8SF_type_node,
21825                                 NULL_TREE);
21826   tree void_ftype_pdouble_v4df
21827     = build_function_type_list (void_type_node,
21828                                 pdouble_type_node, V4DF_type_node,
21829                                 NULL_TREE);
21830   tree pv8sf_type_node = build_pointer_type (V8SF_type_node);
21831   tree pv4sf_type_node = build_pointer_type (V4SF_type_node);
21832   tree pv4df_type_node = build_pointer_type (V4DF_type_node);
21833   tree pv2df_type_node = build_pointer_type (V2DF_type_node);
21834   tree pcv8sf_type_node
21835     = build_pointer_type (build_type_variant (V8SF_type_node, 1, 0));
21836   tree pcv4df_type_node
21837     = build_pointer_type (build_type_variant (V4DF_type_node, 1, 0));
21838   tree v8sf_ftype_pcv8sf_v8sf
21839     = build_function_type_list (V8SF_type_node,
21840                                 pcv8sf_type_node, V8SF_type_node,
21841                                 NULL_TREE);
21842   tree v4df_ftype_pcv4df_v4df
21843     = build_function_type_list (V4DF_type_node,
21844                                 pcv4df_type_node, V4DF_type_node,
21845                                 NULL_TREE);
21846   tree v4sf_ftype_pcv4sf_v4sf
21847     = build_function_type_list (V4SF_type_node,
21848                                 pcv4sf_type_node, V4SF_type_node,
21849                                 NULL_TREE);
21850   tree v2df_ftype_pcv2df_v2df
21851     = build_function_type_list (V2DF_type_node,
21852                                 pcv2df_type_node, V2DF_type_node,
21853                                 NULL_TREE);
21854   tree void_ftype_pv8sf_v8sf_v8sf
21855     = build_function_type_list (void_type_node,
21856                                 pv8sf_type_node, V8SF_type_node,
21857                                 V8SF_type_node,
21858                                 NULL_TREE);
21859   tree void_ftype_pv4df_v4df_v4df
21860     = build_function_type_list (void_type_node,
21861                                 pv4df_type_node, V4DF_type_node,
21862                                 V4DF_type_node,
21863                                 NULL_TREE);
21864   tree void_ftype_pv4sf_v4sf_v4sf
21865     = build_function_type_list (void_type_node,
21866                                 pv4sf_type_node, V4SF_type_node,
21867                                 V4SF_type_node,
21868                                 NULL_TREE);
21869   tree void_ftype_pv2df_v2df_v2df
21870     = build_function_type_list (void_type_node,
21871                                 pv2df_type_node, V2DF_type_node,
21872                                 V2DF_type_node,
21873                                 NULL_TREE);
21874   tree v4df_ftype_v2df
21875     = build_function_type_list (V4DF_type_node,
21876                                 V2DF_type_node,
21877                                 NULL_TREE);
21878   tree v8sf_ftype_v4sf
21879     = build_function_type_list (V8SF_type_node,
21880                                 V4SF_type_node,
21881                                 NULL_TREE);
21882   tree v8si_ftype_v4si
21883     = build_function_type_list (V8SI_type_node,
21884                                 V4SI_type_node,
21885                                 NULL_TREE);
21886   tree v2df_ftype_v4df
21887     = build_function_type_list (V2DF_type_node,
21888                                 V4DF_type_node,
21889                                 NULL_TREE);
21890   tree v4sf_ftype_v8sf
21891     = build_function_type_list (V4SF_type_node,
21892                                 V8SF_type_node,
21893                                 NULL_TREE);
21894   tree v4si_ftype_v8si
21895     = build_function_type_list (V4SI_type_node,
21896                                 V8SI_type_node,
21897                                 NULL_TREE);
21898   tree int_ftype_v4df
21899     = build_function_type_list (integer_type_node,
21900                                 V4DF_type_node,
21901                                 NULL_TREE);
21902   tree int_ftype_v8sf
21903     = build_function_type_list (integer_type_node,
21904                                 V8SF_type_node,
21905                                 NULL_TREE);
21906   tree int_ftype_v8sf_v8sf
21907     = build_function_type_list (integer_type_node,
21908                                 V8SF_type_node, V8SF_type_node,
21909                                 NULL_TREE);
21910   tree int_ftype_v4di_v4di
21911     = build_function_type_list (integer_type_node,
21912                                 V4DI_type_node, V4DI_type_node,
21913                                 NULL_TREE);
21914   tree int_ftype_v4df_v4df
21915     = build_function_type_list (integer_type_node,
21916                                 V4DF_type_node, V4DF_type_node,
21917                                 NULL_TREE);
21918   tree v8sf_ftype_v8sf_v8si
21919     = build_function_type_list (V8SF_type_node,
21920                                 V8SF_type_node, V8SI_type_node,
21921                                 NULL_TREE);
21922   tree v4df_ftype_v4df_v4di
21923     = build_function_type_list (V4DF_type_node,
21924                                 V4DF_type_node, V4DI_type_node,
21925                                 NULL_TREE);
21926   tree v4sf_ftype_v4sf_v4si
21927     = build_function_type_list (V4SF_type_node,
21928                                 V4SF_type_node, V4SI_type_node, NULL_TREE);
21929   tree v2df_ftype_v2df_v2di
21930     = build_function_type_list (V2DF_type_node,
21931                                 V2DF_type_node, V2DI_type_node, NULL_TREE);
21932
21933   tree ftype;
21934
21935   /* Add all special builtins with variable number of operands.  */
21936   for (i = 0, d = bdesc_special_args;
21937        i < ARRAY_SIZE (bdesc_special_args);
21938        i++, d++)
21939     {
21940       tree type;
21941
21942       if (d->name == 0)
21943         continue;
21944
21945       switch ((enum ix86_special_builtin_type) d->flag)
21946         {
21947         case VOID_FTYPE_VOID:
21948           type = void_ftype_void;
21949           break;
21950         case V32QI_FTYPE_PCCHAR:
21951           type = v32qi_ftype_pcchar;
21952           break;
21953         case V16QI_FTYPE_PCCHAR:
21954           type = v16qi_ftype_pcchar;
21955           break;
21956         case V8SF_FTYPE_PCV4SF:
21957           type = v8sf_ftype_pcv4sf;
21958           break;
21959         case V8SF_FTYPE_PCFLOAT:
21960           type = v8sf_ftype_pcfloat;
21961           break;
21962         case V4DF_FTYPE_PCV2DF:
21963           type = v4df_ftype_pcv2df;
21964           break;
21965         case V4DF_FTYPE_PCDOUBLE:
21966           type = v4df_ftype_pcdouble;
21967           break;
21968         case V4SF_FTYPE_PCFLOAT:
21969           type = v4sf_ftype_pcfloat;
21970           break;
21971         case V2DI_FTYPE_PV2DI:
21972           type = v2di_ftype_pv2di;
21973           break;
21974         case V2DF_FTYPE_PCDOUBLE:
21975           type = v2df_ftype_pcdouble;
21976           break;
21977         case V8SF_FTYPE_PCV8SF_V8SF:
21978           type = v8sf_ftype_pcv8sf_v8sf;
21979           break;
21980         case V4DF_FTYPE_PCV4DF_V4DF:
21981           type = v4df_ftype_pcv4df_v4df;
21982           break;
21983         case V4SF_FTYPE_V4SF_PCV2SF:
21984           type = v4sf_ftype_v4sf_pcv2sf;
21985           break;
21986         case V4SF_FTYPE_PCV4SF_V4SF:
21987           type = v4sf_ftype_pcv4sf_v4sf;
21988           break;
21989         case V2DF_FTYPE_V2DF_PCDOUBLE:
21990           type = v2df_ftype_v2df_pcdouble;
21991           break;
21992         case V2DF_FTYPE_PCV2DF_V2DF:
21993           type = v2df_ftype_pcv2df_v2df;
21994           break;
21995         case VOID_FTYPE_PV2SF_V4SF:
21996           type = void_ftype_pv2sf_v4sf;
21997           break;
21998         case VOID_FTYPE_PV2DI_V2DI:
21999           type = void_ftype_pv2di_v2di;
22000           break;
22001         case VOID_FTYPE_PCHAR_V32QI:
22002           type = void_ftype_pchar_v32qi;
22003           break;
22004         case VOID_FTYPE_PCHAR_V16QI:
22005           type = void_ftype_pchar_v16qi;
22006           break;
22007         case VOID_FTYPE_PFLOAT_V8SF:
22008           type = void_ftype_pfloat_v8sf;
22009           break;
22010         case VOID_FTYPE_PFLOAT_V4SF:
22011           type = void_ftype_pfloat_v4sf;
22012           break;
22013         case VOID_FTYPE_PDOUBLE_V4DF:
22014           type = void_ftype_pdouble_v4df;
22015           break;
22016         case VOID_FTYPE_PDOUBLE_V2DF:
22017           type = void_ftype_pdouble_v2df;
22018           break;
22019         case VOID_FTYPE_PDI_DI:
22020           type = void_ftype_pdi_di;
22021           break;
22022         case VOID_FTYPE_PINT_INT:
22023           type = void_ftype_pint_int;
22024           break;
22025         case VOID_FTYPE_PV8SF_V8SF_V8SF:
22026           type = void_ftype_pv8sf_v8sf_v8sf;
22027           break;
22028         case VOID_FTYPE_PV4DF_V4DF_V4DF:
22029           type = void_ftype_pv4df_v4df_v4df;
22030           break;
22031         case VOID_FTYPE_PV4SF_V4SF_V4SF:
22032           type = void_ftype_pv4sf_v4sf_v4sf;
22033           break;
22034         case VOID_FTYPE_PV2DF_V2DF_V2DF:
22035           type = void_ftype_pv2df_v2df_v2df;
22036           break;
22037         default:
22038           gcc_unreachable ();
22039         }
22040
22041       def_builtin (d->mask, d->name, type, d->code);
22042     }
22043
22044   /* Add all builtins with variable number of operands.  */
22045   for (i = 0, d = bdesc_args;
22046        i < ARRAY_SIZE (bdesc_args);
22047        i++, d++)
22048     {
22049       tree type;
22050
22051       if (d->name == 0)
22052         continue;
22053
22054       switch ((enum ix86_builtin_type) d->flag)
22055         {
22056         case FLOAT_FTYPE_FLOAT:
22057           type = float_ftype_float;
22058           break;
22059         case INT_FTYPE_V8SF_V8SF_PTEST:
22060           type = int_ftype_v8sf_v8sf;
22061           break;
22062         case INT_FTYPE_V4DI_V4DI_PTEST:
22063           type = int_ftype_v4di_v4di;
22064           break;
22065         case INT_FTYPE_V4DF_V4DF_PTEST:
22066           type = int_ftype_v4df_v4df;
22067           break;
22068         case INT_FTYPE_V4SF_V4SF_PTEST:
22069           type = int_ftype_v4sf_v4sf;
22070           break;
22071         case INT_FTYPE_V2DI_V2DI_PTEST:
22072           type = int_ftype_v2di_v2di;
22073           break;
22074         case INT_FTYPE_V2DF_V2DF_PTEST:
22075           type = int_ftype_v2df_v2df;
22076           break;
22077         case INT64_FTYPE_V4SF:
22078           type = int64_ftype_v4sf;
22079           break;
22080         case INT64_FTYPE_V2DF:
22081           type = int64_ftype_v2df;
22082           break;
22083         case INT_FTYPE_V16QI:
22084           type = int_ftype_v16qi;
22085           break;
22086         case INT_FTYPE_V8QI:
22087           type = int_ftype_v8qi;
22088           break;
22089         case INT_FTYPE_V8SF:
22090           type = int_ftype_v8sf;
22091           break;
22092         case INT_FTYPE_V4DF:
22093           type = int_ftype_v4df;
22094           break;
22095         case INT_FTYPE_V4SF:
22096           type = int_ftype_v4sf;
22097           break;
22098         case INT_FTYPE_V2DF:
22099           type = int_ftype_v2df;
22100           break;
22101         case V16QI_FTYPE_V16QI:
22102           type = v16qi_ftype_v16qi;
22103           break;
22104         case V8SI_FTYPE_V8SF:
22105           type = v8si_ftype_v8sf;
22106           break;
22107         case V8SI_FTYPE_V4SI:
22108           type = v8si_ftype_v4si;
22109           break;
22110         case V8HI_FTYPE_V8HI:
22111           type = v8hi_ftype_v8hi;
22112           break;
22113         case V8HI_FTYPE_V16QI:
22114           type = v8hi_ftype_v16qi;
22115           break;
22116         case V8QI_FTYPE_V8QI:
22117           type = v8qi_ftype_v8qi;
22118           break;
22119         case V8SF_FTYPE_V8SF:
22120           type = v8sf_ftype_v8sf;
22121           break;
22122         case V8SF_FTYPE_V8SI:
22123           type = v8sf_ftype_v8si;
22124           break;
22125         case V8SF_FTYPE_V4SF:
22126           type = v8sf_ftype_v4sf;
22127           break;
22128         case V4SI_FTYPE_V4DF:
22129           type = v4si_ftype_v4df;
22130           break;
22131         case V4SI_FTYPE_V4SI:
22132           type = v4si_ftype_v4si;
22133           break;
22134         case V4SI_FTYPE_V16QI:
22135           type = v4si_ftype_v16qi;
22136           break;
22137         case V4SI_FTYPE_V8SI:
22138           type = v4si_ftype_v8si;
22139           break;
22140         case V4SI_FTYPE_V8HI:
22141           type = v4si_ftype_v8hi;
22142           break;
22143         case V4SI_FTYPE_V4SF:
22144           type = v4si_ftype_v4sf;
22145           break;
22146         case V4SI_FTYPE_V2DF:
22147           type = v4si_ftype_v2df;
22148           break;
22149         case V4HI_FTYPE_V4HI:
22150           type = v4hi_ftype_v4hi;
22151           break;
22152         case V4DF_FTYPE_V4DF:
22153           type = v4df_ftype_v4df;
22154           break;
22155         case V4DF_FTYPE_V4SI:
22156           type = v4df_ftype_v4si;
22157           break;
22158         case V4DF_FTYPE_V4SF:
22159           type = v4df_ftype_v4sf;
22160           break;
22161         case V4DF_FTYPE_V2DF:
22162           type = v4df_ftype_v2df;
22163           break;
22164         case V4SF_FTYPE_V4SF:
22165         case V4SF_FTYPE_V4SF_VEC_MERGE:
22166           type = v4sf_ftype_v4sf;
22167           break;
22168         case V4SF_FTYPE_V8SF:
22169           type = v4sf_ftype_v8sf;
22170           break;
22171         case V4SF_FTYPE_V4SI:
22172           type = v4sf_ftype_v4si;
22173           break;
22174         case V4SF_FTYPE_V4DF:
22175           type = v4sf_ftype_v4df;
22176           break;
22177         case V4SF_FTYPE_V2DF:
22178           type = v4sf_ftype_v2df;
22179           break;
22180         case V2DI_FTYPE_V2DI:
22181           type = v2di_ftype_v2di;
22182           break;
22183         case V2DI_FTYPE_V16QI:
22184           type = v2di_ftype_v16qi;
22185           break;
22186         case V2DI_FTYPE_V8HI:
22187           type = v2di_ftype_v8hi;
22188           break;
22189         case V2DI_FTYPE_V4SI:
22190           type = v2di_ftype_v4si;
22191           break;
22192         case V2SI_FTYPE_V2SI:
22193           type = v2si_ftype_v2si;
22194           break;
22195         case V2SI_FTYPE_V4SF:
22196           type = v2si_ftype_v4sf;
22197           break;
22198         case V2SI_FTYPE_V2DF:
22199           type = v2si_ftype_v2df;
22200           break;
22201         case V2SI_FTYPE_V2SF:
22202           type = v2si_ftype_v2sf;
22203           break;
22204         case V2DF_FTYPE_V4DF:
22205           type = v2df_ftype_v4df;
22206           break;
22207         case V2DF_FTYPE_V4SF:
22208           type = v2df_ftype_v4sf;
22209           break;
22210         case V2DF_FTYPE_V2DF:
22211         case V2DF_FTYPE_V2DF_VEC_MERGE:
22212           type = v2df_ftype_v2df;
22213           break;
22214         case V2DF_FTYPE_V2SI:
22215           type = v2df_ftype_v2si;
22216           break;
22217         case V2DF_FTYPE_V4SI:
22218           type = v2df_ftype_v4si;
22219           break;
22220         case V2SF_FTYPE_V2SF:
22221           type = v2sf_ftype_v2sf;
22222           break;
22223         case V2SF_FTYPE_V2SI:
22224           type = v2sf_ftype_v2si;
22225           break;
22226         case V16QI_FTYPE_V16QI_V16QI:
22227           type = v16qi_ftype_v16qi_v16qi;
22228           break;
22229         case V16QI_FTYPE_V8HI_V8HI:
22230           type = v16qi_ftype_v8hi_v8hi;
22231           break;
22232         case V8QI_FTYPE_V8QI_V8QI:
22233           type = v8qi_ftype_v8qi_v8qi;
22234           break;
22235         case V8QI_FTYPE_V4HI_V4HI:
22236           type = v8qi_ftype_v4hi_v4hi;
22237           break;
22238         case V8HI_FTYPE_V8HI_V8HI:
22239         case V8HI_FTYPE_V8HI_V8HI_COUNT:
22240           type = v8hi_ftype_v8hi_v8hi;
22241           break;
22242         case V8HI_FTYPE_V16QI_V16QI:
22243           type = v8hi_ftype_v16qi_v16qi;
22244           break;
22245         case V8HI_FTYPE_V4SI_V4SI:
22246           type = v8hi_ftype_v4si_v4si;
22247           break;
22248         case V8HI_FTYPE_V8HI_SI_COUNT:
22249           type = v8hi_ftype_v8hi_int;
22250           break;
22251         case V8SF_FTYPE_V8SF_V8SF:
22252           type = v8sf_ftype_v8sf_v8sf;
22253           break;
22254         case V8SF_FTYPE_V8SF_V8SI:
22255           type = v8sf_ftype_v8sf_v8si;
22256           break;
22257         case V4SI_FTYPE_V4SI_V4SI:
22258         case V4SI_FTYPE_V4SI_V4SI_COUNT:
22259           type = v4si_ftype_v4si_v4si;
22260           break;
22261         case V4SI_FTYPE_V8HI_V8HI:
22262           type = v4si_ftype_v8hi_v8hi;
22263           break;
22264         case V4SI_FTYPE_V4SF_V4SF:
22265           type = v4si_ftype_v4sf_v4sf;
22266           break;
22267         case V4SI_FTYPE_V2DF_V2DF:
22268           type = v4si_ftype_v2df_v2df;
22269           break;
22270         case V4SI_FTYPE_V4SI_SI_COUNT:
22271           type = v4si_ftype_v4si_int;
22272           break;
22273         case V4HI_FTYPE_V4HI_V4HI:
22274         case V4HI_FTYPE_V4HI_V4HI_COUNT:
22275           type = v4hi_ftype_v4hi_v4hi;
22276           break;
22277         case V4HI_FTYPE_V8QI_V8QI:
22278           type = v4hi_ftype_v8qi_v8qi;
22279           break;
22280         case V4HI_FTYPE_V2SI_V2SI:
22281           type = v4hi_ftype_v2si_v2si;
22282           break;
22283         case V4HI_FTYPE_V4HI_SI_COUNT:
22284           type = v4hi_ftype_v4hi_int;
22285           break;
22286         case V4DF_FTYPE_V4DF_V4DF:
22287           type = v4df_ftype_v4df_v4df;
22288           break;
22289         case V4DF_FTYPE_V4DF_V4DI:
22290           type = v4df_ftype_v4df_v4di;
22291           break;
22292         case V4SF_FTYPE_V4SF_V4SF:
22293         case V4SF_FTYPE_V4SF_V4SF_SWAP:
22294           type = v4sf_ftype_v4sf_v4sf;
22295           break;
22296         case V4SF_FTYPE_V4SF_V4SI:
22297           type = v4sf_ftype_v4sf_v4si;
22298           break;
22299         case V4SF_FTYPE_V4SF_V2SI:
22300           type = v4sf_ftype_v4sf_v2si;
22301           break;
22302         case V4SF_FTYPE_V4SF_V2DF:
22303           type = v4sf_ftype_v4sf_v2df;
22304           break;
22305         case V4SF_FTYPE_V4SF_DI:
22306           type = v4sf_ftype_v4sf_int64;
22307           break;
22308         case V4SF_FTYPE_V4SF_SI:
22309           type = v4sf_ftype_v4sf_int;
22310           break;
22311         case V2DI_FTYPE_V2DI_V2DI:
22312         case V2DI_FTYPE_V2DI_V2DI_COUNT:
22313           type = v2di_ftype_v2di_v2di;
22314           break;
22315         case V2DI_FTYPE_V16QI_V16QI:
22316           type = v2di_ftype_v16qi_v16qi;
22317           break;
22318         case V2DI_FTYPE_V4SI_V4SI:
22319           type = v2di_ftype_v4si_v4si;
22320           break;
22321         case V2DI_FTYPE_V2DI_V16QI:
22322           type = v2di_ftype_v2di_v16qi;
22323           break;
22324         case V2DI_FTYPE_V2DF_V2DF:
22325           type = v2di_ftype_v2df_v2df;
22326           break;
22327         case V2DI_FTYPE_V2DI_SI_COUNT:
22328           type = v2di_ftype_v2di_int;
22329           break;
22330         case V2SI_FTYPE_V2SI_V2SI:
22331         case V2SI_FTYPE_V2SI_V2SI_COUNT:
22332           type = v2si_ftype_v2si_v2si;
22333           break;
22334         case V2SI_FTYPE_V4HI_V4HI:
22335           type = v2si_ftype_v4hi_v4hi;
22336           break;
22337         case V2SI_FTYPE_V2SF_V2SF:
22338           type = v2si_ftype_v2sf_v2sf;
22339           break;
22340         case V2SI_FTYPE_V2SI_SI_COUNT:
22341           type = v2si_ftype_v2si_int;
22342           break;
22343         case V2DF_FTYPE_V2DF_V2DF:
22344         case V2DF_FTYPE_V2DF_V2DF_SWAP:
22345           type = v2df_ftype_v2df_v2df;
22346           break;
22347         case V2DF_FTYPE_V2DF_V4SF:
22348           type = v2df_ftype_v2df_v4sf;
22349           break;
22350         case V2DF_FTYPE_V2DF_V2DI:
22351           type = v2df_ftype_v2df_v2di;
22352           break;
22353         case V2DF_FTYPE_V2DF_DI:
22354           type = v2df_ftype_v2df_int64;
22355           break;
22356         case V2DF_FTYPE_V2DF_SI:
22357           type = v2df_ftype_v2df_int;
22358           break;
22359         case V2SF_FTYPE_V2SF_V2SF:
22360           type = v2sf_ftype_v2sf_v2sf;
22361           break;
22362         case V1DI_FTYPE_V1DI_V1DI:
22363         case V1DI_FTYPE_V1DI_V1DI_COUNT:
22364           type = v1di_ftype_v1di_v1di;
22365           break;
22366         case V1DI_FTYPE_V8QI_V8QI:
22367           type = v1di_ftype_v8qi_v8qi;
22368           break;
22369         case V1DI_FTYPE_V2SI_V2SI:
22370           type = v1di_ftype_v2si_v2si;
22371           break;
22372         case V1DI_FTYPE_V1DI_SI_COUNT:
22373           type = v1di_ftype_v1di_int;
22374           break;
22375         case UINT64_FTYPE_UINT64_UINT64:
22376           type = uint64_ftype_uint64_uint64;
22377           break;
22378         case UINT_FTYPE_UINT_UINT:
22379           type = unsigned_ftype_unsigned_unsigned;
22380           break;
22381         case UINT_FTYPE_UINT_USHORT:
22382           type = unsigned_ftype_unsigned_ushort;
22383           break;
22384         case UINT_FTYPE_UINT_UCHAR:
22385           type = unsigned_ftype_unsigned_uchar;
22386           break;
22387         case V8HI_FTYPE_V8HI_INT:
22388           type = v8hi_ftype_v8hi_int;
22389           break;
22390         case V8SF_FTYPE_V8SF_INT:
22391           type = v8sf_ftype_v8sf_int;
22392           break;
22393         case V4SI_FTYPE_V4SI_INT:
22394           type = v4si_ftype_v4si_int;
22395           break;
22396         case V4SI_FTYPE_V8SI_INT:
22397           type = v4si_ftype_v8si_int;
22398           break;
22399         case V4HI_FTYPE_V4HI_INT:
22400           type = v4hi_ftype_v4hi_int;
22401           break;
22402         case V4DF_FTYPE_V4DF_INT:
22403           type = v4df_ftype_v4df_int;
22404           break;
22405         case V4SF_FTYPE_V4SF_INT:
22406           type = v4sf_ftype_v4sf_int;
22407           break;
22408         case V4SF_FTYPE_V8SF_INT:
22409           type = v4sf_ftype_v8sf_int;
22410           break;
22411         case V2DI_FTYPE_V2DI_INT:
22412         case V2DI2TI_FTYPE_V2DI_INT:
22413           type = v2di_ftype_v2di_int;
22414           break;
22415         case V2DF_FTYPE_V2DF_INT:
22416           type = v2df_ftype_v2df_int;
22417           break;
22418         case V2DF_FTYPE_V4DF_INT:
22419           type = v2df_ftype_v4df_int;
22420           break;
22421         case V16QI_FTYPE_V16QI_V16QI_V16QI:
22422           type = v16qi_ftype_v16qi_v16qi_v16qi;
22423           break;
22424         case V8SF_FTYPE_V8SF_V8SF_V8SF:
22425           type = v8sf_ftype_v8sf_v8sf_v8sf;
22426           break;
22427         case V4DF_FTYPE_V4DF_V4DF_V4DF:
22428           type = v4df_ftype_v4df_v4df_v4df;
22429           break;
22430         case V4SF_FTYPE_V4SF_V4SF_V4SF:
22431           type = v4sf_ftype_v4sf_v4sf_v4sf;
22432           break;
22433         case V2DF_FTYPE_V2DF_V2DF_V2DF:
22434           type = v2df_ftype_v2df_v2df_v2df;
22435           break;
22436         case V16QI_FTYPE_V16QI_V16QI_INT:
22437           type = v16qi_ftype_v16qi_v16qi_int;
22438           break;
22439         case V8SI_FTYPE_V8SI_V8SI_INT:
22440           type = v8si_ftype_v8si_v8si_int;
22441           break;
22442         case V8SI_FTYPE_V8SI_V4SI_INT:
22443           type = v8si_ftype_v8si_v4si_int;
22444           break;
22445         case V8HI_FTYPE_V8HI_V8HI_INT:
22446           type = v8hi_ftype_v8hi_v8hi_int;
22447           break;
22448         case V8SF_FTYPE_V8SF_V8SF_INT:
22449           type = v8sf_ftype_v8sf_v8sf_int;
22450           break;
22451         case V8SF_FTYPE_V8SF_V4SF_INT:
22452           type = v8sf_ftype_v8sf_v4sf_int;
22453           break;
22454         case V4SI_FTYPE_V4SI_V4SI_INT:
22455           type = v4si_ftype_v4si_v4si_int;
22456           break;
22457         case V4DF_FTYPE_V4DF_V4DF_INT:
22458           type = v4df_ftype_v4df_v4df_int;
22459           break;
22460         case V4DF_FTYPE_V4DF_V2DF_INT:
22461           type = v4df_ftype_v4df_v2df_int;
22462           break;
22463         case V4SF_FTYPE_V4SF_V4SF_INT:
22464           type = v4sf_ftype_v4sf_v4sf_int;
22465           break;
22466         case V2DI_FTYPE_V2DI_V2DI_INT:
22467         case V2DI2TI_FTYPE_V2DI_V2DI_INT:
22468           type = v2di_ftype_v2di_v2di_int;
22469           break;
22470         case V2DF_FTYPE_V2DF_V2DF_INT:
22471           type = v2df_ftype_v2df_v2df_int;
22472           break;
22473         case V2DI_FTYPE_V2DI_UINT_UINT:
22474           type = v2di_ftype_v2di_unsigned_unsigned;
22475           break;
22476         case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
22477           type = v2di_ftype_v2di_v2di_unsigned_unsigned;
22478           break;
22479         case V1DI2DI_FTYPE_V1DI_V1DI_INT:
22480           type = v1di_ftype_v1di_v1di_int;
22481           break;
22482         case V8SF_FTYPE_V8SF_V8SF_V8SI_INT:
22483           type = v8sf_ftype_v8sf_v8sf_v8si_int;
22484           break;
22485         case V4DF_FTYPE_V4DF_V4DF_V4DI_INT:
22486           type = v4df_ftype_v4df_v4df_v4di_int;
22487           break;
22488         case V4SF_FTYPE_V4SF_V4SF_V4SI_INT:
22489           type = v4sf_ftype_v4sf_v4sf_v4si_int;
22490           break;
22491         case V2DF_FTYPE_V2DF_V2DF_V2DI_INT:
22492           type = v2df_ftype_v2df_v2df_v2di_int;
22493           break;
22494         default:
22495           gcc_unreachable ();
22496         }
22497
22498       def_builtin_const (d->mask, d->name, type, d->code);
22499     }
22500
22501   /* pcmpestr[im] insns.  */
22502   for (i = 0, d = bdesc_pcmpestr;
22503        i < ARRAY_SIZE (bdesc_pcmpestr);
22504        i++, d++)
22505     {
22506       if (d->code == IX86_BUILTIN_PCMPESTRM128)
22507         ftype = v16qi_ftype_v16qi_int_v16qi_int_int;
22508       else
22509         ftype = int_ftype_v16qi_int_v16qi_int_int;
22510       def_builtin_const (d->mask, d->name, ftype, d->code);
22511     }
22512
22513   /* pcmpistr[im] insns.  */
22514   for (i = 0, d = bdesc_pcmpistr;
22515        i < ARRAY_SIZE (bdesc_pcmpistr);
22516        i++, d++)
22517     {
22518       if (d->code == IX86_BUILTIN_PCMPISTRM128)
22519         ftype = v16qi_ftype_v16qi_v16qi_int;
22520       else
22521         ftype = int_ftype_v16qi_v16qi_int;
22522       def_builtin_const (d->mask, d->name, ftype, d->code);
22523     }
22524
22525   /* comi/ucomi insns.  */
22526   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
22527     if (d->mask == OPTION_MASK_ISA_SSE2)
22528       def_builtin_const (d->mask, d->name, int_ftype_v2df_v2df, d->code);
22529     else
22530       def_builtin_const (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
22531
22532   /* SSE */
22533   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr", void_ftype_unsigned, IX86_BUILTIN_LDMXCSR);
22534   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr", unsigned_ftype_void, IX86_BUILTIN_STMXCSR);
22535
22536   /* SSE or 3DNow!A */
22537   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_maskmovq", void_ftype_v8qi_v8qi_pchar, IX86_BUILTIN_MASKMOVQ);
22538
22539   /* SSE2 */
22540   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu", void_ftype_v16qi_v16qi_pchar, IX86_BUILTIN_MASKMOVDQU);
22541
22542   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush", void_ftype_pcvoid, IX86_BUILTIN_CLFLUSH);
22543   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence", void_ftype_void, IX86_BUILTIN_MFENCE);
22544
22545   /* SSE3.  */
22546   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor", void_ftype_pcvoid_unsigned_unsigned, IX86_BUILTIN_MONITOR);
22547   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait", void_ftype_unsigned_unsigned, IX86_BUILTIN_MWAIT);
22548
22549   /* AES */
22550   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENC128);
22551   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENCLAST128);
22552   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDEC128);
22553   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDECLAST128);
22554   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128", v2di_ftype_v2di, IX86_BUILTIN_AESIMC128);
22555   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128", v2di_ftype_v2di_int, IX86_BUILTIN_AESKEYGENASSIST128);
22556
22557   /* PCLMUL */
22558   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128", v2di_ftype_v2di_v2di_int, IX86_BUILTIN_PCLMULQDQ128);
22559
22560   /* AVX */
22561   def_builtin (OPTION_MASK_ISA_AVX, "__builtin_ia32_vzeroupper", void_ftype_void,
22562                TARGET_64BIT ? IX86_BUILTIN_VZEROUPPER_REX64 : IX86_BUILTIN_VZEROUPPER);
22563
22564   /* Access to the vec_init patterns.  */
22565   ftype = build_function_type_list (V2SI_type_node, integer_type_node,
22566                                     integer_type_node, NULL_TREE);
22567   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si", ftype, IX86_BUILTIN_VEC_INIT_V2SI);
22568
22569   ftype = build_function_type_list (V4HI_type_node, short_integer_type_node,
22570                                     short_integer_type_node,
22571                                     short_integer_type_node,
22572                                     short_integer_type_node, NULL_TREE);
22573   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi", ftype, IX86_BUILTIN_VEC_INIT_V4HI);
22574
22575   ftype = build_function_type_list (V8QI_type_node, char_type_node,
22576                                     char_type_node, char_type_node,
22577                                     char_type_node, char_type_node,
22578                                     char_type_node, char_type_node,
22579                                     char_type_node, NULL_TREE);
22580   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi", ftype, IX86_BUILTIN_VEC_INIT_V8QI);
22581
22582   /* Access to the vec_extract patterns.  */
22583   ftype = build_function_type_list (double_type_node, V2DF_type_node,
22584                                     integer_type_node, NULL_TREE);
22585   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df", ftype, IX86_BUILTIN_VEC_EXT_V2DF);
22586
22587   ftype = build_function_type_list (long_long_integer_type_node,
22588                                     V2DI_type_node, integer_type_node,
22589                                     NULL_TREE);
22590   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di", ftype, IX86_BUILTIN_VEC_EXT_V2DI);
22591
22592   ftype = build_function_type_list (float_type_node, V4SF_type_node,
22593                                     integer_type_node, NULL_TREE);
22594   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf", ftype, IX86_BUILTIN_VEC_EXT_V4SF);
22595
22596   ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
22597                                     integer_type_node, NULL_TREE);
22598   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si", ftype, IX86_BUILTIN_VEC_EXT_V4SI);
22599
22600   ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
22601                                     integer_type_node, NULL_TREE);
22602   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi", ftype, IX86_BUILTIN_VEC_EXT_V8HI);
22603
22604   ftype = build_function_type_list (intHI_type_node, V4HI_type_node,
22605                                     integer_type_node, NULL_TREE);
22606   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_ext_v4hi", ftype, IX86_BUILTIN_VEC_EXT_V4HI);
22607
22608   ftype = build_function_type_list (intSI_type_node, V2SI_type_node,
22609                                     integer_type_node, NULL_TREE);
22610   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si", ftype, IX86_BUILTIN_VEC_EXT_V2SI);
22611
22612   ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
22613                                     integer_type_node, NULL_TREE);
22614   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi", ftype, IX86_BUILTIN_VEC_EXT_V16QI);
22615
22616   /* Access to the vec_set patterns.  */
22617   ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
22618                                     intDI_type_node,
22619                                     integer_type_node, NULL_TREE);
22620   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_vec_set_v2di", ftype, IX86_BUILTIN_VEC_SET_V2DI);
22621
22622   ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
22623                                     float_type_node,
22624                                     integer_type_node, NULL_TREE);
22625   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf", ftype, IX86_BUILTIN_VEC_SET_V4SF);
22626
22627   ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
22628                                     intSI_type_node,
22629                                     integer_type_node, NULL_TREE);
22630   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si", ftype, IX86_BUILTIN_VEC_SET_V4SI);
22631
22632   ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
22633                                     intHI_type_node,
22634                                     integer_type_node, NULL_TREE);
22635   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi", ftype, IX86_BUILTIN_VEC_SET_V8HI);
22636
22637   ftype = build_function_type_list (V4HI_type_node, V4HI_type_node,
22638                                     intHI_type_node,
22639                                     integer_type_node, NULL_TREE);
22640   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_set_v4hi", ftype, IX86_BUILTIN_VEC_SET_V4HI);
22641
22642   ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
22643                                     intQI_type_node,
22644                                     integer_type_node, NULL_TREE);
22645   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi", ftype, IX86_BUILTIN_VEC_SET_V16QI);
22646
22647   /* Add SSE5 multi-arg argument instructions */
22648   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
22649     {
22650       tree mtype = NULL_TREE;
22651
22652       if (d->name == 0)
22653         continue;
22654
22655       switch ((enum multi_arg_type)d->flag)
22656         {
22657         case MULTI_ARG_3_SF:     mtype = v4sf_ftype_v4sf_v4sf_v4sf;     break;
22658         case MULTI_ARG_3_DF:     mtype = v2df_ftype_v2df_v2df_v2df;     break;
22659         case MULTI_ARG_3_DI:     mtype = v2di_ftype_v2di_v2di_v2di;     break;
22660         case MULTI_ARG_3_SI:     mtype = v4si_ftype_v4si_v4si_v4si;     break;
22661         case MULTI_ARG_3_SI_DI:  mtype = v4si_ftype_v4si_v4si_v2di;     break;
22662         case MULTI_ARG_3_HI:     mtype = v8hi_ftype_v8hi_v8hi_v8hi;     break;
22663         case MULTI_ARG_3_HI_SI:  mtype = v8hi_ftype_v8hi_v8hi_v4si;     break;
22664         case MULTI_ARG_3_QI:     mtype = v16qi_ftype_v16qi_v16qi_v16qi; break;
22665         case MULTI_ARG_3_PERMPS: mtype = v4sf_ftype_v4sf_v4sf_v16qi;    break;
22666         case MULTI_ARG_3_PERMPD: mtype = v2df_ftype_v2df_v2df_v16qi;    break;
22667         case MULTI_ARG_2_SF:     mtype = v4sf_ftype_v4sf_v4sf;          break;
22668         case MULTI_ARG_2_DF:     mtype = v2df_ftype_v2df_v2df;          break;
22669         case MULTI_ARG_2_DI:     mtype = v2di_ftype_v2di_v2di;          break;
22670         case MULTI_ARG_2_SI:     mtype = v4si_ftype_v4si_v4si;          break;
22671         case MULTI_ARG_2_HI:     mtype = v8hi_ftype_v8hi_v8hi;          break;
22672         case MULTI_ARG_2_QI:     mtype = v16qi_ftype_v16qi_v16qi;       break;
22673         case MULTI_ARG_2_DI_IMM: mtype = v2di_ftype_v2di_si;            break;
22674         case MULTI_ARG_2_SI_IMM: mtype = v4si_ftype_v4si_si;            break;
22675         case MULTI_ARG_2_HI_IMM: mtype = v8hi_ftype_v8hi_si;            break;
22676         case MULTI_ARG_2_QI_IMM: mtype = v16qi_ftype_v16qi_si;          break;
22677         case MULTI_ARG_2_SF_CMP: mtype = v4sf_ftype_v4sf_v4sf;          break;
22678         case MULTI_ARG_2_DF_CMP: mtype = v2df_ftype_v2df_v2df;          break;
22679         case MULTI_ARG_2_DI_CMP: mtype = v2di_ftype_v2di_v2di;          break;
22680         case MULTI_ARG_2_SI_CMP: mtype = v4si_ftype_v4si_v4si;          break;
22681         case MULTI_ARG_2_HI_CMP: mtype = v8hi_ftype_v8hi_v8hi;          break;
22682         case MULTI_ARG_2_QI_CMP: mtype = v16qi_ftype_v16qi_v16qi;       break;
22683         case MULTI_ARG_2_SF_TF:  mtype = v4sf_ftype_v4sf_v4sf;          break;
22684         case MULTI_ARG_2_DF_TF:  mtype = v2df_ftype_v2df_v2df;          break;
22685         case MULTI_ARG_2_DI_TF:  mtype = v2di_ftype_v2di_v2di;          break;
22686         case MULTI_ARG_2_SI_TF:  mtype = v4si_ftype_v4si_v4si;          break;
22687         case MULTI_ARG_2_HI_TF:  mtype = v8hi_ftype_v8hi_v8hi;          break;
22688         case MULTI_ARG_2_QI_TF:  mtype = v16qi_ftype_v16qi_v16qi;       break;
22689         case MULTI_ARG_1_SF:     mtype = v4sf_ftype_v4sf;               break;
22690         case MULTI_ARG_1_DF:     mtype = v2df_ftype_v2df;               break;
22691         case MULTI_ARG_1_DI:     mtype = v2di_ftype_v2di;               break;
22692         case MULTI_ARG_1_SI:     mtype = v4si_ftype_v4si;               break;
22693         case MULTI_ARG_1_HI:     mtype = v8hi_ftype_v8hi;               break;
22694         case MULTI_ARG_1_QI:     mtype = v16qi_ftype_v16qi;             break;
22695         case MULTI_ARG_1_SI_DI:  mtype = v2di_ftype_v4si;               break;
22696         case MULTI_ARG_1_HI_DI:  mtype = v2di_ftype_v8hi;               break;
22697         case MULTI_ARG_1_HI_SI:  mtype = v4si_ftype_v8hi;               break;
22698         case MULTI_ARG_1_QI_DI:  mtype = v2di_ftype_v16qi;              break;
22699         case MULTI_ARG_1_QI_SI:  mtype = v4si_ftype_v16qi;              break;
22700         case MULTI_ARG_1_QI_HI:  mtype = v8hi_ftype_v16qi;              break;
22701         case MULTI_ARG_1_PH2PS:  mtype = v4sf_ftype_v4hi;               break;
22702         case MULTI_ARG_1_PS2PH:  mtype = v4hi_ftype_v4sf;               break;
22703         case MULTI_ARG_UNKNOWN:
22704         default:
22705           gcc_unreachable ();
22706         }
22707
22708       if (mtype)
22709         def_builtin_const (d->mask, d->name, mtype, d->code);
22710     }
22711 }
22712
22713 /* Internal method for ix86_init_builtins.  */
22714
22715 static void
22716 ix86_init_builtins_va_builtins_abi (void)
22717 {
22718   tree ms_va_ref, sysv_va_ref;
22719   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
22720   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
22721   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
22722   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
22723
22724   if (!TARGET_64BIT)
22725     return;
22726   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
22727   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
22728   ms_va_ref = build_reference_type (ms_va_list_type_node);
22729   sysv_va_ref =
22730     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
22731
22732   fnvoid_va_end_ms =
22733     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
22734   fnvoid_va_start_ms =
22735     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
22736   fnvoid_va_end_sysv =
22737     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
22738   fnvoid_va_start_sysv =
22739     build_varargs_function_type_list (void_type_node, sysv_va_ref,
22740                                        NULL_TREE);
22741   fnvoid_va_copy_ms =
22742     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
22743                               NULL_TREE);
22744   fnvoid_va_copy_sysv =
22745     build_function_type_list (void_type_node, sysv_va_ref,
22746                               sysv_va_ref, NULL_TREE);
22747
22748   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
22749                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
22750   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
22751                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
22752   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
22753                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
22754   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
22755                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
22756   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
22757                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
22758   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
22759                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
22760 }
22761
22762 static void
22763 ix86_init_builtins (void)
22764 {
22765   tree float128_type_node = make_node (REAL_TYPE);
22766   tree ftype, decl;
22767
22768   /* The __float80 type.  */
22769   if (TYPE_MODE (long_double_type_node) == XFmode)
22770     (*lang_hooks.types.register_builtin_type) (long_double_type_node,
22771                                                "__float80");
22772   else
22773     {
22774       /* The __float80 type.  */
22775       tree float80_type_node = make_node (REAL_TYPE);
22776
22777       TYPE_PRECISION (float80_type_node) = 80;
22778       layout_type (float80_type_node);
22779       (*lang_hooks.types.register_builtin_type) (float80_type_node,
22780                                                  "__float80");
22781     }
22782
22783   /* The __float128 type.  */
22784   TYPE_PRECISION (float128_type_node) = 128;
22785   layout_type (float128_type_node);
22786   (*lang_hooks.types.register_builtin_type) (float128_type_node,
22787                                              "__float128");
22788
22789   /* TFmode support builtins.  */
22790   ftype = build_function_type (float128_type_node, void_list_node);
22791   decl = add_builtin_function ("__builtin_infq", ftype,
22792                                IX86_BUILTIN_INFQ, BUILT_IN_MD,
22793                                NULL, NULL_TREE);
22794   ix86_builtins[(int) IX86_BUILTIN_INFQ] = decl;
22795
22796   /* We will expand them to normal call if SSE2 isn't available since
22797      they are used by libgcc. */
22798   ftype = build_function_type_list (float128_type_node,
22799                                     float128_type_node,
22800                                     NULL_TREE);
22801   decl = add_builtin_function ("__builtin_fabsq", ftype,
22802                                IX86_BUILTIN_FABSQ, BUILT_IN_MD,
22803                                "__fabstf2", NULL_TREE);
22804   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = decl;
22805   TREE_READONLY (decl) = 1;
22806
22807   ftype = build_function_type_list (float128_type_node,
22808                                     float128_type_node,
22809                                     float128_type_node,
22810                                     NULL_TREE);
22811   decl = add_builtin_function ("__builtin_copysignq", ftype,
22812                                IX86_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
22813                                "__copysigntf3", NULL_TREE);
22814   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = decl;
22815   TREE_READONLY (decl) = 1;
22816
22817   ix86_init_mmx_sse_builtins ();
22818   if (TARGET_64BIT)
22819     ix86_init_builtins_va_builtins_abi ();
22820 }
22821
22822 /* Errors in the source file can cause expand_expr to return const0_rtx
22823    where we expect a vector.  To avoid crashing, use one of the vector
22824    clear instructions.  */
22825 static rtx
22826 safe_vector_operand (rtx x, enum machine_mode mode)
22827 {
22828   if (x == const0_rtx)
22829     x = CONST0_RTX (mode);
22830   return x;
22831 }
22832
22833 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
22834
22835 static rtx
22836 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
22837 {
22838   rtx pat;
22839   tree arg0 = CALL_EXPR_ARG (exp, 0);
22840   tree arg1 = CALL_EXPR_ARG (exp, 1);
22841   rtx op0 = expand_normal (arg0);
22842   rtx op1 = expand_normal (arg1);
22843   enum machine_mode tmode = insn_data[icode].operand[0].mode;
22844   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
22845   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
22846
22847   if (VECTOR_MODE_P (mode0))
22848     op0 = safe_vector_operand (op0, mode0);
22849   if (VECTOR_MODE_P (mode1))
22850     op1 = safe_vector_operand (op1, mode1);
22851
22852   if (optimize || !target
22853       || GET_MODE (target) != tmode
22854       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
22855     target = gen_reg_rtx (tmode);
22856
22857   if (GET_MODE (op1) == SImode && mode1 == TImode)
22858     {
22859       rtx x = gen_reg_rtx (V4SImode);
22860       emit_insn (gen_sse2_loadd (x, op1));
22861       op1 = gen_lowpart (TImode, x);
22862     }
22863
22864   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
22865     op0 = copy_to_mode_reg (mode0, op0);
22866   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
22867     op1 = copy_to_mode_reg (mode1, op1);
22868
22869   pat = GEN_FCN (icode) (target, op0, op1);
22870   if (! pat)
22871     return 0;
22872
22873   emit_insn (pat);
22874
22875   return target;
22876 }
22877
22878 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
22879
22880 static rtx
22881 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
22882                                enum multi_arg_type m_type,
22883                                enum insn_code sub_code)
22884 {
22885   rtx pat;
22886   int i;
22887   int nargs;
22888   bool comparison_p = false;
22889   bool tf_p = false;
22890   bool last_arg_constant = false;
22891   int num_memory = 0;
22892   struct {
22893     rtx op;
22894     enum machine_mode mode;
22895   } args[4];
22896
22897   enum machine_mode tmode = insn_data[icode].operand[0].mode;
22898
22899   switch (m_type)
22900     {
22901     case MULTI_ARG_3_SF:
22902     case MULTI_ARG_3_DF:
22903     case MULTI_ARG_3_DI:
22904     case MULTI_ARG_3_SI:
22905     case MULTI_ARG_3_SI_DI:
22906     case MULTI_ARG_3_HI:
22907     case MULTI_ARG_3_HI_SI:
22908     case MULTI_ARG_3_QI:
22909     case MULTI_ARG_3_PERMPS:
22910     case MULTI_ARG_3_PERMPD:
22911       nargs = 3;
22912       break;
22913
22914     case MULTI_ARG_2_SF:
22915     case MULTI_ARG_2_DF:
22916     case MULTI_ARG_2_DI:
22917     case MULTI_ARG_2_SI:
22918     case MULTI_ARG_2_HI:
22919     case MULTI_ARG_2_QI:
22920       nargs = 2;
22921       break;
22922
22923     case MULTI_ARG_2_DI_IMM:
22924     case MULTI_ARG_2_SI_IMM:
22925     case MULTI_ARG_2_HI_IMM:
22926     case MULTI_ARG_2_QI_IMM:
22927       nargs = 2;
22928       last_arg_constant = true;
22929       break;
22930
22931     case MULTI_ARG_1_SF:
22932     case MULTI_ARG_1_DF:
22933     case MULTI_ARG_1_DI:
22934     case MULTI_ARG_1_SI:
22935     case MULTI_ARG_1_HI:
22936     case MULTI_ARG_1_QI:
22937     case MULTI_ARG_1_SI_DI:
22938     case MULTI_ARG_1_HI_DI:
22939     case MULTI_ARG_1_HI_SI:
22940     case MULTI_ARG_1_QI_DI:
22941     case MULTI_ARG_1_QI_SI:
22942     case MULTI_ARG_1_QI_HI:
22943     case MULTI_ARG_1_PH2PS:
22944     case MULTI_ARG_1_PS2PH:
22945       nargs = 1;
22946       break;
22947
22948     case MULTI_ARG_2_SF_CMP:
22949     case MULTI_ARG_2_DF_CMP:
22950     case MULTI_ARG_2_DI_CMP:
22951     case MULTI_ARG_2_SI_CMP:
22952     case MULTI_ARG_2_HI_CMP:
22953     case MULTI_ARG_2_QI_CMP:
22954       nargs = 2;
22955       comparison_p = true;
22956       break;
22957
22958     case MULTI_ARG_2_SF_TF:
22959     case MULTI_ARG_2_DF_TF:
22960     case MULTI_ARG_2_DI_TF:
22961     case MULTI_ARG_2_SI_TF:
22962     case MULTI_ARG_2_HI_TF:
22963     case MULTI_ARG_2_QI_TF:
22964       nargs = 2;
22965       tf_p = true;
22966       break;
22967
22968     case MULTI_ARG_UNKNOWN:
22969     default:
22970       gcc_unreachable ();
22971     }
22972
22973   if (optimize || !target
22974       || GET_MODE (target) != tmode
22975       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
22976     target = gen_reg_rtx (tmode);
22977
22978   gcc_assert (nargs <= 4);
22979
22980   for (i = 0; i < nargs; i++)
22981     {
22982       tree arg = CALL_EXPR_ARG (exp, i);
22983       rtx op = expand_normal (arg);
22984       int adjust = (comparison_p) ? 1 : 0;
22985       enum machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
22986
22987       if (last_arg_constant && i == nargs-1)
22988         {
22989           if (GET_CODE (op) != CONST_INT)
22990             {
22991               error ("last argument must be an immediate");
22992               return gen_reg_rtx (tmode);
22993             }
22994         }
22995       else
22996         {
22997           if (VECTOR_MODE_P (mode))
22998             op = safe_vector_operand (op, mode);
22999
23000           /* If we aren't optimizing, only allow one memory operand to be
23001              generated.  */
23002           if (memory_operand (op, mode))
23003             num_memory++;
23004
23005           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
23006
23007           if (optimize
23008               || ! (*insn_data[icode].operand[i+adjust+1].predicate) (op, mode)
23009               || num_memory > 1)
23010             op = force_reg (mode, op);
23011         }
23012
23013       args[i].op = op;
23014       args[i].mode = mode;
23015     }
23016
23017   switch (nargs)
23018     {
23019     case 1:
23020       pat = GEN_FCN (icode) (target, args[0].op);
23021       break;
23022
23023     case 2:
23024       if (tf_p)
23025         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
23026                                GEN_INT ((int)sub_code));
23027       else if (! comparison_p)
23028         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
23029       else
23030         {
23031           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
23032                                        args[0].op,
23033                                        args[1].op);
23034
23035           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
23036         }
23037       break;
23038
23039     case 3:
23040       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
23041       break;
23042
23043     default:
23044       gcc_unreachable ();
23045     }
23046
23047   if (! pat)
23048     return 0;
23049
23050   emit_insn (pat);
23051   return target;
23052 }
23053
23054 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
23055    insns with vec_merge.  */
23056
23057 static rtx
23058 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
23059                                     rtx target)
23060 {
23061   rtx pat;
23062   tree arg0 = CALL_EXPR_ARG (exp, 0);
23063   rtx op1, op0 = expand_normal (arg0);
23064   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23065   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
23066
23067   if (optimize || !target
23068       || GET_MODE (target) != tmode
23069       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23070     target = gen_reg_rtx (tmode);
23071
23072   if (VECTOR_MODE_P (mode0))
23073     op0 = safe_vector_operand (op0, mode0);
23074
23075   if ((optimize && !register_operand (op0, mode0))
23076       || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
23077     op0 = copy_to_mode_reg (mode0, op0);
23078
23079   op1 = op0;
23080   if (! (*insn_data[icode].operand[2].predicate) (op1, mode0))
23081     op1 = copy_to_mode_reg (mode0, op1);
23082
23083   pat = GEN_FCN (icode) (target, op0, op1);
23084   if (! pat)
23085     return 0;
23086   emit_insn (pat);
23087   return target;
23088 }
23089
23090 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
23091
23092 static rtx
23093 ix86_expand_sse_compare (const struct builtin_description *d,
23094                          tree exp, rtx target, bool swap)
23095 {
23096   rtx pat;
23097   tree arg0 = CALL_EXPR_ARG (exp, 0);
23098   tree arg1 = CALL_EXPR_ARG (exp, 1);
23099   rtx op0 = expand_normal (arg0);
23100   rtx op1 = expand_normal (arg1);
23101   rtx op2;
23102   enum machine_mode tmode = insn_data[d->icode].operand[0].mode;
23103   enum machine_mode mode0 = insn_data[d->icode].operand[1].mode;
23104   enum machine_mode mode1 = insn_data[d->icode].operand[2].mode;
23105   enum rtx_code comparison = d->comparison;
23106
23107   if (VECTOR_MODE_P (mode0))
23108     op0 = safe_vector_operand (op0, mode0);
23109   if (VECTOR_MODE_P (mode1))
23110     op1 = safe_vector_operand (op1, mode1);
23111
23112   /* Swap operands if we have a comparison that isn't available in
23113      hardware.  */
23114   if (swap)
23115     {
23116       rtx tmp = gen_reg_rtx (mode1);
23117       emit_move_insn (tmp, op1);
23118       op1 = op0;
23119       op0 = tmp;
23120     }
23121
23122   if (optimize || !target
23123       || GET_MODE (target) != tmode
23124       || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode))
23125     target = gen_reg_rtx (tmode);
23126
23127   if ((optimize && !register_operand (op0, mode0))
23128       || ! (*insn_data[d->icode].operand[1].predicate) (op0, mode0))
23129     op0 = copy_to_mode_reg (mode0, op0);
23130   if ((optimize && !register_operand (op1, mode1))
23131       || ! (*insn_data[d->icode].operand[2].predicate) (op1, mode1))
23132     op1 = copy_to_mode_reg (mode1, op1);
23133
23134   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
23135   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
23136   if (! pat)
23137     return 0;
23138   emit_insn (pat);
23139   return target;
23140 }
23141
23142 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
23143
23144 static rtx
23145 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
23146                       rtx target)
23147 {
23148   rtx pat;
23149   tree arg0 = CALL_EXPR_ARG (exp, 0);
23150   tree arg1 = CALL_EXPR_ARG (exp, 1);
23151   rtx op0 = expand_normal (arg0);
23152   rtx op1 = expand_normal (arg1);
23153   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23154   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23155   enum rtx_code comparison = d->comparison;
23156
23157   if (VECTOR_MODE_P (mode0))
23158     op0 = safe_vector_operand (op0, mode0);
23159   if (VECTOR_MODE_P (mode1))
23160     op1 = safe_vector_operand (op1, mode1);
23161
23162   /* Swap operands if we have a comparison that isn't available in
23163      hardware.  */
23164   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
23165     {
23166       rtx tmp = op1;
23167       op1 = op0;
23168       op0 = tmp;
23169     }
23170
23171   target = gen_reg_rtx (SImode);
23172   emit_move_insn (target, const0_rtx);
23173   target = gen_rtx_SUBREG (QImode, target, 0);
23174
23175   if ((optimize && !register_operand (op0, mode0))
23176       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23177     op0 = copy_to_mode_reg (mode0, op0);
23178   if ((optimize && !register_operand (op1, mode1))
23179       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23180     op1 = copy_to_mode_reg (mode1, op1);
23181
23182   pat = GEN_FCN (d->icode) (op0, op1);
23183   if (! pat)
23184     return 0;
23185   emit_insn (pat);
23186   emit_insn (gen_rtx_SET (VOIDmode,
23187                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23188                           gen_rtx_fmt_ee (comparison, QImode,
23189                                           SET_DEST (pat),
23190                                           const0_rtx)));
23191
23192   return SUBREG_REG (target);
23193 }
23194
23195 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
23196
23197 static rtx
23198 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
23199                        rtx target)
23200 {
23201   rtx pat;
23202   tree arg0 = CALL_EXPR_ARG (exp, 0);
23203   tree arg1 = CALL_EXPR_ARG (exp, 1);
23204   rtx op0 = expand_normal (arg0);
23205   rtx op1 = expand_normal (arg1);
23206   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23207   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23208   enum rtx_code comparison = d->comparison;
23209
23210   if (VECTOR_MODE_P (mode0))
23211     op0 = safe_vector_operand (op0, mode0);
23212   if (VECTOR_MODE_P (mode1))
23213     op1 = safe_vector_operand (op1, mode1);
23214
23215   target = gen_reg_rtx (SImode);
23216   emit_move_insn (target, const0_rtx);
23217   target = gen_rtx_SUBREG (QImode, target, 0);
23218
23219   if ((optimize && !register_operand (op0, mode0))
23220       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23221     op0 = copy_to_mode_reg (mode0, op0);
23222   if ((optimize && !register_operand (op1, mode1))
23223       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23224     op1 = copy_to_mode_reg (mode1, op1);
23225
23226   pat = GEN_FCN (d->icode) (op0, op1);
23227   if (! pat)
23228     return 0;
23229   emit_insn (pat);
23230   emit_insn (gen_rtx_SET (VOIDmode,
23231                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23232                           gen_rtx_fmt_ee (comparison, QImode,
23233                                           SET_DEST (pat),
23234                                           const0_rtx)));
23235
23236   return SUBREG_REG (target);
23237 }
23238
23239 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
23240
23241 static rtx
23242 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
23243                           tree exp, rtx target)
23244 {
23245   rtx pat;
23246   tree arg0 = CALL_EXPR_ARG (exp, 0);
23247   tree arg1 = CALL_EXPR_ARG (exp, 1);
23248   tree arg2 = CALL_EXPR_ARG (exp, 2);
23249   tree arg3 = CALL_EXPR_ARG (exp, 3);
23250   tree arg4 = CALL_EXPR_ARG (exp, 4);
23251   rtx scratch0, scratch1;
23252   rtx op0 = expand_normal (arg0);
23253   rtx op1 = expand_normal (arg1);
23254   rtx op2 = expand_normal (arg2);
23255   rtx op3 = expand_normal (arg3);
23256   rtx op4 = expand_normal (arg4);
23257   enum machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
23258
23259   tmode0 = insn_data[d->icode].operand[0].mode;
23260   tmode1 = insn_data[d->icode].operand[1].mode;
23261   modev2 = insn_data[d->icode].operand[2].mode;
23262   modei3 = insn_data[d->icode].operand[3].mode;
23263   modev4 = insn_data[d->icode].operand[4].mode;
23264   modei5 = insn_data[d->icode].operand[5].mode;
23265   modeimm = insn_data[d->icode].operand[6].mode;
23266
23267   if (VECTOR_MODE_P (modev2))
23268     op0 = safe_vector_operand (op0, modev2);
23269   if (VECTOR_MODE_P (modev4))
23270     op2 = safe_vector_operand (op2, modev4);
23271
23272   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
23273     op0 = copy_to_mode_reg (modev2, op0);
23274   if (! (*insn_data[d->icode].operand[3].predicate) (op1, modei3))
23275     op1 = copy_to_mode_reg (modei3, op1);
23276   if ((optimize && !register_operand (op2, modev4))
23277       || !(*insn_data[d->icode].operand[4].predicate) (op2, modev4))
23278     op2 = copy_to_mode_reg (modev4, op2);
23279   if (! (*insn_data[d->icode].operand[5].predicate) (op3, modei5))
23280     op3 = copy_to_mode_reg (modei5, op3);
23281
23282   if (! (*insn_data[d->icode].operand[6].predicate) (op4, modeimm))
23283     {
23284       error ("the fifth argument must be a 8-bit immediate");
23285       return const0_rtx;
23286     }
23287
23288   if (d->code == IX86_BUILTIN_PCMPESTRI128)
23289     {
23290       if (optimize || !target
23291           || GET_MODE (target) != tmode0
23292           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
23293         target = gen_reg_rtx (tmode0);
23294
23295       scratch1 = gen_reg_rtx (tmode1);
23296
23297       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
23298     }
23299   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
23300     {
23301       if (optimize || !target
23302           || GET_MODE (target) != tmode1
23303           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
23304         target = gen_reg_rtx (tmode1);
23305
23306       scratch0 = gen_reg_rtx (tmode0);
23307
23308       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
23309     }
23310   else
23311     {
23312       gcc_assert (d->flag);
23313
23314       scratch0 = gen_reg_rtx (tmode0);
23315       scratch1 = gen_reg_rtx (tmode1);
23316
23317       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
23318     }
23319
23320   if (! pat)
23321     return 0;
23322
23323   emit_insn (pat);
23324
23325   if (d->flag)
23326     {
23327       target = gen_reg_rtx (SImode);
23328       emit_move_insn (target, const0_rtx);
23329       target = gen_rtx_SUBREG (QImode, target, 0);
23330
23331       emit_insn
23332         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23333                       gen_rtx_fmt_ee (EQ, QImode,
23334                                       gen_rtx_REG ((enum machine_mode) d->flag,
23335                                                    FLAGS_REG),
23336                                       const0_rtx)));
23337       return SUBREG_REG (target);
23338     }
23339   else
23340     return target;
23341 }
23342
23343
23344 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
23345
23346 static rtx
23347 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
23348                           tree exp, rtx target)
23349 {
23350   rtx pat;
23351   tree arg0 = CALL_EXPR_ARG (exp, 0);
23352   tree arg1 = CALL_EXPR_ARG (exp, 1);
23353   tree arg2 = CALL_EXPR_ARG (exp, 2);
23354   rtx scratch0, scratch1;
23355   rtx op0 = expand_normal (arg0);
23356   rtx op1 = expand_normal (arg1);
23357   rtx op2 = expand_normal (arg2);
23358   enum machine_mode tmode0, tmode1, modev2, modev3, modeimm;
23359
23360   tmode0 = insn_data[d->icode].operand[0].mode;
23361   tmode1 = insn_data[d->icode].operand[1].mode;
23362   modev2 = insn_data[d->icode].operand[2].mode;
23363   modev3 = insn_data[d->icode].operand[3].mode;
23364   modeimm = insn_data[d->icode].operand[4].mode;
23365
23366   if (VECTOR_MODE_P (modev2))
23367     op0 = safe_vector_operand (op0, modev2);
23368   if (VECTOR_MODE_P (modev3))
23369     op1 = safe_vector_operand (op1, modev3);
23370
23371   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
23372     op0 = copy_to_mode_reg (modev2, op0);
23373   if ((optimize && !register_operand (op1, modev3))
23374       || !(*insn_data[d->icode].operand[3].predicate) (op1, modev3))
23375     op1 = copy_to_mode_reg (modev3, op1);
23376
23377   if (! (*insn_data[d->icode].operand[4].predicate) (op2, modeimm))
23378     {
23379       error ("the third argument must be a 8-bit immediate");
23380       return const0_rtx;
23381     }
23382
23383   if (d->code == IX86_BUILTIN_PCMPISTRI128)
23384     {
23385       if (optimize || !target
23386           || GET_MODE (target) != tmode0
23387           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
23388         target = gen_reg_rtx (tmode0);
23389
23390       scratch1 = gen_reg_rtx (tmode1);
23391
23392       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
23393     }
23394   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
23395     {
23396       if (optimize || !target
23397           || GET_MODE (target) != tmode1
23398           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
23399         target = gen_reg_rtx (tmode1);
23400
23401       scratch0 = gen_reg_rtx (tmode0);
23402
23403       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
23404     }
23405   else
23406     {
23407       gcc_assert (d->flag);
23408
23409       scratch0 = gen_reg_rtx (tmode0);
23410       scratch1 = gen_reg_rtx (tmode1);
23411
23412       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
23413     }
23414
23415   if (! pat)
23416     return 0;
23417
23418   emit_insn (pat);
23419
23420   if (d->flag)
23421     {
23422       target = gen_reg_rtx (SImode);
23423       emit_move_insn (target, const0_rtx);
23424       target = gen_rtx_SUBREG (QImode, target, 0);
23425
23426       emit_insn
23427         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23428                       gen_rtx_fmt_ee (EQ, QImode,
23429                                       gen_rtx_REG ((enum machine_mode) d->flag,
23430                                                    FLAGS_REG),
23431                                       const0_rtx)));
23432       return SUBREG_REG (target);
23433     }
23434   else
23435     return target;
23436 }
23437
23438 /* Subroutine of ix86_expand_builtin to take care of insns with
23439    variable number of operands.  */
23440
23441 static rtx
23442 ix86_expand_args_builtin (const struct builtin_description *d,
23443                           tree exp, rtx target)
23444 {
23445   rtx pat, real_target;
23446   unsigned int i, nargs;
23447   unsigned int nargs_constant = 0;
23448   int num_memory = 0;
23449   struct
23450     {
23451       rtx op;
23452       enum machine_mode mode;
23453     } args[4];
23454   bool last_arg_count = false;
23455   enum insn_code icode = d->icode;
23456   const struct insn_data *insn_p = &insn_data[icode];
23457   enum machine_mode tmode = insn_p->operand[0].mode;
23458   enum machine_mode rmode = VOIDmode;
23459   bool swap = false;
23460   enum rtx_code comparison = d->comparison;
23461
23462   switch ((enum ix86_builtin_type) d->flag)
23463     {
23464     case INT_FTYPE_V8SF_V8SF_PTEST:
23465     case INT_FTYPE_V4DI_V4DI_PTEST:
23466     case INT_FTYPE_V4DF_V4DF_PTEST:
23467     case INT_FTYPE_V4SF_V4SF_PTEST:
23468     case INT_FTYPE_V2DI_V2DI_PTEST:
23469     case INT_FTYPE_V2DF_V2DF_PTEST:
23470       return ix86_expand_sse_ptest (d, exp, target);
23471     case FLOAT128_FTYPE_FLOAT128:
23472     case FLOAT_FTYPE_FLOAT:
23473     case INT64_FTYPE_V4SF:
23474     case INT64_FTYPE_V2DF:
23475     case INT_FTYPE_V16QI:
23476     case INT_FTYPE_V8QI:
23477     case INT_FTYPE_V8SF:
23478     case INT_FTYPE_V4DF:
23479     case INT_FTYPE_V4SF:
23480     case INT_FTYPE_V2DF:
23481     case V16QI_FTYPE_V16QI:
23482     case V8SI_FTYPE_V8SF:
23483     case V8SI_FTYPE_V4SI:
23484     case V8HI_FTYPE_V8HI:
23485     case V8HI_FTYPE_V16QI:
23486     case V8QI_FTYPE_V8QI:
23487     case V8SF_FTYPE_V8SF:
23488     case V8SF_FTYPE_V8SI:
23489     case V8SF_FTYPE_V4SF:
23490     case V4SI_FTYPE_V4SI:
23491     case V4SI_FTYPE_V16QI:
23492     case V4SI_FTYPE_V4SF:
23493     case V4SI_FTYPE_V8SI:
23494     case V4SI_FTYPE_V8HI:
23495     case V4SI_FTYPE_V4DF:
23496     case V4SI_FTYPE_V2DF:
23497     case V4HI_FTYPE_V4HI:
23498     case V4DF_FTYPE_V4DF:
23499     case V4DF_FTYPE_V4SI:
23500     case V4DF_FTYPE_V4SF:
23501     case V4DF_FTYPE_V2DF:
23502     case V4SF_FTYPE_V4SF:
23503     case V4SF_FTYPE_V4SI:
23504     case V4SF_FTYPE_V8SF:
23505     case V4SF_FTYPE_V4DF:
23506     case V4SF_FTYPE_V2DF:
23507     case V2DI_FTYPE_V2DI:
23508     case V2DI_FTYPE_V16QI:
23509     case V2DI_FTYPE_V8HI:
23510     case V2DI_FTYPE_V4SI:
23511     case V2DF_FTYPE_V2DF:
23512     case V2DF_FTYPE_V4SI:
23513     case V2DF_FTYPE_V4DF:
23514     case V2DF_FTYPE_V4SF:
23515     case V2DF_FTYPE_V2SI:
23516     case V2SI_FTYPE_V2SI:
23517     case V2SI_FTYPE_V4SF:
23518     case V2SI_FTYPE_V2SF:
23519     case V2SI_FTYPE_V2DF:
23520     case V2SF_FTYPE_V2SF:
23521     case V2SF_FTYPE_V2SI:
23522       nargs = 1;
23523       break;
23524     case V4SF_FTYPE_V4SF_VEC_MERGE:
23525     case V2DF_FTYPE_V2DF_VEC_MERGE:
23526       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
23527     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
23528     case V16QI_FTYPE_V16QI_V16QI:
23529     case V16QI_FTYPE_V8HI_V8HI:
23530     case V8QI_FTYPE_V8QI_V8QI:
23531     case V8QI_FTYPE_V4HI_V4HI:
23532     case V8HI_FTYPE_V8HI_V8HI:
23533     case V8HI_FTYPE_V16QI_V16QI:
23534     case V8HI_FTYPE_V4SI_V4SI:
23535     case V8SF_FTYPE_V8SF_V8SF:
23536     case V8SF_FTYPE_V8SF_V8SI:
23537     case V4SI_FTYPE_V4SI_V4SI:
23538     case V4SI_FTYPE_V8HI_V8HI:
23539     case V4SI_FTYPE_V4SF_V4SF:
23540     case V4SI_FTYPE_V2DF_V2DF:
23541     case V4HI_FTYPE_V4HI_V4HI:
23542     case V4HI_FTYPE_V8QI_V8QI:
23543     case V4HI_FTYPE_V2SI_V2SI:
23544     case V4DF_FTYPE_V4DF_V4DF:
23545     case V4DF_FTYPE_V4DF_V4DI:
23546     case V4SF_FTYPE_V4SF_V4SF:
23547     case V4SF_FTYPE_V4SF_V4SI:
23548     case V4SF_FTYPE_V4SF_V2SI:
23549     case V4SF_FTYPE_V4SF_V2DF:
23550     case V4SF_FTYPE_V4SF_DI:
23551     case V4SF_FTYPE_V4SF_SI:
23552     case V2DI_FTYPE_V2DI_V2DI:
23553     case V2DI_FTYPE_V16QI_V16QI:
23554     case V2DI_FTYPE_V4SI_V4SI:
23555     case V2DI_FTYPE_V2DI_V16QI:
23556     case V2DI_FTYPE_V2DF_V2DF:
23557     case V2SI_FTYPE_V2SI_V2SI:
23558     case V2SI_FTYPE_V4HI_V4HI:
23559     case V2SI_FTYPE_V2SF_V2SF:
23560     case V2DF_FTYPE_V2DF_V2DF:
23561     case V2DF_FTYPE_V2DF_V4SF:
23562     case V2DF_FTYPE_V2DF_V2DI:
23563     case V2DF_FTYPE_V2DF_DI:
23564     case V2DF_FTYPE_V2DF_SI:
23565     case V2SF_FTYPE_V2SF_V2SF:
23566     case V1DI_FTYPE_V1DI_V1DI:
23567     case V1DI_FTYPE_V8QI_V8QI:
23568     case V1DI_FTYPE_V2SI_V2SI:
23569       if (comparison == UNKNOWN)
23570         return ix86_expand_binop_builtin (icode, exp, target);
23571       nargs = 2;
23572       break;
23573     case V4SF_FTYPE_V4SF_V4SF_SWAP:
23574     case V2DF_FTYPE_V2DF_V2DF_SWAP:
23575       gcc_assert (comparison != UNKNOWN);
23576       nargs = 2;
23577       swap = true;
23578       break;
23579     case V8HI_FTYPE_V8HI_V8HI_COUNT:
23580     case V8HI_FTYPE_V8HI_SI_COUNT:
23581     case V4SI_FTYPE_V4SI_V4SI_COUNT:
23582     case V4SI_FTYPE_V4SI_SI_COUNT:
23583     case V4HI_FTYPE_V4HI_V4HI_COUNT:
23584     case V4HI_FTYPE_V4HI_SI_COUNT:
23585     case V2DI_FTYPE_V2DI_V2DI_COUNT:
23586     case V2DI_FTYPE_V2DI_SI_COUNT:
23587     case V2SI_FTYPE_V2SI_V2SI_COUNT:
23588     case V2SI_FTYPE_V2SI_SI_COUNT:
23589     case V1DI_FTYPE_V1DI_V1DI_COUNT:
23590     case V1DI_FTYPE_V1DI_SI_COUNT:
23591       nargs = 2;
23592       last_arg_count = true;
23593       break;
23594     case UINT64_FTYPE_UINT64_UINT64:
23595     case UINT_FTYPE_UINT_UINT:
23596     case UINT_FTYPE_UINT_USHORT:
23597     case UINT_FTYPE_UINT_UCHAR:
23598       nargs = 2;
23599       break;
23600     case V2DI2TI_FTYPE_V2DI_INT:
23601       nargs = 2;
23602       rmode = V2DImode;
23603       nargs_constant = 1;
23604       break;
23605     case V8HI_FTYPE_V8HI_INT:
23606     case V8SF_FTYPE_V8SF_INT:
23607     case V4SI_FTYPE_V4SI_INT:
23608     case V4SI_FTYPE_V8SI_INT:
23609     case V4HI_FTYPE_V4HI_INT:
23610     case V4DF_FTYPE_V4DF_INT:
23611     case V4SF_FTYPE_V4SF_INT:
23612     case V4SF_FTYPE_V8SF_INT:
23613     case V2DI_FTYPE_V2DI_INT:
23614     case V2DF_FTYPE_V2DF_INT:
23615     case V2DF_FTYPE_V4DF_INT:
23616       nargs = 2;
23617       nargs_constant = 1;
23618       break;
23619     case V16QI_FTYPE_V16QI_V16QI_V16QI:
23620     case V8SF_FTYPE_V8SF_V8SF_V8SF:
23621     case V4DF_FTYPE_V4DF_V4DF_V4DF:
23622     case V4SF_FTYPE_V4SF_V4SF_V4SF:
23623     case V2DF_FTYPE_V2DF_V2DF_V2DF:
23624       nargs = 3;
23625       break;
23626     case V16QI_FTYPE_V16QI_V16QI_INT:
23627     case V8HI_FTYPE_V8HI_V8HI_INT:
23628     case V8SI_FTYPE_V8SI_V8SI_INT:
23629     case V8SI_FTYPE_V8SI_V4SI_INT:
23630     case V8SF_FTYPE_V8SF_V8SF_INT: 
23631     case V8SF_FTYPE_V8SF_V4SF_INT: 
23632     case V4SI_FTYPE_V4SI_V4SI_INT:
23633     case V4DF_FTYPE_V4DF_V4DF_INT:
23634     case V4DF_FTYPE_V4DF_V2DF_INT:
23635     case V4SF_FTYPE_V4SF_V4SF_INT:
23636     case V2DI_FTYPE_V2DI_V2DI_INT:
23637     case V2DF_FTYPE_V2DF_V2DF_INT:
23638       nargs = 3;
23639       nargs_constant = 1;
23640       break;
23641     case V2DI2TI_FTYPE_V2DI_V2DI_INT:
23642       nargs = 3;
23643       rmode = V2DImode;
23644       nargs_constant = 1;
23645       break;
23646     case V1DI2DI_FTYPE_V1DI_V1DI_INT:
23647       nargs = 3;
23648       rmode = DImode;
23649       nargs_constant = 1;
23650       break;
23651     case V2DI_FTYPE_V2DI_UINT_UINT:
23652       nargs = 3;
23653       nargs_constant = 2;
23654       break;
23655     case V8SF_FTYPE_V8SF_V8SF_V8SI_INT:
23656     case V4DF_FTYPE_V4DF_V4DF_V4DI_INT:
23657     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT:
23658     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT:
23659       nargs = 4;
23660       nargs_constant = 1;
23661       break;
23662     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
23663       nargs = 4;
23664       nargs_constant = 2;
23665       break;
23666     default:
23667       gcc_unreachable ();
23668     }
23669
23670   gcc_assert (nargs <= ARRAY_SIZE (args));
23671
23672   if (comparison != UNKNOWN)
23673     {
23674       gcc_assert (nargs == 2);
23675       return ix86_expand_sse_compare (d, exp, target, swap);
23676     }
23677
23678   if (rmode == VOIDmode || rmode == tmode)
23679     {
23680       if (optimize
23681           || target == 0
23682           || GET_MODE (target) != tmode
23683           || ! (*insn_p->operand[0].predicate) (target, tmode))
23684         target = gen_reg_rtx (tmode);
23685       real_target = target;
23686     }
23687   else
23688     {
23689       target = gen_reg_rtx (rmode);
23690       real_target = simplify_gen_subreg (tmode, target, rmode, 0);
23691     }
23692
23693   for (i = 0; i < nargs; i++)
23694     {
23695       tree arg = CALL_EXPR_ARG (exp, i);
23696       rtx op = expand_normal (arg);
23697       enum machine_mode mode = insn_p->operand[i + 1].mode;
23698       bool match = (*insn_p->operand[i + 1].predicate) (op, mode);
23699
23700       if (last_arg_count && (i + 1) == nargs)
23701         {
23702           /* SIMD shift insns take either an 8-bit immediate or
23703              register as count.  But builtin functions take int as
23704              count.  If count doesn't match, we put it in register.  */
23705           if (!match)
23706             {
23707               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
23708               if (!(*insn_p->operand[i + 1].predicate) (op, mode))
23709                 op = copy_to_reg (op);
23710             }
23711         }
23712       else if ((nargs - i) <= nargs_constant)
23713         {
23714           if (!match)
23715             switch (icode)
23716               {
23717               case CODE_FOR_sse4_1_roundpd:
23718               case CODE_FOR_sse4_1_roundps:
23719               case CODE_FOR_sse4_1_roundsd:
23720               case CODE_FOR_sse4_1_roundss:
23721               case CODE_FOR_sse4_1_blendps:
23722               case CODE_FOR_avx_blendpd256:
23723               case CODE_FOR_avx_vpermilv4df:
23724               case CODE_FOR_avx_roundpd256:
23725               case CODE_FOR_avx_roundps256:
23726                 error ("the last argument must be a 4-bit immediate");
23727                 return const0_rtx;
23728
23729               case CODE_FOR_sse4_1_blendpd:
23730               case CODE_FOR_avx_vpermilv2df:
23731               case CODE_FOR_avx_vpermil2v2df3:
23732               case CODE_FOR_avx_vpermil2v4sf3:
23733               case CODE_FOR_avx_vpermil2v4df3:
23734               case CODE_FOR_avx_vpermil2v8sf3:
23735                 error ("the last argument must be a 2-bit immediate");
23736                 return const0_rtx;
23737
23738               case CODE_FOR_avx_vextractf128v4df:
23739               case CODE_FOR_avx_vextractf128v8sf:
23740               case CODE_FOR_avx_vextractf128v8si:
23741               case CODE_FOR_avx_vinsertf128v4df:
23742               case CODE_FOR_avx_vinsertf128v8sf:
23743               case CODE_FOR_avx_vinsertf128v8si:
23744                 error ("the last argument must be a 1-bit immediate");
23745                 return const0_rtx;
23746
23747               case CODE_FOR_avx_cmpsdv2df3:
23748               case CODE_FOR_avx_cmpssv4sf3:
23749               case CODE_FOR_avx_cmppdv2df3:
23750               case CODE_FOR_avx_cmppsv4sf3:
23751               case CODE_FOR_avx_cmppdv4df3:
23752               case CODE_FOR_avx_cmppsv8sf3:
23753                 error ("the last argument must be a 5-bit immediate");
23754                 return const0_rtx;
23755
23756              default:
23757                 switch (nargs_constant)
23758                   {
23759                   case 2:
23760                     if ((nargs - i) == nargs_constant)
23761                       {
23762                         error ("the next to last argument must be an 8-bit immediate");
23763                         break;
23764                       }
23765                   case 1:
23766                     error ("the last argument must be an 8-bit immediate");
23767                     break;
23768                   default:
23769                     gcc_unreachable ();
23770                   }
23771                 return const0_rtx;
23772               }
23773         }
23774       else
23775         {
23776           if (VECTOR_MODE_P (mode))
23777             op = safe_vector_operand (op, mode);
23778
23779           /* If we aren't optimizing, only allow one memory operand to
23780              be generated.  */
23781           if (memory_operand (op, mode))
23782             num_memory++;
23783
23784           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
23785             {
23786               if (optimize || !match || num_memory > 1)
23787                 op = copy_to_mode_reg (mode, op);
23788             }
23789           else
23790             {
23791               op = copy_to_reg (op);
23792               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
23793             }
23794         }
23795
23796       args[i].op = op;
23797       args[i].mode = mode;
23798     }
23799
23800   switch (nargs)
23801     {
23802     case 1:
23803       pat = GEN_FCN (icode) (real_target, args[0].op);
23804       break;
23805     case 2:
23806       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
23807       break;
23808     case 3:
23809       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
23810                              args[2].op);
23811       break;
23812     case 4:
23813       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
23814                              args[2].op, args[3].op);
23815       break;
23816     default:
23817       gcc_unreachable ();
23818     }
23819
23820   if (! pat)
23821     return 0;
23822
23823   emit_insn (pat);
23824   return target;
23825 }
23826
23827 /* Subroutine of ix86_expand_builtin to take care of special insns
23828    with variable number of operands.  */
23829
23830 static rtx
23831 ix86_expand_special_args_builtin (const struct builtin_description *d,
23832                                     tree exp, rtx target)
23833 {
23834   tree arg;
23835   rtx pat, op;
23836   unsigned int i, nargs, arg_adjust, memory;
23837   struct
23838     {
23839       rtx op;
23840       enum machine_mode mode;
23841     } args[2];
23842   enum insn_code icode = d->icode;
23843   bool last_arg_constant = false;
23844   const struct insn_data *insn_p = &insn_data[icode];
23845   enum machine_mode tmode = insn_p->operand[0].mode;
23846   enum { load, store } klass;
23847
23848   switch ((enum ix86_special_builtin_type) d->flag)
23849     {
23850     case VOID_FTYPE_VOID:
23851       emit_insn (GEN_FCN (icode) (target));
23852       return 0;
23853     case V2DI_FTYPE_PV2DI:
23854     case V32QI_FTYPE_PCCHAR:
23855     case V16QI_FTYPE_PCCHAR:
23856     case V8SF_FTYPE_PCV4SF:
23857     case V8SF_FTYPE_PCFLOAT:
23858     case V4SF_FTYPE_PCFLOAT:
23859     case V4DF_FTYPE_PCV2DF:
23860     case V4DF_FTYPE_PCDOUBLE:
23861     case V2DF_FTYPE_PCDOUBLE:
23862       nargs = 1;
23863       klass = load;
23864       memory = 0;
23865       break;
23866     case VOID_FTYPE_PV2SF_V4SF:
23867     case VOID_FTYPE_PV2DI_V2DI:
23868     case VOID_FTYPE_PCHAR_V32QI:
23869     case VOID_FTYPE_PCHAR_V16QI:
23870     case VOID_FTYPE_PFLOAT_V8SF:
23871     case VOID_FTYPE_PFLOAT_V4SF:
23872     case VOID_FTYPE_PDOUBLE_V4DF:
23873     case VOID_FTYPE_PDOUBLE_V2DF:
23874     case VOID_FTYPE_PDI_DI:
23875     case VOID_FTYPE_PINT_INT:
23876       nargs = 1;
23877       klass = store;
23878       /* Reserve memory operand for target.  */
23879       memory = ARRAY_SIZE (args);
23880       break;
23881     case V4SF_FTYPE_V4SF_PCV2SF:
23882     case V2DF_FTYPE_V2DF_PCDOUBLE:
23883       nargs = 2;
23884       klass = load;
23885       memory = 1;
23886       break;
23887     case V8SF_FTYPE_PCV8SF_V8SF:
23888     case V4DF_FTYPE_PCV4DF_V4DF:
23889     case V4SF_FTYPE_PCV4SF_V4SF:
23890     case V2DF_FTYPE_PCV2DF_V2DF:
23891       nargs = 2;
23892       klass = load;
23893       memory = 0;
23894       break;
23895     case VOID_FTYPE_PV8SF_V8SF_V8SF:
23896     case VOID_FTYPE_PV4DF_V4DF_V4DF:
23897     case VOID_FTYPE_PV4SF_V4SF_V4SF:
23898     case VOID_FTYPE_PV2DF_V2DF_V2DF:
23899       nargs = 2;
23900       klass = store;
23901       /* Reserve memory operand for target.  */
23902       memory = ARRAY_SIZE (args);
23903       break;
23904     default:
23905       gcc_unreachable ();
23906     }
23907
23908   gcc_assert (nargs <= ARRAY_SIZE (args));
23909
23910   if (klass == store)
23911     {
23912       arg = CALL_EXPR_ARG (exp, 0);
23913       op = expand_normal (arg);
23914       gcc_assert (target == 0);
23915       target = gen_rtx_MEM (tmode, copy_to_mode_reg (Pmode, op));
23916       arg_adjust = 1;
23917     }
23918   else
23919     {
23920       arg_adjust = 0;
23921       if (optimize
23922           || target == 0
23923           || GET_MODE (target) != tmode
23924           || ! (*insn_p->operand[0].predicate) (target, tmode))
23925         target = gen_reg_rtx (tmode);
23926     }
23927
23928   for (i = 0; i < nargs; i++)
23929     {
23930       enum machine_mode mode = insn_p->operand[i + 1].mode;
23931       bool match;
23932
23933       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
23934       op = expand_normal (arg);
23935       match = (*insn_p->operand[i + 1].predicate) (op, mode);
23936
23937       if (last_arg_constant && (i + 1) == nargs)
23938         {
23939           if (!match)
23940             switch (icode)
23941               {
23942              default:
23943                 error ("the last argument must be an 8-bit immediate");
23944                 return const0_rtx;
23945               }
23946         }
23947       else
23948         {
23949           if (i == memory)
23950             {
23951               /* This must be the memory operand.  */
23952               op = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, op));
23953               gcc_assert (GET_MODE (op) == mode
23954                           || GET_MODE (op) == VOIDmode);
23955             }
23956           else
23957             {
23958               /* This must be register.  */
23959               if (VECTOR_MODE_P (mode))
23960                 op = safe_vector_operand (op, mode);
23961
23962               gcc_assert (GET_MODE (op) == mode
23963                           || GET_MODE (op) == VOIDmode);
23964               op = copy_to_mode_reg (mode, op);
23965             }
23966         }
23967
23968       args[i].op = op;
23969       args[i].mode = mode;
23970     }
23971
23972   switch (nargs)
23973     {
23974     case 1:
23975       pat = GEN_FCN (icode) (target, args[0].op);
23976       break;
23977     case 2:
23978       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
23979       break;
23980     default:
23981       gcc_unreachable ();
23982     }
23983
23984   if (! pat)
23985     return 0;
23986   emit_insn (pat);
23987   return klass == store ? 0 : target;
23988 }
23989
23990 /* Return the integer constant in ARG.  Constrain it to be in the range
23991    of the subparts of VEC_TYPE; issue an error if not.  */
23992
23993 static int
23994 get_element_number (tree vec_type, tree arg)
23995 {
23996   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
23997
23998   if (!host_integerp (arg, 1)
23999       || (elt = tree_low_cst (arg, 1), elt > max))
24000     {
24001       error ("selector must be an integer constant in the range 0..%wi", max);
24002       return 0;
24003     }
24004
24005   return elt;
24006 }
24007
24008 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24009    ix86_expand_vector_init.  We DO have language-level syntax for this, in
24010    the form of  (type){ init-list }.  Except that since we can't place emms
24011    instructions from inside the compiler, we can't allow the use of MMX
24012    registers unless the user explicitly asks for it.  So we do *not* define
24013    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
24014    we have builtins invoked by mmintrin.h that gives us license to emit
24015    these sorts of instructions.  */
24016
24017 static rtx
24018 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
24019 {
24020   enum machine_mode tmode = TYPE_MODE (type);
24021   enum machine_mode inner_mode = GET_MODE_INNER (tmode);
24022   int i, n_elt = GET_MODE_NUNITS (tmode);
24023   rtvec v = rtvec_alloc (n_elt);
24024
24025   gcc_assert (VECTOR_MODE_P (tmode));
24026   gcc_assert (call_expr_nargs (exp) == n_elt);
24027
24028   for (i = 0; i < n_elt; ++i)
24029     {
24030       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
24031       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
24032     }
24033
24034   if (!target || !register_operand (target, tmode))
24035     target = gen_reg_rtx (tmode);
24036
24037   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
24038   return target;
24039 }
24040
24041 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24042    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
24043    had a language-level syntax for referencing vector elements.  */
24044
24045 static rtx
24046 ix86_expand_vec_ext_builtin (tree exp, rtx target)
24047 {
24048   enum machine_mode tmode, mode0;
24049   tree arg0, arg1;
24050   int elt;
24051   rtx op0;
24052
24053   arg0 = CALL_EXPR_ARG (exp, 0);
24054   arg1 = CALL_EXPR_ARG (exp, 1);
24055
24056   op0 = expand_normal (arg0);
24057   elt = get_element_number (TREE_TYPE (arg0), arg1);
24058
24059   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24060   mode0 = TYPE_MODE (TREE_TYPE (arg0));
24061   gcc_assert (VECTOR_MODE_P (mode0));
24062
24063   op0 = force_reg (mode0, op0);
24064
24065   if (optimize || !target || !register_operand (target, tmode))
24066     target = gen_reg_rtx (tmode);
24067
24068   ix86_expand_vector_extract (true, target, op0, elt);
24069
24070   return target;
24071 }
24072
24073 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24074    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
24075    a language-level syntax for referencing vector elements.  */
24076
24077 static rtx
24078 ix86_expand_vec_set_builtin (tree exp)
24079 {
24080   enum machine_mode tmode, mode1;
24081   tree arg0, arg1, arg2;
24082   int elt;
24083   rtx op0, op1, target;
24084
24085   arg0 = CALL_EXPR_ARG (exp, 0);
24086   arg1 = CALL_EXPR_ARG (exp, 1);
24087   arg2 = CALL_EXPR_ARG (exp, 2);
24088
24089   tmode = TYPE_MODE (TREE_TYPE (arg0));
24090   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24091   gcc_assert (VECTOR_MODE_P (tmode));
24092
24093   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
24094   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
24095   elt = get_element_number (TREE_TYPE (arg0), arg2);
24096
24097   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
24098     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
24099
24100   op0 = force_reg (tmode, op0);
24101   op1 = force_reg (mode1, op1);
24102
24103   /* OP0 is the source of these builtin functions and shouldn't be
24104      modified.  Create a copy, use it and return it as target.  */
24105   target = gen_reg_rtx (tmode);
24106   emit_move_insn (target, op0);
24107   ix86_expand_vector_set (true, target, op1, elt);
24108
24109   return target;
24110 }
24111
24112 /* Expand an expression EXP that calls a built-in function,
24113    with result going to TARGET if that's convenient
24114    (and in mode MODE if that's convenient).
24115    SUBTARGET may be used as the target for computing one of EXP's operands.
24116    IGNORE is nonzero if the value is to be ignored.  */
24117
24118 static rtx
24119 ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
24120                      enum machine_mode mode ATTRIBUTE_UNUSED,
24121                      int ignore ATTRIBUTE_UNUSED)
24122 {
24123   const struct builtin_description *d;
24124   size_t i;
24125   enum insn_code icode;
24126   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
24127   tree arg0, arg1, arg2;
24128   rtx op0, op1, op2, pat;
24129   enum machine_mode mode0, mode1, mode2;
24130   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
24131
24132   /* Determine whether the builtin function is available under the current ISA.
24133      Originally the builtin was not created if it wasn't applicable to the
24134      current ISA based on the command line switches.  With function specific
24135      options, we need to check in the context of the function making the call
24136      whether it is supported.  */
24137   if (ix86_builtins_isa[fcode].isa
24138       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
24139     {
24140       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
24141                                        NULL, NULL, false);
24142
24143       if (!opts)
24144         error ("%qE needs unknown isa option", fndecl);
24145       else
24146         {
24147           gcc_assert (opts != NULL);
24148           error ("%qE needs isa option %s", fndecl, opts);
24149           free (opts);
24150         }
24151       return const0_rtx;
24152     }
24153
24154   switch (fcode)
24155     {
24156     case IX86_BUILTIN_MASKMOVQ:
24157     case IX86_BUILTIN_MASKMOVDQU:
24158       icode = (fcode == IX86_BUILTIN_MASKMOVQ
24159                ? CODE_FOR_mmx_maskmovq
24160                : CODE_FOR_sse2_maskmovdqu);
24161       /* Note the arg order is different from the operand order.  */
24162       arg1 = CALL_EXPR_ARG (exp, 0);
24163       arg2 = CALL_EXPR_ARG (exp, 1);
24164       arg0 = CALL_EXPR_ARG (exp, 2);
24165       op0 = expand_normal (arg0);
24166       op1 = expand_normal (arg1);
24167       op2 = expand_normal (arg2);
24168       mode0 = insn_data[icode].operand[0].mode;
24169       mode1 = insn_data[icode].operand[1].mode;
24170       mode2 = insn_data[icode].operand[2].mode;
24171
24172       op0 = force_reg (Pmode, op0);
24173       op0 = gen_rtx_MEM (mode1, op0);
24174
24175       if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
24176         op0 = copy_to_mode_reg (mode0, op0);
24177       if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
24178         op1 = copy_to_mode_reg (mode1, op1);
24179       if (! (*insn_data[icode].operand[2].predicate) (op2, mode2))
24180         op2 = copy_to_mode_reg (mode2, op2);
24181       pat = GEN_FCN (icode) (op0, op1, op2);
24182       if (! pat)
24183         return 0;
24184       emit_insn (pat);
24185       return 0;
24186
24187     case IX86_BUILTIN_LDMXCSR:
24188       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
24189       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24190       emit_move_insn (target, op0);
24191       emit_insn (gen_sse_ldmxcsr (target));
24192       return 0;
24193
24194     case IX86_BUILTIN_STMXCSR:
24195       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24196       emit_insn (gen_sse_stmxcsr (target));
24197       return copy_to_mode_reg (SImode, target);
24198
24199     case IX86_BUILTIN_CLFLUSH:
24200         arg0 = CALL_EXPR_ARG (exp, 0);
24201         op0 = expand_normal (arg0);
24202         icode = CODE_FOR_sse2_clflush;
24203         if (! (*insn_data[icode].operand[0].predicate) (op0, Pmode))
24204             op0 = copy_to_mode_reg (Pmode, op0);
24205
24206         emit_insn (gen_sse2_clflush (op0));
24207         return 0;
24208
24209     case IX86_BUILTIN_MONITOR:
24210       arg0 = CALL_EXPR_ARG (exp, 0);
24211       arg1 = CALL_EXPR_ARG (exp, 1);
24212       arg2 = CALL_EXPR_ARG (exp, 2);
24213       op0 = expand_normal (arg0);
24214       op1 = expand_normal (arg1);
24215       op2 = expand_normal (arg2);
24216       if (!REG_P (op0))
24217         op0 = copy_to_mode_reg (Pmode, op0);
24218       if (!REG_P (op1))
24219         op1 = copy_to_mode_reg (SImode, op1);
24220       if (!REG_P (op2))
24221         op2 = copy_to_mode_reg (SImode, op2);
24222       emit_insn ((*ix86_gen_monitor) (op0, op1, op2));
24223       return 0;
24224
24225     case IX86_BUILTIN_MWAIT:
24226       arg0 = CALL_EXPR_ARG (exp, 0);
24227       arg1 = CALL_EXPR_ARG (exp, 1);
24228       op0 = expand_normal (arg0);
24229       op1 = expand_normal (arg1);
24230       if (!REG_P (op0))
24231         op0 = copy_to_mode_reg (SImode, op0);
24232       if (!REG_P (op1))
24233         op1 = copy_to_mode_reg (SImode, op1);
24234       emit_insn (gen_sse3_mwait (op0, op1));
24235       return 0;
24236
24237     case IX86_BUILTIN_VEC_INIT_V2SI:
24238     case IX86_BUILTIN_VEC_INIT_V4HI:
24239     case IX86_BUILTIN_VEC_INIT_V8QI:
24240       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
24241
24242     case IX86_BUILTIN_VEC_EXT_V2DF:
24243     case IX86_BUILTIN_VEC_EXT_V2DI:
24244     case IX86_BUILTIN_VEC_EXT_V4SF:
24245     case IX86_BUILTIN_VEC_EXT_V4SI:
24246     case IX86_BUILTIN_VEC_EXT_V8HI:
24247     case IX86_BUILTIN_VEC_EXT_V2SI:
24248     case IX86_BUILTIN_VEC_EXT_V4HI:
24249     case IX86_BUILTIN_VEC_EXT_V16QI:
24250       return ix86_expand_vec_ext_builtin (exp, target);
24251
24252     case IX86_BUILTIN_VEC_SET_V2DI:
24253     case IX86_BUILTIN_VEC_SET_V4SF:
24254     case IX86_BUILTIN_VEC_SET_V4SI:
24255     case IX86_BUILTIN_VEC_SET_V8HI:
24256     case IX86_BUILTIN_VEC_SET_V4HI:
24257     case IX86_BUILTIN_VEC_SET_V16QI:
24258       return ix86_expand_vec_set_builtin (exp);
24259
24260     case IX86_BUILTIN_INFQ:
24261       {
24262         REAL_VALUE_TYPE inf;
24263         rtx tmp;
24264
24265         real_inf (&inf);
24266         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
24267
24268         tmp = validize_mem (force_const_mem (mode, tmp));
24269
24270         if (target == 0)
24271           target = gen_reg_rtx (mode);
24272
24273         emit_move_insn (target, tmp);
24274         return target;
24275       }
24276
24277     default:
24278       break;
24279     }
24280
24281   for (i = 0, d = bdesc_special_args;
24282        i < ARRAY_SIZE (bdesc_special_args);
24283        i++, d++)
24284     if (d->code == fcode)
24285       return ix86_expand_special_args_builtin (d, exp, target);
24286
24287   for (i = 0, d = bdesc_args;
24288        i < ARRAY_SIZE (bdesc_args);
24289        i++, d++)
24290     if (d->code == fcode)
24291       switch (fcode)
24292         {
24293         case IX86_BUILTIN_FABSQ:
24294         case IX86_BUILTIN_COPYSIGNQ:
24295           if (!TARGET_SSE2)
24296             /* Emit a normal call if SSE2 isn't available.  */
24297             return expand_call (exp, target, ignore);
24298         default:
24299           return ix86_expand_args_builtin (d, exp, target);
24300         }
24301
24302   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
24303     if (d->code == fcode)
24304       return ix86_expand_sse_comi (d, exp, target);
24305
24306   for (i = 0, d = bdesc_pcmpestr;
24307        i < ARRAY_SIZE (bdesc_pcmpestr);
24308        i++, d++)
24309     if (d->code == fcode)
24310       return ix86_expand_sse_pcmpestr (d, exp, target);
24311
24312   for (i = 0, d = bdesc_pcmpistr;
24313        i < ARRAY_SIZE (bdesc_pcmpistr);
24314        i++, d++)
24315     if (d->code == fcode)
24316       return ix86_expand_sse_pcmpistr (d, exp, target);
24317
24318   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
24319     if (d->code == fcode)
24320       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
24321                                             (enum multi_arg_type)d->flag,
24322                                             d->comparison);
24323
24324   gcc_unreachable ();
24325 }
24326
24327 /* Returns a function decl for a vectorized version of the builtin function
24328    with builtin function code FN and the result vector type TYPE, or NULL_TREE
24329    if it is not available.  */
24330
24331 static tree
24332 ix86_builtin_vectorized_function (unsigned int fn, tree type_out,
24333                                   tree type_in)
24334 {
24335   enum machine_mode in_mode, out_mode;
24336   int in_n, out_n;
24337
24338   if (TREE_CODE (type_out) != VECTOR_TYPE
24339       || TREE_CODE (type_in) != VECTOR_TYPE)
24340     return NULL_TREE;
24341
24342   out_mode = TYPE_MODE (TREE_TYPE (type_out));
24343   out_n = TYPE_VECTOR_SUBPARTS (type_out);
24344   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24345   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24346
24347   switch (fn)
24348     {
24349     case BUILT_IN_SQRT:
24350       if (out_mode == DFmode && out_n == 2
24351           && in_mode == DFmode && in_n == 2)
24352         return ix86_builtins[IX86_BUILTIN_SQRTPD];
24353       break;
24354
24355     case BUILT_IN_SQRTF:
24356       if (out_mode == SFmode && out_n == 4
24357           && in_mode == SFmode && in_n == 4)
24358         return ix86_builtins[IX86_BUILTIN_SQRTPS_NR];
24359       break;
24360
24361     case BUILT_IN_LRINT:
24362       if (out_mode == SImode && out_n == 4
24363           && in_mode == DFmode && in_n == 2)
24364         return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
24365       break;
24366
24367     case BUILT_IN_LRINTF:
24368       if (out_mode == SImode && out_n == 4
24369           && in_mode == SFmode && in_n == 4)
24370         return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
24371       break;
24372
24373     default:
24374       ;
24375     }
24376
24377   /* Dispatch to a handler for a vectorization library.  */
24378   if (ix86_veclib_handler)
24379     return (*ix86_veclib_handler)(fn, type_out, type_in);
24380
24381   return NULL_TREE;
24382 }
24383
24384 /* Handler for an SVML-style interface to
24385    a library with vectorized intrinsics.  */
24386
24387 static tree
24388 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
24389 {
24390   char name[20];
24391   tree fntype, new_fndecl, args;
24392   unsigned arity;
24393   const char *bname;
24394   enum machine_mode el_mode, in_mode;
24395   int n, in_n;
24396
24397   /* The SVML is suitable for unsafe math only.  */
24398   if (!flag_unsafe_math_optimizations)
24399     return NULL_TREE;
24400
24401   el_mode = TYPE_MODE (TREE_TYPE (type_out));
24402   n = TYPE_VECTOR_SUBPARTS (type_out);
24403   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24404   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24405   if (el_mode != in_mode
24406       || n != in_n)
24407     return NULL_TREE;
24408
24409   switch (fn)
24410     {
24411     case BUILT_IN_EXP:
24412     case BUILT_IN_LOG:
24413     case BUILT_IN_LOG10:
24414     case BUILT_IN_POW:
24415     case BUILT_IN_TANH:
24416     case BUILT_IN_TAN:
24417     case BUILT_IN_ATAN:
24418     case BUILT_IN_ATAN2:
24419     case BUILT_IN_ATANH:
24420     case BUILT_IN_CBRT:
24421     case BUILT_IN_SINH:
24422     case BUILT_IN_SIN:
24423     case BUILT_IN_ASINH:
24424     case BUILT_IN_ASIN:
24425     case BUILT_IN_COSH:
24426     case BUILT_IN_COS:
24427     case BUILT_IN_ACOSH:
24428     case BUILT_IN_ACOS:
24429       if (el_mode != DFmode || n != 2)
24430         return NULL_TREE;
24431       break;
24432
24433     case BUILT_IN_EXPF:
24434     case BUILT_IN_LOGF:
24435     case BUILT_IN_LOG10F:
24436     case BUILT_IN_POWF:
24437     case BUILT_IN_TANHF:
24438     case BUILT_IN_TANF:
24439     case BUILT_IN_ATANF:
24440     case BUILT_IN_ATAN2F:
24441     case BUILT_IN_ATANHF:
24442     case BUILT_IN_CBRTF:
24443     case BUILT_IN_SINHF:
24444     case BUILT_IN_SINF:
24445     case BUILT_IN_ASINHF:
24446     case BUILT_IN_ASINF:
24447     case BUILT_IN_COSHF:
24448     case BUILT_IN_COSF:
24449     case BUILT_IN_ACOSHF:
24450     case BUILT_IN_ACOSF:
24451       if (el_mode != SFmode || n != 4)
24452         return NULL_TREE;
24453       break;
24454
24455     default:
24456       return NULL_TREE;
24457     }
24458
24459   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
24460
24461   if (fn == BUILT_IN_LOGF)
24462     strcpy (name, "vmlsLn4");
24463   else if (fn == BUILT_IN_LOG)
24464     strcpy (name, "vmldLn2");
24465   else if (n == 4)
24466     {
24467       sprintf (name, "vmls%s", bname+10);
24468       name[strlen (name)-1] = '4';
24469     }
24470   else
24471     sprintf (name, "vmld%s2", bname+10);
24472
24473   /* Convert to uppercase. */
24474   name[4] &= ~0x20;
24475
24476   arity = 0;
24477   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
24478        args = TREE_CHAIN (args))
24479     arity++;
24480
24481   if (arity == 1)
24482     fntype = build_function_type_list (type_out, type_in, NULL);
24483   else
24484     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
24485
24486   /* Build a function declaration for the vectorized function.  */
24487   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
24488   TREE_PUBLIC (new_fndecl) = 1;
24489   DECL_EXTERNAL (new_fndecl) = 1;
24490   DECL_IS_NOVOPS (new_fndecl) = 1;
24491   TREE_READONLY (new_fndecl) = 1;
24492
24493   return new_fndecl;
24494 }
24495
24496 /* Handler for an ACML-style interface to
24497    a library with vectorized intrinsics.  */
24498
24499 static tree
24500 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
24501 {
24502   char name[20] = "__vr.._";
24503   tree fntype, new_fndecl, args;
24504   unsigned arity;
24505   const char *bname;
24506   enum machine_mode el_mode, in_mode;
24507   int n, in_n;
24508
24509   /* The ACML is 64bits only and suitable for unsafe math only as
24510      it does not correctly support parts of IEEE with the required
24511      precision such as denormals.  */
24512   if (!TARGET_64BIT
24513       || !flag_unsafe_math_optimizations)
24514     return NULL_TREE;
24515
24516   el_mode = TYPE_MODE (TREE_TYPE (type_out));
24517   n = TYPE_VECTOR_SUBPARTS (type_out);
24518   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24519   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24520   if (el_mode != in_mode
24521       || n != in_n)
24522     return NULL_TREE;
24523
24524   switch (fn)
24525     {
24526     case BUILT_IN_SIN:
24527     case BUILT_IN_COS:
24528     case BUILT_IN_EXP:
24529     case BUILT_IN_LOG:
24530     case BUILT_IN_LOG2:
24531     case BUILT_IN_LOG10:
24532       name[4] = 'd';
24533       name[5] = '2';
24534       if (el_mode != DFmode
24535           || n != 2)
24536         return NULL_TREE;
24537       break;
24538
24539     case BUILT_IN_SINF:
24540     case BUILT_IN_COSF:
24541     case BUILT_IN_EXPF:
24542     case BUILT_IN_POWF:
24543     case BUILT_IN_LOGF:
24544     case BUILT_IN_LOG2F:
24545     case BUILT_IN_LOG10F:
24546       name[4] = 's';
24547       name[5] = '4';
24548       if (el_mode != SFmode
24549           || n != 4)
24550         return NULL_TREE;
24551       break;
24552
24553     default:
24554       return NULL_TREE;
24555     }
24556
24557   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
24558   sprintf (name + 7, "%s", bname+10);
24559
24560   arity = 0;
24561   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
24562        args = TREE_CHAIN (args))
24563     arity++;
24564
24565   if (arity == 1)
24566     fntype = build_function_type_list (type_out, type_in, NULL);
24567   else
24568     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
24569
24570   /* Build a function declaration for the vectorized function.  */
24571   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
24572   TREE_PUBLIC (new_fndecl) = 1;
24573   DECL_EXTERNAL (new_fndecl) = 1;
24574   DECL_IS_NOVOPS (new_fndecl) = 1;
24575   TREE_READONLY (new_fndecl) = 1;
24576
24577   return new_fndecl;
24578 }
24579
24580
24581 /* Returns a decl of a function that implements conversion of an integer vector
24582    into a floating-point vector, or vice-versa. TYPE is the type of the integer
24583    side of the conversion.
24584    Return NULL_TREE if it is not available.  */
24585
24586 static tree
24587 ix86_vectorize_builtin_conversion (unsigned int code, tree type)
24588 {
24589   if (TREE_CODE (type) != VECTOR_TYPE)
24590     return NULL_TREE;
24591
24592   switch (code)
24593     {
24594     case FLOAT_EXPR:
24595       switch (TYPE_MODE (type))
24596         {
24597         case V4SImode:
24598           return ix86_builtins[IX86_BUILTIN_CVTDQ2PS];
24599         default:
24600           return NULL_TREE;
24601         }
24602
24603     case FIX_TRUNC_EXPR:
24604       switch (TYPE_MODE (type))
24605         {
24606         case V4SImode:
24607           return ix86_builtins[IX86_BUILTIN_CVTTPS2DQ];
24608         default:
24609           return NULL_TREE;
24610         }
24611     default:
24612       return NULL_TREE;
24613
24614     }
24615 }
24616
24617 /* Returns a code for a target-specific builtin that implements
24618    reciprocal of the function, or NULL_TREE if not available.  */
24619
24620 static tree
24621 ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
24622                          bool sqrt ATTRIBUTE_UNUSED)
24623 {
24624   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
24625          && flag_finite_math_only && !flag_trapping_math
24626          && flag_unsafe_math_optimizations))
24627     return NULL_TREE;
24628
24629   if (md_fn)
24630     /* Machine dependent builtins.  */
24631     switch (fn)
24632       {
24633         /* Vectorized version of sqrt to rsqrt conversion.  */
24634       case IX86_BUILTIN_SQRTPS_NR:
24635         return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR];
24636
24637       default:
24638         return NULL_TREE;
24639       }
24640   else
24641     /* Normal builtins.  */
24642     switch (fn)
24643       {
24644         /* Sqrt to rsqrt conversion.  */
24645       case BUILT_IN_SQRTF:
24646         return ix86_builtins[IX86_BUILTIN_RSQRTF];
24647
24648       default:
24649         return NULL_TREE;
24650       }
24651 }
24652
24653 /* Store OPERAND to the memory after reload is completed.  This means
24654    that we can't easily use assign_stack_local.  */
24655 rtx
24656 ix86_force_to_memory (enum machine_mode mode, rtx operand)
24657 {
24658   rtx result;
24659
24660   gcc_assert (reload_completed);
24661   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE)
24662     {
24663       result = gen_rtx_MEM (mode,
24664                             gen_rtx_PLUS (Pmode,
24665                                           stack_pointer_rtx,
24666                                           GEN_INT (-RED_ZONE_SIZE)));
24667       emit_move_insn (result, operand);
24668     }
24669   else if ((TARGET_64BIT_MS_ABI || !TARGET_RED_ZONE) && TARGET_64BIT)
24670     {
24671       switch (mode)
24672         {
24673         case HImode:
24674         case SImode:
24675           operand = gen_lowpart (DImode, operand);
24676           /* FALLTHRU */
24677         case DImode:
24678           emit_insn (
24679                       gen_rtx_SET (VOIDmode,
24680                                    gen_rtx_MEM (DImode,
24681                                                 gen_rtx_PRE_DEC (DImode,
24682                                                         stack_pointer_rtx)),
24683                                    operand));
24684           break;
24685         default:
24686           gcc_unreachable ();
24687         }
24688       result = gen_rtx_MEM (mode, stack_pointer_rtx);
24689     }
24690   else
24691     {
24692       switch (mode)
24693         {
24694         case DImode:
24695           {
24696             rtx operands[2];
24697             split_di (&operand, 1, operands, operands + 1);
24698             emit_insn (
24699                         gen_rtx_SET (VOIDmode,
24700                                      gen_rtx_MEM (SImode,
24701                                                   gen_rtx_PRE_DEC (Pmode,
24702                                                         stack_pointer_rtx)),
24703                                      operands[1]));
24704             emit_insn (
24705                         gen_rtx_SET (VOIDmode,
24706                                      gen_rtx_MEM (SImode,
24707                                                   gen_rtx_PRE_DEC (Pmode,
24708                                                         stack_pointer_rtx)),
24709                                      operands[0]));
24710           }
24711           break;
24712         case HImode:
24713           /* Store HImodes as SImodes.  */
24714           operand = gen_lowpart (SImode, operand);
24715           /* FALLTHRU */
24716         case SImode:
24717           emit_insn (
24718                       gen_rtx_SET (VOIDmode,
24719                                    gen_rtx_MEM (GET_MODE (operand),
24720                                                 gen_rtx_PRE_DEC (SImode,
24721                                                         stack_pointer_rtx)),
24722                                    operand));
24723           break;
24724         default:
24725           gcc_unreachable ();
24726         }
24727       result = gen_rtx_MEM (mode, stack_pointer_rtx);
24728     }
24729   return result;
24730 }
24731
24732 /* Free operand from the memory.  */
24733 void
24734 ix86_free_from_memory (enum machine_mode mode)
24735 {
24736   if (!TARGET_RED_ZONE || TARGET_64BIT_MS_ABI)
24737     {
24738       int size;
24739
24740       if (mode == DImode || TARGET_64BIT)
24741         size = 8;
24742       else
24743         size = 4;
24744       /* Use LEA to deallocate stack space.  In peephole2 it will be converted
24745          to pop or add instruction if registers are available.  */
24746       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
24747                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
24748                                             GEN_INT (size))));
24749     }
24750 }
24751
24752 /* Put float CONST_DOUBLE in the constant pool instead of fp regs.
24753    QImode must go into class Q_REGS.
24754    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
24755    movdf to do mem-to-mem moves through integer regs.  */
24756 enum reg_class
24757 ix86_preferred_reload_class (rtx x, enum reg_class regclass)
24758 {
24759   enum machine_mode mode = GET_MODE (x);
24760
24761   /* We're only allowed to return a subclass of CLASS.  Many of the
24762      following checks fail for NO_REGS, so eliminate that early.  */
24763   if (regclass == NO_REGS)
24764     return NO_REGS;
24765
24766   /* All classes can load zeros.  */
24767   if (x == CONST0_RTX (mode))
24768     return regclass;
24769
24770   /* Force constants into memory if we are loading a (nonzero) constant into
24771      an MMX or SSE register.  This is because there are no MMX/SSE instructions
24772      to load from a constant.  */
24773   if (CONSTANT_P (x)
24774       && (MAYBE_MMX_CLASS_P (regclass) || MAYBE_SSE_CLASS_P (regclass)))
24775     return NO_REGS;
24776
24777   /* Prefer SSE regs only, if we can use them for math.  */
24778   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
24779     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
24780
24781   /* Floating-point constants need more complex checks.  */
24782   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
24783     {
24784       /* General regs can load everything.  */
24785       if (reg_class_subset_p (regclass, GENERAL_REGS))
24786         return regclass;
24787
24788       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
24789          zero above.  We only want to wind up preferring 80387 registers if
24790          we plan on doing computation with them.  */
24791       if (TARGET_80387
24792           && standard_80387_constant_p (x))
24793         {
24794           /* Limit class to non-sse.  */
24795           if (regclass == FLOAT_SSE_REGS)
24796             return FLOAT_REGS;
24797           if (regclass == FP_TOP_SSE_REGS)
24798             return FP_TOP_REG;
24799           if (regclass == FP_SECOND_SSE_REGS)
24800             return FP_SECOND_REG;
24801           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
24802             return regclass;
24803         }
24804
24805       return NO_REGS;
24806     }
24807
24808   /* Generally when we see PLUS here, it's the function invariant
24809      (plus soft-fp const_int).  Which can only be computed into general
24810      regs.  */
24811   if (GET_CODE (x) == PLUS)
24812     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
24813
24814   /* QImode constants are easy to load, but non-constant QImode data
24815      must go into Q_REGS.  */
24816   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
24817     {
24818       if (reg_class_subset_p (regclass, Q_REGS))
24819         return regclass;
24820       if (reg_class_subset_p (Q_REGS, regclass))
24821         return Q_REGS;
24822       return NO_REGS;
24823     }
24824
24825   return regclass;
24826 }
24827
24828 /* Discourage putting floating-point values in SSE registers unless
24829    SSE math is being used, and likewise for the 387 registers.  */
24830 enum reg_class
24831 ix86_preferred_output_reload_class (rtx x, enum reg_class regclass)
24832 {
24833   enum machine_mode mode = GET_MODE (x);
24834
24835   /* Restrict the output reload class to the register bank that we are doing
24836      math on.  If we would like not to return a subset of CLASS, reject this
24837      alternative: if reload cannot do this, it will still use its choice.  */
24838   mode = GET_MODE (x);
24839   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
24840     return MAYBE_SSE_CLASS_P (regclass) ? SSE_REGS : NO_REGS;
24841
24842   if (X87_FLOAT_MODE_P (mode))
24843     {
24844       if (regclass == FP_TOP_SSE_REGS)
24845         return FP_TOP_REG;
24846       else if (regclass == FP_SECOND_SSE_REGS)
24847         return FP_SECOND_REG;
24848       else
24849         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
24850     }
24851
24852   return regclass;
24853 }
24854
24855 static enum reg_class
24856 ix86_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
24857                        enum machine_mode mode,
24858                        secondary_reload_info *sri ATTRIBUTE_UNUSED)
24859 {
24860   /* QImode spills from non-QI registers require
24861      intermediate register on 32bit targets.  */
24862   if (!in_p && mode == QImode && !TARGET_64BIT
24863       && (rclass == GENERAL_REGS
24864           || rclass == LEGACY_REGS
24865           || rclass == INDEX_REGS))
24866     {
24867       int regno;
24868
24869       if (REG_P (x))
24870         regno = REGNO (x);
24871       else
24872         regno = -1;
24873
24874       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
24875         regno = true_regnum (x);
24876
24877       /* Return Q_REGS if the operand is in memory.  */
24878       if (regno == -1)
24879         return Q_REGS;
24880     }
24881
24882   return NO_REGS;
24883 }
24884
24885 /* If we are copying between general and FP registers, we need a memory
24886    location. The same is true for SSE and MMX registers.
24887
24888    To optimize register_move_cost performance, allow inline variant.
24889
24890    The macro can't work reliably when one of the CLASSES is class containing
24891    registers from multiple units (SSE, MMX, integer).  We avoid this by never
24892    combining those units in single alternative in the machine description.
24893    Ensure that this constraint holds to avoid unexpected surprises.
24894
24895    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
24896    enforce these sanity checks.  */
24897
24898 static inline int
24899 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
24900                               enum machine_mode mode, int strict)
24901 {
24902   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
24903       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
24904       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
24905       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
24906       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
24907       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
24908     {
24909       gcc_assert (!strict);
24910       return true;
24911     }
24912
24913   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
24914     return true;
24915
24916   /* ??? This is a lie.  We do have moves between mmx/general, and for
24917      mmx/sse2.  But by saying we need secondary memory we discourage the
24918      register allocator from using the mmx registers unless needed.  */
24919   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
24920     return true;
24921
24922   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
24923     {
24924       /* SSE1 doesn't have any direct moves from other classes.  */
24925       if (!TARGET_SSE2)
24926         return true;
24927
24928       /* If the target says that inter-unit moves are more expensive
24929          than moving through memory, then don't generate them.  */
24930       if (!TARGET_INTER_UNIT_MOVES)
24931         return true;
24932
24933       /* Between SSE and general, we have moves no larger than word size.  */
24934       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
24935         return true;
24936     }
24937
24938   return false;
24939 }
24940
24941 int
24942 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
24943                               enum machine_mode mode, int strict)
24944 {
24945   return inline_secondary_memory_needed (class1, class2, mode, strict);
24946 }
24947
24948 /* Return true if the registers in CLASS cannot represent the change from
24949    modes FROM to TO.  */
24950
24951 bool
24952 ix86_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
24953                                enum reg_class regclass)
24954 {
24955   if (from == to)
24956     return false;
24957
24958   /* x87 registers can't do subreg at all, as all values are reformatted
24959      to extended precision.  */
24960   if (MAYBE_FLOAT_CLASS_P (regclass))
24961     return true;
24962
24963   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
24964     {
24965       /* Vector registers do not support QI or HImode loads.  If we don't
24966          disallow a change to these modes, reload will assume it's ok to
24967          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
24968          the vec_dupv4hi pattern.  */
24969       if (GET_MODE_SIZE (from) < 4)
24970         return true;
24971
24972       /* Vector registers do not support subreg with nonzero offsets, which
24973          are otherwise valid for integer registers.  Since we can't see
24974          whether we have a nonzero offset from here, prohibit all
24975          nonparadoxical subregs changing size.  */
24976       if (GET_MODE_SIZE (to) < GET_MODE_SIZE (from))
24977         return true;
24978     }
24979
24980   return false;
24981 }
24982
24983 /* Return the cost of moving data of mode M between a
24984    register and memory.  A value of 2 is the default; this cost is
24985    relative to those in `REGISTER_MOVE_COST'.
24986
24987    This function is used extensively by register_move_cost that is used to
24988    build tables at startup.  Make it inline in this case.
24989    When IN is 2, return maximum of in and out move cost.
24990
24991    If moving between registers and memory is more expensive than
24992    between two registers, you should define this macro to express the
24993    relative cost.
24994
24995    Model also increased moving costs of QImode registers in non
24996    Q_REGS classes.
24997  */
24998 static inline int
24999 inline_memory_move_cost (enum machine_mode mode, enum reg_class regclass,
25000                          int in)
25001 {
25002   int cost;
25003   if (FLOAT_CLASS_P (regclass))
25004     {
25005       int index;
25006       switch (mode)
25007         {
25008           case SFmode:
25009             index = 0;
25010             break;
25011           case DFmode:
25012             index = 1;
25013             break;
25014           case XFmode:
25015             index = 2;
25016             break;
25017           default:
25018             return 100;
25019         }
25020       if (in == 2)
25021         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
25022       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
25023     }
25024   if (SSE_CLASS_P (regclass))
25025     {
25026       int index;
25027       switch (GET_MODE_SIZE (mode))
25028         {
25029           case 4:
25030             index = 0;
25031             break;
25032           case 8:
25033             index = 1;
25034             break;
25035           case 16:
25036             index = 2;
25037             break;
25038           default:
25039             return 100;
25040         }
25041       if (in == 2)
25042         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
25043       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
25044     }
25045   if (MMX_CLASS_P (regclass))
25046     {
25047       int index;
25048       switch (GET_MODE_SIZE (mode))
25049         {
25050           case 4:
25051             index = 0;
25052             break;
25053           case 8:
25054             index = 1;
25055             break;
25056           default:
25057             return 100;
25058         }
25059       if (in)
25060         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
25061       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
25062     }
25063   switch (GET_MODE_SIZE (mode))
25064     {
25065       case 1:
25066         if (Q_CLASS_P (regclass) || TARGET_64BIT)
25067           {
25068             if (!in)
25069               return ix86_cost->int_store[0];
25070             if (TARGET_PARTIAL_REG_DEPENDENCY
25071                 && optimize_function_for_speed_p (cfun))
25072               cost = ix86_cost->movzbl_load;
25073             else
25074               cost = ix86_cost->int_load[0];
25075             if (in == 2)
25076               return MAX (cost, ix86_cost->int_store[0]);
25077             return cost;
25078           }
25079         else
25080           {
25081            if (in == 2)
25082              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
25083            if (in)
25084              return ix86_cost->movzbl_load;
25085            else
25086              return ix86_cost->int_store[0] + 4;
25087           }
25088         break;
25089       case 2:
25090         if (in == 2)
25091           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
25092         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
25093       default:
25094         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
25095         if (mode == TFmode)
25096           mode = XFmode;
25097         if (in == 2)
25098           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
25099         else if (in)
25100           cost = ix86_cost->int_load[2];
25101         else
25102           cost = ix86_cost->int_store[2];
25103         return (cost * (((int) GET_MODE_SIZE (mode)
25104                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
25105     }
25106 }
25107
25108 int
25109 ix86_memory_move_cost (enum machine_mode mode, enum reg_class regclass, int in)
25110 {
25111   return inline_memory_move_cost (mode, regclass, in);
25112 }
25113
25114
25115 /* Return the cost of moving data from a register in class CLASS1 to
25116    one in class CLASS2.
25117
25118    It is not required that the cost always equal 2 when FROM is the same as TO;
25119    on some machines it is expensive to move between registers if they are not
25120    general registers.  */
25121
25122 int
25123 ix86_register_move_cost (enum machine_mode mode, enum reg_class class1,
25124                          enum reg_class class2)
25125 {
25126   /* In case we require secondary memory, compute cost of the store followed
25127      by load.  In order to avoid bad register allocation choices, we need
25128      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
25129
25130   if (inline_secondary_memory_needed (class1, class2, mode, 0))
25131     {
25132       int cost = 1;
25133
25134       cost += inline_memory_move_cost (mode, class1, 2);
25135       cost += inline_memory_move_cost (mode, class2, 2);
25136
25137       /* In case of copying from general_purpose_register we may emit multiple
25138          stores followed by single load causing memory size mismatch stall.
25139          Count this as arbitrarily high cost of 20.  */
25140       if (CLASS_MAX_NREGS (class1, mode) > CLASS_MAX_NREGS (class2, mode))
25141         cost += 20;
25142
25143       /* In the case of FP/MMX moves, the registers actually overlap, and we
25144          have to switch modes in order to treat them differently.  */
25145       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
25146           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
25147         cost += 20;
25148
25149       return cost;
25150     }
25151
25152   /* Moves between SSE/MMX and integer unit are expensive.  */
25153   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
25154       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
25155
25156     /* ??? By keeping returned value relatively high, we limit the number
25157        of moves between integer and MMX/SSE registers for all targets.
25158        Additionally, high value prevents problem with x86_modes_tieable_p(),
25159        where integer modes in MMX/SSE registers are not tieable
25160        because of missing QImode and HImode moves to, from or between
25161        MMX/SSE registers.  */
25162     return MAX (8, ix86_cost->mmxsse_to_integer);
25163
25164   if (MAYBE_FLOAT_CLASS_P (class1))
25165     return ix86_cost->fp_move;
25166   if (MAYBE_SSE_CLASS_P (class1))
25167     return ix86_cost->sse_move;
25168   if (MAYBE_MMX_CLASS_P (class1))
25169     return ix86_cost->mmx_move;
25170   return 2;
25171 }
25172
25173 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE.  */
25174
25175 bool
25176 ix86_hard_regno_mode_ok (int regno, enum machine_mode mode)
25177 {
25178   /* Flags and only flags can only hold CCmode values.  */
25179   if (CC_REGNO_P (regno))
25180     return GET_MODE_CLASS (mode) == MODE_CC;
25181   if (GET_MODE_CLASS (mode) == MODE_CC
25182       || GET_MODE_CLASS (mode) == MODE_RANDOM
25183       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
25184     return 0;
25185   if (FP_REGNO_P (regno))
25186     return VALID_FP_MODE_P (mode);
25187   if (SSE_REGNO_P (regno))
25188     {
25189       /* We implement the move patterns for all vector modes into and
25190          out of SSE registers, even when no operation instructions
25191          are available.  OImode move is available only when AVX is
25192          enabled.  */
25193       return ((TARGET_AVX && mode == OImode)
25194               || VALID_AVX256_REG_MODE (mode)
25195               || VALID_SSE_REG_MODE (mode)
25196               || VALID_SSE2_REG_MODE (mode)
25197               || VALID_MMX_REG_MODE (mode)
25198               || VALID_MMX_REG_MODE_3DNOW (mode));
25199     }
25200   if (MMX_REGNO_P (regno))
25201     {
25202       /* We implement the move patterns for 3DNOW modes even in MMX mode,
25203          so if the register is available at all, then we can move data of
25204          the given mode into or out of it.  */
25205       return (VALID_MMX_REG_MODE (mode)
25206               || VALID_MMX_REG_MODE_3DNOW (mode));
25207     }
25208
25209   if (mode == QImode)
25210     {
25211       /* Take care for QImode values - they can be in non-QI regs,
25212          but then they do cause partial register stalls.  */
25213       if (regno < 4 || TARGET_64BIT)
25214         return 1;
25215       if (!TARGET_PARTIAL_REG_STALL)
25216         return 1;
25217       return reload_in_progress || reload_completed;
25218     }
25219   /* We handle both integer and floats in the general purpose registers.  */
25220   else if (VALID_INT_MODE_P (mode))
25221     return 1;
25222   else if (VALID_FP_MODE_P (mode))
25223     return 1;
25224   else if (VALID_DFP_MODE_P (mode))
25225     return 1;
25226   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
25227      on to use that value in smaller contexts, this can easily force a
25228      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
25229      supporting DImode, allow it.  */
25230   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
25231     return 1;
25232
25233   return 0;
25234 }
25235
25236 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
25237    tieable integer mode.  */
25238
25239 static bool
25240 ix86_tieable_integer_mode_p (enum machine_mode mode)
25241 {
25242   switch (mode)
25243     {
25244     case HImode:
25245     case SImode:
25246       return true;
25247
25248     case QImode:
25249       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
25250
25251     case DImode:
25252       return TARGET_64BIT;
25253
25254     default:
25255       return false;
25256     }
25257 }
25258
25259 /* Return true if MODE1 is accessible in a register that can hold MODE2
25260    without copying.  That is, all register classes that can hold MODE2
25261    can also hold MODE1.  */
25262
25263 bool
25264 ix86_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
25265 {
25266   if (mode1 == mode2)
25267     return true;
25268
25269   if (ix86_tieable_integer_mode_p (mode1)
25270       && ix86_tieable_integer_mode_p (mode2))
25271     return true;
25272
25273   /* MODE2 being XFmode implies fp stack or general regs, which means we
25274      can tie any smaller floating point modes to it.  Note that we do not
25275      tie this with TFmode.  */
25276   if (mode2 == XFmode)
25277     return mode1 == SFmode || mode1 == DFmode;
25278
25279   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
25280      that we can tie it with SFmode.  */
25281   if (mode2 == DFmode)
25282     return mode1 == SFmode;
25283
25284   /* If MODE2 is only appropriate for an SSE register, then tie with
25285      any other mode acceptable to SSE registers.  */
25286   if (GET_MODE_SIZE (mode2) == 16
25287       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
25288     return (GET_MODE_SIZE (mode1) == 16
25289             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
25290
25291   /* If MODE2 is appropriate for an MMX register, then tie
25292      with any other mode acceptable to MMX registers.  */
25293   if (GET_MODE_SIZE (mode2) == 8
25294       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
25295     return (GET_MODE_SIZE (mode1) == 8
25296             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
25297
25298   return false;
25299 }
25300
25301 /* Compute a (partial) cost for rtx X.  Return true if the complete
25302    cost has been computed, and false if subexpressions should be
25303    scanned.  In either case, *TOTAL contains the cost result.  */
25304
25305 static bool
25306 ix86_rtx_costs (rtx x, int code, int outer_code_i, int *total, bool speed)
25307 {
25308   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
25309   enum machine_mode mode = GET_MODE (x);
25310   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
25311
25312   switch (code)
25313     {
25314     case CONST_INT:
25315     case CONST:
25316     case LABEL_REF:
25317     case SYMBOL_REF:
25318       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
25319         *total = 3;
25320       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
25321         *total = 2;
25322       else if (flag_pic && SYMBOLIC_CONST (x)
25323                && (!TARGET_64BIT
25324                    || (!GET_CODE (x) != LABEL_REF
25325                        && (GET_CODE (x) != SYMBOL_REF
25326                            || !SYMBOL_REF_LOCAL_P (x)))))
25327         *total = 1;
25328       else
25329         *total = 0;
25330       return true;
25331
25332     case CONST_DOUBLE:
25333       if (mode == VOIDmode)
25334         *total = 0;
25335       else
25336         switch (standard_80387_constant_p (x))
25337           {
25338           case 1: /* 0.0 */
25339             *total = 1;
25340             break;
25341           default: /* Other constants */
25342             *total = 2;
25343             break;
25344           case 0:
25345           case -1:
25346             /* Start with (MEM (SYMBOL_REF)), since that's where
25347                it'll probably end up.  Add a penalty for size.  */
25348             *total = (COSTS_N_INSNS (1)
25349                       + (flag_pic != 0 && !TARGET_64BIT)
25350                       + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
25351             break;
25352           }
25353       return true;
25354
25355     case ZERO_EXTEND:
25356       /* The zero extensions is often completely free on x86_64, so make
25357          it as cheap as possible.  */
25358       if (TARGET_64BIT && mode == DImode
25359           && GET_MODE (XEXP (x, 0)) == SImode)
25360         *total = 1;
25361       else if (TARGET_ZERO_EXTEND_WITH_AND)
25362         *total = cost->add;
25363       else
25364         *total = cost->movzx;
25365       return false;
25366
25367     case SIGN_EXTEND:
25368       *total = cost->movsx;
25369       return false;
25370
25371     case ASHIFT:
25372       if (CONST_INT_P (XEXP (x, 1))
25373           && (GET_MODE (XEXP (x, 0)) != DImode || TARGET_64BIT))
25374         {
25375           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
25376           if (value == 1)
25377             {
25378               *total = cost->add;
25379               return false;
25380             }
25381           if ((value == 2 || value == 3)
25382               && cost->lea <= cost->shift_const)
25383             {
25384               *total = cost->lea;
25385               return false;
25386             }
25387         }
25388       /* FALLTHRU */
25389
25390     case ROTATE:
25391     case ASHIFTRT:
25392     case LSHIFTRT:
25393     case ROTATERT:
25394       if (!TARGET_64BIT && GET_MODE (XEXP (x, 0)) == DImode)
25395         {
25396           if (CONST_INT_P (XEXP (x, 1)))
25397             {
25398               if (INTVAL (XEXP (x, 1)) > 32)
25399                 *total = cost->shift_const + COSTS_N_INSNS (2);
25400               else
25401                 *total = cost->shift_const * 2;
25402             }
25403           else
25404             {
25405               if (GET_CODE (XEXP (x, 1)) == AND)
25406                 *total = cost->shift_var * 2;
25407               else
25408                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
25409             }
25410         }
25411       else
25412         {
25413           if (CONST_INT_P (XEXP (x, 1)))
25414             *total = cost->shift_const;
25415           else
25416             *total = cost->shift_var;
25417         }
25418       return false;
25419
25420     case MULT:
25421       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25422         {
25423           /* ??? SSE scalar cost should be used here.  */
25424           *total = cost->fmul;
25425           return false;
25426         }
25427       else if (X87_FLOAT_MODE_P (mode))
25428         {
25429           *total = cost->fmul;
25430           return false;
25431         }
25432       else if (FLOAT_MODE_P (mode))
25433         {
25434           /* ??? SSE vector cost should be used here.  */
25435           *total = cost->fmul;
25436           return false;
25437         }
25438       else
25439         {
25440           rtx op0 = XEXP (x, 0);
25441           rtx op1 = XEXP (x, 1);
25442           int nbits;
25443           if (CONST_INT_P (XEXP (x, 1)))
25444             {
25445               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
25446               for (nbits = 0; value != 0; value &= value - 1)
25447                 nbits++;
25448             }
25449           else
25450             /* This is arbitrary.  */
25451             nbits = 7;
25452
25453           /* Compute costs correctly for widening multiplication.  */
25454           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
25455               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
25456                  == GET_MODE_SIZE (mode))
25457             {
25458               int is_mulwiden = 0;
25459               enum machine_mode inner_mode = GET_MODE (op0);
25460
25461               if (GET_CODE (op0) == GET_CODE (op1))
25462                 is_mulwiden = 1, op1 = XEXP (op1, 0);
25463               else if (CONST_INT_P (op1))
25464                 {
25465                   if (GET_CODE (op0) == SIGN_EXTEND)
25466                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
25467                                   == INTVAL (op1);
25468                   else
25469                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
25470                 }
25471
25472               if (is_mulwiden)
25473                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
25474             }
25475
25476           *total = (cost->mult_init[MODE_INDEX (mode)]
25477                     + nbits * cost->mult_bit
25478                     + rtx_cost (op0, outer_code, speed) + rtx_cost (op1, outer_code, speed));
25479
25480           return true;
25481         }
25482
25483     case DIV:
25484     case UDIV:
25485     case MOD:
25486     case UMOD:
25487       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25488         /* ??? SSE cost should be used here.  */
25489         *total = cost->fdiv;
25490       else if (X87_FLOAT_MODE_P (mode))
25491         *total = cost->fdiv;
25492       else if (FLOAT_MODE_P (mode))
25493         /* ??? SSE vector cost should be used here.  */
25494         *total = cost->fdiv;
25495       else
25496         *total = cost->divide[MODE_INDEX (mode)];
25497       return false;
25498
25499     case PLUS:
25500       if (GET_MODE_CLASS (mode) == MODE_INT
25501                && GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (Pmode))
25502         {
25503           if (GET_CODE (XEXP (x, 0)) == PLUS
25504               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
25505               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
25506               && CONSTANT_P (XEXP (x, 1)))
25507             {
25508               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
25509               if (val == 2 || val == 4 || val == 8)
25510                 {
25511                   *total = cost->lea;
25512                   *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
25513                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
25514                                       outer_code, speed);
25515                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25516                   return true;
25517                 }
25518             }
25519           else if (GET_CODE (XEXP (x, 0)) == MULT
25520                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
25521             {
25522               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
25523               if (val == 2 || val == 4 || val == 8)
25524                 {
25525                   *total = cost->lea;
25526                   *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
25527                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25528                   return true;
25529                 }
25530             }
25531           else if (GET_CODE (XEXP (x, 0)) == PLUS)
25532             {
25533               *total = cost->lea;
25534               *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
25535               *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
25536               *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25537               return true;
25538             }
25539         }
25540       /* FALLTHRU */
25541
25542     case MINUS:
25543       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25544         {
25545           /* ??? SSE cost should be used here.  */
25546           *total = cost->fadd;
25547           return false;
25548         }
25549       else if (X87_FLOAT_MODE_P (mode))
25550         {
25551           *total = cost->fadd;
25552           return false;
25553         }
25554       else if (FLOAT_MODE_P (mode))
25555         {
25556           /* ??? SSE vector cost should be used here.  */
25557           *total = cost->fadd;
25558           return false;
25559         }
25560       /* FALLTHRU */
25561
25562     case AND:
25563     case IOR:
25564     case XOR:
25565       if (!TARGET_64BIT && mode == DImode)
25566         {
25567           *total = (cost->add * 2
25568                     + (rtx_cost (XEXP (x, 0), outer_code, speed)
25569                        << (GET_MODE (XEXP (x, 0)) != DImode))
25570                     + (rtx_cost (XEXP (x, 1), outer_code, speed)
25571                        << (GET_MODE (XEXP (x, 1)) != DImode)));
25572           return true;
25573         }
25574       /* FALLTHRU */
25575
25576     case NEG:
25577       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25578         {
25579           /* ??? SSE cost should be used here.  */
25580           *total = cost->fchs;
25581           return false;
25582         }
25583       else if (X87_FLOAT_MODE_P (mode))
25584         {
25585           *total = cost->fchs;
25586           return false;
25587         }
25588       else if (FLOAT_MODE_P (mode))
25589         {
25590           /* ??? SSE vector cost should be used here.  */
25591           *total = cost->fchs;
25592           return false;
25593         }
25594       /* FALLTHRU */
25595
25596     case NOT:
25597       if (!TARGET_64BIT && mode == DImode)
25598         *total = cost->add * 2;
25599       else
25600         *total = cost->add;
25601       return false;
25602
25603     case COMPARE:
25604       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
25605           && XEXP (XEXP (x, 0), 1) == const1_rtx
25606           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
25607           && XEXP (x, 1) == const0_rtx)
25608         {
25609           /* This kind of construct is implemented using test[bwl].
25610              Treat it as if we had an AND.  */
25611           *total = (cost->add
25612                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed)
25613                     + rtx_cost (const1_rtx, outer_code, speed));
25614           return true;
25615         }
25616       return false;
25617
25618     case FLOAT_EXTEND:
25619       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
25620         *total = 0;
25621       return false;
25622
25623     case ABS:
25624       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25625         /* ??? SSE cost should be used here.  */
25626         *total = cost->fabs;
25627       else if (X87_FLOAT_MODE_P (mode))
25628         *total = cost->fabs;
25629       else if (FLOAT_MODE_P (mode))
25630         /* ??? SSE vector cost should be used here.  */
25631         *total = cost->fabs;
25632       return false;
25633
25634     case SQRT:
25635       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25636         /* ??? SSE cost should be used here.  */
25637         *total = cost->fsqrt;
25638       else if (X87_FLOAT_MODE_P (mode))
25639         *total = cost->fsqrt;
25640       else if (FLOAT_MODE_P (mode))
25641         /* ??? SSE vector cost should be used here.  */
25642         *total = cost->fsqrt;
25643       return false;
25644
25645     case UNSPEC:
25646       if (XINT (x, 1) == UNSPEC_TP)
25647         *total = 0;
25648       return false;
25649
25650     default:
25651       return false;
25652     }
25653 }
25654
25655 #if TARGET_MACHO
25656
25657 static int current_machopic_label_num;
25658
25659 /* Given a symbol name and its associated stub, write out the
25660    definition of the stub.  */
25661
25662 void
25663 machopic_output_stub (FILE *file, const char *symb, const char *stub)
25664 {
25665   unsigned int length;
25666   char *binder_name, *symbol_name, lazy_ptr_name[32];
25667   int label = ++current_machopic_label_num;
25668
25669   /* For 64-bit we shouldn't get here.  */
25670   gcc_assert (!TARGET_64BIT);
25671
25672   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
25673   symb = (*targetm.strip_name_encoding) (symb);
25674
25675   length = strlen (stub);
25676   binder_name = XALLOCAVEC (char, length + 32);
25677   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
25678
25679   length = strlen (symb);
25680   symbol_name = XALLOCAVEC (char, length + 32);
25681   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
25682
25683   sprintf (lazy_ptr_name, "L%d$lz", label);
25684
25685   if (MACHOPIC_PURE)
25686     switch_to_section (darwin_sections[machopic_picsymbol_stub_section]);
25687   else
25688     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
25689
25690   fprintf (file, "%s:\n", stub);
25691   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
25692
25693   if (MACHOPIC_PURE)
25694     {
25695       fprintf (file, "\tcall\tLPC$%d\nLPC$%d:\tpopl\t%%eax\n", label, label);
25696       fprintf (file, "\tmovl\t%s-LPC$%d(%%eax),%%edx\n", lazy_ptr_name, label);
25697       fprintf (file, "\tjmp\t*%%edx\n");
25698     }
25699   else
25700     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
25701
25702   fprintf (file, "%s:\n", binder_name);
25703
25704   if (MACHOPIC_PURE)
25705     {
25706       fprintf (file, "\tlea\t%s-LPC$%d(%%eax),%%eax\n", lazy_ptr_name, label);
25707       fprintf (file, "\tpushl\t%%eax\n");
25708     }
25709   else
25710     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
25711
25712   fprintf (file, "\tjmp\tdyld_stub_binding_helper\n");
25713
25714   switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
25715   fprintf (file, "%s:\n", lazy_ptr_name);
25716   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
25717   fprintf (file, "\t.long %s\n", binder_name);
25718 }
25719
25720 void
25721 darwin_x86_file_end (void)
25722 {
25723   darwin_file_end ();
25724   ix86_file_end ();
25725 }
25726 #endif /* TARGET_MACHO */
25727
25728 /* Order the registers for register allocator.  */
25729
25730 void
25731 x86_order_regs_for_local_alloc (void)
25732 {
25733    int pos = 0;
25734    int i;
25735
25736    /* First allocate the local general purpose registers.  */
25737    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
25738      if (GENERAL_REGNO_P (i) && call_used_regs[i])
25739         reg_alloc_order [pos++] = i;
25740
25741    /* Global general purpose registers.  */
25742    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
25743      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
25744         reg_alloc_order [pos++] = i;
25745
25746    /* x87 registers come first in case we are doing FP math
25747       using them.  */
25748    if (!TARGET_SSE_MATH)
25749      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
25750        reg_alloc_order [pos++] = i;
25751
25752    /* SSE registers.  */
25753    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
25754      reg_alloc_order [pos++] = i;
25755    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
25756      reg_alloc_order [pos++] = i;
25757
25758    /* x87 registers.  */
25759    if (TARGET_SSE_MATH)
25760      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
25761        reg_alloc_order [pos++] = i;
25762
25763    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
25764      reg_alloc_order [pos++] = i;
25765
25766    /* Initialize the rest of array as we do not allocate some registers
25767       at all.  */
25768    while (pos < FIRST_PSEUDO_REGISTER)
25769      reg_alloc_order [pos++] = 0;
25770 }
25771
25772 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
25773    struct attribute_spec.handler.  */
25774 static tree
25775 ix86_handle_abi_attribute (tree *node, tree name,
25776                               tree args ATTRIBUTE_UNUSED,
25777                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
25778 {
25779   if (TREE_CODE (*node) != FUNCTION_TYPE
25780       && TREE_CODE (*node) != METHOD_TYPE
25781       && TREE_CODE (*node) != FIELD_DECL
25782       && TREE_CODE (*node) != TYPE_DECL)
25783     {
25784       warning (OPT_Wattributes, "%qs attribute only applies to functions",
25785                IDENTIFIER_POINTER (name));
25786       *no_add_attrs = true;
25787       return NULL_TREE;
25788     }
25789   if (!TARGET_64BIT)
25790     {
25791       warning (OPT_Wattributes, "%qs attribute only available for 64-bit",
25792                IDENTIFIER_POINTER (name));
25793       *no_add_attrs = true;
25794       return NULL_TREE;
25795     }
25796
25797   /* Can combine regparm with all attributes but fastcall.  */
25798   if (is_attribute_p ("ms_abi", name))
25799     {
25800       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
25801         {
25802           error ("ms_abi and sysv_abi attributes are not compatible");
25803         }
25804
25805       return NULL_TREE;
25806     }
25807   else if (is_attribute_p ("sysv_abi", name))
25808     {
25809       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
25810         {
25811           error ("ms_abi and sysv_abi attributes are not compatible");
25812         }
25813
25814       return NULL_TREE;
25815     }
25816
25817   return NULL_TREE;
25818 }
25819
25820 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
25821    struct attribute_spec.handler.  */
25822 static tree
25823 ix86_handle_struct_attribute (tree *node, tree name,
25824                               tree args ATTRIBUTE_UNUSED,
25825                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
25826 {
25827   tree *type = NULL;
25828   if (DECL_P (*node))
25829     {
25830       if (TREE_CODE (*node) == TYPE_DECL)
25831         type = &TREE_TYPE (*node);
25832     }
25833   else
25834     type = node;
25835
25836   if (!(type && (TREE_CODE (*type) == RECORD_TYPE
25837                  || TREE_CODE (*type) == UNION_TYPE)))
25838     {
25839       warning (OPT_Wattributes, "%qs attribute ignored",
25840                IDENTIFIER_POINTER (name));
25841       *no_add_attrs = true;
25842     }
25843
25844   else if ((is_attribute_p ("ms_struct", name)
25845             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
25846            || ((is_attribute_p ("gcc_struct", name)
25847                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
25848     {
25849       warning (OPT_Wattributes, "%qs incompatible attribute ignored",
25850                IDENTIFIER_POINTER (name));
25851       *no_add_attrs = true;
25852     }
25853
25854   return NULL_TREE;
25855 }
25856
25857 static bool
25858 ix86_ms_bitfield_layout_p (const_tree record_type)
25859 {
25860   return (TARGET_MS_BITFIELD_LAYOUT &&
25861           !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
25862     || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
25863 }
25864
25865 /* Returns an expression indicating where the this parameter is
25866    located on entry to the FUNCTION.  */
25867
25868 static rtx
25869 x86_this_parameter (tree function)
25870 {
25871   tree type = TREE_TYPE (function);
25872   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
25873   int nregs;
25874
25875   if (TARGET_64BIT)
25876     {
25877       const int *parm_regs;
25878
25879       if (ix86_function_type_abi (type) == MS_ABI)
25880         parm_regs = x86_64_ms_abi_int_parameter_registers;
25881       else
25882         parm_regs = x86_64_int_parameter_registers;
25883       return gen_rtx_REG (DImode, parm_regs[aggr]);
25884     }
25885
25886   nregs = ix86_function_regparm (type, function);
25887
25888   if (nregs > 0 && !stdarg_p (type))
25889     {
25890       int regno;
25891
25892       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
25893         regno = aggr ? DX_REG : CX_REG;
25894       else
25895         {
25896           regno = AX_REG;
25897           if (aggr)
25898             {
25899               regno = DX_REG;
25900               if (nregs == 1)
25901                 return gen_rtx_MEM (SImode,
25902                                     plus_constant (stack_pointer_rtx, 4));
25903             }
25904         }
25905       return gen_rtx_REG (SImode, regno);
25906     }
25907
25908   return gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx, aggr ? 8 : 4));
25909 }
25910
25911 /* Determine whether x86_output_mi_thunk can succeed.  */
25912
25913 static bool
25914 x86_can_output_mi_thunk (const_tree thunk ATTRIBUTE_UNUSED,
25915                          HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
25916                          HOST_WIDE_INT vcall_offset, const_tree function)
25917 {
25918   /* 64-bit can handle anything.  */
25919   if (TARGET_64BIT)
25920     return true;
25921
25922   /* For 32-bit, everything's fine if we have one free register.  */
25923   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
25924     return true;
25925
25926   /* Need a free register for vcall_offset.  */
25927   if (vcall_offset)
25928     return false;
25929
25930   /* Need a free register for GOT references.  */
25931   if (flag_pic && !(*targetm.binds_local_p) (function))
25932     return false;
25933
25934   /* Otherwise ok.  */
25935   return true;
25936 }
25937
25938 /* Output the assembler code for a thunk function.  THUNK_DECL is the
25939    declaration for the thunk function itself, FUNCTION is the decl for
25940    the target function.  DELTA is an immediate constant offset to be
25941    added to THIS.  If VCALL_OFFSET is nonzero, the word at
25942    *(*this + vcall_offset) should be added to THIS.  */
25943
25944 static void
25945 x86_output_mi_thunk (FILE *file ATTRIBUTE_UNUSED,
25946                      tree thunk ATTRIBUTE_UNUSED, HOST_WIDE_INT delta,
25947                      HOST_WIDE_INT vcall_offset, tree function)
25948 {
25949   rtx xops[3];
25950   rtx this_param = x86_this_parameter (function);
25951   rtx this_reg, tmp;
25952
25953   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
25954      pull it in now and let DELTA benefit.  */
25955   if (REG_P (this_param))
25956     this_reg = this_param;
25957   else if (vcall_offset)
25958     {
25959       /* Put the this parameter into %eax.  */
25960       xops[0] = this_param;
25961       xops[1] = this_reg = gen_rtx_REG (Pmode, AX_REG);
25962       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
25963     }
25964   else
25965     this_reg = NULL_RTX;
25966
25967   /* Adjust the this parameter by a fixed constant.  */
25968   if (delta)
25969     {
25970       xops[0] = GEN_INT (delta);
25971       xops[1] = this_reg ? this_reg : this_param;
25972       if (TARGET_64BIT)
25973         {
25974           if (!x86_64_general_operand (xops[0], DImode))
25975             {
25976               tmp = gen_rtx_REG (DImode, R10_REG);
25977               xops[1] = tmp;
25978               output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", xops);
25979               xops[0] = tmp;
25980               xops[1] = this_param;
25981             }
25982           output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
25983         }
25984       else
25985         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
25986     }
25987
25988   /* Adjust the this parameter by a value stored in the vtable.  */
25989   if (vcall_offset)
25990     {
25991       if (TARGET_64BIT)
25992         tmp = gen_rtx_REG (DImode, R10_REG);
25993       else
25994         {
25995           int tmp_regno = CX_REG;
25996           if (lookup_attribute ("fastcall",
25997                                 TYPE_ATTRIBUTES (TREE_TYPE (function))))
25998             tmp_regno = AX_REG;
25999           tmp = gen_rtx_REG (SImode, tmp_regno);
26000         }
26001
26002       xops[0] = gen_rtx_MEM (Pmode, this_reg);
26003       xops[1] = tmp;
26004       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26005
26006       /* Adjust the this parameter.  */
26007       xops[0] = gen_rtx_MEM (Pmode, plus_constant (tmp, vcall_offset));
26008       if (TARGET_64BIT && !memory_operand (xops[0], Pmode))
26009         {
26010           rtx tmp2 = gen_rtx_REG (DImode, R11_REG);
26011           xops[0] = GEN_INT (vcall_offset);
26012           xops[1] = tmp2;
26013           output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
26014           xops[0] = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, tmp, tmp2));
26015         }
26016       xops[1] = this_reg;
26017       output_asm_insn ("add%z1\t{%0, %1|%1, %0}", xops);
26018     }
26019
26020   /* If necessary, drop THIS back to its stack slot.  */
26021   if (this_reg && this_reg != this_param)
26022     {
26023       xops[0] = this_reg;
26024       xops[1] = this_param;
26025       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26026     }
26027
26028   xops[0] = XEXP (DECL_RTL (function), 0);
26029   if (TARGET_64BIT)
26030     {
26031       if (!flag_pic || (*targetm.binds_local_p) (function))
26032         output_asm_insn ("jmp\t%P0", xops);
26033       /* All thunks should be in the same object as their target,
26034          and thus binds_local_p should be true.  */
26035       else if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
26036         gcc_unreachable ();
26037       else
26038         {
26039           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xops[0]), UNSPEC_GOTPCREL);
26040           tmp = gen_rtx_CONST (Pmode, tmp);
26041           tmp = gen_rtx_MEM (QImode, tmp);
26042           xops[0] = tmp;
26043           output_asm_insn ("jmp\t%A0", xops);
26044         }
26045     }
26046   else
26047     {
26048       if (!flag_pic || (*targetm.binds_local_p) (function))
26049         output_asm_insn ("jmp\t%P0", xops);
26050       else
26051 #if TARGET_MACHO
26052         if (TARGET_MACHO)
26053           {
26054             rtx sym_ref = XEXP (DECL_RTL (function), 0);
26055             tmp = (gen_rtx_SYMBOL_REF
26056                    (Pmode,
26057                     machopic_indirection_name (sym_ref, /*stub_p=*/true)));
26058             tmp = gen_rtx_MEM (QImode, tmp);
26059             xops[0] = tmp;
26060             output_asm_insn ("jmp\t%0", xops);
26061           }
26062         else
26063 #endif /* TARGET_MACHO */
26064         {
26065           tmp = gen_rtx_REG (SImode, CX_REG);
26066           output_set_got (tmp, NULL_RTX);
26067
26068           xops[1] = tmp;
26069           output_asm_insn ("mov{l}\t{%0@GOT(%1), %1|%1, %0@GOT[%1]}", xops);
26070           output_asm_insn ("jmp\t{*}%1", xops);
26071         }
26072     }
26073 }
26074
26075 static void
26076 x86_file_start (void)
26077 {
26078   default_file_start ();
26079 #if TARGET_MACHO
26080   darwin_file_start ();
26081 #endif
26082   if (X86_FILE_START_VERSION_DIRECTIVE)
26083     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
26084   if (X86_FILE_START_FLTUSED)
26085     fputs ("\t.global\t__fltused\n", asm_out_file);
26086   if (ix86_asm_dialect == ASM_INTEL)
26087     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
26088 }
26089
26090 int
26091 x86_field_alignment (tree field, int computed)
26092 {
26093   enum machine_mode mode;
26094   tree type = TREE_TYPE (field);
26095
26096   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
26097     return computed;
26098   mode = TYPE_MODE (strip_array_types (type));
26099   if (mode == DFmode || mode == DCmode
26100       || GET_MODE_CLASS (mode) == MODE_INT
26101       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
26102     return MIN (32, computed);
26103   return computed;
26104 }
26105
26106 /* Output assembler code to FILE to increment profiler label # LABELNO
26107    for profiling a function entry.  */
26108 void
26109 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
26110 {
26111   if (TARGET_64BIT)
26112     {
26113 #ifndef NO_PROFILE_COUNTERS
26114       fprintf (file, "\tleaq\t%sP%d@(%%rip),%%r11\n", LPREFIX, labelno);
26115 #endif
26116
26117       if (DEFAULT_ABI == SYSV_ABI && flag_pic)
26118         fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", MCOUNT_NAME);
26119       else
26120         fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26121     }
26122   else if (flag_pic)
26123     {
26124 #ifndef NO_PROFILE_COUNTERS
26125       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%%s\n",
26126                LPREFIX, labelno, PROFILE_COUNT_REGISTER);
26127 #endif
26128       fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", MCOUNT_NAME);
26129     }
26130   else
26131     {
26132 #ifndef NO_PROFILE_COUNTERS
26133       fprintf (file, "\tmovl\t$%sP%d,%%%s\n", LPREFIX, labelno,
26134                PROFILE_COUNT_REGISTER);
26135 #endif
26136       fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26137     }
26138 }
26139
26140 /* We don't have exact information about the insn sizes, but we may assume
26141    quite safely that we are informed about all 1 byte insns and memory
26142    address sizes.  This is enough to eliminate unnecessary padding in
26143    99% of cases.  */
26144
26145 static int
26146 min_insn_size (rtx insn)
26147 {
26148   int l = 0;
26149
26150   if (!INSN_P (insn) || !active_insn_p (insn))
26151     return 0;
26152
26153   /* Discard alignments we've emit and jump instructions.  */
26154   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
26155       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
26156     return 0;
26157   if (JUMP_P (insn)
26158       && (GET_CODE (PATTERN (insn)) == ADDR_VEC
26159           || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
26160     return 0;
26161
26162   /* Important case - calls are always 5 bytes.
26163      It is common to have many calls in the row.  */
26164   if (CALL_P (insn)
26165       && symbolic_reference_mentioned_p (PATTERN (insn))
26166       && !SIBLING_CALL_P (insn))
26167     return 5;
26168   if (get_attr_length (insn) <= 1)
26169     return 1;
26170
26171   /* For normal instructions we may rely on the sizes of addresses
26172      and the presence of symbol to require 4 bytes of encoding.
26173      This is not the case for jumps where references are PC relative.  */
26174   if (!JUMP_P (insn))
26175     {
26176       l = get_attr_length_address (insn);
26177       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
26178         l = 4;
26179     }
26180   if (l)
26181     return 1+l;
26182   else
26183     return 2;
26184 }
26185
26186 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
26187    window.  */
26188
26189 static void
26190 ix86_avoid_jump_misspredicts (void)
26191 {
26192   rtx insn, start = get_insns ();
26193   int nbytes = 0, njumps = 0;
26194   int isjump = 0;
26195
26196   /* Look for all minimal intervals of instructions containing 4 jumps.
26197      The intervals are bounded by START and INSN.  NBYTES is the total
26198      size of instructions in the interval including INSN and not including
26199      START.  When the NBYTES is smaller than 16 bytes, it is possible
26200      that the end of START and INSN ends up in the same 16byte page.
26201
26202      The smallest offset in the page INSN can start is the case where START
26203      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
26204      We add p2align to 16byte window with maxskip 17 - NBYTES + sizeof (INSN).
26205      */
26206   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
26207     {
26208
26209       nbytes += min_insn_size (insn);
26210       if (dump_file)
26211         fprintf(dump_file, "Insn %i estimated to %i bytes\n",
26212                 INSN_UID (insn), min_insn_size (insn));
26213       if ((JUMP_P (insn)
26214            && GET_CODE (PATTERN (insn)) != ADDR_VEC
26215            && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
26216           || CALL_P (insn))
26217         njumps++;
26218       else
26219         continue;
26220
26221       while (njumps > 3)
26222         {
26223           start = NEXT_INSN (start);
26224           if ((JUMP_P (start)
26225                && GET_CODE (PATTERN (start)) != ADDR_VEC
26226                && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
26227               || CALL_P (start))
26228             njumps--, isjump = 1;
26229           else
26230             isjump = 0;
26231           nbytes -= min_insn_size (start);
26232         }
26233       gcc_assert (njumps >= 0);
26234       if (dump_file)
26235         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
26236                 INSN_UID (start), INSN_UID (insn), nbytes);
26237
26238       if (njumps == 3 && isjump && nbytes < 16)
26239         {
26240           int padsize = 15 - nbytes + min_insn_size (insn);
26241
26242           if (dump_file)
26243             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
26244                      INSN_UID (insn), padsize);
26245           emit_insn_before (gen_align (GEN_INT (padsize)), insn);
26246         }
26247     }
26248 }
26249
26250 /* AMD Athlon works faster
26251    when RET is not destination of conditional jump or directly preceded
26252    by other jump instruction.  We avoid the penalty by inserting NOP just
26253    before the RET instructions in such cases.  */
26254 static void
26255 ix86_pad_returns (void)
26256 {
26257   edge e;
26258   edge_iterator ei;
26259
26260   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
26261     {
26262       basic_block bb = e->src;
26263       rtx ret = BB_END (bb);
26264       rtx prev;
26265       bool replace = false;
26266
26267       if (!JUMP_P (ret) || GET_CODE (PATTERN (ret)) != RETURN
26268           || optimize_bb_for_size_p (bb))
26269         continue;
26270       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
26271         if (active_insn_p (prev) || LABEL_P (prev))
26272           break;
26273       if (prev && LABEL_P (prev))
26274         {
26275           edge e;
26276           edge_iterator ei;
26277
26278           FOR_EACH_EDGE (e, ei, bb->preds)
26279             if (EDGE_FREQUENCY (e) && e->src->index >= 0
26280                 && !(e->flags & EDGE_FALLTHRU))
26281               replace = true;
26282         }
26283       if (!replace)
26284         {
26285           prev = prev_active_insn (ret);
26286           if (prev
26287               && ((JUMP_P (prev) && any_condjump_p (prev))
26288                   || CALL_P (prev)))
26289             replace = true;
26290           /* Empty functions get branch mispredict even when the jump destination
26291              is not visible to us.  */
26292           if (!prev && cfun->function_frequency > FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
26293             replace = true;
26294         }
26295       if (replace)
26296         {
26297           emit_insn_before (gen_return_internal_long (), ret);
26298           delete_insn (ret);
26299         }
26300     }
26301 }
26302
26303 /* Implement machine specific optimizations.  We implement padding of returns
26304    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
26305 static void
26306 ix86_reorg (void)
26307 {
26308   if (TARGET_PAD_RETURNS && optimize
26309       && optimize_function_for_speed_p (cfun))
26310     ix86_pad_returns ();
26311   if (TARGET_FOUR_JUMP_LIMIT && optimize
26312       && optimize_function_for_speed_p (cfun))
26313     ix86_avoid_jump_misspredicts ();
26314 }
26315
26316 /* Return nonzero when QImode register that must be represented via REX prefix
26317    is used.  */
26318 bool
26319 x86_extended_QIreg_mentioned_p (rtx insn)
26320 {
26321   int i;
26322   extract_insn_cached (insn);
26323   for (i = 0; i < recog_data.n_operands; i++)
26324     if (REG_P (recog_data.operand[i])
26325         && REGNO (recog_data.operand[i]) >= 4)
26326        return true;
26327   return false;
26328 }
26329
26330 /* Return nonzero when P points to register encoded via REX prefix.
26331    Called via for_each_rtx.  */
26332 static int
26333 extended_reg_mentioned_1 (rtx *p, void *data ATTRIBUTE_UNUSED)
26334 {
26335    unsigned int regno;
26336    if (!REG_P (*p))
26337      return 0;
26338    regno = REGNO (*p);
26339    return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
26340 }
26341
26342 /* Return true when INSN mentions register that must be encoded using REX
26343    prefix.  */
26344 bool
26345 x86_extended_reg_mentioned_p (rtx insn)
26346 {
26347   return for_each_rtx (INSN_P (insn) ? &PATTERN (insn) : &insn,
26348                        extended_reg_mentioned_1, NULL);
26349 }
26350
26351 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
26352    optabs would emit if we didn't have TFmode patterns.  */
26353
26354 void
26355 x86_emit_floatuns (rtx operands[2])
26356 {
26357   rtx neglab, donelab, i0, i1, f0, in, out;
26358   enum machine_mode mode, inmode;
26359
26360   inmode = GET_MODE (operands[1]);
26361   gcc_assert (inmode == SImode || inmode == DImode);
26362
26363   out = operands[0];
26364   in = force_reg (inmode, operands[1]);
26365   mode = GET_MODE (out);
26366   neglab = gen_label_rtx ();
26367   donelab = gen_label_rtx ();
26368   f0 = gen_reg_rtx (mode);
26369
26370   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
26371
26372   expand_float (out, in, 0);
26373
26374   emit_jump_insn (gen_jump (donelab));
26375   emit_barrier ();
26376
26377   emit_label (neglab);
26378
26379   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
26380                             1, OPTAB_DIRECT);
26381   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
26382                             1, OPTAB_DIRECT);
26383   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
26384
26385   expand_float (f0, i0, 0);
26386
26387   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
26388
26389   emit_label (donelab);
26390 }
26391 \f
26392 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26393    with all elements equal to VAR.  Return true if successful.  */
26394
26395 static bool
26396 ix86_expand_vector_init_duplicate (bool mmx_ok, enum machine_mode mode,
26397                                    rtx target, rtx val)
26398 {
26399   enum machine_mode hmode, smode, wsmode, wvmode;
26400   rtx x;
26401
26402   switch (mode)
26403     {
26404     case V2SImode:
26405     case V2SFmode:
26406       if (!mmx_ok)
26407         return false;
26408       /* FALLTHRU */
26409
26410     case V2DFmode:
26411     case V2DImode:
26412     case V4SFmode:
26413     case V4SImode:
26414       val = force_reg (GET_MODE_INNER (mode), val);
26415       x = gen_rtx_VEC_DUPLICATE (mode, val);
26416       emit_insn (gen_rtx_SET (VOIDmode, target, x));
26417       return true;
26418
26419     case V4HImode:
26420       if (!mmx_ok)
26421         return false;
26422       if (TARGET_SSE || TARGET_3DNOW_A)
26423         {
26424           val = gen_lowpart (SImode, val);
26425           x = gen_rtx_TRUNCATE (HImode, val);
26426           x = gen_rtx_VEC_DUPLICATE (mode, x);
26427           emit_insn (gen_rtx_SET (VOIDmode, target, x));
26428           return true;
26429         }
26430       else
26431         {
26432           smode = HImode;
26433           wsmode = SImode;
26434           wvmode = V2SImode;
26435           goto widen;
26436         }
26437
26438     case V8QImode:
26439       if (!mmx_ok)
26440         return false;
26441       smode = QImode;
26442       wsmode = HImode;
26443       wvmode = V4HImode;
26444       goto widen;
26445     case V8HImode:
26446       if (TARGET_SSE2)
26447         {
26448           rtx tmp1, tmp2;
26449           /* Extend HImode to SImode using a paradoxical SUBREG.  */
26450           tmp1 = gen_reg_rtx (SImode);
26451           emit_move_insn (tmp1, gen_lowpart (SImode, val));
26452           /* Insert the SImode value as low element of V4SImode vector. */
26453           tmp2 = gen_reg_rtx (V4SImode);
26454           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
26455                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
26456                                     CONST0_RTX (V4SImode),
26457                                     const1_rtx);
26458           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
26459           /* Cast the V4SImode vector back to a V8HImode vector.  */
26460           tmp1 = gen_reg_rtx (V8HImode);
26461           emit_move_insn (tmp1, gen_lowpart (V8HImode, tmp2));
26462           /* Duplicate the low short through the whole low SImode word.  */
26463           emit_insn (gen_sse2_punpcklwd (tmp1, tmp1, tmp1));
26464           /* Cast the V8HImode vector back to a V4SImode vector.  */
26465           tmp2 = gen_reg_rtx (V4SImode);
26466           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
26467           /* Replicate the low element of the V4SImode vector.  */
26468           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
26469           /* Cast the V2SImode back to V8HImode, and store in target.  */
26470           emit_move_insn (target, gen_lowpart (V8HImode, tmp2));
26471           return true;
26472         }
26473       smode = HImode;
26474       wsmode = SImode;
26475       wvmode = V4SImode;
26476       goto widen;
26477     case V16QImode:
26478       if (TARGET_SSE2)
26479         {
26480           rtx tmp1, tmp2;
26481           /* Extend QImode to SImode using a paradoxical SUBREG.  */
26482           tmp1 = gen_reg_rtx (SImode);
26483           emit_move_insn (tmp1, gen_lowpart (SImode, val));
26484           /* Insert the SImode value as low element of V4SImode vector. */
26485           tmp2 = gen_reg_rtx (V4SImode);
26486           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
26487                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
26488                                     CONST0_RTX (V4SImode),
26489                                     const1_rtx);
26490           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
26491           /* Cast the V4SImode vector back to a V16QImode vector.  */
26492           tmp1 = gen_reg_rtx (V16QImode);
26493           emit_move_insn (tmp1, gen_lowpart (V16QImode, tmp2));
26494           /* Duplicate the low byte through the whole low SImode word.  */
26495           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
26496           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
26497           /* Cast the V16QImode vector back to a V4SImode vector.  */
26498           tmp2 = gen_reg_rtx (V4SImode);
26499           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
26500           /* Replicate the low element of the V4SImode vector.  */
26501           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
26502           /* Cast the V2SImode back to V16QImode, and store in target.  */
26503           emit_move_insn (target, gen_lowpart (V16QImode, tmp2));
26504           return true;
26505         }
26506       smode = QImode;
26507       wsmode = HImode;
26508       wvmode = V8HImode;
26509       goto widen;
26510     widen:
26511       /* Replicate the value once into the next wider mode and recurse.  */
26512       val = convert_modes (wsmode, smode, val, true);
26513       x = expand_simple_binop (wsmode, ASHIFT, val,
26514                                GEN_INT (GET_MODE_BITSIZE (smode)),
26515                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
26516       val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
26517
26518       x = gen_reg_rtx (wvmode);
26519       if (!ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val))
26520         gcc_unreachable ();
26521       emit_move_insn (target, gen_lowpart (mode, x));
26522       return true;
26523
26524     case V4DFmode:
26525       hmode = V2DFmode;
26526       goto half;
26527     case V4DImode:
26528       hmode = V2DImode;
26529       goto half;
26530     case V8SFmode:
26531       hmode = V4SFmode;
26532       goto half;
26533     case V8SImode:
26534       hmode = V4SImode;
26535       goto half;
26536     case V16HImode:
26537       hmode = V8HImode;
26538       goto half;
26539     case V32QImode:
26540       hmode = V16QImode;
26541       goto half;
26542 half:
26543       {
26544         rtx tmp = gen_reg_rtx (hmode);
26545         ix86_expand_vector_init_duplicate (mmx_ok, hmode, tmp, val);
26546         emit_insn (gen_rtx_SET (VOIDmode, target,
26547                                 gen_rtx_VEC_CONCAT (mode, tmp, tmp)));
26548       }
26549       return true;
26550
26551     default:
26552       return false;
26553     }
26554 }
26555
26556 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26557    whose ONE_VAR element is VAR, and other elements are zero.  Return true
26558    if successful.  */
26559
26560 static bool
26561 ix86_expand_vector_init_one_nonzero (bool mmx_ok, enum machine_mode mode,
26562                                      rtx target, rtx var, int one_var)
26563 {
26564   enum machine_mode vsimode;
26565   rtx new_target;
26566   rtx x, tmp;
26567   bool use_vector_set = false;
26568
26569   switch (mode)
26570     {
26571     case V2DImode:
26572       /* For SSE4.1, we normally use vector set.  But if the second
26573          element is zero and inter-unit moves are OK, we use movq
26574          instead.  */
26575       use_vector_set = (TARGET_64BIT
26576                         && TARGET_SSE4_1
26577                         && !(TARGET_INTER_UNIT_MOVES
26578                              && one_var == 0));
26579       break;
26580     case V16QImode:
26581     case V4SImode:
26582     case V4SFmode:
26583       use_vector_set = TARGET_SSE4_1;
26584       break;
26585     case V8HImode:
26586       use_vector_set = TARGET_SSE2;
26587       break;
26588     case V4HImode:
26589       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
26590       break;
26591     case V32QImode:
26592     case V16HImode:
26593     case V8SImode:
26594     case V8SFmode:
26595     case V4DImode:
26596     case V4DFmode:
26597       use_vector_set = TARGET_AVX;
26598       break;
26599     default:
26600       break;
26601     }
26602
26603   if (use_vector_set)
26604     {
26605       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
26606       var = force_reg (GET_MODE_INNER (mode), var);
26607       ix86_expand_vector_set (mmx_ok, target, var, one_var);
26608       return true; 
26609     }
26610
26611   switch (mode)
26612     {
26613     case V2SFmode:
26614     case V2SImode:
26615       if (!mmx_ok)
26616         return false;
26617       /* FALLTHRU */
26618
26619     case V2DFmode:
26620     case V2DImode:
26621       if (one_var != 0)
26622         return false;
26623       var = force_reg (GET_MODE_INNER (mode), var);
26624       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
26625       emit_insn (gen_rtx_SET (VOIDmode, target, x));
26626       return true;
26627
26628     case V4SFmode:
26629     case V4SImode:
26630       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
26631         new_target = gen_reg_rtx (mode);
26632       else
26633         new_target = target;
26634       var = force_reg (GET_MODE_INNER (mode), var);
26635       x = gen_rtx_VEC_DUPLICATE (mode, var);
26636       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
26637       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
26638       if (one_var != 0)
26639         {
26640           /* We need to shuffle the value to the correct position, so
26641              create a new pseudo to store the intermediate result.  */
26642
26643           /* With SSE2, we can use the integer shuffle insns.  */
26644           if (mode != V4SFmode && TARGET_SSE2)
26645             {
26646               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
26647                                             GEN_INT (1),
26648                                             GEN_INT (one_var == 1 ? 0 : 1),
26649                                             GEN_INT (one_var == 2 ? 0 : 1),
26650                                             GEN_INT (one_var == 3 ? 0 : 1)));
26651               if (target != new_target)
26652                 emit_move_insn (target, new_target);
26653               return true;
26654             }
26655
26656           /* Otherwise convert the intermediate result to V4SFmode and
26657              use the SSE1 shuffle instructions.  */
26658           if (mode != V4SFmode)
26659             {
26660               tmp = gen_reg_rtx (V4SFmode);
26661               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
26662             }
26663           else
26664             tmp = new_target;
26665
26666           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
26667                                        GEN_INT (1),
26668                                        GEN_INT (one_var == 1 ? 0 : 1),
26669                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
26670                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
26671
26672           if (mode != V4SFmode)
26673             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
26674           else if (tmp != target)
26675             emit_move_insn (target, tmp);
26676         }
26677       else if (target != new_target)
26678         emit_move_insn (target, new_target);
26679       return true;
26680
26681     case V8HImode:
26682     case V16QImode:
26683       vsimode = V4SImode;
26684       goto widen;
26685     case V4HImode:
26686     case V8QImode:
26687       if (!mmx_ok)
26688         return false;
26689       vsimode = V2SImode;
26690       goto widen;
26691     widen:
26692       if (one_var != 0)
26693         return false;
26694
26695       /* Zero extend the variable element to SImode and recurse.  */
26696       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
26697
26698       x = gen_reg_rtx (vsimode);
26699       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
26700                                                 var, one_var))
26701         gcc_unreachable ();
26702
26703       emit_move_insn (target, gen_lowpart (mode, x));
26704       return true;
26705
26706     default:
26707       return false;
26708     }
26709 }
26710
26711 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26712    consisting of the values in VALS.  It is known that all elements
26713    except ONE_VAR are constants.  Return true if successful.  */
26714
26715 static bool
26716 ix86_expand_vector_init_one_var (bool mmx_ok, enum machine_mode mode,
26717                                  rtx target, rtx vals, int one_var)
26718 {
26719   rtx var = XVECEXP (vals, 0, one_var);
26720   enum machine_mode wmode;
26721   rtx const_vec, x;
26722
26723   const_vec = copy_rtx (vals);
26724   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
26725   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
26726
26727   switch (mode)
26728     {
26729     case V2DFmode:
26730     case V2DImode:
26731     case V2SFmode:
26732     case V2SImode:
26733       /* For the two element vectors, it's just as easy to use
26734          the general case.  */
26735       return false;
26736
26737     case V4DFmode:
26738     case V4DImode:
26739     case V8SFmode:
26740     case V8SImode:
26741     case V16HImode:
26742     case V32QImode:
26743     case V4SFmode:
26744     case V4SImode:
26745     case V8HImode:
26746     case V4HImode:
26747       break;
26748
26749     case V16QImode:
26750       if (TARGET_SSE4_1)
26751         break;
26752       wmode = V8HImode;
26753       goto widen;
26754     case V8QImode:
26755       wmode = V4HImode;
26756       goto widen;
26757     widen:
26758       /* There's no way to set one QImode entry easily.  Combine
26759          the variable value with its adjacent constant value, and
26760          promote to an HImode set.  */
26761       x = XVECEXP (vals, 0, one_var ^ 1);
26762       if (one_var & 1)
26763         {
26764           var = convert_modes (HImode, QImode, var, true);
26765           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
26766                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
26767           x = GEN_INT (INTVAL (x) & 0xff);
26768         }
26769       else
26770         {
26771           var = convert_modes (HImode, QImode, var, true);
26772           x = gen_int_mode (INTVAL (x) << 8, HImode);
26773         }
26774       if (x != const0_rtx)
26775         var = expand_simple_binop (HImode, IOR, var, x, var,
26776                                    1, OPTAB_LIB_WIDEN);
26777
26778       x = gen_reg_rtx (wmode);
26779       emit_move_insn (x, gen_lowpart (wmode, const_vec));
26780       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
26781
26782       emit_move_insn (target, gen_lowpart (mode, x));
26783       return true;
26784
26785     default:
26786       return false;
26787     }
26788
26789   emit_move_insn (target, const_vec);
26790   ix86_expand_vector_set (mmx_ok, target, var, one_var);
26791   return true;
26792 }
26793
26794 /* A subroutine of ix86_expand_vector_init_general.  Use vector
26795    concatenate to handle the most general case: all values variable,
26796    and none identical.  */
26797
26798 static void
26799 ix86_expand_vector_init_concat (enum machine_mode mode,
26800                                 rtx target, rtx *ops, int n)
26801 {
26802   enum machine_mode cmode, hmode = VOIDmode;
26803   rtx first[8], second[4];
26804   rtvec v;
26805   int i, j;
26806
26807   switch (n)
26808     {
26809     case 2:
26810       switch (mode)
26811         {
26812         case V8SImode:
26813           cmode = V4SImode;
26814           break;
26815         case V8SFmode:
26816           cmode = V4SFmode;
26817           break;
26818         case V4DImode:
26819           cmode = V2DImode;
26820           break;
26821         case V4DFmode:
26822           cmode = V2DFmode;
26823           break;
26824         case V4SImode:
26825           cmode = V2SImode;
26826           break;
26827         case V4SFmode:
26828           cmode = V2SFmode;
26829           break;
26830         case V2DImode:
26831           cmode = DImode;
26832           break;
26833         case V2SImode:
26834           cmode = SImode;
26835           break;
26836         case V2DFmode:
26837           cmode = DFmode;
26838           break;
26839         case V2SFmode:
26840           cmode = SFmode;
26841           break;
26842         default:
26843           gcc_unreachable ();
26844         }
26845
26846       if (!register_operand (ops[1], cmode))
26847         ops[1] = force_reg (cmode, ops[1]);
26848       if (!register_operand (ops[0], cmode))
26849         ops[0] = force_reg (cmode, ops[0]);
26850       emit_insn (gen_rtx_SET (VOIDmode, target,
26851                               gen_rtx_VEC_CONCAT (mode, ops[0],
26852                                                   ops[1])));
26853       break;
26854
26855     case 4:
26856       switch (mode)
26857         {
26858         case V4DImode:
26859           cmode = V2DImode;
26860           break;
26861         case V4DFmode:
26862           cmode = V2DFmode;
26863           break;
26864         case V4SImode:
26865           cmode = V2SImode;
26866           break;
26867         case V4SFmode:
26868           cmode = V2SFmode;
26869           break;
26870         default:
26871           gcc_unreachable ();
26872         }
26873       goto half;
26874
26875     case 8:
26876       switch (mode)
26877         {
26878         case V8SImode:
26879           cmode = V2SImode;
26880           hmode = V4SImode;
26881           break;
26882         case V8SFmode:
26883           cmode = V2SFmode;
26884           hmode = V4SFmode;
26885           break;
26886         default:
26887           gcc_unreachable ();
26888         }
26889       goto half;
26890
26891 half:
26892       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
26893       i = n - 1;
26894       j = (n >> 1) - 1;
26895       for (; i > 0; i -= 2, j--)
26896         {
26897           first[j] = gen_reg_rtx (cmode);
26898           v = gen_rtvec (2, ops[i - 1], ops[i]);
26899           ix86_expand_vector_init (false, first[j],
26900                                    gen_rtx_PARALLEL (cmode, v));
26901         }
26902
26903       n >>= 1;
26904       if (n > 2)
26905         {
26906           gcc_assert (hmode != VOIDmode);
26907           for (i = j = 0; i < n; i += 2, j++)
26908             {
26909               second[j] = gen_reg_rtx (hmode);
26910               ix86_expand_vector_init_concat (hmode, second [j],
26911                                               &first [i], 2);
26912             }
26913           n >>= 1;
26914           ix86_expand_vector_init_concat (mode, target, second, n);
26915         }
26916       else
26917         ix86_expand_vector_init_concat (mode, target, first, n);
26918       break;
26919
26920     default:
26921       gcc_unreachable ();
26922     }
26923 }
26924
26925 /* A subroutine of ix86_expand_vector_init_general.  Use vector
26926    interleave to handle the most general case: all values variable,
26927    and none identical.  */
26928
26929 static void
26930 ix86_expand_vector_init_interleave (enum machine_mode mode,
26931                                     rtx target, rtx *ops, int n)
26932 {
26933   enum machine_mode first_imode, second_imode, third_imode, inner_mode;
26934   int i, j;
26935   rtx op0, op1;
26936   rtx (*gen_load_even) (rtx, rtx, rtx);
26937   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
26938   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
26939   
26940   switch (mode)
26941     {
26942     case V8HImode:
26943       gen_load_even = gen_vec_setv8hi;
26944       gen_interleave_first_low = gen_vec_interleave_lowv4si;
26945       gen_interleave_second_low = gen_vec_interleave_lowv2di;
26946       inner_mode = HImode;
26947       first_imode = V4SImode;
26948       second_imode = V2DImode;
26949       third_imode = VOIDmode;
26950       break;
26951     case V16QImode:
26952       gen_load_even = gen_vec_setv16qi;
26953       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
26954       gen_interleave_second_low = gen_vec_interleave_lowv4si;
26955       inner_mode = QImode;
26956       first_imode = V8HImode;
26957       second_imode = V4SImode;
26958       third_imode = V2DImode;
26959       break;
26960     default:
26961       gcc_unreachable ();
26962     }
26963      
26964   for (i = 0; i < n; i++)
26965     {
26966       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
26967       op0 = gen_reg_rtx (SImode);
26968       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
26969
26970       /* Insert the SImode value as low element of V4SImode vector. */
26971       op1 = gen_reg_rtx (V4SImode);
26972       op0 = gen_rtx_VEC_MERGE (V4SImode,
26973                                gen_rtx_VEC_DUPLICATE (V4SImode,
26974                                                       op0),
26975                                CONST0_RTX (V4SImode),
26976                                const1_rtx);
26977       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
26978
26979       /* Cast the V4SImode vector back to a vector in orignal mode.  */
26980       op0 = gen_reg_rtx (mode);
26981       emit_move_insn (op0, gen_lowpart (mode, op1));
26982       
26983       /* Load even elements into the second positon.  */
26984       emit_insn ((*gen_load_even) (op0,
26985                                    force_reg (inner_mode,
26986                                               ops [i + i + 1]),
26987                                    const1_rtx));
26988
26989       /* Cast vector to FIRST_IMODE vector.  */
26990       ops[i] = gen_reg_rtx (first_imode);
26991       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
26992     }
26993
26994   /* Interleave low FIRST_IMODE vectors.  */
26995   for (i = j = 0; i < n; i += 2, j++)
26996     {
26997       op0 = gen_reg_rtx (first_imode);
26998       emit_insn ((*gen_interleave_first_low) (op0, ops[i], ops[i + 1]));
26999
27000       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
27001       ops[j] = gen_reg_rtx (second_imode);
27002       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
27003     }
27004
27005   /* Interleave low SECOND_IMODE vectors.  */
27006   switch (second_imode)
27007     {
27008     case V4SImode:
27009       for (i = j = 0; i < n / 2; i += 2, j++)
27010         {
27011           op0 = gen_reg_rtx (second_imode);
27012           emit_insn ((*gen_interleave_second_low) (op0, ops[i],
27013                                                    ops[i + 1]));
27014
27015           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
27016              vector.  */
27017           ops[j] = gen_reg_rtx (third_imode);
27018           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
27019         }
27020       second_imode = V2DImode;
27021       gen_interleave_second_low = gen_vec_interleave_lowv2di;
27022       /* FALLTHRU */
27023
27024     case V2DImode:
27025       op0 = gen_reg_rtx (second_imode);
27026       emit_insn ((*gen_interleave_second_low) (op0, ops[0],
27027                                                ops[1]));
27028
27029       /* Cast the SECOND_IMODE vector back to a vector on original
27030          mode.  */
27031       emit_insn (gen_rtx_SET (VOIDmode, target,
27032                               gen_lowpart (mode, op0)));
27033       break;
27034
27035     default:
27036       gcc_unreachable ();
27037     }
27038 }
27039
27040 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
27041    all values variable, and none identical.  */
27042
27043 static void
27044 ix86_expand_vector_init_general (bool mmx_ok, enum machine_mode mode,
27045                                  rtx target, rtx vals)
27046 {
27047   rtx ops[32], op0, op1;
27048   enum machine_mode half_mode = VOIDmode;
27049   int n, i;
27050
27051   switch (mode)
27052     {
27053     case V2SFmode:
27054     case V2SImode:
27055       if (!mmx_ok && !TARGET_SSE)
27056         break;
27057       /* FALLTHRU */
27058
27059     case V8SFmode:
27060     case V8SImode:
27061     case V4DFmode:
27062     case V4DImode:
27063     case V4SFmode:
27064     case V4SImode:
27065     case V2DFmode:
27066     case V2DImode:
27067       n = GET_MODE_NUNITS (mode);
27068       for (i = 0; i < n; i++)
27069         ops[i] = XVECEXP (vals, 0, i);
27070       ix86_expand_vector_init_concat (mode, target, ops, n);
27071       return;
27072
27073     case V32QImode:
27074       half_mode = V16QImode;
27075       goto half;
27076
27077     case V16HImode:
27078       half_mode = V8HImode;
27079       goto half;
27080
27081 half:
27082       n = GET_MODE_NUNITS (mode);
27083       for (i = 0; i < n; i++)
27084         ops[i] = XVECEXP (vals, 0, i);
27085       op0 = gen_reg_rtx (half_mode);
27086       op1 = gen_reg_rtx (half_mode);
27087       ix86_expand_vector_init_interleave (half_mode, op0, ops,
27088                                           n >> 2);
27089       ix86_expand_vector_init_interleave (half_mode, op1,
27090                                           &ops [n >> 1], n >> 2);
27091       emit_insn (gen_rtx_SET (VOIDmode, target,
27092                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
27093       return;
27094
27095     case V16QImode:
27096       if (!TARGET_SSE4_1)
27097         break;
27098       /* FALLTHRU */
27099
27100     case V8HImode:
27101       if (!TARGET_SSE2)
27102         break;
27103
27104       /* Don't use ix86_expand_vector_init_interleave if we can't
27105          move from GPR to SSE register directly.  */ 
27106       if (!TARGET_INTER_UNIT_MOVES)
27107         break;
27108
27109       n = GET_MODE_NUNITS (mode);
27110       for (i = 0; i < n; i++)
27111         ops[i] = XVECEXP (vals, 0, i);
27112       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
27113       return;
27114
27115     case V4HImode:
27116     case V8QImode:
27117       break;
27118
27119     default:
27120       gcc_unreachable ();
27121     }
27122
27123     {
27124       int i, j, n_elts, n_words, n_elt_per_word;
27125       enum machine_mode inner_mode;
27126       rtx words[4], shift;
27127
27128       inner_mode = GET_MODE_INNER (mode);
27129       n_elts = GET_MODE_NUNITS (mode);
27130       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
27131       n_elt_per_word = n_elts / n_words;
27132       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
27133
27134       for (i = 0; i < n_words; ++i)
27135         {
27136           rtx word = NULL_RTX;
27137
27138           for (j = 0; j < n_elt_per_word; ++j)
27139             {
27140               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
27141               elt = convert_modes (word_mode, inner_mode, elt, true);
27142
27143               if (j == 0)
27144                 word = elt;
27145               else
27146                 {
27147                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
27148                                               word, 1, OPTAB_LIB_WIDEN);
27149                   word = expand_simple_binop (word_mode, IOR, word, elt,
27150                                               word, 1, OPTAB_LIB_WIDEN);
27151                 }
27152             }
27153
27154           words[i] = word;
27155         }
27156
27157       if (n_words == 1)
27158         emit_move_insn (target, gen_lowpart (mode, words[0]));
27159       else if (n_words == 2)
27160         {
27161           rtx tmp = gen_reg_rtx (mode);
27162           emit_clobber (tmp);
27163           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
27164           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
27165           emit_move_insn (target, tmp);
27166         }
27167       else if (n_words == 4)
27168         {
27169           rtx tmp = gen_reg_rtx (V4SImode);
27170           gcc_assert (word_mode == SImode);
27171           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
27172           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
27173           emit_move_insn (target, gen_lowpart (mode, tmp));
27174         }
27175       else
27176         gcc_unreachable ();
27177     }
27178 }
27179
27180 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
27181    instructions unless MMX_OK is true.  */
27182
27183 void
27184 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
27185 {
27186   enum machine_mode mode = GET_MODE (target);
27187   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27188   int n_elts = GET_MODE_NUNITS (mode);
27189   int n_var = 0, one_var = -1;
27190   bool all_same = true, all_const_zero = true;
27191   int i;
27192   rtx x;
27193
27194   for (i = 0; i < n_elts; ++i)
27195     {
27196       x = XVECEXP (vals, 0, i);
27197       if (!(CONST_INT_P (x)
27198             || GET_CODE (x) == CONST_DOUBLE
27199             || GET_CODE (x) == CONST_FIXED))
27200         n_var++, one_var = i;
27201       else if (x != CONST0_RTX (inner_mode))
27202         all_const_zero = false;
27203       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
27204         all_same = false;
27205     }
27206
27207   /* Constants are best loaded from the constant pool.  */
27208   if (n_var == 0)
27209     {
27210       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
27211       return;
27212     }
27213
27214   /* If all values are identical, broadcast the value.  */
27215   if (all_same
27216       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
27217                                             XVECEXP (vals, 0, 0)))
27218     return;
27219
27220   /* Values where only one field is non-constant are best loaded from
27221      the pool and overwritten via move later.  */
27222   if (n_var == 1)
27223     {
27224       if (all_const_zero
27225           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
27226                                                   XVECEXP (vals, 0, one_var),
27227                                                   one_var))
27228         return;
27229
27230       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
27231         return;
27232     }
27233
27234   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
27235 }
27236
27237 void
27238 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
27239 {
27240   enum machine_mode mode = GET_MODE (target);
27241   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27242   enum machine_mode half_mode;
27243   bool use_vec_merge = false;
27244   rtx tmp;
27245   static rtx (*gen_extract[6][2]) (rtx, rtx)
27246     = {
27247         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
27248         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
27249         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
27250         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
27251         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
27252         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
27253       };
27254   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
27255     = {
27256         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
27257         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
27258         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
27259         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
27260         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
27261         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
27262       };
27263   int i, j, n;
27264
27265   switch (mode)
27266     {
27267     case V2SFmode:
27268     case V2SImode:
27269       if (mmx_ok)
27270         {
27271           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
27272           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
27273           if (elt == 0)
27274             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
27275           else
27276             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
27277           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27278           return;
27279         }
27280       break;
27281
27282     case V2DImode:
27283       use_vec_merge = TARGET_SSE4_1;
27284       if (use_vec_merge)
27285         break;
27286
27287     case V2DFmode:
27288       {
27289         rtx op0, op1;
27290
27291         /* For the two element vectors, we implement a VEC_CONCAT with
27292            the extraction of the other element.  */
27293
27294         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
27295         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
27296
27297         if (elt == 0)
27298           op0 = val, op1 = tmp;
27299         else
27300           op0 = tmp, op1 = val;
27301
27302         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
27303         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27304       }
27305       return;
27306
27307     case V4SFmode:
27308       use_vec_merge = TARGET_SSE4_1;
27309       if (use_vec_merge)
27310         break;
27311
27312       switch (elt)
27313         {
27314         case 0:
27315           use_vec_merge = true;
27316           break;
27317
27318         case 1:
27319           /* tmp = target = A B C D */
27320           tmp = copy_to_reg (target);
27321           /* target = A A B B */
27322           emit_insn (gen_sse_unpcklps (target, target, target));
27323           /* target = X A B B */
27324           ix86_expand_vector_set (false, target, val, 0);
27325           /* target = A X C D  */
27326           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27327                                        GEN_INT (1), GEN_INT (0),
27328                                        GEN_INT (2+4), GEN_INT (3+4)));
27329           return;
27330
27331         case 2:
27332           /* tmp = target = A B C D */
27333           tmp = copy_to_reg (target);
27334           /* tmp = X B C D */
27335           ix86_expand_vector_set (false, tmp, val, 0);
27336           /* target = A B X D */
27337           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27338                                        GEN_INT (0), GEN_INT (1),
27339                                        GEN_INT (0+4), GEN_INT (3+4)));
27340           return;
27341
27342         case 3:
27343           /* tmp = target = A B C D */
27344           tmp = copy_to_reg (target);
27345           /* tmp = X B C D */
27346           ix86_expand_vector_set (false, tmp, val, 0);
27347           /* target = A B X D */
27348           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27349                                        GEN_INT (0), GEN_INT (1),
27350                                        GEN_INT (2+4), GEN_INT (0+4)));
27351           return;
27352
27353         default:
27354           gcc_unreachable ();
27355         }
27356       break;
27357
27358     case V4SImode:
27359       use_vec_merge = TARGET_SSE4_1;
27360       if (use_vec_merge)
27361         break;
27362
27363       /* Element 0 handled by vec_merge below.  */
27364       if (elt == 0)
27365         {
27366           use_vec_merge = true;
27367           break;
27368         }
27369
27370       if (TARGET_SSE2)
27371         {
27372           /* With SSE2, use integer shuffles to swap element 0 and ELT,
27373              store into element 0, then shuffle them back.  */
27374
27375           rtx order[4];
27376
27377           order[0] = GEN_INT (elt);
27378           order[1] = const1_rtx;
27379           order[2] = const2_rtx;
27380           order[3] = GEN_INT (3);
27381           order[elt] = const0_rtx;
27382
27383           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
27384                                         order[1], order[2], order[3]));
27385
27386           ix86_expand_vector_set (false, target, val, 0);
27387
27388           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
27389                                         order[1], order[2], order[3]));
27390         }
27391       else
27392         {
27393           /* For SSE1, we have to reuse the V4SF code.  */
27394           ix86_expand_vector_set (false, gen_lowpart (V4SFmode, target),
27395                                   gen_lowpart (SFmode, val), elt);
27396         }
27397       return;
27398
27399     case V8HImode:
27400       use_vec_merge = TARGET_SSE2;
27401       break;
27402     case V4HImode:
27403       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
27404       break;
27405
27406     case V16QImode:
27407       use_vec_merge = TARGET_SSE4_1;
27408       break;
27409
27410     case V8QImode:
27411       break;
27412
27413     case V32QImode:
27414       half_mode = V16QImode;
27415       j = 0;
27416       n = 16;
27417       goto half;
27418
27419     case V16HImode:
27420       half_mode = V8HImode;
27421       j = 1;
27422       n = 8;
27423       goto half;
27424
27425     case V8SImode:
27426       half_mode = V4SImode;
27427       j = 2;
27428       n = 4;
27429       goto half;
27430
27431     case V4DImode:
27432       half_mode = V2DImode;
27433       j = 3;
27434       n = 2;
27435       goto half;
27436
27437     case V8SFmode:
27438       half_mode = V4SFmode;
27439       j = 4;
27440       n = 4;
27441       goto half;
27442
27443     case V4DFmode:
27444       half_mode = V2DFmode;
27445       j = 5;
27446       n = 2;
27447       goto half;
27448
27449 half:
27450       /* Compute offset.  */
27451       i = elt / n;
27452       elt %= n;
27453
27454       gcc_assert (i <= 1);
27455
27456       /* Extract the half.  */
27457       tmp = gen_reg_rtx (half_mode);
27458       emit_insn ((*gen_extract[j][i]) (tmp, target));
27459
27460       /* Put val in tmp at elt.  */
27461       ix86_expand_vector_set (false, tmp, val, elt);
27462
27463       /* Put it back.  */
27464       emit_insn ((*gen_insert[j][i]) (target, target, tmp));
27465       return;
27466
27467     default:
27468       break;
27469     }
27470
27471   if (use_vec_merge)
27472     {
27473       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
27474       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
27475       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27476     }
27477   else
27478     {
27479       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
27480
27481       emit_move_insn (mem, target);
27482
27483       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
27484       emit_move_insn (tmp, val);
27485
27486       emit_move_insn (target, mem);
27487     }
27488 }
27489
27490 void
27491 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
27492 {
27493   enum machine_mode mode = GET_MODE (vec);
27494   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27495   bool use_vec_extr = false;
27496   rtx tmp;
27497
27498   switch (mode)
27499     {
27500     case V2SImode:
27501     case V2SFmode:
27502       if (!mmx_ok)
27503         break;
27504       /* FALLTHRU */
27505
27506     case V2DFmode:
27507     case V2DImode:
27508       use_vec_extr = true;
27509       break;
27510
27511     case V4SFmode:
27512       use_vec_extr = TARGET_SSE4_1;
27513       if (use_vec_extr)
27514         break;
27515
27516       switch (elt)
27517         {
27518         case 0:
27519           tmp = vec;
27520           break;
27521
27522         case 1:
27523         case 3:
27524           tmp = gen_reg_rtx (mode);
27525           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
27526                                        GEN_INT (elt), GEN_INT (elt),
27527                                        GEN_INT (elt+4), GEN_INT (elt+4)));
27528           break;
27529
27530         case 2:
27531           tmp = gen_reg_rtx (mode);
27532           emit_insn (gen_sse_unpckhps (tmp, vec, vec));
27533           break;
27534
27535         default:
27536           gcc_unreachable ();
27537         }
27538       vec = tmp;
27539       use_vec_extr = true;
27540       elt = 0;
27541       break;
27542
27543     case V4SImode:
27544       use_vec_extr = TARGET_SSE4_1;
27545       if (use_vec_extr)
27546         break;
27547
27548       if (TARGET_SSE2)
27549         {
27550           switch (elt)
27551             {
27552             case 0:
27553               tmp = vec;
27554               break;
27555
27556             case 1:
27557             case 3:
27558               tmp = gen_reg_rtx (mode);
27559               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
27560                                             GEN_INT (elt), GEN_INT (elt),
27561                                             GEN_INT (elt), GEN_INT (elt)));
27562               break;
27563
27564             case 2:
27565               tmp = gen_reg_rtx (mode);
27566               emit_insn (gen_sse2_punpckhdq (tmp, vec, vec));
27567               break;
27568
27569             default:
27570               gcc_unreachable ();
27571             }
27572           vec = tmp;
27573           use_vec_extr = true;
27574           elt = 0;
27575         }
27576       else
27577         {
27578           /* For SSE1, we have to reuse the V4SF code.  */
27579           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
27580                                       gen_lowpart (V4SFmode, vec), elt);
27581           return;
27582         }
27583       break;
27584
27585     case V8HImode:
27586       use_vec_extr = TARGET_SSE2;
27587       break;
27588     case V4HImode:
27589       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
27590       break;
27591
27592     case V16QImode:
27593       use_vec_extr = TARGET_SSE4_1;
27594       break;
27595
27596     case V8QImode:
27597       /* ??? Could extract the appropriate HImode element and shift.  */
27598     default:
27599       break;
27600     }
27601
27602   if (use_vec_extr)
27603     {
27604       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
27605       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
27606
27607       /* Let the rtl optimizers know about the zero extension performed.  */
27608       if (inner_mode == QImode || inner_mode == HImode)
27609         {
27610           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
27611           target = gen_lowpart (SImode, target);
27612         }
27613
27614       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27615     }
27616   else
27617     {
27618       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
27619
27620       emit_move_insn (mem, vec);
27621
27622       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
27623       emit_move_insn (target, tmp);
27624     }
27625 }
27626
27627 /* Expand a vector reduction on V4SFmode for SSE1.  FN is the binary
27628    pattern to reduce; DEST is the destination; IN is the input vector.  */
27629
27630 void
27631 ix86_expand_reduc_v4sf (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
27632 {
27633   rtx tmp1, tmp2, tmp3;
27634
27635   tmp1 = gen_reg_rtx (V4SFmode);
27636   tmp2 = gen_reg_rtx (V4SFmode);
27637   tmp3 = gen_reg_rtx (V4SFmode);
27638
27639   emit_insn (gen_sse_movhlps (tmp1, in, in));
27640   emit_insn (fn (tmp2, tmp1, in));
27641
27642   emit_insn (gen_sse_shufps_v4sf (tmp3, tmp2, tmp2,
27643                                GEN_INT (1), GEN_INT (1),
27644                                GEN_INT (1+4), GEN_INT (1+4)));
27645   emit_insn (fn (dest, tmp2, tmp3));
27646 }
27647 \f
27648 /* Target hook for scalar_mode_supported_p.  */
27649 static bool
27650 ix86_scalar_mode_supported_p (enum machine_mode mode)
27651 {
27652   if (DECIMAL_FLOAT_MODE_P (mode))
27653     return true;
27654   else if (mode == TFmode)
27655     return true;
27656   else
27657     return default_scalar_mode_supported_p (mode);
27658 }
27659
27660 /* Implements target hook vector_mode_supported_p.  */
27661 static bool
27662 ix86_vector_mode_supported_p (enum machine_mode mode)
27663 {
27664   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
27665     return true;
27666   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
27667     return true;
27668   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
27669     return true;
27670   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
27671     return true;
27672   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
27673     return true;
27674   return false;
27675 }
27676
27677 /* Target hook for c_mode_for_suffix.  */
27678 static enum machine_mode
27679 ix86_c_mode_for_suffix (char suffix)
27680 {
27681   if (suffix == 'q')
27682     return TFmode;
27683   if (suffix == 'w')
27684     return XFmode;
27685
27686   return VOIDmode;
27687 }
27688
27689 /* Worker function for TARGET_MD_ASM_CLOBBERS.
27690
27691    We do this in the new i386 backend to maintain source compatibility
27692    with the old cc0-based compiler.  */
27693
27694 static tree
27695 ix86_md_asm_clobbers (tree outputs ATTRIBUTE_UNUSED,
27696                       tree inputs ATTRIBUTE_UNUSED,
27697                       tree clobbers)
27698 {
27699   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
27700                         clobbers);
27701   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
27702                         clobbers);
27703   return clobbers;
27704 }
27705
27706 /* Implements target vector targetm.asm.encode_section_info.  This
27707    is not used by netware.  */
27708
27709 static void ATTRIBUTE_UNUSED
27710 ix86_encode_section_info (tree decl, rtx rtl, int first)
27711 {
27712   default_encode_section_info (decl, rtl, first);
27713
27714   if (TREE_CODE (decl) == VAR_DECL
27715       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
27716       && ix86_in_large_data_p (decl))
27717     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
27718 }
27719
27720 /* Worker function for REVERSE_CONDITION.  */
27721
27722 enum rtx_code
27723 ix86_reverse_condition (enum rtx_code code, enum machine_mode mode)
27724 {
27725   return (mode != CCFPmode && mode != CCFPUmode
27726           ? reverse_condition (code)
27727           : reverse_condition_maybe_unordered (code));
27728 }
27729
27730 /* Output code to perform an x87 FP register move, from OPERANDS[1]
27731    to OPERANDS[0].  */
27732
27733 const char *
27734 output_387_reg_move (rtx insn, rtx *operands)
27735 {
27736   if (REG_P (operands[0]))
27737     {
27738       if (REG_P (operands[1])
27739           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
27740         {
27741           if (REGNO (operands[0]) == FIRST_STACK_REG)
27742             return output_387_ffreep (operands, 0);
27743           return "fstp\t%y0";
27744         }
27745       if (STACK_TOP_P (operands[0]))
27746         return "fld%z1\t%y1";
27747       return "fst\t%y0";
27748     }
27749   else if (MEM_P (operands[0]))
27750     {
27751       gcc_assert (REG_P (operands[1]));
27752       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
27753         return "fstp%z0\t%y0";
27754       else
27755         {
27756           /* There is no non-popping store to memory for XFmode.
27757              So if we need one, follow the store with a load.  */
27758           if (GET_MODE (operands[0]) == XFmode)
27759             return "fstp%z0\t%y0\n\tfld%z0\t%y0";
27760           else
27761             return "fst%z0\t%y0";
27762         }
27763     }
27764   else
27765     gcc_unreachable();
27766 }
27767
27768 /* Output code to perform a conditional jump to LABEL, if C2 flag in
27769    FP status register is set.  */
27770
27771 void
27772 ix86_emit_fp_unordered_jump (rtx label)
27773 {
27774   rtx reg = gen_reg_rtx (HImode);
27775   rtx temp;
27776
27777   emit_insn (gen_x86_fnstsw_1 (reg));
27778
27779   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
27780     {
27781       emit_insn (gen_x86_sahf_1 (reg));
27782
27783       temp = gen_rtx_REG (CCmode, FLAGS_REG);
27784       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
27785     }
27786   else
27787     {
27788       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
27789
27790       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
27791       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
27792     }
27793
27794   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
27795                               gen_rtx_LABEL_REF (VOIDmode, label),
27796                               pc_rtx);
27797   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
27798
27799   emit_jump_insn (temp);
27800   predict_jump (REG_BR_PROB_BASE * 10 / 100);
27801 }
27802
27803 /* Output code to perform a log1p XFmode calculation.  */
27804
27805 void ix86_emit_i387_log1p (rtx op0, rtx op1)
27806 {
27807   rtx label1 = gen_label_rtx ();
27808   rtx label2 = gen_label_rtx ();
27809
27810   rtx tmp = gen_reg_rtx (XFmode);
27811   rtx tmp2 = gen_reg_rtx (XFmode);
27812
27813   emit_insn (gen_absxf2 (tmp, op1));
27814   emit_insn (gen_cmpxf (tmp,
27815     CONST_DOUBLE_FROM_REAL_VALUE (
27816        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
27817        XFmode)));
27818   emit_jump_insn (gen_bge (label1));
27819
27820   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
27821   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
27822   emit_jump (label2);
27823
27824   emit_label (label1);
27825   emit_move_insn (tmp, CONST1_RTX (XFmode));
27826   emit_insn (gen_addxf3 (tmp, op1, tmp));
27827   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
27828   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
27829
27830   emit_label (label2);
27831 }
27832
27833 /* Output code to perform a Newton-Rhapson approximation of a single precision
27834    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
27835
27836 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, enum machine_mode mode)
27837 {
27838   rtx x0, x1, e0, e1, two;
27839
27840   x0 = gen_reg_rtx (mode);
27841   e0 = gen_reg_rtx (mode);
27842   e1 = gen_reg_rtx (mode);
27843   x1 = gen_reg_rtx (mode);
27844
27845   two = CONST_DOUBLE_FROM_REAL_VALUE (dconst2, SFmode);
27846
27847   if (VECTOR_MODE_P (mode))
27848     two = ix86_build_const_vector (SFmode, true, two);
27849
27850   two = force_reg (mode, two);
27851
27852   /* a / b = a * rcp(b) * (2.0 - b * rcp(b)) */
27853
27854   /* x0 = rcp(b) estimate */
27855   emit_insn (gen_rtx_SET (VOIDmode, x0,
27856                           gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
27857                                           UNSPEC_RCP)));
27858   /* e0 = x0 * b */
27859   emit_insn (gen_rtx_SET (VOIDmode, e0,
27860                           gen_rtx_MULT (mode, x0, b)));
27861   /* e1 = 2. - e0 */
27862   emit_insn (gen_rtx_SET (VOIDmode, e1,
27863                           gen_rtx_MINUS (mode, two, e0)));
27864   /* x1 = x0 * e1 */
27865   emit_insn (gen_rtx_SET (VOIDmode, x1,
27866                           gen_rtx_MULT (mode, x0, e1)));
27867   /* res = a * x1 */
27868   emit_insn (gen_rtx_SET (VOIDmode, res,
27869                           gen_rtx_MULT (mode, a, x1)));
27870 }
27871
27872 /* Output code to perform a Newton-Rhapson approximation of a
27873    single precision floating point [reciprocal] square root.  */
27874
27875 void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
27876                          bool recip)
27877 {
27878   rtx x0, e0, e1, e2, e3, mthree, mhalf;
27879   REAL_VALUE_TYPE r;
27880
27881   x0 = gen_reg_rtx (mode);
27882   e0 = gen_reg_rtx (mode);
27883   e1 = gen_reg_rtx (mode);
27884   e2 = gen_reg_rtx (mode);
27885   e3 = gen_reg_rtx (mode);
27886
27887   real_from_integer (&r, VOIDmode, -3, -1, 0);
27888   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
27889
27890   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
27891   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
27892
27893   if (VECTOR_MODE_P (mode))
27894     {
27895       mthree = ix86_build_const_vector (SFmode, true, mthree);
27896       mhalf = ix86_build_const_vector (SFmode, true, mhalf);
27897     }
27898
27899   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
27900      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
27901
27902   /* x0 = rsqrt(a) estimate */
27903   emit_insn (gen_rtx_SET (VOIDmode, x0,
27904                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
27905                                           UNSPEC_RSQRT)));
27906
27907   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
27908   if (!recip)
27909     {
27910       rtx zero, mask;
27911
27912       zero = gen_reg_rtx (mode);
27913       mask = gen_reg_rtx (mode);
27914
27915       zero = force_reg (mode, CONST0_RTX(mode));
27916       emit_insn (gen_rtx_SET (VOIDmode, mask,
27917                               gen_rtx_NE (mode, zero, a)));
27918
27919       emit_insn (gen_rtx_SET (VOIDmode, x0,
27920                               gen_rtx_AND (mode, x0, mask)));
27921     }
27922
27923   /* e0 = x0 * a */
27924   emit_insn (gen_rtx_SET (VOIDmode, e0,
27925                           gen_rtx_MULT (mode, x0, a)));
27926   /* e1 = e0 * x0 */
27927   emit_insn (gen_rtx_SET (VOIDmode, e1,
27928                           gen_rtx_MULT (mode, e0, x0)));
27929
27930   /* e2 = e1 - 3. */
27931   mthree = force_reg (mode, mthree);
27932   emit_insn (gen_rtx_SET (VOIDmode, e2,
27933                           gen_rtx_PLUS (mode, e1, mthree)));
27934
27935   mhalf = force_reg (mode, mhalf);
27936   if (recip)
27937     /* e3 = -.5 * x0 */
27938     emit_insn (gen_rtx_SET (VOIDmode, e3,
27939                             gen_rtx_MULT (mode, x0, mhalf)));
27940   else
27941     /* e3 = -.5 * e0 */
27942     emit_insn (gen_rtx_SET (VOIDmode, e3,
27943                             gen_rtx_MULT (mode, e0, mhalf)));
27944   /* ret = e2 * e3 */
27945   emit_insn (gen_rtx_SET (VOIDmode, res,
27946                           gen_rtx_MULT (mode, e2, e3)));
27947 }
27948
27949 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
27950
27951 static void ATTRIBUTE_UNUSED
27952 i386_solaris_elf_named_section (const char *name, unsigned int flags,
27953                                 tree decl)
27954 {
27955   /* With Binutils 2.15, the "@unwind" marker must be specified on
27956      every occurrence of the ".eh_frame" section, not just the first
27957      one.  */
27958   if (TARGET_64BIT
27959       && strcmp (name, ".eh_frame") == 0)
27960     {
27961       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
27962                flags & SECTION_WRITE ? "aw" : "a");
27963       return;
27964     }
27965   default_elf_asm_named_section (name, flags, decl);
27966 }
27967
27968 /* Return the mangling of TYPE if it is an extended fundamental type.  */
27969
27970 static const char *
27971 ix86_mangle_type (const_tree type)
27972 {
27973   type = TYPE_MAIN_VARIANT (type);
27974
27975   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
27976       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
27977     return NULL;
27978
27979   switch (TYPE_MODE (type))
27980     {
27981     case TFmode:
27982       /* __float128 is "g".  */
27983       return "g";
27984     case XFmode:
27985       /* "long double" or __float80 is "e".  */
27986       return "e";
27987     default:
27988       return NULL;
27989     }
27990 }
27991
27992 /* For 32-bit code we can save PIC register setup by using
27993    __stack_chk_fail_local hidden function instead of calling
27994    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
27995    register, so it is better to call __stack_chk_fail directly.  */
27996
27997 static tree
27998 ix86_stack_protect_fail (void)
27999 {
28000   return TARGET_64BIT
28001          ? default_external_stack_protect_fail ()
28002          : default_hidden_stack_protect_fail ();
28003 }
28004
28005 /* Select a format to encode pointers in exception handling data.  CODE
28006    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
28007    true if the symbol may be affected by dynamic relocations.
28008
28009    ??? All x86 object file formats are capable of representing this.
28010    After all, the relocation needed is the same as for the call insn.
28011    Whether or not a particular assembler allows us to enter such, I
28012    guess we'll have to see.  */
28013 int
28014 asm_preferred_eh_data_format (int code, int global)
28015 {
28016   if (flag_pic)
28017     {
28018       int type = DW_EH_PE_sdata8;
28019       if (!TARGET_64BIT
28020           || ix86_cmodel == CM_SMALL_PIC
28021           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
28022         type = DW_EH_PE_sdata4;
28023       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
28024     }
28025   if (ix86_cmodel == CM_SMALL
28026       || (ix86_cmodel == CM_MEDIUM && code))
28027     return DW_EH_PE_udata4;
28028   return DW_EH_PE_absptr;
28029 }
28030 \f
28031 /* Expand copysign from SIGN to the positive value ABS_VALUE
28032    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
28033    the sign-bit.  */
28034 static void
28035 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
28036 {
28037   enum machine_mode mode = GET_MODE (sign);
28038   rtx sgn = gen_reg_rtx (mode);
28039   if (mask == NULL_RTX)
28040     {
28041       mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), false);
28042       if (!VECTOR_MODE_P (mode))
28043         {
28044           /* We need to generate a scalar mode mask in this case.  */
28045           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28046           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28047           mask = gen_reg_rtx (mode);
28048           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28049         }
28050     }
28051   else
28052     mask = gen_rtx_NOT (mode, mask);
28053   emit_insn (gen_rtx_SET (VOIDmode, sgn,
28054                           gen_rtx_AND (mode, mask, sign)));
28055   emit_insn (gen_rtx_SET (VOIDmode, result,
28056                           gen_rtx_IOR (mode, abs_value, sgn)));
28057 }
28058
28059 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
28060    mask for masking out the sign-bit is stored in *SMASK, if that is
28061    non-null.  */
28062 static rtx
28063 ix86_expand_sse_fabs (rtx op0, rtx *smask)
28064 {
28065   enum machine_mode mode = GET_MODE (op0);
28066   rtx xa, mask;
28067
28068   xa = gen_reg_rtx (mode);
28069   mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), true);
28070   if (!VECTOR_MODE_P (mode))
28071     {
28072       /* We need to generate a scalar mode mask in this case.  */
28073       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28074       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28075       mask = gen_reg_rtx (mode);
28076       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28077     }
28078   emit_insn (gen_rtx_SET (VOIDmode, xa,
28079                           gen_rtx_AND (mode, op0, mask)));
28080
28081   if (smask)
28082     *smask = mask;
28083
28084   return xa;
28085 }
28086
28087 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
28088    swapping the operands if SWAP_OPERANDS is true.  The expanded
28089    code is a forward jump to a newly created label in case the
28090    comparison is true.  The generated label rtx is returned.  */
28091 static rtx
28092 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
28093                                   bool swap_operands)
28094 {
28095   rtx label, tmp;
28096
28097   if (swap_operands)
28098     {
28099       tmp = op0;
28100       op0 = op1;
28101       op1 = tmp;
28102     }
28103
28104   label = gen_label_rtx ();
28105   tmp = gen_rtx_REG (CCFPUmode, FLAGS_REG);
28106   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28107                           gen_rtx_COMPARE (CCFPUmode, op0, op1)));
28108   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
28109   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
28110                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
28111   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
28112   JUMP_LABEL (tmp) = label;
28113
28114   return label;
28115 }
28116
28117 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
28118    using comparison code CODE.  Operands are swapped for the comparison if
28119    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
28120 static rtx
28121 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
28122                               bool swap_operands)
28123 {
28124   enum machine_mode mode = GET_MODE (op0);
28125   rtx mask = gen_reg_rtx (mode);
28126
28127   if (swap_operands)
28128     {
28129       rtx tmp = op0;
28130       op0 = op1;
28131       op1 = tmp;
28132     }
28133
28134   if (mode == DFmode)
28135     emit_insn (gen_sse2_maskcmpdf3 (mask, op0, op1,
28136                                     gen_rtx_fmt_ee (code, mode, op0, op1)));
28137   else
28138     emit_insn (gen_sse_maskcmpsf3 (mask, op0, op1,
28139                                    gen_rtx_fmt_ee (code, mode, op0, op1)));
28140
28141   return mask;
28142 }
28143
28144 /* Generate and return a rtx of mode MODE for 2**n where n is the number
28145    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
28146 static rtx
28147 ix86_gen_TWO52 (enum machine_mode mode)
28148 {
28149   REAL_VALUE_TYPE TWO52r;
28150   rtx TWO52;
28151
28152   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
28153   TWO52 = const_double_from_real_value (TWO52r, mode);
28154   TWO52 = force_reg (mode, TWO52);
28155
28156   return TWO52;
28157 }
28158
28159 /* Expand SSE sequence for computing lround from OP1 storing
28160    into OP0.  */
28161 void
28162 ix86_expand_lround (rtx op0, rtx op1)
28163 {
28164   /* C code for the stuff we're doing below:
28165        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
28166        return (long)tmp;
28167    */
28168   enum machine_mode mode = GET_MODE (op1);
28169   const struct real_format *fmt;
28170   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
28171   rtx adj;
28172
28173   /* load nextafter (0.5, 0.0) */
28174   fmt = REAL_MODE_FORMAT (mode);
28175   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
28176   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
28177
28178   /* adj = copysign (0.5, op1) */
28179   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
28180   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
28181
28182   /* adj = op1 + adj */
28183   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
28184
28185   /* op0 = (imode)adj */
28186   expand_fix (op0, adj, 0);
28187 }
28188
28189 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
28190    into OPERAND0.  */
28191 void
28192 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
28193 {
28194   /* C code for the stuff we're doing below (for do_floor):
28195         xi = (long)op1;
28196         xi -= (double)xi > op1 ? 1 : 0;
28197         return xi;
28198    */
28199   enum machine_mode fmode = GET_MODE (op1);
28200   enum machine_mode imode = GET_MODE (op0);
28201   rtx ireg, freg, label, tmp;
28202
28203   /* reg = (long)op1 */
28204   ireg = gen_reg_rtx (imode);
28205   expand_fix (ireg, op1, 0);
28206
28207   /* freg = (double)reg */
28208   freg = gen_reg_rtx (fmode);
28209   expand_float (freg, ireg, 0);
28210
28211   /* ireg = (freg > op1) ? ireg - 1 : ireg */
28212   label = ix86_expand_sse_compare_and_jump (UNLE,
28213                                             freg, op1, !do_floor);
28214   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
28215                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
28216   emit_move_insn (ireg, tmp);
28217
28218   emit_label (label);
28219   LABEL_NUSES (label) = 1;
28220
28221   emit_move_insn (op0, ireg);
28222 }
28223
28224 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
28225    result in OPERAND0.  */
28226 void
28227 ix86_expand_rint (rtx operand0, rtx operand1)
28228 {
28229   /* C code for the stuff we're doing below:
28230         xa = fabs (operand1);
28231         if (!isless (xa, 2**52))
28232           return operand1;
28233         xa = xa + 2**52 - 2**52;
28234         return copysign (xa, operand1);
28235    */
28236   enum machine_mode mode = GET_MODE (operand0);
28237   rtx res, xa, label, TWO52, mask;
28238
28239   res = gen_reg_rtx (mode);
28240   emit_move_insn (res, operand1);
28241
28242   /* xa = abs (operand1) */
28243   xa = ix86_expand_sse_fabs (res, &mask);
28244
28245   /* if (!isless (xa, TWO52)) goto label; */
28246   TWO52 = ix86_gen_TWO52 (mode);
28247   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28248
28249   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28250   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28251
28252   ix86_sse_copysign_to_positive (res, xa, res, mask);
28253
28254   emit_label (label);
28255   LABEL_NUSES (label) = 1;
28256
28257   emit_move_insn (operand0, res);
28258 }
28259
28260 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
28261    into OPERAND0.  */
28262 void
28263 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
28264 {
28265   /* C code for the stuff we expand below.
28266         double xa = fabs (x), x2;
28267         if (!isless (xa, TWO52))
28268           return x;
28269         xa = xa + TWO52 - TWO52;
28270         x2 = copysign (xa, x);
28271      Compensate.  Floor:
28272         if (x2 > x)
28273           x2 -= 1;
28274      Compensate.  Ceil:
28275         if (x2 < x)
28276           x2 -= -1;
28277         return x2;
28278    */
28279   enum machine_mode mode = GET_MODE (operand0);
28280   rtx xa, TWO52, tmp, label, one, res, mask;
28281
28282   TWO52 = ix86_gen_TWO52 (mode);
28283
28284   /* Temporary for holding the result, initialized to the input
28285      operand to ease control flow.  */
28286   res = gen_reg_rtx (mode);
28287   emit_move_insn (res, operand1);
28288
28289   /* xa = abs (operand1) */
28290   xa = ix86_expand_sse_fabs (res, &mask);
28291
28292   /* if (!isless (xa, TWO52)) goto label; */
28293   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28294
28295   /* xa = xa + TWO52 - TWO52; */
28296   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28297   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28298
28299   /* xa = copysign (xa, operand1) */
28300   ix86_sse_copysign_to_positive (xa, xa, res, mask);
28301
28302   /* generate 1.0 or -1.0 */
28303   one = force_reg (mode,
28304                    const_double_from_real_value (do_floor
28305                                                  ? dconst1 : dconstm1, mode));
28306
28307   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
28308   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
28309   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28310                           gen_rtx_AND (mode, one, tmp)));
28311   /* We always need to subtract here to preserve signed zero.  */
28312   tmp = expand_simple_binop (mode, MINUS,
28313                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28314   emit_move_insn (res, tmp);
28315
28316   emit_label (label);
28317   LABEL_NUSES (label) = 1;
28318
28319   emit_move_insn (operand0, res);
28320 }
28321
28322 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
28323    into OPERAND0.  */
28324 void
28325 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
28326 {
28327   /* C code for the stuff we expand below.
28328         double xa = fabs (x), x2;
28329         if (!isless (xa, TWO52))
28330           return x;
28331         x2 = (double)(long)x;
28332      Compensate.  Floor:
28333         if (x2 > x)
28334           x2 -= 1;
28335      Compensate.  Ceil:
28336         if (x2 < x)
28337           x2 += 1;
28338         if (HONOR_SIGNED_ZEROS (mode))
28339           return copysign (x2, x);
28340         return x2;
28341    */
28342   enum machine_mode mode = GET_MODE (operand0);
28343   rtx xa, xi, TWO52, tmp, label, one, res, mask;
28344
28345   TWO52 = ix86_gen_TWO52 (mode);
28346
28347   /* Temporary for holding the result, initialized to the input
28348      operand to ease control flow.  */
28349   res = gen_reg_rtx (mode);
28350   emit_move_insn (res, operand1);
28351
28352   /* xa = abs (operand1) */
28353   xa = ix86_expand_sse_fabs (res, &mask);
28354
28355   /* if (!isless (xa, TWO52)) goto label; */
28356   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28357
28358   /* xa = (double)(long)x */
28359   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28360   expand_fix (xi, res, 0);
28361   expand_float (xa, xi, 0);
28362
28363   /* generate 1.0 */
28364   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
28365
28366   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
28367   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
28368   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28369                           gen_rtx_AND (mode, one, tmp)));
28370   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
28371                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28372   emit_move_insn (res, tmp);
28373
28374   if (HONOR_SIGNED_ZEROS (mode))
28375     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
28376
28377   emit_label (label);
28378   LABEL_NUSES (label) = 1;
28379
28380   emit_move_insn (operand0, res);
28381 }
28382
28383 /* Expand SSE sequence for computing round from OPERAND1 storing
28384    into OPERAND0.  Sequence that works without relying on DImode truncation
28385    via cvttsd2siq that is only available on 64bit targets.  */
28386 void
28387 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
28388 {
28389   /* C code for the stuff we expand below.
28390         double xa = fabs (x), xa2, x2;
28391         if (!isless (xa, TWO52))
28392           return x;
28393      Using the absolute value and copying back sign makes
28394      -0.0 -> -0.0 correct.
28395         xa2 = xa + TWO52 - TWO52;
28396      Compensate.
28397         dxa = xa2 - xa;
28398         if (dxa <= -0.5)
28399           xa2 += 1;
28400         else if (dxa > 0.5)
28401           xa2 -= 1;
28402         x2 = copysign (xa2, x);
28403         return x2;
28404    */
28405   enum machine_mode mode = GET_MODE (operand0);
28406   rtx xa, xa2, dxa, TWO52, tmp, label, half, mhalf, one, res, mask;
28407
28408   TWO52 = ix86_gen_TWO52 (mode);
28409
28410   /* Temporary for holding the result, initialized to the input
28411      operand to ease control flow.  */
28412   res = gen_reg_rtx (mode);
28413   emit_move_insn (res, operand1);
28414
28415   /* xa = abs (operand1) */
28416   xa = ix86_expand_sse_fabs (res, &mask);
28417
28418   /* if (!isless (xa, TWO52)) goto label; */
28419   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28420
28421   /* xa2 = xa + TWO52 - TWO52; */
28422   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28423   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
28424
28425   /* dxa = xa2 - xa; */
28426   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
28427
28428   /* generate 0.5, 1.0 and -0.5 */
28429   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
28430   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
28431   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
28432                                0, OPTAB_DIRECT);
28433
28434   /* Compensate.  */
28435   tmp = gen_reg_rtx (mode);
28436   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
28437   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
28438   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28439                           gen_rtx_AND (mode, one, tmp)));
28440   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28441   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
28442   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
28443   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28444                           gen_rtx_AND (mode, one, tmp)));
28445   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28446
28447   /* res = copysign (xa2, operand1) */
28448   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
28449
28450   emit_label (label);
28451   LABEL_NUSES (label) = 1;
28452
28453   emit_move_insn (operand0, res);
28454 }
28455
28456 /* Expand SSE sequence for computing trunc from OPERAND1 storing
28457    into OPERAND0.  */
28458 void
28459 ix86_expand_trunc (rtx operand0, rtx operand1)
28460 {
28461   /* C code for SSE variant we expand below.
28462         double xa = fabs (x), x2;
28463         if (!isless (xa, TWO52))
28464           return x;
28465         x2 = (double)(long)x;
28466         if (HONOR_SIGNED_ZEROS (mode))
28467           return copysign (x2, x);
28468         return x2;
28469    */
28470   enum machine_mode mode = GET_MODE (operand0);
28471   rtx xa, xi, TWO52, label, res, mask;
28472
28473   TWO52 = ix86_gen_TWO52 (mode);
28474
28475   /* Temporary for holding the result, initialized to the input
28476      operand to ease control flow.  */
28477   res = gen_reg_rtx (mode);
28478   emit_move_insn (res, operand1);
28479
28480   /* xa = abs (operand1) */
28481   xa = ix86_expand_sse_fabs (res, &mask);
28482
28483   /* if (!isless (xa, TWO52)) goto label; */
28484   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28485
28486   /* x = (double)(long)x */
28487   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28488   expand_fix (xi, res, 0);
28489   expand_float (res, xi, 0);
28490
28491   if (HONOR_SIGNED_ZEROS (mode))
28492     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
28493
28494   emit_label (label);
28495   LABEL_NUSES (label) = 1;
28496
28497   emit_move_insn (operand0, res);
28498 }
28499
28500 /* Expand SSE sequence for computing trunc from OPERAND1 storing
28501    into OPERAND0.  */
28502 void
28503 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
28504 {
28505   enum machine_mode mode = GET_MODE (operand0);
28506   rtx xa, mask, TWO52, label, one, res, smask, tmp;
28507
28508   /* C code for SSE variant we expand below.
28509         double xa = fabs (x), x2;
28510         if (!isless (xa, TWO52))
28511           return x;
28512         xa2 = xa + TWO52 - TWO52;
28513      Compensate:
28514         if (xa2 > xa)
28515           xa2 -= 1.0;
28516         x2 = copysign (xa2, x);
28517         return x2;
28518    */
28519
28520   TWO52 = ix86_gen_TWO52 (mode);
28521
28522   /* Temporary for holding the result, initialized to the input
28523      operand to ease control flow.  */
28524   res = gen_reg_rtx (mode);
28525   emit_move_insn (res, operand1);
28526
28527   /* xa = abs (operand1) */
28528   xa = ix86_expand_sse_fabs (res, &smask);
28529
28530   /* if (!isless (xa, TWO52)) goto label; */
28531   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28532
28533   /* res = xa + TWO52 - TWO52; */
28534   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28535   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
28536   emit_move_insn (res, tmp);
28537
28538   /* generate 1.0 */
28539   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
28540
28541   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
28542   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
28543   emit_insn (gen_rtx_SET (VOIDmode, mask,
28544                           gen_rtx_AND (mode, mask, one)));
28545   tmp = expand_simple_binop (mode, MINUS,
28546                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
28547   emit_move_insn (res, tmp);
28548
28549   /* res = copysign (res, operand1) */
28550   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
28551
28552   emit_label (label);
28553   LABEL_NUSES (label) = 1;
28554
28555   emit_move_insn (operand0, res);
28556 }
28557
28558 /* Expand SSE sequence for computing round from OPERAND1 storing
28559    into OPERAND0.  */
28560 void
28561 ix86_expand_round (rtx operand0, rtx operand1)
28562 {
28563   /* C code for the stuff we're doing below:
28564         double xa = fabs (x);
28565         if (!isless (xa, TWO52))
28566           return x;
28567         xa = (double)(long)(xa + nextafter (0.5, 0.0));
28568         return copysign (xa, x);
28569    */
28570   enum machine_mode mode = GET_MODE (operand0);
28571   rtx res, TWO52, xa, label, xi, half, mask;
28572   const struct real_format *fmt;
28573   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
28574
28575   /* Temporary for holding the result, initialized to the input
28576      operand to ease control flow.  */
28577   res = gen_reg_rtx (mode);
28578   emit_move_insn (res, operand1);
28579
28580   TWO52 = ix86_gen_TWO52 (mode);
28581   xa = ix86_expand_sse_fabs (res, &mask);
28582   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28583
28584   /* load nextafter (0.5, 0.0) */
28585   fmt = REAL_MODE_FORMAT (mode);
28586   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
28587   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
28588
28589   /* xa = xa + 0.5 */
28590   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
28591   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
28592
28593   /* xa = (double)(int64_t)xa */
28594   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28595   expand_fix (xi, xa, 0);
28596   expand_float (xa, xi, 0);
28597
28598   /* res = copysign (xa, operand1) */
28599   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
28600
28601   emit_label (label);
28602   LABEL_NUSES (label) = 1;
28603
28604   emit_move_insn (operand0, res);
28605 }
28606
28607 \f
28608 /* Validate whether a SSE5 instruction is valid or not.
28609    OPERANDS is the array of operands.
28610    NUM is the number of operands.
28611    USES_OC0 is true if the instruction uses OC0 and provides 4 variants.
28612    NUM_MEMORY is the maximum number of memory operands to accept.  
28613    when COMMUTATIVE is set, operand 1 and 2 can be swapped.  */
28614
28615 bool
28616 ix86_sse5_valid_op_p (rtx operands[], rtx insn ATTRIBUTE_UNUSED, int num,
28617                       bool uses_oc0, int num_memory, bool commutative)
28618 {
28619   int mem_mask;
28620   int mem_count;
28621   int i;
28622
28623   /* Count the number of memory arguments */
28624   mem_mask = 0;
28625   mem_count = 0;
28626   for (i = 0; i < num; i++)
28627     {
28628       enum machine_mode mode = GET_MODE (operands[i]);
28629       if (register_operand (operands[i], mode))
28630         ;
28631
28632       else if (memory_operand (operands[i], mode))
28633         {
28634           mem_mask |= (1 << i);
28635           mem_count++;
28636         }
28637
28638       else
28639         {
28640           rtx pattern = PATTERN (insn);
28641
28642           /* allow 0 for pcmov */
28643           if (GET_CODE (pattern) != SET
28644               || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE
28645               || i < 2
28646               || operands[i] != CONST0_RTX (mode))
28647             return false;
28648         }
28649     }
28650
28651   /* Special case pmacsdq{l,h} where we allow the 3rd argument to be
28652      a memory operation.  */
28653   if (num_memory < 0)
28654     {
28655       num_memory = -num_memory;
28656       if ((mem_mask & (1 << (num-1))) != 0)
28657         {
28658           mem_mask &= ~(1 << (num-1));
28659           mem_count--;
28660         }
28661     }
28662
28663   /* If there were no memory operations, allow the insn */
28664   if (mem_mask == 0)
28665     return true;
28666
28667   /* Do not allow the destination register to be a memory operand.  */
28668   else if (mem_mask & (1 << 0))
28669     return false;
28670
28671   /* If there are too many memory operations, disallow the instruction.  While
28672      the hardware only allows 1 memory reference, before register allocation
28673      for some insns, we allow two memory operations sometimes in order to allow
28674      code like the following to be optimized:
28675
28676         float fmadd (float *a, float *b, float *c) { return (*a * *b) + *c; }
28677
28678     or similar cases that are vectorized into using the fmaddss
28679     instruction.  */
28680   else if (mem_count > num_memory)
28681     return false;
28682
28683   /* Don't allow more than one memory operation if not optimizing.  */
28684   else if (mem_count > 1 && !optimize)
28685     return false;
28686
28687   else if (num == 4 && mem_count == 1)
28688     {
28689       /* formats (destination is the first argument), example fmaddss:
28690          xmm1, xmm1, xmm2, xmm3/mem
28691          xmm1, xmm1, xmm2/mem, xmm3
28692          xmm1, xmm2, xmm3/mem, xmm1
28693          xmm1, xmm2/mem, xmm3, xmm1 */
28694       if (uses_oc0)
28695         return ((mem_mask == (1 << 1))
28696                 || (mem_mask == (1 << 2))
28697                 || (mem_mask == (1 << 3)));
28698
28699       /* format, example pmacsdd:
28700          xmm1, xmm2, xmm3/mem, xmm1 */
28701       if (commutative)
28702         return (mem_mask == (1 << 2) || mem_mask == (1 << 1));
28703       else
28704         return (mem_mask == (1 << 2));
28705     }
28706
28707   else if (num == 4 && num_memory == 2)
28708     {
28709       /* If there are two memory operations, we can load one of the memory ops
28710          into the destination register.  This is for optimizing the
28711          multiply/add ops, which the combiner has optimized both the multiply
28712          and the add insns to have a memory operation.  We have to be careful
28713          that the destination doesn't overlap with the inputs.  */
28714       rtx op0 = operands[0];
28715
28716       if (reg_mentioned_p (op0, operands[1])
28717           || reg_mentioned_p (op0, operands[2])
28718           || reg_mentioned_p (op0, operands[3]))
28719         return false;
28720
28721       /* formats (destination is the first argument), example fmaddss:
28722          xmm1, xmm1, xmm2, xmm3/mem
28723          xmm1, xmm1, xmm2/mem, xmm3
28724          xmm1, xmm2, xmm3/mem, xmm1
28725          xmm1, xmm2/mem, xmm3, xmm1
28726
28727          For the oc0 case, we will load either operands[1] or operands[3] into
28728          operands[0], so any combination of 2 memory operands is ok.  */
28729       if (uses_oc0)
28730         return true;
28731
28732       /* format, example pmacsdd:
28733          xmm1, xmm2, xmm3/mem, xmm1
28734
28735          For the integer multiply/add instructions be more restrictive and
28736          require operands[2] and operands[3] to be the memory operands.  */
28737       if (commutative)
28738         return (mem_mask == ((1 << 1) | (1 << 3)) || ((1 << 2) | (1 << 3)));
28739       else
28740         return (mem_mask == ((1 << 2) | (1 << 3)));
28741     }
28742
28743   else if (num == 3 && num_memory == 1)
28744     {
28745       /* formats, example protb:
28746          xmm1, xmm2, xmm3/mem
28747          xmm1, xmm2/mem, xmm3 */
28748       if (uses_oc0)
28749         return ((mem_mask == (1 << 1)) || (mem_mask == (1 << 2)));
28750
28751       /* format, example comeq:
28752          xmm1, xmm2, xmm3/mem */
28753       else
28754         return (mem_mask == (1 << 2));
28755     }
28756
28757   else
28758     gcc_unreachable ();
28759
28760   return false;
28761 }
28762
28763 \f
28764 /* Fixup an SSE5 instruction that has 2 memory input references into a form the
28765    hardware will allow by using the destination register to load one of the
28766    memory operations.  Presently this is used by the multiply/add routines to
28767    allow 2 memory references.  */
28768
28769 void
28770 ix86_expand_sse5_multiple_memory (rtx operands[],
28771                                   int num,
28772                                   enum machine_mode mode)
28773 {
28774   rtx op0 = operands[0];
28775   if (num != 4
28776       || memory_operand (op0, mode)
28777       || reg_mentioned_p (op0, operands[1])
28778       || reg_mentioned_p (op0, operands[2])
28779       || reg_mentioned_p (op0, operands[3]))
28780     gcc_unreachable ();
28781
28782   /* For 2 memory operands, pick either operands[1] or operands[3] to move into
28783      the destination register.  */
28784   if (memory_operand (operands[1], mode))
28785     {
28786       emit_move_insn (op0, operands[1]);
28787       operands[1] = op0;
28788     }
28789   else if (memory_operand (operands[3], mode))
28790     {
28791       emit_move_insn (op0, operands[3]);
28792       operands[3] = op0;
28793     }
28794   else
28795     gcc_unreachable ();
28796
28797   return;
28798 }
28799
28800 \f
28801 /* Table of valid machine attributes.  */
28802 static const struct attribute_spec ix86_attribute_table[] =
28803 {
28804   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
28805   /* Stdcall attribute says callee is responsible for popping arguments
28806      if they are not variable.  */
28807   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute },
28808   /* Fastcall attribute says callee is responsible for popping arguments
28809      if they are not variable.  */
28810   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute },
28811   /* Cdecl attribute says the callee is a normal C declaration */
28812   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute },
28813   /* Regparm attribute specifies how many integer arguments are to be
28814      passed in registers.  */
28815   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute },
28816   /* Sseregparm attribute says we are using x86_64 calling conventions
28817      for FP arguments.  */
28818   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute },
28819   /* force_align_arg_pointer says this function realigns the stack at entry.  */
28820   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
28821     false, true,  true, ix86_handle_cconv_attribute },
28822 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
28823   { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
28824   { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
28825   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute },
28826 #endif
28827   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
28828   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
28829 #ifdef SUBTARGET_ATTRIBUTE_TABLE
28830   SUBTARGET_ATTRIBUTE_TABLE,
28831 #endif
28832   /* ms_abi and sysv_abi calling convention function attributes.  */
28833   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
28834   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
28835   /* End element.  */
28836   { NULL,        0, 0, false, false, false, NULL }
28837 };
28838
28839 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
28840 static int
28841 x86_builtin_vectorization_cost (bool runtime_test)
28842 {
28843   /* If the branch of the runtime test is taken - i.e. - the vectorized
28844      version is skipped - this incurs a misprediction cost (because the
28845      vectorized version is expected to be the fall-through).  So we subtract
28846      the latency of a mispredicted branch from the costs that are incured
28847      when the vectorized version is executed.
28848
28849      TODO: The values in individual target tables have to be tuned or new
28850      fields may be needed. For eg. on K8, the default branch path is the
28851      not-taken path. If the taken path is predicted correctly, the minimum
28852      penalty of going down the taken-path is 1 cycle. If the taken-path is
28853      not predicted correctly, then the minimum penalty is 10 cycles.  */
28854
28855   if (runtime_test)
28856     {
28857       return (-(ix86_cost->cond_taken_branch_cost));
28858     }
28859   else
28860     return 0;
28861 }
28862
28863 /* This function returns the calling abi specific va_list type node.
28864    It returns  the FNDECL specific va_list type.  */
28865
28866 tree
28867 ix86_fn_abi_va_list (tree fndecl)
28868 {
28869   int abi;
28870
28871   if (!TARGET_64BIT)
28872     return va_list_type_node;
28873   gcc_assert (fndecl != NULL_TREE);
28874   abi = ix86_function_abi ((const_tree) fndecl);
28875
28876   if (abi == MS_ABI)
28877     return ms_va_list_type_node;
28878   else
28879     return sysv_va_list_type_node;
28880 }
28881
28882 /* Returns the canonical va_list type specified by TYPE. If there
28883    is no valid TYPE provided, it return NULL_TREE.  */
28884
28885 tree
28886 ix86_canonical_va_list_type (tree type)
28887 {
28888   tree wtype, htype;
28889
28890   /* Resolve references and pointers to va_list type.  */
28891   if (INDIRECT_REF_P (type))
28892     type = TREE_TYPE (type);
28893   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
28894     type = TREE_TYPE (type);
28895
28896   if (TARGET_64BIT)
28897     {
28898       wtype = va_list_type_node;
28899           gcc_assert (wtype != NULL_TREE);
28900       htype = type;
28901       if (TREE_CODE (wtype) == ARRAY_TYPE)
28902         {
28903           /* If va_list is an array type, the argument may have decayed
28904              to a pointer type, e.g. by being passed to another function.
28905              In that case, unwrap both types so that we can compare the
28906              underlying records.  */
28907           if (TREE_CODE (htype) == ARRAY_TYPE
28908               || POINTER_TYPE_P (htype))
28909             {
28910               wtype = TREE_TYPE (wtype);
28911               htype = TREE_TYPE (htype);
28912             }
28913         }
28914       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
28915         return va_list_type_node;
28916       wtype = sysv_va_list_type_node;
28917           gcc_assert (wtype != NULL_TREE);
28918       htype = type;
28919       if (TREE_CODE (wtype) == ARRAY_TYPE)
28920         {
28921           /* If va_list is an array type, the argument may have decayed
28922              to a pointer type, e.g. by being passed to another function.
28923              In that case, unwrap both types so that we can compare the
28924              underlying records.  */
28925           if (TREE_CODE (htype) == ARRAY_TYPE
28926               || POINTER_TYPE_P (htype))
28927             {
28928               wtype = TREE_TYPE (wtype);
28929               htype = TREE_TYPE (htype);
28930             }
28931         }
28932       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
28933         return sysv_va_list_type_node;
28934       wtype = ms_va_list_type_node;
28935           gcc_assert (wtype != NULL_TREE);
28936       htype = type;
28937       if (TREE_CODE (wtype) == ARRAY_TYPE)
28938         {
28939           /* If va_list is an array type, the argument may have decayed
28940              to a pointer type, e.g. by being passed to another function.
28941              In that case, unwrap both types so that we can compare the
28942              underlying records.  */
28943           if (TREE_CODE (htype) == ARRAY_TYPE
28944               || POINTER_TYPE_P (htype))
28945             {
28946               wtype = TREE_TYPE (wtype);
28947               htype = TREE_TYPE (htype);
28948             }
28949         }
28950       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
28951         return ms_va_list_type_node;
28952       return NULL_TREE;
28953     }
28954   return std_canonical_va_list_type (type);
28955 }
28956
28957 /* Iterate through the target-specific builtin types for va_list.
28958     IDX denotes the iterator, *PTREE is set to the result type of
28959     the va_list builtin, and *PNAME to its internal type.
28960     Returns zero if there is no element for this index, otherwise
28961     IDX should be increased upon the next call.
28962     Note, do not iterate a base builtin's name like __builtin_va_list.
28963     Used from c_common_nodes_and_builtins.  */
28964
28965 int
28966 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
28967 {
28968   if (!TARGET_64BIT)
28969     return 0;
28970   switch (idx) {
28971   case 0:
28972     *ptree = ms_va_list_type_node;
28973     *pname = "__builtin_ms_va_list";
28974     break;
28975   case 1:
28976     *ptree = sysv_va_list_type_node;
28977     *pname = "__builtin_sysv_va_list";
28978     break;
28979   default:
28980     return 0;
28981   }
28982   return 1;
28983 }
28984
28985 /* Initialize the GCC target structure.  */
28986 #undef TARGET_RETURN_IN_MEMORY
28987 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
28988
28989 #undef TARGET_ATTRIBUTE_TABLE
28990 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
28991 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
28992 #  undef TARGET_MERGE_DECL_ATTRIBUTES
28993 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
28994 #endif
28995
28996 #undef TARGET_COMP_TYPE_ATTRIBUTES
28997 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
28998
28999 #undef TARGET_INIT_BUILTINS
29000 #define TARGET_INIT_BUILTINS ix86_init_builtins
29001 #undef TARGET_EXPAND_BUILTIN
29002 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
29003
29004 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
29005 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
29006   ix86_builtin_vectorized_function
29007
29008 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
29009 #define TARGET_VECTORIZE_BUILTIN_CONVERSION ix86_vectorize_builtin_conversion
29010
29011 #undef TARGET_BUILTIN_RECIPROCAL
29012 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
29013
29014 #undef TARGET_ASM_FUNCTION_EPILOGUE
29015 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
29016
29017 #undef TARGET_ENCODE_SECTION_INFO
29018 #ifndef SUBTARGET_ENCODE_SECTION_INFO
29019 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
29020 #else
29021 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
29022 #endif
29023
29024 #undef TARGET_ASM_OPEN_PAREN
29025 #define TARGET_ASM_OPEN_PAREN ""
29026 #undef TARGET_ASM_CLOSE_PAREN
29027 #define TARGET_ASM_CLOSE_PAREN ""
29028
29029 #undef TARGET_ASM_ALIGNED_HI_OP
29030 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
29031 #undef TARGET_ASM_ALIGNED_SI_OP
29032 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
29033 #ifdef ASM_QUAD
29034 #undef TARGET_ASM_ALIGNED_DI_OP
29035 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
29036 #endif
29037
29038 #undef TARGET_ASM_UNALIGNED_HI_OP
29039 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
29040 #undef TARGET_ASM_UNALIGNED_SI_OP
29041 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
29042 #undef TARGET_ASM_UNALIGNED_DI_OP
29043 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
29044
29045 #undef TARGET_SCHED_ADJUST_COST
29046 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
29047 #undef TARGET_SCHED_ISSUE_RATE
29048 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
29049 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
29050 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
29051   ia32_multipass_dfa_lookahead
29052
29053 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
29054 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
29055
29056 #ifdef HAVE_AS_TLS
29057 #undef TARGET_HAVE_TLS
29058 #define TARGET_HAVE_TLS true
29059 #endif
29060 #undef TARGET_CANNOT_FORCE_CONST_MEM
29061 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
29062 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
29063 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
29064
29065 #undef TARGET_DELEGITIMIZE_ADDRESS
29066 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
29067
29068 #undef TARGET_MS_BITFIELD_LAYOUT_P
29069 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
29070
29071 #if TARGET_MACHO
29072 #undef TARGET_BINDS_LOCAL_P
29073 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
29074 #endif
29075 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29076 #undef TARGET_BINDS_LOCAL_P
29077 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
29078 #endif
29079
29080 #undef TARGET_ASM_OUTPUT_MI_THUNK
29081 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
29082 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
29083 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
29084
29085 #undef TARGET_ASM_FILE_START
29086 #define TARGET_ASM_FILE_START x86_file_start
29087
29088 #undef TARGET_DEFAULT_TARGET_FLAGS
29089 #define TARGET_DEFAULT_TARGET_FLAGS     \
29090   (TARGET_DEFAULT                       \
29091    | TARGET_SUBTARGET_DEFAULT           \
29092    | TARGET_TLS_DIRECT_SEG_REFS_DEFAULT)
29093
29094 #undef TARGET_HANDLE_OPTION
29095 #define TARGET_HANDLE_OPTION ix86_handle_option
29096
29097 #undef TARGET_RTX_COSTS
29098 #define TARGET_RTX_COSTS ix86_rtx_costs
29099 #undef TARGET_ADDRESS_COST
29100 #define TARGET_ADDRESS_COST ix86_address_cost
29101
29102 #undef TARGET_FIXED_CONDITION_CODE_REGS
29103 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
29104 #undef TARGET_CC_MODES_COMPATIBLE
29105 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
29106
29107 #undef TARGET_MACHINE_DEPENDENT_REORG
29108 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
29109
29110 #undef TARGET_BUILD_BUILTIN_VA_LIST
29111 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
29112
29113 #undef TARGET_FN_ABI_VA_LIST
29114 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
29115
29116 #undef TARGET_CANONICAL_VA_LIST_TYPE
29117 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
29118
29119 #undef TARGET_EXPAND_BUILTIN_VA_START
29120 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
29121
29122 #undef TARGET_MD_ASM_CLOBBERS
29123 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
29124
29125 #undef TARGET_PROMOTE_PROTOTYPES
29126 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
29127 #undef TARGET_STRUCT_VALUE_RTX
29128 #define TARGET_STRUCT_VALUE_RTX ix86_struct_value_rtx
29129 #undef TARGET_SETUP_INCOMING_VARARGS
29130 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
29131 #undef TARGET_MUST_PASS_IN_STACK
29132 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
29133 #undef TARGET_PASS_BY_REFERENCE
29134 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
29135 #undef TARGET_INTERNAL_ARG_POINTER
29136 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
29137 #undef TARGET_UPDATE_STACK_BOUNDARY
29138 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
29139 #undef TARGET_GET_DRAP_RTX
29140 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
29141 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
29142 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC ix86_dwarf_handle_frame_unspec
29143 #undef TARGET_STRICT_ARGUMENT_NAMING
29144 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
29145
29146 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
29147 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
29148
29149 #undef TARGET_SCALAR_MODE_SUPPORTED_P
29150 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
29151
29152 #undef TARGET_VECTOR_MODE_SUPPORTED_P
29153 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
29154
29155 #undef TARGET_C_MODE_FOR_SUFFIX
29156 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
29157
29158 #ifdef HAVE_AS_TLS
29159 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
29160 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
29161 #endif
29162
29163 #ifdef SUBTARGET_INSERT_ATTRIBUTES
29164 #undef TARGET_INSERT_ATTRIBUTES
29165 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
29166 #endif
29167
29168 #undef TARGET_MANGLE_TYPE
29169 #define TARGET_MANGLE_TYPE ix86_mangle_type
29170
29171 #undef TARGET_STACK_PROTECT_FAIL
29172 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
29173
29174 #undef TARGET_FUNCTION_VALUE
29175 #define TARGET_FUNCTION_VALUE ix86_function_value
29176
29177 #undef TARGET_SECONDARY_RELOAD
29178 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
29179
29180 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
29181 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST x86_builtin_vectorization_cost
29182
29183 #undef TARGET_SET_CURRENT_FUNCTION
29184 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
29185
29186 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
29187 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
29188
29189 #undef TARGET_OPTION_SAVE
29190 #define TARGET_OPTION_SAVE ix86_function_specific_save
29191
29192 #undef TARGET_OPTION_RESTORE
29193 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
29194
29195 #undef TARGET_OPTION_PRINT
29196 #define TARGET_OPTION_PRINT ix86_function_specific_print
29197
29198 #undef TARGET_OPTION_CAN_INLINE_P
29199 #define TARGET_OPTION_CAN_INLINE_P ix86_can_inline_p
29200
29201 struct gcc_target targetm = TARGET_INITIALIZER;
29202 \f
29203 #include "gt-i386.h"