OSDN Git Service

* i386.c (ix86_expand_movmem, ix86_expand_movstr): Avoid processing too
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.c
1 /* Subroutines used for code generation on IA-32.
2    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3    2002, 2003, 2004, 2005, 2006, 2007, 2008
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "tm_p.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "real.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "output.h"
35 #include "insn-codes.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "c-common.h"
39 #include "except.h"
40 #include "function.h"
41 #include "recog.h"
42 #include "expr.h"
43 #include "optabs.h"
44 #include "toplev.h"
45 #include "basic-block.h"
46 #include "ggc.h"
47 #include "target.h"
48 #include "target-def.h"
49 #include "langhooks.h"
50 #include "cgraph.h"
51 #include "gimple.h"
52 #include "dwarf2.h"
53 #include "df.h"
54 #include "tm-constrs.h"
55 #include "params.h"
56
57 static int x86_builtin_vectorization_cost (bool);
58 static rtx legitimize_dllimport_symbol (rtx, bool);
59
60 #ifndef CHECK_STACK_LIMIT
61 #define CHECK_STACK_LIMIT (-1)
62 #endif
63
64 /* Return index of given mode in mult and division cost tables.  */
65 #define MODE_INDEX(mode)                                        \
66   ((mode) == QImode ? 0                                         \
67    : (mode) == HImode ? 1                                       \
68    : (mode) == SImode ? 2                                       \
69    : (mode) == DImode ? 3                                       \
70    : 4)
71
72 /* Processor costs (relative to an add) */
73 /* We assume COSTS_N_INSNS is defined as (N)*4 and an addition is 2 bytes.  */
74 #define COSTS_N_BYTES(N) ((N) * 2)
75
76 #define DUMMY_STRINGOP_ALGS {libcall, {{-1, libcall}}}
77
78 const
79 struct processor_costs ix86_size_cost = {/* costs for tuning for size */
80   COSTS_N_BYTES (2),                    /* cost of an add instruction */
81   COSTS_N_BYTES (3),                    /* cost of a lea instruction */
82   COSTS_N_BYTES (2),                    /* variable shift costs */
83   COSTS_N_BYTES (3),                    /* constant shift costs */
84   {COSTS_N_BYTES (3),                   /* cost of starting multiply for QI */
85    COSTS_N_BYTES (3),                   /*                               HI */
86    COSTS_N_BYTES (3),                   /*                               SI */
87    COSTS_N_BYTES (3),                   /*                               DI */
88    COSTS_N_BYTES (5)},                  /*                            other */
89   0,                                    /* cost of multiply per each bit set */
90   {COSTS_N_BYTES (3),                   /* cost of a divide/mod for QI */
91    COSTS_N_BYTES (3),                   /*                          HI */
92    COSTS_N_BYTES (3),                   /*                          SI */
93    COSTS_N_BYTES (3),                   /*                          DI */
94    COSTS_N_BYTES (5)},                  /*                       other */
95   COSTS_N_BYTES (3),                    /* cost of movsx */
96   COSTS_N_BYTES (3),                    /* cost of movzx */
97   0,                                    /* "large" insn */
98   2,                                    /* MOVE_RATIO */
99   2,                                    /* cost for loading QImode using movzbl */
100   {2, 2, 2},                            /* cost of loading integer registers
101                                            in QImode, HImode and SImode.
102                                            Relative to reg-reg move (2).  */
103   {2, 2, 2},                            /* cost of storing integer registers */
104   2,                                    /* cost of reg,reg fld/fst */
105   {2, 2, 2},                            /* cost of loading fp registers
106                                            in SFmode, DFmode and XFmode */
107   {2, 2, 2},                            /* cost of storing fp registers
108                                            in SFmode, DFmode and XFmode */
109   3,                                    /* cost of moving MMX register */
110   {3, 3},                               /* cost of loading MMX registers
111                                            in SImode and DImode */
112   {3, 3},                               /* cost of storing MMX registers
113                                            in SImode and DImode */
114   3,                                    /* cost of moving SSE register */
115   {3, 3, 3},                            /* cost of loading SSE registers
116                                            in SImode, DImode and TImode */
117   {3, 3, 3},                            /* cost of storing SSE registers
118                                            in SImode, DImode and TImode */
119   3,                                    /* MMX or SSE register to integer */
120   0,                                    /* size of l1 cache  */
121   0,                                    /* size of l2 cache  */
122   0,                                    /* size of prefetch block */
123   0,                                    /* number of parallel prefetches */
124   2,                                    /* Branch cost */
125   COSTS_N_BYTES (2),                    /* cost of FADD and FSUB insns.  */
126   COSTS_N_BYTES (2),                    /* cost of FMUL instruction.  */
127   COSTS_N_BYTES (2),                    /* cost of FDIV instruction.  */
128   COSTS_N_BYTES (2),                    /* cost of FABS instruction.  */
129   COSTS_N_BYTES (2),                    /* cost of FCHS instruction.  */
130   COSTS_N_BYTES (2),                    /* cost of FSQRT instruction.  */
131   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
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   1,                                    /* scalar_stmt_cost.  */
136   1,                                    /* scalar load_cost.  */
137   1,                                    /* scalar_store_cost.  */
138   1,                                    /* vec_stmt_cost.  */
139   1,                                    /* vec_to_scalar_cost.  */
140   1,                                    /* scalar_to_vec_cost.  */
141   1,                                    /* vec_align_load_cost.  */
142   1,                                    /* vec_unalign_load_cost.  */
143   1,                                    /* vec_store_cost.  */
144   1,                                    /* cond_taken_branch_cost.  */
145   1,                                    /* cond_not_taken_branch_cost.  */
146 };
147
148 /* Processor costs (relative to an add) */
149 static const
150 struct processor_costs i386_cost = {    /* 386 specific costs */
151   COSTS_N_INSNS (1),                    /* cost of an add instruction */
152   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
153   COSTS_N_INSNS (3),                    /* variable shift costs */
154   COSTS_N_INSNS (2),                    /* constant shift costs */
155   {COSTS_N_INSNS (6),                   /* cost of starting multiply for QI */
156    COSTS_N_INSNS (6),                   /*                               HI */
157    COSTS_N_INSNS (6),                   /*                               SI */
158    COSTS_N_INSNS (6),                   /*                               DI */
159    COSTS_N_INSNS (6)},                  /*                               other */
160   COSTS_N_INSNS (1),                    /* cost of multiply per each bit set */
161   {COSTS_N_INSNS (23),                  /* cost of a divide/mod for QI */
162    COSTS_N_INSNS (23),                  /*                          HI */
163    COSTS_N_INSNS (23),                  /*                          SI */
164    COSTS_N_INSNS (23),                  /*                          DI */
165    COSTS_N_INSNS (23)},                 /*                          other */
166   COSTS_N_INSNS (3),                    /* cost of movsx */
167   COSTS_N_INSNS (2),                    /* cost of movzx */
168   15,                                   /* "large" insn */
169   3,                                    /* MOVE_RATIO */
170   4,                                    /* cost for loading QImode using movzbl */
171   {2, 4, 2},                            /* cost of loading integer registers
172                                            in QImode, HImode and SImode.
173                                            Relative to reg-reg move (2).  */
174   {2, 4, 2},                            /* cost of storing integer registers */
175   2,                                    /* cost of reg,reg fld/fst */
176   {8, 8, 8},                            /* cost of loading fp registers
177                                            in SFmode, DFmode and XFmode */
178   {8, 8, 8},                            /* cost of storing fp registers
179                                            in SFmode, DFmode and XFmode */
180   2,                                    /* cost of moving MMX register */
181   {4, 8},                               /* cost of loading MMX registers
182                                            in SImode and DImode */
183   {4, 8},                               /* cost of storing MMX registers
184                                            in SImode and DImode */
185   2,                                    /* cost of moving SSE register */
186   {4, 8, 16},                           /* cost of loading SSE registers
187                                            in SImode, DImode and TImode */
188   {4, 8, 16},                           /* cost of storing SSE registers
189                                            in SImode, DImode and TImode */
190   3,                                    /* MMX or SSE register to integer */
191   0,                                    /* size of l1 cache  */
192   0,                                    /* size of l2 cache  */
193   0,                                    /* size of prefetch block */
194   0,                                    /* number of parallel prefetches */
195   1,                                    /* Branch cost */
196   COSTS_N_INSNS (23),                   /* cost of FADD and FSUB insns.  */
197   COSTS_N_INSNS (27),                   /* cost of FMUL instruction.  */
198   COSTS_N_INSNS (88),                   /* cost of FDIV instruction.  */
199   COSTS_N_INSNS (22),                   /* cost of FABS instruction.  */
200   COSTS_N_INSNS (24),                   /* cost of FCHS instruction.  */
201   COSTS_N_INSNS (122),                  /* cost of FSQRT instruction.  */
202   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
203    DUMMY_STRINGOP_ALGS},
204   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
205    DUMMY_STRINGOP_ALGS},
206   1,                                    /* scalar_stmt_cost.  */
207   1,                                    /* scalar load_cost.  */
208   1,                                    /* scalar_store_cost.  */
209   1,                                    /* vec_stmt_cost.  */
210   1,                                    /* vec_to_scalar_cost.  */
211   1,                                    /* scalar_to_vec_cost.  */
212   1,                                    /* vec_align_load_cost.  */
213   2,                                    /* vec_unalign_load_cost.  */
214   1,                                    /* vec_store_cost.  */
215   3,                                    /* cond_taken_branch_cost.  */
216   1,                                    /* cond_not_taken_branch_cost.  */
217 };
218
219 static const
220 struct processor_costs i486_cost = {    /* 486 specific costs */
221   COSTS_N_INSNS (1),                    /* cost of an add instruction */
222   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
223   COSTS_N_INSNS (3),                    /* variable shift costs */
224   COSTS_N_INSNS (2),                    /* constant shift costs */
225   {COSTS_N_INSNS (12),                  /* cost of starting multiply for QI */
226    COSTS_N_INSNS (12),                  /*                               HI */
227    COSTS_N_INSNS (12),                  /*                               SI */
228    COSTS_N_INSNS (12),                  /*                               DI */
229    COSTS_N_INSNS (12)},                 /*                               other */
230   1,                                    /* cost of multiply per each bit set */
231   {COSTS_N_INSNS (40),                  /* cost of a divide/mod for QI */
232    COSTS_N_INSNS (40),                  /*                          HI */
233    COSTS_N_INSNS (40),                  /*                          SI */
234    COSTS_N_INSNS (40),                  /*                          DI */
235    COSTS_N_INSNS (40)},                 /*                          other */
236   COSTS_N_INSNS (3),                    /* cost of movsx */
237   COSTS_N_INSNS (2),                    /* cost of movzx */
238   15,                                   /* "large" insn */
239   3,                                    /* MOVE_RATIO */
240   4,                                    /* cost for loading QImode using movzbl */
241   {2, 4, 2},                            /* cost of loading integer registers
242                                            in QImode, HImode and SImode.
243                                            Relative to reg-reg move (2).  */
244   {2, 4, 2},                            /* cost of storing integer registers */
245   2,                                    /* cost of reg,reg fld/fst */
246   {8, 8, 8},                            /* cost of loading fp registers
247                                            in SFmode, DFmode and XFmode */
248   {8, 8, 8},                            /* cost of storing fp registers
249                                            in SFmode, DFmode and XFmode */
250   2,                                    /* cost of moving MMX register */
251   {4, 8},                               /* cost of loading MMX registers
252                                            in SImode and DImode */
253   {4, 8},                               /* cost of storing MMX registers
254                                            in SImode and DImode */
255   2,                                    /* cost of moving SSE register */
256   {4, 8, 16},                           /* cost of loading SSE registers
257                                            in SImode, DImode and TImode */
258   {4, 8, 16},                           /* cost of storing SSE registers
259                                            in SImode, DImode and TImode */
260   3,                                    /* MMX or SSE register to integer */
261   4,                                    /* size of l1 cache.  486 has 8kB cache
262                                            shared for code and data, so 4kB is
263                                            not really precise.  */
264   4,                                    /* size of l2 cache  */
265   0,                                    /* size of prefetch block */
266   0,                                    /* number of parallel prefetches */
267   1,                                    /* Branch cost */
268   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
269   COSTS_N_INSNS (16),                   /* cost of FMUL instruction.  */
270   COSTS_N_INSNS (73),                   /* cost of FDIV instruction.  */
271   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
272   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
273   COSTS_N_INSNS (83),                   /* cost of FSQRT instruction.  */
274   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
275    DUMMY_STRINGOP_ALGS},
276   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
277    DUMMY_STRINGOP_ALGS},
278   1,                                    /* scalar_stmt_cost.  */
279   1,                                    /* scalar load_cost.  */
280   1,                                    /* scalar_store_cost.  */
281   1,                                    /* vec_stmt_cost.  */
282   1,                                    /* vec_to_scalar_cost.  */
283   1,                                    /* scalar_to_vec_cost.  */
284   1,                                    /* vec_align_load_cost.  */
285   2,                                    /* vec_unalign_load_cost.  */
286   1,                                    /* vec_store_cost.  */
287   3,                                    /* cond_taken_branch_cost.  */
288   1,                                    /* cond_not_taken_branch_cost.  */
289 };
290
291 static const
292 struct processor_costs pentium_cost = {
293   COSTS_N_INSNS (1),                    /* cost of an add instruction */
294   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
295   COSTS_N_INSNS (4),                    /* variable shift costs */
296   COSTS_N_INSNS (1),                    /* constant shift costs */
297   {COSTS_N_INSNS (11),                  /* cost of starting multiply for QI */
298    COSTS_N_INSNS (11),                  /*                               HI */
299    COSTS_N_INSNS (11),                  /*                               SI */
300    COSTS_N_INSNS (11),                  /*                               DI */
301    COSTS_N_INSNS (11)},                 /*                               other */
302   0,                                    /* cost of multiply per each bit set */
303   {COSTS_N_INSNS (25),                  /* cost of a divide/mod for QI */
304    COSTS_N_INSNS (25),                  /*                          HI */
305    COSTS_N_INSNS (25),                  /*                          SI */
306    COSTS_N_INSNS (25),                  /*                          DI */
307    COSTS_N_INSNS (25)},                 /*                          other */
308   COSTS_N_INSNS (3),                    /* cost of movsx */
309   COSTS_N_INSNS (2),                    /* cost of movzx */
310   8,                                    /* "large" insn */
311   6,                                    /* MOVE_RATIO */
312   6,                                    /* cost for loading QImode using movzbl */
313   {2, 4, 2},                            /* cost of loading integer registers
314                                            in QImode, HImode and SImode.
315                                            Relative to reg-reg move (2).  */
316   {2, 4, 2},                            /* cost of storing integer registers */
317   2,                                    /* cost of reg,reg fld/fst */
318   {2, 2, 6},                            /* cost of loading fp registers
319                                            in SFmode, DFmode and XFmode */
320   {4, 4, 6},                            /* cost of storing fp registers
321                                            in SFmode, DFmode and XFmode */
322   8,                                    /* cost of moving MMX register */
323   {8, 8},                               /* cost of loading MMX registers
324                                            in SImode and DImode */
325   {8, 8},                               /* cost of storing MMX registers
326                                            in SImode and DImode */
327   2,                                    /* cost of moving SSE register */
328   {4, 8, 16},                           /* cost of loading SSE registers
329                                            in SImode, DImode and TImode */
330   {4, 8, 16},                           /* cost of storing SSE registers
331                                            in SImode, DImode and TImode */
332   3,                                    /* MMX or SSE register to integer */
333   8,                                    /* size of l1 cache.  */
334   8,                                    /* size of l2 cache  */
335   0,                                    /* size of prefetch block */
336   0,                                    /* number of parallel prefetches */
337   2,                                    /* Branch cost */
338   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
339   COSTS_N_INSNS (3),                    /* cost of FMUL instruction.  */
340   COSTS_N_INSNS (39),                   /* cost of FDIV instruction.  */
341   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
342   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
343   COSTS_N_INSNS (70),                   /* cost of FSQRT instruction.  */
344   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
345    DUMMY_STRINGOP_ALGS},
346   {{libcall, {{-1, rep_prefix_4_byte}}},
347    DUMMY_STRINGOP_ALGS},
348   1,                                    /* scalar_stmt_cost.  */
349   1,                                    /* scalar load_cost.  */
350   1,                                    /* scalar_store_cost.  */
351   1,                                    /* vec_stmt_cost.  */
352   1,                                    /* vec_to_scalar_cost.  */
353   1,                                    /* scalar_to_vec_cost.  */
354   1,                                    /* vec_align_load_cost.  */
355   2,                                    /* vec_unalign_load_cost.  */
356   1,                                    /* vec_store_cost.  */
357   3,                                    /* cond_taken_branch_cost.  */
358   1,                                    /* cond_not_taken_branch_cost.  */
359 };
360
361 static const
362 struct processor_costs pentiumpro_cost = {
363   COSTS_N_INSNS (1),                    /* cost of an add instruction */
364   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
365   COSTS_N_INSNS (1),                    /* variable shift costs */
366   COSTS_N_INSNS (1),                    /* constant shift costs */
367   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
368    COSTS_N_INSNS (4),                   /*                               HI */
369    COSTS_N_INSNS (4),                   /*                               SI */
370    COSTS_N_INSNS (4),                   /*                               DI */
371    COSTS_N_INSNS (4)},                  /*                               other */
372   0,                                    /* cost of multiply per each bit set */
373   {COSTS_N_INSNS (17),                  /* cost of a divide/mod for QI */
374    COSTS_N_INSNS (17),                  /*                          HI */
375    COSTS_N_INSNS (17),                  /*                          SI */
376    COSTS_N_INSNS (17),                  /*                          DI */
377    COSTS_N_INSNS (17)},                 /*                          other */
378   COSTS_N_INSNS (1),                    /* cost of movsx */
379   COSTS_N_INSNS (1),                    /* cost of movzx */
380   8,                                    /* "large" insn */
381   6,                                    /* MOVE_RATIO */
382   2,                                    /* cost for loading QImode using movzbl */
383   {4, 4, 4},                            /* cost of loading integer registers
384                                            in QImode, HImode and SImode.
385                                            Relative to reg-reg move (2).  */
386   {2, 2, 2},                            /* cost of storing integer registers */
387   2,                                    /* cost of reg,reg fld/fst */
388   {2, 2, 6},                            /* cost of loading fp registers
389                                            in SFmode, DFmode and XFmode */
390   {4, 4, 6},                            /* cost of storing fp registers
391                                            in SFmode, DFmode and XFmode */
392   2,                                    /* cost of moving MMX register */
393   {2, 2},                               /* cost of loading MMX registers
394                                            in SImode and DImode */
395   {2, 2},                               /* cost of storing MMX registers
396                                            in SImode and DImode */
397   2,                                    /* cost of moving SSE register */
398   {2, 2, 8},                            /* cost of loading SSE registers
399                                            in SImode, DImode and TImode */
400   {2, 2, 8},                            /* cost of storing SSE registers
401                                            in SImode, DImode and TImode */
402   3,                                    /* MMX or SSE register to integer */
403   8,                                    /* size of l1 cache.  */
404   256,                                  /* size of l2 cache  */
405   32,                                   /* size of prefetch block */
406   6,                                    /* number of parallel prefetches */
407   2,                                    /* Branch cost */
408   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
409   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
410   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
411   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
412   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
413   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
414   /* PentiumPro has optimized rep instructions for blocks aligned by 8 bytes (we ensure
415      the alignment).  For small blocks inline loop is still a noticeable win, for bigger
416      blocks either rep movsl or rep movsb is way to go.  Rep movsb has apparently
417      more expensive startup time in CPU, but after 4K the difference is down in the noise.
418    */
419   {{rep_prefix_4_byte, {{128, loop}, {1024, unrolled_loop},
420                         {8192, rep_prefix_4_byte}, {-1, rep_prefix_1_byte}}},
421    DUMMY_STRINGOP_ALGS},
422   {{rep_prefix_4_byte, {{1024, unrolled_loop},
423                         {8192, rep_prefix_4_byte}, {-1, libcall}}},
424    DUMMY_STRINGOP_ALGS},
425   1,                                    /* scalar_stmt_cost.  */
426   1,                                    /* scalar load_cost.  */
427   1,                                    /* scalar_store_cost.  */
428   1,                                    /* vec_stmt_cost.  */
429   1,                                    /* vec_to_scalar_cost.  */
430   1,                                    /* scalar_to_vec_cost.  */
431   1,                                    /* vec_align_load_cost.  */
432   2,                                    /* vec_unalign_load_cost.  */
433   1,                                    /* vec_store_cost.  */
434   3,                                    /* cond_taken_branch_cost.  */
435   1,                                    /* cond_not_taken_branch_cost.  */
436 };
437
438 static const
439 struct processor_costs geode_cost = {
440   COSTS_N_INSNS (1),                    /* cost of an add instruction */
441   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
442   COSTS_N_INSNS (2),                    /* variable shift costs */
443   COSTS_N_INSNS (1),                    /* constant shift costs */
444   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
445    COSTS_N_INSNS (4),                   /*                               HI */
446    COSTS_N_INSNS (7),                   /*                               SI */
447    COSTS_N_INSNS (7),                   /*                               DI */
448    COSTS_N_INSNS (7)},                  /*                               other */
449   0,                                    /* cost of multiply per each bit set */
450   {COSTS_N_INSNS (15),                  /* cost of a divide/mod for QI */
451    COSTS_N_INSNS (23),                  /*                          HI */
452    COSTS_N_INSNS (39),                  /*                          SI */
453    COSTS_N_INSNS (39),                  /*                          DI */
454    COSTS_N_INSNS (39)},                 /*                          other */
455   COSTS_N_INSNS (1),                    /* cost of movsx */
456   COSTS_N_INSNS (1),                    /* cost of movzx */
457   8,                                    /* "large" insn */
458   4,                                    /* MOVE_RATIO */
459   1,                                    /* cost for loading QImode using movzbl */
460   {1, 1, 1},                            /* cost of loading integer registers
461                                            in QImode, HImode and SImode.
462                                            Relative to reg-reg move (2).  */
463   {1, 1, 1},                            /* cost of storing integer registers */
464   1,                                    /* cost of reg,reg fld/fst */
465   {1, 1, 1},                            /* cost of loading fp registers
466                                            in SFmode, DFmode and XFmode */
467   {4, 6, 6},                            /* cost of storing fp registers
468                                            in SFmode, DFmode and XFmode */
469
470   1,                                    /* cost of moving MMX register */
471   {1, 1},                               /* cost of loading MMX registers
472                                            in SImode and DImode */
473   {1, 1},                               /* cost of storing MMX registers
474                                            in SImode and DImode */
475   1,                                    /* cost of moving SSE register */
476   {1, 1, 1},                            /* cost of loading SSE registers
477                                            in SImode, DImode and TImode */
478   {1, 1, 1},                            /* cost of storing SSE registers
479                                            in SImode, DImode and TImode */
480   1,                                    /* MMX or SSE register to integer */
481   64,                                   /* size of l1 cache.  */
482   128,                                  /* size of l2 cache.  */
483   32,                                   /* size of prefetch block */
484   1,                                    /* number of parallel prefetches */
485   1,                                    /* Branch cost */
486   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
487   COSTS_N_INSNS (11),                   /* cost of FMUL instruction.  */
488   COSTS_N_INSNS (47),                   /* cost of FDIV instruction.  */
489   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
490   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
491   COSTS_N_INSNS (54),                   /* cost of FSQRT instruction.  */
492   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
493    DUMMY_STRINGOP_ALGS},
494   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
495    DUMMY_STRINGOP_ALGS},
496   1,                                    /* scalar_stmt_cost.  */
497   1,                                    /* scalar load_cost.  */
498   1,                                    /* scalar_store_cost.  */
499   1,                                    /* vec_stmt_cost.  */
500   1,                                    /* vec_to_scalar_cost.  */
501   1,                                    /* scalar_to_vec_cost.  */
502   1,                                    /* vec_align_load_cost.  */
503   2,                                    /* vec_unalign_load_cost.  */
504   1,                                    /* vec_store_cost.  */
505   3,                                    /* cond_taken_branch_cost.  */
506   1,                                    /* cond_not_taken_branch_cost.  */
507 };
508
509 static const
510 struct processor_costs k6_cost = {
511   COSTS_N_INSNS (1),                    /* cost of an add instruction */
512   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
513   COSTS_N_INSNS (1),                    /* variable shift costs */
514   COSTS_N_INSNS (1),                    /* constant shift costs */
515   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
516    COSTS_N_INSNS (3),                   /*                               HI */
517    COSTS_N_INSNS (3),                   /*                               SI */
518    COSTS_N_INSNS (3),                   /*                               DI */
519    COSTS_N_INSNS (3)},                  /*                               other */
520   0,                                    /* cost of multiply per each bit set */
521   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
522    COSTS_N_INSNS (18),                  /*                          HI */
523    COSTS_N_INSNS (18),                  /*                          SI */
524    COSTS_N_INSNS (18),                  /*                          DI */
525    COSTS_N_INSNS (18)},                 /*                          other */
526   COSTS_N_INSNS (2),                    /* cost of movsx */
527   COSTS_N_INSNS (2),                    /* cost of movzx */
528   8,                                    /* "large" insn */
529   4,                                    /* MOVE_RATIO */
530   3,                                    /* cost for loading QImode using movzbl */
531   {4, 5, 4},                            /* cost of loading integer registers
532                                            in QImode, HImode and SImode.
533                                            Relative to reg-reg move (2).  */
534   {2, 3, 2},                            /* cost of storing integer registers */
535   4,                                    /* cost of reg,reg fld/fst */
536   {6, 6, 6},                            /* cost of loading fp registers
537                                            in SFmode, DFmode and XFmode */
538   {4, 4, 4},                            /* cost of storing fp registers
539                                            in SFmode, DFmode and XFmode */
540   2,                                    /* cost of moving MMX register */
541   {2, 2},                               /* cost of loading MMX registers
542                                            in SImode and DImode */
543   {2, 2},                               /* cost of storing MMX registers
544                                            in SImode and DImode */
545   2,                                    /* cost of moving SSE register */
546   {2, 2, 8},                            /* cost of loading SSE registers
547                                            in SImode, DImode and TImode */
548   {2, 2, 8},                            /* cost of storing SSE registers
549                                            in SImode, DImode and TImode */
550   6,                                    /* MMX or SSE register to integer */
551   32,                                   /* size of l1 cache.  */
552   32,                                   /* size of l2 cache.  Some models
553                                            have integrated l2 cache, but
554                                            optimizing for k6 is not important
555                                            enough to worry about that.  */
556   32,                                   /* size of prefetch block */
557   1,                                    /* number of parallel prefetches */
558   1,                                    /* Branch cost */
559   COSTS_N_INSNS (2),                    /* cost of FADD and FSUB insns.  */
560   COSTS_N_INSNS (2),                    /* cost of FMUL instruction.  */
561   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
562   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
563   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
564   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
565   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
566    DUMMY_STRINGOP_ALGS},
567   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
568    DUMMY_STRINGOP_ALGS},
569   1,                                    /* scalar_stmt_cost.  */
570   1,                                    /* scalar load_cost.  */
571   1,                                    /* scalar_store_cost.  */
572   1,                                    /* vec_stmt_cost.  */
573   1,                                    /* vec_to_scalar_cost.  */
574   1,                                    /* scalar_to_vec_cost.  */
575   1,                                    /* vec_align_load_cost.  */
576   2,                                    /* vec_unalign_load_cost.  */
577   1,                                    /* vec_store_cost.  */
578   3,                                    /* cond_taken_branch_cost.  */
579   1,                                    /* cond_not_taken_branch_cost.  */
580 };
581
582 static const
583 struct processor_costs athlon_cost = {
584   COSTS_N_INSNS (1),                    /* cost of an add instruction */
585   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
586   COSTS_N_INSNS (1),                    /* variable shift costs */
587   COSTS_N_INSNS (1),                    /* constant shift costs */
588   {COSTS_N_INSNS (5),                   /* cost of starting multiply for QI */
589    COSTS_N_INSNS (5),                   /*                               HI */
590    COSTS_N_INSNS (5),                   /*                               SI */
591    COSTS_N_INSNS (5),                   /*                               DI */
592    COSTS_N_INSNS (5)},                  /*                               other */
593   0,                                    /* cost of multiply per each bit set */
594   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
595    COSTS_N_INSNS (26),                  /*                          HI */
596    COSTS_N_INSNS (42),                  /*                          SI */
597    COSTS_N_INSNS (74),                  /*                          DI */
598    COSTS_N_INSNS (74)},                 /*                          other */
599   COSTS_N_INSNS (1),                    /* cost of movsx */
600   COSTS_N_INSNS (1),                    /* cost of movzx */
601   8,                                    /* "large" insn */
602   9,                                    /* MOVE_RATIO */
603   4,                                    /* cost for loading QImode using movzbl */
604   {3, 4, 3},                            /* cost of loading integer registers
605                                            in QImode, HImode and SImode.
606                                            Relative to reg-reg move (2).  */
607   {3, 4, 3},                            /* cost of storing integer registers */
608   4,                                    /* cost of reg,reg fld/fst */
609   {4, 4, 12},                           /* cost of loading fp registers
610                                            in SFmode, DFmode and XFmode */
611   {6, 6, 8},                            /* cost of storing fp registers
612                                            in SFmode, DFmode and XFmode */
613   2,                                    /* cost of moving MMX register */
614   {4, 4},                               /* cost of loading MMX registers
615                                            in SImode and DImode */
616   {4, 4},                               /* cost of storing MMX registers
617                                            in SImode and DImode */
618   2,                                    /* cost of moving SSE register */
619   {4, 4, 6},                            /* cost of loading SSE registers
620                                            in SImode, DImode and TImode */
621   {4, 4, 5},                            /* cost of storing SSE registers
622                                            in SImode, DImode and TImode */
623   5,                                    /* MMX or SSE register to integer */
624   64,                                   /* size of l1 cache.  */
625   256,                                  /* size of l2 cache.  */
626   64,                                   /* size of prefetch block */
627   6,                                    /* number of parallel prefetches */
628   5,                                    /* Branch cost */
629   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
630   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
631   COSTS_N_INSNS (24),                   /* cost of FDIV instruction.  */
632   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
633   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
634   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
635   /* For some reason, Athlon deals better with REP prefix (relative to loops)
636      compared to K8. Alignment becomes important after 8 bytes for memcpy and
637      128 bytes for memset.  */
638   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
639    DUMMY_STRINGOP_ALGS},
640   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
641    DUMMY_STRINGOP_ALGS},
642   1,                                    /* scalar_stmt_cost.  */
643   1,                                    /* scalar load_cost.  */
644   1,                                    /* scalar_store_cost.  */
645   1,                                    /* vec_stmt_cost.  */
646   1,                                    /* vec_to_scalar_cost.  */
647   1,                                    /* scalar_to_vec_cost.  */
648   1,                                    /* vec_align_load_cost.  */
649   2,                                    /* vec_unalign_load_cost.  */
650   1,                                    /* vec_store_cost.  */
651   3,                                    /* cond_taken_branch_cost.  */
652   1,                                    /* cond_not_taken_branch_cost.  */
653 };
654
655 static const
656 struct processor_costs k8_cost = {
657   COSTS_N_INSNS (1),                    /* cost of an add instruction */
658   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
659   COSTS_N_INSNS (1),                    /* variable shift costs */
660   COSTS_N_INSNS (1),                    /* constant shift costs */
661   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
662    COSTS_N_INSNS (4),                   /*                               HI */
663    COSTS_N_INSNS (3),                   /*                               SI */
664    COSTS_N_INSNS (4),                   /*                               DI */
665    COSTS_N_INSNS (5)},                  /*                               other */
666   0,                                    /* cost of multiply per each bit set */
667   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
668    COSTS_N_INSNS (26),                  /*                          HI */
669    COSTS_N_INSNS (42),                  /*                          SI */
670    COSTS_N_INSNS (74),                  /*                          DI */
671    COSTS_N_INSNS (74)},                 /*                          other */
672   COSTS_N_INSNS (1),                    /* cost of movsx */
673   COSTS_N_INSNS (1),                    /* cost of movzx */
674   8,                                    /* "large" insn */
675   9,                                    /* MOVE_RATIO */
676   4,                                    /* cost for loading QImode using movzbl */
677   {3, 4, 3},                            /* cost of loading integer registers
678                                            in QImode, HImode and SImode.
679                                            Relative to reg-reg move (2).  */
680   {3, 4, 3},                            /* cost of storing integer registers */
681   4,                                    /* cost of reg,reg fld/fst */
682   {4, 4, 12},                           /* cost of loading fp registers
683                                            in SFmode, DFmode and XFmode */
684   {6, 6, 8},                            /* cost of storing fp registers
685                                            in SFmode, DFmode and XFmode */
686   2,                                    /* cost of moving MMX register */
687   {3, 3},                               /* cost of loading MMX registers
688                                            in SImode and DImode */
689   {4, 4},                               /* cost of storing MMX registers
690                                            in SImode and DImode */
691   2,                                    /* cost of moving SSE register */
692   {4, 3, 6},                            /* cost of loading SSE registers
693                                            in SImode, DImode and TImode */
694   {4, 4, 5},                            /* cost of storing SSE registers
695                                            in SImode, DImode and TImode */
696   5,                                    /* MMX or SSE register to integer */
697   64,                                   /* size of l1 cache.  */
698   512,                                  /* size of l2 cache.  */
699   64,                                   /* size of prefetch block */
700   /* New AMD processors never drop prefetches; if they cannot be performed
701      immediately, they are queued.  We set number of simultaneous prefetches
702      to a large constant to reflect this (it probably is not a good idea not
703      to limit number of prefetches at all, as their execution also takes some
704      time).  */
705   100,                                  /* number of parallel prefetches */
706   3,                                    /* Branch cost */
707   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
708   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
709   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
710   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
711   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
712   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
713   /* K8 has optimized REP instruction for medium sized blocks, but for very small
714      blocks it is better to use loop. For large blocks, libcall can do
715      nontemporary accesses and beat inline considerably.  */
716   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
717    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
718   {{libcall, {{8, loop}, {24, unrolled_loop},
719               {2048, rep_prefix_4_byte}, {-1, libcall}}},
720    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
721   4,                                    /* scalar_stmt_cost.  */
722   2,                                    /* scalar load_cost.  */
723   2,                                    /* scalar_store_cost.  */
724   5,                                    /* vec_stmt_cost.  */
725   0,                                    /* vec_to_scalar_cost.  */
726   2,                                    /* scalar_to_vec_cost.  */
727   2,                                    /* vec_align_load_cost.  */
728   3,                                    /* vec_unalign_load_cost.  */
729   3,                                    /* vec_store_cost.  */
730   3,                                    /* cond_taken_branch_cost.  */
731   2,                                    /* cond_not_taken_branch_cost.  */
732 };
733
734 struct processor_costs amdfam10_cost = {
735   COSTS_N_INSNS (1),                    /* cost of an add instruction */
736   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
737   COSTS_N_INSNS (1),                    /* variable shift costs */
738   COSTS_N_INSNS (1),                    /* constant shift costs */
739   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
740    COSTS_N_INSNS (4),                   /*                               HI */
741    COSTS_N_INSNS (3),                   /*                               SI */
742    COSTS_N_INSNS (4),                   /*                               DI */
743    COSTS_N_INSNS (5)},                  /*                               other */
744   0,                                    /* cost of multiply per each bit set */
745   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
746    COSTS_N_INSNS (35),                  /*                          HI */
747    COSTS_N_INSNS (51),                  /*                          SI */
748    COSTS_N_INSNS (83),                  /*                          DI */
749    COSTS_N_INSNS (83)},                 /*                          other */
750   COSTS_N_INSNS (1),                    /* cost of movsx */
751   COSTS_N_INSNS (1),                    /* cost of movzx */
752   8,                                    /* "large" insn */
753   9,                                    /* MOVE_RATIO */
754   4,                                    /* cost for loading QImode using movzbl */
755   {3, 4, 3},                            /* cost of loading integer registers
756                                            in QImode, HImode and SImode.
757                                            Relative to reg-reg move (2).  */
758   {3, 4, 3},                            /* cost of storing integer registers */
759   4,                                    /* cost of reg,reg fld/fst */
760   {4, 4, 12},                           /* cost of loading fp registers
761                                            in SFmode, DFmode and XFmode */
762   {6, 6, 8},                            /* cost of storing fp registers
763                                            in SFmode, DFmode and XFmode */
764   2,                                    /* cost of moving MMX register */
765   {3, 3},                               /* cost of loading MMX registers
766                                            in SImode and DImode */
767   {4, 4},                               /* cost of storing MMX registers
768                                            in SImode and DImode */
769   2,                                    /* cost of moving SSE register */
770   {4, 4, 3},                            /* cost of loading SSE registers
771                                            in SImode, DImode and TImode */
772   {4, 4, 5},                            /* cost of storing SSE registers
773                                            in SImode, DImode and TImode */
774   3,                                    /* MMX or SSE register to integer */
775                                         /* On K8
776                                             MOVD reg64, xmmreg  Double  FSTORE 4
777                                             MOVD reg32, xmmreg  Double  FSTORE 4
778                                            On AMDFAM10
779                                             MOVD reg64, xmmreg  Double  FADD 3
780                                                                 1/1  1/1
781                                             MOVD reg32, xmmreg  Double  FADD 3
782                                                                 1/1  1/1 */
783   64,                                   /* size of l1 cache.  */
784   512,                                  /* size of l2 cache.  */
785   64,                                   /* size of prefetch block */
786   /* New AMD processors never drop prefetches; if they cannot be performed
787      immediately, they are queued.  We set number of simultaneous prefetches
788      to a large constant to reflect this (it probably is not a good idea not
789      to limit number of prefetches at all, as their execution also takes some
790      time).  */
791   100,                                  /* number of parallel prefetches */
792   2,                                    /* Branch cost */
793   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
794   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
795   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
796   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
797   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
798   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
799
800   /* AMDFAM10 has optimized REP instruction for medium sized blocks, but for
801      very small blocks it is better to use loop. For large blocks, libcall can
802      do nontemporary accesses and beat inline considerably.  */
803   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
804    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
805   {{libcall, {{8, loop}, {24, unrolled_loop},
806               {2048, rep_prefix_4_byte}, {-1, libcall}}},
807    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
808   4,                                    /* scalar_stmt_cost.  */
809   2,                                    /* scalar load_cost.  */
810   2,                                    /* scalar_store_cost.  */
811   6,                                    /* vec_stmt_cost.  */
812   0,                                    /* vec_to_scalar_cost.  */
813   2,                                    /* scalar_to_vec_cost.  */
814   2,                                    /* vec_align_load_cost.  */
815   2,                                    /* vec_unalign_load_cost.  */
816   2,                                    /* vec_store_cost.  */
817   2,                                    /* cond_taken_branch_cost.  */
818   1,                                    /* cond_not_taken_branch_cost.  */
819 };
820
821 static const
822 struct processor_costs pentium4_cost = {
823   COSTS_N_INSNS (1),                    /* cost of an add instruction */
824   COSTS_N_INSNS (3),                    /* cost of a lea instruction */
825   COSTS_N_INSNS (4),                    /* variable shift costs */
826   COSTS_N_INSNS (4),                    /* constant shift costs */
827   {COSTS_N_INSNS (15),                  /* cost of starting multiply for QI */
828    COSTS_N_INSNS (15),                  /*                               HI */
829    COSTS_N_INSNS (15),                  /*                               SI */
830    COSTS_N_INSNS (15),                  /*                               DI */
831    COSTS_N_INSNS (15)},                 /*                               other */
832   0,                                    /* cost of multiply per each bit set */
833   {COSTS_N_INSNS (56),                  /* cost of a divide/mod for QI */
834    COSTS_N_INSNS (56),                  /*                          HI */
835    COSTS_N_INSNS (56),                  /*                          SI */
836    COSTS_N_INSNS (56),                  /*                          DI */
837    COSTS_N_INSNS (56)},                 /*                          other */
838   COSTS_N_INSNS (1),                    /* cost of movsx */
839   COSTS_N_INSNS (1),                    /* cost of movzx */
840   16,                                   /* "large" insn */
841   6,                                    /* MOVE_RATIO */
842   2,                                    /* cost for loading QImode using movzbl */
843   {4, 5, 4},                            /* cost of loading integer registers
844                                            in QImode, HImode and SImode.
845                                            Relative to reg-reg move (2).  */
846   {2, 3, 2},                            /* cost of storing integer registers */
847   2,                                    /* cost of reg,reg fld/fst */
848   {2, 2, 6},                            /* cost of loading fp registers
849                                            in SFmode, DFmode and XFmode */
850   {4, 4, 6},                            /* cost of storing fp registers
851                                            in SFmode, DFmode and XFmode */
852   2,                                    /* cost of moving MMX register */
853   {2, 2},                               /* cost of loading MMX registers
854                                            in SImode and DImode */
855   {2, 2},                               /* cost of storing MMX registers
856                                            in SImode and DImode */
857   12,                                   /* cost of moving SSE register */
858   {12, 12, 12},                         /* cost of loading SSE registers
859                                            in SImode, DImode and TImode */
860   {2, 2, 8},                            /* cost of storing SSE registers
861                                            in SImode, DImode and TImode */
862   10,                                   /* MMX or SSE register to integer */
863   8,                                    /* size of l1 cache.  */
864   256,                                  /* size of l2 cache.  */
865   64,                                   /* size of prefetch block */
866   6,                                    /* number of parallel prefetches */
867   2,                                    /* Branch cost */
868   COSTS_N_INSNS (5),                    /* cost of FADD and FSUB insns.  */
869   COSTS_N_INSNS (7),                    /* cost of FMUL instruction.  */
870   COSTS_N_INSNS (43),                   /* cost of FDIV instruction.  */
871   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
872   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
873   COSTS_N_INSNS (43),                   /* cost of FSQRT instruction.  */
874   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
875    DUMMY_STRINGOP_ALGS},
876   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
877    {-1, libcall}}},
878    DUMMY_STRINGOP_ALGS},
879   1,                                    /* scalar_stmt_cost.  */
880   1,                                    /* scalar load_cost.  */
881   1,                                    /* scalar_store_cost.  */
882   1,                                    /* vec_stmt_cost.  */
883   1,                                    /* vec_to_scalar_cost.  */
884   1,                                    /* scalar_to_vec_cost.  */
885   1,                                    /* vec_align_load_cost.  */
886   2,                                    /* vec_unalign_load_cost.  */
887   1,                                    /* vec_store_cost.  */
888   3,                                    /* cond_taken_branch_cost.  */
889   1,                                    /* cond_not_taken_branch_cost.  */
890 };
891
892 static const
893 struct processor_costs nocona_cost = {
894   COSTS_N_INSNS (1),                    /* cost of an add instruction */
895   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
896   COSTS_N_INSNS (1),                    /* variable shift costs */
897   COSTS_N_INSNS (1),                    /* constant shift costs */
898   {COSTS_N_INSNS (10),                  /* cost of starting multiply for QI */
899    COSTS_N_INSNS (10),                  /*                               HI */
900    COSTS_N_INSNS (10),                  /*                               SI */
901    COSTS_N_INSNS (10),                  /*                               DI */
902    COSTS_N_INSNS (10)},                 /*                               other */
903   0,                                    /* cost of multiply per each bit set */
904   {COSTS_N_INSNS (66),                  /* cost of a divide/mod for QI */
905    COSTS_N_INSNS (66),                  /*                          HI */
906    COSTS_N_INSNS (66),                  /*                          SI */
907    COSTS_N_INSNS (66),                  /*                          DI */
908    COSTS_N_INSNS (66)},                 /*                          other */
909   COSTS_N_INSNS (1),                    /* cost of movsx */
910   COSTS_N_INSNS (1),                    /* cost of movzx */
911   16,                                   /* "large" insn */
912   17,                                   /* MOVE_RATIO */
913   4,                                    /* cost for loading QImode using movzbl */
914   {4, 4, 4},                            /* cost of loading integer registers
915                                            in QImode, HImode and SImode.
916                                            Relative to reg-reg move (2).  */
917   {4, 4, 4},                            /* cost of storing integer registers */
918   3,                                    /* cost of reg,reg fld/fst */
919   {12, 12, 12},                         /* cost of loading fp registers
920                                            in SFmode, DFmode and XFmode */
921   {4, 4, 4},                            /* cost of storing fp registers
922                                            in SFmode, DFmode and XFmode */
923   6,                                    /* cost of moving MMX register */
924   {12, 12},                             /* cost of loading MMX registers
925                                            in SImode and DImode */
926   {12, 12},                             /* cost of storing MMX registers
927                                            in SImode and DImode */
928   6,                                    /* cost of moving SSE register */
929   {12, 12, 12},                         /* cost of loading SSE registers
930                                            in SImode, DImode and TImode */
931   {12, 12, 12},                         /* cost of storing SSE registers
932                                            in SImode, DImode and TImode */
933   8,                                    /* MMX or SSE register to integer */
934   8,                                    /* size of l1 cache.  */
935   1024,                                 /* size of l2 cache.  */
936   128,                                  /* size of prefetch block */
937   8,                                    /* number of parallel prefetches */
938   1,                                    /* Branch cost */
939   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
940   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
941   COSTS_N_INSNS (40),                   /* cost of FDIV instruction.  */
942   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
943   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
944   COSTS_N_INSNS (44),                   /* cost of FSQRT instruction.  */
945   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
946    {libcall, {{32, loop}, {20000, rep_prefix_8_byte},
947               {100000, unrolled_loop}, {-1, libcall}}}},
948   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
949    {-1, libcall}}},
950    {libcall, {{24, loop}, {64, unrolled_loop},
951               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
952   1,                                    /* scalar_stmt_cost.  */
953   1,                                    /* scalar load_cost.  */
954   1,                                    /* scalar_store_cost.  */
955   1,                                    /* vec_stmt_cost.  */
956   1,                                    /* vec_to_scalar_cost.  */
957   1,                                    /* scalar_to_vec_cost.  */
958   1,                                    /* vec_align_load_cost.  */
959   2,                                    /* vec_unalign_load_cost.  */
960   1,                                    /* vec_store_cost.  */
961   3,                                    /* cond_taken_branch_cost.  */
962   1,                                    /* cond_not_taken_branch_cost.  */
963 };
964
965 static const
966 struct processor_costs core2_cost = {
967   COSTS_N_INSNS (1),                    /* cost of an add instruction */
968   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
969   COSTS_N_INSNS (1),                    /* variable shift costs */
970   COSTS_N_INSNS (1),                    /* constant shift costs */
971   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
972    COSTS_N_INSNS (3),                   /*                               HI */
973    COSTS_N_INSNS (3),                   /*                               SI */
974    COSTS_N_INSNS (3),                   /*                               DI */
975    COSTS_N_INSNS (3)},                  /*                               other */
976   0,                                    /* cost of multiply per each bit set */
977   {COSTS_N_INSNS (22),                  /* cost of a divide/mod for QI */
978    COSTS_N_INSNS (22),                  /*                          HI */
979    COSTS_N_INSNS (22),                  /*                          SI */
980    COSTS_N_INSNS (22),                  /*                          DI */
981    COSTS_N_INSNS (22)},                 /*                          other */
982   COSTS_N_INSNS (1),                    /* cost of movsx */
983   COSTS_N_INSNS (1),                    /* cost of movzx */
984   8,                                    /* "large" insn */
985   16,                                   /* MOVE_RATIO */
986   2,                                    /* cost for loading QImode using movzbl */
987   {6, 6, 6},                            /* cost of loading integer registers
988                                            in QImode, HImode and SImode.
989                                            Relative to reg-reg move (2).  */
990   {4, 4, 4},                            /* cost of storing integer registers */
991   2,                                    /* cost of reg,reg fld/fst */
992   {6, 6, 6},                            /* cost of loading fp registers
993                                            in SFmode, DFmode and XFmode */
994   {4, 4, 4},                            /* cost of loading integer registers */
995   2,                                    /* cost of moving MMX register */
996   {6, 6},                               /* cost of loading MMX registers
997                                            in SImode and DImode */
998   {4, 4},                               /* cost of storing MMX registers
999                                            in SImode and DImode */
1000   2,                                    /* cost of moving SSE register */
1001   {6, 6, 6},                            /* cost of loading SSE registers
1002                                            in SImode, DImode and TImode */
1003   {4, 4, 4},                            /* cost of storing SSE registers
1004                                            in SImode, DImode and TImode */
1005   2,                                    /* MMX or SSE register to integer */
1006   32,                                   /* size of l1 cache.  */
1007   2048,                                 /* size of l2 cache.  */
1008   128,                                  /* size of prefetch block */
1009   8,                                    /* number of parallel prefetches */
1010   3,                                    /* Branch cost */
1011   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
1012   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
1013   COSTS_N_INSNS (32),                   /* cost of FDIV instruction.  */
1014   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
1015   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
1016   COSTS_N_INSNS (58),                   /* cost of FSQRT instruction.  */
1017   {{libcall, {{11, loop}, {-1, rep_prefix_4_byte}}},
1018    {libcall, {{32, loop}, {64, rep_prefix_4_byte},
1019               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1020   {{libcall, {{8, loop}, {15, unrolled_loop},
1021               {2048, rep_prefix_4_byte}, {-1, libcall}}},
1022    {libcall, {{24, loop}, {32, unrolled_loop},
1023               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1024   1,                                    /* scalar_stmt_cost.  */
1025   1,                                    /* scalar load_cost.  */
1026   1,                                    /* scalar_store_cost.  */
1027   1,                                    /* vec_stmt_cost.  */
1028   1,                                    /* vec_to_scalar_cost.  */
1029   1,                                    /* scalar_to_vec_cost.  */
1030   1,                                    /* vec_align_load_cost.  */
1031   2,                                    /* vec_unalign_load_cost.  */
1032   1,                                    /* vec_store_cost.  */
1033   3,                                    /* cond_taken_branch_cost.  */
1034   1,                                    /* cond_not_taken_branch_cost.  */
1035 };
1036
1037 /* Generic64 should produce code tuned for Nocona and K8.  */
1038 static const
1039 struct processor_costs generic64_cost = {
1040   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1041   /* On all chips taken into consideration lea is 2 cycles and more.  With
1042      this cost however our current implementation of synth_mult results in
1043      use of unnecessary temporary registers causing regression on several
1044      SPECfp benchmarks.  */
1045   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1046   COSTS_N_INSNS (1),                    /* variable shift costs */
1047   COSTS_N_INSNS (1),                    /* constant shift costs */
1048   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1049    COSTS_N_INSNS (4),                   /*                               HI */
1050    COSTS_N_INSNS (3),                   /*                               SI */
1051    COSTS_N_INSNS (4),                   /*                               DI */
1052    COSTS_N_INSNS (2)},                  /*                               other */
1053   0,                                    /* cost of multiply per each bit set */
1054   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1055    COSTS_N_INSNS (26),                  /*                          HI */
1056    COSTS_N_INSNS (42),                  /*                          SI */
1057    COSTS_N_INSNS (74),                  /*                          DI */
1058    COSTS_N_INSNS (74)},                 /*                          other */
1059   COSTS_N_INSNS (1),                    /* cost of movsx */
1060   COSTS_N_INSNS (1),                    /* cost of movzx */
1061   8,                                    /* "large" insn */
1062   17,                                   /* MOVE_RATIO */
1063   4,                                    /* cost for loading QImode using movzbl */
1064   {4, 4, 4},                            /* cost of loading integer registers
1065                                            in QImode, HImode and SImode.
1066                                            Relative to reg-reg move (2).  */
1067   {4, 4, 4},                            /* cost of storing integer registers */
1068   4,                                    /* cost of reg,reg fld/fst */
1069   {12, 12, 12},                         /* cost of loading fp registers
1070                                            in SFmode, DFmode and XFmode */
1071   {6, 6, 8},                            /* cost of storing fp registers
1072                                            in SFmode, DFmode and XFmode */
1073   2,                                    /* cost of moving MMX register */
1074   {8, 8},                               /* cost of loading MMX registers
1075                                            in SImode and DImode */
1076   {8, 8},                               /* cost of storing MMX registers
1077                                            in SImode and DImode */
1078   2,                                    /* cost of moving SSE register */
1079   {8, 8, 8},                            /* cost of loading SSE registers
1080                                            in SImode, DImode and TImode */
1081   {8, 8, 8},                            /* cost of storing SSE registers
1082                                            in SImode, DImode and TImode */
1083   5,                                    /* MMX or SSE register to integer */
1084   32,                                   /* size of l1 cache.  */
1085   512,                                  /* size of l2 cache.  */
1086   64,                                   /* size of prefetch block */
1087   6,                                    /* number of parallel prefetches */
1088   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this value
1089      is increased to perhaps more appropriate value of 5.  */
1090   3,                                    /* Branch cost */
1091   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1092   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1093   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1094   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1095   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1096   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1097   {DUMMY_STRINGOP_ALGS,
1098    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1099   {DUMMY_STRINGOP_ALGS,
1100    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1101   1,                                    /* scalar_stmt_cost.  */
1102   1,                                    /* scalar load_cost.  */
1103   1,                                    /* scalar_store_cost.  */
1104   1,                                    /* vec_stmt_cost.  */
1105   1,                                    /* vec_to_scalar_cost.  */
1106   1,                                    /* scalar_to_vec_cost.  */
1107   1,                                    /* vec_align_load_cost.  */
1108   2,                                    /* vec_unalign_load_cost.  */
1109   1,                                    /* vec_store_cost.  */
1110   3,                                    /* cond_taken_branch_cost.  */
1111   1,                                    /* cond_not_taken_branch_cost.  */
1112 };
1113
1114 /* Generic32 should produce code tuned for Athlon, PPro, Pentium4, Nocona and K8.  */
1115 static const
1116 struct processor_costs generic32_cost = {
1117   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1118   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1119   COSTS_N_INSNS (1),                    /* variable shift costs */
1120   COSTS_N_INSNS (1),                    /* constant shift costs */
1121   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1122    COSTS_N_INSNS (4),                   /*                               HI */
1123    COSTS_N_INSNS (3),                   /*                               SI */
1124    COSTS_N_INSNS (4),                   /*                               DI */
1125    COSTS_N_INSNS (2)},                  /*                               other */
1126   0,                                    /* cost of multiply per each bit set */
1127   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1128    COSTS_N_INSNS (26),                  /*                          HI */
1129    COSTS_N_INSNS (42),                  /*                          SI */
1130    COSTS_N_INSNS (74),                  /*                          DI */
1131    COSTS_N_INSNS (74)},                 /*                          other */
1132   COSTS_N_INSNS (1),                    /* cost of movsx */
1133   COSTS_N_INSNS (1),                    /* cost of movzx */
1134   8,                                    /* "large" insn */
1135   17,                                   /* MOVE_RATIO */
1136   4,                                    /* cost for loading QImode using movzbl */
1137   {4, 4, 4},                            /* cost of loading integer registers
1138                                            in QImode, HImode and SImode.
1139                                            Relative to reg-reg move (2).  */
1140   {4, 4, 4},                            /* cost of storing integer registers */
1141   4,                                    /* cost of reg,reg fld/fst */
1142   {12, 12, 12},                         /* cost of loading fp registers
1143                                            in SFmode, DFmode and XFmode */
1144   {6, 6, 8},                            /* cost of storing fp registers
1145                                            in SFmode, DFmode and XFmode */
1146   2,                                    /* cost of moving MMX register */
1147   {8, 8},                               /* cost of loading MMX registers
1148                                            in SImode and DImode */
1149   {8, 8},                               /* cost of storing MMX registers
1150                                            in SImode and DImode */
1151   2,                                    /* cost of moving SSE register */
1152   {8, 8, 8},                            /* cost of loading SSE registers
1153                                            in SImode, DImode and TImode */
1154   {8, 8, 8},                            /* cost of storing SSE registers
1155                                            in SImode, DImode and TImode */
1156   5,                                    /* MMX or SSE register to integer */
1157   32,                                   /* size of l1 cache.  */
1158   256,                                  /* size of l2 cache.  */
1159   64,                                   /* size of prefetch block */
1160   6,                                    /* number of parallel prefetches */
1161   3,                                    /* Branch cost */
1162   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1163   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1164   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1165   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1166   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1167   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1168   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1169    DUMMY_STRINGOP_ALGS},
1170   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1171    DUMMY_STRINGOP_ALGS},
1172   1,                                    /* scalar_stmt_cost.  */
1173   1,                                    /* scalar load_cost.  */
1174   1,                                    /* scalar_store_cost.  */
1175   1,                                    /* vec_stmt_cost.  */
1176   1,                                    /* vec_to_scalar_cost.  */
1177   1,                                    /* scalar_to_vec_cost.  */
1178   1,                                    /* vec_align_load_cost.  */
1179   2,                                    /* vec_unalign_load_cost.  */
1180   1,                                    /* vec_store_cost.  */
1181   3,                                    /* cond_taken_branch_cost.  */
1182   1,                                    /* cond_not_taken_branch_cost.  */
1183 };
1184
1185 const struct processor_costs *ix86_cost = &pentium_cost;
1186
1187 /* Processor feature/optimization bitmasks.  */
1188 #define m_386 (1<<PROCESSOR_I386)
1189 #define m_486 (1<<PROCESSOR_I486)
1190 #define m_PENT (1<<PROCESSOR_PENTIUM)
1191 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
1192 #define m_PENT4  (1<<PROCESSOR_PENTIUM4)
1193 #define m_NOCONA  (1<<PROCESSOR_NOCONA)
1194 #define m_CORE2  (1<<PROCESSOR_CORE2)
1195
1196 #define m_GEODE  (1<<PROCESSOR_GEODE)
1197 #define m_K6  (1<<PROCESSOR_K6)
1198 #define m_K6_GEODE  (m_K6 | m_GEODE)
1199 #define m_K8  (1<<PROCESSOR_K8)
1200 #define m_ATHLON  (1<<PROCESSOR_ATHLON)
1201 #define m_ATHLON_K8  (m_K8 | m_ATHLON)
1202 #define m_AMDFAM10  (1<<PROCESSOR_AMDFAM10)
1203 #define m_AMD_MULTIPLE  (m_K8 | m_ATHLON | m_AMDFAM10)
1204
1205 #define m_GENERIC32 (1<<PROCESSOR_GENERIC32)
1206 #define m_GENERIC64 (1<<PROCESSOR_GENERIC64)
1207
1208 /* Generic instruction choice should be common subset of supported CPUs
1209    (PPro/PENT4/NOCONA/CORE2/Athlon/K8).  */
1210 #define m_GENERIC (m_GENERIC32 | m_GENERIC64)
1211
1212 /* Feature tests against the various tunings.  */
1213 unsigned char ix86_tune_features[X86_TUNE_LAST];
1214
1215 /* Feature tests against the various tunings used to create ix86_tune_features
1216    based on the processor mask.  */
1217 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
1218   /* X86_TUNE_USE_LEAVE: Leave does not affect Nocona SPEC2000 results
1219      negatively, so enabling for Generic64 seems like good code size
1220      tradeoff.  We can't enable it for 32bit generic because it does not
1221      work well with PPro base chips.  */
1222   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_CORE2 | m_GENERIC64,
1223
1224   /* X86_TUNE_PUSH_MEMORY */
1225   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4
1226   | m_NOCONA | m_CORE2 | m_GENERIC,
1227
1228   /* X86_TUNE_ZERO_EXTEND_WITH_AND */
1229   m_486 | m_PENT,
1230
1231   /* X86_TUNE_USE_BIT_TEST */
1232   m_386,
1233
1234   /* X86_TUNE_UNROLL_STRLEN */
1235   m_486 | m_PENT | m_PPRO | m_AMD_MULTIPLE | m_K6 | m_CORE2 | m_GENERIC,
1236
1237   /* X86_TUNE_DEEP_BRANCH_PREDICTION */
1238   m_PPRO | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4 | m_GENERIC,
1239
1240   /* X86_TUNE_BRANCH_PREDICTION_HINTS: Branch hints were put in P4 based
1241      on simulation result. But after P4 was made, no performance benefit
1242      was observed with branch hints.  It also increases the code size.
1243      As a result, icc never generates branch hints.  */
1244   0,
1245
1246   /* X86_TUNE_DOUBLE_WITH_ADD */
1247   ~m_386,
1248
1249   /* X86_TUNE_USE_SAHF */
1250   m_PPRO | m_K6_GEODE | m_K8 | m_AMDFAM10 | m_PENT4
1251   | m_NOCONA | m_CORE2 | m_GENERIC,
1252
1253   /* X86_TUNE_MOVX: Enable to zero extend integer registers to avoid
1254      partial dependencies.  */
1255   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA
1256   | m_CORE2 | m_GENERIC | m_GEODE /* m_386 | m_K6 */,
1257
1258   /* X86_TUNE_PARTIAL_REG_STALL: We probably ought to watch for partial
1259      register stalls on Generic32 compilation setting as well.  However
1260      in current implementation the partial register stalls are not eliminated
1261      very well - they can be introduced via subregs synthesized by combine
1262      and can happen in caller/callee saving sequences.  Because this option
1263      pays back little on PPro based chips and is in conflict with partial reg
1264      dependencies used by Athlon/P4 based chips, it is better to leave it off
1265      for generic32 for now.  */
1266   m_PPRO,
1267
1268   /* X86_TUNE_PARTIAL_FLAG_REG_STALL */
1269   m_CORE2 | m_GENERIC,
1270
1271   /* X86_TUNE_USE_HIMODE_FIOP */
1272   m_386 | m_486 | m_K6_GEODE,
1273
1274   /* X86_TUNE_USE_SIMODE_FIOP */
1275   ~(m_PPRO | m_AMD_MULTIPLE | m_PENT | m_CORE2 | m_GENERIC),
1276
1277   /* X86_TUNE_USE_MOV0 */
1278   m_K6,
1279
1280   /* X86_TUNE_USE_CLTD */
1281   ~(m_PENT | m_K6 | m_CORE2 | m_GENERIC),
1282
1283   /* X86_TUNE_USE_XCHGB: Use xchgb %rh,%rl instead of rolw/rorw $8,rx.  */
1284   m_PENT4,
1285
1286   /* X86_TUNE_SPLIT_LONG_MOVES */
1287   m_PPRO,
1288
1289   /* X86_TUNE_READ_MODIFY_WRITE */
1290   ~m_PENT,
1291
1292   /* X86_TUNE_READ_MODIFY */
1293   ~(m_PENT | m_PPRO),
1294
1295   /* X86_TUNE_PROMOTE_QIMODE */
1296   m_K6_GEODE | m_PENT | m_386 | m_486 | m_AMD_MULTIPLE | m_CORE2
1297   | m_GENERIC /* | m_PENT4 ? */,
1298
1299   /* X86_TUNE_FAST_PREFIX */
1300   ~(m_PENT | m_486 | m_386),
1301
1302   /* X86_TUNE_SINGLE_STRINGOP */
1303   m_386 | m_PENT4 | m_NOCONA,
1304
1305   /* X86_TUNE_QIMODE_MATH */
1306   ~0,
1307
1308   /* X86_TUNE_HIMODE_MATH: On PPro this flag is meant to avoid partial
1309      register stalls.  Just like X86_TUNE_PARTIAL_REG_STALL this option
1310      might be considered for Generic32 if our scheme for avoiding partial
1311      stalls was more effective.  */
1312   ~m_PPRO,
1313
1314   /* X86_TUNE_PROMOTE_QI_REGS */
1315   0,
1316
1317   /* X86_TUNE_PROMOTE_HI_REGS */
1318   m_PPRO,
1319
1320   /* X86_TUNE_ADD_ESP_4: Enable if add/sub is preferred over 1/2 push/pop.  */
1321   m_AMD_MULTIPLE | m_K6_GEODE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1322
1323   /* X86_TUNE_ADD_ESP_8 */
1324   m_AMD_MULTIPLE | m_PPRO | m_K6_GEODE | m_386
1325   | m_486 | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1326
1327   /* X86_TUNE_SUB_ESP_4 */
1328   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1329
1330   /* X86_TUNE_SUB_ESP_8 */
1331   m_AMD_MULTIPLE | m_PPRO | m_386 | m_486
1332   | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1333
1334   /* X86_TUNE_INTEGER_DFMODE_MOVES: Enable if integer moves are preferred
1335      for DFmode copies */
1336   ~(m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2
1337     | m_GENERIC | m_GEODE),
1338
1339   /* X86_TUNE_PARTIAL_REG_DEPENDENCY */
1340   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1341
1342   /* X86_TUNE_SSE_PARTIAL_REG_DEPENDENCY: In the Generic model we have a
1343      conflict here in between PPro/Pentium4 based chips that thread 128bit
1344      SSE registers as single units versus K8 based chips that divide SSE
1345      registers to two 64bit halves.  This knob promotes all store destinations
1346      to be 128bit to allow register renaming on 128bit SSE units, but usually
1347      results in one extra microop on 64bit SSE units.  Experimental results
1348      shows that disabling this option on P4 brings over 20% SPECfp regression,
1349      while enabling it on K8 brings roughly 2.4% regression that can be partly
1350      masked by careful scheduling of moves.  */
1351   m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC | m_AMDFAM10,
1352
1353   /* X86_TUNE_SSE_UNALIGNED_MOVE_OPTIMAL */
1354   m_AMDFAM10,
1355
1356   /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
1357      are resolved on SSE register parts instead of whole registers, so we may
1358      maintain just lower part of scalar values in proper format leaving the
1359      upper part undefined.  */
1360   m_ATHLON_K8,
1361
1362   /* X86_TUNE_SSE_TYPELESS_STORES */
1363   m_AMD_MULTIPLE,
1364
1365   /* X86_TUNE_SSE_LOAD0_BY_PXOR */
1366   m_PPRO | m_PENT4 | m_NOCONA,
1367
1368   /* X86_TUNE_MEMORY_MISMATCH_STALL */
1369   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1370
1371   /* X86_TUNE_PROLOGUE_USING_MOVE */
1372   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1373
1374   /* X86_TUNE_EPILOGUE_USING_MOVE */
1375   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1376
1377   /* X86_TUNE_SHIFT1 */
1378   ~m_486,
1379
1380   /* X86_TUNE_USE_FFREEP */
1381   m_AMD_MULTIPLE,
1382
1383   /* X86_TUNE_INTER_UNIT_MOVES */
1384   ~(m_AMD_MULTIPLE | m_GENERIC),
1385
1386   /* X86_TUNE_INTER_UNIT_CONVERSIONS */
1387   ~(m_AMDFAM10),
1388
1389   /* X86_TUNE_FOUR_JUMP_LIMIT: Some CPU cores are not able to predict more
1390      than 4 branch instructions in the 16 byte window.  */
1391   m_PPRO | m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1392
1393   /* X86_TUNE_SCHEDULE */
1394   m_PPRO | m_AMD_MULTIPLE | m_K6_GEODE | m_PENT | m_CORE2 | m_GENERIC,
1395
1396   /* X86_TUNE_USE_BT */
1397   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1398
1399   /* X86_TUNE_USE_INCDEC */
1400   ~(m_PENT4 | m_NOCONA | m_GENERIC),
1401
1402   /* X86_TUNE_PAD_RETURNS */
1403   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1404
1405   /* X86_TUNE_EXT_80387_CONSTANTS */
1406   m_K6_GEODE | m_ATHLON_K8 | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC,
1407
1408   /* X86_TUNE_SHORTEN_X87_SSE */
1409   ~m_K8,
1410
1411   /* X86_TUNE_AVOID_VECTOR_DECODE */
1412   m_K8 | m_GENERIC64,
1413
1414   /* X86_TUNE_PROMOTE_HIMODE_IMUL: Modern CPUs have same latency for HImode
1415      and SImode multiply, but 386 and 486 do HImode multiply faster.  */
1416   ~(m_386 | m_486),
1417
1418   /* X86_TUNE_SLOW_IMUL_IMM32_MEM: Imul of 32-bit constant and memory is
1419      vector path on AMD machines.  */
1420   m_K8 | m_GENERIC64 | m_AMDFAM10,
1421
1422   /* X86_TUNE_SLOW_IMUL_IMM8: Imul of 8-bit constant is vector path on AMD
1423      machines.  */
1424   m_K8 | m_GENERIC64 | m_AMDFAM10,
1425
1426   /* X86_TUNE_MOVE_M1_VIA_OR: On pentiums, it is faster to load -1 via OR
1427      than a MOV.  */
1428   m_PENT,
1429
1430   /* X86_TUNE_NOT_UNPAIRABLE: NOT is not pairable on Pentium, while XOR is,
1431      but one byte longer.  */
1432   m_PENT,
1433
1434   /* X86_TUNE_NOT_VECTORMODE: On AMD K6, NOT is vector decoded with memory
1435      operand that cannot be represented using a modRM byte.  The XOR
1436      replacement is long decoded, so this split helps here as well.  */
1437   m_K6,
1438
1439   /* X86_TUNE_USE_VECTOR_CONVERTS: Prefer vector packed SSE conversion
1440      from integer to FP. */
1441   m_AMDFAM10,
1442
1443   /* X86_TUNE_FUSE_CMP_AND_BRANCH: Fuse a compare or test instruction
1444      with a subsequent conditional jump instruction into a single
1445      compare-and-branch uop.  */
1446   m_CORE2,
1447 };
1448
1449 /* Feature tests against the various architecture variations.  */
1450 unsigned char ix86_arch_features[X86_ARCH_LAST];
1451
1452 /* Feature tests against the various architecture variations, used to create
1453    ix86_arch_features based on the processor mask.  */
1454 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
1455   /* X86_ARCH_CMOVE: Conditional move was added for pentiumpro.  */
1456   ~(m_386 | m_486 | m_PENT | m_K6),
1457
1458   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
1459   ~m_386,
1460
1461   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
1462   ~(m_386 | m_486),
1463
1464   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
1465   ~m_386,
1466
1467   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
1468   ~m_386,
1469 };
1470
1471 static const unsigned int x86_accumulate_outgoing_args
1472   = m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC;
1473
1474 static const unsigned int x86_arch_always_fancy_math_387
1475   = m_PENT | m_PPRO | m_AMD_MULTIPLE | m_PENT4
1476     | m_NOCONA | m_CORE2 | m_GENERIC;
1477
1478 static enum stringop_alg stringop_alg = no_stringop;
1479
1480 /* In case the average insn count for single function invocation is
1481    lower than this constant, emit fast (but longer) prologue and
1482    epilogue code.  */
1483 #define FAST_PROLOGUE_INSN_COUNT 20
1484
1485 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
1486 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
1487 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
1488 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
1489
1490 /* Array of the smallest class containing reg number REGNO, indexed by
1491    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
1492
1493 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
1494 {
1495   /* ax, dx, cx, bx */
1496   AREG, DREG, CREG, BREG,
1497   /* si, di, bp, sp */
1498   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
1499   /* FP registers */
1500   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
1501   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
1502   /* arg pointer */
1503   NON_Q_REGS,
1504   /* flags, fpsr, fpcr, frame */
1505   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
1506   /* SSE registers */
1507   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1508   SSE_REGS, SSE_REGS,
1509   /* MMX registers */
1510   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
1511   MMX_REGS, MMX_REGS,
1512   /* REX registers */
1513   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1514   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1515   /* SSE REX registers */
1516   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1517   SSE_REGS, SSE_REGS,
1518 };
1519
1520 /* The "default" register map used in 32bit mode.  */
1521
1522 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
1523 {
1524   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
1525   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
1526   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1527   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
1528   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
1529   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1530   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1531 };
1532
1533 static int const x86_64_int_parameter_registers[6] =
1534 {
1535   5 /*RDI*/, 4 /*RSI*/, 1 /*RDX*/, 2 /*RCX*/,
1536   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1537 };
1538
1539 static int const x86_64_ms_abi_int_parameter_registers[4] =
1540 {
1541   2 /*RCX*/, 1 /*RDX*/,
1542   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1543 };
1544
1545 static int const x86_64_int_return_registers[4] =
1546 {
1547   0 /*RAX*/, 1 /*RDX*/, 5 /*RDI*/, 4 /*RSI*/
1548 };
1549
1550 /* The "default" register map used in 64bit mode.  */
1551 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
1552 {
1553   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
1554   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
1555   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1556   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
1557   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
1558   8,9,10,11,12,13,14,15,                /* extended integer registers */
1559   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
1560 };
1561
1562 /* Define the register numbers to be used in Dwarf debugging information.
1563    The SVR4 reference port C compiler uses the following register numbers
1564    in its Dwarf output code:
1565         0 for %eax (gcc regno = 0)
1566         1 for %ecx (gcc regno = 2)
1567         2 for %edx (gcc regno = 1)
1568         3 for %ebx (gcc regno = 3)
1569         4 for %esp (gcc regno = 7)
1570         5 for %ebp (gcc regno = 6)
1571         6 for %esi (gcc regno = 4)
1572         7 for %edi (gcc regno = 5)
1573    The following three DWARF register numbers are never generated by
1574    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
1575    believes these numbers have these meanings.
1576         8  for %eip    (no gcc equivalent)
1577         9  for %eflags (gcc regno = 17)
1578         10 for %trapno (no gcc equivalent)
1579    It is not at all clear how we should number the FP stack registers
1580    for the x86 architecture.  If the version of SDB on x86/svr4 were
1581    a bit less brain dead with respect to floating-point then we would
1582    have a precedent to follow with respect to DWARF register numbers
1583    for x86 FP registers, but the SDB on x86/svr4 is so completely
1584    broken with respect to FP registers that it is hardly worth thinking
1585    of it as something to strive for compatibility with.
1586    The version of x86/svr4 SDB I have at the moment does (partially)
1587    seem to believe that DWARF register number 11 is associated with
1588    the x86 register %st(0), but that's about all.  Higher DWARF
1589    register numbers don't seem to be associated with anything in
1590    particular, and even for DWARF regno 11, SDB only seems to under-
1591    stand that it should say that a variable lives in %st(0) (when
1592    asked via an `=' command) if we said it was in DWARF regno 11,
1593    but SDB still prints garbage when asked for the value of the
1594    variable in question (via a `/' command).
1595    (Also note that the labels SDB prints for various FP stack regs
1596    when doing an `x' command are all wrong.)
1597    Note that these problems generally don't affect the native SVR4
1598    C compiler because it doesn't allow the use of -O with -g and
1599    because when it is *not* optimizing, it allocates a memory
1600    location for each floating-point variable, and the memory
1601    location is what gets described in the DWARF AT_location
1602    attribute for the variable in question.
1603    Regardless of the severe mental illness of the x86/svr4 SDB, we
1604    do something sensible here and we use the following DWARF
1605    register numbers.  Note that these are all stack-top-relative
1606    numbers.
1607         11 for %st(0) (gcc regno = 8)
1608         12 for %st(1) (gcc regno = 9)
1609         13 for %st(2) (gcc regno = 10)
1610         14 for %st(3) (gcc regno = 11)
1611         15 for %st(4) (gcc regno = 12)
1612         16 for %st(5) (gcc regno = 13)
1613         17 for %st(6) (gcc regno = 14)
1614         18 for %st(7) (gcc regno = 15)
1615 */
1616 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
1617 {
1618   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
1619   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
1620   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
1621   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
1622   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
1623   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1624   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1625 };
1626
1627 /* Test and compare insns in i386.md store the information needed to
1628    generate branch and scc insns here.  */
1629
1630 rtx ix86_compare_op0 = NULL_RTX;
1631 rtx ix86_compare_op1 = NULL_RTX;
1632 rtx ix86_compare_emitted = NULL_RTX;
1633
1634 /* Define the structure for the machine field in struct function.  */
1635
1636 struct stack_local_entry GTY(())
1637 {
1638   unsigned short mode;
1639   unsigned short n;
1640   rtx rtl;
1641   struct stack_local_entry *next;
1642 };
1643
1644 /* Structure describing stack frame layout.
1645    Stack grows downward:
1646
1647    [arguments]
1648                                               <- ARG_POINTER
1649    saved pc
1650
1651    saved frame pointer if frame_pointer_needed
1652                                               <- HARD_FRAME_POINTER
1653    [saved regs]
1654
1655    [padding1]          \
1656                         )
1657    [va_arg registers]  (
1658                         > to_allocate         <- FRAME_POINTER
1659    [frame]             (
1660                         )
1661    [padding2]          /
1662   */
1663 struct ix86_frame
1664 {
1665   int nregs;
1666   int padding1;
1667   int va_arg_size;
1668   HOST_WIDE_INT frame;
1669   int padding2;
1670   int outgoing_arguments_size;
1671   int red_zone_size;
1672
1673   HOST_WIDE_INT to_allocate;
1674   /* The offsets relative to ARG_POINTER.  */
1675   HOST_WIDE_INT frame_pointer_offset;
1676   HOST_WIDE_INT hard_frame_pointer_offset;
1677   HOST_WIDE_INT stack_pointer_offset;
1678
1679   /* When save_regs_using_mov is set, emit prologue using
1680      move instead of push instructions.  */
1681   bool save_regs_using_mov;
1682 };
1683
1684 /* Code model option.  */
1685 enum cmodel ix86_cmodel;
1686 /* Asm dialect.  */
1687 enum asm_dialect ix86_asm_dialect = ASM_ATT;
1688 /* TLS dialects.  */
1689 enum tls_dialect ix86_tls_dialect = TLS_DIALECT_GNU;
1690
1691 /* Which unit we are generating floating point math for.  */
1692 enum fpmath_unit ix86_fpmath;
1693
1694 /* Which cpu are we scheduling for.  */
1695 enum processor_type ix86_tune;
1696
1697 /* Which instruction set architecture to use.  */
1698 enum processor_type ix86_arch;
1699
1700 /* true if sse prefetch instruction is not NOOP.  */
1701 int x86_prefetch_sse;
1702
1703 /* ix86_regparm_string as a number */
1704 static int ix86_regparm;
1705
1706 /* -mstackrealign option */
1707 extern int ix86_force_align_arg_pointer;
1708 static const char ix86_force_align_arg_pointer_string[]
1709   = "force_align_arg_pointer";
1710
1711 static rtx (*ix86_gen_leave) (void);
1712 static rtx (*ix86_gen_pop1) (rtx);
1713 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
1714 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
1715 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx);
1716 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
1717 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
1718 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
1719
1720 /* Preferred alignment for stack boundary in bits.  */
1721 unsigned int ix86_preferred_stack_boundary;
1722
1723 /* Alignment for incoming stack boundary in bits specified at
1724    command line.  */
1725 static unsigned int ix86_user_incoming_stack_boundary;
1726
1727 /* Default alignment for incoming stack boundary in bits.  */
1728 static unsigned int ix86_default_incoming_stack_boundary;
1729
1730 /* Alignment for incoming stack boundary in bits.  */
1731 unsigned int ix86_incoming_stack_boundary;
1732
1733 /* Values 1-5: see jump.c */
1734 int ix86_branch_cost;
1735
1736 /* Calling abi specific va_list type nodes.  */
1737 static GTY(()) tree sysv_va_list_type_node;
1738 static GTY(()) tree ms_va_list_type_node;
1739
1740 /* Variables which are this size or smaller are put in the data/bss
1741    or ldata/lbss sections.  */
1742
1743 int ix86_section_threshold = 65536;
1744
1745 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
1746 char internal_label_prefix[16];
1747 int internal_label_prefix_len;
1748
1749 /* Fence to use after loop using movnt.  */
1750 tree x86_mfence;
1751
1752 /* Register class used for passing given 64bit part of the argument.
1753    These represent classes as documented by the PS ABI, with the exception
1754    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
1755    use SF or DFmode move instead of DImode to avoid reformatting penalties.
1756
1757    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
1758    whenever possible (upper half does contain padding).  */
1759 enum x86_64_reg_class
1760   {
1761     X86_64_NO_CLASS,
1762     X86_64_INTEGER_CLASS,
1763     X86_64_INTEGERSI_CLASS,
1764     X86_64_AVX_CLASS,
1765     X86_64_SSE_CLASS,
1766     X86_64_SSESF_CLASS,
1767     X86_64_SSEDF_CLASS,
1768     X86_64_SSEUP_CLASS,
1769     X86_64_X87_CLASS,
1770     X86_64_X87UP_CLASS,
1771     X86_64_COMPLEX_X87_CLASS,
1772     X86_64_MEMORY_CLASS
1773   };
1774 static const char * const x86_64_reg_class_name[] =
1775 {
1776   "no", "integer", "integerSI", "sse", "sseSF", "sseDF",
1777   "sseup", "x87", "x87up", "cplx87", "no"
1778 };
1779
1780 #define MAX_CLASSES 4
1781
1782 /* Table of constants used by fldpi, fldln2, etc....  */
1783 static REAL_VALUE_TYPE ext_80387_constants_table [5];
1784 static bool ext_80387_constants_init = 0;
1785
1786 \f
1787 static struct machine_function * ix86_init_machine_status (void);
1788 static rtx ix86_function_value (const_tree, const_tree, bool);
1789 static int ix86_function_regparm (const_tree, const_tree);
1790 static void ix86_compute_frame_layout (struct ix86_frame *);
1791 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
1792                                                  rtx, rtx, int);
1793 static void ix86_add_new_builtins (int);
1794
1795 enum ix86_function_specific_strings
1796 {
1797   IX86_FUNCTION_SPECIFIC_ARCH,
1798   IX86_FUNCTION_SPECIFIC_TUNE,
1799   IX86_FUNCTION_SPECIFIC_FPMATH,
1800   IX86_FUNCTION_SPECIFIC_MAX
1801 };
1802
1803 static char *ix86_target_string (int, int, const char *, const char *,
1804                                  const char *, bool);
1805 static void ix86_debug_options (void) ATTRIBUTE_UNUSED;
1806 static void ix86_function_specific_save (struct cl_target_option *);
1807 static void ix86_function_specific_restore (struct cl_target_option *);
1808 static void ix86_function_specific_print (FILE *, int,
1809                                           struct cl_target_option *);
1810 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
1811 static bool ix86_valid_target_attribute_inner_p (tree, char *[]);
1812 static bool ix86_can_inline_p (tree, tree);
1813 static void ix86_set_current_function (tree);
1814
1815 \f
1816 /* The svr4 ABI for the i386 says that records and unions are returned
1817    in memory.  */
1818 #ifndef DEFAULT_PCC_STRUCT_RETURN
1819 #define DEFAULT_PCC_STRUCT_RETURN 1
1820 #endif
1821
1822 /* Whether -mtune= or -march= were specified */
1823 static int ix86_tune_defaulted;
1824 static int ix86_arch_specified;
1825
1826 /* Bit flags that specify the ISA we are compiling for.  */
1827 int ix86_isa_flags = TARGET_64BIT_DEFAULT | TARGET_SUBTARGET_ISA_DEFAULT;
1828
1829 /* A mask of ix86_isa_flags that includes bit X if X
1830    was set or cleared on the command line.  */
1831 static int ix86_isa_flags_explicit;
1832
1833 /* Define a set of ISAs which are available when a given ISA is
1834    enabled.  MMX and SSE ISAs are handled separately.  */
1835
1836 #define OPTION_MASK_ISA_MMX_SET OPTION_MASK_ISA_MMX
1837 #define OPTION_MASK_ISA_3DNOW_SET \
1838   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX_SET)
1839
1840 #define OPTION_MASK_ISA_SSE_SET OPTION_MASK_ISA_SSE
1841 #define OPTION_MASK_ISA_SSE2_SET \
1842   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE_SET)
1843 #define OPTION_MASK_ISA_SSE3_SET \
1844   (OPTION_MASK_ISA_SSE3 | OPTION_MASK_ISA_SSE2_SET)
1845 #define OPTION_MASK_ISA_SSSE3_SET \
1846   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE3_SET)
1847 #define OPTION_MASK_ISA_SSE4_1_SET \
1848   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSSE3_SET)
1849 #define OPTION_MASK_ISA_SSE4_2_SET \
1850   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_SSE4_1_SET)
1851 #define OPTION_MASK_ISA_AVX_SET \
1852   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_SSE4_2_SET)
1853 #define OPTION_MASK_ISA_FMA_SET \
1854   (OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_AVX_SET)
1855
1856 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
1857    as -msse4.2.  */
1858 #define OPTION_MASK_ISA_SSE4_SET OPTION_MASK_ISA_SSE4_2_SET
1859
1860 #define OPTION_MASK_ISA_SSE4A_SET \
1861   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE3_SET)
1862 #define OPTION_MASK_ISA_SSE5_SET \
1863   (OPTION_MASK_ISA_SSE5 | OPTION_MASK_ISA_SSE4A_SET)
1864
1865 /* AES and PCLMUL need SSE2 because they use xmm registers */
1866 #define OPTION_MASK_ISA_AES_SET \
1867   (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2_SET)
1868 #define OPTION_MASK_ISA_PCLMUL_SET \
1869   (OPTION_MASK_ISA_PCLMUL | OPTION_MASK_ISA_SSE2_SET)
1870
1871 #define OPTION_MASK_ISA_ABM_SET \
1872   (OPTION_MASK_ISA_ABM | OPTION_MASK_ISA_POPCNT)
1873 #define OPTION_MASK_ISA_POPCNT_SET OPTION_MASK_ISA_POPCNT
1874 #define OPTION_MASK_ISA_CX16_SET OPTION_MASK_ISA_CX16
1875 #define OPTION_MASK_ISA_SAHF_SET OPTION_MASK_ISA_SAHF
1876
1877 /* Define a set of ISAs which aren't available when a given ISA is
1878    disabled.  MMX and SSE ISAs are handled separately.  */
1879
1880 #define OPTION_MASK_ISA_MMX_UNSET \
1881   (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_3DNOW_UNSET)
1882 #define OPTION_MASK_ISA_3DNOW_UNSET \
1883   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_A_UNSET)
1884 #define OPTION_MASK_ISA_3DNOW_A_UNSET OPTION_MASK_ISA_3DNOW_A
1885
1886 #define OPTION_MASK_ISA_SSE_UNSET \
1887   (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_SSE2_UNSET)
1888 #define OPTION_MASK_ISA_SSE2_UNSET \
1889   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3_UNSET)
1890 #define OPTION_MASK_ISA_SSE3_UNSET \
1891   (OPTION_MASK_ISA_SSE3 \
1892    | OPTION_MASK_ISA_SSSE3_UNSET \
1893    | OPTION_MASK_ISA_SSE4A_UNSET )
1894 #define OPTION_MASK_ISA_SSSE3_UNSET \
1895   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE4_1_UNSET)
1896 #define OPTION_MASK_ISA_SSE4_1_UNSET \
1897   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_2_UNSET)
1898 #define OPTION_MASK_ISA_SSE4_2_UNSET \
1899   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_AVX_UNSET )
1900 #define OPTION_MASK_ISA_AVX_UNSET \
1901   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_FMA_UNSET)
1902 #define OPTION_MASK_ISA_FMA_UNSET OPTION_MASK_ISA_FMA
1903
1904 /* SSE4 includes both SSE4.1 and SSE4.2.  -mno-sse4 should the same
1905    as -mno-sse4.1. */
1906 #define OPTION_MASK_ISA_SSE4_UNSET OPTION_MASK_ISA_SSE4_1_UNSET
1907
1908 #define OPTION_MASK_ISA_SSE4A_UNSET \
1909   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE5_UNSET)
1910 #define OPTION_MASK_ISA_SSE5_UNSET OPTION_MASK_ISA_SSE5
1911 #define OPTION_MASK_ISA_AES_UNSET OPTION_MASK_ISA_AES
1912 #define OPTION_MASK_ISA_PCLMUL_UNSET OPTION_MASK_ISA_PCLMUL
1913 #define OPTION_MASK_ISA_ABM_UNSET OPTION_MASK_ISA_ABM
1914 #define OPTION_MASK_ISA_POPCNT_UNSET OPTION_MASK_ISA_POPCNT
1915 #define OPTION_MASK_ISA_CX16_UNSET OPTION_MASK_ISA_CX16
1916 #define OPTION_MASK_ISA_SAHF_UNSET OPTION_MASK_ISA_SAHF
1917
1918 /* Vectorization library interface and handlers.  */
1919 tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL;
1920 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
1921 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
1922
1923 /* Processor target table, indexed by processor number */
1924 struct ptt
1925 {
1926   const struct processor_costs *cost;           /* Processor costs */
1927   const int align_loop;                         /* Default alignments.  */
1928   const int align_loop_max_skip;
1929   const int align_jump;
1930   const int align_jump_max_skip;
1931   const int align_func;
1932 };
1933
1934 static const struct ptt processor_target_table[PROCESSOR_max] =
1935 {
1936   {&i386_cost, 4, 3, 4, 3, 4},
1937   {&i486_cost, 16, 15, 16, 15, 16},
1938   {&pentium_cost, 16, 7, 16, 7, 16},
1939   {&pentiumpro_cost, 16, 15, 16, 10, 16},
1940   {&geode_cost, 0, 0, 0, 0, 0},
1941   {&k6_cost, 32, 7, 32, 7, 32},
1942   {&athlon_cost, 16, 7, 16, 7, 16},
1943   {&pentium4_cost, 0, 0, 0, 0, 0},
1944   {&k8_cost, 16, 7, 16, 7, 16},
1945   {&nocona_cost, 0, 0, 0, 0, 0},
1946   {&core2_cost, 16, 10, 16, 10, 16},
1947   {&generic32_cost, 16, 7, 16, 7, 16},
1948   {&generic64_cost, 16, 10, 16, 10, 16},
1949   {&amdfam10_cost, 32, 24, 32, 7, 32}
1950 };
1951
1952 static const char *const cpu_names[TARGET_CPU_DEFAULT_max] =
1953 {
1954   "generic",
1955   "i386",
1956   "i486",
1957   "pentium",
1958   "pentium-mmx",
1959   "pentiumpro",
1960   "pentium2",
1961   "pentium3",
1962   "pentium4",
1963   "pentium-m",
1964   "prescott",
1965   "nocona",
1966   "core2",
1967   "geode",
1968   "k6",
1969   "k6-2",
1970   "k6-3",
1971   "athlon",
1972   "athlon-4",
1973   "k8",
1974   "amdfam10"
1975 };
1976 \f
1977 /* Implement TARGET_HANDLE_OPTION.  */
1978
1979 static bool
1980 ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value)
1981 {
1982   switch (code)
1983     {
1984     case OPT_mmmx:
1985       if (value)
1986         {
1987           ix86_isa_flags |= OPTION_MASK_ISA_MMX_SET;
1988           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_SET;
1989         }
1990       else
1991         {
1992           ix86_isa_flags &= ~OPTION_MASK_ISA_MMX_UNSET;
1993           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_UNSET;
1994         }
1995       return true;
1996
1997     case OPT_m3dnow:
1998       if (value)
1999         {
2000           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_SET;
2001           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_SET;
2002         }
2003       else
2004         {
2005           ix86_isa_flags &= ~OPTION_MASK_ISA_3DNOW_UNSET;
2006           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_UNSET;
2007         }
2008       return true;
2009
2010     case OPT_m3dnowa:
2011       return false;
2012
2013     case OPT_msse:
2014       if (value)
2015         {
2016           ix86_isa_flags |= OPTION_MASK_ISA_SSE_SET;
2017           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_SET;
2018         }
2019       else
2020         {
2021           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE_UNSET;
2022           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_UNSET;
2023         }
2024       return true;
2025
2026     case OPT_msse2:
2027       if (value)
2028         {
2029           ix86_isa_flags |= OPTION_MASK_ISA_SSE2_SET;
2030           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_SET;
2031         }
2032       else
2033         {
2034           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE2_UNSET;
2035           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_UNSET;
2036         }
2037       return true;
2038
2039     case OPT_msse3:
2040       if (value)
2041         {
2042           ix86_isa_flags |= OPTION_MASK_ISA_SSE3_SET;
2043           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_SET;
2044         }
2045       else
2046         {
2047           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE3_UNSET;
2048           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_UNSET;
2049         }
2050       return true;
2051
2052     case OPT_mssse3:
2053       if (value)
2054         {
2055           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3_SET;
2056           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_SET;
2057         }
2058       else
2059         {
2060           ix86_isa_flags &= ~OPTION_MASK_ISA_SSSE3_UNSET;
2061           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_UNSET;
2062         }
2063       return true;
2064
2065     case OPT_msse4_1:
2066       if (value)
2067         {
2068           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1_SET;
2069           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_SET;
2070         }
2071       else
2072         {
2073           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_1_UNSET;
2074           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_UNSET;
2075         }
2076       return true;
2077
2078     case OPT_msse4_2:
2079       if (value)
2080         {
2081           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2_SET;
2082           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_SET;
2083         }
2084       else
2085         {
2086           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_2_UNSET;
2087           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_UNSET;
2088         }
2089       return true;
2090
2091     case OPT_mavx:
2092       if (value)
2093         {
2094           ix86_isa_flags |= OPTION_MASK_ISA_AVX_SET;
2095           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_SET;
2096         }
2097       else
2098         {
2099           ix86_isa_flags &= ~OPTION_MASK_ISA_AVX_UNSET;
2100           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_UNSET;
2101         }
2102       return true;
2103
2104     case OPT_mfma:
2105       if (value)
2106         {
2107           ix86_isa_flags |= OPTION_MASK_ISA_FMA_SET;
2108           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_SET;
2109         }
2110       else
2111         {
2112           ix86_isa_flags &= ~OPTION_MASK_ISA_FMA_UNSET;
2113           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_UNSET;
2114         }
2115       return true;
2116
2117     case OPT_msse4:
2118       ix86_isa_flags |= OPTION_MASK_ISA_SSE4_SET;
2119       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_SET;
2120       return true;
2121
2122     case OPT_mno_sse4:
2123       ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
2124       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
2125       return true;
2126
2127     case OPT_msse4a:
2128       if (value)
2129         {
2130           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A_SET;
2131           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_SET;
2132         }
2133       else
2134         {
2135           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4A_UNSET;
2136           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_UNSET;
2137         }
2138       return true;
2139
2140     case OPT_msse5:
2141       if (value)
2142         {
2143           ix86_isa_flags |= OPTION_MASK_ISA_SSE5_SET;
2144           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_SET;
2145         }
2146       else
2147         {
2148           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE5_UNSET;
2149           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_UNSET;
2150         }
2151       return true;
2152
2153     case OPT_mabm:
2154       if (value)
2155         {
2156           ix86_isa_flags |= OPTION_MASK_ISA_ABM_SET;
2157           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_SET;
2158         }
2159       else
2160         {
2161           ix86_isa_flags &= ~OPTION_MASK_ISA_ABM_UNSET;
2162           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_UNSET;
2163         }
2164       return true;
2165
2166     case OPT_mpopcnt:
2167       if (value)
2168         {
2169           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT_SET;
2170           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_SET;
2171         }
2172       else
2173         {
2174           ix86_isa_flags &= ~OPTION_MASK_ISA_POPCNT_UNSET;
2175           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_UNSET;
2176         }
2177       return true;
2178
2179     case OPT_msahf:
2180       if (value)
2181         {
2182           ix86_isa_flags |= OPTION_MASK_ISA_SAHF_SET;
2183           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_SET;
2184         }
2185       else
2186         {
2187           ix86_isa_flags &= ~OPTION_MASK_ISA_SAHF_UNSET;
2188           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_UNSET;
2189         }
2190       return true;
2191
2192     case OPT_mcx16:
2193       if (value)
2194         {
2195           ix86_isa_flags |= OPTION_MASK_ISA_CX16_SET;
2196           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_SET;
2197         }
2198       else
2199         {
2200           ix86_isa_flags &= ~OPTION_MASK_ISA_CX16_UNSET;
2201           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_UNSET;
2202         }
2203       return true;
2204
2205     case OPT_maes:
2206       if (value)
2207         {
2208           ix86_isa_flags |= OPTION_MASK_ISA_AES_SET;
2209           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_SET;
2210         }
2211       else
2212         {
2213           ix86_isa_flags &= ~OPTION_MASK_ISA_AES_UNSET;
2214           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_UNSET;
2215         }
2216       return true;
2217
2218     case OPT_mpclmul:
2219       if (value)
2220         {
2221           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL_SET;
2222           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_SET;
2223         }
2224       else
2225         {
2226           ix86_isa_flags &= ~OPTION_MASK_ISA_PCLMUL_UNSET;
2227           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_UNSET;
2228         }
2229       return true;
2230
2231     default:
2232       return true;
2233     }
2234 }
2235 \f
2236 /* Return a string the documents the current -m options.  The caller is
2237    responsible for freeing the string.  */
2238
2239 static char *
2240 ix86_target_string (int isa, int flags, const char *arch, const char *tune,
2241                     const char *fpmath, bool add_nl_p)
2242 {
2243   struct ix86_target_opts
2244   {
2245     const char *option;         /* option string */
2246     int mask;                   /* isa mask options */
2247   };
2248
2249   /* This table is ordered so that options like -msse5 or -msse4.2 that imply
2250      preceding options while match those first.  */
2251   static struct ix86_target_opts isa_opts[] =
2252   {
2253     { "-m64",           OPTION_MASK_ISA_64BIT },
2254     { "-msse5",         OPTION_MASK_ISA_SSE5 },
2255     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2256     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2257     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2258     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2259     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2260     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2261     { "-msse",          OPTION_MASK_ISA_SSE },
2262     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2263     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2264     { "-mmmx",          OPTION_MASK_ISA_MMX },
2265     { "-mabm",          OPTION_MASK_ISA_ABM },
2266     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2267     { "-maes",          OPTION_MASK_ISA_AES },
2268     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2269   };
2270
2271   /* Flag options.  */
2272   static struct ix86_target_opts flag_opts[] =
2273   {
2274     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2275     { "-m80387",                        MASK_80387 },
2276     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2277     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2278     { "-mcld",                          MASK_CLD },
2279     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2280     { "-mieee-fp",                      MASK_IEEE_FP },
2281     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2282     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2283     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2284     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2285     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2286     { "-mno-fused-madd",                MASK_NO_FUSED_MADD },
2287     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2288     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2289     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2290     { "-mrecip",                        MASK_RECIP },
2291     { "-mrtd",                          MASK_RTD },
2292     { "-msseregparm",                   MASK_SSEREGPARM },
2293     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2294     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2295   };
2296
2297   const char *opts[ (sizeof (isa_opts) / sizeof (isa_opts[0])
2298                      + sizeof (flag_opts) / sizeof (flag_opts[0])
2299                      + 6)][2];
2300
2301   char isa_other[40];
2302   char target_other[40];
2303   unsigned num = 0;
2304   unsigned i, j;
2305   char *ret;
2306   char *ptr;
2307   size_t len;
2308   size_t line_len;
2309   size_t sep_len;
2310
2311   memset (opts, '\0', sizeof (opts));
2312
2313   /* Add -march= option.  */
2314   if (arch)
2315     {
2316       opts[num][0] = "-march=";
2317       opts[num++][1] = arch;
2318     }
2319
2320   /* Add -mtune= option.  */
2321   if (tune)
2322     {
2323       opts[num][0] = "-mtune=";
2324       opts[num++][1] = tune;
2325     }
2326
2327   /* Pick out the options in isa options.  */
2328   for (i = 0; i < sizeof (isa_opts) / sizeof (isa_opts[0]); i++)
2329     {
2330       if ((isa & isa_opts[i].mask) != 0)
2331         {
2332           opts[num++][0] = isa_opts[i].option;
2333           isa &= ~ isa_opts[i].mask;
2334         }
2335     }
2336
2337   if (isa && add_nl_p)
2338     {
2339       opts[num++][0] = isa_other;
2340       sprintf (isa_other, "(other isa: 0x%x)", isa);
2341     }
2342
2343   /* Add flag options.  */
2344   for (i = 0; i < sizeof (flag_opts) / sizeof (flag_opts[0]); i++)
2345     {
2346       if ((flags & flag_opts[i].mask) != 0)
2347         {
2348           opts[num++][0] = flag_opts[i].option;
2349           flags &= ~ flag_opts[i].mask;
2350         }
2351     }
2352
2353   if (flags && add_nl_p)
2354     {
2355       opts[num++][0] = target_other;
2356       sprintf (target_other, "(other flags: 0x%x)", isa);
2357     }
2358
2359   /* Add -fpmath= option.  */
2360   if (fpmath)
2361     {
2362       opts[num][0] = "-mfpmath=";
2363       opts[num++][1] = fpmath;
2364     }
2365
2366   /* Any options?  */
2367   if (num == 0)
2368     return NULL;
2369
2370   gcc_assert (num < sizeof (opts) / sizeof (opts[0]));
2371
2372   /* Size the string.  */
2373   len = 0;
2374   sep_len = (add_nl_p) ? 3 : 1;
2375   for (i = 0; i < num; i++)
2376     {
2377       len += sep_len;
2378       for (j = 0; j < 2; j++)
2379         if (opts[i][j])
2380           len += strlen (opts[i][j]);
2381     }
2382
2383   /* Build the string.  */
2384   ret = ptr = (char *) xmalloc (len);
2385   line_len = 0;
2386
2387   for (i = 0; i < num; i++)
2388     {
2389       size_t len2[2];
2390
2391       for (j = 0; j < 2; j++)
2392         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2393
2394       if (i != 0)
2395         {
2396           *ptr++ = ' ';
2397           line_len++;
2398
2399           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2400             {
2401               *ptr++ = '\\';
2402               *ptr++ = '\n';
2403               line_len = 0;
2404             }
2405         }
2406
2407       for (j = 0; j < 2; j++)
2408         if (opts[i][j])
2409           {
2410             memcpy (ptr, opts[i][j], len2[j]);
2411             ptr += len2[j];
2412             line_len += len2[j];
2413           }
2414     }
2415
2416   *ptr = '\0';
2417   gcc_assert (ret + len >= ptr);
2418
2419   return ret;
2420 }
2421
2422 /* Function that is callable from the debugger to print the current
2423    options.  */
2424 void
2425 ix86_debug_options (void)
2426 {
2427   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2428                                    ix86_arch_string, ix86_tune_string,
2429                                    ix86_fpmath_string, true);
2430
2431   if (opts)
2432     {
2433       fprintf (stderr, "%s\n\n", opts);
2434       free (opts);
2435     }
2436   else
2437     fprintf (stderr, "<no options>\n\n");
2438
2439   return;
2440 }
2441 \f
2442 /* Sometimes certain combinations of command options do not make
2443    sense on a particular target machine.  You can define a macro
2444    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
2445    defined, is executed once just after all the command options have
2446    been parsed.
2447
2448    Don't use this macro to turn on various extra optimizations for
2449    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
2450
2451 void
2452 override_options (bool main_args_p)
2453 {
2454   int i;
2455   unsigned int ix86_arch_mask, ix86_tune_mask;
2456   const char *prefix;
2457   const char *suffix;
2458   const char *sw;
2459
2460   /* Comes from final.c -- no real reason to change it.  */
2461 #define MAX_CODE_ALIGN 16
2462
2463   enum pta_flags
2464     {
2465       PTA_SSE = 1 << 0,
2466       PTA_SSE2 = 1 << 1,
2467       PTA_SSE3 = 1 << 2,
2468       PTA_MMX = 1 << 3,
2469       PTA_PREFETCH_SSE = 1 << 4,
2470       PTA_3DNOW = 1 << 5,
2471       PTA_3DNOW_A = 1 << 6,
2472       PTA_64BIT = 1 << 7,
2473       PTA_SSSE3 = 1 << 8,
2474       PTA_CX16 = 1 << 9,
2475       PTA_POPCNT = 1 << 10,
2476       PTA_ABM = 1 << 11,
2477       PTA_SSE4A = 1 << 12,
2478       PTA_NO_SAHF = 1 << 13,
2479       PTA_SSE4_1 = 1 << 14,
2480       PTA_SSE4_2 = 1 << 15,
2481       PTA_SSE5 = 1 << 16,
2482       PTA_AES = 1 << 17,
2483       PTA_PCLMUL = 1 << 18,
2484       PTA_AVX = 1 << 19,
2485       PTA_FMA = 1 << 20 
2486     };
2487
2488   static struct pta
2489     {
2490       const char *const name;           /* processor name or nickname.  */
2491       const enum processor_type processor;
2492       const unsigned /*enum pta_flags*/ flags;
2493     }
2494   const processor_alias_table[] =
2495     {
2496       {"i386", PROCESSOR_I386, 0},
2497       {"i486", PROCESSOR_I486, 0},
2498       {"i586", PROCESSOR_PENTIUM, 0},
2499       {"pentium", PROCESSOR_PENTIUM, 0},
2500       {"pentium-mmx", PROCESSOR_PENTIUM, PTA_MMX},
2501       {"winchip-c6", PROCESSOR_I486, PTA_MMX},
2502       {"winchip2", PROCESSOR_I486, PTA_MMX | PTA_3DNOW},
2503       {"c3", PROCESSOR_I486, PTA_MMX | PTA_3DNOW},
2504       {"c3-2", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2505       {"i686", PROCESSOR_PENTIUMPRO, 0},
2506       {"pentiumpro", PROCESSOR_PENTIUMPRO, 0},
2507       {"pentium2", PROCESSOR_PENTIUMPRO, PTA_MMX},
2508       {"pentium3", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2509       {"pentium3m", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2510       {"pentium-m", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE | PTA_SSE2},
2511       {"pentium4", PROCESSOR_PENTIUM4, PTA_MMX |PTA_SSE | PTA_SSE2},
2512       {"pentium4m", PROCESSOR_PENTIUM4, PTA_MMX | PTA_SSE | PTA_SSE2},
2513       {"prescott", PROCESSOR_NOCONA, PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3},
2514       {"nocona", PROCESSOR_NOCONA, (PTA_64BIT
2515                                     | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2516                                     | PTA_CX16 | PTA_NO_SAHF)},
2517       {"core2", PROCESSOR_CORE2, (PTA_64BIT
2518                                   | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2519                                   | PTA_SSSE3
2520                                   | PTA_CX16)},
2521       {"geode", PROCESSOR_GEODE, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2522                                   |PTA_PREFETCH_SSE)},
2523       {"k6", PROCESSOR_K6, PTA_MMX},
2524       {"k6-2", PROCESSOR_K6, PTA_MMX | PTA_3DNOW},
2525       {"k6-3", PROCESSOR_K6, PTA_MMX | PTA_3DNOW},
2526       {"athlon", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2527                                     | PTA_PREFETCH_SSE)},
2528       {"athlon-tbird", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2529                                           | PTA_PREFETCH_SSE)},
2530       {"athlon-4", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2531                                       | PTA_SSE)},
2532       {"athlon-xp", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2533                                        | PTA_SSE)},
2534       {"athlon-mp", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2535                                        | PTA_SSE)},
2536       {"x86-64", PROCESSOR_K8, (PTA_64BIT
2537                                 | PTA_MMX | PTA_SSE | PTA_SSE2
2538                                 | PTA_NO_SAHF)},
2539       {"k8", PROCESSOR_K8, (PTA_64BIT
2540                             | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2541                             | PTA_SSE | PTA_SSE2
2542                             | PTA_NO_SAHF)},
2543       {"k8-sse3", PROCESSOR_K8, (PTA_64BIT
2544                                  | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2545                                  | PTA_SSE | PTA_SSE2 | PTA_SSE3
2546                                  | PTA_NO_SAHF)},
2547       {"opteron", PROCESSOR_K8, (PTA_64BIT
2548                                  | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2549                                  | PTA_SSE | PTA_SSE2
2550                                  | PTA_NO_SAHF)},
2551       {"opteron-sse3", PROCESSOR_K8, (PTA_64BIT
2552                                       | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2553                                       | PTA_SSE | PTA_SSE2 | PTA_SSE3
2554                                       | PTA_NO_SAHF)},
2555       {"athlon64", PROCESSOR_K8, (PTA_64BIT
2556                                   | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2557                                   | PTA_SSE | PTA_SSE2
2558                                   | PTA_NO_SAHF)},
2559       {"athlon64-sse3", PROCESSOR_K8, (PTA_64BIT
2560                                        | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2561                                        | PTA_SSE | PTA_SSE2 | PTA_SSE3
2562                                        | PTA_NO_SAHF)},
2563       {"athlon-fx", PROCESSOR_K8, (PTA_64BIT
2564                                    | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2565                                    | PTA_SSE | PTA_SSE2
2566                                    | PTA_NO_SAHF)},
2567       {"amdfam10", PROCESSOR_AMDFAM10, (PTA_64BIT
2568                                         | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2569                                         | PTA_SSE | PTA_SSE2 | PTA_SSE3
2570                                         | PTA_SSE4A
2571                                         | PTA_CX16 | PTA_ABM)},
2572       {"barcelona", PROCESSOR_AMDFAM10, (PTA_64BIT
2573                                          | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2574                                          | PTA_SSE | PTA_SSE2 | PTA_SSE3
2575                                          | PTA_SSE4A
2576                                          | PTA_CX16 | PTA_ABM)},
2577       {"generic32", PROCESSOR_GENERIC32, 0 /* flags are only used for -march switch.  */ },
2578       {"generic64", PROCESSOR_GENERIC64, PTA_64BIT /* flags are only used for -march switch.  */ },
2579     };
2580
2581   int const pta_size = ARRAY_SIZE (processor_alias_table);
2582
2583   /* Set up prefix/suffix so the error messages refer to either the command
2584      line argument, or the attribute(target).  */
2585   if (main_args_p)
2586     {
2587       prefix = "-m";
2588       suffix = "";
2589       sw = "switch";
2590     }
2591   else
2592     {
2593       prefix = "option(\"";
2594       suffix = "\")";
2595       sw = "attribute";
2596     }
2597
2598 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2599   SUBTARGET_OVERRIDE_OPTIONS;
2600 #endif
2601
2602 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2603   SUBSUBTARGET_OVERRIDE_OPTIONS;
2604 #endif
2605
2606   /* -fPIC is the default for x86_64.  */
2607   if (TARGET_MACHO && TARGET_64BIT)
2608     flag_pic = 2;
2609
2610   /* Set the default values for switches whose default depends on TARGET_64BIT
2611      in case they weren't overwritten by command line options.  */
2612   if (TARGET_64BIT)
2613     {
2614       /* Mach-O doesn't support omitting the frame pointer for now.  */
2615       if (flag_omit_frame_pointer == 2)
2616         flag_omit_frame_pointer = (TARGET_MACHO ? 0 : 1);
2617       if (flag_asynchronous_unwind_tables == 2)
2618         flag_asynchronous_unwind_tables = 1;
2619       if (flag_pcc_struct_return == 2)
2620         flag_pcc_struct_return = 0;
2621     }
2622   else
2623     {
2624       if (flag_omit_frame_pointer == 2)
2625         flag_omit_frame_pointer = 0;
2626       if (flag_asynchronous_unwind_tables == 2)
2627         flag_asynchronous_unwind_tables = 0;
2628       if (flag_pcc_struct_return == 2)
2629         flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
2630     }
2631
2632   /* Need to check -mtune=generic first.  */
2633   if (ix86_tune_string)
2634     {
2635       if (!strcmp (ix86_tune_string, "generic")
2636           || !strcmp (ix86_tune_string, "i686")
2637           /* As special support for cross compilers we read -mtune=native
2638              as -mtune=generic.  With native compilers we won't see the
2639              -mtune=native, as it was changed by the driver.  */
2640           || !strcmp (ix86_tune_string, "native"))
2641         {
2642           if (TARGET_64BIT)
2643             ix86_tune_string = "generic64";
2644           else
2645             ix86_tune_string = "generic32";
2646         }
2647       /* If this call is for setting the option attribute, allow the
2648          generic32/generic64 that was previously set.  */
2649       else if (!main_args_p
2650                && (!strcmp (ix86_tune_string, "generic32")
2651                    || !strcmp (ix86_tune_string, "generic64")))
2652         ;
2653       else if (!strncmp (ix86_tune_string, "generic", 7))
2654         error ("bad value (%s) for %stune=%s %s",
2655                ix86_tune_string, prefix, suffix, sw);
2656     }
2657   else
2658     {
2659       if (ix86_arch_string)
2660         ix86_tune_string = ix86_arch_string;
2661       if (!ix86_tune_string)
2662         {
2663           ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT];
2664           ix86_tune_defaulted = 1;
2665         }
2666
2667       /* ix86_tune_string is set to ix86_arch_string or defaulted.  We
2668          need to use a sensible tune option.  */
2669       if (!strcmp (ix86_tune_string, "generic")
2670           || !strcmp (ix86_tune_string, "x86-64")
2671           || !strcmp (ix86_tune_string, "i686"))
2672         {
2673           if (TARGET_64BIT)
2674             ix86_tune_string = "generic64";
2675           else
2676             ix86_tune_string = "generic32";
2677         }
2678     }
2679   if (ix86_stringop_string)
2680     {
2681       if (!strcmp (ix86_stringop_string, "rep_byte"))
2682         stringop_alg = rep_prefix_1_byte;
2683       else if (!strcmp (ix86_stringop_string, "libcall"))
2684         stringop_alg = libcall;
2685       else if (!strcmp (ix86_stringop_string, "rep_4byte"))
2686         stringop_alg = rep_prefix_4_byte;
2687       else if (!strcmp (ix86_stringop_string, "rep_8byte"))
2688         stringop_alg = rep_prefix_8_byte;
2689       else if (!strcmp (ix86_stringop_string, "byte_loop"))
2690         stringop_alg = loop_1_byte;
2691       else if (!strcmp (ix86_stringop_string, "loop"))
2692         stringop_alg = loop;
2693       else if (!strcmp (ix86_stringop_string, "unrolled_loop"))
2694         stringop_alg = unrolled_loop;
2695       else
2696         error ("bad value (%s) for %sstringop-strategy=%s %s",
2697                ix86_stringop_string, prefix, suffix, sw);
2698     }
2699   if (!strcmp (ix86_tune_string, "x86-64"))
2700     warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated.  Use "
2701              "%stune=k8%s or %stune=generic%s instead as appropriate.",
2702              prefix, suffix, prefix, suffix, prefix, suffix);
2703
2704   if (!ix86_arch_string)
2705     ix86_arch_string = TARGET_64BIT ? "x86-64" : "i386";
2706   else
2707     ix86_arch_specified = 1;
2708
2709   if (!strcmp (ix86_arch_string, "generic"))
2710     error ("generic CPU can be used only for %stune=%s %s",
2711            prefix, suffix, sw);
2712   if (!strncmp (ix86_arch_string, "generic", 7))
2713     error ("bad value (%s) for %sarch=%s %s",
2714            ix86_arch_string, prefix, suffix, sw);
2715
2716   if (ix86_cmodel_string != 0)
2717     {
2718       if (!strcmp (ix86_cmodel_string, "small"))
2719         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2720       else if (!strcmp (ix86_cmodel_string, "medium"))
2721         ix86_cmodel = flag_pic ? CM_MEDIUM_PIC : CM_MEDIUM;
2722       else if (!strcmp (ix86_cmodel_string, "large"))
2723         ix86_cmodel = flag_pic ? CM_LARGE_PIC : CM_LARGE;
2724       else if (flag_pic)
2725         error ("code model %s does not support PIC mode", ix86_cmodel_string);
2726       else if (!strcmp (ix86_cmodel_string, "32"))
2727         ix86_cmodel = CM_32;
2728       else if (!strcmp (ix86_cmodel_string, "kernel") && !flag_pic)
2729         ix86_cmodel = CM_KERNEL;
2730       else
2731         error ("bad value (%s) for %scmodel=%s %s",
2732                ix86_cmodel_string, prefix, suffix, sw);
2733     }
2734   else
2735     {
2736       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
2737          use of rip-relative addressing.  This eliminates fixups that
2738          would otherwise be needed if this object is to be placed in a
2739          DLL, and is essentially just as efficient as direct addressing.  */
2740       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
2741         ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
2742       else if (TARGET_64BIT)
2743         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2744       else
2745         ix86_cmodel = CM_32;
2746     }
2747   if (ix86_asm_string != 0)
2748     {
2749       if (! TARGET_MACHO
2750           && !strcmp (ix86_asm_string, "intel"))
2751         ix86_asm_dialect = ASM_INTEL;
2752       else if (!strcmp (ix86_asm_string, "att"))
2753         ix86_asm_dialect = ASM_ATT;
2754       else
2755         error ("bad value (%s) for %sasm=%s %s",
2756                ix86_asm_string, prefix, suffix, sw);
2757     }
2758   if ((TARGET_64BIT == 0) != (ix86_cmodel == CM_32))
2759     error ("code model %qs not supported in the %s bit mode",
2760            ix86_cmodel_string, TARGET_64BIT ? "64" : "32");
2761   if ((TARGET_64BIT != 0) != ((ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2762     sorry ("%i-bit mode not compiled in",
2763            (ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2764
2765   for (i = 0; i < pta_size; i++)
2766     if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
2767       {
2768         ix86_arch = processor_alias_table[i].processor;
2769         /* Default cpu tuning to the architecture.  */
2770         ix86_tune = ix86_arch;
2771
2772         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2773           error ("CPU you selected does not support x86-64 "
2774                  "instruction set");
2775
2776         if (processor_alias_table[i].flags & PTA_MMX
2777             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
2778           ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2779         if (processor_alias_table[i].flags & PTA_3DNOW
2780             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
2781           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
2782         if (processor_alias_table[i].flags & PTA_3DNOW_A
2783             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
2784           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
2785         if (processor_alias_table[i].flags & PTA_SSE
2786             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
2787           ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2788         if (processor_alias_table[i].flags & PTA_SSE2
2789             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
2790           ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2791         if (processor_alias_table[i].flags & PTA_SSE3
2792             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
2793           ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2794         if (processor_alias_table[i].flags & PTA_SSSE3
2795             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
2796           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2797         if (processor_alias_table[i].flags & PTA_SSE4_1
2798             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
2799           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2800         if (processor_alias_table[i].flags & PTA_SSE4_2
2801             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
2802           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
2803         if (processor_alias_table[i].flags & PTA_AVX
2804             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
2805           ix86_isa_flags |= OPTION_MASK_ISA_AVX;
2806         if (processor_alias_table[i].flags & PTA_FMA
2807             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
2808           ix86_isa_flags |= OPTION_MASK_ISA_FMA;
2809         if (processor_alias_table[i].flags & PTA_SSE4A
2810             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
2811           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2812         if (processor_alias_table[i].flags & PTA_SSE5
2813             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE5))
2814           ix86_isa_flags |= OPTION_MASK_ISA_SSE5;
2815         if (processor_alias_table[i].flags & PTA_ABM
2816             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
2817           ix86_isa_flags |= OPTION_MASK_ISA_ABM;
2818         if (processor_alias_table[i].flags & PTA_CX16
2819             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
2820           ix86_isa_flags |= OPTION_MASK_ISA_CX16;
2821         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
2822             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
2823           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
2824         if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF))
2825             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
2826           ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
2827         if (processor_alias_table[i].flags & PTA_AES
2828             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
2829           ix86_isa_flags |= OPTION_MASK_ISA_AES;
2830         if (processor_alias_table[i].flags & PTA_PCLMUL
2831             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
2832           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
2833         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
2834           x86_prefetch_sse = true;
2835
2836         break;
2837       }
2838
2839   if (i == pta_size)
2840     error ("bad value (%s) for %sarch=%s %s",
2841            ix86_arch_string, prefix, suffix, sw);
2842
2843   ix86_arch_mask = 1u << ix86_arch;
2844   for (i = 0; i < X86_ARCH_LAST; ++i)
2845     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
2846
2847   for (i = 0; i < pta_size; i++)
2848     if (! strcmp (ix86_tune_string, processor_alias_table[i].name))
2849       {
2850         ix86_tune = processor_alias_table[i].processor;
2851         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2852           {
2853             if (ix86_tune_defaulted)
2854               {
2855                 ix86_tune_string = "x86-64";
2856                 for (i = 0; i < pta_size; i++)
2857                   if (! strcmp (ix86_tune_string,
2858                                 processor_alias_table[i].name))
2859                     break;
2860                 ix86_tune = processor_alias_table[i].processor;
2861               }
2862             else
2863               error ("CPU you selected does not support x86-64 "
2864                      "instruction set");
2865           }
2866         /* Intel CPUs have always interpreted SSE prefetch instructions as
2867            NOPs; so, we can enable SSE prefetch instructions even when
2868            -mtune (rather than -march) points us to a processor that has them.
2869            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
2870            higher processors.  */
2871         if (TARGET_CMOVE
2872             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
2873           x86_prefetch_sse = true;
2874         break;
2875       }
2876   if (i == pta_size)
2877     error ("bad value (%s) for %stune=%s %s",
2878            ix86_tune_string, prefix, suffix, sw);
2879
2880   ix86_tune_mask = 1u << ix86_tune;
2881   for (i = 0; i < X86_TUNE_LAST; ++i)
2882     ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
2883
2884   if (optimize_size)
2885     ix86_cost = &ix86_size_cost;
2886   else
2887     ix86_cost = processor_target_table[ix86_tune].cost;
2888
2889   /* Arrange to set up i386_stack_locals for all functions.  */
2890   init_machine_status = ix86_init_machine_status;
2891
2892   /* Validate -mregparm= value.  */
2893   if (ix86_regparm_string)
2894     {
2895       if (TARGET_64BIT)
2896         warning (0, "%sregparm%s is ignored in 64-bit mode", prefix, suffix);
2897       i = atoi (ix86_regparm_string);
2898       if (i < 0 || i > REGPARM_MAX)
2899         error ("%sregparm=%d%s is not between 0 and %d",
2900                prefix, i, suffix, REGPARM_MAX);
2901       else
2902         ix86_regparm = i;
2903     }
2904   if (TARGET_64BIT)
2905     ix86_regparm = REGPARM_MAX;
2906
2907   /* If the user has provided any of the -malign-* options,
2908      warn and use that value only if -falign-* is not set.
2909      Remove this code in GCC 3.2 or later.  */
2910   if (ix86_align_loops_string)
2911     {
2912       warning (0, "%salign-loops%s is obsolete, use %salign-loops%s",
2913                prefix, suffix, prefix, suffix);
2914       if (align_loops == 0)
2915         {
2916           i = atoi (ix86_align_loops_string);
2917           if (i < 0 || i > MAX_CODE_ALIGN)
2918             error ("%salign-loops=%d%s is not between 0 and %d",
2919                    prefix, i, suffix, MAX_CODE_ALIGN);
2920           else
2921             align_loops = 1 << i;
2922         }
2923     }
2924
2925   if (ix86_align_jumps_string)
2926     {
2927       warning (0, "%salign-jumps%s is obsolete, use %salign-jumps%s",
2928                prefix, suffix, prefix, suffix);
2929       if (align_jumps == 0)
2930         {
2931           i = atoi (ix86_align_jumps_string);
2932           if (i < 0 || i > MAX_CODE_ALIGN)
2933             error ("%salign-loops=%d%s is not between 0 and %d",
2934                    prefix, i, suffix, MAX_CODE_ALIGN);
2935           else
2936             align_jumps = 1 << i;
2937         }
2938     }
2939
2940   if (ix86_align_funcs_string)
2941     {
2942       warning (0, "%salign-functions%s is obsolete, use %salign-functions%s",
2943                prefix, suffix, prefix, suffix);
2944       if (align_functions == 0)
2945         {
2946           i = atoi (ix86_align_funcs_string);
2947           if (i < 0 || i > MAX_CODE_ALIGN)
2948             error ("%salign-loops=%d%s is not between 0 and %d",
2949                    prefix, i, suffix, MAX_CODE_ALIGN);
2950           else
2951             align_functions = 1 << i;
2952         }
2953     }
2954
2955   /* Default align_* from the processor table.  */
2956   if (align_loops == 0)
2957     {
2958       align_loops = processor_target_table[ix86_tune].align_loop;
2959       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
2960     }
2961   if (align_jumps == 0)
2962     {
2963       align_jumps = processor_target_table[ix86_tune].align_jump;
2964       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
2965     }
2966   if (align_functions == 0)
2967     {
2968       align_functions = processor_target_table[ix86_tune].align_func;
2969     }
2970
2971   /* Validate -mbranch-cost= value, or provide default.  */
2972   ix86_branch_cost = ix86_cost->branch_cost;
2973   if (ix86_branch_cost_string)
2974     {
2975       i = atoi (ix86_branch_cost_string);
2976       if (i < 0 || i > 5)
2977         error ("%sbranch-cost=%d%s is not between 0 and 5", prefix, i, suffix);
2978       else
2979         ix86_branch_cost = i;
2980     }
2981   if (ix86_section_threshold_string)
2982     {
2983       i = atoi (ix86_section_threshold_string);
2984       if (i < 0)
2985         error ("%slarge-data-threshold=%d%s is negative", prefix, i, suffix);
2986       else
2987         ix86_section_threshold = i;
2988     }
2989
2990   if (ix86_tls_dialect_string)
2991     {
2992       if (strcmp (ix86_tls_dialect_string, "gnu") == 0)
2993         ix86_tls_dialect = TLS_DIALECT_GNU;
2994       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
2995         ix86_tls_dialect = TLS_DIALECT_GNU2;
2996       else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
2997         ix86_tls_dialect = TLS_DIALECT_SUN;
2998       else
2999         error ("bad value (%s) for %stls-dialect=%s %s",
3000                ix86_tls_dialect_string, prefix, suffix, sw);
3001     }
3002
3003   if (ix87_precision_string)
3004     {
3005       i = atoi (ix87_precision_string);
3006       if (i != 32 && i != 64 && i != 80)
3007         error ("pc%d is not valid precision setting (32, 64 or 80)", i);
3008     }
3009
3010   if (TARGET_64BIT)
3011     {
3012       target_flags |= TARGET_SUBTARGET64_DEFAULT & ~target_flags_explicit;
3013
3014       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3015          explicitly disable any of these.  In particular, disabling SSE and
3016          MMX for kernel code is extremely useful.  */
3017       if (!ix86_arch_specified)
3018       ix86_isa_flags
3019         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3020              | TARGET_SUBTARGET64_ISA_DEFAULT) & ~ix86_isa_flags_explicit);
3021
3022       if (TARGET_RTD)
3023         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3024     }
3025   else
3026     {
3027       target_flags |= TARGET_SUBTARGET32_DEFAULT & ~target_flags_explicit;
3028
3029       if (!ix86_arch_specified)
3030       ix86_isa_flags
3031         |= TARGET_SUBTARGET32_ISA_DEFAULT & ~ix86_isa_flags_explicit;
3032
3033       /* i386 ABI does not specify red zone.  It still makes sense to use it
3034          when programmer takes care to stack from being destroyed.  */
3035       if (!(target_flags_explicit & MASK_NO_RED_ZONE))
3036         target_flags |= MASK_NO_RED_ZONE;
3037     }
3038
3039   /* Keep nonleaf frame pointers.  */
3040   if (flag_omit_frame_pointer)
3041     target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3042   else if (TARGET_OMIT_LEAF_FRAME_POINTER)
3043     flag_omit_frame_pointer = 1;
3044
3045   /* If we're doing fast math, we don't care about comparison order
3046      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3047   if (flag_finite_math_only)
3048     target_flags &= ~MASK_IEEE_FP;
3049
3050   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3051      since the insns won't need emulation.  */
3052   if (x86_arch_always_fancy_math_387 & ix86_arch_mask)
3053     target_flags &= ~MASK_NO_FANCY_MATH_387;
3054
3055   /* Likewise, if the target doesn't have a 387, or we've specified
3056      software floating point, don't use 387 inline intrinsics.  */
3057   if (!TARGET_80387)
3058     target_flags |= MASK_NO_FANCY_MATH_387;
3059
3060   /* Turn on MMX builtins for -msse.  */
3061   if (TARGET_SSE)
3062     {
3063       ix86_isa_flags |= OPTION_MASK_ISA_MMX & ~ix86_isa_flags_explicit;
3064       x86_prefetch_sse = true;
3065     }
3066
3067   /* Turn on popcnt instruction for -msse4.2 or -mabm.  */
3068   if (TARGET_SSE4_2 || TARGET_ABM)
3069     ix86_isa_flags |= OPTION_MASK_ISA_POPCNT & ~ix86_isa_flags_explicit;
3070
3071   /* Validate -mpreferred-stack-boundary= value or default it to
3072      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
3073   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
3074   if (ix86_preferred_stack_boundary_string)
3075     {
3076       i = atoi (ix86_preferred_stack_boundary_string);
3077       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3078         error ("%spreferred-stack-boundary=%d%s is not between %d and 12",
3079                prefix, i, suffix, TARGET_64BIT ? 4 : 2);
3080       else
3081         ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
3082     }
3083
3084   /* Set the default value for -mstackrealign.  */
3085   if (ix86_force_align_arg_pointer == -1)
3086     ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
3087
3088   /* Validate -mincoming-stack-boundary= value or default it to
3089      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
3090   if (ix86_force_align_arg_pointer)
3091     ix86_default_incoming_stack_boundary = MIN_STACK_BOUNDARY;
3092   else
3093     ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
3094   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
3095   if (ix86_incoming_stack_boundary_string)
3096     {
3097       i = atoi (ix86_incoming_stack_boundary_string);
3098       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3099         error ("-mincoming-stack-boundary=%d is not between %d and 12",
3100                i, TARGET_64BIT ? 4 : 2);
3101       else
3102         {
3103           ix86_user_incoming_stack_boundary = (1 << i) * BITS_PER_UNIT;
3104           ix86_incoming_stack_boundary
3105             = ix86_user_incoming_stack_boundary;
3106         }
3107     }
3108
3109   /* Accept -msseregparm only if at least SSE support is enabled.  */
3110   if (TARGET_SSEREGPARM
3111       && ! TARGET_SSE)
3112     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
3113
3114   ix86_fpmath = TARGET_FPMATH_DEFAULT;
3115   if (ix86_fpmath_string != 0)
3116     {
3117       if (! strcmp (ix86_fpmath_string, "387"))
3118         ix86_fpmath = FPMATH_387;
3119       else if (! strcmp (ix86_fpmath_string, "sse"))
3120         {
3121           if (!TARGET_SSE)
3122             {
3123               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3124               ix86_fpmath = FPMATH_387;
3125             }
3126           else
3127             ix86_fpmath = FPMATH_SSE;
3128         }
3129       else if (! strcmp (ix86_fpmath_string, "387,sse")
3130                || ! strcmp (ix86_fpmath_string, "387+sse")
3131                || ! strcmp (ix86_fpmath_string, "sse,387")
3132                || ! strcmp (ix86_fpmath_string, "sse+387")
3133                || ! strcmp (ix86_fpmath_string, "both"))
3134         {
3135           if (!TARGET_SSE)
3136             {
3137               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3138               ix86_fpmath = FPMATH_387;
3139             }
3140           else if (!TARGET_80387)
3141             {
3142               warning (0, "387 instruction set disabled, using SSE arithmetics");
3143               ix86_fpmath = FPMATH_SSE;
3144             }
3145           else
3146             ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
3147         }
3148       else
3149         error ("bad value (%s) for %sfpmath=%s %s",
3150                ix86_fpmath_string, prefix, suffix, sw);
3151     }
3152
3153   /* If the i387 is disabled, then do not return values in it. */
3154   if (!TARGET_80387)
3155     target_flags &= ~MASK_FLOAT_RETURNS;
3156
3157   /* Use external vectorized library in vectorizing intrinsics.  */
3158   if (ix86_veclibabi_string)
3159     {
3160       if (strcmp (ix86_veclibabi_string, "svml") == 0)
3161         ix86_veclib_handler = ix86_veclibabi_svml;
3162       else if (strcmp (ix86_veclibabi_string, "acml") == 0)
3163         ix86_veclib_handler = ix86_veclibabi_acml;
3164       else
3165         error ("unknown vectorization library ABI type (%s) for "
3166                "%sveclibabi=%s %s", ix86_veclibabi_string,
3167                prefix, suffix, sw);
3168     }
3169
3170   if ((x86_accumulate_outgoing_args & ix86_tune_mask)
3171       && !(target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3172       && !optimize_size)
3173     target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3174
3175   /* ??? Unwind info is not correct around the CFG unless either a frame
3176      pointer is present or M_A_O_A is set.  Fixing this requires rewriting
3177      unwind info generation to be aware of the CFG and propagating states
3178      around edges.  */
3179   if ((flag_unwind_tables || flag_asynchronous_unwind_tables
3180        || flag_exceptions || flag_non_call_exceptions)
3181       && flag_omit_frame_pointer
3182       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3183     {
3184       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3185         warning (0, "unwind tables currently require either a frame pointer "
3186                  "or %saccumulate-outgoing-args%s for correctness",
3187                  prefix, suffix);
3188       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3189     }
3190
3191   /* If stack probes are required, the space used for large function
3192      arguments on the stack must also be probed, so enable
3193      -maccumulate-outgoing-args so this happens in the prologue.  */
3194   if (TARGET_STACK_PROBE
3195       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3196     {
3197       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3198         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
3199                  "for correctness", prefix, suffix);
3200       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3201     }
3202
3203   /* For sane SSE instruction set generation we need fcomi instruction.
3204      It is safe to enable all CMOVE instructions.  */
3205   if (TARGET_SSE)
3206     TARGET_CMOVE = 1;
3207
3208   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
3209   {
3210     char *p;
3211     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
3212     p = strchr (internal_label_prefix, 'X');
3213     internal_label_prefix_len = p - internal_label_prefix;
3214     *p = '\0';
3215   }
3216
3217   /* When scheduling description is not available, disable scheduler pass
3218      so it won't slow down the compilation and make x87 code slower.  */
3219   if (!TARGET_SCHEDULE)
3220     flag_schedule_insns_after_reload = flag_schedule_insns = 0;
3221
3222   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
3223     set_param_value ("simultaneous-prefetches",
3224                      ix86_cost->simultaneous_prefetches);
3225   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
3226     set_param_value ("l1-cache-line-size", ix86_cost->prefetch_block);
3227   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
3228     set_param_value ("l1-cache-size", ix86_cost->l1_cache_size);
3229   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
3230     set_param_value ("l2-cache-size", ix86_cost->l2_cache_size);
3231
3232   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
3233      can be optimized to ap = __builtin_next_arg (0).  */
3234   if (!TARGET_64BIT)
3235     targetm.expand_builtin_va_start = NULL;
3236
3237   if (TARGET_64BIT)
3238     {
3239       ix86_gen_leave = gen_leave_rex64;
3240       ix86_gen_pop1 = gen_popdi1;
3241       ix86_gen_add3 = gen_adddi3;
3242       ix86_gen_sub3 = gen_subdi3;
3243       ix86_gen_sub3_carry = gen_subdi3_carry_rex64;
3244       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
3245       ix86_gen_monitor = gen_sse3_monitor64;
3246       ix86_gen_andsp = gen_anddi3;
3247     }
3248   else
3249     {
3250       ix86_gen_leave = gen_leave;
3251       ix86_gen_pop1 = gen_popsi1;
3252       ix86_gen_add3 = gen_addsi3;
3253       ix86_gen_sub3 = gen_subsi3;
3254       ix86_gen_sub3_carry = gen_subsi3_carry;
3255       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
3256       ix86_gen_monitor = gen_sse3_monitor;
3257       ix86_gen_andsp = gen_andsi3;
3258     }
3259
3260 #ifdef USE_IX86_CLD
3261   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
3262   if (!TARGET_64BIT)
3263     target_flags |= MASK_CLD & ~target_flags_explicit;
3264 #endif
3265
3266   /* Save the initial options in case the user does function specific options */
3267   if (main_args_p)
3268     target_option_default_node = target_option_current_node
3269       = build_target_option_node ();
3270 }
3271 \f
3272 /* Save the current options */
3273
3274 static void
3275 ix86_function_specific_save (struct cl_target_option *ptr)
3276 {
3277   gcc_assert (IN_RANGE (ix86_arch, 0, 255));
3278   gcc_assert (IN_RANGE (ix86_tune, 0, 255));
3279   gcc_assert (IN_RANGE (ix86_fpmath, 0, 255));
3280   gcc_assert (IN_RANGE (ix86_branch_cost, 0, 255));
3281
3282   ptr->arch = ix86_arch;
3283   ptr->tune = ix86_tune;
3284   ptr->fpmath = ix86_fpmath;
3285   ptr->branch_cost = ix86_branch_cost;
3286   ptr->tune_defaulted = ix86_tune_defaulted;
3287   ptr->arch_specified = ix86_arch_specified;
3288   ptr->ix86_isa_flags_explicit = ix86_isa_flags_explicit;
3289   ptr->target_flags_explicit = target_flags_explicit;
3290 }
3291
3292 /* Restore the current options */
3293
3294 static void
3295 ix86_function_specific_restore (struct cl_target_option *ptr)
3296 {
3297   enum processor_type old_tune = ix86_tune;
3298   enum processor_type old_arch = ix86_arch;
3299   unsigned int ix86_arch_mask, ix86_tune_mask;
3300   int i;
3301
3302   ix86_arch = ptr->arch;
3303   ix86_tune = ptr->tune;
3304   ix86_fpmath = ptr->fpmath;
3305   ix86_branch_cost = ptr->branch_cost;
3306   ix86_tune_defaulted = ptr->tune_defaulted;
3307   ix86_arch_specified = ptr->arch_specified;
3308   ix86_isa_flags_explicit = ptr->ix86_isa_flags_explicit;
3309   target_flags_explicit = ptr->target_flags_explicit;
3310
3311   /* Recreate the arch feature tests if the arch changed */
3312   if (old_arch != ix86_arch)
3313     {
3314       ix86_arch_mask = 1u << ix86_arch;
3315       for (i = 0; i < X86_ARCH_LAST; ++i)
3316         ix86_arch_features[i]
3317           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3318     }
3319
3320   /* Recreate the tune optimization tests */
3321   if (old_tune != ix86_tune)
3322     {
3323       ix86_tune_mask = 1u << ix86_tune;
3324       for (i = 0; i < X86_TUNE_LAST; ++i)
3325         ix86_tune_features[i]
3326           = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3327     }
3328 }
3329
3330 /* Print the current options */
3331
3332 static void
3333 ix86_function_specific_print (FILE *file, int indent,
3334                               struct cl_target_option *ptr)
3335 {
3336   char *target_string
3337     = ix86_target_string (ptr->ix86_isa_flags, ptr->target_flags,
3338                           NULL, NULL, NULL, false);
3339
3340   fprintf (file, "%*sarch = %d (%s)\n",
3341            indent, "",
3342            ptr->arch,
3343            ((ptr->arch < TARGET_CPU_DEFAULT_max)
3344             ? cpu_names[ptr->arch]
3345             : "<unknown>"));
3346
3347   fprintf (file, "%*stune = %d (%s)\n",
3348            indent, "",
3349            ptr->tune,
3350            ((ptr->tune < TARGET_CPU_DEFAULT_max)
3351             ? cpu_names[ptr->tune]
3352             : "<unknown>"));
3353
3354   fprintf (file, "%*sfpmath = %d%s%s\n", indent, "", ptr->fpmath,
3355            (ptr->fpmath & FPMATH_387) ? ", 387" : "",
3356            (ptr->fpmath & FPMATH_SSE) ? ", sse" : "");
3357   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
3358
3359   if (target_string)
3360     {
3361       fprintf (file, "%*s%s\n", indent, "", target_string);
3362       free (target_string);
3363     }
3364 }
3365
3366 \f
3367 /* Inner function to process the attribute((target(...))), take an argument and
3368    set the current options from the argument. If we have a list, recursively go
3369    over the list.  */
3370
3371 static bool
3372 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[])
3373 {
3374   char *next_optstr;
3375   bool ret = true;
3376
3377 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
3378 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
3379 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
3380 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
3381
3382   enum ix86_opt_type
3383   {
3384     ix86_opt_unknown,
3385     ix86_opt_yes,
3386     ix86_opt_no,
3387     ix86_opt_str,
3388     ix86_opt_isa
3389   };
3390
3391   static const struct
3392   {
3393     const char *string;
3394     size_t len;
3395     enum ix86_opt_type type;
3396     int opt;
3397     int mask;
3398   } attrs[] = {
3399     /* isa options */
3400     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
3401     IX86_ATTR_ISA ("abm",       OPT_mabm),
3402     IX86_ATTR_ISA ("aes",       OPT_maes),
3403     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
3404     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
3405     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
3406     IX86_ATTR_ISA ("sse",       OPT_msse),
3407     IX86_ATTR_ISA ("sse2",      OPT_msse2),
3408     IX86_ATTR_ISA ("sse3",      OPT_msse3),
3409     IX86_ATTR_ISA ("sse4",      OPT_msse4),
3410     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
3411     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
3412     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
3413     IX86_ATTR_ISA ("sse5",      OPT_msse5),
3414     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
3415
3416     /* string options */
3417     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
3418     IX86_ATTR_STR ("fpmath=",   IX86_FUNCTION_SPECIFIC_FPMATH),
3419     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
3420
3421     /* flag options */
3422     IX86_ATTR_YES ("cld",
3423                    OPT_mcld,
3424                    MASK_CLD),
3425
3426     IX86_ATTR_NO ("fancy-math-387",
3427                   OPT_mfancy_math_387,
3428                   MASK_NO_FANCY_MATH_387),
3429
3430     IX86_ATTR_NO ("fused-madd",
3431                   OPT_mfused_madd,
3432                   MASK_NO_FUSED_MADD),
3433
3434     IX86_ATTR_YES ("ieee-fp",
3435                    OPT_mieee_fp,
3436                    MASK_IEEE_FP),
3437
3438     IX86_ATTR_YES ("inline-all-stringops",
3439                    OPT_minline_all_stringops,
3440                    MASK_INLINE_ALL_STRINGOPS),
3441
3442     IX86_ATTR_YES ("inline-stringops-dynamically",
3443                    OPT_minline_stringops_dynamically,
3444                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
3445
3446     IX86_ATTR_NO ("align-stringops",
3447                   OPT_mno_align_stringops,
3448                   MASK_NO_ALIGN_STRINGOPS),
3449
3450     IX86_ATTR_YES ("recip",
3451                    OPT_mrecip,
3452                    MASK_RECIP),
3453
3454   };
3455
3456   /* If this is a list, recurse to get the options.  */
3457   if (TREE_CODE (args) == TREE_LIST)
3458     {
3459       bool ret = true;
3460
3461       for (; args; args = TREE_CHAIN (args))
3462         if (TREE_VALUE (args)
3463             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args), p_strings))
3464           ret = false;
3465
3466       return ret;
3467     }
3468
3469   else if (TREE_CODE (args) != STRING_CST)
3470     gcc_unreachable ();
3471
3472   /* Handle multiple arguments separated by commas.  */
3473   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
3474
3475   while (next_optstr && *next_optstr != '\0')
3476     {
3477       char *p = next_optstr;
3478       char *orig_p = p;
3479       char *comma = strchr (next_optstr, ',');
3480       const char *opt_string;
3481       size_t len, opt_len;
3482       int opt;
3483       bool opt_set_p;
3484       char ch;
3485       unsigned i;
3486       enum ix86_opt_type type = ix86_opt_unknown;
3487       int mask = 0;
3488
3489       if (comma)
3490         {
3491           *comma = '\0';
3492           len = comma - next_optstr;
3493           next_optstr = comma + 1;
3494         }
3495       else
3496         {
3497           len = strlen (p);
3498           next_optstr = NULL;
3499         }
3500
3501       /* Recognize no-xxx.  */
3502       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
3503         {
3504           opt_set_p = false;
3505           p += 3;
3506           len -= 3;
3507         }
3508       else
3509         opt_set_p = true;
3510
3511       /* Find the option.  */
3512       ch = *p;
3513       opt = N_OPTS;
3514       for (i = 0; i < sizeof (attrs) / sizeof (attrs[0]); i++)
3515         {
3516           type = attrs[i].type;
3517           opt_len = attrs[i].len;
3518           if (ch == attrs[i].string[0]
3519               && ((type != ix86_opt_str) ? len == opt_len : len > opt_len)
3520               && memcmp (p, attrs[i].string, opt_len) == 0)
3521             {
3522               opt = attrs[i].opt;
3523               mask = attrs[i].mask;
3524               opt_string = attrs[i].string;
3525               break;
3526             }
3527         }
3528
3529       /* Process the option.  */
3530       if (opt == N_OPTS)
3531         {
3532           error ("attribute(target(\"%s\")) is unknown", orig_p);
3533           ret = false;
3534         }
3535
3536       else if (type == ix86_opt_isa)
3537         ix86_handle_option (opt, p, opt_set_p);
3538
3539       else if (type == ix86_opt_yes || type == ix86_opt_no)
3540         {
3541           if (type == ix86_opt_no)
3542             opt_set_p = !opt_set_p;
3543
3544           if (opt_set_p)
3545             target_flags |= mask;
3546           else
3547             target_flags &= ~mask;
3548         }
3549
3550       else if (type == ix86_opt_str)
3551         {
3552           if (p_strings[opt])
3553             {
3554               error ("option(\"%s\") was already specified", opt_string);
3555               ret = false;
3556             }
3557           else
3558             p_strings[opt] = xstrdup (p + opt_len);
3559         }
3560
3561       else
3562         gcc_unreachable ();
3563     }
3564
3565   return ret;
3566 }
3567
3568 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
3569
3570 tree
3571 ix86_valid_target_attribute_tree (tree args)
3572 {
3573   const char *orig_arch_string = ix86_arch_string;
3574   const char *orig_tune_string = ix86_tune_string;
3575   const char *orig_fpmath_string = ix86_fpmath_string;
3576   int orig_tune_defaulted = ix86_tune_defaulted;
3577   int orig_arch_specified = ix86_arch_specified;
3578   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL, NULL };
3579   tree t = NULL_TREE;
3580   int i;
3581   struct cl_target_option *def
3582     = TREE_TARGET_OPTION (target_option_default_node);
3583
3584   /* Process each of the options on the chain.  */
3585   if (! ix86_valid_target_attribute_inner_p (args, option_strings))
3586     return NULL_TREE;
3587
3588   /* If the changed options are different from the default, rerun override_options,
3589      and then save the options away.  The string options are are attribute options,
3590      and will be undone when we copy the save structure.  */
3591   if (ix86_isa_flags != def->ix86_isa_flags
3592       || target_flags != def->target_flags
3593       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
3594       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
3595       || option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3596     {
3597       /* If we are using the default tune= or arch=, undo the string assigned,
3598          and use the default.  */
3599       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
3600         ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
3601       else if (!orig_arch_specified)
3602         ix86_arch_string = NULL;
3603
3604       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
3605         ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
3606       else if (orig_tune_defaulted)
3607         ix86_tune_string = NULL;
3608
3609       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
3610       if (option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3611         ix86_fpmath_string = option_strings[IX86_FUNCTION_SPECIFIC_FPMATH];
3612       else if (!TARGET_64BIT && TARGET_SSE)
3613         ix86_fpmath_string = "sse,387";
3614
3615       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
3616       override_options (false);
3617
3618       /* Add any builtin functions with the new isa if any.  */
3619       ix86_add_new_builtins (ix86_isa_flags);
3620
3621       /* Save the current options unless we are validating options for
3622          #pragma.  */
3623       t = build_target_option_node ();
3624
3625       ix86_arch_string = orig_arch_string;
3626       ix86_tune_string = orig_tune_string;
3627       ix86_fpmath_string = orig_fpmath_string;
3628
3629       /* Free up memory allocated to hold the strings */
3630       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
3631         if (option_strings[i])
3632           free (option_strings[i]);
3633     }
3634
3635   return t;
3636 }
3637
3638 /* Hook to validate attribute((target("string"))).  */
3639
3640 static bool
3641 ix86_valid_target_attribute_p (tree fndecl,
3642                                tree ARG_UNUSED (name),
3643                                tree args,
3644                                int ARG_UNUSED (flags))
3645 {
3646   struct cl_target_option cur_target;
3647   bool ret = true;
3648   tree old_optimize = build_optimization_node ();
3649   tree new_target, new_optimize;
3650   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
3651
3652   /* If the function changed the optimization levels as well as setting target
3653      options, start with the optimizations specified.  */
3654   if (func_optimize && func_optimize != old_optimize)
3655     cl_optimization_restore (TREE_OPTIMIZATION (func_optimize));
3656
3657   /* The target attributes may also change some optimization flags, so update
3658      the optimization options if necessary.  */
3659   cl_target_option_save (&cur_target);
3660   new_target = ix86_valid_target_attribute_tree (args);
3661   new_optimize = build_optimization_node ();
3662
3663   if (!new_target)
3664     ret = false;
3665
3666   else if (fndecl)
3667     {
3668       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
3669
3670       if (old_optimize != new_optimize)
3671         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
3672     }
3673
3674   cl_target_option_restore (&cur_target);
3675
3676   if (old_optimize != new_optimize)
3677     cl_optimization_restore (TREE_OPTIMIZATION (old_optimize));
3678
3679   return ret;
3680 }
3681
3682 \f
3683 /* Hook to determine if one function can safely inline another.  */
3684
3685 static bool
3686 ix86_can_inline_p (tree caller, tree callee)
3687 {
3688   bool ret = false;
3689   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
3690   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
3691
3692   /* If callee has no option attributes, then it is ok to inline.  */
3693   if (!callee_tree)
3694     ret = true;
3695
3696   /* If caller has no option attributes, but callee does then it is not ok to
3697      inline.  */
3698   else if (!caller_tree)
3699     ret = false;
3700
3701   else
3702     {
3703       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
3704       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
3705
3706       /* Callee's isa options should a subset of the caller's, i.e. a SSE5 function
3707          can inline a SSE2 function but a SSE2 function can't inline a SSE5
3708          function.  */
3709       if ((caller_opts->ix86_isa_flags & callee_opts->ix86_isa_flags)
3710           != callee_opts->ix86_isa_flags)
3711         ret = false;
3712
3713       /* See if we have the same non-isa options.  */
3714       else if (caller_opts->target_flags != callee_opts->target_flags)
3715         ret = false;
3716
3717       /* See if arch, tune, etc. are the same.  */
3718       else if (caller_opts->arch != callee_opts->arch)
3719         ret = false;
3720
3721       else if (caller_opts->tune != callee_opts->tune)
3722         ret = false;
3723
3724       else if (caller_opts->fpmath != callee_opts->fpmath)
3725         ret = false;
3726
3727       else if (caller_opts->branch_cost != callee_opts->branch_cost)
3728         ret = false;
3729
3730       else
3731         ret = true;
3732     }
3733
3734   return ret;
3735 }
3736
3737 \f
3738 /* Remember the last target of ix86_set_current_function.  */
3739 static GTY(()) tree ix86_previous_fndecl;
3740
3741 /* Establish appropriate back-end context for processing the function
3742    FNDECL.  The argument might be NULL to indicate processing at top
3743    level, outside of any function scope.  */
3744 static void
3745 ix86_set_current_function (tree fndecl)
3746 {
3747   /* Only change the context if the function changes.  This hook is called
3748      several times in the course of compiling a function, and we don't want to
3749      slow things down too much or call target_reinit when it isn't safe.  */
3750   if (fndecl && fndecl != ix86_previous_fndecl)
3751     {
3752       tree old_tree = (ix86_previous_fndecl
3753                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
3754                        : NULL_TREE);
3755
3756       tree new_tree = (fndecl
3757                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
3758                        : NULL_TREE);
3759
3760       ix86_previous_fndecl = fndecl;
3761       if (old_tree == new_tree)
3762         ;
3763
3764       else if (new_tree)
3765         {
3766           cl_target_option_restore (TREE_TARGET_OPTION (new_tree));
3767           target_reinit ();
3768         }
3769
3770       else if (old_tree)
3771         {
3772           struct cl_target_option *def
3773             = TREE_TARGET_OPTION (target_option_current_node);
3774
3775           cl_target_option_restore (def);
3776           target_reinit ();
3777         }
3778     }
3779 }
3780
3781 \f
3782 /* Return true if this goes in large data/bss.  */
3783
3784 static bool
3785 ix86_in_large_data_p (tree exp)
3786 {
3787   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
3788     return false;
3789
3790   /* Functions are never large data.  */
3791   if (TREE_CODE (exp) == FUNCTION_DECL)
3792     return false;
3793
3794   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
3795     {
3796       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
3797       if (strcmp (section, ".ldata") == 0
3798           || strcmp (section, ".lbss") == 0)
3799         return true;
3800       return false;
3801     }
3802   else
3803     {
3804       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3805
3806       /* If this is an incomplete type with size 0, then we can't put it
3807          in data because it might be too big when completed.  */
3808       if (!size || size > ix86_section_threshold)
3809         return true;
3810     }
3811
3812   return false;
3813 }
3814
3815 /* Switch to the appropriate section for output of DECL.
3816    DECL is either a `VAR_DECL' node or a constant of some sort.
3817    RELOC indicates whether forming the initial value of DECL requires
3818    link-time relocations.  */
3819
3820 static section * x86_64_elf_select_section (tree, int, unsigned HOST_WIDE_INT)
3821         ATTRIBUTE_UNUSED;
3822
3823 static section *
3824 x86_64_elf_select_section (tree decl, int reloc,
3825                            unsigned HOST_WIDE_INT align)
3826 {
3827   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3828       && ix86_in_large_data_p (decl))
3829     {
3830       const char *sname = NULL;
3831       unsigned int flags = SECTION_WRITE;
3832       switch (categorize_decl_for_section (decl, reloc))
3833         {
3834         case SECCAT_DATA:
3835           sname = ".ldata";
3836           break;
3837         case SECCAT_DATA_REL:
3838           sname = ".ldata.rel";
3839           break;
3840         case SECCAT_DATA_REL_LOCAL:
3841           sname = ".ldata.rel.local";
3842           break;
3843         case SECCAT_DATA_REL_RO:
3844           sname = ".ldata.rel.ro";
3845           break;
3846         case SECCAT_DATA_REL_RO_LOCAL:
3847           sname = ".ldata.rel.ro.local";
3848           break;
3849         case SECCAT_BSS:
3850           sname = ".lbss";
3851           flags |= SECTION_BSS;
3852           break;
3853         case SECCAT_RODATA:
3854         case SECCAT_RODATA_MERGE_STR:
3855         case SECCAT_RODATA_MERGE_STR_INIT:
3856         case SECCAT_RODATA_MERGE_CONST:
3857           sname = ".lrodata";
3858           flags = 0;
3859           break;
3860         case SECCAT_SRODATA:
3861         case SECCAT_SDATA:
3862         case SECCAT_SBSS:
3863           gcc_unreachable ();
3864         case SECCAT_TEXT:
3865         case SECCAT_TDATA:
3866         case SECCAT_TBSS:
3867           /* We don't split these for medium model.  Place them into
3868              default sections and hope for best.  */
3869           break;
3870         case SECCAT_EMUTLS_VAR:
3871         case SECCAT_EMUTLS_TMPL:
3872           gcc_unreachable ();
3873         }
3874       if (sname)
3875         {
3876           /* We might get called with string constants, but get_named_section
3877              doesn't like them as they are not DECLs.  Also, we need to set
3878              flags in that case.  */
3879           if (!DECL_P (decl))
3880             return get_section (sname, flags, NULL);
3881           return get_named_section (decl, sname, reloc);
3882         }
3883     }
3884   return default_elf_select_section (decl, reloc, align);
3885 }
3886
3887 /* Build up a unique section name, expressed as a
3888    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
3889    RELOC indicates whether the initial value of EXP requires
3890    link-time relocations.  */
3891
3892 static void ATTRIBUTE_UNUSED
3893 x86_64_elf_unique_section (tree decl, int reloc)
3894 {
3895   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3896       && ix86_in_large_data_p (decl))
3897     {
3898       const char *prefix = NULL;
3899       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
3900       bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
3901
3902       switch (categorize_decl_for_section (decl, reloc))
3903         {
3904         case SECCAT_DATA:
3905         case SECCAT_DATA_REL:
3906         case SECCAT_DATA_REL_LOCAL:
3907         case SECCAT_DATA_REL_RO:
3908         case SECCAT_DATA_REL_RO_LOCAL:
3909           prefix = one_only ? ".ld" : ".ldata";
3910           break;
3911         case SECCAT_BSS:
3912           prefix = one_only ? ".lb" : ".lbss";
3913           break;
3914         case SECCAT_RODATA:
3915         case SECCAT_RODATA_MERGE_STR:
3916         case SECCAT_RODATA_MERGE_STR_INIT:
3917         case SECCAT_RODATA_MERGE_CONST:
3918           prefix = one_only ? ".lr" : ".lrodata";
3919           break;
3920         case SECCAT_SRODATA:
3921         case SECCAT_SDATA:
3922         case SECCAT_SBSS:
3923           gcc_unreachable ();
3924         case SECCAT_TEXT:
3925         case SECCAT_TDATA:
3926         case SECCAT_TBSS:
3927           /* We don't split these for medium model.  Place them into
3928              default sections and hope for best.  */
3929           break;
3930         case SECCAT_EMUTLS_VAR:
3931           prefix = targetm.emutls.var_section;
3932           break;
3933         case SECCAT_EMUTLS_TMPL:
3934           prefix = targetm.emutls.tmpl_section;
3935           break;
3936         }
3937       if (prefix)
3938         {
3939           const char *name, *linkonce;
3940           char *string;
3941
3942           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
3943           name = targetm.strip_name_encoding (name);
3944           
3945           /* If we're using one_only, then there needs to be a .gnu.linkonce
3946              prefix to the section name.  */
3947           linkonce = one_only ? ".gnu.linkonce" : "";
3948   
3949           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
3950           
3951           DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
3952           return;
3953         }
3954     }
3955   default_unique_section (decl, reloc);
3956 }
3957
3958 #ifdef COMMON_ASM_OP
3959 /* This says how to output assembler code to declare an
3960    uninitialized external linkage data object.
3961
3962    For medium model x86-64 we need to use .largecomm opcode for
3963    large objects.  */
3964 void
3965 x86_elf_aligned_common (FILE *file,
3966                         const char *name, unsigned HOST_WIDE_INT size,
3967                         int align)
3968 {
3969   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3970       && size > (unsigned int)ix86_section_threshold)
3971     fprintf (file, ".largecomm\t");
3972   else
3973     fprintf (file, "%s", COMMON_ASM_OP);
3974   assemble_name (file, name);
3975   fprintf (file, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",
3976            size, align / BITS_PER_UNIT);
3977 }
3978 #endif
3979
3980 /* Utility function for targets to use in implementing
3981    ASM_OUTPUT_ALIGNED_BSS.  */
3982
3983 void
3984 x86_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
3985                         const char *name, unsigned HOST_WIDE_INT size,
3986                         int align)
3987 {
3988   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3989       && size > (unsigned int)ix86_section_threshold)
3990     switch_to_section (get_named_section (decl, ".lbss", 0));
3991   else
3992     switch_to_section (bss_section);
3993   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
3994 #ifdef ASM_DECLARE_OBJECT_NAME
3995   last_assemble_variable_decl = decl;
3996   ASM_DECLARE_OBJECT_NAME (file, name, decl);
3997 #else
3998   /* Standard thing is just output label for the object.  */
3999   ASM_OUTPUT_LABEL (file, name);
4000 #endif /* ASM_DECLARE_OBJECT_NAME */
4001   ASM_OUTPUT_SKIP (file, size ? size : 1);
4002 }
4003 \f
4004 void
4005 optimization_options (int level, int size ATTRIBUTE_UNUSED)
4006 {
4007   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
4008      make the problem with not enough registers even worse.  */
4009 #ifdef INSN_SCHEDULING
4010   if (level > 1)
4011     flag_schedule_insns = 0;
4012 #endif
4013
4014   if (TARGET_MACHO)
4015     /* The Darwin libraries never set errno, so we might as well
4016        avoid calling them when that's the only reason we would.  */
4017     flag_errno_math = 0;
4018
4019   /* The default values of these switches depend on the TARGET_64BIT
4020      that is not known at this moment.  Mark these values with 2 and
4021      let user the to override these.  In case there is no command line option
4022      specifying them, we will set the defaults in override_options.  */
4023   if (optimize >= 1)
4024     flag_omit_frame_pointer = 2;
4025   flag_pcc_struct_return = 2;
4026   flag_asynchronous_unwind_tables = 2;
4027   flag_vect_cost_model = 1;
4028 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
4029   SUBTARGET_OPTIMIZATION_OPTIONS;
4030 #endif
4031 }
4032 \f
4033 /* Decide whether we can make a sibling call to a function.  DECL is the
4034    declaration of the function being targeted by the call and EXP is the
4035    CALL_EXPR representing the call.  */
4036
4037 static bool
4038 ix86_function_ok_for_sibcall (tree decl, tree exp)
4039 {
4040   tree func;
4041   rtx a, b;
4042
4043   /* If we are generating position-independent code, we cannot sibcall
4044      optimize any indirect call, or a direct call to a global function,
4045      as the PLT requires %ebx be live.  */
4046   if (!TARGET_64BIT && flag_pic && (!decl || !targetm.binds_local_p (decl)))
4047     return false;
4048
4049   if (decl)
4050     func = decl;
4051   else
4052     {
4053       func = TREE_TYPE (CALL_EXPR_FN (exp));
4054       if (POINTER_TYPE_P (func))
4055         func = TREE_TYPE (func);
4056     }
4057
4058   /* Check that the return value locations are the same.  Like
4059      if we are returning floats on the 80387 register stack, we cannot
4060      make a sibcall from a function that doesn't return a float to a
4061      function that does or, conversely, from a function that does return
4062      a float to a function that doesn't; the necessary stack adjustment
4063      would not be executed.  This is also the place we notice
4064      differences in the return value ABI.  Note that it is ok for one
4065      of the functions to have void return type as long as the return
4066      value of the other is passed in a register.  */
4067   a = ix86_function_value (TREE_TYPE (exp), func, false);
4068   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
4069                            cfun->decl, false);
4070   if (STACK_REG_P (a) || STACK_REG_P (b))
4071     {
4072       if (!rtx_equal_p (a, b))
4073         return false;
4074     }
4075   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
4076     ;
4077   else if (!rtx_equal_p (a, b))
4078     return false;
4079
4080   /* If this call is indirect, we'll need to be able to use a call-clobbered
4081      register for the address of the target function.  Make sure that all
4082      such registers are not used for passing parameters.  */
4083   if (!decl && !TARGET_64BIT)
4084     {
4085       tree type;
4086
4087       /* We're looking at the CALL_EXPR, we need the type of the function.  */
4088       type = CALL_EXPR_FN (exp);                /* pointer expression */
4089       type = TREE_TYPE (type);                  /* pointer type */
4090       type = TREE_TYPE (type);                  /* function type */
4091
4092       if (ix86_function_regparm (type, NULL) >= 3)
4093         {
4094           /* ??? Need to count the actual number of registers to be used,
4095              not the possible number of registers.  Fix later.  */
4096           return false;
4097         }
4098     }
4099
4100   /* Dllimport'd functions are also called indirectly.  */
4101   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
4102       && decl && DECL_DLLIMPORT_P (decl)
4103       && ix86_function_regparm (TREE_TYPE (decl), NULL) >= 3)
4104     return false;
4105
4106   /* Otherwise okay.  That also includes certain types of indirect calls.  */
4107   return true;
4108 }
4109
4110 /* Handle "cdecl", "stdcall", "fastcall", "regparm" and "sseregparm"
4111    calling convention attributes;
4112    arguments as in struct attribute_spec.handler.  */
4113
4114 static tree
4115 ix86_handle_cconv_attribute (tree *node, tree name,
4116                                    tree args,
4117                                    int flags ATTRIBUTE_UNUSED,
4118                                    bool *no_add_attrs)
4119 {
4120   if (TREE_CODE (*node) != FUNCTION_TYPE
4121       && TREE_CODE (*node) != METHOD_TYPE
4122       && TREE_CODE (*node) != FIELD_DECL
4123       && TREE_CODE (*node) != TYPE_DECL)
4124     {
4125       warning (OPT_Wattributes, "%qs attribute only applies to functions",
4126                IDENTIFIER_POINTER (name));
4127       *no_add_attrs = true;
4128       return NULL_TREE;
4129     }
4130
4131   /* Can combine regparm with all attributes but fastcall.  */
4132   if (is_attribute_p ("regparm", name))
4133     {
4134       tree cst;
4135
4136       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4137         {
4138           error ("fastcall and regparm attributes are not compatible");
4139         }
4140
4141       cst = TREE_VALUE (args);
4142       if (TREE_CODE (cst) != INTEGER_CST)
4143         {
4144           warning (OPT_Wattributes,
4145                    "%qs attribute requires an integer constant argument",
4146                    IDENTIFIER_POINTER (name));
4147           *no_add_attrs = true;
4148         }
4149       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
4150         {
4151           warning (OPT_Wattributes, "argument to %qs attribute larger than %d",
4152                    IDENTIFIER_POINTER (name), REGPARM_MAX);
4153           *no_add_attrs = true;
4154         }
4155
4156       return NULL_TREE;
4157     }
4158
4159   if (TARGET_64BIT)
4160     {
4161       /* Do not warn when emulating the MS ABI.  */
4162       if (TREE_CODE (*node) != FUNCTION_TYPE || ix86_function_type_abi (*node)!=MS_ABI)
4163         warning (OPT_Wattributes, "%qs attribute ignored",
4164                  IDENTIFIER_POINTER (name));
4165       *no_add_attrs = true;
4166       return NULL_TREE;
4167     }
4168
4169   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
4170   if (is_attribute_p ("fastcall", name))
4171     {
4172       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4173         {
4174           error ("fastcall and cdecl attributes are not compatible");
4175         }
4176       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4177         {
4178           error ("fastcall and stdcall attributes are not compatible");
4179         }
4180       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
4181         {
4182           error ("fastcall and regparm attributes are not compatible");
4183         }
4184     }
4185
4186   /* Can combine stdcall with fastcall (redundant), regparm and
4187      sseregparm.  */
4188   else if (is_attribute_p ("stdcall", name))
4189     {
4190       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4191         {
4192           error ("stdcall and cdecl attributes are not compatible");
4193         }
4194       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4195         {
4196           error ("stdcall and fastcall attributes are not compatible");
4197         }
4198     }
4199
4200   /* Can combine cdecl with regparm and sseregparm.  */
4201   else if (is_attribute_p ("cdecl", name))
4202     {
4203       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4204         {
4205           error ("stdcall and cdecl attributes are not compatible");
4206         }
4207       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4208         {
4209           error ("fastcall and cdecl attributes are not compatible");
4210         }
4211     }
4212
4213   /* Can combine sseregparm with all attributes.  */
4214
4215   return NULL_TREE;
4216 }
4217
4218 /* Return 0 if the attributes for two types are incompatible, 1 if they
4219    are compatible, and 2 if they are nearly compatible (which causes a
4220    warning to be generated).  */
4221
4222 static int
4223 ix86_comp_type_attributes (const_tree type1, const_tree type2)
4224 {
4225   /* Check for mismatch of non-default calling convention.  */
4226   const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
4227
4228   if (TREE_CODE (type1) != FUNCTION_TYPE
4229       && TREE_CODE (type1) != METHOD_TYPE)
4230     return 1;
4231
4232   /* Check for mismatched fastcall/regparm types.  */
4233   if ((!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
4234        != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
4235       || (ix86_function_regparm (type1, NULL)
4236           != ix86_function_regparm (type2, NULL)))
4237     return 0;
4238
4239   /* Check for mismatched sseregparm types.  */
4240   if (!lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type1))
4241       != !lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type2)))
4242     return 0;
4243
4244   /* Check for mismatched return types (cdecl vs stdcall).  */
4245   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
4246       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
4247     return 0;
4248
4249   return 1;
4250 }
4251 \f
4252 /* Return the regparm value for a function with the indicated TYPE and DECL.
4253    DECL may be NULL when calling function indirectly
4254    or considering a libcall.  */
4255
4256 static int
4257 ix86_function_regparm (const_tree type, const_tree decl)
4258 {
4259   tree attr;
4260   int regparm = ix86_regparm;
4261
4262   static bool error_issued;
4263
4264   if (TARGET_64BIT)
4265     {
4266       if (ix86_function_type_abi (type) == DEFAULT_ABI)
4267         return regparm;
4268       return DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
4269     }
4270
4271   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
4272   if (attr)
4273     {
4274       regparm
4275         = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
4276
4277       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4278         {
4279           /* We can't use regparm(3) for nested functions because
4280              these pass static chain pointer in %ecx register.  */
4281           if (!error_issued && regparm == 3
4282               && decl_function_context (decl)
4283               && !DECL_NO_STATIC_CHAIN (decl))
4284             {
4285               error ("nested functions are limited to 2 register parameters");
4286               error_issued = true;
4287               return 0;
4288             }
4289         }
4290
4291       return regparm;
4292     }
4293
4294   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4295     return 2;
4296
4297   /* Use register calling convention for local functions when possible.  */
4298   if (decl && TREE_CODE (decl) == FUNCTION_DECL
4299       && !profile_flag)
4300     {
4301       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4302       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4303       if (i && i->local)
4304         {
4305           int local_regparm, globals = 0, regno;
4306           struct function *f;
4307
4308           /* Make sure no regparm register is taken by a
4309              fixed register variable.  */
4310           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4311             if (fixed_regs[local_regparm])
4312               break;
4313
4314           /* We can't use regparm(3) for nested functions as these use
4315              static chain pointer in third argument.  */
4316           if (local_regparm == 3
4317               && decl_function_context (decl)
4318               && !DECL_NO_STATIC_CHAIN (decl))
4319             local_regparm = 2;
4320
4321           /* If the function realigns its stackpointer, the prologue will
4322              clobber %ecx.  If we've already generated code for the callee,
4323              the callee DECL_STRUCT_FUNCTION is gone, so we fall back to
4324              scanning the attributes for the self-realigning property.  */
4325           f = DECL_STRUCT_FUNCTION (decl);
4326           /* Since current internal arg pointer won't conflict with
4327              parameter passing regs, so no need to change stack
4328              realignment and adjust regparm number.
4329
4330              Each fixed register usage increases register pressure,
4331              so less registers should be used for argument passing.
4332              This functionality can be overriden by an explicit
4333              regparm value.  */
4334           for (regno = 0; regno <= DI_REG; regno++)
4335             if (fixed_regs[regno])
4336               globals++;
4337
4338           local_regparm
4339             = globals < local_regparm ? local_regparm - globals : 0;
4340
4341           if (local_regparm > regparm)
4342             regparm = local_regparm;
4343         }
4344     }
4345
4346   return regparm;
4347 }
4348
4349 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
4350    DFmode (2) arguments in SSE registers for a function with the
4351    indicated TYPE and DECL.  DECL may be NULL when calling function
4352    indirectly or considering a libcall.  Otherwise return 0.  */
4353
4354 static int
4355 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
4356 {
4357   gcc_assert (!TARGET_64BIT);
4358
4359   /* Use SSE registers to pass SFmode and DFmode arguments if requested
4360      by the sseregparm attribute.  */
4361   if (TARGET_SSEREGPARM
4362       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
4363     {
4364       if (!TARGET_SSE)
4365         {
4366           if (warn)
4367             {
4368               if (decl)
4369                 error ("Calling %qD with attribute sseregparm without "
4370                        "SSE/SSE2 enabled", decl);
4371               else
4372                 error ("Calling %qT with attribute sseregparm without "
4373                        "SSE/SSE2 enabled", type);
4374             }
4375           return 0;
4376         }
4377
4378       return 2;
4379     }
4380
4381   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4382      (and DFmode for SSE2) arguments in SSE registers.  */
4383   if (decl && TARGET_SSE_MATH && !profile_flag)
4384     {
4385       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4386       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4387       if (i && i->local)
4388         return TARGET_SSE2 ? 2 : 1;
4389     }
4390
4391   return 0;
4392 }
4393
4394 /* Return true if EAX is live at the start of the function.  Used by
4395    ix86_expand_prologue to determine if we need special help before
4396    calling allocate_stack_worker.  */
4397
4398 static bool
4399 ix86_eax_live_at_start_p (void)
4400 {
4401   /* Cheat.  Don't bother working forward from ix86_function_regparm
4402      to the function type to whether an actual argument is located in
4403      eax.  Instead just look at cfg info, which is still close enough
4404      to correct at this point.  This gives false positives for broken
4405      functions that might use uninitialized data that happens to be
4406      allocated in eax, but who cares?  */
4407   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR), 0);
4408 }
4409
4410 /* Value is the number of bytes of arguments automatically
4411    popped when returning from a subroutine call.
4412    FUNDECL is the declaration node of the function (as a tree),
4413    FUNTYPE is the data type of the function (as a tree),
4414    or for a library call it is an identifier node for the subroutine name.
4415    SIZE is the number of bytes of arguments passed on the stack.
4416
4417    On the 80386, the RTD insn may be used to pop them if the number
4418      of args is fixed, but if the number is variable then the caller
4419      must pop them all.  RTD can't be used for library calls now
4420      because the library is compiled with the Unix compiler.
4421    Use of RTD is a selectable option, since it is incompatible with
4422    standard Unix calling sequences.  If the option is not selected,
4423    the caller must always pop the args.
4424
4425    The attribute stdcall is equivalent to RTD on a per module basis.  */
4426
4427 int
4428 ix86_return_pops_args (tree fundecl, tree funtype, int size)
4429 {
4430   int rtd;
4431
4432   /* None of the 64-bit ABIs pop arguments.  */
4433   if (TARGET_64BIT)
4434     return 0;
4435
4436   rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
4437
4438   /* Cdecl functions override -mrtd, and never pop the stack.  */
4439   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
4440     {
4441       /* Stdcall and fastcall functions will pop the stack if not
4442          variable args.  */
4443       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
4444           || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
4445         rtd = 1;
4446
4447       if (rtd && ! stdarg_p (funtype))
4448         return size;
4449     }
4450
4451   /* Lose any fake structure return argument if it is passed on the stack.  */
4452   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
4453       && !KEEP_AGGREGATE_RETURN_POINTER)
4454     {
4455       int nregs = ix86_function_regparm (funtype, fundecl);
4456       if (nregs == 0)
4457         return GET_MODE_SIZE (Pmode);
4458     }
4459
4460   return 0;
4461 }
4462 \f
4463 /* Argument support functions.  */
4464
4465 /* Return true when register may be used to pass function parameters.  */
4466 bool
4467 ix86_function_arg_regno_p (int regno)
4468 {
4469   int i;
4470   const int *parm_regs;
4471
4472   if (!TARGET_64BIT)
4473     {
4474       if (TARGET_MACHO)
4475         return (regno < REGPARM_MAX
4476                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
4477       else
4478         return (regno < REGPARM_MAX
4479                 || (TARGET_MMX && MMX_REGNO_P (regno)
4480                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
4481                 || (TARGET_SSE && SSE_REGNO_P (regno)
4482                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
4483     }
4484
4485   if (TARGET_MACHO)
4486     {
4487       if (SSE_REGNO_P (regno) && TARGET_SSE)
4488         return true;
4489     }
4490   else
4491     {
4492       if (TARGET_SSE && SSE_REGNO_P (regno)
4493           && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
4494         return true;
4495     }
4496
4497   /* TODO: The function should depend on current function ABI but
4498      builtins.c would need updating then. Therefore we use the
4499      default ABI.  */
4500
4501   /* RAX is used as hidden argument to va_arg functions.  */
4502   if (DEFAULT_ABI == SYSV_ABI && regno == AX_REG)
4503     return true;
4504
4505   if (DEFAULT_ABI == MS_ABI)
4506     parm_regs = x86_64_ms_abi_int_parameter_registers;
4507   else
4508     parm_regs = x86_64_int_parameter_registers;
4509   for (i = 0; i < (DEFAULT_ABI == MS_ABI ? X64_REGPARM_MAX
4510                                          : X86_64_REGPARM_MAX); i++)
4511     if (regno == parm_regs[i])
4512       return true;
4513   return false;
4514 }
4515
4516 /* Return if we do not know how to pass TYPE solely in registers.  */
4517
4518 static bool
4519 ix86_must_pass_in_stack (enum machine_mode mode, const_tree type)
4520 {
4521   if (must_pass_in_stack_var_size_or_pad (mode, type))
4522     return true;
4523
4524   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
4525      The layout_type routine is crafty and tries to trick us into passing
4526      currently unsupported vector types on the stack by using TImode.  */
4527   return (!TARGET_64BIT && mode == TImode
4528           && type && TREE_CODE (type) != VECTOR_TYPE);
4529 }
4530
4531 /* It returns the size, in bytes, of the area reserved for arguments passed
4532    in registers for the function represented by fndecl dependent to the used
4533    abi format.  */
4534 int
4535 ix86_reg_parm_stack_space (const_tree fndecl)
4536 {
4537   int call_abi = 0;
4538   /* For libcalls it is possible that there is no fndecl at hand.
4539      Therefore assume for this case the default abi of the target.  */
4540   if (!fndecl)
4541     call_abi = DEFAULT_ABI;
4542   else
4543     call_abi = ix86_function_abi (fndecl);
4544   if (call_abi == 1)
4545     return 32;
4546   return 0;
4547 }
4548
4549 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
4550    call abi used.  */
4551 int
4552 ix86_function_type_abi (const_tree fntype)
4553 {
4554   if (TARGET_64BIT && fntype != NULL)
4555     {
4556       int abi;
4557       if (DEFAULT_ABI == SYSV_ABI)
4558         abi = lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)) ? MS_ABI : SYSV_ABI;
4559       else
4560         abi = lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)) ? SYSV_ABI : MS_ABI;
4561
4562       return abi;
4563     }
4564   return DEFAULT_ABI;
4565 }
4566
4567 int
4568 ix86_function_abi (const_tree fndecl)
4569 {
4570   if (! fndecl)
4571     return DEFAULT_ABI;
4572   return ix86_function_type_abi (TREE_TYPE (fndecl));
4573 }
4574
4575 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
4576    call abi used.  */
4577 int
4578 ix86_cfun_abi (void)
4579 {
4580   if (! cfun || ! TARGET_64BIT)
4581     return DEFAULT_ABI;
4582   return cfun->machine->call_abi;
4583 }
4584
4585 /* regclass.c  */
4586 extern void init_regs (void);
4587
4588 /* Implementation of call abi switching target hook. Specific to FNDECL
4589    the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
4590    for more details.
4591    To prevent redudant calls of costy function init_regs (), it checks not to
4592    reset register usage for default abi.  */
4593 void
4594 ix86_call_abi_override (const_tree fndecl)
4595 {
4596   if (fndecl == NULL_TREE)
4597     cfun->machine->call_abi = DEFAULT_ABI;
4598   else
4599     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
4600   if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
4601     {
4602       if (call_used_regs[4 /*RSI*/] != 0 || call_used_regs[5 /*RDI*/] != 0)
4603         {
4604           call_used_regs[4 /*RSI*/] = 0;
4605           call_used_regs[5 /*RDI*/] = 0;
4606           init_regs ();
4607         }
4608     }
4609   else if (TARGET_64BIT)
4610     {
4611       if (call_used_regs[4 /*RSI*/] != 1 || call_used_regs[5 /*RDI*/] != 1)
4612         {
4613           call_used_regs[4 /*RSI*/] = 1;
4614           call_used_regs[5 /*RDI*/] = 1;
4615           init_regs ();
4616         }
4617     }
4618 }
4619
4620 /* Initialize a variable CUM of type CUMULATIVE_ARGS
4621    for a call to a function whose data type is FNTYPE.
4622    For a library call, FNTYPE is 0.  */
4623
4624 void
4625 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
4626                       tree fntype,      /* tree ptr for function decl */
4627                       rtx libname,      /* SYMBOL_REF of library name or 0 */
4628                       tree fndecl)
4629 {
4630   struct cgraph_local_info *i = fndecl ? cgraph_local_info (fndecl) : NULL;
4631   memset (cum, 0, sizeof (*cum));
4632
4633   cum->call_abi = ix86_function_type_abi (fntype);
4634   /* Set up the number of registers to use for passing arguments.  */
4635   cum->nregs = ix86_regparm;
4636   if (TARGET_64BIT)
4637     {
4638       if (cum->call_abi != DEFAULT_ABI)
4639         cum->nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX
4640                                              : X64_REGPARM_MAX;
4641     }
4642   if (TARGET_SSE)
4643     {
4644       cum->sse_nregs = SSE_REGPARM_MAX;
4645       if (TARGET_64BIT)
4646         {
4647           if (cum->call_abi != DEFAULT_ABI)
4648             cum->sse_nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
4649                                                      : X64_SSE_REGPARM_MAX;
4650         }
4651     }
4652   if (TARGET_MMX)
4653     cum->mmx_nregs = MMX_REGPARM_MAX;
4654   cum->warn_avx = true;
4655   cum->warn_sse = true;
4656   cum->warn_mmx = true;
4657
4658   /* Because type might mismatch in between caller and callee, we need to
4659      use actual type of function for local calls.
4660      FIXME: cgraph_analyze can be told to actually record if function uses
4661      va_start so for local functions maybe_vaarg can be made aggressive
4662      helping K&R code.
4663      FIXME: once typesytem is fixed, we won't need this code anymore.  */
4664   if (i && i->local)
4665     fntype = TREE_TYPE (fndecl);
4666   cum->maybe_vaarg = (fntype
4667                       ? (!prototype_p (fntype) || stdarg_p (fntype))
4668                       : !libname);
4669
4670   if (!TARGET_64BIT)
4671     {
4672       /* If there are variable arguments, then we won't pass anything
4673          in registers in 32-bit mode. */
4674       if (stdarg_p (fntype))
4675         {
4676           cum->nregs = 0;
4677           cum->sse_nregs = 0;
4678           cum->mmx_nregs = 0;
4679           cum->warn_avx = 0;
4680           cum->warn_sse = 0;
4681           cum->warn_mmx = 0;
4682           return;
4683         }
4684
4685       /* Use ecx and edx registers if function has fastcall attribute,
4686          else look for regparm information.  */
4687       if (fntype)
4688         {
4689           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
4690             {
4691               cum->nregs = 2;
4692               cum->fastcall = 1;
4693             }
4694           else
4695             cum->nregs = ix86_function_regparm (fntype, fndecl);
4696         }
4697
4698       /* Set up the number of SSE registers used for passing SFmode
4699          and DFmode arguments.  Warn for mismatching ABI.  */
4700       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
4701     }
4702 }
4703
4704 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
4705    But in the case of vector types, it is some vector mode.
4706
4707    When we have only some of our vector isa extensions enabled, then there
4708    are some modes for which vector_mode_supported_p is false.  For these
4709    modes, the generic vector support in gcc will choose some non-vector mode
4710    in order to implement the type.  By computing the natural mode, we'll
4711    select the proper ABI location for the operand and not depend on whatever
4712    the middle-end decides to do with these vector types.  */
4713
4714 static enum machine_mode
4715 type_natural_mode (const_tree type)
4716 {
4717   enum machine_mode mode = TYPE_MODE (type);
4718
4719   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
4720     {
4721       HOST_WIDE_INT size = int_size_in_bytes (type);
4722       if ((size == 8 || size == 16)
4723           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
4724           && TYPE_VECTOR_SUBPARTS (type) > 1)
4725         {
4726           enum machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
4727
4728           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4729             mode = MIN_MODE_VECTOR_FLOAT;
4730           else
4731             mode = MIN_MODE_VECTOR_INT;
4732
4733           /* Get the mode which has this inner mode and number of units.  */
4734           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
4735             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
4736                 && GET_MODE_INNER (mode) == innermode)
4737               return mode;
4738
4739           gcc_unreachable ();
4740         }
4741     }
4742
4743   return mode;
4744 }
4745
4746 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
4747    this may not agree with the mode that the type system has chosen for the
4748    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
4749    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
4750
4751 static rtx
4752 gen_reg_or_parallel (enum machine_mode mode, enum machine_mode orig_mode,
4753                      unsigned int regno)
4754 {
4755   rtx tmp;
4756
4757   if (orig_mode != BLKmode)
4758     tmp = gen_rtx_REG (orig_mode, regno);
4759   else
4760     {
4761       tmp = gen_rtx_REG (mode, regno);
4762       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
4763       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
4764     }
4765
4766   return tmp;
4767 }
4768
4769 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
4770    of this code is to classify each 8bytes of incoming argument by the register
4771    class and assign registers accordingly.  */
4772
4773 /* Return the union class of CLASS1 and CLASS2.
4774    See the x86-64 PS ABI for details.  */
4775
4776 static enum x86_64_reg_class
4777 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
4778 {
4779   /* Rule #1: If both classes are equal, this is the resulting class.  */
4780   if (class1 == class2)
4781     return class1;
4782
4783   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
4784      the other class.  */
4785   if (class1 == X86_64_NO_CLASS)
4786     return class2;
4787   if (class2 == X86_64_NO_CLASS)
4788     return class1;
4789
4790   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
4791   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
4792     return X86_64_MEMORY_CLASS;
4793
4794   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
4795   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
4796       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
4797     return X86_64_INTEGERSI_CLASS;
4798   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
4799       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
4800     return X86_64_INTEGER_CLASS;
4801
4802   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
4803      MEMORY is used.  */
4804   if (class1 == X86_64_X87_CLASS
4805       || class1 == X86_64_X87UP_CLASS
4806       || class1 == X86_64_COMPLEX_X87_CLASS
4807       || class2 == X86_64_X87_CLASS
4808       || class2 == X86_64_X87UP_CLASS
4809       || class2 == X86_64_COMPLEX_X87_CLASS)
4810     return X86_64_MEMORY_CLASS;
4811
4812   /* Rule #6: Otherwise class SSE is used.  */
4813   return X86_64_SSE_CLASS;
4814 }
4815
4816 /* Classify the argument of type TYPE and mode MODE.
4817    CLASSES will be filled by the register class used to pass each word
4818    of the operand.  The number of words is returned.  In case the parameter
4819    should be passed in memory, 0 is returned. As a special case for zero
4820    sized containers, classes[0] will be NO_CLASS and 1 is returned.
4821
4822    BIT_OFFSET is used internally for handling records and specifies offset
4823    of the offset in bits modulo 256 to avoid overflow cases.
4824
4825    See the x86-64 PS ABI for details.
4826 */
4827
4828 static int
4829 classify_argument (enum machine_mode mode, const_tree type,
4830                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
4831 {
4832   HOST_WIDE_INT bytes =
4833     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
4834   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4835
4836   /* Variable sized entities are always passed/returned in memory.  */
4837   if (bytes < 0)
4838     return 0;
4839
4840   if (mode != VOIDmode
4841       && targetm.calls.must_pass_in_stack (mode, type))
4842     return 0;
4843
4844   if (type && AGGREGATE_TYPE_P (type))
4845     {
4846       int i;
4847       tree field;
4848       enum x86_64_reg_class subclasses[MAX_CLASSES];
4849
4850       /* On x86-64 we pass structures larger than 16 bytes on the stack.  */
4851       if (bytes > 16)
4852         return 0;
4853
4854       for (i = 0; i < words; i++)
4855         classes[i] = X86_64_NO_CLASS;
4856
4857       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
4858          signalize memory class, so handle it as special case.  */
4859       if (!words)
4860         {
4861           classes[0] = X86_64_NO_CLASS;
4862           return 1;
4863         }
4864
4865       /* Classify each field of record and merge classes.  */
4866       switch (TREE_CODE (type))
4867         {
4868         case RECORD_TYPE:
4869           /* And now merge the fields of structure.  */
4870           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4871             {
4872               if (TREE_CODE (field) == FIELD_DECL)
4873                 {
4874                   int num;
4875
4876                   if (TREE_TYPE (field) == error_mark_node)
4877                     continue;
4878
4879                   /* Bitfields are always classified as integer.  Handle them
4880                      early, since later code would consider them to be
4881                      misaligned integers.  */
4882                   if (DECL_BIT_FIELD (field))
4883                     {
4884                       for (i = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4885                            i < ((int_bit_position (field) + (bit_offset % 64))
4886                                 + tree_low_cst (DECL_SIZE (field), 0)
4887                                 + 63) / 8 / 8; i++)
4888                         classes[i] =
4889                           merge_classes (X86_64_INTEGER_CLASS,
4890                                          classes[i]);
4891                     }
4892                   else
4893                     {
4894                       num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4895                                                TREE_TYPE (field), subclasses,
4896                                                (int_bit_position (field)
4897                                                 + bit_offset) % 256);
4898                       if (!num)
4899                         return 0;
4900                       for (i = 0; i < num; i++)
4901                         {
4902                           int pos =
4903                             (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4904                           classes[i + pos] =
4905                             merge_classes (subclasses[i], classes[i + pos]);
4906                         }
4907                     }
4908                 }
4909             }
4910           break;
4911
4912         case ARRAY_TYPE:
4913           /* Arrays are handled as small records.  */
4914           {
4915             int num;
4916             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
4917                                      TREE_TYPE (type), subclasses, bit_offset);
4918             if (!num)
4919               return 0;
4920
4921             /* The partial classes are now full classes.  */
4922             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
4923               subclasses[0] = X86_64_SSE_CLASS;
4924             if (subclasses[0] == X86_64_INTEGERSI_CLASS && bytes != 4)
4925               subclasses[0] = X86_64_INTEGER_CLASS;
4926
4927             for (i = 0; i < words; i++)
4928               classes[i] = subclasses[i % num];
4929
4930             break;
4931           }
4932         case UNION_TYPE:
4933         case QUAL_UNION_TYPE:
4934           /* Unions are similar to RECORD_TYPE but offset is always 0.
4935              */
4936           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4937             {
4938               if (TREE_CODE (field) == FIELD_DECL)
4939                 {
4940                   int num;
4941
4942                   if (TREE_TYPE (field) == error_mark_node)
4943                     continue;
4944
4945                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4946                                            TREE_TYPE (field), subclasses,
4947                                            bit_offset);
4948                   if (!num)
4949                     return 0;
4950                   for (i = 0; i < num; i++)
4951                     classes[i] = merge_classes (subclasses[i], classes[i]);
4952                 }
4953             }
4954           break;
4955
4956         default:
4957           gcc_unreachable ();
4958         }
4959
4960       /* Final merger cleanup.  */
4961       for (i = 0; i < words; i++)
4962         {
4963           /* If one class is MEMORY, everything should be passed in
4964              memory.  */
4965           if (classes[i] == X86_64_MEMORY_CLASS)
4966             return 0;
4967
4968           /* The X86_64_SSEUP_CLASS should be always preceded by
4969              X86_64_SSE_CLASS.  */
4970           if (classes[i] == X86_64_SSEUP_CLASS
4971               && (i == 0 || classes[i - 1] != X86_64_SSE_CLASS))
4972             classes[i] = X86_64_SSE_CLASS;
4973
4974           /*  X86_64_X87UP_CLASS should be preceded by X86_64_X87_CLASS.  */
4975           if (classes[i] == X86_64_X87UP_CLASS
4976               && (i == 0 || classes[i - 1] != X86_64_X87_CLASS))
4977             classes[i] = X86_64_SSE_CLASS;
4978         }
4979       return words;
4980     }
4981
4982   /* Compute alignment needed.  We align all types to natural boundaries with
4983      exception of XFmode that is aligned to 64bits.  */
4984   if (mode != VOIDmode && mode != BLKmode)
4985     {
4986       int mode_alignment = GET_MODE_BITSIZE (mode);
4987
4988       if (mode == XFmode)
4989         mode_alignment = 128;
4990       else if (mode == XCmode)
4991         mode_alignment = 256;
4992       if (COMPLEX_MODE_P (mode))
4993         mode_alignment /= 2;
4994       /* Misaligned fields are always returned in memory.  */
4995       if (bit_offset % mode_alignment)
4996         return 0;
4997     }
4998
4999   /* for V1xx modes, just use the base mode */
5000   if (VECTOR_MODE_P (mode) && mode != V1DImode
5001       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
5002     mode = GET_MODE_INNER (mode);
5003
5004   /* Classification of atomic types.  */
5005   switch (mode)
5006     {
5007     case SDmode:
5008     case DDmode:
5009       classes[0] = X86_64_SSE_CLASS;
5010       return 1;
5011     case TDmode:
5012       classes[0] = X86_64_SSE_CLASS;
5013       classes[1] = X86_64_SSEUP_CLASS;
5014       return 2;
5015     case DImode:
5016     case SImode:
5017     case HImode:
5018     case QImode:
5019     case CSImode:
5020     case CHImode:
5021     case CQImode:
5022       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5023         classes[0] = X86_64_INTEGERSI_CLASS;
5024       else
5025         classes[0] = X86_64_INTEGER_CLASS;
5026       return 1;
5027     case CDImode:
5028     case TImode:
5029       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5030       return 2;
5031     case CTImode:
5032     case COImode:
5033     case OImode:
5034       return 0;
5035     case SFmode:
5036       if (!(bit_offset % 64))
5037         classes[0] = X86_64_SSESF_CLASS;
5038       else
5039         classes[0] = X86_64_SSE_CLASS;
5040       return 1;
5041     case DFmode:
5042       classes[0] = X86_64_SSEDF_CLASS;
5043       return 1;
5044     case XFmode:
5045       classes[0] = X86_64_X87_CLASS;
5046       classes[1] = X86_64_X87UP_CLASS;
5047       return 2;
5048     case TFmode:
5049       classes[0] = X86_64_SSE_CLASS;
5050       classes[1] = X86_64_SSEUP_CLASS;
5051       return 2;
5052     case SCmode:
5053       classes[0] = X86_64_SSE_CLASS;
5054       return 1;
5055     case DCmode:
5056       classes[0] = X86_64_SSEDF_CLASS;
5057       classes[1] = X86_64_SSEDF_CLASS;
5058       return 2;
5059     case XCmode:
5060       classes[0] = X86_64_COMPLEX_X87_CLASS;
5061       return 1;
5062     case TCmode:
5063       /* This modes is larger than 16 bytes.  */
5064       return 0;
5065     case V8SFmode:
5066     case V8SImode:
5067     case V32QImode:
5068     case V16HImode:
5069     case V4DFmode:
5070     case V4DImode:
5071       classes[0] = X86_64_AVX_CLASS;
5072       return 1;
5073     case V4SFmode:
5074     case V4SImode:
5075     case V16QImode:
5076     case V8HImode:
5077     case V2DFmode:
5078     case V2DImode:
5079       classes[0] = X86_64_SSE_CLASS;
5080       classes[1] = X86_64_SSEUP_CLASS;
5081       return 2;
5082     case V1DImode:
5083     case V2SFmode:
5084     case V2SImode:
5085     case V4HImode:
5086     case V8QImode:
5087       classes[0] = X86_64_SSE_CLASS;
5088       return 1;
5089     case BLKmode:
5090     case VOIDmode:
5091       return 0;
5092     default:
5093       gcc_assert (VECTOR_MODE_P (mode));
5094
5095       if (bytes > 16)
5096         return 0;
5097
5098       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
5099
5100       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5101         classes[0] = X86_64_INTEGERSI_CLASS;
5102       else
5103         classes[0] = X86_64_INTEGER_CLASS;
5104       classes[1] = X86_64_INTEGER_CLASS;
5105       return 1 + (bytes > 8);
5106     }
5107 }
5108
5109 /* Examine the argument and return set number of register required in each
5110    class.  Return 0 iff parameter should be passed in memory.  */
5111 static int
5112 examine_argument (enum machine_mode mode, const_tree type, int in_return,
5113                   int *int_nregs, int *sse_nregs)
5114 {
5115   enum x86_64_reg_class regclass[MAX_CLASSES];
5116   int n = classify_argument (mode, type, regclass, 0);
5117
5118   *int_nregs = 0;
5119   *sse_nregs = 0;
5120   if (!n)
5121     return 0;
5122   for (n--; n >= 0; n--)
5123     switch (regclass[n])
5124       {
5125       case X86_64_INTEGER_CLASS:
5126       case X86_64_INTEGERSI_CLASS:
5127         (*int_nregs)++;
5128         break;
5129       case X86_64_AVX_CLASS:
5130       case X86_64_SSE_CLASS:
5131       case X86_64_SSESF_CLASS:
5132       case X86_64_SSEDF_CLASS:
5133         (*sse_nregs)++;
5134         break;
5135       case X86_64_NO_CLASS:
5136       case X86_64_SSEUP_CLASS:
5137         break;
5138       case X86_64_X87_CLASS:
5139       case X86_64_X87UP_CLASS:
5140         if (!in_return)
5141           return 0;
5142         break;
5143       case X86_64_COMPLEX_X87_CLASS:
5144         return in_return ? 2 : 0;
5145       case X86_64_MEMORY_CLASS:
5146         gcc_unreachable ();
5147       }
5148   return 1;
5149 }
5150
5151 /* Construct container for the argument used by GCC interface.  See
5152    FUNCTION_ARG for the detailed description.  */
5153
5154 static rtx
5155 construct_container (enum machine_mode mode, enum machine_mode orig_mode,
5156                      const_tree type, int in_return, int nintregs, int nsseregs,
5157                      const int *intreg, int sse_regno)
5158 {
5159   /* The following variables hold the static issued_error state.  */
5160   static bool issued_sse_arg_error;
5161   static bool issued_sse_ret_error;
5162   static bool issued_x87_ret_error;
5163
5164   enum machine_mode tmpmode;
5165   int bytes =
5166     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
5167   enum x86_64_reg_class regclass[MAX_CLASSES];
5168   int n;
5169   int i;
5170   int nexps = 0;
5171   int needed_sseregs, needed_intregs;
5172   rtx exp[MAX_CLASSES];
5173   rtx ret;
5174
5175   n = classify_argument (mode, type, regclass, 0);
5176   if (!n)
5177     return NULL;
5178   if (!examine_argument (mode, type, in_return, &needed_intregs,
5179                          &needed_sseregs))
5180     return NULL;
5181   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
5182     return NULL;
5183
5184   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
5185      some less clueful developer tries to use floating-point anyway.  */
5186   if (needed_sseregs && !TARGET_SSE)
5187     {
5188       if (in_return)
5189         {
5190           if (!issued_sse_ret_error)
5191             {
5192               error ("SSE register return with SSE disabled");
5193               issued_sse_ret_error = true;
5194             }
5195         }
5196       else if (!issued_sse_arg_error)
5197         {
5198           error ("SSE register argument with SSE disabled");
5199           issued_sse_arg_error = true;
5200         }
5201       return NULL;
5202     }
5203
5204   /* Likewise, error if the ABI requires us to return values in the
5205      x87 registers and the user specified -mno-80387.  */
5206   if (!TARGET_80387 && in_return)
5207     for (i = 0; i < n; i++)
5208       if (regclass[i] == X86_64_X87_CLASS
5209           || regclass[i] == X86_64_X87UP_CLASS
5210           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
5211         {
5212           if (!issued_x87_ret_error)
5213             {
5214               error ("x87 register return with x87 disabled");
5215               issued_x87_ret_error = true;
5216             }
5217           return NULL;
5218         }
5219
5220   /* First construct simple cases.  Avoid SCmode, since we want to use
5221      single register to pass this type.  */
5222   if (n == 1 && mode != SCmode)
5223     switch (regclass[0])
5224       {
5225       case X86_64_INTEGER_CLASS:
5226       case X86_64_INTEGERSI_CLASS:
5227         return gen_rtx_REG (mode, intreg[0]);
5228       case X86_64_AVX_CLASS:
5229       case X86_64_SSE_CLASS:
5230       case X86_64_SSESF_CLASS:
5231       case X86_64_SSEDF_CLASS:
5232         return gen_reg_or_parallel (mode, orig_mode, SSE_REGNO (sse_regno));
5233       case X86_64_X87_CLASS:
5234       case X86_64_COMPLEX_X87_CLASS:
5235         return gen_rtx_REG (mode, FIRST_STACK_REG);
5236       case X86_64_NO_CLASS:
5237         /* Zero sized array, struct or class.  */
5238         return NULL;
5239       default:
5240         gcc_unreachable ();
5241       }
5242   if (n == 2 && regclass[0] == X86_64_SSE_CLASS
5243       && regclass[1] == X86_64_SSEUP_CLASS && mode != BLKmode)
5244     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5245
5246   if (n == 2
5247       && regclass[0] == X86_64_X87_CLASS && regclass[1] == X86_64_X87UP_CLASS)
5248     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
5249   if (n == 2 && regclass[0] == X86_64_INTEGER_CLASS
5250       && regclass[1] == X86_64_INTEGER_CLASS
5251       && (mode == CDImode || mode == TImode || mode == TFmode)
5252       && intreg[0] + 1 == intreg[1])
5253     return gen_rtx_REG (mode, intreg[0]);
5254
5255   /* Otherwise figure out the entries of the PARALLEL.  */
5256   for (i = 0; i < n; i++)
5257     {
5258       switch (regclass[i])
5259         {
5260           case X86_64_NO_CLASS:
5261             break;
5262           case X86_64_INTEGER_CLASS:
5263           case X86_64_INTEGERSI_CLASS:
5264             /* Merge TImodes on aligned occasions here too.  */
5265             if (i * 8 + 8 > bytes)
5266               tmpmode = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
5267             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
5268               tmpmode = SImode;
5269             else
5270               tmpmode = DImode;
5271             /* We've requested 24 bytes we don't have mode for.  Use DImode.  */
5272             if (tmpmode == BLKmode)
5273               tmpmode = DImode;
5274             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5275                                                gen_rtx_REG (tmpmode, *intreg),
5276                                                GEN_INT (i*8));
5277             intreg++;
5278             break;
5279           case X86_64_SSESF_CLASS:
5280             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5281                                                gen_rtx_REG (SFmode,
5282                                                             SSE_REGNO (sse_regno)),
5283                                                GEN_INT (i*8));
5284             sse_regno++;
5285             break;
5286           case X86_64_SSEDF_CLASS:
5287             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5288                                                gen_rtx_REG (DFmode,
5289                                                             SSE_REGNO (sse_regno)),
5290                                                GEN_INT (i*8));
5291             sse_regno++;
5292             break;
5293           case X86_64_SSE_CLASS:
5294             if (i < n - 1 && regclass[i + 1] == X86_64_SSEUP_CLASS)
5295               tmpmode = TImode;
5296             else
5297               tmpmode = DImode;
5298             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5299                                                gen_rtx_REG (tmpmode,
5300                                                             SSE_REGNO (sse_regno)),
5301                                                GEN_INT (i*8));
5302             if (tmpmode == TImode)
5303               i++;
5304             sse_regno++;
5305             break;
5306           default:
5307             gcc_unreachable ();
5308         }
5309     }
5310
5311   /* Empty aligned struct, union or class.  */
5312   if (nexps == 0)
5313     return NULL;
5314
5315   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
5316   for (i = 0; i < nexps; i++)
5317     XVECEXP (ret, 0, i) = exp [i];
5318   return ret;
5319 }
5320
5321 /* Update the data in CUM to advance over an argument of mode MODE
5322    and data type TYPE.  (TYPE is null for libcalls where that information
5323    may not be available.)  */
5324
5325 static void
5326 function_arg_advance_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5327                          tree type, HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5328 {
5329   switch (mode)
5330     {
5331     default:
5332       break;
5333
5334     case BLKmode:
5335       if (bytes < 0)
5336         break;
5337       /* FALLTHRU */
5338
5339     case DImode:
5340     case SImode:
5341     case HImode:
5342     case QImode:
5343       cum->words += words;
5344       cum->nregs -= words;
5345       cum->regno += words;
5346
5347       if (cum->nregs <= 0)
5348         {
5349           cum->nregs = 0;
5350           cum->regno = 0;
5351         }
5352       break;
5353
5354     case DFmode:
5355       if (cum->float_in_sse < 2)
5356         break;
5357     case SFmode:
5358       if (cum->float_in_sse < 1)
5359         break;
5360       /* FALLTHRU */
5361
5362     case OImode:
5363     case V8SFmode:
5364     case V8SImode:
5365     case V32QImode:
5366     case V16HImode:
5367     case V4DFmode:
5368     case V4DImode:
5369     case TImode:
5370     case V16QImode:
5371     case V8HImode:
5372     case V4SImode:
5373     case V2DImode:
5374     case V4SFmode:
5375     case V2DFmode:
5376       if (!type || !AGGREGATE_TYPE_P (type))
5377         {
5378           cum->sse_words += words;
5379           cum->sse_nregs -= 1;
5380           cum->sse_regno += 1;
5381           if (cum->sse_nregs <= 0)
5382             {
5383               cum->sse_nregs = 0;
5384               cum->sse_regno = 0;
5385             }
5386         }
5387       break;
5388
5389     case V8QImode:
5390     case V4HImode:
5391     case V2SImode:
5392     case V2SFmode:
5393     case V1DImode:
5394       if (!type || !AGGREGATE_TYPE_P (type))
5395         {
5396           cum->mmx_words += words;
5397           cum->mmx_nregs -= 1;
5398           cum->mmx_regno += 1;
5399           if (cum->mmx_nregs <= 0)
5400             {
5401               cum->mmx_nregs = 0;
5402               cum->mmx_regno = 0;
5403             }
5404         }
5405       break;
5406     }
5407 }
5408
5409 static void
5410 function_arg_advance_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5411                          tree type, HOST_WIDE_INT words, int named)
5412 {
5413   int int_nregs, sse_nregs;
5414
5415   /* Unnamed 256bit vector mode parameters are passed on stack.  */
5416   if (!named && VALID_AVX256_REG_MODE (mode))
5417     return;
5418
5419   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs))
5420     cum->words += words;
5421   else if (sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
5422     {
5423       cum->nregs -= int_nregs;
5424       cum->sse_nregs -= sse_nregs;
5425       cum->regno += int_nregs;
5426       cum->sse_regno += sse_nregs;
5427     }
5428   else
5429     cum->words += words;
5430 }
5431
5432 static void
5433 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
5434                             HOST_WIDE_INT words)
5435 {
5436   /* Otherwise, this should be passed indirect.  */
5437   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
5438
5439   cum->words += words;
5440   if (cum->nregs > 0)
5441     {
5442       cum->nregs -= 1;
5443       cum->regno += 1;
5444     }
5445 }
5446
5447 void
5448 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5449                       tree type, int named)
5450 {
5451   HOST_WIDE_INT bytes, words;
5452
5453   if (mode == BLKmode)
5454     bytes = int_size_in_bytes (type);
5455   else
5456     bytes = GET_MODE_SIZE (mode);
5457   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5458
5459   if (type)
5460     mode = type_natural_mode (type);
5461
5462   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5463     function_arg_advance_ms_64 (cum, bytes, words);
5464   else if (TARGET_64BIT)
5465     function_arg_advance_64 (cum, mode, type, words, named);
5466   else
5467     function_arg_advance_32 (cum, mode, type, bytes, words);
5468 }
5469
5470 /* Define where to put the arguments to a function.
5471    Value is zero to push the argument on the stack,
5472    or a hard register in which to store the argument.
5473
5474    MODE is the argument's machine mode.
5475    TYPE is the data type of the argument (as a tree).
5476     This is null for libcalls where that information may
5477     not be available.
5478    CUM is a variable of type CUMULATIVE_ARGS which gives info about
5479     the preceding args and about the function being called.
5480    NAMED is nonzero if this argument is a named parameter
5481     (otherwise it is an extra parameter matching an ellipsis).  */
5482
5483 static rtx
5484 function_arg_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5485                  enum machine_mode orig_mode, tree type,
5486                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5487 {
5488   static bool warnedavx, warnedsse, warnedmmx;
5489
5490   /* Avoid the AL settings for the Unix64 ABI.  */
5491   if (mode == VOIDmode)
5492     return constm1_rtx;
5493
5494   switch (mode)
5495     {
5496     default:
5497       break;
5498
5499     case BLKmode:
5500       if (bytes < 0)
5501         break;
5502       /* FALLTHRU */
5503     case DImode:
5504     case SImode:
5505     case HImode:
5506     case QImode:
5507       if (words <= cum->nregs)
5508         {
5509           int regno = cum->regno;
5510
5511           /* Fastcall allocates the first two DWORD (SImode) or
5512             smaller arguments to ECX and EDX if it isn't an
5513             aggregate type .  */
5514           if (cum->fastcall)
5515             {
5516               if (mode == BLKmode
5517                   || mode == DImode
5518                   || (type && AGGREGATE_TYPE_P (type)))
5519                 break;
5520
5521               /* ECX not EAX is the first allocated register.  */
5522               if (regno == AX_REG)
5523                 regno = CX_REG;
5524             }
5525           return gen_rtx_REG (mode, regno);
5526         }
5527       break;
5528
5529     case DFmode:
5530       if (cum->float_in_sse < 2)
5531         break;
5532     case SFmode:
5533       if (cum->float_in_sse < 1)
5534         break;
5535       /* FALLTHRU */
5536     case TImode:
5537       /* In 32bit, we pass TImode in xmm registers.  */
5538     case V16QImode:
5539     case V8HImode:
5540     case V4SImode:
5541     case V2DImode:
5542     case V4SFmode:
5543     case V2DFmode:
5544       if (!type || !AGGREGATE_TYPE_P (type))
5545         {
5546           if (!TARGET_SSE && !warnedsse && cum->warn_sse)
5547             {
5548               warnedsse = true;
5549               warning (0, "SSE vector argument without SSE enabled "
5550                        "changes the ABI");
5551             }
5552           if (cum->sse_nregs)
5553             return gen_reg_or_parallel (mode, orig_mode,
5554                                         cum->sse_regno + FIRST_SSE_REG);
5555         }
5556       break;
5557
5558     case OImode:
5559       /* In 32bit, we pass OImode in ymm registers.  */
5560     case V8SFmode:
5561     case V8SImode:
5562     case V32QImode:
5563     case V16HImode:
5564     case V4DFmode:
5565     case V4DImode:
5566       if (!type || !AGGREGATE_TYPE_P (type))
5567         {
5568           if (!TARGET_AVX && !warnedavx && cum->warn_avx)
5569             {
5570               warnedavx = true;
5571               warning (0, "AVX vector argument without AVX enabled "
5572                        "changes the ABI");
5573             }
5574           if (cum->sse_nregs)
5575             return gen_reg_or_parallel (mode, orig_mode,
5576                                         cum->sse_regno + FIRST_SSE_REG);
5577         }
5578       break;
5579
5580     case V8QImode:
5581     case V4HImode:
5582     case V2SImode:
5583     case V2SFmode:
5584     case V1DImode:
5585       if (!type || !AGGREGATE_TYPE_P (type))
5586         {
5587           if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
5588             {
5589               warnedmmx = true;
5590               warning (0, "MMX vector argument without MMX enabled "
5591                        "changes the ABI");
5592             }
5593           if (cum->mmx_nregs)
5594             return gen_reg_or_parallel (mode, orig_mode,
5595                                         cum->mmx_regno + FIRST_MMX_REG);
5596         }
5597       break;
5598     }
5599
5600   return NULL_RTX;
5601 }
5602
5603 static rtx
5604 function_arg_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5605                  enum machine_mode orig_mode, tree type, int named)
5606 {
5607   static bool warnedavx;
5608
5609   /* Handle a hidden AL argument containing number of registers
5610      for varargs x86-64 functions.  */
5611   if (mode == VOIDmode)
5612     return GEN_INT (cum->maybe_vaarg
5613                     ? (cum->sse_nregs < 0
5614                        ? (cum->call_abi == DEFAULT_ABI
5615                           ? SSE_REGPARM_MAX
5616                           : (DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
5617                                                      : X64_SSE_REGPARM_MAX))
5618                : cum->sse_regno)
5619                     : -1);
5620
5621   switch (mode)
5622     {
5623     default:
5624       break;
5625
5626     case V8SFmode:
5627     case V8SImode:
5628     case V32QImode:
5629     case V16HImode:
5630     case V4DFmode:
5631     case V4DImode:
5632       /* In 64bit, we pass TImode in interger registers and OImode on
5633          stack.  */
5634       if (!type || !AGGREGATE_TYPE_P (type))
5635         {
5636           if (!TARGET_AVX && !warnedavx && cum->warn_avx)
5637             {
5638               warnedavx = true;
5639               warning (0, "AVX vector argument without AVX enabled "
5640                        "changes the ABI");
5641             }
5642         }
5643
5644       /* Unnamed 256bit vector mode parameters are passed on stack.  */
5645       if (!named)
5646         return NULL;
5647       break;
5648     }
5649
5650   return construct_container (mode, orig_mode, type, 0, cum->nregs,
5651                               cum->sse_nregs,
5652                               &x86_64_int_parameter_registers [cum->regno],
5653                               cum->sse_regno);
5654 }
5655
5656 static rtx
5657 function_arg_ms_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5658                     enum machine_mode orig_mode, int named,
5659                     HOST_WIDE_INT bytes)
5660 {
5661   unsigned int regno;
5662
5663   /* Avoid the AL settings for the Unix64 ABI.  */
5664   if (mode == VOIDmode)
5665     return constm1_rtx;
5666
5667   /* If we've run out of registers, it goes on the stack.  */
5668   if (cum->nregs == 0)
5669     return NULL_RTX;
5670
5671   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
5672
5673   /* Only floating point modes are passed in anything but integer regs.  */
5674   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
5675     {
5676       if (named)
5677         regno = cum->regno + FIRST_SSE_REG;
5678       else
5679         {
5680           rtx t1, t2;
5681
5682           /* Unnamed floating parameters are passed in both the
5683              SSE and integer registers.  */
5684           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
5685           t2 = gen_rtx_REG (mode, regno);
5686           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
5687           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
5688           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
5689         }
5690     }
5691   /* Handle aggregated types passed in register.  */
5692   if (orig_mode == BLKmode)
5693     {
5694       if (bytes > 0 && bytes <= 8)
5695         mode = (bytes > 4 ? DImode : SImode);
5696       if (mode == BLKmode)
5697         mode = DImode;
5698     }
5699
5700   return gen_reg_or_parallel (mode, orig_mode, regno);
5701 }
5702
5703 rtx
5704 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
5705               tree type, int named)
5706 {
5707   enum machine_mode mode = omode;
5708   HOST_WIDE_INT bytes, words;
5709
5710   if (mode == BLKmode)
5711     bytes = int_size_in_bytes (type);
5712   else
5713     bytes = GET_MODE_SIZE (mode);
5714   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5715
5716   /* To simplify the code below, represent vector types with a vector mode
5717      even if MMX/SSE are not active.  */
5718   if (type && TREE_CODE (type) == VECTOR_TYPE)
5719     mode = type_natural_mode (type);
5720
5721   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5722     return function_arg_ms_64 (cum, mode, omode, named, bytes);
5723   else if (TARGET_64BIT)
5724     return function_arg_64 (cum, mode, omode, type, named);
5725   else
5726     return function_arg_32 (cum, mode, omode, type, bytes, words);
5727 }
5728
5729 /* A C expression that indicates when an argument must be passed by
5730    reference.  If nonzero for an argument, a copy of that argument is
5731    made in memory and a pointer to the argument is passed instead of
5732    the argument itself.  The pointer is passed in whatever way is
5733    appropriate for passing a pointer to that type.  */
5734
5735 static bool
5736 ix86_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5737                         enum machine_mode mode ATTRIBUTE_UNUSED,
5738                         const_tree type, bool named ATTRIBUTE_UNUSED)
5739 {
5740   /* See Windows x64 Software Convention.  */
5741   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5742     {
5743       int msize = (int) GET_MODE_SIZE (mode);
5744       if (type)
5745         {
5746           /* Arrays are passed by reference.  */
5747           if (TREE_CODE (type) == ARRAY_TYPE)
5748             return true;
5749
5750           if (AGGREGATE_TYPE_P (type))
5751             {
5752               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
5753                  are passed by reference.  */
5754               msize = int_size_in_bytes (type);
5755             }
5756         }
5757
5758       /* __m128 is passed by reference.  */
5759       switch (msize) {
5760       case 1: case 2: case 4: case 8:
5761         break;
5762       default:
5763         return true;
5764       }
5765     }
5766   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
5767     return 1;
5768
5769   return 0;
5770 }
5771
5772 /* Return true when TYPE should be 128bit aligned for 32bit argument passing
5773    ABI.  */
5774 static bool
5775 contains_aligned_value_p (tree type)
5776 {
5777   enum machine_mode mode = TYPE_MODE (type);
5778   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
5779        || mode == TDmode
5780        || mode == TFmode
5781        || mode == TCmode)
5782       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
5783     return true;
5784   if (TYPE_ALIGN (type) < 128)
5785     return false;
5786
5787   if (AGGREGATE_TYPE_P (type))
5788     {
5789       /* Walk the aggregates recursively.  */
5790       switch (TREE_CODE (type))
5791         {
5792         case RECORD_TYPE:
5793         case UNION_TYPE:
5794         case QUAL_UNION_TYPE:
5795           {
5796             tree field;
5797
5798             /* Walk all the structure fields.  */
5799             for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5800               {
5801                 if (TREE_CODE (field) == FIELD_DECL
5802                     && contains_aligned_value_p (TREE_TYPE (field)))
5803                   return true;
5804               }
5805             break;
5806           }
5807
5808         case ARRAY_TYPE:
5809           /* Just for use if some languages passes arrays by value.  */
5810           if (contains_aligned_value_p (TREE_TYPE (type)))
5811             return true;
5812           break;
5813
5814         default:
5815           gcc_unreachable ();
5816         }
5817     }
5818   return false;
5819 }
5820
5821 /* Gives the alignment boundary, in bits, of an argument with the
5822    specified mode and type.  */
5823
5824 int
5825 ix86_function_arg_boundary (enum machine_mode mode, tree type)
5826 {
5827   int align;
5828   if (type)
5829     {
5830       /* Since canonical type is used for call, we convert it to
5831          canonical type if needed.  */
5832       if (!TYPE_STRUCTURAL_EQUALITY_P (type))
5833         type = TYPE_CANONICAL (type);
5834       align = TYPE_ALIGN (type);
5835     }
5836   else
5837     align = GET_MODE_ALIGNMENT (mode);
5838   if (align < PARM_BOUNDARY)
5839     align = PARM_BOUNDARY;
5840   /* In 32bit, only _Decimal128 and __float128 are aligned to their
5841      natural boundaries.  */
5842   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
5843     {
5844       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
5845          make an exception for SSE modes since these require 128bit
5846          alignment.
5847
5848          The handling here differs from field_alignment.  ICC aligns MMX
5849          arguments to 4 byte boundaries, while structure fields are aligned
5850          to 8 byte boundaries.  */
5851       if (!type)
5852         {
5853           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
5854             align = PARM_BOUNDARY;
5855         }
5856       else
5857         {
5858           if (!contains_aligned_value_p (type))
5859             align = PARM_BOUNDARY;
5860         }
5861     }
5862   if (align > BIGGEST_ALIGNMENT)
5863     align = BIGGEST_ALIGNMENT;
5864   return align;
5865 }
5866
5867 /* Return true if N is a possible register number of function value.  */
5868
5869 bool
5870 ix86_function_value_regno_p (int regno)
5871 {
5872   switch (regno)
5873     {
5874     case 0:
5875       return true;
5876
5877     case FIRST_FLOAT_REG:
5878       /* TODO: The function should depend on current function ABI but
5879        builtins.c would need updating then. Therefore we use the
5880        default ABI.  */
5881       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
5882         return false;
5883       return TARGET_FLOAT_RETURNS_IN_80387;
5884
5885     case FIRST_SSE_REG:
5886       return TARGET_SSE;
5887
5888     case FIRST_MMX_REG:
5889       if (TARGET_MACHO || TARGET_64BIT)
5890         return false;
5891       return TARGET_MMX;
5892     }
5893
5894   return false;
5895 }
5896
5897 /* Define how to find the value returned by a function.
5898    VALTYPE is the data type of the value (as a tree).
5899    If the precise function being called is known, FUNC is its FUNCTION_DECL;
5900    otherwise, FUNC is 0.  */
5901
5902 static rtx
5903 function_value_32 (enum machine_mode orig_mode, enum machine_mode mode,
5904                    const_tree fntype, const_tree fn)
5905 {
5906   unsigned int regno;
5907
5908   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
5909      we normally prevent this case when mmx is not available.  However
5910      some ABIs may require the result to be returned like DImode.  */
5911   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
5912     regno = TARGET_MMX ? FIRST_MMX_REG : 0;
5913
5914   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
5915      we prevent this case when sse is not available.  However some ABIs
5916      may require the result to be returned like integer TImode.  */
5917   else if (mode == TImode
5918            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
5919     regno = TARGET_SSE ? FIRST_SSE_REG : 0;
5920
5921   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
5922   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
5923     regno = FIRST_FLOAT_REG;
5924   else
5925     /* Most things go in %eax.  */
5926     regno = AX_REG;
5927
5928   /* Override FP return register with %xmm0 for local functions when
5929      SSE math is enabled or for functions with sseregparm attribute.  */
5930   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
5931     {
5932       int sse_level = ix86_function_sseregparm (fntype, fn, false);
5933       if ((sse_level >= 1 && mode == SFmode)
5934           || (sse_level == 2 && mode == DFmode))
5935         regno = FIRST_SSE_REG;
5936     }
5937
5938   return gen_rtx_REG (orig_mode, regno);
5939 }
5940
5941 static rtx
5942 function_value_64 (enum machine_mode orig_mode, enum machine_mode mode,
5943                    const_tree valtype)
5944 {
5945   rtx ret;
5946
5947   /* Handle libcalls, which don't provide a type node.  */
5948   if (valtype == NULL)
5949     {
5950       switch (mode)
5951         {
5952         case SFmode:
5953         case SCmode:
5954         case DFmode:
5955         case DCmode:
5956         case TFmode:
5957         case SDmode:
5958         case DDmode:
5959         case TDmode:
5960           return gen_rtx_REG (mode, FIRST_SSE_REG);
5961         case XFmode:
5962         case XCmode:
5963           return gen_rtx_REG (mode, FIRST_FLOAT_REG);
5964         case TCmode:
5965           return NULL;
5966         default:
5967           return gen_rtx_REG (mode, AX_REG);
5968         }
5969     }
5970
5971   ret = construct_container (mode, orig_mode, valtype, 1,
5972                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
5973                              x86_64_int_return_registers, 0);
5974
5975   /* For zero sized structures, construct_container returns NULL, but we
5976      need to keep rest of compiler happy by returning meaningful value.  */
5977   if (!ret)
5978     ret = gen_rtx_REG (orig_mode, AX_REG);
5979
5980   return ret;
5981 }
5982
5983 static rtx
5984 function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
5985 {
5986   unsigned int regno = AX_REG;
5987
5988   if (TARGET_SSE)
5989     {
5990       switch (GET_MODE_SIZE (mode))
5991         {
5992         case 16:
5993           if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
5994              && !COMPLEX_MODE_P (mode))
5995             regno = FIRST_SSE_REG;
5996           break;
5997         case 8:
5998         case 4:
5999           if (mode == SFmode || mode == DFmode)
6000             regno = FIRST_SSE_REG;
6001           break;
6002         default:
6003           break;
6004         }
6005     }
6006   return gen_rtx_REG (orig_mode, regno);
6007 }
6008
6009 static rtx
6010 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
6011                        enum machine_mode orig_mode, enum machine_mode mode)
6012 {
6013   const_tree fn, fntype;
6014
6015   fn = NULL_TREE;
6016   if (fntype_or_decl && DECL_P (fntype_or_decl))
6017     fn = fntype_or_decl;
6018   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
6019
6020   if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
6021     return function_value_ms_64 (orig_mode, mode);
6022   else if (TARGET_64BIT)
6023     return function_value_64 (orig_mode, mode, valtype);
6024   else
6025     return function_value_32 (orig_mode, mode, fntype, fn);
6026 }
6027
6028 static rtx
6029 ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
6030                      bool outgoing ATTRIBUTE_UNUSED)
6031 {
6032   enum machine_mode mode, orig_mode;
6033
6034   orig_mode = TYPE_MODE (valtype);
6035   mode = type_natural_mode (valtype);
6036   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
6037 }
6038
6039 rtx
6040 ix86_libcall_value (enum machine_mode mode)
6041 {
6042   return ix86_function_value_1 (NULL, NULL, mode, mode);
6043 }
6044
6045 /* Return true iff type is returned in memory.  */
6046
6047 static int ATTRIBUTE_UNUSED
6048 return_in_memory_32 (const_tree type, enum machine_mode mode)
6049 {
6050   HOST_WIDE_INT size;
6051
6052   if (mode == BLKmode)
6053     return 1;
6054
6055   size = int_size_in_bytes (type);
6056
6057   if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
6058     return 0;
6059
6060   if (VECTOR_MODE_P (mode) || mode == TImode)
6061     {
6062       /* User-created vectors small enough to fit in EAX.  */
6063       if (size < 8)
6064         return 0;
6065
6066       /* MMX/3dNow values are returned in MM0,
6067          except when it doesn't exits.  */
6068       if (size == 8)
6069         return (TARGET_MMX ? 0 : 1);
6070
6071       /* SSE values are returned in XMM0, except when it doesn't exist.  */
6072       if (size == 16)
6073         return (TARGET_SSE ? 0 : 1);
6074     }
6075
6076   if (mode == XFmode)
6077     return 0;
6078
6079   if (size > 12)
6080     return 1;
6081   return 0;
6082 }
6083
6084 static int ATTRIBUTE_UNUSED
6085 return_in_memory_64 (const_tree type, enum machine_mode mode)
6086 {
6087   int needed_intregs, needed_sseregs;
6088   return !examine_argument (mode, type, 1, &needed_intregs, &needed_sseregs);
6089 }
6090
6091 static int ATTRIBUTE_UNUSED
6092 return_in_memory_ms_64 (const_tree type, enum machine_mode mode)
6093 {
6094   HOST_WIDE_INT size = int_size_in_bytes (type);
6095
6096   /* __m128 is returned in xmm0.  */
6097   if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6098       && !COMPLEX_MODE_P (mode) && (GET_MODE_SIZE (mode) == 16 || size == 16))
6099     return 0;
6100
6101   /* Otherwise, the size must be exactly in [1248]. */
6102   return (size != 1 && size != 2 && size != 4 && size != 8);
6103 }
6104
6105 static bool
6106 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6107 {
6108 #ifdef SUBTARGET_RETURN_IN_MEMORY
6109   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
6110 #else
6111    const enum machine_mode mode = type_natural_mode (type);
6112  
6113   if (TARGET_64BIT_MS_ABI)
6114      return return_in_memory_ms_64 (type, mode);
6115    else if (TARGET_64BIT)
6116      return return_in_memory_64 (type, mode);
6117    else
6118      return return_in_memory_32 (type, mode);
6119 #endif
6120 }
6121
6122 /* Return false iff TYPE is returned in memory.  This version is used
6123    on Solaris 10.  It is similar to the generic ix86_return_in_memory,
6124    but differs notably in that when MMX is available, 8-byte vectors
6125    are returned in memory, rather than in MMX registers.  */
6126
6127 bool
6128 ix86_sol10_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6129 {
6130   int size;
6131   enum machine_mode mode = type_natural_mode (type);
6132
6133   if (TARGET_64BIT)
6134     return return_in_memory_64 (type, mode);
6135
6136   if (mode == BLKmode)
6137     return 1;
6138
6139   size = int_size_in_bytes (type);
6140
6141   if (VECTOR_MODE_P (mode))
6142     {
6143       /* Return in memory only if MMX registers *are* available.  This
6144          seems backwards, but it is consistent with the existing
6145          Solaris x86 ABI.  */
6146       if (size == 8)
6147         return TARGET_MMX;
6148       if (size == 16)
6149         return !TARGET_SSE;
6150     }
6151   else if (mode == TImode)
6152     return !TARGET_SSE;
6153   else if (mode == XFmode)
6154     return 0;
6155
6156   return size > 12;
6157 }
6158
6159 /* When returning SSE vector types, we have a choice of either
6160      (1) being abi incompatible with a -march switch, or
6161      (2) generating an error.
6162    Given no good solution, I think the safest thing is one warning.
6163    The user won't be able to use -Werror, but....
6164
6165    Choose the STRUCT_VALUE_RTX hook because that's (at present) only
6166    called in response to actually generating a caller or callee that
6167    uses such a type.  As opposed to TARGET_RETURN_IN_MEMORY, which is called
6168    via aggregate_value_p for general type probing from tree-ssa.  */
6169
6170 static rtx
6171 ix86_struct_value_rtx (tree type, int incoming ATTRIBUTE_UNUSED)
6172 {
6173   static bool warnedsse, warnedmmx;
6174
6175   if (!TARGET_64BIT && type)
6176     {
6177       /* Look at the return type of the function, not the function type.  */
6178       enum machine_mode mode = TYPE_MODE (TREE_TYPE (type));
6179
6180       if (!TARGET_SSE && !warnedsse)
6181         {
6182           if (mode == TImode
6183               || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6184             {
6185               warnedsse = true;
6186               warning (0, "SSE vector return without SSE enabled "
6187                        "changes the ABI");
6188             }
6189         }
6190
6191       if (!TARGET_MMX && !warnedmmx)
6192         {
6193           if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6194             {
6195               warnedmmx = true;
6196               warning (0, "MMX vector return without MMX enabled "
6197                        "changes the ABI");
6198             }
6199         }
6200     }
6201
6202   return NULL;
6203 }
6204
6205 \f
6206 /* Create the va_list data type.  */
6207
6208 /* Returns the calling convention specific va_list date type.
6209    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
6210
6211 static tree
6212 ix86_build_builtin_va_list_abi (enum calling_abi abi)
6213 {
6214   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
6215
6216   /* For i386 we use plain pointer to argument area.  */
6217   if (!TARGET_64BIT || abi == MS_ABI)
6218     return build_pointer_type (char_type_node);
6219
6220   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6221   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6222
6223   f_gpr = build_decl (FIELD_DECL, get_identifier ("gp_offset"),
6224                       unsigned_type_node);
6225   f_fpr = build_decl (FIELD_DECL, get_identifier ("fp_offset"),
6226                       unsigned_type_node);
6227   f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
6228                       ptr_type_node);
6229   f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
6230                       ptr_type_node);
6231
6232   va_list_gpr_counter_field = f_gpr;
6233   va_list_fpr_counter_field = f_fpr;
6234
6235   DECL_FIELD_CONTEXT (f_gpr) = record;
6236   DECL_FIELD_CONTEXT (f_fpr) = record;
6237   DECL_FIELD_CONTEXT (f_ovf) = record;
6238   DECL_FIELD_CONTEXT (f_sav) = record;
6239
6240   TREE_CHAIN (record) = type_decl;
6241   TYPE_NAME (record) = type_decl;
6242   TYPE_FIELDS (record) = f_gpr;
6243   TREE_CHAIN (f_gpr) = f_fpr;
6244   TREE_CHAIN (f_fpr) = f_ovf;
6245   TREE_CHAIN (f_ovf) = f_sav;
6246
6247   layout_type (record);
6248
6249   /* The correct type is an array type of one element.  */
6250   return build_array_type (record, build_index_type (size_zero_node));
6251 }
6252
6253 /* Setup the builtin va_list data type and for 64-bit the additional
6254    calling convention specific va_list data types.  */
6255
6256 static tree
6257 ix86_build_builtin_va_list (void)
6258 {
6259   tree ret = ix86_build_builtin_va_list_abi (DEFAULT_ABI);
6260
6261   /* Initialize abi specific va_list builtin types.  */
6262   if (TARGET_64BIT)
6263     {
6264       tree t;
6265       if (DEFAULT_ABI == MS_ABI)
6266         {
6267           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
6268           if (TREE_CODE (t) != RECORD_TYPE)
6269             t = build_variant_type_copy (t);
6270           sysv_va_list_type_node = t;
6271         }
6272       else
6273         {
6274           t = ret;
6275           if (TREE_CODE (t) != RECORD_TYPE)
6276             t = build_variant_type_copy (t);
6277           sysv_va_list_type_node = t;
6278         }
6279       if (DEFAULT_ABI != MS_ABI)
6280         {
6281           t = ix86_build_builtin_va_list_abi (MS_ABI);
6282           if (TREE_CODE (t) != RECORD_TYPE)
6283             t = build_variant_type_copy (t);
6284           ms_va_list_type_node = t;
6285         }
6286       else
6287         {
6288           t = ret;
6289           if (TREE_CODE (t) != RECORD_TYPE)
6290             t = build_variant_type_copy (t);
6291           ms_va_list_type_node = t;
6292         }
6293     }
6294
6295   return ret;
6296 }
6297
6298 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
6299
6300 static void
6301 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
6302 {
6303   rtx save_area, mem;
6304   rtx label;
6305   rtx label_ref;
6306   rtx tmp_reg;
6307   rtx nsse_reg;
6308   alias_set_type set;
6309   int i;
6310   int regparm = ix86_regparm;
6311
6312   if (cum->call_abi != DEFAULT_ABI)
6313     regparm = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
6314
6315   /* GPR size of varargs save area.  */
6316   if (cfun->va_list_gpr_size)
6317     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
6318   else
6319     ix86_varargs_gpr_size = 0;
6320
6321   /* FPR size of varargs save area.  We don't need it if we don't pass
6322      anything in SSE registers.  */
6323   if (cum->sse_nregs && cfun->va_list_fpr_size)
6324     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
6325   else
6326     ix86_varargs_fpr_size = 0;
6327
6328   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
6329     return;
6330
6331   save_area = frame_pointer_rtx;
6332   set = get_varargs_alias_set ();
6333
6334   for (i = cum->regno;
6335        i < regparm
6336        && i < cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
6337        i++)
6338     {
6339       mem = gen_rtx_MEM (Pmode,
6340                          plus_constant (save_area, i * UNITS_PER_WORD));
6341       MEM_NOTRAP_P (mem) = 1;
6342       set_mem_alias_set (mem, set);
6343       emit_move_insn (mem, gen_rtx_REG (Pmode,
6344                                         x86_64_int_parameter_registers[i]));
6345     }
6346
6347   if (ix86_varargs_fpr_size)
6348     {
6349       /* Now emit code to save SSE registers.  The AX parameter contains number
6350          of SSE parameter registers used to call this function.  We use
6351          sse_prologue_save insn template that produces computed jump across
6352          SSE saves.  We need some preparation work to get this working.  */
6353
6354       label = gen_label_rtx ();
6355       label_ref = gen_rtx_LABEL_REF (Pmode, label);
6356
6357       /* Compute address to jump to :
6358          label - eax*4 + nnamed_sse_arguments*4 Or
6359          label - eax*5 + nnamed_sse_arguments*5 for AVX.  */
6360       tmp_reg = gen_reg_rtx (Pmode);
6361       nsse_reg = gen_reg_rtx (Pmode);
6362       emit_insn (gen_zero_extendqidi2 (nsse_reg, gen_rtx_REG (QImode, AX_REG)));
6363       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6364                               gen_rtx_MULT (Pmode, nsse_reg,
6365                                             GEN_INT (4))));
6366
6367       /* vmovaps is one byte longer than movaps.  */
6368       if (TARGET_AVX)
6369         emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6370                                 gen_rtx_PLUS (Pmode, tmp_reg,
6371                                               nsse_reg)));
6372
6373       if (cum->sse_regno)
6374         emit_move_insn
6375           (nsse_reg,
6376            gen_rtx_CONST (DImode,
6377                           gen_rtx_PLUS (DImode,
6378                                         label_ref,
6379                                         GEN_INT (cum->sse_regno
6380                                                  * (TARGET_AVX ? 5 : 4)))));
6381       else
6382         emit_move_insn (nsse_reg, label_ref);
6383       emit_insn (gen_subdi3 (nsse_reg, nsse_reg, tmp_reg));
6384
6385       /* Compute address of memory block we save into.  We always use pointer
6386          pointing 127 bytes after first byte to store - this is needed to keep
6387          instruction size limited by 4 bytes (5 bytes for AVX) with one
6388          byte displacement.  */
6389       tmp_reg = gen_reg_rtx (Pmode);
6390       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6391                               plus_constant (save_area,
6392                                              ix86_varargs_gpr_size + 127)));
6393       mem = gen_rtx_MEM (BLKmode, plus_constant (tmp_reg, -127));
6394       MEM_NOTRAP_P (mem) = 1;
6395       set_mem_alias_set (mem, set);
6396       set_mem_align (mem, BITS_PER_WORD);
6397
6398       /* And finally do the dirty job!  */
6399       emit_insn (gen_sse_prologue_save (mem, nsse_reg,
6400                                         GEN_INT (cum->sse_regno), label));
6401     }
6402 }
6403
6404 static void
6405 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
6406 {
6407   alias_set_type set = get_varargs_alias_set ();
6408   int i;
6409
6410   for (i = cum->regno; i < X64_REGPARM_MAX; i++)
6411     {
6412       rtx reg, mem;
6413
6414       mem = gen_rtx_MEM (Pmode,
6415                          plus_constant (virtual_incoming_args_rtx,
6416                                         i * UNITS_PER_WORD));
6417       MEM_NOTRAP_P (mem) = 1;
6418       set_mem_alias_set (mem, set);
6419
6420       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
6421       emit_move_insn (mem, reg);
6422     }
6423 }
6424
6425 static void
6426 ix86_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
6427                              tree type, int *pretend_size ATTRIBUTE_UNUSED,
6428                              int no_rtl)
6429 {
6430   CUMULATIVE_ARGS next_cum;
6431   tree fntype;
6432
6433   /* This argument doesn't appear to be used anymore.  Which is good,
6434      because the old code here didn't suppress rtl generation.  */
6435   gcc_assert (!no_rtl);
6436
6437   if (!TARGET_64BIT)
6438     return;
6439
6440   fntype = TREE_TYPE (current_function_decl);
6441
6442   /* For varargs, we do not want to skip the dummy va_dcl argument.
6443      For stdargs, we do want to skip the last named argument.  */
6444   next_cum = *cum;
6445   if (stdarg_p (fntype))
6446     function_arg_advance (&next_cum, mode, type, 1);
6447
6448   if (cum->call_abi == MS_ABI)
6449     setup_incoming_varargs_ms_64 (&next_cum);
6450   else
6451     setup_incoming_varargs_64 (&next_cum);
6452 }
6453
6454 /* Checks if TYPE is of kind va_list char *.  */
6455
6456 static bool
6457 is_va_list_char_pointer (tree type)
6458 {
6459   tree canonic;
6460
6461   /* For 32-bit it is always true.  */
6462   if (!TARGET_64BIT)
6463     return true;
6464   canonic = ix86_canonical_va_list_type (type);
6465   return (canonic == ms_va_list_type_node
6466           || (DEFAULT_ABI == MS_ABI && canonic == va_list_type_node));
6467 }
6468
6469 /* Implement va_start.  */
6470
6471 static void
6472 ix86_va_start (tree valist, rtx nextarg)
6473 {
6474   HOST_WIDE_INT words, n_gpr, n_fpr;
6475   tree f_gpr, f_fpr, f_ovf, f_sav;
6476   tree gpr, fpr, ovf, sav, t;
6477   tree type;
6478
6479   /* Only 64bit target needs something special.  */
6480   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6481     {
6482       std_expand_builtin_va_start (valist, nextarg);
6483       return;
6484     }
6485
6486   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6487   f_fpr = TREE_CHAIN (f_gpr);
6488   f_ovf = TREE_CHAIN (f_fpr);
6489   f_sav = TREE_CHAIN (f_ovf);
6490
6491   valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
6492   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6493   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6494   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6495   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6496
6497   /* Count number of gp and fp argument registers used.  */
6498   words = crtl->args.info.words;
6499   n_gpr = crtl->args.info.regno;
6500   n_fpr = crtl->args.info.sse_regno;
6501
6502   if (cfun->va_list_gpr_size)
6503     {
6504       type = TREE_TYPE (gpr);
6505       t = build2 (MODIFY_EXPR, type,
6506                   gpr, build_int_cst (type, n_gpr * 8));
6507       TREE_SIDE_EFFECTS (t) = 1;
6508       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6509     }
6510
6511   if (TARGET_SSE && cfun->va_list_fpr_size)
6512     {
6513       type = TREE_TYPE (fpr);
6514       t = build2 (MODIFY_EXPR, type, fpr,
6515                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
6516       TREE_SIDE_EFFECTS (t) = 1;
6517       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6518     }
6519
6520   /* Find the overflow area.  */
6521   type = TREE_TYPE (ovf);
6522   t = make_tree (type, crtl->args.internal_arg_pointer);
6523   if (words != 0)
6524     t = build2 (POINTER_PLUS_EXPR, type, t,
6525                 size_int (words * UNITS_PER_WORD));
6526   t = build2 (MODIFY_EXPR, type, ovf, t);
6527   TREE_SIDE_EFFECTS (t) = 1;
6528   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6529
6530   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
6531     {
6532       /* Find the register save area.
6533          Prologue of the function save it right above stack frame.  */
6534       type = TREE_TYPE (sav);
6535       t = make_tree (type, frame_pointer_rtx);
6536       if (!ix86_varargs_gpr_size)
6537         t = build2 (POINTER_PLUS_EXPR, type, t,
6538                     size_int (-8 * X86_64_REGPARM_MAX));
6539       t = build2 (MODIFY_EXPR, type, sav, t);
6540       TREE_SIDE_EFFECTS (t) = 1;
6541       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6542     }
6543 }
6544
6545 /* Implement va_arg.  */
6546
6547 static tree
6548 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
6549                       gimple_seq *post_p)
6550 {
6551   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
6552   tree f_gpr, f_fpr, f_ovf, f_sav;
6553   tree gpr, fpr, ovf, sav, t;
6554   int size, rsize;
6555   tree lab_false, lab_over = NULL_TREE;
6556   tree addr, t2;
6557   rtx container;
6558   int indirect_p = 0;
6559   tree ptrtype;
6560   enum machine_mode nat_mode;
6561   int arg_boundary;
6562
6563   /* Only 64bit target needs something special.  */
6564   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6565     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6566
6567   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6568   f_fpr = TREE_CHAIN (f_gpr);
6569   f_ovf = TREE_CHAIN (f_fpr);
6570   f_sav = TREE_CHAIN (f_ovf);
6571
6572   valist = build_va_arg_indirect_ref (valist);
6573   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6574   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6575   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6576   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6577
6578   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
6579   if (indirect_p)
6580     type = build_pointer_type (type);
6581   size = int_size_in_bytes (type);
6582   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6583
6584   nat_mode = type_natural_mode (type);
6585   switch (nat_mode)
6586     {
6587     case V8SFmode:
6588     case V8SImode:
6589     case V32QImode:
6590     case V16HImode:
6591     case V4DFmode:
6592     case V4DImode:
6593       /* Unnamed 256bit vector mode parameters are passed on stack.  */
6594       if (ix86_cfun_abi () == SYSV_ABI)
6595         {
6596           container = NULL;
6597           break;
6598         }
6599
6600     default:
6601       container = construct_container (nat_mode, TYPE_MODE (type),
6602                                        type, 0, X86_64_REGPARM_MAX,
6603                                        X86_64_SSE_REGPARM_MAX, intreg,
6604                                        0);
6605       break;
6606     }
6607
6608   /* Pull the value out of the saved registers.  */
6609
6610   addr = create_tmp_var (ptr_type_node, "addr");
6611   DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
6612
6613   if (container)
6614     {
6615       int needed_intregs, needed_sseregs;
6616       bool need_temp;
6617       tree int_addr, sse_addr;
6618
6619       lab_false = create_artificial_label ();
6620       lab_over = create_artificial_label ();
6621
6622       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
6623
6624       need_temp = (!REG_P (container)
6625                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
6626                        || TYPE_ALIGN (type) > 128));
6627
6628       /* In case we are passing structure, verify that it is consecutive block
6629          on the register save area.  If not we need to do moves.  */
6630       if (!need_temp && !REG_P (container))
6631         {
6632           /* Verify that all registers are strictly consecutive  */
6633           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
6634             {
6635               int i;
6636
6637               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6638                 {
6639                   rtx slot = XVECEXP (container, 0, i);
6640                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
6641                       || INTVAL (XEXP (slot, 1)) != i * 16)
6642                     need_temp = 1;
6643                 }
6644             }
6645           else
6646             {
6647               int i;
6648
6649               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6650                 {
6651                   rtx slot = XVECEXP (container, 0, i);
6652                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
6653                       || INTVAL (XEXP (slot, 1)) != i * 8)
6654                     need_temp = 1;
6655                 }
6656             }
6657         }
6658       if (!need_temp)
6659         {
6660           int_addr = addr;
6661           sse_addr = addr;
6662         }
6663       else
6664         {
6665           int_addr = create_tmp_var (ptr_type_node, "int_addr");
6666           DECL_POINTER_ALIAS_SET (int_addr) = get_varargs_alias_set ();
6667           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
6668           DECL_POINTER_ALIAS_SET (sse_addr) = get_varargs_alias_set ();
6669         }
6670
6671       /* First ensure that we fit completely in registers.  */
6672       if (needed_intregs)
6673         {
6674           t = build_int_cst (TREE_TYPE (gpr),
6675                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
6676           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
6677           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6678           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6679           gimplify_and_add (t, pre_p);
6680         }
6681       if (needed_sseregs)
6682         {
6683           t = build_int_cst (TREE_TYPE (fpr),
6684                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
6685                              + X86_64_REGPARM_MAX * 8);
6686           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
6687           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6688           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6689           gimplify_and_add (t, pre_p);
6690         }
6691
6692       /* Compute index to start of area used for integer regs.  */
6693       if (needed_intregs)
6694         {
6695           /* int_addr = gpr + sav; */
6696           t = fold_convert (sizetype, gpr);
6697           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6698           gimplify_assign (int_addr, t, pre_p);
6699         }
6700       if (needed_sseregs)
6701         {
6702           /* sse_addr = fpr + sav; */
6703           t = fold_convert (sizetype, fpr);
6704           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6705           gimplify_assign (sse_addr, t, pre_p);
6706         }
6707       if (need_temp)
6708         {
6709           int i;
6710           tree temp = create_tmp_var (type, "va_arg_tmp");
6711
6712           /* addr = &temp; */
6713           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
6714           gimplify_assign (addr, t, pre_p);
6715
6716           for (i = 0; i < XVECLEN (container, 0); i++)
6717             {
6718               rtx slot = XVECEXP (container, 0, i);
6719               rtx reg = XEXP (slot, 0);
6720               enum machine_mode mode = GET_MODE (reg);
6721               tree piece_type = lang_hooks.types.type_for_mode (mode, 1);
6722               tree addr_type = build_pointer_type (piece_type);
6723               tree src_addr, src;
6724               int src_offset;
6725               tree dest_addr, dest;
6726
6727               if (SSE_REGNO_P (REGNO (reg)))
6728                 {
6729                   src_addr = sse_addr;
6730                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
6731                 }
6732               else
6733                 {
6734                   src_addr = int_addr;
6735                   src_offset = REGNO (reg) * 8;
6736                 }
6737               src_addr = fold_convert (addr_type, src_addr);
6738               src_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, src_addr,
6739                                       size_int (src_offset));
6740               src = build_va_arg_indirect_ref (src_addr);
6741
6742               dest_addr = fold_convert (addr_type, addr);
6743               dest_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, dest_addr,
6744                                        size_int (INTVAL (XEXP (slot, 1))));
6745               dest = build_va_arg_indirect_ref (dest_addr);
6746
6747               gimplify_assign (dest, src, pre_p);
6748             }
6749         }
6750
6751       if (needed_intregs)
6752         {
6753           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
6754                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
6755           gimplify_assign (gpr, t, pre_p);
6756         }
6757
6758       if (needed_sseregs)
6759         {
6760           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
6761                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
6762           gimplify_assign (fpr, t, pre_p);
6763         }
6764
6765       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
6766
6767       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
6768     }
6769
6770   /* ... otherwise out of the overflow area.  */
6771
6772   /* When we align parameter on stack for caller, if the parameter
6773      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
6774      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
6775      here with caller.  */
6776   arg_boundary = FUNCTION_ARG_BOUNDARY (VOIDmode, type);
6777   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
6778     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
6779
6780   /* Care for on-stack alignment if needed.  */
6781   if (arg_boundary <= 64
6782       || integer_zerop (TYPE_SIZE (type)))
6783     t = ovf;
6784  else
6785     {
6786       HOST_WIDE_INT align = arg_boundary / 8;
6787       t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovf), ovf,
6788                   size_int (align - 1));
6789       t = fold_convert (sizetype, t);
6790       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
6791                   size_int (-align));
6792       t = fold_convert (TREE_TYPE (ovf), t);
6793     }
6794   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
6795   gimplify_assign (addr, t, pre_p);
6796
6797   t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
6798               size_int (rsize * UNITS_PER_WORD));
6799   gimplify_assign (unshare_expr (ovf), t, pre_p);
6800
6801   if (container)
6802     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
6803
6804   ptrtype = build_pointer_type (type);
6805   addr = fold_convert (ptrtype, addr);
6806
6807   if (indirect_p)
6808     addr = build_va_arg_indirect_ref (addr);
6809   return build_va_arg_indirect_ref (addr);
6810 }
6811 \f
6812 /* Return nonzero if OPNUM's MEM should be matched
6813    in movabs* patterns.  */
6814
6815 int
6816 ix86_check_movabs (rtx insn, int opnum)
6817 {
6818   rtx set, mem;
6819
6820   set = PATTERN (insn);
6821   if (GET_CODE (set) == PARALLEL)
6822     set = XVECEXP (set, 0, 0);
6823   gcc_assert (GET_CODE (set) == SET);
6824   mem = XEXP (set, opnum);
6825   while (GET_CODE (mem) == SUBREG)
6826     mem = SUBREG_REG (mem);
6827   gcc_assert (MEM_P (mem));
6828   return (volatile_ok || !MEM_VOLATILE_P (mem));
6829 }
6830 \f
6831 /* Initialize the table of extra 80387 mathematical constants.  */
6832
6833 static void
6834 init_ext_80387_constants (void)
6835 {
6836   static const char * cst[5] =
6837   {
6838     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
6839     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
6840     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
6841     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
6842     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
6843   };
6844   int i;
6845
6846   for (i = 0; i < 5; i++)
6847     {
6848       real_from_string (&ext_80387_constants_table[i], cst[i]);
6849       /* Ensure each constant is rounded to XFmode precision.  */
6850       real_convert (&ext_80387_constants_table[i],
6851                     XFmode, &ext_80387_constants_table[i]);
6852     }
6853
6854   ext_80387_constants_init = 1;
6855 }
6856
6857 /* Return true if the constant is something that can be loaded with
6858    a special instruction.  */
6859
6860 int
6861 standard_80387_constant_p (rtx x)
6862 {
6863   enum machine_mode mode = GET_MODE (x);
6864
6865   REAL_VALUE_TYPE r;
6866
6867   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
6868     return -1;
6869
6870   if (x == CONST0_RTX (mode))
6871     return 1;
6872   if (x == CONST1_RTX (mode))
6873     return 2;
6874
6875   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
6876
6877   /* For XFmode constants, try to find a special 80387 instruction when
6878      optimizing for size or on those CPUs that benefit from them.  */
6879   if (mode == XFmode
6880       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
6881     {
6882       int i;
6883
6884       if (! ext_80387_constants_init)
6885         init_ext_80387_constants ();
6886
6887       for (i = 0; i < 5; i++)
6888         if (real_identical (&r, &ext_80387_constants_table[i]))
6889           return i + 3;
6890     }
6891
6892   /* Load of the constant -0.0 or -1.0 will be split as
6893      fldz;fchs or fld1;fchs sequence.  */
6894   if (real_isnegzero (&r))
6895     return 8;
6896   if (real_identical (&r, &dconstm1))
6897     return 9;
6898
6899   return 0;
6900 }
6901
6902 /* Return the opcode of the special instruction to be used to load
6903    the constant X.  */
6904
6905 const char *
6906 standard_80387_constant_opcode (rtx x)
6907 {
6908   switch (standard_80387_constant_p (x))
6909     {
6910     case 1:
6911       return "fldz";
6912     case 2:
6913       return "fld1";
6914     case 3:
6915       return "fldlg2";
6916     case 4:
6917       return "fldln2";
6918     case 5:
6919       return "fldl2e";
6920     case 6:
6921       return "fldl2t";
6922     case 7:
6923       return "fldpi";
6924     case 8:
6925     case 9:
6926       return "#";
6927     default:
6928       gcc_unreachable ();
6929     }
6930 }
6931
6932 /* Return the CONST_DOUBLE representing the 80387 constant that is
6933    loaded by the specified special instruction.  The argument IDX
6934    matches the return value from standard_80387_constant_p.  */
6935
6936 rtx
6937 standard_80387_constant_rtx (int idx)
6938 {
6939   int i;
6940
6941   if (! ext_80387_constants_init)
6942     init_ext_80387_constants ();
6943
6944   switch (idx)
6945     {
6946     case 3:
6947     case 4:
6948     case 5:
6949     case 6:
6950     case 7:
6951       i = idx - 3;
6952       break;
6953
6954     default:
6955       gcc_unreachable ();
6956     }
6957
6958   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
6959                                        XFmode);
6960 }
6961
6962 /* Return 1 if mode is a valid mode for sse.  */
6963 static int
6964 standard_sse_mode_p (enum machine_mode mode)
6965 {
6966   switch (mode)
6967     {
6968     case V16QImode:
6969     case V8HImode:
6970     case V4SImode:
6971     case V2DImode:
6972     case V4SFmode:
6973     case V2DFmode:
6974       return 1;
6975
6976     default:
6977       return 0;
6978     }
6979 }
6980
6981 /* Return 1 if X is all 0s.  For all 1s, return 2 if X is in 128bit
6982    SSE modes and SSE2 is enabled,  return 3 if X is in 256bit AVX
6983    modes and AVX is enabled.  */
6984
6985 int
6986 standard_sse_constant_p (rtx x)
6987 {
6988   enum machine_mode mode = GET_MODE (x);
6989
6990   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
6991     return 1;
6992   if (vector_all_ones_operand (x, mode))
6993     {
6994       if (standard_sse_mode_p (mode))
6995         return TARGET_SSE2 ? 2 : -2;
6996       else if (VALID_AVX256_REG_MODE (mode))
6997         return TARGET_AVX ? 3 : -3;
6998     }
6999
7000   return 0;
7001 }
7002
7003 /* Return the opcode of the special instruction to be used to load
7004    the constant X.  */
7005
7006 const char *
7007 standard_sse_constant_opcode (rtx insn, rtx x)
7008 {
7009   switch (standard_sse_constant_p (x))
7010     {
7011     case 1:
7012       switch (get_attr_mode (insn))
7013         {
7014         case MODE_V4SF:
7015           return TARGET_AVX ? "vxorps\t%0, %0, %0" : "xorps\t%0, %0";
7016         case MODE_V2DF:
7017           return TARGET_AVX ? "vxorpd\t%0, %0, %0" : "xorpd\t%0, %0";
7018         case MODE_TI:
7019           return TARGET_AVX ? "vpxor\t%0, %0, %0" : "pxor\t%0, %0";
7020         case MODE_V8SF:
7021           return "vxorps\t%x0, %x0, %x0";
7022         case MODE_V4DF:
7023           return "vxorpd\t%x0, %x0, %x0";
7024         case MODE_OI:
7025           return "vpxor\t%x0, %x0, %x0";
7026         default:
7027           gcc_unreachable ();
7028         }
7029     case 2:
7030       if (TARGET_AVX)
7031         switch (get_attr_mode (insn))
7032           {
7033           case MODE_V4SF:
7034           case MODE_V2DF:
7035           case MODE_TI:
7036             return "vpcmpeqd\t%0, %0, %0";
7037             break;
7038           default:
7039             gcc_unreachable ();
7040         }
7041       else
7042         return "pcmpeqd\t%0, %0";
7043     }
7044   gcc_unreachable ();
7045 }
7046
7047 /* Returns 1 if OP contains a symbol reference */
7048
7049 int
7050 symbolic_reference_mentioned_p (rtx op)
7051 {
7052   const char *fmt;
7053   int i;
7054
7055   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
7056     return 1;
7057
7058   fmt = GET_RTX_FORMAT (GET_CODE (op));
7059   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
7060     {
7061       if (fmt[i] == 'E')
7062         {
7063           int j;
7064
7065           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
7066             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
7067               return 1;
7068         }
7069
7070       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
7071         return 1;
7072     }
7073
7074   return 0;
7075 }
7076
7077 /* Return 1 if it is appropriate to emit `ret' instructions in the
7078    body of a function.  Do this only if the epilogue is simple, needing a
7079    couple of insns.  Prior to reloading, we can't tell how many registers
7080    must be saved, so return 0 then.  Return 0 if there is no frame
7081    marker to de-allocate.  */
7082
7083 int
7084 ix86_can_use_return_insn_p (void)
7085 {
7086   struct ix86_frame frame;
7087
7088   if (! reload_completed || frame_pointer_needed)
7089     return 0;
7090
7091   /* Don't allow more than 32 pop, since that's all we can do
7092      with one instruction.  */
7093   if (crtl->args.pops_args
7094       && crtl->args.size >= 32768)
7095     return 0;
7096
7097   ix86_compute_frame_layout (&frame);
7098   return frame.to_allocate == 0 && frame.nregs == 0;
7099 }
7100 \f
7101 /* Value should be nonzero if functions must have frame pointers.
7102    Zero means the frame pointer need not be set up (and parms may
7103    be accessed via the stack pointer) in functions that seem suitable.  */
7104
7105 int
7106 ix86_frame_pointer_required (void)
7107 {
7108   /* If we accessed previous frames, then the generated code expects
7109      to be able to access the saved ebp value in our frame.  */
7110   if (cfun->machine->accesses_prev_frame)
7111     return 1;
7112
7113   /* Several x86 os'es need a frame pointer for other reasons,
7114      usually pertaining to setjmp.  */
7115   if (SUBTARGET_FRAME_POINTER_REQUIRED)
7116     return 1;
7117
7118   /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
7119      the frame pointer by default.  Turn it back on now if we've not
7120      got a leaf function.  */
7121   if (TARGET_OMIT_LEAF_FRAME_POINTER
7122       && (!current_function_is_leaf
7123           || ix86_current_function_calls_tls_descriptor))
7124     return 1;
7125
7126   if (crtl->profile)
7127     return 1;
7128
7129   return 0;
7130 }
7131
7132 /* Record that the current function accesses previous call frames.  */
7133
7134 void
7135 ix86_setup_frame_addresses (void)
7136 {
7137   cfun->machine->accesses_prev_frame = 1;
7138 }
7139 \f
7140 #if (defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)) || TARGET_MACHO
7141 # define USE_HIDDEN_LINKONCE 1
7142 #else
7143 # define USE_HIDDEN_LINKONCE 0
7144 #endif
7145
7146 static int pic_labels_used;
7147
7148 /* Fills in the label name that should be used for a pc thunk for
7149    the given register.  */
7150
7151 static void
7152 get_pc_thunk_name (char name[32], unsigned int regno)
7153 {
7154   gcc_assert (!TARGET_64BIT);
7155
7156   if (USE_HIDDEN_LINKONCE)
7157     sprintf (name, "__i686.get_pc_thunk.%s", reg_names[regno]);
7158   else
7159     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
7160 }
7161
7162
7163 /* This function generates code for -fpic that loads %ebx with
7164    the return address of the caller and then returns.  */
7165
7166 void
7167 ix86_file_end (void)
7168 {
7169   rtx xops[2];
7170   int regno;
7171
7172   for (regno = 0; regno < 8; ++regno)
7173     {
7174       char name[32];
7175
7176       if (! ((pic_labels_used >> regno) & 1))
7177         continue;
7178
7179       get_pc_thunk_name (name, regno);
7180
7181 #if TARGET_MACHO
7182       if (TARGET_MACHO)
7183         {
7184           switch_to_section (darwin_sections[text_coal_section]);
7185           fputs ("\t.weak_definition\t", asm_out_file);
7186           assemble_name (asm_out_file, name);
7187           fputs ("\n\t.private_extern\t", asm_out_file);
7188           assemble_name (asm_out_file, name);
7189           fputs ("\n", asm_out_file);
7190           ASM_OUTPUT_LABEL (asm_out_file, name);
7191         }
7192       else
7193 #endif
7194       if (USE_HIDDEN_LINKONCE)
7195         {
7196           tree decl;
7197
7198           decl = build_decl (FUNCTION_DECL, get_identifier (name),
7199                              error_mark_node);
7200           TREE_PUBLIC (decl) = 1;
7201           TREE_STATIC (decl) = 1;
7202           DECL_ONE_ONLY (decl) = 1;
7203
7204           (*targetm.asm_out.unique_section) (decl, 0);
7205           switch_to_section (get_named_section (decl, NULL, 0));
7206
7207           (*targetm.asm_out.globalize_label) (asm_out_file, name);
7208           fputs ("\t.hidden\t", asm_out_file);
7209           assemble_name (asm_out_file, name);
7210           fputc ('\n', asm_out_file);
7211           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
7212         }
7213       else
7214         {
7215           switch_to_section (text_section);
7216           ASM_OUTPUT_LABEL (asm_out_file, name);
7217         }
7218
7219       xops[0] = gen_rtx_REG (Pmode, regno);
7220       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
7221       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
7222       output_asm_insn ("ret", xops);
7223     }
7224
7225   if (NEED_INDICATE_EXEC_STACK)
7226     file_end_indicate_exec_stack ();
7227 }
7228
7229 /* Emit code for the SET_GOT patterns.  */
7230
7231 const char *
7232 output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
7233 {
7234   rtx xops[3];
7235
7236   xops[0] = dest;
7237
7238   if (TARGET_VXWORKS_RTP && flag_pic)
7239     {
7240       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
7241       xops[2] = gen_rtx_MEM (Pmode,
7242                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
7243       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
7244
7245       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
7246          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
7247          an unadorned address.  */
7248       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7249       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
7250       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
7251       return "";
7252     }
7253
7254   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
7255
7256   if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
7257     {
7258       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
7259
7260       if (!flag_pic)
7261         output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
7262       else
7263         output_asm_insn ("call\t%a2", xops);
7264
7265 #if TARGET_MACHO
7266       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7267          is what will be referenced by the Mach-O PIC subsystem.  */
7268       if (!label)
7269         ASM_OUTPUT_LABEL (asm_out_file, machopic_function_base_name ());
7270 #endif
7271
7272       (*targetm.asm_out.internal_label) (asm_out_file, "L",
7273                                  CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
7274
7275       if (flag_pic)
7276         output_asm_insn ("pop%z0\t%0", xops);
7277     }
7278   else
7279     {
7280       char name[32];
7281       get_pc_thunk_name (name, REGNO (dest));
7282       pic_labels_used |= 1 << REGNO (dest);
7283
7284       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
7285       xops[2] = gen_rtx_MEM (QImode, xops[2]);
7286       output_asm_insn ("call\t%X2", xops);
7287       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7288          is what will be referenced by the Mach-O PIC subsystem.  */
7289 #if TARGET_MACHO
7290       if (!label)
7291         ASM_OUTPUT_LABEL (asm_out_file, machopic_function_base_name ());
7292       else
7293         targetm.asm_out.internal_label (asm_out_file, "L",
7294                                            CODE_LABEL_NUMBER (label));
7295 #endif
7296     }
7297
7298   if (TARGET_MACHO)
7299     return "";
7300
7301   if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
7302     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
7303   else
7304     output_asm_insn ("add%z0\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
7305
7306   return "";
7307 }
7308
7309 /* Generate an "push" pattern for input ARG.  */
7310
7311 static rtx
7312 gen_push (rtx arg)
7313 {
7314   return gen_rtx_SET (VOIDmode,
7315                       gen_rtx_MEM (Pmode,
7316                                    gen_rtx_PRE_DEC (Pmode,
7317                                                     stack_pointer_rtx)),
7318                       arg);
7319 }
7320
7321 /* Return >= 0 if there is an unused call-clobbered register available
7322    for the entire function.  */
7323
7324 static unsigned int
7325 ix86_select_alt_pic_regnum (void)
7326 {
7327   if (current_function_is_leaf && !crtl->profile
7328       && !ix86_current_function_calls_tls_descriptor)
7329     {
7330       int i, drap;
7331       /* Can't use the same register for both PIC and DRAP.  */
7332       if (crtl->drap_reg)
7333         drap = REGNO (crtl->drap_reg);
7334       else
7335         drap = -1;
7336       for (i = 2; i >= 0; --i)
7337         if (i != drap && !df_regs_ever_live_p (i))
7338           return i;
7339     }
7340
7341   return INVALID_REGNUM;
7342 }
7343
7344 /* Return 1 if we need to save REGNO.  */
7345 static int
7346 ix86_save_reg (unsigned int regno, int maybe_eh_return)
7347 {
7348   if (pic_offset_table_rtx
7349       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
7350       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
7351           || crtl->profile
7352           || crtl->calls_eh_return
7353           || crtl->uses_const_pool))
7354     {
7355       if (ix86_select_alt_pic_regnum () != INVALID_REGNUM)
7356         return 0;
7357       return 1;
7358     }
7359
7360   if (crtl->calls_eh_return && maybe_eh_return)
7361     {
7362       unsigned i;
7363       for (i = 0; ; i++)
7364         {
7365           unsigned test = EH_RETURN_DATA_REGNO (i);
7366           if (test == INVALID_REGNUM)
7367             break;
7368           if (test == regno)
7369             return 1;
7370         }
7371     }
7372
7373   if (crtl->drap_reg
7374       && regno == REGNO (crtl->drap_reg))
7375     return 1;
7376
7377   return (df_regs_ever_live_p (regno)
7378           && !call_used_regs[regno]
7379           && !fixed_regs[regno]
7380           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
7381 }
7382
7383 /* Return number of registers to be saved on the stack.  */
7384
7385 static int
7386 ix86_nsaved_regs (void)
7387 {
7388   int nregs = 0;
7389   int regno;
7390
7391   for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
7392     if (ix86_save_reg (regno, true))
7393       nregs++;
7394   return nregs;
7395 }
7396
7397 /* Given FROM and TO register numbers, say whether this elimination is
7398    allowed.  If stack alignment is needed, we can only replace argument
7399    pointer with hard frame pointer, or replace frame pointer with stack
7400    pointer.  Otherwise, frame pointer elimination is automatically
7401    handled and all other eliminations are valid.  */
7402
7403 int
7404 ix86_can_eliminate (int from, int to)
7405 {
7406   if (stack_realign_fp)
7407     return ((from == ARG_POINTER_REGNUM
7408              && to == HARD_FRAME_POINTER_REGNUM)
7409             || (from == FRAME_POINTER_REGNUM
7410                 && to == STACK_POINTER_REGNUM));
7411   else
7412     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : 1;
7413 }
7414
7415 /* Return the offset between two registers, one to be eliminated, and the other
7416    its replacement, at the start of a routine.  */
7417
7418 HOST_WIDE_INT
7419 ix86_initial_elimination_offset (int from, int to)
7420 {
7421   struct ix86_frame frame;
7422   ix86_compute_frame_layout (&frame);
7423
7424   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
7425     return frame.hard_frame_pointer_offset;
7426   else if (from == FRAME_POINTER_REGNUM
7427            && to == HARD_FRAME_POINTER_REGNUM)
7428     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
7429   else
7430     {
7431       gcc_assert (to == STACK_POINTER_REGNUM);
7432
7433       if (from == ARG_POINTER_REGNUM)
7434         return frame.stack_pointer_offset;
7435
7436       gcc_assert (from == FRAME_POINTER_REGNUM);
7437       return frame.stack_pointer_offset - frame.frame_pointer_offset;
7438     }
7439 }
7440
7441 /* Fill structure ix86_frame about frame of currently computed function.  */
7442
7443 static void
7444 ix86_compute_frame_layout (struct ix86_frame *frame)
7445 {
7446   HOST_WIDE_INT total_size;
7447   unsigned int stack_alignment_needed;
7448   HOST_WIDE_INT offset;
7449   unsigned int preferred_alignment;
7450   HOST_WIDE_INT size = get_frame_size ();
7451
7452   frame->nregs = ix86_nsaved_regs ();
7453   total_size = size;
7454
7455   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
7456   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
7457
7458   gcc_assert (!size || stack_alignment_needed);
7459   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
7460   gcc_assert (preferred_alignment <= stack_alignment_needed);
7461
7462   /* During reload iteration the amount of registers saved can change.
7463      Recompute the value as needed.  Do not recompute when amount of registers
7464      didn't change as reload does multiple calls to the function and does not
7465      expect the decision to change within single iteration.  */
7466   if (!optimize_function_for_size_p (cfun)
7467       && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
7468     {
7469       int count = frame->nregs;
7470
7471       cfun->machine->use_fast_prologue_epilogue_nregs = count;
7472       /* The fast prologue uses move instead of push to save registers.  This
7473          is significantly longer, but also executes faster as modern hardware
7474          can execute the moves in parallel, but can't do that for push/pop.
7475
7476          Be careful about choosing what prologue to emit:  When function takes
7477          many instructions to execute we may use slow version as well as in
7478          case function is known to be outside hot spot (this is known with
7479          feedback only).  Weight the size of function by number of registers
7480          to save as it is cheap to use one or two push instructions but very
7481          slow to use many of them.  */
7482       if (count)
7483         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7484       if (cfun->function_frequency < FUNCTION_FREQUENCY_NORMAL
7485           || (flag_branch_probabilities
7486               && cfun->function_frequency < FUNCTION_FREQUENCY_HOT))
7487         cfun->machine->use_fast_prologue_epilogue = false;
7488       else
7489         cfun->machine->use_fast_prologue_epilogue
7490            = !expensive_function_p (count);
7491     }
7492   if (TARGET_PROLOGUE_USING_MOVE
7493       && cfun->machine->use_fast_prologue_epilogue)
7494     frame->save_regs_using_mov = true;
7495   else
7496     frame->save_regs_using_mov = false;
7497
7498
7499   /* Skip return address and saved base pointer.  */
7500   offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
7501
7502   frame->hard_frame_pointer_offset = offset;
7503
7504   /* Set offset to aligned because the realigned frame starts from
7505      here.  */
7506   if (stack_realign_fp)
7507     offset = (offset + stack_alignment_needed -1) & -stack_alignment_needed;
7508
7509   /* Register save area */
7510   offset += frame->nregs * UNITS_PER_WORD;
7511
7512   /* Va-arg area */
7513   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
7514   offset += frame->va_arg_size;
7515
7516   /* Align start of frame for local function.  */
7517   frame->padding1 = ((offset + stack_alignment_needed - 1)
7518                      & -stack_alignment_needed) - offset;
7519
7520   offset += frame->padding1;
7521
7522   /* Frame pointer points here.  */
7523   frame->frame_pointer_offset = offset;
7524
7525   offset += size;
7526
7527   /* Add outgoing arguments area.  Can be skipped if we eliminated
7528      all the function calls as dead code.
7529      Skipping is however impossible when function calls alloca.  Alloca
7530      expander assumes that last crtl->outgoing_args_size
7531      of stack frame are unused.  */
7532   if (ACCUMULATE_OUTGOING_ARGS
7533       && (!current_function_is_leaf || cfun->calls_alloca
7534           || ix86_current_function_calls_tls_descriptor))
7535     {
7536       offset += crtl->outgoing_args_size;
7537       frame->outgoing_arguments_size = crtl->outgoing_args_size;
7538     }
7539   else
7540     frame->outgoing_arguments_size = 0;
7541
7542   /* Align stack boundary.  Only needed if we're calling another function
7543      or using alloca.  */
7544   if (!current_function_is_leaf || cfun->calls_alloca
7545       || ix86_current_function_calls_tls_descriptor)
7546     frame->padding2 = ((offset + preferred_alignment - 1)
7547                        & -preferred_alignment) - offset;
7548   else
7549     frame->padding2 = 0;
7550
7551   offset += frame->padding2;
7552
7553   /* We've reached end of stack frame.  */
7554   frame->stack_pointer_offset = offset;
7555
7556   /* Size prologue needs to allocate.  */
7557   frame->to_allocate =
7558     (size + frame->padding1 + frame->padding2
7559      + frame->outgoing_arguments_size + frame->va_arg_size);
7560
7561   if ((!frame->to_allocate && frame->nregs <= 1)
7562       || (TARGET_64BIT && frame->to_allocate >= (HOST_WIDE_INT) 0x80000000))
7563     frame->save_regs_using_mov = false;
7564
7565   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && current_function_sp_is_unchanging
7566       && current_function_is_leaf
7567       && !ix86_current_function_calls_tls_descriptor)
7568     {
7569       frame->red_zone_size = frame->to_allocate;
7570       if (frame->save_regs_using_mov)
7571         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7572       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7573         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
7574     }
7575   else
7576     frame->red_zone_size = 0;
7577   frame->to_allocate -= frame->red_zone_size;
7578   frame->stack_pointer_offset -= frame->red_zone_size;
7579 #if 0
7580   fprintf (stderr, "\n");
7581   fprintf (stderr, "nregs: %ld\n", (long)frame->nregs);
7582   fprintf (stderr, "size: %ld\n", (long)size);
7583   fprintf (stderr, "alignment1: %ld\n", (long)stack_alignment_needed);
7584   fprintf (stderr, "padding1: %ld\n", (long)frame->padding1);
7585   fprintf (stderr, "va_arg: %ld\n", (long)frame->va_arg_size);
7586   fprintf (stderr, "padding2: %ld\n", (long)frame->padding2);
7587   fprintf (stderr, "to_allocate: %ld\n", (long)frame->to_allocate);
7588   fprintf (stderr, "red_zone_size: %ld\n", (long)frame->red_zone_size);
7589   fprintf (stderr, "frame_pointer_offset: %ld\n", (long)frame->frame_pointer_offset);
7590   fprintf (stderr, "hard_frame_pointer_offset: %ld\n",
7591            (long)frame->hard_frame_pointer_offset);
7592   fprintf (stderr, "stack_pointer_offset: %ld\n", (long)frame->stack_pointer_offset);
7593   fprintf (stderr, "current_function_is_leaf: %ld\n", (long)current_function_is_leaf);
7594   fprintf (stderr, "cfun->calls_alloca: %ld\n", (long)cfun->calls_alloca);
7595   fprintf (stderr, "x86_current_function_calls_tls_descriptor: %ld\n", (long)ix86_current_function_calls_tls_descriptor);
7596 #endif
7597 }
7598
7599 /* Emit code to save registers in the prologue.  */
7600
7601 static void
7602 ix86_emit_save_regs (void)
7603 {
7604   unsigned int regno;
7605   rtx insn;
7606
7607   for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0; )
7608     if (ix86_save_reg (regno, true))
7609       {
7610         insn = emit_insn (gen_push (gen_rtx_REG (Pmode, regno)));
7611         RTX_FRAME_RELATED_P (insn) = 1;
7612       }
7613 }
7614
7615 /* Emit code to save registers using MOV insns.  First register
7616    is restored from POINTER + OFFSET.  */
7617 static void
7618 ix86_emit_save_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7619 {
7620   unsigned int regno;
7621   rtx insn;
7622
7623   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7624     if (ix86_save_reg (regno, true))
7625       {
7626         insn = emit_move_insn (adjust_address (gen_rtx_MEM (Pmode, pointer),
7627                                                Pmode, offset),
7628                                gen_rtx_REG (Pmode, regno));
7629         RTX_FRAME_RELATED_P (insn) = 1;
7630         offset += UNITS_PER_WORD;
7631       }
7632 }
7633
7634 /* Expand prologue or epilogue stack adjustment.
7635    The pattern exist to put a dependency on all ebp-based memory accesses.
7636    STYLE should be negative if instructions should be marked as frame related,
7637    zero if %r11 register is live and cannot be freely used and positive
7638    otherwise.  */
7639
7640 static void
7641 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset, int style)
7642 {
7643   rtx insn;
7644
7645   if (! TARGET_64BIT)
7646     insn = emit_insn (gen_pro_epilogue_adjust_stack_1 (dest, src, offset));
7647   else if (x86_64_immediate_operand (offset, DImode))
7648     insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64 (dest, src, offset));
7649   else
7650     {
7651       rtx r11;
7652       /* r11 is used by indirect sibcall return as well, set before the
7653          epilogue and used after the epilogue.  ATM indirect sibcall
7654          shouldn't be used together with huge frame sizes in one
7655          function because of the frame_size check in sibcall.c.  */
7656       gcc_assert (style);
7657       r11 = gen_rtx_REG (DImode, R11_REG);
7658       insn = emit_insn (gen_rtx_SET (DImode, r11, offset));
7659       if (style < 0)
7660         RTX_FRAME_RELATED_P (insn) = 1;
7661       insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64_2 (dest, src, r11,
7662                                                                offset));
7663     }
7664   if (style < 0)
7665     RTX_FRAME_RELATED_P (insn) = 1;
7666 }
7667
7668 /* Find an available register to be used as dynamic realign argument
7669    pointer regsiter.  Such a register will be written in prologue and
7670    used in begin of body, so it must not be
7671         1. parameter passing register.
7672         2. GOT pointer.
7673    We reuse static-chain register if it is available.  Otherwise, we
7674    use DI for i386 and R13 for x86-64.  We chose R13 since it has
7675    shorter encoding.
7676
7677    Return: the regno of chosen register.  */
7678
7679 static unsigned int 
7680 find_drap_reg (void)
7681 {
7682   tree decl = cfun->decl;
7683
7684   if (TARGET_64BIT)
7685     {
7686       /* Use R13 for nested function or function need static chain.
7687          Since function with tail call may use any caller-saved
7688          registers in epilogue, DRAP must not use caller-saved
7689          register in such case.  */
7690       if ((decl_function_context (decl)
7691            && !DECL_NO_STATIC_CHAIN (decl))
7692           || crtl->tail_call_emit)
7693         return R13_REG;
7694
7695       return R10_REG;
7696     }
7697   else
7698     {
7699       /* Use DI for nested function or function need static chain.
7700          Since function with tail call may use any caller-saved
7701          registers in epilogue, DRAP must not use caller-saved
7702          register in such case.  */
7703       if ((decl_function_context (decl)
7704            && !DECL_NO_STATIC_CHAIN (decl))
7705           || crtl->tail_call_emit)
7706         return DI_REG;
7707     
7708       /* Reuse static chain register if it isn't used for parameter
7709          passing.  */
7710       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2
7711           && !lookup_attribute ("fastcall",
7712                                 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
7713         return CX_REG;
7714       else
7715         return DI_REG;
7716     }
7717 }
7718
7719 /* Update incoming stack boundary and estimated stack alignment.  */
7720
7721 static void
7722 ix86_update_stack_boundary (void)
7723 {
7724   /* Prefer the one specified at command line. */
7725   ix86_incoming_stack_boundary 
7726     = (ix86_user_incoming_stack_boundary
7727        ? ix86_user_incoming_stack_boundary
7728        : ix86_default_incoming_stack_boundary);
7729
7730   /* Incoming stack alignment can be changed on individual functions
7731      via force_align_arg_pointer attribute.  We use the smallest
7732      incoming stack boundary.  */
7733   if (ix86_incoming_stack_boundary > MIN_STACK_BOUNDARY
7734       && lookup_attribute (ix86_force_align_arg_pointer_string,
7735                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
7736     ix86_incoming_stack_boundary = MIN_STACK_BOUNDARY;
7737
7738   /* Stack at entrance of main is aligned by runtime.  We use the
7739      smallest incoming stack boundary. */
7740   if (ix86_incoming_stack_boundary > MAIN_STACK_BOUNDARY
7741       && DECL_NAME (current_function_decl)
7742       && MAIN_NAME_P (DECL_NAME (current_function_decl))
7743       && DECL_FILE_SCOPE_P (current_function_decl))
7744     ix86_incoming_stack_boundary = MAIN_STACK_BOUNDARY;
7745
7746   /* x86_64 vararg needs 16byte stack alignment for register save
7747      area.  */
7748   if (TARGET_64BIT
7749       && cfun->stdarg
7750       && crtl->stack_alignment_estimated < 128)
7751     crtl->stack_alignment_estimated = 128;
7752 }
7753
7754 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
7755    needed or an rtx for DRAP otherwise.  */
7756
7757 static rtx
7758 ix86_get_drap_rtx (void)
7759 {
7760   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
7761     crtl->need_drap = true;
7762
7763   if (stack_realign_drap)
7764     {
7765       /* Assign DRAP to vDRAP and returns vDRAP */
7766       unsigned int regno = find_drap_reg ();
7767       rtx drap_vreg;
7768       rtx arg_ptr;
7769       rtx seq, insn;
7770
7771       arg_ptr = gen_rtx_REG (Pmode, regno);
7772       crtl->drap_reg = arg_ptr;
7773
7774       start_sequence ();
7775       drap_vreg = copy_to_reg (arg_ptr);
7776       seq = get_insns ();
7777       end_sequence ();
7778       
7779       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
7780       RTX_FRAME_RELATED_P (insn) = 1;
7781       return drap_vreg;
7782     }
7783   else
7784     return NULL;
7785 }
7786
7787 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
7788
7789 static rtx
7790 ix86_internal_arg_pointer (void)
7791 {
7792   return virtual_incoming_args_rtx;
7793 }
7794
7795 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
7796    This is called from dwarf2out.c to emit call frame instructions
7797    for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
7798 static void
7799 ix86_dwarf_handle_frame_unspec (const char *label, rtx pattern, int index)
7800 {
7801   rtx unspec = SET_SRC (pattern);
7802   gcc_assert (GET_CODE (unspec) == UNSPEC);
7803
7804   switch (index)
7805     {
7806     case UNSPEC_REG_SAVE:
7807       dwarf2out_reg_save_reg (label, XVECEXP (unspec, 0, 0),
7808                               SET_DEST (pattern));
7809       break;
7810     case UNSPEC_DEF_CFA:
7811       dwarf2out_def_cfa (label, REGNO (SET_DEST (pattern)),
7812                          INTVAL (XVECEXP (unspec, 0, 0)));
7813       break;
7814     default:
7815       gcc_unreachable ();
7816     }
7817 }
7818
7819 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
7820    to be generated in correct form.  */
7821 static void 
7822 ix86_finalize_stack_realign_flags (void)
7823 {
7824   /* Check if stack realign is really needed after reload, and 
7825      stores result in cfun */
7826   unsigned int incoming_stack_boundary
7827     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
7828        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
7829   unsigned int stack_realign = (incoming_stack_boundary
7830                                 < (current_function_is_leaf
7831                                    ? crtl->max_used_stack_slot_alignment
7832                                    : crtl->stack_alignment_needed));
7833
7834   if (crtl->stack_realign_finalized)
7835     {
7836       /* After stack_realign_needed is finalized, we can't no longer
7837          change it.  */
7838       gcc_assert (crtl->stack_realign_needed == stack_realign);
7839     }
7840   else
7841     {
7842       crtl->stack_realign_needed = stack_realign;
7843       crtl->stack_realign_finalized = true;
7844     }
7845 }
7846
7847 /* Expand the prologue into a bunch of separate insns.  */
7848
7849 void
7850 ix86_expand_prologue (void)
7851 {
7852   rtx insn;
7853   bool pic_reg_used;
7854   struct ix86_frame frame;
7855   HOST_WIDE_INT allocate;
7856
7857   ix86_finalize_stack_realign_flags ();
7858
7859   /* DRAP should not coexist with stack_realign_fp */
7860   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
7861
7862   ix86_compute_frame_layout (&frame);
7863
7864   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
7865      of DRAP is needed and stack realignment is really needed after reload */
7866   if (crtl->drap_reg && crtl->stack_realign_needed)
7867     {
7868       rtx x, y;
7869       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
7870       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
7871                               ? 0 : UNITS_PER_WORD);
7872
7873       gcc_assert (stack_realign_drap);
7874
7875       /* Grab the argument pointer.  */
7876       x = plus_constant (stack_pointer_rtx, 
7877                          (UNITS_PER_WORD + param_ptr_offset));
7878       y = crtl->drap_reg;
7879
7880       /* Only need to push parameter pointer reg if it is caller
7881          saved reg */
7882       if (!call_used_regs[REGNO (crtl->drap_reg)])
7883         {
7884           /* Push arg pointer reg */
7885           insn = emit_insn (gen_push (y));
7886           RTX_FRAME_RELATED_P (insn) = 1;
7887         }
7888
7889       insn = emit_insn (gen_rtx_SET (VOIDmode, y, x));
7890       RTX_FRAME_RELATED_P (insn) = 1; 
7891
7892       /* Align the stack.  */
7893       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
7894                                            stack_pointer_rtx,
7895                                            GEN_INT (-align_bytes)));
7896       RTX_FRAME_RELATED_P (insn) = 1;
7897
7898       /* Replicate the return address on the stack so that return
7899          address can be reached via (argp - 1) slot.  This is needed
7900          to implement macro RETURN_ADDR_RTX and intrinsic function
7901          expand_builtin_return_addr etc.  */
7902       x = crtl->drap_reg;
7903       x = gen_frame_mem (Pmode,
7904                          plus_constant (x, -UNITS_PER_WORD));
7905       insn = emit_insn (gen_push (x));
7906       RTX_FRAME_RELATED_P (insn) = 1;
7907     }
7908
7909   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
7910      slower on all targets.  Also sdb doesn't like it.  */
7911
7912   if (frame_pointer_needed)
7913     {
7914       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
7915       RTX_FRAME_RELATED_P (insn) = 1;
7916
7917       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
7918       RTX_FRAME_RELATED_P (insn) = 1;
7919     }
7920
7921   if (stack_realign_fp)
7922     {
7923       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
7924       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
7925
7926       /* Align the stack.  */
7927       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
7928                                            stack_pointer_rtx,
7929                                            GEN_INT (-align_bytes)));
7930       RTX_FRAME_RELATED_P (insn) = 1;
7931     }
7932
7933   allocate = frame.to_allocate;
7934
7935   if (!frame.save_regs_using_mov)
7936     ix86_emit_save_regs ();
7937   else
7938     allocate += frame.nregs * UNITS_PER_WORD;
7939
7940   /* When using red zone we may start register saving before allocating
7941      the stack frame saving one cycle of the prologue. However I will
7942      avoid doing this if I am going to have to probe the stack since
7943      at least on x86_64 the stack probe can turn into a call that clobbers
7944      a red zone location */
7945   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && frame.save_regs_using_mov
7946       && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT))
7947     ix86_emit_save_regs_using_mov ((frame_pointer_needed
7948                                      && !crtl->stack_realign_needed) 
7949                                    ? hard_frame_pointer_rtx
7950                                    : stack_pointer_rtx,
7951                                    -frame.nregs * UNITS_PER_WORD);
7952
7953   if (allocate == 0)
7954     ;
7955   else if (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)
7956     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
7957                                GEN_INT (-allocate), -1);
7958   else
7959     {
7960       /* Only valid for Win32.  */
7961       rtx eax = gen_rtx_REG (Pmode, AX_REG);
7962       bool eax_live;
7963       rtx t;
7964
7965       gcc_assert (!TARGET_64BIT || cfun->machine->call_abi == MS_ABI);
7966
7967       if (cfun->machine->call_abi == MS_ABI)
7968         eax_live = false;
7969       else
7970         eax_live = ix86_eax_live_at_start_p ();
7971
7972       if (eax_live)
7973         {
7974           emit_insn (gen_push (eax));
7975           allocate -= UNITS_PER_WORD;
7976         }
7977
7978       emit_move_insn (eax, GEN_INT (allocate));
7979
7980       if (TARGET_64BIT)
7981         insn = gen_allocate_stack_worker_64 (eax);
7982       else
7983         insn = gen_allocate_stack_worker_32 (eax);
7984       insn = emit_insn (insn);
7985       RTX_FRAME_RELATED_P (insn) = 1;
7986       t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (-allocate));
7987       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
7988       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7989                                             t, REG_NOTES (insn));
7990
7991       if (eax_live)
7992         {
7993           if (frame_pointer_needed)
7994             t = plus_constant (hard_frame_pointer_rtx,
7995                                allocate
7996                                - frame.to_allocate
7997                                - frame.nregs * UNITS_PER_WORD);
7998           else
7999             t = plus_constant (stack_pointer_rtx, allocate);
8000           emit_move_insn (eax, gen_rtx_MEM (Pmode, t));
8001         }
8002     }
8003
8004   if (frame.save_regs_using_mov
8005       && !(!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
8006          && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)))
8007     {
8008       if (!frame_pointer_needed
8009           || !frame.to_allocate
8010           || crtl->stack_realign_needed)
8011         ix86_emit_save_regs_using_mov (stack_pointer_rtx,
8012                                        frame.to_allocate);
8013       else
8014         ix86_emit_save_regs_using_mov (hard_frame_pointer_rtx,
8015                                        -frame.nregs * UNITS_PER_WORD);
8016     }
8017
8018   pic_reg_used = false;
8019   if (pic_offset_table_rtx
8020       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
8021           || crtl->profile))
8022     {
8023       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
8024
8025       if (alt_pic_reg_used != INVALID_REGNUM)
8026         SET_REGNO (pic_offset_table_rtx, alt_pic_reg_used);
8027
8028       pic_reg_used = true;
8029     }
8030
8031   if (pic_reg_used)
8032     {
8033       if (TARGET_64BIT)
8034         {
8035           if (ix86_cmodel == CM_LARGE_PIC)
8036             {
8037               rtx tmp_reg = gen_rtx_REG (DImode, R11_REG);
8038               rtx label = gen_label_rtx ();
8039               emit_label (label);
8040               LABEL_PRESERVE_P (label) = 1;
8041               gcc_assert (REGNO (pic_offset_table_rtx) != REGNO (tmp_reg));
8042               insn = emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, label));
8043               insn = emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
8044               insn = emit_insn (gen_adddi3 (pic_offset_table_rtx,
8045                                             pic_offset_table_rtx, tmp_reg));
8046             }
8047           else
8048             insn = emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
8049         }
8050       else
8051         insn = emit_insn (gen_set_got (pic_offset_table_rtx));
8052     }
8053
8054   /* Prevent function calls from being scheduled before the call to mcount.
8055      In the pic_reg_used case, make sure that the got load isn't deleted.  */
8056   if (crtl->profile)
8057     {
8058       if (pic_reg_used)
8059         emit_insn (gen_prologue_use (pic_offset_table_rtx));
8060       emit_insn (gen_blockage ());
8061     }
8062
8063   if (crtl->drap_reg && !crtl->stack_realign_needed)
8064     {
8065       /* vDRAP is setup but after reload it turns out stack realign
8066          isn't necessary, here we will emit prologue to setup DRAP
8067          without stack realign adjustment */
8068       int drap_bp_offset = UNITS_PER_WORD * 2;
8069       rtx x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
8070       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, x));
8071     }
8072
8073   /* Emit cld instruction if stringops are used in the function.  */
8074   if (TARGET_CLD && ix86_current_function_needs_cld)
8075     emit_insn (gen_cld ());
8076 }
8077
8078 /* Emit code to restore saved registers using MOV insns.  First register
8079    is restored from POINTER + OFFSET.  */
8080 static void
8081 ix86_emit_restore_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8082                                   int maybe_eh_return)
8083 {
8084   int regno;
8085   rtx base_address = gen_rtx_MEM (Pmode, pointer);
8086
8087   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8088     if (ix86_save_reg (regno, maybe_eh_return))
8089       {
8090         /* Ensure that adjust_address won't be forced to produce pointer
8091            out of range allowed by x86-64 instruction set.  */
8092         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8093           {
8094             rtx r11;
8095
8096             r11 = gen_rtx_REG (DImode, R11_REG);
8097             emit_move_insn (r11, GEN_INT (offset));
8098             emit_insn (gen_adddi3 (r11, r11, pointer));
8099             base_address = gen_rtx_MEM (Pmode, r11);
8100             offset = 0;
8101           }
8102         emit_move_insn (gen_rtx_REG (Pmode, regno),
8103                         adjust_address (base_address, Pmode, offset));
8104         offset += UNITS_PER_WORD;
8105       }
8106 }
8107
8108 /* Restore function stack, frame, and registers.  */
8109
8110 void
8111 ix86_expand_epilogue (int style)
8112 {
8113   int regno;
8114   int sp_valid;
8115   struct ix86_frame frame;
8116   HOST_WIDE_INT offset;
8117
8118   ix86_finalize_stack_realign_flags ();
8119
8120  /* When stack is realigned, SP must be valid.  */
8121   sp_valid = (!frame_pointer_needed
8122               || current_function_sp_is_unchanging
8123               || stack_realign_fp);
8124
8125   ix86_compute_frame_layout (&frame);
8126
8127   /* Calculate start of saved registers relative to ebp.  Special care
8128      must be taken for the normal return case of a function using
8129      eh_return: the eax and edx registers are marked as saved, but not
8130      restored along this path.  */
8131   offset = frame.nregs;
8132   if (crtl->calls_eh_return && style != 2)
8133     offset -= 2;
8134   offset *= -UNITS_PER_WORD;
8135
8136   /* If we're only restoring one register and sp is not valid then
8137      using a move instruction to restore the register since it's
8138      less work than reloading sp and popping the register.
8139
8140      The default code result in stack adjustment using add/lea instruction,
8141      while this code results in LEAVE instruction (or discrete equivalent),
8142      so it is profitable in some other cases as well.  Especially when there
8143      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
8144      and there is exactly one register to pop. This heuristic may need some
8145      tuning in future.  */
8146   if ((!sp_valid && frame.nregs <= 1)
8147       || (TARGET_EPILOGUE_USING_MOVE
8148           && cfun->machine->use_fast_prologue_epilogue
8149           && (frame.nregs > 1 || frame.to_allocate))
8150       || (frame_pointer_needed && !frame.nregs && frame.to_allocate)
8151       || (frame_pointer_needed && TARGET_USE_LEAVE
8152           && cfun->machine->use_fast_prologue_epilogue
8153           && frame.nregs == 1)
8154       || crtl->calls_eh_return)
8155     {
8156       /* Restore registers.  We can use ebp or esp to address the memory
8157          locations.  If both are available, default to ebp, since offsets
8158          are known to be small.  Only exception is esp pointing directly
8159          to the end of block of saved registers, where we may simplify
8160          addressing mode.  
8161
8162          If we are realigning stack with bp and sp, regs restore can't
8163          be addressed by bp. sp must be used instead.  */
8164
8165       if (!frame_pointer_needed
8166           || (sp_valid && !frame.to_allocate) 
8167           || stack_realign_fp)
8168         ix86_emit_restore_regs_using_mov (stack_pointer_rtx,
8169                                           frame.to_allocate, style == 2);
8170       else
8171         ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx,
8172                                           offset, style == 2);
8173
8174       /* eh_return epilogues need %ecx added to the stack pointer.  */
8175       if (style == 2)
8176         {
8177           rtx tmp, sa = EH_RETURN_STACKADJ_RTX;
8178
8179           /* Stack align doesn't work with eh_return.  */
8180           gcc_assert (!crtl->stack_realign_needed);
8181
8182           if (frame_pointer_needed)
8183             {
8184               tmp = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
8185               tmp = plus_constant (tmp, UNITS_PER_WORD);
8186               emit_insn (gen_rtx_SET (VOIDmode, sa, tmp));
8187
8188               tmp = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
8189               emit_move_insn (hard_frame_pointer_rtx, tmp);
8190
8191               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
8192                                          const0_rtx, style);
8193             }
8194           else
8195             {
8196               tmp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
8197               tmp = plus_constant (tmp, (frame.to_allocate
8198                                          + frame.nregs * UNITS_PER_WORD));
8199               emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp));
8200             }
8201         }
8202       else if (!frame_pointer_needed)
8203         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8204                                    GEN_INT (frame.to_allocate
8205                                             + frame.nregs * UNITS_PER_WORD),
8206                                    style);
8207       /* If not an i386, mov & pop is faster than "leave".  */
8208       else if (TARGET_USE_LEAVE || optimize_function_for_size_p (cfun)
8209                || !cfun->machine->use_fast_prologue_epilogue)
8210         emit_insn ((*ix86_gen_leave) ());
8211       else
8212         {
8213           pro_epilogue_adjust_stack (stack_pointer_rtx,
8214                                      hard_frame_pointer_rtx,
8215                                      const0_rtx, style);
8216
8217           emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8218         }
8219     }
8220   else
8221     {
8222       /* First step is to deallocate the stack frame so that we can
8223          pop the registers.
8224
8225          If we realign stack with frame pointer, then stack pointer
8226          won't be able to recover via lea $offset(%bp), %sp, because
8227          there is a padding area between bp and sp for realign. 
8228          "add $to_allocate, %sp" must be used instead.  */
8229       if (!sp_valid)
8230         {
8231           gcc_assert (frame_pointer_needed);
8232           gcc_assert (!stack_realign_fp);
8233           pro_epilogue_adjust_stack (stack_pointer_rtx,
8234                                      hard_frame_pointer_rtx,
8235                                      GEN_INT (offset), style);
8236         }
8237       else if (frame.to_allocate)
8238         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8239                                    GEN_INT (frame.to_allocate), style);
8240
8241       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8242         if (ix86_save_reg (regno, false))
8243           emit_insn ((*ix86_gen_pop1) (gen_rtx_REG (Pmode, regno)));
8244       if (frame_pointer_needed)
8245         {
8246           /* Leave results in shorter dependency chains on CPUs that are
8247              able to grok it fast.  */
8248           if (TARGET_USE_LEAVE)
8249             emit_insn ((*ix86_gen_leave) ());
8250           else
8251             {
8252               /* For stack realigned really happens, recover stack 
8253                  pointer to hard frame pointer is a must, if not using 
8254                  leave.  */
8255               if (stack_realign_fp)
8256                 pro_epilogue_adjust_stack (stack_pointer_rtx,
8257                                            hard_frame_pointer_rtx,
8258                                            const0_rtx, style);
8259               emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8260             }
8261         }
8262     }
8263
8264   if (crtl->drap_reg && crtl->stack_realign_needed)
8265     {
8266       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8267                               ? 0 : UNITS_PER_WORD);
8268       gcc_assert (stack_realign_drap);
8269       emit_insn ((*ix86_gen_add3) (stack_pointer_rtx,
8270                                    crtl->drap_reg,
8271                                    GEN_INT (-(UNITS_PER_WORD
8272                                               + param_ptr_offset))));
8273       if (!call_used_regs[REGNO (crtl->drap_reg)])
8274         emit_insn ((*ix86_gen_pop1) (crtl->drap_reg));
8275       
8276     }
8277
8278   /* Sibcall epilogues don't want a return instruction.  */
8279   if (style == 0)
8280     return;
8281
8282   if (crtl->args.pops_args && crtl->args.size)
8283     {
8284       rtx popc = GEN_INT (crtl->args.pops_args);
8285
8286       /* i386 can only pop 64K bytes.  If asked to pop more, pop
8287          return address, do explicit add, and jump indirectly to the
8288          caller.  */
8289
8290       if (crtl->args.pops_args >= 65536)
8291         {
8292           rtx ecx = gen_rtx_REG (SImode, CX_REG);
8293
8294           /* There is no "pascal" calling convention in any 64bit ABI.  */
8295           gcc_assert (!TARGET_64BIT);
8296
8297           emit_insn (gen_popsi1 (ecx));
8298           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc));
8299           emit_jump_insn (gen_return_indirect_internal (ecx));
8300         }
8301       else
8302         emit_jump_insn (gen_return_pop_internal (popc));
8303     }
8304   else
8305     emit_jump_insn (gen_return_internal ());
8306 }
8307
8308 /* Reset from the function's potential modifications.  */
8309
8310 static void
8311 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
8312                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
8313 {
8314   if (pic_offset_table_rtx)
8315     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
8316 #if TARGET_MACHO
8317   /* Mach-O doesn't support labels at the end of objects, so if
8318      it looks like we might want one, insert a NOP.  */
8319   {
8320     rtx insn = get_last_insn ();
8321     while (insn
8322            && NOTE_P (insn)
8323            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
8324       insn = PREV_INSN (insn);
8325     if (insn
8326         && (LABEL_P (insn)
8327             || (NOTE_P (insn)
8328                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
8329       fputs ("\tnop\n", file);
8330   }
8331 #endif
8332
8333 }
8334 \f
8335 /* Extract the parts of an RTL expression that is a valid memory address
8336    for an instruction.  Return 0 if the structure of the address is
8337    grossly off.  Return -1 if the address contains ASHIFT, so it is not
8338    strictly valid, but still used for computing length of lea instruction.  */
8339
8340 int
8341 ix86_decompose_address (rtx addr, struct ix86_address *out)
8342 {
8343   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
8344   rtx base_reg, index_reg;
8345   HOST_WIDE_INT scale = 1;
8346   rtx scale_rtx = NULL_RTX;
8347   int retval = 1;
8348   enum ix86_address_seg seg = SEG_DEFAULT;
8349
8350   if (REG_P (addr) || GET_CODE (addr) == SUBREG)
8351     base = addr;
8352   else if (GET_CODE (addr) == PLUS)
8353     {
8354       rtx addends[4], op;
8355       int n = 0, i;
8356
8357       op = addr;
8358       do
8359         {
8360           if (n >= 4)
8361             return 0;
8362           addends[n++] = XEXP (op, 1);
8363           op = XEXP (op, 0);
8364         }
8365       while (GET_CODE (op) == PLUS);
8366       if (n >= 4)
8367         return 0;
8368       addends[n] = op;
8369
8370       for (i = n; i >= 0; --i)
8371         {
8372           op = addends[i];
8373           switch (GET_CODE (op))
8374             {
8375             case MULT:
8376               if (index)
8377                 return 0;
8378               index = XEXP (op, 0);
8379               scale_rtx = XEXP (op, 1);
8380               break;
8381
8382             case UNSPEC:
8383               if (XINT (op, 1) == UNSPEC_TP
8384                   && TARGET_TLS_DIRECT_SEG_REFS
8385                   && seg == SEG_DEFAULT)
8386                 seg = TARGET_64BIT ? SEG_FS : SEG_GS;
8387               else
8388                 return 0;
8389               break;
8390
8391             case REG:
8392             case SUBREG:
8393               if (!base)
8394                 base = op;
8395               else if (!index)
8396                 index = op;
8397               else
8398                 return 0;
8399               break;
8400
8401             case CONST:
8402             case CONST_INT:
8403             case SYMBOL_REF:
8404             case LABEL_REF:
8405               if (disp)
8406                 return 0;
8407               disp = op;
8408               break;
8409
8410             default:
8411               return 0;
8412             }
8413         }
8414     }
8415   else if (GET_CODE (addr) == MULT)
8416     {
8417       index = XEXP (addr, 0);           /* index*scale */
8418       scale_rtx = XEXP (addr, 1);
8419     }
8420   else if (GET_CODE (addr) == ASHIFT)
8421     {
8422       rtx tmp;
8423
8424       /* We're called for lea too, which implements ashift on occasion.  */
8425       index = XEXP (addr, 0);
8426       tmp = XEXP (addr, 1);
8427       if (!CONST_INT_P (tmp))
8428         return 0;
8429       scale = INTVAL (tmp);
8430       if ((unsigned HOST_WIDE_INT) scale > 3)
8431         return 0;
8432       scale = 1 << scale;
8433       retval = -1;
8434     }
8435   else
8436     disp = addr;                        /* displacement */
8437
8438   /* Extract the integral value of scale.  */
8439   if (scale_rtx)
8440     {
8441       if (!CONST_INT_P (scale_rtx))
8442         return 0;
8443       scale = INTVAL (scale_rtx);
8444     }
8445
8446   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
8447   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
8448
8449   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
8450   if (base_reg && index_reg && scale == 1
8451       && (index_reg == arg_pointer_rtx
8452           || index_reg == frame_pointer_rtx
8453           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
8454     {
8455       rtx tmp;
8456       tmp = base, base = index, index = tmp;
8457       tmp = base_reg, base_reg = index_reg, index_reg = tmp;
8458     }
8459
8460   /* Special case: %ebp cannot be encoded as a base without a displacement.  */
8461   if ((base_reg == hard_frame_pointer_rtx
8462        || base_reg == frame_pointer_rtx
8463        || base_reg == arg_pointer_rtx) && !disp)
8464     disp = const0_rtx;
8465
8466   /* Special case: on K6, [%esi] makes the instruction vector decoded.
8467      Avoid this by transforming to [%esi+0].
8468      Reload calls address legitimization without cfun defined, so we need
8469      to test cfun for being non-NULL. */
8470   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
8471       && base_reg && !index_reg && !disp
8472       && REG_P (base_reg)
8473       && REGNO_REG_CLASS (REGNO (base_reg)) == SIREG)
8474     disp = const0_rtx;
8475
8476   /* Special case: encode reg+reg instead of reg*2.  */
8477   if (!base && index && scale && scale == 2)
8478     base = index, base_reg = index_reg, scale = 1;
8479
8480   /* Special case: scaling cannot be encoded without base or displacement.  */
8481   if (!base && !disp && index && scale != 1)
8482     disp = const0_rtx;
8483
8484   out->base = base;
8485   out->index = index;
8486   out->disp = disp;
8487   out->scale = scale;
8488   out->seg = seg;
8489
8490   return retval;
8491 }
8492 \f
8493 /* Return cost of the memory address x.
8494    For i386, it is better to use a complex address than let gcc copy
8495    the address into a reg and make a new pseudo.  But not if the address
8496    requires to two regs - that would mean more pseudos with longer
8497    lifetimes.  */
8498 static int
8499 ix86_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
8500 {
8501   struct ix86_address parts;
8502   int cost = 1;
8503   int ok = ix86_decompose_address (x, &parts);
8504
8505   gcc_assert (ok);
8506
8507   if (parts.base && GET_CODE (parts.base) == SUBREG)
8508     parts.base = SUBREG_REG (parts.base);
8509   if (parts.index && GET_CODE (parts.index) == SUBREG)
8510     parts.index = SUBREG_REG (parts.index);
8511
8512   /* Attempt to minimize number of registers in the address.  */
8513   if ((parts.base
8514        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
8515       || (parts.index
8516           && (!REG_P (parts.index)
8517               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
8518     cost++;
8519
8520   if (parts.base
8521       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
8522       && parts.index
8523       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
8524       && parts.base != parts.index)
8525     cost++;
8526
8527   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
8528      since it's predecode logic can't detect the length of instructions
8529      and it degenerates to vector decoded.  Increase cost of such
8530      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
8531      to split such addresses or even refuse such addresses at all.
8532
8533      Following addressing modes are affected:
8534       [base+scale*index]
8535       [scale*index+disp]
8536       [base+index]
8537
8538      The first and last case  may be avoidable by explicitly coding the zero in
8539      memory address, but I don't have AMD-K6 machine handy to check this
8540      theory.  */
8541
8542   if (TARGET_K6
8543       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
8544           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
8545           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
8546     cost += 10;
8547
8548   return cost;
8549 }
8550 \f
8551 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
8552    this is used for to form addresses to local data when -fPIC is in
8553    use.  */
8554
8555 static bool
8556 darwin_local_data_pic (rtx disp)
8557 {
8558   if (GET_CODE (disp) == MINUS)
8559     {
8560       if (GET_CODE (XEXP (disp, 0)) == LABEL_REF
8561           || GET_CODE (XEXP (disp, 0)) == SYMBOL_REF)
8562         if (GET_CODE (XEXP (disp, 1)) == SYMBOL_REF)
8563           {
8564             const char *sym_name = XSTR (XEXP (disp, 1), 0);
8565             if (! strcmp (sym_name, "<pic base>"))
8566               return true;
8567           }
8568     }
8569
8570   return false;
8571 }
8572
8573 /* Determine if a given RTX is a valid constant.  We already know this
8574    satisfies CONSTANT_P.  */
8575
8576 bool
8577 legitimate_constant_p (rtx x)
8578 {
8579   switch (GET_CODE (x))
8580     {
8581     case CONST:
8582       x = XEXP (x, 0);
8583
8584       if (GET_CODE (x) == PLUS)
8585         {
8586           if (!CONST_INT_P (XEXP (x, 1)))
8587             return false;
8588           x = XEXP (x, 0);
8589         }
8590
8591       if (TARGET_MACHO && darwin_local_data_pic (x))
8592         return true;
8593
8594       /* Only some unspecs are valid as "constants".  */
8595       if (GET_CODE (x) == UNSPEC)
8596         switch (XINT (x, 1))
8597           {
8598           case UNSPEC_GOT:
8599           case UNSPEC_GOTOFF:
8600           case UNSPEC_PLTOFF:
8601             return TARGET_64BIT;
8602           case UNSPEC_TPOFF:
8603           case UNSPEC_NTPOFF:
8604             x = XVECEXP (x, 0, 0);
8605             return (GET_CODE (x) == SYMBOL_REF
8606                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8607           case UNSPEC_DTPOFF:
8608             x = XVECEXP (x, 0, 0);
8609             return (GET_CODE (x) == SYMBOL_REF
8610                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
8611           default:
8612             return false;
8613           }
8614
8615       /* We must have drilled down to a symbol.  */
8616       if (GET_CODE (x) == LABEL_REF)
8617         return true;
8618       if (GET_CODE (x) != SYMBOL_REF)
8619         return false;
8620       /* FALLTHRU */
8621
8622     case SYMBOL_REF:
8623       /* TLS symbols are never valid.  */
8624       if (SYMBOL_REF_TLS_MODEL (x))
8625         return false;
8626
8627       /* DLLIMPORT symbols are never valid.  */
8628       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8629           && SYMBOL_REF_DLLIMPORT_P (x))
8630         return false;
8631       break;
8632
8633     case CONST_DOUBLE:
8634       if (GET_MODE (x) == TImode
8635           && x != CONST0_RTX (TImode)
8636           && !TARGET_64BIT)
8637         return false;
8638       break;
8639
8640     case CONST_VECTOR:
8641       if (x == CONST0_RTX (GET_MODE (x)))
8642         return true;
8643       return false;
8644
8645     default:
8646       break;
8647     }
8648
8649   /* Otherwise we handle everything else in the move patterns.  */
8650   return true;
8651 }
8652
8653 /* Determine if it's legal to put X into the constant pool.  This
8654    is not possible for the address of thread-local symbols, which
8655    is checked above.  */
8656
8657 static bool
8658 ix86_cannot_force_const_mem (rtx x)
8659 {
8660   /* We can always put integral constants and vectors in memory.  */
8661   switch (GET_CODE (x))
8662     {
8663     case CONST_INT:
8664     case CONST_DOUBLE:
8665     case CONST_VECTOR:
8666       return false;
8667
8668     default:
8669       break;
8670     }
8671   return !legitimate_constant_p (x);
8672 }
8673
8674 /* Determine if a given RTX is a valid constant address.  */
8675
8676 bool
8677 constant_address_p (rtx x)
8678 {
8679   return CONSTANT_P (x) && legitimate_address_p (Pmode, x, 1);
8680 }
8681
8682 /* Nonzero if the constant value X is a legitimate general operand
8683    when generating PIC code.  It is given that flag_pic is on and
8684    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
8685
8686 bool
8687 legitimate_pic_operand_p (rtx x)
8688 {
8689   rtx inner;
8690
8691   switch (GET_CODE (x))
8692     {
8693     case CONST:
8694       inner = XEXP (x, 0);
8695       if (GET_CODE (inner) == PLUS
8696           && CONST_INT_P (XEXP (inner, 1)))
8697         inner = XEXP (inner, 0);
8698
8699       /* Only some unspecs are valid as "constants".  */
8700       if (GET_CODE (inner) == UNSPEC)
8701         switch (XINT (inner, 1))
8702           {
8703           case UNSPEC_GOT:
8704           case UNSPEC_GOTOFF:
8705           case UNSPEC_PLTOFF:
8706             return TARGET_64BIT;
8707           case UNSPEC_TPOFF:
8708             x = XVECEXP (inner, 0, 0);
8709             return (GET_CODE (x) == SYMBOL_REF
8710                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8711           default:
8712             return false;
8713           }
8714       /* FALLTHRU */
8715
8716     case SYMBOL_REF:
8717     case LABEL_REF:
8718       return legitimate_pic_address_disp_p (x);
8719
8720     default:
8721       return true;
8722     }
8723 }
8724
8725 /* Determine if a given CONST RTX is a valid memory displacement
8726    in PIC mode.  */
8727
8728 int
8729 legitimate_pic_address_disp_p (rtx disp)
8730 {
8731   bool saw_plus;
8732
8733   /* In 64bit mode we can allow direct addresses of symbols and labels
8734      when they are not dynamic symbols.  */
8735   if (TARGET_64BIT)
8736     {
8737       rtx op0 = disp, op1;
8738
8739       switch (GET_CODE (disp))
8740         {
8741         case LABEL_REF:
8742           return true;
8743
8744         case CONST:
8745           if (GET_CODE (XEXP (disp, 0)) != PLUS)
8746             break;
8747           op0 = XEXP (XEXP (disp, 0), 0);
8748           op1 = XEXP (XEXP (disp, 0), 1);
8749           if (!CONST_INT_P (op1)
8750               || INTVAL (op1) >= 16*1024*1024
8751               || INTVAL (op1) < -16*1024*1024)
8752             break;
8753           if (GET_CODE (op0) == LABEL_REF)
8754             return true;
8755           if (GET_CODE (op0) != SYMBOL_REF)
8756             break;
8757           /* FALLTHRU */
8758
8759         case SYMBOL_REF:
8760           /* TLS references should always be enclosed in UNSPEC.  */
8761           if (SYMBOL_REF_TLS_MODEL (op0))
8762             return false;
8763           if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0)
8764               && ix86_cmodel != CM_LARGE_PIC)
8765             return true;
8766           break;
8767
8768         default:
8769           break;
8770         }
8771     }
8772   if (GET_CODE (disp) != CONST)
8773     return 0;
8774   disp = XEXP (disp, 0);
8775
8776   if (TARGET_64BIT)
8777     {
8778       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
8779          of GOT tables.  We should not need these anyway.  */
8780       if (GET_CODE (disp) != UNSPEC
8781           || (XINT (disp, 1) != UNSPEC_GOTPCREL
8782               && XINT (disp, 1) != UNSPEC_GOTOFF
8783               && XINT (disp, 1) != UNSPEC_PLTOFF))
8784         return 0;
8785
8786       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
8787           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
8788         return 0;
8789       return 1;
8790     }
8791
8792   saw_plus = false;
8793   if (GET_CODE (disp) == PLUS)
8794     {
8795       if (!CONST_INT_P (XEXP (disp, 1)))
8796         return 0;
8797       disp = XEXP (disp, 0);
8798       saw_plus = true;
8799     }
8800
8801   if (TARGET_MACHO && darwin_local_data_pic (disp))
8802     return 1;
8803
8804   if (GET_CODE (disp) != UNSPEC)
8805     return 0;
8806
8807   switch (XINT (disp, 1))
8808     {
8809     case UNSPEC_GOT:
8810       if (saw_plus)
8811         return false;
8812       /* We need to check for both symbols and labels because VxWorks loads
8813          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
8814          details.  */
8815       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
8816               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
8817     case UNSPEC_GOTOFF:
8818       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
8819          While ABI specify also 32bit relocation but we don't produce it in
8820          small PIC model at all.  */
8821       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
8822            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
8823           && !TARGET_64BIT)
8824         return gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
8825       return false;
8826     case UNSPEC_GOTTPOFF:
8827     case UNSPEC_GOTNTPOFF:
8828     case UNSPEC_INDNTPOFF:
8829       if (saw_plus)
8830         return false;
8831       disp = XVECEXP (disp, 0, 0);
8832       return (GET_CODE (disp) == SYMBOL_REF
8833               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
8834     case UNSPEC_NTPOFF:
8835       disp = XVECEXP (disp, 0, 0);
8836       return (GET_CODE (disp) == SYMBOL_REF
8837               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
8838     case UNSPEC_DTPOFF:
8839       disp = XVECEXP (disp, 0, 0);
8840       return (GET_CODE (disp) == SYMBOL_REF
8841               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
8842     }
8843
8844   return 0;
8845 }
8846
8847 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid
8848    memory address for an instruction.  The MODE argument is the machine mode
8849    for the MEM expression that wants to use this address.
8850
8851    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
8852    convert common non-canonical forms to canonical form so that they will
8853    be recognized.  */
8854
8855 int
8856 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
8857                       rtx addr, int strict)
8858 {
8859   struct ix86_address parts;
8860   rtx base, index, disp;
8861   HOST_WIDE_INT scale;
8862   const char *reason = NULL;
8863   rtx reason_rtx = NULL_RTX;
8864
8865   if (ix86_decompose_address (addr, &parts) <= 0)
8866     {
8867       reason = "decomposition failed";
8868       goto report_error;
8869     }
8870
8871   base = parts.base;
8872   index = parts.index;
8873   disp = parts.disp;
8874   scale = parts.scale;
8875
8876   /* Validate base register.
8877
8878      Don't allow SUBREG's that span more than a word here.  It can lead to spill
8879      failures when the base is one word out of a two word structure, which is
8880      represented internally as a DImode int.  */
8881
8882   if (base)
8883     {
8884       rtx reg;
8885       reason_rtx = base;
8886
8887       if (REG_P (base))
8888         reg = base;
8889       else if (GET_CODE (base) == SUBREG
8890                && REG_P (SUBREG_REG (base))
8891                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (base)))
8892                   <= UNITS_PER_WORD)
8893         reg = SUBREG_REG (base);
8894       else
8895         {
8896           reason = "base is not a register";
8897           goto report_error;
8898         }
8899
8900       if (GET_MODE (base) != Pmode)
8901         {
8902           reason = "base is not in Pmode";
8903           goto report_error;
8904         }
8905
8906       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
8907           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
8908         {
8909           reason = "base is not valid";
8910           goto report_error;
8911         }
8912     }
8913
8914   /* Validate index register.
8915
8916      Don't allow SUBREG's that span more than a word here -- same as above.  */
8917
8918   if (index)
8919     {
8920       rtx reg;
8921       reason_rtx = index;
8922
8923       if (REG_P (index))
8924         reg = index;
8925       else if (GET_CODE (index) == SUBREG
8926                && REG_P (SUBREG_REG (index))
8927                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (index)))
8928                   <= UNITS_PER_WORD)
8929         reg = SUBREG_REG (index);
8930       else
8931         {
8932           reason = "index is not a register";
8933           goto report_error;
8934         }
8935
8936       if (GET_MODE (index) != Pmode)
8937         {
8938           reason = "index is not in Pmode";
8939           goto report_error;
8940         }
8941
8942       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
8943           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
8944         {
8945           reason = "index is not valid";
8946           goto report_error;
8947         }
8948     }
8949
8950   /* Validate scale factor.  */
8951   if (scale != 1)
8952     {
8953       reason_rtx = GEN_INT (scale);
8954       if (!index)
8955         {
8956           reason = "scale without index";
8957           goto report_error;
8958         }
8959
8960       if (scale != 2 && scale != 4 && scale != 8)
8961         {
8962           reason = "scale is not a valid multiplier";
8963           goto report_error;
8964         }
8965     }
8966
8967   /* Validate displacement.  */
8968   if (disp)
8969     {
8970       reason_rtx = disp;
8971
8972       if (GET_CODE (disp) == CONST
8973           && GET_CODE (XEXP (disp, 0)) == UNSPEC)
8974         switch (XINT (XEXP (disp, 0), 1))
8975           {
8976           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
8977              used.  While ABI specify also 32bit relocations, we don't produce
8978              them at all and use IP relative instead.  */
8979           case UNSPEC_GOT:
8980           case UNSPEC_GOTOFF:
8981             gcc_assert (flag_pic);
8982             if (!TARGET_64BIT)
8983               goto is_legitimate_pic;
8984             reason = "64bit address unspec";
8985             goto report_error;
8986
8987           case UNSPEC_GOTPCREL:
8988             gcc_assert (flag_pic);
8989             goto is_legitimate_pic;
8990
8991           case UNSPEC_GOTTPOFF:
8992           case UNSPEC_GOTNTPOFF:
8993           case UNSPEC_INDNTPOFF:
8994           case UNSPEC_NTPOFF:
8995           case UNSPEC_DTPOFF:
8996             break;
8997
8998           default:
8999             reason = "invalid address unspec";
9000             goto report_error;
9001           }
9002
9003       else if (SYMBOLIC_CONST (disp)
9004                && (flag_pic
9005                    || (TARGET_MACHO
9006 #if TARGET_MACHO
9007                        && MACHOPIC_INDIRECT
9008                        && !machopic_operand_p (disp)
9009 #endif
9010                )))
9011         {
9012
9013         is_legitimate_pic:
9014           if (TARGET_64BIT && (index || base))
9015             {
9016               /* foo@dtpoff(%rX) is ok.  */
9017               if (GET_CODE (disp) != CONST
9018                   || GET_CODE (XEXP (disp, 0)) != PLUS
9019                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
9020                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
9021                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
9022                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
9023                 {
9024                   reason = "non-constant pic memory reference";
9025                   goto report_error;
9026                 }
9027             }
9028           else if (! legitimate_pic_address_disp_p (disp))
9029             {
9030               reason = "displacement is an invalid pic construct";
9031               goto report_error;
9032             }
9033
9034           /* This code used to verify that a symbolic pic displacement
9035              includes the pic_offset_table_rtx register.
9036
9037              While this is good idea, unfortunately these constructs may
9038              be created by "adds using lea" optimization for incorrect
9039              code like:
9040
9041              int a;
9042              int foo(int i)
9043                {
9044                  return *(&a+i);
9045                }
9046
9047              This code is nonsensical, but results in addressing
9048              GOT table with pic_offset_table_rtx base.  We can't
9049              just refuse it easily, since it gets matched by
9050              "addsi3" pattern, that later gets split to lea in the
9051              case output register differs from input.  While this
9052              can be handled by separate addsi pattern for this case
9053              that never results in lea, this seems to be easier and
9054              correct fix for crash to disable this test.  */
9055         }
9056       else if (GET_CODE (disp) != LABEL_REF
9057                && !CONST_INT_P (disp)
9058                && (GET_CODE (disp) != CONST
9059                    || !legitimate_constant_p (disp))
9060                && (GET_CODE (disp) != SYMBOL_REF
9061                    || !legitimate_constant_p (disp)))
9062         {
9063           reason = "displacement is not constant";
9064           goto report_error;
9065         }
9066       else if (TARGET_64BIT
9067                && !x86_64_immediate_operand (disp, VOIDmode))
9068         {
9069           reason = "displacement is out of range";
9070           goto report_error;
9071         }
9072     }
9073
9074   /* Everything looks valid.  */
9075   return TRUE;
9076
9077  report_error:
9078   return FALSE;
9079 }
9080 \f
9081 /* Return a unique alias set for the GOT.  */
9082
9083 static alias_set_type
9084 ix86_GOT_alias_set (void)
9085 {
9086   static alias_set_type set = -1;
9087   if (set == -1)
9088     set = new_alias_set ();
9089   return set;
9090 }
9091
9092 /* Return a legitimate reference for ORIG (an address) using the
9093    register REG.  If REG is 0, a new pseudo is generated.
9094
9095    There are two types of references that must be handled:
9096
9097    1. Global data references must load the address from the GOT, via
9098       the PIC reg.  An insn is emitted to do this load, and the reg is
9099       returned.
9100
9101    2. Static data references, constant pool addresses, and code labels
9102       compute the address as an offset from the GOT, whose base is in
9103       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
9104       differentiate them from global data objects.  The returned
9105       address is the PIC reg + an unspec constant.
9106
9107    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
9108    reg also appears in the address.  */
9109
9110 static rtx
9111 legitimize_pic_address (rtx orig, rtx reg)
9112 {
9113   rtx addr = orig;
9114   rtx new_rtx = orig;
9115   rtx base;
9116
9117 #if TARGET_MACHO
9118   if (TARGET_MACHO && !TARGET_64BIT)
9119     {
9120       if (reg == 0)
9121         reg = gen_reg_rtx (Pmode);
9122       /* Use the generic Mach-O PIC machinery.  */
9123       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
9124     }
9125 #endif
9126
9127   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
9128     new_rtx = addr;
9129   else if (TARGET_64BIT
9130            && ix86_cmodel != CM_SMALL_PIC
9131            && gotoff_operand (addr, Pmode))
9132     {
9133       rtx tmpreg;
9134       /* This symbol may be referenced via a displacement from the PIC
9135          base address (@GOTOFF).  */
9136
9137       if (reload_in_progress)
9138         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9139       if (GET_CODE (addr) == CONST)
9140         addr = XEXP (addr, 0);
9141       if (GET_CODE (addr) == PLUS)
9142           {
9143             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9144                                       UNSPEC_GOTOFF);
9145             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9146           }
9147         else
9148           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9149       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9150       if (!reg)
9151         tmpreg = gen_reg_rtx (Pmode);
9152       else
9153         tmpreg = reg;
9154       emit_move_insn (tmpreg, new_rtx);
9155
9156       if (reg != 0)
9157         {
9158           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
9159                                          tmpreg, 1, OPTAB_DIRECT);
9160           new_rtx = reg;
9161         }
9162       else new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
9163     }
9164   else if (!TARGET_64BIT && gotoff_operand (addr, Pmode))
9165     {
9166       /* This symbol may be referenced via a displacement from the PIC
9167          base address (@GOTOFF).  */
9168
9169       if (reload_in_progress)
9170         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9171       if (GET_CODE (addr) == CONST)
9172         addr = XEXP (addr, 0);
9173       if (GET_CODE (addr) == PLUS)
9174           {
9175             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9176                                       UNSPEC_GOTOFF);
9177             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9178           }
9179         else
9180           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9181       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9182       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9183
9184       if (reg != 0)
9185         {
9186           emit_move_insn (reg, new_rtx);
9187           new_rtx = reg;
9188         }
9189     }
9190   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
9191            /* We can't use @GOTOFF for text labels on VxWorks;
9192               see gotoff_operand.  */
9193            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
9194     {
9195       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9196         {
9197           if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
9198             return legitimize_dllimport_symbol (addr, true);
9199           if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
9200               && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
9201               && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
9202             {
9203               rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), true);
9204               return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
9205             }
9206         }
9207
9208       if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
9209         {
9210           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
9211           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9212           new_rtx = gen_const_mem (Pmode, new_rtx);
9213           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9214
9215           if (reg == 0)
9216             reg = gen_reg_rtx (Pmode);
9217           /* Use directly gen_movsi, otherwise the address is loaded
9218              into register for CSE.  We don't want to CSE this addresses,
9219              instead we CSE addresses from the GOT table, so skip this.  */
9220           emit_insn (gen_movsi (reg, new_rtx));
9221           new_rtx = reg;
9222         }
9223       else
9224         {
9225           /* This symbol must be referenced via a load from the
9226              Global Offset Table (@GOT).  */
9227
9228           if (reload_in_progress)
9229             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9230           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
9231           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9232           if (TARGET_64BIT)
9233             new_rtx = force_reg (Pmode, new_rtx);
9234           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9235           new_rtx = gen_const_mem (Pmode, new_rtx);
9236           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9237
9238           if (reg == 0)
9239             reg = gen_reg_rtx (Pmode);
9240           emit_move_insn (reg, new_rtx);
9241           new_rtx = reg;
9242         }
9243     }
9244   else
9245     {
9246       if (CONST_INT_P (addr)
9247           && !x86_64_immediate_operand (addr, VOIDmode))
9248         {
9249           if (reg)
9250             {
9251               emit_move_insn (reg, addr);
9252               new_rtx = reg;
9253             }
9254           else
9255             new_rtx = force_reg (Pmode, addr);
9256         }
9257       else if (GET_CODE (addr) == CONST)
9258         {
9259           addr = XEXP (addr, 0);
9260
9261           /* We must match stuff we generate before.  Assume the only
9262              unspecs that can get here are ours.  Not that we could do
9263              anything with them anyway....  */
9264           if (GET_CODE (addr) == UNSPEC
9265               || (GET_CODE (addr) == PLUS
9266                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
9267             return orig;
9268           gcc_assert (GET_CODE (addr) == PLUS);
9269         }
9270       if (GET_CODE (addr) == PLUS)
9271         {
9272           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
9273
9274           /* Check first to see if this is a constant offset from a @GOTOFF
9275              symbol reference.  */
9276           if (gotoff_operand (op0, Pmode)
9277               && CONST_INT_P (op1))
9278             {
9279               if (!TARGET_64BIT)
9280                 {
9281                   if (reload_in_progress)
9282                     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9283                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
9284                                             UNSPEC_GOTOFF);
9285                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
9286                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9287                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9288
9289                   if (reg != 0)
9290                     {
9291                       emit_move_insn (reg, new_rtx);
9292                       new_rtx = reg;
9293                     }
9294                 }
9295               else
9296                 {
9297                   if (INTVAL (op1) < -16*1024*1024
9298                       || INTVAL (op1) >= 16*1024*1024)
9299                     {
9300                       if (!x86_64_immediate_operand (op1, Pmode))
9301                         op1 = force_reg (Pmode, op1);
9302                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
9303                     }
9304                 }
9305             }
9306           else
9307             {
9308               base = legitimize_pic_address (XEXP (addr, 0), reg);
9309               new_rtx  = legitimize_pic_address (XEXP (addr, 1),
9310                                                  base == reg ? NULL_RTX : reg);
9311
9312               if (CONST_INT_P (new_rtx))
9313                 new_rtx = plus_constant (base, INTVAL (new_rtx));
9314               else
9315                 {
9316                   if (GET_CODE (new_rtx) == PLUS && CONSTANT_P (XEXP (new_rtx, 1)))
9317                     {
9318                       base = gen_rtx_PLUS (Pmode, base, XEXP (new_rtx, 0));
9319                       new_rtx = XEXP (new_rtx, 1);
9320                     }
9321                   new_rtx = gen_rtx_PLUS (Pmode, base, new_rtx);
9322                 }
9323             }
9324         }
9325     }
9326   return new_rtx;
9327 }
9328 \f
9329 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
9330
9331 static rtx
9332 get_thread_pointer (int to_reg)
9333 {
9334   rtx tp, reg, insn;
9335
9336   tp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
9337   if (!to_reg)
9338     return tp;
9339
9340   reg = gen_reg_rtx (Pmode);
9341   insn = gen_rtx_SET (VOIDmode, reg, tp);
9342   insn = emit_insn (insn);
9343
9344   return reg;
9345 }
9346
9347 /* A subroutine of legitimize_address and ix86_expand_move.  FOR_MOV is
9348    false if we expect this to be used for a memory address and true if
9349    we expect to load the address into a register.  */
9350
9351 static rtx
9352 legitimize_tls_address (rtx x, enum tls_model model, int for_mov)
9353 {
9354   rtx dest, base, off, pic, tp;
9355   int type;
9356
9357   switch (model)
9358     {
9359     case TLS_MODEL_GLOBAL_DYNAMIC:
9360       dest = gen_reg_rtx (Pmode);
9361       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9362
9363       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9364         {
9365           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns;
9366
9367           start_sequence ();
9368           emit_call_insn (gen_tls_global_dynamic_64 (rax, x));
9369           insns = get_insns ();
9370           end_sequence ();
9371
9372           RTL_CONST_CALL_P (insns) = 1;
9373           emit_libcall_block (insns, dest, rax, x);
9374         }
9375       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9376         emit_insn (gen_tls_global_dynamic_64 (dest, x));
9377       else
9378         emit_insn (gen_tls_global_dynamic_32 (dest, x));
9379
9380       if (TARGET_GNU2_TLS)
9381         {
9382           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
9383
9384           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9385         }
9386       break;
9387
9388     case TLS_MODEL_LOCAL_DYNAMIC:
9389       base = gen_reg_rtx (Pmode);
9390       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9391
9392       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9393         {
9394           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns, note;
9395
9396           start_sequence ();
9397           emit_call_insn (gen_tls_local_dynamic_base_64 (rax));
9398           insns = get_insns ();
9399           end_sequence ();
9400
9401           note = gen_rtx_EXPR_LIST (VOIDmode, const0_rtx, NULL);
9402           note = gen_rtx_EXPR_LIST (VOIDmode, ix86_tls_get_addr (), note);
9403           RTL_CONST_CALL_P (insns) = 1;
9404           emit_libcall_block (insns, base, rax, note);
9405         }
9406       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9407         emit_insn (gen_tls_local_dynamic_base_64 (base));
9408       else
9409         emit_insn (gen_tls_local_dynamic_base_32 (base));
9410
9411       if (TARGET_GNU2_TLS)
9412         {
9413           rtx x = ix86_tls_module_base ();
9414
9415           set_unique_reg_note (get_last_insn (), REG_EQUIV,
9416                                gen_rtx_MINUS (Pmode, x, tp));
9417         }
9418
9419       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
9420       off = gen_rtx_CONST (Pmode, off);
9421
9422       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
9423
9424       if (TARGET_GNU2_TLS)
9425         {
9426           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
9427
9428           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9429         }
9430
9431       break;
9432
9433     case TLS_MODEL_INITIAL_EXEC:
9434       if (TARGET_64BIT)
9435         {
9436           pic = NULL;
9437           type = UNSPEC_GOTNTPOFF;
9438         }
9439       else if (flag_pic)
9440         {
9441           if (reload_in_progress)
9442             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9443           pic = pic_offset_table_rtx;
9444           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
9445         }
9446       else if (!TARGET_ANY_GNU_TLS)
9447         {
9448           pic = gen_reg_rtx (Pmode);
9449           emit_insn (gen_set_got (pic));
9450           type = UNSPEC_GOTTPOFF;
9451         }
9452       else
9453         {
9454           pic = NULL;
9455           type = UNSPEC_INDNTPOFF;
9456         }
9457
9458       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), type);
9459       off = gen_rtx_CONST (Pmode, off);
9460       if (pic)
9461         off = gen_rtx_PLUS (Pmode, pic, off);
9462       off = gen_const_mem (Pmode, off);
9463       set_mem_alias_set (off, ix86_GOT_alias_set ());
9464
9465       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9466         {
9467           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9468           off = force_reg (Pmode, off);
9469           return gen_rtx_PLUS (Pmode, base, off);
9470         }
9471       else
9472         {
9473           base = get_thread_pointer (true);
9474           dest = gen_reg_rtx (Pmode);
9475           emit_insn (gen_subsi3 (dest, base, off));
9476         }
9477       break;
9478
9479     case TLS_MODEL_LOCAL_EXEC:
9480       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
9481                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9482                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
9483       off = gen_rtx_CONST (Pmode, off);
9484
9485       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9486         {
9487           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9488           return gen_rtx_PLUS (Pmode, base, off);
9489         }
9490       else
9491         {
9492           base = get_thread_pointer (true);
9493           dest = gen_reg_rtx (Pmode);
9494           emit_insn (gen_subsi3 (dest, base, off));
9495         }
9496       break;
9497
9498     default:
9499       gcc_unreachable ();
9500     }
9501
9502   return dest;
9503 }
9504
9505 /* Create or return the unique __imp_DECL dllimport symbol corresponding
9506    to symbol DECL.  */
9507
9508 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
9509   htab_t dllimport_map;
9510
9511 static tree
9512 get_dllimport_decl (tree decl)
9513 {
9514   struct tree_map *h, in;
9515   void **loc;
9516   const char *name;
9517   const char *prefix;
9518   size_t namelen, prefixlen;
9519   char *imp_name;
9520   tree to;
9521   rtx rtl;
9522
9523   if (!dllimport_map)
9524     dllimport_map = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
9525
9526   in.hash = htab_hash_pointer (decl);
9527   in.base.from = decl;
9528   loc = htab_find_slot_with_hash (dllimport_map, &in, in.hash, INSERT);
9529   h = (struct tree_map *) *loc;
9530   if (h)
9531     return h->to;
9532
9533   *loc = h = GGC_NEW (struct tree_map);
9534   h->hash = in.hash;
9535   h->base.from = decl;
9536   h->to = to = build_decl (VAR_DECL, NULL, ptr_type_node);
9537   DECL_ARTIFICIAL (to) = 1;
9538   DECL_IGNORED_P (to) = 1;
9539   DECL_EXTERNAL (to) = 1;
9540   TREE_READONLY (to) = 1;
9541
9542   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9543   name = targetm.strip_name_encoding (name);
9544   prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
9545     ? "*__imp_" : "*__imp__";
9546   namelen = strlen (name);
9547   prefixlen = strlen (prefix);
9548   imp_name = (char *) alloca (namelen + prefixlen + 1);
9549   memcpy (imp_name, prefix, prefixlen);
9550   memcpy (imp_name + prefixlen, name, namelen + 1);
9551
9552   name = ggc_alloc_string (imp_name, namelen + prefixlen);
9553   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
9554   SET_SYMBOL_REF_DECL (rtl, to);
9555   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL;
9556
9557   rtl = gen_const_mem (Pmode, rtl);
9558   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
9559
9560   SET_DECL_RTL (to, rtl);
9561   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
9562
9563   return to;
9564 }
9565
9566 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
9567    true if we require the result be a register.  */
9568
9569 static rtx
9570 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
9571 {
9572   tree imp_decl;
9573   rtx x;
9574
9575   gcc_assert (SYMBOL_REF_DECL (symbol));
9576   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol));
9577
9578   x = DECL_RTL (imp_decl);
9579   if (want_reg)
9580     x = force_reg (Pmode, x);
9581   return x;
9582 }
9583
9584 /* Try machine-dependent ways of modifying an illegitimate address
9585    to be legitimate.  If we find one, return the new, valid address.
9586    This macro is used in only one place: `memory_address' in explow.c.
9587
9588    OLDX is the address as it was before break_out_memory_refs was called.
9589    In some cases it is useful to look at this to decide what needs to be done.
9590
9591    MODE and WIN are passed so that this macro can use
9592    GO_IF_LEGITIMATE_ADDRESS.
9593
9594    It is always safe for this macro to do nothing.  It exists to recognize
9595    opportunities to optimize the output.
9596
9597    For the 80386, we handle X+REG by loading X into a register R and
9598    using R+REG.  R will go in a general reg and indexing will be used.
9599    However, if REG is a broken-out memory address or multiplication,
9600    nothing needs to be done because REG can certainly go in a general reg.
9601
9602    When -fpic is used, special handling is needed for symbolic references.
9603    See comments by legitimize_pic_address in i386.c for details.  */
9604
9605 rtx
9606 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
9607 {
9608   int changed = 0;
9609   unsigned log;
9610
9611   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
9612   if (log)
9613     return legitimize_tls_address (x, (enum tls_model) log, false);
9614   if (GET_CODE (x) == CONST
9615       && GET_CODE (XEXP (x, 0)) == PLUS
9616       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9617       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
9618     {
9619       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
9620                                       (enum tls_model) log, false);
9621       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9622     }
9623
9624   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9625     {
9626       if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (x))
9627         return legitimize_dllimport_symbol (x, true);
9628       if (GET_CODE (x) == CONST
9629           && GET_CODE (XEXP (x, 0)) == PLUS
9630           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9631           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (x, 0), 0)))
9632         {
9633           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (x, 0), 0), true);
9634           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9635         }
9636     }
9637
9638   if (flag_pic && SYMBOLIC_CONST (x))
9639     return legitimize_pic_address (x, 0);
9640
9641   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
9642   if (GET_CODE (x) == ASHIFT
9643       && CONST_INT_P (XEXP (x, 1))
9644       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
9645     {
9646       changed = 1;
9647       log = INTVAL (XEXP (x, 1));
9648       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
9649                         GEN_INT (1 << log));
9650     }
9651
9652   if (GET_CODE (x) == PLUS)
9653     {
9654       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
9655
9656       if (GET_CODE (XEXP (x, 0)) == ASHIFT
9657           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
9658           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
9659         {
9660           changed = 1;
9661           log = INTVAL (XEXP (XEXP (x, 0), 1));
9662           XEXP (x, 0) = gen_rtx_MULT (Pmode,
9663                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
9664                                       GEN_INT (1 << log));
9665         }
9666
9667       if (GET_CODE (XEXP (x, 1)) == ASHIFT
9668           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
9669           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
9670         {
9671           changed = 1;
9672           log = INTVAL (XEXP (XEXP (x, 1), 1));
9673           XEXP (x, 1) = gen_rtx_MULT (Pmode,
9674                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
9675                                       GEN_INT (1 << log));
9676         }
9677
9678       /* Put multiply first if it isn't already.  */
9679       if (GET_CODE (XEXP (x, 1)) == MULT)
9680         {
9681           rtx tmp = XEXP (x, 0);
9682           XEXP (x, 0) = XEXP (x, 1);
9683           XEXP (x, 1) = tmp;
9684           changed = 1;
9685         }
9686
9687       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
9688          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
9689          created by virtual register instantiation, register elimination, and
9690          similar optimizations.  */
9691       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
9692         {
9693           changed = 1;
9694           x = gen_rtx_PLUS (Pmode,
9695                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
9696                                           XEXP (XEXP (x, 1), 0)),
9697                             XEXP (XEXP (x, 1), 1));
9698         }
9699
9700       /* Canonicalize
9701          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
9702          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
9703       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
9704                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
9705                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
9706                && CONSTANT_P (XEXP (x, 1)))
9707         {
9708           rtx constant;
9709           rtx other = NULL_RTX;
9710
9711           if (CONST_INT_P (XEXP (x, 1)))
9712             {
9713               constant = XEXP (x, 1);
9714               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
9715             }
9716           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
9717             {
9718               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
9719               other = XEXP (x, 1);
9720             }
9721           else
9722             constant = 0;
9723
9724           if (constant)
9725             {
9726               changed = 1;
9727               x = gen_rtx_PLUS (Pmode,
9728                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
9729                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
9730                                 plus_constant (other, INTVAL (constant)));
9731             }
9732         }
9733
9734       if (changed && legitimate_address_p (mode, x, FALSE))
9735         return x;
9736
9737       if (GET_CODE (XEXP (x, 0)) == MULT)
9738         {
9739           changed = 1;
9740           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
9741         }
9742
9743       if (GET_CODE (XEXP (x, 1)) == MULT)
9744         {
9745           changed = 1;
9746           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
9747         }
9748
9749       if (changed
9750           && REG_P (XEXP (x, 1))
9751           && REG_P (XEXP (x, 0)))
9752         return x;
9753
9754       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
9755         {
9756           changed = 1;
9757           x = legitimize_pic_address (x, 0);
9758         }
9759
9760       if (changed && legitimate_address_p (mode, x, FALSE))
9761         return x;
9762
9763       if (REG_P (XEXP (x, 0)))
9764         {
9765           rtx temp = gen_reg_rtx (Pmode);
9766           rtx val  = force_operand (XEXP (x, 1), temp);
9767           if (val != temp)
9768             emit_move_insn (temp, val);
9769
9770           XEXP (x, 1) = temp;
9771           return x;
9772         }
9773
9774       else if (REG_P (XEXP (x, 1)))
9775         {
9776           rtx temp = gen_reg_rtx (Pmode);
9777           rtx val  = force_operand (XEXP (x, 0), temp);
9778           if (val != temp)
9779             emit_move_insn (temp, val);
9780
9781           XEXP (x, 0) = temp;
9782           return x;
9783         }
9784     }
9785
9786   return x;
9787 }
9788 \f
9789 /* Print an integer constant expression in assembler syntax.  Addition
9790    and subtraction are the only arithmetic that may appear in these
9791    expressions.  FILE is the stdio stream to write to, X is the rtx, and
9792    CODE is the operand print code from the output string.  */
9793
9794 static void
9795 output_pic_addr_const (FILE *file, rtx x, int code)
9796 {
9797   char buf[256];
9798
9799   switch (GET_CODE (x))
9800     {
9801     case PC:
9802       gcc_assert (flag_pic);
9803       putc ('.', file);
9804       break;
9805
9806     case SYMBOL_REF:
9807       if (! TARGET_MACHO || TARGET_64BIT)
9808         output_addr_const (file, x);
9809       else
9810         {
9811           const char *name = XSTR (x, 0);
9812
9813           /* Mark the decl as referenced so that cgraph will
9814              output the function.  */
9815           if (SYMBOL_REF_DECL (x))
9816             mark_decl_referenced (SYMBOL_REF_DECL (x));
9817
9818 #if TARGET_MACHO
9819           if (MACHOPIC_INDIRECT
9820               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
9821             name = machopic_indirection_name (x, /*stub_p=*/true);
9822 #endif
9823           assemble_name (file, name);
9824         }
9825       if (!TARGET_MACHO && !(TARGET_64BIT && DEFAULT_ABI == MS_ABI)
9826           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
9827         fputs ("@PLT", file);
9828       break;
9829
9830     case LABEL_REF:
9831       x = XEXP (x, 0);
9832       /* FALLTHRU */
9833     case CODE_LABEL:
9834       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
9835       assemble_name (asm_out_file, buf);
9836       break;
9837
9838     case CONST_INT:
9839       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
9840       break;
9841
9842     case CONST:
9843       /* This used to output parentheses around the expression,
9844          but that does not work on the 386 (either ATT or BSD assembler).  */
9845       output_pic_addr_const (file, XEXP (x, 0), code);
9846       break;
9847
9848     case CONST_DOUBLE:
9849       if (GET_MODE (x) == VOIDmode)
9850         {
9851           /* We can use %d if the number is <32 bits and positive.  */
9852           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
9853             fprintf (file, "0x%lx%08lx",
9854                      (unsigned long) CONST_DOUBLE_HIGH (x),
9855                      (unsigned long) CONST_DOUBLE_LOW (x));
9856           else
9857             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
9858         }
9859       else
9860         /* We can't handle floating point constants;
9861            PRINT_OPERAND must handle them.  */
9862         output_operand_lossage ("floating constant misused");
9863       break;
9864
9865     case PLUS:
9866       /* Some assemblers need integer constants to appear first.  */
9867       if (CONST_INT_P (XEXP (x, 0)))
9868         {
9869           output_pic_addr_const (file, XEXP (x, 0), code);
9870           putc ('+', file);
9871           output_pic_addr_const (file, XEXP (x, 1), code);
9872         }
9873       else
9874         {
9875           gcc_assert (CONST_INT_P (XEXP (x, 1)));
9876           output_pic_addr_const (file, XEXP (x, 1), code);
9877           putc ('+', file);
9878           output_pic_addr_const (file, XEXP (x, 0), code);
9879         }
9880       break;
9881
9882     case MINUS:
9883       if (!TARGET_MACHO)
9884         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
9885       output_pic_addr_const (file, XEXP (x, 0), code);
9886       putc ('-', file);
9887       output_pic_addr_const (file, XEXP (x, 1), code);
9888       if (!TARGET_MACHO)
9889         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
9890       break;
9891
9892      case UNSPEC:
9893        gcc_assert (XVECLEN (x, 0) == 1);
9894        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
9895        switch (XINT (x, 1))
9896         {
9897         case UNSPEC_GOT:
9898           fputs ("@GOT", file);
9899           break;
9900         case UNSPEC_GOTOFF:
9901           fputs ("@GOTOFF", file);
9902           break;
9903         case UNSPEC_PLTOFF:
9904           fputs ("@PLTOFF", file);
9905           break;
9906         case UNSPEC_GOTPCREL:
9907           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
9908                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
9909           break;
9910         case UNSPEC_GOTTPOFF:
9911           /* FIXME: This might be @TPOFF in Sun ld too.  */
9912           fputs ("@GOTTPOFF", file);
9913           break;
9914         case UNSPEC_TPOFF:
9915           fputs ("@TPOFF", file);
9916           break;
9917         case UNSPEC_NTPOFF:
9918           if (TARGET_64BIT)
9919             fputs ("@TPOFF", file);
9920           else
9921             fputs ("@NTPOFF", file);
9922           break;
9923         case UNSPEC_DTPOFF:
9924           fputs ("@DTPOFF", file);
9925           break;
9926         case UNSPEC_GOTNTPOFF:
9927           if (TARGET_64BIT)
9928             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
9929                    "@GOTTPOFF(%rip)": "@GOTTPOFF[rip]", file);
9930           else
9931             fputs ("@GOTNTPOFF", file);
9932           break;
9933         case UNSPEC_INDNTPOFF:
9934           fputs ("@INDNTPOFF", file);
9935           break;
9936         default:
9937           output_operand_lossage ("invalid UNSPEC as operand");
9938           break;
9939         }
9940        break;
9941
9942     default:
9943       output_operand_lossage ("invalid expression as operand");
9944     }
9945 }
9946
9947 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
9948    We need to emit DTP-relative relocations.  */
9949
9950 static void ATTRIBUTE_UNUSED
9951 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
9952 {
9953   fputs (ASM_LONG, file);
9954   output_addr_const (file, x);
9955   fputs ("@DTPOFF", file);
9956   switch (size)
9957     {
9958     case 4:
9959       break;
9960     case 8:
9961       fputs (", 0", file);
9962       break;
9963     default:
9964       gcc_unreachable ();
9965    }
9966 }
9967
9968 /* In the name of slightly smaller debug output, and to cater to
9969    general assembler lossage, recognize PIC+GOTOFF and turn it back
9970    into a direct symbol reference.
9971
9972    On Darwin, this is necessary to avoid a crash, because Darwin
9973    has a different PIC label for each routine but the DWARF debugging
9974    information is not associated with any particular routine, so it's
9975    necessary to remove references to the PIC label from RTL stored by
9976    the DWARF output code.  */
9977
9978 static rtx
9979 ix86_delegitimize_address (rtx orig_x)
9980 {
9981   rtx x = orig_x;
9982   /* reg_addend is NULL or a multiple of some register.  */
9983   rtx reg_addend = NULL_RTX;
9984   /* const_addend is NULL or a const_int.  */
9985   rtx const_addend = NULL_RTX;
9986   /* This is the result, or NULL.  */
9987   rtx result = NULL_RTX;
9988
9989   if (MEM_P (x))
9990     x = XEXP (x, 0);
9991
9992   if (TARGET_64BIT)
9993     {
9994       if (GET_CODE (x) != CONST
9995           || GET_CODE (XEXP (x, 0)) != UNSPEC
9996           || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL
9997           || !MEM_P (orig_x))
9998         return orig_x;
9999       return XVECEXP (XEXP (x, 0), 0, 0);
10000     }
10001
10002   if (GET_CODE (x) != PLUS
10003       || GET_CODE (XEXP (x, 1)) != CONST)
10004     return orig_x;
10005
10006   if (REG_P (XEXP (x, 0))
10007       && REGNO (XEXP (x, 0)) == PIC_OFFSET_TABLE_REGNUM)
10008     /* %ebx + GOT/GOTOFF */
10009     ;
10010   else if (GET_CODE (XEXP (x, 0)) == PLUS)
10011     {
10012       /* %ebx + %reg * scale + GOT/GOTOFF */
10013       reg_addend = XEXP (x, 0);
10014       if (REG_P (XEXP (reg_addend, 0))
10015           && REGNO (XEXP (reg_addend, 0)) == PIC_OFFSET_TABLE_REGNUM)
10016         reg_addend = XEXP (reg_addend, 1);
10017       else if (REG_P (XEXP (reg_addend, 1))
10018                && REGNO (XEXP (reg_addend, 1)) == PIC_OFFSET_TABLE_REGNUM)
10019         reg_addend = XEXP (reg_addend, 0);
10020       else
10021         return orig_x;
10022       if (!REG_P (reg_addend)
10023           && GET_CODE (reg_addend) != MULT
10024           && GET_CODE (reg_addend) != ASHIFT)
10025         return orig_x;
10026     }
10027   else
10028     return orig_x;
10029
10030   x = XEXP (XEXP (x, 1), 0);
10031   if (GET_CODE (x) == PLUS
10032       && CONST_INT_P (XEXP (x, 1)))
10033     {
10034       const_addend = XEXP (x, 1);
10035       x = XEXP (x, 0);
10036     }
10037
10038   if (GET_CODE (x) == UNSPEC
10039       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x))
10040           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))))
10041     result = XVECEXP (x, 0, 0);
10042
10043   if (TARGET_MACHO && darwin_local_data_pic (x)
10044       && !MEM_P (orig_x))
10045     result = XEXP (x, 0);
10046
10047   if (! result)
10048     return orig_x;
10049
10050   if (const_addend)
10051     result = gen_rtx_PLUS (Pmode, result, const_addend);
10052   if (reg_addend)
10053     result = gen_rtx_PLUS (Pmode, reg_addend, result);
10054   return result;
10055 }
10056
10057 /* If X is a machine specific address (i.e. a symbol or label being
10058    referenced as a displacement from the GOT implemented using an
10059    UNSPEC), then return the base term.  Otherwise return X.  */
10060
10061 rtx
10062 ix86_find_base_term (rtx x)
10063 {
10064   rtx term;
10065
10066   if (TARGET_64BIT)
10067     {
10068       if (GET_CODE (x) != CONST)
10069         return x;
10070       term = XEXP (x, 0);
10071       if (GET_CODE (term) == PLUS
10072           && (CONST_INT_P (XEXP (term, 1))
10073               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
10074         term = XEXP (term, 0);
10075       if (GET_CODE (term) != UNSPEC
10076           || XINT (term, 1) != UNSPEC_GOTPCREL)
10077         return x;
10078
10079       term = XVECEXP (term, 0, 0);
10080
10081       if (GET_CODE (term) != SYMBOL_REF
10082           && GET_CODE (term) != LABEL_REF)
10083         return x;
10084
10085       return term;
10086     }
10087
10088   term = ix86_delegitimize_address (x);
10089
10090   if (GET_CODE (term) != SYMBOL_REF
10091       && GET_CODE (term) != LABEL_REF)
10092     return x;
10093
10094   return term;
10095 }
10096 \f
10097 static void
10098 put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
10099                     int fp, FILE *file)
10100 {
10101   const char *suffix;
10102
10103   if (mode == CCFPmode || mode == CCFPUmode)
10104     {
10105       enum rtx_code second_code, bypass_code;
10106       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
10107       gcc_assert (bypass_code == UNKNOWN && second_code == UNKNOWN);
10108       code = ix86_fp_compare_code_to_integer (code);
10109       mode = CCmode;
10110     }
10111   if (reverse)
10112     code = reverse_condition (code);
10113
10114   switch (code)
10115     {
10116     case EQ:
10117       switch (mode)
10118         {
10119         case CCAmode:
10120           suffix = "a";
10121           break;
10122
10123         case CCCmode:
10124           suffix = "c";
10125           break;
10126
10127         case CCOmode:
10128           suffix = "o";
10129           break;
10130
10131         case CCSmode:
10132           suffix = "s";
10133           break;
10134
10135         default:
10136           suffix = "e";
10137         }
10138       break;
10139     case NE:
10140       switch (mode)
10141         {
10142         case CCAmode:
10143           suffix = "na";
10144           break;
10145
10146         case CCCmode:
10147           suffix = "nc";
10148           break;
10149
10150         case CCOmode:
10151           suffix = "no";
10152           break;
10153
10154         case CCSmode:
10155           suffix = "ns";
10156           break;
10157
10158         default:
10159           suffix = "ne";
10160         }
10161       break;
10162     case GT:
10163       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
10164       suffix = "g";
10165       break;
10166     case GTU:
10167       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
10168          Those same assemblers have the same but opposite lossage on cmov.  */
10169       if (mode == CCmode)
10170         suffix = fp ? "nbe" : "a";
10171       else if (mode == CCCmode)
10172         suffix = "b";
10173       else
10174         gcc_unreachable ();
10175       break;
10176     case LT:
10177       switch (mode)
10178         {
10179         case CCNOmode:
10180         case CCGOCmode:
10181           suffix = "s";
10182           break;
10183
10184         case CCmode:
10185         case CCGCmode:
10186           suffix = "l";
10187           break;
10188
10189         default:
10190           gcc_unreachable ();
10191         }
10192       break;
10193     case LTU:
10194       gcc_assert (mode == CCmode || mode == CCCmode);
10195       suffix = "b";
10196       break;
10197     case GE:
10198       switch (mode)
10199         {
10200         case CCNOmode:
10201         case CCGOCmode:
10202           suffix = "ns";
10203           break;
10204
10205         case CCmode:
10206         case CCGCmode:
10207           suffix = "ge";
10208           break;
10209
10210         default:
10211           gcc_unreachable ();
10212         }
10213       break;
10214     case GEU:
10215       /* ??? As above.  */
10216       gcc_assert (mode == CCmode || mode == CCCmode);
10217       suffix = fp ? "nb" : "ae";
10218       break;
10219     case LE:
10220       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
10221       suffix = "le";
10222       break;
10223     case LEU:
10224       /* ??? As above.  */
10225       if (mode == CCmode)
10226         suffix = "be";
10227       else if (mode == CCCmode)
10228         suffix = fp ? "nb" : "ae";
10229       else
10230         gcc_unreachable ();
10231       break;
10232     case UNORDERED:
10233       suffix = fp ? "u" : "p";
10234       break;
10235     case ORDERED:
10236       suffix = fp ? "nu" : "np";
10237       break;
10238     default:
10239       gcc_unreachable ();
10240     }
10241   fputs (suffix, file);
10242 }
10243
10244 /* Print the name of register X to FILE based on its machine mode and number.
10245    If CODE is 'w', pretend the mode is HImode.
10246    If CODE is 'b', pretend the mode is QImode.
10247    If CODE is 'k', pretend the mode is SImode.
10248    If CODE is 'q', pretend the mode is DImode.
10249    If CODE is 'x', pretend the mode is V4SFmode.
10250    If CODE is 't', pretend the mode is V8SFmode.
10251    If CODE is 'h', pretend the reg is the 'high' byte register.
10252    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
10253    If CODE is 'd', duplicate the operand for AVX instruction.
10254  */
10255
10256 void
10257 print_reg (rtx x, int code, FILE *file)
10258 {
10259   const char *reg;
10260   bool duplicated = code == 'd' && TARGET_AVX;
10261
10262   gcc_assert (x == pc_rtx
10263               || (REGNO (x) != ARG_POINTER_REGNUM
10264                   && REGNO (x) != FRAME_POINTER_REGNUM
10265                   && REGNO (x) != FLAGS_REG
10266                   && REGNO (x) != FPSR_REG
10267                   && REGNO (x) != FPCR_REG));
10268
10269   if (ASSEMBLER_DIALECT == ASM_ATT)
10270     putc ('%', file);
10271
10272   if (x == pc_rtx)
10273     {
10274       gcc_assert (TARGET_64BIT);
10275       fputs ("rip", file);
10276       return;
10277     }
10278
10279   if (code == 'w' || MMX_REG_P (x))
10280     code = 2;
10281   else if (code == 'b')
10282     code = 1;
10283   else if (code == 'k')
10284     code = 4;
10285   else if (code == 'q')
10286     code = 8;
10287   else if (code == 'y')
10288     code = 3;
10289   else if (code == 'h')
10290     code = 0;
10291   else if (code == 'x')
10292     code = 16;
10293   else if (code == 't')
10294     code = 32;
10295   else
10296     code = GET_MODE_SIZE (GET_MODE (x));
10297
10298   /* Irritatingly, AMD extended registers use different naming convention
10299      from the normal registers.  */
10300   if (REX_INT_REG_P (x))
10301     {
10302       gcc_assert (TARGET_64BIT);
10303       switch (code)
10304         {
10305           case 0:
10306             error ("extended registers have no high halves");
10307             break;
10308           case 1:
10309             fprintf (file, "r%ib", REGNO (x) - FIRST_REX_INT_REG + 8);
10310             break;
10311           case 2:
10312             fprintf (file, "r%iw", REGNO (x) - FIRST_REX_INT_REG + 8);
10313             break;
10314           case 4:
10315             fprintf (file, "r%id", REGNO (x) - FIRST_REX_INT_REG + 8);
10316             break;
10317           case 8:
10318             fprintf (file, "r%i", REGNO (x) - FIRST_REX_INT_REG + 8);
10319             break;
10320           default:
10321             error ("unsupported operand size for extended register");
10322             break;
10323         }
10324       return;
10325     }
10326
10327   reg = NULL;
10328   switch (code)
10329     {
10330     case 3:
10331       if (STACK_TOP_P (x))
10332         {
10333           reg = "st(0)";
10334           break;
10335         }
10336       /* FALLTHRU */
10337     case 8:
10338     case 4:
10339     case 12:
10340       if (! ANY_FP_REG_P (x))
10341         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
10342       /* FALLTHRU */
10343     case 16:
10344     case 2:
10345     normal:
10346       reg = hi_reg_name[REGNO (x)];
10347       break;
10348     case 1:
10349       if (REGNO (x) >= ARRAY_SIZE (qi_reg_name))
10350         goto normal;
10351       reg = qi_reg_name[REGNO (x)];
10352       break;
10353     case 0:
10354       if (REGNO (x) >= ARRAY_SIZE (qi_high_reg_name))
10355         goto normal;
10356       reg = qi_high_reg_name[REGNO (x)];
10357       break;
10358     case 32:
10359       if (SSE_REG_P (x))
10360         {
10361           gcc_assert (!duplicated);
10362           putc ('y', file);
10363           fputs (hi_reg_name[REGNO (x)] + 1, file);
10364           return;
10365         }
10366       break;
10367     default:
10368       gcc_unreachable ();
10369     }
10370
10371   fputs (reg, file);
10372   if (duplicated)
10373     {
10374       if (ASSEMBLER_DIALECT == ASM_ATT)
10375         fprintf (file, ", %%%s", reg);
10376       else
10377         fprintf (file, ", %s", reg);
10378     }
10379 }
10380
10381 /* Locate some local-dynamic symbol still in use by this function
10382    so that we can print its name in some tls_local_dynamic_base
10383    pattern.  */
10384
10385 static int
10386 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
10387 {
10388   rtx x = *px;
10389
10390   if (GET_CODE (x) == SYMBOL_REF
10391       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
10392     {
10393       cfun->machine->some_ld_name = XSTR (x, 0);
10394       return 1;
10395     }
10396
10397   return 0;
10398 }
10399
10400 static const char *
10401 get_some_local_dynamic_name (void)
10402 {
10403   rtx insn;
10404
10405   if (cfun->machine->some_ld_name)
10406     return cfun->machine->some_ld_name;
10407
10408   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
10409     if (INSN_P (insn)
10410         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
10411       return cfun->machine->some_ld_name;
10412
10413   gcc_unreachable ();
10414 }
10415
10416 /* Meaning of CODE:
10417    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
10418    C -- print opcode suffix for set/cmov insn.
10419    c -- like C, but print reversed condition
10420    E,e -- likewise, but for compare-and-branch fused insn.
10421    F,f -- likewise, but for floating-point.
10422    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
10423         otherwise nothing
10424    R -- print the prefix for register names.
10425    z -- print the opcode suffix for the size of the current operand.
10426    * -- print a star (in certain assembler syntax)
10427    A -- print an absolute memory reference.
10428    w -- print the operand as if it's a "word" (HImode) even if it isn't.
10429    s -- print a shift double count, followed by the assemblers argument
10430         delimiter.
10431    b -- print the QImode name of the register for the indicated operand.
10432         %b0 would print %al if operands[0] is reg 0.
10433    w --  likewise, print the HImode name of the register.
10434    k --  likewise, print the SImode name of the register.
10435    q --  likewise, print the DImode name of the register.
10436    x --  likewise, print the V4SFmode name of the register.
10437    t --  likewise, print the V8SFmode name of the register.
10438    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
10439    y -- print "st(0)" instead of "st" as a register.
10440    d -- print duplicated register operand for AVX instruction.
10441    D -- print condition for SSE cmp instruction.
10442    P -- if PIC, print an @PLT suffix.
10443    X -- don't print any sort of PIC '@' suffix for a symbol.
10444    & -- print some in-use local-dynamic symbol name.
10445    H -- print a memory address offset by 8; used for sse high-parts
10446    Y -- print condition for SSE5 com* instruction.
10447    + -- print a branch hint as 'cs' or 'ds' prefix
10448    ; -- print a semicolon (after prefixes due to bug in older gas).
10449  */
10450
10451 void
10452 print_operand (FILE *file, rtx x, int code)
10453 {
10454   if (code)
10455     {
10456       switch (code)
10457         {
10458         case '*':
10459           if (ASSEMBLER_DIALECT == ASM_ATT)
10460             putc ('*', file);
10461           return;
10462
10463         case '&':
10464           assemble_name (file, get_some_local_dynamic_name ());
10465           return;
10466
10467         case 'A':
10468           switch (ASSEMBLER_DIALECT)
10469             {
10470             case ASM_ATT:
10471               putc ('*', file);
10472               break;
10473
10474             case ASM_INTEL:
10475               /* Intel syntax. For absolute addresses, registers should not
10476                  be surrounded by braces.  */
10477               if (!REG_P (x))
10478                 {
10479                   putc ('[', file);
10480                   PRINT_OPERAND (file, x, 0);
10481                   putc (']', file);
10482                   return;
10483                 }
10484               break;
10485
10486             default:
10487               gcc_unreachable ();
10488             }
10489
10490           PRINT_OPERAND (file, x, 0);
10491           return;
10492
10493
10494         case 'L':
10495           if (ASSEMBLER_DIALECT == ASM_ATT)
10496             putc ('l', file);
10497           return;
10498
10499         case 'W':
10500           if (ASSEMBLER_DIALECT == ASM_ATT)
10501             putc ('w', file);
10502           return;
10503
10504         case 'B':
10505           if (ASSEMBLER_DIALECT == ASM_ATT)
10506             putc ('b', file);
10507           return;
10508
10509         case 'Q':
10510           if (ASSEMBLER_DIALECT == ASM_ATT)
10511             putc ('l', file);
10512           return;
10513
10514         case 'S':
10515           if (ASSEMBLER_DIALECT == ASM_ATT)
10516             putc ('s', file);
10517           return;
10518
10519         case 'T':
10520           if (ASSEMBLER_DIALECT == ASM_ATT)
10521             putc ('t', file);
10522           return;
10523
10524         case 'z':
10525           /* 387 opcodes don't get size suffixes if the operands are
10526              registers.  */
10527           if (STACK_REG_P (x))
10528             return;
10529
10530           /* Likewise if using Intel opcodes.  */
10531           if (ASSEMBLER_DIALECT == ASM_INTEL)
10532             return;
10533
10534           /* This is the size of op from size of operand.  */
10535           switch (GET_MODE_SIZE (GET_MODE (x)))
10536             {
10537             case 1:
10538               putc ('b', file);
10539               return;
10540
10541             case 2:
10542               if (MEM_P (x))
10543                 {
10544 #ifdef HAVE_GAS_FILDS_FISTS
10545                   putc ('s', file);
10546 #endif
10547                   return;
10548                 }
10549               else
10550                 putc ('w', file);
10551               return;
10552
10553             case 4:
10554               if (GET_MODE (x) == SFmode)
10555                 {
10556                   putc ('s', file);
10557                   return;
10558                 }
10559               else
10560                 putc ('l', file);
10561               return;
10562
10563             case 12:
10564             case 16:
10565               putc ('t', file);
10566               return;
10567
10568             case 8:
10569               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
10570                 {
10571                   if (MEM_P (x))
10572                     {
10573 #ifdef GAS_MNEMONICS
10574                       putc ('q', file);
10575 #else
10576                       putc ('l', file);
10577                       putc ('l', file);
10578 #endif
10579                     }
10580                   else
10581                     putc ('q', file);
10582                 }
10583               else
10584                 putc ('l', file);
10585               return;
10586
10587             default:
10588               gcc_unreachable ();
10589             }
10590
10591         case 'd':
10592         case 'b':
10593         case 'w':
10594         case 'k':
10595         case 'q':
10596         case 'h':
10597         case 't':
10598         case 'y':
10599         case 'x':
10600         case 'X':
10601         case 'P':
10602           break;
10603
10604         case 's':
10605           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
10606             {
10607               PRINT_OPERAND (file, x, 0);
10608               fputs (", ", file);
10609             }
10610           return;
10611
10612         case 'D':
10613           /* Little bit of braindamage here.  The SSE compare instructions
10614              does use completely different names for the comparisons that the
10615              fp conditional moves.  */
10616           if (TARGET_AVX)
10617             {
10618               switch (GET_CODE (x))
10619                 {
10620                 case EQ:
10621                   fputs ("eq", file);
10622                   break;
10623                 case UNEQ:
10624                   fputs ("eq_us", file);
10625                   break;
10626                 case LT:
10627                   fputs ("lt", file);
10628                   break;
10629                 case UNLT:
10630                   fputs ("nge", file);
10631                   break;
10632                 case LE:
10633                   fputs ("le", file);
10634                   break;
10635                 case UNLE:
10636                   fputs ("ngt", file);
10637                   break;
10638                 case UNORDERED:
10639                   fputs ("unord", file);
10640                   break;
10641                 case NE:
10642                   fputs ("neq", file);
10643                   break;
10644                 case LTGT:
10645                   fputs ("neq_oq", file);
10646                   break;
10647                 case GE:
10648                   fputs ("ge", file);
10649                   break;
10650                 case UNGE:
10651                   fputs ("nlt", file);
10652                   break;
10653                 case GT:
10654                   fputs ("gt", file);
10655                   break;
10656                 case UNGT:
10657                   fputs ("nle", file);
10658                   break;
10659                 case ORDERED:
10660                   fputs ("ord", file);
10661                   break;
10662                 default:
10663                   gcc_unreachable ();
10664                 }
10665             }
10666           else
10667             {
10668               switch (GET_CODE (x))
10669                 {
10670                 case EQ:
10671                 case UNEQ:
10672                   fputs ("eq", file);
10673                   break;
10674                 case LT:
10675                 case UNLT:
10676                   fputs ("lt", file);
10677                   break;
10678                 case LE:
10679                 case UNLE:
10680                   fputs ("le", file);
10681                   break;
10682                 case UNORDERED:
10683                   fputs ("unord", file);
10684                   break;
10685                 case NE:
10686                 case LTGT:
10687                   fputs ("neq", file);
10688                   break;
10689                 case UNGE:
10690                 case GE:
10691                   fputs ("nlt", file);
10692                   break;
10693                 case UNGT:
10694                 case GT:
10695                   fputs ("nle", file);
10696                   break;
10697                 case ORDERED:
10698                   fputs ("ord", file);
10699                   break;
10700                 default:
10701                   gcc_unreachable ();
10702                 }
10703             }
10704           return;
10705         case 'O':
10706 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10707           if (ASSEMBLER_DIALECT == ASM_ATT)
10708             {
10709               switch (GET_MODE (x))
10710                 {
10711                 case HImode: putc ('w', file); break;
10712                 case SImode:
10713                 case SFmode: putc ('l', file); break;
10714                 case DImode:
10715                 case DFmode: putc ('q', file); break;
10716                 default: gcc_unreachable ();
10717                 }
10718               putc ('.', file);
10719             }
10720 #endif
10721           return;
10722         case 'C':
10723           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
10724           return;
10725         case 'F':
10726 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10727           if (ASSEMBLER_DIALECT == ASM_ATT)
10728             putc ('.', file);
10729 #endif
10730           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
10731           return;
10732
10733           /* Like above, but reverse condition */
10734         case 'c':
10735           /* Check to see if argument to %c is really a constant
10736              and not a condition code which needs to be reversed.  */
10737           if (!COMPARISON_P (x))
10738           {
10739             output_operand_lossage ("operand is neither a constant nor a condition code, invalid operand code 'c'");
10740              return;
10741           }
10742           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
10743           return;
10744         case 'f':
10745 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10746           if (ASSEMBLER_DIALECT == ASM_ATT)
10747             putc ('.', file);
10748 #endif
10749           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
10750           return;
10751
10752         case 'E':
10753           put_condition_code (GET_CODE (x), CCmode, 0, 0, file);
10754           return;
10755
10756         case 'e':
10757           put_condition_code (GET_CODE (x), CCmode, 1, 0, file);
10758           return;
10759
10760         case 'H':
10761           /* It doesn't actually matter what mode we use here, as we're
10762              only going to use this for printing.  */
10763           x = adjust_address_nv (x, DImode, 8);
10764           break;
10765
10766         case '+':
10767           {
10768             rtx x;
10769
10770             if (!optimize
10771                 || optimize_function_for_size_p (cfun) || !TARGET_BRANCH_PREDICTION_HINTS)
10772               return;
10773
10774             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
10775             if (x)
10776               {
10777                 int pred_val = INTVAL (XEXP (x, 0));
10778
10779                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
10780                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
10781                   {
10782                     int taken = pred_val > REG_BR_PROB_BASE / 2;
10783                     int cputaken = final_forward_branch_p (current_output_insn) == 0;
10784
10785                     /* Emit hints only in the case default branch prediction
10786                        heuristics would fail.  */
10787                     if (taken != cputaken)
10788                       {
10789                         /* We use 3e (DS) prefix for taken branches and
10790                            2e (CS) prefix for not taken branches.  */
10791                         if (taken)
10792                           fputs ("ds ; ", file);
10793                         else
10794                           fputs ("cs ; ", file);
10795                       }
10796                   }
10797               }
10798             return;
10799           }
10800
10801         case 'Y':
10802           switch (GET_CODE (x))
10803             {
10804             case NE:
10805               fputs ("neq", file);
10806               break;
10807             case EQ:
10808               fputs ("eq", file);
10809               break;
10810             case GE:
10811             case GEU:
10812               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
10813               break;
10814             case GT:
10815             case GTU:
10816               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
10817               break;
10818             case LE:
10819             case LEU:
10820               fputs ("le", file);
10821               break;
10822             case LT:
10823             case LTU:
10824               fputs ("lt", file);
10825               break;
10826             case UNORDERED:
10827               fputs ("unord", file);
10828               break;
10829             case ORDERED:
10830               fputs ("ord", file);
10831               break;
10832             case UNEQ:
10833               fputs ("ueq", file);
10834               break;
10835             case UNGE:
10836               fputs ("nlt", file);
10837               break;
10838             case UNGT:
10839               fputs ("nle", file);
10840               break;
10841             case UNLE:
10842               fputs ("ule", file);
10843               break;
10844             case UNLT:
10845               fputs ("ult", file);
10846               break;
10847             case LTGT:
10848               fputs ("une", file);
10849               break;
10850             default:
10851               gcc_unreachable ();
10852             }
10853           return;
10854
10855         case ';':
10856 #if TARGET_MACHO
10857           fputs (" ; ", file);
10858 #else
10859           fputc (' ', file);
10860 #endif
10861           return;
10862
10863         default:
10864             output_operand_lossage ("invalid operand code '%c'", code);
10865         }
10866     }
10867
10868   if (REG_P (x))
10869     print_reg (x, code, file);
10870
10871   else if (MEM_P (x))
10872     {
10873       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
10874       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
10875           && GET_MODE (x) != BLKmode)
10876         {
10877           const char * size;
10878           switch (GET_MODE_SIZE (GET_MODE (x)))
10879             {
10880             case 1: size = "BYTE"; break;
10881             case 2: size = "WORD"; break;
10882             case 4: size = "DWORD"; break;
10883             case 8: size = "QWORD"; break;
10884             case 12: size = "XWORD"; break;
10885             case 16:
10886               if (GET_MODE (x) == XFmode)
10887                 size = "XWORD";
10888               else
10889                 size = "XMMWORD";
10890               break;
10891             default:
10892               gcc_unreachable ();
10893             }
10894
10895           /* Check for explicit size override (codes 'b', 'w' and 'k')  */
10896           if (code == 'b')
10897             size = "BYTE";
10898           else if (code == 'w')
10899             size = "WORD";
10900           else if (code == 'k')
10901             size = "DWORD";
10902
10903           fputs (size, file);
10904           fputs (" PTR ", file);
10905         }
10906
10907       x = XEXP (x, 0);
10908       /* Avoid (%rip) for call operands.  */
10909       if (CONSTANT_ADDRESS_P (x) && code == 'P'
10910           && !CONST_INT_P (x))
10911         output_addr_const (file, x);
10912       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
10913         output_operand_lossage ("invalid constraints for operand");
10914       else
10915         output_address (x);
10916     }
10917
10918   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
10919     {
10920       REAL_VALUE_TYPE r;
10921       long l;
10922
10923       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
10924       REAL_VALUE_TO_TARGET_SINGLE (r, l);
10925
10926       if (ASSEMBLER_DIALECT == ASM_ATT)
10927         putc ('$', file);
10928       fprintf (file, "0x%08lx", (long unsigned int) l);
10929     }
10930
10931   /* These float cases don't actually occur as immediate operands.  */
10932   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
10933     {
10934       char dstr[30];
10935
10936       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
10937       fprintf (file, "%s", dstr);
10938     }
10939
10940   else if (GET_CODE (x) == CONST_DOUBLE
10941            && GET_MODE (x) == XFmode)
10942     {
10943       char dstr[30];
10944
10945       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
10946       fprintf (file, "%s", dstr);
10947     }
10948
10949   else
10950     {
10951       /* We have patterns that allow zero sets of memory, for instance.
10952          In 64-bit mode, we should probably support all 8-byte vectors,
10953          since we can in fact encode that into an immediate.  */
10954       if (GET_CODE (x) == CONST_VECTOR)
10955         {
10956           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
10957           x = const0_rtx;
10958         }
10959
10960       if (code != 'P')
10961         {
10962           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
10963             {
10964               if (ASSEMBLER_DIALECT == ASM_ATT)
10965                 putc ('$', file);
10966             }
10967           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
10968                    || GET_CODE (x) == LABEL_REF)
10969             {
10970               if (ASSEMBLER_DIALECT == ASM_ATT)
10971                 putc ('$', file);
10972               else
10973                 fputs ("OFFSET FLAT:", file);
10974             }
10975         }
10976       if (CONST_INT_P (x))
10977         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
10978       else if (flag_pic)
10979         output_pic_addr_const (file, x, code);
10980       else
10981         output_addr_const (file, x);
10982     }
10983 }
10984 \f
10985 /* Print a memory operand whose address is ADDR.  */
10986
10987 void
10988 print_operand_address (FILE *file, rtx addr)
10989 {
10990   struct ix86_address parts;
10991   rtx base, index, disp;
10992   int scale;
10993   int ok = ix86_decompose_address (addr, &parts);
10994
10995   gcc_assert (ok);
10996
10997   base = parts.base;
10998   index = parts.index;
10999   disp = parts.disp;
11000   scale = parts.scale;
11001
11002   switch (parts.seg)
11003     {
11004     case SEG_DEFAULT:
11005       break;
11006     case SEG_FS:
11007     case SEG_GS:
11008       if (ASSEMBLER_DIALECT == ASM_ATT)
11009         putc ('%', file);
11010       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
11011       break;
11012     default:
11013       gcc_unreachable ();
11014     }
11015
11016   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
11017   if (TARGET_64BIT && !base && !index)
11018     {
11019       rtx symbol = disp;
11020
11021       if (GET_CODE (disp) == CONST
11022           && GET_CODE (XEXP (disp, 0)) == PLUS
11023           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11024         symbol = XEXP (XEXP (disp, 0), 0);
11025
11026       if (GET_CODE (symbol) == LABEL_REF
11027           || (GET_CODE (symbol) == SYMBOL_REF
11028               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
11029         base = pc_rtx;
11030     }
11031   if (!base && !index)
11032     {
11033       /* Displacement only requires special attention.  */
11034
11035       if (CONST_INT_P (disp))
11036         {
11037           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
11038             fputs ("ds:", file);
11039           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
11040         }
11041       else if (flag_pic)
11042         output_pic_addr_const (file, disp, 0);
11043       else
11044         output_addr_const (file, disp);
11045     }
11046   else
11047     {
11048       if (ASSEMBLER_DIALECT == ASM_ATT)
11049         {
11050           if (disp)
11051             {
11052               if (flag_pic)
11053                 output_pic_addr_const (file, disp, 0);
11054               else if (GET_CODE (disp) == LABEL_REF)
11055                 output_asm_label (disp);
11056               else
11057                 output_addr_const (file, disp);
11058             }
11059
11060           putc ('(', file);
11061           if (base)
11062             print_reg (base, 0, file);
11063           if (index)
11064             {
11065               putc (',', file);
11066               print_reg (index, 0, file);
11067               if (scale != 1)
11068                 fprintf (file, ",%d", scale);
11069             }
11070           putc (')', file);
11071         }
11072       else
11073         {
11074           rtx offset = NULL_RTX;
11075
11076           if (disp)
11077             {
11078               /* Pull out the offset of a symbol; print any symbol itself.  */
11079               if (GET_CODE (disp) == CONST
11080                   && GET_CODE (XEXP (disp, 0)) == PLUS
11081                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11082                 {
11083                   offset = XEXP (XEXP (disp, 0), 1);
11084                   disp = gen_rtx_CONST (VOIDmode,
11085                                         XEXP (XEXP (disp, 0), 0));
11086                 }
11087
11088               if (flag_pic)
11089                 output_pic_addr_const (file, disp, 0);
11090               else if (GET_CODE (disp) == LABEL_REF)
11091                 output_asm_label (disp);
11092               else if (CONST_INT_P (disp))
11093                 offset = disp;
11094               else
11095                 output_addr_const (file, disp);
11096             }
11097
11098           putc ('[', file);
11099           if (base)
11100             {
11101               print_reg (base, 0, file);
11102               if (offset)
11103                 {
11104                   if (INTVAL (offset) >= 0)
11105                     putc ('+', file);
11106                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11107                 }
11108             }
11109           else if (offset)
11110             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11111           else
11112             putc ('0', file);
11113
11114           if (index)
11115             {
11116               putc ('+', file);
11117               print_reg (index, 0, file);
11118               if (scale != 1)
11119                 fprintf (file, "*%d", scale);
11120             }
11121           putc (']', file);
11122         }
11123     }
11124 }
11125
11126 bool
11127 output_addr_const_extra (FILE *file, rtx x)
11128 {
11129   rtx op;
11130
11131   if (GET_CODE (x) != UNSPEC)
11132     return false;
11133
11134   op = XVECEXP (x, 0, 0);
11135   switch (XINT (x, 1))
11136     {
11137     case UNSPEC_GOTTPOFF:
11138       output_addr_const (file, op);
11139       /* FIXME: This might be @TPOFF in Sun ld.  */
11140       fputs ("@GOTTPOFF", file);
11141       break;
11142     case UNSPEC_TPOFF:
11143       output_addr_const (file, op);
11144       fputs ("@TPOFF", file);
11145       break;
11146     case UNSPEC_NTPOFF:
11147       output_addr_const (file, op);
11148       if (TARGET_64BIT)
11149         fputs ("@TPOFF", file);
11150       else
11151         fputs ("@NTPOFF", file);
11152       break;
11153     case UNSPEC_DTPOFF:
11154       output_addr_const (file, op);
11155       fputs ("@DTPOFF", file);
11156       break;
11157     case UNSPEC_GOTNTPOFF:
11158       output_addr_const (file, op);
11159       if (TARGET_64BIT)
11160         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
11161                "@GOTTPOFF(%rip)" : "@GOTTPOFF[rip]", file);
11162       else
11163         fputs ("@GOTNTPOFF", file);
11164       break;
11165     case UNSPEC_INDNTPOFF:
11166       output_addr_const (file, op);
11167       fputs ("@INDNTPOFF", file);
11168       break;
11169
11170     default:
11171       return false;
11172     }
11173
11174   return true;
11175 }
11176 \f
11177 /* Split one or more DImode RTL references into pairs of SImode
11178    references.  The RTL can be REG, offsettable MEM, integer constant, or
11179    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11180    split and "num" is its length.  lo_half and hi_half are output arrays
11181    that parallel "operands".  */
11182
11183 void
11184 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11185 {
11186   while (num--)
11187     {
11188       rtx op = operands[num];
11189
11190       /* simplify_subreg refuse to split volatile memory addresses,
11191          but we still have to handle it.  */
11192       if (MEM_P (op))
11193         {
11194           lo_half[num] = adjust_address (op, SImode, 0);
11195           hi_half[num] = adjust_address (op, SImode, 4);
11196         }
11197       else
11198         {
11199           lo_half[num] = simplify_gen_subreg (SImode, op,
11200                                               GET_MODE (op) == VOIDmode
11201                                               ? DImode : GET_MODE (op), 0);
11202           hi_half[num] = simplify_gen_subreg (SImode, op,
11203                                               GET_MODE (op) == VOIDmode
11204                                               ? DImode : GET_MODE (op), 4);
11205         }
11206     }
11207 }
11208 /* Split one or more TImode RTL references into pairs of DImode
11209    references.  The RTL can be REG, offsettable MEM, integer constant, or
11210    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11211    split and "num" is its length.  lo_half and hi_half are output arrays
11212    that parallel "operands".  */
11213
11214 void
11215 split_ti (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11216 {
11217   while (num--)
11218     {
11219       rtx op = operands[num];
11220
11221       /* simplify_subreg refuse to split volatile memory addresses, but we
11222          still have to handle it.  */
11223       if (MEM_P (op))
11224         {
11225           lo_half[num] = adjust_address (op, DImode, 0);
11226           hi_half[num] = adjust_address (op, DImode, 8);
11227         }
11228       else
11229         {
11230           lo_half[num] = simplify_gen_subreg (DImode, op, TImode, 0);
11231           hi_half[num] = simplify_gen_subreg (DImode, op, TImode, 8);
11232         }
11233     }
11234 }
11235 \f
11236 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
11237    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
11238    is the expression of the binary operation.  The output may either be
11239    emitted here, or returned to the caller, like all output_* functions.
11240
11241    There is no guarantee that the operands are the same mode, as they
11242    might be within FLOAT or FLOAT_EXTEND expressions.  */
11243
11244 #ifndef SYSV386_COMPAT
11245 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
11246    wants to fix the assemblers because that causes incompatibility
11247    with gcc.  No-one wants to fix gcc because that causes
11248    incompatibility with assemblers...  You can use the option of
11249    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
11250 #define SYSV386_COMPAT 1
11251 #endif
11252
11253 const char *
11254 output_387_binary_op (rtx insn, rtx *operands)
11255 {
11256   static char buf[40];
11257   const char *p;
11258   const char *ssep;
11259   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
11260
11261 #ifdef ENABLE_CHECKING
11262   /* Even if we do not want to check the inputs, this documents input
11263      constraints.  Which helps in understanding the following code.  */
11264   if (STACK_REG_P (operands[0])
11265       && ((REG_P (operands[1])
11266            && REGNO (operands[0]) == REGNO (operands[1])
11267            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
11268           || (REG_P (operands[2])
11269               && REGNO (operands[0]) == REGNO (operands[2])
11270               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
11271       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
11272     ; /* ok */
11273   else
11274     gcc_assert (is_sse);
11275 #endif
11276
11277   switch (GET_CODE (operands[3]))
11278     {
11279     case PLUS:
11280       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11281           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11282         p = "fiadd";
11283       else
11284         p = "fadd";
11285       ssep = "vadd";
11286       break;
11287
11288     case MINUS:
11289       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11290           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11291         p = "fisub";
11292       else
11293         p = "fsub";
11294       ssep = "vsub";
11295       break;
11296
11297     case MULT:
11298       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11299           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11300         p = "fimul";
11301       else
11302         p = "fmul";
11303       ssep = "vmul";
11304       break;
11305
11306     case DIV:
11307       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11308           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11309         p = "fidiv";
11310       else
11311         p = "fdiv";
11312       ssep = "vdiv";
11313       break;
11314
11315     default:
11316       gcc_unreachable ();
11317     }
11318
11319   if (is_sse)
11320    {
11321      if (TARGET_AVX)
11322        {
11323          strcpy (buf, ssep);
11324          if (GET_MODE (operands[0]) == SFmode)
11325            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
11326          else
11327            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
11328        }
11329      else
11330        {
11331          strcpy (buf, ssep + 1);
11332          if (GET_MODE (operands[0]) == SFmode)
11333            strcat (buf, "ss\t{%2, %0|%0, %2}");
11334          else
11335            strcat (buf, "sd\t{%2, %0|%0, %2}");
11336        }
11337       return buf;
11338    }
11339   strcpy (buf, p);
11340
11341   switch (GET_CODE (operands[3]))
11342     {
11343     case MULT:
11344     case PLUS:
11345       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
11346         {
11347           rtx temp = operands[2];
11348           operands[2] = operands[1];
11349           operands[1] = temp;
11350         }
11351
11352       /* know operands[0] == operands[1].  */
11353
11354       if (MEM_P (operands[2]))
11355         {
11356           p = "%z2\t%2";
11357           break;
11358         }
11359
11360       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11361         {
11362           if (STACK_TOP_P (operands[0]))
11363             /* How is it that we are storing to a dead operand[2]?
11364                Well, presumably operands[1] is dead too.  We can't
11365                store the result to st(0) as st(0) gets popped on this
11366                instruction.  Instead store to operands[2] (which I
11367                think has to be st(1)).  st(1) will be popped later.
11368                gcc <= 2.8.1 didn't have this check and generated
11369                assembly code that the Unixware assembler rejected.  */
11370             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
11371           else
11372             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11373           break;
11374         }
11375
11376       if (STACK_TOP_P (operands[0]))
11377         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
11378       else
11379         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
11380       break;
11381
11382     case MINUS:
11383     case DIV:
11384       if (MEM_P (operands[1]))
11385         {
11386           p = "r%z1\t%1";
11387           break;
11388         }
11389
11390       if (MEM_P (operands[2]))
11391         {
11392           p = "%z2\t%2";
11393           break;
11394         }
11395
11396       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11397         {
11398 #if SYSV386_COMPAT
11399           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
11400              derived assemblers, confusingly reverse the direction of
11401              the operation for fsub{r} and fdiv{r} when the
11402              destination register is not st(0).  The Intel assembler
11403              doesn't have this brain damage.  Read !SYSV386_COMPAT to
11404              figure out what the hardware really does.  */
11405           if (STACK_TOP_P (operands[0]))
11406             p = "{p\t%0, %2|rp\t%2, %0}";
11407           else
11408             p = "{rp\t%2, %0|p\t%0, %2}";
11409 #else
11410           if (STACK_TOP_P (operands[0]))
11411             /* As above for fmul/fadd, we can't store to st(0).  */
11412             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
11413           else
11414             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11415 #endif
11416           break;
11417         }
11418
11419       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
11420         {
11421 #if SYSV386_COMPAT
11422           if (STACK_TOP_P (operands[0]))
11423             p = "{rp\t%0, %1|p\t%1, %0}";
11424           else
11425             p = "{p\t%1, %0|rp\t%0, %1}";
11426 #else
11427           if (STACK_TOP_P (operands[0]))
11428             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
11429           else
11430             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
11431 #endif
11432           break;
11433         }
11434
11435       if (STACK_TOP_P (operands[0]))
11436         {
11437           if (STACK_TOP_P (operands[1]))
11438             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
11439           else
11440             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
11441           break;
11442         }
11443       else if (STACK_TOP_P (operands[1]))
11444         {
11445 #if SYSV386_COMPAT
11446           p = "{\t%1, %0|r\t%0, %1}";
11447 #else
11448           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
11449 #endif
11450         }
11451       else
11452         {
11453 #if SYSV386_COMPAT
11454           p = "{r\t%2, %0|\t%0, %2}";
11455 #else
11456           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
11457 #endif
11458         }
11459       break;
11460
11461     default:
11462       gcc_unreachable ();
11463     }
11464
11465   strcat (buf, p);
11466   return buf;
11467 }
11468
11469 /* Return needed mode for entity in optimize_mode_switching pass.  */
11470
11471 int
11472 ix86_mode_needed (int entity, rtx insn)
11473 {
11474   enum attr_i387_cw mode;
11475
11476   /* The mode UNINITIALIZED is used to store control word after a
11477      function call or ASM pattern.  The mode ANY specify that function
11478      has no requirements on the control word and make no changes in the
11479      bits we are interested in.  */
11480
11481   if (CALL_P (insn)
11482       || (NONJUMP_INSN_P (insn)
11483           && (asm_noperands (PATTERN (insn)) >= 0
11484               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
11485     return I387_CW_UNINITIALIZED;
11486
11487   if (recog_memoized (insn) < 0)
11488     return I387_CW_ANY;
11489
11490   mode = get_attr_i387_cw (insn);
11491
11492   switch (entity)
11493     {
11494     case I387_TRUNC:
11495       if (mode == I387_CW_TRUNC)
11496         return mode;
11497       break;
11498
11499     case I387_FLOOR:
11500       if (mode == I387_CW_FLOOR)
11501         return mode;
11502       break;
11503
11504     case I387_CEIL:
11505       if (mode == I387_CW_CEIL)
11506         return mode;
11507       break;
11508
11509     case I387_MASK_PM:
11510       if (mode == I387_CW_MASK_PM)
11511         return mode;
11512       break;
11513
11514     default:
11515       gcc_unreachable ();
11516     }
11517
11518   return I387_CW_ANY;
11519 }
11520
11521 /* Output code to initialize control word copies used by trunc?f?i and
11522    rounding patterns.  CURRENT_MODE is set to current control word,
11523    while NEW_MODE is set to new control word.  */
11524
11525 void
11526 emit_i387_cw_initialization (int mode)
11527 {
11528   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
11529   rtx new_mode;
11530
11531   enum ix86_stack_slot slot;
11532
11533   rtx reg = gen_reg_rtx (HImode);
11534
11535   emit_insn (gen_x86_fnstcw_1 (stored_mode));
11536   emit_move_insn (reg, copy_rtx (stored_mode));
11537
11538   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
11539       || optimize_function_for_size_p (cfun))
11540     {
11541       switch (mode)
11542         {
11543         case I387_CW_TRUNC:
11544           /* round toward zero (truncate) */
11545           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
11546           slot = SLOT_CW_TRUNC;
11547           break;
11548
11549         case I387_CW_FLOOR:
11550           /* round down toward -oo */
11551           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11552           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
11553           slot = SLOT_CW_FLOOR;
11554           break;
11555
11556         case I387_CW_CEIL:
11557           /* round up toward +oo */
11558           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11559           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
11560           slot = SLOT_CW_CEIL;
11561           break;
11562
11563         case I387_CW_MASK_PM:
11564           /* mask precision exception for nearbyint() */
11565           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11566           slot = SLOT_CW_MASK_PM;
11567           break;
11568
11569         default:
11570           gcc_unreachable ();
11571         }
11572     }
11573   else
11574     {
11575       switch (mode)
11576         {
11577         case I387_CW_TRUNC:
11578           /* round toward zero (truncate) */
11579           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
11580           slot = SLOT_CW_TRUNC;
11581           break;
11582
11583         case I387_CW_FLOOR:
11584           /* round down toward -oo */
11585           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
11586           slot = SLOT_CW_FLOOR;
11587           break;
11588
11589         case I387_CW_CEIL:
11590           /* round up toward +oo */
11591           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
11592           slot = SLOT_CW_CEIL;
11593           break;
11594
11595         case I387_CW_MASK_PM:
11596           /* mask precision exception for nearbyint() */
11597           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11598           slot = SLOT_CW_MASK_PM;
11599           break;
11600
11601         default:
11602           gcc_unreachable ();
11603         }
11604     }
11605
11606   gcc_assert (slot < MAX_386_STACK_LOCALS);
11607
11608   new_mode = assign_386_stack_local (HImode, slot);
11609   emit_move_insn (new_mode, reg);
11610 }
11611
11612 /* Output code for INSN to convert a float to a signed int.  OPERANDS
11613    are the insn operands.  The output may be [HSD]Imode and the input
11614    operand may be [SDX]Fmode.  */
11615
11616 const char *
11617 output_fix_trunc (rtx insn, rtx *operands, int fisttp)
11618 {
11619   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11620   int dimode_p = GET_MODE (operands[0]) == DImode;
11621   int round_mode = get_attr_i387_cw (insn);
11622
11623   /* Jump through a hoop or two for DImode, since the hardware has no
11624      non-popping instruction.  We used to do this a different way, but
11625      that was somewhat fragile and broke with post-reload splitters.  */
11626   if ((dimode_p || fisttp) && !stack_top_dies)
11627     output_asm_insn ("fld\t%y1", operands);
11628
11629   gcc_assert (STACK_TOP_P (operands[1]));
11630   gcc_assert (MEM_P (operands[0]));
11631   gcc_assert (GET_MODE (operands[1]) != TFmode);
11632
11633   if (fisttp)
11634       output_asm_insn ("fisttp%z0\t%0", operands);
11635   else
11636     {
11637       if (round_mode != I387_CW_ANY)
11638         output_asm_insn ("fldcw\t%3", operands);
11639       if (stack_top_dies || dimode_p)
11640         output_asm_insn ("fistp%z0\t%0", operands);
11641       else
11642         output_asm_insn ("fist%z0\t%0", operands);
11643       if (round_mode != I387_CW_ANY)
11644         output_asm_insn ("fldcw\t%2", operands);
11645     }
11646
11647   return "";
11648 }
11649
11650 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
11651    have the values zero or one, indicates the ffreep insn's operand
11652    from the OPERANDS array.  */
11653
11654 static const char *
11655 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
11656 {
11657   if (TARGET_USE_FFREEP)
11658 #if HAVE_AS_IX86_FFREEP
11659     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
11660 #else
11661     {
11662       static char retval[] = ".word\t0xc_df";
11663       int regno = REGNO (operands[opno]);
11664
11665       gcc_assert (FP_REGNO_P (regno));
11666
11667       retval[9] = '0' + (regno - FIRST_STACK_REG);
11668       return retval;
11669     }
11670 #endif
11671
11672   return opno ? "fstp\t%y1" : "fstp\t%y0";
11673 }
11674
11675
11676 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
11677    should be used.  UNORDERED_P is true when fucom should be used.  */
11678
11679 const char *
11680 output_fp_compare (rtx insn, rtx *operands, int eflags_p, int unordered_p)
11681 {
11682   int stack_top_dies;
11683   rtx cmp_op0, cmp_op1;
11684   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
11685
11686   if (eflags_p)
11687     {
11688       cmp_op0 = operands[0];
11689       cmp_op1 = operands[1];
11690     }
11691   else
11692     {
11693       cmp_op0 = operands[1];
11694       cmp_op1 = operands[2];
11695     }
11696
11697   if (is_sse)
11698     {
11699       static const char ucomiss[] = "vucomiss\t{%1, %0|%0, %1}";
11700       static const char ucomisd[] = "vucomisd\t{%1, %0|%0, %1}";
11701       static const char comiss[] = "vcomiss\t{%1, %0|%0, %1}";
11702       static const char comisd[] = "vcomisd\t{%1, %0|%0, %1}";
11703
11704       if (GET_MODE (operands[0]) == SFmode)
11705         if (unordered_p)
11706           return &ucomiss[TARGET_AVX ? 0 : 1];
11707         else
11708           return &comiss[TARGET_AVX ? 0 : 1];
11709       else
11710         if (unordered_p)
11711           return &ucomisd[TARGET_AVX ? 0 : 1];
11712         else
11713           return &comisd[TARGET_AVX ? 0 : 1];
11714     }
11715
11716   gcc_assert (STACK_TOP_P (cmp_op0));
11717
11718   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11719
11720   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
11721     {
11722       if (stack_top_dies)
11723         {
11724           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
11725           return output_387_ffreep (operands, 1);
11726         }
11727       else
11728         return "ftst\n\tfnstsw\t%0";
11729     }
11730
11731   if (STACK_REG_P (cmp_op1)
11732       && stack_top_dies
11733       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
11734       && REGNO (cmp_op1) != FIRST_STACK_REG)
11735     {
11736       /* If both the top of the 387 stack dies, and the other operand
11737          is also a stack register that dies, then this must be a
11738          `fcompp' float compare */
11739
11740       if (eflags_p)
11741         {
11742           /* There is no double popping fcomi variant.  Fortunately,
11743              eflags is immune from the fstp's cc clobbering.  */
11744           if (unordered_p)
11745             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
11746           else
11747             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
11748           return output_387_ffreep (operands, 0);
11749         }
11750       else
11751         {
11752           if (unordered_p)
11753             return "fucompp\n\tfnstsw\t%0";
11754           else
11755             return "fcompp\n\tfnstsw\t%0";
11756         }
11757     }
11758   else
11759     {
11760       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
11761
11762       static const char * const alt[16] =
11763       {
11764         "fcom%z2\t%y2\n\tfnstsw\t%0",
11765         "fcomp%z2\t%y2\n\tfnstsw\t%0",
11766         "fucom%z2\t%y2\n\tfnstsw\t%0",
11767         "fucomp%z2\t%y2\n\tfnstsw\t%0",
11768
11769         "ficom%z2\t%y2\n\tfnstsw\t%0",
11770         "ficomp%z2\t%y2\n\tfnstsw\t%0",
11771         NULL,
11772         NULL,
11773
11774         "fcomi\t{%y1, %0|%0, %y1}",
11775         "fcomip\t{%y1, %0|%0, %y1}",
11776         "fucomi\t{%y1, %0|%0, %y1}",
11777         "fucomip\t{%y1, %0|%0, %y1}",
11778
11779         NULL,
11780         NULL,
11781         NULL,
11782         NULL
11783       };
11784
11785       int mask;
11786       const char *ret;
11787
11788       mask  = eflags_p << 3;
11789       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
11790       mask |= unordered_p << 1;
11791       mask |= stack_top_dies;
11792
11793       gcc_assert (mask < 16);
11794       ret = alt[mask];
11795       gcc_assert (ret);
11796
11797       return ret;
11798     }
11799 }
11800
11801 void
11802 ix86_output_addr_vec_elt (FILE *file, int value)
11803 {
11804   const char *directive = ASM_LONG;
11805
11806 #ifdef ASM_QUAD
11807   if (TARGET_64BIT)
11808     directive = ASM_QUAD;
11809 #else
11810   gcc_assert (!TARGET_64BIT);
11811 #endif
11812
11813   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
11814 }
11815
11816 void
11817 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
11818 {
11819   const char *directive = ASM_LONG;
11820
11821 #ifdef ASM_QUAD
11822   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
11823     directive = ASM_QUAD;
11824 #else
11825   gcc_assert (!TARGET_64BIT);
11826 #endif
11827   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
11828   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
11829     fprintf (file, "%s%s%d-%s%d\n",
11830              directive, LPREFIX, value, LPREFIX, rel);
11831   else if (HAVE_AS_GOTOFF_IN_DATA)
11832     fprintf (file, "%s%s%d@GOTOFF\n", ASM_LONG, LPREFIX, value);
11833 #if TARGET_MACHO
11834   else if (TARGET_MACHO)
11835     {
11836       fprintf (file, "%s%s%d-", ASM_LONG, LPREFIX, value);
11837       machopic_output_function_base_name (file);
11838       fprintf(file, "\n");
11839     }
11840 #endif
11841   else
11842     asm_fprintf (file, "%s%U%s+[.-%s%d]\n",
11843                  ASM_LONG, GOT_SYMBOL_NAME, LPREFIX, value);
11844 }
11845 \f
11846 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
11847    for the target.  */
11848
11849 void
11850 ix86_expand_clear (rtx dest)
11851 {
11852   rtx tmp;
11853
11854   /* We play register width games, which are only valid after reload.  */
11855   gcc_assert (reload_completed);
11856
11857   /* Avoid HImode and its attendant prefix byte.  */
11858   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
11859     dest = gen_rtx_REG (SImode, REGNO (dest));
11860   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
11861
11862   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
11863   if (reload_completed && (!TARGET_USE_MOV0 || optimize_insn_for_speed_p ()))
11864     {
11865       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
11866       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
11867     }
11868
11869   emit_insn (tmp);
11870 }
11871
11872 /* X is an unchanging MEM.  If it is a constant pool reference, return
11873    the constant pool rtx, else NULL.  */
11874
11875 rtx
11876 maybe_get_pool_constant (rtx x)
11877 {
11878   x = ix86_delegitimize_address (XEXP (x, 0));
11879
11880   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
11881     return get_pool_constant (x);
11882
11883   return NULL_RTX;
11884 }
11885
11886 void
11887 ix86_expand_move (enum machine_mode mode, rtx operands[])
11888 {
11889   rtx op0, op1;
11890   enum tls_model model;
11891
11892   op0 = operands[0];
11893   op1 = operands[1];
11894
11895   if (GET_CODE (op1) == SYMBOL_REF)
11896     {
11897       model = SYMBOL_REF_TLS_MODEL (op1);
11898       if (model)
11899         {
11900           op1 = legitimize_tls_address (op1, model, true);
11901           op1 = force_operand (op1, op0);
11902           if (op1 == op0)
11903             return;
11904         }
11905       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
11906                && SYMBOL_REF_DLLIMPORT_P (op1))
11907         op1 = legitimize_dllimport_symbol (op1, false);
11908     }
11909   else if (GET_CODE (op1) == CONST
11910            && GET_CODE (XEXP (op1, 0)) == PLUS
11911            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
11912     {
11913       rtx addend = XEXP (XEXP (op1, 0), 1);
11914       rtx symbol = XEXP (XEXP (op1, 0), 0);
11915       rtx tmp = NULL;
11916
11917       model = SYMBOL_REF_TLS_MODEL (symbol);
11918       if (model)
11919         tmp = legitimize_tls_address (symbol, model, true);
11920       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
11921                && SYMBOL_REF_DLLIMPORT_P (symbol))
11922         tmp = legitimize_dllimport_symbol (symbol, true);
11923
11924       if (tmp)
11925         {
11926           tmp = force_operand (tmp, NULL);
11927           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
11928                                      op0, 1, OPTAB_DIRECT);
11929           if (tmp == op0)
11930             return;
11931         }
11932     }
11933
11934   if (flag_pic && mode == Pmode && symbolic_operand (op1, Pmode))
11935     {
11936       if (TARGET_MACHO && !TARGET_64BIT)
11937         {
11938 #if TARGET_MACHO
11939           if (MACHOPIC_PURE)
11940             {
11941               rtx temp = ((reload_in_progress
11942                            || ((op0 && REG_P (op0))
11943                                && mode == Pmode))
11944                           ? op0 : gen_reg_rtx (Pmode));
11945               op1 = machopic_indirect_data_reference (op1, temp);
11946               op1 = machopic_legitimize_pic_address (op1, mode,
11947                                                      temp == op1 ? 0 : temp);
11948             }
11949           else if (MACHOPIC_INDIRECT)
11950             op1 = machopic_indirect_data_reference (op1, 0);
11951           if (op0 == op1)
11952             return;
11953 #endif
11954         }
11955       else
11956         {
11957           if (MEM_P (op0))
11958             op1 = force_reg (Pmode, op1);
11959           else if (!TARGET_64BIT || !x86_64_movabs_operand (op1, Pmode))
11960             {
11961               rtx reg = !can_create_pseudo_p () ? op0 : NULL_RTX;
11962               op1 = legitimize_pic_address (op1, reg);
11963               if (op0 == op1)
11964                 return;
11965             }
11966         }
11967     }
11968   else
11969     {
11970       if (MEM_P (op0)
11971           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
11972               || !push_operand (op0, mode))
11973           && MEM_P (op1))
11974         op1 = force_reg (mode, op1);
11975
11976       if (push_operand (op0, mode)
11977           && ! general_no_elim_operand (op1, mode))
11978         op1 = copy_to_mode_reg (mode, op1);
11979
11980       /* Force large constants in 64bit compilation into register
11981          to get them CSEed.  */
11982       if (can_create_pseudo_p ()
11983           && (mode == DImode) && TARGET_64BIT
11984           && immediate_operand (op1, mode)
11985           && !x86_64_zext_immediate_operand (op1, VOIDmode)
11986           && !register_operand (op0, mode)
11987           && optimize)
11988         op1 = copy_to_mode_reg (mode, op1);
11989
11990       if (can_create_pseudo_p ()
11991           && FLOAT_MODE_P (mode)
11992           && GET_CODE (op1) == CONST_DOUBLE)
11993         {
11994           /* If we are loading a floating point constant to a register,
11995              force the value to memory now, since we'll get better code
11996              out the back end.  */
11997
11998           op1 = validize_mem (force_const_mem (mode, op1));
11999           if (!register_operand (op0, mode))
12000             {
12001               rtx temp = gen_reg_rtx (mode);
12002               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
12003               emit_move_insn (op0, temp);
12004               return;
12005             }
12006         }
12007     }
12008
12009   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12010 }
12011
12012 void
12013 ix86_expand_vector_move (enum machine_mode mode, rtx operands[])
12014 {
12015   rtx op0 = operands[0], op1 = operands[1];
12016   unsigned int align = GET_MODE_ALIGNMENT (mode);
12017
12018   /* Force constants other than zero into memory.  We do not know how
12019      the instructions used to build constants modify the upper 64 bits
12020      of the register, once we have that information we may be able
12021      to handle some of them more efficiently.  */
12022   if (can_create_pseudo_p ()
12023       && register_operand (op0, mode)
12024       && (CONSTANT_P (op1)
12025           || (GET_CODE (op1) == SUBREG
12026               && CONSTANT_P (SUBREG_REG (op1))))
12027       && standard_sse_constant_p (op1) <= 0)
12028     op1 = validize_mem (force_const_mem (mode, op1));
12029
12030   /* We need to check memory alignment for SSE mode since attribute
12031      can make operands unaligned.  */
12032   if (can_create_pseudo_p ()
12033       && SSE_REG_MODE_P (mode)
12034       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
12035           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
12036     {
12037       rtx tmp[2];
12038
12039       /* ix86_expand_vector_move_misalign() does not like constants ... */
12040       if (CONSTANT_P (op1)
12041           || (GET_CODE (op1) == SUBREG
12042               && CONSTANT_P (SUBREG_REG (op1))))
12043         op1 = validize_mem (force_const_mem (mode, op1));
12044
12045       /* ... nor both arguments in memory.  */
12046       if (!register_operand (op0, mode)
12047           && !register_operand (op1, mode))
12048         op1 = force_reg (mode, op1);
12049
12050       tmp[0] = op0; tmp[1] = op1;
12051       ix86_expand_vector_move_misalign (mode, tmp);
12052       return;
12053     }
12054
12055   /* Make operand1 a register if it isn't already.  */
12056   if (can_create_pseudo_p ()
12057       && !register_operand (op0, mode)
12058       && !register_operand (op1, mode))
12059     {
12060       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
12061       return;
12062     }
12063
12064   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12065 }
12066
12067 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
12068    straight to ix86_expand_vector_move.  */
12069 /* Code generation for scalar reg-reg moves of single and double precision data:
12070      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
12071        movaps reg, reg
12072      else
12073        movss reg, reg
12074      if (x86_sse_partial_reg_dependency == true)
12075        movapd reg, reg
12076      else
12077        movsd reg, reg
12078
12079    Code generation for scalar loads of double precision data:
12080      if (x86_sse_split_regs == true)
12081        movlpd mem, reg      (gas syntax)
12082      else
12083        movsd mem, reg
12084
12085    Code generation for unaligned packed loads of single precision data
12086    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
12087      if (x86_sse_unaligned_move_optimal)
12088        movups mem, reg
12089
12090      if (x86_sse_partial_reg_dependency == true)
12091        {
12092          xorps  reg, reg
12093          movlps mem, reg
12094          movhps mem+8, reg
12095        }
12096      else
12097        {
12098          movlps mem, reg
12099          movhps mem+8, reg
12100        }
12101
12102    Code generation for unaligned packed loads of double precision data
12103    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
12104      if (x86_sse_unaligned_move_optimal)
12105        movupd mem, reg
12106
12107      if (x86_sse_split_regs == true)
12108        {
12109          movlpd mem, reg
12110          movhpd mem+8, reg
12111        }
12112      else
12113        {
12114          movsd  mem, reg
12115          movhpd mem+8, reg
12116        }
12117  */
12118
12119 void
12120 ix86_expand_vector_move_misalign (enum machine_mode mode, rtx operands[])
12121 {
12122   rtx op0, op1, m;
12123
12124   op0 = operands[0];
12125   op1 = operands[1];
12126
12127   if (TARGET_AVX)
12128     {
12129       switch (GET_MODE_CLASS (mode))
12130         {
12131         case MODE_VECTOR_INT:
12132         case MODE_INT:
12133           switch (GET_MODE_SIZE (mode))
12134             {
12135             case 16:
12136               op0 = gen_lowpart (V16QImode, op0);
12137               op1 = gen_lowpart (V16QImode, op1);
12138               emit_insn (gen_avx_movdqu (op0, op1));
12139               break;
12140             case 32:
12141               op0 = gen_lowpart (V32QImode, op0);
12142               op1 = gen_lowpart (V32QImode, op1);
12143               emit_insn (gen_avx_movdqu256 (op0, op1));
12144               break;
12145             default:
12146               gcc_unreachable ();
12147             }
12148           break;
12149         case MODE_VECTOR_FLOAT:
12150           op0 = gen_lowpart (mode, op0);
12151           op1 = gen_lowpart (mode, op1);
12152
12153           switch (mode)
12154             { 
12155             case V4SFmode:
12156               emit_insn (gen_avx_movups (op0, op1));
12157               break;
12158             case V8SFmode:
12159               emit_insn (gen_avx_movups256 (op0, op1));
12160               break;
12161             case V2DFmode:
12162               emit_insn (gen_avx_movupd (op0, op1));
12163               break;
12164             case V4DFmode:
12165               emit_insn (gen_avx_movupd256 (op0, op1));
12166               break;
12167             default:
12168               gcc_unreachable ();
12169             }
12170           break;
12171
12172         default:
12173           gcc_unreachable ();
12174         }
12175
12176       return;
12177     }
12178
12179   if (MEM_P (op1))
12180     {
12181       /* If we're optimizing for size, movups is the smallest.  */
12182       if (optimize_insn_for_size_p ())
12183         {
12184           op0 = gen_lowpart (V4SFmode, op0);
12185           op1 = gen_lowpart (V4SFmode, op1);
12186           emit_insn (gen_sse_movups (op0, op1));
12187           return;
12188         }
12189
12190       /* ??? If we have typed data, then it would appear that using
12191          movdqu is the only way to get unaligned data loaded with
12192          integer type.  */
12193       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12194         {
12195           op0 = gen_lowpart (V16QImode, op0);
12196           op1 = gen_lowpart (V16QImode, op1);
12197           emit_insn (gen_sse2_movdqu (op0, op1));
12198           return;
12199         }
12200
12201       if (TARGET_SSE2 && mode == V2DFmode)
12202         {
12203           rtx zero;
12204
12205           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12206             {
12207               op0 = gen_lowpart (V2DFmode, op0);
12208               op1 = gen_lowpart (V2DFmode, op1);
12209               emit_insn (gen_sse2_movupd (op0, op1));
12210               return;
12211             }
12212
12213           /* When SSE registers are split into halves, we can avoid
12214              writing to the top half twice.  */
12215           if (TARGET_SSE_SPLIT_REGS)
12216             {
12217               emit_clobber (op0);
12218               zero = op0;
12219             }
12220           else
12221             {
12222               /* ??? Not sure about the best option for the Intel chips.
12223                  The following would seem to satisfy; the register is
12224                  entirely cleared, breaking the dependency chain.  We
12225                  then store to the upper half, with a dependency depth
12226                  of one.  A rumor has it that Intel recommends two movsd
12227                  followed by an unpacklpd, but this is unconfirmed.  And
12228                  given that the dependency depth of the unpacklpd would
12229                  still be one, I'm not sure why this would be better.  */
12230               zero = CONST0_RTX (V2DFmode);
12231             }
12232
12233           m = adjust_address (op1, DFmode, 0);
12234           emit_insn (gen_sse2_loadlpd (op0, zero, m));
12235           m = adjust_address (op1, DFmode, 8);
12236           emit_insn (gen_sse2_loadhpd (op0, op0, m));
12237         }
12238       else
12239         {
12240           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12241             {
12242               op0 = gen_lowpart (V4SFmode, op0);
12243               op1 = gen_lowpart (V4SFmode, op1);
12244               emit_insn (gen_sse_movups (op0, op1));
12245               return;
12246             }
12247
12248           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
12249             emit_move_insn (op0, CONST0_RTX (mode));
12250           else
12251             emit_clobber (op0);
12252
12253           if (mode != V4SFmode)
12254             op0 = gen_lowpart (V4SFmode, op0);
12255           m = adjust_address (op1, V2SFmode, 0);
12256           emit_insn (gen_sse_loadlps (op0, op0, m));
12257           m = adjust_address (op1, V2SFmode, 8);
12258           emit_insn (gen_sse_loadhps (op0, op0, m));
12259         }
12260     }
12261   else if (MEM_P (op0))
12262     {
12263       /* If we're optimizing for size, movups is the smallest.  */
12264       if (optimize_insn_for_size_p ())
12265         {
12266           op0 = gen_lowpart (V4SFmode, op0);
12267           op1 = gen_lowpart (V4SFmode, op1);
12268           emit_insn (gen_sse_movups (op0, op1));
12269           return;
12270         }
12271
12272       /* ??? Similar to above, only less clear because of quote
12273          typeless stores unquote.  */
12274       if (TARGET_SSE2 && !TARGET_SSE_TYPELESS_STORES
12275           && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12276         {
12277           op0 = gen_lowpart (V16QImode, op0);
12278           op1 = gen_lowpart (V16QImode, op1);
12279           emit_insn (gen_sse2_movdqu (op0, op1));
12280           return;
12281         }
12282
12283       if (TARGET_SSE2 && mode == V2DFmode)
12284         {
12285           m = adjust_address (op0, DFmode, 0);
12286           emit_insn (gen_sse2_storelpd (m, op1));
12287           m = adjust_address (op0, DFmode, 8);
12288           emit_insn (gen_sse2_storehpd (m, op1));
12289         }
12290       else
12291         {
12292           if (mode != V4SFmode)
12293             op1 = gen_lowpart (V4SFmode, op1);
12294           m = adjust_address (op0, V2SFmode, 0);
12295           emit_insn (gen_sse_storelps (m, op1));
12296           m = adjust_address (op0, V2SFmode, 8);
12297           emit_insn (gen_sse_storehps (m, op1));
12298         }
12299     }
12300   else
12301     gcc_unreachable ();
12302 }
12303
12304 /* Expand a push in MODE.  This is some mode for which we do not support
12305    proper push instructions, at least from the registers that we expect
12306    the value to live in.  */
12307
12308 void
12309 ix86_expand_push (enum machine_mode mode, rtx x)
12310 {
12311   rtx tmp;
12312
12313   tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
12314                              GEN_INT (-GET_MODE_SIZE (mode)),
12315                              stack_pointer_rtx, 1, OPTAB_DIRECT);
12316   if (tmp != stack_pointer_rtx)
12317     emit_move_insn (stack_pointer_rtx, tmp);
12318
12319   tmp = gen_rtx_MEM (mode, stack_pointer_rtx);
12320   emit_move_insn (tmp, x);
12321 }
12322
12323 /* Helper function of ix86_fixup_binary_operands to canonicalize
12324    operand order.  Returns true if the operands should be swapped.  */
12325
12326 static bool
12327 ix86_swap_binary_operands_p (enum rtx_code code, enum machine_mode mode,
12328                              rtx operands[])
12329 {
12330   rtx dst = operands[0];
12331   rtx src1 = operands[1];
12332   rtx src2 = operands[2];
12333
12334   /* If the operation is not commutative, we can't do anything.  */
12335   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
12336     return false;
12337
12338   /* Highest priority is that src1 should match dst.  */
12339   if (rtx_equal_p (dst, src1))
12340     return false;
12341   if (rtx_equal_p (dst, src2))
12342     return true;
12343
12344   /* Next highest priority is that immediate constants come second.  */
12345   if (immediate_operand (src2, mode))
12346     return false;
12347   if (immediate_operand (src1, mode))
12348     return true;
12349
12350   /* Lowest priority is that memory references should come second.  */
12351   if (MEM_P (src2))
12352     return false;
12353   if (MEM_P (src1))
12354     return true;
12355
12356   return false;
12357 }
12358
12359
12360 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
12361    destination to use for the operation.  If different from the true
12362    destination in operands[0], a copy operation will be required.  */
12363
12364 rtx
12365 ix86_fixup_binary_operands (enum rtx_code code, enum machine_mode mode,
12366                             rtx operands[])
12367 {
12368   rtx dst = operands[0];
12369   rtx src1 = operands[1];
12370   rtx src2 = operands[2];
12371
12372   /* Canonicalize operand order.  */
12373   if (ix86_swap_binary_operands_p (code, mode, operands))
12374     {
12375       rtx temp;
12376
12377       /* It is invalid to swap operands of different modes.  */
12378       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
12379
12380       temp = src1;
12381       src1 = src2;
12382       src2 = temp;
12383     }
12384
12385   /* Both source operands cannot be in memory.  */
12386   if (MEM_P (src1) && MEM_P (src2))
12387     {
12388       /* Optimization: Only read from memory once.  */
12389       if (rtx_equal_p (src1, src2))
12390         {
12391           src2 = force_reg (mode, src2);
12392           src1 = src2;
12393         }
12394       else
12395         src2 = force_reg (mode, src2);
12396     }
12397
12398   /* If the destination is memory, and we do not have matching source
12399      operands, do things in registers.  */
12400   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12401     dst = gen_reg_rtx (mode);
12402
12403   /* Source 1 cannot be a constant.  */
12404   if (CONSTANT_P (src1))
12405     src1 = force_reg (mode, src1);
12406
12407   /* Source 1 cannot be a non-matching memory.  */
12408   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12409     src1 = force_reg (mode, src1);
12410
12411   operands[1] = src1;
12412   operands[2] = src2;
12413   return dst;
12414 }
12415
12416 /* Similarly, but assume that the destination has already been
12417    set up properly.  */
12418
12419 void
12420 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
12421                                     enum machine_mode mode, rtx operands[])
12422 {
12423   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
12424   gcc_assert (dst == operands[0]);
12425 }
12426
12427 /* Attempt to expand a binary operator.  Make the expansion closer to the
12428    actual machine, then just general_operand, which will allow 3 separate
12429    memory references (one output, two input) in a single insn.  */
12430
12431 void
12432 ix86_expand_binary_operator (enum rtx_code code, enum machine_mode mode,
12433                              rtx operands[])
12434 {
12435   rtx src1, src2, dst, op, clob;
12436
12437   dst = ix86_fixup_binary_operands (code, mode, operands);
12438   src1 = operands[1];
12439   src2 = operands[2];
12440
12441  /* Emit the instruction.  */
12442
12443   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
12444   if (reload_in_progress)
12445     {
12446       /* Reload doesn't know about the flags register, and doesn't know that
12447          it doesn't want to clobber it.  We can only do this with PLUS.  */
12448       gcc_assert (code == PLUS);
12449       emit_insn (op);
12450     }
12451   else
12452     {
12453       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12454       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12455     }
12456
12457   /* Fix up the destination if needed.  */
12458   if (dst != operands[0])
12459     emit_move_insn (operands[0], dst);
12460 }
12461
12462 /* Return TRUE or FALSE depending on whether the binary operator meets the
12463    appropriate constraints.  */
12464
12465 int
12466 ix86_binary_operator_ok (enum rtx_code code, enum machine_mode mode,
12467                          rtx operands[3])
12468 {
12469   rtx dst = operands[0];
12470   rtx src1 = operands[1];
12471   rtx src2 = operands[2];
12472
12473   /* Both source operands cannot be in memory.  */
12474   if (MEM_P (src1) && MEM_P (src2))
12475     return 0;
12476
12477   /* Canonicalize operand order for commutative operators.  */
12478   if (ix86_swap_binary_operands_p (code, mode, operands))
12479     {
12480       rtx temp = src1;
12481       src1 = src2;
12482       src2 = temp;
12483     }
12484
12485   /* If the destination is memory, we must have a matching source operand.  */
12486   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12487       return 0;
12488
12489   /* Source 1 cannot be a constant.  */
12490   if (CONSTANT_P (src1))
12491     return 0;
12492
12493   /* Source 1 cannot be a non-matching memory.  */
12494   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12495     return 0;
12496
12497   return 1;
12498 }
12499
12500 /* Attempt to expand a unary operator.  Make the expansion closer to the
12501    actual machine, then just general_operand, which will allow 2 separate
12502    memory references (one output, one input) in a single insn.  */
12503
12504 void
12505 ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode,
12506                             rtx operands[])
12507 {
12508   int matching_memory;
12509   rtx src, dst, op, clob;
12510
12511   dst = operands[0];
12512   src = operands[1];
12513
12514   /* If the destination is memory, and we do not have matching source
12515      operands, do things in registers.  */
12516   matching_memory = 0;
12517   if (MEM_P (dst))
12518     {
12519       if (rtx_equal_p (dst, src))
12520         matching_memory = 1;
12521       else
12522         dst = gen_reg_rtx (mode);
12523     }
12524
12525   /* When source operand is memory, destination must match.  */
12526   if (MEM_P (src) && !matching_memory)
12527     src = force_reg (mode, src);
12528
12529   /* Emit the instruction.  */
12530
12531   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
12532   if (reload_in_progress || code == NOT)
12533     {
12534       /* Reload doesn't know about the flags register, and doesn't know that
12535          it doesn't want to clobber it.  */
12536       gcc_assert (code == NOT);
12537       emit_insn (op);
12538     }
12539   else
12540     {
12541       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12542       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12543     }
12544
12545   /* Fix up the destination if needed.  */
12546   if (dst != operands[0])
12547     emit_move_insn (operands[0], dst);
12548 }
12549
12550 /* Return TRUE or FALSE depending on whether the unary operator meets the
12551    appropriate constraints.  */
12552
12553 int
12554 ix86_unary_operator_ok (enum rtx_code code ATTRIBUTE_UNUSED,
12555                         enum machine_mode mode ATTRIBUTE_UNUSED,
12556                         rtx operands[2] ATTRIBUTE_UNUSED)
12557 {
12558   /* If one of operands is memory, source and destination must match.  */
12559   if ((MEM_P (operands[0])
12560        || MEM_P (operands[1]))
12561       && ! rtx_equal_p (operands[0], operands[1]))
12562     return FALSE;
12563   return TRUE;
12564 }
12565
12566 /* Post-reload splitter for converting an SF or DFmode value in an
12567    SSE register into an unsigned SImode.  */
12568
12569 void
12570 ix86_split_convert_uns_si_sse (rtx operands[])
12571 {
12572   enum machine_mode vecmode;
12573   rtx value, large, zero_or_two31, input, two31, x;
12574
12575   large = operands[1];
12576   zero_or_two31 = operands[2];
12577   input = operands[3];
12578   two31 = operands[4];
12579   vecmode = GET_MODE (large);
12580   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
12581
12582   /* Load up the value into the low element.  We must ensure that the other
12583      elements are valid floats -- zero is the easiest such value.  */
12584   if (MEM_P (input))
12585     {
12586       if (vecmode == V4SFmode)
12587         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
12588       else
12589         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
12590     }
12591   else
12592     {
12593       input = gen_rtx_REG (vecmode, REGNO (input));
12594       emit_move_insn (value, CONST0_RTX (vecmode));
12595       if (vecmode == V4SFmode)
12596         emit_insn (gen_sse_movss (value, value, input));
12597       else
12598         emit_insn (gen_sse2_movsd (value, value, input));
12599     }
12600
12601   emit_move_insn (large, two31);
12602   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
12603
12604   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
12605   emit_insn (gen_rtx_SET (VOIDmode, large, x));
12606
12607   x = gen_rtx_AND (vecmode, zero_or_two31, large);
12608   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
12609
12610   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
12611   emit_insn (gen_rtx_SET (VOIDmode, value, x));
12612
12613   large = gen_rtx_REG (V4SImode, REGNO (large));
12614   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
12615
12616   x = gen_rtx_REG (V4SImode, REGNO (value));
12617   if (vecmode == V4SFmode)
12618     emit_insn (gen_sse2_cvttps2dq (x, value));
12619   else
12620     emit_insn (gen_sse2_cvttpd2dq (x, value));
12621   value = x;
12622
12623   emit_insn (gen_xorv4si3 (value, value, large));
12624 }
12625
12626 /* Convert an unsigned DImode value into a DFmode, using only SSE.
12627    Expects the 64-bit DImode to be supplied in a pair of integral
12628    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
12629    -mfpmath=sse, !optimize_size only.  */
12630
12631 void
12632 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
12633 {
12634   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
12635   rtx int_xmm, fp_xmm;
12636   rtx biases, exponents;
12637   rtx x;
12638
12639   int_xmm = gen_reg_rtx (V4SImode);
12640   if (TARGET_INTER_UNIT_MOVES)
12641     emit_insn (gen_movdi_to_sse (int_xmm, input));
12642   else if (TARGET_SSE_SPLIT_REGS)
12643     {
12644       emit_clobber (int_xmm);
12645       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
12646     }
12647   else
12648     {
12649       x = gen_reg_rtx (V2DImode);
12650       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
12651       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
12652     }
12653
12654   x = gen_rtx_CONST_VECTOR (V4SImode,
12655                             gen_rtvec (4, GEN_INT (0x43300000UL),
12656                                        GEN_INT (0x45300000UL),
12657                                        const0_rtx, const0_rtx));
12658   exponents = validize_mem (force_const_mem (V4SImode, x));
12659
12660   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
12661   emit_insn (gen_sse2_punpckldq (int_xmm, int_xmm, exponents));
12662
12663   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
12664      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
12665      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
12666      (0x1.0p84 + double(fp_value_hi_xmm)).
12667      Note these exponents differ by 32.  */
12668
12669   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
12670
12671   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
12672      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
12673   real_ldexp (&bias_lo_rvt, &dconst1, 52);
12674   real_ldexp (&bias_hi_rvt, &dconst1, 84);
12675   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
12676   x = const_double_from_real_value (bias_hi_rvt, DFmode);
12677   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
12678   biases = validize_mem (force_const_mem (V2DFmode, biases));
12679   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
12680
12681   /* Add the upper and lower DFmode values together.  */
12682   if (TARGET_SSE3)
12683     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
12684   else
12685     {
12686       x = copy_to_mode_reg (V2DFmode, fp_xmm);
12687       emit_insn (gen_sse2_unpckhpd (fp_xmm, fp_xmm, fp_xmm));
12688       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
12689     }
12690
12691   ix86_expand_vector_extract (false, target, fp_xmm, 0);
12692 }
12693
12694 /* Not used, but eases macroization of patterns.  */
12695 void
12696 ix86_expand_convert_uns_sixf_sse (rtx target ATTRIBUTE_UNUSED,
12697                                   rtx input ATTRIBUTE_UNUSED)
12698 {
12699   gcc_unreachable ();
12700 }
12701
12702 /* Convert an unsigned SImode value into a DFmode.  Only currently used
12703    for SSE, but applicable anywhere.  */
12704
12705 void
12706 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
12707 {
12708   REAL_VALUE_TYPE TWO31r;
12709   rtx x, fp;
12710
12711   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
12712                            NULL, 1, OPTAB_DIRECT);
12713
12714   fp = gen_reg_rtx (DFmode);
12715   emit_insn (gen_floatsidf2 (fp, x));
12716
12717   real_ldexp (&TWO31r, &dconst1, 31);
12718   x = const_double_from_real_value (TWO31r, DFmode);
12719
12720   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
12721   if (x != target)
12722     emit_move_insn (target, x);
12723 }
12724
12725 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
12726    32-bit mode; otherwise we have a direct convert instruction.  */
12727
12728 void
12729 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
12730 {
12731   REAL_VALUE_TYPE TWO32r;
12732   rtx fp_lo, fp_hi, x;
12733
12734   fp_lo = gen_reg_rtx (DFmode);
12735   fp_hi = gen_reg_rtx (DFmode);
12736
12737   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
12738
12739   real_ldexp (&TWO32r, &dconst1, 32);
12740   x = const_double_from_real_value (TWO32r, DFmode);
12741   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
12742
12743   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
12744
12745   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
12746                            0, OPTAB_DIRECT);
12747   if (x != target)
12748     emit_move_insn (target, x);
12749 }
12750
12751 /* Convert an unsigned SImode value into a SFmode, using only SSE.
12752    For x86_32, -mfpmath=sse, !optimize_size only.  */
12753 void
12754 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
12755 {
12756   REAL_VALUE_TYPE ONE16r;
12757   rtx fp_hi, fp_lo, int_hi, int_lo, x;
12758
12759   real_ldexp (&ONE16r, &dconst1, 16);
12760   x = const_double_from_real_value (ONE16r, SFmode);
12761   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
12762                                       NULL, 0, OPTAB_DIRECT);
12763   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
12764                                       NULL, 0, OPTAB_DIRECT);
12765   fp_hi = gen_reg_rtx (SFmode);
12766   fp_lo = gen_reg_rtx (SFmode);
12767   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
12768   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
12769   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
12770                                0, OPTAB_DIRECT);
12771   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
12772                                0, OPTAB_DIRECT);
12773   if (!rtx_equal_p (target, fp_hi))
12774     emit_move_insn (target, fp_hi);
12775 }
12776
12777 /* A subroutine of ix86_build_signbit_mask_vector.  If VECT is true,
12778    then replicate the value for all elements of the vector
12779    register.  */
12780
12781 rtx
12782 ix86_build_const_vector (enum machine_mode mode, bool vect, rtx value)
12783 {
12784   rtvec v;
12785   switch (mode)
12786     {
12787     case SImode:
12788       gcc_assert (vect);
12789       v = gen_rtvec (4, value, value, value, value);
12790       return gen_rtx_CONST_VECTOR (V4SImode, v);
12791
12792     case DImode:
12793       gcc_assert (vect);
12794       v = gen_rtvec (2, value, value);
12795       return gen_rtx_CONST_VECTOR (V2DImode, v);
12796
12797     case SFmode:
12798       if (vect)
12799         v = gen_rtvec (4, value, value, value, value);
12800       else
12801         v = gen_rtvec (4, value, CONST0_RTX (SFmode),
12802                        CONST0_RTX (SFmode), CONST0_RTX (SFmode));
12803       return gen_rtx_CONST_VECTOR (V4SFmode, v);
12804
12805     case DFmode:
12806       if (vect)
12807         v = gen_rtvec (2, value, value);
12808       else
12809         v = gen_rtvec (2, value, CONST0_RTX (DFmode));
12810       return gen_rtx_CONST_VECTOR (V2DFmode, v);
12811
12812     default:
12813       gcc_unreachable ();
12814     }
12815 }
12816
12817 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
12818    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
12819    for an SSE register.  If VECT is true, then replicate the mask for
12820    all elements of the vector register.  If INVERT is true, then create
12821    a mask excluding the sign bit.  */
12822
12823 rtx
12824 ix86_build_signbit_mask (enum machine_mode mode, bool vect, bool invert)
12825 {
12826   enum machine_mode vec_mode, imode;
12827   HOST_WIDE_INT hi, lo;
12828   int shift = 63;
12829   rtx v;
12830   rtx mask;
12831
12832   /* Find the sign bit, sign extended to 2*HWI.  */
12833   switch (mode)
12834     {
12835     case SImode:
12836     case SFmode:
12837       imode = SImode;
12838       vec_mode = (mode == SImode) ? V4SImode : V4SFmode;
12839       lo = 0x80000000, hi = lo < 0;
12840       break;
12841
12842     case DImode:
12843     case DFmode:
12844       imode = DImode;
12845       vec_mode = (mode == DImode) ? V2DImode : V2DFmode;
12846       if (HOST_BITS_PER_WIDE_INT >= 64)
12847         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
12848       else
12849         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
12850       break;
12851
12852     case TImode:
12853     case TFmode:
12854       vec_mode = VOIDmode;
12855       if (HOST_BITS_PER_WIDE_INT >= 64)
12856         {
12857           imode = TImode;
12858           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
12859         }
12860       else
12861         {
12862           rtvec vec;
12863
12864           imode = DImode;
12865           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
12866
12867           if (invert)
12868             {
12869               lo = ~lo, hi = ~hi;
12870               v = constm1_rtx;
12871             }
12872           else
12873             v = const0_rtx;
12874
12875           mask = immed_double_const (lo, hi, imode);
12876
12877           vec = gen_rtvec (2, v, mask);
12878           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
12879           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
12880
12881           return v;
12882         }
12883      break;
12884
12885     default:
12886       gcc_unreachable ();
12887     }
12888
12889   if (invert)
12890     lo = ~lo, hi = ~hi;
12891
12892   /* Force this value into the low part of a fp vector constant.  */
12893   mask = immed_double_const (lo, hi, imode);
12894   mask = gen_lowpart (mode, mask);
12895
12896   if (vec_mode == VOIDmode)
12897     return force_reg (mode, mask);
12898
12899   v = ix86_build_const_vector (mode, vect, mask);
12900   return force_reg (vec_mode, v);
12901 }
12902
12903 /* Generate code for floating point ABS or NEG.  */
12904
12905 void
12906 ix86_expand_fp_absneg_operator (enum rtx_code code, enum machine_mode mode,
12907                                 rtx operands[])
12908 {
12909   rtx mask, set, use, clob, dst, src;
12910   bool use_sse = false;
12911   bool vector_mode = VECTOR_MODE_P (mode);
12912   enum machine_mode elt_mode = mode;
12913
12914   if (vector_mode)
12915     {
12916       elt_mode = GET_MODE_INNER (mode);
12917       use_sse = true;
12918     }
12919   else if (mode == TFmode)
12920     use_sse = true;
12921   else if (TARGET_SSE_MATH)
12922     use_sse = SSE_FLOAT_MODE_P (mode);
12923
12924   /* NEG and ABS performed with SSE use bitwise mask operations.
12925      Create the appropriate mask now.  */
12926   if (use_sse)
12927     mask = ix86_build_signbit_mask (elt_mode, vector_mode, code == ABS);
12928   else
12929     mask = NULL_RTX;
12930
12931   dst = operands[0];
12932   src = operands[1];
12933
12934   if (vector_mode)
12935     {
12936       set = gen_rtx_fmt_ee (code == NEG ? XOR : AND, mode, src, mask);
12937       set = gen_rtx_SET (VOIDmode, dst, set);
12938       emit_insn (set);
12939     }
12940   else
12941     {
12942       set = gen_rtx_fmt_e (code, mode, src);
12943       set = gen_rtx_SET (VOIDmode, dst, set);
12944       if (mask)
12945         {
12946           use = gen_rtx_USE (VOIDmode, mask);
12947           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12948           emit_insn (gen_rtx_PARALLEL (VOIDmode,
12949                                        gen_rtvec (3, set, use, clob)));
12950         }
12951       else
12952         emit_insn (set);
12953     }
12954 }
12955
12956 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
12957
12958 void
12959 ix86_expand_copysign (rtx operands[])
12960 {
12961   enum machine_mode mode;
12962   rtx dest, op0, op1, mask, nmask;
12963
12964   dest = operands[0];
12965   op0 = operands[1];
12966   op1 = operands[2];
12967
12968   mode = GET_MODE (dest);
12969
12970   if (GET_CODE (op0) == CONST_DOUBLE)
12971     {
12972       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
12973
12974       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
12975         op0 = simplify_unary_operation (ABS, mode, op0, mode);
12976
12977       if (mode == SFmode || mode == DFmode)
12978         {
12979           enum machine_mode vmode;
12980
12981           vmode = mode == SFmode ? V4SFmode : V2DFmode;
12982
12983           if (op0 == CONST0_RTX (mode))
12984             op0 = CONST0_RTX (vmode);
12985           else
12986             {
12987               rtvec v;
12988
12989               if (mode == SFmode)
12990                 v = gen_rtvec (4, op0, CONST0_RTX (SFmode),
12991                                CONST0_RTX (SFmode), CONST0_RTX (SFmode));
12992               else
12993                 v = gen_rtvec (2, op0, CONST0_RTX (DFmode));
12994
12995               op0 = force_reg (vmode, gen_rtx_CONST_VECTOR (vmode, v));
12996             }
12997         }
12998       else if (op0 != CONST0_RTX (mode))
12999         op0 = force_reg (mode, op0);
13000
13001       mask = ix86_build_signbit_mask (mode, 0, 0);
13002
13003       if (mode == SFmode)
13004         copysign_insn = gen_copysignsf3_const;
13005       else if (mode == DFmode)
13006         copysign_insn = gen_copysigndf3_const;
13007       else
13008         copysign_insn = gen_copysigntf3_const;
13009
13010         emit_insn (copysign_insn (dest, op0, op1, mask));
13011     }
13012   else
13013     {
13014       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
13015
13016       nmask = ix86_build_signbit_mask (mode, 0, 1);
13017       mask = ix86_build_signbit_mask (mode, 0, 0);
13018
13019       if (mode == SFmode)
13020         copysign_insn = gen_copysignsf3_var;
13021       else if (mode == DFmode)
13022         copysign_insn = gen_copysigndf3_var;
13023       else
13024         copysign_insn = gen_copysigntf3_var;
13025
13026       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
13027     }
13028 }
13029
13030 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
13031    be a constant, and so has already been expanded into a vector constant.  */
13032
13033 void
13034 ix86_split_copysign_const (rtx operands[])
13035 {
13036   enum machine_mode mode, vmode;
13037   rtx dest, op0, op1, mask, x;
13038
13039   dest = operands[0];
13040   op0 = operands[1];
13041   op1 = operands[2];
13042   mask = operands[3];
13043
13044   mode = GET_MODE (dest);
13045   vmode = GET_MODE (mask);
13046
13047   dest = simplify_gen_subreg (vmode, dest, mode, 0);
13048   x = gen_rtx_AND (vmode, dest, mask);
13049   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13050
13051   if (op0 != CONST0_RTX (vmode))
13052     {
13053       x = gen_rtx_IOR (vmode, dest, op0);
13054       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13055     }
13056 }
13057
13058 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
13059    so we have to do two masks.  */
13060
13061 void
13062 ix86_split_copysign_var (rtx operands[])
13063 {
13064   enum machine_mode mode, vmode;
13065   rtx dest, scratch, op0, op1, mask, nmask, x;
13066
13067   dest = operands[0];
13068   scratch = operands[1];
13069   op0 = operands[2];
13070   op1 = operands[3];
13071   nmask = operands[4];
13072   mask = operands[5];
13073
13074   mode = GET_MODE (dest);
13075   vmode = GET_MODE (mask);
13076
13077   if (rtx_equal_p (op0, op1))
13078     {
13079       /* Shouldn't happen often (it's useless, obviously), but when it does
13080          we'd generate incorrect code if we continue below.  */
13081       emit_move_insn (dest, op0);
13082       return;
13083     }
13084
13085   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
13086     {
13087       gcc_assert (REGNO (op1) == REGNO (scratch));
13088
13089       x = gen_rtx_AND (vmode, scratch, mask);
13090       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13091
13092       dest = mask;
13093       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13094       x = gen_rtx_NOT (vmode, dest);
13095       x = gen_rtx_AND (vmode, x, op0);
13096       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13097     }
13098   else
13099     {
13100       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
13101         {
13102           x = gen_rtx_AND (vmode, scratch, mask);
13103         }
13104       else                                              /* alternative 2,4 */
13105         {
13106           gcc_assert (REGNO (mask) == REGNO (scratch));
13107           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
13108           x = gen_rtx_AND (vmode, scratch, op1);
13109         }
13110       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13111
13112       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
13113         {
13114           dest = simplify_gen_subreg (vmode, op0, mode, 0);
13115           x = gen_rtx_AND (vmode, dest, nmask);
13116         }
13117       else                                              /* alternative 3,4 */
13118         {
13119           gcc_assert (REGNO (nmask) == REGNO (dest));
13120           dest = nmask;
13121           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13122           x = gen_rtx_AND (vmode, dest, op0);
13123         }
13124       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13125     }
13126
13127   x = gen_rtx_IOR (vmode, dest, scratch);
13128   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13129 }
13130
13131 /* Return TRUE or FALSE depending on whether the first SET in INSN
13132    has source and destination with matching CC modes, and that the
13133    CC mode is at least as constrained as REQ_MODE.  */
13134
13135 int
13136 ix86_match_ccmode (rtx insn, enum machine_mode req_mode)
13137 {
13138   rtx set;
13139   enum machine_mode set_mode;
13140
13141   set = PATTERN (insn);
13142   if (GET_CODE (set) == PARALLEL)
13143     set = XVECEXP (set, 0, 0);
13144   gcc_assert (GET_CODE (set) == SET);
13145   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
13146
13147   set_mode = GET_MODE (SET_DEST (set));
13148   switch (set_mode)
13149     {
13150     case CCNOmode:
13151       if (req_mode != CCNOmode
13152           && (req_mode != CCmode
13153               || XEXP (SET_SRC (set), 1) != const0_rtx))
13154         return 0;
13155       break;
13156     case CCmode:
13157       if (req_mode == CCGCmode)
13158         return 0;
13159       /* FALLTHRU */
13160     case CCGCmode:
13161       if (req_mode == CCGOCmode || req_mode == CCNOmode)
13162         return 0;
13163       /* FALLTHRU */
13164     case CCGOCmode:
13165       if (req_mode == CCZmode)
13166         return 0;
13167       /* FALLTHRU */
13168     case CCAmode:
13169     case CCCmode:
13170     case CCOmode:
13171     case CCSmode:
13172     case CCZmode:
13173       break;
13174
13175     default:
13176       gcc_unreachable ();
13177     }
13178
13179   return (GET_MODE (SET_SRC (set)) == set_mode);
13180 }
13181
13182 /* Generate insn patterns to do an integer compare of OPERANDS.  */
13183
13184 static rtx
13185 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
13186 {
13187   enum machine_mode cmpmode;
13188   rtx tmp, flags;
13189
13190   cmpmode = SELECT_CC_MODE (code, op0, op1);
13191   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
13192
13193   /* This is very simple, but making the interface the same as in the
13194      FP case makes the rest of the code easier.  */
13195   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
13196   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
13197
13198   /* Return the test that should be put into the flags user, i.e.
13199      the bcc, scc, or cmov instruction.  */
13200   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
13201 }
13202
13203 /* Figure out whether to use ordered or unordered fp comparisons.
13204    Return the appropriate mode to use.  */
13205
13206 enum machine_mode
13207 ix86_fp_compare_mode (enum rtx_code code ATTRIBUTE_UNUSED)
13208 {
13209   /* ??? In order to make all comparisons reversible, we do all comparisons
13210      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
13211      all forms trapping and nontrapping comparisons, we can make inequality
13212      comparisons trapping again, since it results in better code when using
13213      FCOM based compares.  */
13214   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
13215 }
13216
13217 enum machine_mode
13218 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
13219 {
13220   enum machine_mode mode = GET_MODE (op0);
13221
13222   if (SCALAR_FLOAT_MODE_P (mode))
13223     {
13224       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
13225       return ix86_fp_compare_mode (code);
13226     }
13227
13228   switch (code)
13229     {
13230       /* Only zero flag is needed.  */
13231     case EQ:                    /* ZF=0 */
13232     case NE:                    /* ZF!=0 */
13233       return CCZmode;
13234       /* Codes needing carry flag.  */
13235     case GEU:                   /* CF=0 */
13236     case LTU:                   /* CF=1 */
13237       /* Detect overflow checks.  They need just the carry flag.  */
13238       if (GET_CODE (op0) == PLUS
13239           && rtx_equal_p (op1, XEXP (op0, 0)))
13240         return CCCmode;
13241       else
13242         return CCmode;
13243     case GTU:                   /* CF=0 & ZF=0 */
13244     case LEU:                   /* CF=1 | ZF=1 */
13245       /* Detect overflow checks.  They need just the carry flag.  */
13246       if (GET_CODE (op0) == MINUS
13247           && rtx_equal_p (op1, XEXP (op0, 0)))
13248         return CCCmode;
13249       else
13250         return CCmode;
13251       /* Codes possibly doable only with sign flag when
13252          comparing against zero.  */
13253     case GE:                    /* SF=OF   or   SF=0 */
13254     case LT:                    /* SF<>OF  or   SF=1 */
13255       if (op1 == const0_rtx)
13256         return CCGOCmode;
13257       else
13258         /* For other cases Carry flag is not required.  */
13259         return CCGCmode;
13260       /* Codes doable only with sign flag when comparing
13261          against zero, but we miss jump instruction for it
13262          so we need to use relational tests against overflow
13263          that thus needs to be zero.  */
13264     case GT:                    /* ZF=0 & SF=OF */
13265     case LE:                    /* ZF=1 | SF<>OF */
13266       if (op1 == const0_rtx)
13267         return CCNOmode;
13268       else
13269         return CCGCmode;
13270       /* strcmp pattern do (use flags) and combine may ask us for proper
13271          mode.  */
13272     case USE:
13273       return CCmode;
13274     default:
13275       gcc_unreachable ();
13276     }
13277 }
13278
13279 /* Return the fixed registers used for condition codes.  */
13280
13281 static bool
13282 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
13283 {
13284   *p1 = FLAGS_REG;
13285   *p2 = FPSR_REG;
13286   return true;
13287 }
13288
13289 /* If two condition code modes are compatible, return a condition code
13290    mode which is compatible with both.  Otherwise, return
13291    VOIDmode.  */
13292
13293 static enum machine_mode
13294 ix86_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
13295 {
13296   if (m1 == m2)
13297     return m1;
13298
13299   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
13300     return VOIDmode;
13301
13302   if ((m1 == CCGCmode && m2 == CCGOCmode)
13303       || (m1 == CCGOCmode && m2 == CCGCmode))
13304     return CCGCmode;
13305
13306   switch (m1)
13307     {
13308     default:
13309       gcc_unreachable ();
13310
13311     case CCmode:
13312     case CCGCmode:
13313     case CCGOCmode:
13314     case CCNOmode:
13315     case CCAmode:
13316     case CCCmode:
13317     case CCOmode:
13318     case CCSmode:
13319     case CCZmode:
13320       switch (m2)
13321         {
13322         default:
13323           return VOIDmode;
13324
13325         case CCmode:
13326         case CCGCmode:
13327         case CCGOCmode:
13328         case CCNOmode:
13329         case CCAmode:
13330         case CCCmode:
13331         case CCOmode:
13332         case CCSmode:
13333         case CCZmode:
13334           return CCmode;
13335         }
13336
13337     case CCFPmode:
13338     case CCFPUmode:
13339       /* These are only compatible with themselves, which we already
13340          checked above.  */
13341       return VOIDmode;
13342     }
13343 }
13344
13345 /* Split comparison code CODE into comparisons we can do using branch
13346    instructions.  BYPASS_CODE is comparison code for branch that will
13347    branch around FIRST_CODE and SECOND_CODE.  If some of branches
13348    is not required, set value to UNKNOWN.
13349    We never require more than two branches.  */
13350
13351 void
13352 ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *bypass_code,
13353                           enum rtx_code *first_code,
13354                           enum rtx_code *second_code)
13355 {
13356   *first_code = code;
13357   *bypass_code = UNKNOWN;
13358   *second_code = UNKNOWN;
13359
13360   /* The fcomi comparison sets flags as follows:
13361
13362      cmp    ZF PF CF
13363      >      0  0  0
13364      <      0  0  1
13365      =      1  0  0
13366      un     1  1  1 */
13367
13368   switch (code)
13369     {
13370     case GT:                    /* GTU - CF=0 & ZF=0 */
13371     case GE:                    /* GEU - CF=0 */
13372     case ORDERED:               /* PF=0 */
13373     case UNORDERED:             /* PF=1 */
13374     case UNEQ:                  /* EQ - ZF=1 */
13375     case UNLT:                  /* LTU - CF=1 */
13376     case UNLE:                  /* LEU - CF=1 | ZF=1 */
13377     case LTGT:                  /* EQ - ZF=0 */
13378       break;
13379     case LT:                    /* LTU - CF=1 - fails on unordered */
13380       *first_code = UNLT;
13381       *bypass_code = UNORDERED;
13382       break;
13383     case LE:                    /* LEU - CF=1 | ZF=1 - fails on unordered */
13384       *first_code = UNLE;
13385       *bypass_code = UNORDERED;
13386       break;
13387     case EQ:                    /* EQ - ZF=1 - fails on unordered */
13388       *first_code = UNEQ;
13389       *bypass_code = UNORDERED;
13390       break;
13391     case NE:                    /* NE - ZF=0 - fails on unordered */
13392       *first_code = LTGT;
13393       *second_code = UNORDERED;
13394       break;
13395     case UNGE:                  /* GEU - CF=0 - fails on unordered */
13396       *first_code = GE;
13397       *second_code = UNORDERED;
13398       break;
13399     case UNGT:                  /* GTU - CF=0 & ZF=0 - fails on unordered */
13400       *first_code = GT;
13401       *second_code = UNORDERED;
13402       break;
13403     default:
13404       gcc_unreachable ();
13405     }
13406   if (!TARGET_IEEE_FP)
13407     {
13408       *second_code = UNKNOWN;
13409       *bypass_code = UNKNOWN;
13410     }
13411 }
13412
13413 /* Return cost of comparison done fcom + arithmetics operations on AX.
13414    All following functions do use number of instructions as a cost metrics.
13415    In future this should be tweaked to compute bytes for optimize_size and
13416    take into account performance of various instructions on various CPUs.  */
13417 static int
13418 ix86_fp_comparison_arithmetics_cost (enum rtx_code code)
13419 {
13420   if (!TARGET_IEEE_FP)
13421     return 4;
13422   /* The cost of code output by ix86_expand_fp_compare.  */
13423   switch (code)
13424     {
13425     case UNLE:
13426     case UNLT:
13427     case LTGT:
13428     case GT:
13429     case GE:
13430     case UNORDERED:
13431     case ORDERED:
13432     case UNEQ:
13433       return 4;
13434       break;
13435     case LT:
13436     case NE:
13437     case EQ:
13438     case UNGE:
13439       return 5;
13440       break;
13441     case LE:
13442     case UNGT:
13443       return 6;
13444       break;
13445     default:
13446       gcc_unreachable ();
13447     }
13448 }
13449
13450 /* Return cost of comparison done using fcomi operation.
13451    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13452 static int
13453 ix86_fp_comparison_fcomi_cost (enum rtx_code code)
13454 {
13455   enum rtx_code bypass_code, first_code, second_code;
13456   /* Return arbitrarily high cost when instruction is not supported - this
13457      prevents gcc from using it.  */
13458   if (!TARGET_CMOVE)
13459     return 1024;
13460   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13461   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 2;
13462 }
13463
13464 /* Return cost of comparison done using sahf operation.
13465    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13466 static int
13467 ix86_fp_comparison_sahf_cost (enum rtx_code code)
13468 {
13469   enum rtx_code bypass_code, first_code, second_code;
13470   /* Return arbitrarily high cost when instruction is not preferred - this
13471      avoids gcc from using it.  */
13472   if (!(TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ())))
13473     return 1024;
13474   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13475   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 3;
13476 }
13477
13478 /* Compute cost of the comparison done using any method.
13479    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13480 static int
13481 ix86_fp_comparison_cost (enum rtx_code code)
13482 {
13483   int fcomi_cost, sahf_cost, arithmetics_cost = 1024;
13484   int min;
13485
13486   fcomi_cost = ix86_fp_comparison_fcomi_cost (code);
13487   sahf_cost = ix86_fp_comparison_sahf_cost (code);
13488
13489   min = arithmetics_cost = ix86_fp_comparison_arithmetics_cost (code);
13490   if (min > sahf_cost)
13491     min = sahf_cost;
13492   if (min > fcomi_cost)
13493     min = fcomi_cost;
13494   return min;
13495 }
13496
13497 /* Return true if we should use an FCOMI instruction for this
13498    fp comparison.  */
13499
13500 int
13501 ix86_use_fcomi_compare (enum rtx_code code ATTRIBUTE_UNUSED)
13502 {
13503   enum rtx_code swapped_code = swap_condition (code);
13504
13505   return ((ix86_fp_comparison_cost (code)
13506            == ix86_fp_comparison_fcomi_cost (code))
13507           || (ix86_fp_comparison_cost (swapped_code)
13508               == ix86_fp_comparison_fcomi_cost (swapped_code)));
13509 }
13510
13511 /* Swap, force into registers, or otherwise massage the two operands
13512    to a fp comparison.  The operands are updated in place; the new
13513    comparison code is returned.  */
13514
13515 static enum rtx_code
13516 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
13517 {
13518   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
13519   rtx op0 = *pop0, op1 = *pop1;
13520   enum machine_mode op_mode = GET_MODE (op0);
13521   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
13522
13523   /* All of the unordered compare instructions only work on registers.
13524      The same is true of the fcomi compare instructions.  The XFmode
13525      compare instructions require registers except when comparing
13526      against zero or when converting operand 1 from fixed point to
13527      floating point.  */
13528
13529   if (!is_sse
13530       && (fpcmp_mode == CCFPUmode
13531           || (op_mode == XFmode
13532               && ! (standard_80387_constant_p (op0) == 1
13533                     || standard_80387_constant_p (op1) == 1)
13534               && GET_CODE (op1) != FLOAT)
13535           || ix86_use_fcomi_compare (code)))
13536     {
13537       op0 = force_reg (op_mode, op0);
13538       op1 = force_reg (op_mode, op1);
13539     }
13540   else
13541     {
13542       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
13543          things around if they appear profitable, otherwise force op0
13544          into a register.  */
13545
13546       if (standard_80387_constant_p (op0) == 0
13547           || (MEM_P (op0)
13548               && ! (standard_80387_constant_p (op1) == 0
13549                     || MEM_P (op1))))
13550         {
13551           rtx tmp;
13552           tmp = op0, op0 = op1, op1 = tmp;
13553           code = swap_condition (code);
13554         }
13555
13556       if (!REG_P (op0))
13557         op0 = force_reg (op_mode, op0);
13558
13559       if (CONSTANT_P (op1))
13560         {
13561           int tmp = standard_80387_constant_p (op1);
13562           if (tmp == 0)
13563             op1 = validize_mem (force_const_mem (op_mode, op1));
13564           else if (tmp == 1)
13565             {
13566               if (TARGET_CMOVE)
13567                 op1 = force_reg (op_mode, op1);
13568             }
13569           else
13570             op1 = force_reg (op_mode, op1);
13571         }
13572     }
13573
13574   /* Try to rearrange the comparison to make it cheaper.  */
13575   if (ix86_fp_comparison_cost (code)
13576       > ix86_fp_comparison_cost (swap_condition (code))
13577       && (REG_P (op1) || can_create_pseudo_p ()))
13578     {
13579       rtx tmp;
13580       tmp = op0, op0 = op1, op1 = tmp;
13581       code = swap_condition (code);
13582       if (!REG_P (op0))
13583         op0 = force_reg (op_mode, op0);
13584     }
13585
13586   *pop0 = op0;
13587   *pop1 = op1;
13588   return code;
13589 }
13590
13591 /* Convert comparison codes we use to represent FP comparison to integer
13592    code that will result in proper branch.  Return UNKNOWN if no such code
13593    is available.  */
13594
13595 enum rtx_code
13596 ix86_fp_compare_code_to_integer (enum rtx_code code)
13597 {
13598   switch (code)
13599     {
13600     case GT:
13601       return GTU;
13602     case GE:
13603       return GEU;
13604     case ORDERED:
13605     case UNORDERED:
13606       return code;
13607       break;
13608     case UNEQ:
13609       return EQ;
13610       break;
13611     case UNLT:
13612       return LTU;
13613       break;
13614     case UNLE:
13615       return LEU;
13616       break;
13617     case LTGT:
13618       return NE;
13619       break;
13620     default:
13621       return UNKNOWN;
13622     }
13623 }
13624
13625 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
13626
13627 static rtx
13628 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch,
13629                         rtx *second_test, rtx *bypass_test)
13630 {
13631   enum machine_mode fpcmp_mode, intcmp_mode;
13632   rtx tmp, tmp2;
13633   int cost = ix86_fp_comparison_cost (code);
13634   enum rtx_code bypass_code, first_code, second_code;
13635
13636   fpcmp_mode = ix86_fp_compare_mode (code);
13637   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
13638
13639   if (second_test)
13640     *second_test = NULL_RTX;
13641   if (bypass_test)
13642     *bypass_test = NULL_RTX;
13643
13644   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13645
13646   /* Do fcomi/sahf based test when profitable.  */
13647   if (ix86_fp_comparison_arithmetics_cost (code) > cost
13648       && (bypass_code == UNKNOWN || bypass_test)
13649       && (second_code == UNKNOWN || second_test))
13650     {
13651       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13652       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
13653                          tmp);
13654       if (TARGET_CMOVE)
13655         emit_insn (tmp);
13656       else
13657         {
13658           gcc_assert (TARGET_SAHF);
13659
13660           if (!scratch)
13661             scratch = gen_reg_rtx (HImode);
13662           tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
13663
13664           emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
13665         }
13666
13667       /* The FP codes work out to act like unsigned.  */
13668       intcmp_mode = fpcmp_mode;
13669       code = first_code;
13670       if (bypass_code != UNKNOWN)
13671         *bypass_test = gen_rtx_fmt_ee (bypass_code, VOIDmode,
13672                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13673                                        const0_rtx);
13674       if (second_code != UNKNOWN)
13675         *second_test = gen_rtx_fmt_ee (second_code, VOIDmode,
13676                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13677                                        const0_rtx);
13678     }
13679   else
13680     {
13681       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
13682       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13683       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
13684       if (!scratch)
13685         scratch = gen_reg_rtx (HImode);
13686       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
13687
13688       /* In the unordered case, we have to check C2 for NaN's, which
13689          doesn't happen to work out to anything nice combination-wise.
13690          So do some bit twiddling on the value we've got in AH to come
13691          up with an appropriate set of condition codes.  */
13692
13693       intcmp_mode = CCNOmode;
13694       switch (code)
13695         {
13696         case GT:
13697         case UNGT:
13698           if (code == GT || !TARGET_IEEE_FP)
13699             {
13700               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
13701               code = EQ;
13702             }
13703           else
13704             {
13705               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13706               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
13707               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
13708               intcmp_mode = CCmode;
13709               code = GEU;
13710             }
13711           break;
13712         case LT:
13713         case UNLT:
13714           if (code == LT && TARGET_IEEE_FP)
13715             {
13716               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13717               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x01)));
13718               intcmp_mode = CCmode;
13719               code = EQ;
13720             }
13721           else
13722             {
13723               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x01)));
13724               code = NE;
13725             }
13726           break;
13727         case GE:
13728         case UNGE:
13729           if (code == GE || !TARGET_IEEE_FP)
13730             {
13731               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
13732               code = EQ;
13733             }
13734           else
13735             {
13736               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13737               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
13738                                              GEN_INT (0x01)));
13739               code = NE;
13740             }
13741           break;
13742         case LE:
13743         case UNLE:
13744           if (code == LE && TARGET_IEEE_FP)
13745             {
13746               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13747               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
13748               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
13749               intcmp_mode = CCmode;
13750               code = LTU;
13751             }
13752           else
13753             {
13754               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
13755               code = NE;
13756             }
13757           break;
13758         case EQ:
13759         case UNEQ:
13760           if (code == EQ && TARGET_IEEE_FP)
13761             {
13762               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13763               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
13764               intcmp_mode = CCmode;
13765               code = EQ;
13766             }
13767           else
13768             {
13769               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
13770               code = NE;
13771               break;
13772             }
13773           break;
13774         case NE:
13775         case LTGT:
13776           if (code == NE && TARGET_IEEE_FP)
13777             {
13778               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13779               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
13780                                              GEN_INT (0x40)));
13781               code = NE;
13782             }
13783           else
13784             {
13785               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
13786               code = EQ;
13787             }
13788           break;
13789
13790         case UNORDERED:
13791           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
13792           code = NE;
13793           break;
13794         case ORDERED:
13795           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
13796           code = EQ;
13797           break;
13798
13799         default:
13800           gcc_unreachable ();
13801         }
13802     }
13803
13804   /* Return the test that should be put into the flags user, i.e.
13805      the bcc, scc, or cmov instruction.  */
13806   return gen_rtx_fmt_ee (code, VOIDmode,
13807                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
13808                          const0_rtx);
13809 }
13810
13811 rtx
13812 ix86_expand_compare (enum rtx_code code, rtx *second_test, rtx *bypass_test)
13813 {
13814   rtx op0, op1, ret;
13815   op0 = ix86_compare_op0;
13816   op1 = ix86_compare_op1;
13817
13818   if (second_test)
13819     *second_test = NULL_RTX;
13820   if (bypass_test)
13821     *bypass_test = NULL_RTX;
13822
13823   if (ix86_compare_emitted)
13824     {
13825       ret = gen_rtx_fmt_ee (code, VOIDmode, ix86_compare_emitted, const0_rtx);
13826       ix86_compare_emitted = NULL_RTX;
13827     }
13828   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
13829     {
13830       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
13831       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
13832                                     second_test, bypass_test);
13833     }
13834   else
13835     ret = ix86_expand_int_compare (code, op0, op1);
13836
13837   return ret;
13838 }
13839
13840 /* Return true if the CODE will result in nontrivial jump sequence.  */
13841 bool
13842 ix86_fp_jump_nontrivial_p (enum rtx_code code)
13843 {
13844   enum rtx_code bypass_code, first_code, second_code;
13845   if (!TARGET_CMOVE)
13846     return true;
13847   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13848   return bypass_code != UNKNOWN || second_code != UNKNOWN;
13849 }
13850
13851 void
13852 ix86_expand_branch (enum rtx_code code, rtx label)
13853 {
13854   rtx tmp;
13855
13856   /* If we have emitted a compare insn, go straight to simple.
13857      ix86_expand_compare won't emit anything if ix86_compare_emitted
13858      is non NULL.  */
13859   if (ix86_compare_emitted)
13860     goto simple;
13861
13862   switch (GET_MODE (ix86_compare_op0))
13863     {
13864     case QImode:
13865     case HImode:
13866     case SImode:
13867       simple:
13868       tmp = ix86_expand_compare (code, NULL, NULL);
13869       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
13870                                   gen_rtx_LABEL_REF (VOIDmode, label),
13871                                   pc_rtx);
13872       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
13873       return;
13874
13875     case SFmode:
13876     case DFmode:
13877     case XFmode:
13878       {
13879         rtvec vec;
13880         int use_fcomi;
13881         enum rtx_code bypass_code, first_code, second_code;
13882
13883         code = ix86_prepare_fp_compare_args (code, &ix86_compare_op0,
13884                                              &ix86_compare_op1);
13885
13886         ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13887
13888         /* Check whether we will use the natural sequence with one jump.  If
13889            so, we can expand jump early.  Otherwise delay expansion by
13890            creating compound insn to not confuse optimizers.  */
13891         if (bypass_code == UNKNOWN && second_code == UNKNOWN)
13892           {
13893             ix86_split_fp_branch (code, ix86_compare_op0, ix86_compare_op1,
13894                                   gen_rtx_LABEL_REF (VOIDmode, label),
13895                                   pc_rtx, NULL_RTX, NULL_RTX);
13896           }
13897         else
13898           {
13899             tmp = gen_rtx_fmt_ee (code, VOIDmode,
13900                                   ix86_compare_op0, ix86_compare_op1);
13901             tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
13902                                         gen_rtx_LABEL_REF (VOIDmode, label),
13903                                         pc_rtx);
13904             tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
13905
13906             use_fcomi = ix86_use_fcomi_compare (code);
13907             vec = rtvec_alloc (3 + !use_fcomi);
13908             RTVEC_ELT (vec, 0) = tmp;
13909             RTVEC_ELT (vec, 1)
13910               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FPSR_REG));
13911             RTVEC_ELT (vec, 2)
13912               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FLAGS_REG));
13913             if (! use_fcomi)
13914               RTVEC_ELT (vec, 3)
13915                 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (HImode));
13916
13917             emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, vec));
13918           }
13919         return;
13920       }
13921
13922     case DImode:
13923       if (TARGET_64BIT)
13924         goto simple;
13925     case TImode:
13926       /* Expand DImode branch into multiple compare+branch.  */
13927       {
13928         rtx lo[2], hi[2], label2;
13929         enum rtx_code code1, code2, code3;
13930         enum machine_mode submode;
13931
13932         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
13933           {
13934             tmp = ix86_compare_op0;
13935             ix86_compare_op0 = ix86_compare_op1;
13936             ix86_compare_op1 = tmp;
13937             code = swap_condition (code);
13938           }
13939         if (GET_MODE (ix86_compare_op0) == DImode)
13940           {
13941             split_di (&ix86_compare_op0, 1, lo+0, hi+0);
13942             split_di (&ix86_compare_op1, 1, lo+1, hi+1);
13943             submode = SImode;
13944           }
13945         else
13946           {
13947             split_ti (&ix86_compare_op0, 1, lo+0, hi+0);
13948             split_ti (&ix86_compare_op1, 1, lo+1, hi+1);
13949             submode = DImode;
13950           }
13951
13952         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
13953            avoid two branches.  This costs one extra insn, so disable when
13954            optimizing for size.  */
13955
13956         if ((code == EQ || code == NE)
13957             && (!optimize_insn_for_size_p ()
13958                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
13959           {
13960             rtx xor0, xor1;
13961
13962             xor1 = hi[0];
13963             if (hi[1] != const0_rtx)
13964               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
13965                                    NULL_RTX, 0, OPTAB_WIDEN);
13966
13967             xor0 = lo[0];
13968             if (lo[1] != const0_rtx)
13969               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
13970                                    NULL_RTX, 0, OPTAB_WIDEN);
13971
13972             tmp = expand_binop (submode, ior_optab, xor1, xor0,
13973                                 NULL_RTX, 0, OPTAB_WIDEN);
13974
13975             ix86_compare_op0 = tmp;
13976             ix86_compare_op1 = const0_rtx;
13977             ix86_expand_branch (code, label);
13978             return;
13979           }
13980
13981         /* Otherwise, if we are doing less-than or greater-or-equal-than,
13982            op1 is a constant and the low word is zero, then we can just
13983            examine the high word.  Similarly for low word -1 and
13984            less-or-equal-than or greater-than.  */
13985
13986         if (CONST_INT_P (hi[1]))
13987           switch (code)
13988             {
13989             case LT: case LTU: case GE: case GEU:
13990               if (lo[1] == const0_rtx)
13991                 {
13992                   ix86_compare_op0 = hi[0];
13993                   ix86_compare_op1 = hi[1];
13994                   ix86_expand_branch (code, label);
13995                   return;
13996                 }
13997               break;
13998             case LE: case LEU: case GT: case GTU:
13999               if (lo[1] == constm1_rtx)
14000                 {
14001                   ix86_compare_op0 = hi[0];
14002                   ix86_compare_op1 = hi[1];
14003                   ix86_expand_branch (code, label);
14004                   return;
14005                 }
14006               break;
14007             default:
14008               break;
14009             }
14010
14011         /* Otherwise, we need two or three jumps.  */
14012
14013         label2 = gen_label_rtx ();
14014
14015         code1 = code;
14016         code2 = swap_condition (code);
14017         code3 = unsigned_condition (code);
14018
14019         switch (code)
14020           {
14021           case LT: case GT: case LTU: case GTU:
14022             break;
14023
14024           case LE:   code1 = LT;  code2 = GT;  break;
14025           case GE:   code1 = GT;  code2 = LT;  break;
14026           case LEU:  code1 = LTU; code2 = GTU; break;
14027           case GEU:  code1 = GTU; code2 = LTU; break;
14028
14029           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
14030           case NE:   code2 = UNKNOWN; break;
14031
14032           default:
14033             gcc_unreachable ();
14034           }
14035
14036         /*
14037          * a < b =>
14038          *    if (hi(a) < hi(b)) goto true;
14039          *    if (hi(a) > hi(b)) goto false;
14040          *    if (lo(a) < lo(b)) goto true;
14041          *  false:
14042          */
14043
14044         ix86_compare_op0 = hi[0];
14045         ix86_compare_op1 = hi[1];
14046
14047         if (code1 != UNKNOWN)
14048           ix86_expand_branch (code1, label);
14049         if (code2 != UNKNOWN)
14050           ix86_expand_branch (code2, label2);
14051
14052         ix86_compare_op0 = lo[0];
14053         ix86_compare_op1 = lo[1];
14054         ix86_expand_branch (code3, label);
14055
14056         if (code2 != UNKNOWN)
14057           emit_label (label2);
14058         return;
14059       }
14060
14061     default:
14062       gcc_unreachable ();
14063     }
14064 }
14065
14066 /* Split branch based on floating point condition.  */
14067 void
14068 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
14069                       rtx target1, rtx target2, rtx tmp, rtx pushed)
14070 {
14071   rtx second, bypass;
14072   rtx label = NULL_RTX;
14073   rtx condition;
14074   int bypass_probability = -1, second_probability = -1, probability = -1;
14075   rtx i;
14076
14077   if (target2 != pc_rtx)
14078     {
14079       rtx tmp = target2;
14080       code = reverse_condition_maybe_unordered (code);
14081       target2 = target1;
14082       target1 = tmp;
14083     }
14084
14085   condition = ix86_expand_fp_compare (code, op1, op2,
14086                                       tmp, &second, &bypass);
14087
14088   /* Remove pushed operand from stack.  */
14089   if (pushed)
14090     ix86_free_from_memory (GET_MODE (pushed));
14091
14092   if (split_branch_probability >= 0)
14093     {
14094       /* Distribute the probabilities across the jumps.
14095          Assume the BYPASS and SECOND to be always test
14096          for UNORDERED.  */
14097       probability = split_branch_probability;
14098
14099       /* Value of 1 is low enough to make no need for probability
14100          to be updated.  Later we may run some experiments and see
14101          if unordered values are more frequent in practice.  */
14102       if (bypass)
14103         bypass_probability = 1;
14104       if (second)
14105         second_probability = 1;
14106     }
14107   if (bypass != NULL_RTX)
14108     {
14109       label = gen_label_rtx ();
14110       i = emit_jump_insn (gen_rtx_SET
14111                           (VOIDmode, pc_rtx,
14112                            gen_rtx_IF_THEN_ELSE (VOIDmode,
14113                                                  bypass,
14114                                                  gen_rtx_LABEL_REF (VOIDmode,
14115                                                                     label),
14116                                                  pc_rtx)));
14117       if (bypass_probability >= 0)
14118         REG_NOTES (i)
14119           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14120                                GEN_INT (bypass_probability),
14121                                REG_NOTES (i));
14122     }
14123   i = emit_jump_insn (gen_rtx_SET
14124                       (VOIDmode, pc_rtx,
14125                        gen_rtx_IF_THEN_ELSE (VOIDmode,
14126                                              condition, target1, target2)));
14127   if (probability >= 0)
14128     REG_NOTES (i)
14129       = gen_rtx_EXPR_LIST (REG_BR_PROB,
14130                            GEN_INT (probability),
14131                            REG_NOTES (i));
14132   if (second != NULL_RTX)
14133     {
14134       i = emit_jump_insn (gen_rtx_SET
14135                           (VOIDmode, pc_rtx,
14136                            gen_rtx_IF_THEN_ELSE (VOIDmode, second, target1,
14137                                                  target2)));
14138       if (second_probability >= 0)
14139         REG_NOTES (i)
14140           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14141                                GEN_INT (second_probability),
14142                                REG_NOTES (i));
14143     }
14144   if (label != NULL_RTX)
14145     emit_label (label);
14146 }
14147
14148 int
14149 ix86_expand_setcc (enum rtx_code code, rtx dest)
14150 {
14151   rtx ret, tmp, tmpreg, equiv;
14152   rtx second_test, bypass_test;
14153
14154   if (GET_MODE (ix86_compare_op0) == (TARGET_64BIT ? TImode : DImode))
14155     return 0; /* FAIL */
14156
14157   gcc_assert (GET_MODE (dest) == QImode);
14158
14159   ret = ix86_expand_compare (code, &second_test, &bypass_test);
14160   PUT_MODE (ret, QImode);
14161
14162   tmp = dest;
14163   tmpreg = dest;
14164
14165   emit_insn (gen_rtx_SET (VOIDmode, tmp, ret));
14166   if (bypass_test || second_test)
14167     {
14168       rtx test = second_test;
14169       int bypass = 0;
14170       rtx tmp2 = gen_reg_rtx (QImode);
14171       if (bypass_test)
14172         {
14173           gcc_assert (!second_test);
14174           test = bypass_test;
14175           bypass = 1;
14176           PUT_CODE (test, reverse_condition_maybe_unordered (GET_CODE (test)));
14177         }
14178       PUT_MODE (test, QImode);
14179       emit_insn (gen_rtx_SET (VOIDmode, tmp2, test));
14180
14181       if (bypass)
14182         emit_insn (gen_andqi3 (tmp, tmpreg, tmp2));
14183       else
14184         emit_insn (gen_iorqi3 (tmp, tmpreg, tmp2));
14185     }
14186
14187   /* Attach a REG_EQUAL note describing the comparison result.  */
14188   if (ix86_compare_op0 && ix86_compare_op1)
14189     {
14190       equiv = simplify_gen_relational (code, QImode,
14191                                        GET_MODE (ix86_compare_op0),
14192                                        ix86_compare_op0, ix86_compare_op1);
14193       set_unique_reg_note (get_last_insn (), REG_EQUAL, equiv);
14194     }
14195
14196   return 1; /* DONE */
14197 }
14198
14199 /* Expand comparison setting or clearing carry flag.  Return true when
14200    successful and set pop for the operation.  */
14201 static bool
14202 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
14203 {
14204   enum machine_mode mode =
14205     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
14206
14207   /* Do not handle DImode compares that go through special path.  */
14208   if (mode == (TARGET_64BIT ? TImode : DImode))
14209     return false;
14210
14211   if (SCALAR_FLOAT_MODE_P (mode))
14212     {
14213       rtx second_test = NULL, bypass_test = NULL;
14214       rtx compare_op, compare_seq;
14215
14216       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
14217
14218       /* Shortcut:  following common codes never translate
14219          into carry flag compares.  */
14220       if (code == EQ || code == NE || code == UNEQ || code == LTGT
14221           || code == ORDERED || code == UNORDERED)
14222         return false;
14223
14224       /* These comparisons require zero flag; swap operands so they won't.  */
14225       if ((code == GT || code == UNLE || code == LE || code == UNGT)
14226           && !TARGET_IEEE_FP)
14227         {
14228           rtx tmp = op0;
14229           op0 = op1;
14230           op1 = tmp;
14231           code = swap_condition (code);
14232         }
14233
14234       /* Try to expand the comparison and verify that we end up with
14235          carry flag based comparison.  This fails to be true only when
14236          we decide to expand comparison using arithmetic that is not
14237          too common scenario.  */
14238       start_sequence ();
14239       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
14240                                            &second_test, &bypass_test);
14241       compare_seq = get_insns ();
14242       end_sequence ();
14243
14244       if (second_test || bypass_test)
14245         return false;
14246
14247       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14248           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14249         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
14250       else
14251         code = GET_CODE (compare_op);
14252
14253       if (code != LTU && code != GEU)
14254         return false;
14255
14256       emit_insn (compare_seq);
14257       *pop = compare_op;
14258       return true;
14259     }
14260
14261   if (!INTEGRAL_MODE_P (mode))
14262     return false;
14263
14264   switch (code)
14265     {
14266     case LTU:
14267     case GEU:
14268       break;
14269
14270     /* Convert a==0 into (unsigned)a<1.  */
14271     case EQ:
14272     case NE:
14273       if (op1 != const0_rtx)
14274         return false;
14275       op1 = const1_rtx;
14276       code = (code == EQ ? LTU : GEU);
14277       break;
14278
14279     /* Convert a>b into b<a or a>=b-1.  */
14280     case GTU:
14281     case LEU:
14282       if (CONST_INT_P (op1))
14283         {
14284           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
14285           /* Bail out on overflow.  We still can swap operands but that
14286              would force loading of the constant into register.  */
14287           if (op1 == const0_rtx
14288               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
14289             return false;
14290           code = (code == GTU ? GEU : LTU);
14291         }
14292       else
14293         {
14294           rtx tmp = op1;
14295           op1 = op0;
14296           op0 = tmp;
14297           code = (code == GTU ? LTU : GEU);
14298         }
14299       break;
14300
14301     /* Convert a>=0 into (unsigned)a<0x80000000.  */
14302     case LT:
14303     case GE:
14304       if (mode == DImode || op1 != const0_rtx)
14305         return false;
14306       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14307       code = (code == LT ? GEU : LTU);
14308       break;
14309     case LE:
14310     case GT:
14311       if (mode == DImode || op1 != constm1_rtx)
14312         return false;
14313       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14314       code = (code == LE ? GEU : LTU);
14315       break;
14316
14317     default:
14318       return false;
14319     }
14320   /* Swapping operands may cause constant to appear as first operand.  */
14321   if (!nonimmediate_operand (op0, VOIDmode))
14322     {
14323       if (!can_create_pseudo_p ())
14324         return false;
14325       op0 = force_reg (mode, op0);
14326     }
14327   ix86_compare_op0 = op0;
14328   ix86_compare_op1 = op1;
14329   *pop = ix86_expand_compare (code, NULL, NULL);
14330   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
14331   return true;
14332 }
14333
14334 int
14335 ix86_expand_int_movcc (rtx operands[])
14336 {
14337   enum rtx_code code = GET_CODE (operands[1]), compare_code;
14338   rtx compare_seq, compare_op;
14339   rtx second_test, bypass_test;
14340   enum machine_mode mode = GET_MODE (operands[0]);
14341   bool sign_bit_compare_p = false;;
14342
14343   start_sequence ();
14344   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
14345   compare_seq = get_insns ();
14346   end_sequence ();
14347
14348   compare_code = GET_CODE (compare_op);
14349
14350   if ((ix86_compare_op1 == const0_rtx && (code == GE || code == LT))
14351       || (ix86_compare_op1 == constm1_rtx && (code == GT || code == LE)))
14352     sign_bit_compare_p = true;
14353
14354   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
14355      HImode insns, we'd be swallowed in word prefix ops.  */
14356
14357   if ((mode != HImode || TARGET_FAST_PREFIX)
14358       && (mode != (TARGET_64BIT ? TImode : DImode))
14359       && CONST_INT_P (operands[2])
14360       && CONST_INT_P (operands[3]))
14361     {
14362       rtx out = operands[0];
14363       HOST_WIDE_INT ct = INTVAL (operands[2]);
14364       HOST_WIDE_INT cf = INTVAL (operands[3]);
14365       HOST_WIDE_INT diff;
14366
14367       diff = ct - cf;
14368       /*  Sign bit compares are better done using shifts than we do by using
14369           sbb.  */
14370       if (sign_bit_compare_p
14371           || ix86_expand_carry_flag_compare (code, ix86_compare_op0,
14372                                              ix86_compare_op1, &compare_op))
14373         {
14374           /* Detect overlap between destination and compare sources.  */
14375           rtx tmp = out;
14376
14377           if (!sign_bit_compare_p)
14378             {
14379               bool fpcmp = false;
14380
14381               compare_code = GET_CODE (compare_op);
14382
14383               if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14384                   || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14385                 {
14386                   fpcmp = true;
14387                   compare_code = ix86_fp_compare_code_to_integer (compare_code);
14388                 }
14389
14390               /* To simplify rest of code, restrict to the GEU case.  */
14391               if (compare_code == LTU)
14392                 {
14393                   HOST_WIDE_INT tmp = ct;
14394                   ct = cf;
14395                   cf = tmp;
14396                   compare_code = reverse_condition (compare_code);
14397                   code = reverse_condition (code);
14398                 }
14399               else
14400                 {
14401                   if (fpcmp)
14402                     PUT_CODE (compare_op,
14403                               reverse_condition_maybe_unordered
14404                                 (GET_CODE (compare_op)));
14405                   else
14406                     PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
14407                 }
14408               diff = ct - cf;
14409
14410               if (reg_overlap_mentioned_p (out, ix86_compare_op0)
14411                   || reg_overlap_mentioned_p (out, ix86_compare_op1))
14412                 tmp = gen_reg_rtx (mode);
14413
14414               if (mode == DImode)
14415                 emit_insn (gen_x86_movdicc_0_m1_rex64 (tmp, compare_op));
14416               else
14417                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp), compare_op));
14418             }
14419           else
14420             {
14421               if (code == GT || code == GE)
14422                 code = reverse_condition (code);
14423               else
14424                 {
14425                   HOST_WIDE_INT tmp = ct;
14426                   ct = cf;
14427                   cf = tmp;
14428                   diff = ct - cf;
14429                 }
14430               tmp = emit_store_flag (tmp, code, ix86_compare_op0,
14431                                      ix86_compare_op1, VOIDmode, 0, -1);
14432             }
14433
14434           if (diff == 1)
14435             {
14436               /*
14437                * cmpl op0,op1
14438                * sbbl dest,dest
14439                * [addl dest, ct]
14440                *
14441                * Size 5 - 8.
14442                */
14443               if (ct)
14444                 tmp = expand_simple_binop (mode, PLUS,
14445                                            tmp, GEN_INT (ct),
14446                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14447             }
14448           else if (cf == -1)
14449             {
14450               /*
14451                * cmpl op0,op1
14452                * sbbl dest,dest
14453                * orl $ct, dest
14454                *
14455                * Size 8.
14456                */
14457               tmp = expand_simple_binop (mode, IOR,
14458                                          tmp, GEN_INT (ct),
14459                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14460             }
14461           else if (diff == -1 && ct)
14462             {
14463               /*
14464                * cmpl op0,op1
14465                * sbbl dest,dest
14466                * notl dest
14467                * [addl dest, cf]
14468                *
14469                * Size 8 - 11.
14470                */
14471               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14472               if (cf)
14473                 tmp = expand_simple_binop (mode, PLUS,
14474                                            copy_rtx (tmp), GEN_INT (cf),
14475                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14476             }
14477           else
14478             {
14479               /*
14480                * cmpl op0,op1
14481                * sbbl dest,dest
14482                * [notl dest]
14483                * andl cf - ct, dest
14484                * [addl dest, ct]
14485                *
14486                * Size 8 - 11.
14487                */
14488
14489               if (cf == 0)
14490                 {
14491                   cf = ct;
14492                   ct = 0;
14493                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14494                 }
14495
14496               tmp = expand_simple_binop (mode, AND,
14497                                          copy_rtx (tmp),
14498                                          gen_int_mode (cf - ct, mode),
14499                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14500               if (ct)
14501                 tmp = expand_simple_binop (mode, PLUS,
14502                                            copy_rtx (tmp), GEN_INT (ct),
14503                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14504             }
14505
14506           if (!rtx_equal_p (tmp, out))
14507             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
14508
14509           return 1; /* DONE */
14510         }
14511
14512       if (diff < 0)
14513         {
14514           enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14515
14516           HOST_WIDE_INT tmp;
14517           tmp = ct, ct = cf, cf = tmp;
14518           diff = -diff;
14519
14520           if (SCALAR_FLOAT_MODE_P (cmp_mode))
14521             {
14522               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14523
14524               /* We may be reversing unordered compare to normal compare, that
14525                  is not valid in general (we may convert non-trapping condition
14526                  to trapping one), however on i386 we currently emit all
14527                  comparisons unordered.  */
14528               compare_code = reverse_condition_maybe_unordered (compare_code);
14529               code = reverse_condition_maybe_unordered (code);
14530             }
14531           else
14532             {
14533               compare_code = reverse_condition (compare_code);
14534               code = reverse_condition (code);
14535             }
14536         }
14537
14538       compare_code = UNKNOWN;
14539       if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_INT
14540           && CONST_INT_P (ix86_compare_op1))
14541         {
14542           if (ix86_compare_op1 == const0_rtx
14543               && (code == LT || code == GE))
14544             compare_code = code;
14545           else if (ix86_compare_op1 == constm1_rtx)
14546             {
14547               if (code == LE)
14548                 compare_code = LT;
14549               else if (code == GT)
14550                 compare_code = GE;
14551             }
14552         }
14553
14554       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
14555       if (compare_code != UNKNOWN
14556           && GET_MODE (ix86_compare_op0) == GET_MODE (out)
14557           && (cf == -1 || ct == -1))
14558         {
14559           /* If lea code below could be used, only optimize
14560              if it results in a 2 insn sequence.  */
14561
14562           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
14563                  || diff == 3 || diff == 5 || diff == 9)
14564               || (compare_code == LT && ct == -1)
14565               || (compare_code == GE && cf == -1))
14566             {
14567               /*
14568                * notl op1       (if necessary)
14569                * sarl $31, op1
14570                * orl cf, op1
14571                */
14572               if (ct != -1)
14573                 {
14574                   cf = ct;
14575                   ct = -1;
14576                   code = reverse_condition (code);
14577                 }
14578
14579               out = emit_store_flag (out, code, ix86_compare_op0,
14580                                      ix86_compare_op1, VOIDmode, 0, -1);
14581
14582               out = expand_simple_binop (mode, IOR,
14583                                          out, GEN_INT (cf),
14584                                          out, 1, OPTAB_DIRECT);
14585               if (out != operands[0])
14586                 emit_move_insn (operands[0], out);
14587
14588               return 1; /* DONE */
14589             }
14590         }
14591
14592
14593       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
14594            || diff == 3 || diff == 5 || diff == 9)
14595           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
14596           && (mode != DImode
14597               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
14598         {
14599           /*
14600            * xorl dest,dest
14601            * cmpl op1,op2
14602            * setcc dest
14603            * lea cf(dest*(ct-cf)),dest
14604            *
14605            * Size 14.
14606            *
14607            * This also catches the degenerate setcc-only case.
14608            */
14609
14610           rtx tmp;
14611           int nops;
14612
14613           out = emit_store_flag (out, code, ix86_compare_op0,
14614                                  ix86_compare_op1, VOIDmode, 0, 1);
14615
14616           nops = 0;
14617           /* On x86_64 the lea instruction operates on Pmode, so we need
14618              to get arithmetics done in proper mode to match.  */
14619           if (diff == 1)
14620             tmp = copy_rtx (out);
14621           else
14622             {
14623               rtx out1;
14624               out1 = copy_rtx (out);
14625               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
14626               nops++;
14627               if (diff & 1)
14628                 {
14629                   tmp = gen_rtx_PLUS (mode, tmp, out1);
14630                   nops++;
14631                 }
14632             }
14633           if (cf != 0)
14634             {
14635               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
14636               nops++;
14637             }
14638           if (!rtx_equal_p (tmp, out))
14639             {
14640               if (nops == 1)
14641                 out = force_operand (tmp, copy_rtx (out));
14642               else
14643                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
14644             }
14645           if (!rtx_equal_p (out, operands[0]))
14646             emit_move_insn (operands[0], copy_rtx (out));
14647
14648           return 1; /* DONE */
14649         }
14650
14651       /*
14652        * General case:                  Jumpful:
14653        *   xorl dest,dest               cmpl op1, op2
14654        *   cmpl op1, op2                movl ct, dest
14655        *   setcc dest                   jcc 1f
14656        *   decl dest                    movl cf, dest
14657        *   andl (cf-ct),dest            1:
14658        *   addl ct,dest
14659        *
14660        * Size 20.                       Size 14.
14661        *
14662        * This is reasonably steep, but branch mispredict costs are
14663        * high on modern cpus, so consider failing only if optimizing
14664        * for space.
14665        */
14666
14667       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14668           && BRANCH_COST (optimize_insn_for_speed_p (),
14669                           false) >= 2)
14670         {
14671           if (cf == 0)
14672             {
14673               enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14674
14675               cf = ct;
14676               ct = 0;
14677
14678               if (SCALAR_FLOAT_MODE_P (cmp_mode))
14679                 {
14680                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14681
14682                   /* We may be reversing unordered compare to normal compare,
14683                      that is not valid in general (we may convert non-trapping
14684                      condition to trapping one), however on i386 we currently
14685                      emit all comparisons unordered.  */
14686                   code = reverse_condition_maybe_unordered (code);
14687                 }
14688               else
14689                 {
14690                   code = reverse_condition (code);
14691                   if (compare_code != UNKNOWN)
14692                     compare_code = reverse_condition (compare_code);
14693                 }
14694             }
14695
14696           if (compare_code != UNKNOWN)
14697             {
14698               /* notl op1       (if needed)
14699                  sarl $31, op1
14700                  andl (cf-ct), op1
14701                  addl ct, op1
14702
14703                  For x < 0 (resp. x <= -1) there will be no notl,
14704                  so if possible swap the constants to get rid of the
14705                  complement.
14706                  True/false will be -1/0 while code below (store flag
14707                  followed by decrement) is 0/-1, so the constants need
14708                  to be exchanged once more.  */
14709
14710               if (compare_code == GE || !cf)
14711                 {
14712                   code = reverse_condition (code);
14713                   compare_code = LT;
14714                 }
14715               else
14716                 {
14717                   HOST_WIDE_INT tmp = cf;
14718                   cf = ct;
14719                   ct = tmp;
14720                 }
14721
14722               out = emit_store_flag (out, code, ix86_compare_op0,
14723                                      ix86_compare_op1, VOIDmode, 0, -1);
14724             }
14725           else
14726             {
14727               out = emit_store_flag (out, code, ix86_compare_op0,
14728                                      ix86_compare_op1, VOIDmode, 0, 1);
14729
14730               out = expand_simple_binop (mode, PLUS, copy_rtx (out), constm1_rtx,
14731                                          copy_rtx (out), 1, OPTAB_DIRECT);
14732             }
14733
14734           out = expand_simple_binop (mode, AND, copy_rtx (out),
14735                                      gen_int_mode (cf - ct, mode),
14736                                      copy_rtx (out), 1, OPTAB_DIRECT);
14737           if (ct)
14738             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
14739                                        copy_rtx (out), 1, OPTAB_DIRECT);
14740           if (!rtx_equal_p (out, operands[0]))
14741             emit_move_insn (operands[0], copy_rtx (out));
14742
14743           return 1; /* DONE */
14744         }
14745     }
14746
14747   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14748     {
14749       /* Try a few things more with specific constants and a variable.  */
14750
14751       optab op;
14752       rtx var, orig_out, out, tmp;
14753
14754       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
14755         return 0; /* FAIL */
14756
14757       /* If one of the two operands is an interesting constant, load a
14758          constant with the above and mask it in with a logical operation.  */
14759
14760       if (CONST_INT_P (operands[2]))
14761         {
14762           var = operands[3];
14763           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
14764             operands[3] = constm1_rtx, op = and_optab;
14765           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
14766             operands[3] = const0_rtx, op = ior_optab;
14767           else
14768             return 0; /* FAIL */
14769         }
14770       else if (CONST_INT_P (operands[3]))
14771         {
14772           var = operands[2];
14773           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
14774             operands[2] = constm1_rtx, op = and_optab;
14775           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
14776             operands[2] = const0_rtx, op = ior_optab;
14777           else
14778             return 0; /* FAIL */
14779         }
14780       else
14781         return 0; /* FAIL */
14782
14783       orig_out = operands[0];
14784       tmp = gen_reg_rtx (mode);
14785       operands[0] = tmp;
14786
14787       /* Recurse to get the constant loaded.  */
14788       if (ix86_expand_int_movcc (operands) == 0)
14789         return 0; /* FAIL */
14790
14791       /* Mask in the interesting variable.  */
14792       out = expand_binop (mode, op, var, tmp, orig_out, 0,
14793                           OPTAB_WIDEN);
14794       if (!rtx_equal_p (out, orig_out))
14795         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
14796
14797       return 1; /* DONE */
14798     }
14799
14800   /*
14801    * For comparison with above,
14802    *
14803    * movl cf,dest
14804    * movl ct,tmp
14805    * cmpl op1,op2
14806    * cmovcc tmp,dest
14807    *
14808    * Size 15.
14809    */
14810
14811   if (! nonimmediate_operand (operands[2], mode))
14812     operands[2] = force_reg (mode, operands[2]);
14813   if (! nonimmediate_operand (operands[3], mode))
14814     operands[3] = force_reg (mode, operands[3]);
14815
14816   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
14817     {
14818       rtx tmp = gen_reg_rtx (mode);
14819       emit_move_insn (tmp, operands[3]);
14820       operands[3] = tmp;
14821     }
14822   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
14823     {
14824       rtx tmp = gen_reg_rtx (mode);
14825       emit_move_insn (tmp, operands[2]);
14826       operands[2] = tmp;
14827     }
14828
14829   if (! register_operand (operands[2], VOIDmode)
14830       && (mode == QImode
14831           || ! register_operand (operands[3], VOIDmode)))
14832     operands[2] = force_reg (mode, operands[2]);
14833
14834   if (mode == QImode
14835       && ! register_operand (operands[3], VOIDmode))
14836     operands[3] = force_reg (mode, operands[3]);
14837
14838   emit_insn (compare_seq);
14839   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
14840                           gen_rtx_IF_THEN_ELSE (mode,
14841                                                 compare_op, operands[2],
14842                                                 operands[3])));
14843   if (bypass_test)
14844     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
14845                             gen_rtx_IF_THEN_ELSE (mode,
14846                                   bypass_test,
14847                                   copy_rtx (operands[3]),
14848                                   copy_rtx (operands[0]))));
14849   if (second_test)
14850     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
14851                             gen_rtx_IF_THEN_ELSE (mode,
14852                                   second_test,
14853                                   copy_rtx (operands[2]),
14854                                   copy_rtx (operands[0]))));
14855
14856   return 1; /* DONE */
14857 }
14858
14859 /* Swap, force into registers, or otherwise massage the two operands
14860    to an sse comparison with a mask result.  Thus we differ a bit from
14861    ix86_prepare_fp_compare_args which expects to produce a flags result.
14862
14863    The DEST operand exists to help determine whether to commute commutative
14864    operators.  The POP0/POP1 operands are updated in place.  The new
14865    comparison code is returned, or UNKNOWN if not implementable.  */
14866
14867 static enum rtx_code
14868 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
14869                                   rtx *pop0, rtx *pop1)
14870 {
14871   rtx tmp;
14872
14873   switch (code)
14874     {
14875     case LTGT:
14876     case UNEQ:
14877       /* We have no LTGT as an operator.  We could implement it with
14878          NE & ORDERED, but this requires an extra temporary.  It's
14879          not clear that it's worth it.  */
14880       return UNKNOWN;
14881
14882     case LT:
14883     case LE:
14884     case UNGT:
14885     case UNGE:
14886       /* These are supported directly.  */
14887       break;
14888
14889     case EQ:
14890     case NE:
14891     case UNORDERED:
14892     case ORDERED:
14893       /* For commutative operators, try to canonicalize the destination
14894          operand to be first in the comparison - this helps reload to
14895          avoid extra moves.  */
14896       if (!dest || !rtx_equal_p (dest, *pop1))
14897         break;
14898       /* FALLTHRU */
14899
14900     case GE:
14901     case GT:
14902     case UNLE:
14903     case UNLT:
14904       /* These are not supported directly.  Swap the comparison operands
14905          to transform into something that is supported.  */
14906       tmp = *pop0;
14907       *pop0 = *pop1;
14908       *pop1 = tmp;
14909       code = swap_condition (code);
14910       break;
14911
14912     default:
14913       gcc_unreachable ();
14914     }
14915
14916   return code;
14917 }
14918
14919 /* Detect conditional moves that exactly match min/max operational
14920    semantics.  Note that this is IEEE safe, as long as we don't
14921    interchange the operands.
14922
14923    Returns FALSE if this conditional move doesn't match a MIN/MAX,
14924    and TRUE if the operation is successful and instructions are emitted.  */
14925
14926 static bool
14927 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
14928                            rtx cmp_op1, rtx if_true, rtx if_false)
14929 {
14930   enum machine_mode mode;
14931   bool is_min;
14932   rtx tmp;
14933
14934   if (code == LT)
14935     ;
14936   else if (code == UNGE)
14937     {
14938       tmp = if_true;
14939       if_true = if_false;
14940       if_false = tmp;
14941     }
14942   else
14943     return false;
14944
14945   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
14946     is_min = true;
14947   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
14948     is_min = false;
14949   else
14950     return false;
14951
14952   mode = GET_MODE (dest);
14953
14954   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
14955      but MODE may be a vector mode and thus not appropriate.  */
14956   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
14957     {
14958       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
14959       rtvec v;
14960
14961       if_true = force_reg (mode, if_true);
14962       v = gen_rtvec (2, if_true, if_false);
14963       tmp = gen_rtx_UNSPEC (mode, v, u);
14964     }
14965   else
14966     {
14967       code = is_min ? SMIN : SMAX;
14968       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
14969     }
14970
14971   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
14972   return true;
14973 }
14974
14975 /* Expand an sse vector comparison.  Return the register with the result.  */
14976
14977 static rtx
14978 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
14979                      rtx op_true, rtx op_false)
14980 {
14981   enum machine_mode mode = GET_MODE (dest);
14982   rtx x;
14983
14984   cmp_op0 = force_reg (mode, cmp_op0);
14985   if (!nonimmediate_operand (cmp_op1, mode))
14986     cmp_op1 = force_reg (mode, cmp_op1);
14987
14988   if (optimize
14989       || reg_overlap_mentioned_p (dest, op_true)
14990       || reg_overlap_mentioned_p (dest, op_false))
14991     dest = gen_reg_rtx (mode);
14992
14993   x = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
14994   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14995
14996   return dest;
14997 }
14998
14999 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
15000    operations.  This is used for both scalar and vector conditional moves.  */
15001
15002 static void
15003 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
15004 {
15005   enum machine_mode mode = GET_MODE (dest);
15006   rtx t2, t3, x;
15007
15008   if (op_false == CONST0_RTX (mode))
15009     {
15010       op_true = force_reg (mode, op_true);
15011       x = gen_rtx_AND (mode, cmp, op_true);
15012       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15013     }
15014   else if (op_true == CONST0_RTX (mode))
15015     {
15016       op_false = force_reg (mode, op_false);
15017       x = gen_rtx_NOT (mode, cmp);
15018       x = gen_rtx_AND (mode, x, op_false);
15019       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15020     }
15021   else if (TARGET_SSE5)
15022     {
15023       rtx pcmov = gen_rtx_SET (mode, dest,
15024                                gen_rtx_IF_THEN_ELSE (mode, cmp,
15025                                                      op_true,
15026                                                      op_false));
15027       emit_insn (pcmov);
15028     }
15029   else
15030     {
15031       op_true = force_reg (mode, op_true);
15032       op_false = force_reg (mode, op_false);
15033
15034       t2 = gen_reg_rtx (mode);
15035       if (optimize)
15036         t3 = gen_reg_rtx (mode);
15037       else
15038         t3 = dest;
15039
15040       x = gen_rtx_AND (mode, op_true, cmp);
15041       emit_insn (gen_rtx_SET (VOIDmode, t2, x));
15042
15043       x = gen_rtx_NOT (mode, cmp);
15044       x = gen_rtx_AND (mode, x, op_false);
15045       emit_insn (gen_rtx_SET (VOIDmode, t3, x));
15046
15047       x = gen_rtx_IOR (mode, t3, t2);
15048       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15049     }
15050 }
15051
15052 /* Expand a floating-point conditional move.  Return true if successful.  */
15053
15054 int
15055 ix86_expand_fp_movcc (rtx operands[])
15056 {
15057   enum machine_mode mode = GET_MODE (operands[0]);
15058   enum rtx_code code = GET_CODE (operands[1]);
15059   rtx tmp, compare_op, second_test, bypass_test;
15060
15061   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
15062     {
15063       enum machine_mode cmode;
15064
15065       /* Since we've no cmove for sse registers, don't force bad register
15066          allocation just to gain access to it.  Deny movcc when the
15067          comparison mode doesn't match the move mode.  */
15068       cmode = GET_MODE (ix86_compare_op0);
15069       if (cmode == VOIDmode)
15070         cmode = GET_MODE (ix86_compare_op1);
15071       if (cmode != mode)
15072         return 0;
15073
15074       code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15075                                                &ix86_compare_op0,
15076                                                &ix86_compare_op1);
15077       if (code == UNKNOWN)
15078         return 0;
15079
15080       if (ix86_expand_sse_fp_minmax (operands[0], code, ix86_compare_op0,
15081                                      ix86_compare_op1, operands[2],
15082                                      operands[3]))
15083         return 1;
15084
15085       tmp = ix86_expand_sse_cmp (operands[0], code, ix86_compare_op0,
15086                                  ix86_compare_op1, operands[2], operands[3]);
15087       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
15088       return 1;
15089     }
15090
15091   /* The floating point conditional move instructions don't directly
15092      support conditions resulting from a signed integer comparison.  */
15093
15094   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
15095
15096   /* The floating point conditional move instructions don't directly
15097      support signed integer comparisons.  */
15098
15099   if (!fcmov_comparison_operator (compare_op, VOIDmode))
15100     {
15101       gcc_assert (!second_test && !bypass_test);
15102       tmp = gen_reg_rtx (QImode);
15103       ix86_expand_setcc (code, tmp);
15104       code = NE;
15105       ix86_compare_op0 = tmp;
15106       ix86_compare_op1 = const0_rtx;
15107       compare_op = ix86_expand_compare (code,  &second_test, &bypass_test);
15108     }
15109   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
15110     {
15111       tmp = gen_reg_rtx (mode);
15112       emit_move_insn (tmp, operands[3]);
15113       operands[3] = tmp;
15114     }
15115   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
15116     {
15117       tmp = gen_reg_rtx (mode);
15118       emit_move_insn (tmp, operands[2]);
15119       operands[2] = tmp;
15120     }
15121
15122   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15123                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
15124                                                 operands[2], operands[3])));
15125   if (bypass_test)
15126     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15127                             gen_rtx_IF_THEN_ELSE (mode, bypass_test,
15128                                                   operands[3], operands[0])));
15129   if (second_test)
15130     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15131                             gen_rtx_IF_THEN_ELSE (mode, second_test,
15132                                                   operands[2], operands[0])));
15133
15134   return 1;
15135 }
15136
15137 /* Expand a floating-point vector conditional move; a vcond operation
15138    rather than a movcc operation.  */
15139
15140 bool
15141 ix86_expand_fp_vcond (rtx operands[])
15142 {
15143   enum rtx_code code = GET_CODE (operands[3]);
15144   rtx cmp;
15145
15146   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15147                                            &operands[4], &operands[5]);
15148   if (code == UNKNOWN)
15149     return false;
15150
15151   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
15152                                  operands[5], operands[1], operands[2]))
15153     return true;
15154
15155   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
15156                              operands[1], operands[2]);
15157   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
15158   return true;
15159 }
15160
15161 /* Expand a signed/unsigned integral vector conditional move.  */
15162
15163 bool
15164 ix86_expand_int_vcond (rtx operands[])
15165 {
15166   enum machine_mode mode = GET_MODE (operands[0]);
15167   enum rtx_code code = GET_CODE (operands[3]);
15168   bool negate = false;
15169   rtx x, cop0, cop1;
15170
15171   cop0 = operands[4];
15172   cop1 = operands[5];
15173
15174   /* SSE5 supports all of the comparisons on all vector int types.  */
15175   if (!TARGET_SSE5)
15176     {
15177       /* Canonicalize the comparison to EQ, GT, GTU.  */
15178       switch (code)
15179         {
15180         case EQ:
15181         case GT:
15182         case GTU:
15183           break;
15184
15185         case NE:
15186         case LE:
15187         case LEU:
15188           code = reverse_condition (code);
15189           negate = true;
15190           break;
15191
15192         case GE:
15193         case GEU:
15194           code = reverse_condition (code);
15195           negate = true;
15196           /* FALLTHRU */
15197
15198         case LT:
15199         case LTU:
15200           code = swap_condition (code);
15201           x = cop0, cop0 = cop1, cop1 = x;
15202           break;
15203
15204         default:
15205           gcc_unreachable ();
15206         }
15207
15208       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
15209       if (mode == V2DImode)
15210         {
15211           switch (code)
15212             {
15213             case EQ:
15214               /* SSE4.1 supports EQ.  */
15215               if (!TARGET_SSE4_1)
15216                 return false;
15217               break;
15218
15219             case GT:
15220             case GTU:
15221               /* SSE4.2 supports GT/GTU.  */
15222               if (!TARGET_SSE4_2)
15223                 return false;
15224               break;
15225
15226             default:
15227               gcc_unreachable ();
15228             }
15229         }
15230
15231       /* Unsigned parallel compare is not supported by the hardware.  Play some
15232          tricks to turn this into a signed comparison against 0.  */
15233       if (code == GTU)
15234         {
15235           cop0 = force_reg (mode, cop0);
15236
15237           switch (mode)
15238             {
15239             case V4SImode:
15240             case V2DImode:
15241               {
15242                 rtx t1, t2, mask;
15243
15244                 /* Perform a parallel modulo subtraction.  */
15245                 t1 = gen_reg_rtx (mode);
15246                 emit_insn ((mode == V4SImode
15247                             ? gen_subv4si3
15248                             : gen_subv2di3) (t1, cop0, cop1));
15249
15250                 /* Extract the original sign bit of op0.  */
15251                 mask = ix86_build_signbit_mask (GET_MODE_INNER (mode),
15252                                                 true, false);
15253                 t2 = gen_reg_rtx (mode);
15254                 emit_insn ((mode == V4SImode
15255                             ? gen_andv4si3
15256                             : gen_andv2di3) (t2, cop0, mask));
15257
15258                 /* XOR it back into the result of the subtraction.  This results
15259                    in the sign bit set iff we saw unsigned underflow.  */
15260                 x = gen_reg_rtx (mode);
15261                 emit_insn ((mode == V4SImode
15262                             ? gen_xorv4si3
15263                             : gen_xorv2di3) (x, t1, t2));
15264
15265                 code = GT;
15266               }
15267               break;
15268
15269             case V16QImode:
15270             case V8HImode:
15271               /* Perform a parallel unsigned saturating subtraction.  */
15272               x = gen_reg_rtx (mode);
15273               emit_insn (gen_rtx_SET (VOIDmode, x,
15274                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
15275
15276               code = EQ;
15277               negate = !negate;
15278               break;
15279
15280             default:
15281               gcc_unreachable ();
15282             }
15283
15284           cop0 = x;
15285           cop1 = CONST0_RTX (mode);
15286         }
15287     }
15288
15289   x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
15290                            operands[1+negate], operands[2-negate]);
15291
15292   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
15293                          operands[2-negate]);
15294   return true;
15295 }
15296
15297 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
15298    true if we should do zero extension, else sign extension.  HIGH_P is
15299    true if we want the N/2 high elements, else the low elements.  */
15300
15301 void
15302 ix86_expand_sse_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15303 {
15304   enum machine_mode imode = GET_MODE (operands[1]);
15305   rtx (*unpack)(rtx, rtx, rtx);
15306   rtx se, dest;
15307
15308   switch (imode)
15309     {
15310     case V16QImode:
15311       if (high_p)
15312         unpack = gen_vec_interleave_highv16qi;
15313       else
15314         unpack = gen_vec_interleave_lowv16qi;
15315       break;
15316     case V8HImode:
15317       if (high_p)
15318         unpack = gen_vec_interleave_highv8hi;
15319       else
15320         unpack = gen_vec_interleave_lowv8hi;
15321       break;
15322     case V4SImode:
15323       if (high_p)
15324         unpack = gen_vec_interleave_highv4si;
15325       else
15326         unpack = gen_vec_interleave_lowv4si;
15327       break;
15328     default:
15329       gcc_unreachable ();
15330     }
15331
15332   dest = gen_lowpart (imode, operands[0]);
15333
15334   if (unsigned_p)
15335     se = force_reg (imode, CONST0_RTX (imode));
15336   else
15337     se = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
15338                               operands[1], pc_rtx, pc_rtx);
15339
15340   emit_insn (unpack (dest, operands[1], se));
15341 }
15342
15343 /* This function performs the same task as ix86_expand_sse_unpack,
15344    but with SSE4.1 instructions.  */
15345
15346 void
15347 ix86_expand_sse4_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15348 {
15349   enum machine_mode imode = GET_MODE (operands[1]);
15350   rtx (*unpack)(rtx, rtx);
15351   rtx src, dest;
15352
15353   switch (imode)
15354     {
15355     case V16QImode:
15356       if (unsigned_p)
15357         unpack = gen_sse4_1_zero_extendv8qiv8hi2;
15358       else
15359         unpack = gen_sse4_1_extendv8qiv8hi2;
15360       break;
15361     case V8HImode:
15362       if (unsigned_p)
15363         unpack = gen_sse4_1_zero_extendv4hiv4si2;
15364       else
15365         unpack = gen_sse4_1_extendv4hiv4si2;
15366       break;
15367     case V4SImode:
15368       if (unsigned_p)
15369         unpack = gen_sse4_1_zero_extendv2siv2di2;
15370       else
15371         unpack = gen_sse4_1_extendv2siv2di2;
15372       break;
15373     default:
15374       gcc_unreachable ();
15375     }
15376
15377   dest = operands[0];
15378   if (high_p)
15379     {
15380       /* Shift higher 8 bytes to lower 8 bytes.  */
15381       src = gen_reg_rtx (imode);
15382       emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, src),
15383                                    gen_lowpart (TImode, operands[1]),
15384                                    GEN_INT (64)));
15385     }
15386   else
15387     src = operands[1];
15388
15389   emit_insn (unpack (dest, src));
15390 }
15391
15392 /* This function performs the same task as ix86_expand_sse_unpack,
15393    but with sse5 instructions.  */
15394
15395 void
15396 ix86_expand_sse5_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15397 {
15398   enum machine_mode imode = GET_MODE (operands[1]);
15399   int pperm_bytes[16];
15400   int i;
15401   int h = (high_p) ? 8 : 0;
15402   int h2;
15403   int sign_extend;
15404   rtvec v = rtvec_alloc (16);
15405   rtvec vs;
15406   rtx x, p;
15407   rtx op0 = operands[0], op1 = operands[1];
15408
15409   switch (imode)
15410     {
15411     case V16QImode:
15412       vs = rtvec_alloc (8);
15413       h2 = (high_p) ? 8 : 0;
15414       for (i = 0; i < 8; i++)
15415         {
15416           pperm_bytes[2*i+0] = PPERM_SRC | PPERM_SRC2 | i | h;
15417           pperm_bytes[2*i+1] = ((unsigned_p)
15418                                 ? PPERM_ZERO
15419                                 : PPERM_SIGN | PPERM_SRC2 | i | h);
15420         }
15421
15422       for (i = 0; i < 16; i++)
15423         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15424
15425       for (i = 0; i < 8; i++)
15426         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15427
15428       p = gen_rtx_PARALLEL (VOIDmode, vs);
15429       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15430       if (unsigned_p)
15431         emit_insn (gen_sse5_pperm_zero_v16qi_v8hi (op0, op1, p, x));
15432       else
15433         emit_insn (gen_sse5_pperm_sign_v16qi_v8hi (op0, op1, p, x));
15434       break;
15435
15436     case V8HImode:
15437       vs = rtvec_alloc (4);
15438       h2 = (high_p) ? 4 : 0;
15439       for (i = 0; i < 4; i++)
15440         {
15441           sign_extend = ((unsigned_p)
15442                          ? PPERM_ZERO
15443                          : PPERM_SIGN | PPERM_SRC2 | ((2*i) + 1 + h));
15444           pperm_bytes[4*i+0] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 0 + h);
15445           pperm_bytes[4*i+1] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 1 + h);
15446           pperm_bytes[4*i+2] = sign_extend;
15447           pperm_bytes[4*i+3] = sign_extend;
15448         }
15449
15450       for (i = 0; i < 16; i++)
15451         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15452
15453       for (i = 0; i < 4; i++)
15454         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15455
15456       p = gen_rtx_PARALLEL (VOIDmode, vs);
15457       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15458       if (unsigned_p)
15459         emit_insn (gen_sse5_pperm_zero_v8hi_v4si (op0, op1, p, x));
15460       else
15461         emit_insn (gen_sse5_pperm_sign_v8hi_v4si (op0, op1, p, x));
15462       break;
15463
15464     case V4SImode:
15465       vs = rtvec_alloc (2);
15466       h2 = (high_p) ? 2 : 0;
15467       for (i = 0; i < 2; i++)
15468         {
15469           sign_extend = ((unsigned_p)
15470                          ? PPERM_ZERO
15471                          : PPERM_SIGN | PPERM_SRC2 | ((4*i) + 3 + h));
15472           pperm_bytes[8*i+0] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 0 + h);
15473           pperm_bytes[8*i+1] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 1 + h);
15474           pperm_bytes[8*i+2] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 2 + h);
15475           pperm_bytes[8*i+3] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 3 + h);
15476           pperm_bytes[8*i+4] = sign_extend;
15477           pperm_bytes[8*i+5] = sign_extend;
15478           pperm_bytes[8*i+6] = sign_extend;
15479           pperm_bytes[8*i+7] = sign_extend;
15480         }
15481
15482       for (i = 0; i < 16; i++)
15483         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15484
15485       for (i = 0; i < 2; i++)
15486         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15487
15488       p = gen_rtx_PARALLEL (VOIDmode, vs);
15489       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15490       if (unsigned_p)
15491         emit_insn (gen_sse5_pperm_zero_v4si_v2di (op0, op1, p, x));
15492       else
15493         emit_insn (gen_sse5_pperm_sign_v4si_v2di (op0, op1, p, x));
15494       break;
15495
15496     default:
15497       gcc_unreachable ();
15498     }
15499
15500   return;
15501 }
15502
15503 /* Pack the high bits from OPERANDS[1] and low bits from OPERANDS[2] into the
15504    next narrower integer vector type */
15505 void
15506 ix86_expand_sse5_pack (rtx operands[3])
15507 {
15508   enum machine_mode imode = GET_MODE (operands[0]);
15509   int pperm_bytes[16];
15510   int i;
15511   rtvec v = rtvec_alloc (16);
15512   rtx x;
15513   rtx op0 = operands[0];
15514   rtx op1 = operands[1];
15515   rtx op2 = operands[2];
15516
15517   switch (imode)
15518     {
15519     case V16QImode:
15520       for (i = 0; i < 8; i++)
15521         {
15522           pperm_bytes[i+0] = PPERM_SRC | PPERM_SRC1 | (i*2);
15523           pperm_bytes[i+8] = PPERM_SRC | PPERM_SRC2 | (i*2);
15524         }
15525
15526       for (i = 0; i < 16; i++)
15527         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15528
15529       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15530       emit_insn (gen_sse5_pperm_pack_v8hi_v16qi (op0, op1, op2, x));
15531       break;
15532
15533     case V8HImode:
15534       for (i = 0; i < 4; i++)
15535         {
15536           pperm_bytes[(2*i)+0] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 0);
15537           pperm_bytes[(2*i)+1] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 1);
15538           pperm_bytes[(2*i)+8] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 0);
15539           pperm_bytes[(2*i)+9] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 1);
15540         }
15541
15542       for (i = 0; i < 16; i++)
15543         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15544
15545       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15546       emit_insn (gen_sse5_pperm_pack_v4si_v8hi (op0, op1, op2, x));
15547       break;
15548
15549     case V4SImode:
15550       for (i = 0; i < 2; i++)
15551         {
15552           pperm_bytes[(4*i)+0]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 0);
15553           pperm_bytes[(4*i)+1]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 1);
15554           pperm_bytes[(4*i)+2]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 2);
15555           pperm_bytes[(4*i)+3]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 3);
15556           pperm_bytes[(4*i)+8]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 0);
15557           pperm_bytes[(4*i)+9]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 1);
15558           pperm_bytes[(4*i)+10] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 2);
15559           pperm_bytes[(4*i)+11] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 3);
15560         }
15561
15562       for (i = 0; i < 16; i++)
15563         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15564
15565       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15566       emit_insn (gen_sse5_pperm_pack_v2di_v4si (op0, op1, op2, x));
15567       break;
15568
15569     default:
15570       gcc_unreachable ();
15571     }
15572
15573   return;
15574 }
15575
15576 /* Expand conditional increment or decrement using adb/sbb instructions.
15577    The default case using setcc followed by the conditional move can be
15578    done by generic code.  */
15579 int
15580 ix86_expand_int_addcc (rtx operands[])
15581 {
15582   enum rtx_code code = GET_CODE (operands[1]);
15583   rtx compare_op;
15584   rtx val = const0_rtx;
15585   bool fpcmp = false;
15586   enum machine_mode mode = GET_MODE (operands[0]);
15587
15588   if (operands[3] != const1_rtx
15589       && operands[3] != constm1_rtx)
15590     return 0;
15591   if (!ix86_expand_carry_flag_compare (code, ix86_compare_op0,
15592                                        ix86_compare_op1, &compare_op))
15593      return 0;
15594   code = GET_CODE (compare_op);
15595
15596   if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
15597       || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
15598     {
15599       fpcmp = true;
15600       code = ix86_fp_compare_code_to_integer (code);
15601     }
15602
15603   if (code != LTU)
15604     {
15605       val = constm1_rtx;
15606       if (fpcmp)
15607         PUT_CODE (compare_op,
15608                   reverse_condition_maybe_unordered
15609                     (GET_CODE (compare_op)));
15610       else
15611         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
15612     }
15613   PUT_MODE (compare_op, mode);
15614
15615   /* Construct either adc or sbb insn.  */
15616   if ((code == LTU) == (operands[3] == constm1_rtx))
15617     {
15618       switch (GET_MODE (operands[0]))
15619         {
15620           case QImode:
15621             emit_insn (gen_subqi3_carry (operands[0], operands[2], val, compare_op));
15622             break;
15623           case HImode:
15624             emit_insn (gen_subhi3_carry (operands[0], operands[2], val, compare_op));
15625             break;
15626           case SImode:
15627             emit_insn (gen_subsi3_carry (operands[0], operands[2], val, compare_op));
15628             break;
15629           case DImode:
15630             emit_insn (gen_subdi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15631             break;
15632           default:
15633             gcc_unreachable ();
15634         }
15635     }
15636   else
15637     {
15638       switch (GET_MODE (operands[0]))
15639         {
15640           case QImode:
15641             emit_insn (gen_addqi3_carry (operands[0], operands[2], val, compare_op));
15642             break;
15643           case HImode:
15644             emit_insn (gen_addhi3_carry (operands[0], operands[2], val, compare_op));
15645             break;
15646           case SImode:
15647             emit_insn (gen_addsi3_carry (operands[0], operands[2], val, compare_op));
15648             break;
15649           case DImode:
15650             emit_insn (gen_adddi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15651             break;
15652           default:
15653             gcc_unreachable ();
15654         }
15655     }
15656   return 1; /* DONE */
15657 }
15658
15659
15660 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
15661    works for floating pointer parameters and nonoffsetable memories.
15662    For pushes, it returns just stack offsets; the values will be saved
15663    in the right order.  Maximally three parts are generated.  */
15664
15665 static int
15666 ix86_split_to_parts (rtx operand, rtx *parts, enum machine_mode mode)
15667 {
15668   int size;
15669
15670   if (!TARGET_64BIT)
15671     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
15672   else
15673     size = (GET_MODE_SIZE (mode) + 4) / 8;
15674
15675   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
15676   gcc_assert (size >= 2 && size <= 4);
15677
15678   /* Optimize constant pool reference to immediates.  This is used by fp
15679      moves, that force all constants to memory to allow combining.  */
15680   if (MEM_P (operand) && MEM_READONLY_P (operand))
15681     {
15682       rtx tmp = maybe_get_pool_constant (operand);
15683       if (tmp)
15684         operand = tmp;
15685     }
15686
15687   if (MEM_P (operand) && !offsettable_memref_p (operand))
15688     {
15689       /* The only non-offsetable memories we handle are pushes.  */
15690       int ok = push_operand (operand, VOIDmode);
15691
15692       gcc_assert (ok);
15693
15694       operand = copy_rtx (operand);
15695       PUT_MODE (operand, Pmode);
15696       parts[0] = parts[1] = parts[2] = parts[3] = operand;
15697       return size;
15698     }
15699
15700   if (GET_CODE (operand) == CONST_VECTOR)
15701     {
15702       enum machine_mode imode = int_mode_for_mode (mode);
15703       /* Caution: if we looked through a constant pool memory above,
15704          the operand may actually have a different mode now.  That's
15705          ok, since we want to pun this all the way back to an integer.  */
15706       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
15707       gcc_assert (operand != NULL);
15708       mode = imode;
15709     }
15710
15711   if (!TARGET_64BIT)
15712     {
15713       if (mode == DImode)
15714         split_di (&operand, 1, &parts[0], &parts[1]);
15715       else
15716         {
15717           int i;
15718
15719           if (REG_P (operand))
15720             {
15721               gcc_assert (reload_completed);
15722               for (i = 0; i < size; i++)
15723                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
15724             }
15725           else if (offsettable_memref_p (operand))
15726             {
15727               operand = adjust_address (operand, SImode, 0);
15728               parts[0] = operand;
15729               for (i = 1; i < size; i++)
15730                 parts[i] = adjust_address (operand, SImode, 4 * i);
15731             }
15732           else if (GET_CODE (operand) == CONST_DOUBLE)
15733             {
15734               REAL_VALUE_TYPE r;
15735               long l[4];
15736
15737               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
15738               switch (mode)
15739                 {
15740                 case TFmode:
15741                   real_to_target (l, &r, mode);
15742                   parts[3] = gen_int_mode (l[3], SImode);
15743                   parts[2] = gen_int_mode (l[2], SImode);
15744                   break;
15745                 case XFmode:
15746                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
15747                   parts[2] = gen_int_mode (l[2], SImode);
15748                   break;
15749                 case DFmode:
15750                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
15751                   break;
15752                 default:
15753                   gcc_unreachable ();
15754                 }
15755               parts[1] = gen_int_mode (l[1], SImode);
15756               parts[0] = gen_int_mode (l[0], SImode);
15757             }
15758           else
15759             gcc_unreachable ();
15760         }
15761     }
15762   else
15763     {
15764       if (mode == TImode)
15765         split_ti (&operand, 1, &parts[0], &parts[1]);
15766       if (mode == XFmode || mode == TFmode)
15767         {
15768           enum machine_mode upper_mode = mode==XFmode ? SImode : DImode;
15769           if (REG_P (operand))
15770             {
15771               gcc_assert (reload_completed);
15772               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
15773               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
15774             }
15775           else if (offsettable_memref_p (operand))
15776             {
15777               operand = adjust_address (operand, DImode, 0);
15778               parts[0] = operand;
15779               parts[1] = adjust_address (operand, upper_mode, 8);
15780             }
15781           else if (GET_CODE (operand) == CONST_DOUBLE)
15782             {
15783               REAL_VALUE_TYPE r;
15784               long l[4];
15785
15786               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
15787               real_to_target (l, &r, mode);
15788
15789               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
15790               if (HOST_BITS_PER_WIDE_INT >= 64)
15791                 parts[0]
15792                   = gen_int_mode
15793                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
15794                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
15795                        DImode);
15796               else
15797                 parts[0] = immed_double_const (l[0], l[1], DImode);
15798
15799               if (upper_mode == SImode)
15800                 parts[1] = gen_int_mode (l[2], SImode);
15801               else if (HOST_BITS_PER_WIDE_INT >= 64)
15802                 parts[1]
15803                   = gen_int_mode
15804                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
15805                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
15806                        DImode);
15807               else
15808                 parts[1] = immed_double_const (l[2], l[3], DImode);
15809             }
15810           else
15811             gcc_unreachable ();
15812         }
15813     }
15814
15815   return size;
15816 }
15817
15818 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
15819    Return false when normal moves are needed; true when all required
15820    insns have been emitted.  Operands 2-4 contain the input values
15821    int the correct order; operands 5-7 contain the output values.  */
15822
15823 void
15824 ix86_split_long_move (rtx operands[])
15825 {
15826   rtx part[2][4];
15827   int nparts, i, j;
15828   int push = 0;
15829   int collisions = 0;
15830   enum machine_mode mode = GET_MODE (operands[0]);
15831   bool collisionparts[4];
15832
15833   /* The DFmode expanders may ask us to move double.
15834      For 64bit target this is single move.  By hiding the fact
15835      here we simplify i386.md splitters.  */
15836   if (GET_MODE_SIZE (GET_MODE (operands[0])) == 8 && TARGET_64BIT)
15837     {
15838       /* Optimize constant pool reference to immediates.  This is used by
15839          fp moves, that force all constants to memory to allow combining.  */
15840
15841       if (MEM_P (operands[1])
15842           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
15843           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
15844         operands[1] = get_pool_constant (XEXP (operands[1], 0));
15845       if (push_operand (operands[0], VOIDmode))
15846         {
15847           operands[0] = copy_rtx (operands[0]);
15848           PUT_MODE (operands[0], Pmode);
15849         }
15850       else
15851         operands[0] = gen_lowpart (DImode, operands[0]);
15852       operands[1] = gen_lowpart (DImode, operands[1]);
15853       emit_move_insn (operands[0], operands[1]);
15854       return;
15855     }
15856
15857   /* The only non-offsettable memory we handle is push.  */
15858   if (push_operand (operands[0], VOIDmode))
15859     push = 1;
15860   else
15861     gcc_assert (!MEM_P (operands[0])
15862                 || offsettable_memref_p (operands[0]));
15863
15864   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
15865   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
15866
15867   /* When emitting push, take care for source operands on the stack.  */
15868   if (push && MEM_P (operands[1])
15869       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
15870     for (i = 0; i < nparts - 1; i++)
15871       part[1][i] = change_address (part[1][i],
15872                                    GET_MODE (part[1][i]),
15873                                    XEXP (part[1][i + 1], 0));
15874
15875   /* We need to do copy in the right order in case an address register
15876      of the source overlaps the destination.  */
15877   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
15878     {
15879       rtx tmp;
15880
15881       for (i = 0; i < nparts; i++)
15882         {
15883           collisionparts[i]
15884             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
15885           if (collisionparts[i])
15886             collisions++;
15887         }
15888
15889       /* Collision in the middle part can be handled by reordering.  */
15890       if (collisions == 1 && nparts == 3 && collisionparts [1])
15891         {
15892           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
15893           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
15894         }
15895       else if (collisions == 1
15896                && nparts == 4
15897                && (collisionparts [1] || collisionparts [2]))
15898         {
15899           if (collisionparts [1])
15900             {
15901               tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
15902               tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
15903             }
15904           else
15905             {
15906               tmp = part[0][2]; part[0][2] = part[0][3]; part[0][3] = tmp;
15907               tmp = part[1][2]; part[1][2] = part[1][3]; part[1][3] = tmp;
15908             }
15909         }
15910
15911       /* If there are more collisions, we can't handle it by reordering.
15912          Do an lea to the last part and use only one colliding move.  */
15913       else if (collisions > 1)
15914         {
15915           rtx base;
15916
15917           collisions = 1;
15918
15919           base = part[0][nparts - 1];
15920
15921           /* Handle the case when the last part isn't valid for lea.
15922              Happens in 64-bit mode storing the 12-byte XFmode.  */
15923           if (GET_MODE (base) != Pmode)
15924             base = gen_rtx_REG (Pmode, REGNO (base));
15925
15926           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
15927           part[1][0] = replace_equiv_address (part[1][0], base);
15928           for (i = 1; i < nparts; i++)
15929             {
15930               tmp = plus_constant (base, UNITS_PER_WORD * i);
15931               part[1][i] = replace_equiv_address (part[1][i], tmp);
15932             }
15933         }
15934     }
15935
15936   if (push)
15937     {
15938       if (!TARGET_64BIT)
15939         {
15940           if (nparts == 3)
15941             {
15942               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
15943                 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-4)));
15944               emit_move_insn (part[0][2], part[1][2]);
15945             }
15946           else if (nparts == 4)
15947             {
15948               emit_move_insn (part[0][3], part[1][3]);
15949               emit_move_insn (part[0][2], part[1][2]);
15950             }
15951         }
15952       else
15953         {
15954           /* In 64bit mode we don't have 32bit push available.  In case this is
15955              register, it is OK - we will just use larger counterpart.  We also
15956              retype memory - these comes from attempt to avoid REX prefix on
15957              moving of second half of TFmode value.  */
15958           if (GET_MODE (part[1][1]) == SImode)
15959             {
15960               switch (GET_CODE (part[1][1]))
15961                 {
15962                 case MEM:
15963                   part[1][1] = adjust_address (part[1][1], DImode, 0);
15964                   break;
15965
15966                 case REG:
15967                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
15968                   break;
15969
15970                 default:
15971                   gcc_unreachable ();
15972                 }
15973
15974               if (GET_MODE (part[1][0]) == SImode)
15975                 part[1][0] = part[1][1];
15976             }
15977         }
15978       emit_move_insn (part[0][1], part[1][1]);
15979       emit_move_insn (part[0][0], part[1][0]);
15980       return;
15981     }
15982
15983   /* Choose correct order to not overwrite the source before it is copied.  */
15984   if ((REG_P (part[0][0])
15985        && REG_P (part[1][1])
15986        && (REGNO (part[0][0]) == REGNO (part[1][1])
15987            || (nparts == 3
15988                && REGNO (part[0][0]) == REGNO (part[1][2]))
15989            || (nparts == 4
15990                && REGNO (part[0][0]) == REGNO (part[1][3]))))
15991       || (collisions > 0
15992           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
15993     {
15994       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
15995         {
15996           operands[2 + i] = part[0][j];
15997           operands[6 + i] = part[1][j];
15998         }
15999     }
16000   else
16001     {
16002       for (i = 0; i < nparts; i++)
16003         {
16004           operands[2 + i] = part[0][i];
16005           operands[6 + i] = part[1][i];
16006         }
16007     }
16008
16009   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
16010   if (optimize_insn_for_size_p ())
16011     {
16012       for (j = 0; j < nparts - 1; j++)
16013         if (CONST_INT_P (operands[6 + j])
16014             && operands[6 + j] != const0_rtx
16015             && REG_P (operands[2 + j]))
16016           for (i = j; i < nparts - 1; i++)
16017             if (CONST_INT_P (operands[7 + i])
16018                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
16019               operands[7 + i] = operands[2 + j];
16020     }
16021
16022   for (i = 0; i < nparts; i++)
16023     emit_move_insn (operands[2 + i], operands[6 + i]);
16024
16025   return;
16026 }
16027
16028 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
16029    left shift by a constant, either using a single shift or
16030    a sequence of add instructions.  */
16031
16032 static void
16033 ix86_expand_ashl_const (rtx operand, int count, enum machine_mode mode)
16034 {
16035   if (count == 1)
16036     {
16037       emit_insn ((mode == DImode
16038                   ? gen_addsi3
16039                   : gen_adddi3) (operand, operand, operand));
16040     }
16041   else if (!optimize_insn_for_size_p ()
16042            && count * ix86_cost->add <= ix86_cost->shift_const)
16043     {
16044       int i;
16045       for (i=0; i<count; i++)
16046         {
16047           emit_insn ((mode == DImode
16048                       ? gen_addsi3
16049                       : gen_adddi3) (operand, operand, operand));
16050         }
16051     }
16052   else
16053     emit_insn ((mode == DImode
16054                 ? gen_ashlsi3
16055                 : gen_ashldi3) (operand, operand, GEN_INT (count)));
16056 }
16057
16058 void
16059 ix86_split_ashl (rtx *operands, rtx scratch, enum machine_mode mode)
16060 {
16061   rtx low[2], high[2];
16062   int count;
16063   const int single_width = mode == DImode ? 32 : 64;
16064
16065   if (CONST_INT_P (operands[2]))
16066     {
16067       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16068       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16069
16070       if (count >= single_width)
16071         {
16072           emit_move_insn (high[0], low[1]);
16073           emit_move_insn (low[0], const0_rtx);
16074
16075           if (count > single_width)
16076             ix86_expand_ashl_const (high[0], count - single_width, mode);
16077         }
16078       else
16079         {
16080           if (!rtx_equal_p (operands[0], operands[1]))
16081             emit_move_insn (operands[0], operands[1]);
16082           emit_insn ((mode == DImode
16083                      ? gen_x86_shld
16084                      : gen_x86_64_shld) (high[0], low[0], GEN_INT (count)));
16085           ix86_expand_ashl_const (low[0], count, mode);
16086         }
16087       return;
16088     }
16089
16090   (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16091
16092   if (operands[1] == const1_rtx)
16093     {
16094       /* Assuming we've chosen a QImode capable registers, then 1 << N
16095          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
16096       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
16097         {
16098           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
16099
16100           ix86_expand_clear (low[0]);
16101           ix86_expand_clear (high[0]);
16102           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (single_width)));
16103
16104           d = gen_lowpart (QImode, low[0]);
16105           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16106           s = gen_rtx_EQ (QImode, flags, const0_rtx);
16107           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16108
16109           d = gen_lowpart (QImode, high[0]);
16110           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16111           s = gen_rtx_NE (QImode, flags, const0_rtx);
16112           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16113         }
16114
16115       /* Otherwise, we can get the same results by manually performing
16116          a bit extract operation on bit 5/6, and then performing the two
16117          shifts.  The two methods of getting 0/1 into low/high are exactly
16118          the same size.  Avoiding the shift in the bit extract case helps
16119          pentium4 a bit; no one else seems to care much either way.  */
16120       else
16121         {
16122           rtx x;
16123
16124           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
16125             x = gen_rtx_ZERO_EXTEND (mode == DImode ? SImode : DImode, operands[2]);
16126           else
16127             x = gen_lowpart (mode == DImode ? SImode : DImode, operands[2]);
16128           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
16129
16130           emit_insn ((mode == DImode
16131                       ? gen_lshrsi3
16132                       : gen_lshrdi3) (high[0], high[0], GEN_INT (mode == DImode ? 5 : 6)));
16133           emit_insn ((mode == DImode
16134                       ? gen_andsi3
16135                       : gen_anddi3) (high[0], high[0], GEN_INT (1)));
16136           emit_move_insn (low[0], high[0]);
16137           emit_insn ((mode == DImode
16138                       ? gen_xorsi3
16139                       : gen_xordi3) (low[0], low[0], GEN_INT (1)));
16140         }
16141
16142       emit_insn ((mode == DImode
16143                     ? gen_ashlsi3
16144                     : gen_ashldi3) (low[0], low[0], operands[2]));
16145       emit_insn ((mode == DImode
16146                     ? gen_ashlsi3
16147                     : gen_ashldi3) (high[0], high[0], operands[2]));
16148       return;
16149     }
16150
16151   if (operands[1] == constm1_rtx)
16152     {
16153       /* For -1 << N, we can avoid the shld instruction, because we
16154          know that we're shifting 0...31/63 ones into a -1.  */
16155       emit_move_insn (low[0], constm1_rtx);
16156       if (optimize_insn_for_size_p ())
16157         emit_move_insn (high[0], low[0]);
16158       else
16159         emit_move_insn (high[0], constm1_rtx);
16160     }
16161   else
16162     {
16163       if (!rtx_equal_p (operands[0], operands[1]))
16164         emit_move_insn (operands[0], operands[1]);
16165
16166       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16167       emit_insn ((mode == DImode
16168                   ? gen_x86_shld
16169                   : gen_x86_64_shld) (high[0], low[0], operands[2]));
16170     }
16171
16172   emit_insn ((mode == DImode ? gen_ashlsi3 : gen_ashldi3) (low[0], low[0], operands[2]));
16173
16174   if (TARGET_CMOVE && scratch)
16175     {
16176       ix86_expand_clear (scratch);
16177       emit_insn ((mode == DImode
16178                   ? gen_x86_shift_adj_1
16179                   : gen_x86_64_shift_adj_1) (high[0], low[0], operands[2],
16180                                              scratch));
16181     }
16182   else
16183     emit_insn ((mode == DImode
16184                 ? gen_x86_shift_adj_2
16185                 : gen_x86_64_shift_adj_2) (high[0], low[0], operands[2]));
16186 }
16187
16188 void
16189 ix86_split_ashr (rtx *operands, rtx scratch, enum machine_mode mode)
16190 {
16191   rtx low[2], high[2];
16192   int count;
16193   const int single_width = mode == DImode ? 32 : 64;
16194
16195   if (CONST_INT_P (operands[2]))
16196     {
16197       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16198       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16199
16200       if (count == single_width * 2 - 1)
16201         {
16202           emit_move_insn (high[0], high[1]);
16203           emit_insn ((mode == DImode
16204                       ? gen_ashrsi3
16205                       : gen_ashrdi3) (high[0], high[0],
16206                                       GEN_INT (single_width - 1)));
16207           emit_move_insn (low[0], high[0]);
16208
16209         }
16210       else if (count >= single_width)
16211         {
16212           emit_move_insn (low[0], high[1]);
16213           emit_move_insn (high[0], low[0]);
16214           emit_insn ((mode == DImode
16215                       ? gen_ashrsi3
16216                       : gen_ashrdi3) (high[0], high[0],
16217                                       GEN_INT (single_width - 1)));
16218           if (count > single_width)
16219             emit_insn ((mode == DImode
16220                         ? gen_ashrsi3
16221                         : gen_ashrdi3) (low[0], low[0],
16222                                         GEN_INT (count - single_width)));
16223         }
16224       else
16225         {
16226           if (!rtx_equal_p (operands[0], operands[1]))
16227             emit_move_insn (operands[0], operands[1]);
16228           emit_insn ((mode == DImode
16229                       ? gen_x86_shrd
16230                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16231           emit_insn ((mode == DImode
16232                       ? gen_ashrsi3
16233                       : gen_ashrdi3) (high[0], high[0], GEN_INT (count)));
16234         }
16235     }
16236   else
16237     {
16238       if (!rtx_equal_p (operands[0], operands[1]))
16239         emit_move_insn (operands[0], operands[1]);
16240
16241       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16242
16243       emit_insn ((mode == DImode
16244                   ? gen_x86_shrd
16245                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16246       emit_insn ((mode == DImode
16247                   ? gen_ashrsi3
16248                   : gen_ashrdi3)  (high[0], high[0], operands[2]));
16249
16250       if (TARGET_CMOVE && scratch)
16251         {
16252           emit_move_insn (scratch, high[0]);
16253           emit_insn ((mode == DImode
16254                       ? gen_ashrsi3
16255                       : gen_ashrdi3) (scratch, scratch,
16256                                       GEN_INT (single_width - 1)));
16257           emit_insn ((mode == DImode
16258                       ? gen_x86_shift_adj_1
16259                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16260                                                  scratch));
16261         }
16262       else
16263         emit_insn ((mode == DImode
16264                     ? gen_x86_shift_adj_3
16265                     : gen_x86_64_shift_adj_3) (low[0], high[0], operands[2]));
16266     }
16267 }
16268
16269 void
16270 ix86_split_lshr (rtx *operands, rtx scratch, enum machine_mode mode)
16271 {
16272   rtx low[2], high[2];
16273   int count;
16274   const int single_width = mode == DImode ? 32 : 64;
16275
16276   if (CONST_INT_P (operands[2]))
16277     {
16278       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16279       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16280
16281       if (count >= single_width)
16282         {
16283           emit_move_insn (low[0], high[1]);
16284           ix86_expand_clear (high[0]);
16285
16286           if (count > single_width)
16287             emit_insn ((mode == DImode
16288                         ? gen_lshrsi3
16289                         : gen_lshrdi3) (low[0], low[0],
16290                                         GEN_INT (count - single_width)));
16291         }
16292       else
16293         {
16294           if (!rtx_equal_p (operands[0], operands[1]))
16295             emit_move_insn (operands[0], operands[1]);
16296           emit_insn ((mode == DImode
16297                       ? gen_x86_shrd
16298                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16299           emit_insn ((mode == DImode
16300                       ? gen_lshrsi3
16301                       : gen_lshrdi3) (high[0], high[0], GEN_INT (count)));
16302         }
16303     }
16304   else
16305     {
16306       if (!rtx_equal_p (operands[0], operands[1]))
16307         emit_move_insn (operands[0], operands[1]);
16308
16309       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16310
16311       emit_insn ((mode == DImode
16312                   ? gen_x86_shrd
16313                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16314       emit_insn ((mode == DImode
16315                   ? gen_lshrsi3
16316                   : gen_lshrdi3) (high[0], high[0], operands[2]));
16317
16318       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
16319       if (TARGET_CMOVE && scratch)
16320         {
16321           ix86_expand_clear (scratch);
16322           emit_insn ((mode == DImode
16323                       ? gen_x86_shift_adj_1
16324                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16325                                                  scratch));
16326         }
16327       else
16328         emit_insn ((mode == DImode
16329                     ? gen_x86_shift_adj_2
16330                     : gen_x86_64_shift_adj_2) (low[0], high[0], operands[2]));
16331     }
16332 }
16333
16334 /* Predict just emitted jump instruction to be taken with probability PROB.  */
16335 static void
16336 predict_jump (int prob)
16337 {
16338   rtx insn = get_last_insn ();
16339   gcc_assert (JUMP_P (insn));
16340   REG_NOTES (insn)
16341     = gen_rtx_EXPR_LIST (REG_BR_PROB,
16342                          GEN_INT (prob),
16343                          REG_NOTES (insn));
16344 }
16345
16346 /* Helper function for the string operations below.  Dest VARIABLE whether
16347    it is aligned to VALUE bytes.  If true, jump to the label.  */
16348 static rtx
16349 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
16350 {
16351   rtx label = gen_label_rtx ();
16352   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
16353   if (GET_MODE (variable) == DImode)
16354     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
16355   else
16356     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
16357   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
16358                            1, label);
16359   if (epilogue)
16360     predict_jump (REG_BR_PROB_BASE * 50 / 100);
16361   else
16362     predict_jump (REG_BR_PROB_BASE * 90 / 100);
16363   return label;
16364 }
16365
16366 /* Adjust COUNTER by the VALUE.  */
16367 static void
16368 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
16369 {
16370   if (GET_MODE (countreg) == DImode)
16371     emit_insn (gen_adddi3 (countreg, countreg, GEN_INT (-value)));
16372   else
16373     emit_insn (gen_addsi3 (countreg, countreg, GEN_INT (-value)));
16374 }
16375
16376 /* Zero extend possibly SImode EXP to Pmode register.  */
16377 rtx
16378 ix86_zero_extend_to_Pmode (rtx exp)
16379 {
16380   rtx r;
16381   if (GET_MODE (exp) == VOIDmode)
16382     return force_reg (Pmode, exp);
16383   if (GET_MODE (exp) == Pmode)
16384     return copy_to_mode_reg (Pmode, exp);
16385   r = gen_reg_rtx (Pmode);
16386   emit_insn (gen_zero_extendsidi2 (r, exp));
16387   return r;
16388 }
16389
16390 /* Divide COUNTREG by SCALE.  */
16391 static rtx
16392 scale_counter (rtx countreg, int scale)
16393 {
16394   rtx sc;
16395   rtx piece_size_mask;
16396
16397   if (scale == 1)
16398     return countreg;
16399   if (CONST_INT_P (countreg))
16400     return GEN_INT (INTVAL (countreg) / scale);
16401   gcc_assert (REG_P (countreg));
16402
16403   piece_size_mask = GEN_INT (scale - 1);
16404   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
16405                             GEN_INT (exact_log2 (scale)),
16406                             NULL, 1, OPTAB_DIRECT);
16407   return sc;
16408 }
16409
16410 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
16411    DImode for constant loop counts.  */
16412
16413 static enum machine_mode
16414 counter_mode (rtx count_exp)
16415 {
16416   if (GET_MODE (count_exp) != VOIDmode)
16417     return GET_MODE (count_exp);
16418   if (GET_CODE (count_exp) != CONST_INT)
16419     return Pmode;
16420   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
16421     return DImode;
16422   return SImode;
16423 }
16424
16425 /* When SRCPTR is non-NULL, output simple loop to move memory
16426    pointer to SRCPTR to DESTPTR via chunks of MODE unrolled UNROLL times,
16427    overall size is COUNT specified in bytes.  When SRCPTR is NULL, output the
16428    equivalent loop to set memory by VALUE (supposed to be in MODE).
16429
16430    The size is rounded down to whole number of chunk size moved at once.
16431    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
16432
16433
16434 static void
16435 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
16436                                rtx destptr, rtx srcptr, rtx value,
16437                                rtx count, enum machine_mode mode, int unroll,
16438                                int expected_size)
16439 {
16440   rtx out_label, top_label, iter, tmp;
16441   enum machine_mode iter_mode = counter_mode (count);
16442   rtx piece_size = GEN_INT (GET_MODE_SIZE (mode) * unroll);
16443   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
16444   rtx size;
16445   rtx x_addr;
16446   rtx y_addr;
16447   int i;
16448
16449   top_label = gen_label_rtx ();
16450   out_label = gen_label_rtx ();
16451   iter = gen_reg_rtx (iter_mode);
16452
16453   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
16454                               NULL, 1, OPTAB_DIRECT);
16455   /* Those two should combine.  */
16456   if (piece_size == const1_rtx)
16457     {
16458       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
16459                                true, out_label);
16460       predict_jump (REG_BR_PROB_BASE * 10 / 100);
16461     }
16462   emit_move_insn (iter, const0_rtx);
16463
16464   emit_label (top_label);
16465
16466   tmp = convert_modes (Pmode, iter_mode, iter, true);
16467   x_addr = gen_rtx_PLUS (Pmode, destptr, tmp);
16468   destmem = change_address (destmem, mode, x_addr);
16469
16470   if (srcmem)
16471     {
16472       y_addr = gen_rtx_PLUS (Pmode, srcptr, copy_rtx (tmp));
16473       srcmem = change_address (srcmem, mode, y_addr);
16474
16475       /* When unrolling for chips that reorder memory reads and writes,
16476          we can save registers by using single temporary.
16477          Also using 4 temporaries is overkill in 32bit mode.  */
16478       if (!TARGET_64BIT && 0)
16479         {
16480           for (i = 0; i < unroll; i++)
16481             {
16482               if (i)
16483                 {
16484                   destmem =
16485                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16486                   srcmem =
16487                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16488                 }
16489               emit_move_insn (destmem, srcmem);
16490             }
16491         }
16492       else
16493         {
16494           rtx tmpreg[4];
16495           gcc_assert (unroll <= 4);
16496           for (i = 0; i < unroll; i++)
16497             {
16498               tmpreg[i] = gen_reg_rtx (mode);
16499               if (i)
16500                 {
16501                   srcmem =
16502                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16503                 }
16504               emit_move_insn (tmpreg[i], srcmem);
16505             }
16506           for (i = 0; i < unroll; i++)
16507             {
16508               if (i)
16509                 {
16510                   destmem =
16511                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16512                 }
16513               emit_move_insn (destmem, tmpreg[i]);
16514             }
16515         }
16516     }
16517   else
16518     for (i = 0; i < unroll; i++)
16519       {
16520         if (i)
16521           destmem =
16522             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16523         emit_move_insn (destmem, value);
16524       }
16525
16526   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
16527                              true, OPTAB_LIB_WIDEN);
16528   if (tmp != iter)
16529     emit_move_insn (iter, tmp);
16530
16531   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
16532                            true, top_label);
16533   if (expected_size != -1)
16534     {
16535       expected_size /= GET_MODE_SIZE (mode) * unroll;
16536       if (expected_size == 0)
16537         predict_jump (0);
16538       else if (expected_size > REG_BR_PROB_BASE)
16539         predict_jump (REG_BR_PROB_BASE - 1);
16540       else
16541         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
16542     }
16543   else
16544     predict_jump (REG_BR_PROB_BASE * 80 / 100);
16545   iter = ix86_zero_extend_to_Pmode (iter);
16546   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
16547                              true, OPTAB_LIB_WIDEN);
16548   if (tmp != destptr)
16549     emit_move_insn (destptr, tmp);
16550   if (srcptr)
16551     {
16552       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
16553                                  true, OPTAB_LIB_WIDEN);
16554       if (tmp != srcptr)
16555         emit_move_insn (srcptr, tmp);
16556     }
16557   emit_label (out_label);
16558 }
16559
16560 /* Output "rep; mov" instruction.
16561    Arguments have same meaning as for previous function */
16562 static void
16563 expand_movmem_via_rep_mov (rtx destmem, rtx srcmem,
16564                            rtx destptr, rtx srcptr,
16565                            rtx count,
16566                            enum machine_mode mode)
16567 {
16568   rtx destexp;
16569   rtx srcexp;
16570   rtx countreg;
16571
16572   /* If the size is known, it is shorter to use rep movs.  */
16573   if (mode == QImode && CONST_INT_P (count)
16574       && !(INTVAL (count) & 3))
16575     mode = SImode;
16576
16577   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16578     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16579   if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
16580     srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
16581   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16582   if (mode != QImode)
16583     {
16584       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16585                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16586       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16587       srcexp = gen_rtx_ASHIFT (Pmode, countreg,
16588                                GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16589       srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
16590     }
16591   else
16592     {
16593       destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16594       srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
16595     }
16596   emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
16597                           destexp, srcexp));
16598 }
16599
16600 /* Output "rep; stos" instruction.
16601    Arguments have same meaning as for previous function */
16602 static void
16603 expand_setmem_via_rep_stos (rtx destmem, rtx destptr, rtx value,
16604                             rtx count,
16605                             enum machine_mode mode)
16606 {
16607   rtx destexp;
16608   rtx countreg;
16609
16610   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16611     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16612   value = force_reg (mode, gen_lowpart (mode, value));
16613   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16614   if (mode != QImode)
16615     {
16616       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16617                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16618       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16619     }
16620   else
16621     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16622   emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
16623 }
16624
16625 static void
16626 emit_strmov (rtx destmem, rtx srcmem,
16627              rtx destptr, rtx srcptr, enum machine_mode mode, int offset)
16628 {
16629   rtx src = adjust_automodify_address_nv (srcmem, mode, srcptr, offset);
16630   rtx dest = adjust_automodify_address_nv (destmem, mode, destptr, offset);
16631   emit_insn (gen_strmov (destptr, dest, srcptr, src));
16632 }
16633
16634 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
16635 static void
16636 expand_movmem_epilogue (rtx destmem, rtx srcmem,
16637                         rtx destptr, rtx srcptr, rtx count, int max_size)
16638 {
16639   rtx src, dest;
16640   if (CONST_INT_P (count))
16641     {
16642       HOST_WIDE_INT countval = INTVAL (count);
16643       int offset = 0;
16644
16645       if ((countval & 0x10) && max_size > 16)
16646         {
16647           if (TARGET_64BIT)
16648             {
16649               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16650               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset + 8);
16651             }
16652           else
16653             gcc_unreachable ();
16654           offset += 16;
16655         }
16656       if ((countval & 0x08) && max_size > 8)
16657         {
16658           if (TARGET_64BIT)
16659             emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16660           else
16661             {
16662               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16663               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset + 4);
16664             }
16665           offset += 8;
16666         }
16667       if ((countval & 0x04) && max_size > 4)
16668         {
16669           emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16670           offset += 4;
16671         }
16672       if ((countval & 0x02) && max_size > 2)
16673         {
16674           emit_strmov (destmem, srcmem, destptr, srcptr, HImode, offset);
16675           offset += 2;
16676         }
16677       if ((countval & 0x01) && max_size > 1)
16678         {
16679           emit_strmov (destmem, srcmem, destptr, srcptr, QImode, offset);
16680           offset += 1;
16681         }
16682       return;
16683     }
16684   if (max_size > 8)
16685     {
16686       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
16687                                     count, 1, OPTAB_DIRECT);
16688       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
16689                                      count, QImode, 1, 4);
16690       return;
16691     }
16692
16693   /* When there are stringops, we can cheaply increase dest and src pointers.
16694      Otherwise we save code size by maintaining offset (zero is readily
16695      available from preceding rep operation) and using x86 addressing modes.
16696    */
16697   if (TARGET_SINGLE_STRINGOP)
16698     {
16699       if (max_size > 4)
16700         {
16701           rtx label = ix86_expand_aligntest (count, 4, true);
16702           src = change_address (srcmem, SImode, srcptr);
16703           dest = change_address (destmem, SImode, destptr);
16704           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16705           emit_label (label);
16706           LABEL_NUSES (label) = 1;
16707         }
16708       if (max_size > 2)
16709         {
16710           rtx label = ix86_expand_aligntest (count, 2, true);
16711           src = change_address (srcmem, HImode, srcptr);
16712           dest = change_address (destmem, HImode, destptr);
16713           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16714           emit_label (label);
16715           LABEL_NUSES (label) = 1;
16716         }
16717       if (max_size > 1)
16718         {
16719           rtx label = ix86_expand_aligntest (count, 1, true);
16720           src = change_address (srcmem, QImode, srcptr);
16721           dest = change_address (destmem, QImode, destptr);
16722           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16723           emit_label (label);
16724           LABEL_NUSES (label) = 1;
16725         }
16726     }
16727   else
16728     {
16729       rtx offset = force_reg (Pmode, const0_rtx);
16730       rtx tmp;
16731
16732       if (max_size > 4)
16733         {
16734           rtx label = ix86_expand_aligntest (count, 4, true);
16735           src = change_address (srcmem, SImode, srcptr);
16736           dest = change_address (destmem, SImode, destptr);
16737           emit_move_insn (dest, src);
16738           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
16739                                      true, OPTAB_LIB_WIDEN);
16740           if (tmp != offset)
16741             emit_move_insn (offset, tmp);
16742           emit_label (label);
16743           LABEL_NUSES (label) = 1;
16744         }
16745       if (max_size > 2)
16746         {
16747           rtx label = ix86_expand_aligntest (count, 2, true);
16748           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
16749           src = change_address (srcmem, HImode, tmp);
16750           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
16751           dest = change_address (destmem, HImode, tmp);
16752           emit_move_insn (dest, src);
16753           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
16754                                      true, OPTAB_LIB_WIDEN);
16755           if (tmp != offset)
16756             emit_move_insn (offset, tmp);
16757           emit_label (label);
16758           LABEL_NUSES (label) = 1;
16759         }
16760       if (max_size > 1)
16761         {
16762           rtx label = ix86_expand_aligntest (count, 1, true);
16763           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
16764           src = change_address (srcmem, QImode, tmp);
16765           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
16766           dest = change_address (destmem, QImode, tmp);
16767           emit_move_insn (dest, src);
16768           emit_label (label);
16769           LABEL_NUSES (label) = 1;
16770         }
16771     }
16772 }
16773
16774 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
16775 static void
16776 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
16777                                  rtx count, int max_size)
16778 {
16779   count =
16780     expand_simple_binop (counter_mode (count), AND, count,
16781                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
16782   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
16783                                  gen_lowpart (QImode, value), count, QImode,
16784                                  1, max_size / 2);
16785 }
16786
16787 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
16788 static void
16789 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx count, int max_size)
16790 {
16791   rtx dest;
16792
16793   if (CONST_INT_P (count))
16794     {
16795       HOST_WIDE_INT countval = INTVAL (count);
16796       int offset = 0;
16797
16798       if ((countval & 0x10) && max_size > 16)
16799         {
16800           if (TARGET_64BIT)
16801             {
16802               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
16803               emit_insn (gen_strset (destptr, dest, value));
16804               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset + 8);
16805               emit_insn (gen_strset (destptr, dest, value));
16806             }
16807           else
16808             gcc_unreachable ();
16809           offset += 16;
16810         }
16811       if ((countval & 0x08) && max_size > 8)
16812         {
16813           if (TARGET_64BIT)
16814             {
16815               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
16816               emit_insn (gen_strset (destptr, dest, value));
16817             }
16818           else
16819             {
16820               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
16821               emit_insn (gen_strset (destptr, dest, value));
16822               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset + 4);
16823               emit_insn (gen_strset (destptr, dest, value));
16824             }
16825           offset += 8;
16826         }
16827       if ((countval & 0x04) && max_size > 4)
16828         {
16829           dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
16830           emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
16831           offset += 4;
16832         }
16833       if ((countval & 0x02) && max_size > 2)
16834         {
16835           dest = adjust_automodify_address_nv (destmem, HImode, destptr, offset);
16836           emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
16837           offset += 2;
16838         }
16839       if ((countval & 0x01) && max_size > 1)
16840         {
16841           dest = adjust_automodify_address_nv (destmem, QImode, destptr, offset);
16842           emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
16843           offset += 1;
16844         }
16845       return;
16846     }
16847   if (max_size > 32)
16848     {
16849       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
16850       return;
16851     }
16852   if (max_size > 16)
16853     {
16854       rtx label = ix86_expand_aligntest (count, 16, true);
16855       if (TARGET_64BIT)
16856         {
16857           dest = change_address (destmem, DImode, destptr);
16858           emit_insn (gen_strset (destptr, dest, value));
16859           emit_insn (gen_strset (destptr, dest, value));
16860         }
16861       else
16862         {
16863           dest = change_address (destmem, SImode, destptr);
16864           emit_insn (gen_strset (destptr, dest, value));
16865           emit_insn (gen_strset (destptr, dest, value));
16866           emit_insn (gen_strset (destptr, dest, value));
16867           emit_insn (gen_strset (destptr, dest, value));
16868         }
16869       emit_label (label);
16870       LABEL_NUSES (label) = 1;
16871     }
16872   if (max_size > 8)
16873     {
16874       rtx label = ix86_expand_aligntest (count, 8, true);
16875       if (TARGET_64BIT)
16876         {
16877           dest = change_address (destmem, DImode, destptr);
16878           emit_insn (gen_strset (destptr, dest, value));
16879         }
16880       else
16881         {
16882           dest = change_address (destmem, SImode, destptr);
16883           emit_insn (gen_strset (destptr, dest, value));
16884           emit_insn (gen_strset (destptr, dest, value));
16885         }
16886       emit_label (label);
16887       LABEL_NUSES (label) = 1;
16888     }
16889   if (max_size > 4)
16890     {
16891       rtx label = ix86_expand_aligntest (count, 4, true);
16892       dest = change_address (destmem, SImode, destptr);
16893       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
16894       emit_label (label);
16895       LABEL_NUSES (label) = 1;
16896     }
16897   if (max_size > 2)
16898     {
16899       rtx label = ix86_expand_aligntest (count, 2, true);
16900       dest = change_address (destmem, HImode, destptr);
16901       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
16902       emit_label (label);
16903       LABEL_NUSES (label) = 1;
16904     }
16905   if (max_size > 1)
16906     {
16907       rtx label = ix86_expand_aligntest (count, 1, true);
16908       dest = change_address (destmem, QImode, destptr);
16909       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
16910       emit_label (label);
16911       LABEL_NUSES (label) = 1;
16912     }
16913 }
16914
16915 /* Copy enough from DEST to SRC to align DEST known to by aligned by ALIGN to
16916    DESIRED_ALIGNMENT.  */
16917 static void
16918 expand_movmem_prologue (rtx destmem, rtx srcmem,
16919                         rtx destptr, rtx srcptr, rtx count,
16920                         int align, int desired_alignment)
16921 {
16922   if (align <= 1 && desired_alignment > 1)
16923     {
16924       rtx label = ix86_expand_aligntest (destptr, 1, false);
16925       srcmem = change_address (srcmem, QImode, srcptr);
16926       destmem = change_address (destmem, QImode, destptr);
16927       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16928       ix86_adjust_counter (count, 1);
16929       emit_label (label);
16930       LABEL_NUSES (label) = 1;
16931     }
16932   if (align <= 2 && desired_alignment > 2)
16933     {
16934       rtx label = ix86_expand_aligntest (destptr, 2, false);
16935       srcmem = change_address (srcmem, HImode, srcptr);
16936       destmem = change_address (destmem, HImode, destptr);
16937       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16938       ix86_adjust_counter (count, 2);
16939       emit_label (label);
16940       LABEL_NUSES (label) = 1;
16941     }
16942   if (align <= 4 && desired_alignment > 4)
16943     {
16944       rtx label = ix86_expand_aligntest (destptr, 4, false);
16945       srcmem = change_address (srcmem, SImode, srcptr);
16946       destmem = change_address (destmem, SImode, destptr);
16947       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16948       ix86_adjust_counter (count, 4);
16949       emit_label (label);
16950       LABEL_NUSES (label) = 1;
16951     }
16952   gcc_assert (desired_alignment <= 8);
16953 }
16954
16955 /* Set enough from DEST to align DEST known to by aligned by ALIGN to
16956    DESIRED_ALIGNMENT.  */
16957 static void
16958 expand_setmem_prologue (rtx destmem, rtx destptr, rtx value, rtx count,
16959                         int align, int desired_alignment)
16960 {
16961   if (align <= 1 && desired_alignment > 1)
16962     {
16963       rtx label = ix86_expand_aligntest (destptr, 1, false);
16964       destmem = change_address (destmem, QImode, destptr);
16965       emit_insn (gen_strset (destptr, destmem, gen_lowpart (QImode, value)));
16966       ix86_adjust_counter (count, 1);
16967       emit_label (label);
16968       LABEL_NUSES (label) = 1;
16969     }
16970   if (align <= 2 && desired_alignment > 2)
16971     {
16972       rtx label = ix86_expand_aligntest (destptr, 2, false);
16973       destmem = change_address (destmem, HImode, destptr);
16974       emit_insn (gen_strset (destptr, destmem, gen_lowpart (HImode, value)));
16975       ix86_adjust_counter (count, 2);
16976       emit_label (label);
16977       LABEL_NUSES (label) = 1;
16978     }
16979   if (align <= 4 && desired_alignment > 4)
16980     {
16981       rtx label = ix86_expand_aligntest (destptr, 4, false);
16982       destmem = change_address (destmem, SImode, destptr);
16983       emit_insn (gen_strset (destptr, destmem, gen_lowpart (SImode, value)));
16984       ix86_adjust_counter (count, 4);
16985       emit_label (label);
16986       LABEL_NUSES (label) = 1;
16987     }
16988   gcc_assert (desired_alignment <= 8);
16989 }
16990
16991 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
16992 static enum stringop_alg
16993 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, bool memset,
16994             int *dynamic_check)
16995 {
16996   const struct stringop_algs * algs;
16997   bool optimize_for_speed;
16998   /* Algorithms using the rep prefix want at least edi and ecx;
16999      additionally, memset wants eax and memcpy wants esi.  Don't
17000      consider such algorithms if the user has appropriated those
17001      registers for their own purposes.  */
17002   bool rep_prefix_usable = !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
17003                              || (memset
17004                                  ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
17005
17006 #define ALG_USABLE_P(alg) (rep_prefix_usable                    \
17007                            || (alg != rep_prefix_1_byte         \
17008                                && alg != rep_prefix_4_byte      \
17009                                && alg != rep_prefix_8_byte))
17010   const struct processor_costs *cost;
17011   
17012   /* Even if the string operation call is cold, we still might spend a lot
17013      of time processing large blocks.  */
17014   if (optimize_function_for_size_p (cfun)
17015       || (optimize_insn_for_size_p ()
17016           && expected_size != -1 && expected_size < 256))
17017     optimize_for_speed = false;
17018   else
17019     optimize_for_speed = true;
17020
17021   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
17022
17023   *dynamic_check = -1;
17024   if (memset)
17025     algs = &cost->memset[TARGET_64BIT != 0];
17026   else
17027     algs = &cost->memcpy[TARGET_64BIT != 0];
17028   if (stringop_alg != no_stringop && ALG_USABLE_P (stringop_alg))
17029     return stringop_alg;
17030   /* rep; movq or rep; movl is the smallest variant.  */
17031   else if (!optimize_for_speed)
17032     {
17033       if (!count || (count & 3))
17034         return rep_prefix_usable ? rep_prefix_1_byte : loop_1_byte;
17035       else
17036         return rep_prefix_usable ? rep_prefix_4_byte : loop;
17037     }
17038   /* Very tiny blocks are best handled via the loop, REP is expensive to setup.
17039    */
17040   else if (expected_size != -1 && expected_size < 4)
17041     return loop_1_byte;
17042   else if (expected_size != -1)
17043     {
17044       unsigned int i;
17045       enum stringop_alg alg = libcall;
17046       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17047         {
17048           /* We get here if the algorithms that were not libcall-based
17049              were rep-prefix based and we are unable to use rep prefixes
17050              based on global register usage.  Break out of the loop and
17051              use the heuristic below.  */
17052           if (algs->size[i].max == 0)
17053             break;
17054           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
17055             {
17056               enum stringop_alg candidate = algs->size[i].alg;
17057
17058               if (candidate != libcall && ALG_USABLE_P (candidate))
17059                 alg = candidate;
17060               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
17061                  last non-libcall inline algorithm.  */
17062               if (TARGET_INLINE_ALL_STRINGOPS)
17063                 {
17064                   /* When the current size is best to be copied by a libcall,
17065                      but we are still forced to inline, run the heuristic below
17066                      that will pick code for medium sized blocks.  */
17067                   if (alg != libcall)
17068                     return alg;
17069                   break;
17070                 }
17071               else if (ALG_USABLE_P (candidate))
17072                 return candidate;
17073             }
17074         }
17075       gcc_assert (TARGET_INLINE_ALL_STRINGOPS || !rep_prefix_usable);
17076     }
17077   /* When asked to inline the call anyway, try to pick meaningful choice.
17078      We look for maximal size of block that is faster to copy by hand and
17079      take blocks of at most of that size guessing that average size will
17080      be roughly half of the block.
17081
17082      If this turns out to be bad, we might simply specify the preferred
17083      choice in ix86_costs.  */
17084   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17085       && (algs->unknown_size == libcall || !ALG_USABLE_P (algs->unknown_size)))
17086     {
17087       int max = -1;
17088       enum stringop_alg alg;
17089       int i;
17090       bool any_alg_usable_p = true;
17091
17092       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17093         {
17094           enum stringop_alg candidate = algs->size[i].alg;
17095           any_alg_usable_p = any_alg_usable_p && ALG_USABLE_P (candidate);
17096
17097           if (candidate != libcall && candidate
17098               && ALG_USABLE_P (candidate))
17099               max = algs->size[i].max;
17100         }
17101       /* If there aren't any usable algorithms, then recursing on
17102          smaller sizes isn't going to find anything.  Just return the
17103          simple byte-at-a-time copy loop.  */
17104       if (!any_alg_usable_p)
17105         {
17106           /* Pick something reasonable.  */
17107           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17108             *dynamic_check = 128;
17109           return loop_1_byte;
17110         }
17111       if (max == -1)
17112         max = 4096;
17113       alg = decide_alg (count, max / 2, memset, dynamic_check);
17114       gcc_assert (*dynamic_check == -1);
17115       gcc_assert (alg != libcall);
17116       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17117         *dynamic_check = max;
17118       return alg;
17119     }
17120   return ALG_USABLE_P (algs->unknown_size) ? algs->unknown_size : libcall;
17121 #undef ALG_USABLE_P
17122 }
17123
17124 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
17125    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
17126 static int
17127 decide_alignment (int align,
17128                   enum stringop_alg alg,
17129                   int expected_size)
17130 {
17131   int desired_align = 0;
17132   switch (alg)
17133     {
17134       case no_stringop:
17135         gcc_unreachable ();
17136       case loop:
17137       case unrolled_loop:
17138         desired_align = GET_MODE_SIZE (Pmode);
17139         break;
17140       case rep_prefix_8_byte:
17141         desired_align = 8;
17142         break;
17143       case rep_prefix_4_byte:
17144         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17145            copying whole cacheline at once.  */
17146         if (TARGET_PENTIUMPRO)
17147           desired_align = 8;
17148         else
17149           desired_align = 4;
17150         break;
17151       case rep_prefix_1_byte:
17152         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17153            copying whole cacheline at once.  */
17154         if (TARGET_PENTIUMPRO)
17155           desired_align = 8;
17156         else
17157           desired_align = 1;
17158         break;
17159       case loop_1_byte:
17160         desired_align = 1;
17161         break;
17162       case libcall:
17163         return 0;
17164     }
17165
17166   if (optimize_size)
17167     desired_align = 1;
17168   if (desired_align < align)
17169     desired_align = align;
17170   if (expected_size != -1 && expected_size < 4)
17171     desired_align = align;
17172   return desired_align;
17173 }
17174
17175 /* Return the smallest power of 2 greater than VAL.  */
17176 static int
17177 smallest_pow2_greater_than (int val)
17178 {
17179   int ret = 1;
17180   while (ret <= val)
17181     ret <<= 1;
17182   return ret;
17183 }
17184
17185 /* Expand string move (memcpy) operation.  Use i386 string operations when
17186    profitable.  expand_setmem contains similar code.  The code depends upon
17187    architecture, block size and alignment, but always has the same
17188    overall structure:
17189
17190    1) Prologue guard: Conditional that jumps up to epilogues for small
17191       blocks that can be handled by epilogue alone.  This is faster but
17192       also needed for correctness, since prologue assume the block is larger
17193       than the desired alignment.
17194
17195       Optional dynamic check for size and libcall for large
17196       blocks is emitted here too, with -minline-stringops-dynamically.
17197
17198    2) Prologue: copy first few bytes in order to get destination aligned
17199       to DESIRED_ALIGN.  It is emitted only when ALIGN is less than
17200       DESIRED_ALIGN and and up to DESIRED_ALIGN - ALIGN bytes can be copied.
17201       We emit either a jump tree on power of two sized blocks, or a byte loop.
17202
17203    3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
17204       with specified algorithm.
17205
17206    4) Epilogue: code copying tail of the block that is too small to be
17207       handled by main body (or up to size guarded by prologue guard).  */
17208
17209 int
17210 ix86_expand_movmem (rtx dst, rtx src, rtx count_exp, rtx align_exp,
17211                     rtx expected_align_exp, rtx expected_size_exp)
17212 {
17213   rtx destreg;
17214   rtx srcreg;
17215   rtx label = NULL;
17216   rtx tmp;
17217   rtx jump_around_label = NULL;
17218   HOST_WIDE_INT align = 1;
17219   unsigned HOST_WIDE_INT count = 0;
17220   HOST_WIDE_INT expected_size = -1;
17221   int size_needed = 0, epilogue_size_needed;
17222   int desired_align = 0;
17223   enum stringop_alg alg;
17224   int dynamic_check;
17225   bool need_zero_guard = false;
17226
17227   if (CONST_INT_P (align_exp))
17228     align = INTVAL (align_exp);
17229   /* i386 can do misaligned access on reasonably increased cost.  */
17230   if (CONST_INT_P (expected_align_exp)
17231       && INTVAL (expected_align_exp) > align)
17232     align = INTVAL (expected_align_exp);
17233   if (CONST_INT_P (count_exp))
17234     count = expected_size = INTVAL (count_exp);
17235   if (CONST_INT_P (expected_size_exp) && count == 0)
17236     expected_size = INTVAL (expected_size_exp);
17237
17238   /* Make sure we don't need to care about overflow later on.  */
17239   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17240     return 0;
17241
17242   /* Step 0: Decide on preferred algorithm, desired alignment and
17243      size of chunks to be copied by main loop.  */
17244
17245   alg = decide_alg (count, expected_size, false, &dynamic_check);
17246   desired_align = decide_alignment (align, alg, expected_size);
17247
17248   if (!TARGET_ALIGN_STRINGOPS)
17249     align = desired_align;
17250
17251   if (alg == libcall)
17252     return 0;
17253   gcc_assert (alg != no_stringop);
17254   if (!count)
17255     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
17256   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17257   srcreg = copy_to_mode_reg (Pmode, XEXP (src, 0));
17258   switch (alg)
17259     {
17260     case libcall:
17261     case no_stringop:
17262       gcc_unreachable ();
17263     case loop:
17264       need_zero_guard = true;
17265       size_needed = GET_MODE_SIZE (Pmode);
17266       break;
17267     case unrolled_loop:
17268       need_zero_guard = true;
17269       size_needed = GET_MODE_SIZE (Pmode) * (TARGET_64BIT ? 4 : 2);
17270       break;
17271     case rep_prefix_8_byte:
17272       size_needed = 8;
17273       break;
17274     case rep_prefix_4_byte:
17275       size_needed = 4;
17276       break;
17277     case rep_prefix_1_byte:
17278       size_needed = 1;
17279       break;
17280     case loop_1_byte:
17281       need_zero_guard = true;
17282       size_needed = 1;
17283       break;
17284     }
17285
17286   epilogue_size_needed = size_needed;
17287
17288   /* Step 1: Prologue guard.  */
17289
17290   /* Alignment code needs count to be in register.  */
17291   if (CONST_INT_P (count_exp) && desired_align > align)
17292     count_exp = force_reg (counter_mode (count_exp), count_exp);
17293   gcc_assert (desired_align >= 1 && align >= 1);
17294
17295   /* Ensure that alignment prologue won't copy past end of block.  */
17296   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
17297     {
17298       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
17299       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
17300          Make sure it is power of 2.  */
17301       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
17302
17303       if (CONST_INT_P (count_exp))
17304         {
17305           if (UINTVAL (count_exp) < (unsigned HOST_WIDE_INT)epilogue_size_needed)
17306             goto epilogue;
17307         }
17308       else
17309         {
17310           label = gen_label_rtx ();
17311           emit_cmp_and_jump_insns (count_exp,
17312                                    GEN_INT (epilogue_size_needed),
17313                                    LTU, 0, counter_mode (count_exp), 1, label);
17314           if (expected_size == -1 || expected_size < epilogue_size_needed)
17315             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17316           else
17317             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17318         }
17319     }
17320
17321   /* Emit code to decide on runtime whether library call or inline should be
17322      used.  */
17323   if (dynamic_check != -1)
17324     {
17325       if (CONST_INT_P (count_exp))
17326         {
17327           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
17328             {
17329               emit_block_move_via_libcall (dst, src, count_exp, false);
17330               count_exp = const0_rtx;
17331               goto epilogue;
17332             }
17333         }
17334       else
17335         {
17336           rtx hot_label = gen_label_rtx ();
17337           jump_around_label = gen_label_rtx ();
17338           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
17339                                    LEU, 0, GET_MODE (count_exp), 1, hot_label);
17340           predict_jump (REG_BR_PROB_BASE * 90 / 100);
17341           emit_block_move_via_libcall (dst, src, count_exp, false);
17342           emit_jump (jump_around_label);
17343           emit_label (hot_label);
17344         }
17345     }
17346
17347   /* Step 2: Alignment prologue.  */
17348
17349   if (desired_align > align)
17350     {
17351       /* Except for the first move in epilogue, we no longer know
17352          constant offset in aliasing info.  It don't seems to worth
17353          the pain to maintain it for the first move, so throw away
17354          the info early.  */
17355       src = change_address (src, BLKmode, srcreg);
17356       dst = change_address (dst, BLKmode, destreg);
17357       expand_movmem_prologue (dst, src, destreg, srcreg, count_exp, align,
17358                               desired_align);
17359       if (need_zero_guard && !count)
17360         {
17361           /* It is possible that we copied enough so the main loop will not
17362              execute.  */
17363           emit_cmp_and_jump_insns (count_exp,
17364                                    GEN_INT (size_needed),
17365                                    LTU, 0, counter_mode (count_exp), 1, label);
17366           if (expected_size == -1
17367               || expected_size < (desired_align - align) / 2 + size_needed)
17368             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17369           else
17370             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17371         }
17372     }
17373   if (label && size_needed == 1)
17374     {
17375       emit_label (label);
17376       LABEL_NUSES (label) = 1;
17377       label = NULL;
17378     }
17379
17380   /* Step 3: Main loop.  */
17381
17382   switch (alg)
17383     {
17384     case libcall:
17385     case no_stringop:
17386       gcc_unreachable ();
17387     case loop_1_byte:
17388       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17389                                      count_exp, QImode, 1, expected_size);
17390       break;
17391     case loop:
17392       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17393                                      count_exp, Pmode, 1, expected_size);
17394       break;
17395     case unrolled_loop:
17396       /* Unroll only by factor of 2 in 32bit mode, since we don't have enough
17397          registers for 4 temporaries anyway.  */
17398       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17399                                      count_exp, Pmode, TARGET_64BIT ? 4 : 2,
17400                                      expected_size);
17401       break;
17402     case rep_prefix_8_byte:
17403       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17404                                  DImode);
17405       break;
17406     case rep_prefix_4_byte:
17407       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17408                                  SImode);
17409       break;
17410     case rep_prefix_1_byte:
17411       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17412                                  QImode);
17413       break;
17414     }
17415   /* Adjust properly the offset of src and dest memory for aliasing.  */
17416   if (CONST_INT_P (count_exp))
17417     {
17418       src = adjust_automodify_address_nv (src, BLKmode, srcreg,
17419                                           (count / size_needed) * size_needed);
17420       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
17421                                           (count / size_needed) * size_needed);
17422     }
17423   else
17424     {
17425       src = change_address (src, BLKmode, srcreg);
17426       dst = change_address (dst, BLKmode, destreg);
17427     }
17428
17429   /* Step 4: Epilogue to copy the remaining bytes.  */
17430  epilogue:
17431   if (label)
17432     {
17433       /* When the main loop is done, COUNT_EXP might hold original count,
17434          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
17435          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
17436          bytes. Compensate if needed.  */
17437
17438       if (size_needed < epilogue_size_needed)
17439         {
17440           tmp =
17441             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
17442                                  GEN_INT (size_needed - 1), count_exp, 1,
17443                                  OPTAB_DIRECT);
17444           if (tmp != count_exp)
17445             emit_move_insn (count_exp, tmp);
17446         }
17447       emit_label (label);
17448       LABEL_NUSES (label) = 1;
17449     }
17450
17451   if (count_exp != const0_rtx && epilogue_size_needed > 1)
17452     expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
17453                             epilogue_size_needed);
17454   if (jump_around_label)
17455     emit_label (jump_around_label);
17456   return 1;
17457 }
17458
17459 /* Helper function for memcpy.  For QImode value 0xXY produce
17460    0xXYXYXYXY of wide specified by MODE.  This is essentially
17461    a * 0x10101010, but we can do slightly better than
17462    synth_mult by unwinding the sequence by hand on CPUs with
17463    slow multiply.  */
17464 static rtx
17465 promote_duplicated_reg (enum machine_mode mode, rtx val)
17466 {
17467   enum machine_mode valmode = GET_MODE (val);
17468   rtx tmp;
17469   int nops = mode == DImode ? 3 : 2;
17470
17471   gcc_assert (mode == SImode || mode == DImode);
17472   if (val == const0_rtx)
17473     return copy_to_mode_reg (mode, const0_rtx);
17474   if (CONST_INT_P (val))
17475     {
17476       HOST_WIDE_INT v = INTVAL (val) & 255;
17477
17478       v |= v << 8;
17479       v |= v << 16;
17480       if (mode == DImode)
17481         v |= (v << 16) << 16;
17482       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
17483     }
17484
17485   if (valmode == VOIDmode)
17486     valmode = QImode;
17487   if (valmode != QImode)
17488     val = gen_lowpart (QImode, val);
17489   if (mode == QImode)
17490     return val;
17491   if (!TARGET_PARTIAL_REG_STALL)
17492     nops--;
17493   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
17494       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
17495       <= (ix86_cost->shift_const + ix86_cost->add) * nops
17496           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
17497     {
17498       rtx reg = convert_modes (mode, QImode, val, true);
17499       tmp = promote_duplicated_reg (mode, const1_rtx);
17500       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
17501                                   OPTAB_DIRECT);
17502     }
17503   else
17504     {
17505       rtx reg = convert_modes (mode, QImode, val, true);
17506
17507       if (!TARGET_PARTIAL_REG_STALL)
17508         if (mode == SImode)
17509           emit_insn (gen_movsi_insv_1 (reg, reg));
17510         else
17511           emit_insn (gen_movdi_insv_1_rex64 (reg, reg));
17512       else
17513         {
17514           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
17515                                      NULL, 1, OPTAB_DIRECT);
17516           reg =
17517             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17518         }
17519       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
17520                                  NULL, 1, OPTAB_DIRECT);
17521       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17522       if (mode == SImode)
17523         return reg;
17524       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
17525                                  NULL, 1, OPTAB_DIRECT);
17526       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17527       return reg;
17528     }
17529 }
17530
17531 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
17532    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
17533    alignment from ALIGN to DESIRED_ALIGN.  */
17534 static rtx
17535 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align, int align)
17536 {
17537   rtx promoted_val;
17538
17539   if (TARGET_64BIT
17540       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
17541     promoted_val = promote_duplicated_reg (DImode, val);
17542   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
17543     promoted_val = promote_duplicated_reg (SImode, val);
17544   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
17545     promoted_val = promote_duplicated_reg (HImode, val);
17546   else
17547     promoted_val = val;
17548
17549   return promoted_val;
17550 }
17551
17552 /* Expand string clear operation (bzero).  Use i386 string operations when
17553    profitable.  See expand_movmem comment for explanation of individual
17554    steps performed.  */
17555 int
17556 ix86_expand_setmem (rtx dst, rtx count_exp, rtx val_exp, rtx align_exp,
17557                     rtx expected_align_exp, rtx expected_size_exp)
17558 {
17559   rtx destreg;
17560   rtx label = NULL;
17561   rtx tmp;
17562   rtx jump_around_label = NULL;
17563   HOST_WIDE_INT align = 1;
17564   unsigned HOST_WIDE_INT count = 0;
17565   HOST_WIDE_INT expected_size = -1;
17566   int size_needed = 0, epilogue_size_needed;
17567   int desired_align = 0;
17568   enum stringop_alg alg;
17569   rtx promoted_val = NULL;
17570   bool force_loopy_epilogue = false;
17571   int dynamic_check;
17572   bool need_zero_guard = false;
17573
17574   if (CONST_INT_P (align_exp))
17575     align = INTVAL (align_exp);
17576   /* i386 can do misaligned access on reasonably increased cost.  */
17577   if (CONST_INT_P (expected_align_exp)
17578       && INTVAL (expected_align_exp) > align)
17579     align = INTVAL (expected_align_exp);
17580   if (CONST_INT_P (count_exp))
17581     count = expected_size = INTVAL (count_exp);
17582   if (CONST_INT_P (expected_size_exp) && count == 0)
17583     expected_size = INTVAL (expected_size_exp);
17584
17585   /* Make sure we don't need to care about overflow later on.  */
17586   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17587     return 0;
17588
17589   /* Step 0: Decide on preferred algorithm, desired alignment and
17590      size of chunks to be copied by main loop.  */
17591
17592   alg = decide_alg (count, expected_size, true, &dynamic_check);
17593   desired_align = decide_alignment (align, alg, expected_size);
17594
17595   if (!TARGET_ALIGN_STRINGOPS)
17596     align = desired_align;
17597
17598   if (alg == libcall)
17599     return 0;
17600   gcc_assert (alg != no_stringop);
17601   if (!count)
17602     count_exp = copy_to_mode_reg (counter_mode (count_exp), count_exp);
17603   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17604   switch (alg)
17605     {
17606     case libcall:
17607     case no_stringop:
17608       gcc_unreachable ();
17609     case loop:
17610       need_zero_guard = true;
17611       size_needed = GET_MODE_SIZE (Pmode);
17612       break;
17613     case unrolled_loop:
17614       need_zero_guard = true;
17615       size_needed = GET_MODE_SIZE (Pmode) * 4;
17616       break;
17617     case rep_prefix_8_byte:
17618       size_needed = 8;
17619       break;
17620     case rep_prefix_4_byte:
17621       size_needed = 4;
17622       break;
17623     case rep_prefix_1_byte:
17624       size_needed = 1;
17625       break;
17626     case loop_1_byte:
17627       need_zero_guard = true;
17628       size_needed = 1;
17629       break;
17630     }
17631   epilogue_size_needed = size_needed;
17632
17633   /* Step 1: Prologue guard.  */
17634
17635   /* Alignment code needs count to be in register.  */
17636   if (CONST_INT_P (count_exp) && desired_align > align)
17637     {
17638       enum machine_mode mode = SImode;
17639       if (TARGET_64BIT && (count & ~0xffffffff))
17640         mode = DImode;
17641       count_exp = force_reg (mode, count_exp);
17642     }
17643   /* Do the cheap promotion to allow better CSE across the
17644      main loop and epilogue (ie one load of the big constant in the
17645      front of all code.  */
17646   if (CONST_INT_P (val_exp))
17647     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
17648                                                    desired_align, align);
17649   /* Ensure that alignment prologue won't copy past end of block.  */
17650   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
17651     {
17652       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
17653       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
17654          Make sure it is power of 2.  */
17655       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
17656
17657       /* To improve performance of small blocks, we jump around the VAL
17658          promoting mode.  This mean that if the promoted VAL is not constant,
17659          we might not use it in the epilogue and have to use byte
17660          loop variant.  */
17661       if (epilogue_size_needed > 2 && !promoted_val)
17662         force_loopy_epilogue = true;
17663       label = gen_label_rtx ();
17664       emit_cmp_and_jump_insns (count_exp,
17665                                GEN_INT (epilogue_size_needed),
17666                                LTU, 0, counter_mode (count_exp), 1, label);
17667       if (GET_CODE (count_exp) == CONST_INT)
17668         ;
17669       else if (expected_size == -1 || expected_size <= epilogue_size_needed)
17670         predict_jump (REG_BR_PROB_BASE * 60 / 100);
17671       else
17672         predict_jump (REG_BR_PROB_BASE * 20 / 100);
17673     }
17674   if (dynamic_check != -1)
17675     {
17676       rtx hot_label = gen_label_rtx ();
17677       jump_around_label = gen_label_rtx ();
17678       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
17679                                LEU, 0, counter_mode (count_exp), 1, hot_label);
17680       predict_jump (REG_BR_PROB_BASE * 90 / 100);
17681       set_storage_via_libcall (dst, count_exp, val_exp, false);
17682       emit_jump (jump_around_label);
17683       emit_label (hot_label);
17684     }
17685
17686   /* Step 2: Alignment prologue.  */
17687
17688   /* Do the expensive promotion once we branched off the small blocks.  */
17689   if (!promoted_val)
17690     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
17691                                                    desired_align, align);
17692   gcc_assert (desired_align >= 1 && align >= 1);
17693
17694   if (desired_align > align)
17695     {
17696       /* Except for the first move in epilogue, we no longer know
17697          constant offset in aliasing info.  It don't seems to worth
17698          the pain to maintain it for the first move, so throw away
17699          the info early.  */
17700       dst = change_address (dst, BLKmode, destreg);
17701       expand_setmem_prologue (dst, destreg, promoted_val, count_exp, align,
17702                               desired_align);
17703       if (need_zero_guard && !count)
17704         {
17705           /* It is possible that we copied enough so the main loop will not
17706              execute.  */
17707           emit_cmp_and_jump_insns (count_exp,
17708                                    GEN_INT (size_needed),
17709                                    LTU, 0, counter_mode (count_exp), 1, label);
17710           if (expected_size == -1
17711               || expected_size < (desired_align - align) / 2 + size_needed)
17712             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17713           else
17714             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17715         }
17716     }
17717   if (label && size_needed == 1)
17718     {
17719       emit_label (label);
17720       LABEL_NUSES (label) = 1;
17721       label = NULL;
17722     }
17723
17724   /* Step 3: Main loop.  */
17725
17726   switch (alg)
17727     {
17728     case libcall:
17729     case no_stringop:
17730       gcc_unreachable ();
17731     case loop_1_byte:
17732       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17733                                      count_exp, QImode, 1, expected_size);
17734       break;
17735     case loop:
17736       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17737                                      count_exp, Pmode, 1, expected_size);
17738       break;
17739     case unrolled_loop:
17740       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17741                                      count_exp, Pmode, 4, expected_size);
17742       break;
17743     case rep_prefix_8_byte:
17744       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17745                                   DImode);
17746       break;
17747     case rep_prefix_4_byte:
17748       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17749                                   SImode);
17750       break;
17751     case rep_prefix_1_byte:
17752       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17753                                   QImode);
17754       break;
17755     }
17756   /* Adjust properly the offset of src and dest memory for aliasing.  */
17757   if (CONST_INT_P (count_exp))
17758     dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
17759                                         (count / size_needed) * size_needed);
17760   else
17761     dst = change_address (dst, BLKmode, destreg);
17762
17763   /* Step 4: Epilogue to copy the remaining bytes.  */
17764
17765   if (label)
17766     {
17767       /* When the main loop is done, COUNT_EXP might hold original count,
17768          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
17769          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
17770          bytes. Compensate if needed.  */
17771
17772       if (size_needed < desired_align - align)
17773         {
17774           tmp =
17775             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
17776                                  GEN_INT (size_needed - 1), count_exp, 1,
17777                                  OPTAB_DIRECT);
17778           size_needed = desired_align - align + 1;
17779           if (tmp != count_exp)
17780             emit_move_insn (count_exp, tmp);
17781         }
17782       emit_label (label);
17783       LABEL_NUSES (label) = 1;
17784     }
17785   if (count_exp != const0_rtx && epilogue_size_needed > 1)
17786     {
17787       if (force_loopy_epilogue)
17788         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
17789                                          size_needed);
17790       else
17791         expand_setmem_epilogue (dst, destreg, promoted_val, count_exp,
17792                                 size_needed);
17793     }
17794   if (jump_around_label)
17795     emit_label (jump_around_label);
17796   return 1;
17797 }
17798
17799 /* Expand the appropriate insns for doing strlen if not just doing
17800    repnz; scasb
17801
17802    out = result, initialized with the start address
17803    align_rtx = alignment of the address.
17804    scratch = scratch register, initialized with the startaddress when
17805         not aligned, otherwise undefined
17806
17807    This is just the body. It needs the initializations mentioned above and
17808    some address computing at the end.  These things are done in i386.md.  */
17809
17810 static void
17811 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
17812 {
17813   int align;
17814   rtx tmp;
17815   rtx align_2_label = NULL_RTX;
17816   rtx align_3_label = NULL_RTX;
17817   rtx align_4_label = gen_label_rtx ();
17818   rtx end_0_label = gen_label_rtx ();
17819   rtx mem;
17820   rtx tmpreg = gen_reg_rtx (SImode);
17821   rtx scratch = gen_reg_rtx (SImode);
17822   rtx cmp;
17823
17824   align = 0;
17825   if (CONST_INT_P (align_rtx))
17826     align = INTVAL (align_rtx);
17827
17828   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
17829
17830   /* Is there a known alignment and is it less than 4?  */
17831   if (align < 4)
17832     {
17833       rtx scratch1 = gen_reg_rtx (Pmode);
17834       emit_move_insn (scratch1, out);
17835       /* Is there a known alignment and is it not 2? */
17836       if (align != 2)
17837         {
17838           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
17839           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
17840
17841           /* Leave just the 3 lower bits.  */
17842           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
17843                                     NULL_RTX, 0, OPTAB_WIDEN);
17844
17845           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
17846                                    Pmode, 1, align_4_label);
17847           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
17848                                    Pmode, 1, align_2_label);
17849           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
17850                                    Pmode, 1, align_3_label);
17851         }
17852       else
17853         {
17854           /* Since the alignment is 2, we have to check 2 or 0 bytes;
17855              check if is aligned to 4 - byte.  */
17856
17857           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
17858                                     NULL_RTX, 0, OPTAB_WIDEN);
17859
17860           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
17861                                    Pmode, 1, align_4_label);
17862         }
17863
17864       mem = change_address (src, QImode, out);
17865
17866       /* Now compare the bytes.  */
17867
17868       /* Compare the first n unaligned byte on a byte per byte basis.  */
17869       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
17870                                QImode, 1, end_0_label);
17871
17872       /* Increment the address.  */
17873       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17874
17875       /* Not needed with an alignment of 2 */
17876       if (align != 2)
17877         {
17878           emit_label (align_2_label);
17879
17880           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
17881                                    end_0_label);
17882
17883           emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17884
17885           emit_label (align_3_label);
17886         }
17887
17888       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
17889                                end_0_label);
17890
17891       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17892     }
17893
17894   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
17895      align this loop.  It gives only huge programs, but does not help to
17896      speed up.  */
17897   emit_label (align_4_label);
17898
17899   mem = change_address (src, SImode, out);
17900   emit_move_insn (scratch, mem);
17901   emit_insn ((*ix86_gen_add3) (out, out, GEN_INT (4)));
17902
17903   /* This formula yields a nonzero result iff one of the bytes is zero.
17904      This saves three branches inside loop and many cycles.  */
17905
17906   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
17907   emit_insn (gen_one_cmplsi2 (scratch, scratch));
17908   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
17909   emit_insn (gen_andsi3 (tmpreg, tmpreg,
17910                          gen_int_mode (0x80808080, SImode)));
17911   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
17912                            align_4_label);
17913
17914   if (TARGET_CMOVE)
17915     {
17916        rtx reg = gen_reg_rtx (SImode);
17917        rtx reg2 = gen_reg_rtx (Pmode);
17918        emit_move_insn (reg, tmpreg);
17919        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
17920
17921        /* If zero is not in the first two bytes, move two bytes forward.  */
17922        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
17923        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17924        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
17925        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
17926                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
17927                                                      reg,
17928                                                      tmpreg)));
17929        /* Emit lea manually to avoid clobbering of flags.  */
17930        emit_insn (gen_rtx_SET (SImode, reg2,
17931                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
17932
17933        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17934        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
17935        emit_insn (gen_rtx_SET (VOIDmode, out,
17936                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
17937                                                      reg2,
17938                                                      out)));
17939
17940     }
17941   else
17942     {
17943        rtx end_2_label = gen_label_rtx ();
17944        /* Is zero in the first two bytes? */
17945
17946        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
17947        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17948        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
17949        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
17950                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
17951                             pc_rtx);
17952        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
17953        JUMP_LABEL (tmp) = end_2_label;
17954
17955        /* Not in the first two.  Move two bytes forward.  */
17956        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
17957        emit_insn ((*ix86_gen_add3) (out, out, const2_rtx));
17958
17959        emit_label (end_2_label);
17960
17961     }
17962
17963   /* Avoid branch in fixing the byte.  */
17964   tmpreg = gen_lowpart (QImode, tmpreg);
17965   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
17966   cmp = gen_rtx_LTU (Pmode, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx);
17967   emit_insn ((*ix86_gen_sub3_carry) (out, out, GEN_INT (3), cmp));
17968
17969   emit_label (end_0_label);
17970 }
17971
17972 /* Expand strlen.  */
17973
17974 int
17975 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
17976 {
17977   rtx addr, scratch1, scratch2, scratch3, scratch4;
17978
17979   /* The generic case of strlen expander is long.  Avoid it's
17980      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
17981
17982   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
17983       && !TARGET_INLINE_ALL_STRINGOPS
17984       && !optimize_insn_for_size_p ()
17985       && (!CONST_INT_P (align) || INTVAL (align) < 4))
17986     return 0;
17987
17988   addr = force_reg (Pmode, XEXP (src, 0));
17989   scratch1 = gen_reg_rtx (Pmode);
17990
17991   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
17992       && !optimize_insn_for_size_p ())
17993     {
17994       /* Well it seems that some optimizer does not combine a call like
17995          foo(strlen(bar), strlen(bar));
17996          when the move and the subtraction is done here.  It does calculate
17997          the length just once when these instructions are done inside of
17998          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
17999          often used and I use one fewer register for the lifetime of
18000          output_strlen_unroll() this is better.  */
18001
18002       emit_move_insn (out, addr);
18003
18004       ix86_expand_strlensi_unroll_1 (out, src, align);
18005
18006       /* strlensi_unroll_1 returns the address of the zero at the end of
18007          the string, like memchr(), so compute the length by subtracting
18008          the start address.  */
18009       emit_insn ((*ix86_gen_sub3) (out, out, addr));
18010     }
18011   else
18012     {
18013       rtx unspec;
18014
18015       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
18016       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
18017         return false;
18018
18019       scratch2 = gen_reg_rtx (Pmode);
18020       scratch3 = gen_reg_rtx (Pmode);
18021       scratch4 = force_reg (Pmode, constm1_rtx);
18022
18023       emit_move_insn (scratch3, addr);
18024       eoschar = force_reg (QImode, eoschar);
18025
18026       src = replace_equiv_address_nv (src, scratch3);
18027
18028       /* If .md starts supporting :P, this can be done in .md.  */
18029       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
18030                                                  scratch4), UNSPEC_SCAS);
18031       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
18032       emit_insn ((*ix86_gen_one_cmpl2) (scratch2, scratch1));
18033       emit_insn ((*ix86_gen_add3) (out, scratch2, constm1_rtx));
18034     }
18035   return 1;
18036 }
18037
18038 /* For given symbol (function) construct code to compute address of it's PLT
18039    entry in large x86-64 PIC model.  */
18040 rtx
18041 construct_plt_address (rtx symbol)
18042 {
18043   rtx tmp = gen_reg_rtx (Pmode);
18044   rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
18045
18046   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
18047   gcc_assert (ix86_cmodel == CM_LARGE_PIC);
18048
18049   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
18050   emit_insn (gen_adddi3 (tmp, tmp, pic_offset_table_rtx));
18051   return tmp;
18052 }
18053
18054 void
18055 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
18056                   rtx callarg2 ATTRIBUTE_UNUSED,
18057                   rtx pop, int sibcall)
18058 {
18059   rtx use = NULL, call;
18060
18061   if (pop == const0_rtx)
18062     pop = NULL;
18063   gcc_assert (!TARGET_64BIT || !pop);
18064
18065   if (TARGET_MACHO && !TARGET_64BIT)
18066     {
18067 #if TARGET_MACHO
18068       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
18069         fnaddr = machopic_indirect_call_target (fnaddr);
18070 #endif
18071     }
18072   else
18073     {
18074       /* Static functions and indirect calls don't need the pic register.  */
18075       if (flag_pic && (!TARGET_64BIT || ix86_cmodel == CM_LARGE_PIC)
18076           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18077           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
18078         use_reg (&use, pic_offset_table_rtx);
18079     }
18080
18081   if (TARGET_64BIT && INTVAL (callarg2) >= 0)
18082     {
18083       rtx al = gen_rtx_REG (QImode, AX_REG);
18084       emit_move_insn (al, callarg2);
18085       use_reg (&use, al);
18086     }
18087
18088   if (ix86_cmodel == CM_LARGE_PIC
18089       && GET_CODE (fnaddr) == MEM
18090       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18091       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
18092     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
18093   else if (! call_insn_operand (XEXP (fnaddr, 0), Pmode))
18094     {
18095       fnaddr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18096       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18097     }
18098   if (sibcall && TARGET_64BIT
18099       && !constant_call_address_operand (XEXP (fnaddr, 0), Pmode))
18100     {
18101       rtx addr;
18102       addr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18103       fnaddr = gen_rtx_REG (Pmode, R11_REG);
18104       emit_move_insn (fnaddr, addr);
18105       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18106     }
18107
18108   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
18109   if (retval)
18110     call = gen_rtx_SET (VOIDmode, retval, call);
18111   if (pop)
18112     {
18113       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
18114       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
18115       call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop));
18116     }
18117
18118   call = emit_call_insn (call);
18119   if (use)
18120     CALL_INSN_FUNCTION_USAGE (call) = use;
18121 }
18122
18123 \f
18124 /* Clear stack slot assignments remembered from previous functions.
18125    This is called from INIT_EXPANDERS once before RTL is emitted for each
18126    function.  */
18127
18128 static struct machine_function *
18129 ix86_init_machine_status (void)
18130 {
18131   struct machine_function *f;
18132
18133   f = GGC_CNEW (struct machine_function);
18134   f->use_fast_prologue_epilogue_nregs = -1;
18135   f->tls_descriptor_call_expanded_p = 0;
18136   f->call_abi = DEFAULT_ABI;
18137
18138   return f;
18139 }
18140
18141 /* Return a MEM corresponding to a stack slot with mode MODE.
18142    Allocate a new slot if necessary.
18143
18144    The RTL for a function can have several slots available: N is
18145    which slot to use.  */
18146
18147 rtx
18148 assign_386_stack_local (enum machine_mode mode, enum ix86_stack_slot n)
18149 {
18150   struct stack_local_entry *s;
18151
18152   gcc_assert (n < MAX_386_STACK_LOCALS);
18153
18154   /* Virtual slot is valid only before vregs are instantiated.  */
18155   gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
18156
18157   for (s = ix86_stack_locals; s; s = s->next)
18158     if (s->mode == mode && s->n == n)
18159       return copy_rtx (s->rtl);
18160
18161   s = (struct stack_local_entry *)
18162     ggc_alloc (sizeof (struct stack_local_entry));
18163   s->n = n;
18164   s->mode = mode;
18165   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
18166
18167   s->next = ix86_stack_locals;
18168   ix86_stack_locals = s;
18169   return s->rtl;
18170 }
18171
18172 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
18173
18174 static GTY(()) rtx ix86_tls_symbol;
18175 rtx
18176 ix86_tls_get_addr (void)
18177 {
18178
18179   if (!ix86_tls_symbol)
18180     {
18181       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode,
18182                                             (TARGET_ANY_GNU_TLS
18183                                              && !TARGET_64BIT)
18184                                             ? "___tls_get_addr"
18185                                             : "__tls_get_addr");
18186     }
18187
18188   return ix86_tls_symbol;
18189 }
18190
18191 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
18192
18193 static GTY(()) rtx ix86_tls_module_base_symbol;
18194 rtx
18195 ix86_tls_module_base (void)
18196 {
18197
18198   if (!ix86_tls_module_base_symbol)
18199     {
18200       ix86_tls_module_base_symbol = gen_rtx_SYMBOL_REF (Pmode,
18201                                                         "_TLS_MODULE_BASE_");
18202       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
18203         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
18204     }
18205
18206   return ix86_tls_module_base_symbol;
18207 }
18208 \f
18209 /* Calculate the length of the memory address in the instruction
18210    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
18211
18212 int
18213 memory_address_length (rtx addr)
18214 {
18215   struct ix86_address parts;
18216   rtx base, index, disp;
18217   int len;
18218   int ok;
18219
18220   if (GET_CODE (addr) == PRE_DEC
18221       || GET_CODE (addr) == POST_INC
18222       || GET_CODE (addr) == PRE_MODIFY
18223       || GET_CODE (addr) == POST_MODIFY)
18224     return 0;
18225
18226   ok = ix86_decompose_address (addr, &parts);
18227   gcc_assert (ok);
18228
18229   if (parts.base && GET_CODE (parts.base) == SUBREG)
18230     parts.base = SUBREG_REG (parts.base);
18231   if (parts.index && GET_CODE (parts.index) == SUBREG)
18232     parts.index = SUBREG_REG (parts.index);
18233
18234   base = parts.base;
18235   index = parts.index;
18236   disp = parts.disp;
18237   len = 0;
18238
18239   /* Rule of thumb:
18240        - esp as the base always wants an index,
18241        - ebp as the base always wants a displacement.  */
18242
18243   /* Register Indirect.  */
18244   if (base && !index && !disp)
18245     {
18246       /* esp (for its index) and ebp (for its displacement) need
18247          the two-byte modrm form.  */
18248       if (addr == stack_pointer_rtx
18249           || addr == arg_pointer_rtx
18250           || addr == frame_pointer_rtx
18251           || addr == hard_frame_pointer_rtx)
18252         len = 1;
18253     }
18254
18255   /* Direct Addressing.  */
18256   else if (disp && !base && !index)
18257     len = 4;
18258
18259   else
18260     {
18261       /* Find the length of the displacement constant.  */
18262       if (disp)
18263         {
18264           if (base && satisfies_constraint_K (disp))
18265             len = 1;
18266           else
18267             len = 4;
18268         }
18269       /* ebp always wants a displacement.  */
18270       else if (base == hard_frame_pointer_rtx)
18271         len = 1;
18272
18273       /* An index requires the two-byte modrm form....  */
18274       if (index
18275           /* ...like esp, which always wants an index.  */
18276           || base == stack_pointer_rtx
18277           || base == arg_pointer_rtx
18278           || base == frame_pointer_rtx)
18279         len += 1;
18280     }
18281
18282   return len;
18283 }
18284
18285 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
18286    is set, expect that insn have 8bit immediate alternative.  */
18287 int
18288 ix86_attr_length_immediate_default (rtx insn, int shortform)
18289 {
18290   int len = 0;
18291   int i;
18292   extract_insn_cached (insn);
18293   for (i = recog_data.n_operands - 1; i >= 0; --i)
18294     if (CONSTANT_P (recog_data.operand[i]))
18295       {
18296         gcc_assert (!len);
18297         if (shortform && satisfies_constraint_K (recog_data.operand[i]))
18298           len = 1;
18299         else
18300           {
18301             switch (get_attr_mode (insn))
18302               {
18303                 case MODE_QI:
18304                   len+=1;
18305                   break;
18306                 case MODE_HI:
18307                   len+=2;
18308                   break;
18309                 case MODE_SI:
18310                   len+=4;
18311                   break;
18312                 /* Immediates for DImode instructions are encoded as 32bit sign extended values.  */
18313                 case MODE_DI:
18314                   len+=4;
18315                   break;
18316                 default:
18317                   fatal_insn ("unknown insn mode", insn);
18318               }
18319           }
18320       }
18321   return len;
18322 }
18323 /* Compute default value for "length_address" attribute.  */
18324 int
18325 ix86_attr_length_address_default (rtx insn)
18326 {
18327   int i;
18328
18329   if (get_attr_type (insn) == TYPE_LEA)
18330     {
18331       rtx set = PATTERN (insn);
18332
18333       if (GET_CODE (set) == PARALLEL)
18334         set = XVECEXP (set, 0, 0);
18335
18336       gcc_assert (GET_CODE (set) == SET);
18337
18338       return memory_address_length (SET_SRC (set));
18339     }
18340
18341   extract_insn_cached (insn);
18342   for (i = recog_data.n_operands - 1; i >= 0; --i)
18343     if (MEM_P (recog_data.operand[i]))
18344       {
18345         return memory_address_length (XEXP (recog_data.operand[i], 0));
18346         break;
18347       }
18348   return 0;
18349 }
18350
18351 /* Compute default value for "length_vex" attribute. It includes
18352    2 or 3 byte VEX prefix and 1 opcode byte.  */
18353
18354 int
18355 ix86_attr_length_vex_default (rtx insn, int has_0f_opcode,
18356                               int has_vex_w)
18357 {
18358   int i;
18359
18360   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
18361      byte VEX prefix.  */
18362   if (!has_0f_opcode || has_vex_w)
18363     return 3 + 1;
18364
18365  /* We can always use 2 byte VEX prefix in 32bit.  */
18366   if (!TARGET_64BIT)
18367     return 2 + 1;
18368
18369   extract_insn_cached (insn);
18370
18371   for (i = recog_data.n_operands - 1; i >= 0; --i)
18372     if (REG_P (recog_data.operand[i]))
18373       {
18374         /* REX.W bit uses 3 byte VEX prefix.  */
18375         if (GET_MODE (recog_data.operand[i]) == DImode)
18376           return 3 + 1;
18377       }
18378     else
18379       {
18380         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
18381         if (MEM_P (recog_data.operand[i])
18382             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
18383           return 3 + 1;
18384       }
18385
18386   return 2 + 1;
18387 }
18388 \f
18389 /* Return the maximum number of instructions a cpu can issue.  */
18390
18391 static int
18392 ix86_issue_rate (void)
18393 {
18394   switch (ix86_tune)
18395     {
18396     case PROCESSOR_PENTIUM:
18397     case PROCESSOR_K6:
18398       return 2;
18399
18400     case PROCESSOR_PENTIUMPRO:
18401     case PROCESSOR_PENTIUM4:
18402     case PROCESSOR_ATHLON:
18403     case PROCESSOR_K8:
18404     case PROCESSOR_AMDFAM10:
18405     case PROCESSOR_NOCONA:
18406     case PROCESSOR_GENERIC32:
18407     case PROCESSOR_GENERIC64:
18408       return 3;
18409
18410     case PROCESSOR_CORE2:
18411       return 4;
18412
18413     default:
18414       return 1;
18415     }
18416 }
18417
18418 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
18419    by DEP_INSN and nothing set by DEP_INSN.  */
18420
18421 static int
18422 ix86_flags_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
18423 {
18424   rtx set, set2;
18425
18426   /* Simplify the test for uninteresting insns.  */
18427   if (insn_type != TYPE_SETCC
18428       && insn_type != TYPE_ICMOV
18429       && insn_type != TYPE_FCMOV
18430       && insn_type != TYPE_IBR)
18431     return 0;
18432
18433   if ((set = single_set (dep_insn)) != 0)
18434     {
18435       set = SET_DEST (set);
18436       set2 = NULL_RTX;
18437     }
18438   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
18439            && XVECLEN (PATTERN (dep_insn), 0) == 2
18440            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
18441            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
18442     {
18443       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
18444       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
18445     }
18446   else
18447     return 0;
18448
18449   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
18450     return 0;
18451
18452   /* This test is true if the dependent insn reads the flags but
18453      not any other potentially set register.  */
18454   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
18455     return 0;
18456
18457   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
18458     return 0;
18459
18460   return 1;
18461 }
18462
18463 /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory
18464    address with operands set by DEP_INSN.  */
18465
18466 static int
18467 ix86_agi_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
18468 {
18469   rtx addr;
18470
18471   if (insn_type == TYPE_LEA
18472       && TARGET_PENTIUM)
18473     {
18474       addr = PATTERN (insn);
18475
18476       if (GET_CODE (addr) == PARALLEL)
18477         addr = XVECEXP (addr, 0, 0);
18478
18479       gcc_assert (GET_CODE (addr) == SET);
18480
18481       addr = SET_SRC (addr);
18482     }
18483   else
18484     {
18485       int i;
18486       extract_insn_cached (insn);
18487       for (i = recog_data.n_operands - 1; i >= 0; --i)
18488         if (MEM_P (recog_data.operand[i]))
18489           {
18490             addr = XEXP (recog_data.operand[i], 0);
18491             goto found;
18492           }
18493       return 0;
18494     found:;
18495     }
18496
18497   return modified_in_p (addr, dep_insn);
18498 }
18499
18500 static int
18501 ix86_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
18502 {
18503   enum attr_type insn_type, dep_insn_type;
18504   enum attr_memory memory;
18505   rtx set, set2;
18506   int dep_insn_code_number;
18507
18508   /* Anti and output dependencies have zero cost on all CPUs.  */
18509   if (REG_NOTE_KIND (link) != 0)
18510     return 0;
18511
18512   dep_insn_code_number = recog_memoized (dep_insn);
18513
18514   /* If we can't recognize the insns, we can't really do anything.  */
18515   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
18516     return cost;
18517
18518   insn_type = get_attr_type (insn);
18519   dep_insn_type = get_attr_type (dep_insn);
18520
18521   switch (ix86_tune)
18522     {
18523     case PROCESSOR_PENTIUM:
18524       /* Address Generation Interlock adds a cycle of latency.  */
18525       if (ix86_agi_dependent (insn, dep_insn, insn_type))
18526         cost += 1;
18527
18528       /* ??? Compares pair with jump/setcc.  */
18529       if (ix86_flags_dependent (insn, dep_insn, insn_type))
18530         cost = 0;
18531
18532       /* Floating point stores require value to be ready one cycle earlier.  */
18533       if (insn_type == TYPE_FMOV
18534           && get_attr_memory (insn) == MEMORY_STORE
18535           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18536         cost += 1;
18537       break;
18538
18539     case PROCESSOR_PENTIUMPRO:
18540       memory = get_attr_memory (insn);
18541
18542       /* INT->FP conversion is expensive.  */
18543       if (get_attr_fp_int_src (dep_insn))
18544         cost += 5;
18545
18546       /* There is one cycle extra latency between an FP op and a store.  */
18547       if (insn_type == TYPE_FMOV
18548           && (set = single_set (dep_insn)) != NULL_RTX
18549           && (set2 = single_set (insn)) != NULL_RTX
18550           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
18551           && MEM_P (SET_DEST (set2)))
18552         cost += 1;
18553
18554       /* Show ability of reorder buffer to hide latency of load by executing
18555          in parallel with previous instruction in case
18556          previous instruction is not needed to compute the address.  */
18557       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18558           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18559         {
18560           /* Claim moves to take one cycle, as core can issue one load
18561              at time and the next load can start cycle later.  */
18562           if (dep_insn_type == TYPE_IMOV
18563               || dep_insn_type == TYPE_FMOV)
18564             cost = 1;
18565           else if (cost > 1)
18566             cost--;
18567         }
18568       break;
18569
18570     case PROCESSOR_K6:
18571       memory = get_attr_memory (insn);
18572
18573       /* The esp dependency is resolved before the instruction is really
18574          finished.  */
18575       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
18576           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
18577         return 1;
18578
18579       /* INT->FP conversion is expensive.  */
18580       if (get_attr_fp_int_src (dep_insn))
18581         cost += 5;
18582
18583       /* Show ability of reorder buffer to hide latency of load by executing
18584          in parallel with previous instruction in case
18585          previous instruction is not needed to compute the address.  */
18586       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18587           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18588         {
18589           /* Claim moves to take one cycle, as core can issue one load
18590              at time and the next load can start cycle later.  */
18591           if (dep_insn_type == TYPE_IMOV
18592               || dep_insn_type == TYPE_FMOV)
18593             cost = 1;
18594           else if (cost > 2)
18595             cost -= 2;
18596           else
18597             cost = 1;
18598         }
18599       break;
18600
18601     case PROCESSOR_ATHLON:
18602     case PROCESSOR_K8:
18603     case PROCESSOR_AMDFAM10:
18604     case PROCESSOR_GENERIC32:
18605     case PROCESSOR_GENERIC64:
18606       memory = get_attr_memory (insn);
18607
18608       /* Show ability of reorder buffer to hide latency of load by executing
18609          in parallel with previous instruction in case
18610          previous instruction is not needed to compute the address.  */
18611       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18612           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18613         {
18614           enum attr_unit unit = get_attr_unit (insn);
18615           int loadcost = 3;
18616
18617           /* Because of the difference between the length of integer and
18618              floating unit pipeline preparation stages, the memory operands
18619              for floating point are cheaper.
18620
18621              ??? For Athlon it the difference is most probably 2.  */
18622           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
18623             loadcost = 3;
18624           else
18625             loadcost = TARGET_ATHLON ? 2 : 0;
18626
18627           if (cost >= loadcost)
18628             cost -= loadcost;
18629           else
18630             cost = 0;
18631         }
18632
18633     default:
18634       break;
18635     }
18636
18637   return cost;
18638 }
18639
18640 /* How many alternative schedules to try.  This should be as wide as the
18641    scheduling freedom in the DFA, but no wider.  Making this value too
18642    large results extra work for the scheduler.  */
18643
18644 static int
18645 ia32_multipass_dfa_lookahead (void)
18646 {
18647   switch (ix86_tune)
18648     {
18649     case PROCESSOR_PENTIUM:
18650       return 2;
18651
18652     case PROCESSOR_PENTIUMPRO:
18653     case PROCESSOR_K6:
18654       return 1;
18655
18656     default:
18657       return 0;
18658     }
18659 }
18660
18661 \f
18662 /* Compute the alignment given to a constant that is being placed in memory.
18663    EXP is the constant and ALIGN is the alignment that the object would
18664    ordinarily have.
18665    The value of this function is used instead of that alignment to align
18666    the object.  */
18667
18668 int
18669 ix86_constant_alignment (tree exp, int align)
18670 {
18671   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
18672       || TREE_CODE (exp) == INTEGER_CST)
18673     {
18674       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
18675         return 64;
18676       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
18677         return 128;
18678     }
18679   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
18680            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
18681     return BITS_PER_WORD;
18682
18683   return align;
18684 }
18685
18686 /* Compute the alignment for a static variable.
18687    TYPE is the data type, and ALIGN is the alignment that
18688    the object would ordinarily have.  The value of this function is used
18689    instead of that alignment to align the object.  */
18690
18691 int
18692 ix86_data_alignment (tree type, int align)
18693 {
18694   int max_align = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
18695
18696   if (AGGREGATE_TYPE_P (type)
18697       && TYPE_SIZE (type)
18698       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18699       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= (unsigned) max_align
18700           || TREE_INT_CST_HIGH (TYPE_SIZE (type)))
18701       && align < max_align)
18702     align = max_align;
18703
18704   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18705      to 16byte boundary.  */
18706   if (TARGET_64BIT)
18707     {
18708       if (AGGREGATE_TYPE_P (type)
18709            && TYPE_SIZE (type)
18710            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18711            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 128
18712                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
18713         return 128;
18714     }
18715
18716   if (TREE_CODE (type) == ARRAY_TYPE)
18717     {
18718       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18719         return 64;
18720       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18721         return 128;
18722     }
18723   else if (TREE_CODE (type) == COMPLEX_TYPE)
18724     {
18725
18726       if (TYPE_MODE (type) == DCmode && align < 64)
18727         return 64;
18728       if ((TYPE_MODE (type) == XCmode
18729            || TYPE_MODE (type) == TCmode) && align < 128)
18730         return 128;
18731     }
18732   else if ((TREE_CODE (type) == RECORD_TYPE
18733             || TREE_CODE (type) == UNION_TYPE
18734             || TREE_CODE (type) == QUAL_UNION_TYPE)
18735            && TYPE_FIELDS (type))
18736     {
18737       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18738         return 64;
18739       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18740         return 128;
18741     }
18742   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
18743            || TREE_CODE (type) == INTEGER_TYPE)
18744     {
18745       if (TYPE_MODE (type) == DFmode && align < 64)
18746         return 64;
18747       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18748         return 128;
18749     }
18750
18751   return align;
18752 }
18753
18754 /* Compute the alignment for a local variable or a stack slot.  TYPE is
18755    the data type, MODE is the widest mode available and ALIGN is the
18756    alignment that the object would ordinarily have.  The value of this
18757    macro is used instead of that alignment to align the object.  */
18758
18759 unsigned int
18760 ix86_local_alignment (tree type, enum machine_mode mode,
18761                       unsigned int align)
18762 {
18763   /* If TYPE is NULL, we are allocating a stack slot for caller-save
18764      register in MODE.  We will return the largest alignment of XF
18765      and DF.  */
18766   if (!type)
18767     {
18768       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
18769         align = GET_MODE_ALIGNMENT (DFmode);
18770       return align;
18771     }
18772
18773   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18774      to 16byte boundary.  */
18775   if (TARGET_64BIT)
18776     {
18777       if (AGGREGATE_TYPE_P (type)
18778            && TYPE_SIZE (type)
18779            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18780            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16
18781                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
18782         return 128;
18783     }
18784   if (TREE_CODE (type) == ARRAY_TYPE)
18785     {
18786       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18787         return 64;
18788       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18789         return 128;
18790     }
18791   else if (TREE_CODE (type) == COMPLEX_TYPE)
18792     {
18793       if (TYPE_MODE (type) == DCmode && align < 64)
18794         return 64;
18795       if ((TYPE_MODE (type) == XCmode
18796            || TYPE_MODE (type) == TCmode) && align < 128)
18797         return 128;
18798     }
18799   else if ((TREE_CODE (type) == RECORD_TYPE
18800             || TREE_CODE (type) == UNION_TYPE
18801             || TREE_CODE (type) == QUAL_UNION_TYPE)
18802            && TYPE_FIELDS (type))
18803     {
18804       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18805         return 64;
18806       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18807         return 128;
18808     }
18809   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
18810            || TREE_CODE (type) == INTEGER_TYPE)
18811     {
18812
18813       if (TYPE_MODE (type) == DFmode && align < 64)
18814         return 64;
18815       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18816         return 128;
18817     }
18818   return align;
18819 }
18820 \f
18821 /* Emit RTL insns to initialize the variable parts of a trampoline.
18822    FNADDR is an RTX for the address of the function's pure code.
18823    CXT is an RTX for the static chain value for the function.  */
18824 void
18825 x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
18826 {
18827   if (!TARGET_64BIT)
18828     {
18829       /* Compute offset from the end of the jmp to the target function.  */
18830       rtx disp = expand_binop (SImode, sub_optab, fnaddr,
18831                                plus_constant (tramp, 10),
18832                                NULL_RTX, 1, OPTAB_DIRECT);
18833       emit_move_insn (gen_rtx_MEM (QImode, tramp),
18834                       gen_int_mode (0xb9, QImode));
18835       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
18836       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
18837                       gen_int_mode (0xe9, QImode));
18838       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
18839     }
18840   else
18841     {
18842       int offset = 0;
18843       /* Try to load address using shorter movl instead of movabs.
18844          We may want to support movq for kernel mode, but kernel does not use
18845          trampolines at the moment.  */
18846       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
18847         {
18848           fnaddr = copy_to_mode_reg (DImode, fnaddr);
18849           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18850                           gen_int_mode (0xbb41, HImode));
18851           emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
18852                           gen_lowpart (SImode, fnaddr));
18853           offset += 6;
18854         }
18855       else
18856         {
18857           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18858                           gen_int_mode (0xbb49, HImode));
18859           emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
18860                           fnaddr);
18861           offset += 10;
18862         }
18863       /* Load static chain using movabs to r10.  */
18864       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18865                       gen_int_mode (0xba49, HImode));
18866       emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
18867                       cxt);
18868       offset += 10;
18869       /* Jump to the r11 */
18870       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18871                       gen_int_mode (0xff49, HImode));
18872       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
18873                       gen_int_mode (0xe3, QImode));
18874       offset += 3;
18875       gcc_assert (offset <= TRAMPOLINE_SIZE);
18876     }
18877
18878 #ifdef ENABLE_EXECUTE_STACK
18879   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
18880                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
18881 #endif
18882 }
18883 \f
18884 /* Codes for all the SSE/MMX builtins.  */
18885 enum ix86_builtins
18886 {
18887   IX86_BUILTIN_ADDPS,
18888   IX86_BUILTIN_ADDSS,
18889   IX86_BUILTIN_DIVPS,
18890   IX86_BUILTIN_DIVSS,
18891   IX86_BUILTIN_MULPS,
18892   IX86_BUILTIN_MULSS,
18893   IX86_BUILTIN_SUBPS,
18894   IX86_BUILTIN_SUBSS,
18895
18896   IX86_BUILTIN_CMPEQPS,
18897   IX86_BUILTIN_CMPLTPS,
18898   IX86_BUILTIN_CMPLEPS,
18899   IX86_BUILTIN_CMPGTPS,
18900   IX86_BUILTIN_CMPGEPS,
18901   IX86_BUILTIN_CMPNEQPS,
18902   IX86_BUILTIN_CMPNLTPS,
18903   IX86_BUILTIN_CMPNLEPS,
18904   IX86_BUILTIN_CMPNGTPS,
18905   IX86_BUILTIN_CMPNGEPS,
18906   IX86_BUILTIN_CMPORDPS,
18907   IX86_BUILTIN_CMPUNORDPS,
18908   IX86_BUILTIN_CMPEQSS,
18909   IX86_BUILTIN_CMPLTSS,
18910   IX86_BUILTIN_CMPLESS,
18911   IX86_BUILTIN_CMPNEQSS,
18912   IX86_BUILTIN_CMPNLTSS,
18913   IX86_BUILTIN_CMPNLESS,
18914   IX86_BUILTIN_CMPNGTSS,
18915   IX86_BUILTIN_CMPNGESS,
18916   IX86_BUILTIN_CMPORDSS,
18917   IX86_BUILTIN_CMPUNORDSS,
18918
18919   IX86_BUILTIN_COMIEQSS,
18920   IX86_BUILTIN_COMILTSS,
18921   IX86_BUILTIN_COMILESS,
18922   IX86_BUILTIN_COMIGTSS,
18923   IX86_BUILTIN_COMIGESS,
18924   IX86_BUILTIN_COMINEQSS,
18925   IX86_BUILTIN_UCOMIEQSS,
18926   IX86_BUILTIN_UCOMILTSS,
18927   IX86_BUILTIN_UCOMILESS,
18928   IX86_BUILTIN_UCOMIGTSS,
18929   IX86_BUILTIN_UCOMIGESS,
18930   IX86_BUILTIN_UCOMINEQSS,
18931
18932   IX86_BUILTIN_CVTPI2PS,
18933   IX86_BUILTIN_CVTPS2PI,
18934   IX86_BUILTIN_CVTSI2SS,
18935   IX86_BUILTIN_CVTSI642SS,
18936   IX86_BUILTIN_CVTSS2SI,
18937   IX86_BUILTIN_CVTSS2SI64,
18938   IX86_BUILTIN_CVTTPS2PI,
18939   IX86_BUILTIN_CVTTSS2SI,
18940   IX86_BUILTIN_CVTTSS2SI64,
18941
18942   IX86_BUILTIN_MAXPS,
18943   IX86_BUILTIN_MAXSS,
18944   IX86_BUILTIN_MINPS,
18945   IX86_BUILTIN_MINSS,
18946
18947   IX86_BUILTIN_LOADUPS,
18948   IX86_BUILTIN_STOREUPS,
18949   IX86_BUILTIN_MOVSS,
18950
18951   IX86_BUILTIN_MOVHLPS,
18952   IX86_BUILTIN_MOVLHPS,
18953   IX86_BUILTIN_LOADHPS,
18954   IX86_BUILTIN_LOADLPS,
18955   IX86_BUILTIN_STOREHPS,
18956   IX86_BUILTIN_STORELPS,
18957
18958   IX86_BUILTIN_MASKMOVQ,
18959   IX86_BUILTIN_MOVMSKPS,
18960   IX86_BUILTIN_PMOVMSKB,
18961
18962   IX86_BUILTIN_MOVNTPS,
18963   IX86_BUILTIN_MOVNTQ,
18964
18965   IX86_BUILTIN_LOADDQU,
18966   IX86_BUILTIN_STOREDQU,
18967
18968   IX86_BUILTIN_PACKSSWB,
18969   IX86_BUILTIN_PACKSSDW,
18970   IX86_BUILTIN_PACKUSWB,
18971
18972   IX86_BUILTIN_PADDB,
18973   IX86_BUILTIN_PADDW,
18974   IX86_BUILTIN_PADDD,
18975   IX86_BUILTIN_PADDQ,
18976   IX86_BUILTIN_PADDSB,
18977   IX86_BUILTIN_PADDSW,
18978   IX86_BUILTIN_PADDUSB,
18979   IX86_BUILTIN_PADDUSW,
18980   IX86_BUILTIN_PSUBB,
18981   IX86_BUILTIN_PSUBW,
18982   IX86_BUILTIN_PSUBD,
18983   IX86_BUILTIN_PSUBQ,
18984   IX86_BUILTIN_PSUBSB,
18985   IX86_BUILTIN_PSUBSW,
18986   IX86_BUILTIN_PSUBUSB,
18987   IX86_BUILTIN_PSUBUSW,
18988
18989   IX86_BUILTIN_PAND,
18990   IX86_BUILTIN_PANDN,
18991   IX86_BUILTIN_POR,
18992   IX86_BUILTIN_PXOR,
18993
18994   IX86_BUILTIN_PAVGB,
18995   IX86_BUILTIN_PAVGW,
18996
18997   IX86_BUILTIN_PCMPEQB,
18998   IX86_BUILTIN_PCMPEQW,
18999   IX86_BUILTIN_PCMPEQD,
19000   IX86_BUILTIN_PCMPGTB,
19001   IX86_BUILTIN_PCMPGTW,
19002   IX86_BUILTIN_PCMPGTD,
19003
19004   IX86_BUILTIN_PMADDWD,
19005
19006   IX86_BUILTIN_PMAXSW,
19007   IX86_BUILTIN_PMAXUB,
19008   IX86_BUILTIN_PMINSW,
19009   IX86_BUILTIN_PMINUB,
19010
19011   IX86_BUILTIN_PMULHUW,
19012   IX86_BUILTIN_PMULHW,
19013   IX86_BUILTIN_PMULLW,
19014
19015   IX86_BUILTIN_PSADBW,
19016   IX86_BUILTIN_PSHUFW,
19017
19018   IX86_BUILTIN_PSLLW,
19019   IX86_BUILTIN_PSLLD,
19020   IX86_BUILTIN_PSLLQ,
19021   IX86_BUILTIN_PSRAW,
19022   IX86_BUILTIN_PSRAD,
19023   IX86_BUILTIN_PSRLW,
19024   IX86_BUILTIN_PSRLD,
19025   IX86_BUILTIN_PSRLQ,
19026   IX86_BUILTIN_PSLLWI,
19027   IX86_BUILTIN_PSLLDI,
19028   IX86_BUILTIN_PSLLQI,
19029   IX86_BUILTIN_PSRAWI,
19030   IX86_BUILTIN_PSRADI,
19031   IX86_BUILTIN_PSRLWI,
19032   IX86_BUILTIN_PSRLDI,
19033   IX86_BUILTIN_PSRLQI,
19034
19035   IX86_BUILTIN_PUNPCKHBW,
19036   IX86_BUILTIN_PUNPCKHWD,
19037   IX86_BUILTIN_PUNPCKHDQ,
19038   IX86_BUILTIN_PUNPCKLBW,
19039   IX86_BUILTIN_PUNPCKLWD,
19040   IX86_BUILTIN_PUNPCKLDQ,
19041
19042   IX86_BUILTIN_SHUFPS,
19043
19044   IX86_BUILTIN_RCPPS,
19045   IX86_BUILTIN_RCPSS,
19046   IX86_BUILTIN_RSQRTPS,
19047   IX86_BUILTIN_RSQRTPS_NR,
19048   IX86_BUILTIN_RSQRTSS,
19049   IX86_BUILTIN_RSQRTF,
19050   IX86_BUILTIN_SQRTPS,
19051   IX86_BUILTIN_SQRTPS_NR,
19052   IX86_BUILTIN_SQRTSS,
19053
19054   IX86_BUILTIN_UNPCKHPS,
19055   IX86_BUILTIN_UNPCKLPS,
19056
19057   IX86_BUILTIN_ANDPS,
19058   IX86_BUILTIN_ANDNPS,
19059   IX86_BUILTIN_ORPS,
19060   IX86_BUILTIN_XORPS,
19061
19062   IX86_BUILTIN_EMMS,
19063   IX86_BUILTIN_LDMXCSR,
19064   IX86_BUILTIN_STMXCSR,
19065   IX86_BUILTIN_SFENCE,
19066
19067   /* 3DNow! Original */
19068   IX86_BUILTIN_FEMMS,
19069   IX86_BUILTIN_PAVGUSB,
19070   IX86_BUILTIN_PF2ID,
19071   IX86_BUILTIN_PFACC,
19072   IX86_BUILTIN_PFADD,
19073   IX86_BUILTIN_PFCMPEQ,
19074   IX86_BUILTIN_PFCMPGE,
19075   IX86_BUILTIN_PFCMPGT,
19076   IX86_BUILTIN_PFMAX,
19077   IX86_BUILTIN_PFMIN,
19078   IX86_BUILTIN_PFMUL,
19079   IX86_BUILTIN_PFRCP,
19080   IX86_BUILTIN_PFRCPIT1,
19081   IX86_BUILTIN_PFRCPIT2,
19082   IX86_BUILTIN_PFRSQIT1,
19083   IX86_BUILTIN_PFRSQRT,
19084   IX86_BUILTIN_PFSUB,
19085   IX86_BUILTIN_PFSUBR,
19086   IX86_BUILTIN_PI2FD,
19087   IX86_BUILTIN_PMULHRW,
19088
19089   /* 3DNow! Athlon Extensions */
19090   IX86_BUILTIN_PF2IW,
19091   IX86_BUILTIN_PFNACC,
19092   IX86_BUILTIN_PFPNACC,
19093   IX86_BUILTIN_PI2FW,
19094   IX86_BUILTIN_PSWAPDSI,
19095   IX86_BUILTIN_PSWAPDSF,
19096
19097   /* SSE2 */
19098   IX86_BUILTIN_ADDPD,
19099   IX86_BUILTIN_ADDSD,
19100   IX86_BUILTIN_DIVPD,
19101   IX86_BUILTIN_DIVSD,
19102   IX86_BUILTIN_MULPD,
19103   IX86_BUILTIN_MULSD,
19104   IX86_BUILTIN_SUBPD,
19105   IX86_BUILTIN_SUBSD,
19106
19107   IX86_BUILTIN_CMPEQPD,
19108   IX86_BUILTIN_CMPLTPD,
19109   IX86_BUILTIN_CMPLEPD,
19110   IX86_BUILTIN_CMPGTPD,
19111   IX86_BUILTIN_CMPGEPD,
19112   IX86_BUILTIN_CMPNEQPD,
19113   IX86_BUILTIN_CMPNLTPD,
19114   IX86_BUILTIN_CMPNLEPD,
19115   IX86_BUILTIN_CMPNGTPD,
19116   IX86_BUILTIN_CMPNGEPD,
19117   IX86_BUILTIN_CMPORDPD,
19118   IX86_BUILTIN_CMPUNORDPD,
19119   IX86_BUILTIN_CMPEQSD,
19120   IX86_BUILTIN_CMPLTSD,
19121   IX86_BUILTIN_CMPLESD,
19122   IX86_BUILTIN_CMPNEQSD,
19123   IX86_BUILTIN_CMPNLTSD,
19124   IX86_BUILTIN_CMPNLESD,
19125   IX86_BUILTIN_CMPORDSD,
19126   IX86_BUILTIN_CMPUNORDSD,
19127
19128   IX86_BUILTIN_COMIEQSD,
19129   IX86_BUILTIN_COMILTSD,
19130   IX86_BUILTIN_COMILESD,
19131   IX86_BUILTIN_COMIGTSD,
19132   IX86_BUILTIN_COMIGESD,
19133   IX86_BUILTIN_COMINEQSD,
19134   IX86_BUILTIN_UCOMIEQSD,
19135   IX86_BUILTIN_UCOMILTSD,
19136   IX86_BUILTIN_UCOMILESD,
19137   IX86_BUILTIN_UCOMIGTSD,
19138   IX86_BUILTIN_UCOMIGESD,
19139   IX86_BUILTIN_UCOMINEQSD,
19140
19141   IX86_BUILTIN_MAXPD,
19142   IX86_BUILTIN_MAXSD,
19143   IX86_BUILTIN_MINPD,
19144   IX86_BUILTIN_MINSD,
19145
19146   IX86_BUILTIN_ANDPD,
19147   IX86_BUILTIN_ANDNPD,
19148   IX86_BUILTIN_ORPD,
19149   IX86_BUILTIN_XORPD,
19150
19151   IX86_BUILTIN_SQRTPD,
19152   IX86_BUILTIN_SQRTSD,
19153
19154   IX86_BUILTIN_UNPCKHPD,
19155   IX86_BUILTIN_UNPCKLPD,
19156
19157   IX86_BUILTIN_SHUFPD,
19158
19159   IX86_BUILTIN_LOADUPD,
19160   IX86_BUILTIN_STOREUPD,
19161   IX86_BUILTIN_MOVSD,
19162
19163   IX86_BUILTIN_LOADHPD,
19164   IX86_BUILTIN_LOADLPD,
19165
19166   IX86_BUILTIN_CVTDQ2PD,
19167   IX86_BUILTIN_CVTDQ2PS,
19168
19169   IX86_BUILTIN_CVTPD2DQ,
19170   IX86_BUILTIN_CVTPD2PI,
19171   IX86_BUILTIN_CVTPD2PS,
19172   IX86_BUILTIN_CVTTPD2DQ,
19173   IX86_BUILTIN_CVTTPD2PI,
19174
19175   IX86_BUILTIN_CVTPI2PD,
19176   IX86_BUILTIN_CVTSI2SD,
19177   IX86_BUILTIN_CVTSI642SD,
19178
19179   IX86_BUILTIN_CVTSD2SI,
19180   IX86_BUILTIN_CVTSD2SI64,
19181   IX86_BUILTIN_CVTSD2SS,
19182   IX86_BUILTIN_CVTSS2SD,
19183   IX86_BUILTIN_CVTTSD2SI,
19184   IX86_BUILTIN_CVTTSD2SI64,
19185
19186   IX86_BUILTIN_CVTPS2DQ,
19187   IX86_BUILTIN_CVTPS2PD,
19188   IX86_BUILTIN_CVTTPS2DQ,
19189
19190   IX86_BUILTIN_MOVNTI,
19191   IX86_BUILTIN_MOVNTPD,
19192   IX86_BUILTIN_MOVNTDQ,
19193
19194   IX86_BUILTIN_MOVQ128,
19195
19196   /* SSE2 MMX */
19197   IX86_BUILTIN_MASKMOVDQU,
19198   IX86_BUILTIN_MOVMSKPD,
19199   IX86_BUILTIN_PMOVMSKB128,
19200
19201   IX86_BUILTIN_PACKSSWB128,
19202   IX86_BUILTIN_PACKSSDW128,
19203   IX86_BUILTIN_PACKUSWB128,
19204
19205   IX86_BUILTIN_PADDB128,
19206   IX86_BUILTIN_PADDW128,
19207   IX86_BUILTIN_PADDD128,
19208   IX86_BUILTIN_PADDQ128,
19209   IX86_BUILTIN_PADDSB128,
19210   IX86_BUILTIN_PADDSW128,
19211   IX86_BUILTIN_PADDUSB128,
19212   IX86_BUILTIN_PADDUSW128,
19213   IX86_BUILTIN_PSUBB128,
19214   IX86_BUILTIN_PSUBW128,
19215   IX86_BUILTIN_PSUBD128,
19216   IX86_BUILTIN_PSUBQ128,
19217   IX86_BUILTIN_PSUBSB128,
19218   IX86_BUILTIN_PSUBSW128,
19219   IX86_BUILTIN_PSUBUSB128,
19220   IX86_BUILTIN_PSUBUSW128,
19221
19222   IX86_BUILTIN_PAND128,
19223   IX86_BUILTIN_PANDN128,
19224   IX86_BUILTIN_POR128,
19225   IX86_BUILTIN_PXOR128,
19226
19227   IX86_BUILTIN_PAVGB128,
19228   IX86_BUILTIN_PAVGW128,
19229
19230   IX86_BUILTIN_PCMPEQB128,
19231   IX86_BUILTIN_PCMPEQW128,
19232   IX86_BUILTIN_PCMPEQD128,
19233   IX86_BUILTIN_PCMPGTB128,
19234   IX86_BUILTIN_PCMPGTW128,
19235   IX86_BUILTIN_PCMPGTD128,
19236
19237   IX86_BUILTIN_PMADDWD128,
19238
19239   IX86_BUILTIN_PMAXSW128,
19240   IX86_BUILTIN_PMAXUB128,
19241   IX86_BUILTIN_PMINSW128,
19242   IX86_BUILTIN_PMINUB128,
19243
19244   IX86_BUILTIN_PMULUDQ,
19245   IX86_BUILTIN_PMULUDQ128,
19246   IX86_BUILTIN_PMULHUW128,
19247   IX86_BUILTIN_PMULHW128,
19248   IX86_BUILTIN_PMULLW128,
19249
19250   IX86_BUILTIN_PSADBW128,
19251   IX86_BUILTIN_PSHUFHW,
19252   IX86_BUILTIN_PSHUFLW,
19253   IX86_BUILTIN_PSHUFD,
19254
19255   IX86_BUILTIN_PSLLDQI128,
19256   IX86_BUILTIN_PSLLWI128,
19257   IX86_BUILTIN_PSLLDI128,
19258   IX86_BUILTIN_PSLLQI128,
19259   IX86_BUILTIN_PSRAWI128,
19260   IX86_BUILTIN_PSRADI128,
19261   IX86_BUILTIN_PSRLDQI128,
19262   IX86_BUILTIN_PSRLWI128,
19263   IX86_BUILTIN_PSRLDI128,
19264   IX86_BUILTIN_PSRLQI128,
19265
19266   IX86_BUILTIN_PSLLDQ128,
19267   IX86_BUILTIN_PSLLW128,
19268   IX86_BUILTIN_PSLLD128,
19269   IX86_BUILTIN_PSLLQ128,
19270   IX86_BUILTIN_PSRAW128,
19271   IX86_BUILTIN_PSRAD128,
19272   IX86_BUILTIN_PSRLW128,
19273   IX86_BUILTIN_PSRLD128,
19274   IX86_BUILTIN_PSRLQ128,
19275
19276   IX86_BUILTIN_PUNPCKHBW128,
19277   IX86_BUILTIN_PUNPCKHWD128,
19278   IX86_BUILTIN_PUNPCKHDQ128,
19279   IX86_BUILTIN_PUNPCKHQDQ128,
19280   IX86_BUILTIN_PUNPCKLBW128,
19281   IX86_BUILTIN_PUNPCKLWD128,
19282   IX86_BUILTIN_PUNPCKLDQ128,
19283   IX86_BUILTIN_PUNPCKLQDQ128,
19284
19285   IX86_BUILTIN_CLFLUSH,
19286   IX86_BUILTIN_MFENCE,
19287   IX86_BUILTIN_LFENCE,
19288
19289   /* SSE3.  */
19290   IX86_BUILTIN_ADDSUBPS,
19291   IX86_BUILTIN_HADDPS,
19292   IX86_BUILTIN_HSUBPS,
19293   IX86_BUILTIN_MOVSHDUP,
19294   IX86_BUILTIN_MOVSLDUP,
19295   IX86_BUILTIN_ADDSUBPD,
19296   IX86_BUILTIN_HADDPD,
19297   IX86_BUILTIN_HSUBPD,
19298   IX86_BUILTIN_LDDQU,
19299
19300   IX86_BUILTIN_MONITOR,
19301   IX86_BUILTIN_MWAIT,
19302
19303   /* SSSE3.  */
19304   IX86_BUILTIN_PHADDW,
19305   IX86_BUILTIN_PHADDD,
19306   IX86_BUILTIN_PHADDSW,
19307   IX86_BUILTIN_PHSUBW,
19308   IX86_BUILTIN_PHSUBD,
19309   IX86_BUILTIN_PHSUBSW,
19310   IX86_BUILTIN_PMADDUBSW,
19311   IX86_BUILTIN_PMULHRSW,
19312   IX86_BUILTIN_PSHUFB,
19313   IX86_BUILTIN_PSIGNB,
19314   IX86_BUILTIN_PSIGNW,
19315   IX86_BUILTIN_PSIGND,
19316   IX86_BUILTIN_PALIGNR,
19317   IX86_BUILTIN_PABSB,
19318   IX86_BUILTIN_PABSW,
19319   IX86_BUILTIN_PABSD,
19320
19321   IX86_BUILTIN_PHADDW128,
19322   IX86_BUILTIN_PHADDD128,
19323   IX86_BUILTIN_PHADDSW128,
19324   IX86_BUILTIN_PHSUBW128,
19325   IX86_BUILTIN_PHSUBD128,
19326   IX86_BUILTIN_PHSUBSW128,
19327   IX86_BUILTIN_PMADDUBSW128,
19328   IX86_BUILTIN_PMULHRSW128,
19329   IX86_BUILTIN_PSHUFB128,
19330   IX86_BUILTIN_PSIGNB128,
19331   IX86_BUILTIN_PSIGNW128,
19332   IX86_BUILTIN_PSIGND128,
19333   IX86_BUILTIN_PALIGNR128,
19334   IX86_BUILTIN_PABSB128,
19335   IX86_BUILTIN_PABSW128,
19336   IX86_BUILTIN_PABSD128,
19337
19338   /* AMDFAM10 - SSE4A New Instructions.  */
19339   IX86_BUILTIN_MOVNTSD,
19340   IX86_BUILTIN_MOVNTSS,
19341   IX86_BUILTIN_EXTRQI,
19342   IX86_BUILTIN_EXTRQ,
19343   IX86_BUILTIN_INSERTQI,
19344   IX86_BUILTIN_INSERTQ,
19345
19346   /* SSE4.1.  */
19347   IX86_BUILTIN_BLENDPD,
19348   IX86_BUILTIN_BLENDPS,
19349   IX86_BUILTIN_BLENDVPD,
19350   IX86_BUILTIN_BLENDVPS,
19351   IX86_BUILTIN_PBLENDVB128,
19352   IX86_BUILTIN_PBLENDW128,
19353
19354   IX86_BUILTIN_DPPD,
19355   IX86_BUILTIN_DPPS,
19356
19357   IX86_BUILTIN_INSERTPS128,
19358
19359   IX86_BUILTIN_MOVNTDQA,
19360   IX86_BUILTIN_MPSADBW128,
19361   IX86_BUILTIN_PACKUSDW128,
19362   IX86_BUILTIN_PCMPEQQ,
19363   IX86_BUILTIN_PHMINPOSUW128,
19364
19365   IX86_BUILTIN_PMAXSB128,
19366   IX86_BUILTIN_PMAXSD128,
19367   IX86_BUILTIN_PMAXUD128,
19368   IX86_BUILTIN_PMAXUW128,
19369
19370   IX86_BUILTIN_PMINSB128,
19371   IX86_BUILTIN_PMINSD128,
19372   IX86_BUILTIN_PMINUD128,
19373   IX86_BUILTIN_PMINUW128,
19374
19375   IX86_BUILTIN_PMOVSXBW128,
19376   IX86_BUILTIN_PMOVSXBD128,
19377   IX86_BUILTIN_PMOVSXBQ128,
19378   IX86_BUILTIN_PMOVSXWD128,
19379   IX86_BUILTIN_PMOVSXWQ128,
19380   IX86_BUILTIN_PMOVSXDQ128,
19381
19382   IX86_BUILTIN_PMOVZXBW128,
19383   IX86_BUILTIN_PMOVZXBD128,
19384   IX86_BUILTIN_PMOVZXBQ128,
19385   IX86_BUILTIN_PMOVZXWD128,
19386   IX86_BUILTIN_PMOVZXWQ128,
19387   IX86_BUILTIN_PMOVZXDQ128,
19388
19389   IX86_BUILTIN_PMULDQ128,
19390   IX86_BUILTIN_PMULLD128,
19391
19392   IX86_BUILTIN_ROUNDPD,
19393   IX86_BUILTIN_ROUNDPS,
19394   IX86_BUILTIN_ROUNDSD,
19395   IX86_BUILTIN_ROUNDSS,
19396
19397   IX86_BUILTIN_PTESTZ,
19398   IX86_BUILTIN_PTESTC,
19399   IX86_BUILTIN_PTESTNZC,
19400
19401   IX86_BUILTIN_VEC_INIT_V2SI,
19402   IX86_BUILTIN_VEC_INIT_V4HI,
19403   IX86_BUILTIN_VEC_INIT_V8QI,
19404   IX86_BUILTIN_VEC_EXT_V2DF,
19405   IX86_BUILTIN_VEC_EXT_V2DI,
19406   IX86_BUILTIN_VEC_EXT_V4SF,
19407   IX86_BUILTIN_VEC_EXT_V4SI,
19408   IX86_BUILTIN_VEC_EXT_V8HI,
19409   IX86_BUILTIN_VEC_EXT_V2SI,
19410   IX86_BUILTIN_VEC_EXT_V4HI,
19411   IX86_BUILTIN_VEC_EXT_V16QI,
19412   IX86_BUILTIN_VEC_SET_V2DI,
19413   IX86_BUILTIN_VEC_SET_V4SF,
19414   IX86_BUILTIN_VEC_SET_V4SI,
19415   IX86_BUILTIN_VEC_SET_V8HI,
19416   IX86_BUILTIN_VEC_SET_V4HI,
19417   IX86_BUILTIN_VEC_SET_V16QI,
19418
19419   IX86_BUILTIN_VEC_PACK_SFIX,
19420
19421   /* SSE4.2.  */
19422   IX86_BUILTIN_CRC32QI,
19423   IX86_BUILTIN_CRC32HI,
19424   IX86_BUILTIN_CRC32SI,
19425   IX86_BUILTIN_CRC32DI,
19426
19427   IX86_BUILTIN_PCMPESTRI128,
19428   IX86_BUILTIN_PCMPESTRM128,
19429   IX86_BUILTIN_PCMPESTRA128,
19430   IX86_BUILTIN_PCMPESTRC128,
19431   IX86_BUILTIN_PCMPESTRO128,
19432   IX86_BUILTIN_PCMPESTRS128,
19433   IX86_BUILTIN_PCMPESTRZ128,
19434   IX86_BUILTIN_PCMPISTRI128,
19435   IX86_BUILTIN_PCMPISTRM128,
19436   IX86_BUILTIN_PCMPISTRA128,
19437   IX86_BUILTIN_PCMPISTRC128,
19438   IX86_BUILTIN_PCMPISTRO128,
19439   IX86_BUILTIN_PCMPISTRS128,
19440   IX86_BUILTIN_PCMPISTRZ128,
19441
19442   IX86_BUILTIN_PCMPGTQ,
19443
19444   /* AES instructions */
19445   IX86_BUILTIN_AESENC128,
19446   IX86_BUILTIN_AESENCLAST128,
19447   IX86_BUILTIN_AESDEC128,
19448   IX86_BUILTIN_AESDECLAST128,
19449   IX86_BUILTIN_AESIMC128,
19450   IX86_BUILTIN_AESKEYGENASSIST128,
19451
19452   /* PCLMUL instruction */
19453   IX86_BUILTIN_PCLMULQDQ128,
19454
19455   /* AVX */
19456   IX86_BUILTIN_ADDPD256,
19457   IX86_BUILTIN_ADDPS256,
19458   IX86_BUILTIN_ADDSUBPD256,
19459   IX86_BUILTIN_ADDSUBPS256,
19460   IX86_BUILTIN_ANDPD256,
19461   IX86_BUILTIN_ANDPS256,
19462   IX86_BUILTIN_ANDNPD256,
19463   IX86_BUILTIN_ANDNPS256,
19464   IX86_BUILTIN_BLENDPD256,
19465   IX86_BUILTIN_BLENDPS256,
19466   IX86_BUILTIN_BLENDVPD256,
19467   IX86_BUILTIN_BLENDVPS256,
19468   IX86_BUILTIN_DIVPD256,
19469   IX86_BUILTIN_DIVPS256,
19470   IX86_BUILTIN_DPPS256,
19471   IX86_BUILTIN_HADDPD256,
19472   IX86_BUILTIN_HADDPS256,
19473   IX86_BUILTIN_HSUBPD256,
19474   IX86_BUILTIN_HSUBPS256,
19475   IX86_BUILTIN_MAXPD256,
19476   IX86_BUILTIN_MAXPS256,
19477   IX86_BUILTIN_MINPD256,
19478   IX86_BUILTIN_MINPS256,
19479   IX86_BUILTIN_MULPD256,
19480   IX86_BUILTIN_MULPS256,
19481   IX86_BUILTIN_ORPD256,
19482   IX86_BUILTIN_ORPS256,
19483   IX86_BUILTIN_SHUFPD256,
19484   IX86_BUILTIN_SHUFPS256,
19485   IX86_BUILTIN_SUBPD256,
19486   IX86_BUILTIN_SUBPS256,
19487   IX86_BUILTIN_XORPD256,
19488   IX86_BUILTIN_XORPS256,
19489   IX86_BUILTIN_CMPSD,
19490   IX86_BUILTIN_CMPSS,
19491   IX86_BUILTIN_CMPPD,
19492   IX86_BUILTIN_CMPPS,
19493   IX86_BUILTIN_CMPPD256,
19494   IX86_BUILTIN_CMPPS256,
19495   IX86_BUILTIN_CVTDQ2PD256,
19496   IX86_BUILTIN_CVTDQ2PS256,
19497   IX86_BUILTIN_CVTPD2PS256,
19498   IX86_BUILTIN_CVTPS2DQ256,
19499   IX86_BUILTIN_CVTPS2PD256,
19500   IX86_BUILTIN_CVTTPD2DQ256,
19501   IX86_BUILTIN_CVTPD2DQ256,
19502   IX86_BUILTIN_CVTTPS2DQ256,
19503   IX86_BUILTIN_EXTRACTF128PD256,
19504   IX86_BUILTIN_EXTRACTF128PS256,
19505   IX86_BUILTIN_EXTRACTF128SI256,
19506   IX86_BUILTIN_VZEROALL,
19507   IX86_BUILTIN_VZEROUPPER,
19508   IX86_BUILTIN_VZEROUPPER_REX64,
19509   IX86_BUILTIN_VPERMILVARPD,
19510   IX86_BUILTIN_VPERMILVARPS,
19511   IX86_BUILTIN_VPERMILVARPD256,
19512   IX86_BUILTIN_VPERMILVARPS256,
19513   IX86_BUILTIN_VPERMILPD,
19514   IX86_BUILTIN_VPERMILPS,
19515   IX86_BUILTIN_VPERMILPD256,
19516   IX86_BUILTIN_VPERMILPS256,
19517   IX86_BUILTIN_VPERMIL2PD,
19518   IX86_BUILTIN_VPERMIL2PS,
19519   IX86_BUILTIN_VPERMIL2PD256,
19520   IX86_BUILTIN_VPERMIL2PS256,
19521   IX86_BUILTIN_VPERM2F128PD256,
19522   IX86_BUILTIN_VPERM2F128PS256,
19523   IX86_BUILTIN_VPERM2F128SI256,
19524   IX86_BUILTIN_VBROADCASTSS,
19525   IX86_BUILTIN_VBROADCASTSD256,
19526   IX86_BUILTIN_VBROADCASTSS256,
19527   IX86_BUILTIN_VBROADCASTPD256,
19528   IX86_BUILTIN_VBROADCASTPS256,
19529   IX86_BUILTIN_VINSERTF128PD256,
19530   IX86_BUILTIN_VINSERTF128PS256,
19531   IX86_BUILTIN_VINSERTF128SI256,
19532   IX86_BUILTIN_LOADUPD256,
19533   IX86_BUILTIN_LOADUPS256,
19534   IX86_BUILTIN_STOREUPD256,
19535   IX86_BUILTIN_STOREUPS256,
19536   IX86_BUILTIN_LDDQU256,
19537   IX86_BUILTIN_LOADDQU256,
19538   IX86_BUILTIN_STOREDQU256,
19539   IX86_BUILTIN_MASKLOADPD,
19540   IX86_BUILTIN_MASKLOADPS,
19541   IX86_BUILTIN_MASKSTOREPD,
19542   IX86_BUILTIN_MASKSTOREPS,
19543   IX86_BUILTIN_MASKLOADPD256,
19544   IX86_BUILTIN_MASKLOADPS256,
19545   IX86_BUILTIN_MASKSTOREPD256,
19546   IX86_BUILTIN_MASKSTOREPS256,
19547   IX86_BUILTIN_MOVSHDUP256,
19548   IX86_BUILTIN_MOVSLDUP256,
19549   IX86_BUILTIN_MOVDDUP256,
19550
19551   IX86_BUILTIN_SQRTPD256,
19552   IX86_BUILTIN_SQRTPS256,
19553   IX86_BUILTIN_SQRTPS_NR256,
19554   IX86_BUILTIN_RSQRTPS256,
19555   IX86_BUILTIN_RSQRTPS_NR256,
19556
19557   IX86_BUILTIN_RCPPS256,
19558
19559   IX86_BUILTIN_ROUNDPD256,
19560   IX86_BUILTIN_ROUNDPS256,
19561
19562   IX86_BUILTIN_UNPCKHPD256,
19563   IX86_BUILTIN_UNPCKLPD256,
19564   IX86_BUILTIN_UNPCKHPS256,
19565   IX86_BUILTIN_UNPCKLPS256,
19566
19567   IX86_BUILTIN_SI256_SI,
19568   IX86_BUILTIN_PS256_PS,
19569   IX86_BUILTIN_PD256_PD,
19570   IX86_BUILTIN_SI_SI256,
19571   IX86_BUILTIN_PS_PS256,
19572   IX86_BUILTIN_PD_PD256,
19573
19574   IX86_BUILTIN_VTESTZPD,
19575   IX86_BUILTIN_VTESTCPD,
19576   IX86_BUILTIN_VTESTNZCPD,
19577   IX86_BUILTIN_VTESTZPS,
19578   IX86_BUILTIN_VTESTCPS,
19579   IX86_BUILTIN_VTESTNZCPS,
19580   IX86_BUILTIN_VTESTZPD256,
19581   IX86_BUILTIN_VTESTCPD256,
19582   IX86_BUILTIN_VTESTNZCPD256,
19583   IX86_BUILTIN_VTESTZPS256,
19584   IX86_BUILTIN_VTESTCPS256,
19585   IX86_BUILTIN_VTESTNZCPS256,
19586   IX86_BUILTIN_PTESTZ256,
19587   IX86_BUILTIN_PTESTC256,
19588   IX86_BUILTIN_PTESTNZC256,
19589
19590   IX86_BUILTIN_MOVMSKPD256,
19591   IX86_BUILTIN_MOVMSKPS256,
19592
19593   /* TFmode support builtins.  */
19594   IX86_BUILTIN_INFQ,
19595   IX86_BUILTIN_FABSQ,
19596   IX86_BUILTIN_COPYSIGNQ,
19597
19598   /* SSE5 instructions */
19599   IX86_BUILTIN_FMADDSS,
19600   IX86_BUILTIN_FMADDSD,
19601   IX86_BUILTIN_FMADDPS,
19602   IX86_BUILTIN_FMADDPD,
19603   IX86_BUILTIN_FMSUBSS,
19604   IX86_BUILTIN_FMSUBSD,
19605   IX86_BUILTIN_FMSUBPS,
19606   IX86_BUILTIN_FMSUBPD,
19607   IX86_BUILTIN_FNMADDSS,
19608   IX86_BUILTIN_FNMADDSD,
19609   IX86_BUILTIN_FNMADDPS,
19610   IX86_BUILTIN_FNMADDPD,
19611   IX86_BUILTIN_FNMSUBSS,
19612   IX86_BUILTIN_FNMSUBSD,
19613   IX86_BUILTIN_FNMSUBPS,
19614   IX86_BUILTIN_FNMSUBPD,
19615   IX86_BUILTIN_PCMOV,
19616   IX86_BUILTIN_PCMOV_V2DI,
19617   IX86_BUILTIN_PCMOV_V4SI,
19618   IX86_BUILTIN_PCMOV_V8HI,
19619   IX86_BUILTIN_PCMOV_V16QI,
19620   IX86_BUILTIN_PCMOV_V4SF,
19621   IX86_BUILTIN_PCMOV_V2DF,
19622   IX86_BUILTIN_PPERM,
19623   IX86_BUILTIN_PERMPS,
19624   IX86_BUILTIN_PERMPD,
19625   IX86_BUILTIN_PMACSSWW,
19626   IX86_BUILTIN_PMACSWW,
19627   IX86_BUILTIN_PMACSSWD,
19628   IX86_BUILTIN_PMACSWD,
19629   IX86_BUILTIN_PMACSSDD,
19630   IX86_BUILTIN_PMACSDD,
19631   IX86_BUILTIN_PMACSSDQL,
19632   IX86_BUILTIN_PMACSSDQH,
19633   IX86_BUILTIN_PMACSDQL,
19634   IX86_BUILTIN_PMACSDQH,
19635   IX86_BUILTIN_PMADCSSWD,
19636   IX86_BUILTIN_PMADCSWD,
19637   IX86_BUILTIN_PHADDBW,
19638   IX86_BUILTIN_PHADDBD,
19639   IX86_BUILTIN_PHADDBQ,
19640   IX86_BUILTIN_PHADDWD,
19641   IX86_BUILTIN_PHADDWQ,
19642   IX86_BUILTIN_PHADDDQ,
19643   IX86_BUILTIN_PHADDUBW,
19644   IX86_BUILTIN_PHADDUBD,
19645   IX86_BUILTIN_PHADDUBQ,
19646   IX86_BUILTIN_PHADDUWD,
19647   IX86_BUILTIN_PHADDUWQ,
19648   IX86_BUILTIN_PHADDUDQ,
19649   IX86_BUILTIN_PHSUBBW,
19650   IX86_BUILTIN_PHSUBWD,
19651   IX86_BUILTIN_PHSUBDQ,
19652   IX86_BUILTIN_PROTB,
19653   IX86_BUILTIN_PROTW,
19654   IX86_BUILTIN_PROTD,
19655   IX86_BUILTIN_PROTQ,
19656   IX86_BUILTIN_PROTB_IMM,
19657   IX86_BUILTIN_PROTW_IMM,
19658   IX86_BUILTIN_PROTD_IMM,
19659   IX86_BUILTIN_PROTQ_IMM,
19660   IX86_BUILTIN_PSHLB,
19661   IX86_BUILTIN_PSHLW,
19662   IX86_BUILTIN_PSHLD,
19663   IX86_BUILTIN_PSHLQ,
19664   IX86_BUILTIN_PSHAB,
19665   IX86_BUILTIN_PSHAW,
19666   IX86_BUILTIN_PSHAD,
19667   IX86_BUILTIN_PSHAQ,
19668   IX86_BUILTIN_FRCZSS,
19669   IX86_BUILTIN_FRCZSD,
19670   IX86_BUILTIN_FRCZPS,
19671   IX86_BUILTIN_FRCZPD,
19672   IX86_BUILTIN_CVTPH2PS,
19673   IX86_BUILTIN_CVTPS2PH,
19674
19675   IX86_BUILTIN_COMEQSS,
19676   IX86_BUILTIN_COMNESS,
19677   IX86_BUILTIN_COMLTSS,
19678   IX86_BUILTIN_COMLESS,
19679   IX86_BUILTIN_COMGTSS,
19680   IX86_BUILTIN_COMGESS,
19681   IX86_BUILTIN_COMUEQSS,
19682   IX86_BUILTIN_COMUNESS,
19683   IX86_BUILTIN_COMULTSS,
19684   IX86_BUILTIN_COMULESS,
19685   IX86_BUILTIN_COMUGTSS,
19686   IX86_BUILTIN_COMUGESS,
19687   IX86_BUILTIN_COMORDSS,
19688   IX86_BUILTIN_COMUNORDSS,
19689   IX86_BUILTIN_COMFALSESS,
19690   IX86_BUILTIN_COMTRUESS,
19691
19692   IX86_BUILTIN_COMEQSD,
19693   IX86_BUILTIN_COMNESD,
19694   IX86_BUILTIN_COMLTSD,
19695   IX86_BUILTIN_COMLESD,
19696   IX86_BUILTIN_COMGTSD,
19697   IX86_BUILTIN_COMGESD,
19698   IX86_BUILTIN_COMUEQSD,
19699   IX86_BUILTIN_COMUNESD,
19700   IX86_BUILTIN_COMULTSD,
19701   IX86_BUILTIN_COMULESD,
19702   IX86_BUILTIN_COMUGTSD,
19703   IX86_BUILTIN_COMUGESD,
19704   IX86_BUILTIN_COMORDSD,
19705   IX86_BUILTIN_COMUNORDSD,
19706   IX86_BUILTIN_COMFALSESD,
19707   IX86_BUILTIN_COMTRUESD,
19708
19709   IX86_BUILTIN_COMEQPS,
19710   IX86_BUILTIN_COMNEPS,
19711   IX86_BUILTIN_COMLTPS,
19712   IX86_BUILTIN_COMLEPS,
19713   IX86_BUILTIN_COMGTPS,
19714   IX86_BUILTIN_COMGEPS,
19715   IX86_BUILTIN_COMUEQPS,
19716   IX86_BUILTIN_COMUNEPS,
19717   IX86_BUILTIN_COMULTPS,
19718   IX86_BUILTIN_COMULEPS,
19719   IX86_BUILTIN_COMUGTPS,
19720   IX86_BUILTIN_COMUGEPS,
19721   IX86_BUILTIN_COMORDPS,
19722   IX86_BUILTIN_COMUNORDPS,
19723   IX86_BUILTIN_COMFALSEPS,
19724   IX86_BUILTIN_COMTRUEPS,
19725
19726   IX86_BUILTIN_COMEQPD,
19727   IX86_BUILTIN_COMNEPD,
19728   IX86_BUILTIN_COMLTPD,
19729   IX86_BUILTIN_COMLEPD,
19730   IX86_BUILTIN_COMGTPD,
19731   IX86_BUILTIN_COMGEPD,
19732   IX86_BUILTIN_COMUEQPD,
19733   IX86_BUILTIN_COMUNEPD,
19734   IX86_BUILTIN_COMULTPD,
19735   IX86_BUILTIN_COMULEPD,
19736   IX86_BUILTIN_COMUGTPD,
19737   IX86_BUILTIN_COMUGEPD,
19738   IX86_BUILTIN_COMORDPD,
19739   IX86_BUILTIN_COMUNORDPD,
19740   IX86_BUILTIN_COMFALSEPD,
19741   IX86_BUILTIN_COMTRUEPD,
19742
19743   IX86_BUILTIN_PCOMEQUB,
19744   IX86_BUILTIN_PCOMNEUB,
19745   IX86_BUILTIN_PCOMLTUB,
19746   IX86_BUILTIN_PCOMLEUB,
19747   IX86_BUILTIN_PCOMGTUB,
19748   IX86_BUILTIN_PCOMGEUB,
19749   IX86_BUILTIN_PCOMFALSEUB,
19750   IX86_BUILTIN_PCOMTRUEUB,
19751   IX86_BUILTIN_PCOMEQUW,
19752   IX86_BUILTIN_PCOMNEUW,
19753   IX86_BUILTIN_PCOMLTUW,
19754   IX86_BUILTIN_PCOMLEUW,
19755   IX86_BUILTIN_PCOMGTUW,
19756   IX86_BUILTIN_PCOMGEUW,
19757   IX86_BUILTIN_PCOMFALSEUW,
19758   IX86_BUILTIN_PCOMTRUEUW,
19759   IX86_BUILTIN_PCOMEQUD,
19760   IX86_BUILTIN_PCOMNEUD,
19761   IX86_BUILTIN_PCOMLTUD,
19762   IX86_BUILTIN_PCOMLEUD,
19763   IX86_BUILTIN_PCOMGTUD,
19764   IX86_BUILTIN_PCOMGEUD,
19765   IX86_BUILTIN_PCOMFALSEUD,
19766   IX86_BUILTIN_PCOMTRUEUD,
19767   IX86_BUILTIN_PCOMEQUQ,
19768   IX86_BUILTIN_PCOMNEUQ,
19769   IX86_BUILTIN_PCOMLTUQ,
19770   IX86_BUILTIN_PCOMLEUQ,
19771   IX86_BUILTIN_PCOMGTUQ,
19772   IX86_BUILTIN_PCOMGEUQ,
19773   IX86_BUILTIN_PCOMFALSEUQ,
19774   IX86_BUILTIN_PCOMTRUEUQ,
19775
19776   IX86_BUILTIN_PCOMEQB,
19777   IX86_BUILTIN_PCOMNEB,
19778   IX86_BUILTIN_PCOMLTB,
19779   IX86_BUILTIN_PCOMLEB,
19780   IX86_BUILTIN_PCOMGTB,
19781   IX86_BUILTIN_PCOMGEB,
19782   IX86_BUILTIN_PCOMFALSEB,
19783   IX86_BUILTIN_PCOMTRUEB,
19784   IX86_BUILTIN_PCOMEQW,
19785   IX86_BUILTIN_PCOMNEW,
19786   IX86_BUILTIN_PCOMLTW,
19787   IX86_BUILTIN_PCOMLEW,
19788   IX86_BUILTIN_PCOMGTW,
19789   IX86_BUILTIN_PCOMGEW,
19790   IX86_BUILTIN_PCOMFALSEW,
19791   IX86_BUILTIN_PCOMTRUEW,
19792   IX86_BUILTIN_PCOMEQD,
19793   IX86_BUILTIN_PCOMNED,
19794   IX86_BUILTIN_PCOMLTD,
19795   IX86_BUILTIN_PCOMLED,
19796   IX86_BUILTIN_PCOMGTD,
19797   IX86_BUILTIN_PCOMGED,
19798   IX86_BUILTIN_PCOMFALSED,
19799   IX86_BUILTIN_PCOMTRUED,
19800   IX86_BUILTIN_PCOMEQQ,
19801   IX86_BUILTIN_PCOMNEQ,
19802   IX86_BUILTIN_PCOMLTQ,
19803   IX86_BUILTIN_PCOMLEQ,
19804   IX86_BUILTIN_PCOMGTQ,
19805   IX86_BUILTIN_PCOMGEQ,
19806   IX86_BUILTIN_PCOMFALSEQ,
19807   IX86_BUILTIN_PCOMTRUEQ,
19808
19809   IX86_BUILTIN_MAX
19810 };
19811
19812 /* Table for the ix86 builtin decls.  */
19813 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
19814
19815 /* Table of all of the builtin functions that are possible with different ISA's
19816    but are waiting to be built until a function is declared to use that
19817    ISA.  */
19818 struct builtin_isa GTY(())
19819 {
19820   tree type;                    /* builtin type to use in the declaration */
19821   const char *name;             /* function name */
19822   int isa;                      /* isa_flags this builtin is defined for */
19823   bool const_p;                 /* true if the declaration is constant */
19824 };
19825
19826 static GTY(()) struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
19827
19828
19829 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
19830  * of which isa_flags to use in the ix86_builtins_isa array.  Stores the
19831  * function decl in the ix86_builtins array.  Returns the function decl or
19832  * NULL_TREE, if the builtin was not added.
19833  *
19834  * If the front end has a special hook for builtin functions, delay adding
19835  * builtin functions that aren't in the current ISA until the ISA is changed
19836  * with function specific optimization.  Doing so, can save about 300K for the
19837  * default compiler.  When the builtin is expanded, check at that time whether
19838  * it is valid.
19839  *
19840  * If the front end doesn't have a special hook, record all builtins, even if
19841  * it isn't an instruction set in the current ISA in case the user uses
19842  * function specific options for a different ISA, so that we don't get scope
19843  * errors if a builtin is added in the middle of a function scope.  */
19844
19845 static inline tree
19846 def_builtin (int mask, const char *name, tree type, enum ix86_builtins code)
19847 {
19848   tree decl = NULL_TREE;
19849
19850   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
19851     {
19852       ix86_builtins_isa[(int) code].isa = mask;
19853
19854       if ((mask & ix86_isa_flags) != 0
19855           || (lang_hooks.builtin_function
19856               == lang_hooks.builtin_function_ext_scope))
19857
19858         {
19859           decl = add_builtin_function (name, type, code, BUILT_IN_MD, NULL,
19860                                        NULL_TREE);
19861           ix86_builtins[(int) code] = decl;
19862           ix86_builtins_isa[(int) code].type = NULL_TREE;
19863         }
19864       else
19865         {
19866           ix86_builtins[(int) code] = NULL_TREE;
19867           ix86_builtins_isa[(int) code].const_p = false;
19868           ix86_builtins_isa[(int) code].type = type;
19869           ix86_builtins_isa[(int) code].name = name;
19870         }
19871     }
19872
19873   return decl;
19874 }
19875
19876 /* Like def_builtin, but also marks the function decl "const".  */
19877
19878 static inline tree
19879 def_builtin_const (int mask, const char *name, tree type,
19880                    enum ix86_builtins code)
19881 {
19882   tree decl = def_builtin (mask, name, type, code);
19883   if (decl)
19884     TREE_READONLY (decl) = 1;
19885   else
19886     ix86_builtins_isa[(int) code].const_p = true;
19887
19888   return decl;
19889 }
19890
19891 /* Add any new builtin functions for a given ISA that may not have been
19892    declared.  This saves a bit of space compared to adding all of the
19893    declarations to the tree, even if we didn't use them.  */
19894
19895 static void
19896 ix86_add_new_builtins (int isa)
19897 {
19898   int i;
19899   tree decl;
19900
19901   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
19902     {
19903       if ((ix86_builtins_isa[i].isa & isa) != 0
19904           && ix86_builtins_isa[i].type != NULL_TREE)
19905         {
19906           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
19907                                                  ix86_builtins_isa[i].type,
19908                                                  i, BUILT_IN_MD, NULL,
19909                                                  NULL_TREE);
19910
19911           ix86_builtins[i] = decl;
19912           ix86_builtins_isa[i].type = NULL_TREE;
19913           if (ix86_builtins_isa[i].const_p)
19914             TREE_READONLY (decl) = 1;
19915         }
19916     }
19917 }
19918
19919 /* Bits for builtin_description.flag.  */
19920
19921 /* Set when we don't support the comparison natively, and should
19922    swap_comparison in order to support it.  */
19923 #define BUILTIN_DESC_SWAP_OPERANDS      1
19924
19925 struct builtin_description
19926 {
19927   const unsigned int mask;
19928   const enum insn_code icode;
19929   const char *const name;
19930   const enum ix86_builtins code;
19931   const enum rtx_code comparison;
19932   const int flag;
19933 };
19934
19935 static const struct builtin_description bdesc_comi[] =
19936 {
19937   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
19938   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
19939   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
19940   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
19941   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
19942   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
19943   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
19944   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
19945   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
19946   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
19947   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
19948   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
19949   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
19950   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
19951   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
19952   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
19953   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
19954   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
19955   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
19956   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
19957   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
19958   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
19959   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
19960   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
19961 };
19962
19963 static const struct builtin_description bdesc_pcmpestr[] =
19964 {
19965   /* SSE4.2 */
19966   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
19967   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
19968   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
19969   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
19970   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
19971   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
19972   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
19973 };
19974
19975 static const struct builtin_description bdesc_pcmpistr[] =
19976 {
19977   /* SSE4.2 */
19978   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
19979   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
19980   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
19981   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
19982   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
19983   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
19984   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
19985 };
19986
19987 /* Special builtin types */
19988 enum ix86_special_builtin_type
19989 {
19990   SPECIAL_FTYPE_UNKNOWN,
19991   VOID_FTYPE_VOID,
19992   V32QI_FTYPE_PCCHAR,
19993   V16QI_FTYPE_PCCHAR,
19994   V8SF_FTYPE_PCV4SF,
19995   V8SF_FTYPE_PCFLOAT,
19996   V4DF_FTYPE_PCV2DF,
19997   V4DF_FTYPE_PCDOUBLE,
19998   V4SF_FTYPE_PCFLOAT,
19999   V2DF_FTYPE_PCDOUBLE,
20000   V8SF_FTYPE_PCV8SF_V8SF,
20001   V4DF_FTYPE_PCV4DF_V4DF,
20002   V4SF_FTYPE_V4SF_PCV2SF,
20003   V4SF_FTYPE_PCV4SF_V4SF,
20004   V2DF_FTYPE_V2DF_PCDOUBLE,
20005   V2DF_FTYPE_PCV2DF_V2DF,
20006   V2DI_FTYPE_PV2DI,
20007   VOID_FTYPE_PV2SF_V4SF,
20008   VOID_FTYPE_PV2DI_V2DI,
20009   VOID_FTYPE_PCHAR_V32QI,
20010   VOID_FTYPE_PCHAR_V16QI,
20011   VOID_FTYPE_PFLOAT_V8SF,
20012   VOID_FTYPE_PFLOAT_V4SF,
20013   VOID_FTYPE_PDOUBLE_V4DF,
20014   VOID_FTYPE_PDOUBLE_V2DF,
20015   VOID_FTYPE_PDI_DI,
20016   VOID_FTYPE_PINT_INT,
20017   VOID_FTYPE_PV8SF_V8SF_V8SF,
20018   VOID_FTYPE_PV4DF_V4DF_V4DF,
20019   VOID_FTYPE_PV4SF_V4SF_V4SF,
20020   VOID_FTYPE_PV2DF_V2DF_V2DF
20021 };
20022
20023 /* Builtin types */
20024 enum ix86_builtin_type
20025 {
20026   FTYPE_UNKNOWN,
20027   FLOAT128_FTYPE_FLOAT128,
20028   FLOAT_FTYPE_FLOAT,
20029   FLOAT128_FTYPE_FLOAT128_FLOAT128,
20030   INT_FTYPE_V8SF_V8SF_PTEST,
20031   INT_FTYPE_V4DI_V4DI_PTEST,
20032   INT_FTYPE_V4DF_V4DF_PTEST,
20033   INT_FTYPE_V4SF_V4SF_PTEST,
20034   INT_FTYPE_V2DI_V2DI_PTEST,
20035   INT_FTYPE_V2DF_V2DF_PTEST,
20036   INT64_FTYPE_V4SF,
20037   INT64_FTYPE_V2DF,
20038   INT_FTYPE_V16QI,
20039   INT_FTYPE_V8QI,
20040   INT_FTYPE_V8SF,
20041   INT_FTYPE_V4DF,
20042   INT_FTYPE_V4SF,
20043   INT_FTYPE_V2DF,
20044   V16QI_FTYPE_V16QI,
20045   V8SI_FTYPE_V8SF,
20046   V8SI_FTYPE_V4SI,
20047   V8HI_FTYPE_V8HI,
20048   V8HI_FTYPE_V16QI,
20049   V8QI_FTYPE_V8QI,
20050   V8SF_FTYPE_V8SF,
20051   V8SF_FTYPE_V8SI,
20052   V8SF_FTYPE_V4SF,
20053   V4SI_FTYPE_V4SI,
20054   V4SI_FTYPE_V16QI,
20055   V4SI_FTYPE_V8SI,
20056   V4SI_FTYPE_V8HI,
20057   V4SI_FTYPE_V4DF,
20058   V4SI_FTYPE_V4SF,
20059   V4SI_FTYPE_V2DF,
20060   V4HI_FTYPE_V4HI,
20061   V4DF_FTYPE_V4DF,
20062   V4DF_FTYPE_V4SI,
20063   V4DF_FTYPE_V4SF,
20064   V4DF_FTYPE_V2DF,
20065   V4SF_FTYPE_V4DF,
20066   V4SF_FTYPE_V4SF,
20067   V4SF_FTYPE_V4SF_VEC_MERGE,
20068   V4SF_FTYPE_V8SF,
20069   V4SF_FTYPE_V4SI,
20070   V4SF_FTYPE_V2DF,
20071   V2DI_FTYPE_V2DI,
20072   V2DI_FTYPE_V16QI,
20073   V2DI_FTYPE_V8HI,
20074   V2DI_FTYPE_V4SI,
20075   V2DF_FTYPE_V2DF,
20076   V2DF_FTYPE_V2DF_VEC_MERGE,
20077   V2DF_FTYPE_V4SI,
20078   V2DF_FTYPE_V4DF,
20079   V2DF_FTYPE_V4SF,
20080   V2DF_FTYPE_V2SI,
20081   V2SI_FTYPE_V2SI,
20082   V2SI_FTYPE_V4SF,
20083   V2SI_FTYPE_V2SF,
20084   V2SI_FTYPE_V2DF,
20085   V2SF_FTYPE_V2SF,
20086   V2SF_FTYPE_V2SI,
20087   V16QI_FTYPE_V16QI_V16QI,
20088   V16QI_FTYPE_V8HI_V8HI,
20089   V8QI_FTYPE_V8QI_V8QI,
20090   V8QI_FTYPE_V4HI_V4HI,
20091   V8HI_FTYPE_V8HI_V8HI,
20092   V8HI_FTYPE_V8HI_V8HI_COUNT,
20093   V8HI_FTYPE_V16QI_V16QI,
20094   V8HI_FTYPE_V4SI_V4SI,
20095   V8HI_FTYPE_V8HI_SI_COUNT,
20096   V8SF_FTYPE_V8SF_V8SF,
20097   V8SF_FTYPE_V8SF_V8SI,
20098   V4SI_FTYPE_V4SI_V4SI,
20099   V4SI_FTYPE_V4SI_V4SI_COUNT,
20100   V4SI_FTYPE_V8HI_V8HI,
20101   V4SI_FTYPE_V4SF_V4SF,
20102   V4SI_FTYPE_V2DF_V2DF,
20103   V4SI_FTYPE_V4SI_SI_COUNT,
20104   V4HI_FTYPE_V4HI_V4HI,
20105   V4HI_FTYPE_V4HI_V4HI_COUNT,
20106   V4HI_FTYPE_V8QI_V8QI,
20107   V4HI_FTYPE_V2SI_V2SI,
20108   V4HI_FTYPE_V4HI_SI_COUNT,
20109   V4DF_FTYPE_V4DF_V4DF,
20110   V4DF_FTYPE_V4DF_V4DI,
20111   V4SF_FTYPE_V4SF_V4SF,
20112   V4SF_FTYPE_V4SF_V4SF_SWAP,
20113   V4SF_FTYPE_V4SF_V4SI,
20114   V4SF_FTYPE_V4SF_V2SI,
20115   V4SF_FTYPE_V4SF_V2DF,
20116   V4SF_FTYPE_V4SF_DI,
20117   V4SF_FTYPE_V4SF_SI,
20118   V2DI_FTYPE_V2DI_V2DI,
20119   V2DI_FTYPE_V2DI_V2DI_COUNT,
20120   V2DI_FTYPE_V16QI_V16QI,
20121   V2DI_FTYPE_V4SI_V4SI,
20122   V2DI_FTYPE_V2DI_V16QI,
20123   V2DI_FTYPE_V2DF_V2DF,
20124   V2DI_FTYPE_V2DI_SI_COUNT,
20125   V2SI_FTYPE_V2SI_V2SI,
20126   V2SI_FTYPE_V2SI_V2SI_COUNT,
20127   V2SI_FTYPE_V4HI_V4HI,
20128   V2SI_FTYPE_V2SF_V2SF,
20129   V2SI_FTYPE_V2SI_SI_COUNT,
20130   V2DF_FTYPE_V2DF_V2DF,
20131   V2DF_FTYPE_V2DF_V2DF_SWAP,
20132   V2DF_FTYPE_V2DF_V4SF,
20133   V2DF_FTYPE_V2DF_V2DI,
20134   V2DF_FTYPE_V2DF_DI,
20135   V2DF_FTYPE_V2DF_SI,
20136   V2SF_FTYPE_V2SF_V2SF,
20137   V1DI_FTYPE_V1DI_V1DI,
20138   V1DI_FTYPE_V1DI_V1DI_COUNT,
20139   V1DI_FTYPE_V8QI_V8QI,
20140   V1DI_FTYPE_V2SI_V2SI,
20141   V1DI_FTYPE_V1DI_SI_COUNT,
20142   UINT64_FTYPE_UINT64_UINT64,
20143   UINT_FTYPE_UINT_UINT,
20144   UINT_FTYPE_UINT_USHORT,
20145   UINT_FTYPE_UINT_UCHAR,
20146   V8HI_FTYPE_V8HI_INT,
20147   V4SI_FTYPE_V4SI_INT,
20148   V4HI_FTYPE_V4HI_INT,
20149   V8SF_FTYPE_V8SF_INT,
20150   V4SI_FTYPE_V8SI_INT,
20151   V4SF_FTYPE_V8SF_INT,
20152   V2DF_FTYPE_V4DF_INT,
20153   V4DF_FTYPE_V4DF_INT,
20154   V4SF_FTYPE_V4SF_INT,
20155   V2DI_FTYPE_V2DI_INT,
20156   V2DI2TI_FTYPE_V2DI_INT,
20157   V2DF_FTYPE_V2DF_INT,
20158   V16QI_FTYPE_V16QI_V16QI_V16QI,
20159   V8SF_FTYPE_V8SF_V8SF_V8SF,
20160   V4DF_FTYPE_V4DF_V4DF_V4DF,
20161   V4SF_FTYPE_V4SF_V4SF_V4SF,
20162   V2DF_FTYPE_V2DF_V2DF_V2DF,
20163   V16QI_FTYPE_V16QI_V16QI_INT,
20164   V8SI_FTYPE_V8SI_V8SI_INT,
20165   V8SI_FTYPE_V8SI_V4SI_INT,
20166   V8HI_FTYPE_V8HI_V8HI_INT,
20167   V8SF_FTYPE_V8SF_V8SF_INT,
20168   V8SF_FTYPE_V8SF_V4SF_INT,
20169   V4SI_FTYPE_V4SI_V4SI_INT,
20170   V4DF_FTYPE_V4DF_V4DF_INT,
20171   V4DF_FTYPE_V4DF_V2DF_INT,
20172   V4SF_FTYPE_V4SF_V4SF_INT,
20173   V2DI_FTYPE_V2DI_V2DI_INT,
20174   V2DI2TI_FTYPE_V2DI_V2DI_INT,
20175   V1DI2DI_FTYPE_V1DI_V1DI_INT,
20176   V2DF_FTYPE_V2DF_V2DF_INT,
20177   V8SF_FTYPE_V8SF_V8SF_V8SI_INT,
20178   V4DF_FTYPE_V4DF_V4DF_V4DI_INT,
20179   V4SF_FTYPE_V4SF_V4SF_V4SI_INT,
20180   V2DF_FTYPE_V2DF_V2DF_V2DI_INT,
20181   V2DI_FTYPE_V2DI_UINT_UINT,
20182   V2DI_FTYPE_V2DI_V2DI_UINT_UINT
20183 };
20184
20185 /* Special builtins with variable number of arguments.  */
20186 static const struct builtin_description bdesc_special_args[] =
20187 {
20188   /* MMX */
20189   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20190
20191   /* 3DNow! */
20192   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20193
20194   /* SSE */
20195   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20196   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20197   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20198
20199   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20200   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20201   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20202   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20203
20204   /* SSE or 3DNow!A  */
20205   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20206   { 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 },
20207
20208   /* SSE2 */
20209   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20210   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20211   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20212   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
20213   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20214   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
20215   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntsi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
20216   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
20217   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20218
20219   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20220   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20221
20222   /* SSE3 */
20223   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20224
20225   /* SSE4.1 */
20226   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
20227
20228   /* SSE4A */
20229   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20230   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20231
20232   /* AVX */
20233   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
20234   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, 0, IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
20235   { OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_64BIT, CODE_FOR_avx_vzeroupper_rex64, 0, IX86_BUILTIN_VZEROUPPER_REX64, UNKNOWN, (int) VOID_FTYPE_VOID },
20236
20237   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20238   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastsd256, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
20239   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss256, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
20240   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_pd256, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
20241   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_ps256, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
20242
20243   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
20244   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
20245   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
20246   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
20247   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
20248   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
20249   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
20250
20251   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF },
20252   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF },
20253   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF },
20254   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF },
20255   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_V2DF },
20256   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_V4SF },
20257   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_V4DF },
20258   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_V8SF },
20259 };
20260
20261 /* Builtins with variable number of arguments.  */
20262 static const struct builtin_description bdesc_args[] =
20263 {
20264   /* MMX */
20265   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20266   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20267   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20268   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20269   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20270   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20271
20272   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20273   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20274   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20275   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20276   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20277   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20278   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20279   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20280
20281   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20282   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20283
20284   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20285   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_nandv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20286   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20287   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20288
20289   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20290   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20291   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20292   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20293   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20294   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20295
20296   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20297   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20298   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20299   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20300   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
20301   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
20302
20303   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
20304   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
20305   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
20306
20307   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
20308
20309   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20310   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20311   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
20312   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20313   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20314   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
20315
20316   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20317   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20318   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
20319   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20320   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20321   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
20322
20323   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20324   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20325   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20326   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20327
20328   /* 3DNow! */
20329   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
20330   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
20331   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20332   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20333
20334   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20335   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20336   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20337   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20338   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20339   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20340   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20341   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20342   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20343   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20344   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20345   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20346   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20347   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20348   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20349
20350   /* 3DNow!A */
20351   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
20352   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
20353   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
20354   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20355   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20356   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20357
20358   /* SSE */
20359   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
20360   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20361   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20362   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20363   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20364   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20365   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
20366   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
20367   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
20368   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
20369   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
20370   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
20371
20372   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20373
20374   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20375   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20376   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20377   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20378   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20379   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20380   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20381   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20382
20383   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
20384   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
20385   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
20386   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20387   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20388   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20389   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
20390   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
20391   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
20392   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20393   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
20394   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20395   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
20396   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
20397   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
20398   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20399   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
20400   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
20401   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
20402   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngtss", IX86_BUILTIN_CMPNGTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20403   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngess", IX86_BUILTIN_CMPNGESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20404   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20405
20406   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20407   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20408   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20409   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20410
20411   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20412   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_nandv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20413   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20414   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20415
20416   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20417   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20418   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20419   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpckhps, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20420   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpcklps, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20421
20422   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
20423   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
20424   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
20425
20426   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
20427
20428   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20429   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20430   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
20431
20432   /* SSE MMX or 3Dnow!A */
20433   { 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 },
20434   { 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 },
20435   { 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 },
20436
20437   { 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 },
20438   { 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 },
20439   { 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 },
20440   { 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 },
20441
20442   { 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 },
20443   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
20444
20445   { 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 },
20446
20447   /* SSE2 */
20448   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20449
20450   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
20451   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
20452   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
20453   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
20454   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2ps, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
20455
20456   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
20457   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
20458   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
20459   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
20460   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
20461
20462   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
20463
20464   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
20465   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
20466   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
20467   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
20468
20469   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2dq, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
20470   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
20471   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttps2dq, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
20472
20473   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20474   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20475   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20476   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20477   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20478   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20479   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20480   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20481
20482   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
20483   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
20484   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
20485   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20486   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
20487   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20488   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
20489   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
20490   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
20491   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20492   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
20493   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20494   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
20495   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
20496   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
20497   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20498   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
20499   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
20500   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
20501   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
20502
20503   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20504   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20505   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20506   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20507
20508   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20509   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_nandv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20510   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20511   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20512
20513   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20514   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpckhpd_exp, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20515   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpcklpd_exp, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20516
20517   { 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 },
20518
20519   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20520   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20521   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20522   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20523   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20524   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20525   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20526   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20527
20528   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20529   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20530   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20531   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20532   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20533   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20534   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20535   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20536
20537   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20538   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
20539
20540   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20541   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_nandv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20542   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20543   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20544
20545   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20546   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20547
20548   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20549   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20550   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
20551   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20552   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20553   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
20554
20555   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20556   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20557   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20558   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20559
20560   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhbw, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20561   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhwd, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
20562   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhdq, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
20563   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhqdq, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20564   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklbw, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20565   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklwd, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20566   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckldq, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20567   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklqdq, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20568
20569   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
20570   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
20571   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
20572
20573   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20574   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
20575
20576   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
20577   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv2siv2di3, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
20578
20579   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
20580
20581   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
20582   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
20583   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
20584   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
20585
20586   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
20587   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
20588   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
20589   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
20590   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
20591   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
20592   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
20593
20594   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
20595   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
20596   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
20597   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
20598   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
20599   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
20600   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
20601
20602   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
20603   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
20604   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
20605   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
20606
20607   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
20608   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
20609   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
20610
20611   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
20612
20613   { OPTION_MASK_ISA_SSE2, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
20614   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
20615
20616   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
20617
20618   /* SSE2 MMX */
20619   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
20620   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
20621
20622   /* SSE3 */
20623   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
20624   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20625
20626   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20627   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20628   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20629   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20630   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20631   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
20632
20633   /* SSSE3 */
20634   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
20635   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
20636   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
20637   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
20638   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
20639   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
20640
20641   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20642   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20643   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20644   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20645   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20646   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20647   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20648   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20649   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20650   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20651   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20652   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20653   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
20654   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
20655   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20656   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20657   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20658   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20659   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20660   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20661   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20662   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20663   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20664   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20665
20666   /* SSSE3.  */
20667   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_V2DI_INT },
20668   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI2DI_FTYPE_V1DI_V1DI_INT },
20669
20670   /* SSE4.1 */
20671   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20672   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20673   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
20674   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
20675   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20676   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20677   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20678   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
20679   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
20680   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
20681
20682   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
20683   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
20684   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
20685   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
20686   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
20687   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
20688   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
20689   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
20690   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
20691   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
20692   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
20693   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
20694   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
20695
20696   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
20697   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20698   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20699   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20700   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20701   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20702   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
20703   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20704   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20705   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
20706   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
20707   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
20708
20709   /* SSE4.1 and SSE5 */
20710   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
20711   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
20712   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20713   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20714
20715   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
20716   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
20717   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
20718
20719   /* SSE4.2 */
20720   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20721   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32qi, "__builtin_ia32_crc32qi", IX86_BUILTIN_CRC32QI, UNKNOWN, (int) UINT_FTYPE_UINT_UCHAR },
20722   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32hi, "__builtin_ia32_crc32hi", IX86_BUILTIN_CRC32HI, UNKNOWN, (int) UINT_FTYPE_UINT_USHORT },
20723   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32si, "__builtin_ia32_crc32si", IX86_BUILTIN_CRC32SI, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
20724   { 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 },
20725
20726   /* SSE4A */
20727   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
20728   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
20729   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
20730   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20731
20732   /* AES */
20733   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
20734   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
20735
20736   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20737   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20738   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20739   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
20740
20741   /* PCLMUL */
20742   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
20743
20744   /* AVX */
20745   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20746   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20747   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20748   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20749   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20750   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20751   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_nandv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20752   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_nandv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20753   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20754   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20755   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20756   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20757   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20758   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20759   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20760   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20761   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20762   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20763   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20764   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20765   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20766   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20767   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20768   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20769   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20770   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20771
20772   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
20773   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
20774   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
20775   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
20776
20777   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
20778   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20779   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
20780   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
20781   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20782   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
20783   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20784   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpsdv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20785   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpssv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20786   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
20787   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20788   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
20789   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20790   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
20791   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
20792   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
20793   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2pd256, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
20794   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2ps256, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
20795   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
20796   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2dq256, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
20797   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
20798   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttpd2dq256, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
20799   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
20800   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttps2dq256, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
20801   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
20802   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
20803   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
20804   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
20805   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
20806   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
20807   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
20808   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermil2v2df3,  "__builtin_ia32_vpermil2pd", IX86_BUILTIN_VPERMIL2PD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DI_INT },
20809   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermil2v4sf3,  "__builtin_ia32_vpermil2ps", IX86_BUILTIN_VPERMIL2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SI_INT },
20810   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermil2v4df3,  "__builtin_ia32_vpermil2pd256", IX86_BUILTIN_VPERMIL2PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DI_INT },
20811   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermil2v8sf3,  "__builtin_ia32_vpermil2ps256", IX86_BUILTIN_VPERMIL2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SI_INT },
20812   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
20813   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
20814   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
20815
20816   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20817   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20818   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
20819
20820   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
20821   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20822   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20823   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20824   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20825
20826   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
20827
20828   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
20829   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
20830
20831   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20832   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
20833   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20834   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
20835
20836   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
20837   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
20838   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
20839   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si_si256, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
20840   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps_ps256, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
20841   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd_pd256, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
20842
20843   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
20844   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
20845   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
20846   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
20847   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
20848   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
20849   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
20850   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
20851   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
20852   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
20853   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
20854   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
20855   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
20856   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
20857   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
20858
20859   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
20860   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
20861 };
20862
20863 /* SSE5 */
20864 enum multi_arg_type {
20865   MULTI_ARG_UNKNOWN,
20866   MULTI_ARG_3_SF,
20867   MULTI_ARG_3_DF,
20868   MULTI_ARG_3_DI,
20869   MULTI_ARG_3_SI,
20870   MULTI_ARG_3_SI_DI,
20871   MULTI_ARG_3_HI,
20872   MULTI_ARG_3_HI_SI,
20873   MULTI_ARG_3_QI,
20874   MULTI_ARG_3_PERMPS,
20875   MULTI_ARG_3_PERMPD,
20876   MULTI_ARG_2_SF,
20877   MULTI_ARG_2_DF,
20878   MULTI_ARG_2_DI,
20879   MULTI_ARG_2_SI,
20880   MULTI_ARG_2_HI,
20881   MULTI_ARG_2_QI,
20882   MULTI_ARG_2_DI_IMM,
20883   MULTI_ARG_2_SI_IMM,
20884   MULTI_ARG_2_HI_IMM,
20885   MULTI_ARG_2_QI_IMM,
20886   MULTI_ARG_2_SF_CMP,
20887   MULTI_ARG_2_DF_CMP,
20888   MULTI_ARG_2_DI_CMP,
20889   MULTI_ARG_2_SI_CMP,
20890   MULTI_ARG_2_HI_CMP,
20891   MULTI_ARG_2_QI_CMP,
20892   MULTI_ARG_2_DI_TF,
20893   MULTI_ARG_2_SI_TF,
20894   MULTI_ARG_2_HI_TF,
20895   MULTI_ARG_2_QI_TF,
20896   MULTI_ARG_2_SF_TF,
20897   MULTI_ARG_2_DF_TF,
20898   MULTI_ARG_1_SF,
20899   MULTI_ARG_1_DF,
20900   MULTI_ARG_1_DI,
20901   MULTI_ARG_1_SI,
20902   MULTI_ARG_1_HI,
20903   MULTI_ARG_1_QI,
20904   MULTI_ARG_1_SI_DI,
20905   MULTI_ARG_1_HI_DI,
20906   MULTI_ARG_1_HI_SI,
20907   MULTI_ARG_1_QI_DI,
20908   MULTI_ARG_1_QI_SI,
20909   MULTI_ARG_1_QI_HI,
20910   MULTI_ARG_1_PH2PS,
20911   MULTI_ARG_1_PS2PH
20912 };
20913
20914 static const struct builtin_description bdesc_multi_arg[] =
20915 {
20916   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv4sf4,     "__builtin_ia32_fmaddss",    IX86_BUILTIN_FMADDSS,    0,            (int)MULTI_ARG_3_SF },
20917   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv2df4,     "__builtin_ia32_fmaddsd",    IX86_BUILTIN_FMADDSD,    0,            (int)MULTI_ARG_3_DF },
20918   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv4sf4,       "__builtin_ia32_fmaddps",    IX86_BUILTIN_FMADDPS,    0,            (int)MULTI_ARG_3_SF },
20919   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv2df4,       "__builtin_ia32_fmaddpd",    IX86_BUILTIN_FMADDPD,    0,            (int)MULTI_ARG_3_DF },
20920   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv4sf4,     "__builtin_ia32_fmsubss",    IX86_BUILTIN_FMSUBSS,    0,            (int)MULTI_ARG_3_SF },
20921   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv2df4,     "__builtin_ia32_fmsubsd",    IX86_BUILTIN_FMSUBSD,    0,            (int)MULTI_ARG_3_DF },
20922   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv4sf4,       "__builtin_ia32_fmsubps",    IX86_BUILTIN_FMSUBPS,    0,            (int)MULTI_ARG_3_SF },
20923   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv2df4,       "__builtin_ia32_fmsubpd",    IX86_BUILTIN_FMSUBPD,    0,            (int)MULTI_ARG_3_DF },
20924   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv4sf4,    "__builtin_ia32_fnmaddss",   IX86_BUILTIN_FNMADDSS,   0,            (int)MULTI_ARG_3_SF },
20925   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv2df4,    "__builtin_ia32_fnmaddsd",   IX86_BUILTIN_FNMADDSD,   0,            (int)MULTI_ARG_3_DF },
20926   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv4sf4,      "__builtin_ia32_fnmaddps",   IX86_BUILTIN_FNMADDPS,   0,            (int)MULTI_ARG_3_SF },
20927   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv2df4,      "__builtin_ia32_fnmaddpd",   IX86_BUILTIN_FNMADDPD,   0,            (int)MULTI_ARG_3_DF },
20928   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv4sf4,    "__builtin_ia32_fnmsubss",   IX86_BUILTIN_FNMSUBSS,   0,            (int)MULTI_ARG_3_SF },
20929   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv2df4,    "__builtin_ia32_fnmsubsd",   IX86_BUILTIN_FNMSUBSD,   0,            (int)MULTI_ARG_3_DF },
20930   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv4sf4,      "__builtin_ia32_fnmsubps",   IX86_BUILTIN_FNMSUBPS,   0,            (int)MULTI_ARG_3_SF },
20931   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv2df4,      "__builtin_ia32_fnmsubpd",   IX86_BUILTIN_FNMSUBPD,   0,            (int)MULTI_ARG_3_DF },
20932   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov",      IX86_BUILTIN_PCMOV,      0,            (int)MULTI_ARG_3_DI },
20933   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov_v2di", IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
20934   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4si,        "__builtin_ia32_pcmov_v4si", IX86_BUILTIN_PCMOV_V4SI, 0,            (int)MULTI_ARG_3_SI },
20935   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v8hi,        "__builtin_ia32_pcmov_v8hi", IX86_BUILTIN_PCMOV_V8HI, 0,            (int)MULTI_ARG_3_HI },
20936   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v16qi,       "__builtin_ia32_pcmov_v16qi",IX86_BUILTIN_PCMOV_V16QI,0,            (int)MULTI_ARG_3_QI },
20937   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2df,        "__builtin_ia32_pcmov_v2df", IX86_BUILTIN_PCMOV_V2DF, 0,            (int)MULTI_ARG_3_DF },
20938   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4sf,        "__builtin_ia32_pcmov_v4sf", IX86_BUILTIN_PCMOV_V4SF, 0,            (int)MULTI_ARG_3_SF },
20939   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pperm,             "__builtin_ia32_pperm",      IX86_BUILTIN_PPERM,      0,            (int)MULTI_ARG_3_QI },
20940   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv4sf,          "__builtin_ia32_permps",     IX86_BUILTIN_PERMPS,     0,            (int)MULTI_ARG_3_PERMPS },
20941   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv2df,          "__builtin_ia32_permpd",     IX86_BUILTIN_PERMPD,     0,            (int)MULTI_ARG_3_PERMPD },
20942   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssww,          "__builtin_ia32_pmacssww",   IX86_BUILTIN_PMACSSWW,   0,            (int)MULTI_ARG_3_HI },
20943   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsww,           "__builtin_ia32_pmacsww",    IX86_BUILTIN_PMACSWW,    0,            (int)MULTI_ARG_3_HI },
20944   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsswd,          "__builtin_ia32_pmacsswd",   IX86_BUILTIN_PMACSSWD,   0,            (int)MULTI_ARG_3_HI_SI },
20945   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacswd,           "__builtin_ia32_pmacswd",    IX86_BUILTIN_PMACSWD,    0,            (int)MULTI_ARG_3_HI_SI },
20946   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdd,          "__builtin_ia32_pmacssdd",   IX86_BUILTIN_PMACSSDD,   0,            (int)MULTI_ARG_3_SI },
20947   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdd,           "__builtin_ia32_pmacsdd",    IX86_BUILTIN_PMACSDD,    0,            (int)MULTI_ARG_3_SI },
20948   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdql,         "__builtin_ia32_pmacssdql",  IX86_BUILTIN_PMACSSDQL,  0,            (int)MULTI_ARG_3_SI_DI },
20949   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdqh,         "__builtin_ia32_pmacssdqh",  IX86_BUILTIN_PMACSSDQH,  0,            (int)MULTI_ARG_3_SI_DI },
20950   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdql,          "__builtin_ia32_pmacsdql",   IX86_BUILTIN_PMACSDQL,   0,            (int)MULTI_ARG_3_SI_DI },
20951   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdqh,          "__builtin_ia32_pmacsdqh",   IX86_BUILTIN_PMACSDQH,   0,            (int)MULTI_ARG_3_SI_DI },
20952   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcsswd,         "__builtin_ia32_pmadcsswd",  IX86_BUILTIN_PMADCSSWD,  0,            (int)MULTI_ARG_3_HI_SI },
20953   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcswd,          "__builtin_ia32_pmadcswd",   IX86_BUILTIN_PMADCSWD,   0,            (int)MULTI_ARG_3_HI_SI },
20954   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv2di3,        "__builtin_ia32_protq",      IX86_BUILTIN_PROTQ,      0,            (int)MULTI_ARG_2_DI },
20955   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv4si3,        "__builtin_ia32_protd",      IX86_BUILTIN_PROTD,      0,            (int)MULTI_ARG_2_SI },
20956   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv8hi3,        "__builtin_ia32_protw",      IX86_BUILTIN_PROTW,      0,            (int)MULTI_ARG_2_HI },
20957   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv16qi3,       "__builtin_ia32_protb",      IX86_BUILTIN_PROTB,      0,            (int)MULTI_ARG_2_QI },
20958   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv2di3,         "__builtin_ia32_protqi",     IX86_BUILTIN_PROTQ_IMM,  0,            (int)MULTI_ARG_2_DI_IMM },
20959   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv4si3,         "__builtin_ia32_protdi",     IX86_BUILTIN_PROTD_IMM,  0,            (int)MULTI_ARG_2_SI_IMM },
20960   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv8hi3,         "__builtin_ia32_protwi",     IX86_BUILTIN_PROTW_IMM,  0,            (int)MULTI_ARG_2_HI_IMM },
20961   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv16qi3,        "__builtin_ia32_protbi",     IX86_BUILTIN_PROTB_IMM,  0,            (int)MULTI_ARG_2_QI_IMM },
20962   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv2di3,         "__builtin_ia32_pshaq",      IX86_BUILTIN_PSHAQ,      0,            (int)MULTI_ARG_2_DI },
20963   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv4si3,         "__builtin_ia32_pshad",      IX86_BUILTIN_PSHAD,      0,            (int)MULTI_ARG_2_SI },
20964   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv8hi3,         "__builtin_ia32_pshaw",      IX86_BUILTIN_PSHAW,      0,            (int)MULTI_ARG_2_HI },
20965   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv16qi3,        "__builtin_ia32_pshab",      IX86_BUILTIN_PSHAB,      0,            (int)MULTI_ARG_2_QI },
20966   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv2di3,         "__builtin_ia32_pshlq",      IX86_BUILTIN_PSHLQ,      0,            (int)MULTI_ARG_2_DI },
20967   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv4si3,         "__builtin_ia32_pshld",      IX86_BUILTIN_PSHLD,      0,            (int)MULTI_ARG_2_SI },
20968   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv8hi3,         "__builtin_ia32_pshlw",      IX86_BUILTIN_PSHLW,      0,            (int)MULTI_ARG_2_HI },
20969   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv16qi3,        "__builtin_ia32_pshlb",      IX86_BUILTIN_PSHLB,      0,            (int)MULTI_ARG_2_QI },
20970   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv4sf2,       "__builtin_ia32_frczss",     IX86_BUILTIN_FRCZSS,     0,            (int)MULTI_ARG_2_SF },
20971   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv2df2,       "__builtin_ia32_frczsd",     IX86_BUILTIN_FRCZSD,     0,            (int)MULTI_ARG_2_DF },
20972   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv4sf2,         "__builtin_ia32_frczps",     IX86_BUILTIN_FRCZPS,     0,            (int)MULTI_ARG_1_SF },
20973   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv2df2,         "__builtin_ia32_frczpd",     IX86_BUILTIN_FRCZPD,     0,            (int)MULTI_ARG_1_DF },
20974   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtph2ps,          "__builtin_ia32_cvtph2ps",   IX86_BUILTIN_CVTPH2PS,   0,            (int)MULTI_ARG_1_PH2PS },
20975   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtps2ph,          "__builtin_ia32_cvtps2ph",   IX86_BUILTIN_CVTPS2PH,   0,            (int)MULTI_ARG_1_PS2PH },
20976   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbw,           "__builtin_ia32_phaddbw",    IX86_BUILTIN_PHADDBW,    0,            (int)MULTI_ARG_1_QI_HI },
20977   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbd,           "__builtin_ia32_phaddbd",    IX86_BUILTIN_PHADDBD,    0,            (int)MULTI_ARG_1_QI_SI },
20978   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbq,           "__builtin_ia32_phaddbq",    IX86_BUILTIN_PHADDBQ,    0,            (int)MULTI_ARG_1_QI_DI },
20979   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwd,           "__builtin_ia32_phaddwd",    IX86_BUILTIN_PHADDWD,    0,            (int)MULTI_ARG_1_HI_SI },
20980   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwq,           "__builtin_ia32_phaddwq",    IX86_BUILTIN_PHADDWQ,    0,            (int)MULTI_ARG_1_HI_DI },
20981   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadddq,           "__builtin_ia32_phadddq",    IX86_BUILTIN_PHADDDQ,    0,            (int)MULTI_ARG_1_SI_DI },
20982   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubw,          "__builtin_ia32_phaddubw",   IX86_BUILTIN_PHADDUBW,   0,            (int)MULTI_ARG_1_QI_HI },
20983   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubd,          "__builtin_ia32_phaddubd",   IX86_BUILTIN_PHADDUBD,   0,            (int)MULTI_ARG_1_QI_SI },
20984   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubq,          "__builtin_ia32_phaddubq",   IX86_BUILTIN_PHADDUBQ,   0,            (int)MULTI_ARG_1_QI_DI },
20985   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwd,          "__builtin_ia32_phadduwd",   IX86_BUILTIN_PHADDUWD,   0,            (int)MULTI_ARG_1_HI_SI },
20986   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwq,          "__builtin_ia32_phadduwq",   IX86_BUILTIN_PHADDUWQ,   0,            (int)MULTI_ARG_1_HI_DI },
20987   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddudq,          "__builtin_ia32_phaddudq",   IX86_BUILTIN_PHADDUDQ,   0,            (int)MULTI_ARG_1_SI_DI },
20988   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubbw,           "__builtin_ia32_phsubbw",    IX86_BUILTIN_PHSUBBW,    0,            (int)MULTI_ARG_1_QI_HI },
20989   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubwd,           "__builtin_ia32_phsubwd",    IX86_BUILTIN_PHSUBWD,    0,            (int)MULTI_ARG_1_HI_SI },
20990   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubdq,           "__builtin_ia32_phsubdq",    IX86_BUILTIN_PHSUBDQ,    0,            (int)MULTI_ARG_1_SI_DI },
20991
20992   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comeqss",    IX86_BUILTIN_COMEQSS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
20993   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comness",    IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
20994   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comneqss",   IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
20995   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comltss",    IX86_BUILTIN_COMLTSS,    LT,           (int)MULTI_ARG_2_SF_CMP },
20996   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comless",    IX86_BUILTIN_COMLESS,    LE,           (int)MULTI_ARG_2_SF_CMP },
20997   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgtss",    IX86_BUILTIN_COMGTSS,    GT,           (int)MULTI_ARG_2_SF_CMP },
20998   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgess",    IX86_BUILTIN_COMGESS,    GE,           (int)MULTI_ARG_2_SF_CMP },
20999   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comueqss",   IX86_BUILTIN_COMUEQSS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21000   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuness",   IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21001   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuneqss",  IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21002   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunltss",  IX86_BUILTIN_COMULTSS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21003   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunless",  IX86_BUILTIN_COMULESS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21004   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungtss",  IX86_BUILTIN_COMUGTSS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21005   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungess",  IX86_BUILTIN_COMUGESS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21006   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comordss",   IX86_BUILTIN_COMORDSS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21007   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunordss", IX86_BUILTIN_COMUNORDSS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21008
21009   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comeqsd",    IX86_BUILTIN_COMEQSD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21010   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comnesd",    IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21011   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comneqsd",   IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21012   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comltsd",    IX86_BUILTIN_COMLTSD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21013   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comlesd",    IX86_BUILTIN_COMLESD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21014   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgtsd",    IX86_BUILTIN_COMGTSD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21015   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgesd",    IX86_BUILTIN_COMGESD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21016   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comueqsd",   IX86_BUILTIN_COMUEQSD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21017   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunesd",   IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21018   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comuneqsd",  IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21019   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunltsd",  IX86_BUILTIN_COMULTSD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21020   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunlesd",  IX86_BUILTIN_COMULESD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21021   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungtsd",  IX86_BUILTIN_COMUGTSD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21022   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungesd",  IX86_BUILTIN_COMUGESD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21023   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comordsd",   IX86_BUILTIN_COMORDSD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21024   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunordsd", IX86_BUILTIN_COMUNORDSD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21025
21026   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comeqps",    IX86_BUILTIN_COMEQPS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
21027   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneps",    IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21028   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneqps",   IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21029   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comltps",    IX86_BUILTIN_COMLTPS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21030   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comleps",    IX86_BUILTIN_COMLEPS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21031   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgtps",    IX86_BUILTIN_COMGTPS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21032   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgeps",    IX86_BUILTIN_COMGEPS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21033   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comueqps",   IX86_BUILTIN_COMUEQPS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21034   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneps",   IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21035   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneqps",  IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21036   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunltps",  IX86_BUILTIN_COMULTPS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21037   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunleps",  IX86_BUILTIN_COMULEPS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21038   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungtps",  IX86_BUILTIN_COMUGTPS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21039   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungeps",  IX86_BUILTIN_COMUGEPS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21040   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comordps",   IX86_BUILTIN_COMORDPS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21041   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunordps", IX86_BUILTIN_COMUNORDPS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21042
21043   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comeqpd",    IX86_BUILTIN_COMEQPD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21044   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comnepd",    IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21045   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comneqpd",   IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21046   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comltpd",    IX86_BUILTIN_COMLTPD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21047   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comlepd",    IX86_BUILTIN_COMLEPD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21048   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgtpd",    IX86_BUILTIN_COMGTPD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21049   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgepd",    IX86_BUILTIN_COMGEPD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21050   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comueqpd",   IX86_BUILTIN_COMUEQPD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21051   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunepd",   IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21052   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comuneqpd",  IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21053   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunltpd",  IX86_BUILTIN_COMULTPD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21054   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunlepd",  IX86_BUILTIN_COMULEPD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21055   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungtpd",  IX86_BUILTIN_COMUGTPD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21056   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungepd",  IX86_BUILTIN_COMUGEPD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21057   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comordpd",   IX86_BUILTIN_COMORDPD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21058   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunordpd", IX86_BUILTIN_COMUNORDPD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21059
21060   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomeqb",    IX86_BUILTIN_PCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
21061   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneb",    IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21062   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneqb",   IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21063   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomltb",    IX86_BUILTIN_PCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
21064   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomleb",    IX86_BUILTIN_PCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
21065   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgtb",    IX86_BUILTIN_PCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
21066   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgeb",    IX86_BUILTIN_PCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
21067
21068   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomeqw",    IX86_BUILTIN_PCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
21069   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomnew",    IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21070   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomneqw",   IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21071   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomltw",    IX86_BUILTIN_PCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
21072   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomlew",    IX86_BUILTIN_PCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
21073   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgtw",    IX86_BUILTIN_PCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
21074   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgew",    IX86_BUILTIN_PCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
21075
21076   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomeqd",    IX86_BUILTIN_PCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
21077   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomned",    IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21078   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomneqd",   IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21079   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomltd",    IX86_BUILTIN_PCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
21080   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomled",    IX86_BUILTIN_PCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
21081   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomgtd",    IX86_BUILTIN_PCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
21082   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomged",    IX86_BUILTIN_PCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
21083
21084   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomeqq",    IX86_BUILTIN_PCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
21085   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneq",    IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21086   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneqq",   IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21087   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomltq",    IX86_BUILTIN_PCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
21088   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomleq",    IX86_BUILTIN_PCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
21089   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgtq",    IX86_BUILTIN_PCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
21090   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgeq",    IX86_BUILTIN_PCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
21091
21092   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomequb",   IX86_BUILTIN_PCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
21093   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomneub",   IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21094   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomnequb",  IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21095   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomltub",   IX86_BUILTIN_PCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
21096   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomleub",   IX86_BUILTIN_PCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
21097   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgtub",   IX86_BUILTIN_PCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
21098   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgeub",   IX86_BUILTIN_PCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
21099
21100   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomequw",   IX86_BUILTIN_PCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
21101   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomneuw",   IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21102   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomnequw",  IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21103   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomltuw",   IX86_BUILTIN_PCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
21104   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomleuw",   IX86_BUILTIN_PCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
21105   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgtuw",   IX86_BUILTIN_PCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
21106   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgeuw",   IX86_BUILTIN_PCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
21107
21108   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomequd",   IX86_BUILTIN_PCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
21109   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomneud",   IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21110   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomnequd",  IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21111   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomltud",   IX86_BUILTIN_PCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
21112   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomleud",   IX86_BUILTIN_PCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
21113   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgtud",   IX86_BUILTIN_PCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
21114   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgeud",   IX86_BUILTIN_PCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
21115
21116   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomequq",   IX86_BUILTIN_PCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
21117   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomneuq",   IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21118   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomnequq",  IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21119   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomltuq",   IX86_BUILTIN_PCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
21120   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomleuq",   IX86_BUILTIN_PCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
21121   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgtuq",   IX86_BUILTIN_PCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
21122   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgeuq",   IX86_BUILTIN_PCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
21123
21124   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalsess", IX86_BUILTIN_COMFALSESS, COM_FALSE_S,  (int)MULTI_ARG_2_SF_TF },
21125   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtruess",  IX86_BUILTIN_COMTRUESS,  COM_TRUE_S,   (int)MULTI_ARG_2_SF_TF },
21126   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalseps", IX86_BUILTIN_COMFALSEPS, COM_FALSE_P,  (int)MULTI_ARG_2_SF_TF },
21127   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtrueps",  IX86_BUILTIN_COMTRUEPS,  COM_TRUE_P,   (int)MULTI_ARG_2_SF_TF },
21128   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsesd", IX86_BUILTIN_COMFALSESD, COM_FALSE_S,  (int)MULTI_ARG_2_DF_TF },
21129   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruesd",  IX86_BUILTIN_COMTRUESD,  COM_TRUE_S,   (int)MULTI_ARG_2_DF_TF },
21130   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsepd", IX86_BUILTIN_COMFALSEPD, COM_FALSE_P,  (int)MULTI_ARG_2_DF_TF },
21131   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruepd",  IX86_BUILTIN_COMTRUEPD,  COM_TRUE_P,   (int)MULTI_ARG_2_DF_TF },
21132
21133   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseb", IX86_BUILTIN_PCOMFALSEB, PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21134   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalsew", IX86_BUILTIN_PCOMFALSEW, PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21135   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalsed", IX86_BUILTIN_PCOMFALSED, PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21136   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseq", IX86_BUILTIN_PCOMFALSEQ, PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21137   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseub",IX86_BUILTIN_PCOMFALSEUB,PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21138   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalseuw",IX86_BUILTIN_PCOMFALSEUW,PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21139   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalseud",IX86_BUILTIN_PCOMFALSEUD,PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21140   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseuq",IX86_BUILTIN_PCOMFALSEUQ,PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21141
21142   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueb",  IX86_BUILTIN_PCOMTRUEB,  PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21143   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtruew",  IX86_BUILTIN_PCOMTRUEW,  PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21144   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrued",  IX86_BUILTIN_PCOMTRUED,  PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21145   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueq",  IX86_BUILTIN_PCOMTRUEQ,  PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21146   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueub", IX86_BUILTIN_PCOMTRUEUB, PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21147   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtrueuw", IX86_BUILTIN_PCOMTRUEUW, PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21148   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrueud", IX86_BUILTIN_PCOMTRUEUD, PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21149   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueuq", IX86_BUILTIN_PCOMTRUEUQ, PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21150 };
21151
21152 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
21153    in the current target ISA to allow the user to compile particular modules
21154    with different target specific options that differ from the command line
21155    options.  */
21156 static void
21157 ix86_init_mmx_sse_builtins (void)
21158 {
21159   const struct builtin_description * d;
21160   size_t i;
21161
21162   tree V16QI_type_node = build_vector_type_for_mode (char_type_node, V16QImode);
21163   tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
21164   tree V1DI_type_node
21165     = build_vector_type_for_mode (long_long_integer_type_node, V1DImode);
21166   tree V2SF_type_node = build_vector_type_for_mode (float_type_node, V2SFmode);
21167   tree V2DI_type_node
21168     = build_vector_type_for_mode (long_long_integer_type_node, V2DImode);
21169   tree V2DF_type_node = build_vector_type_for_mode (double_type_node, V2DFmode);
21170   tree V4SF_type_node = build_vector_type_for_mode (float_type_node, V4SFmode);
21171   tree V4SI_type_node = build_vector_type_for_mode (intSI_type_node, V4SImode);
21172   tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
21173   tree V8QI_type_node = build_vector_type_for_mode (char_type_node, V8QImode);
21174   tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, V8HImode);
21175
21176   tree pchar_type_node = build_pointer_type (char_type_node);
21177   tree pcchar_type_node
21178     = build_pointer_type (build_type_variant (char_type_node, 1, 0));
21179   tree pfloat_type_node = build_pointer_type (float_type_node);
21180   tree pcfloat_type_node
21181     = build_pointer_type (build_type_variant (float_type_node, 1, 0));
21182   tree pv2sf_type_node = build_pointer_type (V2SF_type_node);
21183   tree pcv2sf_type_node
21184     = build_pointer_type (build_type_variant (V2SF_type_node, 1, 0));
21185   tree pv2di_type_node = build_pointer_type (V2DI_type_node);
21186   tree pdi_type_node = build_pointer_type (long_long_unsigned_type_node);
21187
21188   /* Comparisons.  */
21189   tree int_ftype_v4sf_v4sf
21190     = build_function_type_list (integer_type_node,
21191                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21192   tree v4si_ftype_v4sf_v4sf
21193     = build_function_type_list (V4SI_type_node,
21194                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21195   /* MMX/SSE/integer conversions.  */
21196   tree int_ftype_v4sf
21197     = build_function_type_list (integer_type_node,
21198                                 V4SF_type_node, NULL_TREE);
21199   tree int64_ftype_v4sf
21200     = build_function_type_list (long_long_integer_type_node,
21201                                 V4SF_type_node, NULL_TREE);
21202   tree int_ftype_v8qi
21203     = build_function_type_list (integer_type_node, V8QI_type_node, NULL_TREE);
21204   tree v4sf_ftype_v4sf_int
21205     = build_function_type_list (V4SF_type_node,
21206                                 V4SF_type_node, integer_type_node, NULL_TREE);
21207   tree v4sf_ftype_v4sf_int64
21208     = build_function_type_list (V4SF_type_node,
21209                                 V4SF_type_node, long_long_integer_type_node,
21210                                 NULL_TREE);
21211   tree v4sf_ftype_v4sf_v2si
21212     = build_function_type_list (V4SF_type_node,
21213                                 V4SF_type_node, V2SI_type_node, NULL_TREE);
21214
21215   /* Miscellaneous.  */
21216   tree v8qi_ftype_v4hi_v4hi
21217     = build_function_type_list (V8QI_type_node,
21218                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21219   tree v4hi_ftype_v2si_v2si
21220     = build_function_type_list (V4HI_type_node,
21221                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21222   tree v4sf_ftype_v4sf_v4sf_int
21223     = build_function_type_list (V4SF_type_node,
21224                                 V4SF_type_node, V4SF_type_node,
21225                                 integer_type_node, NULL_TREE);
21226   tree v2si_ftype_v4hi_v4hi
21227     = build_function_type_list (V2SI_type_node,
21228                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21229   tree v4hi_ftype_v4hi_int
21230     = build_function_type_list (V4HI_type_node,
21231                                 V4HI_type_node, integer_type_node, NULL_TREE);
21232   tree v2si_ftype_v2si_int
21233     = build_function_type_list (V2SI_type_node,
21234                                 V2SI_type_node, integer_type_node, NULL_TREE);
21235   tree v1di_ftype_v1di_int
21236     = build_function_type_list (V1DI_type_node,
21237                                 V1DI_type_node, integer_type_node, NULL_TREE);
21238
21239   tree void_ftype_void
21240     = build_function_type (void_type_node, void_list_node);
21241   tree void_ftype_unsigned
21242     = build_function_type_list (void_type_node, unsigned_type_node, NULL_TREE);
21243   tree void_ftype_unsigned_unsigned
21244     = build_function_type_list (void_type_node, unsigned_type_node,
21245                                 unsigned_type_node, NULL_TREE);
21246   tree void_ftype_pcvoid_unsigned_unsigned
21247     = build_function_type_list (void_type_node, const_ptr_type_node,
21248                                 unsigned_type_node, unsigned_type_node,
21249                                 NULL_TREE);
21250   tree unsigned_ftype_void
21251     = build_function_type (unsigned_type_node, void_list_node);
21252   tree v2si_ftype_v4sf
21253     = build_function_type_list (V2SI_type_node, V4SF_type_node, NULL_TREE);
21254   /* Loads/stores.  */
21255   tree void_ftype_v8qi_v8qi_pchar
21256     = build_function_type_list (void_type_node,
21257                                 V8QI_type_node, V8QI_type_node,
21258                                 pchar_type_node, NULL_TREE);
21259   tree v4sf_ftype_pcfloat
21260     = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
21261   tree v4sf_ftype_v4sf_pcv2sf
21262     = build_function_type_list (V4SF_type_node,
21263                                 V4SF_type_node, pcv2sf_type_node, NULL_TREE);
21264   tree void_ftype_pv2sf_v4sf
21265     = build_function_type_list (void_type_node,
21266                                 pv2sf_type_node, V4SF_type_node, NULL_TREE);
21267   tree void_ftype_pfloat_v4sf
21268     = build_function_type_list (void_type_node,
21269                                 pfloat_type_node, V4SF_type_node, NULL_TREE);
21270   tree void_ftype_pdi_di
21271     = build_function_type_list (void_type_node,
21272                                 pdi_type_node, long_long_unsigned_type_node,
21273                                 NULL_TREE);
21274   tree void_ftype_pv2di_v2di
21275     = build_function_type_list (void_type_node,
21276                                 pv2di_type_node, V2DI_type_node, NULL_TREE);
21277   /* Normal vector unops.  */
21278   tree v4sf_ftype_v4sf
21279     = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
21280   tree v16qi_ftype_v16qi
21281     = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
21282   tree v8hi_ftype_v8hi
21283     = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
21284   tree v4si_ftype_v4si
21285     = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
21286   tree v8qi_ftype_v8qi
21287     = build_function_type_list (V8QI_type_node, V8QI_type_node, NULL_TREE);
21288   tree v4hi_ftype_v4hi
21289     = build_function_type_list (V4HI_type_node, V4HI_type_node, NULL_TREE);
21290
21291   /* Normal vector binops.  */
21292   tree v4sf_ftype_v4sf_v4sf
21293     = build_function_type_list (V4SF_type_node,
21294                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21295   tree v8qi_ftype_v8qi_v8qi
21296     = build_function_type_list (V8QI_type_node,
21297                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
21298   tree v4hi_ftype_v4hi_v4hi
21299     = build_function_type_list (V4HI_type_node,
21300                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21301   tree v2si_ftype_v2si_v2si
21302     = build_function_type_list (V2SI_type_node,
21303                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21304   tree v1di_ftype_v1di_v1di
21305     = build_function_type_list (V1DI_type_node,
21306                                 V1DI_type_node, V1DI_type_node, NULL_TREE);
21307   tree v1di_ftype_v1di_v1di_int
21308     = build_function_type_list (V1DI_type_node,
21309                                 V1DI_type_node, V1DI_type_node,
21310                                 integer_type_node, NULL_TREE);
21311   tree v2si_ftype_v2sf
21312     = build_function_type_list (V2SI_type_node, V2SF_type_node, NULL_TREE);
21313   tree v2sf_ftype_v2si
21314     = build_function_type_list (V2SF_type_node, V2SI_type_node, NULL_TREE);
21315   tree v2si_ftype_v2si
21316     = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
21317   tree v2sf_ftype_v2sf
21318     = build_function_type_list (V2SF_type_node, V2SF_type_node, NULL_TREE);
21319   tree v2sf_ftype_v2sf_v2sf
21320     = build_function_type_list (V2SF_type_node,
21321                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
21322   tree v2si_ftype_v2sf_v2sf
21323     = build_function_type_list (V2SI_type_node,
21324                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
21325   tree pint_type_node    = build_pointer_type (integer_type_node);
21326   tree pdouble_type_node = build_pointer_type (double_type_node);
21327   tree pcdouble_type_node = build_pointer_type (
21328                                 build_type_variant (double_type_node, 1, 0));
21329   tree int_ftype_v2df_v2df
21330     = build_function_type_list (integer_type_node,
21331                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21332
21333   tree void_ftype_pcvoid
21334     = build_function_type_list (void_type_node, const_ptr_type_node, NULL_TREE);
21335   tree v4sf_ftype_v4si
21336     = build_function_type_list (V4SF_type_node, V4SI_type_node, NULL_TREE);
21337   tree v4si_ftype_v4sf
21338     = build_function_type_list (V4SI_type_node, V4SF_type_node, NULL_TREE);
21339   tree v2df_ftype_v4si
21340     = build_function_type_list (V2DF_type_node, V4SI_type_node, NULL_TREE);
21341   tree v4si_ftype_v2df
21342     = build_function_type_list (V4SI_type_node, V2DF_type_node, NULL_TREE);
21343   tree v4si_ftype_v2df_v2df
21344     = build_function_type_list (V4SI_type_node,
21345                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21346   tree v2si_ftype_v2df
21347     = build_function_type_list (V2SI_type_node, V2DF_type_node, NULL_TREE);
21348   tree v4sf_ftype_v2df
21349     = build_function_type_list (V4SF_type_node, V2DF_type_node, NULL_TREE);
21350   tree v2df_ftype_v2si
21351     = build_function_type_list (V2DF_type_node, V2SI_type_node, NULL_TREE);
21352   tree v2df_ftype_v4sf
21353     = build_function_type_list (V2DF_type_node, V4SF_type_node, NULL_TREE);
21354   tree int_ftype_v2df
21355     = build_function_type_list (integer_type_node, V2DF_type_node, NULL_TREE);
21356   tree int64_ftype_v2df
21357     = build_function_type_list (long_long_integer_type_node,
21358                                 V2DF_type_node, NULL_TREE);
21359   tree v2df_ftype_v2df_int
21360     = build_function_type_list (V2DF_type_node,
21361                                 V2DF_type_node, integer_type_node, NULL_TREE);
21362   tree v2df_ftype_v2df_int64
21363     = build_function_type_list (V2DF_type_node,
21364                                 V2DF_type_node, long_long_integer_type_node,
21365                                 NULL_TREE);
21366   tree v4sf_ftype_v4sf_v2df
21367     = build_function_type_list (V4SF_type_node,
21368                                 V4SF_type_node, V2DF_type_node, NULL_TREE);
21369   tree v2df_ftype_v2df_v4sf
21370     = build_function_type_list (V2DF_type_node,
21371                                 V2DF_type_node, V4SF_type_node, NULL_TREE);
21372   tree v2df_ftype_v2df_v2df_int
21373     = build_function_type_list (V2DF_type_node,
21374                                 V2DF_type_node, V2DF_type_node,
21375                                 integer_type_node,
21376                                 NULL_TREE);
21377   tree v2df_ftype_v2df_pcdouble
21378     = build_function_type_list (V2DF_type_node,
21379                                 V2DF_type_node, pcdouble_type_node, NULL_TREE);
21380   tree void_ftype_pdouble_v2df
21381     = build_function_type_list (void_type_node,
21382                                 pdouble_type_node, V2DF_type_node, NULL_TREE);
21383   tree void_ftype_pint_int
21384     = build_function_type_list (void_type_node,
21385                                 pint_type_node, integer_type_node, NULL_TREE);
21386   tree void_ftype_v16qi_v16qi_pchar
21387     = build_function_type_list (void_type_node,
21388                                 V16QI_type_node, V16QI_type_node,
21389                                 pchar_type_node, NULL_TREE);
21390   tree v2df_ftype_pcdouble
21391     = build_function_type_list (V2DF_type_node, pcdouble_type_node, NULL_TREE);
21392   tree v2df_ftype_v2df_v2df
21393     = build_function_type_list (V2DF_type_node,
21394                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21395   tree v16qi_ftype_v16qi_v16qi
21396     = build_function_type_list (V16QI_type_node,
21397                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
21398   tree v8hi_ftype_v8hi_v8hi
21399     = build_function_type_list (V8HI_type_node,
21400                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
21401   tree v4si_ftype_v4si_v4si
21402     = build_function_type_list (V4SI_type_node,
21403                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
21404   tree v2di_ftype_v2di_v2di
21405     = build_function_type_list (V2DI_type_node,
21406                                 V2DI_type_node, V2DI_type_node, NULL_TREE);
21407   tree v2di_ftype_v2df_v2df
21408     = build_function_type_list (V2DI_type_node,
21409                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21410   tree v2df_ftype_v2df
21411     = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
21412   tree v2di_ftype_v2di_int
21413     = build_function_type_list (V2DI_type_node,
21414                                 V2DI_type_node, integer_type_node, NULL_TREE);
21415   tree v2di_ftype_v2di_v2di_int
21416     = build_function_type_list (V2DI_type_node, V2DI_type_node,
21417                                 V2DI_type_node, integer_type_node, NULL_TREE);
21418   tree v4si_ftype_v4si_int
21419     = build_function_type_list (V4SI_type_node,
21420                                 V4SI_type_node, integer_type_node, NULL_TREE);
21421   tree v8hi_ftype_v8hi_int
21422     = build_function_type_list (V8HI_type_node,
21423                                 V8HI_type_node, integer_type_node, NULL_TREE);
21424   tree v4si_ftype_v8hi_v8hi
21425     = build_function_type_list (V4SI_type_node,
21426                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
21427   tree v1di_ftype_v8qi_v8qi
21428     = build_function_type_list (V1DI_type_node,
21429                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
21430   tree v1di_ftype_v2si_v2si
21431     = build_function_type_list (V1DI_type_node,
21432                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21433   tree v2di_ftype_v16qi_v16qi
21434     = build_function_type_list (V2DI_type_node,
21435                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
21436   tree v2di_ftype_v4si_v4si
21437     = build_function_type_list (V2DI_type_node,
21438                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
21439   tree int_ftype_v16qi
21440     = build_function_type_list (integer_type_node, V16QI_type_node, NULL_TREE);
21441   tree v16qi_ftype_pcchar
21442     = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
21443   tree void_ftype_pchar_v16qi
21444     = build_function_type_list (void_type_node,
21445                                 pchar_type_node, V16QI_type_node, NULL_TREE);
21446
21447   tree v2di_ftype_v2di_unsigned_unsigned
21448     = build_function_type_list (V2DI_type_node, V2DI_type_node,
21449                                 unsigned_type_node, unsigned_type_node,
21450                                 NULL_TREE);
21451   tree v2di_ftype_v2di_v2di_unsigned_unsigned
21452     = build_function_type_list (V2DI_type_node, V2DI_type_node, V2DI_type_node,
21453                                 unsigned_type_node, unsigned_type_node,
21454                                 NULL_TREE);
21455   tree v2di_ftype_v2di_v16qi
21456     = build_function_type_list (V2DI_type_node, V2DI_type_node, V16QI_type_node,
21457                                 NULL_TREE);
21458   tree v2df_ftype_v2df_v2df_v2df
21459     = build_function_type_list (V2DF_type_node,
21460                                 V2DF_type_node, V2DF_type_node,
21461                                 V2DF_type_node, NULL_TREE);
21462   tree v4sf_ftype_v4sf_v4sf_v4sf
21463     = build_function_type_list (V4SF_type_node,
21464                                 V4SF_type_node, V4SF_type_node,
21465                                 V4SF_type_node, NULL_TREE);
21466   tree v8hi_ftype_v16qi
21467     = build_function_type_list (V8HI_type_node, V16QI_type_node,
21468                                 NULL_TREE);
21469   tree v4si_ftype_v16qi
21470     = build_function_type_list (V4SI_type_node, V16QI_type_node,
21471                                 NULL_TREE);
21472   tree v2di_ftype_v16qi
21473     = build_function_type_list (V2DI_type_node, V16QI_type_node,
21474                                 NULL_TREE);
21475   tree v4si_ftype_v8hi
21476     = build_function_type_list (V4SI_type_node, V8HI_type_node,
21477                                 NULL_TREE);
21478   tree v2di_ftype_v8hi
21479     = build_function_type_list (V2DI_type_node, V8HI_type_node,
21480                                 NULL_TREE);
21481   tree v2di_ftype_v4si
21482     = build_function_type_list (V2DI_type_node, V4SI_type_node,
21483                                 NULL_TREE);
21484   tree v2di_ftype_pv2di
21485     = build_function_type_list (V2DI_type_node, pv2di_type_node,
21486                                 NULL_TREE);
21487   tree v16qi_ftype_v16qi_v16qi_int
21488     = build_function_type_list (V16QI_type_node, V16QI_type_node,
21489                                 V16QI_type_node, integer_type_node,
21490                                 NULL_TREE);
21491   tree v16qi_ftype_v16qi_v16qi_v16qi
21492     = build_function_type_list (V16QI_type_node, V16QI_type_node,
21493                                 V16QI_type_node, V16QI_type_node,
21494                                 NULL_TREE);
21495   tree v8hi_ftype_v8hi_v8hi_int
21496     = build_function_type_list (V8HI_type_node, V8HI_type_node,
21497                                 V8HI_type_node, integer_type_node,
21498                                 NULL_TREE);
21499   tree v4si_ftype_v4si_v4si_int
21500     = build_function_type_list (V4SI_type_node, V4SI_type_node,
21501                                 V4SI_type_node, integer_type_node,
21502                                 NULL_TREE);
21503   tree int_ftype_v2di_v2di
21504     = build_function_type_list (integer_type_node,
21505                                 V2DI_type_node, V2DI_type_node,
21506                                 NULL_TREE);
21507   tree int_ftype_v16qi_int_v16qi_int_int
21508     = build_function_type_list (integer_type_node,
21509                                 V16QI_type_node,
21510                                 integer_type_node,
21511                                 V16QI_type_node,
21512                                 integer_type_node,
21513                                 integer_type_node,
21514                                 NULL_TREE);
21515   tree v16qi_ftype_v16qi_int_v16qi_int_int
21516     = build_function_type_list (V16QI_type_node,
21517                                 V16QI_type_node,
21518                                 integer_type_node,
21519                                 V16QI_type_node,
21520                                 integer_type_node,
21521                                 integer_type_node,
21522                                 NULL_TREE);
21523   tree int_ftype_v16qi_v16qi_int
21524     = build_function_type_list (integer_type_node,
21525                                 V16QI_type_node,
21526                                 V16QI_type_node,
21527                                 integer_type_node,
21528                                 NULL_TREE);
21529
21530   /* SSE5 instructions */
21531   tree v2di_ftype_v2di_v2di_v2di
21532     = build_function_type_list (V2DI_type_node,
21533                                 V2DI_type_node,
21534                                 V2DI_type_node,
21535                                 V2DI_type_node,
21536                                 NULL_TREE);
21537
21538   tree v4si_ftype_v4si_v4si_v4si
21539     = build_function_type_list (V4SI_type_node,
21540                                 V4SI_type_node,
21541                                 V4SI_type_node,
21542                                 V4SI_type_node,
21543                                 NULL_TREE);
21544
21545   tree v4si_ftype_v4si_v4si_v2di
21546     = build_function_type_list (V4SI_type_node,
21547                                 V4SI_type_node,
21548                                 V4SI_type_node,
21549                                 V2DI_type_node,
21550                                 NULL_TREE);
21551
21552   tree v8hi_ftype_v8hi_v8hi_v8hi
21553     = build_function_type_list (V8HI_type_node,
21554                                 V8HI_type_node,
21555                                 V8HI_type_node,
21556                                 V8HI_type_node,
21557                                 NULL_TREE);
21558
21559   tree v8hi_ftype_v8hi_v8hi_v4si
21560     = build_function_type_list (V8HI_type_node,
21561                                 V8HI_type_node,
21562                                 V8HI_type_node,
21563                                 V4SI_type_node,
21564                                 NULL_TREE);
21565
21566   tree v2df_ftype_v2df_v2df_v16qi
21567     = build_function_type_list (V2DF_type_node,
21568                                 V2DF_type_node,
21569                                 V2DF_type_node,
21570                                 V16QI_type_node,
21571                                 NULL_TREE);
21572
21573   tree v4sf_ftype_v4sf_v4sf_v16qi
21574     = build_function_type_list (V4SF_type_node,
21575                                 V4SF_type_node,
21576                                 V4SF_type_node,
21577                                 V16QI_type_node,
21578                                 NULL_TREE);
21579
21580   tree v2di_ftype_v2di_si
21581     = build_function_type_list (V2DI_type_node,
21582                                 V2DI_type_node,
21583                                 integer_type_node,
21584                                 NULL_TREE);
21585
21586   tree v4si_ftype_v4si_si
21587     = build_function_type_list (V4SI_type_node,
21588                                 V4SI_type_node,
21589                                 integer_type_node,
21590                                 NULL_TREE);
21591
21592   tree v8hi_ftype_v8hi_si
21593     = build_function_type_list (V8HI_type_node,
21594                                 V8HI_type_node,
21595                                 integer_type_node,
21596                                 NULL_TREE);
21597
21598   tree v16qi_ftype_v16qi_si
21599     = build_function_type_list (V16QI_type_node,
21600                                 V16QI_type_node,
21601                                 integer_type_node,
21602                                 NULL_TREE);
21603   tree v4sf_ftype_v4hi
21604     = build_function_type_list (V4SF_type_node,
21605                                 V4HI_type_node,
21606                                 NULL_TREE);
21607
21608   tree v4hi_ftype_v4sf
21609     = build_function_type_list (V4HI_type_node,
21610                                 V4SF_type_node,
21611                                 NULL_TREE);
21612
21613   tree v2di_ftype_v2di
21614     = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
21615
21616   tree v16qi_ftype_v8hi_v8hi
21617     = build_function_type_list (V16QI_type_node,
21618                                 V8HI_type_node, V8HI_type_node,
21619                                 NULL_TREE);
21620   tree v8hi_ftype_v4si_v4si
21621     = build_function_type_list (V8HI_type_node,
21622                                 V4SI_type_node, V4SI_type_node,
21623                                 NULL_TREE);
21624   tree v8hi_ftype_v16qi_v16qi 
21625     = build_function_type_list (V8HI_type_node,
21626                                 V16QI_type_node, V16QI_type_node,
21627                                 NULL_TREE);
21628   tree v4hi_ftype_v8qi_v8qi 
21629     = build_function_type_list (V4HI_type_node,
21630                                 V8QI_type_node, V8QI_type_node,
21631                                 NULL_TREE);
21632   tree unsigned_ftype_unsigned_uchar
21633     = build_function_type_list (unsigned_type_node,
21634                                 unsigned_type_node,
21635                                 unsigned_char_type_node,
21636                                 NULL_TREE);
21637   tree unsigned_ftype_unsigned_ushort
21638     = build_function_type_list (unsigned_type_node,
21639                                 unsigned_type_node,
21640                                 short_unsigned_type_node,
21641                                 NULL_TREE);
21642   tree unsigned_ftype_unsigned_unsigned
21643     = build_function_type_list (unsigned_type_node,
21644                                 unsigned_type_node,
21645                                 unsigned_type_node,
21646                                 NULL_TREE);
21647   tree uint64_ftype_uint64_uint64
21648     = build_function_type_list (long_long_unsigned_type_node,
21649                                 long_long_unsigned_type_node,
21650                                 long_long_unsigned_type_node,
21651                                 NULL_TREE);
21652   tree float_ftype_float
21653     = build_function_type_list (float_type_node,
21654                                 float_type_node,
21655                                 NULL_TREE);
21656
21657   /* AVX builtins  */
21658   tree V32QI_type_node = build_vector_type_for_mode (char_type_node,
21659                                                      V32QImode);
21660   tree V8SI_type_node = build_vector_type_for_mode (intSI_type_node,
21661                                                     V8SImode);
21662   tree V8SF_type_node = build_vector_type_for_mode (float_type_node,
21663                                                     V8SFmode);
21664   tree V4DI_type_node = build_vector_type_for_mode (long_long_integer_type_node,
21665                                                     V4DImode);
21666   tree V4DF_type_node = build_vector_type_for_mode (double_type_node,
21667                                                     V4DFmode);
21668   tree v8sf_ftype_v8sf
21669     = build_function_type_list (V8SF_type_node,
21670                                 V8SF_type_node,
21671                                 NULL_TREE);
21672   tree v8si_ftype_v8sf
21673     = build_function_type_list (V8SI_type_node,
21674                                 V8SF_type_node,
21675                                 NULL_TREE);
21676   tree v8sf_ftype_v8si
21677     = build_function_type_list (V8SF_type_node,
21678                                 V8SI_type_node,
21679                                 NULL_TREE);
21680   tree v4si_ftype_v4df
21681     = build_function_type_list (V4SI_type_node,
21682                                 V4DF_type_node,
21683                                 NULL_TREE);
21684   tree v4df_ftype_v4df
21685     = build_function_type_list (V4DF_type_node,
21686                                 V4DF_type_node,
21687                                 NULL_TREE);
21688   tree v4df_ftype_v4si
21689     = build_function_type_list (V4DF_type_node,
21690                                 V4SI_type_node,
21691                                 NULL_TREE);
21692   tree v4df_ftype_v4sf
21693     = build_function_type_list (V4DF_type_node,
21694                                 V4SF_type_node,
21695                                 NULL_TREE);
21696   tree v4sf_ftype_v4df
21697     = build_function_type_list (V4SF_type_node,
21698                                 V4DF_type_node,
21699                                 NULL_TREE);
21700   tree v8sf_ftype_v8sf_v8sf
21701     = build_function_type_list (V8SF_type_node,
21702                                 V8SF_type_node, V8SF_type_node,
21703                                 NULL_TREE);
21704   tree v4df_ftype_v4df_v4df
21705     = build_function_type_list (V4DF_type_node,
21706                                 V4DF_type_node, V4DF_type_node,
21707                                 NULL_TREE);
21708   tree v8sf_ftype_v8sf_int
21709     = build_function_type_list (V8SF_type_node,
21710                                 V8SF_type_node, integer_type_node,
21711                                 NULL_TREE);
21712   tree v4si_ftype_v8si_int
21713     = build_function_type_list (V4SI_type_node,
21714                                 V8SI_type_node, integer_type_node,
21715                                 NULL_TREE);
21716   tree v4df_ftype_v4df_int
21717     = build_function_type_list (V4DF_type_node,
21718                                 V4DF_type_node, integer_type_node,
21719                                 NULL_TREE);
21720   tree v4sf_ftype_v8sf_int
21721     = build_function_type_list (V4SF_type_node,
21722                                 V8SF_type_node, integer_type_node,
21723                                 NULL_TREE);
21724   tree v2df_ftype_v4df_int
21725     = build_function_type_list (V2DF_type_node,
21726                                 V4DF_type_node, integer_type_node,
21727                                 NULL_TREE);
21728   tree v8sf_ftype_v8sf_v8sf_int
21729     = build_function_type_list (V8SF_type_node,
21730                                 V8SF_type_node, V8SF_type_node,
21731                                 integer_type_node,
21732                                 NULL_TREE);
21733   tree v8sf_ftype_v8sf_v8sf_v8sf
21734     = build_function_type_list (V8SF_type_node,
21735                                 V8SF_type_node, V8SF_type_node,
21736                                 V8SF_type_node,
21737                                 NULL_TREE);
21738   tree v4df_ftype_v4df_v4df_v4df
21739     = build_function_type_list (V4DF_type_node,
21740                                 V4DF_type_node, V4DF_type_node,
21741                                 V4DF_type_node,
21742                                 NULL_TREE);
21743   tree v8si_ftype_v8si_v8si_int
21744     = build_function_type_list (V8SI_type_node,
21745                                 V8SI_type_node, V8SI_type_node,
21746                                 integer_type_node,
21747                                 NULL_TREE);
21748   tree v4df_ftype_v4df_v4df_int
21749     = build_function_type_list (V4DF_type_node,
21750                                 V4DF_type_node, V4DF_type_node,
21751                                 integer_type_node,
21752                                 NULL_TREE);
21753   tree v8sf_ftype_v8sf_v8sf_v8si_int
21754     = build_function_type_list (V8SF_type_node,
21755                                 V8SF_type_node, V8SF_type_node,
21756                                 V8SI_type_node, integer_type_node,
21757                                 NULL_TREE);
21758   tree v4df_ftype_v4df_v4df_v4di_int
21759     = build_function_type_list (V4DF_type_node,
21760                                 V4DF_type_node, V4DF_type_node,
21761                                 V4DI_type_node, integer_type_node,
21762                                 NULL_TREE);
21763   tree v4sf_ftype_v4sf_v4sf_v4si_int
21764     = build_function_type_list (V4SF_type_node,
21765                                 V4SF_type_node, V4SF_type_node,
21766                                 V4SI_type_node, integer_type_node,
21767                                 NULL_TREE);
21768   tree v2df_ftype_v2df_v2df_v2di_int
21769     = build_function_type_list (V2DF_type_node,
21770                                 V2DF_type_node, V2DF_type_node,
21771                                 V2DI_type_node, integer_type_node,
21772                                 NULL_TREE);
21773   tree v8sf_ftype_pcfloat
21774     = build_function_type_list (V8SF_type_node,
21775                                 pcfloat_type_node,
21776                                 NULL_TREE);
21777   tree v4df_ftype_pcdouble
21778     = build_function_type_list (V4DF_type_node,
21779                                 pcdouble_type_node,
21780                                 NULL_TREE);
21781   tree pcv4sf_type_node
21782     = build_pointer_type (build_type_variant (V4SF_type_node, 1, 0));
21783   tree pcv2df_type_node
21784     = build_pointer_type (build_type_variant (V2DF_type_node, 1, 0));
21785   tree v8sf_ftype_pcv4sf
21786     = build_function_type_list (V8SF_type_node,
21787                                 pcv4sf_type_node,
21788                                 NULL_TREE);
21789   tree v4df_ftype_pcv2df
21790     = build_function_type_list (V4DF_type_node,
21791                                 pcv2df_type_node,
21792                                 NULL_TREE);
21793   tree v32qi_ftype_pcchar
21794     = build_function_type_list (V32QI_type_node,
21795                                 pcchar_type_node,
21796                                 NULL_TREE);
21797   tree void_ftype_pchar_v32qi
21798     = build_function_type_list (void_type_node,
21799                                 pchar_type_node, V32QI_type_node,
21800                                 NULL_TREE);
21801   tree v8si_ftype_v8si_v4si_int
21802     = build_function_type_list (V8SI_type_node,
21803                                 V8SI_type_node, V4SI_type_node,
21804                                 integer_type_node,
21805                                 NULL_TREE);
21806   tree v8sf_ftype_v8sf_v4sf_int
21807     = build_function_type_list (V8SF_type_node,
21808                                 V8SF_type_node, V4SF_type_node,
21809                                 integer_type_node,
21810                                 NULL_TREE);
21811   tree v4df_ftype_v4df_v2df_int
21812     = build_function_type_list (V4DF_type_node,
21813                                 V4DF_type_node, V2DF_type_node,
21814                                 integer_type_node,
21815                                 NULL_TREE);
21816   tree void_ftype_pfloat_v8sf
21817     = build_function_type_list (void_type_node,
21818                                 pfloat_type_node, V8SF_type_node,
21819                                 NULL_TREE);
21820   tree void_ftype_pdouble_v4df
21821     = build_function_type_list (void_type_node,
21822                                 pdouble_type_node, V4DF_type_node,
21823                                 NULL_TREE);
21824   tree pv8sf_type_node = build_pointer_type (V8SF_type_node);
21825   tree pv4sf_type_node = build_pointer_type (V4SF_type_node);
21826   tree pv4df_type_node = build_pointer_type (V4DF_type_node);
21827   tree pv2df_type_node = build_pointer_type (V2DF_type_node);
21828   tree pcv8sf_type_node
21829     = build_pointer_type (build_type_variant (V8SF_type_node, 1, 0));
21830   tree pcv4df_type_node
21831     = build_pointer_type (build_type_variant (V4DF_type_node, 1, 0));
21832   tree v8sf_ftype_pcv8sf_v8sf
21833     = build_function_type_list (V8SF_type_node,
21834                                 pcv8sf_type_node, V8SF_type_node,
21835                                 NULL_TREE);
21836   tree v4df_ftype_pcv4df_v4df
21837     = build_function_type_list (V4DF_type_node,
21838                                 pcv4df_type_node, V4DF_type_node,
21839                                 NULL_TREE);
21840   tree v4sf_ftype_pcv4sf_v4sf
21841     = build_function_type_list (V4SF_type_node,
21842                                 pcv4sf_type_node, V4SF_type_node,
21843                                 NULL_TREE);
21844   tree v2df_ftype_pcv2df_v2df
21845     = build_function_type_list (V2DF_type_node,
21846                                 pcv2df_type_node, V2DF_type_node,
21847                                 NULL_TREE);
21848   tree void_ftype_pv8sf_v8sf_v8sf
21849     = build_function_type_list (void_type_node,
21850                                 pv8sf_type_node, V8SF_type_node,
21851                                 V8SF_type_node,
21852                                 NULL_TREE);
21853   tree void_ftype_pv4df_v4df_v4df
21854     = build_function_type_list (void_type_node,
21855                                 pv4df_type_node, V4DF_type_node,
21856                                 V4DF_type_node,
21857                                 NULL_TREE);
21858   tree void_ftype_pv4sf_v4sf_v4sf
21859     = build_function_type_list (void_type_node,
21860                                 pv4sf_type_node, V4SF_type_node,
21861                                 V4SF_type_node,
21862                                 NULL_TREE);
21863   tree void_ftype_pv2df_v2df_v2df
21864     = build_function_type_list (void_type_node,
21865                                 pv2df_type_node, V2DF_type_node,
21866                                 V2DF_type_node,
21867                                 NULL_TREE);
21868   tree v4df_ftype_v2df
21869     = build_function_type_list (V4DF_type_node,
21870                                 V2DF_type_node,
21871                                 NULL_TREE);
21872   tree v8sf_ftype_v4sf
21873     = build_function_type_list (V8SF_type_node,
21874                                 V4SF_type_node,
21875                                 NULL_TREE);
21876   tree v8si_ftype_v4si
21877     = build_function_type_list (V8SI_type_node,
21878                                 V4SI_type_node,
21879                                 NULL_TREE);
21880   tree v2df_ftype_v4df
21881     = build_function_type_list (V2DF_type_node,
21882                                 V4DF_type_node,
21883                                 NULL_TREE);
21884   tree v4sf_ftype_v8sf
21885     = build_function_type_list (V4SF_type_node,
21886                                 V8SF_type_node,
21887                                 NULL_TREE);
21888   tree v4si_ftype_v8si
21889     = build_function_type_list (V4SI_type_node,
21890                                 V8SI_type_node,
21891                                 NULL_TREE);
21892   tree int_ftype_v4df
21893     = build_function_type_list (integer_type_node,
21894                                 V4DF_type_node,
21895                                 NULL_TREE);
21896   tree int_ftype_v8sf
21897     = build_function_type_list (integer_type_node,
21898                                 V8SF_type_node,
21899                                 NULL_TREE);
21900   tree int_ftype_v8sf_v8sf
21901     = build_function_type_list (integer_type_node,
21902                                 V8SF_type_node, V8SF_type_node,
21903                                 NULL_TREE);
21904   tree int_ftype_v4di_v4di
21905     = build_function_type_list (integer_type_node,
21906                                 V4DI_type_node, V4DI_type_node,
21907                                 NULL_TREE);
21908   tree int_ftype_v4df_v4df
21909     = build_function_type_list (integer_type_node,
21910                                 V4DF_type_node, V4DF_type_node,
21911                                 NULL_TREE);
21912   tree v8sf_ftype_v8sf_v8si
21913     = build_function_type_list (V8SF_type_node,
21914                                 V8SF_type_node, V8SI_type_node,
21915                                 NULL_TREE);
21916   tree v4df_ftype_v4df_v4di
21917     = build_function_type_list (V4DF_type_node,
21918                                 V4DF_type_node, V4DI_type_node,
21919                                 NULL_TREE);
21920   tree v4sf_ftype_v4sf_v4si
21921     = build_function_type_list (V4SF_type_node,
21922                                 V4SF_type_node, V4SI_type_node, NULL_TREE);
21923   tree v2df_ftype_v2df_v2di
21924     = build_function_type_list (V2DF_type_node,
21925                                 V2DF_type_node, V2DI_type_node, NULL_TREE);
21926
21927   tree ftype;
21928
21929   /* Add all special builtins with variable number of operands.  */
21930   for (i = 0, d = bdesc_special_args;
21931        i < ARRAY_SIZE (bdesc_special_args);
21932        i++, d++)
21933     {
21934       tree type;
21935
21936       if (d->name == 0)
21937         continue;
21938
21939       switch ((enum ix86_special_builtin_type) d->flag)
21940         {
21941         case VOID_FTYPE_VOID:
21942           type = void_ftype_void;
21943           break;
21944         case V32QI_FTYPE_PCCHAR:
21945           type = v32qi_ftype_pcchar;
21946           break;
21947         case V16QI_FTYPE_PCCHAR:
21948           type = v16qi_ftype_pcchar;
21949           break;
21950         case V8SF_FTYPE_PCV4SF:
21951           type = v8sf_ftype_pcv4sf;
21952           break;
21953         case V8SF_FTYPE_PCFLOAT:
21954           type = v8sf_ftype_pcfloat;
21955           break;
21956         case V4DF_FTYPE_PCV2DF:
21957           type = v4df_ftype_pcv2df;
21958           break;
21959         case V4DF_FTYPE_PCDOUBLE:
21960           type = v4df_ftype_pcdouble;
21961           break;
21962         case V4SF_FTYPE_PCFLOAT:
21963           type = v4sf_ftype_pcfloat;
21964           break;
21965         case V2DI_FTYPE_PV2DI:
21966           type = v2di_ftype_pv2di;
21967           break;
21968         case V2DF_FTYPE_PCDOUBLE:
21969           type = v2df_ftype_pcdouble;
21970           break;
21971         case V8SF_FTYPE_PCV8SF_V8SF:
21972           type = v8sf_ftype_pcv8sf_v8sf;
21973           break;
21974         case V4DF_FTYPE_PCV4DF_V4DF:
21975           type = v4df_ftype_pcv4df_v4df;
21976           break;
21977         case V4SF_FTYPE_V4SF_PCV2SF:
21978           type = v4sf_ftype_v4sf_pcv2sf;
21979           break;
21980         case V4SF_FTYPE_PCV4SF_V4SF:
21981           type = v4sf_ftype_pcv4sf_v4sf;
21982           break;
21983         case V2DF_FTYPE_V2DF_PCDOUBLE:
21984           type = v2df_ftype_v2df_pcdouble;
21985           break;
21986         case V2DF_FTYPE_PCV2DF_V2DF:
21987           type = v2df_ftype_pcv2df_v2df;
21988           break;
21989         case VOID_FTYPE_PV2SF_V4SF:
21990           type = void_ftype_pv2sf_v4sf;
21991           break;
21992         case VOID_FTYPE_PV2DI_V2DI:
21993           type = void_ftype_pv2di_v2di;
21994           break;
21995         case VOID_FTYPE_PCHAR_V32QI:
21996           type = void_ftype_pchar_v32qi;
21997           break;
21998         case VOID_FTYPE_PCHAR_V16QI:
21999           type = void_ftype_pchar_v16qi;
22000           break;
22001         case VOID_FTYPE_PFLOAT_V8SF:
22002           type = void_ftype_pfloat_v8sf;
22003           break;
22004         case VOID_FTYPE_PFLOAT_V4SF:
22005           type = void_ftype_pfloat_v4sf;
22006           break;
22007         case VOID_FTYPE_PDOUBLE_V4DF:
22008           type = void_ftype_pdouble_v4df;
22009           break;
22010         case VOID_FTYPE_PDOUBLE_V2DF:
22011           type = void_ftype_pdouble_v2df;
22012           break;
22013         case VOID_FTYPE_PDI_DI:
22014           type = void_ftype_pdi_di;
22015           break;
22016         case VOID_FTYPE_PINT_INT:
22017           type = void_ftype_pint_int;
22018           break;
22019         case VOID_FTYPE_PV8SF_V8SF_V8SF:
22020           type = void_ftype_pv8sf_v8sf_v8sf;
22021           break;
22022         case VOID_FTYPE_PV4DF_V4DF_V4DF:
22023           type = void_ftype_pv4df_v4df_v4df;
22024           break;
22025         case VOID_FTYPE_PV4SF_V4SF_V4SF:
22026           type = void_ftype_pv4sf_v4sf_v4sf;
22027           break;
22028         case VOID_FTYPE_PV2DF_V2DF_V2DF:
22029           type = void_ftype_pv2df_v2df_v2df;
22030           break;
22031         default:
22032           gcc_unreachable ();
22033         }
22034
22035       def_builtin (d->mask, d->name, type, d->code);
22036     }
22037
22038   /* Add all builtins with variable number of operands.  */
22039   for (i = 0, d = bdesc_args;
22040        i < ARRAY_SIZE (bdesc_args);
22041        i++, d++)
22042     {
22043       tree type;
22044
22045       if (d->name == 0)
22046         continue;
22047
22048       switch ((enum ix86_builtin_type) d->flag)
22049         {
22050         case FLOAT_FTYPE_FLOAT:
22051           type = float_ftype_float;
22052           break;
22053         case INT_FTYPE_V8SF_V8SF_PTEST:
22054           type = int_ftype_v8sf_v8sf;
22055           break;
22056         case INT_FTYPE_V4DI_V4DI_PTEST:
22057           type = int_ftype_v4di_v4di;
22058           break;
22059         case INT_FTYPE_V4DF_V4DF_PTEST:
22060           type = int_ftype_v4df_v4df;
22061           break;
22062         case INT_FTYPE_V4SF_V4SF_PTEST:
22063           type = int_ftype_v4sf_v4sf;
22064           break;
22065         case INT_FTYPE_V2DI_V2DI_PTEST:
22066           type = int_ftype_v2di_v2di;
22067           break;
22068         case INT_FTYPE_V2DF_V2DF_PTEST:
22069           type = int_ftype_v2df_v2df;
22070           break;
22071         case INT64_FTYPE_V4SF:
22072           type = int64_ftype_v4sf;
22073           break;
22074         case INT64_FTYPE_V2DF:
22075           type = int64_ftype_v2df;
22076           break;
22077         case INT_FTYPE_V16QI:
22078           type = int_ftype_v16qi;
22079           break;
22080         case INT_FTYPE_V8QI:
22081           type = int_ftype_v8qi;
22082           break;
22083         case INT_FTYPE_V8SF:
22084           type = int_ftype_v8sf;
22085           break;
22086         case INT_FTYPE_V4DF:
22087           type = int_ftype_v4df;
22088           break;
22089         case INT_FTYPE_V4SF:
22090           type = int_ftype_v4sf;
22091           break;
22092         case INT_FTYPE_V2DF:
22093           type = int_ftype_v2df;
22094           break;
22095         case V16QI_FTYPE_V16QI:
22096           type = v16qi_ftype_v16qi;
22097           break;
22098         case V8SI_FTYPE_V8SF:
22099           type = v8si_ftype_v8sf;
22100           break;
22101         case V8SI_FTYPE_V4SI:
22102           type = v8si_ftype_v4si;
22103           break;
22104         case V8HI_FTYPE_V8HI:
22105           type = v8hi_ftype_v8hi;
22106           break;
22107         case V8HI_FTYPE_V16QI:
22108           type = v8hi_ftype_v16qi;
22109           break;
22110         case V8QI_FTYPE_V8QI:
22111           type = v8qi_ftype_v8qi;
22112           break;
22113         case V8SF_FTYPE_V8SF:
22114           type = v8sf_ftype_v8sf;
22115           break;
22116         case V8SF_FTYPE_V8SI:
22117           type = v8sf_ftype_v8si;
22118           break;
22119         case V8SF_FTYPE_V4SF:
22120           type = v8sf_ftype_v4sf;
22121           break;
22122         case V4SI_FTYPE_V4DF:
22123           type = v4si_ftype_v4df;
22124           break;
22125         case V4SI_FTYPE_V4SI:
22126           type = v4si_ftype_v4si;
22127           break;
22128         case V4SI_FTYPE_V16QI:
22129           type = v4si_ftype_v16qi;
22130           break;
22131         case V4SI_FTYPE_V8SI:
22132           type = v4si_ftype_v8si;
22133           break;
22134         case V4SI_FTYPE_V8HI:
22135           type = v4si_ftype_v8hi;
22136           break;
22137         case V4SI_FTYPE_V4SF:
22138           type = v4si_ftype_v4sf;
22139           break;
22140         case V4SI_FTYPE_V2DF:
22141           type = v4si_ftype_v2df;
22142           break;
22143         case V4HI_FTYPE_V4HI:
22144           type = v4hi_ftype_v4hi;
22145           break;
22146         case V4DF_FTYPE_V4DF:
22147           type = v4df_ftype_v4df;
22148           break;
22149         case V4DF_FTYPE_V4SI:
22150           type = v4df_ftype_v4si;
22151           break;
22152         case V4DF_FTYPE_V4SF:
22153           type = v4df_ftype_v4sf;
22154           break;
22155         case V4DF_FTYPE_V2DF:
22156           type = v4df_ftype_v2df;
22157           break;
22158         case V4SF_FTYPE_V4SF:
22159         case V4SF_FTYPE_V4SF_VEC_MERGE:
22160           type = v4sf_ftype_v4sf;
22161           break;
22162         case V4SF_FTYPE_V8SF:
22163           type = v4sf_ftype_v8sf;
22164           break;
22165         case V4SF_FTYPE_V4SI:
22166           type = v4sf_ftype_v4si;
22167           break;
22168         case V4SF_FTYPE_V4DF:
22169           type = v4sf_ftype_v4df;
22170           break;
22171         case V4SF_FTYPE_V2DF:
22172           type = v4sf_ftype_v2df;
22173           break;
22174         case V2DI_FTYPE_V2DI:
22175           type = v2di_ftype_v2di;
22176           break;
22177         case V2DI_FTYPE_V16QI:
22178           type = v2di_ftype_v16qi;
22179           break;
22180         case V2DI_FTYPE_V8HI:
22181           type = v2di_ftype_v8hi;
22182           break;
22183         case V2DI_FTYPE_V4SI:
22184           type = v2di_ftype_v4si;
22185           break;
22186         case V2SI_FTYPE_V2SI:
22187           type = v2si_ftype_v2si;
22188           break;
22189         case V2SI_FTYPE_V4SF:
22190           type = v2si_ftype_v4sf;
22191           break;
22192         case V2SI_FTYPE_V2DF:
22193           type = v2si_ftype_v2df;
22194           break;
22195         case V2SI_FTYPE_V2SF:
22196           type = v2si_ftype_v2sf;
22197           break;
22198         case V2DF_FTYPE_V4DF:
22199           type = v2df_ftype_v4df;
22200           break;
22201         case V2DF_FTYPE_V4SF:
22202           type = v2df_ftype_v4sf;
22203           break;
22204         case V2DF_FTYPE_V2DF:
22205         case V2DF_FTYPE_V2DF_VEC_MERGE:
22206           type = v2df_ftype_v2df;
22207           break;
22208         case V2DF_FTYPE_V2SI:
22209           type = v2df_ftype_v2si;
22210           break;
22211         case V2DF_FTYPE_V4SI:
22212           type = v2df_ftype_v4si;
22213           break;
22214         case V2SF_FTYPE_V2SF:
22215           type = v2sf_ftype_v2sf;
22216           break;
22217         case V2SF_FTYPE_V2SI:
22218           type = v2sf_ftype_v2si;
22219           break;
22220         case V16QI_FTYPE_V16QI_V16QI:
22221           type = v16qi_ftype_v16qi_v16qi;
22222           break;
22223         case V16QI_FTYPE_V8HI_V8HI:
22224           type = v16qi_ftype_v8hi_v8hi;
22225           break;
22226         case V8QI_FTYPE_V8QI_V8QI:
22227           type = v8qi_ftype_v8qi_v8qi;
22228           break;
22229         case V8QI_FTYPE_V4HI_V4HI:
22230           type = v8qi_ftype_v4hi_v4hi;
22231           break;
22232         case V8HI_FTYPE_V8HI_V8HI:
22233         case V8HI_FTYPE_V8HI_V8HI_COUNT:
22234           type = v8hi_ftype_v8hi_v8hi;
22235           break;
22236         case V8HI_FTYPE_V16QI_V16QI:
22237           type = v8hi_ftype_v16qi_v16qi;
22238           break;
22239         case V8HI_FTYPE_V4SI_V4SI:
22240           type = v8hi_ftype_v4si_v4si;
22241           break;
22242         case V8HI_FTYPE_V8HI_SI_COUNT:
22243           type = v8hi_ftype_v8hi_int;
22244           break;
22245         case V8SF_FTYPE_V8SF_V8SF:
22246           type = v8sf_ftype_v8sf_v8sf;
22247           break;
22248         case V8SF_FTYPE_V8SF_V8SI:
22249           type = v8sf_ftype_v8sf_v8si;
22250           break;
22251         case V4SI_FTYPE_V4SI_V4SI:
22252         case V4SI_FTYPE_V4SI_V4SI_COUNT:
22253           type = v4si_ftype_v4si_v4si;
22254           break;
22255         case V4SI_FTYPE_V8HI_V8HI:
22256           type = v4si_ftype_v8hi_v8hi;
22257           break;
22258         case V4SI_FTYPE_V4SF_V4SF:
22259           type = v4si_ftype_v4sf_v4sf;
22260           break;
22261         case V4SI_FTYPE_V2DF_V2DF:
22262           type = v4si_ftype_v2df_v2df;
22263           break;
22264         case V4SI_FTYPE_V4SI_SI_COUNT:
22265           type = v4si_ftype_v4si_int;
22266           break;
22267         case V4HI_FTYPE_V4HI_V4HI:
22268         case V4HI_FTYPE_V4HI_V4HI_COUNT:
22269           type = v4hi_ftype_v4hi_v4hi;
22270           break;
22271         case V4HI_FTYPE_V8QI_V8QI:
22272           type = v4hi_ftype_v8qi_v8qi;
22273           break;
22274         case V4HI_FTYPE_V2SI_V2SI:
22275           type = v4hi_ftype_v2si_v2si;
22276           break;
22277         case V4HI_FTYPE_V4HI_SI_COUNT:
22278           type = v4hi_ftype_v4hi_int;
22279           break;
22280         case V4DF_FTYPE_V4DF_V4DF:
22281           type = v4df_ftype_v4df_v4df;
22282           break;
22283         case V4DF_FTYPE_V4DF_V4DI:
22284           type = v4df_ftype_v4df_v4di;
22285           break;
22286         case V4SF_FTYPE_V4SF_V4SF:
22287         case V4SF_FTYPE_V4SF_V4SF_SWAP:
22288           type = v4sf_ftype_v4sf_v4sf;
22289           break;
22290         case V4SF_FTYPE_V4SF_V4SI:
22291           type = v4sf_ftype_v4sf_v4si;
22292           break;
22293         case V4SF_FTYPE_V4SF_V2SI:
22294           type = v4sf_ftype_v4sf_v2si;
22295           break;
22296         case V4SF_FTYPE_V4SF_V2DF:
22297           type = v4sf_ftype_v4sf_v2df;
22298           break;
22299         case V4SF_FTYPE_V4SF_DI:
22300           type = v4sf_ftype_v4sf_int64;
22301           break;
22302         case V4SF_FTYPE_V4SF_SI:
22303           type = v4sf_ftype_v4sf_int;
22304           break;
22305         case V2DI_FTYPE_V2DI_V2DI:
22306         case V2DI_FTYPE_V2DI_V2DI_COUNT:
22307           type = v2di_ftype_v2di_v2di;
22308           break;
22309         case V2DI_FTYPE_V16QI_V16QI:
22310           type = v2di_ftype_v16qi_v16qi;
22311           break;
22312         case V2DI_FTYPE_V4SI_V4SI:
22313           type = v2di_ftype_v4si_v4si;
22314           break;
22315         case V2DI_FTYPE_V2DI_V16QI:
22316           type = v2di_ftype_v2di_v16qi;
22317           break;
22318         case V2DI_FTYPE_V2DF_V2DF:
22319           type = v2di_ftype_v2df_v2df;
22320           break;
22321         case V2DI_FTYPE_V2DI_SI_COUNT:
22322           type = v2di_ftype_v2di_int;
22323           break;
22324         case V2SI_FTYPE_V2SI_V2SI:
22325         case V2SI_FTYPE_V2SI_V2SI_COUNT:
22326           type = v2si_ftype_v2si_v2si;
22327           break;
22328         case V2SI_FTYPE_V4HI_V4HI:
22329           type = v2si_ftype_v4hi_v4hi;
22330           break;
22331         case V2SI_FTYPE_V2SF_V2SF:
22332           type = v2si_ftype_v2sf_v2sf;
22333           break;
22334         case V2SI_FTYPE_V2SI_SI_COUNT:
22335           type = v2si_ftype_v2si_int;
22336           break;
22337         case V2DF_FTYPE_V2DF_V2DF:
22338         case V2DF_FTYPE_V2DF_V2DF_SWAP:
22339           type = v2df_ftype_v2df_v2df;
22340           break;
22341         case V2DF_FTYPE_V2DF_V4SF:
22342           type = v2df_ftype_v2df_v4sf;
22343           break;
22344         case V2DF_FTYPE_V2DF_V2DI:
22345           type = v2df_ftype_v2df_v2di;
22346           break;
22347         case V2DF_FTYPE_V2DF_DI:
22348           type = v2df_ftype_v2df_int64;
22349           break;
22350         case V2DF_FTYPE_V2DF_SI:
22351           type = v2df_ftype_v2df_int;
22352           break;
22353         case V2SF_FTYPE_V2SF_V2SF:
22354           type = v2sf_ftype_v2sf_v2sf;
22355           break;
22356         case V1DI_FTYPE_V1DI_V1DI:
22357         case V1DI_FTYPE_V1DI_V1DI_COUNT:
22358           type = v1di_ftype_v1di_v1di;
22359           break;
22360         case V1DI_FTYPE_V8QI_V8QI:
22361           type = v1di_ftype_v8qi_v8qi;
22362           break;
22363         case V1DI_FTYPE_V2SI_V2SI:
22364           type = v1di_ftype_v2si_v2si;
22365           break;
22366         case V1DI_FTYPE_V1DI_SI_COUNT:
22367           type = v1di_ftype_v1di_int;
22368           break;
22369         case UINT64_FTYPE_UINT64_UINT64:
22370           type = uint64_ftype_uint64_uint64;
22371           break;
22372         case UINT_FTYPE_UINT_UINT:
22373           type = unsigned_ftype_unsigned_unsigned;
22374           break;
22375         case UINT_FTYPE_UINT_USHORT:
22376           type = unsigned_ftype_unsigned_ushort;
22377           break;
22378         case UINT_FTYPE_UINT_UCHAR:
22379           type = unsigned_ftype_unsigned_uchar;
22380           break;
22381         case V8HI_FTYPE_V8HI_INT:
22382           type = v8hi_ftype_v8hi_int;
22383           break;
22384         case V8SF_FTYPE_V8SF_INT:
22385           type = v8sf_ftype_v8sf_int;
22386           break;
22387         case V4SI_FTYPE_V4SI_INT:
22388           type = v4si_ftype_v4si_int;
22389           break;
22390         case V4SI_FTYPE_V8SI_INT:
22391           type = v4si_ftype_v8si_int;
22392           break;
22393         case V4HI_FTYPE_V4HI_INT:
22394           type = v4hi_ftype_v4hi_int;
22395           break;
22396         case V4DF_FTYPE_V4DF_INT:
22397           type = v4df_ftype_v4df_int;
22398           break;
22399         case V4SF_FTYPE_V4SF_INT:
22400           type = v4sf_ftype_v4sf_int;
22401           break;
22402         case V4SF_FTYPE_V8SF_INT:
22403           type = v4sf_ftype_v8sf_int;
22404           break;
22405         case V2DI_FTYPE_V2DI_INT:
22406         case V2DI2TI_FTYPE_V2DI_INT:
22407           type = v2di_ftype_v2di_int;
22408           break;
22409         case V2DF_FTYPE_V2DF_INT:
22410           type = v2df_ftype_v2df_int;
22411           break;
22412         case V2DF_FTYPE_V4DF_INT:
22413           type = v2df_ftype_v4df_int;
22414           break;
22415         case V16QI_FTYPE_V16QI_V16QI_V16QI:
22416           type = v16qi_ftype_v16qi_v16qi_v16qi;
22417           break;
22418         case V8SF_FTYPE_V8SF_V8SF_V8SF:
22419           type = v8sf_ftype_v8sf_v8sf_v8sf;
22420           break;
22421         case V4DF_FTYPE_V4DF_V4DF_V4DF:
22422           type = v4df_ftype_v4df_v4df_v4df;
22423           break;
22424         case V4SF_FTYPE_V4SF_V4SF_V4SF:
22425           type = v4sf_ftype_v4sf_v4sf_v4sf;
22426           break;
22427         case V2DF_FTYPE_V2DF_V2DF_V2DF:
22428           type = v2df_ftype_v2df_v2df_v2df;
22429           break;
22430         case V16QI_FTYPE_V16QI_V16QI_INT:
22431           type = v16qi_ftype_v16qi_v16qi_int;
22432           break;
22433         case V8SI_FTYPE_V8SI_V8SI_INT:
22434           type = v8si_ftype_v8si_v8si_int;
22435           break;
22436         case V8SI_FTYPE_V8SI_V4SI_INT:
22437           type = v8si_ftype_v8si_v4si_int;
22438           break;
22439         case V8HI_FTYPE_V8HI_V8HI_INT:
22440           type = v8hi_ftype_v8hi_v8hi_int;
22441           break;
22442         case V8SF_FTYPE_V8SF_V8SF_INT:
22443           type = v8sf_ftype_v8sf_v8sf_int;
22444           break;
22445         case V8SF_FTYPE_V8SF_V4SF_INT:
22446           type = v8sf_ftype_v8sf_v4sf_int;
22447           break;
22448         case V4SI_FTYPE_V4SI_V4SI_INT:
22449           type = v4si_ftype_v4si_v4si_int;
22450           break;
22451         case V4DF_FTYPE_V4DF_V4DF_INT:
22452           type = v4df_ftype_v4df_v4df_int;
22453           break;
22454         case V4DF_FTYPE_V4DF_V2DF_INT:
22455           type = v4df_ftype_v4df_v2df_int;
22456           break;
22457         case V4SF_FTYPE_V4SF_V4SF_INT:
22458           type = v4sf_ftype_v4sf_v4sf_int;
22459           break;
22460         case V2DI_FTYPE_V2DI_V2DI_INT:
22461         case V2DI2TI_FTYPE_V2DI_V2DI_INT:
22462           type = v2di_ftype_v2di_v2di_int;
22463           break;
22464         case V2DF_FTYPE_V2DF_V2DF_INT:
22465           type = v2df_ftype_v2df_v2df_int;
22466           break;
22467         case V2DI_FTYPE_V2DI_UINT_UINT:
22468           type = v2di_ftype_v2di_unsigned_unsigned;
22469           break;
22470         case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
22471           type = v2di_ftype_v2di_v2di_unsigned_unsigned;
22472           break;
22473         case V1DI2DI_FTYPE_V1DI_V1DI_INT:
22474           type = v1di_ftype_v1di_v1di_int;
22475           break;
22476         case V8SF_FTYPE_V8SF_V8SF_V8SI_INT:
22477           type = v8sf_ftype_v8sf_v8sf_v8si_int;
22478           break;
22479         case V4DF_FTYPE_V4DF_V4DF_V4DI_INT:
22480           type = v4df_ftype_v4df_v4df_v4di_int;
22481           break;
22482         case V4SF_FTYPE_V4SF_V4SF_V4SI_INT:
22483           type = v4sf_ftype_v4sf_v4sf_v4si_int;
22484           break;
22485         case V2DF_FTYPE_V2DF_V2DF_V2DI_INT:
22486           type = v2df_ftype_v2df_v2df_v2di_int;
22487           break;
22488         default:
22489           gcc_unreachable ();
22490         }
22491
22492       def_builtin_const (d->mask, d->name, type, d->code);
22493     }
22494
22495   /* pcmpestr[im] insns.  */
22496   for (i = 0, d = bdesc_pcmpestr;
22497        i < ARRAY_SIZE (bdesc_pcmpestr);
22498        i++, d++)
22499     {
22500       if (d->code == IX86_BUILTIN_PCMPESTRM128)
22501         ftype = v16qi_ftype_v16qi_int_v16qi_int_int;
22502       else
22503         ftype = int_ftype_v16qi_int_v16qi_int_int;
22504       def_builtin_const (d->mask, d->name, ftype, d->code);
22505     }
22506
22507   /* pcmpistr[im] insns.  */
22508   for (i = 0, d = bdesc_pcmpistr;
22509        i < ARRAY_SIZE (bdesc_pcmpistr);
22510        i++, d++)
22511     {
22512       if (d->code == IX86_BUILTIN_PCMPISTRM128)
22513         ftype = v16qi_ftype_v16qi_v16qi_int;
22514       else
22515         ftype = int_ftype_v16qi_v16qi_int;
22516       def_builtin_const (d->mask, d->name, ftype, d->code);
22517     }
22518
22519   /* comi/ucomi insns.  */
22520   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
22521     if (d->mask == OPTION_MASK_ISA_SSE2)
22522       def_builtin_const (d->mask, d->name, int_ftype_v2df_v2df, d->code);
22523     else
22524       def_builtin_const (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
22525
22526   /* SSE */
22527   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr", void_ftype_unsigned, IX86_BUILTIN_LDMXCSR);
22528   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr", unsigned_ftype_void, IX86_BUILTIN_STMXCSR);
22529
22530   /* SSE or 3DNow!A */
22531   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_maskmovq", void_ftype_v8qi_v8qi_pchar, IX86_BUILTIN_MASKMOVQ);
22532
22533   /* SSE2 */
22534   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu", void_ftype_v16qi_v16qi_pchar, IX86_BUILTIN_MASKMOVDQU);
22535
22536   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush", void_ftype_pcvoid, IX86_BUILTIN_CLFLUSH);
22537   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence", void_ftype_void, IX86_BUILTIN_MFENCE);
22538
22539   /* SSE3.  */
22540   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor", void_ftype_pcvoid_unsigned_unsigned, IX86_BUILTIN_MONITOR);
22541   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait", void_ftype_unsigned_unsigned, IX86_BUILTIN_MWAIT);
22542
22543   /* AES */
22544   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENC128);
22545   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENCLAST128);
22546   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDEC128);
22547   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDECLAST128);
22548   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128", v2di_ftype_v2di, IX86_BUILTIN_AESIMC128);
22549   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128", v2di_ftype_v2di_int, IX86_BUILTIN_AESKEYGENASSIST128);
22550
22551   /* PCLMUL */
22552   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128", v2di_ftype_v2di_v2di_int, IX86_BUILTIN_PCLMULQDQ128);
22553
22554   /* AVX */
22555   def_builtin (OPTION_MASK_ISA_AVX, "__builtin_ia32_vzeroupper", void_ftype_void,
22556                TARGET_64BIT ? IX86_BUILTIN_VZEROUPPER_REX64 : IX86_BUILTIN_VZEROUPPER);
22557
22558   /* Access to the vec_init patterns.  */
22559   ftype = build_function_type_list (V2SI_type_node, integer_type_node,
22560                                     integer_type_node, NULL_TREE);
22561   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si", ftype, IX86_BUILTIN_VEC_INIT_V2SI);
22562
22563   ftype = build_function_type_list (V4HI_type_node, short_integer_type_node,
22564                                     short_integer_type_node,
22565                                     short_integer_type_node,
22566                                     short_integer_type_node, NULL_TREE);
22567   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi", ftype, IX86_BUILTIN_VEC_INIT_V4HI);
22568
22569   ftype = build_function_type_list (V8QI_type_node, char_type_node,
22570                                     char_type_node, char_type_node,
22571                                     char_type_node, char_type_node,
22572                                     char_type_node, char_type_node,
22573                                     char_type_node, NULL_TREE);
22574   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi", ftype, IX86_BUILTIN_VEC_INIT_V8QI);
22575
22576   /* Access to the vec_extract patterns.  */
22577   ftype = build_function_type_list (double_type_node, V2DF_type_node,
22578                                     integer_type_node, NULL_TREE);
22579   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df", ftype, IX86_BUILTIN_VEC_EXT_V2DF);
22580
22581   ftype = build_function_type_list (long_long_integer_type_node,
22582                                     V2DI_type_node, integer_type_node,
22583                                     NULL_TREE);
22584   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di", ftype, IX86_BUILTIN_VEC_EXT_V2DI);
22585
22586   ftype = build_function_type_list (float_type_node, V4SF_type_node,
22587                                     integer_type_node, NULL_TREE);
22588   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf", ftype, IX86_BUILTIN_VEC_EXT_V4SF);
22589
22590   ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
22591                                     integer_type_node, NULL_TREE);
22592   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si", ftype, IX86_BUILTIN_VEC_EXT_V4SI);
22593
22594   ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
22595                                     integer_type_node, NULL_TREE);
22596   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi", ftype, IX86_BUILTIN_VEC_EXT_V8HI);
22597
22598   ftype = build_function_type_list (intHI_type_node, V4HI_type_node,
22599                                     integer_type_node, NULL_TREE);
22600   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_ext_v4hi", ftype, IX86_BUILTIN_VEC_EXT_V4HI);
22601
22602   ftype = build_function_type_list (intSI_type_node, V2SI_type_node,
22603                                     integer_type_node, NULL_TREE);
22604   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si", ftype, IX86_BUILTIN_VEC_EXT_V2SI);
22605
22606   ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
22607                                     integer_type_node, NULL_TREE);
22608   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi", ftype, IX86_BUILTIN_VEC_EXT_V16QI);
22609
22610   /* Access to the vec_set patterns.  */
22611   ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
22612                                     intDI_type_node,
22613                                     integer_type_node, NULL_TREE);
22614   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_vec_set_v2di", ftype, IX86_BUILTIN_VEC_SET_V2DI);
22615
22616   ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
22617                                     float_type_node,
22618                                     integer_type_node, NULL_TREE);
22619   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf", ftype, IX86_BUILTIN_VEC_SET_V4SF);
22620
22621   ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
22622                                     intSI_type_node,
22623                                     integer_type_node, NULL_TREE);
22624   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si", ftype, IX86_BUILTIN_VEC_SET_V4SI);
22625
22626   ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
22627                                     intHI_type_node,
22628                                     integer_type_node, NULL_TREE);
22629   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi", ftype, IX86_BUILTIN_VEC_SET_V8HI);
22630
22631   ftype = build_function_type_list (V4HI_type_node, V4HI_type_node,
22632                                     intHI_type_node,
22633                                     integer_type_node, NULL_TREE);
22634   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_set_v4hi", ftype, IX86_BUILTIN_VEC_SET_V4HI);
22635
22636   ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
22637                                     intQI_type_node,
22638                                     integer_type_node, NULL_TREE);
22639   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi", ftype, IX86_BUILTIN_VEC_SET_V16QI);
22640
22641   /* Add SSE5 multi-arg argument instructions */
22642   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
22643     {
22644       tree mtype = NULL_TREE;
22645
22646       if (d->name == 0)
22647         continue;
22648
22649       switch ((enum multi_arg_type)d->flag)
22650         {
22651         case MULTI_ARG_3_SF:     mtype = v4sf_ftype_v4sf_v4sf_v4sf;     break;
22652         case MULTI_ARG_3_DF:     mtype = v2df_ftype_v2df_v2df_v2df;     break;
22653         case MULTI_ARG_3_DI:     mtype = v2di_ftype_v2di_v2di_v2di;     break;
22654         case MULTI_ARG_3_SI:     mtype = v4si_ftype_v4si_v4si_v4si;     break;
22655         case MULTI_ARG_3_SI_DI:  mtype = v4si_ftype_v4si_v4si_v2di;     break;
22656         case MULTI_ARG_3_HI:     mtype = v8hi_ftype_v8hi_v8hi_v8hi;     break;
22657         case MULTI_ARG_3_HI_SI:  mtype = v8hi_ftype_v8hi_v8hi_v4si;     break;
22658         case MULTI_ARG_3_QI:     mtype = v16qi_ftype_v16qi_v16qi_v16qi; break;
22659         case MULTI_ARG_3_PERMPS: mtype = v4sf_ftype_v4sf_v4sf_v16qi;    break;
22660         case MULTI_ARG_3_PERMPD: mtype = v2df_ftype_v2df_v2df_v16qi;    break;
22661         case MULTI_ARG_2_SF:     mtype = v4sf_ftype_v4sf_v4sf;          break;
22662         case MULTI_ARG_2_DF:     mtype = v2df_ftype_v2df_v2df;          break;
22663         case MULTI_ARG_2_DI:     mtype = v2di_ftype_v2di_v2di;          break;
22664         case MULTI_ARG_2_SI:     mtype = v4si_ftype_v4si_v4si;          break;
22665         case MULTI_ARG_2_HI:     mtype = v8hi_ftype_v8hi_v8hi;          break;
22666         case MULTI_ARG_2_QI:     mtype = v16qi_ftype_v16qi_v16qi;       break;
22667         case MULTI_ARG_2_DI_IMM: mtype = v2di_ftype_v2di_si;            break;
22668         case MULTI_ARG_2_SI_IMM: mtype = v4si_ftype_v4si_si;            break;
22669         case MULTI_ARG_2_HI_IMM: mtype = v8hi_ftype_v8hi_si;            break;
22670         case MULTI_ARG_2_QI_IMM: mtype = v16qi_ftype_v16qi_si;          break;
22671         case MULTI_ARG_2_SF_CMP: mtype = v4sf_ftype_v4sf_v4sf;          break;
22672         case MULTI_ARG_2_DF_CMP: mtype = v2df_ftype_v2df_v2df;          break;
22673         case MULTI_ARG_2_DI_CMP: mtype = v2di_ftype_v2di_v2di;          break;
22674         case MULTI_ARG_2_SI_CMP: mtype = v4si_ftype_v4si_v4si;          break;
22675         case MULTI_ARG_2_HI_CMP: mtype = v8hi_ftype_v8hi_v8hi;          break;
22676         case MULTI_ARG_2_QI_CMP: mtype = v16qi_ftype_v16qi_v16qi;       break;
22677         case MULTI_ARG_2_SF_TF:  mtype = v4sf_ftype_v4sf_v4sf;          break;
22678         case MULTI_ARG_2_DF_TF:  mtype = v2df_ftype_v2df_v2df;          break;
22679         case MULTI_ARG_2_DI_TF:  mtype = v2di_ftype_v2di_v2di;          break;
22680         case MULTI_ARG_2_SI_TF:  mtype = v4si_ftype_v4si_v4si;          break;
22681         case MULTI_ARG_2_HI_TF:  mtype = v8hi_ftype_v8hi_v8hi;          break;
22682         case MULTI_ARG_2_QI_TF:  mtype = v16qi_ftype_v16qi_v16qi;       break;
22683         case MULTI_ARG_1_SF:     mtype = v4sf_ftype_v4sf;               break;
22684         case MULTI_ARG_1_DF:     mtype = v2df_ftype_v2df;               break;
22685         case MULTI_ARG_1_DI:     mtype = v2di_ftype_v2di;               break;
22686         case MULTI_ARG_1_SI:     mtype = v4si_ftype_v4si;               break;
22687         case MULTI_ARG_1_HI:     mtype = v8hi_ftype_v8hi;               break;
22688         case MULTI_ARG_1_QI:     mtype = v16qi_ftype_v16qi;             break;
22689         case MULTI_ARG_1_SI_DI:  mtype = v2di_ftype_v4si;               break;
22690         case MULTI_ARG_1_HI_DI:  mtype = v2di_ftype_v8hi;               break;
22691         case MULTI_ARG_1_HI_SI:  mtype = v4si_ftype_v8hi;               break;
22692         case MULTI_ARG_1_QI_DI:  mtype = v2di_ftype_v16qi;              break;
22693         case MULTI_ARG_1_QI_SI:  mtype = v4si_ftype_v16qi;              break;
22694         case MULTI_ARG_1_QI_HI:  mtype = v8hi_ftype_v16qi;              break;
22695         case MULTI_ARG_1_PH2PS:  mtype = v4sf_ftype_v4hi;               break;
22696         case MULTI_ARG_1_PS2PH:  mtype = v4hi_ftype_v4sf;               break;
22697         case MULTI_ARG_UNKNOWN:
22698         default:
22699           gcc_unreachable ();
22700         }
22701
22702       if (mtype)
22703         def_builtin_const (d->mask, d->name, mtype, d->code);
22704     }
22705 }
22706
22707 /* Internal method for ix86_init_builtins.  */
22708
22709 static void
22710 ix86_init_builtins_va_builtins_abi (void)
22711 {
22712   tree ms_va_ref, sysv_va_ref;
22713   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
22714   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
22715   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
22716   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
22717
22718   if (!TARGET_64BIT)
22719     return;
22720   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
22721   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
22722   ms_va_ref = build_reference_type (ms_va_list_type_node);
22723   sysv_va_ref =
22724     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
22725
22726   fnvoid_va_end_ms =
22727     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
22728   fnvoid_va_start_ms =
22729     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
22730   fnvoid_va_end_sysv =
22731     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
22732   fnvoid_va_start_sysv =
22733     build_varargs_function_type_list (void_type_node, sysv_va_ref,
22734                                        NULL_TREE);
22735   fnvoid_va_copy_ms =
22736     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
22737                               NULL_TREE);
22738   fnvoid_va_copy_sysv =
22739     build_function_type_list (void_type_node, sysv_va_ref,
22740                               sysv_va_ref, NULL_TREE);
22741
22742   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
22743                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
22744   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
22745                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
22746   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
22747                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
22748   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
22749                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
22750   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
22751                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
22752   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
22753                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
22754 }
22755
22756 static void
22757 ix86_init_builtins (void)
22758 {
22759   tree float128_type_node = make_node (REAL_TYPE);
22760   tree ftype, decl;
22761
22762   /* The __float80 type.  */
22763   if (TYPE_MODE (long_double_type_node) == XFmode)
22764     (*lang_hooks.types.register_builtin_type) (long_double_type_node,
22765                                                "__float80");
22766   else
22767     {
22768       /* The __float80 type.  */
22769       tree float80_type_node = make_node (REAL_TYPE);
22770
22771       TYPE_PRECISION (float80_type_node) = 80;
22772       layout_type (float80_type_node);
22773       (*lang_hooks.types.register_builtin_type) (float80_type_node,
22774                                                  "__float80");
22775     }
22776
22777   /* The __float128 type.  */
22778   TYPE_PRECISION (float128_type_node) = 128;
22779   layout_type (float128_type_node);
22780   (*lang_hooks.types.register_builtin_type) (float128_type_node,
22781                                              "__float128");
22782
22783   /* TFmode support builtins.  */
22784   ftype = build_function_type (float128_type_node, void_list_node);
22785   decl = add_builtin_function ("__builtin_infq", ftype,
22786                                IX86_BUILTIN_INFQ, BUILT_IN_MD,
22787                                NULL, NULL_TREE);
22788   ix86_builtins[(int) IX86_BUILTIN_INFQ] = decl;
22789
22790   /* We will expand them to normal call if SSE2 isn't available since
22791      they are used by libgcc. */
22792   ftype = build_function_type_list (float128_type_node,
22793                                     float128_type_node,
22794                                     NULL_TREE);
22795   decl = add_builtin_function ("__builtin_fabsq", ftype,
22796                                IX86_BUILTIN_FABSQ, BUILT_IN_MD,
22797                                "__fabstf2", NULL_TREE);
22798   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = decl;
22799   TREE_READONLY (decl) = 1;
22800
22801   ftype = build_function_type_list (float128_type_node,
22802                                     float128_type_node,
22803                                     float128_type_node,
22804                                     NULL_TREE);
22805   decl = add_builtin_function ("__builtin_copysignq", ftype,
22806                                IX86_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
22807                                "__copysigntf3", NULL_TREE);
22808   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = decl;
22809   TREE_READONLY (decl) = 1;
22810
22811   ix86_init_mmx_sse_builtins ();
22812   if (TARGET_64BIT)
22813     ix86_init_builtins_va_builtins_abi ();
22814 }
22815
22816 /* Errors in the source file can cause expand_expr to return const0_rtx
22817    where we expect a vector.  To avoid crashing, use one of the vector
22818    clear instructions.  */
22819 static rtx
22820 safe_vector_operand (rtx x, enum machine_mode mode)
22821 {
22822   if (x == const0_rtx)
22823     x = CONST0_RTX (mode);
22824   return x;
22825 }
22826
22827 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
22828
22829 static rtx
22830 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
22831 {
22832   rtx pat;
22833   tree arg0 = CALL_EXPR_ARG (exp, 0);
22834   tree arg1 = CALL_EXPR_ARG (exp, 1);
22835   rtx op0 = expand_normal (arg0);
22836   rtx op1 = expand_normal (arg1);
22837   enum machine_mode tmode = insn_data[icode].operand[0].mode;
22838   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
22839   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
22840
22841   if (VECTOR_MODE_P (mode0))
22842     op0 = safe_vector_operand (op0, mode0);
22843   if (VECTOR_MODE_P (mode1))
22844     op1 = safe_vector_operand (op1, mode1);
22845
22846   if (optimize || !target
22847       || GET_MODE (target) != tmode
22848       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
22849     target = gen_reg_rtx (tmode);
22850
22851   if (GET_MODE (op1) == SImode && mode1 == TImode)
22852     {
22853       rtx x = gen_reg_rtx (V4SImode);
22854       emit_insn (gen_sse2_loadd (x, op1));
22855       op1 = gen_lowpart (TImode, x);
22856     }
22857
22858   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
22859     op0 = copy_to_mode_reg (mode0, op0);
22860   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
22861     op1 = copy_to_mode_reg (mode1, op1);
22862
22863   pat = GEN_FCN (icode) (target, op0, op1);
22864   if (! pat)
22865     return 0;
22866
22867   emit_insn (pat);
22868
22869   return target;
22870 }
22871
22872 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
22873
22874 static rtx
22875 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
22876                                enum multi_arg_type m_type,
22877                                enum insn_code sub_code)
22878 {
22879   rtx pat;
22880   int i;
22881   int nargs;
22882   bool comparison_p = false;
22883   bool tf_p = false;
22884   bool last_arg_constant = false;
22885   int num_memory = 0;
22886   struct {
22887     rtx op;
22888     enum machine_mode mode;
22889   } args[4];
22890
22891   enum machine_mode tmode = insn_data[icode].operand[0].mode;
22892
22893   switch (m_type)
22894     {
22895     case MULTI_ARG_3_SF:
22896     case MULTI_ARG_3_DF:
22897     case MULTI_ARG_3_DI:
22898     case MULTI_ARG_3_SI:
22899     case MULTI_ARG_3_SI_DI:
22900     case MULTI_ARG_3_HI:
22901     case MULTI_ARG_3_HI_SI:
22902     case MULTI_ARG_3_QI:
22903     case MULTI_ARG_3_PERMPS:
22904     case MULTI_ARG_3_PERMPD:
22905       nargs = 3;
22906       break;
22907
22908     case MULTI_ARG_2_SF:
22909     case MULTI_ARG_2_DF:
22910     case MULTI_ARG_2_DI:
22911     case MULTI_ARG_2_SI:
22912     case MULTI_ARG_2_HI:
22913     case MULTI_ARG_2_QI:
22914       nargs = 2;
22915       break;
22916
22917     case MULTI_ARG_2_DI_IMM:
22918     case MULTI_ARG_2_SI_IMM:
22919     case MULTI_ARG_2_HI_IMM:
22920     case MULTI_ARG_2_QI_IMM:
22921       nargs = 2;
22922       last_arg_constant = true;
22923       break;
22924
22925     case MULTI_ARG_1_SF:
22926     case MULTI_ARG_1_DF:
22927     case MULTI_ARG_1_DI:
22928     case MULTI_ARG_1_SI:
22929     case MULTI_ARG_1_HI:
22930     case MULTI_ARG_1_QI:
22931     case MULTI_ARG_1_SI_DI:
22932     case MULTI_ARG_1_HI_DI:
22933     case MULTI_ARG_1_HI_SI:
22934     case MULTI_ARG_1_QI_DI:
22935     case MULTI_ARG_1_QI_SI:
22936     case MULTI_ARG_1_QI_HI:
22937     case MULTI_ARG_1_PH2PS:
22938     case MULTI_ARG_1_PS2PH:
22939       nargs = 1;
22940       break;
22941
22942     case MULTI_ARG_2_SF_CMP:
22943     case MULTI_ARG_2_DF_CMP:
22944     case MULTI_ARG_2_DI_CMP:
22945     case MULTI_ARG_2_SI_CMP:
22946     case MULTI_ARG_2_HI_CMP:
22947     case MULTI_ARG_2_QI_CMP:
22948       nargs = 2;
22949       comparison_p = true;
22950       break;
22951
22952     case MULTI_ARG_2_SF_TF:
22953     case MULTI_ARG_2_DF_TF:
22954     case MULTI_ARG_2_DI_TF:
22955     case MULTI_ARG_2_SI_TF:
22956     case MULTI_ARG_2_HI_TF:
22957     case MULTI_ARG_2_QI_TF:
22958       nargs = 2;
22959       tf_p = true;
22960       break;
22961
22962     case MULTI_ARG_UNKNOWN:
22963     default:
22964       gcc_unreachable ();
22965     }
22966
22967   if (optimize || !target
22968       || GET_MODE (target) != tmode
22969       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
22970     target = gen_reg_rtx (tmode);
22971
22972   gcc_assert (nargs <= 4);
22973
22974   for (i = 0; i < nargs; i++)
22975     {
22976       tree arg = CALL_EXPR_ARG (exp, i);
22977       rtx op = expand_normal (arg);
22978       int adjust = (comparison_p) ? 1 : 0;
22979       enum machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
22980
22981       if (last_arg_constant && i == nargs-1)
22982         {
22983           if (GET_CODE (op) != CONST_INT)
22984             {
22985               error ("last argument must be an immediate");
22986               return gen_reg_rtx (tmode);
22987             }
22988         }
22989       else
22990         {
22991           if (VECTOR_MODE_P (mode))
22992             op = safe_vector_operand (op, mode);
22993
22994           /* If we aren't optimizing, only allow one memory operand to be
22995              generated.  */
22996           if (memory_operand (op, mode))
22997             num_memory++;
22998
22999           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
23000
23001           if (optimize
23002               || ! (*insn_data[icode].operand[i+adjust+1].predicate) (op, mode)
23003               || num_memory > 1)
23004             op = force_reg (mode, op);
23005         }
23006
23007       args[i].op = op;
23008       args[i].mode = mode;
23009     }
23010
23011   switch (nargs)
23012     {
23013     case 1:
23014       pat = GEN_FCN (icode) (target, args[0].op);
23015       break;
23016
23017     case 2:
23018       if (tf_p)
23019         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
23020                                GEN_INT ((int)sub_code));
23021       else if (! comparison_p)
23022         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
23023       else
23024         {
23025           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
23026                                        args[0].op,
23027                                        args[1].op);
23028
23029           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
23030         }
23031       break;
23032
23033     case 3:
23034       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
23035       break;
23036
23037     default:
23038       gcc_unreachable ();
23039     }
23040
23041   if (! pat)
23042     return 0;
23043
23044   emit_insn (pat);
23045   return target;
23046 }
23047
23048 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
23049    insns with vec_merge.  */
23050
23051 static rtx
23052 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
23053                                     rtx target)
23054 {
23055   rtx pat;
23056   tree arg0 = CALL_EXPR_ARG (exp, 0);
23057   rtx op1, op0 = expand_normal (arg0);
23058   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23059   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
23060
23061   if (optimize || !target
23062       || GET_MODE (target) != tmode
23063       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23064     target = gen_reg_rtx (tmode);
23065
23066   if (VECTOR_MODE_P (mode0))
23067     op0 = safe_vector_operand (op0, mode0);
23068
23069   if ((optimize && !register_operand (op0, mode0))
23070       || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
23071     op0 = copy_to_mode_reg (mode0, op0);
23072
23073   op1 = op0;
23074   if (! (*insn_data[icode].operand[2].predicate) (op1, mode0))
23075     op1 = copy_to_mode_reg (mode0, op1);
23076
23077   pat = GEN_FCN (icode) (target, op0, op1);
23078   if (! pat)
23079     return 0;
23080   emit_insn (pat);
23081   return target;
23082 }
23083
23084 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
23085
23086 static rtx
23087 ix86_expand_sse_compare (const struct builtin_description *d,
23088                          tree exp, rtx target, bool swap)
23089 {
23090   rtx pat;
23091   tree arg0 = CALL_EXPR_ARG (exp, 0);
23092   tree arg1 = CALL_EXPR_ARG (exp, 1);
23093   rtx op0 = expand_normal (arg0);
23094   rtx op1 = expand_normal (arg1);
23095   rtx op2;
23096   enum machine_mode tmode = insn_data[d->icode].operand[0].mode;
23097   enum machine_mode mode0 = insn_data[d->icode].operand[1].mode;
23098   enum machine_mode mode1 = insn_data[d->icode].operand[2].mode;
23099   enum rtx_code comparison = d->comparison;
23100
23101   if (VECTOR_MODE_P (mode0))
23102     op0 = safe_vector_operand (op0, mode0);
23103   if (VECTOR_MODE_P (mode1))
23104     op1 = safe_vector_operand (op1, mode1);
23105
23106   /* Swap operands if we have a comparison that isn't available in
23107      hardware.  */
23108   if (swap)
23109     {
23110       rtx tmp = gen_reg_rtx (mode1);
23111       emit_move_insn (tmp, op1);
23112       op1 = op0;
23113       op0 = tmp;
23114     }
23115
23116   if (optimize || !target
23117       || GET_MODE (target) != tmode
23118       || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode))
23119     target = gen_reg_rtx (tmode);
23120
23121   if ((optimize && !register_operand (op0, mode0))
23122       || ! (*insn_data[d->icode].operand[1].predicate) (op0, mode0))
23123     op0 = copy_to_mode_reg (mode0, op0);
23124   if ((optimize && !register_operand (op1, mode1))
23125       || ! (*insn_data[d->icode].operand[2].predicate) (op1, mode1))
23126     op1 = copy_to_mode_reg (mode1, op1);
23127
23128   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
23129   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
23130   if (! pat)
23131     return 0;
23132   emit_insn (pat);
23133   return target;
23134 }
23135
23136 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
23137
23138 static rtx
23139 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
23140                       rtx target)
23141 {
23142   rtx pat;
23143   tree arg0 = CALL_EXPR_ARG (exp, 0);
23144   tree arg1 = CALL_EXPR_ARG (exp, 1);
23145   rtx op0 = expand_normal (arg0);
23146   rtx op1 = expand_normal (arg1);
23147   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23148   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23149   enum rtx_code comparison = d->comparison;
23150
23151   if (VECTOR_MODE_P (mode0))
23152     op0 = safe_vector_operand (op0, mode0);
23153   if (VECTOR_MODE_P (mode1))
23154     op1 = safe_vector_operand (op1, mode1);
23155
23156   /* Swap operands if we have a comparison that isn't available in
23157      hardware.  */
23158   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
23159     {
23160       rtx tmp = op1;
23161       op1 = op0;
23162       op0 = tmp;
23163     }
23164
23165   target = gen_reg_rtx (SImode);
23166   emit_move_insn (target, const0_rtx);
23167   target = gen_rtx_SUBREG (QImode, target, 0);
23168
23169   if ((optimize && !register_operand (op0, mode0))
23170       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23171     op0 = copy_to_mode_reg (mode0, op0);
23172   if ((optimize && !register_operand (op1, mode1))
23173       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23174     op1 = copy_to_mode_reg (mode1, op1);
23175
23176   pat = GEN_FCN (d->icode) (op0, op1);
23177   if (! pat)
23178     return 0;
23179   emit_insn (pat);
23180   emit_insn (gen_rtx_SET (VOIDmode,
23181                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23182                           gen_rtx_fmt_ee (comparison, QImode,
23183                                           SET_DEST (pat),
23184                                           const0_rtx)));
23185
23186   return SUBREG_REG (target);
23187 }
23188
23189 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
23190
23191 static rtx
23192 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
23193                        rtx target)
23194 {
23195   rtx pat;
23196   tree arg0 = CALL_EXPR_ARG (exp, 0);
23197   tree arg1 = CALL_EXPR_ARG (exp, 1);
23198   rtx op0 = expand_normal (arg0);
23199   rtx op1 = expand_normal (arg1);
23200   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23201   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23202   enum rtx_code comparison = d->comparison;
23203
23204   if (VECTOR_MODE_P (mode0))
23205     op0 = safe_vector_operand (op0, mode0);
23206   if (VECTOR_MODE_P (mode1))
23207     op1 = safe_vector_operand (op1, mode1);
23208
23209   target = gen_reg_rtx (SImode);
23210   emit_move_insn (target, const0_rtx);
23211   target = gen_rtx_SUBREG (QImode, target, 0);
23212
23213   if ((optimize && !register_operand (op0, mode0))
23214       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23215     op0 = copy_to_mode_reg (mode0, op0);
23216   if ((optimize && !register_operand (op1, mode1))
23217       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23218     op1 = copy_to_mode_reg (mode1, op1);
23219
23220   pat = GEN_FCN (d->icode) (op0, op1);
23221   if (! pat)
23222     return 0;
23223   emit_insn (pat);
23224   emit_insn (gen_rtx_SET (VOIDmode,
23225                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23226                           gen_rtx_fmt_ee (comparison, QImode,
23227                                           SET_DEST (pat),
23228                                           const0_rtx)));
23229
23230   return SUBREG_REG (target);
23231 }
23232
23233 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
23234
23235 static rtx
23236 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
23237                           tree exp, rtx target)
23238 {
23239   rtx pat;
23240   tree arg0 = CALL_EXPR_ARG (exp, 0);
23241   tree arg1 = CALL_EXPR_ARG (exp, 1);
23242   tree arg2 = CALL_EXPR_ARG (exp, 2);
23243   tree arg3 = CALL_EXPR_ARG (exp, 3);
23244   tree arg4 = CALL_EXPR_ARG (exp, 4);
23245   rtx scratch0, scratch1;
23246   rtx op0 = expand_normal (arg0);
23247   rtx op1 = expand_normal (arg1);
23248   rtx op2 = expand_normal (arg2);
23249   rtx op3 = expand_normal (arg3);
23250   rtx op4 = expand_normal (arg4);
23251   enum machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
23252
23253   tmode0 = insn_data[d->icode].operand[0].mode;
23254   tmode1 = insn_data[d->icode].operand[1].mode;
23255   modev2 = insn_data[d->icode].operand[2].mode;
23256   modei3 = insn_data[d->icode].operand[3].mode;
23257   modev4 = insn_data[d->icode].operand[4].mode;
23258   modei5 = insn_data[d->icode].operand[5].mode;
23259   modeimm = insn_data[d->icode].operand[6].mode;
23260
23261   if (VECTOR_MODE_P (modev2))
23262     op0 = safe_vector_operand (op0, modev2);
23263   if (VECTOR_MODE_P (modev4))
23264     op2 = safe_vector_operand (op2, modev4);
23265
23266   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
23267     op0 = copy_to_mode_reg (modev2, op0);
23268   if (! (*insn_data[d->icode].operand[3].predicate) (op1, modei3))
23269     op1 = copy_to_mode_reg (modei3, op1);
23270   if ((optimize && !register_operand (op2, modev4))
23271       || !(*insn_data[d->icode].operand[4].predicate) (op2, modev4))
23272     op2 = copy_to_mode_reg (modev4, op2);
23273   if (! (*insn_data[d->icode].operand[5].predicate) (op3, modei5))
23274     op3 = copy_to_mode_reg (modei5, op3);
23275
23276   if (! (*insn_data[d->icode].operand[6].predicate) (op4, modeimm))
23277     {
23278       error ("the fifth argument must be a 8-bit immediate");
23279       return const0_rtx;
23280     }
23281
23282   if (d->code == IX86_BUILTIN_PCMPESTRI128)
23283     {
23284       if (optimize || !target
23285           || GET_MODE (target) != tmode0
23286           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
23287         target = gen_reg_rtx (tmode0);
23288
23289       scratch1 = gen_reg_rtx (tmode1);
23290
23291       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
23292     }
23293   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
23294     {
23295       if (optimize || !target
23296           || GET_MODE (target) != tmode1
23297           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
23298         target = gen_reg_rtx (tmode1);
23299
23300       scratch0 = gen_reg_rtx (tmode0);
23301
23302       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
23303     }
23304   else
23305     {
23306       gcc_assert (d->flag);
23307
23308       scratch0 = gen_reg_rtx (tmode0);
23309       scratch1 = gen_reg_rtx (tmode1);
23310
23311       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
23312     }
23313
23314   if (! pat)
23315     return 0;
23316
23317   emit_insn (pat);
23318
23319   if (d->flag)
23320     {
23321       target = gen_reg_rtx (SImode);
23322       emit_move_insn (target, const0_rtx);
23323       target = gen_rtx_SUBREG (QImode, target, 0);
23324
23325       emit_insn
23326         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23327                       gen_rtx_fmt_ee (EQ, QImode,
23328                                       gen_rtx_REG ((enum machine_mode) d->flag,
23329                                                    FLAGS_REG),
23330                                       const0_rtx)));
23331       return SUBREG_REG (target);
23332     }
23333   else
23334     return target;
23335 }
23336
23337
23338 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
23339
23340 static rtx
23341 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
23342                           tree exp, rtx target)
23343 {
23344   rtx pat;
23345   tree arg0 = CALL_EXPR_ARG (exp, 0);
23346   tree arg1 = CALL_EXPR_ARG (exp, 1);
23347   tree arg2 = CALL_EXPR_ARG (exp, 2);
23348   rtx scratch0, scratch1;
23349   rtx op0 = expand_normal (arg0);
23350   rtx op1 = expand_normal (arg1);
23351   rtx op2 = expand_normal (arg2);
23352   enum machine_mode tmode0, tmode1, modev2, modev3, modeimm;
23353
23354   tmode0 = insn_data[d->icode].operand[0].mode;
23355   tmode1 = insn_data[d->icode].operand[1].mode;
23356   modev2 = insn_data[d->icode].operand[2].mode;
23357   modev3 = insn_data[d->icode].operand[3].mode;
23358   modeimm = insn_data[d->icode].operand[4].mode;
23359
23360   if (VECTOR_MODE_P (modev2))
23361     op0 = safe_vector_operand (op0, modev2);
23362   if (VECTOR_MODE_P (modev3))
23363     op1 = safe_vector_operand (op1, modev3);
23364
23365   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
23366     op0 = copy_to_mode_reg (modev2, op0);
23367   if ((optimize && !register_operand (op1, modev3))
23368       || !(*insn_data[d->icode].operand[3].predicate) (op1, modev3))
23369     op1 = copy_to_mode_reg (modev3, op1);
23370
23371   if (! (*insn_data[d->icode].operand[4].predicate) (op2, modeimm))
23372     {
23373       error ("the third argument must be a 8-bit immediate");
23374       return const0_rtx;
23375     }
23376
23377   if (d->code == IX86_BUILTIN_PCMPISTRI128)
23378     {
23379       if (optimize || !target
23380           || GET_MODE (target) != tmode0
23381           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
23382         target = gen_reg_rtx (tmode0);
23383
23384       scratch1 = gen_reg_rtx (tmode1);
23385
23386       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
23387     }
23388   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
23389     {
23390       if (optimize || !target
23391           || GET_MODE (target) != tmode1
23392           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
23393         target = gen_reg_rtx (tmode1);
23394
23395       scratch0 = gen_reg_rtx (tmode0);
23396
23397       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
23398     }
23399   else
23400     {
23401       gcc_assert (d->flag);
23402
23403       scratch0 = gen_reg_rtx (tmode0);
23404       scratch1 = gen_reg_rtx (tmode1);
23405
23406       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
23407     }
23408
23409   if (! pat)
23410     return 0;
23411
23412   emit_insn (pat);
23413
23414   if (d->flag)
23415     {
23416       target = gen_reg_rtx (SImode);
23417       emit_move_insn (target, const0_rtx);
23418       target = gen_rtx_SUBREG (QImode, target, 0);
23419
23420       emit_insn
23421         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23422                       gen_rtx_fmt_ee (EQ, QImode,
23423                                       gen_rtx_REG ((enum machine_mode) d->flag,
23424                                                    FLAGS_REG),
23425                                       const0_rtx)));
23426       return SUBREG_REG (target);
23427     }
23428   else
23429     return target;
23430 }
23431
23432 /* Subroutine of ix86_expand_builtin to take care of insns with
23433    variable number of operands.  */
23434
23435 static rtx
23436 ix86_expand_args_builtin (const struct builtin_description *d,
23437                           tree exp, rtx target)
23438 {
23439   rtx pat, real_target;
23440   unsigned int i, nargs;
23441   unsigned int nargs_constant = 0;
23442   int num_memory = 0;
23443   struct
23444     {
23445       rtx op;
23446       enum machine_mode mode;
23447     } args[4];
23448   bool last_arg_count = false;
23449   enum insn_code icode = d->icode;
23450   const struct insn_data *insn_p = &insn_data[icode];
23451   enum machine_mode tmode = insn_p->operand[0].mode;
23452   enum machine_mode rmode = VOIDmode;
23453   bool swap = false;
23454   enum rtx_code comparison = d->comparison;
23455
23456   switch ((enum ix86_builtin_type) d->flag)
23457     {
23458     case INT_FTYPE_V8SF_V8SF_PTEST:
23459     case INT_FTYPE_V4DI_V4DI_PTEST:
23460     case INT_FTYPE_V4DF_V4DF_PTEST:
23461     case INT_FTYPE_V4SF_V4SF_PTEST:
23462     case INT_FTYPE_V2DI_V2DI_PTEST:
23463     case INT_FTYPE_V2DF_V2DF_PTEST:
23464       return ix86_expand_sse_ptest (d, exp, target);
23465     case FLOAT128_FTYPE_FLOAT128:
23466     case FLOAT_FTYPE_FLOAT:
23467     case INT64_FTYPE_V4SF:
23468     case INT64_FTYPE_V2DF:
23469     case INT_FTYPE_V16QI:
23470     case INT_FTYPE_V8QI:
23471     case INT_FTYPE_V8SF:
23472     case INT_FTYPE_V4DF:
23473     case INT_FTYPE_V4SF:
23474     case INT_FTYPE_V2DF:
23475     case V16QI_FTYPE_V16QI:
23476     case V8SI_FTYPE_V8SF:
23477     case V8SI_FTYPE_V4SI:
23478     case V8HI_FTYPE_V8HI:
23479     case V8HI_FTYPE_V16QI:
23480     case V8QI_FTYPE_V8QI:
23481     case V8SF_FTYPE_V8SF:
23482     case V8SF_FTYPE_V8SI:
23483     case V8SF_FTYPE_V4SF:
23484     case V4SI_FTYPE_V4SI:
23485     case V4SI_FTYPE_V16QI:
23486     case V4SI_FTYPE_V4SF:
23487     case V4SI_FTYPE_V8SI:
23488     case V4SI_FTYPE_V8HI:
23489     case V4SI_FTYPE_V4DF:
23490     case V4SI_FTYPE_V2DF:
23491     case V4HI_FTYPE_V4HI:
23492     case V4DF_FTYPE_V4DF:
23493     case V4DF_FTYPE_V4SI:
23494     case V4DF_FTYPE_V4SF:
23495     case V4DF_FTYPE_V2DF:
23496     case V4SF_FTYPE_V4SF:
23497     case V4SF_FTYPE_V4SI:
23498     case V4SF_FTYPE_V8SF:
23499     case V4SF_FTYPE_V4DF:
23500     case V4SF_FTYPE_V2DF:
23501     case V2DI_FTYPE_V2DI:
23502     case V2DI_FTYPE_V16QI:
23503     case V2DI_FTYPE_V8HI:
23504     case V2DI_FTYPE_V4SI:
23505     case V2DF_FTYPE_V2DF:
23506     case V2DF_FTYPE_V4SI:
23507     case V2DF_FTYPE_V4DF:
23508     case V2DF_FTYPE_V4SF:
23509     case V2DF_FTYPE_V2SI:
23510     case V2SI_FTYPE_V2SI:
23511     case V2SI_FTYPE_V4SF:
23512     case V2SI_FTYPE_V2SF:
23513     case V2SI_FTYPE_V2DF:
23514     case V2SF_FTYPE_V2SF:
23515     case V2SF_FTYPE_V2SI:
23516       nargs = 1;
23517       break;
23518     case V4SF_FTYPE_V4SF_VEC_MERGE:
23519     case V2DF_FTYPE_V2DF_VEC_MERGE:
23520       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
23521     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
23522     case V16QI_FTYPE_V16QI_V16QI:
23523     case V16QI_FTYPE_V8HI_V8HI:
23524     case V8QI_FTYPE_V8QI_V8QI:
23525     case V8QI_FTYPE_V4HI_V4HI:
23526     case V8HI_FTYPE_V8HI_V8HI:
23527     case V8HI_FTYPE_V16QI_V16QI:
23528     case V8HI_FTYPE_V4SI_V4SI:
23529     case V8SF_FTYPE_V8SF_V8SF:
23530     case V8SF_FTYPE_V8SF_V8SI:
23531     case V4SI_FTYPE_V4SI_V4SI:
23532     case V4SI_FTYPE_V8HI_V8HI:
23533     case V4SI_FTYPE_V4SF_V4SF:
23534     case V4SI_FTYPE_V2DF_V2DF:
23535     case V4HI_FTYPE_V4HI_V4HI:
23536     case V4HI_FTYPE_V8QI_V8QI:
23537     case V4HI_FTYPE_V2SI_V2SI:
23538     case V4DF_FTYPE_V4DF_V4DF:
23539     case V4DF_FTYPE_V4DF_V4DI:
23540     case V4SF_FTYPE_V4SF_V4SF:
23541     case V4SF_FTYPE_V4SF_V4SI:
23542     case V4SF_FTYPE_V4SF_V2SI:
23543     case V4SF_FTYPE_V4SF_V2DF:
23544     case V4SF_FTYPE_V4SF_DI:
23545     case V4SF_FTYPE_V4SF_SI:
23546     case V2DI_FTYPE_V2DI_V2DI:
23547     case V2DI_FTYPE_V16QI_V16QI:
23548     case V2DI_FTYPE_V4SI_V4SI:
23549     case V2DI_FTYPE_V2DI_V16QI:
23550     case V2DI_FTYPE_V2DF_V2DF:
23551     case V2SI_FTYPE_V2SI_V2SI:
23552     case V2SI_FTYPE_V4HI_V4HI:
23553     case V2SI_FTYPE_V2SF_V2SF:
23554     case V2DF_FTYPE_V2DF_V2DF:
23555     case V2DF_FTYPE_V2DF_V4SF:
23556     case V2DF_FTYPE_V2DF_V2DI:
23557     case V2DF_FTYPE_V2DF_DI:
23558     case V2DF_FTYPE_V2DF_SI:
23559     case V2SF_FTYPE_V2SF_V2SF:
23560     case V1DI_FTYPE_V1DI_V1DI:
23561     case V1DI_FTYPE_V8QI_V8QI:
23562     case V1DI_FTYPE_V2SI_V2SI:
23563       if (comparison == UNKNOWN)
23564         return ix86_expand_binop_builtin (icode, exp, target);
23565       nargs = 2;
23566       break;
23567     case V4SF_FTYPE_V4SF_V4SF_SWAP:
23568     case V2DF_FTYPE_V2DF_V2DF_SWAP:
23569       gcc_assert (comparison != UNKNOWN);
23570       nargs = 2;
23571       swap = true;
23572       break;
23573     case V8HI_FTYPE_V8HI_V8HI_COUNT:
23574     case V8HI_FTYPE_V8HI_SI_COUNT:
23575     case V4SI_FTYPE_V4SI_V4SI_COUNT:
23576     case V4SI_FTYPE_V4SI_SI_COUNT:
23577     case V4HI_FTYPE_V4HI_V4HI_COUNT:
23578     case V4HI_FTYPE_V4HI_SI_COUNT:
23579     case V2DI_FTYPE_V2DI_V2DI_COUNT:
23580     case V2DI_FTYPE_V2DI_SI_COUNT:
23581     case V2SI_FTYPE_V2SI_V2SI_COUNT:
23582     case V2SI_FTYPE_V2SI_SI_COUNT:
23583     case V1DI_FTYPE_V1DI_V1DI_COUNT:
23584     case V1DI_FTYPE_V1DI_SI_COUNT:
23585       nargs = 2;
23586       last_arg_count = true;
23587       break;
23588     case UINT64_FTYPE_UINT64_UINT64:
23589     case UINT_FTYPE_UINT_UINT:
23590     case UINT_FTYPE_UINT_USHORT:
23591     case UINT_FTYPE_UINT_UCHAR:
23592       nargs = 2;
23593       break;
23594     case V2DI2TI_FTYPE_V2DI_INT:
23595       nargs = 2;
23596       rmode = V2DImode;
23597       nargs_constant = 1;
23598       break;
23599     case V8HI_FTYPE_V8HI_INT:
23600     case V8SF_FTYPE_V8SF_INT:
23601     case V4SI_FTYPE_V4SI_INT:
23602     case V4SI_FTYPE_V8SI_INT:
23603     case V4HI_FTYPE_V4HI_INT:
23604     case V4DF_FTYPE_V4DF_INT:
23605     case V4SF_FTYPE_V4SF_INT:
23606     case V4SF_FTYPE_V8SF_INT:
23607     case V2DI_FTYPE_V2DI_INT:
23608     case V2DF_FTYPE_V2DF_INT:
23609     case V2DF_FTYPE_V4DF_INT:
23610       nargs = 2;
23611       nargs_constant = 1;
23612       break;
23613     case V16QI_FTYPE_V16QI_V16QI_V16QI:
23614     case V8SF_FTYPE_V8SF_V8SF_V8SF:
23615     case V4DF_FTYPE_V4DF_V4DF_V4DF:
23616     case V4SF_FTYPE_V4SF_V4SF_V4SF:
23617     case V2DF_FTYPE_V2DF_V2DF_V2DF:
23618       nargs = 3;
23619       break;
23620     case V16QI_FTYPE_V16QI_V16QI_INT:
23621     case V8HI_FTYPE_V8HI_V8HI_INT:
23622     case V8SI_FTYPE_V8SI_V8SI_INT:
23623     case V8SI_FTYPE_V8SI_V4SI_INT:
23624     case V8SF_FTYPE_V8SF_V8SF_INT: 
23625     case V8SF_FTYPE_V8SF_V4SF_INT: 
23626     case V4SI_FTYPE_V4SI_V4SI_INT:
23627     case V4DF_FTYPE_V4DF_V4DF_INT:
23628     case V4DF_FTYPE_V4DF_V2DF_INT:
23629     case V4SF_FTYPE_V4SF_V4SF_INT:
23630     case V2DI_FTYPE_V2DI_V2DI_INT:
23631     case V2DF_FTYPE_V2DF_V2DF_INT:
23632       nargs = 3;
23633       nargs_constant = 1;
23634       break;
23635     case V2DI2TI_FTYPE_V2DI_V2DI_INT:
23636       nargs = 3;
23637       rmode = V2DImode;
23638       nargs_constant = 1;
23639       break;
23640     case V1DI2DI_FTYPE_V1DI_V1DI_INT:
23641       nargs = 3;
23642       rmode = DImode;
23643       nargs_constant = 1;
23644       break;
23645     case V2DI_FTYPE_V2DI_UINT_UINT:
23646       nargs = 3;
23647       nargs_constant = 2;
23648       break;
23649     case V8SF_FTYPE_V8SF_V8SF_V8SI_INT:
23650     case V4DF_FTYPE_V4DF_V4DF_V4DI_INT:
23651     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT:
23652     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT:
23653       nargs = 4;
23654       nargs_constant = 1;
23655       break;
23656     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
23657       nargs = 4;
23658       nargs_constant = 2;
23659       break;
23660     default:
23661       gcc_unreachable ();
23662     }
23663
23664   gcc_assert (nargs <= ARRAY_SIZE (args));
23665
23666   if (comparison != UNKNOWN)
23667     {
23668       gcc_assert (nargs == 2);
23669       return ix86_expand_sse_compare (d, exp, target, swap);
23670     }
23671
23672   if (rmode == VOIDmode || rmode == tmode)
23673     {
23674       if (optimize
23675           || target == 0
23676           || GET_MODE (target) != tmode
23677           || ! (*insn_p->operand[0].predicate) (target, tmode))
23678         target = gen_reg_rtx (tmode);
23679       real_target = target;
23680     }
23681   else
23682     {
23683       target = gen_reg_rtx (rmode);
23684       real_target = simplify_gen_subreg (tmode, target, rmode, 0);
23685     }
23686
23687   for (i = 0; i < nargs; i++)
23688     {
23689       tree arg = CALL_EXPR_ARG (exp, i);
23690       rtx op = expand_normal (arg);
23691       enum machine_mode mode = insn_p->operand[i + 1].mode;
23692       bool match = (*insn_p->operand[i + 1].predicate) (op, mode);
23693
23694       if (last_arg_count && (i + 1) == nargs)
23695         {
23696           /* SIMD shift insns take either an 8-bit immediate or
23697              register as count.  But builtin functions take int as
23698              count.  If count doesn't match, we put it in register.  */
23699           if (!match)
23700             {
23701               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
23702               if (!(*insn_p->operand[i + 1].predicate) (op, mode))
23703                 op = copy_to_reg (op);
23704             }
23705         }
23706       else if ((nargs - i) <= nargs_constant)
23707         {
23708           if (!match)
23709             switch (icode)
23710               {
23711               case CODE_FOR_sse4_1_roundpd:
23712               case CODE_FOR_sse4_1_roundps:
23713               case CODE_FOR_sse4_1_roundsd:
23714               case CODE_FOR_sse4_1_roundss:
23715               case CODE_FOR_sse4_1_blendps:
23716               case CODE_FOR_avx_blendpd256:
23717               case CODE_FOR_avx_vpermilv4df:
23718               case CODE_FOR_avx_roundpd256:
23719               case CODE_FOR_avx_roundps256:
23720                 error ("the last argument must be a 4-bit immediate");
23721                 return const0_rtx;
23722
23723               case CODE_FOR_sse4_1_blendpd:
23724               case CODE_FOR_avx_vpermilv2df:
23725               case CODE_FOR_avx_vpermil2v2df3:
23726               case CODE_FOR_avx_vpermil2v4sf3:
23727               case CODE_FOR_avx_vpermil2v4df3:
23728               case CODE_FOR_avx_vpermil2v8sf3:
23729                 error ("the last argument must be a 2-bit immediate");
23730                 return const0_rtx;
23731
23732               case CODE_FOR_avx_vextractf128v4df:
23733               case CODE_FOR_avx_vextractf128v8sf:
23734               case CODE_FOR_avx_vextractf128v8si:
23735               case CODE_FOR_avx_vinsertf128v4df:
23736               case CODE_FOR_avx_vinsertf128v8sf:
23737               case CODE_FOR_avx_vinsertf128v8si:
23738                 error ("the last argument must be a 1-bit immediate");
23739                 return const0_rtx;
23740
23741               case CODE_FOR_avx_cmpsdv2df3:
23742               case CODE_FOR_avx_cmpssv4sf3:
23743               case CODE_FOR_avx_cmppdv2df3:
23744               case CODE_FOR_avx_cmppsv4sf3:
23745               case CODE_FOR_avx_cmppdv4df3:
23746               case CODE_FOR_avx_cmppsv8sf3:
23747                 error ("the last argument must be a 5-bit immediate");
23748                 return const0_rtx;
23749
23750              default:
23751                 switch (nargs_constant)
23752                   {
23753                   case 2:
23754                     if ((nargs - i) == nargs_constant)
23755                       {
23756                         error ("the next to last argument must be an 8-bit immediate");
23757                         break;
23758                       }
23759                   case 1:
23760                     error ("the last argument must be an 8-bit immediate");
23761                     break;
23762                   default:
23763                     gcc_unreachable ();
23764                   }
23765                 return const0_rtx;
23766               }
23767         }
23768       else
23769         {
23770           if (VECTOR_MODE_P (mode))
23771             op = safe_vector_operand (op, mode);
23772
23773           /* If we aren't optimizing, only allow one memory operand to
23774              be generated.  */
23775           if (memory_operand (op, mode))
23776             num_memory++;
23777
23778           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
23779             {
23780               if (optimize || !match || num_memory > 1)
23781                 op = copy_to_mode_reg (mode, op);
23782             }
23783           else
23784             {
23785               op = copy_to_reg (op);
23786               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
23787             }
23788         }
23789
23790       args[i].op = op;
23791       args[i].mode = mode;
23792     }
23793
23794   switch (nargs)
23795     {
23796     case 1:
23797       pat = GEN_FCN (icode) (real_target, args[0].op);
23798       break;
23799     case 2:
23800       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
23801       break;
23802     case 3:
23803       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
23804                              args[2].op);
23805       break;
23806     case 4:
23807       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
23808                              args[2].op, args[3].op);
23809       break;
23810     default:
23811       gcc_unreachable ();
23812     }
23813
23814   if (! pat)
23815     return 0;
23816
23817   emit_insn (pat);
23818   return target;
23819 }
23820
23821 /* Subroutine of ix86_expand_builtin to take care of special insns
23822    with variable number of operands.  */
23823
23824 static rtx
23825 ix86_expand_special_args_builtin (const struct builtin_description *d,
23826                                     tree exp, rtx target)
23827 {
23828   tree arg;
23829   rtx pat, op;
23830   unsigned int i, nargs, arg_adjust, memory;
23831   struct
23832     {
23833       rtx op;
23834       enum machine_mode mode;
23835     } args[2];
23836   enum insn_code icode = d->icode;
23837   bool last_arg_constant = false;
23838   const struct insn_data *insn_p = &insn_data[icode];
23839   enum machine_mode tmode = insn_p->operand[0].mode;
23840   enum { load, store } klass;
23841
23842   switch ((enum ix86_special_builtin_type) d->flag)
23843     {
23844     case VOID_FTYPE_VOID:
23845       emit_insn (GEN_FCN (icode) (target));
23846       return 0;
23847     case V2DI_FTYPE_PV2DI:
23848     case V32QI_FTYPE_PCCHAR:
23849     case V16QI_FTYPE_PCCHAR:
23850     case V8SF_FTYPE_PCV4SF:
23851     case V8SF_FTYPE_PCFLOAT:
23852     case V4SF_FTYPE_PCFLOAT:
23853     case V4DF_FTYPE_PCV2DF:
23854     case V4DF_FTYPE_PCDOUBLE:
23855     case V2DF_FTYPE_PCDOUBLE:
23856       nargs = 1;
23857       klass = load;
23858       memory = 0;
23859       break;
23860     case VOID_FTYPE_PV2SF_V4SF:
23861     case VOID_FTYPE_PV2DI_V2DI:
23862     case VOID_FTYPE_PCHAR_V32QI:
23863     case VOID_FTYPE_PCHAR_V16QI:
23864     case VOID_FTYPE_PFLOAT_V8SF:
23865     case VOID_FTYPE_PFLOAT_V4SF:
23866     case VOID_FTYPE_PDOUBLE_V4DF:
23867     case VOID_FTYPE_PDOUBLE_V2DF:
23868     case VOID_FTYPE_PDI_DI:
23869     case VOID_FTYPE_PINT_INT:
23870       nargs = 1;
23871       klass = store;
23872       /* Reserve memory operand for target.  */
23873       memory = ARRAY_SIZE (args);
23874       break;
23875     case V4SF_FTYPE_V4SF_PCV2SF:
23876     case V2DF_FTYPE_V2DF_PCDOUBLE:
23877       nargs = 2;
23878       klass = load;
23879       memory = 1;
23880       break;
23881     case V8SF_FTYPE_PCV8SF_V8SF:
23882     case V4DF_FTYPE_PCV4DF_V4DF:
23883     case V4SF_FTYPE_PCV4SF_V4SF:
23884     case V2DF_FTYPE_PCV2DF_V2DF:
23885       nargs = 2;
23886       klass = load;
23887       memory = 0;
23888       break;
23889     case VOID_FTYPE_PV8SF_V8SF_V8SF:
23890     case VOID_FTYPE_PV4DF_V4DF_V4DF:
23891     case VOID_FTYPE_PV4SF_V4SF_V4SF:
23892     case VOID_FTYPE_PV2DF_V2DF_V2DF:
23893       nargs = 2;
23894       klass = store;
23895       /* Reserve memory operand for target.  */
23896       memory = ARRAY_SIZE (args);
23897       break;
23898     default:
23899       gcc_unreachable ();
23900     }
23901
23902   gcc_assert (nargs <= ARRAY_SIZE (args));
23903
23904   if (klass == store)
23905     {
23906       arg = CALL_EXPR_ARG (exp, 0);
23907       op = expand_normal (arg);
23908       gcc_assert (target == 0);
23909       target = gen_rtx_MEM (tmode, copy_to_mode_reg (Pmode, op));
23910       arg_adjust = 1;
23911     }
23912   else
23913     {
23914       arg_adjust = 0;
23915       if (optimize
23916           || target == 0
23917           || GET_MODE (target) != tmode
23918           || ! (*insn_p->operand[0].predicate) (target, tmode))
23919         target = gen_reg_rtx (tmode);
23920     }
23921
23922   for (i = 0; i < nargs; i++)
23923     {
23924       enum machine_mode mode = insn_p->operand[i + 1].mode;
23925       bool match;
23926
23927       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
23928       op = expand_normal (arg);
23929       match = (*insn_p->operand[i + 1].predicate) (op, mode);
23930
23931       if (last_arg_constant && (i + 1) == nargs)
23932         {
23933           if (!match)
23934             switch (icode)
23935               {
23936              default:
23937                 error ("the last argument must be an 8-bit immediate");
23938                 return const0_rtx;
23939               }
23940         }
23941       else
23942         {
23943           if (i == memory)
23944             {
23945               /* This must be the memory operand.  */
23946               op = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, op));
23947               gcc_assert (GET_MODE (op) == mode
23948                           || GET_MODE (op) == VOIDmode);
23949             }
23950           else
23951             {
23952               /* This must be register.  */
23953               if (VECTOR_MODE_P (mode))
23954                 op = safe_vector_operand (op, mode);
23955
23956               gcc_assert (GET_MODE (op) == mode
23957                           || GET_MODE (op) == VOIDmode);
23958               op = copy_to_mode_reg (mode, op);
23959             }
23960         }
23961
23962       args[i].op = op;
23963       args[i].mode = mode;
23964     }
23965
23966   switch (nargs)
23967     {
23968     case 1:
23969       pat = GEN_FCN (icode) (target, args[0].op);
23970       break;
23971     case 2:
23972       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
23973       break;
23974     default:
23975       gcc_unreachable ();
23976     }
23977
23978   if (! pat)
23979     return 0;
23980   emit_insn (pat);
23981   return klass == store ? 0 : target;
23982 }
23983
23984 /* Return the integer constant in ARG.  Constrain it to be in the range
23985    of the subparts of VEC_TYPE; issue an error if not.  */
23986
23987 static int
23988 get_element_number (tree vec_type, tree arg)
23989 {
23990   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
23991
23992   if (!host_integerp (arg, 1)
23993       || (elt = tree_low_cst (arg, 1), elt > max))
23994     {
23995       error ("selector must be an integer constant in the range 0..%wi", max);
23996       return 0;
23997     }
23998
23999   return elt;
24000 }
24001
24002 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24003    ix86_expand_vector_init.  We DO have language-level syntax for this, in
24004    the form of  (type){ init-list }.  Except that since we can't place emms
24005    instructions from inside the compiler, we can't allow the use of MMX
24006    registers unless the user explicitly asks for it.  So we do *not* define
24007    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
24008    we have builtins invoked by mmintrin.h that gives us license to emit
24009    these sorts of instructions.  */
24010
24011 static rtx
24012 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
24013 {
24014   enum machine_mode tmode = TYPE_MODE (type);
24015   enum machine_mode inner_mode = GET_MODE_INNER (tmode);
24016   int i, n_elt = GET_MODE_NUNITS (tmode);
24017   rtvec v = rtvec_alloc (n_elt);
24018
24019   gcc_assert (VECTOR_MODE_P (tmode));
24020   gcc_assert (call_expr_nargs (exp) == n_elt);
24021
24022   for (i = 0; i < n_elt; ++i)
24023     {
24024       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
24025       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
24026     }
24027
24028   if (!target || !register_operand (target, tmode))
24029     target = gen_reg_rtx (tmode);
24030
24031   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
24032   return target;
24033 }
24034
24035 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24036    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
24037    had a language-level syntax for referencing vector elements.  */
24038
24039 static rtx
24040 ix86_expand_vec_ext_builtin (tree exp, rtx target)
24041 {
24042   enum machine_mode tmode, mode0;
24043   tree arg0, arg1;
24044   int elt;
24045   rtx op0;
24046
24047   arg0 = CALL_EXPR_ARG (exp, 0);
24048   arg1 = CALL_EXPR_ARG (exp, 1);
24049
24050   op0 = expand_normal (arg0);
24051   elt = get_element_number (TREE_TYPE (arg0), arg1);
24052
24053   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24054   mode0 = TYPE_MODE (TREE_TYPE (arg0));
24055   gcc_assert (VECTOR_MODE_P (mode0));
24056
24057   op0 = force_reg (mode0, op0);
24058
24059   if (optimize || !target || !register_operand (target, tmode))
24060     target = gen_reg_rtx (tmode);
24061
24062   ix86_expand_vector_extract (true, target, op0, elt);
24063
24064   return target;
24065 }
24066
24067 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24068    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
24069    a language-level syntax for referencing vector elements.  */
24070
24071 static rtx
24072 ix86_expand_vec_set_builtin (tree exp)
24073 {
24074   enum machine_mode tmode, mode1;
24075   tree arg0, arg1, arg2;
24076   int elt;
24077   rtx op0, op1, target;
24078
24079   arg0 = CALL_EXPR_ARG (exp, 0);
24080   arg1 = CALL_EXPR_ARG (exp, 1);
24081   arg2 = CALL_EXPR_ARG (exp, 2);
24082
24083   tmode = TYPE_MODE (TREE_TYPE (arg0));
24084   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24085   gcc_assert (VECTOR_MODE_P (tmode));
24086
24087   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
24088   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
24089   elt = get_element_number (TREE_TYPE (arg0), arg2);
24090
24091   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
24092     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
24093
24094   op0 = force_reg (tmode, op0);
24095   op1 = force_reg (mode1, op1);
24096
24097   /* OP0 is the source of these builtin functions and shouldn't be
24098      modified.  Create a copy, use it and return it as target.  */
24099   target = gen_reg_rtx (tmode);
24100   emit_move_insn (target, op0);
24101   ix86_expand_vector_set (true, target, op1, elt);
24102
24103   return target;
24104 }
24105
24106 /* Expand an expression EXP that calls a built-in function,
24107    with result going to TARGET if that's convenient
24108    (and in mode MODE if that's convenient).
24109    SUBTARGET may be used as the target for computing one of EXP's operands.
24110    IGNORE is nonzero if the value is to be ignored.  */
24111
24112 static rtx
24113 ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
24114                      enum machine_mode mode ATTRIBUTE_UNUSED,
24115                      int ignore ATTRIBUTE_UNUSED)
24116 {
24117   const struct builtin_description *d;
24118   size_t i;
24119   enum insn_code icode;
24120   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
24121   tree arg0, arg1, arg2;
24122   rtx op0, op1, op2, pat;
24123   enum machine_mode mode0, mode1, mode2;
24124   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
24125
24126   /* Determine whether the builtin function is available under the current ISA.
24127      Originally the builtin was not created if it wasn't applicable to the
24128      current ISA based on the command line switches.  With function specific
24129      options, we need to check in the context of the function making the call
24130      whether it is supported.  */
24131   if (ix86_builtins_isa[fcode].isa
24132       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
24133     {
24134       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
24135                                        NULL, NULL, false);
24136
24137       if (!opts)
24138         error ("%qE needs unknown isa option", fndecl);
24139       else
24140         {
24141           gcc_assert (opts != NULL);
24142           error ("%qE needs isa option %s", fndecl, opts);
24143           free (opts);
24144         }
24145       return const0_rtx;
24146     }
24147
24148   switch (fcode)
24149     {
24150     case IX86_BUILTIN_MASKMOVQ:
24151     case IX86_BUILTIN_MASKMOVDQU:
24152       icode = (fcode == IX86_BUILTIN_MASKMOVQ
24153                ? CODE_FOR_mmx_maskmovq
24154                : CODE_FOR_sse2_maskmovdqu);
24155       /* Note the arg order is different from the operand order.  */
24156       arg1 = CALL_EXPR_ARG (exp, 0);
24157       arg2 = CALL_EXPR_ARG (exp, 1);
24158       arg0 = CALL_EXPR_ARG (exp, 2);
24159       op0 = expand_normal (arg0);
24160       op1 = expand_normal (arg1);
24161       op2 = expand_normal (arg2);
24162       mode0 = insn_data[icode].operand[0].mode;
24163       mode1 = insn_data[icode].operand[1].mode;
24164       mode2 = insn_data[icode].operand[2].mode;
24165
24166       op0 = force_reg (Pmode, op0);
24167       op0 = gen_rtx_MEM (mode1, op0);
24168
24169       if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
24170         op0 = copy_to_mode_reg (mode0, op0);
24171       if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
24172         op1 = copy_to_mode_reg (mode1, op1);
24173       if (! (*insn_data[icode].operand[2].predicate) (op2, mode2))
24174         op2 = copy_to_mode_reg (mode2, op2);
24175       pat = GEN_FCN (icode) (op0, op1, op2);
24176       if (! pat)
24177         return 0;
24178       emit_insn (pat);
24179       return 0;
24180
24181     case IX86_BUILTIN_LDMXCSR:
24182       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
24183       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24184       emit_move_insn (target, op0);
24185       emit_insn (gen_sse_ldmxcsr (target));
24186       return 0;
24187
24188     case IX86_BUILTIN_STMXCSR:
24189       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24190       emit_insn (gen_sse_stmxcsr (target));
24191       return copy_to_mode_reg (SImode, target);
24192
24193     case IX86_BUILTIN_CLFLUSH:
24194         arg0 = CALL_EXPR_ARG (exp, 0);
24195         op0 = expand_normal (arg0);
24196         icode = CODE_FOR_sse2_clflush;
24197         if (! (*insn_data[icode].operand[0].predicate) (op0, Pmode))
24198             op0 = copy_to_mode_reg (Pmode, op0);
24199
24200         emit_insn (gen_sse2_clflush (op0));
24201         return 0;
24202
24203     case IX86_BUILTIN_MONITOR:
24204       arg0 = CALL_EXPR_ARG (exp, 0);
24205       arg1 = CALL_EXPR_ARG (exp, 1);
24206       arg2 = CALL_EXPR_ARG (exp, 2);
24207       op0 = expand_normal (arg0);
24208       op1 = expand_normal (arg1);
24209       op2 = expand_normal (arg2);
24210       if (!REG_P (op0))
24211         op0 = copy_to_mode_reg (Pmode, op0);
24212       if (!REG_P (op1))
24213         op1 = copy_to_mode_reg (SImode, op1);
24214       if (!REG_P (op2))
24215         op2 = copy_to_mode_reg (SImode, op2);
24216       emit_insn ((*ix86_gen_monitor) (op0, op1, op2));
24217       return 0;
24218
24219     case IX86_BUILTIN_MWAIT:
24220       arg0 = CALL_EXPR_ARG (exp, 0);
24221       arg1 = CALL_EXPR_ARG (exp, 1);
24222       op0 = expand_normal (arg0);
24223       op1 = expand_normal (arg1);
24224       if (!REG_P (op0))
24225         op0 = copy_to_mode_reg (SImode, op0);
24226       if (!REG_P (op1))
24227         op1 = copy_to_mode_reg (SImode, op1);
24228       emit_insn (gen_sse3_mwait (op0, op1));
24229       return 0;
24230
24231     case IX86_BUILTIN_VEC_INIT_V2SI:
24232     case IX86_BUILTIN_VEC_INIT_V4HI:
24233     case IX86_BUILTIN_VEC_INIT_V8QI:
24234       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
24235
24236     case IX86_BUILTIN_VEC_EXT_V2DF:
24237     case IX86_BUILTIN_VEC_EXT_V2DI:
24238     case IX86_BUILTIN_VEC_EXT_V4SF:
24239     case IX86_BUILTIN_VEC_EXT_V4SI:
24240     case IX86_BUILTIN_VEC_EXT_V8HI:
24241     case IX86_BUILTIN_VEC_EXT_V2SI:
24242     case IX86_BUILTIN_VEC_EXT_V4HI:
24243     case IX86_BUILTIN_VEC_EXT_V16QI:
24244       return ix86_expand_vec_ext_builtin (exp, target);
24245
24246     case IX86_BUILTIN_VEC_SET_V2DI:
24247     case IX86_BUILTIN_VEC_SET_V4SF:
24248     case IX86_BUILTIN_VEC_SET_V4SI:
24249     case IX86_BUILTIN_VEC_SET_V8HI:
24250     case IX86_BUILTIN_VEC_SET_V4HI:
24251     case IX86_BUILTIN_VEC_SET_V16QI:
24252       return ix86_expand_vec_set_builtin (exp);
24253
24254     case IX86_BUILTIN_INFQ:
24255       {
24256         REAL_VALUE_TYPE inf;
24257         rtx tmp;
24258
24259         real_inf (&inf);
24260         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
24261
24262         tmp = validize_mem (force_const_mem (mode, tmp));
24263
24264         if (target == 0)
24265           target = gen_reg_rtx (mode);
24266
24267         emit_move_insn (target, tmp);
24268         return target;
24269       }
24270
24271     default:
24272       break;
24273     }
24274
24275   for (i = 0, d = bdesc_special_args;
24276        i < ARRAY_SIZE (bdesc_special_args);
24277        i++, d++)
24278     if (d->code == fcode)
24279       return ix86_expand_special_args_builtin (d, exp, target);
24280
24281   for (i = 0, d = bdesc_args;
24282        i < ARRAY_SIZE (bdesc_args);
24283        i++, d++)
24284     if (d->code == fcode)
24285       switch (fcode)
24286         {
24287         case IX86_BUILTIN_FABSQ:
24288         case IX86_BUILTIN_COPYSIGNQ:
24289           if (!TARGET_SSE2)
24290             /* Emit a normal call if SSE2 isn't available.  */
24291             return expand_call (exp, target, ignore);
24292         default:
24293           return ix86_expand_args_builtin (d, exp, target);
24294         }
24295
24296   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
24297     if (d->code == fcode)
24298       return ix86_expand_sse_comi (d, exp, target);
24299
24300   for (i = 0, d = bdesc_pcmpestr;
24301        i < ARRAY_SIZE (bdesc_pcmpestr);
24302        i++, d++)
24303     if (d->code == fcode)
24304       return ix86_expand_sse_pcmpestr (d, exp, target);
24305
24306   for (i = 0, d = bdesc_pcmpistr;
24307        i < ARRAY_SIZE (bdesc_pcmpistr);
24308        i++, d++)
24309     if (d->code == fcode)
24310       return ix86_expand_sse_pcmpistr (d, exp, target);
24311
24312   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
24313     if (d->code == fcode)
24314       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
24315                                             (enum multi_arg_type)d->flag,
24316                                             d->comparison);
24317
24318   gcc_unreachable ();
24319 }
24320
24321 /* Returns a function decl for a vectorized version of the builtin function
24322    with builtin function code FN and the result vector type TYPE, or NULL_TREE
24323    if it is not available.  */
24324
24325 static tree
24326 ix86_builtin_vectorized_function (unsigned int fn, tree type_out,
24327                                   tree type_in)
24328 {
24329   enum machine_mode in_mode, out_mode;
24330   int in_n, out_n;
24331
24332   if (TREE_CODE (type_out) != VECTOR_TYPE
24333       || TREE_CODE (type_in) != VECTOR_TYPE)
24334     return NULL_TREE;
24335
24336   out_mode = TYPE_MODE (TREE_TYPE (type_out));
24337   out_n = TYPE_VECTOR_SUBPARTS (type_out);
24338   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24339   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24340
24341   switch (fn)
24342     {
24343     case BUILT_IN_SQRT:
24344       if (out_mode == DFmode && out_n == 2
24345           && in_mode == DFmode && in_n == 2)
24346         return ix86_builtins[IX86_BUILTIN_SQRTPD];
24347       break;
24348
24349     case BUILT_IN_SQRTF:
24350       if (out_mode == SFmode && out_n == 4
24351           && in_mode == SFmode && in_n == 4)
24352         return ix86_builtins[IX86_BUILTIN_SQRTPS_NR];
24353       break;
24354
24355     case BUILT_IN_LRINT:
24356       if (out_mode == SImode && out_n == 4
24357           && in_mode == DFmode && in_n == 2)
24358         return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
24359       break;
24360
24361     case BUILT_IN_LRINTF:
24362       if (out_mode == SImode && out_n == 4
24363           && in_mode == SFmode && in_n == 4)
24364         return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
24365       break;
24366
24367     default:
24368       ;
24369     }
24370
24371   /* Dispatch to a handler for a vectorization library.  */
24372   if (ix86_veclib_handler)
24373     return (*ix86_veclib_handler)(fn, type_out, type_in);
24374
24375   return NULL_TREE;
24376 }
24377
24378 /* Handler for an SVML-style interface to
24379    a library with vectorized intrinsics.  */
24380
24381 static tree
24382 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
24383 {
24384   char name[20];
24385   tree fntype, new_fndecl, args;
24386   unsigned arity;
24387   const char *bname;
24388   enum machine_mode el_mode, in_mode;
24389   int n, in_n;
24390
24391   /* The SVML is suitable for unsafe math only.  */
24392   if (!flag_unsafe_math_optimizations)
24393     return NULL_TREE;
24394
24395   el_mode = TYPE_MODE (TREE_TYPE (type_out));
24396   n = TYPE_VECTOR_SUBPARTS (type_out);
24397   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24398   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24399   if (el_mode != in_mode
24400       || n != in_n)
24401     return NULL_TREE;
24402
24403   switch (fn)
24404     {
24405     case BUILT_IN_EXP:
24406     case BUILT_IN_LOG:
24407     case BUILT_IN_LOG10:
24408     case BUILT_IN_POW:
24409     case BUILT_IN_TANH:
24410     case BUILT_IN_TAN:
24411     case BUILT_IN_ATAN:
24412     case BUILT_IN_ATAN2:
24413     case BUILT_IN_ATANH:
24414     case BUILT_IN_CBRT:
24415     case BUILT_IN_SINH:
24416     case BUILT_IN_SIN:
24417     case BUILT_IN_ASINH:
24418     case BUILT_IN_ASIN:
24419     case BUILT_IN_COSH:
24420     case BUILT_IN_COS:
24421     case BUILT_IN_ACOSH:
24422     case BUILT_IN_ACOS:
24423       if (el_mode != DFmode || n != 2)
24424         return NULL_TREE;
24425       break;
24426
24427     case BUILT_IN_EXPF:
24428     case BUILT_IN_LOGF:
24429     case BUILT_IN_LOG10F:
24430     case BUILT_IN_POWF:
24431     case BUILT_IN_TANHF:
24432     case BUILT_IN_TANF:
24433     case BUILT_IN_ATANF:
24434     case BUILT_IN_ATAN2F:
24435     case BUILT_IN_ATANHF:
24436     case BUILT_IN_CBRTF:
24437     case BUILT_IN_SINHF:
24438     case BUILT_IN_SINF:
24439     case BUILT_IN_ASINHF:
24440     case BUILT_IN_ASINF:
24441     case BUILT_IN_COSHF:
24442     case BUILT_IN_COSF:
24443     case BUILT_IN_ACOSHF:
24444     case BUILT_IN_ACOSF:
24445       if (el_mode != SFmode || n != 4)
24446         return NULL_TREE;
24447       break;
24448
24449     default:
24450       return NULL_TREE;
24451     }
24452
24453   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
24454
24455   if (fn == BUILT_IN_LOGF)
24456     strcpy (name, "vmlsLn4");
24457   else if (fn == BUILT_IN_LOG)
24458     strcpy (name, "vmldLn2");
24459   else if (n == 4)
24460     {
24461       sprintf (name, "vmls%s", bname+10);
24462       name[strlen (name)-1] = '4';
24463     }
24464   else
24465     sprintf (name, "vmld%s2", bname+10);
24466
24467   /* Convert to uppercase. */
24468   name[4] &= ~0x20;
24469
24470   arity = 0;
24471   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
24472        args = TREE_CHAIN (args))
24473     arity++;
24474
24475   if (arity == 1)
24476     fntype = build_function_type_list (type_out, type_in, NULL);
24477   else
24478     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
24479
24480   /* Build a function declaration for the vectorized function.  */
24481   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
24482   TREE_PUBLIC (new_fndecl) = 1;
24483   DECL_EXTERNAL (new_fndecl) = 1;
24484   DECL_IS_NOVOPS (new_fndecl) = 1;
24485   TREE_READONLY (new_fndecl) = 1;
24486
24487   return new_fndecl;
24488 }
24489
24490 /* Handler for an ACML-style interface to
24491    a library with vectorized intrinsics.  */
24492
24493 static tree
24494 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
24495 {
24496   char name[20] = "__vr.._";
24497   tree fntype, new_fndecl, args;
24498   unsigned arity;
24499   const char *bname;
24500   enum machine_mode el_mode, in_mode;
24501   int n, in_n;
24502
24503   /* The ACML is 64bits only and suitable for unsafe math only as
24504      it does not correctly support parts of IEEE with the required
24505      precision such as denormals.  */
24506   if (!TARGET_64BIT
24507       || !flag_unsafe_math_optimizations)
24508     return NULL_TREE;
24509
24510   el_mode = TYPE_MODE (TREE_TYPE (type_out));
24511   n = TYPE_VECTOR_SUBPARTS (type_out);
24512   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24513   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24514   if (el_mode != in_mode
24515       || n != in_n)
24516     return NULL_TREE;
24517
24518   switch (fn)
24519     {
24520     case BUILT_IN_SIN:
24521     case BUILT_IN_COS:
24522     case BUILT_IN_EXP:
24523     case BUILT_IN_LOG:
24524     case BUILT_IN_LOG2:
24525     case BUILT_IN_LOG10:
24526       name[4] = 'd';
24527       name[5] = '2';
24528       if (el_mode != DFmode
24529           || n != 2)
24530         return NULL_TREE;
24531       break;
24532
24533     case BUILT_IN_SINF:
24534     case BUILT_IN_COSF:
24535     case BUILT_IN_EXPF:
24536     case BUILT_IN_POWF:
24537     case BUILT_IN_LOGF:
24538     case BUILT_IN_LOG2F:
24539     case BUILT_IN_LOG10F:
24540       name[4] = 's';
24541       name[5] = '4';
24542       if (el_mode != SFmode
24543           || n != 4)
24544         return NULL_TREE;
24545       break;
24546
24547     default:
24548       return NULL_TREE;
24549     }
24550
24551   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
24552   sprintf (name + 7, "%s", bname+10);
24553
24554   arity = 0;
24555   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
24556        args = TREE_CHAIN (args))
24557     arity++;
24558
24559   if (arity == 1)
24560     fntype = build_function_type_list (type_out, type_in, NULL);
24561   else
24562     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
24563
24564   /* Build a function declaration for the vectorized function.  */
24565   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
24566   TREE_PUBLIC (new_fndecl) = 1;
24567   DECL_EXTERNAL (new_fndecl) = 1;
24568   DECL_IS_NOVOPS (new_fndecl) = 1;
24569   TREE_READONLY (new_fndecl) = 1;
24570
24571   return new_fndecl;
24572 }
24573
24574
24575 /* Returns a decl of a function that implements conversion of an integer vector
24576    into a floating-point vector, or vice-versa. TYPE is the type of the integer
24577    side of the conversion.
24578    Return NULL_TREE if it is not available.  */
24579
24580 static tree
24581 ix86_vectorize_builtin_conversion (unsigned int code, tree type)
24582 {
24583   if (TREE_CODE (type) != VECTOR_TYPE)
24584     return NULL_TREE;
24585
24586   switch (code)
24587     {
24588     case FLOAT_EXPR:
24589       switch (TYPE_MODE (type))
24590         {
24591         case V4SImode:
24592           return ix86_builtins[IX86_BUILTIN_CVTDQ2PS];
24593         default:
24594           return NULL_TREE;
24595         }
24596
24597     case FIX_TRUNC_EXPR:
24598       switch (TYPE_MODE (type))
24599         {
24600         case V4SImode:
24601           return ix86_builtins[IX86_BUILTIN_CVTTPS2DQ];
24602         default:
24603           return NULL_TREE;
24604         }
24605     default:
24606       return NULL_TREE;
24607
24608     }
24609 }
24610
24611 /* Returns a code for a target-specific builtin that implements
24612    reciprocal of the function, or NULL_TREE if not available.  */
24613
24614 static tree
24615 ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
24616                          bool sqrt ATTRIBUTE_UNUSED)
24617 {
24618   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
24619          && flag_finite_math_only && !flag_trapping_math
24620          && flag_unsafe_math_optimizations))
24621     return NULL_TREE;
24622
24623   if (md_fn)
24624     /* Machine dependent builtins.  */
24625     switch (fn)
24626       {
24627         /* Vectorized version of sqrt to rsqrt conversion.  */
24628       case IX86_BUILTIN_SQRTPS_NR:
24629         return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR];
24630
24631       default:
24632         return NULL_TREE;
24633       }
24634   else
24635     /* Normal builtins.  */
24636     switch (fn)
24637       {
24638         /* Sqrt to rsqrt conversion.  */
24639       case BUILT_IN_SQRTF:
24640         return ix86_builtins[IX86_BUILTIN_RSQRTF];
24641
24642       default:
24643         return NULL_TREE;
24644       }
24645 }
24646
24647 /* Store OPERAND to the memory after reload is completed.  This means
24648    that we can't easily use assign_stack_local.  */
24649 rtx
24650 ix86_force_to_memory (enum machine_mode mode, rtx operand)
24651 {
24652   rtx result;
24653
24654   gcc_assert (reload_completed);
24655   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE)
24656     {
24657       result = gen_rtx_MEM (mode,
24658                             gen_rtx_PLUS (Pmode,
24659                                           stack_pointer_rtx,
24660                                           GEN_INT (-RED_ZONE_SIZE)));
24661       emit_move_insn (result, operand);
24662     }
24663   else if ((TARGET_64BIT_MS_ABI || !TARGET_RED_ZONE) && TARGET_64BIT)
24664     {
24665       switch (mode)
24666         {
24667         case HImode:
24668         case SImode:
24669           operand = gen_lowpart (DImode, operand);
24670           /* FALLTHRU */
24671         case DImode:
24672           emit_insn (
24673                       gen_rtx_SET (VOIDmode,
24674                                    gen_rtx_MEM (DImode,
24675                                                 gen_rtx_PRE_DEC (DImode,
24676                                                         stack_pointer_rtx)),
24677                                    operand));
24678           break;
24679         default:
24680           gcc_unreachable ();
24681         }
24682       result = gen_rtx_MEM (mode, stack_pointer_rtx);
24683     }
24684   else
24685     {
24686       switch (mode)
24687         {
24688         case DImode:
24689           {
24690             rtx operands[2];
24691             split_di (&operand, 1, operands, operands + 1);
24692             emit_insn (
24693                         gen_rtx_SET (VOIDmode,
24694                                      gen_rtx_MEM (SImode,
24695                                                   gen_rtx_PRE_DEC (Pmode,
24696                                                         stack_pointer_rtx)),
24697                                      operands[1]));
24698             emit_insn (
24699                         gen_rtx_SET (VOIDmode,
24700                                      gen_rtx_MEM (SImode,
24701                                                   gen_rtx_PRE_DEC (Pmode,
24702                                                         stack_pointer_rtx)),
24703                                      operands[0]));
24704           }
24705           break;
24706         case HImode:
24707           /* Store HImodes as SImodes.  */
24708           operand = gen_lowpart (SImode, operand);
24709           /* FALLTHRU */
24710         case SImode:
24711           emit_insn (
24712                       gen_rtx_SET (VOIDmode,
24713                                    gen_rtx_MEM (GET_MODE (operand),
24714                                                 gen_rtx_PRE_DEC (SImode,
24715                                                         stack_pointer_rtx)),
24716                                    operand));
24717           break;
24718         default:
24719           gcc_unreachable ();
24720         }
24721       result = gen_rtx_MEM (mode, stack_pointer_rtx);
24722     }
24723   return result;
24724 }
24725
24726 /* Free operand from the memory.  */
24727 void
24728 ix86_free_from_memory (enum machine_mode mode)
24729 {
24730   if (!TARGET_RED_ZONE || TARGET_64BIT_MS_ABI)
24731     {
24732       int size;
24733
24734       if (mode == DImode || TARGET_64BIT)
24735         size = 8;
24736       else
24737         size = 4;
24738       /* Use LEA to deallocate stack space.  In peephole2 it will be converted
24739          to pop or add instruction if registers are available.  */
24740       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
24741                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
24742                                             GEN_INT (size))));
24743     }
24744 }
24745
24746 /* Put float CONST_DOUBLE in the constant pool instead of fp regs.
24747    QImode must go into class Q_REGS.
24748    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
24749    movdf to do mem-to-mem moves through integer regs.  */
24750 enum reg_class
24751 ix86_preferred_reload_class (rtx x, enum reg_class regclass)
24752 {
24753   enum machine_mode mode = GET_MODE (x);
24754
24755   /* We're only allowed to return a subclass of CLASS.  Many of the
24756      following checks fail for NO_REGS, so eliminate that early.  */
24757   if (regclass == NO_REGS)
24758     return NO_REGS;
24759
24760   /* All classes can load zeros.  */
24761   if (x == CONST0_RTX (mode))
24762     return regclass;
24763
24764   /* Force constants into memory if we are loading a (nonzero) constant into
24765      an MMX or SSE register.  This is because there are no MMX/SSE instructions
24766      to load from a constant.  */
24767   if (CONSTANT_P (x)
24768       && (MAYBE_MMX_CLASS_P (regclass) || MAYBE_SSE_CLASS_P (regclass)))
24769     return NO_REGS;
24770
24771   /* Prefer SSE regs only, if we can use them for math.  */
24772   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
24773     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
24774
24775   /* Floating-point constants need more complex checks.  */
24776   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
24777     {
24778       /* General regs can load everything.  */
24779       if (reg_class_subset_p (regclass, GENERAL_REGS))
24780         return regclass;
24781
24782       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
24783          zero above.  We only want to wind up preferring 80387 registers if
24784          we plan on doing computation with them.  */
24785       if (TARGET_80387
24786           && standard_80387_constant_p (x))
24787         {
24788           /* Limit class to non-sse.  */
24789           if (regclass == FLOAT_SSE_REGS)
24790             return FLOAT_REGS;
24791           if (regclass == FP_TOP_SSE_REGS)
24792             return FP_TOP_REG;
24793           if (regclass == FP_SECOND_SSE_REGS)
24794             return FP_SECOND_REG;
24795           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
24796             return regclass;
24797         }
24798
24799       return NO_REGS;
24800     }
24801
24802   /* Generally when we see PLUS here, it's the function invariant
24803      (plus soft-fp const_int).  Which can only be computed into general
24804      regs.  */
24805   if (GET_CODE (x) == PLUS)
24806     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
24807
24808   /* QImode constants are easy to load, but non-constant QImode data
24809      must go into Q_REGS.  */
24810   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
24811     {
24812       if (reg_class_subset_p (regclass, Q_REGS))
24813         return regclass;
24814       if (reg_class_subset_p (Q_REGS, regclass))
24815         return Q_REGS;
24816       return NO_REGS;
24817     }
24818
24819   return regclass;
24820 }
24821
24822 /* Discourage putting floating-point values in SSE registers unless
24823    SSE math is being used, and likewise for the 387 registers.  */
24824 enum reg_class
24825 ix86_preferred_output_reload_class (rtx x, enum reg_class regclass)
24826 {
24827   enum machine_mode mode = GET_MODE (x);
24828
24829   /* Restrict the output reload class to the register bank that we are doing
24830      math on.  If we would like not to return a subset of CLASS, reject this
24831      alternative: if reload cannot do this, it will still use its choice.  */
24832   mode = GET_MODE (x);
24833   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
24834     return MAYBE_SSE_CLASS_P (regclass) ? SSE_REGS : NO_REGS;
24835
24836   if (X87_FLOAT_MODE_P (mode))
24837     {
24838       if (regclass == FP_TOP_SSE_REGS)
24839         return FP_TOP_REG;
24840       else if (regclass == FP_SECOND_SSE_REGS)
24841         return FP_SECOND_REG;
24842       else
24843         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
24844     }
24845
24846   return regclass;
24847 }
24848
24849 static enum reg_class
24850 ix86_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
24851                        enum machine_mode mode,
24852                        secondary_reload_info *sri ATTRIBUTE_UNUSED)
24853 {
24854   /* QImode spills from non-QI registers require
24855      intermediate register on 32bit targets.  */
24856   if (!in_p && mode == QImode && !TARGET_64BIT
24857       && (rclass == GENERAL_REGS
24858           || rclass == LEGACY_REGS
24859           || rclass == INDEX_REGS))
24860     {
24861       int regno;
24862
24863       if (REG_P (x))
24864         regno = REGNO (x);
24865       else
24866         regno = -1;
24867
24868       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
24869         regno = true_regnum (x);
24870
24871       /* Return Q_REGS if the operand is in memory.  */
24872       if (regno == -1)
24873         return Q_REGS;
24874     }
24875
24876   return NO_REGS;
24877 }
24878
24879 /* If we are copying between general and FP registers, we need a memory
24880    location. The same is true for SSE and MMX registers.
24881
24882    To optimize register_move_cost performance, allow inline variant.
24883
24884    The macro can't work reliably when one of the CLASSES is class containing
24885    registers from multiple units (SSE, MMX, integer).  We avoid this by never
24886    combining those units in single alternative in the machine description.
24887    Ensure that this constraint holds to avoid unexpected surprises.
24888
24889    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
24890    enforce these sanity checks.  */
24891
24892 static inline int
24893 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
24894                               enum machine_mode mode, int strict)
24895 {
24896   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
24897       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
24898       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
24899       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
24900       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
24901       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
24902     {
24903       gcc_assert (!strict);
24904       return true;
24905     }
24906
24907   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
24908     return true;
24909
24910   /* ??? This is a lie.  We do have moves between mmx/general, and for
24911      mmx/sse2.  But by saying we need secondary memory we discourage the
24912      register allocator from using the mmx registers unless needed.  */
24913   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
24914     return true;
24915
24916   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
24917     {
24918       /* SSE1 doesn't have any direct moves from other classes.  */
24919       if (!TARGET_SSE2)
24920         return true;
24921
24922       /* If the target says that inter-unit moves are more expensive
24923          than moving through memory, then don't generate them.  */
24924       if (!TARGET_INTER_UNIT_MOVES)
24925         return true;
24926
24927       /* Between SSE and general, we have moves no larger than word size.  */
24928       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
24929         return true;
24930     }
24931
24932   return false;
24933 }
24934
24935 int
24936 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
24937                               enum machine_mode mode, int strict)
24938 {
24939   return inline_secondary_memory_needed (class1, class2, mode, strict);
24940 }
24941
24942 /* Return true if the registers in CLASS cannot represent the change from
24943    modes FROM to TO.  */
24944
24945 bool
24946 ix86_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
24947                                enum reg_class regclass)
24948 {
24949   if (from == to)
24950     return false;
24951
24952   /* x87 registers can't do subreg at all, as all values are reformatted
24953      to extended precision.  */
24954   if (MAYBE_FLOAT_CLASS_P (regclass))
24955     return true;
24956
24957   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
24958     {
24959       /* Vector registers do not support QI or HImode loads.  If we don't
24960          disallow a change to these modes, reload will assume it's ok to
24961          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
24962          the vec_dupv4hi pattern.  */
24963       if (GET_MODE_SIZE (from) < 4)
24964         return true;
24965
24966       /* Vector registers do not support subreg with nonzero offsets, which
24967          are otherwise valid for integer registers.  Since we can't see
24968          whether we have a nonzero offset from here, prohibit all
24969          nonparadoxical subregs changing size.  */
24970       if (GET_MODE_SIZE (to) < GET_MODE_SIZE (from))
24971         return true;
24972     }
24973
24974   return false;
24975 }
24976
24977 /* Return the cost of moving data of mode M between a
24978    register and memory.  A value of 2 is the default; this cost is
24979    relative to those in `REGISTER_MOVE_COST'.
24980
24981    This function is used extensively by register_move_cost that is used to
24982    build tables at startup.  Make it inline in this case.
24983    When IN is 2, return maximum of in and out move cost.
24984
24985    If moving between registers and memory is more expensive than
24986    between two registers, you should define this macro to express the
24987    relative cost.
24988
24989    Model also increased moving costs of QImode registers in non
24990    Q_REGS classes.
24991  */
24992 static inline int
24993 inline_memory_move_cost (enum machine_mode mode, enum reg_class regclass,
24994                          int in)
24995 {
24996   int cost;
24997   if (FLOAT_CLASS_P (regclass))
24998     {
24999       int index;
25000       switch (mode)
25001         {
25002           case SFmode:
25003             index = 0;
25004             break;
25005           case DFmode:
25006             index = 1;
25007             break;
25008           case XFmode:
25009             index = 2;
25010             break;
25011           default:
25012             return 100;
25013         }
25014       if (in == 2)
25015         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
25016       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
25017     }
25018   if (SSE_CLASS_P (regclass))
25019     {
25020       int index;
25021       switch (GET_MODE_SIZE (mode))
25022         {
25023           case 4:
25024             index = 0;
25025             break;
25026           case 8:
25027             index = 1;
25028             break;
25029           case 16:
25030             index = 2;
25031             break;
25032           default:
25033             return 100;
25034         }
25035       if (in == 2)
25036         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
25037       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
25038     }
25039   if (MMX_CLASS_P (regclass))
25040     {
25041       int index;
25042       switch (GET_MODE_SIZE (mode))
25043         {
25044           case 4:
25045             index = 0;
25046             break;
25047           case 8:
25048             index = 1;
25049             break;
25050           default:
25051             return 100;
25052         }
25053       if (in)
25054         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
25055       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
25056     }
25057   switch (GET_MODE_SIZE (mode))
25058     {
25059       case 1:
25060         if (Q_CLASS_P (regclass) || TARGET_64BIT)
25061           {
25062             if (!in)
25063               return ix86_cost->int_store[0];
25064             if (TARGET_PARTIAL_REG_DEPENDENCY
25065                 && optimize_function_for_speed_p (cfun))
25066               cost = ix86_cost->movzbl_load;
25067             else
25068               cost = ix86_cost->int_load[0];
25069             if (in == 2)
25070               return MAX (cost, ix86_cost->int_store[0]);
25071             return cost;
25072           }
25073         else
25074           {
25075            if (in == 2)
25076              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
25077            if (in)
25078              return ix86_cost->movzbl_load;
25079            else
25080              return ix86_cost->int_store[0] + 4;
25081           }
25082         break;
25083       case 2:
25084         if (in == 2)
25085           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
25086         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
25087       default:
25088         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
25089         if (mode == TFmode)
25090           mode = XFmode;
25091         if (in == 2)
25092           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
25093         else if (in)
25094           cost = ix86_cost->int_load[2];
25095         else
25096           cost = ix86_cost->int_store[2];
25097         return (cost * (((int) GET_MODE_SIZE (mode)
25098                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
25099     }
25100 }
25101
25102 int
25103 ix86_memory_move_cost (enum machine_mode mode, enum reg_class regclass, int in)
25104 {
25105   return inline_memory_move_cost (mode, regclass, in);
25106 }
25107
25108
25109 /* Return the cost of moving data from a register in class CLASS1 to
25110    one in class CLASS2.
25111
25112    It is not required that the cost always equal 2 when FROM is the same as TO;
25113    on some machines it is expensive to move between registers if they are not
25114    general registers.  */
25115
25116 int
25117 ix86_register_move_cost (enum machine_mode mode, enum reg_class class1,
25118                          enum reg_class class2)
25119 {
25120   /* In case we require secondary memory, compute cost of the store followed
25121      by load.  In order to avoid bad register allocation choices, we need
25122      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
25123
25124   if (inline_secondary_memory_needed (class1, class2, mode, 0))
25125     {
25126       int cost = 1;
25127
25128       cost += inline_memory_move_cost (mode, class1, 2);
25129       cost += inline_memory_move_cost (mode, class2, 2);
25130
25131       /* In case of copying from general_purpose_register we may emit multiple
25132          stores followed by single load causing memory size mismatch stall.
25133          Count this as arbitrarily high cost of 20.  */
25134       if (CLASS_MAX_NREGS (class1, mode) > CLASS_MAX_NREGS (class2, mode))
25135         cost += 20;
25136
25137       /* In the case of FP/MMX moves, the registers actually overlap, and we
25138          have to switch modes in order to treat them differently.  */
25139       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
25140           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
25141         cost += 20;
25142
25143       return cost;
25144     }
25145
25146   /* Moves between SSE/MMX and integer unit are expensive.  */
25147   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
25148       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
25149
25150     /* ??? By keeping returned value relatively high, we limit the number
25151        of moves between integer and MMX/SSE registers for all targets.
25152        Additionally, high value prevents problem with x86_modes_tieable_p(),
25153        where integer modes in MMX/SSE registers are not tieable
25154        because of missing QImode and HImode moves to, from or between
25155        MMX/SSE registers.  */
25156     return MAX (8, ix86_cost->mmxsse_to_integer);
25157
25158   if (MAYBE_FLOAT_CLASS_P (class1))
25159     return ix86_cost->fp_move;
25160   if (MAYBE_SSE_CLASS_P (class1))
25161     return ix86_cost->sse_move;
25162   if (MAYBE_MMX_CLASS_P (class1))
25163     return ix86_cost->mmx_move;
25164   return 2;
25165 }
25166
25167 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE.  */
25168
25169 bool
25170 ix86_hard_regno_mode_ok (int regno, enum machine_mode mode)
25171 {
25172   /* Flags and only flags can only hold CCmode values.  */
25173   if (CC_REGNO_P (regno))
25174     return GET_MODE_CLASS (mode) == MODE_CC;
25175   if (GET_MODE_CLASS (mode) == MODE_CC
25176       || GET_MODE_CLASS (mode) == MODE_RANDOM
25177       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
25178     return 0;
25179   if (FP_REGNO_P (regno))
25180     return VALID_FP_MODE_P (mode);
25181   if (SSE_REGNO_P (regno))
25182     {
25183       /* We implement the move patterns for all vector modes into and
25184          out of SSE registers, even when no operation instructions
25185          are available.  OImode move is available only when AVX is
25186          enabled.  */
25187       return ((TARGET_AVX && mode == OImode)
25188               || VALID_AVX256_REG_MODE (mode)
25189               || VALID_SSE_REG_MODE (mode)
25190               || VALID_SSE2_REG_MODE (mode)
25191               || VALID_MMX_REG_MODE (mode)
25192               || VALID_MMX_REG_MODE_3DNOW (mode));
25193     }
25194   if (MMX_REGNO_P (regno))
25195     {
25196       /* We implement the move patterns for 3DNOW modes even in MMX mode,
25197          so if the register is available at all, then we can move data of
25198          the given mode into or out of it.  */
25199       return (VALID_MMX_REG_MODE (mode)
25200               || VALID_MMX_REG_MODE_3DNOW (mode));
25201     }
25202
25203   if (mode == QImode)
25204     {
25205       /* Take care for QImode values - they can be in non-QI regs,
25206          but then they do cause partial register stalls.  */
25207       if (regno < 4 || TARGET_64BIT)
25208         return 1;
25209       if (!TARGET_PARTIAL_REG_STALL)
25210         return 1;
25211       return reload_in_progress || reload_completed;
25212     }
25213   /* We handle both integer and floats in the general purpose registers.  */
25214   else if (VALID_INT_MODE_P (mode))
25215     return 1;
25216   else if (VALID_FP_MODE_P (mode))
25217     return 1;
25218   else if (VALID_DFP_MODE_P (mode))
25219     return 1;
25220   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
25221      on to use that value in smaller contexts, this can easily force a
25222      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
25223      supporting DImode, allow it.  */
25224   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
25225     return 1;
25226
25227   return 0;
25228 }
25229
25230 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
25231    tieable integer mode.  */
25232
25233 static bool
25234 ix86_tieable_integer_mode_p (enum machine_mode mode)
25235 {
25236   switch (mode)
25237     {
25238     case HImode:
25239     case SImode:
25240       return true;
25241
25242     case QImode:
25243       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
25244
25245     case DImode:
25246       return TARGET_64BIT;
25247
25248     default:
25249       return false;
25250     }
25251 }
25252
25253 /* Return true if MODE1 is accessible in a register that can hold MODE2
25254    without copying.  That is, all register classes that can hold MODE2
25255    can also hold MODE1.  */
25256
25257 bool
25258 ix86_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
25259 {
25260   if (mode1 == mode2)
25261     return true;
25262
25263   if (ix86_tieable_integer_mode_p (mode1)
25264       && ix86_tieable_integer_mode_p (mode2))
25265     return true;
25266
25267   /* MODE2 being XFmode implies fp stack or general regs, which means we
25268      can tie any smaller floating point modes to it.  Note that we do not
25269      tie this with TFmode.  */
25270   if (mode2 == XFmode)
25271     return mode1 == SFmode || mode1 == DFmode;
25272
25273   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
25274      that we can tie it with SFmode.  */
25275   if (mode2 == DFmode)
25276     return mode1 == SFmode;
25277
25278   /* If MODE2 is only appropriate for an SSE register, then tie with
25279      any other mode acceptable to SSE registers.  */
25280   if (GET_MODE_SIZE (mode2) == 16
25281       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
25282     return (GET_MODE_SIZE (mode1) == 16
25283             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
25284
25285   /* If MODE2 is appropriate for an MMX register, then tie
25286      with any other mode acceptable to MMX registers.  */
25287   if (GET_MODE_SIZE (mode2) == 8
25288       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
25289     return (GET_MODE_SIZE (mode1) == 8
25290             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
25291
25292   return false;
25293 }
25294
25295 /* Compute a (partial) cost for rtx X.  Return true if the complete
25296    cost has been computed, and false if subexpressions should be
25297    scanned.  In either case, *TOTAL contains the cost result.  */
25298
25299 static bool
25300 ix86_rtx_costs (rtx x, int code, int outer_code_i, int *total, bool speed)
25301 {
25302   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
25303   enum machine_mode mode = GET_MODE (x);
25304   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
25305
25306   switch (code)
25307     {
25308     case CONST_INT:
25309     case CONST:
25310     case LABEL_REF:
25311     case SYMBOL_REF:
25312       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
25313         *total = 3;
25314       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
25315         *total = 2;
25316       else if (flag_pic && SYMBOLIC_CONST (x)
25317                && (!TARGET_64BIT
25318                    || (!GET_CODE (x) != LABEL_REF
25319                        && (GET_CODE (x) != SYMBOL_REF
25320                            || !SYMBOL_REF_LOCAL_P (x)))))
25321         *total = 1;
25322       else
25323         *total = 0;
25324       return true;
25325
25326     case CONST_DOUBLE:
25327       if (mode == VOIDmode)
25328         *total = 0;
25329       else
25330         switch (standard_80387_constant_p (x))
25331           {
25332           case 1: /* 0.0 */
25333             *total = 1;
25334             break;
25335           default: /* Other constants */
25336             *total = 2;
25337             break;
25338           case 0:
25339           case -1:
25340             /* Start with (MEM (SYMBOL_REF)), since that's where
25341                it'll probably end up.  Add a penalty for size.  */
25342             *total = (COSTS_N_INSNS (1)
25343                       + (flag_pic != 0 && !TARGET_64BIT)
25344                       + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
25345             break;
25346           }
25347       return true;
25348
25349     case ZERO_EXTEND:
25350       /* The zero extensions is often completely free on x86_64, so make
25351          it as cheap as possible.  */
25352       if (TARGET_64BIT && mode == DImode
25353           && GET_MODE (XEXP (x, 0)) == SImode)
25354         *total = 1;
25355       else if (TARGET_ZERO_EXTEND_WITH_AND)
25356         *total = cost->add;
25357       else
25358         *total = cost->movzx;
25359       return false;
25360
25361     case SIGN_EXTEND:
25362       *total = cost->movsx;
25363       return false;
25364
25365     case ASHIFT:
25366       if (CONST_INT_P (XEXP (x, 1))
25367           && (GET_MODE (XEXP (x, 0)) != DImode || TARGET_64BIT))
25368         {
25369           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
25370           if (value == 1)
25371             {
25372               *total = cost->add;
25373               return false;
25374             }
25375           if ((value == 2 || value == 3)
25376               && cost->lea <= cost->shift_const)
25377             {
25378               *total = cost->lea;
25379               return false;
25380             }
25381         }
25382       /* FALLTHRU */
25383
25384     case ROTATE:
25385     case ASHIFTRT:
25386     case LSHIFTRT:
25387     case ROTATERT:
25388       if (!TARGET_64BIT && GET_MODE (XEXP (x, 0)) == DImode)
25389         {
25390           if (CONST_INT_P (XEXP (x, 1)))
25391             {
25392               if (INTVAL (XEXP (x, 1)) > 32)
25393                 *total = cost->shift_const + COSTS_N_INSNS (2);
25394               else
25395                 *total = cost->shift_const * 2;
25396             }
25397           else
25398             {
25399               if (GET_CODE (XEXP (x, 1)) == AND)
25400                 *total = cost->shift_var * 2;
25401               else
25402                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
25403             }
25404         }
25405       else
25406         {
25407           if (CONST_INT_P (XEXP (x, 1)))
25408             *total = cost->shift_const;
25409           else
25410             *total = cost->shift_var;
25411         }
25412       return false;
25413
25414     case MULT:
25415       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25416         {
25417           /* ??? SSE scalar cost should be used here.  */
25418           *total = cost->fmul;
25419           return false;
25420         }
25421       else if (X87_FLOAT_MODE_P (mode))
25422         {
25423           *total = cost->fmul;
25424           return false;
25425         }
25426       else if (FLOAT_MODE_P (mode))
25427         {
25428           /* ??? SSE vector cost should be used here.  */
25429           *total = cost->fmul;
25430           return false;
25431         }
25432       else
25433         {
25434           rtx op0 = XEXP (x, 0);
25435           rtx op1 = XEXP (x, 1);
25436           int nbits;
25437           if (CONST_INT_P (XEXP (x, 1)))
25438             {
25439               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
25440               for (nbits = 0; value != 0; value &= value - 1)
25441                 nbits++;
25442             }
25443           else
25444             /* This is arbitrary.  */
25445             nbits = 7;
25446
25447           /* Compute costs correctly for widening multiplication.  */
25448           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
25449               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
25450                  == GET_MODE_SIZE (mode))
25451             {
25452               int is_mulwiden = 0;
25453               enum machine_mode inner_mode = GET_MODE (op0);
25454
25455               if (GET_CODE (op0) == GET_CODE (op1))
25456                 is_mulwiden = 1, op1 = XEXP (op1, 0);
25457               else if (CONST_INT_P (op1))
25458                 {
25459                   if (GET_CODE (op0) == SIGN_EXTEND)
25460                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
25461                                   == INTVAL (op1);
25462                   else
25463                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
25464                 }
25465
25466               if (is_mulwiden)
25467                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
25468             }
25469
25470           *total = (cost->mult_init[MODE_INDEX (mode)]
25471                     + nbits * cost->mult_bit
25472                     + rtx_cost (op0, outer_code, speed) + rtx_cost (op1, outer_code, speed));
25473
25474           return true;
25475         }
25476
25477     case DIV:
25478     case UDIV:
25479     case MOD:
25480     case UMOD:
25481       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25482         /* ??? SSE cost should be used here.  */
25483         *total = cost->fdiv;
25484       else if (X87_FLOAT_MODE_P (mode))
25485         *total = cost->fdiv;
25486       else if (FLOAT_MODE_P (mode))
25487         /* ??? SSE vector cost should be used here.  */
25488         *total = cost->fdiv;
25489       else
25490         *total = cost->divide[MODE_INDEX (mode)];
25491       return false;
25492
25493     case PLUS:
25494       if (GET_MODE_CLASS (mode) == MODE_INT
25495                && GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (Pmode))
25496         {
25497           if (GET_CODE (XEXP (x, 0)) == PLUS
25498               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
25499               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
25500               && CONSTANT_P (XEXP (x, 1)))
25501             {
25502               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
25503               if (val == 2 || val == 4 || val == 8)
25504                 {
25505                   *total = cost->lea;
25506                   *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
25507                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
25508                                       outer_code, speed);
25509                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25510                   return true;
25511                 }
25512             }
25513           else if (GET_CODE (XEXP (x, 0)) == MULT
25514                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
25515             {
25516               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
25517               if (val == 2 || val == 4 || val == 8)
25518                 {
25519                   *total = cost->lea;
25520                   *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
25521                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25522                   return true;
25523                 }
25524             }
25525           else if (GET_CODE (XEXP (x, 0)) == PLUS)
25526             {
25527               *total = cost->lea;
25528               *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
25529               *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
25530               *total += rtx_cost (XEXP (x, 1), outer_code, speed);
25531               return true;
25532             }
25533         }
25534       /* FALLTHRU */
25535
25536     case MINUS:
25537       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25538         {
25539           /* ??? SSE cost should be used here.  */
25540           *total = cost->fadd;
25541           return false;
25542         }
25543       else if (X87_FLOAT_MODE_P (mode))
25544         {
25545           *total = cost->fadd;
25546           return false;
25547         }
25548       else if (FLOAT_MODE_P (mode))
25549         {
25550           /* ??? SSE vector cost should be used here.  */
25551           *total = cost->fadd;
25552           return false;
25553         }
25554       /* FALLTHRU */
25555
25556     case AND:
25557     case IOR:
25558     case XOR:
25559       if (!TARGET_64BIT && mode == DImode)
25560         {
25561           *total = (cost->add * 2
25562                     + (rtx_cost (XEXP (x, 0), outer_code, speed)
25563                        << (GET_MODE (XEXP (x, 0)) != DImode))
25564                     + (rtx_cost (XEXP (x, 1), outer_code, speed)
25565                        << (GET_MODE (XEXP (x, 1)) != DImode)));
25566           return true;
25567         }
25568       /* FALLTHRU */
25569
25570     case NEG:
25571       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25572         {
25573           /* ??? SSE cost should be used here.  */
25574           *total = cost->fchs;
25575           return false;
25576         }
25577       else if (X87_FLOAT_MODE_P (mode))
25578         {
25579           *total = cost->fchs;
25580           return false;
25581         }
25582       else if (FLOAT_MODE_P (mode))
25583         {
25584           /* ??? SSE vector cost should be used here.  */
25585           *total = cost->fchs;
25586           return false;
25587         }
25588       /* FALLTHRU */
25589
25590     case NOT:
25591       if (!TARGET_64BIT && mode == DImode)
25592         *total = cost->add * 2;
25593       else
25594         *total = cost->add;
25595       return false;
25596
25597     case COMPARE:
25598       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
25599           && XEXP (XEXP (x, 0), 1) == const1_rtx
25600           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
25601           && XEXP (x, 1) == const0_rtx)
25602         {
25603           /* This kind of construct is implemented using test[bwl].
25604              Treat it as if we had an AND.  */
25605           *total = (cost->add
25606                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed)
25607                     + rtx_cost (const1_rtx, outer_code, speed));
25608           return true;
25609         }
25610       return false;
25611
25612     case FLOAT_EXTEND:
25613       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
25614         *total = 0;
25615       return false;
25616
25617     case ABS:
25618       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25619         /* ??? SSE cost should be used here.  */
25620         *total = cost->fabs;
25621       else if (X87_FLOAT_MODE_P (mode))
25622         *total = cost->fabs;
25623       else if (FLOAT_MODE_P (mode))
25624         /* ??? SSE vector cost should be used here.  */
25625         *total = cost->fabs;
25626       return false;
25627
25628     case SQRT:
25629       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25630         /* ??? SSE cost should be used here.  */
25631         *total = cost->fsqrt;
25632       else if (X87_FLOAT_MODE_P (mode))
25633         *total = cost->fsqrt;
25634       else if (FLOAT_MODE_P (mode))
25635         /* ??? SSE vector cost should be used here.  */
25636         *total = cost->fsqrt;
25637       return false;
25638
25639     case UNSPEC:
25640       if (XINT (x, 1) == UNSPEC_TP)
25641         *total = 0;
25642       return false;
25643
25644     default:
25645       return false;
25646     }
25647 }
25648
25649 #if TARGET_MACHO
25650
25651 static int current_machopic_label_num;
25652
25653 /* Given a symbol name and its associated stub, write out the
25654    definition of the stub.  */
25655
25656 void
25657 machopic_output_stub (FILE *file, const char *symb, const char *stub)
25658 {
25659   unsigned int length;
25660   char *binder_name, *symbol_name, lazy_ptr_name[32];
25661   int label = ++current_machopic_label_num;
25662
25663   /* For 64-bit we shouldn't get here.  */
25664   gcc_assert (!TARGET_64BIT);
25665
25666   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
25667   symb = (*targetm.strip_name_encoding) (symb);
25668
25669   length = strlen (stub);
25670   binder_name = XALLOCAVEC (char, length + 32);
25671   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
25672
25673   length = strlen (symb);
25674   symbol_name = XALLOCAVEC (char, length + 32);
25675   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
25676
25677   sprintf (lazy_ptr_name, "L%d$lz", label);
25678
25679   if (MACHOPIC_PURE)
25680     switch_to_section (darwin_sections[machopic_picsymbol_stub_section]);
25681   else
25682     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
25683
25684   fprintf (file, "%s:\n", stub);
25685   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
25686
25687   if (MACHOPIC_PURE)
25688     {
25689       fprintf (file, "\tcall\tLPC$%d\nLPC$%d:\tpopl\t%%eax\n", label, label);
25690       fprintf (file, "\tmovl\t%s-LPC$%d(%%eax),%%edx\n", lazy_ptr_name, label);
25691       fprintf (file, "\tjmp\t*%%edx\n");
25692     }
25693   else
25694     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
25695
25696   fprintf (file, "%s:\n", binder_name);
25697
25698   if (MACHOPIC_PURE)
25699     {
25700       fprintf (file, "\tlea\t%s-LPC$%d(%%eax),%%eax\n", lazy_ptr_name, label);
25701       fprintf (file, "\tpushl\t%%eax\n");
25702     }
25703   else
25704     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
25705
25706   fprintf (file, "\tjmp\tdyld_stub_binding_helper\n");
25707
25708   switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
25709   fprintf (file, "%s:\n", lazy_ptr_name);
25710   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
25711   fprintf (file, "\t.long %s\n", binder_name);
25712 }
25713
25714 void
25715 darwin_x86_file_end (void)
25716 {
25717   darwin_file_end ();
25718   ix86_file_end ();
25719 }
25720 #endif /* TARGET_MACHO */
25721
25722 /* Order the registers for register allocator.  */
25723
25724 void
25725 x86_order_regs_for_local_alloc (void)
25726 {
25727    int pos = 0;
25728    int i;
25729
25730    /* First allocate the local general purpose registers.  */
25731    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
25732      if (GENERAL_REGNO_P (i) && call_used_regs[i])
25733         reg_alloc_order [pos++] = i;
25734
25735    /* Global general purpose registers.  */
25736    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
25737      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
25738         reg_alloc_order [pos++] = i;
25739
25740    /* x87 registers come first in case we are doing FP math
25741       using them.  */
25742    if (!TARGET_SSE_MATH)
25743      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
25744        reg_alloc_order [pos++] = i;
25745
25746    /* SSE registers.  */
25747    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
25748      reg_alloc_order [pos++] = i;
25749    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
25750      reg_alloc_order [pos++] = i;
25751
25752    /* x87 registers.  */
25753    if (TARGET_SSE_MATH)
25754      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
25755        reg_alloc_order [pos++] = i;
25756
25757    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
25758      reg_alloc_order [pos++] = i;
25759
25760    /* Initialize the rest of array as we do not allocate some registers
25761       at all.  */
25762    while (pos < FIRST_PSEUDO_REGISTER)
25763      reg_alloc_order [pos++] = 0;
25764 }
25765
25766 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
25767    struct attribute_spec.handler.  */
25768 static tree
25769 ix86_handle_abi_attribute (tree *node, tree name,
25770                               tree args ATTRIBUTE_UNUSED,
25771                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
25772 {
25773   if (TREE_CODE (*node) != FUNCTION_TYPE
25774       && TREE_CODE (*node) != METHOD_TYPE
25775       && TREE_CODE (*node) != FIELD_DECL
25776       && TREE_CODE (*node) != TYPE_DECL)
25777     {
25778       warning (OPT_Wattributes, "%qs attribute only applies to functions",
25779                IDENTIFIER_POINTER (name));
25780       *no_add_attrs = true;
25781       return NULL_TREE;
25782     }
25783   if (!TARGET_64BIT)
25784     {
25785       warning (OPT_Wattributes, "%qs attribute only available for 64-bit",
25786                IDENTIFIER_POINTER (name));
25787       *no_add_attrs = true;
25788       return NULL_TREE;
25789     }
25790
25791   /* Can combine regparm with all attributes but fastcall.  */
25792   if (is_attribute_p ("ms_abi", name))
25793     {
25794       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
25795         {
25796           error ("ms_abi and sysv_abi attributes are not compatible");
25797         }
25798
25799       return NULL_TREE;
25800     }
25801   else if (is_attribute_p ("sysv_abi", name))
25802     {
25803       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
25804         {
25805           error ("ms_abi and sysv_abi attributes are not compatible");
25806         }
25807
25808       return NULL_TREE;
25809     }
25810
25811   return NULL_TREE;
25812 }
25813
25814 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
25815    struct attribute_spec.handler.  */
25816 static tree
25817 ix86_handle_struct_attribute (tree *node, tree name,
25818                               tree args ATTRIBUTE_UNUSED,
25819                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
25820 {
25821   tree *type = NULL;
25822   if (DECL_P (*node))
25823     {
25824       if (TREE_CODE (*node) == TYPE_DECL)
25825         type = &TREE_TYPE (*node);
25826     }
25827   else
25828     type = node;
25829
25830   if (!(type && (TREE_CODE (*type) == RECORD_TYPE
25831                  || TREE_CODE (*type) == UNION_TYPE)))
25832     {
25833       warning (OPT_Wattributes, "%qs attribute ignored",
25834                IDENTIFIER_POINTER (name));
25835       *no_add_attrs = true;
25836     }
25837
25838   else if ((is_attribute_p ("ms_struct", name)
25839             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
25840            || ((is_attribute_p ("gcc_struct", name)
25841                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
25842     {
25843       warning (OPT_Wattributes, "%qs incompatible attribute ignored",
25844                IDENTIFIER_POINTER (name));
25845       *no_add_attrs = true;
25846     }
25847
25848   return NULL_TREE;
25849 }
25850
25851 static bool
25852 ix86_ms_bitfield_layout_p (const_tree record_type)
25853 {
25854   return (TARGET_MS_BITFIELD_LAYOUT &&
25855           !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
25856     || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
25857 }
25858
25859 /* Returns an expression indicating where the this parameter is
25860    located on entry to the FUNCTION.  */
25861
25862 static rtx
25863 x86_this_parameter (tree function)
25864 {
25865   tree type = TREE_TYPE (function);
25866   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
25867   int nregs;
25868
25869   if (TARGET_64BIT)
25870     {
25871       const int *parm_regs;
25872
25873       if (ix86_function_type_abi (type) == MS_ABI)
25874         parm_regs = x86_64_ms_abi_int_parameter_registers;
25875       else
25876         parm_regs = x86_64_int_parameter_registers;
25877       return gen_rtx_REG (DImode, parm_regs[aggr]);
25878     }
25879
25880   nregs = ix86_function_regparm (type, function);
25881
25882   if (nregs > 0 && !stdarg_p (type))
25883     {
25884       int regno;
25885
25886       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
25887         regno = aggr ? DX_REG : CX_REG;
25888       else
25889         {
25890           regno = AX_REG;
25891           if (aggr)
25892             {
25893               regno = DX_REG;
25894               if (nregs == 1)
25895                 return gen_rtx_MEM (SImode,
25896                                     plus_constant (stack_pointer_rtx, 4));
25897             }
25898         }
25899       return gen_rtx_REG (SImode, regno);
25900     }
25901
25902   return gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx, aggr ? 8 : 4));
25903 }
25904
25905 /* Determine whether x86_output_mi_thunk can succeed.  */
25906
25907 static bool
25908 x86_can_output_mi_thunk (const_tree thunk ATTRIBUTE_UNUSED,
25909                          HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
25910                          HOST_WIDE_INT vcall_offset, const_tree function)
25911 {
25912   /* 64-bit can handle anything.  */
25913   if (TARGET_64BIT)
25914     return true;
25915
25916   /* For 32-bit, everything's fine if we have one free register.  */
25917   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
25918     return true;
25919
25920   /* Need a free register for vcall_offset.  */
25921   if (vcall_offset)
25922     return false;
25923
25924   /* Need a free register for GOT references.  */
25925   if (flag_pic && !(*targetm.binds_local_p) (function))
25926     return false;
25927
25928   /* Otherwise ok.  */
25929   return true;
25930 }
25931
25932 /* Output the assembler code for a thunk function.  THUNK_DECL is the
25933    declaration for the thunk function itself, FUNCTION is the decl for
25934    the target function.  DELTA is an immediate constant offset to be
25935    added to THIS.  If VCALL_OFFSET is nonzero, the word at
25936    *(*this + vcall_offset) should be added to THIS.  */
25937
25938 static void
25939 x86_output_mi_thunk (FILE *file ATTRIBUTE_UNUSED,
25940                      tree thunk ATTRIBUTE_UNUSED, HOST_WIDE_INT delta,
25941                      HOST_WIDE_INT vcall_offset, tree function)
25942 {
25943   rtx xops[3];
25944   rtx this_param = x86_this_parameter (function);
25945   rtx this_reg, tmp;
25946
25947   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
25948      pull it in now and let DELTA benefit.  */
25949   if (REG_P (this_param))
25950     this_reg = this_param;
25951   else if (vcall_offset)
25952     {
25953       /* Put the this parameter into %eax.  */
25954       xops[0] = this_param;
25955       xops[1] = this_reg = gen_rtx_REG (Pmode, AX_REG);
25956       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
25957     }
25958   else
25959     this_reg = NULL_RTX;
25960
25961   /* Adjust the this parameter by a fixed constant.  */
25962   if (delta)
25963     {
25964       xops[0] = GEN_INT (delta);
25965       xops[1] = this_reg ? this_reg : this_param;
25966       if (TARGET_64BIT)
25967         {
25968           if (!x86_64_general_operand (xops[0], DImode))
25969             {
25970               tmp = gen_rtx_REG (DImode, R10_REG);
25971               xops[1] = tmp;
25972               output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", xops);
25973               xops[0] = tmp;
25974               xops[1] = this_param;
25975             }
25976           output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
25977         }
25978       else
25979         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
25980     }
25981
25982   /* Adjust the this parameter by a value stored in the vtable.  */
25983   if (vcall_offset)
25984     {
25985       if (TARGET_64BIT)
25986         tmp = gen_rtx_REG (DImode, R10_REG);
25987       else
25988         {
25989           int tmp_regno = CX_REG;
25990           if (lookup_attribute ("fastcall",
25991                                 TYPE_ATTRIBUTES (TREE_TYPE (function))))
25992             tmp_regno = AX_REG;
25993           tmp = gen_rtx_REG (SImode, tmp_regno);
25994         }
25995
25996       xops[0] = gen_rtx_MEM (Pmode, this_reg);
25997       xops[1] = tmp;
25998       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
25999
26000       /* Adjust the this parameter.  */
26001       xops[0] = gen_rtx_MEM (Pmode, plus_constant (tmp, vcall_offset));
26002       if (TARGET_64BIT && !memory_operand (xops[0], Pmode))
26003         {
26004           rtx tmp2 = gen_rtx_REG (DImode, R11_REG);
26005           xops[0] = GEN_INT (vcall_offset);
26006           xops[1] = tmp2;
26007           output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
26008           xops[0] = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, tmp, tmp2));
26009         }
26010       xops[1] = this_reg;
26011       output_asm_insn ("add%z1\t{%0, %1|%1, %0}", xops);
26012     }
26013
26014   /* If necessary, drop THIS back to its stack slot.  */
26015   if (this_reg && this_reg != this_param)
26016     {
26017       xops[0] = this_reg;
26018       xops[1] = this_param;
26019       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26020     }
26021
26022   xops[0] = XEXP (DECL_RTL (function), 0);
26023   if (TARGET_64BIT)
26024     {
26025       if (!flag_pic || (*targetm.binds_local_p) (function))
26026         output_asm_insn ("jmp\t%P0", xops);
26027       /* All thunks should be in the same object as their target,
26028          and thus binds_local_p should be true.  */
26029       else if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
26030         gcc_unreachable ();
26031       else
26032         {
26033           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xops[0]), UNSPEC_GOTPCREL);
26034           tmp = gen_rtx_CONST (Pmode, tmp);
26035           tmp = gen_rtx_MEM (QImode, tmp);
26036           xops[0] = tmp;
26037           output_asm_insn ("jmp\t%A0", xops);
26038         }
26039     }
26040   else
26041     {
26042       if (!flag_pic || (*targetm.binds_local_p) (function))
26043         output_asm_insn ("jmp\t%P0", xops);
26044       else
26045 #if TARGET_MACHO
26046         if (TARGET_MACHO)
26047           {
26048             rtx sym_ref = XEXP (DECL_RTL (function), 0);
26049             tmp = (gen_rtx_SYMBOL_REF
26050                    (Pmode,
26051                     machopic_indirection_name (sym_ref, /*stub_p=*/true)));
26052             tmp = gen_rtx_MEM (QImode, tmp);
26053             xops[0] = tmp;
26054             output_asm_insn ("jmp\t%0", xops);
26055           }
26056         else
26057 #endif /* TARGET_MACHO */
26058         {
26059           tmp = gen_rtx_REG (SImode, CX_REG);
26060           output_set_got (tmp, NULL_RTX);
26061
26062           xops[1] = tmp;
26063           output_asm_insn ("mov{l}\t{%0@GOT(%1), %1|%1, %0@GOT[%1]}", xops);
26064           output_asm_insn ("jmp\t{*}%1", xops);
26065         }
26066     }
26067 }
26068
26069 static void
26070 x86_file_start (void)
26071 {
26072   default_file_start ();
26073 #if TARGET_MACHO
26074   darwin_file_start ();
26075 #endif
26076   if (X86_FILE_START_VERSION_DIRECTIVE)
26077     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
26078   if (X86_FILE_START_FLTUSED)
26079     fputs ("\t.global\t__fltused\n", asm_out_file);
26080   if (ix86_asm_dialect == ASM_INTEL)
26081     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
26082 }
26083
26084 int
26085 x86_field_alignment (tree field, int computed)
26086 {
26087   enum machine_mode mode;
26088   tree type = TREE_TYPE (field);
26089
26090   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
26091     return computed;
26092   mode = TYPE_MODE (strip_array_types (type));
26093   if (mode == DFmode || mode == DCmode
26094       || GET_MODE_CLASS (mode) == MODE_INT
26095       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
26096     return MIN (32, computed);
26097   return computed;
26098 }
26099
26100 /* Output assembler code to FILE to increment profiler label # LABELNO
26101    for profiling a function entry.  */
26102 void
26103 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
26104 {
26105   if (TARGET_64BIT)
26106     {
26107 #ifndef NO_PROFILE_COUNTERS
26108       fprintf (file, "\tleaq\t%sP%d@(%%rip),%%r11\n", LPREFIX, labelno);
26109 #endif
26110
26111       if (DEFAULT_ABI == SYSV_ABI && flag_pic)
26112         fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", MCOUNT_NAME);
26113       else
26114         fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26115     }
26116   else if (flag_pic)
26117     {
26118 #ifndef NO_PROFILE_COUNTERS
26119       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%%s\n",
26120                LPREFIX, labelno, PROFILE_COUNT_REGISTER);
26121 #endif
26122       fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", MCOUNT_NAME);
26123     }
26124   else
26125     {
26126 #ifndef NO_PROFILE_COUNTERS
26127       fprintf (file, "\tmovl\t$%sP%d,%%%s\n", LPREFIX, labelno,
26128                PROFILE_COUNT_REGISTER);
26129 #endif
26130       fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26131     }
26132 }
26133
26134 /* We don't have exact information about the insn sizes, but we may assume
26135    quite safely that we are informed about all 1 byte insns and memory
26136    address sizes.  This is enough to eliminate unnecessary padding in
26137    99% of cases.  */
26138
26139 static int
26140 min_insn_size (rtx insn)
26141 {
26142   int l = 0;
26143
26144   if (!INSN_P (insn) || !active_insn_p (insn))
26145     return 0;
26146
26147   /* Discard alignments we've emit and jump instructions.  */
26148   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
26149       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
26150     return 0;
26151   if (JUMP_P (insn)
26152       && (GET_CODE (PATTERN (insn)) == ADDR_VEC
26153           || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
26154     return 0;
26155
26156   /* Important case - calls are always 5 bytes.
26157      It is common to have many calls in the row.  */
26158   if (CALL_P (insn)
26159       && symbolic_reference_mentioned_p (PATTERN (insn))
26160       && !SIBLING_CALL_P (insn))
26161     return 5;
26162   if (get_attr_length (insn) <= 1)
26163     return 1;
26164
26165   /* For normal instructions we may rely on the sizes of addresses
26166      and the presence of symbol to require 4 bytes of encoding.
26167      This is not the case for jumps where references are PC relative.  */
26168   if (!JUMP_P (insn))
26169     {
26170       l = get_attr_length_address (insn);
26171       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
26172         l = 4;
26173     }
26174   if (l)
26175     return 1+l;
26176   else
26177     return 2;
26178 }
26179
26180 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
26181    window.  */
26182
26183 static void
26184 ix86_avoid_jump_misspredicts (void)
26185 {
26186   rtx insn, start = get_insns ();
26187   int nbytes = 0, njumps = 0;
26188   int isjump = 0;
26189
26190   /* Look for all minimal intervals of instructions containing 4 jumps.
26191      The intervals are bounded by START and INSN.  NBYTES is the total
26192      size of instructions in the interval including INSN and not including
26193      START.  When the NBYTES is smaller than 16 bytes, it is possible
26194      that the end of START and INSN ends up in the same 16byte page.
26195
26196      The smallest offset in the page INSN can start is the case where START
26197      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
26198      We add p2align to 16byte window with maxskip 17 - NBYTES + sizeof (INSN).
26199      */
26200   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
26201     {
26202
26203       nbytes += min_insn_size (insn);
26204       if (dump_file)
26205         fprintf(dump_file, "Insn %i estimated to %i bytes\n",
26206                 INSN_UID (insn), min_insn_size (insn));
26207       if ((JUMP_P (insn)
26208            && GET_CODE (PATTERN (insn)) != ADDR_VEC
26209            && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
26210           || CALL_P (insn))
26211         njumps++;
26212       else
26213         continue;
26214
26215       while (njumps > 3)
26216         {
26217           start = NEXT_INSN (start);
26218           if ((JUMP_P (start)
26219                && GET_CODE (PATTERN (start)) != ADDR_VEC
26220                && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
26221               || CALL_P (start))
26222             njumps--, isjump = 1;
26223           else
26224             isjump = 0;
26225           nbytes -= min_insn_size (start);
26226         }
26227       gcc_assert (njumps >= 0);
26228       if (dump_file)
26229         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
26230                 INSN_UID (start), INSN_UID (insn), nbytes);
26231
26232       if (njumps == 3 && isjump && nbytes < 16)
26233         {
26234           int padsize = 15 - nbytes + min_insn_size (insn);
26235
26236           if (dump_file)
26237             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
26238                      INSN_UID (insn), padsize);
26239           emit_insn_before (gen_align (GEN_INT (padsize)), insn);
26240         }
26241     }
26242 }
26243
26244 /* AMD Athlon works faster
26245    when RET is not destination of conditional jump or directly preceded
26246    by other jump instruction.  We avoid the penalty by inserting NOP just
26247    before the RET instructions in such cases.  */
26248 static void
26249 ix86_pad_returns (void)
26250 {
26251   edge e;
26252   edge_iterator ei;
26253
26254   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
26255     {
26256       basic_block bb = e->src;
26257       rtx ret = BB_END (bb);
26258       rtx prev;
26259       bool replace = false;
26260
26261       if (!JUMP_P (ret) || GET_CODE (PATTERN (ret)) != RETURN
26262           || optimize_bb_for_size_p (bb))
26263         continue;
26264       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
26265         if (active_insn_p (prev) || LABEL_P (prev))
26266           break;
26267       if (prev && LABEL_P (prev))
26268         {
26269           edge e;
26270           edge_iterator ei;
26271
26272           FOR_EACH_EDGE (e, ei, bb->preds)
26273             if (EDGE_FREQUENCY (e) && e->src->index >= 0
26274                 && !(e->flags & EDGE_FALLTHRU))
26275               replace = true;
26276         }
26277       if (!replace)
26278         {
26279           prev = prev_active_insn (ret);
26280           if (prev
26281               && ((JUMP_P (prev) && any_condjump_p (prev))
26282                   || CALL_P (prev)))
26283             replace = true;
26284           /* Empty functions get branch mispredict even when the jump destination
26285              is not visible to us.  */
26286           if (!prev && cfun->function_frequency > FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
26287             replace = true;
26288         }
26289       if (replace)
26290         {
26291           emit_insn_before (gen_return_internal_long (), ret);
26292           delete_insn (ret);
26293         }
26294     }
26295 }
26296
26297 /* Implement machine specific optimizations.  We implement padding of returns
26298    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
26299 static void
26300 ix86_reorg (void)
26301 {
26302   if (TARGET_PAD_RETURNS && optimize
26303       && optimize_function_for_speed_p (cfun))
26304     ix86_pad_returns ();
26305   if (TARGET_FOUR_JUMP_LIMIT && optimize
26306       && optimize_function_for_speed_p (cfun))
26307     ix86_avoid_jump_misspredicts ();
26308 }
26309
26310 /* Return nonzero when QImode register that must be represented via REX prefix
26311    is used.  */
26312 bool
26313 x86_extended_QIreg_mentioned_p (rtx insn)
26314 {
26315   int i;
26316   extract_insn_cached (insn);
26317   for (i = 0; i < recog_data.n_operands; i++)
26318     if (REG_P (recog_data.operand[i])
26319         && REGNO (recog_data.operand[i]) >= 4)
26320        return true;
26321   return false;
26322 }
26323
26324 /* Return nonzero when P points to register encoded via REX prefix.
26325    Called via for_each_rtx.  */
26326 static int
26327 extended_reg_mentioned_1 (rtx *p, void *data ATTRIBUTE_UNUSED)
26328 {
26329    unsigned int regno;
26330    if (!REG_P (*p))
26331      return 0;
26332    regno = REGNO (*p);
26333    return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
26334 }
26335
26336 /* Return true when INSN mentions register that must be encoded using REX
26337    prefix.  */
26338 bool
26339 x86_extended_reg_mentioned_p (rtx insn)
26340 {
26341   return for_each_rtx (INSN_P (insn) ? &PATTERN (insn) : &insn,
26342                        extended_reg_mentioned_1, NULL);
26343 }
26344
26345 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
26346    optabs would emit if we didn't have TFmode patterns.  */
26347
26348 void
26349 x86_emit_floatuns (rtx operands[2])
26350 {
26351   rtx neglab, donelab, i0, i1, f0, in, out;
26352   enum machine_mode mode, inmode;
26353
26354   inmode = GET_MODE (operands[1]);
26355   gcc_assert (inmode == SImode || inmode == DImode);
26356
26357   out = operands[0];
26358   in = force_reg (inmode, operands[1]);
26359   mode = GET_MODE (out);
26360   neglab = gen_label_rtx ();
26361   donelab = gen_label_rtx ();
26362   f0 = gen_reg_rtx (mode);
26363
26364   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
26365
26366   expand_float (out, in, 0);
26367
26368   emit_jump_insn (gen_jump (donelab));
26369   emit_barrier ();
26370
26371   emit_label (neglab);
26372
26373   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
26374                             1, OPTAB_DIRECT);
26375   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
26376                             1, OPTAB_DIRECT);
26377   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
26378
26379   expand_float (f0, i0, 0);
26380
26381   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
26382
26383   emit_label (donelab);
26384 }
26385 \f
26386 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26387    with all elements equal to VAR.  Return true if successful.  */
26388
26389 static bool
26390 ix86_expand_vector_init_duplicate (bool mmx_ok, enum machine_mode mode,
26391                                    rtx target, rtx val)
26392 {
26393   enum machine_mode hmode, smode, wsmode, wvmode;
26394   rtx x;
26395
26396   switch (mode)
26397     {
26398     case V2SImode:
26399     case V2SFmode:
26400       if (!mmx_ok)
26401         return false;
26402       /* FALLTHRU */
26403
26404     case V2DFmode:
26405     case V2DImode:
26406     case V4SFmode:
26407     case V4SImode:
26408       val = force_reg (GET_MODE_INNER (mode), val);
26409       x = gen_rtx_VEC_DUPLICATE (mode, val);
26410       emit_insn (gen_rtx_SET (VOIDmode, target, x));
26411       return true;
26412
26413     case V4HImode:
26414       if (!mmx_ok)
26415         return false;
26416       if (TARGET_SSE || TARGET_3DNOW_A)
26417         {
26418           val = gen_lowpart (SImode, val);
26419           x = gen_rtx_TRUNCATE (HImode, val);
26420           x = gen_rtx_VEC_DUPLICATE (mode, x);
26421           emit_insn (gen_rtx_SET (VOIDmode, target, x));
26422           return true;
26423         }
26424       else
26425         {
26426           smode = HImode;
26427           wsmode = SImode;
26428           wvmode = V2SImode;
26429           goto widen;
26430         }
26431
26432     case V8QImode:
26433       if (!mmx_ok)
26434         return false;
26435       smode = QImode;
26436       wsmode = HImode;
26437       wvmode = V4HImode;
26438       goto widen;
26439     case V8HImode:
26440       if (TARGET_SSE2)
26441         {
26442           rtx tmp1, tmp2;
26443           /* Extend HImode to SImode using a paradoxical SUBREG.  */
26444           tmp1 = gen_reg_rtx (SImode);
26445           emit_move_insn (tmp1, gen_lowpart (SImode, val));
26446           /* Insert the SImode value as low element of V4SImode vector. */
26447           tmp2 = gen_reg_rtx (V4SImode);
26448           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
26449                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
26450                                     CONST0_RTX (V4SImode),
26451                                     const1_rtx);
26452           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
26453           /* Cast the V4SImode vector back to a V8HImode vector.  */
26454           tmp1 = gen_reg_rtx (V8HImode);
26455           emit_move_insn (tmp1, gen_lowpart (V8HImode, tmp2));
26456           /* Duplicate the low short through the whole low SImode word.  */
26457           emit_insn (gen_sse2_punpcklwd (tmp1, tmp1, tmp1));
26458           /* Cast the V8HImode vector back to a V4SImode vector.  */
26459           tmp2 = gen_reg_rtx (V4SImode);
26460           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
26461           /* Replicate the low element of the V4SImode vector.  */
26462           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
26463           /* Cast the V2SImode back to V8HImode, and store in target.  */
26464           emit_move_insn (target, gen_lowpart (V8HImode, tmp2));
26465           return true;
26466         }
26467       smode = HImode;
26468       wsmode = SImode;
26469       wvmode = V4SImode;
26470       goto widen;
26471     case V16QImode:
26472       if (TARGET_SSE2)
26473         {
26474           rtx tmp1, tmp2;
26475           /* Extend QImode to SImode using a paradoxical SUBREG.  */
26476           tmp1 = gen_reg_rtx (SImode);
26477           emit_move_insn (tmp1, gen_lowpart (SImode, val));
26478           /* Insert the SImode value as low element of V4SImode vector. */
26479           tmp2 = gen_reg_rtx (V4SImode);
26480           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
26481                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
26482                                     CONST0_RTX (V4SImode),
26483                                     const1_rtx);
26484           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
26485           /* Cast the V4SImode vector back to a V16QImode vector.  */
26486           tmp1 = gen_reg_rtx (V16QImode);
26487           emit_move_insn (tmp1, gen_lowpart (V16QImode, tmp2));
26488           /* Duplicate the low byte through the whole low SImode word.  */
26489           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
26490           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
26491           /* Cast the V16QImode vector back to a V4SImode vector.  */
26492           tmp2 = gen_reg_rtx (V4SImode);
26493           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
26494           /* Replicate the low element of the V4SImode vector.  */
26495           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
26496           /* Cast the V2SImode back to V16QImode, and store in target.  */
26497           emit_move_insn (target, gen_lowpart (V16QImode, tmp2));
26498           return true;
26499         }
26500       smode = QImode;
26501       wsmode = HImode;
26502       wvmode = V8HImode;
26503       goto widen;
26504     widen:
26505       /* Replicate the value once into the next wider mode and recurse.  */
26506       val = convert_modes (wsmode, smode, val, true);
26507       x = expand_simple_binop (wsmode, ASHIFT, val,
26508                                GEN_INT (GET_MODE_BITSIZE (smode)),
26509                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
26510       val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
26511
26512       x = gen_reg_rtx (wvmode);
26513       if (!ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val))
26514         gcc_unreachable ();
26515       emit_move_insn (target, gen_lowpart (mode, x));
26516       return true;
26517
26518     case V4DFmode:
26519       hmode = V2DFmode;
26520       goto half;
26521     case V4DImode:
26522       hmode = V2DImode;
26523       goto half;
26524     case V8SFmode:
26525       hmode = V4SFmode;
26526       goto half;
26527     case V8SImode:
26528       hmode = V4SImode;
26529       goto half;
26530     case V16HImode:
26531       hmode = V8HImode;
26532       goto half;
26533     case V32QImode:
26534       hmode = V16QImode;
26535       goto half;
26536 half:
26537       {
26538         rtx tmp = gen_reg_rtx (hmode);
26539         ix86_expand_vector_init_duplicate (mmx_ok, hmode, tmp, val);
26540         emit_insn (gen_rtx_SET (VOIDmode, target,
26541                                 gen_rtx_VEC_CONCAT (mode, tmp, tmp)));
26542       }
26543       return true;
26544
26545     default:
26546       return false;
26547     }
26548 }
26549
26550 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26551    whose ONE_VAR element is VAR, and other elements are zero.  Return true
26552    if successful.  */
26553
26554 static bool
26555 ix86_expand_vector_init_one_nonzero (bool mmx_ok, enum machine_mode mode,
26556                                      rtx target, rtx var, int one_var)
26557 {
26558   enum machine_mode vsimode;
26559   rtx new_target;
26560   rtx x, tmp;
26561   bool use_vector_set = false;
26562
26563   switch (mode)
26564     {
26565     case V2DImode:
26566       /* For SSE4.1, we normally use vector set.  But if the second
26567          element is zero and inter-unit moves are OK, we use movq
26568          instead.  */
26569       use_vector_set = (TARGET_64BIT
26570                         && TARGET_SSE4_1
26571                         && !(TARGET_INTER_UNIT_MOVES
26572                              && one_var == 0));
26573       break;
26574     case V16QImode:
26575     case V4SImode:
26576     case V4SFmode:
26577       use_vector_set = TARGET_SSE4_1;
26578       break;
26579     case V8HImode:
26580       use_vector_set = TARGET_SSE2;
26581       break;
26582     case V4HImode:
26583       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
26584       break;
26585     case V32QImode:
26586     case V16HImode:
26587     case V8SImode:
26588     case V8SFmode:
26589     case V4DImode:
26590     case V4DFmode:
26591       use_vector_set = TARGET_AVX;
26592       break;
26593     default:
26594       break;
26595     }
26596
26597   if (use_vector_set)
26598     {
26599       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
26600       var = force_reg (GET_MODE_INNER (mode), var);
26601       ix86_expand_vector_set (mmx_ok, target, var, one_var);
26602       return true; 
26603     }
26604
26605   switch (mode)
26606     {
26607     case V2SFmode:
26608     case V2SImode:
26609       if (!mmx_ok)
26610         return false;
26611       /* FALLTHRU */
26612
26613     case V2DFmode:
26614     case V2DImode:
26615       if (one_var != 0)
26616         return false;
26617       var = force_reg (GET_MODE_INNER (mode), var);
26618       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
26619       emit_insn (gen_rtx_SET (VOIDmode, target, x));
26620       return true;
26621
26622     case V4SFmode:
26623     case V4SImode:
26624       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
26625         new_target = gen_reg_rtx (mode);
26626       else
26627         new_target = target;
26628       var = force_reg (GET_MODE_INNER (mode), var);
26629       x = gen_rtx_VEC_DUPLICATE (mode, var);
26630       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
26631       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
26632       if (one_var != 0)
26633         {
26634           /* We need to shuffle the value to the correct position, so
26635              create a new pseudo to store the intermediate result.  */
26636
26637           /* With SSE2, we can use the integer shuffle insns.  */
26638           if (mode != V4SFmode && TARGET_SSE2)
26639             {
26640               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
26641                                             GEN_INT (1),
26642                                             GEN_INT (one_var == 1 ? 0 : 1),
26643                                             GEN_INT (one_var == 2 ? 0 : 1),
26644                                             GEN_INT (one_var == 3 ? 0 : 1)));
26645               if (target != new_target)
26646                 emit_move_insn (target, new_target);
26647               return true;
26648             }
26649
26650           /* Otherwise convert the intermediate result to V4SFmode and
26651              use the SSE1 shuffle instructions.  */
26652           if (mode != V4SFmode)
26653             {
26654               tmp = gen_reg_rtx (V4SFmode);
26655               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
26656             }
26657           else
26658             tmp = new_target;
26659
26660           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
26661                                        GEN_INT (1),
26662                                        GEN_INT (one_var == 1 ? 0 : 1),
26663                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
26664                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
26665
26666           if (mode != V4SFmode)
26667             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
26668           else if (tmp != target)
26669             emit_move_insn (target, tmp);
26670         }
26671       else if (target != new_target)
26672         emit_move_insn (target, new_target);
26673       return true;
26674
26675     case V8HImode:
26676     case V16QImode:
26677       vsimode = V4SImode;
26678       goto widen;
26679     case V4HImode:
26680     case V8QImode:
26681       if (!mmx_ok)
26682         return false;
26683       vsimode = V2SImode;
26684       goto widen;
26685     widen:
26686       if (one_var != 0)
26687         return false;
26688
26689       /* Zero extend the variable element to SImode and recurse.  */
26690       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
26691
26692       x = gen_reg_rtx (vsimode);
26693       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
26694                                                 var, one_var))
26695         gcc_unreachable ();
26696
26697       emit_move_insn (target, gen_lowpart (mode, x));
26698       return true;
26699
26700     default:
26701       return false;
26702     }
26703 }
26704
26705 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26706    consisting of the values in VALS.  It is known that all elements
26707    except ONE_VAR are constants.  Return true if successful.  */
26708
26709 static bool
26710 ix86_expand_vector_init_one_var (bool mmx_ok, enum machine_mode mode,
26711                                  rtx target, rtx vals, int one_var)
26712 {
26713   rtx var = XVECEXP (vals, 0, one_var);
26714   enum machine_mode wmode;
26715   rtx const_vec, x;
26716
26717   const_vec = copy_rtx (vals);
26718   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
26719   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
26720
26721   switch (mode)
26722     {
26723     case V2DFmode:
26724     case V2DImode:
26725     case V2SFmode:
26726     case V2SImode:
26727       /* For the two element vectors, it's just as easy to use
26728          the general case.  */
26729       return false;
26730
26731     case V4DFmode:
26732     case V4DImode:
26733     case V8SFmode:
26734     case V8SImode:
26735     case V16HImode:
26736     case V32QImode:
26737     case V4SFmode:
26738     case V4SImode:
26739     case V8HImode:
26740     case V4HImode:
26741       break;
26742
26743     case V16QImode:
26744       if (TARGET_SSE4_1)
26745         break;
26746       wmode = V8HImode;
26747       goto widen;
26748     case V8QImode:
26749       wmode = V4HImode;
26750       goto widen;
26751     widen:
26752       /* There's no way to set one QImode entry easily.  Combine
26753          the variable value with its adjacent constant value, and
26754          promote to an HImode set.  */
26755       x = XVECEXP (vals, 0, one_var ^ 1);
26756       if (one_var & 1)
26757         {
26758           var = convert_modes (HImode, QImode, var, true);
26759           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
26760                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
26761           x = GEN_INT (INTVAL (x) & 0xff);
26762         }
26763       else
26764         {
26765           var = convert_modes (HImode, QImode, var, true);
26766           x = gen_int_mode (INTVAL (x) << 8, HImode);
26767         }
26768       if (x != const0_rtx)
26769         var = expand_simple_binop (HImode, IOR, var, x, var,
26770                                    1, OPTAB_LIB_WIDEN);
26771
26772       x = gen_reg_rtx (wmode);
26773       emit_move_insn (x, gen_lowpart (wmode, const_vec));
26774       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
26775
26776       emit_move_insn (target, gen_lowpart (mode, x));
26777       return true;
26778
26779     default:
26780       return false;
26781     }
26782
26783   emit_move_insn (target, const_vec);
26784   ix86_expand_vector_set (mmx_ok, target, var, one_var);
26785   return true;
26786 }
26787
26788 /* A subroutine of ix86_expand_vector_init_general.  Use vector
26789    concatenate to handle the most general case: all values variable,
26790    and none identical.  */
26791
26792 static void
26793 ix86_expand_vector_init_concat (enum machine_mode mode,
26794                                 rtx target, rtx *ops, int n)
26795 {
26796   enum machine_mode cmode, hmode = VOIDmode;
26797   rtx first[8], second[4];
26798   rtvec v;
26799   int i, j;
26800
26801   switch (n)
26802     {
26803     case 2:
26804       switch (mode)
26805         {
26806         case V8SImode:
26807           cmode = V4SImode;
26808           break;
26809         case V8SFmode:
26810           cmode = V4SFmode;
26811           break;
26812         case V4DImode:
26813           cmode = V2DImode;
26814           break;
26815         case V4DFmode:
26816           cmode = V2DFmode;
26817           break;
26818         case V4SImode:
26819           cmode = V2SImode;
26820           break;
26821         case V4SFmode:
26822           cmode = V2SFmode;
26823           break;
26824         case V2DImode:
26825           cmode = DImode;
26826           break;
26827         case V2SImode:
26828           cmode = SImode;
26829           break;
26830         case V2DFmode:
26831           cmode = DFmode;
26832           break;
26833         case V2SFmode:
26834           cmode = SFmode;
26835           break;
26836         default:
26837           gcc_unreachable ();
26838         }
26839
26840       if (!register_operand (ops[1], cmode))
26841         ops[1] = force_reg (cmode, ops[1]);
26842       if (!register_operand (ops[0], cmode))
26843         ops[0] = force_reg (cmode, ops[0]);
26844       emit_insn (gen_rtx_SET (VOIDmode, target,
26845                               gen_rtx_VEC_CONCAT (mode, ops[0],
26846                                                   ops[1])));
26847       break;
26848
26849     case 4:
26850       switch (mode)
26851         {
26852         case V4DImode:
26853           cmode = V2DImode;
26854           break;
26855         case V4DFmode:
26856           cmode = V2DFmode;
26857           break;
26858         case V4SImode:
26859           cmode = V2SImode;
26860           break;
26861         case V4SFmode:
26862           cmode = V2SFmode;
26863           break;
26864         default:
26865           gcc_unreachable ();
26866         }
26867       goto half;
26868
26869     case 8:
26870       switch (mode)
26871         {
26872         case V8SImode:
26873           cmode = V2SImode;
26874           hmode = V4SImode;
26875           break;
26876         case V8SFmode:
26877           cmode = V2SFmode;
26878           hmode = V4SFmode;
26879           break;
26880         default:
26881           gcc_unreachable ();
26882         }
26883       goto half;
26884
26885 half:
26886       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
26887       i = n - 1;
26888       j = (n >> 1) - 1;
26889       for (; i > 0; i -= 2, j--)
26890         {
26891           first[j] = gen_reg_rtx (cmode);
26892           v = gen_rtvec (2, ops[i - 1], ops[i]);
26893           ix86_expand_vector_init (false, first[j],
26894                                    gen_rtx_PARALLEL (cmode, v));
26895         }
26896
26897       n >>= 1;
26898       if (n > 2)
26899         {
26900           gcc_assert (hmode != VOIDmode);
26901           for (i = j = 0; i < n; i += 2, j++)
26902             {
26903               second[j] = gen_reg_rtx (hmode);
26904               ix86_expand_vector_init_concat (hmode, second [j],
26905                                               &first [i], 2);
26906             }
26907           n >>= 1;
26908           ix86_expand_vector_init_concat (mode, target, second, n);
26909         }
26910       else
26911         ix86_expand_vector_init_concat (mode, target, first, n);
26912       break;
26913
26914     default:
26915       gcc_unreachable ();
26916     }
26917 }
26918
26919 /* A subroutine of ix86_expand_vector_init_general.  Use vector
26920    interleave to handle the most general case: all values variable,
26921    and none identical.  */
26922
26923 static void
26924 ix86_expand_vector_init_interleave (enum machine_mode mode,
26925                                     rtx target, rtx *ops, int n)
26926 {
26927   enum machine_mode first_imode, second_imode, third_imode, inner_mode;
26928   int i, j;
26929   rtx op0, op1;
26930   rtx (*gen_load_even) (rtx, rtx, rtx);
26931   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
26932   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
26933   
26934   switch (mode)
26935     {
26936     case V8HImode:
26937       gen_load_even = gen_vec_setv8hi;
26938       gen_interleave_first_low = gen_vec_interleave_lowv4si;
26939       gen_interleave_second_low = gen_vec_interleave_lowv2di;
26940       inner_mode = HImode;
26941       first_imode = V4SImode;
26942       second_imode = V2DImode;
26943       third_imode = VOIDmode;
26944       break;
26945     case V16QImode:
26946       gen_load_even = gen_vec_setv16qi;
26947       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
26948       gen_interleave_second_low = gen_vec_interleave_lowv4si;
26949       inner_mode = QImode;
26950       first_imode = V8HImode;
26951       second_imode = V4SImode;
26952       third_imode = V2DImode;
26953       break;
26954     default:
26955       gcc_unreachable ();
26956     }
26957      
26958   for (i = 0; i < n; i++)
26959     {
26960       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
26961       op0 = gen_reg_rtx (SImode);
26962       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
26963
26964       /* Insert the SImode value as low element of V4SImode vector. */
26965       op1 = gen_reg_rtx (V4SImode);
26966       op0 = gen_rtx_VEC_MERGE (V4SImode,
26967                                gen_rtx_VEC_DUPLICATE (V4SImode,
26968                                                       op0),
26969                                CONST0_RTX (V4SImode),
26970                                const1_rtx);
26971       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
26972
26973       /* Cast the V4SImode vector back to a vector in orignal mode.  */
26974       op0 = gen_reg_rtx (mode);
26975       emit_move_insn (op0, gen_lowpart (mode, op1));
26976       
26977       /* Load even elements into the second positon.  */
26978       emit_insn ((*gen_load_even) (op0,
26979                                    force_reg (inner_mode,
26980                                               ops [i + i + 1]),
26981                                    const1_rtx));
26982
26983       /* Cast vector to FIRST_IMODE vector.  */
26984       ops[i] = gen_reg_rtx (first_imode);
26985       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
26986     }
26987
26988   /* Interleave low FIRST_IMODE vectors.  */
26989   for (i = j = 0; i < n; i += 2, j++)
26990     {
26991       op0 = gen_reg_rtx (first_imode);
26992       emit_insn ((*gen_interleave_first_low) (op0, ops[i], ops[i + 1]));
26993
26994       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
26995       ops[j] = gen_reg_rtx (second_imode);
26996       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
26997     }
26998
26999   /* Interleave low SECOND_IMODE vectors.  */
27000   switch (second_imode)
27001     {
27002     case V4SImode:
27003       for (i = j = 0; i < n / 2; i += 2, j++)
27004         {
27005           op0 = gen_reg_rtx (second_imode);
27006           emit_insn ((*gen_interleave_second_low) (op0, ops[i],
27007                                                    ops[i + 1]));
27008
27009           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
27010              vector.  */
27011           ops[j] = gen_reg_rtx (third_imode);
27012           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
27013         }
27014       second_imode = V2DImode;
27015       gen_interleave_second_low = gen_vec_interleave_lowv2di;
27016       /* FALLTHRU */
27017
27018     case V2DImode:
27019       op0 = gen_reg_rtx (second_imode);
27020       emit_insn ((*gen_interleave_second_low) (op0, ops[0],
27021                                                ops[1]));
27022
27023       /* Cast the SECOND_IMODE vector back to a vector on original
27024          mode.  */
27025       emit_insn (gen_rtx_SET (VOIDmode, target,
27026                               gen_lowpart (mode, op0)));
27027       break;
27028
27029     default:
27030       gcc_unreachable ();
27031     }
27032 }
27033
27034 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
27035    all values variable, and none identical.  */
27036
27037 static void
27038 ix86_expand_vector_init_general (bool mmx_ok, enum machine_mode mode,
27039                                  rtx target, rtx vals)
27040 {
27041   rtx ops[32], op0, op1;
27042   enum machine_mode half_mode = VOIDmode;
27043   int n, i;
27044
27045   switch (mode)
27046     {
27047     case V2SFmode:
27048     case V2SImode:
27049       if (!mmx_ok && !TARGET_SSE)
27050         break;
27051       /* FALLTHRU */
27052
27053     case V8SFmode:
27054     case V8SImode:
27055     case V4DFmode:
27056     case V4DImode:
27057     case V4SFmode:
27058     case V4SImode:
27059     case V2DFmode:
27060     case V2DImode:
27061       n = GET_MODE_NUNITS (mode);
27062       for (i = 0; i < n; i++)
27063         ops[i] = XVECEXP (vals, 0, i);
27064       ix86_expand_vector_init_concat (mode, target, ops, n);
27065       return;
27066
27067     case V32QImode:
27068       half_mode = V16QImode;
27069       goto half;
27070
27071     case V16HImode:
27072       half_mode = V8HImode;
27073       goto half;
27074
27075 half:
27076       n = GET_MODE_NUNITS (mode);
27077       for (i = 0; i < n; i++)
27078         ops[i] = XVECEXP (vals, 0, i);
27079       op0 = gen_reg_rtx (half_mode);
27080       op1 = gen_reg_rtx (half_mode);
27081       ix86_expand_vector_init_interleave (half_mode, op0, ops,
27082                                           n >> 2);
27083       ix86_expand_vector_init_interleave (half_mode, op1,
27084                                           &ops [n >> 1], n >> 2);
27085       emit_insn (gen_rtx_SET (VOIDmode, target,
27086                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
27087       return;
27088
27089     case V16QImode:
27090       if (!TARGET_SSE4_1)
27091         break;
27092       /* FALLTHRU */
27093
27094     case V8HImode:
27095       if (!TARGET_SSE2)
27096         break;
27097
27098       /* Don't use ix86_expand_vector_init_interleave if we can't
27099          move from GPR to SSE register directly.  */ 
27100       if (!TARGET_INTER_UNIT_MOVES)
27101         break;
27102
27103       n = GET_MODE_NUNITS (mode);
27104       for (i = 0; i < n; i++)
27105         ops[i] = XVECEXP (vals, 0, i);
27106       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
27107       return;
27108
27109     case V4HImode:
27110     case V8QImode:
27111       break;
27112
27113     default:
27114       gcc_unreachable ();
27115     }
27116
27117     {
27118       int i, j, n_elts, n_words, n_elt_per_word;
27119       enum machine_mode inner_mode;
27120       rtx words[4], shift;
27121
27122       inner_mode = GET_MODE_INNER (mode);
27123       n_elts = GET_MODE_NUNITS (mode);
27124       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
27125       n_elt_per_word = n_elts / n_words;
27126       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
27127
27128       for (i = 0; i < n_words; ++i)
27129         {
27130           rtx word = NULL_RTX;
27131
27132           for (j = 0; j < n_elt_per_word; ++j)
27133             {
27134               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
27135               elt = convert_modes (word_mode, inner_mode, elt, true);
27136
27137               if (j == 0)
27138                 word = elt;
27139               else
27140                 {
27141                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
27142                                               word, 1, OPTAB_LIB_WIDEN);
27143                   word = expand_simple_binop (word_mode, IOR, word, elt,
27144                                               word, 1, OPTAB_LIB_WIDEN);
27145                 }
27146             }
27147
27148           words[i] = word;
27149         }
27150
27151       if (n_words == 1)
27152         emit_move_insn (target, gen_lowpart (mode, words[0]));
27153       else if (n_words == 2)
27154         {
27155           rtx tmp = gen_reg_rtx (mode);
27156           emit_clobber (tmp);
27157           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
27158           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
27159           emit_move_insn (target, tmp);
27160         }
27161       else if (n_words == 4)
27162         {
27163           rtx tmp = gen_reg_rtx (V4SImode);
27164           gcc_assert (word_mode == SImode);
27165           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
27166           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
27167           emit_move_insn (target, gen_lowpart (mode, tmp));
27168         }
27169       else
27170         gcc_unreachable ();
27171     }
27172 }
27173
27174 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
27175    instructions unless MMX_OK is true.  */
27176
27177 void
27178 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
27179 {
27180   enum machine_mode mode = GET_MODE (target);
27181   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27182   int n_elts = GET_MODE_NUNITS (mode);
27183   int n_var = 0, one_var = -1;
27184   bool all_same = true, all_const_zero = true;
27185   int i;
27186   rtx x;
27187
27188   for (i = 0; i < n_elts; ++i)
27189     {
27190       x = XVECEXP (vals, 0, i);
27191       if (!(CONST_INT_P (x)
27192             || GET_CODE (x) == CONST_DOUBLE
27193             || GET_CODE (x) == CONST_FIXED))
27194         n_var++, one_var = i;
27195       else if (x != CONST0_RTX (inner_mode))
27196         all_const_zero = false;
27197       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
27198         all_same = false;
27199     }
27200
27201   /* Constants are best loaded from the constant pool.  */
27202   if (n_var == 0)
27203     {
27204       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
27205       return;
27206     }
27207
27208   /* If all values are identical, broadcast the value.  */
27209   if (all_same
27210       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
27211                                             XVECEXP (vals, 0, 0)))
27212     return;
27213
27214   /* Values where only one field is non-constant are best loaded from
27215      the pool and overwritten via move later.  */
27216   if (n_var == 1)
27217     {
27218       if (all_const_zero
27219           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
27220                                                   XVECEXP (vals, 0, one_var),
27221                                                   one_var))
27222         return;
27223
27224       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
27225         return;
27226     }
27227
27228   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
27229 }
27230
27231 void
27232 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
27233 {
27234   enum machine_mode mode = GET_MODE (target);
27235   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27236   enum machine_mode half_mode;
27237   bool use_vec_merge = false;
27238   rtx tmp;
27239   static rtx (*gen_extract[6][2]) (rtx, rtx)
27240     = {
27241         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
27242         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
27243         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
27244         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
27245         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
27246         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
27247       };
27248   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
27249     = {
27250         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
27251         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
27252         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
27253         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
27254         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
27255         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
27256       };
27257   int i, j, n;
27258
27259   switch (mode)
27260     {
27261     case V2SFmode:
27262     case V2SImode:
27263       if (mmx_ok)
27264         {
27265           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
27266           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
27267           if (elt == 0)
27268             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
27269           else
27270             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
27271           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27272           return;
27273         }
27274       break;
27275
27276     case V2DImode:
27277       use_vec_merge = TARGET_SSE4_1;
27278       if (use_vec_merge)
27279         break;
27280
27281     case V2DFmode:
27282       {
27283         rtx op0, op1;
27284
27285         /* For the two element vectors, we implement a VEC_CONCAT with
27286            the extraction of the other element.  */
27287
27288         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
27289         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
27290
27291         if (elt == 0)
27292           op0 = val, op1 = tmp;
27293         else
27294           op0 = tmp, op1 = val;
27295
27296         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
27297         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27298       }
27299       return;
27300
27301     case V4SFmode:
27302       use_vec_merge = TARGET_SSE4_1;
27303       if (use_vec_merge)
27304         break;
27305
27306       switch (elt)
27307         {
27308         case 0:
27309           use_vec_merge = true;
27310           break;
27311
27312         case 1:
27313           /* tmp = target = A B C D */
27314           tmp = copy_to_reg (target);
27315           /* target = A A B B */
27316           emit_insn (gen_sse_unpcklps (target, target, target));
27317           /* target = X A B B */
27318           ix86_expand_vector_set (false, target, val, 0);
27319           /* target = A X C D  */
27320           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27321                                        GEN_INT (1), GEN_INT (0),
27322                                        GEN_INT (2+4), GEN_INT (3+4)));
27323           return;
27324
27325         case 2:
27326           /* tmp = target = A B C D */
27327           tmp = copy_to_reg (target);
27328           /* tmp = X B C D */
27329           ix86_expand_vector_set (false, tmp, val, 0);
27330           /* target = A B X D */
27331           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27332                                        GEN_INT (0), GEN_INT (1),
27333                                        GEN_INT (0+4), GEN_INT (3+4)));
27334           return;
27335
27336         case 3:
27337           /* tmp = target = A B C D */
27338           tmp = copy_to_reg (target);
27339           /* tmp = X B C D */
27340           ix86_expand_vector_set (false, tmp, val, 0);
27341           /* target = A B X D */
27342           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27343                                        GEN_INT (0), GEN_INT (1),
27344                                        GEN_INT (2+4), GEN_INT (0+4)));
27345           return;
27346
27347         default:
27348           gcc_unreachable ();
27349         }
27350       break;
27351
27352     case V4SImode:
27353       use_vec_merge = TARGET_SSE4_1;
27354       if (use_vec_merge)
27355         break;
27356
27357       /* Element 0 handled by vec_merge below.  */
27358       if (elt == 0)
27359         {
27360           use_vec_merge = true;
27361           break;
27362         }
27363
27364       if (TARGET_SSE2)
27365         {
27366           /* With SSE2, use integer shuffles to swap element 0 and ELT,
27367              store into element 0, then shuffle them back.  */
27368
27369           rtx order[4];
27370
27371           order[0] = GEN_INT (elt);
27372           order[1] = const1_rtx;
27373           order[2] = const2_rtx;
27374           order[3] = GEN_INT (3);
27375           order[elt] = const0_rtx;
27376
27377           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
27378                                         order[1], order[2], order[3]));
27379
27380           ix86_expand_vector_set (false, target, val, 0);
27381
27382           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
27383                                         order[1], order[2], order[3]));
27384         }
27385       else
27386         {
27387           /* For SSE1, we have to reuse the V4SF code.  */
27388           ix86_expand_vector_set (false, gen_lowpart (V4SFmode, target),
27389                                   gen_lowpart (SFmode, val), elt);
27390         }
27391       return;
27392
27393     case V8HImode:
27394       use_vec_merge = TARGET_SSE2;
27395       break;
27396     case V4HImode:
27397       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
27398       break;
27399
27400     case V16QImode:
27401       use_vec_merge = TARGET_SSE4_1;
27402       break;
27403
27404     case V8QImode:
27405       break;
27406
27407     case V32QImode:
27408       half_mode = V16QImode;
27409       j = 0;
27410       n = 16;
27411       goto half;
27412
27413     case V16HImode:
27414       half_mode = V8HImode;
27415       j = 1;
27416       n = 8;
27417       goto half;
27418
27419     case V8SImode:
27420       half_mode = V4SImode;
27421       j = 2;
27422       n = 4;
27423       goto half;
27424
27425     case V4DImode:
27426       half_mode = V2DImode;
27427       j = 3;
27428       n = 2;
27429       goto half;
27430
27431     case V8SFmode:
27432       half_mode = V4SFmode;
27433       j = 4;
27434       n = 4;
27435       goto half;
27436
27437     case V4DFmode:
27438       half_mode = V2DFmode;
27439       j = 5;
27440       n = 2;
27441       goto half;
27442
27443 half:
27444       /* Compute offset.  */
27445       i = elt / n;
27446       elt %= n;
27447
27448       gcc_assert (i <= 1);
27449
27450       /* Extract the half.  */
27451       tmp = gen_reg_rtx (half_mode);
27452       emit_insn ((*gen_extract[j][i]) (tmp, target));
27453
27454       /* Put val in tmp at elt.  */
27455       ix86_expand_vector_set (false, tmp, val, elt);
27456
27457       /* Put it back.  */
27458       emit_insn ((*gen_insert[j][i]) (target, target, tmp));
27459       return;
27460
27461     default:
27462       break;
27463     }
27464
27465   if (use_vec_merge)
27466     {
27467       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
27468       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
27469       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27470     }
27471   else
27472     {
27473       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
27474
27475       emit_move_insn (mem, target);
27476
27477       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
27478       emit_move_insn (tmp, val);
27479
27480       emit_move_insn (target, mem);
27481     }
27482 }
27483
27484 void
27485 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
27486 {
27487   enum machine_mode mode = GET_MODE (vec);
27488   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27489   bool use_vec_extr = false;
27490   rtx tmp;
27491
27492   switch (mode)
27493     {
27494     case V2SImode:
27495     case V2SFmode:
27496       if (!mmx_ok)
27497         break;
27498       /* FALLTHRU */
27499
27500     case V2DFmode:
27501     case V2DImode:
27502       use_vec_extr = true;
27503       break;
27504
27505     case V4SFmode:
27506       use_vec_extr = TARGET_SSE4_1;
27507       if (use_vec_extr)
27508         break;
27509
27510       switch (elt)
27511         {
27512         case 0:
27513           tmp = vec;
27514           break;
27515
27516         case 1:
27517         case 3:
27518           tmp = gen_reg_rtx (mode);
27519           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
27520                                        GEN_INT (elt), GEN_INT (elt),
27521                                        GEN_INT (elt+4), GEN_INT (elt+4)));
27522           break;
27523
27524         case 2:
27525           tmp = gen_reg_rtx (mode);
27526           emit_insn (gen_sse_unpckhps (tmp, vec, vec));
27527           break;
27528
27529         default:
27530           gcc_unreachable ();
27531         }
27532       vec = tmp;
27533       use_vec_extr = true;
27534       elt = 0;
27535       break;
27536
27537     case V4SImode:
27538       use_vec_extr = TARGET_SSE4_1;
27539       if (use_vec_extr)
27540         break;
27541
27542       if (TARGET_SSE2)
27543         {
27544           switch (elt)
27545             {
27546             case 0:
27547               tmp = vec;
27548               break;
27549
27550             case 1:
27551             case 3:
27552               tmp = gen_reg_rtx (mode);
27553               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
27554                                             GEN_INT (elt), GEN_INT (elt),
27555                                             GEN_INT (elt), GEN_INT (elt)));
27556               break;
27557
27558             case 2:
27559               tmp = gen_reg_rtx (mode);
27560               emit_insn (gen_sse2_punpckhdq (tmp, vec, vec));
27561               break;
27562
27563             default:
27564               gcc_unreachable ();
27565             }
27566           vec = tmp;
27567           use_vec_extr = true;
27568           elt = 0;
27569         }
27570       else
27571         {
27572           /* For SSE1, we have to reuse the V4SF code.  */
27573           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
27574                                       gen_lowpart (V4SFmode, vec), elt);
27575           return;
27576         }
27577       break;
27578
27579     case V8HImode:
27580       use_vec_extr = TARGET_SSE2;
27581       break;
27582     case V4HImode:
27583       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
27584       break;
27585
27586     case V16QImode:
27587       use_vec_extr = TARGET_SSE4_1;
27588       break;
27589
27590     case V8QImode:
27591       /* ??? Could extract the appropriate HImode element and shift.  */
27592     default:
27593       break;
27594     }
27595
27596   if (use_vec_extr)
27597     {
27598       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
27599       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
27600
27601       /* Let the rtl optimizers know about the zero extension performed.  */
27602       if (inner_mode == QImode || inner_mode == HImode)
27603         {
27604           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
27605           target = gen_lowpart (SImode, target);
27606         }
27607
27608       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27609     }
27610   else
27611     {
27612       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
27613
27614       emit_move_insn (mem, vec);
27615
27616       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
27617       emit_move_insn (target, tmp);
27618     }
27619 }
27620
27621 /* Expand a vector reduction on V4SFmode for SSE1.  FN is the binary
27622    pattern to reduce; DEST is the destination; IN is the input vector.  */
27623
27624 void
27625 ix86_expand_reduc_v4sf (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
27626 {
27627   rtx tmp1, tmp2, tmp3;
27628
27629   tmp1 = gen_reg_rtx (V4SFmode);
27630   tmp2 = gen_reg_rtx (V4SFmode);
27631   tmp3 = gen_reg_rtx (V4SFmode);
27632
27633   emit_insn (gen_sse_movhlps (tmp1, in, in));
27634   emit_insn (fn (tmp2, tmp1, in));
27635
27636   emit_insn (gen_sse_shufps_v4sf (tmp3, tmp2, tmp2,
27637                                GEN_INT (1), GEN_INT (1),
27638                                GEN_INT (1+4), GEN_INT (1+4)));
27639   emit_insn (fn (dest, tmp2, tmp3));
27640 }
27641 \f
27642 /* Target hook for scalar_mode_supported_p.  */
27643 static bool
27644 ix86_scalar_mode_supported_p (enum machine_mode mode)
27645 {
27646   if (DECIMAL_FLOAT_MODE_P (mode))
27647     return true;
27648   else if (mode == TFmode)
27649     return true;
27650   else
27651     return default_scalar_mode_supported_p (mode);
27652 }
27653
27654 /* Implements target hook vector_mode_supported_p.  */
27655 static bool
27656 ix86_vector_mode_supported_p (enum machine_mode mode)
27657 {
27658   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
27659     return true;
27660   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
27661     return true;
27662   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
27663     return true;
27664   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
27665     return true;
27666   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
27667     return true;
27668   return false;
27669 }
27670
27671 /* Target hook for c_mode_for_suffix.  */
27672 static enum machine_mode
27673 ix86_c_mode_for_suffix (char suffix)
27674 {
27675   if (suffix == 'q')
27676     return TFmode;
27677   if (suffix == 'w')
27678     return XFmode;
27679
27680   return VOIDmode;
27681 }
27682
27683 /* Worker function for TARGET_MD_ASM_CLOBBERS.
27684
27685    We do this in the new i386 backend to maintain source compatibility
27686    with the old cc0-based compiler.  */
27687
27688 static tree
27689 ix86_md_asm_clobbers (tree outputs ATTRIBUTE_UNUSED,
27690                       tree inputs ATTRIBUTE_UNUSED,
27691                       tree clobbers)
27692 {
27693   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
27694                         clobbers);
27695   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
27696                         clobbers);
27697   return clobbers;
27698 }
27699
27700 /* Implements target vector targetm.asm.encode_section_info.  This
27701    is not used by netware.  */
27702
27703 static void ATTRIBUTE_UNUSED
27704 ix86_encode_section_info (tree decl, rtx rtl, int first)
27705 {
27706   default_encode_section_info (decl, rtl, first);
27707
27708   if (TREE_CODE (decl) == VAR_DECL
27709       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
27710       && ix86_in_large_data_p (decl))
27711     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
27712 }
27713
27714 /* Worker function for REVERSE_CONDITION.  */
27715
27716 enum rtx_code
27717 ix86_reverse_condition (enum rtx_code code, enum machine_mode mode)
27718 {
27719   return (mode != CCFPmode && mode != CCFPUmode
27720           ? reverse_condition (code)
27721           : reverse_condition_maybe_unordered (code));
27722 }
27723
27724 /* Output code to perform an x87 FP register move, from OPERANDS[1]
27725    to OPERANDS[0].  */
27726
27727 const char *
27728 output_387_reg_move (rtx insn, rtx *operands)
27729 {
27730   if (REG_P (operands[0]))
27731     {
27732       if (REG_P (operands[1])
27733           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
27734         {
27735           if (REGNO (operands[0]) == FIRST_STACK_REG)
27736             return output_387_ffreep (operands, 0);
27737           return "fstp\t%y0";
27738         }
27739       if (STACK_TOP_P (operands[0]))
27740         return "fld%z1\t%y1";
27741       return "fst\t%y0";
27742     }
27743   else if (MEM_P (operands[0]))
27744     {
27745       gcc_assert (REG_P (operands[1]));
27746       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
27747         return "fstp%z0\t%y0";
27748       else
27749         {
27750           /* There is no non-popping store to memory for XFmode.
27751              So if we need one, follow the store with a load.  */
27752           if (GET_MODE (operands[0]) == XFmode)
27753             return "fstp%z0\t%y0\n\tfld%z0\t%y0";
27754           else
27755             return "fst%z0\t%y0";
27756         }
27757     }
27758   else
27759     gcc_unreachable();
27760 }
27761
27762 /* Output code to perform a conditional jump to LABEL, if C2 flag in
27763    FP status register is set.  */
27764
27765 void
27766 ix86_emit_fp_unordered_jump (rtx label)
27767 {
27768   rtx reg = gen_reg_rtx (HImode);
27769   rtx temp;
27770
27771   emit_insn (gen_x86_fnstsw_1 (reg));
27772
27773   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
27774     {
27775       emit_insn (gen_x86_sahf_1 (reg));
27776
27777       temp = gen_rtx_REG (CCmode, FLAGS_REG);
27778       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
27779     }
27780   else
27781     {
27782       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
27783
27784       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
27785       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
27786     }
27787
27788   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
27789                               gen_rtx_LABEL_REF (VOIDmode, label),
27790                               pc_rtx);
27791   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
27792
27793   emit_jump_insn (temp);
27794   predict_jump (REG_BR_PROB_BASE * 10 / 100);
27795 }
27796
27797 /* Output code to perform a log1p XFmode calculation.  */
27798
27799 void ix86_emit_i387_log1p (rtx op0, rtx op1)
27800 {
27801   rtx label1 = gen_label_rtx ();
27802   rtx label2 = gen_label_rtx ();
27803
27804   rtx tmp = gen_reg_rtx (XFmode);
27805   rtx tmp2 = gen_reg_rtx (XFmode);
27806
27807   emit_insn (gen_absxf2 (tmp, op1));
27808   emit_insn (gen_cmpxf (tmp,
27809     CONST_DOUBLE_FROM_REAL_VALUE (
27810        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
27811        XFmode)));
27812   emit_jump_insn (gen_bge (label1));
27813
27814   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
27815   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
27816   emit_jump (label2);
27817
27818   emit_label (label1);
27819   emit_move_insn (tmp, CONST1_RTX (XFmode));
27820   emit_insn (gen_addxf3 (tmp, op1, tmp));
27821   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
27822   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
27823
27824   emit_label (label2);
27825 }
27826
27827 /* Output code to perform a Newton-Rhapson approximation of a single precision
27828    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
27829
27830 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, enum machine_mode mode)
27831 {
27832   rtx x0, x1, e0, e1, two;
27833
27834   x0 = gen_reg_rtx (mode);
27835   e0 = gen_reg_rtx (mode);
27836   e1 = gen_reg_rtx (mode);
27837   x1 = gen_reg_rtx (mode);
27838
27839   two = CONST_DOUBLE_FROM_REAL_VALUE (dconst2, SFmode);
27840
27841   if (VECTOR_MODE_P (mode))
27842     two = ix86_build_const_vector (SFmode, true, two);
27843
27844   two = force_reg (mode, two);
27845
27846   /* a / b = a * rcp(b) * (2.0 - b * rcp(b)) */
27847
27848   /* x0 = rcp(b) estimate */
27849   emit_insn (gen_rtx_SET (VOIDmode, x0,
27850                           gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
27851                                           UNSPEC_RCP)));
27852   /* e0 = x0 * b */
27853   emit_insn (gen_rtx_SET (VOIDmode, e0,
27854                           gen_rtx_MULT (mode, x0, b)));
27855   /* e1 = 2. - e0 */
27856   emit_insn (gen_rtx_SET (VOIDmode, e1,
27857                           gen_rtx_MINUS (mode, two, e0)));
27858   /* x1 = x0 * e1 */
27859   emit_insn (gen_rtx_SET (VOIDmode, x1,
27860                           gen_rtx_MULT (mode, x0, e1)));
27861   /* res = a * x1 */
27862   emit_insn (gen_rtx_SET (VOIDmode, res,
27863                           gen_rtx_MULT (mode, a, x1)));
27864 }
27865
27866 /* Output code to perform a Newton-Rhapson approximation of a
27867    single precision floating point [reciprocal] square root.  */
27868
27869 void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
27870                          bool recip)
27871 {
27872   rtx x0, e0, e1, e2, e3, mthree, mhalf;
27873   REAL_VALUE_TYPE r;
27874
27875   x0 = gen_reg_rtx (mode);
27876   e0 = gen_reg_rtx (mode);
27877   e1 = gen_reg_rtx (mode);
27878   e2 = gen_reg_rtx (mode);
27879   e3 = gen_reg_rtx (mode);
27880
27881   real_from_integer (&r, VOIDmode, -3, -1, 0);
27882   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
27883
27884   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
27885   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
27886
27887   if (VECTOR_MODE_P (mode))
27888     {
27889       mthree = ix86_build_const_vector (SFmode, true, mthree);
27890       mhalf = ix86_build_const_vector (SFmode, true, mhalf);
27891     }
27892
27893   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
27894      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
27895
27896   /* x0 = rsqrt(a) estimate */
27897   emit_insn (gen_rtx_SET (VOIDmode, x0,
27898                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
27899                                           UNSPEC_RSQRT)));
27900
27901   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
27902   if (!recip)
27903     {
27904       rtx zero, mask;
27905
27906       zero = gen_reg_rtx (mode);
27907       mask = gen_reg_rtx (mode);
27908
27909       zero = force_reg (mode, CONST0_RTX(mode));
27910       emit_insn (gen_rtx_SET (VOIDmode, mask,
27911                               gen_rtx_NE (mode, zero, a)));
27912
27913       emit_insn (gen_rtx_SET (VOIDmode, x0,
27914                               gen_rtx_AND (mode, x0, mask)));
27915     }
27916
27917   /* e0 = x0 * a */
27918   emit_insn (gen_rtx_SET (VOIDmode, e0,
27919                           gen_rtx_MULT (mode, x0, a)));
27920   /* e1 = e0 * x0 */
27921   emit_insn (gen_rtx_SET (VOIDmode, e1,
27922                           gen_rtx_MULT (mode, e0, x0)));
27923
27924   /* e2 = e1 - 3. */
27925   mthree = force_reg (mode, mthree);
27926   emit_insn (gen_rtx_SET (VOIDmode, e2,
27927                           gen_rtx_PLUS (mode, e1, mthree)));
27928
27929   mhalf = force_reg (mode, mhalf);
27930   if (recip)
27931     /* e3 = -.5 * x0 */
27932     emit_insn (gen_rtx_SET (VOIDmode, e3,
27933                             gen_rtx_MULT (mode, x0, mhalf)));
27934   else
27935     /* e3 = -.5 * e0 */
27936     emit_insn (gen_rtx_SET (VOIDmode, e3,
27937                             gen_rtx_MULT (mode, e0, mhalf)));
27938   /* ret = e2 * e3 */
27939   emit_insn (gen_rtx_SET (VOIDmode, res,
27940                           gen_rtx_MULT (mode, e2, e3)));
27941 }
27942
27943 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
27944
27945 static void ATTRIBUTE_UNUSED
27946 i386_solaris_elf_named_section (const char *name, unsigned int flags,
27947                                 tree decl)
27948 {
27949   /* With Binutils 2.15, the "@unwind" marker must be specified on
27950      every occurrence of the ".eh_frame" section, not just the first
27951      one.  */
27952   if (TARGET_64BIT
27953       && strcmp (name, ".eh_frame") == 0)
27954     {
27955       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
27956                flags & SECTION_WRITE ? "aw" : "a");
27957       return;
27958     }
27959   default_elf_asm_named_section (name, flags, decl);
27960 }
27961
27962 /* Return the mangling of TYPE if it is an extended fundamental type.  */
27963
27964 static const char *
27965 ix86_mangle_type (const_tree type)
27966 {
27967   type = TYPE_MAIN_VARIANT (type);
27968
27969   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
27970       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
27971     return NULL;
27972
27973   switch (TYPE_MODE (type))
27974     {
27975     case TFmode:
27976       /* __float128 is "g".  */
27977       return "g";
27978     case XFmode:
27979       /* "long double" or __float80 is "e".  */
27980       return "e";
27981     default:
27982       return NULL;
27983     }
27984 }
27985
27986 /* For 32-bit code we can save PIC register setup by using
27987    __stack_chk_fail_local hidden function instead of calling
27988    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
27989    register, so it is better to call __stack_chk_fail directly.  */
27990
27991 static tree
27992 ix86_stack_protect_fail (void)
27993 {
27994   return TARGET_64BIT
27995          ? default_external_stack_protect_fail ()
27996          : default_hidden_stack_protect_fail ();
27997 }
27998
27999 /* Select a format to encode pointers in exception handling data.  CODE
28000    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
28001    true if the symbol may be affected by dynamic relocations.
28002
28003    ??? All x86 object file formats are capable of representing this.
28004    After all, the relocation needed is the same as for the call insn.
28005    Whether or not a particular assembler allows us to enter such, I
28006    guess we'll have to see.  */
28007 int
28008 asm_preferred_eh_data_format (int code, int global)
28009 {
28010   if (flag_pic)
28011     {
28012       int type = DW_EH_PE_sdata8;
28013       if (!TARGET_64BIT
28014           || ix86_cmodel == CM_SMALL_PIC
28015           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
28016         type = DW_EH_PE_sdata4;
28017       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
28018     }
28019   if (ix86_cmodel == CM_SMALL
28020       || (ix86_cmodel == CM_MEDIUM && code))
28021     return DW_EH_PE_udata4;
28022   return DW_EH_PE_absptr;
28023 }
28024 \f
28025 /* Expand copysign from SIGN to the positive value ABS_VALUE
28026    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
28027    the sign-bit.  */
28028 static void
28029 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
28030 {
28031   enum machine_mode mode = GET_MODE (sign);
28032   rtx sgn = gen_reg_rtx (mode);
28033   if (mask == NULL_RTX)
28034     {
28035       mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), false);
28036       if (!VECTOR_MODE_P (mode))
28037         {
28038           /* We need to generate a scalar mode mask in this case.  */
28039           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28040           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28041           mask = gen_reg_rtx (mode);
28042           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28043         }
28044     }
28045   else
28046     mask = gen_rtx_NOT (mode, mask);
28047   emit_insn (gen_rtx_SET (VOIDmode, sgn,
28048                           gen_rtx_AND (mode, mask, sign)));
28049   emit_insn (gen_rtx_SET (VOIDmode, result,
28050                           gen_rtx_IOR (mode, abs_value, sgn)));
28051 }
28052
28053 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
28054    mask for masking out the sign-bit is stored in *SMASK, if that is
28055    non-null.  */
28056 static rtx
28057 ix86_expand_sse_fabs (rtx op0, rtx *smask)
28058 {
28059   enum machine_mode mode = GET_MODE (op0);
28060   rtx xa, mask;
28061
28062   xa = gen_reg_rtx (mode);
28063   mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), true);
28064   if (!VECTOR_MODE_P (mode))
28065     {
28066       /* We need to generate a scalar mode mask in this case.  */
28067       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28068       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28069       mask = gen_reg_rtx (mode);
28070       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28071     }
28072   emit_insn (gen_rtx_SET (VOIDmode, xa,
28073                           gen_rtx_AND (mode, op0, mask)));
28074
28075   if (smask)
28076     *smask = mask;
28077
28078   return xa;
28079 }
28080
28081 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
28082    swapping the operands if SWAP_OPERANDS is true.  The expanded
28083    code is a forward jump to a newly created label in case the
28084    comparison is true.  The generated label rtx is returned.  */
28085 static rtx
28086 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
28087                                   bool swap_operands)
28088 {
28089   rtx label, tmp;
28090
28091   if (swap_operands)
28092     {
28093       tmp = op0;
28094       op0 = op1;
28095       op1 = tmp;
28096     }
28097
28098   label = gen_label_rtx ();
28099   tmp = gen_rtx_REG (CCFPUmode, FLAGS_REG);
28100   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28101                           gen_rtx_COMPARE (CCFPUmode, op0, op1)));
28102   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
28103   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
28104                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
28105   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
28106   JUMP_LABEL (tmp) = label;
28107
28108   return label;
28109 }
28110
28111 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
28112    using comparison code CODE.  Operands are swapped for the comparison if
28113    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
28114 static rtx
28115 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
28116                               bool swap_operands)
28117 {
28118   enum machine_mode mode = GET_MODE (op0);
28119   rtx mask = gen_reg_rtx (mode);
28120
28121   if (swap_operands)
28122     {
28123       rtx tmp = op0;
28124       op0 = op1;
28125       op1 = tmp;
28126     }
28127
28128   if (mode == DFmode)
28129     emit_insn (gen_sse2_maskcmpdf3 (mask, op0, op1,
28130                                     gen_rtx_fmt_ee (code, mode, op0, op1)));
28131   else
28132     emit_insn (gen_sse_maskcmpsf3 (mask, op0, op1,
28133                                    gen_rtx_fmt_ee (code, mode, op0, op1)));
28134
28135   return mask;
28136 }
28137
28138 /* Generate and return a rtx of mode MODE for 2**n where n is the number
28139    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
28140 static rtx
28141 ix86_gen_TWO52 (enum machine_mode mode)
28142 {
28143   REAL_VALUE_TYPE TWO52r;
28144   rtx TWO52;
28145
28146   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
28147   TWO52 = const_double_from_real_value (TWO52r, mode);
28148   TWO52 = force_reg (mode, TWO52);
28149
28150   return TWO52;
28151 }
28152
28153 /* Expand SSE sequence for computing lround from OP1 storing
28154    into OP0.  */
28155 void
28156 ix86_expand_lround (rtx op0, rtx op1)
28157 {
28158   /* C code for the stuff we're doing below:
28159        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
28160        return (long)tmp;
28161    */
28162   enum machine_mode mode = GET_MODE (op1);
28163   const struct real_format *fmt;
28164   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
28165   rtx adj;
28166
28167   /* load nextafter (0.5, 0.0) */
28168   fmt = REAL_MODE_FORMAT (mode);
28169   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
28170   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
28171
28172   /* adj = copysign (0.5, op1) */
28173   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
28174   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
28175
28176   /* adj = op1 + adj */
28177   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
28178
28179   /* op0 = (imode)adj */
28180   expand_fix (op0, adj, 0);
28181 }
28182
28183 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
28184    into OPERAND0.  */
28185 void
28186 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
28187 {
28188   /* C code for the stuff we're doing below (for do_floor):
28189         xi = (long)op1;
28190         xi -= (double)xi > op1 ? 1 : 0;
28191         return xi;
28192    */
28193   enum machine_mode fmode = GET_MODE (op1);
28194   enum machine_mode imode = GET_MODE (op0);
28195   rtx ireg, freg, label, tmp;
28196
28197   /* reg = (long)op1 */
28198   ireg = gen_reg_rtx (imode);
28199   expand_fix (ireg, op1, 0);
28200
28201   /* freg = (double)reg */
28202   freg = gen_reg_rtx (fmode);
28203   expand_float (freg, ireg, 0);
28204
28205   /* ireg = (freg > op1) ? ireg - 1 : ireg */
28206   label = ix86_expand_sse_compare_and_jump (UNLE,
28207                                             freg, op1, !do_floor);
28208   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
28209                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
28210   emit_move_insn (ireg, tmp);
28211
28212   emit_label (label);
28213   LABEL_NUSES (label) = 1;
28214
28215   emit_move_insn (op0, ireg);
28216 }
28217
28218 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
28219    result in OPERAND0.  */
28220 void
28221 ix86_expand_rint (rtx operand0, rtx operand1)
28222 {
28223   /* C code for the stuff we're doing below:
28224         xa = fabs (operand1);
28225         if (!isless (xa, 2**52))
28226           return operand1;
28227         xa = xa + 2**52 - 2**52;
28228         return copysign (xa, operand1);
28229    */
28230   enum machine_mode mode = GET_MODE (operand0);
28231   rtx res, xa, label, TWO52, mask;
28232
28233   res = gen_reg_rtx (mode);
28234   emit_move_insn (res, operand1);
28235
28236   /* xa = abs (operand1) */
28237   xa = ix86_expand_sse_fabs (res, &mask);
28238
28239   /* if (!isless (xa, TWO52)) goto label; */
28240   TWO52 = ix86_gen_TWO52 (mode);
28241   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28242
28243   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28244   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28245
28246   ix86_sse_copysign_to_positive (res, xa, res, mask);
28247
28248   emit_label (label);
28249   LABEL_NUSES (label) = 1;
28250
28251   emit_move_insn (operand0, res);
28252 }
28253
28254 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
28255    into OPERAND0.  */
28256 void
28257 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
28258 {
28259   /* C code for the stuff we expand below.
28260         double xa = fabs (x), x2;
28261         if (!isless (xa, TWO52))
28262           return x;
28263         xa = xa + TWO52 - TWO52;
28264         x2 = copysign (xa, x);
28265      Compensate.  Floor:
28266         if (x2 > x)
28267           x2 -= 1;
28268      Compensate.  Ceil:
28269         if (x2 < x)
28270           x2 -= -1;
28271         return x2;
28272    */
28273   enum machine_mode mode = GET_MODE (operand0);
28274   rtx xa, TWO52, tmp, label, one, res, mask;
28275
28276   TWO52 = ix86_gen_TWO52 (mode);
28277
28278   /* Temporary for holding the result, initialized to the input
28279      operand to ease control flow.  */
28280   res = gen_reg_rtx (mode);
28281   emit_move_insn (res, operand1);
28282
28283   /* xa = abs (operand1) */
28284   xa = ix86_expand_sse_fabs (res, &mask);
28285
28286   /* if (!isless (xa, TWO52)) goto label; */
28287   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28288
28289   /* xa = xa + TWO52 - TWO52; */
28290   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28291   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28292
28293   /* xa = copysign (xa, operand1) */
28294   ix86_sse_copysign_to_positive (xa, xa, res, mask);
28295
28296   /* generate 1.0 or -1.0 */
28297   one = force_reg (mode,
28298                    const_double_from_real_value (do_floor
28299                                                  ? dconst1 : dconstm1, mode));
28300
28301   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
28302   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
28303   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28304                           gen_rtx_AND (mode, one, tmp)));
28305   /* We always need to subtract here to preserve signed zero.  */
28306   tmp = expand_simple_binop (mode, MINUS,
28307                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28308   emit_move_insn (res, tmp);
28309
28310   emit_label (label);
28311   LABEL_NUSES (label) = 1;
28312
28313   emit_move_insn (operand0, res);
28314 }
28315
28316 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
28317    into OPERAND0.  */
28318 void
28319 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
28320 {
28321   /* C code for the stuff we expand below.
28322         double xa = fabs (x), x2;
28323         if (!isless (xa, TWO52))
28324           return x;
28325         x2 = (double)(long)x;
28326      Compensate.  Floor:
28327         if (x2 > x)
28328           x2 -= 1;
28329      Compensate.  Ceil:
28330         if (x2 < x)
28331           x2 += 1;
28332         if (HONOR_SIGNED_ZEROS (mode))
28333           return copysign (x2, x);
28334         return x2;
28335    */
28336   enum machine_mode mode = GET_MODE (operand0);
28337   rtx xa, xi, TWO52, tmp, label, one, res, mask;
28338
28339   TWO52 = ix86_gen_TWO52 (mode);
28340
28341   /* Temporary for holding the result, initialized to the input
28342      operand to ease control flow.  */
28343   res = gen_reg_rtx (mode);
28344   emit_move_insn (res, operand1);
28345
28346   /* xa = abs (operand1) */
28347   xa = ix86_expand_sse_fabs (res, &mask);
28348
28349   /* if (!isless (xa, TWO52)) goto label; */
28350   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28351
28352   /* xa = (double)(long)x */
28353   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28354   expand_fix (xi, res, 0);
28355   expand_float (xa, xi, 0);
28356
28357   /* generate 1.0 */
28358   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
28359
28360   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
28361   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
28362   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28363                           gen_rtx_AND (mode, one, tmp)));
28364   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
28365                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28366   emit_move_insn (res, tmp);
28367
28368   if (HONOR_SIGNED_ZEROS (mode))
28369     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
28370
28371   emit_label (label);
28372   LABEL_NUSES (label) = 1;
28373
28374   emit_move_insn (operand0, res);
28375 }
28376
28377 /* Expand SSE sequence for computing round from OPERAND1 storing
28378    into OPERAND0.  Sequence that works without relying on DImode truncation
28379    via cvttsd2siq that is only available on 64bit targets.  */
28380 void
28381 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
28382 {
28383   /* C code for the stuff we expand below.
28384         double xa = fabs (x), xa2, x2;
28385         if (!isless (xa, TWO52))
28386           return x;
28387      Using the absolute value and copying back sign makes
28388      -0.0 -> -0.0 correct.
28389         xa2 = xa + TWO52 - TWO52;
28390      Compensate.
28391         dxa = xa2 - xa;
28392         if (dxa <= -0.5)
28393           xa2 += 1;
28394         else if (dxa > 0.5)
28395           xa2 -= 1;
28396         x2 = copysign (xa2, x);
28397         return x2;
28398    */
28399   enum machine_mode mode = GET_MODE (operand0);
28400   rtx xa, xa2, dxa, TWO52, tmp, label, half, mhalf, one, res, mask;
28401
28402   TWO52 = ix86_gen_TWO52 (mode);
28403
28404   /* Temporary for holding the result, initialized to the input
28405      operand to ease control flow.  */
28406   res = gen_reg_rtx (mode);
28407   emit_move_insn (res, operand1);
28408
28409   /* xa = abs (operand1) */
28410   xa = ix86_expand_sse_fabs (res, &mask);
28411
28412   /* if (!isless (xa, TWO52)) goto label; */
28413   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28414
28415   /* xa2 = xa + TWO52 - TWO52; */
28416   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28417   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
28418
28419   /* dxa = xa2 - xa; */
28420   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
28421
28422   /* generate 0.5, 1.0 and -0.5 */
28423   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
28424   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
28425   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
28426                                0, OPTAB_DIRECT);
28427
28428   /* Compensate.  */
28429   tmp = gen_reg_rtx (mode);
28430   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
28431   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
28432   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28433                           gen_rtx_AND (mode, one, tmp)));
28434   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28435   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
28436   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
28437   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28438                           gen_rtx_AND (mode, one, tmp)));
28439   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28440
28441   /* res = copysign (xa2, operand1) */
28442   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
28443
28444   emit_label (label);
28445   LABEL_NUSES (label) = 1;
28446
28447   emit_move_insn (operand0, res);
28448 }
28449
28450 /* Expand SSE sequence for computing trunc from OPERAND1 storing
28451    into OPERAND0.  */
28452 void
28453 ix86_expand_trunc (rtx operand0, rtx operand1)
28454 {
28455   /* C code for SSE variant we expand below.
28456         double xa = fabs (x), x2;
28457         if (!isless (xa, TWO52))
28458           return x;
28459         x2 = (double)(long)x;
28460         if (HONOR_SIGNED_ZEROS (mode))
28461           return copysign (x2, x);
28462         return x2;
28463    */
28464   enum machine_mode mode = GET_MODE (operand0);
28465   rtx xa, xi, TWO52, label, res, mask;
28466
28467   TWO52 = ix86_gen_TWO52 (mode);
28468
28469   /* Temporary for holding the result, initialized to the input
28470      operand to ease control flow.  */
28471   res = gen_reg_rtx (mode);
28472   emit_move_insn (res, operand1);
28473
28474   /* xa = abs (operand1) */
28475   xa = ix86_expand_sse_fabs (res, &mask);
28476
28477   /* if (!isless (xa, TWO52)) goto label; */
28478   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28479
28480   /* x = (double)(long)x */
28481   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28482   expand_fix (xi, res, 0);
28483   expand_float (res, xi, 0);
28484
28485   if (HONOR_SIGNED_ZEROS (mode))
28486     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
28487
28488   emit_label (label);
28489   LABEL_NUSES (label) = 1;
28490
28491   emit_move_insn (operand0, res);
28492 }
28493
28494 /* Expand SSE sequence for computing trunc from OPERAND1 storing
28495    into OPERAND0.  */
28496 void
28497 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
28498 {
28499   enum machine_mode mode = GET_MODE (operand0);
28500   rtx xa, mask, TWO52, label, one, res, smask, tmp;
28501
28502   /* C code for SSE variant we expand below.
28503         double xa = fabs (x), x2;
28504         if (!isless (xa, TWO52))
28505           return x;
28506         xa2 = xa + TWO52 - TWO52;
28507      Compensate:
28508         if (xa2 > xa)
28509           xa2 -= 1.0;
28510         x2 = copysign (xa2, x);
28511         return x2;
28512    */
28513
28514   TWO52 = ix86_gen_TWO52 (mode);
28515
28516   /* Temporary for holding the result, initialized to the input
28517      operand to ease control flow.  */
28518   res = gen_reg_rtx (mode);
28519   emit_move_insn (res, operand1);
28520
28521   /* xa = abs (operand1) */
28522   xa = ix86_expand_sse_fabs (res, &smask);
28523
28524   /* if (!isless (xa, TWO52)) goto label; */
28525   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28526
28527   /* res = xa + TWO52 - TWO52; */
28528   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28529   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
28530   emit_move_insn (res, tmp);
28531
28532   /* generate 1.0 */
28533   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
28534
28535   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
28536   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
28537   emit_insn (gen_rtx_SET (VOIDmode, mask,
28538                           gen_rtx_AND (mode, mask, one)));
28539   tmp = expand_simple_binop (mode, MINUS,
28540                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
28541   emit_move_insn (res, tmp);
28542
28543   /* res = copysign (res, operand1) */
28544   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
28545
28546   emit_label (label);
28547   LABEL_NUSES (label) = 1;
28548
28549   emit_move_insn (operand0, res);
28550 }
28551
28552 /* Expand SSE sequence for computing round from OPERAND1 storing
28553    into OPERAND0.  */
28554 void
28555 ix86_expand_round (rtx operand0, rtx operand1)
28556 {
28557   /* C code for the stuff we're doing below:
28558         double xa = fabs (x);
28559         if (!isless (xa, TWO52))
28560           return x;
28561         xa = (double)(long)(xa + nextafter (0.5, 0.0));
28562         return copysign (xa, x);
28563    */
28564   enum machine_mode mode = GET_MODE (operand0);
28565   rtx res, TWO52, xa, label, xi, half, mask;
28566   const struct real_format *fmt;
28567   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
28568
28569   /* Temporary for holding the result, initialized to the input
28570      operand to ease control flow.  */
28571   res = gen_reg_rtx (mode);
28572   emit_move_insn (res, operand1);
28573
28574   TWO52 = ix86_gen_TWO52 (mode);
28575   xa = ix86_expand_sse_fabs (res, &mask);
28576   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28577
28578   /* load nextafter (0.5, 0.0) */
28579   fmt = REAL_MODE_FORMAT (mode);
28580   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
28581   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
28582
28583   /* xa = xa + 0.5 */
28584   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
28585   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
28586
28587   /* xa = (double)(int64_t)xa */
28588   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28589   expand_fix (xi, xa, 0);
28590   expand_float (xa, xi, 0);
28591
28592   /* res = copysign (xa, operand1) */
28593   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
28594
28595   emit_label (label);
28596   LABEL_NUSES (label) = 1;
28597
28598   emit_move_insn (operand0, res);
28599 }
28600
28601 \f
28602 /* Validate whether a SSE5 instruction is valid or not.
28603    OPERANDS is the array of operands.
28604    NUM is the number of operands.
28605    USES_OC0 is true if the instruction uses OC0 and provides 4 variants.
28606    NUM_MEMORY is the maximum number of memory operands to accept.  
28607    when COMMUTATIVE is set, operand 1 and 2 can be swapped.  */
28608
28609 bool
28610 ix86_sse5_valid_op_p (rtx operands[], rtx insn ATTRIBUTE_UNUSED, int num,
28611                       bool uses_oc0, int num_memory, bool commutative)
28612 {
28613   int mem_mask;
28614   int mem_count;
28615   int i;
28616
28617   /* Count the number of memory arguments */
28618   mem_mask = 0;
28619   mem_count = 0;
28620   for (i = 0; i < num; i++)
28621     {
28622       enum machine_mode mode = GET_MODE (operands[i]);
28623       if (register_operand (operands[i], mode))
28624         ;
28625
28626       else if (memory_operand (operands[i], mode))
28627         {
28628           mem_mask |= (1 << i);
28629           mem_count++;
28630         }
28631
28632       else
28633         {
28634           rtx pattern = PATTERN (insn);
28635
28636           /* allow 0 for pcmov */
28637           if (GET_CODE (pattern) != SET
28638               || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE
28639               || i < 2
28640               || operands[i] != CONST0_RTX (mode))
28641             return false;
28642         }
28643     }
28644
28645   /* Special case pmacsdq{l,h} where we allow the 3rd argument to be
28646      a memory operation.  */
28647   if (num_memory < 0)
28648     {
28649       num_memory = -num_memory;
28650       if ((mem_mask & (1 << (num-1))) != 0)
28651         {
28652           mem_mask &= ~(1 << (num-1));
28653           mem_count--;
28654         }
28655     }
28656
28657   /* If there were no memory operations, allow the insn */
28658   if (mem_mask == 0)
28659     return true;
28660
28661   /* Do not allow the destination register to be a memory operand.  */
28662   else if (mem_mask & (1 << 0))
28663     return false;
28664
28665   /* If there are too many memory operations, disallow the instruction.  While
28666      the hardware only allows 1 memory reference, before register allocation
28667      for some insns, we allow two memory operations sometimes in order to allow
28668      code like the following to be optimized:
28669
28670         float fmadd (float *a, float *b, float *c) { return (*a * *b) + *c; }
28671
28672     or similar cases that are vectorized into using the fmaddss
28673     instruction.  */
28674   else if (mem_count > num_memory)
28675     return false;
28676
28677   /* Don't allow more than one memory operation if not optimizing.  */
28678   else if (mem_count > 1 && !optimize)
28679     return false;
28680
28681   else if (num == 4 && mem_count == 1)
28682     {
28683       /* formats (destination is the first argument), example fmaddss:
28684          xmm1, xmm1, xmm2, xmm3/mem
28685          xmm1, xmm1, xmm2/mem, xmm3
28686          xmm1, xmm2, xmm3/mem, xmm1
28687          xmm1, xmm2/mem, xmm3, xmm1 */
28688       if (uses_oc0)
28689         return ((mem_mask == (1 << 1))
28690                 || (mem_mask == (1 << 2))
28691                 || (mem_mask == (1 << 3)));
28692
28693       /* format, example pmacsdd:
28694          xmm1, xmm2, xmm3/mem, xmm1 */
28695       if (commutative)
28696         return (mem_mask == (1 << 2) || mem_mask == (1 << 1));
28697       else
28698         return (mem_mask == (1 << 2));
28699     }
28700
28701   else if (num == 4 && num_memory == 2)
28702     {
28703       /* If there are two memory operations, we can load one of the memory ops
28704          into the destination register.  This is for optimizing the
28705          multiply/add ops, which the combiner has optimized both the multiply
28706          and the add insns to have a memory operation.  We have to be careful
28707          that the destination doesn't overlap with the inputs.  */
28708       rtx op0 = operands[0];
28709
28710       if (reg_mentioned_p (op0, operands[1])
28711           || reg_mentioned_p (op0, operands[2])
28712           || reg_mentioned_p (op0, operands[3]))
28713         return false;
28714
28715       /* formats (destination is the first argument), example fmaddss:
28716          xmm1, xmm1, xmm2, xmm3/mem
28717          xmm1, xmm1, xmm2/mem, xmm3
28718          xmm1, xmm2, xmm3/mem, xmm1
28719          xmm1, xmm2/mem, xmm3, xmm1
28720
28721          For the oc0 case, we will load either operands[1] or operands[3] into
28722          operands[0], so any combination of 2 memory operands is ok.  */
28723       if (uses_oc0)
28724         return true;
28725
28726       /* format, example pmacsdd:
28727          xmm1, xmm2, xmm3/mem, xmm1
28728
28729          For the integer multiply/add instructions be more restrictive and
28730          require operands[2] and operands[3] to be the memory operands.  */
28731       if (commutative)
28732         return (mem_mask == ((1 << 1) | (1 << 3)) || ((1 << 2) | (1 << 3)));
28733       else
28734         return (mem_mask == ((1 << 2) | (1 << 3)));
28735     }
28736
28737   else if (num == 3 && num_memory == 1)
28738     {
28739       /* formats, example protb:
28740          xmm1, xmm2, xmm3/mem
28741          xmm1, xmm2/mem, xmm3 */
28742       if (uses_oc0)
28743         return ((mem_mask == (1 << 1)) || (mem_mask == (1 << 2)));
28744
28745       /* format, example comeq:
28746          xmm1, xmm2, xmm3/mem */
28747       else
28748         return (mem_mask == (1 << 2));
28749     }
28750
28751   else
28752     gcc_unreachable ();
28753
28754   return false;
28755 }
28756
28757 \f
28758 /* Fixup an SSE5 instruction that has 2 memory input references into a form the
28759    hardware will allow by using the destination register to load one of the
28760    memory operations.  Presently this is used by the multiply/add routines to
28761    allow 2 memory references.  */
28762
28763 void
28764 ix86_expand_sse5_multiple_memory (rtx operands[],
28765                                   int num,
28766                                   enum machine_mode mode)
28767 {
28768   rtx op0 = operands[0];
28769   if (num != 4
28770       || memory_operand (op0, mode)
28771       || reg_mentioned_p (op0, operands[1])
28772       || reg_mentioned_p (op0, operands[2])
28773       || reg_mentioned_p (op0, operands[3]))
28774     gcc_unreachable ();
28775
28776   /* For 2 memory operands, pick either operands[1] or operands[3] to move into
28777      the destination register.  */
28778   if (memory_operand (operands[1], mode))
28779     {
28780       emit_move_insn (op0, operands[1]);
28781       operands[1] = op0;
28782     }
28783   else if (memory_operand (operands[3], mode))
28784     {
28785       emit_move_insn (op0, operands[3]);
28786       operands[3] = op0;
28787     }
28788   else
28789     gcc_unreachable ();
28790
28791   return;
28792 }
28793
28794 \f
28795 /* Table of valid machine attributes.  */
28796 static const struct attribute_spec ix86_attribute_table[] =
28797 {
28798   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
28799   /* Stdcall attribute says callee is responsible for popping arguments
28800      if they are not variable.  */
28801   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute },
28802   /* Fastcall attribute says callee is responsible for popping arguments
28803      if they are not variable.  */
28804   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute },
28805   /* Cdecl attribute says the callee is a normal C declaration */
28806   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute },
28807   /* Regparm attribute specifies how many integer arguments are to be
28808      passed in registers.  */
28809   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute },
28810   /* Sseregparm attribute says we are using x86_64 calling conventions
28811      for FP arguments.  */
28812   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute },
28813   /* force_align_arg_pointer says this function realigns the stack at entry.  */
28814   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
28815     false, true,  true, ix86_handle_cconv_attribute },
28816 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
28817   { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
28818   { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
28819   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute },
28820 #endif
28821   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
28822   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
28823 #ifdef SUBTARGET_ATTRIBUTE_TABLE
28824   SUBTARGET_ATTRIBUTE_TABLE,
28825 #endif
28826   /* ms_abi and sysv_abi calling convention function attributes.  */
28827   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
28828   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
28829   /* End element.  */
28830   { NULL,        0, 0, false, false, false, NULL }
28831 };
28832
28833 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
28834 static int
28835 x86_builtin_vectorization_cost (bool runtime_test)
28836 {
28837   /* If the branch of the runtime test is taken - i.e. - the vectorized
28838      version is skipped - this incurs a misprediction cost (because the
28839      vectorized version is expected to be the fall-through).  So we subtract
28840      the latency of a mispredicted branch from the costs that are incured
28841      when the vectorized version is executed.
28842
28843      TODO: The values in individual target tables have to be tuned or new
28844      fields may be needed. For eg. on K8, the default branch path is the
28845      not-taken path. If the taken path is predicted correctly, the minimum
28846      penalty of going down the taken-path is 1 cycle. If the taken-path is
28847      not predicted correctly, then the minimum penalty is 10 cycles.  */
28848
28849   if (runtime_test)
28850     {
28851       return (-(ix86_cost->cond_taken_branch_cost));
28852     }
28853   else
28854     return 0;
28855 }
28856
28857 /* This function returns the calling abi specific va_list type node.
28858    It returns  the FNDECL specific va_list type.  */
28859
28860 tree
28861 ix86_fn_abi_va_list (tree fndecl)
28862 {
28863   int abi;
28864
28865   if (!TARGET_64BIT)
28866     return va_list_type_node;
28867   gcc_assert (fndecl != NULL_TREE);
28868   abi = ix86_function_abi ((const_tree) fndecl);
28869
28870   if (abi == MS_ABI)
28871     return ms_va_list_type_node;
28872   else
28873     return sysv_va_list_type_node;
28874 }
28875
28876 /* Returns the canonical va_list type specified by TYPE. If there
28877    is no valid TYPE provided, it return NULL_TREE.  */
28878
28879 tree
28880 ix86_canonical_va_list_type (tree type)
28881 {
28882   tree wtype, htype;
28883
28884   /* Resolve references and pointers to va_list type.  */
28885   if (INDIRECT_REF_P (type))
28886     type = TREE_TYPE (type);
28887   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
28888     type = TREE_TYPE (type);
28889
28890   if (TARGET_64BIT)
28891     {
28892       wtype = va_list_type_node;
28893           gcc_assert (wtype != NULL_TREE);
28894       htype = type;
28895       if (TREE_CODE (wtype) == ARRAY_TYPE)
28896         {
28897           /* If va_list is an array type, the argument may have decayed
28898              to a pointer type, e.g. by being passed to another function.
28899              In that case, unwrap both types so that we can compare the
28900              underlying records.  */
28901           if (TREE_CODE (htype) == ARRAY_TYPE
28902               || POINTER_TYPE_P (htype))
28903             {
28904               wtype = TREE_TYPE (wtype);
28905               htype = TREE_TYPE (htype);
28906             }
28907         }
28908       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
28909         return va_list_type_node;
28910       wtype = sysv_va_list_type_node;
28911           gcc_assert (wtype != NULL_TREE);
28912       htype = type;
28913       if (TREE_CODE (wtype) == ARRAY_TYPE)
28914         {
28915           /* If va_list is an array type, the argument may have decayed
28916              to a pointer type, e.g. by being passed to another function.
28917              In that case, unwrap both types so that we can compare the
28918              underlying records.  */
28919           if (TREE_CODE (htype) == ARRAY_TYPE
28920               || POINTER_TYPE_P (htype))
28921             {
28922               wtype = TREE_TYPE (wtype);
28923               htype = TREE_TYPE (htype);
28924             }
28925         }
28926       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
28927         return sysv_va_list_type_node;
28928       wtype = ms_va_list_type_node;
28929           gcc_assert (wtype != NULL_TREE);
28930       htype = type;
28931       if (TREE_CODE (wtype) == ARRAY_TYPE)
28932         {
28933           /* If va_list is an array type, the argument may have decayed
28934              to a pointer type, e.g. by being passed to another function.
28935              In that case, unwrap both types so that we can compare the
28936              underlying records.  */
28937           if (TREE_CODE (htype) == ARRAY_TYPE
28938               || POINTER_TYPE_P (htype))
28939             {
28940               wtype = TREE_TYPE (wtype);
28941               htype = TREE_TYPE (htype);
28942             }
28943         }
28944       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
28945         return ms_va_list_type_node;
28946       return NULL_TREE;
28947     }
28948   return std_canonical_va_list_type (type);
28949 }
28950
28951 /* Iterate through the target-specific builtin types for va_list.
28952     IDX denotes the iterator, *PTREE is set to the result type of
28953     the va_list builtin, and *PNAME to its internal type.
28954     Returns zero if there is no element for this index, otherwise
28955     IDX should be increased upon the next call.
28956     Note, do not iterate a base builtin's name like __builtin_va_list.
28957     Used from c_common_nodes_and_builtins.  */
28958
28959 int
28960 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
28961 {
28962   if (!TARGET_64BIT)
28963     return 0;
28964   switch (idx) {
28965   case 0:
28966     *ptree = ms_va_list_type_node;
28967     *pname = "__builtin_ms_va_list";
28968     break;
28969   case 1:
28970     *ptree = sysv_va_list_type_node;
28971     *pname = "__builtin_sysv_va_list";
28972     break;
28973   default:
28974     return 0;
28975   }
28976   return 1;
28977 }
28978
28979 /* Initialize the GCC target structure.  */
28980 #undef TARGET_RETURN_IN_MEMORY
28981 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
28982
28983 #undef TARGET_ATTRIBUTE_TABLE
28984 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
28985 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
28986 #  undef TARGET_MERGE_DECL_ATTRIBUTES
28987 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
28988 #endif
28989
28990 #undef TARGET_COMP_TYPE_ATTRIBUTES
28991 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
28992
28993 #undef TARGET_INIT_BUILTINS
28994 #define TARGET_INIT_BUILTINS ix86_init_builtins
28995 #undef TARGET_EXPAND_BUILTIN
28996 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
28997
28998 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
28999 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
29000   ix86_builtin_vectorized_function
29001
29002 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
29003 #define TARGET_VECTORIZE_BUILTIN_CONVERSION ix86_vectorize_builtin_conversion
29004
29005 #undef TARGET_BUILTIN_RECIPROCAL
29006 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
29007
29008 #undef TARGET_ASM_FUNCTION_EPILOGUE
29009 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
29010
29011 #undef TARGET_ENCODE_SECTION_INFO
29012 #ifndef SUBTARGET_ENCODE_SECTION_INFO
29013 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
29014 #else
29015 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
29016 #endif
29017
29018 #undef TARGET_ASM_OPEN_PAREN
29019 #define TARGET_ASM_OPEN_PAREN ""
29020 #undef TARGET_ASM_CLOSE_PAREN
29021 #define TARGET_ASM_CLOSE_PAREN ""
29022
29023 #undef TARGET_ASM_ALIGNED_HI_OP
29024 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
29025 #undef TARGET_ASM_ALIGNED_SI_OP
29026 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
29027 #ifdef ASM_QUAD
29028 #undef TARGET_ASM_ALIGNED_DI_OP
29029 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
29030 #endif
29031
29032 #undef TARGET_ASM_UNALIGNED_HI_OP
29033 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
29034 #undef TARGET_ASM_UNALIGNED_SI_OP
29035 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
29036 #undef TARGET_ASM_UNALIGNED_DI_OP
29037 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
29038
29039 #undef TARGET_SCHED_ADJUST_COST
29040 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
29041 #undef TARGET_SCHED_ISSUE_RATE
29042 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
29043 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
29044 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
29045   ia32_multipass_dfa_lookahead
29046
29047 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
29048 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
29049
29050 #ifdef HAVE_AS_TLS
29051 #undef TARGET_HAVE_TLS
29052 #define TARGET_HAVE_TLS true
29053 #endif
29054 #undef TARGET_CANNOT_FORCE_CONST_MEM
29055 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
29056 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
29057 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
29058
29059 #undef TARGET_DELEGITIMIZE_ADDRESS
29060 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
29061
29062 #undef TARGET_MS_BITFIELD_LAYOUT_P
29063 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
29064
29065 #if TARGET_MACHO
29066 #undef TARGET_BINDS_LOCAL_P
29067 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
29068 #endif
29069 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29070 #undef TARGET_BINDS_LOCAL_P
29071 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
29072 #endif
29073
29074 #undef TARGET_ASM_OUTPUT_MI_THUNK
29075 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
29076 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
29077 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
29078
29079 #undef TARGET_ASM_FILE_START
29080 #define TARGET_ASM_FILE_START x86_file_start
29081
29082 #undef TARGET_DEFAULT_TARGET_FLAGS
29083 #define TARGET_DEFAULT_TARGET_FLAGS     \
29084   (TARGET_DEFAULT                       \
29085    | TARGET_SUBTARGET_DEFAULT           \
29086    | TARGET_TLS_DIRECT_SEG_REFS_DEFAULT)
29087
29088 #undef TARGET_HANDLE_OPTION
29089 #define TARGET_HANDLE_OPTION ix86_handle_option
29090
29091 #undef TARGET_RTX_COSTS
29092 #define TARGET_RTX_COSTS ix86_rtx_costs
29093 #undef TARGET_ADDRESS_COST
29094 #define TARGET_ADDRESS_COST ix86_address_cost
29095
29096 #undef TARGET_FIXED_CONDITION_CODE_REGS
29097 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
29098 #undef TARGET_CC_MODES_COMPATIBLE
29099 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
29100
29101 #undef TARGET_MACHINE_DEPENDENT_REORG
29102 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
29103
29104 #undef TARGET_BUILD_BUILTIN_VA_LIST
29105 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
29106
29107 #undef TARGET_FN_ABI_VA_LIST
29108 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
29109
29110 #undef TARGET_CANONICAL_VA_LIST_TYPE
29111 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
29112
29113 #undef TARGET_EXPAND_BUILTIN_VA_START
29114 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
29115
29116 #undef TARGET_MD_ASM_CLOBBERS
29117 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
29118
29119 #undef TARGET_PROMOTE_PROTOTYPES
29120 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
29121 #undef TARGET_STRUCT_VALUE_RTX
29122 #define TARGET_STRUCT_VALUE_RTX ix86_struct_value_rtx
29123 #undef TARGET_SETUP_INCOMING_VARARGS
29124 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
29125 #undef TARGET_MUST_PASS_IN_STACK
29126 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
29127 #undef TARGET_PASS_BY_REFERENCE
29128 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
29129 #undef TARGET_INTERNAL_ARG_POINTER
29130 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
29131 #undef TARGET_UPDATE_STACK_BOUNDARY
29132 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
29133 #undef TARGET_GET_DRAP_RTX
29134 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
29135 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
29136 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC ix86_dwarf_handle_frame_unspec
29137 #undef TARGET_STRICT_ARGUMENT_NAMING
29138 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
29139
29140 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
29141 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
29142
29143 #undef TARGET_SCALAR_MODE_SUPPORTED_P
29144 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
29145
29146 #undef TARGET_VECTOR_MODE_SUPPORTED_P
29147 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
29148
29149 #undef TARGET_C_MODE_FOR_SUFFIX
29150 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
29151
29152 #ifdef HAVE_AS_TLS
29153 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
29154 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
29155 #endif
29156
29157 #ifdef SUBTARGET_INSERT_ATTRIBUTES
29158 #undef TARGET_INSERT_ATTRIBUTES
29159 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
29160 #endif
29161
29162 #undef TARGET_MANGLE_TYPE
29163 #define TARGET_MANGLE_TYPE ix86_mangle_type
29164
29165 #undef TARGET_STACK_PROTECT_FAIL
29166 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
29167
29168 #undef TARGET_FUNCTION_VALUE
29169 #define TARGET_FUNCTION_VALUE ix86_function_value
29170
29171 #undef TARGET_SECONDARY_RELOAD
29172 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
29173
29174 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
29175 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST x86_builtin_vectorization_cost
29176
29177 #undef TARGET_SET_CURRENT_FUNCTION
29178 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
29179
29180 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
29181 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
29182
29183 #undef TARGET_OPTION_SAVE
29184 #define TARGET_OPTION_SAVE ix86_function_specific_save
29185
29186 #undef TARGET_OPTION_RESTORE
29187 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
29188
29189 #undef TARGET_OPTION_PRINT
29190 #define TARGET_OPTION_PRINT ix86_function_specific_print
29191
29192 #undef TARGET_OPTION_CAN_INLINE_P
29193 #define TARGET_OPTION_CAN_INLINE_P ix86_can_inline_p
29194
29195 struct gcc_target targetm = TARGET_INITIALIZER;
29196 \f
29197 #include "gt-i386.h"