OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.c
1 /* Subroutines used for code generation on IA-32.
2    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3    2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "tm_p.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "real.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "output.h"
35 #include "insn-codes.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "c-common.h"
39 #include "except.h"
40 #include "function.h"
41 #include "recog.h"
42 #include "expr.h"
43 #include "optabs.h"
44 #include "toplev.h"
45 #include "basic-block.h"
46 #include "ggc.h"
47 #include "target.h"
48 #include "target-def.h"
49 #include "langhooks.h"
50 #include "cgraph.h"
51 #include "gimple.h"
52 #include "dwarf2.h"
53 #include "df.h"
54 #include "tm-constrs.h"
55 #include "params.h"
56 #include "cselib.h"
57
58 static int x86_builtin_vectorization_cost (bool);
59 static rtx legitimize_dllimport_symbol (rtx, bool);
60
61 #ifndef CHECK_STACK_LIMIT
62 #define CHECK_STACK_LIMIT (-1)
63 #endif
64
65 /* Return index of given mode in mult and division cost tables.  */
66 #define MODE_INDEX(mode)                                        \
67   ((mode) == QImode ? 0                                         \
68    : (mode) == HImode ? 1                                       \
69    : (mode) == SImode ? 2                                       \
70    : (mode) == DImode ? 3                                       \
71    : 4)
72
73 /* Processor costs (relative to an add) */
74 /* We assume COSTS_N_INSNS is defined as (N)*4 and an addition is 2 bytes.  */
75 #define COSTS_N_BYTES(N) ((N) * 2)
76
77 #define DUMMY_STRINGOP_ALGS {libcall, {{-1, libcall}}}
78
79 const
80 struct processor_costs ix86_size_cost = {/* costs for tuning for size */
81   COSTS_N_BYTES (2),                    /* cost of an add instruction */
82   COSTS_N_BYTES (3),                    /* cost of a lea instruction */
83   COSTS_N_BYTES (2),                    /* variable shift costs */
84   COSTS_N_BYTES (3),                    /* constant shift costs */
85   {COSTS_N_BYTES (3),                   /* cost of starting multiply for QI */
86    COSTS_N_BYTES (3),                   /*                               HI */
87    COSTS_N_BYTES (3),                   /*                               SI */
88    COSTS_N_BYTES (3),                   /*                               DI */
89    COSTS_N_BYTES (5)},                  /*                            other */
90   0,                                    /* cost of multiply per each bit set */
91   {COSTS_N_BYTES (3),                   /* cost of a divide/mod for QI */
92    COSTS_N_BYTES (3),                   /*                          HI */
93    COSTS_N_BYTES (3),                   /*                          SI */
94    COSTS_N_BYTES (3),                   /*                          DI */
95    COSTS_N_BYTES (5)},                  /*                       other */
96   COSTS_N_BYTES (3),                    /* cost of movsx */
97   COSTS_N_BYTES (3),                    /* cost of movzx */
98   0,                                    /* "large" insn */
99   2,                                    /* MOVE_RATIO */
100   2,                                    /* cost for loading QImode using movzbl */
101   {2, 2, 2},                            /* cost of loading integer registers
102                                            in QImode, HImode and SImode.
103                                            Relative to reg-reg move (2).  */
104   {2, 2, 2},                            /* cost of storing integer registers */
105   2,                                    /* cost of reg,reg fld/fst */
106   {2, 2, 2},                            /* cost of loading fp registers
107                                            in SFmode, DFmode and XFmode */
108   {2, 2, 2},                            /* cost of storing fp registers
109                                            in SFmode, DFmode and XFmode */
110   3,                                    /* cost of moving MMX register */
111   {3, 3},                               /* cost of loading MMX registers
112                                            in SImode and DImode */
113   {3, 3},                               /* cost of storing MMX registers
114                                            in SImode and DImode */
115   3,                                    /* cost of moving SSE register */
116   {3, 3, 3},                            /* cost of loading SSE registers
117                                            in SImode, DImode and TImode */
118   {3, 3, 3},                            /* cost of storing SSE registers
119                                            in SImode, DImode and TImode */
120   3,                                    /* MMX or SSE register to integer */
121   0,                                    /* size of l1 cache  */
122   0,                                    /* size of l2 cache  */
123   0,                                    /* size of prefetch block */
124   0,                                    /* number of parallel prefetches */
125   2,                                    /* Branch cost */
126   COSTS_N_BYTES (2),                    /* cost of FADD and FSUB insns.  */
127   COSTS_N_BYTES (2),                    /* cost of FMUL instruction.  */
128   COSTS_N_BYTES (2),                    /* cost of FDIV instruction.  */
129   COSTS_N_BYTES (2),                    /* cost of FABS instruction.  */
130   COSTS_N_BYTES (2),                    /* cost of FCHS instruction.  */
131   COSTS_N_BYTES (2),                    /* cost of FSQRT instruction.  */
132   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
133    {rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}}},
134   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
135    {rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}}},
136   1,                                    /* scalar_stmt_cost.  */
137   1,                                    /* scalar load_cost.  */
138   1,                                    /* scalar_store_cost.  */
139   1,                                    /* vec_stmt_cost.  */
140   1,                                    /* vec_to_scalar_cost.  */
141   1,                                    /* scalar_to_vec_cost.  */
142   1,                                    /* vec_align_load_cost.  */
143   1,                                    /* vec_unalign_load_cost.  */
144   1,                                    /* vec_store_cost.  */
145   1,                                    /* cond_taken_branch_cost.  */
146   1,                                    /* cond_not_taken_branch_cost.  */
147 };
148
149 /* Processor costs (relative to an add) */
150 static const
151 struct processor_costs i386_cost = {    /* 386 specific costs */
152   COSTS_N_INSNS (1),                    /* cost of an add instruction */
153   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
154   COSTS_N_INSNS (3),                    /* variable shift costs */
155   COSTS_N_INSNS (2),                    /* constant shift costs */
156   {COSTS_N_INSNS (6),                   /* cost of starting multiply for QI */
157    COSTS_N_INSNS (6),                   /*                               HI */
158    COSTS_N_INSNS (6),                   /*                               SI */
159    COSTS_N_INSNS (6),                   /*                               DI */
160    COSTS_N_INSNS (6)},                  /*                               other */
161   COSTS_N_INSNS (1),                    /* cost of multiply per each bit set */
162   {COSTS_N_INSNS (23),                  /* cost of a divide/mod for QI */
163    COSTS_N_INSNS (23),                  /*                          HI */
164    COSTS_N_INSNS (23),                  /*                          SI */
165    COSTS_N_INSNS (23),                  /*                          DI */
166    COSTS_N_INSNS (23)},                 /*                          other */
167   COSTS_N_INSNS (3),                    /* cost of movsx */
168   COSTS_N_INSNS (2),                    /* cost of movzx */
169   15,                                   /* "large" insn */
170   3,                                    /* MOVE_RATIO */
171   4,                                    /* cost for loading QImode using movzbl */
172   {2, 4, 2},                            /* cost of loading integer registers
173                                            in QImode, HImode and SImode.
174                                            Relative to reg-reg move (2).  */
175   {2, 4, 2},                            /* cost of storing integer registers */
176   2,                                    /* cost of reg,reg fld/fst */
177   {8, 8, 8},                            /* cost of loading fp registers
178                                            in SFmode, DFmode and XFmode */
179   {8, 8, 8},                            /* cost of storing fp registers
180                                            in SFmode, DFmode and XFmode */
181   2,                                    /* cost of moving MMX register */
182   {4, 8},                               /* cost of loading MMX registers
183                                            in SImode and DImode */
184   {4, 8},                               /* cost of storing MMX registers
185                                            in SImode and DImode */
186   2,                                    /* cost of moving SSE register */
187   {4, 8, 16},                           /* cost of loading SSE registers
188                                            in SImode, DImode and TImode */
189   {4, 8, 16},                           /* cost of storing SSE registers
190                                            in SImode, DImode and TImode */
191   3,                                    /* MMX or SSE register to integer */
192   0,                                    /* size of l1 cache  */
193   0,                                    /* size of l2 cache  */
194   0,                                    /* size of prefetch block */
195   0,                                    /* number of parallel prefetches */
196   1,                                    /* Branch cost */
197   COSTS_N_INSNS (23),                   /* cost of FADD and FSUB insns.  */
198   COSTS_N_INSNS (27),                   /* cost of FMUL instruction.  */
199   COSTS_N_INSNS (88),                   /* cost of FDIV instruction.  */
200   COSTS_N_INSNS (22),                   /* cost of FABS instruction.  */
201   COSTS_N_INSNS (24),                   /* cost of FCHS instruction.  */
202   COSTS_N_INSNS (122),                  /* cost of FSQRT instruction.  */
203   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
204    DUMMY_STRINGOP_ALGS},
205   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
206    DUMMY_STRINGOP_ALGS},
207   1,                                    /* scalar_stmt_cost.  */
208   1,                                    /* scalar load_cost.  */
209   1,                                    /* scalar_store_cost.  */
210   1,                                    /* vec_stmt_cost.  */
211   1,                                    /* vec_to_scalar_cost.  */
212   1,                                    /* scalar_to_vec_cost.  */
213   1,                                    /* vec_align_load_cost.  */
214   2,                                    /* vec_unalign_load_cost.  */
215   1,                                    /* vec_store_cost.  */
216   3,                                    /* cond_taken_branch_cost.  */
217   1,                                    /* cond_not_taken_branch_cost.  */
218 };
219
220 static const
221 struct processor_costs i486_cost = {    /* 486 specific costs */
222   COSTS_N_INSNS (1),                    /* cost of an add instruction */
223   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
224   COSTS_N_INSNS (3),                    /* variable shift costs */
225   COSTS_N_INSNS (2),                    /* constant shift costs */
226   {COSTS_N_INSNS (12),                  /* cost of starting multiply for QI */
227    COSTS_N_INSNS (12),                  /*                               HI */
228    COSTS_N_INSNS (12),                  /*                               SI */
229    COSTS_N_INSNS (12),                  /*                               DI */
230    COSTS_N_INSNS (12)},                 /*                               other */
231   1,                                    /* cost of multiply per each bit set */
232   {COSTS_N_INSNS (40),                  /* cost of a divide/mod for QI */
233    COSTS_N_INSNS (40),                  /*                          HI */
234    COSTS_N_INSNS (40),                  /*                          SI */
235    COSTS_N_INSNS (40),                  /*                          DI */
236    COSTS_N_INSNS (40)},                 /*                          other */
237   COSTS_N_INSNS (3),                    /* cost of movsx */
238   COSTS_N_INSNS (2),                    /* cost of movzx */
239   15,                                   /* "large" insn */
240   3,                                    /* MOVE_RATIO */
241   4,                                    /* cost for loading QImode using movzbl */
242   {2, 4, 2},                            /* cost of loading integer registers
243                                            in QImode, HImode and SImode.
244                                            Relative to reg-reg move (2).  */
245   {2, 4, 2},                            /* cost of storing integer registers */
246   2,                                    /* cost of reg,reg fld/fst */
247   {8, 8, 8},                            /* cost of loading fp registers
248                                            in SFmode, DFmode and XFmode */
249   {8, 8, 8},                            /* cost of storing fp registers
250                                            in SFmode, DFmode and XFmode */
251   2,                                    /* cost of moving MMX register */
252   {4, 8},                               /* cost of loading MMX registers
253                                            in SImode and DImode */
254   {4, 8},                               /* cost of storing MMX registers
255                                            in SImode and DImode */
256   2,                                    /* cost of moving SSE register */
257   {4, 8, 16},                           /* cost of loading SSE registers
258                                            in SImode, DImode and TImode */
259   {4, 8, 16},                           /* cost of storing SSE registers
260                                            in SImode, DImode and TImode */
261   3,                                    /* MMX or SSE register to integer */
262   4,                                    /* size of l1 cache.  486 has 8kB cache
263                                            shared for code and data, so 4kB is
264                                            not really precise.  */
265   4,                                    /* size of l2 cache  */
266   0,                                    /* size of prefetch block */
267   0,                                    /* number of parallel prefetches */
268   1,                                    /* Branch cost */
269   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
270   COSTS_N_INSNS (16),                   /* cost of FMUL instruction.  */
271   COSTS_N_INSNS (73),                   /* cost of FDIV instruction.  */
272   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
273   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
274   COSTS_N_INSNS (83),                   /* cost of FSQRT instruction.  */
275   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
276    DUMMY_STRINGOP_ALGS},
277   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
278    DUMMY_STRINGOP_ALGS},
279   1,                                    /* scalar_stmt_cost.  */
280   1,                                    /* scalar load_cost.  */
281   1,                                    /* scalar_store_cost.  */
282   1,                                    /* vec_stmt_cost.  */
283   1,                                    /* vec_to_scalar_cost.  */
284   1,                                    /* scalar_to_vec_cost.  */
285   1,                                    /* vec_align_load_cost.  */
286   2,                                    /* vec_unalign_load_cost.  */
287   1,                                    /* vec_store_cost.  */
288   3,                                    /* cond_taken_branch_cost.  */
289   1,                                    /* cond_not_taken_branch_cost.  */
290 };
291
292 static const
293 struct processor_costs pentium_cost = {
294   COSTS_N_INSNS (1),                    /* cost of an add instruction */
295   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
296   COSTS_N_INSNS (4),                    /* variable shift costs */
297   COSTS_N_INSNS (1),                    /* constant shift costs */
298   {COSTS_N_INSNS (11),                  /* cost of starting multiply for QI */
299    COSTS_N_INSNS (11),                  /*                               HI */
300    COSTS_N_INSNS (11),                  /*                               SI */
301    COSTS_N_INSNS (11),                  /*                               DI */
302    COSTS_N_INSNS (11)},                 /*                               other */
303   0,                                    /* cost of multiply per each bit set */
304   {COSTS_N_INSNS (25),                  /* cost of a divide/mod for QI */
305    COSTS_N_INSNS (25),                  /*                          HI */
306    COSTS_N_INSNS (25),                  /*                          SI */
307    COSTS_N_INSNS (25),                  /*                          DI */
308    COSTS_N_INSNS (25)},                 /*                          other */
309   COSTS_N_INSNS (3),                    /* cost of movsx */
310   COSTS_N_INSNS (2),                    /* cost of movzx */
311   8,                                    /* "large" insn */
312   6,                                    /* MOVE_RATIO */
313   6,                                    /* cost for loading QImode using movzbl */
314   {2, 4, 2},                            /* cost of loading integer registers
315                                            in QImode, HImode and SImode.
316                                            Relative to reg-reg move (2).  */
317   {2, 4, 2},                            /* cost of storing integer registers */
318   2,                                    /* cost of reg,reg fld/fst */
319   {2, 2, 6},                            /* cost of loading fp registers
320                                            in SFmode, DFmode and XFmode */
321   {4, 4, 6},                            /* cost of storing fp registers
322                                            in SFmode, DFmode and XFmode */
323   8,                                    /* cost of moving MMX register */
324   {8, 8},                               /* cost of loading MMX registers
325                                            in SImode and DImode */
326   {8, 8},                               /* cost of storing MMX registers
327                                            in SImode and DImode */
328   2,                                    /* cost of moving SSE register */
329   {4, 8, 16},                           /* cost of loading SSE registers
330                                            in SImode, DImode and TImode */
331   {4, 8, 16},                           /* cost of storing SSE registers
332                                            in SImode, DImode and TImode */
333   3,                                    /* MMX or SSE register to integer */
334   8,                                    /* size of l1 cache.  */
335   8,                                    /* size of l2 cache  */
336   0,                                    /* size of prefetch block */
337   0,                                    /* number of parallel prefetches */
338   2,                                    /* Branch cost */
339   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
340   COSTS_N_INSNS (3),                    /* cost of FMUL instruction.  */
341   COSTS_N_INSNS (39),                   /* cost of FDIV instruction.  */
342   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
343   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
344   COSTS_N_INSNS (70),                   /* cost of FSQRT instruction.  */
345   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
346    DUMMY_STRINGOP_ALGS},
347   {{libcall, {{-1, rep_prefix_4_byte}}},
348    DUMMY_STRINGOP_ALGS},
349   1,                                    /* scalar_stmt_cost.  */
350   1,                                    /* scalar load_cost.  */
351   1,                                    /* scalar_store_cost.  */
352   1,                                    /* vec_stmt_cost.  */
353   1,                                    /* vec_to_scalar_cost.  */
354   1,                                    /* scalar_to_vec_cost.  */
355   1,                                    /* vec_align_load_cost.  */
356   2,                                    /* vec_unalign_load_cost.  */
357   1,                                    /* vec_store_cost.  */
358   3,                                    /* cond_taken_branch_cost.  */
359   1,                                    /* cond_not_taken_branch_cost.  */
360 };
361
362 static const
363 struct processor_costs pentiumpro_cost = {
364   COSTS_N_INSNS (1),                    /* cost of an add instruction */
365   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
366   COSTS_N_INSNS (1),                    /* variable shift costs */
367   COSTS_N_INSNS (1),                    /* constant shift costs */
368   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
369    COSTS_N_INSNS (4),                   /*                               HI */
370    COSTS_N_INSNS (4),                   /*                               SI */
371    COSTS_N_INSNS (4),                   /*                               DI */
372    COSTS_N_INSNS (4)},                  /*                               other */
373   0,                                    /* cost of multiply per each bit set */
374   {COSTS_N_INSNS (17),                  /* cost of a divide/mod for QI */
375    COSTS_N_INSNS (17),                  /*                          HI */
376    COSTS_N_INSNS (17),                  /*                          SI */
377    COSTS_N_INSNS (17),                  /*                          DI */
378    COSTS_N_INSNS (17)},                 /*                          other */
379   COSTS_N_INSNS (1),                    /* cost of movsx */
380   COSTS_N_INSNS (1),                    /* cost of movzx */
381   8,                                    /* "large" insn */
382   6,                                    /* MOVE_RATIO */
383   2,                                    /* cost for loading QImode using movzbl */
384   {4, 4, 4},                            /* cost of loading integer registers
385                                            in QImode, HImode and SImode.
386                                            Relative to reg-reg move (2).  */
387   {2, 2, 2},                            /* cost of storing integer registers */
388   2,                                    /* cost of reg,reg fld/fst */
389   {2, 2, 6},                            /* cost of loading fp registers
390                                            in SFmode, DFmode and XFmode */
391   {4, 4, 6},                            /* cost of storing fp registers
392                                            in SFmode, DFmode and XFmode */
393   2,                                    /* cost of moving MMX register */
394   {2, 2},                               /* cost of loading MMX registers
395                                            in SImode and DImode */
396   {2, 2},                               /* cost of storing MMX registers
397                                            in SImode and DImode */
398   2,                                    /* cost of moving SSE register */
399   {2, 2, 8},                            /* cost of loading SSE registers
400                                            in SImode, DImode and TImode */
401   {2, 2, 8},                            /* cost of storing SSE registers
402                                            in SImode, DImode and TImode */
403   3,                                    /* MMX or SSE register to integer */
404   8,                                    /* size of l1 cache.  */
405   256,                                  /* size of l2 cache  */
406   32,                                   /* size of prefetch block */
407   6,                                    /* number of parallel prefetches */
408   2,                                    /* Branch cost */
409   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
410   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
411   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
412   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
413   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
414   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
415   /* PentiumPro has optimized rep instructions for blocks aligned by 8 bytes (we ensure
416      the alignment).  For small blocks inline loop is still a noticeable win, for bigger
417      blocks either rep movsl or rep movsb is way to go.  Rep movsb has apparently
418      more expensive startup time in CPU, but after 4K the difference is down in the noise.
419    */
420   {{rep_prefix_4_byte, {{128, loop}, {1024, unrolled_loop},
421                         {8192, rep_prefix_4_byte}, {-1, rep_prefix_1_byte}}},
422    DUMMY_STRINGOP_ALGS},
423   {{rep_prefix_4_byte, {{1024, unrolled_loop},
424                         {8192, rep_prefix_4_byte}, {-1, libcall}}},
425    DUMMY_STRINGOP_ALGS},
426   1,                                    /* scalar_stmt_cost.  */
427   1,                                    /* scalar load_cost.  */
428   1,                                    /* scalar_store_cost.  */
429   1,                                    /* vec_stmt_cost.  */
430   1,                                    /* vec_to_scalar_cost.  */
431   1,                                    /* scalar_to_vec_cost.  */
432   1,                                    /* vec_align_load_cost.  */
433   2,                                    /* vec_unalign_load_cost.  */
434   1,                                    /* vec_store_cost.  */
435   3,                                    /* cond_taken_branch_cost.  */
436   1,                                    /* cond_not_taken_branch_cost.  */
437 };
438
439 static const
440 struct processor_costs geode_cost = {
441   COSTS_N_INSNS (1),                    /* cost of an add instruction */
442   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
443   COSTS_N_INSNS (2),                    /* variable shift costs */
444   COSTS_N_INSNS (1),                    /* constant shift costs */
445   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
446    COSTS_N_INSNS (4),                   /*                               HI */
447    COSTS_N_INSNS (7),                   /*                               SI */
448    COSTS_N_INSNS (7),                   /*                               DI */
449    COSTS_N_INSNS (7)},                  /*                               other */
450   0,                                    /* cost of multiply per each bit set */
451   {COSTS_N_INSNS (15),                  /* cost of a divide/mod for QI */
452    COSTS_N_INSNS (23),                  /*                          HI */
453    COSTS_N_INSNS (39),                  /*                          SI */
454    COSTS_N_INSNS (39),                  /*                          DI */
455    COSTS_N_INSNS (39)},                 /*                          other */
456   COSTS_N_INSNS (1),                    /* cost of movsx */
457   COSTS_N_INSNS (1),                    /* cost of movzx */
458   8,                                    /* "large" insn */
459   4,                                    /* MOVE_RATIO */
460   1,                                    /* cost for loading QImode using movzbl */
461   {1, 1, 1},                            /* cost of loading integer registers
462                                            in QImode, HImode and SImode.
463                                            Relative to reg-reg move (2).  */
464   {1, 1, 1},                            /* cost of storing integer registers */
465   1,                                    /* cost of reg,reg fld/fst */
466   {1, 1, 1},                            /* cost of loading fp registers
467                                            in SFmode, DFmode and XFmode */
468   {4, 6, 6},                            /* cost of storing fp registers
469                                            in SFmode, DFmode and XFmode */
470
471   1,                                    /* cost of moving MMX register */
472   {1, 1},                               /* cost of loading MMX registers
473                                            in SImode and DImode */
474   {1, 1},                               /* cost of storing MMX registers
475                                            in SImode and DImode */
476   1,                                    /* cost of moving SSE register */
477   {1, 1, 1},                            /* cost of loading SSE registers
478                                            in SImode, DImode and TImode */
479   {1, 1, 1},                            /* cost of storing SSE registers
480                                            in SImode, DImode and TImode */
481   1,                                    /* MMX or SSE register to integer */
482   64,                                   /* size of l1 cache.  */
483   128,                                  /* size of l2 cache.  */
484   32,                                   /* size of prefetch block */
485   1,                                    /* number of parallel prefetches */
486   1,                                    /* Branch cost */
487   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
488   COSTS_N_INSNS (11),                   /* cost of FMUL instruction.  */
489   COSTS_N_INSNS (47),                   /* cost of FDIV instruction.  */
490   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
491   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
492   COSTS_N_INSNS (54),                   /* cost of FSQRT instruction.  */
493   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
494    DUMMY_STRINGOP_ALGS},
495   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
496    DUMMY_STRINGOP_ALGS},
497   1,                                    /* scalar_stmt_cost.  */
498   1,                                    /* scalar load_cost.  */
499   1,                                    /* scalar_store_cost.  */
500   1,                                    /* vec_stmt_cost.  */
501   1,                                    /* vec_to_scalar_cost.  */
502   1,                                    /* scalar_to_vec_cost.  */
503   1,                                    /* vec_align_load_cost.  */
504   2,                                    /* vec_unalign_load_cost.  */
505   1,                                    /* vec_store_cost.  */
506   3,                                    /* cond_taken_branch_cost.  */
507   1,                                    /* cond_not_taken_branch_cost.  */
508 };
509
510 static const
511 struct processor_costs k6_cost = {
512   COSTS_N_INSNS (1),                    /* cost of an add instruction */
513   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
514   COSTS_N_INSNS (1),                    /* variable shift costs */
515   COSTS_N_INSNS (1),                    /* constant shift costs */
516   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
517    COSTS_N_INSNS (3),                   /*                               HI */
518    COSTS_N_INSNS (3),                   /*                               SI */
519    COSTS_N_INSNS (3),                   /*                               DI */
520    COSTS_N_INSNS (3)},                  /*                               other */
521   0,                                    /* cost of multiply per each bit set */
522   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
523    COSTS_N_INSNS (18),                  /*                          HI */
524    COSTS_N_INSNS (18),                  /*                          SI */
525    COSTS_N_INSNS (18),                  /*                          DI */
526    COSTS_N_INSNS (18)},                 /*                          other */
527   COSTS_N_INSNS (2),                    /* cost of movsx */
528   COSTS_N_INSNS (2),                    /* cost of movzx */
529   8,                                    /* "large" insn */
530   4,                                    /* MOVE_RATIO */
531   3,                                    /* cost for loading QImode using movzbl */
532   {4, 5, 4},                            /* cost of loading integer registers
533                                            in QImode, HImode and SImode.
534                                            Relative to reg-reg move (2).  */
535   {2, 3, 2},                            /* cost of storing integer registers */
536   4,                                    /* cost of reg,reg fld/fst */
537   {6, 6, 6},                            /* cost of loading fp registers
538                                            in SFmode, DFmode and XFmode */
539   {4, 4, 4},                            /* cost of storing fp registers
540                                            in SFmode, DFmode and XFmode */
541   2,                                    /* cost of moving MMX register */
542   {2, 2},                               /* cost of loading MMX registers
543                                            in SImode and DImode */
544   {2, 2},                               /* cost of storing MMX registers
545                                            in SImode and DImode */
546   2,                                    /* cost of moving SSE register */
547   {2, 2, 8},                            /* cost of loading SSE registers
548                                            in SImode, DImode and TImode */
549   {2, 2, 8},                            /* cost of storing SSE registers
550                                            in SImode, DImode and TImode */
551   6,                                    /* MMX or SSE register to integer */
552   32,                                   /* size of l1 cache.  */
553   32,                                   /* size of l2 cache.  Some models
554                                            have integrated l2 cache, but
555                                            optimizing for k6 is not important
556                                            enough to worry about that.  */
557   32,                                   /* size of prefetch block */
558   1,                                    /* number of parallel prefetches */
559   1,                                    /* Branch cost */
560   COSTS_N_INSNS (2),                    /* cost of FADD and FSUB insns.  */
561   COSTS_N_INSNS (2),                    /* cost of FMUL instruction.  */
562   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
563   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
564   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
565   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
566   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
567    DUMMY_STRINGOP_ALGS},
568   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
569    DUMMY_STRINGOP_ALGS},
570   1,                                    /* scalar_stmt_cost.  */
571   1,                                    /* scalar load_cost.  */
572   1,                                    /* scalar_store_cost.  */
573   1,                                    /* vec_stmt_cost.  */
574   1,                                    /* vec_to_scalar_cost.  */
575   1,                                    /* scalar_to_vec_cost.  */
576   1,                                    /* vec_align_load_cost.  */
577   2,                                    /* vec_unalign_load_cost.  */
578   1,                                    /* vec_store_cost.  */
579   3,                                    /* cond_taken_branch_cost.  */
580   1,                                    /* cond_not_taken_branch_cost.  */
581 };
582
583 static const
584 struct processor_costs athlon_cost = {
585   COSTS_N_INSNS (1),                    /* cost of an add instruction */
586   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
587   COSTS_N_INSNS (1),                    /* variable shift costs */
588   COSTS_N_INSNS (1),                    /* constant shift costs */
589   {COSTS_N_INSNS (5),                   /* cost of starting multiply for QI */
590    COSTS_N_INSNS (5),                   /*                               HI */
591    COSTS_N_INSNS (5),                   /*                               SI */
592    COSTS_N_INSNS (5),                   /*                               DI */
593    COSTS_N_INSNS (5)},                  /*                               other */
594   0,                                    /* cost of multiply per each bit set */
595   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
596    COSTS_N_INSNS (26),                  /*                          HI */
597    COSTS_N_INSNS (42),                  /*                          SI */
598    COSTS_N_INSNS (74),                  /*                          DI */
599    COSTS_N_INSNS (74)},                 /*                          other */
600   COSTS_N_INSNS (1),                    /* cost of movsx */
601   COSTS_N_INSNS (1),                    /* cost of movzx */
602   8,                                    /* "large" insn */
603   9,                                    /* MOVE_RATIO */
604   4,                                    /* cost for loading QImode using movzbl */
605   {3, 4, 3},                            /* cost of loading integer registers
606                                            in QImode, HImode and SImode.
607                                            Relative to reg-reg move (2).  */
608   {3, 4, 3},                            /* cost of storing integer registers */
609   4,                                    /* cost of reg,reg fld/fst */
610   {4, 4, 12},                           /* cost of loading fp registers
611                                            in SFmode, DFmode and XFmode */
612   {6, 6, 8},                            /* cost of storing fp registers
613                                            in SFmode, DFmode and XFmode */
614   2,                                    /* cost of moving MMX register */
615   {4, 4},                               /* cost of loading MMX registers
616                                            in SImode and DImode */
617   {4, 4},                               /* cost of storing MMX registers
618                                            in SImode and DImode */
619   2,                                    /* cost of moving SSE register */
620   {4, 4, 6},                            /* cost of loading SSE registers
621                                            in SImode, DImode and TImode */
622   {4, 4, 5},                            /* cost of storing SSE registers
623                                            in SImode, DImode and TImode */
624   5,                                    /* MMX or SSE register to integer */
625   64,                                   /* size of l1 cache.  */
626   256,                                  /* size of l2 cache.  */
627   64,                                   /* size of prefetch block */
628   6,                                    /* number of parallel prefetches */
629   5,                                    /* Branch cost */
630   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
631   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
632   COSTS_N_INSNS (24),                   /* cost of FDIV instruction.  */
633   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
634   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
635   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
636   /* For some reason, Athlon deals better with REP prefix (relative to loops)
637      compared to K8. Alignment becomes important after 8 bytes for memcpy and
638      128 bytes for memset.  */
639   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
640    DUMMY_STRINGOP_ALGS},
641   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
642    DUMMY_STRINGOP_ALGS},
643   1,                                    /* scalar_stmt_cost.  */
644   1,                                    /* scalar load_cost.  */
645   1,                                    /* scalar_store_cost.  */
646   1,                                    /* vec_stmt_cost.  */
647   1,                                    /* vec_to_scalar_cost.  */
648   1,                                    /* scalar_to_vec_cost.  */
649   1,                                    /* vec_align_load_cost.  */
650   2,                                    /* vec_unalign_load_cost.  */
651   1,                                    /* vec_store_cost.  */
652   3,                                    /* cond_taken_branch_cost.  */
653   1,                                    /* cond_not_taken_branch_cost.  */
654 };
655
656 static const
657 struct processor_costs k8_cost = {
658   COSTS_N_INSNS (1),                    /* cost of an add instruction */
659   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
660   COSTS_N_INSNS (1),                    /* variable shift costs */
661   COSTS_N_INSNS (1),                    /* constant shift costs */
662   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
663    COSTS_N_INSNS (4),                   /*                               HI */
664    COSTS_N_INSNS (3),                   /*                               SI */
665    COSTS_N_INSNS (4),                   /*                               DI */
666    COSTS_N_INSNS (5)},                  /*                               other */
667   0,                                    /* cost of multiply per each bit set */
668   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
669    COSTS_N_INSNS (26),                  /*                          HI */
670    COSTS_N_INSNS (42),                  /*                          SI */
671    COSTS_N_INSNS (74),                  /*                          DI */
672    COSTS_N_INSNS (74)},                 /*                          other */
673   COSTS_N_INSNS (1),                    /* cost of movsx */
674   COSTS_N_INSNS (1),                    /* cost of movzx */
675   8,                                    /* "large" insn */
676   9,                                    /* MOVE_RATIO */
677   4,                                    /* cost for loading QImode using movzbl */
678   {3, 4, 3},                            /* cost of loading integer registers
679                                            in QImode, HImode and SImode.
680                                            Relative to reg-reg move (2).  */
681   {3, 4, 3},                            /* cost of storing integer registers */
682   4,                                    /* cost of reg,reg fld/fst */
683   {4, 4, 12},                           /* cost of loading fp registers
684                                            in SFmode, DFmode and XFmode */
685   {6, 6, 8},                            /* cost of storing fp registers
686                                            in SFmode, DFmode and XFmode */
687   2,                                    /* cost of moving MMX register */
688   {3, 3},                               /* cost of loading MMX registers
689                                            in SImode and DImode */
690   {4, 4},                               /* cost of storing MMX registers
691                                            in SImode and DImode */
692   2,                                    /* cost of moving SSE register */
693   {4, 3, 6},                            /* cost of loading SSE registers
694                                            in SImode, DImode and TImode */
695   {4, 4, 5},                            /* cost of storing SSE registers
696                                            in SImode, DImode and TImode */
697   5,                                    /* MMX or SSE register to integer */
698   64,                                   /* size of l1 cache.  */
699   512,                                  /* size of l2 cache.  */
700   64,                                   /* size of prefetch block */
701   /* New AMD processors never drop prefetches; if they cannot be performed
702      immediately, they are queued.  We set number of simultaneous prefetches
703      to a large constant to reflect this (it probably is not a good idea not
704      to limit number of prefetches at all, as their execution also takes some
705      time).  */
706   100,                                  /* number of parallel prefetches */
707   3,                                    /* Branch cost */
708   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
709   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
710   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
711   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
712   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
713   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
714   /* K8 has optimized REP instruction for medium sized blocks, but for very small
715      blocks it is better to use loop. For large blocks, libcall can do
716      nontemporary accesses and beat inline considerably.  */
717   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
718    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
719   {{libcall, {{8, loop}, {24, unrolled_loop},
720               {2048, rep_prefix_4_byte}, {-1, libcall}}},
721    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
722   4,                                    /* scalar_stmt_cost.  */
723   2,                                    /* scalar load_cost.  */
724   2,                                    /* scalar_store_cost.  */
725   5,                                    /* vec_stmt_cost.  */
726   0,                                    /* vec_to_scalar_cost.  */
727   2,                                    /* scalar_to_vec_cost.  */
728   2,                                    /* vec_align_load_cost.  */
729   3,                                    /* vec_unalign_load_cost.  */
730   3,                                    /* vec_store_cost.  */
731   3,                                    /* cond_taken_branch_cost.  */
732   2,                                    /* cond_not_taken_branch_cost.  */
733 };
734
735 struct processor_costs amdfam10_cost = {
736   COSTS_N_INSNS (1),                    /* cost of an add instruction */
737   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
738   COSTS_N_INSNS (1),                    /* variable shift costs */
739   COSTS_N_INSNS (1),                    /* constant shift costs */
740   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
741    COSTS_N_INSNS (4),                   /*                               HI */
742    COSTS_N_INSNS (3),                   /*                               SI */
743    COSTS_N_INSNS (4),                   /*                               DI */
744    COSTS_N_INSNS (5)},                  /*                               other */
745   0,                                    /* cost of multiply per each bit set */
746   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
747    COSTS_N_INSNS (35),                  /*                          HI */
748    COSTS_N_INSNS (51),                  /*                          SI */
749    COSTS_N_INSNS (83),                  /*                          DI */
750    COSTS_N_INSNS (83)},                 /*                          other */
751   COSTS_N_INSNS (1),                    /* cost of movsx */
752   COSTS_N_INSNS (1),                    /* cost of movzx */
753   8,                                    /* "large" insn */
754   9,                                    /* MOVE_RATIO */
755   4,                                    /* cost for loading QImode using movzbl */
756   {3, 4, 3},                            /* cost of loading integer registers
757                                            in QImode, HImode and SImode.
758                                            Relative to reg-reg move (2).  */
759   {3, 4, 3},                            /* cost of storing integer registers */
760   4,                                    /* cost of reg,reg fld/fst */
761   {4, 4, 12},                           /* cost of loading fp registers
762                                            in SFmode, DFmode and XFmode */
763   {6, 6, 8},                            /* cost of storing fp registers
764                                            in SFmode, DFmode and XFmode */
765   2,                                    /* cost of moving MMX register */
766   {3, 3},                               /* cost of loading MMX registers
767                                            in SImode and DImode */
768   {4, 4},                               /* cost of storing MMX registers
769                                            in SImode and DImode */
770   2,                                    /* cost of moving SSE register */
771   {4, 4, 3},                            /* cost of loading SSE registers
772                                            in SImode, DImode and TImode */
773   {4, 4, 5},                            /* cost of storing SSE registers
774                                            in SImode, DImode and TImode */
775   3,                                    /* MMX or SSE register to integer */
776                                         /* On K8
777                                             MOVD reg64, xmmreg  Double  FSTORE 4
778                                             MOVD reg32, xmmreg  Double  FSTORE 4
779                                            On AMDFAM10
780                                             MOVD reg64, xmmreg  Double  FADD 3
781                                                                 1/1  1/1
782                                             MOVD reg32, xmmreg  Double  FADD 3
783                                                                 1/1  1/1 */
784   64,                                   /* size of l1 cache.  */
785   512,                                  /* size of l2 cache.  */
786   64,                                   /* size of prefetch block */
787   /* New AMD processors never drop prefetches; if they cannot be performed
788      immediately, they are queued.  We set number of simultaneous prefetches
789      to a large constant to reflect this (it probably is not a good idea not
790      to limit number of prefetches at all, as their execution also takes some
791      time).  */
792   100,                                  /* number of parallel prefetches */
793   2,                                    /* Branch cost */
794   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
795   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
796   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
797   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
798   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
799   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
800
801   /* AMDFAM10 has optimized REP instruction for medium sized blocks, but for
802      very small blocks it is better to use loop. For large blocks, libcall can
803      do nontemporary accesses and beat inline considerably.  */
804   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
805    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
806   {{libcall, {{8, loop}, {24, unrolled_loop},
807               {2048, rep_prefix_4_byte}, {-1, libcall}}},
808    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
809   4,                                    /* scalar_stmt_cost.  */
810   2,                                    /* scalar load_cost.  */
811   2,                                    /* scalar_store_cost.  */
812   6,                                    /* vec_stmt_cost.  */
813   0,                                    /* vec_to_scalar_cost.  */
814   2,                                    /* scalar_to_vec_cost.  */
815   2,                                    /* vec_align_load_cost.  */
816   2,                                    /* vec_unalign_load_cost.  */
817   2,                                    /* vec_store_cost.  */
818   2,                                    /* cond_taken_branch_cost.  */
819   1,                                    /* cond_not_taken_branch_cost.  */
820 };
821
822 static const
823 struct processor_costs pentium4_cost = {
824   COSTS_N_INSNS (1),                    /* cost of an add instruction */
825   COSTS_N_INSNS (3),                    /* cost of a lea instruction */
826   COSTS_N_INSNS (4),                    /* variable shift costs */
827   COSTS_N_INSNS (4),                    /* constant shift costs */
828   {COSTS_N_INSNS (15),                  /* cost of starting multiply for QI */
829    COSTS_N_INSNS (15),                  /*                               HI */
830    COSTS_N_INSNS (15),                  /*                               SI */
831    COSTS_N_INSNS (15),                  /*                               DI */
832    COSTS_N_INSNS (15)},                 /*                               other */
833   0,                                    /* cost of multiply per each bit set */
834   {COSTS_N_INSNS (56),                  /* cost of a divide/mod for QI */
835    COSTS_N_INSNS (56),                  /*                          HI */
836    COSTS_N_INSNS (56),                  /*                          SI */
837    COSTS_N_INSNS (56),                  /*                          DI */
838    COSTS_N_INSNS (56)},                 /*                          other */
839   COSTS_N_INSNS (1),                    /* cost of movsx */
840   COSTS_N_INSNS (1),                    /* cost of movzx */
841   16,                                   /* "large" insn */
842   6,                                    /* MOVE_RATIO */
843   2,                                    /* cost for loading QImode using movzbl */
844   {4, 5, 4},                            /* cost of loading integer registers
845                                            in QImode, HImode and SImode.
846                                            Relative to reg-reg move (2).  */
847   {2, 3, 2},                            /* cost of storing integer registers */
848   2,                                    /* cost of reg,reg fld/fst */
849   {2, 2, 6},                            /* cost of loading fp registers
850                                            in SFmode, DFmode and XFmode */
851   {4, 4, 6},                            /* cost of storing fp registers
852                                            in SFmode, DFmode and XFmode */
853   2,                                    /* cost of moving MMX register */
854   {2, 2},                               /* cost of loading MMX registers
855                                            in SImode and DImode */
856   {2, 2},                               /* cost of storing MMX registers
857                                            in SImode and DImode */
858   12,                                   /* cost of moving SSE register */
859   {12, 12, 12},                         /* cost of loading SSE registers
860                                            in SImode, DImode and TImode */
861   {2, 2, 8},                            /* cost of storing SSE registers
862                                            in SImode, DImode and TImode */
863   10,                                   /* MMX or SSE register to integer */
864   8,                                    /* size of l1 cache.  */
865   256,                                  /* size of l2 cache.  */
866   64,                                   /* size of prefetch block */
867   6,                                    /* number of parallel prefetches */
868   2,                                    /* Branch cost */
869   COSTS_N_INSNS (5),                    /* cost of FADD and FSUB insns.  */
870   COSTS_N_INSNS (7),                    /* cost of FMUL instruction.  */
871   COSTS_N_INSNS (43),                   /* cost of FDIV instruction.  */
872   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
873   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
874   COSTS_N_INSNS (43),                   /* cost of FSQRT instruction.  */
875   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
876    DUMMY_STRINGOP_ALGS},
877   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
878    {-1, libcall}}},
879    DUMMY_STRINGOP_ALGS},
880   1,                                    /* scalar_stmt_cost.  */
881   1,                                    /* scalar load_cost.  */
882   1,                                    /* scalar_store_cost.  */
883   1,                                    /* vec_stmt_cost.  */
884   1,                                    /* vec_to_scalar_cost.  */
885   1,                                    /* scalar_to_vec_cost.  */
886   1,                                    /* vec_align_load_cost.  */
887   2,                                    /* vec_unalign_load_cost.  */
888   1,                                    /* vec_store_cost.  */
889   3,                                    /* cond_taken_branch_cost.  */
890   1,                                    /* cond_not_taken_branch_cost.  */
891 };
892
893 static const
894 struct processor_costs nocona_cost = {
895   COSTS_N_INSNS (1),                    /* cost of an add instruction */
896   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
897   COSTS_N_INSNS (1),                    /* variable shift costs */
898   COSTS_N_INSNS (1),                    /* constant shift costs */
899   {COSTS_N_INSNS (10),                  /* cost of starting multiply for QI */
900    COSTS_N_INSNS (10),                  /*                               HI */
901    COSTS_N_INSNS (10),                  /*                               SI */
902    COSTS_N_INSNS (10),                  /*                               DI */
903    COSTS_N_INSNS (10)},                 /*                               other */
904   0,                                    /* cost of multiply per each bit set */
905   {COSTS_N_INSNS (66),                  /* cost of a divide/mod for QI */
906    COSTS_N_INSNS (66),                  /*                          HI */
907    COSTS_N_INSNS (66),                  /*                          SI */
908    COSTS_N_INSNS (66),                  /*                          DI */
909    COSTS_N_INSNS (66)},                 /*                          other */
910   COSTS_N_INSNS (1),                    /* cost of movsx */
911   COSTS_N_INSNS (1),                    /* cost of movzx */
912   16,                                   /* "large" insn */
913   17,                                   /* MOVE_RATIO */
914   4,                                    /* cost for loading QImode using movzbl */
915   {4, 4, 4},                            /* cost of loading integer registers
916                                            in QImode, HImode and SImode.
917                                            Relative to reg-reg move (2).  */
918   {4, 4, 4},                            /* cost of storing integer registers */
919   3,                                    /* cost of reg,reg fld/fst */
920   {12, 12, 12},                         /* cost of loading fp registers
921                                            in SFmode, DFmode and XFmode */
922   {4, 4, 4},                            /* cost of storing fp registers
923                                            in SFmode, DFmode and XFmode */
924   6,                                    /* cost of moving MMX register */
925   {12, 12},                             /* cost of loading MMX registers
926                                            in SImode and DImode */
927   {12, 12},                             /* cost of storing MMX registers
928                                            in SImode and DImode */
929   6,                                    /* cost of moving SSE register */
930   {12, 12, 12},                         /* cost of loading SSE registers
931                                            in SImode, DImode and TImode */
932   {12, 12, 12},                         /* cost of storing SSE registers
933                                            in SImode, DImode and TImode */
934   8,                                    /* MMX or SSE register to integer */
935   8,                                    /* size of l1 cache.  */
936   1024,                                 /* size of l2 cache.  */
937   128,                                  /* size of prefetch block */
938   8,                                    /* number of parallel prefetches */
939   1,                                    /* Branch cost */
940   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
941   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
942   COSTS_N_INSNS (40),                   /* cost of FDIV instruction.  */
943   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
944   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
945   COSTS_N_INSNS (44),                   /* cost of FSQRT instruction.  */
946   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
947    {libcall, {{32, loop}, {20000, rep_prefix_8_byte},
948               {100000, unrolled_loop}, {-1, libcall}}}},
949   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
950    {-1, libcall}}},
951    {libcall, {{24, loop}, {64, unrolled_loop},
952               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
953   1,                                    /* scalar_stmt_cost.  */
954   1,                                    /* scalar load_cost.  */
955   1,                                    /* scalar_store_cost.  */
956   1,                                    /* vec_stmt_cost.  */
957   1,                                    /* vec_to_scalar_cost.  */
958   1,                                    /* scalar_to_vec_cost.  */
959   1,                                    /* vec_align_load_cost.  */
960   2,                                    /* vec_unalign_load_cost.  */
961   1,                                    /* vec_store_cost.  */
962   3,                                    /* cond_taken_branch_cost.  */
963   1,                                    /* cond_not_taken_branch_cost.  */
964 };
965
966 static const
967 struct processor_costs core2_cost = {
968   COSTS_N_INSNS (1),                    /* cost of an add instruction */
969   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
970   COSTS_N_INSNS (1),                    /* variable shift costs */
971   COSTS_N_INSNS (1),                    /* constant shift costs */
972   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
973    COSTS_N_INSNS (3),                   /*                               HI */
974    COSTS_N_INSNS (3),                   /*                               SI */
975    COSTS_N_INSNS (3),                   /*                               DI */
976    COSTS_N_INSNS (3)},                  /*                               other */
977   0,                                    /* cost of multiply per each bit set */
978   {COSTS_N_INSNS (22),                  /* cost of a divide/mod for QI */
979    COSTS_N_INSNS (22),                  /*                          HI */
980    COSTS_N_INSNS (22),                  /*                          SI */
981    COSTS_N_INSNS (22),                  /*                          DI */
982    COSTS_N_INSNS (22)},                 /*                          other */
983   COSTS_N_INSNS (1),                    /* cost of movsx */
984   COSTS_N_INSNS (1),                    /* cost of movzx */
985   8,                                    /* "large" insn */
986   16,                                   /* MOVE_RATIO */
987   2,                                    /* cost for loading QImode using movzbl */
988   {6, 6, 6},                            /* cost of loading integer registers
989                                            in QImode, HImode and SImode.
990                                            Relative to reg-reg move (2).  */
991   {4, 4, 4},                            /* cost of storing integer registers */
992   2,                                    /* cost of reg,reg fld/fst */
993   {6, 6, 6},                            /* cost of loading fp registers
994                                            in SFmode, DFmode and XFmode */
995   {4, 4, 4},                            /* cost of storing fp registers
996                                            in SFmode, DFmode and XFmode */
997   2,                                    /* cost of moving MMX register */
998   {6, 6},                               /* cost of loading MMX registers
999                                            in SImode and DImode */
1000   {4, 4},                               /* cost of storing MMX registers
1001                                            in SImode and DImode */
1002   2,                                    /* cost of moving SSE register */
1003   {6, 6, 6},                            /* cost of loading SSE registers
1004                                            in SImode, DImode and TImode */
1005   {4, 4, 4},                            /* cost of storing SSE registers
1006                                            in SImode, DImode and TImode */
1007   2,                                    /* MMX or SSE register to integer */
1008   32,                                   /* size of l1 cache.  */
1009   2048,                                 /* size of l2 cache.  */
1010   128,                                  /* size of prefetch block */
1011   8,                                    /* number of parallel prefetches */
1012   3,                                    /* Branch cost */
1013   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
1014   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
1015   COSTS_N_INSNS (32),                   /* cost of FDIV instruction.  */
1016   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
1017   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
1018   COSTS_N_INSNS (58),                   /* cost of FSQRT instruction.  */
1019   {{libcall, {{11, loop}, {-1, rep_prefix_4_byte}}},
1020    {libcall, {{32, loop}, {64, rep_prefix_4_byte},
1021               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1022   {{libcall, {{8, loop}, {15, unrolled_loop},
1023               {2048, rep_prefix_4_byte}, {-1, libcall}}},
1024    {libcall, {{24, loop}, {32, unrolled_loop},
1025               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1026   1,                                    /* scalar_stmt_cost.  */
1027   1,                                    /* scalar load_cost.  */
1028   1,                                    /* scalar_store_cost.  */
1029   1,                                    /* vec_stmt_cost.  */
1030   1,                                    /* vec_to_scalar_cost.  */
1031   1,                                    /* scalar_to_vec_cost.  */
1032   1,                                    /* vec_align_load_cost.  */
1033   2,                                    /* vec_unalign_load_cost.  */
1034   1,                                    /* vec_store_cost.  */
1035   3,                                    /* cond_taken_branch_cost.  */
1036   1,                                    /* cond_not_taken_branch_cost.  */
1037 };
1038
1039 /* Generic64 should produce code tuned for Nocona and K8.  */
1040 static const
1041 struct processor_costs generic64_cost = {
1042   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1043   /* On all chips taken into consideration lea is 2 cycles and more.  With
1044      this cost however our current implementation of synth_mult results in
1045      use of unnecessary temporary registers causing regression on several
1046      SPECfp benchmarks.  */
1047   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1048   COSTS_N_INSNS (1),                    /* variable shift costs */
1049   COSTS_N_INSNS (1),                    /* constant shift costs */
1050   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1051    COSTS_N_INSNS (4),                   /*                               HI */
1052    COSTS_N_INSNS (3),                   /*                               SI */
1053    COSTS_N_INSNS (4),                   /*                               DI */
1054    COSTS_N_INSNS (2)},                  /*                               other */
1055   0,                                    /* cost of multiply per each bit set */
1056   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1057    COSTS_N_INSNS (26),                  /*                          HI */
1058    COSTS_N_INSNS (42),                  /*                          SI */
1059    COSTS_N_INSNS (74),                  /*                          DI */
1060    COSTS_N_INSNS (74)},                 /*                          other */
1061   COSTS_N_INSNS (1),                    /* cost of movsx */
1062   COSTS_N_INSNS (1),                    /* cost of movzx */
1063   8,                                    /* "large" insn */
1064   17,                                   /* MOVE_RATIO */
1065   4,                                    /* cost for loading QImode using movzbl */
1066   {4, 4, 4},                            /* cost of loading integer registers
1067                                            in QImode, HImode and SImode.
1068                                            Relative to reg-reg move (2).  */
1069   {4, 4, 4},                            /* cost of storing integer registers */
1070   4,                                    /* cost of reg,reg fld/fst */
1071   {12, 12, 12},                         /* cost of loading fp registers
1072                                            in SFmode, DFmode and XFmode */
1073   {6, 6, 8},                            /* cost of storing fp registers
1074                                            in SFmode, DFmode and XFmode */
1075   2,                                    /* cost of moving MMX register */
1076   {8, 8},                               /* cost of loading MMX registers
1077                                            in SImode and DImode */
1078   {8, 8},                               /* cost of storing MMX registers
1079                                            in SImode and DImode */
1080   2,                                    /* cost of moving SSE register */
1081   {8, 8, 8},                            /* cost of loading SSE registers
1082                                            in SImode, DImode and TImode */
1083   {8, 8, 8},                            /* cost of storing SSE registers
1084                                            in SImode, DImode and TImode */
1085   5,                                    /* MMX or SSE register to integer */
1086   32,                                   /* size of l1 cache.  */
1087   512,                                  /* size of l2 cache.  */
1088   64,                                   /* size of prefetch block */
1089   6,                                    /* number of parallel prefetches */
1090   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this value
1091      is increased to perhaps more appropriate value of 5.  */
1092   3,                                    /* Branch cost */
1093   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1094   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1095   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1096   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1097   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1098   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1099   {DUMMY_STRINGOP_ALGS,
1100    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1101   {DUMMY_STRINGOP_ALGS,
1102    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1103   1,                                    /* scalar_stmt_cost.  */
1104   1,                                    /* scalar load_cost.  */
1105   1,                                    /* scalar_store_cost.  */
1106   1,                                    /* vec_stmt_cost.  */
1107   1,                                    /* vec_to_scalar_cost.  */
1108   1,                                    /* scalar_to_vec_cost.  */
1109   1,                                    /* vec_align_load_cost.  */
1110   2,                                    /* vec_unalign_load_cost.  */
1111   1,                                    /* vec_store_cost.  */
1112   3,                                    /* cond_taken_branch_cost.  */
1113   1,                                    /* cond_not_taken_branch_cost.  */
1114 };
1115
1116 /* Generic32 should produce code tuned for Athlon, PPro, Pentium4, Nocona and K8.  */
1117 static const
1118 struct processor_costs generic32_cost = {
1119   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1120   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1121   COSTS_N_INSNS (1),                    /* variable shift costs */
1122   COSTS_N_INSNS (1),                    /* constant shift costs */
1123   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1124    COSTS_N_INSNS (4),                   /*                               HI */
1125    COSTS_N_INSNS (3),                   /*                               SI */
1126    COSTS_N_INSNS (4),                   /*                               DI */
1127    COSTS_N_INSNS (2)},                  /*                               other */
1128   0,                                    /* cost of multiply per each bit set */
1129   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1130    COSTS_N_INSNS (26),                  /*                          HI */
1131    COSTS_N_INSNS (42),                  /*                          SI */
1132    COSTS_N_INSNS (74),                  /*                          DI */
1133    COSTS_N_INSNS (74)},                 /*                          other */
1134   COSTS_N_INSNS (1),                    /* cost of movsx */
1135   COSTS_N_INSNS (1),                    /* cost of movzx */
1136   8,                                    /* "large" insn */
1137   17,                                   /* MOVE_RATIO */
1138   4,                                    /* cost for loading QImode using movzbl */
1139   {4, 4, 4},                            /* cost of loading integer registers
1140                                            in QImode, HImode and SImode.
1141                                            Relative to reg-reg move (2).  */
1142   {4, 4, 4},                            /* cost of storing integer registers */
1143   4,                                    /* cost of reg,reg fld/fst */
1144   {12, 12, 12},                         /* cost of loading fp registers
1145                                            in SFmode, DFmode and XFmode */
1146   {6, 6, 8},                            /* cost of storing fp registers
1147                                            in SFmode, DFmode and XFmode */
1148   2,                                    /* cost of moving MMX register */
1149   {8, 8},                               /* cost of loading MMX registers
1150                                            in SImode and DImode */
1151   {8, 8},                               /* cost of storing MMX registers
1152                                            in SImode and DImode */
1153   2,                                    /* cost of moving SSE register */
1154   {8, 8, 8},                            /* cost of loading SSE registers
1155                                            in SImode, DImode and TImode */
1156   {8, 8, 8},                            /* cost of storing SSE registers
1157                                            in SImode, DImode and TImode */
1158   5,                                    /* MMX or SSE register to integer */
1159   32,                                   /* size of l1 cache.  */
1160   256,                                  /* size of l2 cache.  */
1161   64,                                   /* size of prefetch block */
1162   6,                                    /* number of parallel prefetches */
1163   3,                                    /* Branch cost */
1164   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1165   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1166   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1167   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1168   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1169   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1170   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1171    DUMMY_STRINGOP_ALGS},
1172   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1173    DUMMY_STRINGOP_ALGS},
1174   1,                                    /* scalar_stmt_cost.  */
1175   1,                                    /* scalar load_cost.  */
1176   1,                                    /* scalar_store_cost.  */
1177   1,                                    /* vec_stmt_cost.  */
1178   1,                                    /* vec_to_scalar_cost.  */
1179   1,                                    /* scalar_to_vec_cost.  */
1180   1,                                    /* vec_align_load_cost.  */
1181   2,                                    /* vec_unalign_load_cost.  */
1182   1,                                    /* vec_store_cost.  */
1183   3,                                    /* cond_taken_branch_cost.  */
1184   1,                                    /* cond_not_taken_branch_cost.  */
1185 };
1186
1187 const struct processor_costs *ix86_cost = &pentium_cost;
1188
1189 /* Processor feature/optimization bitmasks.  */
1190 #define m_386 (1<<PROCESSOR_I386)
1191 #define m_486 (1<<PROCESSOR_I486)
1192 #define m_PENT (1<<PROCESSOR_PENTIUM)
1193 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
1194 #define m_PENT4  (1<<PROCESSOR_PENTIUM4)
1195 #define m_NOCONA  (1<<PROCESSOR_NOCONA)
1196 #define m_CORE2  (1<<PROCESSOR_CORE2)
1197
1198 #define m_GEODE  (1<<PROCESSOR_GEODE)
1199 #define m_K6  (1<<PROCESSOR_K6)
1200 #define m_K6_GEODE  (m_K6 | m_GEODE)
1201 #define m_K8  (1<<PROCESSOR_K8)
1202 #define m_ATHLON  (1<<PROCESSOR_ATHLON)
1203 #define m_ATHLON_K8  (m_K8 | m_ATHLON)
1204 #define m_AMDFAM10  (1<<PROCESSOR_AMDFAM10)
1205 #define m_AMD_MULTIPLE  (m_K8 | m_ATHLON | m_AMDFAM10)
1206
1207 #define m_GENERIC32 (1<<PROCESSOR_GENERIC32)
1208 #define m_GENERIC64 (1<<PROCESSOR_GENERIC64)
1209
1210 /* Generic instruction choice should be common subset of supported CPUs
1211    (PPro/PENT4/NOCONA/CORE2/Athlon/K8).  */
1212 #define m_GENERIC (m_GENERIC32 | m_GENERIC64)
1213
1214 /* Feature tests against the various tunings.  */
1215 unsigned char ix86_tune_features[X86_TUNE_LAST];
1216
1217 /* Feature tests against the various tunings used to create ix86_tune_features
1218    based on the processor mask.  */
1219 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
1220   /* X86_TUNE_USE_LEAVE: Leave does not affect Nocona SPEC2000 results
1221      negatively, so enabling for Generic64 seems like good code size
1222      tradeoff.  We can't enable it for 32bit generic because it does not
1223      work well with PPro base chips.  */
1224   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_CORE2 | m_GENERIC64,
1225
1226   /* X86_TUNE_PUSH_MEMORY */
1227   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4
1228   | m_NOCONA | m_CORE2 | m_GENERIC,
1229
1230   /* X86_TUNE_ZERO_EXTEND_WITH_AND */
1231   m_486 | m_PENT,
1232
1233   /* X86_TUNE_UNROLL_STRLEN */
1234   m_486 | m_PENT | m_PPRO | m_AMD_MULTIPLE | m_K6 | m_CORE2 | m_GENERIC,
1235
1236   /* X86_TUNE_DEEP_BRANCH_PREDICTION */
1237   m_PPRO | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4 | m_GENERIC,
1238
1239   /* X86_TUNE_BRANCH_PREDICTION_HINTS: Branch hints were put in P4 based
1240      on simulation result. But after P4 was made, no performance benefit
1241      was observed with branch hints.  It also increases the code size.
1242      As a result, icc never generates branch hints.  */
1243   0,
1244
1245   /* X86_TUNE_DOUBLE_WITH_ADD */
1246   ~m_386,
1247
1248   /* X86_TUNE_USE_SAHF */
1249   m_PPRO | m_K6_GEODE | m_K8 | m_AMDFAM10 | m_PENT4
1250   | m_NOCONA | m_CORE2 | m_GENERIC,
1251
1252   /* X86_TUNE_MOVX: Enable to zero extend integer registers to avoid
1253      partial dependencies.  */
1254   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA
1255   | m_CORE2 | m_GENERIC | m_GEODE /* m_386 | m_K6 */,
1256
1257   /* X86_TUNE_PARTIAL_REG_STALL: We probably ought to watch for partial
1258      register stalls on Generic32 compilation setting as well.  However
1259      in current implementation the partial register stalls are not eliminated
1260      very well - they can be introduced via subregs synthesized by combine
1261      and can happen in caller/callee saving sequences.  Because this option
1262      pays back little on PPro based chips and is in conflict with partial reg
1263      dependencies used by Athlon/P4 based chips, it is better to leave it off
1264      for generic32 for now.  */
1265   m_PPRO,
1266
1267   /* X86_TUNE_PARTIAL_FLAG_REG_STALL */
1268   m_CORE2 | m_GENERIC,
1269
1270   /* X86_TUNE_USE_HIMODE_FIOP */
1271   m_386 | m_486 | m_K6_GEODE,
1272
1273   /* X86_TUNE_USE_SIMODE_FIOP */
1274   ~(m_PPRO | m_AMD_MULTIPLE | m_PENT | m_CORE2 | m_GENERIC),
1275
1276   /* X86_TUNE_USE_MOV0 */
1277   m_K6,
1278
1279   /* X86_TUNE_USE_CLTD */
1280   ~(m_PENT | m_K6 | m_CORE2 | m_GENERIC),
1281
1282   /* X86_TUNE_USE_XCHGB: Use xchgb %rh,%rl instead of rolw/rorw $8,rx.  */
1283   m_PENT4,
1284
1285   /* X86_TUNE_SPLIT_LONG_MOVES */
1286   m_PPRO,
1287
1288   /* X86_TUNE_READ_MODIFY_WRITE */
1289   ~m_PENT,
1290
1291   /* X86_TUNE_READ_MODIFY */
1292   ~(m_PENT | m_PPRO),
1293
1294   /* X86_TUNE_PROMOTE_QIMODE */
1295   m_K6_GEODE | m_PENT | m_386 | m_486 | m_AMD_MULTIPLE | m_CORE2
1296   | m_GENERIC /* | m_PENT4 ? */,
1297
1298   /* X86_TUNE_FAST_PREFIX */
1299   ~(m_PENT | m_486 | m_386),
1300
1301   /* X86_TUNE_SINGLE_STRINGOP */
1302   m_386 | m_PENT4 | m_NOCONA,
1303
1304   /* X86_TUNE_QIMODE_MATH */
1305   ~0,
1306
1307   /* X86_TUNE_HIMODE_MATH: On PPro this flag is meant to avoid partial
1308      register stalls.  Just like X86_TUNE_PARTIAL_REG_STALL this option
1309      might be considered for Generic32 if our scheme for avoiding partial
1310      stalls was more effective.  */
1311   ~m_PPRO,
1312
1313   /* X86_TUNE_PROMOTE_QI_REGS */
1314   0,
1315
1316   /* X86_TUNE_PROMOTE_HI_REGS */
1317   m_PPRO,
1318
1319   /* X86_TUNE_ADD_ESP_4: Enable if add/sub is preferred over 1/2 push/pop.  */
1320   m_AMD_MULTIPLE | m_K6_GEODE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1321
1322   /* X86_TUNE_ADD_ESP_8 */
1323   m_AMD_MULTIPLE | m_PPRO | m_K6_GEODE | m_386
1324   | m_486 | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1325
1326   /* X86_TUNE_SUB_ESP_4 */
1327   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1328
1329   /* X86_TUNE_SUB_ESP_8 */
1330   m_AMD_MULTIPLE | m_PPRO | m_386 | m_486
1331   | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1332
1333   /* X86_TUNE_INTEGER_DFMODE_MOVES: Enable if integer moves are preferred
1334      for DFmode copies */
1335   ~(m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2
1336     | m_GENERIC | m_GEODE),
1337
1338   /* X86_TUNE_PARTIAL_REG_DEPENDENCY */
1339   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1340
1341   /* X86_TUNE_SSE_PARTIAL_REG_DEPENDENCY: In the Generic model we have a
1342      conflict here in between PPro/Pentium4 based chips that thread 128bit
1343      SSE registers as single units versus K8 based chips that divide SSE
1344      registers to two 64bit halves.  This knob promotes all store destinations
1345      to be 128bit to allow register renaming on 128bit SSE units, but usually
1346      results in one extra microop on 64bit SSE units.  Experimental results
1347      shows that disabling this option on P4 brings over 20% SPECfp regression,
1348      while enabling it on K8 brings roughly 2.4% regression that can be partly
1349      masked by careful scheduling of moves.  */
1350   m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC | m_AMDFAM10,
1351
1352   /* X86_TUNE_SSE_UNALIGNED_MOVE_OPTIMAL */
1353   m_AMDFAM10,
1354
1355   /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
1356      are resolved on SSE register parts instead of whole registers, so we may
1357      maintain just lower part of scalar values in proper format leaving the
1358      upper part undefined.  */
1359   m_ATHLON_K8,
1360
1361   /* X86_TUNE_SSE_TYPELESS_STORES */
1362   m_AMD_MULTIPLE,
1363
1364   /* X86_TUNE_SSE_LOAD0_BY_PXOR */
1365   m_PPRO | m_PENT4 | m_NOCONA,
1366
1367   /* X86_TUNE_MEMORY_MISMATCH_STALL */
1368   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1369
1370   /* X86_TUNE_PROLOGUE_USING_MOVE */
1371   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1372
1373   /* X86_TUNE_EPILOGUE_USING_MOVE */
1374   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1375
1376   /* X86_TUNE_SHIFT1 */
1377   ~m_486,
1378
1379   /* X86_TUNE_USE_FFREEP */
1380   m_AMD_MULTIPLE,
1381
1382   /* X86_TUNE_INTER_UNIT_MOVES */
1383   ~(m_AMD_MULTIPLE | m_GENERIC),
1384
1385   /* X86_TUNE_INTER_UNIT_CONVERSIONS */
1386   ~(m_AMDFAM10),
1387
1388   /* X86_TUNE_FOUR_JUMP_LIMIT: Some CPU cores are not able to predict more
1389      than 4 branch instructions in the 16 byte window.  */
1390   m_PPRO | m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1391
1392   /* X86_TUNE_SCHEDULE */
1393   m_PPRO | m_AMD_MULTIPLE | m_K6_GEODE | m_PENT | m_CORE2 | m_GENERIC,
1394
1395   /* X86_TUNE_USE_BT */
1396   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1397
1398   /* X86_TUNE_USE_INCDEC */
1399   ~(m_PENT4 | m_NOCONA | m_GENERIC),
1400
1401   /* X86_TUNE_PAD_RETURNS */
1402   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1403
1404   /* X86_TUNE_EXT_80387_CONSTANTS */
1405   m_K6_GEODE | m_ATHLON_K8 | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC,
1406
1407   /* X86_TUNE_SHORTEN_X87_SSE */
1408   ~m_K8,
1409
1410   /* X86_TUNE_AVOID_VECTOR_DECODE */
1411   m_K8 | m_GENERIC64,
1412
1413   /* X86_TUNE_PROMOTE_HIMODE_IMUL: Modern CPUs have same latency for HImode
1414      and SImode multiply, but 386 and 486 do HImode multiply faster.  */
1415   ~(m_386 | m_486),
1416
1417   /* X86_TUNE_SLOW_IMUL_IMM32_MEM: Imul of 32-bit constant and memory is
1418      vector path on AMD machines.  */
1419   m_K8 | m_GENERIC64 | m_AMDFAM10,
1420
1421   /* X86_TUNE_SLOW_IMUL_IMM8: Imul of 8-bit constant is vector path on AMD
1422      machines.  */
1423   m_K8 | m_GENERIC64 | m_AMDFAM10,
1424
1425   /* X86_TUNE_MOVE_M1_VIA_OR: On pentiums, it is faster to load -1 via OR
1426      than a MOV.  */
1427   m_PENT,
1428
1429   /* X86_TUNE_NOT_UNPAIRABLE: NOT is not pairable on Pentium, while XOR is,
1430      but one byte longer.  */
1431   m_PENT,
1432
1433   /* X86_TUNE_NOT_VECTORMODE: On AMD K6, NOT is vector decoded with memory
1434      operand that cannot be represented using a modRM byte.  The XOR
1435      replacement is long decoded, so this split helps here as well.  */
1436   m_K6,
1437
1438   /* X86_TUNE_USE_VECTOR_FP_CONVERTS: Prefer vector packed SSE conversion
1439      from FP to FP. */
1440   m_AMDFAM10 | m_GENERIC,
1441
1442   /* X86_TUNE_USE_VECTOR_CONVERTS: Prefer vector packed SSE conversion
1443      from integer to FP. */
1444   m_AMDFAM10,
1445
1446   /* X86_TUNE_FUSE_CMP_AND_BRANCH: Fuse a compare or test instruction
1447      with a subsequent conditional jump instruction into a single
1448      compare-and-branch uop.  */
1449   m_CORE2,
1450 };
1451
1452 /* Feature tests against the various architecture variations.  */
1453 unsigned char ix86_arch_features[X86_ARCH_LAST];
1454
1455 /* Feature tests against the various architecture variations, used to create
1456    ix86_arch_features based on the processor mask.  */
1457 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
1458   /* X86_ARCH_CMOVE: Conditional move was added for pentiumpro.  */
1459   ~(m_386 | m_486 | m_PENT | m_K6),
1460
1461   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
1462   ~m_386,
1463
1464   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
1465   ~(m_386 | m_486),
1466
1467   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
1468   ~m_386,
1469
1470   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
1471   ~m_386,
1472 };
1473
1474 static const unsigned int x86_accumulate_outgoing_args
1475   = m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC;
1476
1477 static const unsigned int x86_arch_always_fancy_math_387
1478   = m_PENT | m_PPRO | m_AMD_MULTIPLE | m_PENT4
1479     | m_NOCONA | m_CORE2 | m_GENERIC;
1480
1481 static enum stringop_alg stringop_alg = no_stringop;
1482
1483 /* In case the average insn count for single function invocation is
1484    lower than this constant, emit fast (but longer) prologue and
1485    epilogue code.  */
1486 #define FAST_PROLOGUE_INSN_COUNT 20
1487
1488 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
1489 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
1490 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
1491 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
1492
1493 /* Array of the smallest class containing reg number REGNO, indexed by
1494    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
1495
1496 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
1497 {
1498   /* ax, dx, cx, bx */
1499   AREG, DREG, CREG, BREG,
1500   /* si, di, bp, sp */
1501   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
1502   /* FP registers */
1503   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
1504   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
1505   /* arg pointer */
1506   NON_Q_REGS,
1507   /* flags, fpsr, fpcr, frame */
1508   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
1509   /* SSE registers */
1510   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1511   SSE_REGS, SSE_REGS,
1512   /* MMX registers */
1513   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
1514   MMX_REGS, MMX_REGS,
1515   /* REX registers */
1516   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1517   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1518   /* SSE REX registers */
1519   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1520   SSE_REGS, SSE_REGS,
1521 };
1522
1523 /* The "default" register map used in 32bit mode.  */
1524
1525 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
1526 {
1527   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
1528   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
1529   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1530   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
1531   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
1532   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1533   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1534 };
1535
1536 static int const x86_64_int_parameter_registers[6] =
1537 {
1538   5 /*RDI*/, 4 /*RSI*/, 1 /*RDX*/, 2 /*RCX*/,
1539   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1540 };
1541
1542 static int const x86_64_ms_abi_int_parameter_registers[4] =
1543 {
1544   2 /*RCX*/, 1 /*RDX*/,
1545   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1546 };
1547
1548 static int const x86_64_int_return_registers[4] =
1549 {
1550   0 /*RAX*/, 1 /*RDX*/, 5 /*RDI*/, 4 /*RSI*/
1551 };
1552
1553 /* The "default" register map used in 64bit mode.  */
1554 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
1555 {
1556   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
1557   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
1558   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1559   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
1560   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
1561   8,9,10,11,12,13,14,15,                /* extended integer registers */
1562   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
1563 };
1564
1565 /* Define the register numbers to be used in Dwarf debugging information.
1566    The SVR4 reference port C compiler uses the following register numbers
1567    in its Dwarf output code:
1568         0 for %eax (gcc regno = 0)
1569         1 for %ecx (gcc regno = 2)
1570         2 for %edx (gcc regno = 1)
1571         3 for %ebx (gcc regno = 3)
1572         4 for %esp (gcc regno = 7)
1573         5 for %ebp (gcc regno = 6)
1574         6 for %esi (gcc regno = 4)
1575         7 for %edi (gcc regno = 5)
1576    The following three DWARF register numbers are never generated by
1577    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
1578    believes these numbers have these meanings.
1579         8  for %eip    (no gcc equivalent)
1580         9  for %eflags (gcc regno = 17)
1581         10 for %trapno (no gcc equivalent)
1582    It is not at all clear how we should number the FP stack registers
1583    for the x86 architecture.  If the version of SDB on x86/svr4 were
1584    a bit less brain dead with respect to floating-point then we would
1585    have a precedent to follow with respect to DWARF register numbers
1586    for x86 FP registers, but the SDB on x86/svr4 is so completely
1587    broken with respect to FP registers that it is hardly worth thinking
1588    of it as something to strive for compatibility with.
1589    The version of x86/svr4 SDB I have at the moment does (partially)
1590    seem to believe that DWARF register number 11 is associated with
1591    the x86 register %st(0), but that's about all.  Higher DWARF
1592    register numbers don't seem to be associated with anything in
1593    particular, and even for DWARF regno 11, SDB only seems to under-
1594    stand that it should say that a variable lives in %st(0) (when
1595    asked via an `=' command) if we said it was in DWARF regno 11,
1596    but SDB still prints garbage when asked for the value of the
1597    variable in question (via a `/' command).
1598    (Also note that the labels SDB prints for various FP stack regs
1599    when doing an `x' command are all wrong.)
1600    Note that these problems generally don't affect the native SVR4
1601    C compiler because it doesn't allow the use of -O with -g and
1602    because when it is *not* optimizing, it allocates a memory
1603    location for each floating-point variable, and the memory
1604    location is what gets described in the DWARF AT_location
1605    attribute for the variable in question.
1606    Regardless of the severe mental illness of the x86/svr4 SDB, we
1607    do something sensible here and we use the following DWARF
1608    register numbers.  Note that these are all stack-top-relative
1609    numbers.
1610         11 for %st(0) (gcc regno = 8)
1611         12 for %st(1) (gcc regno = 9)
1612         13 for %st(2) (gcc regno = 10)
1613         14 for %st(3) (gcc regno = 11)
1614         15 for %st(4) (gcc regno = 12)
1615         16 for %st(5) (gcc regno = 13)
1616         17 for %st(6) (gcc regno = 14)
1617         18 for %st(7) (gcc regno = 15)
1618 */
1619 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
1620 {
1621   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
1622   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
1623   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
1624   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
1625   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
1626   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1627   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1628 };
1629
1630 /* Test and compare insns in i386.md store the information needed to
1631    generate branch and scc insns here.  */
1632
1633 rtx ix86_compare_op0 = NULL_RTX;
1634 rtx ix86_compare_op1 = NULL_RTX;
1635 rtx ix86_compare_emitted = NULL_RTX;
1636
1637 /* Define the structure for the machine field in struct function.  */
1638
1639 struct stack_local_entry GTY(())
1640 {
1641   unsigned short mode;
1642   unsigned short n;
1643   rtx rtl;
1644   struct stack_local_entry *next;
1645 };
1646
1647 /* Structure describing stack frame layout.
1648    Stack grows downward:
1649
1650    [arguments]
1651                                               <- ARG_POINTER
1652    saved pc
1653
1654    saved frame pointer if frame_pointer_needed
1655                                               <- HARD_FRAME_POINTER
1656    [saved regs]
1657
1658    [padding0]
1659
1660    [saved SSE regs]
1661
1662    [padding1]          \
1663                         )
1664    [va_arg registers]  (
1665                         > to_allocate         <- FRAME_POINTER
1666    [frame]             (
1667                         )
1668    [padding2]          /
1669   */
1670 struct ix86_frame
1671 {
1672   int padding0;
1673   int nsseregs;
1674   int nregs;
1675   int padding1;
1676   int va_arg_size;
1677   HOST_WIDE_INT frame;
1678   int padding2;
1679   int outgoing_arguments_size;
1680   int red_zone_size;
1681
1682   HOST_WIDE_INT to_allocate;
1683   /* The offsets relative to ARG_POINTER.  */
1684   HOST_WIDE_INT frame_pointer_offset;
1685   HOST_WIDE_INT hard_frame_pointer_offset;
1686   HOST_WIDE_INT stack_pointer_offset;
1687
1688   /* When save_regs_using_mov is set, emit prologue using
1689      move instead of push instructions.  */
1690   bool save_regs_using_mov;
1691 };
1692
1693 /* Code model option.  */
1694 enum cmodel ix86_cmodel;
1695 /* Asm dialect.  */
1696 enum asm_dialect ix86_asm_dialect = ASM_ATT;
1697 /* TLS dialects.  */
1698 enum tls_dialect ix86_tls_dialect = TLS_DIALECT_GNU;
1699
1700 /* Which unit we are generating floating point math for.  */
1701 enum fpmath_unit ix86_fpmath;
1702
1703 /* Which cpu are we scheduling for.  */
1704 enum attr_cpu ix86_schedule;
1705
1706 /* Which cpu are we optimizing for.  */
1707 enum processor_type ix86_tune;
1708
1709 /* Which instruction set architecture to use.  */
1710 enum processor_type ix86_arch;
1711
1712 /* true if sse prefetch instruction is not NOOP.  */
1713 int x86_prefetch_sse;
1714
1715 /* ix86_regparm_string as a number */
1716 static int ix86_regparm;
1717
1718 /* -mstackrealign option */
1719 extern int ix86_force_align_arg_pointer;
1720 static const char ix86_force_align_arg_pointer_string[]
1721   = "force_align_arg_pointer";
1722
1723 static rtx (*ix86_gen_leave) (void);
1724 static rtx (*ix86_gen_pop1) (rtx);
1725 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
1726 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
1727 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx);
1728 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
1729 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
1730 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
1731
1732 /* Preferred alignment for stack boundary in bits.  */
1733 unsigned int ix86_preferred_stack_boundary;
1734
1735 /* Alignment for incoming stack boundary in bits specified at
1736    command line.  */
1737 static unsigned int ix86_user_incoming_stack_boundary;
1738
1739 /* Default alignment for incoming stack boundary in bits.  */
1740 static unsigned int ix86_default_incoming_stack_boundary;
1741
1742 /* Alignment for incoming stack boundary in bits.  */
1743 unsigned int ix86_incoming_stack_boundary;
1744
1745 /* Values 1-5: see jump.c */
1746 int ix86_branch_cost;
1747
1748 /* Calling abi specific va_list type nodes.  */
1749 static GTY(()) tree sysv_va_list_type_node;
1750 static GTY(()) tree ms_va_list_type_node;
1751
1752 /* Variables which are this size or smaller are put in the data/bss
1753    or ldata/lbss sections.  */
1754
1755 int ix86_section_threshold = 65536;
1756
1757 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
1758 char internal_label_prefix[16];
1759 int internal_label_prefix_len;
1760
1761 /* Fence to use after loop using movnt.  */
1762 tree x86_mfence;
1763
1764 /* Register class used for passing given 64bit part of the argument.
1765    These represent classes as documented by the PS ABI, with the exception
1766    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
1767    use SF or DFmode move instead of DImode to avoid reformatting penalties.
1768
1769    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
1770    whenever possible (upper half does contain padding).  */
1771 enum x86_64_reg_class
1772   {
1773     X86_64_NO_CLASS,
1774     X86_64_INTEGER_CLASS,
1775     X86_64_INTEGERSI_CLASS,
1776     X86_64_AVX_CLASS,
1777     X86_64_SSE_CLASS,
1778     X86_64_SSESF_CLASS,
1779     X86_64_SSEDF_CLASS,
1780     X86_64_SSEUP_CLASS,
1781     X86_64_X87_CLASS,
1782     X86_64_X87UP_CLASS,
1783     X86_64_COMPLEX_X87_CLASS,
1784     X86_64_MEMORY_CLASS
1785   };
1786 static const char * const x86_64_reg_class_name[] =
1787 {
1788   "no", "integer", "integerSI", "sse", "sseSF", "sseDF",
1789   "sseup", "x87", "x87up", "cplx87", "no"
1790 };
1791
1792 #define MAX_CLASSES 4
1793
1794 /* Table of constants used by fldpi, fldln2, etc....  */
1795 static REAL_VALUE_TYPE ext_80387_constants_table [5];
1796 static bool ext_80387_constants_init = 0;
1797
1798 \f
1799 static struct machine_function * ix86_init_machine_status (void);
1800 static rtx ix86_function_value (const_tree, const_tree, bool);
1801 static int ix86_function_regparm (const_tree, const_tree);
1802 static void ix86_compute_frame_layout (struct ix86_frame *);
1803 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
1804                                                  rtx, rtx, int);
1805 static void ix86_add_new_builtins (int);
1806
1807 enum ix86_function_specific_strings
1808 {
1809   IX86_FUNCTION_SPECIFIC_ARCH,
1810   IX86_FUNCTION_SPECIFIC_TUNE,
1811   IX86_FUNCTION_SPECIFIC_FPMATH,
1812   IX86_FUNCTION_SPECIFIC_MAX
1813 };
1814
1815 static char *ix86_target_string (int, int, const char *, const char *,
1816                                  const char *, bool);
1817 static void ix86_debug_options (void) ATTRIBUTE_UNUSED;
1818 static void ix86_function_specific_save (struct cl_target_option *);
1819 static void ix86_function_specific_restore (struct cl_target_option *);
1820 static void ix86_function_specific_print (FILE *, int,
1821                                           struct cl_target_option *);
1822 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
1823 static bool ix86_valid_target_attribute_inner_p (tree, char *[]);
1824 static bool ix86_can_inline_p (tree, tree);
1825 static void ix86_set_current_function (tree);
1826
1827 \f
1828 /* The svr4 ABI for the i386 says that records and unions are returned
1829    in memory.  */
1830 #ifndef DEFAULT_PCC_STRUCT_RETURN
1831 #define DEFAULT_PCC_STRUCT_RETURN 1
1832 #endif
1833
1834 /* Whether -mtune= or -march= were specified */
1835 static int ix86_tune_defaulted;
1836 static int ix86_arch_specified;
1837
1838 /* Bit flags that specify the ISA we are compiling for.  */
1839 int ix86_isa_flags = TARGET_64BIT_DEFAULT | TARGET_SUBTARGET_ISA_DEFAULT;
1840
1841 /* A mask of ix86_isa_flags that includes bit X if X
1842    was set or cleared on the command line.  */
1843 static int ix86_isa_flags_explicit;
1844
1845 /* Define a set of ISAs which are available when a given ISA is
1846    enabled.  MMX and SSE ISAs are handled separately.  */
1847
1848 #define OPTION_MASK_ISA_MMX_SET OPTION_MASK_ISA_MMX
1849 #define OPTION_MASK_ISA_3DNOW_SET \
1850   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX_SET)
1851
1852 #define OPTION_MASK_ISA_SSE_SET OPTION_MASK_ISA_SSE
1853 #define OPTION_MASK_ISA_SSE2_SET \
1854   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE_SET)
1855 #define OPTION_MASK_ISA_SSE3_SET \
1856   (OPTION_MASK_ISA_SSE3 | OPTION_MASK_ISA_SSE2_SET)
1857 #define OPTION_MASK_ISA_SSSE3_SET \
1858   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE3_SET)
1859 #define OPTION_MASK_ISA_SSE4_1_SET \
1860   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSSE3_SET)
1861 #define OPTION_MASK_ISA_SSE4_2_SET \
1862   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_SSE4_1_SET)
1863 #define OPTION_MASK_ISA_AVX_SET \
1864   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_SSE4_2_SET)
1865 #define OPTION_MASK_ISA_FMA_SET \
1866   (OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_AVX_SET)
1867
1868 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
1869    as -msse4.2.  */
1870 #define OPTION_MASK_ISA_SSE4_SET OPTION_MASK_ISA_SSE4_2_SET
1871
1872 #define OPTION_MASK_ISA_SSE4A_SET \
1873   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE3_SET)
1874 #define OPTION_MASK_ISA_SSE5_SET \
1875   (OPTION_MASK_ISA_SSE5 | OPTION_MASK_ISA_SSE4A_SET)
1876
1877 /* AES and PCLMUL need SSE2 because they use xmm registers */
1878 #define OPTION_MASK_ISA_AES_SET \
1879   (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2_SET)
1880 #define OPTION_MASK_ISA_PCLMUL_SET \
1881   (OPTION_MASK_ISA_PCLMUL | OPTION_MASK_ISA_SSE2_SET)
1882
1883 #define OPTION_MASK_ISA_ABM_SET \
1884   (OPTION_MASK_ISA_ABM | OPTION_MASK_ISA_POPCNT)
1885 #define OPTION_MASK_ISA_POPCNT_SET OPTION_MASK_ISA_POPCNT
1886 #define OPTION_MASK_ISA_CX16_SET OPTION_MASK_ISA_CX16
1887 #define OPTION_MASK_ISA_SAHF_SET OPTION_MASK_ISA_SAHF
1888
1889 /* Define a set of ISAs which aren't available when a given ISA is
1890    disabled.  MMX and SSE ISAs are handled separately.  */
1891
1892 #define OPTION_MASK_ISA_MMX_UNSET \
1893   (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_3DNOW_UNSET)
1894 #define OPTION_MASK_ISA_3DNOW_UNSET \
1895   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_A_UNSET)
1896 #define OPTION_MASK_ISA_3DNOW_A_UNSET OPTION_MASK_ISA_3DNOW_A
1897
1898 #define OPTION_MASK_ISA_SSE_UNSET \
1899   (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_SSE2_UNSET)
1900 #define OPTION_MASK_ISA_SSE2_UNSET \
1901   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3_UNSET)
1902 #define OPTION_MASK_ISA_SSE3_UNSET \
1903   (OPTION_MASK_ISA_SSE3 \
1904    | OPTION_MASK_ISA_SSSE3_UNSET \
1905    | OPTION_MASK_ISA_SSE4A_UNSET )
1906 #define OPTION_MASK_ISA_SSSE3_UNSET \
1907   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE4_1_UNSET)
1908 #define OPTION_MASK_ISA_SSE4_1_UNSET \
1909   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_2_UNSET)
1910 #define OPTION_MASK_ISA_SSE4_2_UNSET \
1911   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_AVX_UNSET )
1912 #define OPTION_MASK_ISA_AVX_UNSET \
1913   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_FMA_UNSET)
1914 #define OPTION_MASK_ISA_FMA_UNSET OPTION_MASK_ISA_FMA
1915
1916 /* SSE4 includes both SSE4.1 and SSE4.2.  -mno-sse4 should the same
1917    as -mno-sse4.1. */
1918 #define OPTION_MASK_ISA_SSE4_UNSET OPTION_MASK_ISA_SSE4_1_UNSET
1919
1920 #define OPTION_MASK_ISA_SSE4A_UNSET \
1921   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE5_UNSET)
1922 #define OPTION_MASK_ISA_SSE5_UNSET OPTION_MASK_ISA_SSE5
1923 #define OPTION_MASK_ISA_AES_UNSET OPTION_MASK_ISA_AES
1924 #define OPTION_MASK_ISA_PCLMUL_UNSET OPTION_MASK_ISA_PCLMUL
1925 #define OPTION_MASK_ISA_ABM_UNSET OPTION_MASK_ISA_ABM
1926 #define OPTION_MASK_ISA_POPCNT_UNSET OPTION_MASK_ISA_POPCNT
1927 #define OPTION_MASK_ISA_CX16_UNSET OPTION_MASK_ISA_CX16
1928 #define OPTION_MASK_ISA_SAHF_UNSET OPTION_MASK_ISA_SAHF
1929
1930 /* Vectorization library interface and handlers.  */
1931 tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL;
1932 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
1933 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
1934
1935 /* Processor target table, indexed by processor number */
1936 struct ptt
1937 {
1938   const struct processor_costs *cost;           /* Processor costs */
1939   const int align_loop;                         /* Default alignments.  */
1940   const int align_loop_max_skip;
1941   const int align_jump;
1942   const int align_jump_max_skip;
1943   const int align_func;
1944 };
1945
1946 static const struct ptt processor_target_table[PROCESSOR_max] =
1947 {
1948   {&i386_cost, 4, 3, 4, 3, 4},
1949   {&i486_cost, 16, 15, 16, 15, 16},
1950   {&pentium_cost, 16, 7, 16, 7, 16},
1951   {&pentiumpro_cost, 16, 15, 16, 10, 16},
1952   {&geode_cost, 0, 0, 0, 0, 0},
1953   {&k6_cost, 32, 7, 32, 7, 32},
1954   {&athlon_cost, 16, 7, 16, 7, 16},
1955   {&pentium4_cost, 0, 0, 0, 0, 0},
1956   {&k8_cost, 16, 7, 16, 7, 16},
1957   {&nocona_cost, 0, 0, 0, 0, 0},
1958   {&core2_cost, 16, 10, 16, 10, 16},
1959   {&generic32_cost, 16, 7, 16, 7, 16},
1960   {&generic64_cost, 16, 10, 16, 10, 16},
1961   {&amdfam10_cost, 32, 24, 32, 7, 32}
1962 };
1963
1964 static const char *const cpu_names[TARGET_CPU_DEFAULT_max] =
1965 {
1966   "generic",
1967   "i386",
1968   "i486",
1969   "pentium",
1970   "pentium-mmx",
1971   "pentiumpro",
1972   "pentium2",
1973   "pentium3",
1974   "pentium4",
1975   "pentium-m",
1976   "prescott",
1977   "nocona",
1978   "core2",
1979   "geode",
1980   "k6",
1981   "k6-2",
1982   "k6-3",
1983   "athlon",
1984   "athlon-4",
1985   "k8",
1986   "amdfam10"
1987 };
1988 \f
1989 /* Implement TARGET_HANDLE_OPTION.  */
1990
1991 static bool
1992 ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value)
1993 {
1994   switch (code)
1995     {
1996     case OPT_mmmx:
1997       if (value)
1998         {
1999           ix86_isa_flags |= OPTION_MASK_ISA_MMX_SET;
2000           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_SET;
2001         }
2002       else
2003         {
2004           ix86_isa_flags &= ~OPTION_MASK_ISA_MMX_UNSET;
2005           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_UNSET;
2006         }
2007       return true;
2008
2009     case OPT_m3dnow:
2010       if (value)
2011         {
2012           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_SET;
2013           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_SET;
2014         }
2015       else
2016         {
2017           ix86_isa_flags &= ~OPTION_MASK_ISA_3DNOW_UNSET;
2018           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_UNSET;
2019         }
2020       return true;
2021
2022     case OPT_m3dnowa:
2023       return false;
2024
2025     case OPT_msse:
2026       if (value)
2027         {
2028           ix86_isa_flags |= OPTION_MASK_ISA_SSE_SET;
2029           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_SET;
2030         }
2031       else
2032         {
2033           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE_UNSET;
2034           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_UNSET;
2035         }
2036       return true;
2037
2038     case OPT_msse2:
2039       if (value)
2040         {
2041           ix86_isa_flags |= OPTION_MASK_ISA_SSE2_SET;
2042           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_SET;
2043         }
2044       else
2045         {
2046           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE2_UNSET;
2047           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_UNSET;
2048         }
2049       return true;
2050
2051     case OPT_msse3:
2052       if (value)
2053         {
2054           ix86_isa_flags |= OPTION_MASK_ISA_SSE3_SET;
2055           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_SET;
2056         }
2057       else
2058         {
2059           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE3_UNSET;
2060           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_UNSET;
2061         }
2062       return true;
2063
2064     case OPT_mssse3:
2065       if (value)
2066         {
2067           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3_SET;
2068           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_SET;
2069         }
2070       else
2071         {
2072           ix86_isa_flags &= ~OPTION_MASK_ISA_SSSE3_UNSET;
2073           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_UNSET;
2074         }
2075       return true;
2076
2077     case OPT_msse4_1:
2078       if (value)
2079         {
2080           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1_SET;
2081           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_SET;
2082         }
2083       else
2084         {
2085           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_1_UNSET;
2086           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_UNSET;
2087         }
2088       return true;
2089
2090     case OPT_msse4_2:
2091       if (value)
2092         {
2093           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2_SET;
2094           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_SET;
2095         }
2096       else
2097         {
2098           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_2_UNSET;
2099           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_UNSET;
2100         }
2101       return true;
2102
2103     case OPT_mavx:
2104       if (value)
2105         {
2106           ix86_isa_flags |= OPTION_MASK_ISA_AVX_SET;
2107           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_SET;
2108         }
2109       else
2110         {
2111           ix86_isa_flags &= ~OPTION_MASK_ISA_AVX_UNSET;
2112           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_UNSET;
2113         }
2114       return true;
2115
2116     case OPT_mfma:
2117       if (value)
2118         {
2119           ix86_isa_flags |= OPTION_MASK_ISA_FMA_SET;
2120           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_SET;
2121         }
2122       else
2123         {
2124           ix86_isa_flags &= ~OPTION_MASK_ISA_FMA_UNSET;
2125           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_UNSET;
2126         }
2127       return true;
2128
2129     case OPT_msse4:
2130       ix86_isa_flags |= OPTION_MASK_ISA_SSE4_SET;
2131       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_SET;
2132       return true;
2133
2134     case OPT_mno_sse4:
2135       ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
2136       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
2137       return true;
2138
2139     case OPT_msse4a:
2140       if (value)
2141         {
2142           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A_SET;
2143           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_SET;
2144         }
2145       else
2146         {
2147           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4A_UNSET;
2148           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_UNSET;
2149         }
2150       return true;
2151
2152     case OPT_msse5:
2153       if (value)
2154         {
2155           ix86_isa_flags |= OPTION_MASK_ISA_SSE5_SET;
2156           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_SET;
2157         }
2158       else
2159         {
2160           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE5_UNSET;
2161           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_UNSET;
2162         }
2163       return true;
2164
2165     case OPT_mabm:
2166       if (value)
2167         {
2168           ix86_isa_flags |= OPTION_MASK_ISA_ABM_SET;
2169           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_SET;
2170         }
2171       else
2172         {
2173           ix86_isa_flags &= ~OPTION_MASK_ISA_ABM_UNSET;
2174           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_UNSET;
2175         }
2176       return true;
2177
2178     case OPT_mpopcnt:
2179       if (value)
2180         {
2181           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT_SET;
2182           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_SET;
2183         }
2184       else
2185         {
2186           ix86_isa_flags &= ~OPTION_MASK_ISA_POPCNT_UNSET;
2187           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_UNSET;
2188         }
2189       return true;
2190
2191     case OPT_msahf:
2192       if (value)
2193         {
2194           ix86_isa_flags |= OPTION_MASK_ISA_SAHF_SET;
2195           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_SET;
2196         }
2197       else
2198         {
2199           ix86_isa_flags &= ~OPTION_MASK_ISA_SAHF_UNSET;
2200           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_UNSET;
2201         }
2202       return true;
2203
2204     case OPT_mcx16:
2205       if (value)
2206         {
2207           ix86_isa_flags |= OPTION_MASK_ISA_CX16_SET;
2208           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_SET;
2209         }
2210       else
2211         {
2212           ix86_isa_flags &= ~OPTION_MASK_ISA_CX16_UNSET;
2213           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_UNSET;
2214         }
2215       return true;
2216
2217     case OPT_maes:
2218       if (value)
2219         {
2220           ix86_isa_flags |= OPTION_MASK_ISA_AES_SET;
2221           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_SET;
2222         }
2223       else
2224         {
2225           ix86_isa_flags &= ~OPTION_MASK_ISA_AES_UNSET;
2226           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_UNSET;
2227         }
2228       return true;
2229
2230     case OPT_mpclmul:
2231       if (value)
2232         {
2233           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL_SET;
2234           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_SET;
2235         }
2236       else
2237         {
2238           ix86_isa_flags &= ~OPTION_MASK_ISA_PCLMUL_UNSET;
2239           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_UNSET;
2240         }
2241       return true;
2242
2243     default:
2244       return true;
2245     }
2246 }
2247 \f
2248 /* Return a string the documents the current -m options.  The caller is
2249    responsible for freeing the string.  */
2250
2251 static char *
2252 ix86_target_string (int isa, int flags, const char *arch, const char *tune,
2253                     const char *fpmath, bool add_nl_p)
2254 {
2255   struct ix86_target_opts
2256   {
2257     const char *option;         /* option string */
2258     int mask;                   /* isa mask options */
2259   };
2260
2261   /* This table is ordered so that options like -msse5 or -msse4.2 that imply
2262      preceding options while match those first.  */
2263   static struct ix86_target_opts isa_opts[] =
2264   {
2265     { "-m64",           OPTION_MASK_ISA_64BIT },
2266     { "-msse5",         OPTION_MASK_ISA_SSE5 },
2267     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2268     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2269     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2270     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2271     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2272     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2273     { "-msse",          OPTION_MASK_ISA_SSE },
2274     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2275     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2276     { "-mmmx",          OPTION_MASK_ISA_MMX },
2277     { "-mabm",          OPTION_MASK_ISA_ABM },
2278     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2279     { "-maes",          OPTION_MASK_ISA_AES },
2280     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2281   };
2282
2283   /* Flag options.  */
2284   static struct ix86_target_opts flag_opts[] =
2285   {
2286     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2287     { "-m80387",                        MASK_80387 },
2288     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2289     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2290     { "-mcld",                          MASK_CLD },
2291     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2292     { "-mieee-fp",                      MASK_IEEE_FP },
2293     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2294     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2295     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2296     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2297     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2298     { "-mno-fused-madd",                MASK_NO_FUSED_MADD },
2299     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2300     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2301     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2302     { "-mrecip",                        MASK_RECIP },
2303     { "-mrtd",                          MASK_RTD },
2304     { "-msseregparm",                   MASK_SSEREGPARM },
2305     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2306     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2307   };
2308
2309   const char *opts[ (sizeof (isa_opts) / sizeof (isa_opts[0])
2310                      + sizeof (flag_opts) / sizeof (flag_opts[0])
2311                      + 6)][2];
2312
2313   char isa_other[40];
2314   char target_other[40];
2315   unsigned num = 0;
2316   unsigned i, j;
2317   char *ret;
2318   char *ptr;
2319   size_t len;
2320   size_t line_len;
2321   size_t sep_len;
2322
2323   memset (opts, '\0', sizeof (opts));
2324
2325   /* Add -march= option.  */
2326   if (arch)
2327     {
2328       opts[num][0] = "-march=";
2329       opts[num++][1] = arch;
2330     }
2331
2332   /* Add -mtune= option.  */
2333   if (tune)
2334     {
2335       opts[num][0] = "-mtune=";
2336       opts[num++][1] = tune;
2337     }
2338
2339   /* Pick out the options in isa options.  */
2340   for (i = 0; i < sizeof (isa_opts) / sizeof (isa_opts[0]); i++)
2341     {
2342       if ((isa & isa_opts[i].mask) != 0)
2343         {
2344           opts[num++][0] = isa_opts[i].option;
2345           isa &= ~ isa_opts[i].mask;
2346         }
2347     }
2348
2349   if (isa && add_nl_p)
2350     {
2351       opts[num++][0] = isa_other;
2352       sprintf (isa_other, "(other isa: 0x%x)", isa);
2353     }
2354
2355   /* Add flag options.  */
2356   for (i = 0; i < sizeof (flag_opts) / sizeof (flag_opts[0]); i++)
2357     {
2358       if ((flags & flag_opts[i].mask) != 0)
2359         {
2360           opts[num++][0] = flag_opts[i].option;
2361           flags &= ~ flag_opts[i].mask;
2362         }
2363     }
2364
2365   if (flags && add_nl_p)
2366     {
2367       opts[num++][0] = target_other;
2368       sprintf (target_other, "(other flags: 0x%x)", isa);
2369     }
2370
2371   /* Add -fpmath= option.  */
2372   if (fpmath)
2373     {
2374       opts[num][0] = "-mfpmath=";
2375       opts[num++][1] = fpmath;
2376     }
2377
2378   /* Any options?  */
2379   if (num == 0)
2380     return NULL;
2381
2382   gcc_assert (num < sizeof (opts) / sizeof (opts[0]));
2383
2384   /* Size the string.  */
2385   len = 0;
2386   sep_len = (add_nl_p) ? 3 : 1;
2387   for (i = 0; i < num; i++)
2388     {
2389       len += sep_len;
2390       for (j = 0; j < 2; j++)
2391         if (opts[i][j])
2392           len += strlen (opts[i][j]);
2393     }
2394
2395   /* Build the string.  */
2396   ret = ptr = (char *) xmalloc (len);
2397   line_len = 0;
2398
2399   for (i = 0; i < num; i++)
2400     {
2401       size_t len2[2];
2402
2403       for (j = 0; j < 2; j++)
2404         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2405
2406       if (i != 0)
2407         {
2408           *ptr++ = ' ';
2409           line_len++;
2410
2411           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2412             {
2413               *ptr++ = '\\';
2414               *ptr++ = '\n';
2415               line_len = 0;
2416             }
2417         }
2418
2419       for (j = 0; j < 2; j++)
2420         if (opts[i][j])
2421           {
2422             memcpy (ptr, opts[i][j], len2[j]);
2423             ptr += len2[j];
2424             line_len += len2[j];
2425           }
2426     }
2427
2428   *ptr = '\0';
2429   gcc_assert (ret + len >= ptr);
2430
2431   return ret;
2432 }
2433
2434 /* Function that is callable from the debugger to print the current
2435    options.  */
2436 void
2437 ix86_debug_options (void)
2438 {
2439   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2440                                    ix86_arch_string, ix86_tune_string,
2441                                    ix86_fpmath_string, true);
2442
2443   if (opts)
2444     {
2445       fprintf (stderr, "%s\n\n", opts);
2446       free (opts);
2447     }
2448   else
2449     fprintf (stderr, "<no options>\n\n");
2450
2451   return;
2452 }
2453 \f
2454 /* Sometimes certain combinations of command options do not make
2455    sense on a particular target machine.  You can define a macro
2456    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
2457    defined, is executed once just after all the command options have
2458    been parsed.
2459
2460    Don't use this macro to turn on various extra optimizations for
2461    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
2462
2463 void
2464 override_options (bool main_args_p)
2465 {
2466   int i;
2467   unsigned int ix86_arch_mask, ix86_tune_mask;
2468   const char *prefix;
2469   const char *suffix;
2470   const char *sw;
2471
2472   /* Comes from final.c -- no real reason to change it.  */
2473 #define MAX_CODE_ALIGN 16
2474
2475   enum pta_flags
2476     {
2477       PTA_SSE = 1 << 0,
2478       PTA_SSE2 = 1 << 1,
2479       PTA_SSE3 = 1 << 2,
2480       PTA_MMX = 1 << 3,
2481       PTA_PREFETCH_SSE = 1 << 4,
2482       PTA_3DNOW = 1 << 5,
2483       PTA_3DNOW_A = 1 << 6,
2484       PTA_64BIT = 1 << 7,
2485       PTA_SSSE3 = 1 << 8,
2486       PTA_CX16 = 1 << 9,
2487       PTA_POPCNT = 1 << 10,
2488       PTA_ABM = 1 << 11,
2489       PTA_SSE4A = 1 << 12,
2490       PTA_NO_SAHF = 1 << 13,
2491       PTA_SSE4_1 = 1 << 14,
2492       PTA_SSE4_2 = 1 << 15,
2493       PTA_SSE5 = 1 << 16,
2494       PTA_AES = 1 << 17,
2495       PTA_PCLMUL = 1 << 18,
2496       PTA_AVX = 1 << 19,
2497       PTA_FMA = 1 << 20 
2498     };
2499
2500   static struct pta
2501     {
2502       const char *const name;           /* processor name or nickname.  */
2503       const enum processor_type processor;
2504       const enum attr_cpu schedule;
2505       const unsigned /*enum pta_flags*/ flags;
2506     }
2507   const processor_alias_table[] =
2508     {
2509       {"i386", PROCESSOR_I386, CPU_NONE, 0},
2510       {"i486", PROCESSOR_I486, CPU_NONE, 0},
2511       {"i586", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
2512       {"pentium", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
2513       {"pentium-mmx", PROCESSOR_PENTIUM, CPU_PENTIUM, PTA_MMX},
2514       {"winchip-c6", PROCESSOR_I486, CPU_NONE, PTA_MMX},
2515       {"winchip2", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW},
2516       {"c3", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW},
2517       {"c3-2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX | PTA_SSE},
2518       {"i686", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
2519       {"pentiumpro", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
2520       {"pentium2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX},
2521       {"pentium3", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2522         PTA_MMX | PTA_SSE},
2523       {"pentium3m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2524         PTA_MMX | PTA_SSE},
2525       {"pentium-m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2526         PTA_MMX | PTA_SSE | PTA_SSE2},
2527       {"pentium4", PROCESSOR_PENTIUM4, CPU_NONE,
2528         PTA_MMX |PTA_SSE | PTA_SSE2},
2529       {"pentium4m", PROCESSOR_PENTIUM4, CPU_NONE,
2530         PTA_MMX | PTA_SSE | PTA_SSE2},
2531       {"prescott", PROCESSOR_NOCONA, CPU_NONE,
2532         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3},
2533       {"nocona", PROCESSOR_NOCONA, CPU_NONE,
2534         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2535         | PTA_CX16 | PTA_NO_SAHF},
2536       {"core2", PROCESSOR_CORE2, CPU_CORE2,
2537         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2538         | PTA_SSSE3 | PTA_CX16},
2539       {"geode", PROCESSOR_GEODE, CPU_GEODE,
2540         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A |PTA_PREFETCH_SSE},
2541       {"k6", PROCESSOR_K6, CPU_K6, PTA_MMX},
2542       {"k6-2", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW},
2543       {"k6-3", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW},
2544       {"athlon", PROCESSOR_ATHLON, CPU_ATHLON,
2545         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE},
2546       {"athlon-tbird", PROCESSOR_ATHLON, CPU_ATHLON,
2547         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE},
2548       {"athlon-4", PROCESSOR_ATHLON, CPU_ATHLON,
2549         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2550       {"athlon-xp", PROCESSOR_ATHLON, CPU_ATHLON,
2551         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2552       {"athlon-mp", PROCESSOR_ATHLON, CPU_ATHLON,
2553         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2554       {"x86-64", PROCESSOR_K8, CPU_K8,
2555         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_NO_SAHF},
2556       {"k8", PROCESSOR_K8, CPU_K8,
2557         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2558         | PTA_SSE2 | PTA_NO_SAHF},
2559       {"k8-sse3", PROCESSOR_K8, CPU_K8,
2560         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2561         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2562       {"opteron", PROCESSOR_K8, CPU_K8,
2563         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2564         | PTA_SSE2 | PTA_NO_SAHF},
2565       {"opteron-sse3", PROCESSOR_K8, CPU_K8,
2566         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2567         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2568       {"athlon64", PROCESSOR_K8, CPU_K8,
2569         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2570         | PTA_SSE2 | PTA_NO_SAHF},
2571       {"athlon64-sse3", PROCESSOR_K8, CPU_K8,
2572         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2573         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2574       {"athlon-fx", PROCESSOR_K8, CPU_K8,
2575         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2576         | PTA_SSE2 | PTA_NO_SAHF},
2577       {"amdfam10", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
2578         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2579         | PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM},
2580       {"barcelona", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
2581         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2582         | PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM},
2583       {"generic32", PROCESSOR_GENERIC32, CPU_PENTIUMPRO,
2584         0 /* flags are only used for -march switch.  */ },
2585       {"generic64", PROCESSOR_GENERIC64, CPU_GENERIC64,
2586         PTA_64BIT /* flags are only used for -march switch.  */ },
2587     };
2588
2589   int const pta_size = ARRAY_SIZE (processor_alias_table);
2590
2591   /* Set up prefix/suffix so the error messages refer to either the command
2592      line argument, or the attribute(target).  */
2593   if (main_args_p)
2594     {
2595       prefix = "-m";
2596       suffix = "";
2597       sw = "switch";
2598     }
2599   else
2600     {
2601       prefix = "option(\"";
2602       suffix = "\")";
2603       sw = "attribute";
2604     }
2605
2606 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2607   SUBTARGET_OVERRIDE_OPTIONS;
2608 #endif
2609
2610 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2611   SUBSUBTARGET_OVERRIDE_OPTIONS;
2612 #endif
2613
2614   /* -fPIC is the default for x86_64.  */
2615   if (TARGET_MACHO && TARGET_64BIT)
2616     flag_pic = 2;
2617
2618   /* Set the default values for switches whose default depends on TARGET_64BIT
2619      in case they weren't overwritten by command line options.  */
2620   if (TARGET_64BIT)
2621     {
2622       /* Mach-O doesn't support omitting the frame pointer for now.  */
2623       if (flag_omit_frame_pointer == 2)
2624         flag_omit_frame_pointer = (TARGET_MACHO ? 0 : 1);
2625       if (flag_asynchronous_unwind_tables == 2)
2626         flag_asynchronous_unwind_tables = 1;
2627       if (flag_pcc_struct_return == 2)
2628         flag_pcc_struct_return = 0;
2629     }
2630   else
2631     {
2632       if (flag_omit_frame_pointer == 2)
2633         flag_omit_frame_pointer = 0;
2634       if (flag_asynchronous_unwind_tables == 2)
2635         flag_asynchronous_unwind_tables = 0;
2636       if (flag_pcc_struct_return == 2)
2637         flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
2638     }
2639
2640   /* Need to check -mtune=generic first.  */
2641   if (ix86_tune_string)
2642     {
2643       if (!strcmp (ix86_tune_string, "generic")
2644           || !strcmp (ix86_tune_string, "i686")
2645           /* As special support for cross compilers we read -mtune=native
2646              as -mtune=generic.  With native compilers we won't see the
2647              -mtune=native, as it was changed by the driver.  */
2648           || !strcmp (ix86_tune_string, "native"))
2649         {
2650           if (TARGET_64BIT)
2651             ix86_tune_string = "generic64";
2652           else
2653             ix86_tune_string = "generic32";
2654         }
2655       /* If this call is for setting the option attribute, allow the
2656          generic32/generic64 that was previously set.  */
2657       else if (!main_args_p
2658                && (!strcmp (ix86_tune_string, "generic32")
2659                    || !strcmp (ix86_tune_string, "generic64")))
2660         ;
2661       else if (!strncmp (ix86_tune_string, "generic", 7))
2662         error ("bad value (%s) for %stune=%s %s",
2663                ix86_tune_string, prefix, suffix, sw);
2664     }
2665   else
2666     {
2667       if (ix86_arch_string)
2668         ix86_tune_string = ix86_arch_string;
2669       if (!ix86_tune_string)
2670         {
2671           ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT];
2672           ix86_tune_defaulted = 1;
2673         }
2674
2675       /* ix86_tune_string is set to ix86_arch_string or defaulted.  We
2676          need to use a sensible tune option.  */
2677       if (!strcmp (ix86_tune_string, "generic")
2678           || !strcmp (ix86_tune_string, "x86-64")
2679           || !strcmp (ix86_tune_string, "i686"))
2680         {
2681           if (TARGET_64BIT)
2682             ix86_tune_string = "generic64";
2683           else
2684             ix86_tune_string = "generic32";
2685         }
2686     }
2687   if (ix86_stringop_string)
2688     {
2689       if (!strcmp (ix86_stringop_string, "rep_byte"))
2690         stringop_alg = rep_prefix_1_byte;
2691       else if (!strcmp (ix86_stringop_string, "libcall"))
2692         stringop_alg = libcall;
2693       else if (!strcmp (ix86_stringop_string, "rep_4byte"))
2694         stringop_alg = rep_prefix_4_byte;
2695       else if (!strcmp (ix86_stringop_string, "rep_8byte"))
2696         stringop_alg = rep_prefix_8_byte;
2697       else if (!strcmp (ix86_stringop_string, "byte_loop"))
2698         stringop_alg = loop_1_byte;
2699       else if (!strcmp (ix86_stringop_string, "loop"))
2700         stringop_alg = loop;
2701       else if (!strcmp (ix86_stringop_string, "unrolled_loop"))
2702         stringop_alg = unrolled_loop;
2703       else
2704         error ("bad value (%s) for %sstringop-strategy=%s %s",
2705                ix86_stringop_string, prefix, suffix, sw);
2706     }
2707   if (!strcmp (ix86_tune_string, "x86-64"))
2708     warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated.  Use "
2709              "%stune=k8%s or %stune=generic%s instead as appropriate.",
2710              prefix, suffix, prefix, suffix, prefix, suffix);
2711
2712   if (!ix86_arch_string)
2713     ix86_arch_string = TARGET_64BIT ? "x86-64" : "i386";
2714   else
2715     ix86_arch_specified = 1;
2716
2717   if (!strcmp (ix86_arch_string, "generic"))
2718     error ("generic CPU can be used only for %stune=%s %s",
2719            prefix, suffix, sw);
2720   if (!strncmp (ix86_arch_string, "generic", 7))
2721     error ("bad value (%s) for %sarch=%s %s",
2722            ix86_arch_string, prefix, suffix, sw);
2723
2724   if (ix86_cmodel_string != 0)
2725     {
2726       if (!strcmp (ix86_cmodel_string, "small"))
2727         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2728       else if (!strcmp (ix86_cmodel_string, "medium"))
2729         ix86_cmodel = flag_pic ? CM_MEDIUM_PIC : CM_MEDIUM;
2730       else if (!strcmp (ix86_cmodel_string, "large"))
2731         ix86_cmodel = flag_pic ? CM_LARGE_PIC : CM_LARGE;
2732       else if (flag_pic)
2733         error ("code model %s does not support PIC mode", ix86_cmodel_string);
2734       else if (!strcmp (ix86_cmodel_string, "32"))
2735         ix86_cmodel = CM_32;
2736       else if (!strcmp (ix86_cmodel_string, "kernel") && !flag_pic)
2737         ix86_cmodel = CM_KERNEL;
2738       else
2739         error ("bad value (%s) for %scmodel=%s %s",
2740                ix86_cmodel_string, prefix, suffix, sw);
2741     }
2742   else
2743     {
2744       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
2745          use of rip-relative addressing.  This eliminates fixups that
2746          would otherwise be needed if this object is to be placed in a
2747          DLL, and is essentially just as efficient as direct addressing.  */
2748       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
2749         ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
2750       else if (TARGET_64BIT)
2751         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2752       else
2753         ix86_cmodel = CM_32;
2754     }
2755   if (ix86_asm_string != 0)
2756     {
2757       if (! TARGET_MACHO
2758           && !strcmp (ix86_asm_string, "intel"))
2759         ix86_asm_dialect = ASM_INTEL;
2760       else if (!strcmp (ix86_asm_string, "att"))
2761         ix86_asm_dialect = ASM_ATT;
2762       else
2763         error ("bad value (%s) for %sasm=%s %s",
2764                ix86_asm_string, prefix, suffix, sw);
2765     }
2766   if ((TARGET_64BIT == 0) != (ix86_cmodel == CM_32))
2767     error ("code model %qs not supported in the %s bit mode",
2768            ix86_cmodel_string, TARGET_64BIT ? "64" : "32");
2769   if ((TARGET_64BIT != 0) != ((ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2770     sorry ("%i-bit mode not compiled in",
2771            (ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2772
2773   for (i = 0; i < pta_size; i++)
2774     if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
2775       {
2776         ix86_schedule = processor_alias_table[i].schedule;
2777         ix86_arch = processor_alias_table[i].processor;
2778         /* Default cpu tuning to the architecture.  */
2779         ix86_tune = ix86_arch;
2780
2781         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2782           error ("CPU you selected does not support x86-64 "
2783                  "instruction set");
2784
2785         if (processor_alias_table[i].flags & PTA_MMX
2786             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
2787           ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2788         if (processor_alias_table[i].flags & PTA_3DNOW
2789             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
2790           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
2791         if (processor_alias_table[i].flags & PTA_3DNOW_A
2792             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
2793           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
2794         if (processor_alias_table[i].flags & PTA_SSE
2795             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
2796           ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2797         if (processor_alias_table[i].flags & PTA_SSE2
2798             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
2799           ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2800         if (processor_alias_table[i].flags & PTA_SSE3
2801             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
2802           ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2803         if (processor_alias_table[i].flags & PTA_SSSE3
2804             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
2805           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2806         if (processor_alias_table[i].flags & PTA_SSE4_1
2807             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
2808           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2809         if (processor_alias_table[i].flags & PTA_SSE4_2
2810             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
2811           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
2812         if (processor_alias_table[i].flags & PTA_AVX
2813             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
2814           ix86_isa_flags |= OPTION_MASK_ISA_AVX;
2815         if (processor_alias_table[i].flags & PTA_FMA
2816             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
2817           ix86_isa_flags |= OPTION_MASK_ISA_FMA;
2818         if (processor_alias_table[i].flags & PTA_SSE4A
2819             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
2820           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2821         if (processor_alias_table[i].flags & PTA_SSE5
2822             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE5))
2823           ix86_isa_flags |= OPTION_MASK_ISA_SSE5;
2824         if (processor_alias_table[i].flags & PTA_ABM
2825             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
2826           ix86_isa_flags |= OPTION_MASK_ISA_ABM;
2827         if (processor_alias_table[i].flags & PTA_CX16
2828             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
2829           ix86_isa_flags |= OPTION_MASK_ISA_CX16;
2830         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
2831             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
2832           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
2833         if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF))
2834             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
2835           ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
2836         if (processor_alias_table[i].flags & PTA_AES
2837             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
2838           ix86_isa_flags |= OPTION_MASK_ISA_AES;
2839         if (processor_alias_table[i].flags & PTA_PCLMUL
2840             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
2841           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
2842         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
2843           x86_prefetch_sse = true;
2844
2845         break;
2846       }
2847
2848   if (i == pta_size)
2849     error ("bad value (%s) for %sarch=%s %s",
2850            ix86_arch_string, prefix, suffix, sw);
2851
2852   ix86_arch_mask = 1u << ix86_arch;
2853   for (i = 0; i < X86_ARCH_LAST; ++i)
2854     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
2855
2856   for (i = 0; i < pta_size; i++)
2857     if (! strcmp (ix86_tune_string, processor_alias_table[i].name))
2858       {
2859         ix86_schedule = processor_alias_table[i].schedule;
2860         ix86_tune = processor_alias_table[i].processor;
2861         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2862           {
2863             if (ix86_tune_defaulted)
2864               {
2865                 ix86_tune_string = "x86-64";
2866                 for (i = 0; i < pta_size; i++)
2867                   if (! strcmp (ix86_tune_string,
2868                                 processor_alias_table[i].name))
2869                     break;
2870                 ix86_schedule = processor_alias_table[i].schedule;
2871                 ix86_tune = processor_alias_table[i].processor;
2872               }
2873             else
2874               error ("CPU you selected does not support x86-64 "
2875                      "instruction set");
2876           }
2877         /* Intel CPUs have always interpreted SSE prefetch instructions as
2878            NOPs; so, we can enable SSE prefetch instructions even when
2879            -mtune (rather than -march) points us to a processor that has them.
2880            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
2881            higher processors.  */
2882         if (TARGET_CMOVE
2883             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
2884           x86_prefetch_sse = true;
2885         break;
2886       }
2887   if (i == pta_size)
2888     error ("bad value (%s) for %stune=%s %s",
2889            ix86_tune_string, prefix, suffix, sw);
2890
2891   ix86_tune_mask = 1u << ix86_tune;
2892   for (i = 0; i < X86_TUNE_LAST; ++i)
2893     ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
2894
2895   if (optimize_size)
2896     ix86_cost = &ix86_size_cost;
2897   else
2898     ix86_cost = processor_target_table[ix86_tune].cost;
2899
2900   /* Arrange to set up i386_stack_locals for all functions.  */
2901   init_machine_status = ix86_init_machine_status;
2902
2903   /* Validate -mregparm= value.  */
2904   if (ix86_regparm_string)
2905     {
2906       if (TARGET_64BIT)
2907         warning (0, "%sregparm%s is ignored in 64-bit mode", prefix, suffix);
2908       i = atoi (ix86_regparm_string);
2909       if (i < 0 || i > REGPARM_MAX)
2910         error ("%sregparm=%d%s is not between 0 and %d",
2911                prefix, i, suffix, REGPARM_MAX);
2912       else
2913         ix86_regparm = i;
2914     }
2915   if (TARGET_64BIT)
2916     ix86_regparm = REGPARM_MAX;
2917
2918   /* If the user has provided any of the -malign-* options,
2919      warn and use that value only if -falign-* is not set.
2920      Remove this code in GCC 3.2 or later.  */
2921   if (ix86_align_loops_string)
2922     {
2923       warning (0, "%salign-loops%s is obsolete, use %salign-loops%s",
2924                prefix, suffix, prefix, suffix);
2925       if (align_loops == 0)
2926         {
2927           i = atoi (ix86_align_loops_string);
2928           if (i < 0 || i > MAX_CODE_ALIGN)
2929             error ("%salign-loops=%d%s is not between 0 and %d",
2930                    prefix, i, suffix, MAX_CODE_ALIGN);
2931           else
2932             align_loops = 1 << i;
2933         }
2934     }
2935
2936   if (ix86_align_jumps_string)
2937     {
2938       warning (0, "%salign-jumps%s is obsolete, use %salign-jumps%s",
2939                prefix, suffix, prefix, suffix);
2940       if (align_jumps == 0)
2941         {
2942           i = atoi (ix86_align_jumps_string);
2943           if (i < 0 || i > MAX_CODE_ALIGN)
2944             error ("%salign-loops=%d%s is not between 0 and %d",
2945                    prefix, i, suffix, MAX_CODE_ALIGN);
2946           else
2947             align_jumps = 1 << i;
2948         }
2949     }
2950
2951   if (ix86_align_funcs_string)
2952     {
2953       warning (0, "%salign-functions%s is obsolete, use %salign-functions%s",
2954                prefix, suffix, prefix, suffix);
2955       if (align_functions == 0)
2956         {
2957           i = atoi (ix86_align_funcs_string);
2958           if (i < 0 || i > MAX_CODE_ALIGN)
2959             error ("%salign-loops=%d%s is not between 0 and %d",
2960                    prefix, i, suffix, MAX_CODE_ALIGN);
2961           else
2962             align_functions = 1 << i;
2963         }
2964     }
2965
2966   /* Default align_* from the processor table.  */
2967   if (align_loops == 0)
2968     {
2969       align_loops = processor_target_table[ix86_tune].align_loop;
2970       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
2971     }
2972   if (align_jumps == 0)
2973     {
2974       align_jumps = processor_target_table[ix86_tune].align_jump;
2975       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
2976     }
2977   if (align_functions == 0)
2978     {
2979       align_functions = processor_target_table[ix86_tune].align_func;
2980     }
2981
2982   /* Validate -mbranch-cost= value, or provide default.  */
2983   ix86_branch_cost = ix86_cost->branch_cost;
2984   if (ix86_branch_cost_string)
2985     {
2986       i = atoi (ix86_branch_cost_string);
2987       if (i < 0 || i > 5)
2988         error ("%sbranch-cost=%d%s is not between 0 and 5", prefix, i, suffix);
2989       else
2990         ix86_branch_cost = i;
2991     }
2992   if (ix86_section_threshold_string)
2993     {
2994       i = atoi (ix86_section_threshold_string);
2995       if (i < 0)
2996         error ("%slarge-data-threshold=%d%s is negative", prefix, i, suffix);
2997       else
2998         ix86_section_threshold = i;
2999     }
3000
3001   if (ix86_tls_dialect_string)
3002     {
3003       if (strcmp (ix86_tls_dialect_string, "gnu") == 0)
3004         ix86_tls_dialect = TLS_DIALECT_GNU;
3005       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
3006         ix86_tls_dialect = TLS_DIALECT_GNU2;
3007       else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
3008         ix86_tls_dialect = TLS_DIALECT_SUN;
3009       else
3010         error ("bad value (%s) for %stls-dialect=%s %s",
3011                ix86_tls_dialect_string, prefix, suffix, sw);
3012     }
3013
3014   if (ix87_precision_string)
3015     {
3016       i = atoi (ix87_precision_string);
3017       if (i != 32 && i != 64 && i != 80)
3018         error ("pc%d is not valid precision setting (32, 64 or 80)", i);
3019     }
3020
3021   if (TARGET_64BIT)
3022     {
3023       target_flags |= TARGET_SUBTARGET64_DEFAULT & ~target_flags_explicit;
3024
3025       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3026          explicitly disable any of these.  In particular, disabling SSE and
3027          MMX for kernel code is extremely useful.  */
3028       if (!ix86_arch_specified)
3029       ix86_isa_flags
3030         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3031              | TARGET_SUBTARGET64_ISA_DEFAULT) & ~ix86_isa_flags_explicit);
3032
3033       if (TARGET_RTD)
3034         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3035     }
3036   else
3037     {
3038       target_flags |= TARGET_SUBTARGET32_DEFAULT & ~target_flags_explicit;
3039
3040       if (!ix86_arch_specified)
3041       ix86_isa_flags
3042         |= TARGET_SUBTARGET32_ISA_DEFAULT & ~ix86_isa_flags_explicit;
3043
3044       /* i386 ABI does not specify red zone.  It still makes sense to use it
3045          when programmer takes care to stack from being destroyed.  */
3046       if (!(target_flags_explicit & MASK_NO_RED_ZONE))
3047         target_flags |= MASK_NO_RED_ZONE;
3048     }
3049
3050   /* Keep nonleaf frame pointers.  */
3051   if (flag_omit_frame_pointer)
3052     target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3053   else if (TARGET_OMIT_LEAF_FRAME_POINTER)
3054     flag_omit_frame_pointer = 1;
3055
3056   /* If we're doing fast math, we don't care about comparison order
3057      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3058   if (flag_finite_math_only)
3059     target_flags &= ~MASK_IEEE_FP;
3060
3061   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3062      since the insns won't need emulation.  */
3063   if (x86_arch_always_fancy_math_387 & ix86_arch_mask)
3064     target_flags &= ~MASK_NO_FANCY_MATH_387;
3065
3066   /* Likewise, if the target doesn't have a 387, or we've specified
3067      software floating point, don't use 387 inline intrinsics.  */
3068   if (!TARGET_80387)
3069     target_flags |= MASK_NO_FANCY_MATH_387;
3070
3071   /* Turn on MMX builtins for -msse.  */
3072   if (TARGET_SSE)
3073     {
3074       ix86_isa_flags |= OPTION_MASK_ISA_MMX & ~ix86_isa_flags_explicit;
3075       x86_prefetch_sse = true;
3076     }
3077
3078   /* Turn on popcnt instruction for -msse4.2 or -mabm.  */
3079   if (TARGET_SSE4_2 || TARGET_ABM)
3080     ix86_isa_flags |= OPTION_MASK_ISA_POPCNT & ~ix86_isa_flags_explicit;
3081
3082   /* Validate -mpreferred-stack-boundary= value or default it to
3083      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
3084   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
3085   if (ix86_preferred_stack_boundary_string)
3086     {
3087       i = atoi (ix86_preferred_stack_boundary_string);
3088       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3089         error ("%spreferred-stack-boundary=%d%s is not between %d and 12",
3090                prefix, i, suffix, TARGET_64BIT ? 4 : 2);
3091       else
3092         ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
3093     }
3094
3095   /* Set the default value for -mstackrealign.  */
3096   if (ix86_force_align_arg_pointer == -1)
3097     ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
3098
3099   /* Validate -mincoming-stack-boundary= value or default it to
3100      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
3101   if (ix86_force_align_arg_pointer)
3102     ix86_default_incoming_stack_boundary = MIN_STACK_BOUNDARY;
3103   else
3104     ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
3105   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
3106   if (ix86_incoming_stack_boundary_string)
3107     {
3108       i = atoi (ix86_incoming_stack_boundary_string);
3109       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3110         error ("-mincoming-stack-boundary=%d is not between %d and 12",
3111                i, TARGET_64BIT ? 4 : 2);
3112       else
3113         {
3114           ix86_user_incoming_stack_boundary = (1 << i) * BITS_PER_UNIT;
3115           ix86_incoming_stack_boundary
3116             = ix86_user_incoming_stack_boundary;
3117         }
3118     }
3119
3120   /* Accept -msseregparm only if at least SSE support is enabled.  */
3121   if (TARGET_SSEREGPARM
3122       && ! TARGET_SSE)
3123     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
3124
3125   ix86_fpmath = TARGET_FPMATH_DEFAULT;
3126   if (ix86_fpmath_string != 0)
3127     {
3128       if (! strcmp (ix86_fpmath_string, "387"))
3129         ix86_fpmath = FPMATH_387;
3130       else if (! strcmp (ix86_fpmath_string, "sse"))
3131         {
3132           if (!TARGET_SSE)
3133             {
3134               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3135               ix86_fpmath = FPMATH_387;
3136             }
3137           else
3138             ix86_fpmath = FPMATH_SSE;
3139         }
3140       else if (! strcmp (ix86_fpmath_string, "387,sse")
3141                || ! strcmp (ix86_fpmath_string, "387+sse")
3142                || ! strcmp (ix86_fpmath_string, "sse,387")
3143                || ! strcmp (ix86_fpmath_string, "sse+387")
3144                || ! strcmp (ix86_fpmath_string, "both"))
3145         {
3146           if (!TARGET_SSE)
3147             {
3148               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3149               ix86_fpmath = FPMATH_387;
3150             }
3151           else if (!TARGET_80387)
3152             {
3153               warning (0, "387 instruction set disabled, using SSE arithmetics");
3154               ix86_fpmath = FPMATH_SSE;
3155             }
3156           else
3157             ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
3158         }
3159       else
3160         error ("bad value (%s) for %sfpmath=%s %s",
3161                ix86_fpmath_string, prefix, suffix, sw);
3162     }
3163
3164   /* If the i387 is disabled, then do not return values in it. */
3165   if (!TARGET_80387)
3166     target_flags &= ~MASK_FLOAT_RETURNS;
3167
3168   /* Use external vectorized library in vectorizing intrinsics.  */
3169   if (ix86_veclibabi_string)
3170     {
3171       if (strcmp (ix86_veclibabi_string, "svml") == 0)
3172         ix86_veclib_handler = ix86_veclibabi_svml;
3173       else if (strcmp (ix86_veclibabi_string, "acml") == 0)
3174         ix86_veclib_handler = ix86_veclibabi_acml;
3175       else
3176         error ("unknown vectorization library ABI type (%s) for "
3177                "%sveclibabi=%s %s", ix86_veclibabi_string,
3178                prefix, suffix, sw);
3179     }
3180
3181   if ((x86_accumulate_outgoing_args & ix86_tune_mask)
3182       && !(target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3183       && !optimize_size)
3184     target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3185
3186   /* ??? Unwind info is not correct around the CFG unless either a frame
3187      pointer is present or M_A_O_A is set.  Fixing this requires rewriting
3188      unwind info generation to be aware of the CFG and propagating states
3189      around edges.  */
3190   if ((flag_unwind_tables || flag_asynchronous_unwind_tables
3191        || flag_exceptions || flag_non_call_exceptions)
3192       && flag_omit_frame_pointer
3193       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3194     {
3195       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3196         warning (0, "unwind tables currently require either a frame pointer "
3197                  "or %saccumulate-outgoing-args%s for correctness",
3198                  prefix, suffix);
3199       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3200     }
3201
3202   /* If stack probes are required, the space used for large function
3203      arguments on the stack must also be probed, so enable
3204      -maccumulate-outgoing-args so this happens in the prologue.  */
3205   if (TARGET_STACK_PROBE
3206       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3207     {
3208       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3209         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
3210                  "for correctness", prefix, suffix);
3211       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3212     }
3213
3214   /* For sane SSE instruction set generation we need fcomi instruction.
3215      It is safe to enable all CMOVE instructions.  */
3216   if (TARGET_SSE)
3217     TARGET_CMOVE = 1;
3218
3219   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
3220   {
3221     char *p;
3222     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
3223     p = strchr (internal_label_prefix, 'X');
3224     internal_label_prefix_len = p - internal_label_prefix;
3225     *p = '\0';
3226   }
3227
3228   /* When scheduling description is not available, disable scheduler pass
3229      so it won't slow down the compilation and make x87 code slower.  */
3230   if (!TARGET_SCHEDULE)
3231     flag_schedule_insns_after_reload = flag_schedule_insns = 0;
3232
3233   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
3234     set_param_value ("simultaneous-prefetches",
3235                      ix86_cost->simultaneous_prefetches);
3236   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
3237     set_param_value ("l1-cache-line-size", ix86_cost->prefetch_block);
3238   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
3239     set_param_value ("l1-cache-size", ix86_cost->l1_cache_size);
3240   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
3241     set_param_value ("l2-cache-size", ix86_cost->l2_cache_size);
3242
3243   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
3244      can be optimized to ap = __builtin_next_arg (0).  */
3245   if (!TARGET_64BIT)
3246     targetm.expand_builtin_va_start = NULL;
3247
3248   if (TARGET_64BIT)
3249     {
3250       ix86_gen_leave = gen_leave_rex64;
3251       ix86_gen_pop1 = gen_popdi1;
3252       ix86_gen_add3 = gen_adddi3;
3253       ix86_gen_sub3 = gen_subdi3;
3254       ix86_gen_sub3_carry = gen_subdi3_carry_rex64;
3255       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
3256       ix86_gen_monitor = gen_sse3_monitor64;
3257       ix86_gen_andsp = gen_anddi3;
3258     }
3259   else
3260     {
3261       ix86_gen_leave = gen_leave;
3262       ix86_gen_pop1 = gen_popsi1;
3263       ix86_gen_add3 = gen_addsi3;
3264       ix86_gen_sub3 = gen_subsi3;
3265       ix86_gen_sub3_carry = gen_subsi3_carry;
3266       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
3267       ix86_gen_monitor = gen_sse3_monitor;
3268       ix86_gen_andsp = gen_andsi3;
3269     }
3270
3271 #ifdef USE_IX86_CLD
3272   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
3273   if (!TARGET_64BIT)
3274     target_flags |= MASK_CLD & ~target_flags_explicit;
3275 #endif
3276
3277   /* Save the initial options in case the user does function specific options */
3278   if (main_args_p)
3279     target_option_default_node = target_option_current_node
3280       = build_target_option_node ();
3281 }
3282 \f
3283 /* Save the current options */
3284
3285 static void
3286 ix86_function_specific_save (struct cl_target_option *ptr)
3287 {
3288   gcc_assert (IN_RANGE (ix86_arch, 0, 255));
3289   gcc_assert (IN_RANGE (ix86_schedule, 0, 255));
3290   gcc_assert (IN_RANGE (ix86_tune, 0, 255));
3291   gcc_assert (IN_RANGE (ix86_fpmath, 0, 255));
3292   gcc_assert (IN_RANGE (ix86_branch_cost, 0, 255));
3293
3294   ptr->arch = ix86_arch;
3295   ptr->schedule = ix86_schedule;
3296   ptr->tune = ix86_tune;
3297   ptr->fpmath = ix86_fpmath;
3298   ptr->branch_cost = ix86_branch_cost;
3299   ptr->tune_defaulted = ix86_tune_defaulted;
3300   ptr->arch_specified = ix86_arch_specified;
3301   ptr->ix86_isa_flags_explicit = ix86_isa_flags_explicit;
3302   ptr->target_flags_explicit = target_flags_explicit;
3303 }
3304
3305 /* Restore the current options */
3306
3307 static void
3308 ix86_function_specific_restore (struct cl_target_option *ptr)
3309 {
3310   enum processor_type old_tune = ix86_tune;
3311   enum processor_type old_arch = ix86_arch;
3312   unsigned int ix86_arch_mask, ix86_tune_mask;
3313   int i;
3314
3315   ix86_arch = ptr->arch;
3316   ix86_schedule = ptr->schedule;
3317   ix86_tune = ptr->tune;
3318   ix86_fpmath = ptr->fpmath;
3319   ix86_branch_cost = ptr->branch_cost;
3320   ix86_tune_defaulted = ptr->tune_defaulted;
3321   ix86_arch_specified = ptr->arch_specified;
3322   ix86_isa_flags_explicit = ptr->ix86_isa_flags_explicit;
3323   target_flags_explicit = ptr->target_flags_explicit;
3324
3325   /* Recreate the arch feature tests if the arch changed */
3326   if (old_arch != ix86_arch)
3327     {
3328       ix86_arch_mask = 1u << ix86_arch;
3329       for (i = 0; i < X86_ARCH_LAST; ++i)
3330         ix86_arch_features[i]
3331           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3332     }
3333
3334   /* Recreate the tune optimization tests */
3335   if (old_tune != ix86_tune)
3336     {
3337       ix86_tune_mask = 1u << ix86_tune;
3338       for (i = 0; i < X86_TUNE_LAST; ++i)
3339         ix86_tune_features[i]
3340           = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3341     }
3342 }
3343
3344 /* Print the current options */
3345
3346 static void
3347 ix86_function_specific_print (FILE *file, int indent,
3348                               struct cl_target_option *ptr)
3349 {
3350   char *target_string
3351     = ix86_target_string (ptr->ix86_isa_flags, ptr->target_flags,
3352                           NULL, NULL, NULL, false);
3353
3354   fprintf (file, "%*sarch = %d (%s)\n",
3355            indent, "",
3356            ptr->arch,
3357            ((ptr->arch < TARGET_CPU_DEFAULT_max)
3358             ? cpu_names[ptr->arch]
3359             : "<unknown>"));
3360
3361   fprintf (file, "%*stune = %d (%s)\n",
3362            indent, "",
3363            ptr->tune,
3364            ((ptr->tune < TARGET_CPU_DEFAULT_max)
3365             ? cpu_names[ptr->tune]
3366             : "<unknown>"));
3367
3368   fprintf (file, "%*sfpmath = %d%s%s\n", indent, "", ptr->fpmath,
3369            (ptr->fpmath & FPMATH_387) ? ", 387" : "",
3370            (ptr->fpmath & FPMATH_SSE) ? ", sse" : "");
3371   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
3372
3373   if (target_string)
3374     {
3375       fprintf (file, "%*s%s\n", indent, "", target_string);
3376       free (target_string);
3377     }
3378 }
3379
3380 \f
3381 /* Inner function to process the attribute((target(...))), take an argument and
3382    set the current options from the argument. If we have a list, recursively go
3383    over the list.  */
3384
3385 static bool
3386 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[])
3387 {
3388   char *next_optstr;
3389   bool ret = true;
3390
3391 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
3392 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
3393 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
3394 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
3395
3396   enum ix86_opt_type
3397   {
3398     ix86_opt_unknown,
3399     ix86_opt_yes,
3400     ix86_opt_no,
3401     ix86_opt_str,
3402     ix86_opt_isa
3403   };
3404
3405   static const struct
3406   {
3407     const char *string;
3408     size_t len;
3409     enum ix86_opt_type type;
3410     int opt;
3411     int mask;
3412   } attrs[] = {
3413     /* isa options */
3414     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
3415     IX86_ATTR_ISA ("abm",       OPT_mabm),
3416     IX86_ATTR_ISA ("aes",       OPT_maes),
3417     IX86_ATTR_ISA ("avx",       OPT_mavx),
3418     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
3419     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
3420     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
3421     IX86_ATTR_ISA ("sse",       OPT_msse),
3422     IX86_ATTR_ISA ("sse2",      OPT_msse2),
3423     IX86_ATTR_ISA ("sse3",      OPT_msse3),
3424     IX86_ATTR_ISA ("sse4",      OPT_msse4),
3425     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
3426     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
3427     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
3428     IX86_ATTR_ISA ("sse5",      OPT_msse5),
3429     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
3430
3431     /* string options */
3432     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
3433     IX86_ATTR_STR ("fpmath=",   IX86_FUNCTION_SPECIFIC_FPMATH),
3434     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
3435
3436     /* flag options */
3437     IX86_ATTR_YES ("cld",
3438                    OPT_mcld,
3439                    MASK_CLD),
3440
3441     IX86_ATTR_NO ("fancy-math-387",
3442                   OPT_mfancy_math_387,
3443                   MASK_NO_FANCY_MATH_387),
3444
3445     IX86_ATTR_NO ("fused-madd",
3446                   OPT_mfused_madd,
3447                   MASK_NO_FUSED_MADD),
3448
3449     IX86_ATTR_YES ("ieee-fp",
3450                    OPT_mieee_fp,
3451                    MASK_IEEE_FP),
3452
3453     IX86_ATTR_YES ("inline-all-stringops",
3454                    OPT_minline_all_stringops,
3455                    MASK_INLINE_ALL_STRINGOPS),
3456
3457     IX86_ATTR_YES ("inline-stringops-dynamically",
3458                    OPT_minline_stringops_dynamically,
3459                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
3460
3461     IX86_ATTR_NO ("align-stringops",
3462                   OPT_mno_align_stringops,
3463                   MASK_NO_ALIGN_STRINGOPS),
3464
3465     IX86_ATTR_YES ("recip",
3466                    OPT_mrecip,
3467                    MASK_RECIP),
3468
3469   };
3470
3471   /* If this is a list, recurse to get the options.  */
3472   if (TREE_CODE (args) == TREE_LIST)
3473     {
3474       bool ret = true;
3475
3476       for (; args; args = TREE_CHAIN (args))
3477         if (TREE_VALUE (args)
3478             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args), p_strings))
3479           ret = false;
3480
3481       return ret;
3482     }
3483
3484   else if (TREE_CODE (args) != STRING_CST)
3485     gcc_unreachable ();
3486
3487   /* Handle multiple arguments separated by commas.  */
3488   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
3489
3490   while (next_optstr && *next_optstr != '\0')
3491     {
3492       char *p = next_optstr;
3493       char *orig_p = p;
3494       char *comma = strchr (next_optstr, ',');
3495       const char *opt_string;
3496       size_t len, opt_len;
3497       int opt;
3498       bool opt_set_p;
3499       char ch;
3500       unsigned i;
3501       enum ix86_opt_type type = ix86_opt_unknown;
3502       int mask = 0;
3503
3504       if (comma)
3505         {
3506           *comma = '\0';
3507           len = comma - next_optstr;
3508           next_optstr = comma + 1;
3509         }
3510       else
3511         {
3512           len = strlen (p);
3513           next_optstr = NULL;
3514         }
3515
3516       /* Recognize no-xxx.  */
3517       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
3518         {
3519           opt_set_p = false;
3520           p += 3;
3521           len -= 3;
3522         }
3523       else
3524         opt_set_p = true;
3525
3526       /* Find the option.  */
3527       ch = *p;
3528       opt = N_OPTS;
3529       for (i = 0; i < sizeof (attrs) / sizeof (attrs[0]); i++)
3530         {
3531           type = attrs[i].type;
3532           opt_len = attrs[i].len;
3533           if (ch == attrs[i].string[0]
3534               && ((type != ix86_opt_str) ? len == opt_len : len > opt_len)
3535               && memcmp (p, attrs[i].string, opt_len) == 0)
3536             {
3537               opt = attrs[i].opt;
3538               mask = attrs[i].mask;
3539               opt_string = attrs[i].string;
3540               break;
3541             }
3542         }
3543
3544       /* Process the option.  */
3545       if (opt == N_OPTS)
3546         {
3547           error ("attribute(target(\"%s\")) is unknown", orig_p);
3548           ret = false;
3549         }
3550
3551       else if (type == ix86_opt_isa)
3552         ix86_handle_option (opt, p, opt_set_p);
3553
3554       else if (type == ix86_opt_yes || type == ix86_opt_no)
3555         {
3556           if (type == ix86_opt_no)
3557             opt_set_p = !opt_set_p;
3558
3559           if (opt_set_p)
3560             target_flags |= mask;
3561           else
3562             target_flags &= ~mask;
3563         }
3564
3565       else if (type == ix86_opt_str)
3566         {
3567           if (p_strings[opt])
3568             {
3569               error ("option(\"%s\") was already specified", opt_string);
3570               ret = false;
3571             }
3572           else
3573             p_strings[opt] = xstrdup (p + opt_len);
3574         }
3575
3576       else
3577         gcc_unreachable ();
3578     }
3579
3580   return ret;
3581 }
3582
3583 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
3584
3585 tree
3586 ix86_valid_target_attribute_tree (tree args)
3587 {
3588   const char *orig_arch_string = ix86_arch_string;
3589   const char *orig_tune_string = ix86_tune_string;
3590   const char *orig_fpmath_string = ix86_fpmath_string;
3591   int orig_tune_defaulted = ix86_tune_defaulted;
3592   int orig_arch_specified = ix86_arch_specified;
3593   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL, NULL };
3594   tree t = NULL_TREE;
3595   int i;
3596   struct cl_target_option *def
3597     = TREE_TARGET_OPTION (target_option_default_node);
3598
3599   /* Process each of the options on the chain.  */
3600   if (! ix86_valid_target_attribute_inner_p (args, option_strings))
3601     return NULL_TREE;
3602
3603   /* If the changed options are different from the default, rerun override_options,
3604      and then save the options away.  The string options are are attribute options,
3605      and will be undone when we copy the save structure.  */
3606   if (ix86_isa_flags != def->ix86_isa_flags
3607       || target_flags != def->target_flags
3608       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
3609       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
3610       || option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3611     {
3612       /* If we are using the default tune= or arch=, undo the string assigned,
3613          and use the default.  */
3614       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
3615         ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
3616       else if (!orig_arch_specified)
3617         ix86_arch_string = NULL;
3618
3619       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
3620         ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
3621       else if (orig_tune_defaulted)
3622         ix86_tune_string = NULL;
3623
3624       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
3625       if (option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3626         ix86_fpmath_string = option_strings[IX86_FUNCTION_SPECIFIC_FPMATH];
3627       else if (!TARGET_64BIT && TARGET_SSE)
3628         ix86_fpmath_string = "sse,387";
3629
3630       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
3631       override_options (false);
3632
3633       /* Add any builtin functions with the new isa if any.  */
3634       ix86_add_new_builtins (ix86_isa_flags);
3635
3636       /* Save the current options unless we are validating options for
3637          #pragma.  */
3638       t = build_target_option_node ();
3639
3640       ix86_arch_string = orig_arch_string;
3641       ix86_tune_string = orig_tune_string;
3642       ix86_fpmath_string = orig_fpmath_string;
3643
3644       /* Free up memory allocated to hold the strings */
3645       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
3646         if (option_strings[i])
3647           free (option_strings[i]);
3648     }
3649
3650   return t;
3651 }
3652
3653 /* Hook to validate attribute((target("string"))).  */
3654
3655 static bool
3656 ix86_valid_target_attribute_p (tree fndecl,
3657                                tree ARG_UNUSED (name),
3658                                tree args,
3659                                int ARG_UNUSED (flags))
3660 {
3661   struct cl_target_option cur_target;
3662   bool ret = true;
3663   tree old_optimize = build_optimization_node ();
3664   tree new_target, new_optimize;
3665   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
3666
3667   /* If the function changed the optimization levels as well as setting target
3668      options, start with the optimizations specified.  */
3669   if (func_optimize && func_optimize != old_optimize)
3670     cl_optimization_restore (TREE_OPTIMIZATION (func_optimize));
3671
3672   /* The target attributes may also change some optimization flags, so update
3673      the optimization options if necessary.  */
3674   cl_target_option_save (&cur_target);
3675   new_target = ix86_valid_target_attribute_tree (args);
3676   new_optimize = build_optimization_node ();
3677
3678   if (!new_target)
3679     ret = false;
3680
3681   else if (fndecl)
3682     {
3683       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
3684
3685       if (old_optimize != new_optimize)
3686         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
3687     }
3688
3689   cl_target_option_restore (&cur_target);
3690
3691   if (old_optimize != new_optimize)
3692     cl_optimization_restore (TREE_OPTIMIZATION (old_optimize));
3693
3694   return ret;
3695 }
3696
3697 \f
3698 /* Hook to determine if one function can safely inline another.  */
3699
3700 static bool
3701 ix86_can_inline_p (tree caller, tree callee)
3702 {
3703   bool ret = false;
3704   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
3705   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
3706
3707   /* If callee has no option attributes, then it is ok to inline.  */
3708   if (!callee_tree)
3709     ret = true;
3710
3711   /* If caller has no option attributes, but callee does then it is not ok to
3712      inline.  */
3713   else if (!caller_tree)
3714     ret = false;
3715
3716   else
3717     {
3718       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
3719       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
3720
3721       /* Callee's isa options should a subset of the caller's, i.e. a SSE5 function
3722          can inline a SSE2 function but a SSE2 function can't inline a SSE5
3723          function.  */
3724       if ((caller_opts->ix86_isa_flags & callee_opts->ix86_isa_flags)
3725           != callee_opts->ix86_isa_flags)
3726         ret = false;
3727
3728       /* See if we have the same non-isa options.  */
3729       else if (caller_opts->target_flags != callee_opts->target_flags)
3730         ret = false;
3731
3732       /* See if arch, tune, etc. are the same.  */
3733       else if (caller_opts->arch != callee_opts->arch)
3734         ret = false;
3735
3736       else if (caller_opts->tune != callee_opts->tune)
3737         ret = false;
3738
3739       else if (caller_opts->fpmath != callee_opts->fpmath)
3740         ret = false;
3741
3742       else if (caller_opts->branch_cost != callee_opts->branch_cost)
3743         ret = false;
3744
3745       else
3746         ret = true;
3747     }
3748
3749   return ret;
3750 }
3751
3752 \f
3753 /* Remember the last target of ix86_set_current_function.  */
3754 static GTY(()) tree ix86_previous_fndecl;
3755
3756 /* Establish appropriate back-end context for processing the function
3757    FNDECL.  The argument might be NULL to indicate processing at top
3758    level, outside of any function scope.  */
3759 static void
3760 ix86_set_current_function (tree fndecl)
3761 {
3762   /* Only change the context if the function changes.  This hook is called
3763      several times in the course of compiling a function, and we don't want to
3764      slow things down too much or call target_reinit when it isn't safe.  */
3765   if (fndecl && fndecl != ix86_previous_fndecl)
3766     {
3767       tree old_tree = (ix86_previous_fndecl
3768                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
3769                        : NULL_TREE);
3770
3771       tree new_tree = (fndecl
3772                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
3773                        : NULL_TREE);
3774
3775       ix86_previous_fndecl = fndecl;
3776       if (old_tree == new_tree)
3777         ;
3778
3779       else if (new_tree)
3780         {
3781           cl_target_option_restore (TREE_TARGET_OPTION (new_tree));
3782           target_reinit ();
3783         }
3784
3785       else if (old_tree)
3786         {
3787           struct cl_target_option *def
3788             = TREE_TARGET_OPTION (target_option_current_node);
3789
3790           cl_target_option_restore (def);
3791           target_reinit ();
3792         }
3793     }
3794 }
3795
3796 \f
3797 /* Return true if this goes in large data/bss.  */
3798
3799 static bool
3800 ix86_in_large_data_p (tree exp)
3801 {
3802   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
3803     return false;
3804
3805   /* Functions are never large data.  */
3806   if (TREE_CODE (exp) == FUNCTION_DECL)
3807     return false;
3808
3809   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
3810     {
3811       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
3812       if (strcmp (section, ".ldata") == 0
3813           || strcmp (section, ".lbss") == 0)
3814         return true;
3815       return false;
3816     }
3817   else
3818     {
3819       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3820
3821       /* If this is an incomplete type with size 0, then we can't put it
3822          in data because it might be too big when completed.  */
3823       if (!size || size > ix86_section_threshold)
3824         return true;
3825     }
3826
3827   return false;
3828 }
3829
3830 /* Switch to the appropriate section for output of DECL.
3831    DECL is either a `VAR_DECL' node or a constant of some sort.
3832    RELOC indicates whether forming the initial value of DECL requires
3833    link-time relocations.  */
3834
3835 static section * x86_64_elf_select_section (tree, int, unsigned HOST_WIDE_INT)
3836         ATTRIBUTE_UNUSED;
3837
3838 static section *
3839 x86_64_elf_select_section (tree decl, int reloc,
3840                            unsigned HOST_WIDE_INT align)
3841 {
3842   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3843       && ix86_in_large_data_p (decl))
3844     {
3845       const char *sname = NULL;
3846       unsigned int flags = SECTION_WRITE;
3847       switch (categorize_decl_for_section (decl, reloc))
3848         {
3849         case SECCAT_DATA:
3850           sname = ".ldata";
3851           break;
3852         case SECCAT_DATA_REL:
3853           sname = ".ldata.rel";
3854           break;
3855         case SECCAT_DATA_REL_LOCAL:
3856           sname = ".ldata.rel.local";
3857           break;
3858         case SECCAT_DATA_REL_RO:
3859           sname = ".ldata.rel.ro";
3860           break;
3861         case SECCAT_DATA_REL_RO_LOCAL:
3862           sname = ".ldata.rel.ro.local";
3863           break;
3864         case SECCAT_BSS:
3865           sname = ".lbss";
3866           flags |= SECTION_BSS;
3867           break;
3868         case SECCAT_RODATA:
3869         case SECCAT_RODATA_MERGE_STR:
3870         case SECCAT_RODATA_MERGE_STR_INIT:
3871         case SECCAT_RODATA_MERGE_CONST:
3872           sname = ".lrodata";
3873           flags = 0;
3874           break;
3875         case SECCAT_SRODATA:
3876         case SECCAT_SDATA:
3877         case SECCAT_SBSS:
3878           gcc_unreachable ();
3879         case SECCAT_TEXT:
3880         case SECCAT_TDATA:
3881         case SECCAT_TBSS:
3882           /* We don't split these for medium model.  Place them into
3883              default sections and hope for best.  */
3884           break;
3885         case SECCAT_EMUTLS_VAR:
3886         case SECCAT_EMUTLS_TMPL:
3887           gcc_unreachable ();
3888         }
3889       if (sname)
3890         {
3891           /* We might get called with string constants, but get_named_section
3892              doesn't like them as they are not DECLs.  Also, we need to set
3893              flags in that case.  */
3894           if (!DECL_P (decl))
3895             return get_section (sname, flags, NULL);
3896           return get_named_section (decl, sname, reloc);
3897         }
3898     }
3899   return default_elf_select_section (decl, reloc, align);
3900 }
3901
3902 /* Build up a unique section name, expressed as a
3903    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
3904    RELOC indicates whether the initial value of EXP requires
3905    link-time relocations.  */
3906
3907 static void ATTRIBUTE_UNUSED
3908 x86_64_elf_unique_section (tree decl, int reloc)
3909 {
3910   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3911       && ix86_in_large_data_p (decl))
3912     {
3913       const char *prefix = NULL;
3914       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
3915       bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
3916
3917       switch (categorize_decl_for_section (decl, reloc))
3918         {
3919         case SECCAT_DATA:
3920         case SECCAT_DATA_REL:
3921         case SECCAT_DATA_REL_LOCAL:
3922         case SECCAT_DATA_REL_RO:
3923         case SECCAT_DATA_REL_RO_LOCAL:
3924           prefix = one_only ? ".ld" : ".ldata";
3925           break;
3926         case SECCAT_BSS:
3927           prefix = one_only ? ".lb" : ".lbss";
3928           break;
3929         case SECCAT_RODATA:
3930         case SECCAT_RODATA_MERGE_STR:
3931         case SECCAT_RODATA_MERGE_STR_INIT:
3932         case SECCAT_RODATA_MERGE_CONST:
3933           prefix = one_only ? ".lr" : ".lrodata";
3934           break;
3935         case SECCAT_SRODATA:
3936         case SECCAT_SDATA:
3937         case SECCAT_SBSS:
3938           gcc_unreachable ();
3939         case SECCAT_TEXT:
3940         case SECCAT_TDATA:
3941         case SECCAT_TBSS:
3942           /* We don't split these for medium model.  Place them into
3943              default sections and hope for best.  */
3944           break;
3945         case SECCAT_EMUTLS_VAR:
3946           prefix = targetm.emutls.var_section;
3947           break;
3948         case SECCAT_EMUTLS_TMPL:
3949           prefix = targetm.emutls.tmpl_section;
3950           break;
3951         }
3952       if (prefix)
3953         {
3954           const char *name, *linkonce;
3955           char *string;
3956
3957           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
3958           name = targetm.strip_name_encoding (name);
3959           
3960           /* If we're using one_only, then there needs to be a .gnu.linkonce
3961              prefix to the section name.  */
3962           linkonce = one_only ? ".gnu.linkonce" : "";
3963   
3964           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
3965           
3966           DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
3967           return;
3968         }
3969     }
3970   default_unique_section (decl, reloc);
3971 }
3972
3973 #ifdef COMMON_ASM_OP
3974 /* This says how to output assembler code to declare an
3975    uninitialized external linkage data object.
3976
3977    For medium model x86-64 we need to use .largecomm opcode for
3978    large objects.  */
3979 void
3980 x86_elf_aligned_common (FILE *file,
3981                         const char *name, unsigned HOST_WIDE_INT size,
3982                         int align)
3983 {
3984   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3985       && size > (unsigned int)ix86_section_threshold)
3986     fprintf (file, ".largecomm\t");
3987   else
3988     fprintf (file, "%s", COMMON_ASM_OP);
3989   assemble_name (file, name);
3990   fprintf (file, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",
3991            size, align / BITS_PER_UNIT);
3992 }
3993 #endif
3994
3995 /* Utility function for targets to use in implementing
3996    ASM_OUTPUT_ALIGNED_BSS.  */
3997
3998 void
3999 x86_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
4000                         const char *name, unsigned HOST_WIDE_INT size,
4001                         int align)
4002 {
4003   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
4004       && size > (unsigned int)ix86_section_threshold)
4005     switch_to_section (get_named_section (decl, ".lbss", 0));
4006   else
4007     switch_to_section (bss_section);
4008   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
4009 #ifdef ASM_DECLARE_OBJECT_NAME
4010   last_assemble_variable_decl = decl;
4011   ASM_DECLARE_OBJECT_NAME (file, name, decl);
4012 #else
4013   /* Standard thing is just output label for the object.  */
4014   ASM_OUTPUT_LABEL (file, name);
4015 #endif /* ASM_DECLARE_OBJECT_NAME */
4016   ASM_OUTPUT_SKIP (file, size ? size : 1);
4017 }
4018 \f
4019 void
4020 optimization_options (int level, int size ATTRIBUTE_UNUSED)
4021 {
4022   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
4023      make the problem with not enough registers even worse.  */
4024 #ifdef INSN_SCHEDULING
4025   if (level > 1)
4026     flag_schedule_insns = 0;
4027 #endif
4028
4029   if (TARGET_MACHO)
4030     /* The Darwin libraries never set errno, so we might as well
4031        avoid calling them when that's the only reason we would.  */
4032     flag_errno_math = 0;
4033
4034   /* The default values of these switches depend on the TARGET_64BIT
4035      that is not known at this moment.  Mark these values with 2 and
4036      let user the to override these.  In case there is no command line option
4037      specifying them, we will set the defaults in override_options.  */
4038   if (optimize >= 1)
4039     flag_omit_frame_pointer = 2;
4040   flag_pcc_struct_return = 2;
4041   flag_asynchronous_unwind_tables = 2;
4042   flag_vect_cost_model = 1;
4043 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
4044   SUBTARGET_OPTIMIZATION_OPTIONS;
4045 #endif
4046 }
4047 \f
4048 /* Decide whether we can make a sibling call to a function.  DECL is the
4049    declaration of the function being targeted by the call and EXP is the
4050    CALL_EXPR representing the call.  */
4051
4052 static bool
4053 ix86_function_ok_for_sibcall (tree decl, tree exp)
4054 {
4055   tree func;
4056   rtx a, b;
4057
4058   /* If we are generating position-independent code, we cannot sibcall
4059      optimize any indirect call, or a direct call to a global function,
4060      as the PLT requires %ebx be live.  */
4061   if (!TARGET_64BIT && flag_pic && (!decl || !targetm.binds_local_p (decl)))
4062     return false;
4063
4064   if (decl)
4065     func = decl;
4066   else
4067     {
4068       func = TREE_TYPE (CALL_EXPR_FN (exp));
4069       if (POINTER_TYPE_P (func))
4070         func = TREE_TYPE (func);
4071     }
4072
4073   /* Check that the return value locations are the same.  Like
4074      if we are returning floats on the 80387 register stack, we cannot
4075      make a sibcall from a function that doesn't return a float to a
4076      function that does or, conversely, from a function that does return
4077      a float to a function that doesn't; the necessary stack adjustment
4078      would not be executed.  This is also the place we notice
4079      differences in the return value ABI.  Note that it is ok for one
4080      of the functions to have void return type as long as the return
4081      value of the other is passed in a register.  */
4082   a = ix86_function_value (TREE_TYPE (exp), func, false);
4083   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
4084                            cfun->decl, false);
4085   if (STACK_REG_P (a) || STACK_REG_P (b))
4086     {
4087       if (!rtx_equal_p (a, b))
4088         return false;
4089     }
4090   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
4091     ;
4092   else if (!rtx_equal_p (a, b))
4093     return false;
4094
4095   /* If this call is indirect, we'll need to be able to use a call-clobbered
4096      register for the address of the target function.  Make sure that all
4097      such registers are not used for passing parameters.  */
4098   if (!decl && !TARGET_64BIT)
4099     {
4100       tree type;
4101
4102       /* We're looking at the CALL_EXPR, we need the type of the function.  */
4103       type = CALL_EXPR_FN (exp);                /* pointer expression */
4104       type = TREE_TYPE (type);                  /* pointer type */
4105       type = TREE_TYPE (type);                  /* function type */
4106
4107       if (ix86_function_regparm (type, NULL) >= 3)
4108         {
4109           /* ??? Need to count the actual number of registers to be used,
4110              not the possible number of registers.  Fix later.  */
4111           return false;
4112         }
4113     }
4114
4115   /* Dllimport'd functions are also called indirectly.  */
4116   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
4117       && !TARGET_64BIT
4118       && decl && DECL_DLLIMPORT_P (decl)
4119       && ix86_function_regparm (TREE_TYPE (decl), NULL) >= 3)
4120     return false;
4121
4122   /* If we need to align the outgoing stack, then sibcalling would
4123      unalign the stack, which may break the called function.  */
4124   if (ix86_incoming_stack_boundary < PREFERRED_STACK_BOUNDARY)
4125     return false;
4126
4127   /* Otherwise okay.  That also includes certain types of indirect calls.  */
4128   return true;
4129 }
4130
4131 /* Handle "cdecl", "stdcall", "fastcall", "regparm" and "sseregparm"
4132    calling convention attributes;
4133    arguments as in struct attribute_spec.handler.  */
4134
4135 static tree
4136 ix86_handle_cconv_attribute (tree *node, tree name,
4137                                    tree args,
4138                                    int flags ATTRIBUTE_UNUSED,
4139                                    bool *no_add_attrs)
4140 {
4141   if (TREE_CODE (*node) != FUNCTION_TYPE
4142       && TREE_CODE (*node) != METHOD_TYPE
4143       && TREE_CODE (*node) != FIELD_DECL
4144       && TREE_CODE (*node) != TYPE_DECL)
4145     {
4146       warning (OPT_Wattributes, "%qs attribute only applies to functions",
4147                IDENTIFIER_POINTER (name));
4148       *no_add_attrs = true;
4149       return NULL_TREE;
4150     }
4151
4152   /* Can combine regparm with all attributes but fastcall.  */
4153   if (is_attribute_p ("regparm", name))
4154     {
4155       tree cst;
4156
4157       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4158         {
4159           error ("fastcall and regparm attributes are not compatible");
4160         }
4161
4162       cst = TREE_VALUE (args);
4163       if (TREE_CODE (cst) != INTEGER_CST)
4164         {
4165           warning (OPT_Wattributes,
4166                    "%qs attribute requires an integer constant argument",
4167                    IDENTIFIER_POINTER (name));
4168           *no_add_attrs = true;
4169         }
4170       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
4171         {
4172           warning (OPT_Wattributes, "argument to %qs attribute larger than %d",
4173                    IDENTIFIER_POINTER (name), REGPARM_MAX);
4174           *no_add_attrs = true;
4175         }
4176
4177       return NULL_TREE;
4178     }
4179
4180   if (TARGET_64BIT)
4181     {
4182       /* Do not warn when emulating the MS ABI.  */
4183       if (TREE_CODE (*node) != FUNCTION_TYPE || ix86_function_type_abi (*node)!=MS_ABI)
4184         warning (OPT_Wattributes, "%qs attribute ignored",
4185                  IDENTIFIER_POINTER (name));
4186       *no_add_attrs = true;
4187       return NULL_TREE;
4188     }
4189
4190   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
4191   if (is_attribute_p ("fastcall", name))
4192     {
4193       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4194         {
4195           error ("fastcall and cdecl attributes are not compatible");
4196         }
4197       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4198         {
4199           error ("fastcall and stdcall attributes are not compatible");
4200         }
4201       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
4202         {
4203           error ("fastcall and regparm attributes are not compatible");
4204         }
4205     }
4206
4207   /* Can combine stdcall with fastcall (redundant), regparm and
4208      sseregparm.  */
4209   else if (is_attribute_p ("stdcall", name))
4210     {
4211       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4212         {
4213           error ("stdcall and cdecl attributes are not compatible");
4214         }
4215       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4216         {
4217           error ("stdcall and fastcall attributes are not compatible");
4218         }
4219     }
4220
4221   /* Can combine cdecl with regparm and sseregparm.  */
4222   else if (is_attribute_p ("cdecl", name))
4223     {
4224       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4225         {
4226           error ("stdcall and cdecl attributes are not compatible");
4227         }
4228       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4229         {
4230           error ("fastcall and cdecl attributes are not compatible");
4231         }
4232     }
4233
4234   /* Can combine sseregparm with all attributes.  */
4235
4236   return NULL_TREE;
4237 }
4238
4239 /* Return 0 if the attributes for two types are incompatible, 1 if they
4240    are compatible, and 2 if they are nearly compatible (which causes a
4241    warning to be generated).  */
4242
4243 static int
4244 ix86_comp_type_attributes (const_tree type1, const_tree type2)
4245 {
4246   /* Check for mismatch of non-default calling convention.  */
4247   const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
4248
4249   if (TREE_CODE (type1) != FUNCTION_TYPE
4250       && TREE_CODE (type1) != METHOD_TYPE)
4251     return 1;
4252
4253   /* Check for mismatched fastcall/regparm types.  */
4254   if ((!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
4255        != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
4256       || (ix86_function_regparm (type1, NULL)
4257           != ix86_function_regparm (type2, NULL)))
4258     return 0;
4259
4260   /* Check for mismatched sseregparm types.  */
4261   if (!lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type1))
4262       != !lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type2)))
4263     return 0;
4264
4265   /* Check for mismatched return types (cdecl vs stdcall).  */
4266   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
4267       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
4268     return 0;
4269
4270   return 1;
4271 }
4272 \f
4273 /* Return the regparm value for a function with the indicated TYPE and DECL.
4274    DECL may be NULL when calling function indirectly
4275    or considering a libcall.  */
4276
4277 static int
4278 ix86_function_regparm (const_tree type, const_tree decl)
4279 {
4280   tree attr;
4281   int regparm = ix86_regparm;
4282
4283   static bool error_issued;
4284
4285   if (TARGET_64BIT)
4286     {
4287       if (ix86_function_type_abi (type) == DEFAULT_ABI)
4288         return regparm;
4289       return DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
4290     }
4291
4292   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
4293   if (attr)
4294     {
4295       regparm
4296         = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
4297
4298       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4299         {
4300           /* We can't use regparm(3) for nested functions because
4301              these pass static chain pointer in %ecx register.  */
4302           if (!error_issued && regparm == 3
4303               && decl_function_context (decl)
4304               && !DECL_NO_STATIC_CHAIN (decl))
4305             {
4306               error ("nested functions are limited to 2 register parameters");
4307               error_issued = true;
4308               return 0;
4309             }
4310         }
4311
4312       return regparm;
4313     }
4314
4315   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4316     return 2;
4317
4318   /* Use register calling convention for local functions when possible.  */
4319   if (decl && TREE_CODE (decl) == FUNCTION_DECL
4320       && !profile_flag)
4321     {
4322       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4323       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4324       if (i && i->local)
4325         {
4326           int local_regparm, globals = 0, regno;
4327           struct function *f;
4328
4329           /* Make sure no regparm register is taken by a
4330              fixed register variable.  */
4331           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4332             if (fixed_regs[local_regparm])
4333               break;
4334
4335           /* We can't use regparm(3) for nested functions as these use
4336              static chain pointer in third argument.  */
4337           if (local_regparm == 3
4338               && decl_function_context (decl)
4339               && !DECL_NO_STATIC_CHAIN (decl))
4340             local_regparm = 2;
4341
4342           /* If the function realigns its stackpointer, the prologue will
4343              clobber %ecx.  If we've already generated code for the callee,
4344              the callee DECL_STRUCT_FUNCTION is gone, so we fall back to
4345              scanning the attributes for the self-realigning property.  */
4346           f = DECL_STRUCT_FUNCTION (decl);
4347           /* Since current internal arg pointer won't conflict with
4348              parameter passing regs, so no need to change stack
4349              realignment and adjust regparm number.
4350
4351              Each fixed register usage increases register pressure,
4352              so less registers should be used for argument passing.
4353              This functionality can be overriden by an explicit
4354              regparm value.  */
4355           for (regno = 0; regno <= DI_REG; regno++)
4356             if (fixed_regs[regno])
4357               globals++;
4358
4359           local_regparm
4360             = globals < local_regparm ? local_regparm - globals : 0;
4361
4362           if (local_regparm > regparm)
4363             regparm = local_regparm;
4364         }
4365     }
4366
4367   return regparm;
4368 }
4369
4370 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
4371    DFmode (2) arguments in SSE registers for a function with the
4372    indicated TYPE and DECL.  DECL may be NULL when calling function
4373    indirectly or considering a libcall.  Otherwise return 0.  */
4374
4375 static int
4376 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
4377 {
4378   gcc_assert (!TARGET_64BIT);
4379
4380   /* Use SSE registers to pass SFmode and DFmode arguments if requested
4381      by the sseregparm attribute.  */
4382   if (TARGET_SSEREGPARM
4383       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
4384     {
4385       if (!TARGET_SSE)
4386         {
4387           if (warn)
4388             {
4389               if (decl)
4390                 error ("Calling %qD with attribute sseregparm without "
4391                        "SSE/SSE2 enabled", decl);
4392               else
4393                 error ("Calling %qT with attribute sseregparm without "
4394                        "SSE/SSE2 enabled", type);
4395             }
4396           return 0;
4397         }
4398
4399       return 2;
4400     }
4401
4402   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4403      (and DFmode for SSE2) arguments in SSE registers.  */
4404   if (decl && TARGET_SSE_MATH && !profile_flag)
4405     {
4406       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4407       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4408       if (i && i->local)
4409         return TARGET_SSE2 ? 2 : 1;
4410     }
4411
4412   return 0;
4413 }
4414
4415 /* Return true if EAX is live at the start of the function.  Used by
4416    ix86_expand_prologue to determine if we need special help before
4417    calling allocate_stack_worker.  */
4418
4419 static bool
4420 ix86_eax_live_at_start_p (void)
4421 {
4422   /* Cheat.  Don't bother working forward from ix86_function_regparm
4423      to the function type to whether an actual argument is located in
4424      eax.  Instead just look at cfg info, which is still close enough
4425      to correct at this point.  This gives false positives for broken
4426      functions that might use uninitialized data that happens to be
4427      allocated in eax, but who cares?  */
4428   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR), 0);
4429 }
4430
4431 /* Value is the number of bytes of arguments automatically
4432    popped when returning from a subroutine call.
4433    FUNDECL is the declaration node of the function (as a tree),
4434    FUNTYPE is the data type of the function (as a tree),
4435    or for a library call it is an identifier node for the subroutine name.
4436    SIZE is the number of bytes of arguments passed on the stack.
4437
4438    On the 80386, the RTD insn may be used to pop them if the number
4439      of args is fixed, but if the number is variable then the caller
4440      must pop them all.  RTD can't be used for library calls now
4441      because the library is compiled with the Unix compiler.
4442    Use of RTD is a selectable option, since it is incompatible with
4443    standard Unix calling sequences.  If the option is not selected,
4444    the caller must always pop the args.
4445
4446    The attribute stdcall is equivalent to RTD on a per module basis.  */
4447
4448 int
4449 ix86_return_pops_args (tree fundecl, tree funtype, int size)
4450 {
4451   int rtd;
4452
4453   /* None of the 64-bit ABIs pop arguments.  */
4454   if (TARGET_64BIT)
4455     return 0;
4456
4457   rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
4458
4459   /* Cdecl functions override -mrtd, and never pop the stack.  */
4460   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
4461     {
4462       /* Stdcall and fastcall functions will pop the stack if not
4463          variable args.  */
4464       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
4465           || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
4466         rtd = 1;
4467
4468       if (rtd && ! stdarg_p (funtype))
4469         return size;
4470     }
4471
4472   /* Lose any fake structure return argument if it is passed on the stack.  */
4473   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
4474       && !KEEP_AGGREGATE_RETURN_POINTER)
4475     {
4476       int nregs = ix86_function_regparm (funtype, fundecl);
4477       if (nregs == 0)
4478         return GET_MODE_SIZE (Pmode);
4479     }
4480
4481   return 0;
4482 }
4483 \f
4484 /* Argument support functions.  */
4485
4486 /* Return true when register may be used to pass function parameters.  */
4487 bool
4488 ix86_function_arg_regno_p (int regno)
4489 {
4490   int i;
4491   const int *parm_regs;
4492
4493   if (!TARGET_64BIT)
4494     {
4495       if (TARGET_MACHO)
4496         return (regno < REGPARM_MAX
4497                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
4498       else
4499         return (regno < REGPARM_MAX
4500                 || (TARGET_MMX && MMX_REGNO_P (regno)
4501                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
4502                 || (TARGET_SSE && SSE_REGNO_P (regno)
4503                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
4504     }
4505
4506   if (TARGET_MACHO)
4507     {
4508       if (SSE_REGNO_P (regno) && TARGET_SSE)
4509         return true;
4510     }
4511   else
4512     {
4513       if (TARGET_SSE && SSE_REGNO_P (regno)
4514           && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
4515         return true;
4516     }
4517
4518   /* TODO: The function should depend on current function ABI but
4519      builtins.c would need updating then. Therefore we use the
4520      default ABI.  */
4521
4522   /* RAX is used as hidden argument to va_arg functions.  */
4523   if (DEFAULT_ABI == SYSV_ABI && regno == AX_REG)
4524     return true;
4525
4526   if (DEFAULT_ABI == MS_ABI)
4527     parm_regs = x86_64_ms_abi_int_parameter_registers;
4528   else
4529     parm_regs = x86_64_int_parameter_registers;
4530   for (i = 0; i < (DEFAULT_ABI == MS_ABI ? X64_REGPARM_MAX
4531                                          : X86_64_REGPARM_MAX); i++)
4532     if (regno == parm_regs[i])
4533       return true;
4534   return false;
4535 }
4536
4537 /* Return if we do not know how to pass TYPE solely in registers.  */
4538
4539 static bool
4540 ix86_must_pass_in_stack (enum machine_mode mode, const_tree type)
4541 {
4542   if (must_pass_in_stack_var_size_or_pad (mode, type))
4543     return true;
4544
4545   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
4546      The layout_type routine is crafty and tries to trick us into passing
4547      currently unsupported vector types on the stack by using TImode.  */
4548   return (!TARGET_64BIT && mode == TImode
4549           && type && TREE_CODE (type) != VECTOR_TYPE);
4550 }
4551
4552 /* It returns the size, in bytes, of the area reserved for arguments passed
4553    in registers for the function represented by fndecl dependent to the used
4554    abi format.  */
4555 int
4556 ix86_reg_parm_stack_space (const_tree fndecl)
4557 {
4558   int call_abi = SYSV_ABI;
4559   if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
4560     call_abi = ix86_function_abi (fndecl);
4561   else
4562     call_abi = ix86_function_type_abi (fndecl);
4563   if (call_abi == MS_ABI)
4564     return 32;
4565   return 0;
4566 }
4567
4568 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
4569    call abi used.  */
4570 int
4571 ix86_function_type_abi (const_tree fntype)
4572 {
4573   if (TARGET_64BIT && fntype != NULL)
4574     {
4575       int abi;
4576       if (DEFAULT_ABI == SYSV_ABI)
4577         abi = lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)) ? MS_ABI : SYSV_ABI;
4578       else
4579         abi = lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)) ? SYSV_ABI : MS_ABI;
4580
4581       return abi;
4582     }
4583   return DEFAULT_ABI;
4584 }
4585
4586 int
4587 ix86_function_abi (const_tree fndecl)
4588 {
4589   if (! fndecl)
4590     return DEFAULT_ABI;
4591   return ix86_function_type_abi (TREE_TYPE (fndecl));
4592 }
4593
4594 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
4595    call abi used.  */
4596 int
4597 ix86_cfun_abi (void)
4598 {
4599   if (! cfun || ! TARGET_64BIT)
4600     return DEFAULT_ABI;
4601   return cfun->machine->call_abi;
4602 }
4603
4604 /* regclass.c  */
4605 extern void init_regs (void);
4606
4607 /* Implementation of call abi switching target hook. Specific to FNDECL
4608    the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
4609    for more details.  */
4610 void
4611 ix86_call_abi_override (const_tree fndecl)
4612 {
4613   if (fndecl == NULL_TREE)
4614     cfun->machine->call_abi = DEFAULT_ABI;
4615   else
4616     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
4617 }
4618
4619 /* MS and SYSV ABI have different set of call used registers.  Avoid expensive
4620    re-initialization of init_regs each time we switch function context since
4621    this is needed only during RTL expansion.  */
4622 static void
4623 ix86_maybe_switch_abi (void)
4624 {
4625   if (TARGET_64BIT &&
4626       call_used_regs[4 /*RSI*/] ==  (cfun->machine->call_abi == MS_ABI))
4627     init_regs ();
4628 }
4629
4630 /* Initialize a variable CUM of type CUMULATIVE_ARGS
4631    for a call to a function whose data type is FNTYPE.
4632    For a library call, FNTYPE is 0.  */
4633
4634 void
4635 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
4636                       tree fntype,      /* tree ptr for function decl */
4637                       rtx libname,      /* SYMBOL_REF of library name or 0 */
4638                       tree fndecl)
4639 {
4640   struct cgraph_local_info *i = fndecl ? cgraph_local_info (fndecl) : NULL;
4641   memset (cum, 0, sizeof (*cum));
4642
4643   if (fndecl)
4644    cum->call_abi = ix86_function_abi (fndecl);
4645   else
4646    cum->call_abi = ix86_function_type_abi (fntype);
4647   /* Set up the number of registers to use for passing arguments.  */
4648
4649   if (cum->call_abi == MS_ABI && !ACCUMULATE_OUTGOING_ARGS)
4650     sorry ("ms_abi attribute require -maccumulate-outgoing-args or subtarget optimization implying it");
4651   cum->nregs = ix86_regparm;
4652   if (TARGET_64BIT)
4653     {
4654       if (cum->call_abi != DEFAULT_ABI)
4655         cum->nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX
4656                                              : X64_REGPARM_MAX;
4657     }
4658   if (TARGET_SSE)
4659     {
4660       cum->sse_nregs = SSE_REGPARM_MAX;
4661       if (TARGET_64BIT)
4662         {
4663           if (cum->call_abi != DEFAULT_ABI)
4664             cum->sse_nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
4665                                                      : X64_SSE_REGPARM_MAX;
4666         }
4667     }
4668   if (TARGET_MMX)
4669     cum->mmx_nregs = MMX_REGPARM_MAX;
4670   cum->warn_avx = true;
4671   cum->warn_sse = true;
4672   cum->warn_mmx = true;
4673
4674   /* Because type might mismatch in between caller and callee, we need to
4675      use actual type of function for local calls.
4676      FIXME: cgraph_analyze can be told to actually record if function uses
4677      va_start so for local functions maybe_vaarg can be made aggressive
4678      helping K&R code.
4679      FIXME: once typesytem is fixed, we won't need this code anymore.  */
4680   if (i && i->local)
4681     fntype = TREE_TYPE (fndecl);
4682   cum->maybe_vaarg = (fntype
4683                       ? (!prototype_p (fntype) || stdarg_p (fntype))
4684                       : !libname);
4685
4686   if (!TARGET_64BIT)
4687     {
4688       /* If there are variable arguments, then we won't pass anything
4689          in registers in 32-bit mode. */
4690       if (stdarg_p (fntype))
4691         {
4692           cum->nregs = 0;
4693           cum->sse_nregs = 0;
4694           cum->mmx_nregs = 0;
4695           cum->warn_avx = 0;
4696           cum->warn_sse = 0;
4697           cum->warn_mmx = 0;
4698           return;
4699         }
4700
4701       /* Use ecx and edx registers if function has fastcall attribute,
4702          else look for regparm information.  */
4703       if (fntype)
4704         {
4705           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
4706             {
4707               cum->nregs = 2;
4708               cum->fastcall = 1;
4709             }
4710           else
4711             cum->nregs = ix86_function_regparm (fntype, fndecl);
4712         }
4713
4714       /* Set up the number of SSE registers used for passing SFmode
4715          and DFmode arguments.  Warn for mismatching ABI.  */
4716       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
4717     }
4718 }
4719
4720 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
4721    But in the case of vector types, it is some vector mode.
4722
4723    When we have only some of our vector isa extensions enabled, then there
4724    are some modes for which vector_mode_supported_p is false.  For these
4725    modes, the generic vector support in gcc will choose some non-vector mode
4726    in order to implement the type.  By computing the natural mode, we'll
4727    select the proper ABI location for the operand and not depend on whatever
4728    the middle-end decides to do with these vector types.  */
4729
4730 static enum machine_mode
4731 type_natural_mode (const_tree type)
4732 {
4733   enum machine_mode mode = TYPE_MODE (type);
4734
4735   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
4736     {
4737       HOST_WIDE_INT size = int_size_in_bytes (type);
4738       if ((size == 8 || size == 16)
4739           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
4740           && TYPE_VECTOR_SUBPARTS (type) > 1)
4741         {
4742           enum machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
4743
4744           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4745             mode = MIN_MODE_VECTOR_FLOAT;
4746           else
4747             mode = MIN_MODE_VECTOR_INT;
4748
4749           /* Get the mode which has this inner mode and number of units.  */
4750           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
4751             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
4752                 && GET_MODE_INNER (mode) == innermode)
4753               return mode;
4754
4755           gcc_unreachable ();
4756         }
4757     }
4758
4759   return mode;
4760 }
4761
4762 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
4763    this may not agree with the mode that the type system has chosen for the
4764    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
4765    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
4766
4767 static rtx
4768 gen_reg_or_parallel (enum machine_mode mode, enum machine_mode orig_mode,
4769                      unsigned int regno)
4770 {
4771   rtx tmp;
4772
4773   if (orig_mode != BLKmode)
4774     tmp = gen_rtx_REG (orig_mode, regno);
4775   else
4776     {
4777       tmp = gen_rtx_REG (mode, regno);
4778       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
4779       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
4780     }
4781
4782   return tmp;
4783 }
4784
4785 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
4786    of this code is to classify each 8bytes of incoming argument by the register
4787    class and assign registers accordingly.  */
4788
4789 /* Return the union class of CLASS1 and CLASS2.
4790    See the x86-64 PS ABI for details.  */
4791
4792 static enum x86_64_reg_class
4793 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
4794 {
4795   /* Rule #1: If both classes are equal, this is the resulting class.  */
4796   if (class1 == class2)
4797     return class1;
4798
4799   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
4800      the other class.  */
4801   if (class1 == X86_64_NO_CLASS)
4802     return class2;
4803   if (class2 == X86_64_NO_CLASS)
4804     return class1;
4805
4806   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
4807   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
4808     return X86_64_MEMORY_CLASS;
4809
4810   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
4811   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
4812       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
4813     return X86_64_INTEGERSI_CLASS;
4814   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
4815       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
4816     return X86_64_INTEGER_CLASS;
4817
4818   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
4819      MEMORY is used.  */
4820   if (class1 == X86_64_X87_CLASS
4821       || class1 == X86_64_X87UP_CLASS
4822       || class1 == X86_64_COMPLEX_X87_CLASS
4823       || class2 == X86_64_X87_CLASS
4824       || class2 == X86_64_X87UP_CLASS
4825       || class2 == X86_64_COMPLEX_X87_CLASS)
4826     return X86_64_MEMORY_CLASS;
4827
4828   /* Rule #6: Otherwise class SSE is used.  */
4829   return X86_64_SSE_CLASS;
4830 }
4831
4832 /* Classify the argument of type TYPE and mode MODE.
4833    CLASSES will be filled by the register class used to pass each word
4834    of the operand.  The number of words is returned.  In case the parameter
4835    should be passed in memory, 0 is returned. As a special case for zero
4836    sized containers, classes[0] will be NO_CLASS and 1 is returned.
4837
4838    BIT_OFFSET is used internally for handling records and specifies offset
4839    of the offset in bits modulo 256 to avoid overflow cases.
4840
4841    See the x86-64 PS ABI for details.
4842 */
4843
4844 static int
4845 classify_argument (enum machine_mode mode, const_tree type,
4846                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
4847 {
4848   HOST_WIDE_INT bytes =
4849     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
4850   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4851
4852   /* Variable sized entities are always passed/returned in memory.  */
4853   if (bytes < 0)
4854     return 0;
4855
4856   if (mode != VOIDmode
4857       && targetm.calls.must_pass_in_stack (mode, type))
4858     return 0;
4859
4860   if (type && AGGREGATE_TYPE_P (type))
4861     {
4862       int i;
4863       tree field;
4864       enum x86_64_reg_class subclasses[MAX_CLASSES];
4865
4866       /* On x86-64 we pass structures larger than 16 bytes on the stack.  */
4867       if (bytes > 16)
4868         return 0;
4869
4870       for (i = 0; i < words; i++)
4871         classes[i] = X86_64_NO_CLASS;
4872
4873       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
4874          signalize memory class, so handle it as special case.  */
4875       if (!words)
4876         {
4877           classes[0] = X86_64_NO_CLASS;
4878           return 1;
4879         }
4880
4881       /* Classify each field of record and merge classes.  */
4882       switch (TREE_CODE (type))
4883         {
4884         case RECORD_TYPE:
4885           /* And now merge the fields of structure.  */
4886           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4887             {
4888               if (TREE_CODE (field) == FIELD_DECL)
4889                 {
4890                   int num;
4891
4892                   if (TREE_TYPE (field) == error_mark_node)
4893                     continue;
4894
4895                   /* Bitfields are always classified as integer.  Handle them
4896                      early, since later code would consider them to be
4897                      misaligned integers.  */
4898                   if (DECL_BIT_FIELD (field))
4899                     {
4900                       for (i = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4901                            i < ((int_bit_position (field) + (bit_offset % 64))
4902                                 + tree_low_cst (DECL_SIZE (field), 0)
4903                                 + 63) / 8 / 8; i++)
4904                         classes[i] =
4905                           merge_classes (X86_64_INTEGER_CLASS,
4906                                          classes[i]);
4907                     }
4908                   else
4909                     {
4910                       num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4911                                                TREE_TYPE (field), subclasses,
4912                                                (int_bit_position (field)
4913                                                 + bit_offset) % 256);
4914                       if (!num)
4915                         return 0;
4916                       for (i = 0; i < num; i++)
4917                         {
4918                           int pos =
4919                             (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4920                           classes[i + pos] =
4921                             merge_classes (subclasses[i], classes[i + pos]);
4922                         }
4923                     }
4924                 }
4925             }
4926           break;
4927
4928         case ARRAY_TYPE:
4929           /* Arrays are handled as small records.  */
4930           {
4931             int num;
4932             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
4933                                      TREE_TYPE (type), subclasses, bit_offset);
4934             if (!num)
4935               return 0;
4936
4937             /* The partial classes are now full classes.  */
4938             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
4939               subclasses[0] = X86_64_SSE_CLASS;
4940             if (subclasses[0] == X86_64_INTEGERSI_CLASS
4941                 && !((bit_offset % 64) == 0 && bytes == 4))
4942               subclasses[0] = X86_64_INTEGER_CLASS;
4943
4944             for (i = 0; i < words; i++)
4945               classes[i] = subclasses[i % num];
4946
4947             break;
4948           }
4949         case UNION_TYPE:
4950         case QUAL_UNION_TYPE:
4951           /* Unions are similar to RECORD_TYPE but offset is always 0.
4952              */
4953           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4954             {
4955               if (TREE_CODE (field) == FIELD_DECL)
4956                 {
4957                   int num;
4958
4959                   if (TREE_TYPE (field) == error_mark_node)
4960                     continue;
4961
4962                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4963                                            TREE_TYPE (field), subclasses,
4964                                            bit_offset);
4965                   if (!num)
4966                     return 0;
4967                   for (i = 0; i < num; i++)
4968                     classes[i] = merge_classes (subclasses[i], classes[i]);
4969                 }
4970             }
4971           break;
4972
4973         default:
4974           gcc_unreachable ();
4975         }
4976
4977       /* Final merger cleanup.  */
4978       for (i = 0; i < words; i++)
4979         {
4980           /* If one class is MEMORY, everything should be passed in
4981              memory.  */
4982           if (classes[i] == X86_64_MEMORY_CLASS)
4983             return 0;
4984
4985           /* The X86_64_SSEUP_CLASS should be always preceded by
4986              X86_64_SSE_CLASS.  */
4987           if (classes[i] == X86_64_SSEUP_CLASS
4988               && (i == 0 || classes[i - 1] != X86_64_SSE_CLASS))
4989             classes[i] = X86_64_SSE_CLASS;
4990
4991           /*  X86_64_X87UP_CLASS should be preceded by X86_64_X87_CLASS.  */
4992           if (classes[i] == X86_64_X87UP_CLASS
4993               && (i == 0 || classes[i - 1] != X86_64_X87_CLASS))
4994             classes[i] = X86_64_SSE_CLASS;
4995         }
4996       return words;
4997     }
4998
4999   /* Compute alignment needed.  We align all types to natural boundaries with
5000      exception of XFmode that is aligned to 64bits.  */
5001   if (mode != VOIDmode && mode != BLKmode)
5002     {
5003       int mode_alignment = GET_MODE_BITSIZE (mode);
5004
5005       if (mode == XFmode)
5006         mode_alignment = 128;
5007       else if (mode == XCmode)
5008         mode_alignment = 256;
5009       if (COMPLEX_MODE_P (mode))
5010         mode_alignment /= 2;
5011       /* Misaligned fields are always returned in memory.  */
5012       if (bit_offset % mode_alignment)
5013         return 0;
5014     }
5015
5016   /* for V1xx modes, just use the base mode */
5017   if (VECTOR_MODE_P (mode) && mode != V1DImode
5018       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
5019     mode = GET_MODE_INNER (mode);
5020
5021   /* Classification of atomic types.  */
5022   switch (mode)
5023     {
5024     case SDmode:
5025     case DDmode:
5026       classes[0] = X86_64_SSE_CLASS;
5027       return 1;
5028     case TDmode:
5029       classes[0] = X86_64_SSE_CLASS;
5030       classes[1] = X86_64_SSEUP_CLASS;
5031       return 2;
5032     case DImode:
5033     case SImode:
5034     case HImode:
5035     case QImode:
5036     case CSImode:
5037     case CHImode:
5038     case CQImode:
5039       {
5040         int size = (bit_offset % 64)+ (int) GET_MODE_BITSIZE (mode);
5041
5042         if (size <= 32)
5043           {
5044             classes[0] = X86_64_INTEGERSI_CLASS;
5045             return 1;
5046           }
5047         else if (size <= 64)
5048           {
5049             classes[0] = X86_64_INTEGER_CLASS;
5050             return 1;
5051           }
5052         else if (size <= 64+32)
5053           {
5054             classes[0] = X86_64_INTEGER_CLASS;
5055             classes[1] = X86_64_INTEGERSI_CLASS;
5056             return 2;
5057           }
5058         else if (size <= 64+64)
5059           {
5060             classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5061             return 2;
5062           }
5063         else
5064           gcc_unreachable ();
5065       }
5066     case CDImode:
5067     case TImode:
5068       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5069       return 2;
5070     case CTImode:
5071     case COImode:
5072     case OImode:
5073       return 0;
5074     case SFmode:
5075       if (!(bit_offset % 64))
5076         classes[0] = X86_64_SSESF_CLASS;
5077       else
5078         classes[0] = X86_64_SSE_CLASS;
5079       return 1;
5080     case DFmode:
5081       classes[0] = X86_64_SSEDF_CLASS;
5082       return 1;
5083     case XFmode:
5084       classes[0] = X86_64_X87_CLASS;
5085       classes[1] = X86_64_X87UP_CLASS;
5086       return 2;
5087     case TFmode:
5088       classes[0] = X86_64_SSE_CLASS;
5089       classes[1] = X86_64_SSEUP_CLASS;
5090       return 2;
5091     case SCmode:
5092       classes[0] = X86_64_SSE_CLASS;
5093       return 1;
5094     case DCmode:
5095       classes[0] = X86_64_SSEDF_CLASS;
5096       classes[1] = X86_64_SSEDF_CLASS;
5097       return 2;
5098     case XCmode:
5099       classes[0] = X86_64_COMPLEX_X87_CLASS;
5100       return 1;
5101     case TCmode:
5102       /* This modes is larger than 16 bytes.  */
5103       return 0;
5104     case V8SFmode:
5105     case V8SImode:
5106     case V32QImode:
5107     case V16HImode:
5108     case V4DFmode:
5109     case V4DImode:
5110       classes[0] = X86_64_AVX_CLASS;
5111       return 1;
5112     case V4SFmode:
5113     case V4SImode:
5114     case V16QImode:
5115     case V8HImode:
5116     case V2DFmode:
5117     case V2DImode:
5118       classes[0] = X86_64_SSE_CLASS;
5119       classes[1] = X86_64_SSEUP_CLASS;
5120       return 2;
5121     case V1DImode:
5122     case V2SFmode:
5123     case V2SImode:
5124     case V4HImode:
5125     case V8QImode:
5126       classes[0] = X86_64_SSE_CLASS;
5127       return 1;
5128     case BLKmode:
5129     case VOIDmode:
5130       return 0;
5131     default:
5132       gcc_assert (VECTOR_MODE_P (mode));
5133
5134       if (bytes > 16)
5135         return 0;
5136
5137       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
5138
5139       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5140         classes[0] = X86_64_INTEGERSI_CLASS;
5141       else
5142         classes[0] = X86_64_INTEGER_CLASS;
5143       classes[1] = X86_64_INTEGER_CLASS;
5144       return 1 + (bytes > 8);
5145     }
5146 }
5147
5148 /* Examine the argument and return set number of register required in each
5149    class.  Return 0 iff parameter should be passed in memory.  */
5150 static int
5151 examine_argument (enum machine_mode mode, const_tree type, int in_return,
5152                   int *int_nregs, int *sse_nregs)
5153 {
5154   enum x86_64_reg_class regclass[MAX_CLASSES];
5155   int n = classify_argument (mode, type, regclass, 0);
5156
5157   *int_nregs = 0;
5158   *sse_nregs = 0;
5159   if (!n)
5160     return 0;
5161   for (n--; n >= 0; n--)
5162     switch (regclass[n])
5163       {
5164       case X86_64_INTEGER_CLASS:
5165       case X86_64_INTEGERSI_CLASS:
5166         (*int_nregs)++;
5167         break;
5168       case X86_64_AVX_CLASS:
5169       case X86_64_SSE_CLASS:
5170       case X86_64_SSESF_CLASS:
5171       case X86_64_SSEDF_CLASS:
5172         (*sse_nregs)++;
5173         break;
5174       case X86_64_NO_CLASS:
5175       case X86_64_SSEUP_CLASS:
5176         break;
5177       case X86_64_X87_CLASS:
5178       case X86_64_X87UP_CLASS:
5179         if (!in_return)
5180           return 0;
5181         break;
5182       case X86_64_COMPLEX_X87_CLASS:
5183         return in_return ? 2 : 0;
5184       case X86_64_MEMORY_CLASS:
5185         gcc_unreachable ();
5186       }
5187   return 1;
5188 }
5189
5190 /* Construct container for the argument used by GCC interface.  See
5191    FUNCTION_ARG for the detailed description.  */
5192
5193 static rtx
5194 construct_container (enum machine_mode mode, enum machine_mode orig_mode,
5195                      const_tree type, int in_return, int nintregs, int nsseregs,
5196                      const int *intreg, int sse_regno)
5197 {
5198   /* The following variables hold the static issued_error state.  */
5199   static bool issued_sse_arg_error;
5200   static bool issued_sse_ret_error;
5201   static bool issued_x87_ret_error;
5202
5203   enum machine_mode tmpmode;
5204   int bytes =
5205     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
5206   enum x86_64_reg_class regclass[MAX_CLASSES];
5207   int n;
5208   int i;
5209   int nexps = 0;
5210   int needed_sseregs, needed_intregs;
5211   rtx exp[MAX_CLASSES];
5212   rtx ret;
5213
5214   n = classify_argument (mode, type, regclass, 0);
5215   if (!n)
5216     return NULL;
5217   if (!examine_argument (mode, type, in_return, &needed_intregs,
5218                          &needed_sseregs))
5219     return NULL;
5220   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
5221     return NULL;
5222
5223   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
5224      some less clueful developer tries to use floating-point anyway.  */
5225   if (needed_sseregs && !TARGET_SSE)
5226     {
5227       if (in_return)
5228         {
5229           if (!issued_sse_ret_error)
5230             {
5231               error ("SSE register return with SSE disabled");
5232               issued_sse_ret_error = true;
5233             }
5234         }
5235       else if (!issued_sse_arg_error)
5236         {
5237           error ("SSE register argument with SSE disabled");
5238           issued_sse_arg_error = true;
5239         }
5240       return NULL;
5241     }
5242
5243   /* Likewise, error if the ABI requires us to return values in the
5244      x87 registers and the user specified -mno-80387.  */
5245   if (!TARGET_80387 && in_return)
5246     for (i = 0; i < n; i++)
5247       if (regclass[i] == X86_64_X87_CLASS
5248           || regclass[i] == X86_64_X87UP_CLASS
5249           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
5250         {
5251           if (!issued_x87_ret_error)
5252             {
5253               error ("x87 register return with x87 disabled");
5254               issued_x87_ret_error = true;
5255             }
5256           return NULL;
5257         }
5258
5259   /* First construct simple cases.  Avoid SCmode, since we want to use
5260      single register to pass this type.  */
5261   if (n == 1 && mode != SCmode)
5262     switch (regclass[0])
5263       {
5264       case X86_64_INTEGER_CLASS:
5265       case X86_64_INTEGERSI_CLASS:
5266         return gen_rtx_REG (mode, intreg[0]);
5267       case X86_64_AVX_CLASS:
5268       case X86_64_SSE_CLASS:
5269       case X86_64_SSESF_CLASS:
5270       case X86_64_SSEDF_CLASS:
5271         return gen_reg_or_parallel (mode, orig_mode, SSE_REGNO (sse_regno));
5272       case X86_64_X87_CLASS:
5273       case X86_64_COMPLEX_X87_CLASS:
5274         return gen_rtx_REG (mode, FIRST_STACK_REG);
5275       case X86_64_NO_CLASS:
5276         /* Zero sized array, struct or class.  */
5277         return NULL;
5278       default:
5279         gcc_unreachable ();
5280       }
5281   if (n == 2 && regclass[0] == X86_64_SSE_CLASS
5282       && regclass[1] == X86_64_SSEUP_CLASS && mode != BLKmode)
5283     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5284
5285   if (n == 2
5286       && regclass[0] == X86_64_X87_CLASS && regclass[1] == X86_64_X87UP_CLASS)
5287     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
5288   if (n == 2 && regclass[0] == X86_64_INTEGER_CLASS
5289       && regclass[1] == X86_64_INTEGER_CLASS
5290       && (mode == CDImode || mode == TImode || mode == TFmode)
5291       && intreg[0] + 1 == intreg[1])
5292     return gen_rtx_REG (mode, intreg[0]);
5293
5294   /* Otherwise figure out the entries of the PARALLEL.  */
5295   for (i = 0; i < n; i++)
5296     {
5297       switch (regclass[i])
5298         {
5299           case X86_64_NO_CLASS:
5300             break;
5301           case X86_64_INTEGER_CLASS:
5302           case X86_64_INTEGERSI_CLASS:
5303             /* Merge TImodes on aligned occasions here too.  */
5304             if (i * 8 + 8 > bytes)
5305               tmpmode = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
5306             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
5307               tmpmode = SImode;
5308             else
5309               tmpmode = DImode;
5310             /* We've requested 24 bytes we don't have mode for.  Use DImode.  */
5311             if (tmpmode == BLKmode)
5312               tmpmode = DImode;
5313             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5314                                                gen_rtx_REG (tmpmode, *intreg),
5315                                                GEN_INT (i*8));
5316             intreg++;
5317             break;
5318           case X86_64_SSESF_CLASS:
5319             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5320                                                gen_rtx_REG (SFmode,
5321                                                             SSE_REGNO (sse_regno)),
5322                                                GEN_INT (i*8));
5323             sse_regno++;
5324             break;
5325           case X86_64_SSEDF_CLASS:
5326             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5327                                                gen_rtx_REG (DFmode,
5328                                                             SSE_REGNO (sse_regno)),
5329                                                GEN_INT (i*8));
5330             sse_regno++;
5331             break;
5332           case X86_64_SSE_CLASS:
5333             if (i < n - 1 && regclass[i + 1] == X86_64_SSEUP_CLASS)
5334               tmpmode = TImode;
5335             else
5336               tmpmode = DImode;
5337             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5338                                                gen_rtx_REG (tmpmode,
5339                                                             SSE_REGNO (sse_regno)),
5340                                                GEN_INT (i*8));
5341             if (tmpmode == TImode)
5342               i++;
5343             sse_regno++;
5344             break;
5345           default:
5346             gcc_unreachable ();
5347         }
5348     }
5349
5350   /* Empty aligned struct, union or class.  */
5351   if (nexps == 0)
5352     return NULL;
5353
5354   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
5355   for (i = 0; i < nexps; i++)
5356     XVECEXP (ret, 0, i) = exp [i];
5357   return ret;
5358 }
5359
5360 /* Update the data in CUM to advance over an argument of mode MODE
5361    and data type TYPE.  (TYPE is null for libcalls where that information
5362    may not be available.)  */
5363
5364 static void
5365 function_arg_advance_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5366                          tree type, HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5367 {
5368   switch (mode)
5369     {
5370     default:
5371       break;
5372
5373     case BLKmode:
5374       if (bytes < 0)
5375         break;
5376       /* FALLTHRU */
5377
5378     case DImode:
5379     case SImode:
5380     case HImode:
5381     case QImode:
5382       cum->words += words;
5383       cum->nregs -= words;
5384       cum->regno += words;
5385
5386       if (cum->nregs <= 0)
5387         {
5388           cum->nregs = 0;
5389           cum->regno = 0;
5390         }
5391       break;
5392
5393     case DFmode:
5394       if (cum->float_in_sse < 2)
5395         break;
5396     case SFmode:
5397       if (cum->float_in_sse < 1)
5398         break;
5399       /* FALLTHRU */
5400
5401     case OImode:
5402     case V8SFmode:
5403     case V8SImode:
5404     case V32QImode:
5405     case V16HImode:
5406     case V4DFmode:
5407     case V4DImode:
5408     case TImode:
5409     case V16QImode:
5410     case V8HImode:
5411     case V4SImode:
5412     case V2DImode:
5413     case V4SFmode:
5414     case V2DFmode:
5415       if (!type || !AGGREGATE_TYPE_P (type))
5416         {
5417           cum->sse_words += words;
5418           cum->sse_nregs -= 1;
5419           cum->sse_regno += 1;
5420           if (cum->sse_nregs <= 0)
5421             {
5422               cum->sse_nregs = 0;
5423               cum->sse_regno = 0;
5424             }
5425         }
5426       break;
5427
5428     case V8QImode:
5429     case V4HImode:
5430     case V2SImode:
5431     case V2SFmode:
5432     case V1DImode:
5433       if (!type || !AGGREGATE_TYPE_P (type))
5434         {
5435           cum->mmx_words += words;
5436           cum->mmx_nregs -= 1;
5437           cum->mmx_regno += 1;
5438           if (cum->mmx_nregs <= 0)
5439             {
5440               cum->mmx_nregs = 0;
5441               cum->mmx_regno = 0;
5442             }
5443         }
5444       break;
5445     }
5446 }
5447
5448 static void
5449 function_arg_advance_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5450                          tree type, HOST_WIDE_INT words, int named)
5451 {
5452   int int_nregs, sse_nregs;
5453
5454   /* Unnamed 256bit vector mode parameters are passed on stack.  */
5455   if (!named && VALID_AVX256_REG_MODE (mode))
5456     return;
5457
5458   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs))
5459     cum->words += words;
5460   else if (sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
5461     {
5462       cum->nregs -= int_nregs;
5463       cum->sse_nregs -= sse_nregs;
5464       cum->regno += int_nregs;
5465       cum->sse_regno += sse_nregs;
5466     }
5467   else
5468     cum->words += words;
5469 }
5470
5471 static void
5472 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
5473                             HOST_WIDE_INT words)
5474 {
5475   /* Otherwise, this should be passed indirect.  */
5476   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
5477
5478   cum->words += words;
5479   if (cum->nregs > 0)
5480     {
5481       cum->nregs -= 1;
5482       cum->regno += 1;
5483     }
5484 }
5485
5486 void
5487 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5488                       tree type, int named)
5489 {
5490   HOST_WIDE_INT bytes, words;
5491
5492   if (mode == BLKmode)
5493     bytes = int_size_in_bytes (type);
5494   else
5495     bytes = GET_MODE_SIZE (mode);
5496   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5497
5498   if (type)
5499     mode = type_natural_mode (type);
5500
5501   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5502     function_arg_advance_ms_64 (cum, bytes, words);
5503   else if (TARGET_64BIT)
5504     function_arg_advance_64 (cum, mode, type, words, named);
5505   else
5506     function_arg_advance_32 (cum, mode, type, bytes, words);
5507 }
5508
5509 /* Define where to put the arguments to a function.
5510    Value is zero to push the argument on the stack,
5511    or a hard register in which to store the argument.
5512
5513    MODE is the argument's machine mode.
5514    TYPE is the data type of the argument (as a tree).
5515     This is null for libcalls where that information may
5516     not be available.
5517    CUM is a variable of type CUMULATIVE_ARGS which gives info about
5518     the preceding args and about the function being called.
5519    NAMED is nonzero if this argument is a named parameter
5520     (otherwise it is an extra parameter matching an ellipsis).  */
5521
5522 static rtx
5523 function_arg_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5524                  enum machine_mode orig_mode, tree type,
5525                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5526 {
5527   static bool warnedavx, warnedsse, warnedmmx;
5528
5529   /* Avoid the AL settings for the Unix64 ABI.  */
5530   if (mode == VOIDmode)
5531     return constm1_rtx;
5532
5533   switch (mode)
5534     {
5535     default:
5536       break;
5537
5538     case BLKmode:
5539       if (bytes < 0)
5540         break;
5541       /* FALLTHRU */
5542     case DImode:
5543     case SImode:
5544     case HImode:
5545     case QImode:
5546       if (words <= cum->nregs)
5547         {
5548           int regno = cum->regno;
5549
5550           /* Fastcall allocates the first two DWORD (SImode) or
5551             smaller arguments to ECX and EDX if it isn't an
5552             aggregate type .  */
5553           if (cum->fastcall)
5554             {
5555               if (mode == BLKmode
5556                   || mode == DImode
5557                   || (type && AGGREGATE_TYPE_P (type)))
5558                 break;
5559
5560               /* ECX not EAX is the first allocated register.  */
5561               if (regno == AX_REG)
5562                 regno = CX_REG;
5563             }
5564           return gen_rtx_REG (mode, regno);
5565         }
5566       break;
5567
5568     case DFmode:
5569       if (cum->float_in_sse < 2)
5570         break;
5571     case SFmode:
5572       if (cum->float_in_sse < 1)
5573         break;
5574       /* FALLTHRU */
5575     case TImode:
5576       /* In 32bit, we pass TImode in xmm registers.  */
5577     case V16QImode:
5578     case V8HImode:
5579     case V4SImode:
5580     case V2DImode:
5581     case V4SFmode:
5582     case V2DFmode:
5583       if (!type || !AGGREGATE_TYPE_P (type))
5584         {
5585           if (!TARGET_SSE && !warnedsse && cum->warn_sse)
5586             {
5587               warnedsse = true;
5588               warning (0, "SSE vector argument without SSE enabled "
5589                        "changes the ABI");
5590             }
5591           if (cum->sse_nregs)
5592             return gen_reg_or_parallel (mode, orig_mode,
5593                                         cum->sse_regno + FIRST_SSE_REG);
5594         }
5595       break;
5596
5597     case OImode:
5598       /* In 32bit, we pass OImode in ymm registers.  */
5599     case V8SFmode:
5600     case V8SImode:
5601     case V32QImode:
5602     case V16HImode:
5603     case V4DFmode:
5604     case V4DImode:
5605       if (!type || !AGGREGATE_TYPE_P (type))
5606         {
5607           if (!TARGET_AVX && !warnedavx && cum->warn_avx)
5608             {
5609               warnedavx = true;
5610               warning (0, "AVX vector argument without AVX enabled "
5611                        "changes the ABI");
5612             }
5613           if (cum->sse_nregs)
5614             return gen_reg_or_parallel (mode, orig_mode,
5615                                         cum->sse_regno + FIRST_SSE_REG);
5616         }
5617       break;
5618
5619     case V8QImode:
5620     case V4HImode:
5621     case V2SImode:
5622     case V2SFmode:
5623     case V1DImode:
5624       if (!type || !AGGREGATE_TYPE_P (type))
5625         {
5626           if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
5627             {
5628               warnedmmx = true;
5629               warning (0, "MMX vector argument without MMX enabled "
5630                        "changes the ABI");
5631             }
5632           if (cum->mmx_nregs)
5633             return gen_reg_or_parallel (mode, orig_mode,
5634                                         cum->mmx_regno + FIRST_MMX_REG);
5635         }
5636       break;
5637     }
5638
5639   return NULL_RTX;
5640 }
5641
5642 static rtx
5643 function_arg_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5644                  enum machine_mode orig_mode, tree type, int named)
5645 {
5646   static bool warnedavx;
5647
5648   /* Handle a hidden AL argument containing number of registers
5649      for varargs x86-64 functions.  */
5650   if (mode == VOIDmode)
5651     return GEN_INT (cum->maybe_vaarg
5652                     ? (cum->sse_nregs < 0
5653                        ? (cum->call_abi == DEFAULT_ABI
5654                           ? SSE_REGPARM_MAX
5655                           : (DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
5656                                                      : X64_SSE_REGPARM_MAX))
5657                : cum->sse_regno)
5658                     : -1);
5659
5660   switch (mode)
5661     {
5662     default:
5663       break;
5664
5665     case V8SFmode:
5666     case V8SImode:
5667     case V32QImode:
5668     case V16HImode:
5669     case V4DFmode:
5670     case V4DImode:
5671       /* In 64bit, we pass TImode in interger registers and OImode on
5672          stack.  */
5673       if (!type || !AGGREGATE_TYPE_P (type))
5674         {
5675           if (!TARGET_AVX && !warnedavx && cum->warn_avx)
5676             {
5677               warnedavx = true;
5678               warning (0, "AVX vector argument without AVX enabled "
5679                        "changes the ABI");
5680             }
5681         }
5682
5683       /* Unnamed 256bit vector mode parameters are passed on stack.  */
5684       if (!named)
5685         return NULL;
5686       break;
5687     }
5688
5689   return construct_container (mode, orig_mode, type, 0, cum->nregs,
5690                               cum->sse_nregs,
5691                               &x86_64_int_parameter_registers [cum->regno],
5692                               cum->sse_regno);
5693 }
5694
5695 static rtx
5696 function_arg_ms_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5697                     enum machine_mode orig_mode, int named,
5698                     HOST_WIDE_INT bytes)
5699 {
5700   unsigned int regno;
5701
5702   /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
5703      We use value of -2 to specify that current function call is MSABI.  */
5704   if (mode == VOIDmode)
5705     return GEN_INT (-2);
5706
5707   /* If we've run out of registers, it goes on the stack.  */
5708   if (cum->nregs == 0)
5709     return NULL_RTX;
5710
5711   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
5712
5713   /* Only floating point modes are passed in anything but integer regs.  */
5714   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
5715     {
5716       if (named)
5717         regno = cum->regno + FIRST_SSE_REG;
5718       else
5719         {
5720           rtx t1, t2;
5721
5722           /* Unnamed floating parameters are passed in both the
5723              SSE and integer registers.  */
5724           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
5725           t2 = gen_rtx_REG (mode, regno);
5726           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
5727           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
5728           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
5729         }
5730     }
5731   /* Handle aggregated types passed in register.  */
5732   if (orig_mode == BLKmode)
5733     {
5734       if (bytes > 0 && bytes <= 8)
5735         mode = (bytes > 4 ? DImode : SImode);
5736       if (mode == BLKmode)
5737         mode = DImode;
5738     }
5739
5740   return gen_reg_or_parallel (mode, orig_mode, regno);
5741 }
5742
5743 rtx
5744 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
5745               tree type, int named)
5746 {
5747   enum machine_mode mode = omode;
5748   HOST_WIDE_INT bytes, words;
5749
5750   if (mode == BLKmode)
5751     bytes = int_size_in_bytes (type);
5752   else
5753     bytes = GET_MODE_SIZE (mode);
5754   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5755
5756   /* To simplify the code below, represent vector types with a vector mode
5757      even if MMX/SSE are not active.  */
5758   if (type && TREE_CODE (type) == VECTOR_TYPE)
5759     mode = type_natural_mode (type);
5760
5761   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5762     return function_arg_ms_64 (cum, mode, omode, named, bytes);
5763   else if (TARGET_64BIT)
5764     return function_arg_64 (cum, mode, omode, type, named);
5765   else
5766     return function_arg_32 (cum, mode, omode, type, bytes, words);
5767 }
5768
5769 /* A C expression that indicates when an argument must be passed by
5770    reference.  If nonzero for an argument, a copy of that argument is
5771    made in memory and a pointer to the argument is passed instead of
5772    the argument itself.  The pointer is passed in whatever way is
5773    appropriate for passing a pointer to that type.  */
5774
5775 static bool
5776 ix86_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5777                         enum machine_mode mode ATTRIBUTE_UNUSED,
5778                         const_tree type, bool named ATTRIBUTE_UNUSED)
5779 {
5780   /* See Windows x64 Software Convention.  */
5781   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5782     {
5783       int msize = (int) GET_MODE_SIZE (mode);
5784       if (type)
5785         {
5786           /* Arrays are passed by reference.  */
5787           if (TREE_CODE (type) == ARRAY_TYPE)
5788             return true;
5789
5790           if (AGGREGATE_TYPE_P (type))
5791             {
5792               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
5793                  are passed by reference.  */
5794               msize = int_size_in_bytes (type);
5795             }
5796         }
5797
5798       /* __m128 is passed by reference.  */
5799       switch (msize) {
5800       case 1: case 2: case 4: case 8:
5801         break;
5802       default:
5803         return true;
5804       }
5805     }
5806   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
5807     return 1;
5808
5809   return 0;
5810 }
5811
5812 /* Return true when TYPE should be 128bit aligned for 32bit argument passing
5813    ABI.  */
5814 static bool
5815 contains_aligned_value_p (tree type)
5816 {
5817   enum machine_mode mode = TYPE_MODE (type);
5818   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
5819        || mode == TDmode
5820        || mode == TFmode
5821        || mode == TCmode)
5822       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
5823     return true;
5824   if (TYPE_ALIGN (type) < 128)
5825     return false;
5826
5827   if (AGGREGATE_TYPE_P (type))
5828     {
5829       /* Walk the aggregates recursively.  */
5830       switch (TREE_CODE (type))
5831         {
5832         case RECORD_TYPE:
5833         case UNION_TYPE:
5834         case QUAL_UNION_TYPE:
5835           {
5836             tree field;
5837
5838             /* Walk all the structure fields.  */
5839             for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5840               {
5841                 if (TREE_CODE (field) == FIELD_DECL
5842                     && contains_aligned_value_p (TREE_TYPE (field)))
5843                   return true;
5844               }
5845             break;
5846           }
5847
5848         case ARRAY_TYPE:
5849           /* Just for use if some languages passes arrays by value.  */
5850           if (contains_aligned_value_p (TREE_TYPE (type)))
5851             return true;
5852           break;
5853
5854         default:
5855           gcc_unreachable ();
5856         }
5857     }
5858   return false;
5859 }
5860
5861 /* Gives the alignment boundary, in bits, of an argument with the
5862    specified mode and type.  */
5863
5864 int
5865 ix86_function_arg_boundary (enum machine_mode mode, tree type)
5866 {
5867   int align;
5868   if (type)
5869     {
5870       /* Since canonical type is used for call, we convert it to
5871          canonical type if needed.  */
5872       if (!TYPE_STRUCTURAL_EQUALITY_P (type))
5873         type = TYPE_CANONICAL (type);
5874       align = TYPE_ALIGN (type);
5875     }
5876   else
5877     align = GET_MODE_ALIGNMENT (mode);
5878   if (align < PARM_BOUNDARY)
5879     align = PARM_BOUNDARY;
5880   /* In 32bit, only _Decimal128 and __float128 are aligned to their
5881      natural boundaries.  */
5882   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
5883     {
5884       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
5885          make an exception for SSE modes since these require 128bit
5886          alignment.
5887
5888          The handling here differs from field_alignment.  ICC aligns MMX
5889          arguments to 4 byte boundaries, while structure fields are aligned
5890          to 8 byte boundaries.  */
5891       if (!type)
5892         {
5893           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
5894             align = PARM_BOUNDARY;
5895         }
5896       else
5897         {
5898           if (!contains_aligned_value_p (type))
5899             align = PARM_BOUNDARY;
5900         }
5901     }
5902   if (align > BIGGEST_ALIGNMENT)
5903     align = BIGGEST_ALIGNMENT;
5904   return align;
5905 }
5906
5907 /* Return true if N is a possible register number of function value.  */
5908
5909 bool
5910 ix86_function_value_regno_p (int regno)
5911 {
5912   switch (regno)
5913     {
5914     case 0:
5915       return true;
5916
5917     case FIRST_FLOAT_REG:
5918       /* TODO: The function should depend on current function ABI but
5919        builtins.c would need updating then. Therefore we use the
5920        default ABI.  */
5921       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
5922         return false;
5923       return TARGET_FLOAT_RETURNS_IN_80387;
5924
5925     case FIRST_SSE_REG:
5926       return TARGET_SSE;
5927
5928     case FIRST_MMX_REG:
5929       if (TARGET_MACHO || TARGET_64BIT)
5930         return false;
5931       return TARGET_MMX;
5932     }
5933
5934   return false;
5935 }
5936
5937 /* Define how to find the value returned by a function.
5938    VALTYPE is the data type of the value (as a tree).
5939    If the precise function being called is known, FUNC is its FUNCTION_DECL;
5940    otherwise, FUNC is 0.  */
5941
5942 static rtx
5943 function_value_32 (enum machine_mode orig_mode, enum machine_mode mode,
5944                    const_tree fntype, const_tree fn)
5945 {
5946   unsigned int regno;
5947
5948   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
5949      we normally prevent this case when mmx is not available.  However
5950      some ABIs may require the result to be returned like DImode.  */
5951   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
5952     regno = TARGET_MMX ? FIRST_MMX_REG : 0;
5953
5954   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
5955      we prevent this case when sse is not available.  However some ABIs
5956      may require the result to be returned like integer TImode.  */
5957   else if (mode == TImode
5958            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
5959     regno = TARGET_SSE ? FIRST_SSE_REG : 0;
5960
5961   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
5962   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
5963     regno = FIRST_FLOAT_REG;
5964   else
5965     /* Most things go in %eax.  */
5966     regno = AX_REG;
5967
5968   /* Override FP return register with %xmm0 for local functions when
5969      SSE math is enabled or for functions with sseregparm attribute.  */
5970   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
5971     {
5972       int sse_level = ix86_function_sseregparm (fntype, fn, false);
5973       if ((sse_level >= 1 && mode == SFmode)
5974           || (sse_level == 2 && mode == DFmode))
5975         regno = FIRST_SSE_REG;
5976     }
5977
5978   return gen_rtx_REG (orig_mode, regno);
5979 }
5980
5981 static rtx
5982 function_value_64 (enum machine_mode orig_mode, enum machine_mode mode,
5983                    const_tree valtype)
5984 {
5985   rtx ret;
5986
5987   /* Handle libcalls, which don't provide a type node.  */
5988   if (valtype == NULL)
5989     {
5990       switch (mode)
5991         {
5992         case SFmode:
5993         case SCmode:
5994         case DFmode:
5995         case DCmode:
5996         case TFmode:
5997         case SDmode:
5998         case DDmode:
5999         case TDmode:
6000           return gen_rtx_REG (mode, FIRST_SSE_REG);
6001         case XFmode:
6002         case XCmode:
6003           return gen_rtx_REG (mode, FIRST_FLOAT_REG);
6004         case TCmode:
6005           return NULL;
6006         default:
6007           return gen_rtx_REG (mode, AX_REG);
6008         }
6009     }
6010
6011   ret = construct_container (mode, orig_mode, valtype, 1,
6012                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
6013                              x86_64_int_return_registers, 0);
6014
6015   /* For zero sized structures, construct_container returns NULL, but we
6016      need to keep rest of compiler happy by returning meaningful value.  */
6017   if (!ret)
6018     ret = gen_rtx_REG (orig_mode, AX_REG);
6019
6020   return ret;
6021 }
6022
6023 static rtx
6024 function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
6025 {
6026   unsigned int regno = AX_REG;
6027
6028   if (TARGET_SSE)
6029     {
6030       switch (GET_MODE_SIZE (mode))
6031         {
6032         case 16:
6033           if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6034              && !COMPLEX_MODE_P (mode))
6035             regno = FIRST_SSE_REG;
6036           break;
6037         case 8:
6038         case 4:
6039           if (mode == SFmode || mode == DFmode)
6040             regno = FIRST_SSE_REG;
6041           break;
6042         default:
6043           break;
6044         }
6045     }
6046   return gen_rtx_REG (orig_mode, regno);
6047 }
6048
6049 static rtx
6050 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
6051                        enum machine_mode orig_mode, enum machine_mode mode)
6052 {
6053   const_tree fn, fntype;
6054
6055   fn = NULL_TREE;
6056   if (fntype_or_decl && DECL_P (fntype_or_decl))
6057     fn = fntype_or_decl;
6058   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
6059
6060   if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
6061     return function_value_ms_64 (orig_mode, mode);
6062   else if (TARGET_64BIT)
6063     return function_value_64 (orig_mode, mode, valtype);
6064   else
6065     return function_value_32 (orig_mode, mode, fntype, fn);
6066 }
6067
6068 static rtx
6069 ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
6070                      bool outgoing ATTRIBUTE_UNUSED)
6071 {
6072   enum machine_mode mode, orig_mode;
6073
6074   orig_mode = TYPE_MODE (valtype);
6075   mode = type_natural_mode (valtype);
6076   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
6077 }
6078
6079 rtx
6080 ix86_libcall_value (enum machine_mode mode)
6081 {
6082   return ix86_function_value_1 (NULL, NULL, mode, mode);
6083 }
6084
6085 /* Return true iff type is returned in memory.  */
6086
6087 static int ATTRIBUTE_UNUSED
6088 return_in_memory_32 (const_tree type, enum machine_mode mode)
6089 {
6090   HOST_WIDE_INT size;
6091
6092   if (mode == BLKmode)
6093     return 1;
6094
6095   size = int_size_in_bytes (type);
6096
6097   if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
6098     return 0;
6099
6100   if (VECTOR_MODE_P (mode) || mode == TImode)
6101     {
6102       /* User-created vectors small enough to fit in EAX.  */
6103       if (size < 8)
6104         return 0;
6105
6106       /* MMX/3dNow values are returned in MM0,
6107          except when it doesn't exits.  */
6108       if (size == 8)
6109         return (TARGET_MMX ? 0 : 1);
6110
6111       /* SSE values are returned in XMM0, except when it doesn't exist.  */
6112       if (size == 16)
6113         return (TARGET_SSE ? 0 : 1);
6114     }
6115
6116   if (mode == XFmode)
6117     return 0;
6118
6119   if (size > 12)
6120     return 1;
6121   return 0;
6122 }
6123
6124 static int ATTRIBUTE_UNUSED
6125 return_in_memory_64 (const_tree type, enum machine_mode mode)
6126 {
6127   int needed_intregs, needed_sseregs;
6128   return !examine_argument (mode, type, 1, &needed_intregs, &needed_sseregs);
6129 }
6130
6131 static int ATTRIBUTE_UNUSED
6132 return_in_memory_ms_64 (const_tree type, enum machine_mode mode)
6133 {
6134   HOST_WIDE_INT size = int_size_in_bytes (type);
6135
6136   /* __m128 is returned in xmm0.  */
6137   if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6138       && !COMPLEX_MODE_P (mode) && (GET_MODE_SIZE (mode) == 16 || size == 16))
6139     return 0;
6140
6141   /* Otherwise, the size must be exactly in [1248]. */
6142   return (size != 1 && size != 2 && size != 4 && size != 8);
6143 }
6144
6145 static bool
6146 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6147 {
6148 #ifdef SUBTARGET_RETURN_IN_MEMORY
6149   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
6150 #else
6151    const enum machine_mode mode = type_natural_mode (type);
6152  
6153   if (TARGET_64BIT_MS_ABI)
6154      return return_in_memory_ms_64 (type, mode);
6155    else if (TARGET_64BIT)
6156      return return_in_memory_64 (type, mode);
6157    else
6158      return return_in_memory_32 (type, mode);
6159 #endif
6160 }
6161
6162 /* Return false iff TYPE is returned in memory.  This version is used
6163    on Solaris 10.  It is similar to the generic ix86_return_in_memory,
6164    but differs notably in that when MMX is available, 8-byte vectors
6165    are returned in memory, rather than in MMX registers.  */
6166
6167 bool
6168 ix86_sol10_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6169 {
6170   int size;
6171   enum machine_mode mode = type_natural_mode (type);
6172
6173   if (TARGET_64BIT)
6174     return return_in_memory_64 (type, mode);
6175
6176   if (mode == BLKmode)
6177     return 1;
6178
6179   size = int_size_in_bytes (type);
6180
6181   if (VECTOR_MODE_P (mode))
6182     {
6183       /* Return in memory only if MMX registers *are* available.  This
6184          seems backwards, but it is consistent with the existing
6185          Solaris x86 ABI.  */
6186       if (size == 8)
6187         return TARGET_MMX;
6188       if (size == 16)
6189         return !TARGET_SSE;
6190     }
6191   else if (mode == TImode)
6192     return !TARGET_SSE;
6193   else if (mode == XFmode)
6194     return 0;
6195
6196   return size > 12;
6197 }
6198
6199 /* When returning SSE vector types, we have a choice of either
6200      (1) being abi incompatible with a -march switch, or
6201      (2) generating an error.
6202    Given no good solution, I think the safest thing is one warning.
6203    The user won't be able to use -Werror, but....
6204
6205    Choose the STRUCT_VALUE_RTX hook because that's (at present) only
6206    called in response to actually generating a caller or callee that
6207    uses such a type.  As opposed to TARGET_RETURN_IN_MEMORY, which is called
6208    via aggregate_value_p for general type probing from tree-ssa.  */
6209
6210 static rtx
6211 ix86_struct_value_rtx (tree type, int incoming ATTRIBUTE_UNUSED)
6212 {
6213   static bool warnedsse, warnedmmx;
6214
6215   if (!TARGET_64BIT && type)
6216     {
6217       /* Look at the return type of the function, not the function type.  */
6218       enum machine_mode mode = TYPE_MODE (TREE_TYPE (type));
6219
6220       if (!TARGET_SSE && !warnedsse)
6221         {
6222           if (mode == TImode
6223               || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6224             {
6225               warnedsse = true;
6226               warning (0, "SSE vector return without SSE enabled "
6227                        "changes the ABI");
6228             }
6229         }
6230
6231       if (!TARGET_MMX && !warnedmmx)
6232         {
6233           if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6234             {
6235               warnedmmx = true;
6236               warning (0, "MMX vector return without MMX enabled "
6237                        "changes the ABI");
6238             }
6239         }
6240     }
6241
6242   return NULL;
6243 }
6244
6245 \f
6246 /* Create the va_list data type.  */
6247
6248 /* Returns the calling convention specific va_list date type.
6249    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
6250
6251 static tree
6252 ix86_build_builtin_va_list_abi (enum calling_abi abi)
6253 {
6254   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
6255
6256   /* For i386 we use plain pointer to argument area.  */
6257   if (!TARGET_64BIT || abi == MS_ABI)
6258     return build_pointer_type (char_type_node);
6259
6260   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6261   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6262
6263   f_gpr = build_decl (FIELD_DECL, get_identifier ("gp_offset"),
6264                       unsigned_type_node);
6265   f_fpr = build_decl (FIELD_DECL, get_identifier ("fp_offset"),
6266                       unsigned_type_node);
6267   f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
6268                       ptr_type_node);
6269   f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
6270                       ptr_type_node);
6271
6272   va_list_gpr_counter_field = f_gpr;
6273   va_list_fpr_counter_field = f_fpr;
6274
6275   DECL_FIELD_CONTEXT (f_gpr) = record;
6276   DECL_FIELD_CONTEXT (f_fpr) = record;
6277   DECL_FIELD_CONTEXT (f_ovf) = record;
6278   DECL_FIELD_CONTEXT (f_sav) = record;
6279
6280   TREE_CHAIN (record) = type_decl;
6281   TYPE_NAME (record) = type_decl;
6282   TYPE_FIELDS (record) = f_gpr;
6283   TREE_CHAIN (f_gpr) = f_fpr;
6284   TREE_CHAIN (f_fpr) = f_ovf;
6285   TREE_CHAIN (f_ovf) = f_sav;
6286
6287   layout_type (record);
6288
6289   /* The correct type is an array type of one element.  */
6290   return build_array_type (record, build_index_type (size_zero_node));
6291 }
6292
6293 /* Setup the builtin va_list data type and for 64-bit the additional
6294    calling convention specific va_list data types.  */
6295
6296 static tree
6297 ix86_build_builtin_va_list (void)
6298 {
6299   tree ret = ix86_build_builtin_va_list_abi (DEFAULT_ABI);
6300
6301   /* Initialize abi specific va_list builtin types.  */
6302   if (TARGET_64BIT)
6303     {
6304       tree t;
6305       if (DEFAULT_ABI == MS_ABI)
6306         {
6307           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
6308           if (TREE_CODE (t) != RECORD_TYPE)
6309             t = build_variant_type_copy (t);
6310           sysv_va_list_type_node = t;
6311         }
6312       else
6313         {
6314           t = ret;
6315           if (TREE_CODE (t) != RECORD_TYPE)
6316             t = build_variant_type_copy (t);
6317           sysv_va_list_type_node = t;
6318         }
6319       if (DEFAULT_ABI != MS_ABI)
6320         {
6321           t = ix86_build_builtin_va_list_abi (MS_ABI);
6322           if (TREE_CODE (t) != RECORD_TYPE)
6323             t = build_variant_type_copy (t);
6324           ms_va_list_type_node = t;
6325         }
6326       else
6327         {
6328           t = ret;
6329           if (TREE_CODE (t) != RECORD_TYPE)
6330             t = build_variant_type_copy (t);
6331           ms_va_list_type_node = t;
6332         }
6333     }
6334
6335   return ret;
6336 }
6337
6338 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
6339
6340 static void
6341 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
6342 {
6343   rtx save_area, mem;
6344   rtx label;
6345   rtx label_ref;
6346   rtx tmp_reg;
6347   rtx nsse_reg;
6348   alias_set_type set;
6349   int i;
6350   int regparm = ix86_regparm;
6351
6352   if (cum->call_abi != DEFAULT_ABI)
6353     regparm = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
6354
6355   /* GPR size of varargs save area.  */
6356   if (cfun->va_list_gpr_size)
6357     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
6358   else
6359     ix86_varargs_gpr_size = 0;
6360
6361   /* FPR size of varargs save area.  We don't need it if we don't pass
6362      anything in SSE registers.  */
6363   if (cum->sse_nregs && cfun->va_list_fpr_size)
6364     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
6365   else
6366     ix86_varargs_fpr_size = 0;
6367
6368   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
6369     return;
6370
6371   save_area = frame_pointer_rtx;
6372   set = get_varargs_alias_set ();
6373
6374   for (i = cum->regno;
6375        i < regparm
6376        && i < cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
6377        i++)
6378     {
6379       mem = gen_rtx_MEM (Pmode,
6380                          plus_constant (save_area, i * UNITS_PER_WORD));
6381       MEM_NOTRAP_P (mem) = 1;
6382       set_mem_alias_set (mem, set);
6383       emit_move_insn (mem, gen_rtx_REG (Pmode,
6384                                         x86_64_int_parameter_registers[i]));
6385     }
6386
6387   if (ix86_varargs_fpr_size)
6388     {
6389       /* Now emit code to save SSE registers.  The AX parameter contains number
6390          of SSE parameter registers used to call this function.  We use
6391          sse_prologue_save insn template that produces computed jump across
6392          SSE saves.  We need some preparation work to get this working.  */
6393
6394       label = gen_label_rtx ();
6395       label_ref = gen_rtx_LABEL_REF (Pmode, label);
6396
6397       /* Compute address to jump to :
6398          label - eax*4 + nnamed_sse_arguments*4 Or
6399          label - eax*5 + nnamed_sse_arguments*5 for AVX.  */
6400       tmp_reg = gen_reg_rtx (Pmode);
6401       nsse_reg = gen_reg_rtx (Pmode);
6402       emit_insn (gen_zero_extendqidi2 (nsse_reg, gen_rtx_REG (QImode, AX_REG)));
6403       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6404                               gen_rtx_MULT (Pmode, nsse_reg,
6405                                             GEN_INT (4))));
6406
6407       /* vmovaps is one byte longer than movaps.  */
6408       if (TARGET_AVX)
6409         emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6410                                 gen_rtx_PLUS (Pmode, tmp_reg,
6411                                               nsse_reg)));
6412
6413       if (cum->sse_regno)
6414         emit_move_insn
6415           (nsse_reg,
6416            gen_rtx_CONST (DImode,
6417                           gen_rtx_PLUS (DImode,
6418                                         label_ref,
6419                                         GEN_INT (cum->sse_regno
6420                                                  * (TARGET_AVX ? 5 : 4)))));
6421       else
6422         emit_move_insn (nsse_reg, label_ref);
6423       emit_insn (gen_subdi3 (nsse_reg, nsse_reg, tmp_reg));
6424
6425       /* Compute address of memory block we save into.  We always use pointer
6426          pointing 127 bytes after first byte to store - this is needed to keep
6427          instruction size limited by 4 bytes (5 bytes for AVX) with one
6428          byte displacement.  */
6429       tmp_reg = gen_reg_rtx (Pmode);
6430       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6431                               plus_constant (save_area,
6432                                              ix86_varargs_gpr_size + 127)));
6433       mem = gen_rtx_MEM (BLKmode, plus_constant (tmp_reg, -127));
6434       MEM_NOTRAP_P (mem) = 1;
6435       set_mem_alias_set (mem, set);
6436       set_mem_align (mem, BITS_PER_WORD);
6437
6438       /* And finally do the dirty job!  */
6439       emit_insn (gen_sse_prologue_save (mem, nsse_reg,
6440                                         GEN_INT (cum->sse_regno), label));
6441     }
6442 }
6443
6444 static void
6445 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
6446 {
6447   alias_set_type set = get_varargs_alias_set ();
6448   int i;
6449
6450   for (i = cum->regno; i < X64_REGPARM_MAX; i++)
6451     {
6452       rtx reg, mem;
6453
6454       mem = gen_rtx_MEM (Pmode,
6455                          plus_constant (virtual_incoming_args_rtx,
6456                                         i * UNITS_PER_WORD));
6457       MEM_NOTRAP_P (mem) = 1;
6458       set_mem_alias_set (mem, set);
6459
6460       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
6461       emit_move_insn (mem, reg);
6462     }
6463 }
6464
6465 static void
6466 ix86_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
6467                              tree type, int *pretend_size ATTRIBUTE_UNUSED,
6468                              int no_rtl)
6469 {
6470   CUMULATIVE_ARGS next_cum;
6471   tree fntype;
6472
6473   /* This argument doesn't appear to be used anymore.  Which is good,
6474      because the old code here didn't suppress rtl generation.  */
6475   gcc_assert (!no_rtl);
6476
6477   if (!TARGET_64BIT)
6478     return;
6479
6480   fntype = TREE_TYPE (current_function_decl);
6481
6482   /* For varargs, we do not want to skip the dummy va_dcl argument.
6483      For stdargs, we do want to skip the last named argument.  */
6484   next_cum = *cum;
6485   if (stdarg_p (fntype))
6486     function_arg_advance (&next_cum, mode, type, 1);
6487
6488   if (cum->call_abi == MS_ABI)
6489     setup_incoming_varargs_ms_64 (&next_cum);
6490   else
6491     setup_incoming_varargs_64 (&next_cum);
6492 }
6493
6494 /* Checks if TYPE is of kind va_list char *.  */
6495
6496 static bool
6497 is_va_list_char_pointer (tree type)
6498 {
6499   tree canonic;
6500
6501   /* For 32-bit it is always true.  */
6502   if (!TARGET_64BIT)
6503     return true;
6504   canonic = ix86_canonical_va_list_type (type);
6505   return (canonic == ms_va_list_type_node
6506           || (DEFAULT_ABI == MS_ABI && canonic == va_list_type_node));
6507 }
6508
6509 /* Implement va_start.  */
6510
6511 static void
6512 ix86_va_start (tree valist, rtx nextarg)
6513 {
6514   HOST_WIDE_INT words, n_gpr, n_fpr;
6515   tree f_gpr, f_fpr, f_ovf, f_sav;
6516   tree gpr, fpr, ovf, sav, t;
6517   tree type;
6518
6519   /* Only 64bit target needs something special.  */
6520   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6521     {
6522       std_expand_builtin_va_start (valist, nextarg);
6523       return;
6524     }
6525
6526   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6527   f_fpr = TREE_CHAIN (f_gpr);
6528   f_ovf = TREE_CHAIN (f_fpr);
6529   f_sav = TREE_CHAIN (f_ovf);
6530
6531   valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
6532   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6533   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6534   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6535   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6536
6537   /* Count number of gp and fp argument registers used.  */
6538   words = crtl->args.info.words;
6539   n_gpr = crtl->args.info.regno;
6540   n_fpr = crtl->args.info.sse_regno;
6541
6542   if (cfun->va_list_gpr_size)
6543     {
6544       type = TREE_TYPE (gpr);
6545       t = build2 (MODIFY_EXPR, type,
6546                   gpr, build_int_cst (type, n_gpr * 8));
6547       TREE_SIDE_EFFECTS (t) = 1;
6548       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6549     }
6550
6551   if (TARGET_SSE && cfun->va_list_fpr_size)
6552     {
6553       type = TREE_TYPE (fpr);
6554       t = build2 (MODIFY_EXPR, type, fpr,
6555                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
6556       TREE_SIDE_EFFECTS (t) = 1;
6557       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6558     }
6559
6560   /* Find the overflow area.  */
6561   type = TREE_TYPE (ovf);
6562   t = make_tree (type, crtl->args.internal_arg_pointer);
6563   if (words != 0)
6564     t = build2 (POINTER_PLUS_EXPR, type, t,
6565                 size_int (words * UNITS_PER_WORD));
6566   t = build2 (MODIFY_EXPR, type, ovf, t);
6567   TREE_SIDE_EFFECTS (t) = 1;
6568   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6569
6570   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
6571     {
6572       /* Find the register save area.
6573          Prologue of the function save it right above stack frame.  */
6574       type = TREE_TYPE (sav);
6575       t = make_tree (type, frame_pointer_rtx);
6576       if (!ix86_varargs_gpr_size)
6577         t = build2 (POINTER_PLUS_EXPR, type, t,
6578                     size_int (-8 * X86_64_REGPARM_MAX));
6579       t = build2 (MODIFY_EXPR, type, sav, t);
6580       TREE_SIDE_EFFECTS (t) = 1;
6581       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6582     }
6583 }
6584
6585 /* Implement va_arg.  */
6586
6587 static tree
6588 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
6589                       gimple_seq *post_p)
6590 {
6591   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
6592   tree f_gpr, f_fpr, f_ovf, f_sav;
6593   tree gpr, fpr, ovf, sav, t;
6594   int size, rsize;
6595   tree lab_false, lab_over = NULL_TREE;
6596   tree addr, t2;
6597   rtx container;
6598   int indirect_p = 0;
6599   tree ptrtype;
6600   enum machine_mode nat_mode;
6601   int arg_boundary;
6602
6603   /* Only 64bit target needs something special.  */
6604   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6605     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6606
6607   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6608   f_fpr = TREE_CHAIN (f_gpr);
6609   f_ovf = TREE_CHAIN (f_fpr);
6610   f_sav = TREE_CHAIN (f_ovf);
6611
6612   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
6613                 build_va_arg_indirect_ref (valist), f_gpr, NULL_TREE);
6614   valist = build_va_arg_indirect_ref (valist);
6615   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6616   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6617   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6618
6619   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
6620   if (indirect_p)
6621     type = build_pointer_type (type);
6622   size = int_size_in_bytes (type);
6623   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6624
6625   nat_mode = type_natural_mode (type);
6626   switch (nat_mode)
6627     {
6628     case V8SFmode:
6629     case V8SImode:
6630     case V32QImode:
6631     case V16HImode:
6632     case V4DFmode:
6633     case V4DImode:
6634       /* Unnamed 256bit vector mode parameters are passed on stack.  */
6635       if (ix86_cfun_abi () == SYSV_ABI)
6636         {
6637           container = NULL;
6638           break;
6639         }
6640
6641     default:
6642       container = construct_container (nat_mode, TYPE_MODE (type),
6643                                        type, 0, X86_64_REGPARM_MAX,
6644                                        X86_64_SSE_REGPARM_MAX, intreg,
6645                                        0);
6646       break;
6647     }
6648
6649   /* Pull the value out of the saved registers.  */
6650
6651   addr = create_tmp_var (ptr_type_node, "addr");
6652   DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
6653
6654   if (container)
6655     {
6656       int needed_intregs, needed_sseregs;
6657       bool need_temp;
6658       tree int_addr, sse_addr;
6659
6660       lab_false = create_artificial_label ();
6661       lab_over = create_artificial_label ();
6662
6663       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
6664
6665       need_temp = (!REG_P (container)
6666                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
6667                        || TYPE_ALIGN (type) > 128));
6668
6669       /* In case we are passing structure, verify that it is consecutive block
6670          on the register save area.  If not we need to do moves.  */
6671       if (!need_temp && !REG_P (container))
6672         {
6673           /* Verify that all registers are strictly consecutive  */
6674           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
6675             {
6676               int i;
6677
6678               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6679                 {
6680                   rtx slot = XVECEXP (container, 0, i);
6681                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
6682                       || INTVAL (XEXP (slot, 1)) != i * 16)
6683                     need_temp = 1;
6684                 }
6685             }
6686           else
6687             {
6688               int i;
6689
6690               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6691                 {
6692                   rtx slot = XVECEXP (container, 0, i);
6693                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
6694                       || INTVAL (XEXP (slot, 1)) != i * 8)
6695                     need_temp = 1;
6696                 }
6697             }
6698         }
6699       if (!need_temp)
6700         {
6701           int_addr = addr;
6702           sse_addr = addr;
6703         }
6704       else
6705         {
6706           int_addr = create_tmp_var (ptr_type_node, "int_addr");
6707           DECL_POINTER_ALIAS_SET (int_addr) = get_varargs_alias_set ();
6708           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
6709           DECL_POINTER_ALIAS_SET (sse_addr) = get_varargs_alias_set ();
6710         }
6711
6712       /* First ensure that we fit completely in registers.  */
6713       if (needed_intregs)
6714         {
6715           t = build_int_cst (TREE_TYPE (gpr),
6716                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
6717           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
6718           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6719           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6720           gimplify_and_add (t, pre_p);
6721         }
6722       if (needed_sseregs)
6723         {
6724           t = build_int_cst (TREE_TYPE (fpr),
6725                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
6726                              + X86_64_REGPARM_MAX * 8);
6727           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
6728           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6729           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6730           gimplify_and_add (t, pre_p);
6731         }
6732
6733       /* Compute index to start of area used for integer regs.  */
6734       if (needed_intregs)
6735         {
6736           /* int_addr = gpr + sav; */
6737           t = fold_convert (sizetype, gpr);
6738           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6739           gimplify_assign (int_addr, t, pre_p);
6740         }
6741       if (needed_sseregs)
6742         {
6743           /* sse_addr = fpr + sav; */
6744           t = fold_convert (sizetype, fpr);
6745           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6746           gimplify_assign (sse_addr, t, pre_p);
6747         }
6748       if (need_temp)
6749         {
6750           int i;
6751           tree temp = create_tmp_var (type, "va_arg_tmp");
6752
6753           /* addr = &temp; */
6754           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
6755           gimplify_assign (addr, t, pre_p);
6756
6757           for (i = 0; i < XVECLEN (container, 0); i++)
6758             {
6759               rtx slot = XVECEXP (container, 0, i);
6760               rtx reg = XEXP (slot, 0);
6761               enum machine_mode mode = GET_MODE (reg);
6762               tree piece_type = lang_hooks.types.type_for_mode (mode, 1);
6763               tree addr_type = build_pointer_type (piece_type);
6764               tree daddr_type = build_pointer_type_for_mode (piece_type,
6765                                                              ptr_mode, true);
6766               tree src_addr, src;
6767               int src_offset;
6768               tree dest_addr, dest;
6769
6770               if (SSE_REGNO_P (REGNO (reg)))
6771                 {
6772                   src_addr = sse_addr;
6773                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
6774                 }
6775               else
6776                 {
6777                   src_addr = int_addr;
6778                   src_offset = REGNO (reg) * 8;
6779                 }
6780               src_addr = fold_convert (addr_type, src_addr);
6781               src_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, src_addr,
6782                                       size_int (src_offset));
6783               src = build_va_arg_indirect_ref (src_addr);
6784
6785               dest_addr = fold_convert (daddr_type, addr);
6786               dest_addr = fold_build2 (POINTER_PLUS_EXPR, daddr_type, dest_addr,
6787                                        size_int (INTVAL (XEXP (slot, 1))));
6788               dest = build_va_arg_indirect_ref (dest_addr);
6789
6790               gimplify_assign (dest, src, pre_p);
6791             }
6792         }
6793
6794       if (needed_intregs)
6795         {
6796           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
6797                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
6798           gimplify_assign (gpr, t, pre_p);
6799         }
6800
6801       if (needed_sseregs)
6802         {
6803           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
6804                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
6805           gimplify_assign (fpr, t, pre_p);
6806         }
6807
6808       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
6809
6810       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
6811     }
6812
6813   /* ... otherwise out of the overflow area.  */
6814
6815   /* When we align parameter on stack for caller, if the parameter
6816      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
6817      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
6818      here with caller.  */
6819   arg_boundary = FUNCTION_ARG_BOUNDARY (VOIDmode, type);
6820   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
6821     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
6822
6823   /* Care for on-stack alignment if needed.  */
6824   if (arg_boundary <= 64
6825       || integer_zerop (TYPE_SIZE (type)))
6826     t = ovf;
6827  else
6828     {
6829       HOST_WIDE_INT align = arg_boundary / 8;
6830       t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovf), ovf,
6831                   size_int (align - 1));
6832       t = fold_convert (sizetype, t);
6833       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
6834                   size_int (-align));
6835       t = fold_convert (TREE_TYPE (ovf), t);
6836     }
6837   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
6838   gimplify_assign (addr, t, pre_p);
6839
6840   t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
6841               size_int (rsize * UNITS_PER_WORD));
6842   gimplify_assign (unshare_expr (ovf), t, pre_p);
6843
6844   if (container)
6845     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
6846
6847   ptrtype = build_pointer_type (type);
6848   addr = fold_convert (ptrtype, addr);
6849
6850   if (indirect_p)
6851     addr = build_va_arg_indirect_ref (addr);
6852   return build_va_arg_indirect_ref (addr);
6853 }
6854 \f
6855 /* Return nonzero if OPNUM's MEM should be matched
6856    in movabs* patterns.  */
6857
6858 int
6859 ix86_check_movabs (rtx insn, int opnum)
6860 {
6861   rtx set, mem;
6862
6863   set = PATTERN (insn);
6864   if (GET_CODE (set) == PARALLEL)
6865     set = XVECEXP (set, 0, 0);
6866   gcc_assert (GET_CODE (set) == SET);
6867   mem = XEXP (set, opnum);
6868   while (GET_CODE (mem) == SUBREG)
6869     mem = SUBREG_REG (mem);
6870   gcc_assert (MEM_P (mem));
6871   return (volatile_ok || !MEM_VOLATILE_P (mem));
6872 }
6873 \f
6874 /* Initialize the table of extra 80387 mathematical constants.  */
6875
6876 static void
6877 init_ext_80387_constants (void)
6878 {
6879   static const char * cst[5] =
6880   {
6881     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
6882     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
6883     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
6884     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
6885     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
6886   };
6887   int i;
6888
6889   for (i = 0; i < 5; i++)
6890     {
6891       real_from_string (&ext_80387_constants_table[i], cst[i]);
6892       /* Ensure each constant is rounded to XFmode precision.  */
6893       real_convert (&ext_80387_constants_table[i],
6894                     XFmode, &ext_80387_constants_table[i]);
6895     }
6896
6897   ext_80387_constants_init = 1;
6898 }
6899
6900 /* Return true if the constant is something that can be loaded with
6901    a special instruction.  */
6902
6903 int
6904 standard_80387_constant_p (rtx x)
6905 {
6906   enum machine_mode mode = GET_MODE (x);
6907
6908   REAL_VALUE_TYPE r;
6909
6910   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
6911     return -1;
6912
6913   if (x == CONST0_RTX (mode))
6914     return 1;
6915   if (x == CONST1_RTX (mode))
6916     return 2;
6917
6918   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
6919
6920   /* For XFmode constants, try to find a special 80387 instruction when
6921      optimizing for size or on those CPUs that benefit from them.  */
6922   if (mode == XFmode
6923       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
6924     {
6925       int i;
6926
6927       if (! ext_80387_constants_init)
6928         init_ext_80387_constants ();
6929
6930       for (i = 0; i < 5; i++)
6931         if (real_identical (&r, &ext_80387_constants_table[i]))
6932           return i + 3;
6933     }
6934
6935   /* Load of the constant -0.0 or -1.0 will be split as
6936      fldz;fchs or fld1;fchs sequence.  */
6937   if (real_isnegzero (&r))
6938     return 8;
6939   if (real_identical (&r, &dconstm1))
6940     return 9;
6941
6942   return 0;
6943 }
6944
6945 /* Return the opcode of the special instruction to be used to load
6946    the constant X.  */
6947
6948 const char *
6949 standard_80387_constant_opcode (rtx x)
6950 {
6951   switch (standard_80387_constant_p (x))
6952     {
6953     case 1:
6954       return "fldz";
6955     case 2:
6956       return "fld1";
6957     case 3:
6958       return "fldlg2";
6959     case 4:
6960       return "fldln2";
6961     case 5:
6962       return "fldl2e";
6963     case 6:
6964       return "fldl2t";
6965     case 7:
6966       return "fldpi";
6967     case 8:
6968     case 9:
6969       return "#";
6970     default:
6971       gcc_unreachable ();
6972     }
6973 }
6974
6975 /* Return the CONST_DOUBLE representing the 80387 constant that is
6976    loaded by the specified special instruction.  The argument IDX
6977    matches the return value from standard_80387_constant_p.  */
6978
6979 rtx
6980 standard_80387_constant_rtx (int idx)
6981 {
6982   int i;
6983
6984   if (! ext_80387_constants_init)
6985     init_ext_80387_constants ();
6986
6987   switch (idx)
6988     {
6989     case 3:
6990     case 4:
6991     case 5:
6992     case 6:
6993     case 7:
6994       i = idx - 3;
6995       break;
6996
6997     default:
6998       gcc_unreachable ();
6999     }
7000
7001   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
7002                                        XFmode);
7003 }
7004
7005 /* Return 1 if mode is a valid mode for sse.  */
7006 static int
7007 standard_sse_mode_p (enum machine_mode mode)
7008 {
7009   switch (mode)
7010     {
7011     case V16QImode:
7012     case V8HImode:
7013     case V4SImode:
7014     case V2DImode:
7015     case V4SFmode:
7016     case V2DFmode:
7017       return 1;
7018
7019     default:
7020       return 0;
7021     }
7022 }
7023
7024 /* Return 1 if X is all 0s.  For all 1s, return 2 if X is in 128bit
7025    SSE modes and SSE2 is enabled,  return 3 if X is in 256bit AVX
7026    modes and AVX is enabled.  */
7027
7028 int
7029 standard_sse_constant_p (rtx x)
7030 {
7031   enum machine_mode mode = GET_MODE (x);
7032
7033   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
7034     return 1;
7035   if (vector_all_ones_operand (x, mode))
7036     {
7037       if (standard_sse_mode_p (mode))
7038         return TARGET_SSE2 ? 2 : -2;
7039       else if (VALID_AVX256_REG_MODE (mode))
7040         return TARGET_AVX ? 3 : -3;
7041     }
7042
7043   return 0;
7044 }
7045
7046 /* Return the opcode of the special instruction to be used to load
7047    the constant X.  */
7048
7049 const char *
7050 standard_sse_constant_opcode (rtx insn, rtx x)
7051 {
7052   switch (standard_sse_constant_p (x))
7053     {
7054     case 1:
7055       switch (get_attr_mode (insn))
7056         {
7057         case MODE_V4SF:
7058           return TARGET_AVX ? "vxorps\t%0, %0, %0" : "xorps\t%0, %0";
7059         case MODE_V2DF:
7060           return TARGET_AVX ? "vxorpd\t%0, %0, %0" : "xorpd\t%0, %0";
7061         case MODE_TI:
7062           return TARGET_AVX ? "vpxor\t%0, %0, %0" : "pxor\t%0, %0";
7063         case MODE_V8SF:
7064           return "vxorps\t%x0, %x0, %x0";
7065         case MODE_V4DF:
7066           return "vxorpd\t%x0, %x0, %x0";
7067         case MODE_OI:
7068           return "vpxor\t%x0, %x0, %x0";
7069         default:
7070           gcc_unreachable ();
7071         }
7072     case 2:
7073       if (TARGET_AVX)
7074         switch (get_attr_mode (insn))
7075           {
7076           case MODE_V4SF:
7077           case MODE_V2DF:
7078           case MODE_TI:
7079             return "vpcmpeqd\t%0, %0, %0";
7080             break;
7081           default:
7082             gcc_unreachable ();
7083         }
7084       else
7085         return "pcmpeqd\t%0, %0";
7086     }
7087   gcc_unreachable ();
7088 }
7089
7090 /* Returns 1 if OP contains a symbol reference */
7091
7092 int
7093 symbolic_reference_mentioned_p (rtx op)
7094 {
7095   const char *fmt;
7096   int i;
7097
7098   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
7099     return 1;
7100
7101   fmt = GET_RTX_FORMAT (GET_CODE (op));
7102   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
7103     {
7104       if (fmt[i] == 'E')
7105         {
7106           int j;
7107
7108           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
7109             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
7110               return 1;
7111         }
7112
7113       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
7114         return 1;
7115     }
7116
7117   return 0;
7118 }
7119
7120 /* Return 1 if it is appropriate to emit `ret' instructions in the
7121    body of a function.  Do this only if the epilogue is simple, needing a
7122    couple of insns.  Prior to reloading, we can't tell how many registers
7123    must be saved, so return 0 then.  Return 0 if there is no frame
7124    marker to de-allocate.  */
7125
7126 int
7127 ix86_can_use_return_insn_p (void)
7128 {
7129   struct ix86_frame frame;
7130
7131   if (! reload_completed || frame_pointer_needed)
7132     return 0;
7133
7134   /* Don't allow more than 32 pop, since that's all we can do
7135      with one instruction.  */
7136   if (crtl->args.pops_args
7137       && crtl->args.size >= 32768)
7138     return 0;
7139
7140   ix86_compute_frame_layout (&frame);
7141   return frame.to_allocate == 0 && frame.nregs == 0;
7142 }
7143 \f
7144 /* Value should be nonzero if functions must have frame pointers.
7145    Zero means the frame pointer need not be set up (and parms may
7146    be accessed via the stack pointer) in functions that seem suitable.  */
7147
7148 int
7149 ix86_frame_pointer_required (void)
7150 {
7151   /* If we accessed previous frames, then the generated code expects
7152      to be able to access the saved ebp value in our frame.  */
7153   if (cfun->machine->accesses_prev_frame)
7154     return 1;
7155
7156   /* Several x86 os'es need a frame pointer for other reasons,
7157      usually pertaining to setjmp.  */
7158   if (SUBTARGET_FRAME_POINTER_REQUIRED)
7159     return 1;
7160
7161   /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
7162      the frame pointer by default.  Turn it back on now if we've not
7163      got a leaf function.  */
7164   if (TARGET_OMIT_LEAF_FRAME_POINTER
7165       && (!current_function_is_leaf
7166           || ix86_current_function_calls_tls_descriptor))
7167     return 1;
7168
7169   if (crtl->profile)
7170     return 1;
7171
7172   return 0;
7173 }
7174
7175 /* Record that the current function accesses previous call frames.  */
7176
7177 void
7178 ix86_setup_frame_addresses (void)
7179 {
7180   cfun->machine->accesses_prev_frame = 1;
7181 }
7182 \f
7183 #if (defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)) || TARGET_MACHO
7184 # define USE_HIDDEN_LINKONCE 1
7185 #else
7186 # define USE_HIDDEN_LINKONCE 0
7187 #endif
7188
7189 static int pic_labels_used;
7190
7191 /* Fills in the label name that should be used for a pc thunk for
7192    the given register.  */
7193
7194 static void
7195 get_pc_thunk_name (char name[32], unsigned int regno)
7196 {
7197   gcc_assert (!TARGET_64BIT);
7198
7199   if (USE_HIDDEN_LINKONCE)
7200     sprintf (name, "__i686.get_pc_thunk.%s", reg_names[regno]);
7201   else
7202     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
7203 }
7204
7205
7206 /* This function generates code for -fpic that loads %ebx with
7207    the return address of the caller and then returns.  */
7208
7209 void
7210 ix86_file_end (void)
7211 {
7212   rtx xops[2];
7213   int regno;
7214
7215   for (regno = 0; regno < 8; ++regno)
7216     {
7217       char name[32];
7218
7219       if (! ((pic_labels_used >> regno) & 1))
7220         continue;
7221
7222       get_pc_thunk_name (name, regno);
7223
7224 #if TARGET_MACHO
7225       if (TARGET_MACHO)
7226         {
7227           switch_to_section (darwin_sections[text_coal_section]);
7228           fputs ("\t.weak_definition\t", asm_out_file);
7229           assemble_name (asm_out_file, name);
7230           fputs ("\n\t.private_extern\t", asm_out_file);
7231           assemble_name (asm_out_file, name);
7232           fputs ("\n", asm_out_file);
7233           ASM_OUTPUT_LABEL (asm_out_file, name);
7234         }
7235       else
7236 #endif
7237       if (USE_HIDDEN_LINKONCE)
7238         {
7239           tree decl;
7240
7241           decl = build_decl (FUNCTION_DECL, get_identifier (name),
7242                              error_mark_node);
7243           TREE_PUBLIC (decl) = 1;
7244           TREE_STATIC (decl) = 1;
7245           DECL_ONE_ONLY (decl) = 1;
7246
7247           (*targetm.asm_out.unique_section) (decl, 0);
7248           switch_to_section (get_named_section (decl, NULL, 0));
7249
7250           (*targetm.asm_out.globalize_label) (asm_out_file, name);
7251           fputs ("\t.hidden\t", asm_out_file);
7252           assemble_name (asm_out_file, name);
7253           fputc ('\n', asm_out_file);
7254           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
7255         }
7256       else
7257         {
7258           switch_to_section (text_section);
7259           ASM_OUTPUT_LABEL (asm_out_file, name);
7260         }
7261
7262       xops[0] = gen_rtx_REG (Pmode, regno);
7263       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
7264       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
7265       output_asm_insn ("ret", xops);
7266     }
7267
7268   if (NEED_INDICATE_EXEC_STACK)
7269     file_end_indicate_exec_stack ();
7270 }
7271
7272 /* Emit code for the SET_GOT patterns.  */
7273
7274 const char *
7275 output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
7276 {
7277   rtx xops[3];
7278
7279   xops[0] = dest;
7280
7281   if (TARGET_VXWORKS_RTP && flag_pic)
7282     {
7283       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
7284       xops[2] = gen_rtx_MEM (Pmode,
7285                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
7286       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
7287
7288       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
7289          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
7290          an unadorned address.  */
7291       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7292       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
7293       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
7294       return "";
7295     }
7296
7297   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
7298
7299   if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
7300     {
7301       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
7302
7303       if (!flag_pic)
7304         output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
7305       else
7306         output_asm_insn ("call\t%a2", xops);
7307
7308 #if TARGET_MACHO
7309       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7310          is what will be referenced by the Mach-O PIC subsystem.  */
7311       if (!label)
7312         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7313 #endif
7314
7315       (*targetm.asm_out.internal_label) (asm_out_file, "L",
7316                                  CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
7317
7318       if (flag_pic)
7319         output_asm_insn ("pop%z0\t%0", xops);
7320     }
7321   else
7322     {
7323       char name[32];
7324       get_pc_thunk_name (name, REGNO (dest));
7325       pic_labels_used |= 1 << REGNO (dest);
7326
7327       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
7328       xops[2] = gen_rtx_MEM (QImode, xops[2]);
7329       output_asm_insn ("call\t%X2", xops);
7330       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7331          is what will be referenced by the Mach-O PIC subsystem.  */
7332 #if TARGET_MACHO
7333       if (!label)
7334         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7335       else
7336         targetm.asm_out.internal_label (asm_out_file, "L",
7337                                            CODE_LABEL_NUMBER (label));
7338 #endif
7339     }
7340
7341   if (TARGET_MACHO)
7342     return "";
7343
7344   if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
7345     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
7346   else
7347     output_asm_insn ("add%z0\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
7348
7349   return "";
7350 }
7351
7352 /* Generate an "push" pattern for input ARG.  */
7353
7354 static rtx
7355 gen_push (rtx arg)
7356 {
7357   return gen_rtx_SET (VOIDmode,
7358                       gen_rtx_MEM (Pmode,
7359                                    gen_rtx_PRE_DEC (Pmode,
7360                                                     stack_pointer_rtx)),
7361                       arg);
7362 }
7363
7364 /* Return >= 0 if there is an unused call-clobbered register available
7365    for the entire function.  */
7366
7367 static unsigned int
7368 ix86_select_alt_pic_regnum (void)
7369 {
7370   if (current_function_is_leaf && !crtl->profile
7371       && !ix86_current_function_calls_tls_descriptor)
7372     {
7373       int i, drap;
7374       /* Can't use the same register for both PIC and DRAP.  */
7375       if (crtl->drap_reg)
7376         drap = REGNO (crtl->drap_reg);
7377       else
7378         drap = -1;
7379       for (i = 2; i >= 0; --i)
7380         if (i != drap && !df_regs_ever_live_p (i))
7381           return i;
7382     }
7383
7384   return INVALID_REGNUM;
7385 }
7386
7387 /* Return 1 if we need to save REGNO.  */
7388 static int
7389 ix86_save_reg (unsigned int regno, int maybe_eh_return)
7390 {
7391   if (pic_offset_table_rtx
7392       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
7393       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
7394           || crtl->profile
7395           || crtl->calls_eh_return
7396           || crtl->uses_const_pool))
7397     {
7398       if (ix86_select_alt_pic_regnum () != INVALID_REGNUM)
7399         return 0;
7400       return 1;
7401     }
7402
7403   if (crtl->calls_eh_return && maybe_eh_return)
7404     {
7405       unsigned i;
7406       for (i = 0; ; i++)
7407         {
7408           unsigned test = EH_RETURN_DATA_REGNO (i);
7409           if (test == INVALID_REGNUM)
7410             break;
7411           if (test == regno)
7412             return 1;
7413         }
7414     }
7415
7416   if (crtl->drap_reg
7417       && regno == REGNO (crtl->drap_reg))
7418     return 1;
7419
7420   return (df_regs_ever_live_p (regno)
7421           && !call_used_regs[regno]
7422           && !fixed_regs[regno]
7423           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
7424 }
7425
7426 /* Return number of saved general prupose registers.  */
7427
7428 static int
7429 ix86_nsaved_regs (void)
7430 {
7431   int nregs = 0;
7432   int regno;
7433
7434   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7435     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7436       nregs ++;
7437   return nregs;
7438 }
7439
7440 /* Return number of saved SSE registrers.  */
7441
7442 static int
7443 ix86_nsaved_sseregs (void)
7444 {
7445   int nregs = 0;
7446   int regno;
7447
7448   if (ix86_cfun_abi () != MS_ABI)
7449     return 0;
7450   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7451     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7452       nregs ++;
7453   return nregs;
7454 }
7455
7456 /* Given FROM and TO register numbers, say whether this elimination is
7457    allowed.  If stack alignment is needed, we can only replace argument
7458    pointer with hard frame pointer, or replace frame pointer with stack
7459    pointer.  Otherwise, frame pointer elimination is automatically
7460    handled and all other eliminations are valid.  */
7461
7462 int
7463 ix86_can_eliminate (int from, int to)
7464 {
7465   if (stack_realign_fp)
7466     return ((from == ARG_POINTER_REGNUM
7467              && to == HARD_FRAME_POINTER_REGNUM)
7468             || (from == FRAME_POINTER_REGNUM
7469                 && to == STACK_POINTER_REGNUM));
7470   else
7471     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : 1;
7472 }
7473
7474 /* Return the offset between two registers, one to be eliminated, and the other
7475    its replacement, at the start of a routine.  */
7476
7477 HOST_WIDE_INT
7478 ix86_initial_elimination_offset (int from, int to)
7479 {
7480   struct ix86_frame frame;
7481   ix86_compute_frame_layout (&frame);
7482
7483   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
7484     return frame.hard_frame_pointer_offset;
7485   else if (from == FRAME_POINTER_REGNUM
7486            && to == HARD_FRAME_POINTER_REGNUM)
7487     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
7488   else
7489     {
7490       gcc_assert (to == STACK_POINTER_REGNUM);
7491
7492       if (from == ARG_POINTER_REGNUM)
7493         return frame.stack_pointer_offset;
7494
7495       gcc_assert (from == FRAME_POINTER_REGNUM);
7496       return frame.stack_pointer_offset - frame.frame_pointer_offset;
7497     }
7498 }
7499
7500 /* Fill structure ix86_frame about frame of currently computed function.  */
7501
7502 static void
7503 ix86_compute_frame_layout (struct ix86_frame *frame)
7504 {
7505   HOST_WIDE_INT total_size;
7506   unsigned int stack_alignment_needed;
7507   HOST_WIDE_INT offset;
7508   unsigned int preferred_alignment;
7509   HOST_WIDE_INT size = get_frame_size ();
7510
7511   frame->nregs = ix86_nsaved_regs ();
7512   frame->nsseregs = ix86_nsaved_sseregs ();
7513   total_size = size;
7514
7515   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
7516   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
7517
7518   /* MS ABI seem to require stack alignment to be always 16 except for function
7519      prologues.  */
7520   if (ix86_cfun_abi () == MS_ABI && preferred_alignment < 16)
7521     {
7522       preferred_alignment = 16;
7523       stack_alignment_needed = 16;
7524       crtl->preferred_stack_boundary = 128;
7525       crtl->stack_alignment_needed = 128;
7526     }
7527
7528   gcc_assert (!size || stack_alignment_needed);
7529   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
7530   gcc_assert (preferred_alignment <= stack_alignment_needed);
7531
7532   /* During reload iteration the amount of registers saved can change.
7533      Recompute the value as needed.  Do not recompute when amount of registers
7534      didn't change as reload does multiple calls to the function and does not
7535      expect the decision to change within single iteration.  */
7536   if (!optimize_function_for_size_p (cfun)
7537       && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
7538     {
7539       int count = frame->nregs;
7540
7541       cfun->machine->use_fast_prologue_epilogue_nregs = count;
7542       /* The fast prologue uses move instead of push to save registers.  This
7543          is significantly longer, but also executes faster as modern hardware
7544          can execute the moves in parallel, but can't do that for push/pop.
7545
7546          Be careful about choosing what prologue to emit:  When function takes
7547          many instructions to execute we may use slow version as well as in
7548          case function is known to be outside hot spot (this is known with
7549          feedback only).  Weight the size of function by number of registers
7550          to save as it is cheap to use one or two push instructions but very
7551          slow to use many of them.  */
7552       if (count)
7553         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7554       if (cfun->function_frequency < FUNCTION_FREQUENCY_NORMAL
7555           || (flag_branch_probabilities
7556               && cfun->function_frequency < FUNCTION_FREQUENCY_HOT))
7557         cfun->machine->use_fast_prologue_epilogue = false;
7558       else
7559         cfun->machine->use_fast_prologue_epilogue
7560            = !expensive_function_p (count);
7561     }
7562   if (TARGET_PROLOGUE_USING_MOVE
7563       && cfun->machine->use_fast_prologue_epilogue)
7564     frame->save_regs_using_mov = true;
7565   else
7566     frame->save_regs_using_mov = false;
7567
7568
7569   /* Skip return address and saved base pointer.  */
7570   offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
7571
7572   frame->hard_frame_pointer_offset = offset;
7573
7574   /* Set offset to aligned because the realigned frame starts from
7575      here.  */
7576   if (stack_realign_fp)
7577     offset = (offset + stack_alignment_needed -1) & -stack_alignment_needed;
7578
7579   /* Register save area */
7580   offset += frame->nregs * UNITS_PER_WORD;
7581
7582   /* Align SSE reg save area.  */
7583   if (frame->nsseregs)
7584     frame->padding0 = ((offset + 16 - 1) & -16) - offset;
7585   else
7586     frame->padding0 = 0;
7587   
7588   /* SSE register save area.  */
7589   offset += frame->padding0 + frame->nsseregs * 16;
7590
7591   /* Va-arg area */
7592   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
7593   offset += frame->va_arg_size;
7594
7595   /* Align start of frame for local function.  */
7596   frame->padding1 = ((offset + stack_alignment_needed - 1)
7597                      & -stack_alignment_needed) - offset;
7598
7599   offset += frame->padding1;
7600
7601   /* Frame pointer points here.  */
7602   frame->frame_pointer_offset = offset;
7603
7604   offset += size;
7605
7606   /* Add outgoing arguments area.  Can be skipped if we eliminated
7607      all the function calls as dead code.
7608      Skipping is however impossible when function calls alloca.  Alloca
7609      expander assumes that last crtl->outgoing_args_size
7610      of stack frame are unused.  */
7611   if (ACCUMULATE_OUTGOING_ARGS
7612       && (!current_function_is_leaf || cfun->calls_alloca
7613           || ix86_current_function_calls_tls_descriptor))
7614     {
7615       offset += crtl->outgoing_args_size;
7616       frame->outgoing_arguments_size = crtl->outgoing_args_size;
7617     }
7618   else
7619     frame->outgoing_arguments_size = 0;
7620
7621   /* Align stack boundary.  Only needed if we're calling another function
7622      or using alloca.  */
7623   if (!current_function_is_leaf || cfun->calls_alloca
7624       || ix86_current_function_calls_tls_descriptor)
7625     frame->padding2 = ((offset + preferred_alignment - 1)
7626                        & -preferred_alignment) - offset;
7627   else
7628     frame->padding2 = 0;
7629
7630   offset += frame->padding2;
7631
7632   /* We've reached end of stack frame.  */
7633   frame->stack_pointer_offset = offset;
7634
7635   /* Size prologue needs to allocate.  */
7636   frame->to_allocate =
7637     (size + frame->padding1 + frame->padding2
7638      + frame->outgoing_arguments_size + frame->va_arg_size);
7639
7640   if ((!frame->to_allocate && frame->nregs <= 1)
7641       || (TARGET_64BIT && frame->to_allocate >= (HOST_WIDE_INT) 0x80000000))
7642     frame->save_regs_using_mov = false;
7643
7644   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && current_function_sp_is_unchanging
7645       && current_function_is_leaf
7646       && !ix86_current_function_calls_tls_descriptor)
7647     {
7648       frame->red_zone_size = frame->to_allocate;
7649       if (frame->save_regs_using_mov)
7650         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7651       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7652         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
7653     }
7654   else
7655     frame->red_zone_size = 0;
7656   frame->to_allocate -= frame->red_zone_size;
7657   frame->stack_pointer_offset -= frame->red_zone_size;
7658 #if 0
7659   fprintf (stderr, "\n");
7660   fprintf (stderr, "size: %ld\n", (long)size);
7661   fprintf (stderr, "nregs: %ld\n", (long)frame->nregs);
7662   fprintf (stderr, "nsseregs: %ld\n", (long)frame->nsseregs);
7663   fprintf (stderr, "padding0: %ld\n", (long)frame->padding0);
7664   fprintf (stderr, "alignment1: %ld\n", (long)stack_alignment_needed);
7665   fprintf (stderr, "padding1: %ld\n", (long)frame->padding1);
7666   fprintf (stderr, "va_arg: %ld\n", (long)frame->va_arg_size);
7667   fprintf (stderr, "padding2: %ld\n", (long)frame->padding2);
7668   fprintf (stderr, "to_allocate: %ld\n", (long)frame->to_allocate);
7669   fprintf (stderr, "red_zone_size: %ld\n", (long)frame->red_zone_size);
7670   fprintf (stderr, "frame_pointer_offset: %ld\n", (long)frame->frame_pointer_offset);
7671   fprintf (stderr, "hard_frame_pointer_offset: %ld\n",
7672            (long)frame->hard_frame_pointer_offset);
7673   fprintf (stderr, "stack_pointer_offset: %ld\n", (long)frame->stack_pointer_offset);
7674   fprintf (stderr, "current_function_is_leaf: %ld\n", (long)current_function_is_leaf);
7675   fprintf (stderr, "cfun->calls_alloca: %ld\n", (long)cfun->calls_alloca);
7676   fprintf (stderr, "x86_current_function_calls_tls_descriptor: %ld\n", (long)ix86_current_function_calls_tls_descriptor);
7677 #endif
7678 }
7679
7680 /* Emit code to save registers in the prologue.  */
7681
7682 static void
7683 ix86_emit_save_regs (void)
7684 {
7685   unsigned int regno;
7686   rtx insn;
7687
7688   for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
7689     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7690       {
7691         insn = emit_insn (gen_push (gen_rtx_REG (Pmode, regno)));
7692         RTX_FRAME_RELATED_P (insn) = 1;
7693       }
7694 }
7695
7696 /* Emit code to save registers using MOV insns.  First register
7697    is restored from POINTER + OFFSET.  */
7698 static void
7699 ix86_emit_save_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7700 {
7701   unsigned int regno;
7702   rtx insn;
7703
7704   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7705     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7706       {
7707         insn = emit_move_insn (adjust_address (gen_rtx_MEM (Pmode, pointer),
7708                                                Pmode, offset),
7709                                gen_rtx_REG (Pmode, regno));
7710         RTX_FRAME_RELATED_P (insn) = 1;
7711         offset += UNITS_PER_WORD;
7712       }
7713 }
7714
7715 /* Emit code to save registers using MOV insns.  First register
7716    is restored from POINTER + OFFSET.  */
7717 static void
7718 ix86_emit_save_sse_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7719 {
7720   unsigned int regno;
7721   rtx insn;
7722   rtx mem;
7723
7724   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7725     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7726       {
7727         mem = adjust_address (gen_rtx_MEM (TImode, pointer), TImode, offset);
7728         set_mem_align (mem, 128);
7729         insn = emit_move_insn (mem, gen_rtx_REG (TImode, regno));
7730         RTX_FRAME_RELATED_P (insn) = 1;
7731         offset += 16;
7732       }
7733 }
7734
7735 /* Expand prologue or epilogue stack adjustment.
7736    The pattern exist to put a dependency on all ebp-based memory accesses.
7737    STYLE should be negative if instructions should be marked as frame related,
7738    zero if %r11 register is live and cannot be freely used and positive
7739    otherwise.  */
7740
7741 static void
7742 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset, int style)
7743 {
7744   rtx insn;
7745
7746   if (! TARGET_64BIT)
7747     insn = emit_insn (gen_pro_epilogue_adjust_stack_1 (dest, src, offset));
7748   else if (x86_64_immediate_operand (offset, DImode))
7749     insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64 (dest, src, offset));
7750   else
7751     {
7752       rtx r11;
7753       /* r11 is used by indirect sibcall return as well, set before the
7754          epilogue and used after the epilogue.  ATM indirect sibcall
7755          shouldn't be used together with huge frame sizes in one
7756          function because of the frame_size check in sibcall.c.  */
7757       gcc_assert (style);
7758       r11 = gen_rtx_REG (DImode, R11_REG);
7759       insn = emit_insn (gen_rtx_SET (DImode, r11, offset));
7760       if (style < 0)
7761         RTX_FRAME_RELATED_P (insn) = 1;
7762       insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64_2 (dest, src, r11,
7763                                                                offset));
7764     }
7765   if (style < 0)
7766     RTX_FRAME_RELATED_P (insn) = 1;
7767 }
7768
7769 /* Find an available register to be used as dynamic realign argument
7770    pointer regsiter.  Such a register will be written in prologue and
7771    used in begin of body, so it must not be
7772         1. parameter passing register.
7773         2. GOT pointer.
7774    We reuse static-chain register if it is available.  Otherwise, we
7775    use DI for i386 and R13 for x86-64.  We chose R13 since it has
7776    shorter encoding.
7777
7778    Return: the regno of chosen register.  */
7779
7780 static unsigned int 
7781 find_drap_reg (void)
7782 {
7783   tree decl = cfun->decl;
7784
7785   if (TARGET_64BIT)
7786     {
7787       /* Use R13 for nested function or function need static chain.
7788          Since function with tail call may use any caller-saved
7789          registers in epilogue, DRAP must not use caller-saved
7790          register in such case.  */
7791       if ((decl_function_context (decl)
7792            && !DECL_NO_STATIC_CHAIN (decl))
7793           || crtl->tail_call_emit)
7794         return R13_REG;
7795
7796       return R10_REG;
7797     }
7798   else
7799     {
7800       /* Use DI for nested function or function need static chain.
7801          Since function with tail call may use any caller-saved
7802          registers in epilogue, DRAP must not use caller-saved
7803          register in such case.  */
7804       if ((decl_function_context (decl)
7805            && !DECL_NO_STATIC_CHAIN (decl))
7806           || crtl->tail_call_emit)
7807         return DI_REG;
7808     
7809       /* Reuse static chain register if it isn't used for parameter
7810          passing.  */
7811       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2
7812           && !lookup_attribute ("fastcall",
7813                                 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
7814         return CX_REG;
7815       else
7816         return DI_REG;
7817     }
7818 }
7819
7820 /* Update incoming stack boundary and estimated stack alignment.  */
7821
7822 static void
7823 ix86_update_stack_boundary (void)
7824 {
7825   /* Prefer the one specified at command line. */
7826   ix86_incoming_stack_boundary 
7827     = (ix86_user_incoming_stack_boundary
7828        ? ix86_user_incoming_stack_boundary
7829        : ix86_default_incoming_stack_boundary);
7830
7831   /* Incoming stack alignment can be changed on individual functions
7832      via force_align_arg_pointer attribute.  We use the smallest
7833      incoming stack boundary.  */
7834   if (ix86_incoming_stack_boundary > MIN_STACK_BOUNDARY
7835       && lookup_attribute (ix86_force_align_arg_pointer_string,
7836                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
7837     ix86_incoming_stack_boundary = MIN_STACK_BOUNDARY;
7838
7839   /* The incoming stack frame has to be aligned at least at
7840      parm_stack_boundary.  */
7841   if (ix86_incoming_stack_boundary < crtl->parm_stack_boundary)
7842     ix86_incoming_stack_boundary = crtl->parm_stack_boundary;
7843
7844   /* Stack at entrance of main is aligned by runtime.  We use the
7845      smallest incoming stack boundary. */
7846   if (ix86_incoming_stack_boundary > MAIN_STACK_BOUNDARY
7847       && DECL_NAME (current_function_decl)
7848       && MAIN_NAME_P (DECL_NAME (current_function_decl))
7849       && DECL_FILE_SCOPE_P (current_function_decl))
7850     ix86_incoming_stack_boundary = MAIN_STACK_BOUNDARY;
7851
7852   /* x86_64 vararg needs 16byte stack alignment for register save
7853      area.  */
7854   if (TARGET_64BIT
7855       && cfun->stdarg
7856       && crtl->stack_alignment_estimated < 128)
7857     crtl->stack_alignment_estimated = 128;
7858 }
7859
7860 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
7861    needed or an rtx for DRAP otherwise.  */
7862
7863 static rtx
7864 ix86_get_drap_rtx (void)
7865 {
7866   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
7867     crtl->need_drap = true;
7868
7869   if (stack_realign_drap)
7870     {
7871       /* Assign DRAP to vDRAP and returns vDRAP */
7872       unsigned int regno = find_drap_reg ();
7873       rtx drap_vreg;
7874       rtx arg_ptr;
7875       rtx seq, insn;
7876
7877       arg_ptr = gen_rtx_REG (Pmode, regno);
7878       crtl->drap_reg = arg_ptr;
7879
7880       start_sequence ();
7881       drap_vreg = copy_to_reg (arg_ptr);
7882       seq = get_insns ();
7883       end_sequence ();
7884       
7885       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
7886       RTX_FRAME_RELATED_P (insn) = 1;
7887       return drap_vreg;
7888     }
7889   else
7890     return NULL;
7891 }
7892
7893 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
7894
7895 static rtx
7896 ix86_internal_arg_pointer (void)
7897 {
7898   return virtual_incoming_args_rtx;
7899 }
7900
7901 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
7902    This is called from dwarf2out.c to emit call frame instructions
7903    for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
7904 static void
7905 ix86_dwarf_handle_frame_unspec (const char *label, rtx pattern, int index)
7906 {
7907   rtx unspec = SET_SRC (pattern);
7908   gcc_assert (GET_CODE (unspec) == UNSPEC);
7909
7910   switch (index)
7911     {
7912     case UNSPEC_REG_SAVE:
7913       dwarf2out_reg_save_reg (label, XVECEXP (unspec, 0, 0),
7914                               SET_DEST (pattern));
7915       break;
7916     case UNSPEC_DEF_CFA:
7917       dwarf2out_def_cfa (label, REGNO (SET_DEST (pattern)),
7918                          INTVAL (XVECEXP (unspec, 0, 0)));
7919       break;
7920     default:
7921       gcc_unreachable ();
7922     }
7923 }
7924
7925 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
7926    to be generated in correct form.  */
7927 static void 
7928 ix86_finalize_stack_realign_flags (void)
7929 {
7930   /* Check if stack realign is really needed after reload, and 
7931      stores result in cfun */
7932   unsigned int incoming_stack_boundary
7933     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
7934        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
7935   unsigned int stack_realign = (incoming_stack_boundary
7936                                 < (current_function_is_leaf
7937                                    ? crtl->max_used_stack_slot_alignment
7938                                    : crtl->stack_alignment_needed));
7939
7940   if (crtl->stack_realign_finalized)
7941     {
7942       /* After stack_realign_needed is finalized, we can't no longer
7943          change it.  */
7944       gcc_assert (crtl->stack_realign_needed == stack_realign);
7945     }
7946   else
7947     {
7948       crtl->stack_realign_needed = stack_realign;
7949       crtl->stack_realign_finalized = true;
7950     }
7951 }
7952
7953 /* Expand the prologue into a bunch of separate insns.  */
7954
7955 void
7956 ix86_expand_prologue (void)
7957 {
7958   rtx insn;
7959   bool pic_reg_used;
7960   struct ix86_frame frame;
7961   HOST_WIDE_INT allocate;
7962
7963   ix86_finalize_stack_realign_flags ();
7964
7965   /* DRAP should not coexist with stack_realign_fp */
7966   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
7967
7968   ix86_compute_frame_layout (&frame);
7969
7970   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
7971      of DRAP is needed and stack realignment is really needed after reload */
7972   if (crtl->drap_reg && crtl->stack_realign_needed)
7973     {
7974       rtx x, y;
7975       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
7976       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
7977                               ? 0 : UNITS_PER_WORD);
7978
7979       gcc_assert (stack_realign_drap);
7980
7981       /* Grab the argument pointer.  */
7982       x = plus_constant (stack_pointer_rtx, 
7983                          (UNITS_PER_WORD + param_ptr_offset));
7984       y = crtl->drap_reg;
7985
7986       /* Only need to push parameter pointer reg if it is caller
7987          saved reg */
7988       if (!call_used_regs[REGNO (crtl->drap_reg)])
7989         {
7990           /* Push arg pointer reg */
7991           insn = emit_insn (gen_push (y));
7992           RTX_FRAME_RELATED_P (insn) = 1;
7993         }
7994
7995       insn = emit_insn (gen_rtx_SET (VOIDmode, y, x));
7996       RTX_FRAME_RELATED_P (insn) = 1; 
7997
7998       /* Align the stack.  */
7999       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
8000                                            stack_pointer_rtx,
8001                                            GEN_INT (-align_bytes)));
8002       RTX_FRAME_RELATED_P (insn) = 1;
8003
8004       /* Replicate the return address on the stack so that return
8005          address can be reached via (argp - 1) slot.  This is needed
8006          to implement macro RETURN_ADDR_RTX and intrinsic function
8007          expand_builtin_return_addr etc.  */
8008       x = crtl->drap_reg;
8009       x = gen_frame_mem (Pmode,
8010                          plus_constant (x, -UNITS_PER_WORD));
8011       insn = emit_insn (gen_push (x));
8012       RTX_FRAME_RELATED_P (insn) = 1;
8013     }
8014
8015   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
8016      slower on all targets.  Also sdb doesn't like it.  */
8017
8018   if (frame_pointer_needed)
8019     {
8020       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
8021       RTX_FRAME_RELATED_P (insn) = 1;
8022
8023       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
8024       RTX_FRAME_RELATED_P (insn) = 1;
8025     }
8026
8027   if (stack_realign_fp)
8028     {
8029       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
8030       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
8031
8032       /* Align the stack.  */
8033       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
8034                                            stack_pointer_rtx,
8035                                            GEN_INT (-align_bytes)));
8036       RTX_FRAME_RELATED_P (insn) = 1;
8037     }
8038
8039   allocate = frame.to_allocate + frame.nsseregs * 16 + frame.padding0;
8040
8041   if (!frame.save_regs_using_mov)
8042     ix86_emit_save_regs ();
8043   else
8044     allocate += frame.nregs * UNITS_PER_WORD;
8045
8046   /* When using red zone we may start register saving before allocating
8047      the stack frame saving one cycle of the prologue. However I will
8048      avoid doing this if I am going to have to probe the stack since
8049      at least on x86_64 the stack probe can turn into a call that clobbers
8050      a red zone location */
8051   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && frame.save_regs_using_mov
8052       && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT))
8053     ix86_emit_save_regs_using_mov ((frame_pointer_needed
8054                                      && !crtl->stack_realign_needed) 
8055                                    ? hard_frame_pointer_rtx
8056                                    : stack_pointer_rtx,
8057                                    -frame.nregs * UNITS_PER_WORD);
8058
8059   if (allocate == 0)
8060     ;
8061   else if (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)
8062     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8063                                GEN_INT (-allocate), -1);
8064   else
8065     {
8066       /* Only valid for Win32.  */
8067       rtx eax = gen_rtx_REG (Pmode, AX_REG);
8068       bool eax_live;
8069       rtx t;
8070
8071       gcc_assert (!TARGET_64BIT || cfun->machine->call_abi == MS_ABI);
8072
8073       if (cfun->machine->call_abi == MS_ABI)
8074         eax_live = false;
8075       else
8076         eax_live = ix86_eax_live_at_start_p ();
8077
8078       if (eax_live)
8079         {
8080           emit_insn (gen_push (eax));
8081           allocate -= UNITS_PER_WORD;
8082         }
8083
8084       emit_move_insn (eax, GEN_INT (allocate));
8085
8086       if (TARGET_64BIT)
8087         insn = gen_allocate_stack_worker_64 (eax, eax);
8088       else
8089         insn = gen_allocate_stack_worker_32 (eax, eax);
8090       insn = emit_insn (insn);
8091       RTX_FRAME_RELATED_P (insn) = 1;
8092       t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (-allocate));
8093       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
8094       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
8095                                             t, REG_NOTES (insn));
8096
8097       if (eax_live)
8098         {
8099           if (frame_pointer_needed)
8100             t = plus_constant (hard_frame_pointer_rtx,
8101                                allocate
8102                                - frame.to_allocate
8103                                - frame.nregs * UNITS_PER_WORD);
8104           else
8105             t = plus_constant (stack_pointer_rtx, allocate);
8106           emit_move_insn (eax, gen_rtx_MEM (Pmode, t));
8107         }
8108     }
8109
8110   if (frame.save_regs_using_mov
8111       && !(!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
8112          && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)))
8113     {
8114       if (!frame_pointer_needed
8115           || !frame.to_allocate
8116           || crtl->stack_realign_needed)
8117         ix86_emit_save_regs_using_mov (stack_pointer_rtx,
8118                                        frame.to_allocate
8119                                        + frame.nsseregs * 16 + frame.padding0);
8120       else
8121         ix86_emit_save_regs_using_mov (hard_frame_pointer_rtx,
8122                                        -frame.nregs * UNITS_PER_WORD);
8123     }
8124   if (!frame_pointer_needed
8125       || !frame.to_allocate
8126       || crtl->stack_realign_needed)
8127     ix86_emit_save_sse_regs_using_mov (stack_pointer_rtx,
8128                                        frame.to_allocate);
8129   else
8130     ix86_emit_save_sse_regs_using_mov (hard_frame_pointer_rtx,
8131                                        - frame.nregs * UNITS_PER_WORD
8132                                        - frame.nsseregs * 16
8133                                        - frame.padding0);
8134
8135   pic_reg_used = false;
8136   if (pic_offset_table_rtx
8137       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
8138           || crtl->profile))
8139     {
8140       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
8141
8142       if (alt_pic_reg_used != INVALID_REGNUM)
8143         SET_REGNO (pic_offset_table_rtx, alt_pic_reg_used);
8144
8145       pic_reg_used = true;
8146     }
8147
8148   if (pic_reg_used)
8149     {
8150       if (TARGET_64BIT)
8151         {
8152           if (ix86_cmodel == CM_LARGE_PIC)
8153             {
8154               rtx tmp_reg = gen_rtx_REG (DImode, R11_REG);
8155               rtx label = gen_label_rtx ();
8156               emit_label (label);
8157               LABEL_PRESERVE_P (label) = 1;
8158               gcc_assert (REGNO (pic_offset_table_rtx) != REGNO (tmp_reg));
8159               insn = emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, label));
8160               insn = emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
8161               insn = emit_insn (gen_adddi3 (pic_offset_table_rtx,
8162                                             pic_offset_table_rtx, tmp_reg));
8163             }
8164           else
8165             insn = emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
8166         }
8167       else
8168         insn = emit_insn (gen_set_got (pic_offset_table_rtx));
8169     }
8170
8171   /* Prevent function calls from being scheduled before the call to mcount.
8172      In the pic_reg_used case, make sure that the got load isn't deleted.  */
8173   if (crtl->profile)
8174     {
8175       if (pic_reg_used)
8176         emit_insn (gen_prologue_use (pic_offset_table_rtx));
8177       emit_insn (gen_blockage ());
8178     }
8179
8180   if (crtl->drap_reg && !crtl->stack_realign_needed)
8181     {
8182       /* vDRAP is setup but after reload it turns out stack realign
8183          isn't necessary, here we will emit prologue to setup DRAP
8184          without stack realign adjustment */
8185       int drap_bp_offset = UNITS_PER_WORD * 2;
8186       rtx x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
8187       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, x));
8188     }
8189
8190   /* Emit cld instruction if stringops are used in the function.  */
8191   if (TARGET_CLD && ix86_current_function_needs_cld)
8192     emit_insn (gen_cld ());
8193 }
8194
8195 /* Emit code to restore saved registers using MOV insns.  First register
8196    is restored from POINTER + OFFSET.  */
8197 static void
8198 ix86_emit_restore_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8199                                   int maybe_eh_return)
8200 {
8201   int regno;
8202   rtx base_address = gen_rtx_MEM (Pmode, pointer);
8203
8204   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8205     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
8206       {
8207         /* Ensure that adjust_address won't be forced to produce pointer
8208            out of range allowed by x86-64 instruction set.  */
8209         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8210           {
8211             rtx r11;
8212
8213             r11 = gen_rtx_REG (DImode, R11_REG);
8214             emit_move_insn (r11, GEN_INT (offset));
8215             emit_insn (gen_adddi3 (r11, r11, pointer));
8216             base_address = gen_rtx_MEM (Pmode, r11);
8217             offset = 0;
8218           }
8219         emit_move_insn (gen_rtx_REG (Pmode, regno),
8220                         adjust_address (base_address, Pmode, offset));
8221         offset += UNITS_PER_WORD;
8222       }
8223 }
8224
8225 /* Emit code to restore saved registers using MOV insns.  First register
8226    is restored from POINTER + OFFSET.  */
8227 static void
8228 ix86_emit_restore_sse_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8229                                       int maybe_eh_return)
8230 {
8231   int regno;
8232   rtx base_address = gen_rtx_MEM (TImode, pointer);
8233   rtx mem;
8234
8235   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8236     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
8237       {
8238         /* Ensure that adjust_address won't be forced to produce pointer
8239            out of range allowed by x86-64 instruction set.  */
8240         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8241           {
8242             rtx r11;
8243
8244             r11 = gen_rtx_REG (DImode, R11_REG);
8245             emit_move_insn (r11, GEN_INT (offset));
8246             emit_insn (gen_adddi3 (r11, r11, pointer));
8247             base_address = gen_rtx_MEM (TImode, r11);
8248             offset = 0;
8249           }
8250         mem = adjust_address (base_address, TImode, offset);
8251         set_mem_align (mem, 128);
8252         emit_move_insn (gen_rtx_REG (TImode, regno), mem);
8253         offset += 16;
8254       }
8255 }
8256
8257 /* Restore function stack, frame, and registers.  */
8258
8259 void
8260 ix86_expand_epilogue (int style)
8261 {
8262   int regno;
8263   int sp_valid;
8264   struct ix86_frame frame;
8265   HOST_WIDE_INT offset;
8266
8267   ix86_finalize_stack_realign_flags ();
8268
8269  /* When stack is realigned, SP must be valid.  */
8270   sp_valid = (!frame_pointer_needed
8271               || current_function_sp_is_unchanging
8272               || stack_realign_fp);
8273
8274   ix86_compute_frame_layout (&frame);
8275
8276   /* Calculate start of saved registers relative to ebp.  Special care
8277      must be taken for the normal return case of a function using
8278      eh_return: the eax and edx registers are marked as saved, but not
8279      restored along this path.  */
8280   offset = frame.nregs;
8281   if (crtl->calls_eh_return && style != 2)
8282     offset -= 2;
8283   offset *= -UNITS_PER_WORD;
8284   offset -= frame.nsseregs * 16 + frame.padding0;
8285
8286   /* If we're only restoring one register and sp is not valid then
8287      using a move instruction to restore the register since it's
8288      less work than reloading sp and popping the register.
8289
8290      The default code result in stack adjustment using add/lea instruction,
8291      while this code results in LEAVE instruction (or discrete equivalent),
8292      so it is profitable in some other cases as well.  Especially when there
8293      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
8294      and there is exactly one register to pop. This heuristic may need some
8295      tuning in future.  */
8296   if ((!sp_valid && frame.nregs <= 1)
8297       || (TARGET_EPILOGUE_USING_MOVE
8298           && cfun->machine->use_fast_prologue_epilogue
8299           && (frame.nregs > 1 || frame.to_allocate))
8300       || (frame_pointer_needed && !frame.nregs && frame.to_allocate)
8301       || (frame_pointer_needed && TARGET_USE_LEAVE
8302           && cfun->machine->use_fast_prologue_epilogue
8303           && frame.nregs == 1)
8304       || crtl->calls_eh_return)
8305     {
8306       /* Restore registers.  We can use ebp or esp to address the memory
8307          locations.  If both are available, default to ebp, since offsets
8308          are known to be small.  Only exception is esp pointing directly
8309          to the end of block of saved registers, where we may simplify
8310          addressing mode.  
8311
8312          If we are realigning stack with bp and sp, regs restore can't
8313          be addressed by bp. sp must be used instead.  */
8314
8315       if (!frame_pointer_needed
8316           || (sp_valid && !frame.to_allocate) 
8317           || stack_realign_fp)
8318         {
8319           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8320                                                 frame.to_allocate, style == 2);
8321           ix86_emit_restore_regs_using_mov (stack_pointer_rtx,
8322                                             frame.to_allocate
8323                                             + frame.nsseregs * 16
8324                                             + frame.padding0, style == 2);
8325         }
8326       else
8327         {
8328           ix86_emit_restore_sse_regs_using_mov (hard_frame_pointer_rtx,
8329                                                 offset, style == 2);
8330           ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx,
8331                                             offset
8332                                             + frame.nsseregs * 16
8333                                             + frame.padding0, style == 2);
8334         }
8335
8336       /* eh_return epilogues need %ecx added to the stack pointer.  */
8337       if (style == 2)
8338         {
8339           rtx tmp, sa = EH_RETURN_STACKADJ_RTX;
8340
8341           /* Stack align doesn't work with eh_return.  */
8342           gcc_assert (!crtl->stack_realign_needed);
8343
8344           if (frame_pointer_needed)
8345             {
8346               tmp = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
8347               tmp = plus_constant (tmp, UNITS_PER_WORD);
8348               emit_insn (gen_rtx_SET (VOIDmode, sa, tmp));
8349
8350               tmp = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
8351               emit_move_insn (hard_frame_pointer_rtx, tmp);
8352
8353               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
8354                                          const0_rtx, style);
8355             }
8356           else
8357             {
8358               tmp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
8359               tmp = plus_constant (tmp, (frame.to_allocate
8360                                          + frame.nregs * UNITS_PER_WORD
8361                                          + frame.nsseregs * 16
8362                                          + frame.padding0));
8363               emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp));
8364             }
8365         }
8366       else if (!frame_pointer_needed)
8367         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8368                                    GEN_INT (frame.to_allocate
8369                                             + frame.nregs * UNITS_PER_WORD
8370                                             + frame.nsseregs * 16
8371                                             + frame.padding0),
8372                                    style);
8373       /* If not an i386, mov & pop is faster than "leave".  */
8374       else if (TARGET_USE_LEAVE || optimize_function_for_size_p (cfun)
8375                || !cfun->machine->use_fast_prologue_epilogue)
8376         emit_insn ((*ix86_gen_leave) ());
8377       else
8378         {
8379           pro_epilogue_adjust_stack (stack_pointer_rtx,
8380                                      hard_frame_pointer_rtx,
8381                                      const0_rtx, style);
8382
8383           emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8384         }
8385     }
8386   else
8387     {
8388       /* First step is to deallocate the stack frame so that we can
8389          pop the registers.
8390
8391          If we realign stack with frame pointer, then stack pointer
8392          won't be able to recover via lea $offset(%bp), %sp, because
8393          there is a padding area between bp and sp for realign. 
8394          "add $to_allocate, %sp" must be used instead.  */
8395       if (!sp_valid)
8396         {
8397           gcc_assert (frame_pointer_needed);
8398           gcc_assert (!stack_realign_fp);
8399           pro_epilogue_adjust_stack (stack_pointer_rtx,
8400                                      hard_frame_pointer_rtx,
8401                                      GEN_INT (offset), style);
8402           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8403                                                 frame.to_allocate, style == 2);
8404           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8405                                      GEN_INT (frame.nsseregs * 16), style);
8406         }
8407       else if (frame.to_allocate || frame.nsseregs)
8408         {
8409           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8410                                                 frame.to_allocate,
8411                                                 style == 2);
8412           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8413                                      GEN_INT (frame.to_allocate
8414                                               + frame.nsseregs * 16
8415                                               + frame.padding0), style);
8416         }
8417
8418       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8419         if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, false))
8420           emit_insn ((*ix86_gen_pop1) (gen_rtx_REG (Pmode, regno)));
8421       if (frame_pointer_needed)
8422         {
8423           /* Leave results in shorter dependency chains on CPUs that are
8424              able to grok it fast.  */
8425           if (TARGET_USE_LEAVE)
8426             emit_insn ((*ix86_gen_leave) ());
8427           else
8428             {
8429               /* For stack realigned really happens, recover stack 
8430                  pointer to hard frame pointer is a must, if not using 
8431                  leave.  */
8432               if (stack_realign_fp)
8433                 pro_epilogue_adjust_stack (stack_pointer_rtx,
8434                                            hard_frame_pointer_rtx,
8435                                            const0_rtx, style);
8436               emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8437             }
8438         }
8439     }
8440
8441   if (crtl->drap_reg && crtl->stack_realign_needed)
8442     {
8443       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8444                               ? 0 : UNITS_PER_WORD);
8445       gcc_assert (stack_realign_drap);
8446       emit_insn ((*ix86_gen_add3) (stack_pointer_rtx,
8447                                    crtl->drap_reg,
8448                                    GEN_INT (-(UNITS_PER_WORD
8449                                               + param_ptr_offset))));
8450       if (!call_used_regs[REGNO (crtl->drap_reg)])
8451         emit_insn ((*ix86_gen_pop1) (crtl->drap_reg));
8452       
8453     }
8454
8455   /* Sibcall epilogues don't want a return instruction.  */
8456   if (style == 0)
8457     return;
8458
8459   if (crtl->args.pops_args && crtl->args.size)
8460     {
8461       rtx popc = GEN_INT (crtl->args.pops_args);
8462
8463       /* i386 can only pop 64K bytes.  If asked to pop more, pop
8464          return address, do explicit add, and jump indirectly to the
8465          caller.  */
8466
8467       if (crtl->args.pops_args >= 65536)
8468         {
8469           rtx ecx = gen_rtx_REG (SImode, CX_REG);
8470
8471           /* There is no "pascal" calling convention in any 64bit ABI.  */
8472           gcc_assert (!TARGET_64BIT);
8473
8474           emit_insn (gen_popsi1 (ecx));
8475           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc));
8476           emit_jump_insn (gen_return_indirect_internal (ecx));
8477         }
8478       else
8479         emit_jump_insn (gen_return_pop_internal (popc));
8480     }
8481   else
8482     emit_jump_insn (gen_return_internal ());
8483 }
8484
8485 /* Reset from the function's potential modifications.  */
8486
8487 static void
8488 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
8489                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
8490 {
8491   if (pic_offset_table_rtx)
8492     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
8493 #if TARGET_MACHO
8494   /* Mach-O doesn't support labels at the end of objects, so if
8495      it looks like we might want one, insert a NOP.  */
8496   {
8497     rtx insn = get_last_insn ();
8498     while (insn
8499            && NOTE_P (insn)
8500            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
8501       insn = PREV_INSN (insn);
8502     if (insn
8503         && (LABEL_P (insn)
8504             || (NOTE_P (insn)
8505                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
8506       fputs ("\tnop\n", file);
8507   }
8508 #endif
8509
8510 }
8511 \f
8512 /* Extract the parts of an RTL expression that is a valid memory address
8513    for an instruction.  Return 0 if the structure of the address is
8514    grossly off.  Return -1 if the address contains ASHIFT, so it is not
8515    strictly valid, but still used for computing length of lea instruction.  */
8516
8517 int
8518 ix86_decompose_address (rtx addr, struct ix86_address *out)
8519 {
8520   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
8521   rtx base_reg, index_reg;
8522   HOST_WIDE_INT scale = 1;
8523   rtx scale_rtx = NULL_RTX;
8524   int retval = 1;
8525   enum ix86_address_seg seg = SEG_DEFAULT;
8526
8527   if (REG_P (addr) || GET_CODE (addr) == SUBREG)
8528     base = addr;
8529   else if (GET_CODE (addr) == PLUS)
8530     {
8531       rtx addends[4], op;
8532       int n = 0, i;
8533
8534       op = addr;
8535       do
8536         {
8537           if (n >= 4)
8538             return 0;
8539           addends[n++] = XEXP (op, 1);
8540           op = XEXP (op, 0);
8541         }
8542       while (GET_CODE (op) == PLUS);
8543       if (n >= 4)
8544         return 0;
8545       addends[n] = op;
8546
8547       for (i = n; i >= 0; --i)
8548         {
8549           op = addends[i];
8550           switch (GET_CODE (op))
8551             {
8552             case MULT:
8553               if (index)
8554                 return 0;
8555               index = XEXP (op, 0);
8556               scale_rtx = XEXP (op, 1);
8557               break;
8558
8559             case UNSPEC:
8560               if (XINT (op, 1) == UNSPEC_TP
8561                   && TARGET_TLS_DIRECT_SEG_REFS
8562                   && seg == SEG_DEFAULT)
8563                 seg = TARGET_64BIT ? SEG_FS : SEG_GS;
8564               else
8565                 return 0;
8566               break;
8567
8568             case REG:
8569             case SUBREG:
8570               if (!base)
8571                 base = op;
8572               else if (!index)
8573                 index = op;
8574               else
8575                 return 0;
8576               break;
8577
8578             case CONST:
8579             case CONST_INT:
8580             case SYMBOL_REF:
8581             case LABEL_REF:
8582               if (disp)
8583                 return 0;
8584               disp = op;
8585               break;
8586
8587             default:
8588               return 0;
8589             }
8590         }
8591     }
8592   else if (GET_CODE (addr) == MULT)
8593     {
8594       index = XEXP (addr, 0);           /* index*scale */
8595       scale_rtx = XEXP (addr, 1);
8596     }
8597   else if (GET_CODE (addr) == ASHIFT)
8598     {
8599       rtx tmp;
8600
8601       /* We're called for lea too, which implements ashift on occasion.  */
8602       index = XEXP (addr, 0);
8603       tmp = XEXP (addr, 1);
8604       if (!CONST_INT_P (tmp))
8605         return 0;
8606       scale = INTVAL (tmp);
8607       if ((unsigned HOST_WIDE_INT) scale > 3)
8608         return 0;
8609       scale = 1 << scale;
8610       retval = -1;
8611     }
8612   else
8613     disp = addr;                        /* displacement */
8614
8615   /* Extract the integral value of scale.  */
8616   if (scale_rtx)
8617     {
8618       if (!CONST_INT_P (scale_rtx))
8619         return 0;
8620       scale = INTVAL (scale_rtx);
8621     }
8622
8623   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
8624   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
8625
8626   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
8627   if (base_reg && index_reg && scale == 1
8628       && (index_reg == arg_pointer_rtx
8629           || index_reg == frame_pointer_rtx
8630           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
8631     {
8632       rtx tmp;
8633       tmp = base, base = index, index = tmp;
8634       tmp = base_reg, base_reg = index_reg, index_reg = tmp;
8635     }
8636
8637   /* Special case: %ebp cannot be encoded as a base without a displacement.  */
8638   if ((base_reg == hard_frame_pointer_rtx
8639        || base_reg == frame_pointer_rtx
8640        || base_reg == arg_pointer_rtx) && !disp)
8641     disp = const0_rtx;
8642
8643   /* Special case: on K6, [%esi] makes the instruction vector decoded.
8644      Avoid this by transforming to [%esi+0].
8645      Reload calls address legitimization without cfun defined, so we need
8646      to test cfun for being non-NULL. */
8647   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
8648       && base_reg && !index_reg && !disp
8649       && REG_P (base_reg)
8650       && REGNO_REG_CLASS (REGNO (base_reg)) == SIREG)
8651     disp = const0_rtx;
8652
8653   /* Special case: encode reg+reg instead of reg*2.  */
8654   if (!base && index && scale && scale == 2)
8655     base = index, base_reg = index_reg, scale = 1;
8656
8657   /* Special case: scaling cannot be encoded without base or displacement.  */
8658   if (!base && !disp && index && scale != 1)
8659     disp = const0_rtx;
8660
8661   out->base = base;
8662   out->index = index;
8663   out->disp = disp;
8664   out->scale = scale;
8665   out->seg = seg;
8666
8667   return retval;
8668 }
8669 \f
8670 /* Return cost of the memory address x.
8671    For i386, it is better to use a complex address than let gcc copy
8672    the address into a reg and make a new pseudo.  But not if the address
8673    requires to two regs - that would mean more pseudos with longer
8674    lifetimes.  */
8675 static int
8676 ix86_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
8677 {
8678   struct ix86_address parts;
8679   int cost = 1;
8680   int ok = ix86_decompose_address (x, &parts);
8681
8682   gcc_assert (ok);
8683
8684   if (parts.base && GET_CODE (parts.base) == SUBREG)
8685     parts.base = SUBREG_REG (parts.base);
8686   if (parts.index && GET_CODE (parts.index) == SUBREG)
8687     parts.index = SUBREG_REG (parts.index);
8688
8689   /* Attempt to minimize number of registers in the address.  */
8690   if ((parts.base
8691        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
8692       || (parts.index
8693           && (!REG_P (parts.index)
8694               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
8695     cost++;
8696
8697   if (parts.base
8698       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
8699       && parts.index
8700       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
8701       && parts.base != parts.index)
8702     cost++;
8703
8704   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
8705      since it's predecode logic can't detect the length of instructions
8706      and it degenerates to vector decoded.  Increase cost of such
8707      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
8708      to split such addresses or even refuse such addresses at all.
8709
8710      Following addressing modes are affected:
8711       [base+scale*index]
8712       [scale*index+disp]
8713       [base+index]
8714
8715      The first and last case  may be avoidable by explicitly coding the zero in
8716      memory address, but I don't have AMD-K6 machine handy to check this
8717      theory.  */
8718
8719   if (TARGET_K6
8720       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
8721           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
8722           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
8723     cost += 10;
8724
8725   return cost;
8726 }
8727 \f
8728 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
8729    this is used for to form addresses to local data when -fPIC is in
8730    use.  */
8731
8732 static bool
8733 darwin_local_data_pic (rtx disp)
8734 {
8735   return (GET_CODE (disp) == UNSPEC
8736           && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
8737 }
8738
8739 /* Determine if a given RTX is a valid constant.  We already know this
8740    satisfies CONSTANT_P.  */
8741
8742 bool
8743 legitimate_constant_p (rtx x)
8744 {
8745   switch (GET_CODE (x))
8746     {
8747     case CONST:
8748       x = XEXP (x, 0);
8749
8750       if (GET_CODE (x) == PLUS)
8751         {
8752           if (!CONST_INT_P (XEXP (x, 1)))
8753             return false;
8754           x = XEXP (x, 0);
8755         }
8756
8757       if (TARGET_MACHO && darwin_local_data_pic (x))
8758         return true;
8759
8760       /* Only some unspecs are valid as "constants".  */
8761       if (GET_CODE (x) == UNSPEC)
8762         switch (XINT (x, 1))
8763           {
8764           case UNSPEC_GOT:
8765           case UNSPEC_GOTOFF:
8766           case UNSPEC_PLTOFF:
8767             return TARGET_64BIT;
8768           case UNSPEC_TPOFF:
8769           case UNSPEC_NTPOFF:
8770             x = XVECEXP (x, 0, 0);
8771             return (GET_CODE (x) == SYMBOL_REF
8772                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8773           case UNSPEC_DTPOFF:
8774             x = XVECEXP (x, 0, 0);
8775             return (GET_CODE (x) == SYMBOL_REF
8776                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
8777           default:
8778             return false;
8779           }
8780
8781       /* We must have drilled down to a symbol.  */
8782       if (GET_CODE (x) == LABEL_REF)
8783         return true;
8784       if (GET_CODE (x) != SYMBOL_REF)
8785         return false;
8786       /* FALLTHRU */
8787
8788     case SYMBOL_REF:
8789       /* TLS symbols are never valid.  */
8790       if (SYMBOL_REF_TLS_MODEL (x))
8791         return false;
8792
8793       /* DLLIMPORT symbols are never valid.  */
8794       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8795           && SYMBOL_REF_DLLIMPORT_P (x))
8796         return false;
8797       break;
8798
8799     case CONST_DOUBLE:
8800       if (GET_MODE (x) == TImode
8801           && x != CONST0_RTX (TImode)
8802           && !TARGET_64BIT)
8803         return false;
8804       break;
8805
8806     case CONST_VECTOR:
8807       if (x == CONST0_RTX (GET_MODE (x)))
8808         return true;
8809       return false;
8810
8811     default:
8812       break;
8813     }
8814
8815   /* Otherwise we handle everything else in the move patterns.  */
8816   return true;
8817 }
8818
8819 /* Determine if it's legal to put X into the constant pool.  This
8820    is not possible for the address of thread-local symbols, which
8821    is checked above.  */
8822
8823 static bool
8824 ix86_cannot_force_const_mem (rtx x)
8825 {
8826   /* We can always put integral constants and vectors in memory.  */
8827   switch (GET_CODE (x))
8828     {
8829     case CONST_INT:
8830     case CONST_DOUBLE:
8831     case CONST_VECTOR:
8832       return false;
8833
8834     default:
8835       break;
8836     }
8837   return !legitimate_constant_p (x);
8838 }
8839
8840 /* Determine if a given RTX is a valid constant address.  */
8841
8842 bool
8843 constant_address_p (rtx x)
8844 {
8845   return CONSTANT_P (x) && legitimate_address_p (Pmode, x, 1);
8846 }
8847
8848 /* Nonzero if the constant value X is a legitimate general operand
8849    when generating PIC code.  It is given that flag_pic is on and
8850    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
8851
8852 bool
8853 legitimate_pic_operand_p (rtx x)
8854 {
8855   rtx inner;
8856
8857   switch (GET_CODE (x))
8858     {
8859     case CONST:
8860       inner = XEXP (x, 0);
8861       if (GET_CODE (inner) == PLUS
8862           && CONST_INT_P (XEXP (inner, 1)))
8863         inner = XEXP (inner, 0);
8864
8865       /* Only some unspecs are valid as "constants".  */
8866       if (GET_CODE (inner) == UNSPEC)
8867         switch (XINT (inner, 1))
8868           {
8869           case UNSPEC_GOT:
8870           case UNSPEC_GOTOFF:
8871           case UNSPEC_PLTOFF:
8872             return TARGET_64BIT;
8873           case UNSPEC_TPOFF:
8874             x = XVECEXP (inner, 0, 0);
8875             return (GET_CODE (x) == SYMBOL_REF
8876                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8877           case UNSPEC_MACHOPIC_OFFSET:
8878             return legitimate_pic_address_disp_p (x);
8879           default:
8880             return false;
8881           }
8882       /* FALLTHRU */
8883
8884     case SYMBOL_REF:
8885     case LABEL_REF:
8886       return legitimate_pic_address_disp_p (x);
8887
8888     default:
8889       return true;
8890     }
8891 }
8892
8893 /* Determine if a given CONST RTX is a valid memory displacement
8894    in PIC mode.  */
8895
8896 int
8897 legitimate_pic_address_disp_p (rtx disp)
8898 {
8899   bool saw_plus;
8900
8901   /* In 64bit mode we can allow direct addresses of symbols and labels
8902      when they are not dynamic symbols.  */
8903   if (TARGET_64BIT)
8904     {
8905       rtx op0 = disp, op1;
8906
8907       switch (GET_CODE (disp))
8908         {
8909         case LABEL_REF:
8910           return true;
8911
8912         case CONST:
8913           if (GET_CODE (XEXP (disp, 0)) != PLUS)
8914             break;
8915           op0 = XEXP (XEXP (disp, 0), 0);
8916           op1 = XEXP (XEXP (disp, 0), 1);
8917           if (!CONST_INT_P (op1)
8918               || INTVAL (op1) >= 16*1024*1024
8919               || INTVAL (op1) < -16*1024*1024)
8920             break;
8921           if (GET_CODE (op0) == LABEL_REF)
8922             return true;
8923           if (GET_CODE (op0) != SYMBOL_REF)
8924             break;
8925           /* FALLTHRU */
8926
8927         case SYMBOL_REF:
8928           /* TLS references should always be enclosed in UNSPEC.  */
8929           if (SYMBOL_REF_TLS_MODEL (op0))
8930             return false;
8931           if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0)
8932               && ix86_cmodel != CM_LARGE_PIC)
8933             return true;
8934           break;
8935
8936         default:
8937           break;
8938         }
8939     }
8940   if (GET_CODE (disp) != CONST)
8941     return 0;
8942   disp = XEXP (disp, 0);
8943
8944   if (TARGET_64BIT)
8945     {
8946       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
8947          of GOT tables.  We should not need these anyway.  */
8948       if (GET_CODE (disp) != UNSPEC
8949           || (XINT (disp, 1) != UNSPEC_GOTPCREL
8950               && XINT (disp, 1) != UNSPEC_GOTOFF
8951               && XINT (disp, 1) != UNSPEC_PLTOFF))
8952         return 0;
8953
8954       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
8955           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
8956         return 0;
8957       return 1;
8958     }
8959
8960   saw_plus = false;
8961   if (GET_CODE (disp) == PLUS)
8962     {
8963       if (!CONST_INT_P (XEXP (disp, 1)))
8964         return 0;
8965       disp = XEXP (disp, 0);
8966       saw_plus = true;
8967     }
8968
8969   if (TARGET_MACHO && darwin_local_data_pic (disp))
8970     return 1;
8971
8972   if (GET_CODE (disp) != UNSPEC)
8973     return 0;
8974
8975   switch (XINT (disp, 1))
8976     {
8977     case UNSPEC_GOT:
8978       if (saw_plus)
8979         return false;
8980       /* We need to check for both symbols and labels because VxWorks loads
8981          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
8982          details.  */
8983       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
8984               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
8985     case UNSPEC_GOTOFF:
8986       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
8987          While ABI specify also 32bit relocation but we don't produce it in
8988          small PIC model at all.  */
8989       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
8990            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
8991           && !TARGET_64BIT)
8992         return gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
8993       return false;
8994     case UNSPEC_GOTTPOFF:
8995     case UNSPEC_GOTNTPOFF:
8996     case UNSPEC_INDNTPOFF:
8997       if (saw_plus)
8998         return false;
8999       disp = XVECEXP (disp, 0, 0);
9000       return (GET_CODE (disp) == SYMBOL_REF
9001               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
9002     case UNSPEC_NTPOFF:
9003       disp = XVECEXP (disp, 0, 0);
9004       return (GET_CODE (disp) == SYMBOL_REF
9005               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
9006     case UNSPEC_DTPOFF:
9007       disp = XVECEXP (disp, 0, 0);
9008       return (GET_CODE (disp) == SYMBOL_REF
9009               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
9010     }
9011
9012   return 0;
9013 }
9014
9015 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid
9016    memory address for an instruction.  The MODE argument is the machine mode
9017    for the MEM expression that wants to use this address.
9018
9019    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
9020    convert common non-canonical forms to canonical form so that they will
9021    be recognized.  */
9022
9023 int
9024 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
9025                       rtx addr, int strict)
9026 {
9027   struct ix86_address parts;
9028   rtx base, index, disp;
9029   HOST_WIDE_INT scale;
9030   const char *reason = NULL;
9031   rtx reason_rtx = NULL_RTX;
9032
9033   if (ix86_decompose_address (addr, &parts) <= 0)
9034     {
9035       reason = "decomposition failed";
9036       goto report_error;
9037     }
9038
9039   base = parts.base;
9040   index = parts.index;
9041   disp = parts.disp;
9042   scale = parts.scale;
9043
9044   /* Validate base register.
9045
9046      Don't allow SUBREG's that span more than a word here.  It can lead to spill
9047      failures when the base is one word out of a two word structure, which is
9048      represented internally as a DImode int.  */
9049
9050   if (base)
9051     {
9052       rtx reg;
9053       reason_rtx = base;
9054
9055       if (REG_P (base))
9056         reg = base;
9057       else if (GET_CODE (base) == SUBREG
9058                && REG_P (SUBREG_REG (base))
9059                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (base)))
9060                   <= UNITS_PER_WORD)
9061         reg = SUBREG_REG (base);
9062       else
9063         {
9064           reason = "base is not a register";
9065           goto report_error;
9066         }
9067
9068       if (GET_MODE (base) != Pmode)
9069         {
9070           reason = "base is not in Pmode";
9071           goto report_error;
9072         }
9073
9074       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
9075           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
9076         {
9077           reason = "base is not valid";
9078           goto report_error;
9079         }
9080     }
9081
9082   /* Validate index register.
9083
9084      Don't allow SUBREG's that span more than a word here -- same as above.  */
9085
9086   if (index)
9087     {
9088       rtx reg;
9089       reason_rtx = index;
9090
9091       if (REG_P (index))
9092         reg = index;
9093       else if (GET_CODE (index) == SUBREG
9094                && REG_P (SUBREG_REG (index))
9095                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (index)))
9096                   <= UNITS_PER_WORD)
9097         reg = SUBREG_REG (index);
9098       else
9099         {
9100           reason = "index is not a register";
9101           goto report_error;
9102         }
9103
9104       if (GET_MODE (index) != Pmode)
9105         {
9106           reason = "index is not in Pmode";
9107           goto report_error;
9108         }
9109
9110       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
9111           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
9112         {
9113           reason = "index is not valid";
9114           goto report_error;
9115         }
9116     }
9117
9118   /* Validate scale factor.  */
9119   if (scale != 1)
9120     {
9121       reason_rtx = GEN_INT (scale);
9122       if (!index)
9123         {
9124           reason = "scale without index";
9125           goto report_error;
9126         }
9127
9128       if (scale != 2 && scale != 4 && scale != 8)
9129         {
9130           reason = "scale is not a valid multiplier";
9131           goto report_error;
9132         }
9133     }
9134
9135   /* Validate displacement.  */
9136   if (disp)
9137     {
9138       reason_rtx = disp;
9139
9140       if (GET_CODE (disp) == CONST
9141           && GET_CODE (XEXP (disp, 0)) == UNSPEC
9142           && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
9143         switch (XINT (XEXP (disp, 0), 1))
9144           {
9145           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
9146              used.  While ABI specify also 32bit relocations, we don't produce
9147              them at all and use IP relative instead.  */
9148           case UNSPEC_GOT:
9149           case UNSPEC_GOTOFF:
9150             gcc_assert (flag_pic);
9151             if (!TARGET_64BIT)
9152               goto is_legitimate_pic;
9153             reason = "64bit address unspec";
9154             goto report_error;
9155
9156           case UNSPEC_GOTPCREL:
9157             gcc_assert (flag_pic);
9158             goto is_legitimate_pic;
9159
9160           case UNSPEC_GOTTPOFF:
9161           case UNSPEC_GOTNTPOFF:
9162           case UNSPEC_INDNTPOFF:
9163           case UNSPEC_NTPOFF:
9164           case UNSPEC_DTPOFF:
9165             break;
9166
9167           default:
9168             reason = "invalid address unspec";
9169             goto report_error;
9170           }
9171
9172       else if (SYMBOLIC_CONST (disp)
9173                && (flag_pic
9174                    || (TARGET_MACHO
9175 #if TARGET_MACHO
9176                        && MACHOPIC_INDIRECT
9177                        && !machopic_operand_p (disp)
9178 #endif
9179                )))
9180         {
9181
9182         is_legitimate_pic:
9183           if (TARGET_64BIT && (index || base))
9184             {
9185               /* foo@dtpoff(%rX) is ok.  */
9186               if (GET_CODE (disp) != CONST
9187                   || GET_CODE (XEXP (disp, 0)) != PLUS
9188                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
9189                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
9190                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
9191                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
9192                 {
9193                   reason = "non-constant pic memory reference";
9194                   goto report_error;
9195                 }
9196             }
9197           else if (! legitimate_pic_address_disp_p (disp))
9198             {
9199               reason = "displacement is an invalid pic construct";
9200               goto report_error;
9201             }
9202
9203           /* This code used to verify that a symbolic pic displacement
9204              includes the pic_offset_table_rtx register.
9205
9206              While this is good idea, unfortunately these constructs may
9207              be created by "adds using lea" optimization for incorrect
9208              code like:
9209
9210              int a;
9211              int foo(int i)
9212                {
9213                  return *(&a+i);
9214                }
9215
9216              This code is nonsensical, but results in addressing
9217              GOT table with pic_offset_table_rtx base.  We can't
9218              just refuse it easily, since it gets matched by
9219              "addsi3" pattern, that later gets split to lea in the
9220              case output register differs from input.  While this
9221              can be handled by separate addsi pattern for this case
9222              that never results in lea, this seems to be easier and
9223              correct fix for crash to disable this test.  */
9224         }
9225       else if (GET_CODE (disp) != LABEL_REF
9226                && !CONST_INT_P (disp)
9227                && (GET_CODE (disp) != CONST
9228                    || !legitimate_constant_p (disp))
9229                && (GET_CODE (disp) != SYMBOL_REF
9230                    || !legitimate_constant_p (disp)))
9231         {
9232           reason = "displacement is not constant";
9233           goto report_error;
9234         }
9235       else if (TARGET_64BIT
9236                && !x86_64_immediate_operand (disp, VOIDmode))
9237         {
9238           reason = "displacement is out of range";
9239           goto report_error;
9240         }
9241     }
9242
9243   /* Everything looks valid.  */
9244   return TRUE;
9245
9246  report_error:
9247   return FALSE;
9248 }
9249 \f
9250 /* Return a unique alias set for the GOT.  */
9251
9252 static alias_set_type
9253 ix86_GOT_alias_set (void)
9254 {
9255   static alias_set_type set = -1;
9256   if (set == -1)
9257     set = new_alias_set ();
9258   return set;
9259 }
9260
9261 /* Return a legitimate reference for ORIG (an address) using the
9262    register REG.  If REG is 0, a new pseudo is generated.
9263
9264    There are two types of references that must be handled:
9265
9266    1. Global data references must load the address from the GOT, via
9267       the PIC reg.  An insn is emitted to do this load, and the reg is
9268       returned.
9269
9270    2. Static data references, constant pool addresses, and code labels
9271       compute the address as an offset from the GOT, whose base is in
9272       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
9273       differentiate them from global data objects.  The returned
9274       address is the PIC reg + an unspec constant.
9275
9276    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
9277    reg also appears in the address.  */
9278
9279 static rtx
9280 legitimize_pic_address (rtx orig, rtx reg)
9281 {
9282   rtx addr = orig;
9283   rtx new_rtx = orig;
9284   rtx base;
9285
9286 #if TARGET_MACHO
9287   if (TARGET_MACHO && !TARGET_64BIT)
9288     {
9289       if (reg == 0)
9290         reg = gen_reg_rtx (Pmode);
9291       /* Use the generic Mach-O PIC machinery.  */
9292       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
9293     }
9294 #endif
9295
9296   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
9297     new_rtx = addr;
9298   else if (TARGET_64BIT
9299            && ix86_cmodel != CM_SMALL_PIC
9300            && gotoff_operand (addr, Pmode))
9301     {
9302       rtx tmpreg;
9303       /* This symbol may be referenced via a displacement from the PIC
9304          base address (@GOTOFF).  */
9305
9306       if (reload_in_progress)
9307         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9308       if (GET_CODE (addr) == CONST)
9309         addr = XEXP (addr, 0);
9310       if (GET_CODE (addr) == PLUS)
9311           {
9312             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9313                                       UNSPEC_GOTOFF);
9314             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9315           }
9316         else
9317           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9318       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9319       if (!reg)
9320         tmpreg = gen_reg_rtx (Pmode);
9321       else
9322         tmpreg = reg;
9323       emit_move_insn (tmpreg, new_rtx);
9324
9325       if (reg != 0)
9326         {
9327           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
9328                                          tmpreg, 1, OPTAB_DIRECT);
9329           new_rtx = reg;
9330         }
9331       else new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
9332     }
9333   else if (!TARGET_64BIT && gotoff_operand (addr, Pmode))
9334     {
9335       /* This symbol may be referenced via a displacement from the PIC
9336          base address (@GOTOFF).  */
9337
9338       if (reload_in_progress)
9339         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9340       if (GET_CODE (addr) == CONST)
9341         addr = XEXP (addr, 0);
9342       if (GET_CODE (addr) == PLUS)
9343           {
9344             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9345                                       UNSPEC_GOTOFF);
9346             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9347           }
9348         else
9349           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9350       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9351       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9352
9353       if (reg != 0)
9354         {
9355           emit_move_insn (reg, new_rtx);
9356           new_rtx = reg;
9357         }
9358     }
9359   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
9360            /* We can't use @GOTOFF for text labels on VxWorks;
9361               see gotoff_operand.  */
9362            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
9363     {
9364       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9365         {
9366           if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
9367             return legitimize_dllimport_symbol (addr, true);
9368           if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
9369               && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
9370               && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
9371             {
9372               rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), true);
9373               return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
9374             }
9375         }
9376
9377       if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
9378         {
9379           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
9380           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9381           new_rtx = gen_const_mem (Pmode, new_rtx);
9382           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9383
9384           if (reg == 0)
9385             reg = gen_reg_rtx (Pmode);
9386           /* Use directly gen_movsi, otherwise the address is loaded
9387              into register for CSE.  We don't want to CSE this addresses,
9388              instead we CSE addresses from the GOT table, so skip this.  */
9389           emit_insn (gen_movsi (reg, new_rtx));
9390           new_rtx = reg;
9391         }
9392       else
9393         {
9394           /* This symbol must be referenced via a load from the
9395              Global Offset Table (@GOT).  */
9396
9397           if (reload_in_progress)
9398             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9399           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
9400           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9401           if (TARGET_64BIT)
9402             new_rtx = force_reg (Pmode, new_rtx);
9403           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9404           new_rtx = gen_const_mem (Pmode, new_rtx);
9405           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9406
9407           if (reg == 0)
9408             reg = gen_reg_rtx (Pmode);
9409           emit_move_insn (reg, new_rtx);
9410           new_rtx = reg;
9411         }
9412     }
9413   else
9414     {
9415       if (CONST_INT_P (addr)
9416           && !x86_64_immediate_operand (addr, VOIDmode))
9417         {
9418           if (reg)
9419             {
9420               emit_move_insn (reg, addr);
9421               new_rtx = reg;
9422             }
9423           else
9424             new_rtx = force_reg (Pmode, addr);
9425         }
9426       else if (GET_CODE (addr) == CONST)
9427         {
9428           addr = XEXP (addr, 0);
9429
9430           /* We must match stuff we generate before.  Assume the only
9431              unspecs that can get here are ours.  Not that we could do
9432              anything with them anyway....  */
9433           if (GET_CODE (addr) == UNSPEC
9434               || (GET_CODE (addr) == PLUS
9435                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
9436             return orig;
9437           gcc_assert (GET_CODE (addr) == PLUS);
9438         }
9439       if (GET_CODE (addr) == PLUS)
9440         {
9441           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
9442
9443           /* Check first to see if this is a constant offset from a @GOTOFF
9444              symbol reference.  */
9445           if (gotoff_operand (op0, Pmode)
9446               && CONST_INT_P (op1))
9447             {
9448               if (!TARGET_64BIT)
9449                 {
9450                   if (reload_in_progress)
9451                     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9452                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
9453                                             UNSPEC_GOTOFF);
9454                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
9455                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9456                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9457
9458                   if (reg != 0)
9459                     {
9460                       emit_move_insn (reg, new_rtx);
9461                       new_rtx = reg;
9462                     }
9463                 }
9464               else
9465                 {
9466                   if (INTVAL (op1) < -16*1024*1024
9467                       || INTVAL (op1) >= 16*1024*1024)
9468                     {
9469                       if (!x86_64_immediate_operand (op1, Pmode))
9470                         op1 = force_reg (Pmode, op1);
9471                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
9472                     }
9473                 }
9474             }
9475           else
9476             {
9477               base = legitimize_pic_address (XEXP (addr, 0), reg);
9478               new_rtx  = legitimize_pic_address (XEXP (addr, 1),
9479                                                  base == reg ? NULL_RTX : reg);
9480
9481               if (CONST_INT_P (new_rtx))
9482                 new_rtx = plus_constant (base, INTVAL (new_rtx));
9483               else
9484                 {
9485                   if (GET_CODE (new_rtx) == PLUS && CONSTANT_P (XEXP (new_rtx, 1)))
9486                     {
9487                       base = gen_rtx_PLUS (Pmode, base, XEXP (new_rtx, 0));
9488                       new_rtx = XEXP (new_rtx, 1);
9489                     }
9490                   new_rtx = gen_rtx_PLUS (Pmode, base, new_rtx);
9491                 }
9492             }
9493         }
9494     }
9495   return new_rtx;
9496 }
9497 \f
9498 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
9499
9500 static rtx
9501 get_thread_pointer (int to_reg)
9502 {
9503   rtx tp, reg, insn;
9504
9505   tp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
9506   if (!to_reg)
9507     return tp;
9508
9509   reg = gen_reg_rtx (Pmode);
9510   insn = gen_rtx_SET (VOIDmode, reg, tp);
9511   insn = emit_insn (insn);
9512
9513   return reg;
9514 }
9515
9516 /* A subroutine of legitimize_address and ix86_expand_move.  FOR_MOV is
9517    false if we expect this to be used for a memory address and true if
9518    we expect to load the address into a register.  */
9519
9520 static rtx
9521 legitimize_tls_address (rtx x, enum tls_model model, int for_mov)
9522 {
9523   rtx dest, base, off, pic, tp;
9524   int type;
9525
9526   switch (model)
9527     {
9528     case TLS_MODEL_GLOBAL_DYNAMIC:
9529       dest = gen_reg_rtx (Pmode);
9530       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9531
9532       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9533         {
9534           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns;
9535
9536           start_sequence ();
9537           emit_call_insn (gen_tls_global_dynamic_64 (rax, x));
9538           insns = get_insns ();
9539           end_sequence ();
9540
9541           RTL_CONST_CALL_P (insns) = 1;
9542           emit_libcall_block (insns, dest, rax, x);
9543         }
9544       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9545         emit_insn (gen_tls_global_dynamic_64 (dest, x));
9546       else
9547         emit_insn (gen_tls_global_dynamic_32 (dest, x));
9548
9549       if (TARGET_GNU2_TLS)
9550         {
9551           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
9552
9553           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9554         }
9555       break;
9556
9557     case TLS_MODEL_LOCAL_DYNAMIC:
9558       base = gen_reg_rtx (Pmode);
9559       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9560
9561       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9562         {
9563           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns, note;
9564
9565           start_sequence ();
9566           emit_call_insn (gen_tls_local_dynamic_base_64 (rax));
9567           insns = get_insns ();
9568           end_sequence ();
9569
9570           note = gen_rtx_EXPR_LIST (VOIDmode, const0_rtx, NULL);
9571           note = gen_rtx_EXPR_LIST (VOIDmode, ix86_tls_get_addr (), note);
9572           RTL_CONST_CALL_P (insns) = 1;
9573           emit_libcall_block (insns, base, rax, note);
9574         }
9575       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9576         emit_insn (gen_tls_local_dynamic_base_64 (base));
9577       else
9578         emit_insn (gen_tls_local_dynamic_base_32 (base));
9579
9580       if (TARGET_GNU2_TLS)
9581         {
9582           rtx x = ix86_tls_module_base ();
9583
9584           set_unique_reg_note (get_last_insn (), REG_EQUIV,
9585                                gen_rtx_MINUS (Pmode, x, tp));
9586         }
9587
9588       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
9589       off = gen_rtx_CONST (Pmode, off);
9590
9591       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
9592
9593       if (TARGET_GNU2_TLS)
9594         {
9595           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
9596
9597           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9598         }
9599
9600       break;
9601
9602     case TLS_MODEL_INITIAL_EXEC:
9603       if (TARGET_64BIT)
9604         {
9605           pic = NULL;
9606           type = UNSPEC_GOTNTPOFF;
9607         }
9608       else if (flag_pic)
9609         {
9610           if (reload_in_progress)
9611             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9612           pic = pic_offset_table_rtx;
9613           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
9614         }
9615       else if (!TARGET_ANY_GNU_TLS)
9616         {
9617           pic = gen_reg_rtx (Pmode);
9618           emit_insn (gen_set_got (pic));
9619           type = UNSPEC_GOTTPOFF;
9620         }
9621       else
9622         {
9623           pic = NULL;
9624           type = UNSPEC_INDNTPOFF;
9625         }
9626
9627       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), type);
9628       off = gen_rtx_CONST (Pmode, off);
9629       if (pic)
9630         off = gen_rtx_PLUS (Pmode, pic, off);
9631       off = gen_const_mem (Pmode, off);
9632       set_mem_alias_set (off, ix86_GOT_alias_set ());
9633
9634       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9635         {
9636           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9637           off = force_reg (Pmode, off);
9638           return gen_rtx_PLUS (Pmode, base, off);
9639         }
9640       else
9641         {
9642           base = get_thread_pointer (true);
9643           dest = gen_reg_rtx (Pmode);
9644           emit_insn (gen_subsi3 (dest, base, off));
9645         }
9646       break;
9647
9648     case TLS_MODEL_LOCAL_EXEC:
9649       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
9650                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9651                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
9652       off = gen_rtx_CONST (Pmode, off);
9653
9654       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9655         {
9656           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9657           return gen_rtx_PLUS (Pmode, base, off);
9658         }
9659       else
9660         {
9661           base = get_thread_pointer (true);
9662           dest = gen_reg_rtx (Pmode);
9663           emit_insn (gen_subsi3 (dest, base, off));
9664         }
9665       break;
9666
9667     default:
9668       gcc_unreachable ();
9669     }
9670
9671   return dest;
9672 }
9673
9674 /* Create or return the unique __imp_DECL dllimport symbol corresponding
9675    to symbol DECL.  */
9676
9677 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
9678   htab_t dllimport_map;
9679
9680 static tree
9681 get_dllimport_decl (tree decl)
9682 {
9683   struct tree_map *h, in;
9684   void **loc;
9685   const char *name;
9686   const char *prefix;
9687   size_t namelen, prefixlen;
9688   char *imp_name;
9689   tree to;
9690   rtx rtl;
9691
9692   if (!dllimport_map)
9693     dllimport_map = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
9694
9695   in.hash = htab_hash_pointer (decl);
9696   in.base.from = decl;
9697   loc = htab_find_slot_with_hash (dllimport_map, &in, in.hash, INSERT);
9698   h = (struct tree_map *) *loc;
9699   if (h)
9700     return h->to;
9701
9702   *loc = h = GGC_NEW (struct tree_map);
9703   h->hash = in.hash;
9704   h->base.from = decl;
9705   h->to = to = build_decl (VAR_DECL, NULL, ptr_type_node);
9706   DECL_ARTIFICIAL (to) = 1;
9707   DECL_IGNORED_P (to) = 1;
9708   DECL_EXTERNAL (to) = 1;
9709   TREE_READONLY (to) = 1;
9710
9711   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9712   name = targetm.strip_name_encoding (name);
9713   prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
9714     ? "*__imp_" : "*__imp__";
9715   namelen = strlen (name);
9716   prefixlen = strlen (prefix);
9717   imp_name = (char *) alloca (namelen + prefixlen + 1);
9718   memcpy (imp_name, prefix, prefixlen);
9719   memcpy (imp_name + prefixlen, name, namelen + 1);
9720
9721   name = ggc_alloc_string (imp_name, namelen + prefixlen);
9722   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
9723   SET_SYMBOL_REF_DECL (rtl, to);
9724   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL;
9725
9726   rtl = gen_const_mem (Pmode, rtl);
9727   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
9728
9729   SET_DECL_RTL (to, rtl);
9730   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
9731
9732   return to;
9733 }
9734
9735 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
9736    true if we require the result be a register.  */
9737
9738 static rtx
9739 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
9740 {
9741   tree imp_decl;
9742   rtx x;
9743
9744   gcc_assert (SYMBOL_REF_DECL (symbol));
9745   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol));
9746
9747   x = DECL_RTL (imp_decl);
9748   if (want_reg)
9749     x = force_reg (Pmode, x);
9750   return x;
9751 }
9752
9753 /* Try machine-dependent ways of modifying an illegitimate address
9754    to be legitimate.  If we find one, return the new, valid address.
9755    This macro is used in only one place: `memory_address' in explow.c.
9756
9757    OLDX is the address as it was before break_out_memory_refs was called.
9758    In some cases it is useful to look at this to decide what needs to be done.
9759
9760    MODE and WIN are passed so that this macro can use
9761    GO_IF_LEGITIMATE_ADDRESS.
9762
9763    It is always safe for this macro to do nothing.  It exists to recognize
9764    opportunities to optimize the output.
9765
9766    For the 80386, we handle X+REG by loading X into a register R and
9767    using R+REG.  R will go in a general reg and indexing will be used.
9768    However, if REG is a broken-out memory address or multiplication,
9769    nothing needs to be done because REG can certainly go in a general reg.
9770
9771    When -fpic is used, special handling is needed for symbolic references.
9772    See comments by legitimize_pic_address in i386.c for details.  */
9773
9774 rtx
9775 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
9776 {
9777   int changed = 0;
9778   unsigned log;
9779
9780   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
9781   if (log)
9782     return legitimize_tls_address (x, (enum tls_model) log, false);
9783   if (GET_CODE (x) == CONST
9784       && GET_CODE (XEXP (x, 0)) == PLUS
9785       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9786       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
9787     {
9788       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
9789                                       (enum tls_model) log, false);
9790       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9791     }
9792
9793   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9794     {
9795       if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (x))
9796         return legitimize_dllimport_symbol (x, true);
9797       if (GET_CODE (x) == CONST
9798           && GET_CODE (XEXP (x, 0)) == PLUS
9799           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9800           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (x, 0), 0)))
9801         {
9802           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (x, 0), 0), true);
9803           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9804         }
9805     }
9806
9807   if (flag_pic && SYMBOLIC_CONST (x))
9808     return legitimize_pic_address (x, 0);
9809
9810   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
9811   if (GET_CODE (x) == ASHIFT
9812       && CONST_INT_P (XEXP (x, 1))
9813       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
9814     {
9815       changed = 1;
9816       log = INTVAL (XEXP (x, 1));
9817       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
9818                         GEN_INT (1 << log));
9819     }
9820
9821   if (GET_CODE (x) == PLUS)
9822     {
9823       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
9824
9825       if (GET_CODE (XEXP (x, 0)) == ASHIFT
9826           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
9827           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
9828         {
9829           changed = 1;
9830           log = INTVAL (XEXP (XEXP (x, 0), 1));
9831           XEXP (x, 0) = gen_rtx_MULT (Pmode,
9832                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
9833                                       GEN_INT (1 << log));
9834         }
9835
9836       if (GET_CODE (XEXP (x, 1)) == ASHIFT
9837           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
9838           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
9839         {
9840           changed = 1;
9841           log = INTVAL (XEXP (XEXP (x, 1), 1));
9842           XEXP (x, 1) = gen_rtx_MULT (Pmode,
9843                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
9844                                       GEN_INT (1 << log));
9845         }
9846
9847       /* Put multiply first if it isn't already.  */
9848       if (GET_CODE (XEXP (x, 1)) == MULT)
9849         {
9850           rtx tmp = XEXP (x, 0);
9851           XEXP (x, 0) = XEXP (x, 1);
9852           XEXP (x, 1) = tmp;
9853           changed = 1;
9854         }
9855
9856       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
9857          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
9858          created by virtual register instantiation, register elimination, and
9859          similar optimizations.  */
9860       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
9861         {
9862           changed = 1;
9863           x = gen_rtx_PLUS (Pmode,
9864                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
9865                                           XEXP (XEXP (x, 1), 0)),
9866                             XEXP (XEXP (x, 1), 1));
9867         }
9868
9869       /* Canonicalize
9870          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
9871          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
9872       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
9873                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
9874                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
9875                && CONSTANT_P (XEXP (x, 1)))
9876         {
9877           rtx constant;
9878           rtx other = NULL_RTX;
9879
9880           if (CONST_INT_P (XEXP (x, 1)))
9881             {
9882               constant = XEXP (x, 1);
9883               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
9884             }
9885           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
9886             {
9887               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
9888               other = XEXP (x, 1);
9889             }
9890           else
9891             constant = 0;
9892
9893           if (constant)
9894             {
9895               changed = 1;
9896               x = gen_rtx_PLUS (Pmode,
9897                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
9898                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
9899                                 plus_constant (other, INTVAL (constant)));
9900             }
9901         }
9902
9903       if (changed && legitimate_address_p (mode, x, FALSE))
9904         return x;
9905
9906       if (GET_CODE (XEXP (x, 0)) == MULT)
9907         {
9908           changed = 1;
9909           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
9910         }
9911
9912       if (GET_CODE (XEXP (x, 1)) == MULT)
9913         {
9914           changed = 1;
9915           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
9916         }
9917
9918       if (changed
9919           && REG_P (XEXP (x, 1))
9920           && REG_P (XEXP (x, 0)))
9921         return x;
9922
9923       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
9924         {
9925           changed = 1;
9926           x = legitimize_pic_address (x, 0);
9927         }
9928
9929       if (changed && legitimate_address_p (mode, x, FALSE))
9930         return x;
9931
9932       if (REG_P (XEXP (x, 0)))
9933         {
9934           rtx temp = gen_reg_rtx (Pmode);
9935           rtx val  = force_operand (XEXP (x, 1), temp);
9936           if (val != temp)
9937             emit_move_insn (temp, val);
9938
9939           XEXP (x, 1) = temp;
9940           return x;
9941         }
9942
9943       else if (REG_P (XEXP (x, 1)))
9944         {
9945           rtx temp = gen_reg_rtx (Pmode);
9946           rtx val  = force_operand (XEXP (x, 0), temp);
9947           if (val != temp)
9948             emit_move_insn (temp, val);
9949
9950           XEXP (x, 0) = temp;
9951           return x;
9952         }
9953     }
9954
9955   return x;
9956 }
9957 \f
9958 /* Print an integer constant expression in assembler syntax.  Addition
9959    and subtraction are the only arithmetic that may appear in these
9960    expressions.  FILE is the stdio stream to write to, X is the rtx, and
9961    CODE is the operand print code from the output string.  */
9962
9963 static void
9964 output_pic_addr_const (FILE *file, rtx x, int code)
9965 {
9966   char buf[256];
9967
9968   switch (GET_CODE (x))
9969     {
9970     case PC:
9971       gcc_assert (flag_pic);
9972       putc ('.', file);
9973       break;
9974
9975     case SYMBOL_REF:
9976       if (! TARGET_MACHO || TARGET_64BIT)
9977         output_addr_const (file, x);
9978       else
9979         {
9980           const char *name = XSTR (x, 0);
9981
9982           /* Mark the decl as referenced so that cgraph will
9983              output the function.  */
9984           if (SYMBOL_REF_DECL (x))
9985             mark_decl_referenced (SYMBOL_REF_DECL (x));
9986
9987 #if TARGET_MACHO
9988           if (MACHOPIC_INDIRECT
9989               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
9990             name = machopic_indirection_name (x, /*stub_p=*/true);
9991 #endif
9992           assemble_name (file, name);
9993         }
9994       if (!TARGET_MACHO && !(TARGET_64BIT && DEFAULT_ABI == MS_ABI)
9995           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
9996         fputs ("@PLT", file);
9997       break;
9998
9999     case LABEL_REF:
10000       x = XEXP (x, 0);
10001       /* FALLTHRU */
10002     case CODE_LABEL:
10003       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
10004       assemble_name (asm_out_file, buf);
10005       break;
10006
10007     case CONST_INT:
10008       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
10009       break;
10010
10011     case CONST:
10012       /* This used to output parentheses around the expression,
10013          but that does not work on the 386 (either ATT or BSD assembler).  */
10014       output_pic_addr_const (file, XEXP (x, 0), code);
10015       break;
10016
10017     case CONST_DOUBLE:
10018       if (GET_MODE (x) == VOIDmode)
10019         {
10020           /* We can use %d if the number is <32 bits and positive.  */
10021           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
10022             fprintf (file, "0x%lx%08lx",
10023                      (unsigned long) CONST_DOUBLE_HIGH (x),
10024                      (unsigned long) CONST_DOUBLE_LOW (x));
10025           else
10026             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
10027         }
10028       else
10029         /* We can't handle floating point constants;
10030            PRINT_OPERAND must handle them.  */
10031         output_operand_lossage ("floating constant misused");
10032       break;
10033
10034     case PLUS:
10035       /* Some assemblers need integer constants to appear first.  */
10036       if (CONST_INT_P (XEXP (x, 0)))
10037         {
10038           output_pic_addr_const (file, XEXP (x, 0), code);
10039           putc ('+', file);
10040           output_pic_addr_const (file, XEXP (x, 1), code);
10041         }
10042       else
10043         {
10044           gcc_assert (CONST_INT_P (XEXP (x, 1)));
10045           output_pic_addr_const (file, XEXP (x, 1), code);
10046           putc ('+', file);
10047           output_pic_addr_const (file, XEXP (x, 0), code);
10048         }
10049       break;
10050
10051     case MINUS:
10052       if (!TARGET_MACHO)
10053         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
10054       output_pic_addr_const (file, XEXP (x, 0), code);
10055       putc ('-', file);
10056       output_pic_addr_const (file, XEXP (x, 1), code);
10057       if (!TARGET_MACHO)
10058         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
10059       break;
10060
10061      case UNSPEC:
10062        gcc_assert (XVECLEN (x, 0) == 1);
10063        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
10064        switch (XINT (x, 1))
10065         {
10066         case UNSPEC_GOT:
10067           fputs ("@GOT", file);
10068           break;
10069         case UNSPEC_GOTOFF:
10070           fputs ("@GOTOFF", file);
10071           break;
10072         case UNSPEC_PLTOFF:
10073           fputs ("@PLTOFF", file);
10074           break;
10075         case UNSPEC_GOTPCREL:
10076           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10077                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
10078           break;
10079         case UNSPEC_GOTTPOFF:
10080           /* FIXME: This might be @TPOFF in Sun ld too.  */
10081           fputs ("@GOTTPOFF", file);
10082           break;
10083         case UNSPEC_TPOFF:
10084           fputs ("@TPOFF", file);
10085           break;
10086         case UNSPEC_NTPOFF:
10087           if (TARGET_64BIT)
10088             fputs ("@TPOFF", file);
10089           else
10090             fputs ("@NTPOFF", file);
10091           break;
10092         case UNSPEC_DTPOFF:
10093           fputs ("@DTPOFF", file);
10094           break;
10095         case UNSPEC_GOTNTPOFF:
10096           if (TARGET_64BIT)
10097             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10098                    "@GOTTPOFF(%rip)": "@GOTTPOFF[rip]", file);
10099           else
10100             fputs ("@GOTNTPOFF", file);
10101           break;
10102         case UNSPEC_INDNTPOFF:
10103           fputs ("@INDNTPOFF", file);
10104           break;
10105 #if TARGET_MACHO
10106         case UNSPEC_MACHOPIC_OFFSET:
10107           putc ('-', file);
10108           machopic_output_function_base_name (file);
10109           break;
10110 #endif
10111         default:
10112           output_operand_lossage ("invalid UNSPEC as operand");
10113           break;
10114         }
10115        break;
10116
10117     default:
10118       output_operand_lossage ("invalid expression as operand");
10119     }
10120 }
10121
10122 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
10123    We need to emit DTP-relative relocations.  */
10124
10125 static void ATTRIBUTE_UNUSED
10126 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
10127 {
10128   fputs (ASM_LONG, file);
10129   output_addr_const (file, x);
10130   fputs ("@DTPOFF", file);
10131   switch (size)
10132     {
10133     case 4:
10134       break;
10135     case 8:
10136       fputs (", 0", file);
10137       break;
10138     default:
10139       gcc_unreachable ();
10140    }
10141 }
10142
10143 /* Return true if X is a representation of the PIC register.  This copes
10144    with calls from ix86_find_base_term, where the register might have
10145    been replaced by a cselib value.  */
10146
10147 static bool
10148 ix86_pic_register_p (rtx x)
10149 {
10150   if (GET_CODE (x) == VALUE)
10151     return (pic_offset_table_rtx
10152             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
10153   else
10154     return REG_P (x) && REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
10155 }
10156
10157 /* In the name of slightly smaller debug output, and to cater to
10158    general assembler lossage, recognize PIC+GOTOFF and turn it back
10159    into a direct symbol reference.
10160
10161    On Darwin, this is necessary to avoid a crash, because Darwin
10162    has a different PIC label for each routine but the DWARF debugging
10163    information is not associated with any particular routine, so it's
10164    necessary to remove references to the PIC label from RTL stored by
10165    the DWARF output code.  */
10166
10167 static rtx
10168 ix86_delegitimize_address (rtx orig_x)
10169 {
10170   rtx x = orig_x;
10171   /* reg_addend is NULL or a multiple of some register.  */
10172   rtx reg_addend = NULL_RTX;
10173   /* const_addend is NULL or a const_int.  */
10174   rtx const_addend = NULL_RTX;
10175   /* This is the result, or NULL.  */
10176   rtx result = NULL_RTX;
10177
10178   if (MEM_P (x))
10179     x = XEXP (x, 0);
10180
10181   if (TARGET_64BIT)
10182     {
10183       if (GET_CODE (x) != CONST
10184           || GET_CODE (XEXP (x, 0)) != UNSPEC
10185           || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL
10186           || !MEM_P (orig_x))
10187         return orig_x;
10188       return XVECEXP (XEXP (x, 0), 0, 0);
10189     }
10190
10191   if (GET_CODE (x) != PLUS
10192       || GET_CODE (XEXP (x, 1)) != CONST)
10193     return orig_x;
10194
10195   if (ix86_pic_register_p (XEXP (x, 0)))
10196     /* %ebx + GOT/GOTOFF */
10197     ;
10198   else if (GET_CODE (XEXP (x, 0)) == PLUS)
10199     {
10200       /* %ebx + %reg * scale + GOT/GOTOFF */
10201       reg_addend = XEXP (x, 0);
10202       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
10203         reg_addend = XEXP (reg_addend, 1);
10204       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
10205         reg_addend = XEXP (reg_addend, 0);
10206       else
10207         return orig_x;
10208       if (!REG_P (reg_addend)
10209           && GET_CODE (reg_addend) != MULT
10210           && GET_CODE (reg_addend) != ASHIFT)
10211         return orig_x;
10212     }
10213   else
10214     return orig_x;
10215
10216   x = XEXP (XEXP (x, 1), 0);
10217   if (GET_CODE (x) == PLUS
10218       && CONST_INT_P (XEXP (x, 1)))
10219     {
10220       const_addend = XEXP (x, 1);
10221       x = XEXP (x, 0);
10222     }
10223
10224   if (GET_CODE (x) == UNSPEC
10225       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x))
10226           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))))
10227     result = XVECEXP (x, 0, 0);
10228
10229   if (TARGET_MACHO && darwin_local_data_pic (x)
10230       && !MEM_P (orig_x))
10231     result = XVECEXP (x, 0, 0);
10232
10233   if (! result)
10234     return orig_x;
10235
10236   if (const_addend)
10237     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
10238   if (reg_addend)
10239     result = gen_rtx_PLUS (Pmode, reg_addend, result);
10240   return result;
10241 }
10242
10243 /* If X is a machine specific address (i.e. a symbol or label being
10244    referenced as a displacement from the GOT implemented using an
10245    UNSPEC), then return the base term.  Otherwise return X.  */
10246
10247 rtx
10248 ix86_find_base_term (rtx x)
10249 {
10250   rtx term;
10251
10252   if (TARGET_64BIT)
10253     {
10254       if (GET_CODE (x) != CONST)
10255         return x;
10256       term = XEXP (x, 0);
10257       if (GET_CODE (term) == PLUS
10258           && (CONST_INT_P (XEXP (term, 1))
10259               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
10260         term = XEXP (term, 0);
10261       if (GET_CODE (term) != UNSPEC
10262           || XINT (term, 1) != UNSPEC_GOTPCREL)
10263         return x;
10264
10265       return XVECEXP (term, 0, 0);
10266     }
10267
10268   return ix86_delegitimize_address (x);
10269 }
10270 \f
10271 static void
10272 put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
10273                     int fp, FILE *file)
10274 {
10275   const char *suffix;
10276
10277   if (mode == CCFPmode || mode == CCFPUmode)
10278     {
10279       enum rtx_code second_code, bypass_code;
10280       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
10281       gcc_assert (bypass_code == UNKNOWN && second_code == UNKNOWN);
10282       code = ix86_fp_compare_code_to_integer (code);
10283       mode = CCmode;
10284     }
10285   if (reverse)
10286     code = reverse_condition (code);
10287
10288   switch (code)
10289     {
10290     case EQ:
10291       switch (mode)
10292         {
10293         case CCAmode:
10294           suffix = "a";
10295           break;
10296
10297         case CCCmode:
10298           suffix = "c";
10299           break;
10300
10301         case CCOmode:
10302           suffix = "o";
10303           break;
10304
10305         case CCSmode:
10306           suffix = "s";
10307           break;
10308
10309         default:
10310           suffix = "e";
10311         }
10312       break;
10313     case NE:
10314       switch (mode)
10315         {
10316         case CCAmode:
10317           suffix = "na";
10318           break;
10319
10320         case CCCmode:
10321           suffix = "nc";
10322           break;
10323
10324         case CCOmode:
10325           suffix = "no";
10326           break;
10327
10328         case CCSmode:
10329           suffix = "ns";
10330           break;
10331
10332         default:
10333           suffix = "ne";
10334         }
10335       break;
10336     case GT:
10337       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
10338       suffix = "g";
10339       break;
10340     case GTU:
10341       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
10342          Those same assemblers have the same but opposite lossage on cmov.  */
10343       if (mode == CCmode)
10344         suffix = fp ? "nbe" : "a";
10345       else if (mode == CCCmode)
10346         suffix = "b";
10347       else
10348         gcc_unreachable ();
10349       break;
10350     case LT:
10351       switch (mode)
10352         {
10353         case CCNOmode:
10354         case CCGOCmode:
10355           suffix = "s";
10356           break;
10357
10358         case CCmode:
10359         case CCGCmode:
10360           suffix = "l";
10361           break;
10362
10363         default:
10364           gcc_unreachable ();
10365         }
10366       break;
10367     case LTU:
10368       gcc_assert (mode == CCmode || mode == CCCmode);
10369       suffix = "b";
10370       break;
10371     case GE:
10372       switch (mode)
10373         {
10374         case CCNOmode:
10375         case CCGOCmode:
10376           suffix = "ns";
10377           break;
10378
10379         case CCmode:
10380         case CCGCmode:
10381           suffix = "ge";
10382           break;
10383
10384         default:
10385           gcc_unreachable ();
10386         }
10387       break;
10388     case GEU:
10389       /* ??? As above.  */
10390       gcc_assert (mode == CCmode || mode == CCCmode);
10391       suffix = fp ? "nb" : "ae";
10392       break;
10393     case LE:
10394       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
10395       suffix = "le";
10396       break;
10397     case LEU:
10398       /* ??? As above.  */
10399       if (mode == CCmode)
10400         suffix = "be";
10401       else if (mode == CCCmode)
10402         suffix = fp ? "nb" : "ae";
10403       else
10404         gcc_unreachable ();
10405       break;
10406     case UNORDERED:
10407       suffix = fp ? "u" : "p";
10408       break;
10409     case ORDERED:
10410       suffix = fp ? "nu" : "np";
10411       break;
10412     default:
10413       gcc_unreachable ();
10414     }
10415   fputs (suffix, file);
10416 }
10417
10418 /* Print the name of register X to FILE based on its machine mode and number.
10419    If CODE is 'w', pretend the mode is HImode.
10420    If CODE is 'b', pretend the mode is QImode.
10421    If CODE is 'k', pretend the mode is SImode.
10422    If CODE is 'q', pretend the mode is DImode.
10423    If CODE is 'x', pretend the mode is V4SFmode.
10424    If CODE is 't', pretend the mode is V8SFmode.
10425    If CODE is 'h', pretend the reg is the 'high' byte register.
10426    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
10427    If CODE is 'd', duplicate the operand for AVX instruction.
10428  */
10429
10430 void
10431 print_reg (rtx x, int code, FILE *file)
10432 {
10433   const char *reg;
10434   bool duplicated = code == 'd' && TARGET_AVX;
10435
10436   gcc_assert (x == pc_rtx
10437               || (REGNO (x) != ARG_POINTER_REGNUM
10438                   && REGNO (x) != FRAME_POINTER_REGNUM
10439                   && REGNO (x) != FLAGS_REG
10440                   && REGNO (x) != FPSR_REG
10441                   && REGNO (x) != FPCR_REG));
10442
10443   if (ASSEMBLER_DIALECT == ASM_ATT)
10444     putc ('%', file);
10445
10446   if (x == pc_rtx)
10447     {
10448       gcc_assert (TARGET_64BIT);
10449       fputs ("rip", file);
10450       return;
10451     }
10452
10453   if (code == 'w' || MMX_REG_P (x))
10454     code = 2;
10455   else if (code == 'b')
10456     code = 1;
10457   else if (code == 'k')
10458     code = 4;
10459   else if (code == 'q')
10460     code = 8;
10461   else if (code == 'y')
10462     code = 3;
10463   else if (code == 'h')
10464     code = 0;
10465   else if (code == 'x')
10466     code = 16;
10467   else if (code == 't')
10468     code = 32;
10469   else
10470     code = GET_MODE_SIZE (GET_MODE (x));
10471
10472   /* Irritatingly, AMD extended registers use different naming convention
10473      from the normal registers.  */
10474   if (REX_INT_REG_P (x))
10475     {
10476       gcc_assert (TARGET_64BIT);
10477       switch (code)
10478         {
10479           case 0:
10480             error ("extended registers have no high halves");
10481             break;
10482           case 1:
10483             fprintf (file, "r%ib", REGNO (x) - FIRST_REX_INT_REG + 8);
10484             break;
10485           case 2:
10486             fprintf (file, "r%iw", REGNO (x) - FIRST_REX_INT_REG + 8);
10487             break;
10488           case 4:
10489             fprintf (file, "r%id", REGNO (x) - FIRST_REX_INT_REG + 8);
10490             break;
10491           case 8:
10492             fprintf (file, "r%i", REGNO (x) - FIRST_REX_INT_REG + 8);
10493             break;
10494           default:
10495             error ("unsupported operand size for extended register");
10496             break;
10497         }
10498       return;
10499     }
10500
10501   reg = NULL;
10502   switch (code)
10503     {
10504     case 3:
10505       if (STACK_TOP_P (x))
10506         {
10507           reg = "st(0)";
10508           break;
10509         }
10510       /* FALLTHRU */
10511     case 8:
10512     case 4:
10513     case 12:
10514       if (! ANY_FP_REG_P (x))
10515         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
10516       /* FALLTHRU */
10517     case 16:
10518     case 2:
10519     normal:
10520       reg = hi_reg_name[REGNO (x)];
10521       break;
10522     case 1:
10523       if (REGNO (x) >= ARRAY_SIZE (qi_reg_name))
10524         goto normal;
10525       reg = qi_reg_name[REGNO (x)];
10526       break;
10527     case 0:
10528       if (REGNO (x) >= ARRAY_SIZE (qi_high_reg_name))
10529         goto normal;
10530       reg = qi_high_reg_name[REGNO (x)];
10531       break;
10532     case 32:
10533       if (SSE_REG_P (x))
10534         {
10535           gcc_assert (!duplicated);
10536           putc ('y', file);
10537           fputs (hi_reg_name[REGNO (x)] + 1, file);
10538           return;
10539         }
10540       break;
10541     default:
10542       gcc_unreachable ();
10543     }
10544
10545   fputs (reg, file);
10546   if (duplicated)
10547     {
10548       if (ASSEMBLER_DIALECT == ASM_ATT)
10549         fprintf (file, ", %%%s", reg);
10550       else
10551         fprintf (file, ", %s", reg);
10552     }
10553 }
10554
10555 /* Locate some local-dynamic symbol still in use by this function
10556    so that we can print its name in some tls_local_dynamic_base
10557    pattern.  */
10558
10559 static int
10560 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
10561 {
10562   rtx x = *px;
10563
10564   if (GET_CODE (x) == SYMBOL_REF
10565       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
10566     {
10567       cfun->machine->some_ld_name = XSTR (x, 0);
10568       return 1;
10569     }
10570
10571   return 0;
10572 }
10573
10574 static const char *
10575 get_some_local_dynamic_name (void)
10576 {
10577   rtx insn;
10578
10579   if (cfun->machine->some_ld_name)
10580     return cfun->machine->some_ld_name;
10581
10582   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
10583     if (INSN_P (insn)
10584         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
10585       return cfun->machine->some_ld_name;
10586
10587   gcc_unreachable ();
10588 }
10589
10590 /* Meaning of CODE:
10591    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
10592    C -- print opcode suffix for set/cmov insn.
10593    c -- like C, but print reversed condition
10594    E,e -- likewise, but for compare-and-branch fused insn.
10595    F,f -- likewise, but for floating-point.
10596    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
10597         otherwise nothing
10598    R -- print the prefix for register names.
10599    z -- print the opcode suffix for the size of the current operand.
10600    * -- print a star (in certain assembler syntax)
10601    A -- print an absolute memory reference.
10602    w -- print the operand as if it's a "word" (HImode) even if it isn't.
10603    s -- print a shift double count, followed by the assemblers argument
10604         delimiter.
10605    b -- print the QImode name of the register for the indicated operand.
10606         %b0 would print %al if operands[0] is reg 0.
10607    w --  likewise, print the HImode name of the register.
10608    k --  likewise, print the SImode name of the register.
10609    q --  likewise, print the DImode name of the register.
10610    x --  likewise, print the V4SFmode name of the register.
10611    t --  likewise, print the V8SFmode name of the register.
10612    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
10613    y -- print "st(0)" instead of "st" as a register.
10614    d -- print duplicated register operand for AVX instruction.
10615    D -- print condition for SSE cmp instruction.
10616    P -- if PIC, print an @PLT suffix.
10617    X -- don't print any sort of PIC '@' suffix for a symbol.
10618    & -- print some in-use local-dynamic symbol name.
10619    H -- print a memory address offset by 8; used for sse high-parts
10620    Y -- print condition for SSE5 com* instruction.
10621    + -- print a branch hint as 'cs' or 'ds' prefix
10622    ; -- print a semicolon (after prefixes due to bug in older gas).
10623  */
10624
10625 void
10626 print_operand (FILE *file, rtx x, int code)
10627 {
10628   if (code)
10629     {
10630       switch (code)
10631         {
10632         case '*':
10633           if (ASSEMBLER_DIALECT == ASM_ATT)
10634             putc ('*', file);
10635           return;
10636
10637         case '&':
10638           assemble_name (file, get_some_local_dynamic_name ());
10639           return;
10640
10641         case 'A':
10642           switch (ASSEMBLER_DIALECT)
10643             {
10644             case ASM_ATT:
10645               putc ('*', file);
10646               break;
10647
10648             case ASM_INTEL:
10649               /* Intel syntax. For absolute addresses, registers should not
10650                  be surrounded by braces.  */
10651               if (!REG_P (x))
10652                 {
10653                   putc ('[', file);
10654                   PRINT_OPERAND (file, x, 0);
10655                   putc (']', file);
10656                   return;
10657                 }
10658               break;
10659
10660             default:
10661               gcc_unreachable ();
10662             }
10663
10664           PRINT_OPERAND (file, x, 0);
10665           return;
10666
10667
10668         case 'L':
10669           if (ASSEMBLER_DIALECT == ASM_ATT)
10670             putc ('l', file);
10671           return;
10672
10673         case 'W':
10674           if (ASSEMBLER_DIALECT == ASM_ATT)
10675             putc ('w', file);
10676           return;
10677
10678         case 'B':
10679           if (ASSEMBLER_DIALECT == ASM_ATT)
10680             putc ('b', file);
10681           return;
10682
10683         case 'Q':
10684           if (ASSEMBLER_DIALECT == ASM_ATT)
10685             putc ('l', file);
10686           return;
10687
10688         case 'S':
10689           if (ASSEMBLER_DIALECT == ASM_ATT)
10690             putc ('s', file);
10691           return;
10692
10693         case 'T':
10694           if (ASSEMBLER_DIALECT == ASM_ATT)
10695             putc ('t', file);
10696           return;
10697
10698         case 'z':
10699           /* 387 opcodes don't get size suffixes if the operands are
10700              registers.  */
10701           if (STACK_REG_P (x))
10702             return;
10703
10704           /* Likewise if using Intel opcodes.  */
10705           if (ASSEMBLER_DIALECT == ASM_INTEL)
10706             return;
10707
10708           /* This is the size of op from size of operand.  */
10709           switch (GET_MODE_SIZE (GET_MODE (x)))
10710             {
10711             case 1:
10712               putc ('b', file);
10713               return;
10714
10715             case 2:
10716               if (MEM_P (x))
10717                 {
10718 #ifdef HAVE_GAS_FILDS_FISTS
10719                   putc ('s', file);
10720 #endif
10721                   return;
10722                 }
10723               else
10724                 putc ('w', file);
10725               return;
10726
10727             case 4:
10728               if (GET_MODE (x) == SFmode)
10729                 {
10730                   putc ('s', file);
10731                   return;
10732                 }
10733               else
10734                 putc ('l', file);
10735               return;
10736
10737             case 12:
10738             case 16:
10739               putc ('t', file);
10740               return;
10741
10742             case 8:
10743               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
10744                 {
10745                   if (MEM_P (x))
10746                     {
10747 #ifdef GAS_MNEMONICS
10748                       putc ('q', file);
10749 #else
10750                       putc ('l', file);
10751                       putc ('l', file);
10752 #endif
10753                     }
10754                   else
10755                     putc ('q', file);
10756                 }
10757               else
10758                 putc ('l', file);
10759               return;
10760
10761             default:
10762               gcc_unreachable ();
10763             }
10764
10765         case 'd':
10766         case 'b':
10767         case 'w':
10768         case 'k':
10769         case 'q':
10770         case 'h':
10771         case 't':
10772         case 'y':
10773         case 'x':
10774         case 'X':
10775         case 'P':
10776           break;
10777
10778         case 's':
10779           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
10780             {
10781               PRINT_OPERAND (file, x, 0);
10782               fputs (", ", file);
10783             }
10784           return;
10785
10786         case 'D':
10787           /* Little bit of braindamage here.  The SSE compare instructions
10788              does use completely different names for the comparisons that the
10789              fp conditional moves.  */
10790           if (TARGET_AVX)
10791             {
10792               switch (GET_CODE (x))
10793                 {
10794                 case EQ:
10795                   fputs ("eq", file);
10796                   break;
10797                 case UNEQ:
10798                   fputs ("eq_us", file);
10799                   break;
10800                 case LT:
10801                   fputs ("lt", file);
10802                   break;
10803                 case UNLT:
10804                   fputs ("nge", file);
10805                   break;
10806                 case LE:
10807                   fputs ("le", file);
10808                   break;
10809                 case UNLE:
10810                   fputs ("ngt", file);
10811                   break;
10812                 case UNORDERED:
10813                   fputs ("unord", file);
10814                   break;
10815                 case NE:
10816                   fputs ("neq", file);
10817                   break;
10818                 case LTGT:
10819                   fputs ("neq_oq", file);
10820                   break;
10821                 case GE:
10822                   fputs ("ge", file);
10823                   break;
10824                 case UNGE:
10825                   fputs ("nlt", file);
10826                   break;
10827                 case GT:
10828                   fputs ("gt", file);
10829                   break;
10830                 case UNGT:
10831                   fputs ("nle", file);
10832                   break;
10833                 case ORDERED:
10834                   fputs ("ord", file);
10835                   break;
10836                 default:
10837                   gcc_unreachable ();
10838                 }
10839             }
10840           else
10841             {
10842               switch (GET_CODE (x))
10843                 {
10844                 case EQ:
10845                 case UNEQ:
10846                   fputs ("eq", file);
10847                   break;
10848                 case LT:
10849                 case UNLT:
10850                   fputs ("lt", file);
10851                   break;
10852                 case LE:
10853                 case UNLE:
10854                   fputs ("le", file);
10855                   break;
10856                 case UNORDERED:
10857                   fputs ("unord", file);
10858                   break;
10859                 case NE:
10860                 case LTGT:
10861                   fputs ("neq", file);
10862                   break;
10863                 case UNGE:
10864                 case GE:
10865                   fputs ("nlt", file);
10866                   break;
10867                 case UNGT:
10868                 case GT:
10869                   fputs ("nle", file);
10870                   break;
10871                 case ORDERED:
10872                   fputs ("ord", file);
10873                   break;
10874                 default:
10875                   gcc_unreachable ();
10876                 }
10877             }
10878           return;
10879         case 'O':
10880 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10881           if (ASSEMBLER_DIALECT == ASM_ATT)
10882             {
10883               switch (GET_MODE (x))
10884                 {
10885                 case HImode: putc ('w', file); break;
10886                 case SImode:
10887                 case SFmode: putc ('l', file); break;
10888                 case DImode:
10889                 case DFmode: putc ('q', file); break;
10890                 default: gcc_unreachable ();
10891                 }
10892               putc ('.', file);
10893             }
10894 #endif
10895           return;
10896         case 'C':
10897           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
10898           return;
10899         case 'F':
10900 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10901           if (ASSEMBLER_DIALECT == ASM_ATT)
10902             putc ('.', file);
10903 #endif
10904           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
10905           return;
10906
10907           /* Like above, but reverse condition */
10908         case 'c':
10909           /* Check to see if argument to %c is really a constant
10910              and not a condition code which needs to be reversed.  */
10911           if (!COMPARISON_P (x))
10912           {
10913             output_operand_lossage ("operand is neither a constant nor a condition code, invalid operand code 'c'");
10914              return;
10915           }
10916           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
10917           return;
10918         case 'f':
10919 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10920           if (ASSEMBLER_DIALECT == ASM_ATT)
10921             putc ('.', file);
10922 #endif
10923           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
10924           return;
10925
10926         case 'E':
10927           put_condition_code (GET_CODE (x), CCmode, 0, 0, file);
10928           return;
10929
10930         case 'e':
10931           put_condition_code (GET_CODE (x), CCmode, 1, 0, file);
10932           return;
10933
10934         case 'H':
10935           /* It doesn't actually matter what mode we use here, as we're
10936              only going to use this for printing.  */
10937           x = adjust_address_nv (x, DImode, 8);
10938           break;
10939
10940         case '+':
10941           {
10942             rtx x;
10943
10944             if (!optimize
10945                 || optimize_function_for_size_p (cfun) || !TARGET_BRANCH_PREDICTION_HINTS)
10946               return;
10947
10948             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
10949             if (x)
10950               {
10951                 int pred_val = INTVAL (XEXP (x, 0));
10952
10953                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
10954                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
10955                   {
10956                     int taken = pred_val > REG_BR_PROB_BASE / 2;
10957                     int cputaken = final_forward_branch_p (current_output_insn) == 0;
10958
10959                     /* Emit hints only in the case default branch prediction
10960                        heuristics would fail.  */
10961                     if (taken != cputaken)
10962                       {
10963                         /* We use 3e (DS) prefix for taken branches and
10964                            2e (CS) prefix for not taken branches.  */
10965                         if (taken)
10966                           fputs ("ds ; ", file);
10967                         else
10968                           fputs ("cs ; ", file);
10969                       }
10970                   }
10971               }
10972             return;
10973           }
10974
10975         case 'Y':
10976           switch (GET_CODE (x))
10977             {
10978             case NE:
10979               fputs ("neq", file);
10980               break;
10981             case EQ:
10982               fputs ("eq", file);
10983               break;
10984             case GE:
10985             case GEU:
10986               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
10987               break;
10988             case GT:
10989             case GTU:
10990               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
10991               break;
10992             case LE:
10993             case LEU:
10994               fputs ("le", file);
10995               break;
10996             case LT:
10997             case LTU:
10998               fputs ("lt", file);
10999               break;
11000             case UNORDERED:
11001               fputs ("unord", file);
11002               break;
11003             case ORDERED:
11004               fputs ("ord", file);
11005               break;
11006             case UNEQ:
11007               fputs ("ueq", file);
11008               break;
11009             case UNGE:
11010               fputs ("nlt", file);
11011               break;
11012             case UNGT:
11013               fputs ("nle", file);
11014               break;
11015             case UNLE:
11016               fputs ("ule", file);
11017               break;
11018             case UNLT:
11019               fputs ("ult", file);
11020               break;
11021             case LTGT:
11022               fputs ("une", file);
11023               break;
11024             default:
11025               gcc_unreachable ();
11026             }
11027           return;
11028
11029         case ';':
11030 #if TARGET_MACHO
11031           fputs (" ; ", file);
11032 #else
11033           fputc (' ', file);
11034 #endif
11035           return;
11036
11037         default:
11038             output_operand_lossage ("invalid operand code '%c'", code);
11039         }
11040     }
11041
11042   if (REG_P (x))
11043     print_reg (x, code, file);
11044
11045   else if (MEM_P (x))
11046     {
11047       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
11048       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
11049           && GET_MODE (x) != BLKmode)
11050         {
11051           const char * size;
11052           switch (GET_MODE_SIZE (GET_MODE (x)))
11053             {
11054             case 1: size = "BYTE"; break;
11055             case 2: size = "WORD"; break;
11056             case 4: size = "DWORD"; break;
11057             case 8: size = "QWORD"; break;
11058             case 12: size = "XWORD"; break;
11059             case 16:
11060               if (GET_MODE (x) == XFmode)
11061                 size = "XWORD";
11062               else
11063                 size = "XMMWORD";
11064               break;
11065             default:
11066               gcc_unreachable ();
11067             }
11068
11069           /* Check for explicit size override (codes 'b', 'w' and 'k')  */
11070           if (code == 'b')
11071             size = "BYTE";
11072           else if (code == 'w')
11073             size = "WORD";
11074           else if (code == 'k')
11075             size = "DWORD";
11076
11077           fputs (size, file);
11078           fputs (" PTR ", file);
11079         }
11080
11081       x = XEXP (x, 0);
11082       /* Avoid (%rip) for call operands.  */
11083       if (CONSTANT_ADDRESS_P (x) && code == 'P'
11084           && !CONST_INT_P (x))
11085         output_addr_const (file, x);
11086       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
11087         output_operand_lossage ("invalid constraints for operand");
11088       else
11089         output_address (x);
11090     }
11091
11092   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
11093     {
11094       REAL_VALUE_TYPE r;
11095       long l;
11096
11097       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
11098       REAL_VALUE_TO_TARGET_SINGLE (r, l);
11099
11100       if (ASSEMBLER_DIALECT == ASM_ATT)
11101         putc ('$', file);
11102       fprintf (file, "0x%08lx", (long unsigned int) l);
11103     }
11104
11105   /* These float cases don't actually occur as immediate operands.  */
11106   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
11107     {
11108       char dstr[30];
11109
11110       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
11111       fprintf (file, "%s", dstr);
11112     }
11113
11114   else if (GET_CODE (x) == CONST_DOUBLE
11115            && GET_MODE (x) == XFmode)
11116     {
11117       char dstr[30];
11118
11119       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
11120       fprintf (file, "%s", dstr);
11121     }
11122
11123   else
11124     {
11125       /* We have patterns that allow zero sets of memory, for instance.
11126          In 64-bit mode, we should probably support all 8-byte vectors,
11127          since we can in fact encode that into an immediate.  */
11128       if (GET_CODE (x) == CONST_VECTOR)
11129         {
11130           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
11131           x = const0_rtx;
11132         }
11133
11134       if (code != 'P')
11135         {
11136           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
11137             {
11138               if (ASSEMBLER_DIALECT == ASM_ATT)
11139                 putc ('$', file);
11140             }
11141           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
11142                    || GET_CODE (x) == LABEL_REF)
11143             {
11144               if (ASSEMBLER_DIALECT == ASM_ATT)
11145                 putc ('$', file);
11146               else
11147                 fputs ("OFFSET FLAT:", file);
11148             }
11149         }
11150       if (CONST_INT_P (x))
11151         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
11152       else if (flag_pic)
11153         output_pic_addr_const (file, x, code);
11154       else
11155         output_addr_const (file, x);
11156     }
11157 }
11158 \f
11159 /* Print a memory operand whose address is ADDR.  */
11160
11161 void
11162 print_operand_address (FILE *file, rtx addr)
11163 {
11164   struct ix86_address parts;
11165   rtx base, index, disp;
11166   int scale;
11167   int ok = ix86_decompose_address (addr, &parts);
11168
11169   gcc_assert (ok);
11170
11171   base = parts.base;
11172   index = parts.index;
11173   disp = parts.disp;
11174   scale = parts.scale;
11175
11176   switch (parts.seg)
11177     {
11178     case SEG_DEFAULT:
11179       break;
11180     case SEG_FS:
11181     case SEG_GS:
11182       if (ASSEMBLER_DIALECT == ASM_ATT)
11183         putc ('%', file);
11184       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
11185       break;
11186     default:
11187       gcc_unreachable ();
11188     }
11189
11190   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
11191   if (TARGET_64BIT && !base && !index)
11192     {
11193       rtx symbol = disp;
11194
11195       if (GET_CODE (disp) == CONST
11196           && GET_CODE (XEXP (disp, 0)) == PLUS
11197           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11198         symbol = XEXP (XEXP (disp, 0), 0);
11199
11200       if (GET_CODE (symbol) == LABEL_REF
11201           || (GET_CODE (symbol) == SYMBOL_REF
11202               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
11203         base = pc_rtx;
11204     }
11205   if (!base && !index)
11206     {
11207       /* Displacement only requires special attention.  */
11208
11209       if (CONST_INT_P (disp))
11210         {
11211           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
11212             fputs ("ds:", file);
11213           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
11214         }
11215       else if (flag_pic)
11216         output_pic_addr_const (file, disp, 0);
11217       else
11218         output_addr_const (file, disp);
11219     }
11220   else
11221     {
11222       if (ASSEMBLER_DIALECT == ASM_ATT)
11223         {
11224           if (disp)
11225             {
11226               if (flag_pic)
11227                 output_pic_addr_const (file, disp, 0);
11228               else if (GET_CODE (disp) == LABEL_REF)
11229                 output_asm_label (disp);
11230               else
11231                 output_addr_const (file, disp);
11232             }
11233
11234           putc ('(', file);
11235           if (base)
11236             print_reg (base, 0, file);
11237           if (index)
11238             {
11239               putc (',', file);
11240               print_reg (index, 0, file);
11241               if (scale != 1)
11242                 fprintf (file, ",%d", scale);
11243             }
11244           putc (')', file);
11245         }
11246       else
11247         {
11248           rtx offset = NULL_RTX;
11249
11250           if (disp)
11251             {
11252               /* Pull out the offset of a symbol; print any symbol itself.  */
11253               if (GET_CODE (disp) == CONST
11254                   && GET_CODE (XEXP (disp, 0)) == PLUS
11255                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11256                 {
11257                   offset = XEXP (XEXP (disp, 0), 1);
11258                   disp = gen_rtx_CONST (VOIDmode,
11259                                         XEXP (XEXP (disp, 0), 0));
11260                 }
11261
11262               if (flag_pic)
11263                 output_pic_addr_const (file, disp, 0);
11264               else if (GET_CODE (disp) == LABEL_REF)
11265                 output_asm_label (disp);
11266               else if (CONST_INT_P (disp))
11267                 offset = disp;
11268               else
11269                 output_addr_const (file, disp);
11270             }
11271
11272           putc ('[', file);
11273           if (base)
11274             {
11275               print_reg (base, 0, file);
11276               if (offset)
11277                 {
11278                   if (INTVAL (offset) >= 0)
11279                     putc ('+', file);
11280                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11281                 }
11282             }
11283           else if (offset)
11284             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11285           else
11286             putc ('0', file);
11287
11288           if (index)
11289             {
11290               putc ('+', file);
11291               print_reg (index, 0, file);
11292               if (scale != 1)
11293                 fprintf (file, "*%d", scale);
11294             }
11295           putc (']', file);
11296         }
11297     }
11298 }
11299
11300 bool
11301 output_addr_const_extra (FILE *file, rtx x)
11302 {
11303   rtx op;
11304
11305   if (GET_CODE (x) != UNSPEC)
11306     return false;
11307
11308   op = XVECEXP (x, 0, 0);
11309   switch (XINT (x, 1))
11310     {
11311     case UNSPEC_GOTTPOFF:
11312       output_addr_const (file, op);
11313       /* FIXME: This might be @TPOFF in Sun ld.  */
11314       fputs ("@GOTTPOFF", file);
11315       break;
11316     case UNSPEC_TPOFF:
11317       output_addr_const (file, op);
11318       fputs ("@TPOFF", file);
11319       break;
11320     case UNSPEC_NTPOFF:
11321       output_addr_const (file, op);
11322       if (TARGET_64BIT)
11323         fputs ("@TPOFF", file);
11324       else
11325         fputs ("@NTPOFF", file);
11326       break;
11327     case UNSPEC_DTPOFF:
11328       output_addr_const (file, op);
11329       fputs ("@DTPOFF", file);
11330       break;
11331     case UNSPEC_GOTNTPOFF:
11332       output_addr_const (file, op);
11333       if (TARGET_64BIT)
11334         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
11335                "@GOTTPOFF(%rip)" : "@GOTTPOFF[rip]", file);
11336       else
11337         fputs ("@GOTNTPOFF", file);
11338       break;
11339     case UNSPEC_INDNTPOFF:
11340       output_addr_const (file, op);
11341       fputs ("@INDNTPOFF", file);
11342       break;
11343 #if TARGET_MACHO
11344     case UNSPEC_MACHOPIC_OFFSET:
11345       output_addr_const (file, op);
11346       putc ('-', file);
11347       machopic_output_function_base_name (file);
11348       break;
11349 #endif
11350
11351     default:
11352       return false;
11353     }
11354
11355   return true;
11356 }
11357 \f
11358 /* Split one or more DImode RTL references into pairs of SImode
11359    references.  The RTL can be REG, offsettable MEM, integer constant, or
11360    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11361    split and "num" is its length.  lo_half and hi_half are output arrays
11362    that parallel "operands".  */
11363
11364 void
11365 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11366 {
11367   while (num--)
11368     {
11369       rtx op = operands[num];
11370
11371       /* simplify_subreg refuse to split volatile memory addresses,
11372          but we still have to handle it.  */
11373       if (MEM_P (op))
11374         {
11375           lo_half[num] = adjust_address (op, SImode, 0);
11376           hi_half[num] = adjust_address (op, SImode, 4);
11377         }
11378       else
11379         {
11380           lo_half[num] = simplify_gen_subreg (SImode, op,
11381                                               GET_MODE (op) == VOIDmode
11382                                               ? DImode : GET_MODE (op), 0);
11383           hi_half[num] = simplify_gen_subreg (SImode, op,
11384                                               GET_MODE (op) == VOIDmode
11385                                               ? DImode : GET_MODE (op), 4);
11386         }
11387     }
11388 }
11389 /* Split one or more TImode RTL references into pairs of DImode
11390    references.  The RTL can be REG, offsettable MEM, integer constant, or
11391    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11392    split and "num" is its length.  lo_half and hi_half are output arrays
11393    that parallel "operands".  */
11394
11395 void
11396 split_ti (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11397 {
11398   while (num--)
11399     {
11400       rtx op = operands[num];
11401
11402       /* simplify_subreg refuse to split volatile memory addresses, but we
11403          still have to handle it.  */
11404       if (MEM_P (op))
11405         {
11406           lo_half[num] = adjust_address (op, DImode, 0);
11407           hi_half[num] = adjust_address (op, DImode, 8);
11408         }
11409       else
11410         {
11411           lo_half[num] = simplify_gen_subreg (DImode, op, TImode, 0);
11412           hi_half[num] = simplify_gen_subreg (DImode, op, TImode, 8);
11413         }
11414     }
11415 }
11416 \f
11417 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
11418    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
11419    is the expression of the binary operation.  The output may either be
11420    emitted here, or returned to the caller, like all output_* functions.
11421
11422    There is no guarantee that the operands are the same mode, as they
11423    might be within FLOAT or FLOAT_EXTEND expressions.  */
11424
11425 #ifndef SYSV386_COMPAT
11426 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
11427    wants to fix the assemblers because that causes incompatibility
11428    with gcc.  No-one wants to fix gcc because that causes
11429    incompatibility with assemblers...  You can use the option of
11430    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
11431 #define SYSV386_COMPAT 1
11432 #endif
11433
11434 const char *
11435 output_387_binary_op (rtx insn, rtx *operands)
11436 {
11437   static char buf[40];
11438   const char *p;
11439   const char *ssep;
11440   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
11441
11442 #ifdef ENABLE_CHECKING
11443   /* Even if we do not want to check the inputs, this documents input
11444      constraints.  Which helps in understanding the following code.  */
11445   if (STACK_REG_P (operands[0])
11446       && ((REG_P (operands[1])
11447            && REGNO (operands[0]) == REGNO (operands[1])
11448            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
11449           || (REG_P (operands[2])
11450               && REGNO (operands[0]) == REGNO (operands[2])
11451               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
11452       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
11453     ; /* ok */
11454   else
11455     gcc_assert (is_sse);
11456 #endif
11457
11458   switch (GET_CODE (operands[3]))
11459     {
11460     case PLUS:
11461       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11462           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11463         p = "fiadd";
11464       else
11465         p = "fadd";
11466       ssep = "vadd";
11467       break;
11468
11469     case MINUS:
11470       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11471           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11472         p = "fisub";
11473       else
11474         p = "fsub";
11475       ssep = "vsub";
11476       break;
11477
11478     case MULT:
11479       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11480           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11481         p = "fimul";
11482       else
11483         p = "fmul";
11484       ssep = "vmul";
11485       break;
11486
11487     case DIV:
11488       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11489           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11490         p = "fidiv";
11491       else
11492         p = "fdiv";
11493       ssep = "vdiv";
11494       break;
11495
11496     default:
11497       gcc_unreachable ();
11498     }
11499
11500   if (is_sse)
11501    {
11502      if (TARGET_AVX)
11503        {
11504          strcpy (buf, ssep);
11505          if (GET_MODE (operands[0]) == SFmode)
11506            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
11507          else
11508            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
11509        }
11510      else
11511        {
11512          strcpy (buf, ssep + 1);
11513          if (GET_MODE (operands[0]) == SFmode)
11514            strcat (buf, "ss\t{%2, %0|%0, %2}");
11515          else
11516            strcat (buf, "sd\t{%2, %0|%0, %2}");
11517        }
11518       return buf;
11519    }
11520   strcpy (buf, p);
11521
11522   switch (GET_CODE (operands[3]))
11523     {
11524     case MULT:
11525     case PLUS:
11526       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
11527         {
11528           rtx temp = operands[2];
11529           operands[2] = operands[1];
11530           operands[1] = temp;
11531         }
11532
11533       /* know operands[0] == operands[1].  */
11534
11535       if (MEM_P (operands[2]))
11536         {
11537           p = "%z2\t%2";
11538           break;
11539         }
11540
11541       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11542         {
11543           if (STACK_TOP_P (operands[0]))
11544             /* How is it that we are storing to a dead operand[2]?
11545                Well, presumably operands[1] is dead too.  We can't
11546                store the result to st(0) as st(0) gets popped on this
11547                instruction.  Instead store to operands[2] (which I
11548                think has to be st(1)).  st(1) will be popped later.
11549                gcc <= 2.8.1 didn't have this check and generated
11550                assembly code that the Unixware assembler rejected.  */
11551             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
11552           else
11553             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11554           break;
11555         }
11556
11557       if (STACK_TOP_P (operands[0]))
11558         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
11559       else
11560         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
11561       break;
11562
11563     case MINUS:
11564     case DIV:
11565       if (MEM_P (operands[1]))
11566         {
11567           p = "r%z1\t%1";
11568           break;
11569         }
11570
11571       if (MEM_P (operands[2]))
11572         {
11573           p = "%z2\t%2";
11574           break;
11575         }
11576
11577       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11578         {
11579 #if SYSV386_COMPAT
11580           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
11581              derived assemblers, confusingly reverse the direction of
11582              the operation for fsub{r} and fdiv{r} when the
11583              destination register is not st(0).  The Intel assembler
11584              doesn't have this brain damage.  Read !SYSV386_COMPAT to
11585              figure out what the hardware really does.  */
11586           if (STACK_TOP_P (operands[0]))
11587             p = "{p\t%0, %2|rp\t%2, %0}";
11588           else
11589             p = "{rp\t%2, %0|p\t%0, %2}";
11590 #else
11591           if (STACK_TOP_P (operands[0]))
11592             /* As above for fmul/fadd, we can't store to st(0).  */
11593             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
11594           else
11595             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11596 #endif
11597           break;
11598         }
11599
11600       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
11601         {
11602 #if SYSV386_COMPAT
11603           if (STACK_TOP_P (operands[0]))
11604             p = "{rp\t%0, %1|p\t%1, %0}";
11605           else
11606             p = "{p\t%1, %0|rp\t%0, %1}";
11607 #else
11608           if (STACK_TOP_P (operands[0]))
11609             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
11610           else
11611             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
11612 #endif
11613           break;
11614         }
11615
11616       if (STACK_TOP_P (operands[0]))
11617         {
11618           if (STACK_TOP_P (operands[1]))
11619             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
11620           else
11621             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
11622           break;
11623         }
11624       else if (STACK_TOP_P (operands[1]))
11625         {
11626 #if SYSV386_COMPAT
11627           p = "{\t%1, %0|r\t%0, %1}";
11628 #else
11629           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
11630 #endif
11631         }
11632       else
11633         {
11634 #if SYSV386_COMPAT
11635           p = "{r\t%2, %0|\t%0, %2}";
11636 #else
11637           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
11638 #endif
11639         }
11640       break;
11641
11642     default:
11643       gcc_unreachable ();
11644     }
11645
11646   strcat (buf, p);
11647   return buf;
11648 }
11649
11650 /* Return needed mode for entity in optimize_mode_switching pass.  */
11651
11652 int
11653 ix86_mode_needed (int entity, rtx insn)
11654 {
11655   enum attr_i387_cw mode;
11656
11657   /* The mode UNINITIALIZED is used to store control word after a
11658      function call or ASM pattern.  The mode ANY specify that function
11659      has no requirements on the control word and make no changes in the
11660      bits we are interested in.  */
11661
11662   if (CALL_P (insn)
11663       || (NONJUMP_INSN_P (insn)
11664           && (asm_noperands (PATTERN (insn)) >= 0
11665               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
11666     return I387_CW_UNINITIALIZED;
11667
11668   if (recog_memoized (insn) < 0)
11669     return I387_CW_ANY;
11670
11671   mode = get_attr_i387_cw (insn);
11672
11673   switch (entity)
11674     {
11675     case I387_TRUNC:
11676       if (mode == I387_CW_TRUNC)
11677         return mode;
11678       break;
11679
11680     case I387_FLOOR:
11681       if (mode == I387_CW_FLOOR)
11682         return mode;
11683       break;
11684
11685     case I387_CEIL:
11686       if (mode == I387_CW_CEIL)
11687         return mode;
11688       break;
11689
11690     case I387_MASK_PM:
11691       if (mode == I387_CW_MASK_PM)
11692         return mode;
11693       break;
11694
11695     default:
11696       gcc_unreachable ();
11697     }
11698
11699   return I387_CW_ANY;
11700 }
11701
11702 /* Output code to initialize control word copies used by trunc?f?i and
11703    rounding patterns.  CURRENT_MODE is set to current control word,
11704    while NEW_MODE is set to new control word.  */
11705
11706 void
11707 emit_i387_cw_initialization (int mode)
11708 {
11709   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
11710   rtx new_mode;
11711
11712   enum ix86_stack_slot slot;
11713
11714   rtx reg = gen_reg_rtx (HImode);
11715
11716   emit_insn (gen_x86_fnstcw_1 (stored_mode));
11717   emit_move_insn (reg, copy_rtx (stored_mode));
11718
11719   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
11720       || optimize_function_for_size_p (cfun))
11721     {
11722       switch (mode)
11723         {
11724         case I387_CW_TRUNC:
11725           /* round toward zero (truncate) */
11726           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
11727           slot = SLOT_CW_TRUNC;
11728           break;
11729
11730         case I387_CW_FLOOR:
11731           /* round down toward -oo */
11732           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11733           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
11734           slot = SLOT_CW_FLOOR;
11735           break;
11736
11737         case I387_CW_CEIL:
11738           /* round up toward +oo */
11739           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11740           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
11741           slot = SLOT_CW_CEIL;
11742           break;
11743
11744         case I387_CW_MASK_PM:
11745           /* mask precision exception for nearbyint() */
11746           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11747           slot = SLOT_CW_MASK_PM;
11748           break;
11749
11750         default:
11751           gcc_unreachable ();
11752         }
11753     }
11754   else
11755     {
11756       switch (mode)
11757         {
11758         case I387_CW_TRUNC:
11759           /* round toward zero (truncate) */
11760           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
11761           slot = SLOT_CW_TRUNC;
11762           break;
11763
11764         case I387_CW_FLOOR:
11765           /* round down toward -oo */
11766           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
11767           slot = SLOT_CW_FLOOR;
11768           break;
11769
11770         case I387_CW_CEIL:
11771           /* round up toward +oo */
11772           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
11773           slot = SLOT_CW_CEIL;
11774           break;
11775
11776         case I387_CW_MASK_PM:
11777           /* mask precision exception for nearbyint() */
11778           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11779           slot = SLOT_CW_MASK_PM;
11780           break;
11781
11782         default:
11783           gcc_unreachable ();
11784         }
11785     }
11786
11787   gcc_assert (slot < MAX_386_STACK_LOCALS);
11788
11789   new_mode = assign_386_stack_local (HImode, slot);
11790   emit_move_insn (new_mode, reg);
11791 }
11792
11793 /* Output code for INSN to convert a float to a signed int.  OPERANDS
11794    are the insn operands.  The output may be [HSD]Imode and the input
11795    operand may be [SDX]Fmode.  */
11796
11797 const char *
11798 output_fix_trunc (rtx insn, rtx *operands, int fisttp)
11799 {
11800   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11801   int dimode_p = GET_MODE (operands[0]) == DImode;
11802   int round_mode = get_attr_i387_cw (insn);
11803
11804   /* Jump through a hoop or two for DImode, since the hardware has no
11805      non-popping instruction.  We used to do this a different way, but
11806      that was somewhat fragile and broke with post-reload splitters.  */
11807   if ((dimode_p || fisttp) && !stack_top_dies)
11808     output_asm_insn ("fld\t%y1", operands);
11809
11810   gcc_assert (STACK_TOP_P (operands[1]));
11811   gcc_assert (MEM_P (operands[0]));
11812   gcc_assert (GET_MODE (operands[1]) != TFmode);
11813
11814   if (fisttp)
11815       output_asm_insn ("fisttp%z0\t%0", operands);
11816   else
11817     {
11818       if (round_mode != I387_CW_ANY)
11819         output_asm_insn ("fldcw\t%3", operands);
11820       if (stack_top_dies || dimode_p)
11821         output_asm_insn ("fistp%z0\t%0", operands);
11822       else
11823         output_asm_insn ("fist%z0\t%0", operands);
11824       if (round_mode != I387_CW_ANY)
11825         output_asm_insn ("fldcw\t%2", operands);
11826     }
11827
11828   return "";
11829 }
11830
11831 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
11832    have the values zero or one, indicates the ffreep insn's operand
11833    from the OPERANDS array.  */
11834
11835 static const char *
11836 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
11837 {
11838   if (TARGET_USE_FFREEP)
11839 #if HAVE_AS_IX86_FFREEP
11840     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
11841 #else
11842     {
11843       static char retval[] = ".word\t0xc_df";
11844       int regno = REGNO (operands[opno]);
11845
11846       gcc_assert (FP_REGNO_P (regno));
11847
11848       retval[9] = '0' + (regno - FIRST_STACK_REG);
11849       return retval;
11850     }
11851 #endif
11852
11853   return opno ? "fstp\t%y1" : "fstp\t%y0";
11854 }
11855
11856
11857 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
11858    should be used.  UNORDERED_P is true when fucom should be used.  */
11859
11860 const char *
11861 output_fp_compare (rtx insn, rtx *operands, int eflags_p, int unordered_p)
11862 {
11863   int stack_top_dies;
11864   rtx cmp_op0, cmp_op1;
11865   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
11866
11867   if (eflags_p)
11868     {
11869       cmp_op0 = operands[0];
11870       cmp_op1 = operands[1];
11871     }
11872   else
11873     {
11874       cmp_op0 = operands[1];
11875       cmp_op1 = operands[2];
11876     }
11877
11878   if (is_sse)
11879     {
11880       static const char ucomiss[] = "vucomiss\t{%1, %0|%0, %1}";
11881       static const char ucomisd[] = "vucomisd\t{%1, %0|%0, %1}";
11882       static const char comiss[] = "vcomiss\t{%1, %0|%0, %1}";
11883       static const char comisd[] = "vcomisd\t{%1, %0|%0, %1}";
11884
11885       if (GET_MODE (operands[0]) == SFmode)
11886         if (unordered_p)
11887           return &ucomiss[TARGET_AVX ? 0 : 1];
11888         else
11889           return &comiss[TARGET_AVX ? 0 : 1];
11890       else
11891         if (unordered_p)
11892           return &ucomisd[TARGET_AVX ? 0 : 1];
11893         else
11894           return &comisd[TARGET_AVX ? 0 : 1];
11895     }
11896
11897   gcc_assert (STACK_TOP_P (cmp_op0));
11898
11899   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11900
11901   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
11902     {
11903       if (stack_top_dies)
11904         {
11905           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
11906           return output_387_ffreep (operands, 1);
11907         }
11908       else
11909         return "ftst\n\tfnstsw\t%0";
11910     }
11911
11912   if (STACK_REG_P (cmp_op1)
11913       && stack_top_dies
11914       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
11915       && REGNO (cmp_op1) != FIRST_STACK_REG)
11916     {
11917       /* If both the top of the 387 stack dies, and the other operand
11918          is also a stack register that dies, then this must be a
11919          `fcompp' float compare */
11920
11921       if (eflags_p)
11922         {
11923           /* There is no double popping fcomi variant.  Fortunately,
11924              eflags is immune from the fstp's cc clobbering.  */
11925           if (unordered_p)
11926             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
11927           else
11928             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
11929           return output_387_ffreep (operands, 0);
11930         }
11931       else
11932         {
11933           if (unordered_p)
11934             return "fucompp\n\tfnstsw\t%0";
11935           else
11936             return "fcompp\n\tfnstsw\t%0";
11937         }
11938     }
11939   else
11940     {
11941       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
11942
11943       static const char * const alt[16] =
11944       {
11945         "fcom%z2\t%y2\n\tfnstsw\t%0",
11946         "fcomp%z2\t%y2\n\tfnstsw\t%0",
11947         "fucom%z2\t%y2\n\tfnstsw\t%0",
11948         "fucomp%z2\t%y2\n\tfnstsw\t%0",
11949
11950         "ficom%z2\t%y2\n\tfnstsw\t%0",
11951         "ficomp%z2\t%y2\n\tfnstsw\t%0",
11952         NULL,
11953         NULL,
11954
11955         "fcomi\t{%y1, %0|%0, %y1}",
11956         "fcomip\t{%y1, %0|%0, %y1}",
11957         "fucomi\t{%y1, %0|%0, %y1}",
11958         "fucomip\t{%y1, %0|%0, %y1}",
11959
11960         NULL,
11961         NULL,
11962         NULL,
11963         NULL
11964       };
11965
11966       int mask;
11967       const char *ret;
11968
11969       mask  = eflags_p << 3;
11970       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
11971       mask |= unordered_p << 1;
11972       mask |= stack_top_dies;
11973
11974       gcc_assert (mask < 16);
11975       ret = alt[mask];
11976       gcc_assert (ret);
11977
11978       return ret;
11979     }
11980 }
11981
11982 void
11983 ix86_output_addr_vec_elt (FILE *file, int value)
11984 {
11985   const char *directive = ASM_LONG;
11986
11987 #ifdef ASM_QUAD
11988   if (TARGET_64BIT)
11989     directive = ASM_QUAD;
11990 #else
11991   gcc_assert (!TARGET_64BIT);
11992 #endif
11993
11994   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
11995 }
11996
11997 void
11998 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
11999 {
12000   const char *directive = ASM_LONG;
12001
12002 #ifdef ASM_QUAD
12003   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
12004     directive = ASM_QUAD;
12005 #else
12006   gcc_assert (!TARGET_64BIT);
12007 #endif
12008   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
12009   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
12010     fprintf (file, "%s%s%d-%s%d\n",
12011              directive, LPREFIX, value, LPREFIX, rel);
12012   else if (HAVE_AS_GOTOFF_IN_DATA)
12013     fprintf (file, "%s%s%d@GOTOFF\n", ASM_LONG, LPREFIX, value);
12014 #if TARGET_MACHO
12015   else if (TARGET_MACHO)
12016     {
12017       fprintf (file, "%s%s%d-", ASM_LONG, LPREFIX, value);
12018       machopic_output_function_base_name (file);
12019       fprintf(file, "\n");
12020     }
12021 #endif
12022   else
12023     asm_fprintf (file, "%s%U%s+[.-%s%d]\n",
12024                  ASM_LONG, GOT_SYMBOL_NAME, LPREFIX, value);
12025 }
12026 \f
12027 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
12028    for the target.  */
12029
12030 void
12031 ix86_expand_clear (rtx dest)
12032 {
12033   rtx tmp;
12034
12035   /* We play register width games, which are only valid after reload.  */
12036   gcc_assert (reload_completed);
12037
12038   /* Avoid HImode and its attendant prefix byte.  */
12039   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
12040     dest = gen_rtx_REG (SImode, REGNO (dest));
12041   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
12042
12043   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
12044   if (reload_completed && (!TARGET_USE_MOV0 || optimize_insn_for_speed_p ()))
12045     {
12046       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12047       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
12048     }
12049
12050   emit_insn (tmp);
12051 }
12052
12053 /* X is an unchanging MEM.  If it is a constant pool reference, return
12054    the constant pool rtx, else NULL.  */
12055
12056 rtx
12057 maybe_get_pool_constant (rtx x)
12058 {
12059   x = ix86_delegitimize_address (XEXP (x, 0));
12060
12061   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
12062     return get_pool_constant (x);
12063
12064   return NULL_RTX;
12065 }
12066
12067 void
12068 ix86_expand_move (enum machine_mode mode, rtx operands[])
12069 {
12070   rtx op0, op1;
12071   enum tls_model model;
12072
12073   op0 = operands[0];
12074   op1 = operands[1];
12075
12076   if (GET_CODE (op1) == SYMBOL_REF)
12077     {
12078       model = SYMBOL_REF_TLS_MODEL (op1);
12079       if (model)
12080         {
12081           op1 = legitimize_tls_address (op1, model, true);
12082           op1 = force_operand (op1, op0);
12083           if (op1 == op0)
12084             return;
12085         }
12086       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12087                && SYMBOL_REF_DLLIMPORT_P (op1))
12088         op1 = legitimize_dllimport_symbol (op1, false);
12089     }
12090   else if (GET_CODE (op1) == CONST
12091            && GET_CODE (XEXP (op1, 0)) == PLUS
12092            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
12093     {
12094       rtx addend = XEXP (XEXP (op1, 0), 1);
12095       rtx symbol = XEXP (XEXP (op1, 0), 0);
12096       rtx tmp = NULL;
12097
12098       model = SYMBOL_REF_TLS_MODEL (symbol);
12099       if (model)
12100         tmp = legitimize_tls_address (symbol, model, true);
12101       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12102                && SYMBOL_REF_DLLIMPORT_P (symbol))
12103         tmp = legitimize_dllimport_symbol (symbol, true);
12104
12105       if (tmp)
12106         {
12107           tmp = force_operand (tmp, NULL);
12108           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
12109                                      op0, 1, OPTAB_DIRECT);
12110           if (tmp == op0)
12111             return;
12112         }
12113     }
12114
12115   if (flag_pic && mode == Pmode && symbolic_operand (op1, Pmode))
12116     {
12117       if (TARGET_MACHO && !TARGET_64BIT)
12118         {
12119 #if TARGET_MACHO
12120           if (MACHOPIC_PURE)
12121             {
12122               rtx temp = ((reload_in_progress
12123                            || ((op0 && REG_P (op0))
12124                                && mode == Pmode))
12125                           ? op0 : gen_reg_rtx (Pmode));
12126               op1 = machopic_indirect_data_reference (op1, temp);
12127               op1 = machopic_legitimize_pic_address (op1, mode,
12128                                                      temp == op1 ? 0 : temp);
12129             }
12130           else if (MACHOPIC_INDIRECT)
12131             op1 = machopic_indirect_data_reference (op1, 0);
12132           if (op0 == op1)
12133             return;
12134 #endif
12135         }
12136       else
12137         {
12138           if (MEM_P (op0))
12139             op1 = force_reg (Pmode, op1);
12140           else if (!TARGET_64BIT || !x86_64_movabs_operand (op1, Pmode))
12141             {
12142               rtx reg = !can_create_pseudo_p () ? op0 : NULL_RTX;
12143               op1 = legitimize_pic_address (op1, reg);
12144               if (op0 == op1)
12145                 return;
12146             }
12147         }
12148     }
12149   else
12150     {
12151       if (MEM_P (op0)
12152           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
12153               || !push_operand (op0, mode))
12154           && MEM_P (op1))
12155         op1 = force_reg (mode, op1);
12156
12157       if (push_operand (op0, mode)
12158           && ! general_no_elim_operand (op1, mode))
12159         op1 = copy_to_mode_reg (mode, op1);
12160
12161       /* Force large constants in 64bit compilation into register
12162          to get them CSEed.  */
12163       if (can_create_pseudo_p ()
12164           && (mode == DImode) && TARGET_64BIT
12165           && immediate_operand (op1, mode)
12166           && !x86_64_zext_immediate_operand (op1, VOIDmode)
12167           && !register_operand (op0, mode)
12168           && optimize)
12169         op1 = copy_to_mode_reg (mode, op1);
12170
12171       if (can_create_pseudo_p ()
12172           && FLOAT_MODE_P (mode)
12173           && GET_CODE (op1) == CONST_DOUBLE)
12174         {
12175           /* If we are loading a floating point constant to a register,
12176              force the value to memory now, since we'll get better code
12177              out the back end.  */
12178
12179           op1 = validize_mem (force_const_mem (mode, op1));
12180           if (!register_operand (op0, mode))
12181             {
12182               rtx temp = gen_reg_rtx (mode);
12183               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
12184               emit_move_insn (op0, temp);
12185               return;
12186             }
12187         }
12188     }
12189
12190   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12191 }
12192
12193 void
12194 ix86_expand_vector_move (enum machine_mode mode, rtx operands[])
12195 {
12196   rtx op0 = operands[0], op1 = operands[1];
12197   unsigned int align = GET_MODE_ALIGNMENT (mode);
12198
12199   /* Force constants other than zero into memory.  We do not know how
12200      the instructions used to build constants modify the upper 64 bits
12201      of the register, once we have that information we may be able
12202      to handle some of them more efficiently.  */
12203   if (can_create_pseudo_p ()
12204       && register_operand (op0, mode)
12205       && (CONSTANT_P (op1)
12206           || (GET_CODE (op1) == SUBREG
12207               && CONSTANT_P (SUBREG_REG (op1))))
12208       && standard_sse_constant_p (op1) <= 0)
12209     op1 = validize_mem (force_const_mem (mode, op1));
12210
12211   /* We need to check memory alignment for SSE mode since attribute
12212      can make operands unaligned.  */
12213   if (can_create_pseudo_p ()
12214       && SSE_REG_MODE_P (mode)
12215       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
12216           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
12217     {
12218       rtx tmp[2];
12219
12220       /* ix86_expand_vector_move_misalign() does not like constants ... */
12221       if (CONSTANT_P (op1)
12222           || (GET_CODE (op1) == SUBREG
12223               && CONSTANT_P (SUBREG_REG (op1))))
12224         op1 = validize_mem (force_const_mem (mode, op1));
12225
12226       /* ... nor both arguments in memory.  */
12227       if (!register_operand (op0, mode)
12228           && !register_operand (op1, mode))
12229         op1 = force_reg (mode, op1);
12230
12231       tmp[0] = op0; tmp[1] = op1;
12232       ix86_expand_vector_move_misalign (mode, tmp);
12233       return;
12234     }
12235
12236   /* Make operand1 a register if it isn't already.  */
12237   if (can_create_pseudo_p ()
12238       && !register_operand (op0, mode)
12239       && !register_operand (op1, mode))
12240     {
12241       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
12242       return;
12243     }
12244
12245   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12246 }
12247
12248 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
12249    straight to ix86_expand_vector_move.  */
12250 /* Code generation for scalar reg-reg moves of single and double precision data:
12251      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
12252        movaps reg, reg
12253      else
12254        movss reg, reg
12255      if (x86_sse_partial_reg_dependency == true)
12256        movapd reg, reg
12257      else
12258        movsd reg, reg
12259
12260    Code generation for scalar loads of double precision data:
12261      if (x86_sse_split_regs == true)
12262        movlpd mem, reg      (gas syntax)
12263      else
12264        movsd mem, reg
12265
12266    Code generation for unaligned packed loads of single precision data
12267    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
12268      if (x86_sse_unaligned_move_optimal)
12269        movups mem, reg
12270
12271      if (x86_sse_partial_reg_dependency == true)
12272        {
12273          xorps  reg, reg
12274          movlps mem, reg
12275          movhps mem+8, reg
12276        }
12277      else
12278        {
12279          movlps mem, reg
12280          movhps mem+8, reg
12281        }
12282
12283    Code generation for unaligned packed loads of double precision data
12284    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
12285      if (x86_sse_unaligned_move_optimal)
12286        movupd mem, reg
12287
12288      if (x86_sse_split_regs == true)
12289        {
12290          movlpd mem, reg
12291          movhpd mem+8, reg
12292        }
12293      else
12294        {
12295          movsd  mem, reg
12296          movhpd mem+8, reg
12297        }
12298  */
12299
12300 void
12301 ix86_expand_vector_move_misalign (enum machine_mode mode, rtx operands[])
12302 {
12303   rtx op0, op1, m;
12304
12305   op0 = operands[0];
12306   op1 = operands[1];
12307
12308   if (TARGET_AVX)
12309     {
12310       switch (GET_MODE_CLASS (mode))
12311         {
12312         case MODE_VECTOR_INT:
12313         case MODE_INT:
12314           switch (GET_MODE_SIZE (mode))
12315             {
12316             case 16:
12317               op0 = gen_lowpart (V16QImode, op0);
12318               op1 = gen_lowpart (V16QImode, op1);
12319               emit_insn (gen_avx_movdqu (op0, op1));
12320               break;
12321             case 32:
12322               op0 = gen_lowpart (V32QImode, op0);
12323               op1 = gen_lowpart (V32QImode, op1);
12324               emit_insn (gen_avx_movdqu256 (op0, op1));
12325               break;
12326             default:
12327               gcc_unreachable ();
12328             }
12329           break;
12330         case MODE_VECTOR_FLOAT:
12331           op0 = gen_lowpart (mode, op0);
12332           op1 = gen_lowpart (mode, op1);
12333
12334           switch (mode)
12335             { 
12336             case V4SFmode:
12337               emit_insn (gen_avx_movups (op0, op1));
12338               break;
12339             case V8SFmode:
12340               emit_insn (gen_avx_movups256 (op0, op1));
12341               break;
12342             case V2DFmode:
12343               emit_insn (gen_avx_movupd (op0, op1));
12344               break;
12345             case V4DFmode:
12346               emit_insn (gen_avx_movupd256 (op0, op1));
12347               break;
12348             default:
12349               gcc_unreachable ();
12350             }
12351           break;
12352
12353         default:
12354           gcc_unreachable ();
12355         }
12356
12357       return;
12358     }
12359
12360   if (MEM_P (op1))
12361     {
12362       /* If we're optimizing for size, movups is the smallest.  */
12363       if (optimize_insn_for_size_p ())
12364         {
12365           op0 = gen_lowpart (V4SFmode, op0);
12366           op1 = gen_lowpart (V4SFmode, op1);
12367           emit_insn (gen_sse_movups (op0, op1));
12368           return;
12369         }
12370
12371       /* ??? If we have typed data, then it would appear that using
12372          movdqu is the only way to get unaligned data loaded with
12373          integer type.  */
12374       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12375         {
12376           op0 = gen_lowpart (V16QImode, op0);
12377           op1 = gen_lowpart (V16QImode, op1);
12378           emit_insn (gen_sse2_movdqu (op0, op1));
12379           return;
12380         }
12381
12382       if (TARGET_SSE2 && mode == V2DFmode)
12383         {
12384           rtx zero;
12385
12386           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12387             {
12388               op0 = gen_lowpart (V2DFmode, op0);
12389               op1 = gen_lowpart (V2DFmode, op1);
12390               emit_insn (gen_sse2_movupd (op0, op1));
12391               return;
12392             }
12393
12394           /* When SSE registers are split into halves, we can avoid
12395              writing to the top half twice.  */
12396           if (TARGET_SSE_SPLIT_REGS)
12397             {
12398               emit_clobber (op0);
12399               zero = op0;
12400             }
12401           else
12402             {
12403               /* ??? Not sure about the best option for the Intel chips.
12404                  The following would seem to satisfy; the register is
12405                  entirely cleared, breaking the dependency chain.  We
12406                  then store to the upper half, with a dependency depth
12407                  of one.  A rumor has it that Intel recommends two movsd
12408                  followed by an unpacklpd, but this is unconfirmed.  And
12409                  given that the dependency depth of the unpacklpd would
12410                  still be one, I'm not sure why this would be better.  */
12411               zero = CONST0_RTX (V2DFmode);
12412             }
12413
12414           m = adjust_address (op1, DFmode, 0);
12415           emit_insn (gen_sse2_loadlpd (op0, zero, m));
12416           m = adjust_address (op1, DFmode, 8);
12417           emit_insn (gen_sse2_loadhpd (op0, op0, m));
12418         }
12419       else
12420         {
12421           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12422             {
12423               op0 = gen_lowpart (V4SFmode, op0);
12424               op1 = gen_lowpart (V4SFmode, op1);
12425               emit_insn (gen_sse_movups (op0, op1));
12426               return;
12427             }
12428
12429           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
12430             emit_move_insn (op0, CONST0_RTX (mode));
12431           else
12432             emit_clobber (op0);
12433
12434           if (mode != V4SFmode)
12435             op0 = gen_lowpart (V4SFmode, op0);
12436           m = adjust_address (op1, V2SFmode, 0);
12437           emit_insn (gen_sse_loadlps (op0, op0, m));
12438           m = adjust_address (op1, V2SFmode, 8);
12439           emit_insn (gen_sse_loadhps (op0, op0, m));
12440         }
12441     }
12442   else if (MEM_P (op0))
12443     {
12444       /* If we're optimizing for size, movups is the smallest.  */
12445       if (optimize_insn_for_size_p ())
12446         {
12447           op0 = gen_lowpart (V4SFmode, op0);
12448           op1 = gen_lowpart (V4SFmode, op1);
12449           emit_insn (gen_sse_movups (op0, op1));
12450           return;
12451         }
12452
12453       /* ??? Similar to above, only less clear because of quote
12454          typeless stores unquote.  */
12455       if (TARGET_SSE2 && !TARGET_SSE_TYPELESS_STORES
12456           && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12457         {
12458           op0 = gen_lowpart (V16QImode, op0);
12459           op1 = gen_lowpart (V16QImode, op1);
12460           emit_insn (gen_sse2_movdqu (op0, op1));
12461           return;
12462         }
12463
12464       if (TARGET_SSE2 && mode == V2DFmode)
12465         {
12466           m = adjust_address (op0, DFmode, 0);
12467           emit_insn (gen_sse2_storelpd (m, op1));
12468           m = adjust_address (op0, DFmode, 8);
12469           emit_insn (gen_sse2_storehpd (m, op1));
12470         }
12471       else
12472         {
12473           if (mode != V4SFmode)
12474             op1 = gen_lowpart (V4SFmode, op1);
12475           m = adjust_address (op0, V2SFmode, 0);
12476           emit_insn (gen_sse_storelps (m, op1));
12477           m = adjust_address (op0, V2SFmode, 8);
12478           emit_insn (gen_sse_storehps (m, op1));
12479         }
12480     }
12481   else
12482     gcc_unreachable ();
12483 }
12484
12485 /* Expand a push in MODE.  This is some mode for which we do not support
12486    proper push instructions, at least from the registers that we expect
12487    the value to live in.  */
12488
12489 void
12490 ix86_expand_push (enum machine_mode mode, rtx x)
12491 {
12492   rtx tmp;
12493
12494   tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
12495                              GEN_INT (-GET_MODE_SIZE (mode)),
12496                              stack_pointer_rtx, 1, OPTAB_DIRECT);
12497   if (tmp != stack_pointer_rtx)
12498     emit_move_insn (stack_pointer_rtx, tmp);
12499
12500   tmp = gen_rtx_MEM (mode, stack_pointer_rtx);
12501   emit_move_insn (tmp, x);
12502 }
12503
12504 /* Helper function of ix86_fixup_binary_operands to canonicalize
12505    operand order.  Returns true if the operands should be swapped.  */
12506
12507 static bool
12508 ix86_swap_binary_operands_p (enum rtx_code code, enum machine_mode mode,
12509                              rtx operands[])
12510 {
12511   rtx dst = operands[0];
12512   rtx src1 = operands[1];
12513   rtx src2 = operands[2];
12514
12515   /* If the operation is not commutative, we can't do anything.  */
12516   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
12517     return false;
12518
12519   /* Highest priority is that src1 should match dst.  */
12520   if (rtx_equal_p (dst, src1))
12521     return false;
12522   if (rtx_equal_p (dst, src2))
12523     return true;
12524
12525   /* Next highest priority is that immediate constants come second.  */
12526   if (immediate_operand (src2, mode))
12527     return false;
12528   if (immediate_operand (src1, mode))
12529     return true;
12530
12531   /* Lowest priority is that memory references should come second.  */
12532   if (MEM_P (src2))
12533     return false;
12534   if (MEM_P (src1))
12535     return true;
12536
12537   return false;
12538 }
12539
12540
12541 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
12542    destination to use for the operation.  If different from the true
12543    destination in operands[0], a copy operation will be required.  */
12544
12545 rtx
12546 ix86_fixup_binary_operands (enum rtx_code code, enum machine_mode mode,
12547                             rtx operands[])
12548 {
12549   rtx dst = operands[0];
12550   rtx src1 = operands[1];
12551   rtx src2 = operands[2];
12552
12553   /* Canonicalize operand order.  */
12554   if (ix86_swap_binary_operands_p (code, mode, operands))
12555     {
12556       rtx temp;
12557
12558       /* It is invalid to swap operands of different modes.  */
12559       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
12560
12561       temp = src1;
12562       src1 = src2;
12563       src2 = temp;
12564     }
12565
12566   /* Both source operands cannot be in memory.  */
12567   if (MEM_P (src1) && MEM_P (src2))
12568     {
12569       /* Optimization: Only read from memory once.  */
12570       if (rtx_equal_p (src1, src2))
12571         {
12572           src2 = force_reg (mode, src2);
12573           src1 = src2;
12574         }
12575       else
12576         src2 = force_reg (mode, src2);
12577     }
12578
12579   /* If the destination is memory, and we do not have matching source
12580      operands, do things in registers.  */
12581   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12582     dst = gen_reg_rtx (mode);
12583
12584   /* Source 1 cannot be a constant.  */
12585   if (CONSTANT_P (src1))
12586     src1 = force_reg (mode, src1);
12587
12588   /* Source 1 cannot be a non-matching memory.  */
12589   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12590     src1 = force_reg (mode, src1);
12591
12592   operands[1] = src1;
12593   operands[2] = src2;
12594   return dst;
12595 }
12596
12597 /* Similarly, but assume that the destination has already been
12598    set up properly.  */
12599
12600 void
12601 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
12602                                     enum machine_mode mode, rtx operands[])
12603 {
12604   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
12605   gcc_assert (dst == operands[0]);
12606 }
12607
12608 /* Attempt to expand a binary operator.  Make the expansion closer to the
12609    actual machine, then just general_operand, which will allow 3 separate
12610    memory references (one output, two input) in a single insn.  */
12611
12612 void
12613 ix86_expand_binary_operator (enum rtx_code code, enum machine_mode mode,
12614                              rtx operands[])
12615 {
12616   rtx src1, src2, dst, op, clob;
12617
12618   dst = ix86_fixup_binary_operands (code, mode, operands);
12619   src1 = operands[1];
12620   src2 = operands[2];
12621
12622  /* Emit the instruction.  */
12623
12624   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
12625   if (reload_in_progress)
12626     {
12627       /* Reload doesn't know about the flags register, and doesn't know that
12628          it doesn't want to clobber it.  We can only do this with PLUS.  */
12629       gcc_assert (code == PLUS);
12630       emit_insn (op);
12631     }
12632   else
12633     {
12634       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12635       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12636     }
12637
12638   /* Fix up the destination if needed.  */
12639   if (dst != operands[0])
12640     emit_move_insn (operands[0], dst);
12641 }
12642
12643 /* Return TRUE or FALSE depending on whether the binary operator meets the
12644    appropriate constraints.  */
12645
12646 int
12647 ix86_binary_operator_ok (enum rtx_code code, enum machine_mode mode,
12648                          rtx operands[3])
12649 {
12650   rtx dst = operands[0];
12651   rtx src1 = operands[1];
12652   rtx src2 = operands[2];
12653
12654   /* Both source operands cannot be in memory.  */
12655   if (MEM_P (src1) && MEM_P (src2))
12656     return 0;
12657
12658   /* Canonicalize operand order for commutative operators.  */
12659   if (ix86_swap_binary_operands_p (code, mode, operands))
12660     {
12661       rtx temp = src1;
12662       src1 = src2;
12663       src2 = temp;
12664     }
12665
12666   /* If the destination is memory, we must have a matching source operand.  */
12667   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12668       return 0;
12669
12670   /* Source 1 cannot be a constant.  */
12671   if (CONSTANT_P (src1))
12672     return 0;
12673
12674   /* Source 1 cannot be a non-matching memory.  */
12675   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12676     return 0;
12677
12678   return 1;
12679 }
12680
12681 /* Attempt to expand a unary operator.  Make the expansion closer to the
12682    actual machine, then just general_operand, which will allow 2 separate
12683    memory references (one output, one input) in a single insn.  */
12684
12685 void
12686 ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode,
12687                             rtx operands[])
12688 {
12689   int matching_memory;
12690   rtx src, dst, op, clob;
12691
12692   dst = operands[0];
12693   src = operands[1];
12694
12695   /* If the destination is memory, and we do not have matching source
12696      operands, do things in registers.  */
12697   matching_memory = 0;
12698   if (MEM_P (dst))
12699     {
12700       if (rtx_equal_p (dst, src))
12701         matching_memory = 1;
12702       else
12703         dst = gen_reg_rtx (mode);
12704     }
12705
12706   /* When source operand is memory, destination must match.  */
12707   if (MEM_P (src) && !matching_memory)
12708     src = force_reg (mode, src);
12709
12710   /* Emit the instruction.  */
12711
12712   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
12713   if (reload_in_progress || code == NOT)
12714     {
12715       /* Reload doesn't know about the flags register, and doesn't know that
12716          it doesn't want to clobber it.  */
12717       gcc_assert (code == NOT);
12718       emit_insn (op);
12719     }
12720   else
12721     {
12722       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12723       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12724     }
12725
12726   /* Fix up the destination if needed.  */
12727   if (dst != operands[0])
12728     emit_move_insn (operands[0], dst);
12729 }
12730
12731 /* Return TRUE or FALSE depending on whether the unary operator meets the
12732    appropriate constraints.  */
12733
12734 int
12735 ix86_unary_operator_ok (enum rtx_code code ATTRIBUTE_UNUSED,
12736                         enum machine_mode mode ATTRIBUTE_UNUSED,
12737                         rtx operands[2] ATTRIBUTE_UNUSED)
12738 {
12739   /* If one of operands is memory, source and destination must match.  */
12740   if ((MEM_P (operands[0])
12741        || MEM_P (operands[1]))
12742       && ! rtx_equal_p (operands[0], operands[1]))
12743     return FALSE;
12744   return TRUE;
12745 }
12746
12747 /* Post-reload splitter for converting an SF or DFmode value in an
12748    SSE register into an unsigned SImode.  */
12749
12750 void
12751 ix86_split_convert_uns_si_sse (rtx operands[])
12752 {
12753   enum machine_mode vecmode;
12754   rtx value, large, zero_or_two31, input, two31, x;
12755
12756   large = operands[1];
12757   zero_or_two31 = operands[2];
12758   input = operands[3];
12759   two31 = operands[4];
12760   vecmode = GET_MODE (large);
12761   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
12762
12763   /* Load up the value into the low element.  We must ensure that the other
12764      elements are valid floats -- zero is the easiest such value.  */
12765   if (MEM_P (input))
12766     {
12767       if (vecmode == V4SFmode)
12768         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
12769       else
12770         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
12771     }
12772   else
12773     {
12774       input = gen_rtx_REG (vecmode, REGNO (input));
12775       emit_move_insn (value, CONST0_RTX (vecmode));
12776       if (vecmode == V4SFmode)
12777         emit_insn (gen_sse_movss (value, value, input));
12778       else
12779         emit_insn (gen_sse2_movsd (value, value, input));
12780     }
12781
12782   emit_move_insn (large, two31);
12783   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
12784
12785   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
12786   emit_insn (gen_rtx_SET (VOIDmode, large, x));
12787
12788   x = gen_rtx_AND (vecmode, zero_or_two31, large);
12789   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
12790
12791   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
12792   emit_insn (gen_rtx_SET (VOIDmode, value, x));
12793
12794   large = gen_rtx_REG (V4SImode, REGNO (large));
12795   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
12796
12797   x = gen_rtx_REG (V4SImode, REGNO (value));
12798   if (vecmode == V4SFmode)
12799     emit_insn (gen_sse2_cvttps2dq (x, value));
12800   else
12801     emit_insn (gen_sse2_cvttpd2dq (x, value));
12802   value = x;
12803
12804   emit_insn (gen_xorv4si3 (value, value, large));
12805 }
12806
12807 /* Convert an unsigned DImode value into a DFmode, using only SSE.
12808    Expects the 64-bit DImode to be supplied in a pair of integral
12809    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
12810    -mfpmath=sse, !optimize_size only.  */
12811
12812 void
12813 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
12814 {
12815   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
12816   rtx int_xmm, fp_xmm;
12817   rtx biases, exponents;
12818   rtx x;
12819
12820   int_xmm = gen_reg_rtx (V4SImode);
12821   if (TARGET_INTER_UNIT_MOVES)
12822     emit_insn (gen_movdi_to_sse (int_xmm, input));
12823   else if (TARGET_SSE_SPLIT_REGS)
12824     {
12825       emit_clobber (int_xmm);
12826       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
12827     }
12828   else
12829     {
12830       x = gen_reg_rtx (V2DImode);
12831       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
12832       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
12833     }
12834
12835   x = gen_rtx_CONST_VECTOR (V4SImode,
12836                             gen_rtvec (4, GEN_INT (0x43300000UL),
12837                                        GEN_INT (0x45300000UL),
12838                                        const0_rtx, const0_rtx));
12839   exponents = validize_mem (force_const_mem (V4SImode, x));
12840
12841   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
12842   emit_insn (gen_sse2_punpckldq (int_xmm, int_xmm, exponents));
12843
12844   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
12845      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
12846      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
12847      (0x1.0p84 + double(fp_value_hi_xmm)).
12848      Note these exponents differ by 32.  */
12849
12850   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
12851
12852   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
12853      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
12854   real_ldexp (&bias_lo_rvt, &dconst1, 52);
12855   real_ldexp (&bias_hi_rvt, &dconst1, 84);
12856   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
12857   x = const_double_from_real_value (bias_hi_rvt, DFmode);
12858   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
12859   biases = validize_mem (force_const_mem (V2DFmode, biases));
12860   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
12861
12862   /* Add the upper and lower DFmode values together.  */
12863   if (TARGET_SSE3)
12864     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
12865   else
12866     {
12867       x = copy_to_mode_reg (V2DFmode, fp_xmm);
12868       emit_insn (gen_sse2_unpckhpd (fp_xmm, fp_xmm, fp_xmm));
12869       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
12870     }
12871
12872   ix86_expand_vector_extract (false, target, fp_xmm, 0);
12873 }
12874
12875 /* Not used, but eases macroization of patterns.  */
12876 void
12877 ix86_expand_convert_uns_sixf_sse (rtx target ATTRIBUTE_UNUSED,
12878                                   rtx input ATTRIBUTE_UNUSED)
12879 {
12880   gcc_unreachable ();
12881 }
12882
12883 /* Convert an unsigned SImode value into a DFmode.  Only currently used
12884    for SSE, but applicable anywhere.  */
12885
12886 void
12887 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
12888 {
12889   REAL_VALUE_TYPE TWO31r;
12890   rtx x, fp;
12891
12892   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
12893                            NULL, 1, OPTAB_DIRECT);
12894
12895   fp = gen_reg_rtx (DFmode);
12896   emit_insn (gen_floatsidf2 (fp, x));
12897
12898   real_ldexp (&TWO31r, &dconst1, 31);
12899   x = const_double_from_real_value (TWO31r, DFmode);
12900
12901   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
12902   if (x != target)
12903     emit_move_insn (target, x);
12904 }
12905
12906 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
12907    32-bit mode; otherwise we have a direct convert instruction.  */
12908
12909 void
12910 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
12911 {
12912   REAL_VALUE_TYPE TWO32r;
12913   rtx fp_lo, fp_hi, x;
12914
12915   fp_lo = gen_reg_rtx (DFmode);
12916   fp_hi = gen_reg_rtx (DFmode);
12917
12918   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
12919
12920   real_ldexp (&TWO32r, &dconst1, 32);
12921   x = const_double_from_real_value (TWO32r, DFmode);
12922   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
12923
12924   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
12925
12926   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
12927                            0, OPTAB_DIRECT);
12928   if (x != target)
12929     emit_move_insn (target, x);
12930 }
12931
12932 /* Convert an unsigned SImode value into a SFmode, using only SSE.
12933    For x86_32, -mfpmath=sse, !optimize_size only.  */
12934 void
12935 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
12936 {
12937   REAL_VALUE_TYPE ONE16r;
12938   rtx fp_hi, fp_lo, int_hi, int_lo, x;
12939
12940   real_ldexp (&ONE16r, &dconst1, 16);
12941   x = const_double_from_real_value (ONE16r, SFmode);
12942   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
12943                                       NULL, 0, OPTAB_DIRECT);
12944   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
12945                                       NULL, 0, OPTAB_DIRECT);
12946   fp_hi = gen_reg_rtx (SFmode);
12947   fp_lo = gen_reg_rtx (SFmode);
12948   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
12949   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
12950   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
12951                                0, OPTAB_DIRECT);
12952   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
12953                                0, OPTAB_DIRECT);
12954   if (!rtx_equal_p (target, fp_hi))
12955     emit_move_insn (target, fp_hi);
12956 }
12957
12958 /* A subroutine of ix86_build_signbit_mask_vector.  If VECT is true,
12959    then replicate the value for all elements of the vector
12960    register.  */
12961
12962 rtx
12963 ix86_build_const_vector (enum machine_mode mode, bool vect, rtx value)
12964 {
12965   rtvec v;
12966   switch (mode)
12967     {
12968     case SImode:
12969       gcc_assert (vect);
12970       v = gen_rtvec (4, value, value, value, value);
12971       return gen_rtx_CONST_VECTOR (V4SImode, v);
12972
12973     case DImode:
12974       gcc_assert (vect);
12975       v = gen_rtvec (2, value, value);
12976       return gen_rtx_CONST_VECTOR (V2DImode, v);
12977
12978     case SFmode:
12979       if (vect)
12980         v = gen_rtvec (4, value, value, value, value);
12981       else
12982         v = gen_rtvec (4, value, CONST0_RTX (SFmode),
12983                        CONST0_RTX (SFmode), CONST0_RTX (SFmode));
12984       return gen_rtx_CONST_VECTOR (V4SFmode, v);
12985
12986     case DFmode:
12987       if (vect)
12988         v = gen_rtvec (2, value, value);
12989       else
12990         v = gen_rtvec (2, value, CONST0_RTX (DFmode));
12991       return gen_rtx_CONST_VECTOR (V2DFmode, v);
12992
12993     default:
12994       gcc_unreachable ();
12995     }
12996 }
12997
12998 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
12999    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
13000    for an SSE register.  If VECT is true, then replicate the mask for
13001    all elements of the vector register.  If INVERT is true, then create
13002    a mask excluding the sign bit.  */
13003
13004 rtx
13005 ix86_build_signbit_mask (enum machine_mode mode, bool vect, bool invert)
13006 {
13007   enum machine_mode vec_mode, imode;
13008   HOST_WIDE_INT hi, lo;
13009   int shift = 63;
13010   rtx v;
13011   rtx mask;
13012
13013   /* Find the sign bit, sign extended to 2*HWI.  */
13014   switch (mode)
13015     {
13016     case SImode:
13017     case SFmode:
13018       imode = SImode;
13019       vec_mode = (mode == SImode) ? V4SImode : V4SFmode;
13020       lo = 0x80000000, hi = lo < 0;
13021       break;
13022
13023     case DImode:
13024     case DFmode:
13025       imode = DImode;
13026       vec_mode = (mode == DImode) ? V2DImode : V2DFmode;
13027       if (HOST_BITS_PER_WIDE_INT >= 64)
13028         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
13029       else
13030         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
13031       break;
13032
13033     case TImode:
13034     case TFmode:
13035       vec_mode = VOIDmode;
13036       if (HOST_BITS_PER_WIDE_INT >= 64)
13037         {
13038           imode = TImode;
13039           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
13040         }
13041       else
13042         {
13043           rtvec vec;
13044
13045           imode = DImode;
13046           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
13047
13048           if (invert)
13049             {
13050               lo = ~lo, hi = ~hi;
13051               v = constm1_rtx;
13052             }
13053           else
13054             v = const0_rtx;
13055
13056           mask = immed_double_const (lo, hi, imode);
13057
13058           vec = gen_rtvec (2, v, mask);
13059           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
13060           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
13061
13062           return v;
13063         }
13064      break;
13065
13066     default:
13067       gcc_unreachable ();
13068     }
13069
13070   if (invert)
13071     lo = ~lo, hi = ~hi;
13072
13073   /* Force this value into the low part of a fp vector constant.  */
13074   mask = immed_double_const (lo, hi, imode);
13075   mask = gen_lowpart (mode, mask);
13076
13077   if (vec_mode == VOIDmode)
13078     return force_reg (mode, mask);
13079
13080   v = ix86_build_const_vector (mode, vect, mask);
13081   return force_reg (vec_mode, v);
13082 }
13083
13084 /* Generate code for floating point ABS or NEG.  */
13085
13086 void
13087 ix86_expand_fp_absneg_operator (enum rtx_code code, enum machine_mode mode,
13088                                 rtx operands[])
13089 {
13090   rtx mask, set, use, clob, dst, src;
13091   bool use_sse = false;
13092   bool vector_mode = VECTOR_MODE_P (mode);
13093   enum machine_mode elt_mode = mode;
13094
13095   if (vector_mode)
13096     {
13097       elt_mode = GET_MODE_INNER (mode);
13098       use_sse = true;
13099     }
13100   else if (mode == TFmode)
13101     use_sse = true;
13102   else if (TARGET_SSE_MATH)
13103     use_sse = SSE_FLOAT_MODE_P (mode);
13104
13105   /* NEG and ABS performed with SSE use bitwise mask operations.
13106      Create the appropriate mask now.  */
13107   if (use_sse)
13108     mask = ix86_build_signbit_mask (elt_mode, vector_mode, code == ABS);
13109   else
13110     mask = NULL_RTX;
13111
13112   dst = operands[0];
13113   src = operands[1];
13114
13115   if (vector_mode)
13116     {
13117       set = gen_rtx_fmt_ee (code == NEG ? XOR : AND, mode, src, mask);
13118       set = gen_rtx_SET (VOIDmode, dst, set);
13119       emit_insn (set);
13120     }
13121   else
13122     {
13123       set = gen_rtx_fmt_e (code, mode, src);
13124       set = gen_rtx_SET (VOIDmode, dst, set);
13125       if (mask)
13126         {
13127           use = gen_rtx_USE (VOIDmode, mask);
13128           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
13129           emit_insn (gen_rtx_PARALLEL (VOIDmode,
13130                                        gen_rtvec (3, set, use, clob)));
13131         }
13132       else
13133         emit_insn (set);
13134     }
13135 }
13136
13137 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
13138
13139 void
13140 ix86_expand_copysign (rtx operands[])
13141 {
13142   enum machine_mode mode;
13143   rtx dest, op0, op1, mask, nmask;
13144
13145   dest = operands[0];
13146   op0 = operands[1];
13147   op1 = operands[2];
13148
13149   mode = GET_MODE (dest);
13150
13151   if (GET_CODE (op0) == CONST_DOUBLE)
13152     {
13153       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
13154
13155       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
13156         op0 = simplify_unary_operation (ABS, mode, op0, mode);
13157
13158       if (mode == SFmode || mode == DFmode)
13159         {
13160           enum machine_mode vmode;
13161
13162           vmode = mode == SFmode ? V4SFmode : V2DFmode;
13163
13164           if (op0 == CONST0_RTX (mode))
13165             op0 = CONST0_RTX (vmode);
13166           else
13167             {
13168               rtvec v;
13169
13170               if (mode == SFmode)
13171                 v = gen_rtvec (4, op0, CONST0_RTX (SFmode),
13172                                CONST0_RTX (SFmode), CONST0_RTX (SFmode));
13173               else
13174                 v = gen_rtvec (2, op0, CONST0_RTX (DFmode));
13175
13176               op0 = force_reg (vmode, gen_rtx_CONST_VECTOR (vmode, v));
13177             }
13178         }
13179       else if (op0 != CONST0_RTX (mode))
13180         op0 = force_reg (mode, op0);
13181
13182       mask = ix86_build_signbit_mask (mode, 0, 0);
13183
13184       if (mode == SFmode)
13185         copysign_insn = gen_copysignsf3_const;
13186       else if (mode == DFmode)
13187         copysign_insn = gen_copysigndf3_const;
13188       else
13189         copysign_insn = gen_copysigntf3_const;
13190
13191         emit_insn (copysign_insn (dest, op0, op1, mask));
13192     }
13193   else
13194     {
13195       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
13196
13197       nmask = ix86_build_signbit_mask (mode, 0, 1);
13198       mask = ix86_build_signbit_mask (mode, 0, 0);
13199
13200       if (mode == SFmode)
13201         copysign_insn = gen_copysignsf3_var;
13202       else if (mode == DFmode)
13203         copysign_insn = gen_copysigndf3_var;
13204       else
13205         copysign_insn = gen_copysigntf3_var;
13206
13207       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
13208     }
13209 }
13210
13211 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
13212    be a constant, and so has already been expanded into a vector constant.  */
13213
13214 void
13215 ix86_split_copysign_const (rtx operands[])
13216 {
13217   enum machine_mode mode, vmode;
13218   rtx dest, op0, op1, mask, x;
13219
13220   dest = operands[0];
13221   op0 = operands[1];
13222   op1 = operands[2];
13223   mask = operands[3];
13224
13225   mode = GET_MODE (dest);
13226   vmode = GET_MODE (mask);
13227
13228   dest = simplify_gen_subreg (vmode, dest, mode, 0);
13229   x = gen_rtx_AND (vmode, dest, mask);
13230   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13231
13232   if (op0 != CONST0_RTX (vmode))
13233     {
13234       x = gen_rtx_IOR (vmode, dest, op0);
13235       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13236     }
13237 }
13238
13239 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
13240    so we have to do two masks.  */
13241
13242 void
13243 ix86_split_copysign_var (rtx operands[])
13244 {
13245   enum machine_mode mode, vmode;
13246   rtx dest, scratch, op0, op1, mask, nmask, x;
13247
13248   dest = operands[0];
13249   scratch = operands[1];
13250   op0 = operands[2];
13251   op1 = operands[3];
13252   nmask = operands[4];
13253   mask = operands[5];
13254
13255   mode = GET_MODE (dest);
13256   vmode = GET_MODE (mask);
13257
13258   if (rtx_equal_p (op0, op1))
13259     {
13260       /* Shouldn't happen often (it's useless, obviously), but when it does
13261          we'd generate incorrect code if we continue below.  */
13262       emit_move_insn (dest, op0);
13263       return;
13264     }
13265
13266   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
13267     {
13268       gcc_assert (REGNO (op1) == REGNO (scratch));
13269
13270       x = gen_rtx_AND (vmode, scratch, mask);
13271       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13272
13273       dest = mask;
13274       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13275       x = gen_rtx_NOT (vmode, dest);
13276       x = gen_rtx_AND (vmode, x, op0);
13277       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13278     }
13279   else
13280     {
13281       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
13282         {
13283           x = gen_rtx_AND (vmode, scratch, mask);
13284         }
13285       else                                              /* alternative 2,4 */
13286         {
13287           gcc_assert (REGNO (mask) == REGNO (scratch));
13288           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
13289           x = gen_rtx_AND (vmode, scratch, op1);
13290         }
13291       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13292
13293       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
13294         {
13295           dest = simplify_gen_subreg (vmode, op0, mode, 0);
13296           x = gen_rtx_AND (vmode, dest, nmask);
13297         }
13298       else                                              /* alternative 3,4 */
13299         {
13300           gcc_assert (REGNO (nmask) == REGNO (dest));
13301           dest = nmask;
13302           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13303           x = gen_rtx_AND (vmode, dest, op0);
13304         }
13305       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13306     }
13307
13308   x = gen_rtx_IOR (vmode, dest, scratch);
13309   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13310 }
13311
13312 /* Return TRUE or FALSE depending on whether the first SET in INSN
13313    has source and destination with matching CC modes, and that the
13314    CC mode is at least as constrained as REQ_MODE.  */
13315
13316 int
13317 ix86_match_ccmode (rtx insn, enum machine_mode req_mode)
13318 {
13319   rtx set;
13320   enum machine_mode set_mode;
13321
13322   set = PATTERN (insn);
13323   if (GET_CODE (set) == PARALLEL)
13324     set = XVECEXP (set, 0, 0);
13325   gcc_assert (GET_CODE (set) == SET);
13326   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
13327
13328   set_mode = GET_MODE (SET_DEST (set));
13329   switch (set_mode)
13330     {
13331     case CCNOmode:
13332       if (req_mode != CCNOmode
13333           && (req_mode != CCmode
13334               || XEXP (SET_SRC (set), 1) != const0_rtx))
13335         return 0;
13336       break;
13337     case CCmode:
13338       if (req_mode == CCGCmode)
13339         return 0;
13340       /* FALLTHRU */
13341     case CCGCmode:
13342       if (req_mode == CCGOCmode || req_mode == CCNOmode)
13343         return 0;
13344       /* FALLTHRU */
13345     case CCGOCmode:
13346       if (req_mode == CCZmode)
13347         return 0;
13348       /* FALLTHRU */
13349     case CCAmode:
13350     case CCCmode:
13351     case CCOmode:
13352     case CCSmode:
13353     case CCZmode:
13354       break;
13355
13356     default:
13357       gcc_unreachable ();
13358     }
13359
13360   return (GET_MODE (SET_SRC (set)) == set_mode);
13361 }
13362
13363 /* Generate insn patterns to do an integer compare of OPERANDS.  */
13364
13365 static rtx
13366 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
13367 {
13368   enum machine_mode cmpmode;
13369   rtx tmp, flags;
13370
13371   cmpmode = SELECT_CC_MODE (code, op0, op1);
13372   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
13373
13374   /* This is very simple, but making the interface the same as in the
13375      FP case makes the rest of the code easier.  */
13376   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
13377   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
13378
13379   /* Return the test that should be put into the flags user, i.e.
13380      the bcc, scc, or cmov instruction.  */
13381   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
13382 }
13383
13384 /* Figure out whether to use ordered or unordered fp comparisons.
13385    Return the appropriate mode to use.  */
13386
13387 enum machine_mode
13388 ix86_fp_compare_mode (enum rtx_code code ATTRIBUTE_UNUSED)
13389 {
13390   /* ??? In order to make all comparisons reversible, we do all comparisons
13391      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
13392      all forms trapping and nontrapping comparisons, we can make inequality
13393      comparisons trapping again, since it results in better code when using
13394      FCOM based compares.  */
13395   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
13396 }
13397
13398 enum machine_mode
13399 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
13400 {
13401   enum machine_mode mode = GET_MODE (op0);
13402
13403   if (SCALAR_FLOAT_MODE_P (mode))
13404     {
13405       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
13406       return ix86_fp_compare_mode (code);
13407     }
13408
13409   switch (code)
13410     {
13411       /* Only zero flag is needed.  */
13412     case EQ:                    /* ZF=0 */
13413     case NE:                    /* ZF!=0 */
13414       return CCZmode;
13415       /* Codes needing carry flag.  */
13416     case GEU:                   /* CF=0 */
13417     case LTU:                   /* CF=1 */
13418       /* Detect overflow checks.  They need just the carry flag.  */
13419       if (GET_CODE (op0) == PLUS
13420           && rtx_equal_p (op1, XEXP (op0, 0)))
13421         return CCCmode;
13422       else
13423         return CCmode;
13424     case GTU:                   /* CF=0 & ZF=0 */
13425     case LEU:                   /* CF=1 | ZF=1 */
13426       /* Detect overflow checks.  They need just the carry flag.  */
13427       if (GET_CODE (op0) == MINUS
13428           && rtx_equal_p (op1, XEXP (op0, 0)))
13429         return CCCmode;
13430       else
13431         return CCmode;
13432       /* Codes possibly doable only with sign flag when
13433          comparing against zero.  */
13434     case GE:                    /* SF=OF   or   SF=0 */
13435     case LT:                    /* SF<>OF  or   SF=1 */
13436       if (op1 == const0_rtx)
13437         return CCGOCmode;
13438       else
13439         /* For other cases Carry flag is not required.  */
13440         return CCGCmode;
13441       /* Codes doable only with sign flag when comparing
13442          against zero, but we miss jump instruction for it
13443          so we need to use relational tests against overflow
13444          that thus needs to be zero.  */
13445     case GT:                    /* ZF=0 & SF=OF */
13446     case LE:                    /* ZF=1 | SF<>OF */
13447       if (op1 == const0_rtx)
13448         return CCNOmode;
13449       else
13450         return CCGCmode;
13451       /* strcmp pattern do (use flags) and combine may ask us for proper
13452          mode.  */
13453     case USE:
13454       return CCmode;
13455     default:
13456       gcc_unreachable ();
13457     }
13458 }
13459
13460 /* Return the fixed registers used for condition codes.  */
13461
13462 static bool
13463 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
13464 {
13465   *p1 = FLAGS_REG;
13466   *p2 = FPSR_REG;
13467   return true;
13468 }
13469
13470 /* If two condition code modes are compatible, return a condition code
13471    mode which is compatible with both.  Otherwise, return
13472    VOIDmode.  */
13473
13474 static enum machine_mode
13475 ix86_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
13476 {
13477   if (m1 == m2)
13478     return m1;
13479
13480   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
13481     return VOIDmode;
13482
13483   if ((m1 == CCGCmode && m2 == CCGOCmode)
13484       || (m1 == CCGOCmode && m2 == CCGCmode))
13485     return CCGCmode;
13486
13487   switch (m1)
13488     {
13489     default:
13490       gcc_unreachable ();
13491
13492     case CCmode:
13493     case CCGCmode:
13494     case CCGOCmode:
13495     case CCNOmode:
13496     case CCAmode:
13497     case CCCmode:
13498     case CCOmode:
13499     case CCSmode:
13500     case CCZmode:
13501       switch (m2)
13502         {
13503         default:
13504           return VOIDmode;
13505
13506         case CCmode:
13507         case CCGCmode:
13508         case CCGOCmode:
13509         case CCNOmode:
13510         case CCAmode:
13511         case CCCmode:
13512         case CCOmode:
13513         case CCSmode:
13514         case CCZmode:
13515           return CCmode;
13516         }
13517
13518     case CCFPmode:
13519     case CCFPUmode:
13520       /* These are only compatible with themselves, which we already
13521          checked above.  */
13522       return VOIDmode;
13523     }
13524 }
13525
13526 /* Split comparison code CODE into comparisons we can do using branch
13527    instructions.  BYPASS_CODE is comparison code for branch that will
13528    branch around FIRST_CODE and SECOND_CODE.  If some of branches
13529    is not required, set value to UNKNOWN.
13530    We never require more than two branches.  */
13531
13532 void
13533 ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *bypass_code,
13534                           enum rtx_code *first_code,
13535                           enum rtx_code *second_code)
13536 {
13537   *first_code = code;
13538   *bypass_code = UNKNOWN;
13539   *second_code = UNKNOWN;
13540
13541   /* The fcomi comparison sets flags as follows:
13542
13543      cmp    ZF PF CF
13544      >      0  0  0
13545      <      0  0  1
13546      =      1  0  0
13547      un     1  1  1 */
13548
13549   switch (code)
13550     {
13551     case GT:                    /* GTU - CF=0 & ZF=0 */
13552     case GE:                    /* GEU - CF=0 */
13553     case ORDERED:               /* PF=0 */
13554     case UNORDERED:             /* PF=1 */
13555     case UNEQ:                  /* EQ - ZF=1 */
13556     case UNLT:                  /* LTU - CF=1 */
13557     case UNLE:                  /* LEU - CF=1 | ZF=1 */
13558     case LTGT:                  /* EQ - ZF=0 */
13559       break;
13560     case LT:                    /* LTU - CF=1 - fails on unordered */
13561       *first_code = UNLT;
13562       *bypass_code = UNORDERED;
13563       break;
13564     case LE:                    /* LEU - CF=1 | ZF=1 - fails on unordered */
13565       *first_code = UNLE;
13566       *bypass_code = UNORDERED;
13567       break;
13568     case EQ:                    /* EQ - ZF=1 - fails on unordered */
13569       *first_code = UNEQ;
13570       *bypass_code = UNORDERED;
13571       break;
13572     case NE:                    /* NE - ZF=0 - fails on unordered */
13573       *first_code = LTGT;
13574       *second_code = UNORDERED;
13575       break;
13576     case UNGE:                  /* GEU - CF=0 - fails on unordered */
13577       *first_code = GE;
13578       *second_code = UNORDERED;
13579       break;
13580     case UNGT:                  /* GTU - CF=0 & ZF=0 - fails on unordered */
13581       *first_code = GT;
13582       *second_code = UNORDERED;
13583       break;
13584     default:
13585       gcc_unreachable ();
13586     }
13587   if (!TARGET_IEEE_FP)
13588     {
13589       *second_code = UNKNOWN;
13590       *bypass_code = UNKNOWN;
13591     }
13592 }
13593
13594 /* Return cost of comparison done fcom + arithmetics operations on AX.
13595    All following functions do use number of instructions as a cost metrics.
13596    In future this should be tweaked to compute bytes for optimize_size and
13597    take into account performance of various instructions on various CPUs.  */
13598 static int
13599 ix86_fp_comparison_arithmetics_cost (enum rtx_code code)
13600 {
13601   if (!TARGET_IEEE_FP)
13602     return 4;
13603   /* The cost of code output by ix86_expand_fp_compare.  */
13604   switch (code)
13605     {
13606     case UNLE:
13607     case UNLT:
13608     case LTGT:
13609     case GT:
13610     case GE:
13611     case UNORDERED:
13612     case ORDERED:
13613     case UNEQ:
13614       return 4;
13615       break;
13616     case LT:
13617     case NE:
13618     case EQ:
13619     case UNGE:
13620       return 5;
13621       break;
13622     case LE:
13623     case UNGT:
13624       return 6;
13625       break;
13626     default:
13627       gcc_unreachable ();
13628     }
13629 }
13630
13631 /* Return cost of comparison done using fcomi operation.
13632    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13633 static int
13634 ix86_fp_comparison_fcomi_cost (enum rtx_code code)
13635 {
13636   enum rtx_code bypass_code, first_code, second_code;
13637   /* Return arbitrarily high cost when instruction is not supported - this
13638      prevents gcc from using it.  */
13639   if (!TARGET_CMOVE)
13640     return 1024;
13641   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13642   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 2;
13643 }
13644
13645 /* Return cost of comparison done using sahf operation.
13646    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13647 static int
13648 ix86_fp_comparison_sahf_cost (enum rtx_code code)
13649 {
13650   enum rtx_code bypass_code, first_code, second_code;
13651   /* Return arbitrarily high cost when instruction is not preferred - this
13652      avoids gcc from using it.  */
13653   if (!(TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ())))
13654     return 1024;
13655   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13656   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 3;
13657 }
13658
13659 /* Compute cost of the comparison done using any method.
13660    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13661 static int
13662 ix86_fp_comparison_cost (enum rtx_code code)
13663 {
13664   int fcomi_cost, sahf_cost, arithmetics_cost = 1024;
13665   int min;
13666
13667   fcomi_cost = ix86_fp_comparison_fcomi_cost (code);
13668   sahf_cost = ix86_fp_comparison_sahf_cost (code);
13669
13670   min = arithmetics_cost = ix86_fp_comparison_arithmetics_cost (code);
13671   if (min > sahf_cost)
13672     min = sahf_cost;
13673   if (min > fcomi_cost)
13674     min = fcomi_cost;
13675   return min;
13676 }
13677
13678 /* Return true if we should use an FCOMI instruction for this
13679    fp comparison.  */
13680
13681 int
13682 ix86_use_fcomi_compare (enum rtx_code code ATTRIBUTE_UNUSED)
13683 {
13684   enum rtx_code swapped_code = swap_condition (code);
13685
13686   return ((ix86_fp_comparison_cost (code)
13687            == ix86_fp_comparison_fcomi_cost (code))
13688           || (ix86_fp_comparison_cost (swapped_code)
13689               == ix86_fp_comparison_fcomi_cost (swapped_code)));
13690 }
13691
13692 /* Swap, force into registers, or otherwise massage the two operands
13693    to a fp comparison.  The operands are updated in place; the new
13694    comparison code is returned.  */
13695
13696 static enum rtx_code
13697 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
13698 {
13699   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
13700   rtx op0 = *pop0, op1 = *pop1;
13701   enum machine_mode op_mode = GET_MODE (op0);
13702   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
13703
13704   /* All of the unordered compare instructions only work on registers.
13705      The same is true of the fcomi compare instructions.  The XFmode
13706      compare instructions require registers except when comparing
13707      against zero or when converting operand 1 from fixed point to
13708      floating point.  */
13709
13710   if (!is_sse
13711       && (fpcmp_mode == CCFPUmode
13712           || (op_mode == XFmode
13713               && ! (standard_80387_constant_p (op0) == 1
13714                     || standard_80387_constant_p (op1) == 1)
13715               && GET_CODE (op1) != FLOAT)
13716           || ix86_use_fcomi_compare (code)))
13717     {
13718       op0 = force_reg (op_mode, op0);
13719       op1 = force_reg (op_mode, op1);
13720     }
13721   else
13722     {
13723       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
13724          things around if they appear profitable, otherwise force op0
13725          into a register.  */
13726
13727       if (standard_80387_constant_p (op0) == 0
13728           || (MEM_P (op0)
13729               && ! (standard_80387_constant_p (op1) == 0
13730                     || MEM_P (op1))))
13731         {
13732           rtx tmp;
13733           tmp = op0, op0 = op1, op1 = tmp;
13734           code = swap_condition (code);
13735         }
13736
13737       if (!REG_P (op0))
13738         op0 = force_reg (op_mode, op0);
13739
13740       if (CONSTANT_P (op1))
13741         {
13742           int tmp = standard_80387_constant_p (op1);
13743           if (tmp == 0)
13744             op1 = validize_mem (force_const_mem (op_mode, op1));
13745           else if (tmp == 1)
13746             {
13747               if (TARGET_CMOVE)
13748                 op1 = force_reg (op_mode, op1);
13749             }
13750           else
13751             op1 = force_reg (op_mode, op1);
13752         }
13753     }
13754
13755   /* Try to rearrange the comparison to make it cheaper.  */
13756   if (ix86_fp_comparison_cost (code)
13757       > ix86_fp_comparison_cost (swap_condition (code))
13758       && (REG_P (op1) || can_create_pseudo_p ()))
13759     {
13760       rtx tmp;
13761       tmp = op0, op0 = op1, op1 = tmp;
13762       code = swap_condition (code);
13763       if (!REG_P (op0))
13764         op0 = force_reg (op_mode, op0);
13765     }
13766
13767   *pop0 = op0;
13768   *pop1 = op1;
13769   return code;
13770 }
13771
13772 /* Convert comparison codes we use to represent FP comparison to integer
13773    code that will result in proper branch.  Return UNKNOWN if no such code
13774    is available.  */
13775
13776 enum rtx_code
13777 ix86_fp_compare_code_to_integer (enum rtx_code code)
13778 {
13779   switch (code)
13780     {
13781     case GT:
13782       return GTU;
13783     case GE:
13784       return GEU;
13785     case ORDERED:
13786     case UNORDERED:
13787       return code;
13788       break;
13789     case UNEQ:
13790       return EQ;
13791       break;
13792     case UNLT:
13793       return LTU;
13794       break;
13795     case UNLE:
13796       return LEU;
13797       break;
13798     case LTGT:
13799       return NE;
13800       break;
13801     default:
13802       return UNKNOWN;
13803     }
13804 }
13805
13806 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
13807
13808 static rtx
13809 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch,
13810                         rtx *second_test, rtx *bypass_test)
13811 {
13812   enum machine_mode fpcmp_mode, intcmp_mode;
13813   rtx tmp, tmp2;
13814   int cost = ix86_fp_comparison_cost (code);
13815   enum rtx_code bypass_code, first_code, second_code;
13816
13817   fpcmp_mode = ix86_fp_compare_mode (code);
13818   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
13819
13820   if (second_test)
13821     *second_test = NULL_RTX;
13822   if (bypass_test)
13823     *bypass_test = NULL_RTX;
13824
13825   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13826
13827   /* Do fcomi/sahf based test when profitable.  */
13828   if (ix86_fp_comparison_arithmetics_cost (code) > cost
13829       && (bypass_code == UNKNOWN || bypass_test)
13830       && (second_code == UNKNOWN || second_test))
13831     {
13832       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13833       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
13834                          tmp);
13835       if (TARGET_CMOVE)
13836         emit_insn (tmp);
13837       else
13838         {
13839           gcc_assert (TARGET_SAHF);
13840
13841           if (!scratch)
13842             scratch = gen_reg_rtx (HImode);
13843           tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
13844
13845           emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
13846         }
13847
13848       /* The FP codes work out to act like unsigned.  */
13849       intcmp_mode = fpcmp_mode;
13850       code = first_code;
13851       if (bypass_code != UNKNOWN)
13852         *bypass_test = gen_rtx_fmt_ee (bypass_code, VOIDmode,
13853                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13854                                        const0_rtx);
13855       if (second_code != UNKNOWN)
13856         *second_test = gen_rtx_fmt_ee (second_code, VOIDmode,
13857                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13858                                        const0_rtx);
13859     }
13860   else
13861     {
13862       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
13863       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13864       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
13865       if (!scratch)
13866         scratch = gen_reg_rtx (HImode);
13867       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
13868
13869       /* In the unordered case, we have to check C2 for NaN's, which
13870          doesn't happen to work out to anything nice combination-wise.
13871          So do some bit twiddling on the value we've got in AH to come
13872          up with an appropriate set of condition codes.  */
13873
13874       intcmp_mode = CCNOmode;
13875       switch (code)
13876         {
13877         case GT:
13878         case UNGT:
13879           if (code == GT || !TARGET_IEEE_FP)
13880             {
13881               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
13882               code = EQ;
13883             }
13884           else
13885             {
13886               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13887               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
13888               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
13889               intcmp_mode = CCmode;
13890               code = GEU;
13891             }
13892           break;
13893         case LT:
13894         case UNLT:
13895           if (code == LT && TARGET_IEEE_FP)
13896             {
13897               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13898               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x01)));
13899               intcmp_mode = CCmode;
13900               code = EQ;
13901             }
13902           else
13903             {
13904               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x01)));
13905               code = NE;
13906             }
13907           break;
13908         case GE:
13909         case UNGE:
13910           if (code == GE || !TARGET_IEEE_FP)
13911             {
13912               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
13913               code = EQ;
13914             }
13915           else
13916             {
13917               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13918               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
13919                                              GEN_INT (0x01)));
13920               code = NE;
13921             }
13922           break;
13923         case LE:
13924         case UNLE:
13925           if (code == LE && TARGET_IEEE_FP)
13926             {
13927               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13928               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
13929               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
13930               intcmp_mode = CCmode;
13931               code = LTU;
13932             }
13933           else
13934             {
13935               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
13936               code = NE;
13937             }
13938           break;
13939         case EQ:
13940         case UNEQ:
13941           if (code == EQ && TARGET_IEEE_FP)
13942             {
13943               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13944               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
13945               intcmp_mode = CCmode;
13946               code = EQ;
13947             }
13948           else
13949             {
13950               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
13951               code = NE;
13952               break;
13953             }
13954           break;
13955         case NE:
13956         case LTGT:
13957           if (code == NE && TARGET_IEEE_FP)
13958             {
13959               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13960               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
13961                                              GEN_INT (0x40)));
13962               code = NE;
13963             }
13964           else
13965             {
13966               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
13967               code = EQ;
13968             }
13969           break;
13970
13971         case UNORDERED:
13972           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
13973           code = NE;
13974           break;
13975         case ORDERED:
13976           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
13977           code = EQ;
13978           break;
13979
13980         default:
13981           gcc_unreachable ();
13982         }
13983     }
13984
13985   /* Return the test that should be put into the flags user, i.e.
13986      the bcc, scc, or cmov instruction.  */
13987   return gen_rtx_fmt_ee (code, VOIDmode,
13988                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
13989                          const0_rtx);
13990 }
13991
13992 rtx
13993 ix86_expand_compare (enum rtx_code code, rtx *second_test, rtx *bypass_test)
13994 {
13995   rtx op0, op1, ret;
13996   op0 = ix86_compare_op0;
13997   op1 = ix86_compare_op1;
13998
13999   if (second_test)
14000     *second_test = NULL_RTX;
14001   if (bypass_test)
14002     *bypass_test = NULL_RTX;
14003
14004   if (ix86_compare_emitted)
14005     {
14006       ret = gen_rtx_fmt_ee (code, VOIDmode, ix86_compare_emitted, const0_rtx);
14007       ix86_compare_emitted = NULL_RTX;
14008     }
14009   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
14010     {
14011       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
14012       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
14013                                     second_test, bypass_test);
14014     }
14015   else
14016     ret = ix86_expand_int_compare (code, op0, op1);
14017
14018   return ret;
14019 }
14020
14021 /* Return true if the CODE will result in nontrivial jump sequence.  */
14022 bool
14023 ix86_fp_jump_nontrivial_p (enum rtx_code code)
14024 {
14025   enum rtx_code bypass_code, first_code, second_code;
14026   if (!TARGET_CMOVE)
14027     return true;
14028   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
14029   return bypass_code != UNKNOWN || second_code != UNKNOWN;
14030 }
14031
14032 void
14033 ix86_expand_branch (enum rtx_code code, rtx label)
14034 {
14035   rtx tmp;
14036
14037   /* If we have emitted a compare insn, go straight to simple.
14038      ix86_expand_compare won't emit anything if ix86_compare_emitted
14039      is non NULL.  */
14040   if (ix86_compare_emitted)
14041     goto simple;
14042
14043   switch (GET_MODE (ix86_compare_op0))
14044     {
14045     case QImode:
14046     case HImode:
14047     case SImode:
14048       simple:
14049       tmp = ix86_expand_compare (code, NULL, NULL);
14050       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
14051                                   gen_rtx_LABEL_REF (VOIDmode, label),
14052                                   pc_rtx);
14053       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
14054       return;
14055
14056     case SFmode:
14057     case DFmode:
14058     case XFmode:
14059       {
14060         rtvec vec;
14061         int use_fcomi;
14062         enum rtx_code bypass_code, first_code, second_code;
14063
14064         code = ix86_prepare_fp_compare_args (code, &ix86_compare_op0,
14065                                              &ix86_compare_op1);
14066
14067         ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
14068
14069         /* Check whether we will use the natural sequence with one jump.  If
14070            so, we can expand jump early.  Otherwise delay expansion by
14071            creating compound insn to not confuse optimizers.  */
14072         if (bypass_code == UNKNOWN && second_code == UNKNOWN)
14073           {
14074             ix86_split_fp_branch (code, ix86_compare_op0, ix86_compare_op1,
14075                                   gen_rtx_LABEL_REF (VOIDmode, label),
14076                                   pc_rtx, NULL_RTX, NULL_RTX);
14077           }
14078         else
14079           {
14080             tmp = gen_rtx_fmt_ee (code, VOIDmode,
14081                                   ix86_compare_op0, ix86_compare_op1);
14082             tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
14083                                         gen_rtx_LABEL_REF (VOIDmode, label),
14084                                         pc_rtx);
14085             tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
14086
14087             use_fcomi = ix86_use_fcomi_compare (code);
14088             vec = rtvec_alloc (3 + !use_fcomi);
14089             RTVEC_ELT (vec, 0) = tmp;
14090             RTVEC_ELT (vec, 1)
14091               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FPSR_REG));
14092             RTVEC_ELT (vec, 2)
14093               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FLAGS_REG));
14094             if (! use_fcomi)
14095               RTVEC_ELT (vec, 3)
14096                 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (HImode));
14097
14098             emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, vec));
14099           }
14100         return;
14101       }
14102
14103     case DImode:
14104       if (TARGET_64BIT)
14105         goto simple;
14106     case TImode:
14107       /* Expand DImode branch into multiple compare+branch.  */
14108       {
14109         rtx lo[2], hi[2], label2;
14110         enum rtx_code code1, code2, code3;
14111         enum machine_mode submode;
14112
14113         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
14114           {
14115             tmp = ix86_compare_op0;
14116             ix86_compare_op0 = ix86_compare_op1;
14117             ix86_compare_op1 = tmp;
14118             code = swap_condition (code);
14119           }
14120         if (GET_MODE (ix86_compare_op0) == DImode)
14121           {
14122             split_di (&ix86_compare_op0, 1, lo+0, hi+0);
14123             split_di (&ix86_compare_op1, 1, lo+1, hi+1);
14124             submode = SImode;
14125           }
14126         else
14127           {
14128             split_ti (&ix86_compare_op0, 1, lo+0, hi+0);
14129             split_ti (&ix86_compare_op1, 1, lo+1, hi+1);
14130             submode = DImode;
14131           }
14132
14133         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
14134            avoid two branches.  This costs one extra insn, so disable when
14135            optimizing for size.  */
14136
14137         if ((code == EQ || code == NE)
14138             && (!optimize_insn_for_size_p ()
14139                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
14140           {
14141             rtx xor0, xor1;
14142
14143             xor1 = hi[0];
14144             if (hi[1] != const0_rtx)
14145               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
14146                                    NULL_RTX, 0, OPTAB_WIDEN);
14147
14148             xor0 = lo[0];
14149             if (lo[1] != const0_rtx)
14150               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
14151                                    NULL_RTX, 0, OPTAB_WIDEN);
14152
14153             tmp = expand_binop (submode, ior_optab, xor1, xor0,
14154                                 NULL_RTX, 0, OPTAB_WIDEN);
14155
14156             ix86_compare_op0 = tmp;
14157             ix86_compare_op1 = const0_rtx;
14158             ix86_expand_branch (code, label);
14159             return;
14160           }
14161
14162         /* Otherwise, if we are doing less-than or greater-or-equal-than,
14163            op1 is a constant and the low word is zero, then we can just
14164            examine the high word.  Similarly for low word -1 and
14165            less-or-equal-than or greater-than.  */
14166
14167         if (CONST_INT_P (hi[1]))
14168           switch (code)
14169             {
14170             case LT: case LTU: case GE: case GEU:
14171               if (lo[1] == const0_rtx)
14172                 {
14173                   ix86_compare_op0 = hi[0];
14174                   ix86_compare_op1 = hi[1];
14175                   ix86_expand_branch (code, label);
14176                   return;
14177                 }
14178               break;
14179             case LE: case LEU: case GT: case GTU:
14180               if (lo[1] == constm1_rtx)
14181                 {
14182                   ix86_compare_op0 = hi[0];
14183                   ix86_compare_op1 = hi[1];
14184                   ix86_expand_branch (code, label);
14185                   return;
14186                 }
14187               break;
14188             default:
14189               break;
14190             }
14191
14192         /* Otherwise, we need two or three jumps.  */
14193
14194         label2 = gen_label_rtx ();
14195
14196         code1 = code;
14197         code2 = swap_condition (code);
14198         code3 = unsigned_condition (code);
14199
14200         switch (code)
14201           {
14202           case LT: case GT: case LTU: case GTU:
14203             break;
14204
14205           case LE:   code1 = LT;  code2 = GT;  break;
14206           case GE:   code1 = GT;  code2 = LT;  break;
14207           case LEU:  code1 = LTU; code2 = GTU; break;
14208           case GEU:  code1 = GTU; code2 = LTU; break;
14209
14210           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
14211           case NE:   code2 = UNKNOWN; break;
14212
14213           default:
14214             gcc_unreachable ();
14215           }
14216
14217         /*
14218          * a < b =>
14219          *    if (hi(a) < hi(b)) goto true;
14220          *    if (hi(a) > hi(b)) goto false;
14221          *    if (lo(a) < lo(b)) goto true;
14222          *  false:
14223          */
14224
14225         ix86_compare_op0 = hi[0];
14226         ix86_compare_op1 = hi[1];
14227
14228         if (code1 != UNKNOWN)
14229           ix86_expand_branch (code1, label);
14230         if (code2 != UNKNOWN)
14231           ix86_expand_branch (code2, label2);
14232
14233         ix86_compare_op0 = lo[0];
14234         ix86_compare_op1 = lo[1];
14235         ix86_expand_branch (code3, label);
14236
14237         if (code2 != UNKNOWN)
14238           emit_label (label2);
14239         return;
14240       }
14241
14242     default:
14243       gcc_unreachable ();
14244     }
14245 }
14246
14247 /* Split branch based on floating point condition.  */
14248 void
14249 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
14250                       rtx target1, rtx target2, rtx tmp, rtx pushed)
14251 {
14252   rtx second, bypass;
14253   rtx label = NULL_RTX;
14254   rtx condition;
14255   int bypass_probability = -1, second_probability = -1, probability = -1;
14256   rtx i;
14257
14258   if (target2 != pc_rtx)
14259     {
14260       rtx tmp = target2;
14261       code = reverse_condition_maybe_unordered (code);
14262       target2 = target1;
14263       target1 = tmp;
14264     }
14265
14266   condition = ix86_expand_fp_compare (code, op1, op2,
14267                                       tmp, &second, &bypass);
14268
14269   /* Remove pushed operand from stack.  */
14270   if (pushed)
14271     ix86_free_from_memory (GET_MODE (pushed));
14272
14273   if (split_branch_probability >= 0)
14274     {
14275       /* Distribute the probabilities across the jumps.
14276          Assume the BYPASS and SECOND to be always test
14277          for UNORDERED.  */
14278       probability = split_branch_probability;
14279
14280       /* Value of 1 is low enough to make no need for probability
14281          to be updated.  Later we may run some experiments and see
14282          if unordered values are more frequent in practice.  */
14283       if (bypass)
14284         bypass_probability = 1;
14285       if (second)
14286         second_probability = 1;
14287     }
14288   if (bypass != NULL_RTX)
14289     {
14290       label = gen_label_rtx ();
14291       i = emit_jump_insn (gen_rtx_SET
14292                           (VOIDmode, pc_rtx,
14293                            gen_rtx_IF_THEN_ELSE (VOIDmode,
14294                                                  bypass,
14295                                                  gen_rtx_LABEL_REF (VOIDmode,
14296                                                                     label),
14297                                                  pc_rtx)));
14298       if (bypass_probability >= 0)
14299         REG_NOTES (i)
14300           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14301                                GEN_INT (bypass_probability),
14302                                REG_NOTES (i));
14303     }
14304   i = emit_jump_insn (gen_rtx_SET
14305                       (VOIDmode, pc_rtx,
14306                        gen_rtx_IF_THEN_ELSE (VOIDmode,
14307                                              condition, target1, target2)));
14308   if (probability >= 0)
14309     REG_NOTES (i)
14310       = gen_rtx_EXPR_LIST (REG_BR_PROB,
14311                            GEN_INT (probability),
14312                            REG_NOTES (i));
14313   if (second != NULL_RTX)
14314     {
14315       i = emit_jump_insn (gen_rtx_SET
14316                           (VOIDmode, pc_rtx,
14317                            gen_rtx_IF_THEN_ELSE (VOIDmode, second, target1,
14318                                                  target2)));
14319       if (second_probability >= 0)
14320         REG_NOTES (i)
14321           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14322                                GEN_INT (second_probability),
14323                                REG_NOTES (i));
14324     }
14325   if (label != NULL_RTX)
14326     emit_label (label);
14327 }
14328
14329 int
14330 ix86_expand_setcc (enum rtx_code code, rtx dest)
14331 {
14332   rtx ret, tmp, tmpreg, equiv;
14333   rtx second_test, bypass_test;
14334
14335   if (GET_MODE (ix86_compare_op0) == (TARGET_64BIT ? TImode : DImode))
14336     return 0; /* FAIL */
14337
14338   gcc_assert (GET_MODE (dest) == QImode);
14339
14340   ret = ix86_expand_compare (code, &second_test, &bypass_test);
14341   PUT_MODE (ret, QImode);
14342
14343   tmp = dest;
14344   tmpreg = dest;
14345
14346   emit_insn (gen_rtx_SET (VOIDmode, tmp, ret));
14347   if (bypass_test || second_test)
14348     {
14349       rtx test = second_test;
14350       int bypass = 0;
14351       rtx tmp2 = gen_reg_rtx (QImode);
14352       if (bypass_test)
14353         {
14354           gcc_assert (!second_test);
14355           test = bypass_test;
14356           bypass = 1;
14357           PUT_CODE (test, reverse_condition_maybe_unordered (GET_CODE (test)));
14358         }
14359       PUT_MODE (test, QImode);
14360       emit_insn (gen_rtx_SET (VOIDmode, tmp2, test));
14361
14362       if (bypass)
14363         emit_insn (gen_andqi3 (tmp, tmpreg, tmp2));
14364       else
14365         emit_insn (gen_iorqi3 (tmp, tmpreg, tmp2));
14366     }
14367
14368   /* Attach a REG_EQUAL note describing the comparison result.  */
14369   if (ix86_compare_op0 && ix86_compare_op1)
14370     {
14371       equiv = simplify_gen_relational (code, QImode,
14372                                        GET_MODE (ix86_compare_op0),
14373                                        ix86_compare_op0, ix86_compare_op1);
14374       set_unique_reg_note (get_last_insn (), REG_EQUAL, equiv);
14375     }
14376
14377   return 1; /* DONE */
14378 }
14379
14380 /* Expand comparison setting or clearing carry flag.  Return true when
14381    successful and set pop for the operation.  */
14382 static bool
14383 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
14384 {
14385   enum machine_mode mode =
14386     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
14387
14388   /* Do not handle DImode compares that go through special path.  */
14389   if (mode == (TARGET_64BIT ? TImode : DImode))
14390     return false;
14391
14392   if (SCALAR_FLOAT_MODE_P (mode))
14393     {
14394       rtx second_test = NULL, bypass_test = NULL;
14395       rtx compare_op, compare_seq;
14396
14397       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
14398
14399       /* Shortcut:  following common codes never translate
14400          into carry flag compares.  */
14401       if (code == EQ || code == NE || code == UNEQ || code == LTGT
14402           || code == ORDERED || code == UNORDERED)
14403         return false;
14404
14405       /* These comparisons require zero flag; swap operands so they won't.  */
14406       if ((code == GT || code == UNLE || code == LE || code == UNGT)
14407           && !TARGET_IEEE_FP)
14408         {
14409           rtx tmp = op0;
14410           op0 = op1;
14411           op1 = tmp;
14412           code = swap_condition (code);
14413         }
14414
14415       /* Try to expand the comparison and verify that we end up with
14416          carry flag based comparison.  This fails to be true only when
14417          we decide to expand comparison using arithmetic that is not
14418          too common scenario.  */
14419       start_sequence ();
14420       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
14421                                            &second_test, &bypass_test);
14422       compare_seq = get_insns ();
14423       end_sequence ();
14424
14425       if (second_test || bypass_test)
14426         return false;
14427
14428       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14429           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14430         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
14431       else
14432         code = GET_CODE (compare_op);
14433
14434       if (code != LTU && code != GEU)
14435         return false;
14436
14437       emit_insn (compare_seq);
14438       *pop = compare_op;
14439       return true;
14440     }
14441
14442   if (!INTEGRAL_MODE_P (mode))
14443     return false;
14444
14445   switch (code)
14446     {
14447     case LTU:
14448     case GEU:
14449       break;
14450
14451     /* Convert a==0 into (unsigned)a<1.  */
14452     case EQ:
14453     case NE:
14454       if (op1 != const0_rtx)
14455         return false;
14456       op1 = const1_rtx;
14457       code = (code == EQ ? LTU : GEU);
14458       break;
14459
14460     /* Convert a>b into b<a or a>=b-1.  */
14461     case GTU:
14462     case LEU:
14463       if (CONST_INT_P (op1))
14464         {
14465           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
14466           /* Bail out on overflow.  We still can swap operands but that
14467              would force loading of the constant into register.  */
14468           if (op1 == const0_rtx
14469               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
14470             return false;
14471           code = (code == GTU ? GEU : LTU);
14472         }
14473       else
14474         {
14475           rtx tmp = op1;
14476           op1 = op0;
14477           op0 = tmp;
14478           code = (code == GTU ? LTU : GEU);
14479         }
14480       break;
14481
14482     /* Convert a>=0 into (unsigned)a<0x80000000.  */
14483     case LT:
14484     case GE:
14485       if (mode == DImode || op1 != const0_rtx)
14486         return false;
14487       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14488       code = (code == LT ? GEU : LTU);
14489       break;
14490     case LE:
14491     case GT:
14492       if (mode == DImode || op1 != constm1_rtx)
14493         return false;
14494       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14495       code = (code == LE ? GEU : LTU);
14496       break;
14497
14498     default:
14499       return false;
14500     }
14501   /* Swapping operands may cause constant to appear as first operand.  */
14502   if (!nonimmediate_operand (op0, VOIDmode))
14503     {
14504       if (!can_create_pseudo_p ())
14505         return false;
14506       op0 = force_reg (mode, op0);
14507     }
14508   ix86_compare_op0 = op0;
14509   ix86_compare_op1 = op1;
14510   *pop = ix86_expand_compare (code, NULL, NULL);
14511   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
14512   return true;
14513 }
14514
14515 int
14516 ix86_expand_int_movcc (rtx operands[])
14517 {
14518   enum rtx_code code = GET_CODE (operands[1]), compare_code;
14519   rtx compare_seq, compare_op;
14520   rtx second_test, bypass_test;
14521   enum machine_mode mode = GET_MODE (operands[0]);
14522   bool sign_bit_compare_p = false;;
14523
14524   start_sequence ();
14525   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
14526   compare_seq = get_insns ();
14527   end_sequence ();
14528
14529   compare_code = GET_CODE (compare_op);
14530
14531   if ((ix86_compare_op1 == const0_rtx && (code == GE || code == LT))
14532       || (ix86_compare_op1 == constm1_rtx && (code == GT || code == LE)))
14533     sign_bit_compare_p = true;
14534
14535   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
14536      HImode insns, we'd be swallowed in word prefix ops.  */
14537
14538   if ((mode != HImode || TARGET_FAST_PREFIX)
14539       && (mode != (TARGET_64BIT ? TImode : DImode))
14540       && CONST_INT_P (operands[2])
14541       && CONST_INT_P (operands[3]))
14542     {
14543       rtx out = operands[0];
14544       HOST_WIDE_INT ct = INTVAL (operands[2]);
14545       HOST_WIDE_INT cf = INTVAL (operands[3]);
14546       HOST_WIDE_INT diff;
14547
14548       diff = ct - cf;
14549       /*  Sign bit compares are better done using shifts than we do by using
14550           sbb.  */
14551       if (sign_bit_compare_p
14552           || ix86_expand_carry_flag_compare (code, ix86_compare_op0,
14553                                              ix86_compare_op1, &compare_op))
14554         {
14555           /* Detect overlap between destination and compare sources.  */
14556           rtx tmp = out;
14557
14558           if (!sign_bit_compare_p)
14559             {
14560               bool fpcmp = false;
14561
14562               compare_code = GET_CODE (compare_op);
14563
14564               if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14565                   || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14566                 {
14567                   fpcmp = true;
14568                   compare_code = ix86_fp_compare_code_to_integer (compare_code);
14569                 }
14570
14571               /* To simplify rest of code, restrict to the GEU case.  */
14572               if (compare_code == LTU)
14573                 {
14574                   HOST_WIDE_INT tmp = ct;
14575                   ct = cf;
14576                   cf = tmp;
14577                   compare_code = reverse_condition (compare_code);
14578                   code = reverse_condition (code);
14579                 }
14580               else
14581                 {
14582                   if (fpcmp)
14583                     PUT_CODE (compare_op,
14584                               reverse_condition_maybe_unordered
14585                                 (GET_CODE (compare_op)));
14586                   else
14587                     PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
14588                 }
14589               diff = ct - cf;
14590
14591               if (reg_overlap_mentioned_p (out, ix86_compare_op0)
14592                   || reg_overlap_mentioned_p (out, ix86_compare_op1))
14593                 tmp = gen_reg_rtx (mode);
14594
14595               if (mode == DImode)
14596                 emit_insn (gen_x86_movdicc_0_m1_rex64 (tmp, compare_op));
14597               else
14598                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp), compare_op));
14599             }
14600           else
14601             {
14602               if (code == GT || code == GE)
14603                 code = reverse_condition (code);
14604               else
14605                 {
14606                   HOST_WIDE_INT tmp = ct;
14607                   ct = cf;
14608                   cf = tmp;
14609                   diff = ct - cf;
14610                 }
14611               tmp = emit_store_flag (tmp, code, ix86_compare_op0,
14612                                      ix86_compare_op1, VOIDmode, 0, -1);
14613             }
14614
14615           if (diff == 1)
14616             {
14617               /*
14618                * cmpl op0,op1
14619                * sbbl dest,dest
14620                * [addl dest, ct]
14621                *
14622                * Size 5 - 8.
14623                */
14624               if (ct)
14625                 tmp = expand_simple_binop (mode, PLUS,
14626                                            tmp, GEN_INT (ct),
14627                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14628             }
14629           else if (cf == -1)
14630             {
14631               /*
14632                * cmpl op0,op1
14633                * sbbl dest,dest
14634                * orl $ct, dest
14635                *
14636                * Size 8.
14637                */
14638               tmp = expand_simple_binop (mode, IOR,
14639                                          tmp, GEN_INT (ct),
14640                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14641             }
14642           else if (diff == -1 && ct)
14643             {
14644               /*
14645                * cmpl op0,op1
14646                * sbbl dest,dest
14647                * notl dest
14648                * [addl dest, cf]
14649                *
14650                * Size 8 - 11.
14651                */
14652               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14653               if (cf)
14654                 tmp = expand_simple_binop (mode, PLUS,
14655                                            copy_rtx (tmp), GEN_INT (cf),
14656                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14657             }
14658           else
14659             {
14660               /*
14661                * cmpl op0,op1
14662                * sbbl dest,dest
14663                * [notl dest]
14664                * andl cf - ct, dest
14665                * [addl dest, ct]
14666                *
14667                * Size 8 - 11.
14668                */
14669
14670               if (cf == 0)
14671                 {
14672                   cf = ct;
14673                   ct = 0;
14674                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14675                 }
14676
14677               tmp = expand_simple_binop (mode, AND,
14678                                          copy_rtx (tmp),
14679                                          gen_int_mode (cf - ct, mode),
14680                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14681               if (ct)
14682                 tmp = expand_simple_binop (mode, PLUS,
14683                                            copy_rtx (tmp), GEN_INT (ct),
14684                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14685             }
14686
14687           if (!rtx_equal_p (tmp, out))
14688             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
14689
14690           return 1; /* DONE */
14691         }
14692
14693       if (diff < 0)
14694         {
14695           enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14696
14697           HOST_WIDE_INT tmp;
14698           tmp = ct, ct = cf, cf = tmp;
14699           diff = -diff;
14700
14701           if (SCALAR_FLOAT_MODE_P (cmp_mode))
14702             {
14703               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14704
14705               /* We may be reversing unordered compare to normal compare, that
14706                  is not valid in general (we may convert non-trapping condition
14707                  to trapping one), however on i386 we currently emit all
14708                  comparisons unordered.  */
14709               compare_code = reverse_condition_maybe_unordered (compare_code);
14710               code = reverse_condition_maybe_unordered (code);
14711             }
14712           else
14713             {
14714               compare_code = reverse_condition (compare_code);
14715               code = reverse_condition (code);
14716             }
14717         }
14718
14719       compare_code = UNKNOWN;
14720       if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_INT
14721           && CONST_INT_P (ix86_compare_op1))
14722         {
14723           if (ix86_compare_op1 == const0_rtx
14724               && (code == LT || code == GE))
14725             compare_code = code;
14726           else if (ix86_compare_op1 == constm1_rtx)
14727             {
14728               if (code == LE)
14729                 compare_code = LT;
14730               else if (code == GT)
14731                 compare_code = GE;
14732             }
14733         }
14734
14735       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
14736       if (compare_code != UNKNOWN
14737           && GET_MODE (ix86_compare_op0) == GET_MODE (out)
14738           && (cf == -1 || ct == -1))
14739         {
14740           /* If lea code below could be used, only optimize
14741              if it results in a 2 insn sequence.  */
14742
14743           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
14744                  || diff == 3 || diff == 5 || diff == 9)
14745               || (compare_code == LT && ct == -1)
14746               || (compare_code == GE && cf == -1))
14747             {
14748               /*
14749                * notl op1       (if necessary)
14750                * sarl $31, op1
14751                * orl cf, op1
14752                */
14753               if (ct != -1)
14754                 {
14755                   cf = ct;
14756                   ct = -1;
14757                   code = reverse_condition (code);
14758                 }
14759
14760               out = emit_store_flag (out, code, ix86_compare_op0,
14761                                      ix86_compare_op1, VOIDmode, 0, -1);
14762
14763               out = expand_simple_binop (mode, IOR,
14764                                          out, GEN_INT (cf),
14765                                          out, 1, OPTAB_DIRECT);
14766               if (out != operands[0])
14767                 emit_move_insn (operands[0], out);
14768
14769               return 1; /* DONE */
14770             }
14771         }
14772
14773
14774       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
14775            || diff == 3 || diff == 5 || diff == 9)
14776           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
14777           && (mode != DImode
14778               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
14779         {
14780           /*
14781            * xorl dest,dest
14782            * cmpl op1,op2
14783            * setcc dest
14784            * lea cf(dest*(ct-cf)),dest
14785            *
14786            * Size 14.
14787            *
14788            * This also catches the degenerate setcc-only case.
14789            */
14790
14791           rtx tmp;
14792           int nops;
14793
14794           out = emit_store_flag (out, code, ix86_compare_op0,
14795                                  ix86_compare_op1, VOIDmode, 0, 1);
14796
14797           nops = 0;
14798           /* On x86_64 the lea instruction operates on Pmode, so we need
14799              to get arithmetics done in proper mode to match.  */
14800           if (diff == 1)
14801             tmp = copy_rtx (out);
14802           else
14803             {
14804               rtx out1;
14805               out1 = copy_rtx (out);
14806               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
14807               nops++;
14808               if (diff & 1)
14809                 {
14810                   tmp = gen_rtx_PLUS (mode, tmp, out1);
14811                   nops++;
14812                 }
14813             }
14814           if (cf != 0)
14815             {
14816               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
14817               nops++;
14818             }
14819           if (!rtx_equal_p (tmp, out))
14820             {
14821               if (nops == 1)
14822                 out = force_operand (tmp, copy_rtx (out));
14823               else
14824                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
14825             }
14826           if (!rtx_equal_p (out, operands[0]))
14827             emit_move_insn (operands[0], copy_rtx (out));
14828
14829           return 1; /* DONE */
14830         }
14831
14832       /*
14833        * General case:                  Jumpful:
14834        *   xorl dest,dest               cmpl op1, op2
14835        *   cmpl op1, op2                movl ct, dest
14836        *   setcc dest                   jcc 1f
14837        *   decl dest                    movl cf, dest
14838        *   andl (cf-ct),dest            1:
14839        *   addl ct,dest
14840        *
14841        * Size 20.                       Size 14.
14842        *
14843        * This is reasonably steep, but branch mispredict costs are
14844        * high on modern cpus, so consider failing only if optimizing
14845        * for space.
14846        */
14847
14848       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14849           && BRANCH_COST (optimize_insn_for_speed_p (),
14850                           false) >= 2)
14851         {
14852           if (cf == 0)
14853             {
14854               enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14855
14856               cf = ct;
14857               ct = 0;
14858
14859               if (SCALAR_FLOAT_MODE_P (cmp_mode))
14860                 {
14861                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14862
14863                   /* We may be reversing unordered compare to normal compare,
14864                      that is not valid in general (we may convert non-trapping
14865                      condition to trapping one), however on i386 we currently
14866                      emit all comparisons unordered.  */
14867                   code = reverse_condition_maybe_unordered (code);
14868                 }
14869               else
14870                 {
14871                   code = reverse_condition (code);
14872                   if (compare_code != UNKNOWN)
14873                     compare_code = reverse_condition (compare_code);
14874                 }
14875             }
14876
14877           if (compare_code != UNKNOWN)
14878             {
14879               /* notl op1       (if needed)
14880                  sarl $31, op1
14881                  andl (cf-ct), op1
14882                  addl ct, op1
14883
14884                  For x < 0 (resp. x <= -1) there will be no notl,
14885                  so if possible swap the constants to get rid of the
14886                  complement.
14887                  True/false will be -1/0 while code below (store flag
14888                  followed by decrement) is 0/-1, so the constants need
14889                  to be exchanged once more.  */
14890
14891               if (compare_code == GE || !cf)
14892                 {
14893                   code = reverse_condition (code);
14894                   compare_code = LT;
14895                 }
14896               else
14897                 {
14898                   HOST_WIDE_INT tmp = cf;
14899                   cf = ct;
14900                   ct = tmp;
14901                 }
14902
14903               out = emit_store_flag (out, code, ix86_compare_op0,
14904                                      ix86_compare_op1, VOIDmode, 0, -1);
14905             }
14906           else
14907             {
14908               out = emit_store_flag (out, code, ix86_compare_op0,
14909                                      ix86_compare_op1, VOIDmode, 0, 1);
14910
14911               out = expand_simple_binop (mode, PLUS, copy_rtx (out), constm1_rtx,
14912                                          copy_rtx (out), 1, OPTAB_DIRECT);
14913             }
14914
14915           out = expand_simple_binop (mode, AND, copy_rtx (out),
14916                                      gen_int_mode (cf - ct, mode),
14917                                      copy_rtx (out), 1, OPTAB_DIRECT);
14918           if (ct)
14919             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
14920                                        copy_rtx (out), 1, OPTAB_DIRECT);
14921           if (!rtx_equal_p (out, operands[0]))
14922             emit_move_insn (operands[0], copy_rtx (out));
14923
14924           return 1; /* DONE */
14925         }
14926     }
14927
14928   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14929     {
14930       /* Try a few things more with specific constants and a variable.  */
14931
14932       optab op;
14933       rtx var, orig_out, out, tmp;
14934
14935       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
14936         return 0; /* FAIL */
14937
14938       /* If one of the two operands is an interesting constant, load a
14939          constant with the above and mask it in with a logical operation.  */
14940
14941       if (CONST_INT_P (operands[2]))
14942         {
14943           var = operands[3];
14944           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
14945             operands[3] = constm1_rtx, op = and_optab;
14946           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
14947             operands[3] = const0_rtx, op = ior_optab;
14948           else
14949             return 0; /* FAIL */
14950         }
14951       else if (CONST_INT_P (operands[3]))
14952         {
14953           var = operands[2];
14954           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
14955             operands[2] = constm1_rtx, op = and_optab;
14956           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
14957             operands[2] = const0_rtx, op = ior_optab;
14958           else
14959             return 0; /* FAIL */
14960         }
14961       else
14962         return 0; /* FAIL */
14963
14964       orig_out = operands[0];
14965       tmp = gen_reg_rtx (mode);
14966       operands[0] = tmp;
14967
14968       /* Recurse to get the constant loaded.  */
14969       if (ix86_expand_int_movcc (operands) == 0)
14970         return 0; /* FAIL */
14971
14972       /* Mask in the interesting variable.  */
14973       out = expand_binop (mode, op, var, tmp, orig_out, 0,
14974                           OPTAB_WIDEN);
14975       if (!rtx_equal_p (out, orig_out))
14976         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
14977
14978       return 1; /* DONE */
14979     }
14980
14981   /*
14982    * For comparison with above,
14983    *
14984    * movl cf,dest
14985    * movl ct,tmp
14986    * cmpl op1,op2
14987    * cmovcc tmp,dest
14988    *
14989    * Size 15.
14990    */
14991
14992   if (! nonimmediate_operand (operands[2], mode))
14993     operands[2] = force_reg (mode, operands[2]);
14994   if (! nonimmediate_operand (operands[3], mode))
14995     operands[3] = force_reg (mode, operands[3]);
14996
14997   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
14998     {
14999       rtx tmp = gen_reg_rtx (mode);
15000       emit_move_insn (tmp, operands[3]);
15001       operands[3] = tmp;
15002     }
15003   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
15004     {
15005       rtx tmp = gen_reg_rtx (mode);
15006       emit_move_insn (tmp, operands[2]);
15007       operands[2] = tmp;
15008     }
15009
15010   if (! register_operand (operands[2], VOIDmode)
15011       && (mode == QImode
15012           || ! register_operand (operands[3], VOIDmode)))
15013     operands[2] = force_reg (mode, operands[2]);
15014
15015   if (mode == QImode
15016       && ! register_operand (operands[3], VOIDmode))
15017     operands[3] = force_reg (mode, operands[3]);
15018
15019   emit_insn (compare_seq);
15020   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15021                           gen_rtx_IF_THEN_ELSE (mode,
15022                                                 compare_op, operands[2],
15023                                                 operands[3])));
15024   if (bypass_test)
15025     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
15026                             gen_rtx_IF_THEN_ELSE (mode,
15027                                   bypass_test,
15028                                   copy_rtx (operands[3]),
15029                                   copy_rtx (operands[0]))));
15030   if (second_test)
15031     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
15032                             gen_rtx_IF_THEN_ELSE (mode,
15033                                   second_test,
15034                                   copy_rtx (operands[2]),
15035                                   copy_rtx (operands[0]))));
15036
15037   return 1; /* DONE */
15038 }
15039
15040 /* Swap, force into registers, or otherwise massage the two operands
15041    to an sse comparison with a mask result.  Thus we differ a bit from
15042    ix86_prepare_fp_compare_args which expects to produce a flags result.
15043
15044    The DEST operand exists to help determine whether to commute commutative
15045    operators.  The POP0/POP1 operands are updated in place.  The new
15046    comparison code is returned, or UNKNOWN if not implementable.  */
15047
15048 static enum rtx_code
15049 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
15050                                   rtx *pop0, rtx *pop1)
15051 {
15052   rtx tmp;
15053
15054   switch (code)
15055     {
15056     case LTGT:
15057     case UNEQ:
15058       /* We have no LTGT as an operator.  We could implement it with
15059          NE & ORDERED, but this requires an extra temporary.  It's
15060          not clear that it's worth it.  */
15061       return UNKNOWN;
15062
15063     case LT:
15064     case LE:
15065     case UNGT:
15066     case UNGE:
15067       /* These are supported directly.  */
15068       break;
15069
15070     case EQ:
15071     case NE:
15072     case UNORDERED:
15073     case ORDERED:
15074       /* For commutative operators, try to canonicalize the destination
15075          operand to be first in the comparison - this helps reload to
15076          avoid extra moves.  */
15077       if (!dest || !rtx_equal_p (dest, *pop1))
15078         break;
15079       /* FALLTHRU */
15080
15081     case GE:
15082     case GT:
15083     case UNLE:
15084     case UNLT:
15085       /* These are not supported directly.  Swap the comparison operands
15086          to transform into something that is supported.  */
15087       tmp = *pop0;
15088       *pop0 = *pop1;
15089       *pop1 = tmp;
15090       code = swap_condition (code);
15091       break;
15092
15093     default:
15094       gcc_unreachable ();
15095     }
15096
15097   return code;
15098 }
15099
15100 /* Detect conditional moves that exactly match min/max operational
15101    semantics.  Note that this is IEEE safe, as long as we don't
15102    interchange the operands.
15103
15104    Returns FALSE if this conditional move doesn't match a MIN/MAX,
15105    and TRUE if the operation is successful and instructions are emitted.  */
15106
15107 static bool
15108 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
15109                            rtx cmp_op1, rtx if_true, rtx if_false)
15110 {
15111   enum machine_mode mode;
15112   bool is_min;
15113   rtx tmp;
15114
15115   if (code == LT)
15116     ;
15117   else if (code == UNGE)
15118     {
15119       tmp = if_true;
15120       if_true = if_false;
15121       if_false = tmp;
15122     }
15123   else
15124     return false;
15125
15126   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
15127     is_min = true;
15128   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
15129     is_min = false;
15130   else
15131     return false;
15132
15133   mode = GET_MODE (dest);
15134
15135   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
15136      but MODE may be a vector mode and thus not appropriate.  */
15137   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
15138     {
15139       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
15140       rtvec v;
15141
15142       if_true = force_reg (mode, if_true);
15143       v = gen_rtvec (2, if_true, if_false);
15144       tmp = gen_rtx_UNSPEC (mode, v, u);
15145     }
15146   else
15147     {
15148       code = is_min ? SMIN : SMAX;
15149       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
15150     }
15151
15152   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
15153   return true;
15154 }
15155
15156 /* Expand an sse vector comparison.  Return the register with the result.  */
15157
15158 static rtx
15159 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
15160                      rtx op_true, rtx op_false)
15161 {
15162   enum machine_mode mode = GET_MODE (dest);
15163   rtx x;
15164
15165   cmp_op0 = force_reg (mode, cmp_op0);
15166   if (!nonimmediate_operand (cmp_op1, mode))
15167     cmp_op1 = force_reg (mode, cmp_op1);
15168
15169   if (optimize
15170       || reg_overlap_mentioned_p (dest, op_true)
15171       || reg_overlap_mentioned_p (dest, op_false))
15172     dest = gen_reg_rtx (mode);
15173
15174   x = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
15175   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15176
15177   return dest;
15178 }
15179
15180 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
15181    operations.  This is used for both scalar and vector conditional moves.  */
15182
15183 static void
15184 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
15185 {
15186   enum machine_mode mode = GET_MODE (dest);
15187   rtx t2, t3, x;
15188
15189   if (op_false == CONST0_RTX (mode))
15190     {
15191       op_true = force_reg (mode, op_true);
15192       x = gen_rtx_AND (mode, cmp, op_true);
15193       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15194     }
15195   else if (op_true == CONST0_RTX (mode))
15196     {
15197       op_false = force_reg (mode, op_false);
15198       x = gen_rtx_NOT (mode, cmp);
15199       x = gen_rtx_AND (mode, x, op_false);
15200       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15201     }
15202   else if (TARGET_SSE5)
15203     {
15204       rtx pcmov = gen_rtx_SET (mode, dest,
15205                                gen_rtx_IF_THEN_ELSE (mode, cmp,
15206                                                      op_true,
15207                                                      op_false));
15208       emit_insn (pcmov);
15209     }
15210   else
15211     {
15212       op_true = force_reg (mode, op_true);
15213       op_false = force_reg (mode, op_false);
15214
15215       t2 = gen_reg_rtx (mode);
15216       if (optimize)
15217         t3 = gen_reg_rtx (mode);
15218       else
15219         t3 = dest;
15220
15221       x = gen_rtx_AND (mode, op_true, cmp);
15222       emit_insn (gen_rtx_SET (VOIDmode, t2, x));
15223
15224       x = gen_rtx_NOT (mode, cmp);
15225       x = gen_rtx_AND (mode, x, op_false);
15226       emit_insn (gen_rtx_SET (VOIDmode, t3, x));
15227
15228       x = gen_rtx_IOR (mode, t3, t2);
15229       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15230     }
15231 }
15232
15233 /* Expand a floating-point conditional move.  Return true if successful.  */
15234
15235 int
15236 ix86_expand_fp_movcc (rtx operands[])
15237 {
15238   enum machine_mode mode = GET_MODE (operands[0]);
15239   enum rtx_code code = GET_CODE (operands[1]);
15240   rtx tmp, compare_op, second_test, bypass_test;
15241
15242   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
15243     {
15244       enum machine_mode cmode;
15245
15246       /* Since we've no cmove for sse registers, don't force bad register
15247          allocation just to gain access to it.  Deny movcc when the
15248          comparison mode doesn't match the move mode.  */
15249       cmode = GET_MODE (ix86_compare_op0);
15250       if (cmode == VOIDmode)
15251         cmode = GET_MODE (ix86_compare_op1);
15252       if (cmode != mode)
15253         return 0;
15254
15255       code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15256                                                &ix86_compare_op0,
15257                                                &ix86_compare_op1);
15258       if (code == UNKNOWN)
15259         return 0;
15260
15261       if (ix86_expand_sse_fp_minmax (operands[0], code, ix86_compare_op0,
15262                                      ix86_compare_op1, operands[2],
15263                                      operands[3]))
15264         return 1;
15265
15266       tmp = ix86_expand_sse_cmp (operands[0], code, ix86_compare_op0,
15267                                  ix86_compare_op1, operands[2], operands[3]);
15268       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
15269       return 1;
15270     }
15271
15272   /* The floating point conditional move instructions don't directly
15273      support conditions resulting from a signed integer comparison.  */
15274
15275   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
15276
15277   /* The floating point conditional move instructions don't directly
15278      support signed integer comparisons.  */
15279
15280   if (!fcmov_comparison_operator (compare_op, VOIDmode))
15281     {
15282       gcc_assert (!second_test && !bypass_test);
15283       tmp = gen_reg_rtx (QImode);
15284       ix86_expand_setcc (code, tmp);
15285       code = NE;
15286       ix86_compare_op0 = tmp;
15287       ix86_compare_op1 = const0_rtx;
15288       compare_op = ix86_expand_compare (code,  &second_test, &bypass_test);
15289     }
15290   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
15291     {
15292       tmp = gen_reg_rtx (mode);
15293       emit_move_insn (tmp, operands[3]);
15294       operands[3] = tmp;
15295     }
15296   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
15297     {
15298       tmp = gen_reg_rtx (mode);
15299       emit_move_insn (tmp, operands[2]);
15300       operands[2] = tmp;
15301     }
15302
15303   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15304                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
15305                                                 operands[2], operands[3])));
15306   if (bypass_test)
15307     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15308                             gen_rtx_IF_THEN_ELSE (mode, bypass_test,
15309                                                   operands[3], operands[0])));
15310   if (second_test)
15311     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15312                             gen_rtx_IF_THEN_ELSE (mode, second_test,
15313                                                   operands[2], operands[0])));
15314
15315   return 1;
15316 }
15317
15318 /* Expand a floating-point vector conditional move; a vcond operation
15319    rather than a movcc operation.  */
15320
15321 bool
15322 ix86_expand_fp_vcond (rtx operands[])
15323 {
15324   enum rtx_code code = GET_CODE (operands[3]);
15325   rtx cmp;
15326
15327   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15328                                            &operands[4], &operands[5]);
15329   if (code == UNKNOWN)
15330     return false;
15331
15332   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
15333                                  operands[5], operands[1], operands[2]))
15334     return true;
15335
15336   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
15337                              operands[1], operands[2]);
15338   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
15339   return true;
15340 }
15341
15342 /* Expand a signed/unsigned integral vector conditional move.  */
15343
15344 bool
15345 ix86_expand_int_vcond (rtx operands[])
15346 {
15347   enum machine_mode mode = GET_MODE (operands[0]);
15348   enum rtx_code code = GET_CODE (operands[3]);
15349   bool negate = false;
15350   rtx x, cop0, cop1;
15351
15352   cop0 = operands[4];
15353   cop1 = operands[5];
15354
15355   /* SSE5 supports all of the comparisons on all vector int types.  */
15356   if (!TARGET_SSE5)
15357     {
15358       /* Canonicalize the comparison to EQ, GT, GTU.  */
15359       switch (code)
15360         {
15361         case EQ:
15362         case GT:
15363         case GTU:
15364           break;
15365
15366         case NE:
15367         case LE:
15368         case LEU:
15369           code = reverse_condition (code);
15370           negate = true;
15371           break;
15372
15373         case GE:
15374         case GEU:
15375           code = reverse_condition (code);
15376           negate = true;
15377           /* FALLTHRU */
15378
15379         case LT:
15380         case LTU:
15381           code = swap_condition (code);
15382           x = cop0, cop0 = cop1, cop1 = x;
15383           break;
15384
15385         default:
15386           gcc_unreachable ();
15387         }
15388
15389       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
15390       if (mode == V2DImode)
15391         {
15392           switch (code)
15393             {
15394             case EQ:
15395               /* SSE4.1 supports EQ.  */
15396               if (!TARGET_SSE4_1)
15397                 return false;
15398               break;
15399
15400             case GT:
15401             case GTU:
15402               /* SSE4.2 supports GT/GTU.  */
15403               if (!TARGET_SSE4_2)
15404                 return false;
15405               break;
15406
15407             default:
15408               gcc_unreachable ();
15409             }
15410         }
15411
15412       /* Unsigned parallel compare is not supported by the hardware.  Play some
15413          tricks to turn this into a signed comparison against 0.  */
15414       if (code == GTU)
15415         {
15416           cop0 = force_reg (mode, cop0);
15417
15418           switch (mode)
15419             {
15420             case V4SImode:
15421             case V2DImode:
15422               {
15423                 rtx t1, t2, mask;
15424
15425                 /* Perform a parallel modulo subtraction.  */
15426                 t1 = gen_reg_rtx (mode);
15427                 emit_insn ((mode == V4SImode
15428                             ? gen_subv4si3
15429                             : gen_subv2di3) (t1, cop0, cop1));
15430
15431                 /* Extract the original sign bit of op0.  */
15432                 mask = ix86_build_signbit_mask (GET_MODE_INNER (mode),
15433                                                 true, false);
15434                 t2 = gen_reg_rtx (mode);
15435                 emit_insn ((mode == V4SImode
15436                             ? gen_andv4si3
15437                             : gen_andv2di3) (t2, cop0, mask));
15438
15439                 /* XOR it back into the result of the subtraction.  This results
15440                    in the sign bit set iff we saw unsigned underflow.  */
15441                 x = gen_reg_rtx (mode);
15442                 emit_insn ((mode == V4SImode
15443                             ? gen_xorv4si3
15444                             : gen_xorv2di3) (x, t1, t2));
15445
15446                 code = GT;
15447               }
15448               break;
15449
15450             case V16QImode:
15451             case V8HImode:
15452               /* Perform a parallel unsigned saturating subtraction.  */
15453               x = gen_reg_rtx (mode);
15454               emit_insn (gen_rtx_SET (VOIDmode, x,
15455                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
15456
15457               code = EQ;
15458               negate = !negate;
15459               break;
15460
15461             default:
15462               gcc_unreachable ();
15463             }
15464
15465           cop0 = x;
15466           cop1 = CONST0_RTX (mode);
15467         }
15468     }
15469
15470   x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
15471                            operands[1+negate], operands[2-negate]);
15472
15473   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
15474                          operands[2-negate]);
15475   return true;
15476 }
15477
15478 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
15479    true if we should do zero extension, else sign extension.  HIGH_P is
15480    true if we want the N/2 high elements, else the low elements.  */
15481
15482 void
15483 ix86_expand_sse_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15484 {
15485   enum machine_mode imode = GET_MODE (operands[1]);
15486   rtx (*unpack)(rtx, rtx, rtx);
15487   rtx se, dest;
15488
15489   switch (imode)
15490     {
15491     case V16QImode:
15492       if (high_p)
15493         unpack = gen_vec_interleave_highv16qi;
15494       else
15495         unpack = gen_vec_interleave_lowv16qi;
15496       break;
15497     case V8HImode:
15498       if (high_p)
15499         unpack = gen_vec_interleave_highv8hi;
15500       else
15501         unpack = gen_vec_interleave_lowv8hi;
15502       break;
15503     case V4SImode:
15504       if (high_p)
15505         unpack = gen_vec_interleave_highv4si;
15506       else
15507         unpack = gen_vec_interleave_lowv4si;
15508       break;
15509     default:
15510       gcc_unreachable ();
15511     }
15512
15513   dest = gen_lowpart (imode, operands[0]);
15514
15515   if (unsigned_p)
15516     se = force_reg (imode, CONST0_RTX (imode));
15517   else
15518     se = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
15519                               operands[1], pc_rtx, pc_rtx);
15520
15521   emit_insn (unpack (dest, operands[1], se));
15522 }
15523
15524 /* This function performs the same task as ix86_expand_sse_unpack,
15525    but with SSE4.1 instructions.  */
15526
15527 void
15528 ix86_expand_sse4_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15529 {
15530   enum machine_mode imode = GET_MODE (operands[1]);
15531   rtx (*unpack)(rtx, rtx);
15532   rtx src, dest;
15533
15534   switch (imode)
15535     {
15536     case V16QImode:
15537       if (unsigned_p)
15538         unpack = gen_sse4_1_zero_extendv8qiv8hi2;
15539       else
15540         unpack = gen_sse4_1_extendv8qiv8hi2;
15541       break;
15542     case V8HImode:
15543       if (unsigned_p)
15544         unpack = gen_sse4_1_zero_extendv4hiv4si2;
15545       else
15546         unpack = gen_sse4_1_extendv4hiv4si2;
15547       break;
15548     case V4SImode:
15549       if (unsigned_p)
15550         unpack = gen_sse4_1_zero_extendv2siv2di2;
15551       else
15552         unpack = gen_sse4_1_extendv2siv2di2;
15553       break;
15554     default:
15555       gcc_unreachable ();
15556     }
15557
15558   dest = operands[0];
15559   if (high_p)
15560     {
15561       /* Shift higher 8 bytes to lower 8 bytes.  */
15562       src = gen_reg_rtx (imode);
15563       emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, src),
15564                                    gen_lowpart (TImode, operands[1]),
15565                                    GEN_INT (64)));
15566     }
15567   else
15568     src = operands[1];
15569
15570   emit_insn (unpack (dest, src));
15571 }
15572
15573 /* This function performs the same task as ix86_expand_sse_unpack,
15574    but with sse5 instructions.  */
15575
15576 void
15577 ix86_expand_sse5_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15578 {
15579   enum machine_mode imode = GET_MODE (operands[1]);
15580   int pperm_bytes[16];
15581   int i;
15582   int h = (high_p) ? 8 : 0;
15583   int h2;
15584   int sign_extend;
15585   rtvec v = rtvec_alloc (16);
15586   rtvec vs;
15587   rtx x, p;
15588   rtx op0 = operands[0], op1 = operands[1];
15589
15590   switch (imode)
15591     {
15592     case V16QImode:
15593       vs = rtvec_alloc (8);
15594       h2 = (high_p) ? 8 : 0;
15595       for (i = 0; i < 8; i++)
15596         {
15597           pperm_bytes[2*i+0] = PPERM_SRC | PPERM_SRC2 | i | h;
15598           pperm_bytes[2*i+1] = ((unsigned_p)
15599                                 ? PPERM_ZERO
15600                                 : PPERM_SIGN | PPERM_SRC2 | i | h);
15601         }
15602
15603       for (i = 0; i < 16; i++)
15604         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15605
15606       for (i = 0; i < 8; i++)
15607         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15608
15609       p = gen_rtx_PARALLEL (VOIDmode, vs);
15610       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15611       if (unsigned_p)
15612         emit_insn (gen_sse5_pperm_zero_v16qi_v8hi (op0, op1, p, x));
15613       else
15614         emit_insn (gen_sse5_pperm_sign_v16qi_v8hi (op0, op1, p, x));
15615       break;
15616
15617     case V8HImode:
15618       vs = rtvec_alloc (4);
15619       h2 = (high_p) ? 4 : 0;
15620       for (i = 0; i < 4; i++)
15621         {
15622           sign_extend = ((unsigned_p)
15623                          ? PPERM_ZERO
15624                          : PPERM_SIGN | PPERM_SRC2 | ((2*i) + 1 + h));
15625           pperm_bytes[4*i+0] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 0 + h);
15626           pperm_bytes[4*i+1] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 1 + h);
15627           pperm_bytes[4*i+2] = sign_extend;
15628           pperm_bytes[4*i+3] = sign_extend;
15629         }
15630
15631       for (i = 0; i < 16; i++)
15632         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15633
15634       for (i = 0; i < 4; i++)
15635         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15636
15637       p = gen_rtx_PARALLEL (VOIDmode, vs);
15638       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15639       if (unsigned_p)
15640         emit_insn (gen_sse5_pperm_zero_v8hi_v4si (op0, op1, p, x));
15641       else
15642         emit_insn (gen_sse5_pperm_sign_v8hi_v4si (op0, op1, p, x));
15643       break;
15644
15645     case V4SImode:
15646       vs = rtvec_alloc (2);
15647       h2 = (high_p) ? 2 : 0;
15648       for (i = 0; i < 2; i++)
15649         {
15650           sign_extend = ((unsigned_p)
15651                          ? PPERM_ZERO
15652                          : PPERM_SIGN | PPERM_SRC2 | ((4*i) + 3 + h));
15653           pperm_bytes[8*i+0] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 0 + h);
15654           pperm_bytes[8*i+1] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 1 + h);
15655           pperm_bytes[8*i+2] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 2 + h);
15656           pperm_bytes[8*i+3] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 3 + h);
15657           pperm_bytes[8*i+4] = sign_extend;
15658           pperm_bytes[8*i+5] = sign_extend;
15659           pperm_bytes[8*i+6] = sign_extend;
15660           pperm_bytes[8*i+7] = sign_extend;
15661         }
15662
15663       for (i = 0; i < 16; i++)
15664         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15665
15666       for (i = 0; i < 2; i++)
15667         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15668
15669       p = gen_rtx_PARALLEL (VOIDmode, vs);
15670       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15671       if (unsigned_p)
15672         emit_insn (gen_sse5_pperm_zero_v4si_v2di (op0, op1, p, x));
15673       else
15674         emit_insn (gen_sse5_pperm_sign_v4si_v2di (op0, op1, p, x));
15675       break;
15676
15677     default:
15678       gcc_unreachable ();
15679     }
15680
15681   return;
15682 }
15683
15684 /* Pack the high bits from OPERANDS[1] and low bits from OPERANDS[2] into the
15685    next narrower integer vector type */
15686 void
15687 ix86_expand_sse5_pack (rtx operands[3])
15688 {
15689   enum machine_mode imode = GET_MODE (operands[0]);
15690   int pperm_bytes[16];
15691   int i;
15692   rtvec v = rtvec_alloc (16);
15693   rtx x;
15694   rtx op0 = operands[0];
15695   rtx op1 = operands[1];
15696   rtx op2 = operands[2];
15697
15698   switch (imode)
15699     {
15700     case V16QImode:
15701       for (i = 0; i < 8; i++)
15702         {
15703           pperm_bytes[i+0] = PPERM_SRC | PPERM_SRC1 | (i*2);
15704           pperm_bytes[i+8] = PPERM_SRC | PPERM_SRC2 | (i*2);
15705         }
15706
15707       for (i = 0; i < 16; i++)
15708         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15709
15710       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15711       emit_insn (gen_sse5_pperm_pack_v8hi_v16qi (op0, op1, op2, x));
15712       break;
15713
15714     case V8HImode:
15715       for (i = 0; i < 4; i++)
15716         {
15717           pperm_bytes[(2*i)+0] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 0);
15718           pperm_bytes[(2*i)+1] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 1);
15719           pperm_bytes[(2*i)+8] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 0);
15720           pperm_bytes[(2*i)+9] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 1);
15721         }
15722
15723       for (i = 0; i < 16; i++)
15724         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15725
15726       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15727       emit_insn (gen_sse5_pperm_pack_v4si_v8hi (op0, op1, op2, x));
15728       break;
15729
15730     case V4SImode:
15731       for (i = 0; i < 2; i++)
15732         {
15733           pperm_bytes[(4*i)+0]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 0);
15734           pperm_bytes[(4*i)+1]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 1);
15735           pperm_bytes[(4*i)+2]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 2);
15736           pperm_bytes[(4*i)+3]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 3);
15737           pperm_bytes[(4*i)+8]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 0);
15738           pperm_bytes[(4*i)+9]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 1);
15739           pperm_bytes[(4*i)+10] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 2);
15740           pperm_bytes[(4*i)+11] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 3);
15741         }
15742
15743       for (i = 0; i < 16; i++)
15744         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15745
15746       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15747       emit_insn (gen_sse5_pperm_pack_v2di_v4si (op0, op1, op2, x));
15748       break;
15749
15750     default:
15751       gcc_unreachable ();
15752     }
15753
15754   return;
15755 }
15756
15757 /* Expand conditional increment or decrement using adb/sbb instructions.
15758    The default case using setcc followed by the conditional move can be
15759    done by generic code.  */
15760 int
15761 ix86_expand_int_addcc (rtx operands[])
15762 {
15763   enum rtx_code code = GET_CODE (operands[1]);
15764   rtx compare_op;
15765   rtx val = const0_rtx;
15766   bool fpcmp = false;
15767   enum machine_mode mode = GET_MODE (operands[0]);
15768
15769   if (operands[3] != const1_rtx
15770       && operands[3] != constm1_rtx)
15771     return 0;
15772   if (!ix86_expand_carry_flag_compare (code, ix86_compare_op0,
15773                                        ix86_compare_op1, &compare_op))
15774      return 0;
15775   code = GET_CODE (compare_op);
15776
15777   if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
15778       || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
15779     {
15780       fpcmp = true;
15781       code = ix86_fp_compare_code_to_integer (code);
15782     }
15783
15784   if (code != LTU)
15785     {
15786       val = constm1_rtx;
15787       if (fpcmp)
15788         PUT_CODE (compare_op,
15789                   reverse_condition_maybe_unordered
15790                     (GET_CODE (compare_op)));
15791       else
15792         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
15793     }
15794   PUT_MODE (compare_op, mode);
15795
15796   /* Construct either adc or sbb insn.  */
15797   if ((code == LTU) == (operands[3] == constm1_rtx))
15798     {
15799       switch (GET_MODE (operands[0]))
15800         {
15801           case QImode:
15802             emit_insn (gen_subqi3_carry (operands[0], operands[2], val, compare_op));
15803             break;
15804           case HImode:
15805             emit_insn (gen_subhi3_carry (operands[0], operands[2], val, compare_op));
15806             break;
15807           case SImode:
15808             emit_insn (gen_subsi3_carry (operands[0], operands[2], val, compare_op));
15809             break;
15810           case DImode:
15811             emit_insn (gen_subdi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15812             break;
15813           default:
15814             gcc_unreachable ();
15815         }
15816     }
15817   else
15818     {
15819       switch (GET_MODE (operands[0]))
15820         {
15821           case QImode:
15822             emit_insn (gen_addqi3_carry (operands[0], operands[2], val, compare_op));
15823             break;
15824           case HImode:
15825             emit_insn (gen_addhi3_carry (operands[0], operands[2], val, compare_op));
15826             break;
15827           case SImode:
15828             emit_insn (gen_addsi3_carry (operands[0], operands[2], val, compare_op));
15829             break;
15830           case DImode:
15831             emit_insn (gen_adddi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15832             break;
15833           default:
15834             gcc_unreachable ();
15835         }
15836     }
15837   return 1; /* DONE */
15838 }
15839
15840
15841 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
15842    works for floating pointer parameters and nonoffsetable memories.
15843    For pushes, it returns just stack offsets; the values will be saved
15844    in the right order.  Maximally three parts are generated.  */
15845
15846 static int
15847 ix86_split_to_parts (rtx operand, rtx *parts, enum machine_mode mode)
15848 {
15849   int size;
15850
15851   if (!TARGET_64BIT)
15852     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
15853   else
15854     size = (GET_MODE_SIZE (mode) + 4) / 8;
15855
15856   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
15857   gcc_assert (size >= 2 && size <= 4);
15858
15859   /* Optimize constant pool reference to immediates.  This is used by fp
15860      moves, that force all constants to memory to allow combining.  */
15861   if (MEM_P (operand) && MEM_READONLY_P (operand))
15862     {
15863       rtx tmp = maybe_get_pool_constant (operand);
15864       if (tmp)
15865         operand = tmp;
15866     }
15867
15868   if (MEM_P (operand) && !offsettable_memref_p (operand))
15869     {
15870       /* The only non-offsetable memories we handle are pushes.  */
15871       int ok = push_operand (operand, VOIDmode);
15872
15873       gcc_assert (ok);
15874
15875       operand = copy_rtx (operand);
15876       PUT_MODE (operand, Pmode);
15877       parts[0] = parts[1] = parts[2] = parts[3] = operand;
15878       return size;
15879     }
15880
15881   if (GET_CODE (operand) == CONST_VECTOR)
15882     {
15883       enum machine_mode imode = int_mode_for_mode (mode);
15884       /* Caution: if we looked through a constant pool memory above,
15885          the operand may actually have a different mode now.  That's
15886          ok, since we want to pun this all the way back to an integer.  */
15887       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
15888       gcc_assert (operand != NULL);
15889       mode = imode;
15890     }
15891
15892   if (!TARGET_64BIT)
15893     {
15894       if (mode == DImode)
15895         split_di (&operand, 1, &parts[0], &parts[1]);
15896       else
15897         {
15898           int i;
15899
15900           if (REG_P (operand))
15901             {
15902               gcc_assert (reload_completed);
15903               for (i = 0; i < size; i++)
15904                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
15905             }
15906           else if (offsettable_memref_p (operand))
15907             {
15908               operand = adjust_address (operand, SImode, 0);
15909               parts[0] = operand;
15910               for (i = 1; i < size; i++)
15911                 parts[i] = adjust_address (operand, SImode, 4 * i);
15912             }
15913           else if (GET_CODE (operand) == CONST_DOUBLE)
15914             {
15915               REAL_VALUE_TYPE r;
15916               long l[4];
15917
15918               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
15919               switch (mode)
15920                 {
15921                 case TFmode:
15922                   real_to_target (l, &r, mode);
15923                   parts[3] = gen_int_mode (l[3], SImode);
15924                   parts[2] = gen_int_mode (l[2], SImode);
15925                   break;
15926                 case XFmode:
15927                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
15928                   parts[2] = gen_int_mode (l[2], SImode);
15929                   break;
15930                 case DFmode:
15931                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
15932                   break;
15933                 default:
15934                   gcc_unreachable ();
15935                 }
15936               parts[1] = gen_int_mode (l[1], SImode);
15937               parts[0] = gen_int_mode (l[0], SImode);
15938             }
15939           else
15940             gcc_unreachable ();
15941         }
15942     }
15943   else
15944     {
15945       if (mode == TImode)
15946         split_ti (&operand, 1, &parts[0], &parts[1]);
15947       if (mode == XFmode || mode == TFmode)
15948         {
15949           enum machine_mode upper_mode = mode==XFmode ? SImode : DImode;
15950           if (REG_P (operand))
15951             {
15952               gcc_assert (reload_completed);
15953               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
15954               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
15955             }
15956           else if (offsettable_memref_p (operand))
15957             {
15958               operand = adjust_address (operand, DImode, 0);
15959               parts[0] = operand;
15960               parts[1] = adjust_address (operand, upper_mode, 8);
15961             }
15962           else if (GET_CODE (operand) == CONST_DOUBLE)
15963             {
15964               REAL_VALUE_TYPE r;
15965               long l[4];
15966
15967               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
15968               real_to_target (l, &r, mode);
15969
15970               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
15971               if (HOST_BITS_PER_WIDE_INT >= 64)
15972                 parts[0]
15973                   = gen_int_mode
15974                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
15975                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
15976                        DImode);
15977               else
15978                 parts[0] = immed_double_const (l[0], l[1], DImode);
15979
15980               if (upper_mode == SImode)
15981                 parts[1] = gen_int_mode (l[2], SImode);
15982               else if (HOST_BITS_PER_WIDE_INT >= 64)
15983                 parts[1]
15984                   = gen_int_mode
15985                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
15986                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
15987                        DImode);
15988               else
15989                 parts[1] = immed_double_const (l[2], l[3], DImode);
15990             }
15991           else
15992             gcc_unreachable ();
15993         }
15994     }
15995
15996   return size;
15997 }
15998
15999 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
16000    Return false when normal moves are needed; true when all required
16001    insns have been emitted.  Operands 2-4 contain the input values
16002    int the correct order; operands 5-7 contain the output values.  */
16003
16004 void
16005 ix86_split_long_move (rtx operands[])
16006 {
16007   rtx part[2][4];
16008   int nparts, i, j;
16009   int push = 0;
16010   int collisions = 0;
16011   enum machine_mode mode = GET_MODE (operands[0]);
16012   bool collisionparts[4];
16013
16014   /* The DFmode expanders may ask us to move double.
16015      For 64bit target this is single move.  By hiding the fact
16016      here we simplify i386.md splitters.  */
16017   if (GET_MODE_SIZE (GET_MODE (operands[0])) == 8 && TARGET_64BIT)
16018     {
16019       /* Optimize constant pool reference to immediates.  This is used by
16020          fp moves, that force all constants to memory to allow combining.  */
16021
16022       if (MEM_P (operands[1])
16023           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
16024           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
16025         operands[1] = get_pool_constant (XEXP (operands[1], 0));
16026       if (push_operand (operands[0], VOIDmode))
16027         {
16028           operands[0] = copy_rtx (operands[0]);
16029           PUT_MODE (operands[0], Pmode);
16030         }
16031       else
16032         operands[0] = gen_lowpart (DImode, operands[0]);
16033       operands[1] = gen_lowpart (DImode, operands[1]);
16034       emit_move_insn (operands[0], operands[1]);
16035       return;
16036     }
16037
16038   /* The only non-offsettable memory we handle is push.  */
16039   if (push_operand (operands[0], VOIDmode))
16040     push = 1;
16041   else
16042     gcc_assert (!MEM_P (operands[0])
16043                 || offsettable_memref_p (operands[0]));
16044
16045   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
16046   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
16047
16048   /* When emitting push, take care for source operands on the stack.  */
16049   if (push && MEM_P (operands[1])
16050       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
16051     for (i = 0; i < nparts - 1; i++)
16052       part[1][i] = change_address (part[1][i],
16053                                    GET_MODE (part[1][i]),
16054                                    XEXP (part[1][i + 1], 0));
16055
16056   /* We need to do copy in the right order in case an address register
16057      of the source overlaps the destination.  */
16058   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
16059     {
16060       rtx tmp;
16061
16062       for (i = 0; i < nparts; i++)
16063         {
16064           collisionparts[i]
16065             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
16066           if (collisionparts[i])
16067             collisions++;
16068         }
16069
16070       /* Collision in the middle part can be handled by reordering.  */
16071       if (collisions == 1 && nparts == 3 && collisionparts [1])
16072         {
16073           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
16074           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
16075         }
16076       else if (collisions == 1
16077                && nparts == 4
16078                && (collisionparts [1] || collisionparts [2]))
16079         {
16080           if (collisionparts [1])
16081             {
16082               tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
16083               tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
16084             }
16085           else
16086             {
16087               tmp = part[0][2]; part[0][2] = part[0][3]; part[0][3] = tmp;
16088               tmp = part[1][2]; part[1][2] = part[1][3]; part[1][3] = tmp;
16089             }
16090         }
16091
16092       /* If there are more collisions, we can't handle it by reordering.
16093          Do an lea to the last part and use only one colliding move.  */
16094       else if (collisions > 1)
16095         {
16096           rtx base;
16097
16098           collisions = 1;
16099
16100           base = part[0][nparts - 1];
16101
16102           /* Handle the case when the last part isn't valid for lea.
16103              Happens in 64-bit mode storing the 12-byte XFmode.  */
16104           if (GET_MODE (base) != Pmode)
16105             base = gen_rtx_REG (Pmode, REGNO (base));
16106
16107           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
16108           part[1][0] = replace_equiv_address (part[1][0], base);
16109           for (i = 1; i < nparts; i++)
16110             {
16111               tmp = plus_constant (base, UNITS_PER_WORD * i);
16112               part[1][i] = replace_equiv_address (part[1][i], tmp);
16113             }
16114         }
16115     }
16116
16117   if (push)
16118     {
16119       if (!TARGET_64BIT)
16120         {
16121           if (nparts == 3)
16122             {
16123               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
16124                 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-4)));
16125               emit_move_insn (part[0][2], part[1][2]);
16126             }
16127           else if (nparts == 4)
16128             {
16129               emit_move_insn (part[0][3], part[1][3]);
16130               emit_move_insn (part[0][2], part[1][2]);
16131             }
16132         }
16133       else
16134         {
16135           /* In 64bit mode we don't have 32bit push available.  In case this is
16136              register, it is OK - we will just use larger counterpart.  We also
16137              retype memory - these comes from attempt to avoid REX prefix on
16138              moving of second half of TFmode value.  */
16139           if (GET_MODE (part[1][1]) == SImode)
16140             {
16141               switch (GET_CODE (part[1][1]))
16142                 {
16143                 case MEM:
16144                   part[1][1] = adjust_address (part[1][1], DImode, 0);
16145                   break;
16146
16147                 case REG:
16148                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
16149                   break;
16150
16151                 default:
16152                   gcc_unreachable ();
16153                 }
16154
16155               if (GET_MODE (part[1][0]) == SImode)
16156                 part[1][0] = part[1][1];
16157             }
16158         }
16159       emit_move_insn (part[0][1], part[1][1]);
16160       emit_move_insn (part[0][0], part[1][0]);
16161       return;
16162     }
16163
16164   /* Choose correct order to not overwrite the source before it is copied.  */
16165   if ((REG_P (part[0][0])
16166        && REG_P (part[1][1])
16167        && (REGNO (part[0][0]) == REGNO (part[1][1])
16168            || (nparts == 3
16169                && REGNO (part[0][0]) == REGNO (part[1][2]))
16170            || (nparts == 4
16171                && REGNO (part[0][0]) == REGNO (part[1][3]))))
16172       || (collisions > 0
16173           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
16174     {
16175       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
16176         {
16177           operands[2 + i] = part[0][j];
16178           operands[6 + i] = part[1][j];
16179         }
16180     }
16181   else
16182     {
16183       for (i = 0; i < nparts; i++)
16184         {
16185           operands[2 + i] = part[0][i];
16186           operands[6 + i] = part[1][i];
16187         }
16188     }
16189
16190   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
16191   if (optimize_insn_for_size_p ())
16192     {
16193       for (j = 0; j < nparts - 1; j++)
16194         if (CONST_INT_P (operands[6 + j])
16195             && operands[6 + j] != const0_rtx
16196             && REG_P (operands[2 + j]))
16197           for (i = j; i < nparts - 1; i++)
16198             if (CONST_INT_P (operands[7 + i])
16199                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
16200               operands[7 + i] = operands[2 + j];
16201     }
16202
16203   for (i = 0; i < nparts; i++)
16204     emit_move_insn (operands[2 + i], operands[6 + i]);
16205
16206   return;
16207 }
16208
16209 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
16210    left shift by a constant, either using a single shift or
16211    a sequence of add instructions.  */
16212
16213 static void
16214 ix86_expand_ashl_const (rtx operand, int count, enum machine_mode mode)
16215 {
16216   if (count == 1)
16217     {
16218       emit_insn ((mode == DImode
16219                   ? gen_addsi3
16220                   : gen_adddi3) (operand, operand, operand));
16221     }
16222   else if (!optimize_insn_for_size_p ()
16223            && count * ix86_cost->add <= ix86_cost->shift_const)
16224     {
16225       int i;
16226       for (i=0; i<count; i++)
16227         {
16228           emit_insn ((mode == DImode
16229                       ? gen_addsi3
16230                       : gen_adddi3) (operand, operand, operand));
16231         }
16232     }
16233   else
16234     emit_insn ((mode == DImode
16235                 ? gen_ashlsi3
16236                 : gen_ashldi3) (operand, operand, GEN_INT (count)));
16237 }
16238
16239 void
16240 ix86_split_ashl (rtx *operands, rtx scratch, enum machine_mode mode)
16241 {
16242   rtx low[2], high[2];
16243   int count;
16244   const int single_width = mode == DImode ? 32 : 64;
16245
16246   if (CONST_INT_P (operands[2]))
16247     {
16248       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16249       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16250
16251       if (count >= single_width)
16252         {
16253           emit_move_insn (high[0], low[1]);
16254           emit_move_insn (low[0], const0_rtx);
16255
16256           if (count > single_width)
16257             ix86_expand_ashl_const (high[0], count - single_width, mode);
16258         }
16259       else
16260         {
16261           if (!rtx_equal_p (operands[0], operands[1]))
16262             emit_move_insn (operands[0], operands[1]);
16263           emit_insn ((mode == DImode
16264                      ? gen_x86_shld
16265                      : gen_x86_64_shld) (high[0], low[0], GEN_INT (count)));
16266           ix86_expand_ashl_const (low[0], count, mode);
16267         }
16268       return;
16269     }
16270
16271   (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16272
16273   if (operands[1] == const1_rtx)
16274     {
16275       /* Assuming we've chosen a QImode capable registers, then 1 << N
16276          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
16277       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
16278         {
16279           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
16280
16281           ix86_expand_clear (low[0]);
16282           ix86_expand_clear (high[0]);
16283           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (single_width)));
16284
16285           d = gen_lowpart (QImode, low[0]);
16286           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16287           s = gen_rtx_EQ (QImode, flags, const0_rtx);
16288           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16289
16290           d = gen_lowpart (QImode, high[0]);
16291           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16292           s = gen_rtx_NE (QImode, flags, const0_rtx);
16293           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16294         }
16295
16296       /* Otherwise, we can get the same results by manually performing
16297          a bit extract operation on bit 5/6, and then performing the two
16298          shifts.  The two methods of getting 0/1 into low/high are exactly
16299          the same size.  Avoiding the shift in the bit extract case helps
16300          pentium4 a bit; no one else seems to care much either way.  */
16301       else
16302         {
16303           rtx x;
16304
16305           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
16306             x = gen_rtx_ZERO_EXTEND (mode == DImode ? SImode : DImode, operands[2]);
16307           else
16308             x = gen_lowpart (mode == DImode ? SImode : DImode, operands[2]);
16309           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
16310
16311           emit_insn ((mode == DImode
16312                       ? gen_lshrsi3
16313                       : gen_lshrdi3) (high[0], high[0], GEN_INT (mode == DImode ? 5 : 6)));
16314           emit_insn ((mode == DImode
16315                       ? gen_andsi3
16316                       : gen_anddi3) (high[0], high[0], GEN_INT (1)));
16317           emit_move_insn (low[0], high[0]);
16318           emit_insn ((mode == DImode
16319                       ? gen_xorsi3
16320                       : gen_xordi3) (low[0], low[0], GEN_INT (1)));
16321         }
16322
16323       emit_insn ((mode == DImode
16324                     ? gen_ashlsi3
16325                     : gen_ashldi3) (low[0], low[0], operands[2]));
16326       emit_insn ((mode == DImode
16327                     ? gen_ashlsi3
16328                     : gen_ashldi3) (high[0], high[0], operands[2]));
16329       return;
16330     }
16331
16332   if (operands[1] == constm1_rtx)
16333     {
16334       /* For -1 << N, we can avoid the shld instruction, because we
16335          know that we're shifting 0...31/63 ones into a -1.  */
16336       emit_move_insn (low[0], constm1_rtx);
16337       if (optimize_insn_for_size_p ())
16338         emit_move_insn (high[0], low[0]);
16339       else
16340         emit_move_insn (high[0], constm1_rtx);
16341     }
16342   else
16343     {
16344       if (!rtx_equal_p (operands[0], operands[1]))
16345         emit_move_insn (operands[0], operands[1]);
16346
16347       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16348       emit_insn ((mode == DImode
16349                   ? gen_x86_shld
16350                   : gen_x86_64_shld) (high[0], low[0], operands[2]));
16351     }
16352
16353   emit_insn ((mode == DImode ? gen_ashlsi3 : gen_ashldi3) (low[0], low[0], operands[2]));
16354
16355   if (TARGET_CMOVE && scratch)
16356     {
16357       ix86_expand_clear (scratch);
16358       emit_insn ((mode == DImode
16359                   ? gen_x86_shift_adj_1
16360                   : gen_x86_64_shift_adj_1) (high[0], low[0], operands[2],
16361                                              scratch));
16362     }
16363   else
16364     emit_insn ((mode == DImode
16365                 ? gen_x86_shift_adj_2
16366                 : gen_x86_64_shift_adj_2) (high[0], low[0], operands[2]));
16367 }
16368
16369 void
16370 ix86_split_ashr (rtx *operands, rtx scratch, enum machine_mode mode)
16371 {
16372   rtx low[2], high[2];
16373   int count;
16374   const int single_width = mode == DImode ? 32 : 64;
16375
16376   if (CONST_INT_P (operands[2]))
16377     {
16378       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16379       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16380
16381       if (count == single_width * 2 - 1)
16382         {
16383           emit_move_insn (high[0], high[1]);
16384           emit_insn ((mode == DImode
16385                       ? gen_ashrsi3
16386                       : gen_ashrdi3) (high[0], high[0],
16387                                       GEN_INT (single_width - 1)));
16388           emit_move_insn (low[0], high[0]);
16389
16390         }
16391       else if (count >= single_width)
16392         {
16393           emit_move_insn (low[0], high[1]);
16394           emit_move_insn (high[0], low[0]);
16395           emit_insn ((mode == DImode
16396                       ? gen_ashrsi3
16397                       : gen_ashrdi3) (high[0], high[0],
16398                                       GEN_INT (single_width - 1)));
16399           if (count > single_width)
16400             emit_insn ((mode == DImode
16401                         ? gen_ashrsi3
16402                         : gen_ashrdi3) (low[0], low[0],
16403                                         GEN_INT (count - single_width)));
16404         }
16405       else
16406         {
16407           if (!rtx_equal_p (operands[0], operands[1]))
16408             emit_move_insn (operands[0], operands[1]);
16409           emit_insn ((mode == DImode
16410                       ? gen_x86_shrd
16411                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16412           emit_insn ((mode == DImode
16413                       ? gen_ashrsi3
16414                       : gen_ashrdi3) (high[0], high[0], GEN_INT (count)));
16415         }
16416     }
16417   else
16418     {
16419       if (!rtx_equal_p (operands[0], operands[1]))
16420         emit_move_insn (operands[0], operands[1]);
16421
16422       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16423
16424       emit_insn ((mode == DImode
16425                   ? gen_x86_shrd
16426                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16427       emit_insn ((mode == DImode
16428                   ? gen_ashrsi3
16429                   : gen_ashrdi3)  (high[0], high[0], operands[2]));
16430
16431       if (TARGET_CMOVE && scratch)
16432         {
16433           emit_move_insn (scratch, high[0]);
16434           emit_insn ((mode == DImode
16435                       ? gen_ashrsi3
16436                       : gen_ashrdi3) (scratch, scratch,
16437                                       GEN_INT (single_width - 1)));
16438           emit_insn ((mode == DImode
16439                       ? gen_x86_shift_adj_1
16440                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16441                                                  scratch));
16442         }
16443       else
16444         emit_insn ((mode == DImode
16445                     ? gen_x86_shift_adj_3
16446                     : gen_x86_64_shift_adj_3) (low[0], high[0], operands[2]));
16447     }
16448 }
16449
16450 void
16451 ix86_split_lshr (rtx *operands, rtx scratch, enum machine_mode mode)
16452 {
16453   rtx low[2], high[2];
16454   int count;
16455   const int single_width = mode == DImode ? 32 : 64;
16456
16457   if (CONST_INT_P (operands[2]))
16458     {
16459       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16460       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16461
16462       if (count >= single_width)
16463         {
16464           emit_move_insn (low[0], high[1]);
16465           ix86_expand_clear (high[0]);
16466
16467           if (count > single_width)
16468             emit_insn ((mode == DImode
16469                         ? gen_lshrsi3
16470                         : gen_lshrdi3) (low[0], low[0],
16471                                         GEN_INT (count - single_width)));
16472         }
16473       else
16474         {
16475           if (!rtx_equal_p (operands[0], operands[1]))
16476             emit_move_insn (operands[0], operands[1]);
16477           emit_insn ((mode == DImode
16478                       ? gen_x86_shrd
16479                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16480           emit_insn ((mode == DImode
16481                       ? gen_lshrsi3
16482                       : gen_lshrdi3) (high[0], high[0], GEN_INT (count)));
16483         }
16484     }
16485   else
16486     {
16487       if (!rtx_equal_p (operands[0], operands[1]))
16488         emit_move_insn (operands[0], operands[1]);
16489
16490       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16491
16492       emit_insn ((mode == DImode
16493                   ? gen_x86_shrd
16494                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16495       emit_insn ((mode == DImode
16496                   ? gen_lshrsi3
16497                   : gen_lshrdi3) (high[0], high[0], operands[2]));
16498
16499       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
16500       if (TARGET_CMOVE && scratch)
16501         {
16502           ix86_expand_clear (scratch);
16503           emit_insn ((mode == DImode
16504                       ? gen_x86_shift_adj_1
16505                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16506                                                  scratch));
16507         }
16508       else
16509         emit_insn ((mode == DImode
16510                     ? gen_x86_shift_adj_2
16511                     : gen_x86_64_shift_adj_2) (low[0], high[0], operands[2]));
16512     }
16513 }
16514
16515 /* Predict just emitted jump instruction to be taken with probability PROB.  */
16516 static void
16517 predict_jump (int prob)
16518 {
16519   rtx insn = get_last_insn ();
16520   gcc_assert (JUMP_P (insn));
16521   REG_NOTES (insn)
16522     = gen_rtx_EXPR_LIST (REG_BR_PROB,
16523                          GEN_INT (prob),
16524                          REG_NOTES (insn));
16525 }
16526
16527 /* Helper function for the string operations below.  Dest VARIABLE whether
16528    it is aligned to VALUE bytes.  If true, jump to the label.  */
16529 static rtx
16530 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
16531 {
16532   rtx label = gen_label_rtx ();
16533   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
16534   if (GET_MODE (variable) == DImode)
16535     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
16536   else
16537     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
16538   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
16539                            1, label);
16540   if (epilogue)
16541     predict_jump (REG_BR_PROB_BASE * 50 / 100);
16542   else
16543     predict_jump (REG_BR_PROB_BASE * 90 / 100);
16544   return label;
16545 }
16546
16547 /* Adjust COUNTER by the VALUE.  */
16548 static void
16549 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
16550 {
16551   if (GET_MODE (countreg) == DImode)
16552     emit_insn (gen_adddi3 (countreg, countreg, GEN_INT (-value)));
16553   else
16554     emit_insn (gen_addsi3 (countreg, countreg, GEN_INT (-value)));
16555 }
16556
16557 /* Zero extend possibly SImode EXP to Pmode register.  */
16558 rtx
16559 ix86_zero_extend_to_Pmode (rtx exp)
16560 {
16561   rtx r;
16562   if (GET_MODE (exp) == VOIDmode)
16563     return force_reg (Pmode, exp);
16564   if (GET_MODE (exp) == Pmode)
16565     return copy_to_mode_reg (Pmode, exp);
16566   r = gen_reg_rtx (Pmode);
16567   emit_insn (gen_zero_extendsidi2 (r, exp));
16568   return r;
16569 }
16570
16571 /* Divide COUNTREG by SCALE.  */
16572 static rtx
16573 scale_counter (rtx countreg, int scale)
16574 {
16575   rtx sc;
16576   rtx piece_size_mask;
16577
16578   if (scale == 1)
16579     return countreg;
16580   if (CONST_INT_P (countreg))
16581     return GEN_INT (INTVAL (countreg) / scale);
16582   gcc_assert (REG_P (countreg));
16583
16584   piece_size_mask = GEN_INT (scale - 1);
16585   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
16586                             GEN_INT (exact_log2 (scale)),
16587                             NULL, 1, OPTAB_DIRECT);
16588   return sc;
16589 }
16590
16591 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
16592    DImode for constant loop counts.  */
16593
16594 static enum machine_mode
16595 counter_mode (rtx count_exp)
16596 {
16597   if (GET_MODE (count_exp) != VOIDmode)
16598     return GET_MODE (count_exp);
16599   if (GET_CODE (count_exp) != CONST_INT)
16600     return Pmode;
16601   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
16602     return DImode;
16603   return SImode;
16604 }
16605
16606 /* When SRCPTR is non-NULL, output simple loop to move memory
16607    pointer to SRCPTR to DESTPTR via chunks of MODE unrolled UNROLL times,
16608    overall size is COUNT specified in bytes.  When SRCPTR is NULL, output the
16609    equivalent loop to set memory by VALUE (supposed to be in MODE).
16610
16611    The size is rounded down to whole number of chunk size moved at once.
16612    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
16613
16614
16615 static void
16616 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
16617                                rtx destptr, rtx srcptr, rtx value,
16618                                rtx count, enum machine_mode mode, int unroll,
16619                                int expected_size)
16620 {
16621   rtx out_label, top_label, iter, tmp;
16622   enum machine_mode iter_mode = counter_mode (count);
16623   rtx piece_size = GEN_INT (GET_MODE_SIZE (mode) * unroll);
16624   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
16625   rtx size;
16626   rtx x_addr;
16627   rtx y_addr;
16628   int i;
16629
16630   top_label = gen_label_rtx ();
16631   out_label = gen_label_rtx ();
16632   iter = gen_reg_rtx (iter_mode);
16633
16634   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
16635                               NULL, 1, OPTAB_DIRECT);
16636   /* Those two should combine.  */
16637   if (piece_size == const1_rtx)
16638     {
16639       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
16640                                true, out_label);
16641       predict_jump (REG_BR_PROB_BASE * 10 / 100);
16642     }
16643   emit_move_insn (iter, const0_rtx);
16644
16645   emit_label (top_label);
16646
16647   tmp = convert_modes (Pmode, iter_mode, iter, true);
16648   x_addr = gen_rtx_PLUS (Pmode, destptr, tmp);
16649   destmem = change_address (destmem, mode, x_addr);
16650
16651   if (srcmem)
16652     {
16653       y_addr = gen_rtx_PLUS (Pmode, srcptr, copy_rtx (tmp));
16654       srcmem = change_address (srcmem, mode, y_addr);
16655
16656       /* When unrolling for chips that reorder memory reads and writes,
16657          we can save registers by using single temporary.
16658          Also using 4 temporaries is overkill in 32bit mode.  */
16659       if (!TARGET_64BIT && 0)
16660         {
16661           for (i = 0; i < unroll; i++)
16662             {
16663               if (i)
16664                 {
16665                   destmem =
16666                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16667                   srcmem =
16668                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16669                 }
16670               emit_move_insn (destmem, srcmem);
16671             }
16672         }
16673       else
16674         {
16675           rtx tmpreg[4];
16676           gcc_assert (unroll <= 4);
16677           for (i = 0; i < unroll; i++)
16678             {
16679               tmpreg[i] = gen_reg_rtx (mode);
16680               if (i)
16681                 {
16682                   srcmem =
16683                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16684                 }
16685               emit_move_insn (tmpreg[i], srcmem);
16686             }
16687           for (i = 0; i < unroll; i++)
16688             {
16689               if (i)
16690                 {
16691                   destmem =
16692                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16693                 }
16694               emit_move_insn (destmem, tmpreg[i]);
16695             }
16696         }
16697     }
16698   else
16699     for (i = 0; i < unroll; i++)
16700       {
16701         if (i)
16702           destmem =
16703             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16704         emit_move_insn (destmem, value);
16705       }
16706
16707   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
16708                              true, OPTAB_LIB_WIDEN);
16709   if (tmp != iter)
16710     emit_move_insn (iter, tmp);
16711
16712   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
16713                            true, top_label);
16714   if (expected_size != -1)
16715     {
16716       expected_size /= GET_MODE_SIZE (mode) * unroll;
16717       if (expected_size == 0)
16718         predict_jump (0);
16719       else if (expected_size > REG_BR_PROB_BASE)
16720         predict_jump (REG_BR_PROB_BASE - 1);
16721       else
16722         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
16723     }
16724   else
16725     predict_jump (REG_BR_PROB_BASE * 80 / 100);
16726   iter = ix86_zero_extend_to_Pmode (iter);
16727   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
16728                              true, OPTAB_LIB_WIDEN);
16729   if (tmp != destptr)
16730     emit_move_insn (destptr, tmp);
16731   if (srcptr)
16732     {
16733       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
16734                                  true, OPTAB_LIB_WIDEN);
16735       if (tmp != srcptr)
16736         emit_move_insn (srcptr, tmp);
16737     }
16738   emit_label (out_label);
16739 }
16740
16741 /* Output "rep; mov" instruction.
16742    Arguments have same meaning as for previous function */
16743 static void
16744 expand_movmem_via_rep_mov (rtx destmem, rtx srcmem,
16745                            rtx destptr, rtx srcptr,
16746                            rtx count,
16747                            enum machine_mode mode)
16748 {
16749   rtx destexp;
16750   rtx srcexp;
16751   rtx countreg;
16752
16753   /* If the size is known, it is shorter to use rep movs.  */
16754   if (mode == QImode && CONST_INT_P (count)
16755       && !(INTVAL (count) & 3))
16756     mode = SImode;
16757
16758   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16759     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16760   if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
16761     srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
16762   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16763   if (mode != QImode)
16764     {
16765       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16766                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16767       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16768       srcexp = gen_rtx_ASHIFT (Pmode, countreg,
16769                                GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16770       srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
16771     }
16772   else
16773     {
16774       destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16775       srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
16776     }
16777   if (CONST_INT_P (count))
16778     {
16779       count = GEN_INT (INTVAL (count)
16780                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
16781       destmem = shallow_copy_rtx (destmem);
16782       srcmem = shallow_copy_rtx (srcmem);
16783       set_mem_size (destmem, count);
16784       set_mem_size (srcmem, count);
16785     }
16786   else
16787     {
16788       if (MEM_SIZE (destmem))
16789         set_mem_size (destmem, NULL_RTX);
16790       if (MEM_SIZE (srcmem))
16791         set_mem_size (srcmem, NULL_RTX);
16792     }
16793   emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
16794                           destexp, srcexp));
16795 }
16796
16797 /* Output "rep; stos" instruction.
16798    Arguments have same meaning as for previous function */
16799 static void
16800 expand_setmem_via_rep_stos (rtx destmem, rtx destptr, rtx value,
16801                             rtx count, enum machine_mode mode,
16802                             rtx orig_value)
16803 {
16804   rtx destexp;
16805   rtx countreg;
16806
16807   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16808     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16809   value = force_reg (mode, gen_lowpart (mode, value));
16810   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16811   if (mode != QImode)
16812     {
16813       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16814                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16815       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16816     }
16817   else
16818     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16819   if (orig_value == const0_rtx && CONST_INT_P (count))
16820     {
16821       count = GEN_INT (INTVAL (count)
16822                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
16823       destmem = shallow_copy_rtx (destmem);
16824       set_mem_size (destmem, count);
16825     }
16826   else if (MEM_SIZE (destmem))
16827     set_mem_size (destmem, NULL_RTX);
16828   emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
16829 }
16830
16831 static void
16832 emit_strmov (rtx destmem, rtx srcmem,
16833              rtx destptr, rtx srcptr, enum machine_mode mode, int offset)
16834 {
16835   rtx src = adjust_automodify_address_nv (srcmem, mode, srcptr, offset);
16836   rtx dest = adjust_automodify_address_nv (destmem, mode, destptr, offset);
16837   emit_insn (gen_strmov (destptr, dest, srcptr, src));
16838 }
16839
16840 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
16841 static void
16842 expand_movmem_epilogue (rtx destmem, rtx srcmem,
16843                         rtx destptr, rtx srcptr, rtx count, int max_size)
16844 {
16845   rtx src, dest;
16846   if (CONST_INT_P (count))
16847     {
16848       HOST_WIDE_INT countval = INTVAL (count);
16849       int offset = 0;
16850
16851       if ((countval & 0x10) && max_size > 16)
16852         {
16853           if (TARGET_64BIT)
16854             {
16855               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16856               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset + 8);
16857             }
16858           else
16859             gcc_unreachable ();
16860           offset += 16;
16861         }
16862       if ((countval & 0x08) && max_size > 8)
16863         {
16864           if (TARGET_64BIT)
16865             emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16866           else
16867             {
16868               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16869               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset + 4);
16870             }
16871           offset += 8;
16872         }
16873       if ((countval & 0x04) && max_size > 4)
16874         {
16875           emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16876           offset += 4;
16877         }
16878       if ((countval & 0x02) && max_size > 2)
16879         {
16880           emit_strmov (destmem, srcmem, destptr, srcptr, HImode, offset);
16881           offset += 2;
16882         }
16883       if ((countval & 0x01) && max_size > 1)
16884         {
16885           emit_strmov (destmem, srcmem, destptr, srcptr, QImode, offset);
16886           offset += 1;
16887         }
16888       return;
16889     }
16890   if (max_size > 8)
16891     {
16892       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
16893                                     count, 1, OPTAB_DIRECT);
16894       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
16895                                      count, QImode, 1, 4);
16896       return;
16897     }
16898
16899   /* When there are stringops, we can cheaply increase dest and src pointers.
16900      Otherwise we save code size by maintaining offset (zero is readily
16901      available from preceding rep operation) and using x86 addressing modes.
16902    */
16903   if (TARGET_SINGLE_STRINGOP)
16904     {
16905       if (max_size > 4)
16906         {
16907           rtx label = ix86_expand_aligntest (count, 4, true);
16908           src = change_address (srcmem, SImode, srcptr);
16909           dest = change_address (destmem, SImode, destptr);
16910           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16911           emit_label (label);
16912           LABEL_NUSES (label) = 1;
16913         }
16914       if (max_size > 2)
16915         {
16916           rtx label = ix86_expand_aligntest (count, 2, true);
16917           src = change_address (srcmem, HImode, srcptr);
16918           dest = change_address (destmem, HImode, destptr);
16919           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16920           emit_label (label);
16921           LABEL_NUSES (label) = 1;
16922         }
16923       if (max_size > 1)
16924         {
16925           rtx label = ix86_expand_aligntest (count, 1, true);
16926           src = change_address (srcmem, QImode, srcptr);
16927           dest = change_address (destmem, QImode, destptr);
16928           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16929           emit_label (label);
16930           LABEL_NUSES (label) = 1;
16931         }
16932     }
16933   else
16934     {
16935       rtx offset = force_reg (Pmode, const0_rtx);
16936       rtx tmp;
16937
16938       if (max_size > 4)
16939         {
16940           rtx label = ix86_expand_aligntest (count, 4, true);
16941           src = change_address (srcmem, SImode, srcptr);
16942           dest = change_address (destmem, SImode, destptr);
16943           emit_move_insn (dest, src);
16944           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
16945                                      true, OPTAB_LIB_WIDEN);
16946           if (tmp != offset)
16947             emit_move_insn (offset, tmp);
16948           emit_label (label);
16949           LABEL_NUSES (label) = 1;
16950         }
16951       if (max_size > 2)
16952         {
16953           rtx label = ix86_expand_aligntest (count, 2, true);
16954           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
16955           src = change_address (srcmem, HImode, tmp);
16956           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
16957           dest = change_address (destmem, HImode, tmp);
16958           emit_move_insn (dest, src);
16959           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
16960                                      true, OPTAB_LIB_WIDEN);
16961           if (tmp != offset)
16962             emit_move_insn (offset, tmp);
16963           emit_label (label);
16964           LABEL_NUSES (label) = 1;
16965         }
16966       if (max_size > 1)
16967         {
16968           rtx label = ix86_expand_aligntest (count, 1, true);
16969           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
16970           src = change_address (srcmem, QImode, tmp);
16971           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
16972           dest = change_address (destmem, QImode, tmp);
16973           emit_move_insn (dest, src);
16974           emit_label (label);
16975           LABEL_NUSES (label) = 1;
16976         }
16977     }
16978 }
16979
16980 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
16981 static void
16982 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
16983                                  rtx count, int max_size)
16984 {
16985   count =
16986     expand_simple_binop (counter_mode (count), AND, count,
16987                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
16988   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
16989                                  gen_lowpart (QImode, value), count, QImode,
16990                                  1, max_size / 2);
16991 }
16992
16993 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
16994 static void
16995 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx count, int max_size)
16996 {
16997   rtx dest;
16998
16999   if (CONST_INT_P (count))
17000     {
17001       HOST_WIDE_INT countval = INTVAL (count);
17002       int offset = 0;
17003
17004       if ((countval & 0x10) && max_size > 16)
17005         {
17006           if (TARGET_64BIT)
17007             {
17008               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
17009               emit_insn (gen_strset (destptr, dest, value));
17010               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset + 8);
17011               emit_insn (gen_strset (destptr, dest, value));
17012             }
17013           else
17014             gcc_unreachable ();
17015           offset += 16;
17016         }
17017       if ((countval & 0x08) && max_size > 8)
17018         {
17019           if (TARGET_64BIT)
17020             {
17021               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
17022               emit_insn (gen_strset (destptr, dest, value));
17023             }
17024           else
17025             {
17026               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
17027               emit_insn (gen_strset (destptr, dest, value));
17028               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset + 4);
17029               emit_insn (gen_strset (destptr, dest, value));
17030             }
17031           offset += 8;
17032         }
17033       if ((countval & 0x04) && max_size > 4)
17034         {
17035           dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
17036           emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
17037           offset += 4;
17038         }
17039       if ((countval & 0x02) && max_size > 2)
17040         {
17041           dest = adjust_automodify_address_nv (destmem, HImode, destptr, offset);
17042           emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
17043           offset += 2;
17044         }
17045       if ((countval & 0x01) && max_size > 1)
17046         {
17047           dest = adjust_automodify_address_nv (destmem, QImode, destptr, offset);
17048           emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
17049           offset += 1;
17050         }
17051       return;
17052     }
17053   if (max_size > 32)
17054     {
17055       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
17056       return;
17057     }
17058   if (max_size > 16)
17059     {
17060       rtx label = ix86_expand_aligntest (count, 16, true);
17061       if (TARGET_64BIT)
17062         {
17063           dest = change_address (destmem, DImode, destptr);
17064           emit_insn (gen_strset (destptr, dest, value));
17065           emit_insn (gen_strset (destptr, dest, value));
17066         }
17067       else
17068         {
17069           dest = change_address (destmem, SImode, destptr);
17070           emit_insn (gen_strset (destptr, dest, value));
17071           emit_insn (gen_strset (destptr, dest, value));
17072           emit_insn (gen_strset (destptr, dest, value));
17073           emit_insn (gen_strset (destptr, dest, value));
17074         }
17075       emit_label (label);
17076       LABEL_NUSES (label) = 1;
17077     }
17078   if (max_size > 8)
17079     {
17080       rtx label = ix86_expand_aligntest (count, 8, true);
17081       if (TARGET_64BIT)
17082         {
17083           dest = change_address (destmem, DImode, destptr);
17084           emit_insn (gen_strset (destptr, dest, value));
17085         }
17086       else
17087         {
17088           dest = change_address (destmem, SImode, destptr);
17089           emit_insn (gen_strset (destptr, dest, value));
17090           emit_insn (gen_strset (destptr, dest, value));
17091         }
17092       emit_label (label);
17093       LABEL_NUSES (label) = 1;
17094     }
17095   if (max_size > 4)
17096     {
17097       rtx label = ix86_expand_aligntest (count, 4, true);
17098       dest = change_address (destmem, SImode, destptr);
17099       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
17100       emit_label (label);
17101       LABEL_NUSES (label) = 1;
17102     }
17103   if (max_size > 2)
17104     {
17105       rtx label = ix86_expand_aligntest (count, 2, true);
17106       dest = change_address (destmem, HImode, destptr);
17107       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
17108       emit_label (label);
17109       LABEL_NUSES (label) = 1;
17110     }
17111   if (max_size > 1)
17112     {
17113       rtx label = ix86_expand_aligntest (count, 1, true);
17114       dest = change_address (destmem, QImode, destptr);
17115       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
17116       emit_label (label);
17117       LABEL_NUSES (label) = 1;
17118     }
17119 }
17120
17121 /* Copy enough from DEST to SRC to align DEST known to by aligned by ALIGN to
17122    DESIRED_ALIGNMENT.  */
17123 static void
17124 expand_movmem_prologue (rtx destmem, rtx srcmem,
17125                         rtx destptr, rtx srcptr, rtx count,
17126                         int align, int desired_alignment)
17127 {
17128   if (align <= 1 && desired_alignment > 1)
17129     {
17130       rtx label = ix86_expand_aligntest (destptr, 1, false);
17131       srcmem = change_address (srcmem, QImode, srcptr);
17132       destmem = change_address (destmem, QImode, destptr);
17133       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17134       ix86_adjust_counter (count, 1);
17135       emit_label (label);
17136       LABEL_NUSES (label) = 1;
17137     }
17138   if (align <= 2 && desired_alignment > 2)
17139     {
17140       rtx label = ix86_expand_aligntest (destptr, 2, false);
17141       srcmem = change_address (srcmem, HImode, srcptr);
17142       destmem = change_address (destmem, HImode, destptr);
17143       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17144       ix86_adjust_counter (count, 2);
17145       emit_label (label);
17146       LABEL_NUSES (label) = 1;
17147     }
17148   if (align <= 4 && desired_alignment > 4)
17149     {
17150       rtx label = ix86_expand_aligntest (destptr, 4, false);
17151       srcmem = change_address (srcmem, SImode, srcptr);
17152       destmem = change_address (destmem, SImode, destptr);
17153       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17154       ix86_adjust_counter (count, 4);
17155       emit_label (label);
17156       LABEL_NUSES (label) = 1;
17157     }
17158   gcc_assert (desired_alignment <= 8);
17159 }
17160
17161 /* Copy enough from DST to SRC to align DST known to DESIRED_ALIGN.
17162    ALIGN_BYTES is how many bytes need to be copied.  */
17163 static rtx
17164 expand_constant_movmem_prologue (rtx dst, rtx *srcp, rtx destreg, rtx srcreg,
17165                                  int desired_align, int align_bytes)
17166 {
17167   rtx src = *srcp;
17168   rtx src_size, dst_size;
17169   int off = 0;
17170   int src_align_bytes = get_mem_align_offset (src, desired_align * BITS_PER_UNIT);
17171   if (src_align_bytes >= 0)
17172     src_align_bytes = desired_align - src_align_bytes;
17173   src_size = MEM_SIZE (src);
17174   dst_size = MEM_SIZE (dst);
17175   if (align_bytes & 1)
17176     {
17177       dst = adjust_automodify_address_nv (dst, QImode, destreg, 0);
17178       src = adjust_automodify_address_nv (src, QImode, srcreg, 0);
17179       off = 1;
17180       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17181     }
17182   if (align_bytes & 2)
17183     {
17184       dst = adjust_automodify_address_nv (dst, HImode, destreg, off);
17185       src = adjust_automodify_address_nv (src, HImode, srcreg, off);
17186       if (MEM_ALIGN (dst) < 2 * BITS_PER_UNIT)
17187         set_mem_align (dst, 2 * BITS_PER_UNIT);
17188       if (src_align_bytes >= 0
17189           && (src_align_bytes & 1) == (align_bytes & 1)
17190           && MEM_ALIGN (src) < 2 * BITS_PER_UNIT)
17191         set_mem_align (src, 2 * BITS_PER_UNIT);
17192       off = 2;
17193       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17194     }
17195   if (align_bytes & 4)
17196     {
17197       dst = adjust_automodify_address_nv (dst, SImode, destreg, off);
17198       src = adjust_automodify_address_nv (src, SImode, srcreg, off);
17199       if (MEM_ALIGN (dst) < 4 * BITS_PER_UNIT)
17200         set_mem_align (dst, 4 * BITS_PER_UNIT);
17201       if (src_align_bytes >= 0)
17202         {
17203           unsigned int src_align = 0;
17204           if ((src_align_bytes & 3) == (align_bytes & 3))
17205             src_align = 4;
17206           else if ((src_align_bytes & 1) == (align_bytes & 1))
17207             src_align = 2;
17208           if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
17209             set_mem_align (src, src_align * BITS_PER_UNIT);
17210         }
17211       off = 4;
17212       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17213     }
17214   dst = adjust_automodify_address_nv (dst, BLKmode, destreg, off);
17215   src = adjust_automodify_address_nv (src, BLKmode, srcreg, off);
17216   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
17217     set_mem_align (dst, desired_align * BITS_PER_UNIT);
17218   if (src_align_bytes >= 0)
17219     {
17220       unsigned int src_align = 0;
17221       if ((src_align_bytes & 7) == (align_bytes & 7))
17222         src_align = 8;
17223       else if ((src_align_bytes & 3) == (align_bytes & 3))
17224         src_align = 4;
17225       else if ((src_align_bytes & 1) == (align_bytes & 1))
17226         src_align = 2;
17227       if (src_align > (unsigned int) desired_align)
17228         src_align = desired_align;
17229       if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
17230         set_mem_align (src, src_align * BITS_PER_UNIT);
17231     }
17232   if (dst_size)
17233     set_mem_size (dst, GEN_INT (INTVAL (dst_size) - align_bytes));
17234   if (src_size)
17235     set_mem_size (dst, GEN_INT (INTVAL (src_size) - align_bytes));
17236   *srcp = src;
17237   return dst;
17238 }
17239
17240 /* Set enough from DEST to align DEST known to by aligned by ALIGN to
17241    DESIRED_ALIGNMENT.  */
17242 static void
17243 expand_setmem_prologue (rtx destmem, rtx destptr, rtx value, rtx count,
17244                         int align, int desired_alignment)
17245 {
17246   if (align <= 1 && desired_alignment > 1)
17247     {
17248       rtx label = ix86_expand_aligntest (destptr, 1, false);
17249       destmem = change_address (destmem, QImode, destptr);
17250       emit_insn (gen_strset (destptr, destmem, gen_lowpart (QImode, value)));
17251       ix86_adjust_counter (count, 1);
17252       emit_label (label);
17253       LABEL_NUSES (label) = 1;
17254     }
17255   if (align <= 2 && desired_alignment > 2)
17256     {
17257       rtx label = ix86_expand_aligntest (destptr, 2, false);
17258       destmem = change_address (destmem, HImode, destptr);
17259       emit_insn (gen_strset (destptr, destmem, gen_lowpart (HImode, value)));
17260       ix86_adjust_counter (count, 2);
17261       emit_label (label);
17262       LABEL_NUSES (label) = 1;
17263     }
17264   if (align <= 4 && desired_alignment > 4)
17265     {
17266       rtx label = ix86_expand_aligntest (destptr, 4, false);
17267       destmem = change_address (destmem, SImode, destptr);
17268       emit_insn (gen_strset (destptr, destmem, gen_lowpart (SImode, value)));
17269       ix86_adjust_counter (count, 4);
17270       emit_label (label);
17271       LABEL_NUSES (label) = 1;
17272     }
17273   gcc_assert (desired_alignment <= 8);
17274 }
17275
17276 /* Set enough from DST to align DST known to by aligned by ALIGN to
17277    DESIRED_ALIGN.  ALIGN_BYTES is how many bytes need to be stored.  */
17278 static rtx
17279 expand_constant_setmem_prologue (rtx dst, rtx destreg, rtx value,
17280                                  int desired_align, int align_bytes)
17281 {
17282   int off = 0;
17283   rtx dst_size = MEM_SIZE (dst);
17284   if (align_bytes & 1)
17285     {
17286       dst = adjust_automodify_address_nv (dst, QImode, destreg, 0);
17287       off = 1;
17288       emit_insn (gen_strset (destreg, dst,
17289                              gen_lowpart (QImode, value)));
17290     }
17291   if (align_bytes & 2)
17292     {
17293       dst = adjust_automodify_address_nv (dst, HImode, destreg, off);
17294       if (MEM_ALIGN (dst) < 2 * BITS_PER_UNIT)
17295         set_mem_align (dst, 2 * BITS_PER_UNIT);
17296       off = 2;
17297       emit_insn (gen_strset (destreg, dst,
17298                              gen_lowpart (HImode, value)));
17299     }
17300   if (align_bytes & 4)
17301     {
17302       dst = adjust_automodify_address_nv (dst, SImode, destreg, off);
17303       if (MEM_ALIGN (dst) < 4 * BITS_PER_UNIT)
17304         set_mem_align (dst, 4 * BITS_PER_UNIT);
17305       off = 4;
17306       emit_insn (gen_strset (destreg, dst,
17307                              gen_lowpart (SImode, value)));
17308     }
17309   dst = adjust_automodify_address_nv (dst, BLKmode, destreg, off);
17310   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
17311     set_mem_align (dst, desired_align * BITS_PER_UNIT);
17312   if (dst_size)
17313     set_mem_size (dst, GEN_INT (INTVAL (dst_size) - align_bytes));
17314   return dst;
17315 }
17316
17317 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
17318 static enum stringop_alg
17319 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, bool memset,
17320             int *dynamic_check)
17321 {
17322   const struct stringop_algs * algs;
17323   bool optimize_for_speed;
17324   /* Algorithms using the rep prefix want at least edi and ecx;
17325      additionally, memset wants eax and memcpy wants esi.  Don't
17326      consider such algorithms if the user has appropriated those
17327      registers for their own purposes.  */
17328   bool rep_prefix_usable = !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
17329                              || (memset
17330                                  ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
17331
17332 #define ALG_USABLE_P(alg) (rep_prefix_usable                    \
17333                            || (alg != rep_prefix_1_byte         \
17334                                && alg != rep_prefix_4_byte      \
17335                                && alg != rep_prefix_8_byte))
17336   const struct processor_costs *cost;
17337   
17338   /* Even if the string operation call is cold, we still might spend a lot
17339      of time processing large blocks.  */
17340   if (optimize_function_for_size_p (cfun)
17341       || (optimize_insn_for_size_p ()
17342           && expected_size != -1 && expected_size < 256))
17343     optimize_for_speed = false;
17344   else
17345     optimize_for_speed = true;
17346
17347   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
17348
17349   *dynamic_check = -1;
17350   if (memset)
17351     algs = &cost->memset[TARGET_64BIT != 0];
17352   else
17353     algs = &cost->memcpy[TARGET_64BIT != 0];
17354   if (stringop_alg != no_stringop && ALG_USABLE_P (stringop_alg))
17355     return stringop_alg;
17356   /* rep; movq or rep; movl is the smallest variant.  */
17357   else if (!optimize_for_speed)
17358     {
17359       if (!count || (count & 3))
17360         return rep_prefix_usable ? rep_prefix_1_byte : loop_1_byte;
17361       else
17362         return rep_prefix_usable ? rep_prefix_4_byte : loop;
17363     }
17364   /* Very tiny blocks are best handled via the loop, REP is expensive to setup.
17365    */
17366   else if (expected_size != -1 && expected_size < 4)
17367     return loop_1_byte;
17368   else if (expected_size != -1)
17369     {
17370       unsigned int i;
17371       enum stringop_alg alg = libcall;
17372       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17373         {
17374           /* We get here if the algorithms that were not libcall-based
17375              were rep-prefix based and we are unable to use rep prefixes
17376              based on global register usage.  Break out of the loop and
17377              use the heuristic below.  */
17378           if (algs->size[i].max == 0)
17379             break;
17380           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
17381             {
17382               enum stringop_alg candidate = algs->size[i].alg;
17383
17384               if (candidate != libcall && ALG_USABLE_P (candidate))
17385                 alg = candidate;
17386               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
17387                  last non-libcall inline algorithm.  */
17388               if (TARGET_INLINE_ALL_STRINGOPS)
17389                 {
17390                   /* When the current size is best to be copied by a libcall,
17391                      but we are still forced to inline, run the heuristic below
17392                      that will pick code for medium sized blocks.  */
17393                   if (alg != libcall)
17394                     return alg;
17395                   break;
17396                 }
17397               else if (ALG_USABLE_P (candidate))
17398                 return candidate;
17399             }
17400         }
17401       gcc_assert (TARGET_INLINE_ALL_STRINGOPS || !rep_prefix_usable);
17402     }
17403   /* When asked to inline the call anyway, try to pick meaningful choice.
17404      We look for maximal size of block that is faster to copy by hand and
17405      take blocks of at most of that size guessing that average size will
17406      be roughly half of the block.
17407
17408      If this turns out to be bad, we might simply specify the preferred
17409      choice in ix86_costs.  */
17410   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17411       && (algs->unknown_size == libcall || !ALG_USABLE_P (algs->unknown_size)))
17412     {
17413       int max = -1;
17414       enum stringop_alg alg;
17415       int i;
17416       bool any_alg_usable_p = true;
17417
17418       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17419         {
17420           enum stringop_alg candidate = algs->size[i].alg;
17421           any_alg_usable_p = any_alg_usable_p && ALG_USABLE_P (candidate);
17422
17423           if (candidate != libcall && candidate
17424               && ALG_USABLE_P (candidate))
17425               max = algs->size[i].max;
17426         }
17427       /* If there aren't any usable algorithms, then recursing on
17428          smaller sizes isn't going to find anything.  Just return the
17429          simple byte-at-a-time copy loop.  */
17430       if (!any_alg_usable_p)
17431         {
17432           /* Pick something reasonable.  */
17433           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17434             *dynamic_check = 128;
17435           return loop_1_byte;
17436         }
17437       if (max == -1)
17438         max = 4096;
17439       alg = decide_alg (count, max / 2, memset, dynamic_check);
17440       gcc_assert (*dynamic_check == -1);
17441       gcc_assert (alg != libcall);
17442       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17443         *dynamic_check = max;
17444       return alg;
17445     }
17446   return ALG_USABLE_P (algs->unknown_size) ? algs->unknown_size : libcall;
17447 #undef ALG_USABLE_P
17448 }
17449
17450 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
17451    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
17452 static int
17453 decide_alignment (int align,
17454                   enum stringop_alg alg,
17455                   int expected_size)
17456 {
17457   int desired_align = 0;
17458   switch (alg)
17459     {
17460       case no_stringop:
17461         gcc_unreachable ();
17462       case loop:
17463       case unrolled_loop:
17464         desired_align = GET_MODE_SIZE (Pmode);
17465         break;
17466       case rep_prefix_8_byte:
17467         desired_align = 8;
17468         break;
17469       case rep_prefix_4_byte:
17470         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17471            copying whole cacheline at once.  */
17472         if (TARGET_PENTIUMPRO)
17473           desired_align = 8;
17474         else
17475           desired_align = 4;
17476         break;
17477       case rep_prefix_1_byte:
17478         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17479            copying whole cacheline at once.  */
17480         if (TARGET_PENTIUMPRO)
17481           desired_align = 8;
17482         else
17483           desired_align = 1;
17484         break;
17485       case loop_1_byte:
17486         desired_align = 1;
17487         break;
17488       case libcall:
17489         return 0;
17490     }
17491
17492   if (optimize_size)
17493     desired_align = 1;
17494   if (desired_align < align)
17495     desired_align = align;
17496   if (expected_size != -1 && expected_size < 4)
17497     desired_align = align;
17498   return desired_align;
17499 }
17500
17501 /* Return the smallest power of 2 greater than VAL.  */
17502 static int
17503 smallest_pow2_greater_than (int val)
17504 {
17505   int ret = 1;
17506   while (ret <= val)
17507     ret <<= 1;
17508   return ret;
17509 }
17510
17511 /* Expand string move (memcpy) operation.  Use i386 string operations when
17512    profitable.  expand_setmem contains similar code.  The code depends upon
17513    architecture, block size and alignment, but always has the same
17514    overall structure:
17515
17516    1) Prologue guard: Conditional that jumps up to epilogues for small
17517       blocks that can be handled by epilogue alone.  This is faster but
17518       also needed for correctness, since prologue assume the block is larger
17519       than the desired alignment.
17520
17521       Optional dynamic check for size and libcall for large
17522       blocks is emitted here too, with -minline-stringops-dynamically.
17523
17524    2) Prologue: copy first few bytes in order to get destination aligned
17525       to DESIRED_ALIGN.  It is emitted only when ALIGN is less than
17526       DESIRED_ALIGN and and up to DESIRED_ALIGN - ALIGN bytes can be copied.
17527       We emit either a jump tree on power of two sized blocks, or a byte loop.
17528
17529    3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
17530       with specified algorithm.
17531
17532    4) Epilogue: code copying tail of the block that is too small to be
17533       handled by main body (or up to size guarded by prologue guard).  */
17534
17535 int
17536 ix86_expand_movmem (rtx dst, rtx src, rtx count_exp, rtx align_exp,
17537                     rtx expected_align_exp, rtx expected_size_exp)
17538 {
17539   rtx destreg;
17540   rtx srcreg;
17541   rtx label = NULL;
17542   rtx tmp;
17543   rtx jump_around_label = NULL;
17544   HOST_WIDE_INT align = 1;
17545   unsigned HOST_WIDE_INT count = 0;
17546   HOST_WIDE_INT expected_size = -1;
17547   int size_needed = 0, epilogue_size_needed;
17548   int desired_align = 0, align_bytes = 0;
17549   enum stringop_alg alg;
17550   int dynamic_check;
17551   bool need_zero_guard = false;
17552
17553   if (CONST_INT_P (align_exp))
17554     align = INTVAL (align_exp);
17555   /* i386 can do misaligned access on reasonably increased cost.  */
17556   if (CONST_INT_P (expected_align_exp)
17557       && INTVAL (expected_align_exp) > align)
17558     align = INTVAL (expected_align_exp);
17559   /* ALIGN is the minimum of destination and source alignment, but we care here
17560      just about destination alignment.  */
17561   else if (MEM_ALIGN (dst) > (unsigned HOST_WIDE_INT) align * BITS_PER_UNIT)
17562     align = MEM_ALIGN (dst) / BITS_PER_UNIT;
17563
17564   if (CONST_INT_P (count_exp))
17565     count = expected_size = INTVAL (count_exp);
17566   if (CONST_INT_P (expected_size_exp) && count == 0)
17567     expected_size = INTVAL (expected_size_exp);
17568
17569   /* Make sure we don't need to care about overflow later on.  */
17570   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17571     return 0;
17572
17573   /* Step 0: Decide on preferred algorithm, desired alignment and
17574      size of chunks to be copied by main loop.  */
17575
17576   alg = decide_alg (count, expected_size, false, &dynamic_check);
17577   desired_align = decide_alignment (align, alg, expected_size);
17578
17579   if (!TARGET_ALIGN_STRINGOPS)
17580     align = desired_align;
17581
17582   if (alg == libcall)
17583     return 0;
17584   gcc_assert (alg != no_stringop);
17585   if (!count)
17586     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
17587   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17588   srcreg = copy_to_mode_reg (Pmode, XEXP (src, 0));
17589   switch (alg)
17590     {
17591     case libcall:
17592     case no_stringop:
17593       gcc_unreachable ();
17594     case loop:
17595       need_zero_guard = true;
17596       size_needed = GET_MODE_SIZE (Pmode);
17597       break;
17598     case unrolled_loop:
17599       need_zero_guard = true;
17600       size_needed = GET_MODE_SIZE (Pmode) * (TARGET_64BIT ? 4 : 2);
17601       break;
17602     case rep_prefix_8_byte:
17603       size_needed = 8;
17604       break;
17605     case rep_prefix_4_byte:
17606       size_needed = 4;
17607       break;
17608     case rep_prefix_1_byte:
17609       size_needed = 1;
17610       break;
17611     case loop_1_byte:
17612       need_zero_guard = true;
17613       size_needed = 1;
17614       break;
17615     }
17616
17617   epilogue_size_needed = size_needed;
17618
17619   /* Step 1: Prologue guard.  */
17620
17621   /* Alignment code needs count to be in register.  */
17622   if (CONST_INT_P (count_exp) && desired_align > align)
17623     {
17624       if (INTVAL (count_exp) > desired_align
17625           && INTVAL (count_exp) > size_needed)
17626         {
17627           align_bytes
17628             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
17629           if (align_bytes <= 0)
17630             align_bytes = 0;
17631           else
17632             align_bytes = desired_align - align_bytes;
17633         }
17634       if (align_bytes == 0)
17635         count_exp = force_reg (counter_mode (count_exp), count_exp);
17636     }
17637   gcc_assert (desired_align >= 1 && align >= 1);
17638
17639   /* Ensure that alignment prologue won't copy past end of block.  */
17640   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
17641     {
17642       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
17643       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
17644          Make sure it is power of 2.  */
17645       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
17646
17647       if (CONST_INT_P (count_exp))
17648         {
17649           if (UINTVAL (count_exp) < (unsigned HOST_WIDE_INT)epilogue_size_needed)
17650             goto epilogue;
17651         }
17652       else
17653         {
17654           label = gen_label_rtx ();
17655           emit_cmp_and_jump_insns (count_exp,
17656                                    GEN_INT (epilogue_size_needed),
17657                                    LTU, 0, counter_mode (count_exp), 1, label);
17658           if (expected_size == -1 || expected_size < epilogue_size_needed)
17659             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17660           else
17661             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17662         }
17663     }
17664
17665   /* Emit code to decide on runtime whether library call or inline should be
17666      used.  */
17667   if (dynamic_check != -1)
17668     {
17669       if (CONST_INT_P (count_exp))
17670         {
17671           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
17672             {
17673               emit_block_move_via_libcall (dst, src, count_exp, false);
17674               count_exp = const0_rtx;
17675               goto epilogue;
17676             }
17677         }
17678       else
17679         {
17680           rtx hot_label = gen_label_rtx ();
17681           jump_around_label = gen_label_rtx ();
17682           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
17683                                    LEU, 0, GET_MODE (count_exp), 1, hot_label);
17684           predict_jump (REG_BR_PROB_BASE * 90 / 100);
17685           emit_block_move_via_libcall (dst, src, count_exp, false);
17686           emit_jump (jump_around_label);
17687           emit_label (hot_label);
17688         }
17689     }
17690
17691   /* Step 2: Alignment prologue.  */
17692
17693   if (desired_align > align)
17694     {
17695       if (align_bytes == 0)
17696         {
17697           /* Except for the first move in epilogue, we no longer know
17698              constant offset in aliasing info.  It don't seems to worth
17699              the pain to maintain it for the first move, so throw away
17700              the info early.  */
17701           src = change_address (src, BLKmode, srcreg);
17702           dst = change_address (dst, BLKmode, destreg);
17703           expand_movmem_prologue (dst, src, destreg, srcreg, count_exp, align,
17704                                   desired_align);
17705         }
17706       else
17707         {
17708           /* If we know how many bytes need to be stored before dst is
17709              sufficiently aligned, maintain aliasing info accurately.  */
17710           dst = expand_constant_movmem_prologue (dst, &src, destreg, srcreg,
17711                                                  desired_align, align_bytes);
17712           count_exp = plus_constant (count_exp, -align_bytes);
17713           count -= align_bytes;
17714         }
17715       if (need_zero_guard && !count)
17716         {
17717           /* It is possible that we copied enough so the main loop will not
17718              execute.  */
17719           emit_cmp_and_jump_insns (count_exp,
17720                                    GEN_INT (size_needed),
17721                                    LTU, 0, counter_mode (count_exp), 1, label);
17722           if (expected_size == -1
17723               || expected_size < (desired_align - align) / 2 + size_needed)
17724             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17725           else
17726             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17727         }
17728     }
17729   if (label && size_needed == 1)
17730     {
17731       emit_label (label);
17732       LABEL_NUSES (label) = 1;
17733       label = NULL;
17734     }
17735
17736   /* Step 3: Main loop.  */
17737
17738   switch (alg)
17739     {
17740     case libcall:
17741     case no_stringop:
17742       gcc_unreachable ();
17743     case loop_1_byte:
17744       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17745                                      count_exp, QImode, 1, expected_size);
17746       break;
17747     case loop:
17748       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17749                                      count_exp, Pmode, 1, expected_size);
17750       break;
17751     case unrolled_loop:
17752       /* Unroll only by factor of 2 in 32bit mode, since we don't have enough
17753          registers for 4 temporaries anyway.  */
17754       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17755                                      count_exp, Pmode, TARGET_64BIT ? 4 : 2,
17756                                      expected_size);
17757       break;
17758     case rep_prefix_8_byte:
17759       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17760                                  DImode);
17761       break;
17762     case rep_prefix_4_byte:
17763       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17764                                  SImode);
17765       break;
17766     case rep_prefix_1_byte:
17767       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17768                                  QImode);
17769       break;
17770     }
17771   /* Adjust properly the offset of src and dest memory for aliasing.  */
17772   if (CONST_INT_P (count_exp))
17773     {
17774       src = adjust_automodify_address_nv (src, BLKmode, srcreg,
17775                                           (count / size_needed) * size_needed);
17776       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
17777                                           (count / size_needed) * size_needed);
17778     }
17779   else
17780     {
17781       src = change_address (src, BLKmode, srcreg);
17782       dst = change_address (dst, BLKmode, destreg);
17783     }
17784
17785   /* Step 4: Epilogue to copy the remaining bytes.  */
17786  epilogue:
17787   if (label)
17788     {
17789       /* When the main loop is done, COUNT_EXP might hold original count,
17790          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
17791          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
17792          bytes. Compensate if needed.  */
17793
17794       if (size_needed < epilogue_size_needed)
17795         {
17796           tmp =
17797             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
17798                                  GEN_INT (size_needed - 1), count_exp, 1,
17799                                  OPTAB_DIRECT);
17800           if (tmp != count_exp)
17801             emit_move_insn (count_exp, tmp);
17802         }
17803       emit_label (label);
17804       LABEL_NUSES (label) = 1;
17805     }
17806
17807   if (count_exp != const0_rtx && epilogue_size_needed > 1)
17808     expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
17809                             epilogue_size_needed);
17810   if (jump_around_label)
17811     emit_label (jump_around_label);
17812   return 1;
17813 }
17814
17815 /* Helper function for memcpy.  For QImode value 0xXY produce
17816    0xXYXYXYXY of wide specified by MODE.  This is essentially
17817    a * 0x10101010, but we can do slightly better than
17818    synth_mult by unwinding the sequence by hand on CPUs with
17819    slow multiply.  */
17820 static rtx
17821 promote_duplicated_reg (enum machine_mode mode, rtx val)
17822 {
17823   enum machine_mode valmode = GET_MODE (val);
17824   rtx tmp;
17825   int nops = mode == DImode ? 3 : 2;
17826
17827   gcc_assert (mode == SImode || mode == DImode);
17828   if (val == const0_rtx)
17829     return copy_to_mode_reg (mode, const0_rtx);
17830   if (CONST_INT_P (val))
17831     {
17832       HOST_WIDE_INT v = INTVAL (val) & 255;
17833
17834       v |= v << 8;
17835       v |= v << 16;
17836       if (mode == DImode)
17837         v |= (v << 16) << 16;
17838       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
17839     }
17840
17841   if (valmode == VOIDmode)
17842     valmode = QImode;
17843   if (valmode != QImode)
17844     val = gen_lowpart (QImode, val);
17845   if (mode == QImode)
17846     return val;
17847   if (!TARGET_PARTIAL_REG_STALL)
17848     nops--;
17849   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
17850       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
17851       <= (ix86_cost->shift_const + ix86_cost->add) * nops
17852           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
17853     {
17854       rtx reg = convert_modes (mode, QImode, val, true);
17855       tmp = promote_duplicated_reg (mode, const1_rtx);
17856       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
17857                                   OPTAB_DIRECT);
17858     }
17859   else
17860     {
17861       rtx reg = convert_modes (mode, QImode, val, true);
17862
17863       if (!TARGET_PARTIAL_REG_STALL)
17864         if (mode == SImode)
17865           emit_insn (gen_movsi_insv_1 (reg, reg));
17866         else
17867           emit_insn (gen_movdi_insv_1_rex64 (reg, reg));
17868       else
17869         {
17870           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
17871                                      NULL, 1, OPTAB_DIRECT);
17872           reg =
17873             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17874         }
17875       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
17876                                  NULL, 1, OPTAB_DIRECT);
17877       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17878       if (mode == SImode)
17879         return reg;
17880       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
17881                                  NULL, 1, OPTAB_DIRECT);
17882       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17883       return reg;
17884     }
17885 }
17886
17887 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
17888    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
17889    alignment from ALIGN to DESIRED_ALIGN.  */
17890 static rtx
17891 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align, int align)
17892 {
17893   rtx promoted_val;
17894
17895   if (TARGET_64BIT
17896       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
17897     promoted_val = promote_duplicated_reg (DImode, val);
17898   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
17899     promoted_val = promote_duplicated_reg (SImode, val);
17900   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
17901     promoted_val = promote_duplicated_reg (HImode, val);
17902   else
17903     promoted_val = val;
17904
17905   return promoted_val;
17906 }
17907
17908 /* Expand string clear operation (bzero).  Use i386 string operations when
17909    profitable.  See expand_movmem comment for explanation of individual
17910    steps performed.  */
17911 int
17912 ix86_expand_setmem (rtx dst, rtx count_exp, rtx val_exp, rtx align_exp,
17913                     rtx expected_align_exp, rtx expected_size_exp)
17914 {
17915   rtx destreg;
17916   rtx label = NULL;
17917   rtx tmp;
17918   rtx jump_around_label = NULL;
17919   HOST_WIDE_INT align = 1;
17920   unsigned HOST_WIDE_INT count = 0;
17921   HOST_WIDE_INT expected_size = -1;
17922   int size_needed = 0, epilogue_size_needed;
17923   int desired_align = 0, align_bytes = 0;
17924   enum stringop_alg alg;
17925   rtx promoted_val = NULL;
17926   bool force_loopy_epilogue = false;
17927   int dynamic_check;
17928   bool need_zero_guard = false;
17929
17930   if (CONST_INT_P (align_exp))
17931     align = INTVAL (align_exp);
17932   /* i386 can do misaligned access on reasonably increased cost.  */
17933   if (CONST_INT_P (expected_align_exp)
17934       && INTVAL (expected_align_exp) > align)
17935     align = INTVAL (expected_align_exp);
17936   if (CONST_INT_P (count_exp))
17937     count = expected_size = INTVAL (count_exp);
17938   if (CONST_INT_P (expected_size_exp) && count == 0)
17939     expected_size = INTVAL (expected_size_exp);
17940
17941   /* Make sure we don't need to care about overflow later on.  */
17942   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17943     return 0;
17944
17945   /* Step 0: Decide on preferred algorithm, desired alignment and
17946      size of chunks to be copied by main loop.  */
17947
17948   alg = decide_alg (count, expected_size, true, &dynamic_check);
17949   desired_align = decide_alignment (align, alg, expected_size);
17950
17951   if (!TARGET_ALIGN_STRINGOPS)
17952     align = desired_align;
17953
17954   if (alg == libcall)
17955     return 0;
17956   gcc_assert (alg != no_stringop);
17957   if (!count)
17958     count_exp = copy_to_mode_reg (counter_mode (count_exp), count_exp);
17959   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17960   switch (alg)
17961     {
17962     case libcall:
17963     case no_stringop:
17964       gcc_unreachable ();
17965     case loop:
17966       need_zero_guard = true;
17967       size_needed = GET_MODE_SIZE (Pmode);
17968       break;
17969     case unrolled_loop:
17970       need_zero_guard = true;
17971       size_needed = GET_MODE_SIZE (Pmode) * 4;
17972       break;
17973     case rep_prefix_8_byte:
17974       size_needed = 8;
17975       break;
17976     case rep_prefix_4_byte:
17977       size_needed = 4;
17978       break;
17979     case rep_prefix_1_byte:
17980       size_needed = 1;
17981       break;
17982     case loop_1_byte:
17983       need_zero_guard = true;
17984       size_needed = 1;
17985       break;
17986     }
17987   epilogue_size_needed = size_needed;
17988
17989   /* Step 1: Prologue guard.  */
17990
17991   /* Alignment code needs count to be in register.  */
17992   if (CONST_INT_P (count_exp) && desired_align > align)
17993     {
17994       if (INTVAL (count_exp) > desired_align
17995           && INTVAL (count_exp) > size_needed)
17996         {
17997           align_bytes
17998             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
17999           if (align_bytes <= 0)
18000             align_bytes = 0;
18001           else
18002             align_bytes = desired_align - align_bytes;
18003         }
18004       if (align_bytes == 0)
18005         {
18006           enum machine_mode mode = SImode;
18007           if (TARGET_64BIT && (count & ~0xffffffff))
18008             mode = DImode;
18009           count_exp = force_reg (mode, count_exp);
18010         }
18011     }
18012   /* Do the cheap promotion to allow better CSE across the
18013      main loop and epilogue (ie one load of the big constant in the
18014      front of all code.  */
18015   if (CONST_INT_P (val_exp))
18016     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
18017                                                    desired_align, align);
18018   /* Ensure that alignment prologue won't copy past end of block.  */
18019   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
18020     {
18021       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
18022       /* Epilogue always copies COUNT_EXP & (EPILOGUE_SIZE_NEEDED - 1) bytes.
18023          Make sure it is power of 2.  */
18024       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
18025
18026       /* To improve performance of small blocks, we jump around the VAL
18027          promoting mode.  This mean that if the promoted VAL is not constant,
18028          we might not use it in the epilogue and have to use byte
18029          loop variant.  */
18030       if (epilogue_size_needed > 2 && !promoted_val)
18031         force_loopy_epilogue = true;
18032       label = gen_label_rtx ();
18033       emit_cmp_and_jump_insns (count_exp,
18034                                GEN_INT (epilogue_size_needed),
18035                                LTU, 0, counter_mode (count_exp), 1, label);
18036       if (GET_CODE (count_exp) == CONST_INT)
18037         ;
18038       else if (expected_size == -1 || expected_size <= epilogue_size_needed)
18039         predict_jump (REG_BR_PROB_BASE * 60 / 100);
18040       else
18041         predict_jump (REG_BR_PROB_BASE * 20 / 100);
18042     }
18043   if (dynamic_check != -1)
18044     {
18045       rtx hot_label = gen_label_rtx ();
18046       jump_around_label = gen_label_rtx ();
18047       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
18048                                LEU, 0, counter_mode (count_exp), 1, hot_label);
18049       predict_jump (REG_BR_PROB_BASE * 90 / 100);
18050       set_storage_via_libcall (dst, count_exp, val_exp, false);
18051       emit_jump (jump_around_label);
18052       emit_label (hot_label);
18053     }
18054
18055   /* Step 2: Alignment prologue.  */
18056
18057   /* Do the expensive promotion once we branched off the small blocks.  */
18058   if (!promoted_val)
18059     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
18060                                                    desired_align, align);
18061   gcc_assert (desired_align >= 1 && align >= 1);
18062
18063   if (desired_align > align)
18064     {
18065       if (align_bytes == 0)
18066         {
18067           /* Except for the first move in epilogue, we no longer know
18068              constant offset in aliasing info.  It don't seems to worth
18069              the pain to maintain it for the first move, so throw away
18070              the info early.  */
18071           dst = change_address (dst, BLKmode, destreg);
18072           expand_setmem_prologue (dst, destreg, promoted_val, count_exp, align,
18073                                   desired_align);
18074         }
18075       else
18076         {
18077           /* If we know how many bytes need to be stored before dst is
18078              sufficiently aligned, maintain aliasing info accurately.  */
18079           dst = expand_constant_setmem_prologue (dst, destreg, promoted_val,
18080                                                  desired_align, align_bytes);
18081           count_exp = plus_constant (count_exp, -align_bytes);
18082           count -= align_bytes;
18083         }
18084       if (need_zero_guard && !count)
18085         {
18086           /* It is possible that we copied enough so the main loop will not
18087              execute.  */
18088           emit_cmp_and_jump_insns (count_exp,
18089                                    GEN_INT (size_needed),
18090                                    LTU, 0, counter_mode (count_exp), 1, label);
18091           if (expected_size == -1
18092               || expected_size < (desired_align - align) / 2 + size_needed)
18093             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18094           else
18095             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18096         }
18097     }
18098   if (label && size_needed == 1)
18099     {
18100       emit_label (label);
18101       LABEL_NUSES (label) = 1;
18102       label = NULL;
18103     }
18104
18105   /* Step 3: Main loop.  */
18106
18107   switch (alg)
18108     {
18109     case libcall:
18110     case no_stringop:
18111       gcc_unreachable ();
18112     case loop_1_byte:
18113       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18114                                      count_exp, QImode, 1, expected_size);
18115       break;
18116     case loop:
18117       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18118                                      count_exp, Pmode, 1, expected_size);
18119       break;
18120     case unrolled_loop:
18121       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18122                                      count_exp, Pmode, 4, expected_size);
18123       break;
18124     case rep_prefix_8_byte:
18125       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18126                                   DImode, val_exp);
18127       break;
18128     case rep_prefix_4_byte:
18129       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18130                                   SImode, val_exp);
18131       break;
18132     case rep_prefix_1_byte:
18133       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18134                                   QImode, val_exp);
18135       break;
18136     }
18137   /* Adjust properly the offset of src and dest memory for aliasing.  */
18138   if (CONST_INT_P (count_exp))
18139     dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
18140                                         (count / size_needed) * size_needed);
18141   else
18142     dst = change_address (dst, BLKmode, destreg);
18143
18144   /* Step 4: Epilogue to copy the remaining bytes.  */
18145
18146   if (label)
18147     {
18148       /* When the main loop is done, COUNT_EXP might hold original count,
18149          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
18150          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
18151          bytes. Compensate if needed.  */
18152
18153       if (size_needed < desired_align - align)
18154         {
18155           tmp =
18156             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
18157                                  GEN_INT (size_needed - 1), count_exp, 1,
18158                                  OPTAB_DIRECT);
18159           size_needed = desired_align - align + 1;
18160           if (tmp != count_exp)
18161             emit_move_insn (count_exp, tmp);
18162         }
18163       emit_label (label);
18164       LABEL_NUSES (label) = 1;
18165     }
18166   if (count_exp != const0_rtx && epilogue_size_needed > 1)
18167     {
18168       if (force_loopy_epilogue)
18169         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
18170                                          size_needed);
18171       else
18172         expand_setmem_epilogue (dst, destreg, promoted_val, count_exp,
18173                                 size_needed);
18174     }
18175   if (jump_around_label)
18176     emit_label (jump_around_label);
18177   return 1;
18178 }
18179
18180 /* Expand the appropriate insns for doing strlen if not just doing
18181    repnz; scasb
18182
18183    out = result, initialized with the start address
18184    align_rtx = alignment of the address.
18185    scratch = scratch register, initialized with the startaddress when
18186         not aligned, otherwise undefined
18187
18188    This is just the body. It needs the initializations mentioned above and
18189    some address computing at the end.  These things are done in i386.md.  */
18190
18191 static void
18192 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
18193 {
18194   int align;
18195   rtx tmp;
18196   rtx align_2_label = NULL_RTX;
18197   rtx align_3_label = NULL_RTX;
18198   rtx align_4_label = gen_label_rtx ();
18199   rtx end_0_label = gen_label_rtx ();
18200   rtx mem;
18201   rtx tmpreg = gen_reg_rtx (SImode);
18202   rtx scratch = gen_reg_rtx (SImode);
18203   rtx cmp;
18204
18205   align = 0;
18206   if (CONST_INT_P (align_rtx))
18207     align = INTVAL (align_rtx);
18208
18209   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
18210
18211   /* Is there a known alignment and is it less than 4?  */
18212   if (align < 4)
18213     {
18214       rtx scratch1 = gen_reg_rtx (Pmode);
18215       emit_move_insn (scratch1, out);
18216       /* Is there a known alignment and is it not 2? */
18217       if (align != 2)
18218         {
18219           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
18220           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
18221
18222           /* Leave just the 3 lower bits.  */
18223           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
18224                                     NULL_RTX, 0, OPTAB_WIDEN);
18225
18226           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
18227                                    Pmode, 1, align_4_label);
18228           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
18229                                    Pmode, 1, align_2_label);
18230           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
18231                                    Pmode, 1, align_3_label);
18232         }
18233       else
18234         {
18235           /* Since the alignment is 2, we have to check 2 or 0 bytes;
18236              check if is aligned to 4 - byte.  */
18237
18238           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
18239                                     NULL_RTX, 0, OPTAB_WIDEN);
18240
18241           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
18242                                    Pmode, 1, align_4_label);
18243         }
18244
18245       mem = change_address (src, QImode, out);
18246
18247       /* Now compare the bytes.  */
18248
18249       /* Compare the first n unaligned byte on a byte per byte basis.  */
18250       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
18251                                QImode, 1, end_0_label);
18252
18253       /* Increment the address.  */
18254       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18255
18256       /* Not needed with an alignment of 2 */
18257       if (align != 2)
18258         {
18259           emit_label (align_2_label);
18260
18261           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
18262                                    end_0_label);
18263
18264           emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18265
18266           emit_label (align_3_label);
18267         }
18268
18269       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
18270                                end_0_label);
18271
18272       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18273     }
18274
18275   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
18276      align this loop.  It gives only huge programs, but does not help to
18277      speed up.  */
18278   emit_label (align_4_label);
18279
18280   mem = change_address (src, SImode, out);
18281   emit_move_insn (scratch, mem);
18282   emit_insn ((*ix86_gen_add3) (out, out, GEN_INT (4)));
18283
18284   /* This formula yields a nonzero result iff one of the bytes is zero.
18285      This saves three branches inside loop and many cycles.  */
18286
18287   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
18288   emit_insn (gen_one_cmplsi2 (scratch, scratch));
18289   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
18290   emit_insn (gen_andsi3 (tmpreg, tmpreg,
18291                          gen_int_mode (0x80808080, SImode)));
18292   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
18293                            align_4_label);
18294
18295   if (TARGET_CMOVE)
18296     {
18297        rtx reg = gen_reg_rtx (SImode);
18298        rtx reg2 = gen_reg_rtx (Pmode);
18299        emit_move_insn (reg, tmpreg);
18300        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
18301
18302        /* If zero is not in the first two bytes, move two bytes forward.  */
18303        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
18304        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18305        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
18306        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
18307                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
18308                                                      reg,
18309                                                      tmpreg)));
18310        /* Emit lea manually to avoid clobbering of flags.  */
18311        emit_insn (gen_rtx_SET (SImode, reg2,
18312                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
18313
18314        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18315        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
18316        emit_insn (gen_rtx_SET (VOIDmode, out,
18317                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
18318                                                      reg2,
18319                                                      out)));
18320
18321     }
18322   else
18323     {
18324        rtx end_2_label = gen_label_rtx ();
18325        /* Is zero in the first two bytes? */
18326
18327        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
18328        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18329        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
18330        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
18331                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
18332                             pc_rtx);
18333        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
18334        JUMP_LABEL (tmp) = end_2_label;
18335
18336        /* Not in the first two.  Move two bytes forward.  */
18337        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
18338        emit_insn ((*ix86_gen_add3) (out, out, const2_rtx));
18339
18340        emit_label (end_2_label);
18341
18342     }
18343
18344   /* Avoid branch in fixing the byte.  */
18345   tmpreg = gen_lowpart (QImode, tmpreg);
18346   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
18347   cmp = gen_rtx_LTU (Pmode, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx);
18348   emit_insn ((*ix86_gen_sub3_carry) (out, out, GEN_INT (3), cmp));
18349
18350   emit_label (end_0_label);
18351 }
18352
18353 /* Expand strlen.  */
18354
18355 int
18356 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
18357 {
18358   rtx addr, scratch1, scratch2, scratch3, scratch4;
18359
18360   /* The generic case of strlen expander is long.  Avoid it's
18361      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
18362
18363   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
18364       && !TARGET_INLINE_ALL_STRINGOPS
18365       && !optimize_insn_for_size_p ()
18366       && (!CONST_INT_P (align) || INTVAL (align) < 4))
18367     return 0;
18368
18369   addr = force_reg (Pmode, XEXP (src, 0));
18370   scratch1 = gen_reg_rtx (Pmode);
18371
18372   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
18373       && !optimize_insn_for_size_p ())
18374     {
18375       /* Well it seems that some optimizer does not combine a call like
18376          foo(strlen(bar), strlen(bar));
18377          when the move and the subtraction is done here.  It does calculate
18378          the length just once when these instructions are done inside of
18379          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
18380          often used and I use one fewer register for the lifetime of
18381          output_strlen_unroll() this is better.  */
18382
18383       emit_move_insn (out, addr);
18384
18385       ix86_expand_strlensi_unroll_1 (out, src, align);
18386
18387       /* strlensi_unroll_1 returns the address of the zero at the end of
18388          the string, like memchr(), so compute the length by subtracting
18389          the start address.  */
18390       emit_insn ((*ix86_gen_sub3) (out, out, addr));
18391     }
18392   else
18393     {
18394       rtx unspec;
18395
18396       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
18397       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
18398         return false;
18399
18400       scratch2 = gen_reg_rtx (Pmode);
18401       scratch3 = gen_reg_rtx (Pmode);
18402       scratch4 = force_reg (Pmode, constm1_rtx);
18403
18404       emit_move_insn (scratch3, addr);
18405       eoschar = force_reg (QImode, eoschar);
18406
18407       src = replace_equiv_address_nv (src, scratch3);
18408
18409       /* If .md starts supporting :P, this can be done in .md.  */
18410       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
18411                                                  scratch4), UNSPEC_SCAS);
18412       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
18413       emit_insn ((*ix86_gen_one_cmpl2) (scratch2, scratch1));
18414       emit_insn ((*ix86_gen_add3) (out, scratch2, constm1_rtx));
18415     }
18416   return 1;
18417 }
18418
18419 /* For given symbol (function) construct code to compute address of it's PLT
18420    entry in large x86-64 PIC model.  */
18421 rtx
18422 construct_plt_address (rtx symbol)
18423 {
18424   rtx tmp = gen_reg_rtx (Pmode);
18425   rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
18426
18427   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
18428   gcc_assert (ix86_cmodel == CM_LARGE_PIC);
18429
18430   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
18431   emit_insn (gen_adddi3 (tmp, tmp, pic_offset_table_rtx));
18432   return tmp;
18433 }
18434
18435 void
18436 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
18437                   rtx callarg2,
18438                   rtx pop, int sibcall)
18439 {
18440   rtx use = NULL, call;
18441   enum calling_abi function_call_abi;
18442
18443   if (callarg2 && INTVAL (callarg2) == -2)
18444     function_call_abi = MS_ABI;
18445   else
18446     function_call_abi = SYSV_ABI;
18447   if (pop == const0_rtx)
18448     pop = NULL;
18449   gcc_assert (!TARGET_64BIT || !pop);
18450
18451   if (TARGET_MACHO && !TARGET_64BIT)
18452     {
18453 #if TARGET_MACHO
18454       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
18455         fnaddr = machopic_indirect_call_target (fnaddr);
18456 #endif
18457     }
18458   else
18459     {
18460       /* Static functions and indirect calls don't need the pic register.  */
18461       if (flag_pic && (!TARGET_64BIT || ix86_cmodel == CM_LARGE_PIC)
18462           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18463           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
18464         use_reg (&use, pic_offset_table_rtx);
18465     }
18466
18467   if (TARGET_64BIT && INTVAL (callarg2) >= 0)
18468     {
18469       rtx al = gen_rtx_REG (QImode, AX_REG);
18470       emit_move_insn (al, callarg2);
18471       use_reg (&use, al);
18472     }
18473
18474   if (ix86_cmodel == CM_LARGE_PIC
18475       && GET_CODE (fnaddr) == MEM
18476       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18477       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
18478     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
18479   else if (! call_insn_operand (XEXP (fnaddr, 0), Pmode))
18480     {
18481       fnaddr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18482       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18483     }
18484   if (sibcall && TARGET_64BIT
18485       && !constant_call_address_operand (XEXP (fnaddr, 0), Pmode))
18486     {
18487       rtx addr;
18488       addr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18489       fnaddr = gen_rtx_REG (Pmode, R11_REG);
18490       emit_move_insn (fnaddr, addr);
18491       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18492     }
18493
18494   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
18495   if (retval)
18496     call = gen_rtx_SET (VOIDmode, retval, call);
18497   if (pop)
18498     {
18499       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
18500       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
18501       call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop));
18502       gcc_assert (ix86_cfun_abi () != MS_ABI || function_call_abi != SYSV_ABI);
18503     }
18504   /* We need to represent that SI and DI registers are clobbered
18505      by SYSV calls.  */
18506   if (ix86_cfun_abi () == MS_ABI && function_call_abi == SYSV_ABI)
18507     {
18508       static int clobbered_registers[] = {27, 28, 45, 46, 47, 48, 49, 50, 51,
18509                                           52, SI_REG, DI_REG};
18510       unsigned int i;
18511       rtx vec[ARRAY_SIZE (clobbered_registers) + 2];
18512       rtx unspec = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, const0_rtx),
18513                                    UNSPEC_MS_TO_SYSV_CALL);
18514
18515       vec[0] = call;
18516       vec[1] = unspec;
18517       for (i = 0; i < ARRAY_SIZE (clobbered_registers); i++)
18518         vec[i + 2] = gen_rtx_CLOBBER (SSE_REGNO_P (clobbered_registers[i])
18519                                       ? TImode : DImode,
18520                                       gen_rtx_REG
18521                                         (SSE_REGNO_P (clobbered_registers[i])
18522                                                       ? TImode : DImode,
18523                                          clobbered_registers[i]));
18524
18525       call = gen_rtx_PARALLEL (VOIDmode,
18526                                gen_rtvec_v (ARRAY_SIZE (clobbered_registers)
18527                                + 2, vec));
18528     }
18529
18530   call = emit_call_insn (call);
18531   if (use)
18532     CALL_INSN_FUNCTION_USAGE (call) = use;
18533 }
18534
18535 \f
18536 /* Clear stack slot assignments remembered from previous functions.
18537    This is called from INIT_EXPANDERS once before RTL is emitted for each
18538    function.  */
18539
18540 static struct machine_function *
18541 ix86_init_machine_status (void)
18542 {
18543   struct machine_function *f;
18544
18545   f = GGC_CNEW (struct machine_function);
18546   f->use_fast_prologue_epilogue_nregs = -1;
18547   f->tls_descriptor_call_expanded_p = 0;
18548   f->call_abi = DEFAULT_ABI;
18549
18550   return f;
18551 }
18552
18553 /* Return a MEM corresponding to a stack slot with mode MODE.
18554    Allocate a new slot if necessary.
18555
18556    The RTL for a function can have several slots available: N is
18557    which slot to use.  */
18558
18559 rtx
18560 assign_386_stack_local (enum machine_mode mode, enum ix86_stack_slot n)
18561 {
18562   struct stack_local_entry *s;
18563
18564   gcc_assert (n < MAX_386_STACK_LOCALS);
18565
18566   /* Virtual slot is valid only before vregs are instantiated.  */
18567   gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
18568
18569   for (s = ix86_stack_locals; s; s = s->next)
18570     if (s->mode == mode && s->n == n)
18571       return copy_rtx (s->rtl);
18572
18573   s = (struct stack_local_entry *)
18574     ggc_alloc (sizeof (struct stack_local_entry));
18575   s->n = n;
18576   s->mode = mode;
18577   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
18578
18579   s->next = ix86_stack_locals;
18580   ix86_stack_locals = s;
18581   return s->rtl;
18582 }
18583
18584 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
18585
18586 static GTY(()) rtx ix86_tls_symbol;
18587 rtx
18588 ix86_tls_get_addr (void)
18589 {
18590
18591   if (!ix86_tls_symbol)
18592     {
18593       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode,
18594                                             (TARGET_ANY_GNU_TLS
18595                                              && !TARGET_64BIT)
18596                                             ? "___tls_get_addr"
18597                                             : "__tls_get_addr");
18598     }
18599
18600   return ix86_tls_symbol;
18601 }
18602
18603 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
18604
18605 static GTY(()) rtx ix86_tls_module_base_symbol;
18606 rtx
18607 ix86_tls_module_base (void)
18608 {
18609
18610   if (!ix86_tls_module_base_symbol)
18611     {
18612       ix86_tls_module_base_symbol = gen_rtx_SYMBOL_REF (Pmode,
18613                                                         "_TLS_MODULE_BASE_");
18614       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
18615         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
18616     }
18617
18618   return ix86_tls_module_base_symbol;
18619 }
18620 \f
18621 /* Calculate the length of the memory address in the instruction
18622    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
18623
18624 int
18625 memory_address_length (rtx addr)
18626 {
18627   struct ix86_address parts;
18628   rtx base, index, disp;
18629   int len;
18630   int ok;
18631
18632   if (GET_CODE (addr) == PRE_DEC
18633       || GET_CODE (addr) == POST_INC
18634       || GET_CODE (addr) == PRE_MODIFY
18635       || GET_CODE (addr) == POST_MODIFY)
18636     return 0;
18637
18638   ok = ix86_decompose_address (addr, &parts);
18639   gcc_assert (ok);
18640
18641   if (parts.base && GET_CODE (parts.base) == SUBREG)
18642     parts.base = SUBREG_REG (parts.base);
18643   if (parts.index && GET_CODE (parts.index) == SUBREG)
18644     parts.index = SUBREG_REG (parts.index);
18645
18646   base = parts.base;
18647   index = parts.index;
18648   disp = parts.disp;
18649   len = 0;
18650
18651   /* Rule of thumb:
18652        - esp as the base always wants an index,
18653        - ebp as the base always wants a displacement.  */
18654
18655   /* Register Indirect.  */
18656   if (base && !index && !disp)
18657     {
18658       /* esp (for its index) and ebp (for its displacement) need
18659          the two-byte modrm form.  */
18660       if (addr == stack_pointer_rtx
18661           || addr == arg_pointer_rtx
18662           || addr == frame_pointer_rtx
18663           || addr == hard_frame_pointer_rtx)
18664         len = 1;
18665     }
18666
18667   /* Direct Addressing.  */
18668   else if (disp && !base && !index)
18669     len = 4;
18670
18671   else
18672     {
18673       /* Find the length of the displacement constant.  */
18674       if (disp)
18675         {
18676           if (base && satisfies_constraint_K (disp))
18677             len = 1;
18678           else
18679             len = 4;
18680         }
18681       /* ebp always wants a displacement.  */
18682       else if (base == hard_frame_pointer_rtx)
18683         len = 1;
18684
18685       /* An index requires the two-byte modrm form....  */
18686       if (index
18687           /* ...like esp, which always wants an index.  */
18688           || base == stack_pointer_rtx
18689           || base == arg_pointer_rtx
18690           || base == frame_pointer_rtx)
18691         len += 1;
18692     }
18693
18694   return len;
18695 }
18696
18697 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
18698    is set, expect that insn have 8bit immediate alternative.  */
18699 int
18700 ix86_attr_length_immediate_default (rtx insn, int shortform)
18701 {
18702   int len = 0;
18703   int i;
18704   extract_insn_cached (insn);
18705   for (i = recog_data.n_operands - 1; i >= 0; --i)
18706     if (CONSTANT_P (recog_data.operand[i]))
18707       {
18708         gcc_assert (!len);
18709         if (shortform && satisfies_constraint_K (recog_data.operand[i]))
18710           len = 1;
18711         else
18712           {
18713             switch (get_attr_mode (insn))
18714               {
18715                 case MODE_QI:
18716                   len+=1;
18717                   break;
18718                 case MODE_HI:
18719                   len+=2;
18720                   break;
18721                 case MODE_SI:
18722                   len+=4;
18723                   break;
18724                 /* Immediates for DImode instructions are encoded as 32bit sign extended values.  */
18725                 case MODE_DI:
18726                   len+=4;
18727                   break;
18728                 default:
18729                   fatal_insn ("unknown insn mode", insn);
18730               }
18731           }
18732       }
18733   return len;
18734 }
18735 /* Compute default value for "length_address" attribute.  */
18736 int
18737 ix86_attr_length_address_default (rtx insn)
18738 {
18739   int i;
18740
18741   if (get_attr_type (insn) == TYPE_LEA)
18742     {
18743       rtx set = PATTERN (insn);
18744
18745       if (GET_CODE (set) == PARALLEL)
18746         set = XVECEXP (set, 0, 0);
18747
18748       gcc_assert (GET_CODE (set) == SET);
18749
18750       return memory_address_length (SET_SRC (set));
18751     }
18752
18753   extract_insn_cached (insn);
18754   for (i = recog_data.n_operands - 1; i >= 0; --i)
18755     if (MEM_P (recog_data.operand[i]))
18756       {
18757         return memory_address_length (XEXP (recog_data.operand[i], 0));
18758         break;
18759       }
18760   return 0;
18761 }
18762
18763 /* Compute default value for "length_vex" attribute. It includes
18764    2 or 3 byte VEX prefix and 1 opcode byte.  */
18765
18766 int
18767 ix86_attr_length_vex_default (rtx insn, int has_0f_opcode,
18768                               int has_vex_w)
18769 {
18770   int i;
18771
18772   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
18773      byte VEX prefix.  */
18774   if (!has_0f_opcode || has_vex_w)
18775     return 3 + 1;
18776
18777  /* We can always use 2 byte VEX prefix in 32bit.  */
18778   if (!TARGET_64BIT)
18779     return 2 + 1;
18780
18781   extract_insn_cached (insn);
18782
18783   for (i = recog_data.n_operands - 1; i >= 0; --i)
18784     if (REG_P (recog_data.operand[i]))
18785       {
18786         /* REX.W bit uses 3 byte VEX prefix.  */
18787         if (GET_MODE (recog_data.operand[i]) == DImode)
18788           return 3 + 1;
18789       }
18790     else
18791       {
18792         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
18793         if (MEM_P (recog_data.operand[i])
18794             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
18795           return 3 + 1;
18796       }
18797
18798   return 2 + 1;
18799 }
18800 \f
18801 /* Return the maximum number of instructions a cpu can issue.  */
18802
18803 static int
18804 ix86_issue_rate (void)
18805 {
18806   switch (ix86_tune)
18807     {
18808     case PROCESSOR_PENTIUM:
18809     case PROCESSOR_K6:
18810       return 2;
18811
18812     case PROCESSOR_PENTIUMPRO:
18813     case PROCESSOR_PENTIUM4:
18814     case PROCESSOR_ATHLON:
18815     case PROCESSOR_K8:
18816     case PROCESSOR_AMDFAM10:
18817     case PROCESSOR_NOCONA:
18818     case PROCESSOR_GENERIC32:
18819     case PROCESSOR_GENERIC64:
18820       return 3;
18821
18822     case PROCESSOR_CORE2:
18823       return 4;
18824
18825     default:
18826       return 1;
18827     }
18828 }
18829
18830 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
18831    by DEP_INSN and nothing set by DEP_INSN.  */
18832
18833 static int
18834 ix86_flags_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
18835 {
18836   rtx set, set2;
18837
18838   /* Simplify the test for uninteresting insns.  */
18839   if (insn_type != TYPE_SETCC
18840       && insn_type != TYPE_ICMOV
18841       && insn_type != TYPE_FCMOV
18842       && insn_type != TYPE_IBR)
18843     return 0;
18844
18845   if ((set = single_set (dep_insn)) != 0)
18846     {
18847       set = SET_DEST (set);
18848       set2 = NULL_RTX;
18849     }
18850   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
18851            && XVECLEN (PATTERN (dep_insn), 0) == 2
18852            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
18853            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
18854     {
18855       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
18856       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
18857     }
18858   else
18859     return 0;
18860
18861   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
18862     return 0;
18863
18864   /* This test is true if the dependent insn reads the flags but
18865      not any other potentially set register.  */
18866   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
18867     return 0;
18868
18869   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
18870     return 0;
18871
18872   return 1;
18873 }
18874
18875 /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory
18876    address with operands set by DEP_INSN.  */
18877
18878 static int
18879 ix86_agi_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
18880 {
18881   rtx addr;
18882
18883   if (insn_type == TYPE_LEA
18884       && TARGET_PENTIUM)
18885     {
18886       addr = PATTERN (insn);
18887
18888       if (GET_CODE (addr) == PARALLEL)
18889         addr = XVECEXP (addr, 0, 0);
18890
18891       gcc_assert (GET_CODE (addr) == SET);
18892
18893       addr = SET_SRC (addr);
18894     }
18895   else
18896     {
18897       int i;
18898       extract_insn_cached (insn);
18899       for (i = recog_data.n_operands - 1; i >= 0; --i)
18900         if (MEM_P (recog_data.operand[i]))
18901           {
18902             addr = XEXP (recog_data.operand[i], 0);
18903             goto found;
18904           }
18905       return 0;
18906     found:;
18907     }
18908
18909   return modified_in_p (addr, dep_insn);
18910 }
18911
18912 static int
18913 ix86_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
18914 {
18915   enum attr_type insn_type, dep_insn_type;
18916   enum attr_memory memory;
18917   rtx set, set2;
18918   int dep_insn_code_number;
18919
18920   /* Anti and output dependencies have zero cost on all CPUs.  */
18921   if (REG_NOTE_KIND (link) != 0)
18922     return 0;
18923
18924   dep_insn_code_number = recog_memoized (dep_insn);
18925
18926   /* If we can't recognize the insns, we can't really do anything.  */
18927   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
18928     return cost;
18929
18930   insn_type = get_attr_type (insn);
18931   dep_insn_type = get_attr_type (dep_insn);
18932
18933   switch (ix86_tune)
18934     {
18935     case PROCESSOR_PENTIUM:
18936       /* Address Generation Interlock adds a cycle of latency.  */
18937       if (ix86_agi_dependent (insn, dep_insn, insn_type))
18938         cost += 1;
18939
18940       /* ??? Compares pair with jump/setcc.  */
18941       if (ix86_flags_dependent (insn, dep_insn, insn_type))
18942         cost = 0;
18943
18944       /* Floating point stores require value to be ready one cycle earlier.  */
18945       if (insn_type == TYPE_FMOV
18946           && get_attr_memory (insn) == MEMORY_STORE
18947           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18948         cost += 1;
18949       break;
18950
18951     case PROCESSOR_PENTIUMPRO:
18952       memory = get_attr_memory (insn);
18953
18954       /* INT->FP conversion is expensive.  */
18955       if (get_attr_fp_int_src (dep_insn))
18956         cost += 5;
18957
18958       /* There is one cycle extra latency between an FP op and a store.  */
18959       if (insn_type == TYPE_FMOV
18960           && (set = single_set (dep_insn)) != NULL_RTX
18961           && (set2 = single_set (insn)) != NULL_RTX
18962           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
18963           && MEM_P (SET_DEST (set2)))
18964         cost += 1;
18965
18966       /* Show ability of reorder buffer to hide latency of load by executing
18967          in parallel with previous instruction in case
18968          previous instruction is not needed to compute the address.  */
18969       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18970           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18971         {
18972           /* Claim moves to take one cycle, as core can issue one load
18973              at time and the next load can start cycle later.  */
18974           if (dep_insn_type == TYPE_IMOV
18975               || dep_insn_type == TYPE_FMOV)
18976             cost = 1;
18977           else if (cost > 1)
18978             cost--;
18979         }
18980       break;
18981
18982     case PROCESSOR_K6:
18983       memory = get_attr_memory (insn);
18984
18985       /* The esp dependency is resolved before the instruction is really
18986          finished.  */
18987       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
18988           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
18989         return 1;
18990
18991       /* INT->FP conversion is expensive.  */
18992       if (get_attr_fp_int_src (dep_insn))
18993         cost += 5;
18994
18995       /* Show ability of reorder buffer to hide latency of load by executing
18996          in parallel with previous instruction in case
18997          previous instruction is not needed to compute the address.  */
18998       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18999           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19000         {
19001           /* Claim moves to take one cycle, as core can issue one load
19002              at time and the next load can start cycle later.  */
19003           if (dep_insn_type == TYPE_IMOV
19004               || dep_insn_type == TYPE_FMOV)
19005             cost = 1;
19006           else if (cost > 2)
19007             cost -= 2;
19008           else
19009             cost = 1;
19010         }
19011       break;
19012
19013     case PROCESSOR_ATHLON:
19014     case PROCESSOR_K8:
19015     case PROCESSOR_AMDFAM10:
19016     case PROCESSOR_GENERIC32:
19017     case PROCESSOR_GENERIC64:
19018       memory = get_attr_memory (insn);
19019
19020       /* Show ability of reorder buffer to hide latency of load by executing
19021          in parallel with previous instruction in case
19022          previous instruction is not needed to compute the address.  */
19023       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19024           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19025         {
19026           enum attr_unit unit = get_attr_unit (insn);
19027           int loadcost = 3;
19028
19029           /* Because of the difference between the length of integer and
19030              floating unit pipeline preparation stages, the memory operands
19031              for floating point are cheaper.
19032
19033              ??? For Athlon it the difference is most probably 2.  */
19034           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
19035             loadcost = 3;
19036           else
19037             loadcost = TARGET_ATHLON ? 2 : 0;
19038
19039           if (cost >= loadcost)
19040             cost -= loadcost;
19041           else
19042             cost = 0;
19043         }
19044
19045     default:
19046       break;
19047     }
19048
19049   return cost;
19050 }
19051
19052 /* How many alternative schedules to try.  This should be as wide as the
19053    scheduling freedom in the DFA, but no wider.  Making this value too
19054    large results extra work for the scheduler.  */
19055
19056 static int
19057 ia32_multipass_dfa_lookahead (void)
19058 {
19059   switch (ix86_tune)
19060     {
19061     case PROCESSOR_PENTIUM:
19062       return 2;
19063
19064     case PROCESSOR_PENTIUMPRO:
19065     case PROCESSOR_K6:
19066       return 1;
19067
19068     default:
19069       return 0;
19070     }
19071 }
19072
19073 \f
19074 /* Compute the alignment given to a constant that is being placed in memory.
19075    EXP is the constant and ALIGN is the alignment that the object would
19076    ordinarily have.
19077    The value of this function is used instead of that alignment to align
19078    the object.  */
19079
19080 int
19081 ix86_constant_alignment (tree exp, int align)
19082 {
19083   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
19084       || TREE_CODE (exp) == INTEGER_CST)
19085     {
19086       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
19087         return 64;
19088       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
19089         return 128;
19090     }
19091   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
19092            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
19093     return BITS_PER_WORD;
19094
19095   return align;
19096 }
19097
19098 /* Compute the alignment for a static variable.
19099    TYPE is the data type, and ALIGN is the alignment that
19100    the object would ordinarily have.  The value of this function is used
19101    instead of that alignment to align the object.  */
19102
19103 int
19104 ix86_data_alignment (tree type, int align)
19105 {
19106   int max_align = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
19107
19108   if (AGGREGATE_TYPE_P (type)
19109       && TYPE_SIZE (type)
19110       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19111       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= (unsigned) max_align
19112           || TREE_INT_CST_HIGH (TYPE_SIZE (type)))
19113       && align < max_align)
19114     align = max_align;
19115
19116   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
19117      to 16byte boundary.  */
19118   if (TARGET_64BIT)
19119     {
19120       if (AGGREGATE_TYPE_P (type)
19121            && TYPE_SIZE (type)
19122            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19123            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 128
19124                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
19125         return 128;
19126     }
19127
19128   if (TREE_CODE (type) == ARRAY_TYPE)
19129     {
19130       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
19131         return 64;
19132       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
19133         return 128;
19134     }
19135   else if (TREE_CODE (type) == COMPLEX_TYPE)
19136     {
19137
19138       if (TYPE_MODE (type) == DCmode && align < 64)
19139         return 64;
19140       if ((TYPE_MODE (type) == XCmode
19141            || TYPE_MODE (type) == TCmode) && align < 128)
19142         return 128;
19143     }
19144   else if ((TREE_CODE (type) == RECORD_TYPE
19145             || TREE_CODE (type) == UNION_TYPE
19146             || TREE_CODE (type) == QUAL_UNION_TYPE)
19147            && TYPE_FIELDS (type))
19148     {
19149       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
19150         return 64;
19151       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
19152         return 128;
19153     }
19154   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
19155            || TREE_CODE (type) == INTEGER_TYPE)
19156     {
19157       if (TYPE_MODE (type) == DFmode && align < 64)
19158         return 64;
19159       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
19160         return 128;
19161     }
19162
19163   return align;
19164 }
19165
19166 /* Compute the alignment for a local variable or a stack slot.  TYPE is
19167    the data type, MODE is the widest mode available and ALIGN is the
19168    alignment that the object would ordinarily have.  The value of this
19169    macro is used instead of that alignment to align the object.  */
19170
19171 unsigned int
19172 ix86_local_alignment (tree type, enum machine_mode mode,
19173                       unsigned int align)
19174 {
19175   /* If TYPE is NULL, we are allocating a stack slot for caller-save
19176      register in MODE.  We will return the largest alignment of XF
19177      and DF.  */
19178   if (!type)
19179     {
19180       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
19181         align = GET_MODE_ALIGNMENT (DFmode);
19182       return align;
19183     }
19184
19185   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
19186      to 16byte boundary.  */
19187   if (TARGET_64BIT)
19188     {
19189       if (AGGREGATE_TYPE_P (type)
19190            && TYPE_SIZE (type)
19191            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19192            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16
19193                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
19194         return 128;
19195     }
19196   if (TREE_CODE (type) == ARRAY_TYPE)
19197     {
19198       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
19199         return 64;
19200       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
19201         return 128;
19202     }
19203   else if (TREE_CODE (type) == COMPLEX_TYPE)
19204     {
19205       if (TYPE_MODE (type) == DCmode && align < 64)
19206         return 64;
19207       if ((TYPE_MODE (type) == XCmode
19208            || TYPE_MODE (type) == TCmode) && align < 128)
19209         return 128;
19210     }
19211   else if ((TREE_CODE (type) == RECORD_TYPE
19212             || TREE_CODE (type) == UNION_TYPE
19213             || TREE_CODE (type) == QUAL_UNION_TYPE)
19214            && TYPE_FIELDS (type))
19215     {
19216       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
19217         return 64;
19218       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
19219         return 128;
19220     }
19221   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
19222            || TREE_CODE (type) == INTEGER_TYPE)
19223     {
19224
19225       if (TYPE_MODE (type) == DFmode && align < 64)
19226         return 64;
19227       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
19228         return 128;
19229     }
19230   return align;
19231 }
19232 \f
19233 /* Emit RTL insns to initialize the variable parts of a trampoline.
19234    FNADDR is an RTX for the address of the function's pure code.
19235    CXT is an RTX for the static chain value for the function.  */
19236 void
19237 x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
19238 {
19239   if (!TARGET_64BIT)
19240     {
19241       /* Compute offset from the end of the jmp to the target function.  */
19242       rtx disp = expand_binop (SImode, sub_optab, fnaddr,
19243                                plus_constant (tramp, 10),
19244                                NULL_RTX, 1, OPTAB_DIRECT);
19245       emit_move_insn (gen_rtx_MEM (QImode, tramp),
19246                       gen_int_mode (0xb9, QImode));
19247       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
19248       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
19249                       gen_int_mode (0xe9, QImode));
19250       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
19251     }
19252   else
19253     {
19254       int offset = 0;
19255       /* Try to load address using shorter movl instead of movabs.
19256          We may want to support movq for kernel mode, but kernel does not use
19257          trampolines at the moment.  */
19258       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
19259         {
19260           fnaddr = copy_to_mode_reg (DImode, fnaddr);
19261           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19262                           gen_int_mode (0xbb41, HImode));
19263           emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
19264                           gen_lowpart (SImode, fnaddr));
19265           offset += 6;
19266         }
19267       else
19268         {
19269           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19270                           gen_int_mode (0xbb49, HImode));
19271           emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
19272                           fnaddr);
19273           offset += 10;
19274         }
19275       /* Load static chain using movabs to r10.  */
19276       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19277                       gen_int_mode (0xba49, HImode));
19278       emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
19279                       cxt);
19280       offset += 10;
19281       /* Jump to the r11 */
19282       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19283                       gen_int_mode (0xff49, HImode));
19284       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
19285                       gen_int_mode (0xe3, QImode));
19286       offset += 3;
19287       gcc_assert (offset <= TRAMPOLINE_SIZE);
19288     }
19289
19290 #ifdef ENABLE_EXECUTE_STACK
19291   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
19292                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
19293 #endif
19294 }
19295 \f
19296 /* Codes for all the SSE/MMX builtins.  */
19297 enum ix86_builtins
19298 {
19299   IX86_BUILTIN_ADDPS,
19300   IX86_BUILTIN_ADDSS,
19301   IX86_BUILTIN_DIVPS,
19302   IX86_BUILTIN_DIVSS,
19303   IX86_BUILTIN_MULPS,
19304   IX86_BUILTIN_MULSS,
19305   IX86_BUILTIN_SUBPS,
19306   IX86_BUILTIN_SUBSS,
19307
19308   IX86_BUILTIN_CMPEQPS,
19309   IX86_BUILTIN_CMPLTPS,
19310   IX86_BUILTIN_CMPLEPS,
19311   IX86_BUILTIN_CMPGTPS,
19312   IX86_BUILTIN_CMPGEPS,
19313   IX86_BUILTIN_CMPNEQPS,
19314   IX86_BUILTIN_CMPNLTPS,
19315   IX86_BUILTIN_CMPNLEPS,
19316   IX86_BUILTIN_CMPNGTPS,
19317   IX86_BUILTIN_CMPNGEPS,
19318   IX86_BUILTIN_CMPORDPS,
19319   IX86_BUILTIN_CMPUNORDPS,
19320   IX86_BUILTIN_CMPEQSS,
19321   IX86_BUILTIN_CMPLTSS,
19322   IX86_BUILTIN_CMPLESS,
19323   IX86_BUILTIN_CMPNEQSS,
19324   IX86_BUILTIN_CMPNLTSS,
19325   IX86_BUILTIN_CMPNLESS,
19326   IX86_BUILTIN_CMPNGTSS,
19327   IX86_BUILTIN_CMPNGESS,
19328   IX86_BUILTIN_CMPORDSS,
19329   IX86_BUILTIN_CMPUNORDSS,
19330
19331   IX86_BUILTIN_COMIEQSS,
19332   IX86_BUILTIN_COMILTSS,
19333   IX86_BUILTIN_COMILESS,
19334   IX86_BUILTIN_COMIGTSS,
19335   IX86_BUILTIN_COMIGESS,
19336   IX86_BUILTIN_COMINEQSS,
19337   IX86_BUILTIN_UCOMIEQSS,
19338   IX86_BUILTIN_UCOMILTSS,
19339   IX86_BUILTIN_UCOMILESS,
19340   IX86_BUILTIN_UCOMIGTSS,
19341   IX86_BUILTIN_UCOMIGESS,
19342   IX86_BUILTIN_UCOMINEQSS,
19343
19344   IX86_BUILTIN_CVTPI2PS,
19345   IX86_BUILTIN_CVTPS2PI,
19346   IX86_BUILTIN_CVTSI2SS,
19347   IX86_BUILTIN_CVTSI642SS,
19348   IX86_BUILTIN_CVTSS2SI,
19349   IX86_BUILTIN_CVTSS2SI64,
19350   IX86_BUILTIN_CVTTPS2PI,
19351   IX86_BUILTIN_CVTTSS2SI,
19352   IX86_BUILTIN_CVTTSS2SI64,
19353
19354   IX86_BUILTIN_MAXPS,
19355   IX86_BUILTIN_MAXSS,
19356   IX86_BUILTIN_MINPS,
19357   IX86_BUILTIN_MINSS,
19358
19359   IX86_BUILTIN_LOADUPS,
19360   IX86_BUILTIN_STOREUPS,
19361   IX86_BUILTIN_MOVSS,
19362
19363   IX86_BUILTIN_MOVHLPS,
19364   IX86_BUILTIN_MOVLHPS,
19365   IX86_BUILTIN_LOADHPS,
19366   IX86_BUILTIN_LOADLPS,
19367   IX86_BUILTIN_STOREHPS,
19368   IX86_BUILTIN_STORELPS,
19369
19370   IX86_BUILTIN_MASKMOVQ,
19371   IX86_BUILTIN_MOVMSKPS,
19372   IX86_BUILTIN_PMOVMSKB,
19373
19374   IX86_BUILTIN_MOVNTPS,
19375   IX86_BUILTIN_MOVNTQ,
19376
19377   IX86_BUILTIN_LOADDQU,
19378   IX86_BUILTIN_STOREDQU,
19379
19380   IX86_BUILTIN_PACKSSWB,
19381   IX86_BUILTIN_PACKSSDW,
19382   IX86_BUILTIN_PACKUSWB,
19383
19384   IX86_BUILTIN_PADDB,
19385   IX86_BUILTIN_PADDW,
19386   IX86_BUILTIN_PADDD,
19387   IX86_BUILTIN_PADDQ,
19388   IX86_BUILTIN_PADDSB,
19389   IX86_BUILTIN_PADDSW,
19390   IX86_BUILTIN_PADDUSB,
19391   IX86_BUILTIN_PADDUSW,
19392   IX86_BUILTIN_PSUBB,
19393   IX86_BUILTIN_PSUBW,
19394   IX86_BUILTIN_PSUBD,
19395   IX86_BUILTIN_PSUBQ,
19396   IX86_BUILTIN_PSUBSB,
19397   IX86_BUILTIN_PSUBSW,
19398   IX86_BUILTIN_PSUBUSB,
19399   IX86_BUILTIN_PSUBUSW,
19400
19401   IX86_BUILTIN_PAND,
19402   IX86_BUILTIN_PANDN,
19403   IX86_BUILTIN_POR,
19404   IX86_BUILTIN_PXOR,
19405
19406   IX86_BUILTIN_PAVGB,
19407   IX86_BUILTIN_PAVGW,
19408
19409   IX86_BUILTIN_PCMPEQB,
19410   IX86_BUILTIN_PCMPEQW,
19411   IX86_BUILTIN_PCMPEQD,
19412   IX86_BUILTIN_PCMPGTB,
19413   IX86_BUILTIN_PCMPGTW,
19414   IX86_BUILTIN_PCMPGTD,
19415
19416   IX86_BUILTIN_PMADDWD,
19417
19418   IX86_BUILTIN_PMAXSW,
19419   IX86_BUILTIN_PMAXUB,
19420   IX86_BUILTIN_PMINSW,
19421   IX86_BUILTIN_PMINUB,
19422
19423   IX86_BUILTIN_PMULHUW,
19424   IX86_BUILTIN_PMULHW,
19425   IX86_BUILTIN_PMULLW,
19426
19427   IX86_BUILTIN_PSADBW,
19428   IX86_BUILTIN_PSHUFW,
19429
19430   IX86_BUILTIN_PSLLW,
19431   IX86_BUILTIN_PSLLD,
19432   IX86_BUILTIN_PSLLQ,
19433   IX86_BUILTIN_PSRAW,
19434   IX86_BUILTIN_PSRAD,
19435   IX86_BUILTIN_PSRLW,
19436   IX86_BUILTIN_PSRLD,
19437   IX86_BUILTIN_PSRLQ,
19438   IX86_BUILTIN_PSLLWI,
19439   IX86_BUILTIN_PSLLDI,
19440   IX86_BUILTIN_PSLLQI,
19441   IX86_BUILTIN_PSRAWI,
19442   IX86_BUILTIN_PSRADI,
19443   IX86_BUILTIN_PSRLWI,
19444   IX86_BUILTIN_PSRLDI,
19445   IX86_BUILTIN_PSRLQI,
19446
19447   IX86_BUILTIN_PUNPCKHBW,
19448   IX86_BUILTIN_PUNPCKHWD,
19449   IX86_BUILTIN_PUNPCKHDQ,
19450   IX86_BUILTIN_PUNPCKLBW,
19451   IX86_BUILTIN_PUNPCKLWD,
19452   IX86_BUILTIN_PUNPCKLDQ,
19453
19454   IX86_BUILTIN_SHUFPS,
19455
19456   IX86_BUILTIN_RCPPS,
19457   IX86_BUILTIN_RCPSS,
19458   IX86_BUILTIN_RSQRTPS,
19459   IX86_BUILTIN_RSQRTPS_NR,
19460   IX86_BUILTIN_RSQRTSS,
19461   IX86_BUILTIN_RSQRTF,
19462   IX86_BUILTIN_SQRTPS,
19463   IX86_BUILTIN_SQRTPS_NR,
19464   IX86_BUILTIN_SQRTSS,
19465
19466   IX86_BUILTIN_UNPCKHPS,
19467   IX86_BUILTIN_UNPCKLPS,
19468
19469   IX86_BUILTIN_ANDPS,
19470   IX86_BUILTIN_ANDNPS,
19471   IX86_BUILTIN_ORPS,
19472   IX86_BUILTIN_XORPS,
19473
19474   IX86_BUILTIN_EMMS,
19475   IX86_BUILTIN_LDMXCSR,
19476   IX86_BUILTIN_STMXCSR,
19477   IX86_BUILTIN_SFENCE,
19478
19479   /* 3DNow! Original */
19480   IX86_BUILTIN_FEMMS,
19481   IX86_BUILTIN_PAVGUSB,
19482   IX86_BUILTIN_PF2ID,
19483   IX86_BUILTIN_PFACC,
19484   IX86_BUILTIN_PFADD,
19485   IX86_BUILTIN_PFCMPEQ,
19486   IX86_BUILTIN_PFCMPGE,
19487   IX86_BUILTIN_PFCMPGT,
19488   IX86_BUILTIN_PFMAX,
19489   IX86_BUILTIN_PFMIN,
19490   IX86_BUILTIN_PFMUL,
19491   IX86_BUILTIN_PFRCP,
19492   IX86_BUILTIN_PFRCPIT1,
19493   IX86_BUILTIN_PFRCPIT2,
19494   IX86_BUILTIN_PFRSQIT1,
19495   IX86_BUILTIN_PFRSQRT,
19496   IX86_BUILTIN_PFSUB,
19497   IX86_BUILTIN_PFSUBR,
19498   IX86_BUILTIN_PI2FD,
19499   IX86_BUILTIN_PMULHRW,
19500
19501   /* 3DNow! Athlon Extensions */
19502   IX86_BUILTIN_PF2IW,
19503   IX86_BUILTIN_PFNACC,
19504   IX86_BUILTIN_PFPNACC,
19505   IX86_BUILTIN_PI2FW,
19506   IX86_BUILTIN_PSWAPDSI,
19507   IX86_BUILTIN_PSWAPDSF,
19508
19509   /* SSE2 */
19510   IX86_BUILTIN_ADDPD,
19511   IX86_BUILTIN_ADDSD,
19512   IX86_BUILTIN_DIVPD,
19513   IX86_BUILTIN_DIVSD,
19514   IX86_BUILTIN_MULPD,
19515   IX86_BUILTIN_MULSD,
19516   IX86_BUILTIN_SUBPD,
19517   IX86_BUILTIN_SUBSD,
19518
19519   IX86_BUILTIN_CMPEQPD,
19520   IX86_BUILTIN_CMPLTPD,
19521   IX86_BUILTIN_CMPLEPD,
19522   IX86_BUILTIN_CMPGTPD,
19523   IX86_BUILTIN_CMPGEPD,
19524   IX86_BUILTIN_CMPNEQPD,
19525   IX86_BUILTIN_CMPNLTPD,
19526   IX86_BUILTIN_CMPNLEPD,
19527   IX86_BUILTIN_CMPNGTPD,
19528   IX86_BUILTIN_CMPNGEPD,
19529   IX86_BUILTIN_CMPORDPD,
19530   IX86_BUILTIN_CMPUNORDPD,
19531   IX86_BUILTIN_CMPEQSD,
19532   IX86_BUILTIN_CMPLTSD,
19533   IX86_BUILTIN_CMPLESD,
19534   IX86_BUILTIN_CMPNEQSD,
19535   IX86_BUILTIN_CMPNLTSD,
19536   IX86_BUILTIN_CMPNLESD,
19537   IX86_BUILTIN_CMPORDSD,
19538   IX86_BUILTIN_CMPUNORDSD,
19539
19540   IX86_BUILTIN_COMIEQSD,
19541   IX86_BUILTIN_COMILTSD,
19542   IX86_BUILTIN_COMILESD,
19543   IX86_BUILTIN_COMIGTSD,
19544   IX86_BUILTIN_COMIGESD,
19545   IX86_BUILTIN_COMINEQSD,
19546   IX86_BUILTIN_UCOMIEQSD,
19547   IX86_BUILTIN_UCOMILTSD,
19548   IX86_BUILTIN_UCOMILESD,
19549   IX86_BUILTIN_UCOMIGTSD,
19550   IX86_BUILTIN_UCOMIGESD,
19551   IX86_BUILTIN_UCOMINEQSD,
19552
19553   IX86_BUILTIN_MAXPD,
19554   IX86_BUILTIN_MAXSD,
19555   IX86_BUILTIN_MINPD,
19556   IX86_BUILTIN_MINSD,
19557
19558   IX86_BUILTIN_ANDPD,
19559   IX86_BUILTIN_ANDNPD,
19560   IX86_BUILTIN_ORPD,
19561   IX86_BUILTIN_XORPD,
19562
19563   IX86_BUILTIN_SQRTPD,
19564   IX86_BUILTIN_SQRTSD,
19565
19566   IX86_BUILTIN_UNPCKHPD,
19567   IX86_BUILTIN_UNPCKLPD,
19568
19569   IX86_BUILTIN_SHUFPD,
19570
19571   IX86_BUILTIN_LOADUPD,
19572   IX86_BUILTIN_STOREUPD,
19573   IX86_BUILTIN_MOVSD,
19574
19575   IX86_BUILTIN_LOADHPD,
19576   IX86_BUILTIN_LOADLPD,
19577
19578   IX86_BUILTIN_CVTDQ2PD,
19579   IX86_BUILTIN_CVTDQ2PS,
19580
19581   IX86_BUILTIN_CVTPD2DQ,
19582   IX86_BUILTIN_CVTPD2PI,
19583   IX86_BUILTIN_CVTPD2PS,
19584   IX86_BUILTIN_CVTTPD2DQ,
19585   IX86_BUILTIN_CVTTPD2PI,
19586
19587   IX86_BUILTIN_CVTPI2PD,
19588   IX86_BUILTIN_CVTSI2SD,
19589   IX86_BUILTIN_CVTSI642SD,
19590
19591   IX86_BUILTIN_CVTSD2SI,
19592   IX86_BUILTIN_CVTSD2SI64,
19593   IX86_BUILTIN_CVTSD2SS,
19594   IX86_BUILTIN_CVTSS2SD,
19595   IX86_BUILTIN_CVTTSD2SI,
19596   IX86_BUILTIN_CVTTSD2SI64,
19597
19598   IX86_BUILTIN_CVTPS2DQ,
19599   IX86_BUILTIN_CVTPS2PD,
19600   IX86_BUILTIN_CVTTPS2DQ,
19601
19602   IX86_BUILTIN_MOVNTI,
19603   IX86_BUILTIN_MOVNTPD,
19604   IX86_BUILTIN_MOVNTDQ,
19605
19606   IX86_BUILTIN_MOVQ128,
19607
19608   /* SSE2 MMX */
19609   IX86_BUILTIN_MASKMOVDQU,
19610   IX86_BUILTIN_MOVMSKPD,
19611   IX86_BUILTIN_PMOVMSKB128,
19612
19613   IX86_BUILTIN_PACKSSWB128,
19614   IX86_BUILTIN_PACKSSDW128,
19615   IX86_BUILTIN_PACKUSWB128,
19616
19617   IX86_BUILTIN_PADDB128,
19618   IX86_BUILTIN_PADDW128,
19619   IX86_BUILTIN_PADDD128,
19620   IX86_BUILTIN_PADDQ128,
19621   IX86_BUILTIN_PADDSB128,
19622   IX86_BUILTIN_PADDSW128,
19623   IX86_BUILTIN_PADDUSB128,
19624   IX86_BUILTIN_PADDUSW128,
19625   IX86_BUILTIN_PSUBB128,
19626   IX86_BUILTIN_PSUBW128,
19627   IX86_BUILTIN_PSUBD128,
19628   IX86_BUILTIN_PSUBQ128,
19629   IX86_BUILTIN_PSUBSB128,
19630   IX86_BUILTIN_PSUBSW128,
19631   IX86_BUILTIN_PSUBUSB128,
19632   IX86_BUILTIN_PSUBUSW128,
19633
19634   IX86_BUILTIN_PAND128,
19635   IX86_BUILTIN_PANDN128,
19636   IX86_BUILTIN_POR128,
19637   IX86_BUILTIN_PXOR128,
19638
19639   IX86_BUILTIN_PAVGB128,
19640   IX86_BUILTIN_PAVGW128,
19641
19642   IX86_BUILTIN_PCMPEQB128,
19643   IX86_BUILTIN_PCMPEQW128,
19644   IX86_BUILTIN_PCMPEQD128,
19645   IX86_BUILTIN_PCMPGTB128,
19646   IX86_BUILTIN_PCMPGTW128,
19647   IX86_BUILTIN_PCMPGTD128,
19648
19649   IX86_BUILTIN_PMADDWD128,
19650
19651   IX86_BUILTIN_PMAXSW128,
19652   IX86_BUILTIN_PMAXUB128,
19653   IX86_BUILTIN_PMINSW128,
19654   IX86_BUILTIN_PMINUB128,
19655
19656   IX86_BUILTIN_PMULUDQ,
19657   IX86_BUILTIN_PMULUDQ128,
19658   IX86_BUILTIN_PMULHUW128,
19659   IX86_BUILTIN_PMULHW128,
19660   IX86_BUILTIN_PMULLW128,
19661
19662   IX86_BUILTIN_PSADBW128,
19663   IX86_BUILTIN_PSHUFHW,
19664   IX86_BUILTIN_PSHUFLW,
19665   IX86_BUILTIN_PSHUFD,
19666
19667   IX86_BUILTIN_PSLLDQI128,
19668   IX86_BUILTIN_PSLLWI128,
19669   IX86_BUILTIN_PSLLDI128,
19670   IX86_BUILTIN_PSLLQI128,
19671   IX86_BUILTIN_PSRAWI128,
19672   IX86_BUILTIN_PSRADI128,
19673   IX86_BUILTIN_PSRLDQI128,
19674   IX86_BUILTIN_PSRLWI128,
19675   IX86_BUILTIN_PSRLDI128,
19676   IX86_BUILTIN_PSRLQI128,
19677
19678   IX86_BUILTIN_PSLLDQ128,
19679   IX86_BUILTIN_PSLLW128,
19680   IX86_BUILTIN_PSLLD128,
19681   IX86_BUILTIN_PSLLQ128,
19682   IX86_BUILTIN_PSRAW128,
19683   IX86_BUILTIN_PSRAD128,
19684   IX86_BUILTIN_PSRLW128,
19685   IX86_BUILTIN_PSRLD128,
19686   IX86_BUILTIN_PSRLQ128,
19687
19688   IX86_BUILTIN_PUNPCKHBW128,
19689   IX86_BUILTIN_PUNPCKHWD128,
19690   IX86_BUILTIN_PUNPCKHDQ128,
19691   IX86_BUILTIN_PUNPCKHQDQ128,
19692   IX86_BUILTIN_PUNPCKLBW128,
19693   IX86_BUILTIN_PUNPCKLWD128,
19694   IX86_BUILTIN_PUNPCKLDQ128,
19695   IX86_BUILTIN_PUNPCKLQDQ128,
19696
19697   IX86_BUILTIN_CLFLUSH,
19698   IX86_BUILTIN_MFENCE,
19699   IX86_BUILTIN_LFENCE,
19700
19701   /* SSE3.  */
19702   IX86_BUILTIN_ADDSUBPS,
19703   IX86_BUILTIN_HADDPS,
19704   IX86_BUILTIN_HSUBPS,
19705   IX86_BUILTIN_MOVSHDUP,
19706   IX86_BUILTIN_MOVSLDUP,
19707   IX86_BUILTIN_ADDSUBPD,
19708   IX86_BUILTIN_HADDPD,
19709   IX86_BUILTIN_HSUBPD,
19710   IX86_BUILTIN_LDDQU,
19711
19712   IX86_BUILTIN_MONITOR,
19713   IX86_BUILTIN_MWAIT,
19714
19715   /* SSSE3.  */
19716   IX86_BUILTIN_PHADDW,
19717   IX86_BUILTIN_PHADDD,
19718   IX86_BUILTIN_PHADDSW,
19719   IX86_BUILTIN_PHSUBW,
19720   IX86_BUILTIN_PHSUBD,
19721   IX86_BUILTIN_PHSUBSW,
19722   IX86_BUILTIN_PMADDUBSW,
19723   IX86_BUILTIN_PMULHRSW,
19724   IX86_BUILTIN_PSHUFB,
19725   IX86_BUILTIN_PSIGNB,
19726   IX86_BUILTIN_PSIGNW,
19727   IX86_BUILTIN_PSIGND,
19728   IX86_BUILTIN_PALIGNR,
19729   IX86_BUILTIN_PABSB,
19730   IX86_BUILTIN_PABSW,
19731   IX86_BUILTIN_PABSD,
19732
19733   IX86_BUILTIN_PHADDW128,
19734   IX86_BUILTIN_PHADDD128,
19735   IX86_BUILTIN_PHADDSW128,
19736   IX86_BUILTIN_PHSUBW128,
19737   IX86_BUILTIN_PHSUBD128,
19738   IX86_BUILTIN_PHSUBSW128,
19739   IX86_BUILTIN_PMADDUBSW128,
19740   IX86_BUILTIN_PMULHRSW128,
19741   IX86_BUILTIN_PSHUFB128,
19742   IX86_BUILTIN_PSIGNB128,
19743   IX86_BUILTIN_PSIGNW128,
19744   IX86_BUILTIN_PSIGND128,
19745   IX86_BUILTIN_PALIGNR128,
19746   IX86_BUILTIN_PABSB128,
19747   IX86_BUILTIN_PABSW128,
19748   IX86_BUILTIN_PABSD128,
19749
19750   /* AMDFAM10 - SSE4A New Instructions.  */
19751   IX86_BUILTIN_MOVNTSD,
19752   IX86_BUILTIN_MOVNTSS,
19753   IX86_BUILTIN_EXTRQI,
19754   IX86_BUILTIN_EXTRQ,
19755   IX86_BUILTIN_INSERTQI,
19756   IX86_BUILTIN_INSERTQ,
19757
19758   /* SSE4.1.  */
19759   IX86_BUILTIN_BLENDPD,
19760   IX86_BUILTIN_BLENDPS,
19761   IX86_BUILTIN_BLENDVPD,
19762   IX86_BUILTIN_BLENDVPS,
19763   IX86_BUILTIN_PBLENDVB128,
19764   IX86_BUILTIN_PBLENDW128,
19765
19766   IX86_BUILTIN_DPPD,
19767   IX86_BUILTIN_DPPS,
19768
19769   IX86_BUILTIN_INSERTPS128,
19770
19771   IX86_BUILTIN_MOVNTDQA,
19772   IX86_BUILTIN_MPSADBW128,
19773   IX86_BUILTIN_PACKUSDW128,
19774   IX86_BUILTIN_PCMPEQQ,
19775   IX86_BUILTIN_PHMINPOSUW128,
19776
19777   IX86_BUILTIN_PMAXSB128,
19778   IX86_BUILTIN_PMAXSD128,
19779   IX86_BUILTIN_PMAXUD128,
19780   IX86_BUILTIN_PMAXUW128,
19781
19782   IX86_BUILTIN_PMINSB128,
19783   IX86_BUILTIN_PMINSD128,
19784   IX86_BUILTIN_PMINUD128,
19785   IX86_BUILTIN_PMINUW128,
19786
19787   IX86_BUILTIN_PMOVSXBW128,
19788   IX86_BUILTIN_PMOVSXBD128,
19789   IX86_BUILTIN_PMOVSXBQ128,
19790   IX86_BUILTIN_PMOVSXWD128,
19791   IX86_BUILTIN_PMOVSXWQ128,
19792   IX86_BUILTIN_PMOVSXDQ128,
19793
19794   IX86_BUILTIN_PMOVZXBW128,
19795   IX86_BUILTIN_PMOVZXBD128,
19796   IX86_BUILTIN_PMOVZXBQ128,
19797   IX86_BUILTIN_PMOVZXWD128,
19798   IX86_BUILTIN_PMOVZXWQ128,
19799   IX86_BUILTIN_PMOVZXDQ128,
19800
19801   IX86_BUILTIN_PMULDQ128,
19802   IX86_BUILTIN_PMULLD128,
19803
19804   IX86_BUILTIN_ROUNDPD,
19805   IX86_BUILTIN_ROUNDPS,
19806   IX86_BUILTIN_ROUNDSD,
19807   IX86_BUILTIN_ROUNDSS,
19808
19809   IX86_BUILTIN_PTESTZ,
19810   IX86_BUILTIN_PTESTC,
19811   IX86_BUILTIN_PTESTNZC,
19812
19813   IX86_BUILTIN_VEC_INIT_V2SI,
19814   IX86_BUILTIN_VEC_INIT_V4HI,
19815   IX86_BUILTIN_VEC_INIT_V8QI,
19816   IX86_BUILTIN_VEC_EXT_V2DF,
19817   IX86_BUILTIN_VEC_EXT_V2DI,
19818   IX86_BUILTIN_VEC_EXT_V4SF,
19819   IX86_BUILTIN_VEC_EXT_V4SI,
19820   IX86_BUILTIN_VEC_EXT_V8HI,
19821   IX86_BUILTIN_VEC_EXT_V2SI,
19822   IX86_BUILTIN_VEC_EXT_V4HI,
19823   IX86_BUILTIN_VEC_EXT_V16QI,
19824   IX86_BUILTIN_VEC_SET_V2DI,
19825   IX86_BUILTIN_VEC_SET_V4SF,
19826   IX86_BUILTIN_VEC_SET_V4SI,
19827   IX86_BUILTIN_VEC_SET_V8HI,
19828   IX86_BUILTIN_VEC_SET_V4HI,
19829   IX86_BUILTIN_VEC_SET_V16QI,
19830
19831   IX86_BUILTIN_VEC_PACK_SFIX,
19832
19833   /* SSE4.2.  */
19834   IX86_BUILTIN_CRC32QI,
19835   IX86_BUILTIN_CRC32HI,
19836   IX86_BUILTIN_CRC32SI,
19837   IX86_BUILTIN_CRC32DI,
19838
19839   IX86_BUILTIN_PCMPESTRI128,
19840   IX86_BUILTIN_PCMPESTRM128,
19841   IX86_BUILTIN_PCMPESTRA128,
19842   IX86_BUILTIN_PCMPESTRC128,
19843   IX86_BUILTIN_PCMPESTRO128,
19844   IX86_BUILTIN_PCMPESTRS128,
19845   IX86_BUILTIN_PCMPESTRZ128,
19846   IX86_BUILTIN_PCMPISTRI128,
19847   IX86_BUILTIN_PCMPISTRM128,
19848   IX86_BUILTIN_PCMPISTRA128,
19849   IX86_BUILTIN_PCMPISTRC128,
19850   IX86_BUILTIN_PCMPISTRO128,
19851   IX86_BUILTIN_PCMPISTRS128,
19852   IX86_BUILTIN_PCMPISTRZ128,
19853
19854   IX86_BUILTIN_PCMPGTQ,
19855
19856   /* AES instructions */
19857   IX86_BUILTIN_AESENC128,
19858   IX86_BUILTIN_AESENCLAST128,
19859   IX86_BUILTIN_AESDEC128,
19860   IX86_BUILTIN_AESDECLAST128,
19861   IX86_BUILTIN_AESIMC128,
19862   IX86_BUILTIN_AESKEYGENASSIST128,
19863
19864   /* PCLMUL instruction */
19865   IX86_BUILTIN_PCLMULQDQ128,
19866
19867   /* AVX */
19868   IX86_BUILTIN_ADDPD256,
19869   IX86_BUILTIN_ADDPS256,
19870   IX86_BUILTIN_ADDSUBPD256,
19871   IX86_BUILTIN_ADDSUBPS256,
19872   IX86_BUILTIN_ANDPD256,
19873   IX86_BUILTIN_ANDPS256,
19874   IX86_BUILTIN_ANDNPD256,
19875   IX86_BUILTIN_ANDNPS256,
19876   IX86_BUILTIN_BLENDPD256,
19877   IX86_BUILTIN_BLENDPS256,
19878   IX86_BUILTIN_BLENDVPD256,
19879   IX86_BUILTIN_BLENDVPS256,
19880   IX86_BUILTIN_DIVPD256,
19881   IX86_BUILTIN_DIVPS256,
19882   IX86_BUILTIN_DPPS256,
19883   IX86_BUILTIN_HADDPD256,
19884   IX86_BUILTIN_HADDPS256,
19885   IX86_BUILTIN_HSUBPD256,
19886   IX86_BUILTIN_HSUBPS256,
19887   IX86_BUILTIN_MAXPD256,
19888   IX86_BUILTIN_MAXPS256,
19889   IX86_BUILTIN_MINPD256,
19890   IX86_BUILTIN_MINPS256,
19891   IX86_BUILTIN_MULPD256,
19892   IX86_BUILTIN_MULPS256,
19893   IX86_BUILTIN_ORPD256,
19894   IX86_BUILTIN_ORPS256,
19895   IX86_BUILTIN_SHUFPD256,
19896   IX86_BUILTIN_SHUFPS256,
19897   IX86_BUILTIN_SUBPD256,
19898   IX86_BUILTIN_SUBPS256,
19899   IX86_BUILTIN_XORPD256,
19900   IX86_BUILTIN_XORPS256,
19901   IX86_BUILTIN_CMPSD,
19902   IX86_BUILTIN_CMPSS,
19903   IX86_BUILTIN_CMPPD,
19904   IX86_BUILTIN_CMPPS,
19905   IX86_BUILTIN_CMPPD256,
19906   IX86_BUILTIN_CMPPS256,
19907   IX86_BUILTIN_CVTDQ2PD256,
19908   IX86_BUILTIN_CVTDQ2PS256,
19909   IX86_BUILTIN_CVTPD2PS256,
19910   IX86_BUILTIN_CVTPS2DQ256,
19911   IX86_BUILTIN_CVTPS2PD256,
19912   IX86_BUILTIN_CVTTPD2DQ256,
19913   IX86_BUILTIN_CVTPD2DQ256,
19914   IX86_BUILTIN_CVTTPS2DQ256,
19915   IX86_BUILTIN_EXTRACTF128PD256,
19916   IX86_BUILTIN_EXTRACTF128PS256,
19917   IX86_BUILTIN_EXTRACTF128SI256,
19918   IX86_BUILTIN_VZEROALL,
19919   IX86_BUILTIN_VZEROUPPER,
19920   IX86_BUILTIN_VZEROUPPER_REX64,
19921   IX86_BUILTIN_VPERMILVARPD,
19922   IX86_BUILTIN_VPERMILVARPS,
19923   IX86_BUILTIN_VPERMILVARPD256,
19924   IX86_BUILTIN_VPERMILVARPS256,
19925   IX86_BUILTIN_VPERMILPD,
19926   IX86_BUILTIN_VPERMILPS,
19927   IX86_BUILTIN_VPERMILPD256,
19928   IX86_BUILTIN_VPERMILPS256,
19929   IX86_BUILTIN_VPERM2F128PD256,
19930   IX86_BUILTIN_VPERM2F128PS256,
19931   IX86_BUILTIN_VPERM2F128SI256,
19932   IX86_BUILTIN_VBROADCASTSS,
19933   IX86_BUILTIN_VBROADCASTSD256,
19934   IX86_BUILTIN_VBROADCASTSS256,
19935   IX86_BUILTIN_VBROADCASTPD256,
19936   IX86_BUILTIN_VBROADCASTPS256,
19937   IX86_BUILTIN_VINSERTF128PD256,
19938   IX86_BUILTIN_VINSERTF128PS256,
19939   IX86_BUILTIN_VINSERTF128SI256,
19940   IX86_BUILTIN_LOADUPD256,
19941   IX86_BUILTIN_LOADUPS256,
19942   IX86_BUILTIN_STOREUPD256,
19943   IX86_BUILTIN_STOREUPS256,
19944   IX86_BUILTIN_LDDQU256,
19945   IX86_BUILTIN_MOVNTDQ256,
19946   IX86_BUILTIN_MOVNTPD256,
19947   IX86_BUILTIN_MOVNTPS256,
19948   IX86_BUILTIN_LOADDQU256,
19949   IX86_BUILTIN_STOREDQU256,
19950   IX86_BUILTIN_MASKLOADPD,
19951   IX86_BUILTIN_MASKLOADPS,
19952   IX86_BUILTIN_MASKSTOREPD,
19953   IX86_BUILTIN_MASKSTOREPS,
19954   IX86_BUILTIN_MASKLOADPD256,
19955   IX86_BUILTIN_MASKLOADPS256,
19956   IX86_BUILTIN_MASKSTOREPD256,
19957   IX86_BUILTIN_MASKSTOREPS256,
19958   IX86_BUILTIN_MOVSHDUP256,
19959   IX86_BUILTIN_MOVSLDUP256,
19960   IX86_BUILTIN_MOVDDUP256,
19961
19962   IX86_BUILTIN_SQRTPD256,
19963   IX86_BUILTIN_SQRTPS256,
19964   IX86_BUILTIN_SQRTPS_NR256,
19965   IX86_BUILTIN_RSQRTPS256,
19966   IX86_BUILTIN_RSQRTPS_NR256,
19967
19968   IX86_BUILTIN_RCPPS256,
19969
19970   IX86_BUILTIN_ROUNDPD256,
19971   IX86_BUILTIN_ROUNDPS256,
19972
19973   IX86_BUILTIN_UNPCKHPD256,
19974   IX86_BUILTIN_UNPCKLPD256,
19975   IX86_BUILTIN_UNPCKHPS256,
19976   IX86_BUILTIN_UNPCKLPS256,
19977
19978   IX86_BUILTIN_SI256_SI,
19979   IX86_BUILTIN_PS256_PS,
19980   IX86_BUILTIN_PD256_PD,
19981   IX86_BUILTIN_SI_SI256,
19982   IX86_BUILTIN_PS_PS256,
19983   IX86_BUILTIN_PD_PD256,
19984
19985   IX86_BUILTIN_VTESTZPD,
19986   IX86_BUILTIN_VTESTCPD,
19987   IX86_BUILTIN_VTESTNZCPD,
19988   IX86_BUILTIN_VTESTZPS,
19989   IX86_BUILTIN_VTESTCPS,
19990   IX86_BUILTIN_VTESTNZCPS,
19991   IX86_BUILTIN_VTESTZPD256,
19992   IX86_BUILTIN_VTESTCPD256,
19993   IX86_BUILTIN_VTESTNZCPD256,
19994   IX86_BUILTIN_VTESTZPS256,
19995   IX86_BUILTIN_VTESTCPS256,
19996   IX86_BUILTIN_VTESTNZCPS256,
19997   IX86_BUILTIN_PTESTZ256,
19998   IX86_BUILTIN_PTESTC256,
19999   IX86_BUILTIN_PTESTNZC256,
20000
20001   IX86_BUILTIN_MOVMSKPD256,
20002   IX86_BUILTIN_MOVMSKPS256,
20003
20004   /* TFmode support builtins.  */
20005   IX86_BUILTIN_INFQ,
20006   IX86_BUILTIN_FABSQ,
20007   IX86_BUILTIN_COPYSIGNQ,
20008
20009   /* SSE5 instructions */
20010   IX86_BUILTIN_FMADDSS,
20011   IX86_BUILTIN_FMADDSD,
20012   IX86_BUILTIN_FMADDPS,
20013   IX86_BUILTIN_FMADDPD,
20014   IX86_BUILTIN_FMSUBSS,
20015   IX86_BUILTIN_FMSUBSD,
20016   IX86_BUILTIN_FMSUBPS,
20017   IX86_BUILTIN_FMSUBPD,
20018   IX86_BUILTIN_FNMADDSS,
20019   IX86_BUILTIN_FNMADDSD,
20020   IX86_BUILTIN_FNMADDPS,
20021   IX86_BUILTIN_FNMADDPD,
20022   IX86_BUILTIN_FNMSUBSS,
20023   IX86_BUILTIN_FNMSUBSD,
20024   IX86_BUILTIN_FNMSUBPS,
20025   IX86_BUILTIN_FNMSUBPD,
20026   IX86_BUILTIN_PCMOV,
20027   IX86_BUILTIN_PCMOV_V2DI,
20028   IX86_BUILTIN_PCMOV_V4SI,
20029   IX86_BUILTIN_PCMOV_V8HI,
20030   IX86_BUILTIN_PCMOV_V16QI,
20031   IX86_BUILTIN_PCMOV_V4SF,
20032   IX86_BUILTIN_PCMOV_V2DF,
20033   IX86_BUILTIN_PPERM,
20034   IX86_BUILTIN_PERMPS,
20035   IX86_BUILTIN_PERMPD,
20036   IX86_BUILTIN_PMACSSWW,
20037   IX86_BUILTIN_PMACSWW,
20038   IX86_BUILTIN_PMACSSWD,
20039   IX86_BUILTIN_PMACSWD,
20040   IX86_BUILTIN_PMACSSDD,
20041   IX86_BUILTIN_PMACSDD,
20042   IX86_BUILTIN_PMACSSDQL,
20043   IX86_BUILTIN_PMACSSDQH,
20044   IX86_BUILTIN_PMACSDQL,
20045   IX86_BUILTIN_PMACSDQH,
20046   IX86_BUILTIN_PMADCSSWD,
20047   IX86_BUILTIN_PMADCSWD,
20048   IX86_BUILTIN_PHADDBW,
20049   IX86_BUILTIN_PHADDBD,
20050   IX86_BUILTIN_PHADDBQ,
20051   IX86_BUILTIN_PHADDWD,
20052   IX86_BUILTIN_PHADDWQ,
20053   IX86_BUILTIN_PHADDDQ,
20054   IX86_BUILTIN_PHADDUBW,
20055   IX86_BUILTIN_PHADDUBD,
20056   IX86_BUILTIN_PHADDUBQ,
20057   IX86_BUILTIN_PHADDUWD,
20058   IX86_BUILTIN_PHADDUWQ,
20059   IX86_BUILTIN_PHADDUDQ,
20060   IX86_BUILTIN_PHSUBBW,
20061   IX86_BUILTIN_PHSUBWD,
20062   IX86_BUILTIN_PHSUBDQ,
20063   IX86_BUILTIN_PROTB,
20064   IX86_BUILTIN_PROTW,
20065   IX86_BUILTIN_PROTD,
20066   IX86_BUILTIN_PROTQ,
20067   IX86_BUILTIN_PROTB_IMM,
20068   IX86_BUILTIN_PROTW_IMM,
20069   IX86_BUILTIN_PROTD_IMM,
20070   IX86_BUILTIN_PROTQ_IMM,
20071   IX86_BUILTIN_PSHLB,
20072   IX86_BUILTIN_PSHLW,
20073   IX86_BUILTIN_PSHLD,
20074   IX86_BUILTIN_PSHLQ,
20075   IX86_BUILTIN_PSHAB,
20076   IX86_BUILTIN_PSHAW,
20077   IX86_BUILTIN_PSHAD,
20078   IX86_BUILTIN_PSHAQ,
20079   IX86_BUILTIN_FRCZSS,
20080   IX86_BUILTIN_FRCZSD,
20081   IX86_BUILTIN_FRCZPS,
20082   IX86_BUILTIN_FRCZPD,
20083   IX86_BUILTIN_CVTPH2PS,
20084   IX86_BUILTIN_CVTPS2PH,
20085
20086   IX86_BUILTIN_COMEQSS,
20087   IX86_BUILTIN_COMNESS,
20088   IX86_BUILTIN_COMLTSS,
20089   IX86_BUILTIN_COMLESS,
20090   IX86_BUILTIN_COMGTSS,
20091   IX86_BUILTIN_COMGESS,
20092   IX86_BUILTIN_COMUEQSS,
20093   IX86_BUILTIN_COMUNESS,
20094   IX86_BUILTIN_COMULTSS,
20095   IX86_BUILTIN_COMULESS,
20096   IX86_BUILTIN_COMUGTSS,
20097   IX86_BUILTIN_COMUGESS,
20098   IX86_BUILTIN_COMORDSS,
20099   IX86_BUILTIN_COMUNORDSS,
20100   IX86_BUILTIN_COMFALSESS,
20101   IX86_BUILTIN_COMTRUESS,
20102
20103   IX86_BUILTIN_COMEQSD,
20104   IX86_BUILTIN_COMNESD,
20105   IX86_BUILTIN_COMLTSD,
20106   IX86_BUILTIN_COMLESD,
20107   IX86_BUILTIN_COMGTSD,
20108   IX86_BUILTIN_COMGESD,
20109   IX86_BUILTIN_COMUEQSD,
20110   IX86_BUILTIN_COMUNESD,
20111   IX86_BUILTIN_COMULTSD,
20112   IX86_BUILTIN_COMULESD,
20113   IX86_BUILTIN_COMUGTSD,
20114   IX86_BUILTIN_COMUGESD,
20115   IX86_BUILTIN_COMORDSD,
20116   IX86_BUILTIN_COMUNORDSD,
20117   IX86_BUILTIN_COMFALSESD,
20118   IX86_BUILTIN_COMTRUESD,
20119
20120   IX86_BUILTIN_COMEQPS,
20121   IX86_BUILTIN_COMNEPS,
20122   IX86_BUILTIN_COMLTPS,
20123   IX86_BUILTIN_COMLEPS,
20124   IX86_BUILTIN_COMGTPS,
20125   IX86_BUILTIN_COMGEPS,
20126   IX86_BUILTIN_COMUEQPS,
20127   IX86_BUILTIN_COMUNEPS,
20128   IX86_BUILTIN_COMULTPS,
20129   IX86_BUILTIN_COMULEPS,
20130   IX86_BUILTIN_COMUGTPS,
20131   IX86_BUILTIN_COMUGEPS,
20132   IX86_BUILTIN_COMORDPS,
20133   IX86_BUILTIN_COMUNORDPS,
20134   IX86_BUILTIN_COMFALSEPS,
20135   IX86_BUILTIN_COMTRUEPS,
20136
20137   IX86_BUILTIN_COMEQPD,
20138   IX86_BUILTIN_COMNEPD,
20139   IX86_BUILTIN_COMLTPD,
20140   IX86_BUILTIN_COMLEPD,
20141   IX86_BUILTIN_COMGTPD,
20142   IX86_BUILTIN_COMGEPD,
20143   IX86_BUILTIN_COMUEQPD,
20144   IX86_BUILTIN_COMUNEPD,
20145   IX86_BUILTIN_COMULTPD,
20146   IX86_BUILTIN_COMULEPD,
20147   IX86_BUILTIN_COMUGTPD,
20148   IX86_BUILTIN_COMUGEPD,
20149   IX86_BUILTIN_COMORDPD,
20150   IX86_BUILTIN_COMUNORDPD,
20151   IX86_BUILTIN_COMFALSEPD,
20152   IX86_BUILTIN_COMTRUEPD,
20153
20154   IX86_BUILTIN_PCOMEQUB,
20155   IX86_BUILTIN_PCOMNEUB,
20156   IX86_BUILTIN_PCOMLTUB,
20157   IX86_BUILTIN_PCOMLEUB,
20158   IX86_BUILTIN_PCOMGTUB,
20159   IX86_BUILTIN_PCOMGEUB,
20160   IX86_BUILTIN_PCOMFALSEUB,
20161   IX86_BUILTIN_PCOMTRUEUB,
20162   IX86_BUILTIN_PCOMEQUW,
20163   IX86_BUILTIN_PCOMNEUW,
20164   IX86_BUILTIN_PCOMLTUW,
20165   IX86_BUILTIN_PCOMLEUW,
20166   IX86_BUILTIN_PCOMGTUW,
20167   IX86_BUILTIN_PCOMGEUW,
20168   IX86_BUILTIN_PCOMFALSEUW,
20169   IX86_BUILTIN_PCOMTRUEUW,
20170   IX86_BUILTIN_PCOMEQUD,
20171   IX86_BUILTIN_PCOMNEUD,
20172   IX86_BUILTIN_PCOMLTUD,
20173   IX86_BUILTIN_PCOMLEUD,
20174   IX86_BUILTIN_PCOMGTUD,
20175   IX86_BUILTIN_PCOMGEUD,
20176   IX86_BUILTIN_PCOMFALSEUD,
20177   IX86_BUILTIN_PCOMTRUEUD,
20178   IX86_BUILTIN_PCOMEQUQ,
20179   IX86_BUILTIN_PCOMNEUQ,
20180   IX86_BUILTIN_PCOMLTUQ,
20181   IX86_BUILTIN_PCOMLEUQ,
20182   IX86_BUILTIN_PCOMGTUQ,
20183   IX86_BUILTIN_PCOMGEUQ,
20184   IX86_BUILTIN_PCOMFALSEUQ,
20185   IX86_BUILTIN_PCOMTRUEUQ,
20186
20187   IX86_BUILTIN_PCOMEQB,
20188   IX86_BUILTIN_PCOMNEB,
20189   IX86_BUILTIN_PCOMLTB,
20190   IX86_BUILTIN_PCOMLEB,
20191   IX86_BUILTIN_PCOMGTB,
20192   IX86_BUILTIN_PCOMGEB,
20193   IX86_BUILTIN_PCOMFALSEB,
20194   IX86_BUILTIN_PCOMTRUEB,
20195   IX86_BUILTIN_PCOMEQW,
20196   IX86_BUILTIN_PCOMNEW,
20197   IX86_BUILTIN_PCOMLTW,
20198   IX86_BUILTIN_PCOMLEW,
20199   IX86_BUILTIN_PCOMGTW,
20200   IX86_BUILTIN_PCOMGEW,
20201   IX86_BUILTIN_PCOMFALSEW,
20202   IX86_BUILTIN_PCOMTRUEW,
20203   IX86_BUILTIN_PCOMEQD,
20204   IX86_BUILTIN_PCOMNED,
20205   IX86_BUILTIN_PCOMLTD,
20206   IX86_BUILTIN_PCOMLED,
20207   IX86_BUILTIN_PCOMGTD,
20208   IX86_BUILTIN_PCOMGED,
20209   IX86_BUILTIN_PCOMFALSED,
20210   IX86_BUILTIN_PCOMTRUED,
20211   IX86_BUILTIN_PCOMEQQ,
20212   IX86_BUILTIN_PCOMNEQ,
20213   IX86_BUILTIN_PCOMLTQ,
20214   IX86_BUILTIN_PCOMLEQ,
20215   IX86_BUILTIN_PCOMGTQ,
20216   IX86_BUILTIN_PCOMGEQ,
20217   IX86_BUILTIN_PCOMFALSEQ,
20218   IX86_BUILTIN_PCOMTRUEQ,
20219
20220   IX86_BUILTIN_MAX
20221 };
20222
20223 /* Table for the ix86 builtin decls.  */
20224 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
20225
20226 /* Table of all of the builtin functions that are possible with different ISA's
20227    but are waiting to be built until a function is declared to use that
20228    ISA.  */
20229 struct builtin_isa GTY(())
20230 {
20231   tree type;                    /* builtin type to use in the declaration */
20232   const char *name;             /* function name */
20233   int isa;                      /* isa_flags this builtin is defined for */
20234   bool const_p;                 /* true if the declaration is constant */
20235 };
20236
20237 static GTY(()) struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
20238
20239
20240 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
20241  * of which isa_flags to use in the ix86_builtins_isa array.  Stores the
20242  * function decl in the ix86_builtins array.  Returns the function decl or
20243  * NULL_TREE, if the builtin was not added.
20244  *
20245  * If the front end has a special hook for builtin functions, delay adding
20246  * builtin functions that aren't in the current ISA until the ISA is changed
20247  * with function specific optimization.  Doing so, can save about 300K for the
20248  * default compiler.  When the builtin is expanded, check at that time whether
20249  * it is valid.
20250  *
20251  * If the front end doesn't have a special hook, record all builtins, even if
20252  * it isn't an instruction set in the current ISA in case the user uses
20253  * function specific options for a different ISA, so that we don't get scope
20254  * errors if a builtin is added in the middle of a function scope.  */
20255
20256 static inline tree
20257 def_builtin (int mask, const char *name, tree type, enum ix86_builtins code)
20258 {
20259   tree decl = NULL_TREE;
20260
20261   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
20262     {
20263       ix86_builtins_isa[(int) code].isa = mask;
20264
20265       if ((mask & ix86_isa_flags) != 0
20266           || (lang_hooks.builtin_function
20267               == lang_hooks.builtin_function_ext_scope))
20268
20269         {
20270           decl = add_builtin_function (name, type, code, BUILT_IN_MD, NULL,
20271                                        NULL_TREE);
20272           ix86_builtins[(int) code] = decl;
20273           ix86_builtins_isa[(int) code].type = NULL_TREE;
20274         }
20275       else
20276         {
20277           ix86_builtins[(int) code] = NULL_TREE;
20278           ix86_builtins_isa[(int) code].const_p = false;
20279           ix86_builtins_isa[(int) code].type = type;
20280           ix86_builtins_isa[(int) code].name = name;
20281         }
20282     }
20283
20284   return decl;
20285 }
20286
20287 /* Like def_builtin, but also marks the function decl "const".  */
20288
20289 static inline tree
20290 def_builtin_const (int mask, const char *name, tree type,
20291                    enum ix86_builtins code)
20292 {
20293   tree decl = def_builtin (mask, name, type, code);
20294   if (decl)
20295     TREE_READONLY (decl) = 1;
20296   else
20297     ix86_builtins_isa[(int) code].const_p = true;
20298
20299   return decl;
20300 }
20301
20302 /* Add any new builtin functions for a given ISA that may not have been
20303    declared.  This saves a bit of space compared to adding all of the
20304    declarations to the tree, even if we didn't use them.  */
20305
20306 static void
20307 ix86_add_new_builtins (int isa)
20308 {
20309   int i;
20310   tree decl;
20311
20312   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
20313     {
20314       if ((ix86_builtins_isa[i].isa & isa) != 0
20315           && ix86_builtins_isa[i].type != NULL_TREE)
20316         {
20317           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
20318                                                  ix86_builtins_isa[i].type,
20319                                                  i, BUILT_IN_MD, NULL,
20320                                                  NULL_TREE);
20321
20322           ix86_builtins[i] = decl;
20323           ix86_builtins_isa[i].type = NULL_TREE;
20324           if (ix86_builtins_isa[i].const_p)
20325             TREE_READONLY (decl) = 1;
20326         }
20327     }
20328 }
20329
20330 /* Bits for builtin_description.flag.  */
20331
20332 /* Set when we don't support the comparison natively, and should
20333    swap_comparison in order to support it.  */
20334 #define BUILTIN_DESC_SWAP_OPERANDS      1
20335
20336 struct builtin_description
20337 {
20338   const unsigned int mask;
20339   const enum insn_code icode;
20340   const char *const name;
20341   const enum ix86_builtins code;
20342   const enum rtx_code comparison;
20343   const int flag;
20344 };
20345
20346 static const struct builtin_description bdesc_comi[] =
20347 {
20348   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
20349   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
20350   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
20351   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
20352   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
20353   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
20354   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
20355   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
20356   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
20357   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
20358   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
20359   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
20360   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
20361   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
20362   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
20363   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
20364   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
20365   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
20366   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
20367   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
20368   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
20369   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
20370   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
20371   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
20372 };
20373
20374 static const struct builtin_description bdesc_pcmpestr[] =
20375 {
20376   /* SSE4.2 */
20377   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
20378   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
20379   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
20380   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
20381   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
20382   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
20383   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
20384 };
20385
20386 static const struct builtin_description bdesc_pcmpistr[] =
20387 {
20388   /* SSE4.2 */
20389   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
20390   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
20391   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
20392   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
20393   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
20394   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
20395   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
20396 };
20397
20398 /* Special builtin types */
20399 enum ix86_special_builtin_type
20400 {
20401   SPECIAL_FTYPE_UNKNOWN,
20402   VOID_FTYPE_VOID,
20403   V32QI_FTYPE_PCCHAR,
20404   V16QI_FTYPE_PCCHAR,
20405   V8SF_FTYPE_PCV4SF,
20406   V8SF_FTYPE_PCFLOAT,
20407   V4DF_FTYPE_PCV2DF,
20408   V4DF_FTYPE_PCDOUBLE,
20409   V4SF_FTYPE_PCFLOAT,
20410   V2DF_FTYPE_PCDOUBLE,
20411   V8SF_FTYPE_PCV8SF_V8SF,
20412   V4DF_FTYPE_PCV4DF_V4DF,
20413   V4SF_FTYPE_V4SF_PCV2SF,
20414   V4SF_FTYPE_PCV4SF_V4SF,
20415   V2DF_FTYPE_V2DF_PCDOUBLE,
20416   V2DF_FTYPE_PCV2DF_V2DF,
20417   V2DI_FTYPE_PV2DI,
20418   VOID_FTYPE_PV2SF_V4SF,
20419   VOID_FTYPE_PV4DI_V4DI,
20420   VOID_FTYPE_PV2DI_V2DI,
20421   VOID_FTYPE_PCHAR_V32QI,
20422   VOID_FTYPE_PCHAR_V16QI,
20423   VOID_FTYPE_PFLOAT_V8SF,
20424   VOID_FTYPE_PFLOAT_V4SF,
20425   VOID_FTYPE_PDOUBLE_V4DF,
20426   VOID_FTYPE_PDOUBLE_V2DF,
20427   VOID_FTYPE_PDI_DI,
20428   VOID_FTYPE_PINT_INT,
20429   VOID_FTYPE_PV8SF_V8SF_V8SF,
20430   VOID_FTYPE_PV4DF_V4DF_V4DF,
20431   VOID_FTYPE_PV4SF_V4SF_V4SF,
20432   VOID_FTYPE_PV2DF_V2DF_V2DF
20433 };
20434
20435 /* Builtin types */
20436 enum ix86_builtin_type
20437 {
20438   FTYPE_UNKNOWN,
20439   FLOAT128_FTYPE_FLOAT128,
20440   FLOAT_FTYPE_FLOAT,
20441   FLOAT128_FTYPE_FLOAT128_FLOAT128,
20442   INT_FTYPE_V8SF_V8SF_PTEST,
20443   INT_FTYPE_V4DI_V4DI_PTEST,
20444   INT_FTYPE_V4DF_V4DF_PTEST,
20445   INT_FTYPE_V4SF_V4SF_PTEST,
20446   INT_FTYPE_V2DI_V2DI_PTEST,
20447   INT_FTYPE_V2DF_V2DF_PTEST,
20448   INT64_FTYPE_V4SF,
20449   INT64_FTYPE_V2DF,
20450   INT_FTYPE_V16QI,
20451   INT_FTYPE_V8QI,
20452   INT_FTYPE_V8SF,
20453   INT_FTYPE_V4DF,
20454   INT_FTYPE_V4SF,
20455   INT_FTYPE_V2DF,
20456   V16QI_FTYPE_V16QI,
20457   V8SI_FTYPE_V8SF,
20458   V8SI_FTYPE_V4SI,
20459   V8HI_FTYPE_V8HI,
20460   V8HI_FTYPE_V16QI,
20461   V8QI_FTYPE_V8QI,
20462   V8SF_FTYPE_V8SF,
20463   V8SF_FTYPE_V8SI,
20464   V8SF_FTYPE_V4SF,
20465   V4SI_FTYPE_V4SI,
20466   V4SI_FTYPE_V16QI,
20467   V4SI_FTYPE_V8SI,
20468   V4SI_FTYPE_V8HI,
20469   V4SI_FTYPE_V4DF,
20470   V4SI_FTYPE_V4SF,
20471   V4SI_FTYPE_V2DF,
20472   V4HI_FTYPE_V4HI,
20473   V4DF_FTYPE_V4DF,
20474   V4DF_FTYPE_V4SI,
20475   V4DF_FTYPE_V4SF,
20476   V4DF_FTYPE_V2DF,
20477   V4SF_FTYPE_V4DF,
20478   V4SF_FTYPE_V4SF,
20479   V4SF_FTYPE_V4SF_VEC_MERGE,
20480   V4SF_FTYPE_V8SF,
20481   V4SF_FTYPE_V4SI,
20482   V4SF_FTYPE_V2DF,
20483   V2DI_FTYPE_V2DI,
20484   V2DI_FTYPE_V16QI,
20485   V2DI_FTYPE_V8HI,
20486   V2DI_FTYPE_V4SI,
20487   V2DF_FTYPE_V2DF,
20488   V2DF_FTYPE_V2DF_VEC_MERGE,
20489   V2DF_FTYPE_V4SI,
20490   V2DF_FTYPE_V4DF,
20491   V2DF_FTYPE_V4SF,
20492   V2DF_FTYPE_V2SI,
20493   V2SI_FTYPE_V2SI,
20494   V2SI_FTYPE_V4SF,
20495   V2SI_FTYPE_V2SF,
20496   V2SI_FTYPE_V2DF,
20497   V2SF_FTYPE_V2SF,
20498   V2SF_FTYPE_V2SI,
20499   V16QI_FTYPE_V16QI_V16QI,
20500   V16QI_FTYPE_V8HI_V8HI,
20501   V8QI_FTYPE_V8QI_V8QI,
20502   V8QI_FTYPE_V4HI_V4HI,
20503   V8HI_FTYPE_V8HI_V8HI,
20504   V8HI_FTYPE_V8HI_V8HI_COUNT,
20505   V8HI_FTYPE_V16QI_V16QI,
20506   V8HI_FTYPE_V4SI_V4SI,
20507   V8HI_FTYPE_V8HI_SI_COUNT,
20508   V8SF_FTYPE_V8SF_V8SF,
20509   V8SF_FTYPE_V8SF_V8SI,
20510   V4SI_FTYPE_V4SI_V4SI,
20511   V4SI_FTYPE_V4SI_V4SI_COUNT,
20512   V4SI_FTYPE_V8HI_V8HI,
20513   V4SI_FTYPE_V4SF_V4SF,
20514   V4SI_FTYPE_V2DF_V2DF,
20515   V4SI_FTYPE_V4SI_SI_COUNT,
20516   V4HI_FTYPE_V4HI_V4HI,
20517   V4HI_FTYPE_V4HI_V4HI_COUNT,
20518   V4HI_FTYPE_V8QI_V8QI,
20519   V4HI_FTYPE_V2SI_V2SI,
20520   V4HI_FTYPE_V4HI_SI_COUNT,
20521   V4DF_FTYPE_V4DF_V4DF,
20522   V4DF_FTYPE_V4DF_V4DI,
20523   V4SF_FTYPE_V4SF_V4SF,
20524   V4SF_FTYPE_V4SF_V4SF_SWAP,
20525   V4SF_FTYPE_V4SF_V4SI,
20526   V4SF_FTYPE_V4SF_V2SI,
20527   V4SF_FTYPE_V4SF_V2DF,
20528   V4SF_FTYPE_V4SF_DI,
20529   V4SF_FTYPE_V4SF_SI,
20530   V2DI_FTYPE_V2DI_V2DI,
20531   V2DI_FTYPE_V2DI_V2DI_COUNT,
20532   V2DI_FTYPE_V16QI_V16QI,
20533   V2DI_FTYPE_V4SI_V4SI,
20534   V2DI_FTYPE_V2DI_V16QI,
20535   V2DI_FTYPE_V2DF_V2DF,
20536   V2DI_FTYPE_V2DI_SI_COUNT,
20537   V2SI_FTYPE_V2SI_V2SI,
20538   V2SI_FTYPE_V2SI_V2SI_COUNT,
20539   V2SI_FTYPE_V4HI_V4HI,
20540   V2SI_FTYPE_V2SF_V2SF,
20541   V2SI_FTYPE_V2SI_SI_COUNT,
20542   V2DF_FTYPE_V2DF_V2DF,
20543   V2DF_FTYPE_V2DF_V2DF_SWAP,
20544   V2DF_FTYPE_V2DF_V4SF,
20545   V2DF_FTYPE_V2DF_V2DI,
20546   V2DF_FTYPE_V2DF_DI,
20547   V2DF_FTYPE_V2DF_SI,
20548   V2SF_FTYPE_V2SF_V2SF,
20549   V1DI_FTYPE_V1DI_V1DI,
20550   V1DI_FTYPE_V1DI_V1DI_COUNT,
20551   V1DI_FTYPE_V8QI_V8QI,
20552   V1DI_FTYPE_V2SI_V2SI,
20553   V1DI_FTYPE_V1DI_SI_COUNT,
20554   UINT64_FTYPE_UINT64_UINT64,
20555   UINT_FTYPE_UINT_UINT,
20556   UINT_FTYPE_UINT_USHORT,
20557   UINT_FTYPE_UINT_UCHAR,
20558   V8HI_FTYPE_V8HI_INT,
20559   V4SI_FTYPE_V4SI_INT,
20560   V4HI_FTYPE_V4HI_INT,
20561   V8SF_FTYPE_V8SF_INT,
20562   V4SI_FTYPE_V8SI_INT,
20563   V4SF_FTYPE_V8SF_INT,
20564   V2DF_FTYPE_V4DF_INT,
20565   V4DF_FTYPE_V4DF_INT,
20566   V4SF_FTYPE_V4SF_INT,
20567   V2DI_FTYPE_V2DI_INT,
20568   V2DI2TI_FTYPE_V2DI_INT,
20569   V2DF_FTYPE_V2DF_INT,
20570   V16QI_FTYPE_V16QI_V16QI_V16QI,
20571   V8SF_FTYPE_V8SF_V8SF_V8SF,
20572   V4DF_FTYPE_V4DF_V4DF_V4DF,
20573   V4SF_FTYPE_V4SF_V4SF_V4SF,
20574   V2DF_FTYPE_V2DF_V2DF_V2DF,
20575   V16QI_FTYPE_V16QI_V16QI_INT,
20576   V8SI_FTYPE_V8SI_V8SI_INT,
20577   V8SI_FTYPE_V8SI_V4SI_INT,
20578   V8HI_FTYPE_V8HI_V8HI_INT,
20579   V8SF_FTYPE_V8SF_V8SF_INT,
20580   V8SF_FTYPE_V8SF_V4SF_INT,
20581   V4SI_FTYPE_V4SI_V4SI_INT,
20582   V4DF_FTYPE_V4DF_V4DF_INT,
20583   V4DF_FTYPE_V4DF_V2DF_INT,
20584   V4SF_FTYPE_V4SF_V4SF_INT,
20585   V2DI_FTYPE_V2DI_V2DI_INT,
20586   V2DI2TI_FTYPE_V2DI_V2DI_INT,
20587   V1DI2DI_FTYPE_V1DI_V1DI_INT,
20588   V2DF_FTYPE_V2DF_V2DF_INT,
20589   V2DI_FTYPE_V2DI_UINT_UINT,
20590   V2DI_FTYPE_V2DI_V2DI_UINT_UINT
20591 };
20592
20593 /* Special builtins with variable number of arguments.  */
20594 static const struct builtin_description bdesc_special_args[] =
20595 {
20596   /* MMX */
20597   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20598
20599   /* 3DNow! */
20600   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20601
20602   /* SSE */
20603   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20604   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20605   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20606
20607   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20608   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20609   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20610   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20611
20612   /* SSE or 3DNow!A  */
20613   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20614   { 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 },
20615
20616   /* SSE2 */
20617   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20618   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20619   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20620   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
20621   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20622   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
20623   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntsi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
20624   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
20625   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20626
20627   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20628   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20629
20630   /* SSE3 */
20631   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20632
20633   /* SSE4.1 */
20634   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
20635
20636   /* SSE4A */
20637   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20638   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20639
20640   /* AVX */
20641   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
20642   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, 0, IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
20643   { OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_64BIT, CODE_FOR_avx_vzeroupper_rex64, 0, IX86_BUILTIN_VZEROUPPER_REX64, UNKNOWN, (int) VOID_FTYPE_VOID },
20644
20645   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20646   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastsd256, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
20647   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss256, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
20648   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_pd256, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
20649   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_ps256, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
20650
20651   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
20652   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
20653   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
20654   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
20655   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
20656   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
20657   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
20658
20659   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4di, "__builtin_ia32_movntdq256", IX86_BUILTIN_MOVNTDQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI },
20660   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4df, "__builtin_ia32_movntpd256", IX86_BUILTIN_MOVNTPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
20661   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv8sf, "__builtin_ia32_movntps256", IX86_BUILTIN_MOVNTPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
20662
20663   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF },
20664   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF },
20665   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF },
20666   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF },
20667   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_V2DF },
20668   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_V4SF },
20669   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_V4DF },
20670   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_V8SF },
20671 };
20672
20673 /* Builtins with variable number of arguments.  */
20674 static const struct builtin_description bdesc_args[] =
20675 {
20676   /* MMX */
20677   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20678   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20679   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20680   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20681   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20682   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20683
20684   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20685   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20686   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20687   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20688   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20689   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20690   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20691   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20692
20693   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20694   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20695
20696   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20697   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andnotv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20698   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20699   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20700
20701   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20702   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20703   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20704   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20705   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20706   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20707
20708   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20709   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20710   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20711   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20712   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
20713   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
20714
20715   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
20716   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
20717   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
20718
20719   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
20720
20721   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20722   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20723   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
20724   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20725   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20726   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
20727
20728   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20729   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20730   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
20731   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20732   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20733   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
20734
20735   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20736   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20737   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20738   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20739
20740   /* 3DNow! */
20741   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
20742   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
20743   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20744   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20745
20746   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20747   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20748   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20749   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20750   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20751   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20752   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20753   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20754   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20755   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20756   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20757   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20758   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20759   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20760   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20761
20762   /* 3DNow!A */
20763   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
20764   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
20765   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
20766   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20767   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20768   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20769
20770   /* SSE */
20771   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
20772   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20773   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20774   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20775   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20776   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20777   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
20778   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
20779   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
20780   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
20781   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
20782   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
20783
20784   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20785
20786   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20787   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20788   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20789   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20790   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20791   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20792   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20793   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20794
20795   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
20796   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
20797   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
20798   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20799   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20800   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20801   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
20802   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
20803   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
20804   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20805   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
20806   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20807   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
20808   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
20809   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
20810   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20811   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
20812   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
20813   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
20814   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngtss", IX86_BUILTIN_CMPNGTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20815   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngess", IX86_BUILTIN_CMPNGESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20816   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20817
20818   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20819   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20820   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20821   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20822
20823   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20824   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_andnotv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20825   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20826   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20827
20828   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20829   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20830   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20831   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpckhps, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20832   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpcklps, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20833
20834   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
20835   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
20836   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
20837
20838   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
20839
20840   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20841   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20842   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20843
20844   /* SSE MMX or 3Dnow!A */
20845   { 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 },
20846   { 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 },
20847   { 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 },
20848
20849   { 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 },
20850   { 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 },
20851   { 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 },
20852   { 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 },
20853
20854   { 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 },
20855   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
20856
20857   { 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 },
20858
20859   /* SSE2 */
20860   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20861
20862   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
20863   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
20864   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
20865   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
20866   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2ps, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
20867
20868   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
20869   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
20870   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
20871   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
20872   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
20873
20874   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
20875
20876   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
20877   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
20878   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
20879   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
20880
20881   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2dq, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
20882   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
20883   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttps2dq, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
20884
20885   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20886   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20887   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20888   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20889   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20890   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20891   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20892   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20893
20894   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
20895   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
20896   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
20897   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20898   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
20899   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20900   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
20901   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
20902   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
20903   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20904   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20905   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20906   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
20907   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
20908   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
20909   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20910   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
20911   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
20912   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
20913   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20914
20915   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20916   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20917   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20918   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20919
20920   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20921   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20922   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20923   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20924
20925   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20926   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpckhpd_exp, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20927   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpcklpd_exp, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20928
20929   { 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 },
20930
20931   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20932   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20933   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20934   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20935   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20936   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20937   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20938   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20939
20940   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20941   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20942   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20943   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20944   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20945   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20946   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20947   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20948
20949   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20950   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
20951
20952   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20953   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20954   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20955   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20956
20957   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20958   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20959
20960   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20961   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20962   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
20963   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20964   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20965   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
20966
20967   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20968   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20969   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20970   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20971
20972   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhbw, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20973   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhwd, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
20974   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhdq, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
20975   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhqdq, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20976   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklbw, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20977   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklwd, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20978   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckldq, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20979   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklqdq, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20980
20981   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
20982   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
20983   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
20984
20985   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20986   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
20987
20988   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
20989   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv2siv2di3, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
20990
20991   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
20992
20993   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
20994   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
20995   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
20996   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
20997
20998   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
20999   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21000   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21001   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
21002   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21003   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21004   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
21005
21006   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
21007   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21008   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21009   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
21010   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21011   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21012   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
21013
21014   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21015   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21016   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21017   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21018
21019   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
21020   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
21021   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
21022
21023   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
21024
21025   { OPTION_MASK_ISA_SSE2, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
21026   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
21027
21028   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
21029
21030   /* SSE2 MMX */
21031   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
21032   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
21033
21034   /* SSE3 */
21035   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
21036   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21037
21038   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21039   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21040   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21041   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21042   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21043   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21044
21045   /* SSSE3 */
21046   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
21047   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
21048   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
21049   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
21050   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
21051   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
21052
21053   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21054   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21055   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21056   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21057   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21058   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21059   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21060   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21061   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21062   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21063   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21064   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21065   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
21066   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
21067   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21068   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21069   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21070   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21071   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21072   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21073   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21074   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21075   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21076   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21077
21078   /* SSSE3.  */
21079   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_V2DI_INT },
21080   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI2DI_FTYPE_V1DI_V1DI_INT },
21081
21082   /* SSE4.1 */
21083   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21084   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21085   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
21086   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
21087   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21088   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21089   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21090   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
21091   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
21092   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
21093
21094   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
21095   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
21096   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
21097   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
21098   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
21099   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
21100   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
21101   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
21102   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
21103   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
21104   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
21105   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
21106   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
21107
21108   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
21109   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21110   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21111   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21112   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21113   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21114   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21115   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21116   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21117   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21118   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
21119   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21120
21121   /* SSE4.1 and SSE5 */
21122   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
21123   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
21124   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21125   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21126
21127   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21128   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21129   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21130
21131   /* SSE4.2 */
21132   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21133   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32qi, "__builtin_ia32_crc32qi", IX86_BUILTIN_CRC32QI, UNKNOWN, (int) UINT_FTYPE_UINT_UCHAR },
21134   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32hi, "__builtin_ia32_crc32hi", IX86_BUILTIN_CRC32HI, UNKNOWN, (int) UINT_FTYPE_UINT_USHORT },
21135   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32si, "__builtin_ia32_crc32si", IX86_BUILTIN_CRC32SI, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
21136   { 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 },
21137
21138   /* SSE4A */
21139   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
21140   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
21141   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
21142   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21143
21144   /* AES */
21145   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
21146   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
21147
21148   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21149   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21150   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21151   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21152
21153   /* PCLMUL */
21154   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
21155
21156   /* AVX */
21157   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21158   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21159   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21160   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21161   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21162   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21163   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21164   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21165   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21166   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21167   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21168   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21169   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21170   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21171   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21172   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21173   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21174   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21175   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21176   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21177   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21178   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21179   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21180   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21181   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21182   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21183
21184   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
21185   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
21186   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
21187   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
21188
21189   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21190   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21191   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
21192   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
21193   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21194   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21195   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21196   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpsdv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21197   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpssv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21198   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21199   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21200   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21201   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21202   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
21203   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
21204   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
21205   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2pd256, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
21206   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2ps256, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
21207   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
21208   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2dq256, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
21209   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
21210   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttpd2dq256, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
21211   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
21212   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttps2dq256, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
21213   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21214   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21215   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
21216   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
21217   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
21218   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
21219   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
21220   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
21221   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
21222   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
21223
21224   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21225   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21226   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
21227
21228   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
21229   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21230   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21231   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21232   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21233
21234   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21235
21236   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
21237   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
21238
21239   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21240   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21241   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21242   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21243
21244   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
21245   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
21246   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
21247   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si_si256, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
21248   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps_ps256, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
21249   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd_pd256, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
21250
21251   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21252   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21253   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21254   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21255   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21256   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21257   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21258   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21259   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21260   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21261   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21262   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21263   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21264   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21265   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21266
21267   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
21268   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
21269 };
21270
21271 /* SSE5 */
21272 enum multi_arg_type {
21273   MULTI_ARG_UNKNOWN,
21274   MULTI_ARG_3_SF,
21275   MULTI_ARG_3_DF,
21276   MULTI_ARG_3_DI,
21277   MULTI_ARG_3_SI,
21278   MULTI_ARG_3_SI_DI,
21279   MULTI_ARG_3_HI,
21280   MULTI_ARG_3_HI_SI,
21281   MULTI_ARG_3_QI,
21282   MULTI_ARG_3_PERMPS,
21283   MULTI_ARG_3_PERMPD,
21284   MULTI_ARG_2_SF,
21285   MULTI_ARG_2_DF,
21286   MULTI_ARG_2_DI,
21287   MULTI_ARG_2_SI,
21288   MULTI_ARG_2_HI,
21289   MULTI_ARG_2_QI,
21290   MULTI_ARG_2_DI_IMM,
21291   MULTI_ARG_2_SI_IMM,
21292   MULTI_ARG_2_HI_IMM,
21293   MULTI_ARG_2_QI_IMM,
21294   MULTI_ARG_2_SF_CMP,
21295   MULTI_ARG_2_DF_CMP,
21296   MULTI_ARG_2_DI_CMP,
21297   MULTI_ARG_2_SI_CMP,
21298   MULTI_ARG_2_HI_CMP,
21299   MULTI_ARG_2_QI_CMP,
21300   MULTI_ARG_2_DI_TF,
21301   MULTI_ARG_2_SI_TF,
21302   MULTI_ARG_2_HI_TF,
21303   MULTI_ARG_2_QI_TF,
21304   MULTI_ARG_2_SF_TF,
21305   MULTI_ARG_2_DF_TF,
21306   MULTI_ARG_1_SF,
21307   MULTI_ARG_1_DF,
21308   MULTI_ARG_1_DI,
21309   MULTI_ARG_1_SI,
21310   MULTI_ARG_1_HI,
21311   MULTI_ARG_1_QI,
21312   MULTI_ARG_1_SI_DI,
21313   MULTI_ARG_1_HI_DI,
21314   MULTI_ARG_1_HI_SI,
21315   MULTI_ARG_1_QI_DI,
21316   MULTI_ARG_1_QI_SI,
21317   MULTI_ARG_1_QI_HI,
21318   MULTI_ARG_1_PH2PS,
21319   MULTI_ARG_1_PS2PH
21320 };
21321
21322 static const struct builtin_description bdesc_multi_arg[] =
21323 {
21324   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv4sf4,     "__builtin_ia32_fmaddss",    IX86_BUILTIN_FMADDSS,    0,            (int)MULTI_ARG_3_SF },
21325   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv2df4,     "__builtin_ia32_fmaddsd",    IX86_BUILTIN_FMADDSD,    0,            (int)MULTI_ARG_3_DF },
21326   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv4sf4,       "__builtin_ia32_fmaddps",    IX86_BUILTIN_FMADDPS,    0,            (int)MULTI_ARG_3_SF },
21327   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv2df4,       "__builtin_ia32_fmaddpd",    IX86_BUILTIN_FMADDPD,    0,            (int)MULTI_ARG_3_DF },
21328   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv4sf4,     "__builtin_ia32_fmsubss",    IX86_BUILTIN_FMSUBSS,    0,            (int)MULTI_ARG_3_SF },
21329   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv2df4,     "__builtin_ia32_fmsubsd",    IX86_BUILTIN_FMSUBSD,    0,            (int)MULTI_ARG_3_DF },
21330   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv4sf4,       "__builtin_ia32_fmsubps",    IX86_BUILTIN_FMSUBPS,    0,            (int)MULTI_ARG_3_SF },
21331   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv2df4,       "__builtin_ia32_fmsubpd",    IX86_BUILTIN_FMSUBPD,    0,            (int)MULTI_ARG_3_DF },
21332   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv4sf4,    "__builtin_ia32_fnmaddss",   IX86_BUILTIN_FNMADDSS,   0,            (int)MULTI_ARG_3_SF },
21333   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv2df4,    "__builtin_ia32_fnmaddsd",   IX86_BUILTIN_FNMADDSD,   0,            (int)MULTI_ARG_3_DF },
21334   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv4sf4,      "__builtin_ia32_fnmaddps",   IX86_BUILTIN_FNMADDPS,   0,            (int)MULTI_ARG_3_SF },
21335   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv2df4,      "__builtin_ia32_fnmaddpd",   IX86_BUILTIN_FNMADDPD,   0,            (int)MULTI_ARG_3_DF },
21336   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv4sf4,    "__builtin_ia32_fnmsubss",   IX86_BUILTIN_FNMSUBSS,   0,            (int)MULTI_ARG_3_SF },
21337   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv2df4,    "__builtin_ia32_fnmsubsd",   IX86_BUILTIN_FNMSUBSD,   0,            (int)MULTI_ARG_3_DF },
21338   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv4sf4,      "__builtin_ia32_fnmsubps",   IX86_BUILTIN_FNMSUBPS,   0,            (int)MULTI_ARG_3_SF },
21339   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv2df4,      "__builtin_ia32_fnmsubpd",   IX86_BUILTIN_FNMSUBPD,   0,            (int)MULTI_ARG_3_DF },
21340   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov",      IX86_BUILTIN_PCMOV,      0,            (int)MULTI_ARG_3_DI },
21341   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov_v2di", IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
21342   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4si,        "__builtin_ia32_pcmov_v4si", IX86_BUILTIN_PCMOV_V4SI, 0,            (int)MULTI_ARG_3_SI },
21343   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v8hi,        "__builtin_ia32_pcmov_v8hi", IX86_BUILTIN_PCMOV_V8HI, 0,            (int)MULTI_ARG_3_HI },
21344   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v16qi,       "__builtin_ia32_pcmov_v16qi",IX86_BUILTIN_PCMOV_V16QI,0,            (int)MULTI_ARG_3_QI },
21345   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2df,        "__builtin_ia32_pcmov_v2df", IX86_BUILTIN_PCMOV_V2DF, 0,            (int)MULTI_ARG_3_DF },
21346   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4sf,        "__builtin_ia32_pcmov_v4sf", IX86_BUILTIN_PCMOV_V4SF, 0,            (int)MULTI_ARG_3_SF },
21347   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pperm,             "__builtin_ia32_pperm",      IX86_BUILTIN_PPERM,      0,            (int)MULTI_ARG_3_QI },
21348   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv4sf,          "__builtin_ia32_permps",     IX86_BUILTIN_PERMPS,     0,            (int)MULTI_ARG_3_PERMPS },
21349   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv2df,          "__builtin_ia32_permpd",     IX86_BUILTIN_PERMPD,     0,            (int)MULTI_ARG_3_PERMPD },
21350   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssww,          "__builtin_ia32_pmacssww",   IX86_BUILTIN_PMACSSWW,   0,            (int)MULTI_ARG_3_HI },
21351   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsww,           "__builtin_ia32_pmacsww",    IX86_BUILTIN_PMACSWW,    0,            (int)MULTI_ARG_3_HI },
21352   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsswd,          "__builtin_ia32_pmacsswd",   IX86_BUILTIN_PMACSSWD,   0,            (int)MULTI_ARG_3_HI_SI },
21353   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacswd,           "__builtin_ia32_pmacswd",    IX86_BUILTIN_PMACSWD,    0,            (int)MULTI_ARG_3_HI_SI },
21354   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdd,          "__builtin_ia32_pmacssdd",   IX86_BUILTIN_PMACSSDD,   0,            (int)MULTI_ARG_3_SI },
21355   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdd,           "__builtin_ia32_pmacsdd",    IX86_BUILTIN_PMACSDD,    0,            (int)MULTI_ARG_3_SI },
21356   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdql,         "__builtin_ia32_pmacssdql",  IX86_BUILTIN_PMACSSDQL,  0,            (int)MULTI_ARG_3_SI_DI },
21357   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdqh,         "__builtin_ia32_pmacssdqh",  IX86_BUILTIN_PMACSSDQH,  0,            (int)MULTI_ARG_3_SI_DI },
21358   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdql,          "__builtin_ia32_pmacsdql",   IX86_BUILTIN_PMACSDQL,   0,            (int)MULTI_ARG_3_SI_DI },
21359   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdqh,          "__builtin_ia32_pmacsdqh",   IX86_BUILTIN_PMACSDQH,   0,            (int)MULTI_ARG_3_SI_DI },
21360   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcsswd,         "__builtin_ia32_pmadcsswd",  IX86_BUILTIN_PMADCSSWD,  0,            (int)MULTI_ARG_3_HI_SI },
21361   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcswd,          "__builtin_ia32_pmadcswd",   IX86_BUILTIN_PMADCSWD,   0,            (int)MULTI_ARG_3_HI_SI },
21362   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv2di3,        "__builtin_ia32_protq",      IX86_BUILTIN_PROTQ,      0,            (int)MULTI_ARG_2_DI },
21363   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv4si3,        "__builtin_ia32_protd",      IX86_BUILTIN_PROTD,      0,            (int)MULTI_ARG_2_SI },
21364   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv8hi3,        "__builtin_ia32_protw",      IX86_BUILTIN_PROTW,      0,            (int)MULTI_ARG_2_HI },
21365   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv16qi3,       "__builtin_ia32_protb",      IX86_BUILTIN_PROTB,      0,            (int)MULTI_ARG_2_QI },
21366   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv2di3,         "__builtin_ia32_protqi",     IX86_BUILTIN_PROTQ_IMM,  0,            (int)MULTI_ARG_2_DI_IMM },
21367   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv4si3,         "__builtin_ia32_protdi",     IX86_BUILTIN_PROTD_IMM,  0,            (int)MULTI_ARG_2_SI_IMM },
21368   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv8hi3,         "__builtin_ia32_protwi",     IX86_BUILTIN_PROTW_IMM,  0,            (int)MULTI_ARG_2_HI_IMM },
21369   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv16qi3,        "__builtin_ia32_protbi",     IX86_BUILTIN_PROTB_IMM,  0,            (int)MULTI_ARG_2_QI_IMM },
21370   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv2di3,         "__builtin_ia32_pshaq",      IX86_BUILTIN_PSHAQ,      0,            (int)MULTI_ARG_2_DI },
21371   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv4si3,         "__builtin_ia32_pshad",      IX86_BUILTIN_PSHAD,      0,            (int)MULTI_ARG_2_SI },
21372   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv8hi3,         "__builtin_ia32_pshaw",      IX86_BUILTIN_PSHAW,      0,            (int)MULTI_ARG_2_HI },
21373   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv16qi3,        "__builtin_ia32_pshab",      IX86_BUILTIN_PSHAB,      0,            (int)MULTI_ARG_2_QI },
21374   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv2di3,         "__builtin_ia32_pshlq",      IX86_BUILTIN_PSHLQ,      0,            (int)MULTI_ARG_2_DI },
21375   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv4si3,         "__builtin_ia32_pshld",      IX86_BUILTIN_PSHLD,      0,            (int)MULTI_ARG_2_SI },
21376   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv8hi3,         "__builtin_ia32_pshlw",      IX86_BUILTIN_PSHLW,      0,            (int)MULTI_ARG_2_HI },
21377   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv16qi3,        "__builtin_ia32_pshlb",      IX86_BUILTIN_PSHLB,      0,            (int)MULTI_ARG_2_QI },
21378   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv4sf2,       "__builtin_ia32_frczss",     IX86_BUILTIN_FRCZSS,     0,            (int)MULTI_ARG_2_SF },
21379   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv2df2,       "__builtin_ia32_frczsd",     IX86_BUILTIN_FRCZSD,     0,            (int)MULTI_ARG_2_DF },
21380   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv4sf2,         "__builtin_ia32_frczps",     IX86_BUILTIN_FRCZPS,     0,            (int)MULTI_ARG_1_SF },
21381   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv2df2,         "__builtin_ia32_frczpd",     IX86_BUILTIN_FRCZPD,     0,            (int)MULTI_ARG_1_DF },
21382   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtph2ps,          "__builtin_ia32_cvtph2ps",   IX86_BUILTIN_CVTPH2PS,   0,            (int)MULTI_ARG_1_PH2PS },
21383   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtps2ph,          "__builtin_ia32_cvtps2ph",   IX86_BUILTIN_CVTPS2PH,   0,            (int)MULTI_ARG_1_PS2PH },
21384   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbw,           "__builtin_ia32_phaddbw",    IX86_BUILTIN_PHADDBW,    0,            (int)MULTI_ARG_1_QI_HI },
21385   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbd,           "__builtin_ia32_phaddbd",    IX86_BUILTIN_PHADDBD,    0,            (int)MULTI_ARG_1_QI_SI },
21386   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbq,           "__builtin_ia32_phaddbq",    IX86_BUILTIN_PHADDBQ,    0,            (int)MULTI_ARG_1_QI_DI },
21387   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwd,           "__builtin_ia32_phaddwd",    IX86_BUILTIN_PHADDWD,    0,            (int)MULTI_ARG_1_HI_SI },
21388   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwq,           "__builtin_ia32_phaddwq",    IX86_BUILTIN_PHADDWQ,    0,            (int)MULTI_ARG_1_HI_DI },
21389   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadddq,           "__builtin_ia32_phadddq",    IX86_BUILTIN_PHADDDQ,    0,            (int)MULTI_ARG_1_SI_DI },
21390   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubw,          "__builtin_ia32_phaddubw",   IX86_BUILTIN_PHADDUBW,   0,            (int)MULTI_ARG_1_QI_HI },
21391   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubd,          "__builtin_ia32_phaddubd",   IX86_BUILTIN_PHADDUBD,   0,            (int)MULTI_ARG_1_QI_SI },
21392   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubq,          "__builtin_ia32_phaddubq",   IX86_BUILTIN_PHADDUBQ,   0,            (int)MULTI_ARG_1_QI_DI },
21393   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwd,          "__builtin_ia32_phadduwd",   IX86_BUILTIN_PHADDUWD,   0,            (int)MULTI_ARG_1_HI_SI },
21394   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwq,          "__builtin_ia32_phadduwq",   IX86_BUILTIN_PHADDUWQ,   0,            (int)MULTI_ARG_1_HI_DI },
21395   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddudq,          "__builtin_ia32_phaddudq",   IX86_BUILTIN_PHADDUDQ,   0,            (int)MULTI_ARG_1_SI_DI },
21396   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubbw,           "__builtin_ia32_phsubbw",    IX86_BUILTIN_PHSUBBW,    0,            (int)MULTI_ARG_1_QI_HI },
21397   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubwd,           "__builtin_ia32_phsubwd",    IX86_BUILTIN_PHSUBWD,    0,            (int)MULTI_ARG_1_HI_SI },
21398   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubdq,           "__builtin_ia32_phsubdq",    IX86_BUILTIN_PHSUBDQ,    0,            (int)MULTI_ARG_1_SI_DI },
21399
21400   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comeqss",    IX86_BUILTIN_COMEQSS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
21401   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comness",    IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21402   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comneqss",   IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21403   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comltss",    IX86_BUILTIN_COMLTSS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21404   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comless",    IX86_BUILTIN_COMLESS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21405   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgtss",    IX86_BUILTIN_COMGTSS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21406   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgess",    IX86_BUILTIN_COMGESS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21407   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comueqss",   IX86_BUILTIN_COMUEQSS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21408   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuness",   IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21409   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuneqss",  IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21410   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunltss",  IX86_BUILTIN_COMULTSS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21411   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunless",  IX86_BUILTIN_COMULESS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21412   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungtss",  IX86_BUILTIN_COMUGTSS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21413   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungess",  IX86_BUILTIN_COMUGESS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21414   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comordss",   IX86_BUILTIN_COMORDSS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21415   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunordss", IX86_BUILTIN_COMUNORDSS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21416
21417   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comeqsd",    IX86_BUILTIN_COMEQSD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21418   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comnesd",    IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21419   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comneqsd",   IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21420   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comltsd",    IX86_BUILTIN_COMLTSD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21421   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comlesd",    IX86_BUILTIN_COMLESD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21422   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgtsd",    IX86_BUILTIN_COMGTSD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21423   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgesd",    IX86_BUILTIN_COMGESD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21424   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comueqsd",   IX86_BUILTIN_COMUEQSD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21425   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunesd",   IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21426   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comuneqsd",  IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21427   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunltsd",  IX86_BUILTIN_COMULTSD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21428   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunlesd",  IX86_BUILTIN_COMULESD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21429   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungtsd",  IX86_BUILTIN_COMUGTSD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21430   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungesd",  IX86_BUILTIN_COMUGESD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21431   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comordsd",   IX86_BUILTIN_COMORDSD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21432   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunordsd", IX86_BUILTIN_COMUNORDSD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21433
21434   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comeqps",    IX86_BUILTIN_COMEQPS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
21435   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneps",    IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21436   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneqps",   IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21437   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comltps",    IX86_BUILTIN_COMLTPS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21438   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comleps",    IX86_BUILTIN_COMLEPS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21439   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgtps",    IX86_BUILTIN_COMGTPS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21440   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgeps",    IX86_BUILTIN_COMGEPS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21441   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comueqps",   IX86_BUILTIN_COMUEQPS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21442   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneps",   IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21443   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneqps",  IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21444   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunltps",  IX86_BUILTIN_COMULTPS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21445   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunleps",  IX86_BUILTIN_COMULEPS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21446   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungtps",  IX86_BUILTIN_COMUGTPS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21447   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungeps",  IX86_BUILTIN_COMUGEPS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21448   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comordps",   IX86_BUILTIN_COMORDPS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21449   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunordps", IX86_BUILTIN_COMUNORDPS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21450
21451   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comeqpd",    IX86_BUILTIN_COMEQPD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21452   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comnepd",    IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21453   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comneqpd",   IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21454   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comltpd",    IX86_BUILTIN_COMLTPD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21455   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comlepd",    IX86_BUILTIN_COMLEPD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21456   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgtpd",    IX86_BUILTIN_COMGTPD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21457   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgepd",    IX86_BUILTIN_COMGEPD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21458   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comueqpd",   IX86_BUILTIN_COMUEQPD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21459   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunepd",   IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21460   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comuneqpd",  IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21461   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunltpd",  IX86_BUILTIN_COMULTPD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21462   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunlepd",  IX86_BUILTIN_COMULEPD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21463   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungtpd",  IX86_BUILTIN_COMUGTPD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21464   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungepd",  IX86_BUILTIN_COMUGEPD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21465   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comordpd",   IX86_BUILTIN_COMORDPD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21466   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunordpd", IX86_BUILTIN_COMUNORDPD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21467
21468   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomeqb",    IX86_BUILTIN_PCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
21469   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneb",    IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21470   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneqb",   IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21471   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomltb",    IX86_BUILTIN_PCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
21472   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomleb",    IX86_BUILTIN_PCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
21473   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgtb",    IX86_BUILTIN_PCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
21474   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgeb",    IX86_BUILTIN_PCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
21475
21476   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomeqw",    IX86_BUILTIN_PCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
21477   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomnew",    IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21478   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomneqw",   IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21479   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomltw",    IX86_BUILTIN_PCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
21480   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomlew",    IX86_BUILTIN_PCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
21481   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgtw",    IX86_BUILTIN_PCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
21482   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgew",    IX86_BUILTIN_PCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
21483
21484   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomeqd",    IX86_BUILTIN_PCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
21485   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomned",    IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21486   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomneqd",   IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21487   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomltd",    IX86_BUILTIN_PCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
21488   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomled",    IX86_BUILTIN_PCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
21489   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomgtd",    IX86_BUILTIN_PCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
21490   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomged",    IX86_BUILTIN_PCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
21491
21492   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomeqq",    IX86_BUILTIN_PCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
21493   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneq",    IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21494   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneqq",   IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21495   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomltq",    IX86_BUILTIN_PCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
21496   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomleq",    IX86_BUILTIN_PCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
21497   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgtq",    IX86_BUILTIN_PCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
21498   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgeq",    IX86_BUILTIN_PCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
21499
21500   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomequb",   IX86_BUILTIN_PCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
21501   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomneub",   IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21502   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomnequb",  IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21503   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomltub",   IX86_BUILTIN_PCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
21504   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomleub",   IX86_BUILTIN_PCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
21505   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgtub",   IX86_BUILTIN_PCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
21506   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgeub",   IX86_BUILTIN_PCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
21507
21508   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomequw",   IX86_BUILTIN_PCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
21509   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomneuw",   IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21510   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomnequw",  IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21511   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomltuw",   IX86_BUILTIN_PCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
21512   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomleuw",   IX86_BUILTIN_PCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
21513   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgtuw",   IX86_BUILTIN_PCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
21514   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgeuw",   IX86_BUILTIN_PCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
21515
21516   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomequd",   IX86_BUILTIN_PCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
21517   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomneud",   IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21518   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomnequd",  IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21519   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomltud",   IX86_BUILTIN_PCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
21520   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomleud",   IX86_BUILTIN_PCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
21521   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgtud",   IX86_BUILTIN_PCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
21522   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgeud",   IX86_BUILTIN_PCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
21523
21524   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomequq",   IX86_BUILTIN_PCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
21525   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomneuq",   IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21526   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomnequq",  IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21527   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomltuq",   IX86_BUILTIN_PCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
21528   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomleuq",   IX86_BUILTIN_PCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
21529   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgtuq",   IX86_BUILTIN_PCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
21530   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgeuq",   IX86_BUILTIN_PCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
21531
21532   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalsess", IX86_BUILTIN_COMFALSESS, COM_FALSE_S,  (int)MULTI_ARG_2_SF_TF },
21533   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtruess",  IX86_BUILTIN_COMTRUESS,  COM_TRUE_S,   (int)MULTI_ARG_2_SF_TF },
21534   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalseps", IX86_BUILTIN_COMFALSEPS, COM_FALSE_P,  (int)MULTI_ARG_2_SF_TF },
21535   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtrueps",  IX86_BUILTIN_COMTRUEPS,  COM_TRUE_P,   (int)MULTI_ARG_2_SF_TF },
21536   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsesd", IX86_BUILTIN_COMFALSESD, COM_FALSE_S,  (int)MULTI_ARG_2_DF_TF },
21537   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruesd",  IX86_BUILTIN_COMTRUESD,  COM_TRUE_S,   (int)MULTI_ARG_2_DF_TF },
21538   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsepd", IX86_BUILTIN_COMFALSEPD, COM_FALSE_P,  (int)MULTI_ARG_2_DF_TF },
21539   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruepd",  IX86_BUILTIN_COMTRUEPD,  COM_TRUE_P,   (int)MULTI_ARG_2_DF_TF },
21540
21541   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseb", IX86_BUILTIN_PCOMFALSEB, PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21542   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalsew", IX86_BUILTIN_PCOMFALSEW, PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21543   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalsed", IX86_BUILTIN_PCOMFALSED, PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21544   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseq", IX86_BUILTIN_PCOMFALSEQ, PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21545   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseub",IX86_BUILTIN_PCOMFALSEUB,PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21546   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalseuw",IX86_BUILTIN_PCOMFALSEUW,PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21547   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalseud",IX86_BUILTIN_PCOMFALSEUD,PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21548   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseuq",IX86_BUILTIN_PCOMFALSEUQ,PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21549
21550   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueb",  IX86_BUILTIN_PCOMTRUEB,  PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21551   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtruew",  IX86_BUILTIN_PCOMTRUEW,  PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21552   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrued",  IX86_BUILTIN_PCOMTRUED,  PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21553   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueq",  IX86_BUILTIN_PCOMTRUEQ,  PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21554   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueub", IX86_BUILTIN_PCOMTRUEUB, PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21555   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtrueuw", IX86_BUILTIN_PCOMTRUEUW, PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21556   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrueud", IX86_BUILTIN_PCOMTRUEUD, PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21557   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueuq", IX86_BUILTIN_PCOMTRUEUQ, PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21558 };
21559
21560 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
21561    in the current target ISA to allow the user to compile particular modules
21562    with different target specific options that differ from the command line
21563    options.  */
21564 static void
21565 ix86_init_mmx_sse_builtins (void)
21566 {
21567   const struct builtin_description * d;
21568   size_t i;
21569
21570   tree V16QI_type_node = build_vector_type_for_mode (char_type_node, V16QImode);
21571   tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
21572   tree V1DI_type_node
21573     = build_vector_type_for_mode (long_long_integer_type_node, V1DImode);
21574   tree V2SF_type_node = build_vector_type_for_mode (float_type_node, V2SFmode);
21575   tree V2DI_type_node
21576     = build_vector_type_for_mode (long_long_integer_type_node, V2DImode);
21577   tree V2DF_type_node = build_vector_type_for_mode (double_type_node, V2DFmode);
21578   tree V4SF_type_node = build_vector_type_for_mode (float_type_node, V4SFmode);
21579   tree V4SI_type_node = build_vector_type_for_mode (intSI_type_node, V4SImode);
21580   tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
21581   tree V8QI_type_node = build_vector_type_for_mode (char_type_node, V8QImode);
21582   tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, V8HImode);
21583
21584   tree pchar_type_node = build_pointer_type (char_type_node);
21585   tree pcchar_type_node
21586     = build_pointer_type (build_type_variant (char_type_node, 1, 0));
21587   tree pfloat_type_node = build_pointer_type (float_type_node);
21588   tree pcfloat_type_node
21589     = build_pointer_type (build_type_variant (float_type_node, 1, 0));
21590   tree pv2sf_type_node = build_pointer_type (V2SF_type_node);
21591   tree pcv2sf_type_node
21592     = build_pointer_type (build_type_variant (V2SF_type_node, 1, 0));
21593   tree pv2di_type_node = build_pointer_type (V2DI_type_node);
21594   tree pdi_type_node = build_pointer_type (long_long_unsigned_type_node);
21595
21596   /* Comparisons.  */
21597   tree int_ftype_v4sf_v4sf
21598     = build_function_type_list (integer_type_node,
21599                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21600   tree v4si_ftype_v4sf_v4sf
21601     = build_function_type_list (V4SI_type_node,
21602                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21603   /* MMX/SSE/integer conversions.  */
21604   tree int_ftype_v4sf
21605     = build_function_type_list (integer_type_node,
21606                                 V4SF_type_node, NULL_TREE);
21607   tree int64_ftype_v4sf
21608     = build_function_type_list (long_long_integer_type_node,
21609                                 V4SF_type_node, NULL_TREE);
21610   tree int_ftype_v8qi
21611     = build_function_type_list (integer_type_node, V8QI_type_node, NULL_TREE);
21612   tree v4sf_ftype_v4sf_int
21613     = build_function_type_list (V4SF_type_node,
21614                                 V4SF_type_node, integer_type_node, NULL_TREE);
21615   tree v4sf_ftype_v4sf_int64
21616     = build_function_type_list (V4SF_type_node,
21617                                 V4SF_type_node, long_long_integer_type_node,
21618                                 NULL_TREE);
21619   tree v4sf_ftype_v4sf_v2si
21620     = build_function_type_list (V4SF_type_node,
21621                                 V4SF_type_node, V2SI_type_node, NULL_TREE);
21622
21623   /* Miscellaneous.  */
21624   tree v8qi_ftype_v4hi_v4hi
21625     = build_function_type_list (V8QI_type_node,
21626                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21627   tree v4hi_ftype_v2si_v2si
21628     = build_function_type_list (V4HI_type_node,
21629                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21630   tree v4sf_ftype_v4sf_v4sf_int
21631     = build_function_type_list (V4SF_type_node,
21632                                 V4SF_type_node, V4SF_type_node,
21633                                 integer_type_node, NULL_TREE);
21634   tree v2si_ftype_v4hi_v4hi
21635     = build_function_type_list (V2SI_type_node,
21636                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21637   tree v4hi_ftype_v4hi_int
21638     = build_function_type_list (V4HI_type_node,
21639                                 V4HI_type_node, integer_type_node, NULL_TREE);
21640   tree v2si_ftype_v2si_int
21641     = build_function_type_list (V2SI_type_node,
21642                                 V2SI_type_node, integer_type_node, NULL_TREE);
21643   tree v1di_ftype_v1di_int
21644     = build_function_type_list (V1DI_type_node,
21645                                 V1DI_type_node, integer_type_node, NULL_TREE);
21646
21647   tree void_ftype_void
21648     = build_function_type (void_type_node, void_list_node);
21649   tree void_ftype_unsigned
21650     = build_function_type_list (void_type_node, unsigned_type_node, NULL_TREE);
21651   tree void_ftype_unsigned_unsigned
21652     = build_function_type_list (void_type_node, unsigned_type_node,
21653                                 unsigned_type_node, NULL_TREE);
21654   tree void_ftype_pcvoid_unsigned_unsigned
21655     = build_function_type_list (void_type_node, const_ptr_type_node,
21656                                 unsigned_type_node, unsigned_type_node,
21657                                 NULL_TREE);
21658   tree unsigned_ftype_void
21659     = build_function_type (unsigned_type_node, void_list_node);
21660   tree v2si_ftype_v4sf
21661     = build_function_type_list (V2SI_type_node, V4SF_type_node, NULL_TREE);
21662   /* Loads/stores.  */
21663   tree void_ftype_v8qi_v8qi_pchar
21664     = build_function_type_list (void_type_node,
21665                                 V8QI_type_node, V8QI_type_node,
21666                                 pchar_type_node, NULL_TREE);
21667   tree v4sf_ftype_pcfloat
21668     = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
21669   tree v4sf_ftype_v4sf_pcv2sf
21670     = build_function_type_list (V4SF_type_node,
21671                                 V4SF_type_node, pcv2sf_type_node, NULL_TREE);
21672   tree void_ftype_pv2sf_v4sf
21673     = build_function_type_list (void_type_node,
21674                                 pv2sf_type_node, V4SF_type_node, NULL_TREE);
21675   tree void_ftype_pfloat_v4sf
21676     = build_function_type_list (void_type_node,
21677                                 pfloat_type_node, V4SF_type_node, NULL_TREE);
21678   tree void_ftype_pdi_di
21679     = build_function_type_list (void_type_node,
21680                                 pdi_type_node, long_long_unsigned_type_node,
21681                                 NULL_TREE);
21682   tree void_ftype_pv2di_v2di
21683     = build_function_type_list (void_type_node,
21684                                 pv2di_type_node, V2DI_type_node, NULL_TREE);
21685   /* Normal vector unops.  */
21686   tree v4sf_ftype_v4sf
21687     = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
21688   tree v16qi_ftype_v16qi
21689     = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
21690   tree v8hi_ftype_v8hi
21691     = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
21692   tree v4si_ftype_v4si
21693     = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
21694   tree v8qi_ftype_v8qi
21695     = build_function_type_list (V8QI_type_node, V8QI_type_node, NULL_TREE);
21696   tree v4hi_ftype_v4hi
21697     = build_function_type_list (V4HI_type_node, V4HI_type_node, NULL_TREE);
21698
21699   /* Normal vector binops.  */
21700   tree v4sf_ftype_v4sf_v4sf
21701     = build_function_type_list (V4SF_type_node,
21702                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21703   tree v8qi_ftype_v8qi_v8qi
21704     = build_function_type_list (V8QI_type_node,
21705                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
21706   tree v4hi_ftype_v4hi_v4hi
21707     = build_function_type_list (V4HI_type_node,
21708                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21709   tree v2si_ftype_v2si_v2si
21710     = build_function_type_list (V2SI_type_node,
21711                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21712   tree v1di_ftype_v1di_v1di
21713     = build_function_type_list (V1DI_type_node,
21714                                 V1DI_type_node, V1DI_type_node, NULL_TREE);
21715   tree v1di_ftype_v1di_v1di_int
21716     = build_function_type_list (V1DI_type_node,
21717                                 V1DI_type_node, V1DI_type_node,
21718                                 integer_type_node, NULL_TREE);
21719   tree v2si_ftype_v2sf
21720     = build_function_type_list (V2SI_type_node, V2SF_type_node, NULL_TREE);
21721   tree v2sf_ftype_v2si
21722     = build_function_type_list (V2SF_type_node, V2SI_type_node, NULL_TREE);
21723   tree v2si_ftype_v2si
21724     = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
21725   tree v2sf_ftype_v2sf
21726     = build_function_type_list (V2SF_type_node, V2SF_type_node, NULL_TREE);
21727   tree v2sf_ftype_v2sf_v2sf
21728     = build_function_type_list (V2SF_type_node,
21729                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
21730   tree v2si_ftype_v2sf_v2sf
21731     = build_function_type_list (V2SI_type_node,
21732                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
21733   tree pint_type_node    = build_pointer_type (integer_type_node);
21734   tree pdouble_type_node = build_pointer_type (double_type_node);
21735   tree pcdouble_type_node = build_pointer_type (
21736                                 build_type_variant (double_type_node, 1, 0));
21737   tree int_ftype_v2df_v2df
21738     = build_function_type_list (integer_type_node,
21739                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21740
21741   tree void_ftype_pcvoid
21742     = build_function_type_list (void_type_node, const_ptr_type_node, NULL_TREE);
21743   tree v4sf_ftype_v4si
21744     = build_function_type_list (V4SF_type_node, V4SI_type_node, NULL_TREE);
21745   tree v4si_ftype_v4sf
21746     = build_function_type_list (V4SI_type_node, V4SF_type_node, NULL_TREE);
21747   tree v2df_ftype_v4si
21748     = build_function_type_list (V2DF_type_node, V4SI_type_node, NULL_TREE);
21749   tree v4si_ftype_v2df
21750     = build_function_type_list (V4SI_type_node, V2DF_type_node, NULL_TREE);
21751   tree v4si_ftype_v2df_v2df
21752     = build_function_type_list (V4SI_type_node,
21753                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21754   tree v2si_ftype_v2df
21755     = build_function_type_list (V2SI_type_node, V2DF_type_node, NULL_TREE);
21756   tree v4sf_ftype_v2df
21757     = build_function_type_list (V4SF_type_node, V2DF_type_node, NULL_TREE);
21758   tree v2df_ftype_v2si
21759     = build_function_type_list (V2DF_type_node, V2SI_type_node, NULL_TREE);
21760   tree v2df_ftype_v4sf
21761     = build_function_type_list (V2DF_type_node, V4SF_type_node, NULL_TREE);
21762   tree int_ftype_v2df
21763     = build_function_type_list (integer_type_node, V2DF_type_node, NULL_TREE);
21764   tree int64_ftype_v2df
21765     = build_function_type_list (long_long_integer_type_node,
21766                                 V2DF_type_node, NULL_TREE);
21767   tree v2df_ftype_v2df_int
21768     = build_function_type_list (V2DF_type_node,
21769                                 V2DF_type_node, integer_type_node, NULL_TREE);
21770   tree v2df_ftype_v2df_int64
21771     = build_function_type_list (V2DF_type_node,
21772                                 V2DF_type_node, long_long_integer_type_node,
21773                                 NULL_TREE);
21774   tree v4sf_ftype_v4sf_v2df
21775     = build_function_type_list (V4SF_type_node,
21776                                 V4SF_type_node, V2DF_type_node, NULL_TREE);
21777   tree v2df_ftype_v2df_v4sf
21778     = build_function_type_list (V2DF_type_node,
21779                                 V2DF_type_node, V4SF_type_node, NULL_TREE);
21780   tree v2df_ftype_v2df_v2df_int
21781     = build_function_type_list (V2DF_type_node,
21782                                 V2DF_type_node, V2DF_type_node,
21783                                 integer_type_node,
21784                                 NULL_TREE);
21785   tree v2df_ftype_v2df_pcdouble
21786     = build_function_type_list (V2DF_type_node,
21787                                 V2DF_type_node, pcdouble_type_node, NULL_TREE);
21788   tree void_ftype_pdouble_v2df
21789     = build_function_type_list (void_type_node,
21790                                 pdouble_type_node, V2DF_type_node, NULL_TREE);
21791   tree void_ftype_pint_int
21792     = build_function_type_list (void_type_node,
21793                                 pint_type_node, integer_type_node, NULL_TREE);
21794   tree void_ftype_v16qi_v16qi_pchar
21795     = build_function_type_list (void_type_node,
21796                                 V16QI_type_node, V16QI_type_node,
21797                                 pchar_type_node, NULL_TREE);
21798   tree v2df_ftype_pcdouble
21799     = build_function_type_list (V2DF_type_node, pcdouble_type_node, NULL_TREE);
21800   tree v2df_ftype_v2df_v2df
21801     = build_function_type_list (V2DF_type_node,
21802                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21803   tree v16qi_ftype_v16qi_v16qi
21804     = build_function_type_list (V16QI_type_node,
21805                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
21806   tree v8hi_ftype_v8hi_v8hi
21807     = build_function_type_list (V8HI_type_node,
21808                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
21809   tree v4si_ftype_v4si_v4si
21810     = build_function_type_list (V4SI_type_node,
21811                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
21812   tree v2di_ftype_v2di_v2di
21813     = build_function_type_list (V2DI_type_node,
21814                                 V2DI_type_node, V2DI_type_node, NULL_TREE);
21815   tree v2di_ftype_v2df_v2df
21816     = build_function_type_list (V2DI_type_node,
21817                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21818   tree v2df_ftype_v2df
21819     = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
21820   tree v2di_ftype_v2di_int
21821     = build_function_type_list (V2DI_type_node,
21822                                 V2DI_type_node, integer_type_node, NULL_TREE);
21823   tree v2di_ftype_v2di_v2di_int
21824     = build_function_type_list (V2DI_type_node, V2DI_type_node,
21825                                 V2DI_type_node, integer_type_node, NULL_TREE);
21826   tree v4si_ftype_v4si_int
21827     = build_function_type_list (V4SI_type_node,
21828                                 V4SI_type_node, integer_type_node, NULL_TREE);
21829   tree v8hi_ftype_v8hi_int
21830     = build_function_type_list (V8HI_type_node,
21831                                 V8HI_type_node, integer_type_node, NULL_TREE);
21832   tree v4si_ftype_v8hi_v8hi
21833     = build_function_type_list (V4SI_type_node,
21834                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
21835   tree v1di_ftype_v8qi_v8qi
21836     = build_function_type_list (V1DI_type_node,
21837                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
21838   tree v1di_ftype_v2si_v2si
21839     = build_function_type_list (V1DI_type_node,
21840                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21841   tree v2di_ftype_v16qi_v16qi
21842     = build_function_type_list (V2DI_type_node,
21843                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
21844   tree v2di_ftype_v4si_v4si
21845     = build_function_type_list (V2DI_type_node,
21846                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
21847   tree int_ftype_v16qi
21848     = build_function_type_list (integer_type_node, V16QI_type_node, NULL_TREE);
21849   tree v16qi_ftype_pcchar
21850     = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
21851   tree void_ftype_pchar_v16qi
21852     = build_function_type_list (void_type_node,
21853                                 pchar_type_node, V16QI_type_node, NULL_TREE);
21854
21855   tree v2di_ftype_v2di_unsigned_unsigned
21856     = build_function_type_list (V2DI_type_node, V2DI_type_node,
21857                                 unsigned_type_node, unsigned_type_node,
21858                                 NULL_TREE);
21859   tree v2di_ftype_v2di_v2di_unsigned_unsigned
21860     = build_function_type_list (V2DI_type_node, V2DI_type_node, V2DI_type_node,
21861                                 unsigned_type_node, unsigned_type_node,
21862                                 NULL_TREE);
21863   tree v2di_ftype_v2di_v16qi
21864     = build_function_type_list (V2DI_type_node, V2DI_type_node, V16QI_type_node,
21865                                 NULL_TREE);
21866   tree v2df_ftype_v2df_v2df_v2df
21867     = build_function_type_list (V2DF_type_node,
21868                                 V2DF_type_node, V2DF_type_node,
21869                                 V2DF_type_node, NULL_TREE);
21870   tree v4sf_ftype_v4sf_v4sf_v4sf
21871     = build_function_type_list (V4SF_type_node,
21872                                 V4SF_type_node, V4SF_type_node,
21873                                 V4SF_type_node, NULL_TREE);
21874   tree v8hi_ftype_v16qi
21875     = build_function_type_list (V8HI_type_node, V16QI_type_node,
21876                                 NULL_TREE);
21877   tree v4si_ftype_v16qi
21878     = build_function_type_list (V4SI_type_node, V16QI_type_node,
21879                                 NULL_TREE);
21880   tree v2di_ftype_v16qi
21881     = build_function_type_list (V2DI_type_node, V16QI_type_node,
21882                                 NULL_TREE);
21883   tree v4si_ftype_v8hi
21884     = build_function_type_list (V4SI_type_node, V8HI_type_node,
21885                                 NULL_TREE);
21886   tree v2di_ftype_v8hi
21887     = build_function_type_list (V2DI_type_node, V8HI_type_node,
21888                                 NULL_TREE);
21889   tree v2di_ftype_v4si
21890     = build_function_type_list (V2DI_type_node, V4SI_type_node,
21891                                 NULL_TREE);
21892   tree v2di_ftype_pv2di
21893     = build_function_type_list (V2DI_type_node, pv2di_type_node,
21894                                 NULL_TREE);
21895   tree v16qi_ftype_v16qi_v16qi_int
21896     = build_function_type_list (V16QI_type_node, V16QI_type_node,
21897                                 V16QI_type_node, integer_type_node,
21898                                 NULL_TREE);
21899   tree v16qi_ftype_v16qi_v16qi_v16qi
21900     = build_function_type_list (V16QI_type_node, V16QI_type_node,
21901                                 V16QI_type_node, V16QI_type_node,
21902                                 NULL_TREE);
21903   tree v8hi_ftype_v8hi_v8hi_int
21904     = build_function_type_list (V8HI_type_node, V8HI_type_node,
21905                                 V8HI_type_node, integer_type_node,
21906                                 NULL_TREE);
21907   tree v4si_ftype_v4si_v4si_int
21908     = build_function_type_list (V4SI_type_node, V4SI_type_node,
21909                                 V4SI_type_node, integer_type_node,
21910                                 NULL_TREE);
21911   tree int_ftype_v2di_v2di
21912     = build_function_type_list (integer_type_node,
21913                                 V2DI_type_node, V2DI_type_node,
21914                                 NULL_TREE);
21915   tree int_ftype_v16qi_int_v16qi_int_int
21916     = build_function_type_list (integer_type_node,
21917                                 V16QI_type_node,
21918                                 integer_type_node,
21919                                 V16QI_type_node,
21920                                 integer_type_node,
21921                                 integer_type_node,
21922                                 NULL_TREE);
21923   tree v16qi_ftype_v16qi_int_v16qi_int_int
21924     = build_function_type_list (V16QI_type_node,
21925                                 V16QI_type_node,
21926                                 integer_type_node,
21927                                 V16QI_type_node,
21928                                 integer_type_node,
21929                                 integer_type_node,
21930                                 NULL_TREE);
21931   tree int_ftype_v16qi_v16qi_int
21932     = build_function_type_list (integer_type_node,
21933                                 V16QI_type_node,
21934                                 V16QI_type_node,
21935                                 integer_type_node,
21936                                 NULL_TREE);
21937
21938   /* SSE5 instructions */
21939   tree v2di_ftype_v2di_v2di_v2di
21940     = build_function_type_list (V2DI_type_node,
21941                                 V2DI_type_node,
21942                                 V2DI_type_node,
21943                                 V2DI_type_node,
21944                                 NULL_TREE);
21945
21946   tree v4si_ftype_v4si_v4si_v4si
21947     = build_function_type_list (V4SI_type_node,
21948                                 V4SI_type_node,
21949                                 V4SI_type_node,
21950                                 V4SI_type_node,
21951                                 NULL_TREE);
21952
21953   tree v4si_ftype_v4si_v4si_v2di
21954     = build_function_type_list (V4SI_type_node,
21955                                 V4SI_type_node,
21956                                 V4SI_type_node,
21957                                 V2DI_type_node,
21958                                 NULL_TREE);
21959
21960   tree v8hi_ftype_v8hi_v8hi_v8hi
21961     = build_function_type_list (V8HI_type_node,
21962                                 V8HI_type_node,
21963                                 V8HI_type_node,
21964                                 V8HI_type_node,
21965                                 NULL_TREE);
21966
21967   tree v8hi_ftype_v8hi_v8hi_v4si
21968     = build_function_type_list (V8HI_type_node,
21969                                 V8HI_type_node,
21970                                 V8HI_type_node,
21971                                 V4SI_type_node,
21972                                 NULL_TREE);
21973
21974   tree v2df_ftype_v2df_v2df_v16qi
21975     = build_function_type_list (V2DF_type_node,
21976                                 V2DF_type_node,
21977                                 V2DF_type_node,
21978                                 V16QI_type_node,
21979                                 NULL_TREE);
21980
21981   tree v4sf_ftype_v4sf_v4sf_v16qi
21982     = build_function_type_list (V4SF_type_node,
21983                                 V4SF_type_node,
21984                                 V4SF_type_node,
21985                                 V16QI_type_node,
21986                                 NULL_TREE);
21987
21988   tree v2di_ftype_v2di_si
21989     = build_function_type_list (V2DI_type_node,
21990                                 V2DI_type_node,
21991                                 integer_type_node,
21992                                 NULL_TREE);
21993
21994   tree v4si_ftype_v4si_si
21995     = build_function_type_list (V4SI_type_node,
21996                                 V4SI_type_node,
21997                                 integer_type_node,
21998                                 NULL_TREE);
21999
22000   tree v8hi_ftype_v8hi_si
22001     = build_function_type_list (V8HI_type_node,
22002                                 V8HI_type_node,
22003                                 integer_type_node,
22004                                 NULL_TREE);
22005
22006   tree v16qi_ftype_v16qi_si
22007     = build_function_type_list (V16QI_type_node,
22008                                 V16QI_type_node,
22009                                 integer_type_node,
22010                                 NULL_TREE);
22011   tree v4sf_ftype_v4hi
22012     = build_function_type_list (V4SF_type_node,
22013                                 V4HI_type_node,
22014                                 NULL_TREE);
22015
22016   tree v4hi_ftype_v4sf
22017     = build_function_type_list (V4HI_type_node,
22018                                 V4SF_type_node,
22019                                 NULL_TREE);
22020
22021   tree v2di_ftype_v2di
22022     = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
22023
22024   tree v16qi_ftype_v8hi_v8hi
22025     = build_function_type_list (V16QI_type_node,
22026                                 V8HI_type_node, V8HI_type_node,
22027                                 NULL_TREE);
22028   tree v8hi_ftype_v4si_v4si
22029     = build_function_type_list (V8HI_type_node,
22030                                 V4SI_type_node, V4SI_type_node,
22031                                 NULL_TREE);
22032   tree v8hi_ftype_v16qi_v16qi 
22033     = build_function_type_list (V8HI_type_node,
22034                                 V16QI_type_node, V16QI_type_node,
22035                                 NULL_TREE);
22036   tree v4hi_ftype_v8qi_v8qi 
22037     = build_function_type_list (V4HI_type_node,
22038                                 V8QI_type_node, V8QI_type_node,
22039                                 NULL_TREE);
22040   tree unsigned_ftype_unsigned_uchar
22041     = build_function_type_list (unsigned_type_node,
22042                                 unsigned_type_node,
22043                                 unsigned_char_type_node,
22044                                 NULL_TREE);
22045   tree unsigned_ftype_unsigned_ushort
22046     = build_function_type_list (unsigned_type_node,
22047                                 unsigned_type_node,
22048                                 short_unsigned_type_node,
22049                                 NULL_TREE);
22050   tree unsigned_ftype_unsigned_unsigned
22051     = build_function_type_list (unsigned_type_node,
22052                                 unsigned_type_node,
22053                                 unsigned_type_node,
22054                                 NULL_TREE);
22055   tree uint64_ftype_uint64_uint64
22056     = build_function_type_list (long_long_unsigned_type_node,
22057                                 long_long_unsigned_type_node,
22058                                 long_long_unsigned_type_node,
22059                                 NULL_TREE);
22060   tree float_ftype_float
22061     = build_function_type_list (float_type_node,
22062                                 float_type_node,
22063                                 NULL_TREE);
22064
22065   /* AVX builtins  */
22066   tree V32QI_type_node = build_vector_type_for_mode (char_type_node,
22067                                                      V32QImode);
22068   tree V8SI_type_node = build_vector_type_for_mode (intSI_type_node,
22069                                                     V8SImode);
22070   tree V8SF_type_node = build_vector_type_for_mode (float_type_node,
22071                                                     V8SFmode);
22072   tree V4DI_type_node = build_vector_type_for_mode (long_long_integer_type_node,
22073                                                     V4DImode);
22074   tree V4DF_type_node = build_vector_type_for_mode (double_type_node,
22075                                                     V4DFmode);
22076   tree v8sf_ftype_v8sf
22077     = build_function_type_list (V8SF_type_node,
22078                                 V8SF_type_node,
22079                                 NULL_TREE);
22080   tree v8si_ftype_v8sf
22081     = build_function_type_list (V8SI_type_node,
22082                                 V8SF_type_node,
22083                                 NULL_TREE);
22084   tree v8sf_ftype_v8si
22085     = build_function_type_list (V8SF_type_node,
22086                                 V8SI_type_node,
22087                                 NULL_TREE);
22088   tree v4si_ftype_v4df
22089     = build_function_type_list (V4SI_type_node,
22090                                 V4DF_type_node,
22091                                 NULL_TREE);
22092   tree v4df_ftype_v4df
22093     = build_function_type_list (V4DF_type_node,
22094                                 V4DF_type_node,
22095                                 NULL_TREE);
22096   tree v4df_ftype_v4si
22097     = build_function_type_list (V4DF_type_node,
22098                                 V4SI_type_node,
22099                                 NULL_TREE);
22100   tree v4df_ftype_v4sf
22101     = build_function_type_list (V4DF_type_node,
22102                                 V4SF_type_node,
22103                                 NULL_TREE);
22104   tree v4sf_ftype_v4df
22105     = build_function_type_list (V4SF_type_node,
22106                                 V4DF_type_node,
22107                                 NULL_TREE);
22108   tree v8sf_ftype_v8sf_v8sf
22109     = build_function_type_list (V8SF_type_node,
22110                                 V8SF_type_node, V8SF_type_node,
22111                                 NULL_TREE);
22112   tree v4df_ftype_v4df_v4df
22113     = build_function_type_list (V4DF_type_node,
22114                                 V4DF_type_node, V4DF_type_node,
22115                                 NULL_TREE);
22116   tree v8sf_ftype_v8sf_int
22117     = build_function_type_list (V8SF_type_node,
22118                                 V8SF_type_node, integer_type_node,
22119                                 NULL_TREE);
22120   tree v4si_ftype_v8si_int
22121     = build_function_type_list (V4SI_type_node,
22122                                 V8SI_type_node, integer_type_node,
22123                                 NULL_TREE);
22124   tree v4df_ftype_v4df_int
22125     = build_function_type_list (V4DF_type_node,
22126                                 V4DF_type_node, integer_type_node,
22127                                 NULL_TREE);
22128   tree v4sf_ftype_v8sf_int
22129     = build_function_type_list (V4SF_type_node,
22130                                 V8SF_type_node, integer_type_node,
22131                                 NULL_TREE);
22132   tree v2df_ftype_v4df_int
22133     = build_function_type_list (V2DF_type_node,
22134                                 V4DF_type_node, integer_type_node,
22135                                 NULL_TREE);
22136   tree v8sf_ftype_v8sf_v8sf_int
22137     = build_function_type_list (V8SF_type_node,
22138                                 V8SF_type_node, V8SF_type_node,
22139                                 integer_type_node,
22140                                 NULL_TREE);
22141   tree v8sf_ftype_v8sf_v8sf_v8sf
22142     = build_function_type_list (V8SF_type_node,
22143                                 V8SF_type_node, V8SF_type_node,
22144                                 V8SF_type_node,
22145                                 NULL_TREE);
22146   tree v4df_ftype_v4df_v4df_v4df
22147     = build_function_type_list (V4DF_type_node,
22148                                 V4DF_type_node, V4DF_type_node,
22149                                 V4DF_type_node,
22150                                 NULL_TREE);
22151   tree v8si_ftype_v8si_v8si_int
22152     = build_function_type_list (V8SI_type_node,
22153                                 V8SI_type_node, V8SI_type_node,
22154                                 integer_type_node,
22155                                 NULL_TREE);
22156   tree v4df_ftype_v4df_v4df_int
22157     = build_function_type_list (V4DF_type_node,
22158                                 V4DF_type_node, V4DF_type_node,
22159                                 integer_type_node,
22160                                 NULL_TREE);
22161   tree v8sf_ftype_pcfloat
22162     = build_function_type_list (V8SF_type_node,
22163                                 pcfloat_type_node,
22164                                 NULL_TREE);
22165   tree v4df_ftype_pcdouble
22166     = build_function_type_list (V4DF_type_node,
22167                                 pcdouble_type_node,
22168                                 NULL_TREE);
22169   tree pcv4sf_type_node
22170     = build_pointer_type (build_type_variant (V4SF_type_node, 1, 0));
22171   tree pcv2df_type_node
22172     = build_pointer_type (build_type_variant (V2DF_type_node, 1, 0));
22173   tree v8sf_ftype_pcv4sf
22174     = build_function_type_list (V8SF_type_node,
22175                                 pcv4sf_type_node,
22176                                 NULL_TREE);
22177   tree v4df_ftype_pcv2df
22178     = build_function_type_list (V4DF_type_node,
22179                                 pcv2df_type_node,
22180                                 NULL_TREE);
22181   tree v32qi_ftype_pcchar
22182     = build_function_type_list (V32QI_type_node,
22183                                 pcchar_type_node,
22184                                 NULL_TREE);
22185   tree void_ftype_pchar_v32qi
22186     = build_function_type_list (void_type_node,
22187                                 pchar_type_node, V32QI_type_node,
22188                                 NULL_TREE);
22189   tree v8si_ftype_v8si_v4si_int
22190     = build_function_type_list (V8SI_type_node,
22191                                 V8SI_type_node, V4SI_type_node,
22192                                 integer_type_node,
22193                                 NULL_TREE);
22194   tree pv4di_type_node = build_pointer_type (V4DI_type_node);
22195   tree void_ftype_pv4di_v4di
22196     = build_function_type_list (void_type_node,
22197                                 pv4di_type_node, V4DI_type_node,
22198                                 NULL_TREE);
22199   tree v8sf_ftype_v8sf_v4sf_int
22200     = build_function_type_list (V8SF_type_node,
22201                                 V8SF_type_node, V4SF_type_node,
22202                                 integer_type_node,
22203                                 NULL_TREE);
22204   tree v4df_ftype_v4df_v2df_int
22205     = build_function_type_list (V4DF_type_node,
22206                                 V4DF_type_node, V2DF_type_node,
22207                                 integer_type_node,
22208                                 NULL_TREE);
22209   tree void_ftype_pfloat_v8sf
22210     = build_function_type_list (void_type_node,
22211                                 pfloat_type_node, V8SF_type_node,
22212                                 NULL_TREE);
22213   tree void_ftype_pdouble_v4df
22214     = build_function_type_list (void_type_node,
22215                                 pdouble_type_node, V4DF_type_node,
22216                                 NULL_TREE);
22217   tree pv8sf_type_node = build_pointer_type (V8SF_type_node);
22218   tree pv4sf_type_node = build_pointer_type (V4SF_type_node);
22219   tree pv4df_type_node = build_pointer_type (V4DF_type_node);
22220   tree pv2df_type_node = build_pointer_type (V2DF_type_node);
22221   tree pcv8sf_type_node
22222     = build_pointer_type (build_type_variant (V8SF_type_node, 1, 0));
22223   tree pcv4df_type_node
22224     = build_pointer_type (build_type_variant (V4DF_type_node, 1, 0));
22225   tree v8sf_ftype_pcv8sf_v8sf
22226     = build_function_type_list (V8SF_type_node,
22227                                 pcv8sf_type_node, V8SF_type_node,
22228                                 NULL_TREE);
22229   tree v4df_ftype_pcv4df_v4df
22230     = build_function_type_list (V4DF_type_node,
22231                                 pcv4df_type_node, V4DF_type_node,
22232                                 NULL_TREE);
22233   tree v4sf_ftype_pcv4sf_v4sf
22234     = build_function_type_list (V4SF_type_node,
22235                                 pcv4sf_type_node, V4SF_type_node,
22236                                 NULL_TREE);
22237   tree v2df_ftype_pcv2df_v2df
22238     = build_function_type_list (V2DF_type_node,
22239                                 pcv2df_type_node, V2DF_type_node,
22240                                 NULL_TREE);
22241   tree void_ftype_pv8sf_v8sf_v8sf
22242     = build_function_type_list (void_type_node,
22243                                 pv8sf_type_node, V8SF_type_node,
22244                                 V8SF_type_node,
22245                                 NULL_TREE);
22246   tree void_ftype_pv4df_v4df_v4df
22247     = build_function_type_list (void_type_node,
22248                                 pv4df_type_node, V4DF_type_node,
22249                                 V4DF_type_node,
22250                                 NULL_TREE);
22251   tree void_ftype_pv4sf_v4sf_v4sf
22252     = build_function_type_list (void_type_node,
22253                                 pv4sf_type_node, V4SF_type_node,
22254                                 V4SF_type_node,
22255                                 NULL_TREE);
22256   tree void_ftype_pv2df_v2df_v2df
22257     = build_function_type_list (void_type_node,
22258                                 pv2df_type_node, V2DF_type_node,
22259                                 V2DF_type_node,
22260                                 NULL_TREE);
22261   tree v4df_ftype_v2df
22262     = build_function_type_list (V4DF_type_node,
22263                                 V2DF_type_node,
22264                                 NULL_TREE);
22265   tree v8sf_ftype_v4sf
22266     = build_function_type_list (V8SF_type_node,
22267                                 V4SF_type_node,
22268                                 NULL_TREE);
22269   tree v8si_ftype_v4si
22270     = build_function_type_list (V8SI_type_node,
22271                                 V4SI_type_node,
22272                                 NULL_TREE);
22273   tree v2df_ftype_v4df
22274     = build_function_type_list (V2DF_type_node,
22275                                 V4DF_type_node,
22276                                 NULL_TREE);
22277   tree v4sf_ftype_v8sf
22278     = build_function_type_list (V4SF_type_node,
22279                                 V8SF_type_node,
22280                                 NULL_TREE);
22281   tree v4si_ftype_v8si
22282     = build_function_type_list (V4SI_type_node,
22283                                 V8SI_type_node,
22284                                 NULL_TREE);
22285   tree int_ftype_v4df
22286     = build_function_type_list (integer_type_node,
22287                                 V4DF_type_node,
22288                                 NULL_TREE);
22289   tree int_ftype_v8sf
22290     = build_function_type_list (integer_type_node,
22291                                 V8SF_type_node,
22292                                 NULL_TREE);
22293   tree int_ftype_v8sf_v8sf
22294     = build_function_type_list (integer_type_node,
22295                                 V8SF_type_node, V8SF_type_node,
22296                                 NULL_TREE);
22297   tree int_ftype_v4di_v4di
22298     = build_function_type_list (integer_type_node,
22299                                 V4DI_type_node, V4DI_type_node,
22300                                 NULL_TREE);
22301   tree int_ftype_v4df_v4df
22302     = build_function_type_list (integer_type_node,
22303                                 V4DF_type_node, V4DF_type_node,
22304                                 NULL_TREE);
22305   tree v8sf_ftype_v8sf_v8si
22306     = build_function_type_list (V8SF_type_node,
22307                                 V8SF_type_node, V8SI_type_node,
22308                                 NULL_TREE);
22309   tree v4df_ftype_v4df_v4di
22310     = build_function_type_list (V4DF_type_node,
22311                                 V4DF_type_node, V4DI_type_node,
22312                                 NULL_TREE);
22313   tree v4sf_ftype_v4sf_v4si
22314     = build_function_type_list (V4SF_type_node,
22315                                 V4SF_type_node, V4SI_type_node, NULL_TREE);
22316   tree v2df_ftype_v2df_v2di
22317     = build_function_type_list (V2DF_type_node,
22318                                 V2DF_type_node, V2DI_type_node, NULL_TREE);
22319
22320   tree ftype;
22321
22322   /* Add all special builtins with variable number of operands.  */
22323   for (i = 0, d = bdesc_special_args;
22324        i < ARRAY_SIZE (bdesc_special_args);
22325        i++, d++)
22326     {
22327       tree type;
22328
22329       if (d->name == 0)
22330         continue;
22331
22332       switch ((enum ix86_special_builtin_type) d->flag)
22333         {
22334         case VOID_FTYPE_VOID:
22335           type = void_ftype_void;
22336           break;
22337         case V32QI_FTYPE_PCCHAR:
22338           type = v32qi_ftype_pcchar;
22339           break;
22340         case V16QI_FTYPE_PCCHAR:
22341           type = v16qi_ftype_pcchar;
22342           break;
22343         case V8SF_FTYPE_PCV4SF:
22344           type = v8sf_ftype_pcv4sf;
22345           break;
22346         case V8SF_FTYPE_PCFLOAT:
22347           type = v8sf_ftype_pcfloat;
22348           break;
22349         case V4DF_FTYPE_PCV2DF:
22350           type = v4df_ftype_pcv2df;
22351           break;
22352         case V4DF_FTYPE_PCDOUBLE:
22353           type = v4df_ftype_pcdouble;
22354           break;
22355         case V4SF_FTYPE_PCFLOAT:
22356           type = v4sf_ftype_pcfloat;
22357           break;
22358         case V2DI_FTYPE_PV2DI:
22359           type = v2di_ftype_pv2di;
22360           break;
22361         case V2DF_FTYPE_PCDOUBLE:
22362           type = v2df_ftype_pcdouble;
22363           break;
22364         case V8SF_FTYPE_PCV8SF_V8SF:
22365           type = v8sf_ftype_pcv8sf_v8sf;
22366           break;
22367         case V4DF_FTYPE_PCV4DF_V4DF:
22368           type = v4df_ftype_pcv4df_v4df;
22369           break;
22370         case V4SF_FTYPE_V4SF_PCV2SF:
22371           type = v4sf_ftype_v4sf_pcv2sf;
22372           break;
22373         case V4SF_FTYPE_PCV4SF_V4SF:
22374           type = v4sf_ftype_pcv4sf_v4sf;
22375           break;
22376         case V2DF_FTYPE_V2DF_PCDOUBLE:
22377           type = v2df_ftype_v2df_pcdouble;
22378           break;
22379         case V2DF_FTYPE_PCV2DF_V2DF:
22380           type = v2df_ftype_pcv2df_v2df;
22381           break;
22382         case VOID_FTYPE_PV2SF_V4SF:
22383           type = void_ftype_pv2sf_v4sf;
22384           break;
22385         case VOID_FTYPE_PV4DI_V4DI:
22386           type = void_ftype_pv4di_v4di;
22387           break;
22388         case VOID_FTYPE_PV2DI_V2DI:
22389           type = void_ftype_pv2di_v2di;
22390           break;
22391         case VOID_FTYPE_PCHAR_V32QI:
22392           type = void_ftype_pchar_v32qi;
22393           break;
22394         case VOID_FTYPE_PCHAR_V16QI:
22395           type = void_ftype_pchar_v16qi;
22396           break;
22397         case VOID_FTYPE_PFLOAT_V8SF:
22398           type = void_ftype_pfloat_v8sf;
22399           break;
22400         case VOID_FTYPE_PFLOAT_V4SF:
22401           type = void_ftype_pfloat_v4sf;
22402           break;
22403         case VOID_FTYPE_PDOUBLE_V4DF:
22404           type = void_ftype_pdouble_v4df;
22405           break;
22406         case VOID_FTYPE_PDOUBLE_V2DF:
22407           type = void_ftype_pdouble_v2df;
22408           break;
22409         case VOID_FTYPE_PDI_DI:
22410           type = void_ftype_pdi_di;
22411           break;
22412         case VOID_FTYPE_PINT_INT:
22413           type = void_ftype_pint_int;
22414           break;
22415         case VOID_FTYPE_PV8SF_V8SF_V8SF:
22416           type = void_ftype_pv8sf_v8sf_v8sf;
22417           break;
22418         case VOID_FTYPE_PV4DF_V4DF_V4DF:
22419           type = void_ftype_pv4df_v4df_v4df;
22420           break;
22421         case VOID_FTYPE_PV4SF_V4SF_V4SF:
22422           type = void_ftype_pv4sf_v4sf_v4sf;
22423           break;
22424         case VOID_FTYPE_PV2DF_V2DF_V2DF:
22425           type = void_ftype_pv2df_v2df_v2df;
22426           break;
22427         default:
22428           gcc_unreachable ();
22429         }
22430
22431       def_builtin (d->mask, d->name, type, d->code);
22432     }
22433
22434   /* Add all builtins with variable number of operands.  */
22435   for (i = 0, d = bdesc_args;
22436        i < ARRAY_SIZE (bdesc_args);
22437        i++, d++)
22438     {
22439       tree type;
22440
22441       if (d->name == 0)
22442         continue;
22443
22444       switch ((enum ix86_builtin_type) d->flag)
22445         {
22446         case FLOAT_FTYPE_FLOAT:
22447           type = float_ftype_float;
22448           break;
22449         case INT_FTYPE_V8SF_V8SF_PTEST:
22450           type = int_ftype_v8sf_v8sf;
22451           break;
22452         case INT_FTYPE_V4DI_V4DI_PTEST:
22453           type = int_ftype_v4di_v4di;
22454           break;
22455         case INT_FTYPE_V4DF_V4DF_PTEST:
22456           type = int_ftype_v4df_v4df;
22457           break;
22458         case INT_FTYPE_V4SF_V4SF_PTEST:
22459           type = int_ftype_v4sf_v4sf;
22460           break;
22461         case INT_FTYPE_V2DI_V2DI_PTEST:
22462           type = int_ftype_v2di_v2di;
22463           break;
22464         case INT_FTYPE_V2DF_V2DF_PTEST:
22465           type = int_ftype_v2df_v2df;
22466           break;
22467         case INT64_FTYPE_V4SF:
22468           type = int64_ftype_v4sf;
22469           break;
22470         case INT64_FTYPE_V2DF:
22471           type = int64_ftype_v2df;
22472           break;
22473         case INT_FTYPE_V16QI:
22474           type = int_ftype_v16qi;
22475           break;
22476         case INT_FTYPE_V8QI:
22477           type = int_ftype_v8qi;
22478           break;
22479         case INT_FTYPE_V8SF:
22480           type = int_ftype_v8sf;
22481           break;
22482         case INT_FTYPE_V4DF:
22483           type = int_ftype_v4df;
22484           break;
22485         case INT_FTYPE_V4SF:
22486           type = int_ftype_v4sf;
22487           break;
22488         case INT_FTYPE_V2DF:
22489           type = int_ftype_v2df;
22490           break;
22491         case V16QI_FTYPE_V16QI:
22492           type = v16qi_ftype_v16qi;
22493           break;
22494         case V8SI_FTYPE_V8SF:
22495           type = v8si_ftype_v8sf;
22496           break;
22497         case V8SI_FTYPE_V4SI:
22498           type = v8si_ftype_v4si;
22499           break;
22500         case V8HI_FTYPE_V8HI:
22501           type = v8hi_ftype_v8hi;
22502           break;
22503         case V8HI_FTYPE_V16QI:
22504           type = v8hi_ftype_v16qi;
22505           break;
22506         case V8QI_FTYPE_V8QI:
22507           type = v8qi_ftype_v8qi;
22508           break;
22509         case V8SF_FTYPE_V8SF:
22510           type = v8sf_ftype_v8sf;
22511           break;
22512         case V8SF_FTYPE_V8SI:
22513           type = v8sf_ftype_v8si;
22514           break;
22515         case V8SF_FTYPE_V4SF:
22516           type = v8sf_ftype_v4sf;
22517           break;
22518         case V4SI_FTYPE_V4DF:
22519           type = v4si_ftype_v4df;
22520           break;
22521         case V4SI_FTYPE_V4SI:
22522           type = v4si_ftype_v4si;
22523           break;
22524         case V4SI_FTYPE_V16QI:
22525           type = v4si_ftype_v16qi;
22526           break;
22527         case V4SI_FTYPE_V8SI:
22528           type = v4si_ftype_v8si;
22529           break;
22530         case V4SI_FTYPE_V8HI:
22531           type = v4si_ftype_v8hi;
22532           break;
22533         case V4SI_FTYPE_V4SF:
22534           type = v4si_ftype_v4sf;
22535           break;
22536         case V4SI_FTYPE_V2DF:
22537           type = v4si_ftype_v2df;
22538           break;
22539         case V4HI_FTYPE_V4HI:
22540           type = v4hi_ftype_v4hi;
22541           break;
22542         case V4DF_FTYPE_V4DF:
22543           type = v4df_ftype_v4df;
22544           break;
22545         case V4DF_FTYPE_V4SI:
22546           type = v4df_ftype_v4si;
22547           break;
22548         case V4DF_FTYPE_V4SF:
22549           type = v4df_ftype_v4sf;
22550           break;
22551         case V4DF_FTYPE_V2DF:
22552           type = v4df_ftype_v2df;
22553           break;
22554         case V4SF_FTYPE_V4SF:
22555         case V4SF_FTYPE_V4SF_VEC_MERGE:
22556           type = v4sf_ftype_v4sf;
22557           break;
22558         case V4SF_FTYPE_V8SF:
22559           type = v4sf_ftype_v8sf;
22560           break;
22561         case V4SF_FTYPE_V4SI:
22562           type = v4sf_ftype_v4si;
22563           break;
22564         case V4SF_FTYPE_V4DF:
22565           type = v4sf_ftype_v4df;
22566           break;
22567         case V4SF_FTYPE_V2DF:
22568           type = v4sf_ftype_v2df;
22569           break;
22570         case V2DI_FTYPE_V2DI:
22571           type = v2di_ftype_v2di;
22572           break;
22573         case V2DI_FTYPE_V16QI:
22574           type = v2di_ftype_v16qi;
22575           break;
22576         case V2DI_FTYPE_V8HI:
22577           type = v2di_ftype_v8hi;
22578           break;
22579         case V2DI_FTYPE_V4SI:
22580           type = v2di_ftype_v4si;
22581           break;
22582         case V2SI_FTYPE_V2SI:
22583           type = v2si_ftype_v2si;
22584           break;
22585         case V2SI_FTYPE_V4SF:
22586           type = v2si_ftype_v4sf;
22587           break;
22588         case V2SI_FTYPE_V2DF:
22589           type = v2si_ftype_v2df;
22590           break;
22591         case V2SI_FTYPE_V2SF:
22592           type = v2si_ftype_v2sf;
22593           break;
22594         case V2DF_FTYPE_V4DF:
22595           type = v2df_ftype_v4df;
22596           break;
22597         case V2DF_FTYPE_V4SF:
22598           type = v2df_ftype_v4sf;
22599           break;
22600         case V2DF_FTYPE_V2DF:
22601         case V2DF_FTYPE_V2DF_VEC_MERGE:
22602           type = v2df_ftype_v2df;
22603           break;
22604         case V2DF_FTYPE_V2SI:
22605           type = v2df_ftype_v2si;
22606           break;
22607         case V2DF_FTYPE_V4SI:
22608           type = v2df_ftype_v4si;
22609           break;
22610         case V2SF_FTYPE_V2SF:
22611           type = v2sf_ftype_v2sf;
22612           break;
22613         case V2SF_FTYPE_V2SI:
22614           type = v2sf_ftype_v2si;
22615           break;
22616         case V16QI_FTYPE_V16QI_V16QI:
22617           type = v16qi_ftype_v16qi_v16qi;
22618           break;
22619         case V16QI_FTYPE_V8HI_V8HI:
22620           type = v16qi_ftype_v8hi_v8hi;
22621           break;
22622         case V8QI_FTYPE_V8QI_V8QI:
22623           type = v8qi_ftype_v8qi_v8qi;
22624           break;
22625         case V8QI_FTYPE_V4HI_V4HI:
22626           type = v8qi_ftype_v4hi_v4hi;
22627           break;
22628         case V8HI_FTYPE_V8HI_V8HI:
22629         case V8HI_FTYPE_V8HI_V8HI_COUNT:
22630           type = v8hi_ftype_v8hi_v8hi;
22631           break;
22632         case V8HI_FTYPE_V16QI_V16QI:
22633           type = v8hi_ftype_v16qi_v16qi;
22634           break;
22635         case V8HI_FTYPE_V4SI_V4SI:
22636           type = v8hi_ftype_v4si_v4si;
22637           break;
22638         case V8HI_FTYPE_V8HI_SI_COUNT:
22639           type = v8hi_ftype_v8hi_int;
22640           break;
22641         case V8SF_FTYPE_V8SF_V8SF:
22642           type = v8sf_ftype_v8sf_v8sf;
22643           break;
22644         case V8SF_FTYPE_V8SF_V8SI:
22645           type = v8sf_ftype_v8sf_v8si;
22646           break;
22647         case V4SI_FTYPE_V4SI_V4SI:
22648         case V4SI_FTYPE_V4SI_V4SI_COUNT:
22649           type = v4si_ftype_v4si_v4si;
22650           break;
22651         case V4SI_FTYPE_V8HI_V8HI:
22652           type = v4si_ftype_v8hi_v8hi;
22653           break;
22654         case V4SI_FTYPE_V4SF_V4SF:
22655           type = v4si_ftype_v4sf_v4sf;
22656           break;
22657         case V4SI_FTYPE_V2DF_V2DF:
22658           type = v4si_ftype_v2df_v2df;
22659           break;
22660         case V4SI_FTYPE_V4SI_SI_COUNT:
22661           type = v4si_ftype_v4si_int;
22662           break;
22663         case V4HI_FTYPE_V4HI_V4HI:
22664         case V4HI_FTYPE_V4HI_V4HI_COUNT:
22665           type = v4hi_ftype_v4hi_v4hi;
22666           break;
22667         case V4HI_FTYPE_V8QI_V8QI:
22668           type = v4hi_ftype_v8qi_v8qi;
22669           break;
22670         case V4HI_FTYPE_V2SI_V2SI:
22671           type = v4hi_ftype_v2si_v2si;
22672           break;
22673         case V4HI_FTYPE_V4HI_SI_COUNT:
22674           type = v4hi_ftype_v4hi_int;
22675           break;
22676         case V4DF_FTYPE_V4DF_V4DF:
22677           type = v4df_ftype_v4df_v4df;
22678           break;
22679         case V4DF_FTYPE_V4DF_V4DI:
22680           type = v4df_ftype_v4df_v4di;
22681           break;
22682         case V4SF_FTYPE_V4SF_V4SF:
22683         case V4SF_FTYPE_V4SF_V4SF_SWAP:
22684           type = v4sf_ftype_v4sf_v4sf;
22685           break;
22686         case V4SF_FTYPE_V4SF_V4SI:
22687           type = v4sf_ftype_v4sf_v4si;
22688           break;
22689         case V4SF_FTYPE_V4SF_V2SI:
22690           type = v4sf_ftype_v4sf_v2si;
22691           break;
22692         case V4SF_FTYPE_V4SF_V2DF:
22693           type = v4sf_ftype_v4sf_v2df;
22694           break;
22695         case V4SF_FTYPE_V4SF_DI:
22696           type = v4sf_ftype_v4sf_int64;
22697           break;
22698         case V4SF_FTYPE_V4SF_SI:
22699           type = v4sf_ftype_v4sf_int;
22700           break;
22701         case V2DI_FTYPE_V2DI_V2DI:
22702         case V2DI_FTYPE_V2DI_V2DI_COUNT:
22703           type = v2di_ftype_v2di_v2di;
22704           break;
22705         case V2DI_FTYPE_V16QI_V16QI:
22706           type = v2di_ftype_v16qi_v16qi;
22707           break;
22708         case V2DI_FTYPE_V4SI_V4SI:
22709           type = v2di_ftype_v4si_v4si;
22710           break;
22711         case V2DI_FTYPE_V2DI_V16QI:
22712           type = v2di_ftype_v2di_v16qi;
22713           break;
22714         case V2DI_FTYPE_V2DF_V2DF:
22715           type = v2di_ftype_v2df_v2df;
22716           break;
22717         case V2DI_FTYPE_V2DI_SI_COUNT:
22718           type = v2di_ftype_v2di_int;
22719           break;
22720         case V2SI_FTYPE_V2SI_V2SI:
22721         case V2SI_FTYPE_V2SI_V2SI_COUNT:
22722           type = v2si_ftype_v2si_v2si;
22723           break;
22724         case V2SI_FTYPE_V4HI_V4HI:
22725           type = v2si_ftype_v4hi_v4hi;
22726           break;
22727         case V2SI_FTYPE_V2SF_V2SF:
22728           type = v2si_ftype_v2sf_v2sf;
22729           break;
22730         case V2SI_FTYPE_V2SI_SI_COUNT:
22731           type = v2si_ftype_v2si_int;
22732           break;
22733         case V2DF_FTYPE_V2DF_V2DF:
22734         case V2DF_FTYPE_V2DF_V2DF_SWAP:
22735           type = v2df_ftype_v2df_v2df;
22736           break;
22737         case V2DF_FTYPE_V2DF_V4SF:
22738           type = v2df_ftype_v2df_v4sf;
22739           break;
22740         case V2DF_FTYPE_V2DF_V2DI:
22741           type = v2df_ftype_v2df_v2di;
22742           break;
22743         case V2DF_FTYPE_V2DF_DI:
22744           type = v2df_ftype_v2df_int64;
22745           break;
22746         case V2DF_FTYPE_V2DF_SI:
22747           type = v2df_ftype_v2df_int;
22748           break;
22749         case V2SF_FTYPE_V2SF_V2SF:
22750           type = v2sf_ftype_v2sf_v2sf;
22751           break;
22752         case V1DI_FTYPE_V1DI_V1DI:
22753         case V1DI_FTYPE_V1DI_V1DI_COUNT:
22754           type = v1di_ftype_v1di_v1di;
22755           break;
22756         case V1DI_FTYPE_V8QI_V8QI:
22757           type = v1di_ftype_v8qi_v8qi;
22758           break;
22759         case V1DI_FTYPE_V2SI_V2SI:
22760           type = v1di_ftype_v2si_v2si;
22761           break;
22762         case V1DI_FTYPE_V1DI_SI_COUNT:
22763           type = v1di_ftype_v1di_int;
22764           break;
22765         case UINT64_FTYPE_UINT64_UINT64:
22766           type = uint64_ftype_uint64_uint64;
22767           break;
22768         case UINT_FTYPE_UINT_UINT:
22769           type = unsigned_ftype_unsigned_unsigned;
22770           break;
22771         case UINT_FTYPE_UINT_USHORT:
22772           type = unsigned_ftype_unsigned_ushort;
22773           break;
22774         case UINT_FTYPE_UINT_UCHAR:
22775           type = unsigned_ftype_unsigned_uchar;
22776           break;
22777         case V8HI_FTYPE_V8HI_INT:
22778           type = v8hi_ftype_v8hi_int;
22779           break;
22780         case V8SF_FTYPE_V8SF_INT:
22781           type = v8sf_ftype_v8sf_int;
22782           break;
22783         case V4SI_FTYPE_V4SI_INT:
22784           type = v4si_ftype_v4si_int;
22785           break;
22786         case V4SI_FTYPE_V8SI_INT:
22787           type = v4si_ftype_v8si_int;
22788           break;
22789         case V4HI_FTYPE_V4HI_INT:
22790           type = v4hi_ftype_v4hi_int;
22791           break;
22792         case V4DF_FTYPE_V4DF_INT:
22793           type = v4df_ftype_v4df_int;
22794           break;
22795         case V4SF_FTYPE_V4SF_INT:
22796           type = v4sf_ftype_v4sf_int;
22797           break;
22798         case V4SF_FTYPE_V8SF_INT:
22799           type = v4sf_ftype_v8sf_int;
22800           break;
22801         case V2DI_FTYPE_V2DI_INT:
22802         case V2DI2TI_FTYPE_V2DI_INT:
22803           type = v2di_ftype_v2di_int;
22804           break;
22805         case V2DF_FTYPE_V2DF_INT:
22806           type = v2df_ftype_v2df_int;
22807           break;
22808         case V2DF_FTYPE_V4DF_INT:
22809           type = v2df_ftype_v4df_int;
22810           break;
22811         case V16QI_FTYPE_V16QI_V16QI_V16QI:
22812           type = v16qi_ftype_v16qi_v16qi_v16qi;
22813           break;
22814         case V8SF_FTYPE_V8SF_V8SF_V8SF:
22815           type = v8sf_ftype_v8sf_v8sf_v8sf;
22816           break;
22817         case V4DF_FTYPE_V4DF_V4DF_V4DF:
22818           type = v4df_ftype_v4df_v4df_v4df;
22819           break;
22820         case V4SF_FTYPE_V4SF_V4SF_V4SF:
22821           type = v4sf_ftype_v4sf_v4sf_v4sf;
22822           break;
22823         case V2DF_FTYPE_V2DF_V2DF_V2DF:
22824           type = v2df_ftype_v2df_v2df_v2df;
22825           break;
22826         case V16QI_FTYPE_V16QI_V16QI_INT:
22827           type = v16qi_ftype_v16qi_v16qi_int;
22828           break;
22829         case V8SI_FTYPE_V8SI_V8SI_INT:
22830           type = v8si_ftype_v8si_v8si_int;
22831           break;
22832         case V8SI_FTYPE_V8SI_V4SI_INT:
22833           type = v8si_ftype_v8si_v4si_int;
22834           break;
22835         case V8HI_FTYPE_V8HI_V8HI_INT:
22836           type = v8hi_ftype_v8hi_v8hi_int;
22837           break;
22838         case V8SF_FTYPE_V8SF_V8SF_INT:
22839           type = v8sf_ftype_v8sf_v8sf_int;
22840           break;
22841         case V8SF_FTYPE_V8SF_V4SF_INT:
22842           type = v8sf_ftype_v8sf_v4sf_int;
22843           break;
22844         case V4SI_FTYPE_V4SI_V4SI_INT:
22845           type = v4si_ftype_v4si_v4si_int;
22846           break;
22847         case V4DF_FTYPE_V4DF_V4DF_INT:
22848           type = v4df_ftype_v4df_v4df_int;
22849           break;
22850         case V4DF_FTYPE_V4DF_V2DF_INT:
22851           type = v4df_ftype_v4df_v2df_int;
22852           break;
22853         case V4SF_FTYPE_V4SF_V4SF_INT:
22854           type = v4sf_ftype_v4sf_v4sf_int;
22855           break;
22856         case V2DI_FTYPE_V2DI_V2DI_INT:
22857         case V2DI2TI_FTYPE_V2DI_V2DI_INT:
22858           type = v2di_ftype_v2di_v2di_int;
22859           break;
22860         case V2DF_FTYPE_V2DF_V2DF_INT:
22861           type = v2df_ftype_v2df_v2df_int;
22862           break;
22863         case V2DI_FTYPE_V2DI_UINT_UINT:
22864           type = v2di_ftype_v2di_unsigned_unsigned;
22865           break;
22866         case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
22867           type = v2di_ftype_v2di_v2di_unsigned_unsigned;
22868           break;
22869         case V1DI2DI_FTYPE_V1DI_V1DI_INT:
22870           type = v1di_ftype_v1di_v1di_int;
22871           break;
22872         default:
22873           gcc_unreachable ();
22874         }
22875
22876       def_builtin_const (d->mask, d->name, type, d->code);
22877     }
22878
22879   /* pcmpestr[im] insns.  */
22880   for (i = 0, d = bdesc_pcmpestr;
22881        i < ARRAY_SIZE (bdesc_pcmpestr);
22882        i++, d++)
22883     {
22884       if (d->code == IX86_BUILTIN_PCMPESTRM128)
22885         ftype = v16qi_ftype_v16qi_int_v16qi_int_int;
22886       else
22887         ftype = int_ftype_v16qi_int_v16qi_int_int;
22888       def_builtin_const (d->mask, d->name, ftype, d->code);
22889     }
22890
22891   /* pcmpistr[im] insns.  */
22892   for (i = 0, d = bdesc_pcmpistr;
22893        i < ARRAY_SIZE (bdesc_pcmpistr);
22894        i++, d++)
22895     {
22896       if (d->code == IX86_BUILTIN_PCMPISTRM128)
22897         ftype = v16qi_ftype_v16qi_v16qi_int;
22898       else
22899         ftype = int_ftype_v16qi_v16qi_int;
22900       def_builtin_const (d->mask, d->name, ftype, d->code);
22901     }
22902
22903   /* comi/ucomi insns.  */
22904   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
22905     if (d->mask == OPTION_MASK_ISA_SSE2)
22906       def_builtin_const (d->mask, d->name, int_ftype_v2df_v2df, d->code);
22907     else
22908       def_builtin_const (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
22909
22910   /* SSE */
22911   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr", void_ftype_unsigned, IX86_BUILTIN_LDMXCSR);
22912   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr", unsigned_ftype_void, IX86_BUILTIN_STMXCSR);
22913
22914   /* SSE or 3DNow!A */
22915   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_maskmovq", void_ftype_v8qi_v8qi_pchar, IX86_BUILTIN_MASKMOVQ);
22916
22917   /* SSE2 */
22918   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu", void_ftype_v16qi_v16qi_pchar, IX86_BUILTIN_MASKMOVDQU);
22919
22920   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush", void_ftype_pcvoid, IX86_BUILTIN_CLFLUSH);
22921   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence", void_ftype_void, IX86_BUILTIN_MFENCE);
22922
22923   /* SSE3.  */
22924   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor", void_ftype_pcvoid_unsigned_unsigned, IX86_BUILTIN_MONITOR);
22925   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait", void_ftype_unsigned_unsigned, IX86_BUILTIN_MWAIT);
22926
22927   /* AES */
22928   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENC128);
22929   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENCLAST128);
22930   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDEC128);
22931   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDECLAST128);
22932   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128", v2di_ftype_v2di, IX86_BUILTIN_AESIMC128);
22933   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128", v2di_ftype_v2di_int, IX86_BUILTIN_AESKEYGENASSIST128);
22934
22935   /* PCLMUL */
22936   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128", v2di_ftype_v2di_v2di_int, IX86_BUILTIN_PCLMULQDQ128);
22937
22938   /* AVX */
22939   def_builtin (OPTION_MASK_ISA_AVX, "__builtin_ia32_vzeroupper", void_ftype_void,
22940                TARGET_64BIT ? IX86_BUILTIN_VZEROUPPER_REX64 : IX86_BUILTIN_VZEROUPPER);
22941
22942   /* Access to the vec_init patterns.  */
22943   ftype = build_function_type_list (V2SI_type_node, integer_type_node,
22944                                     integer_type_node, NULL_TREE);
22945   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si", ftype, IX86_BUILTIN_VEC_INIT_V2SI);
22946
22947   ftype = build_function_type_list (V4HI_type_node, short_integer_type_node,
22948                                     short_integer_type_node,
22949                                     short_integer_type_node,
22950                                     short_integer_type_node, NULL_TREE);
22951   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi", ftype, IX86_BUILTIN_VEC_INIT_V4HI);
22952
22953   ftype = build_function_type_list (V8QI_type_node, char_type_node,
22954                                     char_type_node, char_type_node,
22955                                     char_type_node, char_type_node,
22956                                     char_type_node, char_type_node,
22957                                     char_type_node, NULL_TREE);
22958   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi", ftype, IX86_BUILTIN_VEC_INIT_V8QI);
22959
22960   /* Access to the vec_extract patterns.  */
22961   ftype = build_function_type_list (double_type_node, V2DF_type_node,
22962                                     integer_type_node, NULL_TREE);
22963   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df", ftype, IX86_BUILTIN_VEC_EXT_V2DF);
22964
22965   ftype = build_function_type_list (long_long_integer_type_node,
22966                                     V2DI_type_node, integer_type_node,
22967                                     NULL_TREE);
22968   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di", ftype, IX86_BUILTIN_VEC_EXT_V2DI);
22969
22970   ftype = build_function_type_list (float_type_node, V4SF_type_node,
22971                                     integer_type_node, NULL_TREE);
22972   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf", ftype, IX86_BUILTIN_VEC_EXT_V4SF);
22973
22974   ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
22975                                     integer_type_node, NULL_TREE);
22976   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si", ftype, IX86_BUILTIN_VEC_EXT_V4SI);
22977
22978   ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
22979                                     integer_type_node, NULL_TREE);
22980   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi", ftype, IX86_BUILTIN_VEC_EXT_V8HI);
22981
22982   ftype = build_function_type_list (intHI_type_node, V4HI_type_node,
22983                                     integer_type_node, NULL_TREE);
22984   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_ext_v4hi", ftype, IX86_BUILTIN_VEC_EXT_V4HI);
22985
22986   ftype = build_function_type_list (intSI_type_node, V2SI_type_node,
22987                                     integer_type_node, NULL_TREE);
22988   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si", ftype, IX86_BUILTIN_VEC_EXT_V2SI);
22989
22990   ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
22991                                     integer_type_node, NULL_TREE);
22992   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi", ftype, IX86_BUILTIN_VEC_EXT_V16QI);
22993
22994   /* Access to the vec_set patterns.  */
22995   ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
22996                                     intDI_type_node,
22997                                     integer_type_node, NULL_TREE);
22998   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_vec_set_v2di", ftype, IX86_BUILTIN_VEC_SET_V2DI);
22999
23000   ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
23001                                     float_type_node,
23002                                     integer_type_node, NULL_TREE);
23003   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf", ftype, IX86_BUILTIN_VEC_SET_V4SF);
23004
23005   ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
23006                                     intSI_type_node,
23007                                     integer_type_node, NULL_TREE);
23008   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si", ftype, IX86_BUILTIN_VEC_SET_V4SI);
23009
23010   ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
23011                                     intHI_type_node,
23012                                     integer_type_node, NULL_TREE);
23013   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi", ftype, IX86_BUILTIN_VEC_SET_V8HI);
23014
23015   ftype = build_function_type_list (V4HI_type_node, V4HI_type_node,
23016                                     intHI_type_node,
23017                                     integer_type_node, NULL_TREE);
23018   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_set_v4hi", ftype, IX86_BUILTIN_VEC_SET_V4HI);
23019
23020   ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
23021                                     intQI_type_node,
23022                                     integer_type_node, NULL_TREE);
23023   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi", ftype, IX86_BUILTIN_VEC_SET_V16QI);
23024
23025   /* Add SSE5 multi-arg argument instructions */
23026   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
23027     {
23028       tree mtype = NULL_TREE;
23029
23030       if (d->name == 0)
23031         continue;
23032
23033       switch ((enum multi_arg_type)d->flag)
23034         {
23035         case MULTI_ARG_3_SF:     mtype = v4sf_ftype_v4sf_v4sf_v4sf;     break;
23036         case MULTI_ARG_3_DF:     mtype = v2df_ftype_v2df_v2df_v2df;     break;
23037         case MULTI_ARG_3_DI:     mtype = v2di_ftype_v2di_v2di_v2di;     break;
23038         case MULTI_ARG_3_SI:     mtype = v4si_ftype_v4si_v4si_v4si;     break;
23039         case MULTI_ARG_3_SI_DI:  mtype = v4si_ftype_v4si_v4si_v2di;     break;
23040         case MULTI_ARG_3_HI:     mtype = v8hi_ftype_v8hi_v8hi_v8hi;     break;
23041         case MULTI_ARG_3_HI_SI:  mtype = v8hi_ftype_v8hi_v8hi_v4si;     break;
23042         case MULTI_ARG_3_QI:     mtype = v16qi_ftype_v16qi_v16qi_v16qi; break;
23043         case MULTI_ARG_3_PERMPS: mtype = v4sf_ftype_v4sf_v4sf_v16qi;    break;
23044         case MULTI_ARG_3_PERMPD: mtype = v2df_ftype_v2df_v2df_v16qi;    break;
23045         case MULTI_ARG_2_SF:     mtype = v4sf_ftype_v4sf_v4sf;          break;
23046         case MULTI_ARG_2_DF:     mtype = v2df_ftype_v2df_v2df;          break;
23047         case MULTI_ARG_2_DI:     mtype = v2di_ftype_v2di_v2di;          break;
23048         case MULTI_ARG_2_SI:     mtype = v4si_ftype_v4si_v4si;          break;
23049         case MULTI_ARG_2_HI:     mtype = v8hi_ftype_v8hi_v8hi;          break;
23050         case MULTI_ARG_2_QI:     mtype = v16qi_ftype_v16qi_v16qi;       break;
23051         case MULTI_ARG_2_DI_IMM: mtype = v2di_ftype_v2di_si;            break;
23052         case MULTI_ARG_2_SI_IMM: mtype = v4si_ftype_v4si_si;            break;
23053         case MULTI_ARG_2_HI_IMM: mtype = v8hi_ftype_v8hi_si;            break;
23054         case MULTI_ARG_2_QI_IMM: mtype = v16qi_ftype_v16qi_si;          break;
23055         case MULTI_ARG_2_SF_CMP: mtype = v4sf_ftype_v4sf_v4sf;          break;
23056         case MULTI_ARG_2_DF_CMP: mtype = v2df_ftype_v2df_v2df;          break;
23057         case MULTI_ARG_2_DI_CMP: mtype = v2di_ftype_v2di_v2di;          break;
23058         case MULTI_ARG_2_SI_CMP: mtype = v4si_ftype_v4si_v4si;          break;
23059         case MULTI_ARG_2_HI_CMP: mtype = v8hi_ftype_v8hi_v8hi;          break;
23060         case MULTI_ARG_2_QI_CMP: mtype = v16qi_ftype_v16qi_v16qi;       break;
23061         case MULTI_ARG_2_SF_TF:  mtype = v4sf_ftype_v4sf_v4sf;          break;
23062         case MULTI_ARG_2_DF_TF:  mtype = v2df_ftype_v2df_v2df;          break;
23063         case MULTI_ARG_2_DI_TF:  mtype = v2di_ftype_v2di_v2di;          break;
23064         case MULTI_ARG_2_SI_TF:  mtype = v4si_ftype_v4si_v4si;          break;
23065         case MULTI_ARG_2_HI_TF:  mtype = v8hi_ftype_v8hi_v8hi;          break;
23066         case MULTI_ARG_2_QI_TF:  mtype = v16qi_ftype_v16qi_v16qi;       break;
23067         case MULTI_ARG_1_SF:     mtype = v4sf_ftype_v4sf;               break;
23068         case MULTI_ARG_1_DF:     mtype = v2df_ftype_v2df;               break;
23069         case MULTI_ARG_1_DI:     mtype = v2di_ftype_v2di;               break;
23070         case MULTI_ARG_1_SI:     mtype = v4si_ftype_v4si;               break;
23071         case MULTI_ARG_1_HI:     mtype = v8hi_ftype_v8hi;               break;
23072         case MULTI_ARG_1_QI:     mtype = v16qi_ftype_v16qi;             break;
23073         case MULTI_ARG_1_SI_DI:  mtype = v2di_ftype_v4si;               break;
23074         case MULTI_ARG_1_HI_DI:  mtype = v2di_ftype_v8hi;               break;
23075         case MULTI_ARG_1_HI_SI:  mtype = v4si_ftype_v8hi;               break;
23076         case MULTI_ARG_1_QI_DI:  mtype = v2di_ftype_v16qi;              break;
23077         case MULTI_ARG_1_QI_SI:  mtype = v4si_ftype_v16qi;              break;
23078         case MULTI_ARG_1_QI_HI:  mtype = v8hi_ftype_v16qi;              break;
23079         case MULTI_ARG_1_PH2PS:  mtype = v4sf_ftype_v4hi;               break;
23080         case MULTI_ARG_1_PS2PH:  mtype = v4hi_ftype_v4sf;               break;
23081         case MULTI_ARG_UNKNOWN:
23082         default:
23083           gcc_unreachable ();
23084         }
23085
23086       if (mtype)
23087         def_builtin_const (d->mask, d->name, mtype, d->code);
23088     }
23089 }
23090
23091 /* Internal method for ix86_init_builtins.  */
23092
23093 static void
23094 ix86_init_builtins_va_builtins_abi (void)
23095 {
23096   tree ms_va_ref, sysv_va_ref;
23097   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
23098   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
23099   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
23100   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
23101
23102   if (!TARGET_64BIT)
23103     return;
23104   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
23105   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
23106   ms_va_ref = build_reference_type (ms_va_list_type_node);
23107   sysv_va_ref =
23108     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
23109
23110   fnvoid_va_end_ms =
23111     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
23112   fnvoid_va_start_ms =
23113     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
23114   fnvoid_va_end_sysv =
23115     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
23116   fnvoid_va_start_sysv =
23117     build_varargs_function_type_list (void_type_node, sysv_va_ref,
23118                                        NULL_TREE);
23119   fnvoid_va_copy_ms =
23120     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
23121                               NULL_TREE);
23122   fnvoid_va_copy_sysv =
23123     build_function_type_list (void_type_node, sysv_va_ref,
23124                               sysv_va_ref, NULL_TREE);
23125
23126   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
23127                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
23128   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
23129                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
23130   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
23131                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
23132   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
23133                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23134   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
23135                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23136   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
23137                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23138 }
23139
23140 static void
23141 ix86_init_builtins (void)
23142 {
23143   tree float128_type_node = make_node (REAL_TYPE);
23144   tree ftype, decl;
23145
23146   /* The __float80 type.  */
23147   if (TYPE_MODE (long_double_type_node) == XFmode)
23148     (*lang_hooks.types.register_builtin_type) (long_double_type_node,
23149                                                "__float80");
23150   else
23151     {
23152       /* The __float80 type.  */
23153       tree float80_type_node = make_node (REAL_TYPE);
23154
23155       TYPE_PRECISION (float80_type_node) = 80;
23156       layout_type (float80_type_node);
23157       (*lang_hooks.types.register_builtin_type) (float80_type_node,
23158                                                  "__float80");
23159     }
23160
23161   /* The __float128 type.  */
23162   TYPE_PRECISION (float128_type_node) = 128;
23163   layout_type (float128_type_node);
23164   (*lang_hooks.types.register_builtin_type) (float128_type_node,
23165                                              "__float128");
23166
23167   /* TFmode support builtins.  */
23168   ftype = build_function_type (float128_type_node, void_list_node);
23169   decl = add_builtin_function ("__builtin_infq", ftype,
23170                                IX86_BUILTIN_INFQ, BUILT_IN_MD,
23171                                NULL, NULL_TREE);
23172   ix86_builtins[(int) IX86_BUILTIN_INFQ] = decl;
23173
23174   /* We will expand them to normal call if SSE2 isn't available since
23175      they are used by libgcc. */
23176   ftype = build_function_type_list (float128_type_node,
23177                                     float128_type_node,
23178                                     NULL_TREE);
23179   decl = add_builtin_function ("__builtin_fabsq", ftype,
23180                                IX86_BUILTIN_FABSQ, BUILT_IN_MD,
23181                                "__fabstf2", NULL_TREE);
23182   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = decl;
23183   TREE_READONLY (decl) = 1;
23184
23185   ftype = build_function_type_list (float128_type_node,
23186                                     float128_type_node,
23187                                     float128_type_node,
23188                                     NULL_TREE);
23189   decl = add_builtin_function ("__builtin_copysignq", ftype,
23190                                IX86_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
23191                                "__copysigntf3", NULL_TREE);
23192   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = decl;
23193   TREE_READONLY (decl) = 1;
23194
23195   ix86_init_mmx_sse_builtins ();
23196   if (TARGET_64BIT)
23197     ix86_init_builtins_va_builtins_abi ();
23198 }
23199
23200 /* Errors in the source file can cause expand_expr to return const0_rtx
23201    where we expect a vector.  To avoid crashing, use one of the vector
23202    clear instructions.  */
23203 static rtx
23204 safe_vector_operand (rtx x, enum machine_mode mode)
23205 {
23206   if (x == const0_rtx)
23207     x = CONST0_RTX (mode);
23208   return x;
23209 }
23210
23211 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
23212
23213 static rtx
23214 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
23215 {
23216   rtx pat;
23217   tree arg0 = CALL_EXPR_ARG (exp, 0);
23218   tree arg1 = CALL_EXPR_ARG (exp, 1);
23219   rtx op0 = expand_normal (arg0);
23220   rtx op1 = expand_normal (arg1);
23221   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23222   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
23223   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
23224
23225   if (VECTOR_MODE_P (mode0))
23226     op0 = safe_vector_operand (op0, mode0);
23227   if (VECTOR_MODE_P (mode1))
23228     op1 = safe_vector_operand (op1, mode1);
23229
23230   if (optimize || !target
23231       || GET_MODE (target) != tmode
23232       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23233     target = gen_reg_rtx (tmode);
23234
23235   if (GET_MODE (op1) == SImode && mode1 == TImode)
23236     {
23237       rtx x = gen_reg_rtx (V4SImode);
23238       emit_insn (gen_sse2_loadd (x, op1));
23239       op1 = gen_lowpart (TImode, x);
23240     }
23241
23242   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
23243     op0 = copy_to_mode_reg (mode0, op0);
23244   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
23245     op1 = copy_to_mode_reg (mode1, op1);
23246
23247   pat = GEN_FCN (icode) (target, op0, op1);
23248   if (! pat)
23249     return 0;
23250
23251   emit_insn (pat);
23252
23253   return target;
23254 }
23255
23256 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
23257
23258 static rtx
23259 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
23260                                enum multi_arg_type m_type,
23261                                enum insn_code sub_code)
23262 {
23263   rtx pat;
23264   int i;
23265   int nargs;
23266   bool comparison_p = false;
23267   bool tf_p = false;
23268   bool last_arg_constant = false;
23269   int num_memory = 0;
23270   struct {
23271     rtx op;
23272     enum machine_mode mode;
23273   } args[4];
23274
23275   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23276
23277   switch (m_type)
23278     {
23279     case MULTI_ARG_3_SF:
23280     case MULTI_ARG_3_DF:
23281     case MULTI_ARG_3_DI:
23282     case MULTI_ARG_3_SI:
23283     case MULTI_ARG_3_SI_DI:
23284     case MULTI_ARG_3_HI:
23285     case MULTI_ARG_3_HI_SI:
23286     case MULTI_ARG_3_QI:
23287     case MULTI_ARG_3_PERMPS:
23288     case MULTI_ARG_3_PERMPD:
23289       nargs = 3;
23290       break;
23291
23292     case MULTI_ARG_2_SF:
23293     case MULTI_ARG_2_DF:
23294     case MULTI_ARG_2_DI:
23295     case MULTI_ARG_2_SI:
23296     case MULTI_ARG_2_HI:
23297     case MULTI_ARG_2_QI:
23298       nargs = 2;
23299       break;
23300
23301     case MULTI_ARG_2_DI_IMM:
23302     case MULTI_ARG_2_SI_IMM:
23303     case MULTI_ARG_2_HI_IMM:
23304     case MULTI_ARG_2_QI_IMM:
23305       nargs = 2;
23306       last_arg_constant = true;
23307       break;
23308
23309     case MULTI_ARG_1_SF:
23310     case MULTI_ARG_1_DF:
23311     case MULTI_ARG_1_DI:
23312     case MULTI_ARG_1_SI:
23313     case MULTI_ARG_1_HI:
23314     case MULTI_ARG_1_QI:
23315     case MULTI_ARG_1_SI_DI:
23316     case MULTI_ARG_1_HI_DI:
23317     case MULTI_ARG_1_HI_SI:
23318     case MULTI_ARG_1_QI_DI:
23319     case MULTI_ARG_1_QI_SI:
23320     case MULTI_ARG_1_QI_HI:
23321     case MULTI_ARG_1_PH2PS:
23322     case MULTI_ARG_1_PS2PH:
23323       nargs = 1;
23324       break;
23325
23326     case MULTI_ARG_2_SF_CMP:
23327     case MULTI_ARG_2_DF_CMP:
23328     case MULTI_ARG_2_DI_CMP:
23329     case MULTI_ARG_2_SI_CMP:
23330     case MULTI_ARG_2_HI_CMP:
23331     case MULTI_ARG_2_QI_CMP:
23332       nargs = 2;
23333       comparison_p = true;
23334       break;
23335
23336     case MULTI_ARG_2_SF_TF:
23337     case MULTI_ARG_2_DF_TF:
23338     case MULTI_ARG_2_DI_TF:
23339     case MULTI_ARG_2_SI_TF:
23340     case MULTI_ARG_2_HI_TF:
23341     case MULTI_ARG_2_QI_TF:
23342       nargs = 2;
23343       tf_p = true;
23344       break;
23345
23346     case MULTI_ARG_UNKNOWN:
23347     default:
23348       gcc_unreachable ();
23349     }
23350
23351   if (optimize || !target
23352       || GET_MODE (target) != tmode
23353       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23354     target = gen_reg_rtx (tmode);
23355
23356   gcc_assert (nargs <= 4);
23357
23358   for (i = 0; i < nargs; i++)
23359     {
23360       tree arg = CALL_EXPR_ARG (exp, i);
23361       rtx op = expand_normal (arg);
23362       int adjust = (comparison_p) ? 1 : 0;
23363       enum machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
23364
23365       if (last_arg_constant && i == nargs-1)
23366         {
23367           if (GET_CODE (op) != CONST_INT)
23368             {
23369               error ("last argument must be an immediate");
23370               return gen_reg_rtx (tmode);
23371             }
23372         }
23373       else
23374         {
23375           if (VECTOR_MODE_P (mode))
23376             op = safe_vector_operand (op, mode);
23377
23378           /* If we aren't optimizing, only allow one memory operand to be
23379              generated.  */
23380           if (memory_operand (op, mode))
23381             num_memory++;
23382
23383           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
23384
23385           if (optimize
23386               || ! (*insn_data[icode].operand[i+adjust+1].predicate) (op, mode)
23387               || num_memory > 1)
23388             op = force_reg (mode, op);
23389         }
23390
23391       args[i].op = op;
23392       args[i].mode = mode;
23393     }
23394
23395   switch (nargs)
23396     {
23397     case 1:
23398       pat = GEN_FCN (icode) (target, args[0].op);
23399       break;
23400
23401     case 2:
23402       if (tf_p)
23403         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
23404                                GEN_INT ((int)sub_code));
23405       else if (! comparison_p)
23406         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
23407       else
23408         {
23409           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
23410                                        args[0].op,
23411                                        args[1].op);
23412
23413           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
23414         }
23415       break;
23416
23417     case 3:
23418       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
23419       break;
23420
23421     default:
23422       gcc_unreachable ();
23423     }
23424
23425   if (! pat)
23426     return 0;
23427
23428   emit_insn (pat);
23429   return target;
23430 }
23431
23432 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
23433    insns with vec_merge.  */
23434
23435 static rtx
23436 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
23437                                     rtx target)
23438 {
23439   rtx pat;
23440   tree arg0 = CALL_EXPR_ARG (exp, 0);
23441   rtx op1, op0 = expand_normal (arg0);
23442   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23443   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
23444
23445   if (optimize || !target
23446       || GET_MODE (target) != tmode
23447       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23448     target = gen_reg_rtx (tmode);
23449
23450   if (VECTOR_MODE_P (mode0))
23451     op0 = safe_vector_operand (op0, mode0);
23452
23453   if ((optimize && !register_operand (op0, mode0))
23454       || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
23455     op0 = copy_to_mode_reg (mode0, op0);
23456
23457   op1 = op0;
23458   if (! (*insn_data[icode].operand[2].predicate) (op1, mode0))
23459     op1 = copy_to_mode_reg (mode0, op1);
23460
23461   pat = GEN_FCN (icode) (target, op0, op1);
23462   if (! pat)
23463     return 0;
23464   emit_insn (pat);
23465   return target;
23466 }
23467
23468 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
23469
23470 static rtx
23471 ix86_expand_sse_compare (const struct builtin_description *d,
23472                          tree exp, rtx target, bool swap)
23473 {
23474   rtx pat;
23475   tree arg0 = CALL_EXPR_ARG (exp, 0);
23476   tree arg1 = CALL_EXPR_ARG (exp, 1);
23477   rtx op0 = expand_normal (arg0);
23478   rtx op1 = expand_normal (arg1);
23479   rtx op2;
23480   enum machine_mode tmode = insn_data[d->icode].operand[0].mode;
23481   enum machine_mode mode0 = insn_data[d->icode].operand[1].mode;
23482   enum machine_mode mode1 = insn_data[d->icode].operand[2].mode;
23483   enum rtx_code comparison = d->comparison;
23484
23485   if (VECTOR_MODE_P (mode0))
23486     op0 = safe_vector_operand (op0, mode0);
23487   if (VECTOR_MODE_P (mode1))
23488     op1 = safe_vector_operand (op1, mode1);
23489
23490   /* Swap operands if we have a comparison that isn't available in
23491      hardware.  */
23492   if (swap)
23493     {
23494       rtx tmp = gen_reg_rtx (mode1);
23495       emit_move_insn (tmp, op1);
23496       op1 = op0;
23497       op0 = tmp;
23498     }
23499
23500   if (optimize || !target
23501       || GET_MODE (target) != tmode
23502       || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode))
23503     target = gen_reg_rtx (tmode);
23504
23505   if ((optimize && !register_operand (op0, mode0))
23506       || ! (*insn_data[d->icode].operand[1].predicate) (op0, mode0))
23507     op0 = copy_to_mode_reg (mode0, op0);
23508   if ((optimize && !register_operand (op1, mode1))
23509       || ! (*insn_data[d->icode].operand[2].predicate) (op1, mode1))
23510     op1 = copy_to_mode_reg (mode1, op1);
23511
23512   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
23513   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
23514   if (! pat)
23515     return 0;
23516   emit_insn (pat);
23517   return target;
23518 }
23519
23520 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
23521
23522 static rtx
23523 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
23524                       rtx target)
23525 {
23526   rtx pat;
23527   tree arg0 = CALL_EXPR_ARG (exp, 0);
23528   tree arg1 = CALL_EXPR_ARG (exp, 1);
23529   rtx op0 = expand_normal (arg0);
23530   rtx op1 = expand_normal (arg1);
23531   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23532   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23533   enum rtx_code comparison = d->comparison;
23534
23535   if (VECTOR_MODE_P (mode0))
23536     op0 = safe_vector_operand (op0, mode0);
23537   if (VECTOR_MODE_P (mode1))
23538     op1 = safe_vector_operand (op1, mode1);
23539
23540   /* Swap operands if we have a comparison that isn't available in
23541      hardware.  */
23542   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
23543     {
23544       rtx tmp = op1;
23545       op1 = op0;
23546       op0 = tmp;
23547     }
23548
23549   target = gen_reg_rtx (SImode);
23550   emit_move_insn (target, const0_rtx);
23551   target = gen_rtx_SUBREG (QImode, target, 0);
23552
23553   if ((optimize && !register_operand (op0, mode0))
23554       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23555     op0 = copy_to_mode_reg (mode0, op0);
23556   if ((optimize && !register_operand (op1, mode1))
23557       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23558     op1 = copy_to_mode_reg (mode1, op1);
23559
23560   pat = GEN_FCN (d->icode) (op0, op1);
23561   if (! pat)
23562     return 0;
23563   emit_insn (pat);
23564   emit_insn (gen_rtx_SET (VOIDmode,
23565                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23566                           gen_rtx_fmt_ee (comparison, QImode,
23567                                           SET_DEST (pat),
23568                                           const0_rtx)));
23569
23570   return SUBREG_REG (target);
23571 }
23572
23573 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
23574
23575 static rtx
23576 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
23577                        rtx target)
23578 {
23579   rtx pat;
23580   tree arg0 = CALL_EXPR_ARG (exp, 0);
23581   tree arg1 = CALL_EXPR_ARG (exp, 1);
23582   rtx op0 = expand_normal (arg0);
23583   rtx op1 = expand_normal (arg1);
23584   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23585   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23586   enum rtx_code comparison = d->comparison;
23587
23588   if (VECTOR_MODE_P (mode0))
23589     op0 = safe_vector_operand (op0, mode0);
23590   if (VECTOR_MODE_P (mode1))
23591     op1 = safe_vector_operand (op1, mode1);
23592
23593   target = gen_reg_rtx (SImode);
23594   emit_move_insn (target, const0_rtx);
23595   target = gen_rtx_SUBREG (QImode, target, 0);
23596
23597   if ((optimize && !register_operand (op0, mode0))
23598       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23599     op0 = copy_to_mode_reg (mode0, op0);
23600   if ((optimize && !register_operand (op1, mode1))
23601       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23602     op1 = copy_to_mode_reg (mode1, op1);
23603
23604   pat = GEN_FCN (d->icode) (op0, op1);
23605   if (! pat)
23606     return 0;
23607   emit_insn (pat);
23608   emit_insn (gen_rtx_SET (VOIDmode,
23609                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23610                           gen_rtx_fmt_ee (comparison, QImode,
23611                                           SET_DEST (pat),
23612                                           const0_rtx)));
23613
23614   return SUBREG_REG (target);
23615 }
23616
23617 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
23618
23619 static rtx
23620 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
23621                           tree exp, rtx target)
23622 {
23623   rtx pat;
23624   tree arg0 = CALL_EXPR_ARG (exp, 0);
23625   tree arg1 = CALL_EXPR_ARG (exp, 1);
23626   tree arg2 = CALL_EXPR_ARG (exp, 2);
23627   tree arg3 = CALL_EXPR_ARG (exp, 3);
23628   tree arg4 = CALL_EXPR_ARG (exp, 4);
23629   rtx scratch0, scratch1;
23630   rtx op0 = expand_normal (arg0);
23631   rtx op1 = expand_normal (arg1);
23632   rtx op2 = expand_normal (arg2);
23633   rtx op3 = expand_normal (arg3);
23634   rtx op4 = expand_normal (arg4);
23635   enum machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
23636
23637   tmode0 = insn_data[d->icode].operand[0].mode;
23638   tmode1 = insn_data[d->icode].operand[1].mode;
23639   modev2 = insn_data[d->icode].operand[2].mode;
23640   modei3 = insn_data[d->icode].operand[3].mode;
23641   modev4 = insn_data[d->icode].operand[4].mode;
23642   modei5 = insn_data[d->icode].operand[5].mode;
23643   modeimm = insn_data[d->icode].operand[6].mode;
23644
23645   if (VECTOR_MODE_P (modev2))
23646     op0 = safe_vector_operand (op0, modev2);
23647   if (VECTOR_MODE_P (modev4))
23648     op2 = safe_vector_operand (op2, modev4);
23649
23650   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
23651     op0 = copy_to_mode_reg (modev2, op0);
23652   if (! (*insn_data[d->icode].operand[3].predicate) (op1, modei3))
23653     op1 = copy_to_mode_reg (modei3, op1);
23654   if ((optimize && !register_operand (op2, modev4))
23655       || !(*insn_data[d->icode].operand[4].predicate) (op2, modev4))
23656     op2 = copy_to_mode_reg (modev4, op2);
23657   if (! (*insn_data[d->icode].operand[5].predicate) (op3, modei5))
23658     op3 = copy_to_mode_reg (modei5, op3);
23659
23660   if (! (*insn_data[d->icode].operand[6].predicate) (op4, modeimm))
23661     {
23662       error ("the fifth argument must be a 8-bit immediate");
23663       return const0_rtx;
23664     }
23665
23666   if (d->code == IX86_BUILTIN_PCMPESTRI128)
23667     {
23668       if (optimize || !target
23669           || GET_MODE (target) != tmode0
23670           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
23671         target = gen_reg_rtx (tmode0);
23672
23673       scratch1 = gen_reg_rtx (tmode1);
23674
23675       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
23676     }
23677   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
23678     {
23679       if (optimize || !target
23680           || GET_MODE (target) != tmode1
23681           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
23682         target = gen_reg_rtx (tmode1);
23683
23684       scratch0 = gen_reg_rtx (tmode0);
23685
23686       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
23687     }
23688   else
23689     {
23690       gcc_assert (d->flag);
23691
23692       scratch0 = gen_reg_rtx (tmode0);
23693       scratch1 = gen_reg_rtx (tmode1);
23694
23695       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
23696     }
23697
23698   if (! pat)
23699     return 0;
23700
23701   emit_insn (pat);
23702
23703   if (d->flag)
23704     {
23705       target = gen_reg_rtx (SImode);
23706       emit_move_insn (target, const0_rtx);
23707       target = gen_rtx_SUBREG (QImode, target, 0);
23708
23709       emit_insn
23710         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23711                       gen_rtx_fmt_ee (EQ, QImode,
23712                                       gen_rtx_REG ((enum machine_mode) d->flag,
23713                                                    FLAGS_REG),
23714                                       const0_rtx)));
23715       return SUBREG_REG (target);
23716     }
23717   else
23718     return target;
23719 }
23720
23721
23722 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
23723
23724 static rtx
23725 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
23726                           tree exp, rtx target)
23727 {
23728   rtx pat;
23729   tree arg0 = CALL_EXPR_ARG (exp, 0);
23730   tree arg1 = CALL_EXPR_ARG (exp, 1);
23731   tree arg2 = CALL_EXPR_ARG (exp, 2);
23732   rtx scratch0, scratch1;
23733   rtx op0 = expand_normal (arg0);
23734   rtx op1 = expand_normal (arg1);
23735   rtx op2 = expand_normal (arg2);
23736   enum machine_mode tmode0, tmode1, modev2, modev3, modeimm;
23737
23738   tmode0 = insn_data[d->icode].operand[0].mode;
23739   tmode1 = insn_data[d->icode].operand[1].mode;
23740   modev2 = insn_data[d->icode].operand[2].mode;
23741   modev3 = insn_data[d->icode].operand[3].mode;
23742   modeimm = insn_data[d->icode].operand[4].mode;
23743
23744   if (VECTOR_MODE_P (modev2))
23745     op0 = safe_vector_operand (op0, modev2);
23746   if (VECTOR_MODE_P (modev3))
23747     op1 = safe_vector_operand (op1, modev3);
23748
23749   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
23750     op0 = copy_to_mode_reg (modev2, op0);
23751   if ((optimize && !register_operand (op1, modev3))
23752       || !(*insn_data[d->icode].operand[3].predicate) (op1, modev3))
23753     op1 = copy_to_mode_reg (modev3, op1);
23754
23755   if (! (*insn_data[d->icode].operand[4].predicate) (op2, modeimm))
23756     {
23757       error ("the third argument must be a 8-bit immediate");
23758       return const0_rtx;
23759     }
23760
23761   if (d->code == IX86_BUILTIN_PCMPISTRI128)
23762     {
23763       if (optimize || !target
23764           || GET_MODE (target) != tmode0
23765           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
23766         target = gen_reg_rtx (tmode0);
23767
23768       scratch1 = gen_reg_rtx (tmode1);
23769
23770       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
23771     }
23772   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
23773     {
23774       if (optimize || !target
23775           || GET_MODE (target) != tmode1
23776           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
23777         target = gen_reg_rtx (tmode1);
23778
23779       scratch0 = gen_reg_rtx (tmode0);
23780
23781       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
23782     }
23783   else
23784     {
23785       gcc_assert (d->flag);
23786
23787       scratch0 = gen_reg_rtx (tmode0);
23788       scratch1 = gen_reg_rtx (tmode1);
23789
23790       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
23791     }
23792
23793   if (! pat)
23794     return 0;
23795
23796   emit_insn (pat);
23797
23798   if (d->flag)
23799     {
23800       target = gen_reg_rtx (SImode);
23801       emit_move_insn (target, const0_rtx);
23802       target = gen_rtx_SUBREG (QImode, target, 0);
23803
23804       emit_insn
23805         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23806                       gen_rtx_fmt_ee (EQ, QImode,
23807                                       gen_rtx_REG ((enum machine_mode) d->flag,
23808                                                    FLAGS_REG),
23809                                       const0_rtx)));
23810       return SUBREG_REG (target);
23811     }
23812   else
23813     return target;
23814 }
23815
23816 /* Subroutine of ix86_expand_builtin to take care of insns with
23817    variable number of operands.  */
23818
23819 static rtx
23820 ix86_expand_args_builtin (const struct builtin_description *d,
23821                           tree exp, rtx target)
23822 {
23823   rtx pat, real_target;
23824   unsigned int i, nargs;
23825   unsigned int nargs_constant = 0;
23826   int num_memory = 0;
23827   struct
23828     {
23829       rtx op;
23830       enum machine_mode mode;
23831     } args[4];
23832   bool last_arg_count = false;
23833   enum insn_code icode = d->icode;
23834   const struct insn_data *insn_p = &insn_data[icode];
23835   enum machine_mode tmode = insn_p->operand[0].mode;
23836   enum machine_mode rmode = VOIDmode;
23837   bool swap = false;
23838   enum rtx_code comparison = d->comparison;
23839
23840   switch ((enum ix86_builtin_type) d->flag)
23841     {
23842     case INT_FTYPE_V8SF_V8SF_PTEST:
23843     case INT_FTYPE_V4DI_V4DI_PTEST:
23844     case INT_FTYPE_V4DF_V4DF_PTEST:
23845     case INT_FTYPE_V4SF_V4SF_PTEST:
23846     case INT_FTYPE_V2DI_V2DI_PTEST:
23847     case INT_FTYPE_V2DF_V2DF_PTEST:
23848       return ix86_expand_sse_ptest (d, exp, target);
23849     case FLOAT128_FTYPE_FLOAT128:
23850     case FLOAT_FTYPE_FLOAT:
23851     case INT64_FTYPE_V4SF:
23852     case INT64_FTYPE_V2DF:
23853     case INT_FTYPE_V16QI:
23854     case INT_FTYPE_V8QI:
23855     case INT_FTYPE_V8SF:
23856     case INT_FTYPE_V4DF:
23857     case INT_FTYPE_V4SF:
23858     case INT_FTYPE_V2DF:
23859     case V16QI_FTYPE_V16QI:
23860     case V8SI_FTYPE_V8SF:
23861     case V8SI_FTYPE_V4SI:
23862     case V8HI_FTYPE_V8HI:
23863     case V8HI_FTYPE_V16QI:
23864     case V8QI_FTYPE_V8QI:
23865     case V8SF_FTYPE_V8SF:
23866     case V8SF_FTYPE_V8SI:
23867     case V8SF_FTYPE_V4SF:
23868     case V4SI_FTYPE_V4SI:
23869     case V4SI_FTYPE_V16QI:
23870     case V4SI_FTYPE_V4SF:
23871     case V4SI_FTYPE_V8SI:
23872     case V4SI_FTYPE_V8HI:
23873     case V4SI_FTYPE_V4DF:
23874     case V4SI_FTYPE_V2DF:
23875     case V4HI_FTYPE_V4HI:
23876     case V4DF_FTYPE_V4DF:
23877     case V4DF_FTYPE_V4SI:
23878     case V4DF_FTYPE_V4SF:
23879     case V4DF_FTYPE_V2DF:
23880     case V4SF_FTYPE_V4SF:
23881     case V4SF_FTYPE_V4SI:
23882     case V4SF_FTYPE_V8SF:
23883     case V4SF_FTYPE_V4DF:
23884     case V4SF_FTYPE_V2DF:
23885     case V2DI_FTYPE_V2DI:
23886     case V2DI_FTYPE_V16QI:
23887     case V2DI_FTYPE_V8HI:
23888     case V2DI_FTYPE_V4SI:
23889     case V2DF_FTYPE_V2DF:
23890     case V2DF_FTYPE_V4SI:
23891     case V2DF_FTYPE_V4DF:
23892     case V2DF_FTYPE_V4SF:
23893     case V2DF_FTYPE_V2SI:
23894     case V2SI_FTYPE_V2SI:
23895     case V2SI_FTYPE_V4SF:
23896     case V2SI_FTYPE_V2SF:
23897     case V2SI_FTYPE_V2DF:
23898     case V2SF_FTYPE_V2SF:
23899     case V2SF_FTYPE_V2SI:
23900       nargs = 1;
23901       break;
23902     case V4SF_FTYPE_V4SF_VEC_MERGE:
23903     case V2DF_FTYPE_V2DF_VEC_MERGE:
23904       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
23905     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
23906     case V16QI_FTYPE_V16QI_V16QI:
23907     case V16QI_FTYPE_V8HI_V8HI:
23908     case V8QI_FTYPE_V8QI_V8QI:
23909     case V8QI_FTYPE_V4HI_V4HI:
23910     case V8HI_FTYPE_V8HI_V8HI:
23911     case V8HI_FTYPE_V16QI_V16QI:
23912     case V8HI_FTYPE_V4SI_V4SI:
23913     case V8SF_FTYPE_V8SF_V8SF:
23914     case V8SF_FTYPE_V8SF_V8SI:
23915     case V4SI_FTYPE_V4SI_V4SI:
23916     case V4SI_FTYPE_V8HI_V8HI:
23917     case V4SI_FTYPE_V4SF_V4SF:
23918     case V4SI_FTYPE_V2DF_V2DF:
23919     case V4HI_FTYPE_V4HI_V4HI:
23920     case V4HI_FTYPE_V8QI_V8QI:
23921     case V4HI_FTYPE_V2SI_V2SI:
23922     case V4DF_FTYPE_V4DF_V4DF:
23923     case V4DF_FTYPE_V4DF_V4DI:
23924     case V4SF_FTYPE_V4SF_V4SF:
23925     case V4SF_FTYPE_V4SF_V4SI:
23926     case V4SF_FTYPE_V4SF_V2SI:
23927     case V4SF_FTYPE_V4SF_V2DF:
23928     case V4SF_FTYPE_V4SF_DI:
23929     case V4SF_FTYPE_V4SF_SI:
23930     case V2DI_FTYPE_V2DI_V2DI:
23931     case V2DI_FTYPE_V16QI_V16QI:
23932     case V2DI_FTYPE_V4SI_V4SI:
23933     case V2DI_FTYPE_V2DI_V16QI:
23934     case V2DI_FTYPE_V2DF_V2DF:
23935     case V2SI_FTYPE_V2SI_V2SI:
23936     case V2SI_FTYPE_V4HI_V4HI:
23937     case V2SI_FTYPE_V2SF_V2SF:
23938     case V2DF_FTYPE_V2DF_V2DF:
23939     case V2DF_FTYPE_V2DF_V4SF:
23940     case V2DF_FTYPE_V2DF_V2DI:
23941     case V2DF_FTYPE_V2DF_DI:
23942     case V2DF_FTYPE_V2DF_SI:
23943     case V2SF_FTYPE_V2SF_V2SF:
23944     case V1DI_FTYPE_V1DI_V1DI:
23945     case V1DI_FTYPE_V8QI_V8QI:
23946     case V1DI_FTYPE_V2SI_V2SI:
23947       if (comparison == UNKNOWN)
23948         return ix86_expand_binop_builtin (icode, exp, target);
23949       nargs = 2;
23950       break;
23951     case V4SF_FTYPE_V4SF_V4SF_SWAP:
23952     case V2DF_FTYPE_V2DF_V2DF_SWAP:
23953       gcc_assert (comparison != UNKNOWN);
23954       nargs = 2;
23955       swap = true;
23956       break;
23957     case V8HI_FTYPE_V8HI_V8HI_COUNT:
23958     case V8HI_FTYPE_V8HI_SI_COUNT:
23959     case V4SI_FTYPE_V4SI_V4SI_COUNT:
23960     case V4SI_FTYPE_V4SI_SI_COUNT:
23961     case V4HI_FTYPE_V4HI_V4HI_COUNT:
23962     case V4HI_FTYPE_V4HI_SI_COUNT:
23963     case V2DI_FTYPE_V2DI_V2DI_COUNT:
23964     case V2DI_FTYPE_V2DI_SI_COUNT:
23965     case V2SI_FTYPE_V2SI_V2SI_COUNT:
23966     case V2SI_FTYPE_V2SI_SI_COUNT:
23967     case V1DI_FTYPE_V1DI_V1DI_COUNT:
23968     case V1DI_FTYPE_V1DI_SI_COUNT:
23969       nargs = 2;
23970       last_arg_count = true;
23971       break;
23972     case UINT64_FTYPE_UINT64_UINT64:
23973     case UINT_FTYPE_UINT_UINT:
23974     case UINT_FTYPE_UINT_USHORT:
23975     case UINT_FTYPE_UINT_UCHAR:
23976       nargs = 2;
23977       break;
23978     case V2DI2TI_FTYPE_V2DI_INT:
23979       nargs = 2;
23980       rmode = V2DImode;
23981       nargs_constant = 1;
23982       break;
23983     case V8HI_FTYPE_V8HI_INT:
23984     case V8SF_FTYPE_V8SF_INT:
23985     case V4SI_FTYPE_V4SI_INT:
23986     case V4SI_FTYPE_V8SI_INT:
23987     case V4HI_FTYPE_V4HI_INT:
23988     case V4DF_FTYPE_V4DF_INT:
23989     case V4SF_FTYPE_V4SF_INT:
23990     case V4SF_FTYPE_V8SF_INT:
23991     case V2DI_FTYPE_V2DI_INT:
23992     case V2DF_FTYPE_V2DF_INT:
23993     case V2DF_FTYPE_V4DF_INT:
23994       nargs = 2;
23995       nargs_constant = 1;
23996       break;
23997     case V16QI_FTYPE_V16QI_V16QI_V16QI:
23998     case V8SF_FTYPE_V8SF_V8SF_V8SF:
23999     case V4DF_FTYPE_V4DF_V4DF_V4DF:
24000     case V4SF_FTYPE_V4SF_V4SF_V4SF:
24001     case V2DF_FTYPE_V2DF_V2DF_V2DF:
24002       nargs = 3;
24003       break;
24004     case V16QI_FTYPE_V16QI_V16QI_INT:
24005     case V8HI_FTYPE_V8HI_V8HI_INT:
24006     case V8SI_FTYPE_V8SI_V8SI_INT:
24007     case V8SI_FTYPE_V8SI_V4SI_INT:
24008     case V8SF_FTYPE_V8SF_V8SF_INT: 
24009     case V8SF_FTYPE_V8SF_V4SF_INT: 
24010     case V4SI_FTYPE_V4SI_V4SI_INT:
24011     case V4DF_FTYPE_V4DF_V4DF_INT:
24012     case V4DF_FTYPE_V4DF_V2DF_INT:
24013     case V4SF_FTYPE_V4SF_V4SF_INT:
24014     case V2DI_FTYPE_V2DI_V2DI_INT:
24015     case V2DF_FTYPE_V2DF_V2DF_INT:
24016       nargs = 3;
24017       nargs_constant = 1;
24018       break;
24019     case V2DI2TI_FTYPE_V2DI_V2DI_INT:
24020       nargs = 3;
24021       rmode = V2DImode;
24022       nargs_constant = 1;
24023       break;
24024     case V1DI2DI_FTYPE_V1DI_V1DI_INT:
24025       nargs = 3;
24026       rmode = DImode;
24027       nargs_constant = 1;
24028       break;
24029     case V2DI_FTYPE_V2DI_UINT_UINT:
24030       nargs = 3;
24031       nargs_constant = 2;
24032       break;
24033     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
24034       nargs = 4;
24035       nargs_constant = 2;
24036       break;
24037     default:
24038       gcc_unreachable ();
24039     }
24040
24041   gcc_assert (nargs <= ARRAY_SIZE (args));
24042
24043   if (comparison != UNKNOWN)
24044     {
24045       gcc_assert (nargs == 2);
24046       return ix86_expand_sse_compare (d, exp, target, swap);
24047     }
24048
24049   if (rmode == VOIDmode || rmode == tmode)
24050     {
24051       if (optimize
24052           || target == 0
24053           || GET_MODE (target) != tmode
24054           || ! (*insn_p->operand[0].predicate) (target, tmode))
24055         target = gen_reg_rtx (tmode);
24056       real_target = target;
24057     }
24058   else
24059     {
24060       target = gen_reg_rtx (rmode);
24061       real_target = simplify_gen_subreg (tmode, target, rmode, 0);
24062     }
24063
24064   for (i = 0; i < nargs; i++)
24065     {
24066       tree arg = CALL_EXPR_ARG (exp, i);
24067       rtx op = expand_normal (arg);
24068       enum machine_mode mode = insn_p->operand[i + 1].mode;
24069       bool match = (*insn_p->operand[i + 1].predicate) (op, mode);
24070
24071       if (last_arg_count && (i + 1) == nargs)
24072         {
24073           /* SIMD shift insns take either an 8-bit immediate or
24074              register as count.  But builtin functions take int as
24075              count.  If count doesn't match, we put it in register.  */
24076           if (!match)
24077             {
24078               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
24079               if (!(*insn_p->operand[i + 1].predicate) (op, mode))
24080                 op = copy_to_reg (op);
24081             }
24082         }
24083       else if ((nargs - i) <= nargs_constant)
24084         {
24085           if (!match)
24086             switch (icode)
24087               {
24088               case CODE_FOR_sse4_1_roundpd:
24089               case CODE_FOR_sse4_1_roundps:
24090               case CODE_FOR_sse4_1_roundsd:
24091               case CODE_FOR_sse4_1_roundss:
24092               case CODE_FOR_sse4_1_blendps:
24093               case CODE_FOR_avx_blendpd256:
24094               case CODE_FOR_avx_vpermilv4df:
24095               case CODE_FOR_avx_roundpd256:
24096               case CODE_FOR_avx_roundps256:
24097                 error ("the last argument must be a 4-bit immediate");
24098                 return const0_rtx;
24099
24100               case CODE_FOR_sse4_1_blendpd:
24101               case CODE_FOR_avx_vpermilv2df:
24102                 error ("the last argument must be a 2-bit immediate");
24103                 return const0_rtx;
24104
24105               case CODE_FOR_avx_vextractf128v4df:
24106               case CODE_FOR_avx_vextractf128v8sf:
24107               case CODE_FOR_avx_vextractf128v8si:
24108               case CODE_FOR_avx_vinsertf128v4df:
24109               case CODE_FOR_avx_vinsertf128v8sf:
24110               case CODE_FOR_avx_vinsertf128v8si:
24111                 error ("the last argument must be a 1-bit immediate");
24112                 return const0_rtx;
24113
24114               case CODE_FOR_avx_cmpsdv2df3:
24115               case CODE_FOR_avx_cmpssv4sf3:
24116               case CODE_FOR_avx_cmppdv2df3:
24117               case CODE_FOR_avx_cmppsv4sf3:
24118               case CODE_FOR_avx_cmppdv4df3:
24119               case CODE_FOR_avx_cmppsv8sf3:
24120                 error ("the last argument must be a 5-bit immediate");
24121                 return const0_rtx;
24122
24123              default:
24124                 switch (nargs_constant)
24125                   {
24126                   case 2:
24127                     if ((nargs - i) == nargs_constant)
24128                       {
24129                         error ("the next to last argument must be an 8-bit immediate");
24130                         break;
24131                       }
24132                   case 1:
24133                     error ("the last argument must be an 8-bit immediate");
24134                     break;
24135                   default:
24136                     gcc_unreachable ();
24137                   }
24138                 return const0_rtx;
24139               }
24140         }
24141       else
24142         {
24143           if (VECTOR_MODE_P (mode))
24144             op = safe_vector_operand (op, mode);
24145
24146           /* If we aren't optimizing, only allow one memory operand to
24147              be generated.  */
24148           if (memory_operand (op, mode))
24149             num_memory++;
24150
24151           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
24152             {
24153               if (optimize || !match || num_memory > 1)
24154                 op = copy_to_mode_reg (mode, op);
24155             }
24156           else
24157             {
24158               op = copy_to_reg (op);
24159               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
24160             }
24161         }
24162
24163       args[i].op = op;
24164       args[i].mode = mode;
24165     }
24166
24167   switch (nargs)
24168     {
24169     case 1:
24170       pat = GEN_FCN (icode) (real_target, args[0].op);
24171       break;
24172     case 2:
24173       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
24174       break;
24175     case 3:
24176       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
24177                              args[2].op);
24178       break;
24179     case 4:
24180       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
24181                              args[2].op, args[3].op);
24182       break;
24183     default:
24184       gcc_unreachable ();
24185     }
24186
24187   if (! pat)
24188     return 0;
24189
24190   emit_insn (pat);
24191   return target;
24192 }
24193
24194 /* Subroutine of ix86_expand_builtin to take care of special insns
24195    with variable number of operands.  */
24196
24197 static rtx
24198 ix86_expand_special_args_builtin (const struct builtin_description *d,
24199                                     tree exp, rtx target)
24200 {
24201   tree arg;
24202   rtx pat, op;
24203   unsigned int i, nargs, arg_adjust, memory;
24204   struct
24205     {
24206       rtx op;
24207       enum machine_mode mode;
24208     } args[2];
24209   enum insn_code icode = d->icode;
24210   bool last_arg_constant = false;
24211   const struct insn_data *insn_p = &insn_data[icode];
24212   enum machine_mode tmode = insn_p->operand[0].mode;
24213   enum { load, store } klass;
24214
24215   switch ((enum ix86_special_builtin_type) d->flag)
24216     {
24217     case VOID_FTYPE_VOID:
24218       emit_insn (GEN_FCN (icode) (target));
24219       return 0;
24220     case V2DI_FTYPE_PV2DI:
24221     case V32QI_FTYPE_PCCHAR:
24222     case V16QI_FTYPE_PCCHAR:
24223     case V8SF_FTYPE_PCV4SF:
24224     case V8SF_FTYPE_PCFLOAT:
24225     case V4SF_FTYPE_PCFLOAT:
24226     case V4DF_FTYPE_PCV2DF:
24227     case V4DF_FTYPE_PCDOUBLE:
24228     case V2DF_FTYPE_PCDOUBLE:
24229       nargs = 1;
24230       klass = load;
24231       memory = 0;
24232       break;
24233     case VOID_FTYPE_PV2SF_V4SF:
24234     case VOID_FTYPE_PV4DI_V4DI:
24235     case VOID_FTYPE_PV2DI_V2DI:
24236     case VOID_FTYPE_PCHAR_V32QI:
24237     case VOID_FTYPE_PCHAR_V16QI:
24238     case VOID_FTYPE_PFLOAT_V8SF:
24239     case VOID_FTYPE_PFLOAT_V4SF:
24240     case VOID_FTYPE_PDOUBLE_V4DF:
24241     case VOID_FTYPE_PDOUBLE_V2DF:
24242     case VOID_FTYPE_PDI_DI:
24243     case VOID_FTYPE_PINT_INT:
24244       nargs = 1;
24245       klass = store;
24246       /* Reserve memory operand for target.  */
24247       memory = ARRAY_SIZE (args);
24248       break;
24249     case V4SF_FTYPE_V4SF_PCV2SF:
24250     case V2DF_FTYPE_V2DF_PCDOUBLE:
24251       nargs = 2;
24252       klass = load;
24253       memory = 1;
24254       break;
24255     case V8SF_FTYPE_PCV8SF_V8SF:
24256     case V4DF_FTYPE_PCV4DF_V4DF:
24257     case V4SF_FTYPE_PCV4SF_V4SF:
24258     case V2DF_FTYPE_PCV2DF_V2DF:
24259       nargs = 2;
24260       klass = load;
24261       memory = 0;
24262       break;
24263     case VOID_FTYPE_PV8SF_V8SF_V8SF:
24264     case VOID_FTYPE_PV4DF_V4DF_V4DF:
24265     case VOID_FTYPE_PV4SF_V4SF_V4SF:
24266     case VOID_FTYPE_PV2DF_V2DF_V2DF:
24267       nargs = 2;
24268       klass = store;
24269       /* Reserve memory operand for target.  */
24270       memory = ARRAY_SIZE (args);
24271       break;
24272     default:
24273       gcc_unreachable ();
24274     }
24275
24276   gcc_assert (nargs <= ARRAY_SIZE (args));
24277
24278   if (klass == store)
24279     {
24280       arg = CALL_EXPR_ARG (exp, 0);
24281       op = expand_normal (arg);
24282       gcc_assert (target == 0);
24283       target = gen_rtx_MEM (tmode, copy_to_mode_reg (Pmode, op));
24284       arg_adjust = 1;
24285     }
24286   else
24287     {
24288       arg_adjust = 0;
24289       if (optimize
24290           || target == 0
24291           || GET_MODE (target) != tmode
24292           || ! (*insn_p->operand[0].predicate) (target, tmode))
24293         target = gen_reg_rtx (tmode);
24294     }
24295
24296   for (i = 0; i < nargs; i++)
24297     {
24298       enum machine_mode mode = insn_p->operand[i + 1].mode;
24299       bool match;
24300
24301       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
24302       op = expand_normal (arg);
24303       match = (*insn_p->operand[i + 1].predicate) (op, mode);
24304
24305       if (last_arg_constant && (i + 1) == nargs)
24306         {
24307           if (!match)
24308             switch (icode)
24309               {
24310              default:
24311                 error ("the last argument must be an 8-bit immediate");
24312                 return const0_rtx;
24313               }
24314         }
24315       else
24316         {
24317           if (i == memory)
24318             {
24319               /* This must be the memory operand.  */
24320               op = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, op));
24321               gcc_assert (GET_MODE (op) == mode
24322                           || GET_MODE (op) == VOIDmode);
24323             }
24324           else
24325             {
24326               /* This must be register.  */
24327               if (VECTOR_MODE_P (mode))
24328                 op = safe_vector_operand (op, mode);
24329
24330               gcc_assert (GET_MODE (op) == mode
24331                           || GET_MODE (op) == VOIDmode);
24332               op = copy_to_mode_reg (mode, op);
24333             }
24334         }
24335
24336       args[i].op = op;
24337       args[i].mode = mode;
24338     }
24339
24340   switch (nargs)
24341     {
24342     case 1:
24343       pat = GEN_FCN (icode) (target, args[0].op);
24344       break;
24345     case 2:
24346       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
24347       break;
24348     default:
24349       gcc_unreachable ();
24350     }
24351
24352   if (! pat)
24353     return 0;
24354   emit_insn (pat);
24355   return klass == store ? 0 : target;
24356 }
24357
24358 /* Return the integer constant in ARG.  Constrain it to be in the range
24359    of the subparts of VEC_TYPE; issue an error if not.  */
24360
24361 static int
24362 get_element_number (tree vec_type, tree arg)
24363 {
24364   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
24365
24366   if (!host_integerp (arg, 1)
24367       || (elt = tree_low_cst (arg, 1), elt > max))
24368     {
24369       error ("selector must be an integer constant in the range 0..%wi", max);
24370       return 0;
24371     }
24372
24373   return elt;
24374 }
24375
24376 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24377    ix86_expand_vector_init.  We DO have language-level syntax for this, in
24378    the form of  (type){ init-list }.  Except that since we can't place emms
24379    instructions from inside the compiler, we can't allow the use of MMX
24380    registers unless the user explicitly asks for it.  So we do *not* define
24381    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
24382    we have builtins invoked by mmintrin.h that gives us license to emit
24383    these sorts of instructions.  */
24384
24385 static rtx
24386 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
24387 {
24388   enum machine_mode tmode = TYPE_MODE (type);
24389   enum machine_mode inner_mode = GET_MODE_INNER (tmode);
24390   int i, n_elt = GET_MODE_NUNITS (tmode);
24391   rtvec v = rtvec_alloc (n_elt);
24392
24393   gcc_assert (VECTOR_MODE_P (tmode));
24394   gcc_assert (call_expr_nargs (exp) == n_elt);
24395
24396   for (i = 0; i < n_elt; ++i)
24397     {
24398       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
24399       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
24400     }
24401
24402   if (!target || !register_operand (target, tmode))
24403     target = gen_reg_rtx (tmode);
24404
24405   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
24406   return target;
24407 }
24408
24409 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24410    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
24411    had a language-level syntax for referencing vector elements.  */
24412
24413 static rtx
24414 ix86_expand_vec_ext_builtin (tree exp, rtx target)
24415 {
24416   enum machine_mode tmode, mode0;
24417   tree arg0, arg1;
24418   int elt;
24419   rtx op0;
24420
24421   arg0 = CALL_EXPR_ARG (exp, 0);
24422   arg1 = CALL_EXPR_ARG (exp, 1);
24423
24424   op0 = expand_normal (arg0);
24425   elt = get_element_number (TREE_TYPE (arg0), arg1);
24426
24427   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24428   mode0 = TYPE_MODE (TREE_TYPE (arg0));
24429   gcc_assert (VECTOR_MODE_P (mode0));
24430
24431   op0 = force_reg (mode0, op0);
24432
24433   if (optimize || !target || !register_operand (target, tmode))
24434     target = gen_reg_rtx (tmode);
24435
24436   ix86_expand_vector_extract (true, target, op0, elt);
24437
24438   return target;
24439 }
24440
24441 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24442    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
24443    a language-level syntax for referencing vector elements.  */
24444
24445 static rtx
24446 ix86_expand_vec_set_builtin (tree exp)
24447 {
24448   enum machine_mode tmode, mode1;
24449   tree arg0, arg1, arg2;
24450   int elt;
24451   rtx op0, op1, target;
24452
24453   arg0 = CALL_EXPR_ARG (exp, 0);
24454   arg1 = CALL_EXPR_ARG (exp, 1);
24455   arg2 = CALL_EXPR_ARG (exp, 2);
24456
24457   tmode = TYPE_MODE (TREE_TYPE (arg0));
24458   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24459   gcc_assert (VECTOR_MODE_P (tmode));
24460
24461   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
24462   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
24463   elt = get_element_number (TREE_TYPE (arg0), arg2);
24464
24465   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
24466     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
24467
24468   op0 = force_reg (tmode, op0);
24469   op1 = force_reg (mode1, op1);
24470
24471   /* OP0 is the source of these builtin functions and shouldn't be
24472      modified.  Create a copy, use it and return it as target.  */
24473   target = gen_reg_rtx (tmode);
24474   emit_move_insn (target, op0);
24475   ix86_expand_vector_set (true, target, op1, elt);
24476
24477   return target;
24478 }
24479
24480 /* Expand an expression EXP that calls a built-in function,
24481    with result going to TARGET if that's convenient
24482    (and in mode MODE if that's convenient).
24483    SUBTARGET may be used as the target for computing one of EXP's operands.
24484    IGNORE is nonzero if the value is to be ignored.  */
24485
24486 static rtx
24487 ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
24488                      enum machine_mode mode ATTRIBUTE_UNUSED,
24489                      int ignore ATTRIBUTE_UNUSED)
24490 {
24491   const struct builtin_description *d;
24492   size_t i;
24493   enum insn_code icode;
24494   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
24495   tree arg0, arg1, arg2;
24496   rtx op0, op1, op2, pat;
24497   enum machine_mode mode0, mode1, mode2;
24498   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
24499
24500   /* Determine whether the builtin function is available under the current ISA.
24501      Originally the builtin was not created if it wasn't applicable to the
24502      current ISA based on the command line switches.  With function specific
24503      options, we need to check in the context of the function making the call
24504      whether it is supported.  */
24505   if (ix86_builtins_isa[fcode].isa
24506       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
24507     {
24508       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
24509                                        NULL, NULL, false);
24510
24511       if (!opts)
24512         error ("%qE needs unknown isa option", fndecl);
24513       else
24514         {
24515           gcc_assert (opts != NULL);
24516           error ("%qE needs isa option %s", fndecl, opts);
24517           free (opts);
24518         }
24519       return const0_rtx;
24520     }
24521
24522   switch (fcode)
24523     {
24524     case IX86_BUILTIN_MASKMOVQ:
24525     case IX86_BUILTIN_MASKMOVDQU:
24526       icode = (fcode == IX86_BUILTIN_MASKMOVQ
24527                ? CODE_FOR_mmx_maskmovq
24528                : CODE_FOR_sse2_maskmovdqu);
24529       /* Note the arg order is different from the operand order.  */
24530       arg1 = CALL_EXPR_ARG (exp, 0);
24531       arg2 = CALL_EXPR_ARG (exp, 1);
24532       arg0 = CALL_EXPR_ARG (exp, 2);
24533       op0 = expand_normal (arg0);
24534       op1 = expand_normal (arg1);
24535       op2 = expand_normal (arg2);
24536       mode0 = insn_data[icode].operand[0].mode;
24537       mode1 = insn_data[icode].operand[1].mode;
24538       mode2 = insn_data[icode].operand[2].mode;
24539
24540       op0 = force_reg (Pmode, op0);
24541       op0 = gen_rtx_MEM (mode1, op0);
24542
24543       if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
24544         op0 = copy_to_mode_reg (mode0, op0);
24545       if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
24546         op1 = copy_to_mode_reg (mode1, op1);
24547       if (! (*insn_data[icode].operand[2].predicate) (op2, mode2))
24548         op2 = copy_to_mode_reg (mode2, op2);
24549       pat = GEN_FCN (icode) (op0, op1, op2);
24550       if (! pat)
24551         return 0;
24552       emit_insn (pat);
24553       return 0;
24554
24555     case IX86_BUILTIN_LDMXCSR:
24556       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
24557       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24558       emit_move_insn (target, op0);
24559       emit_insn (gen_sse_ldmxcsr (target));
24560       return 0;
24561
24562     case IX86_BUILTIN_STMXCSR:
24563       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24564       emit_insn (gen_sse_stmxcsr (target));
24565       return copy_to_mode_reg (SImode, target);
24566
24567     case IX86_BUILTIN_CLFLUSH:
24568         arg0 = CALL_EXPR_ARG (exp, 0);
24569         op0 = expand_normal (arg0);
24570         icode = CODE_FOR_sse2_clflush;
24571         if (! (*insn_data[icode].operand[0].predicate) (op0, Pmode))
24572             op0 = copy_to_mode_reg (Pmode, op0);
24573
24574         emit_insn (gen_sse2_clflush (op0));
24575         return 0;
24576
24577     case IX86_BUILTIN_MONITOR:
24578       arg0 = CALL_EXPR_ARG (exp, 0);
24579       arg1 = CALL_EXPR_ARG (exp, 1);
24580       arg2 = CALL_EXPR_ARG (exp, 2);
24581       op0 = expand_normal (arg0);
24582       op1 = expand_normal (arg1);
24583       op2 = expand_normal (arg2);
24584       if (!REG_P (op0))
24585         op0 = copy_to_mode_reg (Pmode, op0);
24586       if (!REG_P (op1))
24587         op1 = copy_to_mode_reg (SImode, op1);
24588       if (!REG_P (op2))
24589         op2 = copy_to_mode_reg (SImode, op2);
24590       emit_insn ((*ix86_gen_monitor) (op0, op1, op2));
24591       return 0;
24592
24593     case IX86_BUILTIN_MWAIT:
24594       arg0 = CALL_EXPR_ARG (exp, 0);
24595       arg1 = CALL_EXPR_ARG (exp, 1);
24596       op0 = expand_normal (arg0);
24597       op1 = expand_normal (arg1);
24598       if (!REG_P (op0))
24599         op0 = copy_to_mode_reg (SImode, op0);
24600       if (!REG_P (op1))
24601         op1 = copy_to_mode_reg (SImode, op1);
24602       emit_insn (gen_sse3_mwait (op0, op1));
24603       return 0;
24604
24605     case IX86_BUILTIN_VEC_INIT_V2SI:
24606     case IX86_BUILTIN_VEC_INIT_V4HI:
24607     case IX86_BUILTIN_VEC_INIT_V8QI:
24608       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
24609
24610     case IX86_BUILTIN_VEC_EXT_V2DF:
24611     case IX86_BUILTIN_VEC_EXT_V2DI:
24612     case IX86_BUILTIN_VEC_EXT_V4SF:
24613     case IX86_BUILTIN_VEC_EXT_V4SI:
24614     case IX86_BUILTIN_VEC_EXT_V8HI:
24615     case IX86_BUILTIN_VEC_EXT_V2SI:
24616     case IX86_BUILTIN_VEC_EXT_V4HI:
24617     case IX86_BUILTIN_VEC_EXT_V16QI:
24618       return ix86_expand_vec_ext_builtin (exp, target);
24619
24620     case IX86_BUILTIN_VEC_SET_V2DI:
24621     case IX86_BUILTIN_VEC_SET_V4SF:
24622     case IX86_BUILTIN_VEC_SET_V4SI:
24623     case IX86_BUILTIN_VEC_SET_V8HI:
24624     case IX86_BUILTIN_VEC_SET_V4HI:
24625     case IX86_BUILTIN_VEC_SET_V16QI:
24626       return ix86_expand_vec_set_builtin (exp);
24627
24628     case IX86_BUILTIN_INFQ:
24629       {
24630         REAL_VALUE_TYPE inf;
24631         rtx tmp;
24632
24633         real_inf (&inf);
24634         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
24635
24636         tmp = validize_mem (force_const_mem (mode, tmp));
24637
24638         if (target == 0)
24639           target = gen_reg_rtx (mode);
24640
24641         emit_move_insn (target, tmp);
24642         return target;
24643       }
24644
24645     default:
24646       break;
24647     }
24648
24649   for (i = 0, d = bdesc_special_args;
24650        i < ARRAY_SIZE (bdesc_special_args);
24651        i++, d++)
24652     if (d->code == fcode)
24653       return ix86_expand_special_args_builtin (d, exp, target);
24654
24655   for (i = 0, d = bdesc_args;
24656        i < ARRAY_SIZE (bdesc_args);
24657        i++, d++)
24658     if (d->code == fcode)
24659       switch (fcode)
24660         {
24661         case IX86_BUILTIN_FABSQ:
24662         case IX86_BUILTIN_COPYSIGNQ:
24663           if (!TARGET_SSE2)
24664             /* Emit a normal call if SSE2 isn't available.  */
24665             return expand_call (exp, target, ignore);
24666         default:
24667           return ix86_expand_args_builtin (d, exp, target);
24668         }
24669
24670   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
24671     if (d->code == fcode)
24672       return ix86_expand_sse_comi (d, exp, target);
24673
24674   for (i = 0, d = bdesc_pcmpestr;
24675        i < ARRAY_SIZE (bdesc_pcmpestr);
24676        i++, d++)
24677     if (d->code == fcode)
24678       return ix86_expand_sse_pcmpestr (d, exp, target);
24679
24680   for (i = 0, d = bdesc_pcmpistr;
24681        i < ARRAY_SIZE (bdesc_pcmpistr);
24682        i++, d++)
24683     if (d->code == fcode)
24684       return ix86_expand_sse_pcmpistr (d, exp, target);
24685
24686   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
24687     if (d->code == fcode)
24688       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
24689                                             (enum multi_arg_type)d->flag,
24690                                             d->comparison);
24691
24692   gcc_unreachable ();
24693 }
24694
24695 /* Returns a function decl for a vectorized version of the builtin function
24696    with builtin function code FN and the result vector type TYPE, or NULL_TREE
24697    if it is not available.  */
24698
24699 static tree
24700 ix86_builtin_vectorized_function (unsigned int fn, tree type_out,
24701                                   tree type_in)
24702 {
24703   enum machine_mode in_mode, out_mode;
24704   int in_n, out_n;
24705
24706   if (TREE_CODE (type_out) != VECTOR_TYPE
24707       || TREE_CODE (type_in) != VECTOR_TYPE)
24708     return NULL_TREE;
24709
24710   out_mode = TYPE_MODE (TREE_TYPE (type_out));
24711   out_n = TYPE_VECTOR_SUBPARTS (type_out);
24712   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24713   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24714
24715   switch (fn)
24716     {
24717     case BUILT_IN_SQRT:
24718       if (out_mode == DFmode && out_n == 2
24719           && in_mode == DFmode && in_n == 2)
24720         return ix86_builtins[IX86_BUILTIN_SQRTPD];
24721       break;
24722
24723     case BUILT_IN_SQRTF:
24724       if (out_mode == SFmode && out_n == 4
24725           && in_mode == SFmode && in_n == 4)
24726         return ix86_builtins[IX86_BUILTIN_SQRTPS_NR];
24727       break;
24728
24729     case BUILT_IN_LRINT:
24730       if (out_mode == SImode && out_n == 4
24731           && in_mode == DFmode && in_n == 2)
24732         return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
24733       break;
24734
24735     case BUILT_IN_LRINTF:
24736       if (out_mode == SImode && out_n == 4
24737           && in_mode == SFmode && in_n == 4)
24738         return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
24739       break;
24740
24741     default:
24742       ;
24743     }
24744
24745   /* Dispatch to a handler for a vectorization library.  */
24746   if (ix86_veclib_handler)
24747     return (*ix86_veclib_handler)(fn, type_out, type_in);
24748
24749   return NULL_TREE;
24750 }
24751
24752 /* Handler for an SVML-style interface to
24753    a library with vectorized intrinsics.  */
24754
24755 static tree
24756 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
24757 {
24758   char name[20];
24759   tree fntype, new_fndecl, args;
24760   unsigned arity;
24761   const char *bname;
24762   enum machine_mode el_mode, in_mode;
24763   int n, in_n;
24764
24765   /* The SVML is suitable for unsafe math only.  */
24766   if (!flag_unsafe_math_optimizations)
24767     return NULL_TREE;
24768
24769   el_mode = TYPE_MODE (TREE_TYPE (type_out));
24770   n = TYPE_VECTOR_SUBPARTS (type_out);
24771   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24772   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24773   if (el_mode != in_mode
24774       || n != in_n)
24775     return NULL_TREE;
24776
24777   switch (fn)
24778     {
24779     case BUILT_IN_EXP:
24780     case BUILT_IN_LOG:
24781     case BUILT_IN_LOG10:
24782     case BUILT_IN_POW:
24783     case BUILT_IN_TANH:
24784     case BUILT_IN_TAN:
24785     case BUILT_IN_ATAN:
24786     case BUILT_IN_ATAN2:
24787     case BUILT_IN_ATANH:
24788     case BUILT_IN_CBRT:
24789     case BUILT_IN_SINH:
24790     case BUILT_IN_SIN:
24791     case BUILT_IN_ASINH:
24792     case BUILT_IN_ASIN:
24793     case BUILT_IN_COSH:
24794     case BUILT_IN_COS:
24795     case BUILT_IN_ACOSH:
24796     case BUILT_IN_ACOS:
24797       if (el_mode != DFmode || n != 2)
24798         return NULL_TREE;
24799       break;
24800
24801     case BUILT_IN_EXPF:
24802     case BUILT_IN_LOGF:
24803     case BUILT_IN_LOG10F:
24804     case BUILT_IN_POWF:
24805     case BUILT_IN_TANHF:
24806     case BUILT_IN_TANF:
24807     case BUILT_IN_ATANF:
24808     case BUILT_IN_ATAN2F:
24809     case BUILT_IN_ATANHF:
24810     case BUILT_IN_CBRTF:
24811     case BUILT_IN_SINHF:
24812     case BUILT_IN_SINF:
24813     case BUILT_IN_ASINHF:
24814     case BUILT_IN_ASINF:
24815     case BUILT_IN_COSHF:
24816     case BUILT_IN_COSF:
24817     case BUILT_IN_ACOSHF:
24818     case BUILT_IN_ACOSF:
24819       if (el_mode != SFmode || n != 4)
24820         return NULL_TREE;
24821       break;
24822
24823     default:
24824       return NULL_TREE;
24825     }
24826
24827   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
24828
24829   if (fn == BUILT_IN_LOGF)
24830     strcpy (name, "vmlsLn4");
24831   else if (fn == BUILT_IN_LOG)
24832     strcpy (name, "vmldLn2");
24833   else if (n == 4)
24834     {
24835       sprintf (name, "vmls%s", bname+10);
24836       name[strlen (name)-1] = '4';
24837     }
24838   else
24839     sprintf (name, "vmld%s2", bname+10);
24840
24841   /* Convert to uppercase. */
24842   name[4] &= ~0x20;
24843
24844   arity = 0;
24845   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
24846        args = TREE_CHAIN (args))
24847     arity++;
24848
24849   if (arity == 1)
24850     fntype = build_function_type_list (type_out, type_in, NULL);
24851   else
24852     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
24853
24854   /* Build a function declaration for the vectorized function.  */
24855   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
24856   TREE_PUBLIC (new_fndecl) = 1;
24857   DECL_EXTERNAL (new_fndecl) = 1;
24858   DECL_IS_NOVOPS (new_fndecl) = 1;
24859   TREE_READONLY (new_fndecl) = 1;
24860
24861   return new_fndecl;
24862 }
24863
24864 /* Handler for an ACML-style interface to
24865    a library with vectorized intrinsics.  */
24866
24867 static tree
24868 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
24869 {
24870   char name[20] = "__vr.._";
24871   tree fntype, new_fndecl, args;
24872   unsigned arity;
24873   const char *bname;
24874   enum machine_mode el_mode, in_mode;
24875   int n, in_n;
24876
24877   /* The ACML is 64bits only and suitable for unsafe math only as
24878      it does not correctly support parts of IEEE with the required
24879      precision such as denormals.  */
24880   if (!TARGET_64BIT
24881       || !flag_unsafe_math_optimizations)
24882     return NULL_TREE;
24883
24884   el_mode = TYPE_MODE (TREE_TYPE (type_out));
24885   n = TYPE_VECTOR_SUBPARTS (type_out);
24886   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24887   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24888   if (el_mode != in_mode
24889       || n != in_n)
24890     return NULL_TREE;
24891
24892   switch (fn)
24893     {
24894     case BUILT_IN_SIN:
24895     case BUILT_IN_COS:
24896     case BUILT_IN_EXP:
24897     case BUILT_IN_LOG:
24898     case BUILT_IN_LOG2:
24899     case BUILT_IN_LOG10:
24900       name[4] = 'd';
24901       name[5] = '2';
24902       if (el_mode != DFmode
24903           || n != 2)
24904         return NULL_TREE;
24905       break;
24906
24907     case BUILT_IN_SINF:
24908     case BUILT_IN_COSF:
24909     case BUILT_IN_EXPF:
24910     case BUILT_IN_POWF:
24911     case BUILT_IN_LOGF:
24912     case BUILT_IN_LOG2F:
24913     case BUILT_IN_LOG10F:
24914       name[4] = 's';
24915       name[5] = '4';
24916       if (el_mode != SFmode
24917           || n != 4)
24918         return NULL_TREE;
24919       break;
24920
24921     default:
24922       return NULL_TREE;
24923     }
24924
24925   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
24926   sprintf (name + 7, "%s", bname+10);
24927
24928   arity = 0;
24929   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
24930        args = TREE_CHAIN (args))
24931     arity++;
24932
24933   if (arity == 1)
24934     fntype = build_function_type_list (type_out, type_in, NULL);
24935   else
24936     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
24937
24938   /* Build a function declaration for the vectorized function.  */
24939   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
24940   TREE_PUBLIC (new_fndecl) = 1;
24941   DECL_EXTERNAL (new_fndecl) = 1;
24942   DECL_IS_NOVOPS (new_fndecl) = 1;
24943   TREE_READONLY (new_fndecl) = 1;
24944
24945   return new_fndecl;
24946 }
24947
24948
24949 /* Returns a decl of a function that implements conversion of an integer vector
24950    into a floating-point vector, or vice-versa. TYPE is the type of the integer
24951    side of the conversion.
24952    Return NULL_TREE if it is not available.  */
24953
24954 static tree
24955 ix86_vectorize_builtin_conversion (unsigned int code, tree type)
24956 {
24957   if (TREE_CODE (type) != VECTOR_TYPE)
24958     return NULL_TREE;
24959
24960   switch (code)
24961     {
24962     case FLOAT_EXPR:
24963       switch (TYPE_MODE (type))
24964         {
24965         case V4SImode:
24966           return ix86_builtins[IX86_BUILTIN_CVTDQ2PS];
24967         default:
24968           return NULL_TREE;
24969         }
24970
24971     case FIX_TRUNC_EXPR:
24972       switch (TYPE_MODE (type))
24973         {
24974         case V4SImode:
24975           return ix86_builtins[IX86_BUILTIN_CVTTPS2DQ];
24976         default:
24977           return NULL_TREE;
24978         }
24979     default:
24980       return NULL_TREE;
24981
24982     }
24983 }
24984
24985 /* Returns a code for a target-specific builtin that implements
24986    reciprocal of the function, or NULL_TREE if not available.  */
24987
24988 static tree
24989 ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
24990                          bool sqrt ATTRIBUTE_UNUSED)
24991 {
24992   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
24993          && flag_finite_math_only && !flag_trapping_math
24994          && flag_unsafe_math_optimizations))
24995     return NULL_TREE;
24996
24997   if (md_fn)
24998     /* Machine dependent builtins.  */
24999     switch (fn)
25000       {
25001         /* Vectorized version of sqrt to rsqrt conversion.  */
25002       case IX86_BUILTIN_SQRTPS_NR:
25003         return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR];
25004
25005       default:
25006         return NULL_TREE;
25007       }
25008   else
25009     /* Normal builtins.  */
25010     switch (fn)
25011       {
25012         /* Sqrt to rsqrt conversion.  */
25013       case BUILT_IN_SQRTF:
25014         return ix86_builtins[IX86_BUILTIN_RSQRTF];
25015
25016       default:
25017         return NULL_TREE;
25018       }
25019 }
25020
25021 /* Store OPERAND to the memory after reload is completed.  This means
25022    that we can't easily use assign_stack_local.  */
25023 rtx
25024 ix86_force_to_memory (enum machine_mode mode, rtx operand)
25025 {
25026   rtx result;
25027
25028   gcc_assert (reload_completed);
25029   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE)
25030     {
25031       result = gen_rtx_MEM (mode,
25032                             gen_rtx_PLUS (Pmode,
25033                                           stack_pointer_rtx,
25034                                           GEN_INT (-RED_ZONE_SIZE)));
25035       emit_move_insn (result, operand);
25036     }
25037   else if ((TARGET_64BIT_MS_ABI || !TARGET_RED_ZONE) && TARGET_64BIT)
25038     {
25039       switch (mode)
25040         {
25041         case HImode:
25042         case SImode:
25043           operand = gen_lowpart (DImode, operand);
25044           /* FALLTHRU */
25045         case DImode:
25046           emit_insn (
25047                       gen_rtx_SET (VOIDmode,
25048                                    gen_rtx_MEM (DImode,
25049                                                 gen_rtx_PRE_DEC (DImode,
25050                                                         stack_pointer_rtx)),
25051                                    operand));
25052           break;
25053         default:
25054           gcc_unreachable ();
25055         }
25056       result = gen_rtx_MEM (mode, stack_pointer_rtx);
25057     }
25058   else
25059     {
25060       switch (mode)
25061         {
25062         case DImode:
25063           {
25064             rtx operands[2];
25065             split_di (&operand, 1, operands, operands + 1);
25066             emit_insn (
25067                         gen_rtx_SET (VOIDmode,
25068                                      gen_rtx_MEM (SImode,
25069                                                   gen_rtx_PRE_DEC (Pmode,
25070                                                         stack_pointer_rtx)),
25071                                      operands[1]));
25072             emit_insn (
25073                         gen_rtx_SET (VOIDmode,
25074                                      gen_rtx_MEM (SImode,
25075                                                   gen_rtx_PRE_DEC (Pmode,
25076                                                         stack_pointer_rtx)),
25077                                      operands[0]));
25078           }
25079           break;
25080         case HImode:
25081           /* Store HImodes as SImodes.  */
25082           operand = gen_lowpart (SImode, operand);
25083           /* FALLTHRU */
25084         case SImode:
25085           emit_insn (
25086                       gen_rtx_SET (VOIDmode,
25087                                    gen_rtx_MEM (GET_MODE (operand),
25088                                                 gen_rtx_PRE_DEC (SImode,
25089                                                         stack_pointer_rtx)),
25090                                    operand));
25091           break;
25092         default:
25093           gcc_unreachable ();
25094         }
25095       result = gen_rtx_MEM (mode, stack_pointer_rtx);
25096     }
25097   return result;
25098 }
25099
25100 /* Free operand from the memory.  */
25101 void
25102 ix86_free_from_memory (enum machine_mode mode)
25103 {
25104   if (!TARGET_RED_ZONE || TARGET_64BIT_MS_ABI)
25105     {
25106       int size;
25107
25108       if (mode == DImode || TARGET_64BIT)
25109         size = 8;
25110       else
25111         size = 4;
25112       /* Use LEA to deallocate stack space.  In peephole2 it will be converted
25113          to pop or add instruction if registers are available.  */
25114       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
25115                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
25116                                             GEN_INT (size))));
25117     }
25118 }
25119
25120 /* Put float CONST_DOUBLE in the constant pool instead of fp regs.
25121    QImode must go into class Q_REGS.
25122    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
25123    movdf to do mem-to-mem moves through integer regs.  */
25124 enum reg_class
25125 ix86_preferred_reload_class (rtx x, enum reg_class regclass)
25126 {
25127   enum machine_mode mode = GET_MODE (x);
25128
25129   /* We're only allowed to return a subclass of CLASS.  Many of the
25130      following checks fail for NO_REGS, so eliminate that early.  */
25131   if (regclass == NO_REGS)
25132     return NO_REGS;
25133
25134   /* All classes can load zeros.  */
25135   if (x == CONST0_RTX (mode))
25136     return regclass;
25137
25138   /* Force constants into memory if we are loading a (nonzero) constant into
25139      an MMX or SSE register.  This is because there are no MMX/SSE instructions
25140      to load from a constant.  */
25141   if (CONSTANT_P (x)
25142       && (MAYBE_MMX_CLASS_P (regclass) || MAYBE_SSE_CLASS_P (regclass)))
25143     return NO_REGS;
25144
25145   /* Prefer SSE regs only, if we can use them for math.  */
25146   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
25147     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
25148
25149   /* Floating-point constants need more complex checks.  */
25150   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
25151     {
25152       /* General regs can load everything.  */
25153       if (reg_class_subset_p (regclass, GENERAL_REGS))
25154         return regclass;
25155
25156       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
25157          zero above.  We only want to wind up preferring 80387 registers if
25158          we plan on doing computation with them.  */
25159       if (TARGET_80387
25160           && standard_80387_constant_p (x))
25161         {
25162           /* Limit class to non-sse.  */
25163           if (regclass == FLOAT_SSE_REGS)
25164             return FLOAT_REGS;
25165           if (regclass == FP_TOP_SSE_REGS)
25166             return FP_TOP_REG;
25167           if (regclass == FP_SECOND_SSE_REGS)
25168             return FP_SECOND_REG;
25169           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
25170             return regclass;
25171         }
25172
25173       return NO_REGS;
25174     }
25175
25176   /* Generally when we see PLUS here, it's the function invariant
25177      (plus soft-fp const_int).  Which can only be computed into general
25178      regs.  */
25179   if (GET_CODE (x) == PLUS)
25180     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
25181
25182   /* QImode constants are easy to load, but non-constant QImode data
25183      must go into Q_REGS.  */
25184   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
25185     {
25186       if (reg_class_subset_p (regclass, Q_REGS))
25187         return regclass;
25188       if (reg_class_subset_p (Q_REGS, regclass))
25189         return Q_REGS;
25190       return NO_REGS;
25191     }
25192
25193   return regclass;
25194 }
25195
25196 /* Discourage putting floating-point values in SSE registers unless
25197    SSE math is being used, and likewise for the 387 registers.  */
25198 enum reg_class
25199 ix86_preferred_output_reload_class (rtx x, enum reg_class regclass)
25200 {
25201   enum machine_mode mode = GET_MODE (x);
25202
25203   /* Restrict the output reload class to the register bank that we are doing
25204      math on.  If we would like not to return a subset of CLASS, reject this
25205      alternative: if reload cannot do this, it will still use its choice.  */
25206   mode = GET_MODE (x);
25207   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
25208     return MAYBE_SSE_CLASS_P (regclass) ? SSE_REGS : NO_REGS;
25209
25210   if (X87_FLOAT_MODE_P (mode))
25211     {
25212       if (regclass == FP_TOP_SSE_REGS)
25213         return FP_TOP_REG;
25214       else if (regclass == FP_SECOND_SSE_REGS)
25215         return FP_SECOND_REG;
25216       else
25217         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
25218     }
25219
25220   return regclass;
25221 }
25222
25223 static enum reg_class
25224 ix86_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
25225                        enum machine_mode mode,
25226                        secondary_reload_info *sri ATTRIBUTE_UNUSED)
25227 {
25228   /* QImode spills from non-QI registers require
25229      intermediate register on 32bit targets.  */
25230   if (!in_p && mode == QImode && !TARGET_64BIT
25231       && (rclass == GENERAL_REGS
25232           || rclass == LEGACY_REGS
25233           || rclass == INDEX_REGS))
25234     {
25235       int regno;
25236
25237       if (REG_P (x))
25238         regno = REGNO (x);
25239       else
25240         regno = -1;
25241
25242       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
25243         regno = true_regnum (x);
25244
25245       /* Return Q_REGS if the operand is in memory.  */
25246       if (regno == -1)
25247         return Q_REGS;
25248     }
25249
25250   return NO_REGS;
25251 }
25252
25253 /* If we are copying between general and FP registers, we need a memory
25254    location. The same is true for SSE and MMX registers.
25255
25256    To optimize register_move_cost performance, allow inline variant.
25257
25258    The macro can't work reliably when one of the CLASSES is class containing
25259    registers from multiple units (SSE, MMX, integer).  We avoid this by never
25260    combining those units in single alternative in the machine description.
25261    Ensure that this constraint holds to avoid unexpected surprises.
25262
25263    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
25264    enforce these sanity checks.  */
25265
25266 static inline int
25267 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
25268                               enum machine_mode mode, int strict)
25269 {
25270   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
25271       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
25272       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
25273       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
25274       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
25275       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
25276     {
25277       gcc_assert (!strict);
25278       return true;
25279     }
25280
25281   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
25282     return true;
25283
25284   /* ??? This is a lie.  We do have moves between mmx/general, and for
25285      mmx/sse2.  But by saying we need secondary memory we discourage the
25286      register allocator from using the mmx registers unless needed.  */
25287   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
25288     return true;
25289
25290   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
25291     {
25292       /* SSE1 doesn't have any direct moves from other classes.  */
25293       if (!TARGET_SSE2)
25294         return true;
25295
25296       /* If the target says that inter-unit moves are more expensive
25297          than moving through memory, then don't generate them.  */
25298       if (!TARGET_INTER_UNIT_MOVES)
25299         return true;
25300
25301       /* Between SSE and general, we have moves no larger than word size.  */
25302       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
25303         return true;
25304     }
25305
25306   return false;
25307 }
25308
25309 int
25310 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
25311                               enum machine_mode mode, int strict)
25312 {
25313   return inline_secondary_memory_needed (class1, class2, mode, strict);
25314 }
25315
25316 /* Return true if the registers in CLASS cannot represent the change from
25317    modes FROM to TO.  */
25318
25319 bool
25320 ix86_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
25321                                enum reg_class regclass)
25322 {
25323   if (from == to)
25324     return false;
25325
25326   /* x87 registers can't do subreg at all, as all values are reformatted
25327      to extended precision.  */
25328   if (MAYBE_FLOAT_CLASS_P (regclass))
25329     return true;
25330
25331   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
25332     {
25333       /* Vector registers do not support QI or HImode loads.  If we don't
25334          disallow a change to these modes, reload will assume it's ok to
25335          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
25336          the vec_dupv4hi pattern.  */
25337       if (GET_MODE_SIZE (from) < 4)
25338         return true;
25339
25340       /* Vector registers do not support subreg with nonzero offsets, which
25341          are otherwise valid for integer registers.  Since we can't see
25342          whether we have a nonzero offset from here, prohibit all
25343          nonparadoxical subregs changing size.  */
25344       if (GET_MODE_SIZE (to) < GET_MODE_SIZE (from))
25345         return true;
25346     }
25347
25348   return false;
25349 }
25350
25351 /* Return the cost of moving data of mode M between a
25352    register and memory.  A value of 2 is the default; this cost is
25353    relative to those in `REGISTER_MOVE_COST'.
25354
25355    This function is used extensively by register_move_cost that is used to
25356    build tables at startup.  Make it inline in this case.
25357    When IN is 2, return maximum of in and out move cost.
25358
25359    If moving between registers and memory is more expensive than
25360    between two registers, you should define this macro to express the
25361    relative cost.
25362
25363    Model also increased moving costs of QImode registers in non
25364    Q_REGS classes.
25365  */
25366 static inline int
25367 inline_memory_move_cost (enum machine_mode mode, enum reg_class regclass,
25368                          int in)
25369 {
25370   int cost;
25371   if (FLOAT_CLASS_P (regclass))
25372     {
25373       int index;
25374       switch (mode)
25375         {
25376           case SFmode:
25377             index = 0;
25378             break;
25379           case DFmode:
25380             index = 1;
25381             break;
25382           case XFmode:
25383             index = 2;
25384             break;
25385           default:
25386             return 100;
25387         }
25388       if (in == 2)
25389         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
25390       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
25391     }
25392   if (SSE_CLASS_P (regclass))
25393     {
25394       int index;
25395       switch (GET_MODE_SIZE (mode))
25396         {
25397           case 4:
25398             index = 0;
25399             break;
25400           case 8:
25401             index = 1;
25402             break;
25403           case 16:
25404             index = 2;
25405             break;
25406           default:
25407             return 100;
25408         }
25409       if (in == 2)
25410         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
25411       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
25412     }
25413   if (MMX_CLASS_P (regclass))
25414     {
25415       int index;
25416       switch (GET_MODE_SIZE (mode))
25417         {
25418           case 4:
25419             index = 0;
25420             break;
25421           case 8:
25422             index = 1;
25423             break;
25424           default:
25425             return 100;
25426         }
25427       if (in)
25428         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
25429       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
25430     }
25431   switch (GET_MODE_SIZE (mode))
25432     {
25433       case 1:
25434         if (Q_CLASS_P (regclass) || TARGET_64BIT)
25435           {
25436             if (!in)
25437               return ix86_cost->int_store[0];
25438             if (TARGET_PARTIAL_REG_DEPENDENCY
25439                 && optimize_function_for_speed_p (cfun))
25440               cost = ix86_cost->movzbl_load;
25441             else
25442               cost = ix86_cost->int_load[0];
25443             if (in == 2)
25444               return MAX (cost, ix86_cost->int_store[0]);
25445             return cost;
25446           }
25447         else
25448           {
25449            if (in == 2)
25450              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
25451            if (in)
25452              return ix86_cost->movzbl_load;
25453            else
25454              return ix86_cost->int_store[0] + 4;
25455           }
25456         break;
25457       case 2:
25458         if (in == 2)
25459           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
25460         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
25461       default:
25462         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
25463         if (mode == TFmode)
25464           mode = XFmode;
25465         if (in == 2)
25466           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
25467         else if (in)
25468           cost = ix86_cost->int_load[2];
25469         else
25470           cost = ix86_cost->int_store[2];
25471         return (cost * (((int) GET_MODE_SIZE (mode)
25472                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
25473     }
25474 }
25475
25476 int
25477 ix86_memory_move_cost (enum machine_mode mode, enum reg_class regclass, int in)
25478 {
25479   return inline_memory_move_cost (mode, regclass, in);
25480 }
25481
25482
25483 /* Return the cost of moving data from a register in class CLASS1 to
25484    one in class CLASS2.
25485
25486    It is not required that the cost always equal 2 when FROM is the same as TO;
25487    on some machines it is expensive to move between registers if they are not
25488    general registers.  */
25489
25490 int
25491 ix86_register_move_cost (enum machine_mode mode, enum reg_class class1,
25492                          enum reg_class class2)
25493 {
25494   /* In case we require secondary memory, compute cost of the store followed
25495      by load.  In order to avoid bad register allocation choices, we need
25496      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
25497
25498   if (inline_secondary_memory_needed (class1, class2, mode, 0))
25499     {
25500       int cost = 1;
25501
25502       cost += inline_memory_move_cost (mode, class1, 2);
25503       cost += inline_memory_move_cost (mode, class2, 2);
25504
25505       /* In case of copying from general_purpose_register we may emit multiple
25506          stores followed by single load causing memory size mismatch stall.
25507          Count this as arbitrarily high cost of 20.  */
25508       if (CLASS_MAX_NREGS (class1, mode) > CLASS_MAX_NREGS (class2, mode))
25509         cost += 20;
25510
25511       /* In the case of FP/MMX moves, the registers actually overlap, and we
25512          have to switch modes in order to treat them differently.  */
25513       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
25514           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
25515         cost += 20;
25516
25517       return cost;
25518     }
25519
25520   /* Moves between SSE/MMX and integer unit are expensive.  */
25521   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
25522       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
25523
25524     /* ??? By keeping returned value relatively high, we limit the number
25525        of moves between integer and MMX/SSE registers for all targets.
25526        Additionally, high value prevents problem with x86_modes_tieable_p(),
25527        where integer modes in MMX/SSE registers are not tieable
25528        because of missing QImode and HImode moves to, from or between
25529        MMX/SSE registers.  */
25530     return MAX (8, ix86_cost->mmxsse_to_integer);
25531
25532   if (MAYBE_FLOAT_CLASS_P (class1))
25533     return ix86_cost->fp_move;
25534   if (MAYBE_SSE_CLASS_P (class1))
25535     return ix86_cost->sse_move;
25536   if (MAYBE_MMX_CLASS_P (class1))
25537     return ix86_cost->mmx_move;
25538   return 2;
25539 }
25540
25541 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE.  */
25542
25543 bool
25544 ix86_hard_regno_mode_ok (int regno, enum machine_mode mode)
25545 {
25546   /* Flags and only flags can only hold CCmode values.  */
25547   if (CC_REGNO_P (regno))
25548     return GET_MODE_CLASS (mode) == MODE_CC;
25549   if (GET_MODE_CLASS (mode) == MODE_CC
25550       || GET_MODE_CLASS (mode) == MODE_RANDOM
25551       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
25552     return 0;
25553   if (FP_REGNO_P (regno))
25554     return VALID_FP_MODE_P (mode);
25555   if (SSE_REGNO_P (regno))
25556     {
25557       /* We implement the move patterns for all vector modes into and
25558          out of SSE registers, even when no operation instructions
25559          are available.  OImode move is available only when AVX is
25560          enabled.  */
25561       return ((TARGET_AVX && mode == OImode)
25562               || VALID_AVX256_REG_MODE (mode)
25563               || VALID_SSE_REG_MODE (mode)
25564               || VALID_SSE2_REG_MODE (mode)
25565               || VALID_MMX_REG_MODE (mode)
25566               || VALID_MMX_REG_MODE_3DNOW (mode));
25567     }
25568   if (MMX_REGNO_P (regno))
25569     {
25570       /* We implement the move patterns for 3DNOW modes even in MMX mode,
25571          so if the register is available at all, then we can move data of
25572          the given mode into or out of it.  */
25573       return (VALID_MMX_REG_MODE (mode)
25574               || VALID_MMX_REG_MODE_3DNOW (mode));
25575     }
25576
25577   if (mode == QImode)
25578     {
25579       /* Take care for QImode values - they can be in non-QI regs,
25580          but then they do cause partial register stalls.  */
25581       if (regno < 4 || TARGET_64BIT)
25582         return 1;
25583       if (!TARGET_PARTIAL_REG_STALL)
25584         return 1;
25585       return reload_in_progress || reload_completed;
25586     }
25587   /* We handle both integer and floats in the general purpose registers.  */
25588   else if (VALID_INT_MODE_P (mode))
25589     return 1;
25590   else if (VALID_FP_MODE_P (mode))
25591     return 1;
25592   else if (VALID_DFP_MODE_P (mode))
25593     return 1;
25594   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
25595      on to use that value in smaller contexts, this can easily force a
25596      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
25597      supporting DImode, allow it.  */
25598   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
25599     return 1;
25600
25601   return 0;
25602 }
25603
25604 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
25605    tieable integer mode.  */
25606
25607 static bool
25608 ix86_tieable_integer_mode_p (enum machine_mode mode)
25609 {
25610   switch (mode)
25611     {
25612     case HImode:
25613     case SImode:
25614       return true;
25615
25616     case QImode:
25617       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
25618
25619     case DImode:
25620       return TARGET_64BIT;
25621
25622     default:
25623       return false;
25624     }
25625 }
25626
25627 /* Return true if MODE1 is accessible in a register that can hold MODE2
25628    without copying.  That is, all register classes that can hold MODE2
25629    can also hold MODE1.  */
25630
25631 bool
25632 ix86_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
25633 {
25634   if (mode1 == mode2)
25635     return true;
25636
25637   if (ix86_tieable_integer_mode_p (mode1)
25638       && ix86_tieable_integer_mode_p (mode2))
25639     return true;
25640
25641   /* MODE2 being XFmode implies fp stack or general regs, which means we
25642      can tie any smaller floating point modes to it.  Note that we do not
25643      tie this with TFmode.  */
25644   if (mode2 == XFmode)
25645     return mode1 == SFmode || mode1 == DFmode;
25646
25647   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
25648      that we can tie it with SFmode.  */
25649   if (mode2 == DFmode)
25650     return mode1 == SFmode;
25651
25652   /* If MODE2 is only appropriate for an SSE register, then tie with
25653      any other mode acceptable to SSE registers.  */
25654   if (GET_MODE_SIZE (mode2) == 16
25655       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
25656     return (GET_MODE_SIZE (mode1) == 16
25657             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
25658
25659   /* If MODE2 is appropriate for an MMX register, then tie
25660      with any other mode acceptable to MMX registers.  */
25661   if (GET_MODE_SIZE (mode2) == 8
25662       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
25663     return (GET_MODE_SIZE (mode1) == 8
25664             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
25665
25666   return false;
25667 }
25668
25669 /* Compute a (partial) cost for rtx X.  Return true if the complete
25670    cost has been computed, and false if subexpressions should be
25671    scanned.  In either case, *TOTAL contains the cost result.  */
25672
25673 static bool
25674 ix86_rtx_costs (rtx x, int code, int outer_code_i, int *total, bool speed)
25675 {
25676   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
25677   enum machine_mode mode = GET_MODE (x);
25678   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
25679
25680   switch (code)
25681     {
25682     case CONST_INT:
25683     case CONST:
25684     case LABEL_REF:
25685     case SYMBOL_REF:
25686       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
25687         *total = 3;
25688       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
25689         *total = 2;
25690       else if (flag_pic && SYMBOLIC_CONST (x)
25691                && (!TARGET_64BIT
25692                    || (!GET_CODE (x) != LABEL_REF
25693                        && (GET_CODE (x) != SYMBOL_REF
25694                            || !SYMBOL_REF_LOCAL_P (x)))))
25695         *total = 1;
25696       else
25697         *total = 0;
25698       return true;
25699
25700     case CONST_DOUBLE:
25701       if (mode == VOIDmode)
25702         *total = 0;
25703       else
25704         switch (standard_80387_constant_p (x))
25705           {
25706           case 1: /* 0.0 */
25707             *total = 1;
25708             break;
25709           default: /* Other constants */
25710             *total = 2;
25711             break;
25712           case 0:
25713           case -1:
25714             /* Start with (MEM (SYMBOL_REF)), since that's where
25715                it'll probably end up.  Add a penalty for size.  */
25716             *total = (COSTS_N_INSNS (1)
25717                       + (flag_pic != 0 && !TARGET_64BIT)
25718                       + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
25719             break;
25720           }
25721       return true;
25722
25723     case ZERO_EXTEND:
25724       /* The zero extensions is often completely free on x86_64, so make
25725          it as cheap as possible.  */
25726       if (TARGET_64BIT && mode == DImode
25727           && GET_MODE (XEXP (x, 0)) == SImode)
25728         *total = 1;
25729       else if (TARGET_ZERO_EXTEND_WITH_AND)
25730         *total = cost->add;
25731       else
25732         *total = cost->movzx;
25733       return false;
25734
25735     case SIGN_EXTEND:
25736       *total = cost->movsx;
25737       return false;
25738
25739     case ASHIFT:
25740       if (CONST_INT_P (XEXP (x, 1))
25741           && (GET_MODE (XEXP (x, 0)) != DImode || TARGET_64BIT))
25742         {
25743           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
25744           if (value == 1)
25745             {
25746               *total = cost->add;
25747               return false;
25748             }
25749           if ((value == 2 || value == 3)
25750               && cost->lea <= cost->shift_const)
25751             {
25752               *total = cost->lea;
25753               return false;
25754             }
25755         }
25756       /* FALLTHRU */
25757
25758     case ROTATE:
25759     case ASHIFTRT:
25760     case LSHIFTRT:
25761     case ROTATERT:
25762       if (!TARGET_64BIT && GET_MODE (XEXP (x, 0)) == DImode)
25763         {
25764           if (CONST_INT_P (XEXP (x, 1)))
25765             {
25766               if (INTVAL (XEXP (x, 1)) > 32)
25767                 *total = cost->shift_const + COSTS_N_INSNS (2);
25768               else
25769                 *total = cost->shift_const * 2;
25770             }
25771           else
25772             {
25773               if (GET_CODE (XEXP (x, 1)) == AND)
25774                 *total = cost->shift_var * 2;
25775               else
25776                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
25777             }
25778         }
25779       else
25780         {
25781           if (CONST_INT_P (XEXP (x, 1)))
25782             *total = cost->shift_const;
25783           else
25784             *total = cost->shift_var;
25785         }
25786       return false;
25787
25788     case MULT:
25789       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25790         {
25791           /* ??? SSE scalar cost should be used here.  */
25792           *total = cost->fmul;
25793           return false;
25794         }
25795       else if (X87_FLOAT_MODE_P (mode))
25796         {
25797           *total = cost->fmul;
25798           return false;
25799         }
25800       else if (FLOAT_MODE_P (mode))
25801         {
25802           /* ??? SSE vector cost should be used here.  */
25803           *total = cost->fmul;
25804           return false;
25805         }
25806       else
25807         {
25808           rtx op0 = XEXP (x, 0);
25809           rtx op1 = XEXP (x, 1);
25810           int nbits;
25811           if (CONST_INT_P (XEXP (x, 1)))
25812             {
25813               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
25814               for (nbits = 0; value != 0; value &= value - 1)
25815                 nbits++;
25816             }
25817           else
25818             /* This is arbitrary.  */
25819             nbits = 7;
25820
25821           /* Compute costs correctly for widening multiplication.  */
25822           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
25823               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
25824                  == GET_MODE_SIZE (mode))
25825             {
25826               int is_mulwiden = 0;
25827               enum machine_mode inner_mode = GET_MODE (op0);
25828
25829               if (GET_CODE (op0) == GET_CODE (op1))
25830                 is_mulwiden = 1, op1 = XEXP (op1, 0);
25831               else if (CONST_INT_P (op1))
25832                 {
25833                   if (GET_CODE (op0) == SIGN_EXTEND)
25834                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
25835                                   == INTVAL (op1);
25836                   else
25837                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
25838                 }
25839
25840               if (is_mulwiden)
25841                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
25842             }
25843
25844           *total = (cost->mult_init[MODE_INDEX (mode)]
25845                     + nbits * cost->mult_bit
25846                     + rtx_cost (op0, outer_code, speed) + rtx_cost (op1, outer_code, speed));
25847
25848           return true;
25849         }
25850
25851     case DIV:
25852     case UDIV:
25853     case MOD:
25854     case UMOD:
25855       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25856         /* ??? SSE cost should be used here.  */
25857         *total = cost->fdiv;
25858       else if (X87_FLOAT_MODE_P (mode))
25859         *total = cost->fdiv;
25860       else if (FLOAT_MODE_P (mode))
25861         /* ??? SSE vector cost should be used here.  */
25862         *total = cost->fdiv;
25863       else
25864         *total = cost->divide[MODE_INDEX (mode)];
25865       return false;
25866
25867     case PLUS:
25868       if (GET_MODE_CLASS (mode) == MODE_INT
25869                && GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (Pmode))
25870         {
25871           if (GET_CODE (XEXP (x, 0)) == PLUS
25872               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
25873               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
25874               && CONSTANT_P (XEXP (x, 1)))
25875             {
25876               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
25877               if (val == 2 || val == 4 || val == 8)
25878                 {
25879                   *total = cost->lea;
25880                   *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
25881                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
25882                                       outer_code, speed);
25883                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25884                   return true;
25885                 }
25886             }
25887           else if (GET_CODE (XEXP (x, 0)) == MULT
25888                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
25889             {
25890               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
25891               if (val == 2 || val == 4 || val == 8)
25892                 {
25893                   *total = cost->lea;
25894                   *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
25895                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25896                   return true;
25897                 }
25898             }
25899           else if (GET_CODE (XEXP (x, 0)) == PLUS)
25900             {
25901               *total = cost->lea;
25902               *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
25903               *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
25904               *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25905               return true;
25906             }
25907         }
25908       /* FALLTHRU */
25909
25910     case MINUS:
25911       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25912         {
25913           /* ??? SSE cost should be used here.  */
25914           *total = cost->fadd;
25915           return false;
25916         }
25917       else if (X87_FLOAT_MODE_P (mode))
25918         {
25919           *total = cost->fadd;
25920           return false;
25921         }
25922       else if (FLOAT_MODE_P (mode))
25923         {
25924           /* ??? SSE vector cost should be used here.  */
25925           *total = cost->fadd;
25926           return false;
25927         }
25928       /* FALLTHRU */
25929
25930     case AND:
25931     case IOR:
25932     case XOR:
25933       if (!TARGET_64BIT && mode == DImode)
25934         {
25935           *total = (cost->add * 2
25936                     + (rtx_cost (XEXP (x, 0), outer_code, speed)
25937                        << (GET_MODE (XEXP (x, 0)) != DImode))
25938                     + (rtx_cost (XEXP (x, 1), outer_code, speed)
25939                        << (GET_MODE (XEXP (x, 1)) != DImode)));
25940           return true;
25941         }
25942       /* FALLTHRU */
25943
25944     case NEG:
25945       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25946         {
25947           /* ??? SSE cost should be used here.  */
25948           *total = cost->fchs;
25949           return false;
25950         }
25951       else if (X87_FLOAT_MODE_P (mode))
25952         {
25953           *total = cost->fchs;
25954           return false;
25955         }
25956       else if (FLOAT_MODE_P (mode))
25957         {
25958           /* ??? SSE vector cost should be used here.  */
25959           *total = cost->fchs;
25960           return false;
25961         }
25962       /* FALLTHRU */
25963
25964     case NOT:
25965       if (!TARGET_64BIT && mode == DImode)
25966         *total = cost->add * 2;
25967       else
25968         *total = cost->add;
25969       return false;
25970
25971     case COMPARE:
25972       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
25973           && XEXP (XEXP (x, 0), 1) == const1_rtx
25974           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
25975           && XEXP (x, 1) == const0_rtx)
25976         {
25977           /* This kind of construct is implemented using test[bwl].
25978              Treat it as if we had an AND.  */
25979           *total = (cost->add
25980                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed)
25981                     + rtx_cost (const1_rtx, outer_code, speed));
25982           return true;
25983         }
25984       return false;
25985
25986     case FLOAT_EXTEND:
25987       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
25988         *total = 0;
25989       return false;
25990
25991     case ABS:
25992       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25993         /* ??? SSE cost should be used here.  */
25994         *total = cost->fabs;
25995       else if (X87_FLOAT_MODE_P (mode))
25996         *total = cost->fabs;
25997       else if (FLOAT_MODE_P (mode))
25998         /* ??? SSE vector cost should be used here.  */
25999         *total = cost->fabs;
26000       return false;
26001
26002     case SQRT:
26003       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26004         /* ??? SSE cost should be used here.  */
26005         *total = cost->fsqrt;
26006       else if (X87_FLOAT_MODE_P (mode))
26007         *total = cost->fsqrt;
26008       else if (FLOAT_MODE_P (mode))
26009         /* ??? SSE vector cost should be used here.  */
26010         *total = cost->fsqrt;
26011       return false;
26012
26013     case UNSPEC:
26014       if (XINT (x, 1) == UNSPEC_TP)
26015         *total = 0;
26016       return false;
26017
26018     default:
26019       return false;
26020     }
26021 }
26022
26023 #if TARGET_MACHO
26024
26025 static int current_machopic_label_num;
26026
26027 /* Given a symbol name and its associated stub, write out the
26028    definition of the stub.  */
26029
26030 void
26031 machopic_output_stub (FILE *file, const char *symb, const char *stub)
26032 {
26033   unsigned int length;
26034   char *binder_name, *symbol_name, lazy_ptr_name[32];
26035   int label = ++current_machopic_label_num;
26036
26037   /* For 64-bit we shouldn't get here.  */
26038   gcc_assert (!TARGET_64BIT);
26039
26040   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
26041   symb = (*targetm.strip_name_encoding) (symb);
26042
26043   length = strlen (stub);
26044   binder_name = XALLOCAVEC (char, length + 32);
26045   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
26046
26047   length = strlen (symb);
26048   symbol_name = XALLOCAVEC (char, length + 32);
26049   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
26050
26051   sprintf (lazy_ptr_name, "L%d$lz", label);
26052
26053   if (MACHOPIC_PURE)
26054     switch_to_section (darwin_sections[machopic_picsymbol_stub_section]);
26055   else
26056     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
26057
26058   fprintf (file, "%s:\n", stub);
26059   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
26060
26061   if (MACHOPIC_PURE)
26062     {
26063       fprintf (file, "\tcall\tLPC$%d\nLPC$%d:\tpopl\t%%eax\n", label, label);
26064       fprintf (file, "\tmovl\t%s-LPC$%d(%%eax),%%edx\n", lazy_ptr_name, label);
26065       fprintf (file, "\tjmp\t*%%edx\n");
26066     }
26067   else
26068     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
26069
26070   fprintf (file, "%s:\n", binder_name);
26071
26072   if (MACHOPIC_PURE)
26073     {
26074       fprintf (file, "\tlea\t%s-LPC$%d(%%eax),%%eax\n", lazy_ptr_name, label);
26075       fprintf (file, "\tpushl\t%%eax\n");
26076     }
26077   else
26078     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
26079
26080   fprintf (file, "\tjmp\tdyld_stub_binding_helper\n");
26081
26082   switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
26083   fprintf (file, "%s:\n", lazy_ptr_name);
26084   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
26085   fprintf (file, "\t.long %s\n", binder_name);
26086 }
26087
26088 void
26089 darwin_x86_file_end (void)
26090 {
26091   darwin_file_end ();
26092   ix86_file_end ();
26093 }
26094 #endif /* TARGET_MACHO */
26095
26096 /* Order the registers for register allocator.  */
26097
26098 void
26099 x86_order_regs_for_local_alloc (void)
26100 {
26101    int pos = 0;
26102    int i;
26103
26104    /* First allocate the local general purpose registers.  */
26105    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
26106      if (GENERAL_REGNO_P (i) && call_used_regs[i])
26107         reg_alloc_order [pos++] = i;
26108
26109    /* Global general purpose registers.  */
26110    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
26111      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
26112         reg_alloc_order [pos++] = i;
26113
26114    /* x87 registers come first in case we are doing FP math
26115       using them.  */
26116    if (!TARGET_SSE_MATH)
26117      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
26118        reg_alloc_order [pos++] = i;
26119
26120    /* SSE registers.  */
26121    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
26122      reg_alloc_order [pos++] = i;
26123    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
26124      reg_alloc_order [pos++] = i;
26125
26126    /* x87 registers.  */
26127    if (TARGET_SSE_MATH)
26128      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
26129        reg_alloc_order [pos++] = i;
26130
26131    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
26132      reg_alloc_order [pos++] = i;
26133
26134    /* Initialize the rest of array as we do not allocate some registers
26135       at all.  */
26136    while (pos < FIRST_PSEUDO_REGISTER)
26137      reg_alloc_order [pos++] = 0;
26138 }
26139
26140 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
26141    struct attribute_spec.handler.  */
26142 static tree
26143 ix86_handle_abi_attribute (tree *node, tree name,
26144                               tree args ATTRIBUTE_UNUSED,
26145                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
26146 {
26147   if (TREE_CODE (*node) != FUNCTION_TYPE
26148       && TREE_CODE (*node) != METHOD_TYPE
26149       && TREE_CODE (*node) != FIELD_DECL
26150       && TREE_CODE (*node) != TYPE_DECL)
26151     {
26152       warning (OPT_Wattributes, "%qs attribute only applies to functions",
26153                IDENTIFIER_POINTER (name));
26154       *no_add_attrs = true;
26155       return NULL_TREE;
26156     }
26157   if (!TARGET_64BIT)
26158     {
26159       warning (OPT_Wattributes, "%qs attribute only available for 64-bit",
26160                IDENTIFIER_POINTER (name));
26161       *no_add_attrs = true;
26162       return NULL_TREE;
26163     }
26164
26165   /* Can combine regparm with all attributes but fastcall.  */
26166   if (is_attribute_p ("ms_abi", name))
26167     {
26168       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
26169         {
26170           error ("ms_abi and sysv_abi attributes are not compatible");
26171         }
26172
26173       return NULL_TREE;
26174     }
26175   else if (is_attribute_p ("sysv_abi", name))
26176     {
26177       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
26178         {
26179           error ("ms_abi and sysv_abi attributes are not compatible");
26180         }
26181
26182       return NULL_TREE;
26183     }
26184
26185   return NULL_TREE;
26186 }
26187
26188 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
26189    struct attribute_spec.handler.  */
26190 static tree
26191 ix86_handle_struct_attribute (tree *node, tree name,
26192                               tree args ATTRIBUTE_UNUSED,
26193                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
26194 {
26195   tree *type = NULL;
26196   if (DECL_P (*node))
26197     {
26198       if (TREE_CODE (*node) == TYPE_DECL)
26199         type = &TREE_TYPE (*node);
26200     }
26201   else
26202     type = node;
26203
26204   if (!(type && (TREE_CODE (*type) == RECORD_TYPE
26205                  || TREE_CODE (*type) == UNION_TYPE)))
26206     {
26207       warning (OPT_Wattributes, "%qs attribute ignored",
26208                IDENTIFIER_POINTER (name));
26209       *no_add_attrs = true;
26210     }
26211
26212   else if ((is_attribute_p ("ms_struct", name)
26213             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
26214            || ((is_attribute_p ("gcc_struct", name)
26215                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
26216     {
26217       warning (OPT_Wattributes, "%qs incompatible attribute ignored",
26218                IDENTIFIER_POINTER (name));
26219       *no_add_attrs = true;
26220     }
26221
26222   return NULL_TREE;
26223 }
26224
26225 static bool
26226 ix86_ms_bitfield_layout_p (const_tree record_type)
26227 {
26228   return (TARGET_MS_BITFIELD_LAYOUT &&
26229           !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
26230     || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
26231 }
26232
26233 /* Returns an expression indicating where the this parameter is
26234    located on entry to the FUNCTION.  */
26235
26236 static rtx
26237 x86_this_parameter (tree function)
26238 {
26239   tree type = TREE_TYPE (function);
26240   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
26241   int nregs;
26242
26243   if (TARGET_64BIT)
26244     {
26245       const int *parm_regs;
26246
26247       if (ix86_function_type_abi (type) == MS_ABI)
26248         parm_regs = x86_64_ms_abi_int_parameter_registers;
26249       else
26250         parm_regs = x86_64_int_parameter_registers;
26251       return gen_rtx_REG (DImode, parm_regs[aggr]);
26252     }
26253
26254   nregs = ix86_function_regparm (type, function);
26255
26256   if (nregs > 0 && !stdarg_p (type))
26257     {
26258       int regno;
26259
26260       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
26261         regno = aggr ? DX_REG : CX_REG;
26262       else
26263         {
26264           regno = AX_REG;
26265           if (aggr)
26266             {
26267               regno = DX_REG;
26268               if (nregs == 1)
26269                 return gen_rtx_MEM (SImode,
26270                                     plus_constant (stack_pointer_rtx, 4));
26271             }
26272         }
26273       return gen_rtx_REG (SImode, regno);
26274     }
26275
26276   return gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx, aggr ? 8 : 4));
26277 }
26278
26279 /* Determine whether x86_output_mi_thunk can succeed.  */
26280
26281 static bool
26282 x86_can_output_mi_thunk (const_tree thunk ATTRIBUTE_UNUSED,
26283                          HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
26284                          HOST_WIDE_INT vcall_offset, const_tree function)
26285 {
26286   /* 64-bit can handle anything.  */
26287   if (TARGET_64BIT)
26288     return true;
26289
26290   /* For 32-bit, everything's fine if we have one free register.  */
26291   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
26292     return true;
26293
26294   /* Need a free register for vcall_offset.  */
26295   if (vcall_offset)
26296     return false;
26297
26298   /* Need a free register for GOT references.  */
26299   if (flag_pic && !(*targetm.binds_local_p) (function))
26300     return false;
26301
26302   /* Otherwise ok.  */
26303   return true;
26304 }
26305
26306 /* Output the assembler code for a thunk function.  THUNK_DECL is the
26307    declaration for the thunk function itself, FUNCTION is the decl for
26308    the target function.  DELTA is an immediate constant offset to be
26309    added to THIS.  If VCALL_OFFSET is nonzero, the word at
26310    *(*this + vcall_offset) should be added to THIS.  */
26311
26312 static void
26313 x86_output_mi_thunk (FILE *file ATTRIBUTE_UNUSED,
26314                      tree thunk ATTRIBUTE_UNUSED, HOST_WIDE_INT delta,
26315                      HOST_WIDE_INT vcall_offset, tree function)
26316 {
26317   rtx xops[3];
26318   rtx this_param = x86_this_parameter (function);
26319   rtx this_reg, tmp;
26320
26321   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
26322      pull it in now and let DELTA benefit.  */
26323   if (REG_P (this_param))
26324     this_reg = this_param;
26325   else if (vcall_offset)
26326     {
26327       /* Put the this parameter into %eax.  */
26328       xops[0] = this_param;
26329       xops[1] = this_reg = gen_rtx_REG (Pmode, AX_REG);
26330       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26331     }
26332   else
26333     this_reg = NULL_RTX;
26334
26335   /* Adjust the this parameter by a fixed constant.  */
26336   if (delta)
26337     {
26338       xops[0] = GEN_INT (delta);
26339       xops[1] = this_reg ? this_reg : this_param;
26340       if (TARGET_64BIT)
26341         {
26342           if (!x86_64_general_operand (xops[0], DImode))
26343             {
26344               tmp = gen_rtx_REG (DImode, R10_REG);
26345               xops[1] = tmp;
26346               output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", xops);
26347               xops[0] = tmp;
26348               xops[1] = this_param;
26349             }
26350           output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
26351         }
26352       else
26353         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
26354     }
26355
26356   /* Adjust the this parameter by a value stored in the vtable.  */
26357   if (vcall_offset)
26358     {
26359       if (TARGET_64BIT)
26360         tmp = gen_rtx_REG (DImode, R10_REG);
26361       else
26362         {
26363           int tmp_regno = CX_REG;
26364           if (lookup_attribute ("fastcall",
26365                                 TYPE_ATTRIBUTES (TREE_TYPE (function))))
26366             tmp_regno = AX_REG;
26367           tmp = gen_rtx_REG (SImode, tmp_regno);
26368         }
26369
26370       xops[0] = gen_rtx_MEM (Pmode, this_reg);
26371       xops[1] = tmp;
26372       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26373
26374       /* Adjust the this parameter.  */
26375       xops[0] = gen_rtx_MEM (Pmode, plus_constant (tmp, vcall_offset));
26376       if (TARGET_64BIT && !memory_operand (xops[0], Pmode))
26377         {
26378           rtx tmp2 = gen_rtx_REG (DImode, R11_REG);
26379           xops[0] = GEN_INT (vcall_offset);
26380           xops[1] = tmp2;
26381           output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
26382           xops[0] = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, tmp, tmp2));
26383         }
26384       xops[1] = this_reg;
26385       output_asm_insn ("add%z1\t{%0, %1|%1, %0}", xops);
26386     }
26387
26388   /* If necessary, drop THIS back to its stack slot.  */
26389   if (this_reg && this_reg != this_param)
26390     {
26391       xops[0] = this_reg;
26392       xops[1] = this_param;
26393       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26394     }
26395
26396   xops[0] = XEXP (DECL_RTL (function), 0);
26397   if (TARGET_64BIT)
26398     {
26399       if (!flag_pic || (*targetm.binds_local_p) (function))
26400         output_asm_insn ("jmp\t%P0", xops);
26401       /* All thunks should be in the same object as their target,
26402          and thus binds_local_p should be true.  */
26403       else if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
26404         gcc_unreachable ();
26405       else
26406         {
26407           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xops[0]), UNSPEC_GOTPCREL);
26408           tmp = gen_rtx_CONST (Pmode, tmp);
26409           tmp = gen_rtx_MEM (QImode, tmp);
26410           xops[0] = tmp;
26411           output_asm_insn ("jmp\t%A0", xops);
26412         }
26413     }
26414   else
26415     {
26416       if (!flag_pic || (*targetm.binds_local_p) (function))
26417         output_asm_insn ("jmp\t%P0", xops);
26418       else
26419 #if TARGET_MACHO
26420         if (TARGET_MACHO)
26421           {
26422             rtx sym_ref = XEXP (DECL_RTL (function), 0);
26423             tmp = (gen_rtx_SYMBOL_REF
26424                    (Pmode,
26425                     machopic_indirection_name (sym_ref, /*stub_p=*/true)));
26426             tmp = gen_rtx_MEM (QImode, tmp);
26427             xops[0] = tmp;
26428             output_asm_insn ("jmp\t%0", xops);
26429           }
26430         else
26431 #endif /* TARGET_MACHO */
26432         {
26433           tmp = gen_rtx_REG (SImode, CX_REG);
26434           output_set_got (tmp, NULL_RTX);
26435
26436           xops[1] = tmp;
26437           output_asm_insn ("mov{l}\t{%0@GOT(%1), %1|%1, %0@GOT[%1]}", xops);
26438           output_asm_insn ("jmp\t{*}%1", xops);
26439         }
26440     }
26441 }
26442
26443 static void
26444 x86_file_start (void)
26445 {
26446   default_file_start ();
26447 #if TARGET_MACHO
26448   darwin_file_start ();
26449 #endif
26450   if (X86_FILE_START_VERSION_DIRECTIVE)
26451     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
26452   if (X86_FILE_START_FLTUSED)
26453     fputs ("\t.global\t__fltused\n", asm_out_file);
26454   if (ix86_asm_dialect == ASM_INTEL)
26455     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
26456 }
26457
26458 int
26459 x86_field_alignment (tree field, int computed)
26460 {
26461   enum machine_mode mode;
26462   tree type = TREE_TYPE (field);
26463
26464   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
26465     return computed;
26466   mode = TYPE_MODE (strip_array_types (type));
26467   if (mode == DFmode || mode == DCmode
26468       || GET_MODE_CLASS (mode) == MODE_INT
26469       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
26470     return MIN (32, computed);
26471   return computed;
26472 }
26473
26474 /* Output assembler code to FILE to increment profiler label # LABELNO
26475    for profiling a function entry.  */
26476 void
26477 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
26478 {
26479   if (TARGET_64BIT)
26480     {
26481 #ifndef NO_PROFILE_COUNTERS
26482       fprintf (file, "\tleaq\t%sP%d@(%%rip),%%r11\n", LPREFIX, labelno);
26483 #endif
26484
26485       if (DEFAULT_ABI == SYSV_ABI && flag_pic)
26486         fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", MCOUNT_NAME);
26487       else
26488         fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26489     }
26490   else if (flag_pic)
26491     {
26492 #ifndef NO_PROFILE_COUNTERS
26493       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%%s\n",
26494                LPREFIX, labelno, PROFILE_COUNT_REGISTER);
26495 #endif
26496       fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", MCOUNT_NAME);
26497     }
26498   else
26499     {
26500 #ifndef NO_PROFILE_COUNTERS
26501       fprintf (file, "\tmovl\t$%sP%d,%%%s\n", LPREFIX, labelno,
26502                PROFILE_COUNT_REGISTER);
26503 #endif
26504       fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26505     }
26506 }
26507
26508 /* We don't have exact information about the insn sizes, but we may assume
26509    quite safely that we are informed about all 1 byte insns and memory
26510    address sizes.  This is enough to eliminate unnecessary padding in
26511    99% of cases.  */
26512
26513 static int
26514 min_insn_size (rtx insn)
26515 {
26516   int l = 0;
26517
26518   if (!INSN_P (insn) || !active_insn_p (insn))
26519     return 0;
26520
26521   /* Discard alignments we've emit and jump instructions.  */
26522   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
26523       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
26524     return 0;
26525   if (JUMP_P (insn)
26526       && (GET_CODE (PATTERN (insn)) == ADDR_VEC
26527           || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
26528     return 0;
26529
26530   /* Important case - calls are always 5 bytes.
26531      It is common to have many calls in the row.  */
26532   if (CALL_P (insn)
26533       && symbolic_reference_mentioned_p (PATTERN (insn))
26534       && !SIBLING_CALL_P (insn))
26535     return 5;
26536   if (get_attr_length (insn) <= 1)
26537     return 1;
26538
26539   /* For normal instructions we may rely on the sizes of addresses
26540      and the presence of symbol to require 4 bytes of encoding.
26541      This is not the case for jumps where references are PC relative.  */
26542   if (!JUMP_P (insn))
26543     {
26544       l = get_attr_length_address (insn);
26545       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
26546         l = 4;
26547     }
26548   if (l)
26549     return 1+l;
26550   else
26551     return 2;
26552 }
26553
26554 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
26555    window.  */
26556
26557 static void
26558 ix86_avoid_jump_misspredicts (void)
26559 {
26560   rtx insn, start = get_insns ();
26561   int nbytes = 0, njumps = 0;
26562   int isjump = 0;
26563
26564   /* Look for all minimal intervals of instructions containing 4 jumps.
26565      The intervals are bounded by START and INSN.  NBYTES is the total
26566      size of instructions in the interval including INSN and not including
26567      START.  When the NBYTES is smaller than 16 bytes, it is possible
26568      that the end of START and INSN ends up in the same 16byte page.
26569
26570      The smallest offset in the page INSN can start is the case where START
26571      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
26572      We add p2align to 16byte window with maxskip 17 - NBYTES + sizeof (INSN).
26573      */
26574   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
26575     {
26576
26577       nbytes += min_insn_size (insn);
26578       if (dump_file)
26579         fprintf(dump_file, "Insn %i estimated to %i bytes\n",
26580                 INSN_UID (insn), min_insn_size (insn));
26581       if ((JUMP_P (insn)
26582            && GET_CODE (PATTERN (insn)) != ADDR_VEC
26583            && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
26584           || CALL_P (insn))
26585         njumps++;
26586       else
26587         continue;
26588
26589       while (njumps > 3)
26590         {
26591           start = NEXT_INSN (start);
26592           if ((JUMP_P (start)
26593                && GET_CODE (PATTERN (start)) != ADDR_VEC
26594                && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
26595               || CALL_P (start))
26596             njumps--, isjump = 1;
26597           else
26598             isjump = 0;
26599           nbytes -= min_insn_size (start);
26600         }
26601       gcc_assert (njumps >= 0);
26602       if (dump_file)
26603         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
26604                 INSN_UID (start), INSN_UID (insn), nbytes);
26605
26606       if (njumps == 3 && isjump && nbytes < 16)
26607         {
26608           int padsize = 15 - nbytes + min_insn_size (insn);
26609
26610           if (dump_file)
26611             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
26612                      INSN_UID (insn), padsize);
26613           emit_insn_before (gen_align (GEN_INT (padsize)), insn);
26614         }
26615     }
26616 }
26617
26618 /* AMD Athlon works faster
26619    when RET is not destination of conditional jump or directly preceded
26620    by other jump instruction.  We avoid the penalty by inserting NOP just
26621    before the RET instructions in such cases.  */
26622 static void
26623 ix86_pad_returns (void)
26624 {
26625   edge e;
26626   edge_iterator ei;
26627
26628   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
26629     {
26630       basic_block bb = e->src;
26631       rtx ret = BB_END (bb);
26632       rtx prev;
26633       bool replace = false;
26634
26635       if (!JUMP_P (ret) || GET_CODE (PATTERN (ret)) != RETURN
26636           || optimize_bb_for_size_p (bb))
26637         continue;
26638       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
26639         if (active_insn_p (prev) || LABEL_P (prev))
26640           break;
26641       if (prev && LABEL_P (prev))
26642         {
26643           edge e;
26644           edge_iterator ei;
26645
26646           FOR_EACH_EDGE (e, ei, bb->preds)
26647             if (EDGE_FREQUENCY (e) && e->src->index >= 0
26648                 && !(e->flags & EDGE_FALLTHRU))
26649               replace = true;
26650         }
26651       if (!replace)
26652         {
26653           prev = prev_active_insn (ret);
26654           if (prev
26655               && ((JUMP_P (prev) && any_condjump_p (prev))
26656                   || CALL_P (prev)))
26657             replace = true;
26658           /* Empty functions get branch mispredict even when the jump destination
26659              is not visible to us.  */
26660           if (!prev && cfun->function_frequency > FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
26661             replace = true;
26662         }
26663       if (replace)
26664         {
26665           emit_insn_before (gen_return_internal_long (), ret);
26666           delete_insn (ret);
26667         }
26668     }
26669 }
26670
26671 /* Implement machine specific optimizations.  We implement padding of returns
26672    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
26673 static void
26674 ix86_reorg (void)
26675 {
26676   if (TARGET_PAD_RETURNS && optimize
26677       && optimize_function_for_speed_p (cfun))
26678     ix86_pad_returns ();
26679   if (TARGET_FOUR_JUMP_LIMIT && optimize
26680       && optimize_function_for_speed_p (cfun))
26681     ix86_avoid_jump_misspredicts ();
26682 }
26683
26684 /* Return nonzero when QImode register that must be represented via REX prefix
26685    is used.  */
26686 bool
26687 x86_extended_QIreg_mentioned_p (rtx insn)
26688 {
26689   int i;
26690   extract_insn_cached (insn);
26691   for (i = 0; i < recog_data.n_operands; i++)
26692     if (REG_P (recog_data.operand[i])
26693         && REGNO (recog_data.operand[i]) >= 4)
26694        return true;
26695   return false;
26696 }
26697
26698 /* Return nonzero when P points to register encoded via REX prefix.
26699    Called via for_each_rtx.  */
26700 static int
26701 extended_reg_mentioned_1 (rtx *p, void *data ATTRIBUTE_UNUSED)
26702 {
26703    unsigned int regno;
26704    if (!REG_P (*p))
26705      return 0;
26706    regno = REGNO (*p);
26707    return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
26708 }
26709
26710 /* Return true when INSN mentions register that must be encoded using REX
26711    prefix.  */
26712 bool
26713 x86_extended_reg_mentioned_p (rtx insn)
26714 {
26715   return for_each_rtx (INSN_P (insn) ? &PATTERN (insn) : &insn,
26716                        extended_reg_mentioned_1, NULL);
26717 }
26718
26719 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
26720    optabs would emit if we didn't have TFmode patterns.  */
26721
26722 void
26723 x86_emit_floatuns (rtx operands[2])
26724 {
26725   rtx neglab, donelab, i0, i1, f0, in, out;
26726   enum machine_mode mode, inmode;
26727
26728   inmode = GET_MODE (operands[1]);
26729   gcc_assert (inmode == SImode || inmode == DImode);
26730
26731   out = operands[0];
26732   in = force_reg (inmode, operands[1]);
26733   mode = GET_MODE (out);
26734   neglab = gen_label_rtx ();
26735   donelab = gen_label_rtx ();
26736   f0 = gen_reg_rtx (mode);
26737
26738   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
26739
26740   expand_float (out, in, 0);
26741
26742   emit_jump_insn (gen_jump (donelab));
26743   emit_barrier ();
26744
26745   emit_label (neglab);
26746
26747   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
26748                             1, OPTAB_DIRECT);
26749   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
26750                             1, OPTAB_DIRECT);
26751   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
26752
26753   expand_float (f0, i0, 0);
26754
26755   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
26756
26757   emit_label (donelab);
26758 }
26759 \f
26760 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26761    with all elements equal to VAR.  Return true if successful.  */
26762
26763 static bool
26764 ix86_expand_vector_init_duplicate (bool mmx_ok, enum machine_mode mode,
26765                                    rtx target, rtx val)
26766 {
26767   enum machine_mode hmode, smode, wsmode, wvmode;
26768   rtx x;
26769
26770   switch (mode)
26771     {
26772     case V2SImode:
26773     case V2SFmode:
26774       if (!mmx_ok)
26775         return false;
26776       /* FALLTHRU */
26777
26778     case V2DFmode:
26779     case V2DImode:
26780     case V4SFmode:
26781     case V4SImode:
26782       val = force_reg (GET_MODE_INNER (mode), val);
26783       x = gen_rtx_VEC_DUPLICATE (mode, val);
26784       emit_insn (gen_rtx_SET (VOIDmode, target, x));
26785       return true;
26786
26787     case V4HImode:
26788       if (!mmx_ok)
26789         return false;
26790       if (TARGET_SSE || TARGET_3DNOW_A)
26791         {
26792           val = gen_lowpart (SImode, val);
26793           x = gen_rtx_TRUNCATE (HImode, val);
26794           x = gen_rtx_VEC_DUPLICATE (mode, x);
26795           emit_insn (gen_rtx_SET (VOIDmode, target, x));
26796           return true;
26797         }
26798       else
26799         {
26800           smode = HImode;
26801           wsmode = SImode;
26802           wvmode = V2SImode;
26803           goto widen;
26804         }
26805
26806     case V8QImode:
26807       if (!mmx_ok)
26808         return false;
26809       smode = QImode;
26810       wsmode = HImode;
26811       wvmode = V4HImode;
26812       goto widen;
26813     case V8HImode:
26814       if (TARGET_SSE2)
26815         {
26816           rtx tmp1, tmp2;
26817           /* Extend HImode to SImode using a paradoxical SUBREG.  */
26818           tmp1 = gen_reg_rtx (SImode);
26819           emit_move_insn (tmp1, gen_lowpart (SImode, val));
26820           /* Insert the SImode value as low element of V4SImode vector. */
26821           tmp2 = gen_reg_rtx (V4SImode);
26822           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
26823                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
26824                                     CONST0_RTX (V4SImode),
26825                                     const1_rtx);
26826           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
26827           /* Cast the V4SImode vector back to a V8HImode vector.  */
26828           tmp1 = gen_reg_rtx (V8HImode);
26829           emit_move_insn (tmp1, gen_lowpart (V8HImode, tmp2));
26830           /* Duplicate the low short through the whole low SImode word.  */
26831           emit_insn (gen_sse2_punpcklwd (tmp1, tmp1, tmp1));
26832           /* Cast the V8HImode vector back to a V4SImode vector.  */
26833           tmp2 = gen_reg_rtx (V4SImode);
26834           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
26835           /* Replicate the low element of the V4SImode vector.  */
26836           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
26837           /* Cast the V2SImode back to V8HImode, and store in target.  */
26838           emit_move_insn (target, gen_lowpart (V8HImode, tmp2));
26839           return true;
26840         }
26841       smode = HImode;
26842       wsmode = SImode;
26843       wvmode = V4SImode;
26844       goto widen;
26845     case V16QImode:
26846       if (TARGET_SSE2)
26847         {
26848           rtx tmp1, tmp2;
26849           /* Extend QImode to SImode using a paradoxical SUBREG.  */
26850           tmp1 = gen_reg_rtx (SImode);
26851           emit_move_insn (tmp1, gen_lowpart (SImode, val));
26852           /* Insert the SImode value as low element of V4SImode vector. */
26853           tmp2 = gen_reg_rtx (V4SImode);
26854           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
26855                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
26856                                     CONST0_RTX (V4SImode),
26857                                     const1_rtx);
26858           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
26859           /* Cast the V4SImode vector back to a V16QImode vector.  */
26860           tmp1 = gen_reg_rtx (V16QImode);
26861           emit_move_insn (tmp1, gen_lowpart (V16QImode, tmp2));
26862           /* Duplicate the low byte through the whole low SImode word.  */
26863           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
26864           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
26865           /* Cast the V16QImode vector back to a V4SImode vector.  */
26866           tmp2 = gen_reg_rtx (V4SImode);
26867           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
26868           /* Replicate the low element of the V4SImode vector.  */
26869           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
26870           /* Cast the V2SImode back to V16QImode, and store in target.  */
26871           emit_move_insn (target, gen_lowpart (V16QImode, tmp2));
26872           return true;
26873         }
26874       smode = QImode;
26875       wsmode = HImode;
26876       wvmode = V8HImode;
26877       goto widen;
26878     widen:
26879       /* Replicate the value once into the next wider mode and recurse.  */
26880       val = convert_modes (wsmode, smode, val, true);
26881       x = expand_simple_binop (wsmode, ASHIFT, val,
26882                                GEN_INT (GET_MODE_BITSIZE (smode)),
26883                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
26884       val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
26885
26886       x = gen_reg_rtx (wvmode);
26887       if (!ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val))
26888         gcc_unreachable ();
26889       emit_move_insn (target, gen_lowpart (mode, x));
26890       return true;
26891
26892     case V4DFmode:
26893       hmode = V2DFmode;
26894       goto half;
26895     case V4DImode:
26896       hmode = V2DImode;
26897       goto half;
26898     case V8SFmode:
26899       hmode = V4SFmode;
26900       goto half;
26901     case V8SImode:
26902       hmode = V4SImode;
26903       goto half;
26904     case V16HImode:
26905       hmode = V8HImode;
26906       goto half;
26907     case V32QImode:
26908       hmode = V16QImode;
26909       goto half;
26910 half:
26911       {
26912         rtx tmp = gen_reg_rtx (hmode);
26913         ix86_expand_vector_init_duplicate (mmx_ok, hmode, tmp, val);
26914         emit_insn (gen_rtx_SET (VOIDmode, target,
26915                                 gen_rtx_VEC_CONCAT (mode, tmp, tmp)));
26916       }
26917       return true;
26918
26919     default:
26920       return false;
26921     }
26922 }
26923
26924 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26925    whose ONE_VAR element is VAR, and other elements are zero.  Return true
26926    if successful.  */
26927
26928 static bool
26929 ix86_expand_vector_init_one_nonzero (bool mmx_ok, enum machine_mode mode,
26930                                      rtx target, rtx var, int one_var)
26931 {
26932   enum machine_mode vsimode;
26933   rtx new_target;
26934   rtx x, tmp;
26935   bool use_vector_set = false;
26936
26937   switch (mode)
26938     {
26939     case V2DImode:
26940       /* For SSE4.1, we normally use vector set.  But if the second
26941          element is zero and inter-unit moves are OK, we use movq
26942          instead.  */
26943       use_vector_set = (TARGET_64BIT
26944                         && TARGET_SSE4_1
26945                         && !(TARGET_INTER_UNIT_MOVES
26946                              && one_var == 0));
26947       break;
26948     case V16QImode:
26949     case V4SImode:
26950     case V4SFmode:
26951       use_vector_set = TARGET_SSE4_1;
26952       break;
26953     case V8HImode:
26954       use_vector_set = TARGET_SSE2;
26955       break;
26956     case V4HImode:
26957       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
26958       break;
26959     case V32QImode:
26960     case V16HImode:
26961     case V8SImode:
26962     case V8SFmode:
26963     case V4DImode:
26964     case V4DFmode:
26965       use_vector_set = TARGET_AVX;
26966       break;
26967     default:
26968       break;
26969     }
26970
26971   if (use_vector_set)
26972     {
26973       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
26974       var = force_reg (GET_MODE_INNER (mode), var);
26975       ix86_expand_vector_set (mmx_ok, target, var, one_var);
26976       return true; 
26977     }
26978
26979   switch (mode)
26980     {
26981     case V2SFmode:
26982     case V2SImode:
26983       if (!mmx_ok)
26984         return false;
26985       /* FALLTHRU */
26986
26987     case V2DFmode:
26988     case V2DImode:
26989       if (one_var != 0)
26990         return false;
26991       var = force_reg (GET_MODE_INNER (mode), var);
26992       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
26993       emit_insn (gen_rtx_SET (VOIDmode, target, x));
26994       return true;
26995
26996     case V4SFmode:
26997     case V4SImode:
26998       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
26999         new_target = gen_reg_rtx (mode);
27000       else
27001         new_target = target;
27002       var = force_reg (GET_MODE_INNER (mode), var);
27003       x = gen_rtx_VEC_DUPLICATE (mode, var);
27004       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
27005       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
27006       if (one_var != 0)
27007         {
27008           /* We need to shuffle the value to the correct position, so
27009              create a new pseudo to store the intermediate result.  */
27010
27011           /* With SSE2, we can use the integer shuffle insns.  */
27012           if (mode != V4SFmode && TARGET_SSE2)
27013             {
27014               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
27015                                             GEN_INT (1),
27016                                             GEN_INT (one_var == 1 ? 0 : 1),
27017                                             GEN_INT (one_var == 2 ? 0 : 1),
27018                                             GEN_INT (one_var == 3 ? 0 : 1)));
27019               if (target != new_target)
27020                 emit_move_insn (target, new_target);
27021               return true;
27022             }
27023
27024           /* Otherwise convert the intermediate result to V4SFmode and
27025              use the SSE1 shuffle instructions.  */
27026           if (mode != V4SFmode)
27027             {
27028               tmp = gen_reg_rtx (V4SFmode);
27029               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
27030             }
27031           else
27032             tmp = new_target;
27033
27034           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
27035                                        GEN_INT (1),
27036                                        GEN_INT (one_var == 1 ? 0 : 1),
27037                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
27038                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
27039
27040           if (mode != V4SFmode)
27041             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
27042           else if (tmp != target)
27043             emit_move_insn (target, tmp);
27044         }
27045       else if (target != new_target)
27046         emit_move_insn (target, new_target);
27047       return true;
27048
27049     case V8HImode:
27050     case V16QImode:
27051       vsimode = V4SImode;
27052       goto widen;
27053     case V4HImode:
27054     case V8QImode:
27055       if (!mmx_ok)
27056         return false;
27057       vsimode = V2SImode;
27058       goto widen;
27059     widen:
27060       if (one_var != 0)
27061         return false;
27062
27063       /* Zero extend the variable element to SImode and recurse.  */
27064       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
27065
27066       x = gen_reg_rtx (vsimode);
27067       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
27068                                                 var, one_var))
27069         gcc_unreachable ();
27070
27071       emit_move_insn (target, gen_lowpart (mode, x));
27072       return true;
27073
27074     default:
27075       return false;
27076     }
27077 }
27078
27079 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
27080    consisting of the values in VALS.  It is known that all elements
27081    except ONE_VAR are constants.  Return true if successful.  */
27082
27083 static bool
27084 ix86_expand_vector_init_one_var (bool mmx_ok, enum machine_mode mode,
27085                                  rtx target, rtx vals, int one_var)
27086 {
27087   rtx var = XVECEXP (vals, 0, one_var);
27088   enum machine_mode wmode;
27089   rtx const_vec, x;
27090
27091   const_vec = copy_rtx (vals);
27092   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
27093   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
27094
27095   switch (mode)
27096     {
27097     case V2DFmode:
27098     case V2DImode:
27099     case V2SFmode:
27100     case V2SImode:
27101       /* For the two element vectors, it's just as easy to use
27102          the general case.  */
27103       return false;
27104
27105     case V4DFmode:
27106     case V4DImode:
27107     case V8SFmode:
27108     case V8SImode:
27109     case V16HImode:
27110     case V32QImode:
27111     case V4SFmode:
27112     case V4SImode:
27113     case V8HImode:
27114     case V4HImode:
27115       break;
27116
27117     case V16QImode:
27118       if (TARGET_SSE4_1)
27119         break;
27120       wmode = V8HImode;
27121       goto widen;
27122     case V8QImode:
27123       wmode = V4HImode;
27124       goto widen;
27125     widen:
27126       /* There's no way to set one QImode entry easily.  Combine
27127          the variable value with its adjacent constant value, and
27128          promote to an HImode set.  */
27129       x = XVECEXP (vals, 0, one_var ^ 1);
27130       if (one_var & 1)
27131         {
27132           var = convert_modes (HImode, QImode, var, true);
27133           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
27134                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
27135           x = GEN_INT (INTVAL (x) & 0xff);
27136         }
27137       else
27138         {
27139           var = convert_modes (HImode, QImode, var, true);
27140           x = gen_int_mode (INTVAL (x) << 8, HImode);
27141         }
27142       if (x != const0_rtx)
27143         var = expand_simple_binop (HImode, IOR, var, x, var,
27144                                    1, OPTAB_LIB_WIDEN);
27145
27146       x = gen_reg_rtx (wmode);
27147       emit_move_insn (x, gen_lowpart (wmode, const_vec));
27148       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
27149
27150       emit_move_insn (target, gen_lowpart (mode, x));
27151       return true;
27152
27153     default:
27154       return false;
27155     }
27156
27157   emit_move_insn (target, const_vec);
27158   ix86_expand_vector_set (mmx_ok, target, var, one_var);
27159   return true;
27160 }
27161
27162 /* A subroutine of ix86_expand_vector_init_general.  Use vector
27163    concatenate to handle the most general case: all values variable,
27164    and none identical.  */
27165
27166 static void
27167 ix86_expand_vector_init_concat (enum machine_mode mode,
27168                                 rtx target, rtx *ops, int n)
27169 {
27170   enum machine_mode cmode, hmode = VOIDmode;
27171   rtx first[8], second[4];
27172   rtvec v;
27173   int i, j;
27174
27175   switch (n)
27176     {
27177     case 2:
27178       switch (mode)
27179         {
27180         case V8SImode:
27181           cmode = V4SImode;
27182           break;
27183         case V8SFmode:
27184           cmode = V4SFmode;
27185           break;
27186         case V4DImode:
27187           cmode = V2DImode;
27188           break;
27189         case V4DFmode:
27190           cmode = V2DFmode;
27191           break;
27192         case V4SImode:
27193           cmode = V2SImode;
27194           break;
27195         case V4SFmode:
27196           cmode = V2SFmode;
27197           break;
27198         case V2DImode:
27199           cmode = DImode;
27200           break;
27201         case V2SImode:
27202           cmode = SImode;
27203           break;
27204         case V2DFmode:
27205           cmode = DFmode;
27206           break;
27207         case V2SFmode:
27208           cmode = SFmode;
27209           break;
27210         default:
27211           gcc_unreachable ();
27212         }
27213
27214       if (!register_operand (ops[1], cmode))
27215         ops[1] = force_reg (cmode, ops[1]);
27216       if (!register_operand (ops[0], cmode))
27217         ops[0] = force_reg (cmode, ops[0]);
27218       emit_insn (gen_rtx_SET (VOIDmode, target,
27219                               gen_rtx_VEC_CONCAT (mode, ops[0],
27220                                                   ops[1])));
27221       break;
27222
27223     case 4:
27224       switch (mode)
27225         {
27226         case V4DImode:
27227           cmode = V2DImode;
27228           break;
27229         case V4DFmode:
27230           cmode = V2DFmode;
27231           break;
27232         case V4SImode:
27233           cmode = V2SImode;
27234           break;
27235         case V4SFmode:
27236           cmode = V2SFmode;
27237           break;
27238         default:
27239           gcc_unreachable ();
27240         }
27241       goto half;
27242
27243     case 8:
27244       switch (mode)
27245         {
27246         case V8SImode:
27247           cmode = V2SImode;
27248           hmode = V4SImode;
27249           break;
27250         case V8SFmode:
27251           cmode = V2SFmode;
27252           hmode = V4SFmode;
27253           break;
27254         default:
27255           gcc_unreachable ();
27256         }
27257       goto half;
27258
27259 half:
27260       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
27261       i = n - 1;
27262       j = (n >> 1) - 1;
27263       for (; i > 0; i -= 2, j--)
27264         {
27265           first[j] = gen_reg_rtx (cmode);
27266           v = gen_rtvec (2, ops[i - 1], ops[i]);
27267           ix86_expand_vector_init (false, first[j],
27268                                    gen_rtx_PARALLEL (cmode, v));
27269         }
27270
27271       n >>= 1;
27272       if (n > 2)
27273         {
27274           gcc_assert (hmode != VOIDmode);
27275           for (i = j = 0; i < n; i += 2, j++)
27276             {
27277               second[j] = gen_reg_rtx (hmode);
27278               ix86_expand_vector_init_concat (hmode, second [j],
27279                                               &first [i], 2);
27280             }
27281           n >>= 1;
27282           ix86_expand_vector_init_concat (mode, target, second, n);
27283         }
27284       else
27285         ix86_expand_vector_init_concat (mode, target, first, n);
27286       break;
27287
27288     default:
27289       gcc_unreachable ();
27290     }
27291 }
27292
27293 /* A subroutine of ix86_expand_vector_init_general.  Use vector
27294    interleave to handle the most general case: all values variable,
27295    and none identical.  */
27296
27297 static void
27298 ix86_expand_vector_init_interleave (enum machine_mode mode,
27299                                     rtx target, rtx *ops, int n)
27300 {
27301   enum machine_mode first_imode, second_imode, third_imode, inner_mode;
27302   int i, j;
27303   rtx op0, op1;
27304   rtx (*gen_load_even) (rtx, rtx, rtx);
27305   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
27306   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
27307   
27308   switch (mode)
27309     {
27310     case V8HImode:
27311       gen_load_even = gen_vec_setv8hi;
27312       gen_interleave_first_low = gen_vec_interleave_lowv4si;
27313       gen_interleave_second_low = gen_vec_interleave_lowv2di;
27314       inner_mode = HImode;
27315       first_imode = V4SImode;
27316       second_imode = V2DImode;
27317       third_imode = VOIDmode;
27318       break;
27319     case V16QImode:
27320       gen_load_even = gen_vec_setv16qi;
27321       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
27322       gen_interleave_second_low = gen_vec_interleave_lowv4si;
27323       inner_mode = QImode;
27324       first_imode = V8HImode;
27325       second_imode = V4SImode;
27326       third_imode = V2DImode;
27327       break;
27328     default:
27329       gcc_unreachable ();
27330     }
27331      
27332   for (i = 0; i < n; i++)
27333     {
27334       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
27335       op0 = gen_reg_rtx (SImode);
27336       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
27337
27338       /* Insert the SImode value as low element of V4SImode vector. */
27339       op1 = gen_reg_rtx (V4SImode);
27340       op0 = gen_rtx_VEC_MERGE (V4SImode,
27341                                gen_rtx_VEC_DUPLICATE (V4SImode,
27342                                                       op0),
27343                                CONST0_RTX (V4SImode),
27344                                const1_rtx);
27345       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
27346
27347       /* Cast the V4SImode vector back to a vector in orignal mode.  */
27348       op0 = gen_reg_rtx (mode);
27349       emit_move_insn (op0, gen_lowpart (mode, op1));
27350       
27351       /* Load even elements into the second positon.  */
27352       emit_insn ((*gen_load_even) (op0,
27353                                    force_reg (inner_mode,
27354                                               ops [i + i + 1]),
27355                                    const1_rtx));
27356
27357       /* Cast vector to FIRST_IMODE vector.  */
27358       ops[i] = gen_reg_rtx (first_imode);
27359       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
27360     }
27361
27362   /* Interleave low FIRST_IMODE vectors.  */
27363   for (i = j = 0; i < n; i += 2, j++)
27364     {
27365       op0 = gen_reg_rtx (first_imode);
27366       emit_insn ((*gen_interleave_first_low) (op0, ops[i], ops[i + 1]));
27367
27368       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
27369       ops[j] = gen_reg_rtx (second_imode);
27370       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
27371     }
27372
27373   /* Interleave low SECOND_IMODE vectors.  */
27374   switch (second_imode)
27375     {
27376     case V4SImode:
27377       for (i = j = 0; i < n / 2; i += 2, j++)
27378         {
27379           op0 = gen_reg_rtx (second_imode);
27380           emit_insn ((*gen_interleave_second_low) (op0, ops[i],
27381                                                    ops[i + 1]));
27382
27383           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
27384              vector.  */
27385           ops[j] = gen_reg_rtx (third_imode);
27386           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
27387         }
27388       second_imode = V2DImode;
27389       gen_interleave_second_low = gen_vec_interleave_lowv2di;
27390       /* FALLTHRU */
27391
27392     case V2DImode:
27393       op0 = gen_reg_rtx (second_imode);
27394       emit_insn ((*gen_interleave_second_low) (op0, ops[0],
27395                                                ops[1]));
27396
27397       /* Cast the SECOND_IMODE vector back to a vector on original
27398          mode.  */
27399       emit_insn (gen_rtx_SET (VOIDmode, target,
27400                               gen_lowpart (mode, op0)));
27401       break;
27402
27403     default:
27404       gcc_unreachable ();
27405     }
27406 }
27407
27408 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
27409    all values variable, and none identical.  */
27410
27411 static void
27412 ix86_expand_vector_init_general (bool mmx_ok, enum machine_mode mode,
27413                                  rtx target, rtx vals)
27414 {
27415   rtx ops[32], op0, op1;
27416   enum machine_mode half_mode = VOIDmode;
27417   int n, i;
27418
27419   switch (mode)
27420     {
27421     case V2SFmode:
27422     case V2SImode:
27423       if (!mmx_ok && !TARGET_SSE)
27424         break;
27425       /* FALLTHRU */
27426
27427     case V8SFmode:
27428     case V8SImode:
27429     case V4DFmode:
27430     case V4DImode:
27431     case V4SFmode:
27432     case V4SImode:
27433     case V2DFmode:
27434     case V2DImode:
27435       n = GET_MODE_NUNITS (mode);
27436       for (i = 0; i < n; i++)
27437         ops[i] = XVECEXP (vals, 0, i);
27438       ix86_expand_vector_init_concat (mode, target, ops, n);
27439       return;
27440
27441     case V32QImode:
27442       half_mode = V16QImode;
27443       goto half;
27444
27445     case V16HImode:
27446       half_mode = V8HImode;
27447       goto half;
27448
27449 half:
27450       n = GET_MODE_NUNITS (mode);
27451       for (i = 0; i < n; i++)
27452         ops[i] = XVECEXP (vals, 0, i);
27453       op0 = gen_reg_rtx (half_mode);
27454       op1 = gen_reg_rtx (half_mode);
27455       ix86_expand_vector_init_interleave (half_mode, op0, ops,
27456                                           n >> 2);
27457       ix86_expand_vector_init_interleave (half_mode, op1,
27458                                           &ops [n >> 1], n >> 2);
27459       emit_insn (gen_rtx_SET (VOIDmode, target,
27460                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
27461       return;
27462
27463     case V16QImode:
27464       if (!TARGET_SSE4_1)
27465         break;
27466       /* FALLTHRU */
27467
27468     case V8HImode:
27469       if (!TARGET_SSE2)
27470         break;
27471
27472       /* Don't use ix86_expand_vector_init_interleave if we can't
27473          move from GPR to SSE register directly.  */ 
27474       if (!TARGET_INTER_UNIT_MOVES)
27475         break;
27476
27477       n = GET_MODE_NUNITS (mode);
27478       for (i = 0; i < n; i++)
27479         ops[i] = XVECEXP (vals, 0, i);
27480       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
27481       return;
27482
27483     case V4HImode:
27484     case V8QImode:
27485       break;
27486
27487     default:
27488       gcc_unreachable ();
27489     }
27490
27491     {
27492       int i, j, n_elts, n_words, n_elt_per_word;
27493       enum machine_mode inner_mode;
27494       rtx words[4], shift;
27495
27496       inner_mode = GET_MODE_INNER (mode);
27497       n_elts = GET_MODE_NUNITS (mode);
27498       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
27499       n_elt_per_word = n_elts / n_words;
27500       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
27501
27502       for (i = 0; i < n_words; ++i)
27503         {
27504           rtx word = NULL_RTX;
27505
27506           for (j = 0; j < n_elt_per_word; ++j)
27507             {
27508               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
27509               elt = convert_modes (word_mode, inner_mode, elt, true);
27510
27511               if (j == 0)
27512                 word = elt;
27513               else
27514                 {
27515                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
27516                                               word, 1, OPTAB_LIB_WIDEN);
27517                   word = expand_simple_binop (word_mode, IOR, word, elt,
27518                                               word, 1, OPTAB_LIB_WIDEN);
27519                 }
27520             }
27521
27522           words[i] = word;
27523         }
27524
27525       if (n_words == 1)
27526         emit_move_insn (target, gen_lowpart (mode, words[0]));
27527       else if (n_words == 2)
27528         {
27529           rtx tmp = gen_reg_rtx (mode);
27530           emit_clobber (tmp);
27531           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
27532           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
27533           emit_move_insn (target, tmp);
27534         }
27535       else if (n_words == 4)
27536         {
27537           rtx tmp = gen_reg_rtx (V4SImode);
27538           gcc_assert (word_mode == SImode);
27539           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
27540           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
27541           emit_move_insn (target, gen_lowpart (mode, tmp));
27542         }
27543       else
27544         gcc_unreachable ();
27545     }
27546 }
27547
27548 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
27549    instructions unless MMX_OK is true.  */
27550
27551 void
27552 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
27553 {
27554   enum machine_mode mode = GET_MODE (target);
27555   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27556   int n_elts = GET_MODE_NUNITS (mode);
27557   int n_var = 0, one_var = -1;
27558   bool all_same = true, all_const_zero = true;
27559   int i;
27560   rtx x;
27561
27562   for (i = 0; i < n_elts; ++i)
27563     {
27564       x = XVECEXP (vals, 0, i);
27565       if (!(CONST_INT_P (x)
27566             || GET_CODE (x) == CONST_DOUBLE
27567             || GET_CODE (x) == CONST_FIXED))
27568         n_var++, one_var = i;
27569       else if (x != CONST0_RTX (inner_mode))
27570         all_const_zero = false;
27571       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
27572         all_same = false;
27573     }
27574
27575   /* Constants are best loaded from the constant pool.  */
27576   if (n_var == 0)
27577     {
27578       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
27579       return;
27580     }
27581
27582   /* If all values are identical, broadcast the value.  */
27583   if (all_same
27584       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
27585                                             XVECEXP (vals, 0, 0)))
27586     return;
27587
27588   /* Values where only one field is non-constant are best loaded from
27589      the pool and overwritten via move later.  */
27590   if (n_var == 1)
27591     {
27592       if (all_const_zero
27593           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
27594                                                   XVECEXP (vals, 0, one_var),
27595                                                   one_var))
27596         return;
27597
27598       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
27599         return;
27600     }
27601
27602   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
27603 }
27604
27605 void
27606 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
27607 {
27608   enum machine_mode mode = GET_MODE (target);
27609   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27610   enum machine_mode half_mode;
27611   bool use_vec_merge = false;
27612   rtx tmp;
27613   static rtx (*gen_extract[6][2]) (rtx, rtx)
27614     = {
27615         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
27616         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
27617         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
27618         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
27619         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
27620         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
27621       };
27622   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
27623     = {
27624         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
27625         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
27626         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
27627         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
27628         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
27629         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
27630       };
27631   int i, j, n;
27632
27633   switch (mode)
27634     {
27635     case V2SFmode:
27636     case V2SImode:
27637       if (mmx_ok)
27638         {
27639           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
27640           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
27641           if (elt == 0)
27642             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
27643           else
27644             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
27645           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27646           return;
27647         }
27648       break;
27649
27650     case V2DImode:
27651       use_vec_merge = TARGET_SSE4_1;
27652       if (use_vec_merge)
27653         break;
27654
27655     case V2DFmode:
27656       {
27657         rtx op0, op1;
27658
27659         /* For the two element vectors, we implement a VEC_CONCAT with
27660            the extraction of the other element.  */
27661
27662         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
27663         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
27664
27665         if (elt == 0)
27666           op0 = val, op1 = tmp;
27667         else
27668           op0 = tmp, op1 = val;
27669
27670         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
27671         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27672       }
27673       return;
27674
27675     case V4SFmode:
27676       use_vec_merge = TARGET_SSE4_1;
27677       if (use_vec_merge)
27678         break;
27679
27680       switch (elt)
27681         {
27682         case 0:
27683           use_vec_merge = true;
27684           break;
27685
27686         case 1:
27687           /* tmp = target = A B C D */
27688           tmp = copy_to_reg (target);
27689           /* target = A A B B */
27690           emit_insn (gen_sse_unpcklps (target, target, target));
27691           /* target = X A B B */
27692           ix86_expand_vector_set (false, target, val, 0);
27693           /* target = A X C D  */
27694           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27695                                        GEN_INT (1), GEN_INT (0),
27696                                        GEN_INT (2+4), GEN_INT (3+4)));
27697           return;
27698
27699         case 2:
27700           /* tmp = target = A B C D */
27701           tmp = copy_to_reg (target);
27702           /* tmp = X B C D */
27703           ix86_expand_vector_set (false, tmp, val, 0);
27704           /* target = A B X D */
27705           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27706                                        GEN_INT (0), GEN_INT (1),
27707                                        GEN_INT (0+4), GEN_INT (3+4)));
27708           return;
27709
27710         case 3:
27711           /* tmp = target = A B C D */
27712           tmp = copy_to_reg (target);
27713           /* tmp = X B C D */
27714           ix86_expand_vector_set (false, tmp, val, 0);
27715           /* target = A B X D */
27716           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27717                                        GEN_INT (0), GEN_INT (1),
27718                                        GEN_INT (2+4), GEN_INT (0+4)));
27719           return;
27720
27721         default:
27722           gcc_unreachable ();
27723         }
27724       break;
27725
27726     case V4SImode:
27727       use_vec_merge = TARGET_SSE4_1;
27728       if (use_vec_merge)
27729         break;
27730
27731       /* Element 0 handled by vec_merge below.  */
27732       if (elt == 0)
27733         {
27734           use_vec_merge = true;
27735           break;
27736         }
27737
27738       if (TARGET_SSE2)
27739         {
27740           /* With SSE2, use integer shuffles to swap element 0 and ELT,
27741              store into element 0, then shuffle them back.  */
27742
27743           rtx order[4];
27744
27745           order[0] = GEN_INT (elt);
27746           order[1] = const1_rtx;
27747           order[2] = const2_rtx;
27748           order[3] = GEN_INT (3);
27749           order[elt] = const0_rtx;
27750
27751           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
27752                                         order[1], order[2], order[3]));
27753
27754           ix86_expand_vector_set (false, target, val, 0);
27755
27756           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
27757                                         order[1], order[2], order[3]));
27758         }
27759       else
27760         {
27761           /* For SSE1, we have to reuse the V4SF code.  */
27762           ix86_expand_vector_set (false, gen_lowpart (V4SFmode, target),
27763                                   gen_lowpart (SFmode, val), elt);
27764         }
27765       return;
27766
27767     case V8HImode:
27768       use_vec_merge = TARGET_SSE2;
27769       break;
27770     case V4HImode:
27771       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
27772       break;
27773
27774     case V16QImode:
27775       use_vec_merge = TARGET_SSE4_1;
27776       break;
27777
27778     case V8QImode:
27779       break;
27780
27781     case V32QImode:
27782       half_mode = V16QImode;
27783       j = 0;
27784       n = 16;
27785       goto half;
27786
27787     case V16HImode:
27788       half_mode = V8HImode;
27789       j = 1;
27790       n = 8;
27791       goto half;
27792
27793     case V8SImode:
27794       half_mode = V4SImode;
27795       j = 2;
27796       n = 4;
27797       goto half;
27798
27799     case V4DImode:
27800       half_mode = V2DImode;
27801       j = 3;
27802       n = 2;
27803       goto half;
27804
27805     case V8SFmode:
27806       half_mode = V4SFmode;
27807       j = 4;
27808       n = 4;
27809       goto half;
27810
27811     case V4DFmode:
27812       half_mode = V2DFmode;
27813       j = 5;
27814       n = 2;
27815       goto half;
27816
27817 half:
27818       /* Compute offset.  */
27819       i = elt / n;
27820       elt %= n;
27821
27822       gcc_assert (i <= 1);
27823
27824       /* Extract the half.  */
27825       tmp = gen_reg_rtx (half_mode);
27826       emit_insn ((*gen_extract[j][i]) (tmp, target));
27827
27828       /* Put val in tmp at elt.  */
27829       ix86_expand_vector_set (false, tmp, val, elt);
27830
27831       /* Put it back.  */
27832       emit_insn ((*gen_insert[j][i]) (target, target, tmp));
27833       return;
27834
27835     default:
27836       break;
27837     }
27838
27839   if (use_vec_merge)
27840     {
27841       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
27842       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
27843       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27844     }
27845   else
27846     {
27847       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
27848
27849       emit_move_insn (mem, target);
27850
27851       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
27852       emit_move_insn (tmp, val);
27853
27854       emit_move_insn (target, mem);
27855     }
27856 }
27857
27858 void
27859 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
27860 {
27861   enum machine_mode mode = GET_MODE (vec);
27862   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27863   bool use_vec_extr = false;
27864   rtx tmp;
27865
27866   switch (mode)
27867     {
27868     case V2SImode:
27869     case V2SFmode:
27870       if (!mmx_ok)
27871         break;
27872       /* FALLTHRU */
27873
27874     case V2DFmode:
27875     case V2DImode:
27876       use_vec_extr = true;
27877       break;
27878
27879     case V4SFmode:
27880       use_vec_extr = TARGET_SSE4_1;
27881       if (use_vec_extr)
27882         break;
27883
27884       switch (elt)
27885         {
27886         case 0:
27887           tmp = vec;
27888           break;
27889
27890         case 1:
27891         case 3:
27892           tmp = gen_reg_rtx (mode);
27893           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
27894                                        GEN_INT (elt), GEN_INT (elt),
27895                                        GEN_INT (elt+4), GEN_INT (elt+4)));
27896           break;
27897
27898         case 2:
27899           tmp = gen_reg_rtx (mode);
27900           emit_insn (gen_sse_unpckhps (tmp, vec, vec));
27901           break;
27902
27903         default:
27904           gcc_unreachable ();
27905         }
27906       vec = tmp;
27907       use_vec_extr = true;
27908       elt = 0;
27909       break;
27910
27911     case V4SImode:
27912       use_vec_extr = TARGET_SSE4_1;
27913       if (use_vec_extr)
27914         break;
27915
27916       if (TARGET_SSE2)
27917         {
27918           switch (elt)
27919             {
27920             case 0:
27921               tmp = vec;
27922               break;
27923
27924             case 1:
27925             case 3:
27926               tmp = gen_reg_rtx (mode);
27927               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
27928                                             GEN_INT (elt), GEN_INT (elt),
27929                                             GEN_INT (elt), GEN_INT (elt)));
27930               break;
27931
27932             case 2:
27933               tmp = gen_reg_rtx (mode);
27934               emit_insn (gen_sse2_punpckhdq (tmp, vec, vec));
27935               break;
27936
27937             default:
27938               gcc_unreachable ();
27939             }
27940           vec = tmp;
27941           use_vec_extr = true;
27942           elt = 0;
27943         }
27944       else
27945         {
27946           /* For SSE1, we have to reuse the V4SF code.  */
27947           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
27948                                       gen_lowpart (V4SFmode, vec), elt);
27949           return;
27950         }
27951       break;
27952
27953     case V8HImode:
27954       use_vec_extr = TARGET_SSE2;
27955       break;
27956     case V4HImode:
27957       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
27958       break;
27959
27960     case V16QImode:
27961       use_vec_extr = TARGET_SSE4_1;
27962       break;
27963
27964     case V8QImode:
27965       /* ??? Could extract the appropriate HImode element and shift.  */
27966     default:
27967       break;
27968     }
27969
27970   if (use_vec_extr)
27971     {
27972       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
27973       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
27974
27975       /* Let the rtl optimizers know about the zero extension performed.  */
27976       if (inner_mode == QImode || inner_mode == HImode)
27977         {
27978           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
27979           target = gen_lowpart (SImode, target);
27980         }
27981
27982       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27983     }
27984   else
27985     {
27986       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
27987
27988       emit_move_insn (mem, vec);
27989
27990       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
27991       emit_move_insn (target, tmp);
27992     }
27993 }
27994
27995 /* Expand a vector reduction on V4SFmode for SSE1.  FN is the binary
27996    pattern to reduce; DEST is the destination; IN is the input vector.  */
27997
27998 void
27999 ix86_expand_reduc_v4sf (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
28000 {
28001   rtx tmp1, tmp2, tmp3;
28002
28003   tmp1 = gen_reg_rtx (V4SFmode);
28004   tmp2 = gen_reg_rtx (V4SFmode);
28005   tmp3 = gen_reg_rtx (V4SFmode);
28006
28007   emit_insn (gen_sse_movhlps (tmp1, in, in));
28008   emit_insn (fn (tmp2, tmp1, in));
28009
28010   emit_insn (gen_sse_shufps_v4sf (tmp3, tmp2, tmp2,
28011                                GEN_INT (1), GEN_INT (1),
28012                                GEN_INT (1+4), GEN_INT (1+4)));
28013   emit_insn (fn (dest, tmp2, tmp3));
28014 }
28015 \f
28016 /* Target hook for scalar_mode_supported_p.  */
28017 static bool
28018 ix86_scalar_mode_supported_p (enum machine_mode mode)
28019 {
28020   if (DECIMAL_FLOAT_MODE_P (mode))
28021     return true;
28022   else if (mode == TFmode)
28023     return true;
28024   else
28025     return default_scalar_mode_supported_p (mode);
28026 }
28027
28028 /* Implements target hook vector_mode_supported_p.  */
28029 static bool
28030 ix86_vector_mode_supported_p (enum machine_mode mode)
28031 {
28032   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
28033     return true;
28034   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
28035     return true;
28036   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
28037     return true;
28038   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
28039     return true;
28040   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
28041     return true;
28042   return false;
28043 }
28044
28045 /* Target hook for c_mode_for_suffix.  */
28046 static enum machine_mode
28047 ix86_c_mode_for_suffix (char suffix)
28048 {
28049   if (suffix == 'q')
28050     return TFmode;
28051   if (suffix == 'w')
28052     return XFmode;
28053
28054   return VOIDmode;
28055 }
28056
28057 /* Worker function for TARGET_MD_ASM_CLOBBERS.
28058
28059    We do this in the new i386 backend to maintain source compatibility
28060    with the old cc0-based compiler.  */
28061
28062 static tree
28063 ix86_md_asm_clobbers (tree outputs ATTRIBUTE_UNUSED,
28064                       tree inputs ATTRIBUTE_UNUSED,
28065                       tree clobbers)
28066 {
28067   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
28068                         clobbers);
28069   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
28070                         clobbers);
28071   return clobbers;
28072 }
28073
28074 /* Implements target vector targetm.asm.encode_section_info.  This
28075    is not used by netware.  */
28076
28077 static void ATTRIBUTE_UNUSED
28078 ix86_encode_section_info (tree decl, rtx rtl, int first)
28079 {
28080   default_encode_section_info (decl, rtl, first);
28081
28082   if (TREE_CODE (decl) == VAR_DECL
28083       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
28084       && ix86_in_large_data_p (decl))
28085     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
28086 }
28087
28088 /* Worker function for REVERSE_CONDITION.  */
28089
28090 enum rtx_code
28091 ix86_reverse_condition (enum rtx_code code, enum machine_mode mode)
28092 {
28093   return (mode != CCFPmode && mode != CCFPUmode
28094           ? reverse_condition (code)
28095           : reverse_condition_maybe_unordered (code));
28096 }
28097
28098 /* Output code to perform an x87 FP register move, from OPERANDS[1]
28099    to OPERANDS[0].  */
28100
28101 const char *
28102 output_387_reg_move (rtx insn, rtx *operands)
28103 {
28104   if (REG_P (operands[0]))
28105     {
28106       if (REG_P (operands[1])
28107           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
28108         {
28109           if (REGNO (operands[0]) == FIRST_STACK_REG)
28110             return output_387_ffreep (operands, 0);
28111           return "fstp\t%y0";
28112         }
28113       if (STACK_TOP_P (operands[0]))
28114         return "fld%z1\t%y1";
28115       return "fst\t%y0";
28116     }
28117   else if (MEM_P (operands[0]))
28118     {
28119       gcc_assert (REG_P (operands[1]));
28120       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
28121         return "fstp%z0\t%y0";
28122       else
28123         {
28124           /* There is no non-popping store to memory for XFmode.
28125              So if we need one, follow the store with a load.  */
28126           if (GET_MODE (operands[0]) == XFmode)
28127             return "fstp%z0\t%y0\n\tfld%z0\t%y0";
28128           else
28129             return "fst%z0\t%y0";
28130         }
28131     }
28132   else
28133     gcc_unreachable();
28134 }
28135
28136 /* Output code to perform a conditional jump to LABEL, if C2 flag in
28137    FP status register is set.  */
28138
28139 void
28140 ix86_emit_fp_unordered_jump (rtx label)
28141 {
28142   rtx reg = gen_reg_rtx (HImode);
28143   rtx temp;
28144
28145   emit_insn (gen_x86_fnstsw_1 (reg));
28146
28147   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
28148     {
28149       emit_insn (gen_x86_sahf_1 (reg));
28150
28151       temp = gen_rtx_REG (CCmode, FLAGS_REG);
28152       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
28153     }
28154   else
28155     {
28156       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
28157
28158       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
28159       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
28160     }
28161
28162   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
28163                               gen_rtx_LABEL_REF (VOIDmode, label),
28164                               pc_rtx);
28165   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
28166
28167   emit_jump_insn (temp);
28168   predict_jump (REG_BR_PROB_BASE * 10 / 100);
28169 }
28170
28171 /* Output code to perform a log1p XFmode calculation.  */
28172
28173 void ix86_emit_i387_log1p (rtx op0, rtx op1)
28174 {
28175   rtx label1 = gen_label_rtx ();
28176   rtx label2 = gen_label_rtx ();
28177
28178   rtx tmp = gen_reg_rtx (XFmode);
28179   rtx tmp2 = gen_reg_rtx (XFmode);
28180
28181   emit_insn (gen_absxf2 (tmp, op1));
28182   emit_insn (gen_cmpxf (tmp,
28183     CONST_DOUBLE_FROM_REAL_VALUE (
28184        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
28185        XFmode)));
28186   emit_jump_insn (gen_bge (label1));
28187
28188   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
28189   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
28190   emit_jump (label2);
28191
28192   emit_label (label1);
28193   emit_move_insn (tmp, CONST1_RTX (XFmode));
28194   emit_insn (gen_addxf3 (tmp, op1, tmp));
28195   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
28196   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
28197
28198   emit_label (label2);
28199 }
28200
28201 /* Output code to perform a Newton-Rhapson approximation of a single precision
28202    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
28203
28204 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, enum machine_mode mode)
28205 {
28206   rtx x0, x1, e0, e1, two;
28207
28208   x0 = gen_reg_rtx (mode);
28209   e0 = gen_reg_rtx (mode);
28210   e1 = gen_reg_rtx (mode);
28211   x1 = gen_reg_rtx (mode);
28212
28213   two = CONST_DOUBLE_FROM_REAL_VALUE (dconst2, SFmode);
28214
28215   if (VECTOR_MODE_P (mode))
28216     two = ix86_build_const_vector (SFmode, true, two);
28217
28218   two = force_reg (mode, two);
28219
28220   /* a / b = a * rcp(b) * (2.0 - b * rcp(b)) */
28221
28222   /* x0 = rcp(b) estimate */
28223   emit_insn (gen_rtx_SET (VOIDmode, x0,
28224                           gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
28225                                           UNSPEC_RCP)));
28226   /* e0 = x0 * b */
28227   emit_insn (gen_rtx_SET (VOIDmode, e0,
28228                           gen_rtx_MULT (mode, x0, b)));
28229   /* e1 = 2. - e0 */
28230   emit_insn (gen_rtx_SET (VOIDmode, e1,
28231                           gen_rtx_MINUS (mode, two, e0)));
28232   /* x1 = x0 * e1 */
28233   emit_insn (gen_rtx_SET (VOIDmode, x1,
28234                           gen_rtx_MULT (mode, x0, e1)));
28235   /* res = a * x1 */
28236   emit_insn (gen_rtx_SET (VOIDmode, res,
28237                           gen_rtx_MULT (mode, a, x1)));
28238 }
28239
28240 /* Output code to perform a Newton-Rhapson approximation of a
28241    single precision floating point [reciprocal] square root.  */
28242
28243 void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
28244                          bool recip)
28245 {
28246   rtx x0, e0, e1, e2, e3, mthree, mhalf;
28247   REAL_VALUE_TYPE r;
28248
28249   x0 = gen_reg_rtx (mode);
28250   e0 = gen_reg_rtx (mode);
28251   e1 = gen_reg_rtx (mode);
28252   e2 = gen_reg_rtx (mode);
28253   e3 = gen_reg_rtx (mode);
28254
28255   real_from_integer (&r, VOIDmode, -3, -1, 0);
28256   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
28257
28258   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
28259   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
28260
28261   if (VECTOR_MODE_P (mode))
28262     {
28263       mthree = ix86_build_const_vector (SFmode, true, mthree);
28264       mhalf = ix86_build_const_vector (SFmode, true, mhalf);
28265     }
28266
28267   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
28268      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
28269
28270   /* x0 = rsqrt(a) estimate */
28271   emit_insn (gen_rtx_SET (VOIDmode, x0,
28272                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
28273                                           UNSPEC_RSQRT)));
28274
28275   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
28276   if (!recip)
28277     {
28278       rtx zero, mask;
28279
28280       zero = gen_reg_rtx (mode);
28281       mask = gen_reg_rtx (mode);
28282
28283       zero = force_reg (mode, CONST0_RTX(mode));
28284       emit_insn (gen_rtx_SET (VOIDmode, mask,
28285                               gen_rtx_NE (mode, zero, a)));
28286
28287       emit_insn (gen_rtx_SET (VOIDmode, x0,
28288                               gen_rtx_AND (mode, x0, mask)));
28289     }
28290
28291   /* e0 = x0 * a */
28292   emit_insn (gen_rtx_SET (VOIDmode, e0,
28293                           gen_rtx_MULT (mode, x0, a)));
28294   /* e1 = e0 * x0 */
28295   emit_insn (gen_rtx_SET (VOIDmode, e1,
28296                           gen_rtx_MULT (mode, e0, x0)));
28297
28298   /* e2 = e1 - 3. */
28299   mthree = force_reg (mode, mthree);
28300   emit_insn (gen_rtx_SET (VOIDmode, e2,
28301                           gen_rtx_PLUS (mode, e1, mthree)));
28302
28303   mhalf = force_reg (mode, mhalf);
28304   if (recip)
28305     /* e3 = -.5 * x0 */
28306     emit_insn (gen_rtx_SET (VOIDmode, e3,
28307                             gen_rtx_MULT (mode, x0, mhalf)));
28308   else
28309     /* e3 = -.5 * e0 */
28310     emit_insn (gen_rtx_SET (VOIDmode, e3,
28311                             gen_rtx_MULT (mode, e0, mhalf)));
28312   /* ret = e2 * e3 */
28313   emit_insn (gen_rtx_SET (VOIDmode, res,
28314                           gen_rtx_MULT (mode, e2, e3)));
28315 }
28316
28317 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
28318
28319 static void ATTRIBUTE_UNUSED
28320 i386_solaris_elf_named_section (const char *name, unsigned int flags,
28321                                 tree decl)
28322 {
28323   /* With Binutils 2.15, the "@unwind" marker must be specified on
28324      every occurrence of the ".eh_frame" section, not just the first
28325      one.  */
28326   if (TARGET_64BIT
28327       && strcmp (name, ".eh_frame") == 0)
28328     {
28329       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
28330                flags & SECTION_WRITE ? "aw" : "a");
28331       return;
28332     }
28333   default_elf_asm_named_section (name, flags, decl);
28334 }
28335
28336 /* Return the mangling of TYPE if it is an extended fundamental type.  */
28337
28338 static const char *
28339 ix86_mangle_type (const_tree type)
28340 {
28341   type = TYPE_MAIN_VARIANT (type);
28342
28343   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
28344       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
28345     return NULL;
28346
28347   switch (TYPE_MODE (type))
28348     {
28349     case TFmode:
28350       /* __float128 is "g".  */
28351       return "g";
28352     case XFmode:
28353       /* "long double" or __float80 is "e".  */
28354       return "e";
28355     default:
28356       return NULL;
28357     }
28358 }
28359
28360 /* For 32-bit code we can save PIC register setup by using
28361    __stack_chk_fail_local hidden function instead of calling
28362    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
28363    register, so it is better to call __stack_chk_fail directly.  */
28364
28365 static tree
28366 ix86_stack_protect_fail (void)
28367 {
28368   return TARGET_64BIT
28369          ? default_external_stack_protect_fail ()
28370          : default_hidden_stack_protect_fail ();
28371 }
28372
28373 /* Select a format to encode pointers in exception handling data.  CODE
28374    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
28375    true if the symbol may be affected by dynamic relocations.
28376
28377    ??? All x86 object file formats are capable of representing this.
28378    After all, the relocation needed is the same as for the call insn.
28379    Whether or not a particular assembler allows us to enter such, I
28380    guess we'll have to see.  */
28381 int
28382 asm_preferred_eh_data_format (int code, int global)
28383 {
28384   if (flag_pic)
28385     {
28386       int type = DW_EH_PE_sdata8;
28387       if (!TARGET_64BIT
28388           || ix86_cmodel == CM_SMALL_PIC
28389           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
28390         type = DW_EH_PE_sdata4;
28391       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
28392     }
28393   if (ix86_cmodel == CM_SMALL
28394       || (ix86_cmodel == CM_MEDIUM && code))
28395     return DW_EH_PE_udata4;
28396   return DW_EH_PE_absptr;
28397 }
28398 \f
28399 /* Expand copysign from SIGN to the positive value ABS_VALUE
28400    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
28401    the sign-bit.  */
28402 static void
28403 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
28404 {
28405   enum machine_mode mode = GET_MODE (sign);
28406   rtx sgn = gen_reg_rtx (mode);
28407   if (mask == NULL_RTX)
28408     {
28409       mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), false);
28410       if (!VECTOR_MODE_P (mode))
28411         {
28412           /* We need to generate a scalar mode mask in this case.  */
28413           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28414           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28415           mask = gen_reg_rtx (mode);
28416           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28417         }
28418     }
28419   else
28420     mask = gen_rtx_NOT (mode, mask);
28421   emit_insn (gen_rtx_SET (VOIDmode, sgn,
28422                           gen_rtx_AND (mode, mask, sign)));
28423   emit_insn (gen_rtx_SET (VOIDmode, result,
28424                           gen_rtx_IOR (mode, abs_value, sgn)));
28425 }
28426
28427 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
28428    mask for masking out the sign-bit is stored in *SMASK, if that is
28429    non-null.  */
28430 static rtx
28431 ix86_expand_sse_fabs (rtx op0, rtx *smask)
28432 {
28433   enum machine_mode mode = GET_MODE (op0);
28434   rtx xa, mask;
28435
28436   xa = gen_reg_rtx (mode);
28437   mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), true);
28438   if (!VECTOR_MODE_P (mode))
28439     {
28440       /* We need to generate a scalar mode mask in this case.  */
28441       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28442       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28443       mask = gen_reg_rtx (mode);
28444       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28445     }
28446   emit_insn (gen_rtx_SET (VOIDmode, xa,
28447                           gen_rtx_AND (mode, op0, mask)));
28448
28449   if (smask)
28450     *smask = mask;
28451
28452   return xa;
28453 }
28454
28455 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
28456    swapping the operands if SWAP_OPERANDS is true.  The expanded
28457    code is a forward jump to a newly created label in case the
28458    comparison is true.  The generated label rtx is returned.  */
28459 static rtx
28460 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
28461                                   bool swap_operands)
28462 {
28463   rtx label, tmp;
28464
28465   if (swap_operands)
28466     {
28467       tmp = op0;
28468       op0 = op1;
28469       op1 = tmp;
28470     }
28471
28472   label = gen_label_rtx ();
28473   tmp = gen_rtx_REG (CCFPUmode, FLAGS_REG);
28474   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28475                           gen_rtx_COMPARE (CCFPUmode, op0, op1)));
28476   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
28477   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
28478                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
28479   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
28480   JUMP_LABEL (tmp) = label;
28481
28482   return label;
28483 }
28484
28485 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
28486    using comparison code CODE.  Operands are swapped for the comparison if
28487    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
28488 static rtx
28489 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
28490                               bool swap_operands)
28491 {
28492   enum machine_mode mode = GET_MODE (op0);
28493   rtx mask = gen_reg_rtx (mode);
28494
28495   if (swap_operands)
28496     {
28497       rtx tmp = op0;
28498       op0 = op1;
28499       op1 = tmp;
28500     }
28501
28502   if (mode == DFmode)
28503     emit_insn (gen_sse2_maskcmpdf3 (mask, op0, op1,
28504                                     gen_rtx_fmt_ee (code, mode, op0, op1)));
28505   else
28506     emit_insn (gen_sse_maskcmpsf3 (mask, op0, op1,
28507                                    gen_rtx_fmt_ee (code, mode, op0, op1)));
28508
28509   return mask;
28510 }
28511
28512 /* Generate and return a rtx of mode MODE for 2**n where n is the number
28513    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
28514 static rtx
28515 ix86_gen_TWO52 (enum machine_mode mode)
28516 {
28517   REAL_VALUE_TYPE TWO52r;
28518   rtx TWO52;
28519
28520   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
28521   TWO52 = const_double_from_real_value (TWO52r, mode);
28522   TWO52 = force_reg (mode, TWO52);
28523
28524   return TWO52;
28525 }
28526
28527 /* Expand SSE sequence for computing lround from OP1 storing
28528    into OP0.  */
28529 void
28530 ix86_expand_lround (rtx op0, rtx op1)
28531 {
28532   /* C code for the stuff we're doing below:
28533        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
28534        return (long)tmp;
28535    */
28536   enum machine_mode mode = GET_MODE (op1);
28537   const struct real_format *fmt;
28538   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
28539   rtx adj;
28540
28541   /* load nextafter (0.5, 0.0) */
28542   fmt = REAL_MODE_FORMAT (mode);
28543   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
28544   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
28545
28546   /* adj = copysign (0.5, op1) */
28547   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
28548   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
28549
28550   /* adj = op1 + adj */
28551   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
28552
28553   /* op0 = (imode)adj */
28554   expand_fix (op0, adj, 0);
28555 }
28556
28557 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
28558    into OPERAND0.  */
28559 void
28560 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
28561 {
28562   /* C code for the stuff we're doing below (for do_floor):
28563         xi = (long)op1;
28564         xi -= (double)xi > op1 ? 1 : 0;
28565         return xi;
28566    */
28567   enum machine_mode fmode = GET_MODE (op1);
28568   enum machine_mode imode = GET_MODE (op0);
28569   rtx ireg, freg, label, tmp;
28570
28571   /* reg = (long)op1 */
28572   ireg = gen_reg_rtx (imode);
28573   expand_fix (ireg, op1, 0);
28574
28575   /* freg = (double)reg */
28576   freg = gen_reg_rtx (fmode);
28577   expand_float (freg, ireg, 0);
28578
28579   /* ireg = (freg > op1) ? ireg - 1 : ireg */
28580   label = ix86_expand_sse_compare_and_jump (UNLE,
28581                                             freg, op1, !do_floor);
28582   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
28583                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
28584   emit_move_insn (ireg, tmp);
28585
28586   emit_label (label);
28587   LABEL_NUSES (label) = 1;
28588
28589   emit_move_insn (op0, ireg);
28590 }
28591
28592 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
28593    result in OPERAND0.  */
28594 void
28595 ix86_expand_rint (rtx operand0, rtx operand1)
28596 {
28597   /* C code for the stuff we're doing below:
28598         xa = fabs (operand1);
28599         if (!isless (xa, 2**52))
28600           return operand1;
28601         xa = xa + 2**52 - 2**52;
28602         return copysign (xa, operand1);
28603    */
28604   enum machine_mode mode = GET_MODE (operand0);
28605   rtx res, xa, label, TWO52, mask;
28606
28607   res = gen_reg_rtx (mode);
28608   emit_move_insn (res, operand1);
28609
28610   /* xa = abs (operand1) */
28611   xa = ix86_expand_sse_fabs (res, &mask);
28612
28613   /* if (!isless (xa, TWO52)) goto label; */
28614   TWO52 = ix86_gen_TWO52 (mode);
28615   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28616
28617   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28618   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28619
28620   ix86_sse_copysign_to_positive (res, xa, res, mask);
28621
28622   emit_label (label);
28623   LABEL_NUSES (label) = 1;
28624
28625   emit_move_insn (operand0, res);
28626 }
28627
28628 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
28629    into OPERAND0.  */
28630 void
28631 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
28632 {
28633   /* C code for the stuff we expand below.
28634         double xa = fabs (x), x2;
28635         if (!isless (xa, TWO52))
28636           return x;
28637         xa = xa + TWO52 - TWO52;
28638         x2 = copysign (xa, x);
28639      Compensate.  Floor:
28640         if (x2 > x)
28641           x2 -= 1;
28642      Compensate.  Ceil:
28643         if (x2 < x)
28644           x2 -= -1;
28645         return x2;
28646    */
28647   enum machine_mode mode = GET_MODE (operand0);
28648   rtx xa, TWO52, tmp, label, one, res, mask;
28649
28650   TWO52 = ix86_gen_TWO52 (mode);
28651
28652   /* Temporary for holding the result, initialized to the input
28653      operand to ease control flow.  */
28654   res = gen_reg_rtx (mode);
28655   emit_move_insn (res, operand1);
28656
28657   /* xa = abs (operand1) */
28658   xa = ix86_expand_sse_fabs (res, &mask);
28659
28660   /* if (!isless (xa, TWO52)) goto label; */
28661   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28662
28663   /* xa = xa + TWO52 - TWO52; */
28664   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28665   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28666
28667   /* xa = copysign (xa, operand1) */
28668   ix86_sse_copysign_to_positive (xa, xa, res, mask);
28669
28670   /* generate 1.0 or -1.0 */
28671   one = force_reg (mode,
28672                    const_double_from_real_value (do_floor
28673                                                  ? dconst1 : dconstm1, mode));
28674
28675   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
28676   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
28677   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28678                           gen_rtx_AND (mode, one, tmp)));
28679   /* We always need to subtract here to preserve signed zero.  */
28680   tmp = expand_simple_binop (mode, MINUS,
28681                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28682   emit_move_insn (res, tmp);
28683
28684   emit_label (label);
28685   LABEL_NUSES (label) = 1;
28686
28687   emit_move_insn (operand0, res);
28688 }
28689
28690 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
28691    into OPERAND0.  */
28692 void
28693 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
28694 {
28695   /* C code for the stuff we expand below.
28696         double xa = fabs (x), x2;
28697         if (!isless (xa, TWO52))
28698           return x;
28699         x2 = (double)(long)x;
28700      Compensate.  Floor:
28701         if (x2 > x)
28702           x2 -= 1;
28703      Compensate.  Ceil:
28704         if (x2 < x)
28705           x2 += 1;
28706         if (HONOR_SIGNED_ZEROS (mode))
28707           return copysign (x2, x);
28708         return x2;
28709    */
28710   enum machine_mode mode = GET_MODE (operand0);
28711   rtx xa, xi, TWO52, tmp, label, one, res, mask;
28712
28713   TWO52 = ix86_gen_TWO52 (mode);
28714
28715   /* Temporary for holding the result, initialized to the input
28716      operand to ease control flow.  */
28717   res = gen_reg_rtx (mode);
28718   emit_move_insn (res, operand1);
28719
28720   /* xa = abs (operand1) */
28721   xa = ix86_expand_sse_fabs (res, &mask);
28722
28723   /* if (!isless (xa, TWO52)) goto label; */
28724   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28725
28726   /* xa = (double)(long)x */
28727   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28728   expand_fix (xi, res, 0);
28729   expand_float (xa, xi, 0);
28730
28731   /* generate 1.0 */
28732   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
28733
28734   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
28735   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
28736   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28737                           gen_rtx_AND (mode, one, tmp)));
28738   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
28739                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28740   emit_move_insn (res, tmp);
28741
28742   if (HONOR_SIGNED_ZEROS (mode))
28743     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
28744
28745   emit_label (label);
28746   LABEL_NUSES (label) = 1;
28747
28748   emit_move_insn (operand0, res);
28749 }
28750
28751 /* Expand SSE sequence for computing round from OPERAND1 storing
28752    into OPERAND0.  Sequence that works without relying on DImode truncation
28753    via cvttsd2siq that is only available on 64bit targets.  */
28754 void
28755 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
28756 {
28757   /* C code for the stuff we expand below.
28758         double xa = fabs (x), xa2, x2;
28759         if (!isless (xa, TWO52))
28760           return x;
28761      Using the absolute value and copying back sign makes
28762      -0.0 -> -0.0 correct.
28763         xa2 = xa + TWO52 - TWO52;
28764      Compensate.
28765         dxa = xa2 - xa;
28766         if (dxa <= -0.5)
28767           xa2 += 1;
28768         else if (dxa > 0.5)
28769           xa2 -= 1;
28770         x2 = copysign (xa2, x);
28771         return x2;
28772    */
28773   enum machine_mode mode = GET_MODE (operand0);
28774   rtx xa, xa2, dxa, TWO52, tmp, label, half, mhalf, one, res, mask;
28775
28776   TWO52 = ix86_gen_TWO52 (mode);
28777
28778   /* Temporary for holding the result, initialized to the input
28779      operand to ease control flow.  */
28780   res = gen_reg_rtx (mode);
28781   emit_move_insn (res, operand1);
28782
28783   /* xa = abs (operand1) */
28784   xa = ix86_expand_sse_fabs (res, &mask);
28785
28786   /* if (!isless (xa, TWO52)) goto label; */
28787   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28788
28789   /* xa2 = xa + TWO52 - TWO52; */
28790   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28791   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
28792
28793   /* dxa = xa2 - xa; */
28794   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
28795
28796   /* generate 0.5, 1.0 and -0.5 */
28797   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
28798   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
28799   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
28800                                0, OPTAB_DIRECT);
28801
28802   /* Compensate.  */
28803   tmp = gen_reg_rtx (mode);
28804   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
28805   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
28806   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28807                           gen_rtx_AND (mode, one, tmp)));
28808   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28809   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
28810   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
28811   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28812                           gen_rtx_AND (mode, one, tmp)));
28813   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28814
28815   /* res = copysign (xa2, operand1) */
28816   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
28817
28818   emit_label (label);
28819   LABEL_NUSES (label) = 1;
28820
28821   emit_move_insn (operand0, res);
28822 }
28823
28824 /* Expand SSE sequence for computing trunc from OPERAND1 storing
28825    into OPERAND0.  */
28826 void
28827 ix86_expand_trunc (rtx operand0, rtx operand1)
28828 {
28829   /* C code for SSE variant we expand below.
28830         double xa = fabs (x), x2;
28831         if (!isless (xa, TWO52))
28832           return x;
28833         x2 = (double)(long)x;
28834         if (HONOR_SIGNED_ZEROS (mode))
28835           return copysign (x2, x);
28836         return x2;
28837    */
28838   enum machine_mode mode = GET_MODE (operand0);
28839   rtx xa, xi, TWO52, label, res, mask;
28840
28841   TWO52 = ix86_gen_TWO52 (mode);
28842
28843   /* Temporary for holding the result, initialized to the input
28844      operand to ease control flow.  */
28845   res = gen_reg_rtx (mode);
28846   emit_move_insn (res, operand1);
28847
28848   /* xa = abs (operand1) */
28849   xa = ix86_expand_sse_fabs (res, &mask);
28850
28851   /* if (!isless (xa, TWO52)) goto label; */
28852   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28853
28854   /* x = (double)(long)x */
28855   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28856   expand_fix (xi, res, 0);
28857   expand_float (res, xi, 0);
28858
28859   if (HONOR_SIGNED_ZEROS (mode))
28860     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
28861
28862   emit_label (label);
28863   LABEL_NUSES (label) = 1;
28864
28865   emit_move_insn (operand0, res);
28866 }
28867
28868 /* Expand SSE sequence for computing trunc from OPERAND1 storing
28869    into OPERAND0.  */
28870 void
28871 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
28872 {
28873   enum machine_mode mode = GET_MODE (operand0);
28874   rtx xa, mask, TWO52, label, one, res, smask, tmp;
28875
28876   /* C code for SSE variant we expand below.
28877         double xa = fabs (x), x2;
28878         if (!isless (xa, TWO52))
28879           return x;
28880         xa2 = xa + TWO52 - TWO52;
28881      Compensate:
28882         if (xa2 > xa)
28883           xa2 -= 1.0;
28884         x2 = copysign (xa2, x);
28885         return x2;
28886    */
28887
28888   TWO52 = ix86_gen_TWO52 (mode);
28889
28890   /* Temporary for holding the result, initialized to the input
28891      operand to ease control flow.  */
28892   res = gen_reg_rtx (mode);
28893   emit_move_insn (res, operand1);
28894
28895   /* xa = abs (operand1) */
28896   xa = ix86_expand_sse_fabs (res, &smask);
28897
28898   /* if (!isless (xa, TWO52)) goto label; */
28899   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28900
28901   /* res = xa + TWO52 - TWO52; */
28902   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28903   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
28904   emit_move_insn (res, tmp);
28905
28906   /* generate 1.0 */
28907   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
28908
28909   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
28910   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
28911   emit_insn (gen_rtx_SET (VOIDmode, mask,
28912                           gen_rtx_AND (mode, mask, one)));
28913   tmp = expand_simple_binop (mode, MINUS,
28914                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
28915   emit_move_insn (res, tmp);
28916
28917   /* res = copysign (res, operand1) */
28918   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
28919
28920   emit_label (label);
28921   LABEL_NUSES (label) = 1;
28922
28923   emit_move_insn (operand0, res);
28924 }
28925
28926 /* Expand SSE sequence for computing round from OPERAND1 storing
28927    into OPERAND0.  */
28928 void
28929 ix86_expand_round (rtx operand0, rtx operand1)
28930 {
28931   /* C code for the stuff we're doing below:
28932         double xa = fabs (x);
28933         if (!isless (xa, TWO52))
28934           return x;
28935         xa = (double)(long)(xa + nextafter (0.5, 0.0));
28936         return copysign (xa, x);
28937    */
28938   enum machine_mode mode = GET_MODE (operand0);
28939   rtx res, TWO52, xa, label, xi, half, mask;
28940   const struct real_format *fmt;
28941   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
28942
28943   /* Temporary for holding the result, initialized to the input
28944      operand to ease control flow.  */
28945   res = gen_reg_rtx (mode);
28946   emit_move_insn (res, operand1);
28947
28948   TWO52 = ix86_gen_TWO52 (mode);
28949   xa = ix86_expand_sse_fabs (res, &mask);
28950   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28951
28952   /* load nextafter (0.5, 0.0) */
28953   fmt = REAL_MODE_FORMAT (mode);
28954   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
28955   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
28956
28957   /* xa = xa + 0.5 */
28958   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
28959   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
28960
28961   /* xa = (double)(int64_t)xa */
28962   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28963   expand_fix (xi, xa, 0);
28964   expand_float (xa, xi, 0);
28965
28966   /* res = copysign (xa, operand1) */
28967   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
28968
28969   emit_label (label);
28970   LABEL_NUSES (label) = 1;
28971
28972   emit_move_insn (operand0, res);
28973 }
28974
28975 \f
28976 /* Validate whether a SSE5 instruction is valid or not.
28977    OPERANDS is the array of operands.
28978    NUM is the number of operands.
28979    USES_OC0 is true if the instruction uses OC0 and provides 4 variants.
28980    NUM_MEMORY is the maximum number of memory operands to accept.  
28981    when COMMUTATIVE is set, operand 1 and 2 can be swapped.  */
28982
28983 bool
28984 ix86_sse5_valid_op_p (rtx operands[], rtx insn ATTRIBUTE_UNUSED, int num,
28985                       bool uses_oc0, int num_memory, bool commutative)
28986 {
28987   int mem_mask;
28988   int mem_count;
28989   int i;
28990
28991   /* Count the number of memory arguments */
28992   mem_mask = 0;
28993   mem_count = 0;
28994   for (i = 0; i < num; i++)
28995     {
28996       enum machine_mode mode = GET_MODE (operands[i]);
28997       if (register_operand (operands[i], mode))
28998         ;
28999
29000       else if (memory_operand (operands[i], mode))
29001         {
29002           mem_mask |= (1 << i);
29003           mem_count++;
29004         }
29005
29006       else
29007         {
29008           rtx pattern = PATTERN (insn);
29009
29010           /* allow 0 for pcmov */
29011           if (GET_CODE (pattern) != SET
29012               || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE
29013               || i < 2
29014               || operands[i] != CONST0_RTX (mode))
29015             return false;
29016         }
29017     }
29018
29019   /* Special case pmacsdq{l,h} where we allow the 3rd argument to be
29020      a memory operation.  */
29021   if (num_memory < 0)
29022     {
29023       num_memory = -num_memory;
29024       if ((mem_mask & (1 << (num-1))) != 0)
29025         {
29026           mem_mask &= ~(1 << (num-1));
29027           mem_count--;
29028         }
29029     }
29030
29031   /* If there were no memory operations, allow the insn */
29032   if (mem_mask == 0)
29033     return true;
29034
29035   /* Do not allow the destination register to be a memory operand.  */
29036   else if (mem_mask & (1 << 0))
29037     return false;
29038
29039   /* If there are too many memory operations, disallow the instruction.  While
29040      the hardware only allows 1 memory reference, before register allocation
29041      for some insns, we allow two memory operations sometimes in order to allow
29042      code like the following to be optimized:
29043
29044         float fmadd (float *a, float *b, float *c) { return (*a * *b) + *c; }
29045
29046     or similar cases that are vectorized into using the fmaddss
29047     instruction.  */
29048   else if (mem_count > num_memory)
29049     return false;
29050
29051   /* Don't allow more than one memory operation if not optimizing.  */
29052   else if (mem_count > 1 && !optimize)
29053     return false;
29054
29055   else if (num == 4 && mem_count == 1)
29056     {
29057       /* formats (destination is the first argument), example fmaddss:
29058          xmm1, xmm1, xmm2, xmm3/mem
29059          xmm1, xmm1, xmm2/mem, xmm3
29060          xmm1, xmm2, xmm3/mem, xmm1
29061          xmm1, xmm2/mem, xmm3, xmm1 */
29062       if (uses_oc0)
29063         return ((mem_mask == (1 << 1))
29064                 || (mem_mask == (1 << 2))
29065                 || (mem_mask == (1 << 3)));
29066
29067       /* format, example pmacsdd:
29068          xmm1, xmm2, xmm3/mem, xmm1 */
29069       if (commutative)
29070         return (mem_mask == (1 << 2) || mem_mask == (1 << 1));
29071       else
29072         return (mem_mask == (1 << 2));
29073     }
29074
29075   else if (num == 4 && num_memory == 2)
29076     {
29077       /* If there are two memory operations, we can load one of the memory ops
29078          into the destination register.  This is for optimizing the
29079          multiply/add ops, which the combiner has optimized both the multiply
29080          and the add insns to have a memory operation.  We have to be careful
29081          that the destination doesn't overlap with the inputs.  */
29082       rtx op0 = operands[0];
29083
29084       if (reg_mentioned_p (op0, operands[1])
29085           || reg_mentioned_p (op0, operands[2])
29086           || reg_mentioned_p (op0, operands[3]))
29087         return false;
29088
29089       /* formats (destination is the first argument), example fmaddss:
29090          xmm1, xmm1, xmm2, xmm3/mem
29091          xmm1, xmm1, xmm2/mem, xmm3
29092          xmm1, xmm2, xmm3/mem, xmm1
29093          xmm1, xmm2/mem, xmm3, xmm1
29094
29095          For the oc0 case, we will load either operands[1] or operands[3] into
29096          operands[0], so any combination of 2 memory operands is ok.  */
29097       if (uses_oc0)
29098         return true;
29099
29100       /* format, example pmacsdd:
29101          xmm1, xmm2, xmm3/mem, xmm1
29102
29103          For the integer multiply/add instructions be more restrictive and
29104          require operands[2] and operands[3] to be the memory operands.  */
29105       if (commutative)
29106         return (mem_mask == ((1 << 1) | (1 << 3)) || ((1 << 2) | (1 << 3)));
29107       else
29108         return (mem_mask == ((1 << 2) | (1 << 3)));
29109     }
29110
29111   else if (num == 3 && num_memory == 1)
29112     {
29113       /* formats, example protb:
29114          xmm1, xmm2, xmm3/mem
29115          xmm1, xmm2/mem, xmm3 */
29116       if (uses_oc0)
29117         return ((mem_mask == (1 << 1)) || (mem_mask == (1 << 2)));
29118
29119       /* format, example comeq:
29120          xmm1, xmm2, xmm3/mem */
29121       else
29122         return (mem_mask == (1 << 2));
29123     }
29124
29125   else
29126     gcc_unreachable ();
29127
29128   return false;
29129 }
29130
29131 \f
29132 /* Fixup an SSE5 instruction that has 2 memory input references into a form the
29133    hardware will allow by using the destination register to load one of the
29134    memory operations.  Presently this is used by the multiply/add routines to
29135    allow 2 memory references.  */
29136
29137 void
29138 ix86_expand_sse5_multiple_memory (rtx operands[],
29139                                   int num,
29140                                   enum machine_mode mode)
29141 {
29142   rtx op0 = operands[0];
29143   if (num != 4
29144       || memory_operand (op0, mode)
29145       || reg_mentioned_p (op0, operands[1])
29146       || reg_mentioned_p (op0, operands[2])
29147       || reg_mentioned_p (op0, operands[3]))
29148     gcc_unreachable ();
29149
29150   /* For 2 memory operands, pick either operands[1] or operands[3] to move into
29151      the destination register.  */
29152   if (memory_operand (operands[1], mode))
29153     {
29154       emit_move_insn (op0, operands[1]);
29155       operands[1] = op0;
29156     }
29157   else if (memory_operand (operands[3], mode))
29158     {
29159       emit_move_insn (op0, operands[3]);
29160       operands[3] = op0;
29161     }
29162   else
29163     gcc_unreachable ();
29164
29165   return;
29166 }
29167
29168 \f
29169 /* Table of valid machine attributes.  */
29170 static const struct attribute_spec ix86_attribute_table[] =
29171 {
29172   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
29173   /* Stdcall attribute says callee is responsible for popping arguments
29174      if they are not variable.  */
29175   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29176   /* Fastcall attribute says callee is responsible for popping arguments
29177      if they are not variable.  */
29178   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29179   /* Cdecl attribute says the callee is a normal C declaration */
29180   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29181   /* Regparm attribute specifies how many integer arguments are to be
29182      passed in registers.  */
29183   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute },
29184   /* Sseregparm attribute says we are using x86_64 calling conventions
29185      for FP arguments.  */
29186   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute },
29187   /* force_align_arg_pointer says this function realigns the stack at entry.  */
29188   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
29189     false, true,  true, ix86_handle_cconv_attribute },
29190 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29191   { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
29192   { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
29193   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute },
29194 #endif
29195   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
29196   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
29197 #ifdef SUBTARGET_ATTRIBUTE_TABLE
29198   SUBTARGET_ATTRIBUTE_TABLE,
29199 #endif
29200   /* ms_abi and sysv_abi calling convention function attributes.  */
29201   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
29202   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
29203   /* End element.  */
29204   { NULL,        0, 0, false, false, false, NULL }
29205 };
29206
29207 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
29208 static int
29209 x86_builtin_vectorization_cost (bool runtime_test)
29210 {
29211   /* If the branch of the runtime test is taken - i.e. - the vectorized
29212      version is skipped - this incurs a misprediction cost (because the
29213      vectorized version is expected to be the fall-through).  So we subtract
29214      the latency of a mispredicted branch from the costs that are incured
29215      when the vectorized version is executed.
29216
29217      TODO: The values in individual target tables have to be tuned or new
29218      fields may be needed. For eg. on K8, the default branch path is the
29219      not-taken path. If the taken path is predicted correctly, the minimum
29220      penalty of going down the taken-path is 1 cycle. If the taken-path is
29221      not predicted correctly, then the minimum penalty is 10 cycles.  */
29222
29223   if (runtime_test)
29224     {
29225       return (-(ix86_cost->cond_taken_branch_cost));
29226     }
29227   else
29228     return 0;
29229 }
29230
29231 /* This function returns the calling abi specific va_list type node.
29232    It returns  the FNDECL specific va_list type.  */
29233
29234 tree
29235 ix86_fn_abi_va_list (tree fndecl)
29236 {
29237   int abi;
29238
29239   if (!TARGET_64BIT)
29240     return va_list_type_node;
29241   gcc_assert (fndecl != NULL_TREE);
29242   abi = ix86_function_abi ((const_tree) fndecl);
29243
29244   if (abi == MS_ABI)
29245     return ms_va_list_type_node;
29246   else
29247     return sysv_va_list_type_node;
29248 }
29249
29250 /* Returns the canonical va_list type specified by TYPE. If there
29251    is no valid TYPE provided, it return NULL_TREE.  */
29252
29253 tree
29254 ix86_canonical_va_list_type (tree type)
29255 {
29256   tree wtype, htype;
29257
29258   /* Resolve references and pointers to va_list type.  */
29259   if (INDIRECT_REF_P (type))
29260     type = TREE_TYPE (type);
29261   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
29262     type = TREE_TYPE (type);
29263
29264   if (TARGET_64BIT)
29265     {
29266       wtype = va_list_type_node;
29267           gcc_assert (wtype != NULL_TREE);
29268       htype = type;
29269       if (TREE_CODE (wtype) == ARRAY_TYPE)
29270         {
29271           /* If va_list is an array type, the argument may have decayed
29272              to a pointer type, e.g. by being passed to another function.
29273              In that case, unwrap both types so that we can compare the
29274              underlying records.  */
29275           if (TREE_CODE (htype) == ARRAY_TYPE
29276               || POINTER_TYPE_P (htype))
29277             {
29278               wtype = TREE_TYPE (wtype);
29279               htype = TREE_TYPE (htype);
29280             }
29281         }
29282       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29283         return va_list_type_node;
29284       wtype = sysv_va_list_type_node;
29285           gcc_assert (wtype != NULL_TREE);
29286       htype = type;
29287       if (TREE_CODE (wtype) == ARRAY_TYPE)
29288         {
29289           /* If va_list is an array type, the argument may have decayed
29290              to a pointer type, e.g. by being passed to another function.
29291              In that case, unwrap both types so that we can compare the
29292              underlying records.  */
29293           if (TREE_CODE (htype) == ARRAY_TYPE
29294               || POINTER_TYPE_P (htype))
29295             {
29296               wtype = TREE_TYPE (wtype);
29297               htype = TREE_TYPE (htype);
29298             }
29299         }
29300       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29301         return sysv_va_list_type_node;
29302       wtype = ms_va_list_type_node;
29303           gcc_assert (wtype != NULL_TREE);
29304       htype = type;
29305       if (TREE_CODE (wtype) == ARRAY_TYPE)
29306         {
29307           /* If va_list is an array type, the argument may have decayed
29308              to a pointer type, e.g. by being passed to another function.
29309              In that case, unwrap both types so that we can compare the
29310              underlying records.  */
29311           if (TREE_CODE (htype) == ARRAY_TYPE
29312               || POINTER_TYPE_P (htype))
29313             {
29314               wtype = TREE_TYPE (wtype);
29315               htype = TREE_TYPE (htype);
29316             }
29317         }
29318       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29319         return ms_va_list_type_node;
29320       return NULL_TREE;
29321     }
29322   return std_canonical_va_list_type (type);
29323 }
29324
29325 /* Iterate through the target-specific builtin types for va_list.
29326     IDX denotes the iterator, *PTREE is set to the result type of
29327     the va_list builtin, and *PNAME to its internal type.
29328     Returns zero if there is no element for this index, otherwise
29329     IDX should be increased upon the next call.
29330     Note, do not iterate a base builtin's name like __builtin_va_list.
29331     Used from c_common_nodes_and_builtins.  */
29332
29333 int
29334 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
29335 {
29336   if (!TARGET_64BIT)
29337     return 0;
29338   switch (idx) {
29339   case 0:
29340     *ptree = ms_va_list_type_node;
29341     *pname = "__builtin_ms_va_list";
29342     break;
29343   case 1:
29344     *ptree = sysv_va_list_type_node;
29345     *pname = "__builtin_sysv_va_list";
29346     break;
29347   default:
29348     return 0;
29349   }
29350   return 1;
29351 }
29352
29353 /* Initialize the GCC target structure.  */
29354 #undef TARGET_RETURN_IN_MEMORY
29355 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
29356
29357 #undef TARGET_ATTRIBUTE_TABLE
29358 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
29359 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29360 #  undef TARGET_MERGE_DECL_ATTRIBUTES
29361 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
29362 #endif
29363
29364 #undef TARGET_COMP_TYPE_ATTRIBUTES
29365 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
29366
29367 #undef TARGET_INIT_BUILTINS
29368 #define TARGET_INIT_BUILTINS ix86_init_builtins
29369 #undef TARGET_EXPAND_BUILTIN
29370 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
29371
29372 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
29373 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
29374   ix86_builtin_vectorized_function
29375
29376 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
29377 #define TARGET_VECTORIZE_BUILTIN_CONVERSION ix86_vectorize_builtin_conversion
29378
29379 #undef TARGET_BUILTIN_RECIPROCAL
29380 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
29381
29382 #undef TARGET_ASM_FUNCTION_EPILOGUE
29383 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
29384
29385 #undef TARGET_ENCODE_SECTION_INFO
29386 #ifndef SUBTARGET_ENCODE_SECTION_INFO
29387 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
29388 #else
29389 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
29390 #endif
29391
29392 #undef TARGET_ASM_OPEN_PAREN
29393 #define TARGET_ASM_OPEN_PAREN ""
29394 #undef TARGET_ASM_CLOSE_PAREN
29395 #define TARGET_ASM_CLOSE_PAREN ""
29396
29397 #undef TARGET_ASM_ALIGNED_HI_OP
29398 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
29399 #undef TARGET_ASM_ALIGNED_SI_OP
29400 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
29401 #ifdef ASM_QUAD
29402 #undef TARGET_ASM_ALIGNED_DI_OP
29403 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
29404 #endif
29405
29406 #undef TARGET_ASM_UNALIGNED_HI_OP
29407 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
29408 #undef TARGET_ASM_UNALIGNED_SI_OP
29409 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
29410 #undef TARGET_ASM_UNALIGNED_DI_OP
29411 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
29412
29413 #undef TARGET_SCHED_ADJUST_COST
29414 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
29415 #undef TARGET_SCHED_ISSUE_RATE
29416 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
29417 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
29418 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
29419   ia32_multipass_dfa_lookahead
29420
29421 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
29422 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
29423
29424 #ifdef HAVE_AS_TLS
29425 #undef TARGET_HAVE_TLS
29426 #define TARGET_HAVE_TLS true
29427 #endif
29428 #undef TARGET_CANNOT_FORCE_CONST_MEM
29429 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
29430 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
29431 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
29432
29433 #undef TARGET_DELEGITIMIZE_ADDRESS
29434 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
29435
29436 #undef TARGET_MS_BITFIELD_LAYOUT_P
29437 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
29438
29439 #if TARGET_MACHO
29440 #undef TARGET_BINDS_LOCAL_P
29441 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
29442 #endif
29443 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29444 #undef TARGET_BINDS_LOCAL_P
29445 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
29446 #endif
29447
29448 #undef TARGET_ASM_OUTPUT_MI_THUNK
29449 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
29450 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
29451 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
29452
29453 #undef TARGET_ASM_FILE_START
29454 #define TARGET_ASM_FILE_START x86_file_start
29455
29456 #undef TARGET_DEFAULT_TARGET_FLAGS
29457 #define TARGET_DEFAULT_TARGET_FLAGS     \
29458   (TARGET_DEFAULT                       \
29459    | TARGET_SUBTARGET_DEFAULT           \
29460    | TARGET_TLS_DIRECT_SEG_REFS_DEFAULT)
29461
29462 #undef TARGET_HANDLE_OPTION
29463 #define TARGET_HANDLE_OPTION ix86_handle_option
29464
29465 #undef TARGET_RTX_COSTS
29466 #define TARGET_RTX_COSTS ix86_rtx_costs
29467 #undef TARGET_ADDRESS_COST
29468 #define TARGET_ADDRESS_COST ix86_address_cost
29469
29470 #undef TARGET_FIXED_CONDITION_CODE_REGS
29471 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
29472 #undef TARGET_CC_MODES_COMPATIBLE
29473 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
29474
29475 #undef TARGET_MACHINE_DEPENDENT_REORG
29476 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
29477
29478 #undef TARGET_BUILD_BUILTIN_VA_LIST
29479 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
29480
29481 #undef TARGET_FN_ABI_VA_LIST
29482 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
29483
29484 #undef TARGET_CANONICAL_VA_LIST_TYPE
29485 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
29486
29487 #undef TARGET_EXPAND_BUILTIN_VA_START
29488 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
29489
29490 #undef TARGET_MD_ASM_CLOBBERS
29491 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
29492
29493 #undef TARGET_PROMOTE_PROTOTYPES
29494 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
29495 #undef TARGET_STRUCT_VALUE_RTX
29496 #define TARGET_STRUCT_VALUE_RTX ix86_struct_value_rtx
29497 #undef TARGET_SETUP_INCOMING_VARARGS
29498 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
29499 #undef TARGET_MUST_PASS_IN_STACK
29500 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
29501 #undef TARGET_PASS_BY_REFERENCE
29502 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
29503 #undef TARGET_INTERNAL_ARG_POINTER
29504 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
29505 #undef TARGET_UPDATE_STACK_BOUNDARY
29506 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
29507 #undef TARGET_GET_DRAP_RTX
29508 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
29509 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
29510 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC ix86_dwarf_handle_frame_unspec
29511 #undef TARGET_STRICT_ARGUMENT_NAMING
29512 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
29513
29514 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
29515 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
29516
29517 #undef TARGET_SCALAR_MODE_SUPPORTED_P
29518 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
29519
29520 #undef TARGET_VECTOR_MODE_SUPPORTED_P
29521 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
29522
29523 #undef TARGET_C_MODE_FOR_SUFFIX
29524 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
29525
29526 #ifdef HAVE_AS_TLS
29527 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
29528 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
29529 #endif
29530
29531 #ifdef SUBTARGET_INSERT_ATTRIBUTES
29532 #undef TARGET_INSERT_ATTRIBUTES
29533 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
29534 #endif
29535
29536 #undef TARGET_MANGLE_TYPE
29537 #define TARGET_MANGLE_TYPE ix86_mangle_type
29538
29539 #undef TARGET_STACK_PROTECT_FAIL
29540 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
29541
29542 #undef TARGET_FUNCTION_VALUE
29543 #define TARGET_FUNCTION_VALUE ix86_function_value
29544
29545 #undef TARGET_SECONDARY_RELOAD
29546 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
29547
29548 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
29549 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST x86_builtin_vectorization_cost
29550
29551 #undef TARGET_SET_CURRENT_FUNCTION
29552 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
29553
29554 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
29555 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
29556
29557 #undef TARGET_OPTION_SAVE
29558 #define TARGET_OPTION_SAVE ix86_function_specific_save
29559
29560 #undef TARGET_OPTION_RESTORE
29561 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
29562
29563 #undef TARGET_OPTION_PRINT
29564 #define TARGET_OPTION_PRINT ix86_function_specific_print
29565
29566 #undef TARGET_OPTION_CAN_INLINE_P
29567 #define TARGET_OPTION_CAN_INLINE_P ix86_can_inline_p
29568
29569 #undef TARGET_EXPAND_TO_RTL_HOOK
29570 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
29571
29572 struct gcc_target targetm = TARGET_INITIALIZER;
29573 \f
29574 #include "gt-i386.h"