OSDN Git Service

8b73fca0c6f9e1a10a3c22013969b400e733053f
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.c
1 /* Subroutines used for code generation on IA-32.
2    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3    2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "tm_p.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "real.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "output.h"
35 #include "insn-codes.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "except.h"
39 #include "function.h"
40 #include "recog.h"
41 #include "expr.h"
42 #include "optabs.h"
43 #include "toplev.h"
44 #include "basic-block.h"
45 #include "ggc.h"
46 #include "target.h"
47 #include "target-def.h"
48 #include "langhooks.h"
49 #include "cgraph.h"
50 #include "gimple.h"
51 #include "dwarf2.h"
52 #include "df.h"
53 #include "tm-constrs.h"
54 #include "params.h"
55 #include "cselib.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 storing fp registers
995                                            in SFmode, DFmode and XFmode */
996   2,                                    /* cost of moving MMX register */
997   {6, 6},                               /* cost of loading MMX registers
998                                            in SImode and DImode */
999   {4, 4},                               /* cost of storing MMX registers
1000                                            in SImode and DImode */
1001   2,                                    /* cost of moving SSE register */
1002   {6, 6, 6},                            /* cost of loading SSE registers
1003                                            in SImode, DImode and TImode */
1004   {4, 4, 4},                            /* cost of storing SSE registers
1005                                            in SImode, DImode and TImode */
1006   2,                                    /* MMX or SSE register to integer */
1007   32,                                   /* size of l1 cache.  */
1008   2048,                                 /* size of l2 cache.  */
1009   128,                                  /* size of prefetch block */
1010   8,                                    /* number of parallel prefetches */
1011   3,                                    /* Branch cost */
1012   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
1013   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
1014   COSTS_N_INSNS (32),                   /* cost of FDIV instruction.  */
1015   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
1016   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
1017   COSTS_N_INSNS (58),                   /* cost of FSQRT instruction.  */
1018   {{libcall, {{11, loop}, {-1, rep_prefix_4_byte}}},
1019    {libcall, {{32, loop}, {64, rep_prefix_4_byte},
1020               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1021   {{libcall, {{8, loop}, {15, unrolled_loop},
1022               {2048, rep_prefix_4_byte}, {-1, libcall}}},
1023    {libcall, {{24, loop}, {32, unrolled_loop},
1024               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1025   1,                                    /* scalar_stmt_cost.  */
1026   1,                                    /* scalar load_cost.  */
1027   1,                                    /* scalar_store_cost.  */
1028   1,                                    /* vec_stmt_cost.  */
1029   1,                                    /* vec_to_scalar_cost.  */
1030   1,                                    /* scalar_to_vec_cost.  */
1031   1,                                    /* vec_align_load_cost.  */
1032   2,                                    /* vec_unalign_load_cost.  */
1033   1,                                    /* vec_store_cost.  */
1034   3,                                    /* cond_taken_branch_cost.  */
1035   1,                                    /* cond_not_taken_branch_cost.  */
1036 };
1037
1038 static const
1039 struct processor_costs atom_cost = {
1040   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1041   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1042   COSTS_N_INSNS (1),                    /* variable shift costs */
1043   COSTS_N_INSNS (1),                    /* constant shift costs */
1044   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1045    COSTS_N_INSNS (4),                   /*                               HI */
1046    COSTS_N_INSNS (3),                   /*                               SI */
1047    COSTS_N_INSNS (4),                   /*                               DI */
1048    COSTS_N_INSNS (2)},                  /*                               other */
1049   0,                                    /* cost of multiply per each bit set */
1050   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1051    COSTS_N_INSNS (26),                  /*                          HI */
1052    COSTS_N_INSNS (42),                  /*                          SI */
1053    COSTS_N_INSNS (74),                  /*                          DI */
1054    COSTS_N_INSNS (74)},                 /*                          other */
1055   COSTS_N_INSNS (1),                    /* cost of movsx */
1056   COSTS_N_INSNS (1),                    /* cost of movzx */
1057   8,                                    /* "large" insn */
1058   17,                                   /* MOVE_RATIO */
1059   2,                                    /* cost for loading QImode using movzbl */
1060   {4, 4, 4},                            /* cost of loading integer registers
1061                                            in QImode, HImode and SImode.
1062                                            Relative to reg-reg move (2).  */
1063   {4, 4, 4},                            /* cost of storing integer registers */
1064   4,                                    /* cost of reg,reg fld/fst */
1065   {12, 12, 12},                         /* cost of loading fp registers
1066                                            in SFmode, DFmode and XFmode */
1067   {6, 6, 8},                            /* cost of storing fp registers
1068                                            in SFmode, DFmode and XFmode */
1069   2,                                    /* cost of moving MMX register */
1070   {8, 8},                               /* cost of loading MMX registers
1071                                            in SImode and DImode */
1072   {8, 8},                               /* cost of storing MMX registers
1073                                            in SImode and DImode */
1074   2,                                    /* cost of moving SSE register */
1075   {8, 8, 8},                            /* cost of loading SSE registers
1076                                            in SImode, DImode and TImode */
1077   {8, 8, 8},                            /* cost of storing SSE registers
1078                                            in SImode, DImode and TImode */
1079   5,                                    /* MMX or SSE register to integer */
1080   32,                                   /* size of l1 cache.  */
1081   256,                                  /* size of l2 cache.  */
1082   64,                                   /* size of prefetch block */
1083   6,                                    /* number of parallel prefetches */
1084   3,                                    /* Branch cost */
1085   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1086   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1087   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1088   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1089   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1090   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1091   {{libcall, {{11, loop}, {-1, rep_prefix_4_byte}}},
1092    {libcall, {{32, loop}, {64, rep_prefix_4_byte},
1093           {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1094   {{libcall, {{8, loop}, {15, unrolled_loop},
1095           {2048, rep_prefix_4_byte}, {-1, libcall}}},
1096    {libcall, {{24, loop}, {32, unrolled_loop},
1097           {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1098   1,                                    /* scalar_stmt_cost.  */
1099   1,                                    /* scalar load_cost.  */
1100   1,                                    /* scalar_store_cost.  */
1101   1,                                    /* vec_stmt_cost.  */
1102   1,                                    /* vec_to_scalar_cost.  */
1103   1,                                    /* scalar_to_vec_cost.  */
1104   1,                                    /* vec_align_load_cost.  */
1105   2,                                    /* vec_unalign_load_cost.  */
1106   1,                                    /* vec_store_cost.  */
1107   3,                                    /* cond_taken_branch_cost.  */
1108   1,                                    /* cond_not_taken_branch_cost.  */
1109 };
1110
1111 /* Generic64 should produce code tuned for Nocona and K8.  */
1112 static const
1113 struct processor_costs generic64_cost = {
1114   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1115   /* On all chips taken into consideration lea is 2 cycles and more.  With
1116      this cost however our current implementation of synth_mult results in
1117      use of unnecessary temporary registers causing regression on several
1118      SPECfp benchmarks.  */
1119   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1120   COSTS_N_INSNS (1),                    /* variable shift costs */
1121   COSTS_N_INSNS (1),                    /* constant shift costs */
1122   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1123    COSTS_N_INSNS (4),                   /*                               HI */
1124    COSTS_N_INSNS (3),                   /*                               SI */
1125    COSTS_N_INSNS (4),                   /*                               DI */
1126    COSTS_N_INSNS (2)},                  /*                               other */
1127   0,                                    /* cost of multiply per each bit set */
1128   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1129    COSTS_N_INSNS (26),                  /*                          HI */
1130    COSTS_N_INSNS (42),                  /*                          SI */
1131    COSTS_N_INSNS (74),                  /*                          DI */
1132    COSTS_N_INSNS (74)},                 /*                          other */
1133   COSTS_N_INSNS (1),                    /* cost of movsx */
1134   COSTS_N_INSNS (1),                    /* cost of movzx */
1135   8,                                    /* "large" insn */
1136   17,                                   /* MOVE_RATIO */
1137   4,                                    /* cost for loading QImode using movzbl */
1138   {4, 4, 4},                            /* cost of loading integer registers
1139                                            in QImode, HImode and SImode.
1140                                            Relative to reg-reg move (2).  */
1141   {4, 4, 4},                            /* cost of storing integer registers */
1142   4,                                    /* cost of reg,reg fld/fst */
1143   {12, 12, 12},                         /* cost of loading fp registers
1144                                            in SFmode, DFmode and XFmode */
1145   {6, 6, 8},                            /* cost of storing fp registers
1146                                            in SFmode, DFmode and XFmode */
1147   2,                                    /* cost of moving MMX register */
1148   {8, 8},                               /* cost of loading MMX registers
1149                                            in SImode and DImode */
1150   {8, 8},                               /* cost of storing MMX registers
1151                                            in SImode and DImode */
1152   2,                                    /* cost of moving SSE register */
1153   {8, 8, 8},                            /* cost of loading SSE registers
1154                                            in SImode, DImode and TImode */
1155   {8, 8, 8},                            /* cost of storing SSE registers
1156                                            in SImode, DImode and TImode */
1157   5,                                    /* MMX or SSE register to integer */
1158   32,                                   /* size of l1 cache.  */
1159   512,                                  /* size of l2 cache.  */
1160   64,                                   /* size of prefetch block */
1161   6,                                    /* number of parallel prefetches */
1162   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this value
1163      is increased to perhaps more appropriate value of 5.  */
1164   3,                                    /* Branch cost */
1165   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1166   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1167   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1168   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1169   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1170   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1171   {DUMMY_STRINGOP_ALGS,
1172    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1173   {DUMMY_STRINGOP_ALGS,
1174    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1175   1,                                    /* scalar_stmt_cost.  */
1176   1,                                    /* scalar load_cost.  */
1177   1,                                    /* scalar_store_cost.  */
1178   1,                                    /* vec_stmt_cost.  */
1179   1,                                    /* vec_to_scalar_cost.  */
1180   1,                                    /* scalar_to_vec_cost.  */
1181   1,                                    /* vec_align_load_cost.  */
1182   2,                                    /* vec_unalign_load_cost.  */
1183   1,                                    /* vec_store_cost.  */
1184   3,                                    /* cond_taken_branch_cost.  */
1185   1,                                    /* cond_not_taken_branch_cost.  */
1186 };
1187
1188 /* Generic32 should produce code tuned for Athlon, PPro, Pentium4, Nocona and K8.  */
1189 static const
1190 struct processor_costs generic32_cost = {
1191   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1192   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1193   COSTS_N_INSNS (1),                    /* variable shift costs */
1194   COSTS_N_INSNS (1),                    /* constant shift costs */
1195   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1196    COSTS_N_INSNS (4),                   /*                               HI */
1197    COSTS_N_INSNS (3),                   /*                               SI */
1198    COSTS_N_INSNS (4),                   /*                               DI */
1199    COSTS_N_INSNS (2)},                  /*                               other */
1200   0,                                    /* cost of multiply per each bit set */
1201   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1202    COSTS_N_INSNS (26),                  /*                          HI */
1203    COSTS_N_INSNS (42),                  /*                          SI */
1204    COSTS_N_INSNS (74),                  /*                          DI */
1205    COSTS_N_INSNS (74)},                 /*                          other */
1206   COSTS_N_INSNS (1),                    /* cost of movsx */
1207   COSTS_N_INSNS (1),                    /* cost of movzx */
1208   8,                                    /* "large" insn */
1209   17,                                   /* MOVE_RATIO */
1210   4,                                    /* cost for loading QImode using movzbl */
1211   {4, 4, 4},                            /* cost of loading integer registers
1212                                            in QImode, HImode and SImode.
1213                                            Relative to reg-reg move (2).  */
1214   {4, 4, 4},                            /* cost of storing integer registers */
1215   4,                                    /* cost of reg,reg fld/fst */
1216   {12, 12, 12},                         /* cost of loading fp registers
1217                                            in SFmode, DFmode and XFmode */
1218   {6, 6, 8},                            /* cost of storing fp registers
1219                                            in SFmode, DFmode and XFmode */
1220   2,                                    /* cost of moving MMX register */
1221   {8, 8},                               /* cost of loading MMX registers
1222                                            in SImode and DImode */
1223   {8, 8},                               /* cost of storing MMX registers
1224                                            in SImode and DImode */
1225   2,                                    /* cost of moving SSE register */
1226   {8, 8, 8},                            /* cost of loading SSE registers
1227                                            in SImode, DImode and TImode */
1228   {8, 8, 8},                            /* cost of storing SSE registers
1229                                            in SImode, DImode and TImode */
1230   5,                                    /* MMX or SSE register to integer */
1231   32,                                   /* size of l1 cache.  */
1232   256,                                  /* size of l2 cache.  */
1233   64,                                   /* size of prefetch block */
1234   6,                                    /* number of parallel prefetches */
1235   3,                                    /* Branch cost */
1236   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1237   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1238   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1239   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1240   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1241   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1242   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1243    DUMMY_STRINGOP_ALGS},
1244   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1245    DUMMY_STRINGOP_ALGS},
1246   1,                                    /* scalar_stmt_cost.  */
1247   1,                                    /* scalar load_cost.  */
1248   1,                                    /* scalar_store_cost.  */
1249   1,                                    /* vec_stmt_cost.  */
1250   1,                                    /* vec_to_scalar_cost.  */
1251   1,                                    /* scalar_to_vec_cost.  */
1252   1,                                    /* vec_align_load_cost.  */
1253   2,                                    /* vec_unalign_load_cost.  */
1254   1,                                    /* vec_store_cost.  */
1255   3,                                    /* cond_taken_branch_cost.  */
1256   1,                                    /* cond_not_taken_branch_cost.  */
1257 };
1258
1259 const struct processor_costs *ix86_cost = &pentium_cost;
1260
1261 /* Processor feature/optimization bitmasks.  */
1262 #define m_386 (1<<PROCESSOR_I386)
1263 #define m_486 (1<<PROCESSOR_I486)
1264 #define m_PENT (1<<PROCESSOR_PENTIUM)
1265 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
1266 #define m_PENT4  (1<<PROCESSOR_PENTIUM4)
1267 #define m_NOCONA  (1<<PROCESSOR_NOCONA)
1268 #define m_CORE2  (1<<PROCESSOR_CORE2)
1269 #define m_ATOM  (1<<PROCESSOR_ATOM)
1270
1271 #define m_GEODE  (1<<PROCESSOR_GEODE)
1272 #define m_K6  (1<<PROCESSOR_K6)
1273 #define m_K6_GEODE  (m_K6 | m_GEODE)
1274 #define m_K8  (1<<PROCESSOR_K8)
1275 #define m_ATHLON  (1<<PROCESSOR_ATHLON)
1276 #define m_ATHLON_K8  (m_K8 | m_ATHLON)
1277 #define m_AMDFAM10  (1<<PROCESSOR_AMDFAM10)
1278 #define m_AMD_MULTIPLE  (m_K8 | m_ATHLON | m_AMDFAM10)
1279
1280 #define m_GENERIC32 (1<<PROCESSOR_GENERIC32)
1281 #define m_GENERIC64 (1<<PROCESSOR_GENERIC64)
1282
1283 /* Generic instruction choice should be common subset of supported CPUs
1284    (PPro/PENT4/NOCONA/CORE2/Athlon/K8).  */
1285 #define m_GENERIC (m_GENERIC32 | m_GENERIC64)
1286
1287 /* Feature tests against the various tunings.  */
1288 unsigned char ix86_tune_features[X86_TUNE_LAST];
1289
1290 /* Feature tests against the various tunings used to create ix86_tune_features
1291    based on the processor mask.  */
1292 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
1293   /* X86_TUNE_USE_LEAVE: Leave does not affect Nocona SPEC2000 results
1294      negatively, so enabling for Generic64 seems like good code size
1295      tradeoff.  We can't enable it for 32bit generic because it does not
1296      work well with PPro base chips.  */
1297   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_CORE2 | m_GENERIC64,
1298
1299   /* X86_TUNE_PUSH_MEMORY */
1300   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4
1301   | m_NOCONA | m_CORE2 | m_GENERIC,
1302
1303   /* X86_TUNE_ZERO_EXTEND_WITH_AND */
1304   m_486 | m_PENT,
1305
1306   /* X86_TUNE_UNROLL_STRLEN */
1307   m_486 | m_PENT | m_ATOM | m_PPRO | m_AMD_MULTIPLE | m_K6
1308   | m_CORE2 | m_GENERIC,
1309
1310   /* X86_TUNE_DEEP_BRANCH_PREDICTION */
1311   m_ATOM | m_PPRO | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4 | m_GENERIC,
1312
1313   /* X86_TUNE_BRANCH_PREDICTION_HINTS: Branch hints were put in P4 based
1314      on simulation result. But after P4 was made, no performance benefit
1315      was observed with branch hints.  It also increases the code size.
1316      As a result, icc never generates branch hints.  */
1317   0,
1318
1319   /* X86_TUNE_DOUBLE_WITH_ADD */
1320   ~m_386,
1321
1322   /* X86_TUNE_USE_SAHF */
1323   m_ATOM | m_PPRO | m_K6_GEODE | m_K8 | m_AMDFAM10 | m_PENT4
1324   | m_NOCONA | m_CORE2 | m_GENERIC,
1325
1326   /* X86_TUNE_MOVX: Enable to zero extend integer registers to avoid
1327      partial dependencies.  */
1328   m_AMD_MULTIPLE | m_ATOM | m_PPRO | m_PENT4 | m_NOCONA
1329   | m_CORE2 | m_GENERIC | m_GEODE /* m_386 | m_K6 */,
1330
1331   /* X86_TUNE_PARTIAL_REG_STALL: We probably ought to watch for partial
1332      register stalls on Generic32 compilation setting as well.  However
1333      in current implementation the partial register stalls are not eliminated
1334      very well - they can be introduced via subregs synthesized by combine
1335      and can happen in caller/callee saving sequences.  Because this option
1336      pays back little on PPro based chips and is in conflict with partial reg
1337      dependencies used by Athlon/P4 based chips, it is better to leave it off
1338      for generic32 for now.  */
1339   m_PPRO,
1340
1341   /* X86_TUNE_PARTIAL_FLAG_REG_STALL */
1342   m_CORE2 | m_GENERIC,
1343
1344   /* X86_TUNE_USE_HIMODE_FIOP */
1345   m_386 | m_486 | m_K6_GEODE,
1346
1347   /* X86_TUNE_USE_SIMODE_FIOP */
1348   ~(m_PPRO | m_AMD_MULTIPLE | m_PENT | m_ATOM | m_CORE2 | m_GENERIC),
1349
1350   /* X86_TUNE_USE_MOV0 */
1351   m_K6,
1352
1353   /* X86_TUNE_USE_CLTD */
1354   ~(m_PENT | m_ATOM | m_K6 | m_CORE2 | m_GENERIC),
1355
1356   /* X86_TUNE_USE_XCHGB: Use xchgb %rh,%rl instead of rolw/rorw $8,rx.  */
1357   m_PENT4,
1358
1359   /* X86_TUNE_SPLIT_LONG_MOVES */
1360   m_PPRO,
1361
1362   /* X86_TUNE_READ_MODIFY_WRITE */
1363   ~m_PENT,
1364
1365   /* X86_TUNE_READ_MODIFY */
1366   ~(m_PENT | m_PPRO),
1367
1368   /* X86_TUNE_PROMOTE_QIMODE */
1369   m_K6_GEODE | m_PENT | m_ATOM | m_386 | m_486 | m_AMD_MULTIPLE
1370   | m_CORE2 | m_GENERIC /* | m_PENT4 ? */,
1371
1372   /* X86_TUNE_FAST_PREFIX */
1373   ~(m_PENT | m_486 | m_386),
1374
1375   /* X86_TUNE_SINGLE_STRINGOP */
1376   m_386 | m_PENT4 | m_NOCONA,
1377
1378   /* X86_TUNE_QIMODE_MATH */
1379   ~0,
1380
1381   /* X86_TUNE_HIMODE_MATH: On PPro this flag is meant to avoid partial
1382      register stalls.  Just like X86_TUNE_PARTIAL_REG_STALL this option
1383      might be considered for Generic32 if our scheme for avoiding partial
1384      stalls was more effective.  */
1385   ~m_PPRO,
1386
1387   /* X86_TUNE_PROMOTE_QI_REGS */
1388   0,
1389
1390   /* X86_TUNE_PROMOTE_HI_REGS */
1391   m_PPRO,
1392
1393   /* X86_TUNE_ADD_ESP_4: Enable if add/sub is preferred over 1/2 push/pop.  */
1394   m_ATOM | m_AMD_MULTIPLE | m_K6_GEODE | m_PENT4 | m_NOCONA
1395   | m_CORE2 | m_GENERIC,
1396
1397   /* X86_TUNE_ADD_ESP_8 */
1398   m_AMD_MULTIPLE | m_ATOM | m_PPRO | m_K6_GEODE | m_386
1399   | m_486 | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1400
1401   /* X86_TUNE_SUB_ESP_4 */
1402   m_AMD_MULTIPLE | m_ATOM | m_PPRO | m_PENT4 | m_NOCONA | m_CORE2
1403   | m_GENERIC,
1404
1405   /* X86_TUNE_SUB_ESP_8 */
1406   m_AMD_MULTIPLE | m_ATOM | m_PPRO | m_386 | m_486
1407   | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1408
1409   /* X86_TUNE_INTEGER_DFMODE_MOVES: Enable if integer moves are preferred
1410      for DFmode copies */
1411   ~(m_AMD_MULTIPLE | m_ATOM | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2
1412     | m_GENERIC | m_GEODE),
1413
1414   /* X86_TUNE_PARTIAL_REG_DEPENDENCY */
1415   m_AMD_MULTIPLE | m_ATOM | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1416
1417   /* X86_TUNE_SSE_PARTIAL_REG_DEPENDENCY: In the Generic model we have a
1418      conflict here in between PPro/Pentium4 based chips that thread 128bit
1419      SSE registers as single units versus K8 based chips that divide SSE
1420      registers to two 64bit halves.  This knob promotes all store destinations
1421      to be 128bit to allow register renaming on 128bit SSE units, but usually
1422      results in one extra microop on 64bit SSE units.  Experimental results
1423      shows that disabling this option on P4 brings over 20% SPECfp regression,
1424      while enabling it on K8 brings roughly 2.4% regression that can be partly
1425      masked by careful scheduling of moves.  */
1426   m_ATOM | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC
1427   | m_AMDFAM10,
1428
1429   /* X86_TUNE_SSE_UNALIGNED_MOVE_OPTIMAL */
1430   m_AMDFAM10,
1431
1432   /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
1433      are resolved on SSE register parts instead of whole registers, so we may
1434      maintain just lower part of scalar values in proper format leaving the
1435      upper part undefined.  */
1436   m_ATHLON_K8,
1437
1438   /* X86_TUNE_SSE_TYPELESS_STORES */
1439   m_AMD_MULTIPLE,
1440
1441   /* X86_TUNE_SSE_LOAD0_BY_PXOR */
1442   m_PPRO | m_PENT4 | m_NOCONA,
1443
1444   /* X86_TUNE_MEMORY_MISMATCH_STALL */
1445   m_AMD_MULTIPLE | m_ATOM | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1446
1447   /* X86_TUNE_PROLOGUE_USING_MOVE */
1448   m_ATHLON_K8 | m_ATOM | m_PPRO | m_CORE2 | m_GENERIC,
1449
1450   /* X86_TUNE_EPILOGUE_USING_MOVE */
1451   m_ATHLON_K8 | m_ATOM | m_PPRO | m_CORE2 | m_GENERIC,
1452
1453   /* X86_TUNE_SHIFT1 */
1454   ~m_486,
1455
1456   /* X86_TUNE_USE_FFREEP */
1457   m_AMD_MULTIPLE,
1458
1459   /* X86_TUNE_INTER_UNIT_MOVES */
1460   ~(m_AMD_MULTIPLE | m_ATOM | m_GENERIC),
1461
1462   /* X86_TUNE_INTER_UNIT_CONVERSIONS */
1463   ~(m_AMDFAM10),
1464
1465   /* X86_TUNE_FOUR_JUMP_LIMIT: Some CPU cores are not able to predict more
1466      than 4 branch instructions in the 16 byte window.  */
1467   m_ATOM | m_PPRO | m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2
1468   | m_GENERIC,
1469
1470   /* X86_TUNE_SCHEDULE */
1471   m_PPRO | m_AMD_MULTIPLE | m_K6_GEODE | m_PENT | m_ATOM | m_CORE2
1472   | m_GENERIC,
1473
1474   /* X86_TUNE_USE_BT */
1475   m_AMD_MULTIPLE | m_ATOM | m_CORE2 | m_GENERIC,
1476
1477   /* X86_TUNE_USE_INCDEC */
1478   ~(m_PENT4 | m_NOCONA | m_GENERIC | m_ATOM),
1479
1480   /* X86_TUNE_PAD_RETURNS */
1481   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1482
1483   /* X86_TUNE_EXT_80387_CONSTANTS */
1484   m_K6_GEODE | m_ATHLON_K8 | m_ATOM | m_PENT4 | m_NOCONA | m_PPRO
1485   | m_CORE2 | m_GENERIC,
1486
1487   /* X86_TUNE_SHORTEN_X87_SSE */
1488   ~m_K8,
1489
1490   /* X86_TUNE_AVOID_VECTOR_DECODE */
1491   m_K8 | m_GENERIC64,
1492
1493   /* X86_TUNE_PROMOTE_HIMODE_IMUL: Modern CPUs have same latency for HImode
1494      and SImode multiply, but 386 and 486 do HImode multiply faster.  */
1495   ~(m_386 | m_486),
1496
1497   /* X86_TUNE_SLOW_IMUL_IMM32_MEM: Imul of 32-bit constant and memory is
1498      vector path on AMD machines.  */
1499   m_K8 | m_GENERIC64 | m_AMDFAM10,
1500
1501   /* X86_TUNE_SLOW_IMUL_IMM8: Imul of 8-bit constant is vector path on AMD
1502      machines.  */
1503   m_K8 | m_GENERIC64 | m_AMDFAM10,
1504
1505   /* X86_TUNE_MOVE_M1_VIA_OR: On pentiums, it is faster to load -1 via OR
1506      than a MOV.  */
1507   m_PENT,
1508
1509   /* X86_TUNE_NOT_UNPAIRABLE: NOT is not pairable on Pentium, while XOR is,
1510      but one byte longer.  */
1511   m_PENT,
1512
1513   /* X86_TUNE_NOT_VECTORMODE: On AMD K6, NOT is vector decoded with memory
1514      operand that cannot be represented using a modRM byte.  The XOR
1515      replacement is long decoded, so this split helps here as well.  */
1516   m_K6,
1517
1518   /* X86_TUNE_USE_VECTOR_FP_CONVERTS: Prefer vector packed SSE conversion
1519      from FP to FP. */
1520   m_AMDFAM10 | m_GENERIC,
1521
1522   /* X86_TUNE_USE_VECTOR_CONVERTS: Prefer vector packed SSE conversion
1523      from integer to FP. */
1524   m_AMDFAM10,
1525
1526   /* X86_TUNE_FUSE_CMP_AND_BRANCH: Fuse a compare or test instruction
1527      with a subsequent conditional jump instruction into a single
1528      compare-and-branch uop.  */
1529   m_CORE2,
1530
1531   /* X86_TUNE_OPT_AGU: Optimize for Address Generation Unit. This flag
1532      will impact LEA instruction selection. */
1533   m_ATOM,
1534 };
1535
1536 /* Feature tests against the various architecture variations.  */
1537 unsigned char ix86_arch_features[X86_ARCH_LAST];
1538
1539 /* Feature tests against the various architecture variations, used to create
1540    ix86_arch_features based on the processor mask.  */
1541 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
1542   /* X86_ARCH_CMOVE: Conditional move was added for pentiumpro.  */
1543   ~(m_386 | m_486 | m_PENT | m_K6),
1544
1545   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
1546   ~m_386,
1547
1548   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
1549   ~(m_386 | m_486),
1550
1551   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
1552   ~m_386,
1553
1554   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
1555   ~m_386,
1556 };
1557
1558 static const unsigned int x86_accumulate_outgoing_args
1559   = m_AMD_MULTIPLE | m_ATOM | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2
1560     | m_GENERIC;
1561
1562 static const unsigned int x86_arch_always_fancy_math_387
1563   = m_PENT | m_ATOM | m_PPRO | m_AMD_MULTIPLE | m_PENT4
1564     | m_NOCONA | m_CORE2 | m_GENERIC;
1565
1566 static enum stringop_alg stringop_alg = no_stringop;
1567
1568 /* In case the average insn count for single function invocation is
1569    lower than this constant, emit fast (but longer) prologue and
1570    epilogue code.  */
1571 #define FAST_PROLOGUE_INSN_COUNT 20
1572
1573 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
1574 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
1575 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
1576 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
1577
1578 /* Array of the smallest class containing reg number REGNO, indexed by
1579    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
1580
1581 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
1582 {
1583   /* ax, dx, cx, bx */
1584   AREG, DREG, CREG, BREG,
1585   /* si, di, bp, sp */
1586   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
1587   /* FP registers */
1588   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
1589   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
1590   /* arg pointer */
1591   NON_Q_REGS,
1592   /* flags, fpsr, fpcr, frame */
1593   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
1594   /* SSE registers */
1595   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1596   SSE_REGS, SSE_REGS,
1597   /* MMX registers */
1598   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
1599   MMX_REGS, MMX_REGS,
1600   /* REX registers */
1601   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1602   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1603   /* SSE REX registers */
1604   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1605   SSE_REGS, SSE_REGS,
1606 };
1607
1608 /* The "default" register map used in 32bit mode.  */
1609
1610 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
1611 {
1612   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
1613   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
1614   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1615   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
1616   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
1617   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1618   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1619 };
1620
1621 /* The "default" register map used in 64bit mode.  */
1622
1623 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
1624 {
1625   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
1626   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
1627   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1628   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
1629   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
1630   8,9,10,11,12,13,14,15,                /* extended integer registers */
1631   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
1632 };
1633
1634 /* Define the register numbers to be used in Dwarf debugging information.
1635    The SVR4 reference port C compiler uses the following register numbers
1636    in its Dwarf output code:
1637         0 for %eax (gcc regno = 0)
1638         1 for %ecx (gcc regno = 2)
1639         2 for %edx (gcc regno = 1)
1640         3 for %ebx (gcc regno = 3)
1641         4 for %esp (gcc regno = 7)
1642         5 for %ebp (gcc regno = 6)
1643         6 for %esi (gcc regno = 4)
1644         7 for %edi (gcc regno = 5)
1645    The following three DWARF register numbers are never generated by
1646    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
1647    believes these numbers have these meanings.
1648         8  for %eip    (no gcc equivalent)
1649         9  for %eflags (gcc regno = 17)
1650         10 for %trapno (no gcc equivalent)
1651    It is not at all clear how we should number the FP stack registers
1652    for the x86 architecture.  If the version of SDB on x86/svr4 were
1653    a bit less brain dead with respect to floating-point then we would
1654    have a precedent to follow with respect to DWARF register numbers
1655    for x86 FP registers, but the SDB on x86/svr4 is so completely
1656    broken with respect to FP registers that it is hardly worth thinking
1657    of it as something to strive for compatibility with.
1658    The version of x86/svr4 SDB I have at the moment does (partially)
1659    seem to believe that DWARF register number 11 is associated with
1660    the x86 register %st(0), but that's about all.  Higher DWARF
1661    register numbers don't seem to be associated with anything in
1662    particular, and even for DWARF regno 11, SDB only seems to under-
1663    stand that it should say that a variable lives in %st(0) (when
1664    asked via an `=' command) if we said it was in DWARF regno 11,
1665    but SDB still prints garbage when asked for the value of the
1666    variable in question (via a `/' command).
1667    (Also note that the labels SDB prints for various FP stack regs
1668    when doing an `x' command are all wrong.)
1669    Note that these problems generally don't affect the native SVR4
1670    C compiler because it doesn't allow the use of -O with -g and
1671    because when it is *not* optimizing, it allocates a memory
1672    location for each floating-point variable, and the memory
1673    location is what gets described in the DWARF AT_location
1674    attribute for the variable in question.
1675    Regardless of the severe mental illness of the x86/svr4 SDB, we
1676    do something sensible here and we use the following DWARF
1677    register numbers.  Note that these are all stack-top-relative
1678    numbers.
1679         11 for %st(0) (gcc regno = 8)
1680         12 for %st(1) (gcc regno = 9)
1681         13 for %st(2) (gcc regno = 10)
1682         14 for %st(3) (gcc regno = 11)
1683         15 for %st(4) (gcc regno = 12)
1684         16 for %st(5) (gcc regno = 13)
1685         17 for %st(6) (gcc regno = 14)
1686         18 for %st(7) (gcc regno = 15)
1687 */
1688 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
1689 {
1690   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
1691   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
1692   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
1693   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
1694   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
1695   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1696   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1697 };
1698
1699 /* Test and compare insns in i386.md store the information needed to
1700    generate branch and scc insns here.  */
1701
1702 rtx ix86_compare_op0 = NULL_RTX;
1703 rtx ix86_compare_op1 = NULL_RTX;
1704
1705 /* Define parameter passing and return registers.  */
1706
1707 static int const x86_64_int_parameter_registers[6] =
1708 {
1709   DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
1710 };
1711
1712 static int const x86_64_ms_abi_int_parameter_registers[4] =
1713 {
1714   CX_REG, DX_REG, R8_REG, R9_REG
1715 };
1716
1717 static int const x86_64_int_return_registers[4] =
1718 {
1719   AX_REG, DX_REG, DI_REG, SI_REG
1720 };
1721
1722 /* Define the structure for the machine field in struct function.  */
1723
1724 struct GTY(()) stack_local_entry {
1725   unsigned short mode;
1726   unsigned short n;
1727   rtx rtl;
1728   struct stack_local_entry *next;
1729 };
1730
1731 /* Structure describing stack frame layout.
1732    Stack grows downward:
1733
1734    [arguments]
1735                                               <- ARG_POINTER
1736    saved pc
1737
1738    saved frame pointer if frame_pointer_needed
1739                                               <- HARD_FRAME_POINTER
1740    [saved regs]
1741
1742    [padding0]
1743
1744    [saved SSE regs]
1745
1746    [padding1]          \
1747                         )
1748    [va_arg registers]  (
1749                         > to_allocate         <- FRAME_POINTER
1750    [frame]             (
1751                         )
1752    [padding2]          /
1753   */
1754 struct ix86_frame
1755 {
1756   int padding0;
1757   int nsseregs;
1758   int nregs;
1759   int padding1;
1760   int va_arg_size;
1761   HOST_WIDE_INT frame;
1762   int padding2;
1763   int outgoing_arguments_size;
1764   int red_zone_size;
1765
1766   HOST_WIDE_INT to_allocate;
1767   /* The offsets relative to ARG_POINTER.  */
1768   HOST_WIDE_INT frame_pointer_offset;
1769   HOST_WIDE_INT hard_frame_pointer_offset;
1770   HOST_WIDE_INT stack_pointer_offset;
1771
1772   /* When save_regs_using_mov is set, emit prologue using
1773      move instead of push instructions.  */
1774   bool save_regs_using_mov;
1775 };
1776
1777 /* Code model option.  */
1778 enum cmodel ix86_cmodel;
1779 /* Asm dialect.  */
1780 enum asm_dialect ix86_asm_dialect = ASM_ATT;
1781 /* TLS dialects.  */
1782 enum tls_dialect ix86_tls_dialect = TLS_DIALECT_GNU;
1783
1784 /* Which unit we are generating floating point math for.  */
1785 enum fpmath_unit ix86_fpmath;
1786
1787 /* Which cpu are we scheduling for.  */
1788 enum attr_cpu ix86_schedule;
1789
1790 /* Which cpu are we optimizing for.  */
1791 enum processor_type ix86_tune;
1792
1793 /* Which instruction set architecture to use.  */
1794 enum processor_type ix86_arch;
1795
1796 /* true if sse prefetch instruction is not NOOP.  */
1797 int x86_prefetch_sse;
1798
1799 /* ix86_regparm_string as a number */
1800 static int ix86_regparm;
1801
1802 /* -mstackrealign option */
1803 extern int ix86_force_align_arg_pointer;
1804 static const char ix86_force_align_arg_pointer_string[]
1805   = "force_align_arg_pointer";
1806
1807 static rtx (*ix86_gen_leave) (void);
1808 static rtx (*ix86_gen_pop1) (rtx);
1809 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
1810 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
1811 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx);
1812 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
1813 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
1814 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
1815
1816 /* Preferred alignment for stack boundary in bits.  */
1817 unsigned int ix86_preferred_stack_boundary;
1818
1819 /* Alignment for incoming stack boundary in bits specified at
1820    command line.  */
1821 static unsigned int ix86_user_incoming_stack_boundary;
1822
1823 /* Default alignment for incoming stack boundary in bits.  */
1824 static unsigned int ix86_default_incoming_stack_boundary;
1825
1826 /* Alignment for incoming stack boundary in bits.  */
1827 unsigned int ix86_incoming_stack_boundary;
1828
1829 /* The abi used by target.  */
1830 enum calling_abi ix86_abi;
1831
1832 /* Values 1-5: see jump.c */
1833 int ix86_branch_cost;
1834
1835 /* Calling abi specific va_list type nodes.  */
1836 static GTY(()) tree sysv_va_list_type_node;
1837 static GTY(()) tree ms_va_list_type_node;
1838
1839 /* Variables which are this size or smaller are put in the data/bss
1840    or ldata/lbss sections.  */
1841
1842 int ix86_section_threshold = 65536;
1843
1844 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
1845 char internal_label_prefix[16];
1846 int internal_label_prefix_len;
1847
1848 /* Fence to use after loop using movnt.  */
1849 tree x86_mfence;
1850
1851 /* Register class used for passing given 64bit part of the argument.
1852    These represent classes as documented by the PS ABI, with the exception
1853    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
1854    use SF or DFmode move instead of DImode to avoid reformatting penalties.
1855
1856    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
1857    whenever possible (upper half does contain padding).  */
1858 enum x86_64_reg_class
1859   {
1860     X86_64_NO_CLASS,
1861     X86_64_INTEGER_CLASS,
1862     X86_64_INTEGERSI_CLASS,
1863     X86_64_SSE_CLASS,
1864     X86_64_SSESF_CLASS,
1865     X86_64_SSEDF_CLASS,
1866     X86_64_SSEUP_CLASS,
1867     X86_64_X87_CLASS,
1868     X86_64_X87UP_CLASS,
1869     X86_64_COMPLEX_X87_CLASS,
1870     X86_64_MEMORY_CLASS
1871   };
1872
1873 #define MAX_CLASSES 4
1874
1875 /* Table of constants used by fldpi, fldln2, etc....  */
1876 static REAL_VALUE_TYPE ext_80387_constants_table [5];
1877 static bool ext_80387_constants_init = 0;
1878
1879 \f
1880 static struct machine_function * ix86_init_machine_status (void);
1881 static rtx ix86_function_value (const_tree, const_tree, bool);
1882 static int ix86_function_regparm (const_tree, const_tree);
1883 static void ix86_compute_frame_layout (struct ix86_frame *);
1884 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
1885                                                  rtx, rtx, int);
1886 static void ix86_add_new_builtins (int);
1887
1888 enum ix86_function_specific_strings
1889 {
1890   IX86_FUNCTION_SPECIFIC_ARCH,
1891   IX86_FUNCTION_SPECIFIC_TUNE,
1892   IX86_FUNCTION_SPECIFIC_FPMATH,
1893   IX86_FUNCTION_SPECIFIC_MAX
1894 };
1895
1896 static char *ix86_target_string (int, int, const char *, const char *,
1897                                  const char *, bool);
1898 static void ix86_debug_options (void) ATTRIBUTE_UNUSED;
1899 static void ix86_function_specific_save (struct cl_target_option *);
1900 static void ix86_function_specific_restore (struct cl_target_option *);
1901 static void ix86_function_specific_print (FILE *, int,
1902                                           struct cl_target_option *);
1903 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
1904 static bool ix86_valid_target_attribute_inner_p (tree, char *[]);
1905 static bool ix86_can_inline_p (tree, tree);
1906 static void ix86_set_current_function (tree);
1907
1908 static enum calling_abi ix86_function_abi (const_tree);
1909
1910 \f
1911 /* The svr4 ABI for the i386 says that records and unions are returned
1912    in memory.  */
1913 #ifndef DEFAULT_PCC_STRUCT_RETURN
1914 #define DEFAULT_PCC_STRUCT_RETURN 1
1915 #endif
1916
1917 /* Whether -mtune= or -march= were specified */
1918 static int ix86_tune_defaulted;
1919 static int ix86_arch_specified;
1920
1921 /* Bit flags that specify the ISA we are compiling for.  */
1922 int ix86_isa_flags = TARGET_64BIT_DEFAULT | TARGET_SUBTARGET_ISA_DEFAULT;
1923
1924 /* A mask of ix86_isa_flags that includes bit X if X
1925    was set or cleared on the command line.  */
1926 static int ix86_isa_flags_explicit;
1927
1928 /* Define a set of ISAs which are available when a given ISA is
1929    enabled.  MMX and SSE ISAs are handled separately.  */
1930
1931 #define OPTION_MASK_ISA_MMX_SET OPTION_MASK_ISA_MMX
1932 #define OPTION_MASK_ISA_3DNOW_SET \
1933   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX_SET)
1934
1935 #define OPTION_MASK_ISA_SSE_SET OPTION_MASK_ISA_SSE
1936 #define OPTION_MASK_ISA_SSE2_SET \
1937   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE_SET)
1938 #define OPTION_MASK_ISA_SSE3_SET \
1939   (OPTION_MASK_ISA_SSE3 | OPTION_MASK_ISA_SSE2_SET)
1940 #define OPTION_MASK_ISA_SSSE3_SET \
1941   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE3_SET)
1942 #define OPTION_MASK_ISA_SSE4_1_SET \
1943   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSSE3_SET)
1944 #define OPTION_MASK_ISA_SSE4_2_SET \
1945   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_SSE4_1_SET)
1946 #define OPTION_MASK_ISA_AVX_SET \
1947   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_SSE4_2_SET)
1948 #define OPTION_MASK_ISA_FMA_SET \
1949   (OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_AVX_SET)
1950
1951 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
1952    as -msse4.2.  */
1953 #define OPTION_MASK_ISA_SSE4_SET OPTION_MASK_ISA_SSE4_2_SET
1954
1955 #define OPTION_MASK_ISA_SSE4A_SET \
1956   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE3_SET)
1957 #define OPTION_MASK_ISA_SSE5_SET \
1958   (OPTION_MASK_ISA_SSE5 | OPTION_MASK_ISA_SSE4A_SET)
1959
1960 /* AES and PCLMUL need SSE2 because they use xmm registers */
1961 #define OPTION_MASK_ISA_AES_SET \
1962   (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2_SET)
1963 #define OPTION_MASK_ISA_PCLMUL_SET \
1964   (OPTION_MASK_ISA_PCLMUL | OPTION_MASK_ISA_SSE2_SET)
1965
1966 #define OPTION_MASK_ISA_ABM_SET \
1967   (OPTION_MASK_ISA_ABM | OPTION_MASK_ISA_POPCNT)
1968
1969 #define OPTION_MASK_ISA_POPCNT_SET OPTION_MASK_ISA_POPCNT
1970 #define OPTION_MASK_ISA_CX16_SET OPTION_MASK_ISA_CX16
1971 #define OPTION_MASK_ISA_SAHF_SET OPTION_MASK_ISA_SAHF
1972 #define OPTION_MASK_ISA_MOVBE_SET OPTION_MASK_ISA_MOVBE
1973 #define OPTION_MASK_ISA_CRC32_SET OPTION_MASK_ISA_CRC32
1974
1975 /* Define a set of ISAs which aren't available when a given ISA is
1976    disabled.  MMX and SSE ISAs are handled separately.  */
1977
1978 #define OPTION_MASK_ISA_MMX_UNSET \
1979   (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_3DNOW_UNSET)
1980 #define OPTION_MASK_ISA_3DNOW_UNSET \
1981   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_A_UNSET)
1982 #define OPTION_MASK_ISA_3DNOW_A_UNSET OPTION_MASK_ISA_3DNOW_A
1983
1984 #define OPTION_MASK_ISA_SSE_UNSET \
1985   (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_SSE2_UNSET)
1986 #define OPTION_MASK_ISA_SSE2_UNSET \
1987   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3_UNSET)
1988 #define OPTION_MASK_ISA_SSE3_UNSET \
1989   (OPTION_MASK_ISA_SSE3 \
1990    | OPTION_MASK_ISA_SSSE3_UNSET \
1991    | OPTION_MASK_ISA_SSE4A_UNSET )
1992 #define OPTION_MASK_ISA_SSSE3_UNSET \
1993   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE4_1_UNSET)
1994 #define OPTION_MASK_ISA_SSE4_1_UNSET \
1995   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_2_UNSET)
1996 #define OPTION_MASK_ISA_SSE4_2_UNSET \
1997   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_AVX_UNSET )
1998 #define OPTION_MASK_ISA_AVX_UNSET \
1999   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_FMA_UNSET)
2000 #define OPTION_MASK_ISA_FMA_UNSET OPTION_MASK_ISA_FMA
2001
2002 /* SSE4 includes both SSE4.1 and SSE4.2.  -mno-sse4 should the same
2003    as -mno-sse4.1. */
2004 #define OPTION_MASK_ISA_SSE4_UNSET OPTION_MASK_ISA_SSE4_1_UNSET
2005
2006 #define OPTION_MASK_ISA_SSE4A_UNSET \
2007   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE5_UNSET)
2008 #define OPTION_MASK_ISA_SSE5_UNSET OPTION_MASK_ISA_SSE5
2009 #define OPTION_MASK_ISA_AES_UNSET OPTION_MASK_ISA_AES
2010 #define OPTION_MASK_ISA_PCLMUL_UNSET OPTION_MASK_ISA_PCLMUL
2011 #define OPTION_MASK_ISA_ABM_UNSET OPTION_MASK_ISA_ABM
2012 #define OPTION_MASK_ISA_POPCNT_UNSET OPTION_MASK_ISA_POPCNT
2013 #define OPTION_MASK_ISA_CX16_UNSET OPTION_MASK_ISA_CX16
2014 #define OPTION_MASK_ISA_SAHF_UNSET OPTION_MASK_ISA_SAHF
2015 #define OPTION_MASK_ISA_MOVBE_UNSET OPTION_MASK_ISA_MOVBE
2016 #define OPTION_MASK_ISA_CRC32_UNSET OPTION_MASK_ISA_CRC32
2017
2018 /* Vectorization library interface and handlers.  */
2019 tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL;
2020 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
2021 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
2022
2023 /* Processor target table, indexed by processor number */
2024 struct ptt
2025 {
2026   const struct processor_costs *cost;           /* Processor costs */
2027   const int align_loop;                         /* Default alignments.  */
2028   const int align_loop_max_skip;
2029   const int align_jump;
2030   const int align_jump_max_skip;
2031   const int align_func;
2032 };
2033
2034 static const struct ptt processor_target_table[PROCESSOR_max] =
2035 {
2036   {&i386_cost, 4, 3, 4, 3, 4},
2037   {&i486_cost, 16, 15, 16, 15, 16},
2038   {&pentium_cost, 16, 7, 16, 7, 16},
2039   {&pentiumpro_cost, 16, 15, 16, 10, 16},
2040   {&geode_cost, 0, 0, 0, 0, 0},
2041   {&k6_cost, 32, 7, 32, 7, 32},
2042   {&athlon_cost, 16, 7, 16, 7, 16},
2043   {&pentium4_cost, 0, 0, 0, 0, 0},
2044   {&k8_cost, 16, 7, 16, 7, 16},
2045   {&nocona_cost, 0, 0, 0, 0, 0},
2046   {&core2_cost, 16, 10, 16, 10, 16},
2047   {&generic32_cost, 16, 7, 16, 7, 16},
2048   {&generic64_cost, 16, 10, 16, 10, 16},
2049   {&amdfam10_cost, 32, 24, 32, 7, 32},
2050   {&atom_cost, 16, 7, 16, 7, 16}
2051 };
2052
2053 static const char *const cpu_names[TARGET_CPU_DEFAULT_max] =
2054 {
2055   "generic",
2056   "i386",
2057   "i486",
2058   "pentium",
2059   "pentium-mmx",
2060   "pentiumpro",
2061   "pentium2",
2062   "pentium3",
2063   "pentium4",
2064   "pentium-m",
2065   "prescott",
2066   "nocona",
2067   "core2",
2068   "atom",
2069   "geode",
2070   "k6",
2071   "k6-2",
2072   "k6-3",
2073   "athlon",
2074   "athlon-4",
2075   "k8",
2076   "amdfam10"
2077 };
2078 \f
2079 /* Implement TARGET_HANDLE_OPTION.  */
2080
2081 static bool
2082 ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value)
2083 {
2084   switch (code)
2085     {
2086     case OPT_mmmx:
2087       if (value)
2088         {
2089           ix86_isa_flags |= OPTION_MASK_ISA_MMX_SET;
2090           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_SET;
2091         }
2092       else
2093         {
2094           ix86_isa_flags &= ~OPTION_MASK_ISA_MMX_UNSET;
2095           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_UNSET;
2096         }
2097       return true;
2098
2099     case OPT_m3dnow:
2100       if (value)
2101         {
2102           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_SET;
2103           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_SET;
2104         }
2105       else
2106         {
2107           ix86_isa_flags &= ~OPTION_MASK_ISA_3DNOW_UNSET;
2108           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_UNSET;
2109         }
2110       return true;
2111
2112     case OPT_m3dnowa:
2113       return false;
2114
2115     case OPT_msse:
2116       if (value)
2117         {
2118           ix86_isa_flags |= OPTION_MASK_ISA_SSE_SET;
2119           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_SET;
2120         }
2121       else
2122         {
2123           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE_UNSET;
2124           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_UNSET;
2125         }
2126       return true;
2127
2128     case OPT_msse2:
2129       if (value)
2130         {
2131           ix86_isa_flags |= OPTION_MASK_ISA_SSE2_SET;
2132           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_SET;
2133         }
2134       else
2135         {
2136           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE2_UNSET;
2137           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_UNSET;
2138         }
2139       return true;
2140
2141     case OPT_msse3:
2142       if (value)
2143         {
2144           ix86_isa_flags |= OPTION_MASK_ISA_SSE3_SET;
2145           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_SET;
2146         }
2147       else
2148         {
2149           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE3_UNSET;
2150           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_UNSET;
2151         }
2152       return true;
2153
2154     case OPT_mssse3:
2155       if (value)
2156         {
2157           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3_SET;
2158           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_SET;
2159         }
2160       else
2161         {
2162           ix86_isa_flags &= ~OPTION_MASK_ISA_SSSE3_UNSET;
2163           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_UNSET;
2164         }
2165       return true;
2166
2167     case OPT_msse4_1:
2168       if (value)
2169         {
2170           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1_SET;
2171           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_SET;
2172         }
2173       else
2174         {
2175           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_1_UNSET;
2176           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_UNSET;
2177         }
2178       return true;
2179
2180     case OPT_msse4_2:
2181       if (value)
2182         {
2183           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2_SET;
2184           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_SET;
2185         }
2186       else
2187         {
2188           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_2_UNSET;
2189           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_UNSET;
2190         }
2191       return true;
2192
2193     case OPT_mavx:
2194       if (value)
2195         {
2196           ix86_isa_flags |= OPTION_MASK_ISA_AVX_SET;
2197           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_SET;
2198         }
2199       else
2200         {
2201           ix86_isa_flags &= ~OPTION_MASK_ISA_AVX_UNSET;
2202           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_UNSET;
2203         }
2204       return true;
2205
2206     case OPT_mfma:
2207       if (value)
2208         {
2209           ix86_isa_flags |= OPTION_MASK_ISA_FMA_SET;
2210           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_SET;
2211         }
2212       else
2213         {
2214           ix86_isa_flags &= ~OPTION_MASK_ISA_FMA_UNSET;
2215           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_UNSET;
2216         }
2217       return true;
2218
2219     case OPT_msse4:
2220       ix86_isa_flags |= OPTION_MASK_ISA_SSE4_SET;
2221       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_SET;
2222       return true;
2223
2224     case OPT_mno_sse4:
2225       ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
2226       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
2227       return true;
2228
2229     case OPT_msse4a:
2230       if (value)
2231         {
2232           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A_SET;
2233           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_SET;
2234         }
2235       else
2236         {
2237           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4A_UNSET;
2238           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_UNSET;
2239         }
2240       return true;
2241
2242     case OPT_msse5:
2243       if (value)
2244         {
2245           ix86_isa_flags |= OPTION_MASK_ISA_SSE5_SET;
2246           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_SET;
2247         }
2248       else
2249         {
2250           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE5_UNSET;
2251           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_UNSET;
2252         }
2253       return true;
2254
2255     case OPT_mabm:
2256       if (value)
2257         {
2258           ix86_isa_flags |= OPTION_MASK_ISA_ABM_SET;
2259           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_SET;
2260         }
2261       else
2262         {
2263           ix86_isa_flags &= ~OPTION_MASK_ISA_ABM_UNSET;
2264           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_UNSET;
2265         }
2266       return true;
2267
2268     case OPT_mpopcnt:
2269       if (value)
2270         {
2271           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT_SET;
2272           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_SET;
2273         }
2274       else
2275         {
2276           ix86_isa_flags &= ~OPTION_MASK_ISA_POPCNT_UNSET;
2277           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_UNSET;
2278         }
2279       return true;
2280
2281     case OPT_msahf:
2282       if (value)
2283         {
2284           ix86_isa_flags |= OPTION_MASK_ISA_SAHF_SET;
2285           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_SET;
2286         }
2287       else
2288         {
2289           ix86_isa_flags &= ~OPTION_MASK_ISA_SAHF_UNSET;
2290           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_UNSET;
2291         }
2292       return true;
2293
2294     case OPT_mcx16:
2295       if (value)
2296         {
2297           ix86_isa_flags |= OPTION_MASK_ISA_CX16_SET;
2298           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_SET;
2299         }
2300       else
2301         {
2302           ix86_isa_flags &= ~OPTION_MASK_ISA_CX16_UNSET;
2303           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_UNSET;
2304         }
2305       return true;
2306
2307     case OPT_mmovbe:
2308       if (value)
2309         {
2310           ix86_isa_flags |= OPTION_MASK_ISA_MOVBE_SET;
2311           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MOVBE_SET;
2312         }
2313       else
2314         {
2315           ix86_isa_flags &= ~OPTION_MASK_ISA_MOVBE_UNSET;
2316           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MOVBE_UNSET;
2317         }
2318       return true;
2319
2320     case OPT_mcrc32:
2321       if (value)
2322         {
2323           ix86_isa_flags |= OPTION_MASK_ISA_CRC32_SET;
2324           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CRC32_SET;
2325         }
2326       else
2327         {
2328           ix86_isa_flags &= ~OPTION_MASK_ISA_CRC32_UNSET;
2329           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CRC32_UNSET;
2330         }
2331       return true;
2332
2333     case OPT_maes:
2334       if (value)
2335         {
2336           ix86_isa_flags |= OPTION_MASK_ISA_AES_SET;
2337           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_SET;
2338         }
2339       else
2340         {
2341           ix86_isa_flags &= ~OPTION_MASK_ISA_AES_UNSET;
2342           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_UNSET;
2343         }
2344       return true;
2345
2346     case OPT_mpclmul:
2347       if (value)
2348         {
2349           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL_SET;
2350           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_SET;
2351         }
2352       else
2353         {
2354           ix86_isa_flags &= ~OPTION_MASK_ISA_PCLMUL_UNSET;
2355           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_UNSET;
2356         }
2357       return true;
2358
2359     default:
2360       return true;
2361     }
2362 }
2363 \f
2364 /* Return a string the documents the current -m options.  The caller is
2365    responsible for freeing the string.  */
2366
2367 static char *
2368 ix86_target_string (int isa, int flags, const char *arch, const char *tune,
2369                     const char *fpmath, bool add_nl_p)
2370 {
2371   struct ix86_target_opts
2372   {
2373     const char *option;         /* option string */
2374     int mask;                   /* isa mask options */
2375   };
2376
2377   /* This table is ordered so that options like -msse5 or -msse4.2 that imply
2378      preceding options while match those first.  */
2379   static struct ix86_target_opts isa_opts[] =
2380   {
2381     { "-m64",           OPTION_MASK_ISA_64BIT },
2382     { "-msse5",         OPTION_MASK_ISA_SSE5 },
2383     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2384     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2385     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2386     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2387     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2388     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2389     { "-msse",          OPTION_MASK_ISA_SSE },
2390     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2391     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2392     { "-mmmx",          OPTION_MASK_ISA_MMX },
2393     { "-mabm",          OPTION_MASK_ISA_ABM },
2394     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2395     { "-mmovbe",        OPTION_MASK_ISA_MOVBE },
2396     { "-mcrc32",        OPTION_MASK_ISA_CRC32 },
2397     { "-maes",          OPTION_MASK_ISA_AES },
2398     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2399   };
2400
2401   /* Flag options.  */
2402   static struct ix86_target_opts flag_opts[] =
2403   {
2404     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2405     { "-m80387",                        MASK_80387 },
2406     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2407     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2408     { "-mcld",                          MASK_CLD },
2409     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2410     { "-mieee-fp",                      MASK_IEEE_FP },
2411     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2412     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2413     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2414     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2415     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2416     { "-mno-fused-madd",                MASK_NO_FUSED_MADD },
2417     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2418     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2419     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2420     { "-mrecip",                        MASK_RECIP },
2421     { "-mrtd",                          MASK_RTD },
2422     { "-msseregparm",                   MASK_SSEREGPARM },
2423     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2424     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2425   };
2426
2427   const char *opts[ARRAY_SIZE (isa_opts) + ARRAY_SIZE (flag_opts) + 6][2];
2428
2429   char isa_other[40];
2430   char target_other[40];
2431   unsigned num = 0;
2432   unsigned i, j;
2433   char *ret;
2434   char *ptr;
2435   size_t len;
2436   size_t line_len;
2437   size_t sep_len;
2438
2439   memset (opts, '\0', sizeof (opts));
2440
2441   /* Add -march= option.  */
2442   if (arch)
2443     {
2444       opts[num][0] = "-march=";
2445       opts[num++][1] = arch;
2446     }
2447
2448   /* Add -mtune= option.  */
2449   if (tune)
2450     {
2451       opts[num][0] = "-mtune=";
2452       opts[num++][1] = tune;
2453     }
2454
2455   /* Pick out the options in isa options.  */
2456   for (i = 0; i < ARRAY_SIZE (isa_opts); i++)
2457     {
2458       if ((isa & isa_opts[i].mask) != 0)
2459         {
2460           opts[num++][0] = isa_opts[i].option;
2461           isa &= ~ isa_opts[i].mask;
2462         }
2463     }
2464
2465   if (isa && add_nl_p)
2466     {
2467       opts[num++][0] = isa_other;
2468       sprintf (isa_other, "(other isa: 0x%x)", isa);
2469     }
2470
2471   /* Add flag options.  */
2472   for (i = 0; i < ARRAY_SIZE (flag_opts); i++)
2473     {
2474       if ((flags & flag_opts[i].mask) != 0)
2475         {
2476           opts[num++][0] = flag_opts[i].option;
2477           flags &= ~ flag_opts[i].mask;
2478         }
2479     }
2480
2481   if (flags && add_nl_p)
2482     {
2483       opts[num++][0] = target_other;
2484       sprintf (target_other, "(other flags: 0x%x)", isa);
2485     }
2486
2487   /* Add -fpmath= option.  */
2488   if (fpmath)
2489     {
2490       opts[num][0] = "-mfpmath=";
2491       opts[num++][1] = fpmath;
2492     }
2493
2494   /* Any options?  */
2495   if (num == 0)
2496     return NULL;
2497
2498   gcc_assert (num < ARRAY_SIZE (opts));
2499
2500   /* Size the string.  */
2501   len = 0;
2502   sep_len = (add_nl_p) ? 3 : 1;
2503   for (i = 0; i < num; i++)
2504     {
2505       len += sep_len;
2506       for (j = 0; j < 2; j++)
2507         if (opts[i][j])
2508           len += strlen (opts[i][j]);
2509     }
2510
2511   /* Build the string.  */
2512   ret = ptr = (char *) xmalloc (len);
2513   line_len = 0;
2514
2515   for (i = 0; i < num; i++)
2516     {
2517       size_t len2[2];
2518
2519       for (j = 0; j < 2; j++)
2520         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2521
2522       if (i != 0)
2523         {
2524           *ptr++ = ' ';
2525           line_len++;
2526
2527           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2528             {
2529               *ptr++ = '\\';
2530               *ptr++ = '\n';
2531               line_len = 0;
2532             }
2533         }
2534
2535       for (j = 0; j < 2; j++)
2536         if (opts[i][j])
2537           {
2538             memcpy (ptr, opts[i][j], len2[j]);
2539             ptr += len2[j];
2540             line_len += len2[j];
2541           }
2542     }
2543
2544   *ptr = '\0';
2545   gcc_assert (ret + len >= ptr);
2546
2547   return ret;
2548 }
2549
2550 /* Function that is callable from the debugger to print the current
2551    options.  */
2552 void
2553 ix86_debug_options (void)
2554 {
2555   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2556                                    ix86_arch_string, ix86_tune_string,
2557                                    ix86_fpmath_string, true);
2558
2559   if (opts)
2560     {
2561       fprintf (stderr, "%s\n\n", opts);
2562       free (opts);
2563     }
2564   else
2565     fputs ("<no options>\n\n", stderr);
2566
2567   return;
2568 }
2569 \f
2570 /* Sometimes certain combinations of command options do not make
2571    sense on a particular target machine.  You can define a macro
2572    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
2573    defined, is executed once just after all the command options have
2574    been parsed.
2575
2576    Don't use this macro to turn on various extra optimizations for
2577    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
2578
2579 void
2580 override_options (bool main_args_p)
2581 {
2582   int i;
2583   unsigned int ix86_arch_mask, ix86_tune_mask;
2584   const char *prefix;
2585   const char *suffix;
2586   const char *sw;
2587
2588   /* Comes from final.c -- no real reason to change it.  */
2589 #define MAX_CODE_ALIGN 16
2590
2591   enum pta_flags
2592     {
2593       PTA_SSE = 1 << 0,
2594       PTA_SSE2 = 1 << 1,
2595       PTA_SSE3 = 1 << 2,
2596       PTA_MMX = 1 << 3,
2597       PTA_PREFETCH_SSE = 1 << 4,
2598       PTA_3DNOW = 1 << 5,
2599       PTA_3DNOW_A = 1 << 6,
2600       PTA_64BIT = 1 << 7,
2601       PTA_SSSE3 = 1 << 8,
2602       PTA_CX16 = 1 << 9,
2603       PTA_POPCNT = 1 << 10,
2604       PTA_ABM = 1 << 11,
2605       PTA_SSE4A = 1 << 12,
2606       PTA_NO_SAHF = 1 << 13,
2607       PTA_SSE4_1 = 1 << 14,
2608       PTA_SSE4_2 = 1 << 15,
2609       PTA_SSE5 = 1 << 16,
2610       PTA_AES = 1 << 17,
2611       PTA_PCLMUL = 1 << 18,
2612       PTA_AVX = 1 << 19,
2613       PTA_FMA = 1 << 20,
2614       PTA_MOVBE = 1 << 21
2615     };
2616
2617   static struct pta
2618     {
2619       const char *const name;           /* processor name or nickname.  */
2620       const enum processor_type processor;
2621       const enum attr_cpu schedule;
2622       const unsigned /*enum pta_flags*/ flags;
2623     }
2624   const processor_alias_table[] =
2625     {
2626       {"i386", PROCESSOR_I386, CPU_NONE, 0},
2627       {"i486", PROCESSOR_I486, CPU_NONE, 0},
2628       {"i586", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
2629       {"pentium", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
2630       {"pentium-mmx", PROCESSOR_PENTIUM, CPU_PENTIUM, PTA_MMX},
2631       {"winchip-c6", PROCESSOR_I486, CPU_NONE, PTA_MMX},
2632       {"winchip2", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW},
2633       {"c3", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW},
2634       {"c3-2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX | PTA_SSE},
2635       {"i686", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
2636       {"pentiumpro", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
2637       {"pentium2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX},
2638       {"pentium3", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2639         PTA_MMX | PTA_SSE},
2640       {"pentium3m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2641         PTA_MMX | PTA_SSE},
2642       {"pentium-m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2643         PTA_MMX | PTA_SSE | PTA_SSE2},
2644       {"pentium4", PROCESSOR_PENTIUM4, CPU_NONE,
2645         PTA_MMX |PTA_SSE | PTA_SSE2},
2646       {"pentium4m", PROCESSOR_PENTIUM4, CPU_NONE,
2647         PTA_MMX | PTA_SSE | PTA_SSE2},
2648       {"prescott", PROCESSOR_NOCONA, CPU_NONE,
2649         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3},
2650       {"nocona", PROCESSOR_NOCONA, CPU_NONE,
2651         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2652         | PTA_CX16 | PTA_NO_SAHF},
2653       {"core2", PROCESSOR_CORE2, CPU_CORE2,
2654         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2655         | PTA_SSSE3 | PTA_CX16},
2656       {"atom", PROCESSOR_ATOM, CPU_ATOM,
2657         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2658         | PTA_SSSE3 | PTA_CX16 | PTA_MOVBE},
2659       {"geode", PROCESSOR_GEODE, CPU_GEODE,
2660         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A |PTA_PREFETCH_SSE},
2661       {"k6", PROCESSOR_K6, CPU_K6, PTA_MMX},
2662       {"k6-2", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW},
2663       {"k6-3", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW},
2664       {"athlon", PROCESSOR_ATHLON, CPU_ATHLON,
2665         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE},
2666       {"athlon-tbird", PROCESSOR_ATHLON, CPU_ATHLON,
2667         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE},
2668       {"athlon-4", PROCESSOR_ATHLON, CPU_ATHLON,
2669         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2670       {"athlon-xp", PROCESSOR_ATHLON, CPU_ATHLON,
2671         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2672       {"athlon-mp", PROCESSOR_ATHLON, CPU_ATHLON,
2673         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2674       {"x86-64", PROCESSOR_K8, CPU_K8,
2675         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_NO_SAHF},
2676       {"k8", PROCESSOR_K8, CPU_K8,
2677         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2678         | PTA_SSE2 | PTA_NO_SAHF},
2679       {"k8-sse3", PROCESSOR_K8, CPU_K8,
2680         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2681         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2682       {"opteron", PROCESSOR_K8, CPU_K8,
2683         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2684         | PTA_SSE2 | PTA_NO_SAHF},
2685       {"opteron-sse3", PROCESSOR_K8, CPU_K8,
2686         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2687         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2688       {"athlon64", PROCESSOR_K8, CPU_K8,
2689         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2690         | PTA_SSE2 | PTA_NO_SAHF},
2691       {"athlon64-sse3", PROCESSOR_K8, CPU_K8,
2692         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2693         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2694       {"athlon-fx", PROCESSOR_K8, CPU_K8,
2695         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2696         | PTA_SSE2 | PTA_NO_SAHF},
2697       {"amdfam10", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
2698         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2699         | PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM},
2700       {"barcelona", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
2701         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2702         | PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM},
2703       {"generic32", PROCESSOR_GENERIC32, CPU_PENTIUMPRO,
2704         0 /* flags are only used for -march switch.  */ },
2705       {"generic64", PROCESSOR_GENERIC64, CPU_GENERIC64,
2706         PTA_64BIT /* flags are only used for -march switch.  */ },
2707     };
2708
2709   int const pta_size = ARRAY_SIZE (processor_alias_table);
2710
2711   /* Set up prefix/suffix so the error messages refer to either the command
2712      line argument, or the attribute(target).  */
2713   if (main_args_p)
2714     {
2715       prefix = "-m";
2716       suffix = "";
2717       sw = "switch";
2718     }
2719   else
2720     {
2721       prefix = "option(\"";
2722       suffix = "\")";
2723       sw = "attribute";
2724     }
2725
2726 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2727   SUBTARGET_OVERRIDE_OPTIONS;
2728 #endif
2729
2730 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2731   SUBSUBTARGET_OVERRIDE_OPTIONS;
2732 #endif
2733
2734   /* -fPIC is the default for x86_64.  */
2735   if (TARGET_MACHO && TARGET_64BIT)
2736     flag_pic = 2;
2737
2738   /* Set the default values for switches whose default depends on TARGET_64BIT
2739      in case they weren't overwritten by command line options.  */
2740   if (TARGET_64BIT)
2741     {
2742       /* Mach-O doesn't support omitting the frame pointer for now.  */
2743       if (flag_omit_frame_pointer == 2)
2744         flag_omit_frame_pointer = (TARGET_MACHO ? 0 : 1);
2745       if (flag_asynchronous_unwind_tables == 2)
2746         flag_asynchronous_unwind_tables = 1;
2747       if (flag_pcc_struct_return == 2)
2748         flag_pcc_struct_return = 0;
2749     }
2750   else
2751     {
2752       if (flag_omit_frame_pointer == 2)
2753         flag_omit_frame_pointer = 0;
2754       if (flag_asynchronous_unwind_tables == 2)
2755         flag_asynchronous_unwind_tables = 0;
2756       if (flag_pcc_struct_return == 2)
2757         flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
2758     }
2759
2760   /* Need to check -mtune=generic first.  */
2761   if (ix86_tune_string)
2762     {
2763       if (!strcmp (ix86_tune_string, "generic")
2764           || !strcmp (ix86_tune_string, "i686")
2765           /* As special support for cross compilers we read -mtune=native
2766              as -mtune=generic.  With native compilers we won't see the
2767              -mtune=native, as it was changed by the driver.  */
2768           || !strcmp (ix86_tune_string, "native"))
2769         {
2770           if (TARGET_64BIT)
2771             ix86_tune_string = "generic64";
2772           else
2773             ix86_tune_string = "generic32";
2774         }
2775       /* If this call is for setting the option attribute, allow the
2776          generic32/generic64 that was previously set.  */
2777       else if (!main_args_p
2778                && (!strcmp (ix86_tune_string, "generic32")
2779                    || !strcmp (ix86_tune_string, "generic64")))
2780         ;
2781       else if (!strncmp (ix86_tune_string, "generic", 7))
2782         error ("bad value (%s) for %stune=%s %s",
2783                ix86_tune_string, prefix, suffix, sw);
2784     }
2785   else
2786     {
2787       if (ix86_arch_string)
2788         ix86_tune_string = ix86_arch_string;
2789       if (!ix86_tune_string)
2790         {
2791           ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT];
2792           ix86_tune_defaulted = 1;
2793         }
2794
2795       /* ix86_tune_string is set to ix86_arch_string or defaulted.  We
2796          need to use a sensible tune option.  */
2797       if (!strcmp (ix86_tune_string, "generic")
2798           || !strcmp (ix86_tune_string, "x86-64")
2799           || !strcmp (ix86_tune_string, "i686"))
2800         {
2801           if (TARGET_64BIT)
2802             ix86_tune_string = "generic64";
2803           else
2804             ix86_tune_string = "generic32";
2805         }
2806     }
2807   if (ix86_stringop_string)
2808     {
2809       if (!strcmp (ix86_stringop_string, "rep_byte"))
2810         stringop_alg = rep_prefix_1_byte;
2811       else if (!strcmp (ix86_stringop_string, "libcall"))
2812         stringop_alg = libcall;
2813       else if (!strcmp (ix86_stringop_string, "rep_4byte"))
2814         stringop_alg = rep_prefix_4_byte;
2815       else if (!strcmp (ix86_stringop_string, "rep_8byte")
2816                && TARGET_64BIT)
2817         /* rep; movq isn't available in 32-bit code.  */
2818         stringop_alg = rep_prefix_8_byte;
2819       else if (!strcmp (ix86_stringop_string, "byte_loop"))
2820         stringop_alg = loop_1_byte;
2821       else if (!strcmp (ix86_stringop_string, "loop"))
2822         stringop_alg = loop;
2823       else if (!strcmp (ix86_stringop_string, "unrolled_loop"))
2824         stringop_alg = unrolled_loop;
2825       else
2826         error ("bad value (%s) for %sstringop-strategy=%s %s",
2827                ix86_stringop_string, prefix, suffix, sw);
2828     }
2829   if (!strcmp (ix86_tune_string, "x86-64"))
2830     warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated.  Use "
2831              "%stune=k8%s or %stune=generic%s instead as appropriate.",
2832              prefix, suffix, prefix, suffix, prefix, suffix);
2833
2834   if (!ix86_arch_string)
2835     ix86_arch_string = TARGET_64BIT ? "x86-64" : "i386";
2836   else
2837     ix86_arch_specified = 1;
2838
2839   if (!strcmp (ix86_arch_string, "generic"))
2840     error ("generic CPU can be used only for %stune=%s %s",
2841            prefix, suffix, sw);
2842   if (!strncmp (ix86_arch_string, "generic", 7))
2843     error ("bad value (%s) for %sarch=%s %s",
2844            ix86_arch_string, prefix, suffix, sw);
2845
2846   /* Validate -mabi= value.  */
2847   if (ix86_abi_string)
2848     {
2849       if (strcmp (ix86_abi_string, "sysv") == 0)
2850         ix86_abi = SYSV_ABI;
2851       else if (strcmp (ix86_abi_string, "ms") == 0)
2852         ix86_abi = MS_ABI;
2853       else
2854         error ("unknown ABI (%s) for %sabi=%s %s",
2855                ix86_abi_string, prefix, suffix, sw);
2856     }
2857   else
2858     ix86_abi = DEFAULT_ABI;
2859
2860   if (ix86_cmodel_string != 0)
2861     {
2862       if (!strcmp (ix86_cmodel_string, "small"))
2863         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2864       else if (!strcmp (ix86_cmodel_string, "medium"))
2865         ix86_cmodel = flag_pic ? CM_MEDIUM_PIC : CM_MEDIUM;
2866       else if (!strcmp (ix86_cmodel_string, "large"))
2867         ix86_cmodel = flag_pic ? CM_LARGE_PIC : CM_LARGE;
2868       else if (flag_pic)
2869         error ("code model %s does not support PIC mode", ix86_cmodel_string);
2870       else if (!strcmp (ix86_cmodel_string, "32"))
2871         ix86_cmodel = CM_32;
2872       else if (!strcmp (ix86_cmodel_string, "kernel") && !flag_pic)
2873         ix86_cmodel = CM_KERNEL;
2874       else
2875         error ("bad value (%s) for %scmodel=%s %s",
2876                ix86_cmodel_string, prefix, suffix, sw);
2877     }
2878   else
2879     {
2880       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
2881          use of rip-relative addressing.  This eliminates fixups that
2882          would otherwise be needed if this object is to be placed in a
2883          DLL, and is essentially just as efficient as direct addressing.  */
2884       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
2885         ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
2886       else if (TARGET_64BIT)
2887         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2888       else
2889         ix86_cmodel = CM_32;
2890     }
2891   if (ix86_asm_string != 0)
2892     {
2893       if (! TARGET_MACHO
2894           && !strcmp (ix86_asm_string, "intel"))
2895         ix86_asm_dialect = ASM_INTEL;
2896       else if (!strcmp (ix86_asm_string, "att"))
2897         ix86_asm_dialect = ASM_ATT;
2898       else
2899         error ("bad value (%s) for %sasm=%s %s",
2900                ix86_asm_string, prefix, suffix, sw);
2901     }
2902   if ((TARGET_64BIT == 0) != (ix86_cmodel == CM_32))
2903     error ("code model %qs not supported in the %s bit mode",
2904            ix86_cmodel_string, TARGET_64BIT ? "64" : "32");
2905   if ((TARGET_64BIT != 0) != ((ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2906     sorry ("%i-bit mode not compiled in",
2907            (ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2908
2909   for (i = 0; i < pta_size; i++)
2910     if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
2911       {
2912         ix86_schedule = processor_alias_table[i].schedule;
2913         ix86_arch = processor_alias_table[i].processor;
2914         /* Default cpu tuning to the architecture.  */
2915         ix86_tune = ix86_arch;
2916
2917         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2918           error ("CPU you selected does not support x86-64 "
2919                  "instruction set");
2920
2921         if (processor_alias_table[i].flags & PTA_MMX
2922             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
2923           ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2924         if (processor_alias_table[i].flags & PTA_3DNOW
2925             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
2926           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
2927         if (processor_alias_table[i].flags & PTA_3DNOW_A
2928             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
2929           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
2930         if (processor_alias_table[i].flags & PTA_SSE
2931             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
2932           ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2933         if (processor_alias_table[i].flags & PTA_SSE2
2934             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
2935           ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2936         if (processor_alias_table[i].flags & PTA_SSE3
2937             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
2938           ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2939         if (processor_alias_table[i].flags & PTA_SSSE3
2940             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
2941           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2942         if (processor_alias_table[i].flags & PTA_SSE4_1
2943             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
2944           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2945         if (processor_alias_table[i].flags & PTA_SSE4_2
2946             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
2947           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
2948         if (processor_alias_table[i].flags & PTA_AVX
2949             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
2950           ix86_isa_flags |= OPTION_MASK_ISA_AVX;
2951         if (processor_alias_table[i].flags & PTA_FMA
2952             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
2953           ix86_isa_flags |= OPTION_MASK_ISA_FMA;
2954         if (processor_alias_table[i].flags & PTA_SSE4A
2955             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
2956           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2957         if (processor_alias_table[i].flags & PTA_SSE5
2958             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE5))
2959           ix86_isa_flags |= OPTION_MASK_ISA_SSE5;
2960         if (processor_alias_table[i].flags & PTA_ABM
2961             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
2962           ix86_isa_flags |= OPTION_MASK_ISA_ABM;
2963         if (processor_alias_table[i].flags & PTA_CX16
2964             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
2965           ix86_isa_flags |= OPTION_MASK_ISA_CX16;
2966         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
2967             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
2968           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
2969         if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF))
2970             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
2971           ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
2972         if (processor_alias_table[i].flags & PTA_MOVBE
2973             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MOVBE))
2974           ix86_isa_flags |= OPTION_MASK_ISA_MOVBE;
2975         if (processor_alias_table[i].flags & PTA_AES
2976             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
2977           ix86_isa_flags |= OPTION_MASK_ISA_AES;
2978         if (processor_alias_table[i].flags & PTA_PCLMUL
2979             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
2980           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
2981         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
2982           x86_prefetch_sse = true;
2983
2984         break;
2985       }
2986
2987   if (i == pta_size)
2988     error ("bad value (%s) for %sarch=%s %s",
2989            ix86_arch_string, prefix, suffix, sw);
2990
2991   ix86_arch_mask = 1u << ix86_arch;
2992   for (i = 0; i < X86_ARCH_LAST; ++i)
2993     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
2994
2995   for (i = 0; i < pta_size; i++)
2996     if (! strcmp (ix86_tune_string, processor_alias_table[i].name))
2997       {
2998         ix86_schedule = processor_alias_table[i].schedule;
2999         ix86_tune = processor_alias_table[i].processor;
3000         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
3001           {
3002             if (ix86_tune_defaulted)
3003               {
3004                 ix86_tune_string = "x86-64";
3005                 for (i = 0; i < pta_size; i++)
3006                   if (! strcmp (ix86_tune_string,
3007                                 processor_alias_table[i].name))
3008                     break;
3009                 ix86_schedule = processor_alias_table[i].schedule;
3010                 ix86_tune = processor_alias_table[i].processor;
3011               }
3012             else
3013               error ("CPU you selected does not support x86-64 "
3014                      "instruction set");
3015           }
3016         /* Intel CPUs have always interpreted SSE prefetch instructions as
3017            NOPs; so, we can enable SSE prefetch instructions even when
3018            -mtune (rather than -march) points us to a processor that has them.
3019            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
3020            higher processors.  */
3021         if (TARGET_CMOVE
3022             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
3023           x86_prefetch_sse = true;
3024         break;
3025       }
3026   if (i == pta_size)
3027     error ("bad value (%s) for %stune=%s %s",
3028            ix86_tune_string, prefix, suffix, sw);
3029
3030   ix86_tune_mask = 1u << ix86_tune;
3031   for (i = 0; i < X86_TUNE_LAST; ++i)
3032     ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3033
3034   if (optimize_size)
3035     ix86_cost = &ix86_size_cost;
3036   else
3037     ix86_cost = processor_target_table[ix86_tune].cost;
3038
3039   /* Arrange to set up i386_stack_locals for all functions.  */
3040   init_machine_status = ix86_init_machine_status;
3041
3042   /* Validate -mregparm= value.  */
3043   if (ix86_regparm_string)
3044     {
3045       if (TARGET_64BIT)
3046         warning (0, "%sregparm%s is ignored in 64-bit mode", prefix, suffix);
3047       i = atoi (ix86_regparm_string);
3048       if (i < 0 || i > REGPARM_MAX)
3049         error ("%sregparm=%d%s is not between 0 and %d",
3050                prefix, i, suffix, REGPARM_MAX);
3051       else
3052         ix86_regparm = i;
3053     }
3054   if (TARGET_64BIT)
3055     ix86_regparm = REGPARM_MAX;
3056
3057   /* If the user has provided any of the -malign-* options,
3058      warn and use that value only if -falign-* is not set.
3059      Remove this code in GCC 3.2 or later.  */
3060   if (ix86_align_loops_string)
3061     {
3062       warning (0, "%salign-loops%s is obsolete, use -falign-loops%s",
3063                prefix, suffix, suffix);
3064       if (align_loops == 0)
3065         {
3066           i = atoi (ix86_align_loops_string);
3067           if (i < 0 || i > MAX_CODE_ALIGN)
3068             error ("%salign-loops=%d%s is not between 0 and %d",
3069                    prefix, i, suffix, MAX_CODE_ALIGN);
3070           else
3071             align_loops = 1 << i;
3072         }
3073     }
3074
3075   if (ix86_align_jumps_string)
3076     {
3077       warning (0, "%salign-jumps%s is obsolete, use -falign-jumps%s",
3078                prefix, suffix, suffix);
3079       if (align_jumps == 0)
3080         {
3081           i = atoi (ix86_align_jumps_string);
3082           if (i < 0 || i > MAX_CODE_ALIGN)
3083             error ("%salign-loops=%d%s is not between 0 and %d",
3084                    prefix, i, suffix, MAX_CODE_ALIGN);
3085           else
3086             align_jumps = 1 << i;
3087         }
3088     }
3089
3090   if (ix86_align_funcs_string)
3091     {
3092       warning (0, "%salign-functions%s is obsolete, use -falign-functions%s",
3093                prefix, suffix, suffix);
3094       if (align_functions == 0)
3095         {
3096           i = atoi (ix86_align_funcs_string);
3097           if (i < 0 || i > MAX_CODE_ALIGN)
3098             error ("%salign-loops=%d%s is not between 0 and %d",
3099                    prefix, i, suffix, MAX_CODE_ALIGN);
3100           else
3101             align_functions = 1 << i;
3102         }
3103     }
3104
3105   /* Default align_* from the processor table.  */
3106   if (align_loops == 0)
3107     {
3108       align_loops = processor_target_table[ix86_tune].align_loop;
3109       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
3110     }
3111   if (align_jumps == 0)
3112     {
3113       align_jumps = processor_target_table[ix86_tune].align_jump;
3114       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
3115     }
3116   if (align_functions == 0)
3117     {
3118       align_functions = processor_target_table[ix86_tune].align_func;
3119     }
3120
3121   /* Validate -mbranch-cost= value, or provide default.  */
3122   ix86_branch_cost = ix86_cost->branch_cost;
3123   if (ix86_branch_cost_string)
3124     {
3125       i = atoi (ix86_branch_cost_string);
3126       if (i < 0 || i > 5)
3127         error ("%sbranch-cost=%d%s is not between 0 and 5", prefix, i, suffix);
3128       else
3129         ix86_branch_cost = i;
3130     }
3131   if (ix86_section_threshold_string)
3132     {
3133       i = atoi (ix86_section_threshold_string);
3134       if (i < 0)
3135         error ("%slarge-data-threshold=%d%s is negative", prefix, i, suffix);
3136       else
3137         ix86_section_threshold = i;
3138     }
3139
3140   if (ix86_tls_dialect_string)
3141     {
3142       if (strcmp (ix86_tls_dialect_string, "gnu") == 0)
3143         ix86_tls_dialect = TLS_DIALECT_GNU;
3144       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
3145         ix86_tls_dialect = TLS_DIALECT_GNU2;
3146       else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
3147         ix86_tls_dialect = TLS_DIALECT_SUN;
3148       else
3149         error ("bad value (%s) for %stls-dialect=%s %s",
3150                ix86_tls_dialect_string, prefix, suffix, sw);
3151     }
3152
3153   if (ix87_precision_string)
3154     {
3155       i = atoi (ix87_precision_string);
3156       if (i != 32 && i != 64 && i != 80)
3157         error ("pc%d is not valid precision setting (32, 64 or 80)", i);
3158     }
3159
3160   if (TARGET_64BIT)
3161     {
3162       target_flags |= TARGET_SUBTARGET64_DEFAULT & ~target_flags_explicit;
3163
3164       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3165          explicitly disable any of these.  In particular, disabling SSE and
3166          MMX for kernel code is extremely useful.  */
3167       if (!ix86_arch_specified)
3168       ix86_isa_flags
3169         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3170              | TARGET_SUBTARGET64_ISA_DEFAULT) & ~ix86_isa_flags_explicit);
3171
3172       if (TARGET_RTD)
3173         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3174     }
3175   else
3176     {
3177       target_flags |= TARGET_SUBTARGET32_DEFAULT & ~target_flags_explicit;
3178
3179       if (!ix86_arch_specified)
3180       ix86_isa_flags
3181         |= TARGET_SUBTARGET32_ISA_DEFAULT & ~ix86_isa_flags_explicit;
3182
3183       /* i386 ABI does not specify red zone.  It still makes sense to use it
3184          when programmer takes care to stack from being destroyed.  */
3185       if (!(target_flags_explicit & MASK_NO_RED_ZONE))
3186         target_flags |= MASK_NO_RED_ZONE;
3187     }
3188
3189   /* Keep nonleaf frame pointers.  */
3190   if (flag_omit_frame_pointer)
3191     target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3192   else if (TARGET_OMIT_LEAF_FRAME_POINTER)
3193     flag_omit_frame_pointer = 1;
3194
3195   /* If we're doing fast math, we don't care about comparison order
3196      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3197   if (flag_finite_math_only)
3198     target_flags &= ~MASK_IEEE_FP;
3199
3200   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3201      since the insns won't need emulation.  */
3202   if (x86_arch_always_fancy_math_387 & ix86_arch_mask)
3203     target_flags &= ~MASK_NO_FANCY_MATH_387;
3204
3205   /* Likewise, if the target doesn't have a 387, or we've specified
3206      software floating point, don't use 387 inline intrinsics.  */
3207   if (!TARGET_80387)
3208     target_flags |= MASK_NO_FANCY_MATH_387;
3209
3210   /* Turn on MMX builtins for -msse.  */
3211   if (TARGET_SSE)
3212     {
3213       ix86_isa_flags |= OPTION_MASK_ISA_MMX & ~ix86_isa_flags_explicit;
3214       x86_prefetch_sse = true;
3215     }
3216
3217   /* Turn on popcnt instruction for -msse4.2 or -mabm.  */
3218   if (TARGET_SSE4_2 || TARGET_ABM)
3219     ix86_isa_flags |= OPTION_MASK_ISA_POPCNT & ~ix86_isa_flags_explicit;
3220
3221   /* Validate -mpreferred-stack-boundary= value or default it to
3222      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
3223   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
3224   if (ix86_preferred_stack_boundary_string)
3225     {
3226       i = atoi (ix86_preferred_stack_boundary_string);
3227       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3228         error ("%spreferred-stack-boundary=%d%s is not between %d and 12",
3229                prefix, i, suffix, TARGET_64BIT ? 4 : 2);
3230       else
3231         ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
3232     }
3233
3234   /* Set the default value for -mstackrealign.  */
3235   if (ix86_force_align_arg_pointer == -1)
3236     ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
3237
3238   /* Validate -mincoming-stack-boundary= value or default it to
3239      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
3240   if (ix86_force_align_arg_pointer)
3241     ix86_default_incoming_stack_boundary = MIN_STACK_BOUNDARY;
3242   else
3243     ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
3244   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
3245   if (ix86_incoming_stack_boundary_string)
3246     {
3247       i = atoi (ix86_incoming_stack_boundary_string);
3248       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3249         error ("-mincoming-stack-boundary=%d is not between %d and 12",
3250                i, TARGET_64BIT ? 4 : 2);
3251       else
3252         {
3253           ix86_user_incoming_stack_boundary = (1 << i) * BITS_PER_UNIT;
3254           ix86_incoming_stack_boundary
3255             = ix86_user_incoming_stack_boundary;
3256         }
3257     }
3258
3259   /* Accept -msseregparm only if at least SSE support is enabled.  */
3260   if (TARGET_SSEREGPARM
3261       && ! TARGET_SSE)
3262     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
3263
3264   ix86_fpmath = TARGET_FPMATH_DEFAULT;
3265   if (ix86_fpmath_string != 0)
3266     {
3267       if (! strcmp (ix86_fpmath_string, "387"))
3268         ix86_fpmath = FPMATH_387;
3269       else if (! strcmp (ix86_fpmath_string, "sse"))
3270         {
3271           if (!TARGET_SSE)
3272             {
3273               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3274               ix86_fpmath = FPMATH_387;
3275             }
3276           else
3277             ix86_fpmath = FPMATH_SSE;
3278         }
3279       else if (! strcmp (ix86_fpmath_string, "387,sse")
3280                || ! strcmp (ix86_fpmath_string, "387+sse")
3281                || ! strcmp (ix86_fpmath_string, "sse,387")
3282                || ! strcmp (ix86_fpmath_string, "sse+387")
3283                || ! strcmp (ix86_fpmath_string, "both"))
3284         {
3285           if (!TARGET_SSE)
3286             {
3287               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3288               ix86_fpmath = FPMATH_387;
3289             }
3290           else if (!TARGET_80387)
3291             {
3292               warning (0, "387 instruction set disabled, using SSE arithmetics");
3293               ix86_fpmath = FPMATH_SSE;
3294             }
3295           else
3296             ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
3297         }
3298       else
3299         error ("bad value (%s) for %sfpmath=%s %s",
3300                ix86_fpmath_string, prefix, suffix, sw);
3301     }
3302
3303   /* If the i387 is disabled, then do not return values in it. */
3304   if (!TARGET_80387)
3305     target_flags &= ~MASK_FLOAT_RETURNS;
3306
3307   /* Use external vectorized library in vectorizing intrinsics.  */
3308   if (ix86_veclibabi_string)
3309     {
3310       if (strcmp (ix86_veclibabi_string, "svml") == 0)
3311         ix86_veclib_handler = ix86_veclibabi_svml;
3312       else if (strcmp (ix86_veclibabi_string, "acml") == 0)
3313         ix86_veclib_handler = ix86_veclibabi_acml;
3314       else
3315         error ("unknown vectorization library ABI type (%s) for "
3316                "%sveclibabi=%s %s", ix86_veclibabi_string,
3317                prefix, suffix, sw);
3318     }
3319
3320   if ((x86_accumulate_outgoing_args & ix86_tune_mask)
3321       && !(target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3322       && !optimize_size)
3323     target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3324
3325   /* ??? Unwind info is not correct around the CFG unless either a frame
3326      pointer is present or M_A_O_A is set.  Fixing this requires rewriting
3327      unwind info generation to be aware of the CFG and propagating states
3328      around edges.  */
3329   if ((flag_unwind_tables || flag_asynchronous_unwind_tables
3330        || flag_exceptions || flag_non_call_exceptions)
3331       && flag_omit_frame_pointer
3332       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3333     {
3334       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3335         warning (0, "unwind tables currently require either a frame pointer "
3336                  "or %saccumulate-outgoing-args%s for correctness",
3337                  prefix, suffix);
3338       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3339     }
3340
3341   /* If stack probes are required, the space used for large function
3342      arguments on the stack must also be probed, so enable
3343      -maccumulate-outgoing-args so this happens in the prologue.  */
3344   if (TARGET_STACK_PROBE
3345       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3346     {
3347       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3348         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
3349                  "for correctness", prefix, suffix);
3350       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3351     }
3352
3353   /* For sane SSE instruction set generation we need fcomi instruction.
3354      It is safe to enable all CMOVE instructions.  */
3355   if (TARGET_SSE)
3356     TARGET_CMOVE = 1;
3357
3358   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
3359   {
3360     char *p;
3361     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
3362     p = strchr (internal_label_prefix, 'X');
3363     internal_label_prefix_len = p - internal_label_prefix;
3364     *p = '\0';
3365   }
3366
3367   /* When scheduling description is not available, disable scheduler pass
3368      so it won't slow down the compilation and make x87 code slower.  */
3369   if (!TARGET_SCHEDULE)
3370     flag_schedule_insns_after_reload = flag_schedule_insns = 0;
3371
3372   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
3373     set_param_value ("simultaneous-prefetches",
3374                      ix86_cost->simultaneous_prefetches);
3375   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
3376     set_param_value ("l1-cache-line-size", ix86_cost->prefetch_block);
3377   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
3378     set_param_value ("l1-cache-size", ix86_cost->l1_cache_size);
3379   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
3380     set_param_value ("l2-cache-size", ix86_cost->l2_cache_size);
3381
3382   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
3383      can be optimized to ap = __builtin_next_arg (0).  */
3384   if (!TARGET_64BIT)
3385     targetm.expand_builtin_va_start = NULL;
3386
3387   if (TARGET_64BIT)
3388     {
3389       ix86_gen_leave = gen_leave_rex64;
3390       ix86_gen_pop1 = gen_popdi1;
3391       ix86_gen_add3 = gen_adddi3;
3392       ix86_gen_sub3 = gen_subdi3;
3393       ix86_gen_sub3_carry = gen_subdi3_carry_rex64;
3394       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
3395       ix86_gen_monitor = gen_sse3_monitor64;
3396       ix86_gen_andsp = gen_anddi3;
3397     }
3398   else
3399     {
3400       ix86_gen_leave = gen_leave;
3401       ix86_gen_pop1 = gen_popsi1;
3402       ix86_gen_add3 = gen_addsi3;
3403       ix86_gen_sub3 = gen_subsi3;
3404       ix86_gen_sub3_carry = gen_subsi3_carry;
3405       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
3406       ix86_gen_monitor = gen_sse3_monitor;
3407       ix86_gen_andsp = gen_andsi3;
3408     }
3409
3410 #ifdef USE_IX86_CLD
3411   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
3412   if (!TARGET_64BIT)
3413     target_flags |= MASK_CLD & ~target_flags_explicit;
3414 #endif
3415
3416   /* Save the initial options in case the user does function specific options */
3417   if (main_args_p)
3418     target_option_default_node = target_option_current_node
3419       = build_target_option_node ();
3420 }
3421
3422 /* Update register usage after having seen the compiler flags.  */
3423
3424 void
3425 ix86_conditional_register_usage (void)
3426 {
3427   int i;
3428   unsigned int j;
3429
3430   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3431     {
3432       if (fixed_regs[i] > 1)
3433         fixed_regs[i] = (fixed_regs[i] == (TARGET_64BIT ? 3 : 2));
3434       if (call_used_regs[i] > 1)
3435         call_used_regs[i] = (call_used_regs[i] == (TARGET_64BIT ? 3 : 2));
3436     }
3437
3438   /* The PIC register, if it exists, is fixed.  */
3439   j = PIC_OFFSET_TABLE_REGNUM;
3440   if (j != INVALID_REGNUM)
3441     fixed_regs[j] = call_used_regs[j] = 1;
3442
3443   /* The MS_ABI changes the set of call-used registers.  */
3444   if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI)
3445     {
3446       call_used_regs[SI_REG] = 0;
3447       call_used_regs[DI_REG] = 0;
3448       call_used_regs[XMM6_REG] = 0;
3449       call_used_regs[XMM7_REG] = 0;
3450       for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
3451         call_used_regs[i] = 0;
3452     }
3453
3454   /* The default setting of CLOBBERED_REGS is for 32-bit; add in the
3455      other call-clobbered regs for 64-bit.  */
3456   if (TARGET_64BIT)
3457     {
3458       CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]);
3459
3460       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3461         if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i)
3462             && call_used_regs[i])
3463           SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i);
3464     }
3465
3466   /* If MMX is disabled, squash the registers.  */
3467   if (! TARGET_MMX)
3468     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3469       if (TEST_HARD_REG_BIT (reg_class_contents[(int)MMX_REGS], i))
3470         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
3471
3472   /* If SSE is disabled, squash the registers.  */
3473   if (! TARGET_SSE)
3474     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3475       if (TEST_HARD_REG_BIT (reg_class_contents[(int)SSE_REGS], i))
3476         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
3477
3478   /* If the FPU is disabled, squash the registers.  */
3479   if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
3480     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3481       if (TEST_HARD_REG_BIT (reg_class_contents[(int)FLOAT_REGS], i))
3482         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
3483
3484   /* If 32-bit, squash the 64-bit registers.  */
3485   if (! TARGET_64BIT)
3486     {
3487       for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++)
3488         reg_names[i] = "";
3489       for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
3490         reg_names[i] = "";
3491     }
3492 }
3493
3494 \f
3495 /* Save the current options */
3496
3497 static void
3498 ix86_function_specific_save (struct cl_target_option *ptr)
3499 {
3500   ptr->arch = ix86_arch;
3501   ptr->schedule = ix86_schedule;
3502   ptr->tune = ix86_tune;
3503   ptr->fpmath = ix86_fpmath;
3504   ptr->branch_cost = ix86_branch_cost;
3505   ptr->tune_defaulted = ix86_tune_defaulted;
3506   ptr->arch_specified = ix86_arch_specified;
3507   ptr->ix86_isa_flags_explicit = ix86_isa_flags_explicit;
3508   ptr->target_flags_explicit = target_flags_explicit;
3509
3510   /* The fields are char but the variables are not; make sure the
3511      values fit in the fields.  */
3512   gcc_assert (ptr->arch == ix86_arch);
3513   gcc_assert (ptr->schedule == ix86_schedule);
3514   gcc_assert (ptr->tune == ix86_tune);
3515   gcc_assert (ptr->fpmath == ix86_fpmath);
3516   gcc_assert (ptr->branch_cost == ix86_branch_cost);
3517 }
3518
3519 /* Restore the current options */
3520
3521 static void
3522 ix86_function_specific_restore (struct cl_target_option *ptr)
3523 {
3524   enum processor_type old_tune = ix86_tune;
3525   enum processor_type old_arch = ix86_arch;
3526   unsigned int ix86_arch_mask, ix86_tune_mask;
3527   int i;
3528
3529   ix86_arch = (enum processor_type) ptr->arch;
3530   ix86_schedule = (enum attr_cpu) ptr->schedule;
3531   ix86_tune = (enum processor_type) ptr->tune;
3532   ix86_fpmath = (enum fpmath_unit) ptr->fpmath;
3533   ix86_branch_cost = ptr->branch_cost;
3534   ix86_tune_defaulted = ptr->tune_defaulted;
3535   ix86_arch_specified = ptr->arch_specified;
3536   ix86_isa_flags_explicit = ptr->ix86_isa_flags_explicit;
3537   target_flags_explicit = ptr->target_flags_explicit;
3538
3539   /* Recreate the arch feature tests if the arch changed */
3540   if (old_arch != ix86_arch)
3541     {
3542       ix86_arch_mask = 1u << ix86_arch;
3543       for (i = 0; i < X86_ARCH_LAST; ++i)
3544         ix86_arch_features[i]
3545           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3546     }
3547
3548   /* Recreate the tune optimization tests */
3549   if (old_tune != ix86_tune)
3550     {
3551       ix86_tune_mask = 1u << ix86_tune;
3552       for (i = 0; i < X86_TUNE_LAST; ++i)
3553         ix86_tune_features[i]
3554           = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3555     }
3556 }
3557
3558 /* Print the current options */
3559
3560 static void
3561 ix86_function_specific_print (FILE *file, int indent,
3562                               struct cl_target_option *ptr)
3563 {
3564   char *target_string
3565     = ix86_target_string (ptr->ix86_isa_flags, ptr->target_flags,
3566                           NULL, NULL, NULL, false);
3567
3568   fprintf (file, "%*sarch = %d (%s)\n",
3569            indent, "",
3570            ptr->arch,
3571            ((ptr->arch < TARGET_CPU_DEFAULT_max)
3572             ? cpu_names[ptr->arch]
3573             : "<unknown>"));
3574
3575   fprintf (file, "%*stune = %d (%s)\n",
3576            indent, "",
3577            ptr->tune,
3578            ((ptr->tune < TARGET_CPU_DEFAULT_max)
3579             ? cpu_names[ptr->tune]
3580             : "<unknown>"));
3581
3582   fprintf (file, "%*sfpmath = %d%s%s\n", indent, "", ptr->fpmath,
3583            (ptr->fpmath & FPMATH_387) ? ", 387" : "",
3584            (ptr->fpmath & FPMATH_SSE) ? ", sse" : "");
3585   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
3586
3587   if (target_string)
3588     {
3589       fprintf (file, "%*s%s\n", indent, "", target_string);
3590       free (target_string);
3591     }
3592 }
3593
3594 \f
3595 /* Inner function to process the attribute((target(...))), take an argument and
3596    set the current options from the argument. If we have a list, recursively go
3597    over the list.  */
3598
3599 static bool
3600 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[])
3601 {
3602   char *next_optstr;
3603   bool ret = true;
3604
3605 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
3606 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
3607 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
3608 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
3609
3610   enum ix86_opt_type
3611   {
3612     ix86_opt_unknown,
3613     ix86_opt_yes,
3614     ix86_opt_no,
3615     ix86_opt_str,
3616     ix86_opt_isa
3617   };
3618
3619   static const struct
3620   {
3621     const char *string;
3622     size_t len;
3623     enum ix86_opt_type type;
3624     int opt;
3625     int mask;
3626   } attrs[] = {
3627     /* isa options */
3628     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
3629     IX86_ATTR_ISA ("abm",       OPT_mabm),
3630     IX86_ATTR_ISA ("aes",       OPT_maes),
3631     IX86_ATTR_ISA ("avx",       OPT_mavx),
3632     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
3633     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
3634     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
3635     IX86_ATTR_ISA ("sse",       OPT_msse),
3636     IX86_ATTR_ISA ("sse2",      OPT_msse2),
3637     IX86_ATTR_ISA ("sse3",      OPT_msse3),
3638     IX86_ATTR_ISA ("sse4",      OPT_msse4),
3639     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
3640     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
3641     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
3642     IX86_ATTR_ISA ("sse5",      OPT_msse5),
3643     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
3644
3645     /* string options */
3646     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
3647     IX86_ATTR_STR ("fpmath=",   IX86_FUNCTION_SPECIFIC_FPMATH),
3648     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
3649
3650     /* flag options */
3651     IX86_ATTR_YES ("cld",
3652                    OPT_mcld,
3653                    MASK_CLD),
3654
3655     IX86_ATTR_NO ("fancy-math-387",
3656                   OPT_mfancy_math_387,
3657                   MASK_NO_FANCY_MATH_387),
3658
3659     IX86_ATTR_NO ("fused-madd",
3660                   OPT_mfused_madd,
3661                   MASK_NO_FUSED_MADD),
3662
3663     IX86_ATTR_YES ("ieee-fp",
3664                    OPT_mieee_fp,
3665                    MASK_IEEE_FP),
3666
3667     IX86_ATTR_YES ("inline-all-stringops",
3668                    OPT_minline_all_stringops,
3669                    MASK_INLINE_ALL_STRINGOPS),
3670
3671     IX86_ATTR_YES ("inline-stringops-dynamically",
3672                    OPT_minline_stringops_dynamically,
3673                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
3674
3675     IX86_ATTR_NO ("align-stringops",
3676                   OPT_mno_align_stringops,
3677                   MASK_NO_ALIGN_STRINGOPS),
3678
3679     IX86_ATTR_YES ("recip",
3680                    OPT_mrecip,
3681                    MASK_RECIP),
3682
3683   };
3684
3685   /* If this is a list, recurse to get the options.  */
3686   if (TREE_CODE (args) == TREE_LIST)
3687     {
3688       bool ret = true;
3689
3690       for (; args; args = TREE_CHAIN (args))
3691         if (TREE_VALUE (args)
3692             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args), p_strings))
3693           ret = false;
3694
3695       return ret;
3696     }
3697
3698   else if (TREE_CODE (args) != STRING_CST)
3699     gcc_unreachable ();
3700
3701   /* Handle multiple arguments separated by commas.  */
3702   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
3703
3704   while (next_optstr && *next_optstr != '\0')
3705     {
3706       char *p = next_optstr;
3707       char *orig_p = p;
3708       char *comma = strchr (next_optstr, ',');
3709       const char *opt_string;
3710       size_t len, opt_len;
3711       int opt;
3712       bool opt_set_p;
3713       char ch;
3714       unsigned i;
3715       enum ix86_opt_type type = ix86_opt_unknown;
3716       int mask = 0;
3717
3718       if (comma)
3719         {
3720           *comma = '\0';
3721           len = comma - next_optstr;
3722           next_optstr = comma + 1;
3723         }
3724       else
3725         {
3726           len = strlen (p);
3727           next_optstr = NULL;
3728         }
3729
3730       /* Recognize no-xxx.  */
3731       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
3732         {
3733           opt_set_p = false;
3734           p += 3;
3735           len -= 3;
3736         }
3737       else
3738         opt_set_p = true;
3739
3740       /* Find the option.  */
3741       ch = *p;
3742       opt = N_OPTS;
3743       for (i = 0; i < ARRAY_SIZE (attrs); i++)
3744         {
3745           type = attrs[i].type;
3746           opt_len = attrs[i].len;
3747           if (ch == attrs[i].string[0]
3748               && ((type != ix86_opt_str) ? len == opt_len : len > opt_len)
3749               && memcmp (p, attrs[i].string, opt_len) == 0)
3750             {
3751               opt = attrs[i].opt;
3752               mask = attrs[i].mask;
3753               opt_string = attrs[i].string;
3754               break;
3755             }
3756         }
3757
3758       /* Process the option.  */
3759       if (opt == N_OPTS)
3760         {
3761           error ("attribute(target(\"%s\")) is unknown", orig_p);
3762           ret = false;
3763         }
3764
3765       else if (type == ix86_opt_isa)
3766         ix86_handle_option (opt, p, opt_set_p);
3767
3768       else if (type == ix86_opt_yes || type == ix86_opt_no)
3769         {
3770           if (type == ix86_opt_no)
3771             opt_set_p = !opt_set_p;
3772
3773           if (opt_set_p)
3774             target_flags |= mask;
3775           else
3776             target_flags &= ~mask;
3777         }
3778
3779       else if (type == ix86_opt_str)
3780         {
3781           if (p_strings[opt])
3782             {
3783               error ("option(\"%s\") was already specified", opt_string);
3784               ret = false;
3785             }
3786           else
3787             p_strings[opt] = xstrdup (p + opt_len);
3788         }
3789
3790       else
3791         gcc_unreachable ();
3792     }
3793
3794   return ret;
3795 }
3796
3797 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
3798
3799 tree
3800 ix86_valid_target_attribute_tree (tree args)
3801 {
3802   const char *orig_arch_string = ix86_arch_string;
3803   const char *orig_tune_string = ix86_tune_string;
3804   const char *orig_fpmath_string = ix86_fpmath_string;
3805   int orig_tune_defaulted = ix86_tune_defaulted;
3806   int orig_arch_specified = ix86_arch_specified;
3807   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL, NULL };
3808   tree t = NULL_TREE;
3809   int i;
3810   struct cl_target_option *def
3811     = TREE_TARGET_OPTION (target_option_default_node);
3812
3813   /* Process each of the options on the chain.  */
3814   if (! ix86_valid_target_attribute_inner_p (args, option_strings))
3815     return NULL_TREE;
3816
3817   /* If the changed options are different from the default, rerun override_options,
3818      and then save the options away.  The string options are are attribute options,
3819      and will be undone when we copy the save structure.  */
3820   if (ix86_isa_flags != def->ix86_isa_flags
3821       || target_flags != def->target_flags
3822       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
3823       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
3824       || option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3825     {
3826       /* If we are using the default tune= or arch=, undo the string assigned,
3827          and use the default.  */
3828       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
3829         ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
3830       else if (!orig_arch_specified)
3831         ix86_arch_string = NULL;
3832
3833       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
3834         ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
3835       else if (orig_tune_defaulted)
3836         ix86_tune_string = NULL;
3837
3838       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
3839       if (option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3840         ix86_fpmath_string = option_strings[IX86_FUNCTION_SPECIFIC_FPMATH];
3841       else if (!TARGET_64BIT && TARGET_SSE)
3842         ix86_fpmath_string = "sse,387";
3843
3844       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
3845       override_options (false);
3846
3847       /* Add any builtin functions with the new isa if any.  */
3848       ix86_add_new_builtins (ix86_isa_flags);
3849
3850       /* Save the current options unless we are validating options for
3851          #pragma.  */
3852       t = build_target_option_node ();
3853
3854       ix86_arch_string = orig_arch_string;
3855       ix86_tune_string = orig_tune_string;
3856       ix86_fpmath_string = orig_fpmath_string;
3857
3858       /* Free up memory allocated to hold the strings */
3859       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
3860         if (option_strings[i])
3861           free (option_strings[i]);
3862     }
3863
3864   return t;
3865 }
3866
3867 /* Hook to validate attribute((target("string"))).  */
3868
3869 static bool
3870 ix86_valid_target_attribute_p (tree fndecl,
3871                                tree ARG_UNUSED (name),
3872                                tree args,
3873                                int ARG_UNUSED (flags))
3874 {
3875   struct cl_target_option cur_target;
3876   bool ret = true;
3877   tree old_optimize = build_optimization_node ();
3878   tree new_target, new_optimize;
3879   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
3880
3881   /* If the function changed the optimization levels as well as setting target
3882      options, start with the optimizations specified.  */
3883   if (func_optimize && func_optimize != old_optimize)
3884     cl_optimization_restore (TREE_OPTIMIZATION (func_optimize));
3885
3886   /* The target attributes may also change some optimization flags, so update
3887      the optimization options if necessary.  */
3888   cl_target_option_save (&cur_target);
3889   new_target = ix86_valid_target_attribute_tree (args);
3890   new_optimize = build_optimization_node ();
3891
3892   if (!new_target)
3893     ret = false;
3894
3895   else if (fndecl)
3896     {
3897       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
3898
3899       if (old_optimize != new_optimize)
3900         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
3901     }
3902
3903   cl_target_option_restore (&cur_target);
3904
3905   if (old_optimize != new_optimize)
3906     cl_optimization_restore (TREE_OPTIMIZATION (old_optimize));
3907
3908   return ret;
3909 }
3910
3911 \f
3912 /* Hook to determine if one function can safely inline another.  */
3913
3914 static bool
3915 ix86_can_inline_p (tree caller, tree callee)
3916 {
3917   bool ret = false;
3918   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
3919   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
3920
3921   /* If callee has no option attributes, then it is ok to inline.  */
3922   if (!callee_tree)
3923     ret = true;
3924
3925   /* If caller has no option attributes, but callee does then it is not ok to
3926      inline.  */
3927   else if (!caller_tree)
3928     ret = false;
3929
3930   else
3931     {
3932       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
3933       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
3934
3935       /* Callee's isa options should a subset of the caller's, i.e. a SSE5 function
3936          can inline a SSE2 function but a SSE2 function can't inline a SSE5
3937          function.  */
3938       if ((caller_opts->ix86_isa_flags & callee_opts->ix86_isa_flags)
3939           != callee_opts->ix86_isa_flags)
3940         ret = false;
3941
3942       /* See if we have the same non-isa options.  */
3943       else if (caller_opts->target_flags != callee_opts->target_flags)
3944         ret = false;
3945
3946       /* See if arch, tune, etc. are the same.  */
3947       else if (caller_opts->arch != callee_opts->arch)
3948         ret = false;
3949
3950       else if (caller_opts->tune != callee_opts->tune)
3951         ret = false;
3952
3953       else if (caller_opts->fpmath != callee_opts->fpmath)
3954         ret = false;
3955
3956       else if (caller_opts->branch_cost != callee_opts->branch_cost)
3957         ret = false;
3958
3959       else
3960         ret = true;
3961     }
3962
3963   return ret;
3964 }
3965
3966 \f
3967 /* Remember the last target of ix86_set_current_function.  */
3968 static GTY(()) tree ix86_previous_fndecl;
3969
3970 /* Establish appropriate back-end context for processing the function
3971    FNDECL.  The argument might be NULL to indicate processing at top
3972    level, outside of any function scope.  */
3973 static void
3974 ix86_set_current_function (tree fndecl)
3975 {
3976   /* Only change the context if the function changes.  This hook is called
3977      several times in the course of compiling a function, and we don't want to
3978      slow things down too much or call target_reinit when it isn't safe.  */
3979   if (fndecl && fndecl != ix86_previous_fndecl)
3980     {
3981       tree old_tree = (ix86_previous_fndecl
3982                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
3983                        : NULL_TREE);
3984
3985       tree new_tree = (fndecl
3986                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
3987                        : NULL_TREE);
3988
3989       ix86_previous_fndecl = fndecl;
3990       if (old_tree == new_tree)
3991         ;
3992
3993       else if (new_tree)
3994         {
3995           cl_target_option_restore (TREE_TARGET_OPTION (new_tree));
3996           target_reinit ();
3997         }
3998
3999       else if (old_tree)
4000         {
4001           struct cl_target_option *def
4002             = TREE_TARGET_OPTION (target_option_current_node);
4003
4004           cl_target_option_restore (def);
4005           target_reinit ();
4006         }
4007     }
4008 }
4009
4010 \f
4011 /* Return true if this goes in large data/bss.  */
4012
4013 static bool
4014 ix86_in_large_data_p (tree exp)
4015 {
4016   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
4017     return false;
4018
4019   /* Functions are never large data.  */
4020   if (TREE_CODE (exp) == FUNCTION_DECL)
4021     return false;
4022
4023   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
4024     {
4025       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
4026       if (strcmp (section, ".ldata") == 0
4027           || strcmp (section, ".lbss") == 0)
4028         return true;
4029       return false;
4030     }
4031   else
4032     {
4033       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
4034
4035       /* If this is an incomplete type with size 0, then we can't put it
4036          in data because it might be too big when completed.  */
4037       if (!size || size > ix86_section_threshold)
4038         return true;
4039     }
4040
4041   return false;
4042 }
4043
4044 /* Switch to the appropriate section for output of DECL.
4045    DECL is either a `VAR_DECL' node or a constant of some sort.
4046    RELOC indicates whether forming the initial value of DECL requires
4047    link-time relocations.  */
4048
4049 static section * x86_64_elf_select_section (tree, int, unsigned HOST_WIDE_INT)
4050         ATTRIBUTE_UNUSED;
4051
4052 static section *
4053 x86_64_elf_select_section (tree decl, int reloc,
4054                            unsigned HOST_WIDE_INT align)
4055 {
4056   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
4057       && ix86_in_large_data_p (decl))
4058     {
4059       const char *sname = NULL;
4060       unsigned int flags = SECTION_WRITE;
4061       switch (categorize_decl_for_section (decl, reloc))
4062         {
4063         case SECCAT_DATA:
4064           sname = ".ldata";
4065           break;
4066         case SECCAT_DATA_REL:
4067           sname = ".ldata.rel";
4068           break;
4069         case SECCAT_DATA_REL_LOCAL:
4070           sname = ".ldata.rel.local";
4071           break;
4072         case SECCAT_DATA_REL_RO:
4073           sname = ".ldata.rel.ro";
4074           break;
4075         case SECCAT_DATA_REL_RO_LOCAL:
4076           sname = ".ldata.rel.ro.local";
4077           break;
4078         case SECCAT_BSS:
4079           sname = ".lbss";
4080           flags |= SECTION_BSS;
4081           break;
4082         case SECCAT_RODATA:
4083         case SECCAT_RODATA_MERGE_STR:
4084         case SECCAT_RODATA_MERGE_STR_INIT:
4085         case SECCAT_RODATA_MERGE_CONST:
4086           sname = ".lrodata";
4087           flags = 0;
4088           break;
4089         case SECCAT_SRODATA:
4090         case SECCAT_SDATA:
4091         case SECCAT_SBSS:
4092           gcc_unreachable ();
4093         case SECCAT_TEXT:
4094         case SECCAT_TDATA:
4095         case SECCAT_TBSS:
4096           /* We don't split these for medium model.  Place them into
4097              default sections and hope for best.  */
4098           break;
4099         case SECCAT_EMUTLS_VAR:
4100         case SECCAT_EMUTLS_TMPL:
4101           gcc_unreachable ();
4102         }
4103       if (sname)
4104         {
4105           /* We might get called with string constants, but get_named_section
4106              doesn't like them as they are not DECLs.  Also, we need to set
4107              flags in that case.  */
4108           if (!DECL_P (decl))
4109             return get_section (sname, flags, NULL);
4110           return get_named_section (decl, sname, reloc);
4111         }
4112     }
4113   return default_elf_select_section (decl, reloc, align);
4114 }
4115
4116 /* Build up a unique section name, expressed as a
4117    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
4118    RELOC indicates whether the initial value of EXP requires
4119    link-time relocations.  */
4120
4121 static void ATTRIBUTE_UNUSED
4122 x86_64_elf_unique_section (tree decl, int reloc)
4123 {
4124   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
4125       && ix86_in_large_data_p (decl))
4126     {
4127       const char *prefix = NULL;
4128       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
4129       bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
4130
4131       switch (categorize_decl_for_section (decl, reloc))
4132         {
4133         case SECCAT_DATA:
4134         case SECCAT_DATA_REL:
4135         case SECCAT_DATA_REL_LOCAL:
4136         case SECCAT_DATA_REL_RO:
4137         case SECCAT_DATA_REL_RO_LOCAL:
4138           prefix = one_only ? ".ld" : ".ldata";
4139           break;
4140         case SECCAT_BSS:
4141           prefix = one_only ? ".lb" : ".lbss";
4142           break;
4143         case SECCAT_RODATA:
4144         case SECCAT_RODATA_MERGE_STR:
4145         case SECCAT_RODATA_MERGE_STR_INIT:
4146         case SECCAT_RODATA_MERGE_CONST:
4147           prefix = one_only ? ".lr" : ".lrodata";
4148           break;
4149         case SECCAT_SRODATA:
4150         case SECCAT_SDATA:
4151         case SECCAT_SBSS:
4152           gcc_unreachable ();
4153         case SECCAT_TEXT:
4154         case SECCAT_TDATA:
4155         case SECCAT_TBSS:
4156           /* We don't split these for medium model.  Place them into
4157              default sections and hope for best.  */
4158           break;
4159         case SECCAT_EMUTLS_VAR:
4160           prefix = targetm.emutls.var_section;
4161           break;
4162         case SECCAT_EMUTLS_TMPL:
4163           prefix = targetm.emutls.tmpl_section;
4164           break;
4165         }
4166       if (prefix)
4167         {
4168           const char *name, *linkonce;
4169           char *string;
4170
4171           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4172           name = targetm.strip_name_encoding (name);
4173           
4174           /* If we're using one_only, then there needs to be a .gnu.linkonce
4175              prefix to the section name.  */
4176           linkonce = one_only ? ".gnu.linkonce" : "";
4177   
4178           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
4179           
4180           DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
4181           return;
4182         }
4183     }
4184   default_unique_section (decl, reloc);
4185 }
4186
4187 #ifdef COMMON_ASM_OP
4188 /* This says how to output assembler code to declare an
4189    uninitialized external linkage data object.
4190
4191    For medium model x86-64 we need to use .largecomm opcode for
4192    large objects.  */
4193 void
4194 x86_elf_aligned_common (FILE *file,
4195                         const char *name, unsigned HOST_WIDE_INT size,
4196                         int align)
4197 {
4198   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
4199       && size > (unsigned int)ix86_section_threshold)
4200     fputs (".largecomm\t", file);
4201   else
4202     fputs (COMMON_ASM_OP, file);
4203   assemble_name (file, name);
4204   fprintf (file, "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
4205            size, align / BITS_PER_UNIT);
4206 }
4207 #endif
4208
4209 /* Utility function for targets to use in implementing
4210    ASM_OUTPUT_ALIGNED_BSS.  */
4211
4212 void
4213 x86_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
4214                         const char *name, unsigned HOST_WIDE_INT size,
4215                         int align)
4216 {
4217   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
4218       && size > (unsigned int)ix86_section_threshold)
4219     switch_to_section (get_named_section (decl, ".lbss", 0));
4220   else
4221     switch_to_section (bss_section);
4222   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
4223 #ifdef ASM_DECLARE_OBJECT_NAME
4224   last_assemble_variable_decl = decl;
4225   ASM_DECLARE_OBJECT_NAME (file, name, decl);
4226 #else
4227   /* Standard thing is just output label for the object.  */
4228   ASM_OUTPUT_LABEL (file, name);
4229 #endif /* ASM_DECLARE_OBJECT_NAME */
4230   ASM_OUTPUT_SKIP (file, size ? size : 1);
4231 }
4232 \f
4233 void
4234 optimization_options (int level, int size ATTRIBUTE_UNUSED)
4235 {
4236   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
4237      make the problem with not enough registers even worse.  */
4238 #ifdef INSN_SCHEDULING
4239   if (level > 1)
4240     flag_schedule_insns = 0;
4241 #endif
4242
4243   if (TARGET_MACHO)
4244     /* The Darwin libraries never set errno, so we might as well
4245        avoid calling them when that's the only reason we would.  */
4246     flag_errno_math = 0;
4247
4248   /* The default values of these switches depend on the TARGET_64BIT
4249      that is not known at this moment.  Mark these values with 2 and
4250      let user the to override these.  In case there is no command line option
4251      specifying them, we will set the defaults in override_options.  */
4252   if (optimize >= 1)
4253     flag_omit_frame_pointer = 2;
4254   flag_pcc_struct_return = 2;
4255   flag_asynchronous_unwind_tables = 2;
4256   flag_vect_cost_model = 1;
4257 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
4258   SUBTARGET_OPTIMIZATION_OPTIONS;
4259 #endif
4260 }
4261 \f
4262 /* Decide whether we can make a sibling call to a function.  DECL is the
4263    declaration of the function being targeted by the call and EXP is the
4264    CALL_EXPR representing the call.  */
4265
4266 static bool
4267 ix86_function_ok_for_sibcall (tree decl, tree exp)
4268 {
4269   tree type, decl_or_type;
4270   rtx a, b;
4271
4272   /* If we are generating position-independent code, we cannot sibcall
4273      optimize any indirect call, or a direct call to a global function,
4274      as the PLT requires %ebx be live.  */
4275   if (!TARGET_64BIT && flag_pic && (!decl || !targetm.binds_local_p (decl)))
4276     return false;
4277
4278   /* If we need to align the outgoing stack, then sibcalling would
4279      unalign the stack, which may break the called function.  */
4280   if (ix86_incoming_stack_boundary < PREFERRED_STACK_BOUNDARY)
4281     return false;
4282
4283   if (decl)
4284     {
4285       decl_or_type = decl;
4286       type = TREE_TYPE (decl);
4287     }
4288   else
4289     {
4290       /* We're looking at the CALL_EXPR, we need the type of the function.  */
4291       type = CALL_EXPR_FN (exp);                /* pointer expression */
4292       type = TREE_TYPE (type);                  /* pointer type */
4293       type = TREE_TYPE (type);                  /* function type */
4294       decl_or_type = type;
4295     }
4296
4297   /* Check that the return value locations are the same.  Like
4298      if we are returning floats on the 80387 register stack, we cannot
4299      make a sibcall from a function that doesn't return a float to a
4300      function that does or, conversely, from a function that does return
4301      a float to a function that doesn't; the necessary stack adjustment
4302      would not be executed.  This is also the place we notice
4303      differences in the return value ABI.  Note that it is ok for one
4304      of the functions to have void return type as long as the return
4305      value of the other is passed in a register.  */
4306   a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false);
4307   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
4308                            cfun->decl, false);
4309   if (STACK_REG_P (a) || STACK_REG_P (b))
4310     {
4311       if (!rtx_equal_p (a, b))
4312         return false;
4313     }
4314   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
4315     ;
4316   else if (!rtx_equal_p (a, b))
4317     return false;
4318
4319   if (TARGET_64BIT)
4320     {
4321       /* The SYSV ABI has more call-clobbered registers;
4322          disallow sibcalls from MS to SYSV.  */
4323       if (cfun->machine->call_abi == MS_ABI
4324           && ix86_function_type_abi (type) == SYSV_ABI)
4325         return false;
4326     }
4327   else
4328     {
4329       /* If this call is indirect, we'll need to be able to use a
4330          call-clobbered register for the address of the target function.
4331          Make sure that all such registers are not used for passing
4332          parameters.  Note that DLLIMPORT functions are indirect.  */
4333       if (!decl
4334           || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl)))
4335         {
4336           if (ix86_function_regparm (type, NULL) >= 3)
4337             {
4338               /* ??? Need to count the actual number of registers to be used,
4339                  not the possible number of registers.  Fix later.  */
4340               return false;
4341             }
4342         }
4343     }
4344
4345   /* Otherwise okay.  That also includes certain types of indirect calls.  */
4346   return true;
4347 }
4348
4349 /* Handle "cdecl", "stdcall", "fastcall", "regparm" and "sseregparm"
4350    calling convention attributes;
4351    arguments as in struct attribute_spec.handler.  */
4352
4353 static tree
4354 ix86_handle_cconv_attribute (tree *node, tree name,
4355                                    tree args,
4356                                    int flags ATTRIBUTE_UNUSED,
4357                                    bool *no_add_attrs)
4358 {
4359   if (TREE_CODE (*node) != FUNCTION_TYPE
4360       && TREE_CODE (*node) != METHOD_TYPE
4361       && TREE_CODE (*node) != FIELD_DECL
4362       && TREE_CODE (*node) != TYPE_DECL)
4363     {
4364       warning (OPT_Wattributes, "%qE attribute only applies to functions",
4365                name);
4366       *no_add_attrs = true;
4367       return NULL_TREE;
4368     }
4369
4370   /* Can combine regparm with all attributes but fastcall.  */
4371   if (is_attribute_p ("regparm", name))
4372     {
4373       tree cst;
4374
4375       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4376         {
4377           error ("fastcall and regparm attributes are not compatible");
4378         }
4379
4380       cst = TREE_VALUE (args);
4381       if (TREE_CODE (cst) != INTEGER_CST)
4382         {
4383           warning (OPT_Wattributes,
4384                    "%qE attribute requires an integer constant argument",
4385                    name);
4386           *no_add_attrs = true;
4387         }
4388       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
4389         {
4390           warning (OPT_Wattributes, "argument to %qE attribute larger than %d",
4391                    name, REGPARM_MAX);
4392           *no_add_attrs = true;
4393         }
4394
4395       return NULL_TREE;
4396     }
4397
4398   if (TARGET_64BIT)
4399     {
4400       /* Do not warn when emulating the MS ABI.  */
4401       if (TREE_CODE (*node) != FUNCTION_TYPE
4402           || ix86_function_type_abi (*node) != MS_ABI)
4403         warning (OPT_Wattributes, "%qE attribute ignored",
4404                  name);
4405       *no_add_attrs = true;
4406       return NULL_TREE;
4407     }
4408
4409   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
4410   if (is_attribute_p ("fastcall", name))
4411     {
4412       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4413         {
4414           error ("fastcall and cdecl attributes are not compatible");
4415         }
4416       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4417         {
4418           error ("fastcall and stdcall attributes are not compatible");
4419         }
4420       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
4421         {
4422           error ("fastcall and regparm attributes are not compatible");
4423         }
4424     }
4425
4426   /* Can combine stdcall with fastcall (redundant), regparm and
4427      sseregparm.  */
4428   else if (is_attribute_p ("stdcall", name))
4429     {
4430       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4431         {
4432           error ("stdcall and cdecl attributes are not compatible");
4433         }
4434       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4435         {
4436           error ("stdcall and fastcall attributes are not compatible");
4437         }
4438     }
4439
4440   /* Can combine cdecl with regparm and sseregparm.  */
4441   else if (is_attribute_p ("cdecl", name))
4442     {
4443       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4444         {
4445           error ("stdcall and cdecl attributes are not compatible");
4446         }
4447       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4448         {
4449           error ("fastcall and cdecl attributes are not compatible");
4450         }
4451     }
4452
4453   /* Can combine sseregparm with all attributes.  */
4454
4455   return NULL_TREE;
4456 }
4457
4458 /* Return 0 if the attributes for two types are incompatible, 1 if they
4459    are compatible, and 2 if they are nearly compatible (which causes a
4460    warning to be generated).  */
4461
4462 static int
4463 ix86_comp_type_attributes (const_tree type1, const_tree type2)
4464 {
4465   /* Check for mismatch of non-default calling convention.  */
4466   const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
4467
4468   if (TREE_CODE (type1) != FUNCTION_TYPE
4469       && TREE_CODE (type1) != METHOD_TYPE)
4470     return 1;
4471
4472   /* Check for mismatched fastcall/regparm types.  */
4473   if ((!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
4474        != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
4475       || (ix86_function_regparm (type1, NULL)
4476           != ix86_function_regparm (type2, NULL)))
4477     return 0;
4478
4479   /* Check for mismatched sseregparm types.  */
4480   if (!lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type1))
4481       != !lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type2)))
4482     return 0;
4483
4484   /* Check for mismatched return types (cdecl vs stdcall).  */
4485   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
4486       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
4487     return 0;
4488
4489   return 1;
4490 }
4491 \f
4492 /* Return the regparm value for a function with the indicated TYPE and DECL.
4493    DECL may be NULL when calling function indirectly
4494    or considering a libcall.  */
4495
4496 static int
4497 ix86_function_regparm (const_tree type, const_tree decl)
4498 {
4499   tree attr;
4500   int regparm;
4501
4502   static bool error_issued;
4503
4504   if (TARGET_64BIT)
4505     return (ix86_function_type_abi (type) == SYSV_ABI
4506             ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
4507
4508   regparm = ix86_regparm;
4509   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
4510   if (attr)
4511     {
4512       regparm
4513         = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
4514
4515       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4516         {
4517           /* We can't use regparm(3) for nested functions because
4518              these pass static chain pointer in %ecx register.  */
4519           if (!error_issued && regparm == 3
4520               && decl_function_context (decl)
4521               && !DECL_NO_STATIC_CHAIN (decl))
4522             {
4523               error ("nested functions are limited to 2 register parameters");
4524               error_issued = true;
4525               return 0;
4526             }
4527         }
4528
4529       return regparm;
4530     }
4531
4532   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4533     return 2;
4534
4535   /* Use register calling convention for local functions when possible.  */
4536   if (decl
4537       && TREE_CODE (decl) == FUNCTION_DECL
4538       && optimize
4539       && !profile_flag)
4540     {
4541       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4542       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4543       if (i && i->local)
4544         {
4545           int local_regparm, globals = 0, regno;
4546           struct function *f;
4547
4548           /* Make sure no regparm register is taken by a
4549              fixed register variable.  */
4550           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4551             if (fixed_regs[local_regparm])
4552               break;
4553
4554           /* We can't use regparm(3) for nested functions as these use
4555              static chain pointer in third argument.  */
4556           if (local_regparm == 3
4557               && decl_function_context (decl)
4558               && !DECL_NO_STATIC_CHAIN (decl))
4559             local_regparm = 2;
4560
4561           /* If the function realigns its stackpointer, the prologue will
4562              clobber %ecx.  If we've already generated code for the callee,
4563              the callee DECL_STRUCT_FUNCTION is gone, so we fall back to
4564              scanning the attributes for the self-realigning property.  */
4565           f = DECL_STRUCT_FUNCTION (decl);
4566           /* Since current internal arg pointer won't conflict with
4567              parameter passing regs, so no need to change stack
4568              realignment and adjust regparm number.
4569
4570              Each fixed register usage increases register pressure,
4571              so less registers should be used for argument passing.
4572              This functionality can be overriden by an explicit
4573              regparm value.  */
4574           for (regno = 0; regno <= DI_REG; regno++)
4575             if (fixed_regs[regno])
4576               globals++;
4577
4578           local_regparm
4579             = globals < local_regparm ? local_regparm - globals : 0;
4580
4581           if (local_regparm > regparm)
4582             regparm = local_regparm;
4583         }
4584     }
4585
4586   return regparm;
4587 }
4588
4589 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
4590    DFmode (2) arguments in SSE registers for a function with the
4591    indicated TYPE and DECL.  DECL may be NULL when calling function
4592    indirectly or considering a libcall.  Otherwise return 0.  */
4593
4594 static int
4595 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
4596 {
4597   gcc_assert (!TARGET_64BIT);
4598
4599   /* Use SSE registers to pass SFmode and DFmode arguments if requested
4600      by the sseregparm attribute.  */
4601   if (TARGET_SSEREGPARM
4602       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
4603     {
4604       if (!TARGET_SSE)
4605         {
4606           if (warn)
4607             {
4608               if (decl)
4609                 error ("Calling %qD with attribute sseregparm without "
4610                        "SSE/SSE2 enabled", decl);
4611               else
4612                 error ("Calling %qT with attribute sseregparm without "
4613                        "SSE/SSE2 enabled", type);
4614             }
4615           return 0;
4616         }
4617
4618       return 2;
4619     }
4620
4621   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4622      (and DFmode for SSE2) arguments in SSE registers.  */
4623   if (decl && TARGET_SSE_MATH && optimize && !profile_flag)
4624     {
4625       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4626       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4627       if (i && i->local)
4628         return TARGET_SSE2 ? 2 : 1;
4629     }
4630
4631   return 0;
4632 }
4633
4634 /* Return true if EAX is live at the start of the function.  Used by
4635    ix86_expand_prologue to determine if we need special help before
4636    calling allocate_stack_worker.  */
4637
4638 static bool
4639 ix86_eax_live_at_start_p (void)
4640 {
4641   /* Cheat.  Don't bother working forward from ix86_function_regparm
4642      to the function type to whether an actual argument is located in
4643      eax.  Instead just look at cfg info, which is still close enough
4644      to correct at this point.  This gives false positives for broken
4645      functions that might use uninitialized data that happens to be
4646      allocated in eax, but who cares?  */
4647   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR), 0);
4648 }
4649
4650 /* Value is the number of bytes of arguments automatically
4651    popped when returning from a subroutine call.
4652    FUNDECL is the declaration node of the function (as a tree),
4653    FUNTYPE is the data type of the function (as a tree),
4654    or for a library call it is an identifier node for the subroutine name.
4655    SIZE is the number of bytes of arguments passed on the stack.
4656
4657    On the 80386, the RTD insn may be used to pop them if the number
4658      of args is fixed, but if the number is variable then the caller
4659      must pop them all.  RTD can't be used for library calls now
4660      because the library is compiled with the Unix compiler.
4661    Use of RTD is a selectable option, since it is incompatible with
4662    standard Unix calling sequences.  If the option is not selected,
4663    the caller must always pop the args.
4664
4665    The attribute stdcall is equivalent to RTD on a per module basis.  */
4666
4667 int
4668 ix86_return_pops_args (tree fundecl, tree funtype, int size)
4669 {
4670   int rtd;
4671
4672   /* None of the 64-bit ABIs pop arguments.  */
4673   if (TARGET_64BIT)
4674     return 0;
4675
4676   rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
4677
4678   /* Cdecl functions override -mrtd, and never pop the stack.  */
4679   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
4680     {
4681       /* Stdcall and fastcall functions will pop the stack if not
4682          variable args.  */
4683       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
4684           || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
4685         rtd = 1;
4686
4687       if (rtd && ! stdarg_p (funtype))
4688         return size;
4689     }
4690
4691   /* Lose any fake structure return argument if it is passed on the stack.  */
4692   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
4693       && !KEEP_AGGREGATE_RETURN_POINTER)
4694     {
4695       int nregs = ix86_function_regparm (funtype, fundecl);
4696       if (nregs == 0)
4697         return GET_MODE_SIZE (Pmode);
4698     }
4699
4700   return 0;
4701 }
4702 \f
4703 /* Argument support functions.  */
4704
4705 /* Return true when register may be used to pass function parameters.  */
4706 bool
4707 ix86_function_arg_regno_p (int regno)
4708 {
4709   int i;
4710   const int *parm_regs;
4711
4712   if (!TARGET_64BIT)
4713     {
4714       if (TARGET_MACHO)
4715         return (regno < REGPARM_MAX
4716                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
4717       else
4718         return (regno < REGPARM_MAX
4719                 || (TARGET_MMX && MMX_REGNO_P (regno)
4720                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
4721                 || (TARGET_SSE && SSE_REGNO_P (regno)
4722                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
4723     }
4724
4725   if (TARGET_MACHO)
4726     {
4727       if (SSE_REGNO_P (regno) && TARGET_SSE)
4728         return true;
4729     }
4730   else
4731     {
4732       if (TARGET_SSE && SSE_REGNO_P (regno)
4733           && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
4734         return true;
4735     }
4736
4737   /* TODO: The function should depend on current function ABI but
4738      builtins.c would need updating then. Therefore we use the
4739      default ABI.  */
4740
4741   /* RAX is used as hidden argument to va_arg functions.  */
4742   if (ix86_abi == SYSV_ABI && regno == AX_REG)
4743     return true;
4744
4745   if (ix86_abi == MS_ABI)
4746     parm_regs = x86_64_ms_abi_int_parameter_registers;
4747   else
4748     parm_regs = x86_64_int_parameter_registers;
4749   for (i = 0; i < (ix86_abi == MS_ABI
4750                    ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++)
4751     if (regno == parm_regs[i])
4752       return true;
4753   return false;
4754 }
4755
4756 /* Return if we do not know how to pass TYPE solely in registers.  */
4757
4758 static bool
4759 ix86_must_pass_in_stack (enum machine_mode mode, const_tree type)
4760 {
4761   if (must_pass_in_stack_var_size_or_pad (mode, type))
4762     return true;
4763
4764   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
4765      The layout_type routine is crafty and tries to trick us into passing
4766      currently unsupported vector types on the stack by using TImode.  */
4767   return (!TARGET_64BIT && mode == TImode
4768           && type && TREE_CODE (type) != VECTOR_TYPE);
4769 }
4770
4771 /* It returns the size, in bytes, of the area reserved for arguments passed
4772    in registers for the function represented by fndecl dependent to the used
4773    abi format.  */
4774 int
4775 ix86_reg_parm_stack_space (const_tree fndecl)
4776 {
4777   enum calling_abi call_abi = SYSV_ABI;
4778   if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
4779     call_abi = ix86_function_abi (fndecl);
4780   else
4781     call_abi = ix86_function_type_abi (fndecl);
4782   if (call_abi == MS_ABI)
4783     return 32;
4784   return 0;
4785 }
4786
4787 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
4788    call abi used.  */
4789 enum calling_abi
4790 ix86_function_type_abi (const_tree fntype)
4791 {
4792   if (TARGET_64BIT && fntype != NULL)
4793     {
4794       enum calling_abi abi = ix86_abi;
4795       if (abi == SYSV_ABI)
4796         {
4797           if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)))
4798             abi = MS_ABI;
4799         }
4800       else if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)))
4801         abi = SYSV_ABI;
4802       return abi;
4803     }
4804   return ix86_abi;
4805 }
4806
4807 static enum calling_abi
4808 ix86_function_abi (const_tree fndecl)
4809 {
4810   if (! fndecl)
4811     return ix86_abi;
4812   return ix86_function_type_abi (TREE_TYPE (fndecl));
4813 }
4814
4815 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
4816    call abi used.  */
4817 enum calling_abi
4818 ix86_cfun_abi (void)
4819 {
4820   if (! cfun || ! TARGET_64BIT)
4821     return ix86_abi;
4822   return cfun->machine->call_abi;
4823 }
4824
4825 /* regclass.c  */
4826 extern void init_regs (void);
4827
4828 /* Implementation of call abi switching target hook. Specific to FNDECL
4829    the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
4830    for more details.  */
4831 void
4832 ix86_call_abi_override (const_tree fndecl)
4833 {
4834   if (fndecl == NULL_TREE)
4835     cfun->machine->call_abi = ix86_abi;
4836   else
4837     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
4838 }
4839
4840 /* MS and SYSV ABI have different set of call used registers.  Avoid expensive
4841    re-initialization of init_regs each time we switch function context since
4842    this is needed only during RTL expansion.  */
4843 static void
4844 ix86_maybe_switch_abi (void)
4845 {
4846   if (TARGET_64BIT &&
4847       call_used_regs[SI_REG] == (cfun->machine->call_abi == MS_ABI))
4848     reinit_regs ();
4849 }
4850
4851 /* Initialize a variable CUM of type CUMULATIVE_ARGS
4852    for a call to a function whose data type is FNTYPE.
4853    For a library call, FNTYPE is 0.  */
4854
4855 void
4856 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
4857                       tree fntype,      /* tree ptr for function decl */
4858                       rtx libname,      /* SYMBOL_REF of library name or 0 */
4859                       tree fndecl)
4860 {
4861   struct cgraph_local_info *i = fndecl ? cgraph_local_info (fndecl) : NULL;
4862   memset (cum, 0, sizeof (*cum));
4863
4864   if (fndecl)
4865    cum->call_abi = ix86_function_abi (fndecl);
4866   else
4867    cum->call_abi = ix86_function_type_abi (fntype);
4868   /* Set up the number of registers to use for passing arguments.  */
4869
4870   if (cum->call_abi == MS_ABI && !ACCUMULATE_OUTGOING_ARGS)
4871     sorry ("ms_abi attribute requires -maccumulate-outgoing-args "
4872            "or subtarget optimization implying it");
4873   cum->nregs = ix86_regparm;
4874   if (TARGET_64BIT)
4875     {
4876       if (cum->call_abi != ix86_abi)
4877         cum->nregs = (ix86_abi != SYSV_ABI
4878                       ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
4879     }
4880   if (TARGET_SSE)
4881     {
4882       cum->sse_nregs = SSE_REGPARM_MAX;
4883       if (TARGET_64BIT)
4884         {
4885           if (cum->call_abi != ix86_abi)
4886             cum->sse_nregs = (ix86_abi != SYSV_ABI
4887                               ? X86_64_SSE_REGPARM_MAX
4888                               : X86_64_MS_SSE_REGPARM_MAX);
4889         }
4890     }
4891   if (TARGET_MMX)
4892     cum->mmx_nregs = MMX_REGPARM_MAX;
4893   cum->warn_avx = true;
4894   cum->warn_sse = true;
4895   cum->warn_mmx = true;
4896
4897   /* Because type might mismatch in between caller and callee, we need to
4898      use actual type of function for local calls.
4899      FIXME: cgraph_analyze can be told to actually record if function uses
4900      va_start so for local functions maybe_vaarg can be made aggressive
4901      helping K&R code.
4902      FIXME: once typesytem is fixed, we won't need this code anymore.  */
4903   if (i && i->local)
4904     fntype = TREE_TYPE (fndecl);
4905   cum->maybe_vaarg = (fntype
4906                       ? (!prototype_p (fntype) || stdarg_p (fntype))
4907                       : !libname);
4908
4909   if (!TARGET_64BIT)
4910     {
4911       /* If there are variable arguments, then we won't pass anything
4912          in registers in 32-bit mode. */
4913       if (stdarg_p (fntype))
4914         {
4915           cum->nregs = 0;
4916           cum->sse_nregs = 0;
4917           cum->mmx_nregs = 0;
4918           cum->warn_avx = 0;
4919           cum->warn_sse = 0;
4920           cum->warn_mmx = 0;
4921           return;
4922         }
4923
4924       /* Use ecx and edx registers if function has fastcall attribute,
4925          else look for regparm information.  */
4926       if (fntype)
4927         {
4928           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
4929             {
4930               cum->nregs = 2;
4931               cum->fastcall = 1;
4932             }
4933           else
4934             cum->nregs = ix86_function_regparm (fntype, fndecl);
4935         }
4936
4937       /* Set up the number of SSE registers used for passing SFmode
4938          and DFmode arguments.  Warn for mismatching ABI.  */
4939       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
4940     }
4941 }
4942
4943 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
4944    But in the case of vector types, it is some vector mode.
4945
4946    When we have only some of our vector isa extensions enabled, then there
4947    are some modes for which vector_mode_supported_p is false.  For these
4948    modes, the generic vector support in gcc will choose some non-vector mode
4949    in order to implement the type.  By computing the natural mode, we'll
4950    select the proper ABI location for the operand and not depend on whatever
4951    the middle-end decides to do with these vector types.
4952
4953    The midde-end can't deal with the vector types > 16 bytes.  In this
4954    case, we return the original mode and warn ABI change if CUM isn't
4955    NULL.  */
4956
4957 static enum machine_mode
4958 type_natural_mode (const_tree type, CUMULATIVE_ARGS *cum)
4959 {
4960   enum machine_mode mode = TYPE_MODE (type);
4961
4962   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
4963     {
4964       HOST_WIDE_INT size = int_size_in_bytes (type);
4965       if ((size == 8 || size == 16 || size == 32)
4966           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
4967           && TYPE_VECTOR_SUBPARTS (type) > 1)
4968         {
4969           enum machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
4970
4971           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4972             mode = MIN_MODE_VECTOR_FLOAT;
4973           else
4974             mode = MIN_MODE_VECTOR_INT;
4975
4976           /* Get the mode which has this inner mode and number of units.  */
4977           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
4978             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
4979                 && GET_MODE_INNER (mode) == innermode)
4980               {
4981                 if (size == 32 && !TARGET_AVX)
4982                   {
4983                     static bool warnedavx;
4984
4985                     if (cum
4986                         && !warnedavx 
4987                         && cum->warn_avx)
4988                       {
4989                         warnedavx = true;
4990                         warning (0, "AVX vector argument without AVX "
4991                                  "enabled changes the ABI");
4992                       }
4993                     return TYPE_MODE (type);
4994                   }
4995                 else
4996                   return mode;
4997               }
4998
4999           gcc_unreachable ();
5000         }
5001     }
5002
5003   return mode;
5004 }
5005
5006 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
5007    this may not agree with the mode that the type system has chosen for the
5008    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
5009    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
5010
5011 static rtx
5012 gen_reg_or_parallel (enum machine_mode mode, enum machine_mode orig_mode,
5013                      unsigned int regno)
5014 {
5015   rtx tmp;
5016
5017   if (orig_mode != BLKmode)
5018     tmp = gen_rtx_REG (orig_mode, regno);
5019   else
5020     {
5021       tmp = gen_rtx_REG (mode, regno);
5022       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
5023       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
5024     }
5025
5026   return tmp;
5027 }
5028
5029 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
5030    of this code is to classify each 8bytes of incoming argument by the register
5031    class and assign registers accordingly.  */
5032
5033 /* Return the union class of CLASS1 and CLASS2.
5034    See the x86-64 PS ABI for details.  */
5035
5036 static enum x86_64_reg_class
5037 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
5038 {
5039   /* Rule #1: If both classes are equal, this is the resulting class.  */
5040   if (class1 == class2)
5041     return class1;
5042
5043   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
5044      the other class.  */
5045   if (class1 == X86_64_NO_CLASS)
5046     return class2;
5047   if (class2 == X86_64_NO_CLASS)
5048     return class1;
5049
5050   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
5051   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
5052     return X86_64_MEMORY_CLASS;
5053
5054   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
5055   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
5056       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
5057     return X86_64_INTEGERSI_CLASS;
5058   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
5059       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
5060     return X86_64_INTEGER_CLASS;
5061
5062   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
5063      MEMORY is used.  */
5064   if (class1 == X86_64_X87_CLASS
5065       || class1 == X86_64_X87UP_CLASS
5066       || class1 == X86_64_COMPLEX_X87_CLASS
5067       || class2 == X86_64_X87_CLASS
5068       || class2 == X86_64_X87UP_CLASS
5069       || class2 == X86_64_COMPLEX_X87_CLASS)
5070     return X86_64_MEMORY_CLASS;
5071
5072   /* Rule #6: Otherwise class SSE is used.  */
5073   return X86_64_SSE_CLASS;
5074 }
5075
5076 /* Classify the argument of type TYPE and mode MODE.
5077    CLASSES will be filled by the register class used to pass each word
5078    of the operand.  The number of words is returned.  In case the parameter
5079    should be passed in memory, 0 is returned. As a special case for zero
5080    sized containers, classes[0] will be NO_CLASS and 1 is returned.
5081
5082    BIT_OFFSET is used internally for handling records and specifies offset
5083    of the offset in bits modulo 256 to avoid overflow cases.
5084
5085    See the x86-64 PS ABI for details.
5086 */
5087
5088 static int
5089 classify_argument (enum machine_mode mode, const_tree type,
5090                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
5091 {
5092   HOST_WIDE_INT bytes =
5093     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
5094   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5095
5096   /* Variable sized entities are always passed/returned in memory.  */
5097   if (bytes < 0)
5098     return 0;
5099
5100   if (mode != VOIDmode
5101       && targetm.calls.must_pass_in_stack (mode, type))
5102     return 0;
5103
5104   if (type && AGGREGATE_TYPE_P (type))
5105     {
5106       int i;
5107       tree field;
5108       enum x86_64_reg_class subclasses[MAX_CLASSES];
5109
5110       /* On x86-64 we pass structures larger than 32 bytes on the stack.  */
5111       if (bytes > 32)
5112         return 0;
5113
5114       for (i = 0; i < words; i++)
5115         classes[i] = X86_64_NO_CLASS;
5116
5117       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
5118          signalize memory class, so handle it as special case.  */
5119       if (!words)
5120         {
5121           classes[0] = X86_64_NO_CLASS;
5122           return 1;
5123         }
5124
5125       /* Classify each field of record and merge classes.  */
5126       switch (TREE_CODE (type))
5127         {
5128         case RECORD_TYPE:
5129           /* And now merge the fields of structure.  */
5130           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5131             {
5132               if (TREE_CODE (field) == FIELD_DECL)
5133                 {
5134                   int num;
5135
5136                   if (TREE_TYPE (field) == error_mark_node)
5137                     continue;
5138
5139                   /* Bitfields are always classified as integer.  Handle them
5140                      early, since later code would consider them to be
5141                      misaligned integers.  */
5142                   if (DECL_BIT_FIELD (field))
5143                     {
5144                       for (i = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
5145                            i < ((int_bit_position (field) + (bit_offset % 64))
5146                                 + tree_low_cst (DECL_SIZE (field), 0)
5147                                 + 63) / 8 / 8; i++)
5148                         classes[i] =
5149                           merge_classes (X86_64_INTEGER_CLASS,
5150                                          classes[i]);
5151                     }
5152                   else
5153                     {
5154                       int pos;
5155
5156                       type = TREE_TYPE (field);
5157
5158                       /* Flexible array member is ignored.  */
5159                       if (TYPE_MODE (type) == BLKmode
5160                           && TREE_CODE (type) == ARRAY_TYPE
5161                           && TYPE_SIZE (type) == NULL_TREE
5162                           && TYPE_DOMAIN (type) != NULL_TREE
5163                           && (TYPE_MAX_VALUE (TYPE_DOMAIN (type))
5164                               == NULL_TREE))
5165                         {
5166                           static bool warned;
5167                           
5168                           if (!warned && warn_psabi)
5169                             {
5170                               warned = true;
5171                               inform (input_location,
5172                                       "The ABI of passing struct with"
5173                                       " a flexible array member has"
5174                                       " changed in GCC 4.4");
5175                             }
5176                           continue;
5177                         }
5178                       num = classify_argument (TYPE_MODE (type), type,
5179                                                subclasses,
5180                                                (int_bit_position (field)
5181                                                 + bit_offset) % 256);
5182                       if (!num)
5183                         return 0;
5184                       pos = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
5185                       for (i = 0; i < num && (i + pos) < words; i++)
5186                         classes[i + pos] =
5187                           merge_classes (subclasses[i], classes[i + pos]);
5188                     }
5189                 }
5190             }
5191           break;
5192
5193         case ARRAY_TYPE:
5194           /* Arrays are handled as small records.  */
5195           {
5196             int num;
5197             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
5198                                      TREE_TYPE (type), subclasses, bit_offset);
5199             if (!num)
5200               return 0;
5201
5202             /* The partial classes are now full classes.  */
5203             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
5204               subclasses[0] = X86_64_SSE_CLASS;
5205             if (subclasses[0] == X86_64_INTEGERSI_CLASS
5206                 && !((bit_offset % 64) == 0 && bytes == 4))
5207               subclasses[0] = X86_64_INTEGER_CLASS;
5208
5209             for (i = 0; i < words; i++)
5210               classes[i] = subclasses[i % num];
5211
5212             break;
5213           }
5214         case UNION_TYPE:
5215         case QUAL_UNION_TYPE:
5216           /* Unions are similar to RECORD_TYPE but offset is always 0.
5217              */
5218           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5219             {
5220               if (TREE_CODE (field) == FIELD_DECL)
5221                 {
5222                   int num;
5223
5224                   if (TREE_TYPE (field) == error_mark_node)
5225                     continue;
5226
5227                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
5228                                            TREE_TYPE (field), subclasses,
5229                                            bit_offset);
5230                   if (!num)
5231                     return 0;
5232                   for (i = 0; i < num; i++)
5233                     classes[i] = merge_classes (subclasses[i], classes[i]);
5234                 }
5235             }
5236           break;
5237
5238         default:
5239           gcc_unreachable ();
5240         }
5241
5242       if (words > 2)
5243         {
5244           /* When size > 16 bytes, if the first one isn't
5245              X86_64_SSE_CLASS or any other ones aren't
5246              X86_64_SSEUP_CLASS, everything should be passed in
5247              memory.  */
5248           if (classes[0] != X86_64_SSE_CLASS)
5249               return 0;
5250
5251           for (i = 1; i < words; i++)
5252             if (classes[i] != X86_64_SSEUP_CLASS)
5253               return 0;
5254         }
5255
5256       /* Final merger cleanup.  */
5257       for (i = 0; i < words; i++)
5258         {
5259           /* If one class is MEMORY, everything should be passed in
5260              memory.  */
5261           if (classes[i] == X86_64_MEMORY_CLASS)
5262             return 0;
5263
5264           /* The X86_64_SSEUP_CLASS should be always preceded by
5265              X86_64_SSE_CLASS or X86_64_SSEUP_CLASS.  */
5266           if (classes[i] == X86_64_SSEUP_CLASS
5267               && classes[i - 1] != X86_64_SSE_CLASS
5268               && classes[i - 1] != X86_64_SSEUP_CLASS)
5269             {
5270               /* The first one should never be X86_64_SSEUP_CLASS.  */
5271               gcc_assert (i != 0);
5272               classes[i] = X86_64_SSE_CLASS;
5273             }
5274
5275           /*  If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
5276                everything should be passed in memory.  */
5277           if (classes[i] == X86_64_X87UP_CLASS
5278               && (classes[i - 1] != X86_64_X87_CLASS))
5279             {
5280               static bool warned;
5281
5282               /* The first one should never be X86_64_X87UP_CLASS.  */
5283               gcc_assert (i != 0);
5284               if (!warned && warn_psabi)
5285                 {
5286                   warned = true;
5287                   inform (input_location,
5288                           "The ABI of passing union with long double"
5289                           " has changed in GCC 4.4");
5290                 }
5291               return 0;
5292             }
5293         }
5294       return words;
5295     }
5296
5297   /* Compute alignment needed.  We align all types to natural boundaries with
5298      exception of XFmode that is aligned to 64bits.  */
5299   if (mode != VOIDmode && mode != BLKmode)
5300     {
5301       int mode_alignment = GET_MODE_BITSIZE (mode);
5302
5303       if (mode == XFmode)
5304         mode_alignment = 128;
5305       else if (mode == XCmode)
5306         mode_alignment = 256;
5307       if (COMPLEX_MODE_P (mode))
5308         mode_alignment /= 2;
5309       /* Misaligned fields are always returned in memory.  */
5310       if (bit_offset % mode_alignment)
5311         return 0;
5312     }
5313
5314   /* for V1xx modes, just use the base mode */
5315   if (VECTOR_MODE_P (mode) && mode != V1DImode
5316       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
5317     mode = GET_MODE_INNER (mode);
5318
5319   /* Classification of atomic types.  */
5320   switch (mode)
5321     {
5322     case SDmode:
5323     case DDmode:
5324       classes[0] = X86_64_SSE_CLASS;
5325       return 1;
5326     case TDmode:
5327       classes[0] = X86_64_SSE_CLASS;
5328       classes[1] = X86_64_SSEUP_CLASS;
5329       return 2;
5330     case DImode:
5331     case SImode:
5332     case HImode:
5333     case QImode:
5334     case CSImode:
5335     case CHImode:
5336     case CQImode:
5337       {
5338         int size = (bit_offset % 64)+ (int) GET_MODE_BITSIZE (mode);
5339
5340         if (size <= 32)
5341           {
5342             classes[0] = X86_64_INTEGERSI_CLASS;
5343             return 1;
5344           }
5345         else if (size <= 64)
5346           {
5347             classes[0] = X86_64_INTEGER_CLASS;
5348             return 1;
5349           }
5350         else if (size <= 64+32)
5351           {
5352             classes[0] = X86_64_INTEGER_CLASS;
5353             classes[1] = X86_64_INTEGERSI_CLASS;
5354             return 2;
5355           }
5356         else if (size <= 64+64)
5357           {
5358             classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5359             return 2;
5360           }
5361         else
5362           gcc_unreachable ();
5363       }
5364     case CDImode:
5365     case TImode:
5366       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5367       return 2;
5368     case COImode:
5369     case OImode:
5370       /* OImode shouldn't be used directly.  */
5371       gcc_unreachable ();
5372     case CTImode:
5373       return 0;
5374     case SFmode:
5375       if (!(bit_offset % 64))
5376         classes[0] = X86_64_SSESF_CLASS;
5377       else
5378         classes[0] = X86_64_SSE_CLASS;
5379       return 1;
5380     case DFmode:
5381       classes[0] = X86_64_SSEDF_CLASS;
5382       return 1;
5383     case XFmode:
5384       classes[0] = X86_64_X87_CLASS;
5385       classes[1] = X86_64_X87UP_CLASS;
5386       return 2;
5387     case TFmode:
5388       classes[0] = X86_64_SSE_CLASS;
5389       classes[1] = X86_64_SSEUP_CLASS;
5390       return 2;
5391     case SCmode:
5392       classes[0] = X86_64_SSE_CLASS;
5393       if (!(bit_offset % 64))
5394         return 1;
5395       else
5396         {
5397           static bool warned;
5398
5399           if (!warned && warn_psabi)
5400             {
5401               warned = true;
5402               inform (input_location,
5403                       "The ABI of passing structure with complex float"
5404                       " member has changed in GCC 4.4");
5405             }
5406           classes[1] = X86_64_SSESF_CLASS;
5407           return 2;
5408         }
5409     case DCmode:
5410       classes[0] = X86_64_SSEDF_CLASS;
5411       classes[1] = X86_64_SSEDF_CLASS;
5412       return 2;
5413     case XCmode:
5414       classes[0] = X86_64_COMPLEX_X87_CLASS;
5415       return 1;
5416     case TCmode:
5417       /* This modes is larger than 16 bytes.  */
5418       return 0;
5419     case V8SFmode:
5420     case V8SImode:
5421     case V32QImode:
5422     case V16HImode:
5423     case V4DFmode:
5424     case V4DImode:
5425       classes[0] = X86_64_SSE_CLASS;
5426       classes[1] = X86_64_SSEUP_CLASS;
5427       classes[2] = X86_64_SSEUP_CLASS;
5428       classes[3] = X86_64_SSEUP_CLASS;
5429       return 4;
5430     case V4SFmode:
5431     case V4SImode:
5432     case V16QImode:
5433     case V8HImode:
5434     case V2DFmode:
5435     case V2DImode:
5436       classes[0] = X86_64_SSE_CLASS;
5437       classes[1] = X86_64_SSEUP_CLASS;
5438       return 2;
5439     case V1DImode:
5440     case V2SFmode:
5441     case V2SImode:
5442     case V4HImode:
5443     case V8QImode:
5444       classes[0] = X86_64_SSE_CLASS;
5445       return 1;
5446     case BLKmode:
5447     case VOIDmode:
5448       return 0;
5449     default:
5450       gcc_assert (VECTOR_MODE_P (mode));
5451
5452       if (bytes > 16)
5453         return 0;
5454
5455       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
5456
5457       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5458         classes[0] = X86_64_INTEGERSI_CLASS;
5459       else
5460         classes[0] = X86_64_INTEGER_CLASS;
5461       classes[1] = X86_64_INTEGER_CLASS;
5462       return 1 + (bytes > 8);
5463     }
5464 }
5465
5466 /* Examine the argument and return set number of register required in each
5467    class.  Return 0 iff parameter should be passed in memory.  */
5468 static int
5469 examine_argument (enum machine_mode mode, const_tree type, int in_return,
5470                   int *int_nregs, int *sse_nregs)
5471 {
5472   enum x86_64_reg_class regclass[MAX_CLASSES];
5473   int n = classify_argument (mode, type, regclass, 0);
5474
5475   *int_nregs = 0;
5476   *sse_nregs = 0;
5477   if (!n)
5478     return 0;
5479   for (n--; n >= 0; n--)
5480     switch (regclass[n])
5481       {
5482       case X86_64_INTEGER_CLASS:
5483       case X86_64_INTEGERSI_CLASS:
5484         (*int_nregs)++;
5485         break;
5486       case X86_64_SSE_CLASS:
5487       case X86_64_SSESF_CLASS:
5488       case X86_64_SSEDF_CLASS:
5489         (*sse_nregs)++;
5490         break;
5491       case X86_64_NO_CLASS:
5492       case X86_64_SSEUP_CLASS:
5493         break;
5494       case X86_64_X87_CLASS:
5495       case X86_64_X87UP_CLASS:
5496         if (!in_return)
5497           return 0;
5498         break;
5499       case X86_64_COMPLEX_X87_CLASS:
5500         return in_return ? 2 : 0;
5501       case X86_64_MEMORY_CLASS:
5502         gcc_unreachable ();
5503       }
5504   return 1;
5505 }
5506
5507 /* Construct container for the argument used by GCC interface.  See
5508    FUNCTION_ARG for the detailed description.  */
5509
5510 static rtx
5511 construct_container (enum machine_mode mode, enum machine_mode orig_mode,
5512                      const_tree type, int in_return, int nintregs, int nsseregs,
5513                      const int *intreg, int sse_regno)
5514 {
5515   /* The following variables hold the static issued_error state.  */
5516   static bool issued_sse_arg_error;
5517   static bool issued_sse_ret_error;
5518   static bool issued_x87_ret_error;
5519
5520   enum machine_mode tmpmode;
5521   int bytes =
5522     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
5523   enum x86_64_reg_class regclass[MAX_CLASSES];
5524   int n;
5525   int i;
5526   int nexps = 0;
5527   int needed_sseregs, needed_intregs;
5528   rtx exp[MAX_CLASSES];
5529   rtx ret;
5530
5531   n = classify_argument (mode, type, regclass, 0);
5532   if (!n)
5533     return NULL;
5534   if (!examine_argument (mode, type, in_return, &needed_intregs,
5535                          &needed_sseregs))
5536     return NULL;
5537   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
5538     return NULL;
5539
5540   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
5541      some less clueful developer tries to use floating-point anyway.  */
5542   if (needed_sseregs && !TARGET_SSE)
5543     {
5544       if (in_return)
5545         {
5546           if (!issued_sse_ret_error)
5547             {
5548               error ("SSE register return with SSE disabled");
5549               issued_sse_ret_error = true;
5550             }
5551         }
5552       else if (!issued_sse_arg_error)
5553         {
5554           error ("SSE register argument with SSE disabled");
5555           issued_sse_arg_error = true;
5556         }
5557       return NULL;
5558     }
5559
5560   /* Likewise, error if the ABI requires us to return values in the
5561      x87 registers and the user specified -mno-80387.  */
5562   if (!TARGET_80387 && in_return)
5563     for (i = 0; i < n; i++)
5564       if (regclass[i] == X86_64_X87_CLASS
5565           || regclass[i] == X86_64_X87UP_CLASS
5566           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
5567         {
5568           if (!issued_x87_ret_error)
5569             {
5570               error ("x87 register return with x87 disabled");
5571               issued_x87_ret_error = true;
5572             }
5573           return NULL;
5574         }
5575
5576   /* First construct simple cases.  Avoid SCmode, since we want to use
5577      single register to pass this type.  */
5578   if (n == 1 && mode != SCmode)
5579     switch (regclass[0])
5580       {
5581       case X86_64_INTEGER_CLASS:
5582       case X86_64_INTEGERSI_CLASS:
5583         return gen_rtx_REG (mode, intreg[0]);
5584       case X86_64_SSE_CLASS:
5585       case X86_64_SSESF_CLASS:
5586       case X86_64_SSEDF_CLASS:
5587         if (mode != BLKmode)
5588           return gen_reg_or_parallel (mode, orig_mode, 
5589                                       SSE_REGNO (sse_regno));
5590         break;
5591       case X86_64_X87_CLASS:
5592       case X86_64_COMPLEX_X87_CLASS:
5593         return gen_rtx_REG (mode, FIRST_STACK_REG);
5594       case X86_64_NO_CLASS:
5595         /* Zero sized array, struct or class.  */
5596         return NULL;
5597       default:
5598         gcc_unreachable ();
5599       }
5600   if (n == 2 && regclass[0] == X86_64_SSE_CLASS
5601       && regclass[1] == X86_64_SSEUP_CLASS && mode != BLKmode)
5602     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5603   if (n == 4
5604       && regclass[0] == X86_64_SSE_CLASS
5605       && regclass[1] == X86_64_SSEUP_CLASS
5606       && regclass[2] == X86_64_SSEUP_CLASS
5607       && regclass[3] == X86_64_SSEUP_CLASS
5608       && mode != BLKmode)
5609     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5610
5611   if (n == 2
5612       && regclass[0] == X86_64_X87_CLASS && regclass[1] == X86_64_X87UP_CLASS)
5613     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
5614   if (n == 2 && regclass[0] == X86_64_INTEGER_CLASS
5615       && regclass[1] == X86_64_INTEGER_CLASS
5616       && (mode == CDImode || mode == TImode || mode == TFmode)
5617       && intreg[0] + 1 == intreg[1])
5618     return gen_rtx_REG (mode, intreg[0]);
5619
5620   /* Otherwise figure out the entries of the PARALLEL.  */
5621   for (i = 0; i < n; i++)
5622     {
5623       int pos;
5624
5625       switch (regclass[i])
5626         {
5627           case X86_64_NO_CLASS:
5628             break;
5629           case X86_64_INTEGER_CLASS:
5630           case X86_64_INTEGERSI_CLASS:
5631             /* Merge TImodes on aligned occasions here too.  */
5632             if (i * 8 + 8 > bytes)
5633               tmpmode = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
5634             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
5635               tmpmode = SImode;
5636             else
5637               tmpmode = DImode;
5638             /* We've requested 24 bytes we don't have mode for.  Use DImode.  */
5639             if (tmpmode == BLKmode)
5640               tmpmode = DImode;
5641             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5642                                                gen_rtx_REG (tmpmode, *intreg),
5643                                                GEN_INT (i*8));
5644             intreg++;
5645             break;
5646           case X86_64_SSESF_CLASS:
5647             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5648                                                gen_rtx_REG (SFmode,
5649                                                             SSE_REGNO (sse_regno)),
5650                                                GEN_INT (i*8));
5651             sse_regno++;
5652             break;
5653           case X86_64_SSEDF_CLASS:
5654             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5655                                                gen_rtx_REG (DFmode,
5656                                                             SSE_REGNO (sse_regno)),
5657                                                GEN_INT (i*8));
5658             sse_regno++;
5659             break;
5660           case X86_64_SSE_CLASS:
5661             pos = i;
5662             switch (n)
5663               {
5664               case 1:
5665                 tmpmode = DImode;
5666                 break;
5667               case 2:
5668                 if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
5669                   {
5670                     tmpmode = TImode;
5671                     i++;
5672                   }
5673                 else
5674                   tmpmode = DImode;
5675                 break;
5676               case 4:
5677                 gcc_assert (i == 0
5678                             && regclass[1] == X86_64_SSEUP_CLASS
5679                             && regclass[2] == X86_64_SSEUP_CLASS
5680                             && regclass[3] == X86_64_SSEUP_CLASS);
5681                 tmpmode = OImode;
5682                 i += 3;
5683                 break;
5684               default:
5685                 gcc_unreachable ();
5686               }
5687             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5688                                                gen_rtx_REG (tmpmode,
5689                                                             SSE_REGNO (sse_regno)),
5690                                                GEN_INT (pos*8));
5691             sse_regno++;
5692             break;
5693           default:
5694             gcc_unreachable ();
5695         }
5696     }
5697
5698   /* Empty aligned struct, union or class.  */
5699   if (nexps == 0)
5700     return NULL;
5701
5702   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
5703   for (i = 0; i < nexps; i++)
5704     XVECEXP (ret, 0, i) = exp [i];
5705   return ret;
5706 }
5707
5708 /* Update the data in CUM to advance over an argument of mode MODE
5709    and data type TYPE.  (TYPE is null for libcalls where that information
5710    may not be available.)  */
5711
5712 static void
5713 function_arg_advance_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5714                          tree type, HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5715 {
5716   switch (mode)
5717     {
5718     default:
5719       break;
5720
5721     case BLKmode:
5722       if (bytes < 0)
5723         break;
5724       /* FALLTHRU */
5725
5726     case DImode:
5727     case SImode:
5728     case HImode:
5729     case QImode:
5730       cum->words += words;
5731       cum->nregs -= words;
5732       cum->regno += words;
5733
5734       if (cum->nregs <= 0)
5735         {
5736           cum->nregs = 0;
5737           cum->regno = 0;
5738         }
5739       break;
5740
5741     case OImode:
5742       /* OImode shouldn't be used directly.  */
5743       gcc_unreachable ();
5744
5745     case DFmode:
5746       if (cum->float_in_sse < 2)
5747         break;
5748     case SFmode:
5749       if (cum->float_in_sse < 1)
5750         break;
5751       /* FALLTHRU */
5752
5753     case V8SFmode:
5754     case V8SImode:
5755     case V32QImode:
5756     case V16HImode:
5757     case V4DFmode:
5758     case V4DImode:
5759     case TImode:
5760     case V16QImode:
5761     case V8HImode:
5762     case V4SImode:
5763     case V2DImode:
5764     case V4SFmode:
5765     case V2DFmode:
5766       if (!type || !AGGREGATE_TYPE_P (type))
5767         {
5768           cum->sse_words += words;
5769           cum->sse_nregs -= 1;
5770           cum->sse_regno += 1;
5771           if (cum->sse_nregs <= 0)
5772             {
5773               cum->sse_nregs = 0;
5774               cum->sse_regno = 0;
5775             }
5776         }
5777       break;
5778
5779     case V8QImode:
5780     case V4HImode:
5781     case V2SImode:
5782     case V2SFmode:
5783     case V1DImode:
5784       if (!type || !AGGREGATE_TYPE_P (type))
5785         {
5786           cum->mmx_words += words;
5787           cum->mmx_nregs -= 1;
5788           cum->mmx_regno += 1;
5789           if (cum->mmx_nregs <= 0)
5790             {
5791               cum->mmx_nregs = 0;
5792               cum->mmx_regno = 0;
5793             }
5794         }
5795       break;
5796     }
5797 }
5798
5799 static void
5800 function_arg_advance_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5801                          tree type, HOST_WIDE_INT words, int named)
5802 {
5803   int int_nregs, sse_nregs;
5804
5805   /* Unnamed 256bit vector mode parameters are passed on stack.  */
5806   if (!named && VALID_AVX256_REG_MODE (mode))
5807     return;
5808
5809   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs))
5810     cum->words += words;
5811   else if (sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
5812     {
5813       cum->nregs -= int_nregs;
5814       cum->sse_nregs -= sse_nregs;
5815       cum->regno += int_nregs;
5816       cum->sse_regno += sse_nregs;
5817     }
5818   else
5819     cum->words += words;
5820 }
5821
5822 static void
5823 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
5824                             HOST_WIDE_INT words)
5825 {
5826   /* Otherwise, this should be passed indirect.  */
5827   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
5828
5829   cum->words += words;
5830   if (cum->nregs > 0)
5831     {
5832       cum->nregs -= 1;
5833       cum->regno += 1;
5834     }
5835 }
5836
5837 void
5838 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5839                       tree type, int named)
5840 {
5841   HOST_WIDE_INT bytes, words;
5842
5843   if (mode == BLKmode)
5844     bytes = int_size_in_bytes (type);
5845   else
5846     bytes = GET_MODE_SIZE (mode);
5847   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5848
5849   if (type)
5850     mode = type_natural_mode (type, NULL);
5851
5852   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
5853     function_arg_advance_ms_64 (cum, bytes, words);
5854   else if (TARGET_64BIT)
5855     function_arg_advance_64 (cum, mode, type, words, named);
5856   else
5857     function_arg_advance_32 (cum, mode, type, bytes, words);
5858 }
5859
5860 /* Define where to put the arguments to a function.
5861    Value is zero to push the argument on the stack,
5862    or a hard register in which to store the argument.
5863
5864    MODE is the argument's machine mode.
5865    TYPE is the data type of the argument (as a tree).
5866     This is null for libcalls where that information may
5867     not be available.
5868    CUM is a variable of type CUMULATIVE_ARGS which gives info about
5869     the preceding args and about the function being called.
5870    NAMED is nonzero if this argument is a named parameter
5871     (otherwise it is an extra parameter matching an ellipsis).  */
5872
5873 static rtx
5874 function_arg_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5875                  enum machine_mode orig_mode, tree type,
5876                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5877 {
5878   static bool warnedsse, warnedmmx;
5879
5880   /* Avoid the AL settings for the Unix64 ABI.  */
5881   if (mode == VOIDmode)
5882     return constm1_rtx;
5883
5884   switch (mode)
5885     {
5886     default:
5887       break;
5888
5889     case BLKmode:
5890       if (bytes < 0)
5891         break;
5892       /* FALLTHRU */
5893     case DImode:
5894     case SImode:
5895     case HImode:
5896     case QImode:
5897       if (words <= cum->nregs)
5898         {
5899           int regno = cum->regno;
5900
5901           /* Fastcall allocates the first two DWORD (SImode) or
5902             smaller arguments to ECX and EDX if it isn't an
5903             aggregate type .  */
5904           if (cum->fastcall)
5905             {
5906               if (mode == BLKmode
5907                   || mode == DImode
5908                   || (type && AGGREGATE_TYPE_P (type)))
5909                 break;
5910
5911               /* ECX not EAX is the first allocated register.  */
5912               if (regno == AX_REG)
5913                 regno = CX_REG;
5914             }
5915           return gen_rtx_REG (mode, regno);
5916         }
5917       break;
5918
5919     case DFmode:
5920       if (cum->float_in_sse < 2)
5921         break;
5922     case SFmode:
5923       if (cum->float_in_sse < 1)
5924         break;
5925       /* FALLTHRU */
5926     case TImode:
5927       /* In 32bit, we pass TImode in xmm registers.  */
5928     case V16QImode:
5929     case V8HImode:
5930     case V4SImode:
5931     case V2DImode:
5932     case V4SFmode:
5933     case V2DFmode:
5934       if (!type || !AGGREGATE_TYPE_P (type))
5935         {
5936           if (!TARGET_SSE && !warnedsse && cum->warn_sse)
5937             {
5938               warnedsse = true;
5939               warning (0, "SSE vector argument without SSE enabled "
5940                        "changes the ABI");
5941             }
5942           if (cum->sse_nregs)
5943             return gen_reg_or_parallel (mode, orig_mode,
5944                                         cum->sse_regno + FIRST_SSE_REG);
5945         }
5946       break;
5947
5948     case OImode:
5949       /* OImode shouldn't be used directly.  */
5950       gcc_unreachable ();
5951
5952     case V8SFmode:
5953     case V8SImode:
5954     case V32QImode:
5955     case V16HImode:
5956     case V4DFmode:
5957     case V4DImode:
5958       if (!type || !AGGREGATE_TYPE_P (type))
5959         {
5960           if (cum->sse_nregs)
5961             return gen_reg_or_parallel (mode, orig_mode,
5962                                         cum->sse_regno + FIRST_SSE_REG);
5963         }
5964       break;
5965
5966     case V8QImode:
5967     case V4HImode:
5968     case V2SImode:
5969     case V2SFmode:
5970     case V1DImode:
5971       if (!type || !AGGREGATE_TYPE_P (type))
5972         {
5973           if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
5974             {
5975               warnedmmx = true;
5976               warning (0, "MMX vector argument without MMX enabled "
5977                        "changes the ABI");
5978             }
5979           if (cum->mmx_nregs)
5980             return gen_reg_or_parallel (mode, orig_mode,
5981                                         cum->mmx_regno + FIRST_MMX_REG);
5982         }
5983       break;
5984     }
5985
5986   return NULL_RTX;
5987 }
5988
5989 static rtx
5990 function_arg_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5991                  enum machine_mode orig_mode, tree type, int named)
5992 {
5993   /* Handle a hidden AL argument containing number of registers
5994      for varargs x86-64 functions.  */
5995   if (mode == VOIDmode)
5996     return GEN_INT (cum->maybe_vaarg
5997                     ? (cum->sse_nregs < 0
5998                        ? (cum->call_abi == ix86_abi
5999                           ? SSE_REGPARM_MAX
6000                           : (ix86_abi != SYSV_ABI
6001                              ? X86_64_SSE_REGPARM_MAX
6002                              : X86_64_MS_SSE_REGPARM_MAX))
6003                        : cum->sse_regno)
6004                     : -1);
6005
6006   switch (mode)
6007     {
6008     default:
6009       break;
6010
6011     case V8SFmode:
6012     case V8SImode:
6013     case V32QImode:
6014     case V16HImode:
6015     case V4DFmode:
6016     case V4DImode:
6017       /* Unnamed 256bit vector mode parameters are passed on stack.  */
6018       if (!named)
6019         return NULL;
6020       break;
6021     }
6022
6023   return construct_container (mode, orig_mode, type, 0, cum->nregs,
6024                               cum->sse_nregs,
6025                               &x86_64_int_parameter_registers [cum->regno],
6026                               cum->sse_regno);
6027 }
6028
6029 static rtx
6030 function_arg_ms_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
6031                     enum machine_mode orig_mode, int named,
6032                     HOST_WIDE_INT bytes)
6033 {
6034   unsigned int regno;
6035
6036   /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
6037      We use value of -2 to specify that current function call is MSABI.  */
6038   if (mode == VOIDmode)
6039     return GEN_INT (-2);
6040
6041   /* If we've run out of registers, it goes on the stack.  */
6042   if (cum->nregs == 0)
6043     return NULL_RTX;
6044
6045   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
6046
6047   /* Only floating point modes are passed in anything but integer regs.  */
6048   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
6049     {
6050       if (named)
6051         regno = cum->regno + FIRST_SSE_REG;
6052       else
6053         {
6054           rtx t1, t2;
6055
6056           /* Unnamed floating parameters are passed in both the
6057              SSE and integer registers.  */
6058           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
6059           t2 = gen_rtx_REG (mode, regno);
6060           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
6061           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
6062           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
6063         }
6064     }
6065   /* Handle aggregated types passed in register.  */
6066   if (orig_mode == BLKmode)
6067     {
6068       if (bytes > 0 && bytes <= 8)
6069         mode = (bytes > 4 ? DImode : SImode);
6070       if (mode == BLKmode)
6071         mode = DImode;
6072     }
6073
6074   return gen_reg_or_parallel (mode, orig_mode, regno);
6075 }
6076
6077 rtx
6078 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
6079               tree type, int named)
6080 {
6081   enum machine_mode mode = omode;
6082   HOST_WIDE_INT bytes, words;
6083
6084   if (mode == BLKmode)
6085     bytes = int_size_in_bytes (type);
6086   else
6087     bytes = GET_MODE_SIZE (mode);
6088   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6089
6090   /* To simplify the code below, represent vector types with a vector mode
6091      even if MMX/SSE are not active.  */
6092   if (type && TREE_CODE (type) == VECTOR_TYPE)
6093     mode = type_natural_mode (type, cum);
6094
6095   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
6096     return function_arg_ms_64 (cum, mode, omode, named, bytes);
6097   else if (TARGET_64BIT)
6098     return function_arg_64 (cum, mode, omode, type, named);
6099   else
6100     return function_arg_32 (cum, mode, omode, type, bytes, words);
6101 }
6102
6103 /* A C expression that indicates when an argument must be passed by
6104    reference.  If nonzero for an argument, a copy of that argument is
6105    made in memory and a pointer to the argument is passed instead of
6106    the argument itself.  The pointer is passed in whatever way is
6107    appropriate for passing a pointer to that type.  */
6108
6109 static bool
6110 ix86_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
6111                         enum machine_mode mode ATTRIBUTE_UNUSED,
6112                         const_tree type, bool named ATTRIBUTE_UNUSED)
6113 {
6114   /* See Windows x64 Software Convention.  */
6115   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
6116     {
6117       int msize = (int) GET_MODE_SIZE (mode);
6118       if (type)
6119         {
6120           /* Arrays are passed by reference.  */
6121           if (TREE_CODE (type) == ARRAY_TYPE)
6122             return true;
6123
6124           if (AGGREGATE_TYPE_P (type))
6125             {
6126               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
6127                  are passed by reference.  */
6128               msize = int_size_in_bytes (type);
6129             }
6130         }
6131
6132       /* __m128 is passed by reference.  */
6133       switch (msize) {
6134       case 1: case 2: case 4: case 8:
6135         break;
6136       default:
6137         return true;
6138       }
6139     }
6140   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
6141     return 1;
6142
6143   return 0;
6144 }
6145
6146 /* Return true when TYPE should be 128bit aligned for 32bit argument passing
6147    ABI.  */
6148 static bool
6149 contains_aligned_value_p (tree type)
6150 {
6151   enum machine_mode mode = TYPE_MODE (type);
6152   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
6153        || mode == TDmode
6154        || mode == TFmode
6155        || mode == TCmode)
6156       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
6157     return true;
6158   if (TYPE_ALIGN (type) < 128)
6159     return false;
6160
6161   if (AGGREGATE_TYPE_P (type))
6162     {
6163       /* Walk the aggregates recursively.  */
6164       switch (TREE_CODE (type))
6165         {
6166         case RECORD_TYPE:
6167         case UNION_TYPE:
6168         case QUAL_UNION_TYPE:
6169           {
6170             tree field;
6171
6172             /* Walk all the structure fields.  */
6173             for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
6174               {
6175                 if (TREE_CODE (field) == FIELD_DECL
6176                     && contains_aligned_value_p (TREE_TYPE (field)))
6177                   return true;
6178               }
6179             break;
6180           }
6181
6182         case ARRAY_TYPE:
6183           /* Just for use if some languages passes arrays by value.  */
6184           if (contains_aligned_value_p (TREE_TYPE (type)))
6185             return true;
6186           break;
6187
6188         default:
6189           gcc_unreachable ();
6190         }
6191     }
6192   return false;
6193 }
6194
6195 /* Gives the alignment boundary, in bits, of an argument with the
6196    specified mode and type.  */
6197
6198 int
6199 ix86_function_arg_boundary (enum machine_mode mode, tree type)
6200 {
6201   int align;
6202   if (type)
6203     {
6204       /* Since canonical type is used for call, we convert it to
6205          canonical type if needed.  */
6206       if (!TYPE_STRUCTURAL_EQUALITY_P (type))
6207         type = TYPE_CANONICAL (type);
6208       align = TYPE_ALIGN (type);
6209     }
6210   else
6211     align = GET_MODE_ALIGNMENT (mode);
6212   if (align < PARM_BOUNDARY)
6213     align = PARM_BOUNDARY;
6214   /* In 32bit, only _Decimal128 and __float128 are aligned to their
6215      natural boundaries.  */
6216   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
6217     {
6218       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
6219          make an exception for SSE modes since these require 128bit
6220          alignment.
6221
6222          The handling here differs from field_alignment.  ICC aligns MMX
6223          arguments to 4 byte boundaries, while structure fields are aligned
6224          to 8 byte boundaries.  */
6225       if (!type)
6226         {
6227           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
6228             align = PARM_BOUNDARY;
6229         }
6230       else
6231         {
6232           if (!contains_aligned_value_p (type))
6233             align = PARM_BOUNDARY;
6234         }
6235     }
6236   if (align > BIGGEST_ALIGNMENT)
6237     align = BIGGEST_ALIGNMENT;
6238   return align;
6239 }
6240
6241 /* Return true if N is a possible register number of function value.  */
6242
6243 bool
6244 ix86_function_value_regno_p (int regno)
6245 {
6246   switch (regno)
6247     {
6248     case 0:
6249       return true;
6250
6251     case FIRST_FLOAT_REG:
6252       /* TODO: The function should depend on current function ABI but
6253        builtins.c would need updating then. Therefore we use the
6254        default ABI.  */
6255       if (TARGET_64BIT && ix86_abi == MS_ABI)
6256         return false;
6257       return TARGET_FLOAT_RETURNS_IN_80387;
6258
6259     case FIRST_SSE_REG:
6260       return TARGET_SSE;
6261
6262     case FIRST_MMX_REG:
6263       if (TARGET_MACHO || TARGET_64BIT)
6264         return false;
6265       return TARGET_MMX;
6266     }
6267
6268   return false;
6269 }
6270
6271 /* Define how to find the value returned by a function.
6272    VALTYPE is the data type of the value (as a tree).
6273    If the precise function being called is known, FUNC is its FUNCTION_DECL;
6274    otherwise, FUNC is 0.  */
6275
6276 static rtx
6277 function_value_32 (enum machine_mode orig_mode, enum machine_mode mode,
6278                    const_tree fntype, const_tree fn)
6279 {
6280   unsigned int regno;
6281
6282   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
6283      we normally prevent this case when mmx is not available.  However
6284      some ABIs may require the result to be returned like DImode.  */
6285   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6286     regno = TARGET_MMX ? FIRST_MMX_REG : 0;
6287
6288   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
6289      we prevent this case when sse is not available.  However some ABIs
6290      may require the result to be returned like integer TImode.  */
6291   else if (mode == TImode
6292            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6293     regno = TARGET_SSE ? FIRST_SSE_REG : 0;
6294
6295   /* 32-byte vector modes in %ymm0.   */
6296   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32)
6297     regno = TARGET_AVX ? FIRST_SSE_REG : 0;
6298
6299   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
6300   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
6301     regno = FIRST_FLOAT_REG;
6302   else
6303     /* Most things go in %eax.  */
6304     regno = AX_REG;
6305
6306   /* Override FP return register with %xmm0 for local functions when
6307      SSE math is enabled or for functions with sseregparm attribute.  */
6308   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
6309     {
6310       int sse_level = ix86_function_sseregparm (fntype, fn, false);
6311       if ((sse_level >= 1 && mode == SFmode)
6312           || (sse_level == 2 && mode == DFmode))
6313         regno = FIRST_SSE_REG;
6314     }
6315
6316   /* OImode shouldn't be used directly.  */
6317   gcc_assert (mode != OImode);
6318
6319   return gen_rtx_REG (orig_mode, regno);
6320 }
6321
6322 static rtx
6323 function_value_64 (enum machine_mode orig_mode, enum machine_mode mode,
6324                    const_tree valtype)
6325 {
6326   rtx ret;
6327
6328   /* Handle libcalls, which don't provide a type node.  */
6329   if (valtype == NULL)
6330     {
6331       switch (mode)
6332         {
6333         case SFmode:
6334         case SCmode:
6335         case DFmode:
6336         case DCmode:
6337         case TFmode:
6338         case SDmode:
6339         case DDmode:
6340         case TDmode:
6341           return gen_rtx_REG (mode, FIRST_SSE_REG);
6342         case XFmode:
6343         case XCmode:
6344           return gen_rtx_REG (mode, FIRST_FLOAT_REG);
6345         case TCmode:
6346           return NULL;
6347         default:
6348           return gen_rtx_REG (mode, AX_REG);
6349         }
6350     }
6351
6352   ret = construct_container (mode, orig_mode, valtype, 1,
6353                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
6354                              x86_64_int_return_registers, 0);
6355
6356   /* For zero sized structures, construct_container returns NULL, but we
6357      need to keep rest of compiler happy by returning meaningful value.  */
6358   if (!ret)
6359     ret = gen_rtx_REG (orig_mode, AX_REG);
6360
6361   return ret;
6362 }
6363
6364 static rtx
6365 function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
6366 {
6367   unsigned int regno = AX_REG;
6368
6369   if (TARGET_SSE)
6370     {
6371       switch (GET_MODE_SIZE (mode))
6372         {
6373         case 16:
6374           if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6375              && !COMPLEX_MODE_P (mode))
6376             regno = FIRST_SSE_REG;
6377           break;
6378         case 8:
6379         case 4:
6380           if (mode == SFmode || mode == DFmode)
6381             regno = FIRST_SSE_REG;
6382           break;
6383         default:
6384           break;
6385         }
6386     }
6387   return gen_rtx_REG (orig_mode, regno);
6388 }
6389
6390 static rtx
6391 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
6392                        enum machine_mode orig_mode, enum machine_mode mode)
6393 {
6394   const_tree fn, fntype;
6395
6396   fn = NULL_TREE;
6397   if (fntype_or_decl && DECL_P (fntype_or_decl))
6398     fn = fntype_or_decl;
6399   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
6400
6401   if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
6402     return function_value_ms_64 (orig_mode, mode);
6403   else if (TARGET_64BIT)
6404     return function_value_64 (orig_mode, mode, valtype);
6405   else
6406     return function_value_32 (orig_mode, mode, fntype, fn);
6407 }
6408
6409 static rtx
6410 ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
6411                      bool outgoing ATTRIBUTE_UNUSED)
6412 {
6413   enum machine_mode mode, orig_mode;
6414
6415   orig_mode = TYPE_MODE (valtype);
6416   mode = type_natural_mode (valtype, NULL);
6417   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
6418 }
6419
6420 rtx
6421 ix86_libcall_value (enum machine_mode mode)
6422 {
6423   return ix86_function_value_1 (NULL, NULL, mode, mode);
6424 }
6425
6426 /* Return true iff type is returned in memory.  */
6427
6428 static int ATTRIBUTE_UNUSED
6429 return_in_memory_32 (const_tree type, enum machine_mode mode)
6430 {
6431   HOST_WIDE_INT size;
6432
6433   if (mode == BLKmode)
6434     return 1;
6435
6436   size = int_size_in_bytes (type);
6437
6438   if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
6439     return 0;
6440
6441   if (VECTOR_MODE_P (mode) || mode == TImode)
6442     {
6443       /* User-created vectors small enough to fit in EAX.  */
6444       if (size < 8)
6445         return 0;
6446
6447       /* MMX/3dNow values are returned in MM0,
6448          except when it doesn't exits.  */
6449       if (size == 8)
6450         return (TARGET_MMX ? 0 : 1);
6451
6452       /* SSE values are returned in XMM0, except when it doesn't exist.  */
6453       if (size == 16)
6454         return (TARGET_SSE ? 0 : 1);
6455
6456       /* AVX values are returned in YMM0, except when it doesn't exist.  */
6457       if (size == 32)
6458         return TARGET_AVX ? 0 : 1;
6459     }
6460
6461   if (mode == XFmode)
6462     return 0;
6463
6464   if (size > 12)
6465     return 1;
6466
6467   /* OImode shouldn't be used directly.  */
6468   gcc_assert (mode != OImode);
6469
6470   return 0;
6471 }
6472
6473 static int ATTRIBUTE_UNUSED
6474 return_in_memory_64 (const_tree type, enum machine_mode mode)
6475 {
6476   int needed_intregs, needed_sseregs;
6477   return !examine_argument (mode, type, 1, &needed_intregs, &needed_sseregs);
6478 }
6479
6480 static int ATTRIBUTE_UNUSED
6481 return_in_memory_ms_64 (const_tree type, enum machine_mode mode)
6482 {
6483   HOST_WIDE_INT size = int_size_in_bytes (type);
6484
6485   /* __m128 is returned in xmm0.  */
6486   if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6487       && !COMPLEX_MODE_P (mode) && (GET_MODE_SIZE (mode) == 16 || size == 16))
6488     return 0;
6489
6490   /* Otherwise, the size must be exactly in [1248]. */
6491   return (size != 1 && size != 2 && size != 4 && size != 8);
6492 }
6493
6494 static bool
6495 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6496 {
6497 #ifdef SUBTARGET_RETURN_IN_MEMORY
6498   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
6499 #else
6500   const enum machine_mode mode = type_natural_mode (type, NULL);
6501  
6502   if (TARGET_64BIT)
6503     {
6504       if (ix86_function_type_abi (fntype) == MS_ABI)
6505         return return_in_memory_ms_64 (type, mode);
6506       else
6507         return return_in_memory_64 (type, mode);
6508     }
6509   else
6510     return return_in_memory_32 (type, mode);
6511 #endif
6512 }
6513
6514 /* Return false iff TYPE is returned in memory.  This version is used
6515    on Solaris 10.  It is similar to the generic ix86_return_in_memory,
6516    but differs notably in that when MMX is available, 8-byte vectors
6517    are returned in memory, rather than in MMX registers.  */
6518
6519 bool
6520 ix86_sol10_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6521 {
6522   int size;
6523   enum machine_mode mode = type_natural_mode (type, NULL);
6524
6525   if (TARGET_64BIT)
6526     return return_in_memory_64 (type, mode);
6527
6528   if (mode == BLKmode)
6529     return 1;
6530
6531   size = int_size_in_bytes (type);
6532
6533   if (VECTOR_MODE_P (mode))
6534     {
6535       /* Return in memory only if MMX registers *are* available.  This
6536          seems backwards, but it is consistent with the existing
6537          Solaris x86 ABI.  */
6538       if (size == 8)
6539         return TARGET_MMX;
6540       if (size == 16)
6541         return !TARGET_SSE;
6542     }
6543   else if (mode == TImode)
6544     return !TARGET_SSE;
6545   else if (mode == XFmode)
6546     return 0;
6547
6548   return size > 12;
6549 }
6550
6551 /* When returning SSE vector types, we have a choice of either
6552      (1) being abi incompatible with a -march switch, or
6553      (2) generating an error.
6554    Given no good solution, I think the safest thing is one warning.
6555    The user won't be able to use -Werror, but....
6556
6557    Choose the STRUCT_VALUE_RTX hook because that's (at present) only
6558    called in response to actually generating a caller or callee that
6559    uses such a type.  As opposed to TARGET_RETURN_IN_MEMORY, which is called
6560    via aggregate_value_p for general type probing from tree-ssa.  */
6561
6562 static rtx
6563 ix86_struct_value_rtx (tree type, int incoming ATTRIBUTE_UNUSED)
6564 {
6565   static bool warnedsse, warnedmmx;
6566
6567   if (!TARGET_64BIT && type)
6568     {
6569       /* Look at the return type of the function, not the function type.  */
6570       enum machine_mode mode = TYPE_MODE (TREE_TYPE (type));
6571
6572       if (!TARGET_SSE && !warnedsse)
6573         {
6574           if (mode == TImode
6575               || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6576             {
6577               warnedsse = true;
6578               warning (0, "SSE vector return without SSE enabled "
6579                        "changes the ABI");
6580             }
6581         }
6582
6583       if (!TARGET_MMX && !warnedmmx)
6584         {
6585           if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6586             {
6587               warnedmmx = true;
6588               warning (0, "MMX vector return without MMX enabled "
6589                        "changes the ABI");
6590             }
6591         }
6592     }
6593
6594   return NULL;
6595 }
6596
6597 \f
6598 /* Create the va_list data type.  */
6599
6600 /* Returns the calling convention specific va_list date type.
6601    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
6602
6603 static tree
6604 ix86_build_builtin_va_list_abi (enum calling_abi abi)
6605 {
6606   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
6607
6608   /* For i386 we use plain pointer to argument area.  */
6609   if (!TARGET_64BIT || abi == MS_ABI)
6610     return build_pointer_type (char_type_node);
6611
6612   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6613   type_decl = build_decl (BUILTINS_LOCATION,
6614                           TYPE_DECL, get_identifier ("__va_list_tag"), record);
6615
6616   f_gpr = build_decl (BUILTINS_LOCATION,
6617                       FIELD_DECL, get_identifier ("gp_offset"),
6618                       unsigned_type_node);
6619   f_fpr = build_decl (BUILTINS_LOCATION,
6620                       FIELD_DECL, get_identifier ("fp_offset"),
6621                       unsigned_type_node);
6622   f_ovf = build_decl (BUILTINS_LOCATION,
6623                       FIELD_DECL, get_identifier ("overflow_arg_area"),
6624                       ptr_type_node);
6625   f_sav = build_decl (BUILTINS_LOCATION,
6626                       FIELD_DECL, get_identifier ("reg_save_area"),
6627                       ptr_type_node);
6628
6629   va_list_gpr_counter_field = f_gpr;
6630   va_list_fpr_counter_field = f_fpr;
6631
6632   DECL_FIELD_CONTEXT (f_gpr) = record;
6633   DECL_FIELD_CONTEXT (f_fpr) = record;
6634   DECL_FIELD_CONTEXT (f_ovf) = record;
6635   DECL_FIELD_CONTEXT (f_sav) = record;
6636
6637   TREE_CHAIN (record) = type_decl;
6638   TYPE_NAME (record) = type_decl;
6639   TYPE_FIELDS (record) = f_gpr;
6640   TREE_CHAIN (f_gpr) = f_fpr;
6641   TREE_CHAIN (f_fpr) = f_ovf;
6642   TREE_CHAIN (f_ovf) = f_sav;
6643
6644   layout_type (record);
6645
6646   /* The correct type is an array type of one element.  */
6647   return build_array_type (record, build_index_type (size_zero_node));
6648 }
6649
6650 /* Setup the builtin va_list data type and for 64-bit the additional
6651    calling convention specific va_list data types.  */
6652
6653 static tree
6654 ix86_build_builtin_va_list (void)
6655 {
6656   tree ret = ix86_build_builtin_va_list_abi (ix86_abi);
6657
6658   /* Initialize abi specific va_list builtin types.  */
6659   if (TARGET_64BIT)
6660     {
6661       tree t;
6662       if (ix86_abi == MS_ABI)
6663         {
6664           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
6665           if (TREE_CODE (t) != RECORD_TYPE)
6666             t = build_variant_type_copy (t);
6667           sysv_va_list_type_node = t;
6668         }
6669       else
6670         {
6671           t = ret;
6672           if (TREE_CODE (t) != RECORD_TYPE)
6673             t = build_variant_type_copy (t);
6674           sysv_va_list_type_node = t;
6675         }
6676       if (ix86_abi != MS_ABI)
6677         {
6678           t = ix86_build_builtin_va_list_abi (MS_ABI);
6679           if (TREE_CODE (t) != RECORD_TYPE)
6680             t = build_variant_type_copy (t);
6681           ms_va_list_type_node = t;
6682         }
6683       else
6684         {
6685           t = ret;
6686           if (TREE_CODE (t) != RECORD_TYPE)
6687             t = build_variant_type_copy (t);
6688           ms_va_list_type_node = t;
6689         }
6690     }
6691
6692   return ret;
6693 }
6694
6695 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
6696
6697 static void
6698 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
6699 {
6700   rtx save_area, mem;
6701   rtx label;
6702   rtx label_ref;
6703   rtx tmp_reg;
6704   rtx nsse_reg;
6705   alias_set_type set;
6706   int i;
6707   int regparm = ix86_regparm;
6708
6709   if (cum->call_abi != ix86_abi)
6710     regparm = (ix86_abi != SYSV_ABI
6711                ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
6712
6713   /* GPR size of varargs save area.  */
6714   if (cfun->va_list_gpr_size)
6715     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
6716   else
6717     ix86_varargs_gpr_size = 0;
6718
6719   /* FPR size of varargs save area.  We don't need it if we don't pass
6720      anything in SSE registers.  */
6721   if (cum->sse_nregs && cfun->va_list_fpr_size)
6722     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
6723   else
6724     ix86_varargs_fpr_size = 0;
6725
6726   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
6727     return;
6728
6729   save_area = frame_pointer_rtx;
6730   set = get_varargs_alias_set ();
6731
6732   for (i = cum->regno;
6733        i < regparm
6734        && i < cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
6735        i++)
6736     {
6737       mem = gen_rtx_MEM (Pmode,
6738                          plus_constant (save_area, i * UNITS_PER_WORD));
6739       MEM_NOTRAP_P (mem) = 1;
6740       set_mem_alias_set (mem, set);
6741       emit_move_insn (mem, gen_rtx_REG (Pmode,
6742                                         x86_64_int_parameter_registers[i]));
6743     }
6744
6745   if (ix86_varargs_fpr_size)
6746     {
6747       /* Now emit code to save SSE registers.  The AX parameter contains number
6748          of SSE parameter registers used to call this function.  We use
6749          sse_prologue_save insn template that produces computed jump across
6750          SSE saves.  We need some preparation work to get this working.  */
6751
6752       label = gen_label_rtx ();
6753       label_ref = gen_rtx_LABEL_REF (Pmode, label);
6754
6755       /* Compute address to jump to :
6756          label - eax*4 + nnamed_sse_arguments*4 Or
6757          label - eax*5 + nnamed_sse_arguments*5 for AVX.  */
6758       tmp_reg = gen_reg_rtx (Pmode);
6759       nsse_reg = gen_reg_rtx (Pmode);
6760       emit_insn (gen_zero_extendqidi2 (nsse_reg, gen_rtx_REG (QImode, AX_REG)));
6761       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6762                               gen_rtx_MULT (Pmode, nsse_reg,
6763                                             GEN_INT (4))));
6764
6765       /* vmovaps is one byte longer than movaps.  */
6766       if (TARGET_AVX)
6767         emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6768                                 gen_rtx_PLUS (Pmode, tmp_reg,
6769                                               nsse_reg)));
6770
6771       if (cum->sse_regno)
6772         emit_move_insn
6773           (nsse_reg,
6774            gen_rtx_CONST (DImode,
6775                           gen_rtx_PLUS (DImode,
6776                                         label_ref,
6777                                         GEN_INT (cum->sse_regno
6778                                                  * (TARGET_AVX ? 5 : 4)))));
6779       else
6780         emit_move_insn (nsse_reg, label_ref);
6781       emit_insn (gen_subdi3 (nsse_reg, nsse_reg, tmp_reg));
6782
6783       /* Compute address of memory block we save into.  We always use pointer
6784          pointing 127 bytes after first byte to store - this is needed to keep
6785          instruction size limited by 4 bytes (5 bytes for AVX) with one
6786          byte displacement.  */
6787       tmp_reg = gen_reg_rtx (Pmode);
6788       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6789                               plus_constant (save_area,
6790                                              ix86_varargs_gpr_size + 127)));
6791       mem = gen_rtx_MEM (BLKmode, plus_constant (tmp_reg, -127));
6792       MEM_NOTRAP_P (mem) = 1;
6793       set_mem_alias_set (mem, set);
6794       set_mem_align (mem, BITS_PER_WORD);
6795
6796       /* And finally do the dirty job!  */
6797       emit_insn (gen_sse_prologue_save (mem, nsse_reg,
6798                                         GEN_INT (cum->sse_regno), label));
6799     }
6800 }
6801
6802 static void
6803 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
6804 {
6805   alias_set_type set = get_varargs_alias_set ();
6806   int i;
6807
6808   for (i = cum->regno; i < X86_64_MS_REGPARM_MAX; i++)
6809     {
6810       rtx reg, mem;
6811
6812       mem = gen_rtx_MEM (Pmode,
6813                          plus_constant (virtual_incoming_args_rtx,
6814                                         i * UNITS_PER_WORD));
6815       MEM_NOTRAP_P (mem) = 1;
6816       set_mem_alias_set (mem, set);
6817
6818       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
6819       emit_move_insn (mem, reg);
6820     }
6821 }
6822
6823 static void
6824 ix86_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
6825                              tree type, int *pretend_size ATTRIBUTE_UNUSED,
6826                              int no_rtl)
6827 {
6828   CUMULATIVE_ARGS next_cum;
6829   tree fntype;
6830
6831   /* This argument doesn't appear to be used anymore.  Which is good,
6832      because the old code here didn't suppress rtl generation.  */
6833   gcc_assert (!no_rtl);
6834
6835   if (!TARGET_64BIT)
6836     return;
6837
6838   fntype = TREE_TYPE (current_function_decl);
6839
6840   /* For varargs, we do not want to skip the dummy va_dcl argument.
6841      For stdargs, we do want to skip the last named argument.  */
6842   next_cum = *cum;
6843   if (stdarg_p (fntype))
6844     function_arg_advance (&next_cum, mode, type, 1);
6845
6846   if (cum->call_abi == MS_ABI)
6847     setup_incoming_varargs_ms_64 (&next_cum);
6848   else
6849     setup_incoming_varargs_64 (&next_cum);
6850 }
6851
6852 /* Checks if TYPE is of kind va_list char *.  */
6853
6854 static bool
6855 is_va_list_char_pointer (tree type)
6856 {
6857   tree canonic;
6858
6859   /* For 32-bit it is always true.  */
6860   if (!TARGET_64BIT)
6861     return true;
6862   canonic = ix86_canonical_va_list_type (type);
6863   return (canonic == ms_va_list_type_node
6864           || (ix86_abi == MS_ABI && canonic == va_list_type_node));
6865 }
6866
6867 /* Implement va_start.  */
6868
6869 static void
6870 ix86_va_start (tree valist, rtx nextarg)
6871 {
6872   HOST_WIDE_INT words, n_gpr, n_fpr;
6873   tree f_gpr, f_fpr, f_ovf, f_sav;
6874   tree gpr, fpr, ovf, sav, t;
6875   tree type;
6876
6877   /* Only 64bit target needs something special.  */
6878   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6879     {
6880       std_expand_builtin_va_start (valist, nextarg);
6881       return;
6882     }
6883
6884   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6885   f_fpr = TREE_CHAIN (f_gpr);
6886   f_ovf = TREE_CHAIN (f_fpr);
6887   f_sav = TREE_CHAIN (f_ovf);
6888
6889   valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
6890   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6891   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6892   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6893   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6894
6895   /* Count number of gp and fp argument registers used.  */
6896   words = crtl->args.info.words;
6897   n_gpr = crtl->args.info.regno;
6898   n_fpr = crtl->args.info.sse_regno;
6899
6900   if (cfun->va_list_gpr_size)
6901     {
6902       type = TREE_TYPE (gpr);
6903       t = build2 (MODIFY_EXPR, type,
6904                   gpr, build_int_cst (type, n_gpr * 8));
6905       TREE_SIDE_EFFECTS (t) = 1;
6906       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6907     }
6908
6909   if (TARGET_SSE && cfun->va_list_fpr_size)
6910     {
6911       type = TREE_TYPE (fpr);
6912       t = build2 (MODIFY_EXPR, type, fpr,
6913                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
6914       TREE_SIDE_EFFECTS (t) = 1;
6915       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6916     }
6917
6918   /* Find the overflow area.  */
6919   type = TREE_TYPE (ovf);
6920   t = make_tree (type, crtl->args.internal_arg_pointer);
6921   if (words != 0)
6922     t = build2 (POINTER_PLUS_EXPR, type, t,
6923                 size_int (words * UNITS_PER_WORD));
6924   t = build2 (MODIFY_EXPR, type, ovf, t);
6925   TREE_SIDE_EFFECTS (t) = 1;
6926   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6927
6928   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
6929     {
6930       /* Find the register save area.
6931          Prologue of the function save it right above stack frame.  */
6932       type = TREE_TYPE (sav);
6933       t = make_tree (type, frame_pointer_rtx);
6934       if (!ix86_varargs_gpr_size)
6935         t = build2 (POINTER_PLUS_EXPR, type, t,
6936                     size_int (-8 * X86_64_REGPARM_MAX));
6937       t = build2 (MODIFY_EXPR, type, sav, t);
6938       TREE_SIDE_EFFECTS (t) = 1;
6939       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6940     }
6941 }
6942
6943 /* Implement va_arg.  */
6944
6945 static tree
6946 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
6947                       gimple_seq *post_p)
6948 {
6949   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
6950   tree f_gpr, f_fpr, f_ovf, f_sav;
6951   tree gpr, fpr, ovf, sav, t;
6952   int size, rsize;
6953   tree lab_false, lab_over = NULL_TREE;
6954   tree addr, t2;
6955   rtx container;
6956   int indirect_p = 0;
6957   tree ptrtype;
6958   enum machine_mode nat_mode;
6959   int arg_boundary;
6960
6961   /* Only 64bit target needs something special.  */
6962   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6963     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6964
6965   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6966   f_fpr = TREE_CHAIN (f_gpr);
6967   f_ovf = TREE_CHAIN (f_fpr);
6968   f_sav = TREE_CHAIN (f_ovf);
6969
6970   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
6971                 build_va_arg_indirect_ref (valist), f_gpr, NULL_TREE);
6972   valist = build_va_arg_indirect_ref (valist);
6973   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6974   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6975   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6976
6977   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
6978   if (indirect_p)
6979     type = build_pointer_type (type);
6980   size = int_size_in_bytes (type);
6981   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6982
6983   nat_mode = type_natural_mode (type, NULL);
6984   switch (nat_mode)
6985     {
6986     case V8SFmode:
6987     case V8SImode:
6988     case V32QImode:
6989     case V16HImode:
6990     case V4DFmode:
6991     case V4DImode:
6992       /* Unnamed 256bit vector mode parameters are passed on stack.  */
6993       if (ix86_cfun_abi () == SYSV_ABI)
6994         {
6995           container = NULL;
6996           break;
6997         }
6998
6999     default:
7000       container = construct_container (nat_mode, TYPE_MODE (type),
7001                                        type, 0, X86_64_REGPARM_MAX,
7002                                        X86_64_SSE_REGPARM_MAX, intreg,
7003                                        0);
7004       break;
7005     }
7006
7007   /* Pull the value out of the saved registers.  */
7008
7009   addr = create_tmp_var (ptr_type_node, "addr");
7010
7011   if (container)
7012     {
7013       int needed_intregs, needed_sseregs;
7014       bool need_temp;
7015       tree int_addr, sse_addr;
7016
7017       lab_false = create_artificial_label (UNKNOWN_LOCATION);
7018       lab_over = create_artificial_label (UNKNOWN_LOCATION);
7019
7020       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
7021
7022       need_temp = (!REG_P (container)
7023                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
7024                        || TYPE_ALIGN (type) > 128));
7025
7026       /* In case we are passing structure, verify that it is consecutive block
7027          on the register save area.  If not we need to do moves.  */
7028       if (!need_temp && !REG_P (container))
7029         {
7030           /* Verify that all registers are strictly consecutive  */
7031           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
7032             {
7033               int i;
7034
7035               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
7036                 {
7037                   rtx slot = XVECEXP (container, 0, i);
7038                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
7039                       || INTVAL (XEXP (slot, 1)) != i * 16)
7040                     need_temp = 1;
7041                 }
7042             }
7043           else
7044             {
7045               int i;
7046
7047               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
7048                 {
7049                   rtx slot = XVECEXP (container, 0, i);
7050                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
7051                       || INTVAL (XEXP (slot, 1)) != i * 8)
7052                     need_temp = 1;
7053                 }
7054             }
7055         }
7056       if (!need_temp)
7057         {
7058           int_addr = addr;
7059           sse_addr = addr;
7060         }
7061       else
7062         {
7063           int_addr = create_tmp_var (ptr_type_node, "int_addr");
7064           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
7065         }
7066
7067       /* First ensure that we fit completely in registers.  */
7068       if (needed_intregs)
7069         {
7070           t = build_int_cst (TREE_TYPE (gpr),
7071                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
7072           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
7073           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
7074           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
7075           gimplify_and_add (t, pre_p);
7076         }
7077       if (needed_sseregs)
7078         {
7079           t = build_int_cst (TREE_TYPE (fpr),
7080                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
7081                              + X86_64_REGPARM_MAX * 8);
7082           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
7083           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
7084           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
7085           gimplify_and_add (t, pre_p);
7086         }
7087
7088       /* Compute index to start of area used for integer regs.  */
7089       if (needed_intregs)
7090         {
7091           /* int_addr = gpr + sav; */
7092           t = fold_convert (sizetype, gpr);
7093           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
7094           gimplify_assign (int_addr, t, pre_p);
7095         }
7096       if (needed_sseregs)
7097         {
7098           /* sse_addr = fpr + sav; */
7099           t = fold_convert (sizetype, fpr);
7100           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
7101           gimplify_assign (sse_addr, t, pre_p);
7102         }
7103       if (need_temp)
7104         {
7105           int i;
7106           tree temp = create_tmp_var (type, "va_arg_tmp");
7107
7108           /* addr = &temp; */
7109           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
7110           gimplify_assign (addr, t, pre_p);
7111
7112           for (i = 0; i < XVECLEN (container, 0); i++)
7113             {
7114               rtx slot = XVECEXP (container, 0, i);
7115               rtx reg = XEXP (slot, 0);
7116               enum machine_mode mode = GET_MODE (reg);
7117               tree piece_type = lang_hooks.types.type_for_mode (mode, 1);
7118               tree addr_type = build_pointer_type (piece_type);
7119               tree daddr_type = build_pointer_type_for_mode (piece_type,
7120                                                              ptr_mode, true);
7121               tree src_addr, src;
7122               int src_offset;
7123               tree dest_addr, dest;
7124
7125               if (SSE_REGNO_P (REGNO (reg)))
7126                 {
7127                   src_addr = sse_addr;
7128                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
7129                 }
7130               else
7131                 {
7132                   src_addr = int_addr;
7133                   src_offset = REGNO (reg) * 8;
7134                 }
7135               src_addr = fold_convert (addr_type, src_addr);
7136               src_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, src_addr,
7137                                       size_int (src_offset));
7138               src = build_va_arg_indirect_ref (src_addr);
7139
7140               dest_addr = fold_convert (daddr_type, addr);
7141               dest_addr = fold_build2 (POINTER_PLUS_EXPR, daddr_type, dest_addr,
7142                                        size_int (INTVAL (XEXP (slot, 1))));
7143               dest = build_va_arg_indirect_ref (dest_addr);
7144
7145               gimplify_assign (dest, src, pre_p);
7146             }
7147         }
7148
7149       if (needed_intregs)
7150         {
7151           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
7152                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
7153           gimplify_assign (gpr, t, pre_p);
7154         }
7155
7156       if (needed_sseregs)
7157         {
7158           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
7159                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
7160           gimplify_assign (fpr, t, pre_p);
7161         }
7162
7163       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
7164
7165       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
7166     }
7167
7168   /* ... otherwise out of the overflow area.  */
7169
7170   /* When we align parameter on stack for caller, if the parameter
7171      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
7172      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
7173      here with caller.  */
7174   arg_boundary = FUNCTION_ARG_BOUNDARY (VOIDmode, type);
7175   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
7176     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
7177
7178   /* Care for on-stack alignment if needed.  */
7179   if (arg_boundary <= 64
7180       || integer_zerop (TYPE_SIZE (type)))
7181     t = ovf;
7182  else
7183     {
7184       HOST_WIDE_INT align = arg_boundary / 8;
7185       t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovf), ovf,
7186                   size_int (align - 1));
7187       t = fold_convert (sizetype, t);
7188       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
7189                   size_int (-align));
7190       t = fold_convert (TREE_TYPE (ovf), t);
7191     }
7192   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
7193   gimplify_assign (addr, t, pre_p);
7194
7195   t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
7196               size_int (rsize * UNITS_PER_WORD));
7197   gimplify_assign (unshare_expr (ovf), t, pre_p);
7198
7199   if (container)
7200     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
7201
7202   ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
7203   addr = fold_convert (ptrtype, addr);
7204
7205   if (indirect_p)
7206     addr = build_va_arg_indirect_ref (addr);
7207   return build_va_arg_indirect_ref (addr);
7208 }
7209 \f
7210 /* Return nonzero if OPNUM's MEM should be matched
7211    in movabs* patterns.  */
7212
7213 int
7214 ix86_check_movabs (rtx insn, int opnum)
7215 {
7216   rtx set, mem;
7217
7218   set = PATTERN (insn);
7219   if (GET_CODE (set) == PARALLEL)
7220     set = XVECEXP (set, 0, 0);
7221   gcc_assert (GET_CODE (set) == SET);
7222   mem = XEXP (set, opnum);
7223   while (GET_CODE (mem) == SUBREG)
7224     mem = SUBREG_REG (mem);
7225   gcc_assert (MEM_P (mem));
7226   return (volatile_ok || !MEM_VOLATILE_P (mem));
7227 }
7228 \f
7229 /* Initialize the table of extra 80387 mathematical constants.  */
7230
7231 static void
7232 init_ext_80387_constants (void)
7233 {
7234   static const char * cst[5] =
7235   {
7236     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
7237     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
7238     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
7239     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
7240     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
7241   };
7242   int i;
7243
7244   for (i = 0; i < 5; i++)
7245     {
7246       real_from_string (&ext_80387_constants_table[i], cst[i]);
7247       /* Ensure each constant is rounded to XFmode precision.  */
7248       real_convert (&ext_80387_constants_table[i],
7249                     XFmode, &ext_80387_constants_table[i]);
7250     }
7251
7252   ext_80387_constants_init = 1;
7253 }
7254
7255 /* Return true if the constant is something that can be loaded with
7256    a special instruction.  */
7257
7258 int
7259 standard_80387_constant_p (rtx x)
7260 {
7261   enum machine_mode mode = GET_MODE (x);
7262
7263   REAL_VALUE_TYPE r;
7264
7265   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
7266     return -1;
7267
7268   if (x == CONST0_RTX (mode))
7269     return 1;
7270   if (x == CONST1_RTX (mode))
7271     return 2;
7272
7273   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
7274
7275   /* For XFmode constants, try to find a special 80387 instruction when
7276      optimizing for size or on those CPUs that benefit from them.  */
7277   if (mode == XFmode
7278       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
7279     {
7280       int i;
7281
7282       if (! ext_80387_constants_init)
7283         init_ext_80387_constants ();
7284
7285       for (i = 0; i < 5; i++)
7286         if (real_identical (&r, &ext_80387_constants_table[i]))
7287           return i + 3;
7288     }
7289
7290   /* Load of the constant -0.0 or -1.0 will be split as
7291      fldz;fchs or fld1;fchs sequence.  */
7292   if (real_isnegzero (&r))
7293     return 8;
7294   if (real_identical (&r, &dconstm1))
7295     return 9;
7296
7297   return 0;
7298 }
7299
7300 /* Return the opcode of the special instruction to be used to load
7301    the constant X.  */
7302
7303 const char *
7304 standard_80387_constant_opcode (rtx x)
7305 {
7306   switch (standard_80387_constant_p (x))
7307     {
7308     case 1:
7309       return "fldz";
7310     case 2:
7311       return "fld1";
7312     case 3:
7313       return "fldlg2";
7314     case 4:
7315       return "fldln2";
7316     case 5:
7317       return "fldl2e";
7318     case 6:
7319       return "fldl2t";
7320     case 7:
7321       return "fldpi";
7322     case 8:
7323     case 9:
7324       return "#";
7325     default:
7326       gcc_unreachable ();
7327     }
7328 }
7329
7330 /* Return the CONST_DOUBLE representing the 80387 constant that is
7331    loaded by the specified special instruction.  The argument IDX
7332    matches the return value from standard_80387_constant_p.  */
7333
7334 rtx
7335 standard_80387_constant_rtx (int idx)
7336 {
7337   int i;
7338
7339   if (! ext_80387_constants_init)
7340     init_ext_80387_constants ();
7341
7342   switch (idx)
7343     {
7344     case 3:
7345     case 4:
7346     case 5:
7347     case 6:
7348     case 7:
7349       i = idx - 3;
7350       break;
7351
7352     default:
7353       gcc_unreachable ();
7354     }
7355
7356   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
7357                                        XFmode);
7358 }
7359
7360 /* Return 1 if X is all 0s and 2 if x is all 1s
7361    in supported SSE vector mode.  */
7362
7363 int
7364 standard_sse_constant_p (rtx x)
7365 {
7366   enum machine_mode mode = GET_MODE (x);
7367
7368   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
7369     return 1;
7370   if (vector_all_ones_operand (x, mode))
7371     switch (mode)
7372       {
7373       case V16QImode:
7374       case V8HImode:
7375       case V4SImode:
7376       case V2DImode:
7377         if (TARGET_SSE2)
7378           return 2;
7379       default:
7380         break;
7381       }
7382
7383   return 0;
7384 }
7385
7386 /* Return the opcode of the special instruction to be used to load
7387    the constant X.  */
7388
7389 const char *
7390 standard_sse_constant_opcode (rtx insn, rtx x)
7391 {
7392   switch (standard_sse_constant_p (x))
7393     {
7394     case 1:
7395       switch (get_attr_mode (insn))
7396         {
7397         case MODE_V4SF:
7398           return TARGET_AVX ? "vxorps\t%0, %0, %0" : "xorps\t%0, %0";
7399         case MODE_V2DF:
7400           return TARGET_AVX ? "vxorpd\t%0, %0, %0" : "xorpd\t%0, %0";
7401         case MODE_TI:
7402           return TARGET_AVX ? "vpxor\t%0, %0, %0" : "pxor\t%0, %0";
7403         case MODE_V8SF:
7404           return "vxorps\t%x0, %x0, %x0";
7405         case MODE_V4DF:
7406           return "vxorpd\t%x0, %x0, %x0";
7407         case MODE_OI:
7408           return "vpxor\t%x0, %x0, %x0";
7409         default:
7410           break;
7411         }
7412     case 2:
7413       return TARGET_AVX ? "vpcmpeqd\t%0, %0, %0" : "pcmpeqd\t%0, %0";
7414     default:
7415       break;
7416     }
7417   gcc_unreachable ();
7418 }
7419
7420 /* Returns 1 if OP contains a symbol reference */
7421
7422 int
7423 symbolic_reference_mentioned_p (rtx op)
7424 {
7425   const char *fmt;
7426   int i;
7427
7428   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
7429     return 1;
7430
7431   fmt = GET_RTX_FORMAT (GET_CODE (op));
7432   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
7433     {
7434       if (fmt[i] == 'E')
7435         {
7436           int j;
7437
7438           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
7439             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
7440               return 1;
7441         }
7442
7443       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
7444         return 1;
7445     }
7446
7447   return 0;
7448 }
7449
7450 /* Return 1 if it is appropriate to emit `ret' instructions in the
7451    body of a function.  Do this only if the epilogue is simple, needing a
7452    couple of insns.  Prior to reloading, we can't tell how many registers
7453    must be saved, so return 0 then.  Return 0 if there is no frame
7454    marker to de-allocate.  */
7455
7456 int
7457 ix86_can_use_return_insn_p (void)
7458 {
7459   struct ix86_frame frame;
7460
7461   if (! reload_completed || frame_pointer_needed)
7462     return 0;
7463
7464   /* Don't allow more than 32 pop, since that's all we can do
7465      with one instruction.  */
7466   if (crtl->args.pops_args
7467       && crtl->args.size >= 32768)
7468     return 0;
7469
7470   ix86_compute_frame_layout (&frame);
7471   return frame.to_allocate == 0 && (frame.nregs + frame.nsseregs) == 0;
7472 }
7473 \f
7474 /* Value should be nonzero if functions must have frame pointers.
7475    Zero means the frame pointer need not be set up (and parms may
7476    be accessed via the stack pointer) in functions that seem suitable.  */
7477
7478 static bool
7479 ix86_frame_pointer_required (void)
7480 {
7481   /* If we accessed previous frames, then the generated code expects
7482      to be able to access the saved ebp value in our frame.  */
7483   if (cfun->machine->accesses_prev_frame)
7484     return true;
7485
7486   /* Several x86 os'es need a frame pointer for other reasons,
7487      usually pertaining to setjmp.  */
7488   if (SUBTARGET_FRAME_POINTER_REQUIRED)
7489     return true;
7490
7491   /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
7492      the frame pointer by default.  Turn it back on now if we've not
7493      got a leaf function.  */
7494   if (TARGET_OMIT_LEAF_FRAME_POINTER
7495       && (!current_function_is_leaf
7496           || ix86_current_function_calls_tls_descriptor))
7497     return true;
7498
7499   if (crtl->profile)
7500     return true;
7501
7502   return false;
7503 }
7504
7505 /* Record that the current function accesses previous call frames.  */
7506
7507 void
7508 ix86_setup_frame_addresses (void)
7509 {
7510   cfun->machine->accesses_prev_frame = 1;
7511 }
7512 \f
7513 #ifndef USE_HIDDEN_LINKONCE
7514 # if (defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)) || TARGET_MACHO
7515 #  define USE_HIDDEN_LINKONCE 1
7516 # else
7517 #  define USE_HIDDEN_LINKONCE 0
7518 # endif
7519 #endif
7520
7521 static int pic_labels_used;
7522
7523 /* Fills in the label name that should be used for a pc thunk for
7524    the given register.  */
7525
7526 static void
7527 get_pc_thunk_name (char name[32], unsigned int regno)
7528 {
7529   gcc_assert (!TARGET_64BIT);
7530
7531   if (USE_HIDDEN_LINKONCE)
7532     sprintf (name, "__i686.get_pc_thunk.%s", reg_names[regno]);
7533   else
7534     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
7535 }
7536
7537
7538 /* This function generates code for -fpic that loads %ebx with
7539    the return address of the caller and then returns.  */
7540
7541 void
7542 ix86_file_end (void)
7543 {
7544   rtx xops[2];
7545   int regno;
7546
7547   for (regno = 0; regno < 8; ++regno)
7548     {
7549       char name[32];
7550
7551       if (! ((pic_labels_used >> regno) & 1))
7552         continue;
7553
7554       get_pc_thunk_name (name, regno);
7555
7556 #if TARGET_MACHO
7557       if (TARGET_MACHO)
7558         {
7559           switch_to_section (darwin_sections[text_coal_section]);
7560           fputs ("\t.weak_definition\t", asm_out_file);
7561           assemble_name (asm_out_file, name);
7562           fputs ("\n\t.private_extern\t", asm_out_file);
7563           assemble_name (asm_out_file, name);
7564           fputs ("\n", asm_out_file);
7565           ASM_OUTPUT_LABEL (asm_out_file, name);
7566         }
7567       else
7568 #endif
7569       if (USE_HIDDEN_LINKONCE)
7570         {
7571           tree decl;
7572
7573           decl = build_decl (BUILTINS_LOCATION,
7574                              FUNCTION_DECL, get_identifier (name),
7575                              error_mark_node);
7576           TREE_PUBLIC (decl) = 1;
7577           TREE_STATIC (decl) = 1;
7578           DECL_COMDAT_GROUP (decl) = DECL_ASSEMBLER_NAME (decl);
7579
7580           (*targetm.asm_out.unique_section) (decl, 0);
7581           switch_to_section (get_named_section (decl, NULL, 0));
7582
7583           (*targetm.asm_out.globalize_label) (asm_out_file, name);
7584           fputs ("\t.hidden\t", asm_out_file);
7585           assemble_name (asm_out_file, name);
7586           putc ('\n', asm_out_file);
7587           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
7588         }
7589       else
7590         {
7591           switch_to_section (text_section);
7592           ASM_OUTPUT_LABEL (asm_out_file, name);
7593         }
7594
7595       xops[0] = gen_rtx_REG (Pmode, regno);
7596       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
7597       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
7598       output_asm_insn ("ret", xops);
7599     }
7600
7601   if (NEED_INDICATE_EXEC_STACK)
7602     file_end_indicate_exec_stack ();
7603 }
7604
7605 /* Emit code for the SET_GOT patterns.  */
7606
7607 const char *
7608 output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
7609 {
7610   rtx xops[3];
7611
7612   xops[0] = dest;
7613
7614   if (TARGET_VXWORKS_RTP && flag_pic)
7615     {
7616       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
7617       xops[2] = gen_rtx_MEM (Pmode,
7618                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
7619       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
7620
7621       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
7622          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
7623          an unadorned address.  */
7624       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7625       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
7626       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
7627       return "";
7628     }
7629
7630   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
7631
7632   if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
7633     {
7634       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
7635
7636       if (!flag_pic)
7637         output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
7638       else
7639         output_asm_insn ("call\t%a2", xops);
7640
7641 #if TARGET_MACHO
7642       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7643          is what will be referenced by the Mach-O PIC subsystem.  */
7644       if (!label)
7645         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7646 #endif
7647
7648       (*targetm.asm_out.internal_label) (asm_out_file, "L",
7649                                  CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
7650
7651       if (flag_pic)
7652         output_asm_insn ("pop%z0\t%0", xops);
7653     }
7654   else
7655     {
7656       char name[32];
7657       get_pc_thunk_name (name, REGNO (dest));
7658       pic_labels_used |= 1 << REGNO (dest);
7659
7660       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
7661       xops[2] = gen_rtx_MEM (QImode, xops[2]);
7662       output_asm_insn ("call\t%X2", xops);
7663       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7664          is what will be referenced by the Mach-O PIC subsystem.  */
7665 #if TARGET_MACHO
7666       if (!label)
7667         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7668       else
7669         targetm.asm_out.internal_label (asm_out_file, "L",
7670                                            CODE_LABEL_NUMBER (label));
7671 #endif
7672     }
7673
7674   if (TARGET_MACHO)
7675     return "";
7676
7677   if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
7678     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
7679   else
7680     output_asm_insn ("add%z0\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
7681
7682   return "";
7683 }
7684
7685 /* Generate an "push" pattern for input ARG.  */
7686
7687 static rtx
7688 gen_push (rtx arg)
7689 {
7690   if (ix86_cfa_state->reg == stack_pointer_rtx)
7691     ix86_cfa_state->offset += UNITS_PER_WORD;
7692
7693   return gen_rtx_SET (VOIDmode,
7694                       gen_rtx_MEM (Pmode,
7695                                    gen_rtx_PRE_DEC (Pmode,
7696                                                     stack_pointer_rtx)),
7697                       arg);
7698 }
7699
7700 /* Return >= 0 if there is an unused call-clobbered register available
7701    for the entire function.  */
7702
7703 static unsigned int
7704 ix86_select_alt_pic_regnum (void)
7705 {
7706   if (current_function_is_leaf && !crtl->profile
7707       && !ix86_current_function_calls_tls_descriptor)
7708     {
7709       int i, drap;
7710       /* Can't use the same register for both PIC and DRAP.  */
7711       if (crtl->drap_reg)
7712         drap = REGNO (crtl->drap_reg);
7713       else
7714         drap = -1;
7715       for (i = 2; i >= 0; --i)
7716         if (i != drap && !df_regs_ever_live_p (i))
7717           return i;
7718     }
7719
7720   return INVALID_REGNUM;
7721 }
7722
7723 /* Return 1 if we need to save REGNO.  */
7724 static int
7725 ix86_save_reg (unsigned int regno, int maybe_eh_return)
7726 {
7727   if (pic_offset_table_rtx
7728       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
7729       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
7730           || crtl->profile
7731           || crtl->calls_eh_return
7732           || crtl->uses_const_pool))
7733     {
7734       if (ix86_select_alt_pic_regnum () != INVALID_REGNUM)
7735         return 0;
7736       return 1;
7737     }
7738
7739   if (crtl->calls_eh_return && maybe_eh_return)
7740     {
7741       unsigned i;
7742       for (i = 0; ; i++)
7743         {
7744           unsigned test = EH_RETURN_DATA_REGNO (i);
7745           if (test == INVALID_REGNUM)
7746             break;
7747           if (test == regno)
7748             return 1;
7749         }
7750     }
7751
7752   if (crtl->drap_reg && regno == REGNO (crtl->drap_reg))
7753     return 1;
7754
7755   return (df_regs_ever_live_p (regno)
7756           && !call_used_regs[regno]
7757           && !fixed_regs[regno]
7758           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
7759 }
7760
7761 /* Return number of saved general prupose registers.  */
7762
7763 static int
7764 ix86_nsaved_regs (void)
7765 {
7766   int nregs = 0;
7767   int regno;
7768
7769   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7770     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7771       nregs ++;
7772   return nregs;
7773 }
7774
7775 /* Return number of saved SSE registrers.  */
7776
7777 static int
7778 ix86_nsaved_sseregs (void)
7779 {
7780   int nregs = 0;
7781   int regno;
7782
7783   if (ix86_cfun_abi () != MS_ABI)
7784     return 0;
7785   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7786     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7787       nregs ++;
7788   return nregs;
7789 }
7790
7791 /* Given FROM and TO register numbers, say whether this elimination is
7792    allowed.  If stack alignment is needed, we can only replace argument
7793    pointer with hard frame pointer, or replace frame pointer with stack
7794    pointer.  Otherwise, frame pointer elimination is automatically
7795    handled and all other eliminations are valid.  */
7796
7797 int
7798 ix86_can_eliminate (int from, int to)
7799 {
7800   if (stack_realign_fp)
7801     return ((from == ARG_POINTER_REGNUM
7802              && to == HARD_FRAME_POINTER_REGNUM)
7803             || (from == FRAME_POINTER_REGNUM
7804                 && to == STACK_POINTER_REGNUM));
7805   else
7806     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : 1;
7807 }
7808
7809 /* Return the offset between two registers, one to be eliminated, and the other
7810    its replacement, at the start of a routine.  */
7811
7812 HOST_WIDE_INT
7813 ix86_initial_elimination_offset (int from, int to)
7814 {
7815   struct ix86_frame frame;
7816   ix86_compute_frame_layout (&frame);
7817
7818   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
7819     return frame.hard_frame_pointer_offset;
7820   else if (from == FRAME_POINTER_REGNUM
7821            && to == HARD_FRAME_POINTER_REGNUM)
7822     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
7823   else
7824     {
7825       gcc_assert (to == STACK_POINTER_REGNUM);
7826
7827       if (from == ARG_POINTER_REGNUM)
7828         return frame.stack_pointer_offset;
7829
7830       gcc_assert (from == FRAME_POINTER_REGNUM);
7831       return frame.stack_pointer_offset - frame.frame_pointer_offset;
7832     }
7833 }
7834
7835 /* In a dynamically-aligned function, we can't know the offset from
7836    stack pointer to frame pointer, so we must ensure that setjmp
7837    eliminates fp against the hard fp (%ebp) rather than trying to
7838    index from %esp up to the top of the frame across a gap that is
7839    of unknown (at compile-time) size.  */
7840 static rtx
7841 ix86_builtin_setjmp_frame_value (void)
7842 {
7843   return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
7844 }
7845
7846 /* Fill structure ix86_frame about frame of currently computed function.  */
7847
7848 static void
7849 ix86_compute_frame_layout (struct ix86_frame *frame)
7850 {
7851   HOST_WIDE_INT total_size;
7852   unsigned int stack_alignment_needed;
7853   HOST_WIDE_INT offset;
7854   unsigned int preferred_alignment;
7855   HOST_WIDE_INT size = get_frame_size ();
7856
7857   frame->nregs = ix86_nsaved_regs ();
7858   frame->nsseregs = ix86_nsaved_sseregs ();
7859   total_size = size;
7860
7861   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
7862   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
7863
7864   /* MS ABI seem to require stack alignment to be always 16 except for function
7865      prologues.  */
7866   if (ix86_cfun_abi () == MS_ABI && preferred_alignment < 16)
7867     {
7868       preferred_alignment = 16;
7869       stack_alignment_needed = 16;
7870       crtl->preferred_stack_boundary = 128;
7871       crtl->stack_alignment_needed = 128;
7872     }
7873
7874   gcc_assert (!size || stack_alignment_needed);
7875   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
7876   gcc_assert (preferred_alignment <= stack_alignment_needed);
7877
7878   /* During reload iteration the amount of registers saved can change.
7879      Recompute the value as needed.  Do not recompute when amount of registers
7880      didn't change as reload does multiple calls to the function and does not
7881      expect the decision to change within single iteration.  */
7882   if (!optimize_function_for_size_p (cfun)
7883       && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
7884     {
7885       int count = frame->nregs;
7886
7887       cfun->machine->use_fast_prologue_epilogue_nregs = count;
7888       /* The fast prologue uses move instead of push to save registers.  This
7889          is significantly longer, but also executes faster as modern hardware
7890          can execute the moves in parallel, but can't do that for push/pop.
7891
7892          Be careful about choosing what prologue to emit:  When function takes
7893          many instructions to execute we may use slow version as well as in
7894          case function is known to be outside hot spot (this is known with
7895          feedback only).  Weight the size of function by number of registers
7896          to save as it is cheap to use one or two push instructions but very
7897          slow to use many of them.  */
7898       if (count)
7899         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7900       if (cfun->function_frequency < FUNCTION_FREQUENCY_NORMAL
7901           || (flag_branch_probabilities
7902               && cfun->function_frequency < FUNCTION_FREQUENCY_HOT))
7903         cfun->machine->use_fast_prologue_epilogue = false;
7904       else
7905         cfun->machine->use_fast_prologue_epilogue
7906            = !expensive_function_p (count);
7907     }
7908   if (TARGET_PROLOGUE_USING_MOVE
7909       && cfun->machine->use_fast_prologue_epilogue)
7910     frame->save_regs_using_mov = true;
7911   else
7912     frame->save_regs_using_mov = false;
7913
7914
7915   /* Skip return address and saved base pointer.  */
7916   offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
7917
7918   frame->hard_frame_pointer_offset = offset;
7919
7920   /* Set offset to aligned because the realigned frame starts from
7921      here.  */
7922   if (stack_realign_fp)
7923     offset = (offset + stack_alignment_needed -1) & -stack_alignment_needed;
7924
7925   /* Register save area */
7926   offset += frame->nregs * UNITS_PER_WORD;
7927
7928   /* Align SSE reg save area.  */
7929   if (frame->nsseregs)
7930     frame->padding0 = ((offset + 16 - 1) & -16) - offset;
7931   else
7932     frame->padding0 = 0;
7933   
7934   /* SSE register save area.  */
7935   offset += frame->padding0 + frame->nsseregs * 16;
7936
7937   /* Va-arg area */
7938   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
7939   offset += frame->va_arg_size;
7940
7941   /* Align start of frame for local function.  */
7942   frame->padding1 = ((offset + stack_alignment_needed - 1)
7943                      & -stack_alignment_needed) - offset;
7944
7945   offset += frame->padding1;
7946
7947   /* Frame pointer points here.  */
7948   frame->frame_pointer_offset = offset;
7949
7950   offset += size;
7951
7952   /* Add outgoing arguments area.  Can be skipped if we eliminated
7953      all the function calls as dead code.
7954      Skipping is however impossible when function calls alloca.  Alloca
7955      expander assumes that last crtl->outgoing_args_size
7956      of stack frame are unused.  */
7957   if (ACCUMULATE_OUTGOING_ARGS
7958       && (!current_function_is_leaf || cfun->calls_alloca
7959           || ix86_current_function_calls_tls_descriptor))
7960     {
7961       offset += crtl->outgoing_args_size;
7962       frame->outgoing_arguments_size = crtl->outgoing_args_size;
7963     }
7964   else
7965     frame->outgoing_arguments_size = 0;
7966
7967   /* Align stack boundary.  Only needed if we're calling another function
7968      or using alloca.  */
7969   if (!current_function_is_leaf || cfun->calls_alloca
7970       || ix86_current_function_calls_tls_descriptor)
7971     frame->padding2 = ((offset + preferred_alignment - 1)
7972                        & -preferred_alignment) - offset;
7973   else
7974     frame->padding2 = 0;
7975
7976   offset += frame->padding2;
7977
7978   /* We've reached end of stack frame.  */
7979   frame->stack_pointer_offset = offset;
7980
7981   /* Size prologue needs to allocate.  */
7982   frame->to_allocate =
7983     (size + frame->padding1 + frame->padding2
7984      + frame->outgoing_arguments_size + frame->va_arg_size);
7985
7986   if ((!frame->to_allocate && frame->nregs <= 1)
7987       || (TARGET_64BIT && frame->to_allocate >= (HOST_WIDE_INT) 0x80000000))
7988     frame->save_regs_using_mov = false;
7989
7990   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
7991       && current_function_sp_is_unchanging
7992       && current_function_is_leaf
7993       && !ix86_current_function_calls_tls_descriptor)
7994     {
7995       frame->red_zone_size = frame->to_allocate;
7996       if (frame->save_regs_using_mov)
7997         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7998       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7999         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
8000     }
8001   else
8002     frame->red_zone_size = 0;
8003   frame->to_allocate -= frame->red_zone_size;
8004   frame->stack_pointer_offset -= frame->red_zone_size;
8005 #if 0
8006   fprintf (stderr, "\n");
8007   fprintf (stderr, "size: %ld\n", (long)size);
8008   fprintf (stderr, "nregs: %ld\n", (long)frame->nregs);
8009   fprintf (stderr, "nsseregs: %ld\n", (long)frame->nsseregs);
8010   fprintf (stderr, "padding0: %ld\n", (long)frame->padding0);
8011   fprintf (stderr, "alignment1: %ld\n", (long)stack_alignment_needed);
8012   fprintf (stderr, "padding1: %ld\n", (long)frame->padding1);
8013   fprintf (stderr, "va_arg: %ld\n", (long)frame->va_arg_size);
8014   fprintf (stderr, "padding2: %ld\n", (long)frame->padding2);
8015   fprintf (stderr, "to_allocate: %ld\n", (long)frame->to_allocate);
8016   fprintf (stderr, "red_zone_size: %ld\n", (long)frame->red_zone_size);
8017   fprintf (stderr, "frame_pointer_offset: %ld\n", (long)frame->frame_pointer_offset);
8018   fprintf (stderr, "hard_frame_pointer_offset: %ld\n",
8019            (long)frame->hard_frame_pointer_offset);
8020   fprintf (stderr, "stack_pointer_offset: %ld\n", (long)frame->stack_pointer_offset);
8021   fprintf (stderr, "current_function_is_leaf: %ld\n", (long)current_function_is_leaf);
8022   fprintf (stderr, "cfun->calls_alloca: %ld\n", (long)cfun->calls_alloca);
8023   fprintf (stderr, "x86_current_function_calls_tls_descriptor: %ld\n", (long)ix86_current_function_calls_tls_descriptor);
8024 #endif
8025 }
8026
8027 /* Emit code to save registers in the prologue.  */
8028
8029 static void
8030 ix86_emit_save_regs (void)
8031 {
8032   unsigned int regno;
8033   rtx insn;
8034
8035   for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
8036     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
8037       {
8038         insn = emit_insn (gen_push (gen_rtx_REG (Pmode, regno)));
8039         RTX_FRAME_RELATED_P (insn) = 1;
8040       }
8041 }
8042
8043 /* Emit code to save registers using MOV insns.  First register
8044    is restored from POINTER + OFFSET.  */
8045 static void
8046 ix86_emit_save_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
8047 {
8048   unsigned int regno;
8049   rtx insn;
8050
8051   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8052     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
8053       {
8054         insn = emit_move_insn (adjust_address (gen_rtx_MEM (Pmode, pointer),
8055                                                Pmode, offset),
8056                                gen_rtx_REG (Pmode, regno));
8057         RTX_FRAME_RELATED_P (insn) = 1;
8058         offset += UNITS_PER_WORD;
8059       }
8060 }
8061
8062 /* Emit code to save registers using MOV insns.  First register
8063    is restored from POINTER + OFFSET.  */
8064 static void
8065 ix86_emit_save_sse_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
8066 {
8067   unsigned int regno;
8068   rtx insn;
8069   rtx mem;
8070
8071   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8072     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
8073       {
8074         mem = adjust_address (gen_rtx_MEM (TImode, pointer), TImode, offset);
8075         set_mem_align (mem, 128);
8076         insn = emit_move_insn (mem, gen_rtx_REG (TImode, regno));
8077         RTX_FRAME_RELATED_P (insn) = 1;
8078         offset += 16;
8079       }
8080 }
8081
8082 static GTY(()) rtx queued_cfa_restores;
8083
8084 /* Add a REG_CFA_RESTORE REG note to INSN or queue them until next stack
8085    manipulation insn.  Don't add it if the previously
8086    saved value will be left untouched within stack red-zone till return,
8087    as unwinders can find the same value in the register and
8088    on the stack.  */
8089
8090 static void
8091 ix86_add_cfa_restore_note (rtx insn, rtx reg, HOST_WIDE_INT red_offset)
8092 {
8093   if (TARGET_RED_ZONE
8094       && !TARGET_64BIT_MS_ABI
8095       && red_offset + RED_ZONE_SIZE >= 0
8096       && crtl->args.pops_args < 65536)
8097     return;
8098
8099   if (insn)
8100     {
8101       add_reg_note (insn, REG_CFA_RESTORE, reg);
8102       RTX_FRAME_RELATED_P (insn) = 1;
8103     }
8104   else
8105     queued_cfa_restores
8106       = alloc_reg_note (REG_CFA_RESTORE, reg, queued_cfa_restores);
8107 }
8108
8109 /* Add queued REG_CFA_RESTORE notes if any to INSN.  */
8110
8111 static void
8112 ix86_add_queued_cfa_restore_notes (rtx insn)
8113 {
8114   rtx last;
8115   if (!queued_cfa_restores)
8116     return;
8117   for (last = queued_cfa_restores; XEXP (last, 1); last = XEXP (last, 1))
8118     ;
8119   XEXP (last, 1) = REG_NOTES (insn);
8120   REG_NOTES (insn) = queued_cfa_restores;
8121   queued_cfa_restores = NULL_RTX;
8122   RTX_FRAME_RELATED_P (insn) = 1;
8123 }
8124
8125 /* Expand prologue or epilogue stack adjustment.
8126    The pattern exist to put a dependency on all ebp-based memory accesses.
8127    STYLE should be negative if instructions should be marked as frame related,
8128    zero if %r11 register is live and cannot be freely used and positive
8129    otherwise.  */
8130
8131 static void
8132 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
8133                            int style, bool set_cfa)
8134 {
8135   rtx insn;
8136
8137   if (! TARGET_64BIT)
8138     insn = emit_insn (gen_pro_epilogue_adjust_stack_1 (dest, src, offset));
8139   else if (x86_64_immediate_operand (offset, DImode))
8140     insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64 (dest, src, offset));
8141   else
8142     {
8143       rtx r11;
8144       /* r11 is used by indirect sibcall return as well, set before the
8145          epilogue and used after the epilogue.  ATM indirect sibcall
8146          shouldn't be used together with huge frame sizes in one
8147          function because of the frame_size check in sibcall.c.  */
8148       gcc_assert (style);
8149       r11 = gen_rtx_REG (DImode, R11_REG);
8150       insn = emit_insn (gen_rtx_SET (DImode, r11, offset));
8151       if (style < 0)
8152         RTX_FRAME_RELATED_P (insn) = 1;
8153       insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64_2 (dest, src, r11,
8154                                                                offset));
8155     }
8156
8157   if (style >= 0)
8158     ix86_add_queued_cfa_restore_notes (insn);
8159
8160   if (set_cfa)
8161     {
8162       rtx r;
8163
8164       gcc_assert (ix86_cfa_state->reg == src);
8165       ix86_cfa_state->offset += INTVAL (offset);
8166       ix86_cfa_state->reg = dest;
8167     
8168       r = gen_rtx_PLUS (Pmode, src, offset);
8169       r = gen_rtx_SET (VOIDmode, dest, r);
8170       add_reg_note (insn, REG_CFA_ADJUST_CFA, r);
8171       RTX_FRAME_RELATED_P (insn) = 1;
8172     }
8173   else if (style < 0)
8174     RTX_FRAME_RELATED_P (insn) = 1;
8175 }
8176
8177 /* Find an available register to be used as dynamic realign argument
8178    pointer regsiter.  Such a register will be written in prologue and
8179    used in begin of body, so it must not be
8180         1. parameter passing register.
8181         2. GOT pointer.
8182    We reuse static-chain register if it is available.  Otherwise, we
8183    use DI for i386 and R13 for x86-64.  We chose R13 since it has
8184    shorter encoding.
8185
8186    Return: the regno of chosen register.  */
8187
8188 static unsigned int 
8189 find_drap_reg (void)
8190 {
8191   tree decl = cfun->decl;
8192
8193   if (TARGET_64BIT)
8194     {
8195       /* Use R13 for nested function or function need static chain.
8196          Since function with tail call may use any caller-saved
8197          registers in epilogue, DRAP must not use caller-saved
8198          register in such case.  */
8199       if ((decl_function_context (decl)
8200            && !DECL_NO_STATIC_CHAIN (decl))
8201           || crtl->tail_call_emit)
8202         return R13_REG;
8203
8204       return R10_REG;
8205     }
8206   else
8207     {
8208       /* Use DI for nested function or function need static chain.
8209          Since function with tail call may use any caller-saved
8210          registers in epilogue, DRAP must not use caller-saved
8211          register in such case.  */
8212       if ((decl_function_context (decl)
8213            && !DECL_NO_STATIC_CHAIN (decl))
8214           || crtl->tail_call_emit)
8215         return DI_REG;
8216     
8217       /* Reuse static chain register if it isn't used for parameter
8218          passing.  */
8219       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2
8220           && !lookup_attribute ("fastcall",
8221                                 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
8222         return CX_REG;
8223       else
8224         return DI_REG;
8225     }
8226 }
8227
8228 /* Update incoming stack boundary and estimated stack alignment.  */
8229
8230 static void
8231 ix86_update_stack_boundary (void)
8232 {
8233   /* Prefer the one specified at command line. */
8234   ix86_incoming_stack_boundary 
8235     = (ix86_user_incoming_stack_boundary
8236        ? ix86_user_incoming_stack_boundary
8237        : ix86_default_incoming_stack_boundary);
8238
8239   /* Incoming stack alignment can be changed on individual functions
8240      via force_align_arg_pointer attribute.  We use the smallest
8241      incoming stack boundary.  */
8242   if (ix86_incoming_stack_boundary > MIN_STACK_BOUNDARY
8243       && lookup_attribute (ix86_force_align_arg_pointer_string,
8244                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
8245     ix86_incoming_stack_boundary = MIN_STACK_BOUNDARY;
8246
8247   /* The incoming stack frame has to be aligned at least at
8248      parm_stack_boundary.  */
8249   if (ix86_incoming_stack_boundary < crtl->parm_stack_boundary)
8250     ix86_incoming_stack_boundary = crtl->parm_stack_boundary;
8251
8252   /* Stack at entrance of main is aligned by runtime.  We use the
8253      smallest incoming stack boundary. */
8254   if (ix86_incoming_stack_boundary > MAIN_STACK_BOUNDARY
8255       && DECL_NAME (current_function_decl)
8256       && MAIN_NAME_P (DECL_NAME (current_function_decl))
8257       && DECL_FILE_SCOPE_P (current_function_decl))
8258     ix86_incoming_stack_boundary = MAIN_STACK_BOUNDARY;
8259
8260   /* x86_64 vararg needs 16byte stack alignment for register save
8261      area.  */
8262   if (TARGET_64BIT
8263       && cfun->stdarg
8264       && crtl->stack_alignment_estimated < 128)
8265     crtl->stack_alignment_estimated = 128;
8266 }
8267
8268 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
8269    needed or an rtx for DRAP otherwise.  */
8270
8271 static rtx
8272 ix86_get_drap_rtx (void)
8273 {
8274   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
8275     crtl->need_drap = true;
8276
8277   if (stack_realign_drap)
8278     {
8279       /* Assign DRAP to vDRAP and returns vDRAP */
8280       unsigned int regno = find_drap_reg ();
8281       rtx drap_vreg;
8282       rtx arg_ptr;
8283       rtx seq, insn;
8284
8285       arg_ptr = gen_rtx_REG (Pmode, regno);
8286       crtl->drap_reg = arg_ptr;
8287
8288       start_sequence ();
8289       drap_vreg = copy_to_reg (arg_ptr);
8290       seq = get_insns ();
8291       end_sequence ();
8292       
8293       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
8294       RTX_FRAME_RELATED_P (insn) = 1;
8295       return drap_vreg;
8296     }
8297   else
8298     return NULL;
8299 }
8300
8301 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
8302
8303 static rtx
8304 ix86_internal_arg_pointer (void)
8305 {
8306   return virtual_incoming_args_rtx;
8307 }
8308
8309 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
8310    to be generated in correct form.  */
8311 static void 
8312 ix86_finalize_stack_realign_flags (void)
8313 {
8314   /* Check if stack realign is really needed after reload, and 
8315      stores result in cfun */
8316   unsigned int incoming_stack_boundary
8317     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
8318        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
8319   unsigned int stack_realign = (incoming_stack_boundary
8320                                 < (current_function_is_leaf
8321                                    ? crtl->max_used_stack_slot_alignment
8322                                    : crtl->stack_alignment_needed));
8323
8324   if (crtl->stack_realign_finalized)
8325     {
8326       /* After stack_realign_needed is finalized, we can't no longer
8327          change it.  */
8328       gcc_assert (crtl->stack_realign_needed == stack_realign);
8329     }
8330   else
8331     {
8332       crtl->stack_realign_needed = stack_realign;
8333       crtl->stack_realign_finalized = true;
8334     }
8335 }
8336
8337 /* Expand the prologue into a bunch of separate insns.  */
8338
8339 void
8340 ix86_expand_prologue (void)
8341 {
8342   rtx insn;
8343   bool pic_reg_used;
8344   struct ix86_frame frame;
8345   HOST_WIDE_INT allocate;
8346
8347   ix86_finalize_stack_realign_flags ();
8348
8349   /* DRAP should not coexist with stack_realign_fp */
8350   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
8351
8352   /* Initialize CFA state for before the prologue.  */
8353   ix86_cfa_state->reg = stack_pointer_rtx;
8354   ix86_cfa_state->offset = INCOMING_FRAME_SP_OFFSET;
8355
8356   ix86_compute_frame_layout (&frame);
8357
8358   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
8359      of DRAP is needed and stack realignment is really needed after reload */
8360   if (crtl->drap_reg && crtl->stack_realign_needed)
8361     {
8362       rtx x, y;
8363       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
8364       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8365                               ? 0 : UNITS_PER_WORD);
8366
8367       gcc_assert (stack_realign_drap);
8368
8369       /* Grab the argument pointer.  */
8370       x = plus_constant (stack_pointer_rtx, 
8371                          (UNITS_PER_WORD + param_ptr_offset));
8372       y = crtl->drap_reg;
8373
8374       /* Only need to push parameter pointer reg if it is caller
8375          saved reg */
8376       if (!call_used_regs[REGNO (crtl->drap_reg)])
8377         {
8378           /* Push arg pointer reg */
8379           insn = emit_insn (gen_push (y));
8380           RTX_FRAME_RELATED_P (insn) = 1;
8381         }
8382
8383       insn = emit_insn (gen_rtx_SET (VOIDmode, y, x));
8384       RTX_FRAME_RELATED_P (insn) = 1; 
8385       ix86_cfa_state->reg = crtl->drap_reg;
8386
8387       /* Align the stack.  */
8388       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
8389                                            stack_pointer_rtx,
8390                                            GEN_INT (-align_bytes)));
8391       RTX_FRAME_RELATED_P (insn) = 1;
8392
8393       /* Replicate the return address on the stack so that return
8394          address can be reached via (argp - 1) slot.  This is needed
8395          to implement macro RETURN_ADDR_RTX and intrinsic function
8396          expand_builtin_return_addr etc.  */
8397       x = crtl->drap_reg;
8398       x = gen_frame_mem (Pmode,
8399                          plus_constant (x, -UNITS_PER_WORD));
8400       insn = emit_insn (gen_push (x));
8401       RTX_FRAME_RELATED_P (insn) = 1;
8402     }
8403
8404   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
8405      slower on all targets.  Also sdb doesn't like it.  */
8406
8407   if (frame_pointer_needed)
8408     {
8409       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
8410       RTX_FRAME_RELATED_P (insn) = 1;
8411
8412       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
8413       RTX_FRAME_RELATED_P (insn) = 1;
8414
8415       if (ix86_cfa_state->reg == stack_pointer_rtx)
8416         ix86_cfa_state->reg = hard_frame_pointer_rtx;
8417     }
8418
8419   if (stack_realign_fp)
8420     {
8421       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
8422       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
8423
8424       /* Align the stack.  */
8425       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
8426                                            stack_pointer_rtx,
8427                                            GEN_INT (-align_bytes)));
8428       RTX_FRAME_RELATED_P (insn) = 1;
8429     }
8430
8431   allocate = frame.to_allocate + frame.nsseregs * 16 + frame.padding0;
8432
8433   if (!frame.save_regs_using_mov)
8434     ix86_emit_save_regs ();
8435   else
8436     allocate += frame.nregs * UNITS_PER_WORD;
8437
8438   /* When using red zone we may start register saving before allocating
8439      the stack frame saving one cycle of the prologue. However I will
8440      avoid doing this if I am going to have to probe the stack since
8441      at least on x86_64 the stack probe can turn into a call that clobbers
8442      a red zone location */
8443   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && frame.save_regs_using_mov
8444       && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT))
8445     ix86_emit_save_regs_using_mov ((frame_pointer_needed
8446                                      && !crtl->stack_realign_needed) 
8447                                    ? hard_frame_pointer_rtx
8448                                    : stack_pointer_rtx,
8449                                    -frame.nregs * UNITS_PER_WORD);
8450
8451   if (allocate == 0)
8452     ;
8453   else if (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)
8454     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8455                                GEN_INT (-allocate), -1,
8456                                ix86_cfa_state->reg == stack_pointer_rtx);
8457   else
8458     {
8459       /* Only valid for Win32.  */
8460       rtx eax = gen_rtx_REG (Pmode, AX_REG);
8461       bool eax_live;
8462       rtx t;
8463
8464       gcc_assert (!TARGET_64BIT || cfun->machine->call_abi == MS_ABI);
8465
8466       if (cfun->machine->call_abi == MS_ABI)
8467         eax_live = false;
8468       else
8469         eax_live = ix86_eax_live_at_start_p ();
8470
8471       if (eax_live)
8472         {
8473           emit_insn (gen_push (eax));
8474           allocate -= UNITS_PER_WORD;
8475         }
8476
8477       emit_move_insn (eax, GEN_INT (allocate));
8478
8479       if (TARGET_64BIT)
8480         insn = gen_allocate_stack_worker_64 (eax, eax);
8481       else
8482         insn = gen_allocate_stack_worker_32 (eax, eax);
8483       insn = emit_insn (insn);
8484
8485       if (ix86_cfa_state->reg == stack_pointer_rtx)
8486         {
8487           ix86_cfa_state->offset += allocate;
8488           t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (-allocate));
8489           t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
8490           add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
8491           RTX_FRAME_RELATED_P (insn) = 1;
8492         }
8493
8494       if (eax_live)
8495         {
8496           if (frame_pointer_needed)
8497             t = plus_constant (hard_frame_pointer_rtx,
8498                                allocate
8499                                - frame.to_allocate
8500                                - frame.nregs * UNITS_PER_WORD);
8501           else
8502             t = plus_constant (stack_pointer_rtx, allocate);
8503           emit_move_insn (eax, gen_rtx_MEM (Pmode, t));
8504         }
8505     }
8506
8507   if (frame.save_regs_using_mov
8508       && !(!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
8509          && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)))
8510     {
8511       if (!frame_pointer_needed
8512           || !frame.to_allocate
8513           || crtl->stack_realign_needed)
8514         ix86_emit_save_regs_using_mov (stack_pointer_rtx,
8515                                        frame.to_allocate
8516                                        + frame.nsseregs * 16 + frame.padding0);
8517       else
8518         ix86_emit_save_regs_using_mov (hard_frame_pointer_rtx,
8519                                        -frame.nregs * UNITS_PER_WORD);
8520     }
8521   if (!frame_pointer_needed
8522       || !frame.to_allocate
8523       || crtl->stack_realign_needed)
8524     ix86_emit_save_sse_regs_using_mov (stack_pointer_rtx,
8525                                        frame.to_allocate);
8526   else
8527     ix86_emit_save_sse_regs_using_mov (hard_frame_pointer_rtx,
8528                                        - frame.nregs * UNITS_PER_WORD
8529                                        - frame.nsseregs * 16
8530                                        - frame.padding0);
8531
8532   pic_reg_used = false;
8533   if (pic_offset_table_rtx
8534       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
8535           || crtl->profile))
8536     {
8537       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
8538
8539       if (alt_pic_reg_used != INVALID_REGNUM)
8540         SET_REGNO (pic_offset_table_rtx, alt_pic_reg_used);
8541
8542       pic_reg_used = true;
8543     }
8544
8545   if (pic_reg_used)
8546     {
8547       if (TARGET_64BIT)
8548         {
8549           if (ix86_cmodel == CM_LARGE_PIC)
8550             {
8551               rtx tmp_reg = gen_rtx_REG (DImode, R11_REG);
8552               rtx label = gen_label_rtx ();
8553               emit_label (label);
8554               LABEL_PRESERVE_P (label) = 1;
8555               gcc_assert (REGNO (pic_offset_table_rtx) != REGNO (tmp_reg));
8556               insn = emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, label));
8557               insn = emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
8558               insn = emit_insn (gen_adddi3 (pic_offset_table_rtx,
8559                                             pic_offset_table_rtx, tmp_reg));
8560             }
8561           else
8562             insn = emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
8563         }
8564       else
8565         insn = emit_insn (gen_set_got (pic_offset_table_rtx));
8566     }
8567
8568   /* In the pic_reg_used case, make sure that the got load isn't deleted
8569      when mcount needs it.  Blockage to avoid call movement across mcount
8570      call is emitted in generic code after the NOTE_INSN_PROLOGUE_END
8571      note.  */
8572   if (crtl->profile && pic_reg_used)
8573     emit_insn (gen_prologue_use (pic_offset_table_rtx));
8574
8575   if (crtl->drap_reg && !crtl->stack_realign_needed)
8576     {
8577       /* vDRAP is setup but after reload it turns out stack realign
8578          isn't necessary, here we will emit prologue to setup DRAP
8579          without stack realign adjustment */
8580       int drap_bp_offset = UNITS_PER_WORD * 2;
8581       rtx x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
8582       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, x));
8583     }
8584
8585   /* Prevent instructions from being scheduled into register save push
8586      sequence when access to the redzone area is done through frame pointer.
8587      The offset betweeh the frame pointer and the stack pointer is calculated
8588      relative to the value of the stack pointer at the end of the function
8589      prologue, and moving instructions that access redzone area via frame
8590      pointer inside push sequence violates this assumption.  */
8591   if (frame_pointer_needed && frame.red_zone_size)
8592     emit_insn (gen_memory_blockage ());
8593
8594   /* Emit cld instruction if stringops are used in the function.  */
8595   if (TARGET_CLD && ix86_current_function_needs_cld)
8596     emit_insn (gen_cld ());
8597 }
8598
8599 /* Emit code to restore REG using a POP insn.  */
8600
8601 static void
8602 ix86_emit_restore_reg_using_pop (rtx reg, HOST_WIDE_INT red_offset)
8603 {
8604   rtx insn = emit_insn (ix86_gen_pop1 (reg));
8605
8606   if (ix86_cfa_state->reg == crtl->drap_reg
8607       && REGNO (reg) == REGNO (crtl->drap_reg))
8608     {
8609       /* Previously we'd represented the CFA as an expression
8610          like *(%ebp - 8).  We've just popped that value from
8611          the stack, which means we need to reset the CFA to
8612          the drap register.  This will remain until we restore
8613          the stack pointer.  */
8614       add_reg_note (insn, REG_CFA_DEF_CFA, reg);
8615       RTX_FRAME_RELATED_P (insn) = 1;
8616       return;
8617     }
8618
8619   if (ix86_cfa_state->reg == stack_pointer_rtx)
8620     {
8621       ix86_cfa_state->offset -= UNITS_PER_WORD;
8622       add_reg_note (insn, REG_CFA_ADJUST_CFA,
8623                     copy_rtx (XVECEXP (PATTERN (insn), 0, 1)));
8624       RTX_FRAME_RELATED_P (insn) = 1;
8625     }
8626
8627   /* When the frame pointer is the CFA, and we pop it, we are
8628      swapping back to the stack pointer as the CFA.  This happens
8629      for stack frames that don't allocate other data, so we assume
8630      the stack pointer is now pointing at the return address, i.e.
8631      the function entry state, which makes the offset be 1 word.  */
8632   else if (ix86_cfa_state->reg == hard_frame_pointer_rtx
8633            && reg == hard_frame_pointer_rtx)
8634     {
8635       ix86_cfa_state->reg = stack_pointer_rtx;
8636       ix86_cfa_state->offset = UNITS_PER_WORD;
8637
8638       add_reg_note (insn, REG_CFA_DEF_CFA,
8639                     gen_rtx_PLUS (Pmode, stack_pointer_rtx,
8640                                   GEN_INT (UNITS_PER_WORD)));
8641       RTX_FRAME_RELATED_P (insn) = 1;
8642     }
8643
8644   ix86_add_cfa_restore_note (insn, reg, red_offset);
8645 }
8646
8647 /* Emit code to restore saved registers using POP insns.  */
8648
8649 static void
8650 ix86_emit_restore_regs_using_pop (HOST_WIDE_INT red_offset)
8651 {
8652   int regno;
8653
8654   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8655     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, false))
8656       {
8657         ix86_emit_restore_reg_using_pop (gen_rtx_REG (Pmode, regno),
8658                                          red_offset);
8659         red_offset += UNITS_PER_WORD;
8660       }
8661 }
8662
8663 /* Emit code and notes for the LEAVE instruction.  */
8664
8665 static void
8666 ix86_emit_leave (HOST_WIDE_INT red_offset)
8667 {
8668   rtx insn = emit_insn (ix86_gen_leave ());
8669
8670   ix86_add_queued_cfa_restore_notes (insn);
8671
8672   if (ix86_cfa_state->reg == hard_frame_pointer_rtx)
8673     {
8674       add_reg_note (insn, REG_CFA_ADJUST_CFA, 
8675                     copy_rtx (XVECEXP (PATTERN (insn), 0, 0)));
8676       RTX_FRAME_RELATED_P (insn) = 1;
8677       ix86_add_cfa_restore_note (insn, hard_frame_pointer_rtx, red_offset);
8678     }
8679 }
8680
8681 /* Emit code to restore saved registers using MOV insns.  First register
8682    is restored from POINTER + OFFSET.  */
8683 static void
8684 ix86_emit_restore_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8685                                   HOST_WIDE_INT red_offset,
8686                                   int maybe_eh_return)
8687 {
8688   unsigned int regno;
8689   rtx base_address = gen_rtx_MEM (Pmode, pointer);
8690   rtx insn;
8691
8692   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8693     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
8694       {
8695         rtx reg = gen_rtx_REG (Pmode, regno);
8696
8697         /* Ensure that adjust_address won't be forced to produce pointer
8698            out of range allowed by x86-64 instruction set.  */
8699         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8700           {
8701             rtx r11;
8702
8703             r11 = gen_rtx_REG (DImode, R11_REG);
8704             emit_move_insn (r11, GEN_INT (offset));
8705             emit_insn (gen_adddi3 (r11, r11, pointer));
8706             base_address = gen_rtx_MEM (Pmode, r11);
8707             offset = 0;
8708           }
8709         insn = emit_move_insn (reg,
8710                                adjust_address (base_address, Pmode, offset));
8711         offset += UNITS_PER_WORD;
8712
8713         if (ix86_cfa_state->reg == crtl->drap_reg
8714             && regno == REGNO (crtl->drap_reg))
8715           {
8716             /* Previously we'd represented the CFA as an expression
8717                like *(%ebp - 8).  We've just popped that value from
8718                the stack, which means we need to reset the CFA to
8719                the drap register.  This will remain until we restore
8720                the stack pointer.  */
8721             add_reg_note (insn, REG_CFA_DEF_CFA, reg);
8722             RTX_FRAME_RELATED_P (insn) = 1;
8723           }
8724         else
8725           ix86_add_cfa_restore_note (NULL_RTX, reg, red_offset);
8726
8727         red_offset += UNITS_PER_WORD;
8728       }
8729 }
8730
8731 /* Emit code to restore saved registers using MOV insns.  First register
8732    is restored from POINTER + OFFSET.  */
8733 static void
8734 ix86_emit_restore_sse_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8735                                       HOST_WIDE_INT red_offset,
8736                                       int maybe_eh_return)
8737 {
8738   int regno;
8739   rtx base_address = gen_rtx_MEM (TImode, pointer);
8740   rtx mem, insn;
8741
8742   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8743     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
8744       {
8745         rtx reg = gen_rtx_REG (TImode, regno);
8746
8747         /* Ensure that adjust_address won't be forced to produce pointer
8748            out of range allowed by x86-64 instruction set.  */
8749         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8750           {
8751             rtx r11;
8752
8753             r11 = gen_rtx_REG (DImode, R11_REG);
8754             emit_move_insn (r11, GEN_INT (offset));
8755             emit_insn (gen_adddi3 (r11, r11, pointer));
8756             base_address = gen_rtx_MEM (TImode, r11);
8757             offset = 0;
8758           }
8759         mem = adjust_address (base_address, TImode, offset);
8760         set_mem_align (mem, 128);
8761         insn = emit_move_insn (reg, mem);
8762         offset += 16;
8763
8764         ix86_add_cfa_restore_note (NULL_RTX, reg, red_offset);
8765
8766         red_offset += 16;
8767       }
8768 }
8769
8770 /* Restore function stack, frame, and registers.  */
8771
8772 void
8773 ix86_expand_epilogue (int style)
8774 {
8775   int sp_valid;
8776   struct ix86_frame frame;
8777   HOST_WIDE_INT offset, red_offset;
8778   struct machine_cfa_state cfa_state_save = *ix86_cfa_state;
8779   bool using_drap;
8780
8781   ix86_finalize_stack_realign_flags ();
8782
8783  /* When stack is realigned, SP must be valid.  */
8784   sp_valid = (!frame_pointer_needed
8785               || current_function_sp_is_unchanging
8786               || stack_realign_fp);
8787
8788   ix86_compute_frame_layout (&frame);
8789
8790   /* See the comment about red zone and frame
8791      pointer usage in ix86_expand_prologue.  */
8792   if (frame_pointer_needed && frame.red_zone_size)
8793     emit_insn (gen_memory_blockage ()); 
8794
8795   using_drap = crtl->drap_reg && crtl->stack_realign_needed;
8796   gcc_assert (!using_drap || ix86_cfa_state->reg == crtl->drap_reg);
8797
8798   /* Calculate start of saved registers relative to ebp.  Special care
8799      must be taken for the normal return case of a function using
8800      eh_return: the eax and edx registers are marked as saved, but not
8801      restored along this path.  */
8802   offset = frame.nregs;
8803   if (crtl->calls_eh_return && style != 2)
8804     offset -= 2;
8805   offset *= -UNITS_PER_WORD;
8806   offset -= frame.nsseregs * 16 + frame.padding0;
8807
8808   /* Calculate start of saved registers relative to esp on entry of the
8809      function.  When realigning stack, this needs to be the most negative
8810      value possible at runtime.  */
8811   red_offset = offset;
8812   if (using_drap)
8813     red_offset -= crtl->stack_alignment_needed / BITS_PER_UNIT
8814                   + UNITS_PER_WORD;
8815   else if (stack_realign_fp)
8816     red_offset -= crtl->stack_alignment_needed / BITS_PER_UNIT
8817                   - UNITS_PER_WORD;
8818   if (frame_pointer_needed)
8819     red_offset -= UNITS_PER_WORD;
8820
8821   /* If we're only restoring one register and sp is not valid then
8822      using a move instruction to restore the register since it's
8823      less work than reloading sp and popping the register.
8824
8825      The default code result in stack adjustment using add/lea instruction,
8826      while this code results in LEAVE instruction (or discrete equivalent),
8827      so it is profitable in some other cases as well.  Especially when there
8828      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
8829      and there is exactly one register to pop. This heuristic may need some
8830      tuning in future.  */
8831   if ((!sp_valid && (frame.nregs + frame.nsseregs) <= 1)
8832       || (TARGET_EPILOGUE_USING_MOVE
8833           && cfun->machine->use_fast_prologue_epilogue
8834           && ((frame.nregs + frame.nsseregs) > 1 || frame.to_allocate))
8835       || (frame_pointer_needed && !(frame.nregs + frame.nsseregs)
8836           && frame.to_allocate)
8837       || (frame_pointer_needed && TARGET_USE_LEAVE
8838           && cfun->machine->use_fast_prologue_epilogue
8839           && (frame.nregs + frame.nsseregs) == 1)
8840       || crtl->calls_eh_return)
8841     {
8842       /* Restore registers.  We can use ebp or esp to address the memory
8843          locations.  If both are available, default to ebp, since offsets
8844          are known to be small.  Only exception is esp pointing directly
8845          to the end of block of saved registers, where we may simplify
8846          addressing mode.  
8847
8848          If we are realigning stack with bp and sp, regs restore can't
8849          be addressed by bp. sp must be used instead.  */
8850
8851       if (!frame_pointer_needed
8852           || (sp_valid && !frame.to_allocate) 
8853           || stack_realign_fp)
8854         {
8855           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8856                                                 frame.to_allocate, red_offset,
8857                                                 style == 2);
8858           ix86_emit_restore_regs_using_mov (stack_pointer_rtx,
8859                                             frame.to_allocate
8860                                             + frame.nsseregs * 16
8861                                             + frame.padding0,
8862                                             red_offset
8863                                             + frame.nsseregs * 16
8864                                             + frame.padding0, style == 2);
8865         }
8866       else
8867         {
8868           ix86_emit_restore_sse_regs_using_mov (hard_frame_pointer_rtx,
8869                                                 offset, red_offset,
8870                                                 style == 2);
8871           ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx,
8872                                             offset
8873                                             + frame.nsseregs * 16
8874                                             + frame.padding0,
8875                                             red_offset
8876                                             + frame.nsseregs * 16
8877                                             + frame.padding0, style == 2);
8878         }
8879
8880       red_offset -= offset;
8881
8882       /* eh_return epilogues need %ecx added to the stack pointer.  */
8883       if (style == 2)
8884         {
8885           rtx tmp, sa = EH_RETURN_STACKADJ_RTX;
8886
8887           /* Stack align doesn't work with eh_return.  */
8888           gcc_assert (!crtl->stack_realign_needed);
8889
8890           if (frame_pointer_needed)
8891             {
8892               tmp = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
8893               tmp = plus_constant (tmp, UNITS_PER_WORD);
8894               tmp = emit_insn (gen_rtx_SET (VOIDmode, sa, tmp));
8895
8896               tmp = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
8897               tmp = emit_move_insn (hard_frame_pointer_rtx, tmp);
8898
8899               /* Note that we use SA as a temporary CFA, as the return
8900                  address is at the proper place relative to it.  We
8901                  pretend this happens at the FP restore insn because
8902                  prior to this insn the FP would be stored at the wrong
8903                  offset relative to SA, and after this insn we have no
8904                  other reasonable register to use for the CFA.  We don't
8905                  bother resetting the CFA to the SP for the duration of
8906                  the return insn.  */
8907               add_reg_note (tmp, REG_CFA_DEF_CFA,
8908                             plus_constant (sa, UNITS_PER_WORD));
8909               ix86_add_queued_cfa_restore_notes (tmp);
8910               add_reg_note (tmp, REG_CFA_RESTORE, hard_frame_pointer_rtx);
8911               RTX_FRAME_RELATED_P (tmp) = 1;
8912               ix86_cfa_state->reg = sa;
8913               ix86_cfa_state->offset = UNITS_PER_WORD;
8914
8915               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
8916                                          const0_rtx, style, false);
8917             }
8918           else
8919             {
8920               tmp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
8921               tmp = plus_constant (tmp, (frame.to_allocate
8922                                          + frame.nregs * UNITS_PER_WORD
8923                                          + frame.nsseregs * 16
8924                                          + frame.padding0));
8925               tmp = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp));
8926               ix86_add_queued_cfa_restore_notes (tmp);
8927
8928               gcc_assert (ix86_cfa_state->reg == stack_pointer_rtx);
8929               if (ix86_cfa_state->offset != UNITS_PER_WORD)
8930                 {
8931                   ix86_cfa_state->offset = UNITS_PER_WORD;
8932                   add_reg_note (tmp, REG_CFA_DEF_CFA,
8933                                 plus_constant (stack_pointer_rtx,
8934                                                UNITS_PER_WORD));
8935                   RTX_FRAME_RELATED_P (tmp) = 1;
8936                 }
8937             }
8938         }
8939       else if (!frame_pointer_needed)
8940         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8941                                    GEN_INT (frame.to_allocate
8942                                             + frame.nregs * UNITS_PER_WORD
8943                                             + frame.nsseregs * 16
8944                                             + frame.padding0),
8945                                    style, !using_drap);
8946       /* If not an i386, mov & pop is faster than "leave".  */
8947       else if (TARGET_USE_LEAVE || optimize_function_for_size_p (cfun)
8948                || !cfun->machine->use_fast_prologue_epilogue)
8949         ix86_emit_leave (red_offset);
8950       else
8951         {
8952           pro_epilogue_adjust_stack (stack_pointer_rtx,
8953                                      hard_frame_pointer_rtx,
8954                                      const0_rtx, style, !using_drap);
8955
8956           ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx, red_offset);
8957         }
8958     }
8959   else
8960     {
8961       /* First step is to deallocate the stack frame so that we can
8962          pop the registers.
8963
8964          If we realign stack with frame pointer, then stack pointer
8965          won't be able to recover via lea $offset(%bp), %sp, because
8966          there is a padding area between bp and sp for realign. 
8967          "add $to_allocate, %sp" must be used instead.  */
8968       if (!sp_valid)
8969         {
8970           gcc_assert (frame_pointer_needed);
8971           gcc_assert (!stack_realign_fp);
8972           pro_epilogue_adjust_stack (stack_pointer_rtx,
8973                                      hard_frame_pointer_rtx,
8974                                      GEN_INT (offset), style, false);
8975           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8976                                                 frame.to_allocate, red_offset,
8977                                                 style == 2);
8978           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8979                                      GEN_INT (frame.nsseregs * 16),
8980                                      style, false);
8981         }
8982       else if (frame.to_allocate || frame.nsseregs)
8983         {
8984           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8985                                                 frame.to_allocate, red_offset,
8986                                                 style == 2);
8987           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8988                                      GEN_INT (frame.to_allocate
8989                                               + frame.nsseregs * 16
8990                                               + frame.padding0), style,
8991                                      !using_drap && !frame_pointer_needed);
8992         }
8993
8994       ix86_emit_restore_regs_using_pop (red_offset + frame.nsseregs * 16
8995                                         + frame.padding0);
8996       red_offset -= offset;
8997
8998       if (frame_pointer_needed)
8999         {
9000           /* Leave results in shorter dependency chains on CPUs that are
9001              able to grok it fast.  */
9002           if (TARGET_USE_LEAVE)
9003             ix86_emit_leave (red_offset);
9004           else
9005             {
9006               /* For stack realigned really happens, recover stack 
9007                  pointer to hard frame pointer is a must, if not using 
9008                  leave.  */
9009               if (stack_realign_fp)
9010                 pro_epilogue_adjust_stack (stack_pointer_rtx,
9011                                            hard_frame_pointer_rtx,
9012                                            const0_rtx, style, !using_drap);
9013               ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx,
9014                                                red_offset);
9015             }
9016         }
9017     }
9018
9019   if (using_drap)
9020     {
9021       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
9022                               ? 0 : UNITS_PER_WORD);
9023       rtx insn;
9024
9025       gcc_assert (stack_realign_drap);
9026
9027       insn = emit_insn ((*ix86_gen_add3) (stack_pointer_rtx,
9028                                           crtl->drap_reg,
9029                                           GEN_INT (-(UNITS_PER_WORD
9030                                                      + param_ptr_offset))));
9031
9032       ix86_cfa_state->reg = stack_pointer_rtx;
9033       ix86_cfa_state->offset = UNITS_PER_WORD + param_ptr_offset;
9034
9035       add_reg_note (insn, REG_CFA_DEF_CFA,
9036                     gen_rtx_PLUS (Pmode, ix86_cfa_state->reg,
9037                                   GEN_INT (ix86_cfa_state->offset)));
9038       RTX_FRAME_RELATED_P (insn) = 1;
9039
9040       if (param_ptr_offset)
9041         ix86_emit_restore_reg_using_pop (crtl->drap_reg, -UNITS_PER_WORD);
9042     }
9043
9044   /* Sibcall epilogues don't want a return instruction.  */
9045   if (style == 0)
9046     {
9047       *ix86_cfa_state = cfa_state_save;
9048       return;
9049     }
9050
9051   if (crtl->args.pops_args && crtl->args.size)
9052     {
9053       rtx popc = GEN_INT (crtl->args.pops_args);
9054
9055       /* i386 can only pop 64K bytes.  If asked to pop more, pop return
9056          address, do explicit add, and jump indirectly to the caller.  */
9057
9058       if (crtl->args.pops_args >= 65536)
9059         {
9060           rtx ecx = gen_rtx_REG (SImode, CX_REG);
9061           rtx insn;
9062
9063           /* There is no "pascal" calling convention in any 64bit ABI.  */
9064           gcc_assert (!TARGET_64BIT);
9065
9066           insn = emit_insn (gen_popsi1 (ecx));
9067           ix86_cfa_state->offset -= UNITS_PER_WORD;
9068
9069           add_reg_note (insn, REG_CFA_ADJUST_CFA,
9070                         copy_rtx (XVECEXP (PATTERN (insn), 0, 1)));
9071           add_reg_note (insn, REG_CFA_REGISTER,
9072                         gen_rtx_SET (VOIDmode, ecx, pc_rtx));
9073           RTX_FRAME_RELATED_P (insn) = 1;
9074
9075           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
9076                                      popc, -1, true);
9077           emit_jump_insn (gen_return_indirect_internal (ecx));
9078         }
9079       else
9080         emit_jump_insn (gen_return_pop_internal (popc));
9081     }
9082   else
9083     emit_jump_insn (gen_return_internal ());
9084
9085   /* Restore the state back to the state from the prologue,
9086      so that it's correct for the next epilogue.  */
9087   *ix86_cfa_state = cfa_state_save;
9088 }
9089
9090 /* Reset from the function's potential modifications.  */
9091
9092 static void
9093 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
9094                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9095 {
9096   if (pic_offset_table_rtx)
9097     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
9098 #if TARGET_MACHO
9099   /* Mach-O doesn't support labels at the end of objects, so if
9100      it looks like we might want one, insert a NOP.  */
9101   {
9102     rtx insn = get_last_insn ();
9103     while (insn
9104            && NOTE_P (insn)
9105            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
9106       insn = PREV_INSN (insn);
9107     if (insn
9108         && (LABEL_P (insn)
9109             || (NOTE_P (insn)
9110                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
9111       fputs ("\tnop\n", file);
9112   }
9113 #endif
9114
9115 }
9116 \f
9117 /* Extract the parts of an RTL expression that is a valid memory address
9118    for an instruction.  Return 0 if the structure of the address is
9119    grossly off.  Return -1 if the address contains ASHIFT, so it is not
9120    strictly valid, but still used for computing length of lea instruction.  */
9121
9122 int
9123 ix86_decompose_address (rtx addr, struct ix86_address *out)
9124 {
9125   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
9126   rtx base_reg, index_reg;
9127   HOST_WIDE_INT scale = 1;
9128   rtx scale_rtx = NULL_RTX;
9129   int retval = 1;
9130   enum ix86_address_seg seg = SEG_DEFAULT;
9131
9132   if (REG_P (addr) || GET_CODE (addr) == SUBREG)
9133     base = addr;
9134   else if (GET_CODE (addr) == PLUS)
9135     {
9136       rtx addends[4], op;
9137       int n = 0, i;
9138
9139       op = addr;
9140       do
9141         {
9142           if (n >= 4)
9143             return 0;
9144           addends[n++] = XEXP (op, 1);
9145           op = XEXP (op, 0);
9146         }
9147       while (GET_CODE (op) == PLUS);
9148       if (n >= 4)
9149         return 0;
9150       addends[n] = op;
9151
9152       for (i = n; i >= 0; --i)
9153         {
9154           op = addends[i];
9155           switch (GET_CODE (op))
9156             {
9157             case MULT:
9158               if (index)
9159                 return 0;
9160               index = XEXP (op, 0);
9161               scale_rtx = XEXP (op, 1);
9162               break;
9163
9164             case UNSPEC:
9165               if (XINT (op, 1) == UNSPEC_TP
9166                   && TARGET_TLS_DIRECT_SEG_REFS
9167                   && seg == SEG_DEFAULT)
9168                 seg = TARGET_64BIT ? SEG_FS : SEG_GS;
9169               else
9170                 return 0;
9171               break;
9172
9173             case REG:
9174             case SUBREG:
9175               if (!base)
9176                 base = op;
9177               else if (!index)
9178                 index = op;
9179               else
9180                 return 0;
9181               break;
9182
9183             case CONST:
9184             case CONST_INT:
9185             case SYMBOL_REF:
9186             case LABEL_REF:
9187               if (disp)
9188                 return 0;
9189               disp = op;
9190               break;
9191
9192             default:
9193               return 0;
9194             }
9195         }
9196     }
9197   else if (GET_CODE (addr) == MULT)
9198     {
9199       index = XEXP (addr, 0);           /* index*scale */
9200       scale_rtx = XEXP (addr, 1);
9201     }
9202   else if (GET_CODE (addr) == ASHIFT)
9203     {
9204       rtx tmp;
9205
9206       /* We're called for lea too, which implements ashift on occasion.  */
9207       index = XEXP (addr, 0);
9208       tmp = XEXP (addr, 1);
9209       if (!CONST_INT_P (tmp))
9210         return 0;
9211       scale = INTVAL (tmp);
9212       if ((unsigned HOST_WIDE_INT) scale > 3)
9213         return 0;
9214       scale = 1 << scale;
9215       retval = -1;
9216     }
9217   else
9218     disp = addr;                        /* displacement */
9219
9220   /* Extract the integral value of scale.  */
9221   if (scale_rtx)
9222     {
9223       if (!CONST_INT_P (scale_rtx))
9224         return 0;
9225       scale = INTVAL (scale_rtx);
9226     }
9227
9228   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
9229   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
9230
9231   /* Avoid useless 0 displacement.  */
9232   if (disp == const0_rtx && (base || index))
9233     disp = NULL_RTX;
9234
9235   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
9236   if (base_reg && index_reg && scale == 1
9237       && (index_reg == arg_pointer_rtx
9238           || index_reg == frame_pointer_rtx
9239           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
9240     {
9241       rtx tmp;
9242       tmp = base, base = index, index = tmp;
9243       tmp = base_reg, base_reg = index_reg, index_reg = tmp;
9244     }
9245
9246   /* Special case: %ebp cannot be encoded as a base without a displacement.
9247      Similarly %r13.  */
9248   if (!disp
9249       && base_reg
9250       && (base_reg == hard_frame_pointer_rtx
9251           || base_reg == frame_pointer_rtx
9252           || base_reg == arg_pointer_rtx
9253           || (REG_P (base_reg)
9254               && (REGNO (base_reg) == HARD_FRAME_POINTER_REGNUM
9255                   || REGNO (base_reg) == R13_REG))))
9256     disp = const0_rtx;
9257
9258   /* Special case: on K6, [%esi] makes the instruction vector decoded.
9259      Avoid this by transforming to [%esi+0].
9260      Reload calls address legitimization without cfun defined, so we need
9261      to test cfun for being non-NULL. */
9262   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
9263       && base_reg && !index_reg && !disp
9264       && REG_P (base_reg)
9265       && REGNO_REG_CLASS (REGNO (base_reg)) == SIREG)
9266     disp = const0_rtx;
9267
9268   /* Special case: encode reg+reg instead of reg*2.  */
9269   if (!base && index && scale == 2)
9270     base = index, base_reg = index_reg, scale = 1;
9271
9272   /* Special case: scaling cannot be encoded without base or displacement.  */
9273   if (!base && !disp && index && scale != 1)
9274     disp = const0_rtx;
9275
9276   out->base = base;
9277   out->index = index;
9278   out->disp = disp;
9279   out->scale = scale;
9280   out->seg = seg;
9281
9282   return retval;
9283 }
9284 \f
9285 /* Return cost of the memory address x.
9286    For i386, it is better to use a complex address than let gcc copy
9287    the address into a reg and make a new pseudo.  But not if the address
9288    requires to two regs - that would mean more pseudos with longer
9289    lifetimes.  */
9290 static int
9291 ix86_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
9292 {
9293   struct ix86_address parts;
9294   int cost = 1;
9295   int ok = ix86_decompose_address (x, &parts);
9296
9297   gcc_assert (ok);
9298
9299   if (parts.base && GET_CODE (parts.base) == SUBREG)
9300     parts.base = SUBREG_REG (parts.base);
9301   if (parts.index && GET_CODE (parts.index) == SUBREG)
9302     parts.index = SUBREG_REG (parts.index);
9303
9304   /* Attempt to minimize number of registers in the address.  */
9305   if ((parts.base
9306        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
9307       || (parts.index
9308           && (!REG_P (parts.index)
9309               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
9310     cost++;
9311
9312   if (parts.base
9313       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
9314       && parts.index
9315       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
9316       && parts.base != parts.index)
9317     cost++;
9318
9319   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
9320      since it's predecode logic can't detect the length of instructions
9321      and it degenerates to vector decoded.  Increase cost of such
9322      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
9323      to split such addresses or even refuse such addresses at all.
9324
9325      Following addressing modes are affected:
9326       [base+scale*index]
9327       [scale*index+disp]
9328       [base+index]
9329
9330      The first and last case  may be avoidable by explicitly coding the zero in
9331      memory address, but I don't have AMD-K6 machine handy to check this
9332      theory.  */
9333
9334   if (TARGET_K6
9335       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
9336           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
9337           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
9338     cost += 10;
9339
9340   return cost;
9341 }
9342 \f
9343 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
9344    this is used for to form addresses to local data when -fPIC is in
9345    use.  */
9346
9347 static bool
9348 darwin_local_data_pic (rtx disp)
9349 {
9350   return (GET_CODE (disp) == UNSPEC
9351           && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
9352 }
9353
9354 /* Determine if a given RTX is a valid constant.  We already know this
9355    satisfies CONSTANT_P.  */
9356
9357 bool
9358 legitimate_constant_p (rtx x)
9359 {
9360   switch (GET_CODE (x))
9361     {
9362     case CONST:
9363       x = XEXP (x, 0);
9364
9365       if (GET_CODE (x) == PLUS)
9366         {
9367           if (!CONST_INT_P (XEXP (x, 1)))
9368             return false;
9369           x = XEXP (x, 0);
9370         }
9371
9372       if (TARGET_MACHO && darwin_local_data_pic (x))
9373         return true;
9374
9375       /* Only some unspecs are valid as "constants".  */
9376       if (GET_CODE (x) == UNSPEC)
9377         switch (XINT (x, 1))
9378           {
9379           case UNSPEC_GOT:
9380           case UNSPEC_GOTOFF:
9381           case UNSPEC_PLTOFF:
9382             return TARGET_64BIT;
9383           case UNSPEC_TPOFF:
9384           case UNSPEC_NTPOFF:
9385             x = XVECEXP (x, 0, 0);
9386             return (GET_CODE (x) == SYMBOL_REF
9387                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
9388           case UNSPEC_DTPOFF:
9389             x = XVECEXP (x, 0, 0);
9390             return (GET_CODE (x) == SYMBOL_REF
9391                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
9392           default:
9393             return false;
9394           }
9395
9396       /* We must have drilled down to a symbol.  */
9397       if (GET_CODE (x) == LABEL_REF)
9398         return true;
9399       if (GET_CODE (x) != SYMBOL_REF)
9400         return false;
9401       /* FALLTHRU */
9402
9403     case SYMBOL_REF:
9404       /* TLS symbols are never valid.  */
9405       if (SYMBOL_REF_TLS_MODEL (x))
9406         return false;
9407
9408       /* DLLIMPORT symbols are never valid.  */
9409       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
9410           && SYMBOL_REF_DLLIMPORT_P (x))
9411         return false;
9412       break;
9413
9414     case CONST_DOUBLE:
9415       if (GET_MODE (x) == TImode
9416           && x != CONST0_RTX (TImode)
9417           && !TARGET_64BIT)
9418         return false;
9419       break;
9420
9421     case CONST_VECTOR:
9422       if (!standard_sse_constant_p (x))
9423         return false;
9424
9425     default:
9426       break;
9427     }
9428
9429   /* Otherwise we handle everything else in the move patterns.  */
9430   return true;
9431 }
9432
9433 /* Determine if it's legal to put X into the constant pool.  This
9434    is not possible for the address of thread-local symbols, which
9435    is checked above.  */
9436
9437 static bool
9438 ix86_cannot_force_const_mem (rtx x)
9439 {
9440   /* We can always put integral constants and vectors in memory.  */
9441   switch (GET_CODE (x))
9442     {
9443     case CONST_INT:
9444     case CONST_DOUBLE:
9445     case CONST_VECTOR:
9446       return false;
9447
9448     default:
9449       break;
9450     }
9451   return !legitimate_constant_p (x);
9452 }
9453
9454
9455 /* Nonzero if the constant value X is a legitimate general operand
9456    when generating PIC code.  It is given that flag_pic is on and
9457    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
9458
9459 bool
9460 legitimate_pic_operand_p (rtx x)
9461 {
9462   rtx inner;
9463
9464   switch (GET_CODE (x))
9465     {
9466     case CONST:
9467       inner = XEXP (x, 0);
9468       if (GET_CODE (inner) == PLUS
9469           && CONST_INT_P (XEXP (inner, 1)))
9470         inner = XEXP (inner, 0);
9471
9472       /* Only some unspecs are valid as "constants".  */
9473       if (GET_CODE (inner) == UNSPEC)
9474         switch (XINT (inner, 1))
9475           {
9476           case UNSPEC_GOT:
9477           case UNSPEC_GOTOFF:
9478           case UNSPEC_PLTOFF:
9479             return TARGET_64BIT;
9480           case UNSPEC_TPOFF:
9481             x = XVECEXP (inner, 0, 0);
9482             return (GET_CODE (x) == SYMBOL_REF
9483                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
9484           case UNSPEC_MACHOPIC_OFFSET:
9485             return legitimate_pic_address_disp_p (x);
9486           default:
9487             return false;
9488           }
9489       /* FALLTHRU */
9490
9491     case SYMBOL_REF:
9492     case LABEL_REF:
9493       return legitimate_pic_address_disp_p (x);
9494
9495     default:
9496       return true;
9497     }
9498 }
9499
9500 /* Determine if a given CONST RTX is a valid memory displacement
9501    in PIC mode.  */
9502
9503 int
9504 legitimate_pic_address_disp_p (rtx disp)
9505 {
9506   bool saw_plus;
9507
9508   /* In 64bit mode we can allow direct addresses of symbols and labels
9509      when they are not dynamic symbols.  */
9510   if (TARGET_64BIT)
9511     {
9512       rtx op0 = disp, op1;
9513
9514       switch (GET_CODE (disp))
9515         {
9516         case LABEL_REF:
9517           return true;
9518
9519         case CONST:
9520           if (GET_CODE (XEXP (disp, 0)) != PLUS)
9521             break;
9522           op0 = XEXP (XEXP (disp, 0), 0);
9523           op1 = XEXP (XEXP (disp, 0), 1);
9524           if (!CONST_INT_P (op1)
9525               || INTVAL (op1) >= 16*1024*1024
9526               || INTVAL (op1) < -16*1024*1024)
9527             break;
9528           if (GET_CODE (op0) == LABEL_REF)
9529             return true;
9530           if (GET_CODE (op0) != SYMBOL_REF)
9531             break;
9532           /* FALLTHRU */
9533
9534         case SYMBOL_REF:
9535           /* TLS references should always be enclosed in UNSPEC.  */
9536           if (SYMBOL_REF_TLS_MODEL (op0))
9537             return false;
9538           if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0)
9539               && ix86_cmodel != CM_LARGE_PIC)
9540             return true;
9541           break;
9542
9543         default:
9544           break;
9545         }
9546     }
9547   if (GET_CODE (disp) != CONST)
9548     return 0;
9549   disp = XEXP (disp, 0);
9550
9551   if (TARGET_64BIT)
9552     {
9553       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
9554          of GOT tables.  We should not need these anyway.  */
9555       if (GET_CODE (disp) != UNSPEC
9556           || (XINT (disp, 1) != UNSPEC_GOTPCREL
9557               && XINT (disp, 1) != UNSPEC_GOTOFF
9558               && XINT (disp, 1) != UNSPEC_PLTOFF))
9559         return 0;
9560
9561       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
9562           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
9563         return 0;
9564       return 1;
9565     }
9566
9567   saw_plus = false;
9568   if (GET_CODE (disp) == PLUS)
9569     {
9570       if (!CONST_INT_P (XEXP (disp, 1)))
9571         return 0;
9572       disp = XEXP (disp, 0);
9573       saw_plus = true;
9574     }
9575
9576   if (TARGET_MACHO && darwin_local_data_pic (disp))
9577     return 1;
9578
9579   if (GET_CODE (disp) != UNSPEC)
9580     return 0;
9581
9582   switch (XINT (disp, 1))
9583     {
9584     case UNSPEC_GOT:
9585       if (saw_plus)
9586         return false;
9587       /* We need to check for both symbols and labels because VxWorks loads
9588          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
9589          details.  */
9590       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
9591               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
9592     case UNSPEC_GOTOFF:
9593       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
9594          While ABI specify also 32bit relocation but we don't produce it in
9595          small PIC model at all.  */
9596       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
9597            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
9598           && !TARGET_64BIT)
9599         return gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
9600       return false;
9601     case UNSPEC_GOTTPOFF:
9602     case UNSPEC_GOTNTPOFF:
9603     case UNSPEC_INDNTPOFF:
9604       if (saw_plus)
9605         return false;
9606       disp = XVECEXP (disp, 0, 0);
9607       return (GET_CODE (disp) == SYMBOL_REF
9608               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
9609     case UNSPEC_NTPOFF:
9610       disp = XVECEXP (disp, 0, 0);
9611       return (GET_CODE (disp) == SYMBOL_REF
9612               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
9613     case UNSPEC_DTPOFF:
9614       disp = XVECEXP (disp, 0, 0);
9615       return (GET_CODE (disp) == SYMBOL_REF
9616               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
9617     }
9618
9619   return 0;
9620 }
9621
9622 /* Recognizes RTL expressions that are valid memory addresses for an
9623    instruction.  The MODE argument is the machine mode for the MEM
9624    expression that wants to use this address.
9625
9626    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
9627    convert common non-canonical forms to canonical form so that they will
9628    be recognized.  */
9629
9630 static bool
9631 ix86_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
9632                            rtx addr, bool strict)
9633 {
9634   struct ix86_address parts;
9635   rtx base, index, disp;
9636   HOST_WIDE_INT scale;
9637   const char *reason = NULL;
9638   rtx reason_rtx = NULL_RTX;
9639
9640   if (ix86_decompose_address (addr, &parts) <= 0)
9641     {
9642       reason = "decomposition failed";
9643       goto report_error;
9644     }
9645
9646   base = parts.base;
9647   index = parts.index;
9648   disp = parts.disp;
9649   scale = parts.scale;
9650
9651   /* Validate base register.
9652
9653      Don't allow SUBREG's that span more than a word here.  It can lead to spill
9654      failures when the base is one word out of a two word structure, which is
9655      represented internally as a DImode int.  */
9656
9657   if (base)
9658     {
9659       rtx reg;
9660       reason_rtx = base;
9661
9662       if (REG_P (base))
9663         reg = base;
9664       else if (GET_CODE (base) == SUBREG
9665                && REG_P (SUBREG_REG (base))
9666                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (base)))
9667                   <= UNITS_PER_WORD)
9668         reg = SUBREG_REG (base);
9669       else
9670         {
9671           reason = "base is not a register";
9672           goto report_error;
9673         }
9674
9675       if (GET_MODE (base) != Pmode)
9676         {
9677           reason = "base is not in Pmode";
9678           goto report_error;
9679         }
9680
9681       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
9682           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
9683         {
9684           reason = "base is not valid";
9685           goto report_error;
9686         }
9687     }
9688
9689   /* Validate index register.
9690
9691      Don't allow SUBREG's that span more than a word here -- same as above.  */
9692
9693   if (index)
9694     {
9695       rtx reg;
9696       reason_rtx = index;
9697
9698       if (REG_P (index))
9699         reg = index;
9700       else if (GET_CODE (index) == SUBREG
9701                && REG_P (SUBREG_REG (index))
9702                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (index)))
9703                   <= UNITS_PER_WORD)
9704         reg = SUBREG_REG (index);
9705       else
9706         {
9707           reason = "index is not a register";
9708           goto report_error;
9709         }
9710
9711       if (GET_MODE (index) != Pmode)
9712         {
9713           reason = "index is not in Pmode";
9714           goto report_error;
9715         }
9716
9717       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
9718           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
9719         {
9720           reason = "index is not valid";
9721           goto report_error;
9722         }
9723     }
9724
9725   /* Validate scale factor.  */
9726   if (scale != 1)
9727     {
9728       reason_rtx = GEN_INT (scale);
9729       if (!index)
9730         {
9731           reason = "scale without index";
9732           goto report_error;
9733         }
9734
9735       if (scale != 2 && scale != 4 && scale != 8)
9736         {
9737           reason = "scale is not a valid multiplier";
9738           goto report_error;
9739         }
9740     }
9741
9742   /* Validate displacement.  */
9743   if (disp)
9744     {
9745       reason_rtx = disp;
9746
9747       if (GET_CODE (disp) == CONST
9748           && GET_CODE (XEXP (disp, 0)) == UNSPEC
9749           && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
9750         switch (XINT (XEXP (disp, 0), 1))
9751           {
9752           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
9753              used.  While ABI specify also 32bit relocations, we don't produce
9754              them at all and use IP relative instead.  */
9755           case UNSPEC_GOT:
9756           case UNSPEC_GOTOFF:
9757             gcc_assert (flag_pic);
9758             if (!TARGET_64BIT)
9759               goto is_legitimate_pic;
9760             reason = "64bit address unspec";
9761             goto report_error;
9762
9763           case UNSPEC_GOTPCREL:
9764             gcc_assert (flag_pic);
9765             goto is_legitimate_pic;
9766
9767           case UNSPEC_GOTTPOFF:
9768           case UNSPEC_GOTNTPOFF:
9769           case UNSPEC_INDNTPOFF:
9770           case UNSPEC_NTPOFF:
9771           case UNSPEC_DTPOFF:
9772             break;
9773
9774           default:
9775             reason = "invalid address unspec";
9776             goto report_error;
9777           }
9778
9779       else if (SYMBOLIC_CONST (disp)
9780                && (flag_pic
9781                    || (TARGET_MACHO
9782 #if TARGET_MACHO
9783                        && MACHOPIC_INDIRECT
9784                        && !machopic_operand_p (disp)
9785 #endif
9786                )))
9787         {
9788
9789         is_legitimate_pic:
9790           if (TARGET_64BIT && (index || base))
9791             {
9792               /* foo@dtpoff(%rX) is ok.  */
9793               if (GET_CODE (disp) != CONST
9794                   || GET_CODE (XEXP (disp, 0)) != PLUS
9795                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
9796                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
9797                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
9798                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
9799                 {
9800                   reason = "non-constant pic memory reference";
9801                   goto report_error;
9802                 }
9803             }
9804           else if (! legitimate_pic_address_disp_p (disp))
9805             {
9806               reason = "displacement is an invalid pic construct";
9807               goto report_error;
9808             }
9809
9810           /* This code used to verify that a symbolic pic displacement
9811              includes the pic_offset_table_rtx register.
9812
9813              While this is good idea, unfortunately these constructs may
9814              be created by "adds using lea" optimization for incorrect
9815              code like:
9816
9817              int a;
9818              int foo(int i)
9819                {
9820                  return *(&a+i);
9821                }
9822
9823              This code is nonsensical, but results in addressing
9824              GOT table with pic_offset_table_rtx base.  We can't
9825              just refuse it easily, since it gets matched by
9826              "addsi3" pattern, that later gets split to lea in the
9827              case output register differs from input.  While this
9828              can be handled by separate addsi pattern for this case
9829              that never results in lea, this seems to be easier and
9830              correct fix for crash to disable this test.  */
9831         }
9832       else if (GET_CODE (disp) != LABEL_REF
9833                && !CONST_INT_P (disp)
9834                && (GET_CODE (disp) != CONST
9835                    || !legitimate_constant_p (disp))
9836                && (GET_CODE (disp) != SYMBOL_REF
9837                    || !legitimate_constant_p (disp)))
9838         {
9839           reason = "displacement is not constant";
9840           goto report_error;
9841         }
9842       else if (TARGET_64BIT
9843                && !x86_64_immediate_operand (disp, VOIDmode))
9844         {
9845           reason = "displacement is out of range";
9846           goto report_error;
9847         }
9848     }
9849
9850   /* Everything looks valid.  */
9851   return TRUE;
9852
9853  report_error:
9854   return FALSE;
9855 }
9856
9857 /* Determine if a given RTX is a valid constant address.  */
9858
9859 bool
9860 constant_address_p (rtx x)
9861 {
9862   return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1);
9863 }
9864 \f
9865 /* Return a unique alias set for the GOT.  */
9866
9867 static alias_set_type
9868 ix86_GOT_alias_set (void)
9869 {
9870   static alias_set_type set = -1;
9871   if (set == -1)
9872     set = new_alias_set ();
9873   return set;
9874 }
9875
9876 /* Return a legitimate reference for ORIG (an address) using the
9877    register REG.  If REG is 0, a new pseudo is generated.
9878
9879    There are two types of references that must be handled:
9880
9881    1. Global data references must load the address from the GOT, via
9882       the PIC reg.  An insn is emitted to do this load, and the reg is
9883       returned.
9884
9885    2. Static data references, constant pool addresses, and code labels
9886       compute the address as an offset from the GOT, whose base is in
9887       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
9888       differentiate them from global data objects.  The returned
9889       address is the PIC reg + an unspec constant.
9890
9891    TARGET_LEGITIMATE_ADDRESS_P rejects symbolic references unless the PIC
9892    reg also appears in the address.  */
9893
9894 static rtx
9895 legitimize_pic_address (rtx orig, rtx reg)
9896 {
9897   rtx addr = orig;
9898   rtx new_rtx = orig;
9899   rtx base;
9900
9901 #if TARGET_MACHO
9902   if (TARGET_MACHO && !TARGET_64BIT)
9903     {
9904       if (reg == 0)
9905         reg = gen_reg_rtx (Pmode);
9906       /* Use the generic Mach-O PIC machinery.  */
9907       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
9908     }
9909 #endif
9910
9911   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
9912     new_rtx = addr;
9913   else if (TARGET_64BIT
9914            && ix86_cmodel != CM_SMALL_PIC
9915            && gotoff_operand (addr, Pmode))
9916     {
9917       rtx tmpreg;
9918       /* This symbol may be referenced via a displacement from the PIC
9919          base address (@GOTOFF).  */
9920
9921       if (reload_in_progress)
9922         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9923       if (GET_CODE (addr) == CONST)
9924         addr = XEXP (addr, 0);
9925       if (GET_CODE (addr) == PLUS)
9926           {
9927             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9928                                       UNSPEC_GOTOFF);
9929             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9930           }
9931         else
9932           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9933       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9934       if (!reg)
9935         tmpreg = gen_reg_rtx (Pmode);
9936       else
9937         tmpreg = reg;
9938       emit_move_insn (tmpreg, new_rtx);
9939
9940       if (reg != 0)
9941         {
9942           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
9943                                          tmpreg, 1, OPTAB_DIRECT);
9944           new_rtx = reg;
9945         }
9946       else new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
9947     }
9948   else if (!TARGET_64BIT && gotoff_operand (addr, Pmode))
9949     {
9950       /* This symbol may be referenced via a displacement from the PIC
9951          base address (@GOTOFF).  */
9952
9953       if (reload_in_progress)
9954         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9955       if (GET_CODE (addr) == CONST)
9956         addr = XEXP (addr, 0);
9957       if (GET_CODE (addr) == PLUS)
9958           {
9959             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9960                                       UNSPEC_GOTOFF);
9961             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9962           }
9963         else
9964           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9965       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9966       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9967
9968       if (reg != 0)
9969         {
9970           emit_move_insn (reg, new_rtx);
9971           new_rtx = reg;
9972         }
9973     }
9974   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
9975            /* We can't use @GOTOFF for text labels on VxWorks;
9976               see gotoff_operand.  */
9977            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
9978     {
9979       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9980         {
9981           if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
9982             return legitimize_dllimport_symbol (addr, true);
9983           if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
9984               && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
9985               && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
9986             {
9987               rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), true);
9988               return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
9989             }
9990         }
9991
9992       if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
9993         {
9994           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
9995           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9996           new_rtx = gen_const_mem (Pmode, new_rtx);
9997           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9998
9999           if (reg == 0)
10000             reg = gen_reg_rtx (Pmode);
10001           /* Use directly gen_movsi, otherwise the address is loaded
10002              into register for CSE.  We don't want to CSE this addresses,
10003              instead we CSE addresses from the GOT table, so skip this.  */
10004           emit_insn (gen_movsi (reg, new_rtx));
10005           new_rtx = reg;
10006         }
10007       else
10008         {
10009           /* This symbol must be referenced via a load from the
10010              Global Offset Table (@GOT).  */
10011
10012           if (reload_in_progress)
10013             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
10014           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
10015           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
10016           if (TARGET_64BIT)
10017             new_rtx = force_reg (Pmode, new_rtx);
10018           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
10019           new_rtx = gen_const_mem (Pmode, new_rtx);
10020           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
10021
10022           if (reg == 0)
10023             reg = gen_reg_rtx (Pmode);
10024           emit_move_insn (reg, new_rtx);
10025           new_rtx = reg;
10026         }
10027     }
10028   else
10029     {
10030       if (CONST_INT_P (addr)
10031           && !x86_64_immediate_operand (addr, VOIDmode))
10032         {
10033           if (reg)
10034             {
10035               emit_move_insn (reg, addr);
10036               new_rtx = reg;
10037             }
10038           else
10039             new_rtx = force_reg (Pmode, addr);
10040         }
10041       else if (GET_CODE (addr) == CONST)
10042         {
10043           addr = XEXP (addr, 0);
10044
10045           /* We must match stuff we generate before.  Assume the only
10046              unspecs that can get here are ours.  Not that we could do
10047              anything with them anyway....  */
10048           if (GET_CODE (addr) == UNSPEC
10049               || (GET_CODE (addr) == PLUS
10050                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
10051             return orig;
10052           gcc_assert (GET_CODE (addr) == PLUS);
10053         }
10054       if (GET_CODE (addr) == PLUS)
10055         {
10056           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
10057
10058           /* Check first to see if this is a constant offset from a @GOTOFF
10059              symbol reference.  */
10060           if (gotoff_operand (op0, Pmode)
10061               && CONST_INT_P (op1))
10062             {
10063               if (!TARGET_64BIT)
10064                 {
10065                   if (reload_in_progress)
10066                     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
10067                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
10068                                             UNSPEC_GOTOFF);
10069                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
10070                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
10071                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
10072
10073                   if (reg != 0)
10074                     {
10075                       emit_move_insn (reg, new_rtx);
10076                       new_rtx = reg;
10077                     }
10078                 }
10079               else
10080                 {
10081                   if (INTVAL (op1) < -16*1024*1024
10082                       || INTVAL (op1) >= 16*1024*1024)
10083                     {
10084                       if (!x86_64_immediate_operand (op1, Pmode))
10085                         op1 = force_reg (Pmode, op1);
10086                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
10087                     }
10088                 }
10089             }
10090           else
10091             {
10092               base = legitimize_pic_address (XEXP (addr, 0), reg);
10093               new_rtx  = legitimize_pic_address (XEXP (addr, 1),
10094                                                  base == reg ? NULL_RTX : reg);
10095
10096               if (CONST_INT_P (new_rtx))
10097                 new_rtx = plus_constant (base, INTVAL (new_rtx));
10098               else
10099                 {
10100                   if (GET_CODE (new_rtx) == PLUS && CONSTANT_P (XEXP (new_rtx, 1)))
10101                     {
10102                       base = gen_rtx_PLUS (Pmode, base, XEXP (new_rtx, 0));
10103                       new_rtx = XEXP (new_rtx, 1);
10104                     }
10105                   new_rtx = gen_rtx_PLUS (Pmode, base, new_rtx);
10106                 }
10107             }
10108         }
10109     }
10110   return new_rtx;
10111 }
10112 \f
10113 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
10114
10115 static rtx
10116 get_thread_pointer (int to_reg)
10117 {
10118   rtx tp, reg, insn;
10119
10120   tp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
10121   if (!to_reg)
10122     return tp;
10123
10124   reg = gen_reg_rtx (Pmode);
10125   insn = gen_rtx_SET (VOIDmode, reg, tp);
10126   insn = emit_insn (insn);
10127
10128   return reg;
10129 }
10130
10131 /* A subroutine of ix86_legitimize_address and ix86_expand_move.  FOR_MOV is
10132    false if we expect this to be used for a memory address and true if
10133    we expect to load the address into a register.  */
10134
10135 static rtx
10136 legitimize_tls_address (rtx x, enum tls_model model, int for_mov)
10137 {
10138   rtx dest, base, off, pic, tp;
10139   int type;
10140
10141   switch (model)
10142     {
10143     case TLS_MODEL_GLOBAL_DYNAMIC:
10144       dest = gen_reg_rtx (Pmode);
10145       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
10146
10147       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
10148         {
10149           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns;
10150
10151           start_sequence ();
10152           emit_call_insn (gen_tls_global_dynamic_64 (rax, x));
10153           insns = get_insns ();
10154           end_sequence ();
10155
10156           RTL_CONST_CALL_P (insns) = 1;
10157           emit_libcall_block (insns, dest, rax, x);
10158         }
10159       else if (TARGET_64BIT && TARGET_GNU2_TLS)
10160         emit_insn (gen_tls_global_dynamic_64 (dest, x));
10161       else
10162         emit_insn (gen_tls_global_dynamic_32 (dest, x));
10163
10164       if (TARGET_GNU2_TLS)
10165         {
10166           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
10167
10168           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
10169         }
10170       break;
10171
10172     case TLS_MODEL_LOCAL_DYNAMIC:
10173       base = gen_reg_rtx (Pmode);
10174       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
10175
10176       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
10177         {
10178           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns, note;
10179
10180           start_sequence ();
10181           emit_call_insn (gen_tls_local_dynamic_base_64 (rax));
10182           insns = get_insns ();
10183           end_sequence ();
10184
10185           note = gen_rtx_EXPR_LIST (VOIDmode, const0_rtx, NULL);
10186           note = gen_rtx_EXPR_LIST (VOIDmode, ix86_tls_get_addr (), note);
10187           RTL_CONST_CALL_P (insns) = 1;
10188           emit_libcall_block (insns, base, rax, note);
10189         }
10190       else if (TARGET_64BIT && TARGET_GNU2_TLS)
10191         emit_insn (gen_tls_local_dynamic_base_64 (base));
10192       else
10193         emit_insn (gen_tls_local_dynamic_base_32 (base));
10194
10195       if (TARGET_GNU2_TLS)
10196         {
10197           rtx x = ix86_tls_module_base ();
10198
10199           set_unique_reg_note (get_last_insn (), REG_EQUIV,
10200                                gen_rtx_MINUS (Pmode, x, tp));
10201         }
10202
10203       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
10204       off = gen_rtx_CONST (Pmode, off);
10205
10206       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
10207
10208       if (TARGET_GNU2_TLS)
10209         {
10210           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
10211
10212           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
10213         }
10214
10215       break;
10216
10217     case TLS_MODEL_INITIAL_EXEC:
10218       if (TARGET_64BIT)
10219         {
10220           pic = NULL;
10221           type = UNSPEC_GOTNTPOFF;
10222         }
10223       else if (flag_pic)
10224         {
10225           if (reload_in_progress)
10226             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
10227           pic = pic_offset_table_rtx;
10228           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
10229         }
10230       else if (!TARGET_ANY_GNU_TLS)
10231         {
10232           pic = gen_reg_rtx (Pmode);
10233           emit_insn (gen_set_got (pic));
10234           type = UNSPEC_GOTTPOFF;
10235         }
10236       else
10237         {
10238           pic = NULL;
10239           type = UNSPEC_INDNTPOFF;
10240         }
10241
10242       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), type);
10243       off = gen_rtx_CONST (Pmode, off);
10244       if (pic)
10245         off = gen_rtx_PLUS (Pmode, pic, off);
10246       off = gen_const_mem (Pmode, off);
10247       set_mem_alias_set (off, ix86_GOT_alias_set ());
10248
10249       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
10250         {
10251           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
10252           off = force_reg (Pmode, off);
10253           return gen_rtx_PLUS (Pmode, base, off);
10254         }
10255       else
10256         {
10257           base = get_thread_pointer (true);
10258           dest = gen_reg_rtx (Pmode);
10259           emit_insn (gen_subsi3 (dest, base, off));
10260         }
10261       break;
10262
10263     case TLS_MODEL_LOCAL_EXEC:
10264       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
10265                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
10266                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
10267       off = gen_rtx_CONST (Pmode, off);
10268
10269       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
10270         {
10271           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
10272           return gen_rtx_PLUS (Pmode, base, off);
10273         }
10274       else
10275         {
10276           base = get_thread_pointer (true);
10277           dest = gen_reg_rtx (Pmode);
10278           emit_insn (gen_subsi3 (dest, base, off));
10279         }
10280       break;
10281
10282     default:
10283       gcc_unreachable ();
10284     }
10285
10286   return dest;
10287 }
10288
10289 /* Create or return the unique __imp_DECL dllimport symbol corresponding
10290    to symbol DECL.  */
10291
10292 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
10293   htab_t dllimport_map;
10294
10295 static tree
10296 get_dllimport_decl (tree decl)
10297 {
10298   struct tree_map *h, in;
10299   void **loc;
10300   const char *name;
10301   const char *prefix;
10302   size_t namelen, prefixlen;
10303   char *imp_name;
10304   tree to;
10305   rtx rtl;
10306
10307   if (!dllimport_map)
10308     dllimport_map = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
10309
10310   in.hash = htab_hash_pointer (decl);
10311   in.base.from = decl;
10312   loc = htab_find_slot_with_hash (dllimport_map, &in, in.hash, INSERT);
10313   h = (struct tree_map *) *loc;
10314   if (h)
10315     return h->to;
10316
10317   *loc = h = GGC_NEW (struct tree_map);
10318   h->hash = in.hash;
10319   h->base.from = decl;
10320   h->to = to = build_decl (DECL_SOURCE_LOCATION (decl),
10321                            VAR_DECL, NULL, ptr_type_node);
10322   DECL_ARTIFICIAL (to) = 1;
10323   DECL_IGNORED_P (to) = 1;
10324   DECL_EXTERNAL (to) = 1;
10325   TREE_READONLY (to) = 1;
10326
10327   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
10328   name = targetm.strip_name_encoding (name);
10329   prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
10330     ? "*__imp_" : "*__imp__";
10331   namelen = strlen (name);
10332   prefixlen = strlen (prefix);
10333   imp_name = (char *) alloca (namelen + prefixlen + 1);
10334   memcpy (imp_name, prefix, prefixlen);
10335   memcpy (imp_name + prefixlen, name, namelen + 1);
10336
10337   name = ggc_alloc_string (imp_name, namelen + prefixlen);
10338   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
10339   SET_SYMBOL_REF_DECL (rtl, to);
10340   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL;
10341
10342   rtl = gen_const_mem (Pmode, rtl);
10343   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
10344
10345   SET_DECL_RTL (to, rtl);
10346   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
10347
10348   return to;
10349 }
10350
10351 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
10352    true if we require the result be a register.  */
10353
10354 static rtx
10355 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
10356 {
10357   tree imp_decl;
10358   rtx x;
10359
10360   gcc_assert (SYMBOL_REF_DECL (symbol));
10361   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol));
10362
10363   x = DECL_RTL (imp_decl);
10364   if (want_reg)
10365     x = force_reg (Pmode, x);
10366   return x;
10367 }
10368
10369 /* Try machine-dependent ways of modifying an illegitimate address
10370    to be legitimate.  If we find one, return the new, valid address.
10371    This macro is used in only one place: `memory_address' in explow.c.
10372
10373    OLDX is the address as it was before break_out_memory_refs was called.
10374    In some cases it is useful to look at this to decide what needs to be done.
10375
10376    It is always safe for this macro to do nothing.  It exists to recognize
10377    opportunities to optimize the output.
10378
10379    For the 80386, we handle X+REG by loading X into a register R and
10380    using R+REG.  R will go in a general reg and indexing will be used.
10381    However, if REG is a broken-out memory address or multiplication,
10382    nothing needs to be done because REG can certainly go in a general reg.
10383
10384    When -fpic is used, special handling is needed for symbolic references.
10385    See comments by legitimize_pic_address in i386.c for details.  */
10386
10387 static rtx
10388 ix86_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
10389                          enum machine_mode mode)
10390 {
10391   int changed = 0;
10392   unsigned log;
10393
10394   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
10395   if (log)
10396     return legitimize_tls_address (x, (enum tls_model) log, false);
10397   if (GET_CODE (x) == CONST
10398       && GET_CODE (XEXP (x, 0)) == PLUS
10399       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
10400       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
10401     {
10402       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
10403                                       (enum tls_model) log, false);
10404       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
10405     }
10406
10407   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
10408     {
10409       if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (x))
10410         return legitimize_dllimport_symbol (x, true);
10411       if (GET_CODE (x) == CONST
10412           && GET_CODE (XEXP (x, 0)) == PLUS
10413           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
10414           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (x, 0), 0)))
10415         {
10416           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (x, 0), 0), true);
10417           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
10418         }
10419     }
10420
10421   if (flag_pic && SYMBOLIC_CONST (x))
10422     return legitimize_pic_address (x, 0);
10423
10424   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
10425   if (GET_CODE (x) == ASHIFT
10426       && CONST_INT_P (XEXP (x, 1))
10427       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
10428     {
10429       changed = 1;
10430       log = INTVAL (XEXP (x, 1));
10431       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
10432                         GEN_INT (1 << log));
10433     }
10434
10435   if (GET_CODE (x) == PLUS)
10436     {
10437       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
10438
10439       if (GET_CODE (XEXP (x, 0)) == ASHIFT
10440           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
10441           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
10442         {
10443           changed = 1;
10444           log = INTVAL (XEXP (XEXP (x, 0), 1));
10445           XEXP (x, 0) = gen_rtx_MULT (Pmode,
10446                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
10447                                       GEN_INT (1 << log));
10448         }
10449
10450       if (GET_CODE (XEXP (x, 1)) == ASHIFT
10451           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
10452           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
10453         {
10454           changed = 1;
10455           log = INTVAL (XEXP (XEXP (x, 1), 1));
10456           XEXP (x, 1) = gen_rtx_MULT (Pmode,
10457                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
10458                                       GEN_INT (1 << log));
10459         }
10460
10461       /* Put multiply first if it isn't already.  */
10462       if (GET_CODE (XEXP (x, 1)) == MULT)
10463         {
10464           rtx tmp = XEXP (x, 0);
10465           XEXP (x, 0) = XEXP (x, 1);
10466           XEXP (x, 1) = tmp;
10467           changed = 1;
10468         }
10469
10470       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
10471          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
10472          created by virtual register instantiation, register elimination, and
10473          similar optimizations.  */
10474       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
10475         {
10476           changed = 1;
10477           x = gen_rtx_PLUS (Pmode,
10478                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
10479                                           XEXP (XEXP (x, 1), 0)),
10480                             XEXP (XEXP (x, 1), 1));
10481         }
10482
10483       /* Canonicalize
10484          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
10485          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
10486       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
10487                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
10488                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
10489                && CONSTANT_P (XEXP (x, 1)))
10490         {
10491           rtx constant;
10492           rtx other = NULL_RTX;
10493
10494           if (CONST_INT_P (XEXP (x, 1)))
10495             {
10496               constant = XEXP (x, 1);
10497               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
10498             }
10499           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
10500             {
10501               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
10502               other = XEXP (x, 1);
10503             }
10504           else
10505             constant = 0;
10506
10507           if (constant)
10508             {
10509               changed = 1;
10510               x = gen_rtx_PLUS (Pmode,
10511                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
10512                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
10513                                 plus_constant (other, INTVAL (constant)));
10514             }
10515         }
10516
10517       if (changed && ix86_legitimate_address_p (mode, x, FALSE))
10518         return x;
10519
10520       if (GET_CODE (XEXP (x, 0)) == MULT)
10521         {
10522           changed = 1;
10523           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
10524         }
10525
10526       if (GET_CODE (XEXP (x, 1)) == MULT)
10527         {
10528           changed = 1;
10529           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
10530         }
10531
10532       if (changed
10533           && REG_P (XEXP (x, 1))
10534           && REG_P (XEXP (x, 0)))
10535         return x;
10536
10537       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
10538         {
10539           changed = 1;
10540           x = legitimize_pic_address (x, 0);
10541         }
10542
10543       if (changed && ix86_legitimate_address_p (mode, x, FALSE))
10544         return x;
10545
10546       if (REG_P (XEXP (x, 0)))
10547         {
10548           rtx temp = gen_reg_rtx (Pmode);
10549           rtx val  = force_operand (XEXP (x, 1), temp);
10550           if (val != temp)
10551             emit_move_insn (temp, val);
10552
10553           XEXP (x, 1) = temp;
10554           return x;
10555         }
10556
10557       else if (REG_P (XEXP (x, 1)))
10558         {
10559           rtx temp = gen_reg_rtx (Pmode);
10560           rtx val  = force_operand (XEXP (x, 0), temp);
10561           if (val != temp)
10562             emit_move_insn (temp, val);
10563
10564           XEXP (x, 0) = temp;
10565           return x;
10566         }
10567     }
10568
10569   return x;
10570 }
10571 \f
10572 /* Print an integer constant expression in assembler syntax.  Addition
10573    and subtraction are the only arithmetic that may appear in these
10574    expressions.  FILE is the stdio stream to write to, X is the rtx, and
10575    CODE is the operand print code from the output string.  */
10576
10577 static void
10578 output_pic_addr_const (FILE *file, rtx x, int code)
10579 {
10580   char buf[256];
10581
10582   switch (GET_CODE (x))
10583     {
10584     case PC:
10585       gcc_assert (flag_pic);
10586       putc ('.', file);
10587       break;
10588
10589     case SYMBOL_REF:
10590       if (! TARGET_MACHO || TARGET_64BIT)
10591         output_addr_const (file, x);
10592       else
10593         {
10594           const char *name = XSTR (x, 0);
10595
10596           /* Mark the decl as referenced so that cgraph will
10597              output the function.  */
10598           if (SYMBOL_REF_DECL (x))
10599             mark_decl_referenced (SYMBOL_REF_DECL (x));
10600
10601 #if TARGET_MACHO
10602           if (MACHOPIC_INDIRECT
10603               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
10604             name = machopic_indirection_name (x, /*stub_p=*/true);
10605 #endif
10606           assemble_name (file, name);
10607         }
10608       if (!TARGET_MACHO && !(TARGET_64BIT && DEFAULT_ABI == MS_ABI)
10609           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
10610         fputs ("@PLT", file);
10611       break;
10612
10613     case LABEL_REF:
10614       x = XEXP (x, 0);
10615       /* FALLTHRU */
10616     case CODE_LABEL:
10617       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
10618       assemble_name (asm_out_file, buf);
10619       break;
10620
10621     case CONST_INT:
10622       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
10623       break;
10624
10625     case CONST:
10626       /* This used to output parentheses around the expression,
10627          but that does not work on the 386 (either ATT or BSD assembler).  */
10628       output_pic_addr_const (file, XEXP (x, 0), code);
10629       break;
10630
10631     case CONST_DOUBLE:
10632       if (GET_MODE (x) == VOIDmode)
10633         {
10634           /* We can use %d if the number is <32 bits and positive.  */
10635           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
10636             fprintf (file, "0x%lx%08lx",
10637                      (unsigned long) CONST_DOUBLE_HIGH (x),
10638                      (unsigned long) CONST_DOUBLE_LOW (x));
10639           else
10640             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
10641         }
10642       else
10643         /* We can't handle floating point constants;
10644            PRINT_OPERAND must handle them.  */
10645         output_operand_lossage ("floating constant misused");
10646       break;
10647
10648     case PLUS:
10649       /* Some assemblers need integer constants to appear first.  */
10650       if (CONST_INT_P (XEXP (x, 0)))
10651         {
10652           output_pic_addr_const (file, XEXP (x, 0), code);
10653           putc ('+', file);
10654           output_pic_addr_const (file, XEXP (x, 1), code);
10655         }
10656       else
10657         {
10658           gcc_assert (CONST_INT_P (XEXP (x, 1)));
10659           output_pic_addr_const (file, XEXP (x, 1), code);
10660           putc ('+', file);
10661           output_pic_addr_const (file, XEXP (x, 0), code);
10662         }
10663       break;
10664
10665     case MINUS:
10666       if (!TARGET_MACHO)
10667         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
10668       output_pic_addr_const (file, XEXP (x, 0), code);
10669       putc ('-', file);
10670       output_pic_addr_const (file, XEXP (x, 1), code);
10671       if (!TARGET_MACHO)
10672         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
10673       break;
10674
10675      case UNSPEC:
10676        gcc_assert (XVECLEN (x, 0) == 1);
10677        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
10678        switch (XINT (x, 1))
10679         {
10680         case UNSPEC_GOT:
10681           fputs ("@GOT", file);
10682           break;
10683         case UNSPEC_GOTOFF:
10684           fputs ("@GOTOFF", file);
10685           break;
10686         case UNSPEC_PLTOFF:
10687           fputs ("@PLTOFF", file);
10688           break;
10689         case UNSPEC_GOTPCREL:
10690           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10691                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
10692           break;
10693         case UNSPEC_GOTTPOFF:
10694           /* FIXME: This might be @TPOFF in Sun ld too.  */
10695           fputs ("@GOTTPOFF", file);
10696           break;
10697         case UNSPEC_TPOFF:
10698           fputs ("@TPOFF", file);
10699           break;
10700         case UNSPEC_NTPOFF:
10701           if (TARGET_64BIT)
10702             fputs ("@TPOFF", file);
10703           else
10704             fputs ("@NTPOFF", file);
10705           break;
10706         case UNSPEC_DTPOFF:
10707           fputs ("@DTPOFF", file);
10708           break;
10709         case UNSPEC_GOTNTPOFF:
10710           if (TARGET_64BIT)
10711             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10712                    "@GOTTPOFF(%rip)": "@GOTTPOFF[rip]", file);
10713           else
10714             fputs ("@GOTNTPOFF", file);
10715           break;
10716         case UNSPEC_INDNTPOFF:
10717           fputs ("@INDNTPOFF", file);
10718           break;
10719 #if TARGET_MACHO
10720         case UNSPEC_MACHOPIC_OFFSET:
10721           putc ('-', file);
10722           machopic_output_function_base_name (file);
10723           break;
10724 #endif
10725         default:
10726           output_operand_lossage ("invalid UNSPEC as operand");
10727           break;
10728         }
10729        break;
10730
10731     default:
10732       output_operand_lossage ("invalid expression as operand");
10733     }
10734 }
10735
10736 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
10737    We need to emit DTP-relative relocations.  */
10738
10739 static void ATTRIBUTE_UNUSED
10740 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
10741 {
10742   fputs (ASM_LONG, file);
10743   output_addr_const (file, x);
10744   fputs ("@DTPOFF", file);
10745   switch (size)
10746     {
10747     case 4:
10748       break;
10749     case 8:
10750       fputs (", 0", file);
10751       break;
10752     default:
10753       gcc_unreachable ();
10754    }
10755 }
10756
10757 /* Return true if X is a representation of the PIC register.  This copes
10758    with calls from ix86_find_base_term, where the register might have
10759    been replaced by a cselib value.  */
10760
10761 static bool
10762 ix86_pic_register_p (rtx x)
10763 {
10764   if (GET_CODE (x) == VALUE)
10765     return (pic_offset_table_rtx
10766             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
10767   else
10768     return REG_P (x) && REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
10769 }
10770
10771 /* In the name of slightly smaller debug output, and to cater to
10772    general assembler lossage, recognize PIC+GOTOFF and turn it back
10773    into a direct symbol reference.
10774
10775    On Darwin, this is necessary to avoid a crash, because Darwin
10776    has a different PIC label for each routine but the DWARF debugging
10777    information is not associated with any particular routine, so it's
10778    necessary to remove references to the PIC label from RTL stored by
10779    the DWARF output code.  */
10780
10781 static rtx
10782 ix86_delegitimize_address (rtx orig_x)
10783 {
10784   rtx x = orig_x;
10785   /* reg_addend is NULL or a multiple of some register.  */
10786   rtx reg_addend = NULL_RTX;
10787   /* const_addend is NULL or a const_int.  */
10788   rtx const_addend = NULL_RTX;
10789   /* This is the result, or NULL.  */
10790   rtx result = NULL_RTX;
10791
10792   if (MEM_P (x))
10793     x = XEXP (x, 0);
10794
10795   if (TARGET_64BIT)
10796     {
10797       if (GET_CODE (x) != CONST
10798           || GET_CODE (XEXP (x, 0)) != UNSPEC
10799           || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL
10800           || !MEM_P (orig_x))
10801         return orig_x;
10802       return XVECEXP (XEXP (x, 0), 0, 0);
10803     }
10804
10805   if (GET_CODE (x) != PLUS
10806       || GET_CODE (XEXP (x, 1)) != CONST)
10807     return orig_x;
10808
10809   if (ix86_pic_register_p (XEXP (x, 0)))
10810     /* %ebx + GOT/GOTOFF */
10811     ;
10812   else if (GET_CODE (XEXP (x, 0)) == PLUS)
10813     {
10814       /* %ebx + %reg * scale + GOT/GOTOFF */
10815       reg_addend = XEXP (x, 0);
10816       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
10817         reg_addend = XEXP (reg_addend, 1);
10818       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
10819         reg_addend = XEXP (reg_addend, 0);
10820       else
10821         return orig_x;
10822       if (!REG_P (reg_addend)
10823           && GET_CODE (reg_addend) != MULT
10824           && GET_CODE (reg_addend) != ASHIFT)
10825         return orig_x;
10826     }
10827   else
10828     return orig_x;
10829
10830   x = XEXP (XEXP (x, 1), 0);
10831   if (GET_CODE (x) == PLUS
10832       && CONST_INT_P (XEXP (x, 1)))
10833     {
10834       const_addend = XEXP (x, 1);
10835       x = XEXP (x, 0);
10836     }
10837
10838   if (GET_CODE (x) == UNSPEC
10839       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x))
10840           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))))
10841     result = XVECEXP (x, 0, 0);
10842
10843   if (TARGET_MACHO && darwin_local_data_pic (x)
10844       && !MEM_P (orig_x))
10845     result = XVECEXP (x, 0, 0);
10846
10847   if (! result)
10848     return orig_x;
10849
10850   if (const_addend)
10851     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
10852   if (reg_addend)
10853     result = gen_rtx_PLUS (Pmode, reg_addend, result);
10854   return result;
10855 }
10856
10857 /* If X is a machine specific address (i.e. a symbol or label being
10858    referenced as a displacement from the GOT implemented using an
10859    UNSPEC), then return the base term.  Otherwise return X.  */
10860
10861 rtx
10862 ix86_find_base_term (rtx x)
10863 {
10864   rtx term;
10865
10866   if (TARGET_64BIT)
10867     {
10868       if (GET_CODE (x) != CONST)
10869         return x;
10870       term = XEXP (x, 0);
10871       if (GET_CODE (term) == PLUS
10872           && (CONST_INT_P (XEXP (term, 1))
10873               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
10874         term = XEXP (term, 0);
10875       if (GET_CODE (term) != UNSPEC
10876           || XINT (term, 1) != UNSPEC_GOTPCREL)
10877         return x;
10878
10879       return XVECEXP (term, 0, 0);
10880     }
10881
10882   return ix86_delegitimize_address (x);
10883 }
10884 \f
10885 static void
10886 put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
10887                     int fp, FILE *file)
10888 {
10889   const char *suffix;
10890
10891   if (mode == CCFPmode || mode == CCFPUmode)
10892     {
10893       code = ix86_fp_compare_code_to_integer (code);
10894       mode = CCmode;
10895     }
10896   if (reverse)
10897     code = reverse_condition (code);
10898
10899   switch (code)
10900     {
10901     case EQ:
10902       switch (mode)
10903         {
10904         case CCAmode:
10905           suffix = "a";
10906           break;
10907
10908         case CCCmode:
10909           suffix = "c";
10910           break;
10911
10912         case CCOmode:
10913           suffix = "o";
10914           break;
10915
10916         case CCSmode:
10917           suffix = "s";
10918           break;
10919
10920         default:
10921           suffix = "e";
10922         }
10923       break;
10924     case NE:
10925       switch (mode)
10926         {
10927         case CCAmode:
10928           suffix = "na";
10929           break;
10930
10931         case CCCmode:
10932           suffix = "nc";
10933           break;
10934
10935         case CCOmode:
10936           suffix = "no";
10937           break;
10938
10939         case CCSmode:
10940           suffix = "ns";
10941           break;
10942
10943         default:
10944           suffix = "ne";
10945         }
10946       break;
10947     case GT:
10948       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
10949       suffix = "g";
10950       break;
10951     case GTU:
10952       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
10953          Those same assemblers have the same but opposite lossage on cmov.  */
10954       if (mode == CCmode)
10955         suffix = fp ? "nbe" : "a";
10956       else if (mode == CCCmode)
10957         suffix = "b";
10958       else
10959         gcc_unreachable ();
10960       break;
10961     case LT:
10962       switch (mode)
10963         {
10964         case CCNOmode:
10965         case CCGOCmode:
10966           suffix = "s";
10967           break;
10968
10969         case CCmode:
10970         case CCGCmode:
10971           suffix = "l";
10972           break;
10973
10974         default:
10975           gcc_unreachable ();
10976         }
10977       break;
10978     case LTU:
10979       gcc_assert (mode == CCmode || mode == CCCmode);
10980       suffix = "b";
10981       break;
10982     case GE:
10983       switch (mode)
10984         {
10985         case CCNOmode:
10986         case CCGOCmode:
10987           suffix = "ns";
10988           break;
10989
10990         case CCmode:
10991         case CCGCmode:
10992           suffix = "ge";
10993           break;
10994
10995         default:
10996           gcc_unreachable ();
10997         }
10998       break;
10999     case GEU:
11000       /* ??? As above.  */
11001       gcc_assert (mode == CCmode || mode == CCCmode);
11002       suffix = fp ? "nb" : "ae";
11003       break;
11004     case LE:
11005       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
11006       suffix = "le";
11007       break;
11008     case LEU:
11009       /* ??? As above.  */
11010       if (mode == CCmode)
11011         suffix = "be";
11012       else if (mode == CCCmode)
11013         suffix = fp ? "nb" : "ae";
11014       else
11015         gcc_unreachable ();
11016       break;
11017     case UNORDERED:
11018       suffix = fp ? "u" : "p";
11019       break;
11020     case ORDERED:
11021       suffix = fp ? "nu" : "np";
11022       break;
11023     default:
11024       gcc_unreachable ();
11025     }
11026   fputs (suffix, file);
11027 }
11028
11029 /* Print the name of register X to FILE based on its machine mode and number.
11030    If CODE is 'w', pretend the mode is HImode.
11031    If CODE is 'b', pretend the mode is QImode.
11032    If CODE is 'k', pretend the mode is SImode.
11033    If CODE is 'q', pretend the mode is DImode.
11034    If CODE is 'x', pretend the mode is V4SFmode.
11035    If CODE is 't', pretend the mode is V8SFmode.
11036    If CODE is 'h', pretend the reg is the 'high' byte register.
11037    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
11038    If CODE is 'd', duplicate the operand for AVX instruction.
11039  */
11040
11041 void
11042 print_reg (rtx x, int code, FILE *file)
11043 {
11044   const char *reg;
11045   bool duplicated = code == 'd' && TARGET_AVX;
11046
11047   gcc_assert (x == pc_rtx
11048               || (REGNO (x) != ARG_POINTER_REGNUM
11049                   && REGNO (x) != FRAME_POINTER_REGNUM
11050                   && REGNO (x) != FLAGS_REG
11051                   && REGNO (x) != FPSR_REG
11052                   && REGNO (x) != FPCR_REG));
11053
11054   if (ASSEMBLER_DIALECT == ASM_ATT)
11055     putc ('%', file);
11056
11057   if (x == pc_rtx)
11058     {
11059       gcc_assert (TARGET_64BIT);
11060       fputs ("rip", file);
11061       return;
11062     }
11063
11064   if (code == 'w' || MMX_REG_P (x))
11065     code = 2;
11066   else if (code == 'b')
11067     code = 1;
11068   else if (code == 'k')
11069     code = 4;
11070   else if (code == 'q')
11071     code = 8;
11072   else if (code == 'y')
11073     code = 3;
11074   else if (code == 'h')
11075     code = 0;
11076   else if (code == 'x')
11077     code = 16;
11078   else if (code == 't')
11079     code = 32;
11080   else
11081     code = GET_MODE_SIZE (GET_MODE (x));
11082
11083   /* Irritatingly, AMD extended registers use different naming convention
11084      from the normal registers.  */
11085   if (REX_INT_REG_P (x))
11086     {
11087       gcc_assert (TARGET_64BIT);
11088       switch (code)
11089         {
11090           case 0:
11091             error ("extended registers have no high halves");
11092             break;
11093           case 1:
11094             fprintf (file, "r%ib", REGNO (x) - FIRST_REX_INT_REG + 8);
11095             break;
11096           case 2:
11097             fprintf (file, "r%iw", REGNO (x) - FIRST_REX_INT_REG + 8);
11098             break;
11099           case 4:
11100             fprintf (file, "r%id", REGNO (x) - FIRST_REX_INT_REG + 8);
11101             break;
11102           case 8:
11103             fprintf (file, "r%i", REGNO (x) - FIRST_REX_INT_REG + 8);
11104             break;
11105           default:
11106             error ("unsupported operand size for extended register");
11107             break;
11108         }
11109       return;
11110     }
11111
11112   reg = NULL;
11113   switch (code)
11114     {
11115     case 3:
11116       if (STACK_TOP_P (x))
11117         {
11118           reg = "st(0)";
11119           break;
11120         }
11121       /* FALLTHRU */
11122     case 8:
11123     case 4:
11124     case 12:
11125       if (! ANY_FP_REG_P (x))
11126         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
11127       /* FALLTHRU */
11128     case 16:
11129     case 2:
11130     normal:
11131       reg = hi_reg_name[REGNO (x)];
11132       break;
11133     case 1:
11134       if (REGNO (x) >= ARRAY_SIZE (qi_reg_name))
11135         goto normal;
11136       reg = qi_reg_name[REGNO (x)];
11137       break;
11138     case 0:
11139       if (REGNO (x) >= ARRAY_SIZE (qi_high_reg_name))
11140         goto normal;
11141       reg = qi_high_reg_name[REGNO (x)];
11142       break;
11143     case 32:
11144       if (SSE_REG_P (x))
11145         {
11146           gcc_assert (!duplicated);
11147           putc ('y', file);
11148           fputs (hi_reg_name[REGNO (x)] + 1, file);
11149           return;
11150         }
11151       break;
11152     default:
11153       gcc_unreachable ();
11154     }
11155
11156   fputs (reg, file);
11157   if (duplicated)
11158     {
11159       if (ASSEMBLER_DIALECT == ASM_ATT)
11160         fprintf (file, ", %%%s", reg);
11161       else
11162         fprintf (file, ", %s", reg);
11163     }
11164 }
11165
11166 /* Locate some local-dynamic symbol still in use by this function
11167    so that we can print its name in some tls_local_dynamic_base
11168    pattern.  */
11169
11170 static int
11171 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
11172 {
11173   rtx x = *px;
11174
11175   if (GET_CODE (x) == SYMBOL_REF
11176       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
11177     {
11178       cfun->machine->some_ld_name = XSTR (x, 0);
11179       return 1;
11180     }
11181
11182   return 0;
11183 }
11184
11185 static const char *
11186 get_some_local_dynamic_name (void)
11187 {
11188   rtx insn;
11189
11190   if (cfun->machine->some_ld_name)
11191     return cfun->machine->some_ld_name;
11192
11193   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
11194     if (INSN_P (insn)
11195         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
11196       return cfun->machine->some_ld_name;
11197
11198   gcc_unreachable ();
11199 }
11200
11201 /* Meaning of CODE:
11202    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
11203    C -- print opcode suffix for set/cmov insn.
11204    c -- like C, but print reversed condition
11205    E,e -- likewise, but for compare-and-branch fused insn.
11206    F,f -- likewise, but for floating-point.
11207    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
11208         otherwise nothing
11209    R -- print the prefix for register names.
11210    z -- print the opcode suffix for the size of the current operand.
11211    Z -- likewise, with special suffixes for x87 instructions.
11212    * -- print a star (in certain assembler syntax)
11213    A -- print an absolute memory reference.
11214    w -- print the operand as if it's a "word" (HImode) even if it isn't.
11215    s -- print a shift double count, followed by the assemblers argument
11216         delimiter.
11217    b -- print the QImode name of the register for the indicated operand.
11218         %b0 would print %al if operands[0] is reg 0.
11219    w --  likewise, print the HImode name of the register.
11220    k --  likewise, print the SImode name of the register.
11221    q --  likewise, print the DImode name of the register.
11222    x --  likewise, print the V4SFmode name of the register.
11223    t --  likewise, print the V8SFmode name of the register.
11224    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
11225    y -- print "st(0)" instead of "st" as a register.
11226    d -- print duplicated register operand for AVX instruction.
11227    D -- print condition for SSE cmp instruction.
11228    P -- if PIC, print an @PLT suffix.
11229    X -- don't print any sort of PIC '@' suffix for a symbol.
11230    & -- print some in-use local-dynamic symbol name.
11231    H -- print a memory address offset by 8; used for sse high-parts
11232    Y -- print condition for SSE5 com* instruction.
11233    + -- print a branch hint as 'cs' or 'ds' prefix
11234    ; -- print a semicolon (after prefixes due to bug in older gas).
11235  */
11236
11237 void
11238 print_operand (FILE *file, rtx x, int code)
11239 {
11240   if (code)
11241     {
11242       switch (code)
11243         {
11244         case '*':
11245           if (ASSEMBLER_DIALECT == ASM_ATT)
11246             putc ('*', file);
11247           return;
11248
11249         case '&':
11250           assemble_name (file, get_some_local_dynamic_name ());
11251           return;
11252
11253         case 'A':
11254           switch (ASSEMBLER_DIALECT)
11255             {
11256             case ASM_ATT:
11257               putc ('*', file);
11258               break;
11259
11260             case ASM_INTEL:
11261               /* Intel syntax. For absolute addresses, registers should not
11262                  be surrounded by braces.  */
11263               if (!REG_P (x))
11264                 {
11265                   putc ('[', file);
11266                   PRINT_OPERAND (file, x, 0);
11267                   putc (']', file);
11268                   return;
11269                 }
11270               break;
11271
11272             default:
11273               gcc_unreachable ();
11274             }
11275
11276           PRINT_OPERAND (file, x, 0);
11277           return;
11278
11279
11280         case 'L':
11281           if (ASSEMBLER_DIALECT == ASM_ATT)
11282             putc ('l', file);
11283           return;
11284
11285         case 'W':
11286           if (ASSEMBLER_DIALECT == ASM_ATT)
11287             putc ('w', file);
11288           return;
11289
11290         case 'B':
11291           if (ASSEMBLER_DIALECT == ASM_ATT)
11292             putc ('b', file);
11293           return;
11294
11295         case 'Q':
11296           if (ASSEMBLER_DIALECT == ASM_ATT)
11297             putc ('l', file);
11298           return;
11299
11300         case 'S':
11301           if (ASSEMBLER_DIALECT == ASM_ATT)
11302             putc ('s', file);
11303           return;
11304
11305         case 'T':
11306           if (ASSEMBLER_DIALECT == ASM_ATT)
11307             putc ('t', file);
11308           return;
11309
11310         case 'z':
11311           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
11312             {
11313               /* Opcodes don't get size suffixes if using Intel opcodes.  */
11314               if (ASSEMBLER_DIALECT == ASM_INTEL)
11315                 return;
11316
11317               switch (GET_MODE_SIZE (GET_MODE (x)))
11318                 {
11319                 case 1:
11320                   putc ('b', file);
11321                   return;
11322
11323                 case 2:
11324                   putc ('w', file);
11325                   return;
11326
11327                 case 4:
11328                   putc ('l', file);
11329                   return;
11330
11331                 case 8:
11332                   putc ('q', file);
11333                   return;
11334
11335                 default:
11336                   output_operand_lossage
11337                     ("invalid operand size for operand code '%c'", code);
11338                   return;
11339                 }
11340             }
11341
11342           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
11343             warning
11344               (0, "non-integer operand used with operand code '%c'", code);
11345           /* FALLTHRU */
11346
11347         case 'Z':
11348           /* 387 opcodes don't get size suffixes if using Intel opcodes.  */
11349           if (ASSEMBLER_DIALECT == ASM_INTEL)
11350             return;
11351
11352           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
11353             {
11354               switch (GET_MODE_SIZE (GET_MODE (x)))
11355                 {
11356                 case 2:
11357 #ifdef HAVE_AS_IX86_FILDS
11358                   putc ('s', file);
11359 #endif
11360                   return;
11361
11362                 case 4:
11363                   putc ('l', file);
11364                   return;
11365
11366                 case 8:
11367 #ifdef HAVE_AS_IX86_FILDQ
11368                   putc ('q', file);
11369 #else
11370                   fputs ("ll", file);
11371 #endif
11372                   return;
11373
11374                 default:
11375                   break;
11376                 }
11377             }
11378           else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
11379             {
11380               /* 387 opcodes don't get size suffixes
11381                  if the operands are registers.  */
11382               if (STACK_REG_P (x))
11383                 return;
11384
11385               switch (GET_MODE_SIZE (GET_MODE (x)))
11386                 {
11387                 case 4:
11388                   putc ('s', file);
11389                   return;
11390
11391                 case 8:
11392                   putc ('l', file);
11393                   return;
11394
11395                 case 12:
11396                 case 16:
11397                   putc ('t', file);
11398                   return;
11399
11400                 default:
11401                   break;
11402                 }
11403             }
11404           else
11405             {
11406               output_operand_lossage
11407                 ("invalid operand type used with operand code '%c'", code);
11408               return;
11409             }
11410
11411           output_operand_lossage
11412             ("invalid operand size for operand code '%c'", code);
11413           return;
11414             
11415         case 'd':
11416         case 'b':
11417         case 'w':
11418         case 'k':
11419         case 'q':
11420         case 'h':
11421         case 't':
11422         case 'y':
11423         case 'x':
11424         case 'X':
11425         case 'P':
11426           break;
11427
11428         case 's':
11429           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
11430             {
11431               PRINT_OPERAND (file, x, 0);
11432               fputs (", ", file);
11433             }
11434           return;
11435
11436         case 'D':
11437           /* Little bit of braindamage here.  The SSE compare instructions
11438              does use completely different names for the comparisons that the
11439              fp conditional moves.  */
11440           if (TARGET_AVX)
11441             {
11442               switch (GET_CODE (x))
11443                 {
11444                 case EQ:
11445                   fputs ("eq", file);
11446                   break;
11447                 case UNEQ:
11448                   fputs ("eq_us", file);
11449                   break;
11450                 case LT:
11451                   fputs ("lt", file);
11452                   break;
11453                 case UNLT:
11454                   fputs ("nge", file);
11455                   break;
11456                 case LE:
11457                   fputs ("le", file);
11458                   break;
11459                 case UNLE:
11460                   fputs ("ngt", file);
11461                   break;
11462                 case UNORDERED:
11463                   fputs ("unord", file);
11464                   break;
11465                 case NE:
11466                   fputs ("neq", file);
11467                   break;
11468                 case LTGT:
11469                   fputs ("neq_oq", file);
11470                   break;
11471                 case GE:
11472                   fputs ("ge", file);
11473                   break;
11474                 case UNGE:
11475                   fputs ("nlt", file);
11476                   break;
11477                 case GT:
11478                   fputs ("gt", file);
11479                   break;
11480                 case UNGT:
11481                   fputs ("nle", file);
11482                   break;
11483                 case ORDERED:
11484                   fputs ("ord", file);
11485                   break;
11486                 default:
11487                   output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
11488                   return;
11489                 }
11490             }
11491           else
11492             {
11493               switch (GET_CODE (x))
11494                 {
11495                 case EQ:
11496                 case UNEQ:
11497                   fputs ("eq", file);
11498                   break;
11499                 case LT:
11500                 case UNLT:
11501                   fputs ("lt", file);
11502                   break;
11503                 case LE:
11504                 case UNLE:
11505                   fputs ("le", file);
11506                   break;
11507                 case UNORDERED:
11508                   fputs ("unord", file);
11509                   break;
11510                 case NE:
11511                 case LTGT:
11512                   fputs ("neq", file);
11513                   break;
11514                 case UNGE:
11515                 case GE:
11516                   fputs ("nlt", file);
11517                   break;
11518                 case UNGT:
11519                 case GT:
11520                   fputs ("nle", file);
11521                   break;
11522                 case ORDERED:
11523                   fputs ("ord", file);
11524                   break;
11525                 default:
11526                   output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
11527                   return;
11528                 }
11529             }
11530           return;
11531         case 'O':
11532 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
11533           if (ASSEMBLER_DIALECT == ASM_ATT)
11534             {
11535               switch (GET_MODE (x))
11536                 {
11537                 case HImode: putc ('w', file); break;
11538                 case SImode:
11539                 case SFmode: putc ('l', file); break;
11540                 case DImode:
11541                 case DFmode: putc ('q', file); break;
11542                 default: gcc_unreachable ();
11543                 }
11544               putc ('.', file);
11545             }
11546 #endif
11547           return;
11548         case 'C':
11549           if (!COMPARISON_P (x))
11550             {
11551               output_operand_lossage ("operand is neither a constant nor a "
11552                                       "condition code, invalid operand code "
11553                                       "'C'");
11554               return;
11555             }
11556           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
11557           return;
11558         case 'F':
11559           if (!COMPARISON_P (x))
11560             {
11561               output_operand_lossage ("operand is neither a constant nor a "
11562                                       "condition code, invalid operand code "
11563                                       "'F'");
11564               return;
11565             }
11566 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
11567           if (ASSEMBLER_DIALECT == ASM_ATT)
11568             putc ('.', file);
11569 #endif
11570           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
11571           return;
11572
11573           /* Like above, but reverse condition */
11574         case 'c':
11575           /* Check to see if argument to %c is really a constant
11576              and not a condition code which needs to be reversed.  */
11577           if (!COMPARISON_P (x))
11578             {
11579               output_operand_lossage ("operand is neither a constant nor a "
11580                                       "condition code, invalid operand "
11581                                       "code 'c'");
11582               return;
11583             }
11584           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
11585           return;
11586         case 'f':
11587           if (!COMPARISON_P (x))
11588             {
11589               output_operand_lossage ("operand is neither a constant nor a "
11590                                       "condition code, invalid operand "
11591                                       "code 'f'");
11592               return;
11593             }
11594 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
11595           if (ASSEMBLER_DIALECT == ASM_ATT)
11596             putc ('.', file);
11597 #endif
11598           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
11599           return;
11600
11601         case 'E':
11602           put_condition_code (GET_CODE (x), CCmode, 0, 0, file);
11603           return;
11604
11605         case 'e':
11606           put_condition_code (GET_CODE (x), CCmode, 1, 0, file);
11607           return;
11608
11609         case 'H':
11610           /* It doesn't actually matter what mode we use here, as we're
11611              only going to use this for printing.  */
11612           x = adjust_address_nv (x, DImode, 8);
11613           break;
11614
11615         case '+':
11616           {
11617             rtx x;
11618
11619             if (!optimize
11620                 || optimize_function_for_size_p (cfun) || !TARGET_BRANCH_PREDICTION_HINTS)
11621               return;
11622
11623             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
11624             if (x)
11625               {
11626                 int pred_val = INTVAL (XEXP (x, 0));
11627
11628                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
11629                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
11630                   {
11631                     int taken = pred_val > REG_BR_PROB_BASE / 2;
11632                     int cputaken = final_forward_branch_p (current_output_insn) == 0;
11633
11634                     /* Emit hints only in the case default branch prediction
11635                        heuristics would fail.  */
11636                     if (taken != cputaken)
11637                       {
11638                         /* We use 3e (DS) prefix for taken branches and
11639                            2e (CS) prefix for not taken branches.  */
11640                         if (taken)
11641                           fputs ("ds ; ", file);
11642                         else
11643                           fputs ("cs ; ", file);
11644                       }
11645                   }
11646               }
11647             return;
11648           }
11649
11650         case 'Y':
11651           switch (GET_CODE (x))
11652             {
11653             case NE:
11654               fputs ("neq", file);
11655               break;
11656             case EQ:
11657               fputs ("eq", file);
11658               break;
11659             case GE:
11660             case GEU:
11661               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
11662               break;
11663             case GT:
11664             case GTU:
11665               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
11666               break;
11667             case LE:
11668             case LEU:
11669               fputs ("le", file);
11670               break;
11671             case LT:
11672             case LTU:
11673               fputs ("lt", file);
11674               break;
11675             case UNORDERED:
11676               fputs ("unord", file);
11677               break;
11678             case ORDERED:
11679               fputs ("ord", file);
11680               break;
11681             case UNEQ:
11682               fputs ("ueq", file);
11683               break;
11684             case UNGE:
11685               fputs ("nlt", file);
11686               break;
11687             case UNGT:
11688               fputs ("nle", file);
11689               break;
11690             case UNLE:
11691               fputs ("ule", file);
11692               break;
11693             case UNLT:
11694               fputs ("ult", file);
11695               break;
11696             case LTGT:
11697               fputs ("une", file);
11698               break;
11699             default:
11700               output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
11701               return;
11702             }
11703           return;
11704
11705         case ';':
11706 #if TARGET_MACHO
11707           fputs (" ; ", file);
11708 #else
11709           putc (' ', file);
11710 #endif
11711           return;
11712
11713         default:
11714             output_operand_lossage ("invalid operand code '%c'", code);
11715         }
11716     }
11717
11718   if (REG_P (x))
11719     print_reg (x, code, file);
11720
11721   else if (MEM_P (x))
11722     {
11723       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
11724       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
11725           && GET_MODE (x) != BLKmode)
11726         {
11727           const char * size;
11728           switch (GET_MODE_SIZE (GET_MODE (x)))
11729             {
11730             case 1: size = "BYTE"; break;
11731             case 2: size = "WORD"; break;
11732             case 4: size = "DWORD"; break;
11733             case 8: size = "QWORD"; break;
11734             case 12: size = "XWORD"; break;
11735             case 16:
11736               if (GET_MODE (x) == XFmode)
11737                 size = "XWORD";
11738               else
11739                 size = "XMMWORD";
11740               break;
11741             default:
11742               gcc_unreachable ();
11743             }
11744
11745           /* Check for explicit size override (codes 'b', 'w' and 'k')  */
11746           if (code == 'b')
11747             size = "BYTE";
11748           else if (code == 'w')
11749             size = "WORD";
11750           else if (code == 'k')
11751             size = "DWORD";
11752
11753           fputs (size, file);
11754           fputs (" PTR ", file);
11755         }
11756
11757       x = XEXP (x, 0);
11758       /* Avoid (%rip) for call operands.  */
11759       if (CONSTANT_ADDRESS_P (x) && code == 'P'
11760           && !CONST_INT_P (x))
11761         output_addr_const (file, x);
11762       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
11763         output_operand_lossage ("invalid constraints for operand");
11764       else
11765         output_address (x);
11766     }
11767
11768   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
11769     {
11770       REAL_VALUE_TYPE r;
11771       long l;
11772
11773       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
11774       REAL_VALUE_TO_TARGET_SINGLE (r, l);
11775
11776       if (ASSEMBLER_DIALECT == ASM_ATT)
11777         putc ('$', file);
11778       fprintf (file, "0x%08lx", (long unsigned int) l);
11779     }
11780
11781   /* These float cases don't actually occur as immediate operands.  */
11782   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
11783     {
11784       char dstr[30];
11785
11786       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
11787       fputs (dstr, file);
11788     }
11789
11790   else if (GET_CODE (x) == CONST_DOUBLE
11791            && GET_MODE (x) == XFmode)
11792     {
11793       char dstr[30];
11794
11795       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
11796       fputs (dstr, file);
11797     }
11798
11799   else
11800     {
11801       /* We have patterns that allow zero sets of memory, for instance.
11802          In 64-bit mode, we should probably support all 8-byte vectors,
11803          since we can in fact encode that into an immediate.  */
11804       if (GET_CODE (x) == CONST_VECTOR)
11805         {
11806           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
11807           x = const0_rtx;
11808         }
11809
11810       if (code != 'P')
11811         {
11812           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
11813             {
11814               if (ASSEMBLER_DIALECT == ASM_ATT)
11815                 putc ('$', file);
11816             }
11817           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
11818                    || GET_CODE (x) == LABEL_REF)
11819             {
11820               if (ASSEMBLER_DIALECT == ASM_ATT)
11821                 putc ('$', file);
11822               else
11823                 fputs ("OFFSET FLAT:", file);
11824             }
11825         }
11826       if (CONST_INT_P (x))
11827         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
11828       else if (flag_pic)
11829         output_pic_addr_const (file, x, code);
11830       else
11831         output_addr_const (file, x);
11832     }
11833 }
11834 \f
11835 /* Print a memory operand whose address is ADDR.  */
11836
11837 void
11838 print_operand_address (FILE *file, rtx addr)
11839 {
11840   struct ix86_address parts;
11841   rtx base, index, disp;
11842   int scale;
11843   int ok = ix86_decompose_address (addr, &parts);
11844
11845   gcc_assert (ok);
11846
11847   base = parts.base;
11848   index = parts.index;
11849   disp = parts.disp;
11850   scale = parts.scale;
11851
11852   switch (parts.seg)
11853     {
11854     case SEG_DEFAULT:
11855       break;
11856     case SEG_FS:
11857     case SEG_GS:
11858       if (ASSEMBLER_DIALECT == ASM_ATT)
11859         putc ('%', file);
11860       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
11861       break;
11862     default:
11863       gcc_unreachable ();
11864     }
11865
11866   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
11867   if (TARGET_64BIT && !base && !index)
11868     {
11869       rtx symbol = disp;
11870
11871       if (GET_CODE (disp) == CONST
11872           && GET_CODE (XEXP (disp, 0)) == PLUS
11873           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11874         symbol = XEXP (XEXP (disp, 0), 0);
11875
11876       if (GET_CODE (symbol) == LABEL_REF
11877           || (GET_CODE (symbol) == SYMBOL_REF
11878               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
11879         base = pc_rtx;
11880     }
11881   if (!base && !index)
11882     {
11883       /* Displacement only requires special attention.  */
11884
11885       if (CONST_INT_P (disp))
11886         {
11887           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
11888             fputs ("ds:", file);
11889           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
11890         }
11891       else if (flag_pic)
11892         output_pic_addr_const (file, disp, 0);
11893       else
11894         output_addr_const (file, disp);
11895     }
11896   else
11897     {
11898       if (ASSEMBLER_DIALECT == ASM_ATT)
11899         {
11900           if (disp)
11901             {
11902               if (flag_pic)
11903                 output_pic_addr_const (file, disp, 0);
11904               else if (GET_CODE (disp) == LABEL_REF)
11905                 output_asm_label (disp);
11906               else
11907                 output_addr_const (file, disp);
11908             }
11909
11910           putc ('(', file);
11911           if (base)
11912             print_reg (base, 0, file);
11913           if (index)
11914             {
11915               putc (',', file);
11916               print_reg (index, 0, file);
11917               if (scale != 1)
11918                 fprintf (file, ",%d", scale);
11919             }
11920           putc (')', file);
11921         }
11922       else
11923         {
11924           rtx offset = NULL_RTX;
11925
11926           if (disp)
11927             {
11928               /* Pull out the offset of a symbol; print any symbol itself.  */
11929               if (GET_CODE (disp) == CONST
11930                   && GET_CODE (XEXP (disp, 0)) == PLUS
11931                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11932                 {
11933                   offset = XEXP (XEXP (disp, 0), 1);
11934                   disp = gen_rtx_CONST (VOIDmode,
11935                                         XEXP (XEXP (disp, 0), 0));
11936                 }
11937
11938               if (flag_pic)
11939                 output_pic_addr_const (file, disp, 0);
11940               else if (GET_CODE (disp) == LABEL_REF)
11941                 output_asm_label (disp);
11942               else if (CONST_INT_P (disp))
11943                 offset = disp;
11944               else
11945                 output_addr_const (file, disp);
11946             }
11947
11948           putc ('[', file);
11949           if (base)
11950             {
11951               print_reg (base, 0, file);
11952               if (offset)
11953                 {
11954                   if (INTVAL (offset) >= 0)
11955                     putc ('+', file);
11956                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11957                 }
11958             }
11959           else if (offset)
11960             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11961           else
11962             putc ('0', file);
11963
11964           if (index)
11965             {
11966               putc ('+', file);
11967               print_reg (index, 0, file);
11968               if (scale != 1)
11969                 fprintf (file, "*%d", scale);
11970             }
11971           putc (']', file);
11972         }
11973     }
11974 }
11975
11976 bool
11977 output_addr_const_extra (FILE *file, rtx x)
11978 {
11979   rtx op;
11980
11981   if (GET_CODE (x) != UNSPEC)
11982     return false;
11983
11984   op = XVECEXP (x, 0, 0);
11985   switch (XINT (x, 1))
11986     {
11987     case UNSPEC_GOTTPOFF:
11988       output_addr_const (file, op);
11989       /* FIXME: This might be @TPOFF in Sun ld.  */
11990       fputs ("@GOTTPOFF", file);
11991       break;
11992     case UNSPEC_TPOFF:
11993       output_addr_const (file, op);
11994       fputs ("@TPOFF", file);
11995       break;
11996     case UNSPEC_NTPOFF:
11997       output_addr_const (file, op);
11998       if (TARGET_64BIT)
11999         fputs ("@TPOFF", file);
12000       else
12001         fputs ("@NTPOFF", file);
12002       break;
12003     case UNSPEC_DTPOFF:
12004       output_addr_const (file, op);
12005       fputs ("@DTPOFF", file);
12006       break;
12007     case UNSPEC_GOTNTPOFF:
12008       output_addr_const (file, op);
12009       if (TARGET_64BIT)
12010         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
12011                "@GOTTPOFF(%rip)" : "@GOTTPOFF[rip]", file);
12012       else
12013         fputs ("@GOTNTPOFF", file);
12014       break;
12015     case UNSPEC_INDNTPOFF:
12016       output_addr_const (file, op);
12017       fputs ("@INDNTPOFF", file);
12018       break;
12019 #if TARGET_MACHO
12020     case UNSPEC_MACHOPIC_OFFSET:
12021       output_addr_const (file, op);
12022       putc ('-', file);
12023       machopic_output_function_base_name (file);
12024       break;
12025 #endif
12026
12027     default:
12028       return false;
12029     }
12030
12031   return true;
12032 }
12033 \f
12034 /* Split one or more DImode RTL references into pairs of SImode
12035    references.  The RTL can be REG, offsettable MEM, integer constant, or
12036    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
12037    split and "num" is its length.  lo_half and hi_half are output arrays
12038    that parallel "operands".  */
12039
12040 void
12041 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
12042 {
12043   while (num--)
12044     {
12045       rtx op = operands[num];
12046
12047       /* simplify_subreg refuse to split volatile memory addresses,
12048          but we still have to handle it.  */
12049       if (MEM_P (op))
12050         {
12051           lo_half[num] = adjust_address (op, SImode, 0);
12052           hi_half[num] = adjust_address (op, SImode, 4);
12053         }
12054       else
12055         {
12056           lo_half[num] = simplify_gen_subreg (SImode, op,
12057                                               GET_MODE (op) == VOIDmode
12058                                               ? DImode : GET_MODE (op), 0);
12059           hi_half[num] = simplify_gen_subreg (SImode, op,
12060                                               GET_MODE (op) == VOIDmode
12061                                               ? DImode : GET_MODE (op), 4);
12062         }
12063     }
12064 }
12065 /* Split one or more TImode RTL references into pairs of DImode
12066    references.  The RTL can be REG, offsettable MEM, integer constant, or
12067    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
12068    split and "num" is its length.  lo_half and hi_half are output arrays
12069    that parallel "operands".  */
12070
12071 void
12072 split_ti (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
12073 {
12074   while (num--)
12075     {
12076       rtx op = operands[num];
12077
12078       /* simplify_subreg refuse to split volatile memory addresses, but we
12079          still have to handle it.  */
12080       if (MEM_P (op))
12081         {
12082           lo_half[num] = adjust_address (op, DImode, 0);
12083           hi_half[num] = adjust_address (op, DImode, 8);
12084         }
12085       else
12086         {
12087           lo_half[num] = simplify_gen_subreg (DImode, op, TImode, 0);
12088           hi_half[num] = simplify_gen_subreg (DImode, op, TImode, 8);
12089         }
12090     }
12091 }
12092 \f
12093 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
12094    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
12095    is the expression of the binary operation.  The output may either be
12096    emitted here, or returned to the caller, like all output_* functions.
12097
12098    There is no guarantee that the operands are the same mode, as they
12099    might be within FLOAT or FLOAT_EXTEND expressions.  */
12100
12101 #ifndef SYSV386_COMPAT
12102 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
12103    wants to fix the assemblers because that causes incompatibility
12104    with gcc.  No-one wants to fix gcc because that causes
12105    incompatibility with assemblers...  You can use the option of
12106    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
12107 #define SYSV386_COMPAT 1
12108 #endif
12109
12110 const char *
12111 output_387_binary_op (rtx insn, rtx *operands)
12112 {
12113   static char buf[40];
12114   const char *p;
12115   const char *ssep;
12116   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
12117
12118 #ifdef ENABLE_CHECKING
12119   /* Even if we do not want to check the inputs, this documents input
12120      constraints.  Which helps in understanding the following code.  */
12121   if (STACK_REG_P (operands[0])
12122       && ((REG_P (operands[1])
12123            && REGNO (operands[0]) == REGNO (operands[1])
12124            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
12125           || (REG_P (operands[2])
12126               && REGNO (operands[0]) == REGNO (operands[2])
12127               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
12128       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
12129     ; /* ok */
12130   else
12131     gcc_assert (is_sse);
12132 #endif
12133
12134   switch (GET_CODE (operands[3]))
12135     {
12136     case PLUS:
12137       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
12138           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
12139         p = "fiadd";
12140       else
12141         p = "fadd";
12142       ssep = "vadd";
12143       break;
12144
12145     case MINUS:
12146       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
12147           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
12148         p = "fisub";
12149       else
12150         p = "fsub";
12151       ssep = "vsub";
12152       break;
12153
12154     case MULT:
12155       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
12156           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
12157         p = "fimul";
12158       else
12159         p = "fmul";
12160       ssep = "vmul";
12161       break;
12162
12163     case DIV:
12164       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
12165           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
12166         p = "fidiv";
12167       else
12168         p = "fdiv";
12169       ssep = "vdiv";
12170       break;
12171
12172     default:
12173       gcc_unreachable ();
12174     }
12175
12176   if (is_sse)
12177    {
12178      if (TARGET_AVX)
12179        {
12180          strcpy (buf, ssep);
12181          if (GET_MODE (operands[0]) == SFmode)
12182            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
12183          else
12184            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
12185        }
12186      else
12187        {
12188          strcpy (buf, ssep + 1);
12189          if (GET_MODE (operands[0]) == SFmode)
12190            strcat (buf, "ss\t{%2, %0|%0, %2}");
12191          else
12192            strcat (buf, "sd\t{%2, %0|%0, %2}");
12193        }
12194       return buf;
12195    }
12196   strcpy (buf, p);
12197
12198   switch (GET_CODE (operands[3]))
12199     {
12200     case MULT:
12201     case PLUS:
12202       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
12203         {
12204           rtx temp = operands[2];
12205           operands[2] = operands[1];
12206           operands[1] = temp;
12207         }
12208
12209       /* know operands[0] == operands[1].  */
12210
12211       if (MEM_P (operands[2]))
12212         {
12213           p = "%Z2\t%2";
12214           break;
12215         }
12216
12217       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
12218         {
12219           if (STACK_TOP_P (operands[0]))
12220             /* How is it that we are storing to a dead operand[2]?
12221                Well, presumably operands[1] is dead too.  We can't
12222                store the result to st(0) as st(0) gets popped on this
12223                instruction.  Instead store to operands[2] (which I
12224                think has to be st(1)).  st(1) will be popped later.
12225                gcc <= 2.8.1 didn't have this check and generated
12226                assembly code that the Unixware assembler rejected.  */
12227             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
12228           else
12229             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
12230           break;
12231         }
12232
12233       if (STACK_TOP_P (operands[0]))
12234         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
12235       else
12236         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
12237       break;
12238
12239     case MINUS:
12240     case DIV:
12241       if (MEM_P (operands[1]))
12242         {
12243           p = "r%Z1\t%1";
12244           break;
12245         }
12246
12247       if (MEM_P (operands[2]))
12248         {
12249           p = "%Z2\t%2";
12250           break;
12251         }
12252
12253       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
12254         {
12255 #if SYSV386_COMPAT
12256           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
12257              derived assemblers, confusingly reverse the direction of
12258              the operation for fsub{r} and fdiv{r} when the
12259              destination register is not st(0).  The Intel assembler
12260              doesn't have this brain damage.  Read !SYSV386_COMPAT to
12261              figure out what the hardware really does.  */
12262           if (STACK_TOP_P (operands[0]))
12263             p = "{p\t%0, %2|rp\t%2, %0}";
12264           else
12265             p = "{rp\t%2, %0|p\t%0, %2}";
12266 #else
12267           if (STACK_TOP_P (operands[0]))
12268             /* As above for fmul/fadd, we can't store to st(0).  */
12269             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
12270           else
12271             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
12272 #endif
12273           break;
12274         }
12275
12276       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
12277         {
12278 #if SYSV386_COMPAT
12279           if (STACK_TOP_P (operands[0]))
12280             p = "{rp\t%0, %1|p\t%1, %0}";
12281           else
12282             p = "{p\t%1, %0|rp\t%0, %1}";
12283 #else
12284           if (STACK_TOP_P (operands[0]))
12285             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
12286           else
12287             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
12288 #endif
12289           break;
12290         }
12291
12292       if (STACK_TOP_P (operands[0]))
12293         {
12294           if (STACK_TOP_P (operands[1]))
12295             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
12296           else
12297             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
12298           break;
12299         }
12300       else if (STACK_TOP_P (operands[1]))
12301         {
12302 #if SYSV386_COMPAT
12303           p = "{\t%1, %0|r\t%0, %1}";
12304 #else
12305           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
12306 #endif
12307         }
12308       else
12309         {
12310 #if SYSV386_COMPAT
12311           p = "{r\t%2, %0|\t%0, %2}";
12312 #else
12313           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
12314 #endif
12315         }
12316       break;
12317
12318     default:
12319       gcc_unreachable ();
12320     }
12321
12322   strcat (buf, p);
12323   return buf;
12324 }
12325
12326 /* Return needed mode for entity in optimize_mode_switching pass.  */
12327
12328 int
12329 ix86_mode_needed (int entity, rtx insn)
12330 {
12331   enum attr_i387_cw mode;
12332
12333   /* The mode UNINITIALIZED is used to store control word after a
12334      function call or ASM pattern.  The mode ANY specify that function
12335      has no requirements on the control word and make no changes in the
12336      bits we are interested in.  */
12337
12338   if (CALL_P (insn)
12339       || (NONJUMP_INSN_P (insn)
12340           && (asm_noperands (PATTERN (insn)) >= 0
12341               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
12342     return I387_CW_UNINITIALIZED;
12343
12344   if (recog_memoized (insn) < 0)
12345     return I387_CW_ANY;
12346
12347   mode = get_attr_i387_cw (insn);
12348
12349   switch (entity)
12350     {
12351     case I387_TRUNC:
12352       if (mode == I387_CW_TRUNC)
12353         return mode;
12354       break;
12355
12356     case I387_FLOOR:
12357       if (mode == I387_CW_FLOOR)
12358         return mode;
12359       break;
12360
12361     case I387_CEIL:
12362       if (mode == I387_CW_CEIL)
12363         return mode;
12364       break;
12365
12366     case I387_MASK_PM:
12367       if (mode == I387_CW_MASK_PM)
12368         return mode;
12369       break;
12370
12371     default:
12372       gcc_unreachable ();
12373     }
12374
12375   return I387_CW_ANY;
12376 }
12377
12378 /* Output code to initialize control word copies used by trunc?f?i and
12379    rounding patterns.  CURRENT_MODE is set to current control word,
12380    while NEW_MODE is set to new control word.  */
12381
12382 void
12383 emit_i387_cw_initialization (int mode)
12384 {
12385   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
12386   rtx new_mode;
12387
12388   enum ix86_stack_slot slot;
12389
12390   rtx reg = gen_reg_rtx (HImode);
12391
12392   emit_insn (gen_x86_fnstcw_1 (stored_mode));
12393   emit_move_insn (reg, copy_rtx (stored_mode));
12394
12395   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
12396       || optimize_function_for_size_p (cfun))
12397     {
12398       switch (mode)
12399         {
12400         case I387_CW_TRUNC:
12401           /* round toward zero (truncate) */
12402           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
12403           slot = SLOT_CW_TRUNC;
12404           break;
12405
12406         case I387_CW_FLOOR:
12407           /* round down toward -oo */
12408           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
12409           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
12410           slot = SLOT_CW_FLOOR;
12411           break;
12412
12413         case I387_CW_CEIL:
12414           /* round up toward +oo */
12415           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
12416           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
12417           slot = SLOT_CW_CEIL;
12418           break;
12419
12420         case I387_CW_MASK_PM:
12421           /* mask precision exception for nearbyint() */
12422           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
12423           slot = SLOT_CW_MASK_PM;
12424           break;
12425
12426         default:
12427           gcc_unreachable ();
12428         }
12429     }
12430   else
12431     {
12432       switch (mode)
12433         {
12434         case I387_CW_TRUNC:
12435           /* round toward zero (truncate) */
12436           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
12437           slot = SLOT_CW_TRUNC;
12438           break;
12439
12440         case I387_CW_FLOOR:
12441           /* round down toward -oo */
12442           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
12443           slot = SLOT_CW_FLOOR;
12444           break;
12445
12446         case I387_CW_CEIL:
12447           /* round up toward +oo */
12448           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
12449           slot = SLOT_CW_CEIL;
12450           break;
12451
12452         case I387_CW_MASK_PM:
12453           /* mask precision exception for nearbyint() */
12454           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
12455           slot = SLOT_CW_MASK_PM;
12456           break;
12457
12458         default:
12459           gcc_unreachable ();
12460         }
12461     }
12462
12463   gcc_assert (slot < MAX_386_STACK_LOCALS);
12464
12465   new_mode = assign_386_stack_local (HImode, slot);
12466   emit_move_insn (new_mode, reg);
12467 }
12468
12469 /* Output code for INSN to convert a float to a signed int.  OPERANDS
12470    are the insn operands.  The output may be [HSD]Imode and the input
12471    operand may be [SDX]Fmode.  */
12472
12473 const char *
12474 output_fix_trunc (rtx insn, rtx *operands, int fisttp)
12475 {
12476   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
12477   int dimode_p = GET_MODE (operands[0]) == DImode;
12478   int round_mode = get_attr_i387_cw (insn);
12479
12480   /* Jump through a hoop or two for DImode, since the hardware has no
12481      non-popping instruction.  We used to do this a different way, but
12482      that was somewhat fragile and broke with post-reload splitters.  */
12483   if ((dimode_p || fisttp) && !stack_top_dies)
12484     output_asm_insn ("fld\t%y1", operands);
12485
12486   gcc_assert (STACK_TOP_P (operands[1]));
12487   gcc_assert (MEM_P (operands[0]));
12488   gcc_assert (GET_MODE (operands[1]) != TFmode);
12489
12490   if (fisttp)
12491       output_asm_insn ("fisttp%Z0\t%0", operands);
12492   else
12493     {
12494       if (round_mode != I387_CW_ANY)
12495         output_asm_insn ("fldcw\t%3", operands);
12496       if (stack_top_dies || dimode_p)
12497         output_asm_insn ("fistp%Z0\t%0", operands);
12498       else
12499         output_asm_insn ("fist%Z0\t%0", operands);
12500       if (round_mode != I387_CW_ANY)
12501         output_asm_insn ("fldcw\t%2", operands);
12502     }
12503
12504   return "";
12505 }
12506
12507 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
12508    have the values zero or one, indicates the ffreep insn's operand
12509    from the OPERANDS array.  */
12510
12511 static const char *
12512 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
12513 {
12514   if (TARGET_USE_FFREEP)
12515 #ifdef HAVE_AS_IX86_FFREEP
12516     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
12517 #else
12518     {
12519       static char retval[32];
12520       int regno = REGNO (operands[opno]);
12521
12522       gcc_assert (FP_REGNO_P (regno));
12523
12524       regno -= FIRST_STACK_REG;
12525
12526       snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno);
12527       return retval;
12528     }
12529 #endif
12530
12531   return opno ? "fstp\t%y1" : "fstp\t%y0";
12532 }
12533
12534
12535 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
12536    should be used.  UNORDERED_P is true when fucom should be used.  */
12537
12538 const char *
12539 output_fp_compare (rtx insn, rtx *operands, int eflags_p, int unordered_p)
12540 {
12541   int stack_top_dies;
12542   rtx cmp_op0, cmp_op1;
12543   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
12544
12545   if (eflags_p)
12546     {
12547       cmp_op0 = operands[0];
12548       cmp_op1 = operands[1];
12549     }
12550   else
12551     {
12552       cmp_op0 = operands[1];
12553       cmp_op1 = operands[2];
12554     }
12555
12556   if (is_sse)
12557     {
12558       static const char ucomiss[] = "vucomiss\t{%1, %0|%0, %1}";
12559       static const char ucomisd[] = "vucomisd\t{%1, %0|%0, %1}";
12560       static const char comiss[] = "vcomiss\t{%1, %0|%0, %1}";
12561       static const char comisd[] = "vcomisd\t{%1, %0|%0, %1}";
12562
12563       if (GET_MODE (operands[0]) == SFmode)
12564         if (unordered_p)
12565           return &ucomiss[TARGET_AVX ? 0 : 1];
12566         else
12567           return &comiss[TARGET_AVX ? 0 : 1];
12568       else
12569         if (unordered_p)
12570           return &ucomisd[TARGET_AVX ? 0 : 1];
12571         else
12572           return &comisd[TARGET_AVX ? 0 : 1];
12573     }
12574
12575   gcc_assert (STACK_TOP_P (cmp_op0));
12576
12577   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
12578
12579   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
12580     {
12581       if (stack_top_dies)
12582         {
12583           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
12584           return output_387_ffreep (operands, 1);
12585         }
12586       else
12587         return "ftst\n\tfnstsw\t%0";
12588     }
12589
12590   if (STACK_REG_P (cmp_op1)
12591       && stack_top_dies
12592       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
12593       && REGNO (cmp_op1) != FIRST_STACK_REG)
12594     {
12595       /* If both the top of the 387 stack dies, and the other operand
12596          is also a stack register that dies, then this must be a
12597          `fcompp' float compare */
12598
12599       if (eflags_p)
12600         {
12601           /* There is no double popping fcomi variant.  Fortunately,
12602              eflags is immune from the fstp's cc clobbering.  */
12603           if (unordered_p)
12604             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
12605           else
12606             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
12607           return output_387_ffreep (operands, 0);
12608         }
12609       else
12610         {
12611           if (unordered_p)
12612             return "fucompp\n\tfnstsw\t%0";
12613           else
12614             return "fcompp\n\tfnstsw\t%0";
12615         }
12616     }
12617   else
12618     {
12619       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
12620
12621       static const char * const alt[16] =
12622       {
12623         "fcom%Z2\t%y2\n\tfnstsw\t%0",
12624         "fcomp%Z2\t%y2\n\tfnstsw\t%0",
12625         "fucom%Z2\t%y2\n\tfnstsw\t%0",
12626         "fucomp%Z2\t%y2\n\tfnstsw\t%0",
12627
12628         "ficom%Z2\t%y2\n\tfnstsw\t%0",
12629         "ficomp%Z2\t%y2\n\tfnstsw\t%0",
12630         NULL,
12631         NULL,
12632
12633         "fcomi\t{%y1, %0|%0, %y1}",
12634         "fcomip\t{%y1, %0|%0, %y1}",
12635         "fucomi\t{%y1, %0|%0, %y1}",
12636         "fucomip\t{%y1, %0|%0, %y1}",
12637
12638         NULL,
12639         NULL,
12640         NULL,
12641         NULL
12642       };
12643
12644       int mask;
12645       const char *ret;
12646
12647       mask  = eflags_p << 3;
12648       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
12649       mask |= unordered_p << 1;
12650       mask |= stack_top_dies;
12651
12652       gcc_assert (mask < 16);
12653       ret = alt[mask];
12654       gcc_assert (ret);
12655
12656       return ret;
12657     }
12658 }
12659
12660 void
12661 ix86_output_addr_vec_elt (FILE *file, int value)
12662 {
12663   const char *directive = ASM_LONG;
12664
12665 #ifdef ASM_QUAD
12666   if (TARGET_64BIT)
12667     directive = ASM_QUAD;
12668 #else
12669   gcc_assert (!TARGET_64BIT);
12670 #endif
12671
12672   fprintf (file, "%s" LPREFIX "%d\n", directive, value);
12673 }
12674
12675 void
12676 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
12677 {
12678   const char *directive = ASM_LONG;
12679
12680 #ifdef ASM_QUAD
12681   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
12682     directive = ASM_QUAD;
12683 #else
12684   gcc_assert (!TARGET_64BIT);
12685 #endif
12686   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
12687   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
12688     fprintf (file, "%s" LPREFIX "%d-" LPREFIX "%d\n",
12689              directive, value, rel);
12690   else if (HAVE_AS_GOTOFF_IN_DATA)
12691     fprintf (file, ASM_LONG LPREFIX "%d@GOTOFF\n", value);
12692 #if TARGET_MACHO
12693   else if (TARGET_MACHO)
12694     {
12695       fprintf (file, ASM_LONG LPREFIX "%d-", value);
12696       machopic_output_function_base_name (file);
12697       putc ('\n', file);
12698     }
12699 #endif
12700   else
12701     asm_fprintf (file, ASM_LONG "%U%s+[.-" LPREFIX "%d]\n",
12702                  GOT_SYMBOL_NAME, value);
12703 }
12704 \f
12705 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
12706    for the target.  */
12707
12708 void
12709 ix86_expand_clear (rtx dest)
12710 {
12711   rtx tmp;
12712
12713   /* We play register width games, which are only valid after reload.  */
12714   gcc_assert (reload_completed);
12715
12716   /* Avoid HImode and its attendant prefix byte.  */
12717   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
12718     dest = gen_rtx_REG (SImode, REGNO (dest));
12719   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
12720
12721   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
12722   if (reload_completed && (!TARGET_USE_MOV0 || optimize_insn_for_speed_p ()))
12723     {
12724       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12725       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
12726     }
12727
12728   emit_insn (tmp);
12729 }
12730
12731 /* X is an unchanging MEM.  If it is a constant pool reference, return
12732    the constant pool rtx, else NULL.  */
12733
12734 rtx
12735 maybe_get_pool_constant (rtx x)
12736 {
12737   x = ix86_delegitimize_address (XEXP (x, 0));
12738
12739   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
12740     return get_pool_constant (x);
12741
12742   return NULL_RTX;
12743 }
12744
12745 void
12746 ix86_expand_move (enum machine_mode mode, rtx operands[])
12747 {
12748   rtx op0, op1;
12749   enum tls_model model;
12750
12751   op0 = operands[0];
12752   op1 = operands[1];
12753
12754   if (GET_CODE (op1) == SYMBOL_REF)
12755     {
12756       model = SYMBOL_REF_TLS_MODEL (op1);
12757       if (model)
12758         {
12759           op1 = legitimize_tls_address (op1, model, true);
12760           op1 = force_operand (op1, op0);
12761           if (op1 == op0)
12762             return;
12763         }
12764       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12765                && SYMBOL_REF_DLLIMPORT_P (op1))
12766         op1 = legitimize_dllimport_symbol (op1, false);
12767     }
12768   else if (GET_CODE (op1) == CONST
12769            && GET_CODE (XEXP (op1, 0)) == PLUS
12770            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
12771     {
12772       rtx addend = XEXP (XEXP (op1, 0), 1);
12773       rtx symbol = XEXP (XEXP (op1, 0), 0);
12774       rtx tmp = NULL;
12775
12776       model = SYMBOL_REF_TLS_MODEL (symbol);
12777       if (model)
12778         tmp = legitimize_tls_address (symbol, model, true);
12779       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12780                && SYMBOL_REF_DLLIMPORT_P (symbol))
12781         tmp = legitimize_dllimport_symbol (symbol, true);
12782
12783       if (tmp)
12784         {
12785           tmp = force_operand (tmp, NULL);
12786           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
12787                                      op0, 1, OPTAB_DIRECT);
12788           if (tmp == op0)
12789             return;
12790         }
12791     }
12792
12793   if (flag_pic && mode == Pmode && symbolic_operand (op1, Pmode))
12794     {
12795       if (TARGET_MACHO && !TARGET_64BIT)
12796         {
12797 #if TARGET_MACHO
12798           if (MACHOPIC_PURE)
12799             {
12800               rtx temp = ((reload_in_progress
12801                            || ((op0 && REG_P (op0))
12802                                && mode == Pmode))
12803                           ? op0 : gen_reg_rtx (Pmode));
12804               op1 = machopic_indirect_data_reference (op1, temp);
12805               op1 = machopic_legitimize_pic_address (op1, mode,
12806                                                      temp == op1 ? 0 : temp);
12807             }
12808           else if (MACHOPIC_INDIRECT)
12809             op1 = machopic_indirect_data_reference (op1, 0);
12810           if (op0 == op1)
12811             return;
12812 #endif
12813         }
12814       else
12815         {
12816           if (MEM_P (op0))
12817             op1 = force_reg (Pmode, op1);
12818           else if (!TARGET_64BIT || !x86_64_movabs_operand (op1, Pmode))
12819             {
12820               rtx reg = can_create_pseudo_p () ? NULL_RTX : op0;
12821               op1 = legitimize_pic_address (op1, reg);
12822               if (op0 == op1)
12823                 return;
12824             }
12825         }
12826     }
12827   else
12828     {
12829       if (MEM_P (op0)
12830           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
12831               || !push_operand (op0, mode))
12832           && MEM_P (op1))
12833         op1 = force_reg (mode, op1);
12834
12835       if (push_operand (op0, mode)
12836           && ! general_no_elim_operand (op1, mode))
12837         op1 = copy_to_mode_reg (mode, op1);
12838
12839       /* Force large constants in 64bit compilation into register
12840          to get them CSEed.  */
12841       if (can_create_pseudo_p ()
12842           && (mode == DImode) && TARGET_64BIT
12843           && immediate_operand (op1, mode)
12844           && !x86_64_zext_immediate_operand (op1, VOIDmode)
12845           && !register_operand (op0, mode)
12846           && optimize)
12847         op1 = copy_to_mode_reg (mode, op1);
12848
12849       if (can_create_pseudo_p ()
12850           && FLOAT_MODE_P (mode)
12851           && GET_CODE (op1) == CONST_DOUBLE)
12852         {
12853           /* If we are loading a floating point constant to a register,
12854              force the value to memory now, since we'll get better code
12855              out the back end.  */
12856
12857           op1 = validize_mem (force_const_mem (mode, op1));
12858           if (!register_operand (op0, mode))
12859             {
12860               rtx temp = gen_reg_rtx (mode);
12861               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
12862               emit_move_insn (op0, temp);
12863               return;
12864             }
12865         }
12866     }
12867
12868   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12869 }
12870
12871 void
12872 ix86_expand_vector_move (enum machine_mode mode, rtx operands[])
12873 {
12874   rtx op0 = operands[0], op1 = operands[1];
12875   unsigned int align = GET_MODE_ALIGNMENT (mode);
12876
12877   /* Force constants other than zero into memory.  We do not know how
12878      the instructions used to build constants modify the upper 64 bits
12879      of the register, once we have that information we may be able
12880      to handle some of them more efficiently.  */
12881   if (can_create_pseudo_p ()
12882       && register_operand (op0, mode)
12883       && (CONSTANT_P (op1)
12884           || (GET_CODE (op1) == SUBREG
12885               && CONSTANT_P (SUBREG_REG (op1))))
12886       && !standard_sse_constant_p (op1))
12887     op1 = validize_mem (force_const_mem (mode, op1));
12888
12889   /* We need to check memory alignment for SSE mode since attribute
12890      can make operands unaligned.  */
12891   if (can_create_pseudo_p ()
12892       && SSE_REG_MODE_P (mode)
12893       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
12894           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
12895     {
12896       rtx tmp[2];
12897
12898       /* ix86_expand_vector_move_misalign() does not like constants ... */
12899       if (CONSTANT_P (op1)
12900           || (GET_CODE (op1) == SUBREG
12901               && CONSTANT_P (SUBREG_REG (op1))))
12902         op1 = validize_mem (force_const_mem (mode, op1));
12903
12904       /* ... nor both arguments in memory.  */
12905       if (!register_operand (op0, mode)
12906           && !register_operand (op1, mode))
12907         op1 = force_reg (mode, op1);
12908
12909       tmp[0] = op0; tmp[1] = op1;
12910       ix86_expand_vector_move_misalign (mode, tmp);
12911       return;
12912     }
12913
12914   /* Make operand1 a register if it isn't already.  */
12915   if (can_create_pseudo_p ()
12916       && !register_operand (op0, mode)
12917       && !register_operand (op1, mode))
12918     {
12919       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
12920       return;
12921     }
12922
12923   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12924 }
12925
12926 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
12927    straight to ix86_expand_vector_move.  */
12928 /* Code generation for scalar reg-reg moves of single and double precision data:
12929      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
12930        movaps reg, reg
12931      else
12932        movss reg, reg
12933      if (x86_sse_partial_reg_dependency == true)
12934        movapd reg, reg
12935      else
12936        movsd reg, reg
12937
12938    Code generation for scalar loads of double precision data:
12939      if (x86_sse_split_regs == true)
12940        movlpd mem, reg      (gas syntax)
12941      else
12942        movsd mem, reg
12943
12944    Code generation for unaligned packed loads of single precision data
12945    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
12946      if (x86_sse_unaligned_move_optimal)
12947        movups mem, reg
12948
12949      if (x86_sse_partial_reg_dependency == true)
12950        {
12951          xorps  reg, reg
12952          movlps mem, reg
12953          movhps mem+8, reg
12954        }
12955      else
12956        {
12957          movlps mem, reg
12958          movhps mem+8, reg
12959        }
12960
12961    Code generation for unaligned packed loads of double precision data
12962    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
12963      if (x86_sse_unaligned_move_optimal)
12964        movupd mem, reg
12965
12966      if (x86_sse_split_regs == true)
12967        {
12968          movlpd mem, reg
12969          movhpd mem+8, reg
12970        }
12971      else
12972        {
12973          movsd  mem, reg
12974          movhpd mem+8, reg
12975        }
12976  */
12977
12978 void
12979 ix86_expand_vector_move_misalign (enum machine_mode mode, rtx operands[])
12980 {
12981   rtx op0, op1, m;
12982
12983   op0 = operands[0];
12984   op1 = operands[1];
12985
12986   if (TARGET_AVX)
12987     {
12988       switch (GET_MODE_CLASS (mode))
12989         {
12990         case MODE_VECTOR_INT:
12991         case MODE_INT:
12992           switch (GET_MODE_SIZE (mode))
12993             {
12994             case 16:
12995               op0 = gen_lowpart (V16QImode, op0);
12996               op1 = gen_lowpart (V16QImode, op1);
12997               emit_insn (gen_avx_movdqu (op0, op1));
12998               break;
12999             case 32:
13000               op0 = gen_lowpart (V32QImode, op0);
13001               op1 = gen_lowpart (V32QImode, op1);
13002               emit_insn (gen_avx_movdqu256 (op0, op1));
13003               break;
13004             default:
13005               gcc_unreachable ();
13006             }
13007           break;
13008         case MODE_VECTOR_FLOAT:
13009           op0 = gen_lowpart (mode, op0);
13010           op1 = gen_lowpart (mode, op1);
13011
13012           switch (mode)
13013             { 
13014             case V4SFmode:
13015               emit_insn (gen_avx_movups (op0, op1));
13016               break;
13017             case V8SFmode:
13018               emit_insn (gen_avx_movups256 (op0, op1));
13019               break;
13020             case V2DFmode:
13021               emit_insn (gen_avx_movupd (op0, op1));
13022               break;
13023             case V4DFmode:
13024               emit_insn (gen_avx_movupd256 (op0, op1));
13025               break;
13026             default:
13027               gcc_unreachable ();
13028             }
13029           break;
13030
13031         default:
13032           gcc_unreachable ();
13033         }
13034
13035       return;
13036     }
13037
13038   if (MEM_P (op1))
13039     {
13040       /* If we're optimizing for size, movups is the smallest.  */
13041       if (optimize_insn_for_size_p ())
13042         {
13043           op0 = gen_lowpart (V4SFmode, op0);
13044           op1 = gen_lowpart (V4SFmode, op1);
13045           emit_insn (gen_sse_movups (op0, op1));
13046           return;
13047         }
13048
13049       /* ??? If we have typed data, then it would appear that using
13050          movdqu is the only way to get unaligned data loaded with
13051          integer type.  */
13052       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
13053         {
13054           op0 = gen_lowpart (V16QImode, op0);
13055           op1 = gen_lowpart (V16QImode, op1);
13056           emit_insn (gen_sse2_movdqu (op0, op1));
13057           return;
13058         }
13059
13060       if (TARGET_SSE2 && mode == V2DFmode)
13061         {
13062           rtx zero;
13063
13064           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
13065             {
13066               op0 = gen_lowpart (V2DFmode, op0);
13067               op1 = gen_lowpart (V2DFmode, op1);
13068               emit_insn (gen_sse2_movupd (op0, op1));
13069               return;
13070             }
13071
13072           /* When SSE registers are split into halves, we can avoid
13073              writing to the top half twice.  */
13074           if (TARGET_SSE_SPLIT_REGS)
13075             {
13076               emit_clobber (op0);
13077               zero = op0;
13078             }
13079           else
13080             {
13081               /* ??? Not sure about the best option for the Intel chips.
13082                  The following would seem to satisfy; the register is
13083                  entirely cleared, breaking the dependency chain.  We
13084                  then store to the upper half, with a dependency depth
13085                  of one.  A rumor has it that Intel recommends two movsd
13086                  followed by an unpacklpd, but this is unconfirmed.  And
13087                  given that the dependency depth of the unpacklpd would
13088                  still be one, I'm not sure why this would be better.  */
13089               zero = CONST0_RTX (V2DFmode);
13090             }
13091
13092           m = adjust_address (op1, DFmode, 0);
13093           emit_insn (gen_sse2_loadlpd (op0, zero, m));
13094           m = adjust_address (op1, DFmode, 8);
13095           emit_insn (gen_sse2_loadhpd (op0, op0, m));
13096         }
13097       else
13098         {
13099           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
13100             {
13101               op0 = gen_lowpart (V4SFmode, op0);
13102               op1 = gen_lowpart (V4SFmode, op1);
13103               emit_insn (gen_sse_movups (op0, op1));
13104               return;
13105             }
13106
13107           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
13108             emit_move_insn (op0, CONST0_RTX (mode));
13109           else
13110             emit_clobber (op0);
13111
13112           if (mode != V4SFmode)
13113             op0 = gen_lowpart (V4SFmode, op0);
13114           m = adjust_address (op1, V2SFmode, 0);
13115           emit_insn (gen_sse_loadlps (op0, op0, m));
13116           m = adjust_address (op1, V2SFmode, 8);
13117           emit_insn (gen_sse_loadhps (op0, op0, m));
13118         }
13119     }
13120   else if (MEM_P (op0))
13121     {
13122       /* If we're optimizing for size, movups is the smallest.  */
13123       if (optimize_insn_for_size_p ())
13124         {
13125           op0 = gen_lowpart (V4SFmode, op0);
13126           op1 = gen_lowpart (V4SFmode, op1);
13127           emit_insn (gen_sse_movups (op0, op1));
13128           return;
13129         }
13130
13131       /* ??? Similar to above, only less clear because of quote
13132          typeless stores unquote.  */
13133       if (TARGET_SSE2 && !TARGET_SSE_TYPELESS_STORES
13134           && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
13135         {
13136           op0 = gen_lowpart (V16QImode, op0);
13137           op1 = gen_lowpart (V16QImode, op1);
13138           emit_insn (gen_sse2_movdqu (op0, op1));
13139           return;
13140         }
13141
13142       if (TARGET_SSE2 && mode == V2DFmode)
13143         {
13144           m = adjust_address (op0, DFmode, 0);
13145           emit_insn (gen_sse2_storelpd (m, op1));
13146           m = adjust_address (op0, DFmode, 8);
13147           emit_insn (gen_sse2_storehpd (m, op1));
13148         }
13149       else
13150         {
13151           if (mode != V4SFmode)
13152             op1 = gen_lowpart (V4SFmode, op1);
13153           m = adjust_address (op0, V2SFmode, 0);
13154           emit_insn (gen_sse_storelps (m, op1));
13155           m = adjust_address (op0, V2SFmode, 8);
13156           emit_insn (gen_sse_storehps (m, op1));
13157         }
13158     }
13159   else
13160     gcc_unreachable ();
13161 }
13162
13163 /* Expand a push in MODE.  This is some mode for which we do not support
13164    proper push instructions, at least from the registers that we expect
13165    the value to live in.  */
13166
13167 void
13168 ix86_expand_push (enum machine_mode mode, rtx x)
13169 {
13170   rtx tmp;
13171
13172   tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
13173                              GEN_INT (-GET_MODE_SIZE (mode)),
13174                              stack_pointer_rtx, 1, OPTAB_DIRECT);
13175   if (tmp != stack_pointer_rtx)
13176     emit_move_insn (stack_pointer_rtx, tmp);
13177
13178   tmp = gen_rtx_MEM (mode, stack_pointer_rtx);
13179
13180   /* When we push an operand onto stack, it has to be aligned at least
13181      at the function argument boundary.  However since we don't have
13182      the argument type, we can't determine the actual argument
13183      boundary.  */
13184   emit_move_insn (tmp, x);
13185 }
13186
13187 /* Helper function of ix86_fixup_binary_operands to canonicalize
13188    operand order.  Returns true if the operands should be swapped.  */
13189
13190 static bool
13191 ix86_swap_binary_operands_p (enum rtx_code code, enum machine_mode mode,
13192                              rtx operands[])
13193 {
13194   rtx dst = operands[0];
13195   rtx src1 = operands[1];
13196   rtx src2 = operands[2];
13197
13198   /* If the operation is not commutative, we can't do anything.  */
13199   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
13200     return false;
13201
13202   /* Highest priority is that src1 should match dst.  */
13203   if (rtx_equal_p (dst, src1))
13204     return false;
13205   if (rtx_equal_p (dst, src2))
13206     return true;
13207
13208   /* Next highest priority is that immediate constants come second.  */
13209   if (immediate_operand (src2, mode))
13210     return false;
13211   if (immediate_operand (src1, mode))
13212     return true;
13213
13214   /* Lowest priority is that memory references should come second.  */
13215   if (MEM_P (src2))
13216     return false;
13217   if (MEM_P (src1))
13218     return true;
13219
13220   return false;
13221 }
13222
13223
13224 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
13225    destination to use for the operation.  If different from the true
13226    destination in operands[0], a copy operation will be required.  */
13227
13228 rtx
13229 ix86_fixup_binary_operands (enum rtx_code code, enum machine_mode mode,
13230                             rtx operands[])
13231 {
13232   rtx dst = operands[0];
13233   rtx src1 = operands[1];
13234   rtx src2 = operands[2];
13235
13236   /* Canonicalize operand order.  */
13237   if (ix86_swap_binary_operands_p (code, mode, operands))
13238     {
13239       rtx temp;
13240
13241       /* It is invalid to swap operands of different modes.  */
13242       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
13243
13244       temp = src1;
13245       src1 = src2;
13246       src2 = temp;
13247     }
13248
13249   /* Both source operands cannot be in memory.  */
13250   if (MEM_P (src1) && MEM_P (src2))
13251     {
13252       /* Optimization: Only read from memory once.  */
13253       if (rtx_equal_p (src1, src2))
13254         {
13255           src2 = force_reg (mode, src2);
13256           src1 = src2;
13257         }
13258       else
13259         src2 = force_reg (mode, src2);
13260     }
13261
13262   /* If the destination is memory, and we do not have matching source
13263      operands, do things in registers.  */
13264   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
13265     dst = gen_reg_rtx (mode);
13266
13267   /* Source 1 cannot be a constant.  */
13268   if (CONSTANT_P (src1))
13269     src1 = force_reg (mode, src1);
13270
13271   /* Source 1 cannot be a non-matching memory.  */
13272   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
13273     src1 = force_reg (mode, src1);
13274
13275   operands[1] = src1;
13276   operands[2] = src2;
13277   return dst;
13278 }
13279
13280 /* Similarly, but assume that the destination has already been
13281    set up properly.  */
13282
13283 void
13284 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
13285                                     enum machine_mode mode, rtx operands[])
13286 {
13287   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
13288   gcc_assert (dst == operands[0]);
13289 }
13290
13291 /* Attempt to expand a binary operator.  Make the expansion closer to the
13292    actual machine, then just general_operand, which will allow 3 separate
13293    memory references (one output, two input) in a single insn.  */
13294
13295 void
13296 ix86_expand_binary_operator (enum rtx_code code, enum machine_mode mode,
13297                              rtx operands[])
13298 {
13299   rtx src1, src2, dst, op, clob;
13300
13301   dst = ix86_fixup_binary_operands (code, mode, operands);
13302   src1 = operands[1];
13303   src2 = operands[2];
13304
13305  /* Emit the instruction.  */
13306
13307   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
13308   if (reload_in_progress)
13309     {
13310       /* Reload doesn't know about the flags register, and doesn't know that
13311          it doesn't want to clobber it.  We can only do this with PLUS.  */
13312       gcc_assert (code == PLUS);
13313       emit_insn (op);
13314     }
13315   else
13316     {
13317       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
13318       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
13319     }
13320
13321   /* Fix up the destination if needed.  */
13322   if (dst != operands[0])
13323     emit_move_insn (operands[0], dst);
13324 }
13325
13326 /* Return TRUE or FALSE depending on whether the binary operator meets the
13327    appropriate constraints.  */
13328
13329 int
13330 ix86_binary_operator_ok (enum rtx_code code, enum machine_mode mode,
13331                          rtx operands[3])
13332 {
13333   rtx dst = operands[0];
13334   rtx src1 = operands[1];
13335   rtx src2 = operands[2];
13336
13337   /* Both source operands cannot be in memory.  */
13338   if (MEM_P (src1) && MEM_P (src2))
13339     return 0;
13340
13341   /* Canonicalize operand order for commutative operators.  */
13342   if (ix86_swap_binary_operands_p (code, mode, operands))
13343     {
13344       rtx temp = src1;
13345       src1 = src2;
13346       src2 = temp;
13347     }
13348
13349   /* If the destination is memory, we must have a matching source operand.  */
13350   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
13351       return 0;
13352
13353   /* Source 1 cannot be a constant.  */
13354   if (CONSTANT_P (src1))
13355     return 0;
13356
13357   /* Source 1 cannot be a non-matching memory.  */
13358   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
13359     return 0;
13360
13361   return 1;
13362 }
13363
13364 /* Attempt to expand a unary operator.  Make the expansion closer to the
13365    actual machine, then just general_operand, which will allow 2 separate
13366    memory references (one output, one input) in a single insn.  */
13367
13368 void
13369 ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode,
13370                             rtx operands[])
13371 {
13372   int matching_memory;
13373   rtx src, dst, op, clob;
13374
13375   dst = operands[0];
13376   src = operands[1];
13377
13378   /* If the destination is memory, and we do not have matching source
13379      operands, do things in registers.  */
13380   matching_memory = 0;
13381   if (MEM_P (dst))
13382     {
13383       if (rtx_equal_p (dst, src))
13384         matching_memory = 1;
13385       else
13386         dst = gen_reg_rtx (mode);
13387     }
13388
13389   /* When source operand is memory, destination must match.  */
13390   if (MEM_P (src) && !matching_memory)
13391     src = force_reg (mode, src);
13392
13393   /* Emit the instruction.  */
13394
13395   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
13396   if (reload_in_progress || code == NOT)
13397     {
13398       /* Reload doesn't know about the flags register, and doesn't know that
13399          it doesn't want to clobber it.  */
13400       gcc_assert (code == NOT);
13401       emit_insn (op);
13402     }
13403   else
13404     {
13405       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
13406       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
13407     }
13408
13409   /* Fix up the destination if needed.  */
13410   if (dst != operands[0])
13411     emit_move_insn (operands[0], dst);
13412 }
13413
13414 #define LEA_SEARCH_THRESHOLD 12
13415
13416 /* Search backward for non-agu definition of register number REGNO1
13417    or register number REGNO2 in INSN's basic block until 
13418    1. Pass LEA_SEARCH_THRESHOLD instructions, or
13419    2. Reach BB boundary, or
13420    3. Reach agu definition.
13421    Returns the distance between the non-agu definition point and INSN.
13422    If no definition point, returns -1.  */
13423
13424 static int
13425 distance_non_agu_define (unsigned int regno1, unsigned int regno2,
13426                          rtx insn)
13427 {
13428   basic_block bb = BLOCK_FOR_INSN (insn);
13429   int distance = 0;
13430   df_ref *def_rec;
13431   enum attr_type insn_type;
13432
13433   if (insn != BB_HEAD (bb))
13434     {
13435       rtx prev = PREV_INSN (insn);
13436       while (prev && distance < LEA_SEARCH_THRESHOLD)
13437         {
13438           if (INSN_P (prev))
13439             {
13440               distance++;
13441               for (def_rec = DF_INSN_DEFS (prev); *def_rec; def_rec++)
13442                 if (DF_REF_TYPE (*def_rec) == DF_REF_REG_DEF
13443                     && !DF_REF_IS_ARTIFICIAL (*def_rec)
13444                     && (regno1 == DF_REF_REGNO (*def_rec)
13445                         || regno2 == DF_REF_REGNO (*def_rec)))
13446                   {
13447                     insn_type = get_attr_type (prev);
13448                     if (insn_type != TYPE_LEA)
13449                       goto done;
13450                   }
13451             }
13452           if (prev == BB_HEAD (bb))
13453             break;
13454           prev = PREV_INSN (prev);
13455         }
13456     }
13457   
13458   if (distance < LEA_SEARCH_THRESHOLD)
13459     {
13460       edge e;
13461       edge_iterator ei;
13462       bool simple_loop = false;
13463   
13464       FOR_EACH_EDGE (e, ei, bb->preds)
13465         if (e->src == bb)
13466           {
13467             simple_loop = true;
13468             break;
13469           }
13470   
13471       if (simple_loop)
13472         {
13473           rtx prev = BB_END (bb);
13474           while (prev
13475                  && prev != insn
13476                  && distance < LEA_SEARCH_THRESHOLD)
13477             {
13478               if (INSN_P (prev))
13479                 {
13480                   distance++;
13481                   for (def_rec = DF_INSN_DEFS (prev); *def_rec; def_rec++)
13482                     if (DF_REF_TYPE (*def_rec) == DF_REF_REG_DEF
13483                         && !DF_REF_IS_ARTIFICIAL (*def_rec)
13484                         && (regno1 == DF_REF_REGNO (*def_rec)
13485                             || regno2 == DF_REF_REGNO (*def_rec)))
13486                       {
13487                         insn_type = get_attr_type (prev);
13488                         if (insn_type != TYPE_LEA)
13489                           goto done;
13490                       }
13491                 }
13492               prev = PREV_INSN (prev);
13493             }
13494         }
13495     }
13496
13497   distance = -1;
13498
13499 done:
13500   /* get_attr_type may modify recog data.  We want to make sure
13501      that recog data is valid for instruction INSN, on which
13502      distance_non_agu_define is called.  INSN is unchanged here.  */
13503   extract_insn_cached (insn);
13504   return distance;
13505 }
13506
13507 /* Return the distance between INSN and the next insn that uses 
13508    register number REGNO0 in memory address.  Return -1 if no such
13509    a use is found within LEA_SEARCH_THRESHOLD or REGNO0 is set.  */
13510
13511 static int
13512 distance_agu_use (unsigned int regno0, rtx insn)
13513 {
13514   basic_block bb = BLOCK_FOR_INSN (insn);
13515   int distance = 0;
13516   df_ref *def_rec;
13517   df_ref *use_rec;
13518
13519   if (insn != BB_END (bb))
13520     {
13521       rtx next = NEXT_INSN (insn);
13522       while (next && distance < LEA_SEARCH_THRESHOLD)
13523         {
13524           if (INSN_P (next))
13525             {
13526               distance++;
13527
13528               for (use_rec = DF_INSN_USES (next); *use_rec; use_rec++)
13529                 if ((DF_REF_TYPE (*use_rec) == DF_REF_REG_MEM_LOAD
13530                      || DF_REF_TYPE (*use_rec) == DF_REF_REG_MEM_STORE)
13531                     && regno0 == DF_REF_REGNO (*use_rec))
13532                   {
13533                     /* Return DISTANCE if OP0 is used in memory
13534                        address in NEXT.  */
13535                     return distance;
13536                   }
13537
13538               for (def_rec = DF_INSN_DEFS (next); *def_rec; def_rec++)
13539                 if (DF_REF_TYPE (*def_rec) == DF_REF_REG_DEF
13540                     && !DF_REF_IS_ARTIFICIAL (*def_rec)
13541                     && regno0 == DF_REF_REGNO (*def_rec))
13542                   {
13543                     /* Return -1 if OP0 is set in NEXT.  */
13544                     return -1;
13545                   }
13546             }
13547           if (next == BB_END (bb))
13548             break;
13549           next = NEXT_INSN (next);
13550         }
13551     }
13552
13553   if (distance < LEA_SEARCH_THRESHOLD)
13554     {
13555       edge e;
13556       edge_iterator ei;
13557       bool simple_loop = false;
13558   
13559       FOR_EACH_EDGE (e, ei, bb->succs)
13560         if (e->dest == bb)
13561           {
13562             simple_loop = true;
13563             break;
13564           }
13565   
13566       if (simple_loop)
13567         {
13568           rtx next = BB_HEAD (bb);
13569           while (next
13570                  && next != insn
13571                  && distance < LEA_SEARCH_THRESHOLD)
13572             {
13573               if (INSN_P (next))
13574                 {
13575                   distance++;
13576
13577                   for (use_rec = DF_INSN_USES (next); *use_rec; use_rec++)
13578                     if ((DF_REF_TYPE (*use_rec) == DF_REF_REG_MEM_LOAD
13579                          || DF_REF_TYPE (*use_rec) == DF_REF_REG_MEM_STORE)
13580                         && regno0 == DF_REF_REGNO (*use_rec))
13581                       {
13582                         /* Return DISTANCE if OP0 is used in memory
13583                            address in NEXT.  */
13584                         return distance;
13585                       }
13586
13587                   for (def_rec = DF_INSN_DEFS (next); *def_rec; def_rec++)
13588                     if (DF_REF_TYPE (*def_rec) == DF_REF_REG_DEF
13589                         && !DF_REF_IS_ARTIFICIAL (*def_rec)
13590                         && regno0 == DF_REF_REGNO (*def_rec))
13591                       {
13592                         /* Return -1 if OP0 is set in NEXT.  */
13593                         return -1;
13594                       }
13595
13596                 }
13597               next = NEXT_INSN (next);
13598             }
13599         }
13600     }  
13601
13602   return -1;
13603 }
13604
13605 /* Define this macro to tune LEA priority vs ADD, it take effect when
13606    there is a dilemma of choicing LEA or ADD
13607    Negative value: ADD is more preferred than LEA
13608    Zero: Netrual
13609    Positive value: LEA is more preferred than ADD*/
13610 #define IX86_LEA_PRIORITY 2
13611
13612 /* Return true if it is ok to optimize an ADD operation to LEA
13613    operation to avoid flag register consumation.  For the processors
13614    like ATOM, if the destination register of LEA holds an actual
13615    address which will be used soon, LEA is better and otherwise ADD
13616    is better.  */
13617
13618 bool
13619 ix86_lea_for_add_ok (enum rtx_code code ATTRIBUTE_UNUSED,
13620                      rtx insn, rtx operands[])
13621 {
13622   unsigned int regno0 = true_regnum (operands[0]);
13623   unsigned int regno1 = true_regnum (operands[1]);
13624   unsigned int regno2;
13625
13626   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
13627     return regno0 != regno1;
13628
13629   regno2 = true_regnum (operands[2]);
13630
13631   /* If a = b + c, (a!=b && a!=c), must use lea form. */
13632   if (regno0 != regno1 && regno0 != regno2)
13633     return true;
13634   else    
13635     {
13636       int dist_define, dist_use;
13637       dist_define = distance_non_agu_define (regno1, regno2, insn);
13638       if (dist_define <= 0)
13639         return true;
13640
13641       /* If this insn has both backward non-agu dependence and forward
13642          agu dependence, the one with short distance take effect. */
13643       dist_use = distance_agu_use (regno0, insn);
13644       if (dist_use <= 0
13645           || (dist_define + IX86_LEA_PRIORITY) < dist_use)
13646         return false;
13647
13648       return true;
13649     }
13650 }
13651
13652 /* Return true if destination reg of SET_BODY is shift count of
13653    USE_BODY.  */
13654
13655 static bool
13656 ix86_dep_by_shift_count_body (const_rtx set_body, const_rtx use_body)
13657 {
13658   rtx set_dest;
13659   rtx shift_rtx;
13660   int i;
13661
13662   /* Retrieve destination of SET_BODY.  */
13663   switch (GET_CODE (set_body))
13664     {
13665     case SET:
13666       set_dest = SET_DEST (set_body);
13667       if (!set_dest || !REG_P (set_dest))
13668         return false;
13669       break;
13670     case PARALLEL:
13671       for (i = XVECLEN (set_body, 0) - 1; i >= 0; i--)
13672         if (ix86_dep_by_shift_count_body (XVECEXP (set_body, 0, i),
13673                                           use_body))
13674           return true;
13675     default:
13676       return false;
13677       break;
13678     }
13679
13680   /* Retrieve shift count of USE_BODY.  */
13681   switch (GET_CODE (use_body))
13682     {
13683     case SET:
13684       shift_rtx = XEXP (use_body, 1);
13685       break;
13686     case PARALLEL:
13687       for (i = XVECLEN (use_body, 0) - 1; i >= 0; i--)
13688         if (ix86_dep_by_shift_count_body (set_body,
13689                                           XVECEXP (use_body, 0, i)))
13690           return true;
13691     default:
13692       return false;
13693       break;
13694     }
13695
13696   if (shift_rtx 
13697       && (GET_CODE (shift_rtx) == ASHIFT
13698           || GET_CODE (shift_rtx) == LSHIFTRT
13699           || GET_CODE (shift_rtx) == ASHIFTRT
13700           || GET_CODE (shift_rtx) == ROTATE
13701           || GET_CODE (shift_rtx) == ROTATERT))
13702     {
13703       rtx shift_count = XEXP (shift_rtx, 1);
13704
13705       /* Return true if shift count is dest of SET_BODY.  */
13706       if (REG_P (shift_count)
13707           && true_regnum (set_dest) == true_regnum (shift_count))
13708         return true;
13709     }
13710
13711   return false;
13712 }
13713
13714 /* Return true if destination reg of SET_INSN is shift count of
13715    USE_INSN.  */
13716
13717 bool
13718 ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn)
13719 {
13720   return ix86_dep_by_shift_count_body (PATTERN (set_insn),
13721                                        PATTERN (use_insn));
13722 }
13723
13724 /* Return TRUE or FALSE depending on whether the unary operator meets the
13725    appropriate constraints.  */
13726
13727 int
13728 ix86_unary_operator_ok (enum rtx_code code ATTRIBUTE_UNUSED,
13729                         enum machine_mode mode ATTRIBUTE_UNUSED,
13730                         rtx operands[2] ATTRIBUTE_UNUSED)
13731 {
13732   /* If one of operands is memory, source and destination must match.  */
13733   if ((MEM_P (operands[0])
13734        || MEM_P (operands[1]))
13735       && ! rtx_equal_p (operands[0], operands[1]))
13736     return FALSE;
13737   return TRUE;
13738 }
13739
13740 /* Post-reload splitter for converting an SF or DFmode value in an
13741    SSE register into an unsigned SImode.  */
13742
13743 void
13744 ix86_split_convert_uns_si_sse (rtx operands[])
13745 {
13746   enum machine_mode vecmode;
13747   rtx value, large, zero_or_two31, input, two31, x;
13748
13749   large = operands[1];
13750   zero_or_two31 = operands[2];
13751   input = operands[3];
13752   two31 = operands[4];
13753   vecmode = GET_MODE (large);
13754   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
13755
13756   /* Load up the value into the low element.  We must ensure that the other
13757      elements are valid floats -- zero is the easiest such value.  */
13758   if (MEM_P (input))
13759     {
13760       if (vecmode == V4SFmode)
13761         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
13762       else
13763         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
13764     }
13765   else
13766     {
13767       input = gen_rtx_REG (vecmode, REGNO (input));
13768       emit_move_insn (value, CONST0_RTX (vecmode));
13769       if (vecmode == V4SFmode)
13770         emit_insn (gen_sse_movss (value, value, input));
13771       else
13772         emit_insn (gen_sse2_movsd (value, value, input));
13773     }
13774
13775   emit_move_insn (large, two31);
13776   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
13777
13778   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
13779   emit_insn (gen_rtx_SET (VOIDmode, large, x));
13780
13781   x = gen_rtx_AND (vecmode, zero_or_two31, large);
13782   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
13783
13784   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
13785   emit_insn (gen_rtx_SET (VOIDmode, value, x));
13786
13787   large = gen_rtx_REG (V4SImode, REGNO (large));
13788   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
13789
13790   x = gen_rtx_REG (V4SImode, REGNO (value));
13791   if (vecmode == V4SFmode)
13792     emit_insn (gen_sse2_cvttps2dq (x, value));
13793   else
13794     emit_insn (gen_sse2_cvttpd2dq (x, value));
13795   value = x;
13796
13797   emit_insn (gen_xorv4si3 (value, value, large));
13798 }
13799
13800 /* Convert an unsigned DImode value into a DFmode, using only SSE.
13801    Expects the 64-bit DImode to be supplied in a pair of integral
13802    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
13803    -mfpmath=sse, !optimize_size only.  */
13804
13805 void
13806 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
13807 {
13808   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
13809   rtx int_xmm, fp_xmm;
13810   rtx biases, exponents;
13811   rtx x;
13812
13813   int_xmm = gen_reg_rtx (V4SImode);
13814   if (TARGET_INTER_UNIT_MOVES)
13815     emit_insn (gen_movdi_to_sse (int_xmm, input));
13816   else if (TARGET_SSE_SPLIT_REGS)
13817     {
13818       emit_clobber (int_xmm);
13819       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
13820     }
13821   else
13822     {
13823       x = gen_reg_rtx (V2DImode);
13824       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
13825       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
13826     }
13827
13828   x = gen_rtx_CONST_VECTOR (V4SImode,
13829                             gen_rtvec (4, GEN_INT (0x43300000UL),
13830                                        GEN_INT (0x45300000UL),
13831                                        const0_rtx, const0_rtx));
13832   exponents = validize_mem (force_const_mem (V4SImode, x));
13833
13834   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
13835   emit_insn (gen_sse2_punpckldq (int_xmm, int_xmm, exponents));
13836
13837   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
13838      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
13839      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
13840      (0x1.0p84 + double(fp_value_hi_xmm)).
13841      Note these exponents differ by 32.  */
13842
13843   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
13844
13845   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
13846      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
13847   real_ldexp (&bias_lo_rvt, &dconst1, 52);
13848   real_ldexp (&bias_hi_rvt, &dconst1, 84);
13849   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
13850   x = const_double_from_real_value (bias_hi_rvt, DFmode);
13851   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
13852   biases = validize_mem (force_const_mem (V2DFmode, biases));
13853   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
13854
13855   /* Add the upper and lower DFmode values together.  */
13856   if (TARGET_SSE3)
13857     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
13858   else
13859     {
13860       x = copy_to_mode_reg (V2DFmode, fp_xmm);
13861       emit_insn (gen_sse2_unpckhpd (fp_xmm, fp_xmm, fp_xmm));
13862       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
13863     }
13864
13865   ix86_expand_vector_extract (false, target, fp_xmm, 0);
13866 }
13867
13868 /* Not used, but eases macroization of patterns.  */
13869 void
13870 ix86_expand_convert_uns_sixf_sse (rtx target ATTRIBUTE_UNUSED,
13871                                   rtx input ATTRIBUTE_UNUSED)
13872 {
13873   gcc_unreachable ();
13874 }
13875
13876 /* Convert an unsigned SImode value into a DFmode.  Only currently used
13877    for SSE, but applicable anywhere.  */
13878
13879 void
13880 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
13881 {
13882   REAL_VALUE_TYPE TWO31r;
13883   rtx x, fp;
13884
13885   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
13886                            NULL, 1, OPTAB_DIRECT);
13887
13888   fp = gen_reg_rtx (DFmode);
13889   emit_insn (gen_floatsidf2 (fp, x));
13890
13891   real_ldexp (&TWO31r, &dconst1, 31);
13892   x = const_double_from_real_value (TWO31r, DFmode);
13893
13894   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
13895   if (x != target)
13896     emit_move_insn (target, x);
13897 }
13898
13899 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
13900    32-bit mode; otherwise we have a direct convert instruction.  */
13901
13902 void
13903 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
13904 {
13905   REAL_VALUE_TYPE TWO32r;
13906   rtx fp_lo, fp_hi, x;
13907
13908   fp_lo = gen_reg_rtx (DFmode);
13909   fp_hi = gen_reg_rtx (DFmode);
13910
13911   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
13912
13913   real_ldexp (&TWO32r, &dconst1, 32);
13914   x = const_double_from_real_value (TWO32r, DFmode);
13915   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
13916
13917   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
13918
13919   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
13920                            0, OPTAB_DIRECT);
13921   if (x != target)
13922     emit_move_insn (target, x);
13923 }
13924
13925 /* Convert an unsigned SImode value into a SFmode, using only SSE.
13926    For x86_32, -mfpmath=sse, !optimize_size only.  */
13927 void
13928 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
13929 {
13930   REAL_VALUE_TYPE ONE16r;
13931   rtx fp_hi, fp_lo, int_hi, int_lo, x;
13932
13933   real_ldexp (&ONE16r, &dconst1, 16);
13934   x = const_double_from_real_value (ONE16r, SFmode);
13935   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
13936                                       NULL, 0, OPTAB_DIRECT);
13937   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
13938                                       NULL, 0, OPTAB_DIRECT);
13939   fp_hi = gen_reg_rtx (SFmode);
13940   fp_lo = gen_reg_rtx (SFmode);
13941   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
13942   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
13943   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
13944                                0, OPTAB_DIRECT);
13945   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
13946                                0, OPTAB_DIRECT);
13947   if (!rtx_equal_p (target, fp_hi))
13948     emit_move_insn (target, fp_hi);
13949 }
13950
13951 /* A subroutine of ix86_build_signbit_mask.  If VECT is true,
13952    then replicate the value for all elements of the vector
13953    register.  */
13954
13955 rtx
13956 ix86_build_const_vector (enum machine_mode mode, bool vect, rtx value)
13957 {
13958   rtvec v;
13959   switch (mode)
13960     {
13961     case SImode:
13962       gcc_assert (vect);
13963       v = gen_rtvec (4, value, value, value, value);
13964       return gen_rtx_CONST_VECTOR (V4SImode, v);
13965
13966     case DImode:
13967       gcc_assert (vect);
13968       v = gen_rtvec (2, value, value);
13969       return gen_rtx_CONST_VECTOR (V2DImode, v);
13970
13971     case SFmode:
13972       if (vect)
13973         v = gen_rtvec (4, value, value, value, value);
13974       else
13975         v = gen_rtvec (4, value, CONST0_RTX (SFmode),
13976                        CONST0_RTX (SFmode), CONST0_RTX (SFmode));
13977       return gen_rtx_CONST_VECTOR (V4SFmode, v);
13978
13979     case DFmode:
13980       if (vect)
13981         v = gen_rtvec (2, value, value);
13982       else
13983         v = gen_rtvec (2, value, CONST0_RTX (DFmode));
13984       return gen_rtx_CONST_VECTOR (V2DFmode, v);
13985
13986     default:
13987       gcc_unreachable ();
13988     }
13989 }
13990
13991 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
13992    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
13993    for an SSE register.  If VECT is true, then replicate the mask for
13994    all elements of the vector register.  If INVERT is true, then create
13995    a mask excluding the sign bit.  */
13996
13997 rtx
13998 ix86_build_signbit_mask (enum machine_mode mode, bool vect, bool invert)
13999 {
14000   enum machine_mode vec_mode, imode;
14001   HOST_WIDE_INT hi, lo;
14002   int shift = 63;
14003   rtx v;
14004   rtx mask;
14005
14006   /* Find the sign bit, sign extended to 2*HWI.  */
14007   switch (mode)
14008     {
14009     case SImode:
14010     case SFmode:
14011       imode = SImode;
14012       vec_mode = (mode == SImode) ? V4SImode : V4SFmode;
14013       lo = 0x80000000, hi = lo < 0;
14014       break;
14015
14016     case DImode:
14017     case DFmode:
14018       imode = DImode;
14019       vec_mode = (mode == DImode) ? V2DImode : V2DFmode;
14020       if (HOST_BITS_PER_WIDE_INT >= 64)
14021         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
14022       else
14023         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
14024       break;
14025
14026     case TImode:
14027     case TFmode:
14028       vec_mode = VOIDmode;
14029       if (HOST_BITS_PER_WIDE_INT >= 64)
14030         {
14031           imode = TImode;
14032           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
14033         }
14034       else
14035         {
14036           rtvec vec;
14037
14038           imode = DImode;
14039           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
14040
14041           if (invert)
14042             {
14043               lo = ~lo, hi = ~hi;
14044               v = constm1_rtx;
14045             }
14046           else
14047             v = const0_rtx;
14048
14049           mask = immed_double_const (lo, hi, imode);
14050
14051           vec = gen_rtvec (2, v, mask);
14052           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
14053           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
14054
14055           return v;
14056         }
14057      break;
14058
14059     default:
14060       gcc_unreachable ();
14061     }
14062
14063   if (invert)
14064     lo = ~lo, hi = ~hi;
14065
14066   /* Force this value into the low part of a fp vector constant.  */
14067   mask = immed_double_const (lo, hi, imode);
14068   mask = gen_lowpart (mode, mask);
14069
14070   if (vec_mode == VOIDmode)
14071     return force_reg (mode, mask);
14072
14073   v = ix86_build_const_vector (mode, vect, mask);
14074   return force_reg (vec_mode, v);
14075 }
14076
14077 /* Generate code for floating point ABS or NEG.  */
14078
14079 void
14080 ix86_expand_fp_absneg_operator (enum rtx_code code, enum machine_mode mode,
14081                                 rtx operands[])
14082 {
14083   rtx mask, set, use, clob, dst, src;
14084   bool use_sse = false;
14085   bool vector_mode = VECTOR_MODE_P (mode);
14086   enum machine_mode elt_mode = mode;
14087
14088   if (vector_mode)
14089     {
14090       elt_mode = GET_MODE_INNER (mode);
14091       use_sse = true;
14092     }
14093   else if (mode == TFmode)
14094     use_sse = true;
14095   else if (TARGET_SSE_MATH)
14096     use_sse = SSE_FLOAT_MODE_P (mode);
14097
14098   /* NEG and ABS performed with SSE use bitwise mask operations.
14099      Create the appropriate mask now.  */
14100   if (use_sse)
14101     mask = ix86_build_signbit_mask (elt_mode, vector_mode, code == ABS);
14102   else
14103     mask = NULL_RTX;
14104
14105   dst = operands[0];
14106   src = operands[1];
14107
14108   if (vector_mode)
14109     {
14110       set = gen_rtx_fmt_ee (code == NEG ? XOR : AND, mode, src, mask);
14111       set = gen_rtx_SET (VOIDmode, dst, set);
14112       emit_insn (set);
14113     }
14114   else
14115     {
14116       set = gen_rtx_fmt_e (code, mode, src);
14117       set = gen_rtx_SET (VOIDmode, dst, set);
14118       if (mask)
14119         {
14120           use = gen_rtx_USE (VOIDmode, mask);
14121           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
14122           emit_insn (gen_rtx_PARALLEL (VOIDmode,
14123                                        gen_rtvec (3, set, use, clob)));
14124         }
14125       else
14126         emit_insn (set);
14127     }
14128 }
14129
14130 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
14131
14132 void
14133 ix86_expand_copysign (rtx operands[])
14134 {
14135   enum machine_mode mode;
14136   rtx dest, op0, op1, mask, nmask;
14137
14138   dest = operands[0];
14139   op0 = operands[1];
14140   op1 = operands[2];
14141
14142   mode = GET_MODE (dest);
14143
14144   if (GET_CODE (op0) == CONST_DOUBLE)
14145     {
14146       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
14147
14148       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
14149         op0 = simplify_unary_operation (ABS, mode, op0, mode);
14150
14151       if (mode == SFmode || mode == DFmode)
14152         {
14153           enum machine_mode vmode;
14154
14155           vmode = mode == SFmode ? V4SFmode : V2DFmode;
14156
14157           if (op0 == CONST0_RTX (mode))
14158             op0 = CONST0_RTX (vmode);
14159           else
14160             {
14161               rtx v = ix86_build_const_vector (mode, false, op0);
14162
14163               op0 = force_reg (vmode, v);
14164             }
14165         }
14166       else if (op0 != CONST0_RTX (mode))
14167         op0 = force_reg (mode, op0);
14168
14169       mask = ix86_build_signbit_mask (mode, 0, 0);
14170
14171       if (mode == SFmode)
14172         copysign_insn = gen_copysignsf3_const;
14173       else if (mode == DFmode)
14174         copysign_insn = gen_copysigndf3_const;
14175       else
14176         copysign_insn = gen_copysigntf3_const;
14177
14178         emit_insn (copysign_insn (dest, op0, op1, mask));
14179     }
14180   else
14181     {
14182       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
14183
14184       nmask = ix86_build_signbit_mask (mode, 0, 1);
14185       mask = ix86_build_signbit_mask (mode, 0, 0);
14186
14187       if (mode == SFmode)
14188         copysign_insn = gen_copysignsf3_var;
14189       else if (mode == DFmode)
14190         copysign_insn = gen_copysigndf3_var;
14191       else
14192         copysign_insn = gen_copysigntf3_var;
14193
14194       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
14195     }
14196 }
14197
14198 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
14199    be a constant, and so has already been expanded into a vector constant.  */
14200
14201 void
14202 ix86_split_copysign_const (rtx operands[])
14203 {
14204   enum machine_mode mode, vmode;
14205   rtx dest, op0, op1, mask, x;
14206
14207   dest = operands[0];
14208   op0 = operands[1];
14209   op1 = operands[2];
14210   mask = operands[3];
14211
14212   mode = GET_MODE (dest);
14213   vmode = GET_MODE (mask);
14214
14215   dest = simplify_gen_subreg (vmode, dest, mode, 0);
14216   x = gen_rtx_AND (vmode, dest, mask);
14217   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14218
14219   if (op0 != CONST0_RTX (vmode))
14220     {
14221       x = gen_rtx_IOR (vmode, dest, op0);
14222       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14223     }
14224 }
14225
14226 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
14227    so we have to do two masks.  */
14228
14229 void
14230 ix86_split_copysign_var (rtx operands[])
14231 {
14232   enum machine_mode mode, vmode;
14233   rtx dest, scratch, op0, op1, mask, nmask, x;
14234
14235   dest = operands[0];
14236   scratch = operands[1];
14237   op0 = operands[2];
14238   op1 = operands[3];
14239   nmask = operands[4];
14240   mask = operands[5];
14241
14242   mode = GET_MODE (dest);
14243   vmode = GET_MODE (mask);
14244
14245   if (rtx_equal_p (op0, op1))
14246     {
14247       /* Shouldn't happen often (it's useless, obviously), but when it does
14248          we'd generate incorrect code if we continue below.  */
14249       emit_move_insn (dest, op0);
14250       return;
14251     }
14252
14253   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
14254     {
14255       gcc_assert (REGNO (op1) == REGNO (scratch));
14256
14257       x = gen_rtx_AND (vmode, scratch, mask);
14258       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
14259
14260       dest = mask;
14261       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
14262       x = gen_rtx_NOT (vmode, dest);
14263       x = gen_rtx_AND (vmode, x, op0);
14264       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14265     }
14266   else
14267     {
14268       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
14269         {
14270           x = gen_rtx_AND (vmode, scratch, mask);
14271         }
14272       else                                              /* alternative 2,4 */
14273         {
14274           gcc_assert (REGNO (mask) == REGNO (scratch));
14275           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
14276           x = gen_rtx_AND (vmode, scratch, op1);
14277         }
14278       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
14279
14280       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
14281         {
14282           dest = simplify_gen_subreg (vmode, op0, mode, 0);
14283           x = gen_rtx_AND (vmode, dest, nmask);
14284         }
14285       else                                              /* alternative 3,4 */
14286         {
14287           gcc_assert (REGNO (nmask) == REGNO (dest));
14288           dest = nmask;
14289           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
14290           x = gen_rtx_AND (vmode, dest, op0);
14291         }
14292       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14293     }
14294
14295   x = gen_rtx_IOR (vmode, dest, scratch);
14296   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14297 }
14298
14299 /* Return TRUE or FALSE depending on whether the first SET in INSN
14300    has source and destination with matching CC modes, and that the
14301    CC mode is at least as constrained as REQ_MODE.  */
14302
14303 int
14304 ix86_match_ccmode (rtx insn, enum machine_mode req_mode)
14305 {
14306   rtx set;
14307   enum machine_mode set_mode;
14308
14309   set = PATTERN (insn);
14310   if (GET_CODE (set) == PARALLEL)
14311     set = XVECEXP (set, 0, 0);
14312   gcc_assert (GET_CODE (set) == SET);
14313   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
14314
14315   set_mode = GET_MODE (SET_DEST (set));
14316   switch (set_mode)
14317     {
14318     case CCNOmode:
14319       if (req_mode != CCNOmode
14320           && (req_mode != CCmode
14321               || XEXP (SET_SRC (set), 1) != const0_rtx))
14322         return 0;
14323       break;
14324     case CCmode:
14325       if (req_mode == CCGCmode)
14326         return 0;
14327       /* FALLTHRU */
14328     case CCGCmode:
14329       if (req_mode == CCGOCmode || req_mode == CCNOmode)
14330         return 0;
14331       /* FALLTHRU */
14332     case CCGOCmode:
14333       if (req_mode == CCZmode)
14334         return 0;
14335       /* FALLTHRU */
14336     case CCAmode:
14337     case CCCmode:
14338     case CCOmode:
14339     case CCSmode:
14340     case CCZmode:
14341       break;
14342
14343     default:
14344       gcc_unreachable ();
14345     }
14346
14347   return (GET_MODE (SET_SRC (set)) == set_mode);
14348 }
14349
14350 /* Generate insn patterns to do an integer compare of OPERANDS.  */
14351
14352 static rtx
14353 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
14354 {
14355   enum machine_mode cmpmode;
14356   rtx tmp, flags;
14357
14358   cmpmode = SELECT_CC_MODE (code, op0, op1);
14359   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
14360
14361   /* This is very simple, but making the interface the same as in the
14362      FP case makes the rest of the code easier.  */
14363   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
14364   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
14365
14366   /* Return the test that should be put into the flags user, i.e.
14367      the bcc, scc, or cmov instruction.  */
14368   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
14369 }
14370
14371 /* Figure out whether to use ordered or unordered fp comparisons.
14372    Return the appropriate mode to use.  */
14373
14374 enum machine_mode
14375 ix86_fp_compare_mode (enum rtx_code code ATTRIBUTE_UNUSED)
14376 {
14377   /* ??? In order to make all comparisons reversible, we do all comparisons
14378      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
14379      all forms trapping and nontrapping comparisons, we can make inequality
14380      comparisons trapping again, since it results in better code when using
14381      FCOM based compares.  */
14382   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
14383 }
14384
14385 enum machine_mode
14386 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
14387 {
14388   enum machine_mode mode = GET_MODE (op0);
14389
14390   if (SCALAR_FLOAT_MODE_P (mode))
14391     {
14392       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
14393       return ix86_fp_compare_mode (code);
14394     }
14395
14396   switch (code)
14397     {
14398       /* Only zero flag is needed.  */
14399     case EQ:                    /* ZF=0 */
14400     case NE:                    /* ZF!=0 */
14401       return CCZmode;
14402       /* Codes needing carry flag.  */
14403     case GEU:                   /* CF=0 */
14404     case LTU:                   /* CF=1 */
14405       /* Detect overflow checks.  They need just the carry flag.  */
14406       if (GET_CODE (op0) == PLUS
14407           && rtx_equal_p (op1, XEXP (op0, 0)))
14408         return CCCmode;
14409       else
14410         return CCmode;
14411     case GTU:                   /* CF=0 & ZF=0 */
14412     case LEU:                   /* CF=1 | ZF=1 */
14413       /* Detect overflow checks.  They need just the carry flag.  */
14414       if (GET_CODE (op0) == MINUS
14415           && rtx_equal_p (op1, XEXP (op0, 0)))
14416         return CCCmode;
14417       else
14418         return CCmode;
14419       /* Codes possibly doable only with sign flag when
14420          comparing against zero.  */
14421     case GE:                    /* SF=OF   or   SF=0 */
14422     case LT:                    /* SF<>OF  or   SF=1 */
14423       if (op1 == const0_rtx)
14424         return CCGOCmode;
14425       else
14426         /* For other cases Carry flag is not required.  */
14427         return CCGCmode;
14428       /* Codes doable only with sign flag when comparing
14429          against zero, but we miss jump instruction for it
14430          so we need to use relational tests against overflow
14431          that thus needs to be zero.  */
14432     case GT:                    /* ZF=0 & SF=OF */
14433     case LE:                    /* ZF=1 | SF<>OF */
14434       if (op1 == const0_rtx)
14435         return CCNOmode;
14436       else
14437         return CCGCmode;
14438       /* strcmp pattern do (use flags) and combine may ask us for proper
14439          mode.  */
14440     case USE:
14441       return CCmode;
14442     default:
14443       gcc_unreachable ();
14444     }
14445 }
14446
14447 /* Return the fixed registers used for condition codes.  */
14448
14449 static bool
14450 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
14451 {
14452   *p1 = FLAGS_REG;
14453   *p2 = FPSR_REG;
14454   return true;
14455 }
14456
14457 /* If two condition code modes are compatible, return a condition code
14458    mode which is compatible with both.  Otherwise, return
14459    VOIDmode.  */
14460
14461 static enum machine_mode
14462 ix86_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
14463 {
14464   if (m1 == m2)
14465     return m1;
14466
14467   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
14468     return VOIDmode;
14469
14470   if ((m1 == CCGCmode && m2 == CCGOCmode)
14471       || (m1 == CCGOCmode && m2 == CCGCmode))
14472     return CCGCmode;
14473
14474   switch (m1)
14475     {
14476     default:
14477       gcc_unreachable ();
14478
14479     case CCmode:
14480     case CCGCmode:
14481     case CCGOCmode:
14482     case CCNOmode:
14483     case CCAmode:
14484     case CCCmode:
14485     case CCOmode:
14486     case CCSmode:
14487     case CCZmode:
14488       switch (m2)
14489         {
14490         default:
14491           return VOIDmode;
14492
14493         case CCmode:
14494         case CCGCmode:
14495         case CCGOCmode:
14496         case CCNOmode:
14497         case CCAmode:
14498         case CCCmode:
14499         case CCOmode:
14500         case CCSmode:
14501         case CCZmode:
14502           return CCmode;
14503         }
14504
14505     case CCFPmode:
14506     case CCFPUmode:
14507       /* These are only compatible with themselves, which we already
14508          checked above.  */
14509       return VOIDmode;
14510     }
14511 }
14512
14513
14514 /* Return a comparison we can do and that it is equivalent to 
14515    swap_condition (code) apart possibly from orderedness.
14516    But, never change orderedness if TARGET_IEEE_FP, returning
14517    UNKNOWN in that case if necessary.  */
14518
14519 static enum rtx_code
14520 ix86_fp_swap_condition (enum rtx_code code)
14521 {
14522   switch (code)
14523     {
14524     case GT:                   /* GTU - CF=0 & ZF=0 */
14525       return TARGET_IEEE_FP ? UNKNOWN : UNLT;
14526     case GE:                   /* GEU - CF=0 */
14527       return TARGET_IEEE_FP ? UNKNOWN : UNLE;
14528     case UNLT:                 /* LTU - CF=1 */
14529       return TARGET_IEEE_FP ? UNKNOWN : GT;
14530     case UNLE:                 /* LEU - CF=1 | ZF=1 */
14531       return TARGET_IEEE_FP ? UNKNOWN : GE;
14532     default:
14533       return swap_condition (code);
14534     }
14535 }
14536
14537 /* Return cost of comparison CODE using the best strategy for performance.
14538    All following functions do use number of instructions as a cost metrics.
14539    In future this should be tweaked to compute bytes for optimize_size and
14540    take into account performance of various instructions on various CPUs.  */
14541
14542 static int
14543 ix86_fp_comparison_cost (enum rtx_code code)
14544 {
14545   int arith_cost;
14546
14547   /* The cost of code using bit-twiddling on %ah.  */
14548   switch (code)
14549     {
14550     case UNLE:
14551     case UNLT:
14552     case LTGT:
14553     case GT:
14554     case GE:
14555     case UNORDERED:
14556     case ORDERED:
14557     case UNEQ:
14558       arith_cost = 4;
14559       break;
14560     case LT:
14561     case NE:
14562     case EQ:
14563     case UNGE:
14564       arith_cost = TARGET_IEEE_FP ? 5 : 4;
14565       break;
14566     case LE:
14567     case UNGT:
14568       arith_cost = TARGET_IEEE_FP ? 6 : 4;
14569       break;
14570     default:
14571       gcc_unreachable ();
14572     }
14573
14574   switch (ix86_fp_comparison_strategy (code))
14575     {
14576     case IX86_FPCMP_COMI:
14577       return arith_cost > 4 ? 3 : 2;
14578     case IX86_FPCMP_SAHF:
14579       return arith_cost > 4 ? 4 : 3;
14580     default:
14581       return arith_cost;
14582     }
14583 }
14584
14585 /* Return strategy to use for floating-point.  We assume that fcomi is always
14586    preferrable where available, since that is also true when looking at size
14587    (2 bytes, vs. 3 for fnstsw+sahf and at least 5 for fnstsw+test).  */
14588
14589 enum ix86_fpcmp_strategy
14590 ix86_fp_comparison_strategy (enum rtx_code code ATTRIBUTE_UNUSED)
14591 {
14592   /* Do fcomi/sahf based test when profitable.  */
14593
14594   if (TARGET_CMOVE)
14595     return IX86_FPCMP_COMI;
14596
14597   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_function_for_size_p (cfun)))
14598     return IX86_FPCMP_SAHF;
14599
14600   return IX86_FPCMP_ARITH;
14601 }
14602
14603 /* Swap, force into registers, or otherwise massage the two operands
14604    to a fp comparison.  The operands are updated in place; the new
14605    comparison code is returned.  */
14606
14607 static enum rtx_code
14608 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
14609 {
14610   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
14611   rtx op0 = *pop0, op1 = *pop1;
14612   enum machine_mode op_mode = GET_MODE (op0);
14613   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
14614
14615   /* All of the unordered compare instructions only work on registers.
14616      The same is true of the fcomi compare instructions.  The XFmode
14617      compare instructions require registers except when comparing
14618      against zero or when converting operand 1 from fixed point to
14619      floating point.  */
14620
14621   if (!is_sse
14622       && (fpcmp_mode == CCFPUmode
14623           || (op_mode == XFmode
14624               && ! (standard_80387_constant_p (op0) == 1
14625                     || standard_80387_constant_p (op1) == 1)
14626               && GET_CODE (op1) != FLOAT)
14627           || ix86_fp_comparison_strategy (code) == IX86_FPCMP_COMI))
14628     {
14629       op0 = force_reg (op_mode, op0);
14630       op1 = force_reg (op_mode, op1);
14631     }
14632   else
14633     {
14634       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
14635          things around if they appear profitable, otherwise force op0
14636          into a register.  */
14637
14638       if (standard_80387_constant_p (op0) == 0
14639           || (MEM_P (op0)
14640               && ! (standard_80387_constant_p (op1) == 0
14641                     || MEM_P (op1))))
14642         {
14643           enum rtx_code new_code = ix86_fp_swap_condition (code);
14644           if (new_code != UNKNOWN)
14645             {
14646               rtx tmp;
14647               tmp = op0, op0 = op1, op1 = tmp;
14648               code = new_code;
14649             }
14650         }
14651
14652       if (!REG_P (op0))
14653         op0 = force_reg (op_mode, op0);
14654
14655       if (CONSTANT_P (op1))
14656         {
14657           int tmp = standard_80387_constant_p (op1);
14658           if (tmp == 0)
14659             op1 = validize_mem (force_const_mem (op_mode, op1));
14660           else if (tmp == 1)
14661             {
14662               if (TARGET_CMOVE)
14663                 op1 = force_reg (op_mode, op1);
14664             }
14665           else
14666             op1 = force_reg (op_mode, op1);
14667         }
14668     }
14669
14670   /* Try to rearrange the comparison to make it cheaper.  */
14671   if (ix86_fp_comparison_cost (code)
14672       > ix86_fp_comparison_cost (swap_condition (code))
14673       && (REG_P (op1) || can_create_pseudo_p ()))
14674     {
14675       rtx tmp;
14676       tmp = op0, op0 = op1, op1 = tmp;
14677       code = swap_condition (code);
14678       if (!REG_P (op0))
14679         op0 = force_reg (op_mode, op0);
14680     }
14681
14682   *pop0 = op0;
14683   *pop1 = op1;
14684   return code;
14685 }
14686
14687 /* Convert comparison codes we use to represent FP comparison to integer
14688    code that will result in proper branch.  Return UNKNOWN if no such code
14689    is available.  */
14690
14691 enum rtx_code
14692 ix86_fp_compare_code_to_integer (enum rtx_code code)
14693 {
14694   switch (code)
14695     {
14696     case GT:
14697       return GTU;
14698     case GE:
14699       return GEU;
14700     case ORDERED:
14701     case UNORDERED:
14702       return code;
14703       break;
14704     case UNEQ:
14705       return EQ;
14706       break;
14707     case UNLT:
14708       return LTU;
14709       break;
14710     case UNLE:
14711       return LEU;
14712       break;
14713     case LTGT:
14714       return NE;
14715       break;
14716     default:
14717       return UNKNOWN;
14718     }
14719 }
14720
14721 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
14722
14723 static rtx
14724 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch)
14725 {
14726   enum machine_mode fpcmp_mode, intcmp_mode;
14727   rtx tmp, tmp2;
14728
14729   fpcmp_mode = ix86_fp_compare_mode (code);
14730   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
14731
14732   /* Do fcomi/sahf based test when profitable.  */
14733   switch (ix86_fp_comparison_strategy (code))
14734     {
14735     case IX86_FPCMP_COMI:
14736       intcmp_mode = fpcmp_mode;
14737       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
14738       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
14739                          tmp);
14740       emit_insn (tmp);
14741       break;
14742
14743     case IX86_FPCMP_SAHF:
14744       intcmp_mode = fpcmp_mode;
14745       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
14746       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
14747                          tmp);
14748
14749       if (!scratch)
14750         scratch = gen_reg_rtx (HImode);
14751       tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
14752       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
14753       break;
14754
14755     case IX86_FPCMP_ARITH:
14756       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
14757       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
14758       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
14759       if (!scratch)
14760         scratch = gen_reg_rtx (HImode);
14761       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
14762
14763       /* In the unordered case, we have to check C2 for NaN's, which
14764          doesn't happen to work out to anything nice combination-wise.
14765          So do some bit twiddling on the value we've got in AH to come
14766          up with an appropriate set of condition codes.  */
14767
14768       intcmp_mode = CCNOmode;
14769       switch (code)
14770         {
14771         case GT:
14772         case UNGT:
14773           if (code == GT || !TARGET_IEEE_FP)
14774             {
14775               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
14776               code = EQ;
14777             }
14778           else
14779             {
14780               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14781               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
14782               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
14783               intcmp_mode = CCmode;
14784               code = GEU;
14785             }
14786           break;
14787         case LT:
14788         case UNLT:
14789           if (code == LT && TARGET_IEEE_FP)
14790             {
14791               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14792               emit_insn (gen_cmpqi_ext_3 (scratch, const1_rtx));
14793               intcmp_mode = CCmode;
14794               code = EQ;
14795             }
14796           else
14797             {
14798               emit_insn (gen_testqi_ext_ccno_0 (scratch, const1_rtx));
14799               code = NE;
14800             }
14801           break;
14802         case GE:
14803         case UNGE:
14804           if (code == GE || !TARGET_IEEE_FP)
14805             {
14806               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
14807               code = EQ;
14808             }
14809           else
14810             {
14811               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14812               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch, const1_rtx));
14813               code = NE;
14814             }
14815           break;
14816         case LE:
14817         case UNLE:
14818           if (code == LE && TARGET_IEEE_FP)
14819             {
14820               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14821               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
14822               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
14823               intcmp_mode = CCmode;
14824               code = LTU;
14825             }
14826           else
14827             {
14828               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
14829               code = NE;
14830             }
14831           break;
14832         case EQ:
14833         case UNEQ:
14834           if (code == EQ && TARGET_IEEE_FP)
14835             {
14836               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14837               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
14838               intcmp_mode = CCmode;
14839               code = EQ;
14840             }
14841           else
14842             {
14843               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
14844               code = NE;
14845             }
14846           break;
14847         case NE:
14848         case LTGT:
14849           if (code == NE && TARGET_IEEE_FP)
14850             {
14851               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14852               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
14853                                              GEN_INT (0x40)));
14854               code = NE;
14855             }
14856           else
14857             {
14858               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
14859               code = EQ;
14860             }
14861           break;
14862
14863         case UNORDERED:
14864           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
14865           code = NE;
14866           break;
14867         case ORDERED:
14868           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
14869           code = EQ;
14870           break;
14871
14872         default:
14873           gcc_unreachable ();
14874         }
14875         break;
14876
14877     default:
14878       gcc_unreachable();
14879     }
14880
14881   /* Return the test that should be put into the flags user, i.e.
14882      the bcc, scc, or cmov instruction.  */
14883   return gen_rtx_fmt_ee (code, VOIDmode,
14884                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
14885                          const0_rtx);
14886 }
14887
14888 rtx
14889 ix86_expand_compare (enum rtx_code code)
14890 {
14891   rtx op0, op1, ret;
14892   op0 = ix86_compare_op0;
14893   op1 = ix86_compare_op1;
14894
14895   if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_CC)
14896     ret = gen_rtx_fmt_ee (code, VOIDmode, ix86_compare_op0, ix86_compare_op1);
14897
14898   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
14899     {
14900       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
14901       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX);
14902     }
14903   else
14904     ret = ix86_expand_int_compare (code, op0, op1);
14905
14906   return ret;
14907 }
14908
14909 void
14910 ix86_expand_branch (enum rtx_code code, rtx label)
14911 {
14912   rtx tmp;
14913
14914   switch (GET_MODE (ix86_compare_op0))
14915     {
14916     case SFmode:
14917     case DFmode:
14918     case XFmode:
14919     case QImode:
14920     case HImode:
14921     case SImode:
14922       simple:
14923       tmp = ix86_expand_compare (code);
14924       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
14925                                   gen_rtx_LABEL_REF (VOIDmode, label),
14926                                   pc_rtx);
14927       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
14928       return;
14929
14930     case DImode:
14931       if (TARGET_64BIT)
14932         goto simple;
14933     case TImode:
14934       /* Expand DImode branch into multiple compare+branch.  */
14935       {
14936         rtx lo[2], hi[2], label2;
14937         enum rtx_code code1, code2, code3;
14938         enum machine_mode submode;
14939
14940         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
14941           {
14942             tmp = ix86_compare_op0;
14943             ix86_compare_op0 = ix86_compare_op1;
14944             ix86_compare_op1 = tmp;
14945             code = swap_condition (code);
14946           }
14947         if (GET_MODE (ix86_compare_op0) == DImode)
14948           {
14949             split_di (&ix86_compare_op0, 1, lo+0, hi+0);
14950             split_di (&ix86_compare_op1, 1, lo+1, hi+1);
14951             submode = SImode;
14952           }
14953         else
14954           {
14955             split_ti (&ix86_compare_op0, 1, lo+0, hi+0);
14956             split_ti (&ix86_compare_op1, 1, lo+1, hi+1);
14957             submode = DImode;
14958           }
14959
14960         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
14961            avoid two branches.  This costs one extra insn, so disable when
14962            optimizing for size.  */
14963
14964         if ((code == EQ || code == NE)
14965             && (!optimize_insn_for_size_p ()
14966                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
14967           {
14968             rtx xor0, xor1;
14969
14970             xor1 = hi[0];
14971             if (hi[1] != const0_rtx)
14972               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
14973                                    NULL_RTX, 0, OPTAB_WIDEN);
14974
14975             xor0 = lo[0];
14976             if (lo[1] != const0_rtx)
14977               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
14978                                    NULL_RTX, 0, OPTAB_WIDEN);
14979
14980             tmp = expand_binop (submode, ior_optab, xor1, xor0,
14981                                 NULL_RTX, 0, OPTAB_WIDEN);
14982
14983             ix86_compare_op0 = tmp;
14984             ix86_compare_op1 = const0_rtx;
14985             ix86_expand_branch (code, label);
14986             return;
14987           }
14988
14989         /* Otherwise, if we are doing less-than or greater-or-equal-than,
14990            op1 is a constant and the low word is zero, then we can just
14991            examine the high word.  Similarly for low word -1 and
14992            less-or-equal-than or greater-than.  */
14993
14994         if (CONST_INT_P (hi[1]))
14995           switch (code)
14996             {
14997             case LT: case LTU: case GE: case GEU:
14998               if (lo[1] == const0_rtx)
14999                 {
15000                   ix86_compare_op0 = hi[0];
15001                   ix86_compare_op1 = hi[1];
15002                   ix86_expand_branch (code, label);
15003                   return;
15004                 }
15005               break;
15006             case LE: case LEU: case GT: case GTU:
15007               if (lo[1] == constm1_rtx)
15008                 {
15009                   ix86_compare_op0 = hi[0];
15010                   ix86_compare_op1 = hi[1];
15011                   ix86_expand_branch (code, label);
15012                   return;
15013                 }
15014               break;
15015             default:
15016               break;
15017             }
15018
15019         /* Otherwise, we need two or three jumps.  */
15020
15021         label2 = gen_label_rtx ();
15022
15023         code1 = code;
15024         code2 = swap_condition (code);
15025         code3 = unsigned_condition (code);
15026
15027         switch (code)
15028           {
15029           case LT: case GT: case LTU: case GTU:
15030             break;
15031
15032           case LE:   code1 = LT;  code2 = GT;  break;
15033           case GE:   code1 = GT;  code2 = LT;  break;
15034           case LEU:  code1 = LTU; code2 = GTU; break;
15035           case GEU:  code1 = GTU; code2 = LTU; break;
15036
15037           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
15038           case NE:   code2 = UNKNOWN; break;
15039
15040           default:
15041             gcc_unreachable ();
15042           }
15043
15044         /*
15045          * a < b =>
15046          *    if (hi(a) < hi(b)) goto true;
15047          *    if (hi(a) > hi(b)) goto false;
15048          *    if (lo(a) < lo(b)) goto true;
15049          *  false:
15050          */
15051
15052         ix86_compare_op0 = hi[0];
15053         ix86_compare_op1 = hi[1];
15054
15055         if (code1 != UNKNOWN)
15056           ix86_expand_branch (code1, label);
15057         if (code2 != UNKNOWN)
15058           ix86_expand_branch (code2, label2);
15059
15060         ix86_compare_op0 = lo[0];
15061         ix86_compare_op1 = lo[1];
15062         ix86_expand_branch (code3, label);
15063
15064         if (code2 != UNKNOWN)
15065           emit_label (label2);
15066         return;
15067       }
15068
15069     default:
15070       /* If we have already emitted a compare insn, go straight to simple.
15071          ix86_expand_compare won't emit anything if ix86_compare_emitted
15072          is non NULL.  */
15073       gcc_assert (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_CC);
15074       goto simple;
15075     }
15076 }
15077
15078 /* Split branch based on floating point condition.  */
15079 void
15080 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
15081                       rtx target1, rtx target2, rtx tmp, rtx pushed)
15082 {
15083   rtx condition;
15084   rtx i;
15085
15086   if (target2 != pc_rtx)
15087     {
15088       rtx tmp = target2;
15089       code = reverse_condition_maybe_unordered (code);
15090       target2 = target1;
15091       target1 = tmp;
15092     }
15093
15094   condition = ix86_expand_fp_compare (code, op1, op2,
15095                                       tmp);
15096
15097   /* Remove pushed operand from stack.  */
15098   if (pushed)
15099     ix86_free_from_memory (GET_MODE (pushed));
15100
15101   i = emit_jump_insn (gen_rtx_SET
15102                       (VOIDmode, pc_rtx,
15103                        gen_rtx_IF_THEN_ELSE (VOIDmode,
15104                                              condition, target1, target2)));
15105   if (split_branch_probability >= 0)
15106     add_reg_note (i, REG_BR_PROB, GEN_INT (split_branch_probability));
15107 }
15108
15109 void
15110 ix86_expand_setcc (enum rtx_code code, rtx dest)
15111 {
15112   rtx ret;
15113
15114   gcc_assert (GET_MODE (dest) == QImode);
15115
15116   ret = ix86_expand_compare (code);
15117   PUT_MODE (ret, QImode);
15118   emit_insn (gen_rtx_SET (VOIDmode, dest, ret));
15119 }
15120
15121 /* Expand comparison setting or clearing carry flag.  Return true when
15122    successful and set pop for the operation.  */
15123 static bool
15124 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
15125 {
15126   enum machine_mode mode =
15127     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
15128
15129   /* Do not handle DImode compares that go through special path.  */
15130   if (mode == (TARGET_64BIT ? TImode : DImode))
15131     return false;
15132
15133   if (SCALAR_FLOAT_MODE_P (mode))
15134     {
15135       rtx compare_op, compare_seq;
15136
15137       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
15138
15139       /* Shortcut:  following common codes never translate
15140          into carry flag compares.  */
15141       if (code == EQ || code == NE || code == UNEQ || code == LTGT
15142           || code == ORDERED || code == UNORDERED)
15143         return false;
15144
15145       /* These comparisons require zero flag; swap operands so they won't.  */
15146       if ((code == GT || code == UNLE || code == LE || code == UNGT)
15147           && !TARGET_IEEE_FP)
15148         {
15149           rtx tmp = op0;
15150           op0 = op1;
15151           op1 = tmp;
15152           code = swap_condition (code);
15153         }
15154
15155       /* Try to expand the comparison and verify that we end up with
15156          carry flag based comparison.  This fails to be true only when
15157          we decide to expand comparison using arithmetic that is not
15158          too common scenario.  */
15159       start_sequence ();
15160       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX);
15161       compare_seq = get_insns ();
15162       end_sequence ();
15163
15164       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
15165           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
15166         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
15167       else
15168         code = GET_CODE (compare_op);
15169
15170       if (code != LTU && code != GEU)
15171         return false;
15172
15173       emit_insn (compare_seq);
15174       *pop = compare_op;
15175       return true;
15176     }
15177
15178   if (!INTEGRAL_MODE_P (mode))
15179     return false;
15180
15181   switch (code)
15182     {
15183     case LTU:
15184     case GEU:
15185       break;
15186
15187     /* Convert a==0 into (unsigned)a<1.  */
15188     case EQ:
15189     case NE:
15190       if (op1 != const0_rtx)
15191         return false;
15192       op1 = const1_rtx;
15193       code = (code == EQ ? LTU : GEU);
15194       break;
15195
15196     /* Convert a>b into b<a or a>=b-1.  */
15197     case GTU:
15198     case LEU:
15199       if (CONST_INT_P (op1))
15200         {
15201           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
15202           /* Bail out on overflow.  We still can swap operands but that
15203              would force loading of the constant into register.  */
15204           if (op1 == const0_rtx
15205               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
15206             return false;
15207           code = (code == GTU ? GEU : LTU);
15208         }
15209       else
15210         {
15211           rtx tmp = op1;
15212           op1 = op0;
15213           op0 = tmp;
15214           code = (code == GTU ? LTU : GEU);
15215         }
15216       break;
15217
15218     /* Convert a>=0 into (unsigned)a<0x80000000.  */
15219     case LT:
15220     case GE:
15221       if (mode == DImode || op1 != const0_rtx)
15222         return false;
15223       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
15224       code = (code == LT ? GEU : LTU);
15225       break;
15226     case LE:
15227     case GT:
15228       if (mode == DImode || op1 != constm1_rtx)
15229         return false;
15230       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
15231       code = (code == LE ? GEU : LTU);
15232       break;
15233
15234     default:
15235       return false;
15236     }
15237   /* Swapping operands may cause constant to appear as first operand.  */
15238   if (!nonimmediate_operand (op0, VOIDmode))
15239     {
15240       if (!can_create_pseudo_p ())
15241         return false;
15242       op0 = force_reg (mode, op0);
15243     }
15244   ix86_compare_op0 = op0;
15245   ix86_compare_op1 = op1;
15246   *pop = ix86_expand_compare (code);
15247   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
15248   return true;
15249 }
15250
15251 int
15252 ix86_expand_int_movcc (rtx operands[])
15253 {
15254   enum rtx_code code = GET_CODE (operands[1]), compare_code;
15255   rtx compare_seq, compare_op;
15256   enum machine_mode mode = GET_MODE (operands[0]);
15257   bool sign_bit_compare_p = false;;
15258
15259   start_sequence ();
15260   ix86_compare_op0 = XEXP (operands[1], 0);
15261   ix86_compare_op1 = XEXP (operands[1], 1);
15262   compare_op = ix86_expand_compare (code);
15263   compare_seq = get_insns ();
15264   end_sequence ();
15265
15266   compare_code = GET_CODE (compare_op);
15267
15268   if ((ix86_compare_op1 == const0_rtx && (code == GE || code == LT))
15269       || (ix86_compare_op1 == constm1_rtx && (code == GT || code == LE)))
15270     sign_bit_compare_p = true;
15271
15272   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
15273      HImode insns, we'd be swallowed in word prefix ops.  */
15274
15275   if ((mode != HImode || TARGET_FAST_PREFIX)
15276       && (mode != (TARGET_64BIT ? TImode : DImode))
15277       && CONST_INT_P (operands[2])
15278       && CONST_INT_P (operands[3]))
15279     {
15280       rtx out = operands[0];
15281       HOST_WIDE_INT ct = INTVAL (operands[2]);
15282       HOST_WIDE_INT cf = INTVAL (operands[3]);
15283       HOST_WIDE_INT diff;
15284
15285       diff = ct - cf;
15286       /*  Sign bit compares are better done using shifts than we do by using
15287           sbb.  */
15288       if (sign_bit_compare_p
15289           || ix86_expand_carry_flag_compare (code, ix86_compare_op0,
15290                                              ix86_compare_op1, &compare_op))
15291         {
15292           /* Detect overlap between destination and compare sources.  */
15293           rtx tmp = out;
15294
15295           if (!sign_bit_compare_p)
15296             {
15297               bool fpcmp = false;
15298
15299               compare_code = GET_CODE (compare_op);
15300
15301               if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
15302                   || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
15303                 {
15304                   fpcmp = true;
15305                   compare_code = ix86_fp_compare_code_to_integer (compare_code);
15306                 }
15307
15308               /* To simplify rest of code, restrict to the GEU case.  */
15309               if (compare_code == LTU)
15310                 {
15311                   HOST_WIDE_INT tmp = ct;
15312                   ct = cf;
15313                   cf = tmp;
15314                   compare_code = reverse_condition (compare_code);
15315                   code = reverse_condition (code);
15316                 }
15317               else
15318                 {
15319                   if (fpcmp)
15320                     PUT_CODE (compare_op,
15321                               reverse_condition_maybe_unordered
15322                                 (GET_CODE (compare_op)));
15323                   else
15324                     PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
15325                 }
15326               diff = ct - cf;
15327
15328               if (reg_overlap_mentioned_p (out, ix86_compare_op0)
15329                   || reg_overlap_mentioned_p (out, ix86_compare_op1))
15330                 tmp = gen_reg_rtx (mode);
15331
15332               if (mode == DImode)
15333                 emit_insn (gen_x86_movdicc_0_m1_rex64 (tmp, compare_op));
15334               else
15335                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp), compare_op));
15336             }
15337           else
15338             {
15339               if (code == GT || code == GE)
15340                 code = reverse_condition (code);
15341               else
15342                 {
15343                   HOST_WIDE_INT tmp = ct;
15344                   ct = cf;
15345                   cf = tmp;
15346                   diff = ct - cf;
15347                 }
15348               tmp = emit_store_flag (tmp, code, ix86_compare_op0,
15349                                      ix86_compare_op1, VOIDmode, 0, -1);
15350             }
15351
15352           if (diff == 1)
15353             {
15354               /*
15355                * cmpl op0,op1
15356                * sbbl dest,dest
15357                * [addl dest, ct]
15358                *
15359                * Size 5 - 8.
15360                */
15361               if (ct)
15362                 tmp = expand_simple_binop (mode, PLUS,
15363                                            tmp, GEN_INT (ct),
15364                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
15365             }
15366           else if (cf == -1)
15367             {
15368               /*
15369                * cmpl op0,op1
15370                * sbbl dest,dest
15371                * orl $ct, dest
15372                *
15373                * Size 8.
15374                */
15375               tmp = expand_simple_binop (mode, IOR,
15376                                          tmp, GEN_INT (ct),
15377                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
15378             }
15379           else if (diff == -1 && ct)
15380             {
15381               /*
15382                * cmpl op0,op1
15383                * sbbl dest,dest
15384                * notl dest
15385                * [addl dest, cf]
15386                *
15387                * Size 8 - 11.
15388                */
15389               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
15390               if (cf)
15391                 tmp = expand_simple_binop (mode, PLUS,
15392                                            copy_rtx (tmp), GEN_INT (cf),
15393                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
15394             }
15395           else
15396             {
15397               /*
15398                * cmpl op0,op1
15399                * sbbl dest,dest
15400                * [notl dest]
15401                * andl cf - ct, dest
15402                * [addl dest, ct]
15403                *
15404                * Size 8 - 11.
15405                */
15406
15407               if (cf == 0)
15408                 {
15409                   cf = ct;
15410                   ct = 0;
15411                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
15412                 }
15413
15414               tmp = expand_simple_binop (mode, AND,
15415                                          copy_rtx (tmp),
15416                                          gen_int_mode (cf - ct, mode),
15417                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
15418               if (ct)
15419                 tmp = expand_simple_binop (mode, PLUS,
15420                                            copy_rtx (tmp), GEN_INT (ct),
15421                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
15422             }
15423
15424           if (!rtx_equal_p (tmp, out))
15425             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
15426
15427           return 1; /* DONE */
15428         }
15429
15430       if (diff < 0)
15431         {
15432           enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
15433
15434           HOST_WIDE_INT tmp;
15435           tmp = ct, ct = cf, cf = tmp;
15436           diff = -diff;
15437
15438           if (SCALAR_FLOAT_MODE_P (cmp_mode))
15439             {
15440               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
15441
15442               /* We may be reversing unordered compare to normal compare, that
15443                  is not valid in general (we may convert non-trapping condition
15444                  to trapping one), however on i386 we currently emit all
15445                  comparisons unordered.  */
15446               compare_code = reverse_condition_maybe_unordered (compare_code);
15447               code = reverse_condition_maybe_unordered (code);
15448             }
15449           else
15450             {
15451               compare_code = reverse_condition (compare_code);
15452               code = reverse_condition (code);
15453             }
15454         }
15455
15456       compare_code = UNKNOWN;
15457       if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_INT
15458           && CONST_INT_P (ix86_compare_op1))
15459         {
15460           if (ix86_compare_op1 == const0_rtx
15461               && (code == LT || code == GE))
15462             compare_code = code;
15463           else if (ix86_compare_op1 == constm1_rtx)
15464             {
15465               if (code == LE)
15466                 compare_code = LT;
15467               else if (code == GT)
15468                 compare_code = GE;
15469             }
15470         }
15471
15472       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
15473       if (compare_code != UNKNOWN
15474           && GET_MODE (ix86_compare_op0) == GET_MODE (out)
15475           && (cf == -1 || ct == -1))
15476         {
15477           /* If lea code below could be used, only optimize
15478              if it results in a 2 insn sequence.  */
15479
15480           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
15481                  || diff == 3 || diff == 5 || diff == 9)
15482               || (compare_code == LT && ct == -1)
15483               || (compare_code == GE && cf == -1))
15484             {
15485               /*
15486                * notl op1       (if necessary)
15487                * sarl $31, op1
15488                * orl cf, op1
15489                */
15490               if (ct != -1)
15491                 {
15492                   cf = ct;
15493                   ct = -1;
15494                   code = reverse_condition (code);
15495                 }
15496
15497               out = emit_store_flag (out, code, ix86_compare_op0,
15498                                      ix86_compare_op1, VOIDmode, 0, -1);
15499
15500               out = expand_simple_binop (mode, IOR,
15501                                          out, GEN_INT (cf),
15502                                          out, 1, OPTAB_DIRECT);
15503               if (out != operands[0])
15504                 emit_move_insn (operands[0], out);
15505
15506               return 1; /* DONE */
15507             }
15508         }
15509
15510
15511       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
15512            || diff == 3 || diff == 5 || diff == 9)
15513           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
15514           && (mode != DImode
15515               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
15516         {
15517           /*
15518            * xorl dest,dest
15519            * cmpl op1,op2
15520            * setcc dest
15521            * lea cf(dest*(ct-cf)),dest
15522            *
15523            * Size 14.
15524            *
15525            * This also catches the degenerate setcc-only case.
15526            */
15527
15528           rtx tmp;
15529           int nops;
15530
15531           out = emit_store_flag (out, code, ix86_compare_op0,
15532                                  ix86_compare_op1, VOIDmode, 0, 1);
15533
15534           nops = 0;
15535           /* On x86_64 the lea instruction operates on Pmode, so we need
15536              to get arithmetics done in proper mode to match.  */
15537           if (diff == 1)
15538             tmp = copy_rtx (out);
15539           else
15540             {
15541               rtx out1;
15542               out1 = copy_rtx (out);
15543               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
15544               nops++;
15545               if (diff & 1)
15546                 {
15547                   tmp = gen_rtx_PLUS (mode, tmp, out1);
15548                   nops++;
15549                 }
15550             }
15551           if (cf != 0)
15552             {
15553               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
15554               nops++;
15555             }
15556           if (!rtx_equal_p (tmp, out))
15557             {
15558               if (nops == 1)
15559                 out = force_operand (tmp, copy_rtx (out));
15560               else
15561                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
15562             }
15563           if (!rtx_equal_p (out, operands[0]))
15564             emit_move_insn (operands[0], copy_rtx (out));
15565
15566           return 1; /* DONE */
15567         }
15568
15569       /*
15570        * General case:                  Jumpful:
15571        *   xorl dest,dest               cmpl op1, op2
15572        *   cmpl op1, op2                movl ct, dest
15573        *   setcc dest                   jcc 1f
15574        *   decl dest                    movl cf, dest
15575        *   andl (cf-ct),dest            1:
15576        *   addl ct,dest
15577        *
15578        * Size 20.                       Size 14.
15579        *
15580        * This is reasonably steep, but branch mispredict costs are
15581        * high on modern cpus, so consider failing only if optimizing
15582        * for space.
15583        */
15584
15585       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
15586           && BRANCH_COST (optimize_insn_for_speed_p (),
15587                           false) >= 2)
15588         {
15589           if (cf == 0)
15590             {
15591               enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
15592
15593               cf = ct;
15594               ct = 0;
15595
15596               if (SCALAR_FLOAT_MODE_P (cmp_mode))
15597                 {
15598                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
15599
15600                   /* We may be reversing unordered compare to normal compare,
15601                      that is not valid in general (we may convert non-trapping
15602                      condition to trapping one), however on i386 we currently
15603                      emit all comparisons unordered.  */
15604                   code = reverse_condition_maybe_unordered (code);
15605                 }
15606               else
15607                 {
15608                   code = reverse_condition (code);
15609                   if (compare_code != UNKNOWN)
15610                     compare_code = reverse_condition (compare_code);
15611                 }
15612             }
15613
15614           if (compare_code != UNKNOWN)
15615             {
15616               /* notl op1       (if needed)
15617                  sarl $31, op1
15618                  andl (cf-ct), op1
15619                  addl ct, op1
15620
15621                  For x < 0 (resp. x <= -1) there will be no notl,
15622                  so if possible swap the constants to get rid of the
15623                  complement.
15624                  True/false will be -1/0 while code below (store flag
15625                  followed by decrement) is 0/-1, so the constants need
15626                  to be exchanged once more.  */
15627
15628               if (compare_code == GE || !cf)
15629                 {
15630                   code = reverse_condition (code);
15631                   compare_code = LT;
15632                 }
15633               else
15634                 {
15635                   HOST_WIDE_INT tmp = cf;
15636                   cf = ct;
15637                   ct = tmp;
15638                 }
15639
15640               out = emit_store_flag (out, code, ix86_compare_op0,
15641                                      ix86_compare_op1, VOIDmode, 0, -1);
15642             }
15643           else
15644             {
15645               out = emit_store_flag (out, code, ix86_compare_op0,
15646                                      ix86_compare_op1, VOIDmode, 0, 1);
15647
15648               out = expand_simple_binop (mode, PLUS, copy_rtx (out), constm1_rtx,
15649                                          copy_rtx (out), 1, OPTAB_DIRECT);
15650             }
15651
15652           out = expand_simple_binop (mode, AND, copy_rtx (out),
15653                                      gen_int_mode (cf - ct, mode),
15654                                      copy_rtx (out), 1, OPTAB_DIRECT);
15655           if (ct)
15656             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
15657                                        copy_rtx (out), 1, OPTAB_DIRECT);
15658           if (!rtx_equal_p (out, operands[0]))
15659             emit_move_insn (operands[0], copy_rtx (out));
15660
15661           return 1; /* DONE */
15662         }
15663     }
15664
15665   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
15666     {
15667       /* Try a few things more with specific constants and a variable.  */
15668
15669       optab op;
15670       rtx var, orig_out, out, tmp;
15671
15672       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
15673         return 0; /* FAIL */
15674
15675       /* If one of the two operands is an interesting constant, load a
15676          constant with the above and mask it in with a logical operation.  */
15677
15678       if (CONST_INT_P (operands[2]))
15679         {
15680           var = operands[3];
15681           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
15682             operands[3] = constm1_rtx, op = and_optab;
15683           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
15684             operands[3] = const0_rtx, op = ior_optab;
15685           else
15686             return 0; /* FAIL */
15687         }
15688       else if (CONST_INT_P (operands[3]))
15689         {
15690           var = operands[2];
15691           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
15692             operands[2] = constm1_rtx, op = and_optab;
15693           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
15694             operands[2] = const0_rtx, op = ior_optab;
15695           else
15696             return 0; /* FAIL */
15697         }
15698       else
15699         return 0; /* FAIL */
15700
15701       orig_out = operands[0];
15702       tmp = gen_reg_rtx (mode);
15703       operands[0] = tmp;
15704
15705       /* Recurse to get the constant loaded.  */
15706       if (ix86_expand_int_movcc (operands) == 0)
15707         return 0; /* FAIL */
15708
15709       /* Mask in the interesting variable.  */
15710       out = expand_binop (mode, op, var, tmp, orig_out, 0,
15711                           OPTAB_WIDEN);
15712       if (!rtx_equal_p (out, orig_out))
15713         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
15714
15715       return 1; /* DONE */
15716     }
15717
15718   /*
15719    * For comparison with above,
15720    *
15721    * movl cf,dest
15722    * movl ct,tmp
15723    * cmpl op1,op2
15724    * cmovcc tmp,dest
15725    *
15726    * Size 15.
15727    */
15728
15729   if (! nonimmediate_operand (operands[2], mode))
15730     operands[2] = force_reg (mode, operands[2]);
15731   if (! nonimmediate_operand (operands[3], mode))
15732     operands[3] = force_reg (mode, operands[3]);
15733
15734   if (! register_operand (operands[2], VOIDmode)
15735       && (mode == QImode
15736           || ! register_operand (operands[3], VOIDmode)))
15737     operands[2] = force_reg (mode, operands[2]);
15738
15739   if (mode == QImode
15740       && ! register_operand (operands[3], VOIDmode))
15741     operands[3] = force_reg (mode, operands[3]);
15742
15743   emit_insn (compare_seq);
15744   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15745                           gen_rtx_IF_THEN_ELSE (mode,
15746                                                 compare_op, operands[2],
15747                                                 operands[3])));
15748
15749   return 1; /* DONE */
15750 }
15751
15752 /* Swap, force into registers, or otherwise massage the two operands
15753    to an sse comparison with a mask result.  Thus we differ a bit from
15754    ix86_prepare_fp_compare_args which expects to produce a flags result.
15755
15756    The DEST operand exists to help determine whether to commute commutative
15757    operators.  The POP0/POP1 operands are updated in place.  The new
15758    comparison code is returned, or UNKNOWN if not implementable.  */
15759
15760 static enum rtx_code
15761 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
15762                                   rtx *pop0, rtx *pop1)
15763 {
15764   rtx tmp;
15765
15766   switch (code)
15767     {
15768     case LTGT:
15769     case UNEQ:
15770       /* We have no LTGT as an operator.  We could implement it with
15771          NE & ORDERED, but this requires an extra temporary.  It's
15772          not clear that it's worth it.  */
15773       return UNKNOWN;
15774
15775     case LT:
15776     case LE:
15777     case UNGT:
15778     case UNGE:
15779       /* These are supported directly.  */
15780       break;
15781
15782     case EQ:
15783     case NE:
15784     case UNORDERED:
15785     case ORDERED:
15786       /* For commutative operators, try to canonicalize the destination
15787          operand to be first in the comparison - this helps reload to
15788          avoid extra moves.  */
15789       if (!dest || !rtx_equal_p (dest, *pop1))
15790         break;
15791       /* FALLTHRU */
15792
15793     case GE:
15794     case GT:
15795     case UNLE:
15796     case UNLT:
15797       /* These are not supported directly.  Swap the comparison operands
15798          to transform into something that is supported.  */
15799       tmp = *pop0;
15800       *pop0 = *pop1;
15801       *pop1 = tmp;
15802       code = swap_condition (code);
15803       break;
15804
15805     default:
15806       gcc_unreachable ();
15807     }
15808
15809   return code;
15810 }
15811
15812 /* Detect conditional moves that exactly match min/max operational
15813    semantics.  Note that this is IEEE safe, as long as we don't
15814    interchange the operands.
15815
15816    Returns FALSE if this conditional move doesn't match a MIN/MAX,
15817    and TRUE if the operation is successful and instructions are emitted.  */
15818
15819 static bool
15820 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
15821                            rtx cmp_op1, rtx if_true, rtx if_false)
15822 {
15823   enum machine_mode mode;
15824   bool is_min;
15825   rtx tmp;
15826
15827   if (code == LT)
15828     ;
15829   else if (code == UNGE)
15830     {
15831       tmp = if_true;
15832       if_true = if_false;
15833       if_false = tmp;
15834     }
15835   else
15836     return false;
15837
15838   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
15839     is_min = true;
15840   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
15841     is_min = false;
15842   else
15843     return false;
15844
15845   mode = GET_MODE (dest);
15846
15847   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
15848      but MODE may be a vector mode and thus not appropriate.  */
15849   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
15850     {
15851       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
15852       rtvec v;
15853
15854       if_true = force_reg (mode, if_true);
15855       v = gen_rtvec (2, if_true, if_false);
15856       tmp = gen_rtx_UNSPEC (mode, v, u);
15857     }
15858   else
15859     {
15860       code = is_min ? SMIN : SMAX;
15861       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
15862     }
15863
15864   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
15865   return true;
15866 }
15867
15868 /* Expand an sse vector comparison.  Return the register with the result.  */
15869
15870 static rtx
15871 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
15872                      rtx op_true, rtx op_false)
15873 {
15874   enum machine_mode mode = GET_MODE (dest);
15875   rtx x;
15876
15877   cmp_op0 = force_reg (mode, cmp_op0);
15878   if (!nonimmediate_operand (cmp_op1, mode))
15879     cmp_op1 = force_reg (mode, cmp_op1);
15880
15881   if (optimize
15882       || reg_overlap_mentioned_p (dest, op_true)
15883       || reg_overlap_mentioned_p (dest, op_false))
15884     dest = gen_reg_rtx (mode);
15885
15886   x = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
15887   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15888
15889   return dest;
15890 }
15891
15892 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
15893    operations.  This is used for both scalar and vector conditional moves.  */
15894
15895 static void
15896 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
15897 {
15898   enum machine_mode mode = GET_MODE (dest);
15899   rtx t2, t3, x;
15900
15901   if (op_false == CONST0_RTX (mode))
15902     {
15903       op_true = force_reg (mode, op_true);
15904       x = gen_rtx_AND (mode, cmp, op_true);
15905       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15906     }
15907   else if (op_true == CONST0_RTX (mode))
15908     {
15909       op_false = force_reg (mode, op_false);
15910       x = gen_rtx_NOT (mode, cmp);
15911       x = gen_rtx_AND (mode, x, op_false);
15912       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15913     }
15914   else if (TARGET_SSE5)
15915     {
15916       rtx pcmov = gen_rtx_SET (mode, dest,
15917                                gen_rtx_IF_THEN_ELSE (mode, cmp,
15918                                                      op_true,
15919                                                      op_false));
15920       emit_insn (pcmov);
15921     }
15922   else
15923     {
15924       op_true = force_reg (mode, op_true);
15925       op_false = force_reg (mode, op_false);
15926
15927       t2 = gen_reg_rtx (mode);
15928       if (optimize)
15929         t3 = gen_reg_rtx (mode);
15930       else
15931         t3 = dest;
15932
15933       x = gen_rtx_AND (mode, op_true, cmp);
15934       emit_insn (gen_rtx_SET (VOIDmode, t2, x));
15935
15936       x = gen_rtx_NOT (mode, cmp);
15937       x = gen_rtx_AND (mode, x, op_false);
15938       emit_insn (gen_rtx_SET (VOIDmode, t3, x));
15939
15940       x = gen_rtx_IOR (mode, t3, t2);
15941       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15942     }
15943 }
15944
15945 /* Expand a floating-point conditional move.  Return true if successful.  */
15946
15947 int
15948 ix86_expand_fp_movcc (rtx operands[])
15949 {
15950   enum machine_mode mode = GET_MODE (operands[0]);
15951   enum rtx_code code = GET_CODE (operands[1]);
15952   rtx tmp, compare_op;
15953
15954   ix86_compare_op0 = XEXP (operands[1], 0);
15955   ix86_compare_op1 = XEXP (operands[1], 1);
15956   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
15957     {
15958       enum machine_mode cmode;
15959
15960       /* Since we've no cmove for sse registers, don't force bad register
15961          allocation just to gain access to it.  Deny movcc when the
15962          comparison mode doesn't match the move mode.  */
15963       cmode = GET_MODE (ix86_compare_op0);
15964       if (cmode == VOIDmode)
15965         cmode = GET_MODE (ix86_compare_op1);
15966       if (cmode != mode)
15967         return 0;
15968
15969       code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15970                                                &ix86_compare_op0,
15971                                                &ix86_compare_op1);
15972       if (code == UNKNOWN)
15973         return 0;
15974
15975       if (ix86_expand_sse_fp_minmax (operands[0], code, ix86_compare_op0,
15976                                      ix86_compare_op1, operands[2],
15977                                      operands[3]))
15978         return 1;
15979
15980       tmp = ix86_expand_sse_cmp (operands[0], code, ix86_compare_op0,
15981                                  ix86_compare_op1, operands[2], operands[3]);
15982       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
15983       return 1;
15984     }
15985
15986   /* The floating point conditional move instructions don't directly
15987      support conditions resulting from a signed integer comparison.  */
15988
15989   compare_op = ix86_expand_compare (code);
15990   if (!fcmov_comparison_operator (compare_op, VOIDmode))
15991     {
15992       tmp = gen_reg_rtx (QImode);
15993       ix86_expand_setcc (code, tmp);
15994       code = NE;
15995       ix86_compare_op0 = tmp;
15996       ix86_compare_op1 = const0_rtx;
15997       compare_op = ix86_expand_compare (code);
15998     }
15999
16000   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
16001                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
16002                                                 operands[2], operands[3])));
16003
16004   return 1;
16005 }
16006
16007 /* Expand a floating-point vector conditional move; a vcond operation
16008    rather than a movcc operation.  */
16009
16010 bool
16011 ix86_expand_fp_vcond (rtx operands[])
16012 {
16013   enum rtx_code code = GET_CODE (operands[3]);
16014   rtx cmp;
16015
16016   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
16017                                            &operands[4], &operands[5]);
16018   if (code == UNKNOWN)
16019     return false;
16020
16021   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
16022                                  operands[5], operands[1], operands[2]))
16023     return true;
16024
16025   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
16026                              operands[1], operands[2]);
16027   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
16028   return true;
16029 }
16030
16031 /* Expand a signed/unsigned integral vector conditional move.  */
16032
16033 bool
16034 ix86_expand_int_vcond (rtx operands[])
16035 {
16036   enum machine_mode mode = GET_MODE (operands[0]);
16037   enum rtx_code code = GET_CODE (operands[3]);
16038   bool negate = false;
16039   rtx x, cop0, cop1;
16040
16041   cop0 = operands[4];
16042   cop1 = operands[5];
16043
16044   /* SSE5 supports all of the comparisons on all vector int types.  */
16045   if (!TARGET_SSE5)
16046     {
16047       /* Canonicalize the comparison to EQ, GT, GTU.  */
16048       switch (code)
16049         {
16050         case EQ:
16051         case GT:
16052         case GTU:
16053           break;
16054
16055         case NE:
16056         case LE:
16057         case LEU:
16058           code = reverse_condition (code);
16059           negate = true;
16060           break;
16061
16062         case GE:
16063         case GEU:
16064           code = reverse_condition (code);
16065           negate = true;
16066           /* FALLTHRU */
16067
16068         case LT:
16069         case LTU:
16070           code = swap_condition (code);
16071           x = cop0, cop0 = cop1, cop1 = x;
16072           break;
16073
16074         default:
16075           gcc_unreachable ();
16076         }
16077
16078       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
16079       if (mode == V2DImode)
16080         {
16081           switch (code)
16082             {
16083             case EQ:
16084               /* SSE4.1 supports EQ.  */
16085               if (!TARGET_SSE4_1)
16086                 return false;
16087               break;
16088
16089             case GT:
16090             case GTU:
16091               /* SSE4.2 supports GT/GTU.  */
16092               if (!TARGET_SSE4_2)
16093                 return false;
16094               break;
16095
16096             default:
16097               gcc_unreachable ();
16098             }
16099         }
16100
16101       /* Unsigned parallel compare is not supported by the hardware.  Play some
16102          tricks to turn this into a signed comparison against 0.  */
16103       if (code == GTU)
16104         {
16105           cop0 = force_reg (mode, cop0);
16106
16107           switch (mode)
16108             {
16109             case V4SImode:
16110             case V2DImode:
16111               {
16112                 rtx t1, t2, mask;
16113
16114                 /* Perform a parallel modulo subtraction.  */
16115                 t1 = gen_reg_rtx (mode);
16116                 emit_insn ((mode == V4SImode
16117                             ? gen_subv4si3
16118                             : gen_subv2di3) (t1, cop0, cop1));
16119
16120                 /* Extract the original sign bit of op0.  */
16121                 mask = ix86_build_signbit_mask (GET_MODE_INNER (mode),
16122                                                 true, false);
16123                 t2 = gen_reg_rtx (mode);
16124                 emit_insn ((mode == V4SImode
16125                             ? gen_andv4si3
16126                             : gen_andv2di3) (t2, cop0, mask));
16127
16128                 /* XOR it back into the result of the subtraction.  This results
16129                    in the sign bit set iff we saw unsigned underflow.  */
16130                 x = gen_reg_rtx (mode);
16131                 emit_insn ((mode == V4SImode
16132                             ? gen_xorv4si3
16133                             : gen_xorv2di3) (x, t1, t2));
16134
16135                 code = GT;
16136               }
16137               break;
16138
16139             case V16QImode:
16140             case V8HImode:
16141               /* Perform a parallel unsigned saturating subtraction.  */
16142               x = gen_reg_rtx (mode);
16143               emit_insn (gen_rtx_SET (VOIDmode, x,
16144                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
16145
16146               code = EQ;
16147               negate = !negate;
16148               break;
16149
16150             default:
16151               gcc_unreachable ();
16152             }
16153
16154           cop0 = x;
16155           cop1 = CONST0_RTX (mode);
16156         }
16157     }
16158
16159   x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
16160                            operands[1+negate], operands[2-negate]);
16161
16162   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
16163                          operands[2-negate]);
16164   return true;
16165 }
16166
16167 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
16168    true if we should do zero extension, else sign extension.  HIGH_P is
16169    true if we want the N/2 high elements, else the low elements.  */
16170
16171 void
16172 ix86_expand_sse_unpack (rtx operands[2], bool unsigned_p, bool high_p)
16173 {
16174   enum machine_mode imode = GET_MODE (operands[1]);
16175   rtx (*unpack)(rtx, rtx, rtx);
16176   rtx se, dest;
16177
16178   switch (imode)
16179     {
16180     case V16QImode:
16181       if (high_p)
16182         unpack = gen_vec_interleave_highv16qi;
16183       else
16184         unpack = gen_vec_interleave_lowv16qi;
16185       break;
16186     case V8HImode:
16187       if (high_p)
16188         unpack = gen_vec_interleave_highv8hi;
16189       else
16190         unpack = gen_vec_interleave_lowv8hi;
16191       break;
16192     case V4SImode:
16193       if (high_p)
16194         unpack = gen_vec_interleave_highv4si;
16195       else
16196         unpack = gen_vec_interleave_lowv4si;
16197       break;
16198     default:
16199       gcc_unreachable ();
16200     }
16201
16202   dest = gen_lowpart (imode, operands[0]);
16203
16204   if (unsigned_p)
16205     se = force_reg (imode, CONST0_RTX (imode));
16206   else
16207     se = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
16208                               operands[1], pc_rtx, pc_rtx);
16209
16210   emit_insn (unpack (dest, operands[1], se));
16211 }
16212
16213 /* This function performs the same task as ix86_expand_sse_unpack,
16214    but with SSE4.1 instructions.  */
16215
16216 void
16217 ix86_expand_sse4_unpack (rtx operands[2], bool unsigned_p, bool high_p)
16218 {
16219   enum machine_mode imode = GET_MODE (operands[1]);
16220   rtx (*unpack)(rtx, rtx);
16221   rtx src, dest;
16222
16223   switch (imode)
16224     {
16225     case V16QImode:
16226       if (unsigned_p)
16227         unpack = gen_sse4_1_zero_extendv8qiv8hi2;
16228       else
16229         unpack = gen_sse4_1_extendv8qiv8hi2;
16230       break;
16231     case V8HImode:
16232       if (unsigned_p)
16233         unpack = gen_sse4_1_zero_extendv4hiv4si2;
16234       else
16235         unpack = gen_sse4_1_extendv4hiv4si2;
16236       break;
16237     case V4SImode:
16238       if (unsigned_p)
16239         unpack = gen_sse4_1_zero_extendv2siv2di2;
16240       else
16241         unpack = gen_sse4_1_extendv2siv2di2;
16242       break;
16243     default:
16244       gcc_unreachable ();
16245     }
16246
16247   dest = operands[0];
16248   if (high_p)
16249     {
16250       /* Shift higher 8 bytes to lower 8 bytes.  */
16251       src = gen_reg_rtx (imode);
16252       emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, src),
16253                                    gen_lowpart (TImode, operands[1]),
16254                                    GEN_INT (64)));
16255     }
16256   else
16257     src = operands[1];
16258
16259   emit_insn (unpack (dest, src));
16260 }
16261
16262 /* This function performs the same task as ix86_expand_sse_unpack,
16263    but with sse5 instructions.  */
16264
16265 void
16266 ix86_expand_sse5_unpack (rtx operands[2], bool unsigned_p, bool high_p)
16267 {
16268   enum machine_mode imode = GET_MODE (operands[1]);
16269   int pperm_bytes[16];
16270   int i;
16271   int h = (high_p) ? 8 : 0;
16272   int h2;
16273   int sign_extend;
16274   rtvec v = rtvec_alloc (16);
16275   rtvec vs;
16276   rtx x, p;
16277   rtx op0 = operands[0], op1 = operands[1];
16278
16279   switch (imode)
16280     {
16281     case V16QImode:
16282       vs = rtvec_alloc (8);
16283       h2 = (high_p) ? 8 : 0;
16284       for (i = 0; i < 8; i++)
16285         {
16286           pperm_bytes[2*i+0] = PPERM_SRC | PPERM_SRC2 | i | h;
16287           pperm_bytes[2*i+1] = ((unsigned_p)
16288                                 ? PPERM_ZERO
16289                                 : PPERM_SIGN | PPERM_SRC2 | i | h);
16290         }
16291
16292       for (i = 0; i < 16; i++)
16293         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
16294
16295       for (i = 0; i < 8; i++)
16296         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
16297
16298       p = gen_rtx_PARALLEL (VOIDmode, vs);
16299       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
16300       if (unsigned_p)
16301         emit_insn (gen_sse5_pperm_zero_v16qi_v8hi (op0, op1, p, x));
16302       else
16303         emit_insn (gen_sse5_pperm_sign_v16qi_v8hi (op0, op1, p, x));
16304       break;
16305
16306     case V8HImode:
16307       vs = rtvec_alloc (4);
16308       h2 = (high_p) ? 4 : 0;
16309       for (i = 0; i < 4; i++)
16310         {
16311           sign_extend = ((unsigned_p)
16312                          ? PPERM_ZERO
16313                          : PPERM_SIGN | PPERM_SRC2 | ((2*i) + 1 + h));
16314           pperm_bytes[4*i+0] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 0 + h);
16315           pperm_bytes[4*i+1] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 1 + h);
16316           pperm_bytes[4*i+2] = sign_extend;
16317           pperm_bytes[4*i+3] = sign_extend;
16318         }
16319
16320       for (i = 0; i < 16; i++)
16321         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
16322
16323       for (i = 0; i < 4; i++)
16324         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
16325
16326       p = gen_rtx_PARALLEL (VOIDmode, vs);
16327       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
16328       if (unsigned_p)
16329         emit_insn (gen_sse5_pperm_zero_v8hi_v4si (op0, op1, p, x));
16330       else
16331         emit_insn (gen_sse5_pperm_sign_v8hi_v4si (op0, op1, p, x));
16332       break;
16333
16334     case V4SImode:
16335       vs = rtvec_alloc (2);
16336       h2 = (high_p) ? 2 : 0;
16337       for (i = 0; i < 2; i++)
16338         {
16339           sign_extend = ((unsigned_p)
16340                          ? PPERM_ZERO
16341                          : PPERM_SIGN | PPERM_SRC2 | ((4*i) + 3 + h));
16342           pperm_bytes[8*i+0] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 0 + h);
16343           pperm_bytes[8*i+1] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 1 + h);
16344           pperm_bytes[8*i+2] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 2 + h);
16345           pperm_bytes[8*i+3] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 3 + h);
16346           pperm_bytes[8*i+4] = sign_extend;
16347           pperm_bytes[8*i+5] = sign_extend;
16348           pperm_bytes[8*i+6] = sign_extend;
16349           pperm_bytes[8*i+7] = sign_extend;
16350         }
16351
16352       for (i = 0; i < 16; i++)
16353         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
16354
16355       for (i = 0; i < 2; i++)
16356         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
16357
16358       p = gen_rtx_PARALLEL (VOIDmode, vs);
16359       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
16360       if (unsigned_p)
16361         emit_insn (gen_sse5_pperm_zero_v4si_v2di (op0, op1, p, x));
16362       else
16363         emit_insn (gen_sse5_pperm_sign_v4si_v2di (op0, op1, p, x));
16364       break;
16365
16366     default:
16367       gcc_unreachable ();
16368     }
16369
16370   return;
16371 }
16372
16373 /* Pack the high bits from OPERANDS[1] and low bits from OPERANDS[2] into the
16374    next narrower integer vector type */
16375 void
16376 ix86_expand_sse5_pack (rtx operands[3])
16377 {
16378   enum machine_mode imode = GET_MODE (operands[0]);
16379   int pperm_bytes[16];
16380   int i;
16381   rtvec v = rtvec_alloc (16);
16382   rtx x;
16383   rtx op0 = operands[0];
16384   rtx op1 = operands[1];
16385   rtx op2 = operands[2];
16386
16387   switch (imode)
16388     {
16389     case V16QImode:
16390       for (i = 0; i < 8; i++)
16391         {
16392           pperm_bytes[i+0] = PPERM_SRC | PPERM_SRC1 | (i*2);
16393           pperm_bytes[i+8] = PPERM_SRC | PPERM_SRC2 | (i*2);
16394         }
16395
16396       for (i = 0; i < 16; i++)
16397         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
16398
16399       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
16400       emit_insn (gen_sse5_pperm_pack_v8hi_v16qi (op0, op1, op2, x));
16401       break;
16402
16403     case V8HImode:
16404       for (i = 0; i < 4; i++)
16405         {
16406           pperm_bytes[(2*i)+0] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 0);
16407           pperm_bytes[(2*i)+1] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 1);
16408           pperm_bytes[(2*i)+8] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 0);
16409           pperm_bytes[(2*i)+9] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 1);
16410         }
16411
16412       for (i = 0; i < 16; i++)
16413         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
16414
16415       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
16416       emit_insn (gen_sse5_pperm_pack_v4si_v8hi (op0, op1, op2, x));
16417       break;
16418
16419     case V4SImode:
16420       for (i = 0; i < 2; i++)
16421         {
16422           pperm_bytes[(4*i)+0]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 0);
16423           pperm_bytes[(4*i)+1]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 1);
16424           pperm_bytes[(4*i)+2]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 2);
16425           pperm_bytes[(4*i)+3]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 3);
16426           pperm_bytes[(4*i)+8]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 0);
16427           pperm_bytes[(4*i)+9]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 1);
16428           pperm_bytes[(4*i)+10] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 2);
16429           pperm_bytes[(4*i)+11] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 3);
16430         }
16431
16432       for (i = 0; i < 16; i++)
16433         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
16434
16435       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
16436       emit_insn (gen_sse5_pperm_pack_v2di_v4si (op0, op1, op2, x));
16437       break;
16438
16439     default:
16440       gcc_unreachable ();
16441     }
16442
16443   return;
16444 }
16445
16446 /* Expand conditional increment or decrement using adb/sbb instructions.
16447    The default case using setcc followed by the conditional move can be
16448    done by generic code.  */
16449 int
16450 ix86_expand_int_addcc (rtx operands[])
16451 {
16452   enum rtx_code code = GET_CODE (operands[1]);
16453   rtx compare_op;
16454   rtx val = const0_rtx;
16455   bool fpcmp = false;
16456   enum machine_mode mode = GET_MODE (operands[0]);
16457
16458   ix86_compare_op0 = XEXP (operands[1], 0);
16459   ix86_compare_op1 = XEXP (operands[1], 1);
16460   if (operands[3] != const1_rtx
16461       && operands[3] != constm1_rtx)
16462     return 0;
16463   if (!ix86_expand_carry_flag_compare (code, ix86_compare_op0,
16464                                        ix86_compare_op1, &compare_op))
16465      return 0;
16466   code = GET_CODE (compare_op);
16467
16468   if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
16469       || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
16470     {
16471       fpcmp = true;
16472       code = ix86_fp_compare_code_to_integer (code);
16473     }
16474
16475   if (code != LTU)
16476     {
16477       val = constm1_rtx;
16478       if (fpcmp)
16479         PUT_CODE (compare_op,
16480                   reverse_condition_maybe_unordered
16481                     (GET_CODE (compare_op)));
16482       else
16483         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
16484     }
16485   PUT_MODE (compare_op, mode);
16486
16487   /* Construct either adc or sbb insn.  */
16488   if ((code == LTU) == (operands[3] == constm1_rtx))
16489     {
16490       switch (GET_MODE (operands[0]))
16491         {
16492           case QImode:
16493             emit_insn (gen_subqi3_carry (operands[0], operands[2], val, compare_op));
16494             break;
16495           case HImode:
16496             emit_insn (gen_subhi3_carry (operands[0], operands[2], val, compare_op));
16497             break;
16498           case SImode:
16499             emit_insn (gen_subsi3_carry (operands[0], operands[2], val, compare_op));
16500             break;
16501           case DImode:
16502             emit_insn (gen_subdi3_carry_rex64 (operands[0], operands[2], val, compare_op));
16503             break;
16504           default:
16505             gcc_unreachable ();
16506         }
16507     }
16508   else
16509     {
16510       switch (GET_MODE (operands[0]))
16511         {
16512           case QImode:
16513             emit_insn (gen_addqi3_carry (operands[0], operands[2], val, compare_op));
16514             break;
16515           case HImode:
16516             emit_insn (gen_addhi3_carry (operands[0], operands[2], val, compare_op));
16517             break;
16518           case SImode:
16519             emit_insn (gen_addsi3_carry (operands[0], operands[2], val, compare_op));
16520             break;
16521           case DImode:
16522             emit_insn (gen_adddi3_carry_rex64 (operands[0], operands[2], val, compare_op));
16523             break;
16524           default:
16525             gcc_unreachable ();
16526         }
16527     }
16528   return 1; /* DONE */
16529 }
16530
16531
16532 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
16533    works for floating pointer parameters and nonoffsetable memories.
16534    For pushes, it returns just stack offsets; the values will be saved
16535    in the right order.  Maximally three parts are generated.  */
16536
16537 static int
16538 ix86_split_to_parts (rtx operand, rtx *parts, enum machine_mode mode)
16539 {
16540   int size;
16541
16542   if (!TARGET_64BIT)
16543     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
16544   else
16545     size = (GET_MODE_SIZE (mode) + 4) / 8;
16546
16547   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
16548   gcc_assert (size >= 2 && size <= 4);
16549
16550   /* Optimize constant pool reference to immediates.  This is used by fp
16551      moves, that force all constants to memory to allow combining.  */
16552   if (MEM_P (operand) && MEM_READONLY_P (operand))
16553     {
16554       rtx tmp = maybe_get_pool_constant (operand);
16555       if (tmp)
16556         operand = tmp;
16557     }
16558
16559   if (MEM_P (operand) && !offsettable_memref_p (operand))
16560     {
16561       /* The only non-offsetable memories we handle are pushes.  */
16562       int ok = push_operand (operand, VOIDmode);
16563
16564       gcc_assert (ok);
16565
16566       operand = copy_rtx (operand);
16567       PUT_MODE (operand, Pmode);
16568       parts[0] = parts[1] = parts[2] = parts[3] = operand;
16569       return size;
16570     }
16571
16572   if (GET_CODE (operand) == CONST_VECTOR)
16573     {
16574       enum machine_mode imode = int_mode_for_mode (mode);
16575       /* Caution: if we looked through a constant pool memory above,
16576          the operand may actually have a different mode now.  That's
16577          ok, since we want to pun this all the way back to an integer.  */
16578       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
16579       gcc_assert (operand != NULL);
16580       mode = imode;
16581     }
16582
16583   if (!TARGET_64BIT)
16584     {
16585       if (mode == DImode)
16586         split_di (&operand, 1, &parts[0], &parts[1]);
16587       else
16588         {
16589           int i;
16590
16591           if (REG_P (operand))
16592             {
16593               gcc_assert (reload_completed);
16594               for (i = 0; i < size; i++)
16595                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
16596             }
16597           else if (offsettable_memref_p (operand))
16598             {
16599               operand = adjust_address (operand, SImode, 0);
16600               parts[0] = operand;
16601               for (i = 1; i < size; i++)
16602                 parts[i] = adjust_address (operand, SImode, 4 * i);
16603             }
16604           else if (GET_CODE (operand) == CONST_DOUBLE)
16605             {
16606               REAL_VALUE_TYPE r;
16607               long l[4];
16608
16609               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
16610               switch (mode)
16611                 {
16612                 case TFmode:
16613                   real_to_target (l, &r, mode);
16614                   parts[3] = gen_int_mode (l[3], SImode);
16615                   parts[2] = gen_int_mode (l[2], SImode);
16616                   break;
16617                 case XFmode:
16618                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
16619                   parts[2] = gen_int_mode (l[2], SImode);
16620                   break;
16621                 case DFmode:
16622                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
16623                   break;
16624                 default:
16625                   gcc_unreachable ();
16626                 }
16627               parts[1] = gen_int_mode (l[1], SImode);
16628               parts[0] = gen_int_mode (l[0], SImode);
16629             }
16630           else
16631             gcc_unreachable ();
16632         }
16633     }
16634   else
16635     {
16636       if (mode == TImode)
16637         split_ti (&operand, 1, &parts[0], &parts[1]);
16638       if (mode == XFmode || mode == TFmode)
16639         {
16640           enum machine_mode upper_mode = mode==XFmode ? SImode : DImode;
16641           if (REG_P (operand))
16642             {
16643               gcc_assert (reload_completed);
16644               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
16645               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
16646             }
16647           else if (offsettable_memref_p (operand))
16648             {
16649               operand = adjust_address (operand, DImode, 0);
16650               parts[0] = operand;
16651               parts[1] = adjust_address (operand, upper_mode, 8);
16652             }
16653           else if (GET_CODE (operand) == CONST_DOUBLE)
16654             {
16655               REAL_VALUE_TYPE r;
16656               long l[4];
16657
16658               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
16659               real_to_target (l, &r, mode);
16660
16661               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
16662               if (HOST_BITS_PER_WIDE_INT >= 64)
16663                 parts[0]
16664                   = gen_int_mode
16665                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
16666                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
16667                        DImode);
16668               else
16669                 parts[0] = immed_double_const (l[0], l[1], DImode);
16670
16671               if (upper_mode == SImode)
16672                 parts[1] = gen_int_mode (l[2], SImode);
16673               else if (HOST_BITS_PER_WIDE_INT >= 64)
16674                 parts[1]
16675                   = gen_int_mode
16676                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
16677                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
16678                        DImode);
16679               else
16680                 parts[1] = immed_double_const (l[2], l[3], DImode);
16681             }
16682           else
16683             gcc_unreachable ();
16684         }
16685     }
16686
16687   return size;
16688 }
16689
16690 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
16691    Return false when normal moves are needed; true when all required
16692    insns have been emitted.  Operands 2-4 contain the input values
16693    int the correct order; operands 5-7 contain the output values.  */
16694
16695 void
16696 ix86_split_long_move (rtx operands[])
16697 {
16698   rtx part[2][4];
16699   int nparts, i, j;
16700   int push = 0;
16701   int collisions = 0;
16702   enum machine_mode mode = GET_MODE (operands[0]);
16703   bool collisionparts[4];
16704
16705   /* The DFmode expanders may ask us to move double.
16706      For 64bit target this is single move.  By hiding the fact
16707      here we simplify i386.md splitters.  */
16708   if (GET_MODE_SIZE (GET_MODE (operands[0])) == 8 && TARGET_64BIT)
16709     {
16710       /* Optimize constant pool reference to immediates.  This is used by
16711          fp moves, that force all constants to memory to allow combining.  */
16712
16713       if (MEM_P (operands[1])
16714           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
16715           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
16716         operands[1] = get_pool_constant (XEXP (operands[1], 0));
16717       if (push_operand (operands[0], VOIDmode))
16718         {
16719           operands[0] = copy_rtx (operands[0]);
16720           PUT_MODE (operands[0], Pmode);
16721         }
16722       else
16723         operands[0] = gen_lowpart (DImode, operands[0]);
16724       operands[1] = gen_lowpart (DImode, operands[1]);
16725       emit_move_insn (operands[0], operands[1]);
16726       return;
16727     }
16728
16729   /* The only non-offsettable memory we handle is push.  */
16730   if (push_operand (operands[0], VOIDmode))
16731     push = 1;
16732   else
16733     gcc_assert (!MEM_P (operands[0])
16734                 || offsettable_memref_p (operands[0]));
16735
16736   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
16737   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
16738
16739   /* When emitting push, take care for source operands on the stack.  */
16740   if (push && MEM_P (operands[1])
16741       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
16742     {
16743       rtx src_base = XEXP (part[1][nparts - 1], 0);
16744
16745       /* Compensate for the stack decrement by 4.  */
16746       if (!TARGET_64BIT && nparts == 3
16747           && mode == XFmode && TARGET_128BIT_LONG_DOUBLE)
16748         src_base = plus_constant (src_base, 4);
16749
16750       /* src_base refers to the stack pointer and is
16751          automatically decreased by emitted push.  */
16752       for (i = 0; i < nparts; i++)
16753         part[1][i] = change_address (part[1][i],
16754                                      GET_MODE (part[1][i]), src_base);
16755     }
16756
16757   /* We need to do copy in the right order in case an address register
16758      of the source overlaps the destination.  */
16759   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
16760     {
16761       rtx tmp;
16762
16763       for (i = 0; i < nparts; i++)
16764         {
16765           collisionparts[i]
16766             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
16767           if (collisionparts[i])
16768             collisions++;
16769         }
16770
16771       /* Collision in the middle part can be handled by reordering.  */
16772       if (collisions == 1 && nparts == 3 && collisionparts [1])
16773         {
16774           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
16775           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
16776         }
16777       else if (collisions == 1
16778                && nparts == 4
16779                && (collisionparts [1] || collisionparts [2]))
16780         {
16781           if (collisionparts [1])
16782             {
16783               tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
16784               tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
16785             }
16786           else
16787             {
16788               tmp = part[0][2]; part[0][2] = part[0][3]; part[0][3] = tmp;
16789               tmp = part[1][2]; part[1][2] = part[1][3]; part[1][3] = tmp;
16790             }
16791         }
16792
16793       /* If there are more collisions, we can't handle it by reordering.
16794          Do an lea to the last part and use only one colliding move.  */
16795       else if (collisions > 1)
16796         {
16797           rtx base;
16798
16799           collisions = 1;
16800
16801           base = part[0][nparts - 1];
16802
16803           /* Handle the case when the last part isn't valid for lea.
16804              Happens in 64-bit mode storing the 12-byte XFmode.  */
16805           if (GET_MODE (base) != Pmode)
16806             base = gen_rtx_REG (Pmode, REGNO (base));
16807
16808           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
16809           part[1][0] = replace_equiv_address (part[1][0], base);
16810           for (i = 1; i < nparts; i++)
16811             {
16812               tmp = plus_constant (base, UNITS_PER_WORD * i);
16813               part[1][i] = replace_equiv_address (part[1][i], tmp);
16814             }
16815         }
16816     }
16817
16818   if (push)
16819     {
16820       if (!TARGET_64BIT)
16821         {
16822           if (nparts == 3)
16823             {
16824               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
16825                 emit_insn (gen_addsi3 (stack_pointer_rtx,
16826                                        stack_pointer_rtx, GEN_INT (-4)));
16827               emit_move_insn (part[0][2], part[1][2]);
16828             }
16829           else if (nparts == 4)
16830             {
16831               emit_move_insn (part[0][3], part[1][3]);
16832               emit_move_insn (part[0][2], part[1][2]);
16833             }
16834         }
16835       else
16836         {
16837           /* In 64bit mode we don't have 32bit push available.  In case this is
16838              register, it is OK - we will just use larger counterpart.  We also
16839              retype memory - these comes from attempt to avoid REX prefix on
16840              moving of second half of TFmode value.  */
16841           if (GET_MODE (part[1][1]) == SImode)
16842             {
16843               switch (GET_CODE (part[1][1]))
16844                 {
16845                 case MEM:
16846                   part[1][1] = adjust_address (part[1][1], DImode, 0);
16847                   break;
16848
16849                 case REG:
16850                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
16851                   break;
16852
16853                 default:
16854                   gcc_unreachable ();
16855                 }
16856
16857               if (GET_MODE (part[1][0]) == SImode)
16858                 part[1][0] = part[1][1];
16859             }
16860         }
16861       emit_move_insn (part[0][1], part[1][1]);
16862       emit_move_insn (part[0][0], part[1][0]);
16863       return;
16864     }
16865
16866   /* Choose correct order to not overwrite the source before it is copied.  */
16867   if ((REG_P (part[0][0])
16868        && REG_P (part[1][1])
16869        && (REGNO (part[0][0]) == REGNO (part[1][1])
16870            || (nparts == 3
16871                && REGNO (part[0][0]) == REGNO (part[1][2]))
16872            || (nparts == 4
16873                && REGNO (part[0][0]) == REGNO (part[1][3]))))
16874       || (collisions > 0
16875           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
16876     {
16877       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
16878         {
16879           operands[2 + i] = part[0][j];
16880           operands[6 + i] = part[1][j];
16881         }
16882     }
16883   else
16884     {
16885       for (i = 0; i < nparts; i++)
16886         {
16887           operands[2 + i] = part[0][i];
16888           operands[6 + i] = part[1][i];
16889         }
16890     }
16891
16892   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
16893   if (optimize_insn_for_size_p ())
16894     {
16895       for (j = 0; j < nparts - 1; j++)
16896         if (CONST_INT_P (operands[6 + j])
16897             && operands[6 + j] != const0_rtx
16898             && REG_P (operands[2 + j]))
16899           for (i = j; i < nparts - 1; i++)
16900             if (CONST_INT_P (operands[7 + i])
16901                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
16902               operands[7 + i] = operands[2 + j];
16903     }
16904
16905   for (i = 0; i < nparts; i++)
16906     emit_move_insn (operands[2 + i], operands[6 + i]);
16907
16908   return;
16909 }
16910
16911 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
16912    left shift by a constant, either using a single shift or
16913    a sequence of add instructions.  */
16914
16915 static void
16916 ix86_expand_ashl_const (rtx operand, int count, enum machine_mode mode)
16917 {
16918   if (count == 1)
16919     {
16920       emit_insn ((mode == DImode
16921                   ? gen_addsi3
16922                   : gen_adddi3) (operand, operand, operand));
16923     }
16924   else if (!optimize_insn_for_size_p ()
16925            && count * ix86_cost->add <= ix86_cost->shift_const)
16926     {
16927       int i;
16928       for (i=0; i<count; i++)
16929         {
16930           emit_insn ((mode == DImode
16931                       ? gen_addsi3
16932                       : gen_adddi3) (operand, operand, operand));
16933         }
16934     }
16935   else
16936     emit_insn ((mode == DImode
16937                 ? gen_ashlsi3
16938                 : gen_ashldi3) (operand, operand, GEN_INT (count)));
16939 }
16940
16941 void
16942 ix86_split_ashl (rtx *operands, rtx scratch, enum machine_mode mode)
16943 {
16944   rtx low[2], high[2];
16945   int count;
16946   const int single_width = mode == DImode ? 32 : 64;
16947
16948   if (CONST_INT_P (operands[2]))
16949     {
16950       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16951       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16952
16953       if (count >= single_width)
16954         {
16955           emit_move_insn (high[0], low[1]);
16956           emit_move_insn (low[0], const0_rtx);
16957
16958           if (count > single_width)
16959             ix86_expand_ashl_const (high[0], count - single_width, mode);
16960         }
16961       else
16962         {
16963           if (!rtx_equal_p (operands[0], operands[1]))
16964             emit_move_insn (operands[0], operands[1]);
16965           emit_insn ((mode == DImode
16966                      ? gen_x86_shld
16967                      : gen_x86_64_shld) (high[0], low[0], GEN_INT (count)));
16968           ix86_expand_ashl_const (low[0], count, mode);
16969         }
16970       return;
16971     }
16972
16973   (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16974
16975   if (operands[1] == const1_rtx)
16976     {
16977       /* Assuming we've chosen a QImode capable registers, then 1 << N
16978          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
16979       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
16980         {
16981           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
16982
16983           ix86_expand_clear (low[0]);
16984           ix86_expand_clear (high[0]);
16985           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (single_width)));
16986
16987           d = gen_lowpart (QImode, low[0]);
16988           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16989           s = gen_rtx_EQ (QImode, flags, const0_rtx);
16990           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16991
16992           d = gen_lowpart (QImode, high[0]);
16993           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16994           s = gen_rtx_NE (QImode, flags, const0_rtx);
16995           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16996         }
16997
16998       /* Otherwise, we can get the same results by manually performing
16999          a bit extract operation on bit 5/6, and then performing the two
17000          shifts.  The two methods of getting 0/1 into low/high are exactly
17001          the same size.  Avoiding the shift in the bit extract case helps
17002          pentium4 a bit; no one else seems to care much either way.  */
17003       else
17004         {
17005           rtx x;
17006
17007           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
17008             x = gen_rtx_ZERO_EXTEND (mode == DImode ? SImode : DImode, operands[2]);
17009           else
17010             x = gen_lowpart (mode == DImode ? SImode : DImode, operands[2]);
17011           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
17012
17013           emit_insn ((mode == DImode
17014                       ? gen_lshrsi3
17015                       : gen_lshrdi3) (high[0], high[0],
17016                                       GEN_INT (mode == DImode ? 5 : 6)));
17017           emit_insn ((mode == DImode
17018                       ? gen_andsi3
17019                       : gen_anddi3) (high[0], high[0], const1_rtx));
17020           emit_move_insn (low[0], high[0]);
17021           emit_insn ((mode == DImode
17022                       ? gen_xorsi3
17023                       : gen_xordi3) (low[0], low[0], const1_rtx));
17024         }
17025
17026       emit_insn ((mode == DImode
17027                     ? gen_ashlsi3
17028                     : gen_ashldi3) (low[0], low[0], operands[2]));
17029       emit_insn ((mode == DImode
17030                     ? gen_ashlsi3
17031                     : gen_ashldi3) (high[0], high[0], operands[2]));
17032       return;
17033     }
17034
17035   if (operands[1] == constm1_rtx)
17036     {
17037       /* For -1 << N, we can avoid the shld instruction, because we
17038          know that we're shifting 0...31/63 ones into a -1.  */
17039       emit_move_insn (low[0], constm1_rtx);
17040       if (optimize_insn_for_size_p ())
17041         emit_move_insn (high[0], low[0]);
17042       else
17043         emit_move_insn (high[0], constm1_rtx);
17044     }
17045   else
17046     {
17047       if (!rtx_equal_p (operands[0], operands[1]))
17048         emit_move_insn (operands[0], operands[1]);
17049
17050       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
17051       emit_insn ((mode == DImode
17052                   ? gen_x86_shld
17053                   : gen_x86_64_shld) (high[0], low[0], operands[2]));
17054     }
17055
17056   emit_insn ((mode == DImode ? gen_ashlsi3 : gen_ashldi3) (low[0], low[0], operands[2]));
17057
17058   if (TARGET_CMOVE && scratch)
17059     {
17060       ix86_expand_clear (scratch);
17061       emit_insn ((mode == DImode
17062                   ? gen_x86_shift_adj_1
17063                   : gen_x86_64_shift_adj_1) (high[0], low[0], operands[2],
17064                                              scratch));
17065     }
17066   else
17067     emit_insn ((mode == DImode
17068                 ? gen_x86_shift_adj_2
17069                 : gen_x86_64_shift_adj_2) (high[0], low[0], operands[2]));
17070 }
17071
17072 void
17073 ix86_split_ashr (rtx *operands, rtx scratch, enum machine_mode mode)
17074 {
17075   rtx low[2], high[2];
17076   int count;
17077   const int single_width = mode == DImode ? 32 : 64;
17078
17079   if (CONST_INT_P (operands[2]))
17080     {
17081       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
17082       count = INTVAL (operands[2]) & (single_width * 2 - 1);
17083
17084       if (count == single_width * 2 - 1)
17085         {
17086           emit_move_insn (high[0], high[1]);
17087           emit_insn ((mode == DImode
17088                       ? gen_ashrsi3
17089                       : gen_ashrdi3) (high[0], high[0],
17090                                       GEN_INT (single_width - 1)));
17091           emit_move_insn (low[0], high[0]);
17092
17093         }
17094       else if (count >= single_width)
17095         {
17096           emit_move_insn (low[0], high[1]);
17097           emit_move_insn (high[0], low[0]);
17098           emit_insn ((mode == DImode
17099                       ? gen_ashrsi3
17100                       : gen_ashrdi3) (high[0], high[0],
17101                                       GEN_INT (single_width - 1)));
17102           if (count > single_width)
17103             emit_insn ((mode == DImode
17104                         ? gen_ashrsi3
17105                         : gen_ashrdi3) (low[0], low[0],
17106                                         GEN_INT (count - single_width)));
17107         }
17108       else
17109         {
17110           if (!rtx_equal_p (operands[0], operands[1]))
17111             emit_move_insn (operands[0], operands[1]);
17112           emit_insn ((mode == DImode
17113                       ? gen_x86_shrd
17114                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
17115           emit_insn ((mode == DImode
17116                       ? gen_ashrsi3
17117                       : gen_ashrdi3) (high[0], high[0], GEN_INT (count)));
17118         }
17119     }
17120   else
17121     {
17122       if (!rtx_equal_p (operands[0], operands[1]))
17123         emit_move_insn (operands[0], operands[1]);
17124
17125       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
17126
17127       emit_insn ((mode == DImode
17128                   ? gen_x86_shrd
17129                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
17130       emit_insn ((mode == DImode
17131                   ? gen_ashrsi3
17132                   : gen_ashrdi3)  (high[0], high[0], operands[2]));
17133
17134       if (TARGET_CMOVE && scratch)
17135         {
17136           emit_move_insn (scratch, high[0]);
17137           emit_insn ((mode == DImode
17138                       ? gen_ashrsi3
17139                       : gen_ashrdi3) (scratch, scratch,
17140                                       GEN_INT (single_width - 1)));
17141           emit_insn ((mode == DImode
17142                       ? gen_x86_shift_adj_1
17143                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
17144                                                  scratch));
17145         }
17146       else
17147         emit_insn ((mode == DImode
17148                     ? gen_x86_shift_adj_3
17149                     : gen_x86_64_shift_adj_3) (low[0], high[0], operands[2]));
17150     }
17151 }
17152
17153 void
17154 ix86_split_lshr (rtx *operands, rtx scratch, enum machine_mode mode)
17155 {
17156   rtx low[2], high[2];
17157   int count;
17158   const int single_width = mode == DImode ? 32 : 64;
17159
17160   if (CONST_INT_P (operands[2]))
17161     {
17162       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
17163       count = INTVAL (operands[2]) & (single_width * 2 - 1);
17164
17165       if (count >= single_width)
17166         {
17167           emit_move_insn (low[0], high[1]);
17168           ix86_expand_clear (high[0]);
17169
17170           if (count > single_width)
17171             emit_insn ((mode == DImode
17172                         ? gen_lshrsi3
17173                         : gen_lshrdi3) (low[0], low[0],
17174                                         GEN_INT (count - single_width)));
17175         }
17176       else
17177         {
17178           if (!rtx_equal_p (operands[0], operands[1]))
17179             emit_move_insn (operands[0], operands[1]);
17180           emit_insn ((mode == DImode
17181                       ? gen_x86_shrd
17182                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
17183           emit_insn ((mode == DImode
17184                       ? gen_lshrsi3
17185                       : gen_lshrdi3) (high[0], high[0], GEN_INT (count)));
17186         }
17187     }
17188   else
17189     {
17190       if (!rtx_equal_p (operands[0], operands[1]))
17191         emit_move_insn (operands[0], operands[1]);
17192
17193       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
17194
17195       emit_insn ((mode == DImode
17196                   ? gen_x86_shrd
17197                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
17198       emit_insn ((mode == DImode
17199                   ? gen_lshrsi3
17200                   : gen_lshrdi3) (high[0], high[0], operands[2]));
17201
17202       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
17203       if (TARGET_CMOVE && scratch)
17204         {
17205           ix86_expand_clear (scratch);
17206           emit_insn ((mode == DImode
17207                       ? gen_x86_shift_adj_1
17208                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
17209                                                  scratch));
17210         }
17211       else
17212         emit_insn ((mode == DImode
17213                     ? gen_x86_shift_adj_2
17214                     : gen_x86_64_shift_adj_2) (low[0], high[0], operands[2]));
17215     }
17216 }
17217
17218 /* Predict just emitted jump instruction to be taken with probability PROB.  */
17219 static void
17220 predict_jump (int prob)
17221 {
17222   rtx insn = get_last_insn ();
17223   gcc_assert (JUMP_P (insn));
17224   add_reg_note (insn, REG_BR_PROB, GEN_INT (prob));
17225 }
17226
17227 /* Helper function for the string operations below.  Dest VARIABLE whether
17228    it is aligned to VALUE bytes.  If true, jump to the label.  */
17229 static rtx
17230 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
17231 {
17232   rtx label = gen_label_rtx ();
17233   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
17234   if (GET_MODE (variable) == DImode)
17235     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
17236   else
17237     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
17238   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
17239                            1, label);
17240   if (epilogue)
17241     predict_jump (REG_BR_PROB_BASE * 50 / 100);
17242   else
17243     predict_jump (REG_BR_PROB_BASE * 90 / 100);
17244   return label;
17245 }
17246
17247 /* Adjust COUNTER by the VALUE.  */
17248 static void
17249 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
17250 {
17251   if (GET_MODE (countreg) == DImode)
17252     emit_insn (gen_adddi3 (countreg, countreg, GEN_INT (-value)));
17253   else
17254     emit_insn (gen_addsi3 (countreg, countreg, GEN_INT (-value)));
17255 }
17256
17257 /* Zero extend possibly SImode EXP to Pmode register.  */
17258 rtx
17259 ix86_zero_extend_to_Pmode (rtx exp)
17260 {
17261   rtx r;
17262   if (GET_MODE (exp) == VOIDmode)
17263     return force_reg (Pmode, exp);
17264   if (GET_MODE (exp) == Pmode)
17265     return copy_to_mode_reg (Pmode, exp);
17266   r = gen_reg_rtx (Pmode);
17267   emit_insn (gen_zero_extendsidi2 (r, exp));
17268   return r;
17269 }
17270
17271 /* Divide COUNTREG by SCALE.  */
17272 static rtx
17273 scale_counter (rtx countreg, int scale)
17274 {
17275   rtx sc;
17276   rtx piece_size_mask;
17277
17278   if (scale == 1)
17279     return countreg;
17280   if (CONST_INT_P (countreg))
17281     return GEN_INT (INTVAL (countreg) / scale);
17282   gcc_assert (REG_P (countreg));
17283
17284   piece_size_mask = GEN_INT (scale - 1);
17285   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
17286                             GEN_INT (exact_log2 (scale)),
17287                             NULL, 1, OPTAB_DIRECT);
17288   return sc;
17289 }
17290
17291 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
17292    DImode for constant loop counts.  */
17293
17294 static enum machine_mode
17295 counter_mode (rtx count_exp)
17296 {
17297   if (GET_MODE (count_exp) != VOIDmode)
17298     return GET_MODE (count_exp);
17299   if (!CONST_INT_P (count_exp))
17300     return Pmode;
17301   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
17302     return DImode;
17303   return SImode;
17304 }
17305
17306 /* When SRCPTR is non-NULL, output simple loop to move memory
17307    pointer to SRCPTR to DESTPTR via chunks of MODE unrolled UNROLL times,
17308    overall size is COUNT specified in bytes.  When SRCPTR is NULL, output the
17309    equivalent loop to set memory by VALUE (supposed to be in MODE).
17310
17311    The size is rounded down to whole number of chunk size moved at once.
17312    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
17313
17314
17315 static void
17316 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
17317                                rtx destptr, rtx srcptr, rtx value,
17318                                rtx count, enum machine_mode mode, int unroll,
17319                                int expected_size)
17320 {
17321   rtx out_label, top_label, iter, tmp;
17322   enum machine_mode iter_mode = counter_mode (count);
17323   rtx piece_size = GEN_INT (GET_MODE_SIZE (mode) * unroll);
17324   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
17325   rtx size;
17326   rtx x_addr;
17327   rtx y_addr;
17328   int i;
17329
17330   top_label = gen_label_rtx ();
17331   out_label = gen_label_rtx ();
17332   iter = gen_reg_rtx (iter_mode);
17333
17334   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
17335                               NULL, 1, OPTAB_DIRECT);
17336   /* Those two should combine.  */
17337   if (piece_size == const1_rtx)
17338     {
17339       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
17340                                true, out_label);
17341       predict_jump (REG_BR_PROB_BASE * 10 / 100);
17342     }
17343   emit_move_insn (iter, const0_rtx);
17344
17345   emit_label (top_label);
17346
17347   tmp = convert_modes (Pmode, iter_mode, iter, true);
17348   x_addr = gen_rtx_PLUS (Pmode, destptr, tmp);
17349   destmem = change_address (destmem, mode, x_addr);
17350
17351   if (srcmem)
17352     {
17353       y_addr = gen_rtx_PLUS (Pmode, srcptr, copy_rtx (tmp));
17354       srcmem = change_address (srcmem, mode, y_addr);
17355
17356       /* When unrolling for chips that reorder memory reads and writes,
17357          we can save registers by using single temporary.
17358          Also using 4 temporaries is overkill in 32bit mode.  */
17359       if (!TARGET_64BIT && 0)
17360         {
17361           for (i = 0; i < unroll; i++)
17362             {
17363               if (i)
17364                 {
17365                   destmem =
17366                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
17367                   srcmem =
17368                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
17369                 }
17370               emit_move_insn (destmem, srcmem);
17371             }
17372         }
17373       else
17374         {
17375           rtx tmpreg[4];
17376           gcc_assert (unroll <= 4);
17377           for (i = 0; i < unroll; i++)
17378             {
17379               tmpreg[i] = gen_reg_rtx (mode);
17380               if (i)
17381                 {
17382                   srcmem =
17383                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
17384                 }
17385               emit_move_insn (tmpreg[i], srcmem);
17386             }
17387           for (i = 0; i < unroll; i++)
17388             {
17389               if (i)
17390                 {
17391                   destmem =
17392                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
17393                 }
17394               emit_move_insn (destmem, tmpreg[i]);
17395             }
17396         }
17397     }
17398   else
17399     for (i = 0; i < unroll; i++)
17400       {
17401         if (i)
17402           destmem =
17403             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
17404         emit_move_insn (destmem, value);
17405       }
17406
17407   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
17408                              true, OPTAB_LIB_WIDEN);
17409   if (tmp != iter)
17410     emit_move_insn (iter, tmp);
17411
17412   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
17413                            true, top_label);
17414   if (expected_size != -1)
17415     {
17416       expected_size /= GET_MODE_SIZE (mode) * unroll;
17417       if (expected_size == 0)
17418         predict_jump (0);
17419       else if (expected_size > REG_BR_PROB_BASE)
17420         predict_jump (REG_BR_PROB_BASE - 1);
17421       else
17422         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
17423     }
17424   else
17425     predict_jump (REG_BR_PROB_BASE * 80 / 100);
17426   iter = ix86_zero_extend_to_Pmode (iter);
17427   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
17428                              true, OPTAB_LIB_WIDEN);
17429   if (tmp != destptr)
17430     emit_move_insn (destptr, tmp);
17431   if (srcptr)
17432     {
17433       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
17434                                  true, OPTAB_LIB_WIDEN);
17435       if (tmp != srcptr)
17436         emit_move_insn (srcptr, tmp);
17437     }
17438   emit_label (out_label);
17439 }
17440
17441 /* Output "rep; mov" instruction.
17442    Arguments have same meaning as for previous function */
17443 static void
17444 expand_movmem_via_rep_mov (rtx destmem, rtx srcmem,
17445                            rtx destptr, rtx srcptr,
17446                            rtx count,
17447                            enum machine_mode mode)
17448 {
17449   rtx destexp;
17450   rtx srcexp;
17451   rtx countreg;
17452
17453   /* If the size is known, it is shorter to use rep movs.  */
17454   if (mode == QImode && CONST_INT_P (count)
17455       && !(INTVAL (count) & 3))
17456     mode = SImode;
17457
17458   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
17459     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
17460   if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
17461     srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
17462   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
17463   if (mode != QImode)
17464     {
17465       destexp = gen_rtx_ASHIFT (Pmode, countreg,
17466                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
17467       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
17468       srcexp = gen_rtx_ASHIFT (Pmode, countreg,
17469                                GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
17470       srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
17471     }
17472   else
17473     {
17474       destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
17475       srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
17476     }
17477   if (CONST_INT_P (count))
17478     {
17479       count = GEN_INT (INTVAL (count)
17480                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
17481       destmem = shallow_copy_rtx (destmem);
17482       srcmem = shallow_copy_rtx (srcmem);
17483       set_mem_size (destmem, count);
17484       set_mem_size (srcmem, count);
17485     }
17486   else
17487     {
17488       if (MEM_SIZE (destmem))
17489         set_mem_size (destmem, NULL_RTX);
17490       if (MEM_SIZE (srcmem))
17491         set_mem_size (srcmem, NULL_RTX);
17492     }
17493   emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
17494                           destexp, srcexp));
17495 }
17496
17497 /* Output "rep; stos" instruction.
17498    Arguments have same meaning as for previous function */
17499 static void
17500 expand_setmem_via_rep_stos (rtx destmem, rtx destptr, rtx value,
17501                             rtx count, enum machine_mode mode,
17502                             rtx orig_value)
17503 {
17504   rtx destexp;
17505   rtx countreg;
17506
17507   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
17508     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
17509   value = force_reg (mode, gen_lowpart (mode, value));
17510   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
17511   if (mode != QImode)
17512     {
17513       destexp = gen_rtx_ASHIFT (Pmode, countreg,
17514                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
17515       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
17516     }
17517   else
17518     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
17519   if (orig_value == const0_rtx && CONST_INT_P (count))
17520     {
17521       count = GEN_INT (INTVAL (count)
17522                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
17523       destmem = shallow_copy_rtx (destmem);
17524       set_mem_size (destmem, count);
17525     }
17526   else if (MEM_SIZE (destmem))
17527     set_mem_size (destmem, NULL_RTX);
17528   emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
17529 }
17530
17531 static void
17532 emit_strmov (rtx destmem, rtx srcmem,
17533              rtx destptr, rtx srcptr, enum machine_mode mode, int offset)
17534 {
17535   rtx src = adjust_automodify_address_nv (srcmem, mode, srcptr, offset);
17536   rtx dest = adjust_automodify_address_nv (destmem, mode, destptr, offset);
17537   emit_insn (gen_strmov (destptr, dest, srcptr, src));
17538 }
17539
17540 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
17541 static void
17542 expand_movmem_epilogue (rtx destmem, rtx srcmem,
17543                         rtx destptr, rtx srcptr, rtx count, int max_size)
17544 {
17545   rtx src, dest;
17546   if (CONST_INT_P (count))
17547     {
17548       HOST_WIDE_INT countval = INTVAL (count);
17549       int offset = 0;
17550
17551       if ((countval & 0x10) && max_size > 16)
17552         {
17553           if (TARGET_64BIT)
17554             {
17555               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
17556               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset + 8);
17557             }
17558           else
17559             gcc_unreachable ();
17560           offset += 16;
17561         }
17562       if ((countval & 0x08) && max_size > 8)
17563         {
17564           if (TARGET_64BIT)
17565             emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
17566           else
17567             {
17568               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
17569               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset + 4);
17570             }
17571           offset += 8;
17572         }
17573       if ((countval & 0x04) && max_size > 4)
17574         {
17575           emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
17576           offset += 4;
17577         }
17578       if ((countval & 0x02) && max_size > 2)
17579         {
17580           emit_strmov (destmem, srcmem, destptr, srcptr, HImode, offset);
17581           offset += 2;
17582         }
17583       if ((countval & 0x01) && max_size > 1)
17584         {
17585           emit_strmov (destmem, srcmem, destptr, srcptr, QImode, offset);
17586           offset += 1;
17587         }
17588       return;
17589     }
17590   if (max_size > 8)
17591     {
17592       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
17593                                     count, 1, OPTAB_DIRECT);
17594       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
17595                                      count, QImode, 1, 4);
17596       return;
17597     }
17598
17599   /* When there are stringops, we can cheaply increase dest and src pointers.
17600      Otherwise we save code size by maintaining offset (zero is readily
17601      available from preceding rep operation) and using x86 addressing modes.
17602    */
17603   if (TARGET_SINGLE_STRINGOP)
17604     {
17605       if (max_size > 4)
17606         {
17607           rtx label = ix86_expand_aligntest (count, 4, true);
17608           src = change_address (srcmem, SImode, srcptr);
17609           dest = change_address (destmem, SImode, destptr);
17610           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17611           emit_label (label);
17612           LABEL_NUSES (label) = 1;
17613         }
17614       if (max_size > 2)
17615         {
17616           rtx label = ix86_expand_aligntest (count, 2, true);
17617           src = change_address (srcmem, HImode, srcptr);
17618           dest = change_address (destmem, HImode, destptr);
17619           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17620           emit_label (label);
17621           LABEL_NUSES (label) = 1;
17622         }
17623       if (max_size > 1)
17624         {
17625           rtx label = ix86_expand_aligntest (count, 1, true);
17626           src = change_address (srcmem, QImode, srcptr);
17627           dest = change_address (destmem, QImode, destptr);
17628           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17629           emit_label (label);
17630           LABEL_NUSES (label) = 1;
17631         }
17632     }
17633   else
17634     {
17635       rtx offset = force_reg (Pmode, const0_rtx);
17636       rtx tmp;
17637
17638       if (max_size > 4)
17639         {
17640           rtx label = ix86_expand_aligntest (count, 4, true);
17641           src = change_address (srcmem, SImode, srcptr);
17642           dest = change_address (destmem, SImode, destptr);
17643           emit_move_insn (dest, src);
17644           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
17645                                      true, OPTAB_LIB_WIDEN);
17646           if (tmp != offset)
17647             emit_move_insn (offset, tmp);
17648           emit_label (label);
17649           LABEL_NUSES (label) = 1;
17650         }
17651       if (max_size > 2)
17652         {
17653           rtx label = ix86_expand_aligntest (count, 2, true);
17654           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
17655           src = change_address (srcmem, HImode, tmp);
17656           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
17657           dest = change_address (destmem, HImode, tmp);
17658           emit_move_insn (dest, src);
17659           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
17660                                      true, OPTAB_LIB_WIDEN);
17661           if (tmp != offset)
17662             emit_move_insn (offset, tmp);
17663           emit_label (label);
17664           LABEL_NUSES (label) = 1;
17665         }
17666       if (max_size > 1)
17667         {
17668           rtx label = ix86_expand_aligntest (count, 1, true);
17669           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
17670           src = change_address (srcmem, QImode, tmp);
17671           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
17672           dest = change_address (destmem, QImode, tmp);
17673           emit_move_insn (dest, src);
17674           emit_label (label);
17675           LABEL_NUSES (label) = 1;
17676         }
17677     }
17678 }
17679
17680 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
17681 static void
17682 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
17683                                  rtx count, int max_size)
17684 {
17685   count =
17686     expand_simple_binop (counter_mode (count), AND, count,
17687                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
17688   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
17689                                  gen_lowpart (QImode, value), count, QImode,
17690                                  1, max_size / 2);
17691 }
17692
17693 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
17694 static void
17695 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx count, int max_size)
17696 {
17697   rtx dest;
17698
17699   if (CONST_INT_P (count))
17700     {
17701       HOST_WIDE_INT countval = INTVAL (count);
17702       int offset = 0;
17703
17704       if ((countval & 0x10) && max_size > 16)
17705         {
17706           if (TARGET_64BIT)
17707             {
17708               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
17709               emit_insn (gen_strset (destptr, dest, value));
17710               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset + 8);
17711               emit_insn (gen_strset (destptr, dest, value));
17712             }
17713           else
17714             gcc_unreachable ();
17715           offset += 16;
17716         }
17717       if ((countval & 0x08) && max_size > 8)
17718         {
17719           if (TARGET_64BIT)
17720             {
17721               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
17722               emit_insn (gen_strset (destptr, dest, value));
17723             }
17724           else
17725             {
17726               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
17727               emit_insn (gen_strset (destptr, dest, value));
17728               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset + 4);
17729               emit_insn (gen_strset (destptr, dest, value));
17730             }
17731           offset += 8;
17732         }
17733       if ((countval & 0x04) && max_size > 4)
17734         {
17735           dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
17736           emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
17737           offset += 4;
17738         }
17739       if ((countval & 0x02) && max_size > 2)
17740         {
17741           dest = adjust_automodify_address_nv (destmem, HImode, destptr, offset);
17742           emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
17743           offset += 2;
17744         }
17745       if ((countval & 0x01) && max_size > 1)
17746         {
17747           dest = adjust_automodify_address_nv (destmem, QImode, destptr, offset);
17748           emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
17749           offset += 1;
17750         }
17751       return;
17752     }
17753   if (max_size > 32)
17754     {
17755       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
17756       return;
17757     }
17758   if (max_size > 16)
17759     {
17760       rtx label = ix86_expand_aligntest (count, 16, true);
17761       if (TARGET_64BIT)
17762         {
17763           dest = change_address (destmem, DImode, destptr);
17764           emit_insn (gen_strset (destptr, dest, value));
17765           emit_insn (gen_strset (destptr, dest, value));
17766         }
17767       else
17768         {
17769           dest = change_address (destmem, SImode, destptr);
17770           emit_insn (gen_strset (destptr, dest, value));
17771           emit_insn (gen_strset (destptr, dest, value));
17772           emit_insn (gen_strset (destptr, dest, value));
17773           emit_insn (gen_strset (destptr, dest, value));
17774         }
17775       emit_label (label);
17776       LABEL_NUSES (label) = 1;
17777     }
17778   if (max_size > 8)
17779     {
17780       rtx label = ix86_expand_aligntest (count, 8, true);
17781       if (TARGET_64BIT)
17782         {
17783           dest = change_address (destmem, DImode, destptr);
17784           emit_insn (gen_strset (destptr, dest, value));
17785         }
17786       else
17787         {
17788           dest = change_address (destmem, SImode, destptr);
17789           emit_insn (gen_strset (destptr, dest, value));
17790           emit_insn (gen_strset (destptr, dest, value));
17791         }
17792       emit_label (label);
17793       LABEL_NUSES (label) = 1;
17794     }
17795   if (max_size > 4)
17796     {
17797       rtx label = ix86_expand_aligntest (count, 4, true);
17798       dest = change_address (destmem, SImode, destptr);
17799       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
17800       emit_label (label);
17801       LABEL_NUSES (label) = 1;
17802     }
17803   if (max_size > 2)
17804     {
17805       rtx label = ix86_expand_aligntest (count, 2, true);
17806       dest = change_address (destmem, HImode, destptr);
17807       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
17808       emit_label (label);
17809       LABEL_NUSES (label) = 1;
17810     }
17811   if (max_size > 1)
17812     {
17813       rtx label = ix86_expand_aligntest (count, 1, true);
17814       dest = change_address (destmem, QImode, destptr);
17815       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
17816       emit_label (label);
17817       LABEL_NUSES (label) = 1;
17818     }
17819 }
17820
17821 /* Copy enough from DEST to SRC to align DEST known to by aligned by ALIGN to
17822    DESIRED_ALIGNMENT.  */
17823 static void
17824 expand_movmem_prologue (rtx destmem, rtx srcmem,
17825                         rtx destptr, rtx srcptr, rtx count,
17826                         int align, int desired_alignment)
17827 {
17828   if (align <= 1 && desired_alignment > 1)
17829     {
17830       rtx label = ix86_expand_aligntest (destptr, 1, false);
17831       srcmem = change_address (srcmem, QImode, srcptr);
17832       destmem = change_address (destmem, QImode, destptr);
17833       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17834       ix86_adjust_counter (count, 1);
17835       emit_label (label);
17836       LABEL_NUSES (label) = 1;
17837     }
17838   if (align <= 2 && desired_alignment > 2)
17839     {
17840       rtx label = ix86_expand_aligntest (destptr, 2, false);
17841       srcmem = change_address (srcmem, HImode, srcptr);
17842       destmem = change_address (destmem, HImode, destptr);
17843       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17844       ix86_adjust_counter (count, 2);
17845       emit_label (label);
17846       LABEL_NUSES (label) = 1;
17847     }
17848   if (align <= 4 && desired_alignment > 4)
17849     {
17850       rtx label = ix86_expand_aligntest (destptr, 4, false);
17851       srcmem = change_address (srcmem, SImode, srcptr);
17852       destmem = change_address (destmem, SImode, destptr);
17853       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17854       ix86_adjust_counter (count, 4);
17855       emit_label (label);
17856       LABEL_NUSES (label) = 1;
17857     }
17858   gcc_assert (desired_alignment <= 8);
17859 }
17860
17861 /* Copy enough from DST to SRC to align DST known to DESIRED_ALIGN.
17862    ALIGN_BYTES is how many bytes need to be copied.  */
17863 static rtx
17864 expand_constant_movmem_prologue (rtx dst, rtx *srcp, rtx destreg, rtx srcreg,
17865                                  int desired_align, int align_bytes)
17866 {
17867   rtx src = *srcp;
17868   rtx src_size, dst_size;
17869   int off = 0;
17870   int src_align_bytes = get_mem_align_offset (src, desired_align * BITS_PER_UNIT);
17871   if (src_align_bytes >= 0)
17872     src_align_bytes = desired_align - src_align_bytes;
17873   src_size = MEM_SIZE (src);
17874   dst_size = MEM_SIZE (dst);
17875   if (align_bytes & 1)
17876     {
17877       dst = adjust_automodify_address_nv (dst, QImode, destreg, 0);
17878       src = adjust_automodify_address_nv (src, QImode, srcreg, 0);
17879       off = 1;
17880       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17881     }
17882   if (align_bytes & 2)
17883     {
17884       dst = adjust_automodify_address_nv (dst, HImode, destreg, off);
17885       src = adjust_automodify_address_nv (src, HImode, srcreg, off);
17886       if (MEM_ALIGN (dst) < 2 * BITS_PER_UNIT)
17887         set_mem_align (dst, 2 * BITS_PER_UNIT);
17888       if (src_align_bytes >= 0
17889           && (src_align_bytes & 1) == (align_bytes & 1)
17890           && MEM_ALIGN (src) < 2 * BITS_PER_UNIT)
17891         set_mem_align (src, 2 * BITS_PER_UNIT);
17892       off = 2;
17893       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17894     }
17895   if (align_bytes & 4)
17896     {
17897       dst = adjust_automodify_address_nv (dst, SImode, destreg, off);
17898       src = adjust_automodify_address_nv (src, SImode, srcreg, off);
17899       if (MEM_ALIGN (dst) < 4 * BITS_PER_UNIT)
17900         set_mem_align (dst, 4 * BITS_PER_UNIT);
17901       if (src_align_bytes >= 0)
17902         {
17903           unsigned int src_align = 0;
17904           if ((src_align_bytes & 3) == (align_bytes & 3))
17905             src_align = 4;
17906           else if ((src_align_bytes & 1) == (align_bytes & 1))
17907             src_align = 2;
17908           if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
17909             set_mem_align (src, src_align * BITS_PER_UNIT);
17910         }
17911       off = 4;
17912       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17913     }
17914   dst = adjust_automodify_address_nv (dst, BLKmode, destreg, off);
17915   src = adjust_automodify_address_nv (src, BLKmode, srcreg, off);
17916   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
17917     set_mem_align (dst, desired_align * BITS_PER_UNIT);
17918   if (src_align_bytes >= 0)
17919     {
17920       unsigned int src_align = 0;
17921       if ((src_align_bytes & 7) == (align_bytes & 7))
17922         src_align = 8;
17923       else if ((src_align_bytes & 3) == (align_bytes & 3))
17924         src_align = 4;
17925       else if ((src_align_bytes & 1) == (align_bytes & 1))
17926         src_align = 2;
17927       if (src_align > (unsigned int) desired_align)
17928         src_align = desired_align;
17929       if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
17930         set_mem_align (src, src_align * BITS_PER_UNIT);
17931     }
17932   if (dst_size)
17933     set_mem_size (dst, GEN_INT (INTVAL (dst_size) - align_bytes));
17934   if (src_size)
17935     set_mem_size (dst, GEN_INT (INTVAL (src_size) - align_bytes));
17936   *srcp = src;
17937   return dst;
17938 }
17939
17940 /* Set enough from DEST to align DEST known to by aligned by ALIGN to
17941    DESIRED_ALIGNMENT.  */
17942 static void
17943 expand_setmem_prologue (rtx destmem, rtx destptr, rtx value, rtx count,
17944                         int align, int desired_alignment)
17945 {
17946   if (align <= 1 && desired_alignment > 1)
17947     {
17948       rtx label = ix86_expand_aligntest (destptr, 1, false);
17949       destmem = change_address (destmem, QImode, destptr);
17950       emit_insn (gen_strset (destptr, destmem, gen_lowpart (QImode, value)));
17951       ix86_adjust_counter (count, 1);
17952       emit_label (label);
17953       LABEL_NUSES (label) = 1;
17954     }
17955   if (align <= 2 && desired_alignment > 2)
17956     {
17957       rtx label = ix86_expand_aligntest (destptr, 2, false);
17958       destmem = change_address (destmem, HImode, destptr);
17959       emit_insn (gen_strset (destptr, destmem, gen_lowpart (HImode, value)));
17960       ix86_adjust_counter (count, 2);
17961       emit_label (label);
17962       LABEL_NUSES (label) = 1;
17963     }
17964   if (align <= 4 && desired_alignment > 4)
17965     {
17966       rtx label = ix86_expand_aligntest (destptr, 4, false);
17967       destmem = change_address (destmem, SImode, destptr);
17968       emit_insn (gen_strset (destptr, destmem, gen_lowpart (SImode, value)));
17969       ix86_adjust_counter (count, 4);
17970       emit_label (label);
17971       LABEL_NUSES (label) = 1;
17972     }
17973   gcc_assert (desired_alignment <= 8);
17974 }
17975
17976 /* Set enough from DST to align DST known to by aligned by ALIGN to
17977    DESIRED_ALIGN.  ALIGN_BYTES is how many bytes need to be stored.  */
17978 static rtx
17979 expand_constant_setmem_prologue (rtx dst, rtx destreg, rtx value,
17980                                  int desired_align, int align_bytes)
17981 {
17982   int off = 0;
17983   rtx dst_size = MEM_SIZE (dst);
17984   if (align_bytes & 1)
17985     {
17986       dst = adjust_automodify_address_nv (dst, QImode, destreg, 0);
17987       off = 1;
17988       emit_insn (gen_strset (destreg, dst,
17989                              gen_lowpart (QImode, value)));
17990     }
17991   if (align_bytes & 2)
17992     {
17993       dst = adjust_automodify_address_nv (dst, HImode, destreg, off);
17994       if (MEM_ALIGN (dst) < 2 * BITS_PER_UNIT)
17995         set_mem_align (dst, 2 * BITS_PER_UNIT);
17996       off = 2;
17997       emit_insn (gen_strset (destreg, dst,
17998                              gen_lowpart (HImode, value)));
17999     }
18000   if (align_bytes & 4)
18001     {
18002       dst = adjust_automodify_address_nv (dst, SImode, destreg, off);
18003       if (MEM_ALIGN (dst) < 4 * BITS_PER_UNIT)
18004         set_mem_align (dst, 4 * BITS_PER_UNIT);
18005       off = 4;
18006       emit_insn (gen_strset (destreg, dst,
18007                              gen_lowpart (SImode, value)));
18008     }
18009   dst = adjust_automodify_address_nv (dst, BLKmode, destreg, off);
18010   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
18011     set_mem_align (dst, desired_align * BITS_PER_UNIT);
18012   if (dst_size)
18013     set_mem_size (dst, GEN_INT (INTVAL (dst_size) - align_bytes));
18014   return dst;
18015 }
18016
18017 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
18018 static enum stringop_alg
18019 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, bool memset,
18020             int *dynamic_check)
18021 {
18022   const struct stringop_algs * algs;
18023   bool optimize_for_speed;
18024   /* Algorithms using the rep prefix want at least edi and ecx;
18025      additionally, memset wants eax and memcpy wants esi.  Don't
18026      consider such algorithms if the user has appropriated those
18027      registers for their own purposes.  */
18028   bool rep_prefix_usable = !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
18029                              || (memset
18030                                  ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
18031
18032 #define ALG_USABLE_P(alg) (rep_prefix_usable                    \
18033                            || (alg != rep_prefix_1_byte         \
18034                                && alg != rep_prefix_4_byte      \
18035                                && alg != rep_prefix_8_byte))
18036   const struct processor_costs *cost;
18037   
18038   /* Even if the string operation call is cold, we still might spend a lot
18039      of time processing large blocks.  */
18040   if (optimize_function_for_size_p (cfun)
18041       || (optimize_insn_for_size_p ()
18042           && expected_size != -1 && expected_size < 256))
18043     optimize_for_speed = false;
18044   else
18045     optimize_for_speed = true;
18046
18047   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
18048
18049   *dynamic_check = -1;
18050   if (memset)
18051     algs = &cost->memset[TARGET_64BIT != 0];
18052   else
18053     algs = &cost->memcpy[TARGET_64BIT != 0];
18054   if (stringop_alg != no_stringop && ALG_USABLE_P (stringop_alg))
18055     return stringop_alg;
18056   /* rep; movq or rep; movl is the smallest variant.  */
18057   else if (!optimize_for_speed)
18058     {
18059       if (!count || (count & 3))
18060         return rep_prefix_usable ? rep_prefix_1_byte : loop_1_byte;
18061       else
18062         return rep_prefix_usable ? rep_prefix_4_byte : loop;
18063     }
18064   /* Very tiny blocks are best handled via the loop, REP is expensive to setup.
18065    */
18066   else if (expected_size != -1 && expected_size < 4)
18067     return loop_1_byte;
18068   else if (expected_size != -1)
18069     {
18070       unsigned int i;
18071       enum stringop_alg alg = libcall;
18072       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
18073         {
18074           /* We get here if the algorithms that were not libcall-based
18075              were rep-prefix based and we are unable to use rep prefixes
18076              based on global register usage.  Break out of the loop and
18077              use the heuristic below.  */
18078           if (algs->size[i].max == 0)
18079             break;
18080           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
18081             {
18082               enum stringop_alg candidate = algs->size[i].alg;
18083
18084               if (candidate != libcall && ALG_USABLE_P (candidate))
18085                 alg = candidate;
18086               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
18087                  last non-libcall inline algorithm.  */
18088               if (TARGET_INLINE_ALL_STRINGOPS)
18089                 {
18090                   /* When the current size is best to be copied by a libcall,
18091                      but we are still forced to inline, run the heuristic below
18092                      that will pick code for medium sized blocks.  */
18093                   if (alg != libcall)
18094                     return alg;
18095                   break;
18096                 }
18097               else if (ALG_USABLE_P (candidate))
18098                 return candidate;
18099             }
18100         }
18101       gcc_assert (TARGET_INLINE_ALL_STRINGOPS || !rep_prefix_usable);
18102     }
18103   /* When asked to inline the call anyway, try to pick meaningful choice.
18104      We look for maximal size of block that is faster to copy by hand and
18105      take blocks of at most of that size guessing that average size will
18106      be roughly half of the block.
18107
18108      If this turns out to be bad, we might simply specify the preferred
18109      choice in ix86_costs.  */
18110   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
18111       && (algs->unknown_size == libcall || !ALG_USABLE_P (algs->unknown_size)))
18112     {
18113       int max = -1;
18114       enum stringop_alg alg;
18115       int i;
18116       bool any_alg_usable_p = true;
18117
18118       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
18119         {
18120           enum stringop_alg candidate = algs->size[i].alg;
18121           any_alg_usable_p = any_alg_usable_p && ALG_USABLE_P (candidate);
18122
18123           if (candidate != libcall && candidate
18124               && ALG_USABLE_P (candidate))
18125               max = algs->size[i].max;
18126         }
18127       /* If there aren't any usable algorithms, then recursing on
18128          smaller sizes isn't going to find anything.  Just return the
18129          simple byte-at-a-time copy loop.  */
18130       if (!any_alg_usable_p)
18131         {
18132           /* Pick something reasonable.  */
18133           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
18134             *dynamic_check = 128;
18135           return loop_1_byte;
18136         }
18137       if (max == -1)
18138         max = 4096;
18139       alg = decide_alg (count, max / 2, memset, dynamic_check);
18140       gcc_assert (*dynamic_check == -1);
18141       gcc_assert (alg != libcall);
18142       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
18143         *dynamic_check = max;
18144       return alg;
18145     }
18146   return ALG_USABLE_P (algs->unknown_size) ? algs->unknown_size : libcall;
18147 #undef ALG_USABLE_P
18148 }
18149
18150 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
18151    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
18152 static int
18153 decide_alignment (int align,
18154                   enum stringop_alg alg,
18155                   int expected_size)
18156 {
18157   int desired_align = 0;
18158   switch (alg)
18159     {
18160       case no_stringop:
18161         gcc_unreachable ();
18162       case loop:
18163       case unrolled_loop:
18164         desired_align = GET_MODE_SIZE (Pmode);
18165         break;
18166       case rep_prefix_8_byte:
18167         desired_align = 8;
18168         break;
18169       case rep_prefix_4_byte:
18170         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
18171            copying whole cacheline at once.  */
18172         if (TARGET_PENTIUMPRO)
18173           desired_align = 8;
18174         else
18175           desired_align = 4;
18176         break;
18177       case rep_prefix_1_byte:
18178         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
18179            copying whole cacheline at once.  */
18180         if (TARGET_PENTIUMPRO)
18181           desired_align = 8;
18182         else
18183           desired_align = 1;
18184         break;
18185       case loop_1_byte:
18186         desired_align = 1;
18187         break;
18188       case libcall:
18189         return 0;
18190     }
18191
18192   if (optimize_size)
18193     desired_align = 1;
18194   if (desired_align < align)
18195     desired_align = align;
18196   if (expected_size != -1 && expected_size < 4)
18197     desired_align = align;
18198   return desired_align;
18199 }
18200
18201 /* Return the smallest power of 2 greater than VAL.  */
18202 static int
18203 smallest_pow2_greater_than (int val)
18204 {
18205   int ret = 1;
18206   while (ret <= val)
18207     ret <<= 1;
18208   return ret;
18209 }
18210
18211 /* Expand string move (memcpy) operation.  Use i386 string operations when
18212    profitable.  expand_setmem contains similar code.  The code depends upon
18213    architecture, block size and alignment, but always has the same
18214    overall structure:
18215
18216    1) Prologue guard: Conditional that jumps up to epilogues for small
18217       blocks that can be handled by epilogue alone.  This is faster but
18218       also needed for correctness, since prologue assume the block is larger
18219       than the desired alignment.
18220
18221       Optional dynamic check for size and libcall for large
18222       blocks is emitted here too, with -minline-stringops-dynamically.
18223
18224    2) Prologue: copy first few bytes in order to get destination aligned
18225       to DESIRED_ALIGN.  It is emitted only when ALIGN is less than
18226       DESIRED_ALIGN and and up to DESIRED_ALIGN - ALIGN bytes can be copied.
18227       We emit either a jump tree on power of two sized blocks, or a byte loop.
18228
18229    3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
18230       with specified algorithm.
18231
18232    4) Epilogue: code copying tail of the block that is too small to be
18233       handled by main body (or up to size guarded by prologue guard).  */
18234
18235 int
18236 ix86_expand_movmem (rtx dst, rtx src, rtx count_exp, rtx align_exp,
18237                     rtx expected_align_exp, rtx expected_size_exp)
18238 {
18239   rtx destreg;
18240   rtx srcreg;
18241   rtx label = NULL;
18242   rtx tmp;
18243   rtx jump_around_label = NULL;
18244   HOST_WIDE_INT align = 1;
18245   unsigned HOST_WIDE_INT count = 0;
18246   HOST_WIDE_INT expected_size = -1;
18247   int size_needed = 0, epilogue_size_needed;
18248   int desired_align = 0, align_bytes = 0;
18249   enum stringop_alg alg;
18250   int dynamic_check;
18251   bool need_zero_guard = false;
18252
18253   if (CONST_INT_P (align_exp))
18254     align = INTVAL (align_exp);
18255   /* i386 can do misaligned access on reasonably increased cost.  */
18256   if (CONST_INT_P (expected_align_exp)
18257       && INTVAL (expected_align_exp) > align)
18258     align = INTVAL (expected_align_exp);
18259   /* ALIGN is the minimum of destination and source alignment, but we care here
18260      just about destination alignment.  */
18261   else if (MEM_ALIGN (dst) > (unsigned HOST_WIDE_INT) align * BITS_PER_UNIT)
18262     align = MEM_ALIGN (dst) / BITS_PER_UNIT;
18263
18264   if (CONST_INT_P (count_exp))
18265     count = expected_size = INTVAL (count_exp);
18266   if (CONST_INT_P (expected_size_exp) && count == 0)
18267     expected_size = INTVAL (expected_size_exp);
18268
18269   /* Make sure we don't need to care about overflow later on.  */
18270   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
18271     return 0;
18272
18273   /* Step 0: Decide on preferred algorithm, desired alignment and
18274      size of chunks to be copied by main loop.  */
18275
18276   alg = decide_alg (count, expected_size, false, &dynamic_check);
18277   desired_align = decide_alignment (align, alg, expected_size);
18278
18279   if (!TARGET_ALIGN_STRINGOPS)
18280     align = desired_align;
18281
18282   if (alg == libcall)
18283     return 0;
18284   gcc_assert (alg != no_stringop);
18285   if (!count)
18286     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
18287   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
18288   srcreg = copy_to_mode_reg (Pmode, XEXP (src, 0));
18289   switch (alg)
18290     {
18291     case libcall:
18292     case no_stringop:
18293       gcc_unreachable ();
18294     case loop:
18295       need_zero_guard = true;
18296       size_needed = GET_MODE_SIZE (Pmode);
18297       break;
18298     case unrolled_loop:
18299       need_zero_guard = true;
18300       size_needed = GET_MODE_SIZE (Pmode) * (TARGET_64BIT ? 4 : 2);
18301       break;
18302     case rep_prefix_8_byte:
18303       size_needed = 8;
18304       break;
18305     case rep_prefix_4_byte:
18306       size_needed = 4;
18307       break;
18308     case rep_prefix_1_byte:
18309       size_needed = 1;
18310       break;
18311     case loop_1_byte:
18312       need_zero_guard = true;
18313       size_needed = 1;
18314       break;
18315     }
18316
18317   epilogue_size_needed = size_needed;
18318
18319   /* Step 1: Prologue guard.  */
18320
18321   /* Alignment code needs count to be in register.  */
18322   if (CONST_INT_P (count_exp) && desired_align > align)
18323     {
18324       if (INTVAL (count_exp) > desired_align
18325           && INTVAL (count_exp) > size_needed)
18326         {
18327           align_bytes
18328             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
18329           if (align_bytes <= 0)
18330             align_bytes = 0;
18331           else
18332             align_bytes = desired_align - align_bytes;
18333         }
18334       if (align_bytes == 0)
18335         count_exp = force_reg (counter_mode (count_exp), count_exp);
18336     }
18337   gcc_assert (desired_align >= 1 && align >= 1);
18338
18339   /* Ensure that alignment prologue won't copy past end of block.  */
18340   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
18341     {
18342       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
18343       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
18344          Make sure it is power of 2.  */
18345       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
18346
18347       if (count)
18348         {
18349           if (count < (unsigned HOST_WIDE_INT)epilogue_size_needed)
18350             {
18351               /* If main algorithm works on QImode, no epilogue is needed.
18352                  For small sizes just don't align anything.  */
18353               if (size_needed == 1)
18354                 desired_align = align;
18355               else
18356                 goto epilogue;
18357             }
18358         }
18359       else
18360         {
18361           label = gen_label_rtx ();
18362           emit_cmp_and_jump_insns (count_exp,
18363                                    GEN_INT (epilogue_size_needed),
18364                                    LTU, 0, counter_mode (count_exp), 1, label);
18365           if (expected_size == -1 || expected_size < epilogue_size_needed)
18366             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18367           else
18368             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18369         }
18370     }
18371
18372   /* Emit code to decide on runtime whether library call or inline should be
18373      used.  */
18374   if (dynamic_check != -1)
18375     {
18376       if (CONST_INT_P (count_exp))
18377         {
18378           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
18379             {
18380               emit_block_move_via_libcall (dst, src, count_exp, false);
18381               count_exp = const0_rtx;
18382               goto epilogue;
18383             }
18384         }
18385       else
18386         {
18387           rtx hot_label = gen_label_rtx ();
18388           jump_around_label = gen_label_rtx ();
18389           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
18390                                    LEU, 0, GET_MODE (count_exp), 1, hot_label);
18391           predict_jump (REG_BR_PROB_BASE * 90 / 100);
18392           emit_block_move_via_libcall (dst, src, count_exp, false);
18393           emit_jump (jump_around_label);
18394           emit_label (hot_label);
18395         }
18396     }
18397
18398   /* Step 2: Alignment prologue.  */
18399
18400   if (desired_align > align)
18401     {
18402       if (align_bytes == 0)
18403         {
18404           /* Except for the first move in epilogue, we no longer know
18405              constant offset in aliasing info.  It don't seems to worth
18406              the pain to maintain it for the first move, so throw away
18407              the info early.  */
18408           src = change_address (src, BLKmode, srcreg);
18409           dst = change_address (dst, BLKmode, destreg);
18410           expand_movmem_prologue (dst, src, destreg, srcreg, count_exp, align,
18411                                   desired_align);
18412         }
18413       else
18414         {
18415           /* If we know how many bytes need to be stored before dst is
18416              sufficiently aligned, maintain aliasing info accurately.  */
18417           dst = expand_constant_movmem_prologue (dst, &src, destreg, srcreg,
18418                                                  desired_align, align_bytes);
18419           count_exp = plus_constant (count_exp, -align_bytes);
18420           count -= align_bytes;
18421         }
18422       if (need_zero_guard
18423           && (count < (unsigned HOST_WIDE_INT) size_needed
18424               || (align_bytes == 0
18425                   && count < ((unsigned HOST_WIDE_INT) size_needed
18426                               + desired_align - align))))
18427         {
18428           /* It is possible that we copied enough so the main loop will not
18429              execute.  */
18430           gcc_assert (size_needed > 1);
18431           if (label == NULL_RTX)
18432             label = gen_label_rtx ();
18433           emit_cmp_and_jump_insns (count_exp,
18434                                    GEN_INT (size_needed),
18435                                    LTU, 0, counter_mode (count_exp), 1, label);
18436           if (expected_size == -1
18437               || expected_size < (desired_align - align) / 2 + size_needed)
18438             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18439           else
18440             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18441         }
18442     }
18443   if (label && size_needed == 1)
18444     {
18445       emit_label (label);
18446       LABEL_NUSES (label) = 1;
18447       label = NULL;
18448       epilogue_size_needed = 1;
18449     }
18450   else if (label == NULL_RTX)
18451     epilogue_size_needed = size_needed;
18452
18453   /* Step 3: Main loop.  */
18454
18455   switch (alg)
18456     {
18457     case libcall:
18458     case no_stringop:
18459       gcc_unreachable ();
18460     case loop_1_byte:
18461       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
18462                                      count_exp, QImode, 1, expected_size);
18463       break;
18464     case loop:
18465       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
18466                                      count_exp, Pmode, 1, expected_size);
18467       break;
18468     case unrolled_loop:
18469       /* Unroll only by factor of 2 in 32bit mode, since we don't have enough
18470          registers for 4 temporaries anyway.  */
18471       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
18472                                      count_exp, Pmode, TARGET_64BIT ? 4 : 2,
18473                                      expected_size);
18474       break;
18475     case rep_prefix_8_byte:
18476       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
18477                                  DImode);
18478       break;
18479     case rep_prefix_4_byte:
18480       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
18481                                  SImode);
18482       break;
18483     case rep_prefix_1_byte:
18484       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
18485                                  QImode);
18486       break;
18487     }
18488   /* Adjust properly the offset of src and dest memory for aliasing.  */
18489   if (CONST_INT_P (count_exp))
18490     {
18491       src = adjust_automodify_address_nv (src, BLKmode, srcreg,
18492                                           (count / size_needed) * size_needed);
18493       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
18494                                           (count / size_needed) * size_needed);
18495     }
18496   else
18497     {
18498       src = change_address (src, BLKmode, srcreg);
18499       dst = change_address (dst, BLKmode, destreg);
18500     }
18501
18502   /* Step 4: Epilogue to copy the remaining bytes.  */
18503  epilogue:
18504   if (label)
18505     {
18506       /* When the main loop is done, COUNT_EXP might hold original count,
18507          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
18508          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
18509          bytes. Compensate if needed.  */
18510
18511       if (size_needed < epilogue_size_needed)
18512         {
18513           tmp =
18514             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
18515                                  GEN_INT (size_needed - 1), count_exp, 1,
18516                                  OPTAB_DIRECT);
18517           if (tmp != count_exp)
18518             emit_move_insn (count_exp, tmp);
18519         }
18520       emit_label (label);
18521       LABEL_NUSES (label) = 1;
18522     }
18523
18524   if (count_exp != const0_rtx && epilogue_size_needed > 1)
18525     expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
18526                             epilogue_size_needed);
18527   if (jump_around_label)
18528     emit_label (jump_around_label);
18529   return 1;
18530 }
18531
18532 /* Helper function for memcpy.  For QImode value 0xXY produce
18533    0xXYXYXYXY of wide specified by MODE.  This is essentially
18534    a * 0x10101010, but we can do slightly better than
18535    synth_mult by unwinding the sequence by hand on CPUs with
18536    slow multiply.  */
18537 static rtx
18538 promote_duplicated_reg (enum machine_mode mode, rtx val)
18539 {
18540   enum machine_mode valmode = GET_MODE (val);
18541   rtx tmp;
18542   int nops = mode == DImode ? 3 : 2;
18543
18544   gcc_assert (mode == SImode || mode == DImode);
18545   if (val == const0_rtx)
18546     return copy_to_mode_reg (mode, const0_rtx);
18547   if (CONST_INT_P (val))
18548     {
18549       HOST_WIDE_INT v = INTVAL (val) & 255;
18550
18551       v |= v << 8;
18552       v |= v << 16;
18553       if (mode == DImode)
18554         v |= (v << 16) << 16;
18555       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
18556     }
18557
18558   if (valmode == VOIDmode)
18559     valmode = QImode;
18560   if (valmode != QImode)
18561     val = gen_lowpart (QImode, val);
18562   if (mode == QImode)
18563     return val;
18564   if (!TARGET_PARTIAL_REG_STALL)
18565     nops--;
18566   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
18567       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
18568       <= (ix86_cost->shift_const + ix86_cost->add) * nops
18569           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
18570     {
18571       rtx reg = convert_modes (mode, QImode, val, true);
18572       tmp = promote_duplicated_reg (mode, const1_rtx);
18573       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
18574                                   OPTAB_DIRECT);
18575     }
18576   else
18577     {
18578       rtx reg = convert_modes (mode, QImode, val, true);
18579
18580       if (!TARGET_PARTIAL_REG_STALL)
18581         if (mode == SImode)
18582           emit_insn (gen_movsi_insv_1 (reg, reg));
18583         else
18584           emit_insn (gen_movdi_insv_1_rex64 (reg, reg));
18585       else
18586         {
18587           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
18588                                      NULL, 1, OPTAB_DIRECT);
18589           reg =
18590             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18591         }
18592       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
18593                                  NULL, 1, OPTAB_DIRECT);
18594       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18595       if (mode == SImode)
18596         return reg;
18597       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
18598                                  NULL, 1, OPTAB_DIRECT);
18599       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18600       return reg;
18601     }
18602 }
18603
18604 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
18605    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
18606    alignment from ALIGN to DESIRED_ALIGN.  */
18607 static rtx
18608 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align, int align)
18609 {
18610   rtx promoted_val;
18611
18612   if (TARGET_64BIT
18613       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
18614     promoted_val = promote_duplicated_reg (DImode, val);
18615   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
18616     promoted_val = promote_duplicated_reg (SImode, val);
18617   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
18618     promoted_val = promote_duplicated_reg (HImode, val);
18619   else
18620     promoted_val = val;
18621
18622   return promoted_val;
18623 }
18624
18625 /* Expand string clear operation (bzero).  Use i386 string operations when
18626    profitable.  See expand_movmem comment for explanation of individual
18627    steps performed.  */
18628 int
18629 ix86_expand_setmem (rtx dst, rtx count_exp, rtx val_exp, rtx align_exp,
18630                     rtx expected_align_exp, rtx expected_size_exp)
18631 {
18632   rtx destreg;
18633   rtx label = NULL;
18634   rtx tmp;
18635   rtx jump_around_label = NULL;
18636   HOST_WIDE_INT align = 1;
18637   unsigned HOST_WIDE_INT count = 0;
18638   HOST_WIDE_INT expected_size = -1;
18639   int size_needed = 0, epilogue_size_needed;
18640   int desired_align = 0, align_bytes = 0;
18641   enum stringop_alg alg;
18642   rtx promoted_val = NULL;
18643   bool force_loopy_epilogue = false;
18644   int dynamic_check;
18645   bool need_zero_guard = false;
18646
18647   if (CONST_INT_P (align_exp))
18648     align = INTVAL (align_exp);
18649   /* i386 can do misaligned access on reasonably increased cost.  */
18650   if (CONST_INT_P (expected_align_exp)
18651       && INTVAL (expected_align_exp) > align)
18652     align = INTVAL (expected_align_exp);
18653   if (CONST_INT_P (count_exp))
18654     count = expected_size = INTVAL (count_exp);
18655   if (CONST_INT_P (expected_size_exp) && count == 0)
18656     expected_size = INTVAL (expected_size_exp);
18657
18658   /* Make sure we don't need to care about overflow later on.  */
18659   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
18660     return 0;
18661
18662   /* Step 0: Decide on preferred algorithm, desired alignment and
18663      size of chunks to be copied by main loop.  */
18664
18665   alg = decide_alg (count, expected_size, true, &dynamic_check);
18666   desired_align = decide_alignment (align, alg, expected_size);
18667
18668   if (!TARGET_ALIGN_STRINGOPS)
18669     align = desired_align;
18670
18671   if (alg == libcall)
18672     return 0;
18673   gcc_assert (alg != no_stringop);
18674   if (!count)
18675     count_exp = copy_to_mode_reg (counter_mode (count_exp), count_exp);
18676   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
18677   switch (alg)
18678     {
18679     case libcall:
18680     case no_stringop:
18681       gcc_unreachable ();
18682     case loop:
18683       need_zero_guard = true;
18684       size_needed = GET_MODE_SIZE (Pmode);
18685       break;
18686     case unrolled_loop:
18687       need_zero_guard = true;
18688       size_needed = GET_MODE_SIZE (Pmode) * 4;
18689       break;
18690     case rep_prefix_8_byte:
18691       size_needed = 8;
18692       break;
18693     case rep_prefix_4_byte:
18694       size_needed = 4;
18695       break;
18696     case rep_prefix_1_byte:
18697       size_needed = 1;
18698       break;
18699     case loop_1_byte:
18700       need_zero_guard = true;
18701       size_needed = 1;
18702       break;
18703     }
18704   epilogue_size_needed = size_needed;
18705
18706   /* Step 1: Prologue guard.  */
18707
18708   /* Alignment code needs count to be in register.  */
18709   if (CONST_INT_P (count_exp) && desired_align > align)
18710     {
18711       if (INTVAL (count_exp) > desired_align
18712           && INTVAL (count_exp) > size_needed)
18713         {
18714           align_bytes
18715             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
18716           if (align_bytes <= 0)
18717             align_bytes = 0;
18718           else
18719             align_bytes = desired_align - align_bytes;
18720         }
18721       if (align_bytes == 0)
18722         {
18723           enum machine_mode mode = SImode;
18724           if (TARGET_64BIT && (count & ~0xffffffff))
18725             mode = DImode;
18726           count_exp = force_reg (mode, count_exp);
18727         }
18728     }
18729   /* Do the cheap promotion to allow better CSE across the
18730      main loop and epilogue (ie one load of the big constant in the
18731      front of all code.  */
18732   if (CONST_INT_P (val_exp))
18733     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
18734                                                    desired_align, align);
18735   /* Ensure that alignment prologue won't copy past end of block.  */
18736   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
18737     {
18738       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
18739       /* Epilogue always copies COUNT_EXP & (EPILOGUE_SIZE_NEEDED - 1) bytes.
18740          Make sure it is power of 2.  */
18741       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
18742
18743       /* To improve performance of small blocks, we jump around the VAL
18744          promoting mode.  This mean that if the promoted VAL is not constant,
18745          we might not use it in the epilogue and have to use byte
18746          loop variant.  */
18747       if (epilogue_size_needed > 2 && !promoted_val)
18748         force_loopy_epilogue = true;
18749       if (count)
18750         {
18751           if (count < (unsigned HOST_WIDE_INT)epilogue_size_needed)
18752             {
18753               /* If main algorithm works on QImode, no epilogue is needed.
18754                  For small sizes just don't align anything.  */
18755               if (size_needed == 1)
18756                 desired_align = align;
18757               else
18758                 goto epilogue;
18759             }
18760         }
18761       else
18762         {
18763           label = gen_label_rtx ();
18764           emit_cmp_and_jump_insns (count_exp,
18765                                    GEN_INT (epilogue_size_needed),
18766                                    LTU, 0, counter_mode (count_exp), 1, label);
18767           if (expected_size == -1 || expected_size <= epilogue_size_needed)
18768             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18769           else
18770             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18771         }
18772     }
18773   if (dynamic_check != -1)
18774     {
18775       rtx hot_label = gen_label_rtx ();
18776       jump_around_label = gen_label_rtx ();
18777       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
18778                                LEU, 0, counter_mode (count_exp), 1, hot_label);
18779       predict_jump (REG_BR_PROB_BASE * 90 / 100);
18780       set_storage_via_libcall (dst, count_exp, val_exp, false);
18781       emit_jump (jump_around_label);
18782       emit_label (hot_label);
18783     }
18784
18785   /* Step 2: Alignment prologue.  */
18786
18787   /* Do the expensive promotion once we branched off the small blocks.  */
18788   if (!promoted_val)
18789     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
18790                                                    desired_align, align);
18791   gcc_assert (desired_align >= 1 && align >= 1);
18792
18793   if (desired_align > align)
18794     {
18795       if (align_bytes == 0)
18796         {
18797           /* Except for the first move in epilogue, we no longer know
18798              constant offset in aliasing info.  It don't seems to worth
18799              the pain to maintain it for the first move, so throw away
18800              the info early.  */
18801           dst = change_address (dst, BLKmode, destreg);
18802           expand_setmem_prologue (dst, destreg, promoted_val, count_exp, align,
18803                                   desired_align);
18804         }
18805       else
18806         {
18807           /* If we know how many bytes need to be stored before dst is
18808              sufficiently aligned, maintain aliasing info accurately.  */
18809           dst = expand_constant_setmem_prologue (dst, destreg, promoted_val,
18810                                                  desired_align, align_bytes);
18811           count_exp = plus_constant (count_exp, -align_bytes);
18812           count -= align_bytes;
18813         }
18814       if (need_zero_guard
18815           && (count < (unsigned HOST_WIDE_INT) size_needed
18816               || (align_bytes == 0
18817                   && count < ((unsigned HOST_WIDE_INT) size_needed
18818                               + desired_align - align))))
18819         {
18820           /* It is possible that we copied enough so the main loop will not
18821              execute.  */
18822           gcc_assert (size_needed > 1);
18823           if (label == NULL_RTX)
18824             label = gen_label_rtx ();
18825           emit_cmp_and_jump_insns (count_exp,
18826                                    GEN_INT (size_needed),
18827                                    LTU, 0, counter_mode (count_exp), 1, label);
18828           if (expected_size == -1
18829               || expected_size < (desired_align - align) / 2 + size_needed)
18830             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18831           else
18832             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18833         }
18834     }
18835   if (label && size_needed == 1)
18836     {
18837       emit_label (label);
18838       LABEL_NUSES (label) = 1;
18839       label = NULL;
18840       promoted_val = val_exp;
18841       epilogue_size_needed = 1;
18842     }
18843   else if (label == NULL_RTX)
18844     epilogue_size_needed = size_needed;
18845
18846   /* Step 3: Main loop.  */
18847
18848   switch (alg)
18849     {
18850     case libcall:
18851     case no_stringop:
18852       gcc_unreachable ();
18853     case loop_1_byte:
18854       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18855                                      count_exp, QImode, 1, expected_size);
18856       break;
18857     case loop:
18858       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18859                                      count_exp, Pmode, 1, expected_size);
18860       break;
18861     case unrolled_loop:
18862       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18863                                      count_exp, Pmode, 4, expected_size);
18864       break;
18865     case rep_prefix_8_byte:
18866       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18867                                   DImode, val_exp);
18868       break;
18869     case rep_prefix_4_byte:
18870       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18871                                   SImode, val_exp);
18872       break;
18873     case rep_prefix_1_byte:
18874       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18875                                   QImode, val_exp);
18876       break;
18877     }
18878   /* Adjust properly the offset of src and dest memory for aliasing.  */
18879   if (CONST_INT_P (count_exp))
18880     dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
18881                                         (count / size_needed) * size_needed);
18882   else
18883     dst = change_address (dst, BLKmode, destreg);
18884
18885   /* Step 4: Epilogue to copy the remaining bytes.  */
18886
18887   if (label)
18888     {
18889       /* When the main loop is done, COUNT_EXP might hold original count,
18890          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
18891          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
18892          bytes. Compensate if needed.  */
18893
18894       if (size_needed < epilogue_size_needed)
18895         {
18896           tmp =
18897             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
18898                                  GEN_INT (size_needed - 1), count_exp, 1,
18899                                  OPTAB_DIRECT);
18900           if (tmp != count_exp)
18901             emit_move_insn (count_exp, tmp);
18902         }
18903       emit_label (label);
18904       LABEL_NUSES (label) = 1;
18905     }
18906  epilogue:
18907   if (count_exp != const0_rtx && epilogue_size_needed > 1)
18908     {
18909       if (force_loopy_epilogue)
18910         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
18911                                          epilogue_size_needed);
18912       else
18913         expand_setmem_epilogue (dst, destreg, promoted_val, count_exp,
18914                                 epilogue_size_needed);
18915     }
18916   if (jump_around_label)
18917     emit_label (jump_around_label);
18918   return 1;
18919 }
18920
18921 /* Expand the appropriate insns for doing strlen if not just doing
18922    repnz; scasb
18923
18924    out = result, initialized with the start address
18925    align_rtx = alignment of the address.
18926    scratch = scratch register, initialized with the startaddress when
18927         not aligned, otherwise undefined
18928
18929    This is just the body. It needs the initializations mentioned above and
18930    some address computing at the end.  These things are done in i386.md.  */
18931
18932 static void
18933 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
18934 {
18935   int align;
18936   rtx tmp;
18937   rtx align_2_label = NULL_RTX;
18938   rtx align_3_label = NULL_RTX;
18939   rtx align_4_label = gen_label_rtx ();
18940   rtx end_0_label = gen_label_rtx ();
18941   rtx mem;
18942   rtx tmpreg = gen_reg_rtx (SImode);
18943   rtx scratch = gen_reg_rtx (SImode);
18944   rtx cmp;
18945
18946   align = 0;
18947   if (CONST_INT_P (align_rtx))
18948     align = INTVAL (align_rtx);
18949
18950   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
18951
18952   /* Is there a known alignment and is it less than 4?  */
18953   if (align < 4)
18954     {
18955       rtx scratch1 = gen_reg_rtx (Pmode);
18956       emit_move_insn (scratch1, out);
18957       /* Is there a known alignment and is it not 2? */
18958       if (align != 2)
18959         {
18960           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
18961           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
18962
18963           /* Leave just the 3 lower bits.  */
18964           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
18965                                     NULL_RTX, 0, OPTAB_WIDEN);
18966
18967           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
18968                                    Pmode, 1, align_4_label);
18969           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
18970                                    Pmode, 1, align_2_label);
18971           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
18972                                    Pmode, 1, align_3_label);
18973         }
18974       else
18975         {
18976           /* Since the alignment is 2, we have to check 2 or 0 bytes;
18977              check if is aligned to 4 - byte.  */
18978
18979           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
18980                                     NULL_RTX, 0, OPTAB_WIDEN);
18981
18982           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
18983                                    Pmode, 1, align_4_label);
18984         }
18985
18986       mem = change_address (src, QImode, out);
18987
18988       /* Now compare the bytes.  */
18989
18990       /* Compare the first n unaligned byte on a byte per byte basis.  */
18991       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
18992                                QImode, 1, end_0_label);
18993
18994       /* Increment the address.  */
18995       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18996
18997       /* Not needed with an alignment of 2 */
18998       if (align != 2)
18999         {
19000           emit_label (align_2_label);
19001
19002           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
19003                                    end_0_label);
19004
19005           emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
19006
19007           emit_label (align_3_label);
19008         }
19009
19010       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
19011                                end_0_label);
19012
19013       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
19014     }
19015
19016   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
19017      align this loop.  It gives only huge programs, but does not help to
19018      speed up.  */
19019   emit_label (align_4_label);
19020
19021   mem = change_address (src, SImode, out);
19022   emit_move_insn (scratch, mem);
19023   emit_insn ((*ix86_gen_add3) (out, out, GEN_INT (4)));
19024
19025   /* This formula yields a nonzero result iff one of the bytes is zero.
19026      This saves three branches inside loop and many cycles.  */
19027
19028   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
19029   emit_insn (gen_one_cmplsi2 (scratch, scratch));
19030   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
19031   emit_insn (gen_andsi3 (tmpreg, tmpreg,
19032                          gen_int_mode (0x80808080, SImode)));
19033   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
19034                            align_4_label);
19035
19036   if (TARGET_CMOVE)
19037     {
19038        rtx reg = gen_reg_rtx (SImode);
19039        rtx reg2 = gen_reg_rtx (Pmode);
19040        emit_move_insn (reg, tmpreg);
19041        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
19042
19043        /* If zero is not in the first two bytes, move two bytes forward.  */
19044        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
19045        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
19046        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
19047        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
19048                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
19049                                                      reg,
19050                                                      tmpreg)));
19051        /* Emit lea manually to avoid clobbering of flags.  */
19052        emit_insn (gen_rtx_SET (SImode, reg2,
19053                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
19054
19055        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
19056        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
19057        emit_insn (gen_rtx_SET (VOIDmode, out,
19058                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
19059                                                      reg2,
19060                                                      out)));
19061
19062     }
19063   else
19064     {
19065        rtx end_2_label = gen_label_rtx ();
19066        /* Is zero in the first two bytes? */
19067
19068        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
19069        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
19070        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
19071        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
19072                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
19073                             pc_rtx);
19074        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
19075        JUMP_LABEL (tmp) = end_2_label;
19076
19077        /* Not in the first two.  Move two bytes forward.  */
19078        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
19079        emit_insn ((*ix86_gen_add3) (out, out, const2_rtx));
19080
19081        emit_label (end_2_label);
19082
19083     }
19084
19085   /* Avoid branch in fixing the byte.  */
19086   tmpreg = gen_lowpart (QImode, tmpreg);
19087   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
19088   cmp = gen_rtx_LTU (Pmode, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx);
19089   emit_insn ((*ix86_gen_sub3_carry) (out, out, GEN_INT (3), cmp));
19090
19091   emit_label (end_0_label);
19092 }
19093
19094 /* Expand strlen.  */
19095
19096 int
19097 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
19098 {
19099   rtx addr, scratch1, scratch2, scratch3, scratch4;
19100
19101   /* The generic case of strlen expander is long.  Avoid it's
19102      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
19103
19104   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
19105       && !TARGET_INLINE_ALL_STRINGOPS
19106       && !optimize_insn_for_size_p ()
19107       && (!CONST_INT_P (align) || INTVAL (align) < 4))
19108     return 0;
19109
19110   addr = force_reg (Pmode, XEXP (src, 0));
19111   scratch1 = gen_reg_rtx (Pmode);
19112
19113   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
19114       && !optimize_insn_for_size_p ())
19115     {
19116       /* Well it seems that some optimizer does not combine a call like
19117          foo(strlen(bar), strlen(bar));
19118          when the move and the subtraction is done here.  It does calculate
19119          the length just once when these instructions are done inside of
19120          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
19121          often used and I use one fewer register for the lifetime of
19122          output_strlen_unroll() this is better.  */
19123
19124       emit_move_insn (out, addr);
19125
19126       ix86_expand_strlensi_unroll_1 (out, src, align);
19127
19128       /* strlensi_unroll_1 returns the address of the zero at the end of
19129          the string, like memchr(), so compute the length by subtracting
19130          the start address.  */
19131       emit_insn ((*ix86_gen_sub3) (out, out, addr));
19132     }
19133   else
19134     {
19135       rtx unspec;
19136
19137       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
19138       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
19139         return false;
19140
19141       scratch2 = gen_reg_rtx (Pmode);
19142       scratch3 = gen_reg_rtx (Pmode);
19143       scratch4 = force_reg (Pmode, constm1_rtx);
19144
19145       emit_move_insn (scratch3, addr);
19146       eoschar = force_reg (QImode, eoschar);
19147
19148       src = replace_equiv_address_nv (src, scratch3);
19149
19150       /* If .md starts supporting :P, this can be done in .md.  */
19151       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
19152                                                  scratch4), UNSPEC_SCAS);
19153       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
19154       emit_insn ((*ix86_gen_one_cmpl2) (scratch2, scratch1));
19155       emit_insn ((*ix86_gen_add3) (out, scratch2, constm1_rtx));
19156     }
19157   return 1;
19158 }
19159
19160 /* For given symbol (function) construct code to compute address of it's PLT
19161    entry in large x86-64 PIC model.  */
19162 rtx
19163 construct_plt_address (rtx symbol)
19164 {
19165   rtx tmp = gen_reg_rtx (Pmode);
19166   rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
19167
19168   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
19169   gcc_assert (ix86_cmodel == CM_LARGE_PIC);
19170
19171   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
19172   emit_insn (gen_adddi3 (tmp, tmp, pic_offset_table_rtx));
19173   return tmp;
19174 }
19175
19176 void
19177 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
19178                   rtx callarg2,
19179                   rtx pop, int sibcall)
19180 {
19181   rtx use = NULL, call;
19182
19183   if (pop == const0_rtx)
19184     pop = NULL;
19185   gcc_assert (!TARGET_64BIT || !pop);
19186
19187   if (TARGET_MACHO && !TARGET_64BIT)
19188     {
19189 #if TARGET_MACHO
19190       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
19191         fnaddr = machopic_indirect_call_target (fnaddr);
19192 #endif
19193     }
19194   else
19195     {
19196       /* Static functions and indirect calls don't need the pic register.  */
19197       if (flag_pic && (!TARGET_64BIT || ix86_cmodel == CM_LARGE_PIC)
19198           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
19199           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
19200         use_reg (&use, pic_offset_table_rtx);
19201     }
19202
19203   if (TARGET_64BIT && INTVAL (callarg2) >= 0)
19204     {
19205       rtx al = gen_rtx_REG (QImode, AX_REG);
19206       emit_move_insn (al, callarg2);
19207       use_reg (&use, al);
19208     }
19209
19210   if (ix86_cmodel == CM_LARGE_PIC
19211       && MEM_P (fnaddr) 
19212       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
19213       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
19214     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
19215   else if (sibcall
19216            ? !sibcall_insn_operand (XEXP (fnaddr, 0), Pmode)
19217            : !call_insn_operand (XEXP (fnaddr, 0), Pmode))
19218     {
19219       fnaddr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
19220       fnaddr = gen_rtx_MEM (QImode, fnaddr);
19221     }
19222
19223   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
19224   if (retval)
19225     call = gen_rtx_SET (VOIDmode, retval, call);
19226   if (pop)
19227     {
19228       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
19229       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
19230       call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop));
19231     }
19232   if (TARGET_64BIT
19233       && ix86_cfun_abi () == MS_ABI
19234       && (!callarg2 || INTVAL (callarg2) != -2))
19235     {
19236       /* We need to represent that SI and DI registers are clobbered
19237          by SYSV calls.  */
19238       static int clobbered_registers[] = {
19239         XMM6_REG, XMM7_REG, XMM8_REG,
19240         XMM9_REG, XMM10_REG, XMM11_REG,
19241         XMM12_REG, XMM13_REG, XMM14_REG,
19242         XMM15_REG, SI_REG, DI_REG
19243       };
19244       unsigned int i;
19245       rtx vec[ARRAY_SIZE (clobbered_registers) + 2];
19246       rtx unspec = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, const0_rtx),
19247                                    UNSPEC_MS_TO_SYSV_CALL);
19248
19249       vec[0] = call;
19250       vec[1] = unspec;
19251       for (i = 0; i < ARRAY_SIZE (clobbered_registers); i++)
19252         vec[i + 2] = gen_rtx_CLOBBER (SSE_REGNO_P (clobbered_registers[i])
19253                                       ? TImode : DImode,
19254                                       gen_rtx_REG
19255                                         (SSE_REGNO_P (clobbered_registers[i])
19256                                                       ? TImode : DImode,
19257                                          clobbered_registers[i]));
19258
19259       call = gen_rtx_PARALLEL (VOIDmode,
19260                                gen_rtvec_v (ARRAY_SIZE (clobbered_registers)
19261                                + 2, vec));
19262     }
19263
19264   call = emit_call_insn (call);
19265   if (use)
19266     CALL_INSN_FUNCTION_USAGE (call) = use;
19267 }
19268
19269 \f
19270 /* Clear stack slot assignments remembered from previous functions.
19271    This is called from INIT_EXPANDERS once before RTL is emitted for each
19272    function.  */
19273
19274 static struct machine_function *
19275 ix86_init_machine_status (void)
19276 {
19277   struct machine_function *f;
19278
19279   f = GGC_CNEW (struct machine_function);
19280   f->use_fast_prologue_epilogue_nregs = -1;
19281   f->tls_descriptor_call_expanded_p = 0;
19282   f->call_abi = ix86_abi;
19283
19284   return f;
19285 }
19286
19287 /* Return a MEM corresponding to a stack slot with mode MODE.
19288    Allocate a new slot if necessary.
19289
19290    The RTL for a function can have several slots available: N is
19291    which slot to use.  */
19292
19293 rtx
19294 assign_386_stack_local (enum machine_mode mode, enum ix86_stack_slot n)
19295 {
19296   struct stack_local_entry *s;
19297
19298   gcc_assert (n < MAX_386_STACK_LOCALS);
19299
19300   /* Virtual slot is valid only before vregs are instantiated.  */
19301   gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
19302
19303   for (s = ix86_stack_locals; s; s = s->next)
19304     if (s->mode == mode && s->n == n)
19305       return copy_rtx (s->rtl);
19306
19307   s = (struct stack_local_entry *)
19308     ggc_alloc (sizeof (struct stack_local_entry));
19309   s->n = n;
19310   s->mode = mode;
19311   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
19312
19313   s->next = ix86_stack_locals;
19314   ix86_stack_locals = s;
19315   return s->rtl;
19316 }
19317
19318 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
19319
19320 static GTY(()) rtx ix86_tls_symbol;
19321 rtx
19322 ix86_tls_get_addr (void)
19323 {
19324
19325   if (!ix86_tls_symbol)
19326     {
19327       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode,
19328                                             (TARGET_ANY_GNU_TLS
19329                                              && !TARGET_64BIT)
19330                                             ? "___tls_get_addr"
19331                                             : "__tls_get_addr");
19332     }
19333
19334   return ix86_tls_symbol;
19335 }
19336
19337 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
19338
19339 static GTY(()) rtx ix86_tls_module_base_symbol;
19340 rtx
19341 ix86_tls_module_base (void)
19342 {
19343
19344   if (!ix86_tls_module_base_symbol)
19345     {
19346       ix86_tls_module_base_symbol = gen_rtx_SYMBOL_REF (Pmode,
19347                                                         "_TLS_MODULE_BASE_");
19348       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
19349         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
19350     }
19351
19352   return ix86_tls_module_base_symbol;
19353 }
19354 \f
19355 /* Calculate the length of the memory address in the instruction
19356    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
19357
19358 int
19359 memory_address_length (rtx addr)
19360 {
19361   struct ix86_address parts;
19362   rtx base, index, disp;
19363   int len;
19364   int ok;
19365
19366   if (GET_CODE (addr) == PRE_DEC
19367       || GET_CODE (addr) == POST_INC
19368       || GET_CODE (addr) == PRE_MODIFY
19369       || GET_CODE (addr) == POST_MODIFY)
19370     return 0;
19371
19372   ok = ix86_decompose_address (addr, &parts);
19373   gcc_assert (ok);
19374
19375   if (parts.base && GET_CODE (parts.base) == SUBREG)
19376     parts.base = SUBREG_REG (parts.base);
19377   if (parts.index && GET_CODE (parts.index) == SUBREG)
19378     parts.index = SUBREG_REG (parts.index);
19379
19380   base = parts.base;
19381   index = parts.index;
19382   disp = parts.disp;
19383   len = 0;
19384
19385   /* Rule of thumb:
19386        - esp as the base always wants an index,
19387        - ebp as the base always wants a displacement,
19388        - r12 as the base always wants an index,
19389        - r13 as the base always wants a displacement.  */
19390
19391   /* Register Indirect.  */
19392   if (base && !index && !disp)
19393     {
19394       /* esp (for its index) and ebp (for its displacement) need
19395          the two-byte modrm form.  Similarly for r12 and r13 in 64-bit
19396          code.  */
19397       if (REG_P (addr)
19398           && (addr == arg_pointer_rtx
19399               || addr == frame_pointer_rtx
19400               || REGNO (addr) == SP_REG
19401               || REGNO (addr) == BP_REG
19402               || REGNO (addr) == R12_REG
19403               || REGNO (addr) == R13_REG))
19404         len = 1;
19405     }
19406
19407   /* Direct Addressing.  In 64-bit mode mod 00 r/m 5
19408      is not disp32, but disp32(%rip), so for disp32
19409      SIB byte is needed, unless print_operand_address
19410      optimizes it into disp32(%rip) or (%rip) is implied
19411      by UNSPEC.  */
19412   else if (disp && !base && !index)
19413     {
19414       len = 4;
19415       if (TARGET_64BIT)
19416         {
19417           rtx symbol = disp;
19418
19419           if (GET_CODE (disp) == CONST)
19420             symbol = XEXP (disp, 0);
19421           if (GET_CODE (symbol) == PLUS
19422               && CONST_INT_P (XEXP (symbol, 1)))
19423             symbol = XEXP (symbol, 0);
19424
19425           if (GET_CODE (symbol) != LABEL_REF
19426               && (GET_CODE (symbol) != SYMBOL_REF
19427                   || SYMBOL_REF_TLS_MODEL (symbol) != 0)
19428               && (GET_CODE (symbol) != UNSPEC
19429                   || (XINT (symbol, 1) != UNSPEC_GOTPCREL
19430                       && XINT (symbol, 1) != UNSPEC_GOTNTPOFF)))
19431             len += 1;
19432         }
19433     }
19434
19435   else
19436     {
19437       /* Find the length of the displacement constant.  */
19438       if (disp)
19439         {
19440           if (base && satisfies_constraint_K (disp))
19441             len = 1;
19442           else
19443             len = 4;
19444         }
19445       /* ebp always wants a displacement.  Similarly r13.  */
19446       else if (base && REG_P (base)
19447                && (REGNO (base) == BP_REG || REGNO (base) == R13_REG))
19448         len = 1;
19449
19450       /* An index requires the two-byte modrm form....  */
19451       if (index
19452           /* ...like esp (or r12), which always wants an index.  */
19453           || base == arg_pointer_rtx
19454           || base == frame_pointer_rtx
19455           || (base && REG_P (base)
19456               && (REGNO (base) == SP_REG || REGNO (base) == R12_REG)))
19457         len += 1;
19458     }
19459
19460   switch (parts.seg)
19461     {
19462     case SEG_FS:
19463     case SEG_GS:
19464       len += 1;
19465       break;
19466     default:
19467       break;
19468     }
19469
19470   return len;
19471 }
19472
19473 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
19474    is set, expect that insn have 8bit immediate alternative.  */
19475 int
19476 ix86_attr_length_immediate_default (rtx insn, int shortform)
19477 {
19478   int len = 0;
19479   int i;
19480   extract_insn_cached (insn);
19481   for (i = recog_data.n_operands - 1; i >= 0; --i)
19482     if (CONSTANT_P (recog_data.operand[i]))
19483       {
19484         enum attr_mode mode = get_attr_mode (insn);
19485
19486         gcc_assert (!len);
19487         if (shortform && CONST_INT_P (recog_data.operand[i]))
19488           {
19489             HOST_WIDE_INT ival = INTVAL (recog_data.operand[i]);
19490             switch (mode)
19491               {
19492               case MODE_QI:
19493                 len = 1;
19494                 continue;
19495               case MODE_HI:
19496                 ival = trunc_int_for_mode (ival, HImode);
19497                 break;
19498               case MODE_SI:
19499                 ival = trunc_int_for_mode (ival, SImode);
19500                 break;
19501               default:
19502                 break;
19503               }
19504             if (IN_RANGE (ival, -128, 127))
19505               {
19506                 len = 1;
19507                 continue;
19508               }
19509           }
19510         switch (mode)
19511           {
19512           case MODE_QI:
19513             len = 1;
19514             break;
19515           case MODE_HI:
19516             len = 2;
19517             break;
19518           case MODE_SI:
19519             len = 4;
19520             break;
19521           /* Immediates for DImode instructions are encoded as 32bit sign extended values.  */
19522           case MODE_DI:
19523             len = 4;
19524             break;
19525           default:
19526             fatal_insn ("unknown insn mode", insn);
19527         }
19528       }
19529   return len;
19530 }
19531 /* Compute default value for "length_address" attribute.  */
19532 int
19533 ix86_attr_length_address_default (rtx insn)
19534 {
19535   int i;
19536
19537   if (get_attr_type (insn) == TYPE_LEA)
19538     {
19539       rtx set = PATTERN (insn), addr;
19540
19541       if (GET_CODE (set) == PARALLEL)
19542         set = XVECEXP (set, 0, 0);
19543
19544       gcc_assert (GET_CODE (set) == SET);
19545
19546       addr = SET_SRC (set);
19547       if (TARGET_64BIT && get_attr_mode (insn) == MODE_SI)
19548         {
19549           if (GET_CODE (addr) == ZERO_EXTEND)
19550             addr = XEXP (addr, 0);
19551           if (GET_CODE (addr) == SUBREG)
19552             addr = SUBREG_REG (addr);
19553         }
19554
19555       return memory_address_length (addr);
19556     }
19557
19558   extract_insn_cached (insn);
19559   for (i = recog_data.n_operands - 1; i >= 0; --i)
19560     if (MEM_P (recog_data.operand[i]))
19561       {
19562         constrain_operands_cached (reload_completed);
19563         if (which_alternative != -1)
19564           {
19565             const char *constraints = recog_data.constraints[i];
19566             int alt = which_alternative;
19567
19568             while (*constraints == '=' || *constraints == '+')
19569               constraints++;
19570             while (alt-- > 0)
19571               while (*constraints++ != ',')
19572                 ;
19573             /* Skip ignored operands.  */
19574             if (*constraints == 'X')
19575               continue;
19576           }
19577         return memory_address_length (XEXP (recog_data.operand[i], 0));
19578       }
19579   return 0;
19580 }
19581
19582 /* Compute default value for "length_vex" attribute. It includes
19583    2 or 3 byte VEX prefix and 1 opcode byte.  */
19584
19585 int
19586 ix86_attr_length_vex_default (rtx insn, int has_0f_opcode,
19587                               int has_vex_w)
19588 {
19589   int i;
19590
19591   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
19592      byte VEX prefix.  */
19593   if (!has_0f_opcode || has_vex_w)
19594     return 3 + 1;
19595
19596  /* We can always use 2 byte VEX prefix in 32bit.  */
19597   if (!TARGET_64BIT)
19598     return 2 + 1;
19599
19600   extract_insn_cached (insn);
19601
19602   for (i = recog_data.n_operands - 1; i >= 0; --i)
19603     if (REG_P (recog_data.operand[i]))
19604       {
19605         /* REX.W bit uses 3 byte VEX prefix.  */
19606         if (GET_MODE (recog_data.operand[i]) == DImode
19607             && GENERAL_REG_P (recog_data.operand[i]))
19608           return 3 + 1;
19609       }
19610     else
19611       {
19612         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
19613         if (MEM_P (recog_data.operand[i])
19614             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
19615           return 3 + 1;
19616       }
19617
19618   return 2 + 1;
19619 }
19620 \f
19621 /* Return the maximum number of instructions a cpu can issue.  */
19622
19623 static int
19624 ix86_issue_rate (void)
19625 {
19626   switch (ix86_tune)
19627     {
19628     case PROCESSOR_PENTIUM:
19629     case PROCESSOR_ATOM:
19630     case PROCESSOR_K6:
19631       return 2;
19632
19633     case PROCESSOR_PENTIUMPRO:
19634     case PROCESSOR_PENTIUM4:
19635     case PROCESSOR_ATHLON:
19636     case PROCESSOR_K8:
19637     case PROCESSOR_AMDFAM10:
19638     case PROCESSOR_NOCONA:
19639     case PROCESSOR_GENERIC32:
19640     case PROCESSOR_GENERIC64:
19641       return 3;
19642
19643     case PROCESSOR_CORE2:
19644       return 4;
19645
19646     default:
19647       return 1;
19648     }
19649 }
19650
19651 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
19652    by DEP_INSN and nothing set by DEP_INSN.  */
19653
19654 static int
19655 ix86_flags_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
19656 {
19657   rtx set, set2;
19658
19659   /* Simplify the test for uninteresting insns.  */
19660   if (insn_type != TYPE_SETCC
19661       && insn_type != TYPE_ICMOV
19662       && insn_type != TYPE_FCMOV
19663       && insn_type != TYPE_IBR)
19664     return 0;
19665
19666   if ((set = single_set (dep_insn)) != 0)
19667     {
19668       set = SET_DEST (set);
19669       set2 = NULL_RTX;
19670     }
19671   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
19672            && XVECLEN (PATTERN (dep_insn), 0) == 2
19673            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
19674            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
19675     {
19676       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
19677       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
19678     }
19679   else
19680     return 0;
19681
19682   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
19683     return 0;
19684
19685   /* This test is true if the dependent insn reads the flags but
19686      not any other potentially set register.  */
19687   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
19688     return 0;
19689
19690   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
19691     return 0;
19692
19693   return 1;
19694 }
19695
19696 /* Return true iff USE_INSN has a memory address with operands set by
19697    SET_INSN.  */
19698
19699 bool
19700 ix86_agi_dependent (rtx set_insn, rtx use_insn)
19701 {
19702   int i;
19703   extract_insn_cached (use_insn);
19704   for (i = recog_data.n_operands - 1; i >= 0; --i)
19705     if (MEM_P (recog_data.operand[i]))
19706       {
19707         rtx addr = XEXP (recog_data.operand[i], 0);
19708         return modified_in_p (addr, set_insn) != 0;
19709       }
19710   return false;
19711 }
19712
19713 static int
19714 ix86_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
19715 {
19716   enum attr_type insn_type, dep_insn_type;
19717   enum attr_memory memory;
19718   rtx set, set2;
19719   int dep_insn_code_number;
19720
19721   /* Anti and output dependencies have zero cost on all CPUs.  */
19722   if (REG_NOTE_KIND (link) != 0)
19723     return 0;
19724
19725   dep_insn_code_number = recog_memoized (dep_insn);
19726
19727   /* If we can't recognize the insns, we can't really do anything.  */
19728   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
19729     return cost;
19730
19731   insn_type = get_attr_type (insn);
19732   dep_insn_type = get_attr_type (dep_insn);
19733
19734   switch (ix86_tune)
19735     {
19736     case PROCESSOR_PENTIUM:
19737       /* Address Generation Interlock adds a cycle of latency.  */
19738       if (insn_type == TYPE_LEA)
19739         {
19740           rtx addr = PATTERN (insn);
19741
19742           if (GET_CODE (addr) == PARALLEL)
19743             addr = XVECEXP (addr, 0, 0);
19744
19745           gcc_assert (GET_CODE (addr) == SET);
19746
19747           addr = SET_SRC (addr);
19748           if (modified_in_p (addr, dep_insn))
19749             cost += 1;
19750         }
19751       else if (ix86_agi_dependent (dep_insn, insn))
19752         cost += 1;
19753
19754       /* ??? Compares pair with jump/setcc.  */
19755       if (ix86_flags_dependent (insn, dep_insn, insn_type))
19756         cost = 0;
19757
19758       /* Floating point stores require value to be ready one cycle earlier.  */
19759       if (insn_type == TYPE_FMOV
19760           && get_attr_memory (insn) == MEMORY_STORE
19761           && !ix86_agi_dependent (dep_insn, insn))
19762         cost += 1;
19763       break;
19764
19765     case PROCESSOR_PENTIUMPRO:
19766       memory = get_attr_memory (insn);
19767
19768       /* INT->FP conversion is expensive.  */
19769       if (get_attr_fp_int_src (dep_insn))
19770         cost += 5;
19771
19772       /* There is one cycle extra latency between an FP op and a store.  */
19773       if (insn_type == TYPE_FMOV
19774           && (set = single_set (dep_insn)) != NULL_RTX
19775           && (set2 = single_set (insn)) != NULL_RTX
19776           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
19777           && MEM_P (SET_DEST (set2)))
19778         cost += 1;
19779
19780       /* Show ability of reorder buffer to hide latency of load by executing
19781          in parallel with previous instruction in case
19782          previous instruction is not needed to compute the address.  */
19783       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19784           && !ix86_agi_dependent (dep_insn, insn))
19785         {
19786           /* Claim moves to take one cycle, as core can issue one load
19787              at time and the next load can start cycle later.  */
19788           if (dep_insn_type == TYPE_IMOV
19789               || dep_insn_type == TYPE_FMOV)
19790             cost = 1;
19791           else if (cost > 1)
19792             cost--;
19793         }
19794       break;
19795
19796     case PROCESSOR_K6:
19797       memory = get_attr_memory (insn);
19798
19799       /* The esp dependency is resolved before the instruction is really
19800          finished.  */
19801       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
19802           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
19803         return 1;
19804
19805       /* INT->FP conversion is expensive.  */
19806       if (get_attr_fp_int_src (dep_insn))
19807         cost += 5;
19808
19809       /* Show ability of reorder buffer to hide latency of load by executing
19810          in parallel with previous instruction in case
19811          previous instruction is not needed to compute the address.  */
19812       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19813           && !ix86_agi_dependent (dep_insn, insn))
19814         {
19815           /* Claim moves to take one cycle, as core can issue one load
19816              at time and the next load can start cycle later.  */
19817           if (dep_insn_type == TYPE_IMOV
19818               || dep_insn_type == TYPE_FMOV)
19819             cost = 1;
19820           else if (cost > 2)
19821             cost -= 2;
19822           else
19823             cost = 1;
19824         }
19825       break;
19826
19827     case PROCESSOR_ATHLON:
19828     case PROCESSOR_K8:
19829     case PROCESSOR_AMDFAM10:
19830     case PROCESSOR_ATOM:
19831     case PROCESSOR_GENERIC32:
19832     case PROCESSOR_GENERIC64:
19833       memory = get_attr_memory (insn);
19834
19835       /* Show ability of reorder buffer to hide latency of load by executing
19836          in parallel with previous instruction in case
19837          previous instruction is not needed to compute the address.  */
19838       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19839           && !ix86_agi_dependent (dep_insn, insn))
19840         {
19841           enum attr_unit unit = get_attr_unit (insn);
19842           int loadcost = 3;
19843
19844           /* Because of the difference between the length of integer and
19845              floating unit pipeline preparation stages, the memory operands
19846              for floating point are cheaper.
19847
19848              ??? For Athlon it the difference is most probably 2.  */
19849           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
19850             loadcost = 3;
19851           else
19852             loadcost = TARGET_ATHLON ? 2 : 0;
19853
19854           if (cost >= loadcost)
19855             cost -= loadcost;
19856           else
19857             cost = 0;
19858         }
19859
19860     default:
19861       break;
19862     }
19863
19864   return cost;
19865 }
19866
19867 /* How many alternative schedules to try.  This should be as wide as the
19868    scheduling freedom in the DFA, but no wider.  Making this value too
19869    large results extra work for the scheduler.  */
19870
19871 static int
19872 ia32_multipass_dfa_lookahead (void)
19873 {
19874   switch (ix86_tune)
19875     {
19876     case PROCESSOR_PENTIUM:
19877       return 2;
19878
19879     case PROCESSOR_PENTIUMPRO:
19880     case PROCESSOR_K6:
19881       return 1;
19882
19883     default:
19884       return 0;
19885     }
19886 }
19887
19888 \f
19889 /* Compute the alignment given to a constant that is being placed in memory.
19890    EXP is the constant and ALIGN is the alignment that the object would
19891    ordinarily have.
19892    The value of this function is used instead of that alignment to align
19893    the object.  */
19894
19895 int
19896 ix86_constant_alignment (tree exp, int align)
19897 {
19898   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
19899       || TREE_CODE (exp) == INTEGER_CST)
19900     {
19901       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
19902         return 64;
19903       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
19904         return 128;
19905     }
19906   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
19907            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
19908     return BITS_PER_WORD;
19909
19910   return align;
19911 }
19912
19913 /* Compute the alignment for a static variable.
19914    TYPE is the data type, and ALIGN is the alignment that
19915    the object would ordinarily have.  The value of this function is used
19916    instead of that alignment to align the object.  */
19917
19918 int
19919 ix86_data_alignment (tree type, int align)
19920 {
19921   int max_align = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
19922
19923   if (AGGREGATE_TYPE_P (type)
19924       && TYPE_SIZE (type)
19925       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19926       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= (unsigned) max_align
19927           || TREE_INT_CST_HIGH (TYPE_SIZE (type)))
19928       && align < max_align)
19929     align = max_align;
19930
19931   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
19932      to 16byte boundary.  */
19933   if (TARGET_64BIT)
19934     {
19935       if (AGGREGATE_TYPE_P (type)
19936            && TYPE_SIZE (type)
19937            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19938            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 128
19939                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
19940         return 128;
19941     }
19942
19943   if (TREE_CODE (type) == ARRAY_TYPE)
19944     {
19945       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
19946         return 64;
19947       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
19948         return 128;
19949     }
19950   else if (TREE_CODE (type) == COMPLEX_TYPE)
19951     {
19952
19953       if (TYPE_MODE (type) == DCmode && align < 64)
19954         return 64;
19955       if ((TYPE_MODE (type) == XCmode
19956            || TYPE_MODE (type) == TCmode) && align < 128)
19957         return 128;
19958     }
19959   else if ((TREE_CODE (type) == RECORD_TYPE
19960             || TREE_CODE (type) == UNION_TYPE
19961             || TREE_CODE (type) == QUAL_UNION_TYPE)
19962            && TYPE_FIELDS (type))
19963     {
19964       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
19965         return 64;
19966       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
19967         return 128;
19968     }
19969   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
19970            || TREE_CODE (type) == INTEGER_TYPE)
19971     {
19972       if (TYPE_MODE (type) == DFmode && align < 64)
19973         return 64;
19974       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
19975         return 128;
19976     }
19977
19978   return align;
19979 }
19980
19981 /* Compute the alignment for a local variable or a stack slot.  EXP is
19982    the data type or decl itself, MODE is the widest mode available and
19983    ALIGN is the alignment that the object would ordinarily have.  The
19984    value of this macro is used instead of that alignment to align the
19985    object.  */
19986
19987 unsigned int
19988 ix86_local_alignment (tree exp, enum machine_mode mode,
19989                       unsigned int align)
19990 {
19991   tree type, decl;
19992
19993   if (exp && DECL_P (exp))
19994     {
19995       type = TREE_TYPE (exp);
19996       decl = exp;
19997     }
19998   else
19999     {
20000       type = exp;
20001       decl = NULL;
20002     }
20003
20004   /* Don't do dynamic stack realignment for long long objects with
20005      -mpreferred-stack-boundary=2.  */
20006   if (!TARGET_64BIT
20007       && align == 64
20008       && ix86_preferred_stack_boundary < 64
20009       && (mode == DImode || (type && TYPE_MODE (type) == DImode))
20010       && (!type || !TYPE_USER_ALIGN (type))
20011       && (!decl || !DECL_USER_ALIGN (decl)))
20012     align = 32;
20013
20014   /* If TYPE is NULL, we are allocating a stack slot for caller-save
20015      register in MODE.  We will return the largest alignment of XF
20016      and DF.  */
20017   if (!type)
20018     {
20019       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
20020         align = GET_MODE_ALIGNMENT (DFmode);
20021       return align;
20022     }
20023
20024   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
20025      to 16byte boundary.  */
20026   if (TARGET_64BIT)
20027     {
20028       if (AGGREGATE_TYPE_P (type)
20029            && TYPE_SIZE (type)
20030            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
20031            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16
20032                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
20033         return 128;
20034     }
20035   if (TREE_CODE (type) == ARRAY_TYPE)
20036     {
20037       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
20038         return 64;
20039       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
20040         return 128;
20041     }
20042   else if (TREE_CODE (type) == COMPLEX_TYPE)
20043     {
20044       if (TYPE_MODE (type) == DCmode && align < 64)
20045         return 64;
20046       if ((TYPE_MODE (type) == XCmode
20047            || TYPE_MODE (type) == TCmode) && align < 128)
20048         return 128;
20049     }
20050   else if ((TREE_CODE (type) == RECORD_TYPE
20051             || TREE_CODE (type) == UNION_TYPE
20052             || TREE_CODE (type) == QUAL_UNION_TYPE)
20053            && TYPE_FIELDS (type))
20054     {
20055       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
20056         return 64;
20057       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
20058         return 128;
20059     }
20060   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
20061            || TREE_CODE (type) == INTEGER_TYPE)
20062     {
20063
20064       if (TYPE_MODE (type) == DFmode && align < 64)
20065         return 64;
20066       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
20067         return 128;
20068     }
20069   return align;
20070 }
20071
20072 /* Compute the minimum required alignment for dynamic stack realignment
20073    purposes for a local variable, parameter or a stack slot.  EXP is
20074    the data type or decl itself, MODE is its mode and ALIGN is the
20075    alignment that the object would ordinarily have.  */
20076
20077 unsigned int
20078 ix86_minimum_alignment (tree exp, enum machine_mode mode,
20079                         unsigned int align)
20080 {
20081   tree type, decl;
20082
20083   if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
20084     return align;
20085
20086   if (exp && DECL_P (exp))
20087     {
20088       type = TREE_TYPE (exp);
20089       decl = exp;
20090     }
20091   else
20092     {
20093       type = exp;
20094       decl = NULL;
20095     }
20096
20097   /* Don't do dynamic stack realignment for long long objects with
20098      -mpreferred-stack-boundary=2.  */
20099   if ((mode == DImode || (type && TYPE_MODE (type) == DImode))
20100       && (!type || !TYPE_USER_ALIGN (type))
20101       && (!decl || !DECL_USER_ALIGN (decl)))
20102     return 32;
20103
20104   return align;
20105 }
20106 \f
20107 /* Emit RTL insns to initialize the variable parts of a trampoline.
20108    FNADDR is an RTX for the address of the function's pure code.
20109    CXT is an RTX for the static chain value for the function.  */
20110 void
20111 x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
20112 {
20113   if (!TARGET_64BIT)
20114     {
20115       /* Compute offset from the end of the jmp to the target function.  */
20116       rtx disp = expand_binop (SImode, sub_optab, fnaddr,
20117                                plus_constant (tramp, 10),
20118                                NULL_RTX, 1, OPTAB_DIRECT);
20119       emit_move_insn (gen_rtx_MEM (QImode, tramp),
20120                       gen_int_mode (0xb9, QImode));
20121       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
20122       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
20123                       gen_int_mode (0xe9, QImode));
20124       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
20125     }
20126   else
20127     {
20128       int offset = 0;
20129       /* Try to load address using shorter movl instead of movabs.
20130          We may want to support movq for kernel mode, but kernel does not use
20131          trampolines at the moment.  */
20132       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
20133         {
20134           fnaddr = copy_to_mode_reg (DImode, fnaddr);
20135           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
20136                           gen_int_mode (0xbb41, HImode));
20137           emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
20138                           gen_lowpart (SImode, fnaddr));
20139           offset += 6;
20140         }
20141       else
20142         {
20143           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
20144                           gen_int_mode (0xbb49, HImode));
20145           emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
20146                           fnaddr);
20147           offset += 10;
20148         }
20149       /* Load static chain using movabs to r10.  */
20150       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
20151                       gen_int_mode (0xba49, HImode));
20152       emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
20153                       cxt);
20154       offset += 10;
20155       /* Jump to the r11 */
20156       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
20157                       gen_int_mode (0xff49, HImode));
20158       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
20159                       gen_int_mode (0xe3, QImode));
20160       offset += 3;
20161       gcc_assert (offset <= TRAMPOLINE_SIZE);
20162     }
20163
20164 #ifdef ENABLE_EXECUTE_STACK
20165   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
20166                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
20167 #endif
20168 }
20169 \f
20170 /* Codes for all the SSE/MMX builtins.  */
20171 enum ix86_builtins
20172 {
20173   IX86_BUILTIN_ADDPS,
20174   IX86_BUILTIN_ADDSS,
20175   IX86_BUILTIN_DIVPS,
20176   IX86_BUILTIN_DIVSS,
20177   IX86_BUILTIN_MULPS,
20178   IX86_BUILTIN_MULSS,
20179   IX86_BUILTIN_SUBPS,
20180   IX86_BUILTIN_SUBSS,
20181
20182   IX86_BUILTIN_CMPEQPS,
20183   IX86_BUILTIN_CMPLTPS,
20184   IX86_BUILTIN_CMPLEPS,
20185   IX86_BUILTIN_CMPGTPS,
20186   IX86_BUILTIN_CMPGEPS,
20187   IX86_BUILTIN_CMPNEQPS,
20188   IX86_BUILTIN_CMPNLTPS,
20189   IX86_BUILTIN_CMPNLEPS,
20190   IX86_BUILTIN_CMPNGTPS,
20191   IX86_BUILTIN_CMPNGEPS,
20192   IX86_BUILTIN_CMPORDPS,
20193   IX86_BUILTIN_CMPUNORDPS,
20194   IX86_BUILTIN_CMPEQSS,
20195   IX86_BUILTIN_CMPLTSS,
20196   IX86_BUILTIN_CMPLESS,
20197   IX86_BUILTIN_CMPNEQSS,
20198   IX86_BUILTIN_CMPNLTSS,
20199   IX86_BUILTIN_CMPNLESS,
20200   IX86_BUILTIN_CMPNGTSS,
20201   IX86_BUILTIN_CMPNGESS,
20202   IX86_BUILTIN_CMPORDSS,
20203   IX86_BUILTIN_CMPUNORDSS,
20204
20205   IX86_BUILTIN_COMIEQSS,
20206   IX86_BUILTIN_COMILTSS,
20207   IX86_BUILTIN_COMILESS,
20208   IX86_BUILTIN_COMIGTSS,
20209   IX86_BUILTIN_COMIGESS,
20210   IX86_BUILTIN_COMINEQSS,
20211   IX86_BUILTIN_UCOMIEQSS,
20212   IX86_BUILTIN_UCOMILTSS,
20213   IX86_BUILTIN_UCOMILESS,
20214   IX86_BUILTIN_UCOMIGTSS,
20215   IX86_BUILTIN_UCOMIGESS,
20216   IX86_BUILTIN_UCOMINEQSS,
20217
20218   IX86_BUILTIN_CVTPI2PS,
20219   IX86_BUILTIN_CVTPS2PI,
20220   IX86_BUILTIN_CVTSI2SS,
20221   IX86_BUILTIN_CVTSI642SS,
20222   IX86_BUILTIN_CVTSS2SI,
20223   IX86_BUILTIN_CVTSS2SI64,
20224   IX86_BUILTIN_CVTTPS2PI,
20225   IX86_BUILTIN_CVTTSS2SI,
20226   IX86_BUILTIN_CVTTSS2SI64,
20227
20228   IX86_BUILTIN_MAXPS,
20229   IX86_BUILTIN_MAXSS,
20230   IX86_BUILTIN_MINPS,
20231   IX86_BUILTIN_MINSS,
20232
20233   IX86_BUILTIN_LOADUPS,
20234   IX86_BUILTIN_STOREUPS,
20235   IX86_BUILTIN_MOVSS,
20236
20237   IX86_BUILTIN_MOVHLPS,
20238   IX86_BUILTIN_MOVLHPS,
20239   IX86_BUILTIN_LOADHPS,
20240   IX86_BUILTIN_LOADLPS,
20241   IX86_BUILTIN_STOREHPS,
20242   IX86_BUILTIN_STORELPS,
20243
20244   IX86_BUILTIN_MASKMOVQ,
20245   IX86_BUILTIN_MOVMSKPS,
20246   IX86_BUILTIN_PMOVMSKB,
20247
20248   IX86_BUILTIN_MOVNTPS,
20249   IX86_BUILTIN_MOVNTQ,
20250
20251   IX86_BUILTIN_LOADDQU,
20252   IX86_BUILTIN_STOREDQU,
20253
20254   IX86_BUILTIN_PACKSSWB,
20255   IX86_BUILTIN_PACKSSDW,
20256   IX86_BUILTIN_PACKUSWB,
20257
20258   IX86_BUILTIN_PADDB,
20259   IX86_BUILTIN_PADDW,
20260   IX86_BUILTIN_PADDD,
20261   IX86_BUILTIN_PADDQ,
20262   IX86_BUILTIN_PADDSB,
20263   IX86_BUILTIN_PADDSW,
20264   IX86_BUILTIN_PADDUSB,
20265   IX86_BUILTIN_PADDUSW,
20266   IX86_BUILTIN_PSUBB,
20267   IX86_BUILTIN_PSUBW,
20268   IX86_BUILTIN_PSUBD,
20269   IX86_BUILTIN_PSUBQ,
20270   IX86_BUILTIN_PSUBSB,
20271   IX86_BUILTIN_PSUBSW,
20272   IX86_BUILTIN_PSUBUSB,
20273   IX86_BUILTIN_PSUBUSW,
20274
20275   IX86_BUILTIN_PAND,
20276   IX86_BUILTIN_PANDN,
20277   IX86_BUILTIN_POR,
20278   IX86_BUILTIN_PXOR,
20279
20280   IX86_BUILTIN_PAVGB,
20281   IX86_BUILTIN_PAVGW,
20282
20283   IX86_BUILTIN_PCMPEQB,
20284   IX86_BUILTIN_PCMPEQW,
20285   IX86_BUILTIN_PCMPEQD,
20286   IX86_BUILTIN_PCMPGTB,
20287   IX86_BUILTIN_PCMPGTW,
20288   IX86_BUILTIN_PCMPGTD,
20289
20290   IX86_BUILTIN_PMADDWD,
20291
20292   IX86_BUILTIN_PMAXSW,
20293   IX86_BUILTIN_PMAXUB,
20294   IX86_BUILTIN_PMINSW,
20295   IX86_BUILTIN_PMINUB,
20296
20297   IX86_BUILTIN_PMULHUW,
20298   IX86_BUILTIN_PMULHW,
20299   IX86_BUILTIN_PMULLW,
20300
20301   IX86_BUILTIN_PSADBW,
20302   IX86_BUILTIN_PSHUFW,
20303
20304   IX86_BUILTIN_PSLLW,
20305   IX86_BUILTIN_PSLLD,
20306   IX86_BUILTIN_PSLLQ,
20307   IX86_BUILTIN_PSRAW,
20308   IX86_BUILTIN_PSRAD,
20309   IX86_BUILTIN_PSRLW,
20310   IX86_BUILTIN_PSRLD,
20311   IX86_BUILTIN_PSRLQ,
20312   IX86_BUILTIN_PSLLWI,
20313   IX86_BUILTIN_PSLLDI,
20314   IX86_BUILTIN_PSLLQI,
20315   IX86_BUILTIN_PSRAWI,
20316   IX86_BUILTIN_PSRADI,
20317   IX86_BUILTIN_PSRLWI,
20318   IX86_BUILTIN_PSRLDI,
20319   IX86_BUILTIN_PSRLQI,
20320
20321   IX86_BUILTIN_PUNPCKHBW,
20322   IX86_BUILTIN_PUNPCKHWD,
20323   IX86_BUILTIN_PUNPCKHDQ,
20324   IX86_BUILTIN_PUNPCKLBW,
20325   IX86_BUILTIN_PUNPCKLWD,
20326   IX86_BUILTIN_PUNPCKLDQ,
20327
20328   IX86_BUILTIN_SHUFPS,
20329
20330   IX86_BUILTIN_RCPPS,
20331   IX86_BUILTIN_RCPSS,
20332   IX86_BUILTIN_RSQRTPS,
20333   IX86_BUILTIN_RSQRTPS_NR,
20334   IX86_BUILTIN_RSQRTSS,
20335   IX86_BUILTIN_RSQRTF,
20336   IX86_BUILTIN_SQRTPS,
20337   IX86_BUILTIN_SQRTPS_NR,
20338   IX86_BUILTIN_SQRTSS,
20339
20340   IX86_BUILTIN_UNPCKHPS,
20341   IX86_BUILTIN_UNPCKLPS,
20342
20343   IX86_BUILTIN_ANDPS,
20344   IX86_BUILTIN_ANDNPS,
20345   IX86_BUILTIN_ORPS,
20346   IX86_BUILTIN_XORPS,
20347
20348   IX86_BUILTIN_EMMS,
20349   IX86_BUILTIN_LDMXCSR,
20350   IX86_BUILTIN_STMXCSR,
20351   IX86_BUILTIN_SFENCE,
20352
20353   /* 3DNow! Original */
20354   IX86_BUILTIN_FEMMS,
20355   IX86_BUILTIN_PAVGUSB,
20356   IX86_BUILTIN_PF2ID,
20357   IX86_BUILTIN_PFACC,
20358   IX86_BUILTIN_PFADD,
20359   IX86_BUILTIN_PFCMPEQ,
20360   IX86_BUILTIN_PFCMPGE,
20361   IX86_BUILTIN_PFCMPGT,
20362   IX86_BUILTIN_PFMAX,
20363   IX86_BUILTIN_PFMIN,
20364   IX86_BUILTIN_PFMUL,
20365   IX86_BUILTIN_PFRCP,
20366   IX86_BUILTIN_PFRCPIT1,
20367   IX86_BUILTIN_PFRCPIT2,
20368   IX86_BUILTIN_PFRSQIT1,
20369   IX86_BUILTIN_PFRSQRT,
20370   IX86_BUILTIN_PFSUB,
20371   IX86_BUILTIN_PFSUBR,
20372   IX86_BUILTIN_PI2FD,
20373   IX86_BUILTIN_PMULHRW,
20374
20375   /* 3DNow! Athlon Extensions */
20376   IX86_BUILTIN_PF2IW,
20377   IX86_BUILTIN_PFNACC,
20378   IX86_BUILTIN_PFPNACC,
20379   IX86_BUILTIN_PI2FW,
20380   IX86_BUILTIN_PSWAPDSI,
20381   IX86_BUILTIN_PSWAPDSF,
20382
20383   /* SSE2 */
20384   IX86_BUILTIN_ADDPD,
20385   IX86_BUILTIN_ADDSD,
20386   IX86_BUILTIN_DIVPD,
20387   IX86_BUILTIN_DIVSD,
20388   IX86_BUILTIN_MULPD,
20389   IX86_BUILTIN_MULSD,
20390   IX86_BUILTIN_SUBPD,
20391   IX86_BUILTIN_SUBSD,
20392
20393   IX86_BUILTIN_CMPEQPD,
20394   IX86_BUILTIN_CMPLTPD,
20395   IX86_BUILTIN_CMPLEPD,
20396   IX86_BUILTIN_CMPGTPD,
20397   IX86_BUILTIN_CMPGEPD,
20398   IX86_BUILTIN_CMPNEQPD,
20399   IX86_BUILTIN_CMPNLTPD,
20400   IX86_BUILTIN_CMPNLEPD,
20401   IX86_BUILTIN_CMPNGTPD,
20402   IX86_BUILTIN_CMPNGEPD,
20403   IX86_BUILTIN_CMPORDPD,
20404   IX86_BUILTIN_CMPUNORDPD,
20405   IX86_BUILTIN_CMPEQSD,
20406   IX86_BUILTIN_CMPLTSD,
20407   IX86_BUILTIN_CMPLESD,
20408   IX86_BUILTIN_CMPNEQSD,
20409   IX86_BUILTIN_CMPNLTSD,
20410   IX86_BUILTIN_CMPNLESD,
20411   IX86_BUILTIN_CMPORDSD,
20412   IX86_BUILTIN_CMPUNORDSD,
20413
20414   IX86_BUILTIN_COMIEQSD,
20415   IX86_BUILTIN_COMILTSD,
20416   IX86_BUILTIN_COMILESD,
20417   IX86_BUILTIN_COMIGTSD,
20418   IX86_BUILTIN_COMIGESD,
20419   IX86_BUILTIN_COMINEQSD,
20420   IX86_BUILTIN_UCOMIEQSD,
20421   IX86_BUILTIN_UCOMILTSD,
20422   IX86_BUILTIN_UCOMILESD,
20423   IX86_BUILTIN_UCOMIGTSD,
20424   IX86_BUILTIN_UCOMIGESD,
20425   IX86_BUILTIN_UCOMINEQSD,
20426
20427   IX86_BUILTIN_MAXPD,
20428   IX86_BUILTIN_MAXSD,
20429   IX86_BUILTIN_MINPD,
20430   IX86_BUILTIN_MINSD,
20431
20432   IX86_BUILTIN_ANDPD,
20433   IX86_BUILTIN_ANDNPD,
20434   IX86_BUILTIN_ORPD,
20435   IX86_BUILTIN_XORPD,
20436
20437   IX86_BUILTIN_SQRTPD,
20438   IX86_BUILTIN_SQRTSD,
20439
20440   IX86_BUILTIN_UNPCKHPD,
20441   IX86_BUILTIN_UNPCKLPD,
20442
20443   IX86_BUILTIN_SHUFPD,
20444
20445   IX86_BUILTIN_LOADUPD,
20446   IX86_BUILTIN_STOREUPD,
20447   IX86_BUILTIN_MOVSD,
20448
20449   IX86_BUILTIN_LOADHPD,
20450   IX86_BUILTIN_LOADLPD,
20451
20452   IX86_BUILTIN_CVTDQ2PD,
20453   IX86_BUILTIN_CVTDQ2PS,
20454
20455   IX86_BUILTIN_CVTPD2DQ,
20456   IX86_BUILTIN_CVTPD2PI,
20457   IX86_BUILTIN_CVTPD2PS,
20458   IX86_BUILTIN_CVTTPD2DQ,
20459   IX86_BUILTIN_CVTTPD2PI,
20460
20461   IX86_BUILTIN_CVTPI2PD,
20462   IX86_BUILTIN_CVTSI2SD,
20463   IX86_BUILTIN_CVTSI642SD,
20464
20465   IX86_BUILTIN_CVTSD2SI,
20466   IX86_BUILTIN_CVTSD2SI64,
20467   IX86_BUILTIN_CVTSD2SS,
20468   IX86_BUILTIN_CVTSS2SD,
20469   IX86_BUILTIN_CVTTSD2SI,
20470   IX86_BUILTIN_CVTTSD2SI64,
20471
20472   IX86_BUILTIN_CVTPS2DQ,
20473   IX86_BUILTIN_CVTPS2PD,
20474   IX86_BUILTIN_CVTTPS2DQ,
20475
20476   IX86_BUILTIN_MOVNTI,
20477   IX86_BUILTIN_MOVNTPD,
20478   IX86_BUILTIN_MOVNTDQ,
20479
20480   IX86_BUILTIN_MOVQ128,
20481
20482   /* SSE2 MMX */
20483   IX86_BUILTIN_MASKMOVDQU,
20484   IX86_BUILTIN_MOVMSKPD,
20485   IX86_BUILTIN_PMOVMSKB128,
20486
20487   IX86_BUILTIN_PACKSSWB128,
20488   IX86_BUILTIN_PACKSSDW128,
20489   IX86_BUILTIN_PACKUSWB128,
20490
20491   IX86_BUILTIN_PADDB128,
20492   IX86_BUILTIN_PADDW128,
20493   IX86_BUILTIN_PADDD128,
20494   IX86_BUILTIN_PADDQ128,
20495   IX86_BUILTIN_PADDSB128,
20496   IX86_BUILTIN_PADDSW128,
20497   IX86_BUILTIN_PADDUSB128,
20498   IX86_BUILTIN_PADDUSW128,
20499   IX86_BUILTIN_PSUBB128,
20500   IX86_BUILTIN_PSUBW128,
20501   IX86_BUILTIN_PSUBD128,
20502   IX86_BUILTIN_PSUBQ128,
20503   IX86_BUILTIN_PSUBSB128,
20504   IX86_BUILTIN_PSUBSW128,
20505   IX86_BUILTIN_PSUBUSB128,
20506   IX86_BUILTIN_PSUBUSW128,
20507
20508   IX86_BUILTIN_PAND128,
20509   IX86_BUILTIN_PANDN128,
20510   IX86_BUILTIN_POR128,
20511   IX86_BUILTIN_PXOR128,
20512
20513   IX86_BUILTIN_PAVGB128,
20514   IX86_BUILTIN_PAVGW128,
20515
20516   IX86_BUILTIN_PCMPEQB128,
20517   IX86_BUILTIN_PCMPEQW128,
20518   IX86_BUILTIN_PCMPEQD128,
20519   IX86_BUILTIN_PCMPGTB128,
20520   IX86_BUILTIN_PCMPGTW128,
20521   IX86_BUILTIN_PCMPGTD128,
20522
20523   IX86_BUILTIN_PMADDWD128,
20524
20525   IX86_BUILTIN_PMAXSW128,
20526   IX86_BUILTIN_PMAXUB128,
20527   IX86_BUILTIN_PMINSW128,
20528   IX86_BUILTIN_PMINUB128,
20529
20530   IX86_BUILTIN_PMULUDQ,
20531   IX86_BUILTIN_PMULUDQ128,
20532   IX86_BUILTIN_PMULHUW128,
20533   IX86_BUILTIN_PMULHW128,
20534   IX86_BUILTIN_PMULLW128,
20535
20536   IX86_BUILTIN_PSADBW128,
20537   IX86_BUILTIN_PSHUFHW,
20538   IX86_BUILTIN_PSHUFLW,
20539   IX86_BUILTIN_PSHUFD,
20540
20541   IX86_BUILTIN_PSLLDQI128,
20542   IX86_BUILTIN_PSLLWI128,
20543   IX86_BUILTIN_PSLLDI128,
20544   IX86_BUILTIN_PSLLQI128,
20545   IX86_BUILTIN_PSRAWI128,
20546   IX86_BUILTIN_PSRADI128,
20547   IX86_BUILTIN_PSRLDQI128,
20548   IX86_BUILTIN_PSRLWI128,
20549   IX86_BUILTIN_PSRLDI128,
20550   IX86_BUILTIN_PSRLQI128,
20551
20552   IX86_BUILTIN_PSLLDQ128,
20553   IX86_BUILTIN_PSLLW128,
20554   IX86_BUILTIN_PSLLD128,
20555   IX86_BUILTIN_PSLLQ128,
20556   IX86_BUILTIN_PSRAW128,
20557   IX86_BUILTIN_PSRAD128,
20558   IX86_BUILTIN_PSRLW128,
20559   IX86_BUILTIN_PSRLD128,
20560   IX86_BUILTIN_PSRLQ128,
20561
20562   IX86_BUILTIN_PUNPCKHBW128,
20563   IX86_BUILTIN_PUNPCKHWD128,
20564   IX86_BUILTIN_PUNPCKHDQ128,
20565   IX86_BUILTIN_PUNPCKHQDQ128,
20566   IX86_BUILTIN_PUNPCKLBW128,
20567   IX86_BUILTIN_PUNPCKLWD128,
20568   IX86_BUILTIN_PUNPCKLDQ128,
20569   IX86_BUILTIN_PUNPCKLQDQ128,
20570
20571   IX86_BUILTIN_CLFLUSH,
20572   IX86_BUILTIN_MFENCE,
20573   IX86_BUILTIN_LFENCE,
20574
20575   IX86_BUILTIN_BSRSI,
20576   IX86_BUILTIN_BSRDI,
20577   IX86_BUILTIN_RDPMC,
20578   IX86_BUILTIN_RDTSC,
20579   IX86_BUILTIN_RDTSCP,
20580   IX86_BUILTIN_ROLQI,
20581   IX86_BUILTIN_ROLHI,
20582   IX86_BUILTIN_RORQI,
20583   IX86_BUILTIN_RORHI,
20584
20585   /* SSE3.  */
20586   IX86_BUILTIN_ADDSUBPS,
20587   IX86_BUILTIN_HADDPS,
20588   IX86_BUILTIN_HSUBPS,
20589   IX86_BUILTIN_MOVSHDUP,
20590   IX86_BUILTIN_MOVSLDUP,
20591   IX86_BUILTIN_ADDSUBPD,
20592   IX86_BUILTIN_HADDPD,
20593   IX86_BUILTIN_HSUBPD,
20594   IX86_BUILTIN_LDDQU,
20595
20596   IX86_BUILTIN_MONITOR,
20597   IX86_BUILTIN_MWAIT,
20598
20599   /* SSSE3.  */
20600   IX86_BUILTIN_PHADDW,
20601   IX86_BUILTIN_PHADDD,
20602   IX86_BUILTIN_PHADDSW,
20603   IX86_BUILTIN_PHSUBW,
20604   IX86_BUILTIN_PHSUBD,
20605   IX86_BUILTIN_PHSUBSW,
20606   IX86_BUILTIN_PMADDUBSW,
20607   IX86_BUILTIN_PMULHRSW,
20608   IX86_BUILTIN_PSHUFB,
20609   IX86_BUILTIN_PSIGNB,
20610   IX86_BUILTIN_PSIGNW,
20611   IX86_BUILTIN_PSIGND,
20612   IX86_BUILTIN_PALIGNR,
20613   IX86_BUILTIN_PABSB,
20614   IX86_BUILTIN_PABSW,
20615   IX86_BUILTIN_PABSD,
20616
20617   IX86_BUILTIN_PHADDW128,
20618   IX86_BUILTIN_PHADDD128,
20619   IX86_BUILTIN_PHADDSW128,
20620   IX86_BUILTIN_PHSUBW128,
20621   IX86_BUILTIN_PHSUBD128,
20622   IX86_BUILTIN_PHSUBSW128,
20623   IX86_BUILTIN_PMADDUBSW128,
20624   IX86_BUILTIN_PMULHRSW128,
20625   IX86_BUILTIN_PSHUFB128,
20626   IX86_BUILTIN_PSIGNB128,
20627   IX86_BUILTIN_PSIGNW128,
20628   IX86_BUILTIN_PSIGND128,
20629   IX86_BUILTIN_PALIGNR128,
20630   IX86_BUILTIN_PABSB128,
20631   IX86_BUILTIN_PABSW128,
20632   IX86_BUILTIN_PABSD128,
20633
20634   /* AMDFAM10 - SSE4A New Instructions.  */
20635   IX86_BUILTIN_MOVNTSD,
20636   IX86_BUILTIN_MOVNTSS,
20637   IX86_BUILTIN_EXTRQI,
20638   IX86_BUILTIN_EXTRQ,
20639   IX86_BUILTIN_INSERTQI,
20640   IX86_BUILTIN_INSERTQ,
20641
20642   /* SSE4.1.  */
20643   IX86_BUILTIN_BLENDPD,
20644   IX86_BUILTIN_BLENDPS,
20645   IX86_BUILTIN_BLENDVPD,
20646   IX86_BUILTIN_BLENDVPS,
20647   IX86_BUILTIN_PBLENDVB128,
20648   IX86_BUILTIN_PBLENDW128,
20649
20650   IX86_BUILTIN_DPPD,
20651   IX86_BUILTIN_DPPS,
20652
20653   IX86_BUILTIN_INSERTPS128,
20654
20655   IX86_BUILTIN_MOVNTDQA,
20656   IX86_BUILTIN_MPSADBW128,
20657   IX86_BUILTIN_PACKUSDW128,
20658   IX86_BUILTIN_PCMPEQQ,
20659   IX86_BUILTIN_PHMINPOSUW128,
20660
20661   IX86_BUILTIN_PMAXSB128,
20662   IX86_BUILTIN_PMAXSD128,
20663   IX86_BUILTIN_PMAXUD128,
20664   IX86_BUILTIN_PMAXUW128,
20665
20666   IX86_BUILTIN_PMINSB128,
20667   IX86_BUILTIN_PMINSD128,
20668   IX86_BUILTIN_PMINUD128,
20669   IX86_BUILTIN_PMINUW128,
20670
20671   IX86_BUILTIN_PMOVSXBW128,
20672   IX86_BUILTIN_PMOVSXBD128,
20673   IX86_BUILTIN_PMOVSXBQ128,
20674   IX86_BUILTIN_PMOVSXWD128,
20675   IX86_BUILTIN_PMOVSXWQ128,
20676   IX86_BUILTIN_PMOVSXDQ128,
20677
20678   IX86_BUILTIN_PMOVZXBW128,
20679   IX86_BUILTIN_PMOVZXBD128,
20680   IX86_BUILTIN_PMOVZXBQ128,
20681   IX86_BUILTIN_PMOVZXWD128,
20682   IX86_BUILTIN_PMOVZXWQ128,
20683   IX86_BUILTIN_PMOVZXDQ128,
20684
20685   IX86_BUILTIN_PMULDQ128,
20686   IX86_BUILTIN_PMULLD128,
20687
20688   IX86_BUILTIN_ROUNDPD,
20689   IX86_BUILTIN_ROUNDPS,
20690   IX86_BUILTIN_ROUNDSD,
20691   IX86_BUILTIN_ROUNDSS,
20692
20693   IX86_BUILTIN_PTESTZ,
20694   IX86_BUILTIN_PTESTC,
20695   IX86_BUILTIN_PTESTNZC,
20696
20697   IX86_BUILTIN_VEC_INIT_V2SI,
20698   IX86_BUILTIN_VEC_INIT_V4HI,
20699   IX86_BUILTIN_VEC_INIT_V8QI,
20700   IX86_BUILTIN_VEC_EXT_V2DF,
20701   IX86_BUILTIN_VEC_EXT_V2DI,
20702   IX86_BUILTIN_VEC_EXT_V4SF,
20703   IX86_BUILTIN_VEC_EXT_V4SI,
20704   IX86_BUILTIN_VEC_EXT_V8HI,
20705   IX86_BUILTIN_VEC_EXT_V2SI,
20706   IX86_BUILTIN_VEC_EXT_V4HI,
20707   IX86_BUILTIN_VEC_EXT_V16QI,
20708   IX86_BUILTIN_VEC_SET_V2DI,
20709   IX86_BUILTIN_VEC_SET_V4SF,
20710   IX86_BUILTIN_VEC_SET_V4SI,
20711   IX86_BUILTIN_VEC_SET_V8HI,
20712   IX86_BUILTIN_VEC_SET_V4HI,
20713   IX86_BUILTIN_VEC_SET_V16QI,
20714
20715   IX86_BUILTIN_VEC_PACK_SFIX,
20716
20717   /* SSE4.2.  */
20718   IX86_BUILTIN_CRC32QI,
20719   IX86_BUILTIN_CRC32HI,
20720   IX86_BUILTIN_CRC32SI,
20721   IX86_BUILTIN_CRC32DI,
20722
20723   IX86_BUILTIN_PCMPESTRI128,
20724   IX86_BUILTIN_PCMPESTRM128,
20725   IX86_BUILTIN_PCMPESTRA128,
20726   IX86_BUILTIN_PCMPESTRC128,
20727   IX86_BUILTIN_PCMPESTRO128,
20728   IX86_BUILTIN_PCMPESTRS128,
20729   IX86_BUILTIN_PCMPESTRZ128,
20730   IX86_BUILTIN_PCMPISTRI128,
20731   IX86_BUILTIN_PCMPISTRM128,
20732   IX86_BUILTIN_PCMPISTRA128,
20733   IX86_BUILTIN_PCMPISTRC128,
20734   IX86_BUILTIN_PCMPISTRO128,
20735   IX86_BUILTIN_PCMPISTRS128,
20736   IX86_BUILTIN_PCMPISTRZ128,
20737
20738   IX86_BUILTIN_PCMPGTQ,
20739
20740   /* AES instructions */
20741   IX86_BUILTIN_AESENC128,
20742   IX86_BUILTIN_AESENCLAST128,
20743   IX86_BUILTIN_AESDEC128,
20744   IX86_BUILTIN_AESDECLAST128,
20745   IX86_BUILTIN_AESIMC128,
20746   IX86_BUILTIN_AESKEYGENASSIST128,
20747
20748   /* PCLMUL instruction */
20749   IX86_BUILTIN_PCLMULQDQ128,
20750
20751   /* AVX */
20752   IX86_BUILTIN_ADDPD256,
20753   IX86_BUILTIN_ADDPS256,
20754   IX86_BUILTIN_ADDSUBPD256,
20755   IX86_BUILTIN_ADDSUBPS256,
20756   IX86_BUILTIN_ANDPD256,
20757   IX86_BUILTIN_ANDPS256,
20758   IX86_BUILTIN_ANDNPD256,
20759   IX86_BUILTIN_ANDNPS256,
20760   IX86_BUILTIN_BLENDPD256,
20761   IX86_BUILTIN_BLENDPS256,
20762   IX86_BUILTIN_BLENDVPD256,
20763   IX86_BUILTIN_BLENDVPS256,
20764   IX86_BUILTIN_DIVPD256,
20765   IX86_BUILTIN_DIVPS256,
20766   IX86_BUILTIN_DPPS256,
20767   IX86_BUILTIN_HADDPD256,
20768   IX86_BUILTIN_HADDPS256,
20769   IX86_BUILTIN_HSUBPD256,
20770   IX86_BUILTIN_HSUBPS256,
20771   IX86_BUILTIN_MAXPD256,
20772   IX86_BUILTIN_MAXPS256,
20773   IX86_BUILTIN_MINPD256,
20774   IX86_BUILTIN_MINPS256,
20775   IX86_BUILTIN_MULPD256,
20776   IX86_BUILTIN_MULPS256,
20777   IX86_BUILTIN_ORPD256,
20778   IX86_BUILTIN_ORPS256,
20779   IX86_BUILTIN_SHUFPD256,
20780   IX86_BUILTIN_SHUFPS256,
20781   IX86_BUILTIN_SUBPD256,
20782   IX86_BUILTIN_SUBPS256,
20783   IX86_BUILTIN_XORPD256,
20784   IX86_BUILTIN_XORPS256,
20785   IX86_BUILTIN_CMPSD,
20786   IX86_BUILTIN_CMPSS,
20787   IX86_BUILTIN_CMPPD,
20788   IX86_BUILTIN_CMPPS,
20789   IX86_BUILTIN_CMPPD256,
20790   IX86_BUILTIN_CMPPS256,
20791   IX86_BUILTIN_CVTDQ2PD256,
20792   IX86_BUILTIN_CVTDQ2PS256,
20793   IX86_BUILTIN_CVTPD2PS256,
20794   IX86_BUILTIN_CVTPS2DQ256,
20795   IX86_BUILTIN_CVTPS2PD256,
20796   IX86_BUILTIN_CVTTPD2DQ256,
20797   IX86_BUILTIN_CVTPD2DQ256,
20798   IX86_BUILTIN_CVTTPS2DQ256,
20799   IX86_BUILTIN_EXTRACTF128PD256,
20800   IX86_BUILTIN_EXTRACTF128PS256,
20801   IX86_BUILTIN_EXTRACTF128SI256,
20802   IX86_BUILTIN_VZEROALL,
20803   IX86_BUILTIN_VZEROUPPER,
20804   IX86_BUILTIN_VZEROUPPER_REX64,
20805   IX86_BUILTIN_VPERMILVARPD,
20806   IX86_BUILTIN_VPERMILVARPS,
20807   IX86_BUILTIN_VPERMILVARPD256,
20808   IX86_BUILTIN_VPERMILVARPS256,
20809   IX86_BUILTIN_VPERMILPD,
20810   IX86_BUILTIN_VPERMILPS,
20811   IX86_BUILTIN_VPERMILPD256,
20812   IX86_BUILTIN_VPERMILPS256,
20813   IX86_BUILTIN_VPERM2F128PD256,
20814   IX86_BUILTIN_VPERM2F128PS256,
20815   IX86_BUILTIN_VPERM2F128SI256,
20816   IX86_BUILTIN_VBROADCASTSS,
20817   IX86_BUILTIN_VBROADCASTSD256,
20818   IX86_BUILTIN_VBROADCASTSS256,
20819   IX86_BUILTIN_VBROADCASTPD256,
20820   IX86_BUILTIN_VBROADCASTPS256,
20821   IX86_BUILTIN_VINSERTF128PD256,
20822   IX86_BUILTIN_VINSERTF128PS256,
20823   IX86_BUILTIN_VINSERTF128SI256,
20824   IX86_BUILTIN_LOADUPD256,
20825   IX86_BUILTIN_LOADUPS256,
20826   IX86_BUILTIN_STOREUPD256,
20827   IX86_BUILTIN_STOREUPS256,
20828   IX86_BUILTIN_LDDQU256,
20829   IX86_BUILTIN_MOVNTDQ256,
20830   IX86_BUILTIN_MOVNTPD256,
20831   IX86_BUILTIN_MOVNTPS256,
20832   IX86_BUILTIN_LOADDQU256,
20833   IX86_BUILTIN_STOREDQU256,
20834   IX86_BUILTIN_MASKLOADPD,
20835   IX86_BUILTIN_MASKLOADPS,
20836   IX86_BUILTIN_MASKSTOREPD,
20837   IX86_BUILTIN_MASKSTOREPS,
20838   IX86_BUILTIN_MASKLOADPD256,
20839   IX86_BUILTIN_MASKLOADPS256,
20840   IX86_BUILTIN_MASKSTOREPD256,
20841   IX86_BUILTIN_MASKSTOREPS256,
20842   IX86_BUILTIN_MOVSHDUP256,
20843   IX86_BUILTIN_MOVSLDUP256,
20844   IX86_BUILTIN_MOVDDUP256,
20845
20846   IX86_BUILTIN_SQRTPD256,
20847   IX86_BUILTIN_SQRTPS256,
20848   IX86_BUILTIN_SQRTPS_NR256,
20849   IX86_BUILTIN_RSQRTPS256,
20850   IX86_BUILTIN_RSQRTPS_NR256,
20851
20852   IX86_BUILTIN_RCPPS256,
20853
20854   IX86_BUILTIN_ROUNDPD256,
20855   IX86_BUILTIN_ROUNDPS256,
20856
20857   IX86_BUILTIN_UNPCKHPD256,
20858   IX86_BUILTIN_UNPCKLPD256,
20859   IX86_BUILTIN_UNPCKHPS256,
20860   IX86_BUILTIN_UNPCKLPS256,
20861
20862   IX86_BUILTIN_SI256_SI,
20863   IX86_BUILTIN_PS256_PS,
20864   IX86_BUILTIN_PD256_PD,
20865   IX86_BUILTIN_SI_SI256,
20866   IX86_BUILTIN_PS_PS256,
20867   IX86_BUILTIN_PD_PD256,
20868
20869   IX86_BUILTIN_VTESTZPD,
20870   IX86_BUILTIN_VTESTCPD,
20871   IX86_BUILTIN_VTESTNZCPD,
20872   IX86_BUILTIN_VTESTZPS,
20873   IX86_BUILTIN_VTESTCPS,
20874   IX86_BUILTIN_VTESTNZCPS,
20875   IX86_BUILTIN_VTESTZPD256,
20876   IX86_BUILTIN_VTESTCPD256,
20877   IX86_BUILTIN_VTESTNZCPD256,
20878   IX86_BUILTIN_VTESTZPS256,
20879   IX86_BUILTIN_VTESTCPS256,
20880   IX86_BUILTIN_VTESTNZCPS256,
20881   IX86_BUILTIN_PTESTZ256,
20882   IX86_BUILTIN_PTESTC256,
20883   IX86_BUILTIN_PTESTNZC256,
20884
20885   IX86_BUILTIN_MOVMSKPD256,
20886   IX86_BUILTIN_MOVMSKPS256,
20887
20888   /* TFmode support builtins.  */
20889   IX86_BUILTIN_INFQ,
20890   IX86_BUILTIN_HUGE_VALQ,
20891   IX86_BUILTIN_FABSQ,
20892   IX86_BUILTIN_COPYSIGNQ,
20893
20894   /* Vectorizer support builtins.  */
20895   IX86_BUILTIN_CPYSGNPS,
20896   IX86_BUILTIN_CPYSGNPD,
20897
20898   IX86_BUILTIN_CVTUDQ2PS,
20899
20900   /* SSE5 instructions */
20901   IX86_BUILTIN_FMADDSS,
20902   IX86_BUILTIN_FMADDSD,
20903   IX86_BUILTIN_FMADDPS,
20904   IX86_BUILTIN_FMADDPD,
20905   IX86_BUILTIN_FMSUBSS,
20906   IX86_BUILTIN_FMSUBSD,
20907   IX86_BUILTIN_FMSUBPS,
20908   IX86_BUILTIN_FMSUBPD,
20909   IX86_BUILTIN_FNMADDSS,
20910   IX86_BUILTIN_FNMADDSD,
20911   IX86_BUILTIN_FNMADDPS,
20912   IX86_BUILTIN_FNMADDPD,
20913   IX86_BUILTIN_FNMSUBSS,
20914   IX86_BUILTIN_FNMSUBSD,
20915   IX86_BUILTIN_FNMSUBPS,
20916   IX86_BUILTIN_FNMSUBPD,
20917   IX86_BUILTIN_PCMOV,
20918   IX86_BUILTIN_PCMOV_V2DI,
20919   IX86_BUILTIN_PCMOV_V4SI,
20920   IX86_BUILTIN_PCMOV_V8HI,
20921   IX86_BUILTIN_PCMOV_V16QI,
20922   IX86_BUILTIN_PCMOV_V4SF,
20923   IX86_BUILTIN_PCMOV_V2DF,
20924   IX86_BUILTIN_PPERM,
20925   IX86_BUILTIN_PERMPS,
20926   IX86_BUILTIN_PERMPD,
20927   IX86_BUILTIN_PMACSSWW,
20928   IX86_BUILTIN_PMACSWW,
20929   IX86_BUILTIN_PMACSSWD,
20930   IX86_BUILTIN_PMACSWD,
20931   IX86_BUILTIN_PMACSSDD,
20932   IX86_BUILTIN_PMACSDD,
20933   IX86_BUILTIN_PMACSSDQL,
20934   IX86_BUILTIN_PMACSSDQH,
20935   IX86_BUILTIN_PMACSDQL,
20936   IX86_BUILTIN_PMACSDQH,
20937   IX86_BUILTIN_PMADCSSWD,
20938   IX86_BUILTIN_PMADCSWD,
20939   IX86_BUILTIN_PHADDBW,
20940   IX86_BUILTIN_PHADDBD,
20941   IX86_BUILTIN_PHADDBQ,
20942   IX86_BUILTIN_PHADDWD,
20943   IX86_BUILTIN_PHADDWQ,
20944   IX86_BUILTIN_PHADDDQ,
20945   IX86_BUILTIN_PHADDUBW,
20946   IX86_BUILTIN_PHADDUBD,
20947   IX86_BUILTIN_PHADDUBQ,
20948   IX86_BUILTIN_PHADDUWD,
20949   IX86_BUILTIN_PHADDUWQ,
20950   IX86_BUILTIN_PHADDUDQ,
20951   IX86_BUILTIN_PHSUBBW,
20952   IX86_BUILTIN_PHSUBWD,
20953   IX86_BUILTIN_PHSUBDQ,
20954   IX86_BUILTIN_PROTB,
20955   IX86_BUILTIN_PROTW,
20956   IX86_BUILTIN_PROTD,
20957   IX86_BUILTIN_PROTQ,
20958   IX86_BUILTIN_PROTB_IMM,
20959   IX86_BUILTIN_PROTW_IMM,
20960   IX86_BUILTIN_PROTD_IMM,
20961   IX86_BUILTIN_PROTQ_IMM,
20962   IX86_BUILTIN_PSHLB,
20963   IX86_BUILTIN_PSHLW,
20964   IX86_BUILTIN_PSHLD,
20965   IX86_BUILTIN_PSHLQ,
20966   IX86_BUILTIN_PSHAB,
20967   IX86_BUILTIN_PSHAW,
20968   IX86_BUILTIN_PSHAD,
20969   IX86_BUILTIN_PSHAQ,
20970   IX86_BUILTIN_FRCZSS,
20971   IX86_BUILTIN_FRCZSD,
20972   IX86_BUILTIN_FRCZPS,
20973   IX86_BUILTIN_FRCZPD,
20974   IX86_BUILTIN_CVTPH2PS,
20975   IX86_BUILTIN_CVTPS2PH,
20976
20977   IX86_BUILTIN_COMEQSS,
20978   IX86_BUILTIN_COMNESS,
20979   IX86_BUILTIN_COMLTSS,
20980   IX86_BUILTIN_COMLESS,
20981   IX86_BUILTIN_COMGTSS,
20982   IX86_BUILTIN_COMGESS,
20983   IX86_BUILTIN_COMUEQSS,
20984   IX86_BUILTIN_COMUNESS,
20985   IX86_BUILTIN_COMULTSS,
20986   IX86_BUILTIN_COMULESS,
20987   IX86_BUILTIN_COMUGTSS,
20988   IX86_BUILTIN_COMUGESS,
20989   IX86_BUILTIN_COMORDSS,
20990   IX86_BUILTIN_COMUNORDSS,
20991   IX86_BUILTIN_COMFALSESS,
20992   IX86_BUILTIN_COMTRUESS,
20993
20994   IX86_BUILTIN_COMEQSD,
20995   IX86_BUILTIN_COMNESD,
20996   IX86_BUILTIN_COMLTSD,
20997   IX86_BUILTIN_COMLESD,
20998   IX86_BUILTIN_COMGTSD,
20999   IX86_BUILTIN_COMGESD,
21000   IX86_BUILTIN_COMUEQSD,
21001   IX86_BUILTIN_COMUNESD,
21002   IX86_BUILTIN_COMULTSD,
21003   IX86_BUILTIN_COMULESD,
21004   IX86_BUILTIN_COMUGTSD,
21005   IX86_BUILTIN_COMUGESD,
21006   IX86_BUILTIN_COMORDSD,
21007   IX86_BUILTIN_COMUNORDSD,
21008   IX86_BUILTIN_COMFALSESD,
21009   IX86_BUILTIN_COMTRUESD,
21010
21011   IX86_BUILTIN_COMEQPS,
21012   IX86_BUILTIN_COMNEPS,
21013   IX86_BUILTIN_COMLTPS,
21014   IX86_BUILTIN_COMLEPS,
21015   IX86_BUILTIN_COMGTPS,
21016   IX86_BUILTIN_COMGEPS,
21017   IX86_BUILTIN_COMUEQPS,
21018   IX86_BUILTIN_COMUNEPS,
21019   IX86_BUILTIN_COMULTPS,
21020   IX86_BUILTIN_COMULEPS,
21021   IX86_BUILTIN_COMUGTPS,
21022   IX86_BUILTIN_COMUGEPS,
21023   IX86_BUILTIN_COMORDPS,
21024   IX86_BUILTIN_COMUNORDPS,
21025   IX86_BUILTIN_COMFALSEPS,
21026   IX86_BUILTIN_COMTRUEPS,
21027
21028   IX86_BUILTIN_COMEQPD,
21029   IX86_BUILTIN_COMNEPD,
21030   IX86_BUILTIN_COMLTPD,
21031   IX86_BUILTIN_COMLEPD,
21032   IX86_BUILTIN_COMGTPD,
21033   IX86_BUILTIN_COMGEPD,
21034   IX86_BUILTIN_COMUEQPD,
21035   IX86_BUILTIN_COMUNEPD,
21036   IX86_BUILTIN_COMULTPD,
21037   IX86_BUILTIN_COMULEPD,
21038   IX86_BUILTIN_COMUGTPD,
21039   IX86_BUILTIN_COMUGEPD,
21040   IX86_BUILTIN_COMORDPD,
21041   IX86_BUILTIN_COMUNORDPD,
21042   IX86_BUILTIN_COMFALSEPD,
21043   IX86_BUILTIN_COMTRUEPD,
21044
21045   IX86_BUILTIN_PCOMEQUB,
21046   IX86_BUILTIN_PCOMNEUB,
21047   IX86_BUILTIN_PCOMLTUB,
21048   IX86_BUILTIN_PCOMLEUB,
21049   IX86_BUILTIN_PCOMGTUB,
21050   IX86_BUILTIN_PCOMGEUB,
21051   IX86_BUILTIN_PCOMFALSEUB,
21052   IX86_BUILTIN_PCOMTRUEUB,
21053   IX86_BUILTIN_PCOMEQUW,
21054   IX86_BUILTIN_PCOMNEUW,
21055   IX86_BUILTIN_PCOMLTUW,
21056   IX86_BUILTIN_PCOMLEUW,
21057   IX86_BUILTIN_PCOMGTUW,
21058   IX86_BUILTIN_PCOMGEUW,
21059   IX86_BUILTIN_PCOMFALSEUW,
21060   IX86_BUILTIN_PCOMTRUEUW,
21061   IX86_BUILTIN_PCOMEQUD,
21062   IX86_BUILTIN_PCOMNEUD,
21063   IX86_BUILTIN_PCOMLTUD,
21064   IX86_BUILTIN_PCOMLEUD,
21065   IX86_BUILTIN_PCOMGTUD,
21066   IX86_BUILTIN_PCOMGEUD,
21067   IX86_BUILTIN_PCOMFALSEUD,
21068   IX86_BUILTIN_PCOMTRUEUD,
21069   IX86_BUILTIN_PCOMEQUQ,
21070   IX86_BUILTIN_PCOMNEUQ,
21071   IX86_BUILTIN_PCOMLTUQ,
21072   IX86_BUILTIN_PCOMLEUQ,
21073   IX86_BUILTIN_PCOMGTUQ,
21074   IX86_BUILTIN_PCOMGEUQ,
21075   IX86_BUILTIN_PCOMFALSEUQ,
21076   IX86_BUILTIN_PCOMTRUEUQ,
21077
21078   IX86_BUILTIN_PCOMEQB,
21079   IX86_BUILTIN_PCOMNEB,
21080   IX86_BUILTIN_PCOMLTB,
21081   IX86_BUILTIN_PCOMLEB,
21082   IX86_BUILTIN_PCOMGTB,
21083   IX86_BUILTIN_PCOMGEB,
21084   IX86_BUILTIN_PCOMFALSEB,
21085   IX86_BUILTIN_PCOMTRUEB,
21086   IX86_BUILTIN_PCOMEQW,
21087   IX86_BUILTIN_PCOMNEW,
21088   IX86_BUILTIN_PCOMLTW,
21089   IX86_BUILTIN_PCOMLEW,
21090   IX86_BUILTIN_PCOMGTW,
21091   IX86_BUILTIN_PCOMGEW,
21092   IX86_BUILTIN_PCOMFALSEW,
21093   IX86_BUILTIN_PCOMTRUEW,
21094   IX86_BUILTIN_PCOMEQD,
21095   IX86_BUILTIN_PCOMNED,
21096   IX86_BUILTIN_PCOMLTD,
21097   IX86_BUILTIN_PCOMLED,
21098   IX86_BUILTIN_PCOMGTD,
21099   IX86_BUILTIN_PCOMGED,
21100   IX86_BUILTIN_PCOMFALSED,
21101   IX86_BUILTIN_PCOMTRUED,
21102   IX86_BUILTIN_PCOMEQQ,
21103   IX86_BUILTIN_PCOMNEQ,
21104   IX86_BUILTIN_PCOMLTQ,
21105   IX86_BUILTIN_PCOMLEQ,
21106   IX86_BUILTIN_PCOMGTQ,
21107   IX86_BUILTIN_PCOMGEQ,
21108   IX86_BUILTIN_PCOMFALSEQ,
21109   IX86_BUILTIN_PCOMTRUEQ,
21110
21111   IX86_BUILTIN_MAX
21112 };
21113
21114 /* Table for the ix86 builtin decls.  */
21115 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
21116
21117 /* Table of all of the builtin functions that are possible with different ISA's
21118    but are waiting to be built until a function is declared to use that
21119    ISA.  */
21120 struct GTY(()) builtin_isa {
21121   tree type;                    /* builtin type to use in the declaration */
21122   const char *name;             /* function name */
21123   int isa;                      /* isa_flags this builtin is defined for */
21124   bool const_p;                 /* true if the declaration is constant */
21125 };
21126
21127 static GTY(()) struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
21128
21129
21130 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
21131  * of which isa_flags to use in the ix86_builtins_isa array.  Stores the
21132  * function decl in the ix86_builtins array.  Returns the function decl or
21133  * NULL_TREE, if the builtin was not added.
21134  *
21135  * If the front end has a special hook for builtin functions, delay adding
21136  * builtin functions that aren't in the current ISA until the ISA is changed
21137  * with function specific optimization.  Doing so, can save about 300K for the
21138  * default compiler.  When the builtin is expanded, check at that time whether
21139  * it is valid.
21140  *
21141  * If the front end doesn't have a special hook, record all builtins, even if
21142  * it isn't an instruction set in the current ISA in case the user uses
21143  * function specific options for a different ISA, so that we don't get scope
21144  * errors if a builtin is added in the middle of a function scope.  */
21145
21146 static inline tree
21147 def_builtin (int mask, const char *name, tree type, enum ix86_builtins code)
21148 {
21149   tree decl = NULL_TREE;
21150
21151   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
21152     {
21153       ix86_builtins_isa[(int) code].isa = mask;
21154
21155       if ((mask & ix86_isa_flags) != 0
21156           || (lang_hooks.builtin_function
21157               == lang_hooks.builtin_function_ext_scope))
21158
21159         {
21160           decl = add_builtin_function (name, type, code, BUILT_IN_MD, NULL,
21161                                        NULL_TREE);
21162           ix86_builtins[(int) code] = decl;
21163           ix86_builtins_isa[(int) code].type = NULL_TREE;
21164         }
21165       else
21166         {
21167           ix86_builtins[(int) code] = NULL_TREE;
21168           ix86_builtins_isa[(int) code].const_p = false;
21169           ix86_builtins_isa[(int) code].type = type;
21170           ix86_builtins_isa[(int) code].name = name;
21171         }
21172     }
21173
21174   return decl;
21175 }
21176
21177 /* Like def_builtin, but also marks the function decl "const".  */
21178
21179 static inline tree
21180 def_builtin_const (int mask, const char *name, tree type,
21181                    enum ix86_builtins code)
21182 {
21183   tree decl = def_builtin (mask, name, type, code);
21184   if (decl)
21185     TREE_READONLY (decl) = 1;
21186   else
21187     ix86_builtins_isa[(int) code].const_p = true;
21188
21189   return decl;
21190 }
21191
21192 /* Add any new builtin functions for a given ISA that may not have been
21193    declared.  This saves a bit of space compared to adding all of the
21194    declarations to the tree, even if we didn't use them.  */
21195
21196 static void
21197 ix86_add_new_builtins (int isa)
21198 {
21199   int i;
21200   tree decl;
21201
21202   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
21203     {
21204       if ((ix86_builtins_isa[i].isa & isa) != 0
21205           && ix86_builtins_isa[i].type != NULL_TREE)
21206         {
21207           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
21208                                                  ix86_builtins_isa[i].type,
21209                                                  i, BUILT_IN_MD, NULL,
21210                                                  NULL_TREE);
21211
21212           ix86_builtins[i] = decl;
21213           ix86_builtins_isa[i].type = NULL_TREE;
21214           if (ix86_builtins_isa[i].const_p)
21215             TREE_READONLY (decl) = 1;
21216         }
21217     }
21218 }
21219
21220 /* Bits for builtin_description.flag.  */
21221
21222 /* Set when we don't support the comparison natively, and should
21223    swap_comparison in order to support it.  */
21224 #define BUILTIN_DESC_SWAP_OPERANDS      1
21225
21226 struct builtin_description
21227 {
21228   const unsigned int mask;
21229   const enum insn_code icode;
21230   const char *const name;
21231   const enum ix86_builtins code;
21232   const enum rtx_code comparison;
21233   const int flag;
21234 };
21235
21236 static const struct builtin_description bdesc_comi[] =
21237 {
21238   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
21239   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
21240   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
21241   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
21242   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
21243   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
21244   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
21245   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
21246   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
21247   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
21248   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
21249   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
21250   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
21251   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
21252   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
21253   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
21254   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
21255   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
21256   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
21257   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
21258   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
21259   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
21260   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
21261   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
21262 };
21263
21264 static const struct builtin_description bdesc_pcmpestr[] =
21265 {
21266   /* SSE4.2 */
21267   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
21268   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
21269   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
21270   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
21271   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
21272   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
21273   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
21274 };
21275
21276 static const struct builtin_description bdesc_pcmpistr[] =
21277 {
21278   /* SSE4.2 */
21279   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
21280   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
21281   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
21282   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
21283   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
21284   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
21285   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
21286 };
21287
21288 /* Special builtin types */
21289 enum ix86_special_builtin_type
21290 {
21291   SPECIAL_FTYPE_UNKNOWN,
21292   VOID_FTYPE_VOID,
21293   UINT64_FTYPE_VOID,
21294   UINT64_FTYPE_PUNSIGNED,
21295   V32QI_FTYPE_PCCHAR,
21296   V16QI_FTYPE_PCCHAR,
21297   V8SF_FTYPE_PCV4SF,
21298   V8SF_FTYPE_PCFLOAT,
21299   V4DF_FTYPE_PCV2DF,
21300   V4DF_FTYPE_PCDOUBLE,
21301   V4SF_FTYPE_PCFLOAT,
21302   V2DF_FTYPE_PCDOUBLE,
21303   V8SF_FTYPE_PCV8SF_V8SF,
21304   V4DF_FTYPE_PCV4DF_V4DF,
21305   V4SF_FTYPE_V4SF_PCV2SF,
21306   V4SF_FTYPE_PCV4SF_V4SF,
21307   V2DF_FTYPE_V2DF_PCDOUBLE,
21308   V2DF_FTYPE_PCV2DF_V2DF,
21309   V2DI_FTYPE_PV2DI,
21310   VOID_FTYPE_PV2SF_V4SF,
21311   VOID_FTYPE_PV4DI_V4DI,
21312   VOID_FTYPE_PV2DI_V2DI,
21313   VOID_FTYPE_PCHAR_V32QI,
21314   VOID_FTYPE_PCHAR_V16QI,
21315   VOID_FTYPE_PFLOAT_V8SF,
21316   VOID_FTYPE_PFLOAT_V4SF,
21317   VOID_FTYPE_PDOUBLE_V4DF,
21318   VOID_FTYPE_PDOUBLE_V2DF,
21319   VOID_FTYPE_PDI_DI,
21320   VOID_FTYPE_PINT_INT,
21321   VOID_FTYPE_PV8SF_V8SF_V8SF,
21322   VOID_FTYPE_PV4DF_V4DF_V4DF,
21323   VOID_FTYPE_PV4SF_V4SF_V4SF,
21324   VOID_FTYPE_PV2DF_V2DF_V2DF
21325 };
21326
21327 /* Builtin types */
21328 enum ix86_builtin_type
21329 {
21330   FTYPE_UNKNOWN,
21331   FLOAT128_FTYPE_FLOAT128,
21332   FLOAT_FTYPE_FLOAT,
21333   FLOAT128_FTYPE_FLOAT128_FLOAT128,
21334   INT_FTYPE_V8SF_V8SF_PTEST,
21335   INT_FTYPE_V4DI_V4DI_PTEST,
21336   INT_FTYPE_V4DF_V4DF_PTEST,
21337   INT_FTYPE_V4SF_V4SF_PTEST,
21338   INT_FTYPE_V2DI_V2DI_PTEST,
21339   INT_FTYPE_V2DF_V2DF_PTEST,
21340   INT_FTYPE_INT,
21341   UINT64_FTYPE_INT,
21342   INT64_FTYPE_INT64,
21343   INT64_FTYPE_V4SF,
21344   INT64_FTYPE_V2DF,
21345   INT_FTYPE_V16QI,
21346   INT_FTYPE_V8QI,
21347   INT_FTYPE_V8SF,
21348   INT_FTYPE_V4DF,
21349   INT_FTYPE_V4SF,
21350   INT_FTYPE_V2DF,
21351   V16QI_FTYPE_V16QI,
21352   V8SI_FTYPE_V8SF,
21353   V8SI_FTYPE_V4SI,
21354   V8HI_FTYPE_V8HI,
21355   V8HI_FTYPE_V16QI,
21356   V8QI_FTYPE_V8QI,
21357   V8SF_FTYPE_V8SF,
21358   V8SF_FTYPE_V8SI,
21359   V8SF_FTYPE_V4SF,
21360   V4SI_FTYPE_V4SI,
21361   V4SI_FTYPE_V16QI,
21362   V4SI_FTYPE_V8SI,
21363   V4SI_FTYPE_V8HI,
21364   V4SI_FTYPE_V4DF,
21365   V4SI_FTYPE_V4SF,
21366   V4SI_FTYPE_V2DF,
21367   V4HI_FTYPE_V4HI,
21368   V4DF_FTYPE_V4DF,
21369   V4DF_FTYPE_V4SI,
21370   V4DF_FTYPE_V4SF,
21371   V4DF_FTYPE_V2DF,
21372   V4SF_FTYPE_V4DF,
21373   V4SF_FTYPE_V4SF,
21374   V4SF_FTYPE_V4SF_VEC_MERGE,
21375   V4SF_FTYPE_V8SF,
21376   V4SF_FTYPE_V4SI,
21377   V4SF_FTYPE_V2DF,
21378   V2DI_FTYPE_V2DI,
21379   V2DI_FTYPE_V16QI,
21380   V2DI_FTYPE_V8HI,
21381   V2DI_FTYPE_V4SI,
21382   V2DF_FTYPE_V2DF,
21383   V2DF_FTYPE_V2DF_VEC_MERGE,
21384   V2DF_FTYPE_V4SI,
21385   V2DF_FTYPE_V4DF,
21386   V2DF_FTYPE_V4SF,
21387   V2DF_FTYPE_V2SI,
21388   V2SI_FTYPE_V2SI,
21389   V2SI_FTYPE_V4SF,
21390   V2SI_FTYPE_V2SF,
21391   V2SI_FTYPE_V2DF,
21392   V2SF_FTYPE_V2SF,
21393   V2SF_FTYPE_V2SI,
21394   V16QI_FTYPE_V16QI_V16QI,
21395   V16QI_FTYPE_V8HI_V8HI,
21396   V8QI_FTYPE_V8QI_V8QI,
21397   V8QI_FTYPE_V4HI_V4HI,
21398   V8HI_FTYPE_V8HI_V8HI,
21399   V8HI_FTYPE_V8HI_V8HI_COUNT,
21400   V8HI_FTYPE_V16QI_V16QI,
21401   V8HI_FTYPE_V4SI_V4SI,
21402   V8HI_FTYPE_V8HI_SI_COUNT,
21403   V8SF_FTYPE_V8SF_V8SF,
21404   V8SF_FTYPE_V8SF_V8SI,
21405   V4SI_FTYPE_V4SI_V4SI,
21406   V4SI_FTYPE_V4SI_V4SI_COUNT,
21407   V4SI_FTYPE_V8HI_V8HI,
21408   V4SI_FTYPE_V4SF_V4SF,
21409   V4SI_FTYPE_V2DF_V2DF,
21410   V4SI_FTYPE_V4SI_SI_COUNT,
21411   V4HI_FTYPE_V4HI_V4HI,
21412   V4HI_FTYPE_V4HI_V4HI_COUNT,
21413   V4HI_FTYPE_V8QI_V8QI,
21414   V4HI_FTYPE_V2SI_V2SI,
21415   V4HI_FTYPE_V4HI_SI_COUNT,
21416   V4DF_FTYPE_V4DF_V4DF,
21417   V4DF_FTYPE_V4DF_V4DI,
21418   V4SF_FTYPE_V4SF_V4SF,
21419   V4SF_FTYPE_V4SF_V4SF_SWAP,
21420   V4SF_FTYPE_V4SF_V4SI,
21421   V4SF_FTYPE_V4SF_V2SI,
21422   V4SF_FTYPE_V4SF_V2DF,
21423   V4SF_FTYPE_V4SF_DI,
21424   V4SF_FTYPE_V4SF_SI,
21425   V2DI_FTYPE_V2DI_V2DI,
21426   V2DI_FTYPE_V2DI_V2DI_COUNT,
21427   V2DI_FTYPE_V16QI_V16QI,
21428   V2DI_FTYPE_V4SI_V4SI,
21429   V2DI_FTYPE_V2DI_V16QI,
21430   V2DI_FTYPE_V2DF_V2DF,
21431   V2DI_FTYPE_V2DI_SI_COUNT,
21432   V2SI_FTYPE_V2SI_V2SI,
21433   V2SI_FTYPE_V2SI_V2SI_COUNT,
21434   V2SI_FTYPE_V4HI_V4HI,
21435   V2SI_FTYPE_V2SF_V2SF,
21436   V2SI_FTYPE_V2SI_SI_COUNT,
21437   V2DF_FTYPE_V2DF_V2DF,
21438   V2DF_FTYPE_V2DF_V2DF_SWAP,
21439   V2DF_FTYPE_V2DF_V4SF,
21440   V2DF_FTYPE_V2DF_V2DI,
21441   V2DF_FTYPE_V2DF_DI,
21442   V2DF_FTYPE_V2DF_SI,
21443   V2SF_FTYPE_V2SF_V2SF,
21444   V1DI_FTYPE_V1DI_V1DI,
21445   V1DI_FTYPE_V1DI_V1DI_COUNT,
21446   V1DI_FTYPE_V8QI_V8QI,
21447   V1DI_FTYPE_V2SI_V2SI,
21448   V1DI_FTYPE_V1DI_SI_COUNT,
21449   UINT64_FTYPE_UINT64_UINT64,
21450   UINT_FTYPE_UINT_UINT,
21451   UINT_FTYPE_UINT_USHORT,
21452   UINT_FTYPE_UINT_UCHAR,
21453   UINT16_FTYPE_UINT16_INT,
21454   UINT8_FTYPE_UINT8_INT,
21455   V8HI_FTYPE_V8HI_INT,
21456   V4SI_FTYPE_V4SI_INT,
21457   V4HI_FTYPE_V4HI_INT,
21458   V8SF_FTYPE_V8SF_INT,
21459   V4SI_FTYPE_V8SI_INT,
21460   V4SF_FTYPE_V8SF_INT,
21461   V2DF_FTYPE_V4DF_INT,
21462   V4DF_FTYPE_V4DF_INT,
21463   V4SF_FTYPE_V4SF_INT,
21464   V2DI_FTYPE_V2DI_INT,
21465   V2DI2TI_FTYPE_V2DI_INT,
21466   V2DF_FTYPE_V2DF_INT,
21467   V16QI_FTYPE_V16QI_V16QI_V16QI,
21468   V8SF_FTYPE_V8SF_V8SF_V8SF,
21469   V4DF_FTYPE_V4DF_V4DF_V4DF,
21470   V4SF_FTYPE_V4SF_V4SF_V4SF,
21471   V2DF_FTYPE_V2DF_V2DF_V2DF,
21472   V16QI_FTYPE_V16QI_V16QI_INT,
21473   V8SI_FTYPE_V8SI_V8SI_INT,
21474   V8SI_FTYPE_V8SI_V4SI_INT,
21475   V8HI_FTYPE_V8HI_V8HI_INT,
21476   V8SF_FTYPE_V8SF_V8SF_INT,
21477   V8SF_FTYPE_V8SF_V4SF_INT,
21478   V4SI_FTYPE_V4SI_V4SI_INT,
21479   V4DF_FTYPE_V4DF_V4DF_INT,
21480   V4DF_FTYPE_V4DF_V2DF_INT,
21481   V4SF_FTYPE_V4SF_V4SF_INT,
21482   V2DI_FTYPE_V2DI_V2DI_INT,
21483   V2DI2TI_FTYPE_V2DI_V2DI_INT,
21484   V1DI2DI_FTYPE_V1DI_V1DI_INT,
21485   V2DF_FTYPE_V2DF_V2DF_INT,
21486   V2DI_FTYPE_V2DI_UINT_UINT,
21487   V2DI_FTYPE_V2DI_V2DI_UINT_UINT
21488 };
21489
21490 /* Special builtins with variable number of arguments.  */
21491 static const struct builtin_description bdesc_special_args[] =
21492 {
21493   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rdtsc, "__builtin_ia32_rdtsc", IX86_BUILTIN_RDTSC, UNKNOWN, (int) UINT64_FTYPE_VOID },
21494   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rdtscp, "__builtin_ia32_rdtscp", IX86_BUILTIN_RDTSCP, UNKNOWN, (int) UINT64_FTYPE_PUNSIGNED },
21495
21496   /* MMX */
21497   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
21498
21499   /* 3DNow! */
21500   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
21501
21502   /* SSE */
21503   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
21504   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
21505   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
21506
21507   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
21508   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
21509   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
21510   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
21511
21512   /* SSE or 3DNow!A  */
21513   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
21514   { 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 },
21515
21516   /* SSE2 */
21517   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
21518   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
21519   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
21520   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
21521   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
21522   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
21523   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntsi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
21524   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
21525   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
21526
21527   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
21528   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
21529
21530   /* SSE3 */
21531   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
21532
21533   /* SSE4.1 */
21534   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
21535
21536   /* SSE4A */
21537   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
21538   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
21539
21540   /* AVX */
21541   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
21542   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, 0, IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
21543   { OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_64BIT, CODE_FOR_avx_vzeroupper_rex64, 0, IX86_BUILTIN_VZEROUPPER_REX64, UNKNOWN, (int) VOID_FTYPE_VOID },
21544
21545   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
21546   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastsd256, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
21547   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss256, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
21548   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_pd256, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
21549   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_ps256, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
21550
21551   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
21552   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
21553   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
21554   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
21555   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
21556   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
21557   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
21558
21559   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4di, "__builtin_ia32_movntdq256", IX86_BUILTIN_MOVNTDQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI },
21560   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4df, "__builtin_ia32_movntpd256", IX86_BUILTIN_MOVNTPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
21561   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv8sf, "__builtin_ia32_movntps256", IX86_BUILTIN_MOVNTPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
21562
21563   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF },
21564   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF },
21565   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF },
21566   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF },
21567   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_V2DF },
21568   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_V4SF },
21569   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_V4DF },
21570   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_V8SF },
21571 };
21572
21573 /* Builtins with variable number of arguments.  */
21574 static const struct builtin_description bdesc_args[] =
21575 {
21576   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_bsr, "__builtin_ia32_bsrsi", IX86_BUILTIN_BSRSI, UNKNOWN, (int) INT_FTYPE_INT },
21577   { OPTION_MASK_ISA_64BIT, CODE_FOR_bsr_rex64, "__builtin_ia32_bsrdi", IX86_BUILTIN_BSRDI, UNKNOWN, (int) INT64_FTYPE_INT64 },
21578   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rdpmc, "__builtin_ia32_rdpmc", IX86_BUILTIN_RDPMC, UNKNOWN, (int) UINT64_FTYPE_INT },
21579   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotlqi3, "__builtin_ia32_rolqi", IX86_BUILTIN_ROLQI, UNKNOWN, (int) UINT8_FTYPE_UINT8_INT },
21580   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotlhi3, "__builtin_ia32_rolhi", IX86_BUILTIN_ROLHI, UNKNOWN, (int) UINT16_FTYPE_UINT16_INT },
21581   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotrqi3, "__builtin_ia32_rorqi", IX86_BUILTIN_RORQI, UNKNOWN, (int) UINT8_FTYPE_UINT8_INT },
21582   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotrhi3, "__builtin_ia32_rorhi", IX86_BUILTIN_RORHI, UNKNOWN, (int) UINT16_FTYPE_UINT16_INT },
21583
21584   /* MMX */
21585   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21586   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21587   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21588   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21589   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21590   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21591
21592   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21593   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21594   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21595   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21596   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21597   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21598   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21599   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21600
21601   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21602   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21603
21604   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21605   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andnotv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21606   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21607   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21608
21609   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21610   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21611   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21612   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21613   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21614   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21615
21616   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21617   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21618   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21619   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21620   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
21621   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
21622
21623   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
21624   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
21625   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
21626
21627   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
21628
21629   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
21630   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
21631   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
21632   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
21633   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
21634   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
21635
21636   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
21637   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
21638   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
21639   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
21640   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
21641   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
21642
21643   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
21644   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
21645   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
21646   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
21647
21648   /* 3DNow! */
21649   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
21650   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
21651   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
21652   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
21653
21654   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21655   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21656   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21657   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
21658   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
21659   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
21660   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21661   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21662   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21663   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21664   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21665   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21666   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21667   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21668   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21669
21670   /* 3DNow!A */
21671   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
21672   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
21673   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
21674   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
21675   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21676   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21677
21678   /* SSE */
21679   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
21680   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21681   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21682   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21683   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21684   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21685   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
21686   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
21687   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
21688   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
21689   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
21690   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
21691
21692   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21693
21694   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21695   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21696   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21697   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21698   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21699   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21700   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21701   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21702
21703   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
21704   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
21705   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
21706   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21707   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21708   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
21709   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
21710   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
21711   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
21712   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21713   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
21714   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
21715   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
21716   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
21717   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
21718   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
21719   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
21720   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
21721   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
21722   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngtss", IX86_BUILTIN_CMPNGTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21723   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngess", IX86_BUILTIN_CMPNGESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21724   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
21725
21726   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21727   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21728   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21729   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21730
21731   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21732   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_andnotv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21733   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21734   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21735
21736   { OPTION_MASK_ISA_SSE, CODE_FOR_copysignv4sf3,  "__builtin_ia32_copysignps", IX86_BUILTIN_CPYSGNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21737
21738   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21739   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21740   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21741   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpckhps, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21742   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpcklps, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21743
21744   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
21745   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
21746   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
21747
21748   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
21749
21750   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21751   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21752   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21753
21754   /* SSE MMX or 3Dnow!A */
21755   { 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 },
21756   { 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 },
21757   { 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 },
21758
21759   { 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 },
21760   { 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 },
21761   { 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 },
21762   { 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 },
21763
21764   { 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 },
21765   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
21766
21767   { 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 },
21768
21769   /* SSE2 */
21770   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21771
21772   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
21773   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
21774   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
21775   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
21776   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2ps, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
21777   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtudq2ps, "__builtin_ia32_cvtudq2ps", IX86_BUILTIN_CVTUDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
21778
21779   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
21780   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
21781   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
21782   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
21783   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
21784
21785   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
21786
21787   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
21788   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
21789   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
21790   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
21791
21792   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2dq, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
21793   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
21794   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttps2dq, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
21795
21796   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21797   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21798   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21799   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21800   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21801   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21802   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21803   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21804
21805   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
21806   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
21807   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
21808   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21809   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
21810   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21811   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
21812   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
21813   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
21814   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21815   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21816   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21817   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
21818   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
21819   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
21820   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21821   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
21822   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
21823   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
21824   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21825
21826   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21827   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21828   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21829   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21830
21831   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21832   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21833   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21834   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21835
21836   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysignv2df3,  "__builtin_ia32_copysignpd", IX86_BUILTIN_CPYSGNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21837
21838   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21839   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpckhpd_exp, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21840   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpcklpd_exp, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21841
21842   { 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 },
21843
21844   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21845   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21846   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21847   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21848   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21849   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21850   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21851   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21852
21853   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21854   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21855   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21856   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21857   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21858   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21859   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21860   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21861
21862   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21863   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
21864
21865   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21866   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21867   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21868   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21869
21870   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21871   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21872
21873   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21874   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21875   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
21876   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21877   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21878   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
21879
21880   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21881   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21882   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21883   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21884
21885   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhbw, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21886   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhwd, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
21887   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhdq, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
21888   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhqdq, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21889   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklbw, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21890   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklwd, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21891   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckldq, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21892   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklqdq, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21893
21894   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
21895   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
21896   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
21897
21898   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21899   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
21900
21901   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
21902   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv2siv2di3, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
21903
21904   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
21905
21906   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
21907   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
21908   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
21909   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
21910
21911   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
21912   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21913   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21914   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
21915   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21916   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21917   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
21918
21919   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
21920   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21921   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21922   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
21923   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21924   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21925   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
21926
21927   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21928   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21929   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21930   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21931
21932   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
21933   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
21934   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
21935
21936   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
21937
21938   { OPTION_MASK_ISA_SSE2, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
21939   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
21940
21941   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
21942
21943   /* SSE2 MMX */
21944   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
21945   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
21946
21947   /* SSE3 */
21948   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
21949   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21950
21951   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21952   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21953   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21954   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21955   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21956   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21957
21958   /* SSSE3 */
21959   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
21960   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
21961   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
21962   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
21963   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
21964   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
21965
21966   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21967   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21968   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21969   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21970   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21971   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21972   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21973   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21974   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21975   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21976   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21977   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21978   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
21979   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
21980   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21981   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21982   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21983   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21984   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21985   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21986   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21987   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21988   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21989   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21990
21991   /* SSSE3.  */
21992   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_V2DI_INT },
21993   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI2DI_FTYPE_V1DI_V1DI_INT },
21994
21995   /* SSE4.1 */
21996   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21997   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21998   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
21999   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
22000   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
22001   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
22002   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
22003   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
22004   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
22005   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
22006
22007   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
22008   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
22009   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
22010   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
22011   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
22012   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
22013   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
22014   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
22015   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
22016   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
22017   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
22018   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
22019   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
22020
22021   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
22022   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
22023   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
22024   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
22025   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
22026   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
22027   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
22028   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
22029   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
22030   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
22031   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
22032   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
22033
22034   /* SSE4.1 and SSE5 */
22035   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
22036   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
22037   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
22038   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
22039
22040   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
22041   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
22042   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
22043
22044   /* SSE4.2 */
22045   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
22046   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_CRC32, CODE_FOR_sse4_2_crc32qi, "__builtin_ia32_crc32qi", IX86_BUILTIN_CRC32QI, UNKNOWN, (int) UINT_FTYPE_UINT_UCHAR },
22047   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_CRC32, CODE_FOR_sse4_2_crc32hi, "__builtin_ia32_crc32hi", IX86_BUILTIN_CRC32HI, UNKNOWN, (int) UINT_FTYPE_UINT_USHORT },
22048   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_CRC32, CODE_FOR_sse4_2_crc32si, "__builtin_ia32_crc32si", IX86_BUILTIN_CRC32SI, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
22049   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_CRC32 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse4_2_crc32di, "__builtin_ia32_crc32di", IX86_BUILTIN_CRC32DI, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
22050
22051   /* SSE4A */
22052   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
22053   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
22054   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
22055   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
22056
22057   /* AES */
22058   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
22059   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
22060
22061   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
22062   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
22063   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
22064   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
22065
22066   /* PCLMUL */
22067   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
22068
22069   /* AVX */
22070   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22071   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22072   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22073   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22074   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22075   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22076   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22077   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22078   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22079   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22080   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22081   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22082   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22083   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22084   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22085   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22086   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22087   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22088   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22089   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22090   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22091   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22092   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22093   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22094   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22095   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22096
22097   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
22098   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
22099   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
22100   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
22101
22102   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
22103   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
22104   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
22105   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
22106   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
22107   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
22108   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
22109   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpsdv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
22110   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpssv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
22111   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
22112   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
22113   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
22114   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
22115   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
22116   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
22117   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
22118   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2pd256, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
22119   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2ps256, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
22120   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
22121   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2dq256, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
22122   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
22123   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttpd2dq256, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
22124   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
22125   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttps2dq256, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
22126   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
22127   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
22128   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
22129   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
22130   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
22131   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
22132   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
22133   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
22134   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
22135   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
22136
22137   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
22138   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
22139   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
22140
22141   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
22142   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
22143   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
22144   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
22145   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
22146
22147   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
22148
22149   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
22150   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
22151
22152   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22153   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
22154   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22155   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
22156
22157   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
22158   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
22159   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
22160   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si_si256, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
22161   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps_ps256, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
22162   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd_pd256, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
22163
22164   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
22165   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
22166   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
22167   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
22168   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
22169   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
22170   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
22171   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
22172   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
22173   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
22174   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
22175   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
22176   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
22177   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
22178   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
22179
22180   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
22181   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
22182 };
22183
22184 /* SSE5 */
22185 enum multi_arg_type {
22186   MULTI_ARG_UNKNOWN,
22187   MULTI_ARG_3_SF,
22188   MULTI_ARG_3_DF,
22189   MULTI_ARG_3_DI,
22190   MULTI_ARG_3_SI,
22191   MULTI_ARG_3_SI_DI,
22192   MULTI_ARG_3_HI,
22193   MULTI_ARG_3_HI_SI,
22194   MULTI_ARG_3_QI,
22195   MULTI_ARG_3_PERMPS,
22196   MULTI_ARG_3_PERMPD,
22197   MULTI_ARG_2_SF,
22198   MULTI_ARG_2_DF,
22199   MULTI_ARG_2_DI,
22200   MULTI_ARG_2_SI,
22201   MULTI_ARG_2_HI,
22202   MULTI_ARG_2_QI,
22203   MULTI_ARG_2_DI_IMM,
22204   MULTI_ARG_2_SI_IMM,
22205   MULTI_ARG_2_HI_IMM,
22206   MULTI_ARG_2_QI_IMM,
22207   MULTI_ARG_2_SF_CMP,
22208   MULTI_ARG_2_DF_CMP,
22209   MULTI_ARG_2_DI_CMP,
22210   MULTI_ARG_2_SI_CMP,
22211   MULTI_ARG_2_HI_CMP,
22212   MULTI_ARG_2_QI_CMP,
22213   MULTI_ARG_2_DI_TF,
22214   MULTI_ARG_2_SI_TF,
22215   MULTI_ARG_2_HI_TF,
22216   MULTI_ARG_2_QI_TF,
22217   MULTI_ARG_2_SF_TF,
22218   MULTI_ARG_2_DF_TF,
22219   MULTI_ARG_1_SF,
22220   MULTI_ARG_1_DF,
22221   MULTI_ARG_1_DI,
22222   MULTI_ARG_1_SI,
22223   MULTI_ARG_1_HI,
22224   MULTI_ARG_1_QI,
22225   MULTI_ARG_1_SI_DI,
22226   MULTI_ARG_1_HI_DI,
22227   MULTI_ARG_1_HI_SI,
22228   MULTI_ARG_1_QI_DI,
22229   MULTI_ARG_1_QI_SI,
22230   MULTI_ARG_1_QI_HI,
22231   MULTI_ARG_1_PH2PS,
22232   MULTI_ARG_1_PS2PH
22233 };
22234
22235 static const struct builtin_description bdesc_multi_arg[] =
22236 {
22237   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv4sf4,     "__builtin_ia32_fmaddss",    IX86_BUILTIN_FMADDSS,    UNKNOWN,      (int)MULTI_ARG_3_SF },
22238   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv2df4,     "__builtin_ia32_fmaddsd",    IX86_BUILTIN_FMADDSD,    UNKNOWN,      (int)MULTI_ARG_3_DF },
22239   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv4sf4,       "__builtin_ia32_fmaddps",    IX86_BUILTIN_FMADDPS,    UNKNOWN,      (int)MULTI_ARG_3_SF },
22240   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv2df4,       "__builtin_ia32_fmaddpd",    IX86_BUILTIN_FMADDPD,    UNKNOWN,      (int)MULTI_ARG_3_DF },
22241   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv4sf4,     "__builtin_ia32_fmsubss",    IX86_BUILTIN_FMSUBSS,    UNKNOWN,      (int)MULTI_ARG_3_SF },
22242   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv2df4,     "__builtin_ia32_fmsubsd",    IX86_BUILTIN_FMSUBSD,    UNKNOWN,      (int)MULTI_ARG_3_DF },
22243   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv4sf4,       "__builtin_ia32_fmsubps",    IX86_BUILTIN_FMSUBPS,    UNKNOWN,      (int)MULTI_ARG_3_SF },
22244   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv2df4,       "__builtin_ia32_fmsubpd",    IX86_BUILTIN_FMSUBPD,    UNKNOWN,      (int)MULTI_ARG_3_DF },
22245   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv4sf4,    "__builtin_ia32_fnmaddss",   IX86_BUILTIN_FNMADDSS,   UNKNOWN,      (int)MULTI_ARG_3_SF },
22246   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv2df4,    "__builtin_ia32_fnmaddsd",   IX86_BUILTIN_FNMADDSD,   UNKNOWN,      (int)MULTI_ARG_3_DF },
22247   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv4sf4,      "__builtin_ia32_fnmaddps",   IX86_BUILTIN_FNMADDPS,   UNKNOWN,      (int)MULTI_ARG_3_SF },
22248   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv2df4,      "__builtin_ia32_fnmaddpd",   IX86_BUILTIN_FNMADDPD,   UNKNOWN,      (int)MULTI_ARG_3_DF },
22249   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv4sf4,    "__builtin_ia32_fnmsubss",   IX86_BUILTIN_FNMSUBSS,   UNKNOWN,      (int)MULTI_ARG_3_SF },
22250   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv2df4,    "__builtin_ia32_fnmsubsd",   IX86_BUILTIN_FNMSUBSD,   UNKNOWN,      (int)MULTI_ARG_3_DF },
22251   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv4sf4,      "__builtin_ia32_fnmsubps",   IX86_BUILTIN_FNMSUBPS,   UNKNOWN,      (int)MULTI_ARG_3_SF },
22252   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv2df4,      "__builtin_ia32_fnmsubpd",   IX86_BUILTIN_FNMSUBPD,   UNKNOWN,      (int)MULTI_ARG_3_DF },
22253   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov",      IX86_BUILTIN_PCMOV,      UNKNOWN,      (int)MULTI_ARG_3_DI },
22254   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov_v2di", IX86_BUILTIN_PCMOV_V2DI, UNKNOWN,      (int)MULTI_ARG_3_DI },
22255   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4si,        "__builtin_ia32_pcmov_v4si", IX86_BUILTIN_PCMOV_V4SI, UNKNOWN,      (int)MULTI_ARG_3_SI },
22256   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v8hi,        "__builtin_ia32_pcmov_v8hi", IX86_BUILTIN_PCMOV_V8HI, UNKNOWN,      (int)MULTI_ARG_3_HI },
22257   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v16qi,       "__builtin_ia32_pcmov_v16qi",IX86_BUILTIN_PCMOV_V16QI,UNKNOWN,      (int)MULTI_ARG_3_QI },
22258   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2df,        "__builtin_ia32_pcmov_v2df", IX86_BUILTIN_PCMOV_V2DF, UNKNOWN,      (int)MULTI_ARG_3_DF },
22259   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4sf,        "__builtin_ia32_pcmov_v4sf", IX86_BUILTIN_PCMOV_V4SF, UNKNOWN,      (int)MULTI_ARG_3_SF },
22260   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pperm,             "__builtin_ia32_pperm",      IX86_BUILTIN_PPERM,      UNKNOWN,      (int)MULTI_ARG_3_QI },
22261   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv4sf,          "__builtin_ia32_permps",     IX86_BUILTIN_PERMPS,     UNKNOWN,      (int)MULTI_ARG_3_PERMPS },
22262   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv2df,          "__builtin_ia32_permpd",     IX86_BUILTIN_PERMPD,     UNKNOWN,      (int)MULTI_ARG_3_PERMPD },
22263   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssww,          "__builtin_ia32_pmacssww",   IX86_BUILTIN_PMACSSWW,   UNKNOWN,      (int)MULTI_ARG_3_HI },
22264   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsww,           "__builtin_ia32_pmacsww",    IX86_BUILTIN_PMACSWW,    UNKNOWN,      (int)MULTI_ARG_3_HI },
22265   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsswd,          "__builtin_ia32_pmacsswd",   IX86_BUILTIN_PMACSSWD,   UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
22266   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacswd,           "__builtin_ia32_pmacswd",    IX86_BUILTIN_PMACSWD,    UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
22267   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdd,          "__builtin_ia32_pmacssdd",   IX86_BUILTIN_PMACSSDD,   UNKNOWN,      (int)MULTI_ARG_3_SI },
22268   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdd,           "__builtin_ia32_pmacsdd",    IX86_BUILTIN_PMACSDD,    UNKNOWN,      (int)MULTI_ARG_3_SI },
22269   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdql,         "__builtin_ia32_pmacssdql",  IX86_BUILTIN_PMACSSDQL,  UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
22270   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdqh,         "__builtin_ia32_pmacssdqh",  IX86_BUILTIN_PMACSSDQH,  UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
22271   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdql,          "__builtin_ia32_pmacsdql",   IX86_BUILTIN_PMACSDQL,   UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
22272   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdqh,          "__builtin_ia32_pmacsdqh",   IX86_BUILTIN_PMACSDQH,   UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
22273   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcsswd,         "__builtin_ia32_pmadcsswd",  IX86_BUILTIN_PMADCSSWD,  UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
22274   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcswd,          "__builtin_ia32_pmadcswd",   IX86_BUILTIN_PMADCSWD,   UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
22275   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv2di3,        "__builtin_ia32_protq",      IX86_BUILTIN_PROTQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
22276   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv4si3,        "__builtin_ia32_protd",      IX86_BUILTIN_PROTD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
22277   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv8hi3,        "__builtin_ia32_protw",      IX86_BUILTIN_PROTW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
22278   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv16qi3,       "__builtin_ia32_protb",      IX86_BUILTIN_PROTB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
22279   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv2di3,         "__builtin_ia32_protqi",     IX86_BUILTIN_PROTQ_IMM,  UNKNOWN,      (int)MULTI_ARG_2_DI_IMM },
22280   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv4si3,         "__builtin_ia32_protdi",     IX86_BUILTIN_PROTD_IMM,  UNKNOWN,      (int)MULTI_ARG_2_SI_IMM },
22281   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv8hi3,         "__builtin_ia32_protwi",     IX86_BUILTIN_PROTW_IMM,  UNKNOWN,      (int)MULTI_ARG_2_HI_IMM },
22282   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv16qi3,        "__builtin_ia32_protbi",     IX86_BUILTIN_PROTB_IMM,  UNKNOWN,      (int)MULTI_ARG_2_QI_IMM },
22283   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv2di3,         "__builtin_ia32_pshaq",      IX86_BUILTIN_PSHAQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
22284   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv4si3,         "__builtin_ia32_pshad",      IX86_BUILTIN_PSHAD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
22285   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv8hi3,         "__builtin_ia32_pshaw",      IX86_BUILTIN_PSHAW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
22286   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv16qi3,        "__builtin_ia32_pshab",      IX86_BUILTIN_PSHAB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
22287   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv2di3,         "__builtin_ia32_pshlq",      IX86_BUILTIN_PSHLQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
22288   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv4si3,         "__builtin_ia32_pshld",      IX86_BUILTIN_PSHLD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
22289   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv8hi3,         "__builtin_ia32_pshlw",      IX86_BUILTIN_PSHLW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
22290   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv16qi3,        "__builtin_ia32_pshlb",      IX86_BUILTIN_PSHLB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
22291   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv4sf2,       "__builtin_ia32_frczss",     IX86_BUILTIN_FRCZSS,     UNKNOWN,      (int)MULTI_ARG_2_SF },
22292   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv2df2,       "__builtin_ia32_frczsd",     IX86_BUILTIN_FRCZSD,     UNKNOWN,      (int)MULTI_ARG_2_DF },
22293   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv4sf2,         "__builtin_ia32_frczps",     IX86_BUILTIN_FRCZPS,     UNKNOWN,      (int)MULTI_ARG_1_SF },
22294   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv2df2,         "__builtin_ia32_frczpd",     IX86_BUILTIN_FRCZPD,     UNKNOWN,      (int)MULTI_ARG_1_DF },
22295   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtph2ps,          "__builtin_ia32_cvtph2ps",   IX86_BUILTIN_CVTPH2PS,   UNKNOWN,      (int)MULTI_ARG_1_PH2PS },
22296   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtps2ph,          "__builtin_ia32_cvtps2ph",   IX86_BUILTIN_CVTPS2PH,   UNKNOWN,      (int)MULTI_ARG_1_PS2PH },
22297   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbw,           "__builtin_ia32_phaddbw",    IX86_BUILTIN_PHADDBW,    UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
22298   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbd,           "__builtin_ia32_phaddbd",    IX86_BUILTIN_PHADDBD,    UNKNOWN,      (int)MULTI_ARG_1_QI_SI },
22299   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbq,           "__builtin_ia32_phaddbq",    IX86_BUILTIN_PHADDBQ,    UNKNOWN,      (int)MULTI_ARG_1_QI_DI },
22300   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwd,           "__builtin_ia32_phaddwd",    IX86_BUILTIN_PHADDWD,    UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
22301   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwq,           "__builtin_ia32_phaddwq",    IX86_BUILTIN_PHADDWQ,    UNKNOWN,      (int)MULTI_ARG_1_HI_DI },
22302   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadddq,           "__builtin_ia32_phadddq",    IX86_BUILTIN_PHADDDQ,    UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
22303   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubw,          "__builtin_ia32_phaddubw",   IX86_BUILTIN_PHADDUBW,   UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
22304   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubd,          "__builtin_ia32_phaddubd",   IX86_BUILTIN_PHADDUBD,   UNKNOWN,      (int)MULTI_ARG_1_QI_SI },
22305   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubq,          "__builtin_ia32_phaddubq",   IX86_BUILTIN_PHADDUBQ,   UNKNOWN,      (int)MULTI_ARG_1_QI_DI },
22306   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwd,          "__builtin_ia32_phadduwd",   IX86_BUILTIN_PHADDUWD,   UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
22307   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwq,          "__builtin_ia32_phadduwq",   IX86_BUILTIN_PHADDUWQ,   UNKNOWN,      (int)MULTI_ARG_1_HI_DI },
22308   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddudq,          "__builtin_ia32_phaddudq",   IX86_BUILTIN_PHADDUDQ,   UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
22309   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubbw,           "__builtin_ia32_phsubbw",    IX86_BUILTIN_PHSUBBW,    UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
22310   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubwd,           "__builtin_ia32_phsubwd",    IX86_BUILTIN_PHSUBWD,    UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
22311   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubdq,           "__builtin_ia32_phsubdq",    IX86_BUILTIN_PHSUBDQ,    UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
22312
22313   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comeqss",    IX86_BUILTIN_COMEQSS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
22314   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comness",    IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
22315   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comneqss",   IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
22316   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comltss",    IX86_BUILTIN_COMLTSS,    LT,           (int)MULTI_ARG_2_SF_CMP },
22317   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comless",    IX86_BUILTIN_COMLESS,    LE,           (int)MULTI_ARG_2_SF_CMP },
22318   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgtss",    IX86_BUILTIN_COMGTSS,    GT,           (int)MULTI_ARG_2_SF_CMP },
22319   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgess",    IX86_BUILTIN_COMGESS,    GE,           (int)MULTI_ARG_2_SF_CMP },
22320   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comueqss",   IX86_BUILTIN_COMUEQSS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
22321   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuness",   IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
22322   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuneqss",  IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
22323   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunltss",  IX86_BUILTIN_COMULTSS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
22324   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunless",  IX86_BUILTIN_COMULESS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
22325   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungtss",  IX86_BUILTIN_COMUGTSS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
22326   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungess",  IX86_BUILTIN_COMUGESS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
22327   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comordss",   IX86_BUILTIN_COMORDSS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
22328   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunordss", IX86_BUILTIN_COMUNORDSS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
22329
22330   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comeqsd",    IX86_BUILTIN_COMEQSD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
22331   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comnesd",    IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
22332   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comneqsd",   IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
22333   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comltsd",    IX86_BUILTIN_COMLTSD,    LT,           (int)MULTI_ARG_2_DF_CMP },
22334   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comlesd",    IX86_BUILTIN_COMLESD,    LE,           (int)MULTI_ARG_2_DF_CMP },
22335   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgtsd",    IX86_BUILTIN_COMGTSD,    GT,           (int)MULTI_ARG_2_DF_CMP },
22336   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgesd",    IX86_BUILTIN_COMGESD,    GE,           (int)MULTI_ARG_2_DF_CMP },
22337   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comueqsd",   IX86_BUILTIN_COMUEQSD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
22338   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunesd",   IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
22339   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comuneqsd",  IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
22340   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunltsd",  IX86_BUILTIN_COMULTSD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
22341   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunlesd",  IX86_BUILTIN_COMULESD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
22342   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungtsd",  IX86_BUILTIN_COMUGTSD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
22343   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungesd",  IX86_BUILTIN_COMUGESD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
22344   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comordsd",   IX86_BUILTIN_COMORDSD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
22345   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunordsd", IX86_BUILTIN_COMUNORDSD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
22346
22347   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comeqps",    IX86_BUILTIN_COMEQPS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
22348   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneps",    IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
22349   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneqps",   IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
22350   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comltps",    IX86_BUILTIN_COMLTPS,    LT,           (int)MULTI_ARG_2_SF_CMP },
22351   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comleps",    IX86_BUILTIN_COMLEPS,    LE,           (int)MULTI_ARG_2_SF_CMP },
22352   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgtps",    IX86_BUILTIN_COMGTPS,    GT,           (int)MULTI_ARG_2_SF_CMP },
22353   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgeps",    IX86_BUILTIN_COMGEPS,    GE,           (int)MULTI_ARG_2_SF_CMP },
22354   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comueqps",   IX86_BUILTIN_COMUEQPS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
22355   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneps",   IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
22356   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneqps",  IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
22357   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunltps",  IX86_BUILTIN_COMULTPS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
22358   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunleps",  IX86_BUILTIN_COMULEPS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
22359   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungtps",  IX86_BUILTIN_COMUGTPS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
22360   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungeps",  IX86_BUILTIN_COMUGEPS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
22361   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comordps",   IX86_BUILTIN_COMORDPS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
22362   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunordps", IX86_BUILTIN_COMUNORDPS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
22363
22364   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comeqpd",    IX86_BUILTIN_COMEQPD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
22365   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comnepd",    IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
22366   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comneqpd",   IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
22367   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comltpd",    IX86_BUILTIN_COMLTPD,    LT,           (int)MULTI_ARG_2_DF_CMP },
22368   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comlepd",    IX86_BUILTIN_COMLEPD,    LE,           (int)MULTI_ARG_2_DF_CMP },
22369   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgtpd",    IX86_BUILTIN_COMGTPD,    GT,           (int)MULTI_ARG_2_DF_CMP },
22370   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgepd",    IX86_BUILTIN_COMGEPD,    GE,           (int)MULTI_ARG_2_DF_CMP },
22371   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comueqpd",   IX86_BUILTIN_COMUEQPD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
22372   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunepd",   IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
22373   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comuneqpd",  IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
22374   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunltpd",  IX86_BUILTIN_COMULTPD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
22375   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunlepd",  IX86_BUILTIN_COMULEPD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
22376   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungtpd",  IX86_BUILTIN_COMUGTPD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
22377   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungepd",  IX86_BUILTIN_COMUGEPD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
22378   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comordpd",   IX86_BUILTIN_COMORDPD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
22379   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunordpd", IX86_BUILTIN_COMUNORDPD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
22380
22381   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomeqb",    IX86_BUILTIN_PCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
22382   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneb",    IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
22383   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneqb",   IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
22384   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomltb",    IX86_BUILTIN_PCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
22385   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomleb",    IX86_BUILTIN_PCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
22386   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgtb",    IX86_BUILTIN_PCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
22387   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgeb",    IX86_BUILTIN_PCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
22388
22389   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomeqw",    IX86_BUILTIN_PCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
22390   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomnew",    IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
22391   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomneqw",   IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
22392   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomltw",    IX86_BUILTIN_PCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
22393   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomlew",    IX86_BUILTIN_PCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
22394   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgtw",    IX86_BUILTIN_PCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
22395   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgew",    IX86_BUILTIN_PCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
22396
22397   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomeqd",    IX86_BUILTIN_PCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
22398   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomned",    IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
22399   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomneqd",   IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
22400   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomltd",    IX86_BUILTIN_PCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
22401   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomled",    IX86_BUILTIN_PCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
22402   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomgtd",    IX86_BUILTIN_PCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
22403   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomged",    IX86_BUILTIN_PCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
22404
22405   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomeqq",    IX86_BUILTIN_PCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
22406   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneq",    IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
22407   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneqq",   IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
22408   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomltq",    IX86_BUILTIN_PCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
22409   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomleq",    IX86_BUILTIN_PCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
22410   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgtq",    IX86_BUILTIN_PCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
22411   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgeq",    IX86_BUILTIN_PCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
22412
22413   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomequb",   IX86_BUILTIN_PCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
22414   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomneub",   IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
22415   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomnequb",  IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
22416   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomltub",   IX86_BUILTIN_PCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
22417   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomleub",   IX86_BUILTIN_PCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
22418   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgtub",   IX86_BUILTIN_PCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
22419   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgeub",   IX86_BUILTIN_PCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
22420
22421   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomequw",   IX86_BUILTIN_PCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
22422   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomneuw",   IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
22423   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomnequw",  IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
22424   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomltuw",   IX86_BUILTIN_PCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
22425   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomleuw",   IX86_BUILTIN_PCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
22426   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgtuw",   IX86_BUILTIN_PCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
22427   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgeuw",   IX86_BUILTIN_PCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
22428
22429   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomequd",   IX86_BUILTIN_PCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
22430   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomneud",   IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
22431   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomnequd",  IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
22432   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomltud",   IX86_BUILTIN_PCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
22433   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomleud",   IX86_BUILTIN_PCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
22434   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgtud",   IX86_BUILTIN_PCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
22435   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgeud",   IX86_BUILTIN_PCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
22436
22437   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomequq",   IX86_BUILTIN_PCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
22438   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomneuq",   IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
22439   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomnequq",  IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
22440   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomltuq",   IX86_BUILTIN_PCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
22441   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomleuq",   IX86_BUILTIN_PCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
22442   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgtuq",   IX86_BUILTIN_PCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
22443   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgeuq",   IX86_BUILTIN_PCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
22444
22445   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalsess", IX86_BUILTIN_COMFALSESS, (enum rtx_code) COM_FALSE_S,  (int)MULTI_ARG_2_SF_TF },
22446   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtruess",  IX86_BUILTIN_COMTRUESS,  (enum rtx_code) COM_TRUE_S,   (int)MULTI_ARG_2_SF_TF },
22447   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalseps", IX86_BUILTIN_COMFALSEPS, (enum rtx_code) COM_FALSE_P,  (int)MULTI_ARG_2_SF_TF },
22448   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtrueps",  IX86_BUILTIN_COMTRUEPS,  (enum rtx_code) COM_TRUE_P,   (int)MULTI_ARG_2_SF_TF },
22449   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsesd", IX86_BUILTIN_COMFALSESD, (enum rtx_code) COM_FALSE_S,  (int)MULTI_ARG_2_DF_TF },
22450   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruesd",  IX86_BUILTIN_COMTRUESD,  (enum rtx_code) COM_TRUE_S,   (int)MULTI_ARG_2_DF_TF },
22451   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsepd", IX86_BUILTIN_COMFALSEPD, (enum rtx_code) COM_FALSE_P,  (int)MULTI_ARG_2_DF_TF },
22452   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruepd",  IX86_BUILTIN_COMTRUEPD,  (enum rtx_code) COM_TRUE_P,   (int)MULTI_ARG_2_DF_TF },
22453
22454   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseb", IX86_BUILTIN_PCOMFALSEB, (enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
22455   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalsew", IX86_BUILTIN_PCOMFALSEW, (enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
22456   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalsed", IX86_BUILTIN_PCOMFALSED, (enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
22457   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseq", IX86_BUILTIN_PCOMFALSEQ, (enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
22458   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseub",IX86_BUILTIN_PCOMFALSEUB,(enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
22459   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalseuw",IX86_BUILTIN_PCOMFALSEUW,(enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
22460   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalseud",IX86_BUILTIN_PCOMFALSEUD,(enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
22461   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseuq",IX86_BUILTIN_PCOMFALSEUQ,(enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
22462
22463   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueb",  IX86_BUILTIN_PCOMTRUEB,  (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
22464   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtruew",  IX86_BUILTIN_PCOMTRUEW,  (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
22465   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrued",  IX86_BUILTIN_PCOMTRUED,  (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
22466   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueq",  IX86_BUILTIN_PCOMTRUEQ,  (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
22467   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueub", IX86_BUILTIN_PCOMTRUEUB, (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
22468   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtrueuw", IX86_BUILTIN_PCOMTRUEUW, (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
22469   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrueud", IX86_BUILTIN_PCOMTRUEUD, (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
22470   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueuq", IX86_BUILTIN_PCOMTRUEUQ, (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
22471 };
22472
22473 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
22474    in the current target ISA to allow the user to compile particular modules
22475    with different target specific options that differ from the command line
22476    options.  */
22477 static void
22478 ix86_init_mmx_sse_builtins (void)
22479 {
22480   const struct builtin_description * d;
22481   size_t i;
22482
22483   tree V16QI_type_node = build_vector_type_for_mode (char_type_node, V16QImode);
22484   tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
22485   tree V1DI_type_node
22486     = build_vector_type_for_mode (long_long_integer_type_node, V1DImode);
22487   tree V2SF_type_node = build_vector_type_for_mode (float_type_node, V2SFmode);
22488   tree V2DI_type_node
22489     = build_vector_type_for_mode (long_long_integer_type_node, V2DImode);
22490   tree V2DF_type_node = build_vector_type_for_mode (double_type_node, V2DFmode);
22491   tree V4SF_type_node = build_vector_type_for_mode (float_type_node, V4SFmode);
22492   tree V4SI_type_node = build_vector_type_for_mode (intSI_type_node, V4SImode);
22493   tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
22494   tree V8QI_type_node = build_vector_type_for_mode (char_type_node, V8QImode);
22495   tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, V8HImode);
22496
22497   tree pchar_type_node = build_pointer_type (char_type_node);
22498   tree pcchar_type_node
22499     = build_pointer_type (build_type_variant (char_type_node, 1, 0));
22500   tree pfloat_type_node = build_pointer_type (float_type_node);
22501   tree pcfloat_type_node
22502     = build_pointer_type (build_type_variant (float_type_node, 1, 0));
22503   tree pv2sf_type_node = build_pointer_type (V2SF_type_node);
22504   tree pcv2sf_type_node
22505     = build_pointer_type (build_type_variant (V2SF_type_node, 1, 0));
22506   tree pv2di_type_node = build_pointer_type (V2DI_type_node);
22507   tree pdi_type_node = build_pointer_type (long_long_unsigned_type_node);
22508
22509   /* Comparisons.  */
22510   tree int_ftype_v4sf_v4sf
22511     = build_function_type_list (integer_type_node,
22512                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
22513   tree v4si_ftype_v4sf_v4sf
22514     = build_function_type_list (V4SI_type_node,
22515                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
22516   /* MMX/SSE/integer conversions.  */
22517   tree int_ftype_v4sf
22518     = build_function_type_list (integer_type_node,
22519                                 V4SF_type_node, NULL_TREE);
22520   tree int64_ftype_v4sf
22521     = build_function_type_list (long_long_integer_type_node,
22522                                 V4SF_type_node, NULL_TREE);
22523   tree int_ftype_v8qi
22524     = build_function_type_list (integer_type_node, V8QI_type_node, NULL_TREE);
22525   tree v4sf_ftype_v4sf_int
22526     = build_function_type_list (V4SF_type_node,
22527                                 V4SF_type_node, integer_type_node, NULL_TREE);
22528   tree v4sf_ftype_v4sf_int64
22529     = build_function_type_list (V4SF_type_node,
22530                                 V4SF_type_node, long_long_integer_type_node,
22531                                 NULL_TREE);
22532   tree v4sf_ftype_v4sf_v2si
22533     = build_function_type_list (V4SF_type_node,
22534                                 V4SF_type_node, V2SI_type_node, NULL_TREE);
22535
22536   /* Miscellaneous.  */
22537   tree v8qi_ftype_v4hi_v4hi
22538     = build_function_type_list (V8QI_type_node,
22539                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
22540   tree v4hi_ftype_v2si_v2si
22541     = build_function_type_list (V4HI_type_node,
22542                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
22543   tree v4sf_ftype_v4sf_v4sf_int
22544     = build_function_type_list (V4SF_type_node,
22545                                 V4SF_type_node, V4SF_type_node,
22546                                 integer_type_node, NULL_TREE);
22547   tree v2si_ftype_v4hi_v4hi
22548     = build_function_type_list (V2SI_type_node,
22549                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
22550   tree v4hi_ftype_v4hi_int
22551     = build_function_type_list (V4HI_type_node,
22552                                 V4HI_type_node, integer_type_node, NULL_TREE);
22553   tree v2si_ftype_v2si_int
22554     = build_function_type_list (V2SI_type_node,
22555                                 V2SI_type_node, integer_type_node, NULL_TREE);
22556   tree v1di_ftype_v1di_int
22557     = build_function_type_list (V1DI_type_node,
22558                                 V1DI_type_node, integer_type_node, NULL_TREE);
22559
22560   tree void_ftype_void
22561     = build_function_type (void_type_node, void_list_node);
22562   tree void_ftype_unsigned
22563     = build_function_type_list (void_type_node, unsigned_type_node, NULL_TREE);
22564   tree void_ftype_unsigned_unsigned
22565     = build_function_type_list (void_type_node, unsigned_type_node,
22566                                 unsigned_type_node, NULL_TREE);
22567   tree void_ftype_pcvoid_unsigned_unsigned
22568     = build_function_type_list (void_type_node, const_ptr_type_node,
22569                                 unsigned_type_node, unsigned_type_node,
22570                                 NULL_TREE);
22571   tree unsigned_ftype_void
22572     = build_function_type (unsigned_type_node, void_list_node);
22573   tree v2si_ftype_v4sf
22574     = build_function_type_list (V2SI_type_node, V4SF_type_node, NULL_TREE);
22575   /* Loads/stores.  */
22576   tree void_ftype_v8qi_v8qi_pchar
22577     = build_function_type_list (void_type_node,
22578                                 V8QI_type_node, V8QI_type_node,
22579                                 pchar_type_node, NULL_TREE);
22580   tree v4sf_ftype_pcfloat
22581     = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
22582   tree v4sf_ftype_v4sf_pcv2sf
22583     = build_function_type_list (V4SF_type_node,
22584                                 V4SF_type_node, pcv2sf_type_node, NULL_TREE);
22585   tree void_ftype_pv2sf_v4sf
22586     = build_function_type_list (void_type_node,
22587                                 pv2sf_type_node, V4SF_type_node, NULL_TREE);
22588   tree void_ftype_pfloat_v4sf
22589     = build_function_type_list (void_type_node,
22590                                 pfloat_type_node, V4SF_type_node, NULL_TREE);
22591   tree void_ftype_pdi_di
22592     = build_function_type_list (void_type_node,
22593                                 pdi_type_node, long_long_unsigned_type_node,
22594                                 NULL_TREE);
22595   tree void_ftype_pv2di_v2di
22596     = build_function_type_list (void_type_node,
22597                                 pv2di_type_node, V2DI_type_node, NULL_TREE);
22598   /* Normal vector unops.  */
22599   tree v4sf_ftype_v4sf
22600     = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
22601   tree v16qi_ftype_v16qi
22602     = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
22603   tree v8hi_ftype_v8hi
22604     = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
22605   tree v4si_ftype_v4si
22606     = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
22607   tree v8qi_ftype_v8qi
22608     = build_function_type_list (V8QI_type_node, V8QI_type_node, NULL_TREE);
22609   tree v4hi_ftype_v4hi
22610     = build_function_type_list (V4HI_type_node, V4HI_type_node, NULL_TREE);
22611
22612   /* Normal vector binops.  */
22613   tree v4sf_ftype_v4sf_v4sf
22614     = build_function_type_list (V4SF_type_node,
22615                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
22616   tree v8qi_ftype_v8qi_v8qi
22617     = build_function_type_list (V8QI_type_node,
22618                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
22619   tree v4hi_ftype_v4hi_v4hi
22620     = build_function_type_list (V4HI_type_node,
22621                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
22622   tree v2si_ftype_v2si_v2si
22623     = build_function_type_list (V2SI_type_node,
22624                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
22625   tree v1di_ftype_v1di_v1di
22626     = build_function_type_list (V1DI_type_node,
22627                                 V1DI_type_node, V1DI_type_node, NULL_TREE);
22628   tree v1di_ftype_v1di_v1di_int
22629     = build_function_type_list (V1DI_type_node,
22630                                 V1DI_type_node, V1DI_type_node,
22631                                 integer_type_node, NULL_TREE);
22632   tree v2si_ftype_v2sf
22633     = build_function_type_list (V2SI_type_node, V2SF_type_node, NULL_TREE);
22634   tree v2sf_ftype_v2si
22635     = build_function_type_list (V2SF_type_node, V2SI_type_node, NULL_TREE);
22636   tree v2si_ftype_v2si
22637     = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
22638   tree v2sf_ftype_v2sf
22639     = build_function_type_list (V2SF_type_node, V2SF_type_node, NULL_TREE);
22640   tree v2sf_ftype_v2sf_v2sf
22641     = build_function_type_list (V2SF_type_node,
22642                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
22643   tree v2si_ftype_v2sf_v2sf
22644     = build_function_type_list (V2SI_type_node,
22645                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
22646   tree pint_type_node    = build_pointer_type (integer_type_node);
22647   tree pdouble_type_node = build_pointer_type (double_type_node);
22648   tree pcdouble_type_node = build_pointer_type (
22649                                 build_type_variant (double_type_node, 1, 0));
22650   tree int_ftype_v2df_v2df
22651     = build_function_type_list (integer_type_node,
22652                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
22653
22654   tree void_ftype_pcvoid
22655     = build_function_type_list (void_type_node, const_ptr_type_node, NULL_TREE);
22656   tree v4sf_ftype_v4si
22657     = build_function_type_list (V4SF_type_node, V4SI_type_node, NULL_TREE);
22658   tree v4si_ftype_v4sf
22659     = build_function_type_list (V4SI_type_node, V4SF_type_node, NULL_TREE);
22660   tree v2df_ftype_v4si
22661     = build_function_type_list (V2DF_type_node, V4SI_type_node, NULL_TREE);
22662   tree v4si_ftype_v2df
22663     = build_function_type_list (V4SI_type_node, V2DF_type_node, NULL_TREE);
22664   tree v4si_ftype_v2df_v2df
22665     = build_function_type_list (V4SI_type_node,
22666                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
22667   tree v2si_ftype_v2df
22668     = build_function_type_list (V2SI_type_node, V2DF_type_node, NULL_TREE);
22669   tree v4sf_ftype_v2df
22670     = build_function_type_list (V4SF_type_node, V2DF_type_node, NULL_TREE);
22671   tree v2df_ftype_v2si
22672     = build_function_type_list (V2DF_type_node, V2SI_type_node, NULL_TREE);
22673   tree v2df_ftype_v4sf
22674     = build_function_type_list (V2DF_type_node, V4SF_type_node, NULL_TREE);
22675   tree int_ftype_v2df
22676     = build_function_type_list (integer_type_node, V2DF_type_node, NULL_TREE);
22677   tree int64_ftype_v2df
22678     = build_function_type_list (long_long_integer_type_node,
22679                                 V2DF_type_node, NULL_TREE);
22680   tree v2df_ftype_v2df_int
22681     = build_function_type_list (V2DF_type_node,
22682                                 V2DF_type_node, integer_type_node, NULL_TREE);
22683   tree v2df_ftype_v2df_int64
22684     = build_function_type_list (V2DF_type_node,
22685                                 V2DF_type_node, long_long_integer_type_node,
22686                                 NULL_TREE);
22687   tree v4sf_ftype_v4sf_v2df
22688     = build_function_type_list (V4SF_type_node,
22689                                 V4SF_type_node, V2DF_type_node, NULL_TREE);
22690   tree v2df_ftype_v2df_v4sf
22691     = build_function_type_list (V2DF_type_node,
22692                                 V2DF_type_node, V4SF_type_node, NULL_TREE);
22693   tree v2df_ftype_v2df_v2df_int
22694     = build_function_type_list (V2DF_type_node,
22695                                 V2DF_type_node, V2DF_type_node,
22696                                 integer_type_node,
22697                                 NULL_TREE);
22698   tree v2df_ftype_v2df_pcdouble
22699     = build_function_type_list (V2DF_type_node,
22700                                 V2DF_type_node, pcdouble_type_node, NULL_TREE);
22701   tree void_ftype_pdouble_v2df
22702     = build_function_type_list (void_type_node,
22703                                 pdouble_type_node, V2DF_type_node, NULL_TREE);
22704   tree void_ftype_pint_int
22705     = build_function_type_list (void_type_node,
22706                                 pint_type_node, integer_type_node, NULL_TREE);
22707   tree void_ftype_v16qi_v16qi_pchar
22708     = build_function_type_list (void_type_node,
22709                                 V16QI_type_node, V16QI_type_node,
22710                                 pchar_type_node, NULL_TREE);
22711   tree v2df_ftype_pcdouble
22712     = build_function_type_list (V2DF_type_node, pcdouble_type_node, NULL_TREE);
22713   tree v2df_ftype_v2df_v2df
22714     = build_function_type_list (V2DF_type_node,
22715                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
22716   tree v16qi_ftype_v16qi_v16qi
22717     = build_function_type_list (V16QI_type_node,
22718                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
22719   tree v8hi_ftype_v8hi_v8hi
22720     = build_function_type_list (V8HI_type_node,
22721                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
22722   tree v4si_ftype_v4si_v4si
22723     = build_function_type_list (V4SI_type_node,
22724                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
22725   tree v2di_ftype_v2di_v2di
22726     = build_function_type_list (V2DI_type_node,
22727                                 V2DI_type_node, V2DI_type_node, NULL_TREE);
22728   tree v2di_ftype_v2df_v2df
22729     = build_function_type_list (V2DI_type_node,
22730                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
22731   tree v2df_ftype_v2df
22732     = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
22733   tree v2di_ftype_v2di_int
22734     = build_function_type_list (V2DI_type_node,
22735                                 V2DI_type_node, integer_type_node, NULL_TREE);
22736   tree v2di_ftype_v2di_v2di_int
22737     = build_function_type_list (V2DI_type_node, V2DI_type_node,
22738                                 V2DI_type_node, integer_type_node, NULL_TREE);
22739   tree v4si_ftype_v4si_int
22740     = build_function_type_list (V4SI_type_node,
22741                                 V4SI_type_node, integer_type_node, NULL_TREE);
22742   tree v8hi_ftype_v8hi_int
22743     = build_function_type_list (V8HI_type_node,
22744                                 V8HI_type_node, integer_type_node, NULL_TREE);
22745   tree v4si_ftype_v8hi_v8hi
22746     = build_function_type_list (V4SI_type_node,
22747                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
22748   tree v1di_ftype_v8qi_v8qi
22749     = build_function_type_list (V1DI_type_node,
22750                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
22751   tree v1di_ftype_v2si_v2si
22752     = build_function_type_list (V1DI_type_node,
22753                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
22754   tree v2di_ftype_v16qi_v16qi
22755     = build_function_type_list (V2DI_type_node,
22756                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
22757   tree v2di_ftype_v4si_v4si
22758     = build_function_type_list (V2DI_type_node,
22759                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
22760   tree int_ftype_v16qi
22761     = build_function_type_list (integer_type_node, V16QI_type_node, NULL_TREE);
22762   tree v16qi_ftype_pcchar
22763     = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
22764   tree void_ftype_pchar_v16qi
22765     = build_function_type_list (void_type_node,
22766                                 pchar_type_node, V16QI_type_node, NULL_TREE);
22767
22768   tree v2di_ftype_v2di_unsigned_unsigned
22769     = build_function_type_list (V2DI_type_node, V2DI_type_node,
22770                                 unsigned_type_node, unsigned_type_node,
22771                                 NULL_TREE);
22772   tree v2di_ftype_v2di_v2di_unsigned_unsigned
22773     = build_function_type_list (V2DI_type_node, V2DI_type_node, V2DI_type_node,
22774                                 unsigned_type_node, unsigned_type_node,
22775                                 NULL_TREE);
22776   tree v2di_ftype_v2di_v16qi
22777     = build_function_type_list (V2DI_type_node, V2DI_type_node, V16QI_type_node,
22778                                 NULL_TREE);
22779   tree v2df_ftype_v2df_v2df_v2df
22780     = build_function_type_list (V2DF_type_node,
22781                                 V2DF_type_node, V2DF_type_node,
22782                                 V2DF_type_node, NULL_TREE);
22783   tree v4sf_ftype_v4sf_v4sf_v4sf
22784     = build_function_type_list (V4SF_type_node,
22785                                 V4SF_type_node, V4SF_type_node,
22786                                 V4SF_type_node, NULL_TREE);
22787   tree v8hi_ftype_v16qi
22788     = build_function_type_list (V8HI_type_node, V16QI_type_node,
22789                                 NULL_TREE);
22790   tree v4si_ftype_v16qi
22791     = build_function_type_list (V4SI_type_node, V16QI_type_node,
22792                                 NULL_TREE);
22793   tree v2di_ftype_v16qi
22794     = build_function_type_list (V2DI_type_node, V16QI_type_node,
22795                                 NULL_TREE);
22796   tree v4si_ftype_v8hi
22797     = build_function_type_list (V4SI_type_node, V8HI_type_node,
22798                                 NULL_TREE);
22799   tree v2di_ftype_v8hi
22800     = build_function_type_list (V2DI_type_node, V8HI_type_node,
22801                                 NULL_TREE);
22802   tree v2di_ftype_v4si
22803     = build_function_type_list (V2DI_type_node, V4SI_type_node,
22804                                 NULL_TREE);
22805   tree v2di_ftype_pv2di
22806     = build_function_type_list (V2DI_type_node, pv2di_type_node,
22807                                 NULL_TREE);
22808   tree v16qi_ftype_v16qi_v16qi_int
22809     = build_function_type_list (V16QI_type_node, V16QI_type_node,
22810                                 V16QI_type_node, integer_type_node,
22811                                 NULL_TREE);
22812   tree v16qi_ftype_v16qi_v16qi_v16qi
22813     = build_function_type_list (V16QI_type_node, V16QI_type_node,
22814                                 V16QI_type_node, V16QI_type_node,
22815                                 NULL_TREE);
22816   tree v8hi_ftype_v8hi_v8hi_int
22817     = build_function_type_list (V8HI_type_node, V8HI_type_node,
22818                                 V8HI_type_node, integer_type_node,
22819                                 NULL_TREE);
22820   tree v4si_ftype_v4si_v4si_int
22821     = build_function_type_list (V4SI_type_node, V4SI_type_node,
22822                                 V4SI_type_node, integer_type_node,
22823                                 NULL_TREE);
22824   tree int_ftype_v2di_v2di
22825     = build_function_type_list (integer_type_node,
22826                                 V2DI_type_node, V2DI_type_node,
22827                                 NULL_TREE);
22828   tree int_ftype_v16qi_int_v16qi_int_int
22829     = build_function_type_list (integer_type_node,
22830                                 V16QI_type_node,
22831                                 integer_type_node,
22832                                 V16QI_type_node,
22833                                 integer_type_node,
22834                                 integer_type_node,
22835                                 NULL_TREE);
22836   tree v16qi_ftype_v16qi_int_v16qi_int_int
22837     = build_function_type_list (V16QI_type_node,
22838                                 V16QI_type_node,
22839                                 integer_type_node,
22840                                 V16QI_type_node,
22841                                 integer_type_node,
22842                                 integer_type_node,
22843                                 NULL_TREE);
22844   tree int_ftype_v16qi_v16qi_int
22845     = build_function_type_list (integer_type_node,
22846                                 V16QI_type_node,
22847                                 V16QI_type_node,
22848                                 integer_type_node,
22849                                 NULL_TREE);
22850
22851   /* SSE5 instructions */
22852   tree v2di_ftype_v2di_v2di_v2di
22853     = build_function_type_list (V2DI_type_node,
22854                                 V2DI_type_node,
22855                                 V2DI_type_node,
22856                                 V2DI_type_node,
22857                                 NULL_TREE);
22858
22859   tree v4si_ftype_v4si_v4si_v4si
22860     = build_function_type_list (V4SI_type_node,
22861                                 V4SI_type_node,
22862                                 V4SI_type_node,
22863                                 V4SI_type_node,
22864                                 NULL_TREE);
22865
22866   tree v4si_ftype_v4si_v4si_v2di
22867     = build_function_type_list (V4SI_type_node,
22868                                 V4SI_type_node,
22869                                 V4SI_type_node,
22870                                 V2DI_type_node,
22871                                 NULL_TREE);
22872
22873   tree v8hi_ftype_v8hi_v8hi_v8hi
22874     = build_function_type_list (V8HI_type_node,
22875                                 V8HI_type_node,
22876                                 V8HI_type_node,
22877                                 V8HI_type_node,
22878                                 NULL_TREE);
22879
22880   tree v8hi_ftype_v8hi_v8hi_v4si
22881     = build_function_type_list (V8HI_type_node,
22882                                 V8HI_type_node,
22883                                 V8HI_type_node,
22884                                 V4SI_type_node,
22885                                 NULL_TREE);
22886
22887   tree v2df_ftype_v2df_v2df_v16qi
22888     = build_function_type_list (V2DF_type_node,
22889                                 V2DF_type_node,
22890                                 V2DF_type_node,
22891                                 V16QI_type_node,
22892                                 NULL_TREE);
22893
22894   tree v4sf_ftype_v4sf_v4sf_v16qi
22895     = build_function_type_list (V4SF_type_node,
22896                                 V4SF_type_node,
22897                                 V4SF_type_node,
22898                                 V16QI_type_node,
22899                                 NULL_TREE);
22900
22901   tree v2di_ftype_v2di_si
22902     = build_function_type_list (V2DI_type_node,
22903                                 V2DI_type_node,
22904                                 integer_type_node,
22905                                 NULL_TREE);
22906
22907   tree v4si_ftype_v4si_si
22908     = build_function_type_list (V4SI_type_node,
22909                                 V4SI_type_node,
22910                                 integer_type_node,
22911                                 NULL_TREE);
22912
22913   tree v8hi_ftype_v8hi_si
22914     = build_function_type_list (V8HI_type_node,
22915                                 V8HI_type_node,
22916                                 integer_type_node,
22917                                 NULL_TREE);
22918
22919   tree v16qi_ftype_v16qi_si
22920     = build_function_type_list (V16QI_type_node,
22921                                 V16QI_type_node,
22922                                 integer_type_node,
22923                                 NULL_TREE);
22924   tree v4sf_ftype_v4hi
22925     = build_function_type_list (V4SF_type_node,
22926                                 V4HI_type_node,
22927                                 NULL_TREE);
22928
22929   tree v4hi_ftype_v4sf
22930     = build_function_type_list (V4HI_type_node,
22931                                 V4SF_type_node,
22932                                 NULL_TREE);
22933
22934   tree v2di_ftype_v2di
22935     = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
22936
22937   tree v16qi_ftype_v8hi_v8hi
22938     = build_function_type_list (V16QI_type_node,
22939                                 V8HI_type_node, V8HI_type_node,
22940                                 NULL_TREE);
22941   tree v8hi_ftype_v4si_v4si
22942     = build_function_type_list (V8HI_type_node,
22943                                 V4SI_type_node, V4SI_type_node,
22944                                 NULL_TREE);
22945   tree v8hi_ftype_v16qi_v16qi 
22946     = build_function_type_list (V8HI_type_node,
22947                                 V16QI_type_node, V16QI_type_node,
22948                                 NULL_TREE);
22949   tree v4hi_ftype_v8qi_v8qi 
22950     = build_function_type_list (V4HI_type_node,
22951                                 V8QI_type_node, V8QI_type_node,
22952                                 NULL_TREE);
22953   tree unsigned_ftype_unsigned_uchar
22954     = build_function_type_list (unsigned_type_node,
22955                                 unsigned_type_node,
22956                                 unsigned_char_type_node,
22957                                 NULL_TREE);
22958   tree unsigned_ftype_unsigned_ushort
22959     = build_function_type_list (unsigned_type_node,
22960                                 unsigned_type_node,
22961                                 short_unsigned_type_node,
22962                                 NULL_TREE);
22963   tree unsigned_ftype_unsigned_unsigned
22964     = build_function_type_list (unsigned_type_node,
22965                                 unsigned_type_node,
22966                                 unsigned_type_node,
22967                                 NULL_TREE);
22968   tree uint64_ftype_uint64_uint64
22969     = build_function_type_list (long_long_unsigned_type_node,
22970                                 long_long_unsigned_type_node,
22971                                 long_long_unsigned_type_node,
22972                                 NULL_TREE);
22973   tree float_ftype_float
22974     = build_function_type_list (float_type_node,
22975                                 float_type_node,
22976                                 NULL_TREE);
22977
22978   /* AVX builtins  */
22979   tree V32QI_type_node = build_vector_type_for_mode (char_type_node,
22980                                                      V32QImode);
22981   tree V8SI_type_node = build_vector_type_for_mode (intSI_type_node,
22982                                                     V8SImode);
22983   tree V8SF_type_node = build_vector_type_for_mode (float_type_node,
22984                                                     V8SFmode);
22985   tree V4DI_type_node = build_vector_type_for_mode (long_long_integer_type_node,
22986                                                     V4DImode);
22987   tree V4DF_type_node = build_vector_type_for_mode (double_type_node,
22988                                                     V4DFmode);
22989   tree v8sf_ftype_v8sf
22990     = build_function_type_list (V8SF_type_node,
22991                                 V8SF_type_node,
22992                                 NULL_TREE);
22993   tree v8si_ftype_v8sf
22994     = build_function_type_list (V8SI_type_node,
22995                                 V8SF_type_node,
22996                                 NULL_TREE);
22997   tree v8sf_ftype_v8si
22998     = build_function_type_list (V8SF_type_node,
22999                                 V8SI_type_node,
23000                                 NULL_TREE);
23001   tree v4si_ftype_v4df
23002     = build_function_type_list (V4SI_type_node,
23003                                 V4DF_type_node,
23004                                 NULL_TREE);
23005   tree v4df_ftype_v4df
23006     = build_function_type_list (V4DF_type_node,
23007                                 V4DF_type_node,
23008                                 NULL_TREE);
23009   tree v4df_ftype_v4si
23010     = build_function_type_list (V4DF_type_node,
23011                                 V4SI_type_node,
23012                                 NULL_TREE);
23013   tree v4df_ftype_v4sf
23014     = build_function_type_list (V4DF_type_node,
23015                                 V4SF_type_node,
23016                                 NULL_TREE);
23017   tree v4sf_ftype_v4df
23018     = build_function_type_list (V4SF_type_node,
23019                                 V4DF_type_node,
23020                                 NULL_TREE);
23021   tree v8sf_ftype_v8sf_v8sf
23022     = build_function_type_list (V8SF_type_node,
23023                                 V8SF_type_node, V8SF_type_node,
23024                                 NULL_TREE);
23025   tree v4df_ftype_v4df_v4df
23026     = build_function_type_list (V4DF_type_node,
23027                                 V4DF_type_node, V4DF_type_node,
23028                                 NULL_TREE);
23029   tree v8sf_ftype_v8sf_int
23030     = build_function_type_list (V8SF_type_node,
23031                                 V8SF_type_node, integer_type_node,
23032                                 NULL_TREE);
23033   tree v4si_ftype_v8si_int
23034     = build_function_type_list (V4SI_type_node,
23035                                 V8SI_type_node, integer_type_node,
23036                                 NULL_TREE);
23037   tree v4df_ftype_v4df_int
23038     = build_function_type_list (V4DF_type_node,
23039                                 V4DF_type_node, integer_type_node,
23040                                 NULL_TREE);
23041   tree v4sf_ftype_v8sf_int
23042     = build_function_type_list (V4SF_type_node,
23043                                 V8SF_type_node, integer_type_node,
23044                                 NULL_TREE);
23045   tree v2df_ftype_v4df_int
23046     = build_function_type_list (V2DF_type_node,
23047                                 V4DF_type_node, integer_type_node,
23048                                 NULL_TREE);
23049   tree v8sf_ftype_v8sf_v8sf_int
23050     = build_function_type_list (V8SF_type_node,
23051                                 V8SF_type_node, V8SF_type_node,
23052                                 integer_type_node,
23053                                 NULL_TREE);
23054   tree v8sf_ftype_v8sf_v8sf_v8sf
23055     = build_function_type_list (V8SF_type_node,
23056                                 V8SF_type_node, V8SF_type_node,
23057                                 V8SF_type_node,
23058                                 NULL_TREE);
23059   tree v4df_ftype_v4df_v4df_v4df
23060     = build_function_type_list (V4DF_type_node,
23061                                 V4DF_type_node, V4DF_type_node,
23062                                 V4DF_type_node,
23063                                 NULL_TREE);
23064   tree v8si_ftype_v8si_v8si_int
23065     = build_function_type_list (V8SI_type_node,
23066                                 V8SI_type_node, V8SI_type_node,
23067                                 integer_type_node,
23068                                 NULL_TREE);
23069   tree v4df_ftype_v4df_v4df_int
23070     = build_function_type_list (V4DF_type_node,
23071                                 V4DF_type_node, V4DF_type_node,
23072                                 integer_type_node,
23073                                 NULL_TREE);
23074   tree v8sf_ftype_pcfloat
23075     = build_function_type_list (V8SF_type_node,
23076                                 pcfloat_type_node,
23077                                 NULL_TREE);
23078   tree v4df_ftype_pcdouble
23079     = build_function_type_list (V4DF_type_node,
23080                                 pcdouble_type_node,
23081                                 NULL_TREE);
23082   tree pcv4sf_type_node
23083     = build_pointer_type (build_type_variant (V4SF_type_node, 1, 0));
23084   tree pcv2df_type_node
23085     = build_pointer_type (build_type_variant (V2DF_type_node, 1, 0));
23086   tree v8sf_ftype_pcv4sf
23087     = build_function_type_list (V8SF_type_node,
23088                                 pcv4sf_type_node,
23089                                 NULL_TREE);
23090   tree v4df_ftype_pcv2df
23091     = build_function_type_list (V4DF_type_node,
23092                                 pcv2df_type_node,
23093                                 NULL_TREE);
23094   tree v32qi_ftype_pcchar
23095     = build_function_type_list (V32QI_type_node,
23096                                 pcchar_type_node,
23097                                 NULL_TREE);
23098   tree void_ftype_pchar_v32qi
23099     = build_function_type_list (void_type_node,
23100                                 pchar_type_node, V32QI_type_node,
23101                                 NULL_TREE);
23102   tree v8si_ftype_v8si_v4si_int
23103     = build_function_type_list (V8SI_type_node,
23104                                 V8SI_type_node, V4SI_type_node,
23105                                 integer_type_node,
23106                                 NULL_TREE);
23107   tree pv4di_type_node = build_pointer_type (V4DI_type_node);
23108   tree void_ftype_pv4di_v4di
23109     = build_function_type_list (void_type_node,
23110                                 pv4di_type_node, V4DI_type_node,
23111                                 NULL_TREE);
23112   tree v8sf_ftype_v8sf_v4sf_int
23113     = build_function_type_list (V8SF_type_node,
23114                                 V8SF_type_node, V4SF_type_node,
23115                                 integer_type_node,
23116                                 NULL_TREE);
23117   tree v4df_ftype_v4df_v2df_int
23118     = build_function_type_list (V4DF_type_node,
23119                                 V4DF_type_node, V2DF_type_node,
23120                                 integer_type_node,
23121                                 NULL_TREE);
23122   tree void_ftype_pfloat_v8sf
23123     = build_function_type_list (void_type_node,
23124                                 pfloat_type_node, V8SF_type_node,
23125                                 NULL_TREE);
23126   tree void_ftype_pdouble_v4df
23127     = build_function_type_list (void_type_node,
23128                                 pdouble_type_node, V4DF_type_node,
23129                                 NULL_TREE);
23130   tree pv8sf_type_node = build_pointer_type (V8SF_type_node);
23131   tree pv4sf_type_node = build_pointer_type (V4SF_type_node);
23132   tree pv4df_type_node = build_pointer_type (V4DF_type_node);
23133   tree pv2df_type_node = build_pointer_type (V2DF_type_node);
23134   tree pcv8sf_type_node
23135     = build_pointer_type (build_type_variant (V8SF_type_node, 1, 0));
23136   tree pcv4df_type_node
23137     = build_pointer_type (build_type_variant (V4DF_type_node, 1, 0));
23138   tree v8sf_ftype_pcv8sf_v8sf
23139     = build_function_type_list (V8SF_type_node,
23140                                 pcv8sf_type_node, V8SF_type_node,
23141                                 NULL_TREE);
23142   tree v4df_ftype_pcv4df_v4df
23143     = build_function_type_list (V4DF_type_node,
23144                                 pcv4df_type_node, V4DF_type_node,
23145                                 NULL_TREE);
23146   tree v4sf_ftype_pcv4sf_v4sf
23147     = build_function_type_list (V4SF_type_node,
23148                                 pcv4sf_type_node, V4SF_type_node,
23149                                 NULL_TREE);
23150   tree v2df_ftype_pcv2df_v2df
23151     = build_function_type_list (V2DF_type_node,
23152                                 pcv2df_type_node, V2DF_type_node,
23153                                 NULL_TREE);
23154   tree void_ftype_pv8sf_v8sf_v8sf
23155     = build_function_type_list (void_type_node,
23156                                 pv8sf_type_node, V8SF_type_node,
23157                                 V8SF_type_node,
23158                                 NULL_TREE);
23159   tree void_ftype_pv4df_v4df_v4df
23160     = build_function_type_list (void_type_node,
23161                                 pv4df_type_node, V4DF_type_node,
23162                                 V4DF_type_node,
23163                                 NULL_TREE);
23164   tree void_ftype_pv4sf_v4sf_v4sf
23165     = build_function_type_list (void_type_node,
23166                                 pv4sf_type_node, V4SF_type_node,
23167                                 V4SF_type_node,
23168                                 NULL_TREE);
23169   tree void_ftype_pv2df_v2df_v2df
23170     = build_function_type_list (void_type_node,
23171                                 pv2df_type_node, V2DF_type_node,
23172                                 V2DF_type_node,
23173                                 NULL_TREE);
23174   tree v4df_ftype_v2df
23175     = build_function_type_list (V4DF_type_node,
23176                                 V2DF_type_node,
23177                                 NULL_TREE);
23178   tree v8sf_ftype_v4sf
23179     = build_function_type_list (V8SF_type_node,
23180                                 V4SF_type_node,
23181                                 NULL_TREE);
23182   tree v8si_ftype_v4si
23183     = build_function_type_list (V8SI_type_node,
23184                                 V4SI_type_node,
23185                                 NULL_TREE);
23186   tree v2df_ftype_v4df
23187     = build_function_type_list (V2DF_type_node,
23188                                 V4DF_type_node,
23189                                 NULL_TREE);
23190   tree v4sf_ftype_v8sf
23191     = build_function_type_list (V4SF_type_node,
23192                                 V8SF_type_node,
23193                                 NULL_TREE);
23194   tree v4si_ftype_v8si
23195     = build_function_type_list (V4SI_type_node,
23196                                 V8SI_type_node,
23197                                 NULL_TREE);
23198   tree int_ftype_v4df
23199     = build_function_type_list (integer_type_node,
23200                                 V4DF_type_node,
23201                                 NULL_TREE);
23202   tree int_ftype_v8sf
23203     = build_function_type_list (integer_type_node,
23204                                 V8SF_type_node,
23205                                 NULL_TREE);
23206   tree int_ftype_v8sf_v8sf
23207     = build_function_type_list (integer_type_node,
23208                                 V8SF_type_node, V8SF_type_node,
23209                                 NULL_TREE);
23210   tree int_ftype_v4di_v4di
23211     = build_function_type_list (integer_type_node,
23212                                 V4DI_type_node, V4DI_type_node,
23213                                 NULL_TREE);
23214   tree int_ftype_v4df_v4df
23215     = build_function_type_list (integer_type_node,
23216                                 V4DF_type_node, V4DF_type_node,
23217                                 NULL_TREE);
23218   tree v8sf_ftype_v8sf_v8si
23219     = build_function_type_list (V8SF_type_node,
23220                                 V8SF_type_node, V8SI_type_node,
23221                                 NULL_TREE);
23222   tree v4df_ftype_v4df_v4di
23223     = build_function_type_list (V4DF_type_node,
23224                                 V4DF_type_node, V4DI_type_node,
23225                                 NULL_TREE);
23226   tree v4sf_ftype_v4sf_v4si
23227     = build_function_type_list (V4SF_type_node,
23228                                 V4SF_type_node, V4SI_type_node, NULL_TREE);
23229   tree v2df_ftype_v2df_v2di
23230     = build_function_type_list (V2DF_type_node,
23231                                 V2DF_type_node, V2DI_type_node, NULL_TREE);
23232
23233   /* Integer intrinsics.  */
23234   tree uint64_ftype_void
23235     = build_function_type (long_long_unsigned_type_node,
23236                            void_list_node);
23237   tree int_ftype_int
23238     = build_function_type_list (integer_type_node,
23239                                 integer_type_node, NULL_TREE);
23240   tree int64_ftype_int64
23241     = build_function_type_list (long_long_integer_type_node,
23242                                 long_long_integer_type_node,
23243                                 NULL_TREE);
23244   tree uint64_ftype_int
23245     = build_function_type_list (long_long_unsigned_type_node,
23246                                 integer_type_node, NULL_TREE);
23247   tree punsigned_type_node = build_pointer_type (unsigned_type_node);
23248   tree uint64_ftype_punsigned
23249     = build_function_type_list (long_long_unsigned_type_node,
23250                                 punsigned_type_node, NULL_TREE);
23251   tree ushort_ftype_ushort_int
23252     = build_function_type_list (short_unsigned_type_node,
23253                                 short_unsigned_type_node,
23254                                 integer_type_node,
23255                                 NULL_TREE);
23256   tree uchar_ftype_uchar_int
23257     = build_function_type_list (unsigned_char_type_node,
23258                                 unsigned_char_type_node,
23259                                 integer_type_node,
23260                                 NULL_TREE);
23261
23262   tree ftype;
23263
23264   /* Add all special builtins with variable number of operands.  */
23265   for (i = 0, d = bdesc_special_args;
23266        i < ARRAY_SIZE (bdesc_special_args);
23267        i++, d++)
23268     {
23269       tree type;
23270
23271       if (d->name == 0)
23272         continue;
23273
23274       switch ((enum ix86_special_builtin_type) d->flag)
23275         {
23276         case VOID_FTYPE_VOID:
23277           type = void_ftype_void;
23278           break;
23279         case UINT64_FTYPE_VOID:
23280           type = uint64_ftype_void;
23281           break;
23282         case UINT64_FTYPE_PUNSIGNED:
23283           type = uint64_ftype_punsigned;
23284           break;
23285         case V32QI_FTYPE_PCCHAR:
23286           type = v32qi_ftype_pcchar;
23287           break;
23288         case V16QI_FTYPE_PCCHAR:
23289           type = v16qi_ftype_pcchar;
23290           break;
23291         case V8SF_FTYPE_PCV4SF:
23292           type = v8sf_ftype_pcv4sf;
23293           break;
23294         case V8SF_FTYPE_PCFLOAT:
23295           type = v8sf_ftype_pcfloat;
23296           break;
23297         case V4DF_FTYPE_PCV2DF:
23298           type = v4df_ftype_pcv2df;
23299           break;
23300         case V4DF_FTYPE_PCDOUBLE:
23301           type = v4df_ftype_pcdouble;
23302           break;
23303         case V4SF_FTYPE_PCFLOAT:
23304           type = v4sf_ftype_pcfloat;
23305           break;
23306         case V2DI_FTYPE_PV2DI:
23307           type = v2di_ftype_pv2di;
23308           break;
23309         case V2DF_FTYPE_PCDOUBLE:
23310           type = v2df_ftype_pcdouble;
23311           break;
23312         case V8SF_FTYPE_PCV8SF_V8SF:
23313           type = v8sf_ftype_pcv8sf_v8sf;
23314           break;
23315         case V4DF_FTYPE_PCV4DF_V4DF:
23316           type = v4df_ftype_pcv4df_v4df;
23317           break;
23318         case V4SF_FTYPE_V4SF_PCV2SF:
23319           type = v4sf_ftype_v4sf_pcv2sf;
23320           break;
23321         case V4SF_FTYPE_PCV4SF_V4SF:
23322           type = v4sf_ftype_pcv4sf_v4sf;
23323           break;
23324         case V2DF_FTYPE_V2DF_PCDOUBLE:
23325           type = v2df_ftype_v2df_pcdouble;
23326           break;
23327         case V2DF_FTYPE_PCV2DF_V2DF:
23328           type = v2df_ftype_pcv2df_v2df;
23329           break;
23330         case VOID_FTYPE_PV2SF_V4SF:
23331           type = void_ftype_pv2sf_v4sf;
23332           break;
23333         case VOID_FTYPE_PV4DI_V4DI:
23334           type = void_ftype_pv4di_v4di;
23335           break;
23336         case VOID_FTYPE_PV2DI_V2DI:
23337           type = void_ftype_pv2di_v2di;
23338           break;
23339         case VOID_FTYPE_PCHAR_V32QI:
23340           type = void_ftype_pchar_v32qi;
23341           break;
23342         case VOID_FTYPE_PCHAR_V16QI:
23343           type = void_ftype_pchar_v16qi;
23344           break;
23345         case VOID_FTYPE_PFLOAT_V8SF:
23346           type = void_ftype_pfloat_v8sf;
23347           break;
23348         case VOID_FTYPE_PFLOAT_V4SF:
23349           type = void_ftype_pfloat_v4sf;
23350           break;
23351         case VOID_FTYPE_PDOUBLE_V4DF:
23352           type = void_ftype_pdouble_v4df;
23353           break;
23354         case VOID_FTYPE_PDOUBLE_V2DF:
23355           type = void_ftype_pdouble_v2df;
23356           break;
23357         case VOID_FTYPE_PDI_DI:
23358           type = void_ftype_pdi_di;
23359           break;
23360         case VOID_FTYPE_PINT_INT:
23361           type = void_ftype_pint_int;
23362           break;
23363         case VOID_FTYPE_PV8SF_V8SF_V8SF:
23364           type = void_ftype_pv8sf_v8sf_v8sf;
23365           break;
23366         case VOID_FTYPE_PV4DF_V4DF_V4DF:
23367           type = void_ftype_pv4df_v4df_v4df;
23368           break;
23369         case VOID_FTYPE_PV4SF_V4SF_V4SF:
23370           type = void_ftype_pv4sf_v4sf_v4sf;
23371           break;
23372         case VOID_FTYPE_PV2DF_V2DF_V2DF:
23373           type = void_ftype_pv2df_v2df_v2df;
23374           break;
23375         default:
23376           gcc_unreachable ();
23377         }
23378
23379       def_builtin (d->mask, d->name, type, d->code);
23380     }
23381
23382   /* Add all builtins with variable number of operands.  */
23383   for (i = 0, d = bdesc_args;
23384        i < ARRAY_SIZE (bdesc_args);
23385        i++, d++)
23386     {
23387       tree type;
23388
23389       if (d->name == 0)
23390         continue;
23391
23392       switch ((enum ix86_builtin_type) d->flag)
23393         {
23394         case FLOAT_FTYPE_FLOAT:
23395           type = float_ftype_float;
23396           break;
23397         case INT_FTYPE_V8SF_V8SF_PTEST:
23398           type = int_ftype_v8sf_v8sf;
23399           break;
23400         case INT_FTYPE_V4DI_V4DI_PTEST:
23401           type = int_ftype_v4di_v4di;
23402           break;
23403         case INT_FTYPE_V4DF_V4DF_PTEST:
23404           type = int_ftype_v4df_v4df;
23405           break;
23406         case INT_FTYPE_V4SF_V4SF_PTEST:
23407           type = int_ftype_v4sf_v4sf;
23408           break;
23409         case INT_FTYPE_V2DI_V2DI_PTEST:
23410           type = int_ftype_v2di_v2di;
23411           break;
23412         case INT_FTYPE_V2DF_V2DF_PTEST:
23413           type = int_ftype_v2df_v2df;
23414           break;
23415         case INT_FTYPE_INT:
23416           type = int_ftype_int;
23417           break;
23418         case UINT64_FTYPE_INT:
23419           type = uint64_ftype_int;
23420           break;
23421         case INT64_FTYPE_INT64:
23422           type = int64_ftype_int64;
23423           break;
23424         case INT64_FTYPE_V4SF:
23425           type = int64_ftype_v4sf;
23426           break;
23427         case INT64_FTYPE_V2DF:
23428           type = int64_ftype_v2df;
23429           break;
23430         case INT_FTYPE_V16QI:
23431           type = int_ftype_v16qi;
23432           break;
23433         case INT_FTYPE_V8QI:
23434           type = int_ftype_v8qi;
23435           break;
23436         case INT_FTYPE_V8SF:
23437           type = int_ftype_v8sf;
23438           break;
23439         case INT_FTYPE_V4DF:
23440           type = int_ftype_v4df;
23441           break;
23442         case INT_FTYPE_V4SF:
23443           type = int_ftype_v4sf;
23444           break;
23445         case INT_FTYPE_V2DF:
23446           type = int_ftype_v2df;
23447           break;
23448         case V16QI_FTYPE_V16QI:
23449           type = v16qi_ftype_v16qi;
23450           break;
23451         case V8SI_FTYPE_V8SF:
23452           type = v8si_ftype_v8sf;
23453           break;
23454         case V8SI_FTYPE_V4SI:
23455           type = v8si_ftype_v4si;
23456           break;
23457         case V8HI_FTYPE_V8HI:
23458           type = v8hi_ftype_v8hi;
23459           break;
23460         case V8HI_FTYPE_V16QI:
23461           type = v8hi_ftype_v16qi;
23462           break;
23463         case V8QI_FTYPE_V8QI:
23464           type = v8qi_ftype_v8qi;
23465           break;
23466         case V8SF_FTYPE_V8SF:
23467           type = v8sf_ftype_v8sf;
23468           break;
23469         case V8SF_FTYPE_V8SI:
23470           type = v8sf_ftype_v8si;
23471           break;
23472         case V8SF_FTYPE_V4SF:
23473           type = v8sf_ftype_v4sf;
23474           break;
23475         case V4SI_FTYPE_V4DF:
23476           type = v4si_ftype_v4df;
23477           break;
23478         case V4SI_FTYPE_V4SI:
23479           type = v4si_ftype_v4si;
23480           break;
23481         case V4SI_FTYPE_V16QI:
23482           type = v4si_ftype_v16qi;
23483           break;
23484         case V4SI_FTYPE_V8SI:
23485           type = v4si_ftype_v8si;
23486           break;
23487         case V4SI_FTYPE_V8HI:
23488           type = v4si_ftype_v8hi;
23489           break;
23490         case V4SI_FTYPE_V4SF:
23491           type = v4si_ftype_v4sf;
23492           break;
23493         case V4SI_FTYPE_V2DF:
23494           type = v4si_ftype_v2df;
23495           break;
23496         case V4HI_FTYPE_V4HI:
23497           type = v4hi_ftype_v4hi;
23498           break;
23499         case V4DF_FTYPE_V4DF:
23500           type = v4df_ftype_v4df;
23501           break;
23502         case V4DF_FTYPE_V4SI:
23503           type = v4df_ftype_v4si;
23504           break;
23505         case V4DF_FTYPE_V4SF:
23506           type = v4df_ftype_v4sf;
23507           break;
23508         case V4DF_FTYPE_V2DF:
23509           type = v4df_ftype_v2df;
23510           break;
23511         case V4SF_FTYPE_V4SF:
23512         case V4SF_FTYPE_V4SF_VEC_MERGE:
23513           type = v4sf_ftype_v4sf;
23514           break;
23515         case V4SF_FTYPE_V8SF:
23516           type = v4sf_ftype_v8sf;
23517           break;
23518         case V4SF_FTYPE_V4SI:
23519           type = v4sf_ftype_v4si;
23520           break;
23521         case V4SF_FTYPE_V4DF:
23522           type = v4sf_ftype_v4df;
23523           break;
23524         case V4SF_FTYPE_V2DF:
23525           type = v4sf_ftype_v2df;
23526           break;
23527         case V2DI_FTYPE_V2DI:
23528           type = v2di_ftype_v2di;
23529           break;
23530         case V2DI_FTYPE_V16QI:
23531           type = v2di_ftype_v16qi;
23532           break;
23533         case V2DI_FTYPE_V8HI:
23534           type = v2di_ftype_v8hi;
23535           break;
23536         case V2DI_FTYPE_V4SI:
23537           type = v2di_ftype_v4si;
23538           break;
23539         case V2SI_FTYPE_V2SI:
23540           type = v2si_ftype_v2si;
23541           break;
23542         case V2SI_FTYPE_V4SF:
23543           type = v2si_ftype_v4sf;
23544           break;
23545         case V2SI_FTYPE_V2DF:
23546           type = v2si_ftype_v2df;
23547           break;
23548         case V2SI_FTYPE_V2SF:
23549           type = v2si_ftype_v2sf;
23550           break;
23551         case V2DF_FTYPE_V4DF:
23552           type = v2df_ftype_v4df;
23553           break;
23554         case V2DF_FTYPE_V4SF:
23555           type = v2df_ftype_v4sf;
23556           break;
23557         case V2DF_FTYPE_V2DF:
23558         case V2DF_FTYPE_V2DF_VEC_MERGE:
23559           type = v2df_ftype_v2df;
23560           break;
23561         case V2DF_FTYPE_V2SI:
23562           type = v2df_ftype_v2si;
23563           break;
23564         case V2DF_FTYPE_V4SI:
23565           type = v2df_ftype_v4si;
23566           break;
23567         case V2SF_FTYPE_V2SF:
23568           type = v2sf_ftype_v2sf;
23569           break;
23570         case V2SF_FTYPE_V2SI:
23571           type = v2sf_ftype_v2si;
23572           break;
23573         case V16QI_FTYPE_V16QI_V16QI:
23574           type = v16qi_ftype_v16qi_v16qi;
23575           break;
23576         case V16QI_FTYPE_V8HI_V8HI:
23577           type = v16qi_ftype_v8hi_v8hi;
23578           break;
23579         case V8QI_FTYPE_V8QI_V8QI:
23580           type = v8qi_ftype_v8qi_v8qi;
23581           break;
23582         case V8QI_FTYPE_V4HI_V4HI:
23583           type = v8qi_ftype_v4hi_v4hi;
23584           break;
23585         case V8HI_FTYPE_V8HI_V8HI:
23586         case V8HI_FTYPE_V8HI_V8HI_COUNT:
23587           type = v8hi_ftype_v8hi_v8hi;
23588           break;
23589         case V8HI_FTYPE_V16QI_V16QI:
23590           type = v8hi_ftype_v16qi_v16qi;
23591           break;
23592         case V8HI_FTYPE_V4SI_V4SI:
23593           type = v8hi_ftype_v4si_v4si;
23594           break;
23595         case V8HI_FTYPE_V8HI_SI_COUNT:
23596           type = v8hi_ftype_v8hi_int;
23597           break;
23598         case V8SF_FTYPE_V8SF_V8SF:
23599           type = v8sf_ftype_v8sf_v8sf;
23600           break;
23601         case V8SF_FTYPE_V8SF_V8SI:
23602           type = v8sf_ftype_v8sf_v8si;
23603           break;
23604         case V4SI_FTYPE_V4SI_V4SI:
23605         case V4SI_FTYPE_V4SI_V4SI_COUNT:
23606           type = v4si_ftype_v4si_v4si;
23607           break;
23608         case V4SI_FTYPE_V8HI_V8HI:
23609           type = v4si_ftype_v8hi_v8hi;
23610           break;
23611         case V4SI_FTYPE_V4SF_V4SF:
23612           type = v4si_ftype_v4sf_v4sf;
23613           break;
23614         case V4SI_FTYPE_V2DF_V2DF:
23615           type = v4si_ftype_v2df_v2df;
23616           break;
23617         case V4SI_FTYPE_V4SI_SI_COUNT:
23618           type = v4si_ftype_v4si_int;
23619           break;
23620         case V4HI_FTYPE_V4HI_V4HI:
23621         case V4HI_FTYPE_V4HI_V4HI_COUNT:
23622           type = v4hi_ftype_v4hi_v4hi;
23623           break;
23624         case V4HI_FTYPE_V8QI_V8QI:
23625           type = v4hi_ftype_v8qi_v8qi;
23626           break;
23627         case V4HI_FTYPE_V2SI_V2SI:
23628           type = v4hi_ftype_v2si_v2si;
23629           break;
23630         case V4HI_FTYPE_V4HI_SI_COUNT:
23631           type = v4hi_ftype_v4hi_int;
23632           break;
23633         case V4DF_FTYPE_V4DF_V4DF:
23634           type = v4df_ftype_v4df_v4df;
23635           break;
23636         case V4DF_FTYPE_V4DF_V4DI:
23637           type = v4df_ftype_v4df_v4di;
23638           break;
23639         case V4SF_FTYPE_V4SF_V4SF:
23640         case V4SF_FTYPE_V4SF_V4SF_SWAP:
23641           type = v4sf_ftype_v4sf_v4sf;
23642           break;
23643         case V4SF_FTYPE_V4SF_V4SI:
23644           type = v4sf_ftype_v4sf_v4si;
23645           break;
23646         case V4SF_FTYPE_V4SF_V2SI:
23647           type = v4sf_ftype_v4sf_v2si;
23648           break;
23649         case V4SF_FTYPE_V4SF_V2DF:
23650           type = v4sf_ftype_v4sf_v2df;
23651           break;
23652         case V4SF_FTYPE_V4SF_DI:
23653           type = v4sf_ftype_v4sf_int64;
23654           break;
23655         case V4SF_FTYPE_V4SF_SI:
23656           type = v4sf_ftype_v4sf_int;
23657           break;
23658         case V2DI_FTYPE_V2DI_V2DI:
23659         case V2DI_FTYPE_V2DI_V2DI_COUNT:
23660           type = v2di_ftype_v2di_v2di;
23661           break;
23662         case V2DI_FTYPE_V16QI_V16QI:
23663           type = v2di_ftype_v16qi_v16qi;
23664           break;
23665         case V2DI_FTYPE_V4SI_V4SI:
23666           type = v2di_ftype_v4si_v4si;
23667           break;
23668         case V2DI_FTYPE_V2DI_V16QI:
23669           type = v2di_ftype_v2di_v16qi;
23670           break;
23671         case V2DI_FTYPE_V2DF_V2DF:
23672           type = v2di_ftype_v2df_v2df;
23673           break;
23674         case V2DI_FTYPE_V2DI_SI_COUNT:
23675           type = v2di_ftype_v2di_int;
23676           break;
23677         case V2SI_FTYPE_V2SI_V2SI:
23678         case V2SI_FTYPE_V2SI_V2SI_COUNT:
23679           type = v2si_ftype_v2si_v2si;
23680           break;
23681         case V2SI_FTYPE_V4HI_V4HI:
23682           type = v2si_ftype_v4hi_v4hi;
23683           break;
23684         case V2SI_FTYPE_V2SF_V2SF:
23685           type = v2si_ftype_v2sf_v2sf;
23686           break;
23687         case V2SI_FTYPE_V2SI_SI_COUNT:
23688           type = v2si_ftype_v2si_int;
23689           break;
23690         case V2DF_FTYPE_V2DF_V2DF:
23691         case V2DF_FTYPE_V2DF_V2DF_SWAP:
23692           type = v2df_ftype_v2df_v2df;
23693           break;
23694         case V2DF_FTYPE_V2DF_V4SF:
23695           type = v2df_ftype_v2df_v4sf;
23696           break;
23697         case V2DF_FTYPE_V2DF_V2DI:
23698           type = v2df_ftype_v2df_v2di;
23699           break;
23700         case V2DF_FTYPE_V2DF_DI:
23701           type = v2df_ftype_v2df_int64;
23702           break;
23703         case V2DF_FTYPE_V2DF_SI:
23704           type = v2df_ftype_v2df_int;
23705           break;
23706         case V2SF_FTYPE_V2SF_V2SF:
23707           type = v2sf_ftype_v2sf_v2sf;
23708           break;
23709         case V1DI_FTYPE_V1DI_V1DI:
23710         case V1DI_FTYPE_V1DI_V1DI_COUNT:
23711           type = v1di_ftype_v1di_v1di;
23712           break;
23713         case V1DI_FTYPE_V8QI_V8QI:
23714           type = v1di_ftype_v8qi_v8qi;
23715           break;
23716         case V1DI_FTYPE_V2SI_V2SI:
23717           type = v1di_ftype_v2si_v2si;
23718           break;
23719         case V1DI_FTYPE_V1DI_SI_COUNT:
23720           type = v1di_ftype_v1di_int;
23721           break;
23722         case UINT64_FTYPE_UINT64_UINT64:
23723           type = uint64_ftype_uint64_uint64;
23724           break;
23725         case UINT_FTYPE_UINT_UINT:
23726           type = unsigned_ftype_unsigned_unsigned;
23727           break;
23728         case UINT_FTYPE_UINT_USHORT:
23729           type = unsigned_ftype_unsigned_ushort;
23730           break;
23731         case UINT_FTYPE_UINT_UCHAR:
23732           type = unsigned_ftype_unsigned_uchar;
23733           break;
23734         case UINT16_FTYPE_UINT16_INT:
23735           type = ushort_ftype_ushort_int;
23736           break;
23737         case UINT8_FTYPE_UINT8_INT:
23738           type = uchar_ftype_uchar_int;
23739           break;
23740         case V8HI_FTYPE_V8HI_INT:
23741           type = v8hi_ftype_v8hi_int;
23742           break;
23743         case V8SF_FTYPE_V8SF_INT:
23744           type = v8sf_ftype_v8sf_int;
23745           break;
23746         case V4SI_FTYPE_V4SI_INT:
23747           type = v4si_ftype_v4si_int;
23748           break;
23749         case V4SI_FTYPE_V8SI_INT:
23750           type = v4si_ftype_v8si_int;
23751           break;
23752         case V4HI_FTYPE_V4HI_INT:
23753           type = v4hi_ftype_v4hi_int;
23754           break;
23755         case V4DF_FTYPE_V4DF_INT:
23756           type = v4df_ftype_v4df_int;
23757           break;
23758         case V4SF_FTYPE_V4SF_INT:
23759           type = v4sf_ftype_v4sf_int;
23760           break;
23761         case V4SF_FTYPE_V8SF_INT:
23762           type = v4sf_ftype_v8sf_int;
23763           break;
23764         case V2DI_FTYPE_V2DI_INT:
23765         case V2DI2TI_FTYPE_V2DI_INT:
23766           type = v2di_ftype_v2di_int;
23767           break;
23768         case V2DF_FTYPE_V2DF_INT:
23769           type = v2df_ftype_v2df_int;
23770           break;
23771         case V2DF_FTYPE_V4DF_INT:
23772           type = v2df_ftype_v4df_int;
23773           break;
23774         case V16QI_FTYPE_V16QI_V16QI_V16QI:
23775           type = v16qi_ftype_v16qi_v16qi_v16qi;
23776           break;
23777         case V8SF_FTYPE_V8SF_V8SF_V8SF:
23778           type = v8sf_ftype_v8sf_v8sf_v8sf;
23779           break;
23780         case V4DF_FTYPE_V4DF_V4DF_V4DF:
23781           type = v4df_ftype_v4df_v4df_v4df;
23782           break;
23783         case V4SF_FTYPE_V4SF_V4SF_V4SF:
23784           type = v4sf_ftype_v4sf_v4sf_v4sf;
23785           break;
23786         case V2DF_FTYPE_V2DF_V2DF_V2DF:
23787           type = v2df_ftype_v2df_v2df_v2df;
23788           break;
23789         case V16QI_FTYPE_V16QI_V16QI_INT:
23790           type = v16qi_ftype_v16qi_v16qi_int;
23791           break;
23792         case V8SI_FTYPE_V8SI_V8SI_INT:
23793           type = v8si_ftype_v8si_v8si_int;
23794           break;
23795         case V8SI_FTYPE_V8SI_V4SI_INT:
23796           type = v8si_ftype_v8si_v4si_int;
23797           break;
23798         case V8HI_FTYPE_V8HI_V8HI_INT:
23799           type = v8hi_ftype_v8hi_v8hi_int;
23800           break;
23801         case V8SF_FTYPE_V8SF_V8SF_INT:
23802           type = v8sf_ftype_v8sf_v8sf_int;
23803           break;
23804         case V8SF_FTYPE_V8SF_V4SF_INT:
23805           type = v8sf_ftype_v8sf_v4sf_int;
23806           break;
23807         case V4SI_FTYPE_V4SI_V4SI_INT:
23808           type = v4si_ftype_v4si_v4si_int;
23809           break;
23810         case V4DF_FTYPE_V4DF_V4DF_INT:
23811           type = v4df_ftype_v4df_v4df_int;
23812           break;
23813         case V4DF_FTYPE_V4DF_V2DF_INT:
23814           type = v4df_ftype_v4df_v2df_int;
23815           break;
23816         case V4SF_FTYPE_V4SF_V4SF_INT:
23817           type = v4sf_ftype_v4sf_v4sf_int;
23818           break;
23819         case V2DI_FTYPE_V2DI_V2DI_INT:
23820         case V2DI2TI_FTYPE_V2DI_V2DI_INT:
23821           type = v2di_ftype_v2di_v2di_int;
23822           break;
23823         case V2DF_FTYPE_V2DF_V2DF_INT:
23824           type = v2df_ftype_v2df_v2df_int;
23825           break;
23826         case V2DI_FTYPE_V2DI_UINT_UINT:
23827           type = v2di_ftype_v2di_unsigned_unsigned;
23828           break;
23829         case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
23830           type = v2di_ftype_v2di_v2di_unsigned_unsigned;
23831           break;
23832         case V1DI2DI_FTYPE_V1DI_V1DI_INT:
23833           type = v1di_ftype_v1di_v1di_int;
23834           break;
23835         default:
23836           gcc_unreachable ();
23837         }
23838
23839       def_builtin_const (d->mask, d->name, type, d->code);
23840     }
23841
23842   /* pcmpestr[im] insns.  */
23843   for (i = 0, d = bdesc_pcmpestr;
23844        i < ARRAY_SIZE (bdesc_pcmpestr);
23845        i++, d++)
23846     {
23847       if (d->code == IX86_BUILTIN_PCMPESTRM128)
23848         ftype = v16qi_ftype_v16qi_int_v16qi_int_int;
23849       else
23850         ftype = int_ftype_v16qi_int_v16qi_int_int;
23851       def_builtin_const (d->mask, d->name, ftype, d->code);
23852     }
23853
23854   /* pcmpistr[im] insns.  */
23855   for (i = 0, d = bdesc_pcmpistr;
23856        i < ARRAY_SIZE (bdesc_pcmpistr);
23857        i++, d++)
23858     {
23859       if (d->code == IX86_BUILTIN_PCMPISTRM128)
23860         ftype = v16qi_ftype_v16qi_v16qi_int;
23861       else
23862         ftype = int_ftype_v16qi_v16qi_int;
23863       def_builtin_const (d->mask, d->name, ftype, d->code);
23864     }
23865
23866   /* comi/ucomi insns.  */
23867   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
23868     if (d->mask == OPTION_MASK_ISA_SSE2)
23869       def_builtin_const (d->mask, d->name, int_ftype_v2df_v2df, d->code);
23870     else
23871       def_builtin_const (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
23872
23873   /* SSE */
23874   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr", void_ftype_unsigned, IX86_BUILTIN_LDMXCSR);
23875   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr", unsigned_ftype_void, IX86_BUILTIN_STMXCSR);
23876
23877   /* SSE or 3DNow!A */
23878   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_maskmovq", void_ftype_v8qi_v8qi_pchar, IX86_BUILTIN_MASKMOVQ);
23879
23880   /* SSE2 */
23881   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu", void_ftype_v16qi_v16qi_pchar, IX86_BUILTIN_MASKMOVDQU);
23882
23883   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush", void_ftype_pcvoid, IX86_BUILTIN_CLFLUSH);
23884   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence", void_ftype_void, IX86_BUILTIN_MFENCE);
23885
23886   /* SSE3.  */
23887   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor", void_ftype_pcvoid_unsigned_unsigned, IX86_BUILTIN_MONITOR);
23888   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait", void_ftype_unsigned_unsigned, IX86_BUILTIN_MWAIT);
23889
23890   /* AES */
23891   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENC128);
23892   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENCLAST128);
23893   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDEC128);
23894   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDECLAST128);
23895   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128", v2di_ftype_v2di, IX86_BUILTIN_AESIMC128);
23896   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128", v2di_ftype_v2di_int, IX86_BUILTIN_AESKEYGENASSIST128);
23897
23898   /* PCLMUL */
23899   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128", v2di_ftype_v2di_v2di_int, IX86_BUILTIN_PCLMULQDQ128);
23900
23901   /* AVX */
23902   def_builtin (OPTION_MASK_ISA_AVX, "__builtin_ia32_vzeroupper", void_ftype_void,
23903                TARGET_64BIT ? IX86_BUILTIN_VZEROUPPER_REX64 : IX86_BUILTIN_VZEROUPPER);
23904
23905   /* Access to the vec_init patterns.  */
23906   ftype = build_function_type_list (V2SI_type_node, integer_type_node,
23907                                     integer_type_node, NULL_TREE);
23908   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si", ftype, IX86_BUILTIN_VEC_INIT_V2SI);
23909
23910   ftype = build_function_type_list (V4HI_type_node, short_integer_type_node,
23911                                     short_integer_type_node,
23912                                     short_integer_type_node,
23913                                     short_integer_type_node, NULL_TREE);
23914   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi", ftype, IX86_BUILTIN_VEC_INIT_V4HI);
23915
23916   ftype = build_function_type_list (V8QI_type_node, char_type_node,
23917                                     char_type_node, char_type_node,
23918                                     char_type_node, char_type_node,
23919                                     char_type_node, char_type_node,
23920                                     char_type_node, NULL_TREE);
23921   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi", ftype, IX86_BUILTIN_VEC_INIT_V8QI);
23922
23923   /* Access to the vec_extract patterns.  */
23924   ftype = build_function_type_list (double_type_node, V2DF_type_node,
23925                                     integer_type_node, NULL_TREE);
23926   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df", ftype, IX86_BUILTIN_VEC_EXT_V2DF);
23927
23928   ftype = build_function_type_list (long_long_integer_type_node,
23929                                     V2DI_type_node, integer_type_node,
23930                                     NULL_TREE);
23931   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di", ftype, IX86_BUILTIN_VEC_EXT_V2DI);
23932
23933   ftype = build_function_type_list (float_type_node, V4SF_type_node,
23934                                     integer_type_node, NULL_TREE);
23935   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf", ftype, IX86_BUILTIN_VEC_EXT_V4SF);
23936
23937   ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
23938                                     integer_type_node, NULL_TREE);
23939   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si", ftype, IX86_BUILTIN_VEC_EXT_V4SI);
23940
23941   ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
23942                                     integer_type_node, NULL_TREE);
23943   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi", ftype, IX86_BUILTIN_VEC_EXT_V8HI);
23944
23945   ftype = build_function_type_list (intHI_type_node, V4HI_type_node,
23946                                     integer_type_node, NULL_TREE);
23947   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_ext_v4hi", ftype, IX86_BUILTIN_VEC_EXT_V4HI);
23948
23949   ftype = build_function_type_list (intSI_type_node, V2SI_type_node,
23950                                     integer_type_node, NULL_TREE);
23951   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si", ftype, IX86_BUILTIN_VEC_EXT_V2SI);
23952
23953   ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
23954                                     integer_type_node, NULL_TREE);
23955   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi", ftype, IX86_BUILTIN_VEC_EXT_V16QI);
23956
23957   /* Access to the vec_set patterns.  */
23958   ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
23959                                     intDI_type_node,
23960                                     integer_type_node, NULL_TREE);
23961   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_vec_set_v2di", ftype, IX86_BUILTIN_VEC_SET_V2DI);
23962
23963   ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
23964                                     float_type_node,
23965                                     integer_type_node, NULL_TREE);
23966   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf", ftype, IX86_BUILTIN_VEC_SET_V4SF);
23967
23968   ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
23969                                     intSI_type_node,
23970                                     integer_type_node, NULL_TREE);
23971   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si", ftype, IX86_BUILTIN_VEC_SET_V4SI);
23972
23973   ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
23974                                     intHI_type_node,
23975                                     integer_type_node, NULL_TREE);
23976   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi", ftype, IX86_BUILTIN_VEC_SET_V8HI);
23977
23978   ftype = build_function_type_list (V4HI_type_node, V4HI_type_node,
23979                                     intHI_type_node,
23980                                     integer_type_node, NULL_TREE);
23981   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_set_v4hi", ftype, IX86_BUILTIN_VEC_SET_V4HI);
23982
23983   ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
23984                                     intQI_type_node,
23985                                     integer_type_node, NULL_TREE);
23986   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi", ftype, IX86_BUILTIN_VEC_SET_V16QI);
23987
23988   /* Add SSE5 multi-arg argument instructions */
23989   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
23990     {
23991       tree mtype = NULL_TREE;
23992
23993       if (d->name == 0)
23994         continue;
23995
23996       switch ((enum multi_arg_type)d->flag)
23997         {
23998         case MULTI_ARG_3_SF:     mtype = v4sf_ftype_v4sf_v4sf_v4sf;     break;
23999         case MULTI_ARG_3_DF:     mtype = v2df_ftype_v2df_v2df_v2df;     break;
24000         case MULTI_ARG_3_DI:     mtype = v2di_ftype_v2di_v2di_v2di;     break;
24001         case MULTI_ARG_3_SI:     mtype = v4si_ftype_v4si_v4si_v4si;     break;
24002         case MULTI_ARG_3_SI_DI:  mtype = v4si_ftype_v4si_v4si_v2di;     break;
24003         case MULTI_ARG_3_HI:     mtype = v8hi_ftype_v8hi_v8hi_v8hi;     break;
24004         case MULTI_ARG_3_HI_SI:  mtype = v8hi_ftype_v8hi_v8hi_v4si;     break;
24005         case MULTI_ARG_3_QI:     mtype = v16qi_ftype_v16qi_v16qi_v16qi; break;
24006         case MULTI_ARG_3_PERMPS: mtype = v4sf_ftype_v4sf_v4sf_v16qi;    break;
24007         case MULTI_ARG_3_PERMPD: mtype = v2df_ftype_v2df_v2df_v16qi;    break;
24008         case MULTI_ARG_2_SF:     mtype = v4sf_ftype_v4sf_v4sf;          break;
24009         case MULTI_ARG_2_DF:     mtype = v2df_ftype_v2df_v2df;          break;
24010         case MULTI_ARG_2_DI:     mtype = v2di_ftype_v2di_v2di;          break;
24011         case MULTI_ARG_2_SI:     mtype = v4si_ftype_v4si_v4si;          break;
24012         case MULTI_ARG_2_HI:     mtype = v8hi_ftype_v8hi_v8hi;          break;
24013         case MULTI_ARG_2_QI:     mtype = v16qi_ftype_v16qi_v16qi;       break;
24014         case MULTI_ARG_2_DI_IMM: mtype = v2di_ftype_v2di_si;            break;
24015         case MULTI_ARG_2_SI_IMM: mtype = v4si_ftype_v4si_si;            break;
24016         case MULTI_ARG_2_HI_IMM: mtype = v8hi_ftype_v8hi_si;            break;
24017         case MULTI_ARG_2_QI_IMM: mtype = v16qi_ftype_v16qi_si;          break;
24018         case MULTI_ARG_2_SF_CMP: mtype = v4sf_ftype_v4sf_v4sf;          break;
24019         case MULTI_ARG_2_DF_CMP: mtype = v2df_ftype_v2df_v2df;          break;
24020         case MULTI_ARG_2_DI_CMP: mtype = v2di_ftype_v2di_v2di;          break;
24021         case MULTI_ARG_2_SI_CMP: mtype = v4si_ftype_v4si_v4si;          break;
24022         case MULTI_ARG_2_HI_CMP: mtype = v8hi_ftype_v8hi_v8hi;          break;
24023         case MULTI_ARG_2_QI_CMP: mtype = v16qi_ftype_v16qi_v16qi;       break;
24024         case MULTI_ARG_2_SF_TF:  mtype = v4sf_ftype_v4sf_v4sf;          break;
24025         case MULTI_ARG_2_DF_TF:  mtype = v2df_ftype_v2df_v2df;          break;
24026         case MULTI_ARG_2_DI_TF:  mtype = v2di_ftype_v2di_v2di;          break;
24027         case MULTI_ARG_2_SI_TF:  mtype = v4si_ftype_v4si_v4si;          break;
24028         case MULTI_ARG_2_HI_TF:  mtype = v8hi_ftype_v8hi_v8hi;          break;
24029         case MULTI_ARG_2_QI_TF:  mtype = v16qi_ftype_v16qi_v16qi;       break;
24030         case MULTI_ARG_1_SF:     mtype = v4sf_ftype_v4sf;               break;
24031         case MULTI_ARG_1_DF:     mtype = v2df_ftype_v2df;               break;
24032         case MULTI_ARG_1_DI:     mtype = v2di_ftype_v2di;               break;
24033         case MULTI_ARG_1_SI:     mtype = v4si_ftype_v4si;               break;
24034         case MULTI_ARG_1_HI:     mtype = v8hi_ftype_v8hi;               break;
24035         case MULTI_ARG_1_QI:     mtype = v16qi_ftype_v16qi;             break;
24036         case MULTI_ARG_1_SI_DI:  mtype = v2di_ftype_v4si;               break;
24037         case MULTI_ARG_1_HI_DI:  mtype = v2di_ftype_v8hi;               break;
24038         case MULTI_ARG_1_HI_SI:  mtype = v4si_ftype_v8hi;               break;
24039         case MULTI_ARG_1_QI_DI:  mtype = v2di_ftype_v16qi;              break;
24040         case MULTI_ARG_1_QI_SI:  mtype = v4si_ftype_v16qi;              break;
24041         case MULTI_ARG_1_QI_HI:  mtype = v8hi_ftype_v16qi;              break;
24042         case MULTI_ARG_1_PH2PS:  mtype = v4sf_ftype_v4hi;               break;
24043         case MULTI_ARG_1_PS2PH:  mtype = v4hi_ftype_v4sf;               break;
24044         case MULTI_ARG_UNKNOWN:
24045         default:
24046           gcc_unreachable ();
24047         }
24048
24049       if (mtype)
24050         def_builtin_const (d->mask, d->name, mtype, d->code);
24051     }
24052 }
24053
24054 /* Internal method for ix86_init_builtins.  */
24055
24056 static void
24057 ix86_init_builtins_va_builtins_abi (void)
24058 {
24059   tree ms_va_ref, sysv_va_ref;
24060   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
24061   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
24062   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
24063   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
24064
24065   if (!TARGET_64BIT)
24066     return;
24067   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
24068   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
24069   ms_va_ref = build_reference_type (ms_va_list_type_node);
24070   sysv_va_ref =
24071     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
24072
24073   fnvoid_va_end_ms =
24074     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
24075   fnvoid_va_start_ms =
24076     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
24077   fnvoid_va_end_sysv =
24078     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
24079   fnvoid_va_start_sysv =
24080     build_varargs_function_type_list (void_type_node, sysv_va_ref,
24081                                        NULL_TREE);
24082   fnvoid_va_copy_ms =
24083     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
24084                               NULL_TREE);
24085   fnvoid_va_copy_sysv =
24086     build_function_type_list (void_type_node, sysv_va_ref,
24087                               sysv_va_ref, NULL_TREE);
24088
24089   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
24090                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
24091   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
24092                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
24093   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
24094                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
24095   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
24096                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
24097   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
24098                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
24099   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
24100                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
24101 }
24102
24103 static void
24104 ix86_init_builtins (void)
24105 {
24106   tree float128_type_node = make_node (REAL_TYPE);
24107   tree ftype, decl;
24108
24109   /* The __float80 type.  */
24110   if (TYPE_MODE (long_double_type_node) == XFmode)
24111     (*lang_hooks.types.register_builtin_type) (long_double_type_node,
24112                                                "__float80");
24113   else
24114     {
24115       /* The __float80 type.  */
24116       tree float80_type_node = make_node (REAL_TYPE);
24117
24118       TYPE_PRECISION (float80_type_node) = 80;
24119       layout_type (float80_type_node);
24120       (*lang_hooks.types.register_builtin_type) (float80_type_node,
24121                                                  "__float80");
24122     }
24123
24124   /* The __float128 type.  */
24125   TYPE_PRECISION (float128_type_node) = 128;
24126   layout_type (float128_type_node);
24127   (*lang_hooks.types.register_builtin_type) (float128_type_node,
24128                                              "__float128");
24129
24130   /* TFmode support builtins.  */
24131   ftype = build_function_type (float128_type_node, void_list_node);
24132   decl = add_builtin_function ("__builtin_infq", ftype,
24133                                IX86_BUILTIN_INFQ, BUILT_IN_MD,
24134                                NULL, NULL_TREE);
24135   ix86_builtins[(int) IX86_BUILTIN_INFQ] = decl;
24136
24137   decl = add_builtin_function ("__builtin_huge_valq", ftype,
24138                                IX86_BUILTIN_HUGE_VALQ, BUILT_IN_MD,
24139                                NULL, NULL_TREE);
24140   ix86_builtins[(int) IX86_BUILTIN_HUGE_VALQ] = decl;
24141
24142   /* We will expand them to normal call if SSE2 isn't available since
24143      they are used by libgcc. */
24144   ftype = build_function_type_list (float128_type_node,
24145                                     float128_type_node,
24146                                     NULL_TREE);
24147   decl = add_builtin_function ("__builtin_fabsq", ftype,
24148                                IX86_BUILTIN_FABSQ, BUILT_IN_MD,
24149                                "__fabstf2", NULL_TREE);
24150   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = decl;
24151   TREE_READONLY (decl) = 1;
24152
24153   ftype = build_function_type_list (float128_type_node,
24154                                     float128_type_node,
24155                                     float128_type_node,
24156                                     NULL_TREE);
24157   decl = add_builtin_function ("__builtin_copysignq", ftype,
24158                                IX86_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
24159                                "__copysigntf3", NULL_TREE);
24160   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = decl;
24161   TREE_READONLY (decl) = 1;
24162
24163   ix86_init_mmx_sse_builtins ();
24164   if (TARGET_64BIT)
24165     ix86_init_builtins_va_builtins_abi ();
24166 }
24167
24168 /* Errors in the source file can cause expand_expr to return const0_rtx
24169    where we expect a vector.  To avoid crashing, use one of the vector
24170    clear instructions.  */
24171 static rtx
24172 safe_vector_operand (rtx x, enum machine_mode mode)
24173 {
24174   if (x == const0_rtx)
24175     x = CONST0_RTX (mode);
24176   return x;
24177 }
24178
24179 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
24180
24181 static rtx
24182 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
24183 {
24184   rtx pat;
24185   tree arg0 = CALL_EXPR_ARG (exp, 0);
24186   tree arg1 = CALL_EXPR_ARG (exp, 1);
24187   rtx op0 = expand_normal (arg0);
24188   rtx op1 = expand_normal (arg1);
24189   enum machine_mode tmode = insn_data[icode].operand[0].mode;
24190   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
24191   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
24192
24193   if (VECTOR_MODE_P (mode0))
24194     op0 = safe_vector_operand (op0, mode0);
24195   if (VECTOR_MODE_P (mode1))
24196     op1 = safe_vector_operand (op1, mode1);
24197
24198   if (optimize || !target
24199       || GET_MODE (target) != tmode
24200       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
24201     target = gen_reg_rtx (tmode);
24202
24203   if (GET_MODE (op1) == SImode && mode1 == TImode)
24204     {
24205       rtx x = gen_reg_rtx (V4SImode);
24206       emit_insn (gen_sse2_loadd (x, op1));
24207       op1 = gen_lowpart (TImode, x);
24208     }
24209
24210   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
24211     op0 = copy_to_mode_reg (mode0, op0);
24212   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
24213     op1 = copy_to_mode_reg (mode1, op1);
24214
24215   pat = GEN_FCN (icode) (target, op0, op1);
24216   if (! pat)
24217     return 0;
24218
24219   emit_insn (pat);
24220
24221   return target;
24222 }
24223
24224 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
24225
24226 static rtx
24227 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
24228                                enum multi_arg_type m_type,
24229                                enum rtx_code sub_code)
24230 {
24231   rtx pat;
24232   int i;
24233   int nargs;
24234   bool comparison_p = false;
24235   bool tf_p = false;
24236   bool last_arg_constant = false;
24237   int num_memory = 0;
24238   struct {
24239     rtx op;
24240     enum machine_mode mode;
24241   } args[4];
24242
24243   enum machine_mode tmode = insn_data[icode].operand[0].mode;
24244
24245   switch (m_type)
24246     {
24247     case MULTI_ARG_3_SF:
24248     case MULTI_ARG_3_DF:
24249     case MULTI_ARG_3_DI:
24250     case MULTI_ARG_3_SI:
24251     case MULTI_ARG_3_SI_DI:
24252     case MULTI_ARG_3_HI:
24253     case MULTI_ARG_3_HI_SI:
24254     case MULTI_ARG_3_QI:
24255     case MULTI_ARG_3_PERMPS:
24256     case MULTI_ARG_3_PERMPD:
24257       nargs = 3;
24258       break;
24259
24260     case MULTI_ARG_2_SF:
24261     case MULTI_ARG_2_DF:
24262     case MULTI_ARG_2_DI:
24263     case MULTI_ARG_2_SI:
24264     case MULTI_ARG_2_HI:
24265     case MULTI_ARG_2_QI:
24266       nargs = 2;
24267       break;
24268
24269     case MULTI_ARG_2_DI_IMM:
24270     case MULTI_ARG_2_SI_IMM:
24271     case MULTI_ARG_2_HI_IMM:
24272     case MULTI_ARG_2_QI_IMM:
24273       nargs = 2;
24274       last_arg_constant = true;
24275       break;
24276
24277     case MULTI_ARG_1_SF:
24278     case MULTI_ARG_1_DF:
24279     case MULTI_ARG_1_DI:
24280     case MULTI_ARG_1_SI:
24281     case MULTI_ARG_1_HI:
24282     case MULTI_ARG_1_QI:
24283     case MULTI_ARG_1_SI_DI:
24284     case MULTI_ARG_1_HI_DI:
24285     case MULTI_ARG_1_HI_SI:
24286     case MULTI_ARG_1_QI_DI:
24287     case MULTI_ARG_1_QI_SI:
24288     case MULTI_ARG_1_QI_HI:
24289     case MULTI_ARG_1_PH2PS:
24290     case MULTI_ARG_1_PS2PH:
24291       nargs = 1;
24292       break;
24293
24294     case MULTI_ARG_2_SF_CMP:
24295     case MULTI_ARG_2_DF_CMP:
24296     case MULTI_ARG_2_DI_CMP:
24297     case MULTI_ARG_2_SI_CMP:
24298     case MULTI_ARG_2_HI_CMP:
24299     case MULTI_ARG_2_QI_CMP:
24300       nargs = 2;
24301       comparison_p = true;
24302       break;
24303
24304     case MULTI_ARG_2_SF_TF:
24305     case MULTI_ARG_2_DF_TF:
24306     case MULTI_ARG_2_DI_TF:
24307     case MULTI_ARG_2_SI_TF:
24308     case MULTI_ARG_2_HI_TF:
24309     case MULTI_ARG_2_QI_TF:
24310       nargs = 2;
24311       tf_p = true;
24312       break;
24313
24314     case MULTI_ARG_UNKNOWN:
24315     default:
24316       gcc_unreachable ();
24317     }
24318
24319   if (optimize || !target
24320       || GET_MODE (target) != tmode
24321       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
24322     target = gen_reg_rtx (tmode);
24323
24324   gcc_assert (nargs <= 4);
24325
24326   for (i = 0; i < nargs; i++)
24327     {
24328       tree arg = CALL_EXPR_ARG (exp, i);
24329       rtx op = expand_normal (arg);
24330       int adjust = (comparison_p) ? 1 : 0;
24331       enum machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
24332
24333       if (last_arg_constant && i == nargs-1)
24334         {
24335           if (!CONST_INT_P (op))
24336             {
24337               error ("last argument must be an immediate");
24338               return gen_reg_rtx (tmode);
24339             }
24340         }
24341       else
24342         {
24343           if (VECTOR_MODE_P (mode))
24344             op = safe_vector_operand (op, mode);
24345
24346           /* If we aren't optimizing, only allow one memory operand to be
24347              generated.  */
24348           if (memory_operand (op, mode))
24349             num_memory++;
24350
24351           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
24352
24353           if (optimize
24354               || ! (*insn_data[icode].operand[i+adjust+1].predicate) (op, mode)
24355               || num_memory > 1)
24356             op = force_reg (mode, op);
24357         }
24358
24359       args[i].op = op;
24360       args[i].mode = mode;
24361     }
24362
24363   switch (nargs)
24364     {
24365     case 1:
24366       pat = GEN_FCN (icode) (target, args[0].op);
24367       break;
24368
24369     case 2:
24370       if (tf_p)
24371         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
24372                                GEN_INT ((int)sub_code));
24373       else if (! comparison_p)
24374         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
24375       else
24376         {
24377           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
24378                                        args[0].op,
24379                                        args[1].op);
24380
24381           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
24382         }
24383       break;
24384
24385     case 3:
24386       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
24387       break;
24388
24389     default:
24390       gcc_unreachable ();
24391     }
24392
24393   if (! pat)
24394     return 0;
24395
24396   emit_insn (pat);
24397   return target;
24398 }
24399
24400 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
24401    insns with vec_merge.  */
24402
24403 static rtx
24404 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
24405                                     rtx target)
24406 {
24407   rtx pat;
24408   tree arg0 = CALL_EXPR_ARG (exp, 0);
24409   rtx op1, op0 = expand_normal (arg0);
24410   enum machine_mode tmode = insn_data[icode].operand[0].mode;
24411   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
24412
24413   if (optimize || !target
24414       || GET_MODE (target) != tmode
24415       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
24416     target = gen_reg_rtx (tmode);
24417
24418   if (VECTOR_MODE_P (mode0))
24419     op0 = safe_vector_operand (op0, mode0);
24420
24421   if ((optimize && !register_operand (op0, mode0))
24422       || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
24423     op0 = copy_to_mode_reg (mode0, op0);
24424
24425   op1 = op0;
24426   if (! (*insn_data[icode].operand[2].predicate) (op1, mode0))
24427     op1 = copy_to_mode_reg (mode0, op1);
24428
24429   pat = GEN_FCN (icode) (target, op0, op1);
24430   if (! pat)
24431     return 0;
24432   emit_insn (pat);
24433   return target;
24434 }
24435
24436 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
24437
24438 static rtx
24439 ix86_expand_sse_compare (const struct builtin_description *d,
24440                          tree exp, rtx target, bool swap)
24441 {
24442   rtx pat;
24443   tree arg0 = CALL_EXPR_ARG (exp, 0);
24444   tree arg1 = CALL_EXPR_ARG (exp, 1);
24445   rtx op0 = expand_normal (arg0);
24446   rtx op1 = expand_normal (arg1);
24447   rtx op2;
24448   enum machine_mode tmode = insn_data[d->icode].operand[0].mode;
24449   enum machine_mode mode0 = insn_data[d->icode].operand[1].mode;
24450   enum machine_mode mode1 = insn_data[d->icode].operand[2].mode;
24451   enum rtx_code comparison = d->comparison;
24452
24453   if (VECTOR_MODE_P (mode0))
24454     op0 = safe_vector_operand (op0, mode0);
24455   if (VECTOR_MODE_P (mode1))
24456     op1 = safe_vector_operand (op1, mode1);
24457
24458   /* Swap operands if we have a comparison that isn't available in
24459      hardware.  */
24460   if (swap)
24461     {
24462       rtx tmp = gen_reg_rtx (mode1);
24463       emit_move_insn (tmp, op1);
24464       op1 = op0;
24465       op0 = tmp;
24466     }
24467
24468   if (optimize || !target
24469       || GET_MODE (target) != tmode
24470       || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode))
24471     target = gen_reg_rtx (tmode);
24472
24473   if ((optimize && !register_operand (op0, mode0))
24474       || ! (*insn_data[d->icode].operand[1].predicate) (op0, mode0))
24475     op0 = copy_to_mode_reg (mode0, op0);
24476   if ((optimize && !register_operand (op1, mode1))
24477       || ! (*insn_data[d->icode].operand[2].predicate) (op1, mode1))
24478     op1 = copy_to_mode_reg (mode1, op1);
24479
24480   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
24481   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
24482   if (! pat)
24483     return 0;
24484   emit_insn (pat);
24485   return target;
24486 }
24487
24488 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
24489
24490 static rtx
24491 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
24492                       rtx target)
24493 {
24494   rtx pat;
24495   tree arg0 = CALL_EXPR_ARG (exp, 0);
24496   tree arg1 = CALL_EXPR_ARG (exp, 1);
24497   rtx op0 = expand_normal (arg0);
24498   rtx op1 = expand_normal (arg1);
24499   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
24500   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
24501   enum rtx_code comparison = d->comparison;
24502
24503   if (VECTOR_MODE_P (mode0))
24504     op0 = safe_vector_operand (op0, mode0);
24505   if (VECTOR_MODE_P (mode1))
24506     op1 = safe_vector_operand (op1, mode1);
24507
24508   /* Swap operands if we have a comparison that isn't available in
24509      hardware.  */
24510   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
24511     {
24512       rtx tmp = op1;
24513       op1 = op0;
24514       op0 = tmp;
24515     }
24516
24517   target = gen_reg_rtx (SImode);
24518   emit_move_insn (target, const0_rtx);
24519   target = gen_rtx_SUBREG (QImode, target, 0);
24520
24521   if ((optimize && !register_operand (op0, mode0))
24522       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
24523     op0 = copy_to_mode_reg (mode0, op0);
24524   if ((optimize && !register_operand (op1, mode1))
24525       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
24526     op1 = copy_to_mode_reg (mode1, op1);
24527
24528   pat = GEN_FCN (d->icode) (op0, op1);
24529   if (! pat)
24530     return 0;
24531   emit_insn (pat);
24532   emit_insn (gen_rtx_SET (VOIDmode,
24533                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
24534                           gen_rtx_fmt_ee (comparison, QImode,
24535                                           SET_DEST (pat),
24536                                           const0_rtx)));
24537
24538   return SUBREG_REG (target);
24539 }
24540
24541 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
24542
24543 static rtx
24544 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
24545                        rtx target)
24546 {
24547   rtx pat;
24548   tree arg0 = CALL_EXPR_ARG (exp, 0);
24549   tree arg1 = CALL_EXPR_ARG (exp, 1);
24550   rtx op0 = expand_normal (arg0);
24551   rtx op1 = expand_normal (arg1);
24552   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
24553   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
24554   enum rtx_code comparison = d->comparison;
24555
24556   if (VECTOR_MODE_P (mode0))
24557     op0 = safe_vector_operand (op0, mode0);
24558   if (VECTOR_MODE_P (mode1))
24559     op1 = safe_vector_operand (op1, mode1);
24560
24561   target = gen_reg_rtx (SImode);
24562   emit_move_insn (target, const0_rtx);
24563   target = gen_rtx_SUBREG (QImode, target, 0);
24564
24565   if ((optimize && !register_operand (op0, mode0))
24566       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
24567     op0 = copy_to_mode_reg (mode0, op0);
24568   if ((optimize && !register_operand (op1, mode1))
24569       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
24570     op1 = copy_to_mode_reg (mode1, op1);
24571
24572   pat = GEN_FCN (d->icode) (op0, op1);
24573   if (! pat)
24574     return 0;
24575   emit_insn (pat);
24576   emit_insn (gen_rtx_SET (VOIDmode,
24577                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
24578                           gen_rtx_fmt_ee (comparison, QImode,
24579                                           SET_DEST (pat),
24580                                           const0_rtx)));
24581
24582   return SUBREG_REG (target);
24583 }
24584
24585 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
24586
24587 static rtx
24588 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
24589                           tree exp, rtx target)
24590 {
24591   rtx pat;
24592   tree arg0 = CALL_EXPR_ARG (exp, 0);
24593   tree arg1 = CALL_EXPR_ARG (exp, 1);
24594   tree arg2 = CALL_EXPR_ARG (exp, 2);
24595   tree arg3 = CALL_EXPR_ARG (exp, 3);
24596   tree arg4 = CALL_EXPR_ARG (exp, 4);
24597   rtx scratch0, scratch1;
24598   rtx op0 = expand_normal (arg0);
24599   rtx op1 = expand_normal (arg1);
24600   rtx op2 = expand_normal (arg2);
24601   rtx op3 = expand_normal (arg3);
24602   rtx op4 = expand_normal (arg4);
24603   enum machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
24604
24605   tmode0 = insn_data[d->icode].operand[0].mode;
24606   tmode1 = insn_data[d->icode].operand[1].mode;
24607   modev2 = insn_data[d->icode].operand[2].mode;
24608   modei3 = insn_data[d->icode].operand[3].mode;
24609   modev4 = insn_data[d->icode].operand[4].mode;
24610   modei5 = insn_data[d->icode].operand[5].mode;
24611   modeimm = insn_data[d->icode].operand[6].mode;
24612
24613   if (VECTOR_MODE_P (modev2))
24614     op0 = safe_vector_operand (op0, modev2);
24615   if (VECTOR_MODE_P (modev4))
24616     op2 = safe_vector_operand (op2, modev4);
24617
24618   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
24619     op0 = copy_to_mode_reg (modev2, op0);
24620   if (! (*insn_data[d->icode].operand[3].predicate) (op1, modei3))
24621     op1 = copy_to_mode_reg (modei3, op1);
24622   if ((optimize && !register_operand (op2, modev4))
24623       || !(*insn_data[d->icode].operand[4].predicate) (op2, modev4))
24624     op2 = copy_to_mode_reg (modev4, op2);
24625   if (! (*insn_data[d->icode].operand[5].predicate) (op3, modei5))
24626     op3 = copy_to_mode_reg (modei5, op3);
24627
24628   if (! (*insn_data[d->icode].operand[6].predicate) (op4, modeimm))
24629     {
24630       error ("the fifth argument must be a 8-bit immediate");
24631       return const0_rtx;
24632     }
24633
24634   if (d->code == IX86_BUILTIN_PCMPESTRI128)
24635     {
24636       if (optimize || !target
24637           || GET_MODE (target) != tmode0
24638           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
24639         target = gen_reg_rtx (tmode0);
24640
24641       scratch1 = gen_reg_rtx (tmode1);
24642
24643       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
24644     }
24645   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
24646     {
24647       if (optimize || !target
24648           || GET_MODE (target) != tmode1
24649           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
24650         target = gen_reg_rtx (tmode1);
24651
24652       scratch0 = gen_reg_rtx (tmode0);
24653
24654       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
24655     }
24656   else
24657     {
24658       gcc_assert (d->flag);
24659
24660       scratch0 = gen_reg_rtx (tmode0);
24661       scratch1 = gen_reg_rtx (tmode1);
24662
24663       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
24664     }
24665
24666   if (! pat)
24667     return 0;
24668
24669   emit_insn (pat);
24670
24671   if (d->flag)
24672     {
24673       target = gen_reg_rtx (SImode);
24674       emit_move_insn (target, const0_rtx);
24675       target = gen_rtx_SUBREG (QImode, target, 0);
24676
24677       emit_insn
24678         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
24679                       gen_rtx_fmt_ee (EQ, QImode,
24680                                       gen_rtx_REG ((enum machine_mode) d->flag,
24681                                                    FLAGS_REG),
24682                                       const0_rtx)));
24683       return SUBREG_REG (target);
24684     }
24685   else
24686     return target;
24687 }
24688
24689
24690 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
24691
24692 static rtx
24693 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
24694                           tree exp, rtx target)
24695 {
24696   rtx pat;
24697   tree arg0 = CALL_EXPR_ARG (exp, 0);
24698   tree arg1 = CALL_EXPR_ARG (exp, 1);
24699   tree arg2 = CALL_EXPR_ARG (exp, 2);
24700   rtx scratch0, scratch1;
24701   rtx op0 = expand_normal (arg0);
24702   rtx op1 = expand_normal (arg1);
24703   rtx op2 = expand_normal (arg2);
24704   enum machine_mode tmode0, tmode1, modev2, modev3, modeimm;
24705
24706   tmode0 = insn_data[d->icode].operand[0].mode;
24707   tmode1 = insn_data[d->icode].operand[1].mode;
24708   modev2 = insn_data[d->icode].operand[2].mode;
24709   modev3 = insn_data[d->icode].operand[3].mode;
24710   modeimm = insn_data[d->icode].operand[4].mode;
24711
24712   if (VECTOR_MODE_P (modev2))
24713     op0 = safe_vector_operand (op0, modev2);
24714   if (VECTOR_MODE_P (modev3))
24715     op1 = safe_vector_operand (op1, modev3);
24716
24717   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
24718     op0 = copy_to_mode_reg (modev2, op0);
24719   if ((optimize && !register_operand (op1, modev3))
24720       || !(*insn_data[d->icode].operand[3].predicate) (op1, modev3))
24721     op1 = copy_to_mode_reg (modev3, op1);
24722
24723   if (! (*insn_data[d->icode].operand[4].predicate) (op2, modeimm))
24724     {
24725       error ("the third argument must be a 8-bit immediate");
24726       return const0_rtx;
24727     }
24728
24729   if (d->code == IX86_BUILTIN_PCMPISTRI128)
24730     {
24731       if (optimize || !target
24732           || GET_MODE (target) != tmode0
24733           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
24734         target = gen_reg_rtx (tmode0);
24735
24736       scratch1 = gen_reg_rtx (tmode1);
24737
24738       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
24739     }
24740   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
24741     {
24742       if (optimize || !target
24743           || GET_MODE (target) != tmode1
24744           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
24745         target = gen_reg_rtx (tmode1);
24746
24747       scratch0 = gen_reg_rtx (tmode0);
24748
24749       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
24750     }
24751   else
24752     {
24753       gcc_assert (d->flag);
24754
24755       scratch0 = gen_reg_rtx (tmode0);
24756       scratch1 = gen_reg_rtx (tmode1);
24757
24758       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
24759     }
24760
24761   if (! pat)
24762     return 0;
24763
24764   emit_insn (pat);
24765
24766   if (d->flag)
24767     {
24768       target = gen_reg_rtx (SImode);
24769       emit_move_insn (target, const0_rtx);
24770       target = gen_rtx_SUBREG (QImode, target, 0);
24771
24772       emit_insn
24773         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
24774                       gen_rtx_fmt_ee (EQ, QImode,
24775                                       gen_rtx_REG ((enum machine_mode) d->flag,
24776                                                    FLAGS_REG),
24777                                       const0_rtx)));
24778       return SUBREG_REG (target);
24779     }
24780   else
24781     return target;
24782 }
24783
24784 /* Subroutine of ix86_expand_builtin to take care of insns with
24785    variable number of operands.  */
24786
24787 static rtx
24788 ix86_expand_args_builtin (const struct builtin_description *d,
24789                           tree exp, rtx target)
24790 {
24791   rtx pat, real_target;
24792   unsigned int i, nargs;
24793   unsigned int nargs_constant = 0;
24794   int num_memory = 0;
24795   struct
24796     {
24797       rtx op;
24798       enum machine_mode mode;
24799     } args[4];
24800   bool last_arg_count = false;
24801   enum insn_code icode = d->icode;
24802   const struct insn_data *insn_p = &insn_data[icode];
24803   enum machine_mode tmode = insn_p->operand[0].mode;
24804   enum machine_mode rmode = VOIDmode;
24805   bool swap = false;
24806   enum rtx_code comparison = d->comparison;
24807
24808   switch ((enum ix86_builtin_type) d->flag)
24809     {
24810     case INT_FTYPE_V8SF_V8SF_PTEST:
24811     case INT_FTYPE_V4DI_V4DI_PTEST:
24812     case INT_FTYPE_V4DF_V4DF_PTEST:
24813     case INT_FTYPE_V4SF_V4SF_PTEST:
24814     case INT_FTYPE_V2DI_V2DI_PTEST:
24815     case INT_FTYPE_V2DF_V2DF_PTEST:
24816       return ix86_expand_sse_ptest (d, exp, target);
24817     case FLOAT128_FTYPE_FLOAT128:
24818     case FLOAT_FTYPE_FLOAT:
24819     case INT_FTYPE_INT:
24820     case UINT64_FTYPE_INT:
24821     case INT64_FTYPE_INT64:
24822     case INT64_FTYPE_V4SF:
24823     case INT64_FTYPE_V2DF:
24824     case INT_FTYPE_V16QI:
24825     case INT_FTYPE_V8QI:
24826     case INT_FTYPE_V8SF:
24827     case INT_FTYPE_V4DF:
24828     case INT_FTYPE_V4SF:
24829     case INT_FTYPE_V2DF:
24830     case V16QI_FTYPE_V16QI:
24831     case V8SI_FTYPE_V8SF:
24832     case V8SI_FTYPE_V4SI:
24833     case V8HI_FTYPE_V8HI:
24834     case V8HI_FTYPE_V16QI:
24835     case V8QI_FTYPE_V8QI:
24836     case V8SF_FTYPE_V8SF:
24837     case V8SF_FTYPE_V8SI:
24838     case V8SF_FTYPE_V4SF:
24839     case V4SI_FTYPE_V4SI:
24840     case V4SI_FTYPE_V16QI:
24841     case V4SI_FTYPE_V4SF:
24842     case V4SI_FTYPE_V8SI:
24843     case V4SI_FTYPE_V8HI:
24844     case V4SI_FTYPE_V4DF:
24845     case V4SI_FTYPE_V2DF:
24846     case V4HI_FTYPE_V4HI:
24847     case V4DF_FTYPE_V4DF:
24848     case V4DF_FTYPE_V4SI:
24849     case V4DF_FTYPE_V4SF:
24850     case V4DF_FTYPE_V2DF:
24851     case V4SF_FTYPE_V4SF:
24852     case V4SF_FTYPE_V4SI:
24853     case V4SF_FTYPE_V8SF:
24854     case V4SF_FTYPE_V4DF:
24855     case V4SF_FTYPE_V2DF:
24856     case V2DI_FTYPE_V2DI:
24857     case V2DI_FTYPE_V16QI:
24858     case V2DI_FTYPE_V8HI:
24859     case V2DI_FTYPE_V4SI:
24860     case V2DF_FTYPE_V2DF:
24861     case V2DF_FTYPE_V4SI:
24862     case V2DF_FTYPE_V4DF:
24863     case V2DF_FTYPE_V4SF:
24864     case V2DF_FTYPE_V2SI:
24865     case V2SI_FTYPE_V2SI:
24866     case V2SI_FTYPE_V4SF:
24867     case V2SI_FTYPE_V2SF:
24868     case V2SI_FTYPE_V2DF:
24869     case V2SF_FTYPE_V2SF:
24870     case V2SF_FTYPE_V2SI:
24871       nargs = 1;
24872       break;
24873     case V4SF_FTYPE_V4SF_VEC_MERGE:
24874     case V2DF_FTYPE_V2DF_VEC_MERGE:
24875       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
24876     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
24877     case V16QI_FTYPE_V16QI_V16QI:
24878     case V16QI_FTYPE_V8HI_V8HI:
24879     case V8QI_FTYPE_V8QI_V8QI:
24880     case V8QI_FTYPE_V4HI_V4HI:
24881     case V8HI_FTYPE_V8HI_V8HI:
24882     case V8HI_FTYPE_V16QI_V16QI:
24883     case V8HI_FTYPE_V4SI_V4SI:
24884     case V8SF_FTYPE_V8SF_V8SF:
24885     case V8SF_FTYPE_V8SF_V8SI:
24886     case V4SI_FTYPE_V4SI_V4SI:
24887     case V4SI_FTYPE_V8HI_V8HI:
24888     case V4SI_FTYPE_V4SF_V4SF:
24889     case V4SI_FTYPE_V2DF_V2DF:
24890     case V4HI_FTYPE_V4HI_V4HI:
24891     case V4HI_FTYPE_V8QI_V8QI:
24892     case V4HI_FTYPE_V2SI_V2SI:
24893     case V4DF_FTYPE_V4DF_V4DF:
24894     case V4DF_FTYPE_V4DF_V4DI:
24895     case V4SF_FTYPE_V4SF_V4SF:
24896     case V4SF_FTYPE_V4SF_V4SI:
24897     case V4SF_FTYPE_V4SF_V2SI:
24898     case V4SF_FTYPE_V4SF_V2DF:
24899     case V4SF_FTYPE_V4SF_DI:
24900     case V4SF_FTYPE_V4SF_SI:
24901     case V2DI_FTYPE_V2DI_V2DI:
24902     case V2DI_FTYPE_V16QI_V16QI:
24903     case V2DI_FTYPE_V4SI_V4SI:
24904     case V2DI_FTYPE_V2DI_V16QI:
24905     case V2DI_FTYPE_V2DF_V2DF:
24906     case V2SI_FTYPE_V2SI_V2SI:
24907     case V2SI_FTYPE_V4HI_V4HI:
24908     case V2SI_FTYPE_V2SF_V2SF:
24909     case V2DF_FTYPE_V2DF_V2DF:
24910     case V2DF_FTYPE_V2DF_V4SF:
24911     case V2DF_FTYPE_V2DF_V2DI:
24912     case V2DF_FTYPE_V2DF_DI:
24913     case V2DF_FTYPE_V2DF_SI:
24914     case V2SF_FTYPE_V2SF_V2SF:
24915     case V1DI_FTYPE_V1DI_V1DI:
24916     case V1DI_FTYPE_V8QI_V8QI:
24917     case V1DI_FTYPE_V2SI_V2SI:
24918       if (comparison == UNKNOWN)
24919         return ix86_expand_binop_builtin (icode, exp, target);
24920       nargs = 2;
24921       break;
24922     case V4SF_FTYPE_V4SF_V4SF_SWAP:
24923     case V2DF_FTYPE_V2DF_V2DF_SWAP:
24924       gcc_assert (comparison != UNKNOWN);
24925       nargs = 2;
24926       swap = true;
24927       break;
24928     case V8HI_FTYPE_V8HI_V8HI_COUNT:
24929     case V8HI_FTYPE_V8HI_SI_COUNT:
24930     case V4SI_FTYPE_V4SI_V4SI_COUNT:
24931     case V4SI_FTYPE_V4SI_SI_COUNT:
24932     case V4HI_FTYPE_V4HI_V4HI_COUNT:
24933     case V4HI_FTYPE_V4HI_SI_COUNT:
24934     case V2DI_FTYPE_V2DI_V2DI_COUNT:
24935     case V2DI_FTYPE_V2DI_SI_COUNT:
24936     case V2SI_FTYPE_V2SI_V2SI_COUNT:
24937     case V2SI_FTYPE_V2SI_SI_COUNT:
24938     case V1DI_FTYPE_V1DI_V1DI_COUNT:
24939     case V1DI_FTYPE_V1DI_SI_COUNT:
24940       nargs = 2;
24941       last_arg_count = true;
24942       break;
24943     case UINT64_FTYPE_UINT64_UINT64:
24944     case UINT_FTYPE_UINT_UINT:
24945     case UINT_FTYPE_UINT_USHORT:
24946     case UINT_FTYPE_UINT_UCHAR:
24947     case UINT16_FTYPE_UINT16_INT:
24948     case UINT8_FTYPE_UINT8_INT:
24949       nargs = 2;
24950       break;
24951     case V2DI2TI_FTYPE_V2DI_INT:
24952       nargs = 2;
24953       rmode = V2DImode;
24954       nargs_constant = 1;
24955       break;
24956     case V8HI_FTYPE_V8HI_INT:
24957     case V8SF_FTYPE_V8SF_INT:
24958     case V4SI_FTYPE_V4SI_INT:
24959     case V4SI_FTYPE_V8SI_INT:
24960     case V4HI_FTYPE_V4HI_INT:
24961     case V4DF_FTYPE_V4DF_INT:
24962     case V4SF_FTYPE_V4SF_INT:
24963     case V4SF_FTYPE_V8SF_INT:
24964     case V2DI_FTYPE_V2DI_INT:
24965     case V2DF_FTYPE_V2DF_INT:
24966     case V2DF_FTYPE_V4DF_INT:
24967       nargs = 2;
24968       nargs_constant = 1;
24969       break;
24970     case V16QI_FTYPE_V16QI_V16QI_V16QI:
24971     case V8SF_FTYPE_V8SF_V8SF_V8SF:
24972     case V4DF_FTYPE_V4DF_V4DF_V4DF:
24973     case V4SF_FTYPE_V4SF_V4SF_V4SF:
24974     case V2DF_FTYPE_V2DF_V2DF_V2DF:
24975       nargs = 3;
24976       break;
24977     case V16QI_FTYPE_V16QI_V16QI_INT:
24978     case V8HI_FTYPE_V8HI_V8HI_INT:
24979     case V8SI_FTYPE_V8SI_V8SI_INT:
24980     case V8SI_FTYPE_V8SI_V4SI_INT:
24981     case V8SF_FTYPE_V8SF_V8SF_INT: 
24982     case V8SF_FTYPE_V8SF_V4SF_INT: 
24983     case V4SI_FTYPE_V4SI_V4SI_INT:
24984     case V4DF_FTYPE_V4DF_V4DF_INT:
24985     case V4DF_FTYPE_V4DF_V2DF_INT:
24986     case V4SF_FTYPE_V4SF_V4SF_INT:
24987     case V2DI_FTYPE_V2DI_V2DI_INT:
24988     case V2DF_FTYPE_V2DF_V2DF_INT:
24989       nargs = 3;
24990       nargs_constant = 1;
24991       break;
24992     case V2DI2TI_FTYPE_V2DI_V2DI_INT:
24993       nargs = 3;
24994       rmode = V2DImode;
24995       nargs_constant = 1;
24996       break;
24997     case V1DI2DI_FTYPE_V1DI_V1DI_INT:
24998       nargs = 3;
24999       rmode = DImode;
25000       nargs_constant = 1;
25001       break;
25002     case V2DI_FTYPE_V2DI_UINT_UINT:
25003       nargs = 3;
25004       nargs_constant = 2;
25005       break;
25006     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
25007       nargs = 4;
25008       nargs_constant = 2;
25009       break;
25010     default:
25011       gcc_unreachable ();
25012     }
25013
25014   gcc_assert (nargs <= ARRAY_SIZE (args));
25015
25016   if (comparison != UNKNOWN)
25017     {
25018       gcc_assert (nargs == 2);
25019       return ix86_expand_sse_compare (d, exp, target, swap);
25020     }
25021
25022   if (rmode == VOIDmode || rmode == tmode)
25023     {
25024       if (optimize
25025           || target == 0
25026           || GET_MODE (target) != tmode
25027           || ! (*insn_p->operand[0].predicate) (target, tmode))
25028         target = gen_reg_rtx (tmode);
25029       real_target = target;
25030     }
25031   else
25032     {
25033       target = gen_reg_rtx (rmode);
25034       real_target = simplify_gen_subreg (tmode, target, rmode, 0);
25035     }
25036
25037   for (i = 0; i < nargs; i++)
25038     {
25039       tree arg = CALL_EXPR_ARG (exp, i);
25040       rtx op = expand_normal (arg);
25041       enum machine_mode mode = insn_p->operand[i + 1].mode;
25042       bool match = (*insn_p->operand[i + 1].predicate) (op, mode);
25043
25044       if (last_arg_count && (i + 1) == nargs)
25045         {
25046           /* SIMD shift insns take either an 8-bit immediate or
25047              register as count.  But builtin functions take int as
25048              count.  If count doesn't match, we put it in register.  */
25049           if (!match)
25050             {
25051               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
25052               if (!(*insn_p->operand[i + 1].predicate) (op, mode))
25053                 op = copy_to_reg (op);
25054             }
25055         }
25056       else if ((nargs - i) <= nargs_constant)
25057         {
25058           if (!match)
25059             switch (icode)
25060               {
25061               case CODE_FOR_sse4_1_roundpd:
25062               case CODE_FOR_sse4_1_roundps:
25063               case CODE_FOR_sse4_1_roundsd:
25064               case CODE_FOR_sse4_1_roundss:
25065               case CODE_FOR_sse4_1_blendps:
25066               case CODE_FOR_avx_blendpd256:
25067               case CODE_FOR_avx_vpermilv4df:
25068               case CODE_FOR_avx_roundpd256:
25069               case CODE_FOR_avx_roundps256:
25070                 error ("the last argument must be a 4-bit immediate");
25071                 return const0_rtx;
25072
25073               case CODE_FOR_sse4_1_blendpd:
25074               case CODE_FOR_avx_vpermilv2df:
25075                 error ("the last argument must be a 2-bit immediate");
25076                 return const0_rtx;
25077
25078               case CODE_FOR_avx_vextractf128v4df:
25079               case CODE_FOR_avx_vextractf128v8sf:
25080               case CODE_FOR_avx_vextractf128v8si:
25081               case CODE_FOR_avx_vinsertf128v4df:
25082               case CODE_FOR_avx_vinsertf128v8sf:
25083               case CODE_FOR_avx_vinsertf128v8si:
25084                 error ("the last argument must be a 1-bit immediate");
25085                 return const0_rtx;
25086
25087               case CODE_FOR_avx_cmpsdv2df3:
25088               case CODE_FOR_avx_cmpssv4sf3:
25089               case CODE_FOR_avx_cmppdv2df3:
25090               case CODE_FOR_avx_cmppsv4sf3:
25091               case CODE_FOR_avx_cmppdv4df3:
25092               case CODE_FOR_avx_cmppsv8sf3:
25093                 error ("the last argument must be a 5-bit immediate");
25094                 return const0_rtx;
25095
25096              default:
25097                 switch (nargs_constant)
25098                   {
25099                   case 2:
25100                     if ((nargs - i) == nargs_constant)
25101                       {
25102                         error ("the next to last argument must be an 8-bit immediate");
25103                         break;
25104                       }
25105                   case 1:
25106                     error ("the last argument must be an 8-bit immediate");
25107                     break;
25108                   default:
25109                     gcc_unreachable ();
25110                   }
25111                 return const0_rtx;
25112               }
25113         }
25114       else
25115         {
25116           if (VECTOR_MODE_P (mode))
25117             op = safe_vector_operand (op, mode);
25118
25119           /* If we aren't optimizing, only allow one memory operand to
25120              be generated.  */
25121           if (memory_operand (op, mode))
25122             num_memory++;
25123
25124           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
25125             {
25126               if (optimize || !match || num_memory > 1)
25127                 op = copy_to_mode_reg (mode, op);
25128             }
25129           else
25130             {
25131               op = copy_to_reg (op);
25132               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
25133             }
25134         }
25135
25136       args[i].op = op;
25137       args[i].mode = mode;
25138     }
25139
25140   switch (nargs)
25141     {
25142     case 1:
25143       pat = GEN_FCN (icode) (real_target, args[0].op);
25144       break;
25145     case 2:
25146       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
25147       break;
25148     case 3:
25149       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
25150                              args[2].op);
25151       break;
25152     case 4:
25153       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
25154                              args[2].op, args[3].op);
25155       break;
25156     default:
25157       gcc_unreachable ();
25158     }
25159
25160   if (! pat)
25161     return 0;
25162
25163   emit_insn (pat);
25164   return target;
25165 }
25166
25167 /* Subroutine of ix86_expand_builtin to take care of special insns
25168    with variable number of operands.  */
25169
25170 static rtx
25171 ix86_expand_special_args_builtin (const struct builtin_description *d,
25172                                     tree exp, rtx target)
25173 {
25174   tree arg;
25175   rtx pat, op;
25176   unsigned int i, nargs, arg_adjust, memory;
25177   struct
25178     {
25179       rtx op;
25180       enum machine_mode mode;
25181     } args[2];
25182   enum insn_code icode = d->icode;
25183   bool last_arg_constant = false;
25184   const struct insn_data *insn_p = &insn_data[icode];
25185   enum machine_mode tmode = insn_p->operand[0].mode;
25186   enum { load, store } klass;
25187
25188   switch ((enum ix86_special_builtin_type) d->flag)
25189     {
25190     case VOID_FTYPE_VOID:
25191       emit_insn (GEN_FCN (icode) (target));
25192       return 0;
25193     case UINT64_FTYPE_VOID:
25194       nargs = 0;
25195       klass = load;
25196       memory = 0;
25197       break;
25198     case UINT64_FTYPE_PUNSIGNED:
25199     case V2DI_FTYPE_PV2DI:
25200     case V32QI_FTYPE_PCCHAR:
25201     case V16QI_FTYPE_PCCHAR:
25202     case V8SF_FTYPE_PCV4SF:
25203     case V8SF_FTYPE_PCFLOAT:
25204     case V4SF_FTYPE_PCFLOAT:
25205     case V4DF_FTYPE_PCV2DF:
25206     case V4DF_FTYPE_PCDOUBLE:
25207     case V2DF_FTYPE_PCDOUBLE:
25208       nargs = 1;
25209       klass = load;
25210       memory = 0;
25211       break;
25212     case VOID_FTYPE_PV2SF_V4SF:
25213     case VOID_FTYPE_PV4DI_V4DI:
25214     case VOID_FTYPE_PV2DI_V2DI:
25215     case VOID_FTYPE_PCHAR_V32QI:
25216     case VOID_FTYPE_PCHAR_V16QI:
25217     case VOID_FTYPE_PFLOAT_V8SF:
25218     case VOID_FTYPE_PFLOAT_V4SF:
25219     case VOID_FTYPE_PDOUBLE_V4DF:
25220     case VOID_FTYPE_PDOUBLE_V2DF:
25221     case VOID_FTYPE_PDI_DI:
25222     case VOID_FTYPE_PINT_INT:
25223       nargs = 1;
25224       klass = store;
25225       /* Reserve memory operand for target.  */
25226       memory = ARRAY_SIZE (args);
25227       break;
25228     case V4SF_FTYPE_V4SF_PCV2SF:
25229     case V2DF_FTYPE_V2DF_PCDOUBLE:
25230       nargs = 2;
25231       klass = load;
25232       memory = 1;
25233       break;
25234     case V8SF_FTYPE_PCV8SF_V8SF:
25235     case V4DF_FTYPE_PCV4DF_V4DF:
25236     case V4SF_FTYPE_PCV4SF_V4SF:
25237     case V2DF_FTYPE_PCV2DF_V2DF:
25238       nargs = 2;
25239       klass = load;
25240       memory = 0;
25241       break;
25242     case VOID_FTYPE_PV8SF_V8SF_V8SF:
25243     case VOID_FTYPE_PV4DF_V4DF_V4DF:
25244     case VOID_FTYPE_PV4SF_V4SF_V4SF:
25245     case VOID_FTYPE_PV2DF_V2DF_V2DF:
25246       nargs = 2;
25247       klass = store;
25248       /* Reserve memory operand for target.  */
25249       memory = ARRAY_SIZE (args);
25250       break;
25251     default:
25252       gcc_unreachable ();
25253     }
25254
25255   gcc_assert (nargs <= ARRAY_SIZE (args));
25256
25257   if (klass == store)
25258     {
25259       arg = CALL_EXPR_ARG (exp, 0);
25260       op = expand_normal (arg);
25261       gcc_assert (target == 0);
25262       target = gen_rtx_MEM (tmode, copy_to_mode_reg (Pmode, op));
25263       arg_adjust = 1;
25264     }
25265   else
25266     {
25267       arg_adjust = 0;
25268       if (optimize
25269           || target == 0
25270           || GET_MODE (target) != tmode
25271           || ! (*insn_p->operand[0].predicate) (target, tmode))
25272         target = gen_reg_rtx (tmode);
25273     }
25274
25275   for (i = 0; i < nargs; i++)
25276     {
25277       enum machine_mode mode = insn_p->operand[i + 1].mode;
25278       bool match;
25279
25280       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
25281       op = expand_normal (arg);
25282       match = (*insn_p->operand[i + 1].predicate) (op, mode);
25283
25284       if (last_arg_constant && (i + 1) == nargs)
25285         {
25286           if (!match)
25287             switch (icode)
25288               {
25289              default:
25290                 error ("the last argument must be an 8-bit immediate");
25291                 return const0_rtx;
25292               }
25293         }
25294       else
25295         {
25296           if (i == memory)
25297             {
25298               /* This must be the memory operand.  */
25299               op = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, op));
25300               gcc_assert (GET_MODE (op) == mode
25301                           || GET_MODE (op) == VOIDmode);
25302             }
25303           else
25304             {
25305               /* This must be register.  */
25306               if (VECTOR_MODE_P (mode))
25307                 op = safe_vector_operand (op, mode);
25308
25309               gcc_assert (GET_MODE (op) == mode
25310                           || GET_MODE (op) == VOIDmode);
25311               op = copy_to_mode_reg (mode, op);
25312             }
25313         }
25314
25315       args[i].op = op;
25316       args[i].mode = mode;
25317     }
25318
25319   switch (nargs)
25320     {
25321     case 0:
25322       pat = GEN_FCN (icode) (target);
25323       break;
25324     case 1:
25325       pat = GEN_FCN (icode) (target, args[0].op);
25326       break;
25327     case 2:
25328       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
25329       break;
25330     default:
25331       gcc_unreachable ();
25332     }
25333
25334   if (! pat)
25335     return 0;
25336   emit_insn (pat);
25337   return klass == store ? 0 : target;
25338 }
25339
25340 /* Return the integer constant in ARG.  Constrain it to be in the range
25341    of the subparts of VEC_TYPE; issue an error if not.  */
25342
25343 static int
25344 get_element_number (tree vec_type, tree arg)
25345 {
25346   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
25347
25348   if (!host_integerp (arg, 1)
25349       || (elt = tree_low_cst (arg, 1), elt > max))
25350     {
25351       error ("selector must be an integer constant in the range 0..%wi", max);
25352       return 0;
25353     }
25354
25355   return elt;
25356 }
25357
25358 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
25359    ix86_expand_vector_init.  We DO have language-level syntax for this, in
25360    the form of  (type){ init-list }.  Except that since we can't place emms
25361    instructions from inside the compiler, we can't allow the use of MMX
25362    registers unless the user explicitly asks for it.  So we do *not* define
25363    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
25364    we have builtins invoked by mmintrin.h that gives us license to emit
25365    these sorts of instructions.  */
25366
25367 static rtx
25368 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
25369 {
25370   enum machine_mode tmode = TYPE_MODE (type);
25371   enum machine_mode inner_mode = GET_MODE_INNER (tmode);
25372   int i, n_elt = GET_MODE_NUNITS (tmode);
25373   rtvec v = rtvec_alloc (n_elt);
25374
25375   gcc_assert (VECTOR_MODE_P (tmode));
25376   gcc_assert (call_expr_nargs (exp) == n_elt);
25377
25378   for (i = 0; i < n_elt; ++i)
25379     {
25380       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
25381       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
25382     }
25383
25384   if (!target || !register_operand (target, tmode))
25385     target = gen_reg_rtx (tmode);
25386
25387   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
25388   return target;
25389 }
25390
25391 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
25392    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
25393    had a language-level syntax for referencing vector elements.  */
25394
25395 static rtx
25396 ix86_expand_vec_ext_builtin (tree exp, rtx target)
25397 {
25398   enum machine_mode tmode, mode0;
25399   tree arg0, arg1;
25400   int elt;
25401   rtx op0;
25402
25403   arg0 = CALL_EXPR_ARG (exp, 0);
25404   arg1 = CALL_EXPR_ARG (exp, 1);
25405
25406   op0 = expand_normal (arg0);
25407   elt = get_element_number (TREE_TYPE (arg0), arg1);
25408
25409   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
25410   mode0 = TYPE_MODE (TREE_TYPE (arg0));
25411   gcc_assert (VECTOR_MODE_P (mode0));
25412
25413   op0 = force_reg (mode0, op0);
25414
25415   if (optimize || !target || !register_operand (target, tmode))
25416     target = gen_reg_rtx (tmode);
25417
25418   ix86_expand_vector_extract (true, target, op0, elt);
25419
25420   return target;
25421 }
25422
25423 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
25424    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
25425    a language-level syntax for referencing vector elements.  */
25426
25427 static rtx
25428 ix86_expand_vec_set_builtin (tree exp)
25429 {
25430   enum machine_mode tmode, mode1;
25431   tree arg0, arg1, arg2;
25432   int elt;
25433   rtx op0, op1, target;
25434
25435   arg0 = CALL_EXPR_ARG (exp, 0);
25436   arg1 = CALL_EXPR_ARG (exp, 1);
25437   arg2 = CALL_EXPR_ARG (exp, 2);
25438
25439   tmode = TYPE_MODE (TREE_TYPE (arg0));
25440   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
25441   gcc_assert (VECTOR_MODE_P (tmode));
25442
25443   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
25444   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
25445   elt = get_element_number (TREE_TYPE (arg0), arg2);
25446
25447   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
25448     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
25449
25450   op0 = force_reg (tmode, op0);
25451   op1 = force_reg (mode1, op1);
25452
25453   /* OP0 is the source of these builtin functions and shouldn't be
25454      modified.  Create a copy, use it and return it as target.  */
25455   target = gen_reg_rtx (tmode);
25456   emit_move_insn (target, op0);
25457   ix86_expand_vector_set (true, target, op1, elt);
25458
25459   return target;
25460 }
25461
25462 /* Expand an expression EXP that calls a built-in function,
25463    with result going to TARGET if that's convenient
25464    (and in mode MODE if that's convenient).
25465    SUBTARGET may be used as the target for computing one of EXP's operands.
25466    IGNORE is nonzero if the value is to be ignored.  */
25467
25468 static rtx
25469 ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
25470                      enum machine_mode mode ATTRIBUTE_UNUSED,
25471                      int ignore ATTRIBUTE_UNUSED)
25472 {
25473   const struct builtin_description *d;
25474   size_t i;
25475   enum insn_code icode;
25476   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
25477   tree arg0, arg1, arg2;
25478   rtx op0, op1, op2, pat;
25479   enum machine_mode mode0, mode1, mode2;
25480   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
25481
25482   /* Determine whether the builtin function is available under the current ISA.
25483      Originally the builtin was not created if it wasn't applicable to the
25484      current ISA based on the command line switches.  With function specific
25485      options, we need to check in the context of the function making the call
25486      whether it is supported.  */
25487   if (ix86_builtins_isa[fcode].isa
25488       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
25489     {
25490       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
25491                                        NULL, NULL, false);
25492
25493       if (!opts)
25494         error ("%qE needs unknown isa option", fndecl);
25495       else
25496         {
25497           gcc_assert (opts != NULL);
25498           error ("%qE needs isa option %s", fndecl, opts);
25499           free (opts);
25500         }
25501       return const0_rtx;
25502     }
25503
25504   switch (fcode)
25505     {
25506     case IX86_BUILTIN_MASKMOVQ:
25507     case IX86_BUILTIN_MASKMOVDQU:
25508       icode = (fcode == IX86_BUILTIN_MASKMOVQ
25509                ? CODE_FOR_mmx_maskmovq
25510                : CODE_FOR_sse2_maskmovdqu);
25511       /* Note the arg order is different from the operand order.  */
25512       arg1 = CALL_EXPR_ARG (exp, 0);
25513       arg2 = CALL_EXPR_ARG (exp, 1);
25514       arg0 = CALL_EXPR_ARG (exp, 2);
25515       op0 = expand_normal (arg0);
25516       op1 = expand_normal (arg1);
25517       op2 = expand_normal (arg2);
25518       mode0 = insn_data[icode].operand[0].mode;
25519       mode1 = insn_data[icode].operand[1].mode;
25520       mode2 = insn_data[icode].operand[2].mode;
25521
25522       op0 = force_reg (Pmode, op0);
25523       op0 = gen_rtx_MEM (mode1, op0);
25524
25525       if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
25526         op0 = copy_to_mode_reg (mode0, op0);
25527       if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
25528         op1 = copy_to_mode_reg (mode1, op1);
25529       if (! (*insn_data[icode].operand[2].predicate) (op2, mode2))
25530         op2 = copy_to_mode_reg (mode2, op2);
25531       pat = GEN_FCN (icode) (op0, op1, op2);
25532       if (! pat)
25533         return 0;
25534       emit_insn (pat);
25535       return 0;
25536
25537     case IX86_BUILTIN_LDMXCSR:
25538       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
25539       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
25540       emit_move_insn (target, op0);
25541       emit_insn (gen_sse_ldmxcsr (target));
25542       return 0;
25543
25544     case IX86_BUILTIN_STMXCSR:
25545       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
25546       emit_insn (gen_sse_stmxcsr (target));
25547       return copy_to_mode_reg (SImode, target);
25548
25549     case IX86_BUILTIN_CLFLUSH:
25550         arg0 = CALL_EXPR_ARG (exp, 0);
25551         op0 = expand_normal (arg0);
25552         icode = CODE_FOR_sse2_clflush;
25553         if (! (*insn_data[icode].operand[0].predicate) (op0, Pmode))
25554             op0 = copy_to_mode_reg (Pmode, op0);
25555
25556         emit_insn (gen_sse2_clflush (op0));
25557         return 0;
25558
25559     case IX86_BUILTIN_MONITOR:
25560       arg0 = CALL_EXPR_ARG (exp, 0);
25561       arg1 = CALL_EXPR_ARG (exp, 1);
25562       arg2 = CALL_EXPR_ARG (exp, 2);
25563       op0 = expand_normal (arg0);
25564       op1 = expand_normal (arg1);
25565       op2 = expand_normal (arg2);
25566       if (!REG_P (op0))
25567         op0 = copy_to_mode_reg (Pmode, op0);
25568       if (!REG_P (op1))
25569         op1 = copy_to_mode_reg (SImode, op1);
25570       if (!REG_P (op2))
25571         op2 = copy_to_mode_reg (SImode, op2);
25572       emit_insn ((*ix86_gen_monitor) (op0, op1, op2));
25573       return 0;
25574
25575     case IX86_BUILTIN_MWAIT:
25576       arg0 = CALL_EXPR_ARG (exp, 0);
25577       arg1 = CALL_EXPR_ARG (exp, 1);
25578       op0 = expand_normal (arg0);
25579       op1 = expand_normal (arg1);
25580       if (!REG_P (op0))
25581         op0 = copy_to_mode_reg (SImode, op0);
25582       if (!REG_P (op1))
25583         op1 = copy_to_mode_reg (SImode, op1);
25584       emit_insn (gen_sse3_mwait (op0, op1));
25585       return 0;
25586
25587     case IX86_BUILTIN_VEC_INIT_V2SI:
25588     case IX86_BUILTIN_VEC_INIT_V4HI:
25589     case IX86_BUILTIN_VEC_INIT_V8QI:
25590       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
25591
25592     case IX86_BUILTIN_VEC_EXT_V2DF:
25593     case IX86_BUILTIN_VEC_EXT_V2DI:
25594     case IX86_BUILTIN_VEC_EXT_V4SF:
25595     case IX86_BUILTIN_VEC_EXT_V4SI:
25596     case IX86_BUILTIN_VEC_EXT_V8HI:
25597     case IX86_BUILTIN_VEC_EXT_V2SI:
25598     case IX86_BUILTIN_VEC_EXT_V4HI:
25599     case IX86_BUILTIN_VEC_EXT_V16QI:
25600       return ix86_expand_vec_ext_builtin (exp, target);
25601
25602     case IX86_BUILTIN_VEC_SET_V2DI:
25603     case IX86_BUILTIN_VEC_SET_V4SF:
25604     case IX86_BUILTIN_VEC_SET_V4SI:
25605     case IX86_BUILTIN_VEC_SET_V8HI:
25606     case IX86_BUILTIN_VEC_SET_V4HI:
25607     case IX86_BUILTIN_VEC_SET_V16QI:
25608       return ix86_expand_vec_set_builtin (exp);
25609
25610     case IX86_BUILTIN_INFQ:
25611     case IX86_BUILTIN_HUGE_VALQ:
25612       {
25613         REAL_VALUE_TYPE inf;
25614         rtx tmp;
25615
25616         real_inf (&inf);
25617         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
25618
25619         tmp = validize_mem (force_const_mem (mode, tmp));
25620
25621         if (target == 0)
25622           target = gen_reg_rtx (mode);
25623
25624         emit_move_insn (target, tmp);
25625         return target;
25626       }
25627
25628     default:
25629       break;
25630     }
25631
25632   for (i = 0, d = bdesc_special_args;
25633        i < ARRAY_SIZE (bdesc_special_args);
25634        i++, d++)
25635     if (d->code == fcode)
25636       return ix86_expand_special_args_builtin (d, exp, target);
25637
25638   for (i = 0, d = bdesc_args;
25639        i < ARRAY_SIZE (bdesc_args);
25640        i++, d++)
25641     if (d->code == fcode)
25642       switch (fcode)
25643         {
25644         case IX86_BUILTIN_FABSQ:
25645         case IX86_BUILTIN_COPYSIGNQ:
25646           if (!TARGET_SSE2)
25647             /* Emit a normal call if SSE2 isn't available.  */
25648             return expand_call (exp, target, ignore);
25649         default:
25650           return ix86_expand_args_builtin (d, exp, target);
25651         }
25652
25653   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
25654     if (d->code == fcode)
25655       return ix86_expand_sse_comi (d, exp, target);
25656
25657   for (i = 0, d = bdesc_pcmpestr;
25658        i < ARRAY_SIZE (bdesc_pcmpestr);
25659        i++, d++)
25660     if (d->code == fcode)
25661       return ix86_expand_sse_pcmpestr (d, exp, target);
25662
25663   for (i = 0, d = bdesc_pcmpistr;
25664        i < ARRAY_SIZE (bdesc_pcmpistr);
25665        i++, d++)
25666     if (d->code == fcode)
25667       return ix86_expand_sse_pcmpistr (d, exp, target);
25668
25669   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
25670     if (d->code == fcode)
25671       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
25672                                             (enum multi_arg_type)d->flag,
25673                                             d->comparison);
25674
25675   gcc_unreachable ();
25676 }
25677
25678 /* Returns a function decl for a vectorized version of the builtin function
25679    with builtin function code FN and the result vector type TYPE, or NULL_TREE
25680    if it is not available.  */
25681
25682 static tree
25683 ix86_builtin_vectorized_function (unsigned int fn, tree type_out,
25684                                   tree type_in)
25685 {
25686   enum machine_mode in_mode, out_mode;
25687   int in_n, out_n;
25688
25689   if (TREE_CODE (type_out) != VECTOR_TYPE
25690       || TREE_CODE (type_in) != VECTOR_TYPE)
25691     return NULL_TREE;
25692
25693   out_mode = TYPE_MODE (TREE_TYPE (type_out));
25694   out_n = TYPE_VECTOR_SUBPARTS (type_out);
25695   in_mode = TYPE_MODE (TREE_TYPE (type_in));
25696   in_n = TYPE_VECTOR_SUBPARTS (type_in);
25697
25698   switch (fn)
25699     {
25700     case BUILT_IN_SQRT:
25701       if (out_mode == DFmode && out_n == 2
25702           && in_mode == DFmode && in_n == 2)
25703         return ix86_builtins[IX86_BUILTIN_SQRTPD];
25704       break;
25705
25706     case BUILT_IN_SQRTF:
25707       if (out_mode == SFmode && out_n == 4
25708           && in_mode == SFmode && in_n == 4)
25709         return ix86_builtins[IX86_BUILTIN_SQRTPS_NR];
25710       break;
25711
25712     case BUILT_IN_LRINT:
25713       if (out_mode == SImode && out_n == 4
25714           && in_mode == DFmode && in_n == 2)
25715         return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
25716       break;
25717
25718     case BUILT_IN_LRINTF:
25719       if (out_mode == SImode && out_n == 4
25720           && in_mode == SFmode && in_n == 4)
25721         return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
25722       break;
25723
25724     case BUILT_IN_COPYSIGN:
25725       if (out_mode == DFmode && out_n == 2
25726           && in_mode == DFmode && in_n == 2)
25727         return ix86_builtins[IX86_BUILTIN_CPYSGNPD];
25728       break;
25729
25730     case BUILT_IN_COPYSIGNF:
25731       if (out_mode == SFmode && out_n == 4
25732           && in_mode == SFmode && in_n == 4)
25733         return ix86_builtins[IX86_BUILTIN_CPYSGNPS];
25734       break;
25735
25736     default:
25737       ;
25738     }
25739
25740   /* Dispatch to a handler for a vectorization library.  */
25741   if (ix86_veclib_handler)
25742     return (*ix86_veclib_handler) ((enum built_in_function) fn, type_out,
25743                                    type_in);
25744
25745   return NULL_TREE;
25746 }
25747
25748 /* Handler for an SVML-style interface to
25749    a library with vectorized intrinsics.  */
25750
25751 static tree
25752 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
25753 {
25754   char name[20];
25755   tree fntype, new_fndecl, args;
25756   unsigned arity;
25757   const char *bname;
25758   enum machine_mode el_mode, in_mode;
25759   int n, in_n;
25760
25761   /* The SVML is suitable for unsafe math only.  */
25762   if (!flag_unsafe_math_optimizations)
25763     return NULL_TREE;
25764
25765   el_mode = TYPE_MODE (TREE_TYPE (type_out));
25766   n = TYPE_VECTOR_SUBPARTS (type_out);
25767   in_mode = TYPE_MODE (TREE_TYPE (type_in));
25768   in_n = TYPE_VECTOR_SUBPARTS (type_in);
25769   if (el_mode != in_mode
25770       || n != in_n)
25771     return NULL_TREE;
25772
25773   switch (fn)
25774     {
25775     case BUILT_IN_EXP:
25776     case BUILT_IN_LOG:
25777     case BUILT_IN_LOG10:
25778     case BUILT_IN_POW:
25779     case BUILT_IN_TANH:
25780     case BUILT_IN_TAN:
25781     case BUILT_IN_ATAN:
25782     case BUILT_IN_ATAN2:
25783     case BUILT_IN_ATANH:
25784     case BUILT_IN_CBRT:
25785     case BUILT_IN_SINH:
25786     case BUILT_IN_SIN:
25787     case BUILT_IN_ASINH:
25788     case BUILT_IN_ASIN:
25789     case BUILT_IN_COSH:
25790     case BUILT_IN_COS:
25791     case BUILT_IN_ACOSH:
25792     case BUILT_IN_ACOS:
25793       if (el_mode != DFmode || n != 2)
25794         return NULL_TREE;
25795       break;
25796
25797     case BUILT_IN_EXPF:
25798     case BUILT_IN_LOGF:
25799     case BUILT_IN_LOG10F:
25800     case BUILT_IN_POWF:
25801     case BUILT_IN_TANHF:
25802     case BUILT_IN_TANF:
25803     case BUILT_IN_ATANF:
25804     case BUILT_IN_ATAN2F:
25805     case BUILT_IN_ATANHF:
25806     case BUILT_IN_CBRTF:
25807     case BUILT_IN_SINHF:
25808     case BUILT_IN_SINF:
25809     case BUILT_IN_ASINHF:
25810     case BUILT_IN_ASINF:
25811     case BUILT_IN_COSHF:
25812     case BUILT_IN_COSF:
25813     case BUILT_IN_ACOSHF:
25814     case BUILT_IN_ACOSF:
25815       if (el_mode != SFmode || n != 4)
25816         return NULL_TREE;
25817       break;
25818
25819     default:
25820       return NULL_TREE;
25821     }
25822
25823   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
25824
25825   if (fn == BUILT_IN_LOGF)
25826     strcpy (name, "vmlsLn4");
25827   else if (fn == BUILT_IN_LOG)
25828     strcpy (name, "vmldLn2");
25829   else if (n == 4)
25830     {
25831       sprintf (name, "vmls%s", bname+10);
25832       name[strlen (name)-1] = '4';
25833     }
25834   else
25835     sprintf (name, "vmld%s2", bname+10);
25836
25837   /* Convert to uppercase. */
25838   name[4] &= ~0x20;
25839
25840   arity = 0;
25841   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
25842        args = TREE_CHAIN (args))
25843     arity++;
25844
25845   if (arity == 1)
25846     fntype = build_function_type_list (type_out, type_in, NULL);
25847   else
25848     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
25849
25850   /* Build a function declaration for the vectorized function.  */
25851   new_fndecl = build_decl (BUILTINS_LOCATION,
25852                            FUNCTION_DECL, get_identifier (name), fntype);
25853   TREE_PUBLIC (new_fndecl) = 1;
25854   DECL_EXTERNAL (new_fndecl) = 1;
25855   DECL_IS_NOVOPS (new_fndecl) = 1;
25856   TREE_READONLY (new_fndecl) = 1;
25857
25858   return new_fndecl;
25859 }
25860
25861 /* Handler for an ACML-style interface to
25862    a library with vectorized intrinsics.  */
25863
25864 static tree
25865 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
25866 {
25867   char name[20] = "__vr.._";
25868   tree fntype, new_fndecl, args;
25869   unsigned arity;
25870   const char *bname;
25871   enum machine_mode el_mode, in_mode;
25872   int n, in_n;
25873
25874   /* The ACML is 64bits only and suitable for unsafe math only as
25875      it does not correctly support parts of IEEE with the required
25876      precision such as denormals.  */
25877   if (!TARGET_64BIT
25878       || !flag_unsafe_math_optimizations)
25879     return NULL_TREE;
25880
25881   el_mode = TYPE_MODE (TREE_TYPE (type_out));
25882   n = TYPE_VECTOR_SUBPARTS (type_out);
25883   in_mode = TYPE_MODE (TREE_TYPE (type_in));
25884   in_n = TYPE_VECTOR_SUBPARTS (type_in);
25885   if (el_mode != in_mode
25886       || n != in_n)
25887     return NULL_TREE;
25888
25889   switch (fn)
25890     {
25891     case BUILT_IN_SIN:
25892     case BUILT_IN_COS:
25893     case BUILT_IN_EXP:
25894     case BUILT_IN_LOG:
25895     case BUILT_IN_LOG2:
25896     case BUILT_IN_LOG10:
25897       name[4] = 'd';
25898       name[5] = '2';
25899       if (el_mode != DFmode
25900           || n != 2)
25901         return NULL_TREE;
25902       break;
25903
25904     case BUILT_IN_SINF:
25905     case BUILT_IN_COSF:
25906     case BUILT_IN_EXPF:
25907     case BUILT_IN_POWF:
25908     case BUILT_IN_LOGF:
25909     case BUILT_IN_LOG2F:
25910     case BUILT_IN_LOG10F:
25911       name[4] = 's';
25912       name[5] = '4';
25913       if (el_mode != SFmode
25914           || n != 4)
25915         return NULL_TREE;
25916       break;
25917
25918     default:
25919       return NULL_TREE;
25920     }
25921
25922   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
25923   sprintf (name + 7, "%s", bname+10);
25924
25925   arity = 0;
25926   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
25927        args = TREE_CHAIN (args))
25928     arity++;
25929
25930   if (arity == 1)
25931     fntype = build_function_type_list (type_out, type_in, NULL);
25932   else
25933     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
25934
25935   /* Build a function declaration for the vectorized function.  */
25936   new_fndecl = build_decl (BUILTINS_LOCATION,
25937                            FUNCTION_DECL, get_identifier (name), fntype);
25938   TREE_PUBLIC (new_fndecl) = 1;
25939   DECL_EXTERNAL (new_fndecl) = 1;
25940   DECL_IS_NOVOPS (new_fndecl) = 1;
25941   TREE_READONLY (new_fndecl) = 1;
25942
25943   return new_fndecl;
25944 }
25945
25946
25947 /* Returns a decl of a function that implements conversion of an integer vector
25948    into a floating-point vector, or vice-versa. TYPE is the type of the integer
25949    side of the conversion.
25950    Return NULL_TREE if it is not available.  */
25951
25952 static tree
25953 ix86_vectorize_builtin_conversion (unsigned int code, tree type)
25954 {
25955   if (TREE_CODE (type) != VECTOR_TYPE)
25956     return NULL_TREE;
25957
25958   switch (code)
25959     {
25960     case FLOAT_EXPR:
25961       switch (TYPE_MODE (type))
25962         {
25963         case V4SImode:
25964           return TYPE_UNSIGNED (type)
25965             ? ix86_builtins[IX86_BUILTIN_CVTUDQ2PS]
25966             : ix86_builtins[IX86_BUILTIN_CVTDQ2PS];
25967         default:
25968           return NULL_TREE;
25969         }
25970
25971     case FIX_TRUNC_EXPR:
25972       switch (TYPE_MODE (type))
25973         {
25974         case V4SImode:
25975           return TYPE_UNSIGNED (type)
25976             ? NULL_TREE
25977             : ix86_builtins[IX86_BUILTIN_CVTTPS2DQ];
25978         default:
25979           return NULL_TREE;
25980         }
25981     default:
25982       return NULL_TREE;
25983
25984     }
25985 }
25986
25987 /* Returns a code for a target-specific builtin that implements
25988    reciprocal of the function, or NULL_TREE if not available.  */
25989
25990 static tree
25991 ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
25992                          bool sqrt ATTRIBUTE_UNUSED)
25993 {
25994   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
25995          && flag_finite_math_only && !flag_trapping_math
25996          && flag_unsafe_math_optimizations))
25997     return NULL_TREE;
25998
25999   if (md_fn)
26000     /* Machine dependent builtins.  */
26001     switch (fn)
26002       {
26003         /* Vectorized version of sqrt to rsqrt conversion.  */
26004       case IX86_BUILTIN_SQRTPS_NR:
26005         return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR];
26006
26007       default:
26008         return NULL_TREE;
26009       }
26010   else
26011     /* Normal builtins.  */
26012     switch (fn)
26013       {
26014         /* Sqrt to rsqrt conversion.  */
26015       case BUILT_IN_SQRTF:
26016         return ix86_builtins[IX86_BUILTIN_RSQRTF];
26017
26018       default:
26019         return NULL_TREE;
26020       }
26021 }
26022
26023 /* Store OPERAND to the memory after reload is completed.  This means
26024    that we can't easily use assign_stack_local.  */
26025 rtx
26026 ix86_force_to_memory (enum machine_mode mode, rtx operand)
26027 {
26028   rtx result;
26029
26030   gcc_assert (reload_completed);
26031   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE)
26032     {
26033       result = gen_rtx_MEM (mode,
26034                             gen_rtx_PLUS (Pmode,
26035                                           stack_pointer_rtx,
26036                                           GEN_INT (-RED_ZONE_SIZE)));
26037       emit_move_insn (result, operand);
26038     }
26039   else if ((TARGET_64BIT_MS_ABI || !TARGET_RED_ZONE) && TARGET_64BIT)
26040     {
26041       switch (mode)
26042         {
26043         case HImode:
26044         case SImode:
26045           operand = gen_lowpart (DImode, operand);
26046           /* FALLTHRU */
26047         case DImode:
26048           emit_insn (
26049                       gen_rtx_SET (VOIDmode,
26050                                    gen_rtx_MEM (DImode,
26051                                                 gen_rtx_PRE_DEC (DImode,
26052                                                         stack_pointer_rtx)),
26053                                    operand));
26054           break;
26055         default:
26056           gcc_unreachable ();
26057         }
26058       result = gen_rtx_MEM (mode, stack_pointer_rtx);
26059     }
26060   else
26061     {
26062       switch (mode)
26063         {
26064         case DImode:
26065           {
26066             rtx operands[2];
26067             split_di (&operand, 1, operands, operands + 1);
26068             emit_insn (
26069                         gen_rtx_SET (VOIDmode,
26070                                      gen_rtx_MEM (SImode,
26071                                                   gen_rtx_PRE_DEC (Pmode,
26072                                                         stack_pointer_rtx)),
26073                                      operands[1]));
26074             emit_insn (
26075                         gen_rtx_SET (VOIDmode,
26076                                      gen_rtx_MEM (SImode,
26077                                                   gen_rtx_PRE_DEC (Pmode,
26078                                                         stack_pointer_rtx)),
26079                                      operands[0]));
26080           }
26081           break;
26082         case HImode:
26083           /* Store HImodes as SImodes.  */
26084           operand = gen_lowpart (SImode, operand);
26085           /* FALLTHRU */
26086         case SImode:
26087           emit_insn (
26088                       gen_rtx_SET (VOIDmode,
26089                                    gen_rtx_MEM (GET_MODE (operand),
26090                                                 gen_rtx_PRE_DEC (SImode,
26091                                                         stack_pointer_rtx)),
26092                                    operand));
26093           break;
26094         default:
26095           gcc_unreachable ();
26096         }
26097       result = gen_rtx_MEM (mode, stack_pointer_rtx);
26098     }
26099   return result;
26100 }
26101
26102 /* Free operand from the memory.  */
26103 void
26104 ix86_free_from_memory (enum machine_mode mode)
26105 {
26106   if (!TARGET_RED_ZONE || TARGET_64BIT_MS_ABI)
26107     {
26108       int size;
26109
26110       if (mode == DImode || TARGET_64BIT)
26111         size = 8;
26112       else
26113         size = 4;
26114       /* Use LEA to deallocate stack space.  In peephole2 it will be converted
26115          to pop or add instruction if registers are available.  */
26116       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
26117                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
26118                                             GEN_INT (size))));
26119     }
26120 }
26121
26122 /* Implement TARGET_IRA_COVER_CLASSES.  If -mfpmath=sse, we prefer
26123    SSE_REGS to FLOAT_REGS if their costs for a pseudo are the
26124    same.  */
26125 static const enum reg_class *
26126 i386_ira_cover_classes (void)
26127 {
26128   static const enum reg_class sse_fpmath_classes[] = {
26129     GENERAL_REGS, SSE_REGS, MMX_REGS, FLOAT_REGS, LIM_REG_CLASSES
26130   };
26131   static const enum reg_class no_sse_fpmath_classes[] = {
26132     GENERAL_REGS, FLOAT_REGS, MMX_REGS, SSE_REGS, LIM_REG_CLASSES
26133   };
26134
26135  return TARGET_SSE_MATH ? sse_fpmath_classes : no_sse_fpmath_classes;
26136 }
26137
26138 /* Put float CONST_DOUBLE in the constant pool instead of fp regs.
26139    QImode must go into class Q_REGS.
26140    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
26141    movdf to do mem-to-mem moves through integer regs.  */
26142 enum reg_class
26143 ix86_preferred_reload_class (rtx x, enum reg_class regclass)
26144 {
26145   enum machine_mode mode = GET_MODE (x);
26146
26147   /* We're only allowed to return a subclass of CLASS.  Many of the
26148      following checks fail for NO_REGS, so eliminate that early.  */
26149   if (regclass == NO_REGS)
26150     return NO_REGS;
26151
26152   /* All classes can load zeros.  */
26153   if (x == CONST0_RTX (mode))
26154     return regclass;
26155
26156   /* Force constants into memory if we are loading a (nonzero) constant into
26157      an MMX or SSE register.  This is because there are no MMX/SSE instructions
26158      to load from a constant.  */
26159   if (CONSTANT_P (x)
26160       && (MAYBE_MMX_CLASS_P (regclass) || MAYBE_SSE_CLASS_P (regclass)))
26161     return NO_REGS;
26162
26163   /* Prefer SSE regs only, if we can use them for math.  */
26164   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
26165     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
26166
26167   /* Floating-point constants need more complex checks.  */
26168   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
26169     {
26170       /* General regs can load everything.  */
26171       if (reg_class_subset_p (regclass, GENERAL_REGS))
26172         return regclass;
26173
26174       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
26175          zero above.  We only want to wind up preferring 80387 registers if
26176          we plan on doing computation with them.  */
26177       if (TARGET_80387
26178           && standard_80387_constant_p (x))
26179         {
26180           /* Limit class to non-sse.  */
26181           if (regclass == FLOAT_SSE_REGS)
26182             return FLOAT_REGS;
26183           if (regclass == FP_TOP_SSE_REGS)
26184             return FP_TOP_REG;
26185           if (regclass == FP_SECOND_SSE_REGS)
26186             return FP_SECOND_REG;
26187           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
26188             return regclass;
26189         }
26190
26191       return NO_REGS;
26192     }
26193
26194   /* Generally when we see PLUS here, it's the function invariant
26195      (plus soft-fp const_int).  Which can only be computed into general
26196      regs.  */
26197   if (GET_CODE (x) == PLUS)
26198     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
26199
26200   /* QImode constants are easy to load, but non-constant QImode data
26201      must go into Q_REGS.  */
26202   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
26203     {
26204       if (reg_class_subset_p (regclass, Q_REGS))
26205         return regclass;
26206       if (reg_class_subset_p (Q_REGS, regclass))
26207         return Q_REGS;
26208       return NO_REGS;
26209     }
26210
26211   return regclass;
26212 }
26213
26214 /* Discourage putting floating-point values in SSE registers unless
26215    SSE math is being used, and likewise for the 387 registers.  */
26216 enum reg_class
26217 ix86_preferred_output_reload_class (rtx x, enum reg_class regclass)
26218 {
26219   enum machine_mode mode = GET_MODE (x);
26220
26221   /* Restrict the output reload class to the register bank that we are doing
26222      math on.  If we would like not to return a subset of CLASS, reject this
26223      alternative: if reload cannot do this, it will still use its choice.  */
26224   mode = GET_MODE (x);
26225   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
26226     return MAYBE_SSE_CLASS_P (regclass) ? SSE_REGS : NO_REGS;
26227
26228   if (X87_FLOAT_MODE_P (mode))
26229     {
26230       if (regclass == FP_TOP_SSE_REGS)
26231         return FP_TOP_REG;
26232       else if (regclass == FP_SECOND_SSE_REGS)
26233         return FP_SECOND_REG;
26234       else
26235         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
26236     }
26237
26238   return regclass;
26239 }
26240
26241 static enum reg_class
26242 ix86_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
26243                        enum machine_mode mode,
26244                        secondary_reload_info *sri ATTRIBUTE_UNUSED)
26245 {
26246   /* QImode spills from non-QI registers require
26247      intermediate register on 32bit targets.  */
26248   if (!in_p && mode == QImode && !TARGET_64BIT
26249       && (rclass == GENERAL_REGS
26250           || rclass == LEGACY_REGS
26251           || rclass == INDEX_REGS))
26252     {
26253       int regno;
26254
26255       if (REG_P (x))
26256         regno = REGNO (x);
26257       else
26258         regno = -1;
26259
26260       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
26261         regno = true_regnum (x);
26262
26263       /* Return Q_REGS if the operand is in memory.  */
26264       if (regno == -1)
26265         return Q_REGS;
26266     }
26267
26268   return NO_REGS;
26269 }
26270
26271 /* If we are copying between general and FP registers, we need a memory
26272    location. The same is true for SSE and MMX registers.
26273
26274    To optimize register_move_cost performance, allow inline variant.
26275
26276    The macro can't work reliably when one of the CLASSES is class containing
26277    registers from multiple units (SSE, MMX, integer).  We avoid this by never
26278    combining those units in single alternative in the machine description.
26279    Ensure that this constraint holds to avoid unexpected surprises.
26280
26281    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
26282    enforce these sanity checks.  */
26283
26284 static inline int
26285 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
26286                               enum machine_mode mode, int strict)
26287 {
26288   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
26289       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
26290       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
26291       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
26292       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
26293       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
26294     {
26295       gcc_assert (!strict);
26296       return true;
26297     }
26298
26299   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
26300     return true;
26301
26302   /* ??? This is a lie.  We do have moves between mmx/general, and for
26303      mmx/sse2.  But by saying we need secondary memory we discourage the
26304      register allocator from using the mmx registers unless needed.  */
26305   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
26306     return true;
26307
26308   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
26309     {
26310       /* SSE1 doesn't have any direct moves from other classes.  */
26311       if (!TARGET_SSE2)
26312         return true;
26313
26314       /* If the target says that inter-unit moves are more expensive
26315          than moving through memory, then don't generate them.  */
26316       if (!TARGET_INTER_UNIT_MOVES)
26317         return true;
26318
26319       /* Between SSE and general, we have moves no larger than word size.  */
26320       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
26321         return true;
26322     }
26323
26324   return false;
26325 }
26326
26327 int
26328 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
26329                               enum machine_mode mode, int strict)
26330 {
26331   return inline_secondary_memory_needed (class1, class2, mode, strict);
26332 }
26333
26334 /* Return true if the registers in CLASS cannot represent the change from
26335    modes FROM to TO.  */
26336
26337 bool
26338 ix86_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
26339                                enum reg_class regclass)
26340 {
26341   if (from == to)
26342     return false;
26343
26344   /* x87 registers can't do subreg at all, as all values are reformatted
26345      to extended precision.  */
26346   if (MAYBE_FLOAT_CLASS_P (regclass))
26347     return true;
26348
26349   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
26350     {
26351       /* Vector registers do not support QI or HImode loads.  If we don't
26352          disallow a change to these modes, reload will assume it's ok to
26353          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
26354          the vec_dupv4hi pattern.  */
26355       if (GET_MODE_SIZE (from) < 4)
26356         return true;
26357
26358       /* Vector registers do not support subreg with nonzero offsets, which
26359          are otherwise valid for integer registers.  Since we can't see
26360          whether we have a nonzero offset from here, prohibit all
26361          nonparadoxical subregs changing size.  */
26362       if (GET_MODE_SIZE (to) < GET_MODE_SIZE (from))
26363         return true;
26364     }
26365
26366   return false;
26367 }
26368
26369 /* Return the cost of moving data of mode M between a
26370    register and memory.  A value of 2 is the default; this cost is
26371    relative to those in `REGISTER_MOVE_COST'.
26372
26373    This function is used extensively by register_move_cost that is used to
26374    build tables at startup.  Make it inline in this case.
26375    When IN is 2, return maximum of in and out move cost.
26376
26377    If moving between registers and memory is more expensive than
26378    between two registers, you should define this macro to express the
26379    relative cost.
26380
26381    Model also increased moving costs of QImode registers in non
26382    Q_REGS classes.
26383  */
26384 static inline int
26385 inline_memory_move_cost (enum machine_mode mode, enum reg_class regclass,
26386                          int in)
26387 {
26388   int cost;
26389   if (FLOAT_CLASS_P (regclass))
26390     {
26391       int index;
26392       switch (mode)
26393         {
26394           case SFmode:
26395             index = 0;
26396             break;
26397           case DFmode:
26398             index = 1;
26399             break;
26400           case XFmode:
26401             index = 2;
26402             break;
26403           default:
26404             return 100;
26405         }
26406       if (in == 2)
26407         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
26408       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
26409     }
26410   if (SSE_CLASS_P (regclass))
26411     {
26412       int index;
26413       switch (GET_MODE_SIZE (mode))
26414         {
26415           case 4:
26416             index = 0;
26417             break;
26418           case 8:
26419             index = 1;
26420             break;
26421           case 16:
26422             index = 2;
26423             break;
26424           default:
26425             return 100;
26426         }
26427       if (in == 2)
26428         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
26429       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
26430     }
26431   if (MMX_CLASS_P (regclass))
26432     {
26433       int index;
26434       switch (GET_MODE_SIZE (mode))
26435         {
26436           case 4:
26437             index = 0;
26438             break;
26439           case 8:
26440             index = 1;
26441             break;
26442           default:
26443             return 100;
26444         }
26445       if (in)
26446         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
26447       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
26448     }
26449   switch (GET_MODE_SIZE (mode))
26450     {
26451       case 1:
26452         if (Q_CLASS_P (regclass) || TARGET_64BIT)
26453           {
26454             if (!in)
26455               return ix86_cost->int_store[0];
26456             if (TARGET_PARTIAL_REG_DEPENDENCY
26457                 && optimize_function_for_speed_p (cfun))
26458               cost = ix86_cost->movzbl_load;
26459             else
26460               cost = ix86_cost->int_load[0];
26461             if (in == 2)
26462               return MAX (cost, ix86_cost->int_store[0]);
26463             return cost;
26464           }
26465         else
26466           {
26467            if (in == 2)
26468              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
26469            if (in)
26470              return ix86_cost->movzbl_load;
26471            else
26472              return ix86_cost->int_store[0] + 4;
26473           }
26474         break;
26475       case 2:
26476         if (in == 2)
26477           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
26478         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
26479       default:
26480         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
26481         if (mode == TFmode)
26482           mode = XFmode;
26483         if (in == 2)
26484           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
26485         else if (in)
26486           cost = ix86_cost->int_load[2];
26487         else
26488           cost = ix86_cost->int_store[2];
26489         return (cost * (((int) GET_MODE_SIZE (mode)
26490                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
26491     }
26492 }
26493
26494 int
26495 ix86_memory_move_cost (enum machine_mode mode, enum reg_class regclass, int in)
26496 {
26497   return inline_memory_move_cost (mode, regclass, in);
26498 }
26499
26500
26501 /* Return the cost of moving data from a register in class CLASS1 to
26502    one in class CLASS2.
26503
26504    It is not required that the cost always equal 2 when FROM is the same as TO;
26505    on some machines it is expensive to move between registers if they are not
26506    general registers.  */
26507
26508 int
26509 ix86_register_move_cost (enum machine_mode mode, enum reg_class class1,
26510                          enum reg_class class2)
26511 {
26512   /* In case we require secondary memory, compute cost of the store followed
26513      by load.  In order to avoid bad register allocation choices, we need
26514      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
26515
26516   if (inline_secondary_memory_needed (class1, class2, mode, 0))
26517     {
26518       int cost = 1;
26519
26520       cost += inline_memory_move_cost (mode, class1, 2);
26521       cost += inline_memory_move_cost (mode, class2, 2);
26522
26523       /* In case of copying from general_purpose_register we may emit multiple
26524          stores followed by single load causing memory size mismatch stall.
26525          Count this as arbitrarily high cost of 20.  */
26526       if (CLASS_MAX_NREGS (class1, mode) > CLASS_MAX_NREGS (class2, mode))
26527         cost += 20;
26528
26529       /* In the case of FP/MMX moves, the registers actually overlap, and we
26530          have to switch modes in order to treat them differently.  */
26531       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
26532           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
26533         cost += 20;
26534
26535       return cost;
26536     }
26537
26538   /* Moves between SSE/MMX and integer unit are expensive.  */
26539   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
26540       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
26541
26542     /* ??? By keeping returned value relatively high, we limit the number
26543        of moves between integer and MMX/SSE registers for all targets.
26544        Additionally, high value prevents problem with x86_modes_tieable_p(),
26545        where integer modes in MMX/SSE registers are not tieable
26546        because of missing QImode and HImode moves to, from or between
26547        MMX/SSE registers.  */
26548     return MAX (8, ix86_cost->mmxsse_to_integer);
26549
26550   if (MAYBE_FLOAT_CLASS_P (class1))
26551     return ix86_cost->fp_move;
26552   if (MAYBE_SSE_CLASS_P (class1))
26553     return ix86_cost->sse_move;
26554   if (MAYBE_MMX_CLASS_P (class1))
26555     return ix86_cost->mmx_move;
26556   return 2;
26557 }
26558
26559 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE.  */
26560
26561 bool
26562 ix86_hard_regno_mode_ok (int regno, enum machine_mode mode)
26563 {
26564   /* Flags and only flags can only hold CCmode values.  */
26565   if (CC_REGNO_P (regno))
26566     return GET_MODE_CLASS (mode) == MODE_CC;
26567   if (GET_MODE_CLASS (mode) == MODE_CC
26568       || GET_MODE_CLASS (mode) == MODE_RANDOM
26569       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
26570     return 0;
26571   if (FP_REGNO_P (regno))
26572     return VALID_FP_MODE_P (mode);
26573   if (SSE_REGNO_P (regno))
26574     {
26575       /* We implement the move patterns for all vector modes into and
26576          out of SSE registers, even when no operation instructions
26577          are available.  OImode move is available only when AVX is
26578          enabled.  */
26579       return ((TARGET_AVX && mode == OImode)
26580               || VALID_AVX256_REG_MODE (mode)
26581               || VALID_SSE_REG_MODE (mode)
26582               || VALID_SSE2_REG_MODE (mode)
26583               || VALID_MMX_REG_MODE (mode)
26584               || VALID_MMX_REG_MODE_3DNOW (mode));
26585     }
26586   if (MMX_REGNO_P (regno))
26587     {
26588       /* We implement the move patterns for 3DNOW modes even in MMX mode,
26589          so if the register is available at all, then we can move data of
26590          the given mode into or out of it.  */
26591       return (VALID_MMX_REG_MODE (mode)
26592               || VALID_MMX_REG_MODE_3DNOW (mode));
26593     }
26594
26595   if (mode == QImode)
26596     {
26597       /* Take care for QImode values - they can be in non-QI regs,
26598          but then they do cause partial register stalls.  */
26599       if (regno <= BX_REG || TARGET_64BIT)
26600         return 1;
26601       if (!TARGET_PARTIAL_REG_STALL)
26602         return 1;
26603       return reload_in_progress || reload_completed;
26604     }
26605   /* We handle both integer and floats in the general purpose registers.  */
26606   else if (VALID_INT_MODE_P (mode))
26607     return 1;
26608   else if (VALID_FP_MODE_P (mode))
26609     return 1;
26610   else if (VALID_DFP_MODE_P (mode))
26611     return 1;
26612   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
26613      on to use that value in smaller contexts, this can easily force a
26614      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
26615      supporting DImode, allow it.  */
26616   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
26617     return 1;
26618
26619   return 0;
26620 }
26621
26622 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
26623    tieable integer mode.  */
26624
26625 static bool
26626 ix86_tieable_integer_mode_p (enum machine_mode mode)
26627 {
26628   switch (mode)
26629     {
26630     case HImode:
26631     case SImode:
26632       return true;
26633
26634     case QImode:
26635       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
26636
26637     case DImode:
26638       return TARGET_64BIT;
26639
26640     default:
26641       return false;
26642     }
26643 }
26644
26645 /* Return true if MODE1 is accessible in a register that can hold MODE2
26646    without copying.  That is, all register classes that can hold MODE2
26647    can also hold MODE1.  */
26648
26649 bool
26650 ix86_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
26651 {
26652   if (mode1 == mode2)
26653     return true;
26654
26655   if (ix86_tieable_integer_mode_p (mode1)
26656       && ix86_tieable_integer_mode_p (mode2))
26657     return true;
26658
26659   /* MODE2 being XFmode implies fp stack or general regs, which means we
26660      can tie any smaller floating point modes to it.  Note that we do not
26661      tie this with TFmode.  */
26662   if (mode2 == XFmode)
26663     return mode1 == SFmode || mode1 == DFmode;
26664
26665   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
26666      that we can tie it with SFmode.  */
26667   if (mode2 == DFmode)
26668     return mode1 == SFmode;
26669
26670   /* If MODE2 is only appropriate for an SSE register, then tie with
26671      any other mode acceptable to SSE registers.  */
26672   if (GET_MODE_SIZE (mode2) == 16
26673       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
26674     return (GET_MODE_SIZE (mode1) == 16
26675             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
26676
26677   /* If MODE2 is appropriate for an MMX register, then tie
26678      with any other mode acceptable to MMX registers.  */
26679   if (GET_MODE_SIZE (mode2) == 8
26680       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
26681     return (GET_MODE_SIZE (mode1) == 8
26682             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
26683
26684   return false;
26685 }
26686
26687 /* Compute a (partial) cost for rtx X.  Return true if the complete
26688    cost has been computed, and false if subexpressions should be
26689    scanned.  In either case, *TOTAL contains the cost result.  */
26690
26691 static bool
26692 ix86_rtx_costs (rtx x, int code, int outer_code_i, int *total, bool speed)
26693 {
26694   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
26695   enum machine_mode mode = GET_MODE (x);
26696   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
26697
26698   switch (code)
26699     {
26700     case CONST_INT:
26701     case CONST:
26702     case LABEL_REF:
26703     case SYMBOL_REF:
26704       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
26705         *total = 3;
26706       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
26707         *total = 2;
26708       else if (flag_pic && SYMBOLIC_CONST (x)
26709                && (!TARGET_64BIT
26710                    || (!GET_CODE (x) != LABEL_REF
26711                        && (GET_CODE (x) != SYMBOL_REF
26712                            || !SYMBOL_REF_LOCAL_P (x)))))
26713         *total = 1;
26714       else
26715         *total = 0;
26716       return true;
26717
26718     case CONST_DOUBLE:
26719       if (mode == VOIDmode)
26720         *total = 0;
26721       else
26722         switch (standard_80387_constant_p (x))
26723           {
26724           case 1: /* 0.0 */
26725             *total = 1;
26726             break;
26727           default: /* Other constants */
26728             *total = 2;
26729             break;
26730           case 0:
26731           case -1:
26732             /* Start with (MEM (SYMBOL_REF)), since that's where
26733                it'll probably end up.  Add a penalty for size.  */
26734             *total = (COSTS_N_INSNS (1)
26735                       + (flag_pic != 0 && !TARGET_64BIT)
26736                       + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
26737             break;
26738           }
26739       return true;
26740
26741     case ZERO_EXTEND:
26742       /* The zero extensions is often completely free on x86_64, so make
26743          it as cheap as possible.  */
26744       if (TARGET_64BIT && mode == DImode
26745           && GET_MODE (XEXP (x, 0)) == SImode)
26746         *total = 1;
26747       else if (TARGET_ZERO_EXTEND_WITH_AND)
26748         *total = cost->add;
26749       else
26750         *total = cost->movzx;
26751       return false;
26752
26753     case SIGN_EXTEND:
26754       *total = cost->movsx;
26755       return false;
26756
26757     case ASHIFT:
26758       if (CONST_INT_P (XEXP (x, 1))
26759           && (GET_MODE (XEXP (x, 0)) != DImode || TARGET_64BIT))
26760         {
26761           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
26762           if (value == 1)
26763             {
26764               *total = cost->add;
26765               return false;
26766             }
26767           if ((value == 2 || value == 3)
26768               && cost->lea <= cost->shift_const)
26769             {
26770               *total = cost->lea;
26771               return false;
26772             }
26773         }
26774       /* FALLTHRU */
26775
26776     case ROTATE:
26777     case ASHIFTRT:
26778     case LSHIFTRT:
26779     case ROTATERT:
26780       if (!TARGET_64BIT && GET_MODE (XEXP (x, 0)) == DImode)
26781         {
26782           if (CONST_INT_P (XEXP (x, 1)))
26783             {
26784               if (INTVAL (XEXP (x, 1)) > 32)
26785                 *total = cost->shift_const + COSTS_N_INSNS (2);
26786               else
26787                 *total = cost->shift_const * 2;
26788             }
26789           else
26790             {
26791               if (GET_CODE (XEXP (x, 1)) == AND)
26792                 *total = cost->shift_var * 2;
26793               else
26794                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
26795             }
26796         }
26797       else
26798         {
26799           if (CONST_INT_P (XEXP (x, 1)))
26800             *total = cost->shift_const;
26801           else
26802             *total = cost->shift_var;
26803         }
26804       return false;
26805
26806     case MULT:
26807       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26808         {
26809           /* ??? SSE scalar cost should be used here.  */
26810           *total = cost->fmul;
26811           return false;
26812         }
26813       else if (X87_FLOAT_MODE_P (mode))
26814         {
26815           *total = cost->fmul;
26816           return false;
26817         }
26818       else if (FLOAT_MODE_P (mode))
26819         {
26820           /* ??? SSE vector cost should be used here.  */
26821           *total = cost->fmul;
26822           return false;
26823         }
26824       else
26825         {
26826           rtx op0 = XEXP (x, 0);
26827           rtx op1 = XEXP (x, 1);
26828           int nbits;
26829           if (CONST_INT_P (XEXP (x, 1)))
26830             {
26831               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
26832               for (nbits = 0; value != 0; value &= value - 1)
26833                 nbits++;
26834             }
26835           else
26836             /* This is arbitrary.  */
26837             nbits = 7;
26838
26839           /* Compute costs correctly for widening multiplication.  */
26840           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
26841               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
26842                  == GET_MODE_SIZE (mode))
26843             {
26844               int is_mulwiden = 0;
26845               enum machine_mode inner_mode = GET_MODE (op0);
26846
26847               if (GET_CODE (op0) == GET_CODE (op1))
26848                 is_mulwiden = 1, op1 = XEXP (op1, 0);
26849               else if (CONST_INT_P (op1))
26850                 {
26851                   if (GET_CODE (op0) == SIGN_EXTEND)
26852                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
26853                                   == INTVAL (op1);
26854                   else
26855                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
26856                 }
26857
26858               if (is_mulwiden)
26859                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
26860             }
26861
26862           *total = (cost->mult_init[MODE_INDEX (mode)]
26863                     + nbits * cost->mult_bit
26864                     + rtx_cost (op0, outer_code, speed) + rtx_cost (op1, outer_code, speed));
26865
26866           return true;
26867         }
26868
26869     case DIV:
26870     case UDIV:
26871     case MOD:
26872     case UMOD:
26873       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26874         /* ??? SSE cost should be used here.  */
26875         *total = cost->fdiv;
26876       else if (X87_FLOAT_MODE_P (mode))
26877         *total = cost->fdiv;
26878       else if (FLOAT_MODE_P (mode))
26879         /* ??? SSE vector cost should be used here.  */
26880         *total = cost->fdiv;
26881       else
26882         *total = cost->divide[MODE_INDEX (mode)];
26883       return false;
26884
26885     case PLUS:
26886       if (GET_MODE_CLASS (mode) == MODE_INT
26887                && GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (Pmode))
26888         {
26889           if (GET_CODE (XEXP (x, 0)) == PLUS
26890               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
26891               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
26892               && CONSTANT_P (XEXP (x, 1)))
26893             {
26894               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
26895               if (val == 2 || val == 4 || val == 8)
26896                 {
26897                   *total = cost->lea;
26898                   *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
26899                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
26900                                       outer_code, speed);
26901                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26902                   return true;
26903                 }
26904             }
26905           else if (GET_CODE (XEXP (x, 0)) == MULT
26906                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
26907             {
26908               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
26909               if (val == 2 || val == 4 || val == 8)
26910                 {
26911                   *total = cost->lea;
26912                   *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
26913                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26914                   return true;
26915                 }
26916             }
26917           else if (GET_CODE (XEXP (x, 0)) == PLUS)
26918             {
26919               *total = cost->lea;
26920               *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
26921               *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
26922               *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26923               return true;
26924             }
26925         }
26926       /* FALLTHRU */
26927
26928     case MINUS:
26929       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26930         {
26931           /* ??? SSE cost should be used here.  */
26932           *total = cost->fadd;
26933           return false;
26934         }
26935       else if (X87_FLOAT_MODE_P (mode))
26936         {
26937           *total = cost->fadd;
26938           return false;
26939         }
26940       else if (FLOAT_MODE_P (mode))
26941         {
26942           /* ??? SSE vector cost should be used here.  */
26943           *total = cost->fadd;
26944           return false;
26945         }
26946       /* FALLTHRU */
26947
26948     case AND:
26949     case IOR:
26950     case XOR:
26951       if (!TARGET_64BIT && mode == DImode)
26952         {
26953           *total = (cost->add * 2
26954                     + (rtx_cost (XEXP (x, 0), outer_code, speed)
26955                        << (GET_MODE (XEXP (x, 0)) != DImode))
26956                     + (rtx_cost (XEXP (x, 1), outer_code, speed)
26957                        << (GET_MODE (XEXP (x, 1)) != DImode)));
26958           return true;
26959         }
26960       /* FALLTHRU */
26961
26962     case NEG:
26963       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26964         {
26965           /* ??? SSE cost should be used here.  */
26966           *total = cost->fchs;
26967           return false;
26968         }
26969       else if (X87_FLOAT_MODE_P (mode))
26970         {
26971           *total = cost->fchs;
26972           return false;
26973         }
26974       else if (FLOAT_MODE_P (mode))
26975         {
26976           /* ??? SSE vector cost should be used here.  */
26977           *total = cost->fchs;
26978           return false;
26979         }
26980       /* FALLTHRU */
26981
26982     case NOT:
26983       if (!TARGET_64BIT && mode == DImode)
26984         *total = cost->add * 2;
26985       else
26986         *total = cost->add;
26987       return false;
26988
26989     case COMPARE:
26990       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
26991           && XEXP (XEXP (x, 0), 1) == const1_rtx
26992           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
26993           && XEXP (x, 1) == const0_rtx)
26994         {
26995           /* This kind of construct is implemented using test[bwl].
26996              Treat it as if we had an AND.  */
26997           *total = (cost->add
26998                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed)
26999                     + rtx_cost (const1_rtx, outer_code, speed));
27000           return true;
27001         }
27002       return false;
27003
27004     case FLOAT_EXTEND:
27005       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
27006         *total = 0;
27007       return false;
27008
27009     case ABS:
27010       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
27011         /* ??? SSE cost should be used here.  */
27012         *total = cost->fabs;
27013       else if (X87_FLOAT_MODE_P (mode))
27014         *total = cost->fabs;
27015       else if (FLOAT_MODE_P (mode))
27016         /* ??? SSE vector cost should be used here.  */
27017         *total = cost->fabs;
27018       return false;
27019
27020     case SQRT:
27021       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
27022         /* ??? SSE cost should be used here.  */
27023         *total = cost->fsqrt;
27024       else if (X87_FLOAT_MODE_P (mode))
27025         *total = cost->fsqrt;
27026       else if (FLOAT_MODE_P (mode))
27027         /* ??? SSE vector cost should be used here.  */
27028         *total = cost->fsqrt;
27029       return false;
27030
27031     case UNSPEC:
27032       if (XINT (x, 1) == UNSPEC_TP)
27033         *total = 0;
27034       return false;
27035
27036     default:
27037       return false;
27038     }
27039 }
27040
27041 #if TARGET_MACHO
27042
27043 static int current_machopic_label_num;
27044
27045 /* Given a symbol name and its associated stub, write out the
27046    definition of the stub.  */
27047
27048 void
27049 machopic_output_stub (FILE *file, const char *symb, const char *stub)
27050 {
27051   unsigned int length;
27052   char *binder_name, *symbol_name, lazy_ptr_name[32];
27053   int label = ++current_machopic_label_num;
27054
27055   /* For 64-bit we shouldn't get here.  */
27056   gcc_assert (!TARGET_64BIT);
27057
27058   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
27059   symb = (*targetm.strip_name_encoding) (symb);
27060
27061   length = strlen (stub);
27062   binder_name = XALLOCAVEC (char, length + 32);
27063   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
27064
27065   length = strlen (symb);
27066   symbol_name = XALLOCAVEC (char, length + 32);
27067   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
27068
27069   sprintf (lazy_ptr_name, "L%d$lz", label);
27070
27071   if (MACHOPIC_PURE)
27072     switch_to_section (darwin_sections[machopic_picsymbol_stub_section]);
27073   else
27074     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
27075
27076   fprintf (file, "%s:\n", stub);
27077   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
27078
27079   if (MACHOPIC_PURE)
27080     {
27081       fprintf (file, "\tcall\tLPC$%d\nLPC$%d:\tpopl\t%%eax\n", label, label);
27082       fprintf (file, "\tmovl\t%s-LPC$%d(%%eax),%%edx\n", lazy_ptr_name, label);
27083       fprintf (file, "\tjmp\t*%%edx\n");
27084     }
27085   else
27086     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
27087
27088   fprintf (file, "%s:\n", binder_name);
27089
27090   if (MACHOPIC_PURE)
27091     {
27092       fprintf (file, "\tlea\t%s-LPC$%d(%%eax),%%eax\n", lazy_ptr_name, label);
27093       fputs ("\tpushl\t%eax\n", file);
27094     }
27095   else
27096     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
27097
27098   fputs ("\tjmp\tdyld_stub_binding_helper\n", file);
27099
27100   switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
27101   fprintf (file, "%s:\n", lazy_ptr_name);
27102   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
27103   fprintf (file, ASM_LONG "%s\n", binder_name);
27104 }
27105
27106 void
27107 darwin_x86_file_end (void)
27108 {
27109   darwin_file_end ();
27110   ix86_file_end ();
27111 }
27112 #endif /* TARGET_MACHO */
27113
27114 /* Order the registers for register allocator.  */
27115
27116 void
27117 x86_order_regs_for_local_alloc (void)
27118 {
27119    int pos = 0;
27120    int i;
27121
27122    /* First allocate the local general purpose registers.  */
27123    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
27124      if (GENERAL_REGNO_P (i) && call_used_regs[i])
27125         reg_alloc_order [pos++] = i;
27126
27127    /* Global general purpose registers.  */
27128    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
27129      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
27130         reg_alloc_order [pos++] = i;
27131
27132    /* x87 registers come first in case we are doing FP math
27133       using them.  */
27134    if (!TARGET_SSE_MATH)
27135      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
27136        reg_alloc_order [pos++] = i;
27137
27138    /* SSE registers.  */
27139    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
27140      reg_alloc_order [pos++] = i;
27141    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
27142      reg_alloc_order [pos++] = i;
27143
27144    /* x87 registers.  */
27145    if (TARGET_SSE_MATH)
27146      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
27147        reg_alloc_order [pos++] = i;
27148
27149    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
27150      reg_alloc_order [pos++] = i;
27151
27152    /* Initialize the rest of array as we do not allocate some registers
27153       at all.  */
27154    while (pos < FIRST_PSEUDO_REGISTER)
27155      reg_alloc_order [pos++] = 0;
27156 }
27157
27158 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
27159    struct attribute_spec.handler.  */
27160 static tree
27161 ix86_handle_abi_attribute (tree *node, tree name,
27162                               tree args ATTRIBUTE_UNUSED,
27163                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
27164 {
27165   if (TREE_CODE (*node) != FUNCTION_TYPE
27166       && TREE_CODE (*node) != METHOD_TYPE
27167       && TREE_CODE (*node) != FIELD_DECL
27168       && TREE_CODE (*node) != TYPE_DECL)
27169     {
27170       warning (OPT_Wattributes, "%qE attribute only applies to functions",
27171                name);
27172       *no_add_attrs = true;
27173       return NULL_TREE;
27174     }
27175   if (!TARGET_64BIT)
27176     {
27177       warning (OPT_Wattributes, "%qE attribute only available for 64-bit",
27178                name);
27179       *no_add_attrs = true;
27180       return NULL_TREE;
27181     }
27182
27183   /* Can combine regparm with all attributes but fastcall.  */
27184   if (is_attribute_p ("ms_abi", name))
27185     {
27186       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
27187         {
27188           error ("ms_abi and sysv_abi attributes are not compatible");
27189         }
27190
27191       return NULL_TREE;
27192     }
27193   else if (is_attribute_p ("sysv_abi", name))
27194     {
27195       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
27196         {
27197           error ("ms_abi and sysv_abi attributes are not compatible");
27198         }
27199
27200       return NULL_TREE;
27201     }
27202
27203   return NULL_TREE;
27204 }
27205
27206 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
27207    struct attribute_spec.handler.  */
27208 static tree
27209 ix86_handle_struct_attribute (tree *node, tree name,
27210                               tree args ATTRIBUTE_UNUSED,
27211                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
27212 {
27213   tree *type = NULL;
27214   if (DECL_P (*node))
27215     {
27216       if (TREE_CODE (*node) == TYPE_DECL)
27217         type = &TREE_TYPE (*node);
27218     }
27219   else
27220     type = node;
27221
27222   if (!(type && (TREE_CODE (*type) == RECORD_TYPE
27223                  || TREE_CODE (*type) == UNION_TYPE)))
27224     {
27225       warning (OPT_Wattributes, "%qE attribute ignored",
27226                name);
27227       *no_add_attrs = true;
27228     }
27229
27230   else if ((is_attribute_p ("ms_struct", name)
27231             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
27232            || ((is_attribute_p ("gcc_struct", name)
27233                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
27234     {
27235       warning (OPT_Wattributes, "%qE incompatible attribute ignored",
27236                name);
27237       *no_add_attrs = true;
27238     }
27239
27240   return NULL_TREE;
27241 }
27242
27243 static bool
27244 ix86_ms_bitfield_layout_p (const_tree record_type)
27245 {
27246   return (TARGET_MS_BITFIELD_LAYOUT &&
27247           !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
27248     || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
27249 }
27250
27251 /* Returns an expression indicating where the this parameter is
27252    located on entry to the FUNCTION.  */
27253
27254 static rtx
27255 x86_this_parameter (tree function)
27256 {
27257   tree type = TREE_TYPE (function);
27258   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
27259   int nregs;
27260
27261   if (TARGET_64BIT)
27262     {
27263       const int *parm_regs;
27264
27265       if (ix86_function_type_abi (type) == MS_ABI)
27266         parm_regs = x86_64_ms_abi_int_parameter_registers;
27267       else
27268         parm_regs = x86_64_int_parameter_registers;
27269       return gen_rtx_REG (DImode, parm_regs[aggr]);
27270     }
27271
27272   nregs = ix86_function_regparm (type, function);
27273
27274   if (nregs > 0 && !stdarg_p (type))
27275     {
27276       int regno;
27277
27278       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
27279         regno = aggr ? DX_REG : CX_REG;
27280       else
27281         {
27282           regno = AX_REG;
27283           if (aggr)
27284             {
27285               regno = DX_REG;
27286               if (nregs == 1)
27287                 return gen_rtx_MEM (SImode,
27288                                     plus_constant (stack_pointer_rtx, 4));
27289             }
27290         }
27291       return gen_rtx_REG (SImode, regno);
27292     }
27293
27294   return gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx, aggr ? 8 : 4));
27295 }
27296
27297 /* Determine whether x86_output_mi_thunk can succeed.  */
27298
27299 static bool
27300 x86_can_output_mi_thunk (const_tree thunk ATTRIBUTE_UNUSED,
27301                          HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
27302                          HOST_WIDE_INT vcall_offset, const_tree function)
27303 {
27304   /* 64-bit can handle anything.  */
27305   if (TARGET_64BIT)
27306     return true;
27307
27308   /* For 32-bit, everything's fine if we have one free register.  */
27309   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
27310     return true;
27311
27312   /* Need a free register for vcall_offset.  */
27313   if (vcall_offset)
27314     return false;
27315
27316   /* Need a free register for GOT references.  */
27317   if (flag_pic && !(*targetm.binds_local_p) (function))
27318     return false;
27319
27320   /* Otherwise ok.  */
27321   return true;
27322 }
27323
27324 /* Output the assembler code for a thunk function.  THUNK_DECL is the
27325    declaration for the thunk function itself, FUNCTION is the decl for
27326    the target function.  DELTA is an immediate constant offset to be
27327    added to THIS.  If VCALL_OFFSET is nonzero, the word at
27328    *(*this + vcall_offset) should be added to THIS.  */
27329
27330 static void
27331 x86_output_mi_thunk (FILE *file ATTRIBUTE_UNUSED,
27332                      tree thunk ATTRIBUTE_UNUSED, HOST_WIDE_INT delta,
27333                      HOST_WIDE_INT vcall_offset, tree function)
27334 {
27335   rtx xops[3];
27336   rtx this_param = x86_this_parameter (function);
27337   rtx this_reg, tmp;
27338
27339   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
27340      pull it in now and let DELTA benefit.  */
27341   if (REG_P (this_param))
27342     this_reg = this_param;
27343   else if (vcall_offset)
27344     {
27345       /* Put the this parameter into %eax.  */
27346       xops[0] = this_param;
27347       xops[1] = this_reg = gen_rtx_REG (Pmode, AX_REG);
27348       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
27349     }
27350   else
27351     this_reg = NULL_RTX;
27352
27353   /* Adjust the this parameter by a fixed constant.  */
27354   if (delta)
27355     {
27356       xops[0] = GEN_INT (delta);
27357       xops[1] = this_reg ? this_reg : this_param;
27358       if (TARGET_64BIT)
27359         {
27360           if (!x86_64_general_operand (xops[0], DImode))
27361             {
27362               tmp = gen_rtx_REG (DImode, R10_REG);
27363               xops[1] = tmp;
27364               output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", xops);
27365               xops[0] = tmp;
27366               xops[1] = this_param;
27367             }
27368           output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
27369         }
27370       else
27371         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
27372     }
27373
27374   /* Adjust the this parameter by a value stored in the vtable.  */
27375   if (vcall_offset)
27376     {
27377       if (TARGET_64BIT)
27378         tmp = gen_rtx_REG (DImode, R10_REG);
27379       else
27380         {
27381           int tmp_regno = CX_REG;
27382           if (lookup_attribute ("fastcall",
27383                                 TYPE_ATTRIBUTES (TREE_TYPE (function))))
27384             tmp_regno = AX_REG;
27385           tmp = gen_rtx_REG (SImode, tmp_regno);
27386         }
27387
27388       xops[0] = gen_rtx_MEM (Pmode, this_reg);
27389       xops[1] = tmp;
27390       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
27391
27392       /* Adjust the this parameter.  */
27393       xops[0] = gen_rtx_MEM (Pmode, plus_constant (tmp, vcall_offset));
27394       if (TARGET_64BIT && !memory_operand (xops[0], Pmode))
27395         {
27396           rtx tmp2 = gen_rtx_REG (DImode, R11_REG);
27397           xops[0] = GEN_INT (vcall_offset);
27398           xops[1] = tmp2;
27399           output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
27400           xops[0] = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, tmp, tmp2));
27401         }
27402       xops[1] = this_reg;
27403       output_asm_insn ("add%z1\t{%0, %1|%1, %0}", xops);
27404     }
27405
27406   /* If necessary, drop THIS back to its stack slot.  */
27407   if (this_reg && this_reg != this_param)
27408     {
27409       xops[0] = this_reg;
27410       xops[1] = this_param;
27411       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
27412     }
27413
27414   xops[0] = XEXP (DECL_RTL (function), 0);
27415   if (TARGET_64BIT)
27416     {
27417       if (!flag_pic || (*targetm.binds_local_p) (function))
27418         output_asm_insn ("jmp\t%P0", xops);
27419       /* All thunks should be in the same object as their target,
27420          and thus binds_local_p should be true.  */
27421       else if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
27422         gcc_unreachable ();
27423       else
27424         {
27425           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xops[0]), UNSPEC_GOTPCREL);
27426           tmp = gen_rtx_CONST (Pmode, tmp);
27427           tmp = gen_rtx_MEM (QImode, tmp);
27428           xops[0] = tmp;
27429           output_asm_insn ("jmp\t%A0", xops);
27430         }
27431     }
27432   else
27433     {
27434       if (!flag_pic || (*targetm.binds_local_p) (function))
27435         output_asm_insn ("jmp\t%P0", xops);
27436       else
27437 #if TARGET_MACHO
27438         if (TARGET_MACHO)
27439           {
27440             rtx sym_ref = XEXP (DECL_RTL (function), 0);
27441             tmp = (gen_rtx_SYMBOL_REF
27442                    (Pmode,
27443                     machopic_indirection_name (sym_ref, /*stub_p=*/true)));
27444             tmp = gen_rtx_MEM (QImode, tmp);
27445             xops[0] = tmp;
27446             output_asm_insn ("jmp\t%0", xops);
27447           }
27448         else
27449 #endif /* TARGET_MACHO */
27450         {
27451           tmp = gen_rtx_REG (SImode, CX_REG);
27452           output_set_got (tmp, NULL_RTX);
27453
27454           xops[1] = tmp;
27455           output_asm_insn ("mov{l}\t{%0@GOT(%1), %1|%1, %0@GOT[%1]}", xops);
27456           output_asm_insn ("jmp\t{*}%1", xops);
27457         }
27458     }
27459 }
27460
27461 static void
27462 x86_file_start (void)
27463 {
27464   default_file_start ();
27465 #if TARGET_MACHO
27466   darwin_file_start ();
27467 #endif
27468   if (X86_FILE_START_VERSION_DIRECTIVE)
27469     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
27470   if (X86_FILE_START_FLTUSED)
27471     fputs ("\t.global\t__fltused\n", asm_out_file);
27472   if (ix86_asm_dialect == ASM_INTEL)
27473     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
27474 }
27475
27476 int
27477 x86_field_alignment (tree field, int computed)
27478 {
27479   enum machine_mode mode;
27480   tree type = TREE_TYPE (field);
27481
27482   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
27483     return computed;
27484   mode = TYPE_MODE (strip_array_types (type));
27485   if (mode == DFmode || mode == DCmode
27486       || GET_MODE_CLASS (mode) == MODE_INT
27487       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
27488     return MIN (32, computed);
27489   return computed;
27490 }
27491
27492 /* Output assembler code to FILE to increment profiler label # LABELNO
27493    for profiling a function entry.  */
27494 void
27495 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
27496 {
27497   if (TARGET_64BIT)
27498     {
27499 #ifndef NO_PROFILE_COUNTERS
27500       fprintf (file, "\tleaq\t" LPREFIX "P%d@(%%rip),%%r11\n", labelno);
27501 #endif
27502
27503       if (DEFAULT_ABI == SYSV_ABI && flag_pic)
27504         fputs ("\tcall\t*" MCOUNT_NAME "@GOTPCREL(%rip)\n", file);
27505       else
27506         fputs ("\tcall\t" MCOUNT_NAME "\n", file);
27507     }
27508   else if (flag_pic)
27509     {
27510 #ifndef NO_PROFILE_COUNTERS
27511       fprintf (file, "\tleal\t" LPREFIX "P%d@GOTOFF(%%ebx),%%" PROFILE_COUNT_REGISTER "\n",
27512                labelno);
27513 #endif
27514       fputs ("\tcall\t*" MCOUNT_NAME "@GOT(%ebx)\n", file);
27515     }
27516   else
27517     {
27518 #ifndef NO_PROFILE_COUNTERS
27519       fprintf (file, "\tmovl\t$" LPREFIX "P%d,%%" PROFILE_COUNT_REGISTER "\n",
27520                labelno);
27521 #endif
27522       fputs ("\tcall\t" MCOUNT_NAME "\n", file);
27523     }
27524 }
27525
27526 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
27527 /* We don't have exact information about the insn sizes, but we may assume
27528    quite safely that we are informed about all 1 byte insns and memory
27529    address sizes.  This is enough to eliminate unnecessary padding in
27530    99% of cases.  */
27531
27532 static int
27533 min_insn_size (rtx insn)
27534 {
27535   int l = 0, len;
27536
27537   if (!INSN_P (insn) || !active_insn_p (insn))
27538     return 0;
27539
27540   /* Discard alignments we've emit and jump instructions.  */
27541   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
27542       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
27543     return 0;
27544   if (JUMP_TABLE_DATA_P (insn))
27545     return 0;
27546
27547   /* Important case - calls are always 5 bytes.
27548      It is common to have many calls in the row.  */
27549   if (CALL_P (insn)
27550       && symbolic_reference_mentioned_p (PATTERN (insn))
27551       && !SIBLING_CALL_P (insn))
27552     return 5;
27553   len = get_attr_length (insn);
27554   if (len <= 1)
27555     return 1;
27556
27557   /* For normal instructions we rely on get_attr_length being exact,
27558      with a few exceptions.  */
27559   if (!JUMP_P (insn))
27560     {
27561       enum attr_type type = get_attr_type (insn);
27562
27563       switch (type)
27564         {
27565         case TYPE_MULTI:
27566           if (GET_CODE (PATTERN (insn)) == ASM_INPUT
27567               || asm_noperands (PATTERN (insn)) >= 0)
27568             return 0;
27569           break;
27570         case TYPE_OTHER:
27571         case TYPE_FCMP:
27572           break;
27573         default:
27574           /* Otherwise trust get_attr_length.  */
27575           return len;
27576         }
27577
27578       l = get_attr_length_address (insn);
27579       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
27580         l = 4;
27581     }
27582   if (l)
27583     return 1+l;
27584   else
27585     return 2;
27586 }
27587
27588 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
27589    window.  */
27590
27591 static void
27592 ix86_avoid_jump_mispredicts (void)
27593 {
27594   rtx insn, start = get_insns ();
27595   int nbytes = 0, njumps = 0;
27596   int isjump = 0;
27597
27598   /* Look for all minimal intervals of instructions containing 4 jumps.
27599      The intervals are bounded by START and INSN.  NBYTES is the total
27600      size of instructions in the interval including INSN and not including
27601      START.  When the NBYTES is smaller than 16 bytes, it is possible
27602      that the end of START and INSN ends up in the same 16byte page.
27603
27604      The smallest offset in the page INSN can start is the case where START
27605      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
27606      We add p2align to 16byte window with maxskip 15 - NBYTES + sizeof (INSN).
27607      */
27608   for (insn = start; insn; insn = NEXT_INSN (insn))
27609     {
27610       int min_size;
27611
27612       if (LABEL_P (insn))
27613         {
27614           int align = label_to_alignment (insn);
27615           int max_skip = label_to_max_skip (insn);
27616
27617           if (max_skip > 15)
27618             max_skip = 15;
27619           /* If align > 3, only up to 16 - max_skip - 1 bytes can be
27620              already in the current 16 byte page, because otherwise
27621              ASM_OUTPUT_MAX_SKIP_ALIGN could skip max_skip or fewer
27622              bytes to reach 16 byte boundary.  */
27623           if (align <= 0
27624               || (align <= 3 && max_skip != (1 << align) - 1))
27625             max_skip = 0;
27626           if (dump_file)
27627             fprintf (dump_file, "Label %i with max_skip %i\n",
27628                      INSN_UID (insn), max_skip);
27629           if (max_skip)
27630             {
27631               while (nbytes + max_skip >= 16)
27632                 {
27633                   start = NEXT_INSN (start);
27634                   if ((JUMP_P (start)
27635                        && GET_CODE (PATTERN (start)) != ADDR_VEC
27636                        && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
27637                       || CALL_P (start))
27638                     njumps--, isjump = 1;
27639                   else
27640                     isjump = 0;
27641                   nbytes -= min_insn_size (start);
27642                 }
27643             }
27644           continue;
27645         }
27646
27647       min_size = min_insn_size (insn);
27648       nbytes += min_size;
27649       if (dump_file)
27650         fprintf (dump_file, "Insn %i estimated to %i bytes\n",
27651                  INSN_UID (insn), min_size);
27652       if ((JUMP_P (insn)
27653            && GET_CODE (PATTERN (insn)) != ADDR_VEC
27654            && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
27655           || CALL_P (insn))
27656         njumps++;
27657       else
27658         continue;
27659
27660       while (njumps > 3)
27661         {
27662           start = NEXT_INSN (start);
27663           if ((JUMP_P (start)
27664                && GET_CODE (PATTERN (start)) != ADDR_VEC
27665                && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
27666               || CALL_P (start))
27667             njumps--, isjump = 1;
27668           else
27669             isjump = 0;
27670           nbytes -= min_insn_size (start);
27671         }
27672       gcc_assert (njumps >= 0);
27673       if (dump_file)
27674         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
27675                  INSN_UID (start), INSN_UID (insn), nbytes);
27676
27677       if (njumps == 3 && isjump && nbytes < 16)
27678         {
27679           int padsize = 15 - nbytes + min_insn_size (insn);
27680
27681           if (dump_file)
27682             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
27683                      INSN_UID (insn), padsize);
27684           emit_insn_before (gen_pad (GEN_INT (padsize)), insn);
27685         }
27686     }
27687 }
27688 #endif
27689
27690 /* AMD Athlon works faster
27691    when RET is not destination of conditional jump or directly preceded
27692    by other jump instruction.  We avoid the penalty by inserting NOP just
27693    before the RET instructions in such cases.  */
27694 static void
27695 ix86_pad_returns (void)
27696 {
27697   edge e;
27698   edge_iterator ei;
27699
27700   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
27701     {
27702       basic_block bb = e->src;
27703       rtx ret = BB_END (bb);
27704       rtx prev;
27705       bool replace = false;
27706
27707       if (!JUMP_P (ret) || GET_CODE (PATTERN (ret)) != RETURN
27708           || optimize_bb_for_size_p (bb))
27709         continue;
27710       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
27711         if (active_insn_p (prev) || LABEL_P (prev))
27712           break;
27713       if (prev && LABEL_P (prev))
27714         {
27715           edge e;
27716           edge_iterator ei;
27717
27718           FOR_EACH_EDGE (e, ei, bb->preds)
27719             if (EDGE_FREQUENCY (e) && e->src->index >= 0
27720                 && !(e->flags & EDGE_FALLTHRU))
27721               replace = true;
27722         }
27723       if (!replace)
27724         {
27725           prev = prev_active_insn (ret);
27726           if (prev
27727               && ((JUMP_P (prev) && any_condjump_p (prev))
27728                   || CALL_P (prev)))
27729             replace = true;
27730           /* Empty functions get branch mispredict even when the jump destination
27731              is not visible to us.  */
27732           if (!prev && cfun->function_frequency > FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
27733             replace = true;
27734         }
27735       if (replace)
27736         {
27737           emit_jump_insn_before (gen_return_internal_long (), ret);
27738           delete_insn (ret);
27739         }
27740     }
27741 }
27742
27743 /* Implement machine specific optimizations.  We implement padding of returns
27744    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
27745 static void
27746 ix86_reorg (void)
27747 {
27748   if (optimize && optimize_function_for_speed_p (cfun))
27749     {
27750       if (TARGET_PAD_RETURNS)
27751         ix86_pad_returns ();
27752 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
27753       if (TARGET_FOUR_JUMP_LIMIT)
27754         ix86_avoid_jump_mispredicts ();
27755 #endif
27756     }
27757 }
27758
27759 /* Return nonzero when QImode register that must be represented via REX prefix
27760    is used.  */
27761 bool
27762 x86_extended_QIreg_mentioned_p (rtx insn)
27763 {
27764   int i;
27765   extract_insn_cached (insn);
27766   for (i = 0; i < recog_data.n_operands; i++)
27767     if (REG_P (recog_data.operand[i])
27768         && REGNO (recog_data.operand[i]) > BX_REG)
27769        return true;
27770   return false;
27771 }
27772
27773 /* Return nonzero when P points to register encoded via REX prefix.
27774    Called via for_each_rtx.  */
27775 static int
27776 extended_reg_mentioned_1 (rtx *p, void *data ATTRIBUTE_UNUSED)
27777 {
27778    unsigned int regno;
27779    if (!REG_P (*p))
27780      return 0;
27781    regno = REGNO (*p);
27782    return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
27783 }
27784
27785 /* Return true when INSN mentions register that must be encoded using REX
27786    prefix.  */
27787 bool
27788 x86_extended_reg_mentioned_p (rtx insn)
27789 {
27790   return for_each_rtx (INSN_P (insn) ? &PATTERN (insn) : &insn,
27791                        extended_reg_mentioned_1, NULL);
27792 }
27793
27794 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
27795    optabs would emit if we didn't have TFmode patterns.  */
27796
27797 void
27798 x86_emit_floatuns (rtx operands[2])
27799 {
27800   rtx neglab, donelab, i0, i1, f0, in, out;
27801   enum machine_mode mode, inmode;
27802
27803   inmode = GET_MODE (operands[1]);
27804   gcc_assert (inmode == SImode || inmode == DImode);
27805
27806   out = operands[0];
27807   in = force_reg (inmode, operands[1]);
27808   mode = GET_MODE (out);
27809   neglab = gen_label_rtx ();
27810   donelab = gen_label_rtx ();
27811   f0 = gen_reg_rtx (mode);
27812
27813   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
27814
27815   expand_float (out, in, 0);
27816
27817   emit_jump_insn (gen_jump (donelab));
27818   emit_barrier ();
27819
27820   emit_label (neglab);
27821
27822   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
27823                             1, OPTAB_DIRECT);
27824   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
27825                             1, OPTAB_DIRECT);
27826   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
27827
27828   expand_float (f0, i0, 0);
27829
27830   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
27831
27832   emit_label (donelab);
27833 }
27834 \f
27835 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
27836    with all elements equal to VAR.  Return true if successful.  */
27837
27838 static bool
27839 ix86_expand_vector_init_duplicate (bool mmx_ok, enum machine_mode mode,
27840                                    rtx target, rtx val)
27841 {
27842   enum machine_mode hmode, smode, wsmode, wvmode;
27843   rtx x;
27844
27845   switch (mode)
27846     {
27847     case V2SImode:
27848     case V2SFmode:
27849       if (!mmx_ok)
27850         return false;
27851       /* FALLTHRU */
27852
27853     case V2DFmode:
27854     case V2DImode:
27855     case V4SFmode:
27856     case V4SImode:
27857       val = force_reg (GET_MODE_INNER (mode), val);
27858       x = gen_rtx_VEC_DUPLICATE (mode, val);
27859       emit_insn (gen_rtx_SET (VOIDmode, target, x));
27860       return true;
27861
27862     case V4HImode:
27863       if (!mmx_ok)
27864         return false;
27865       if (TARGET_SSE || TARGET_3DNOW_A)
27866         {
27867           val = gen_lowpart (SImode, val);
27868           x = gen_rtx_TRUNCATE (HImode, val);
27869           x = gen_rtx_VEC_DUPLICATE (mode, x);
27870           emit_insn (gen_rtx_SET (VOIDmode, target, x));
27871           return true;
27872         }
27873       else
27874         {
27875           smode = HImode;
27876           wsmode = SImode;
27877           wvmode = V2SImode;
27878           goto widen;
27879         }
27880
27881     case V8QImode:
27882       if (!mmx_ok)
27883         return false;
27884       smode = QImode;
27885       wsmode = HImode;
27886       wvmode = V4HImode;
27887       goto widen;
27888     case V8HImode:
27889       if (TARGET_SSE2)
27890         {
27891           rtx tmp1, tmp2;
27892           /* Extend HImode to SImode using a paradoxical SUBREG.  */
27893           tmp1 = gen_reg_rtx (SImode);
27894           emit_move_insn (tmp1, gen_lowpart (SImode, val));
27895           /* Insert the SImode value as low element of V4SImode vector. */
27896           tmp2 = gen_reg_rtx (V4SImode);
27897           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
27898                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
27899                                     CONST0_RTX (V4SImode),
27900                                     const1_rtx);
27901           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
27902           /* Cast the V4SImode vector back to a V8HImode vector.  */
27903           tmp1 = gen_reg_rtx (V8HImode);
27904           emit_move_insn (tmp1, gen_lowpart (V8HImode, tmp2));
27905           /* Duplicate the low short through the whole low SImode word.  */
27906           emit_insn (gen_sse2_punpcklwd (tmp1, tmp1, tmp1));
27907           /* Cast the V8HImode vector back to a V4SImode vector.  */
27908           tmp2 = gen_reg_rtx (V4SImode);
27909           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
27910           /* Replicate the low element of the V4SImode vector.  */
27911           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
27912           /* Cast the V2SImode back to V8HImode, and store in target.  */
27913           emit_move_insn (target, gen_lowpart (V8HImode, tmp2));
27914           return true;
27915         }
27916       smode = HImode;
27917       wsmode = SImode;
27918       wvmode = V4SImode;
27919       goto widen;
27920     case V16QImode:
27921       if (TARGET_SSE2)
27922         {
27923           rtx tmp1, tmp2;
27924           /* Extend QImode to SImode using a paradoxical SUBREG.  */
27925           tmp1 = gen_reg_rtx (SImode);
27926           emit_move_insn (tmp1, gen_lowpart (SImode, val));
27927           /* Insert the SImode value as low element of V4SImode vector. */
27928           tmp2 = gen_reg_rtx (V4SImode);
27929           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
27930                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
27931                                     CONST0_RTX (V4SImode),
27932                                     const1_rtx);
27933           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
27934           /* Cast the V4SImode vector back to a V16QImode vector.  */
27935           tmp1 = gen_reg_rtx (V16QImode);
27936           emit_move_insn (tmp1, gen_lowpart (V16QImode, tmp2));
27937           /* Duplicate the low byte through the whole low SImode word.  */
27938           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
27939           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
27940           /* Cast the V16QImode vector back to a V4SImode vector.  */
27941           tmp2 = gen_reg_rtx (V4SImode);
27942           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
27943           /* Replicate the low element of the V4SImode vector.  */
27944           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
27945           /* Cast the V2SImode back to V16QImode, and store in target.  */
27946           emit_move_insn (target, gen_lowpart (V16QImode, tmp2));
27947           return true;
27948         }
27949       smode = QImode;
27950       wsmode = HImode;
27951       wvmode = V8HImode;
27952       goto widen;
27953     widen:
27954       /* Replicate the value once into the next wider mode and recurse.  */
27955       val = convert_modes (wsmode, smode, val, true);
27956       x = expand_simple_binop (wsmode, ASHIFT, val,
27957                                GEN_INT (GET_MODE_BITSIZE (smode)),
27958                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
27959       val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
27960
27961       x = gen_reg_rtx (wvmode);
27962       if (!ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val))
27963         gcc_unreachable ();
27964       emit_move_insn (target, gen_lowpart (mode, x));
27965       return true;
27966
27967     case V4DFmode:
27968       hmode = V2DFmode;
27969       goto half;
27970     case V4DImode:
27971       hmode = V2DImode;
27972       goto half;
27973     case V8SFmode:
27974       hmode = V4SFmode;
27975       goto half;
27976     case V8SImode:
27977       hmode = V4SImode;
27978       goto half;
27979     case V16HImode:
27980       hmode = V8HImode;
27981       goto half;
27982     case V32QImode:
27983       hmode = V16QImode;
27984       goto half;
27985 half:
27986       {
27987         rtx tmp = gen_reg_rtx (hmode);
27988         ix86_expand_vector_init_duplicate (mmx_ok, hmode, tmp, val);
27989         emit_insn (gen_rtx_SET (VOIDmode, target,
27990                                 gen_rtx_VEC_CONCAT (mode, tmp, tmp)));
27991       }
27992       return true;
27993
27994     default:
27995       return false;
27996     }
27997 }
27998
27999 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
28000    whose ONE_VAR element is VAR, and other elements are zero.  Return true
28001    if successful.  */
28002
28003 static bool
28004 ix86_expand_vector_init_one_nonzero (bool mmx_ok, enum machine_mode mode,
28005                                      rtx target, rtx var, int one_var)
28006 {
28007   enum machine_mode vsimode;
28008   rtx new_target;
28009   rtx x, tmp;
28010   bool use_vector_set = false;
28011
28012   switch (mode)
28013     {
28014     case V2DImode:
28015       /* For SSE4.1, we normally use vector set.  But if the second
28016          element is zero and inter-unit moves are OK, we use movq
28017          instead.  */
28018       use_vector_set = (TARGET_64BIT
28019                         && TARGET_SSE4_1
28020                         && !(TARGET_INTER_UNIT_MOVES
28021                              && one_var == 0));
28022       break;
28023     case V16QImode:
28024     case V4SImode:
28025     case V4SFmode:
28026       use_vector_set = TARGET_SSE4_1;
28027       break;
28028     case V8HImode:
28029       use_vector_set = TARGET_SSE2;
28030       break;
28031     case V4HImode:
28032       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
28033       break;
28034     case V32QImode:
28035     case V16HImode:
28036     case V8SImode:
28037     case V8SFmode:
28038     case V4DFmode:
28039       use_vector_set = TARGET_AVX;
28040       break;
28041     case V4DImode:
28042       /* Use ix86_expand_vector_set in 64bit mode only.  */
28043       use_vector_set = TARGET_AVX && TARGET_64BIT;
28044       break;
28045     default:
28046       break;
28047     }
28048
28049   if (use_vector_set)
28050     {
28051       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
28052       var = force_reg (GET_MODE_INNER (mode), var);
28053       ix86_expand_vector_set (mmx_ok, target, var, one_var);
28054       return true; 
28055     }
28056
28057   switch (mode)
28058     {
28059     case V2SFmode:
28060     case V2SImode:
28061       if (!mmx_ok)
28062         return false;
28063       /* FALLTHRU */
28064
28065     case V2DFmode:
28066     case V2DImode:
28067       if (one_var != 0)
28068         return false;
28069       var = force_reg (GET_MODE_INNER (mode), var);
28070       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
28071       emit_insn (gen_rtx_SET (VOIDmode, target, x));
28072       return true;
28073
28074     case V4SFmode:
28075     case V4SImode:
28076       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
28077         new_target = gen_reg_rtx (mode);
28078       else
28079         new_target = target;
28080       var = force_reg (GET_MODE_INNER (mode), var);
28081       x = gen_rtx_VEC_DUPLICATE (mode, var);
28082       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
28083       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
28084       if (one_var != 0)
28085         {
28086           /* We need to shuffle the value to the correct position, so
28087              create a new pseudo to store the intermediate result.  */
28088
28089           /* With SSE2, we can use the integer shuffle insns.  */
28090           if (mode != V4SFmode && TARGET_SSE2)
28091             {
28092               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
28093                                             const1_rtx,
28094                                             GEN_INT (one_var == 1 ? 0 : 1),
28095                                             GEN_INT (one_var == 2 ? 0 : 1),
28096                                             GEN_INT (one_var == 3 ? 0 : 1)));
28097               if (target != new_target)
28098                 emit_move_insn (target, new_target);
28099               return true;
28100             }
28101
28102           /* Otherwise convert the intermediate result to V4SFmode and
28103              use the SSE1 shuffle instructions.  */
28104           if (mode != V4SFmode)
28105             {
28106               tmp = gen_reg_rtx (V4SFmode);
28107               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
28108             }
28109           else
28110             tmp = new_target;
28111
28112           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
28113                                        const1_rtx,
28114                                        GEN_INT (one_var == 1 ? 0 : 1),
28115                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
28116                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
28117
28118           if (mode != V4SFmode)
28119             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
28120           else if (tmp != target)
28121             emit_move_insn (target, tmp);
28122         }
28123       else if (target != new_target)
28124         emit_move_insn (target, new_target);
28125       return true;
28126
28127     case V8HImode:
28128     case V16QImode:
28129       vsimode = V4SImode;
28130       goto widen;
28131     case V4HImode:
28132     case V8QImode:
28133       if (!mmx_ok)
28134         return false;
28135       vsimode = V2SImode;
28136       goto widen;
28137     widen:
28138       if (one_var != 0)
28139         return false;
28140
28141       /* Zero extend the variable element to SImode and recurse.  */
28142       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
28143
28144       x = gen_reg_rtx (vsimode);
28145       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
28146                                                 var, one_var))
28147         gcc_unreachable ();
28148
28149       emit_move_insn (target, gen_lowpart (mode, x));
28150       return true;
28151
28152     default:
28153       return false;
28154     }
28155 }
28156
28157 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
28158    consisting of the values in VALS.  It is known that all elements
28159    except ONE_VAR are constants.  Return true if successful.  */
28160
28161 static bool
28162 ix86_expand_vector_init_one_var (bool mmx_ok, enum machine_mode mode,
28163                                  rtx target, rtx vals, int one_var)
28164 {
28165   rtx var = XVECEXP (vals, 0, one_var);
28166   enum machine_mode wmode;
28167   rtx const_vec, x;
28168
28169   const_vec = copy_rtx (vals);
28170   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
28171   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
28172
28173   switch (mode)
28174     {
28175     case V2DFmode:
28176     case V2DImode:
28177     case V2SFmode:
28178     case V2SImode:
28179       /* For the two element vectors, it's just as easy to use
28180          the general case.  */
28181       return false;
28182
28183     case V4DImode:
28184       /* Use ix86_expand_vector_set in 64bit mode only.  */
28185       if (!TARGET_64BIT)
28186         return false;
28187     case V4DFmode:
28188     case V8SFmode:
28189     case V8SImode:
28190     case V16HImode:
28191     case V32QImode:
28192     case V4SFmode:
28193     case V4SImode:
28194     case V8HImode:
28195     case V4HImode:
28196       break;
28197
28198     case V16QImode:
28199       if (TARGET_SSE4_1)
28200         break;
28201       wmode = V8HImode;
28202       goto widen;
28203     case V8QImode:
28204       wmode = V4HImode;
28205       goto widen;
28206     widen:
28207       /* There's no way to set one QImode entry easily.  Combine
28208          the variable value with its adjacent constant value, and
28209          promote to an HImode set.  */
28210       x = XVECEXP (vals, 0, one_var ^ 1);
28211       if (one_var & 1)
28212         {
28213           var = convert_modes (HImode, QImode, var, true);
28214           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
28215                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
28216           x = GEN_INT (INTVAL (x) & 0xff);
28217         }
28218       else
28219         {
28220           var = convert_modes (HImode, QImode, var, true);
28221           x = gen_int_mode (INTVAL (x) << 8, HImode);
28222         }
28223       if (x != const0_rtx)
28224         var = expand_simple_binop (HImode, IOR, var, x, var,
28225                                    1, OPTAB_LIB_WIDEN);
28226
28227       x = gen_reg_rtx (wmode);
28228       emit_move_insn (x, gen_lowpart (wmode, const_vec));
28229       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
28230
28231       emit_move_insn (target, gen_lowpart (mode, x));
28232       return true;
28233
28234     default:
28235       return false;
28236     }
28237
28238   emit_move_insn (target, const_vec);
28239   ix86_expand_vector_set (mmx_ok, target, var, one_var);
28240   return true;
28241 }
28242
28243 /* A subroutine of ix86_expand_vector_init_general.  Use vector
28244    concatenate to handle the most general case: all values variable,
28245    and none identical.  */
28246
28247 static void
28248 ix86_expand_vector_init_concat (enum machine_mode mode,
28249                                 rtx target, rtx *ops, int n)
28250 {
28251   enum machine_mode cmode, hmode = VOIDmode;
28252   rtx first[8], second[4];
28253   rtvec v;
28254   int i, j;
28255
28256   switch (n)
28257     {
28258     case 2:
28259       switch (mode)
28260         {
28261         case V8SImode:
28262           cmode = V4SImode;
28263           break;
28264         case V8SFmode:
28265           cmode = V4SFmode;
28266           break;
28267         case V4DImode:
28268           cmode = V2DImode;
28269           break;
28270         case V4DFmode:
28271           cmode = V2DFmode;
28272           break;
28273         case V4SImode:
28274           cmode = V2SImode;
28275           break;
28276         case V4SFmode:
28277           cmode = V2SFmode;
28278           break;
28279         case V2DImode:
28280           cmode = DImode;
28281           break;
28282         case V2SImode:
28283           cmode = SImode;
28284           break;
28285         case V2DFmode:
28286           cmode = DFmode;
28287           break;
28288         case V2SFmode:
28289           cmode = SFmode;
28290           break;
28291         default:
28292           gcc_unreachable ();
28293         }
28294
28295       if (!register_operand (ops[1], cmode))
28296         ops[1] = force_reg (cmode, ops[1]);
28297       if (!register_operand (ops[0], cmode))
28298         ops[0] = force_reg (cmode, ops[0]);
28299       emit_insn (gen_rtx_SET (VOIDmode, target,
28300                               gen_rtx_VEC_CONCAT (mode, ops[0],
28301                                                   ops[1])));
28302       break;
28303
28304     case 4:
28305       switch (mode)
28306         {
28307         case V4DImode:
28308           cmode = V2DImode;
28309           break;
28310         case V4DFmode:
28311           cmode = V2DFmode;
28312           break;
28313         case V4SImode:
28314           cmode = V2SImode;
28315           break;
28316         case V4SFmode:
28317           cmode = V2SFmode;
28318           break;
28319         default:
28320           gcc_unreachable ();
28321         }
28322       goto half;
28323
28324     case 8:
28325       switch (mode)
28326         {
28327         case V8SImode:
28328           cmode = V2SImode;
28329           hmode = V4SImode;
28330           break;
28331         case V8SFmode:
28332           cmode = V2SFmode;
28333           hmode = V4SFmode;
28334           break;
28335         default:
28336           gcc_unreachable ();
28337         }
28338       goto half;
28339
28340 half:
28341       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
28342       i = n - 1;
28343       j = (n >> 1) - 1;
28344       for (; i > 0; i -= 2, j--)
28345         {
28346           first[j] = gen_reg_rtx (cmode);
28347           v = gen_rtvec (2, ops[i - 1], ops[i]);
28348           ix86_expand_vector_init (false, first[j],
28349                                    gen_rtx_PARALLEL (cmode, v));
28350         }
28351
28352       n >>= 1;
28353       if (n > 2)
28354         {
28355           gcc_assert (hmode != VOIDmode);
28356           for (i = j = 0; i < n; i += 2, j++)
28357             {
28358               second[j] = gen_reg_rtx (hmode);
28359               ix86_expand_vector_init_concat (hmode, second [j],
28360                                               &first [i], 2);
28361             }
28362           n >>= 1;
28363           ix86_expand_vector_init_concat (mode, target, second, n);
28364         }
28365       else
28366         ix86_expand_vector_init_concat (mode, target, first, n);
28367       break;
28368
28369     default:
28370       gcc_unreachable ();
28371     }
28372 }
28373
28374 /* A subroutine of ix86_expand_vector_init_general.  Use vector
28375    interleave to handle the most general case: all values variable,
28376    and none identical.  */
28377
28378 static void
28379 ix86_expand_vector_init_interleave (enum machine_mode mode,
28380                                     rtx target, rtx *ops, int n)
28381 {
28382   enum machine_mode first_imode, second_imode, third_imode, inner_mode;
28383   int i, j;
28384   rtx op0, op1;
28385   rtx (*gen_load_even) (rtx, rtx, rtx);
28386   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
28387   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
28388   
28389   switch (mode)
28390     {
28391     case V8HImode:
28392       gen_load_even = gen_vec_setv8hi;
28393       gen_interleave_first_low = gen_vec_interleave_lowv4si;
28394       gen_interleave_second_low = gen_vec_interleave_lowv2di;
28395       inner_mode = HImode;
28396       first_imode = V4SImode;
28397       second_imode = V2DImode;
28398       third_imode = VOIDmode;
28399       break;
28400     case V16QImode:
28401       gen_load_even = gen_vec_setv16qi;
28402       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
28403       gen_interleave_second_low = gen_vec_interleave_lowv4si;
28404       inner_mode = QImode;
28405       first_imode = V8HImode;
28406       second_imode = V4SImode;
28407       third_imode = V2DImode;
28408       break;
28409     default:
28410       gcc_unreachable ();
28411     }
28412      
28413   for (i = 0; i < n; i++)
28414     {
28415       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
28416       op0 = gen_reg_rtx (SImode);
28417       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
28418
28419       /* Insert the SImode value as low element of V4SImode vector. */
28420       op1 = gen_reg_rtx (V4SImode);
28421       op0 = gen_rtx_VEC_MERGE (V4SImode,
28422                                gen_rtx_VEC_DUPLICATE (V4SImode,
28423                                                       op0),
28424                                CONST0_RTX (V4SImode),
28425                                const1_rtx);
28426       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
28427
28428       /* Cast the V4SImode vector back to a vector in orignal mode.  */
28429       op0 = gen_reg_rtx (mode);
28430       emit_move_insn (op0, gen_lowpart (mode, op1));
28431       
28432       /* Load even elements into the second positon.  */
28433       emit_insn ((*gen_load_even) (op0,
28434                                    force_reg (inner_mode,
28435                                               ops [i + i + 1]),
28436                                    const1_rtx));
28437
28438       /* Cast vector to FIRST_IMODE vector.  */
28439       ops[i] = gen_reg_rtx (first_imode);
28440       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
28441     }
28442
28443   /* Interleave low FIRST_IMODE vectors.  */
28444   for (i = j = 0; i < n; i += 2, j++)
28445     {
28446       op0 = gen_reg_rtx (first_imode);
28447       emit_insn ((*gen_interleave_first_low) (op0, ops[i], ops[i + 1]));
28448
28449       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
28450       ops[j] = gen_reg_rtx (second_imode);
28451       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
28452     }
28453
28454   /* Interleave low SECOND_IMODE vectors.  */
28455   switch (second_imode)
28456     {
28457     case V4SImode:
28458       for (i = j = 0; i < n / 2; i += 2, j++)
28459         {
28460           op0 = gen_reg_rtx (second_imode);
28461           emit_insn ((*gen_interleave_second_low) (op0, ops[i],
28462                                                    ops[i + 1]));
28463
28464           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
28465              vector.  */
28466           ops[j] = gen_reg_rtx (third_imode);
28467           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
28468         }
28469       second_imode = V2DImode;
28470       gen_interleave_second_low = gen_vec_interleave_lowv2di;
28471       /* FALLTHRU */
28472
28473     case V2DImode:
28474       op0 = gen_reg_rtx (second_imode);
28475       emit_insn ((*gen_interleave_second_low) (op0, ops[0],
28476                                                ops[1]));
28477
28478       /* Cast the SECOND_IMODE vector back to a vector on original
28479          mode.  */
28480       emit_insn (gen_rtx_SET (VOIDmode, target,
28481                               gen_lowpart (mode, op0)));
28482       break;
28483
28484     default:
28485       gcc_unreachable ();
28486     }
28487 }
28488
28489 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
28490    all values variable, and none identical.  */
28491
28492 static void
28493 ix86_expand_vector_init_general (bool mmx_ok, enum machine_mode mode,
28494                                  rtx target, rtx vals)
28495 {
28496   rtx ops[32], op0, op1;
28497   enum machine_mode half_mode = VOIDmode;
28498   int n, i;
28499
28500   switch (mode)
28501     {
28502     case V2SFmode:
28503     case V2SImode:
28504       if (!mmx_ok && !TARGET_SSE)
28505         break;
28506       /* FALLTHRU */
28507
28508     case V8SFmode:
28509     case V8SImode:
28510     case V4DFmode:
28511     case V4DImode:
28512     case V4SFmode:
28513     case V4SImode:
28514     case V2DFmode:
28515     case V2DImode:
28516       n = GET_MODE_NUNITS (mode);
28517       for (i = 0; i < n; i++)
28518         ops[i] = XVECEXP (vals, 0, i);
28519       ix86_expand_vector_init_concat (mode, target, ops, n);
28520       return;
28521
28522     case V32QImode:
28523       half_mode = V16QImode;
28524       goto half;
28525
28526     case V16HImode:
28527       half_mode = V8HImode;
28528       goto half;
28529
28530 half:
28531       n = GET_MODE_NUNITS (mode);
28532       for (i = 0; i < n; i++)
28533         ops[i] = XVECEXP (vals, 0, i);
28534       op0 = gen_reg_rtx (half_mode);
28535       op1 = gen_reg_rtx (half_mode);
28536       ix86_expand_vector_init_interleave (half_mode, op0, ops,
28537                                           n >> 2);
28538       ix86_expand_vector_init_interleave (half_mode, op1,
28539                                           &ops [n >> 1], n >> 2);
28540       emit_insn (gen_rtx_SET (VOIDmode, target,
28541                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
28542       return;
28543
28544     case V16QImode:
28545       if (!TARGET_SSE4_1)
28546         break;
28547       /* FALLTHRU */
28548
28549     case V8HImode:
28550       if (!TARGET_SSE2)
28551         break;
28552
28553       /* Don't use ix86_expand_vector_init_interleave if we can't
28554          move from GPR to SSE register directly.  */ 
28555       if (!TARGET_INTER_UNIT_MOVES)
28556         break;
28557
28558       n = GET_MODE_NUNITS (mode);
28559       for (i = 0; i < n; i++)
28560         ops[i] = XVECEXP (vals, 0, i);
28561       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
28562       return;
28563
28564     case V4HImode:
28565     case V8QImode:
28566       break;
28567
28568     default:
28569       gcc_unreachable ();
28570     }
28571
28572     {
28573       int i, j, n_elts, n_words, n_elt_per_word;
28574       enum machine_mode inner_mode;
28575       rtx words[4], shift;
28576
28577       inner_mode = GET_MODE_INNER (mode);
28578       n_elts = GET_MODE_NUNITS (mode);
28579       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
28580       n_elt_per_word = n_elts / n_words;
28581       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
28582
28583       for (i = 0; i < n_words; ++i)
28584         {
28585           rtx word = NULL_RTX;
28586
28587           for (j = 0; j < n_elt_per_word; ++j)
28588             {
28589               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
28590               elt = convert_modes (word_mode, inner_mode, elt, true);
28591
28592               if (j == 0)
28593                 word = elt;
28594               else
28595                 {
28596                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
28597                                               word, 1, OPTAB_LIB_WIDEN);
28598                   word = expand_simple_binop (word_mode, IOR, word, elt,
28599                                               word, 1, OPTAB_LIB_WIDEN);
28600                 }
28601             }
28602
28603           words[i] = word;
28604         }
28605
28606       if (n_words == 1)
28607         emit_move_insn (target, gen_lowpart (mode, words[0]));
28608       else if (n_words == 2)
28609         {
28610           rtx tmp = gen_reg_rtx (mode);
28611           emit_clobber (tmp);
28612           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
28613           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
28614           emit_move_insn (target, tmp);
28615         }
28616       else if (n_words == 4)
28617         {
28618           rtx tmp = gen_reg_rtx (V4SImode);
28619           gcc_assert (word_mode == SImode);
28620           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
28621           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
28622           emit_move_insn (target, gen_lowpart (mode, tmp));
28623         }
28624       else
28625         gcc_unreachable ();
28626     }
28627 }
28628
28629 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
28630    instructions unless MMX_OK is true.  */
28631
28632 void
28633 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
28634 {
28635   enum machine_mode mode = GET_MODE (target);
28636   enum machine_mode inner_mode = GET_MODE_INNER (mode);
28637   int n_elts = GET_MODE_NUNITS (mode);
28638   int n_var = 0, one_var = -1;
28639   bool all_same = true, all_const_zero = true;
28640   int i;
28641   rtx x;
28642
28643   for (i = 0; i < n_elts; ++i)
28644     {
28645       x = XVECEXP (vals, 0, i);
28646       if (!(CONST_INT_P (x)
28647             || GET_CODE (x) == CONST_DOUBLE
28648             || GET_CODE (x) == CONST_FIXED))
28649         n_var++, one_var = i;
28650       else if (x != CONST0_RTX (inner_mode))
28651         all_const_zero = false;
28652       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
28653         all_same = false;
28654     }
28655
28656   /* Constants are best loaded from the constant pool.  */
28657   if (n_var == 0)
28658     {
28659       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
28660       return;
28661     }
28662
28663   /* If all values are identical, broadcast the value.  */
28664   if (all_same
28665       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
28666                                             XVECEXP (vals, 0, 0)))
28667     return;
28668
28669   /* Values where only one field is non-constant are best loaded from
28670      the pool and overwritten via move later.  */
28671   if (n_var == 1)
28672     {
28673       if (all_const_zero
28674           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
28675                                                   XVECEXP (vals, 0, one_var),
28676                                                   one_var))
28677         return;
28678
28679       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
28680         return;
28681     }
28682
28683   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
28684 }
28685
28686 void
28687 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
28688 {
28689   enum machine_mode mode = GET_MODE (target);
28690   enum machine_mode inner_mode = GET_MODE_INNER (mode);
28691   enum machine_mode half_mode;
28692   bool use_vec_merge = false;
28693   rtx tmp;
28694   static rtx (*gen_extract[6][2]) (rtx, rtx)
28695     = {
28696         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
28697         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
28698         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
28699         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
28700         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
28701         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
28702       };
28703   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
28704     = {
28705         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
28706         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
28707         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
28708         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
28709         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
28710         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
28711       };
28712   int i, j, n;
28713
28714   switch (mode)
28715     {
28716     case V2SFmode:
28717     case V2SImode:
28718       if (mmx_ok)
28719         {
28720           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
28721           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
28722           if (elt == 0)
28723             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
28724           else
28725             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
28726           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28727           return;
28728         }
28729       break;
28730
28731     case V2DImode:
28732       use_vec_merge = TARGET_SSE4_1;
28733       if (use_vec_merge)
28734         break;
28735
28736     case V2DFmode:
28737       {
28738         rtx op0, op1;
28739
28740         /* For the two element vectors, we implement a VEC_CONCAT with
28741            the extraction of the other element.  */
28742
28743         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
28744         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
28745
28746         if (elt == 0)
28747           op0 = val, op1 = tmp;
28748         else
28749           op0 = tmp, op1 = val;
28750
28751         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
28752         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28753       }
28754       return;
28755
28756     case V4SFmode:
28757       use_vec_merge = TARGET_SSE4_1;
28758       if (use_vec_merge)
28759         break;
28760
28761       switch (elt)
28762         {
28763         case 0:
28764           use_vec_merge = true;
28765           break;
28766
28767         case 1:
28768           /* tmp = target = A B C D */
28769           tmp = copy_to_reg (target);
28770           /* target = A A B B */
28771           emit_insn (gen_sse_unpcklps (target, target, target));
28772           /* target = X A B B */
28773           ix86_expand_vector_set (false, target, val, 0);
28774           /* target = A X C D  */
28775           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
28776                                           const1_rtx, const0_rtx,
28777                                           GEN_INT (2+4), GEN_INT (3+4)));
28778           return;
28779
28780         case 2:
28781           /* tmp = target = A B C D */
28782           tmp = copy_to_reg (target);
28783           /* tmp = X B C D */
28784           ix86_expand_vector_set (false, tmp, val, 0);
28785           /* target = A B X D */
28786           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
28787                                           const0_rtx, const1_rtx,
28788                                           GEN_INT (0+4), GEN_INT (3+4)));
28789           return;
28790
28791         case 3:
28792           /* tmp = target = A B C D */
28793           tmp = copy_to_reg (target);
28794           /* tmp = X B C D */
28795           ix86_expand_vector_set (false, tmp, val, 0);
28796           /* target = A B X D */
28797           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
28798                                           const0_rtx, const1_rtx,
28799                                           GEN_INT (2+4), GEN_INT (0+4)));
28800           return;
28801
28802         default:
28803           gcc_unreachable ();
28804         }
28805       break;
28806
28807     case V4SImode:
28808       use_vec_merge = TARGET_SSE4_1;
28809       if (use_vec_merge)
28810         break;
28811
28812       /* Element 0 handled by vec_merge below.  */
28813       if (elt == 0)
28814         {
28815           use_vec_merge = true;
28816           break;
28817         }
28818
28819       if (TARGET_SSE2)
28820         {
28821           /* With SSE2, use integer shuffles to swap element 0 and ELT,
28822              store into element 0, then shuffle them back.  */
28823
28824           rtx order[4];
28825
28826           order[0] = GEN_INT (elt);
28827           order[1] = const1_rtx;
28828           order[2] = const2_rtx;
28829           order[3] = GEN_INT (3);
28830           order[elt] = const0_rtx;
28831
28832           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
28833                                         order[1], order[2], order[3]));
28834
28835           ix86_expand_vector_set (false, target, val, 0);
28836
28837           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
28838                                         order[1], order[2], order[3]));
28839         }
28840       else
28841         {
28842           /* For SSE1, we have to reuse the V4SF code.  */
28843           ix86_expand_vector_set (false, gen_lowpart (V4SFmode, target),
28844                                   gen_lowpart (SFmode, val), elt);
28845         }
28846       return;
28847
28848     case V8HImode:
28849       use_vec_merge = TARGET_SSE2;
28850       break;
28851     case V4HImode:
28852       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
28853       break;
28854
28855     case V16QImode:
28856       use_vec_merge = TARGET_SSE4_1;
28857       break;
28858
28859     case V8QImode:
28860       break;
28861
28862     case V32QImode:
28863       half_mode = V16QImode;
28864       j = 0;
28865       n = 16;
28866       goto half;
28867
28868     case V16HImode:
28869       half_mode = V8HImode;
28870       j = 1;
28871       n = 8;
28872       goto half;
28873
28874     case V8SImode:
28875       half_mode = V4SImode;
28876       j = 2;
28877       n = 4;
28878       goto half;
28879
28880     case V4DImode:
28881       half_mode = V2DImode;
28882       j = 3;
28883       n = 2;
28884       goto half;
28885
28886     case V8SFmode:
28887       half_mode = V4SFmode;
28888       j = 4;
28889       n = 4;
28890       goto half;
28891
28892     case V4DFmode:
28893       half_mode = V2DFmode;
28894       j = 5;
28895       n = 2;
28896       goto half;
28897
28898 half:
28899       /* Compute offset.  */
28900       i = elt / n;
28901       elt %= n;
28902
28903       gcc_assert (i <= 1);
28904
28905       /* Extract the half.  */
28906       tmp = gen_reg_rtx (half_mode);
28907       emit_insn ((*gen_extract[j][i]) (tmp, target));
28908
28909       /* Put val in tmp at elt.  */
28910       ix86_expand_vector_set (false, tmp, val, elt);
28911
28912       /* Put it back.  */
28913       emit_insn ((*gen_insert[j][i]) (target, target, tmp));
28914       return;
28915
28916     default:
28917       break;
28918     }
28919
28920   if (use_vec_merge)
28921     {
28922       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
28923       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
28924       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28925     }
28926   else
28927     {
28928       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
28929
28930       emit_move_insn (mem, target);
28931
28932       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
28933       emit_move_insn (tmp, val);
28934
28935       emit_move_insn (target, mem);
28936     }
28937 }
28938
28939 void
28940 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
28941 {
28942   enum machine_mode mode = GET_MODE (vec);
28943   enum machine_mode inner_mode = GET_MODE_INNER (mode);
28944   bool use_vec_extr = false;
28945   rtx tmp;
28946
28947   switch (mode)
28948     {
28949     case V2SImode:
28950     case V2SFmode:
28951       if (!mmx_ok)
28952         break;
28953       /* FALLTHRU */
28954
28955     case V2DFmode:
28956     case V2DImode:
28957       use_vec_extr = true;
28958       break;
28959
28960     case V4SFmode:
28961       use_vec_extr = TARGET_SSE4_1;
28962       if (use_vec_extr)
28963         break;
28964
28965       switch (elt)
28966         {
28967         case 0:
28968           tmp = vec;
28969           break;
28970
28971         case 1:
28972         case 3:
28973           tmp = gen_reg_rtx (mode);
28974           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
28975                                        GEN_INT (elt), GEN_INT (elt),
28976                                        GEN_INT (elt+4), GEN_INT (elt+4)));
28977           break;
28978
28979         case 2:
28980           tmp = gen_reg_rtx (mode);
28981           emit_insn (gen_sse_unpckhps (tmp, vec, vec));
28982           break;
28983
28984         default:
28985           gcc_unreachable ();
28986         }
28987       vec = tmp;
28988       use_vec_extr = true;
28989       elt = 0;
28990       break;
28991
28992     case V4SImode:
28993       use_vec_extr = TARGET_SSE4_1;
28994       if (use_vec_extr)
28995         break;
28996
28997       if (TARGET_SSE2)
28998         {
28999           switch (elt)
29000             {
29001             case 0:
29002               tmp = vec;
29003               break;
29004
29005             case 1:
29006             case 3:
29007               tmp = gen_reg_rtx (mode);
29008               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
29009                                             GEN_INT (elt), GEN_INT (elt),
29010                                             GEN_INT (elt), GEN_INT (elt)));
29011               break;
29012
29013             case 2:
29014               tmp = gen_reg_rtx (mode);
29015               emit_insn (gen_sse2_punpckhdq (tmp, vec, vec));
29016               break;
29017
29018             default:
29019               gcc_unreachable ();
29020             }
29021           vec = tmp;
29022           use_vec_extr = true;
29023           elt = 0;
29024         }
29025       else
29026         {
29027           /* For SSE1, we have to reuse the V4SF code.  */
29028           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
29029                                       gen_lowpart (V4SFmode, vec), elt);
29030           return;
29031         }
29032       break;
29033
29034     case V8HImode:
29035       use_vec_extr = TARGET_SSE2;
29036       break;
29037     case V4HImode:
29038       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
29039       break;
29040
29041     case V16QImode:
29042       use_vec_extr = TARGET_SSE4_1;
29043       break;
29044
29045     case V8QImode:
29046       /* ??? Could extract the appropriate HImode element and shift.  */
29047     default:
29048       break;
29049     }
29050
29051   if (use_vec_extr)
29052     {
29053       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
29054       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
29055
29056       /* Let the rtl optimizers know about the zero extension performed.  */
29057       if (inner_mode == QImode || inner_mode == HImode)
29058         {
29059           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
29060           target = gen_lowpart (SImode, target);
29061         }
29062
29063       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
29064     }
29065   else
29066     {
29067       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
29068
29069       emit_move_insn (mem, vec);
29070
29071       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
29072       emit_move_insn (target, tmp);
29073     }
29074 }
29075
29076 /* Expand a vector reduction on V4SFmode for SSE1.  FN is the binary
29077    pattern to reduce; DEST is the destination; IN is the input vector.  */
29078
29079 void
29080 ix86_expand_reduc_v4sf (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
29081 {
29082   rtx tmp1, tmp2, tmp3;
29083
29084   tmp1 = gen_reg_rtx (V4SFmode);
29085   tmp2 = gen_reg_rtx (V4SFmode);
29086   tmp3 = gen_reg_rtx (V4SFmode);
29087
29088   emit_insn (gen_sse_movhlps (tmp1, in, in));
29089   emit_insn (fn (tmp2, tmp1, in));
29090
29091   emit_insn (gen_sse_shufps_v4sf (tmp3, tmp2, tmp2,
29092                                   const1_rtx, const1_rtx,
29093                                   GEN_INT (1+4), GEN_INT (1+4)));
29094   emit_insn (fn (dest, tmp2, tmp3));
29095 }
29096 \f
29097 /* Target hook for scalar_mode_supported_p.  */
29098 static bool
29099 ix86_scalar_mode_supported_p (enum machine_mode mode)
29100 {
29101   if (DECIMAL_FLOAT_MODE_P (mode))
29102     return true;
29103   else if (mode == TFmode)
29104     return true;
29105   else
29106     return default_scalar_mode_supported_p (mode);
29107 }
29108
29109 /* Implements target hook vector_mode_supported_p.  */
29110 static bool
29111 ix86_vector_mode_supported_p (enum machine_mode mode)
29112 {
29113   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
29114     return true;
29115   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
29116     return true;
29117   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
29118     return true;
29119   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
29120     return true;
29121   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
29122     return true;
29123   return false;
29124 }
29125
29126 /* Target hook for c_mode_for_suffix.  */
29127 static enum machine_mode
29128 ix86_c_mode_for_suffix (char suffix)
29129 {
29130   if (suffix == 'q')
29131     return TFmode;
29132   if (suffix == 'w')
29133     return XFmode;
29134
29135   return VOIDmode;
29136 }
29137
29138 /* Worker function for TARGET_MD_ASM_CLOBBERS.
29139
29140    We do this in the new i386 backend to maintain source compatibility
29141    with the old cc0-based compiler.  */
29142
29143 static tree
29144 ix86_md_asm_clobbers (tree outputs ATTRIBUTE_UNUSED,
29145                       tree inputs ATTRIBUTE_UNUSED,
29146                       tree clobbers)
29147 {
29148   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
29149                         clobbers);
29150   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
29151                         clobbers);
29152   return clobbers;
29153 }
29154
29155 /* Implements target vector targetm.asm.encode_section_info.  This
29156    is not used by netware.  */
29157
29158 static void ATTRIBUTE_UNUSED
29159 ix86_encode_section_info (tree decl, rtx rtl, int first)
29160 {
29161   default_encode_section_info (decl, rtl, first);
29162
29163   if (TREE_CODE (decl) == VAR_DECL
29164       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
29165       && ix86_in_large_data_p (decl))
29166     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
29167 }
29168
29169 /* Worker function for REVERSE_CONDITION.  */
29170
29171 enum rtx_code
29172 ix86_reverse_condition (enum rtx_code code, enum machine_mode mode)
29173 {
29174   return (mode != CCFPmode && mode != CCFPUmode
29175           ? reverse_condition (code)
29176           : reverse_condition_maybe_unordered (code));
29177 }
29178
29179 /* Output code to perform an x87 FP register move, from OPERANDS[1]
29180    to OPERANDS[0].  */
29181
29182 const char *
29183 output_387_reg_move (rtx insn, rtx *operands)
29184 {
29185   if (REG_P (operands[0]))
29186     {
29187       if (REG_P (operands[1])
29188           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
29189         {
29190           if (REGNO (operands[0]) == FIRST_STACK_REG)
29191             return output_387_ffreep (operands, 0);
29192           return "fstp\t%y0";
29193         }
29194       if (STACK_TOP_P (operands[0]))
29195         return "fld%Z1\t%y1";
29196       return "fst\t%y0";
29197     }
29198   else if (MEM_P (operands[0]))
29199     {
29200       gcc_assert (REG_P (operands[1]));
29201       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
29202         return "fstp%Z0\t%y0";
29203       else
29204         {
29205           /* There is no non-popping store to memory for XFmode.
29206              So if we need one, follow the store with a load.  */
29207           if (GET_MODE (operands[0]) == XFmode)
29208             return "fstp%Z0\t%y0\n\tfld%Z0\t%y0";
29209           else
29210             return "fst%Z0\t%y0";
29211         }
29212     }
29213   else
29214     gcc_unreachable();
29215 }
29216
29217 /* Output code to perform a conditional jump to LABEL, if C2 flag in
29218    FP status register is set.  */
29219
29220 void
29221 ix86_emit_fp_unordered_jump (rtx label)
29222 {
29223   rtx reg = gen_reg_rtx (HImode);
29224   rtx temp;
29225
29226   emit_insn (gen_x86_fnstsw_1 (reg));
29227
29228   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
29229     {
29230       emit_insn (gen_x86_sahf_1 (reg));
29231
29232       temp = gen_rtx_REG (CCmode, FLAGS_REG);
29233       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
29234     }
29235   else
29236     {
29237       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
29238
29239       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
29240       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
29241     }
29242
29243   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
29244                               gen_rtx_LABEL_REF (VOIDmode, label),
29245                               pc_rtx);
29246   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
29247
29248   emit_jump_insn (temp);
29249   predict_jump (REG_BR_PROB_BASE * 10 / 100);
29250 }
29251
29252 /* Output code to perform a log1p XFmode calculation.  */
29253
29254 void ix86_emit_i387_log1p (rtx op0, rtx op1)
29255 {
29256   rtx label1 = gen_label_rtx ();
29257   rtx label2 = gen_label_rtx ();
29258
29259   rtx tmp = gen_reg_rtx (XFmode);
29260   rtx tmp2 = gen_reg_rtx (XFmode);
29261   rtx test;
29262
29263   emit_insn (gen_absxf2 (tmp, op1));
29264   test = gen_rtx_GE (VOIDmode, tmp,
29265     CONST_DOUBLE_FROM_REAL_VALUE (
29266        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
29267        XFmode));
29268   emit_jump_insn (gen_cbranchxf4 (test, XEXP (test, 0), XEXP (test, 1), label1));
29269
29270   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
29271   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
29272   emit_jump (label2);
29273
29274   emit_label (label1);
29275   emit_move_insn (tmp, CONST1_RTX (XFmode));
29276   emit_insn (gen_addxf3 (tmp, op1, tmp));
29277   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
29278   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
29279
29280   emit_label (label2);
29281 }
29282
29283 /* Output code to perform a Newton-Rhapson approximation of a single precision
29284    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
29285
29286 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, enum machine_mode mode)
29287 {
29288   rtx x0, x1, e0, e1, two;
29289
29290   x0 = gen_reg_rtx (mode);
29291   e0 = gen_reg_rtx (mode);
29292   e1 = gen_reg_rtx (mode);
29293   x1 = gen_reg_rtx (mode);
29294
29295   two = CONST_DOUBLE_FROM_REAL_VALUE (dconst2, SFmode);
29296
29297   if (VECTOR_MODE_P (mode))
29298     two = ix86_build_const_vector (SFmode, true, two);
29299
29300   two = force_reg (mode, two);
29301
29302   /* a / b = a * rcp(b) * (2.0 - b * rcp(b)) */
29303
29304   /* x0 = rcp(b) estimate */
29305   emit_insn (gen_rtx_SET (VOIDmode, x0,
29306                           gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
29307                                           UNSPEC_RCP)));
29308   /* e0 = x0 * b */
29309   emit_insn (gen_rtx_SET (VOIDmode, e0,
29310                           gen_rtx_MULT (mode, x0, b)));
29311   /* e1 = 2. - e0 */
29312   emit_insn (gen_rtx_SET (VOIDmode, e1,
29313                           gen_rtx_MINUS (mode, two, e0)));
29314   /* x1 = x0 * e1 */
29315   emit_insn (gen_rtx_SET (VOIDmode, x1,
29316                           gen_rtx_MULT (mode, x0, e1)));
29317   /* res = a * x1 */
29318   emit_insn (gen_rtx_SET (VOIDmode, res,
29319                           gen_rtx_MULT (mode, a, x1)));
29320 }
29321
29322 /* Output code to perform a Newton-Rhapson approximation of a
29323    single precision floating point [reciprocal] square root.  */
29324
29325 void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
29326                          bool recip)
29327 {
29328   rtx x0, e0, e1, e2, e3, mthree, mhalf;
29329   REAL_VALUE_TYPE r;
29330
29331   x0 = gen_reg_rtx (mode);
29332   e0 = gen_reg_rtx (mode);
29333   e1 = gen_reg_rtx (mode);
29334   e2 = gen_reg_rtx (mode);
29335   e3 = gen_reg_rtx (mode);
29336
29337   real_from_integer (&r, VOIDmode, -3, -1, 0);
29338   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
29339
29340   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
29341   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
29342
29343   if (VECTOR_MODE_P (mode))
29344     {
29345       mthree = ix86_build_const_vector (SFmode, true, mthree);
29346       mhalf = ix86_build_const_vector (SFmode, true, mhalf);
29347     }
29348
29349   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
29350      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
29351
29352   /* x0 = rsqrt(a) estimate */
29353   emit_insn (gen_rtx_SET (VOIDmode, x0,
29354                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
29355                                           UNSPEC_RSQRT)));
29356
29357   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
29358   if (!recip)
29359     {
29360       rtx zero, mask;
29361
29362       zero = gen_reg_rtx (mode);
29363       mask = gen_reg_rtx (mode);
29364
29365       zero = force_reg (mode, CONST0_RTX(mode));
29366       emit_insn (gen_rtx_SET (VOIDmode, mask,
29367                               gen_rtx_NE (mode, zero, a)));
29368
29369       emit_insn (gen_rtx_SET (VOIDmode, x0,
29370                               gen_rtx_AND (mode, x0, mask)));
29371     }
29372
29373   /* e0 = x0 * a */
29374   emit_insn (gen_rtx_SET (VOIDmode, e0,
29375                           gen_rtx_MULT (mode, x0, a)));
29376   /* e1 = e0 * x0 */
29377   emit_insn (gen_rtx_SET (VOIDmode, e1,
29378                           gen_rtx_MULT (mode, e0, x0)));
29379
29380   /* e2 = e1 - 3. */
29381   mthree = force_reg (mode, mthree);
29382   emit_insn (gen_rtx_SET (VOIDmode, e2,
29383                           gen_rtx_PLUS (mode, e1, mthree)));
29384
29385   mhalf = force_reg (mode, mhalf);
29386   if (recip)
29387     /* e3 = -.5 * x0 */
29388     emit_insn (gen_rtx_SET (VOIDmode, e3,
29389                             gen_rtx_MULT (mode, x0, mhalf)));
29390   else
29391     /* e3 = -.5 * e0 */
29392     emit_insn (gen_rtx_SET (VOIDmode, e3,
29393                             gen_rtx_MULT (mode, e0, mhalf)));
29394   /* ret = e2 * e3 */
29395   emit_insn (gen_rtx_SET (VOIDmode, res,
29396                           gen_rtx_MULT (mode, e2, e3)));
29397 }
29398
29399 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
29400
29401 static void ATTRIBUTE_UNUSED
29402 i386_solaris_elf_named_section (const char *name, unsigned int flags,
29403                                 tree decl)
29404 {
29405   /* With Binutils 2.15, the "@unwind" marker must be specified on
29406      every occurrence of the ".eh_frame" section, not just the first
29407      one.  */
29408   if (TARGET_64BIT
29409       && strcmp (name, ".eh_frame") == 0)
29410     {
29411       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
29412                flags & SECTION_WRITE ? "aw" : "a");
29413       return;
29414     }
29415   default_elf_asm_named_section (name, flags, decl);
29416 }
29417
29418 /* Return the mangling of TYPE if it is an extended fundamental type.  */
29419
29420 static const char *
29421 ix86_mangle_type (const_tree type)
29422 {
29423   type = TYPE_MAIN_VARIANT (type);
29424
29425   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
29426       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
29427     return NULL;
29428
29429   switch (TYPE_MODE (type))
29430     {
29431     case TFmode:
29432       /* __float128 is "g".  */
29433       return "g";
29434     case XFmode:
29435       /* "long double" or __float80 is "e".  */
29436       return "e";
29437     default:
29438       return NULL;
29439     }
29440 }
29441
29442 /* For 32-bit code we can save PIC register setup by using
29443    __stack_chk_fail_local hidden function instead of calling
29444    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
29445    register, so it is better to call __stack_chk_fail directly.  */
29446
29447 static tree
29448 ix86_stack_protect_fail (void)
29449 {
29450   return TARGET_64BIT
29451          ? default_external_stack_protect_fail ()
29452          : default_hidden_stack_protect_fail ();
29453 }
29454
29455 /* Select a format to encode pointers in exception handling data.  CODE
29456    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
29457    true if the symbol may be affected by dynamic relocations.
29458
29459    ??? All x86 object file formats are capable of representing this.
29460    After all, the relocation needed is the same as for the call insn.
29461    Whether or not a particular assembler allows us to enter such, I
29462    guess we'll have to see.  */
29463 int
29464 asm_preferred_eh_data_format (int code, int global)
29465 {
29466   if (flag_pic)
29467     {
29468       int type = DW_EH_PE_sdata8;
29469       if (!TARGET_64BIT
29470           || ix86_cmodel == CM_SMALL_PIC
29471           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
29472         type = DW_EH_PE_sdata4;
29473       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
29474     }
29475   if (ix86_cmodel == CM_SMALL
29476       || (ix86_cmodel == CM_MEDIUM && code))
29477     return DW_EH_PE_udata4;
29478   return DW_EH_PE_absptr;
29479 }
29480 \f
29481 /* Expand copysign from SIGN to the positive value ABS_VALUE
29482    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
29483    the sign-bit.  */
29484 static void
29485 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
29486 {
29487   enum machine_mode mode = GET_MODE (sign);
29488   rtx sgn = gen_reg_rtx (mode);
29489   if (mask == NULL_RTX)
29490     {
29491       mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), false);
29492       if (!VECTOR_MODE_P (mode))
29493         {
29494           /* We need to generate a scalar mode mask in this case.  */
29495           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
29496           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
29497           mask = gen_reg_rtx (mode);
29498           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
29499         }
29500     }
29501   else
29502     mask = gen_rtx_NOT (mode, mask);
29503   emit_insn (gen_rtx_SET (VOIDmode, sgn,
29504                           gen_rtx_AND (mode, mask, sign)));
29505   emit_insn (gen_rtx_SET (VOIDmode, result,
29506                           gen_rtx_IOR (mode, abs_value, sgn)));
29507 }
29508
29509 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
29510    mask for masking out the sign-bit is stored in *SMASK, if that is
29511    non-null.  */
29512 static rtx
29513 ix86_expand_sse_fabs (rtx op0, rtx *smask)
29514 {
29515   enum machine_mode mode = GET_MODE (op0);
29516   rtx xa, mask;
29517
29518   xa = gen_reg_rtx (mode);
29519   mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), true);
29520   if (!VECTOR_MODE_P (mode))
29521     {
29522       /* We need to generate a scalar mode mask in this case.  */
29523       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
29524       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
29525       mask = gen_reg_rtx (mode);
29526       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
29527     }
29528   emit_insn (gen_rtx_SET (VOIDmode, xa,
29529                           gen_rtx_AND (mode, op0, mask)));
29530
29531   if (smask)
29532     *smask = mask;
29533
29534   return xa;
29535 }
29536
29537 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
29538    swapping the operands if SWAP_OPERANDS is true.  The expanded
29539    code is a forward jump to a newly created label in case the
29540    comparison is true.  The generated label rtx is returned.  */
29541 static rtx
29542 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
29543                                   bool swap_operands)
29544 {
29545   rtx label, tmp;
29546
29547   if (swap_operands)
29548     {
29549       tmp = op0;
29550       op0 = op1;
29551       op1 = tmp;
29552     }
29553
29554   label = gen_label_rtx ();
29555   tmp = gen_rtx_REG (CCFPUmode, FLAGS_REG);
29556   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29557                           gen_rtx_COMPARE (CCFPUmode, op0, op1)));
29558   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
29559   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
29560                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
29561   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
29562   JUMP_LABEL (tmp) = label;
29563
29564   return label;
29565 }
29566
29567 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
29568    using comparison code CODE.  Operands are swapped for the comparison if
29569    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
29570 static rtx
29571 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
29572                               bool swap_operands)
29573 {
29574   enum machine_mode mode = GET_MODE (op0);
29575   rtx mask = gen_reg_rtx (mode);
29576
29577   if (swap_operands)
29578     {
29579       rtx tmp = op0;
29580       op0 = op1;
29581       op1 = tmp;
29582     }
29583
29584   if (mode == DFmode)
29585     emit_insn (gen_sse2_maskcmpdf3 (mask, op0, op1,
29586                                     gen_rtx_fmt_ee (code, mode, op0, op1)));
29587   else
29588     emit_insn (gen_sse_maskcmpsf3 (mask, op0, op1,
29589                                    gen_rtx_fmt_ee (code, mode, op0, op1)));
29590
29591   return mask;
29592 }
29593
29594 /* Generate and return a rtx of mode MODE for 2**n where n is the number
29595    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
29596 static rtx
29597 ix86_gen_TWO52 (enum machine_mode mode)
29598 {
29599   REAL_VALUE_TYPE TWO52r;
29600   rtx TWO52;
29601
29602   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
29603   TWO52 = const_double_from_real_value (TWO52r, mode);
29604   TWO52 = force_reg (mode, TWO52);
29605
29606   return TWO52;
29607 }
29608
29609 /* Expand SSE sequence for computing lround from OP1 storing
29610    into OP0.  */
29611 void
29612 ix86_expand_lround (rtx op0, rtx op1)
29613 {
29614   /* C code for the stuff we're doing below:
29615        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
29616        return (long)tmp;
29617    */
29618   enum machine_mode mode = GET_MODE (op1);
29619   const struct real_format *fmt;
29620   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
29621   rtx adj;
29622
29623   /* load nextafter (0.5, 0.0) */
29624   fmt = REAL_MODE_FORMAT (mode);
29625   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
29626   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
29627
29628   /* adj = copysign (0.5, op1) */
29629   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
29630   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
29631
29632   /* adj = op1 + adj */
29633   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
29634
29635   /* op0 = (imode)adj */
29636   expand_fix (op0, adj, 0);
29637 }
29638
29639 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
29640    into OPERAND0.  */
29641 void
29642 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
29643 {
29644   /* C code for the stuff we're doing below (for do_floor):
29645         xi = (long)op1;
29646         xi -= (double)xi > op1 ? 1 : 0;
29647         return xi;
29648    */
29649   enum machine_mode fmode = GET_MODE (op1);
29650   enum machine_mode imode = GET_MODE (op0);
29651   rtx ireg, freg, label, tmp;
29652
29653   /* reg = (long)op1 */
29654   ireg = gen_reg_rtx (imode);
29655   expand_fix (ireg, op1, 0);
29656
29657   /* freg = (double)reg */
29658   freg = gen_reg_rtx (fmode);
29659   expand_float (freg, ireg, 0);
29660
29661   /* ireg = (freg > op1) ? ireg - 1 : ireg */
29662   label = ix86_expand_sse_compare_and_jump (UNLE,
29663                                             freg, op1, !do_floor);
29664   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
29665                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
29666   emit_move_insn (ireg, tmp);
29667
29668   emit_label (label);
29669   LABEL_NUSES (label) = 1;
29670
29671   emit_move_insn (op0, ireg);
29672 }
29673
29674 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
29675    result in OPERAND0.  */
29676 void
29677 ix86_expand_rint (rtx operand0, rtx operand1)
29678 {
29679   /* C code for the stuff we're doing below:
29680         xa = fabs (operand1);
29681         if (!isless (xa, 2**52))
29682           return operand1;
29683         xa = xa + 2**52 - 2**52;
29684         return copysign (xa, operand1);
29685    */
29686   enum machine_mode mode = GET_MODE (operand0);
29687   rtx res, xa, label, TWO52, mask;
29688
29689   res = gen_reg_rtx (mode);
29690   emit_move_insn (res, operand1);
29691
29692   /* xa = abs (operand1) */
29693   xa = ix86_expand_sse_fabs (res, &mask);
29694
29695   /* if (!isless (xa, TWO52)) goto label; */
29696   TWO52 = ix86_gen_TWO52 (mode);
29697   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29698
29699   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
29700   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
29701
29702   ix86_sse_copysign_to_positive (res, xa, res, mask);
29703
29704   emit_label (label);
29705   LABEL_NUSES (label) = 1;
29706
29707   emit_move_insn (operand0, res);
29708 }
29709
29710 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
29711    into OPERAND0.  */
29712 void
29713 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
29714 {
29715   /* C code for the stuff we expand below.
29716         double xa = fabs (x), x2;
29717         if (!isless (xa, TWO52))
29718           return x;
29719         xa = xa + TWO52 - TWO52;
29720         x2 = copysign (xa, x);
29721      Compensate.  Floor:
29722         if (x2 > x)
29723           x2 -= 1;
29724      Compensate.  Ceil:
29725         if (x2 < x)
29726           x2 -= -1;
29727         return x2;
29728    */
29729   enum machine_mode mode = GET_MODE (operand0);
29730   rtx xa, TWO52, tmp, label, one, res, mask;
29731
29732   TWO52 = ix86_gen_TWO52 (mode);
29733
29734   /* Temporary for holding the result, initialized to the input
29735      operand to ease control flow.  */
29736   res = gen_reg_rtx (mode);
29737   emit_move_insn (res, operand1);
29738
29739   /* xa = abs (operand1) */
29740   xa = ix86_expand_sse_fabs (res, &mask);
29741
29742   /* if (!isless (xa, TWO52)) goto label; */
29743   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29744
29745   /* xa = xa + TWO52 - TWO52; */
29746   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
29747   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
29748
29749   /* xa = copysign (xa, operand1) */
29750   ix86_sse_copysign_to_positive (xa, xa, res, mask);
29751
29752   /* generate 1.0 or -1.0 */
29753   one = force_reg (mode,
29754                    const_double_from_real_value (do_floor
29755                                                  ? dconst1 : dconstm1, mode));
29756
29757   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
29758   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
29759   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29760                           gen_rtx_AND (mode, one, tmp)));
29761   /* We always need to subtract here to preserve signed zero.  */
29762   tmp = expand_simple_binop (mode, MINUS,
29763                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
29764   emit_move_insn (res, tmp);
29765
29766   emit_label (label);
29767   LABEL_NUSES (label) = 1;
29768
29769   emit_move_insn (operand0, res);
29770 }
29771
29772 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
29773    into OPERAND0.  */
29774 void
29775 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
29776 {
29777   /* C code for the stuff we expand below.
29778         double xa = fabs (x), x2;
29779         if (!isless (xa, TWO52))
29780           return x;
29781         x2 = (double)(long)x;
29782      Compensate.  Floor:
29783         if (x2 > x)
29784           x2 -= 1;
29785      Compensate.  Ceil:
29786         if (x2 < x)
29787           x2 += 1;
29788         if (HONOR_SIGNED_ZEROS (mode))
29789           return copysign (x2, x);
29790         return x2;
29791    */
29792   enum machine_mode mode = GET_MODE (operand0);
29793   rtx xa, xi, TWO52, tmp, label, one, res, mask;
29794
29795   TWO52 = ix86_gen_TWO52 (mode);
29796
29797   /* Temporary for holding the result, initialized to the input
29798      operand to ease control flow.  */
29799   res = gen_reg_rtx (mode);
29800   emit_move_insn (res, operand1);
29801
29802   /* xa = abs (operand1) */
29803   xa = ix86_expand_sse_fabs (res, &mask);
29804
29805   /* if (!isless (xa, TWO52)) goto label; */
29806   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29807
29808   /* xa = (double)(long)x */
29809   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
29810   expand_fix (xi, res, 0);
29811   expand_float (xa, xi, 0);
29812
29813   /* generate 1.0 */
29814   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
29815
29816   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
29817   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
29818   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29819                           gen_rtx_AND (mode, one, tmp)));
29820   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
29821                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
29822   emit_move_insn (res, tmp);
29823
29824   if (HONOR_SIGNED_ZEROS (mode))
29825     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
29826
29827   emit_label (label);
29828   LABEL_NUSES (label) = 1;
29829
29830   emit_move_insn (operand0, res);
29831 }
29832
29833 /* Expand SSE sequence for computing round from OPERAND1 storing
29834    into OPERAND0.  Sequence that works without relying on DImode truncation
29835    via cvttsd2siq that is only available on 64bit targets.  */
29836 void
29837 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
29838 {
29839   /* C code for the stuff we expand below.
29840         double xa = fabs (x), xa2, x2;
29841         if (!isless (xa, TWO52))
29842           return x;
29843      Using the absolute value and copying back sign makes
29844      -0.0 -> -0.0 correct.
29845         xa2 = xa + TWO52 - TWO52;
29846      Compensate.
29847         dxa = xa2 - xa;
29848         if (dxa <= -0.5)
29849           xa2 += 1;
29850         else if (dxa > 0.5)
29851           xa2 -= 1;
29852         x2 = copysign (xa2, x);
29853         return x2;
29854    */
29855   enum machine_mode mode = GET_MODE (operand0);
29856   rtx xa, xa2, dxa, TWO52, tmp, label, half, mhalf, one, res, mask;
29857
29858   TWO52 = ix86_gen_TWO52 (mode);
29859
29860   /* Temporary for holding the result, initialized to the input
29861      operand to ease control flow.  */
29862   res = gen_reg_rtx (mode);
29863   emit_move_insn (res, operand1);
29864
29865   /* xa = abs (operand1) */
29866   xa = ix86_expand_sse_fabs (res, &mask);
29867
29868   /* if (!isless (xa, TWO52)) goto label; */
29869   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29870
29871   /* xa2 = xa + TWO52 - TWO52; */
29872   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
29873   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
29874
29875   /* dxa = xa2 - xa; */
29876   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
29877
29878   /* generate 0.5, 1.0 and -0.5 */
29879   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
29880   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
29881   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
29882                                0, OPTAB_DIRECT);
29883
29884   /* Compensate.  */
29885   tmp = gen_reg_rtx (mode);
29886   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
29887   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
29888   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29889                           gen_rtx_AND (mode, one, tmp)));
29890   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
29891   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
29892   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
29893   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29894                           gen_rtx_AND (mode, one, tmp)));
29895   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
29896
29897   /* res = copysign (xa2, operand1) */
29898   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
29899
29900   emit_label (label);
29901   LABEL_NUSES (label) = 1;
29902
29903   emit_move_insn (operand0, res);
29904 }
29905
29906 /* Expand SSE sequence for computing trunc from OPERAND1 storing
29907    into OPERAND0.  */
29908 void
29909 ix86_expand_trunc (rtx operand0, rtx operand1)
29910 {
29911   /* C code for SSE variant we expand below.
29912         double xa = fabs (x), x2;
29913         if (!isless (xa, TWO52))
29914           return x;
29915         x2 = (double)(long)x;
29916         if (HONOR_SIGNED_ZEROS (mode))
29917           return copysign (x2, x);
29918         return x2;
29919    */
29920   enum machine_mode mode = GET_MODE (operand0);
29921   rtx xa, xi, TWO52, label, res, mask;
29922
29923   TWO52 = ix86_gen_TWO52 (mode);
29924
29925   /* Temporary for holding the result, initialized to the input
29926      operand to ease control flow.  */
29927   res = gen_reg_rtx (mode);
29928   emit_move_insn (res, operand1);
29929
29930   /* xa = abs (operand1) */
29931   xa = ix86_expand_sse_fabs (res, &mask);
29932
29933   /* if (!isless (xa, TWO52)) goto label; */
29934   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29935
29936   /* x = (double)(long)x */
29937   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
29938   expand_fix (xi, res, 0);
29939   expand_float (res, xi, 0);
29940
29941   if (HONOR_SIGNED_ZEROS (mode))
29942     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
29943
29944   emit_label (label);
29945   LABEL_NUSES (label) = 1;
29946
29947   emit_move_insn (operand0, res);
29948 }
29949
29950 /* Expand SSE sequence for computing trunc from OPERAND1 storing
29951    into OPERAND0.  */
29952 void
29953 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
29954 {
29955   enum machine_mode mode = GET_MODE (operand0);
29956   rtx xa, mask, TWO52, label, one, res, smask, tmp;
29957
29958   /* C code for SSE variant we expand below.
29959         double xa = fabs (x), x2;
29960         if (!isless (xa, TWO52))
29961           return x;
29962         xa2 = xa + TWO52 - TWO52;
29963      Compensate:
29964         if (xa2 > xa)
29965           xa2 -= 1.0;
29966         x2 = copysign (xa2, x);
29967         return x2;
29968    */
29969
29970   TWO52 = ix86_gen_TWO52 (mode);
29971
29972   /* Temporary for holding the result, initialized to the input
29973      operand to ease control flow.  */
29974   res = gen_reg_rtx (mode);
29975   emit_move_insn (res, operand1);
29976
29977   /* xa = abs (operand1) */
29978   xa = ix86_expand_sse_fabs (res, &smask);
29979
29980   /* if (!isless (xa, TWO52)) goto label; */
29981   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29982
29983   /* res = xa + TWO52 - TWO52; */
29984   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
29985   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
29986   emit_move_insn (res, tmp);
29987
29988   /* generate 1.0 */
29989   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
29990
29991   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
29992   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
29993   emit_insn (gen_rtx_SET (VOIDmode, mask,
29994                           gen_rtx_AND (mode, mask, one)));
29995   tmp = expand_simple_binop (mode, MINUS,
29996                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
29997   emit_move_insn (res, tmp);
29998
29999   /* res = copysign (res, operand1) */
30000   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
30001
30002   emit_label (label);
30003   LABEL_NUSES (label) = 1;
30004
30005   emit_move_insn (operand0, res);
30006 }
30007
30008 /* Expand SSE sequence for computing round from OPERAND1 storing
30009    into OPERAND0.  */
30010 void
30011 ix86_expand_round (rtx operand0, rtx operand1)
30012 {
30013   /* C code for the stuff we're doing below:
30014         double xa = fabs (x);
30015         if (!isless (xa, TWO52))
30016           return x;
30017         xa = (double)(long)(xa + nextafter (0.5, 0.0));
30018         return copysign (xa, x);
30019    */
30020   enum machine_mode mode = GET_MODE (operand0);
30021   rtx res, TWO52, xa, label, xi, half, mask;
30022   const struct real_format *fmt;
30023   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
30024
30025   /* Temporary for holding the result, initialized to the input
30026      operand to ease control flow.  */
30027   res = gen_reg_rtx (mode);
30028   emit_move_insn (res, operand1);
30029
30030   TWO52 = ix86_gen_TWO52 (mode);
30031   xa = ix86_expand_sse_fabs (res, &mask);
30032   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
30033
30034   /* load nextafter (0.5, 0.0) */
30035   fmt = REAL_MODE_FORMAT (mode);
30036   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
30037   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
30038
30039   /* xa = xa + 0.5 */
30040   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
30041   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
30042
30043   /* xa = (double)(int64_t)xa */
30044   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
30045   expand_fix (xi, xa, 0);
30046   expand_float (xa, xi, 0);
30047
30048   /* res = copysign (xa, operand1) */
30049   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
30050
30051   emit_label (label);
30052   LABEL_NUSES (label) = 1;
30053
30054   emit_move_insn (operand0, res);
30055 }
30056
30057 \f
30058 /* Validate whether a SSE5 instruction is valid or not.
30059    OPERANDS is the array of operands.
30060    NUM is the number of operands.
30061    USES_OC0 is true if the instruction uses OC0 and provides 4 variants.
30062    NUM_MEMORY is the maximum number of memory operands to accept.  
30063    when COMMUTATIVE is set, operand 1 and 2 can be swapped.  */
30064
30065 bool
30066 ix86_sse5_valid_op_p (rtx operands[], rtx insn ATTRIBUTE_UNUSED, int num,
30067                       bool uses_oc0, int num_memory, bool commutative)
30068 {
30069   int mem_mask;
30070   int mem_count;
30071   int i;
30072
30073   /* Count the number of memory arguments */
30074   mem_mask = 0;
30075   mem_count = 0;
30076   for (i = 0; i < num; i++)
30077     {
30078       enum machine_mode mode = GET_MODE (operands[i]);
30079       if (register_operand (operands[i], mode))
30080         ;
30081
30082       else if (memory_operand (operands[i], mode))
30083         {
30084           mem_mask |= (1 << i);
30085           mem_count++;
30086         }
30087
30088       else
30089         {
30090           rtx pattern = PATTERN (insn);
30091
30092           /* allow 0 for pcmov */
30093           if (GET_CODE (pattern) != SET
30094               || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE
30095               || i < 2
30096               || operands[i] != CONST0_RTX (mode))
30097             return false;
30098         }
30099     }
30100
30101   /* Special case pmacsdq{l,h} where we allow the 3rd argument to be
30102      a memory operation.  */
30103   if (num_memory < 0)
30104     {
30105       num_memory = -num_memory;
30106       if ((mem_mask & (1 << (num-1))) != 0)
30107         {
30108           mem_mask &= ~(1 << (num-1));
30109           mem_count--;
30110         }
30111     }
30112
30113   /* If there were no memory operations, allow the insn */
30114   if (mem_mask == 0)
30115     return true;
30116
30117   /* Do not allow the destination register to be a memory operand.  */
30118   else if (mem_mask & (1 << 0))
30119     return false;
30120
30121   /* If there are too many memory operations, disallow the instruction.  While
30122      the hardware only allows 1 memory reference, before register allocation
30123      for some insns, we allow two memory operations sometimes in order to allow
30124      code like the following to be optimized:
30125
30126         float fmadd (float *a, float *b, float *c) { return (*a * *b) + *c; }
30127
30128     or similar cases that are vectorized into using the fmaddss
30129     instruction.  */
30130   else if (mem_count > num_memory)
30131     return false;
30132
30133   /* Don't allow more than one memory operation if not optimizing.  */
30134   else if (mem_count > 1 && !optimize)
30135     return false;
30136
30137   else if (num == 4 && mem_count == 1)
30138     {
30139       /* formats (destination is the first argument), example fmaddss:
30140          xmm1, xmm1, xmm2, xmm3/mem
30141          xmm1, xmm1, xmm2/mem, xmm3
30142          xmm1, xmm2, xmm3/mem, xmm1
30143          xmm1, xmm2/mem, xmm3, xmm1 */
30144       if (uses_oc0)
30145         return ((mem_mask == (1 << 1))
30146                 || (mem_mask == (1 << 2))
30147                 || (mem_mask == (1 << 3)));
30148
30149       /* format, example pmacsdd:
30150          xmm1, xmm2, xmm3/mem, xmm1 */
30151       if (commutative)
30152         return (mem_mask == (1 << 2) || mem_mask == (1 << 1));
30153       else
30154         return (mem_mask == (1 << 2));
30155     }
30156
30157   else if (num == 4 && num_memory == 2)
30158     {
30159       /* If there are two memory operations, we can load one of the memory ops
30160          into the destination register.  This is for optimizing the
30161          multiply/add ops, which the combiner has optimized both the multiply
30162          and the add insns to have a memory operation.  We have to be careful
30163          that the destination doesn't overlap with the inputs.  */
30164       rtx op0 = operands[0];
30165
30166       if (reg_mentioned_p (op0, operands[1])
30167           || reg_mentioned_p (op0, operands[2])
30168           || reg_mentioned_p (op0, operands[3]))
30169         return false;
30170
30171       /* formats (destination is the first argument), example fmaddss:
30172          xmm1, xmm1, xmm2, xmm3/mem
30173          xmm1, xmm1, xmm2/mem, xmm3
30174          xmm1, xmm2, xmm3/mem, xmm1
30175          xmm1, xmm2/mem, xmm3, xmm1
30176
30177          For the oc0 case, we will load either operands[1] or operands[3] into
30178          operands[0], so any combination of 2 memory operands is ok.  */
30179       if (uses_oc0)
30180         return true;
30181
30182       /* format, example pmacsdd:
30183          xmm1, xmm2, xmm3/mem, xmm1
30184
30185          For the integer multiply/add instructions be more restrictive and
30186          require operands[2] and operands[3] to be the memory operands.  */
30187       if (commutative)
30188         return (mem_mask == ((1 << 1) | (1 << 3)) || ((1 << 2) | (1 << 3)));
30189       else
30190         return (mem_mask == ((1 << 2) | (1 << 3)));
30191     }
30192
30193   else if (num == 3 && num_memory == 1)
30194     {
30195       /* formats, example protb:
30196          xmm1, xmm2, xmm3/mem
30197          xmm1, xmm2/mem, xmm3 */
30198       if (uses_oc0)
30199         return ((mem_mask == (1 << 1)) || (mem_mask == (1 << 2)));
30200
30201       /* format, example comeq:
30202          xmm1, xmm2, xmm3/mem */
30203       else
30204         return (mem_mask == (1 << 2));
30205     }
30206
30207   else
30208     gcc_unreachable ();
30209
30210   return false;
30211 }
30212
30213 \f
30214 /* Fixup an SSE5 instruction that has 2 memory input references into a form the
30215    hardware will allow by using the destination register to load one of the
30216    memory operations.  Presently this is used by the multiply/add routines to
30217    allow 2 memory references.  */
30218
30219 void
30220 ix86_expand_sse5_multiple_memory (rtx operands[],
30221                                   int num,
30222                                   enum machine_mode mode)
30223 {
30224   rtx op0 = operands[0];
30225   if (num != 4
30226       || memory_operand (op0, mode)
30227       || reg_mentioned_p (op0, operands[1])
30228       || reg_mentioned_p (op0, operands[2])
30229       || reg_mentioned_p (op0, operands[3]))
30230     gcc_unreachable ();
30231
30232   /* For 2 memory operands, pick either operands[1] or operands[3] to move into
30233      the destination register.  */
30234   if (memory_operand (operands[1], mode))
30235     {
30236       emit_move_insn (op0, operands[1]);
30237       operands[1] = op0;
30238     }
30239   else if (memory_operand (operands[3], mode))
30240     {
30241       emit_move_insn (op0, operands[3]);
30242       operands[3] = op0;
30243     }
30244   else
30245     gcc_unreachable ();
30246
30247   return;
30248 }
30249
30250 \f
30251 /* Table of valid machine attributes.  */
30252 static const struct attribute_spec ix86_attribute_table[] =
30253 {
30254   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
30255   /* Stdcall attribute says callee is responsible for popping arguments
30256      if they are not variable.  */
30257   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute },
30258   /* Fastcall attribute says callee is responsible for popping arguments
30259      if they are not variable.  */
30260   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute },
30261   /* Cdecl attribute says the callee is a normal C declaration */
30262   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute },
30263   /* Regparm attribute specifies how many integer arguments are to be
30264      passed in registers.  */
30265   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute },
30266   /* Sseregparm attribute says we are using x86_64 calling conventions
30267      for FP arguments.  */
30268   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute },
30269   /* force_align_arg_pointer says this function realigns the stack at entry.  */
30270   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
30271     false, true,  true, ix86_handle_cconv_attribute },
30272 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
30273   { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
30274   { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
30275   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute },
30276 #endif
30277   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
30278   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
30279 #ifdef SUBTARGET_ATTRIBUTE_TABLE
30280   SUBTARGET_ATTRIBUTE_TABLE,
30281 #endif
30282   /* ms_abi and sysv_abi calling convention function attributes.  */
30283   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
30284   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
30285   /* End element.  */
30286   { NULL,        0, 0, false, false, false, NULL }
30287 };
30288
30289 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
30290 static int
30291 x86_builtin_vectorization_cost (bool runtime_test)
30292 {
30293   /* If the branch of the runtime test is taken - i.e. - the vectorized
30294      version is skipped - this incurs a misprediction cost (because the
30295      vectorized version is expected to be the fall-through).  So we subtract
30296      the latency of a mispredicted branch from the costs that are incured
30297      when the vectorized version is executed.
30298
30299      TODO: The values in individual target tables have to be tuned or new
30300      fields may be needed. For eg. on K8, the default branch path is the
30301      not-taken path. If the taken path is predicted correctly, the minimum
30302      penalty of going down the taken-path is 1 cycle. If the taken-path is
30303      not predicted correctly, then the minimum penalty is 10 cycles.  */
30304
30305   if (runtime_test)
30306     {
30307       return (-(ix86_cost->cond_taken_branch_cost));
30308     }
30309   else
30310     return 0;
30311 }
30312
30313 /* This function returns the calling abi specific va_list type node.
30314    It returns  the FNDECL specific va_list type.  */
30315
30316 tree
30317 ix86_fn_abi_va_list (tree fndecl)
30318 {
30319   if (!TARGET_64BIT)
30320     return va_list_type_node;
30321   gcc_assert (fndecl != NULL_TREE);
30322
30323   if (ix86_function_abi ((const_tree) fndecl) == MS_ABI)
30324     return ms_va_list_type_node;
30325   else
30326     return sysv_va_list_type_node;
30327 }
30328
30329 /* Returns the canonical va_list type specified by TYPE. If there
30330    is no valid TYPE provided, it return NULL_TREE.  */
30331
30332 tree
30333 ix86_canonical_va_list_type (tree type)
30334 {
30335   tree wtype, htype;
30336
30337   /* Resolve references and pointers to va_list type.  */
30338   if (INDIRECT_REF_P (type))
30339     type = TREE_TYPE (type);
30340   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
30341     type = TREE_TYPE (type);
30342
30343   if (TARGET_64BIT)
30344     {
30345       wtype = va_list_type_node;
30346           gcc_assert (wtype != NULL_TREE);
30347       htype = type;
30348       if (TREE_CODE (wtype) == ARRAY_TYPE)
30349         {
30350           /* If va_list is an array type, the argument may have decayed
30351              to a pointer type, e.g. by being passed to another function.
30352              In that case, unwrap both types so that we can compare the
30353              underlying records.  */
30354           if (TREE_CODE (htype) == ARRAY_TYPE
30355               || POINTER_TYPE_P (htype))
30356             {
30357               wtype = TREE_TYPE (wtype);
30358               htype = TREE_TYPE (htype);
30359             }
30360         }
30361       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
30362         return va_list_type_node;
30363       wtype = sysv_va_list_type_node;
30364           gcc_assert (wtype != NULL_TREE);
30365       htype = type;
30366       if (TREE_CODE (wtype) == ARRAY_TYPE)
30367         {
30368           /* If va_list is an array type, the argument may have decayed
30369              to a pointer type, e.g. by being passed to another function.
30370              In that case, unwrap both types so that we can compare the
30371              underlying records.  */
30372           if (TREE_CODE (htype) == ARRAY_TYPE
30373               || POINTER_TYPE_P (htype))
30374             {
30375               wtype = TREE_TYPE (wtype);
30376               htype = TREE_TYPE (htype);
30377             }
30378         }
30379       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
30380         return sysv_va_list_type_node;
30381       wtype = ms_va_list_type_node;
30382           gcc_assert (wtype != NULL_TREE);
30383       htype = type;
30384       if (TREE_CODE (wtype) == ARRAY_TYPE)
30385         {
30386           /* If va_list is an array type, the argument may have decayed
30387              to a pointer type, e.g. by being passed to another function.
30388              In that case, unwrap both types so that we can compare the
30389              underlying records.  */
30390           if (TREE_CODE (htype) == ARRAY_TYPE
30391               || POINTER_TYPE_P (htype))
30392             {
30393               wtype = TREE_TYPE (wtype);
30394               htype = TREE_TYPE (htype);
30395             }
30396         }
30397       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
30398         return ms_va_list_type_node;
30399       return NULL_TREE;
30400     }
30401   return std_canonical_va_list_type (type);
30402 }
30403
30404 /* Iterate through the target-specific builtin types for va_list.
30405     IDX denotes the iterator, *PTREE is set to the result type of
30406     the va_list builtin, and *PNAME to its internal type.
30407     Returns zero if there is no element for this index, otherwise
30408     IDX should be increased upon the next call.
30409     Note, do not iterate a base builtin's name like __builtin_va_list.
30410     Used from c_common_nodes_and_builtins.  */
30411
30412 int
30413 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
30414 {
30415   if (!TARGET_64BIT)
30416     return 0;
30417   switch (idx) {
30418   case 0:
30419     *ptree = ms_va_list_type_node;
30420     *pname = "__builtin_ms_va_list";
30421     break;
30422   case 1:
30423     *ptree = sysv_va_list_type_node;
30424     *pname = "__builtin_sysv_va_list";
30425     break;
30426   default:
30427     return 0;
30428   }
30429   return 1;
30430 }
30431
30432 /* Initialize the GCC target structure.  */
30433 #undef TARGET_RETURN_IN_MEMORY
30434 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
30435
30436 #undef TARGET_LEGITIMIZE_ADDRESS
30437 #define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address
30438
30439 #undef TARGET_ATTRIBUTE_TABLE
30440 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
30441 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
30442 #  undef TARGET_MERGE_DECL_ATTRIBUTES
30443 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
30444 #endif
30445
30446 #undef TARGET_COMP_TYPE_ATTRIBUTES
30447 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
30448
30449 #undef TARGET_INIT_BUILTINS
30450 #define TARGET_INIT_BUILTINS ix86_init_builtins
30451 #undef TARGET_EXPAND_BUILTIN
30452 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
30453
30454 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
30455 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
30456   ix86_builtin_vectorized_function
30457
30458 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
30459 #define TARGET_VECTORIZE_BUILTIN_CONVERSION ix86_vectorize_builtin_conversion
30460
30461 #undef TARGET_BUILTIN_RECIPROCAL
30462 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
30463
30464 #undef TARGET_ASM_FUNCTION_EPILOGUE
30465 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
30466
30467 #undef TARGET_ENCODE_SECTION_INFO
30468 #ifndef SUBTARGET_ENCODE_SECTION_INFO
30469 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
30470 #else
30471 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
30472 #endif
30473
30474 #undef TARGET_ASM_OPEN_PAREN
30475 #define TARGET_ASM_OPEN_PAREN ""
30476 #undef TARGET_ASM_CLOSE_PAREN
30477 #define TARGET_ASM_CLOSE_PAREN ""
30478
30479 #undef TARGET_ASM_BYTE_OP
30480 #define TARGET_ASM_BYTE_OP ASM_BYTE
30481
30482 #undef TARGET_ASM_ALIGNED_HI_OP
30483 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
30484 #undef TARGET_ASM_ALIGNED_SI_OP
30485 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
30486 #ifdef ASM_QUAD
30487 #undef TARGET_ASM_ALIGNED_DI_OP
30488 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
30489 #endif
30490
30491 #undef TARGET_ASM_UNALIGNED_HI_OP
30492 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
30493 #undef TARGET_ASM_UNALIGNED_SI_OP
30494 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
30495 #undef TARGET_ASM_UNALIGNED_DI_OP
30496 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
30497
30498 #undef TARGET_SCHED_ADJUST_COST
30499 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
30500 #undef TARGET_SCHED_ISSUE_RATE
30501 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
30502 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
30503 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
30504   ia32_multipass_dfa_lookahead
30505
30506 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
30507 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
30508
30509 #ifdef HAVE_AS_TLS
30510 #undef TARGET_HAVE_TLS
30511 #define TARGET_HAVE_TLS true
30512 #endif
30513 #undef TARGET_CANNOT_FORCE_CONST_MEM
30514 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
30515 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
30516 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
30517
30518 #undef TARGET_DELEGITIMIZE_ADDRESS
30519 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
30520
30521 #undef TARGET_MS_BITFIELD_LAYOUT_P
30522 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
30523
30524 #if TARGET_MACHO
30525 #undef TARGET_BINDS_LOCAL_P
30526 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
30527 #endif
30528 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
30529 #undef TARGET_BINDS_LOCAL_P
30530 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
30531 #endif
30532
30533 #undef TARGET_ASM_OUTPUT_MI_THUNK
30534 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
30535 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
30536 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
30537
30538 #undef TARGET_ASM_FILE_START
30539 #define TARGET_ASM_FILE_START x86_file_start
30540
30541 #undef TARGET_DEFAULT_TARGET_FLAGS
30542 #define TARGET_DEFAULT_TARGET_FLAGS     \
30543   (TARGET_DEFAULT                       \
30544    | TARGET_SUBTARGET_DEFAULT           \
30545    | TARGET_TLS_DIRECT_SEG_REFS_DEFAULT)
30546
30547 #undef TARGET_HANDLE_OPTION
30548 #define TARGET_HANDLE_OPTION ix86_handle_option
30549
30550 #undef TARGET_RTX_COSTS
30551 #define TARGET_RTX_COSTS ix86_rtx_costs
30552 #undef TARGET_ADDRESS_COST
30553 #define TARGET_ADDRESS_COST ix86_address_cost
30554
30555 #undef TARGET_FIXED_CONDITION_CODE_REGS
30556 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
30557 #undef TARGET_CC_MODES_COMPATIBLE
30558 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
30559
30560 #undef TARGET_MACHINE_DEPENDENT_REORG
30561 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
30562
30563 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
30564 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE ix86_builtin_setjmp_frame_value
30565
30566 #undef TARGET_BUILD_BUILTIN_VA_LIST
30567 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
30568
30569 #undef TARGET_FN_ABI_VA_LIST
30570 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
30571
30572 #undef TARGET_CANONICAL_VA_LIST_TYPE
30573 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
30574
30575 #undef TARGET_EXPAND_BUILTIN_VA_START
30576 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
30577
30578 #undef TARGET_MD_ASM_CLOBBERS
30579 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
30580
30581 #undef TARGET_PROMOTE_PROTOTYPES
30582 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
30583 #undef TARGET_STRUCT_VALUE_RTX
30584 #define TARGET_STRUCT_VALUE_RTX ix86_struct_value_rtx
30585 #undef TARGET_SETUP_INCOMING_VARARGS
30586 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
30587 #undef TARGET_MUST_PASS_IN_STACK
30588 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
30589 #undef TARGET_PASS_BY_REFERENCE
30590 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
30591 #undef TARGET_INTERNAL_ARG_POINTER
30592 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
30593 #undef TARGET_UPDATE_STACK_BOUNDARY
30594 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
30595 #undef TARGET_GET_DRAP_RTX
30596 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
30597 #undef TARGET_STRICT_ARGUMENT_NAMING
30598 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
30599
30600 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
30601 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
30602
30603 #undef TARGET_SCALAR_MODE_SUPPORTED_P
30604 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
30605
30606 #undef TARGET_VECTOR_MODE_SUPPORTED_P
30607 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
30608
30609 #undef TARGET_C_MODE_FOR_SUFFIX
30610 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
30611
30612 #ifdef HAVE_AS_TLS
30613 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
30614 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
30615 #endif
30616
30617 #ifdef SUBTARGET_INSERT_ATTRIBUTES
30618 #undef TARGET_INSERT_ATTRIBUTES
30619 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
30620 #endif
30621
30622 #undef TARGET_MANGLE_TYPE
30623 #define TARGET_MANGLE_TYPE ix86_mangle_type
30624
30625 #undef TARGET_STACK_PROTECT_FAIL
30626 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
30627
30628 #undef TARGET_FUNCTION_VALUE
30629 #define TARGET_FUNCTION_VALUE ix86_function_value
30630
30631 #undef TARGET_SECONDARY_RELOAD
30632 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
30633
30634 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
30635 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST x86_builtin_vectorization_cost
30636
30637 #undef TARGET_SET_CURRENT_FUNCTION
30638 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
30639
30640 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
30641 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
30642
30643 #undef TARGET_OPTION_SAVE
30644 #define TARGET_OPTION_SAVE ix86_function_specific_save
30645
30646 #undef TARGET_OPTION_RESTORE
30647 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
30648
30649 #undef TARGET_OPTION_PRINT
30650 #define TARGET_OPTION_PRINT ix86_function_specific_print
30651
30652 #undef TARGET_CAN_INLINE_P
30653 #define TARGET_CAN_INLINE_P ix86_can_inline_p
30654
30655 #undef TARGET_EXPAND_TO_RTL_HOOK
30656 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
30657
30658 #undef TARGET_LEGITIMATE_ADDRESS_P
30659 #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
30660
30661 #undef TARGET_IRA_COVER_CLASSES
30662 #define TARGET_IRA_COVER_CLASSES i386_ira_cover_classes
30663
30664 #undef TARGET_FRAME_POINTER_REQUIRED
30665 #define TARGET_FRAME_POINTER_REQUIRED ix86_frame_pointer_required
30666
30667 struct gcc_target targetm = TARGET_INITIALIZER;
30668 \f
30669 #include "gt-i386.h"