OSDN Git Service

* optabs.c (emit_unop_insn): Break out to ...
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.c
1 /* Subroutines used for code generation on IA-32.
2    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3    2002, 2003, 2004, 2005, 2006, 2007, 2008
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "tm_p.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "real.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "output.h"
35 #include "insn-codes.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "c-common.h"
39 #include "except.h"
40 #include "function.h"
41 #include "recog.h"
42 #include "expr.h"
43 #include "optabs.h"
44 #include "toplev.h"
45 #include "basic-block.h"
46 #include "ggc.h"
47 #include "target.h"
48 #include "target-def.h"
49 #include "langhooks.h"
50 #include "cgraph.h"
51 #include "gimple.h"
52 #include "dwarf2.h"
53 #include "df.h"
54 #include "tm-constrs.h"
55 #include "params.h"
56
57 static int x86_builtin_vectorization_cost (bool);
58 static rtx legitimize_dllimport_symbol (rtx, bool);
59
60 #ifndef CHECK_STACK_LIMIT
61 #define CHECK_STACK_LIMIT (-1)
62 #endif
63
64 /* Return index of given mode in mult and division cost tables.  */
65 #define MODE_INDEX(mode)                                        \
66   ((mode) == QImode ? 0                                         \
67    : (mode) == HImode ? 1                                       \
68    : (mode) == SImode ? 2                                       \
69    : (mode) == DImode ? 3                                       \
70    : 4)
71
72 /* Processor costs (relative to an add) */
73 /* We assume COSTS_N_INSNS is defined as (N)*4 and an addition is 2 bytes.  */
74 #define COSTS_N_BYTES(N) ((N) * 2)
75
76 #define DUMMY_STRINGOP_ALGS {libcall, {{-1, libcall}}}
77
78 static const
79 struct processor_costs size_cost = {    /* costs for tuning for size */
80   COSTS_N_BYTES (2),                    /* cost of an add instruction */
81   COSTS_N_BYTES (3),                    /* cost of a lea instruction */
82   COSTS_N_BYTES (2),                    /* variable shift costs */
83   COSTS_N_BYTES (3),                    /* constant shift costs */
84   {COSTS_N_BYTES (3),                   /* cost of starting multiply for QI */
85    COSTS_N_BYTES (3),                   /*                               HI */
86    COSTS_N_BYTES (3),                   /*                               SI */
87    COSTS_N_BYTES (3),                   /*                               DI */
88    COSTS_N_BYTES (5)},                  /*                            other */
89   0,                                    /* cost of multiply per each bit set */
90   {COSTS_N_BYTES (3),                   /* cost of a divide/mod for QI */
91    COSTS_N_BYTES (3),                   /*                          HI */
92    COSTS_N_BYTES (3),                   /*                          SI */
93    COSTS_N_BYTES (3),                   /*                          DI */
94    COSTS_N_BYTES (5)},                  /*                       other */
95   COSTS_N_BYTES (3),                    /* cost of movsx */
96   COSTS_N_BYTES (3),                    /* cost of movzx */
97   0,                                    /* "large" insn */
98   2,                                    /* MOVE_RATIO */
99   2,                                    /* cost for loading QImode using movzbl */
100   {2, 2, 2},                            /* cost of loading integer registers
101                                            in QImode, HImode and SImode.
102                                            Relative to reg-reg move (2).  */
103   {2, 2, 2},                            /* cost of storing integer registers */
104   2,                                    /* cost of reg,reg fld/fst */
105   {2, 2, 2},                            /* cost of loading fp registers
106                                            in SFmode, DFmode and XFmode */
107   {2, 2, 2},                            /* cost of storing fp registers
108                                            in SFmode, DFmode and XFmode */
109   3,                                    /* cost of moving MMX register */
110   {3, 3},                               /* cost of loading MMX registers
111                                            in SImode and DImode */
112   {3, 3},                               /* cost of storing MMX registers
113                                            in SImode and DImode */
114   3,                                    /* cost of moving SSE register */
115   {3, 3, 3},                            /* cost of loading SSE registers
116                                            in SImode, DImode and TImode */
117   {3, 3, 3},                            /* cost of storing SSE registers
118                                            in SImode, DImode and TImode */
119   3,                                    /* MMX or SSE register to integer */
120   0,                                    /* size of l1 cache  */
121   0,                                    /* size of l2 cache  */
122   0,                                    /* size of prefetch block */
123   0,                                    /* number of parallel prefetches */
124   2,                                    /* Branch cost */
125   COSTS_N_BYTES (2),                    /* cost of FADD and FSUB insns.  */
126   COSTS_N_BYTES (2),                    /* cost of FMUL instruction.  */
127   COSTS_N_BYTES (2),                    /* cost of FDIV instruction.  */
128   COSTS_N_BYTES (2),                    /* cost of FABS instruction.  */
129   COSTS_N_BYTES (2),                    /* cost of FCHS instruction.  */
130   COSTS_N_BYTES (2),                    /* cost of FSQRT instruction.  */
131   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
132    {rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}}},
133   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
134    {rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}}},
135   1,                                    /* scalar_stmt_cost.  */
136   1,                                    /* scalar load_cost.  */
137   1,                                    /* scalar_store_cost.  */
138   1,                                    /* vec_stmt_cost.  */
139   1,                                    /* vec_to_scalar_cost.  */
140   1,                                    /* scalar_to_vec_cost.  */
141   1,                                    /* vec_align_load_cost.  */
142   1,                                    /* vec_unalign_load_cost.  */
143   1,                                    /* vec_store_cost.  */
144   1,                                    /* cond_taken_branch_cost.  */
145   1,                                    /* cond_not_taken_branch_cost.  */
146 };
147
148 /* Processor costs (relative to an add) */
149 static const
150 struct processor_costs i386_cost = {    /* 386 specific costs */
151   COSTS_N_INSNS (1),                    /* cost of an add instruction */
152   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
153   COSTS_N_INSNS (3),                    /* variable shift costs */
154   COSTS_N_INSNS (2),                    /* constant shift costs */
155   {COSTS_N_INSNS (6),                   /* cost of starting multiply for QI */
156    COSTS_N_INSNS (6),                   /*                               HI */
157    COSTS_N_INSNS (6),                   /*                               SI */
158    COSTS_N_INSNS (6),                   /*                               DI */
159    COSTS_N_INSNS (6)},                  /*                               other */
160   COSTS_N_INSNS (1),                    /* cost of multiply per each bit set */
161   {COSTS_N_INSNS (23),                  /* cost of a divide/mod for QI */
162    COSTS_N_INSNS (23),                  /*                          HI */
163    COSTS_N_INSNS (23),                  /*                          SI */
164    COSTS_N_INSNS (23),                  /*                          DI */
165    COSTS_N_INSNS (23)},                 /*                          other */
166   COSTS_N_INSNS (3),                    /* cost of movsx */
167   COSTS_N_INSNS (2),                    /* cost of movzx */
168   15,                                   /* "large" insn */
169   3,                                    /* MOVE_RATIO */
170   4,                                    /* cost for loading QImode using movzbl */
171   {2, 4, 2},                            /* cost of loading integer registers
172                                            in QImode, HImode and SImode.
173                                            Relative to reg-reg move (2).  */
174   {2, 4, 2},                            /* cost of storing integer registers */
175   2,                                    /* cost of reg,reg fld/fst */
176   {8, 8, 8},                            /* cost of loading fp registers
177                                            in SFmode, DFmode and XFmode */
178   {8, 8, 8},                            /* cost of storing fp registers
179                                            in SFmode, DFmode and XFmode */
180   2,                                    /* cost of moving MMX register */
181   {4, 8},                               /* cost of loading MMX registers
182                                            in SImode and DImode */
183   {4, 8},                               /* cost of storing MMX registers
184                                            in SImode and DImode */
185   2,                                    /* cost of moving SSE register */
186   {4, 8, 16},                           /* cost of loading SSE registers
187                                            in SImode, DImode and TImode */
188   {4, 8, 16},                           /* cost of storing SSE registers
189                                            in SImode, DImode and TImode */
190   3,                                    /* MMX or SSE register to integer */
191   0,                                    /* size of l1 cache  */
192   0,                                    /* size of l2 cache  */
193   0,                                    /* size of prefetch block */
194   0,                                    /* number of parallel prefetches */
195   1,                                    /* Branch cost */
196   COSTS_N_INSNS (23),                   /* cost of FADD and FSUB insns.  */
197   COSTS_N_INSNS (27),                   /* cost of FMUL instruction.  */
198   COSTS_N_INSNS (88),                   /* cost of FDIV instruction.  */
199   COSTS_N_INSNS (22),                   /* cost of FABS instruction.  */
200   COSTS_N_INSNS (24),                   /* cost of FCHS instruction.  */
201   COSTS_N_INSNS (122),                  /* cost of FSQRT instruction.  */
202   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
203    DUMMY_STRINGOP_ALGS},
204   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
205    DUMMY_STRINGOP_ALGS},
206   1,                                    /* scalar_stmt_cost.  */
207   1,                                    /* scalar load_cost.  */
208   1,                                    /* scalar_store_cost.  */
209   1,                                    /* vec_stmt_cost.  */
210   1,                                    /* vec_to_scalar_cost.  */
211   1,                                    /* scalar_to_vec_cost.  */
212   1,                                    /* vec_align_load_cost.  */
213   2,                                    /* vec_unalign_load_cost.  */
214   1,                                    /* vec_store_cost.  */
215   3,                                    /* cond_taken_branch_cost.  */
216   1,                                    /* cond_not_taken_branch_cost.  */
217 };
218
219 static const
220 struct processor_costs i486_cost = {    /* 486 specific costs */
221   COSTS_N_INSNS (1),                    /* cost of an add instruction */
222   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
223   COSTS_N_INSNS (3),                    /* variable shift costs */
224   COSTS_N_INSNS (2),                    /* constant shift costs */
225   {COSTS_N_INSNS (12),                  /* cost of starting multiply for QI */
226    COSTS_N_INSNS (12),                  /*                               HI */
227    COSTS_N_INSNS (12),                  /*                               SI */
228    COSTS_N_INSNS (12),                  /*                               DI */
229    COSTS_N_INSNS (12)},                 /*                               other */
230   1,                                    /* cost of multiply per each bit set */
231   {COSTS_N_INSNS (40),                  /* cost of a divide/mod for QI */
232    COSTS_N_INSNS (40),                  /*                          HI */
233    COSTS_N_INSNS (40),                  /*                          SI */
234    COSTS_N_INSNS (40),                  /*                          DI */
235    COSTS_N_INSNS (40)},                 /*                          other */
236   COSTS_N_INSNS (3),                    /* cost of movsx */
237   COSTS_N_INSNS (2),                    /* cost of movzx */
238   15,                                   /* "large" insn */
239   3,                                    /* MOVE_RATIO */
240   4,                                    /* cost for loading QImode using movzbl */
241   {2, 4, 2},                            /* cost of loading integer registers
242                                            in QImode, HImode and SImode.
243                                            Relative to reg-reg move (2).  */
244   {2, 4, 2},                            /* cost of storing integer registers */
245   2,                                    /* cost of reg,reg fld/fst */
246   {8, 8, 8},                            /* cost of loading fp registers
247                                            in SFmode, DFmode and XFmode */
248   {8, 8, 8},                            /* cost of storing fp registers
249                                            in SFmode, DFmode and XFmode */
250   2,                                    /* cost of moving MMX register */
251   {4, 8},                               /* cost of loading MMX registers
252                                            in SImode and DImode */
253   {4, 8},                               /* cost of storing MMX registers
254                                            in SImode and DImode */
255   2,                                    /* cost of moving SSE register */
256   {4, 8, 16},                           /* cost of loading SSE registers
257                                            in SImode, DImode and TImode */
258   {4, 8, 16},                           /* cost of storing SSE registers
259                                            in SImode, DImode and TImode */
260   3,                                    /* MMX or SSE register to integer */
261   4,                                    /* size of l1 cache.  486 has 8kB cache
262                                            shared for code and data, so 4kB is
263                                            not really precise.  */
264   4,                                    /* size of l2 cache  */
265   0,                                    /* size of prefetch block */
266   0,                                    /* number of parallel prefetches */
267   1,                                    /* Branch cost */
268   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
269   COSTS_N_INSNS (16),                   /* cost of FMUL instruction.  */
270   COSTS_N_INSNS (73),                   /* cost of FDIV instruction.  */
271   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
272   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
273   COSTS_N_INSNS (83),                   /* cost of FSQRT instruction.  */
274   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
275    DUMMY_STRINGOP_ALGS},
276   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
277    DUMMY_STRINGOP_ALGS},
278   1,                                    /* scalar_stmt_cost.  */
279   1,                                    /* scalar load_cost.  */
280   1,                                    /* scalar_store_cost.  */
281   1,                                    /* vec_stmt_cost.  */
282   1,                                    /* vec_to_scalar_cost.  */
283   1,                                    /* scalar_to_vec_cost.  */
284   1,                                    /* vec_align_load_cost.  */
285   2,                                    /* vec_unalign_load_cost.  */
286   1,                                    /* vec_store_cost.  */
287   3,                                    /* cond_taken_branch_cost.  */
288   1,                                    /* cond_not_taken_branch_cost.  */
289 };
290
291 static const
292 struct processor_costs pentium_cost = {
293   COSTS_N_INSNS (1),                    /* cost of an add instruction */
294   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
295   COSTS_N_INSNS (4),                    /* variable shift costs */
296   COSTS_N_INSNS (1),                    /* constant shift costs */
297   {COSTS_N_INSNS (11),                  /* cost of starting multiply for QI */
298    COSTS_N_INSNS (11),                  /*                               HI */
299    COSTS_N_INSNS (11),                  /*                               SI */
300    COSTS_N_INSNS (11),                  /*                               DI */
301    COSTS_N_INSNS (11)},                 /*                               other */
302   0,                                    /* cost of multiply per each bit set */
303   {COSTS_N_INSNS (25),                  /* cost of a divide/mod for QI */
304    COSTS_N_INSNS (25),                  /*                          HI */
305    COSTS_N_INSNS (25),                  /*                          SI */
306    COSTS_N_INSNS (25),                  /*                          DI */
307    COSTS_N_INSNS (25)},                 /*                          other */
308   COSTS_N_INSNS (3),                    /* cost of movsx */
309   COSTS_N_INSNS (2),                    /* cost of movzx */
310   8,                                    /* "large" insn */
311   6,                                    /* MOVE_RATIO */
312   6,                                    /* cost for loading QImode using movzbl */
313   {2, 4, 2},                            /* cost of loading integer registers
314                                            in QImode, HImode and SImode.
315                                            Relative to reg-reg move (2).  */
316   {2, 4, 2},                            /* cost of storing integer registers */
317   2,                                    /* cost of reg,reg fld/fst */
318   {2, 2, 6},                            /* cost of loading fp registers
319                                            in SFmode, DFmode and XFmode */
320   {4, 4, 6},                            /* cost of storing fp registers
321                                            in SFmode, DFmode and XFmode */
322   8,                                    /* cost of moving MMX register */
323   {8, 8},                               /* cost of loading MMX registers
324                                            in SImode and DImode */
325   {8, 8},                               /* cost of storing MMX registers
326                                            in SImode and DImode */
327   2,                                    /* cost of moving SSE register */
328   {4, 8, 16},                           /* cost of loading SSE registers
329                                            in SImode, DImode and TImode */
330   {4, 8, 16},                           /* cost of storing SSE registers
331                                            in SImode, DImode and TImode */
332   3,                                    /* MMX or SSE register to integer */
333   8,                                    /* size of l1 cache.  */
334   8,                                    /* size of l2 cache  */
335   0,                                    /* size of prefetch block */
336   0,                                    /* number of parallel prefetches */
337   2,                                    /* Branch cost */
338   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
339   COSTS_N_INSNS (3),                    /* cost of FMUL instruction.  */
340   COSTS_N_INSNS (39),                   /* cost of FDIV instruction.  */
341   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
342   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
343   COSTS_N_INSNS (70),                   /* cost of FSQRT instruction.  */
344   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
345    DUMMY_STRINGOP_ALGS},
346   {{libcall, {{-1, rep_prefix_4_byte}}},
347    DUMMY_STRINGOP_ALGS},
348   1,                                    /* scalar_stmt_cost.  */
349   1,                                    /* scalar load_cost.  */
350   1,                                    /* scalar_store_cost.  */
351   1,                                    /* vec_stmt_cost.  */
352   1,                                    /* vec_to_scalar_cost.  */
353   1,                                    /* scalar_to_vec_cost.  */
354   1,                                    /* vec_align_load_cost.  */
355   2,                                    /* vec_unalign_load_cost.  */
356   1,                                    /* vec_store_cost.  */
357   3,                                    /* cond_taken_branch_cost.  */
358   1,                                    /* cond_not_taken_branch_cost.  */
359 };
360
361 static const
362 struct processor_costs pentiumpro_cost = {
363   COSTS_N_INSNS (1),                    /* cost of an add instruction */
364   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
365   COSTS_N_INSNS (1),                    /* variable shift costs */
366   COSTS_N_INSNS (1),                    /* constant shift costs */
367   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
368    COSTS_N_INSNS (4),                   /*                               HI */
369    COSTS_N_INSNS (4),                   /*                               SI */
370    COSTS_N_INSNS (4),                   /*                               DI */
371    COSTS_N_INSNS (4)},                  /*                               other */
372   0,                                    /* cost of multiply per each bit set */
373   {COSTS_N_INSNS (17),                  /* cost of a divide/mod for QI */
374    COSTS_N_INSNS (17),                  /*                          HI */
375    COSTS_N_INSNS (17),                  /*                          SI */
376    COSTS_N_INSNS (17),                  /*                          DI */
377    COSTS_N_INSNS (17)},                 /*                          other */
378   COSTS_N_INSNS (1),                    /* cost of movsx */
379   COSTS_N_INSNS (1),                    /* cost of movzx */
380   8,                                    /* "large" insn */
381   6,                                    /* MOVE_RATIO */
382   2,                                    /* cost for loading QImode using movzbl */
383   {4, 4, 4},                            /* cost of loading integer registers
384                                            in QImode, HImode and SImode.
385                                            Relative to reg-reg move (2).  */
386   {2, 2, 2},                            /* cost of storing integer registers */
387   2,                                    /* cost of reg,reg fld/fst */
388   {2, 2, 6},                            /* cost of loading fp registers
389                                            in SFmode, DFmode and XFmode */
390   {4, 4, 6},                            /* cost of storing fp registers
391                                            in SFmode, DFmode and XFmode */
392   2,                                    /* cost of moving MMX register */
393   {2, 2},                               /* cost of loading MMX registers
394                                            in SImode and DImode */
395   {2, 2},                               /* cost of storing MMX registers
396                                            in SImode and DImode */
397   2,                                    /* cost of moving SSE register */
398   {2, 2, 8},                            /* cost of loading SSE registers
399                                            in SImode, DImode and TImode */
400   {2, 2, 8},                            /* cost of storing SSE registers
401                                            in SImode, DImode and TImode */
402   3,                                    /* MMX or SSE register to integer */
403   8,                                    /* size of l1 cache.  */
404   256,                                  /* size of l2 cache  */
405   32,                                   /* size of prefetch block */
406   6,                                    /* number of parallel prefetches */
407   2,                                    /* Branch cost */
408   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
409   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
410   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
411   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
412   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
413   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
414   /* PentiumPro has optimized rep instructions for blocks aligned by 8 bytes (we ensure
415      the alignment).  For small blocks inline loop is still a noticeable win, for bigger
416      blocks either rep movsl or rep movsb is way to go.  Rep movsb has apparently
417      more expensive startup time in CPU, but after 4K the difference is down in the noise.
418    */
419   {{rep_prefix_4_byte, {{128, loop}, {1024, unrolled_loop},
420                         {8192, rep_prefix_4_byte}, {-1, rep_prefix_1_byte}}},
421    DUMMY_STRINGOP_ALGS},
422   {{rep_prefix_4_byte, {{1024, unrolled_loop},
423                         {8192, rep_prefix_4_byte}, {-1, libcall}}},
424    DUMMY_STRINGOP_ALGS},
425   1,                                    /* scalar_stmt_cost.  */
426   1,                                    /* scalar load_cost.  */
427   1,                                    /* scalar_store_cost.  */
428   1,                                    /* vec_stmt_cost.  */
429   1,                                    /* vec_to_scalar_cost.  */
430   1,                                    /* scalar_to_vec_cost.  */
431   1,                                    /* vec_align_load_cost.  */
432   2,                                    /* vec_unalign_load_cost.  */
433   1,                                    /* vec_store_cost.  */
434   3,                                    /* cond_taken_branch_cost.  */
435   1,                                    /* cond_not_taken_branch_cost.  */
436 };
437
438 static const
439 struct processor_costs geode_cost = {
440   COSTS_N_INSNS (1),                    /* cost of an add instruction */
441   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
442   COSTS_N_INSNS (2),                    /* variable shift costs */
443   COSTS_N_INSNS (1),                    /* constant shift costs */
444   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
445    COSTS_N_INSNS (4),                   /*                               HI */
446    COSTS_N_INSNS (7),                   /*                               SI */
447    COSTS_N_INSNS (7),                   /*                               DI */
448    COSTS_N_INSNS (7)},                  /*                               other */
449   0,                                    /* cost of multiply per each bit set */
450   {COSTS_N_INSNS (15),                  /* cost of a divide/mod for QI */
451    COSTS_N_INSNS (23),                  /*                          HI */
452    COSTS_N_INSNS (39),                  /*                          SI */
453    COSTS_N_INSNS (39),                  /*                          DI */
454    COSTS_N_INSNS (39)},                 /*                          other */
455   COSTS_N_INSNS (1),                    /* cost of movsx */
456   COSTS_N_INSNS (1),                    /* cost of movzx */
457   8,                                    /* "large" insn */
458   4,                                    /* MOVE_RATIO */
459   1,                                    /* cost for loading QImode using movzbl */
460   {1, 1, 1},                            /* cost of loading integer registers
461                                            in QImode, HImode and SImode.
462                                            Relative to reg-reg move (2).  */
463   {1, 1, 1},                            /* cost of storing integer registers */
464   1,                                    /* cost of reg,reg fld/fst */
465   {1, 1, 1},                            /* cost of loading fp registers
466                                            in SFmode, DFmode and XFmode */
467   {4, 6, 6},                            /* cost of storing fp registers
468                                            in SFmode, DFmode and XFmode */
469
470   1,                                    /* cost of moving MMX register */
471   {1, 1},                               /* cost of loading MMX registers
472                                            in SImode and DImode */
473   {1, 1},                               /* cost of storing MMX registers
474                                            in SImode and DImode */
475   1,                                    /* cost of moving SSE register */
476   {1, 1, 1},                            /* cost of loading SSE registers
477                                            in SImode, DImode and TImode */
478   {1, 1, 1},                            /* cost of storing SSE registers
479                                            in SImode, DImode and TImode */
480   1,                                    /* MMX or SSE register to integer */
481   64,                                   /* size of l1 cache.  */
482   128,                                  /* size of l2 cache.  */
483   32,                                   /* size of prefetch block */
484   1,                                    /* number of parallel prefetches */
485   1,                                    /* Branch cost */
486   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
487   COSTS_N_INSNS (11),                   /* cost of FMUL instruction.  */
488   COSTS_N_INSNS (47),                   /* cost of FDIV instruction.  */
489   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
490   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
491   COSTS_N_INSNS (54),                   /* cost of FSQRT instruction.  */
492   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
493    DUMMY_STRINGOP_ALGS},
494   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
495    DUMMY_STRINGOP_ALGS},
496   1,                                    /* scalar_stmt_cost.  */
497   1,                                    /* scalar load_cost.  */
498   1,                                    /* scalar_store_cost.  */
499   1,                                    /* vec_stmt_cost.  */
500   1,                                    /* vec_to_scalar_cost.  */
501   1,                                    /* scalar_to_vec_cost.  */
502   1,                                    /* vec_align_load_cost.  */
503   2,                                    /* vec_unalign_load_cost.  */
504   1,                                    /* vec_store_cost.  */
505   3,                                    /* cond_taken_branch_cost.  */
506   1,                                    /* cond_not_taken_branch_cost.  */
507 };
508
509 static const
510 struct processor_costs k6_cost = {
511   COSTS_N_INSNS (1),                    /* cost of an add instruction */
512   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
513   COSTS_N_INSNS (1),                    /* variable shift costs */
514   COSTS_N_INSNS (1),                    /* constant shift costs */
515   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
516    COSTS_N_INSNS (3),                   /*                               HI */
517    COSTS_N_INSNS (3),                   /*                               SI */
518    COSTS_N_INSNS (3),                   /*                               DI */
519    COSTS_N_INSNS (3)},                  /*                               other */
520   0,                                    /* cost of multiply per each bit set */
521   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
522    COSTS_N_INSNS (18),                  /*                          HI */
523    COSTS_N_INSNS (18),                  /*                          SI */
524    COSTS_N_INSNS (18),                  /*                          DI */
525    COSTS_N_INSNS (18)},                 /*                          other */
526   COSTS_N_INSNS (2),                    /* cost of movsx */
527   COSTS_N_INSNS (2),                    /* cost of movzx */
528   8,                                    /* "large" insn */
529   4,                                    /* MOVE_RATIO */
530   3,                                    /* cost for loading QImode using movzbl */
531   {4, 5, 4},                            /* cost of loading integer registers
532                                            in QImode, HImode and SImode.
533                                            Relative to reg-reg move (2).  */
534   {2, 3, 2},                            /* cost of storing integer registers */
535   4,                                    /* cost of reg,reg fld/fst */
536   {6, 6, 6},                            /* cost of loading fp registers
537                                            in SFmode, DFmode and XFmode */
538   {4, 4, 4},                            /* cost of storing fp registers
539                                            in SFmode, DFmode and XFmode */
540   2,                                    /* cost of moving MMX register */
541   {2, 2},                               /* cost of loading MMX registers
542                                            in SImode and DImode */
543   {2, 2},                               /* cost of storing MMX registers
544                                            in SImode and DImode */
545   2,                                    /* cost of moving SSE register */
546   {2, 2, 8},                            /* cost of loading SSE registers
547                                            in SImode, DImode and TImode */
548   {2, 2, 8},                            /* cost of storing SSE registers
549                                            in SImode, DImode and TImode */
550   6,                                    /* MMX or SSE register to integer */
551   32,                                   /* size of l1 cache.  */
552   32,                                   /* size of l2 cache.  Some models
553                                            have integrated l2 cache, but
554                                            optimizing for k6 is not important
555                                            enough to worry about that.  */
556   32,                                   /* size of prefetch block */
557   1,                                    /* number of parallel prefetches */
558   1,                                    /* Branch cost */
559   COSTS_N_INSNS (2),                    /* cost of FADD and FSUB insns.  */
560   COSTS_N_INSNS (2),                    /* cost of FMUL instruction.  */
561   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
562   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
563   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
564   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
565   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
566    DUMMY_STRINGOP_ALGS},
567   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
568    DUMMY_STRINGOP_ALGS},
569   1,                                    /* scalar_stmt_cost.  */
570   1,                                    /* scalar load_cost.  */
571   1,                                    /* scalar_store_cost.  */
572   1,                                    /* vec_stmt_cost.  */
573   1,                                    /* vec_to_scalar_cost.  */
574   1,                                    /* scalar_to_vec_cost.  */
575   1,                                    /* vec_align_load_cost.  */
576   2,                                    /* vec_unalign_load_cost.  */
577   1,                                    /* vec_store_cost.  */
578   3,                                    /* cond_taken_branch_cost.  */
579   1,                                    /* cond_not_taken_branch_cost.  */
580 };
581
582 static const
583 struct processor_costs athlon_cost = {
584   COSTS_N_INSNS (1),                    /* cost of an add instruction */
585   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
586   COSTS_N_INSNS (1),                    /* variable shift costs */
587   COSTS_N_INSNS (1),                    /* constant shift costs */
588   {COSTS_N_INSNS (5),                   /* cost of starting multiply for QI */
589    COSTS_N_INSNS (5),                   /*                               HI */
590    COSTS_N_INSNS (5),                   /*                               SI */
591    COSTS_N_INSNS (5),                   /*                               DI */
592    COSTS_N_INSNS (5)},                  /*                               other */
593   0,                                    /* cost of multiply per each bit set */
594   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
595    COSTS_N_INSNS (26),                  /*                          HI */
596    COSTS_N_INSNS (42),                  /*                          SI */
597    COSTS_N_INSNS (74),                  /*                          DI */
598    COSTS_N_INSNS (74)},                 /*                          other */
599   COSTS_N_INSNS (1),                    /* cost of movsx */
600   COSTS_N_INSNS (1),                    /* cost of movzx */
601   8,                                    /* "large" insn */
602   9,                                    /* MOVE_RATIO */
603   4,                                    /* cost for loading QImode using movzbl */
604   {3, 4, 3},                            /* cost of loading integer registers
605                                            in QImode, HImode and SImode.
606                                            Relative to reg-reg move (2).  */
607   {3, 4, 3},                            /* cost of storing integer registers */
608   4,                                    /* cost of reg,reg fld/fst */
609   {4, 4, 12},                           /* cost of loading fp registers
610                                            in SFmode, DFmode and XFmode */
611   {6, 6, 8},                            /* cost of storing fp registers
612                                            in SFmode, DFmode and XFmode */
613   2,                                    /* cost of moving MMX register */
614   {4, 4},                               /* cost of loading MMX registers
615                                            in SImode and DImode */
616   {4, 4},                               /* cost of storing MMX registers
617                                            in SImode and DImode */
618   2,                                    /* cost of moving SSE register */
619   {4, 4, 6},                            /* cost of loading SSE registers
620                                            in SImode, DImode and TImode */
621   {4, 4, 5},                            /* cost of storing SSE registers
622                                            in SImode, DImode and TImode */
623   5,                                    /* MMX or SSE register to integer */
624   64,                                   /* size of l1 cache.  */
625   256,                                  /* size of l2 cache.  */
626   64,                                   /* size of prefetch block */
627   6,                                    /* number of parallel prefetches */
628   5,                                    /* Branch cost */
629   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
630   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
631   COSTS_N_INSNS (24),                   /* cost of FDIV instruction.  */
632   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
633   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
634   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
635   /* For some reason, Athlon deals better with REP prefix (relative to loops)
636      compared to K8. Alignment becomes important after 8 bytes for memcpy and
637      128 bytes for memset.  */
638   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
639    DUMMY_STRINGOP_ALGS},
640   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
641    DUMMY_STRINGOP_ALGS},
642   1,                                    /* scalar_stmt_cost.  */
643   1,                                    /* scalar load_cost.  */
644   1,                                    /* scalar_store_cost.  */
645   1,                                    /* vec_stmt_cost.  */
646   1,                                    /* vec_to_scalar_cost.  */
647   1,                                    /* scalar_to_vec_cost.  */
648   1,                                    /* vec_align_load_cost.  */
649   2,                                    /* vec_unalign_load_cost.  */
650   1,                                    /* vec_store_cost.  */
651   3,                                    /* cond_taken_branch_cost.  */
652   1,                                    /* cond_not_taken_branch_cost.  */
653 };
654
655 static const
656 struct processor_costs k8_cost = {
657   COSTS_N_INSNS (1),                    /* cost of an add instruction */
658   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
659   COSTS_N_INSNS (1),                    /* variable shift costs */
660   COSTS_N_INSNS (1),                    /* constant shift costs */
661   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
662    COSTS_N_INSNS (4),                   /*                               HI */
663    COSTS_N_INSNS (3),                   /*                               SI */
664    COSTS_N_INSNS (4),                   /*                               DI */
665    COSTS_N_INSNS (5)},                  /*                               other */
666   0,                                    /* cost of multiply per each bit set */
667   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
668    COSTS_N_INSNS (26),                  /*                          HI */
669    COSTS_N_INSNS (42),                  /*                          SI */
670    COSTS_N_INSNS (74),                  /*                          DI */
671    COSTS_N_INSNS (74)},                 /*                          other */
672   COSTS_N_INSNS (1),                    /* cost of movsx */
673   COSTS_N_INSNS (1),                    /* cost of movzx */
674   8,                                    /* "large" insn */
675   9,                                    /* MOVE_RATIO */
676   4,                                    /* cost for loading QImode using movzbl */
677   {3, 4, 3},                            /* cost of loading integer registers
678                                            in QImode, HImode and SImode.
679                                            Relative to reg-reg move (2).  */
680   {3, 4, 3},                            /* cost of storing integer registers */
681   4,                                    /* cost of reg,reg fld/fst */
682   {4, 4, 12},                           /* cost of loading fp registers
683                                            in SFmode, DFmode and XFmode */
684   {6, 6, 8},                            /* cost of storing fp registers
685                                            in SFmode, DFmode and XFmode */
686   2,                                    /* cost of moving MMX register */
687   {3, 3},                               /* cost of loading MMX registers
688                                            in SImode and DImode */
689   {4, 4},                               /* cost of storing MMX registers
690                                            in SImode and DImode */
691   2,                                    /* cost of moving SSE register */
692   {4, 3, 6},                            /* cost of loading SSE registers
693                                            in SImode, DImode and TImode */
694   {4, 4, 5},                            /* cost of storing SSE registers
695                                            in SImode, DImode and TImode */
696   5,                                    /* MMX or SSE register to integer */
697   64,                                   /* size of l1 cache.  */
698   512,                                  /* size of l2 cache.  */
699   64,                                   /* size of prefetch block */
700   /* New AMD processors never drop prefetches; if they cannot be performed
701      immediately, they are queued.  We set number of simultaneous prefetches
702      to a large constant to reflect this (it probably is not a good idea not
703      to limit number of prefetches at all, as their execution also takes some
704      time).  */
705   100,                                  /* number of parallel prefetches */
706   3,                                    /* Branch cost */
707   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
708   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
709   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
710   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
711   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
712   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
713   /* K8 has optimized REP instruction for medium sized blocks, but for very small
714      blocks it is better to use loop. For large blocks, libcall can do
715      nontemporary accesses and beat inline considerably.  */
716   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
717    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
718   {{libcall, {{8, loop}, {24, unrolled_loop},
719               {2048, rep_prefix_4_byte}, {-1, libcall}}},
720    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
721   4,                                    /* scalar_stmt_cost.  */
722   2,                                    /* scalar load_cost.  */
723   2,                                    /* scalar_store_cost.  */
724   5,                                    /* vec_stmt_cost.  */
725   0,                                    /* vec_to_scalar_cost.  */
726   2,                                    /* scalar_to_vec_cost.  */
727   2,                                    /* vec_align_load_cost.  */
728   3,                                    /* vec_unalign_load_cost.  */
729   3,                                    /* vec_store_cost.  */
730   3,                                    /* cond_taken_branch_cost.  */
731   2,                                    /* cond_not_taken_branch_cost.  */
732 };
733
734 struct processor_costs amdfam10_cost = {
735   COSTS_N_INSNS (1),                    /* cost of an add instruction */
736   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
737   COSTS_N_INSNS (1),                    /* variable shift costs */
738   COSTS_N_INSNS (1),                    /* constant shift costs */
739   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
740    COSTS_N_INSNS (4),                   /*                               HI */
741    COSTS_N_INSNS (3),                   /*                               SI */
742    COSTS_N_INSNS (4),                   /*                               DI */
743    COSTS_N_INSNS (5)},                  /*                               other */
744   0,                                    /* cost of multiply per each bit set */
745   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
746    COSTS_N_INSNS (35),                  /*                          HI */
747    COSTS_N_INSNS (51),                  /*                          SI */
748    COSTS_N_INSNS (83),                  /*                          DI */
749    COSTS_N_INSNS (83)},                 /*                          other */
750   COSTS_N_INSNS (1),                    /* cost of movsx */
751   COSTS_N_INSNS (1),                    /* cost of movzx */
752   8,                                    /* "large" insn */
753   9,                                    /* MOVE_RATIO */
754   4,                                    /* cost for loading QImode using movzbl */
755   {3, 4, 3},                            /* cost of loading integer registers
756                                            in QImode, HImode and SImode.
757                                            Relative to reg-reg move (2).  */
758   {3, 4, 3},                            /* cost of storing integer registers */
759   4,                                    /* cost of reg,reg fld/fst */
760   {4, 4, 12},                           /* cost of loading fp registers
761                                            in SFmode, DFmode and XFmode */
762   {6, 6, 8},                            /* cost of storing fp registers
763                                            in SFmode, DFmode and XFmode */
764   2,                                    /* cost of moving MMX register */
765   {3, 3},                               /* cost of loading MMX registers
766                                            in SImode and DImode */
767   {4, 4},                               /* cost of storing MMX registers
768                                            in SImode and DImode */
769   2,                                    /* cost of moving SSE register */
770   {4, 4, 3},                            /* cost of loading SSE registers
771                                            in SImode, DImode and TImode */
772   {4, 4, 5},                            /* cost of storing SSE registers
773                                            in SImode, DImode and TImode */
774   3,                                    /* MMX or SSE register to integer */
775                                         /* On K8
776                                             MOVD reg64, xmmreg  Double  FSTORE 4
777                                             MOVD reg32, xmmreg  Double  FSTORE 4
778                                            On AMDFAM10
779                                             MOVD reg64, xmmreg  Double  FADD 3
780                                                                 1/1  1/1
781                                             MOVD reg32, xmmreg  Double  FADD 3
782                                                                 1/1  1/1 */
783   64,                                   /* size of l1 cache.  */
784   512,                                  /* size of l2 cache.  */
785   64,                                   /* size of prefetch block */
786   /* New AMD processors never drop prefetches; if they cannot be performed
787      immediately, they are queued.  We set number of simultaneous prefetches
788      to a large constant to reflect this (it probably is not a good idea not
789      to limit number of prefetches at all, as their execution also takes some
790      time).  */
791   100,                                  /* number of parallel prefetches */
792   2,                                    /* Branch cost */
793   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
794   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
795   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
796   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
797   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
798   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
799
800   /* AMDFAM10 has optimized REP instruction for medium sized blocks, but for
801      very small blocks it is better to use loop. For large blocks, libcall can
802      do nontemporary accesses and beat inline considerably.  */
803   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
804    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
805   {{libcall, {{8, loop}, {24, unrolled_loop},
806               {2048, rep_prefix_4_byte}, {-1, libcall}}},
807    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
808   4,                                    /* scalar_stmt_cost.  */
809   2,                                    /* scalar load_cost.  */
810   2,                                    /* scalar_store_cost.  */
811   6,                                    /* vec_stmt_cost.  */
812   0,                                    /* vec_to_scalar_cost.  */
813   2,                                    /* scalar_to_vec_cost.  */
814   2,                                    /* vec_align_load_cost.  */
815   2,                                    /* vec_unalign_load_cost.  */
816   2,                                    /* vec_store_cost.  */
817   2,                                    /* cond_taken_branch_cost.  */
818   1,                                    /* cond_not_taken_branch_cost.  */
819 };
820
821 static const
822 struct processor_costs pentium4_cost = {
823   COSTS_N_INSNS (1),                    /* cost of an add instruction */
824   COSTS_N_INSNS (3),                    /* cost of a lea instruction */
825   COSTS_N_INSNS (4),                    /* variable shift costs */
826   COSTS_N_INSNS (4),                    /* constant shift costs */
827   {COSTS_N_INSNS (15),                  /* cost of starting multiply for QI */
828    COSTS_N_INSNS (15),                  /*                               HI */
829    COSTS_N_INSNS (15),                  /*                               SI */
830    COSTS_N_INSNS (15),                  /*                               DI */
831    COSTS_N_INSNS (15)},                 /*                               other */
832   0,                                    /* cost of multiply per each bit set */
833   {COSTS_N_INSNS (56),                  /* cost of a divide/mod for QI */
834    COSTS_N_INSNS (56),                  /*                          HI */
835    COSTS_N_INSNS (56),                  /*                          SI */
836    COSTS_N_INSNS (56),                  /*                          DI */
837    COSTS_N_INSNS (56)},                 /*                          other */
838   COSTS_N_INSNS (1),                    /* cost of movsx */
839   COSTS_N_INSNS (1),                    /* cost of movzx */
840   16,                                   /* "large" insn */
841   6,                                    /* MOVE_RATIO */
842   2,                                    /* cost for loading QImode using movzbl */
843   {4, 5, 4},                            /* cost of loading integer registers
844                                            in QImode, HImode and SImode.
845                                            Relative to reg-reg move (2).  */
846   {2, 3, 2},                            /* cost of storing integer registers */
847   2,                                    /* cost of reg,reg fld/fst */
848   {2, 2, 6},                            /* cost of loading fp registers
849                                            in SFmode, DFmode and XFmode */
850   {4, 4, 6},                            /* cost of storing fp registers
851                                            in SFmode, DFmode and XFmode */
852   2,                                    /* cost of moving MMX register */
853   {2, 2},                               /* cost of loading MMX registers
854                                            in SImode and DImode */
855   {2, 2},                               /* cost of storing MMX registers
856                                            in SImode and DImode */
857   12,                                   /* cost of moving SSE register */
858   {12, 12, 12},                         /* cost of loading SSE registers
859                                            in SImode, DImode and TImode */
860   {2, 2, 8},                            /* cost of storing SSE registers
861                                            in SImode, DImode and TImode */
862   10,                                   /* MMX or SSE register to integer */
863   8,                                    /* size of l1 cache.  */
864   256,                                  /* size of l2 cache.  */
865   64,                                   /* size of prefetch block */
866   6,                                    /* number of parallel prefetches */
867   2,                                    /* Branch cost */
868   COSTS_N_INSNS (5),                    /* cost of FADD and FSUB insns.  */
869   COSTS_N_INSNS (7),                    /* cost of FMUL instruction.  */
870   COSTS_N_INSNS (43),                   /* cost of FDIV instruction.  */
871   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
872   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
873   COSTS_N_INSNS (43),                   /* cost of FSQRT instruction.  */
874   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
875    DUMMY_STRINGOP_ALGS},
876   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
877    {-1, libcall}}},
878    DUMMY_STRINGOP_ALGS},
879   1,                                    /* scalar_stmt_cost.  */
880   1,                                    /* scalar load_cost.  */
881   1,                                    /* scalar_store_cost.  */
882   1,                                    /* vec_stmt_cost.  */
883   1,                                    /* vec_to_scalar_cost.  */
884   1,                                    /* scalar_to_vec_cost.  */
885   1,                                    /* vec_align_load_cost.  */
886   2,                                    /* vec_unalign_load_cost.  */
887   1,                                    /* vec_store_cost.  */
888   3,                                    /* cond_taken_branch_cost.  */
889   1,                                    /* cond_not_taken_branch_cost.  */
890 };
891
892 static const
893 struct processor_costs nocona_cost = {
894   COSTS_N_INSNS (1),                    /* cost of an add instruction */
895   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
896   COSTS_N_INSNS (1),                    /* variable shift costs */
897   COSTS_N_INSNS (1),                    /* constant shift costs */
898   {COSTS_N_INSNS (10),                  /* cost of starting multiply for QI */
899    COSTS_N_INSNS (10),                  /*                               HI */
900    COSTS_N_INSNS (10),                  /*                               SI */
901    COSTS_N_INSNS (10),                  /*                               DI */
902    COSTS_N_INSNS (10)},                 /*                               other */
903   0,                                    /* cost of multiply per each bit set */
904   {COSTS_N_INSNS (66),                  /* cost of a divide/mod for QI */
905    COSTS_N_INSNS (66),                  /*                          HI */
906    COSTS_N_INSNS (66),                  /*                          SI */
907    COSTS_N_INSNS (66),                  /*                          DI */
908    COSTS_N_INSNS (66)},                 /*                          other */
909   COSTS_N_INSNS (1),                    /* cost of movsx */
910   COSTS_N_INSNS (1),                    /* cost of movzx */
911   16,                                   /* "large" insn */
912   17,                                   /* MOVE_RATIO */
913   4,                                    /* cost for loading QImode using movzbl */
914   {4, 4, 4},                            /* cost of loading integer registers
915                                            in QImode, HImode and SImode.
916                                            Relative to reg-reg move (2).  */
917   {4, 4, 4},                            /* cost of storing integer registers */
918   3,                                    /* cost of reg,reg fld/fst */
919   {12, 12, 12},                         /* cost of loading fp registers
920                                            in SFmode, DFmode and XFmode */
921   {4, 4, 4},                            /* cost of storing fp registers
922                                            in SFmode, DFmode and XFmode */
923   6,                                    /* cost of moving MMX register */
924   {12, 12},                             /* cost of loading MMX registers
925                                            in SImode and DImode */
926   {12, 12},                             /* cost of storing MMX registers
927                                            in SImode and DImode */
928   6,                                    /* cost of moving SSE register */
929   {12, 12, 12},                         /* cost of loading SSE registers
930                                            in SImode, DImode and TImode */
931   {12, 12, 12},                         /* cost of storing SSE registers
932                                            in SImode, DImode and TImode */
933   8,                                    /* MMX or SSE register to integer */
934   8,                                    /* size of l1 cache.  */
935   1024,                                 /* size of l2 cache.  */
936   128,                                  /* size of prefetch block */
937   8,                                    /* number of parallel prefetches */
938   1,                                    /* Branch cost */
939   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
940   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
941   COSTS_N_INSNS (40),                   /* cost of FDIV instruction.  */
942   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
943   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
944   COSTS_N_INSNS (44),                   /* cost of FSQRT instruction.  */
945   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
946    {libcall, {{32, loop}, {20000, rep_prefix_8_byte},
947               {100000, unrolled_loop}, {-1, libcall}}}},
948   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
949    {-1, libcall}}},
950    {libcall, {{24, loop}, {64, unrolled_loop},
951               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
952   1,                                    /* scalar_stmt_cost.  */
953   1,                                    /* scalar load_cost.  */
954   1,                                    /* scalar_store_cost.  */
955   1,                                    /* vec_stmt_cost.  */
956   1,                                    /* vec_to_scalar_cost.  */
957   1,                                    /* scalar_to_vec_cost.  */
958   1,                                    /* vec_align_load_cost.  */
959   2,                                    /* vec_unalign_load_cost.  */
960   1,                                    /* vec_store_cost.  */
961   3,                                    /* cond_taken_branch_cost.  */
962   1,                                    /* cond_not_taken_branch_cost.  */
963 };
964
965 static const
966 struct processor_costs core2_cost = {
967   COSTS_N_INSNS (1),                    /* cost of an add instruction */
968   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
969   COSTS_N_INSNS (1),                    /* variable shift costs */
970   COSTS_N_INSNS (1),                    /* constant shift costs */
971   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
972    COSTS_N_INSNS (3),                   /*                               HI */
973    COSTS_N_INSNS (3),                   /*                               SI */
974    COSTS_N_INSNS (3),                   /*                               DI */
975    COSTS_N_INSNS (3)},                  /*                               other */
976   0,                                    /* cost of multiply per each bit set */
977   {COSTS_N_INSNS (22),                  /* cost of a divide/mod for QI */
978    COSTS_N_INSNS (22),                  /*                          HI */
979    COSTS_N_INSNS (22),                  /*                          SI */
980    COSTS_N_INSNS (22),                  /*                          DI */
981    COSTS_N_INSNS (22)},                 /*                          other */
982   COSTS_N_INSNS (1),                    /* cost of movsx */
983   COSTS_N_INSNS (1),                    /* cost of movzx */
984   8,                                    /* "large" insn */
985   16,                                   /* MOVE_RATIO */
986   2,                                    /* cost for loading QImode using movzbl */
987   {6, 6, 6},                            /* cost of loading integer registers
988                                            in QImode, HImode and SImode.
989                                            Relative to reg-reg move (2).  */
990   {4, 4, 4},                            /* cost of storing integer registers */
991   2,                                    /* cost of reg,reg fld/fst */
992   {6, 6, 6},                            /* cost of loading fp registers
993                                            in SFmode, DFmode and XFmode */
994   {4, 4, 4},                            /* cost of loading integer registers */
995   2,                                    /* cost of moving MMX register */
996   {6, 6},                               /* cost of loading MMX registers
997                                            in SImode and DImode */
998   {4, 4},                               /* cost of storing MMX registers
999                                            in SImode and DImode */
1000   2,                                    /* cost of moving SSE register */
1001   {6, 6, 6},                            /* cost of loading SSE registers
1002                                            in SImode, DImode and TImode */
1003   {4, 4, 4},                            /* cost of storing SSE registers
1004                                            in SImode, DImode and TImode */
1005   2,                                    /* MMX or SSE register to integer */
1006   32,                                   /* size of l1 cache.  */
1007   2048,                                 /* size of l2 cache.  */
1008   128,                                  /* size of prefetch block */
1009   8,                                    /* number of parallel prefetches */
1010   3,                                    /* Branch cost */
1011   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
1012   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
1013   COSTS_N_INSNS (32),                   /* cost of FDIV instruction.  */
1014   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
1015   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
1016   COSTS_N_INSNS (58),                   /* cost of FSQRT instruction.  */
1017   {{libcall, {{11, loop}, {-1, rep_prefix_4_byte}}},
1018    {libcall, {{32, loop}, {64, rep_prefix_4_byte},
1019               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1020   {{libcall, {{8, loop}, {15, unrolled_loop},
1021               {2048, rep_prefix_4_byte}, {-1, libcall}}},
1022    {libcall, {{24, loop}, {32, unrolled_loop},
1023               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1024   1,                                    /* scalar_stmt_cost.  */
1025   1,                                    /* scalar load_cost.  */
1026   1,                                    /* scalar_store_cost.  */
1027   1,                                    /* vec_stmt_cost.  */
1028   1,                                    /* vec_to_scalar_cost.  */
1029   1,                                    /* scalar_to_vec_cost.  */
1030   1,                                    /* vec_align_load_cost.  */
1031   2,                                    /* vec_unalign_load_cost.  */
1032   1,                                    /* vec_store_cost.  */
1033   3,                                    /* cond_taken_branch_cost.  */
1034   1,                                    /* cond_not_taken_branch_cost.  */
1035 };
1036
1037 /* Generic64 should produce code tuned for Nocona and K8.  */
1038 static const
1039 struct processor_costs generic64_cost = {
1040   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1041   /* On all chips taken into consideration lea is 2 cycles and more.  With
1042      this cost however our current implementation of synth_mult results in
1043      use of unnecessary temporary registers causing regression on several
1044      SPECfp benchmarks.  */
1045   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1046   COSTS_N_INSNS (1),                    /* variable shift costs */
1047   COSTS_N_INSNS (1),                    /* constant shift costs */
1048   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1049    COSTS_N_INSNS (4),                   /*                               HI */
1050    COSTS_N_INSNS (3),                   /*                               SI */
1051    COSTS_N_INSNS (4),                   /*                               DI */
1052    COSTS_N_INSNS (2)},                  /*                               other */
1053   0,                                    /* cost of multiply per each bit set */
1054   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1055    COSTS_N_INSNS (26),                  /*                          HI */
1056    COSTS_N_INSNS (42),                  /*                          SI */
1057    COSTS_N_INSNS (74),                  /*                          DI */
1058    COSTS_N_INSNS (74)},                 /*                          other */
1059   COSTS_N_INSNS (1),                    /* cost of movsx */
1060   COSTS_N_INSNS (1),                    /* cost of movzx */
1061   8,                                    /* "large" insn */
1062   17,                                   /* MOVE_RATIO */
1063   4,                                    /* cost for loading QImode using movzbl */
1064   {4, 4, 4},                            /* cost of loading integer registers
1065                                            in QImode, HImode and SImode.
1066                                            Relative to reg-reg move (2).  */
1067   {4, 4, 4},                            /* cost of storing integer registers */
1068   4,                                    /* cost of reg,reg fld/fst */
1069   {12, 12, 12},                         /* cost of loading fp registers
1070                                            in SFmode, DFmode and XFmode */
1071   {6, 6, 8},                            /* cost of storing fp registers
1072                                            in SFmode, DFmode and XFmode */
1073   2,                                    /* cost of moving MMX register */
1074   {8, 8},                               /* cost of loading MMX registers
1075                                            in SImode and DImode */
1076   {8, 8},                               /* cost of storing MMX registers
1077                                            in SImode and DImode */
1078   2,                                    /* cost of moving SSE register */
1079   {8, 8, 8},                            /* cost of loading SSE registers
1080                                            in SImode, DImode and TImode */
1081   {8, 8, 8},                            /* cost of storing SSE registers
1082                                            in SImode, DImode and TImode */
1083   5,                                    /* MMX or SSE register to integer */
1084   32,                                   /* size of l1 cache.  */
1085   512,                                  /* size of l2 cache.  */
1086   64,                                   /* size of prefetch block */
1087   6,                                    /* number of parallel prefetches */
1088   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this value
1089      is increased to perhaps more appropriate value of 5.  */
1090   3,                                    /* Branch cost */
1091   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1092   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1093   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1094   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1095   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1096   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1097   {DUMMY_STRINGOP_ALGS,
1098    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1099   {DUMMY_STRINGOP_ALGS,
1100    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1101   1,                                    /* scalar_stmt_cost.  */
1102   1,                                    /* scalar load_cost.  */
1103   1,                                    /* scalar_store_cost.  */
1104   1,                                    /* vec_stmt_cost.  */
1105   1,                                    /* vec_to_scalar_cost.  */
1106   1,                                    /* scalar_to_vec_cost.  */
1107   1,                                    /* vec_align_load_cost.  */
1108   2,                                    /* vec_unalign_load_cost.  */
1109   1,                                    /* vec_store_cost.  */
1110   3,                                    /* cond_taken_branch_cost.  */
1111   1,                                    /* cond_not_taken_branch_cost.  */
1112 };
1113
1114 /* Generic32 should produce code tuned for Athlon, PPro, Pentium4, Nocona and K8.  */
1115 static const
1116 struct processor_costs generic32_cost = {
1117   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1118   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1119   COSTS_N_INSNS (1),                    /* variable shift costs */
1120   COSTS_N_INSNS (1),                    /* constant shift costs */
1121   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1122    COSTS_N_INSNS (4),                   /*                               HI */
1123    COSTS_N_INSNS (3),                   /*                               SI */
1124    COSTS_N_INSNS (4),                   /*                               DI */
1125    COSTS_N_INSNS (2)},                  /*                               other */
1126   0,                                    /* cost of multiply per each bit set */
1127   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1128    COSTS_N_INSNS (26),                  /*                          HI */
1129    COSTS_N_INSNS (42),                  /*                          SI */
1130    COSTS_N_INSNS (74),                  /*                          DI */
1131    COSTS_N_INSNS (74)},                 /*                          other */
1132   COSTS_N_INSNS (1),                    /* cost of movsx */
1133   COSTS_N_INSNS (1),                    /* cost of movzx */
1134   8,                                    /* "large" insn */
1135   17,                                   /* MOVE_RATIO */
1136   4,                                    /* cost for loading QImode using movzbl */
1137   {4, 4, 4},                            /* cost of loading integer registers
1138                                            in QImode, HImode and SImode.
1139                                            Relative to reg-reg move (2).  */
1140   {4, 4, 4},                            /* cost of storing integer registers */
1141   4,                                    /* cost of reg,reg fld/fst */
1142   {12, 12, 12},                         /* cost of loading fp registers
1143                                            in SFmode, DFmode and XFmode */
1144   {6, 6, 8},                            /* cost of storing fp registers
1145                                            in SFmode, DFmode and XFmode */
1146   2,                                    /* cost of moving MMX register */
1147   {8, 8},                               /* cost of loading MMX registers
1148                                            in SImode and DImode */
1149   {8, 8},                               /* cost of storing MMX registers
1150                                            in SImode and DImode */
1151   2,                                    /* cost of moving SSE register */
1152   {8, 8, 8},                            /* cost of loading SSE registers
1153                                            in SImode, DImode and TImode */
1154   {8, 8, 8},                            /* cost of storing SSE registers
1155                                            in SImode, DImode and TImode */
1156   5,                                    /* MMX or SSE register to integer */
1157   32,                                   /* size of l1 cache.  */
1158   256,                                  /* size of l2 cache.  */
1159   64,                                   /* size of prefetch block */
1160   6,                                    /* number of parallel prefetches */
1161   3,                                    /* Branch cost */
1162   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1163   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1164   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1165   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1166   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1167   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1168   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1169    DUMMY_STRINGOP_ALGS},
1170   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1171    DUMMY_STRINGOP_ALGS},
1172   1,                                    /* scalar_stmt_cost.  */
1173   1,                                    /* scalar load_cost.  */
1174   1,                                    /* scalar_store_cost.  */
1175   1,                                    /* vec_stmt_cost.  */
1176   1,                                    /* vec_to_scalar_cost.  */
1177   1,                                    /* scalar_to_vec_cost.  */
1178   1,                                    /* vec_align_load_cost.  */
1179   2,                                    /* vec_unalign_load_cost.  */
1180   1,                                    /* vec_store_cost.  */
1181   3,                                    /* cond_taken_branch_cost.  */
1182   1,                                    /* cond_not_taken_branch_cost.  */
1183 };
1184
1185 const struct processor_costs *ix86_cost = &pentium_cost;
1186
1187 /* Processor feature/optimization bitmasks.  */
1188 #define m_386 (1<<PROCESSOR_I386)
1189 #define m_486 (1<<PROCESSOR_I486)
1190 #define m_PENT (1<<PROCESSOR_PENTIUM)
1191 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
1192 #define m_PENT4  (1<<PROCESSOR_PENTIUM4)
1193 #define m_NOCONA  (1<<PROCESSOR_NOCONA)
1194 #define m_CORE2  (1<<PROCESSOR_CORE2)
1195
1196 #define m_GEODE  (1<<PROCESSOR_GEODE)
1197 #define m_K6  (1<<PROCESSOR_K6)
1198 #define m_K6_GEODE  (m_K6 | m_GEODE)
1199 #define m_K8  (1<<PROCESSOR_K8)
1200 #define m_ATHLON  (1<<PROCESSOR_ATHLON)
1201 #define m_ATHLON_K8  (m_K8 | m_ATHLON)
1202 #define m_AMDFAM10  (1<<PROCESSOR_AMDFAM10)
1203 #define m_AMD_MULTIPLE  (m_K8 | m_ATHLON | m_AMDFAM10)
1204
1205 #define m_GENERIC32 (1<<PROCESSOR_GENERIC32)
1206 #define m_GENERIC64 (1<<PROCESSOR_GENERIC64)
1207
1208 /* Generic instruction choice should be common subset of supported CPUs
1209    (PPro/PENT4/NOCONA/CORE2/Athlon/K8).  */
1210 #define m_GENERIC (m_GENERIC32 | m_GENERIC64)
1211
1212 /* Feature tests against the various tunings.  */
1213 unsigned char ix86_tune_features[X86_TUNE_LAST];
1214
1215 /* Feature tests against the various tunings used to create ix86_tune_features
1216    based on the processor mask.  */
1217 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
1218   /* X86_TUNE_USE_LEAVE: Leave does not affect Nocona SPEC2000 results
1219      negatively, so enabling for Generic64 seems like good code size
1220      tradeoff.  We can't enable it for 32bit generic because it does not
1221      work well with PPro base chips.  */
1222   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_CORE2 | m_GENERIC64,
1223
1224   /* X86_TUNE_PUSH_MEMORY */
1225   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4
1226   | m_NOCONA | m_CORE2 | m_GENERIC,
1227
1228   /* X86_TUNE_ZERO_EXTEND_WITH_AND */
1229   m_486 | m_PENT,
1230
1231   /* X86_TUNE_USE_BIT_TEST */
1232   m_386,
1233
1234   /* X86_TUNE_UNROLL_STRLEN */
1235   m_486 | m_PENT | m_PPRO | m_AMD_MULTIPLE | m_K6 | m_CORE2 | m_GENERIC,
1236
1237   /* X86_TUNE_DEEP_BRANCH_PREDICTION */
1238   m_PPRO | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4 | m_GENERIC,
1239
1240   /* X86_TUNE_BRANCH_PREDICTION_HINTS: Branch hints were put in P4 based
1241      on simulation result. But after P4 was made, no performance benefit
1242      was observed with branch hints.  It also increases the code size.
1243      As a result, icc never generates branch hints.  */
1244   0,
1245
1246   /* X86_TUNE_DOUBLE_WITH_ADD */
1247   ~m_386,
1248
1249   /* X86_TUNE_USE_SAHF */
1250   m_PPRO | m_K6_GEODE | m_K8 | m_AMDFAM10 | m_PENT4
1251   | m_NOCONA | m_CORE2 | m_GENERIC,
1252
1253   /* X86_TUNE_MOVX: Enable to zero extend integer registers to avoid
1254      partial dependencies.  */
1255   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA
1256   | m_CORE2 | m_GENERIC | m_GEODE /* m_386 | m_K6 */,
1257
1258   /* X86_TUNE_PARTIAL_REG_STALL: We probably ought to watch for partial
1259      register stalls on Generic32 compilation setting as well.  However
1260      in current implementation the partial register stalls are not eliminated
1261      very well - they can be introduced via subregs synthesized by combine
1262      and can happen in caller/callee saving sequences.  Because this option
1263      pays back little on PPro based chips and is in conflict with partial reg
1264      dependencies used by Athlon/P4 based chips, it is better to leave it off
1265      for generic32 for now.  */
1266   m_PPRO,
1267
1268   /* X86_TUNE_PARTIAL_FLAG_REG_STALL */
1269   m_CORE2 | m_GENERIC,
1270
1271   /* X86_TUNE_USE_HIMODE_FIOP */
1272   m_386 | m_486 | m_K6_GEODE,
1273
1274   /* X86_TUNE_USE_SIMODE_FIOP */
1275   ~(m_PPRO | m_AMD_MULTIPLE | m_PENT | m_CORE2 | m_GENERIC),
1276
1277   /* X86_TUNE_USE_MOV0 */
1278   m_K6,
1279
1280   /* X86_TUNE_USE_CLTD */
1281   ~(m_PENT | m_K6 | m_CORE2 | m_GENERIC),
1282
1283   /* X86_TUNE_USE_XCHGB: Use xchgb %rh,%rl instead of rolw/rorw $8,rx.  */
1284   m_PENT4,
1285
1286   /* X86_TUNE_SPLIT_LONG_MOVES */
1287   m_PPRO,
1288
1289   /* X86_TUNE_READ_MODIFY_WRITE */
1290   ~m_PENT,
1291
1292   /* X86_TUNE_READ_MODIFY */
1293   ~(m_PENT | m_PPRO),
1294
1295   /* X86_TUNE_PROMOTE_QIMODE */
1296   m_K6_GEODE | m_PENT | m_386 | m_486 | m_AMD_MULTIPLE | m_CORE2
1297   | m_GENERIC /* | m_PENT4 ? */,
1298
1299   /* X86_TUNE_FAST_PREFIX */
1300   ~(m_PENT | m_486 | m_386),
1301
1302   /* X86_TUNE_SINGLE_STRINGOP */
1303   m_386 | m_PENT4 | m_NOCONA,
1304
1305   /* X86_TUNE_QIMODE_MATH */
1306   ~0,
1307
1308   /* X86_TUNE_HIMODE_MATH: On PPro this flag is meant to avoid partial
1309      register stalls.  Just like X86_TUNE_PARTIAL_REG_STALL this option
1310      might be considered for Generic32 if our scheme for avoiding partial
1311      stalls was more effective.  */
1312   ~m_PPRO,
1313
1314   /* X86_TUNE_PROMOTE_QI_REGS */
1315   0,
1316
1317   /* X86_TUNE_PROMOTE_HI_REGS */
1318   m_PPRO,
1319
1320   /* X86_TUNE_ADD_ESP_4: Enable if add/sub is preferred over 1/2 push/pop.  */
1321   m_AMD_MULTIPLE | m_K6_GEODE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1322
1323   /* X86_TUNE_ADD_ESP_8 */
1324   m_AMD_MULTIPLE | m_PPRO | m_K6_GEODE | m_386
1325   | m_486 | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1326
1327   /* X86_TUNE_SUB_ESP_4 */
1328   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1329
1330   /* X86_TUNE_SUB_ESP_8 */
1331   m_AMD_MULTIPLE | m_PPRO | m_386 | m_486
1332   | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1333
1334   /* X86_TUNE_INTEGER_DFMODE_MOVES: Enable if integer moves are preferred
1335      for DFmode copies */
1336   ~(m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2
1337     | m_GENERIC | m_GEODE),
1338
1339   /* X86_TUNE_PARTIAL_REG_DEPENDENCY */
1340   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1341
1342   /* X86_TUNE_SSE_PARTIAL_REG_DEPENDENCY: In the Generic model we have a
1343      conflict here in between PPro/Pentium4 based chips that thread 128bit
1344      SSE registers as single units versus K8 based chips that divide SSE
1345      registers to two 64bit halves.  This knob promotes all store destinations
1346      to be 128bit to allow register renaming on 128bit SSE units, but usually
1347      results in one extra microop on 64bit SSE units.  Experimental results
1348      shows that disabling this option on P4 brings over 20% SPECfp regression,
1349      while enabling it on K8 brings roughly 2.4% regression that can be partly
1350      masked by careful scheduling of moves.  */
1351   m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC | m_AMDFAM10,
1352
1353   /* X86_TUNE_SSE_UNALIGNED_MOVE_OPTIMAL */
1354   m_AMDFAM10,
1355
1356   /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
1357      are resolved on SSE register parts instead of whole registers, so we may
1358      maintain just lower part of scalar values in proper format leaving the
1359      upper part undefined.  */
1360   m_ATHLON_K8,
1361
1362   /* X86_TUNE_SSE_TYPELESS_STORES */
1363   m_AMD_MULTIPLE,
1364
1365   /* X86_TUNE_SSE_LOAD0_BY_PXOR */
1366   m_PPRO | m_PENT4 | m_NOCONA,
1367
1368   /* X86_TUNE_MEMORY_MISMATCH_STALL */
1369   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1370
1371   /* X86_TUNE_PROLOGUE_USING_MOVE */
1372   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1373
1374   /* X86_TUNE_EPILOGUE_USING_MOVE */
1375   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1376
1377   /* X86_TUNE_SHIFT1 */
1378   ~m_486,
1379
1380   /* X86_TUNE_USE_FFREEP */
1381   m_AMD_MULTIPLE,
1382
1383   /* X86_TUNE_INTER_UNIT_MOVES */
1384   ~(m_AMD_MULTIPLE | m_GENERIC),
1385
1386   /* X86_TUNE_INTER_UNIT_CONVERSIONS */
1387   ~(m_AMDFAM10),
1388
1389   /* X86_TUNE_FOUR_JUMP_LIMIT: Some CPU cores are not able to predict more
1390      than 4 branch instructions in the 16 byte window.  */
1391   m_PPRO | m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1392
1393   /* X86_TUNE_SCHEDULE */
1394   m_PPRO | m_AMD_MULTIPLE | m_K6_GEODE | m_PENT | m_CORE2 | m_GENERIC,
1395
1396   /* X86_TUNE_USE_BT */
1397   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1398
1399   /* X86_TUNE_USE_INCDEC */
1400   ~(m_PENT4 | m_NOCONA | m_GENERIC),
1401
1402   /* X86_TUNE_PAD_RETURNS */
1403   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1404
1405   /* X86_TUNE_EXT_80387_CONSTANTS */
1406   m_K6_GEODE | m_ATHLON_K8 | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC,
1407
1408   /* X86_TUNE_SHORTEN_X87_SSE */
1409   ~m_K8,
1410
1411   /* X86_TUNE_AVOID_VECTOR_DECODE */
1412   m_K8 | m_GENERIC64,
1413
1414   /* X86_TUNE_PROMOTE_HIMODE_IMUL: Modern CPUs have same latency for HImode
1415      and SImode multiply, but 386 and 486 do HImode multiply faster.  */
1416   ~(m_386 | m_486),
1417
1418   /* X86_TUNE_SLOW_IMUL_IMM32_MEM: Imul of 32-bit constant and memory is
1419      vector path on AMD machines.  */
1420   m_K8 | m_GENERIC64 | m_AMDFAM10,
1421
1422   /* X86_TUNE_SLOW_IMUL_IMM8: Imul of 8-bit constant is vector path on AMD
1423      machines.  */
1424   m_K8 | m_GENERIC64 | m_AMDFAM10,
1425
1426   /* X86_TUNE_MOVE_M1_VIA_OR: On pentiums, it is faster to load -1 via OR
1427      than a MOV.  */
1428   m_PENT,
1429
1430   /* X86_TUNE_NOT_UNPAIRABLE: NOT is not pairable on Pentium, while XOR is,
1431      but one byte longer.  */
1432   m_PENT,
1433
1434   /* X86_TUNE_NOT_VECTORMODE: On AMD K6, NOT is vector decoded with memory
1435      operand that cannot be represented using a modRM byte.  The XOR
1436      replacement is long decoded, so this split helps here as well.  */
1437   m_K6,
1438
1439   /* X86_TUNE_USE_VECTOR_CONVERTS: Prefer vector packed SSE conversion
1440      from integer to FP. */
1441   m_AMDFAM10,
1442
1443   /* X86_TUNE_FUSE_CMP_AND_BRANCH: Fuse a compare or test instruction
1444      with a subsequent conditional jump instruction into a single
1445      compare-and-branch uop.  */
1446   m_CORE2,
1447 };
1448
1449 /* Feature tests against the various architecture variations.  */
1450 unsigned char ix86_arch_features[X86_ARCH_LAST];
1451
1452 /* Feature tests against the various architecture variations, used to create
1453    ix86_arch_features based on the processor mask.  */
1454 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
1455   /* X86_ARCH_CMOVE: Conditional move was added for pentiumpro.  */
1456   ~(m_386 | m_486 | m_PENT | m_K6),
1457
1458   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
1459   ~m_386,
1460
1461   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
1462   ~(m_386 | m_486),
1463
1464   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
1465   ~m_386,
1466
1467   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
1468   ~m_386,
1469 };
1470
1471 static const unsigned int x86_accumulate_outgoing_args
1472   = m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC;
1473
1474 static const unsigned int x86_arch_always_fancy_math_387
1475   = m_PENT | m_PPRO | m_AMD_MULTIPLE | m_PENT4
1476     | m_NOCONA | m_CORE2 | m_GENERIC;
1477
1478 static enum stringop_alg stringop_alg = no_stringop;
1479
1480 /* In case the average insn count for single function invocation is
1481    lower than this constant, emit fast (but longer) prologue and
1482    epilogue code.  */
1483 #define FAST_PROLOGUE_INSN_COUNT 20
1484
1485 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
1486 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
1487 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
1488 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
1489
1490 /* Array of the smallest class containing reg number REGNO, indexed by
1491    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
1492
1493 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
1494 {
1495   /* ax, dx, cx, bx */
1496   AREG, DREG, CREG, BREG,
1497   /* si, di, bp, sp */
1498   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
1499   /* FP registers */
1500   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
1501   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
1502   /* arg pointer */
1503   NON_Q_REGS,
1504   /* flags, fpsr, fpcr, frame */
1505   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
1506   /* SSE registers */
1507   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1508   SSE_REGS, SSE_REGS,
1509   /* MMX registers */
1510   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
1511   MMX_REGS, MMX_REGS,
1512   /* REX registers */
1513   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1514   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1515   /* SSE REX registers */
1516   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1517   SSE_REGS, SSE_REGS,
1518 };
1519
1520 /* The "default" register map used in 32bit mode.  */
1521
1522 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
1523 {
1524   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
1525   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
1526   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1527   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
1528   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
1529   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1530   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1531 };
1532
1533 static int const x86_64_int_parameter_registers[6] =
1534 {
1535   5 /*RDI*/, 4 /*RSI*/, 1 /*RDX*/, 2 /*RCX*/,
1536   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1537 };
1538
1539 static int const x86_64_ms_abi_int_parameter_registers[4] =
1540 {
1541   2 /*RCX*/, 1 /*RDX*/,
1542   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1543 };
1544
1545 static int const x86_64_int_return_registers[4] =
1546 {
1547   0 /*RAX*/, 1 /*RDX*/, 5 /*RDI*/, 4 /*RSI*/
1548 };
1549
1550 /* The "default" register map used in 64bit mode.  */
1551 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
1552 {
1553   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
1554   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
1555   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1556   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
1557   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
1558   8,9,10,11,12,13,14,15,                /* extended integer registers */
1559   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
1560 };
1561
1562 /* Define the register numbers to be used in Dwarf debugging information.
1563    The SVR4 reference port C compiler uses the following register numbers
1564    in its Dwarf output code:
1565         0 for %eax (gcc regno = 0)
1566         1 for %ecx (gcc regno = 2)
1567         2 for %edx (gcc regno = 1)
1568         3 for %ebx (gcc regno = 3)
1569         4 for %esp (gcc regno = 7)
1570         5 for %ebp (gcc regno = 6)
1571         6 for %esi (gcc regno = 4)
1572         7 for %edi (gcc regno = 5)
1573    The following three DWARF register numbers are never generated by
1574    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
1575    believes these numbers have these meanings.
1576         8  for %eip    (no gcc equivalent)
1577         9  for %eflags (gcc regno = 17)
1578         10 for %trapno (no gcc equivalent)
1579    It is not at all clear how we should number the FP stack registers
1580    for the x86 architecture.  If the version of SDB on x86/svr4 were
1581    a bit less brain dead with respect to floating-point then we would
1582    have a precedent to follow with respect to DWARF register numbers
1583    for x86 FP registers, but the SDB on x86/svr4 is so completely
1584    broken with respect to FP registers that it is hardly worth thinking
1585    of it as something to strive for compatibility with.
1586    The version of x86/svr4 SDB I have at the moment does (partially)
1587    seem to believe that DWARF register number 11 is associated with
1588    the x86 register %st(0), but that's about all.  Higher DWARF
1589    register numbers don't seem to be associated with anything in
1590    particular, and even for DWARF regno 11, SDB only seems to under-
1591    stand that it should say that a variable lives in %st(0) (when
1592    asked via an `=' command) if we said it was in DWARF regno 11,
1593    but SDB still prints garbage when asked for the value of the
1594    variable in question (via a `/' command).
1595    (Also note that the labels SDB prints for various FP stack regs
1596    when doing an `x' command are all wrong.)
1597    Note that these problems generally don't affect the native SVR4
1598    C compiler because it doesn't allow the use of -O with -g and
1599    because when it is *not* optimizing, it allocates a memory
1600    location for each floating-point variable, and the memory
1601    location is what gets described in the DWARF AT_location
1602    attribute for the variable in question.
1603    Regardless of the severe mental illness of the x86/svr4 SDB, we
1604    do something sensible here and we use the following DWARF
1605    register numbers.  Note that these are all stack-top-relative
1606    numbers.
1607         11 for %st(0) (gcc regno = 8)
1608         12 for %st(1) (gcc regno = 9)
1609         13 for %st(2) (gcc regno = 10)
1610         14 for %st(3) (gcc regno = 11)
1611         15 for %st(4) (gcc regno = 12)
1612         16 for %st(5) (gcc regno = 13)
1613         17 for %st(6) (gcc regno = 14)
1614         18 for %st(7) (gcc regno = 15)
1615 */
1616 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
1617 {
1618   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
1619   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
1620   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
1621   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
1622   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
1623   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1624   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1625 };
1626
1627 /* Test and compare insns in i386.md store the information needed to
1628    generate branch and scc insns here.  */
1629
1630 rtx ix86_compare_op0 = NULL_RTX;
1631 rtx ix86_compare_op1 = NULL_RTX;
1632 rtx ix86_compare_emitted = NULL_RTX;
1633
1634 /* Size of the register save area.  */
1635 #define X86_64_VARARGS_SIZE (X86_64_REGPARM_MAX * UNITS_PER_WORD + X86_64_SSE_REGPARM_MAX * 16)
1636
1637 /* Define the structure for the machine field in struct function.  */
1638
1639 struct stack_local_entry GTY(())
1640 {
1641   unsigned short mode;
1642   unsigned short n;
1643   rtx rtl;
1644   struct stack_local_entry *next;
1645 };
1646
1647 /* Structure describing stack frame layout.
1648    Stack grows downward:
1649
1650    [arguments]
1651                                               <- ARG_POINTER
1652    saved pc
1653
1654    saved frame pointer if frame_pointer_needed
1655                                               <- HARD_FRAME_POINTER
1656    [saved regs]
1657
1658    [padding1]          \
1659                         )
1660    [va_arg registers]  (
1661                         > to_allocate         <- FRAME_POINTER
1662    [frame]             (
1663                         )
1664    [padding2]          /
1665   */
1666 struct ix86_frame
1667 {
1668   int nregs;
1669   int padding1;
1670   int va_arg_size;
1671   HOST_WIDE_INT frame;
1672   int padding2;
1673   int outgoing_arguments_size;
1674   int red_zone_size;
1675
1676   HOST_WIDE_INT to_allocate;
1677   /* The offsets relative to ARG_POINTER.  */
1678   HOST_WIDE_INT frame_pointer_offset;
1679   HOST_WIDE_INT hard_frame_pointer_offset;
1680   HOST_WIDE_INT stack_pointer_offset;
1681
1682   /* When save_regs_using_mov is set, emit prologue using
1683      move instead of push instructions.  */
1684   bool save_regs_using_mov;
1685 };
1686
1687 /* Code model option.  */
1688 enum cmodel ix86_cmodel;
1689 /* Asm dialect.  */
1690 enum asm_dialect ix86_asm_dialect = ASM_ATT;
1691 /* TLS dialects.  */
1692 enum tls_dialect ix86_tls_dialect = TLS_DIALECT_GNU;
1693
1694 /* Which unit we are generating floating point math for.  */
1695 enum fpmath_unit ix86_fpmath;
1696
1697 /* Which cpu are we scheduling for.  */
1698 enum processor_type ix86_tune;
1699
1700 /* Which instruction set architecture to use.  */
1701 enum processor_type ix86_arch;
1702
1703 /* true if sse prefetch instruction is not NOOP.  */
1704 int x86_prefetch_sse;
1705
1706 /* ix86_regparm_string as a number */
1707 static int ix86_regparm;
1708
1709 /* -mstackrealign option */
1710 extern int ix86_force_align_arg_pointer;
1711 static const char ix86_force_align_arg_pointer_string[]
1712   = "force_align_arg_pointer";
1713
1714 static rtx (*ix86_gen_leave) (void);
1715 static rtx (*ix86_gen_pop1) (rtx);
1716 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
1717 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
1718 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx);
1719 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
1720 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
1721 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
1722
1723 /* Preferred alignment for stack boundary in bits.  */
1724 unsigned int ix86_preferred_stack_boundary;
1725
1726 /* Alignment for incoming stack boundary in bits specified at
1727    command line.  */
1728 static unsigned int ix86_user_incoming_stack_boundary;
1729
1730 /* Default alignment for incoming stack boundary in bits.  */
1731 static unsigned int ix86_default_incoming_stack_boundary;
1732
1733 /* Alignment for incoming stack boundary in bits.  */
1734 unsigned int ix86_incoming_stack_boundary;
1735
1736 /* Values 1-5: see jump.c */
1737 int ix86_branch_cost;
1738
1739 /* Calling abi specific va_list type nodes.  */
1740 static GTY(()) tree sysv_va_list_type_node;
1741 static GTY(()) tree ms_va_list_type_node;
1742
1743 /* Variables which are this size or smaller are put in the data/bss
1744    or ldata/lbss sections.  */
1745
1746 int ix86_section_threshold = 65536;
1747
1748 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
1749 char internal_label_prefix[16];
1750 int internal_label_prefix_len;
1751
1752 /* Fence to use after loop using movnt.  */
1753 tree x86_mfence;
1754
1755 /* Register class used for passing given 64bit part of the argument.
1756    These represent classes as documented by the PS ABI, with the exception
1757    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
1758    use SF or DFmode move instead of DImode to avoid reformatting penalties.
1759
1760    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
1761    whenever possible (upper half does contain padding).  */
1762 enum x86_64_reg_class
1763   {
1764     X86_64_NO_CLASS,
1765     X86_64_INTEGER_CLASS,
1766     X86_64_INTEGERSI_CLASS,
1767     X86_64_SSE_CLASS,
1768     X86_64_SSESF_CLASS,
1769     X86_64_SSEDF_CLASS,
1770     X86_64_SSEUP_CLASS,
1771     X86_64_X87_CLASS,
1772     X86_64_X87UP_CLASS,
1773     X86_64_COMPLEX_X87_CLASS,
1774     X86_64_MEMORY_CLASS
1775   };
1776 static const char * const x86_64_reg_class_name[] =
1777 {
1778   "no", "integer", "integerSI", "sse", "sseSF", "sseDF",
1779   "sseup", "x87", "x87up", "cplx87", "no"
1780 };
1781
1782 #define MAX_CLASSES 4
1783
1784 /* Table of constants used by fldpi, fldln2, etc....  */
1785 static REAL_VALUE_TYPE ext_80387_constants_table [5];
1786 static bool ext_80387_constants_init = 0;
1787
1788 \f
1789 static struct machine_function * ix86_init_machine_status (void);
1790 static rtx ix86_function_value (const_tree, const_tree, bool);
1791 static int ix86_function_regparm (const_tree, const_tree);
1792 static void ix86_compute_frame_layout (struct ix86_frame *);
1793 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
1794                                                  rtx, rtx, int);
1795
1796 enum ix86_function_specific_strings
1797 {
1798   IX86_FUNCTION_SPECIFIC_ARCH,
1799   IX86_FUNCTION_SPECIFIC_TUNE,
1800   IX86_FUNCTION_SPECIFIC_FPMATH,
1801   IX86_FUNCTION_SPECIFIC_MAX
1802 };
1803
1804 static char *ix86_target_string (int, int, const char *, const char *,
1805                                  const char *, bool);
1806 static void ix86_debug_options (void) ATTRIBUTE_UNUSED;
1807 static void ix86_function_specific_save (struct cl_target_option *);
1808 static void ix86_function_specific_restore (struct cl_target_option *);
1809 static void ix86_function_specific_print (FILE *, int,
1810                                           struct cl_target_option *);
1811 static bool ix86_valid_option_attribute_p (tree, tree, tree, int);
1812 static bool ix86_valid_option_attribute_inner_p (tree, char *[]);
1813 static bool ix86_can_inline_p (tree, tree);
1814 static void ix86_set_current_function (tree);
1815
1816 \f
1817 /* The svr4 ABI for the i386 says that records and unions are returned
1818    in memory.  */
1819 #ifndef DEFAULT_PCC_STRUCT_RETURN
1820 #define DEFAULT_PCC_STRUCT_RETURN 1
1821 #endif
1822
1823 /* Whether -mtune= or -march= were specified */
1824 static int ix86_tune_defaulted;
1825 static int ix86_arch_specified;
1826
1827 /* Bit flags that specify the ISA we are compiling for.  */
1828 int ix86_isa_flags = TARGET_64BIT_DEFAULT | TARGET_SUBTARGET_ISA_DEFAULT;
1829
1830 /* A mask of ix86_isa_flags that includes bit X if X
1831    was set or cleared on the command line.  */
1832 static int ix86_isa_flags_explicit;
1833
1834 /* Define a set of ISAs which are available when a given ISA is
1835    enabled.  MMX and SSE ISAs are handled separately.  */
1836
1837 #define OPTION_MASK_ISA_MMX_SET OPTION_MASK_ISA_MMX
1838 #define OPTION_MASK_ISA_3DNOW_SET \
1839   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX_SET)
1840
1841 #define OPTION_MASK_ISA_SSE_SET OPTION_MASK_ISA_SSE
1842 #define OPTION_MASK_ISA_SSE2_SET \
1843   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE_SET)
1844 #define OPTION_MASK_ISA_SSE3_SET \
1845   (OPTION_MASK_ISA_SSE3 | OPTION_MASK_ISA_SSE2_SET)
1846 #define OPTION_MASK_ISA_SSSE3_SET \
1847   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE3_SET)
1848 #define OPTION_MASK_ISA_SSE4_1_SET \
1849   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSSE3_SET)
1850 #define OPTION_MASK_ISA_SSE4_2_SET \
1851   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_SSE4_1_SET)
1852
1853 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
1854    as -msse4.2.  */
1855 #define OPTION_MASK_ISA_SSE4_SET OPTION_MASK_ISA_SSE4_2_SET
1856
1857 #define OPTION_MASK_ISA_SSE4A_SET \
1858   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE3_SET)
1859 #define OPTION_MASK_ISA_SSE5_SET \
1860   (OPTION_MASK_ISA_SSE5 | OPTION_MASK_ISA_SSE4A_SET)
1861
1862 /* AES and PCLMUL need SSE2 because they use xmm registers */
1863 #define OPTION_MASK_ISA_AES_SET \
1864   (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2_SET)
1865 #define OPTION_MASK_ISA_PCLMUL_SET \
1866   (OPTION_MASK_ISA_PCLMUL | OPTION_MASK_ISA_SSE2_SET)
1867
1868 #define OPTION_MASK_ISA_ABM_SET \
1869   (OPTION_MASK_ISA_ABM | OPTION_MASK_ISA_POPCNT)
1870 #define OPTION_MASK_ISA_POPCNT_SET OPTION_MASK_ISA_POPCNT
1871 #define OPTION_MASK_ISA_CX16_SET OPTION_MASK_ISA_CX16
1872 #define OPTION_MASK_ISA_SAHF_SET OPTION_MASK_ISA_SAHF
1873
1874 /* Define a set of ISAs which aren't available when a given ISA is
1875    disabled.  MMX and SSE ISAs are handled separately.  */
1876
1877 #define OPTION_MASK_ISA_MMX_UNSET \
1878   (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_3DNOW_UNSET)
1879 #define OPTION_MASK_ISA_3DNOW_UNSET \
1880   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_A_UNSET)
1881 #define OPTION_MASK_ISA_3DNOW_A_UNSET OPTION_MASK_ISA_3DNOW_A
1882
1883 #define OPTION_MASK_ISA_SSE_UNSET \
1884   (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_SSE2_UNSET)
1885 #define OPTION_MASK_ISA_SSE2_UNSET \
1886   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3_UNSET)
1887 #define OPTION_MASK_ISA_SSE3_UNSET \
1888   (OPTION_MASK_ISA_SSE3 \
1889    | OPTION_MASK_ISA_SSSE3_UNSET \
1890    | OPTION_MASK_ISA_SSE4A_UNSET )
1891 #define OPTION_MASK_ISA_SSSE3_UNSET \
1892   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE4_1_UNSET)
1893 #define OPTION_MASK_ISA_SSE4_1_UNSET \
1894   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_2_UNSET)
1895 #define OPTION_MASK_ISA_SSE4_2_UNSET OPTION_MASK_ISA_SSE4_2
1896
1897 /* SSE4 includes both SSE4.1 and SSE4.2.  -mno-sse4 should the same
1898    as -mno-sse4.1. */
1899 #define OPTION_MASK_ISA_SSE4_UNSET OPTION_MASK_ISA_SSE4_1_UNSET
1900
1901 #define OPTION_MASK_ISA_SSE4A_UNSET \
1902   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE5_UNSET)
1903 #define OPTION_MASK_ISA_SSE5_UNSET OPTION_MASK_ISA_SSE5
1904 #define OPTION_MASK_ISA_AES_UNSET OPTION_MASK_ISA_AES
1905 #define OPTION_MASK_ISA_PCLMUL_UNSET OPTION_MASK_ISA_PCLMUL
1906 #define OPTION_MASK_ISA_ABM_UNSET OPTION_MASK_ISA_ABM
1907 #define OPTION_MASK_ISA_POPCNT_UNSET OPTION_MASK_ISA_POPCNT
1908 #define OPTION_MASK_ISA_CX16_UNSET OPTION_MASK_ISA_CX16
1909 #define OPTION_MASK_ISA_SAHF_UNSET OPTION_MASK_ISA_SAHF
1910
1911 /* Vectorization library interface and handlers.  */
1912 tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL;
1913 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
1914 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
1915
1916 /* Processor target table, indexed by processor number */
1917 struct ptt
1918 {
1919   const struct processor_costs *cost;           /* Processor costs */
1920   const int align_loop;                         /* Default alignments.  */
1921   const int align_loop_max_skip;
1922   const int align_jump;
1923   const int align_jump_max_skip;
1924   const int align_func;
1925 };
1926
1927 static const struct ptt processor_target_table[PROCESSOR_max] =
1928 {
1929   {&i386_cost, 4, 3, 4, 3, 4},
1930   {&i486_cost, 16, 15, 16, 15, 16},
1931   {&pentium_cost, 16, 7, 16, 7, 16},
1932   {&pentiumpro_cost, 16, 15, 16, 10, 16},
1933   {&geode_cost, 0, 0, 0, 0, 0},
1934   {&k6_cost, 32, 7, 32, 7, 32},
1935   {&athlon_cost, 16, 7, 16, 7, 16},
1936   {&pentium4_cost, 0, 0, 0, 0, 0},
1937   {&k8_cost, 16, 7, 16, 7, 16},
1938   {&nocona_cost, 0, 0, 0, 0, 0},
1939   {&core2_cost, 16, 10, 16, 10, 16},
1940   {&generic32_cost, 16, 7, 16, 7, 16},
1941   {&generic64_cost, 16, 10, 16, 10, 16},
1942   {&amdfam10_cost, 32, 24, 32, 7, 32}
1943 };
1944
1945 static const char *const cpu_names[TARGET_CPU_DEFAULT_max] =
1946 {
1947   "generic",
1948   "i386",
1949   "i486",
1950   "pentium",
1951   "pentium-mmx",
1952   "pentiumpro",
1953   "pentium2",
1954   "pentium3",
1955   "pentium4",
1956   "pentium-m",
1957   "prescott",
1958   "nocona",
1959   "core2",
1960   "geode",
1961   "k6",
1962   "k6-2",
1963   "k6-3",
1964   "athlon",
1965   "athlon-4",
1966   "k8",
1967   "amdfam10"
1968 };
1969 \f
1970 /* Implement TARGET_HANDLE_OPTION.  */
1971
1972 static bool
1973 ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value)
1974 {
1975   switch (code)
1976     {
1977     case OPT_mmmx:
1978       if (value)
1979         {
1980           ix86_isa_flags |= OPTION_MASK_ISA_MMX_SET;
1981           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_SET;
1982         }
1983       else
1984         {
1985           ix86_isa_flags &= ~OPTION_MASK_ISA_MMX_UNSET;
1986           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_UNSET;
1987         }
1988       return true;
1989
1990     case OPT_m3dnow:
1991       if (value)
1992         {
1993           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_SET;
1994           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_SET;
1995         }
1996       else
1997         {
1998           ix86_isa_flags &= ~OPTION_MASK_ISA_3DNOW_UNSET;
1999           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_UNSET;
2000         }
2001       return true;
2002
2003     case OPT_m3dnowa:
2004       return false;
2005
2006     case OPT_msse:
2007       if (value)
2008         {
2009           ix86_isa_flags |= OPTION_MASK_ISA_SSE_SET;
2010           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_SET;
2011         }
2012       else
2013         {
2014           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE_UNSET;
2015           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_UNSET;
2016         }
2017       return true;
2018
2019     case OPT_msse2:
2020       if (value)
2021         {
2022           ix86_isa_flags |= OPTION_MASK_ISA_SSE2_SET;
2023           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_SET;
2024         }
2025       else
2026         {
2027           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE2_UNSET;
2028           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_UNSET;
2029         }
2030       return true;
2031
2032     case OPT_msse3:
2033       if (value)
2034         {
2035           ix86_isa_flags |= OPTION_MASK_ISA_SSE3_SET;
2036           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_SET;
2037         }
2038       else
2039         {
2040           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE3_UNSET;
2041           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_UNSET;
2042         }
2043       return true;
2044
2045     case OPT_mssse3:
2046       if (value)
2047         {
2048           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3_SET;
2049           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_SET;
2050         }
2051       else
2052         {
2053           ix86_isa_flags &= ~OPTION_MASK_ISA_SSSE3_UNSET;
2054           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_UNSET;
2055         }
2056       return true;
2057
2058     case OPT_msse4_1:
2059       if (value)
2060         {
2061           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1_SET;
2062           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_SET;
2063         }
2064       else
2065         {
2066           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_1_UNSET;
2067           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_UNSET;
2068         }
2069       return true;
2070
2071     case OPT_msse4_2:
2072       if (value)
2073         {
2074           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2_SET;
2075           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_SET;
2076         }
2077       else
2078         {
2079           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_2_UNSET;
2080           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_UNSET;
2081         }
2082       return true;
2083
2084     case OPT_msse4:
2085       ix86_isa_flags |= OPTION_MASK_ISA_SSE4_SET;
2086       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_SET;
2087       return true;
2088
2089     case OPT_mno_sse4:
2090       ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
2091       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
2092       return true;
2093
2094     case OPT_msse4a:
2095       if (value)
2096         {
2097           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A_SET;
2098           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_SET;
2099         }
2100       else
2101         {
2102           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4A_UNSET;
2103           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_UNSET;
2104         }
2105       return true;
2106
2107     case OPT_msse5:
2108       if (value)
2109         {
2110           ix86_isa_flags |= OPTION_MASK_ISA_SSE5_SET;
2111           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_SET;
2112         }
2113       else
2114         {
2115           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE5_UNSET;
2116           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_UNSET;
2117         }
2118       return true;
2119
2120     case OPT_mabm:
2121       if (value)
2122         {
2123           ix86_isa_flags |= OPTION_MASK_ISA_ABM_SET;
2124           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_SET;
2125         }
2126       else
2127         {
2128           ix86_isa_flags &= ~OPTION_MASK_ISA_ABM_UNSET;
2129           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_UNSET;
2130         }
2131       return true;
2132
2133     case OPT_mpopcnt:
2134       if (value)
2135         {
2136           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT_SET;
2137           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_SET;
2138         }
2139       else
2140         {
2141           ix86_isa_flags &= ~OPTION_MASK_ISA_POPCNT_UNSET;
2142           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_UNSET;
2143         }
2144       return true;
2145
2146     case OPT_msahf:
2147       if (value)
2148         {
2149           ix86_isa_flags |= OPTION_MASK_ISA_SAHF_SET;
2150           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_SET;
2151         }
2152       else
2153         {
2154           ix86_isa_flags &= ~OPTION_MASK_ISA_SAHF_UNSET;
2155           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_UNSET;
2156         }
2157       return true;
2158
2159     case OPT_mcx16:
2160       if (value)
2161         {
2162           ix86_isa_flags |= OPTION_MASK_ISA_CX16_SET;
2163           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_SET;
2164         }
2165       else
2166         {
2167           ix86_isa_flags &= ~OPTION_MASK_ISA_CX16_UNSET;
2168           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_UNSET;
2169         }
2170       return true;
2171
2172     case OPT_maes:
2173       if (value)
2174         {
2175           ix86_isa_flags |= OPTION_MASK_ISA_AES_SET;
2176           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_SET;
2177         }
2178       else
2179         {
2180           ix86_isa_flags &= ~OPTION_MASK_ISA_AES_UNSET;
2181           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_UNSET;
2182         }
2183       return true;
2184
2185     case OPT_mpclmul:
2186       if (value)
2187         {
2188           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL_SET;
2189           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_SET;
2190         }
2191       else
2192         {
2193           ix86_isa_flags &= ~OPTION_MASK_ISA_PCLMUL_UNSET;
2194           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_UNSET;
2195         }
2196       return true;
2197
2198     default:
2199       return true;
2200     }
2201 }
2202 \f
2203 /* Return a string the documents the current -m options.  The caller is
2204    responsible for freeing the string.  */
2205
2206 static char *
2207 ix86_target_string (int isa, int flags, const char *arch, const char *tune,
2208                     const char *fpmath, bool add_nl_p)
2209 {
2210   struct ix86_target_opts
2211   {
2212     const char *option;         /* option string */
2213     int mask;                   /* isa mask options */
2214   };
2215
2216   /* This table is ordered so that options like -msse5 or -msse4.2 that imply
2217      preceding options while match those first.  */
2218   static struct ix86_target_opts isa_opts[] =
2219   {
2220     { "-m64",           OPTION_MASK_ISA_64BIT },
2221     { "-msse5",         OPTION_MASK_ISA_SSE5 },
2222     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2223     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2224     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2225     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2226     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2227     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2228     { "-msse",          OPTION_MASK_ISA_SSE },
2229     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2230     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2231     { "-mmmx",          OPTION_MASK_ISA_MMX },
2232     { "-mabm",          OPTION_MASK_ISA_ABM },
2233     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2234     { "-maes",          OPTION_MASK_ISA_AES },
2235     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2236   };
2237
2238   /* Flag options.  */
2239   static struct ix86_target_opts flag_opts[] =
2240   {
2241     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2242     { "-m80387",                        MASK_80387 },
2243     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2244     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2245     { "-mcld",                          MASK_CLD },
2246     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2247     { "-mieee-fp",                      MASK_IEEE_FP },
2248     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2249     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2250     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2251     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2252     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2253     { "-mno-fused-madd",                MASK_NO_FUSED_MADD },
2254     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2255     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2256     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2257     { "-mrecip",                        MASK_RECIP },
2258     { "-mrtd",                          MASK_RTD },
2259     { "-msseregparm",                   MASK_SSEREGPARM },
2260     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2261     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2262   };
2263
2264   const char *opts[ (sizeof (isa_opts) / sizeof (isa_opts[0])
2265                      + sizeof (flag_opts) / sizeof (flag_opts[0])
2266                      + 6)][2];
2267
2268   char isa_other[40];
2269   char target_other[40];
2270   unsigned num = 0;
2271   unsigned i, j;
2272   char *ret;
2273   char *ptr;
2274   size_t len;
2275   size_t line_len;
2276   size_t sep_len;
2277
2278   memset (opts, '\0', sizeof (opts));
2279
2280   /* Add -march= option.  */
2281   if (arch)
2282     {
2283       opts[num][0] = "-march=";
2284       opts[num++][1] = arch;
2285     }
2286
2287   /* Add -mtune= option.  */
2288   if (tune)
2289     {
2290       opts[num][0] = "-mtune=";
2291       opts[num++][1] = tune;
2292     }
2293
2294   /* Pick out the options in isa options.  */
2295   for (i = 0; i < sizeof (isa_opts) / sizeof (isa_opts[0]); i++)
2296     {
2297       if ((isa & isa_opts[i].mask) != 0)
2298         {
2299           opts[num++][0] = isa_opts[i].option;
2300           isa &= ~ isa_opts[i].mask;
2301         }
2302     }
2303
2304   if (isa && add_nl_p)
2305     {
2306       opts[num++][0] = isa_other;
2307       sprintf (isa_other, "(other isa: 0x%x)", isa);
2308     }
2309
2310   /* Add flag options.  */
2311   for (i = 0; i < sizeof (flag_opts) / sizeof (flag_opts[0]); i++)
2312     {
2313       if ((flags & flag_opts[i].mask) != 0)
2314         {
2315           opts[num++][0] = flag_opts[i].option;
2316           flags &= ~ flag_opts[i].mask;
2317         }
2318     }
2319
2320   if (flags && add_nl_p)
2321     {
2322       opts[num++][0] = target_other;
2323       sprintf (target_other, "(other flags: 0x%x)", isa);
2324     }
2325
2326   /* Add -fpmath= option.  */
2327   if (fpmath)
2328     {
2329       opts[num][0] = "-mfpmath=";
2330       opts[num++][1] = fpmath;
2331     }
2332
2333   /* Any options?  */
2334   if (num == 0)
2335     return NULL;
2336
2337   gcc_assert (num < sizeof (opts) / sizeof (opts[0]));
2338
2339   /* Size the string.  */
2340   len = 0;
2341   sep_len = (add_nl_p) ? 3 : 1;
2342   for (i = 0; i < num; i++)
2343     {
2344       len += sep_len;
2345       for (j = 0; j < 2; j++)
2346         if (opts[i][j])
2347           len += strlen (opts[i][j]);
2348     }
2349
2350   /* Build the string.  */
2351   ret = ptr = (char *) xmalloc (len);
2352   line_len = 0;
2353
2354   for (i = 0; i < num; i++)
2355     {
2356       size_t len2[2];
2357
2358       for (j = 0; j < 2; j++)
2359         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2360
2361       if (i != 0)
2362         {
2363           *ptr++ = ' ';
2364           line_len++;
2365
2366           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2367             {
2368               *ptr++ = '\\';
2369               *ptr++ = '\n';
2370               line_len = 0;
2371             }
2372         }
2373
2374       for (j = 0; j < 2; j++)
2375         if (opts[i][j])
2376           {
2377             memcpy (ptr, opts[i][j], len2[j]);
2378             ptr += len2[j];
2379             line_len += len2[j];
2380           }
2381     }
2382
2383   *ptr = '\0';
2384   gcc_assert (ret + len >= ptr);
2385
2386   return ret;
2387 }
2388
2389 /* Function that is callable from the debugger to print the current
2390    options.  */
2391 void
2392 ix86_debug_options (void)
2393 {
2394   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2395                                    ix86_arch_string, ix86_tune_string,
2396                                    ix86_fpmath_string, true);
2397
2398   if (opts)
2399     {
2400       fprintf (stderr, "%s\n\n", opts);
2401       free (opts);
2402     }
2403   else
2404     fprintf (stderr, "<no options>\n\n");
2405
2406   return;
2407 }
2408 \f
2409 /* Sometimes certain combinations of command options do not make
2410    sense on a particular target machine.  You can define a macro
2411    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
2412    defined, is executed once just after all the command options have
2413    been parsed.
2414
2415    Don't use this macro to turn on various extra optimizations for
2416    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
2417
2418 void
2419 override_options (bool main_args_p)
2420 {
2421   int i;
2422   unsigned int ix86_arch_mask, ix86_tune_mask;
2423   const char *prefix;
2424   const char *suffix;
2425   const char *sw;
2426
2427   /* Comes from final.c -- no real reason to change it.  */
2428 #define MAX_CODE_ALIGN 16
2429
2430   enum pta_flags
2431     {
2432       PTA_SSE = 1 << 0,
2433       PTA_SSE2 = 1 << 1,
2434       PTA_SSE3 = 1 << 2,
2435       PTA_MMX = 1 << 3,
2436       PTA_PREFETCH_SSE = 1 << 4,
2437       PTA_3DNOW = 1 << 5,
2438       PTA_3DNOW_A = 1 << 6,
2439       PTA_64BIT = 1 << 7,
2440       PTA_SSSE3 = 1 << 8,
2441       PTA_CX16 = 1 << 9,
2442       PTA_POPCNT = 1 << 10,
2443       PTA_ABM = 1 << 11,
2444       PTA_SSE4A = 1 << 12,
2445       PTA_NO_SAHF = 1 << 13,
2446       PTA_SSE4_1 = 1 << 14,
2447       PTA_SSE4_2 = 1 << 15,
2448       PTA_SSE5 = 1 << 16,
2449       PTA_AES = 1 << 17,
2450       PTA_PCLMUL = 1 << 18
2451     };
2452
2453   static struct pta
2454     {
2455       const char *const name;           /* processor name or nickname.  */
2456       const enum processor_type processor;
2457       const unsigned /*enum pta_flags*/ flags;
2458     }
2459   const processor_alias_table[] =
2460     {
2461       {"i386", PROCESSOR_I386, 0},
2462       {"i486", PROCESSOR_I486, 0},
2463       {"i586", PROCESSOR_PENTIUM, 0},
2464       {"pentium", PROCESSOR_PENTIUM, 0},
2465       {"pentium-mmx", PROCESSOR_PENTIUM, PTA_MMX},
2466       {"winchip-c6", PROCESSOR_I486, PTA_MMX},
2467       {"winchip2", PROCESSOR_I486, PTA_MMX | PTA_3DNOW},
2468       {"c3", PROCESSOR_I486, PTA_MMX | PTA_3DNOW},
2469       {"c3-2", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2470       {"i686", PROCESSOR_PENTIUMPRO, 0},
2471       {"pentiumpro", PROCESSOR_PENTIUMPRO, 0},
2472       {"pentium2", PROCESSOR_PENTIUMPRO, PTA_MMX},
2473       {"pentium3", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2474       {"pentium3m", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2475       {"pentium-m", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE | PTA_SSE2},
2476       {"pentium4", PROCESSOR_PENTIUM4, PTA_MMX |PTA_SSE | PTA_SSE2},
2477       {"pentium4m", PROCESSOR_PENTIUM4, PTA_MMX | PTA_SSE | PTA_SSE2},
2478       {"prescott", PROCESSOR_NOCONA, PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3},
2479       {"nocona", PROCESSOR_NOCONA, (PTA_64BIT
2480                                     | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2481                                     | PTA_CX16 | PTA_NO_SAHF)},
2482       {"core2", PROCESSOR_CORE2, (PTA_64BIT
2483                                   | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2484                                   | PTA_SSSE3
2485                                   | PTA_CX16)},
2486       {"geode", PROCESSOR_GEODE, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2487                                   |PTA_PREFETCH_SSE)},
2488       {"k6", PROCESSOR_K6, PTA_MMX},
2489       {"k6-2", PROCESSOR_K6, PTA_MMX | PTA_3DNOW},
2490       {"k6-3", PROCESSOR_K6, PTA_MMX | PTA_3DNOW},
2491       {"athlon", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2492                                     | PTA_PREFETCH_SSE)},
2493       {"athlon-tbird", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2494                                           | PTA_PREFETCH_SSE)},
2495       {"athlon-4", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2496                                       | PTA_SSE)},
2497       {"athlon-xp", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2498                                        | PTA_SSE)},
2499       {"athlon-mp", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2500                                        | PTA_SSE)},
2501       {"x86-64", PROCESSOR_K8, (PTA_64BIT
2502                                 | PTA_MMX | PTA_SSE | PTA_SSE2
2503                                 | PTA_NO_SAHF)},
2504       {"k8", PROCESSOR_K8, (PTA_64BIT
2505                             | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2506                             | PTA_SSE | PTA_SSE2
2507                             | PTA_NO_SAHF)},
2508       {"k8-sse3", PROCESSOR_K8, (PTA_64BIT
2509                                  | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2510                                  | PTA_SSE | PTA_SSE2 | PTA_SSE3
2511                                  | PTA_NO_SAHF)},
2512       {"opteron", PROCESSOR_K8, (PTA_64BIT
2513                                  | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2514                                  | PTA_SSE | PTA_SSE2
2515                                  | PTA_NO_SAHF)},
2516       {"opteron-sse3", PROCESSOR_K8, (PTA_64BIT
2517                                       | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2518                                       | PTA_SSE | PTA_SSE2 | PTA_SSE3
2519                                       | PTA_NO_SAHF)},
2520       {"athlon64", PROCESSOR_K8, (PTA_64BIT
2521                                   | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2522                                   | PTA_SSE | PTA_SSE2
2523                                   | PTA_NO_SAHF)},
2524       {"athlon64-sse3", PROCESSOR_K8, (PTA_64BIT
2525                                        | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2526                                        | PTA_SSE | PTA_SSE2 | PTA_SSE3
2527                                        | PTA_NO_SAHF)},
2528       {"athlon-fx", PROCESSOR_K8, (PTA_64BIT
2529                                    | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2530                                    | PTA_SSE | PTA_SSE2
2531                                    | PTA_NO_SAHF)},
2532       {"amdfam10", PROCESSOR_AMDFAM10, (PTA_64BIT
2533                                         | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2534                                         | PTA_SSE | PTA_SSE2 | PTA_SSE3
2535                                         | PTA_SSE4A
2536                                         | PTA_CX16 | PTA_ABM)},
2537       {"barcelona", PROCESSOR_AMDFAM10, (PTA_64BIT
2538                                          | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2539                                          | PTA_SSE | PTA_SSE2 | PTA_SSE3
2540                                          | PTA_SSE4A
2541                                          | PTA_CX16 | PTA_ABM)},
2542       {"generic32", PROCESSOR_GENERIC32, 0 /* flags are only used for -march switch.  */ },
2543       {"generic64", PROCESSOR_GENERIC64, PTA_64BIT /* flags are only used for -march switch.  */ },
2544     };
2545
2546   int const pta_size = ARRAY_SIZE (processor_alias_table);
2547
2548   /* Set up prefix/suffix so the error messages refer to either the command
2549      line argument, or the attribute(option).  */
2550   if (main_args_p)
2551     {
2552       prefix = "-m";
2553       suffix = "";
2554       sw = "switch";
2555     }
2556   else
2557     {
2558       prefix = "option(\"";
2559       suffix = "\")";
2560       sw = "attribute";
2561     }
2562
2563 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2564   SUBTARGET_OVERRIDE_OPTIONS;
2565 #endif
2566
2567 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2568   SUBSUBTARGET_OVERRIDE_OPTIONS;
2569 #endif
2570
2571   /* -fPIC is the default for x86_64.  */
2572   if (TARGET_MACHO && TARGET_64BIT)
2573     flag_pic = 2;
2574
2575   /* Set the default values for switches whose default depends on TARGET_64BIT
2576      in case they weren't overwritten by command line options.  */
2577   if (TARGET_64BIT)
2578     {
2579       /* Mach-O doesn't support omitting the frame pointer for now.  */
2580       if (flag_omit_frame_pointer == 2)
2581         flag_omit_frame_pointer = (TARGET_MACHO ? 0 : 1);
2582       if (flag_asynchronous_unwind_tables == 2)
2583         flag_asynchronous_unwind_tables = 1;
2584       if (flag_pcc_struct_return == 2)
2585         flag_pcc_struct_return = 0;
2586     }
2587   else
2588     {
2589       if (flag_omit_frame_pointer == 2)
2590         flag_omit_frame_pointer = 0;
2591       if (flag_asynchronous_unwind_tables == 2)
2592         flag_asynchronous_unwind_tables = 0;
2593       if (flag_pcc_struct_return == 2)
2594         flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
2595     }
2596
2597   /* Need to check -mtune=generic first.  */
2598   if (ix86_tune_string)
2599     {
2600       if (!strcmp (ix86_tune_string, "generic")
2601           || !strcmp (ix86_tune_string, "i686")
2602           /* As special support for cross compilers we read -mtune=native
2603              as -mtune=generic.  With native compilers we won't see the
2604              -mtune=native, as it was changed by the driver.  */
2605           || !strcmp (ix86_tune_string, "native"))
2606         {
2607           if (TARGET_64BIT)
2608             ix86_tune_string = "generic64";
2609           else
2610             ix86_tune_string = "generic32";
2611         }
2612       /* If this call is for setting the option attribute, allow the
2613          generic32/generic64 that was previously set.  */
2614       else if (!main_args_p
2615                && (!strcmp (ix86_tune_string, "generic32")
2616                    || !strcmp (ix86_tune_string, "generic64")))
2617         ;
2618       else if (!strncmp (ix86_tune_string, "generic", 7))
2619         error ("bad value (%s) for %stune=%s %s",
2620                ix86_tune_string, prefix, suffix, sw);
2621     }
2622   else
2623     {
2624       if (ix86_arch_string)
2625         ix86_tune_string = ix86_arch_string;
2626       if (!ix86_tune_string)
2627         {
2628           ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT];
2629           ix86_tune_defaulted = 1;
2630         }
2631
2632       /* ix86_tune_string is set to ix86_arch_string or defaulted.  We
2633          need to use a sensible tune option.  */
2634       if (!strcmp (ix86_tune_string, "generic")
2635           || !strcmp (ix86_tune_string, "x86-64")
2636           || !strcmp (ix86_tune_string, "i686"))
2637         {
2638           if (TARGET_64BIT)
2639             ix86_tune_string = "generic64";
2640           else
2641             ix86_tune_string = "generic32";
2642         }
2643     }
2644   if (ix86_stringop_string)
2645     {
2646       if (!strcmp (ix86_stringop_string, "rep_byte"))
2647         stringop_alg = rep_prefix_1_byte;
2648       else if (!strcmp (ix86_stringop_string, "libcall"))
2649         stringop_alg = libcall;
2650       else if (!strcmp (ix86_stringop_string, "rep_4byte"))
2651         stringop_alg = rep_prefix_4_byte;
2652       else if (!strcmp (ix86_stringop_string, "rep_8byte"))
2653         stringop_alg = rep_prefix_8_byte;
2654       else if (!strcmp (ix86_stringop_string, "byte_loop"))
2655         stringop_alg = loop_1_byte;
2656       else if (!strcmp (ix86_stringop_string, "loop"))
2657         stringop_alg = loop;
2658       else if (!strcmp (ix86_stringop_string, "unrolled_loop"))
2659         stringop_alg = unrolled_loop;
2660       else
2661         error ("bad value (%s) for %sstringop-strategy=%s %s",
2662                ix86_stringop_string, prefix, suffix, sw);
2663     }
2664   if (!strcmp (ix86_tune_string, "x86-64"))
2665     warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated.  Use "
2666              "%stune=k8%s or %stune=generic%s instead as appropriate.",
2667              prefix, suffix, prefix, suffix, prefix, suffix);
2668
2669   if (!ix86_arch_string)
2670     ix86_arch_string = TARGET_64BIT ? "x86-64" : "i386";
2671   else
2672     ix86_arch_specified = 1;
2673
2674   if (!strcmp (ix86_arch_string, "generic"))
2675     error ("generic CPU can be used only for %stune=%s %s",
2676            prefix, suffix, sw);
2677   if (!strncmp (ix86_arch_string, "generic", 7))
2678     error ("bad value (%s) for %sarch=%s %s",
2679            ix86_arch_string, prefix, suffix, sw);
2680
2681   if (ix86_cmodel_string != 0)
2682     {
2683       if (!strcmp (ix86_cmodel_string, "small"))
2684         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2685       else if (!strcmp (ix86_cmodel_string, "medium"))
2686         ix86_cmodel = flag_pic ? CM_MEDIUM_PIC : CM_MEDIUM;
2687       else if (!strcmp (ix86_cmodel_string, "large"))
2688         ix86_cmodel = flag_pic ? CM_LARGE_PIC : CM_LARGE;
2689       else if (flag_pic)
2690         error ("code model %s does not support PIC mode", ix86_cmodel_string);
2691       else if (!strcmp (ix86_cmodel_string, "32"))
2692         ix86_cmodel = CM_32;
2693       else if (!strcmp (ix86_cmodel_string, "kernel") && !flag_pic)
2694         ix86_cmodel = CM_KERNEL;
2695       else
2696         error ("bad value (%s) for %scmodel=%s %s",
2697                ix86_cmodel_string, prefix, suffix, sw);
2698     }
2699   else
2700     {
2701       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
2702          use of rip-relative addressing.  This eliminates fixups that
2703          would otherwise be needed if this object is to be placed in a
2704          DLL, and is essentially just as efficient as direct addressing.  */
2705       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
2706         ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
2707       else if (TARGET_64BIT)
2708         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2709       else
2710         ix86_cmodel = CM_32;
2711     }
2712   if (ix86_asm_string != 0)
2713     {
2714       if (! TARGET_MACHO
2715           && !strcmp (ix86_asm_string, "intel"))
2716         ix86_asm_dialect = ASM_INTEL;
2717       else if (!strcmp (ix86_asm_string, "att"))
2718         ix86_asm_dialect = ASM_ATT;
2719       else
2720         error ("bad value (%s) for %sasm=%s %s",
2721                ix86_asm_string, prefix, suffix, sw);
2722     }
2723   if ((TARGET_64BIT == 0) != (ix86_cmodel == CM_32))
2724     error ("code model %qs not supported in the %s bit mode",
2725            ix86_cmodel_string, TARGET_64BIT ? "64" : "32");
2726   if ((TARGET_64BIT != 0) != ((ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2727     sorry ("%i-bit mode not compiled in",
2728            (ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2729
2730   for (i = 0; i < pta_size; i++)
2731     if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
2732       {
2733         ix86_arch = processor_alias_table[i].processor;
2734         /* Default cpu tuning to the architecture.  */
2735         ix86_tune = ix86_arch;
2736
2737         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2738           error ("CPU you selected does not support x86-64 "
2739                  "instruction set");
2740
2741         if (processor_alias_table[i].flags & PTA_MMX
2742             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
2743           ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2744         if (processor_alias_table[i].flags & PTA_3DNOW
2745             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
2746           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
2747         if (processor_alias_table[i].flags & PTA_3DNOW_A
2748             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
2749           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
2750         if (processor_alias_table[i].flags & PTA_SSE
2751             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
2752           ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2753         if (processor_alias_table[i].flags & PTA_SSE2
2754             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
2755           ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2756         if (processor_alias_table[i].flags & PTA_SSE3
2757             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
2758           ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2759         if (processor_alias_table[i].flags & PTA_SSSE3
2760             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
2761           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2762         if (processor_alias_table[i].flags & PTA_SSE4_1
2763             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
2764           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2765         if (processor_alias_table[i].flags & PTA_SSE4_2
2766             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
2767           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
2768         if (processor_alias_table[i].flags & PTA_SSE4A
2769             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
2770           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2771         if (processor_alias_table[i].flags & PTA_SSE5
2772             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE5))
2773           ix86_isa_flags |= OPTION_MASK_ISA_SSE5;
2774         if (processor_alias_table[i].flags & PTA_ABM
2775             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
2776           ix86_isa_flags |= OPTION_MASK_ISA_ABM;
2777         if (processor_alias_table[i].flags & PTA_CX16
2778             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
2779           ix86_isa_flags |= OPTION_MASK_ISA_CX16;
2780         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
2781             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
2782           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
2783         if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF))
2784             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
2785           ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
2786         if (processor_alias_table[i].flags & PTA_AES
2787             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
2788           ix86_isa_flags |= OPTION_MASK_ISA_AES;
2789         if (processor_alias_table[i].flags & PTA_PCLMUL
2790             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
2791           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
2792         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
2793           x86_prefetch_sse = true;
2794
2795         break;
2796       }
2797
2798   if (i == pta_size)
2799     error ("bad value (%s) for %sarch=%s %s",
2800            ix86_arch_string, prefix, suffix, sw);
2801
2802   ix86_arch_mask = 1u << ix86_arch;
2803   for (i = 0; i < X86_ARCH_LAST; ++i)
2804     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
2805
2806   for (i = 0; i < pta_size; i++)
2807     if (! strcmp (ix86_tune_string, processor_alias_table[i].name))
2808       {
2809         ix86_tune = processor_alias_table[i].processor;
2810         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2811           {
2812             if (ix86_tune_defaulted)
2813               {
2814                 ix86_tune_string = "x86-64";
2815                 for (i = 0; i < pta_size; i++)
2816                   if (! strcmp (ix86_tune_string,
2817                                 processor_alias_table[i].name))
2818                     break;
2819                 ix86_tune = processor_alias_table[i].processor;
2820               }
2821             else
2822               error ("CPU you selected does not support x86-64 "
2823                      "instruction set");
2824           }
2825         /* Intel CPUs have always interpreted SSE prefetch instructions as
2826            NOPs; so, we can enable SSE prefetch instructions even when
2827            -mtune (rather than -march) points us to a processor that has them.
2828            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
2829            higher processors.  */
2830         if (TARGET_CMOVE
2831             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
2832           x86_prefetch_sse = true;
2833         break;
2834       }
2835   if (i == pta_size)
2836     error ("bad value (%s) for %stune=%s %s",
2837            ix86_tune_string, prefix, suffix, sw);
2838
2839   ix86_tune_mask = 1u << ix86_tune;
2840   for (i = 0; i < X86_TUNE_LAST; ++i)
2841     ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
2842
2843   if (optimize_size)
2844     ix86_cost = &size_cost;
2845   else
2846     ix86_cost = processor_target_table[ix86_tune].cost;
2847
2848   /* Arrange to set up i386_stack_locals for all functions.  */
2849   init_machine_status = ix86_init_machine_status;
2850
2851   /* Validate -mregparm= value.  */
2852   if (ix86_regparm_string)
2853     {
2854       if (TARGET_64BIT)
2855         warning (0, "%sregparm%s is ignored in 64-bit mode", prefix, suffix);
2856       i = atoi (ix86_regparm_string);
2857       if (i < 0 || i > REGPARM_MAX)
2858         error ("%sregparm=%d%s is not between 0 and %d",
2859                prefix, i, suffix, REGPARM_MAX);
2860       else
2861         ix86_regparm = i;
2862     }
2863   if (TARGET_64BIT)
2864     ix86_regparm = REGPARM_MAX;
2865
2866   /* If the user has provided any of the -malign-* options,
2867      warn and use that value only if -falign-* is not set.
2868      Remove this code in GCC 3.2 or later.  */
2869   if (ix86_align_loops_string)
2870     {
2871       warning (0, "%salign-loops%s is obsolete, use %salign-loops%s",
2872                prefix, suffix, prefix, suffix);
2873       if (align_loops == 0)
2874         {
2875           i = atoi (ix86_align_loops_string);
2876           if (i < 0 || i > MAX_CODE_ALIGN)
2877             error ("%salign-loops=%d%s is not between 0 and %d",
2878                    prefix, i, suffix, MAX_CODE_ALIGN);
2879           else
2880             align_loops = 1 << i;
2881         }
2882     }
2883
2884   if (ix86_align_jumps_string)
2885     {
2886       warning (0, "%salign-jumps%s is obsolete, use %salign-jumps%s",
2887                prefix, suffix, prefix, suffix);
2888       if (align_jumps == 0)
2889         {
2890           i = atoi (ix86_align_jumps_string);
2891           if (i < 0 || i > MAX_CODE_ALIGN)
2892             error ("%salign-loops=%d%s is not between 0 and %d",
2893                    prefix, i, suffix, MAX_CODE_ALIGN);
2894           else
2895             align_jumps = 1 << i;
2896         }
2897     }
2898
2899   if (ix86_align_funcs_string)
2900     {
2901       warning (0, "%salign-functions%s is obsolete, use %salign-functions%s",
2902                prefix, suffix, prefix, suffix);
2903       if (align_functions == 0)
2904         {
2905           i = atoi (ix86_align_funcs_string);
2906           if (i < 0 || i > MAX_CODE_ALIGN)
2907             error ("%salign-loops=%d%s is not between 0 and %d",
2908                    prefix, i, suffix, MAX_CODE_ALIGN);
2909           else
2910             align_functions = 1 << i;
2911         }
2912     }
2913
2914   /* Default align_* from the processor table.  */
2915   if (align_loops == 0)
2916     {
2917       align_loops = processor_target_table[ix86_tune].align_loop;
2918       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
2919     }
2920   if (align_jumps == 0)
2921     {
2922       align_jumps = processor_target_table[ix86_tune].align_jump;
2923       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
2924     }
2925   if (align_functions == 0)
2926     {
2927       align_functions = processor_target_table[ix86_tune].align_func;
2928     }
2929
2930   /* Validate -mbranch-cost= value, or provide default.  */
2931   ix86_branch_cost = ix86_cost->branch_cost;
2932   if (ix86_branch_cost_string)
2933     {
2934       i = atoi (ix86_branch_cost_string);
2935       if (i < 0 || i > 5)
2936         error ("%sbranch-cost=%d%s is not between 0 and 5", prefix, i, suffix);
2937       else
2938         ix86_branch_cost = i;
2939     }
2940   if (ix86_section_threshold_string)
2941     {
2942       i = atoi (ix86_section_threshold_string);
2943       if (i < 0)
2944         error ("%slarge-data-threshold=%d%s is negative", prefix, i, suffix);
2945       else
2946         ix86_section_threshold = i;
2947     }
2948
2949   if (ix86_tls_dialect_string)
2950     {
2951       if (strcmp (ix86_tls_dialect_string, "gnu") == 0)
2952         ix86_tls_dialect = TLS_DIALECT_GNU;
2953       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
2954         ix86_tls_dialect = TLS_DIALECT_GNU2;
2955       else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
2956         ix86_tls_dialect = TLS_DIALECT_SUN;
2957       else
2958         error ("bad value (%s) for %stls-dialect=%s %s",
2959                ix86_tls_dialect_string, prefix, suffix, sw);
2960     }
2961
2962   if (ix87_precision_string)
2963     {
2964       i = atoi (ix87_precision_string);
2965       if (i != 32 && i != 64 && i != 80)
2966         error ("pc%d is not valid precision setting (32, 64 or 80)", i);
2967     }
2968
2969   if (TARGET_64BIT)
2970     {
2971       target_flags |= TARGET_SUBTARGET64_DEFAULT & ~target_flags_explicit;
2972
2973       /* Enable by default the SSE and MMX builtins.  Do allow the user to
2974          explicitly disable any of these.  In particular, disabling SSE and
2975          MMX for kernel code is extremely useful.  */
2976       if (!ix86_arch_specified)
2977       ix86_isa_flags
2978         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
2979              | TARGET_SUBTARGET64_ISA_DEFAULT) & ~ix86_isa_flags_explicit);
2980
2981       if (TARGET_RTD)
2982         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
2983     }
2984   else
2985     {
2986       target_flags |= TARGET_SUBTARGET32_DEFAULT & ~target_flags_explicit;
2987
2988       if (!ix86_arch_specified)
2989       ix86_isa_flags
2990         |= TARGET_SUBTARGET32_ISA_DEFAULT & ~ix86_isa_flags_explicit;
2991
2992       /* i386 ABI does not specify red zone.  It still makes sense to use it
2993          when programmer takes care to stack from being destroyed.  */
2994       if (!(target_flags_explicit & MASK_NO_RED_ZONE))
2995         target_flags |= MASK_NO_RED_ZONE;
2996     }
2997
2998   /* Keep nonleaf frame pointers.  */
2999   if (flag_omit_frame_pointer)
3000     target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3001   else if (TARGET_OMIT_LEAF_FRAME_POINTER)
3002     flag_omit_frame_pointer = 1;
3003
3004   /* If we're doing fast math, we don't care about comparison order
3005      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3006   if (flag_finite_math_only)
3007     target_flags &= ~MASK_IEEE_FP;
3008
3009   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3010      since the insns won't need emulation.  */
3011   if (x86_arch_always_fancy_math_387 & ix86_arch_mask)
3012     target_flags &= ~MASK_NO_FANCY_MATH_387;
3013
3014   /* Likewise, if the target doesn't have a 387, or we've specified
3015      software floating point, don't use 387 inline intrinsics.  */
3016   if (!TARGET_80387)
3017     target_flags |= MASK_NO_FANCY_MATH_387;
3018
3019   /* Turn on MMX builtins for -msse.  */
3020   if (TARGET_SSE)
3021     {
3022       ix86_isa_flags |= OPTION_MASK_ISA_MMX & ~ix86_isa_flags_explicit;
3023       x86_prefetch_sse = true;
3024     }
3025
3026   /* Turn on popcnt instruction for -msse4.2 or -mabm.  */
3027   if (TARGET_SSE4_2 || TARGET_ABM)
3028     ix86_isa_flags |= OPTION_MASK_ISA_POPCNT & ~ix86_isa_flags_explicit;
3029
3030   /* Validate -mpreferred-stack-boundary= value or default it to
3031      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
3032   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
3033   if (ix86_preferred_stack_boundary_string)
3034     {
3035       i = atoi (ix86_preferred_stack_boundary_string);
3036       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3037         error ("%spreferred-stack-boundary=%d%s is not between %d and 12",
3038                prefix, i, suffix, TARGET_64BIT ? 4 : 2);
3039       else
3040         ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
3041     }
3042
3043   /* Set the default value for -mstackrealign.  */
3044   if (ix86_force_align_arg_pointer == -1)
3045     ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
3046
3047   /* Validate -mincoming-stack-boundary= value or default it to
3048      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
3049   if (ix86_force_align_arg_pointer)
3050     ix86_default_incoming_stack_boundary = MIN_STACK_BOUNDARY;
3051   else
3052     ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
3053   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
3054   if (ix86_incoming_stack_boundary_string)
3055     {
3056       i = atoi (ix86_incoming_stack_boundary_string);
3057       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3058         error ("-mincoming-stack-boundary=%d is not between %d and 12",
3059                i, TARGET_64BIT ? 4 : 2);
3060       else
3061         {
3062           ix86_user_incoming_stack_boundary = (1 << i) * BITS_PER_UNIT;
3063           ix86_incoming_stack_boundary
3064             = ix86_user_incoming_stack_boundary;
3065         }
3066     }
3067
3068   /* Accept -msseregparm only if at least SSE support is enabled.  */
3069   if (TARGET_SSEREGPARM
3070       && ! TARGET_SSE)
3071     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
3072
3073   ix86_fpmath = TARGET_FPMATH_DEFAULT;
3074   if (ix86_fpmath_string != 0)
3075     {
3076       if (! strcmp (ix86_fpmath_string, "387"))
3077         ix86_fpmath = FPMATH_387;
3078       else if (! strcmp (ix86_fpmath_string, "sse"))
3079         {
3080           if (!TARGET_SSE)
3081             {
3082               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3083               ix86_fpmath = FPMATH_387;
3084             }
3085           else
3086             ix86_fpmath = FPMATH_SSE;
3087         }
3088       else if (! strcmp (ix86_fpmath_string, "387,sse")
3089                || ! strcmp (ix86_fpmath_string, "387+sse")
3090                || ! strcmp (ix86_fpmath_string, "sse,387")
3091                || ! strcmp (ix86_fpmath_string, "sse+387")
3092                || ! strcmp (ix86_fpmath_string, "both"))
3093         {
3094           if (!TARGET_SSE)
3095             {
3096               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3097               ix86_fpmath = FPMATH_387;
3098             }
3099           else if (!TARGET_80387)
3100             {
3101               warning (0, "387 instruction set disabled, using SSE arithmetics");
3102               ix86_fpmath = FPMATH_SSE;
3103             }
3104           else
3105             ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
3106         }
3107       else
3108         error ("bad value (%s) for %sfpmath=%s %s",
3109                ix86_fpmath_string, prefix, suffix, sw);
3110     }
3111
3112   /* If the i387 is disabled, then do not return values in it. */
3113   if (!TARGET_80387)
3114     target_flags &= ~MASK_FLOAT_RETURNS;
3115
3116   /* Use external vectorized library in vectorizing intrinsics.  */
3117   if (ix86_veclibabi_string)
3118     {
3119       if (strcmp (ix86_veclibabi_string, "svml") == 0)
3120         ix86_veclib_handler = ix86_veclibabi_svml;
3121       else if (strcmp (ix86_veclibabi_string, "acml") == 0)
3122         ix86_veclib_handler = ix86_veclibabi_acml;
3123       else
3124         error ("unknown vectorization library ABI type (%s) for "
3125                "%sveclibabi=%s %s", ix86_veclibabi_string,
3126                prefix, suffix, sw);
3127     }
3128
3129   if ((x86_accumulate_outgoing_args & ix86_tune_mask)
3130       && !(target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3131       && !optimize_size)
3132     target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3133
3134   /* ??? Unwind info is not correct around the CFG unless either a frame
3135      pointer is present or M_A_O_A is set.  Fixing this requires rewriting
3136      unwind info generation to be aware of the CFG and propagating states
3137      around edges.  */
3138   if ((flag_unwind_tables || flag_asynchronous_unwind_tables
3139        || flag_exceptions || flag_non_call_exceptions)
3140       && flag_omit_frame_pointer
3141       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3142     {
3143       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3144         warning (0, "unwind tables currently require either a frame pointer "
3145                  "or %saccumulate-outgoing-args%s for correctness",
3146                  prefix, suffix);
3147       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3148     }
3149
3150   /* If stack probes are required, the space used for large function
3151      arguments on the stack must also be probed, so enable
3152      -maccumulate-outgoing-args so this happens in the prologue.  */
3153   if (TARGET_STACK_PROBE
3154       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3155     {
3156       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3157         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
3158                  "for correctness", prefix, suffix);
3159       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3160     }
3161
3162   /* For sane SSE instruction set generation we need fcomi instruction.
3163      It is safe to enable all CMOVE instructions.  */
3164   if (TARGET_SSE)
3165     TARGET_CMOVE = 1;
3166
3167   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
3168   {
3169     char *p;
3170     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
3171     p = strchr (internal_label_prefix, 'X');
3172     internal_label_prefix_len = p - internal_label_prefix;
3173     *p = '\0';
3174   }
3175
3176   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
3177     set_param_value ("simultaneous-prefetches",
3178                      ix86_cost->simultaneous_prefetches);
3179   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
3180     set_param_value ("l1-cache-line-size", ix86_cost->prefetch_block);
3181   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
3182     set_param_value ("l1-cache-size", ix86_cost->l1_cache_size);
3183   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
3184     set_param_value ("l2-cache-size", ix86_cost->l2_cache_size);
3185
3186   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
3187      can be optimized to ap = __builtin_next_arg (0).  */
3188   if (!TARGET_64BIT)
3189     targetm.expand_builtin_va_start = NULL;
3190
3191   if (TARGET_64BIT)
3192     {
3193       ix86_gen_leave = gen_leave_rex64;
3194       ix86_gen_pop1 = gen_popdi1;
3195       ix86_gen_add3 = gen_adddi3;
3196       ix86_gen_sub3 = gen_subdi3;
3197       ix86_gen_sub3_carry = gen_subdi3_carry_rex64;
3198       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
3199       ix86_gen_monitor = gen_sse3_monitor64;
3200       ix86_gen_andsp = gen_anddi3;
3201     }
3202   else
3203     {
3204       ix86_gen_leave = gen_leave;
3205       ix86_gen_pop1 = gen_popsi1;
3206       ix86_gen_add3 = gen_addsi3;
3207       ix86_gen_sub3 = gen_subsi3;
3208       ix86_gen_sub3_carry = gen_subsi3_carry;
3209       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
3210       ix86_gen_monitor = gen_sse3_monitor;
3211       ix86_gen_andsp = gen_andsi3;
3212     }
3213
3214 #ifdef USE_IX86_CLD
3215   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
3216   if (!TARGET_64BIT)
3217     target_flags |= MASK_CLD & ~target_flags_explicit;
3218 #endif
3219
3220   /* Save the initial options in case the user does function specific options */
3221   if (main_args_p)
3222     target_option_default_node = target_option_current_node
3223       = build_target_option_node ();
3224 }
3225 \f
3226 /* Save the current options */
3227
3228 static void
3229 ix86_function_specific_save (struct cl_target_option *ptr)
3230 {
3231   gcc_assert (IN_RANGE (ix86_arch, 0, 255));
3232   gcc_assert (IN_RANGE (ix86_tune, 0, 255));
3233   gcc_assert (IN_RANGE (ix86_fpmath, 0, 255));
3234   gcc_assert (IN_RANGE (ix86_branch_cost, 0, 255));
3235
3236   ptr->arch = ix86_arch;
3237   ptr->tune = ix86_tune;
3238   ptr->fpmath = ix86_fpmath;
3239   ptr->branch_cost = ix86_branch_cost;
3240   ptr->tune_defaulted = ix86_tune_defaulted;
3241   ptr->arch_specified = ix86_arch_specified;
3242   ptr->ix86_isa_flags_explicit = ix86_isa_flags_explicit;
3243   ptr->target_flags_explicit = target_flags_explicit;
3244 }
3245
3246 /* Restore the current options */
3247
3248 static void
3249 ix86_function_specific_restore (struct cl_target_option *ptr)
3250 {
3251   enum processor_type old_tune = ix86_tune;
3252   enum processor_type old_arch = ix86_arch;
3253   unsigned int ix86_arch_mask, ix86_tune_mask;
3254   int i;
3255
3256   ix86_arch = ptr->arch;
3257   ix86_tune = ptr->tune;
3258   ix86_fpmath = ptr->fpmath;
3259   ix86_branch_cost = ptr->branch_cost;
3260   ix86_tune_defaulted = ptr->tune_defaulted;
3261   ix86_arch_specified = ptr->arch_specified;
3262   ix86_isa_flags_explicit = ptr->ix86_isa_flags_explicit;
3263   target_flags_explicit = ptr->target_flags_explicit;
3264
3265   /* Recreate the arch feature tests if the arch changed */
3266   if (old_arch != ix86_arch)
3267     {
3268       ix86_arch_mask = 1u << ix86_arch;
3269       for (i = 0; i < X86_ARCH_LAST; ++i)
3270         ix86_arch_features[i]
3271           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3272     }
3273
3274   /* Recreate the tune optimization tests */
3275   if (old_tune != ix86_tune)
3276     {
3277       ix86_tune_mask = 1u << ix86_tune;
3278       for (i = 0; i < X86_TUNE_LAST; ++i)
3279         ix86_tune_features[i]
3280           = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3281     }
3282 }
3283
3284 /* Print the current options */
3285
3286 static void
3287 ix86_function_specific_print (FILE *file, int indent,
3288                               struct cl_target_option *ptr)
3289 {
3290   char *target_string
3291     = ix86_target_string (ptr->ix86_isa_flags, ptr->target_flags,
3292                           NULL, NULL, NULL, false);
3293
3294   fprintf (file, "%*sarch = %d (%s)\n",
3295            indent, "",
3296            ptr->arch,
3297            ((ptr->arch < TARGET_CPU_DEFAULT_max)
3298             ? cpu_names[ptr->arch]
3299             : "<unknown>"));
3300
3301   fprintf (file, "%*stune = %d (%s)\n",
3302            indent, "",
3303            ptr->tune,
3304            ((ptr->tune < TARGET_CPU_DEFAULT_max)
3305             ? cpu_names[ptr->tune]
3306             : "<unknown>"));
3307
3308   fprintf (file, "%*sfpmath = %d%s%s\n", indent, "", ptr->fpmath,
3309            (ptr->fpmath & FPMATH_387) ? ", 387" : "",
3310            (ptr->fpmath & FPMATH_SSE) ? ", sse" : "");
3311   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
3312
3313   if (target_string)
3314     {
3315       fprintf (file, "%*s%s\n", indent, "", target_string);
3316       free (target_string);
3317     }
3318 }
3319
3320 \f
3321 /* Inner function to process the attribute((option(...))), take an argument and
3322    set the current options from the argument. If we have a list, recursively go
3323    over the list.  */
3324
3325 static bool
3326 ix86_valid_option_attribute_inner_p (tree args, char *p_strings[])
3327 {
3328   char *next_optstr;
3329   bool ret = true;
3330
3331 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
3332 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
3333 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
3334 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
3335
3336   enum ix86_opt_type
3337   {
3338     ix86_opt_unknown,
3339     ix86_opt_yes,
3340     ix86_opt_no,
3341     ix86_opt_str,
3342     ix86_opt_isa
3343   };
3344
3345   static const struct
3346   {
3347     const char *string;
3348     size_t len;
3349     enum ix86_opt_type type;
3350     int opt;
3351     int mask;
3352   } attrs[] = {
3353     /* isa options */
3354     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
3355     IX86_ATTR_ISA ("abm",       OPT_mabm),
3356     IX86_ATTR_ISA ("aes",       OPT_maes),
3357     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
3358     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
3359     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
3360     IX86_ATTR_ISA ("sse",       OPT_msse),
3361     IX86_ATTR_ISA ("sse2",      OPT_msse2),
3362     IX86_ATTR_ISA ("sse3",      OPT_msse3),
3363     IX86_ATTR_ISA ("sse4",      OPT_msse4),
3364     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
3365     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
3366     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
3367     IX86_ATTR_ISA ("sse5",      OPT_msse5),
3368     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
3369
3370     /* string options */
3371     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
3372     IX86_ATTR_STR ("fpmath=",   IX86_FUNCTION_SPECIFIC_FPMATH),
3373     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
3374
3375     /* flag options */
3376     IX86_ATTR_YES ("cld",
3377                    OPT_mcld,
3378                    MASK_CLD),
3379
3380     IX86_ATTR_NO ("fancy-math-387",
3381                   OPT_mfancy_math_387,
3382                   MASK_NO_FANCY_MATH_387),
3383
3384     IX86_ATTR_NO ("fused-madd",
3385                   OPT_mfused_madd,
3386                   MASK_NO_FUSED_MADD),
3387
3388     IX86_ATTR_YES ("ieee-fp",
3389                    OPT_mieee_fp,
3390                    MASK_IEEE_FP),
3391
3392     IX86_ATTR_YES ("inline-all-stringops",
3393                    OPT_minline_all_stringops,
3394                    MASK_INLINE_ALL_STRINGOPS),
3395
3396     IX86_ATTR_YES ("inline-stringops-dynamically",
3397                    OPT_minline_stringops_dynamically,
3398                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
3399
3400     IX86_ATTR_NO ("align-stringops",
3401                   OPT_mno_align_stringops,
3402                   MASK_NO_ALIGN_STRINGOPS),
3403
3404     IX86_ATTR_YES ("recip",
3405                    OPT_mrecip,
3406                    MASK_RECIP),
3407
3408   };
3409
3410   /* If this is a list, recurse to get the options.  */
3411   if (TREE_CODE (args) == TREE_LIST)
3412     {
3413       bool ret = true;
3414
3415       for (; args; args = TREE_CHAIN (args))
3416         if (TREE_VALUE (args)
3417             && !ix86_valid_option_attribute_inner_p (TREE_VALUE (args), p_strings))
3418           ret = false;
3419
3420       return ret;
3421     }
3422
3423   else if (TREE_CODE (args) != STRING_CST)
3424     gcc_unreachable ();
3425
3426   /* Handle multiple arguments separated by commas.  */
3427   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
3428
3429   while (next_optstr && *next_optstr != '\0')
3430     {
3431       char *p = next_optstr;
3432       char *orig_p = p;
3433       char *comma = strchr (next_optstr, ',');
3434       const char *opt_string;
3435       size_t len, opt_len;
3436       int opt;
3437       bool opt_set_p;
3438       char ch;
3439       unsigned i;
3440       enum ix86_opt_type type = ix86_opt_unknown;
3441       int mask = 0;
3442
3443       if (comma)
3444         {
3445           *comma = '\0';
3446           len = comma - next_optstr;
3447           next_optstr = comma + 1;
3448         }
3449       else
3450         {
3451           len = strlen (p);
3452           next_optstr = NULL;
3453         }
3454
3455       /* Recognize no-xxx.  */
3456       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
3457         {
3458           opt_set_p = false;
3459           p += 3;
3460           len -= 3;
3461         }
3462       else
3463         opt_set_p = true;
3464
3465       /* Find the option.  */
3466       ch = *p;
3467       opt = N_OPTS;
3468       for (i = 0; i < sizeof (attrs) / sizeof (attrs[0]); i++)
3469         {
3470           type = attrs[i].type;
3471           opt_len = attrs[i].len;
3472           if (ch == attrs[i].string[0]
3473               && ((type != ix86_opt_str) ? len == opt_len : len > opt_len)
3474               && memcmp (p, attrs[i].string, opt_len) == 0)
3475             {
3476               opt = attrs[i].opt;
3477               mask = attrs[i].mask;
3478               opt_string = attrs[i].string;
3479               break;
3480             }
3481         }
3482
3483       /* Process the option.  */
3484       if (opt == N_OPTS)
3485         {
3486           error ("attribute(option(\"%s\")) is unknown", orig_p);
3487           ret = false;
3488         }
3489
3490       else if (type == ix86_opt_isa)
3491         ix86_handle_option (opt, p, opt_set_p);
3492
3493       else if (type == ix86_opt_yes || type == ix86_opt_no)
3494         {
3495           if (type == ix86_opt_no)
3496             opt_set_p = !opt_set_p;
3497
3498           if (opt_set_p)
3499             target_flags |= mask;
3500           else
3501             target_flags &= ~mask;
3502         }
3503
3504       else if (type == ix86_opt_str)
3505         {
3506           if (p_strings[opt])
3507             {
3508               error ("option(\"%s\") was already specified", opt_string);
3509               ret = false;
3510             }
3511           else
3512             p_strings[opt] = xstrdup (p + opt_len);
3513         }
3514
3515       else
3516         gcc_unreachable ();
3517     }
3518
3519   return ret;
3520 }
3521
3522 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
3523
3524 tree
3525 ix86_valid_option_attribute_tree (tree args)
3526 {
3527   const char *orig_arch_string = ix86_arch_string;
3528   const char *orig_tune_string = ix86_tune_string;
3529   const char *orig_fpmath_string = ix86_fpmath_string;
3530   int orig_tune_defaulted = ix86_tune_defaulted;
3531   int orig_arch_specified = ix86_arch_specified;
3532   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL, NULL };
3533   tree t = NULL_TREE;
3534   int i;
3535   struct cl_target_option *def
3536     = TREE_TARGET_OPTION (target_option_default_node);
3537
3538   /* Process each of the options on the chain.  */
3539   if (! ix86_valid_option_attribute_inner_p (args, option_strings))
3540     return NULL_TREE;
3541
3542   /* If the changed options are different from the default, rerun override_options,
3543      and then save the options away.  The string options are are attribute options,
3544      and will be undone when we copy the save structure.  */
3545   if (ix86_isa_flags != def->ix86_isa_flags
3546       || target_flags != def->target_flags
3547       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
3548       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
3549       || option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3550     {
3551       /* If we are using the default tune= or arch=, undo the string assigned,
3552          and use the default.  */
3553       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
3554         ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
3555       else if (!orig_arch_specified)
3556         ix86_arch_string = NULL;
3557
3558       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
3559         ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
3560       else if (orig_tune_defaulted)
3561         ix86_tune_string = NULL;
3562
3563       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
3564       if (option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3565         ix86_fpmath_string = option_strings[IX86_FUNCTION_SPECIFIC_FPMATH];
3566       else if (!TARGET_64BIT && TARGET_SSE)
3567         ix86_fpmath_string = "sse,387";
3568
3569       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
3570       override_options (false);
3571
3572       /* Save the current options unless we are validating options for
3573          #pragma.  */
3574       t = build_target_option_node ();
3575
3576       ix86_arch_string = orig_arch_string;
3577       ix86_tune_string = orig_tune_string;
3578       ix86_fpmath_string = orig_fpmath_string;
3579
3580       /* Free up memory allocated to hold the strings */
3581       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
3582         if (option_strings[i])
3583           free (option_strings[i]);
3584     }
3585
3586   return t;
3587 }
3588
3589 /* Hook to validate attribute((option("string"))).  */
3590
3591 static bool
3592 ix86_valid_option_attribute_p (tree fndecl,
3593                                tree ARG_UNUSED (name),
3594                                tree args,
3595                                int ARG_UNUSED (flags))
3596 {
3597   struct cl_target_option cur_opts;
3598   bool ret = true;
3599   tree new_opts;
3600
3601   cl_target_option_save (&cur_opts);
3602   new_opts = ix86_valid_option_attribute_tree (args);
3603   if (!new_opts)
3604     ret = false;
3605
3606   else if (fndecl)
3607     DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_opts;
3608
3609   cl_target_option_restore (&cur_opts);
3610   return ret;
3611 }
3612
3613 \f
3614 /* Hook to determine if one function can safely inline another.  */
3615
3616 static bool
3617 ix86_can_inline_p (tree caller, tree callee)
3618 {
3619   bool ret = false;
3620   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
3621   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
3622
3623   /* If callee has no option attributes, then it is ok to inline.  */
3624   if (!callee_tree)
3625     ret = true;
3626
3627   /* If caller has no option attributes, but callee does then it is not ok to
3628      inline.  */
3629   else if (!caller_tree)
3630     ret = false;
3631
3632   else
3633     {
3634       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
3635       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
3636
3637       /* Callee's isa options should a subset of the caller's, i.e. a SSE5 function
3638          can inline a SSE2 function but a SSE2 function can't inline a SSE5
3639          function.  */
3640       if ((caller_opts->ix86_isa_flags & callee_opts->ix86_isa_flags)
3641           != callee_opts->ix86_isa_flags)
3642         ret = false;
3643
3644       /* See if we have the same non-isa options.  */
3645       else if (caller_opts->target_flags != callee_opts->target_flags)
3646         ret = false;
3647
3648       /* See if arch, tune, etc. are the same.  */
3649       else if (caller_opts->arch != callee_opts->arch)
3650         ret = false;
3651
3652       else if (caller_opts->tune != callee_opts->tune)
3653         ret = false;
3654
3655       else if (caller_opts->fpmath != callee_opts->fpmath)
3656         ret = false;
3657
3658       else if (caller_opts->branch_cost != callee_opts->branch_cost)
3659         ret = false;
3660
3661       else
3662         ret = true;
3663     }
3664
3665   return ret;
3666 }
3667
3668 \f
3669 /* Remember the last target of ix86_set_current_function.  */
3670 static GTY(()) tree ix86_previous_fndecl;
3671
3672 /* Establish appropriate back-end context for processing the function
3673    FNDECL.  The argument might be NULL to indicate processing at top
3674    level, outside of any function scope.  */
3675 static void
3676 ix86_set_current_function (tree fndecl)
3677 {
3678   /* Only change the context if the function changes.  This hook is called
3679      several times in the course of compiling a function, and we don't want to
3680      slow things down too much or call target_reinit when it isn't safe.  */
3681   if (fndecl && fndecl != ix86_previous_fndecl)
3682     {
3683       tree old_tree = (ix86_previous_fndecl
3684                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
3685                        : NULL_TREE);
3686
3687       tree new_tree = (fndecl
3688                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
3689                        : NULL_TREE);
3690
3691       ix86_previous_fndecl = fndecl;
3692       if (old_tree == new_tree)
3693         ;
3694
3695       else if (new_tree)
3696         {
3697           cl_target_option_restore (TREE_TARGET_OPTION (new_tree));
3698           target_reinit ();
3699         }
3700
3701       else if (old_tree)
3702         {
3703           struct cl_target_option *def
3704             = TREE_TARGET_OPTION (target_option_current_node);
3705
3706           cl_target_option_restore (def);
3707           target_reinit ();
3708         }
3709     }
3710 }
3711
3712 \f
3713 /* Return true if this goes in large data/bss.  */
3714
3715 static bool
3716 ix86_in_large_data_p (tree exp)
3717 {
3718   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
3719     return false;
3720
3721   /* Functions are never large data.  */
3722   if (TREE_CODE (exp) == FUNCTION_DECL)
3723     return false;
3724
3725   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
3726     {
3727       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
3728       if (strcmp (section, ".ldata") == 0
3729           || strcmp (section, ".lbss") == 0)
3730         return true;
3731       return false;
3732     }
3733   else
3734     {
3735       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3736
3737       /* If this is an incomplete type with size 0, then we can't put it
3738          in data because it might be too big when completed.  */
3739       if (!size || size > ix86_section_threshold)
3740         return true;
3741     }
3742
3743   return false;
3744 }
3745
3746 /* Switch to the appropriate section for output of DECL.
3747    DECL is either a `VAR_DECL' node or a constant of some sort.
3748    RELOC indicates whether forming the initial value of DECL requires
3749    link-time relocations.  */
3750
3751 static section * x86_64_elf_select_section (tree, int, unsigned HOST_WIDE_INT)
3752         ATTRIBUTE_UNUSED;
3753
3754 static section *
3755 x86_64_elf_select_section (tree decl, int reloc,
3756                            unsigned HOST_WIDE_INT align)
3757 {
3758   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3759       && ix86_in_large_data_p (decl))
3760     {
3761       const char *sname = NULL;
3762       unsigned int flags = SECTION_WRITE;
3763       switch (categorize_decl_for_section (decl, reloc))
3764         {
3765         case SECCAT_DATA:
3766           sname = ".ldata";
3767           break;
3768         case SECCAT_DATA_REL:
3769           sname = ".ldata.rel";
3770           break;
3771         case SECCAT_DATA_REL_LOCAL:
3772           sname = ".ldata.rel.local";
3773           break;
3774         case SECCAT_DATA_REL_RO:
3775           sname = ".ldata.rel.ro";
3776           break;
3777         case SECCAT_DATA_REL_RO_LOCAL:
3778           sname = ".ldata.rel.ro.local";
3779           break;
3780         case SECCAT_BSS:
3781           sname = ".lbss";
3782           flags |= SECTION_BSS;
3783           break;
3784         case SECCAT_RODATA:
3785         case SECCAT_RODATA_MERGE_STR:
3786         case SECCAT_RODATA_MERGE_STR_INIT:
3787         case SECCAT_RODATA_MERGE_CONST:
3788           sname = ".lrodata";
3789           flags = 0;
3790           break;
3791         case SECCAT_SRODATA:
3792         case SECCAT_SDATA:
3793         case SECCAT_SBSS:
3794           gcc_unreachable ();
3795         case SECCAT_TEXT:
3796         case SECCAT_TDATA:
3797         case SECCAT_TBSS:
3798           /* We don't split these for medium model.  Place them into
3799              default sections and hope for best.  */
3800           break;
3801         case SECCAT_EMUTLS_VAR:
3802         case SECCAT_EMUTLS_TMPL:
3803           gcc_unreachable ();
3804         }
3805       if (sname)
3806         {
3807           /* We might get called with string constants, but get_named_section
3808              doesn't like them as they are not DECLs.  Also, we need to set
3809              flags in that case.  */
3810           if (!DECL_P (decl))
3811             return get_section (sname, flags, NULL);
3812           return get_named_section (decl, sname, reloc);
3813         }
3814     }
3815   return default_elf_select_section (decl, reloc, align);
3816 }
3817
3818 /* Build up a unique section name, expressed as a
3819    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
3820    RELOC indicates whether the initial value of EXP requires
3821    link-time relocations.  */
3822
3823 static void ATTRIBUTE_UNUSED
3824 x86_64_elf_unique_section (tree decl, int reloc)
3825 {
3826   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3827       && ix86_in_large_data_p (decl))
3828     {
3829       const char *prefix = NULL;
3830       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
3831       bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
3832
3833       switch (categorize_decl_for_section (decl, reloc))
3834         {
3835         case SECCAT_DATA:
3836         case SECCAT_DATA_REL:
3837         case SECCAT_DATA_REL_LOCAL:
3838         case SECCAT_DATA_REL_RO:
3839         case SECCAT_DATA_REL_RO_LOCAL:
3840           prefix = one_only ? ".ld" : ".ldata";
3841           break;
3842         case SECCAT_BSS:
3843           prefix = one_only ? ".lb" : ".lbss";
3844           break;
3845         case SECCAT_RODATA:
3846         case SECCAT_RODATA_MERGE_STR:
3847         case SECCAT_RODATA_MERGE_STR_INIT:
3848         case SECCAT_RODATA_MERGE_CONST:
3849           prefix = one_only ? ".lr" : ".lrodata";
3850           break;
3851         case SECCAT_SRODATA:
3852         case SECCAT_SDATA:
3853         case SECCAT_SBSS:
3854           gcc_unreachable ();
3855         case SECCAT_TEXT:
3856         case SECCAT_TDATA:
3857         case SECCAT_TBSS:
3858           /* We don't split these for medium model.  Place them into
3859              default sections and hope for best.  */
3860           break;
3861         case SECCAT_EMUTLS_VAR:
3862           prefix = targetm.emutls.var_section;
3863           break;
3864         case SECCAT_EMUTLS_TMPL:
3865           prefix = targetm.emutls.tmpl_section;
3866           break;
3867         }
3868       if (prefix)
3869         {
3870           const char *name, *linkonce;
3871           char *string;
3872
3873           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
3874           name = targetm.strip_name_encoding (name);
3875           
3876           /* If we're using one_only, then there needs to be a .gnu.linkonce
3877              prefix to the section name.  */
3878           linkonce = one_only ? ".gnu.linkonce" : "";
3879   
3880           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
3881           
3882           DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
3883           return;
3884         }
3885     }
3886   default_unique_section (decl, reloc);
3887 }
3888
3889 #ifdef COMMON_ASM_OP
3890 /* This says how to output assembler code to declare an
3891    uninitialized external linkage data object.
3892
3893    For medium model x86-64 we need to use .largecomm opcode for
3894    large objects.  */
3895 void
3896 x86_elf_aligned_common (FILE *file,
3897                         const char *name, unsigned HOST_WIDE_INT size,
3898                         int align)
3899 {
3900   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3901       && size > (unsigned int)ix86_section_threshold)
3902     fprintf (file, ".largecomm\t");
3903   else
3904     fprintf (file, "%s", COMMON_ASM_OP);
3905   assemble_name (file, name);
3906   fprintf (file, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",
3907            size, align / BITS_PER_UNIT);
3908 }
3909 #endif
3910
3911 /* Utility function for targets to use in implementing
3912    ASM_OUTPUT_ALIGNED_BSS.  */
3913
3914 void
3915 x86_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
3916                         const char *name, unsigned HOST_WIDE_INT size,
3917                         int align)
3918 {
3919   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3920       && size > (unsigned int)ix86_section_threshold)
3921     switch_to_section (get_named_section (decl, ".lbss", 0));
3922   else
3923     switch_to_section (bss_section);
3924   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
3925 #ifdef ASM_DECLARE_OBJECT_NAME
3926   last_assemble_variable_decl = decl;
3927   ASM_DECLARE_OBJECT_NAME (file, name, decl);
3928 #else
3929   /* Standard thing is just output label for the object.  */
3930   ASM_OUTPUT_LABEL (file, name);
3931 #endif /* ASM_DECLARE_OBJECT_NAME */
3932   ASM_OUTPUT_SKIP (file, size ? size : 1);
3933 }
3934 \f
3935 void
3936 optimization_options (int level, int size ATTRIBUTE_UNUSED)
3937 {
3938   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
3939      make the problem with not enough registers even worse.  */
3940 #ifdef INSN_SCHEDULING
3941   if (level > 1)
3942     flag_schedule_insns = 0;
3943 #endif
3944
3945   /* When scheduling description is not available, disable scheduler pass
3946      so it won't slow down the compilation and make x87 code slower.  */
3947   if (!TARGET_SCHEDULE)
3948     flag_schedule_insns_after_reload = flag_schedule_insns = 0;
3949
3950   if (TARGET_MACHO)
3951     /* The Darwin libraries never set errno, so we might as well
3952        avoid calling them when that's the only reason we would.  */
3953     flag_errno_math = 0;
3954
3955   /* The default values of these switches depend on the TARGET_64BIT
3956      that is not known at this moment.  Mark these values with 2 and
3957      let user the to override these.  In case there is no command line option
3958      specifying them, we will set the defaults in override_options.  */
3959   if (optimize >= 1)
3960     flag_omit_frame_pointer = 2;
3961   flag_pcc_struct_return = 2;
3962   flag_asynchronous_unwind_tables = 2;
3963   flag_vect_cost_model = 1;
3964 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
3965   SUBTARGET_OPTIMIZATION_OPTIONS;
3966 #endif
3967 }
3968 \f
3969 /* Decide whether we can make a sibling call to a function.  DECL is the
3970    declaration of the function being targeted by the call and EXP is the
3971    CALL_EXPR representing the call.  */
3972
3973 static bool
3974 ix86_function_ok_for_sibcall (tree decl, tree exp)
3975 {
3976   tree func;
3977   rtx a, b;
3978
3979   /* If we are generating position-independent code, we cannot sibcall
3980      optimize any indirect call, or a direct call to a global function,
3981      as the PLT requires %ebx be live.  */
3982   if (!TARGET_64BIT && flag_pic && (!decl || !targetm.binds_local_p (decl)))
3983     return false;
3984
3985   if (decl)
3986     func = decl;
3987   else
3988     {
3989       func = TREE_TYPE (CALL_EXPR_FN (exp));
3990       if (POINTER_TYPE_P (func))
3991         func = TREE_TYPE (func);
3992     }
3993
3994   /* Check that the return value locations are the same.  Like
3995      if we are returning floats on the 80387 register stack, we cannot
3996      make a sibcall from a function that doesn't return a float to a
3997      function that does or, conversely, from a function that does return
3998      a float to a function that doesn't; the necessary stack adjustment
3999      would not be executed.  This is also the place we notice
4000      differences in the return value ABI.  Note that it is ok for one
4001      of the functions to have void return type as long as the return
4002      value of the other is passed in a register.  */
4003   a = ix86_function_value (TREE_TYPE (exp), func, false);
4004   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
4005                            cfun->decl, false);
4006   if (STACK_REG_P (a) || STACK_REG_P (b))
4007     {
4008       if (!rtx_equal_p (a, b))
4009         return false;
4010     }
4011   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
4012     ;
4013   else if (!rtx_equal_p (a, b))
4014     return false;
4015
4016   /* If this call is indirect, we'll need to be able to use a call-clobbered
4017      register for the address of the target function.  Make sure that all
4018      such registers are not used for passing parameters.  */
4019   if (!decl && !TARGET_64BIT)
4020     {
4021       tree type;
4022
4023       /* We're looking at the CALL_EXPR, we need the type of the function.  */
4024       type = CALL_EXPR_FN (exp);                /* pointer expression */
4025       type = TREE_TYPE (type);                  /* pointer type */
4026       type = TREE_TYPE (type);                  /* function type */
4027
4028       if (ix86_function_regparm (type, NULL) >= 3)
4029         {
4030           /* ??? Need to count the actual number of registers to be used,
4031              not the possible number of registers.  Fix later.  */
4032           return false;
4033         }
4034     }
4035
4036   /* Dllimport'd functions are also called indirectly.  */
4037   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
4038       && decl && DECL_DLLIMPORT_P (decl)
4039       && ix86_function_regparm (TREE_TYPE (decl), NULL) >= 3)
4040     return false;
4041
4042   /* Otherwise okay.  That also includes certain types of indirect calls.  */
4043   return true;
4044 }
4045
4046 /* Handle "cdecl", "stdcall", "fastcall", "regparm" and "sseregparm"
4047    calling convention attributes;
4048    arguments as in struct attribute_spec.handler.  */
4049
4050 static tree
4051 ix86_handle_cconv_attribute (tree *node, tree name,
4052                                    tree args,
4053                                    int flags ATTRIBUTE_UNUSED,
4054                                    bool *no_add_attrs)
4055 {
4056   if (TREE_CODE (*node) != FUNCTION_TYPE
4057       && TREE_CODE (*node) != METHOD_TYPE
4058       && TREE_CODE (*node) != FIELD_DECL
4059       && TREE_CODE (*node) != TYPE_DECL)
4060     {
4061       warning (OPT_Wattributes, "%qs attribute only applies to functions",
4062                IDENTIFIER_POINTER (name));
4063       *no_add_attrs = true;
4064       return NULL_TREE;
4065     }
4066
4067   /* Can combine regparm with all attributes but fastcall.  */
4068   if (is_attribute_p ("regparm", name))
4069     {
4070       tree cst;
4071
4072       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4073         {
4074           error ("fastcall and regparm attributes are not compatible");
4075         }
4076
4077       cst = TREE_VALUE (args);
4078       if (TREE_CODE (cst) != INTEGER_CST)
4079         {
4080           warning (OPT_Wattributes,
4081                    "%qs attribute requires an integer constant argument",
4082                    IDENTIFIER_POINTER (name));
4083           *no_add_attrs = true;
4084         }
4085       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
4086         {
4087           warning (OPT_Wattributes, "argument to %qs attribute larger than %d",
4088                    IDENTIFIER_POINTER (name), REGPARM_MAX);
4089           *no_add_attrs = true;
4090         }
4091
4092       return NULL_TREE;
4093     }
4094
4095   if (TARGET_64BIT)
4096     {
4097       /* Do not warn when emulating the MS ABI.  */
4098       if (TREE_CODE (*node) != FUNCTION_TYPE || ix86_function_type_abi (*node)!=MS_ABI)
4099         warning (OPT_Wattributes, "%qs attribute ignored",
4100                  IDENTIFIER_POINTER (name));
4101       *no_add_attrs = true;
4102       return NULL_TREE;
4103     }
4104
4105   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
4106   if (is_attribute_p ("fastcall", name))
4107     {
4108       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4109         {
4110           error ("fastcall and cdecl attributes are not compatible");
4111         }
4112       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4113         {
4114           error ("fastcall and stdcall attributes are not compatible");
4115         }
4116       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
4117         {
4118           error ("fastcall and regparm attributes are not compatible");
4119         }
4120     }
4121
4122   /* Can combine stdcall with fastcall (redundant), regparm and
4123      sseregparm.  */
4124   else if (is_attribute_p ("stdcall", name))
4125     {
4126       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4127         {
4128           error ("stdcall and cdecl attributes are not compatible");
4129         }
4130       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4131         {
4132           error ("stdcall and fastcall attributes are not compatible");
4133         }
4134     }
4135
4136   /* Can combine cdecl with regparm and sseregparm.  */
4137   else if (is_attribute_p ("cdecl", name))
4138     {
4139       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4140         {
4141           error ("stdcall and cdecl attributes are not compatible");
4142         }
4143       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4144         {
4145           error ("fastcall and cdecl attributes are not compatible");
4146         }
4147     }
4148
4149   /* Can combine sseregparm with all attributes.  */
4150
4151   return NULL_TREE;
4152 }
4153
4154 /* Return 0 if the attributes for two types are incompatible, 1 if they
4155    are compatible, and 2 if they are nearly compatible (which causes a
4156    warning to be generated).  */
4157
4158 static int
4159 ix86_comp_type_attributes (const_tree type1, const_tree type2)
4160 {
4161   /* Check for mismatch of non-default calling convention.  */
4162   const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
4163
4164   if (TREE_CODE (type1) != FUNCTION_TYPE
4165       && TREE_CODE (type1) != METHOD_TYPE)
4166     return 1;
4167
4168   /* Check for mismatched fastcall/regparm types.  */
4169   if ((!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
4170        != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
4171       || (ix86_function_regparm (type1, NULL)
4172           != ix86_function_regparm (type2, NULL)))
4173     return 0;
4174
4175   /* Check for mismatched sseregparm types.  */
4176   if (!lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type1))
4177       != !lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type2)))
4178     return 0;
4179
4180   /* Check for mismatched return types (cdecl vs stdcall).  */
4181   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
4182       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
4183     return 0;
4184
4185   return 1;
4186 }
4187 \f
4188 /* Return the regparm value for a function with the indicated TYPE and DECL.
4189    DECL may be NULL when calling function indirectly
4190    or considering a libcall.  */
4191
4192 static int
4193 ix86_function_regparm (const_tree type, const_tree decl)
4194 {
4195   tree attr;
4196   int regparm = ix86_regparm;
4197
4198   static bool error_issued;
4199
4200   if (TARGET_64BIT)
4201     {
4202       if (ix86_function_type_abi (type) == DEFAULT_ABI)
4203         return regparm;
4204       return DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
4205     }
4206
4207   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
4208   if (attr)
4209     {
4210       regparm
4211         = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
4212
4213       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4214         {
4215           /* We can't use regparm(3) for nested functions because
4216              these pass static chain pointer in %ecx register.  */
4217           if (!error_issued && regparm == 3
4218               && decl_function_context (decl)
4219               && !DECL_NO_STATIC_CHAIN (decl))
4220             {
4221               error ("nested functions are limited to 2 register parameters");
4222               error_issued = true;
4223               return 0;
4224             }
4225         }
4226
4227       return regparm;
4228     }
4229
4230   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4231     return 2;
4232
4233   /* Use register calling convention for local functions when possible.  */
4234   if (decl && TREE_CODE (decl) == FUNCTION_DECL
4235       && !profile_flag)
4236     {
4237       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4238       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4239       if (i && i->local)
4240         {
4241           int local_regparm, globals = 0, regno;
4242           struct function *f;
4243
4244           /* Make sure no regparm register is taken by a
4245              fixed register variable.  */
4246           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4247             if (fixed_regs[local_regparm])
4248               break;
4249
4250           /* We can't use regparm(3) for nested functions as these use
4251              static chain pointer in third argument.  */
4252           if (local_regparm == 3
4253               && decl_function_context (decl)
4254               && !DECL_NO_STATIC_CHAIN (decl))
4255             local_regparm = 2;
4256
4257           /* If the function realigns its stackpointer, the prologue will
4258              clobber %ecx.  If we've already generated code for the callee,
4259              the callee DECL_STRUCT_FUNCTION is gone, so we fall back to
4260              scanning the attributes for the self-realigning property.  */
4261           f = DECL_STRUCT_FUNCTION (decl);
4262           /* Since current internal arg pointer won't conflict with
4263              parameter passing regs, so no need to change stack
4264              realignment and adjust regparm number.
4265
4266              Each fixed register usage increases register pressure,
4267              so less registers should be used for argument passing.
4268              This functionality can be overriden by an explicit
4269              regparm value.  */
4270           for (regno = 0; regno <= DI_REG; regno++)
4271             if (fixed_regs[regno])
4272               globals++;
4273
4274           local_regparm
4275             = globals < local_regparm ? local_regparm - globals : 0;
4276
4277           if (local_regparm > regparm)
4278             regparm = local_regparm;
4279         }
4280     }
4281
4282   return regparm;
4283 }
4284
4285 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
4286    DFmode (2) arguments in SSE registers for a function with the
4287    indicated TYPE and DECL.  DECL may be NULL when calling function
4288    indirectly or considering a libcall.  Otherwise return 0.  */
4289
4290 static int
4291 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
4292 {
4293   gcc_assert (!TARGET_64BIT);
4294
4295   /* Use SSE registers to pass SFmode and DFmode arguments if requested
4296      by the sseregparm attribute.  */
4297   if (TARGET_SSEREGPARM
4298       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
4299     {
4300       if (!TARGET_SSE)
4301         {
4302           if (warn)
4303             {
4304               if (decl)
4305                 error ("Calling %qD with attribute sseregparm without "
4306                        "SSE/SSE2 enabled", decl);
4307               else
4308                 error ("Calling %qT with attribute sseregparm without "
4309                        "SSE/SSE2 enabled", type);
4310             }
4311           return 0;
4312         }
4313
4314       return 2;
4315     }
4316
4317   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4318      (and DFmode for SSE2) arguments in SSE registers.  */
4319   if (decl && TARGET_SSE_MATH && !profile_flag)
4320     {
4321       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4322       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4323       if (i && i->local)
4324         return TARGET_SSE2 ? 2 : 1;
4325     }
4326
4327   return 0;
4328 }
4329
4330 /* Return true if EAX is live at the start of the function.  Used by
4331    ix86_expand_prologue to determine if we need special help before
4332    calling allocate_stack_worker.  */
4333
4334 static bool
4335 ix86_eax_live_at_start_p (void)
4336 {
4337   /* Cheat.  Don't bother working forward from ix86_function_regparm
4338      to the function type to whether an actual argument is located in
4339      eax.  Instead just look at cfg info, which is still close enough
4340      to correct at this point.  This gives false positives for broken
4341      functions that might use uninitialized data that happens to be
4342      allocated in eax, but who cares?  */
4343   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR), 0);
4344 }
4345
4346 /* Value is the number of bytes of arguments automatically
4347    popped when returning from a subroutine call.
4348    FUNDECL is the declaration node of the function (as a tree),
4349    FUNTYPE is the data type of the function (as a tree),
4350    or for a library call it is an identifier node for the subroutine name.
4351    SIZE is the number of bytes of arguments passed on the stack.
4352
4353    On the 80386, the RTD insn may be used to pop them if the number
4354      of args is fixed, but if the number is variable then the caller
4355      must pop them all.  RTD can't be used for library calls now
4356      because the library is compiled with the Unix compiler.
4357    Use of RTD is a selectable option, since it is incompatible with
4358    standard Unix calling sequences.  If the option is not selected,
4359    the caller must always pop the args.
4360
4361    The attribute stdcall is equivalent to RTD on a per module basis.  */
4362
4363 int
4364 ix86_return_pops_args (tree fundecl, tree funtype, int size)
4365 {
4366   int rtd;
4367
4368   /* None of the 64-bit ABIs pop arguments.  */
4369   if (TARGET_64BIT)
4370     return 0;
4371
4372   rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
4373
4374   /* Cdecl functions override -mrtd, and never pop the stack.  */
4375   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
4376     {
4377       /* Stdcall and fastcall functions will pop the stack if not
4378          variable args.  */
4379       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
4380           || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
4381         rtd = 1;
4382
4383       if (rtd && ! stdarg_p (funtype))
4384         return size;
4385     }
4386
4387   /* Lose any fake structure return argument if it is passed on the stack.  */
4388   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
4389       && !KEEP_AGGREGATE_RETURN_POINTER)
4390     {
4391       int nregs = ix86_function_regparm (funtype, fundecl);
4392       if (nregs == 0)
4393         return GET_MODE_SIZE (Pmode);
4394     }
4395
4396   return 0;
4397 }
4398 \f
4399 /* Argument support functions.  */
4400
4401 /* Return true when register may be used to pass function parameters.  */
4402 bool
4403 ix86_function_arg_regno_p (int regno)
4404 {
4405   int i;
4406   const int *parm_regs;
4407
4408   if (!TARGET_64BIT)
4409     {
4410       if (TARGET_MACHO)
4411         return (regno < REGPARM_MAX
4412                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
4413       else
4414         return (regno < REGPARM_MAX
4415                 || (TARGET_MMX && MMX_REGNO_P (regno)
4416                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
4417                 || (TARGET_SSE && SSE_REGNO_P (regno)
4418                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
4419     }
4420
4421   if (TARGET_MACHO)
4422     {
4423       if (SSE_REGNO_P (regno) && TARGET_SSE)
4424         return true;
4425     }
4426   else
4427     {
4428       if (TARGET_SSE && SSE_REGNO_P (regno)
4429           && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
4430         return true;
4431     }
4432
4433   /* TODO: The function should depend on current function ABI but
4434      builtins.c would need updating then. Therefore we use the
4435      default ABI.  */
4436
4437   /* RAX is used as hidden argument to va_arg functions.  */
4438   if (DEFAULT_ABI == SYSV_ABI && regno == AX_REG)
4439     return true;
4440
4441   if (DEFAULT_ABI == MS_ABI)
4442     parm_regs = x86_64_ms_abi_int_parameter_registers;
4443   else
4444     parm_regs = x86_64_int_parameter_registers;
4445   for (i = 0; i < (DEFAULT_ABI == MS_ABI ? X64_REGPARM_MAX
4446                                          : X86_64_REGPARM_MAX); i++)
4447     if (regno == parm_regs[i])
4448       return true;
4449   return false;
4450 }
4451
4452 /* Return if we do not know how to pass TYPE solely in registers.  */
4453
4454 static bool
4455 ix86_must_pass_in_stack (enum machine_mode mode, const_tree type)
4456 {
4457   if (must_pass_in_stack_var_size_or_pad (mode, type))
4458     return true;
4459
4460   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
4461      The layout_type routine is crafty and tries to trick us into passing
4462      currently unsupported vector types on the stack by using TImode.  */
4463   return (!TARGET_64BIT && mode == TImode
4464           && type && TREE_CODE (type) != VECTOR_TYPE);
4465 }
4466
4467 /* It returns the size, in bytes, of the area reserved for arguments passed
4468    in registers for the function represented by fndecl dependent to the used
4469    abi format.  */
4470 int
4471 ix86_reg_parm_stack_space (const_tree fndecl)
4472 {
4473   int call_abi = 0;
4474   /* For libcalls it is possible that there is no fndecl at hand.
4475      Therefore assume for this case the default abi of the target.  */
4476   if (!fndecl)
4477     call_abi = DEFAULT_ABI;
4478   else
4479     call_abi = ix86_function_abi (fndecl);
4480   if (call_abi == 1)
4481     return 32;
4482   return 0;
4483 }
4484
4485 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
4486    call abi used.  */
4487 int
4488 ix86_function_type_abi (const_tree fntype)
4489 {
4490   if (TARGET_64BIT && fntype != NULL)
4491     {
4492       int abi;
4493       if (DEFAULT_ABI == SYSV_ABI)
4494         abi = lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)) ? MS_ABI : SYSV_ABI;
4495       else
4496         abi = lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)) ? SYSV_ABI : MS_ABI;
4497
4498       return abi;
4499     }
4500   return DEFAULT_ABI;
4501 }
4502
4503 int
4504 ix86_function_abi (const_tree fndecl)
4505 {
4506   if (! fndecl)
4507     return DEFAULT_ABI;
4508   return ix86_function_type_abi (TREE_TYPE (fndecl));
4509 }
4510
4511 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
4512    call abi used.  */
4513 int
4514 ix86_cfun_abi (void)
4515 {
4516   if (! cfun || ! TARGET_64BIT)
4517     return DEFAULT_ABI;
4518   return cfun->machine->call_abi;
4519 }
4520
4521 /* regclass.c  */
4522 extern void init_regs (void);
4523
4524 /* Implementation of call abi switching target hook. Specific to FNDECL
4525    the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
4526    for more details.
4527    To prevent redudant calls of costy function init_regs (), it checks not to
4528    reset register usage for default abi.  */
4529 void
4530 ix86_call_abi_override (const_tree fndecl)
4531 {
4532   if (fndecl == NULL_TREE)
4533     cfun->machine->call_abi = DEFAULT_ABI;
4534   else
4535     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
4536   if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
4537     {
4538       if (call_used_regs[4 /*RSI*/] != 0 || call_used_regs[5 /*RDI*/] != 0)
4539         {
4540           call_used_regs[4 /*RSI*/] = 0;
4541           call_used_regs[5 /*RDI*/] = 0;
4542           init_regs ();
4543         }
4544     }
4545   else if (TARGET_64BIT)
4546     {
4547       if (call_used_regs[4 /*RSI*/] != 1 || call_used_regs[5 /*RDI*/] != 1)
4548         {
4549           call_used_regs[4 /*RSI*/] = 1;
4550           call_used_regs[5 /*RDI*/] = 1;
4551           init_regs ();
4552         }
4553     }
4554 }
4555
4556 /* Initialize a variable CUM of type CUMULATIVE_ARGS
4557    for a call to a function whose data type is FNTYPE.
4558    For a library call, FNTYPE is 0.  */
4559
4560 void
4561 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
4562                       tree fntype,      /* tree ptr for function decl */
4563                       rtx libname,      /* SYMBOL_REF of library name or 0 */
4564                       tree fndecl)
4565 {
4566   struct cgraph_local_info *i = fndecl ? cgraph_local_info (fndecl) : NULL;
4567   memset (cum, 0, sizeof (*cum));
4568
4569   cum->call_abi = ix86_function_type_abi (fntype);
4570   /* Set up the number of registers to use for passing arguments.  */
4571   cum->nregs = ix86_regparm;
4572   if (TARGET_64BIT)
4573     {
4574       if (cum->call_abi != DEFAULT_ABI)
4575         cum->nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX
4576                                              : X64_REGPARM_MAX;
4577     }
4578   if (TARGET_SSE)
4579     {
4580       cum->sse_nregs = SSE_REGPARM_MAX;
4581       if (TARGET_64BIT)
4582         {
4583           if (cum->call_abi != DEFAULT_ABI)
4584             cum->sse_nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
4585                                                      : X64_SSE_REGPARM_MAX;
4586         }
4587     }
4588   if (TARGET_MMX)
4589     cum->mmx_nregs = MMX_REGPARM_MAX;
4590   cum->warn_sse = true;
4591   cum->warn_mmx = true;
4592
4593   /* Because type might mismatch in between caller and callee, we need to
4594      use actual type of function for local calls.
4595      FIXME: cgraph_analyze can be told to actually record if function uses
4596      va_start so for local functions maybe_vaarg can be made aggressive
4597      helping K&R code.
4598      FIXME: once typesytem is fixed, we won't need this code anymore.  */
4599   if (i && i->local)
4600     fntype = TREE_TYPE (fndecl);
4601   cum->maybe_vaarg = (fntype
4602                       ? (!prototype_p (fntype) || stdarg_p (fntype))
4603                       : !libname);
4604
4605   if (!TARGET_64BIT)
4606     {
4607       /* If there are variable arguments, then we won't pass anything
4608          in registers in 32-bit mode. */
4609       if (stdarg_p (fntype))
4610         {
4611           cum->nregs = 0;
4612           cum->sse_nregs = 0;
4613           cum->mmx_nregs = 0;
4614           cum->warn_sse = 0;
4615           cum->warn_mmx = 0;
4616           return;
4617         }
4618
4619       /* Use ecx and edx registers if function has fastcall attribute,
4620          else look for regparm information.  */
4621       if (fntype)
4622         {
4623           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
4624             {
4625               cum->nregs = 2;
4626               cum->fastcall = 1;
4627             }
4628           else
4629             cum->nregs = ix86_function_regparm (fntype, fndecl);
4630         }
4631
4632       /* Set up the number of SSE registers used for passing SFmode
4633          and DFmode arguments.  Warn for mismatching ABI.  */
4634       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
4635     }
4636 }
4637
4638 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
4639    But in the case of vector types, it is some vector mode.
4640
4641    When we have only some of our vector isa extensions enabled, then there
4642    are some modes for which vector_mode_supported_p is false.  For these
4643    modes, the generic vector support in gcc will choose some non-vector mode
4644    in order to implement the type.  By computing the natural mode, we'll
4645    select the proper ABI location for the operand and not depend on whatever
4646    the middle-end decides to do with these vector types.  */
4647
4648 static enum machine_mode
4649 type_natural_mode (const_tree type)
4650 {
4651   enum machine_mode mode = TYPE_MODE (type);
4652
4653   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
4654     {
4655       HOST_WIDE_INT size = int_size_in_bytes (type);
4656       if ((size == 8 || size == 16)
4657           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
4658           && TYPE_VECTOR_SUBPARTS (type) > 1)
4659         {
4660           enum machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
4661
4662           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4663             mode = MIN_MODE_VECTOR_FLOAT;
4664           else
4665             mode = MIN_MODE_VECTOR_INT;
4666
4667           /* Get the mode which has this inner mode and number of units.  */
4668           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
4669             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
4670                 && GET_MODE_INNER (mode) == innermode)
4671               return mode;
4672
4673           gcc_unreachable ();
4674         }
4675     }
4676
4677   return mode;
4678 }
4679
4680 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
4681    this may not agree with the mode that the type system has chosen for the
4682    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
4683    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
4684
4685 static rtx
4686 gen_reg_or_parallel (enum machine_mode mode, enum machine_mode orig_mode,
4687                      unsigned int regno)
4688 {
4689   rtx tmp;
4690
4691   if (orig_mode != BLKmode)
4692     tmp = gen_rtx_REG (orig_mode, regno);
4693   else
4694     {
4695       tmp = gen_rtx_REG (mode, regno);
4696       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
4697       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
4698     }
4699
4700   return tmp;
4701 }
4702
4703 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
4704    of this code is to classify each 8bytes of incoming argument by the register
4705    class and assign registers accordingly.  */
4706
4707 /* Return the union class of CLASS1 and CLASS2.
4708    See the x86-64 PS ABI for details.  */
4709
4710 static enum x86_64_reg_class
4711 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
4712 {
4713   /* Rule #1: If both classes are equal, this is the resulting class.  */
4714   if (class1 == class2)
4715     return class1;
4716
4717   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
4718      the other class.  */
4719   if (class1 == X86_64_NO_CLASS)
4720     return class2;
4721   if (class2 == X86_64_NO_CLASS)
4722     return class1;
4723
4724   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
4725   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
4726     return X86_64_MEMORY_CLASS;
4727
4728   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
4729   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
4730       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
4731     return X86_64_INTEGERSI_CLASS;
4732   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
4733       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
4734     return X86_64_INTEGER_CLASS;
4735
4736   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
4737      MEMORY is used.  */
4738   if (class1 == X86_64_X87_CLASS
4739       || class1 == X86_64_X87UP_CLASS
4740       || class1 == X86_64_COMPLEX_X87_CLASS
4741       || class2 == X86_64_X87_CLASS
4742       || class2 == X86_64_X87UP_CLASS
4743       || class2 == X86_64_COMPLEX_X87_CLASS)
4744     return X86_64_MEMORY_CLASS;
4745
4746   /* Rule #6: Otherwise class SSE is used.  */
4747   return X86_64_SSE_CLASS;
4748 }
4749
4750 /* Classify the argument of type TYPE and mode MODE.
4751    CLASSES will be filled by the register class used to pass each word
4752    of the operand.  The number of words is returned.  In case the parameter
4753    should be passed in memory, 0 is returned. As a special case for zero
4754    sized containers, classes[0] will be NO_CLASS and 1 is returned.
4755
4756    BIT_OFFSET is used internally for handling records and specifies offset
4757    of the offset in bits modulo 256 to avoid overflow cases.
4758
4759    See the x86-64 PS ABI for details.
4760 */
4761
4762 static int
4763 classify_argument (enum machine_mode mode, const_tree type,
4764                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
4765 {
4766   HOST_WIDE_INT bytes =
4767     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
4768   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4769
4770   /* Variable sized entities are always passed/returned in memory.  */
4771   if (bytes < 0)
4772     return 0;
4773
4774   if (mode != VOIDmode
4775       && targetm.calls.must_pass_in_stack (mode, type))
4776     return 0;
4777
4778   if (type && AGGREGATE_TYPE_P (type))
4779     {
4780       int i;
4781       tree field;
4782       enum x86_64_reg_class subclasses[MAX_CLASSES];
4783
4784       /* On x86-64 we pass structures larger than 16 bytes on the stack.  */
4785       if (bytes > 16)
4786         return 0;
4787
4788       for (i = 0; i < words; i++)
4789         classes[i] = X86_64_NO_CLASS;
4790
4791       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
4792          signalize memory class, so handle it as special case.  */
4793       if (!words)
4794         {
4795           classes[0] = X86_64_NO_CLASS;
4796           return 1;
4797         }
4798
4799       /* Classify each field of record and merge classes.  */
4800       switch (TREE_CODE (type))
4801         {
4802         case RECORD_TYPE:
4803           /* And now merge the fields of structure.  */
4804           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4805             {
4806               if (TREE_CODE (field) == FIELD_DECL)
4807                 {
4808                   int num;
4809
4810                   if (TREE_TYPE (field) == error_mark_node)
4811                     continue;
4812
4813                   /* Bitfields are always classified as integer.  Handle them
4814                      early, since later code would consider them to be
4815                      misaligned integers.  */
4816                   if (DECL_BIT_FIELD (field))
4817                     {
4818                       for (i = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4819                            i < ((int_bit_position (field) + (bit_offset % 64))
4820                                 + tree_low_cst (DECL_SIZE (field), 0)
4821                                 + 63) / 8 / 8; i++)
4822                         classes[i] =
4823                           merge_classes (X86_64_INTEGER_CLASS,
4824                                          classes[i]);
4825                     }
4826                   else
4827                     {
4828                       num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4829                                                TREE_TYPE (field), subclasses,
4830                                                (int_bit_position (field)
4831                                                 + bit_offset) % 256);
4832                       if (!num)
4833                         return 0;
4834                       for (i = 0; i < num; i++)
4835                         {
4836                           int pos =
4837                             (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4838                           classes[i + pos] =
4839                             merge_classes (subclasses[i], classes[i + pos]);
4840                         }
4841                     }
4842                 }
4843             }
4844           break;
4845
4846         case ARRAY_TYPE:
4847           /* Arrays are handled as small records.  */
4848           {
4849             int num;
4850             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
4851                                      TREE_TYPE (type), subclasses, bit_offset);
4852             if (!num)
4853               return 0;
4854
4855             /* The partial classes are now full classes.  */
4856             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
4857               subclasses[0] = X86_64_SSE_CLASS;
4858             if (subclasses[0] == X86_64_INTEGERSI_CLASS && bytes != 4)
4859               subclasses[0] = X86_64_INTEGER_CLASS;
4860
4861             for (i = 0; i < words; i++)
4862               classes[i] = subclasses[i % num];
4863
4864             break;
4865           }
4866         case UNION_TYPE:
4867         case QUAL_UNION_TYPE:
4868           /* Unions are similar to RECORD_TYPE but offset is always 0.
4869              */
4870           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4871             {
4872               if (TREE_CODE (field) == FIELD_DECL)
4873                 {
4874                   int num;
4875
4876                   if (TREE_TYPE (field) == error_mark_node)
4877                     continue;
4878
4879                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4880                                            TREE_TYPE (field), subclasses,
4881                                            bit_offset);
4882                   if (!num)
4883                     return 0;
4884                   for (i = 0; i < num; i++)
4885                     classes[i] = merge_classes (subclasses[i], classes[i]);
4886                 }
4887             }
4888           break;
4889
4890         default:
4891           gcc_unreachable ();
4892         }
4893
4894       /* Final merger cleanup.  */
4895       for (i = 0; i < words; i++)
4896         {
4897           /* If one class is MEMORY, everything should be passed in
4898              memory.  */
4899           if (classes[i] == X86_64_MEMORY_CLASS)
4900             return 0;
4901
4902           /* The X86_64_SSEUP_CLASS should be always preceded by
4903              X86_64_SSE_CLASS.  */
4904           if (classes[i] == X86_64_SSEUP_CLASS
4905               && (i == 0 || classes[i - 1] != X86_64_SSE_CLASS))
4906             classes[i] = X86_64_SSE_CLASS;
4907
4908           /*  X86_64_X87UP_CLASS should be preceded by X86_64_X87_CLASS.  */
4909           if (classes[i] == X86_64_X87UP_CLASS
4910               && (i == 0 || classes[i - 1] != X86_64_X87_CLASS))
4911             classes[i] = X86_64_SSE_CLASS;
4912         }
4913       return words;
4914     }
4915
4916   /* Compute alignment needed.  We align all types to natural boundaries with
4917      exception of XFmode that is aligned to 64bits.  */
4918   if (mode != VOIDmode && mode != BLKmode)
4919     {
4920       int mode_alignment = GET_MODE_BITSIZE (mode);
4921
4922       if (mode == XFmode)
4923         mode_alignment = 128;
4924       else if (mode == XCmode)
4925         mode_alignment = 256;
4926       if (COMPLEX_MODE_P (mode))
4927         mode_alignment /= 2;
4928       /* Misaligned fields are always returned in memory.  */
4929       if (bit_offset % mode_alignment)
4930         return 0;
4931     }
4932
4933   /* for V1xx modes, just use the base mode */
4934   if (VECTOR_MODE_P (mode) && mode != V1DImode
4935       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
4936     mode = GET_MODE_INNER (mode);
4937
4938   /* Classification of atomic types.  */
4939   switch (mode)
4940     {
4941     case SDmode:
4942     case DDmode:
4943       classes[0] = X86_64_SSE_CLASS;
4944       return 1;
4945     case TDmode:
4946       classes[0] = X86_64_SSE_CLASS;
4947       classes[1] = X86_64_SSEUP_CLASS;
4948       return 2;
4949     case DImode:
4950     case SImode:
4951     case HImode:
4952     case QImode:
4953     case CSImode:
4954     case CHImode:
4955     case CQImode:
4956       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
4957         classes[0] = X86_64_INTEGERSI_CLASS;
4958       else
4959         classes[0] = X86_64_INTEGER_CLASS;
4960       return 1;
4961     case CDImode:
4962     case TImode:
4963       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
4964       return 2;
4965     case CTImode:
4966       return 0;
4967     case SFmode:
4968       if (!(bit_offset % 64))
4969         classes[0] = X86_64_SSESF_CLASS;
4970       else
4971         classes[0] = X86_64_SSE_CLASS;
4972       return 1;
4973     case DFmode:
4974       classes[0] = X86_64_SSEDF_CLASS;
4975       return 1;
4976     case XFmode:
4977       classes[0] = X86_64_X87_CLASS;
4978       classes[1] = X86_64_X87UP_CLASS;
4979       return 2;
4980     case TFmode:
4981       classes[0] = X86_64_SSE_CLASS;
4982       classes[1] = X86_64_SSEUP_CLASS;
4983       return 2;
4984     case SCmode:
4985       classes[0] = X86_64_SSE_CLASS;
4986       return 1;
4987     case DCmode:
4988       classes[0] = X86_64_SSEDF_CLASS;
4989       classes[1] = X86_64_SSEDF_CLASS;
4990       return 2;
4991     case XCmode:
4992       classes[0] = X86_64_COMPLEX_X87_CLASS;
4993       return 1;
4994     case TCmode:
4995       /* This modes is larger than 16 bytes.  */
4996       return 0;
4997     case V4SFmode:
4998     case V4SImode:
4999     case V16QImode:
5000     case V8HImode:
5001     case V2DFmode:
5002     case V2DImode:
5003       classes[0] = X86_64_SSE_CLASS;
5004       classes[1] = X86_64_SSEUP_CLASS;
5005       return 2;
5006     case V1DImode:
5007     case V2SFmode:
5008     case V2SImode:
5009     case V4HImode:
5010     case V8QImode:
5011       classes[0] = X86_64_SSE_CLASS;
5012       return 1;
5013     case BLKmode:
5014     case VOIDmode:
5015       return 0;
5016     default:
5017       gcc_assert (VECTOR_MODE_P (mode));
5018
5019       if (bytes > 16)
5020         return 0;
5021
5022       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
5023
5024       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5025         classes[0] = X86_64_INTEGERSI_CLASS;
5026       else
5027         classes[0] = X86_64_INTEGER_CLASS;
5028       classes[1] = X86_64_INTEGER_CLASS;
5029       return 1 + (bytes > 8);
5030     }
5031 }
5032
5033 /* Examine the argument and return set number of register required in each
5034    class.  Return 0 iff parameter should be passed in memory.  */
5035 static int
5036 examine_argument (enum machine_mode mode, const_tree type, int in_return,
5037                   int *int_nregs, int *sse_nregs)
5038 {
5039   enum x86_64_reg_class regclass[MAX_CLASSES];
5040   int n = classify_argument (mode, type, regclass, 0);
5041
5042   *int_nregs = 0;
5043   *sse_nregs = 0;
5044   if (!n)
5045     return 0;
5046   for (n--; n >= 0; n--)
5047     switch (regclass[n])
5048       {
5049       case X86_64_INTEGER_CLASS:
5050       case X86_64_INTEGERSI_CLASS:
5051         (*int_nregs)++;
5052         break;
5053       case X86_64_SSE_CLASS:
5054       case X86_64_SSESF_CLASS:
5055       case X86_64_SSEDF_CLASS:
5056         (*sse_nregs)++;
5057         break;
5058       case X86_64_NO_CLASS:
5059       case X86_64_SSEUP_CLASS:
5060         break;
5061       case X86_64_X87_CLASS:
5062       case X86_64_X87UP_CLASS:
5063         if (!in_return)
5064           return 0;
5065         break;
5066       case X86_64_COMPLEX_X87_CLASS:
5067         return in_return ? 2 : 0;
5068       case X86_64_MEMORY_CLASS:
5069         gcc_unreachable ();
5070       }
5071   return 1;
5072 }
5073
5074 /* Construct container for the argument used by GCC interface.  See
5075    FUNCTION_ARG for the detailed description.  */
5076
5077 static rtx
5078 construct_container (enum machine_mode mode, enum machine_mode orig_mode,
5079                      const_tree type, int in_return, int nintregs, int nsseregs,
5080                      const int *intreg, int sse_regno)
5081 {
5082   /* The following variables hold the static issued_error state.  */
5083   static bool issued_sse_arg_error;
5084   static bool issued_sse_ret_error;
5085   static bool issued_x87_ret_error;
5086
5087   enum machine_mode tmpmode;
5088   int bytes =
5089     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
5090   enum x86_64_reg_class regclass[MAX_CLASSES];
5091   int n;
5092   int i;
5093   int nexps = 0;
5094   int needed_sseregs, needed_intregs;
5095   rtx exp[MAX_CLASSES];
5096   rtx ret;
5097
5098   n = classify_argument (mode, type, regclass, 0);
5099   if (!n)
5100     return NULL;
5101   if (!examine_argument (mode, type, in_return, &needed_intregs,
5102                          &needed_sseregs))
5103     return NULL;
5104   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
5105     return NULL;
5106
5107   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
5108      some less clueful developer tries to use floating-point anyway.  */
5109   if (needed_sseregs && !TARGET_SSE)
5110     {
5111       if (in_return)
5112         {
5113           if (!issued_sse_ret_error)
5114             {
5115               error ("SSE register return with SSE disabled");
5116               issued_sse_ret_error = true;
5117             }
5118         }
5119       else if (!issued_sse_arg_error)
5120         {
5121           error ("SSE register argument with SSE disabled");
5122           issued_sse_arg_error = true;
5123         }
5124       return NULL;
5125     }
5126
5127   /* Likewise, error if the ABI requires us to return values in the
5128      x87 registers and the user specified -mno-80387.  */
5129   if (!TARGET_80387 && in_return)
5130     for (i = 0; i < n; i++)
5131       if (regclass[i] == X86_64_X87_CLASS
5132           || regclass[i] == X86_64_X87UP_CLASS
5133           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
5134         {
5135           if (!issued_x87_ret_error)
5136             {
5137               error ("x87 register return with x87 disabled");
5138               issued_x87_ret_error = true;
5139             }
5140           return NULL;
5141         }
5142
5143   /* First construct simple cases.  Avoid SCmode, since we want to use
5144      single register to pass this type.  */
5145   if (n == 1 && mode != SCmode)
5146     switch (regclass[0])
5147       {
5148       case X86_64_INTEGER_CLASS:
5149       case X86_64_INTEGERSI_CLASS:
5150         return gen_rtx_REG (mode, intreg[0]);
5151       case X86_64_SSE_CLASS:
5152       case X86_64_SSESF_CLASS:
5153       case X86_64_SSEDF_CLASS:
5154         return gen_reg_or_parallel (mode, orig_mode, SSE_REGNO (sse_regno));
5155       case X86_64_X87_CLASS:
5156       case X86_64_COMPLEX_X87_CLASS:
5157         return gen_rtx_REG (mode, FIRST_STACK_REG);
5158       case X86_64_NO_CLASS:
5159         /* Zero sized array, struct or class.  */
5160         return NULL;
5161       default:
5162         gcc_unreachable ();
5163       }
5164   if (n == 2 && regclass[0] == X86_64_SSE_CLASS
5165       && regclass[1] == X86_64_SSEUP_CLASS && mode != BLKmode)
5166     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5167
5168   if (n == 2
5169       && regclass[0] == X86_64_X87_CLASS && regclass[1] == X86_64_X87UP_CLASS)
5170     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
5171   if (n == 2 && regclass[0] == X86_64_INTEGER_CLASS
5172       && regclass[1] == X86_64_INTEGER_CLASS
5173       && (mode == CDImode || mode == TImode || mode == TFmode)
5174       && intreg[0] + 1 == intreg[1])
5175     return gen_rtx_REG (mode, intreg[0]);
5176
5177   /* Otherwise figure out the entries of the PARALLEL.  */
5178   for (i = 0; i < n; i++)
5179     {
5180       switch (regclass[i])
5181         {
5182           case X86_64_NO_CLASS:
5183             break;
5184           case X86_64_INTEGER_CLASS:
5185           case X86_64_INTEGERSI_CLASS:
5186             /* Merge TImodes on aligned occasions here too.  */
5187             if (i * 8 + 8 > bytes)
5188               tmpmode = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
5189             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
5190               tmpmode = SImode;
5191             else
5192               tmpmode = DImode;
5193             /* We've requested 24 bytes we don't have mode for.  Use DImode.  */
5194             if (tmpmode == BLKmode)
5195               tmpmode = DImode;
5196             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5197                                                gen_rtx_REG (tmpmode, *intreg),
5198                                                GEN_INT (i*8));
5199             intreg++;
5200             break;
5201           case X86_64_SSESF_CLASS:
5202             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5203                                                gen_rtx_REG (SFmode,
5204                                                             SSE_REGNO (sse_regno)),
5205                                                GEN_INT (i*8));
5206             sse_regno++;
5207             break;
5208           case X86_64_SSEDF_CLASS:
5209             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5210                                                gen_rtx_REG (DFmode,
5211                                                             SSE_REGNO (sse_regno)),
5212                                                GEN_INT (i*8));
5213             sse_regno++;
5214             break;
5215           case X86_64_SSE_CLASS:
5216             if (i < n - 1 && regclass[i + 1] == X86_64_SSEUP_CLASS)
5217               tmpmode = TImode;
5218             else
5219               tmpmode = DImode;
5220             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5221                                                gen_rtx_REG (tmpmode,
5222                                                             SSE_REGNO (sse_regno)),
5223                                                GEN_INT (i*8));
5224             if (tmpmode == TImode)
5225               i++;
5226             sse_regno++;
5227             break;
5228           default:
5229             gcc_unreachable ();
5230         }
5231     }
5232
5233   /* Empty aligned struct, union or class.  */
5234   if (nexps == 0)
5235     return NULL;
5236
5237   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
5238   for (i = 0; i < nexps; i++)
5239     XVECEXP (ret, 0, i) = exp [i];
5240   return ret;
5241 }
5242
5243 /* Update the data in CUM to advance over an argument of mode MODE
5244    and data type TYPE.  (TYPE is null for libcalls where that information
5245    may not be available.)  */
5246
5247 static void
5248 function_arg_advance_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5249                          tree type, HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5250 {
5251   switch (mode)
5252     {
5253     default:
5254       break;
5255
5256     case BLKmode:
5257       if (bytes < 0)
5258         break;
5259       /* FALLTHRU */
5260
5261     case DImode:
5262     case SImode:
5263     case HImode:
5264     case QImode:
5265       cum->words += words;
5266       cum->nregs -= words;
5267       cum->regno += words;
5268
5269       if (cum->nregs <= 0)
5270         {
5271           cum->nregs = 0;
5272           cum->regno = 0;
5273         }
5274       break;
5275
5276     case DFmode:
5277       if (cum->float_in_sse < 2)
5278         break;
5279     case SFmode:
5280       if (cum->float_in_sse < 1)
5281         break;
5282       /* FALLTHRU */
5283
5284     case TImode:
5285     case V16QImode:
5286     case V8HImode:
5287     case V4SImode:
5288     case V2DImode:
5289     case V4SFmode:
5290     case V2DFmode:
5291       if (!type || !AGGREGATE_TYPE_P (type))
5292         {
5293           cum->sse_words += words;
5294           cum->sse_nregs -= 1;
5295           cum->sse_regno += 1;
5296           if (cum->sse_nregs <= 0)
5297             {
5298               cum->sse_nregs = 0;
5299               cum->sse_regno = 0;
5300             }
5301         }
5302       break;
5303
5304     case V8QImode:
5305     case V4HImode:
5306     case V2SImode:
5307     case V2SFmode:
5308     case V1DImode:
5309       if (!type || !AGGREGATE_TYPE_P (type))
5310         {
5311           cum->mmx_words += words;
5312           cum->mmx_nregs -= 1;
5313           cum->mmx_regno += 1;
5314           if (cum->mmx_nregs <= 0)
5315             {
5316               cum->mmx_nregs = 0;
5317               cum->mmx_regno = 0;
5318             }
5319         }
5320       break;
5321     }
5322 }
5323
5324 static void
5325 function_arg_advance_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5326                          tree type, HOST_WIDE_INT words)
5327 {
5328   int int_nregs, sse_nregs;
5329
5330   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs))
5331     cum->words += words;
5332   else if (sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
5333     {
5334       cum->nregs -= int_nregs;
5335       cum->sse_nregs -= sse_nregs;
5336       cum->regno += int_nregs;
5337       cum->sse_regno += sse_nregs;
5338     }
5339   else
5340     cum->words += words;
5341 }
5342
5343 static void
5344 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
5345                             HOST_WIDE_INT words)
5346 {
5347   /* Otherwise, this should be passed indirect.  */
5348   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
5349
5350   cum->words += words;
5351   if (cum->nregs > 0)
5352     {
5353       cum->nregs -= 1;
5354       cum->regno += 1;
5355     }
5356 }
5357
5358 void
5359 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5360                       tree type, int named ATTRIBUTE_UNUSED)
5361 {
5362   HOST_WIDE_INT bytes, words;
5363
5364   if (mode == BLKmode)
5365     bytes = int_size_in_bytes (type);
5366   else
5367     bytes = GET_MODE_SIZE (mode);
5368   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5369
5370   if (type)
5371     mode = type_natural_mode (type);
5372
5373   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5374     function_arg_advance_ms_64 (cum, bytes, words);
5375   else if (TARGET_64BIT)
5376     function_arg_advance_64 (cum, mode, type, words);
5377   else
5378     function_arg_advance_32 (cum, mode, type, bytes, words);
5379 }
5380
5381 /* Define where to put the arguments to a function.
5382    Value is zero to push the argument on the stack,
5383    or a hard register in which to store the argument.
5384
5385    MODE is the argument's machine mode.
5386    TYPE is the data type of the argument (as a tree).
5387     This is null for libcalls where that information may
5388     not be available.
5389    CUM is a variable of type CUMULATIVE_ARGS which gives info about
5390     the preceding args and about the function being called.
5391    NAMED is nonzero if this argument is a named parameter
5392     (otherwise it is an extra parameter matching an ellipsis).  */
5393
5394 static rtx
5395 function_arg_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5396                  enum machine_mode orig_mode, tree type,
5397                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5398 {
5399   static bool warnedsse, warnedmmx;
5400
5401   /* Avoid the AL settings for the Unix64 ABI.  */
5402   if (mode == VOIDmode)
5403     return constm1_rtx;
5404
5405   switch (mode)
5406     {
5407     default:
5408       break;
5409
5410     case BLKmode:
5411       if (bytes < 0)
5412         break;
5413       /* FALLTHRU */
5414     case DImode:
5415     case SImode:
5416     case HImode:
5417     case QImode:
5418       if (words <= cum->nregs)
5419         {
5420           int regno = cum->regno;
5421
5422           /* Fastcall allocates the first two DWORD (SImode) or
5423             smaller arguments to ECX and EDX if it isn't an
5424             aggregate type .  */
5425           if (cum->fastcall)
5426             {
5427               if (mode == BLKmode
5428                   || mode == DImode
5429                   || (type && AGGREGATE_TYPE_P (type)))
5430                 break;
5431
5432               /* ECX not EAX is the first allocated register.  */
5433               if (regno == AX_REG)
5434                 regno = CX_REG;
5435             }
5436           return gen_rtx_REG (mode, regno);
5437         }
5438       break;
5439
5440     case DFmode:
5441       if (cum->float_in_sse < 2)
5442         break;
5443     case SFmode:
5444       if (cum->float_in_sse < 1)
5445         break;
5446       /* FALLTHRU */
5447     case TImode:
5448     case V16QImode:
5449     case V8HImode:
5450     case V4SImode:
5451     case V2DImode:
5452     case V4SFmode:
5453     case V2DFmode:
5454       if (!type || !AGGREGATE_TYPE_P (type))
5455         {
5456           if (!TARGET_SSE && !warnedsse && cum->warn_sse)
5457             {
5458               warnedsse = true;
5459               warning (0, "SSE vector argument without SSE enabled "
5460                        "changes the ABI");
5461             }
5462           if (cum->sse_nregs)
5463             return gen_reg_or_parallel (mode, orig_mode,
5464                                         cum->sse_regno + FIRST_SSE_REG);
5465         }
5466       break;
5467
5468     case V8QImode:
5469     case V4HImode:
5470     case V2SImode:
5471     case V2SFmode:
5472     case V1DImode:
5473       if (!type || !AGGREGATE_TYPE_P (type))
5474         {
5475           if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
5476             {
5477               warnedmmx = true;
5478               warning (0, "MMX vector argument without MMX enabled "
5479                        "changes the ABI");
5480             }
5481           if (cum->mmx_nregs)
5482             return gen_reg_or_parallel (mode, orig_mode,
5483                                         cum->mmx_regno + FIRST_MMX_REG);
5484         }
5485       break;
5486     }
5487
5488   return NULL_RTX;
5489 }
5490
5491 static rtx
5492 function_arg_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5493                  enum machine_mode orig_mode, tree type)
5494 {
5495   /* Handle a hidden AL argument containing number of registers
5496      for varargs x86-64 functions.  */
5497   if (mode == VOIDmode)
5498     return GEN_INT (cum->maybe_vaarg
5499                     ? (cum->sse_nregs < 0
5500                        ? (cum->call_abi == DEFAULT_ABI
5501                           ? SSE_REGPARM_MAX
5502                           : (DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
5503                                                      : X64_SSE_REGPARM_MAX))
5504                : cum->sse_regno)
5505                     : -1);
5506
5507   return construct_container (mode, orig_mode, type, 0, cum->nregs,
5508                               cum->sse_nregs,
5509                               &x86_64_int_parameter_registers [cum->regno],
5510                               cum->sse_regno);
5511 }
5512
5513 static rtx
5514 function_arg_ms_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5515                     enum machine_mode orig_mode, int named,
5516                     HOST_WIDE_INT bytes)
5517 {
5518   unsigned int regno;
5519
5520   /* Avoid the AL settings for the Unix64 ABI.  */
5521   if (mode == VOIDmode)
5522     return constm1_rtx;
5523
5524   /* If we've run out of registers, it goes on the stack.  */
5525   if (cum->nregs == 0)
5526     return NULL_RTX;
5527
5528   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
5529
5530   /* Only floating point modes are passed in anything but integer regs.  */
5531   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
5532     {
5533       if (named)
5534         regno = cum->regno + FIRST_SSE_REG;
5535       else
5536         {
5537           rtx t1, t2;
5538
5539           /* Unnamed floating parameters are passed in both the
5540              SSE and integer registers.  */
5541           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
5542           t2 = gen_rtx_REG (mode, regno);
5543           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
5544           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
5545           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
5546         }
5547     }
5548   /* Handle aggregated types passed in register.  */
5549   if (orig_mode == BLKmode)
5550     {
5551       if (bytes > 0 && bytes <= 8)
5552         mode = (bytes > 4 ? DImode : SImode);
5553       if (mode == BLKmode)
5554         mode = DImode;
5555     }
5556
5557   return gen_reg_or_parallel (mode, orig_mode, regno);
5558 }
5559
5560 rtx
5561 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
5562               tree type, int named)
5563 {
5564   enum machine_mode mode = omode;
5565   HOST_WIDE_INT bytes, words;
5566
5567   if (mode == BLKmode)
5568     bytes = int_size_in_bytes (type);
5569   else
5570     bytes = GET_MODE_SIZE (mode);
5571   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5572
5573   /* To simplify the code below, represent vector types with a vector mode
5574      even if MMX/SSE are not active.  */
5575   if (type && TREE_CODE (type) == VECTOR_TYPE)
5576     mode = type_natural_mode (type);
5577
5578   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5579     return function_arg_ms_64 (cum, mode, omode, named, bytes);
5580   else if (TARGET_64BIT)
5581     return function_arg_64 (cum, mode, omode, type);
5582   else
5583     return function_arg_32 (cum, mode, omode, type, bytes, words);
5584 }
5585
5586 /* A C expression that indicates when an argument must be passed by
5587    reference.  If nonzero for an argument, a copy of that argument is
5588    made in memory and a pointer to the argument is passed instead of
5589    the argument itself.  The pointer is passed in whatever way is
5590    appropriate for passing a pointer to that type.  */
5591
5592 static bool
5593 ix86_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5594                         enum machine_mode mode ATTRIBUTE_UNUSED,
5595                         const_tree type, bool named ATTRIBUTE_UNUSED)
5596 {
5597   /* See Windows x64 Software Convention.  */
5598   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5599     {
5600       int msize = (int) GET_MODE_SIZE (mode);
5601       if (type)
5602         {
5603           /* Arrays are passed by reference.  */
5604           if (TREE_CODE (type) == ARRAY_TYPE)
5605             return true;
5606
5607           if (AGGREGATE_TYPE_P (type))
5608             {
5609               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
5610                  are passed by reference.  */
5611               msize = int_size_in_bytes (type);
5612             }
5613         }
5614
5615       /* __m128 is passed by reference.  */
5616       switch (msize) {
5617       case 1: case 2: case 4: case 8:
5618         break;
5619       default:
5620         return true;
5621       }
5622     }
5623   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
5624     return 1;
5625
5626   return 0;
5627 }
5628
5629 /* Return true when TYPE should be 128bit aligned for 32bit argument passing
5630    ABI.  */
5631 static bool
5632 contains_aligned_value_p (tree type)
5633 {
5634   enum machine_mode mode = TYPE_MODE (type);
5635   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
5636        || mode == TDmode
5637        || mode == TFmode
5638        || mode == TCmode)
5639       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
5640     return true;
5641   if (TYPE_ALIGN (type) < 128)
5642     return false;
5643
5644   if (AGGREGATE_TYPE_P (type))
5645     {
5646       /* Walk the aggregates recursively.  */
5647       switch (TREE_CODE (type))
5648         {
5649         case RECORD_TYPE:
5650         case UNION_TYPE:
5651         case QUAL_UNION_TYPE:
5652           {
5653             tree field;
5654
5655             /* Walk all the structure fields.  */
5656             for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5657               {
5658                 if (TREE_CODE (field) == FIELD_DECL
5659                     && contains_aligned_value_p (TREE_TYPE (field)))
5660                   return true;
5661               }
5662             break;
5663           }
5664
5665         case ARRAY_TYPE:
5666           /* Just for use if some languages passes arrays by value.  */
5667           if (contains_aligned_value_p (TREE_TYPE (type)))
5668             return true;
5669           break;
5670
5671         default:
5672           gcc_unreachable ();
5673         }
5674     }
5675   return false;
5676 }
5677
5678 /* Gives the alignment boundary, in bits, of an argument with the
5679    specified mode and type.  */
5680
5681 int
5682 ix86_function_arg_boundary (enum machine_mode mode, tree type)
5683 {
5684   int align;
5685   if (type)
5686     {
5687       /* Since canonical type is used for call, we convert it to
5688          canonical type if needed.  */
5689       if (!TYPE_STRUCTURAL_EQUALITY_P (type))
5690         type = TYPE_CANONICAL (type);
5691       align = TYPE_ALIGN (type);
5692     }
5693   else
5694     align = GET_MODE_ALIGNMENT (mode);
5695   if (align < PARM_BOUNDARY)
5696     align = PARM_BOUNDARY;
5697   /* In 32bit, only _Decimal128 and __float128 are aligned to their
5698      natural boundaries.  */
5699   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
5700     {
5701       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
5702          make an exception for SSE modes since these require 128bit
5703          alignment.
5704
5705          The handling here differs from field_alignment.  ICC aligns MMX
5706          arguments to 4 byte boundaries, while structure fields are aligned
5707          to 8 byte boundaries.  */
5708       if (!type)
5709         {
5710           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
5711             align = PARM_BOUNDARY;
5712         }
5713       else
5714         {
5715           if (!contains_aligned_value_p (type))
5716             align = PARM_BOUNDARY;
5717         }
5718     }
5719   if (align > BIGGEST_ALIGNMENT)
5720     align = BIGGEST_ALIGNMENT;
5721   return align;
5722 }
5723
5724 /* Return true if N is a possible register number of function value.  */
5725
5726 bool
5727 ix86_function_value_regno_p (int regno)
5728 {
5729   switch (regno)
5730     {
5731     case 0:
5732       return true;
5733
5734     case FIRST_FLOAT_REG:
5735       /* TODO: The function should depend on current function ABI but
5736        builtins.c would need updating then. Therefore we use the
5737        default ABI.  */
5738       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
5739         return false;
5740       return TARGET_FLOAT_RETURNS_IN_80387;
5741
5742     case FIRST_SSE_REG:
5743       return TARGET_SSE;
5744
5745     case FIRST_MMX_REG:
5746       if (TARGET_MACHO || TARGET_64BIT)
5747         return false;
5748       return TARGET_MMX;
5749     }
5750
5751   return false;
5752 }
5753
5754 /* Define how to find the value returned by a function.
5755    VALTYPE is the data type of the value (as a tree).
5756    If the precise function being called is known, FUNC is its FUNCTION_DECL;
5757    otherwise, FUNC is 0.  */
5758
5759 static rtx
5760 function_value_32 (enum machine_mode orig_mode, enum machine_mode mode,
5761                    const_tree fntype, const_tree fn)
5762 {
5763   unsigned int regno;
5764
5765   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
5766      we normally prevent this case when mmx is not available.  However
5767      some ABIs may require the result to be returned like DImode.  */
5768   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
5769     regno = TARGET_MMX ? FIRST_MMX_REG : 0;
5770
5771   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
5772      we prevent this case when sse is not available.  However some ABIs
5773      may require the result to be returned like integer TImode.  */
5774   else if (mode == TImode
5775            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
5776     regno = TARGET_SSE ? FIRST_SSE_REG : 0;
5777
5778   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
5779   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
5780     regno = FIRST_FLOAT_REG;
5781   else
5782     /* Most things go in %eax.  */
5783     regno = AX_REG;
5784
5785   /* Override FP return register with %xmm0 for local functions when
5786      SSE math is enabled or for functions with sseregparm attribute.  */
5787   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
5788     {
5789       int sse_level = ix86_function_sseregparm (fntype, fn, false);
5790       if ((sse_level >= 1 && mode == SFmode)
5791           || (sse_level == 2 && mode == DFmode))
5792         regno = FIRST_SSE_REG;
5793     }
5794
5795   return gen_rtx_REG (orig_mode, regno);
5796 }
5797
5798 static rtx
5799 function_value_64 (enum machine_mode orig_mode, enum machine_mode mode,
5800                    const_tree valtype)
5801 {
5802   rtx ret;
5803
5804   /* Handle libcalls, which don't provide a type node.  */
5805   if (valtype == NULL)
5806     {
5807       switch (mode)
5808         {
5809         case SFmode:
5810         case SCmode:
5811         case DFmode:
5812         case DCmode:
5813         case TFmode:
5814         case SDmode:
5815         case DDmode:
5816         case TDmode:
5817           return gen_rtx_REG (mode, FIRST_SSE_REG);
5818         case XFmode:
5819         case XCmode:
5820           return gen_rtx_REG (mode, FIRST_FLOAT_REG);
5821         case TCmode:
5822           return NULL;
5823         default:
5824           return gen_rtx_REG (mode, AX_REG);
5825         }
5826     }
5827
5828   ret = construct_container (mode, orig_mode, valtype, 1,
5829                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
5830                              x86_64_int_return_registers, 0);
5831
5832   /* For zero sized structures, construct_container returns NULL, but we
5833      need to keep rest of compiler happy by returning meaningful value.  */
5834   if (!ret)
5835     ret = gen_rtx_REG (orig_mode, AX_REG);
5836
5837   return ret;
5838 }
5839
5840 static rtx
5841 function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
5842 {
5843   unsigned int regno = AX_REG;
5844
5845   if (TARGET_SSE)
5846     {
5847       switch (GET_MODE_SIZE (mode))
5848         {
5849         case 16:
5850           if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
5851              && !COMPLEX_MODE_P (mode))
5852             regno = FIRST_SSE_REG;
5853           break;
5854         case 8:
5855         case 4:
5856           if (mode == SFmode || mode == DFmode)
5857             regno = FIRST_SSE_REG;
5858           break;
5859         default:
5860           break;
5861         }
5862     }
5863   return gen_rtx_REG (orig_mode, regno);
5864 }
5865
5866 static rtx
5867 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
5868                        enum machine_mode orig_mode, enum machine_mode mode)
5869 {
5870   const_tree fn, fntype;
5871
5872   fn = NULL_TREE;
5873   if (fntype_or_decl && DECL_P (fntype_or_decl))
5874     fn = fntype_or_decl;
5875   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
5876
5877   if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
5878     return function_value_ms_64 (orig_mode, mode);
5879   else if (TARGET_64BIT)
5880     return function_value_64 (orig_mode, mode, valtype);
5881   else
5882     return function_value_32 (orig_mode, mode, fntype, fn);
5883 }
5884
5885 static rtx
5886 ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
5887                      bool outgoing ATTRIBUTE_UNUSED)
5888 {
5889   enum machine_mode mode, orig_mode;
5890
5891   orig_mode = TYPE_MODE (valtype);
5892   mode = type_natural_mode (valtype);
5893   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
5894 }
5895
5896 rtx
5897 ix86_libcall_value (enum machine_mode mode)
5898 {
5899   return ix86_function_value_1 (NULL, NULL, mode, mode);
5900 }
5901
5902 /* Return true iff type is returned in memory.  */
5903
5904 static int ATTRIBUTE_UNUSED
5905 return_in_memory_32 (const_tree type, enum machine_mode mode)
5906 {
5907   HOST_WIDE_INT size;
5908
5909   if (mode == BLKmode)
5910     return 1;
5911
5912   size = int_size_in_bytes (type);
5913
5914   if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
5915     return 0;
5916
5917   if (VECTOR_MODE_P (mode) || mode == TImode)
5918     {
5919       /* User-created vectors small enough to fit in EAX.  */
5920       if (size < 8)
5921         return 0;
5922
5923       /* MMX/3dNow values are returned in MM0,
5924          except when it doesn't exits.  */
5925       if (size == 8)
5926         return (TARGET_MMX ? 0 : 1);
5927
5928       /* SSE values are returned in XMM0, except when it doesn't exist.  */
5929       if (size == 16)
5930         return (TARGET_SSE ? 0 : 1);
5931     }
5932
5933   if (mode == XFmode)
5934     return 0;
5935
5936   if (size > 12)
5937     return 1;
5938   return 0;
5939 }
5940
5941 static int ATTRIBUTE_UNUSED
5942 return_in_memory_64 (const_tree type, enum machine_mode mode)
5943 {
5944   int needed_intregs, needed_sseregs;
5945   return !examine_argument (mode, type, 1, &needed_intregs, &needed_sseregs);
5946 }
5947
5948 static int ATTRIBUTE_UNUSED
5949 return_in_memory_ms_64 (const_tree type, enum machine_mode mode)
5950 {
5951   HOST_WIDE_INT size = int_size_in_bytes (type);
5952
5953   /* __m128 is returned in xmm0.  */
5954   if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
5955       && !COMPLEX_MODE_P (mode) && (GET_MODE_SIZE (mode) == 16 || size == 16))
5956     return 0;
5957
5958   /* Otherwise, the size must be exactly in [1248]. */
5959   return (size != 1 && size != 2 && size != 4 && size != 8);
5960 }
5961
5962 static bool
5963 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
5964 {
5965 #ifdef SUBTARGET_RETURN_IN_MEMORY
5966   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
5967 #else
5968    const enum machine_mode mode = type_natural_mode (type);
5969  
5970   if (TARGET_64BIT_MS_ABI)
5971      return return_in_memory_ms_64 (type, mode);
5972    else if (TARGET_64BIT)
5973      return return_in_memory_64 (type, mode);
5974    else
5975      return return_in_memory_32 (type, mode);
5976 #endif
5977 }
5978
5979 /* Return false iff TYPE is returned in memory.  This version is used
5980    on Solaris 10.  It is similar to the generic ix86_return_in_memory,
5981    but differs notably in that when MMX is available, 8-byte vectors
5982    are returned in memory, rather than in MMX registers.  */
5983
5984 bool
5985 ix86_sol10_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
5986 {
5987   int size;
5988   enum machine_mode mode = type_natural_mode (type);
5989
5990   if (TARGET_64BIT)
5991     return return_in_memory_64 (type, mode);
5992
5993   if (mode == BLKmode)
5994     return 1;
5995
5996   size = int_size_in_bytes (type);
5997
5998   if (VECTOR_MODE_P (mode))
5999     {
6000       /* Return in memory only if MMX registers *are* available.  This
6001          seems backwards, but it is consistent with the existing
6002          Solaris x86 ABI.  */
6003       if (size == 8)
6004         return TARGET_MMX;
6005       if (size == 16)
6006         return !TARGET_SSE;
6007     }
6008   else if (mode == TImode)
6009     return !TARGET_SSE;
6010   else if (mode == XFmode)
6011     return 0;
6012
6013   return size > 12;
6014 }
6015
6016 /* When returning SSE vector types, we have a choice of either
6017      (1) being abi incompatible with a -march switch, or
6018      (2) generating an error.
6019    Given no good solution, I think the safest thing is one warning.
6020    The user won't be able to use -Werror, but....
6021
6022    Choose the STRUCT_VALUE_RTX hook because that's (at present) only
6023    called in response to actually generating a caller or callee that
6024    uses such a type.  As opposed to TARGET_RETURN_IN_MEMORY, which is called
6025    via aggregate_value_p for general type probing from tree-ssa.  */
6026
6027 static rtx
6028 ix86_struct_value_rtx (tree type, int incoming ATTRIBUTE_UNUSED)
6029 {
6030   static bool warnedsse, warnedmmx;
6031
6032   if (!TARGET_64BIT && type)
6033     {
6034       /* Look at the return type of the function, not the function type.  */
6035       enum machine_mode mode = TYPE_MODE (TREE_TYPE (type));
6036
6037       if (!TARGET_SSE && !warnedsse)
6038         {
6039           if (mode == TImode
6040               || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6041             {
6042               warnedsse = true;
6043               warning (0, "SSE vector return without SSE enabled "
6044                        "changes the ABI");
6045             }
6046         }
6047
6048       if (!TARGET_MMX && !warnedmmx)
6049         {
6050           if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6051             {
6052               warnedmmx = true;
6053               warning (0, "MMX vector return without MMX enabled "
6054                        "changes the ABI");
6055             }
6056         }
6057     }
6058
6059   return NULL;
6060 }
6061
6062 \f
6063 /* Create the va_list data type.  */
6064
6065 /* Returns the calling convention specific va_list date type.
6066    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
6067
6068 static tree
6069 ix86_build_builtin_va_list_abi (enum calling_abi abi)
6070 {
6071   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
6072
6073   /* For i386 we use plain pointer to argument area.  */
6074   if (!TARGET_64BIT || abi == MS_ABI)
6075     return build_pointer_type (char_type_node);
6076
6077   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6078   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6079
6080   f_gpr = build_decl (FIELD_DECL, get_identifier ("gp_offset"),
6081                       unsigned_type_node);
6082   f_fpr = build_decl (FIELD_DECL, get_identifier ("fp_offset"),
6083                       unsigned_type_node);
6084   f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
6085                       ptr_type_node);
6086   f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
6087                       ptr_type_node);
6088
6089   va_list_gpr_counter_field = f_gpr;
6090   va_list_fpr_counter_field = f_fpr;
6091
6092   DECL_FIELD_CONTEXT (f_gpr) = record;
6093   DECL_FIELD_CONTEXT (f_fpr) = record;
6094   DECL_FIELD_CONTEXT (f_ovf) = record;
6095   DECL_FIELD_CONTEXT (f_sav) = record;
6096
6097   TREE_CHAIN (record) = type_decl;
6098   TYPE_NAME (record) = type_decl;
6099   TYPE_FIELDS (record) = f_gpr;
6100   TREE_CHAIN (f_gpr) = f_fpr;
6101   TREE_CHAIN (f_fpr) = f_ovf;
6102   TREE_CHAIN (f_ovf) = f_sav;
6103
6104   layout_type (record);
6105
6106   /* The correct type is an array type of one element.  */
6107   return build_array_type (record, build_index_type (size_zero_node));
6108 }
6109
6110 /* Setup the builtin va_list data type and for 64-bit the additional
6111    calling convention specific va_list data types.  */
6112
6113 static tree
6114 ix86_build_builtin_va_list (void)
6115 {
6116   tree ret = ix86_build_builtin_va_list_abi (DEFAULT_ABI);
6117
6118   /* Initialize abi specific va_list builtin types.  */
6119   if (TARGET_64BIT)
6120     {
6121       tree t;
6122       if (DEFAULT_ABI == MS_ABI)
6123         {
6124           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
6125           if (TREE_CODE (t) != RECORD_TYPE)
6126             t = build_variant_type_copy (t);
6127           sysv_va_list_type_node = t;
6128         }
6129       else
6130         {
6131           t = ret;
6132           if (TREE_CODE (t) != RECORD_TYPE)
6133             t = build_variant_type_copy (t);
6134           sysv_va_list_type_node = t;
6135         }
6136       if (DEFAULT_ABI != MS_ABI)
6137         {
6138           t = ix86_build_builtin_va_list_abi (MS_ABI);
6139           if (TREE_CODE (t) != RECORD_TYPE)
6140             t = build_variant_type_copy (t);
6141           ms_va_list_type_node = t;
6142         }
6143       else
6144         {
6145           t = ret;
6146           if (TREE_CODE (t) != RECORD_TYPE)
6147             t = build_variant_type_copy (t);
6148           ms_va_list_type_node = t;
6149         }
6150     }
6151
6152   return ret;
6153 }
6154
6155 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
6156
6157 static void
6158 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
6159 {
6160   rtx save_area, mem;
6161   rtx label;
6162   rtx label_ref;
6163   rtx tmp_reg;
6164   rtx nsse_reg;
6165   alias_set_type set;
6166   int i;
6167   int regparm = ix86_regparm;
6168
6169   if((cum ? cum->call_abi : ix86_cfun_abi ()) != DEFAULT_ABI)
6170     regparm = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
6171
6172   if (! cfun->va_list_gpr_size && ! cfun->va_list_fpr_size)
6173     return;
6174
6175   /* Indicate to allocate space on the stack for varargs save area.  */
6176   ix86_save_varrargs_registers = 1;
6177
6178   save_area = frame_pointer_rtx;
6179   set = get_varargs_alias_set ();
6180
6181   for (i = cum->regno;
6182        i < regparm
6183        && i < cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
6184        i++)
6185     {
6186       mem = gen_rtx_MEM (Pmode,
6187                          plus_constant (save_area, i * UNITS_PER_WORD));
6188       MEM_NOTRAP_P (mem) = 1;
6189       set_mem_alias_set (mem, set);
6190       emit_move_insn (mem, gen_rtx_REG (Pmode,
6191                                         x86_64_int_parameter_registers[i]));
6192     }
6193
6194   if (cum->sse_nregs && cfun->va_list_fpr_size)
6195     {
6196       /* Now emit code to save SSE registers.  The AX parameter contains number
6197          of SSE parameter registers used to call this function.  We use
6198          sse_prologue_save insn template that produces computed jump across
6199          SSE saves.  We need some preparation work to get this working.  */
6200
6201       label = gen_label_rtx ();
6202       label_ref = gen_rtx_LABEL_REF (Pmode, label);
6203
6204       /* Compute address to jump to :
6205          label - eax*4 + nnamed_sse_arguments*4  */
6206       tmp_reg = gen_reg_rtx (Pmode);
6207       nsse_reg = gen_reg_rtx (Pmode);
6208       emit_insn (gen_zero_extendqidi2 (nsse_reg, gen_rtx_REG (QImode, AX_REG)));
6209       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6210                               gen_rtx_MULT (Pmode, nsse_reg,
6211                                             GEN_INT (4))));
6212       if (cum->sse_regno)
6213         emit_move_insn
6214           (nsse_reg,
6215            gen_rtx_CONST (DImode,
6216                           gen_rtx_PLUS (DImode,
6217                                         label_ref,
6218                                         GEN_INT (cum->sse_regno * 4))));
6219       else
6220         emit_move_insn (nsse_reg, label_ref);
6221       emit_insn (gen_subdi3 (nsse_reg, nsse_reg, tmp_reg));
6222
6223       /* Compute address of memory block we save into.  We always use pointer
6224          pointing 127 bytes after first byte to store - this is needed to keep
6225          instruction size limited by 4 bytes.  */
6226       tmp_reg = gen_reg_rtx (Pmode);
6227       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6228                               plus_constant (save_area,
6229                                              8 * X86_64_REGPARM_MAX + 127)));
6230       mem = gen_rtx_MEM (BLKmode, plus_constant (tmp_reg, -127));
6231       MEM_NOTRAP_P (mem) = 1;
6232       set_mem_alias_set (mem, set);
6233       set_mem_align (mem, BITS_PER_WORD);
6234
6235       /* And finally do the dirty job!  */
6236       emit_insn (gen_sse_prologue_save (mem, nsse_reg,
6237                                         GEN_INT (cum->sse_regno), label));
6238     }
6239 }
6240
6241 static void
6242 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
6243 {
6244   alias_set_type set = get_varargs_alias_set ();
6245   int i;
6246
6247   for (i = cum->regno; i < X64_REGPARM_MAX; i++)
6248     {
6249       rtx reg, mem;
6250
6251       mem = gen_rtx_MEM (Pmode,
6252                          plus_constant (virtual_incoming_args_rtx,
6253                                         i * UNITS_PER_WORD));
6254       MEM_NOTRAP_P (mem) = 1;
6255       set_mem_alias_set (mem, set);
6256
6257       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
6258       emit_move_insn (mem, reg);
6259     }
6260 }
6261
6262 static void
6263 ix86_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
6264                              tree type, int *pretend_size ATTRIBUTE_UNUSED,
6265                              int no_rtl)
6266 {
6267   CUMULATIVE_ARGS next_cum;
6268   tree fntype;
6269
6270   /* This argument doesn't appear to be used anymore.  Which is good,
6271      because the old code here didn't suppress rtl generation.  */
6272   gcc_assert (!no_rtl);
6273
6274   if (!TARGET_64BIT)
6275     return;
6276
6277   fntype = TREE_TYPE (current_function_decl);
6278
6279   /* For varargs, we do not want to skip the dummy va_dcl argument.
6280      For stdargs, we do want to skip the last named argument.  */
6281   next_cum = *cum;
6282   if (stdarg_p (fntype))
6283     function_arg_advance (&next_cum, mode, type, 1);
6284
6285   if ((cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
6286     setup_incoming_varargs_ms_64 (&next_cum);
6287   else
6288     setup_incoming_varargs_64 (&next_cum);
6289 }
6290
6291 /* Checks if TYPE is of kind va_list char *.  */
6292
6293 static bool
6294 is_va_list_char_pointer (tree type)
6295 {
6296   tree canonic;
6297
6298   /* For 32-bit it is always true.  */
6299   if (!TARGET_64BIT)
6300     return true;
6301   canonic = ix86_canonical_va_list_type (type);
6302   return (canonic == ms_va_list_type_node
6303           || (DEFAULT_ABI == MS_ABI && canonic == va_list_type_node));
6304 }
6305
6306 /* Implement va_start.  */
6307
6308 static void
6309 ix86_va_start (tree valist, rtx nextarg)
6310 {
6311   HOST_WIDE_INT words, n_gpr, n_fpr;
6312   tree f_gpr, f_fpr, f_ovf, f_sav;
6313   tree gpr, fpr, ovf, sav, t;
6314   tree type;
6315
6316   /* Only 64bit target needs something special.  */
6317   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6318     {
6319       std_expand_builtin_va_start (valist, nextarg);
6320       return;
6321     }
6322
6323   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6324   f_fpr = TREE_CHAIN (f_gpr);
6325   f_ovf = TREE_CHAIN (f_fpr);
6326   f_sav = TREE_CHAIN (f_ovf);
6327
6328   valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
6329   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6330   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6331   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6332   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6333
6334   /* Count number of gp and fp argument registers used.  */
6335   words = crtl->args.info.words;
6336   n_gpr = crtl->args.info.regno;
6337   n_fpr = crtl->args.info.sse_regno;
6338
6339   if (cfun->va_list_gpr_size)
6340     {
6341       type = TREE_TYPE (gpr);
6342       t = build2 (MODIFY_EXPR, type,
6343                   gpr, build_int_cst (type, n_gpr * 8));
6344       TREE_SIDE_EFFECTS (t) = 1;
6345       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6346     }
6347
6348   if (cfun->va_list_fpr_size)
6349     {
6350       type = TREE_TYPE (fpr);
6351       t = build2 (MODIFY_EXPR, type, fpr,
6352                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
6353       TREE_SIDE_EFFECTS (t) = 1;
6354       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6355     }
6356
6357   /* Find the overflow area.  */
6358   type = TREE_TYPE (ovf);
6359   t = make_tree (type, crtl->args.internal_arg_pointer);
6360   if (words != 0)
6361     t = build2 (POINTER_PLUS_EXPR, type, t,
6362                 size_int (words * UNITS_PER_WORD));
6363   t = build2 (MODIFY_EXPR, type, ovf, t);
6364   TREE_SIDE_EFFECTS (t) = 1;
6365   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6366
6367   if (cfun->va_list_gpr_size || cfun->va_list_fpr_size)
6368     {
6369       /* Find the register save area.
6370          Prologue of the function save it right above stack frame.  */
6371       type = TREE_TYPE (sav);
6372       t = make_tree (type, frame_pointer_rtx);
6373       t = build2 (MODIFY_EXPR, type, sav, t);
6374       TREE_SIDE_EFFECTS (t) = 1;
6375       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6376     }
6377 }
6378
6379 /* Implement va_arg.  */
6380
6381 static tree
6382 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
6383                       gimple_seq *post_p)
6384 {
6385   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
6386   tree f_gpr, f_fpr, f_ovf, f_sav;
6387   tree gpr, fpr, ovf, sav, t;
6388   int size, rsize;
6389   tree lab_false, lab_over = NULL_TREE;
6390   tree addr, t2;
6391   rtx container;
6392   int indirect_p = 0;
6393   tree ptrtype;
6394   enum machine_mode nat_mode;
6395   int arg_boundary;
6396
6397   /* Only 64bit target needs something special.  */
6398   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6399     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6400
6401   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6402   f_fpr = TREE_CHAIN (f_gpr);
6403   f_ovf = TREE_CHAIN (f_fpr);
6404   f_sav = TREE_CHAIN (f_ovf);
6405
6406   valist = build_va_arg_indirect_ref (valist);
6407   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6408   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6409   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6410   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6411
6412   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
6413   if (indirect_p)
6414     type = build_pointer_type (type);
6415   size = int_size_in_bytes (type);
6416   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6417
6418   nat_mode = type_natural_mode (type);
6419   container = construct_container (nat_mode, TYPE_MODE (type), type, 0,
6420                                    X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
6421                                    intreg, 0);
6422
6423   /* Pull the value out of the saved registers.  */
6424
6425   addr = create_tmp_var (ptr_type_node, "addr");
6426   DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
6427
6428   if (container)
6429     {
6430       int needed_intregs, needed_sseregs;
6431       bool need_temp;
6432       tree int_addr, sse_addr;
6433
6434       lab_false = create_artificial_label ();
6435       lab_over = create_artificial_label ();
6436
6437       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
6438
6439       need_temp = (!REG_P (container)
6440                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
6441                        || TYPE_ALIGN (type) > 128));
6442
6443       /* In case we are passing structure, verify that it is consecutive block
6444          on the register save area.  If not we need to do moves.  */
6445       if (!need_temp && !REG_P (container))
6446         {
6447           /* Verify that all registers are strictly consecutive  */
6448           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
6449             {
6450               int i;
6451
6452               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6453                 {
6454                   rtx slot = XVECEXP (container, 0, i);
6455                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
6456                       || INTVAL (XEXP (slot, 1)) != i * 16)
6457                     need_temp = 1;
6458                 }
6459             }
6460           else
6461             {
6462               int i;
6463
6464               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6465                 {
6466                   rtx slot = XVECEXP (container, 0, i);
6467                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
6468                       || INTVAL (XEXP (slot, 1)) != i * 8)
6469                     need_temp = 1;
6470                 }
6471             }
6472         }
6473       if (!need_temp)
6474         {
6475           int_addr = addr;
6476           sse_addr = addr;
6477         }
6478       else
6479         {
6480           int_addr = create_tmp_var (ptr_type_node, "int_addr");
6481           DECL_POINTER_ALIAS_SET (int_addr) = get_varargs_alias_set ();
6482           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
6483           DECL_POINTER_ALIAS_SET (sse_addr) = get_varargs_alias_set ();
6484         }
6485
6486       /* First ensure that we fit completely in registers.  */
6487       if (needed_intregs)
6488         {
6489           t = build_int_cst (TREE_TYPE (gpr),
6490                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
6491           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
6492           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6493           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6494           gimplify_and_add (t, pre_p);
6495         }
6496       if (needed_sseregs)
6497         {
6498           t = build_int_cst (TREE_TYPE (fpr),
6499                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
6500                              + X86_64_REGPARM_MAX * 8);
6501           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
6502           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6503           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6504           gimplify_and_add (t, pre_p);
6505         }
6506
6507       /* Compute index to start of area used for integer regs.  */
6508       if (needed_intregs)
6509         {
6510           /* int_addr = gpr + sav; */
6511           t = fold_convert (sizetype, gpr);
6512           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6513           gimplify_assign (int_addr, t, pre_p);
6514         }
6515       if (needed_sseregs)
6516         {
6517           /* sse_addr = fpr + sav; */
6518           t = fold_convert (sizetype, fpr);
6519           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6520           gimplify_assign (sse_addr, t, pre_p);
6521         }
6522       if (need_temp)
6523         {
6524           int i;
6525           tree temp = create_tmp_var (type, "va_arg_tmp");
6526
6527           /* addr = &temp; */
6528           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
6529           gimplify_assign (addr, t, pre_p);
6530
6531           for (i = 0; i < XVECLEN (container, 0); i++)
6532             {
6533               rtx slot = XVECEXP (container, 0, i);
6534               rtx reg = XEXP (slot, 0);
6535               enum machine_mode mode = GET_MODE (reg);
6536               tree piece_type = lang_hooks.types.type_for_mode (mode, 1);
6537               tree addr_type = build_pointer_type (piece_type);
6538               tree src_addr, src;
6539               int src_offset;
6540               tree dest_addr, dest;
6541
6542               if (SSE_REGNO_P (REGNO (reg)))
6543                 {
6544                   src_addr = sse_addr;
6545                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
6546                 }
6547               else
6548                 {
6549                   src_addr = int_addr;
6550                   src_offset = REGNO (reg) * 8;
6551                 }
6552               src_addr = fold_convert (addr_type, src_addr);
6553               src_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, src_addr,
6554                                       size_int (src_offset));
6555               src = build_va_arg_indirect_ref (src_addr);
6556
6557               dest_addr = fold_convert (addr_type, addr);
6558               dest_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, dest_addr,
6559                                        size_int (INTVAL (XEXP (slot, 1))));
6560               dest = build_va_arg_indirect_ref (dest_addr);
6561
6562               gimplify_assign (dest, src, pre_p);
6563             }
6564         }
6565
6566       if (needed_intregs)
6567         {
6568           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
6569                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
6570           gimplify_assign (gpr, t, pre_p);
6571         }
6572
6573       if (needed_sseregs)
6574         {
6575           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
6576                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
6577           gimplify_assign (fpr, t, pre_p);
6578         }
6579
6580       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
6581
6582       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
6583     }
6584
6585   /* ... otherwise out of the overflow area.  */
6586
6587   /* When we align parameter on stack for caller, if the parameter
6588      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
6589      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
6590      here with caller.  */
6591   arg_boundary = FUNCTION_ARG_BOUNDARY (VOIDmode, type);
6592   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
6593     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
6594
6595   /* Care for on-stack alignment if needed.  */
6596   if (arg_boundary <= 64
6597       || integer_zerop (TYPE_SIZE (type)))
6598     t = ovf;
6599  else
6600     {
6601       HOST_WIDE_INT align = arg_boundary / 8;
6602       t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovf), ovf,
6603                   size_int (align - 1));
6604       t = fold_convert (sizetype, t);
6605       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
6606                   size_int (-align));
6607       t = fold_convert (TREE_TYPE (ovf), t);
6608     }
6609   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
6610   gimplify_assign (addr, t, pre_p);
6611
6612   t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
6613               size_int (rsize * UNITS_PER_WORD));
6614   gimplify_assign (unshare_expr (ovf), t, pre_p);
6615
6616   if (container)
6617     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
6618
6619   ptrtype = build_pointer_type (type);
6620   addr = fold_convert (ptrtype, addr);
6621
6622   if (indirect_p)
6623     addr = build_va_arg_indirect_ref (addr);
6624   return build_va_arg_indirect_ref (addr);
6625 }
6626 \f
6627 /* Return nonzero if OPNUM's MEM should be matched
6628    in movabs* patterns.  */
6629
6630 int
6631 ix86_check_movabs (rtx insn, int opnum)
6632 {
6633   rtx set, mem;
6634
6635   set = PATTERN (insn);
6636   if (GET_CODE (set) == PARALLEL)
6637     set = XVECEXP (set, 0, 0);
6638   gcc_assert (GET_CODE (set) == SET);
6639   mem = XEXP (set, opnum);
6640   while (GET_CODE (mem) == SUBREG)
6641     mem = SUBREG_REG (mem);
6642   gcc_assert (MEM_P (mem));
6643   return (volatile_ok || !MEM_VOLATILE_P (mem));
6644 }
6645 \f
6646 /* Initialize the table of extra 80387 mathematical constants.  */
6647
6648 static void
6649 init_ext_80387_constants (void)
6650 {
6651   static const char * cst[5] =
6652   {
6653     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
6654     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
6655     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
6656     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
6657     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
6658   };
6659   int i;
6660
6661   for (i = 0; i < 5; i++)
6662     {
6663       real_from_string (&ext_80387_constants_table[i], cst[i]);
6664       /* Ensure each constant is rounded to XFmode precision.  */
6665       real_convert (&ext_80387_constants_table[i],
6666                     XFmode, &ext_80387_constants_table[i]);
6667     }
6668
6669   ext_80387_constants_init = 1;
6670 }
6671
6672 /* Return true if the constant is something that can be loaded with
6673    a special instruction.  */
6674
6675 int
6676 standard_80387_constant_p (rtx x)
6677 {
6678   enum machine_mode mode = GET_MODE (x);
6679
6680   REAL_VALUE_TYPE r;
6681
6682   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
6683     return -1;
6684
6685   if (x == CONST0_RTX (mode))
6686     return 1;
6687   if (x == CONST1_RTX (mode))
6688     return 2;
6689
6690   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
6691
6692   /* For XFmode constants, try to find a special 80387 instruction when
6693      optimizing for size or on those CPUs that benefit from them.  */
6694   if (mode == XFmode
6695       && (optimize_insn_for_size_p () || TARGET_EXT_80387_CONSTANTS))
6696     {
6697       int i;
6698
6699       if (! ext_80387_constants_init)
6700         init_ext_80387_constants ();
6701
6702       for (i = 0; i < 5; i++)
6703         if (real_identical (&r, &ext_80387_constants_table[i]))
6704           return i + 3;
6705     }
6706
6707   /* Load of the constant -0.0 or -1.0 will be split as
6708      fldz;fchs or fld1;fchs sequence.  */
6709   if (real_isnegzero (&r))
6710     return 8;
6711   if (real_identical (&r, &dconstm1))
6712     return 9;
6713
6714   return 0;
6715 }
6716
6717 /* Return the opcode of the special instruction to be used to load
6718    the constant X.  */
6719
6720 const char *
6721 standard_80387_constant_opcode (rtx x)
6722 {
6723   switch (standard_80387_constant_p (x))
6724     {
6725     case 1:
6726       return "fldz";
6727     case 2:
6728       return "fld1";
6729     case 3:
6730       return "fldlg2";
6731     case 4:
6732       return "fldln2";
6733     case 5:
6734       return "fldl2e";
6735     case 6:
6736       return "fldl2t";
6737     case 7:
6738       return "fldpi";
6739     case 8:
6740     case 9:
6741       return "#";
6742     default:
6743       gcc_unreachable ();
6744     }
6745 }
6746
6747 /* Return the CONST_DOUBLE representing the 80387 constant that is
6748    loaded by the specified special instruction.  The argument IDX
6749    matches the return value from standard_80387_constant_p.  */
6750
6751 rtx
6752 standard_80387_constant_rtx (int idx)
6753 {
6754   int i;
6755
6756   if (! ext_80387_constants_init)
6757     init_ext_80387_constants ();
6758
6759   switch (idx)
6760     {
6761     case 3:
6762     case 4:
6763     case 5:
6764     case 6:
6765     case 7:
6766       i = idx - 3;
6767       break;
6768
6769     default:
6770       gcc_unreachable ();
6771     }
6772
6773   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
6774                                        XFmode);
6775 }
6776
6777 /* Return 1 if mode is a valid mode for sse.  */
6778 static int
6779 standard_sse_mode_p (enum machine_mode mode)
6780 {
6781   switch (mode)
6782     {
6783     case V16QImode:
6784     case V8HImode:
6785     case V4SImode:
6786     case V2DImode:
6787     case V4SFmode:
6788     case V2DFmode:
6789       return 1;
6790
6791     default:
6792       return 0;
6793     }
6794 }
6795
6796 /* Return 1 if X is FP constant we can load to SSE register w/o using memory.
6797  */
6798 int
6799 standard_sse_constant_p (rtx x)
6800 {
6801   enum machine_mode mode = GET_MODE (x);
6802
6803   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
6804     return 1;
6805   if (vector_all_ones_operand (x, mode)
6806       && standard_sse_mode_p (mode))
6807     return TARGET_SSE2 ? 2 : -1;
6808
6809   return 0;
6810 }
6811
6812 /* Return the opcode of the special instruction to be used to load
6813    the constant X.  */
6814
6815 const char *
6816 standard_sse_constant_opcode (rtx insn, rtx x)
6817 {
6818   switch (standard_sse_constant_p (x))
6819     {
6820     case 1:
6821       if (get_attr_mode (insn) == MODE_V4SF)
6822         return "xorps\t%0, %0";
6823       else if (get_attr_mode (insn) == MODE_V2DF)
6824         return "xorpd\t%0, %0";
6825       else
6826         return "pxor\t%0, %0";
6827     case 2:
6828       return "pcmpeqd\t%0, %0";
6829     }
6830   gcc_unreachable ();
6831 }
6832
6833 /* Returns 1 if OP contains a symbol reference */
6834
6835 int
6836 symbolic_reference_mentioned_p (rtx op)
6837 {
6838   const char *fmt;
6839   int i;
6840
6841   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
6842     return 1;
6843
6844   fmt = GET_RTX_FORMAT (GET_CODE (op));
6845   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
6846     {
6847       if (fmt[i] == 'E')
6848         {
6849           int j;
6850
6851           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
6852             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
6853               return 1;
6854         }
6855
6856       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
6857         return 1;
6858     }
6859
6860   return 0;
6861 }
6862
6863 /* Return 1 if it is appropriate to emit `ret' instructions in the
6864    body of a function.  Do this only if the epilogue is simple, needing a
6865    couple of insns.  Prior to reloading, we can't tell how many registers
6866    must be saved, so return 0 then.  Return 0 if there is no frame
6867    marker to de-allocate.  */
6868
6869 int
6870 ix86_can_use_return_insn_p (void)
6871 {
6872   struct ix86_frame frame;
6873
6874   if (! reload_completed || frame_pointer_needed)
6875     return 0;
6876
6877   /* Don't allow more than 32 pop, since that's all we can do
6878      with one instruction.  */
6879   if (crtl->args.pops_args
6880       && crtl->args.size >= 32768)
6881     return 0;
6882
6883   ix86_compute_frame_layout (&frame);
6884   return frame.to_allocate == 0 && frame.nregs == 0;
6885 }
6886 \f
6887 /* Value should be nonzero if functions must have frame pointers.
6888    Zero means the frame pointer need not be set up (and parms may
6889    be accessed via the stack pointer) in functions that seem suitable.  */
6890
6891 int
6892 ix86_frame_pointer_required (void)
6893 {
6894   /* If we accessed previous frames, then the generated code expects
6895      to be able to access the saved ebp value in our frame.  */
6896   if (cfun->machine->accesses_prev_frame)
6897     return 1;
6898
6899   /* Several x86 os'es need a frame pointer for other reasons,
6900      usually pertaining to setjmp.  */
6901   if (SUBTARGET_FRAME_POINTER_REQUIRED)
6902     return 1;
6903
6904   /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
6905      the frame pointer by default.  Turn it back on now if we've not
6906      got a leaf function.  */
6907   if (TARGET_OMIT_LEAF_FRAME_POINTER
6908       && (!current_function_is_leaf
6909           || ix86_current_function_calls_tls_descriptor))
6910     return 1;
6911
6912   if (crtl->profile)
6913     return 1;
6914
6915   return 0;
6916 }
6917
6918 /* Record that the current function accesses previous call frames.  */
6919
6920 void
6921 ix86_setup_frame_addresses (void)
6922 {
6923   cfun->machine->accesses_prev_frame = 1;
6924 }
6925 \f
6926 #if (defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)) || TARGET_MACHO
6927 # define USE_HIDDEN_LINKONCE 1
6928 #else
6929 # define USE_HIDDEN_LINKONCE 0
6930 #endif
6931
6932 static int pic_labels_used;
6933
6934 /* Fills in the label name that should be used for a pc thunk for
6935    the given register.  */
6936
6937 static void
6938 get_pc_thunk_name (char name[32], unsigned int regno)
6939 {
6940   gcc_assert (!TARGET_64BIT);
6941
6942   if (USE_HIDDEN_LINKONCE)
6943     sprintf (name, "__i686.get_pc_thunk.%s", reg_names[regno]);
6944   else
6945     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
6946 }
6947
6948
6949 /* This function generates code for -fpic that loads %ebx with
6950    the return address of the caller and then returns.  */
6951
6952 void
6953 ix86_file_end (void)
6954 {
6955   rtx xops[2];
6956   int regno;
6957
6958   for (regno = 0; regno < 8; ++regno)
6959     {
6960       char name[32];
6961
6962       if (! ((pic_labels_used >> regno) & 1))
6963         continue;
6964
6965       get_pc_thunk_name (name, regno);
6966
6967 #if TARGET_MACHO
6968       if (TARGET_MACHO)
6969         {
6970           switch_to_section (darwin_sections[text_coal_section]);
6971           fputs ("\t.weak_definition\t", asm_out_file);
6972           assemble_name (asm_out_file, name);
6973           fputs ("\n\t.private_extern\t", asm_out_file);
6974           assemble_name (asm_out_file, name);
6975           fputs ("\n", asm_out_file);
6976           ASM_OUTPUT_LABEL (asm_out_file, name);
6977         }
6978       else
6979 #endif
6980       if (USE_HIDDEN_LINKONCE)
6981         {
6982           tree decl;
6983
6984           decl = build_decl (FUNCTION_DECL, get_identifier (name),
6985                              error_mark_node);
6986           TREE_PUBLIC (decl) = 1;
6987           TREE_STATIC (decl) = 1;
6988           DECL_ONE_ONLY (decl) = 1;
6989
6990           (*targetm.asm_out.unique_section) (decl, 0);
6991           switch_to_section (get_named_section (decl, NULL, 0));
6992
6993           (*targetm.asm_out.globalize_label) (asm_out_file, name);
6994           fputs ("\t.hidden\t", asm_out_file);
6995           assemble_name (asm_out_file, name);
6996           fputc ('\n', asm_out_file);
6997           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
6998         }
6999       else
7000         {
7001           switch_to_section (text_section);
7002           ASM_OUTPUT_LABEL (asm_out_file, name);
7003         }
7004
7005       xops[0] = gen_rtx_REG (Pmode, regno);
7006       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
7007       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
7008       output_asm_insn ("ret", xops);
7009     }
7010
7011   if (NEED_INDICATE_EXEC_STACK)
7012     file_end_indicate_exec_stack ();
7013 }
7014
7015 /* Emit code for the SET_GOT patterns.  */
7016
7017 const char *
7018 output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
7019 {
7020   rtx xops[3];
7021
7022   xops[0] = dest;
7023
7024   if (TARGET_VXWORKS_RTP && flag_pic)
7025     {
7026       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
7027       xops[2] = gen_rtx_MEM (Pmode,
7028                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
7029       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
7030
7031       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
7032          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
7033          an unadorned address.  */
7034       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7035       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
7036       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
7037       return "";
7038     }
7039
7040   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
7041
7042   if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
7043     {
7044       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
7045
7046       if (!flag_pic)
7047         output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
7048       else
7049         output_asm_insn ("call\t%a2", xops);
7050
7051 #if TARGET_MACHO
7052       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7053          is what will be referenced by the Mach-O PIC subsystem.  */
7054       if (!label)
7055         ASM_OUTPUT_LABEL (asm_out_file, machopic_function_base_name ());
7056 #endif
7057
7058       (*targetm.asm_out.internal_label) (asm_out_file, "L",
7059                                  CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
7060
7061       if (flag_pic)
7062         output_asm_insn ("pop%z0\t%0", xops);
7063     }
7064   else
7065     {
7066       char name[32];
7067       get_pc_thunk_name (name, REGNO (dest));
7068       pic_labels_used |= 1 << REGNO (dest);
7069
7070       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
7071       xops[2] = gen_rtx_MEM (QImode, xops[2]);
7072       output_asm_insn ("call\t%X2", xops);
7073       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7074          is what will be referenced by the Mach-O PIC subsystem.  */
7075 #if TARGET_MACHO
7076       if (!label)
7077         ASM_OUTPUT_LABEL (asm_out_file, machopic_function_base_name ());
7078       else
7079         targetm.asm_out.internal_label (asm_out_file, "L",
7080                                            CODE_LABEL_NUMBER (label));
7081 #endif
7082     }
7083
7084   if (TARGET_MACHO)
7085     return "";
7086
7087   if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
7088     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
7089   else
7090     output_asm_insn ("add%z0\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
7091
7092   return "";
7093 }
7094
7095 /* Generate an "push" pattern for input ARG.  */
7096
7097 static rtx
7098 gen_push (rtx arg)
7099 {
7100   return gen_rtx_SET (VOIDmode,
7101                       gen_rtx_MEM (Pmode,
7102                                    gen_rtx_PRE_DEC (Pmode,
7103                                                     stack_pointer_rtx)),
7104                       arg);
7105 }
7106
7107 /* Return >= 0 if there is an unused call-clobbered register available
7108    for the entire function.  */
7109
7110 static unsigned int
7111 ix86_select_alt_pic_regnum (void)
7112 {
7113   if (current_function_is_leaf && !crtl->profile
7114       && !ix86_current_function_calls_tls_descriptor)
7115     {
7116       int i, drap;
7117       /* Can't use the same register for both PIC and DRAP.  */
7118       if (crtl->drap_reg)
7119         drap = REGNO (crtl->drap_reg);
7120       else
7121         drap = -1;
7122       for (i = 2; i >= 0; --i)
7123         if (i != drap && !df_regs_ever_live_p (i))
7124           return i;
7125     }
7126
7127   return INVALID_REGNUM;
7128 }
7129
7130 /* Return 1 if we need to save REGNO.  */
7131 static int
7132 ix86_save_reg (unsigned int regno, int maybe_eh_return)
7133 {
7134   if (pic_offset_table_rtx
7135       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
7136       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
7137           || crtl->profile
7138           || crtl->calls_eh_return
7139           || crtl->uses_const_pool))
7140     {
7141       if (ix86_select_alt_pic_regnum () != INVALID_REGNUM)
7142         return 0;
7143       return 1;
7144     }
7145
7146   if (crtl->calls_eh_return && maybe_eh_return)
7147     {
7148       unsigned i;
7149       for (i = 0; ; i++)
7150         {
7151           unsigned test = EH_RETURN_DATA_REGNO (i);
7152           if (test == INVALID_REGNUM)
7153             break;
7154           if (test == regno)
7155             return 1;
7156         }
7157     }
7158
7159   if (crtl->drap_reg
7160       && regno == REGNO (crtl->drap_reg))
7161     return 1;
7162
7163   return (df_regs_ever_live_p (regno)
7164           && !call_used_regs[regno]
7165           && !fixed_regs[regno]
7166           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
7167 }
7168
7169 /* Return number of registers to be saved on the stack.  */
7170
7171 static int
7172 ix86_nsaved_regs (void)
7173 {
7174   int nregs = 0;
7175   int regno;
7176
7177   for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
7178     if (ix86_save_reg (regno, true))
7179       nregs++;
7180   return nregs;
7181 }
7182
7183 /* Given FROM and TO register numbers, say whether this elimination is
7184    allowed.  If stack alignment is needed, we can only replace argument
7185    pointer with hard frame pointer, or replace frame pointer with stack
7186    pointer.  Otherwise, frame pointer elimination is automatically
7187    handled and all other eliminations are valid.  */
7188
7189 int
7190 ix86_can_eliminate (int from, int to)
7191 {
7192   if (stack_realign_fp)
7193     return ((from == ARG_POINTER_REGNUM
7194              && to == HARD_FRAME_POINTER_REGNUM)
7195             || (from == FRAME_POINTER_REGNUM
7196                 && to == STACK_POINTER_REGNUM));
7197   else
7198     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : 1;
7199 }
7200
7201 /* Return the offset between two registers, one to be eliminated, and the other
7202    its replacement, at the start of a routine.  */
7203
7204 HOST_WIDE_INT
7205 ix86_initial_elimination_offset (int from, int to)
7206 {
7207   struct ix86_frame frame;
7208   ix86_compute_frame_layout (&frame);
7209
7210   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
7211     return frame.hard_frame_pointer_offset;
7212   else if (from == FRAME_POINTER_REGNUM
7213            && to == HARD_FRAME_POINTER_REGNUM)
7214     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
7215   else
7216     {
7217       gcc_assert (to == STACK_POINTER_REGNUM);
7218
7219       if (from == ARG_POINTER_REGNUM)
7220         return frame.stack_pointer_offset;
7221
7222       gcc_assert (from == FRAME_POINTER_REGNUM);
7223       return frame.stack_pointer_offset - frame.frame_pointer_offset;
7224     }
7225 }
7226
7227 /* Fill structure ix86_frame about frame of currently computed function.  */
7228
7229 static void
7230 ix86_compute_frame_layout (struct ix86_frame *frame)
7231 {
7232   HOST_WIDE_INT total_size;
7233   unsigned int stack_alignment_needed;
7234   HOST_WIDE_INT offset;
7235   unsigned int preferred_alignment;
7236   HOST_WIDE_INT size = get_frame_size ();
7237
7238   frame->nregs = ix86_nsaved_regs ();
7239   total_size = size;
7240
7241   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
7242   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
7243
7244   gcc_assert (!size || stack_alignment_needed);
7245   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
7246   gcc_assert (preferred_alignment <= stack_alignment_needed);
7247
7248   /* During reload iteration the amount of registers saved can change.
7249      Recompute the value as needed.  Do not recompute when amount of registers
7250      didn't change as reload does multiple calls to the function and does not
7251      expect the decision to change within single iteration.  */
7252   if (!optimize_size
7253       && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
7254     {
7255       int count = frame->nregs;
7256
7257       cfun->machine->use_fast_prologue_epilogue_nregs = count;
7258       /* The fast prologue uses move instead of push to save registers.  This
7259          is significantly longer, but also executes faster as modern hardware
7260          can execute the moves in parallel, but can't do that for push/pop.
7261
7262          Be careful about choosing what prologue to emit:  When function takes
7263          many instructions to execute we may use slow version as well as in
7264          case function is known to be outside hot spot (this is known with
7265          feedback only).  Weight the size of function by number of registers
7266          to save as it is cheap to use one or two push instructions but very
7267          slow to use many of them.  */
7268       if (count)
7269         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7270       if (cfun->function_frequency < FUNCTION_FREQUENCY_NORMAL
7271           || (flag_branch_probabilities
7272               && cfun->function_frequency < FUNCTION_FREQUENCY_HOT))
7273         cfun->machine->use_fast_prologue_epilogue = false;
7274       else
7275         cfun->machine->use_fast_prologue_epilogue
7276            = !expensive_function_p (count);
7277     }
7278   if (TARGET_PROLOGUE_USING_MOVE
7279       && cfun->machine->use_fast_prologue_epilogue)
7280     frame->save_regs_using_mov = true;
7281   else
7282     frame->save_regs_using_mov = false;
7283
7284
7285   /* Skip return address and saved base pointer.  */
7286   offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
7287
7288   frame->hard_frame_pointer_offset = offset;
7289
7290   /* Set offset to aligned because the realigned frame starts from
7291      here.  */
7292   if (stack_realign_fp)
7293     offset = (offset + stack_alignment_needed -1) & -stack_alignment_needed;
7294
7295   /* Register save area */
7296   offset += frame->nregs * UNITS_PER_WORD;
7297
7298   /* Va-arg area */
7299   if (ix86_save_varrargs_registers)
7300     {
7301       offset += X86_64_VARARGS_SIZE;
7302       frame->va_arg_size = X86_64_VARARGS_SIZE;
7303     }
7304   else
7305     frame->va_arg_size = 0;
7306
7307   /* Align start of frame for local function.  */
7308   frame->padding1 = ((offset + stack_alignment_needed - 1)
7309                      & -stack_alignment_needed) - offset;
7310
7311   offset += frame->padding1;
7312
7313   /* Frame pointer points here.  */
7314   frame->frame_pointer_offset = offset;
7315
7316   offset += size;
7317
7318   /* Add outgoing arguments area.  Can be skipped if we eliminated
7319      all the function calls as dead code.
7320      Skipping is however impossible when function calls alloca.  Alloca
7321      expander assumes that last crtl->outgoing_args_size
7322      of stack frame are unused.  */
7323   if (ACCUMULATE_OUTGOING_ARGS
7324       && (!current_function_is_leaf || cfun->calls_alloca
7325           || ix86_current_function_calls_tls_descriptor))
7326     {
7327       offset += crtl->outgoing_args_size;
7328       frame->outgoing_arguments_size = crtl->outgoing_args_size;
7329     }
7330   else
7331     frame->outgoing_arguments_size = 0;
7332
7333   /* Align stack boundary.  Only needed if we're calling another function
7334      or using alloca.  */
7335   if (!current_function_is_leaf || cfun->calls_alloca
7336       || ix86_current_function_calls_tls_descriptor)
7337     frame->padding2 = ((offset + preferred_alignment - 1)
7338                        & -preferred_alignment) - offset;
7339   else
7340     frame->padding2 = 0;
7341
7342   offset += frame->padding2;
7343
7344   /* We've reached end of stack frame.  */
7345   frame->stack_pointer_offset = offset;
7346
7347   /* Size prologue needs to allocate.  */
7348   frame->to_allocate =
7349     (size + frame->padding1 + frame->padding2
7350      + frame->outgoing_arguments_size + frame->va_arg_size);
7351
7352   if ((!frame->to_allocate && frame->nregs <= 1)
7353       || (TARGET_64BIT && frame->to_allocate >= (HOST_WIDE_INT) 0x80000000))
7354     frame->save_regs_using_mov = false;
7355
7356   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && current_function_sp_is_unchanging
7357       && current_function_is_leaf
7358       && !ix86_current_function_calls_tls_descriptor)
7359     {
7360       frame->red_zone_size = frame->to_allocate;
7361       if (frame->save_regs_using_mov)
7362         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7363       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7364         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
7365     }
7366   else
7367     frame->red_zone_size = 0;
7368   frame->to_allocate -= frame->red_zone_size;
7369   frame->stack_pointer_offset -= frame->red_zone_size;
7370 #if 0
7371   fprintf (stderr, "\n");
7372   fprintf (stderr, "nregs: %ld\n", (long)frame->nregs);
7373   fprintf (stderr, "size: %ld\n", (long)size);
7374   fprintf (stderr, "alignment1: %ld\n", (long)stack_alignment_needed);
7375   fprintf (stderr, "padding1: %ld\n", (long)frame->padding1);
7376   fprintf (stderr, "va_arg: %ld\n", (long)frame->va_arg_size);
7377   fprintf (stderr, "padding2: %ld\n", (long)frame->padding2);
7378   fprintf (stderr, "to_allocate: %ld\n", (long)frame->to_allocate);
7379   fprintf (stderr, "red_zone_size: %ld\n", (long)frame->red_zone_size);
7380   fprintf (stderr, "frame_pointer_offset: %ld\n", (long)frame->frame_pointer_offset);
7381   fprintf (stderr, "hard_frame_pointer_offset: %ld\n",
7382            (long)frame->hard_frame_pointer_offset);
7383   fprintf (stderr, "stack_pointer_offset: %ld\n", (long)frame->stack_pointer_offset);
7384   fprintf (stderr, "current_function_is_leaf: %ld\n", (long)current_function_is_leaf);
7385   fprintf (stderr, "cfun->calls_alloca: %ld\n", (long)cfun->calls_alloca);
7386   fprintf (stderr, "x86_current_function_calls_tls_descriptor: %ld\n", (long)ix86_current_function_calls_tls_descriptor);
7387 #endif
7388 }
7389
7390 /* Emit code to save registers in the prologue.  */
7391
7392 static void
7393 ix86_emit_save_regs (void)
7394 {
7395   unsigned int regno;
7396   rtx insn;
7397
7398   for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0; )
7399     if (ix86_save_reg (regno, true))
7400       {
7401         insn = emit_insn (gen_push (gen_rtx_REG (Pmode, regno)));
7402         RTX_FRAME_RELATED_P (insn) = 1;
7403       }
7404 }
7405
7406 /* Emit code to save registers using MOV insns.  First register
7407    is restored from POINTER + OFFSET.  */
7408 static void
7409 ix86_emit_save_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7410 {
7411   unsigned int regno;
7412   rtx insn;
7413
7414   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7415     if (ix86_save_reg (regno, true))
7416       {
7417         insn = emit_move_insn (adjust_address (gen_rtx_MEM (Pmode, pointer),
7418                                                Pmode, offset),
7419                                gen_rtx_REG (Pmode, regno));
7420         RTX_FRAME_RELATED_P (insn) = 1;
7421         offset += UNITS_PER_WORD;
7422       }
7423 }
7424
7425 /* Expand prologue or epilogue stack adjustment.
7426    The pattern exist to put a dependency on all ebp-based memory accesses.
7427    STYLE should be negative if instructions should be marked as frame related,
7428    zero if %r11 register is live and cannot be freely used and positive
7429    otherwise.  */
7430
7431 static void
7432 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset, int style)
7433 {
7434   rtx insn;
7435
7436   if (! TARGET_64BIT)
7437     insn = emit_insn (gen_pro_epilogue_adjust_stack_1 (dest, src, offset));
7438   else if (x86_64_immediate_operand (offset, DImode))
7439     insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64 (dest, src, offset));
7440   else
7441     {
7442       rtx r11;
7443       /* r11 is used by indirect sibcall return as well, set before the
7444          epilogue and used after the epilogue.  ATM indirect sibcall
7445          shouldn't be used together with huge frame sizes in one
7446          function because of the frame_size check in sibcall.c.  */
7447       gcc_assert (style);
7448       r11 = gen_rtx_REG (DImode, R11_REG);
7449       insn = emit_insn (gen_rtx_SET (DImode, r11, offset));
7450       if (style < 0)
7451         RTX_FRAME_RELATED_P (insn) = 1;
7452       insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64_2 (dest, src, r11,
7453                                                                offset));
7454     }
7455   if (style < 0)
7456     RTX_FRAME_RELATED_P (insn) = 1;
7457 }
7458
7459 /* Find an available register to be used as dynamic realign argument
7460    pointer regsiter.  Such a register will be written in prologue and
7461    used in begin of body, so it must not be
7462         1. parameter passing register.
7463         2. GOT pointer.
7464    We reuse static-chain register if it is available.  Otherwise, we
7465    use DI for i386 and R13 for x86-64.  We chose R13 since it has
7466    shorter encoding.
7467
7468    Return: the regno of chosen register.  */
7469
7470 static unsigned int 
7471 find_drap_reg (void)
7472 {
7473   tree decl = cfun->decl;
7474
7475   if (TARGET_64BIT)
7476     {
7477       /* Use R13 for nested function or function need static chain.
7478          Since function with tail call may use any caller-saved
7479          registers in epilogue, DRAP must not use caller-saved
7480          register in such case.  */
7481       if ((decl_function_context (decl)
7482            && !DECL_NO_STATIC_CHAIN (decl))
7483           || crtl->tail_call_emit)
7484         return R13_REG;
7485
7486       return R10_REG;
7487     }
7488   else
7489     {
7490       /* Use DI for nested function or function need static chain.
7491          Since function with tail call may use any caller-saved
7492          registers in epilogue, DRAP must not use caller-saved
7493          register in such case.  */
7494       if ((decl_function_context (decl)
7495            && !DECL_NO_STATIC_CHAIN (decl))
7496           || crtl->tail_call_emit)
7497         return DI_REG;
7498     
7499       /* Reuse static chain register if it isn't used for parameter
7500          passing.  */
7501       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2
7502           && !lookup_attribute ("fastcall",
7503                                 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
7504         return CX_REG;
7505       else
7506         return DI_REG;
7507     }
7508 }
7509
7510 /* Update incoming stack boundary and estimated stack alignment.  */
7511
7512 static void
7513 ix86_update_stack_boundary (void)
7514 {
7515   /* Prefer the one specified at command line. */
7516   ix86_incoming_stack_boundary 
7517     = (ix86_user_incoming_stack_boundary
7518        ? ix86_user_incoming_stack_boundary
7519        : ix86_default_incoming_stack_boundary);
7520
7521   /* Incoming stack alignment can be changed on individual functions
7522      via force_align_arg_pointer attribute.  We use the smallest
7523      incoming stack boundary.  */
7524   if (ix86_incoming_stack_boundary > MIN_STACK_BOUNDARY
7525       && lookup_attribute (ix86_force_align_arg_pointer_string,
7526                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
7527     ix86_incoming_stack_boundary = MIN_STACK_BOUNDARY;
7528
7529   /* Stack at entrance of main is aligned by runtime.  We use the
7530      smallest incoming stack boundary. */
7531   if (ix86_incoming_stack_boundary > MAIN_STACK_BOUNDARY
7532       && DECL_NAME (current_function_decl)
7533       && MAIN_NAME_P (DECL_NAME (current_function_decl))
7534       && DECL_FILE_SCOPE_P (current_function_decl))
7535     ix86_incoming_stack_boundary = MAIN_STACK_BOUNDARY;
7536
7537   /* x86_64 vararg needs 16byte stack alignment for register save
7538      area.  */
7539   if (TARGET_64BIT
7540       && cfun->stdarg
7541       && crtl->stack_alignment_estimated < 128)
7542     crtl->stack_alignment_estimated = 128;
7543 }
7544
7545 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
7546    needed or an rtx for DRAP otherwise.  */
7547
7548 static rtx
7549 ix86_get_drap_rtx (void)
7550 {
7551   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
7552     crtl->need_drap = true;
7553
7554   if (stack_realign_drap)
7555     {
7556       /* Assign DRAP to vDRAP and returns vDRAP */
7557       unsigned int regno = find_drap_reg ();
7558       rtx drap_vreg;
7559       rtx arg_ptr;
7560       rtx seq, insn;
7561
7562       arg_ptr = gen_rtx_REG (Pmode, regno);
7563       crtl->drap_reg = arg_ptr;
7564
7565       start_sequence ();
7566       drap_vreg = copy_to_reg (arg_ptr);
7567       seq = get_insns ();
7568       end_sequence ();
7569       
7570       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
7571       RTX_FRAME_RELATED_P (insn) = 1;
7572       return drap_vreg;
7573     }
7574   else
7575     return NULL;
7576 }
7577
7578 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
7579
7580 static rtx
7581 ix86_internal_arg_pointer (void)
7582 {
7583   return virtual_incoming_args_rtx;
7584 }
7585
7586 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
7587    This is called from dwarf2out.c to emit call frame instructions
7588    for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
7589 static void
7590 ix86_dwarf_handle_frame_unspec (const char *label, rtx pattern, int index)
7591 {
7592   rtx unspec = SET_SRC (pattern);
7593   gcc_assert (GET_CODE (unspec) == UNSPEC);
7594
7595   switch (index)
7596     {
7597     case UNSPEC_REG_SAVE:
7598       dwarf2out_reg_save_reg (label, XVECEXP (unspec, 0, 0),
7599                               SET_DEST (pattern));
7600       break;
7601     case UNSPEC_DEF_CFA:
7602       dwarf2out_def_cfa (label, REGNO (SET_DEST (pattern)),
7603                          INTVAL (XVECEXP (unspec, 0, 0)));
7604       break;
7605     default:
7606       gcc_unreachable ();
7607     }
7608 }
7609
7610 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
7611    to be generated in correct form.  */
7612 static void 
7613 ix86_finalize_stack_realign_flags (void)
7614 {
7615   /* Check if stack realign is really needed after reload, and 
7616      stores result in cfun */
7617   unsigned int incoming_stack_boundary
7618     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
7619        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
7620   unsigned int stack_realign = (incoming_stack_boundary
7621                                 < (current_function_is_leaf
7622                                    ? crtl->max_used_stack_slot_alignment
7623                                    : crtl->stack_alignment_needed));
7624
7625   if (crtl->stack_realign_finalized)
7626     {
7627       /* After stack_realign_needed is finalized, we can't no longer
7628          change it.  */
7629       gcc_assert (crtl->stack_realign_needed == stack_realign);
7630     }
7631   else
7632     {
7633       crtl->stack_realign_needed = stack_realign;
7634       crtl->stack_realign_finalized = true;
7635     }
7636 }
7637
7638 /* Expand the prologue into a bunch of separate insns.  */
7639
7640 void
7641 ix86_expand_prologue (void)
7642 {
7643   rtx insn;
7644   bool pic_reg_used;
7645   struct ix86_frame frame;
7646   HOST_WIDE_INT allocate;
7647
7648   ix86_finalize_stack_realign_flags ();
7649
7650   /* DRAP should not coexist with stack_realign_fp */
7651   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
7652
7653   ix86_compute_frame_layout (&frame);
7654
7655   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
7656      of DRAP is needed and stack realignment is really needed after reload */
7657   if (crtl->drap_reg && crtl->stack_realign_needed)
7658     {
7659       rtx x, y;
7660       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
7661       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
7662                               ? 0 : UNITS_PER_WORD);
7663
7664       gcc_assert (stack_realign_drap);
7665
7666       /* Grab the argument pointer.  */
7667       x = plus_constant (stack_pointer_rtx, 
7668                          (UNITS_PER_WORD + param_ptr_offset));
7669       y = crtl->drap_reg;
7670
7671       /* Only need to push parameter pointer reg if it is caller
7672          saved reg */
7673       if (!call_used_regs[REGNO (crtl->drap_reg)])
7674         {
7675           /* Push arg pointer reg */
7676           insn = emit_insn (gen_push (y));
7677           RTX_FRAME_RELATED_P (insn) = 1;
7678         }
7679
7680       insn = emit_insn (gen_rtx_SET (VOIDmode, y, x));
7681       RTX_FRAME_RELATED_P (insn) = 1; 
7682
7683       /* Align the stack.  */
7684       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
7685                                            stack_pointer_rtx,
7686                                            GEN_INT (-align_bytes)));
7687       RTX_FRAME_RELATED_P (insn) = 1;
7688
7689       /* Replicate the return address on the stack so that return
7690          address can be reached via (argp - 1) slot.  This is needed
7691          to implement macro RETURN_ADDR_RTX and intrinsic function
7692          expand_builtin_return_addr etc.  */
7693       x = crtl->drap_reg;
7694       x = gen_frame_mem (Pmode,
7695                          plus_constant (x, -UNITS_PER_WORD));
7696       insn = emit_insn (gen_push (x));
7697       RTX_FRAME_RELATED_P (insn) = 1;
7698     }
7699
7700   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
7701      slower on all targets.  Also sdb doesn't like it.  */
7702
7703   if (frame_pointer_needed)
7704     {
7705       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
7706       RTX_FRAME_RELATED_P (insn) = 1;
7707
7708       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
7709       RTX_FRAME_RELATED_P (insn) = 1;
7710     }
7711
7712   if (stack_realign_fp)
7713     {
7714       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
7715       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
7716
7717       /* Align the stack.  */
7718       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
7719                                            stack_pointer_rtx,
7720                                            GEN_INT (-align_bytes)));
7721       RTX_FRAME_RELATED_P (insn) = 1;
7722     }
7723
7724   allocate = frame.to_allocate;
7725
7726   if (!frame.save_regs_using_mov)
7727     ix86_emit_save_regs ();
7728   else
7729     allocate += frame.nregs * UNITS_PER_WORD;
7730
7731   /* When using red zone we may start register saving before allocating
7732      the stack frame saving one cycle of the prologue. However I will
7733      avoid doing this if I am going to have to probe the stack since
7734      at least on x86_64 the stack probe can turn into a call that clobbers
7735      a red zone location */
7736   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && frame.save_regs_using_mov
7737       && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT))
7738     ix86_emit_save_regs_using_mov ((frame_pointer_needed
7739                                      && !crtl->stack_realign_needed) 
7740                                    ? hard_frame_pointer_rtx
7741                                    : stack_pointer_rtx,
7742                                    -frame.nregs * UNITS_PER_WORD);
7743
7744   if (allocate == 0)
7745     ;
7746   else if (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)
7747     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
7748                                GEN_INT (-allocate), -1);
7749   else
7750     {
7751       /* Only valid for Win32.  */
7752       rtx eax = gen_rtx_REG (Pmode, AX_REG);
7753       bool eax_live;
7754       rtx t;
7755
7756       gcc_assert (!TARGET_64BIT || cfun->machine->call_abi == MS_ABI);
7757
7758       if (cfun->machine->call_abi == MS_ABI)
7759         eax_live = false;
7760       else
7761         eax_live = ix86_eax_live_at_start_p ();
7762
7763       if (eax_live)
7764         {
7765           emit_insn (gen_push (eax));
7766           allocate -= UNITS_PER_WORD;
7767         }
7768
7769       emit_move_insn (eax, GEN_INT (allocate));
7770
7771       if (TARGET_64BIT)
7772         insn = gen_allocate_stack_worker_64 (eax);
7773       else
7774         insn = gen_allocate_stack_worker_32 (eax);
7775       insn = emit_insn (insn);
7776       RTX_FRAME_RELATED_P (insn) = 1;
7777       t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (-allocate));
7778       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
7779       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7780                                             t, REG_NOTES (insn));
7781
7782       if (eax_live)
7783         {
7784           if (frame_pointer_needed)
7785             t = plus_constant (hard_frame_pointer_rtx,
7786                                allocate
7787                                - frame.to_allocate
7788                                - frame.nregs * UNITS_PER_WORD);
7789           else
7790             t = plus_constant (stack_pointer_rtx, allocate);
7791           emit_move_insn (eax, gen_rtx_MEM (Pmode, t));
7792         }
7793     }
7794
7795   if (frame.save_regs_using_mov
7796       && !(!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
7797          && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)))
7798     {
7799       if (!frame_pointer_needed
7800           || !frame.to_allocate
7801           || crtl->stack_realign_needed)
7802         ix86_emit_save_regs_using_mov (stack_pointer_rtx,
7803                                        frame.to_allocate);
7804       else
7805         ix86_emit_save_regs_using_mov (hard_frame_pointer_rtx,
7806                                        -frame.nregs * UNITS_PER_WORD);
7807     }
7808
7809   pic_reg_used = false;
7810   if (pic_offset_table_rtx
7811       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
7812           || crtl->profile))
7813     {
7814       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
7815
7816       if (alt_pic_reg_used != INVALID_REGNUM)
7817         SET_REGNO (pic_offset_table_rtx, alt_pic_reg_used);
7818
7819       pic_reg_used = true;
7820     }
7821
7822   if (pic_reg_used)
7823     {
7824       if (TARGET_64BIT)
7825         {
7826           if (ix86_cmodel == CM_LARGE_PIC)
7827             {
7828               rtx tmp_reg = gen_rtx_REG (DImode, R11_REG);
7829               rtx label = gen_label_rtx ();
7830               emit_label (label);
7831               LABEL_PRESERVE_P (label) = 1;
7832               gcc_assert (REGNO (pic_offset_table_rtx) != REGNO (tmp_reg));
7833               insn = emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, label));
7834               insn = emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
7835               insn = emit_insn (gen_adddi3 (pic_offset_table_rtx,
7836                                             pic_offset_table_rtx, tmp_reg));
7837             }
7838           else
7839             insn = emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
7840         }
7841       else
7842         insn = emit_insn (gen_set_got (pic_offset_table_rtx));
7843     }
7844
7845   /* Prevent function calls from being scheduled before the call to mcount.
7846      In the pic_reg_used case, make sure that the got load isn't deleted.  */
7847   if (crtl->profile)
7848     {
7849       if (pic_reg_used)
7850         emit_insn (gen_prologue_use (pic_offset_table_rtx));
7851       emit_insn (gen_blockage ());
7852     }
7853
7854   if (crtl->drap_reg && !crtl->stack_realign_needed)
7855     {
7856       /* vDRAP is setup but after reload it turns out stack realign
7857          isn't necessary, here we will emit prologue to setup DRAP
7858          without stack realign adjustment */
7859       int drap_bp_offset = UNITS_PER_WORD * 2;
7860       rtx x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
7861       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, x));
7862     }
7863
7864   /* Emit cld instruction if stringops are used in the function.  */
7865   if (TARGET_CLD && ix86_current_function_needs_cld)
7866     emit_insn (gen_cld ());
7867 }
7868
7869 /* Emit code to restore saved registers using MOV insns.  First register
7870    is restored from POINTER + OFFSET.  */
7871 static void
7872 ix86_emit_restore_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
7873                                   int maybe_eh_return)
7874 {
7875   int regno;
7876   rtx base_address = gen_rtx_MEM (Pmode, pointer);
7877
7878   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7879     if (ix86_save_reg (regno, maybe_eh_return))
7880       {
7881         /* Ensure that adjust_address won't be forced to produce pointer
7882            out of range allowed by x86-64 instruction set.  */
7883         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
7884           {
7885             rtx r11;
7886
7887             r11 = gen_rtx_REG (DImode, R11_REG);
7888             emit_move_insn (r11, GEN_INT (offset));
7889             emit_insn (gen_adddi3 (r11, r11, pointer));
7890             base_address = gen_rtx_MEM (Pmode, r11);
7891             offset = 0;
7892           }
7893         emit_move_insn (gen_rtx_REG (Pmode, regno),
7894                         adjust_address (base_address, Pmode, offset));
7895         offset += UNITS_PER_WORD;
7896       }
7897 }
7898
7899 /* Restore function stack, frame, and registers.  */
7900
7901 void
7902 ix86_expand_epilogue (int style)
7903 {
7904   int regno;
7905   int sp_valid;
7906   struct ix86_frame frame;
7907   HOST_WIDE_INT offset;
7908
7909   ix86_finalize_stack_realign_flags ();
7910
7911  /* When stack is realigned, SP must be valid.  */
7912   sp_valid = (!frame_pointer_needed
7913               || current_function_sp_is_unchanging
7914               || stack_realign_fp);
7915
7916   ix86_compute_frame_layout (&frame);
7917
7918   /* Calculate start of saved registers relative to ebp.  Special care
7919      must be taken for the normal return case of a function using
7920      eh_return: the eax and edx registers are marked as saved, but not
7921      restored along this path.  */
7922   offset = frame.nregs;
7923   if (crtl->calls_eh_return && style != 2)
7924     offset -= 2;
7925   offset *= -UNITS_PER_WORD;
7926
7927   /* If we're only restoring one register and sp is not valid then
7928      using a move instruction to restore the register since it's
7929      less work than reloading sp and popping the register.
7930
7931      The default code result in stack adjustment using add/lea instruction,
7932      while this code results in LEAVE instruction (or discrete equivalent),
7933      so it is profitable in some other cases as well.  Especially when there
7934      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
7935      and there is exactly one register to pop. This heuristic may need some
7936      tuning in future.  */
7937   if ((!sp_valid && frame.nregs <= 1)
7938       || (TARGET_EPILOGUE_USING_MOVE
7939           && cfun->machine->use_fast_prologue_epilogue
7940           && (frame.nregs > 1 || frame.to_allocate))
7941       || (frame_pointer_needed && !frame.nregs && frame.to_allocate)
7942       || (frame_pointer_needed && TARGET_USE_LEAVE
7943           && cfun->machine->use_fast_prologue_epilogue
7944           && frame.nregs == 1)
7945       || crtl->calls_eh_return)
7946     {
7947       /* Restore registers.  We can use ebp or esp to address the memory
7948          locations.  If both are available, default to ebp, since offsets
7949          are known to be small.  Only exception is esp pointing directly
7950          to the end of block of saved registers, where we may simplify
7951          addressing mode.  
7952
7953          If we are realigning stack with bp and sp, regs restore can't
7954          be addressed by bp. sp must be used instead.  */
7955
7956       if (!frame_pointer_needed
7957           || (sp_valid && !frame.to_allocate) 
7958           || stack_realign_fp)
7959         ix86_emit_restore_regs_using_mov (stack_pointer_rtx,
7960                                           frame.to_allocate, style == 2);
7961       else
7962         ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx,
7963                                           offset, style == 2);
7964
7965       /* eh_return epilogues need %ecx added to the stack pointer.  */
7966       if (style == 2)
7967         {
7968           rtx tmp, sa = EH_RETURN_STACKADJ_RTX;
7969
7970           /* Stack align doesn't work with eh_return.  */
7971           gcc_assert (!crtl->stack_realign_needed);
7972
7973           if (frame_pointer_needed)
7974             {
7975               tmp = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
7976               tmp = plus_constant (tmp, UNITS_PER_WORD);
7977               emit_insn (gen_rtx_SET (VOIDmode, sa, tmp));
7978
7979               tmp = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
7980               emit_move_insn (hard_frame_pointer_rtx, tmp);
7981
7982               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
7983                                          const0_rtx, style);
7984             }
7985           else
7986             {
7987               tmp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
7988               tmp = plus_constant (tmp, (frame.to_allocate
7989                                          + frame.nregs * UNITS_PER_WORD));
7990               emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp));
7991             }
7992         }
7993       else if (!frame_pointer_needed)
7994         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
7995                                    GEN_INT (frame.to_allocate
7996                                             + frame.nregs * UNITS_PER_WORD),
7997                                    style);
7998       /* If not an i386, mov & pop is faster than "leave".  */
7999       else if (TARGET_USE_LEAVE || optimize_size
8000                || !cfun->machine->use_fast_prologue_epilogue)
8001         emit_insn ((*ix86_gen_leave) ());
8002       else
8003         {
8004           pro_epilogue_adjust_stack (stack_pointer_rtx,
8005                                      hard_frame_pointer_rtx,
8006                                      const0_rtx, style);
8007
8008           emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8009         }
8010     }
8011   else
8012     {
8013       /* First step is to deallocate the stack frame so that we can
8014          pop the registers.
8015
8016          If we realign stack with frame pointer, then stack pointer
8017          won't be able to recover via lea $offset(%bp), %sp, because
8018          there is a padding area between bp and sp for realign. 
8019          "add $to_allocate, %sp" must be used instead.  */
8020       if (!sp_valid)
8021         {
8022           gcc_assert (frame_pointer_needed);
8023           gcc_assert (!stack_realign_fp);
8024           pro_epilogue_adjust_stack (stack_pointer_rtx,
8025                                      hard_frame_pointer_rtx,
8026                                      GEN_INT (offset), style);
8027         }
8028       else if (frame.to_allocate)
8029         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8030                                    GEN_INT (frame.to_allocate), style);
8031
8032       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8033         if (ix86_save_reg (regno, false))
8034           emit_insn ((*ix86_gen_pop1) (gen_rtx_REG (Pmode, regno)));
8035       if (frame_pointer_needed)
8036         {
8037           /* Leave results in shorter dependency chains on CPUs that are
8038              able to grok it fast.  */
8039           if (TARGET_USE_LEAVE)
8040             emit_insn ((*ix86_gen_leave) ());
8041           else
8042             {
8043               /* For stack realigned really happens, recover stack 
8044                  pointer to hard frame pointer is a must, if not using 
8045                  leave.  */
8046               if (stack_realign_fp)
8047                 pro_epilogue_adjust_stack (stack_pointer_rtx,
8048                                            hard_frame_pointer_rtx,
8049                                            const0_rtx, style);
8050               emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8051             }
8052         }
8053     }
8054
8055   if (crtl->drap_reg && crtl->stack_realign_needed)
8056     {
8057       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8058                               ? 0 : UNITS_PER_WORD);
8059       gcc_assert (stack_realign_drap);
8060       emit_insn ((*ix86_gen_add3) (stack_pointer_rtx,
8061                                    crtl->drap_reg,
8062                                    GEN_INT (-(UNITS_PER_WORD
8063                                               + param_ptr_offset))));
8064       if (!call_used_regs[REGNO (crtl->drap_reg)])
8065         emit_insn ((*ix86_gen_pop1) (crtl->drap_reg));
8066       
8067     }
8068
8069   /* Sibcall epilogues don't want a return instruction.  */
8070   if (style == 0)
8071     return;
8072
8073   if (crtl->args.pops_args && crtl->args.size)
8074     {
8075       rtx popc = GEN_INT (crtl->args.pops_args);
8076
8077       /* i386 can only pop 64K bytes.  If asked to pop more, pop
8078          return address, do explicit add, and jump indirectly to the
8079          caller.  */
8080
8081       if (crtl->args.pops_args >= 65536)
8082         {
8083           rtx ecx = gen_rtx_REG (SImode, CX_REG);
8084
8085           /* There is no "pascal" calling convention in any 64bit ABI.  */
8086           gcc_assert (!TARGET_64BIT);
8087
8088           emit_insn (gen_popsi1 (ecx));
8089           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc));
8090           emit_jump_insn (gen_return_indirect_internal (ecx));
8091         }
8092       else
8093         emit_jump_insn (gen_return_pop_internal (popc));
8094     }
8095   else
8096     emit_jump_insn (gen_return_internal ());
8097 }
8098
8099 /* Reset from the function's potential modifications.  */
8100
8101 static void
8102 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
8103                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
8104 {
8105   if (pic_offset_table_rtx)
8106     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
8107 #if TARGET_MACHO
8108   /* Mach-O doesn't support labels at the end of objects, so if
8109      it looks like we might want one, insert a NOP.  */
8110   {
8111     rtx insn = get_last_insn ();
8112     while (insn
8113            && NOTE_P (insn)
8114            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
8115       insn = PREV_INSN (insn);
8116     if (insn
8117         && (LABEL_P (insn)
8118             || (NOTE_P (insn)
8119                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
8120       fputs ("\tnop\n", file);
8121   }
8122 #endif
8123
8124 }
8125 \f
8126 /* Extract the parts of an RTL expression that is a valid memory address
8127    for an instruction.  Return 0 if the structure of the address is
8128    grossly off.  Return -1 if the address contains ASHIFT, so it is not
8129    strictly valid, but still used for computing length of lea instruction.  */
8130
8131 int
8132 ix86_decompose_address (rtx addr, struct ix86_address *out)
8133 {
8134   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
8135   rtx base_reg, index_reg;
8136   HOST_WIDE_INT scale = 1;
8137   rtx scale_rtx = NULL_RTX;
8138   int retval = 1;
8139   enum ix86_address_seg seg = SEG_DEFAULT;
8140
8141   if (REG_P (addr) || GET_CODE (addr) == SUBREG)
8142     base = addr;
8143   else if (GET_CODE (addr) == PLUS)
8144     {
8145       rtx addends[4], op;
8146       int n = 0, i;
8147
8148       op = addr;
8149       do
8150         {
8151           if (n >= 4)
8152             return 0;
8153           addends[n++] = XEXP (op, 1);
8154           op = XEXP (op, 0);
8155         }
8156       while (GET_CODE (op) == PLUS);
8157       if (n >= 4)
8158         return 0;
8159       addends[n] = op;
8160
8161       for (i = n; i >= 0; --i)
8162         {
8163           op = addends[i];
8164           switch (GET_CODE (op))
8165             {
8166             case MULT:
8167               if (index)
8168                 return 0;
8169               index = XEXP (op, 0);
8170               scale_rtx = XEXP (op, 1);
8171               break;
8172
8173             case UNSPEC:
8174               if (XINT (op, 1) == UNSPEC_TP
8175                   && TARGET_TLS_DIRECT_SEG_REFS
8176                   && seg == SEG_DEFAULT)
8177                 seg = TARGET_64BIT ? SEG_FS : SEG_GS;
8178               else
8179                 return 0;
8180               break;
8181
8182             case REG:
8183             case SUBREG:
8184               if (!base)
8185                 base = op;
8186               else if (!index)
8187                 index = op;
8188               else
8189                 return 0;
8190               break;
8191
8192             case CONST:
8193             case CONST_INT:
8194             case SYMBOL_REF:
8195             case LABEL_REF:
8196               if (disp)
8197                 return 0;
8198               disp = op;
8199               break;
8200
8201             default:
8202               return 0;
8203             }
8204         }
8205     }
8206   else if (GET_CODE (addr) == MULT)
8207     {
8208       index = XEXP (addr, 0);           /* index*scale */
8209       scale_rtx = XEXP (addr, 1);
8210     }
8211   else if (GET_CODE (addr) == ASHIFT)
8212     {
8213       rtx tmp;
8214
8215       /* We're called for lea too, which implements ashift on occasion.  */
8216       index = XEXP (addr, 0);
8217       tmp = XEXP (addr, 1);
8218       if (!CONST_INT_P (tmp))
8219         return 0;
8220       scale = INTVAL (tmp);
8221       if ((unsigned HOST_WIDE_INT) scale > 3)
8222         return 0;
8223       scale = 1 << scale;
8224       retval = -1;
8225     }
8226   else
8227     disp = addr;                        /* displacement */
8228
8229   /* Extract the integral value of scale.  */
8230   if (scale_rtx)
8231     {
8232       if (!CONST_INT_P (scale_rtx))
8233         return 0;
8234       scale = INTVAL (scale_rtx);
8235     }
8236
8237   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
8238   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
8239
8240   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
8241   if (base_reg && index_reg && scale == 1
8242       && (index_reg == arg_pointer_rtx
8243           || index_reg == frame_pointer_rtx
8244           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
8245     {
8246       rtx tmp;
8247       tmp = base, base = index, index = tmp;
8248       tmp = base_reg, base_reg = index_reg, index_reg = tmp;
8249     }
8250
8251   /* Special case: %ebp cannot be encoded as a base without a displacement.  */
8252   if ((base_reg == hard_frame_pointer_rtx
8253        || base_reg == frame_pointer_rtx
8254        || base_reg == arg_pointer_rtx) && !disp)
8255     disp = const0_rtx;
8256
8257   /* Special case: on K6, [%esi] makes the instruction vector decoded.
8258      Avoid this by transforming to [%esi+0].  */
8259   if (TARGET_K6 && !optimize_size
8260       && base_reg && !index_reg && !disp
8261       && REG_P (base_reg)
8262       && REGNO_REG_CLASS (REGNO (base_reg)) == SIREG)
8263     disp = const0_rtx;
8264
8265   /* Special case: encode reg+reg instead of reg*2.  */
8266   if (!base && index && scale && scale == 2)
8267     base = index, base_reg = index_reg, scale = 1;
8268
8269   /* Special case: scaling cannot be encoded without base or displacement.  */
8270   if (!base && !disp && index && scale != 1)
8271     disp = const0_rtx;
8272
8273   out->base = base;
8274   out->index = index;
8275   out->disp = disp;
8276   out->scale = scale;
8277   out->seg = seg;
8278
8279   return retval;
8280 }
8281 \f
8282 /* Return cost of the memory address x.
8283    For i386, it is better to use a complex address than let gcc copy
8284    the address into a reg and make a new pseudo.  But not if the address
8285    requires to two regs - that would mean more pseudos with longer
8286    lifetimes.  */
8287 static int
8288 ix86_address_cost (rtx x)
8289 {
8290   struct ix86_address parts;
8291   int cost = 1;
8292   int ok = ix86_decompose_address (x, &parts);
8293
8294   gcc_assert (ok);
8295
8296   if (parts.base && GET_CODE (parts.base) == SUBREG)
8297     parts.base = SUBREG_REG (parts.base);
8298   if (parts.index && GET_CODE (parts.index) == SUBREG)
8299     parts.index = SUBREG_REG (parts.index);
8300
8301   /* Attempt to minimize number of registers in the address.  */
8302   if ((parts.base
8303        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
8304       || (parts.index
8305           && (!REG_P (parts.index)
8306               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
8307     cost++;
8308
8309   if (parts.base
8310       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
8311       && parts.index
8312       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
8313       && parts.base != parts.index)
8314     cost++;
8315
8316   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
8317      since it's predecode logic can't detect the length of instructions
8318      and it degenerates to vector decoded.  Increase cost of such
8319      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
8320      to split such addresses or even refuse such addresses at all.
8321
8322      Following addressing modes are affected:
8323       [base+scale*index]
8324       [scale*index+disp]
8325       [base+index]
8326
8327      The first and last case  may be avoidable by explicitly coding the zero in
8328      memory address, but I don't have AMD-K6 machine handy to check this
8329      theory.  */
8330
8331   if (TARGET_K6
8332       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
8333           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
8334           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
8335     cost += 10;
8336
8337   return cost;
8338 }
8339 \f
8340 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
8341    this is used for to form addresses to local data when -fPIC is in
8342    use.  */
8343
8344 static bool
8345 darwin_local_data_pic (rtx disp)
8346 {
8347   if (GET_CODE (disp) == MINUS)
8348     {
8349       if (GET_CODE (XEXP (disp, 0)) == LABEL_REF
8350           || GET_CODE (XEXP (disp, 0)) == SYMBOL_REF)
8351         if (GET_CODE (XEXP (disp, 1)) == SYMBOL_REF)
8352           {
8353             const char *sym_name = XSTR (XEXP (disp, 1), 0);
8354             if (! strcmp (sym_name, "<pic base>"))
8355               return true;
8356           }
8357     }
8358
8359   return false;
8360 }
8361
8362 /* Determine if a given RTX is a valid constant.  We already know this
8363    satisfies CONSTANT_P.  */
8364
8365 bool
8366 legitimate_constant_p (rtx x)
8367 {
8368   switch (GET_CODE (x))
8369     {
8370     case CONST:
8371       x = XEXP (x, 0);
8372
8373       if (GET_CODE (x) == PLUS)
8374         {
8375           if (!CONST_INT_P (XEXP (x, 1)))
8376             return false;
8377           x = XEXP (x, 0);
8378         }
8379
8380       if (TARGET_MACHO && darwin_local_data_pic (x))
8381         return true;
8382
8383       /* Only some unspecs are valid as "constants".  */
8384       if (GET_CODE (x) == UNSPEC)
8385         switch (XINT (x, 1))
8386           {
8387           case UNSPEC_GOT:
8388           case UNSPEC_GOTOFF:
8389           case UNSPEC_PLTOFF:
8390             return TARGET_64BIT;
8391           case UNSPEC_TPOFF:
8392           case UNSPEC_NTPOFF:
8393             x = XVECEXP (x, 0, 0);
8394             return (GET_CODE (x) == SYMBOL_REF
8395                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8396           case UNSPEC_DTPOFF:
8397             x = XVECEXP (x, 0, 0);
8398             return (GET_CODE (x) == SYMBOL_REF
8399                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
8400           default:
8401             return false;
8402           }
8403
8404       /* We must have drilled down to a symbol.  */
8405       if (GET_CODE (x) == LABEL_REF)
8406         return true;
8407       if (GET_CODE (x) != SYMBOL_REF)
8408         return false;
8409       /* FALLTHRU */
8410
8411     case SYMBOL_REF:
8412       /* TLS symbols are never valid.  */
8413       if (SYMBOL_REF_TLS_MODEL (x))
8414         return false;
8415
8416       /* DLLIMPORT symbols are never valid.  */
8417       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8418           && SYMBOL_REF_DLLIMPORT_P (x))
8419         return false;
8420       break;
8421
8422     case CONST_DOUBLE:
8423       if (GET_MODE (x) == TImode
8424           && x != CONST0_RTX (TImode)
8425           && !TARGET_64BIT)
8426         return false;
8427       break;
8428
8429     case CONST_VECTOR:
8430       if (x == CONST0_RTX (GET_MODE (x)))
8431         return true;
8432       return false;
8433
8434     default:
8435       break;
8436     }
8437
8438   /* Otherwise we handle everything else in the move patterns.  */
8439   return true;
8440 }
8441
8442 /* Determine if it's legal to put X into the constant pool.  This
8443    is not possible for the address of thread-local symbols, which
8444    is checked above.  */
8445
8446 static bool
8447 ix86_cannot_force_const_mem (rtx x)
8448 {
8449   /* We can always put integral constants and vectors in memory.  */
8450   switch (GET_CODE (x))
8451     {
8452     case CONST_INT:
8453     case CONST_DOUBLE:
8454     case CONST_VECTOR:
8455       return false;
8456
8457     default:
8458       break;
8459     }
8460   return !legitimate_constant_p (x);
8461 }
8462
8463 /* Determine if a given RTX is a valid constant address.  */
8464
8465 bool
8466 constant_address_p (rtx x)
8467 {
8468   return CONSTANT_P (x) && legitimate_address_p (Pmode, x, 1);
8469 }
8470
8471 /* Nonzero if the constant value X is a legitimate general operand
8472    when generating PIC code.  It is given that flag_pic is on and
8473    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
8474
8475 bool
8476 legitimate_pic_operand_p (rtx x)
8477 {
8478   rtx inner;
8479
8480   switch (GET_CODE (x))
8481     {
8482     case CONST:
8483       inner = XEXP (x, 0);
8484       if (GET_CODE (inner) == PLUS
8485           && CONST_INT_P (XEXP (inner, 1)))
8486         inner = XEXP (inner, 0);
8487
8488       /* Only some unspecs are valid as "constants".  */
8489       if (GET_CODE (inner) == UNSPEC)
8490         switch (XINT (inner, 1))
8491           {
8492           case UNSPEC_GOT:
8493           case UNSPEC_GOTOFF:
8494           case UNSPEC_PLTOFF:
8495             return TARGET_64BIT;
8496           case UNSPEC_TPOFF:
8497             x = XVECEXP (inner, 0, 0);
8498             return (GET_CODE (x) == SYMBOL_REF
8499                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8500           default:
8501             return false;
8502           }
8503       /* FALLTHRU */
8504
8505     case SYMBOL_REF:
8506     case LABEL_REF:
8507       return legitimate_pic_address_disp_p (x);
8508
8509     default:
8510       return true;
8511     }
8512 }
8513
8514 /* Determine if a given CONST RTX is a valid memory displacement
8515    in PIC mode.  */
8516
8517 int
8518 legitimate_pic_address_disp_p (rtx disp)
8519 {
8520   bool saw_plus;
8521
8522   /* In 64bit mode we can allow direct addresses of symbols and labels
8523      when they are not dynamic symbols.  */
8524   if (TARGET_64BIT)
8525     {
8526       rtx op0 = disp, op1;
8527
8528       switch (GET_CODE (disp))
8529         {
8530         case LABEL_REF:
8531           return true;
8532
8533         case CONST:
8534           if (GET_CODE (XEXP (disp, 0)) != PLUS)
8535             break;
8536           op0 = XEXP (XEXP (disp, 0), 0);
8537           op1 = XEXP (XEXP (disp, 0), 1);
8538           if (!CONST_INT_P (op1)
8539               || INTVAL (op1) >= 16*1024*1024
8540               || INTVAL (op1) < -16*1024*1024)
8541             break;
8542           if (GET_CODE (op0) == LABEL_REF)
8543             return true;
8544           if (GET_CODE (op0) != SYMBOL_REF)
8545             break;
8546           /* FALLTHRU */
8547
8548         case SYMBOL_REF:
8549           /* TLS references should always be enclosed in UNSPEC.  */
8550           if (SYMBOL_REF_TLS_MODEL (op0))
8551             return false;
8552           if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0)
8553               && ix86_cmodel != CM_LARGE_PIC)
8554             return true;
8555           break;
8556
8557         default:
8558           break;
8559         }
8560     }
8561   if (GET_CODE (disp) != CONST)
8562     return 0;
8563   disp = XEXP (disp, 0);
8564
8565   if (TARGET_64BIT)
8566     {
8567       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
8568          of GOT tables.  We should not need these anyway.  */
8569       if (GET_CODE (disp) != UNSPEC
8570           || (XINT (disp, 1) != UNSPEC_GOTPCREL
8571               && XINT (disp, 1) != UNSPEC_GOTOFF
8572               && XINT (disp, 1) != UNSPEC_PLTOFF))
8573         return 0;
8574
8575       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
8576           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
8577         return 0;
8578       return 1;
8579     }
8580
8581   saw_plus = false;
8582   if (GET_CODE (disp) == PLUS)
8583     {
8584       if (!CONST_INT_P (XEXP (disp, 1)))
8585         return 0;
8586       disp = XEXP (disp, 0);
8587       saw_plus = true;
8588     }
8589
8590   if (TARGET_MACHO && darwin_local_data_pic (disp))
8591     return 1;
8592
8593   if (GET_CODE (disp) != UNSPEC)
8594     return 0;
8595
8596   switch (XINT (disp, 1))
8597     {
8598     case UNSPEC_GOT:
8599       if (saw_plus)
8600         return false;
8601       /* We need to check for both symbols and labels because VxWorks loads
8602          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
8603          details.  */
8604       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
8605               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
8606     case UNSPEC_GOTOFF:
8607       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
8608          While ABI specify also 32bit relocation but we don't produce it in
8609          small PIC model at all.  */
8610       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
8611            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
8612           && !TARGET_64BIT)
8613         return gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
8614       return false;
8615     case UNSPEC_GOTTPOFF:
8616     case UNSPEC_GOTNTPOFF:
8617     case UNSPEC_INDNTPOFF:
8618       if (saw_plus)
8619         return false;
8620       disp = XVECEXP (disp, 0, 0);
8621       return (GET_CODE (disp) == SYMBOL_REF
8622               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
8623     case UNSPEC_NTPOFF:
8624       disp = XVECEXP (disp, 0, 0);
8625       return (GET_CODE (disp) == SYMBOL_REF
8626               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
8627     case UNSPEC_DTPOFF:
8628       disp = XVECEXP (disp, 0, 0);
8629       return (GET_CODE (disp) == SYMBOL_REF
8630               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
8631     }
8632
8633   return 0;
8634 }
8635
8636 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid
8637    memory address for an instruction.  The MODE argument is the machine mode
8638    for the MEM expression that wants to use this address.
8639
8640    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
8641    convert common non-canonical forms to canonical form so that they will
8642    be recognized.  */
8643
8644 int
8645 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
8646                       rtx addr, int strict)
8647 {
8648   struct ix86_address parts;
8649   rtx base, index, disp;
8650   HOST_WIDE_INT scale;
8651   const char *reason = NULL;
8652   rtx reason_rtx = NULL_RTX;
8653
8654   if (ix86_decompose_address (addr, &parts) <= 0)
8655     {
8656       reason = "decomposition failed";
8657       goto report_error;
8658     }
8659
8660   base = parts.base;
8661   index = parts.index;
8662   disp = parts.disp;
8663   scale = parts.scale;
8664
8665   /* Validate base register.
8666
8667      Don't allow SUBREG's that span more than a word here.  It can lead to spill
8668      failures when the base is one word out of a two word structure, which is
8669      represented internally as a DImode int.  */
8670
8671   if (base)
8672     {
8673       rtx reg;
8674       reason_rtx = base;
8675
8676       if (REG_P (base))
8677         reg = base;
8678       else if (GET_CODE (base) == SUBREG
8679                && REG_P (SUBREG_REG (base))
8680                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (base)))
8681                   <= UNITS_PER_WORD)
8682         reg = SUBREG_REG (base);
8683       else
8684         {
8685           reason = "base is not a register";
8686           goto report_error;
8687         }
8688
8689       if (GET_MODE (base) != Pmode)
8690         {
8691           reason = "base is not in Pmode";
8692           goto report_error;
8693         }
8694
8695       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
8696           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
8697         {
8698           reason = "base is not valid";
8699           goto report_error;
8700         }
8701     }
8702
8703   /* Validate index register.
8704
8705      Don't allow SUBREG's that span more than a word here -- same as above.  */
8706
8707   if (index)
8708     {
8709       rtx reg;
8710       reason_rtx = index;
8711
8712       if (REG_P (index))
8713         reg = index;
8714       else if (GET_CODE (index) == SUBREG
8715                && REG_P (SUBREG_REG (index))
8716                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (index)))
8717                   <= UNITS_PER_WORD)
8718         reg = SUBREG_REG (index);
8719       else
8720         {
8721           reason = "index is not a register";
8722           goto report_error;
8723         }
8724
8725       if (GET_MODE (index) != Pmode)
8726         {
8727           reason = "index is not in Pmode";
8728           goto report_error;
8729         }
8730
8731       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
8732           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
8733         {
8734           reason = "index is not valid";
8735           goto report_error;
8736         }
8737     }
8738
8739   /* Validate scale factor.  */
8740   if (scale != 1)
8741     {
8742       reason_rtx = GEN_INT (scale);
8743       if (!index)
8744         {
8745           reason = "scale without index";
8746           goto report_error;
8747         }
8748
8749       if (scale != 2 && scale != 4 && scale != 8)
8750         {
8751           reason = "scale is not a valid multiplier";
8752           goto report_error;
8753         }
8754     }
8755
8756   /* Validate displacement.  */
8757   if (disp)
8758     {
8759       reason_rtx = disp;
8760
8761       if (GET_CODE (disp) == CONST
8762           && GET_CODE (XEXP (disp, 0)) == UNSPEC)
8763         switch (XINT (XEXP (disp, 0), 1))
8764           {
8765           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
8766              used.  While ABI specify also 32bit relocations, we don't produce
8767              them at all and use IP relative instead.  */
8768           case UNSPEC_GOT:
8769           case UNSPEC_GOTOFF:
8770             gcc_assert (flag_pic);
8771             if (!TARGET_64BIT)
8772               goto is_legitimate_pic;
8773             reason = "64bit address unspec";
8774             goto report_error;
8775
8776           case UNSPEC_GOTPCREL:
8777             gcc_assert (flag_pic);
8778             goto is_legitimate_pic;
8779
8780           case UNSPEC_GOTTPOFF:
8781           case UNSPEC_GOTNTPOFF:
8782           case UNSPEC_INDNTPOFF:
8783           case UNSPEC_NTPOFF:
8784           case UNSPEC_DTPOFF:
8785             break;
8786
8787           default:
8788             reason = "invalid address unspec";
8789             goto report_error;
8790           }
8791
8792       else if (SYMBOLIC_CONST (disp)
8793                && (flag_pic
8794                    || (TARGET_MACHO
8795 #if TARGET_MACHO
8796                        && MACHOPIC_INDIRECT
8797                        && !machopic_operand_p (disp)
8798 #endif
8799                )))
8800         {
8801
8802         is_legitimate_pic:
8803           if (TARGET_64BIT && (index || base))
8804             {
8805               /* foo@dtpoff(%rX) is ok.  */
8806               if (GET_CODE (disp) != CONST
8807                   || GET_CODE (XEXP (disp, 0)) != PLUS
8808                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
8809                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
8810                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
8811                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
8812                 {
8813                   reason = "non-constant pic memory reference";
8814                   goto report_error;
8815                 }
8816             }
8817           else if (! legitimate_pic_address_disp_p (disp))
8818             {
8819               reason = "displacement is an invalid pic construct";
8820               goto report_error;
8821             }
8822
8823           /* This code used to verify that a symbolic pic displacement
8824              includes the pic_offset_table_rtx register.
8825
8826              While this is good idea, unfortunately these constructs may
8827              be created by "adds using lea" optimization for incorrect
8828              code like:
8829
8830              int a;
8831              int foo(int i)
8832                {
8833                  return *(&a+i);
8834                }
8835
8836              This code is nonsensical, but results in addressing
8837              GOT table with pic_offset_table_rtx base.  We can't
8838              just refuse it easily, since it gets matched by
8839              "addsi3" pattern, that later gets split to lea in the
8840              case output register differs from input.  While this
8841              can be handled by separate addsi pattern for this case
8842              that never results in lea, this seems to be easier and
8843              correct fix for crash to disable this test.  */
8844         }
8845       else if (GET_CODE (disp) != LABEL_REF
8846                && !CONST_INT_P (disp)
8847                && (GET_CODE (disp) != CONST
8848                    || !legitimate_constant_p (disp))
8849                && (GET_CODE (disp) != SYMBOL_REF
8850                    || !legitimate_constant_p (disp)))
8851         {
8852           reason = "displacement is not constant";
8853           goto report_error;
8854         }
8855       else if (TARGET_64BIT
8856                && !x86_64_immediate_operand (disp, VOIDmode))
8857         {
8858           reason = "displacement is out of range";
8859           goto report_error;
8860         }
8861     }
8862
8863   /* Everything looks valid.  */
8864   return TRUE;
8865
8866  report_error:
8867   return FALSE;
8868 }
8869 \f
8870 /* Return a unique alias set for the GOT.  */
8871
8872 static alias_set_type
8873 ix86_GOT_alias_set (void)
8874 {
8875   static alias_set_type set = -1;
8876   if (set == -1)
8877     set = new_alias_set ();
8878   return set;
8879 }
8880
8881 /* Return a legitimate reference for ORIG (an address) using the
8882    register REG.  If REG is 0, a new pseudo is generated.
8883
8884    There are two types of references that must be handled:
8885
8886    1. Global data references must load the address from the GOT, via
8887       the PIC reg.  An insn is emitted to do this load, and the reg is
8888       returned.
8889
8890    2. Static data references, constant pool addresses, and code labels
8891       compute the address as an offset from the GOT, whose base is in
8892       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
8893       differentiate them from global data objects.  The returned
8894       address is the PIC reg + an unspec constant.
8895
8896    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
8897    reg also appears in the address.  */
8898
8899 static rtx
8900 legitimize_pic_address (rtx orig, rtx reg)
8901 {
8902   rtx addr = orig;
8903   rtx new_rtx = orig;
8904   rtx base;
8905
8906 #if TARGET_MACHO
8907   if (TARGET_MACHO && !TARGET_64BIT)
8908     {
8909       if (reg == 0)
8910         reg = gen_reg_rtx (Pmode);
8911       /* Use the generic Mach-O PIC machinery.  */
8912       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
8913     }
8914 #endif
8915
8916   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
8917     new_rtx = addr;
8918   else if (TARGET_64BIT
8919            && ix86_cmodel != CM_SMALL_PIC
8920            && gotoff_operand (addr, Pmode))
8921     {
8922       rtx tmpreg;
8923       /* This symbol may be referenced via a displacement from the PIC
8924          base address (@GOTOFF).  */
8925
8926       if (reload_in_progress)
8927         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
8928       if (GET_CODE (addr) == CONST)
8929         addr = XEXP (addr, 0);
8930       if (GET_CODE (addr) == PLUS)
8931           {
8932             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
8933                                       UNSPEC_GOTOFF);
8934             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
8935           }
8936         else
8937           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
8938       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
8939       if (!reg)
8940         tmpreg = gen_reg_rtx (Pmode);
8941       else
8942         tmpreg = reg;
8943       emit_move_insn (tmpreg, new_rtx);
8944
8945       if (reg != 0)
8946         {
8947           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
8948                                          tmpreg, 1, OPTAB_DIRECT);
8949           new_rtx = reg;
8950         }
8951       else new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
8952     }
8953   else if (!TARGET_64BIT && gotoff_operand (addr, Pmode))
8954     {
8955       /* This symbol may be referenced via a displacement from the PIC
8956          base address (@GOTOFF).  */
8957
8958       if (reload_in_progress)
8959         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
8960       if (GET_CODE (addr) == CONST)
8961         addr = XEXP (addr, 0);
8962       if (GET_CODE (addr) == PLUS)
8963           {
8964             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
8965                                       UNSPEC_GOTOFF);
8966             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
8967           }
8968         else
8969           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
8970       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
8971       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
8972
8973       if (reg != 0)
8974         {
8975           emit_move_insn (reg, new_rtx);
8976           new_rtx = reg;
8977         }
8978     }
8979   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
8980            /* We can't use @GOTOFF for text labels on VxWorks;
8981               see gotoff_operand.  */
8982            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
8983     {
8984       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
8985         {
8986           if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
8987             return legitimize_dllimport_symbol (addr, true);
8988           if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
8989               && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
8990               && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
8991             {
8992               rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), true);
8993               return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
8994             }
8995         }
8996
8997       if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
8998         {
8999           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
9000           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9001           new_rtx = gen_const_mem (Pmode, new_rtx);
9002           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9003
9004           if (reg == 0)
9005             reg = gen_reg_rtx (Pmode);
9006           /* Use directly gen_movsi, otherwise the address is loaded
9007              into register for CSE.  We don't want to CSE this addresses,
9008              instead we CSE addresses from the GOT table, so skip this.  */
9009           emit_insn (gen_movsi (reg, new_rtx));
9010           new_rtx = reg;
9011         }
9012       else
9013         {
9014           /* This symbol must be referenced via a load from the
9015              Global Offset Table (@GOT).  */
9016
9017           if (reload_in_progress)
9018             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9019           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
9020           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9021           if (TARGET_64BIT)
9022             new_rtx = force_reg (Pmode, new_rtx);
9023           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9024           new_rtx = gen_const_mem (Pmode, new_rtx);
9025           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9026
9027           if (reg == 0)
9028             reg = gen_reg_rtx (Pmode);
9029           emit_move_insn (reg, new_rtx);
9030           new_rtx = reg;
9031         }
9032     }
9033   else
9034     {
9035       if (CONST_INT_P (addr)
9036           && !x86_64_immediate_operand (addr, VOIDmode))
9037         {
9038           if (reg)
9039             {
9040               emit_move_insn (reg, addr);
9041               new_rtx = reg;
9042             }
9043           else
9044             new_rtx = force_reg (Pmode, addr);
9045         }
9046       else if (GET_CODE (addr) == CONST)
9047         {
9048           addr = XEXP (addr, 0);
9049
9050           /* We must match stuff we generate before.  Assume the only
9051              unspecs that can get here are ours.  Not that we could do
9052              anything with them anyway....  */
9053           if (GET_CODE (addr) == UNSPEC
9054               || (GET_CODE (addr) == PLUS
9055                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
9056             return orig;
9057           gcc_assert (GET_CODE (addr) == PLUS);
9058         }
9059       if (GET_CODE (addr) == PLUS)
9060         {
9061           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
9062
9063           /* Check first to see if this is a constant offset from a @GOTOFF
9064              symbol reference.  */
9065           if (gotoff_operand (op0, Pmode)
9066               && CONST_INT_P (op1))
9067             {
9068               if (!TARGET_64BIT)
9069                 {
9070                   if (reload_in_progress)
9071                     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9072                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
9073                                             UNSPEC_GOTOFF);
9074                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
9075                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9076                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9077
9078                   if (reg != 0)
9079                     {
9080                       emit_move_insn (reg, new_rtx);
9081                       new_rtx = reg;
9082                     }
9083                 }
9084               else
9085                 {
9086                   if (INTVAL (op1) < -16*1024*1024
9087                       || INTVAL (op1) >= 16*1024*1024)
9088                     {
9089                       if (!x86_64_immediate_operand (op1, Pmode))
9090                         op1 = force_reg (Pmode, op1);
9091                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
9092                     }
9093                 }
9094             }
9095           else
9096             {
9097               base = legitimize_pic_address (XEXP (addr, 0), reg);
9098               new_rtx  = legitimize_pic_address (XEXP (addr, 1),
9099                                                  base == reg ? NULL_RTX : reg);
9100
9101               if (CONST_INT_P (new_rtx))
9102                 new_rtx = plus_constant (base, INTVAL (new_rtx));
9103               else
9104                 {
9105                   if (GET_CODE (new_rtx) == PLUS && CONSTANT_P (XEXP (new_rtx, 1)))
9106                     {
9107                       base = gen_rtx_PLUS (Pmode, base, XEXP (new_rtx, 0));
9108                       new_rtx = XEXP (new_rtx, 1);
9109                     }
9110                   new_rtx = gen_rtx_PLUS (Pmode, base, new_rtx);
9111                 }
9112             }
9113         }
9114     }
9115   return new_rtx;
9116 }
9117 \f
9118 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
9119
9120 static rtx
9121 get_thread_pointer (int to_reg)
9122 {
9123   rtx tp, reg, insn;
9124
9125   tp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
9126   if (!to_reg)
9127     return tp;
9128
9129   reg = gen_reg_rtx (Pmode);
9130   insn = gen_rtx_SET (VOIDmode, reg, tp);
9131   insn = emit_insn (insn);
9132
9133   return reg;
9134 }
9135
9136 /* A subroutine of legitimize_address and ix86_expand_move.  FOR_MOV is
9137    false if we expect this to be used for a memory address and true if
9138    we expect to load the address into a register.  */
9139
9140 static rtx
9141 legitimize_tls_address (rtx x, enum tls_model model, int for_mov)
9142 {
9143   rtx dest, base, off, pic, tp;
9144   int type;
9145
9146   switch (model)
9147     {
9148     case TLS_MODEL_GLOBAL_DYNAMIC:
9149       dest = gen_reg_rtx (Pmode);
9150       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9151
9152       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9153         {
9154           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns;
9155
9156           start_sequence ();
9157           emit_call_insn (gen_tls_global_dynamic_64 (rax, x));
9158           insns = get_insns ();
9159           end_sequence ();
9160
9161           RTL_CONST_CALL_P (insns) = 1;
9162           emit_libcall_block (insns, dest, rax, x);
9163         }
9164       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9165         emit_insn (gen_tls_global_dynamic_64 (dest, x));
9166       else
9167         emit_insn (gen_tls_global_dynamic_32 (dest, x));
9168
9169       if (TARGET_GNU2_TLS)
9170         {
9171           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
9172
9173           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9174         }
9175       break;
9176
9177     case TLS_MODEL_LOCAL_DYNAMIC:
9178       base = gen_reg_rtx (Pmode);
9179       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9180
9181       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9182         {
9183           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns, note;
9184
9185           start_sequence ();
9186           emit_call_insn (gen_tls_local_dynamic_base_64 (rax));
9187           insns = get_insns ();
9188           end_sequence ();
9189
9190           note = gen_rtx_EXPR_LIST (VOIDmode, const0_rtx, NULL);
9191           note = gen_rtx_EXPR_LIST (VOIDmode, ix86_tls_get_addr (), note);
9192           RTL_CONST_CALL_P (insns) = 1;
9193           emit_libcall_block (insns, base, rax, note);
9194         }
9195       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9196         emit_insn (gen_tls_local_dynamic_base_64 (base));
9197       else
9198         emit_insn (gen_tls_local_dynamic_base_32 (base));
9199
9200       if (TARGET_GNU2_TLS)
9201         {
9202           rtx x = ix86_tls_module_base ();
9203
9204           set_unique_reg_note (get_last_insn (), REG_EQUIV,
9205                                gen_rtx_MINUS (Pmode, x, tp));
9206         }
9207
9208       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
9209       off = gen_rtx_CONST (Pmode, off);
9210
9211       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
9212
9213       if (TARGET_GNU2_TLS)
9214         {
9215           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
9216
9217           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9218         }
9219
9220       break;
9221
9222     case TLS_MODEL_INITIAL_EXEC:
9223       if (TARGET_64BIT)
9224         {
9225           pic = NULL;
9226           type = UNSPEC_GOTNTPOFF;
9227         }
9228       else if (flag_pic)
9229         {
9230           if (reload_in_progress)
9231             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9232           pic = pic_offset_table_rtx;
9233           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
9234         }
9235       else if (!TARGET_ANY_GNU_TLS)
9236         {
9237           pic = gen_reg_rtx (Pmode);
9238           emit_insn (gen_set_got (pic));
9239           type = UNSPEC_GOTTPOFF;
9240         }
9241       else
9242         {
9243           pic = NULL;
9244           type = UNSPEC_INDNTPOFF;
9245         }
9246
9247       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), type);
9248       off = gen_rtx_CONST (Pmode, off);
9249       if (pic)
9250         off = gen_rtx_PLUS (Pmode, pic, off);
9251       off = gen_const_mem (Pmode, off);
9252       set_mem_alias_set (off, ix86_GOT_alias_set ());
9253
9254       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9255         {
9256           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9257           off = force_reg (Pmode, off);
9258           return gen_rtx_PLUS (Pmode, base, off);
9259         }
9260       else
9261         {
9262           base = get_thread_pointer (true);
9263           dest = gen_reg_rtx (Pmode);
9264           emit_insn (gen_subsi3 (dest, base, off));
9265         }
9266       break;
9267
9268     case TLS_MODEL_LOCAL_EXEC:
9269       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
9270                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9271                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
9272       off = gen_rtx_CONST (Pmode, off);
9273
9274       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9275         {
9276           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9277           return gen_rtx_PLUS (Pmode, base, off);
9278         }
9279       else
9280         {
9281           base = get_thread_pointer (true);
9282           dest = gen_reg_rtx (Pmode);
9283           emit_insn (gen_subsi3 (dest, base, off));
9284         }
9285       break;
9286
9287     default:
9288       gcc_unreachable ();
9289     }
9290
9291   return dest;
9292 }
9293
9294 /* Create or return the unique __imp_DECL dllimport symbol corresponding
9295    to symbol DECL.  */
9296
9297 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
9298   htab_t dllimport_map;
9299
9300 static tree
9301 get_dllimport_decl (tree decl)
9302 {
9303   struct tree_map *h, in;
9304   void **loc;
9305   const char *name;
9306   const char *prefix;
9307   size_t namelen, prefixlen;
9308   char *imp_name;
9309   tree to;
9310   rtx rtl;
9311
9312   if (!dllimport_map)
9313     dllimport_map = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
9314
9315   in.hash = htab_hash_pointer (decl);
9316   in.base.from = decl;
9317   loc = htab_find_slot_with_hash (dllimport_map, &in, in.hash, INSERT);
9318   h = (struct tree_map *) *loc;
9319   if (h)
9320     return h->to;
9321
9322   *loc = h = GGC_NEW (struct tree_map);
9323   h->hash = in.hash;
9324   h->base.from = decl;
9325   h->to = to = build_decl (VAR_DECL, NULL, ptr_type_node);
9326   DECL_ARTIFICIAL (to) = 1;
9327   DECL_IGNORED_P (to) = 1;
9328   DECL_EXTERNAL (to) = 1;
9329   TREE_READONLY (to) = 1;
9330
9331   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9332   name = targetm.strip_name_encoding (name);
9333   prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
9334     ? "*__imp_" : "*__imp__";
9335   namelen = strlen (name);
9336   prefixlen = strlen (prefix);
9337   imp_name = (char *) alloca (namelen + prefixlen + 1);
9338   memcpy (imp_name, prefix, prefixlen);
9339   memcpy (imp_name + prefixlen, name, namelen + 1);
9340
9341   name = ggc_alloc_string (imp_name, namelen + prefixlen);
9342   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
9343   SET_SYMBOL_REF_DECL (rtl, to);
9344   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL;
9345
9346   rtl = gen_const_mem (Pmode, rtl);
9347   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
9348
9349   SET_DECL_RTL (to, rtl);
9350   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
9351
9352   return to;
9353 }
9354
9355 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
9356    true if we require the result be a register.  */
9357
9358 static rtx
9359 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
9360 {
9361   tree imp_decl;
9362   rtx x;
9363
9364   gcc_assert (SYMBOL_REF_DECL (symbol));
9365   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol));
9366
9367   x = DECL_RTL (imp_decl);
9368   if (want_reg)
9369     x = force_reg (Pmode, x);
9370   return x;
9371 }
9372
9373 /* Try machine-dependent ways of modifying an illegitimate address
9374    to be legitimate.  If we find one, return the new, valid address.
9375    This macro is used in only one place: `memory_address' in explow.c.
9376
9377    OLDX is the address as it was before break_out_memory_refs was called.
9378    In some cases it is useful to look at this to decide what needs to be done.
9379
9380    MODE and WIN are passed so that this macro can use
9381    GO_IF_LEGITIMATE_ADDRESS.
9382
9383    It is always safe for this macro to do nothing.  It exists to recognize
9384    opportunities to optimize the output.
9385
9386    For the 80386, we handle X+REG by loading X into a register R and
9387    using R+REG.  R will go in a general reg and indexing will be used.
9388    However, if REG is a broken-out memory address or multiplication,
9389    nothing needs to be done because REG can certainly go in a general reg.
9390
9391    When -fpic is used, special handling is needed for symbolic references.
9392    See comments by legitimize_pic_address in i386.c for details.  */
9393
9394 rtx
9395 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
9396 {
9397   int changed = 0;
9398   unsigned log;
9399
9400   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
9401   if (log)
9402     return legitimize_tls_address (x, (enum tls_model) log, false);
9403   if (GET_CODE (x) == CONST
9404       && GET_CODE (XEXP (x, 0)) == PLUS
9405       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9406       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
9407     {
9408       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
9409                                       (enum tls_model) log, false);
9410       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9411     }
9412
9413   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9414     {
9415       if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (x))
9416         return legitimize_dllimport_symbol (x, true);
9417       if (GET_CODE (x) == CONST
9418           && GET_CODE (XEXP (x, 0)) == PLUS
9419           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9420           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (x, 0), 0)))
9421         {
9422           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (x, 0), 0), true);
9423           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9424         }
9425     }
9426
9427   if (flag_pic && SYMBOLIC_CONST (x))
9428     return legitimize_pic_address (x, 0);
9429
9430   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
9431   if (GET_CODE (x) == ASHIFT
9432       && CONST_INT_P (XEXP (x, 1))
9433       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
9434     {
9435       changed = 1;
9436       log = INTVAL (XEXP (x, 1));
9437       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
9438                         GEN_INT (1 << log));
9439     }
9440
9441   if (GET_CODE (x) == PLUS)
9442     {
9443       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
9444
9445       if (GET_CODE (XEXP (x, 0)) == ASHIFT
9446           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
9447           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
9448         {
9449           changed = 1;
9450           log = INTVAL (XEXP (XEXP (x, 0), 1));
9451           XEXP (x, 0) = gen_rtx_MULT (Pmode,
9452                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
9453                                       GEN_INT (1 << log));
9454         }
9455
9456       if (GET_CODE (XEXP (x, 1)) == ASHIFT
9457           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
9458           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
9459         {
9460           changed = 1;
9461           log = INTVAL (XEXP (XEXP (x, 1), 1));
9462           XEXP (x, 1) = gen_rtx_MULT (Pmode,
9463                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
9464                                       GEN_INT (1 << log));
9465         }
9466
9467       /* Put multiply first if it isn't already.  */
9468       if (GET_CODE (XEXP (x, 1)) == MULT)
9469         {
9470           rtx tmp = XEXP (x, 0);
9471           XEXP (x, 0) = XEXP (x, 1);
9472           XEXP (x, 1) = tmp;
9473           changed = 1;
9474         }
9475
9476       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
9477          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
9478          created by virtual register instantiation, register elimination, and
9479          similar optimizations.  */
9480       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
9481         {
9482           changed = 1;
9483           x = gen_rtx_PLUS (Pmode,
9484                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
9485                                           XEXP (XEXP (x, 1), 0)),
9486                             XEXP (XEXP (x, 1), 1));
9487         }
9488
9489       /* Canonicalize
9490          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
9491          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
9492       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
9493                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
9494                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
9495                && CONSTANT_P (XEXP (x, 1)))
9496         {
9497           rtx constant;
9498           rtx other = NULL_RTX;
9499
9500           if (CONST_INT_P (XEXP (x, 1)))
9501             {
9502               constant = XEXP (x, 1);
9503               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
9504             }
9505           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
9506             {
9507               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
9508               other = XEXP (x, 1);
9509             }
9510           else
9511             constant = 0;
9512
9513           if (constant)
9514             {
9515               changed = 1;
9516               x = gen_rtx_PLUS (Pmode,
9517                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
9518                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
9519                                 plus_constant (other, INTVAL (constant)));
9520             }
9521         }
9522
9523       if (changed && legitimate_address_p (mode, x, FALSE))
9524         return x;
9525
9526       if (GET_CODE (XEXP (x, 0)) == MULT)
9527         {
9528           changed = 1;
9529           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
9530         }
9531
9532       if (GET_CODE (XEXP (x, 1)) == MULT)
9533         {
9534           changed = 1;
9535           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
9536         }
9537
9538       if (changed
9539           && REG_P (XEXP (x, 1))
9540           && REG_P (XEXP (x, 0)))
9541         return x;
9542
9543       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
9544         {
9545           changed = 1;
9546           x = legitimize_pic_address (x, 0);
9547         }
9548
9549       if (changed && legitimate_address_p (mode, x, FALSE))
9550         return x;
9551
9552       if (REG_P (XEXP (x, 0)))
9553         {
9554           rtx temp = gen_reg_rtx (Pmode);
9555           rtx val  = force_operand (XEXP (x, 1), temp);
9556           if (val != temp)
9557             emit_move_insn (temp, val);
9558
9559           XEXP (x, 1) = temp;
9560           return x;
9561         }
9562
9563       else if (REG_P (XEXP (x, 1)))
9564         {
9565           rtx temp = gen_reg_rtx (Pmode);
9566           rtx val  = force_operand (XEXP (x, 0), temp);
9567           if (val != temp)
9568             emit_move_insn (temp, val);
9569
9570           XEXP (x, 0) = temp;
9571           return x;
9572         }
9573     }
9574
9575   return x;
9576 }
9577 \f
9578 /* Print an integer constant expression in assembler syntax.  Addition
9579    and subtraction are the only arithmetic that may appear in these
9580    expressions.  FILE is the stdio stream to write to, X is the rtx, and
9581    CODE is the operand print code from the output string.  */
9582
9583 static void
9584 output_pic_addr_const (FILE *file, rtx x, int code)
9585 {
9586   char buf[256];
9587
9588   switch (GET_CODE (x))
9589     {
9590     case PC:
9591       gcc_assert (flag_pic);
9592       putc ('.', file);
9593       break;
9594
9595     case SYMBOL_REF:
9596       if (! TARGET_MACHO || TARGET_64BIT)
9597         output_addr_const (file, x);
9598       else
9599         {
9600           const char *name = XSTR (x, 0);
9601
9602           /* Mark the decl as referenced so that cgraph will
9603              output the function.  */
9604           if (SYMBOL_REF_DECL (x))
9605             mark_decl_referenced (SYMBOL_REF_DECL (x));
9606
9607 #if TARGET_MACHO
9608           if (MACHOPIC_INDIRECT
9609               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
9610             name = machopic_indirection_name (x, /*stub_p=*/true);
9611 #endif
9612           assemble_name (file, name);
9613         }
9614       if (!TARGET_MACHO && !(TARGET_64BIT && DEFAULT_ABI == MS_ABI)
9615           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
9616         fputs ("@PLT", file);
9617       break;
9618
9619     case LABEL_REF:
9620       x = XEXP (x, 0);
9621       /* FALLTHRU */
9622     case CODE_LABEL:
9623       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
9624       assemble_name (asm_out_file, buf);
9625       break;
9626
9627     case CONST_INT:
9628       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
9629       break;
9630
9631     case CONST:
9632       /* This used to output parentheses around the expression,
9633          but that does not work on the 386 (either ATT or BSD assembler).  */
9634       output_pic_addr_const (file, XEXP (x, 0), code);
9635       break;
9636
9637     case CONST_DOUBLE:
9638       if (GET_MODE (x) == VOIDmode)
9639         {
9640           /* We can use %d if the number is <32 bits and positive.  */
9641           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
9642             fprintf (file, "0x%lx%08lx",
9643                      (unsigned long) CONST_DOUBLE_HIGH (x),
9644                      (unsigned long) CONST_DOUBLE_LOW (x));
9645           else
9646             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
9647         }
9648       else
9649         /* We can't handle floating point constants;
9650            PRINT_OPERAND must handle them.  */
9651         output_operand_lossage ("floating constant misused");
9652       break;
9653
9654     case PLUS:
9655       /* Some assemblers need integer constants to appear first.  */
9656       if (CONST_INT_P (XEXP (x, 0)))
9657         {
9658           output_pic_addr_const (file, XEXP (x, 0), code);
9659           putc ('+', file);
9660           output_pic_addr_const (file, XEXP (x, 1), code);
9661         }
9662       else
9663         {
9664           gcc_assert (CONST_INT_P (XEXP (x, 1)));
9665           output_pic_addr_const (file, XEXP (x, 1), code);
9666           putc ('+', file);
9667           output_pic_addr_const (file, XEXP (x, 0), code);
9668         }
9669       break;
9670
9671     case MINUS:
9672       if (!TARGET_MACHO)
9673         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
9674       output_pic_addr_const (file, XEXP (x, 0), code);
9675       putc ('-', file);
9676       output_pic_addr_const (file, XEXP (x, 1), code);
9677       if (!TARGET_MACHO)
9678         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
9679       break;
9680
9681      case UNSPEC:
9682        gcc_assert (XVECLEN (x, 0) == 1);
9683        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
9684        switch (XINT (x, 1))
9685         {
9686         case UNSPEC_GOT:
9687           fputs ("@GOT", file);
9688           break;
9689         case UNSPEC_GOTOFF:
9690           fputs ("@GOTOFF", file);
9691           break;
9692         case UNSPEC_PLTOFF:
9693           fputs ("@PLTOFF", file);
9694           break;
9695         case UNSPEC_GOTPCREL:
9696           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
9697                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
9698           break;
9699         case UNSPEC_GOTTPOFF:
9700           /* FIXME: This might be @TPOFF in Sun ld too.  */
9701           fputs ("@GOTTPOFF", file);
9702           break;
9703         case UNSPEC_TPOFF:
9704           fputs ("@TPOFF", file);
9705           break;
9706         case UNSPEC_NTPOFF:
9707           if (TARGET_64BIT)
9708             fputs ("@TPOFF", file);
9709           else
9710             fputs ("@NTPOFF", file);
9711           break;
9712         case UNSPEC_DTPOFF:
9713           fputs ("@DTPOFF", file);
9714           break;
9715         case UNSPEC_GOTNTPOFF:
9716           if (TARGET_64BIT)
9717             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
9718                    "@GOTTPOFF(%rip)": "@GOTTPOFF[rip]", file);
9719           else
9720             fputs ("@GOTNTPOFF", file);
9721           break;
9722         case UNSPEC_INDNTPOFF:
9723           fputs ("@INDNTPOFF", file);
9724           break;
9725         default:
9726           output_operand_lossage ("invalid UNSPEC as operand");
9727           break;
9728         }
9729        break;
9730
9731     default:
9732       output_operand_lossage ("invalid expression as operand");
9733     }
9734 }
9735
9736 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
9737    We need to emit DTP-relative relocations.  */
9738
9739 static void ATTRIBUTE_UNUSED
9740 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
9741 {
9742   fputs (ASM_LONG, file);
9743   output_addr_const (file, x);
9744   fputs ("@DTPOFF", file);
9745   switch (size)
9746     {
9747     case 4:
9748       break;
9749     case 8:
9750       fputs (", 0", file);
9751       break;
9752     default:
9753       gcc_unreachable ();
9754    }
9755 }
9756
9757 /* In the name of slightly smaller debug output, and to cater to
9758    general assembler lossage, recognize PIC+GOTOFF and turn it back
9759    into a direct symbol reference.
9760
9761    On Darwin, this is necessary to avoid a crash, because Darwin
9762    has a different PIC label for each routine but the DWARF debugging
9763    information is not associated with any particular routine, so it's
9764    necessary to remove references to the PIC label from RTL stored by
9765    the DWARF output code.  */
9766
9767 static rtx
9768 ix86_delegitimize_address (rtx orig_x)
9769 {
9770   rtx x = orig_x;
9771   /* reg_addend is NULL or a multiple of some register.  */
9772   rtx reg_addend = NULL_RTX;
9773   /* const_addend is NULL or a const_int.  */
9774   rtx const_addend = NULL_RTX;
9775   /* This is the result, or NULL.  */
9776   rtx result = NULL_RTX;
9777
9778   if (MEM_P (x))
9779     x = XEXP (x, 0);
9780
9781   if (TARGET_64BIT)
9782     {
9783       if (GET_CODE (x) != CONST
9784           || GET_CODE (XEXP (x, 0)) != UNSPEC
9785           || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL
9786           || !MEM_P (orig_x))
9787         return orig_x;
9788       return XVECEXP (XEXP (x, 0), 0, 0);
9789     }
9790
9791   if (GET_CODE (x) != PLUS
9792       || GET_CODE (XEXP (x, 1)) != CONST)
9793     return orig_x;
9794
9795   if (REG_P (XEXP (x, 0))
9796       && REGNO (XEXP (x, 0)) == PIC_OFFSET_TABLE_REGNUM)
9797     /* %ebx + GOT/GOTOFF */
9798     ;
9799   else if (GET_CODE (XEXP (x, 0)) == PLUS)
9800     {
9801       /* %ebx + %reg * scale + GOT/GOTOFF */
9802       reg_addend = XEXP (x, 0);
9803       if (REG_P (XEXP (reg_addend, 0))
9804           && REGNO (XEXP (reg_addend, 0)) == PIC_OFFSET_TABLE_REGNUM)
9805         reg_addend = XEXP (reg_addend, 1);
9806       else if (REG_P (XEXP (reg_addend, 1))
9807                && REGNO (XEXP (reg_addend, 1)) == PIC_OFFSET_TABLE_REGNUM)
9808         reg_addend = XEXP (reg_addend, 0);
9809       else
9810         return orig_x;
9811       if (!REG_P (reg_addend)
9812           && GET_CODE (reg_addend) != MULT
9813           && GET_CODE (reg_addend) != ASHIFT)
9814         return orig_x;
9815     }
9816   else
9817     return orig_x;
9818
9819   x = XEXP (XEXP (x, 1), 0);
9820   if (GET_CODE (x) == PLUS
9821       && CONST_INT_P (XEXP (x, 1)))
9822     {
9823       const_addend = XEXP (x, 1);
9824       x = XEXP (x, 0);
9825     }
9826
9827   if (GET_CODE (x) == UNSPEC
9828       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x))
9829           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))))
9830     result = XVECEXP (x, 0, 0);
9831
9832   if (TARGET_MACHO && darwin_local_data_pic (x)
9833       && !MEM_P (orig_x))
9834     result = XEXP (x, 0);
9835
9836   if (! result)
9837     return orig_x;
9838
9839   if (const_addend)
9840     result = gen_rtx_PLUS (Pmode, result, const_addend);
9841   if (reg_addend)
9842     result = gen_rtx_PLUS (Pmode, reg_addend, result);
9843   return result;
9844 }
9845
9846 /* If X is a machine specific address (i.e. a symbol or label being
9847    referenced as a displacement from the GOT implemented using an
9848    UNSPEC), then return the base term.  Otherwise return X.  */
9849
9850 rtx
9851 ix86_find_base_term (rtx x)
9852 {
9853   rtx term;
9854
9855   if (TARGET_64BIT)
9856     {
9857       if (GET_CODE (x) != CONST)
9858         return x;
9859       term = XEXP (x, 0);
9860       if (GET_CODE (term) == PLUS
9861           && (CONST_INT_P (XEXP (term, 1))
9862               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
9863         term = XEXP (term, 0);
9864       if (GET_CODE (term) != UNSPEC
9865           || XINT (term, 1) != UNSPEC_GOTPCREL)
9866         return x;
9867
9868       term = XVECEXP (term, 0, 0);
9869
9870       if (GET_CODE (term) != SYMBOL_REF
9871           && GET_CODE (term) != LABEL_REF)
9872         return x;
9873
9874       return term;
9875     }
9876
9877   term = ix86_delegitimize_address (x);
9878
9879   if (GET_CODE (term) != SYMBOL_REF
9880       && GET_CODE (term) != LABEL_REF)
9881     return x;
9882
9883   return term;
9884 }
9885 \f
9886 static void
9887 put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
9888                     int fp, FILE *file)
9889 {
9890   const char *suffix;
9891
9892   if (mode == CCFPmode || mode == CCFPUmode)
9893     {
9894       enum rtx_code second_code, bypass_code;
9895       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
9896       gcc_assert (bypass_code == UNKNOWN && second_code == UNKNOWN);
9897       code = ix86_fp_compare_code_to_integer (code);
9898       mode = CCmode;
9899     }
9900   if (reverse)
9901     code = reverse_condition (code);
9902
9903   switch (code)
9904     {
9905     case EQ:
9906       switch (mode)
9907         {
9908         case CCAmode:
9909           suffix = "a";
9910           break;
9911
9912         case CCCmode:
9913           suffix = "c";
9914           break;
9915
9916         case CCOmode:
9917           suffix = "o";
9918           break;
9919
9920         case CCSmode:
9921           suffix = "s";
9922           break;
9923
9924         default:
9925           suffix = "e";
9926         }
9927       break;
9928     case NE:
9929       switch (mode)
9930         {
9931         case CCAmode:
9932           suffix = "na";
9933           break;
9934
9935         case CCCmode:
9936           suffix = "nc";
9937           break;
9938
9939         case CCOmode:
9940           suffix = "no";
9941           break;
9942
9943         case CCSmode:
9944           suffix = "ns";
9945           break;
9946
9947         default:
9948           suffix = "ne";
9949         }
9950       break;
9951     case GT:
9952       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
9953       suffix = "g";
9954       break;
9955     case GTU:
9956       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
9957          Those same assemblers have the same but opposite lossage on cmov.  */
9958       if (mode == CCmode)
9959         suffix = fp ? "nbe" : "a";
9960       else if (mode == CCCmode)
9961         suffix = "b";
9962       else
9963         gcc_unreachable ();
9964       break;
9965     case LT:
9966       switch (mode)
9967         {
9968         case CCNOmode:
9969         case CCGOCmode:
9970           suffix = "s";
9971           break;
9972
9973         case CCmode:
9974         case CCGCmode:
9975           suffix = "l";
9976           break;
9977
9978         default:
9979           gcc_unreachable ();
9980         }
9981       break;
9982     case LTU:
9983       gcc_assert (mode == CCmode || mode == CCCmode);
9984       suffix = "b";
9985       break;
9986     case GE:
9987       switch (mode)
9988         {
9989         case CCNOmode:
9990         case CCGOCmode:
9991           suffix = "ns";
9992           break;
9993
9994         case CCmode:
9995         case CCGCmode:
9996           suffix = "ge";
9997           break;
9998
9999         default:
10000           gcc_unreachable ();
10001         }
10002       break;
10003     case GEU:
10004       /* ??? As above.  */
10005       gcc_assert (mode == CCmode || mode == CCCmode);
10006       suffix = fp ? "nb" : "ae";
10007       break;
10008     case LE:
10009       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
10010       suffix = "le";
10011       break;
10012     case LEU:
10013       /* ??? As above.  */
10014       if (mode == CCmode)
10015         suffix = "be";
10016       else if (mode == CCCmode)
10017         suffix = fp ? "nb" : "ae";
10018       else
10019         gcc_unreachable ();
10020       break;
10021     case UNORDERED:
10022       suffix = fp ? "u" : "p";
10023       break;
10024     case ORDERED:
10025       suffix = fp ? "nu" : "np";
10026       break;
10027     default:
10028       gcc_unreachable ();
10029     }
10030   fputs (suffix, file);
10031 }
10032
10033 /* Print the name of register X to FILE based on its machine mode and number.
10034    If CODE is 'w', pretend the mode is HImode.
10035    If CODE is 'b', pretend the mode is QImode.
10036    If CODE is 'k', pretend the mode is SImode.
10037    If CODE is 'q', pretend the mode is DImode.
10038    If CODE is 'h', pretend the reg is the 'high' byte register.
10039    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.  */
10040
10041 void
10042 print_reg (rtx x, int code, FILE *file)
10043 {
10044   gcc_assert (x == pc_rtx
10045               || (REGNO (x) != ARG_POINTER_REGNUM
10046                   && REGNO (x) != FRAME_POINTER_REGNUM
10047                   && REGNO (x) != FLAGS_REG
10048                   && REGNO (x) != FPSR_REG
10049                   && REGNO (x) != FPCR_REG));
10050
10051   if (ASSEMBLER_DIALECT == ASM_ATT)
10052     putc ('%', file);
10053
10054   if (x == pc_rtx)
10055     {
10056       gcc_assert (TARGET_64BIT);
10057       fputs ("rip", file);
10058       return;
10059     }
10060
10061   if (code == 'w' || MMX_REG_P (x))
10062     code = 2;
10063   else if (code == 'b')
10064     code = 1;
10065   else if (code == 'k')
10066     code = 4;
10067   else if (code == 'q')
10068     code = 8;
10069   else if (code == 'y')
10070     code = 3;
10071   else if (code == 'h')
10072     code = 0;
10073   else
10074     code = GET_MODE_SIZE (GET_MODE (x));
10075
10076   /* Irritatingly, AMD extended registers use different naming convention
10077      from the normal registers.  */
10078   if (REX_INT_REG_P (x))
10079     {
10080       gcc_assert (TARGET_64BIT);
10081       switch (code)
10082         {
10083           case 0:
10084             error ("extended registers have no high halves");
10085             break;
10086           case 1:
10087             fprintf (file, "r%ib", REGNO (x) - FIRST_REX_INT_REG + 8);
10088             break;
10089           case 2:
10090             fprintf (file, "r%iw", REGNO (x) - FIRST_REX_INT_REG + 8);
10091             break;
10092           case 4:
10093             fprintf (file, "r%id", REGNO (x) - FIRST_REX_INT_REG + 8);
10094             break;
10095           case 8:
10096             fprintf (file, "r%i", REGNO (x) - FIRST_REX_INT_REG + 8);
10097             break;
10098           default:
10099             error ("unsupported operand size for extended register");
10100             break;
10101         }
10102       return;
10103     }
10104   switch (code)
10105     {
10106     case 3:
10107       if (STACK_TOP_P (x))
10108         {
10109           fputs ("st(0)", file);
10110           break;
10111         }
10112       /* FALLTHRU */
10113     case 8:
10114     case 4:
10115     case 12:
10116       if (! ANY_FP_REG_P (x))
10117         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
10118       /* FALLTHRU */
10119     case 16:
10120     case 2:
10121     normal:
10122       fputs (hi_reg_name[REGNO (x)], file);
10123       break;
10124     case 1:
10125       if (REGNO (x) >= ARRAY_SIZE (qi_reg_name))
10126         goto normal;
10127       fputs (qi_reg_name[REGNO (x)], file);
10128       break;
10129     case 0:
10130       if (REGNO (x) >= ARRAY_SIZE (qi_high_reg_name))
10131         goto normal;
10132       fputs (qi_high_reg_name[REGNO (x)], file);
10133       break;
10134     default:
10135       gcc_unreachable ();
10136     }
10137 }
10138
10139 /* Locate some local-dynamic symbol still in use by this function
10140    so that we can print its name in some tls_local_dynamic_base
10141    pattern.  */
10142
10143 static int
10144 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
10145 {
10146   rtx x = *px;
10147
10148   if (GET_CODE (x) == SYMBOL_REF
10149       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
10150     {
10151       cfun->machine->some_ld_name = XSTR (x, 0);
10152       return 1;
10153     }
10154
10155   return 0;
10156 }
10157
10158 static const char *
10159 get_some_local_dynamic_name (void)
10160 {
10161   rtx insn;
10162
10163   if (cfun->machine->some_ld_name)
10164     return cfun->machine->some_ld_name;
10165
10166   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
10167     if (INSN_P (insn)
10168         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
10169       return cfun->machine->some_ld_name;
10170
10171   gcc_unreachable ();
10172 }
10173
10174 /* Meaning of CODE:
10175    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
10176    C -- print opcode suffix for set/cmov insn.
10177    c -- like C, but print reversed condition
10178    E,e -- likewise, but for compare-and-branch fused insn.
10179    F,f -- likewise, but for floating-point.
10180    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
10181         otherwise nothing
10182    R -- print the prefix for register names.
10183    z -- print the opcode suffix for the size of the current operand.
10184    * -- print a star (in certain assembler syntax)
10185    A -- print an absolute memory reference.
10186    w -- print the operand as if it's a "word" (HImode) even if it isn't.
10187    s -- print a shift double count, followed by the assemblers argument
10188         delimiter.
10189    b -- print the QImode name of the register for the indicated operand.
10190         %b0 would print %al if operands[0] is reg 0.
10191    w --  likewise, print the HImode name of the register.
10192    k --  likewise, print the SImode name of the register.
10193    q --  likewise, print the DImode name of the register.
10194    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
10195    y -- print "st(0)" instead of "st" as a register.
10196    D -- print condition for SSE cmp instruction.
10197    P -- if PIC, print an @PLT suffix.
10198    X -- don't print any sort of PIC '@' suffix for a symbol.
10199    & -- print some in-use local-dynamic symbol name.
10200    H -- print a memory address offset by 8; used for sse high-parts
10201    Y -- print condition for SSE5 com* instruction.
10202    + -- print a branch hint as 'cs' or 'ds' prefix
10203    ; -- print a semicolon (after prefixes due to bug in older gas).
10204  */
10205
10206 void
10207 print_operand (FILE *file, rtx x, int code)
10208 {
10209   if (code)
10210     {
10211       switch (code)
10212         {
10213         case '*':
10214           if (ASSEMBLER_DIALECT == ASM_ATT)
10215             putc ('*', file);
10216           return;
10217
10218         case '&':
10219           assemble_name (file, get_some_local_dynamic_name ());
10220           return;
10221
10222         case 'A':
10223           switch (ASSEMBLER_DIALECT)
10224             {
10225             case ASM_ATT:
10226               putc ('*', file);
10227               break;
10228
10229             case ASM_INTEL:
10230               /* Intel syntax. For absolute addresses, registers should not
10231                  be surrounded by braces.  */
10232               if (!REG_P (x))
10233                 {
10234                   putc ('[', file);
10235                   PRINT_OPERAND (file, x, 0);
10236                   putc (']', file);
10237                   return;
10238                 }
10239               break;
10240
10241             default:
10242               gcc_unreachable ();
10243             }
10244
10245           PRINT_OPERAND (file, x, 0);
10246           return;
10247
10248
10249         case 'L':
10250           if (ASSEMBLER_DIALECT == ASM_ATT)
10251             putc ('l', file);
10252           return;
10253
10254         case 'W':
10255           if (ASSEMBLER_DIALECT == ASM_ATT)
10256             putc ('w', file);
10257           return;
10258
10259         case 'B':
10260           if (ASSEMBLER_DIALECT == ASM_ATT)
10261             putc ('b', file);
10262           return;
10263
10264         case 'Q':
10265           if (ASSEMBLER_DIALECT == ASM_ATT)
10266             putc ('l', file);
10267           return;
10268
10269         case 'S':
10270           if (ASSEMBLER_DIALECT == ASM_ATT)
10271             putc ('s', file);
10272           return;
10273
10274         case 'T':
10275           if (ASSEMBLER_DIALECT == ASM_ATT)
10276             putc ('t', file);
10277           return;
10278
10279         case 'z':
10280           /* 387 opcodes don't get size suffixes if the operands are
10281              registers.  */
10282           if (STACK_REG_P (x))
10283             return;
10284
10285           /* Likewise if using Intel opcodes.  */
10286           if (ASSEMBLER_DIALECT == ASM_INTEL)
10287             return;
10288
10289           /* This is the size of op from size of operand.  */
10290           switch (GET_MODE_SIZE (GET_MODE (x)))
10291             {
10292             case 1:
10293               putc ('b', file);
10294               return;
10295
10296             case 2:
10297               if (MEM_P (x))
10298                 {
10299 #ifdef HAVE_GAS_FILDS_FISTS
10300                   putc ('s', file);
10301 #endif
10302                   return;
10303                 }
10304               else
10305                 putc ('w', file);
10306               return;
10307
10308             case 4:
10309               if (GET_MODE (x) == SFmode)
10310                 {
10311                   putc ('s', file);
10312                   return;
10313                 }
10314               else
10315                 putc ('l', file);
10316               return;
10317
10318             case 12:
10319             case 16:
10320               putc ('t', file);
10321               return;
10322
10323             case 8:
10324               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
10325                 {
10326                   if (MEM_P (x))
10327                     {
10328 #ifdef GAS_MNEMONICS
10329                       putc ('q', file);
10330 #else
10331                       putc ('l', file);
10332                       putc ('l', file);
10333 #endif
10334                     }
10335                   else
10336                     putc ('q', file);
10337                 }
10338               else
10339                 putc ('l', file);
10340               return;
10341
10342             default:
10343               gcc_unreachable ();
10344             }
10345
10346         case 'b':
10347         case 'w':
10348         case 'k':
10349         case 'q':
10350         case 'h':
10351         case 'y':
10352         case 'X':
10353         case 'P':
10354           break;
10355
10356         case 's':
10357           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
10358             {
10359               PRINT_OPERAND (file, x, 0);
10360               fputs (", ", file);
10361             }
10362           return;
10363
10364         case 'D':
10365           /* Little bit of braindamage here.  The SSE compare instructions
10366              does use completely different names for the comparisons that the
10367              fp conditional moves.  */
10368           switch (GET_CODE (x))
10369             {
10370             case EQ:
10371             case UNEQ:
10372               fputs ("eq", file);
10373               break;
10374             case LT:
10375             case UNLT:
10376               fputs ("lt", file);
10377               break;
10378             case LE:
10379             case UNLE:
10380               fputs ("le", file);
10381               break;
10382             case UNORDERED:
10383               fputs ("unord", file);
10384               break;
10385             case NE:
10386             case LTGT:
10387               fputs ("neq", file);
10388               break;
10389             case UNGE:
10390             case GE:
10391               fputs ("nlt", file);
10392               break;
10393             case UNGT:
10394             case GT:
10395               fputs ("nle", file);
10396               break;
10397             case ORDERED:
10398               fputs ("ord", file);
10399               break;
10400             default:
10401               gcc_unreachable ();
10402             }
10403           return;
10404         case 'O':
10405 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10406           if (ASSEMBLER_DIALECT == ASM_ATT)
10407             {
10408               switch (GET_MODE (x))
10409                 {
10410                 case HImode: putc ('w', file); break;
10411                 case SImode:
10412                 case SFmode: putc ('l', file); break;
10413                 case DImode:
10414                 case DFmode: putc ('q', file); break;
10415                 default: gcc_unreachable ();
10416                 }
10417               putc ('.', file);
10418             }
10419 #endif
10420           return;
10421         case 'C':
10422           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
10423           return;
10424         case 'F':
10425 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10426           if (ASSEMBLER_DIALECT == ASM_ATT)
10427             putc ('.', file);
10428 #endif
10429           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
10430           return;
10431
10432           /* Like above, but reverse condition */
10433         case 'c':
10434           /* Check to see if argument to %c is really a constant
10435              and not a condition code which needs to be reversed.  */
10436           if (!COMPARISON_P (x))
10437           {
10438             output_operand_lossage ("operand is neither a constant nor a condition code, invalid operand code 'c'");
10439              return;
10440           }
10441           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
10442           return;
10443         case 'f':
10444 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10445           if (ASSEMBLER_DIALECT == ASM_ATT)
10446             putc ('.', file);
10447 #endif
10448           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
10449           return;
10450
10451         case 'E':
10452           put_condition_code (GET_CODE (x), CCmode, 0, 0, file);
10453           return;
10454
10455         case 'e':
10456           put_condition_code (GET_CODE (x), CCmode, 1, 0, file);
10457           return;
10458
10459         case 'H':
10460           /* It doesn't actually matter what mode we use here, as we're
10461              only going to use this for printing.  */
10462           x = adjust_address_nv (x, DImode, 8);
10463           break;
10464
10465         case '+':
10466           {
10467             rtx x;
10468
10469             if (!optimize || optimize_size || !TARGET_BRANCH_PREDICTION_HINTS)
10470               return;
10471
10472             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
10473             if (x)
10474               {
10475                 int pred_val = INTVAL (XEXP (x, 0));
10476
10477                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
10478                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
10479                   {
10480                     int taken = pred_val > REG_BR_PROB_BASE / 2;
10481                     int cputaken = final_forward_branch_p (current_output_insn) == 0;
10482
10483                     /* Emit hints only in the case default branch prediction
10484                        heuristics would fail.  */
10485                     if (taken != cputaken)
10486                       {
10487                         /* We use 3e (DS) prefix for taken branches and
10488                            2e (CS) prefix for not taken branches.  */
10489                         if (taken)
10490                           fputs ("ds ; ", file);
10491                         else
10492                           fputs ("cs ; ", file);
10493                       }
10494                   }
10495               }
10496             return;
10497           }
10498
10499         case 'Y':
10500           switch (GET_CODE (x))
10501             {
10502             case NE:
10503               fputs ("neq", file);
10504               break;
10505             case EQ:
10506               fputs ("eq", file);
10507               break;
10508             case GE:
10509             case GEU:
10510               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
10511               break;
10512             case GT:
10513             case GTU:
10514               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
10515               break;
10516             case LE:
10517             case LEU:
10518               fputs ("le", file);
10519               break;
10520             case LT:
10521             case LTU:
10522               fputs ("lt", file);
10523               break;
10524             case UNORDERED:
10525               fputs ("unord", file);
10526               break;
10527             case ORDERED:
10528               fputs ("ord", file);
10529               break;
10530             case UNEQ:
10531               fputs ("ueq", file);
10532               break;
10533             case UNGE:
10534               fputs ("nlt", file);
10535               break;
10536             case UNGT:
10537               fputs ("nle", file);
10538               break;
10539             case UNLE:
10540               fputs ("ule", file);
10541               break;
10542             case UNLT:
10543               fputs ("ult", file);
10544               break;
10545             case LTGT:
10546               fputs ("une", file);
10547               break;
10548             default:
10549               gcc_unreachable ();
10550             }
10551           return;
10552
10553         case ';':
10554 #if TARGET_MACHO
10555           fputs (" ; ", file);
10556 #else
10557           fputc (' ', file);
10558 #endif
10559           return;
10560
10561         default:
10562             output_operand_lossage ("invalid operand code '%c'", code);
10563         }
10564     }
10565
10566   if (REG_P (x))
10567     print_reg (x, code, file);
10568
10569   else if (MEM_P (x))
10570     {
10571       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
10572       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
10573           && GET_MODE (x) != BLKmode)
10574         {
10575           const char * size;
10576           switch (GET_MODE_SIZE (GET_MODE (x)))
10577             {
10578             case 1: size = "BYTE"; break;
10579             case 2: size = "WORD"; break;
10580             case 4: size = "DWORD"; break;
10581             case 8: size = "QWORD"; break;
10582             case 12: size = "XWORD"; break;
10583             case 16:
10584               if (GET_MODE (x) == XFmode)
10585                 size = "XWORD";
10586               else
10587                 size = "XMMWORD";
10588               break;
10589             default:
10590               gcc_unreachable ();
10591             }
10592
10593           /* Check for explicit size override (codes 'b', 'w' and 'k')  */
10594           if (code == 'b')
10595             size = "BYTE";
10596           else if (code == 'w')
10597             size = "WORD";
10598           else if (code == 'k')
10599             size = "DWORD";
10600
10601           fputs (size, file);
10602           fputs (" PTR ", file);
10603         }
10604
10605       x = XEXP (x, 0);
10606       /* Avoid (%rip) for call operands.  */
10607       if (CONSTANT_ADDRESS_P (x) && code == 'P'
10608           && !CONST_INT_P (x))
10609         output_addr_const (file, x);
10610       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
10611         output_operand_lossage ("invalid constraints for operand");
10612       else
10613         output_address (x);
10614     }
10615
10616   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
10617     {
10618       REAL_VALUE_TYPE r;
10619       long l;
10620
10621       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
10622       REAL_VALUE_TO_TARGET_SINGLE (r, l);
10623
10624       if (ASSEMBLER_DIALECT == ASM_ATT)
10625         putc ('$', file);
10626       fprintf (file, "0x%08lx", (long unsigned int) l);
10627     }
10628
10629   /* These float cases don't actually occur as immediate operands.  */
10630   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
10631     {
10632       char dstr[30];
10633
10634       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
10635       fprintf (file, "%s", dstr);
10636     }
10637
10638   else if (GET_CODE (x) == CONST_DOUBLE
10639            && GET_MODE (x) == XFmode)
10640     {
10641       char dstr[30];
10642
10643       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
10644       fprintf (file, "%s", dstr);
10645     }
10646
10647   else
10648     {
10649       /* We have patterns that allow zero sets of memory, for instance.
10650          In 64-bit mode, we should probably support all 8-byte vectors,
10651          since we can in fact encode that into an immediate.  */
10652       if (GET_CODE (x) == CONST_VECTOR)
10653         {
10654           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
10655           x = const0_rtx;
10656         }
10657
10658       if (code != 'P')
10659         {
10660           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
10661             {
10662               if (ASSEMBLER_DIALECT == ASM_ATT)
10663                 putc ('$', file);
10664             }
10665           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
10666                    || GET_CODE (x) == LABEL_REF)
10667             {
10668               if (ASSEMBLER_DIALECT == ASM_ATT)
10669                 putc ('$', file);
10670               else
10671                 fputs ("OFFSET FLAT:", file);
10672             }
10673         }
10674       if (CONST_INT_P (x))
10675         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
10676       else if (flag_pic)
10677         output_pic_addr_const (file, x, code);
10678       else
10679         output_addr_const (file, x);
10680     }
10681 }
10682 \f
10683 /* Print a memory operand whose address is ADDR.  */
10684
10685 void
10686 print_operand_address (FILE *file, rtx addr)
10687 {
10688   struct ix86_address parts;
10689   rtx base, index, disp;
10690   int scale;
10691   int ok = ix86_decompose_address (addr, &parts);
10692
10693   gcc_assert (ok);
10694
10695   base = parts.base;
10696   index = parts.index;
10697   disp = parts.disp;
10698   scale = parts.scale;
10699
10700   switch (parts.seg)
10701     {
10702     case SEG_DEFAULT:
10703       break;
10704     case SEG_FS:
10705     case SEG_GS:
10706       if (ASSEMBLER_DIALECT == ASM_ATT)
10707         putc ('%', file);
10708       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
10709       break;
10710     default:
10711       gcc_unreachable ();
10712     }
10713
10714   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
10715   if (TARGET_64BIT && !base && !index)
10716     {
10717       rtx symbol = disp;
10718
10719       if (GET_CODE (disp) == CONST
10720           && GET_CODE (XEXP (disp, 0)) == PLUS
10721           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
10722         symbol = XEXP (XEXP (disp, 0), 0);
10723
10724       if (GET_CODE (symbol) == LABEL_REF
10725           || (GET_CODE (symbol) == SYMBOL_REF
10726               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
10727         base = pc_rtx;
10728     }
10729   if (!base && !index)
10730     {
10731       /* Displacement only requires special attention.  */
10732
10733       if (CONST_INT_P (disp))
10734         {
10735           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
10736             fputs ("ds:", file);
10737           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
10738         }
10739       else if (flag_pic)
10740         output_pic_addr_const (file, disp, 0);
10741       else
10742         output_addr_const (file, disp);
10743     }
10744   else
10745     {
10746       if (ASSEMBLER_DIALECT == ASM_ATT)
10747         {
10748           if (disp)
10749             {
10750               if (flag_pic)
10751                 output_pic_addr_const (file, disp, 0);
10752               else if (GET_CODE (disp) == LABEL_REF)
10753                 output_asm_label (disp);
10754               else
10755                 output_addr_const (file, disp);
10756             }
10757
10758           putc ('(', file);
10759           if (base)
10760             print_reg (base, 0, file);
10761           if (index)
10762             {
10763               putc (',', file);
10764               print_reg (index, 0, file);
10765               if (scale != 1)
10766                 fprintf (file, ",%d", scale);
10767             }
10768           putc (')', file);
10769         }
10770       else
10771         {
10772           rtx offset = NULL_RTX;
10773
10774           if (disp)
10775             {
10776               /* Pull out the offset of a symbol; print any symbol itself.  */
10777               if (GET_CODE (disp) == CONST
10778                   && GET_CODE (XEXP (disp, 0)) == PLUS
10779                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
10780                 {
10781                   offset = XEXP (XEXP (disp, 0), 1);
10782                   disp = gen_rtx_CONST (VOIDmode,
10783                                         XEXP (XEXP (disp, 0), 0));
10784                 }
10785
10786               if (flag_pic)
10787                 output_pic_addr_const (file, disp, 0);
10788               else if (GET_CODE (disp) == LABEL_REF)
10789                 output_asm_label (disp);
10790               else if (CONST_INT_P (disp))
10791                 offset = disp;
10792               else
10793                 output_addr_const (file, disp);
10794             }
10795
10796           putc ('[', file);
10797           if (base)
10798             {
10799               print_reg (base, 0, file);
10800               if (offset)
10801                 {
10802                   if (INTVAL (offset) >= 0)
10803                     putc ('+', file);
10804                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
10805                 }
10806             }
10807           else if (offset)
10808             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
10809           else
10810             putc ('0', file);
10811
10812           if (index)
10813             {
10814               putc ('+', file);
10815               print_reg (index, 0, file);
10816               if (scale != 1)
10817                 fprintf (file, "*%d", scale);
10818             }
10819           putc (']', file);
10820         }
10821     }
10822 }
10823
10824 bool
10825 output_addr_const_extra (FILE *file, rtx x)
10826 {
10827   rtx op;
10828
10829   if (GET_CODE (x) != UNSPEC)
10830     return false;
10831
10832   op = XVECEXP (x, 0, 0);
10833   switch (XINT (x, 1))
10834     {
10835     case UNSPEC_GOTTPOFF:
10836       output_addr_const (file, op);
10837       /* FIXME: This might be @TPOFF in Sun ld.  */
10838       fputs ("@GOTTPOFF", file);
10839       break;
10840     case UNSPEC_TPOFF:
10841       output_addr_const (file, op);
10842       fputs ("@TPOFF", file);
10843       break;
10844     case UNSPEC_NTPOFF:
10845       output_addr_const (file, op);
10846       if (TARGET_64BIT)
10847         fputs ("@TPOFF", file);
10848       else
10849         fputs ("@NTPOFF", file);
10850       break;
10851     case UNSPEC_DTPOFF:
10852       output_addr_const (file, op);
10853       fputs ("@DTPOFF", file);
10854       break;
10855     case UNSPEC_GOTNTPOFF:
10856       output_addr_const (file, op);
10857       if (TARGET_64BIT)
10858         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10859                "@GOTTPOFF(%rip)" : "@GOTTPOFF[rip]", file);
10860       else
10861         fputs ("@GOTNTPOFF", file);
10862       break;
10863     case UNSPEC_INDNTPOFF:
10864       output_addr_const (file, op);
10865       fputs ("@INDNTPOFF", file);
10866       break;
10867
10868     default:
10869       return false;
10870     }
10871
10872   return true;
10873 }
10874 \f
10875 /* Split one or more DImode RTL references into pairs of SImode
10876    references.  The RTL can be REG, offsettable MEM, integer constant, or
10877    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
10878    split and "num" is its length.  lo_half and hi_half are output arrays
10879    that parallel "operands".  */
10880
10881 void
10882 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
10883 {
10884   while (num--)
10885     {
10886       rtx op = operands[num];
10887
10888       /* simplify_subreg refuse to split volatile memory addresses,
10889          but we still have to handle it.  */
10890       if (MEM_P (op))
10891         {
10892           lo_half[num] = adjust_address (op, SImode, 0);
10893           hi_half[num] = adjust_address (op, SImode, 4);
10894         }
10895       else
10896         {
10897           lo_half[num] = simplify_gen_subreg (SImode, op,
10898                                               GET_MODE (op) == VOIDmode
10899                                               ? DImode : GET_MODE (op), 0);
10900           hi_half[num] = simplify_gen_subreg (SImode, op,
10901                                               GET_MODE (op) == VOIDmode
10902                                               ? DImode : GET_MODE (op), 4);
10903         }
10904     }
10905 }
10906 /* Split one or more TImode RTL references into pairs of DImode
10907    references.  The RTL can be REG, offsettable MEM, integer constant, or
10908    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
10909    split and "num" is its length.  lo_half and hi_half are output arrays
10910    that parallel "operands".  */
10911
10912 void
10913 split_ti (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
10914 {
10915   while (num--)
10916     {
10917       rtx op = operands[num];
10918
10919       /* simplify_subreg refuse to split volatile memory addresses, but we
10920          still have to handle it.  */
10921       if (MEM_P (op))
10922         {
10923           lo_half[num] = adjust_address (op, DImode, 0);
10924           hi_half[num] = adjust_address (op, DImode, 8);
10925         }
10926       else
10927         {
10928           lo_half[num] = simplify_gen_subreg (DImode, op, TImode, 0);
10929           hi_half[num] = simplify_gen_subreg (DImode, op, TImode, 8);
10930         }
10931     }
10932 }
10933 \f
10934 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
10935    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
10936    is the expression of the binary operation.  The output may either be
10937    emitted here, or returned to the caller, like all output_* functions.
10938
10939    There is no guarantee that the operands are the same mode, as they
10940    might be within FLOAT or FLOAT_EXTEND expressions.  */
10941
10942 #ifndef SYSV386_COMPAT
10943 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
10944    wants to fix the assemblers because that causes incompatibility
10945    with gcc.  No-one wants to fix gcc because that causes
10946    incompatibility with assemblers...  You can use the option of
10947    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
10948 #define SYSV386_COMPAT 1
10949 #endif
10950
10951 const char *
10952 output_387_binary_op (rtx insn, rtx *operands)
10953 {
10954   static char buf[30];
10955   const char *p;
10956   const char *ssep;
10957   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
10958
10959 #ifdef ENABLE_CHECKING
10960   /* Even if we do not want to check the inputs, this documents input
10961      constraints.  Which helps in understanding the following code.  */
10962   if (STACK_REG_P (operands[0])
10963       && ((REG_P (operands[1])
10964            && REGNO (operands[0]) == REGNO (operands[1])
10965            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
10966           || (REG_P (operands[2])
10967               && REGNO (operands[0]) == REGNO (operands[2])
10968               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
10969       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
10970     ; /* ok */
10971   else
10972     gcc_assert (is_sse);
10973 #endif
10974
10975   switch (GET_CODE (operands[3]))
10976     {
10977     case PLUS:
10978       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
10979           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
10980         p = "fiadd";
10981       else
10982         p = "fadd";
10983       ssep = "add";
10984       break;
10985
10986     case MINUS:
10987       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
10988           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
10989         p = "fisub";
10990       else
10991         p = "fsub";
10992       ssep = "sub";
10993       break;
10994
10995     case MULT:
10996       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
10997           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
10998         p = "fimul";
10999       else
11000         p = "fmul";
11001       ssep = "mul";
11002       break;
11003
11004     case DIV:
11005       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11006           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11007         p = "fidiv";
11008       else
11009         p = "fdiv";
11010       ssep = "div";
11011       break;
11012
11013     default:
11014       gcc_unreachable ();
11015     }
11016
11017   if (is_sse)
11018    {
11019       strcpy (buf, ssep);
11020       if (GET_MODE (operands[0]) == SFmode)
11021         strcat (buf, "ss\t{%2, %0|%0, %2}");
11022       else
11023         strcat (buf, "sd\t{%2, %0|%0, %2}");
11024       return buf;
11025    }
11026   strcpy (buf, p);
11027
11028   switch (GET_CODE (operands[3]))
11029     {
11030     case MULT:
11031     case PLUS:
11032       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
11033         {
11034           rtx temp = operands[2];
11035           operands[2] = operands[1];
11036           operands[1] = temp;
11037         }
11038
11039       /* know operands[0] == operands[1].  */
11040
11041       if (MEM_P (operands[2]))
11042         {
11043           p = "%z2\t%2";
11044           break;
11045         }
11046
11047       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11048         {
11049           if (STACK_TOP_P (operands[0]))
11050             /* How is it that we are storing to a dead operand[2]?
11051                Well, presumably operands[1] is dead too.  We can't
11052                store the result to st(0) as st(0) gets popped on this
11053                instruction.  Instead store to operands[2] (which I
11054                think has to be st(1)).  st(1) will be popped later.
11055                gcc <= 2.8.1 didn't have this check and generated
11056                assembly code that the Unixware assembler rejected.  */
11057             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
11058           else
11059             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11060           break;
11061         }
11062
11063       if (STACK_TOP_P (operands[0]))
11064         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
11065       else
11066         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
11067       break;
11068
11069     case MINUS:
11070     case DIV:
11071       if (MEM_P (operands[1]))
11072         {
11073           p = "r%z1\t%1";
11074           break;
11075         }
11076
11077       if (MEM_P (operands[2]))
11078         {
11079           p = "%z2\t%2";
11080           break;
11081         }
11082
11083       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11084         {
11085 #if SYSV386_COMPAT
11086           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
11087              derived assemblers, confusingly reverse the direction of
11088              the operation for fsub{r} and fdiv{r} when the
11089              destination register is not st(0).  The Intel assembler
11090              doesn't have this brain damage.  Read !SYSV386_COMPAT to
11091              figure out what the hardware really does.  */
11092           if (STACK_TOP_P (operands[0]))
11093             p = "{p\t%0, %2|rp\t%2, %0}";
11094           else
11095             p = "{rp\t%2, %0|p\t%0, %2}";
11096 #else
11097           if (STACK_TOP_P (operands[0]))
11098             /* As above for fmul/fadd, we can't store to st(0).  */
11099             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
11100           else
11101             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11102 #endif
11103           break;
11104         }
11105
11106       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
11107         {
11108 #if SYSV386_COMPAT
11109           if (STACK_TOP_P (operands[0]))
11110             p = "{rp\t%0, %1|p\t%1, %0}";
11111           else
11112             p = "{p\t%1, %0|rp\t%0, %1}";
11113 #else
11114           if (STACK_TOP_P (operands[0]))
11115             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
11116           else
11117             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
11118 #endif
11119           break;
11120         }
11121
11122       if (STACK_TOP_P (operands[0]))
11123         {
11124           if (STACK_TOP_P (operands[1]))
11125             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
11126           else
11127             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
11128           break;
11129         }
11130       else if (STACK_TOP_P (operands[1]))
11131         {
11132 #if SYSV386_COMPAT
11133           p = "{\t%1, %0|r\t%0, %1}";
11134 #else
11135           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
11136 #endif
11137         }
11138       else
11139         {
11140 #if SYSV386_COMPAT
11141           p = "{r\t%2, %0|\t%0, %2}";
11142 #else
11143           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
11144 #endif
11145         }
11146       break;
11147
11148     default:
11149       gcc_unreachable ();
11150     }
11151
11152   strcat (buf, p);
11153   return buf;
11154 }
11155
11156 /* Return needed mode for entity in optimize_mode_switching pass.  */
11157
11158 int
11159 ix86_mode_needed (int entity, rtx insn)
11160 {
11161   enum attr_i387_cw mode;
11162
11163   /* The mode UNINITIALIZED is used to store control word after a
11164      function call or ASM pattern.  The mode ANY specify that function
11165      has no requirements on the control word and make no changes in the
11166      bits we are interested in.  */
11167
11168   if (CALL_P (insn)
11169       || (NONJUMP_INSN_P (insn)
11170           && (asm_noperands (PATTERN (insn)) >= 0
11171               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
11172     return I387_CW_UNINITIALIZED;
11173
11174   if (recog_memoized (insn) < 0)
11175     return I387_CW_ANY;
11176
11177   mode = get_attr_i387_cw (insn);
11178
11179   switch (entity)
11180     {
11181     case I387_TRUNC:
11182       if (mode == I387_CW_TRUNC)
11183         return mode;
11184       break;
11185
11186     case I387_FLOOR:
11187       if (mode == I387_CW_FLOOR)
11188         return mode;
11189       break;
11190
11191     case I387_CEIL:
11192       if (mode == I387_CW_CEIL)
11193         return mode;
11194       break;
11195
11196     case I387_MASK_PM:
11197       if (mode == I387_CW_MASK_PM)
11198         return mode;
11199       break;
11200
11201     default:
11202       gcc_unreachable ();
11203     }
11204
11205   return I387_CW_ANY;
11206 }
11207
11208 /* Output code to initialize control word copies used by trunc?f?i and
11209    rounding patterns.  CURRENT_MODE is set to current control word,
11210    while NEW_MODE is set to new control word.  */
11211
11212 void
11213 emit_i387_cw_initialization (int mode)
11214 {
11215   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
11216   rtx new_mode;
11217
11218   enum ix86_stack_slot slot;
11219
11220   rtx reg = gen_reg_rtx (HImode);
11221
11222   emit_insn (gen_x86_fnstcw_1 (stored_mode));
11223   emit_move_insn (reg, copy_rtx (stored_mode));
11224
11225   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL || optimize_size)
11226     {
11227       switch (mode)
11228         {
11229         case I387_CW_TRUNC:
11230           /* round toward zero (truncate) */
11231           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
11232           slot = SLOT_CW_TRUNC;
11233           break;
11234
11235         case I387_CW_FLOOR:
11236           /* round down toward -oo */
11237           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11238           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
11239           slot = SLOT_CW_FLOOR;
11240           break;
11241
11242         case I387_CW_CEIL:
11243           /* round up toward +oo */
11244           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11245           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
11246           slot = SLOT_CW_CEIL;
11247           break;
11248
11249         case I387_CW_MASK_PM:
11250           /* mask precision exception for nearbyint() */
11251           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11252           slot = SLOT_CW_MASK_PM;
11253           break;
11254
11255         default:
11256           gcc_unreachable ();
11257         }
11258     }
11259   else
11260     {
11261       switch (mode)
11262         {
11263         case I387_CW_TRUNC:
11264           /* round toward zero (truncate) */
11265           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
11266           slot = SLOT_CW_TRUNC;
11267           break;
11268
11269         case I387_CW_FLOOR:
11270           /* round down toward -oo */
11271           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
11272           slot = SLOT_CW_FLOOR;
11273           break;
11274
11275         case I387_CW_CEIL:
11276           /* round up toward +oo */
11277           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
11278           slot = SLOT_CW_CEIL;
11279           break;
11280
11281         case I387_CW_MASK_PM:
11282           /* mask precision exception for nearbyint() */
11283           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11284           slot = SLOT_CW_MASK_PM;
11285           break;
11286
11287         default:
11288           gcc_unreachable ();
11289         }
11290     }
11291
11292   gcc_assert (slot < MAX_386_STACK_LOCALS);
11293
11294   new_mode = assign_386_stack_local (HImode, slot);
11295   emit_move_insn (new_mode, reg);
11296 }
11297
11298 /* Output code for INSN to convert a float to a signed int.  OPERANDS
11299    are the insn operands.  The output may be [HSD]Imode and the input
11300    operand may be [SDX]Fmode.  */
11301
11302 const char *
11303 output_fix_trunc (rtx insn, rtx *operands, int fisttp)
11304 {
11305   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11306   int dimode_p = GET_MODE (operands[0]) == DImode;
11307   int round_mode = get_attr_i387_cw (insn);
11308
11309   /* Jump through a hoop or two for DImode, since the hardware has no
11310      non-popping instruction.  We used to do this a different way, but
11311      that was somewhat fragile and broke with post-reload splitters.  */
11312   if ((dimode_p || fisttp) && !stack_top_dies)
11313     output_asm_insn ("fld\t%y1", operands);
11314
11315   gcc_assert (STACK_TOP_P (operands[1]));
11316   gcc_assert (MEM_P (operands[0]));
11317   gcc_assert (GET_MODE (operands[1]) != TFmode);
11318
11319   if (fisttp)
11320       output_asm_insn ("fisttp%z0\t%0", operands);
11321   else
11322     {
11323       if (round_mode != I387_CW_ANY)
11324         output_asm_insn ("fldcw\t%3", operands);
11325       if (stack_top_dies || dimode_p)
11326         output_asm_insn ("fistp%z0\t%0", operands);
11327       else
11328         output_asm_insn ("fist%z0\t%0", operands);
11329       if (round_mode != I387_CW_ANY)
11330         output_asm_insn ("fldcw\t%2", operands);
11331     }
11332
11333   return "";
11334 }
11335
11336 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
11337    have the values zero or one, indicates the ffreep insn's operand
11338    from the OPERANDS array.  */
11339
11340 static const char *
11341 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
11342 {
11343   if (TARGET_USE_FFREEP)
11344 #if HAVE_AS_IX86_FFREEP
11345     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
11346 #else
11347     {
11348       static char retval[] = ".word\t0xc_df";
11349       int regno = REGNO (operands[opno]);
11350
11351       gcc_assert (FP_REGNO_P (regno));
11352
11353       retval[9] = '0' + (regno - FIRST_STACK_REG);
11354       return retval;
11355     }
11356 #endif
11357
11358   return opno ? "fstp\t%y1" : "fstp\t%y0";
11359 }
11360
11361
11362 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
11363    should be used.  UNORDERED_P is true when fucom should be used.  */
11364
11365 const char *
11366 output_fp_compare (rtx insn, rtx *operands, int eflags_p, int unordered_p)
11367 {
11368   int stack_top_dies;
11369   rtx cmp_op0, cmp_op1;
11370   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
11371
11372   if (eflags_p)
11373     {
11374       cmp_op0 = operands[0];
11375       cmp_op1 = operands[1];
11376     }
11377   else
11378     {
11379       cmp_op0 = operands[1];
11380       cmp_op1 = operands[2];
11381     }
11382
11383   if (is_sse)
11384     {
11385       if (GET_MODE (operands[0]) == SFmode)
11386         if (unordered_p)
11387           return "ucomiss\t{%1, %0|%0, %1}";
11388         else
11389           return "comiss\t{%1, %0|%0, %1}";
11390       else
11391         if (unordered_p)
11392           return "ucomisd\t{%1, %0|%0, %1}";
11393         else
11394           return "comisd\t{%1, %0|%0, %1}";
11395     }
11396
11397   gcc_assert (STACK_TOP_P (cmp_op0));
11398
11399   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11400
11401   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
11402     {
11403       if (stack_top_dies)
11404         {
11405           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
11406           return output_387_ffreep (operands, 1);
11407         }
11408       else
11409         return "ftst\n\tfnstsw\t%0";
11410     }
11411
11412   if (STACK_REG_P (cmp_op1)
11413       && stack_top_dies
11414       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
11415       && REGNO (cmp_op1) != FIRST_STACK_REG)
11416     {
11417       /* If both the top of the 387 stack dies, and the other operand
11418          is also a stack register that dies, then this must be a
11419          `fcompp' float compare */
11420
11421       if (eflags_p)
11422         {
11423           /* There is no double popping fcomi variant.  Fortunately,
11424              eflags is immune from the fstp's cc clobbering.  */
11425           if (unordered_p)
11426             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
11427           else
11428             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
11429           return output_387_ffreep (operands, 0);
11430         }
11431       else
11432         {
11433           if (unordered_p)
11434             return "fucompp\n\tfnstsw\t%0";
11435           else
11436             return "fcompp\n\tfnstsw\t%0";
11437         }
11438     }
11439   else
11440     {
11441       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
11442
11443       static const char * const alt[16] =
11444       {
11445         "fcom%z2\t%y2\n\tfnstsw\t%0",
11446         "fcomp%z2\t%y2\n\tfnstsw\t%0",
11447         "fucom%z2\t%y2\n\tfnstsw\t%0",
11448         "fucomp%z2\t%y2\n\tfnstsw\t%0",
11449
11450         "ficom%z2\t%y2\n\tfnstsw\t%0",
11451         "ficomp%z2\t%y2\n\tfnstsw\t%0",
11452         NULL,
11453         NULL,
11454
11455         "fcomi\t{%y1, %0|%0, %y1}",
11456         "fcomip\t{%y1, %0|%0, %y1}",
11457         "fucomi\t{%y1, %0|%0, %y1}",
11458         "fucomip\t{%y1, %0|%0, %y1}",
11459
11460         NULL,
11461         NULL,
11462         NULL,
11463         NULL
11464       };
11465
11466       int mask;
11467       const char *ret;
11468
11469       mask  = eflags_p << 3;
11470       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
11471       mask |= unordered_p << 1;
11472       mask |= stack_top_dies;
11473
11474       gcc_assert (mask < 16);
11475       ret = alt[mask];
11476       gcc_assert (ret);
11477
11478       return ret;
11479     }
11480 }
11481
11482 void
11483 ix86_output_addr_vec_elt (FILE *file, int value)
11484 {
11485   const char *directive = ASM_LONG;
11486
11487 #ifdef ASM_QUAD
11488   if (TARGET_64BIT)
11489     directive = ASM_QUAD;
11490 #else
11491   gcc_assert (!TARGET_64BIT);
11492 #endif
11493
11494   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
11495 }
11496
11497 void
11498 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
11499 {
11500   const char *directive = ASM_LONG;
11501
11502 #ifdef ASM_QUAD
11503   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
11504     directive = ASM_QUAD;
11505 #else
11506   gcc_assert (!TARGET_64BIT);
11507 #endif
11508   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
11509   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
11510     fprintf (file, "%s%s%d-%s%d\n",
11511              directive, LPREFIX, value, LPREFIX, rel);
11512   else if (HAVE_AS_GOTOFF_IN_DATA)
11513     fprintf (file, "%s%s%d@GOTOFF\n", ASM_LONG, LPREFIX, value);
11514 #if TARGET_MACHO
11515   else if (TARGET_MACHO)
11516     {
11517       fprintf (file, "%s%s%d-", ASM_LONG, LPREFIX, value);
11518       machopic_output_function_base_name (file);
11519       fprintf(file, "\n");
11520     }
11521 #endif
11522   else
11523     asm_fprintf (file, "%s%U%s+[.-%s%d]\n",
11524                  ASM_LONG, GOT_SYMBOL_NAME, LPREFIX, value);
11525 }
11526 \f
11527 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
11528    for the target.  */
11529
11530 void
11531 ix86_expand_clear (rtx dest)
11532 {
11533   rtx tmp;
11534
11535   /* We play register width games, which are only valid after reload.  */
11536   gcc_assert (reload_completed);
11537
11538   /* Avoid HImode and its attendant prefix byte.  */
11539   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
11540     dest = gen_rtx_REG (SImode, REGNO (dest));
11541   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
11542
11543   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
11544   if (reload_completed && (!TARGET_USE_MOV0 || optimize_size))
11545     {
11546       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
11547       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
11548     }
11549
11550   emit_insn (tmp);
11551 }
11552
11553 /* X is an unchanging MEM.  If it is a constant pool reference, return
11554    the constant pool rtx, else NULL.  */
11555
11556 rtx
11557 maybe_get_pool_constant (rtx x)
11558 {
11559   x = ix86_delegitimize_address (XEXP (x, 0));
11560
11561   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
11562     return get_pool_constant (x);
11563
11564   return NULL_RTX;
11565 }
11566
11567 void
11568 ix86_expand_move (enum machine_mode mode, rtx operands[])
11569 {
11570   rtx op0, op1;
11571   enum tls_model model;
11572
11573   op0 = operands[0];
11574   op1 = operands[1];
11575
11576   if (GET_CODE (op1) == SYMBOL_REF)
11577     {
11578       model = SYMBOL_REF_TLS_MODEL (op1);
11579       if (model)
11580         {
11581           op1 = legitimize_tls_address (op1, model, true);
11582           op1 = force_operand (op1, op0);
11583           if (op1 == op0)
11584             return;
11585         }
11586       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
11587                && SYMBOL_REF_DLLIMPORT_P (op1))
11588         op1 = legitimize_dllimport_symbol (op1, false);
11589     }
11590   else if (GET_CODE (op1) == CONST
11591            && GET_CODE (XEXP (op1, 0)) == PLUS
11592            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
11593     {
11594       rtx addend = XEXP (XEXP (op1, 0), 1);
11595       rtx symbol = XEXP (XEXP (op1, 0), 0);
11596       rtx tmp = NULL;
11597
11598       model = SYMBOL_REF_TLS_MODEL (symbol);
11599       if (model)
11600         tmp = legitimize_tls_address (symbol, model, true);
11601       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
11602                && SYMBOL_REF_DLLIMPORT_P (symbol))
11603         tmp = legitimize_dllimport_symbol (symbol, true);
11604
11605       if (tmp)
11606         {
11607           tmp = force_operand (tmp, NULL);
11608           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
11609                                      op0, 1, OPTAB_DIRECT);
11610           if (tmp == op0)
11611             return;
11612         }
11613     }
11614
11615   if (flag_pic && mode == Pmode && symbolic_operand (op1, Pmode))
11616     {
11617       if (TARGET_MACHO && !TARGET_64BIT)
11618         {
11619 #if TARGET_MACHO
11620           if (MACHOPIC_PURE)
11621             {
11622               rtx temp = ((reload_in_progress
11623                            || ((op0 && REG_P (op0))
11624                                && mode == Pmode))
11625                           ? op0 : gen_reg_rtx (Pmode));
11626               op1 = machopic_indirect_data_reference (op1, temp);
11627               op1 = machopic_legitimize_pic_address (op1, mode,
11628                                                      temp == op1 ? 0 : temp);
11629             }
11630           else if (MACHOPIC_INDIRECT)
11631             op1 = machopic_indirect_data_reference (op1, 0);
11632           if (op0 == op1)
11633             return;
11634 #endif
11635         }
11636       else
11637         {
11638           if (MEM_P (op0))
11639             op1 = force_reg (Pmode, op1);
11640           else if (!TARGET_64BIT || !x86_64_movabs_operand (op1, Pmode))
11641             {
11642               rtx reg = !can_create_pseudo_p () ? op0 : NULL_RTX;
11643               op1 = legitimize_pic_address (op1, reg);
11644               if (op0 == op1)
11645                 return;
11646             }
11647         }
11648     }
11649   else
11650     {
11651       if (MEM_P (op0)
11652           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
11653               || !push_operand (op0, mode))
11654           && MEM_P (op1))
11655         op1 = force_reg (mode, op1);
11656
11657       if (push_operand (op0, mode)
11658           && ! general_no_elim_operand (op1, mode))
11659         op1 = copy_to_mode_reg (mode, op1);
11660
11661       /* Force large constants in 64bit compilation into register
11662          to get them CSEed.  */
11663       if (can_create_pseudo_p ()
11664           && (mode == DImode) && TARGET_64BIT
11665           && immediate_operand (op1, mode)
11666           && !x86_64_zext_immediate_operand (op1, VOIDmode)
11667           && !register_operand (op0, mode)
11668           && optimize)
11669         op1 = copy_to_mode_reg (mode, op1);
11670
11671       if (can_create_pseudo_p ()
11672           && FLOAT_MODE_P (mode)
11673           && GET_CODE (op1) == CONST_DOUBLE)
11674         {
11675           /* If we are loading a floating point constant to a register,
11676              force the value to memory now, since we'll get better code
11677              out the back end.  */
11678
11679           op1 = validize_mem (force_const_mem (mode, op1));
11680           if (!register_operand (op0, mode))
11681             {
11682               rtx temp = gen_reg_rtx (mode);
11683               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
11684               emit_move_insn (op0, temp);
11685               return;
11686             }
11687         }
11688     }
11689
11690   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
11691 }
11692
11693 void
11694 ix86_expand_vector_move (enum machine_mode mode, rtx operands[])
11695 {
11696   rtx op0 = operands[0], op1 = operands[1];
11697   unsigned int align = GET_MODE_ALIGNMENT (mode);
11698
11699   /* Force constants other than zero into memory.  We do not know how
11700      the instructions used to build constants modify the upper 64 bits
11701      of the register, once we have that information we may be able
11702      to handle some of them more efficiently.  */
11703   if (can_create_pseudo_p ()
11704       && register_operand (op0, mode)
11705       && (CONSTANT_P (op1)
11706           || (GET_CODE (op1) == SUBREG
11707               && CONSTANT_P (SUBREG_REG (op1))))
11708       && standard_sse_constant_p (op1) <= 0)
11709     op1 = validize_mem (force_const_mem (mode, op1));
11710
11711   /* We need to check memory alignment for SSE mode since attribute
11712      can make operands unaligned.  */
11713   if (can_create_pseudo_p ()
11714       && SSE_REG_MODE_P (mode)
11715       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
11716           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
11717     {
11718       rtx tmp[2];
11719
11720       /* ix86_expand_vector_move_misalign() does not like constants ... */
11721       if (CONSTANT_P (op1)
11722           || (GET_CODE (op1) == SUBREG
11723               && CONSTANT_P (SUBREG_REG (op1))))
11724         op1 = validize_mem (force_const_mem (mode, op1));
11725
11726       /* ... nor both arguments in memory.  */
11727       if (!register_operand (op0, mode)
11728           && !register_operand (op1, mode))
11729         op1 = force_reg (mode, op1);
11730
11731       tmp[0] = op0; tmp[1] = op1;
11732       ix86_expand_vector_move_misalign (mode, tmp);
11733       return;
11734     }
11735
11736   /* Make operand1 a register if it isn't already.  */
11737   if (can_create_pseudo_p ()
11738       && !register_operand (op0, mode)
11739       && !register_operand (op1, mode))
11740     {
11741       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
11742       return;
11743     }
11744
11745   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
11746 }
11747
11748 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
11749    straight to ix86_expand_vector_move.  */
11750 /* Code generation for scalar reg-reg moves of single and double precision data:
11751      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
11752        movaps reg, reg
11753      else
11754        movss reg, reg
11755      if (x86_sse_partial_reg_dependency == true)
11756        movapd reg, reg
11757      else
11758        movsd reg, reg
11759
11760    Code generation for scalar loads of double precision data:
11761      if (x86_sse_split_regs == true)
11762        movlpd mem, reg      (gas syntax)
11763      else
11764        movsd mem, reg
11765
11766    Code generation for unaligned packed loads of single precision data
11767    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
11768      if (x86_sse_unaligned_move_optimal)
11769        movups mem, reg
11770
11771      if (x86_sse_partial_reg_dependency == true)
11772        {
11773          xorps  reg, reg
11774          movlps mem, reg
11775          movhps mem+8, reg
11776        }
11777      else
11778        {
11779          movlps mem, reg
11780          movhps mem+8, reg
11781        }
11782
11783    Code generation for unaligned packed loads of double precision data
11784    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
11785      if (x86_sse_unaligned_move_optimal)
11786        movupd mem, reg
11787
11788      if (x86_sse_split_regs == true)
11789        {
11790          movlpd mem, reg
11791          movhpd mem+8, reg
11792        }
11793      else
11794        {
11795          movsd  mem, reg
11796          movhpd mem+8, reg
11797        }
11798  */
11799
11800 void
11801 ix86_expand_vector_move_misalign (enum machine_mode mode, rtx operands[])
11802 {
11803   rtx op0, op1, m;
11804
11805   op0 = operands[0];
11806   op1 = operands[1];
11807
11808   if (MEM_P (op1))
11809     {
11810       /* If we're optimizing for size, movups is the smallest.  */
11811       if (optimize_insn_for_size_p ())
11812         {
11813           op0 = gen_lowpart (V4SFmode, op0);
11814           op1 = gen_lowpart (V4SFmode, op1);
11815           emit_insn (gen_sse_movups (op0, op1));
11816           return;
11817         }
11818
11819       /* ??? If we have typed data, then it would appear that using
11820          movdqu is the only way to get unaligned data loaded with
11821          integer type.  */
11822       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
11823         {
11824           op0 = gen_lowpart (V16QImode, op0);
11825           op1 = gen_lowpart (V16QImode, op1);
11826           emit_insn (gen_sse2_movdqu (op0, op1));
11827           return;
11828         }
11829
11830       if (TARGET_SSE2 && mode == V2DFmode)
11831         {
11832           rtx zero;
11833
11834           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
11835             {
11836               op0 = gen_lowpart (V2DFmode, op0);
11837               op1 = gen_lowpart (V2DFmode, op1);
11838               emit_insn (gen_sse2_movupd (op0, op1));
11839               return;
11840             }
11841
11842           /* When SSE registers are split into halves, we can avoid
11843              writing to the top half twice.  */
11844           if (TARGET_SSE_SPLIT_REGS)
11845             {
11846               emit_clobber (op0);
11847               zero = op0;
11848             }
11849           else
11850             {
11851               /* ??? Not sure about the best option for the Intel chips.
11852                  The following would seem to satisfy; the register is
11853                  entirely cleared, breaking the dependency chain.  We
11854                  then store to the upper half, with a dependency depth
11855                  of one.  A rumor has it that Intel recommends two movsd
11856                  followed by an unpacklpd, but this is unconfirmed.  And
11857                  given that the dependency depth of the unpacklpd would
11858                  still be one, I'm not sure why this would be better.  */
11859               zero = CONST0_RTX (V2DFmode);
11860             }
11861
11862           m = adjust_address (op1, DFmode, 0);
11863           emit_insn (gen_sse2_loadlpd (op0, zero, m));
11864           m = adjust_address (op1, DFmode, 8);
11865           emit_insn (gen_sse2_loadhpd (op0, op0, m));
11866         }
11867       else
11868         {
11869           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
11870             {
11871               op0 = gen_lowpart (V4SFmode, op0);
11872               op1 = gen_lowpart (V4SFmode, op1);
11873               emit_insn (gen_sse_movups (op0, op1));
11874               return;
11875             }
11876
11877           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
11878             emit_move_insn (op0, CONST0_RTX (mode));
11879           else
11880             emit_clobber (op0);
11881
11882           if (mode != V4SFmode)
11883             op0 = gen_lowpart (V4SFmode, op0);
11884           m = adjust_address (op1, V2SFmode, 0);
11885           emit_insn (gen_sse_loadlps (op0, op0, m));
11886           m = adjust_address (op1, V2SFmode, 8);
11887           emit_insn (gen_sse_loadhps (op0, op0, m));
11888         }
11889     }
11890   else if (MEM_P (op0))
11891     {
11892       /* If we're optimizing for size, movups is the smallest.  */
11893       if (optimize_insn_for_size_p ())
11894         {
11895           op0 = gen_lowpart (V4SFmode, op0);
11896           op1 = gen_lowpart (V4SFmode, op1);
11897           emit_insn (gen_sse_movups (op0, op1));
11898           return;
11899         }
11900
11901       /* ??? Similar to above, only less clear because of quote
11902          typeless stores unquote.  */
11903       if (TARGET_SSE2 && !TARGET_SSE_TYPELESS_STORES
11904           && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
11905         {
11906           op0 = gen_lowpart (V16QImode, op0);
11907           op1 = gen_lowpart (V16QImode, op1);
11908           emit_insn (gen_sse2_movdqu (op0, op1));
11909           return;
11910         }
11911
11912       if (TARGET_SSE2 && mode == V2DFmode)
11913         {
11914           m = adjust_address (op0, DFmode, 0);
11915           emit_insn (gen_sse2_storelpd (m, op1));
11916           m = adjust_address (op0, DFmode, 8);
11917           emit_insn (gen_sse2_storehpd (m, op1));
11918         }
11919       else
11920         {
11921           if (mode != V4SFmode)
11922             op1 = gen_lowpart (V4SFmode, op1);
11923           m = adjust_address (op0, V2SFmode, 0);
11924           emit_insn (gen_sse_storelps (m, op1));
11925           m = adjust_address (op0, V2SFmode, 8);
11926           emit_insn (gen_sse_storehps (m, op1));
11927         }
11928     }
11929   else
11930     gcc_unreachable ();
11931 }
11932
11933 /* Expand a push in MODE.  This is some mode for which we do not support
11934    proper push instructions, at least from the registers that we expect
11935    the value to live in.  */
11936
11937 void
11938 ix86_expand_push (enum machine_mode mode, rtx x)
11939 {
11940   rtx tmp;
11941
11942   tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
11943                              GEN_INT (-GET_MODE_SIZE (mode)),
11944                              stack_pointer_rtx, 1, OPTAB_DIRECT);
11945   if (tmp != stack_pointer_rtx)
11946     emit_move_insn (stack_pointer_rtx, tmp);
11947
11948   tmp = gen_rtx_MEM (mode, stack_pointer_rtx);
11949   emit_move_insn (tmp, x);
11950 }
11951
11952 /* Helper function of ix86_fixup_binary_operands to canonicalize
11953    operand order.  Returns true if the operands should be swapped.  */
11954
11955 static bool
11956 ix86_swap_binary_operands_p (enum rtx_code code, enum machine_mode mode,
11957                              rtx operands[])
11958 {
11959   rtx dst = operands[0];
11960   rtx src1 = operands[1];
11961   rtx src2 = operands[2];
11962
11963   /* If the operation is not commutative, we can't do anything.  */
11964   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
11965     return false;
11966
11967   /* Highest priority is that src1 should match dst.  */
11968   if (rtx_equal_p (dst, src1))
11969     return false;
11970   if (rtx_equal_p (dst, src2))
11971     return true;
11972
11973   /* Next highest priority is that immediate constants come second.  */
11974   if (immediate_operand (src2, mode))
11975     return false;
11976   if (immediate_operand (src1, mode))
11977     return true;
11978
11979   /* Lowest priority is that memory references should come second.  */
11980   if (MEM_P (src2))
11981     return false;
11982   if (MEM_P (src1))
11983     return true;
11984
11985   return false;
11986 }
11987
11988
11989 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
11990    destination to use for the operation.  If different from the true
11991    destination in operands[0], a copy operation will be required.  */
11992
11993 rtx
11994 ix86_fixup_binary_operands (enum rtx_code code, enum machine_mode mode,
11995                             rtx operands[])
11996 {
11997   rtx dst = operands[0];
11998   rtx src1 = operands[1];
11999   rtx src2 = operands[2];
12000
12001   /* Canonicalize operand order.  */
12002   if (ix86_swap_binary_operands_p (code, mode, operands))
12003     {
12004       rtx temp;
12005
12006       /* It is invalid to swap operands of different modes.  */
12007       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
12008
12009       temp = src1;
12010       src1 = src2;
12011       src2 = temp;
12012     }
12013
12014   /* Both source operands cannot be in memory.  */
12015   if (MEM_P (src1) && MEM_P (src2))
12016     {
12017       /* Optimization: Only read from memory once.  */
12018       if (rtx_equal_p (src1, src2))
12019         {
12020           src2 = force_reg (mode, src2);
12021           src1 = src2;
12022         }
12023       else
12024         src2 = force_reg (mode, src2);
12025     }
12026
12027   /* If the destination is memory, and we do not have matching source
12028      operands, do things in registers.  */
12029   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12030     dst = gen_reg_rtx (mode);
12031
12032   /* Source 1 cannot be a constant.  */
12033   if (CONSTANT_P (src1))
12034     src1 = force_reg (mode, src1);
12035
12036   /* Source 1 cannot be a non-matching memory.  */
12037   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12038     src1 = force_reg (mode, src1);
12039
12040   operands[1] = src1;
12041   operands[2] = src2;
12042   return dst;
12043 }
12044
12045 /* Similarly, but assume that the destination has already been
12046    set up properly.  */
12047
12048 void
12049 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
12050                                     enum machine_mode mode, rtx operands[])
12051 {
12052   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
12053   gcc_assert (dst == operands[0]);
12054 }
12055
12056 /* Attempt to expand a binary operator.  Make the expansion closer to the
12057    actual machine, then just general_operand, which will allow 3 separate
12058    memory references (one output, two input) in a single insn.  */
12059
12060 void
12061 ix86_expand_binary_operator (enum rtx_code code, enum machine_mode mode,
12062                              rtx operands[])
12063 {
12064   rtx src1, src2, dst, op, clob;
12065
12066   dst = ix86_fixup_binary_operands (code, mode, operands);
12067   src1 = operands[1];
12068   src2 = operands[2];
12069
12070  /* Emit the instruction.  */
12071
12072   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
12073   if (reload_in_progress)
12074     {
12075       /* Reload doesn't know about the flags register, and doesn't know that
12076          it doesn't want to clobber it.  We can only do this with PLUS.  */
12077       gcc_assert (code == PLUS);
12078       emit_insn (op);
12079     }
12080   else
12081     {
12082       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12083       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12084     }
12085
12086   /* Fix up the destination if needed.  */
12087   if (dst != operands[0])
12088     emit_move_insn (operands[0], dst);
12089 }
12090
12091 /* Return TRUE or FALSE depending on whether the binary operator meets the
12092    appropriate constraints.  */
12093
12094 int
12095 ix86_binary_operator_ok (enum rtx_code code, enum machine_mode mode,
12096                          rtx operands[3])
12097 {
12098   rtx dst = operands[0];
12099   rtx src1 = operands[1];
12100   rtx src2 = operands[2];
12101
12102   /* Both source operands cannot be in memory.  */
12103   if (MEM_P (src1) && MEM_P (src2))
12104     return 0;
12105
12106   /* Canonicalize operand order for commutative operators.  */
12107   if (ix86_swap_binary_operands_p (code, mode, operands))
12108     {
12109       rtx temp = src1;
12110       src1 = src2;
12111       src2 = temp;
12112     }
12113
12114   /* If the destination is memory, we must have a matching source operand.  */
12115   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12116       return 0;
12117
12118   /* Source 1 cannot be a constant.  */
12119   if (CONSTANT_P (src1))
12120     return 0;
12121
12122   /* Source 1 cannot be a non-matching memory.  */
12123   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12124     return 0;
12125
12126   return 1;
12127 }
12128
12129 /* Attempt to expand a unary operator.  Make the expansion closer to the
12130    actual machine, then just general_operand, which will allow 2 separate
12131    memory references (one output, one input) in a single insn.  */
12132
12133 void
12134 ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode,
12135                             rtx operands[])
12136 {
12137   int matching_memory;
12138   rtx src, dst, op, clob;
12139
12140   dst = operands[0];
12141   src = operands[1];
12142
12143   /* If the destination is memory, and we do not have matching source
12144      operands, do things in registers.  */
12145   matching_memory = 0;
12146   if (MEM_P (dst))
12147     {
12148       if (rtx_equal_p (dst, src))
12149         matching_memory = 1;
12150       else
12151         dst = gen_reg_rtx (mode);
12152     }
12153
12154   /* When source operand is memory, destination must match.  */
12155   if (MEM_P (src) && !matching_memory)
12156     src = force_reg (mode, src);
12157
12158   /* Emit the instruction.  */
12159
12160   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
12161   if (reload_in_progress || code == NOT)
12162     {
12163       /* Reload doesn't know about the flags register, and doesn't know that
12164          it doesn't want to clobber it.  */
12165       gcc_assert (code == NOT);
12166       emit_insn (op);
12167     }
12168   else
12169     {
12170       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12171       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12172     }
12173
12174   /* Fix up the destination if needed.  */
12175   if (dst != operands[0])
12176     emit_move_insn (operands[0], dst);
12177 }
12178
12179 /* Return TRUE or FALSE depending on whether the unary operator meets the
12180    appropriate constraints.  */
12181
12182 int
12183 ix86_unary_operator_ok (enum rtx_code code ATTRIBUTE_UNUSED,
12184                         enum machine_mode mode ATTRIBUTE_UNUSED,
12185                         rtx operands[2] ATTRIBUTE_UNUSED)
12186 {
12187   /* If one of operands is memory, source and destination must match.  */
12188   if ((MEM_P (operands[0])
12189        || MEM_P (operands[1]))
12190       && ! rtx_equal_p (operands[0], operands[1]))
12191     return FALSE;
12192   return TRUE;
12193 }
12194
12195 /* Post-reload splitter for converting an SF or DFmode value in an
12196    SSE register into an unsigned SImode.  */
12197
12198 void
12199 ix86_split_convert_uns_si_sse (rtx operands[])
12200 {
12201   enum machine_mode vecmode;
12202   rtx value, large, zero_or_two31, input, two31, x;
12203
12204   large = operands[1];
12205   zero_or_two31 = operands[2];
12206   input = operands[3];
12207   two31 = operands[4];
12208   vecmode = GET_MODE (large);
12209   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
12210
12211   /* Load up the value into the low element.  We must ensure that the other
12212      elements are valid floats -- zero is the easiest such value.  */
12213   if (MEM_P (input))
12214     {
12215       if (vecmode == V4SFmode)
12216         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
12217       else
12218         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
12219     }
12220   else
12221     {
12222       input = gen_rtx_REG (vecmode, REGNO (input));
12223       emit_move_insn (value, CONST0_RTX (vecmode));
12224       if (vecmode == V4SFmode)
12225         emit_insn (gen_sse_movss (value, value, input));
12226       else
12227         emit_insn (gen_sse2_movsd (value, value, input));
12228     }
12229
12230   emit_move_insn (large, two31);
12231   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
12232
12233   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
12234   emit_insn (gen_rtx_SET (VOIDmode, large, x));
12235
12236   x = gen_rtx_AND (vecmode, zero_or_two31, large);
12237   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
12238
12239   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
12240   emit_insn (gen_rtx_SET (VOIDmode, value, x));
12241
12242   large = gen_rtx_REG (V4SImode, REGNO (large));
12243   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
12244
12245   x = gen_rtx_REG (V4SImode, REGNO (value));
12246   if (vecmode == V4SFmode)
12247     emit_insn (gen_sse2_cvttps2dq (x, value));
12248   else
12249     emit_insn (gen_sse2_cvttpd2dq (x, value));
12250   value = x;
12251
12252   emit_insn (gen_xorv4si3 (value, value, large));
12253 }
12254
12255 /* Convert an unsigned DImode value into a DFmode, using only SSE.
12256    Expects the 64-bit DImode to be supplied in a pair of integral
12257    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
12258    -mfpmath=sse, !optimize_size only.  */
12259
12260 void
12261 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
12262 {
12263   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
12264   rtx int_xmm, fp_xmm;
12265   rtx biases, exponents;
12266   rtx x;
12267
12268   int_xmm = gen_reg_rtx (V4SImode);
12269   if (TARGET_INTER_UNIT_MOVES)
12270     emit_insn (gen_movdi_to_sse (int_xmm, input));
12271   else if (TARGET_SSE_SPLIT_REGS)
12272     {
12273       emit_clobber (int_xmm);
12274       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
12275     }
12276   else
12277     {
12278       x = gen_reg_rtx (V2DImode);
12279       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
12280       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
12281     }
12282
12283   x = gen_rtx_CONST_VECTOR (V4SImode,
12284                             gen_rtvec (4, GEN_INT (0x43300000UL),
12285                                        GEN_INT (0x45300000UL),
12286                                        const0_rtx, const0_rtx));
12287   exponents = validize_mem (force_const_mem (V4SImode, x));
12288
12289   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
12290   emit_insn (gen_sse2_punpckldq (int_xmm, int_xmm, exponents));
12291
12292   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
12293      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
12294      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
12295      (0x1.0p84 + double(fp_value_hi_xmm)).
12296      Note these exponents differ by 32.  */
12297
12298   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
12299
12300   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
12301      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
12302   real_ldexp (&bias_lo_rvt, &dconst1, 52);
12303   real_ldexp (&bias_hi_rvt, &dconst1, 84);
12304   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
12305   x = const_double_from_real_value (bias_hi_rvt, DFmode);
12306   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
12307   biases = validize_mem (force_const_mem (V2DFmode, biases));
12308   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
12309
12310   /* Add the upper and lower DFmode values together.  */
12311   if (TARGET_SSE3)
12312     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
12313   else
12314     {
12315       x = copy_to_mode_reg (V2DFmode, fp_xmm);
12316       emit_insn (gen_sse2_unpckhpd (fp_xmm, fp_xmm, fp_xmm));
12317       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
12318     }
12319
12320   ix86_expand_vector_extract (false, target, fp_xmm, 0);
12321 }
12322
12323 /* Not used, but eases macroization of patterns.  */
12324 void
12325 ix86_expand_convert_uns_sixf_sse (rtx target ATTRIBUTE_UNUSED,
12326                                   rtx input ATTRIBUTE_UNUSED)
12327 {
12328   gcc_unreachable ();
12329 }
12330
12331 /* Convert an unsigned SImode value into a DFmode.  Only currently used
12332    for SSE, but applicable anywhere.  */
12333
12334 void
12335 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
12336 {
12337   REAL_VALUE_TYPE TWO31r;
12338   rtx x, fp;
12339
12340   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
12341                            NULL, 1, OPTAB_DIRECT);
12342
12343   fp = gen_reg_rtx (DFmode);
12344   emit_insn (gen_floatsidf2 (fp, x));
12345
12346   real_ldexp (&TWO31r, &dconst1, 31);
12347   x = const_double_from_real_value (TWO31r, DFmode);
12348
12349   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
12350   if (x != target)
12351     emit_move_insn (target, x);
12352 }
12353
12354 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
12355    32-bit mode; otherwise we have a direct convert instruction.  */
12356
12357 void
12358 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
12359 {
12360   REAL_VALUE_TYPE TWO32r;
12361   rtx fp_lo, fp_hi, x;
12362
12363   fp_lo = gen_reg_rtx (DFmode);
12364   fp_hi = gen_reg_rtx (DFmode);
12365
12366   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
12367
12368   real_ldexp (&TWO32r, &dconst1, 32);
12369   x = const_double_from_real_value (TWO32r, DFmode);
12370   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
12371
12372   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
12373
12374   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
12375                            0, OPTAB_DIRECT);
12376   if (x != target)
12377     emit_move_insn (target, x);
12378 }
12379
12380 /* Convert an unsigned SImode value into a SFmode, using only SSE.
12381    For x86_32, -mfpmath=sse, !optimize_size only.  */
12382 void
12383 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
12384 {
12385   REAL_VALUE_TYPE ONE16r;
12386   rtx fp_hi, fp_lo, int_hi, int_lo, x;
12387
12388   real_ldexp (&ONE16r, &dconst1, 16);
12389   x = const_double_from_real_value (ONE16r, SFmode);
12390   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
12391                                       NULL, 0, OPTAB_DIRECT);
12392   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
12393                                       NULL, 0, OPTAB_DIRECT);
12394   fp_hi = gen_reg_rtx (SFmode);
12395   fp_lo = gen_reg_rtx (SFmode);
12396   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
12397   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
12398   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
12399                                0, OPTAB_DIRECT);
12400   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
12401                                0, OPTAB_DIRECT);
12402   if (!rtx_equal_p (target, fp_hi))
12403     emit_move_insn (target, fp_hi);
12404 }
12405
12406 /* A subroutine of ix86_build_signbit_mask_vector.  If VECT is true,
12407    then replicate the value for all elements of the vector
12408    register.  */
12409
12410 rtx
12411 ix86_build_const_vector (enum machine_mode mode, bool vect, rtx value)
12412 {
12413   rtvec v;
12414   switch (mode)
12415     {
12416     case SImode:
12417       gcc_assert (vect);
12418       v = gen_rtvec (4, value, value, value, value);
12419       return gen_rtx_CONST_VECTOR (V4SImode, v);
12420
12421     case DImode:
12422       gcc_assert (vect);
12423       v = gen_rtvec (2, value, value);
12424       return gen_rtx_CONST_VECTOR (V2DImode, v);
12425
12426     case SFmode:
12427       if (vect)
12428         v = gen_rtvec (4, value, value, value, value);
12429       else
12430         v = gen_rtvec (4, value, CONST0_RTX (SFmode),
12431                        CONST0_RTX (SFmode), CONST0_RTX (SFmode));
12432       return gen_rtx_CONST_VECTOR (V4SFmode, v);
12433
12434     case DFmode:
12435       if (vect)
12436         v = gen_rtvec (2, value, value);
12437       else
12438         v = gen_rtvec (2, value, CONST0_RTX (DFmode));
12439       return gen_rtx_CONST_VECTOR (V2DFmode, v);
12440
12441     default:
12442       gcc_unreachable ();
12443     }
12444 }
12445
12446 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
12447    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
12448    for an SSE register.  If VECT is true, then replicate the mask for
12449    all elements of the vector register.  If INVERT is true, then create
12450    a mask excluding the sign bit.  */
12451
12452 rtx
12453 ix86_build_signbit_mask (enum machine_mode mode, bool vect, bool invert)
12454 {
12455   enum machine_mode vec_mode, imode;
12456   HOST_WIDE_INT hi, lo;
12457   int shift = 63;
12458   rtx v;
12459   rtx mask;
12460
12461   /* Find the sign bit, sign extended to 2*HWI.  */
12462   switch (mode)
12463     {
12464     case SImode:
12465     case SFmode:
12466       imode = SImode;
12467       vec_mode = (mode == SImode) ? V4SImode : V4SFmode;
12468       lo = 0x80000000, hi = lo < 0;
12469       break;
12470
12471     case DImode:
12472     case DFmode:
12473       imode = DImode;
12474       vec_mode = (mode == DImode) ? V2DImode : V2DFmode;
12475       if (HOST_BITS_PER_WIDE_INT >= 64)
12476         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
12477       else
12478         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
12479       break;
12480
12481     case TImode:
12482     case TFmode:
12483       vec_mode = VOIDmode;
12484       if (HOST_BITS_PER_WIDE_INT >= 64)
12485         {
12486           imode = TImode;
12487           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
12488         }
12489       else
12490         {
12491           rtvec vec;
12492
12493           imode = DImode;
12494           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
12495
12496           if (invert)
12497             {
12498               lo = ~lo, hi = ~hi;
12499               v = constm1_rtx;
12500             }
12501           else
12502             v = const0_rtx;
12503
12504           mask = immed_double_const (lo, hi, imode);
12505
12506           vec = gen_rtvec (2, v, mask);
12507           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
12508           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
12509
12510           return v;
12511         }
12512      break;
12513
12514     default:
12515       gcc_unreachable ();
12516     }
12517
12518   if (invert)
12519     lo = ~lo, hi = ~hi;
12520
12521   /* Force this value into the low part of a fp vector constant.  */
12522   mask = immed_double_const (lo, hi, imode);
12523   mask = gen_lowpart (mode, mask);
12524
12525   if (vec_mode == VOIDmode)
12526     return force_reg (mode, mask);
12527
12528   v = ix86_build_const_vector (mode, vect, mask);
12529   return force_reg (vec_mode, v);
12530 }
12531
12532 /* Generate code for floating point ABS or NEG.  */
12533
12534 void
12535 ix86_expand_fp_absneg_operator (enum rtx_code code, enum machine_mode mode,
12536                                 rtx operands[])
12537 {
12538   rtx mask, set, use, clob, dst, src;
12539   bool use_sse = false;
12540   bool vector_mode = VECTOR_MODE_P (mode);
12541   enum machine_mode elt_mode = mode;
12542
12543   if (vector_mode)
12544     {
12545       elt_mode = GET_MODE_INNER (mode);
12546       use_sse = true;
12547     }
12548   else if (mode == TFmode)
12549     use_sse = true;
12550   else if (TARGET_SSE_MATH)
12551     use_sse = SSE_FLOAT_MODE_P (mode);
12552
12553   /* NEG and ABS performed with SSE use bitwise mask operations.
12554      Create the appropriate mask now.  */
12555   if (use_sse)
12556     mask = ix86_build_signbit_mask (elt_mode, vector_mode, code == ABS);
12557   else
12558     mask = NULL_RTX;
12559
12560   dst = operands[0];
12561   src = operands[1];
12562
12563   if (vector_mode)
12564     {
12565       set = gen_rtx_fmt_ee (code == NEG ? XOR : AND, mode, src, mask);
12566       set = gen_rtx_SET (VOIDmode, dst, set);
12567       emit_insn (set);
12568     }
12569   else
12570     {
12571       set = gen_rtx_fmt_e (code, mode, src);
12572       set = gen_rtx_SET (VOIDmode, dst, set);
12573       if (mask)
12574         {
12575           use = gen_rtx_USE (VOIDmode, mask);
12576           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12577           emit_insn (gen_rtx_PARALLEL (VOIDmode,
12578                                        gen_rtvec (3, set, use, clob)));
12579         }
12580       else
12581         emit_insn (set);
12582     }
12583 }
12584
12585 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
12586
12587 void
12588 ix86_expand_copysign (rtx operands[])
12589 {
12590   enum machine_mode mode;
12591   rtx dest, op0, op1, mask, nmask;
12592
12593   dest = operands[0];
12594   op0 = operands[1];
12595   op1 = operands[2];
12596
12597   mode = GET_MODE (dest);
12598
12599   if (GET_CODE (op0) == CONST_DOUBLE)
12600     {
12601       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
12602
12603       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
12604         op0 = simplify_unary_operation (ABS, mode, op0, mode);
12605
12606       if (mode == SFmode || mode == DFmode)
12607         {
12608           enum machine_mode vmode;
12609
12610           vmode = mode == SFmode ? V4SFmode : V2DFmode;
12611
12612           if (op0 == CONST0_RTX (mode))
12613             op0 = CONST0_RTX (vmode);
12614           else
12615             {
12616               rtvec v;
12617
12618               if (mode == SFmode)
12619                 v = gen_rtvec (4, op0, CONST0_RTX (SFmode),
12620                                CONST0_RTX (SFmode), CONST0_RTX (SFmode));
12621               else
12622                 v = gen_rtvec (2, op0, CONST0_RTX (DFmode));
12623
12624               op0 = force_reg (vmode, gen_rtx_CONST_VECTOR (vmode, v));
12625             }
12626         }
12627       else if (op0 != CONST0_RTX (mode))
12628         op0 = force_reg (mode, op0);
12629
12630       mask = ix86_build_signbit_mask (mode, 0, 0);
12631
12632       if (mode == SFmode)
12633         copysign_insn = gen_copysignsf3_const;
12634       else if (mode == DFmode)
12635         copysign_insn = gen_copysigndf3_const;
12636       else
12637         copysign_insn = gen_copysigntf3_const;
12638
12639         emit_insn (copysign_insn (dest, op0, op1, mask));
12640     }
12641   else
12642     {
12643       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
12644
12645       nmask = ix86_build_signbit_mask (mode, 0, 1);
12646       mask = ix86_build_signbit_mask (mode, 0, 0);
12647
12648       if (mode == SFmode)
12649         copysign_insn = gen_copysignsf3_var;
12650       else if (mode == DFmode)
12651         copysign_insn = gen_copysigndf3_var;
12652       else
12653         copysign_insn = gen_copysigntf3_var;
12654
12655       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
12656     }
12657 }
12658
12659 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
12660    be a constant, and so has already been expanded into a vector constant.  */
12661
12662 void
12663 ix86_split_copysign_const (rtx operands[])
12664 {
12665   enum machine_mode mode, vmode;
12666   rtx dest, op0, op1, mask, x;
12667
12668   dest = operands[0];
12669   op0 = operands[1];
12670   op1 = operands[2];
12671   mask = operands[3];
12672
12673   mode = GET_MODE (dest);
12674   vmode = GET_MODE (mask);
12675
12676   dest = simplify_gen_subreg (vmode, dest, mode, 0);
12677   x = gen_rtx_AND (vmode, dest, mask);
12678   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
12679
12680   if (op0 != CONST0_RTX (vmode))
12681     {
12682       x = gen_rtx_IOR (vmode, dest, op0);
12683       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
12684     }
12685 }
12686
12687 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
12688    so we have to do two masks.  */
12689
12690 void
12691 ix86_split_copysign_var (rtx operands[])
12692 {
12693   enum machine_mode mode, vmode;
12694   rtx dest, scratch, op0, op1, mask, nmask, x;
12695
12696   dest = operands[0];
12697   scratch = operands[1];
12698   op0 = operands[2];
12699   op1 = operands[3];
12700   nmask = operands[4];
12701   mask = operands[5];
12702
12703   mode = GET_MODE (dest);
12704   vmode = GET_MODE (mask);
12705
12706   if (rtx_equal_p (op0, op1))
12707     {
12708       /* Shouldn't happen often (it's useless, obviously), but when it does
12709          we'd generate incorrect code if we continue below.  */
12710       emit_move_insn (dest, op0);
12711       return;
12712     }
12713
12714   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
12715     {
12716       gcc_assert (REGNO (op1) == REGNO (scratch));
12717
12718       x = gen_rtx_AND (vmode, scratch, mask);
12719       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
12720
12721       dest = mask;
12722       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
12723       x = gen_rtx_NOT (vmode, dest);
12724       x = gen_rtx_AND (vmode, x, op0);
12725       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
12726     }
12727   else
12728     {
12729       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
12730         {
12731           x = gen_rtx_AND (vmode, scratch, mask);
12732         }
12733       else                                              /* alternative 2,4 */
12734         {
12735           gcc_assert (REGNO (mask) == REGNO (scratch));
12736           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
12737           x = gen_rtx_AND (vmode, scratch, op1);
12738         }
12739       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
12740
12741       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
12742         {
12743           dest = simplify_gen_subreg (vmode, op0, mode, 0);
12744           x = gen_rtx_AND (vmode, dest, nmask);
12745         }
12746       else                                              /* alternative 3,4 */
12747         {
12748           gcc_assert (REGNO (nmask) == REGNO (dest));
12749           dest = nmask;
12750           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
12751           x = gen_rtx_AND (vmode, dest, op0);
12752         }
12753       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
12754     }
12755
12756   x = gen_rtx_IOR (vmode, dest, scratch);
12757   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
12758 }
12759
12760 /* Return TRUE or FALSE depending on whether the first SET in INSN
12761    has source and destination with matching CC modes, and that the
12762    CC mode is at least as constrained as REQ_MODE.  */
12763
12764 int
12765 ix86_match_ccmode (rtx insn, enum machine_mode req_mode)
12766 {
12767   rtx set;
12768   enum machine_mode set_mode;
12769
12770   set = PATTERN (insn);
12771   if (GET_CODE (set) == PARALLEL)
12772     set = XVECEXP (set, 0, 0);
12773   gcc_assert (GET_CODE (set) == SET);
12774   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
12775
12776   set_mode = GET_MODE (SET_DEST (set));
12777   switch (set_mode)
12778     {
12779     case CCNOmode:
12780       if (req_mode != CCNOmode
12781           && (req_mode != CCmode
12782               || XEXP (SET_SRC (set), 1) != const0_rtx))
12783         return 0;
12784       break;
12785     case CCmode:
12786       if (req_mode == CCGCmode)
12787         return 0;
12788       /* FALLTHRU */
12789     case CCGCmode:
12790       if (req_mode == CCGOCmode || req_mode == CCNOmode)
12791         return 0;
12792       /* FALLTHRU */
12793     case CCGOCmode:
12794       if (req_mode == CCZmode)
12795         return 0;
12796       /* FALLTHRU */
12797     case CCZmode:
12798       break;
12799
12800     default:
12801       gcc_unreachable ();
12802     }
12803
12804   return (GET_MODE (SET_SRC (set)) == set_mode);
12805 }
12806
12807 /* Generate insn patterns to do an integer compare of OPERANDS.  */
12808
12809 static rtx
12810 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
12811 {
12812   enum machine_mode cmpmode;
12813   rtx tmp, flags;
12814
12815   cmpmode = SELECT_CC_MODE (code, op0, op1);
12816   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
12817
12818   /* This is very simple, but making the interface the same as in the
12819      FP case makes the rest of the code easier.  */
12820   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
12821   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
12822
12823   /* Return the test that should be put into the flags user, i.e.
12824      the bcc, scc, or cmov instruction.  */
12825   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
12826 }
12827
12828 /* Figure out whether to use ordered or unordered fp comparisons.
12829    Return the appropriate mode to use.  */
12830
12831 enum machine_mode
12832 ix86_fp_compare_mode (enum rtx_code code ATTRIBUTE_UNUSED)
12833 {
12834   /* ??? In order to make all comparisons reversible, we do all comparisons
12835      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
12836      all forms trapping and nontrapping comparisons, we can make inequality
12837      comparisons trapping again, since it results in better code when using
12838      FCOM based compares.  */
12839   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
12840 }
12841
12842 enum machine_mode
12843 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
12844 {
12845   enum machine_mode mode = GET_MODE (op0);
12846
12847   if (SCALAR_FLOAT_MODE_P (mode))
12848     {
12849       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
12850       return ix86_fp_compare_mode (code);
12851     }
12852
12853   switch (code)
12854     {
12855       /* Only zero flag is needed.  */
12856     case EQ:                    /* ZF=0 */
12857     case NE:                    /* ZF!=0 */
12858       return CCZmode;
12859       /* Codes needing carry flag.  */
12860     case GEU:                   /* CF=0 */
12861     case LTU:                   /* CF=1 */
12862       /* Detect overflow checks.  They need just the carry flag.  */
12863       if (GET_CODE (op0) == PLUS
12864           && rtx_equal_p (op1, XEXP (op0, 0)))
12865         return CCCmode;
12866       else
12867         return CCmode;
12868     case GTU:                   /* CF=0 & ZF=0 */
12869     case LEU:                   /* CF=1 | ZF=1 */
12870       /* Detect overflow checks.  They need just the carry flag.  */
12871       if (GET_CODE (op0) == MINUS
12872           && rtx_equal_p (op1, XEXP (op0, 0)))
12873         return CCCmode;
12874       else
12875         return CCmode;
12876       /* Codes possibly doable only with sign flag when
12877          comparing against zero.  */
12878     case GE:                    /* SF=OF   or   SF=0 */
12879     case LT:                    /* SF<>OF  or   SF=1 */
12880       if (op1 == const0_rtx)
12881         return CCGOCmode;
12882       else
12883         /* For other cases Carry flag is not required.  */
12884         return CCGCmode;
12885       /* Codes doable only with sign flag when comparing
12886          against zero, but we miss jump instruction for it
12887          so we need to use relational tests against overflow
12888          that thus needs to be zero.  */
12889     case GT:                    /* ZF=0 & SF=OF */
12890     case LE:                    /* ZF=1 | SF<>OF */
12891       if (op1 == const0_rtx)
12892         return CCNOmode;
12893       else
12894         return CCGCmode;
12895       /* strcmp pattern do (use flags) and combine may ask us for proper
12896          mode.  */
12897     case USE:
12898       return CCmode;
12899     default:
12900       gcc_unreachable ();
12901     }
12902 }
12903
12904 /* Return the fixed registers used for condition codes.  */
12905
12906 static bool
12907 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
12908 {
12909   *p1 = FLAGS_REG;
12910   *p2 = FPSR_REG;
12911   return true;
12912 }
12913
12914 /* If two condition code modes are compatible, return a condition code
12915    mode which is compatible with both.  Otherwise, return
12916    VOIDmode.  */
12917
12918 static enum machine_mode
12919 ix86_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
12920 {
12921   if (m1 == m2)
12922     return m1;
12923
12924   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
12925     return VOIDmode;
12926
12927   if ((m1 == CCGCmode && m2 == CCGOCmode)
12928       || (m1 == CCGOCmode && m2 == CCGCmode))
12929     return CCGCmode;
12930
12931   switch (m1)
12932     {
12933     default:
12934       gcc_unreachable ();
12935
12936     case CCmode:
12937     case CCGCmode:
12938     case CCGOCmode:
12939     case CCNOmode:
12940     case CCAmode:
12941     case CCCmode:
12942     case CCOmode:
12943     case CCSmode:
12944     case CCZmode:
12945       switch (m2)
12946         {
12947         default:
12948           return VOIDmode;
12949
12950         case CCmode:
12951         case CCGCmode:
12952         case CCGOCmode:
12953         case CCNOmode:
12954         case CCAmode:
12955         case CCCmode:
12956         case CCOmode:
12957         case CCSmode:
12958         case CCZmode:
12959           return CCmode;
12960         }
12961
12962     case CCFPmode:
12963     case CCFPUmode:
12964       /* These are only compatible with themselves, which we already
12965          checked above.  */
12966       return VOIDmode;
12967     }
12968 }
12969
12970 /* Split comparison code CODE into comparisons we can do using branch
12971    instructions.  BYPASS_CODE is comparison code for branch that will
12972    branch around FIRST_CODE and SECOND_CODE.  If some of branches
12973    is not required, set value to UNKNOWN.
12974    We never require more than two branches.  */
12975
12976 void
12977 ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *bypass_code,
12978                           enum rtx_code *first_code,
12979                           enum rtx_code *second_code)
12980 {
12981   *first_code = code;
12982   *bypass_code = UNKNOWN;
12983   *second_code = UNKNOWN;
12984
12985   /* The fcomi comparison sets flags as follows:
12986
12987      cmp    ZF PF CF
12988      >      0  0  0
12989      <      0  0  1
12990      =      1  0  0
12991      un     1  1  1 */
12992
12993   switch (code)
12994     {
12995     case GT:                    /* GTU - CF=0 & ZF=0 */
12996     case GE:                    /* GEU - CF=0 */
12997     case ORDERED:               /* PF=0 */
12998     case UNORDERED:             /* PF=1 */
12999     case UNEQ:                  /* EQ - ZF=1 */
13000     case UNLT:                  /* LTU - CF=1 */
13001     case UNLE:                  /* LEU - CF=1 | ZF=1 */
13002     case LTGT:                  /* EQ - ZF=0 */
13003       break;
13004     case LT:                    /* LTU - CF=1 - fails on unordered */
13005       *first_code = UNLT;
13006       *bypass_code = UNORDERED;
13007       break;
13008     case LE:                    /* LEU - CF=1 | ZF=1 - fails on unordered */
13009       *first_code = UNLE;
13010       *bypass_code = UNORDERED;
13011       break;
13012     case EQ:                    /* EQ - ZF=1 - fails on unordered */
13013       *first_code = UNEQ;
13014       *bypass_code = UNORDERED;
13015       break;
13016     case NE:                    /* NE - ZF=0 - fails on unordered */
13017       *first_code = LTGT;
13018       *second_code = UNORDERED;
13019       break;
13020     case UNGE:                  /* GEU - CF=0 - fails on unordered */
13021       *first_code = GE;
13022       *second_code = UNORDERED;
13023       break;
13024     case UNGT:                  /* GTU - CF=0 & ZF=0 - fails on unordered */
13025       *first_code = GT;
13026       *second_code = UNORDERED;
13027       break;
13028     default:
13029       gcc_unreachable ();
13030     }
13031   if (!TARGET_IEEE_FP)
13032     {
13033       *second_code = UNKNOWN;
13034       *bypass_code = UNKNOWN;
13035     }
13036 }
13037
13038 /* Return cost of comparison done fcom + arithmetics operations on AX.
13039    All following functions do use number of instructions as a cost metrics.
13040    In future this should be tweaked to compute bytes for optimize_size and
13041    take into account performance of various instructions on various CPUs.  */
13042 static int
13043 ix86_fp_comparison_arithmetics_cost (enum rtx_code code)
13044 {
13045   if (!TARGET_IEEE_FP)
13046     return 4;
13047   /* The cost of code output by ix86_expand_fp_compare.  */
13048   switch (code)
13049     {
13050     case UNLE:
13051     case UNLT:
13052     case LTGT:
13053     case GT:
13054     case GE:
13055     case UNORDERED:
13056     case ORDERED:
13057     case UNEQ:
13058       return 4;
13059       break;
13060     case LT:
13061     case NE:
13062     case EQ:
13063     case UNGE:
13064       return 5;
13065       break;
13066     case LE:
13067     case UNGT:
13068       return 6;
13069       break;
13070     default:
13071       gcc_unreachable ();
13072     }
13073 }
13074
13075 /* Return cost of comparison done using fcomi operation.
13076    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13077 static int
13078 ix86_fp_comparison_fcomi_cost (enum rtx_code code)
13079 {
13080   enum rtx_code bypass_code, first_code, second_code;
13081   /* Return arbitrarily high cost when instruction is not supported - this
13082      prevents gcc from using it.  */
13083   if (!TARGET_CMOVE)
13084     return 1024;
13085   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13086   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 2;
13087 }
13088
13089 /* Return cost of comparison done using sahf operation.
13090    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13091 static int
13092 ix86_fp_comparison_sahf_cost (enum rtx_code code)
13093 {
13094   enum rtx_code bypass_code, first_code, second_code;
13095   /* Return arbitrarily high cost when instruction is not preferred - this
13096      avoids gcc from using it.  */
13097   if (!(TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ())))
13098     return 1024;
13099   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13100   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 3;
13101 }
13102
13103 /* Compute cost of the comparison done using any method.
13104    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13105 static int
13106 ix86_fp_comparison_cost (enum rtx_code code)
13107 {
13108   int fcomi_cost, sahf_cost, arithmetics_cost = 1024;
13109   int min;
13110
13111   fcomi_cost = ix86_fp_comparison_fcomi_cost (code);
13112   sahf_cost = ix86_fp_comparison_sahf_cost (code);
13113
13114   min = arithmetics_cost = ix86_fp_comparison_arithmetics_cost (code);
13115   if (min > sahf_cost)
13116     min = sahf_cost;
13117   if (min > fcomi_cost)
13118     min = fcomi_cost;
13119   return min;
13120 }
13121
13122 /* Return true if we should use an FCOMI instruction for this
13123    fp comparison.  */
13124
13125 int
13126 ix86_use_fcomi_compare (enum rtx_code code ATTRIBUTE_UNUSED)
13127 {
13128   enum rtx_code swapped_code = swap_condition (code);
13129
13130   return ((ix86_fp_comparison_cost (code)
13131            == ix86_fp_comparison_fcomi_cost (code))
13132           || (ix86_fp_comparison_cost (swapped_code)
13133               == ix86_fp_comparison_fcomi_cost (swapped_code)));
13134 }
13135
13136 /* Swap, force into registers, or otherwise massage the two operands
13137    to a fp comparison.  The operands are updated in place; the new
13138    comparison code is returned.  */
13139
13140 static enum rtx_code
13141 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
13142 {
13143   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
13144   rtx op0 = *pop0, op1 = *pop1;
13145   enum machine_mode op_mode = GET_MODE (op0);
13146   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
13147
13148   /* All of the unordered compare instructions only work on registers.
13149      The same is true of the fcomi compare instructions.  The XFmode
13150      compare instructions require registers except when comparing
13151      against zero or when converting operand 1 from fixed point to
13152      floating point.  */
13153
13154   if (!is_sse
13155       && (fpcmp_mode == CCFPUmode
13156           || (op_mode == XFmode
13157               && ! (standard_80387_constant_p (op0) == 1
13158                     || standard_80387_constant_p (op1) == 1)
13159               && GET_CODE (op1) != FLOAT)
13160           || ix86_use_fcomi_compare (code)))
13161     {
13162       op0 = force_reg (op_mode, op0);
13163       op1 = force_reg (op_mode, op1);
13164     }
13165   else
13166     {
13167       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
13168          things around if they appear profitable, otherwise force op0
13169          into a register.  */
13170
13171       if (standard_80387_constant_p (op0) == 0
13172           || (MEM_P (op0)
13173               && ! (standard_80387_constant_p (op1) == 0
13174                     || MEM_P (op1))))
13175         {
13176           rtx tmp;
13177           tmp = op0, op0 = op1, op1 = tmp;
13178           code = swap_condition (code);
13179         }
13180
13181       if (!REG_P (op0))
13182         op0 = force_reg (op_mode, op0);
13183
13184       if (CONSTANT_P (op1))
13185         {
13186           int tmp = standard_80387_constant_p (op1);
13187           if (tmp == 0)
13188             op1 = validize_mem (force_const_mem (op_mode, op1));
13189           else if (tmp == 1)
13190             {
13191               if (TARGET_CMOVE)
13192                 op1 = force_reg (op_mode, op1);
13193             }
13194           else
13195             op1 = force_reg (op_mode, op1);
13196         }
13197     }
13198
13199   /* Try to rearrange the comparison to make it cheaper.  */
13200   if (ix86_fp_comparison_cost (code)
13201       > ix86_fp_comparison_cost (swap_condition (code))
13202       && (REG_P (op1) || can_create_pseudo_p ()))
13203     {
13204       rtx tmp;
13205       tmp = op0, op0 = op1, op1 = tmp;
13206       code = swap_condition (code);
13207       if (!REG_P (op0))
13208         op0 = force_reg (op_mode, op0);
13209     }
13210
13211   *pop0 = op0;
13212   *pop1 = op1;
13213   return code;
13214 }
13215
13216 /* Convert comparison codes we use to represent FP comparison to integer
13217    code that will result in proper branch.  Return UNKNOWN if no such code
13218    is available.  */
13219
13220 enum rtx_code
13221 ix86_fp_compare_code_to_integer (enum rtx_code code)
13222 {
13223   switch (code)
13224     {
13225     case GT:
13226       return GTU;
13227     case GE:
13228       return GEU;
13229     case ORDERED:
13230     case UNORDERED:
13231       return code;
13232       break;
13233     case UNEQ:
13234       return EQ;
13235       break;
13236     case UNLT:
13237       return LTU;
13238       break;
13239     case UNLE:
13240       return LEU;
13241       break;
13242     case LTGT:
13243       return NE;
13244       break;
13245     default:
13246       return UNKNOWN;
13247     }
13248 }
13249
13250 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
13251
13252 static rtx
13253 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch,
13254                         rtx *second_test, rtx *bypass_test)
13255 {
13256   enum machine_mode fpcmp_mode, intcmp_mode;
13257   rtx tmp, tmp2;
13258   int cost = ix86_fp_comparison_cost (code);
13259   enum rtx_code bypass_code, first_code, second_code;
13260
13261   fpcmp_mode = ix86_fp_compare_mode (code);
13262   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
13263
13264   if (second_test)
13265     *second_test = NULL_RTX;
13266   if (bypass_test)
13267     *bypass_test = NULL_RTX;
13268
13269   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13270
13271   /* Do fcomi/sahf based test when profitable.  */
13272   if (ix86_fp_comparison_arithmetics_cost (code) > cost
13273       && (bypass_code == UNKNOWN || bypass_test)
13274       && (second_code == UNKNOWN || second_test))
13275     {
13276       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13277       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
13278                          tmp);
13279       if (TARGET_CMOVE)
13280         emit_insn (tmp);
13281       else
13282         {
13283           gcc_assert (TARGET_SAHF);
13284
13285           if (!scratch)
13286             scratch = gen_reg_rtx (HImode);
13287           tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
13288
13289           emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
13290         }
13291
13292       /* The FP codes work out to act like unsigned.  */
13293       intcmp_mode = fpcmp_mode;
13294       code = first_code;
13295       if (bypass_code != UNKNOWN)
13296         *bypass_test = gen_rtx_fmt_ee (bypass_code, VOIDmode,
13297                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13298                                        const0_rtx);
13299       if (second_code != UNKNOWN)
13300         *second_test = gen_rtx_fmt_ee (second_code, VOIDmode,
13301                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13302                                        const0_rtx);
13303     }
13304   else
13305     {
13306       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
13307       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13308       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
13309       if (!scratch)
13310         scratch = gen_reg_rtx (HImode);
13311       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
13312
13313       /* In the unordered case, we have to check C2 for NaN's, which
13314          doesn't happen to work out to anything nice combination-wise.
13315          So do some bit twiddling on the value we've got in AH to come
13316          up with an appropriate set of condition codes.  */
13317
13318       intcmp_mode = CCNOmode;
13319       switch (code)
13320         {
13321         case GT:
13322         case UNGT:
13323           if (code == GT || !TARGET_IEEE_FP)
13324             {
13325               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
13326               code = EQ;
13327             }
13328           else
13329             {
13330               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13331               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
13332               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
13333               intcmp_mode = CCmode;
13334               code = GEU;
13335             }
13336           break;
13337         case LT:
13338         case UNLT:
13339           if (code == LT && TARGET_IEEE_FP)
13340             {
13341               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13342               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x01)));
13343               intcmp_mode = CCmode;
13344               code = EQ;
13345             }
13346           else
13347             {
13348               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x01)));
13349               code = NE;
13350             }
13351           break;
13352         case GE:
13353         case UNGE:
13354           if (code == GE || !TARGET_IEEE_FP)
13355             {
13356               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
13357               code = EQ;
13358             }
13359           else
13360             {
13361               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13362               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
13363                                              GEN_INT (0x01)));
13364               code = NE;
13365             }
13366           break;
13367         case LE:
13368         case UNLE:
13369           if (code == LE && TARGET_IEEE_FP)
13370             {
13371               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13372               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
13373               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
13374               intcmp_mode = CCmode;
13375               code = LTU;
13376             }
13377           else
13378             {
13379               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
13380               code = NE;
13381             }
13382           break;
13383         case EQ:
13384         case UNEQ:
13385           if (code == EQ && TARGET_IEEE_FP)
13386             {
13387               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13388               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
13389               intcmp_mode = CCmode;
13390               code = EQ;
13391             }
13392           else
13393             {
13394               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
13395               code = NE;
13396               break;
13397             }
13398           break;
13399         case NE:
13400         case LTGT:
13401           if (code == NE && TARGET_IEEE_FP)
13402             {
13403               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
13404               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
13405                                              GEN_INT (0x40)));
13406               code = NE;
13407             }
13408           else
13409             {
13410               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
13411               code = EQ;
13412             }
13413           break;
13414
13415         case UNORDERED:
13416           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
13417           code = NE;
13418           break;
13419         case ORDERED:
13420           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
13421           code = EQ;
13422           break;
13423
13424         default:
13425           gcc_unreachable ();
13426         }
13427     }
13428
13429   /* Return the test that should be put into the flags user, i.e.
13430      the bcc, scc, or cmov instruction.  */
13431   return gen_rtx_fmt_ee (code, VOIDmode,
13432                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
13433                          const0_rtx);
13434 }
13435
13436 rtx
13437 ix86_expand_compare (enum rtx_code code, rtx *second_test, rtx *bypass_test)
13438 {
13439   rtx op0, op1, ret;
13440   op0 = ix86_compare_op0;
13441   op1 = ix86_compare_op1;
13442
13443   if (second_test)
13444     *second_test = NULL_RTX;
13445   if (bypass_test)
13446     *bypass_test = NULL_RTX;
13447
13448   if (ix86_compare_emitted)
13449     {
13450       ret = gen_rtx_fmt_ee (code, VOIDmode, ix86_compare_emitted, const0_rtx);
13451       ix86_compare_emitted = NULL_RTX;
13452     }
13453   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
13454     {
13455       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
13456       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
13457                                     second_test, bypass_test);
13458     }
13459   else
13460     ret = ix86_expand_int_compare (code, op0, op1);
13461
13462   return ret;
13463 }
13464
13465 /* Return true if the CODE will result in nontrivial jump sequence.  */
13466 bool
13467 ix86_fp_jump_nontrivial_p (enum rtx_code code)
13468 {
13469   enum rtx_code bypass_code, first_code, second_code;
13470   if (!TARGET_CMOVE)
13471     return true;
13472   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13473   return bypass_code != UNKNOWN || second_code != UNKNOWN;
13474 }
13475
13476 void
13477 ix86_expand_branch (enum rtx_code code, rtx label)
13478 {
13479   rtx tmp;
13480
13481   /* If we have emitted a compare insn, go straight to simple.
13482      ix86_expand_compare won't emit anything if ix86_compare_emitted
13483      is non NULL.  */
13484   if (ix86_compare_emitted)
13485     goto simple;
13486
13487   switch (GET_MODE (ix86_compare_op0))
13488     {
13489     case QImode:
13490     case HImode:
13491     case SImode:
13492       simple:
13493       tmp = ix86_expand_compare (code, NULL, NULL);
13494       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
13495                                   gen_rtx_LABEL_REF (VOIDmode, label),
13496                                   pc_rtx);
13497       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
13498       return;
13499
13500     case SFmode:
13501     case DFmode:
13502     case XFmode:
13503       {
13504         rtvec vec;
13505         int use_fcomi;
13506         enum rtx_code bypass_code, first_code, second_code;
13507
13508         code = ix86_prepare_fp_compare_args (code, &ix86_compare_op0,
13509                                              &ix86_compare_op1);
13510
13511         ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13512
13513         /* Check whether we will use the natural sequence with one jump.  If
13514            so, we can expand jump early.  Otherwise delay expansion by
13515            creating compound insn to not confuse optimizers.  */
13516         if (bypass_code == UNKNOWN && second_code == UNKNOWN)
13517           {
13518             ix86_split_fp_branch (code, ix86_compare_op0, ix86_compare_op1,
13519                                   gen_rtx_LABEL_REF (VOIDmode, label),
13520                                   pc_rtx, NULL_RTX, NULL_RTX);
13521           }
13522         else
13523           {
13524             tmp = gen_rtx_fmt_ee (code, VOIDmode,
13525                                   ix86_compare_op0, ix86_compare_op1);
13526             tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
13527                                         gen_rtx_LABEL_REF (VOIDmode, label),
13528                                         pc_rtx);
13529             tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
13530
13531             use_fcomi = ix86_use_fcomi_compare (code);
13532             vec = rtvec_alloc (3 + !use_fcomi);
13533             RTVEC_ELT (vec, 0) = tmp;
13534             RTVEC_ELT (vec, 1)
13535               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FPSR_REG));
13536             RTVEC_ELT (vec, 2)
13537               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FLAGS_REG));
13538             if (! use_fcomi)
13539               RTVEC_ELT (vec, 3)
13540                 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (HImode));
13541
13542             emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, vec));
13543           }
13544         return;
13545       }
13546
13547     case DImode:
13548       if (TARGET_64BIT)
13549         goto simple;
13550     case TImode:
13551       /* Expand DImode branch into multiple compare+branch.  */
13552       {
13553         rtx lo[2], hi[2], label2;
13554         enum rtx_code code1, code2, code3;
13555         enum machine_mode submode;
13556
13557         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
13558           {
13559             tmp = ix86_compare_op0;
13560             ix86_compare_op0 = ix86_compare_op1;
13561             ix86_compare_op1 = tmp;
13562             code = swap_condition (code);
13563           }
13564         if (GET_MODE (ix86_compare_op0) == DImode)
13565           {
13566             split_di (&ix86_compare_op0, 1, lo+0, hi+0);
13567             split_di (&ix86_compare_op1, 1, lo+1, hi+1);
13568             submode = SImode;
13569           }
13570         else
13571           {
13572             split_ti (&ix86_compare_op0, 1, lo+0, hi+0);
13573             split_ti (&ix86_compare_op1, 1, lo+1, hi+1);
13574             submode = DImode;
13575           }
13576
13577         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
13578            avoid two branches.  This costs one extra insn, so disable when
13579            optimizing for size.  */
13580
13581         if ((code == EQ || code == NE)
13582             && (!optimize_insn_for_size_p ()
13583                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
13584           {
13585             rtx xor0, xor1;
13586
13587             xor1 = hi[0];
13588             if (hi[1] != const0_rtx)
13589               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
13590                                    NULL_RTX, 0, OPTAB_WIDEN);
13591
13592             xor0 = lo[0];
13593             if (lo[1] != const0_rtx)
13594               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
13595                                    NULL_RTX, 0, OPTAB_WIDEN);
13596
13597             tmp = expand_binop (submode, ior_optab, xor1, xor0,
13598                                 NULL_RTX, 0, OPTAB_WIDEN);
13599
13600             ix86_compare_op0 = tmp;
13601             ix86_compare_op1 = const0_rtx;
13602             ix86_expand_branch (code, label);
13603             return;
13604           }
13605
13606         /* Otherwise, if we are doing less-than or greater-or-equal-than,
13607            op1 is a constant and the low word is zero, then we can just
13608            examine the high word.  Similarly for low word -1 and
13609            less-or-equal-than or greater-than.  */
13610
13611         if (CONST_INT_P (hi[1]))
13612           switch (code)
13613             {
13614             case LT: case LTU: case GE: case GEU:
13615               if (lo[1] == const0_rtx)
13616                 {
13617                   ix86_compare_op0 = hi[0];
13618                   ix86_compare_op1 = hi[1];
13619                   ix86_expand_branch (code, label);
13620                   return;
13621                 }
13622               break;
13623             case LE: case LEU: case GT: case GTU:
13624               if (lo[1] == constm1_rtx)
13625                 {
13626                   ix86_compare_op0 = hi[0];
13627                   ix86_compare_op1 = hi[1];
13628                   ix86_expand_branch (code, label);
13629                   return;
13630                 }
13631               break;
13632             default:
13633               break;
13634             }
13635
13636         /* Otherwise, we need two or three jumps.  */
13637
13638         label2 = gen_label_rtx ();
13639
13640         code1 = code;
13641         code2 = swap_condition (code);
13642         code3 = unsigned_condition (code);
13643
13644         switch (code)
13645           {
13646           case LT: case GT: case LTU: case GTU:
13647             break;
13648
13649           case LE:   code1 = LT;  code2 = GT;  break;
13650           case GE:   code1 = GT;  code2 = LT;  break;
13651           case LEU:  code1 = LTU; code2 = GTU; break;
13652           case GEU:  code1 = GTU; code2 = LTU; break;
13653
13654           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
13655           case NE:   code2 = UNKNOWN; break;
13656
13657           default:
13658             gcc_unreachable ();
13659           }
13660
13661         /*
13662          * a < b =>
13663          *    if (hi(a) < hi(b)) goto true;
13664          *    if (hi(a) > hi(b)) goto false;
13665          *    if (lo(a) < lo(b)) goto true;
13666          *  false:
13667          */
13668
13669         ix86_compare_op0 = hi[0];
13670         ix86_compare_op1 = hi[1];
13671
13672         if (code1 != UNKNOWN)
13673           ix86_expand_branch (code1, label);
13674         if (code2 != UNKNOWN)
13675           ix86_expand_branch (code2, label2);
13676
13677         ix86_compare_op0 = lo[0];
13678         ix86_compare_op1 = lo[1];
13679         ix86_expand_branch (code3, label);
13680
13681         if (code2 != UNKNOWN)
13682           emit_label (label2);
13683         return;
13684       }
13685
13686     default:
13687       gcc_unreachable ();
13688     }
13689 }
13690
13691 /* Split branch based on floating point condition.  */
13692 void
13693 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
13694                       rtx target1, rtx target2, rtx tmp, rtx pushed)
13695 {
13696   rtx second, bypass;
13697   rtx label = NULL_RTX;
13698   rtx condition;
13699   int bypass_probability = -1, second_probability = -1, probability = -1;
13700   rtx i;
13701
13702   if (target2 != pc_rtx)
13703     {
13704       rtx tmp = target2;
13705       code = reverse_condition_maybe_unordered (code);
13706       target2 = target1;
13707       target1 = tmp;
13708     }
13709
13710   condition = ix86_expand_fp_compare (code, op1, op2,
13711                                       tmp, &second, &bypass);
13712
13713   /* Remove pushed operand from stack.  */
13714   if (pushed)
13715     ix86_free_from_memory (GET_MODE (pushed));
13716
13717   if (split_branch_probability >= 0)
13718     {
13719       /* Distribute the probabilities across the jumps.
13720          Assume the BYPASS and SECOND to be always test
13721          for UNORDERED.  */
13722       probability = split_branch_probability;
13723
13724       /* Value of 1 is low enough to make no need for probability
13725          to be updated.  Later we may run some experiments and see
13726          if unordered values are more frequent in practice.  */
13727       if (bypass)
13728         bypass_probability = 1;
13729       if (second)
13730         second_probability = 1;
13731     }
13732   if (bypass != NULL_RTX)
13733     {
13734       label = gen_label_rtx ();
13735       i = emit_jump_insn (gen_rtx_SET
13736                           (VOIDmode, pc_rtx,
13737                            gen_rtx_IF_THEN_ELSE (VOIDmode,
13738                                                  bypass,
13739                                                  gen_rtx_LABEL_REF (VOIDmode,
13740                                                                     label),
13741                                                  pc_rtx)));
13742       if (bypass_probability >= 0)
13743         REG_NOTES (i)
13744           = gen_rtx_EXPR_LIST (REG_BR_PROB,
13745                                GEN_INT (bypass_probability),
13746                                REG_NOTES (i));
13747     }
13748   i = emit_jump_insn (gen_rtx_SET
13749                       (VOIDmode, pc_rtx,
13750                        gen_rtx_IF_THEN_ELSE (VOIDmode,
13751                                              condition, target1, target2)));
13752   if (probability >= 0)
13753     REG_NOTES (i)
13754       = gen_rtx_EXPR_LIST (REG_BR_PROB,
13755                            GEN_INT (probability),
13756                            REG_NOTES (i));
13757   if (second != NULL_RTX)
13758     {
13759       i = emit_jump_insn (gen_rtx_SET
13760                           (VOIDmode, pc_rtx,
13761                            gen_rtx_IF_THEN_ELSE (VOIDmode, second, target1,
13762                                                  target2)));
13763       if (second_probability >= 0)
13764         REG_NOTES (i)
13765           = gen_rtx_EXPR_LIST (REG_BR_PROB,
13766                                GEN_INT (second_probability),
13767                                REG_NOTES (i));
13768     }
13769   if (label != NULL_RTX)
13770     emit_label (label);
13771 }
13772
13773 int
13774 ix86_expand_setcc (enum rtx_code code, rtx dest)
13775 {
13776   rtx ret, tmp, tmpreg, equiv;
13777   rtx second_test, bypass_test;
13778
13779   if (GET_MODE (ix86_compare_op0) == (TARGET_64BIT ? TImode : DImode))
13780     return 0; /* FAIL */
13781
13782   gcc_assert (GET_MODE (dest) == QImode);
13783
13784   ret = ix86_expand_compare (code, &second_test, &bypass_test);
13785   PUT_MODE (ret, QImode);
13786
13787   tmp = dest;
13788   tmpreg = dest;
13789
13790   emit_insn (gen_rtx_SET (VOIDmode, tmp, ret));
13791   if (bypass_test || second_test)
13792     {
13793       rtx test = second_test;
13794       int bypass = 0;
13795       rtx tmp2 = gen_reg_rtx (QImode);
13796       if (bypass_test)
13797         {
13798           gcc_assert (!second_test);
13799           test = bypass_test;
13800           bypass = 1;
13801           PUT_CODE (test, reverse_condition_maybe_unordered (GET_CODE (test)));
13802         }
13803       PUT_MODE (test, QImode);
13804       emit_insn (gen_rtx_SET (VOIDmode, tmp2, test));
13805
13806       if (bypass)
13807         emit_insn (gen_andqi3 (tmp, tmpreg, tmp2));
13808       else
13809         emit_insn (gen_iorqi3 (tmp, tmpreg, tmp2));
13810     }
13811
13812   /* Attach a REG_EQUAL note describing the comparison result.  */
13813   if (ix86_compare_op0 && ix86_compare_op1)
13814     {
13815       equiv = simplify_gen_relational (code, QImode,
13816                                        GET_MODE (ix86_compare_op0),
13817                                        ix86_compare_op0, ix86_compare_op1);
13818       set_unique_reg_note (get_last_insn (), REG_EQUAL, equiv);
13819     }
13820
13821   return 1; /* DONE */
13822 }
13823
13824 /* Expand comparison setting or clearing carry flag.  Return true when
13825    successful and set pop for the operation.  */
13826 static bool
13827 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
13828 {
13829   enum machine_mode mode =
13830     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
13831
13832   /* Do not handle DImode compares that go through special path.  */
13833   if (mode == (TARGET_64BIT ? TImode : DImode))
13834     return false;
13835
13836   if (SCALAR_FLOAT_MODE_P (mode))
13837     {
13838       rtx second_test = NULL, bypass_test = NULL;
13839       rtx compare_op, compare_seq;
13840
13841       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
13842
13843       /* Shortcut:  following common codes never translate
13844          into carry flag compares.  */
13845       if (code == EQ || code == NE || code == UNEQ || code == LTGT
13846           || code == ORDERED || code == UNORDERED)
13847         return false;
13848
13849       /* These comparisons require zero flag; swap operands so they won't.  */
13850       if ((code == GT || code == UNLE || code == LE || code == UNGT)
13851           && !TARGET_IEEE_FP)
13852         {
13853           rtx tmp = op0;
13854           op0 = op1;
13855           op1 = tmp;
13856           code = swap_condition (code);
13857         }
13858
13859       /* Try to expand the comparison and verify that we end up with
13860          carry flag based comparison.  This fails to be true only when
13861          we decide to expand comparison using arithmetic that is not
13862          too common scenario.  */
13863       start_sequence ();
13864       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
13865                                            &second_test, &bypass_test);
13866       compare_seq = get_insns ();
13867       end_sequence ();
13868
13869       if (second_test || bypass_test)
13870         return false;
13871
13872       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
13873           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
13874         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
13875       else
13876         code = GET_CODE (compare_op);
13877
13878       if (code != LTU && code != GEU)
13879         return false;
13880
13881       emit_insn (compare_seq);
13882       *pop = compare_op;
13883       return true;
13884     }
13885
13886   if (!INTEGRAL_MODE_P (mode))
13887     return false;
13888
13889   switch (code)
13890     {
13891     case LTU:
13892     case GEU:
13893       break;
13894
13895     /* Convert a==0 into (unsigned)a<1.  */
13896     case EQ:
13897     case NE:
13898       if (op1 != const0_rtx)
13899         return false;
13900       op1 = const1_rtx;
13901       code = (code == EQ ? LTU : GEU);
13902       break;
13903
13904     /* Convert a>b into b<a or a>=b-1.  */
13905     case GTU:
13906     case LEU:
13907       if (CONST_INT_P (op1))
13908         {
13909           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
13910           /* Bail out on overflow.  We still can swap operands but that
13911              would force loading of the constant into register.  */
13912           if (op1 == const0_rtx
13913               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
13914             return false;
13915           code = (code == GTU ? GEU : LTU);
13916         }
13917       else
13918         {
13919           rtx tmp = op1;
13920           op1 = op0;
13921           op0 = tmp;
13922           code = (code == GTU ? LTU : GEU);
13923         }
13924       break;
13925
13926     /* Convert a>=0 into (unsigned)a<0x80000000.  */
13927     case LT:
13928     case GE:
13929       if (mode == DImode || op1 != const0_rtx)
13930         return false;
13931       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
13932       code = (code == LT ? GEU : LTU);
13933       break;
13934     case LE:
13935     case GT:
13936       if (mode == DImode || op1 != constm1_rtx)
13937         return false;
13938       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
13939       code = (code == LE ? GEU : LTU);
13940       break;
13941
13942     default:
13943       return false;
13944     }
13945   /* Swapping operands may cause constant to appear as first operand.  */
13946   if (!nonimmediate_operand (op0, VOIDmode))
13947     {
13948       if (!can_create_pseudo_p ())
13949         return false;
13950       op0 = force_reg (mode, op0);
13951     }
13952   ix86_compare_op0 = op0;
13953   ix86_compare_op1 = op1;
13954   *pop = ix86_expand_compare (code, NULL, NULL);
13955   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
13956   return true;
13957 }
13958
13959 int
13960 ix86_expand_int_movcc (rtx operands[])
13961 {
13962   enum rtx_code code = GET_CODE (operands[1]), compare_code;
13963   rtx compare_seq, compare_op;
13964   rtx second_test, bypass_test;
13965   enum machine_mode mode = GET_MODE (operands[0]);
13966   bool sign_bit_compare_p = false;;
13967
13968   start_sequence ();
13969   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
13970   compare_seq = get_insns ();
13971   end_sequence ();
13972
13973   compare_code = GET_CODE (compare_op);
13974
13975   if ((ix86_compare_op1 == const0_rtx && (code == GE || code == LT))
13976       || (ix86_compare_op1 == constm1_rtx && (code == GT || code == LE)))
13977     sign_bit_compare_p = true;
13978
13979   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
13980      HImode insns, we'd be swallowed in word prefix ops.  */
13981
13982   if ((mode != HImode || TARGET_FAST_PREFIX)
13983       && (mode != (TARGET_64BIT ? TImode : DImode))
13984       && CONST_INT_P (operands[2])
13985       && CONST_INT_P (operands[3]))
13986     {
13987       rtx out = operands[0];
13988       HOST_WIDE_INT ct = INTVAL (operands[2]);
13989       HOST_WIDE_INT cf = INTVAL (operands[3]);
13990       HOST_WIDE_INT diff;
13991
13992       diff = ct - cf;
13993       /*  Sign bit compares are better done using shifts than we do by using
13994           sbb.  */
13995       if (sign_bit_compare_p
13996           || ix86_expand_carry_flag_compare (code, ix86_compare_op0,
13997                                              ix86_compare_op1, &compare_op))
13998         {
13999           /* Detect overlap between destination and compare sources.  */
14000           rtx tmp = out;
14001
14002           if (!sign_bit_compare_p)
14003             {
14004               bool fpcmp = false;
14005
14006               compare_code = GET_CODE (compare_op);
14007
14008               if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14009                   || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14010                 {
14011                   fpcmp = true;
14012                   compare_code = ix86_fp_compare_code_to_integer (compare_code);
14013                 }
14014
14015               /* To simplify rest of code, restrict to the GEU case.  */
14016               if (compare_code == LTU)
14017                 {
14018                   HOST_WIDE_INT tmp = ct;
14019                   ct = cf;
14020                   cf = tmp;
14021                   compare_code = reverse_condition (compare_code);
14022                   code = reverse_condition (code);
14023                 }
14024               else
14025                 {
14026                   if (fpcmp)
14027                     PUT_CODE (compare_op,
14028                               reverse_condition_maybe_unordered
14029                                 (GET_CODE (compare_op)));
14030                   else
14031                     PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
14032                 }
14033               diff = ct - cf;
14034
14035               if (reg_overlap_mentioned_p (out, ix86_compare_op0)
14036                   || reg_overlap_mentioned_p (out, ix86_compare_op1))
14037                 tmp = gen_reg_rtx (mode);
14038
14039               if (mode == DImode)
14040                 emit_insn (gen_x86_movdicc_0_m1_rex64 (tmp, compare_op));
14041               else
14042                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp), compare_op));
14043             }
14044           else
14045             {
14046               if (code == GT || code == GE)
14047                 code = reverse_condition (code);
14048               else
14049                 {
14050                   HOST_WIDE_INT tmp = ct;
14051                   ct = cf;
14052                   cf = tmp;
14053                   diff = ct - cf;
14054                 }
14055               tmp = emit_store_flag (tmp, code, ix86_compare_op0,
14056                                      ix86_compare_op1, VOIDmode, 0, -1);
14057             }
14058
14059           if (diff == 1)
14060             {
14061               /*
14062                * cmpl op0,op1
14063                * sbbl dest,dest
14064                * [addl dest, ct]
14065                *
14066                * Size 5 - 8.
14067                */
14068               if (ct)
14069                 tmp = expand_simple_binop (mode, PLUS,
14070                                            tmp, GEN_INT (ct),
14071                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14072             }
14073           else if (cf == -1)
14074             {
14075               /*
14076                * cmpl op0,op1
14077                * sbbl dest,dest
14078                * orl $ct, dest
14079                *
14080                * Size 8.
14081                */
14082               tmp = expand_simple_binop (mode, IOR,
14083                                          tmp, GEN_INT (ct),
14084                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14085             }
14086           else if (diff == -1 && ct)
14087             {
14088               /*
14089                * cmpl op0,op1
14090                * sbbl dest,dest
14091                * notl dest
14092                * [addl dest, cf]
14093                *
14094                * Size 8 - 11.
14095                */
14096               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14097               if (cf)
14098                 tmp = expand_simple_binop (mode, PLUS,
14099                                            copy_rtx (tmp), GEN_INT (cf),
14100                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14101             }
14102           else
14103             {
14104               /*
14105                * cmpl op0,op1
14106                * sbbl dest,dest
14107                * [notl dest]
14108                * andl cf - ct, dest
14109                * [addl dest, ct]
14110                *
14111                * Size 8 - 11.
14112                */
14113
14114               if (cf == 0)
14115                 {
14116                   cf = ct;
14117                   ct = 0;
14118                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14119                 }
14120
14121               tmp = expand_simple_binop (mode, AND,
14122                                          copy_rtx (tmp),
14123                                          gen_int_mode (cf - ct, mode),
14124                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14125               if (ct)
14126                 tmp = expand_simple_binop (mode, PLUS,
14127                                            copy_rtx (tmp), GEN_INT (ct),
14128                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14129             }
14130
14131           if (!rtx_equal_p (tmp, out))
14132             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
14133
14134           return 1; /* DONE */
14135         }
14136
14137       if (diff < 0)
14138         {
14139           enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14140
14141           HOST_WIDE_INT tmp;
14142           tmp = ct, ct = cf, cf = tmp;
14143           diff = -diff;
14144
14145           if (SCALAR_FLOAT_MODE_P (cmp_mode))
14146             {
14147               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14148
14149               /* We may be reversing unordered compare to normal compare, that
14150                  is not valid in general (we may convert non-trapping condition
14151                  to trapping one), however on i386 we currently emit all
14152                  comparisons unordered.  */
14153               compare_code = reverse_condition_maybe_unordered (compare_code);
14154               code = reverse_condition_maybe_unordered (code);
14155             }
14156           else
14157             {
14158               compare_code = reverse_condition (compare_code);
14159               code = reverse_condition (code);
14160             }
14161         }
14162
14163       compare_code = UNKNOWN;
14164       if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_INT
14165           && CONST_INT_P (ix86_compare_op1))
14166         {
14167           if (ix86_compare_op1 == const0_rtx
14168               && (code == LT || code == GE))
14169             compare_code = code;
14170           else if (ix86_compare_op1 == constm1_rtx)
14171             {
14172               if (code == LE)
14173                 compare_code = LT;
14174               else if (code == GT)
14175                 compare_code = GE;
14176             }
14177         }
14178
14179       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
14180       if (compare_code != UNKNOWN
14181           && GET_MODE (ix86_compare_op0) == GET_MODE (out)
14182           && (cf == -1 || ct == -1))
14183         {
14184           /* If lea code below could be used, only optimize
14185              if it results in a 2 insn sequence.  */
14186
14187           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
14188                  || diff == 3 || diff == 5 || diff == 9)
14189               || (compare_code == LT && ct == -1)
14190               || (compare_code == GE && cf == -1))
14191             {
14192               /*
14193                * notl op1       (if necessary)
14194                * sarl $31, op1
14195                * orl cf, op1
14196                */
14197               if (ct != -1)
14198                 {
14199                   cf = ct;
14200                   ct = -1;
14201                   code = reverse_condition (code);
14202                 }
14203
14204               out = emit_store_flag (out, code, ix86_compare_op0,
14205                                      ix86_compare_op1, VOIDmode, 0, -1);
14206
14207               out = expand_simple_binop (mode, IOR,
14208                                          out, GEN_INT (cf),
14209                                          out, 1, OPTAB_DIRECT);
14210               if (out != operands[0])
14211                 emit_move_insn (operands[0], out);
14212
14213               return 1; /* DONE */
14214             }
14215         }
14216
14217
14218       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
14219            || diff == 3 || diff == 5 || diff == 9)
14220           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
14221           && (mode != DImode
14222               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
14223         {
14224           /*
14225            * xorl dest,dest
14226            * cmpl op1,op2
14227            * setcc dest
14228            * lea cf(dest*(ct-cf)),dest
14229            *
14230            * Size 14.
14231            *
14232            * This also catches the degenerate setcc-only case.
14233            */
14234
14235           rtx tmp;
14236           int nops;
14237
14238           out = emit_store_flag (out, code, ix86_compare_op0,
14239                                  ix86_compare_op1, VOIDmode, 0, 1);
14240
14241           nops = 0;
14242           /* On x86_64 the lea instruction operates on Pmode, so we need
14243              to get arithmetics done in proper mode to match.  */
14244           if (diff == 1)
14245             tmp = copy_rtx (out);
14246           else
14247             {
14248               rtx out1;
14249               out1 = copy_rtx (out);
14250               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
14251               nops++;
14252               if (diff & 1)
14253                 {
14254                   tmp = gen_rtx_PLUS (mode, tmp, out1);
14255                   nops++;
14256                 }
14257             }
14258           if (cf != 0)
14259             {
14260               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
14261               nops++;
14262             }
14263           if (!rtx_equal_p (tmp, out))
14264             {
14265               if (nops == 1)
14266                 out = force_operand (tmp, copy_rtx (out));
14267               else
14268                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
14269             }
14270           if (!rtx_equal_p (out, operands[0]))
14271             emit_move_insn (operands[0], copy_rtx (out));
14272
14273           return 1; /* DONE */
14274         }
14275
14276       /*
14277        * General case:                  Jumpful:
14278        *   xorl dest,dest               cmpl op1, op2
14279        *   cmpl op1, op2                movl ct, dest
14280        *   setcc dest                   jcc 1f
14281        *   decl dest                    movl cf, dest
14282        *   andl (cf-ct),dest            1:
14283        *   addl ct,dest
14284        *
14285        * Size 20.                       Size 14.
14286        *
14287        * This is reasonably steep, but branch mispredict costs are
14288        * high on modern cpus, so consider failing only if optimizing
14289        * for space.
14290        */
14291
14292       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14293           && BRANCH_COST >= 2)
14294         {
14295           if (cf == 0)
14296             {
14297               enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14298
14299               cf = ct;
14300               ct = 0;
14301
14302               if (SCALAR_FLOAT_MODE_P (cmp_mode))
14303                 {
14304                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14305
14306                   /* We may be reversing unordered compare to normal compare,
14307                      that is not valid in general (we may convert non-trapping
14308                      condition to trapping one), however on i386 we currently
14309                      emit all comparisons unordered.  */
14310                   code = reverse_condition_maybe_unordered (code);
14311                 }
14312               else
14313                 {
14314                   code = reverse_condition (code);
14315                   if (compare_code != UNKNOWN)
14316                     compare_code = reverse_condition (compare_code);
14317                 }
14318             }
14319
14320           if (compare_code != UNKNOWN)
14321             {
14322               /* notl op1       (if needed)
14323                  sarl $31, op1
14324                  andl (cf-ct), op1
14325                  addl ct, op1
14326
14327                  For x < 0 (resp. x <= -1) there will be no notl,
14328                  so if possible swap the constants to get rid of the
14329                  complement.
14330                  True/false will be -1/0 while code below (store flag
14331                  followed by decrement) is 0/-1, so the constants need
14332                  to be exchanged once more.  */
14333
14334               if (compare_code == GE || !cf)
14335                 {
14336                   code = reverse_condition (code);
14337                   compare_code = LT;
14338                 }
14339               else
14340                 {
14341                   HOST_WIDE_INT tmp = cf;
14342                   cf = ct;
14343                   ct = tmp;
14344                 }
14345
14346               out = emit_store_flag (out, code, ix86_compare_op0,
14347                                      ix86_compare_op1, VOIDmode, 0, -1);
14348             }
14349           else
14350             {
14351               out = emit_store_flag (out, code, ix86_compare_op0,
14352                                      ix86_compare_op1, VOIDmode, 0, 1);
14353
14354               out = expand_simple_binop (mode, PLUS, copy_rtx (out), constm1_rtx,
14355                                          copy_rtx (out), 1, OPTAB_DIRECT);
14356             }
14357
14358           out = expand_simple_binop (mode, AND, copy_rtx (out),
14359                                      gen_int_mode (cf - ct, mode),
14360                                      copy_rtx (out), 1, OPTAB_DIRECT);
14361           if (ct)
14362             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
14363                                        copy_rtx (out), 1, OPTAB_DIRECT);
14364           if (!rtx_equal_p (out, operands[0]))
14365             emit_move_insn (operands[0], copy_rtx (out));
14366
14367           return 1; /* DONE */
14368         }
14369     }
14370
14371   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14372     {
14373       /* Try a few things more with specific constants and a variable.  */
14374
14375       optab op;
14376       rtx var, orig_out, out, tmp;
14377
14378       if (BRANCH_COST <= 2)
14379         return 0; /* FAIL */
14380
14381       /* If one of the two operands is an interesting constant, load a
14382          constant with the above and mask it in with a logical operation.  */
14383
14384       if (CONST_INT_P (operands[2]))
14385         {
14386           var = operands[3];
14387           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
14388             operands[3] = constm1_rtx, op = and_optab;
14389           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
14390             operands[3] = const0_rtx, op = ior_optab;
14391           else
14392             return 0; /* FAIL */
14393         }
14394       else if (CONST_INT_P (operands[3]))
14395         {
14396           var = operands[2];
14397           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
14398             operands[2] = constm1_rtx, op = and_optab;
14399           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
14400             operands[2] = const0_rtx, op = ior_optab;
14401           else
14402             return 0; /* FAIL */
14403         }
14404       else
14405         return 0; /* FAIL */
14406
14407       orig_out = operands[0];
14408       tmp = gen_reg_rtx (mode);
14409       operands[0] = tmp;
14410
14411       /* Recurse to get the constant loaded.  */
14412       if (ix86_expand_int_movcc (operands) == 0)
14413         return 0; /* FAIL */
14414
14415       /* Mask in the interesting variable.  */
14416       out = expand_binop (mode, op, var, tmp, orig_out, 0,
14417                           OPTAB_WIDEN);
14418       if (!rtx_equal_p (out, orig_out))
14419         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
14420
14421       return 1; /* DONE */
14422     }
14423
14424   /*
14425    * For comparison with above,
14426    *
14427    * movl cf,dest
14428    * movl ct,tmp
14429    * cmpl op1,op2
14430    * cmovcc tmp,dest
14431    *
14432    * Size 15.
14433    */
14434
14435   if (! nonimmediate_operand (operands[2], mode))
14436     operands[2] = force_reg (mode, operands[2]);
14437   if (! nonimmediate_operand (operands[3], mode))
14438     operands[3] = force_reg (mode, operands[3]);
14439
14440   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
14441     {
14442       rtx tmp = gen_reg_rtx (mode);
14443       emit_move_insn (tmp, operands[3]);
14444       operands[3] = tmp;
14445     }
14446   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
14447     {
14448       rtx tmp = gen_reg_rtx (mode);
14449       emit_move_insn (tmp, operands[2]);
14450       operands[2] = tmp;
14451     }
14452
14453   if (! register_operand (operands[2], VOIDmode)
14454       && (mode == QImode
14455           || ! register_operand (operands[3], VOIDmode)))
14456     operands[2] = force_reg (mode, operands[2]);
14457
14458   if (mode == QImode
14459       && ! register_operand (operands[3], VOIDmode))
14460     operands[3] = force_reg (mode, operands[3]);
14461
14462   emit_insn (compare_seq);
14463   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
14464                           gen_rtx_IF_THEN_ELSE (mode,
14465                                                 compare_op, operands[2],
14466                                                 operands[3])));
14467   if (bypass_test)
14468     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
14469                             gen_rtx_IF_THEN_ELSE (mode,
14470                                   bypass_test,
14471                                   copy_rtx (operands[3]),
14472                                   copy_rtx (operands[0]))));
14473   if (second_test)
14474     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
14475                             gen_rtx_IF_THEN_ELSE (mode,
14476                                   second_test,
14477                                   copy_rtx (operands[2]),
14478                                   copy_rtx (operands[0]))));
14479
14480   return 1; /* DONE */
14481 }
14482
14483 /* Swap, force into registers, or otherwise massage the two operands
14484    to an sse comparison with a mask result.  Thus we differ a bit from
14485    ix86_prepare_fp_compare_args which expects to produce a flags result.
14486
14487    The DEST operand exists to help determine whether to commute commutative
14488    operators.  The POP0/POP1 operands are updated in place.  The new
14489    comparison code is returned, or UNKNOWN if not implementable.  */
14490
14491 static enum rtx_code
14492 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
14493                                   rtx *pop0, rtx *pop1)
14494 {
14495   rtx tmp;
14496
14497   switch (code)
14498     {
14499     case LTGT:
14500     case UNEQ:
14501       /* We have no LTGT as an operator.  We could implement it with
14502          NE & ORDERED, but this requires an extra temporary.  It's
14503          not clear that it's worth it.  */
14504       return UNKNOWN;
14505
14506     case LT:
14507     case LE:
14508     case UNGT:
14509     case UNGE:
14510       /* These are supported directly.  */
14511       break;
14512
14513     case EQ:
14514     case NE:
14515     case UNORDERED:
14516     case ORDERED:
14517       /* For commutative operators, try to canonicalize the destination
14518          operand to be first in the comparison - this helps reload to
14519          avoid extra moves.  */
14520       if (!dest || !rtx_equal_p (dest, *pop1))
14521         break;
14522       /* FALLTHRU */
14523
14524     case GE:
14525     case GT:
14526     case UNLE:
14527     case UNLT:
14528       /* These are not supported directly.  Swap the comparison operands
14529          to transform into something that is supported.  */
14530       tmp = *pop0;
14531       *pop0 = *pop1;
14532       *pop1 = tmp;
14533       code = swap_condition (code);
14534       break;
14535
14536     default:
14537       gcc_unreachable ();
14538     }
14539
14540   return code;
14541 }
14542
14543 /* Detect conditional moves that exactly match min/max operational
14544    semantics.  Note that this is IEEE safe, as long as we don't
14545    interchange the operands.
14546
14547    Returns FALSE if this conditional move doesn't match a MIN/MAX,
14548    and TRUE if the operation is successful and instructions are emitted.  */
14549
14550 static bool
14551 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
14552                            rtx cmp_op1, rtx if_true, rtx if_false)
14553 {
14554   enum machine_mode mode;
14555   bool is_min;
14556   rtx tmp;
14557
14558   if (code == LT)
14559     ;
14560   else if (code == UNGE)
14561     {
14562       tmp = if_true;
14563       if_true = if_false;
14564       if_false = tmp;
14565     }
14566   else
14567     return false;
14568
14569   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
14570     is_min = true;
14571   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
14572     is_min = false;
14573   else
14574     return false;
14575
14576   mode = GET_MODE (dest);
14577
14578   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
14579      but MODE may be a vector mode and thus not appropriate.  */
14580   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
14581     {
14582       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
14583       rtvec v;
14584
14585       if_true = force_reg (mode, if_true);
14586       v = gen_rtvec (2, if_true, if_false);
14587       tmp = gen_rtx_UNSPEC (mode, v, u);
14588     }
14589   else
14590     {
14591       code = is_min ? SMIN : SMAX;
14592       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
14593     }
14594
14595   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
14596   return true;
14597 }
14598
14599 /* Expand an sse vector comparison.  Return the register with the result.  */
14600
14601 static rtx
14602 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
14603                      rtx op_true, rtx op_false)
14604 {
14605   enum machine_mode mode = GET_MODE (dest);
14606   rtx x;
14607
14608   cmp_op0 = force_reg (mode, cmp_op0);
14609   if (!nonimmediate_operand (cmp_op1, mode))
14610     cmp_op1 = force_reg (mode, cmp_op1);
14611
14612   if (optimize
14613       || reg_overlap_mentioned_p (dest, op_true)
14614       || reg_overlap_mentioned_p (dest, op_false))
14615     dest = gen_reg_rtx (mode);
14616
14617   x = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
14618   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14619
14620   return dest;
14621 }
14622
14623 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
14624    operations.  This is used for both scalar and vector conditional moves.  */
14625
14626 static void
14627 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
14628 {
14629   enum machine_mode mode = GET_MODE (dest);
14630   rtx t2, t3, x;
14631
14632   if (op_false == CONST0_RTX (mode))
14633     {
14634       op_true = force_reg (mode, op_true);
14635       x = gen_rtx_AND (mode, cmp, op_true);
14636       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14637     }
14638   else if (op_true == CONST0_RTX (mode))
14639     {
14640       op_false = force_reg (mode, op_false);
14641       x = gen_rtx_NOT (mode, cmp);
14642       x = gen_rtx_AND (mode, x, op_false);
14643       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14644     }
14645   else if (TARGET_SSE5)
14646     {
14647       rtx pcmov = gen_rtx_SET (mode, dest,
14648                                gen_rtx_IF_THEN_ELSE (mode, cmp,
14649                                                      op_true,
14650                                                      op_false));
14651       emit_insn (pcmov);
14652     }
14653   else
14654     {
14655       op_true = force_reg (mode, op_true);
14656       op_false = force_reg (mode, op_false);
14657
14658       t2 = gen_reg_rtx (mode);
14659       if (optimize)
14660         t3 = gen_reg_rtx (mode);
14661       else
14662         t3 = dest;
14663
14664       x = gen_rtx_AND (mode, op_true, cmp);
14665       emit_insn (gen_rtx_SET (VOIDmode, t2, x));
14666
14667       x = gen_rtx_NOT (mode, cmp);
14668       x = gen_rtx_AND (mode, x, op_false);
14669       emit_insn (gen_rtx_SET (VOIDmode, t3, x));
14670
14671       x = gen_rtx_IOR (mode, t3, t2);
14672       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
14673     }
14674 }
14675
14676 /* Expand a floating-point conditional move.  Return true if successful.  */
14677
14678 int
14679 ix86_expand_fp_movcc (rtx operands[])
14680 {
14681   enum machine_mode mode = GET_MODE (operands[0]);
14682   enum rtx_code code = GET_CODE (operands[1]);
14683   rtx tmp, compare_op, second_test, bypass_test;
14684
14685   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
14686     {
14687       enum machine_mode cmode;
14688
14689       /* Since we've no cmove for sse registers, don't force bad register
14690          allocation just to gain access to it.  Deny movcc when the
14691          comparison mode doesn't match the move mode.  */
14692       cmode = GET_MODE (ix86_compare_op0);
14693       if (cmode == VOIDmode)
14694         cmode = GET_MODE (ix86_compare_op1);
14695       if (cmode != mode)
14696         return 0;
14697
14698       code = ix86_prepare_sse_fp_compare_args (operands[0], code,
14699                                                &ix86_compare_op0,
14700                                                &ix86_compare_op1);
14701       if (code == UNKNOWN)
14702         return 0;
14703
14704       if (ix86_expand_sse_fp_minmax (operands[0], code, ix86_compare_op0,
14705                                      ix86_compare_op1, operands[2],
14706                                      operands[3]))
14707         return 1;
14708
14709       tmp = ix86_expand_sse_cmp (operands[0], code, ix86_compare_op0,
14710                                  ix86_compare_op1, operands[2], operands[3]);
14711       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
14712       return 1;
14713     }
14714
14715   /* The floating point conditional move instructions don't directly
14716      support conditions resulting from a signed integer comparison.  */
14717
14718   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
14719
14720   /* The floating point conditional move instructions don't directly
14721      support signed integer comparisons.  */
14722
14723   if (!fcmov_comparison_operator (compare_op, VOIDmode))
14724     {
14725       gcc_assert (!second_test && !bypass_test);
14726       tmp = gen_reg_rtx (QImode);
14727       ix86_expand_setcc (code, tmp);
14728       code = NE;
14729       ix86_compare_op0 = tmp;
14730       ix86_compare_op1 = const0_rtx;
14731       compare_op = ix86_expand_compare (code,  &second_test, &bypass_test);
14732     }
14733   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
14734     {
14735       tmp = gen_reg_rtx (mode);
14736       emit_move_insn (tmp, operands[3]);
14737       operands[3] = tmp;
14738     }
14739   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
14740     {
14741       tmp = gen_reg_rtx (mode);
14742       emit_move_insn (tmp, operands[2]);
14743       operands[2] = tmp;
14744     }
14745
14746   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
14747                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
14748                                                 operands[2], operands[3])));
14749   if (bypass_test)
14750     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
14751                             gen_rtx_IF_THEN_ELSE (mode, bypass_test,
14752                                                   operands[3], operands[0])));
14753   if (second_test)
14754     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
14755                             gen_rtx_IF_THEN_ELSE (mode, second_test,
14756                                                   operands[2], operands[0])));
14757
14758   return 1;
14759 }
14760
14761 /* Expand a floating-point vector conditional move; a vcond operation
14762    rather than a movcc operation.  */
14763
14764 bool
14765 ix86_expand_fp_vcond (rtx operands[])
14766 {
14767   enum rtx_code code = GET_CODE (operands[3]);
14768   rtx cmp;
14769
14770   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
14771                                            &operands[4], &operands[5]);
14772   if (code == UNKNOWN)
14773     return false;
14774
14775   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
14776                                  operands[5], operands[1], operands[2]))
14777     return true;
14778
14779   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
14780                              operands[1], operands[2]);
14781   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
14782   return true;
14783 }
14784
14785 /* Expand a signed/unsigned integral vector conditional move.  */
14786
14787 bool
14788 ix86_expand_int_vcond (rtx operands[])
14789 {
14790   enum machine_mode mode = GET_MODE (operands[0]);
14791   enum rtx_code code = GET_CODE (operands[3]);
14792   bool negate = false;
14793   rtx x, cop0, cop1;
14794
14795   cop0 = operands[4];
14796   cop1 = operands[5];
14797
14798   /* SSE5 supports all of the comparisons on all vector int types.  */
14799   if (!TARGET_SSE5)
14800     {
14801       /* Canonicalize the comparison to EQ, GT, GTU.  */
14802       switch (code)
14803         {
14804         case EQ:
14805         case GT:
14806         case GTU:
14807           break;
14808
14809         case NE:
14810         case LE:
14811         case LEU:
14812           code = reverse_condition (code);
14813           negate = true;
14814           break;
14815
14816         case GE:
14817         case GEU:
14818           code = reverse_condition (code);
14819           negate = true;
14820           /* FALLTHRU */
14821
14822         case LT:
14823         case LTU:
14824           code = swap_condition (code);
14825           x = cop0, cop0 = cop1, cop1 = x;
14826           break;
14827
14828         default:
14829           gcc_unreachable ();
14830         }
14831
14832       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
14833       if (mode == V2DImode)
14834         {
14835           switch (code)
14836             {
14837             case EQ:
14838               /* SSE4.1 supports EQ.  */
14839               if (!TARGET_SSE4_1)
14840                 return false;
14841               break;
14842
14843             case GT:
14844             case GTU:
14845               /* SSE4.2 supports GT/GTU.  */
14846               if (!TARGET_SSE4_2)
14847                 return false;
14848               break;
14849
14850             default:
14851               gcc_unreachable ();
14852             }
14853         }
14854
14855       /* Unsigned parallel compare is not supported by the hardware.  Play some
14856          tricks to turn this into a signed comparison against 0.  */
14857       if (code == GTU)
14858         {
14859           cop0 = force_reg (mode, cop0);
14860
14861           switch (mode)
14862             {
14863             case V4SImode:
14864             case V2DImode:
14865               {
14866                 rtx t1, t2, mask;
14867
14868                 /* Perform a parallel modulo subtraction.  */
14869                 t1 = gen_reg_rtx (mode);
14870                 emit_insn ((mode == V4SImode
14871                             ? gen_subv4si3
14872                             : gen_subv2di3) (t1, cop0, cop1));
14873
14874                 /* Extract the original sign bit of op0.  */
14875                 mask = ix86_build_signbit_mask (GET_MODE_INNER (mode),
14876                                                 true, false);
14877                 t2 = gen_reg_rtx (mode);
14878                 emit_insn ((mode == V4SImode
14879                             ? gen_andv4si3
14880                             : gen_andv2di3) (t2, cop0, mask));
14881
14882                 /* XOR it back into the result of the subtraction.  This results
14883                    in the sign bit set iff we saw unsigned underflow.  */
14884                 x = gen_reg_rtx (mode);
14885                 emit_insn ((mode == V4SImode
14886                             ? gen_xorv4si3
14887                             : gen_xorv2di3) (x, t1, t2));
14888
14889                 code = GT;
14890               }
14891               break;
14892
14893             case V16QImode:
14894             case V8HImode:
14895               /* Perform a parallel unsigned saturating subtraction.  */
14896               x = gen_reg_rtx (mode);
14897               emit_insn (gen_rtx_SET (VOIDmode, x,
14898                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
14899
14900               code = EQ;
14901               negate = !negate;
14902               break;
14903
14904             default:
14905               gcc_unreachable ();
14906             }
14907
14908           cop0 = x;
14909           cop1 = CONST0_RTX (mode);
14910         }
14911     }
14912
14913   x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
14914                            operands[1+negate], operands[2-negate]);
14915
14916   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
14917                          operands[2-negate]);
14918   return true;
14919 }
14920
14921 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
14922    true if we should do zero extension, else sign extension.  HIGH_P is
14923    true if we want the N/2 high elements, else the low elements.  */
14924
14925 void
14926 ix86_expand_sse_unpack (rtx operands[2], bool unsigned_p, bool high_p)
14927 {
14928   enum machine_mode imode = GET_MODE (operands[1]);
14929   rtx (*unpack)(rtx, rtx, rtx);
14930   rtx se, dest;
14931
14932   switch (imode)
14933     {
14934     case V16QImode:
14935       if (high_p)
14936         unpack = gen_vec_interleave_highv16qi;
14937       else
14938         unpack = gen_vec_interleave_lowv16qi;
14939       break;
14940     case V8HImode:
14941       if (high_p)
14942         unpack = gen_vec_interleave_highv8hi;
14943       else
14944         unpack = gen_vec_interleave_lowv8hi;
14945       break;
14946     case V4SImode:
14947       if (high_p)
14948         unpack = gen_vec_interleave_highv4si;
14949       else
14950         unpack = gen_vec_interleave_lowv4si;
14951       break;
14952     default:
14953       gcc_unreachable ();
14954     }
14955
14956   dest = gen_lowpart (imode, operands[0]);
14957
14958   if (unsigned_p)
14959     se = force_reg (imode, CONST0_RTX (imode));
14960   else
14961     se = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
14962                               operands[1], pc_rtx, pc_rtx);
14963
14964   emit_insn (unpack (dest, operands[1], se));
14965 }
14966
14967 /* This function performs the same task as ix86_expand_sse_unpack,
14968    but with SSE4.1 instructions.  */
14969
14970 void
14971 ix86_expand_sse4_unpack (rtx operands[2], bool unsigned_p, bool high_p)
14972 {
14973   enum machine_mode imode = GET_MODE (operands[1]);
14974   rtx (*unpack)(rtx, rtx);
14975   rtx src, dest;
14976
14977   switch (imode)
14978     {
14979     case V16QImode:
14980       if (unsigned_p)
14981         unpack = gen_sse4_1_zero_extendv8qiv8hi2;
14982       else
14983         unpack = gen_sse4_1_extendv8qiv8hi2;
14984       break;
14985     case V8HImode:
14986       if (unsigned_p)
14987         unpack = gen_sse4_1_zero_extendv4hiv4si2;
14988       else
14989         unpack = gen_sse4_1_extendv4hiv4si2;
14990       break;
14991     case V4SImode:
14992       if (unsigned_p)
14993         unpack = gen_sse4_1_zero_extendv2siv2di2;
14994       else
14995         unpack = gen_sse4_1_extendv2siv2di2;
14996       break;
14997     default:
14998       gcc_unreachable ();
14999     }
15000
15001   dest = operands[0];
15002   if (high_p)
15003     {
15004       /* Shift higher 8 bytes to lower 8 bytes.  */
15005       src = gen_reg_rtx (imode);
15006       emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, src),
15007                                    gen_lowpart (TImode, operands[1]),
15008                                    GEN_INT (64)));
15009     }
15010   else
15011     src = operands[1];
15012
15013   emit_insn (unpack (dest, src));
15014 }
15015
15016 /* This function performs the same task as ix86_expand_sse_unpack,
15017    but with sse5 instructions.  */
15018
15019 void
15020 ix86_expand_sse5_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15021 {
15022   enum machine_mode imode = GET_MODE (operands[1]);
15023   int pperm_bytes[16];
15024   int i;
15025   int h = (high_p) ? 8 : 0;
15026   int h2;
15027   int sign_extend;
15028   rtvec v = rtvec_alloc (16);
15029   rtvec vs;
15030   rtx x, p;
15031   rtx op0 = operands[0], op1 = operands[1];
15032
15033   switch (imode)
15034     {
15035     case V16QImode:
15036       vs = rtvec_alloc (8);
15037       h2 = (high_p) ? 8 : 0;
15038       for (i = 0; i < 8; i++)
15039         {
15040           pperm_bytes[2*i+0] = PPERM_SRC | PPERM_SRC2 | i | h;
15041           pperm_bytes[2*i+1] = ((unsigned_p)
15042                                 ? PPERM_ZERO
15043                                 : PPERM_SIGN | PPERM_SRC2 | i | h);
15044         }
15045
15046       for (i = 0; i < 16; i++)
15047         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15048
15049       for (i = 0; i < 8; i++)
15050         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15051
15052       p = gen_rtx_PARALLEL (VOIDmode, vs);
15053       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15054       if (unsigned_p)
15055         emit_insn (gen_sse5_pperm_zero_v16qi_v8hi (op0, op1, p, x));
15056       else
15057         emit_insn (gen_sse5_pperm_sign_v16qi_v8hi (op0, op1, p, x));
15058       break;
15059
15060     case V8HImode:
15061       vs = rtvec_alloc (4);
15062       h2 = (high_p) ? 4 : 0;
15063       for (i = 0; i < 4; i++)
15064         {
15065           sign_extend = ((unsigned_p)
15066                          ? PPERM_ZERO
15067                          : PPERM_SIGN | PPERM_SRC2 | ((2*i) + 1 + h));
15068           pperm_bytes[4*i+0] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 0 + h);
15069           pperm_bytes[4*i+1] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 1 + h);
15070           pperm_bytes[4*i+2] = sign_extend;
15071           pperm_bytes[4*i+3] = sign_extend;
15072         }
15073
15074       for (i = 0; i < 16; i++)
15075         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15076
15077       for (i = 0; i < 4; i++)
15078         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15079
15080       p = gen_rtx_PARALLEL (VOIDmode, vs);
15081       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15082       if (unsigned_p)
15083         emit_insn (gen_sse5_pperm_zero_v8hi_v4si (op0, op1, p, x));
15084       else
15085         emit_insn (gen_sse5_pperm_sign_v8hi_v4si (op0, op1, p, x));
15086       break;
15087
15088     case V4SImode:
15089       vs = rtvec_alloc (2);
15090       h2 = (high_p) ? 2 : 0;
15091       for (i = 0; i < 2; i++)
15092         {
15093           sign_extend = ((unsigned_p)
15094                          ? PPERM_ZERO
15095                          : PPERM_SIGN | PPERM_SRC2 | ((4*i) + 3 + h));
15096           pperm_bytes[8*i+0] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 0 + h);
15097           pperm_bytes[8*i+1] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 1 + h);
15098           pperm_bytes[8*i+2] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 2 + h);
15099           pperm_bytes[8*i+3] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 3 + h);
15100           pperm_bytes[8*i+4] = sign_extend;
15101           pperm_bytes[8*i+5] = sign_extend;
15102           pperm_bytes[8*i+6] = sign_extend;
15103           pperm_bytes[8*i+7] = sign_extend;
15104         }
15105
15106       for (i = 0; i < 16; i++)
15107         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15108
15109       for (i = 0; i < 2; i++)
15110         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15111
15112       p = gen_rtx_PARALLEL (VOIDmode, vs);
15113       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15114       if (unsigned_p)
15115         emit_insn (gen_sse5_pperm_zero_v4si_v2di (op0, op1, p, x));
15116       else
15117         emit_insn (gen_sse5_pperm_sign_v4si_v2di (op0, op1, p, x));
15118       break;
15119
15120     default:
15121       gcc_unreachable ();
15122     }
15123
15124   return;
15125 }
15126
15127 /* Pack the high bits from OPERANDS[1] and low bits from OPERANDS[2] into the
15128    next narrower integer vector type */
15129 void
15130 ix86_expand_sse5_pack (rtx operands[3])
15131 {
15132   enum machine_mode imode = GET_MODE (operands[0]);
15133   int pperm_bytes[16];
15134   int i;
15135   rtvec v = rtvec_alloc (16);
15136   rtx x;
15137   rtx op0 = operands[0];
15138   rtx op1 = operands[1];
15139   rtx op2 = operands[2];
15140
15141   switch (imode)
15142     {
15143     case V16QImode:
15144       for (i = 0; i < 8; i++)
15145         {
15146           pperm_bytes[i+0] = PPERM_SRC | PPERM_SRC1 | (i*2);
15147           pperm_bytes[i+8] = PPERM_SRC | PPERM_SRC2 | (i*2);
15148         }
15149
15150       for (i = 0; i < 16; i++)
15151         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15152
15153       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15154       emit_insn (gen_sse5_pperm_pack_v8hi_v16qi (op0, op1, op2, x));
15155       break;
15156
15157     case V8HImode:
15158       for (i = 0; i < 4; i++)
15159         {
15160           pperm_bytes[(2*i)+0] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 0);
15161           pperm_bytes[(2*i)+1] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 1);
15162           pperm_bytes[(2*i)+8] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 0);
15163           pperm_bytes[(2*i)+9] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 1);
15164         }
15165
15166       for (i = 0; i < 16; i++)
15167         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15168
15169       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15170       emit_insn (gen_sse5_pperm_pack_v4si_v8hi (op0, op1, op2, x));
15171       break;
15172
15173     case V4SImode:
15174       for (i = 0; i < 2; i++)
15175         {
15176           pperm_bytes[(4*i)+0]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 0);
15177           pperm_bytes[(4*i)+1]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 1);
15178           pperm_bytes[(4*i)+2]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 2);
15179           pperm_bytes[(4*i)+3]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 3);
15180           pperm_bytes[(4*i)+8]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 0);
15181           pperm_bytes[(4*i)+9]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 1);
15182           pperm_bytes[(4*i)+10] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 2);
15183           pperm_bytes[(4*i)+11] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 3);
15184         }
15185
15186       for (i = 0; i < 16; i++)
15187         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15188
15189       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15190       emit_insn (gen_sse5_pperm_pack_v2di_v4si (op0, op1, op2, x));
15191       break;
15192
15193     default:
15194       gcc_unreachable ();
15195     }
15196
15197   return;
15198 }
15199
15200 /* Expand conditional increment or decrement using adb/sbb instructions.
15201    The default case using setcc followed by the conditional move can be
15202    done by generic code.  */
15203 int
15204 ix86_expand_int_addcc (rtx operands[])
15205 {
15206   enum rtx_code code = GET_CODE (operands[1]);
15207   rtx compare_op;
15208   rtx val = const0_rtx;
15209   bool fpcmp = false;
15210   enum machine_mode mode = GET_MODE (operands[0]);
15211
15212   if (operands[3] != const1_rtx
15213       && operands[3] != constm1_rtx)
15214     return 0;
15215   if (!ix86_expand_carry_flag_compare (code, ix86_compare_op0,
15216                                        ix86_compare_op1, &compare_op))
15217      return 0;
15218   code = GET_CODE (compare_op);
15219
15220   if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
15221       || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
15222     {
15223       fpcmp = true;
15224       code = ix86_fp_compare_code_to_integer (code);
15225     }
15226
15227   if (code != LTU)
15228     {
15229       val = constm1_rtx;
15230       if (fpcmp)
15231         PUT_CODE (compare_op,
15232                   reverse_condition_maybe_unordered
15233                     (GET_CODE (compare_op)));
15234       else
15235         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
15236     }
15237   PUT_MODE (compare_op, mode);
15238
15239   /* Construct either adc or sbb insn.  */
15240   if ((code == LTU) == (operands[3] == constm1_rtx))
15241     {
15242       switch (GET_MODE (operands[0]))
15243         {
15244           case QImode:
15245             emit_insn (gen_subqi3_carry (operands[0], operands[2], val, compare_op));
15246             break;
15247           case HImode:
15248             emit_insn (gen_subhi3_carry (operands[0], operands[2], val, compare_op));
15249             break;
15250           case SImode:
15251             emit_insn (gen_subsi3_carry (operands[0], operands[2], val, compare_op));
15252             break;
15253           case DImode:
15254             emit_insn (gen_subdi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15255             break;
15256           default:
15257             gcc_unreachable ();
15258         }
15259     }
15260   else
15261     {
15262       switch (GET_MODE (operands[0]))
15263         {
15264           case QImode:
15265             emit_insn (gen_addqi3_carry (operands[0], operands[2], val, compare_op));
15266             break;
15267           case HImode:
15268             emit_insn (gen_addhi3_carry (operands[0], operands[2], val, compare_op));
15269             break;
15270           case SImode:
15271             emit_insn (gen_addsi3_carry (operands[0], operands[2], val, compare_op));
15272             break;
15273           case DImode:
15274             emit_insn (gen_adddi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15275             break;
15276           default:
15277             gcc_unreachable ();
15278         }
15279     }
15280   return 1; /* DONE */
15281 }
15282
15283
15284 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
15285    works for floating pointer parameters and nonoffsetable memories.
15286    For pushes, it returns just stack offsets; the values will be saved
15287    in the right order.  Maximally three parts are generated.  */
15288
15289 static int
15290 ix86_split_to_parts (rtx operand, rtx *parts, enum machine_mode mode)
15291 {
15292   int size;
15293
15294   if (!TARGET_64BIT)
15295     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
15296   else
15297     size = (GET_MODE_SIZE (mode) + 4) / 8;
15298
15299   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
15300   gcc_assert (size >= 2 && size <= 4);
15301
15302   /* Optimize constant pool reference to immediates.  This is used by fp
15303      moves, that force all constants to memory to allow combining.  */
15304   if (MEM_P (operand) && MEM_READONLY_P (operand))
15305     {
15306       rtx tmp = maybe_get_pool_constant (operand);
15307       if (tmp)
15308         operand = tmp;
15309     }
15310
15311   if (MEM_P (operand) && !offsettable_memref_p (operand))
15312     {
15313       /* The only non-offsetable memories we handle are pushes.  */
15314       int ok = push_operand (operand, VOIDmode);
15315
15316       gcc_assert (ok);
15317
15318       operand = copy_rtx (operand);
15319       PUT_MODE (operand, Pmode);
15320       parts[0] = parts[1] = parts[2] = parts[3] = operand;
15321       return size;
15322     }
15323
15324   if (GET_CODE (operand) == CONST_VECTOR)
15325     {
15326       enum machine_mode imode = int_mode_for_mode (mode);
15327       /* Caution: if we looked through a constant pool memory above,
15328          the operand may actually have a different mode now.  That's
15329          ok, since we want to pun this all the way back to an integer.  */
15330       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
15331       gcc_assert (operand != NULL);
15332       mode = imode;
15333     }
15334
15335   if (!TARGET_64BIT)
15336     {
15337       if (mode == DImode)
15338         split_di (&operand, 1, &parts[0], &parts[1]);
15339       else
15340         {
15341           int i;
15342
15343           if (REG_P (operand))
15344             {
15345               gcc_assert (reload_completed);
15346               for (i = 0; i < size; i++)
15347                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
15348             }
15349           else if (offsettable_memref_p (operand))
15350             {
15351               operand = adjust_address (operand, SImode, 0);
15352               parts[0] = operand;
15353               for (i = 1; i < size; i++)
15354                 parts[i] = adjust_address (operand, SImode, 4 * i);
15355             }
15356           else if (GET_CODE (operand) == CONST_DOUBLE)
15357             {
15358               REAL_VALUE_TYPE r;
15359               long l[4];
15360
15361               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
15362               switch (mode)
15363                 {
15364                 case TFmode:
15365                   real_to_target (l, &r, mode);
15366                   parts[3] = gen_int_mode (l[3], SImode);
15367                   parts[2] = gen_int_mode (l[2], SImode);
15368                   break;
15369                 case XFmode:
15370                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
15371                   parts[2] = gen_int_mode (l[2], SImode);
15372                   break;
15373                 case DFmode:
15374                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
15375                   break;
15376                 default:
15377                   gcc_unreachable ();
15378                 }
15379               parts[1] = gen_int_mode (l[1], SImode);
15380               parts[0] = gen_int_mode (l[0], SImode);
15381             }
15382           else
15383             gcc_unreachable ();
15384         }
15385     }
15386   else
15387     {
15388       if (mode == TImode)
15389         split_ti (&operand, 1, &parts[0], &parts[1]);
15390       if (mode == XFmode || mode == TFmode)
15391         {
15392           enum machine_mode upper_mode = mode==XFmode ? SImode : DImode;
15393           if (REG_P (operand))
15394             {
15395               gcc_assert (reload_completed);
15396               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
15397               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
15398             }
15399           else if (offsettable_memref_p (operand))
15400             {
15401               operand = adjust_address (operand, DImode, 0);
15402               parts[0] = operand;
15403               parts[1] = adjust_address (operand, upper_mode, 8);
15404             }
15405           else if (GET_CODE (operand) == CONST_DOUBLE)
15406             {
15407               REAL_VALUE_TYPE r;
15408               long l[4];
15409
15410               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
15411               real_to_target (l, &r, mode);
15412
15413               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
15414               if (HOST_BITS_PER_WIDE_INT >= 64)
15415                 parts[0]
15416                   = gen_int_mode
15417                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
15418                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
15419                        DImode);
15420               else
15421                 parts[0] = immed_double_const (l[0], l[1], DImode);
15422
15423               if (upper_mode == SImode)
15424                 parts[1] = gen_int_mode (l[2], SImode);
15425               else if (HOST_BITS_PER_WIDE_INT >= 64)
15426                 parts[1]
15427                   = gen_int_mode
15428                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
15429                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
15430                        DImode);
15431               else
15432                 parts[1] = immed_double_const (l[2], l[3], DImode);
15433             }
15434           else
15435             gcc_unreachable ();
15436         }
15437     }
15438
15439   return size;
15440 }
15441
15442 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
15443    Return false when normal moves are needed; true when all required
15444    insns have been emitted.  Operands 2-4 contain the input values
15445    int the correct order; operands 5-7 contain the output values.  */
15446
15447 void
15448 ix86_split_long_move (rtx operands[])
15449 {
15450   rtx part[2][4];
15451   int nparts, i, j;
15452   int push = 0;
15453   int collisions = 0;
15454   enum machine_mode mode = GET_MODE (operands[0]);
15455   bool collisionparts[4];
15456
15457   /* The DFmode expanders may ask us to move double.
15458      For 64bit target this is single move.  By hiding the fact
15459      here we simplify i386.md splitters.  */
15460   if (GET_MODE_SIZE (GET_MODE (operands[0])) == 8 && TARGET_64BIT)
15461     {
15462       /* Optimize constant pool reference to immediates.  This is used by
15463          fp moves, that force all constants to memory to allow combining.  */
15464
15465       if (MEM_P (operands[1])
15466           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
15467           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
15468         operands[1] = get_pool_constant (XEXP (operands[1], 0));
15469       if (push_operand (operands[0], VOIDmode))
15470         {
15471           operands[0] = copy_rtx (operands[0]);
15472           PUT_MODE (operands[0], Pmode);
15473         }
15474       else
15475         operands[0] = gen_lowpart (DImode, operands[0]);
15476       operands[1] = gen_lowpart (DImode, operands[1]);
15477       emit_move_insn (operands[0], operands[1]);
15478       return;
15479     }
15480
15481   /* The only non-offsettable memory we handle is push.  */
15482   if (push_operand (operands[0], VOIDmode))
15483     push = 1;
15484   else
15485     gcc_assert (!MEM_P (operands[0])
15486                 || offsettable_memref_p (operands[0]));
15487
15488   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
15489   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
15490
15491   /* When emitting push, take care for source operands on the stack.  */
15492   if (push && MEM_P (operands[1])
15493       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
15494     for (i = 0; i < nparts - 1; i++)
15495       part[1][i] = change_address (part[1][i],
15496                                    GET_MODE (part[1][i]),
15497                                    XEXP (part[1][i + 1], 0));
15498
15499   /* We need to do copy in the right order in case an address register
15500      of the source overlaps the destination.  */
15501   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
15502     {
15503       rtx tmp;
15504
15505       for (i = 0; i < nparts; i++)
15506         {
15507           collisionparts[i]
15508             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
15509           if (collisionparts[i])
15510             collisions++;
15511         }
15512
15513       /* Collision in the middle part can be handled by reordering.  */
15514       if (collisions == 1 && nparts == 3 && collisionparts [1])
15515         {
15516           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
15517           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
15518         }
15519       else if (collisions == 1
15520                && nparts == 4
15521                && (collisionparts [1] || collisionparts [2]))
15522         {
15523           if (collisionparts [1])
15524             {
15525               tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
15526               tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
15527             }
15528           else
15529             {
15530               tmp = part[0][2]; part[0][2] = part[0][3]; part[0][3] = tmp;
15531               tmp = part[1][2]; part[1][2] = part[1][3]; part[1][3] = tmp;
15532             }
15533         }
15534
15535       /* If there are more collisions, we can't handle it by reordering.
15536          Do an lea to the last part and use only one colliding move.  */
15537       else if (collisions > 1)
15538         {
15539           rtx base;
15540
15541           collisions = 1;
15542
15543           base = part[0][nparts - 1];
15544
15545           /* Handle the case when the last part isn't valid for lea.
15546              Happens in 64-bit mode storing the 12-byte XFmode.  */
15547           if (GET_MODE (base) != Pmode)
15548             base = gen_rtx_REG (Pmode, REGNO (base));
15549
15550           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
15551           part[1][0] = replace_equiv_address (part[1][0], base);
15552           for (i = 1; i < nparts; i++)
15553             {
15554               tmp = plus_constant (base, UNITS_PER_WORD * i);
15555               part[1][i] = replace_equiv_address (part[1][i], tmp);
15556             }
15557         }
15558     }
15559
15560   if (push)
15561     {
15562       if (!TARGET_64BIT)
15563         {
15564           if (nparts == 3)
15565             {
15566               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
15567                 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-4)));
15568               emit_move_insn (part[0][2], part[1][2]);
15569             }
15570           else if (nparts == 4)
15571             {
15572               emit_move_insn (part[0][3], part[1][3]);
15573               emit_move_insn (part[0][2], part[1][2]);
15574             }
15575         }
15576       else
15577         {
15578           /* In 64bit mode we don't have 32bit push available.  In case this is
15579              register, it is OK - we will just use larger counterpart.  We also
15580              retype memory - these comes from attempt to avoid REX prefix on
15581              moving of second half of TFmode value.  */
15582           if (GET_MODE (part[1][1]) == SImode)
15583             {
15584               switch (GET_CODE (part[1][1]))
15585                 {
15586                 case MEM:
15587                   part[1][1] = adjust_address (part[1][1], DImode, 0);
15588                   break;
15589
15590                 case REG:
15591                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
15592                   break;
15593
15594                 default:
15595                   gcc_unreachable ();
15596                 }
15597
15598               if (GET_MODE (part[1][0]) == SImode)
15599                 part[1][0] = part[1][1];
15600             }
15601         }
15602       emit_move_insn (part[0][1], part[1][1]);
15603       emit_move_insn (part[0][0], part[1][0]);
15604       return;
15605     }
15606
15607   /* Choose correct order to not overwrite the source before it is copied.  */
15608   if ((REG_P (part[0][0])
15609        && REG_P (part[1][1])
15610        && (REGNO (part[0][0]) == REGNO (part[1][1])
15611            || (nparts == 3
15612                && REGNO (part[0][0]) == REGNO (part[1][2]))
15613            || (nparts == 4
15614                && REGNO (part[0][0]) == REGNO (part[1][3]))))
15615       || (collisions > 0
15616           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
15617     {
15618       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
15619         {
15620           operands[2 + i] = part[0][j];
15621           operands[6 + i] = part[1][j];
15622         }
15623     }
15624   else
15625     {
15626       for (i = 0; i < nparts; i++)
15627         {
15628           operands[2 + i] = part[0][i];
15629           operands[6 + i] = part[1][i];
15630         }
15631     }
15632
15633   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
15634   if (optimize_insn_for_size_p ())
15635     {
15636       for (j = 0; j < nparts - 1; j++)
15637         if (CONST_INT_P (operands[6 + j])
15638             && operands[6 + j] != const0_rtx
15639             && REG_P (operands[2 + j]))
15640           for (i = j; i < nparts - 1; i++)
15641             if (CONST_INT_P (operands[7 + i])
15642                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
15643               operands[7 + i] = operands[2 + j];
15644     }
15645
15646   for (i = 0; i < nparts; i++)
15647     emit_move_insn (operands[2 + i], operands[6 + i]);
15648
15649   return;
15650 }
15651
15652 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
15653    left shift by a constant, either using a single shift or
15654    a sequence of add instructions.  */
15655
15656 static void
15657 ix86_expand_ashl_const (rtx operand, int count, enum machine_mode mode)
15658 {
15659   if (count == 1)
15660     {
15661       emit_insn ((mode == DImode
15662                   ? gen_addsi3
15663                   : gen_adddi3) (operand, operand, operand));
15664     }
15665   else if (!optimize_insn_for_size_p ()
15666            && count * ix86_cost->add <= ix86_cost->shift_const)
15667     {
15668       int i;
15669       for (i=0; i<count; i++)
15670         {
15671           emit_insn ((mode == DImode
15672                       ? gen_addsi3
15673                       : gen_adddi3) (operand, operand, operand));
15674         }
15675     }
15676   else
15677     emit_insn ((mode == DImode
15678                 ? gen_ashlsi3
15679                 : gen_ashldi3) (operand, operand, GEN_INT (count)));
15680 }
15681
15682 void
15683 ix86_split_ashl (rtx *operands, rtx scratch, enum machine_mode mode)
15684 {
15685   rtx low[2], high[2];
15686   int count;
15687   const int single_width = mode == DImode ? 32 : 64;
15688
15689   if (CONST_INT_P (operands[2]))
15690     {
15691       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
15692       count = INTVAL (operands[2]) & (single_width * 2 - 1);
15693
15694       if (count >= single_width)
15695         {
15696           emit_move_insn (high[0], low[1]);
15697           emit_move_insn (low[0], const0_rtx);
15698
15699           if (count > single_width)
15700             ix86_expand_ashl_const (high[0], count - single_width, mode);
15701         }
15702       else
15703         {
15704           if (!rtx_equal_p (operands[0], operands[1]))
15705             emit_move_insn (operands[0], operands[1]);
15706           emit_insn ((mode == DImode
15707                      ? gen_x86_shld
15708                      : gen_x86_64_shld) (high[0], low[0], GEN_INT (count)));
15709           ix86_expand_ashl_const (low[0], count, mode);
15710         }
15711       return;
15712     }
15713
15714   (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
15715
15716   if (operands[1] == const1_rtx)
15717     {
15718       /* Assuming we've chosen a QImode capable registers, then 1 << N
15719          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
15720       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
15721         {
15722           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
15723
15724           ix86_expand_clear (low[0]);
15725           ix86_expand_clear (high[0]);
15726           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (single_width)));
15727
15728           d = gen_lowpart (QImode, low[0]);
15729           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
15730           s = gen_rtx_EQ (QImode, flags, const0_rtx);
15731           emit_insn (gen_rtx_SET (VOIDmode, d, s));
15732
15733           d = gen_lowpart (QImode, high[0]);
15734           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
15735           s = gen_rtx_NE (QImode, flags, const0_rtx);
15736           emit_insn (gen_rtx_SET (VOIDmode, d, s));
15737         }
15738
15739       /* Otherwise, we can get the same results by manually performing
15740          a bit extract operation on bit 5/6, and then performing the two
15741          shifts.  The two methods of getting 0/1 into low/high are exactly
15742          the same size.  Avoiding the shift in the bit extract case helps
15743          pentium4 a bit; no one else seems to care much either way.  */
15744       else
15745         {
15746           rtx x;
15747
15748           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
15749             x = gen_rtx_ZERO_EXTEND (mode == DImode ? SImode : DImode, operands[2]);
15750           else
15751             x = gen_lowpart (mode == DImode ? SImode : DImode, operands[2]);
15752           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
15753
15754           emit_insn ((mode == DImode
15755                       ? gen_lshrsi3
15756                       : gen_lshrdi3) (high[0], high[0], GEN_INT (mode == DImode ? 5 : 6)));
15757           emit_insn ((mode == DImode
15758                       ? gen_andsi3
15759                       : gen_anddi3) (high[0], high[0], GEN_INT (1)));
15760           emit_move_insn (low[0], high[0]);
15761           emit_insn ((mode == DImode
15762                       ? gen_xorsi3
15763                       : gen_xordi3) (low[0], low[0], GEN_INT (1)));
15764         }
15765
15766       emit_insn ((mode == DImode
15767                     ? gen_ashlsi3
15768                     : gen_ashldi3) (low[0], low[0], operands[2]));
15769       emit_insn ((mode == DImode
15770                     ? gen_ashlsi3
15771                     : gen_ashldi3) (high[0], high[0], operands[2]));
15772       return;
15773     }
15774
15775   if (operands[1] == constm1_rtx)
15776     {
15777       /* For -1 << N, we can avoid the shld instruction, because we
15778          know that we're shifting 0...31/63 ones into a -1.  */
15779       emit_move_insn (low[0], constm1_rtx);
15780       if (optimize_insn_for_size_p ())
15781         emit_move_insn (high[0], low[0]);
15782       else
15783         emit_move_insn (high[0], constm1_rtx);
15784     }
15785   else
15786     {
15787       if (!rtx_equal_p (operands[0], operands[1]))
15788         emit_move_insn (operands[0], operands[1]);
15789
15790       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
15791       emit_insn ((mode == DImode
15792                   ? gen_x86_shld
15793                   : gen_x86_64_shld) (high[0], low[0], operands[2]));
15794     }
15795
15796   emit_insn ((mode == DImode ? gen_ashlsi3 : gen_ashldi3) (low[0], low[0], operands[2]));
15797
15798   if (TARGET_CMOVE && scratch)
15799     {
15800       ix86_expand_clear (scratch);
15801       emit_insn ((mode == DImode
15802                   ? gen_x86_shift_adj_1
15803                   : gen_x86_64_shift_adj_1) (high[0], low[0], operands[2],
15804                                              scratch));
15805     }
15806   else
15807     emit_insn ((mode == DImode
15808                 ? gen_x86_shift_adj_2
15809                 : gen_x86_64_shift_adj_2) (high[0], low[0], operands[2]));
15810 }
15811
15812 void
15813 ix86_split_ashr (rtx *operands, rtx scratch, enum machine_mode mode)
15814 {
15815   rtx low[2], high[2];
15816   int count;
15817   const int single_width = mode == DImode ? 32 : 64;
15818
15819   if (CONST_INT_P (operands[2]))
15820     {
15821       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
15822       count = INTVAL (operands[2]) & (single_width * 2 - 1);
15823
15824       if (count == single_width * 2 - 1)
15825         {
15826           emit_move_insn (high[0], high[1]);
15827           emit_insn ((mode == DImode
15828                       ? gen_ashrsi3
15829                       : gen_ashrdi3) (high[0], high[0],
15830                                       GEN_INT (single_width - 1)));
15831           emit_move_insn (low[0], high[0]);
15832
15833         }
15834       else if (count >= single_width)
15835         {
15836           emit_move_insn (low[0], high[1]);
15837           emit_move_insn (high[0], low[0]);
15838           emit_insn ((mode == DImode
15839                       ? gen_ashrsi3
15840                       : gen_ashrdi3) (high[0], high[0],
15841                                       GEN_INT (single_width - 1)));
15842           if (count > single_width)
15843             emit_insn ((mode == DImode
15844                         ? gen_ashrsi3
15845                         : gen_ashrdi3) (low[0], low[0],
15846                                         GEN_INT (count - single_width)));
15847         }
15848       else
15849         {
15850           if (!rtx_equal_p (operands[0], operands[1]))
15851             emit_move_insn (operands[0], operands[1]);
15852           emit_insn ((mode == DImode
15853                       ? gen_x86_shrd
15854                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
15855           emit_insn ((mode == DImode
15856                       ? gen_ashrsi3
15857                       : gen_ashrdi3) (high[0], high[0], GEN_INT (count)));
15858         }
15859     }
15860   else
15861     {
15862       if (!rtx_equal_p (operands[0], operands[1]))
15863         emit_move_insn (operands[0], operands[1]);
15864
15865       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
15866
15867       emit_insn ((mode == DImode
15868                   ? gen_x86_shrd
15869                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
15870       emit_insn ((mode == DImode
15871                   ? gen_ashrsi3
15872                   : gen_ashrdi3)  (high[0], high[0], operands[2]));
15873
15874       if (TARGET_CMOVE && scratch)
15875         {
15876           emit_move_insn (scratch, high[0]);
15877           emit_insn ((mode == DImode
15878                       ? gen_ashrsi3
15879                       : gen_ashrdi3) (scratch, scratch,
15880                                       GEN_INT (single_width - 1)));
15881           emit_insn ((mode == DImode
15882                       ? gen_x86_shift_adj_1
15883                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
15884                                                  scratch));
15885         }
15886       else
15887         emit_insn ((mode == DImode
15888                     ? gen_x86_shift_adj_3
15889                     : gen_x86_64_shift_adj_3) (low[0], high[0], operands[2]));
15890     }
15891 }
15892
15893 void
15894 ix86_split_lshr (rtx *operands, rtx scratch, enum machine_mode mode)
15895 {
15896   rtx low[2], high[2];
15897   int count;
15898   const int single_width = mode == DImode ? 32 : 64;
15899
15900   if (CONST_INT_P (operands[2]))
15901     {
15902       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
15903       count = INTVAL (operands[2]) & (single_width * 2 - 1);
15904
15905       if (count >= single_width)
15906         {
15907           emit_move_insn (low[0], high[1]);
15908           ix86_expand_clear (high[0]);
15909
15910           if (count > single_width)
15911             emit_insn ((mode == DImode
15912                         ? gen_lshrsi3
15913                         : gen_lshrdi3) (low[0], low[0],
15914                                         GEN_INT (count - single_width)));
15915         }
15916       else
15917         {
15918           if (!rtx_equal_p (operands[0], operands[1]))
15919             emit_move_insn (operands[0], operands[1]);
15920           emit_insn ((mode == DImode
15921                       ? gen_x86_shrd
15922                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
15923           emit_insn ((mode == DImode
15924                       ? gen_lshrsi3
15925                       : gen_lshrdi3) (high[0], high[0], GEN_INT (count)));
15926         }
15927     }
15928   else
15929     {
15930       if (!rtx_equal_p (operands[0], operands[1]))
15931         emit_move_insn (operands[0], operands[1]);
15932
15933       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
15934
15935       emit_insn ((mode == DImode
15936                   ? gen_x86_shrd
15937                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
15938       emit_insn ((mode == DImode
15939                   ? gen_lshrsi3
15940                   : gen_lshrdi3) (high[0], high[0], operands[2]));
15941
15942       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
15943       if (TARGET_CMOVE && scratch)
15944         {
15945           ix86_expand_clear (scratch);
15946           emit_insn ((mode == DImode
15947                       ? gen_x86_shift_adj_1
15948                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
15949                                                  scratch));
15950         }
15951       else
15952         emit_insn ((mode == DImode
15953                     ? gen_x86_shift_adj_2
15954                     : gen_x86_64_shift_adj_2) (low[0], high[0], operands[2]));
15955     }
15956 }
15957
15958 /* Predict just emitted jump instruction to be taken with probability PROB.  */
15959 static void
15960 predict_jump (int prob)
15961 {
15962   rtx insn = get_last_insn ();
15963   gcc_assert (JUMP_P (insn));
15964   REG_NOTES (insn)
15965     = gen_rtx_EXPR_LIST (REG_BR_PROB,
15966                          GEN_INT (prob),
15967                          REG_NOTES (insn));
15968 }
15969
15970 /* Helper function for the string operations below.  Dest VARIABLE whether
15971    it is aligned to VALUE bytes.  If true, jump to the label.  */
15972 static rtx
15973 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
15974 {
15975   rtx label = gen_label_rtx ();
15976   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
15977   if (GET_MODE (variable) == DImode)
15978     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
15979   else
15980     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
15981   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
15982                            1, label);
15983   if (epilogue)
15984     predict_jump (REG_BR_PROB_BASE * 50 / 100);
15985   else
15986     predict_jump (REG_BR_PROB_BASE * 90 / 100);
15987   return label;
15988 }
15989
15990 /* Adjust COUNTER by the VALUE.  */
15991 static void
15992 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
15993 {
15994   if (GET_MODE (countreg) == DImode)
15995     emit_insn (gen_adddi3 (countreg, countreg, GEN_INT (-value)));
15996   else
15997     emit_insn (gen_addsi3 (countreg, countreg, GEN_INT (-value)));
15998 }
15999
16000 /* Zero extend possibly SImode EXP to Pmode register.  */
16001 rtx
16002 ix86_zero_extend_to_Pmode (rtx exp)
16003 {
16004   rtx r;
16005   if (GET_MODE (exp) == VOIDmode)
16006     return force_reg (Pmode, exp);
16007   if (GET_MODE (exp) == Pmode)
16008     return copy_to_mode_reg (Pmode, exp);
16009   r = gen_reg_rtx (Pmode);
16010   emit_insn (gen_zero_extendsidi2 (r, exp));
16011   return r;
16012 }
16013
16014 /* Divide COUNTREG by SCALE.  */
16015 static rtx
16016 scale_counter (rtx countreg, int scale)
16017 {
16018   rtx sc;
16019   rtx piece_size_mask;
16020
16021   if (scale == 1)
16022     return countreg;
16023   if (CONST_INT_P (countreg))
16024     return GEN_INT (INTVAL (countreg) / scale);
16025   gcc_assert (REG_P (countreg));
16026
16027   piece_size_mask = GEN_INT (scale - 1);
16028   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
16029                             GEN_INT (exact_log2 (scale)),
16030                             NULL, 1, OPTAB_DIRECT);
16031   return sc;
16032 }
16033
16034 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
16035    DImode for constant loop counts.  */
16036
16037 static enum machine_mode
16038 counter_mode (rtx count_exp)
16039 {
16040   if (GET_MODE (count_exp) != VOIDmode)
16041     return GET_MODE (count_exp);
16042   if (GET_CODE (count_exp) != CONST_INT)
16043     return Pmode;
16044   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
16045     return DImode;
16046   return SImode;
16047 }
16048
16049 /* When SRCPTR is non-NULL, output simple loop to move memory
16050    pointer to SRCPTR to DESTPTR via chunks of MODE unrolled UNROLL times,
16051    overall size is COUNT specified in bytes.  When SRCPTR is NULL, output the
16052    equivalent loop to set memory by VALUE (supposed to be in MODE).
16053
16054    The size is rounded down to whole number of chunk size moved at once.
16055    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
16056
16057
16058 static void
16059 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
16060                                rtx destptr, rtx srcptr, rtx value,
16061                                rtx count, enum machine_mode mode, int unroll,
16062                                int expected_size)
16063 {
16064   rtx out_label, top_label, iter, tmp;
16065   enum machine_mode iter_mode = counter_mode (count);
16066   rtx piece_size = GEN_INT (GET_MODE_SIZE (mode) * unroll);
16067   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
16068   rtx size;
16069   rtx x_addr;
16070   rtx y_addr;
16071   int i;
16072
16073   top_label = gen_label_rtx ();
16074   out_label = gen_label_rtx ();
16075   iter = gen_reg_rtx (iter_mode);
16076
16077   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
16078                               NULL, 1, OPTAB_DIRECT);
16079   /* Those two should combine.  */
16080   if (piece_size == const1_rtx)
16081     {
16082       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
16083                                true, out_label);
16084       predict_jump (REG_BR_PROB_BASE * 10 / 100);
16085     }
16086   emit_move_insn (iter, const0_rtx);
16087
16088   emit_label (top_label);
16089
16090   tmp = convert_modes (Pmode, iter_mode, iter, true);
16091   x_addr = gen_rtx_PLUS (Pmode, destptr, tmp);
16092   destmem = change_address (destmem, mode, x_addr);
16093
16094   if (srcmem)
16095     {
16096       y_addr = gen_rtx_PLUS (Pmode, srcptr, copy_rtx (tmp));
16097       srcmem = change_address (srcmem, mode, y_addr);
16098
16099       /* When unrolling for chips that reorder memory reads and writes,
16100          we can save registers by using single temporary.
16101          Also using 4 temporaries is overkill in 32bit mode.  */
16102       if (!TARGET_64BIT && 0)
16103         {
16104           for (i = 0; i < unroll; i++)
16105             {
16106               if (i)
16107                 {
16108                   destmem =
16109                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16110                   srcmem =
16111                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16112                 }
16113               emit_move_insn (destmem, srcmem);
16114             }
16115         }
16116       else
16117         {
16118           rtx tmpreg[4];
16119           gcc_assert (unroll <= 4);
16120           for (i = 0; i < unroll; i++)
16121             {
16122               tmpreg[i] = gen_reg_rtx (mode);
16123               if (i)
16124                 {
16125                   srcmem =
16126                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16127                 }
16128               emit_move_insn (tmpreg[i], srcmem);
16129             }
16130           for (i = 0; i < unroll; i++)
16131             {
16132               if (i)
16133                 {
16134                   destmem =
16135                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16136                 }
16137               emit_move_insn (destmem, tmpreg[i]);
16138             }
16139         }
16140     }
16141   else
16142     for (i = 0; i < unroll; i++)
16143       {
16144         if (i)
16145           destmem =
16146             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16147         emit_move_insn (destmem, value);
16148       }
16149
16150   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
16151                              true, OPTAB_LIB_WIDEN);
16152   if (tmp != iter)
16153     emit_move_insn (iter, tmp);
16154
16155   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
16156                            true, top_label);
16157   if (expected_size != -1)
16158     {
16159       expected_size /= GET_MODE_SIZE (mode) * unroll;
16160       if (expected_size == 0)
16161         predict_jump (0);
16162       else if (expected_size > REG_BR_PROB_BASE)
16163         predict_jump (REG_BR_PROB_BASE - 1);
16164       else
16165         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
16166     }
16167   else
16168     predict_jump (REG_BR_PROB_BASE * 80 / 100);
16169   iter = ix86_zero_extend_to_Pmode (iter);
16170   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
16171                              true, OPTAB_LIB_WIDEN);
16172   if (tmp != destptr)
16173     emit_move_insn (destptr, tmp);
16174   if (srcptr)
16175     {
16176       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
16177                                  true, OPTAB_LIB_WIDEN);
16178       if (tmp != srcptr)
16179         emit_move_insn (srcptr, tmp);
16180     }
16181   emit_label (out_label);
16182 }
16183
16184 /* Output "rep; mov" instruction.
16185    Arguments have same meaning as for previous function */
16186 static void
16187 expand_movmem_via_rep_mov (rtx destmem, rtx srcmem,
16188                            rtx destptr, rtx srcptr,
16189                            rtx count,
16190                            enum machine_mode mode)
16191 {
16192   rtx destexp;
16193   rtx srcexp;
16194   rtx countreg;
16195
16196   /* If the size is known, it is shorter to use rep movs.  */
16197   if (mode == QImode && CONST_INT_P (count)
16198       && !(INTVAL (count) & 3))
16199     mode = SImode;
16200
16201   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16202     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16203   if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
16204     srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
16205   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16206   if (mode != QImode)
16207     {
16208       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16209                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16210       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16211       srcexp = gen_rtx_ASHIFT (Pmode, countreg,
16212                                GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16213       srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
16214     }
16215   else
16216     {
16217       destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16218       srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
16219     }
16220   emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
16221                           destexp, srcexp));
16222 }
16223
16224 /* Output "rep; stos" instruction.
16225    Arguments have same meaning as for previous function */
16226 static void
16227 expand_setmem_via_rep_stos (rtx destmem, rtx destptr, rtx value,
16228                             rtx count,
16229                             enum machine_mode mode)
16230 {
16231   rtx destexp;
16232   rtx countreg;
16233
16234   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16235     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16236   value = force_reg (mode, gen_lowpart (mode, value));
16237   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16238   if (mode != QImode)
16239     {
16240       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16241                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16242       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16243     }
16244   else
16245     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16246   emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
16247 }
16248
16249 static void
16250 emit_strmov (rtx destmem, rtx srcmem,
16251              rtx destptr, rtx srcptr, enum machine_mode mode, int offset)
16252 {
16253   rtx src = adjust_automodify_address_nv (srcmem, mode, srcptr, offset);
16254   rtx dest = adjust_automodify_address_nv (destmem, mode, destptr, offset);
16255   emit_insn (gen_strmov (destptr, dest, srcptr, src));
16256 }
16257
16258 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
16259 static void
16260 expand_movmem_epilogue (rtx destmem, rtx srcmem,
16261                         rtx destptr, rtx srcptr, rtx count, int max_size)
16262 {
16263   rtx src, dest;
16264   if (CONST_INT_P (count))
16265     {
16266       HOST_WIDE_INT countval = INTVAL (count);
16267       int offset = 0;
16268
16269       if ((countval & 0x10) && max_size > 16)
16270         {
16271           if (TARGET_64BIT)
16272             {
16273               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16274               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset + 8);
16275             }
16276           else
16277             gcc_unreachable ();
16278           offset += 16;
16279         }
16280       if ((countval & 0x08) && max_size > 8)
16281         {
16282           if (TARGET_64BIT)
16283             emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16284           else
16285             {
16286               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16287               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset + 4);
16288             }
16289           offset += 8;
16290         }
16291       if ((countval & 0x04) && max_size > 4)
16292         {
16293           emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16294           offset += 4;
16295         }
16296       if ((countval & 0x02) && max_size > 2)
16297         {
16298           emit_strmov (destmem, srcmem, destptr, srcptr, HImode, offset);
16299           offset += 2;
16300         }
16301       if ((countval & 0x01) && max_size > 1)
16302         {
16303           emit_strmov (destmem, srcmem, destptr, srcptr, QImode, offset);
16304           offset += 1;
16305         }
16306       return;
16307     }
16308   if (max_size > 8)
16309     {
16310       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
16311                                     count, 1, OPTAB_DIRECT);
16312       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
16313                                      count, QImode, 1, 4);
16314       return;
16315     }
16316
16317   /* When there are stringops, we can cheaply increase dest and src pointers.
16318      Otherwise we save code size by maintaining offset (zero is readily
16319      available from preceding rep operation) and using x86 addressing modes.
16320    */
16321   if (TARGET_SINGLE_STRINGOP)
16322     {
16323       if (max_size > 4)
16324         {
16325           rtx label = ix86_expand_aligntest (count, 4, true);
16326           src = change_address (srcmem, SImode, srcptr);
16327           dest = change_address (destmem, SImode, destptr);
16328           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16329           emit_label (label);
16330           LABEL_NUSES (label) = 1;
16331         }
16332       if (max_size > 2)
16333         {
16334           rtx label = ix86_expand_aligntest (count, 2, true);
16335           src = change_address (srcmem, HImode, srcptr);
16336           dest = change_address (destmem, HImode, destptr);
16337           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16338           emit_label (label);
16339           LABEL_NUSES (label) = 1;
16340         }
16341       if (max_size > 1)
16342         {
16343           rtx label = ix86_expand_aligntest (count, 1, true);
16344           src = change_address (srcmem, QImode, srcptr);
16345           dest = change_address (destmem, QImode, destptr);
16346           emit_insn (gen_strmov (destptr, dest, srcptr, src));
16347           emit_label (label);
16348           LABEL_NUSES (label) = 1;
16349         }
16350     }
16351   else
16352     {
16353       rtx offset = force_reg (Pmode, const0_rtx);
16354       rtx tmp;
16355
16356       if (max_size > 4)
16357         {
16358           rtx label = ix86_expand_aligntest (count, 4, true);
16359           src = change_address (srcmem, SImode, srcptr);
16360           dest = change_address (destmem, SImode, destptr);
16361           emit_move_insn (dest, src);
16362           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
16363                                      true, OPTAB_LIB_WIDEN);
16364           if (tmp != offset)
16365             emit_move_insn (offset, tmp);
16366           emit_label (label);
16367           LABEL_NUSES (label) = 1;
16368         }
16369       if (max_size > 2)
16370         {
16371           rtx label = ix86_expand_aligntest (count, 2, true);
16372           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
16373           src = change_address (srcmem, HImode, tmp);
16374           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
16375           dest = change_address (destmem, HImode, tmp);
16376           emit_move_insn (dest, src);
16377           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
16378                                      true, OPTAB_LIB_WIDEN);
16379           if (tmp != offset)
16380             emit_move_insn (offset, tmp);
16381           emit_label (label);
16382           LABEL_NUSES (label) = 1;
16383         }
16384       if (max_size > 1)
16385         {
16386           rtx label = ix86_expand_aligntest (count, 1, true);
16387           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
16388           src = change_address (srcmem, QImode, tmp);
16389           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
16390           dest = change_address (destmem, QImode, tmp);
16391           emit_move_insn (dest, src);
16392           emit_label (label);
16393           LABEL_NUSES (label) = 1;
16394         }
16395     }
16396 }
16397
16398 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
16399 static void
16400 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
16401                                  rtx count, int max_size)
16402 {
16403   count =
16404     expand_simple_binop (counter_mode (count), AND, count,
16405                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
16406   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
16407                                  gen_lowpart (QImode, value), count, QImode,
16408                                  1, max_size / 2);
16409 }
16410
16411 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
16412 static void
16413 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx count, int max_size)
16414 {
16415   rtx dest;
16416
16417   if (CONST_INT_P (count))
16418     {
16419       HOST_WIDE_INT countval = INTVAL (count);
16420       int offset = 0;
16421
16422       if ((countval & 0x10) && max_size > 16)
16423         {
16424           if (TARGET_64BIT)
16425             {
16426               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
16427               emit_insn (gen_strset (destptr, dest, value));
16428               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset + 8);
16429               emit_insn (gen_strset (destptr, dest, value));
16430             }
16431           else
16432             gcc_unreachable ();
16433           offset += 16;
16434         }
16435       if ((countval & 0x08) && max_size > 8)
16436         {
16437           if (TARGET_64BIT)
16438             {
16439               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
16440               emit_insn (gen_strset (destptr, dest, value));
16441             }
16442           else
16443             {
16444               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
16445               emit_insn (gen_strset (destptr, dest, value));
16446               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset + 4);
16447               emit_insn (gen_strset (destptr, dest, value));
16448             }
16449           offset += 8;
16450         }
16451       if ((countval & 0x04) && max_size > 4)
16452         {
16453           dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
16454           emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
16455           offset += 4;
16456         }
16457       if ((countval & 0x02) && max_size > 2)
16458         {
16459           dest = adjust_automodify_address_nv (destmem, HImode, destptr, offset);
16460           emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
16461           offset += 2;
16462         }
16463       if ((countval & 0x01) && max_size > 1)
16464         {
16465           dest = adjust_automodify_address_nv (destmem, QImode, destptr, offset);
16466           emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
16467           offset += 1;
16468         }
16469       return;
16470     }
16471   if (max_size > 32)
16472     {
16473       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
16474       return;
16475     }
16476   if (max_size > 16)
16477     {
16478       rtx label = ix86_expand_aligntest (count, 16, true);
16479       if (TARGET_64BIT)
16480         {
16481           dest = change_address (destmem, DImode, destptr);
16482           emit_insn (gen_strset (destptr, dest, value));
16483           emit_insn (gen_strset (destptr, dest, value));
16484         }
16485       else
16486         {
16487           dest = change_address (destmem, SImode, destptr);
16488           emit_insn (gen_strset (destptr, dest, value));
16489           emit_insn (gen_strset (destptr, dest, value));
16490           emit_insn (gen_strset (destptr, dest, value));
16491           emit_insn (gen_strset (destptr, dest, value));
16492         }
16493       emit_label (label);
16494       LABEL_NUSES (label) = 1;
16495     }
16496   if (max_size > 8)
16497     {
16498       rtx label = ix86_expand_aligntest (count, 8, true);
16499       if (TARGET_64BIT)
16500         {
16501           dest = change_address (destmem, DImode, destptr);
16502           emit_insn (gen_strset (destptr, dest, value));
16503         }
16504       else
16505         {
16506           dest = change_address (destmem, SImode, destptr);
16507           emit_insn (gen_strset (destptr, dest, value));
16508           emit_insn (gen_strset (destptr, dest, value));
16509         }
16510       emit_label (label);
16511       LABEL_NUSES (label) = 1;
16512     }
16513   if (max_size > 4)
16514     {
16515       rtx label = ix86_expand_aligntest (count, 4, true);
16516       dest = change_address (destmem, SImode, destptr);
16517       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
16518       emit_label (label);
16519       LABEL_NUSES (label) = 1;
16520     }
16521   if (max_size > 2)
16522     {
16523       rtx label = ix86_expand_aligntest (count, 2, true);
16524       dest = change_address (destmem, HImode, destptr);
16525       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
16526       emit_label (label);
16527       LABEL_NUSES (label) = 1;
16528     }
16529   if (max_size > 1)
16530     {
16531       rtx label = ix86_expand_aligntest (count, 1, true);
16532       dest = change_address (destmem, QImode, destptr);
16533       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
16534       emit_label (label);
16535       LABEL_NUSES (label) = 1;
16536     }
16537 }
16538
16539 /* Copy enough from DEST to SRC to align DEST known to by aligned by ALIGN to
16540    DESIRED_ALIGNMENT.  */
16541 static void
16542 expand_movmem_prologue (rtx destmem, rtx srcmem,
16543                         rtx destptr, rtx srcptr, rtx count,
16544                         int align, int desired_alignment)
16545 {
16546   if (align <= 1 && desired_alignment > 1)
16547     {
16548       rtx label = ix86_expand_aligntest (destptr, 1, false);
16549       srcmem = change_address (srcmem, QImode, srcptr);
16550       destmem = change_address (destmem, QImode, destptr);
16551       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16552       ix86_adjust_counter (count, 1);
16553       emit_label (label);
16554       LABEL_NUSES (label) = 1;
16555     }
16556   if (align <= 2 && desired_alignment > 2)
16557     {
16558       rtx label = ix86_expand_aligntest (destptr, 2, false);
16559       srcmem = change_address (srcmem, HImode, srcptr);
16560       destmem = change_address (destmem, HImode, destptr);
16561       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16562       ix86_adjust_counter (count, 2);
16563       emit_label (label);
16564       LABEL_NUSES (label) = 1;
16565     }
16566   if (align <= 4 && desired_alignment > 4)
16567     {
16568       rtx label = ix86_expand_aligntest (destptr, 4, false);
16569       srcmem = change_address (srcmem, SImode, srcptr);
16570       destmem = change_address (destmem, SImode, destptr);
16571       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
16572       ix86_adjust_counter (count, 4);
16573       emit_label (label);
16574       LABEL_NUSES (label) = 1;
16575     }
16576   gcc_assert (desired_alignment <= 8);
16577 }
16578
16579 /* Set enough from DEST to align DEST known to by aligned by ALIGN to
16580    DESIRED_ALIGNMENT.  */
16581 static void
16582 expand_setmem_prologue (rtx destmem, rtx destptr, rtx value, rtx count,
16583                         int align, int desired_alignment)
16584 {
16585   if (align <= 1 && desired_alignment > 1)
16586     {
16587       rtx label = ix86_expand_aligntest (destptr, 1, false);
16588       destmem = change_address (destmem, QImode, destptr);
16589       emit_insn (gen_strset (destptr, destmem, gen_lowpart (QImode, value)));
16590       ix86_adjust_counter (count, 1);
16591       emit_label (label);
16592       LABEL_NUSES (label) = 1;
16593     }
16594   if (align <= 2 && desired_alignment > 2)
16595     {
16596       rtx label = ix86_expand_aligntest (destptr, 2, false);
16597       destmem = change_address (destmem, HImode, destptr);
16598       emit_insn (gen_strset (destptr, destmem, gen_lowpart (HImode, value)));
16599       ix86_adjust_counter (count, 2);
16600       emit_label (label);
16601       LABEL_NUSES (label) = 1;
16602     }
16603   if (align <= 4 && desired_alignment > 4)
16604     {
16605       rtx label = ix86_expand_aligntest (destptr, 4, false);
16606       destmem = change_address (destmem, SImode, destptr);
16607       emit_insn (gen_strset (destptr, destmem, gen_lowpart (SImode, value)));
16608       ix86_adjust_counter (count, 4);
16609       emit_label (label);
16610       LABEL_NUSES (label) = 1;
16611     }
16612   gcc_assert (desired_alignment <= 8);
16613 }
16614
16615 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
16616 static enum stringop_alg
16617 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, bool memset,
16618             int *dynamic_check)
16619 {
16620   const struct stringop_algs * algs;
16621   /* Algorithms using the rep prefix want at least edi and ecx;
16622      additionally, memset wants eax and memcpy wants esi.  Don't
16623      consider such algorithms if the user has appropriated those
16624      registers for their own purposes.  */
16625   bool rep_prefix_usable = !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
16626                              || (memset
16627                                  ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
16628
16629 #define ALG_USABLE_P(alg) (rep_prefix_usable                    \
16630                            || (alg != rep_prefix_1_byte         \
16631                                && alg != rep_prefix_4_byte      \
16632                                && alg != rep_prefix_8_byte))
16633   const struct processor_costs *cost;
16634   
16635   cost = optimize_insn_for_size_p () ? &size_cost : ix86_cost;
16636
16637   *dynamic_check = -1;
16638   if (memset)
16639     algs = &cost->memset[TARGET_64BIT != 0];
16640   else
16641     algs = &cost->memcpy[TARGET_64BIT != 0];
16642   if (stringop_alg != no_stringop && ALG_USABLE_P (stringop_alg))
16643     return stringop_alg;
16644   /* rep; movq or rep; movl is the smallest variant.  */
16645   else if (optimize_insn_for_size_p ())
16646     {
16647       if (!count || (count & 3))
16648         return rep_prefix_usable ? rep_prefix_1_byte : loop_1_byte;
16649       else
16650         return rep_prefix_usable ? rep_prefix_4_byte : loop;
16651     }
16652   /* Very tiny blocks are best handled via the loop, REP is expensive to setup.
16653    */
16654   else if (expected_size != -1 && expected_size < 4)
16655     return loop_1_byte;
16656   else if (expected_size != -1)
16657     {
16658       unsigned int i;
16659       enum stringop_alg alg = libcall;
16660       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
16661         {
16662           /* We get here if the algorithms that were not libcall-based
16663              were rep-prefix based and we are unable to use rep prefixes
16664              based on global register usage.  Break out of the loop and
16665              use the heuristic below.  */
16666           if (algs->size[i].max == 0)
16667             break;
16668           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
16669             {
16670               enum stringop_alg candidate = algs->size[i].alg;
16671
16672               if (candidate != libcall && ALG_USABLE_P (candidate))
16673                 alg = candidate;
16674               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
16675                  last non-libcall inline algorithm.  */
16676               if (TARGET_INLINE_ALL_STRINGOPS)
16677                 {
16678                   /* When the current size is best to be copied by a libcall,
16679                      but we are still forced to inline, run the heuristic below
16680                      that will pick code for medium sized blocks.  */
16681                   if (alg != libcall)
16682                     return alg;
16683                   break;
16684                 }
16685               else if (ALG_USABLE_P (candidate))
16686                 return candidate;
16687             }
16688         }
16689       gcc_assert (TARGET_INLINE_ALL_STRINGOPS || !rep_prefix_usable);
16690     }
16691   /* When asked to inline the call anyway, try to pick meaningful choice.
16692      We look for maximal size of block that is faster to copy by hand and
16693      take blocks of at most of that size guessing that average size will
16694      be roughly half of the block.
16695
16696      If this turns out to be bad, we might simply specify the preferred
16697      choice in ix86_costs.  */
16698   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
16699       && (algs->unknown_size == libcall || !ALG_USABLE_P (algs->unknown_size)))
16700     {
16701       int max = -1;
16702       enum stringop_alg alg;
16703       int i;
16704       bool any_alg_usable_p = true;
16705
16706       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
16707         {
16708           enum stringop_alg candidate = algs->size[i].alg;
16709           any_alg_usable_p = any_alg_usable_p && ALG_USABLE_P (candidate);
16710
16711           if (candidate != libcall && candidate
16712               && ALG_USABLE_P (candidate))
16713               max = algs->size[i].max;
16714         }
16715       /* If there aren't any usable algorithms, then recursing on
16716          smaller sizes isn't going to find anything.  Just return the
16717          simple byte-at-a-time copy loop.  */
16718       if (!any_alg_usable_p)
16719         {
16720           /* Pick something reasonable.  */
16721           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
16722             *dynamic_check = 128;
16723           return loop_1_byte;
16724         }
16725       if (max == -1)
16726         max = 4096;
16727       alg = decide_alg (count, max / 2, memset, dynamic_check);
16728       gcc_assert (*dynamic_check == -1);
16729       gcc_assert (alg != libcall);
16730       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
16731         *dynamic_check = max;
16732       return alg;
16733     }
16734   return ALG_USABLE_P (algs->unknown_size) ? algs->unknown_size : libcall;
16735 #undef ALG_USABLE_P
16736 }
16737
16738 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
16739    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
16740 static int
16741 decide_alignment (int align,
16742                   enum stringop_alg alg,
16743                   int expected_size)
16744 {
16745   int desired_align = 0;
16746   switch (alg)
16747     {
16748       case no_stringop:
16749         gcc_unreachable ();
16750       case loop:
16751       case unrolled_loop:
16752         desired_align = GET_MODE_SIZE (Pmode);
16753         break;
16754       case rep_prefix_8_byte:
16755         desired_align = 8;
16756         break;
16757       case rep_prefix_4_byte:
16758         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
16759            copying whole cacheline at once.  */
16760         if (TARGET_PENTIUMPRO)
16761           desired_align = 8;
16762         else
16763           desired_align = 4;
16764         break;
16765       case rep_prefix_1_byte:
16766         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
16767            copying whole cacheline at once.  */
16768         if (TARGET_PENTIUMPRO)
16769           desired_align = 8;
16770         else
16771           desired_align = 1;
16772         break;
16773       case loop_1_byte:
16774         desired_align = 1;
16775         break;
16776       case libcall:
16777         return 0;
16778     }
16779
16780   if (optimize_size)
16781     desired_align = 1;
16782   if (desired_align < align)
16783     desired_align = align;
16784   if (expected_size != -1 && expected_size < 4)
16785     desired_align = align;
16786   return desired_align;
16787 }
16788
16789 /* Return the smallest power of 2 greater than VAL.  */
16790 static int
16791 smallest_pow2_greater_than (int val)
16792 {
16793   int ret = 1;
16794   while (ret <= val)
16795     ret <<= 1;
16796   return ret;
16797 }
16798
16799 /* Expand string move (memcpy) operation.  Use i386 string operations when
16800    profitable.  expand_setmem contains similar code.  The code depends upon
16801    architecture, block size and alignment, but always has the same
16802    overall structure:
16803
16804    1) Prologue guard: Conditional that jumps up to epilogues for small
16805       blocks that can be handled by epilogue alone.  This is faster but
16806       also needed for correctness, since prologue assume the block is larger
16807       than the desired alignment.
16808
16809       Optional dynamic check for size and libcall for large
16810       blocks is emitted here too, with -minline-stringops-dynamically.
16811
16812    2) Prologue: copy first few bytes in order to get destination aligned
16813       to DESIRED_ALIGN.  It is emitted only when ALIGN is less than
16814       DESIRED_ALIGN and and up to DESIRED_ALIGN - ALIGN bytes can be copied.
16815       We emit either a jump tree on power of two sized blocks, or a byte loop.
16816
16817    3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
16818       with specified algorithm.
16819
16820    4) Epilogue: code copying tail of the block that is too small to be
16821       handled by main body (or up to size guarded by prologue guard).  */
16822
16823 int
16824 ix86_expand_movmem (rtx dst, rtx src, rtx count_exp, rtx align_exp,
16825                     rtx expected_align_exp, rtx expected_size_exp)
16826 {
16827   rtx destreg;
16828   rtx srcreg;
16829   rtx label = NULL;
16830   rtx tmp;
16831   rtx jump_around_label = NULL;
16832   HOST_WIDE_INT align = 1;
16833   unsigned HOST_WIDE_INT count = 0;
16834   HOST_WIDE_INT expected_size = -1;
16835   int size_needed = 0, epilogue_size_needed;
16836   int desired_align = 0;
16837   enum stringop_alg alg;
16838   int dynamic_check;
16839
16840   if (CONST_INT_P (align_exp))
16841     align = INTVAL (align_exp);
16842   /* i386 can do misaligned access on reasonably increased cost.  */
16843   if (CONST_INT_P (expected_align_exp)
16844       && INTVAL (expected_align_exp) > align)
16845     align = INTVAL (expected_align_exp);
16846   if (CONST_INT_P (count_exp))
16847     count = expected_size = INTVAL (count_exp);
16848   if (CONST_INT_P (expected_size_exp) && count == 0)
16849     expected_size = INTVAL (expected_size_exp);
16850
16851   /* Make sure we don't need to care about overflow later on.  */
16852   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
16853     return 0;
16854
16855   /* Step 0: Decide on preferred algorithm, desired alignment and
16856      size of chunks to be copied by main loop.  */
16857
16858   alg = decide_alg (count, expected_size, false, &dynamic_check);
16859   desired_align = decide_alignment (align, alg, expected_size);
16860
16861   if (!TARGET_ALIGN_STRINGOPS)
16862     align = desired_align;
16863
16864   if (alg == libcall)
16865     return 0;
16866   gcc_assert (alg != no_stringop);
16867   if (!count)
16868     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
16869   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
16870   srcreg = copy_to_mode_reg (Pmode, XEXP (src, 0));
16871   switch (alg)
16872     {
16873     case libcall:
16874     case no_stringop:
16875       gcc_unreachable ();
16876     case loop:
16877       size_needed = GET_MODE_SIZE (Pmode);
16878       break;
16879     case unrolled_loop:
16880       size_needed = GET_MODE_SIZE (Pmode) * (TARGET_64BIT ? 4 : 2);
16881       break;
16882     case rep_prefix_8_byte:
16883       size_needed = 8;
16884       break;
16885     case rep_prefix_4_byte:
16886       size_needed = 4;
16887       break;
16888     case rep_prefix_1_byte:
16889     case loop_1_byte:
16890       size_needed = 1;
16891       break;
16892     }
16893
16894   epilogue_size_needed = size_needed;
16895
16896   /* Step 1: Prologue guard.  */
16897
16898   /* Alignment code needs count to be in register.  */
16899   if (CONST_INT_P (count_exp) && desired_align > align)
16900     count_exp = force_reg (counter_mode (count_exp), count_exp);
16901   gcc_assert (desired_align >= 1 && align >= 1);
16902
16903   /* Ensure that alignment prologue won't copy past end of block.  */
16904   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
16905     {
16906       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
16907       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
16908          Make sure it is power of 2.  */
16909       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
16910
16911       if (CONST_INT_P (count_exp))
16912         {
16913           if (UINTVAL (count_exp) < (unsigned HOST_WIDE_INT)epilogue_size_needed)
16914             goto epilogue;
16915         }
16916       else
16917         {
16918           label = gen_label_rtx ();
16919           emit_cmp_and_jump_insns (count_exp,
16920                                    GEN_INT (epilogue_size_needed),
16921                                    LTU, 0, counter_mode (count_exp), 1, label);
16922           if (expected_size == -1 || expected_size < epilogue_size_needed)
16923             predict_jump (REG_BR_PROB_BASE * 60 / 100);
16924           else
16925             predict_jump (REG_BR_PROB_BASE * 20 / 100);
16926         }
16927     }
16928
16929   /* Emit code to decide on runtime whether library call or inline should be
16930      used.  */
16931   if (dynamic_check != -1)
16932     {
16933       if (CONST_INT_P (count_exp))
16934         {
16935           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
16936             {
16937               emit_block_move_via_libcall (dst, src, count_exp, false);
16938               count_exp = const0_rtx;
16939               goto epilogue;
16940             }
16941         }
16942       else
16943         {
16944           rtx hot_label = gen_label_rtx ();
16945           jump_around_label = gen_label_rtx ();
16946           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
16947                                    LEU, 0, GET_MODE (count_exp), 1, hot_label);
16948           predict_jump (REG_BR_PROB_BASE * 90 / 100);
16949           emit_block_move_via_libcall (dst, src, count_exp, false);
16950           emit_jump (jump_around_label);
16951           emit_label (hot_label);
16952         }
16953     }
16954
16955   /* Step 2: Alignment prologue.  */
16956
16957   if (desired_align > align)
16958     {
16959       /* Except for the first move in epilogue, we no longer know
16960          constant offset in aliasing info.  It don't seems to worth
16961          the pain to maintain it for the first move, so throw away
16962          the info early.  */
16963       src = change_address (src, BLKmode, srcreg);
16964       dst = change_address (dst, BLKmode, destreg);
16965       expand_movmem_prologue (dst, src, destreg, srcreg, count_exp, align,
16966                               desired_align);
16967     }
16968   if (label && size_needed == 1)
16969     {
16970       emit_label (label);
16971       LABEL_NUSES (label) = 1;
16972       label = NULL;
16973     }
16974
16975   /* Step 3: Main loop.  */
16976
16977   switch (alg)
16978     {
16979     case libcall:
16980     case no_stringop:
16981       gcc_unreachable ();
16982     case loop_1_byte:
16983       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
16984                                      count_exp, QImode, 1, expected_size);
16985       break;
16986     case loop:
16987       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
16988                                      count_exp, Pmode, 1, expected_size);
16989       break;
16990     case unrolled_loop:
16991       /* Unroll only by factor of 2 in 32bit mode, since we don't have enough
16992          registers for 4 temporaries anyway.  */
16993       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
16994                                      count_exp, Pmode, TARGET_64BIT ? 4 : 2,
16995                                      expected_size);
16996       break;
16997     case rep_prefix_8_byte:
16998       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
16999                                  DImode);
17000       break;
17001     case rep_prefix_4_byte:
17002       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17003                                  SImode);
17004       break;
17005     case rep_prefix_1_byte:
17006       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17007                                  QImode);
17008       break;
17009     }
17010   /* Adjust properly the offset of src and dest memory for aliasing.  */
17011   if (CONST_INT_P (count_exp))
17012     {
17013       src = adjust_automodify_address_nv (src, BLKmode, srcreg,
17014                                           (count / size_needed) * size_needed);
17015       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
17016                                           (count / size_needed) * size_needed);
17017     }
17018   else
17019     {
17020       src = change_address (src, BLKmode, srcreg);
17021       dst = change_address (dst, BLKmode, destreg);
17022     }
17023
17024   /* Step 4: Epilogue to copy the remaining bytes.  */
17025  epilogue:
17026   if (label)
17027     {
17028       /* When the main loop is done, COUNT_EXP might hold original count,
17029          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
17030          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
17031          bytes. Compensate if needed.  */
17032
17033       if (size_needed < epilogue_size_needed)
17034         {
17035           tmp =
17036             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
17037                                  GEN_INT (size_needed - 1), count_exp, 1,
17038                                  OPTAB_DIRECT);
17039           if (tmp != count_exp)
17040             emit_move_insn (count_exp, tmp);
17041         }
17042       emit_label (label);
17043       LABEL_NUSES (label) = 1;
17044     }
17045
17046   if (count_exp != const0_rtx && epilogue_size_needed > 1)
17047     expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
17048                             epilogue_size_needed);
17049   if (jump_around_label)
17050     emit_label (jump_around_label);
17051   return 1;
17052 }
17053
17054 /* Helper function for memcpy.  For QImode value 0xXY produce
17055    0xXYXYXYXY of wide specified by MODE.  This is essentially
17056    a * 0x10101010, but we can do slightly better than
17057    synth_mult by unwinding the sequence by hand on CPUs with
17058    slow multiply.  */
17059 static rtx
17060 promote_duplicated_reg (enum machine_mode mode, rtx val)
17061 {
17062   enum machine_mode valmode = GET_MODE (val);
17063   rtx tmp;
17064   int nops = mode == DImode ? 3 : 2;
17065
17066   gcc_assert (mode == SImode || mode == DImode);
17067   if (val == const0_rtx)
17068     return copy_to_mode_reg (mode, const0_rtx);
17069   if (CONST_INT_P (val))
17070     {
17071       HOST_WIDE_INT v = INTVAL (val) & 255;
17072
17073       v |= v << 8;
17074       v |= v << 16;
17075       if (mode == DImode)
17076         v |= (v << 16) << 16;
17077       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
17078     }
17079
17080   if (valmode == VOIDmode)
17081     valmode = QImode;
17082   if (valmode != QImode)
17083     val = gen_lowpart (QImode, val);
17084   if (mode == QImode)
17085     return val;
17086   if (!TARGET_PARTIAL_REG_STALL)
17087     nops--;
17088   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
17089       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
17090       <= (ix86_cost->shift_const + ix86_cost->add) * nops
17091           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
17092     {
17093       rtx reg = convert_modes (mode, QImode, val, true);
17094       tmp = promote_duplicated_reg (mode, const1_rtx);
17095       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
17096                                   OPTAB_DIRECT);
17097     }
17098   else
17099     {
17100       rtx reg = convert_modes (mode, QImode, val, true);
17101
17102       if (!TARGET_PARTIAL_REG_STALL)
17103         if (mode == SImode)
17104           emit_insn (gen_movsi_insv_1 (reg, reg));
17105         else
17106           emit_insn (gen_movdi_insv_1_rex64 (reg, reg));
17107       else
17108         {
17109           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
17110                                      NULL, 1, OPTAB_DIRECT);
17111           reg =
17112             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17113         }
17114       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
17115                                  NULL, 1, OPTAB_DIRECT);
17116       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17117       if (mode == SImode)
17118         return reg;
17119       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
17120                                  NULL, 1, OPTAB_DIRECT);
17121       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
17122       return reg;
17123     }
17124 }
17125
17126 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
17127    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
17128    alignment from ALIGN to DESIRED_ALIGN.  */
17129 static rtx
17130 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align, int align)
17131 {
17132   rtx promoted_val;
17133
17134   if (TARGET_64BIT
17135       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
17136     promoted_val = promote_duplicated_reg (DImode, val);
17137   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
17138     promoted_val = promote_duplicated_reg (SImode, val);
17139   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
17140     promoted_val = promote_duplicated_reg (HImode, val);
17141   else
17142     promoted_val = val;
17143
17144   return promoted_val;
17145 }
17146
17147 /* Expand string clear operation (bzero).  Use i386 string operations when
17148    profitable.  See expand_movmem comment for explanation of individual
17149    steps performed.  */
17150 int
17151 ix86_expand_setmem (rtx dst, rtx count_exp, rtx val_exp, rtx align_exp,
17152                     rtx expected_align_exp, rtx expected_size_exp)
17153 {
17154   rtx destreg;
17155   rtx label = NULL;
17156   rtx tmp;
17157   rtx jump_around_label = NULL;
17158   HOST_WIDE_INT align = 1;
17159   unsigned HOST_WIDE_INT count = 0;
17160   HOST_WIDE_INT expected_size = -1;
17161   int size_needed = 0, epilogue_size_needed;
17162   int desired_align = 0;
17163   enum stringop_alg alg;
17164   rtx promoted_val = NULL;
17165   bool force_loopy_epilogue = false;
17166   int dynamic_check;
17167
17168   if (CONST_INT_P (align_exp))
17169     align = INTVAL (align_exp);
17170   /* i386 can do misaligned access on reasonably increased cost.  */
17171   if (CONST_INT_P (expected_align_exp)
17172       && INTVAL (expected_align_exp) > align)
17173     align = INTVAL (expected_align_exp);
17174   if (CONST_INT_P (count_exp))
17175     count = expected_size = INTVAL (count_exp);
17176   if (CONST_INT_P (expected_size_exp) && count == 0)
17177     expected_size = INTVAL (expected_size_exp);
17178
17179   /* Make sure we don't need to care about overflow later on.  */
17180   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17181     return 0;
17182
17183   /* Step 0: Decide on preferred algorithm, desired alignment and
17184      size of chunks to be copied by main loop.  */
17185
17186   alg = decide_alg (count, expected_size, true, &dynamic_check);
17187   desired_align = decide_alignment (align, alg, expected_size);
17188
17189   if (!TARGET_ALIGN_STRINGOPS)
17190     align = desired_align;
17191
17192   if (alg == libcall)
17193     return 0;
17194   gcc_assert (alg != no_stringop);
17195   if (!count)
17196     count_exp = copy_to_mode_reg (counter_mode (count_exp), count_exp);
17197   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17198   switch (alg)
17199     {
17200     case libcall:
17201     case no_stringop:
17202       gcc_unreachable ();
17203     case loop:
17204       size_needed = GET_MODE_SIZE (Pmode);
17205       break;
17206     case unrolled_loop:
17207       size_needed = GET_MODE_SIZE (Pmode) * 4;
17208       break;
17209     case rep_prefix_8_byte:
17210       size_needed = 8;
17211       break;
17212     case rep_prefix_4_byte:
17213       size_needed = 4;
17214       break;
17215     case rep_prefix_1_byte:
17216     case loop_1_byte:
17217       size_needed = 1;
17218       break;
17219     }
17220   epilogue_size_needed = size_needed;
17221
17222   /* Step 1: Prologue guard.  */
17223
17224   /* Alignment code needs count to be in register.  */
17225   if (CONST_INT_P (count_exp) && desired_align > align)
17226     {
17227       enum machine_mode mode = SImode;
17228       if (TARGET_64BIT && (count & ~0xffffffff))
17229         mode = DImode;
17230       count_exp = force_reg (mode, count_exp);
17231     }
17232   /* Do the cheap promotion to allow better CSE across the
17233      main loop and epilogue (ie one load of the big constant in the
17234      front of all code.  */
17235   if (CONST_INT_P (val_exp))
17236     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
17237                                                    desired_align, align);
17238   /* Ensure that alignment prologue won't copy past end of block.  */
17239   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
17240     {
17241       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
17242       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
17243          Make sure it is power of 2.  */
17244       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
17245
17246       /* To improve performance of small blocks, we jump around the VAL
17247          promoting mode.  This mean that if the promoted VAL is not constant,
17248          we might not use it in the epilogue and have to use byte
17249          loop variant.  */
17250       if (epilogue_size_needed > 2 && !promoted_val)
17251         force_loopy_epilogue = true;
17252       label = gen_label_rtx ();
17253       emit_cmp_and_jump_insns (count_exp,
17254                                GEN_INT (epilogue_size_needed),
17255                                LTU, 0, counter_mode (count_exp), 1, label);
17256       if (GET_CODE (count_exp) == CONST_INT)
17257         ;
17258       else if (expected_size == -1 || expected_size <= epilogue_size_needed)
17259         predict_jump (REG_BR_PROB_BASE * 60 / 100);
17260       else
17261         predict_jump (REG_BR_PROB_BASE * 20 / 100);
17262     }
17263   if (dynamic_check != -1)
17264     {
17265       rtx hot_label = gen_label_rtx ();
17266       jump_around_label = gen_label_rtx ();
17267       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
17268                                LEU, 0, counter_mode (count_exp), 1, hot_label);
17269       predict_jump (REG_BR_PROB_BASE * 90 / 100);
17270       set_storage_via_libcall (dst, count_exp, val_exp, false);
17271       emit_jump (jump_around_label);
17272       emit_label (hot_label);
17273     }
17274
17275   /* Step 2: Alignment prologue.  */
17276
17277   /* Do the expensive promotion once we branched off the small blocks.  */
17278   if (!promoted_val)
17279     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
17280                                                    desired_align, align);
17281   gcc_assert (desired_align >= 1 && align >= 1);
17282
17283   if (desired_align > align)
17284     {
17285       /* Except for the first move in epilogue, we no longer know
17286          constant offset in aliasing info.  It don't seems to worth
17287          the pain to maintain it for the first move, so throw away
17288          the info early.  */
17289       dst = change_address (dst, BLKmode, destreg);
17290       expand_setmem_prologue (dst, destreg, promoted_val, count_exp, align,
17291                               desired_align);
17292     }
17293   if (label && size_needed == 1)
17294     {
17295       emit_label (label);
17296       LABEL_NUSES (label) = 1;
17297       label = NULL;
17298     }
17299
17300   /* Step 3: Main loop.  */
17301
17302   switch (alg)
17303     {
17304     case libcall:
17305     case no_stringop:
17306       gcc_unreachable ();
17307     case loop_1_byte:
17308       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17309                                      count_exp, QImode, 1, expected_size);
17310       break;
17311     case loop:
17312       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17313                                      count_exp, Pmode, 1, expected_size);
17314       break;
17315     case unrolled_loop:
17316       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
17317                                      count_exp, Pmode, 4, expected_size);
17318       break;
17319     case rep_prefix_8_byte:
17320       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17321                                   DImode);
17322       break;
17323     case rep_prefix_4_byte:
17324       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17325                                   SImode);
17326       break;
17327     case rep_prefix_1_byte:
17328       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
17329                                   QImode);
17330       break;
17331     }
17332   /* Adjust properly the offset of src and dest memory for aliasing.  */
17333   if (CONST_INT_P (count_exp))
17334     dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
17335                                         (count / size_needed) * size_needed);
17336   else
17337     dst = change_address (dst, BLKmode, destreg);
17338
17339   /* Step 4: Epilogue to copy the remaining bytes.  */
17340
17341   if (label)
17342     {
17343       /* When the main loop is done, COUNT_EXP might hold original count,
17344          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
17345          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
17346          bytes. Compensate if needed.  */
17347
17348       if (size_needed < desired_align - align)
17349         {
17350           tmp =
17351             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
17352                                  GEN_INT (size_needed - 1), count_exp, 1,
17353                                  OPTAB_DIRECT);
17354           size_needed = desired_align - align + 1;
17355           if (tmp != count_exp)
17356             emit_move_insn (count_exp, tmp);
17357         }
17358       emit_label (label);
17359       LABEL_NUSES (label) = 1;
17360     }
17361   if (count_exp != const0_rtx && epilogue_size_needed > 1)
17362     {
17363       if (force_loopy_epilogue)
17364         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
17365                                          size_needed);
17366       else
17367         expand_setmem_epilogue (dst, destreg, promoted_val, count_exp,
17368                                 size_needed);
17369     }
17370   if (jump_around_label)
17371     emit_label (jump_around_label);
17372   return 1;
17373 }
17374
17375 /* Expand the appropriate insns for doing strlen if not just doing
17376    repnz; scasb
17377
17378    out = result, initialized with the start address
17379    align_rtx = alignment of the address.
17380    scratch = scratch register, initialized with the startaddress when
17381         not aligned, otherwise undefined
17382
17383    This is just the body. It needs the initializations mentioned above and
17384    some address computing at the end.  These things are done in i386.md.  */
17385
17386 static void
17387 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
17388 {
17389   int align;
17390   rtx tmp;
17391   rtx align_2_label = NULL_RTX;
17392   rtx align_3_label = NULL_RTX;
17393   rtx align_4_label = gen_label_rtx ();
17394   rtx end_0_label = gen_label_rtx ();
17395   rtx mem;
17396   rtx tmpreg = gen_reg_rtx (SImode);
17397   rtx scratch = gen_reg_rtx (SImode);
17398   rtx cmp;
17399
17400   align = 0;
17401   if (CONST_INT_P (align_rtx))
17402     align = INTVAL (align_rtx);
17403
17404   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
17405
17406   /* Is there a known alignment and is it less than 4?  */
17407   if (align < 4)
17408     {
17409       rtx scratch1 = gen_reg_rtx (Pmode);
17410       emit_move_insn (scratch1, out);
17411       /* Is there a known alignment and is it not 2? */
17412       if (align != 2)
17413         {
17414           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
17415           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
17416
17417           /* Leave just the 3 lower bits.  */
17418           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
17419                                     NULL_RTX, 0, OPTAB_WIDEN);
17420
17421           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
17422                                    Pmode, 1, align_4_label);
17423           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
17424                                    Pmode, 1, align_2_label);
17425           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
17426                                    Pmode, 1, align_3_label);
17427         }
17428       else
17429         {
17430           /* Since the alignment is 2, we have to check 2 or 0 bytes;
17431              check if is aligned to 4 - byte.  */
17432
17433           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
17434                                     NULL_RTX, 0, OPTAB_WIDEN);
17435
17436           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
17437                                    Pmode, 1, align_4_label);
17438         }
17439
17440       mem = change_address (src, QImode, out);
17441
17442       /* Now compare the bytes.  */
17443
17444       /* Compare the first n unaligned byte on a byte per byte basis.  */
17445       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
17446                                QImode, 1, end_0_label);
17447
17448       /* Increment the address.  */
17449       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17450
17451       /* Not needed with an alignment of 2 */
17452       if (align != 2)
17453         {
17454           emit_label (align_2_label);
17455
17456           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
17457                                    end_0_label);
17458
17459           emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17460
17461           emit_label (align_3_label);
17462         }
17463
17464       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
17465                                end_0_label);
17466
17467       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
17468     }
17469
17470   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
17471      align this loop.  It gives only huge programs, but does not help to
17472      speed up.  */
17473   emit_label (align_4_label);
17474
17475   mem = change_address (src, SImode, out);
17476   emit_move_insn (scratch, mem);
17477   emit_insn ((*ix86_gen_add3) (out, out, GEN_INT (4)));
17478
17479   /* This formula yields a nonzero result iff one of the bytes is zero.
17480      This saves three branches inside loop and many cycles.  */
17481
17482   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
17483   emit_insn (gen_one_cmplsi2 (scratch, scratch));
17484   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
17485   emit_insn (gen_andsi3 (tmpreg, tmpreg,
17486                          gen_int_mode (0x80808080, SImode)));
17487   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
17488                            align_4_label);
17489
17490   if (TARGET_CMOVE)
17491     {
17492        rtx reg = gen_reg_rtx (SImode);
17493        rtx reg2 = gen_reg_rtx (Pmode);
17494        emit_move_insn (reg, tmpreg);
17495        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
17496
17497        /* If zero is not in the first two bytes, move two bytes forward.  */
17498        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
17499        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17500        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
17501        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
17502                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
17503                                                      reg,
17504                                                      tmpreg)));
17505        /* Emit lea manually to avoid clobbering of flags.  */
17506        emit_insn (gen_rtx_SET (SImode, reg2,
17507                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
17508
17509        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17510        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
17511        emit_insn (gen_rtx_SET (VOIDmode, out,
17512                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
17513                                                      reg2,
17514                                                      out)));
17515
17516     }
17517   else
17518     {
17519        rtx end_2_label = gen_label_rtx ();
17520        /* Is zero in the first two bytes? */
17521
17522        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
17523        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
17524        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
17525        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
17526                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
17527                             pc_rtx);
17528        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
17529        JUMP_LABEL (tmp) = end_2_label;
17530
17531        /* Not in the first two.  Move two bytes forward.  */
17532        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
17533        emit_insn ((*ix86_gen_add3) (out, out, const2_rtx));
17534
17535        emit_label (end_2_label);
17536
17537     }
17538
17539   /* Avoid branch in fixing the byte.  */
17540   tmpreg = gen_lowpart (QImode, tmpreg);
17541   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
17542   cmp = gen_rtx_LTU (Pmode, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx);
17543   emit_insn ((*ix86_gen_sub3_carry) (out, out, GEN_INT (3), cmp));
17544
17545   emit_label (end_0_label);
17546 }
17547
17548 /* Expand strlen.  */
17549
17550 int
17551 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
17552 {
17553   rtx addr, scratch1, scratch2, scratch3, scratch4;
17554
17555   /* The generic case of strlen expander is long.  Avoid it's
17556      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
17557
17558   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
17559       && !TARGET_INLINE_ALL_STRINGOPS
17560       && !optimize_insn_for_size_p ()
17561       && (!CONST_INT_P (align) || INTVAL (align) < 4))
17562     return 0;
17563
17564   addr = force_reg (Pmode, XEXP (src, 0));
17565   scratch1 = gen_reg_rtx (Pmode);
17566
17567   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
17568       && !optimize_insn_for_size_p ())
17569     {
17570       /* Well it seems that some optimizer does not combine a call like
17571          foo(strlen(bar), strlen(bar));
17572          when the move and the subtraction is done here.  It does calculate
17573          the length just once when these instructions are done inside of
17574          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
17575          often used and I use one fewer register for the lifetime of
17576          output_strlen_unroll() this is better.  */
17577
17578       emit_move_insn (out, addr);
17579
17580       ix86_expand_strlensi_unroll_1 (out, src, align);
17581
17582       /* strlensi_unroll_1 returns the address of the zero at the end of
17583          the string, like memchr(), so compute the length by subtracting
17584          the start address.  */
17585       emit_insn ((*ix86_gen_sub3) (out, out, addr));
17586     }
17587   else
17588     {
17589       rtx unspec;
17590
17591       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
17592       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
17593         return false;
17594
17595       scratch2 = gen_reg_rtx (Pmode);
17596       scratch3 = gen_reg_rtx (Pmode);
17597       scratch4 = force_reg (Pmode, constm1_rtx);
17598
17599       emit_move_insn (scratch3, addr);
17600       eoschar = force_reg (QImode, eoschar);
17601
17602       src = replace_equiv_address_nv (src, scratch3);
17603
17604       /* If .md starts supporting :P, this can be done in .md.  */
17605       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
17606                                                  scratch4), UNSPEC_SCAS);
17607       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
17608       emit_insn ((*ix86_gen_one_cmpl2) (scratch2, scratch1));
17609       emit_insn ((*ix86_gen_add3) (out, scratch2, constm1_rtx));
17610     }
17611   return 1;
17612 }
17613
17614 /* For given symbol (function) construct code to compute address of it's PLT
17615    entry in large x86-64 PIC model.  */
17616 rtx
17617 construct_plt_address (rtx symbol)
17618 {
17619   rtx tmp = gen_reg_rtx (Pmode);
17620   rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
17621
17622   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
17623   gcc_assert (ix86_cmodel == CM_LARGE_PIC);
17624
17625   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
17626   emit_insn (gen_adddi3 (tmp, tmp, pic_offset_table_rtx));
17627   return tmp;
17628 }
17629
17630 void
17631 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
17632                   rtx callarg2 ATTRIBUTE_UNUSED,
17633                   rtx pop, int sibcall)
17634 {
17635   rtx use = NULL, call;
17636
17637   if (pop == const0_rtx)
17638     pop = NULL;
17639   gcc_assert (!TARGET_64BIT || !pop);
17640
17641   if (TARGET_MACHO && !TARGET_64BIT)
17642     {
17643 #if TARGET_MACHO
17644       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
17645         fnaddr = machopic_indirect_call_target (fnaddr);
17646 #endif
17647     }
17648   else
17649     {
17650       /* Static functions and indirect calls don't need the pic register.  */
17651       if (flag_pic && (!TARGET_64BIT || ix86_cmodel == CM_LARGE_PIC)
17652           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
17653           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
17654         use_reg (&use, pic_offset_table_rtx);
17655     }
17656
17657   if (TARGET_64BIT && INTVAL (callarg2) >= 0)
17658     {
17659       rtx al = gen_rtx_REG (QImode, AX_REG);
17660       emit_move_insn (al, callarg2);
17661       use_reg (&use, al);
17662     }
17663
17664   if (ix86_cmodel == CM_LARGE_PIC
17665       && GET_CODE (fnaddr) == MEM
17666       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
17667       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
17668     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
17669   else if (! call_insn_operand (XEXP (fnaddr, 0), Pmode))
17670     {
17671       fnaddr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
17672       fnaddr = gen_rtx_MEM (QImode, fnaddr);
17673     }
17674   if (sibcall && TARGET_64BIT
17675       && !constant_call_address_operand (XEXP (fnaddr, 0), Pmode))
17676     {
17677       rtx addr;
17678       addr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
17679       fnaddr = gen_rtx_REG (Pmode, R11_REG);
17680       emit_move_insn (fnaddr, addr);
17681       fnaddr = gen_rtx_MEM (QImode, fnaddr);
17682     }
17683
17684   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
17685   if (retval)
17686     call = gen_rtx_SET (VOIDmode, retval, call);
17687   if (pop)
17688     {
17689       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
17690       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
17691       call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop));
17692     }
17693
17694   call = emit_call_insn (call);
17695   if (use)
17696     CALL_INSN_FUNCTION_USAGE (call) = use;
17697 }
17698
17699 \f
17700 /* Clear stack slot assignments remembered from previous functions.
17701    This is called from INIT_EXPANDERS once before RTL is emitted for each
17702    function.  */
17703
17704 static struct machine_function *
17705 ix86_init_machine_status (void)
17706 {
17707   struct machine_function *f;
17708
17709   f = GGC_CNEW (struct machine_function);
17710   f->use_fast_prologue_epilogue_nregs = -1;
17711   f->tls_descriptor_call_expanded_p = 0;
17712   f->call_abi = DEFAULT_ABI;
17713
17714   return f;
17715 }
17716
17717 /* Return a MEM corresponding to a stack slot with mode MODE.
17718    Allocate a new slot if necessary.
17719
17720    The RTL for a function can have several slots available: N is
17721    which slot to use.  */
17722
17723 rtx
17724 assign_386_stack_local (enum machine_mode mode, enum ix86_stack_slot n)
17725 {
17726   struct stack_local_entry *s;
17727
17728   gcc_assert (n < MAX_386_STACK_LOCALS);
17729
17730   /* Virtual slot is valid only before vregs are instantiated.  */
17731   gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
17732
17733   for (s = ix86_stack_locals; s; s = s->next)
17734     if (s->mode == mode && s->n == n)
17735       return copy_rtx (s->rtl);
17736
17737   s = (struct stack_local_entry *)
17738     ggc_alloc (sizeof (struct stack_local_entry));
17739   s->n = n;
17740   s->mode = mode;
17741   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
17742
17743   s->next = ix86_stack_locals;
17744   ix86_stack_locals = s;
17745   return s->rtl;
17746 }
17747
17748 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
17749
17750 static GTY(()) rtx ix86_tls_symbol;
17751 rtx
17752 ix86_tls_get_addr (void)
17753 {
17754
17755   if (!ix86_tls_symbol)
17756     {
17757       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode,
17758                                             (TARGET_ANY_GNU_TLS
17759                                              && !TARGET_64BIT)
17760                                             ? "___tls_get_addr"
17761                                             : "__tls_get_addr");
17762     }
17763
17764   return ix86_tls_symbol;
17765 }
17766
17767 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
17768
17769 static GTY(()) rtx ix86_tls_module_base_symbol;
17770 rtx
17771 ix86_tls_module_base (void)
17772 {
17773
17774   if (!ix86_tls_module_base_symbol)
17775     {
17776       ix86_tls_module_base_symbol = gen_rtx_SYMBOL_REF (Pmode,
17777                                                         "_TLS_MODULE_BASE_");
17778       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
17779         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
17780     }
17781
17782   return ix86_tls_module_base_symbol;
17783 }
17784 \f
17785 /* Calculate the length of the memory address in the instruction
17786    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
17787
17788 int
17789 memory_address_length (rtx addr)
17790 {
17791   struct ix86_address parts;
17792   rtx base, index, disp;
17793   int len;
17794   int ok;
17795
17796   if (GET_CODE (addr) == PRE_DEC
17797       || GET_CODE (addr) == POST_INC
17798       || GET_CODE (addr) == PRE_MODIFY
17799       || GET_CODE (addr) == POST_MODIFY)
17800     return 0;
17801
17802   ok = ix86_decompose_address (addr, &parts);
17803   gcc_assert (ok);
17804
17805   if (parts.base && GET_CODE (parts.base) == SUBREG)
17806     parts.base = SUBREG_REG (parts.base);
17807   if (parts.index && GET_CODE (parts.index) == SUBREG)
17808     parts.index = SUBREG_REG (parts.index);
17809
17810   base = parts.base;
17811   index = parts.index;
17812   disp = parts.disp;
17813   len = 0;
17814
17815   /* Rule of thumb:
17816        - esp as the base always wants an index,
17817        - ebp as the base always wants a displacement.  */
17818
17819   /* Register Indirect.  */
17820   if (base && !index && !disp)
17821     {
17822       /* esp (for its index) and ebp (for its displacement) need
17823          the two-byte modrm form.  */
17824       if (addr == stack_pointer_rtx
17825           || addr == arg_pointer_rtx
17826           || addr == frame_pointer_rtx
17827           || addr == hard_frame_pointer_rtx)
17828         len = 1;
17829     }
17830
17831   /* Direct Addressing.  */
17832   else if (disp && !base && !index)
17833     len = 4;
17834
17835   else
17836     {
17837       /* Find the length of the displacement constant.  */
17838       if (disp)
17839         {
17840           if (base && satisfies_constraint_K (disp))
17841             len = 1;
17842           else
17843             len = 4;
17844         }
17845       /* ebp always wants a displacement.  */
17846       else if (base == hard_frame_pointer_rtx)
17847         len = 1;
17848
17849       /* An index requires the two-byte modrm form....  */
17850       if (index
17851           /* ...like esp, which always wants an index.  */
17852           || base == stack_pointer_rtx
17853           || base == arg_pointer_rtx
17854           || base == frame_pointer_rtx)
17855         len += 1;
17856     }
17857
17858   return len;
17859 }
17860
17861 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
17862    is set, expect that insn have 8bit immediate alternative.  */
17863 int
17864 ix86_attr_length_immediate_default (rtx insn, int shortform)
17865 {
17866   int len = 0;
17867   int i;
17868   extract_insn_cached (insn);
17869   for (i = recog_data.n_operands - 1; i >= 0; --i)
17870     if (CONSTANT_P (recog_data.operand[i]))
17871       {
17872         gcc_assert (!len);
17873         if (shortform && satisfies_constraint_K (recog_data.operand[i]))
17874           len = 1;
17875         else
17876           {
17877             switch (get_attr_mode (insn))
17878               {
17879                 case MODE_QI:
17880                   len+=1;
17881                   break;
17882                 case MODE_HI:
17883                   len+=2;
17884                   break;
17885                 case MODE_SI:
17886                   len+=4;
17887                   break;
17888                 /* Immediates for DImode instructions are encoded as 32bit sign extended values.  */
17889                 case MODE_DI:
17890                   len+=4;
17891                   break;
17892                 default:
17893                   fatal_insn ("unknown insn mode", insn);
17894               }
17895           }
17896       }
17897   return len;
17898 }
17899 /* Compute default value for "length_address" attribute.  */
17900 int
17901 ix86_attr_length_address_default (rtx insn)
17902 {
17903   int i;
17904
17905   if (get_attr_type (insn) == TYPE_LEA)
17906     {
17907       rtx set = PATTERN (insn);
17908
17909       if (GET_CODE (set) == PARALLEL)
17910         set = XVECEXP (set, 0, 0);
17911
17912       gcc_assert (GET_CODE (set) == SET);
17913
17914       return memory_address_length (SET_SRC (set));
17915     }
17916
17917   extract_insn_cached (insn);
17918   for (i = recog_data.n_operands - 1; i >= 0; --i)
17919     if (MEM_P (recog_data.operand[i]))
17920       {
17921         return memory_address_length (XEXP (recog_data.operand[i], 0));
17922         break;
17923       }
17924   return 0;
17925 }
17926 \f
17927 /* Return the maximum number of instructions a cpu can issue.  */
17928
17929 static int
17930 ix86_issue_rate (void)
17931 {
17932   switch (ix86_tune)
17933     {
17934     case PROCESSOR_PENTIUM:
17935     case PROCESSOR_K6:
17936       return 2;
17937
17938     case PROCESSOR_PENTIUMPRO:
17939     case PROCESSOR_PENTIUM4:
17940     case PROCESSOR_ATHLON:
17941     case PROCESSOR_K8:
17942     case PROCESSOR_AMDFAM10:
17943     case PROCESSOR_NOCONA:
17944     case PROCESSOR_GENERIC32:
17945     case PROCESSOR_GENERIC64:
17946       return 3;
17947
17948     case PROCESSOR_CORE2:
17949       return 4;
17950
17951     default:
17952       return 1;
17953     }
17954 }
17955
17956 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
17957    by DEP_INSN and nothing set by DEP_INSN.  */
17958
17959 static int
17960 ix86_flags_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
17961 {
17962   rtx set, set2;
17963
17964   /* Simplify the test for uninteresting insns.  */
17965   if (insn_type != TYPE_SETCC
17966       && insn_type != TYPE_ICMOV
17967       && insn_type != TYPE_FCMOV
17968       && insn_type != TYPE_IBR)
17969     return 0;
17970
17971   if ((set = single_set (dep_insn)) != 0)
17972     {
17973       set = SET_DEST (set);
17974       set2 = NULL_RTX;
17975     }
17976   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
17977            && XVECLEN (PATTERN (dep_insn), 0) == 2
17978            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
17979            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
17980     {
17981       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
17982       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
17983     }
17984   else
17985     return 0;
17986
17987   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
17988     return 0;
17989
17990   /* This test is true if the dependent insn reads the flags but
17991      not any other potentially set register.  */
17992   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
17993     return 0;
17994
17995   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
17996     return 0;
17997
17998   return 1;
17999 }
18000
18001 /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory
18002    address with operands set by DEP_INSN.  */
18003
18004 static int
18005 ix86_agi_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
18006 {
18007   rtx addr;
18008
18009   if (insn_type == TYPE_LEA
18010       && TARGET_PENTIUM)
18011     {
18012       addr = PATTERN (insn);
18013
18014       if (GET_CODE (addr) == PARALLEL)
18015         addr = XVECEXP (addr, 0, 0);
18016
18017       gcc_assert (GET_CODE (addr) == SET);
18018
18019       addr = SET_SRC (addr);
18020     }
18021   else
18022     {
18023       int i;
18024       extract_insn_cached (insn);
18025       for (i = recog_data.n_operands - 1; i >= 0; --i)
18026         if (MEM_P (recog_data.operand[i]))
18027           {
18028             addr = XEXP (recog_data.operand[i], 0);
18029             goto found;
18030           }
18031       return 0;
18032     found:;
18033     }
18034
18035   return modified_in_p (addr, dep_insn);
18036 }
18037
18038 static int
18039 ix86_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
18040 {
18041   enum attr_type insn_type, dep_insn_type;
18042   enum attr_memory memory;
18043   rtx set, set2;
18044   int dep_insn_code_number;
18045
18046   /* Anti and output dependencies have zero cost on all CPUs.  */
18047   if (REG_NOTE_KIND (link) != 0)
18048     return 0;
18049
18050   dep_insn_code_number = recog_memoized (dep_insn);
18051
18052   /* If we can't recognize the insns, we can't really do anything.  */
18053   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
18054     return cost;
18055
18056   insn_type = get_attr_type (insn);
18057   dep_insn_type = get_attr_type (dep_insn);
18058
18059   switch (ix86_tune)
18060     {
18061     case PROCESSOR_PENTIUM:
18062       /* Address Generation Interlock adds a cycle of latency.  */
18063       if (ix86_agi_dependent (insn, dep_insn, insn_type))
18064         cost += 1;
18065
18066       /* ??? Compares pair with jump/setcc.  */
18067       if (ix86_flags_dependent (insn, dep_insn, insn_type))
18068         cost = 0;
18069
18070       /* Floating point stores require value to be ready one cycle earlier.  */
18071       if (insn_type == TYPE_FMOV
18072           && get_attr_memory (insn) == MEMORY_STORE
18073           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18074         cost += 1;
18075       break;
18076
18077     case PROCESSOR_PENTIUMPRO:
18078       memory = get_attr_memory (insn);
18079
18080       /* INT->FP conversion is expensive.  */
18081       if (get_attr_fp_int_src (dep_insn))
18082         cost += 5;
18083
18084       /* There is one cycle extra latency between an FP op and a store.  */
18085       if (insn_type == TYPE_FMOV
18086           && (set = single_set (dep_insn)) != NULL_RTX
18087           && (set2 = single_set (insn)) != NULL_RTX
18088           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
18089           && MEM_P (SET_DEST (set2)))
18090         cost += 1;
18091
18092       /* Show ability of reorder buffer to hide latency of load by executing
18093          in parallel with previous instruction in case
18094          previous instruction is not needed to compute the address.  */
18095       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18096           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18097         {
18098           /* Claim moves to take one cycle, as core can issue one load
18099              at time and the next load can start cycle later.  */
18100           if (dep_insn_type == TYPE_IMOV
18101               || dep_insn_type == TYPE_FMOV)
18102             cost = 1;
18103           else if (cost > 1)
18104             cost--;
18105         }
18106       break;
18107
18108     case PROCESSOR_K6:
18109       memory = get_attr_memory (insn);
18110
18111       /* The esp dependency is resolved before the instruction is really
18112          finished.  */
18113       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
18114           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
18115         return 1;
18116
18117       /* INT->FP conversion is expensive.  */
18118       if (get_attr_fp_int_src (dep_insn))
18119         cost += 5;
18120
18121       /* Show ability of reorder buffer to hide latency of load by executing
18122          in parallel with previous instruction in case
18123          previous instruction is not needed to compute the address.  */
18124       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18125           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18126         {
18127           /* Claim moves to take one cycle, as core can issue one load
18128              at time and the next load can start cycle later.  */
18129           if (dep_insn_type == TYPE_IMOV
18130               || dep_insn_type == TYPE_FMOV)
18131             cost = 1;
18132           else if (cost > 2)
18133             cost -= 2;
18134           else
18135             cost = 1;
18136         }
18137       break;
18138
18139     case PROCESSOR_ATHLON:
18140     case PROCESSOR_K8:
18141     case PROCESSOR_AMDFAM10:
18142     case PROCESSOR_GENERIC32:
18143     case PROCESSOR_GENERIC64:
18144       memory = get_attr_memory (insn);
18145
18146       /* Show ability of reorder buffer to hide latency of load by executing
18147          in parallel with previous instruction in case
18148          previous instruction is not needed to compute the address.  */
18149       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
18150           && !ix86_agi_dependent (insn, dep_insn, insn_type))
18151         {
18152           enum attr_unit unit = get_attr_unit (insn);
18153           int loadcost = 3;
18154
18155           /* Because of the difference between the length of integer and
18156              floating unit pipeline preparation stages, the memory operands
18157              for floating point are cheaper.
18158
18159              ??? For Athlon it the difference is most probably 2.  */
18160           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
18161             loadcost = 3;
18162           else
18163             loadcost = TARGET_ATHLON ? 2 : 0;
18164
18165           if (cost >= loadcost)
18166             cost -= loadcost;
18167           else
18168             cost = 0;
18169         }
18170
18171     default:
18172       break;
18173     }
18174
18175   return cost;
18176 }
18177
18178 /* How many alternative schedules to try.  This should be as wide as the
18179    scheduling freedom in the DFA, but no wider.  Making this value too
18180    large results extra work for the scheduler.  */
18181
18182 static int
18183 ia32_multipass_dfa_lookahead (void)
18184 {
18185   switch (ix86_tune)
18186     {
18187     case PROCESSOR_PENTIUM:
18188       return 2;
18189
18190     case PROCESSOR_PENTIUMPRO:
18191     case PROCESSOR_K6:
18192       return 1;
18193
18194     default:
18195       return 0;
18196     }
18197 }
18198
18199 \f
18200 /* Compute the alignment given to a constant that is being placed in memory.
18201    EXP is the constant and ALIGN is the alignment that the object would
18202    ordinarily have.
18203    The value of this function is used instead of that alignment to align
18204    the object.  */
18205
18206 int
18207 ix86_constant_alignment (tree exp, int align)
18208 {
18209   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
18210       || TREE_CODE (exp) == INTEGER_CST)
18211     {
18212       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
18213         return 64;
18214       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
18215         return 128;
18216     }
18217   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
18218            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
18219     return BITS_PER_WORD;
18220
18221   return align;
18222 }
18223
18224 /* Compute the alignment for a static variable.
18225    TYPE is the data type, and ALIGN is the alignment that
18226    the object would ordinarily have.  The value of this function is used
18227    instead of that alignment to align the object.  */
18228
18229 int
18230 ix86_data_alignment (tree type, int align)
18231 {
18232   int max_align = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
18233
18234   if (AGGREGATE_TYPE_P (type)
18235       && TYPE_SIZE (type)
18236       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18237       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= (unsigned) max_align
18238           || TREE_INT_CST_HIGH (TYPE_SIZE (type)))
18239       && align < max_align)
18240     align = max_align;
18241
18242   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18243      to 16byte boundary.  */
18244   if (TARGET_64BIT)
18245     {
18246       if (AGGREGATE_TYPE_P (type)
18247            && TYPE_SIZE (type)
18248            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18249            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 128
18250                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
18251         return 128;
18252     }
18253
18254   if (TREE_CODE (type) == ARRAY_TYPE)
18255     {
18256       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18257         return 64;
18258       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18259         return 128;
18260     }
18261   else if (TREE_CODE (type) == COMPLEX_TYPE)
18262     {
18263
18264       if (TYPE_MODE (type) == DCmode && align < 64)
18265         return 64;
18266       if ((TYPE_MODE (type) == XCmode
18267            || TYPE_MODE (type) == TCmode) && align < 128)
18268         return 128;
18269     }
18270   else if ((TREE_CODE (type) == RECORD_TYPE
18271             || TREE_CODE (type) == UNION_TYPE
18272             || TREE_CODE (type) == QUAL_UNION_TYPE)
18273            && TYPE_FIELDS (type))
18274     {
18275       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18276         return 64;
18277       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18278         return 128;
18279     }
18280   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
18281            || TREE_CODE (type) == INTEGER_TYPE)
18282     {
18283       if (TYPE_MODE (type) == DFmode && align < 64)
18284         return 64;
18285       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18286         return 128;
18287     }
18288
18289   return align;
18290 }
18291
18292 /* Compute the alignment for a local variable or a stack slot.  TYPE is
18293    the data type, MODE is the widest mode available and ALIGN is the
18294    alignment that the object would ordinarily have.  The value of this
18295    macro is used instead of that alignment to align the object.  */
18296
18297 unsigned int
18298 ix86_local_alignment (tree type, enum machine_mode mode,
18299                       unsigned int align)
18300 {
18301   /* If TYPE is NULL, we are allocating a stack slot for caller-save
18302      register in MODE.  We will return the largest alignment of XF
18303      and DF.  */
18304   if (!type)
18305     {
18306       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
18307         align = GET_MODE_ALIGNMENT (DFmode);
18308       return align;
18309     }
18310
18311   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18312      to 16byte boundary.  */
18313   if (TARGET_64BIT)
18314     {
18315       if (AGGREGATE_TYPE_P (type)
18316            && TYPE_SIZE (type)
18317            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18318            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16
18319                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
18320         return 128;
18321     }
18322   if (TREE_CODE (type) == ARRAY_TYPE)
18323     {
18324       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18325         return 64;
18326       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18327         return 128;
18328     }
18329   else if (TREE_CODE (type) == COMPLEX_TYPE)
18330     {
18331       if (TYPE_MODE (type) == DCmode && align < 64)
18332         return 64;
18333       if ((TYPE_MODE (type) == XCmode
18334            || TYPE_MODE (type) == TCmode) && align < 128)
18335         return 128;
18336     }
18337   else if ((TREE_CODE (type) == RECORD_TYPE
18338             || TREE_CODE (type) == UNION_TYPE
18339             || TREE_CODE (type) == QUAL_UNION_TYPE)
18340            && TYPE_FIELDS (type))
18341     {
18342       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18343         return 64;
18344       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18345         return 128;
18346     }
18347   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
18348            || TREE_CODE (type) == INTEGER_TYPE)
18349     {
18350
18351       if (TYPE_MODE (type) == DFmode && align < 64)
18352         return 64;
18353       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18354         return 128;
18355     }
18356   return align;
18357 }
18358 \f
18359 /* Emit RTL insns to initialize the variable parts of a trampoline.
18360    FNADDR is an RTX for the address of the function's pure code.
18361    CXT is an RTX for the static chain value for the function.  */
18362 void
18363 x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
18364 {
18365   if (!TARGET_64BIT)
18366     {
18367       /* Compute offset from the end of the jmp to the target function.  */
18368       rtx disp = expand_binop (SImode, sub_optab, fnaddr,
18369                                plus_constant (tramp, 10),
18370                                NULL_RTX, 1, OPTAB_DIRECT);
18371       emit_move_insn (gen_rtx_MEM (QImode, tramp),
18372                       gen_int_mode (0xb9, QImode));
18373       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
18374       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
18375                       gen_int_mode (0xe9, QImode));
18376       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
18377     }
18378   else
18379     {
18380       int offset = 0;
18381       /* Try to load address using shorter movl instead of movabs.
18382          We may want to support movq for kernel mode, but kernel does not use
18383          trampolines at the moment.  */
18384       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
18385         {
18386           fnaddr = copy_to_mode_reg (DImode, fnaddr);
18387           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18388                           gen_int_mode (0xbb41, HImode));
18389           emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
18390                           gen_lowpart (SImode, fnaddr));
18391           offset += 6;
18392         }
18393       else
18394         {
18395           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18396                           gen_int_mode (0xbb49, HImode));
18397           emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
18398                           fnaddr);
18399           offset += 10;
18400         }
18401       /* Load static chain using movabs to r10.  */
18402       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18403                       gen_int_mode (0xba49, HImode));
18404       emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
18405                       cxt);
18406       offset += 10;
18407       /* Jump to the r11 */
18408       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
18409                       gen_int_mode (0xff49, HImode));
18410       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
18411                       gen_int_mode (0xe3, QImode));
18412       offset += 3;
18413       gcc_assert (offset <= TRAMPOLINE_SIZE);
18414     }
18415
18416 #ifdef ENABLE_EXECUTE_STACK
18417   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
18418                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
18419 #endif
18420 }
18421 \f
18422 /* Codes for all the SSE/MMX builtins.  */
18423 enum ix86_builtins
18424 {
18425   IX86_BUILTIN_ADDPS,
18426   IX86_BUILTIN_ADDSS,
18427   IX86_BUILTIN_DIVPS,
18428   IX86_BUILTIN_DIVSS,
18429   IX86_BUILTIN_MULPS,
18430   IX86_BUILTIN_MULSS,
18431   IX86_BUILTIN_SUBPS,
18432   IX86_BUILTIN_SUBSS,
18433
18434   IX86_BUILTIN_CMPEQPS,
18435   IX86_BUILTIN_CMPLTPS,
18436   IX86_BUILTIN_CMPLEPS,
18437   IX86_BUILTIN_CMPGTPS,
18438   IX86_BUILTIN_CMPGEPS,
18439   IX86_BUILTIN_CMPNEQPS,
18440   IX86_BUILTIN_CMPNLTPS,
18441   IX86_BUILTIN_CMPNLEPS,
18442   IX86_BUILTIN_CMPNGTPS,
18443   IX86_BUILTIN_CMPNGEPS,
18444   IX86_BUILTIN_CMPORDPS,
18445   IX86_BUILTIN_CMPUNORDPS,
18446   IX86_BUILTIN_CMPEQSS,
18447   IX86_BUILTIN_CMPLTSS,
18448   IX86_BUILTIN_CMPLESS,
18449   IX86_BUILTIN_CMPNEQSS,
18450   IX86_BUILTIN_CMPNLTSS,
18451   IX86_BUILTIN_CMPNLESS,
18452   IX86_BUILTIN_CMPNGTSS,
18453   IX86_BUILTIN_CMPNGESS,
18454   IX86_BUILTIN_CMPORDSS,
18455   IX86_BUILTIN_CMPUNORDSS,
18456
18457   IX86_BUILTIN_COMIEQSS,
18458   IX86_BUILTIN_COMILTSS,
18459   IX86_BUILTIN_COMILESS,
18460   IX86_BUILTIN_COMIGTSS,
18461   IX86_BUILTIN_COMIGESS,
18462   IX86_BUILTIN_COMINEQSS,
18463   IX86_BUILTIN_UCOMIEQSS,
18464   IX86_BUILTIN_UCOMILTSS,
18465   IX86_BUILTIN_UCOMILESS,
18466   IX86_BUILTIN_UCOMIGTSS,
18467   IX86_BUILTIN_UCOMIGESS,
18468   IX86_BUILTIN_UCOMINEQSS,
18469
18470   IX86_BUILTIN_CVTPI2PS,
18471   IX86_BUILTIN_CVTPS2PI,
18472   IX86_BUILTIN_CVTSI2SS,
18473   IX86_BUILTIN_CVTSI642SS,
18474   IX86_BUILTIN_CVTSS2SI,
18475   IX86_BUILTIN_CVTSS2SI64,
18476   IX86_BUILTIN_CVTTPS2PI,
18477   IX86_BUILTIN_CVTTSS2SI,
18478   IX86_BUILTIN_CVTTSS2SI64,
18479
18480   IX86_BUILTIN_MAXPS,
18481   IX86_BUILTIN_MAXSS,
18482   IX86_BUILTIN_MINPS,
18483   IX86_BUILTIN_MINSS,
18484
18485   IX86_BUILTIN_LOADUPS,
18486   IX86_BUILTIN_STOREUPS,
18487   IX86_BUILTIN_MOVSS,
18488
18489   IX86_BUILTIN_MOVHLPS,
18490   IX86_BUILTIN_MOVLHPS,
18491   IX86_BUILTIN_LOADHPS,
18492   IX86_BUILTIN_LOADLPS,
18493   IX86_BUILTIN_STOREHPS,
18494   IX86_BUILTIN_STORELPS,
18495
18496   IX86_BUILTIN_MASKMOVQ,
18497   IX86_BUILTIN_MOVMSKPS,
18498   IX86_BUILTIN_PMOVMSKB,
18499
18500   IX86_BUILTIN_MOVNTPS,
18501   IX86_BUILTIN_MOVNTQ,
18502
18503   IX86_BUILTIN_LOADDQU,
18504   IX86_BUILTIN_STOREDQU,
18505
18506   IX86_BUILTIN_PACKSSWB,
18507   IX86_BUILTIN_PACKSSDW,
18508   IX86_BUILTIN_PACKUSWB,
18509
18510   IX86_BUILTIN_PADDB,
18511   IX86_BUILTIN_PADDW,
18512   IX86_BUILTIN_PADDD,
18513   IX86_BUILTIN_PADDQ,
18514   IX86_BUILTIN_PADDSB,
18515   IX86_BUILTIN_PADDSW,
18516   IX86_BUILTIN_PADDUSB,
18517   IX86_BUILTIN_PADDUSW,
18518   IX86_BUILTIN_PSUBB,
18519   IX86_BUILTIN_PSUBW,
18520   IX86_BUILTIN_PSUBD,
18521   IX86_BUILTIN_PSUBQ,
18522   IX86_BUILTIN_PSUBSB,
18523   IX86_BUILTIN_PSUBSW,
18524   IX86_BUILTIN_PSUBUSB,
18525   IX86_BUILTIN_PSUBUSW,
18526
18527   IX86_BUILTIN_PAND,
18528   IX86_BUILTIN_PANDN,
18529   IX86_BUILTIN_POR,
18530   IX86_BUILTIN_PXOR,
18531
18532   IX86_BUILTIN_PAVGB,
18533   IX86_BUILTIN_PAVGW,
18534
18535   IX86_BUILTIN_PCMPEQB,
18536   IX86_BUILTIN_PCMPEQW,
18537   IX86_BUILTIN_PCMPEQD,
18538   IX86_BUILTIN_PCMPGTB,
18539   IX86_BUILTIN_PCMPGTW,
18540   IX86_BUILTIN_PCMPGTD,
18541
18542   IX86_BUILTIN_PMADDWD,
18543
18544   IX86_BUILTIN_PMAXSW,
18545   IX86_BUILTIN_PMAXUB,
18546   IX86_BUILTIN_PMINSW,
18547   IX86_BUILTIN_PMINUB,
18548
18549   IX86_BUILTIN_PMULHUW,
18550   IX86_BUILTIN_PMULHW,
18551   IX86_BUILTIN_PMULLW,
18552
18553   IX86_BUILTIN_PSADBW,
18554   IX86_BUILTIN_PSHUFW,
18555
18556   IX86_BUILTIN_PSLLW,
18557   IX86_BUILTIN_PSLLD,
18558   IX86_BUILTIN_PSLLQ,
18559   IX86_BUILTIN_PSRAW,
18560   IX86_BUILTIN_PSRAD,
18561   IX86_BUILTIN_PSRLW,
18562   IX86_BUILTIN_PSRLD,
18563   IX86_BUILTIN_PSRLQ,
18564   IX86_BUILTIN_PSLLWI,
18565   IX86_BUILTIN_PSLLDI,
18566   IX86_BUILTIN_PSLLQI,
18567   IX86_BUILTIN_PSRAWI,
18568   IX86_BUILTIN_PSRADI,
18569   IX86_BUILTIN_PSRLWI,
18570   IX86_BUILTIN_PSRLDI,
18571   IX86_BUILTIN_PSRLQI,
18572
18573   IX86_BUILTIN_PUNPCKHBW,
18574   IX86_BUILTIN_PUNPCKHWD,
18575   IX86_BUILTIN_PUNPCKHDQ,
18576   IX86_BUILTIN_PUNPCKLBW,
18577   IX86_BUILTIN_PUNPCKLWD,
18578   IX86_BUILTIN_PUNPCKLDQ,
18579
18580   IX86_BUILTIN_SHUFPS,
18581
18582   IX86_BUILTIN_RCPPS,
18583   IX86_BUILTIN_RCPSS,
18584   IX86_BUILTIN_RSQRTPS,
18585   IX86_BUILTIN_RSQRTPS_NR,
18586   IX86_BUILTIN_RSQRTSS,
18587   IX86_BUILTIN_RSQRTF,
18588   IX86_BUILTIN_SQRTPS,
18589   IX86_BUILTIN_SQRTPS_NR,
18590   IX86_BUILTIN_SQRTSS,
18591
18592   IX86_BUILTIN_UNPCKHPS,
18593   IX86_BUILTIN_UNPCKLPS,
18594
18595   IX86_BUILTIN_ANDPS,
18596   IX86_BUILTIN_ANDNPS,
18597   IX86_BUILTIN_ORPS,
18598   IX86_BUILTIN_XORPS,
18599
18600   IX86_BUILTIN_EMMS,
18601   IX86_BUILTIN_LDMXCSR,
18602   IX86_BUILTIN_STMXCSR,
18603   IX86_BUILTIN_SFENCE,
18604
18605   /* 3DNow! Original */
18606   IX86_BUILTIN_FEMMS,
18607   IX86_BUILTIN_PAVGUSB,
18608   IX86_BUILTIN_PF2ID,
18609   IX86_BUILTIN_PFACC,
18610   IX86_BUILTIN_PFADD,
18611   IX86_BUILTIN_PFCMPEQ,
18612   IX86_BUILTIN_PFCMPGE,
18613   IX86_BUILTIN_PFCMPGT,
18614   IX86_BUILTIN_PFMAX,
18615   IX86_BUILTIN_PFMIN,
18616   IX86_BUILTIN_PFMUL,
18617   IX86_BUILTIN_PFRCP,
18618   IX86_BUILTIN_PFRCPIT1,
18619   IX86_BUILTIN_PFRCPIT2,
18620   IX86_BUILTIN_PFRSQIT1,
18621   IX86_BUILTIN_PFRSQRT,
18622   IX86_BUILTIN_PFSUB,
18623   IX86_BUILTIN_PFSUBR,
18624   IX86_BUILTIN_PI2FD,
18625   IX86_BUILTIN_PMULHRW,
18626
18627   /* 3DNow! Athlon Extensions */
18628   IX86_BUILTIN_PF2IW,
18629   IX86_BUILTIN_PFNACC,
18630   IX86_BUILTIN_PFPNACC,
18631   IX86_BUILTIN_PI2FW,
18632   IX86_BUILTIN_PSWAPDSI,
18633   IX86_BUILTIN_PSWAPDSF,
18634
18635   /* SSE2 */
18636   IX86_BUILTIN_ADDPD,
18637   IX86_BUILTIN_ADDSD,
18638   IX86_BUILTIN_DIVPD,
18639   IX86_BUILTIN_DIVSD,
18640   IX86_BUILTIN_MULPD,
18641   IX86_BUILTIN_MULSD,
18642   IX86_BUILTIN_SUBPD,
18643   IX86_BUILTIN_SUBSD,
18644
18645   IX86_BUILTIN_CMPEQPD,
18646   IX86_BUILTIN_CMPLTPD,
18647   IX86_BUILTIN_CMPLEPD,
18648   IX86_BUILTIN_CMPGTPD,
18649   IX86_BUILTIN_CMPGEPD,
18650   IX86_BUILTIN_CMPNEQPD,
18651   IX86_BUILTIN_CMPNLTPD,
18652   IX86_BUILTIN_CMPNLEPD,
18653   IX86_BUILTIN_CMPNGTPD,
18654   IX86_BUILTIN_CMPNGEPD,
18655   IX86_BUILTIN_CMPORDPD,
18656   IX86_BUILTIN_CMPUNORDPD,
18657   IX86_BUILTIN_CMPEQSD,
18658   IX86_BUILTIN_CMPLTSD,
18659   IX86_BUILTIN_CMPLESD,
18660   IX86_BUILTIN_CMPNEQSD,
18661   IX86_BUILTIN_CMPNLTSD,
18662   IX86_BUILTIN_CMPNLESD,
18663   IX86_BUILTIN_CMPORDSD,
18664   IX86_BUILTIN_CMPUNORDSD,
18665
18666   IX86_BUILTIN_COMIEQSD,
18667   IX86_BUILTIN_COMILTSD,
18668   IX86_BUILTIN_COMILESD,
18669   IX86_BUILTIN_COMIGTSD,
18670   IX86_BUILTIN_COMIGESD,
18671   IX86_BUILTIN_COMINEQSD,
18672   IX86_BUILTIN_UCOMIEQSD,
18673   IX86_BUILTIN_UCOMILTSD,
18674   IX86_BUILTIN_UCOMILESD,
18675   IX86_BUILTIN_UCOMIGTSD,
18676   IX86_BUILTIN_UCOMIGESD,
18677   IX86_BUILTIN_UCOMINEQSD,
18678
18679   IX86_BUILTIN_MAXPD,
18680   IX86_BUILTIN_MAXSD,
18681   IX86_BUILTIN_MINPD,
18682   IX86_BUILTIN_MINSD,
18683
18684   IX86_BUILTIN_ANDPD,
18685   IX86_BUILTIN_ANDNPD,
18686   IX86_BUILTIN_ORPD,
18687   IX86_BUILTIN_XORPD,
18688
18689   IX86_BUILTIN_SQRTPD,
18690   IX86_BUILTIN_SQRTSD,
18691
18692   IX86_BUILTIN_UNPCKHPD,
18693   IX86_BUILTIN_UNPCKLPD,
18694
18695   IX86_BUILTIN_SHUFPD,
18696
18697   IX86_BUILTIN_LOADUPD,
18698   IX86_BUILTIN_STOREUPD,
18699   IX86_BUILTIN_MOVSD,
18700
18701   IX86_BUILTIN_LOADHPD,
18702   IX86_BUILTIN_LOADLPD,
18703
18704   IX86_BUILTIN_CVTDQ2PD,
18705   IX86_BUILTIN_CVTDQ2PS,
18706
18707   IX86_BUILTIN_CVTPD2DQ,
18708   IX86_BUILTIN_CVTPD2PI,
18709   IX86_BUILTIN_CVTPD2PS,
18710   IX86_BUILTIN_CVTTPD2DQ,
18711   IX86_BUILTIN_CVTTPD2PI,
18712
18713   IX86_BUILTIN_CVTPI2PD,
18714   IX86_BUILTIN_CVTSI2SD,
18715   IX86_BUILTIN_CVTSI642SD,
18716
18717   IX86_BUILTIN_CVTSD2SI,
18718   IX86_BUILTIN_CVTSD2SI64,
18719   IX86_BUILTIN_CVTSD2SS,
18720   IX86_BUILTIN_CVTSS2SD,
18721   IX86_BUILTIN_CVTTSD2SI,
18722   IX86_BUILTIN_CVTTSD2SI64,
18723
18724   IX86_BUILTIN_CVTPS2DQ,
18725   IX86_BUILTIN_CVTPS2PD,
18726   IX86_BUILTIN_CVTTPS2DQ,
18727
18728   IX86_BUILTIN_MOVNTI,
18729   IX86_BUILTIN_MOVNTPD,
18730   IX86_BUILTIN_MOVNTDQ,
18731
18732   /* SSE2 MMX */
18733   IX86_BUILTIN_MASKMOVDQU,
18734   IX86_BUILTIN_MOVMSKPD,
18735   IX86_BUILTIN_PMOVMSKB128,
18736
18737   IX86_BUILTIN_PACKSSWB128,
18738   IX86_BUILTIN_PACKSSDW128,
18739   IX86_BUILTIN_PACKUSWB128,
18740
18741   IX86_BUILTIN_PADDB128,
18742   IX86_BUILTIN_PADDW128,
18743   IX86_BUILTIN_PADDD128,
18744   IX86_BUILTIN_PADDQ128,
18745   IX86_BUILTIN_PADDSB128,
18746   IX86_BUILTIN_PADDSW128,
18747   IX86_BUILTIN_PADDUSB128,
18748   IX86_BUILTIN_PADDUSW128,
18749   IX86_BUILTIN_PSUBB128,
18750   IX86_BUILTIN_PSUBW128,
18751   IX86_BUILTIN_PSUBD128,
18752   IX86_BUILTIN_PSUBQ128,
18753   IX86_BUILTIN_PSUBSB128,
18754   IX86_BUILTIN_PSUBSW128,
18755   IX86_BUILTIN_PSUBUSB128,
18756   IX86_BUILTIN_PSUBUSW128,
18757
18758   IX86_BUILTIN_PAND128,
18759   IX86_BUILTIN_PANDN128,
18760   IX86_BUILTIN_POR128,
18761   IX86_BUILTIN_PXOR128,
18762
18763   IX86_BUILTIN_PAVGB128,
18764   IX86_BUILTIN_PAVGW128,
18765
18766   IX86_BUILTIN_PCMPEQB128,
18767   IX86_BUILTIN_PCMPEQW128,
18768   IX86_BUILTIN_PCMPEQD128,
18769   IX86_BUILTIN_PCMPGTB128,
18770   IX86_BUILTIN_PCMPGTW128,
18771   IX86_BUILTIN_PCMPGTD128,
18772
18773   IX86_BUILTIN_PMADDWD128,
18774
18775   IX86_BUILTIN_PMAXSW128,
18776   IX86_BUILTIN_PMAXUB128,
18777   IX86_BUILTIN_PMINSW128,
18778   IX86_BUILTIN_PMINUB128,
18779
18780   IX86_BUILTIN_PMULUDQ,
18781   IX86_BUILTIN_PMULUDQ128,
18782   IX86_BUILTIN_PMULHUW128,
18783   IX86_BUILTIN_PMULHW128,
18784   IX86_BUILTIN_PMULLW128,
18785
18786   IX86_BUILTIN_PSADBW128,
18787   IX86_BUILTIN_PSHUFHW,
18788   IX86_BUILTIN_PSHUFLW,
18789   IX86_BUILTIN_PSHUFD,
18790
18791   IX86_BUILTIN_PSLLDQI128,
18792   IX86_BUILTIN_PSLLWI128,
18793   IX86_BUILTIN_PSLLDI128,
18794   IX86_BUILTIN_PSLLQI128,
18795   IX86_BUILTIN_PSRAWI128,
18796   IX86_BUILTIN_PSRADI128,
18797   IX86_BUILTIN_PSRLDQI128,
18798   IX86_BUILTIN_PSRLWI128,
18799   IX86_BUILTIN_PSRLDI128,
18800   IX86_BUILTIN_PSRLQI128,
18801
18802   IX86_BUILTIN_PSLLDQ128,
18803   IX86_BUILTIN_PSLLW128,
18804   IX86_BUILTIN_PSLLD128,
18805   IX86_BUILTIN_PSLLQ128,
18806   IX86_BUILTIN_PSRAW128,
18807   IX86_BUILTIN_PSRAD128,
18808   IX86_BUILTIN_PSRLW128,
18809   IX86_BUILTIN_PSRLD128,
18810   IX86_BUILTIN_PSRLQ128,
18811
18812   IX86_BUILTIN_PUNPCKHBW128,
18813   IX86_BUILTIN_PUNPCKHWD128,
18814   IX86_BUILTIN_PUNPCKHDQ128,
18815   IX86_BUILTIN_PUNPCKHQDQ128,
18816   IX86_BUILTIN_PUNPCKLBW128,
18817   IX86_BUILTIN_PUNPCKLWD128,
18818   IX86_BUILTIN_PUNPCKLDQ128,
18819   IX86_BUILTIN_PUNPCKLQDQ128,
18820
18821   IX86_BUILTIN_CLFLUSH,
18822   IX86_BUILTIN_MFENCE,
18823   IX86_BUILTIN_LFENCE,
18824
18825   /* SSE3.  */
18826   IX86_BUILTIN_ADDSUBPS,
18827   IX86_BUILTIN_HADDPS,
18828   IX86_BUILTIN_HSUBPS,
18829   IX86_BUILTIN_MOVSHDUP,
18830   IX86_BUILTIN_MOVSLDUP,
18831   IX86_BUILTIN_ADDSUBPD,
18832   IX86_BUILTIN_HADDPD,
18833   IX86_BUILTIN_HSUBPD,
18834   IX86_BUILTIN_LDDQU,
18835
18836   IX86_BUILTIN_MONITOR,
18837   IX86_BUILTIN_MWAIT,
18838
18839   /* SSSE3.  */
18840   IX86_BUILTIN_PHADDW,
18841   IX86_BUILTIN_PHADDD,
18842   IX86_BUILTIN_PHADDSW,
18843   IX86_BUILTIN_PHSUBW,
18844   IX86_BUILTIN_PHSUBD,
18845   IX86_BUILTIN_PHSUBSW,
18846   IX86_BUILTIN_PMADDUBSW,
18847   IX86_BUILTIN_PMULHRSW,
18848   IX86_BUILTIN_PSHUFB,
18849   IX86_BUILTIN_PSIGNB,
18850   IX86_BUILTIN_PSIGNW,
18851   IX86_BUILTIN_PSIGND,
18852   IX86_BUILTIN_PALIGNR,
18853   IX86_BUILTIN_PABSB,
18854   IX86_BUILTIN_PABSW,
18855   IX86_BUILTIN_PABSD,
18856
18857   IX86_BUILTIN_PHADDW128,
18858   IX86_BUILTIN_PHADDD128,
18859   IX86_BUILTIN_PHADDSW128,
18860   IX86_BUILTIN_PHSUBW128,
18861   IX86_BUILTIN_PHSUBD128,
18862   IX86_BUILTIN_PHSUBSW128,
18863   IX86_BUILTIN_PMADDUBSW128,
18864   IX86_BUILTIN_PMULHRSW128,
18865   IX86_BUILTIN_PSHUFB128,
18866   IX86_BUILTIN_PSIGNB128,
18867   IX86_BUILTIN_PSIGNW128,
18868   IX86_BUILTIN_PSIGND128,
18869   IX86_BUILTIN_PALIGNR128,
18870   IX86_BUILTIN_PABSB128,
18871   IX86_BUILTIN_PABSW128,
18872   IX86_BUILTIN_PABSD128,
18873
18874   /* AMDFAM10 - SSE4A New Instructions.  */
18875   IX86_BUILTIN_MOVNTSD,
18876   IX86_BUILTIN_MOVNTSS,
18877   IX86_BUILTIN_EXTRQI,
18878   IX86_BUILTIN_EXTRQ,
18879   IX86_BUILTIN_INSERTQI,
18880   IX86_BUILTIN_INSERTQ,
18881
18882   /* SSE4.1.  */
18883   IX86_BUILTIN_BLENDPD,
18884   IX86_BUILTIN_BLENDPS,
18885   IX86_BUILTIN_BLENDVPD,
18886   IX86_BUILTIN_BLENDVPS,
18887   IX86_BUILTIN_PBLENDVB128,
18888   IX86_BUILTIN_PBLENDW128,
18889
18890   IX86_BUILTIN_DPPD,
18891   IX86_BUILTIN_DPPS,
18892
18893   IX86_BUILTIN_INSERTPS128,
18894
18895   IX86_BUILTIN_MOVNTDQA,
18896   IX86_BUILTIN_MPSADBW128,
18897   IX86_BUILTIN_PACKUSDW128,
18898   IX86_BUILTIN_PCMPEQQ,
18899   IX86_BUILTIN_PHMINPOSUW128,
18900
18901   IX86_BUILTIN_PMAXSB128,
18902   IX86_BUILTIN_PMAXSD128,
18903   IX86_BUILTIN_PMAXUD128,
18904   IX86_BUILTIN_PMAXUW128,
18905
18906   IX86_BUILTIN_PMINSB128,
18907   IX86_BUILTIN_PMINSD128,
18908   IX86_BUILTIN_PMINUD128,
18909   IX86_BUILTIN_PMINUW128,
18910
18911   IX86_BUILTIN_PMOVSXBW128,
18912   IX86_BUILTIN_PMOVSXBD128,
18913   IX86_BUILTIN_PMOVSXBQ128,
18914   IX86_BUILTIN_PMOVSXWD128,
18915   IX86_BUILTIN_PMOVSXWQ128,
18916   IX86_BUILTIN_PMOVSXDQ128,
18917
18918   IX86_BUILTIN_PMOVZXBW128,
18919   IX86_BUILTIN_PMOVZXBD128,
18920   IX86_BUILTIN_PMOVZXBQ128,
18921   IX86_BUILTIN_PMOVZXWD128,
18922   IX86_BUILTIN_PMOVZXWQ128,
18923   IX86_BUILTIN_PMOVZXDQ128,
18924
18925   IX86_BUILTIN_PMULDQ128,
18926   IX86_BUILTIN_PMULLD128,
18927
18928   IX86_BUILTIN_ROUNDPD,
18929   IX86_BUILTIN_ROUNDPS,
18930   IX86_BUILTIN_ROUNDSD,
18931   IX86_BUILTIN_ROUNDSS,
18932
18933   IX86_BUILTIN_PTESTZ,
18934   IX86_BUILTIN_PTESTC,
18935   IX86_BUILTIN_PTESTNZC,
18936
18937   IX86_BUILTIN_VEC_INIT_V2SI,
18938   IX86_BUILTIN_VEC_INIT_V4HI,
18939   IX86_BUILTIN_VEC_INIT_V8QI,
18940   IX86_BUILTIN_VEC_EXT_V2DF,
18941   IX86_BUILTIN_VEC_EXT_V2DI,
18942   IX86_BUILTIN_VEC_EXT_V4SF,
18943   IX86_BUILTIN_VEC_EXT_V4SI,
18944   IX86_BUILTIN_VEC_EXT_V8HI,
18945   IX86_BUILTIN_VEC_EXT_V2SI,
18946   IX86_BUILTIN_VEC_EXT_V4HI,
18947   IX86_BUILTIN_VEC_EXT_V16QI,
18948   IX86_BUILTIN_VEC_SET_V2DI,
18949   IX86_BUILTIN_VEC_SET_V4SF,
18950   IX86_BUILTIN_VEC_SET_V4SI,
18951   IX86_BUILTIN_VEC_SET_V8HI,
18952   IX86_BUILTIN_VEC_SET_V4HI,
18953   IX86_BUILTIN_VEC_SET_V16QI,
18954
18955   IX86_BUILTIN_VEC_PACK_SFIX,
18956
18957   /* SSE4.2.  */
18958   IX86_BUILTIN_CRC32QI,
18959   IX86_BUILTIN_CRC32HI,
18960   IX86_BUILTIN_CRC32SI,
18961   IX86_BUILTIN_CRC32DI,
18962
18963   IX86_BUILTIN_PCMPESTRI128,
18964   IX86_BUILTIN_PCMPESTRM128,
18965   IX86_BUILTIN_PCMPESTRA128,
18966   IX86_BUILTIN_PCMPESTRC128,
18967   IX86_BUILTIN_PCMPESTRO128,
18968   IX86_BUILTIN_PCMPESTRS128,
18969   IX86_BUILTIN_PCMPESTRZ128,
18970   IX86_BUILTIN_PCMPISTRI128,
18971   IX86_BUILTIN_PCMPISTRM128,
18972   IX86_BUILTIN_PCMPISTRA128,
18973   IX86_BUILTIN_PCMPISTRC128,
18974   IX86_BUILTIN_PCMPISTRO128,
18975   IX86_BUILTIN_PCMPISTRS128,
18976   IX86_BUILTIN_PCMPISTRZ128,
18977
18978   IX86_BUILTIN_PCMPGTQ,
18979
18980   /* AES instructions */
18981   IX86_BUILTIN_AESENC128,
18982   IX86_BUILTIN_AESENCLAST128,
18983   IX86_BUILTIN_AESDEC128,
18984   IX86_BUILTIN_AESDECLAST128,
18985   IX86_BUILTIN_AESIMC128,
18986   IX86_BUILTIN_AESKEYGENASSIST128,
18987
18988   /* PCLMUL instruction */
18989   IX86_BUILTIN_PCLMULQDQ128,
18990
18991   /* TFmode support builtins.  */
18992   IX86_BUILTIN_INFQ,
18993   IX86_BUILTIN_FABSQ,
18994   IX86_BUILTIN_COPYSIGNQ,
18995
18996   /* SSE5 instructions */
18997   IX86_BUILTIN_FMADDSS,
18998   IX86_BUILTIN_FMADDSD,
18999   IX86_BUILTIN_FMADDPS,
19000   IX86_BUILTIN_FMADDPD,
19001   IX86_BUILTIN_FMSUBSS,
19002   IX86_BUILTIN_FMSUBSD,
19003   IX86_BUILTIN_FMSUBPS,
19004   IX86_BUILTIN_FMSUBPD,
19005   IX86_BUILTIN_FNMADDSS,
19006   IX86_BUILTIN_FNMADDSD,
19007   IX86_BUILTIN_FNMADDPS,
19008   IX86_BUILTIN_FNMADDPD,
19009   IX86_BUILTIN_FNMSUBSS,
19010   IX86_BUILTIN_FNMSUBSD,
19011   IX86_BUILTIN_FNMSUBPS,
19012   IX86_BUILTIN_FNMSUBPD,
19013   IX86_BUILTIN_PCMOV_V2DI,
19014   IX86_BUILTIN_PCMOV_V4SI,
19015   IX86_BUILTIN_PCMOV_V8HI,
19016   IX86_BUILTIN_PCMOV_V16QI,
19017   IX86_BUILTIN_PCMOV_V4SF,
19018   IX86_BUILTIN_PCMOV_V2DF,
19019   IX86_BUILTIN_PPERM,
19020   IX86_BUILTIN_PERMPS,
19021   IX86_BUILTIN_PERMPD,
19022   IX86_BUILTIN_PMACSSWW,
19023   IX86_BUILTIN_PMACSWW,
19024   IX86_BUILTIN_PMACSSWD,
19025   IX86_BUILTIN_PMACSWD,
19026   IX86_BUILTIN_PMACSSDD,
19027   IX86_BUILTIN_PMACSDD,
19028   IX86_BUILTIN_PMACSSDQL,
19029   IX86_BUILTIN_PMACSSDQH,
19030   IX86_BUILTIN_PMACSDQL,
19031   IX86_BUILTIN_PMACSDQH,
19032   IX86_BUILTIN_PMADCSSWD,
19033   IX86_BUILTIN_PMADCSWD,
19034   IX86_BUILTIN_PHADDBW,
19035   IX86_BUILTIN_PHADDBD,
19036   IX86_BUILTIN_PHADDBQ,
19037   IX86_BUILTIN_PHADDWD,
19038   IX86_BUILTIN_PHADDWQ,
19039   IX86_BUILTIN_PHADDDQ,
19040   IX86_BUILTIN_PHADDUBW,
19041   IX86_BUILTIN_PHADDUBD,
19042   IX86_BUILTIN_PHADDUBQ,
19043   IX86_BUILTIN_PHADDUWD,
19044   IX86_BUILTIN_PHADDUWQ,
19045   IX86_BUILTIN_PHADDUDQ,
19046   IX86_BUILTIN_PHSUBBW,
19047   IX86_BUILTIN_PHSUBWD,
19048   IX86_BUILTIN_PHSUBDQ,
19049   IX86_BUILTIN_PROTB,
19050   IX86_BUILTIN_PROTW,
19051   IX86_BUILTIN_PROTD,
19052   IX86_BUILTIN_PROTQ,
19053   IX86_BUILTIN_PROTB_IMM,
19054   IX86_BUILTIN_PROTW_IMM,
19055   IX86_BUILTIN_PROTD_IMM,
19056   IX86_BUILTIN_PROTQ_IMM,
19057   IX86_BUILTIN_PSHLB,
19058   IX86_BUILTIN_PSHLW,
19059   IX86_BUILTIN_PSHLD,
19060   IX86_BUILTIN_PSHLQ,
19061   IX86_BUILTIN_PSHAB,
19062   IX86_BUILTIN_PSHAW,
19063   IX86_BUILTIN_PSHAD,
19064   IX86_BUILTIN_PSHAQ,
19065   IX86_BUILTIN_FRCZSS,
19066   IX86_BUILTIN_FRCZSD,
19067   IX86_BUILTIN_FRCZPS,
19068   IX86_BUILTIN_FRCZPD,
19069   IX86_BUILTIN_CVTPH2PS,
19070   IX86_BUILTIN_CVTPS2PH,
19071
19072   IX86_BUILTIN_COMEQSS,
19073   IX86_BUILTIN_COMNESS,
19074   IX86_BUILTIN_COMLTSS,
19075   IX86_BUILTIN_COMLESS,
19076   IX86_BUILTIN_COMGTSS,
19077   IX86_BUILTIN_COMGESS,
19078   IX86_BUILTIN_COMUEQSS,
19079   IX86_BUILTIN_COMUNESS,
19080   IX86_BUILTIN_COMULTSS,
19081   IX86_BUILTIN_COMULESS,
19082   IX86_BUILTIN_COMUGTSS,
19083   IX86_BUILTIN_COMUGESS,
19084   IX86_BUILTIN_COMORDSS,
19085   IX86_BUILTIN_COMUNORDSS,
19086   IX86_BUILTIN_COMFALSESS,
19087   IX86_BUILTIN_COMTRUESS,
19088
19089   IX86_BUILTIN_COMEQSD,
19090   IX86_BUILTIN_COMNESD,
19091   IX86_BUILTIN_COMLTSD,
19092   IX86_BUILTIN_COMLESD,
19093   IX86_BUILTIN_COMGTSD,
19094   IX86_BUILTIN_COMGESD,
19095   IX86_BUILTIN_COMUEQSD,
19096   IX86_BUILTIN_COMUNESD,
19097   IX86_BUILTIN_COMULTSD,
19098   IX86_BUILTIN_COMULESD,
19099   IX86_BUILTIN_COMUGTSD,
19100   IX86_BUILTIN_COMUGESD,
19101   IX86_BUILTIN_COMORDSD,
19102   IX86_BUILTIN_COMUNORDSD,
19103   IX86_BUILTIN_COMFALSESD,
19104   IX86_BUILTIN_COMTRUESD,
19105
19106   IX86_BUILTIN_COMEQPS,
19107   IX86_BUILTIN_COMNEPS,
19108   IX86_BUILTIN_COMLTPS,
19109   IX86_BUILTIN_COMLEPS,
19110   IX86_BUILTIN_COMGTPS,
19111   IX86_BUILTIN_COMGEPS,
19112   IX86_BUILTIN_COMUEQPS,
19113   IX86_BUILTIN_COMUNEPS,
19114   IX86_BUILTIN_COMULTPS,
19115   IX86_BUILTIN_COMULEPS,
19116   IX86_BUILTIN_COMUGTPS,
19117   IX86_BUILTIN_COMUGEPS,
19118   IX86_BUILTIN_COMORDPS,
19119   IX86_BUILTIN_COMUNORDPS,
19120   IX86_BUILTIN_COMFALSEPS,
19121   IX86_BUILTIN_COMTRUEPS,
19122
19123   IX86_BUILTIN_COMEQPD,
19124   IX86_BUILTIN_COMNEPD,
19125   IX86_BUILTIN_COMLTPD,
19126   IX86_BUILTIN_COMLEPD,
19127   IX86_BUILTIN_COMGTPD,
19128   IX86_BUILTIN_COMGEPD,
19129   IX86_BUILTIN_COMUEQPD,
19130   IX86_BUILTIN_COMUNEPD,
19131   IX86_BUILTIN_COMULTPD,
19132   IX86_BUILTIN_COMULEPD,
19133   IX86_BUILTIN_COMUGTPD,
19134   IX86_BUILTIN_COMUGEPD,
19135   IX86_BUILTIN_COMORDPD,
19136   IX86_BUILTIN_COMUNORDPD,
19137   IX86_BUILTIN_COMFALSEPD,
19138   IX86_BUILTIN_COMTRUEPD,
19139
19140   IX86_BUILTIN_PCOMEQUB,
19141   IX86_BUILTIN_PCOMNEUB,
19142   IX86_BUILTIN_PCOMLTUB,
19143   IX86_BUILTIN_PCOMLEUB,
19144   IX86_BUILTIN_PCOMGTUB,
19145   IX86_BUILTIN_PCOMGEUB,
19146   IX86_BUILTIN_PCOMFALSEUB,
19147   IX86_BUILTIN_PCOMTRUEUB,
19148   IX86_BUILTIN_PCOMEQUW,
19149   IX86_BUILTIN_PCOMNEUW,
19150   IX86_BUILTIN_PCOMLTUW,
19151   IX86_BUILTIN_PCOMLEUW,
19152   IX86_BUILTIN_PCOMGTUW,
19153   IX86_BUILTIN_PCOMGEUW,
19154   IX86_BUILTIN_PCOMFALSEUW,
19155   IX86_BUILTIN_PCOMTRUEUW,
19156   IX86_BUILTIN_PCOMEQUD,
19157   IX86_BUILTIN_PCOMNEUD,
19158   IX86_BUILTIN_PCOMLTUD,
19159   IX86_BUILTIN_PCOMLEUD,
19160   IX86_BUILTIN_PCOMGTUD,
19161   IX86_BUILTIN_PCOMGEUD,
19162   IX86_BUILTIN_PCOMFALSEUD,
19163   IX86_BUILTIN_PCOMTRUEUD,
19164   IX86_BUILTIN_PCOMEQUQ,
19165   IX86_BUILTIN_PCOMNEUQ,
19166   IX86_BUILTIN_PCOMLTUQ,
19167   IX86_BUILTIN_PCOMLEUQ,
19168   IX86_BUILTIN_PCOMGTUQ,
19169   IX86_BUILTIN_PCOMGEUQ,
19170   IX86_BUILTIN_PCOMFALSEUQ,
19171   IX86_BUILTIN_PCOMTRUEUQ,
19172
19173   IX86_BUILTIN_PCOMEQB,
19174   IX86_BUILTIN_PCOMNEB,
19175   IX86_BUILTIN_PCOMLTB,
19176   IX86_BUILTIN_PCOMLEB,
19177   IX86_BUILTIN_PCOMGTB,
19178   IX86_BUILTIN_PCOMGEB,
19179   IX86_BUILTIN_PCOMFALSEB,
19180   IX86_BUILTIN_PCOMTRUEB,
19181   IX86_BUILTIN_PCOMEQW,
19182   IX86_BUILTIN_PCOMNEW,
19183   IX86_BUILTIN_PCOMLTW,
19184   IX86_BUILTIN_PCOMLEW,
19185   IX86_BUILTIN_PCOMGTW,
19186   IX86_BUILTIN_PCOMGEW,
19187   IX86_BUILTIN_PCOMFALSEW,
19188   IX86_BUILTIN_PCOMTRUEW,
19189   IX86_BUILTIN_PCOMEQD,
19190   IX86_BUILTIN_PCOMNED,
19191   IX86_BUILTIN_PCOMLTD,
19192   IX86_BUILTIN_PCOMLED,
19193   IX86_BUILTIN_PCOMGTD,
19194   IX86_BUILTIN_PCOMGED,
19195   IX86_BUILTIN_PCOMFALSED,
19196   IX86_BUILTIN_PCOMTRUED,
19197   IX86_BUILTIN_PCOMEQQ,
19198   IX86_BUILTIN_PCOMNEQ,
19199   IX86_BUILTIN_PCOMLTQ,
19200   IX86_BUILTIN_PCOMLEQ,
19201   IX86_BUILTIN_PCOMGTQ,
19202   IX86_BUILTIN_PCOMGEQ,
19203   IX86_BUILTIN_PCOMFALSEQ,
19204   IX86_BUILTIN_PCOMTRUEQ,
19205
19206   IX86_BUILTIN_MAX
19207 };
19208
19209 /* Table for the ix86 builtin decls.  */
19210 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
19211
19212 /* Table to record which ISA options the builtin needs.  */
19213 static int ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
19214
19215 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
19216  * of which isa_flags to use in the ix86_builtins_isa array.  Stores the
19217  * function decl in the ix86_builtins array.  Returns the function decl or
19218  * NULL_TREE, if the builtin was not added.
19219  *
19220  * Record all builtins, even if it isn't an instruction set in the current ISA
19221  * in case the user uses function specific options for a different ISA.  When
19222  * the builtin is expanded, check at that time whether it is valid.  */
19223
19224 static inline tree
19225 def_builtin (int mask, const char *name, tree type, enum ix86_builtins code)
19226 {
19227   tree decl = NULL_TREE;
19228
19229   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
19230     {
19231       decl = add_builtin_function (name, type, code, BUILT_IN_MD,
19232                                    NULL, NULL_TREE);
19233       ix86_builtins[(int) code] = decl;
19234       ix86_builtins_isa[(int) code] = mask;
19235     }
19236
19237   return decl;
19238 }
19239
19240 /* Like def_builtin, but also marks the function decl "const".  */
19241
19242 static inline tree
19243 def_builtin_const (int mask, const char *name, tree type,
19244                    enum ix86_builtins code)
19245 {
19246   tree decl = def_builtin (mask, name, type, code);
19247   if (decl)
19248     TREE_READONLY (decl) = 1;
19249   return decl;
19250 }
19251
19252 /* Bits for builtin_description.flag.  */
19253
19254 /* Set when we don't support the comparison natively, and should
19255    swap_comparison in order to support it.  */
19256 #define BUILTIN_DESC_SWAP_OPERANDS      1
19257
19258 struct builtin_description
19259 {
19260   const unsigned int mask;
19261   const enum insn_code icode;
19262   const char *const name;
19263   const enum ix86_builtins code;
19264   const enum rtx_code comparison;
19265   const int flag;
19266 };
19267
19268 static const struct builtin_description bdesc_comi[] =
19269 {
19270   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
19271   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
19272   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
19273   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
19274   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
19275   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
19276   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
19277   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
19278   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
19279   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
19280   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
19281   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
19282   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
19283   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
19284   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
19285   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
19286   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
19287   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
19288   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
19289   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
19290   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
19291   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
19292   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
19293   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
19294 };
19295
19296 static const struct builtin_description bdesc_pcmpestr[] =
19297 {
19298   /* SSE4.2 */
19299   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
19300   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
19301   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
19302   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
19303   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
19304   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
19305   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
19306 };
19307
19308 static const struct builtin_description bdesc_pcmpistr[] =
19309 {
19310   /* SSE4.2 */
19311   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
19312   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
19313   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
19314   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
19315   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
19316   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
19317   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
19318 };
19319
19320 /* Special builtin types */
19321 enum ix86_special_builtin_type
19322 {
19323   SPECIAL_FTYPE_UNKNOWN,
19324   VOID_FTYPE_VOID,
19325   V16QI_FTYPE_PCCHAR,
19326   V4SF_FTYPE_PCFLOAT,
19327   V2DF_FTYPE_PCDOUBLE,
19328   V4SF_FTYPE_V4SF_PCV2SF,
19329   V2DF_FTYPE_V2DF_PCDOUBLE,
19330   V2DI_FTYPE_PV2DI,
19331   VOID_FTYPE_PV2SF_V4SF,
19332   VOID_FTYPE_PV2DI_V2DI,
19333   VOID_FTYPE_PCHAR_V16QI,
19334   VOID_FTYPE_PFLOAT_V4SF,
19335   VOID_FTYPE_PDOUBLE_V2DF,
19336   VOID_FTYPE_PDI_DI,
19337   VOID_FTYPE_PINT_INT
19338 };
19339
19340 /* Builtin types */
19341 enum ix86_builtin_type
19342 {
19343   FTYPE_UNKNOWN,
19344   FLOAT128_FTYPE_FLOAT128,
19345   FLOAT_FTYPE_FLOAT,
19346   FLOAT128_FTYPE_FLOAT128_FLOAT128,
19347   INT_FTYPE_V2DI_V2DI_PTEST,
19348   INT64_FTYPE_V4SF,
19349   INT64_FTYPE_V2DF,
19350   INT_FTYPE_V16QI,
19351   INT_FTYPE_V8QI,
19352   INT_FTYPE_V4SF,
19353   INT_FTYPE_V2DF,
19354   V16QI_FTYPE_V16QI,
19355   V8HI_FTYPE_V8HI,
19356   V8HI_FTYPE_V16QI,
19357   V8QI_FTYPE_V8QI,
19358   V4SI_FTYPE_V4SI,
19359   V4SI_FTYPE_V16QI,
19360   V4SI_FTYPE_V8HI,
19361   V4SI_FTYPE_V4SF,
19362   V4SI_FTYPE_V2DF,
19363   V4HI_FTYPE_V4HI,
19364   V4SF_FTYPE_V4SF,
19365   V4SF_FTYPE_V4SF_VEC_MERGE,
19366   V4SF_FTYPE_V4SI,
19367   V4SF_FTYPE_V2DF,
19368   V2DI_FTYPE_V2DI,
19369   V2DI_FTYPE_V16QI,
19370   V2DI_FTYPE_V8HI,
19371   V2DI_FTYPE_V4SI,
19372   V2DF_FTYPE_V2DF,
19373   V2DF_FTYPE_V2DF_VEC_MERGE,
19374   V2DF_FTYPE_V4SI,
19375   V2DF_FTYPE_V4SF,
19376   V2DF_FTYPE_V2SI,
19377   V2SI_FTYPE_V2SI,
19378   V2SI_FTYPE_V4SF,
19379   V2SI_FTYPE_V2SF,
19380   V2SI_FTYPE_V2DF,
19381   V2SF_FTYPE_V2SF,
19382   V2SF_FTYPE_V2SI,
19383   V16QI_FTYPE_V16QI_V16QI,
19384   V16QI_FTYPE_V8HI_V8HI,
19385   V8QI_FTYPE_V8QI_V8QI,
19386   V8QI_FTYPE_V4HI_V4HI,
19387   V8HI_FTYPE_V8HI_V8HI,
19388   V8HI_FTYPE_V8HI_V8HI_COUNT,
19389   V8HI_FTYPE_V16QI_V16QI,
19390   V8HI_FTYPE_V4SI_V4SI,
19391   V8HI_FTYPE_V8HI_SI_COUNT,
19392   V4SI_FTYPE_V4SI_V4SI,
19393   V4SI_FTYPE_V4SI_V4SI_COUNT,
19394   V4SI_FTYPE_V8HI_V8HI,
19395   V4SI_FTYPE_V4SF_V4SF,
19396   V4SI_FTYPE_V2DF_V2DF,
19397   V4SI_FTYPE_V4SI_SI_COUNT,
19398   V4HI_FTYPE_V4HI_V4HI,
19399   V4HI_FTYPE_V4HI_V4HI_COUNT,
19400   V4HI_FTYPE_V8QI_V8QI,
19401   V4HI_FTYPE_V2SI_V2SI,
19402   V4HI_FTYPE_V4HI_SI_COUNT,
19403   V4SF_FTYPE_V4SF_V4SF,
19404   V4SF_FTYPE_V4SF_V4SF_SWAP,
19405   V4SF_FTYPE_V4SF_V2SI,
19406   V4SF_FTYPE_V4SF_V2DF,
19407   V4SF_FTYPE_V4SF_DI,
19408   V4SF_FTYPE_V4SF_SI,
19409   V2DI_FTYPE_V2DI_V2DI,
19410   V2DI_FTYPE_V2DI_V2DI_COUNT,
19411   V2DI_FTYPE_V16QI_V16QI,
19412   V2DI_FTYPE_V4SI_V4SI,
19413   V2DI_FTYPE_V2DI_V16QI,
19414   V2DI_FTYPE_V2DF_V2DF,
19415   V2DI_FTYPE_V2DI_SI_COUNT,
19416   V2SI_FTYPE_V2SI_V2SI,
19417   V2SI_FTYPE_V2SI_V2SI_COUNT,
19418   V2SI_FTYPE_V4HI_V4HI,
19419   V2SI_FTYPE_V2SF_V2SF,
19420   V2SI_FTYPE_V2SI_SI_COUNT,
19421   V2DF_FTYPE_V2DF_V2DF,
19422   V2DF_FTYPE_V2DF_V2DF_SWAP,
19423   V2DF_FTYPE_V2DF_V4SF,
19424   V2DF_FTYPE_V2DF_DI,
19425   V2DF_FTYPE_V2DF_SI,
19426   V2SF_FTYPE_V2SF_V2SF,
19427   V1DI_FTYPE_V1DI_V1DI,
19428   V1DI_FTYPE_V1DI_V1DI_COUNT,
19429   V1DI_FTYPE_V8QI_V8QI,
19430   V1DI_FTYPE_V2SI_V2SI,
19431   V1DI_FTYPE_V1DI_SI_COUNT,
19432   UINT64_FTYPE_UINT64_UINT64,
19433   UINT_FTYPE_UINT_UINT,
19434   UINT_FTYPE_UINT_USHORT,
19435   UINT_FTYPE_UINT_UCHAR,
19436   V8HI_FTYPE_V8HI_INT,
19437   V4SI_FTYPE_V4SI_INT,
19438   V4HI_FTYPE_V4HI_INT,
19439   V4SF_FTYPE_V4SF_INT,
19440   V2DI_FTYPE_V2DI_INT,
19441   V2DI2TI_FTYPE_V2DI_INT,
19442   V2DF_FTYPE_V2DF_INT,
19443   V16QI_FTYPE_V16QI_V16QI_V16QI,
19444   V4SF_FTYPE_V4SF_V4SF_V4SF,
19445   V2DF_FTYPE_V2DF_V2DF_V2DF,
19446   V16QI_FTYPE_V16QI_V16QI_INT,
19447   V8HI_FTYPE_V8HI_V8HI_INT,
19448   V4SI_FTYPE_V4SI_V4SI_INT,
19449   V4SF_FTYPE_V4SF_V4SF_INT,
19450   V2DI_FTYPE_V2DI_V2DI_INT,
19451   V2DI2TI_FTYPE_V2DI_V2DI_INT,
19452   V1DI2DI_FTYPE_V1DI_V1DI_INT,
19453   V2DF_FTYPE_V2DF_V2DF_INT,
19454   V2DI_FTYPE_V2DI_UINT_UINT,
19455   V2DI_FTYPE_V2DI_V2DI_UINT_UINT
19456 };
19457
19458 /* Special builtins with variable number of arguments.  */
19459 static const struct builtin_description bdesc_special_args[] =
19460 {
19461   /* MMX */
19462   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
19463
19464   /* 3DNow! */
19465   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
19466
19467   /* SSE */
19468   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
19469   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
19470   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
19471
19472   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
19473   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
19474   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
19475   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
19476
19477   /* SSE or 3DNow!A  */
19478   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
19479   { 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 },
19480
19481   /* SSE2 */
19482   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
19483   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
19484   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
19485   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
19486   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
19487   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
19488   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntsi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
19489   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
19490   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
19491
19492   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
19493   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
19494
19495   /* SSE3 */
19496   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
19497
19498   /* SSE4.1 */
19499   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
19500
19501   /* SSE4A */
19502   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
19503   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
19504 };
19505
19506 /* Builtins with variable number of arguments.  */
19507 static const struct builtin_description bdesc_args[] =
19508 {
19509   /* MMX */
19510   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19511   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19512   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19513   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19514   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19515   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19516
19517   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19518   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19519   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19520   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19521   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19522   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19523   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19524   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19525
19526   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19527   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19528
19529   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19530   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_nandv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19531   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19532   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19533
19534   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19535   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19536   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19537   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19538   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19539   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19540
19541   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19542   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19543   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19544   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19545   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
19546   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
19547
19548   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
19549   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
19550   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
19551
19552   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
19553
19554   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
19555   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
19556   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
19557   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
19558   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
19559   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
19560
19561   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
19562   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
19563   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
19564   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
19565   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
19566   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
19567
19568   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
19569   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
19570   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
19571   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
19572
19573   /* 3DNow! */
19574   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
19575   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
19576   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
19577   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
19578
19579   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19580   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19581   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19582   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
19583   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
19584   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
19585   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19586   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19587   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19588   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19589   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19590   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19591   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19592   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19593   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19594
19595   /* 3DNow!A */
19596   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
19597   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
19598   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
19599   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
19600   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19601   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
19602
19603   /* SSE */
19604   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
19605   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
19606   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
19607   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
19608   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
19609   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
19610   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
19611   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
19612   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
19613   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
19614   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
19615   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
19616
19617   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
19618
19619   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19620   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19621   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19622   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19623   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19624   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19625   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19626   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19627
19628   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
19629   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
19630   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
19631   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
19632   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
19633   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
19634   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
19635   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
19636   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
19637   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
19638   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
19639   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
19640   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
19641   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
19642   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
19643   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
19644   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
19645   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
19646   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
19647   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngtss", IX86_BUILTIN_CMPNGTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
19648   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngess", IX86_BUILTIN_CMPNGESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
19649   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
19650
19651   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19652   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19653   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19654   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19655
19656   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19657   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_nandv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19658   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19659   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19660
19661   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19662   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19663   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19664   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpckhps, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19665   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpcklps, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19666
19667   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
19668   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
19669   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
19670
19671   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
19672
19673   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
19674   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
19675   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
19676
19677   /* SSE MMX or 3Dnow!A */
19678   { 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 },
19679   { 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 },
19680   { 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 },
19681
19682   { 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 },
19683   { 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 },
19684   { 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 },
19685   { 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 },
19686
19687   { 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 },
19688   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
19689
19690   { 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 },
19691
19692   /* SSE2 */
19693   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
19694
19695   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
19696   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
19697   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
19698   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
19699   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2ps, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
19700
19701   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
19702   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
19703   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
19704   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
19705   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
19706
19707   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
19708
19709   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
19710   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
19711   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
19712   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
19713
19714   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2dq, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
19715   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
19716   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttps2dq, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
19717
19718   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19719   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19720   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19721   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19722   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19723   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19724   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19725   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19726
19727   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
19728   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
19729   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
19730   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
19731   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
19732   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
19733   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
19734   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
19735   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
19736   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
19737   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
19738   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
19739   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
19740   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
19741   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
19742   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
19743   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
19744   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
19745   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
19746   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
19747
19748   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19749   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19750   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19751   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19752
19753   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19754   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_nandv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19755   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19756   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19757
19758   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19759   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpckhpd_exp, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19760   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpcklpd_exp, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19761
19762   { 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 },
19763
19764   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19765   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19766   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19767   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19768   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19769   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19770   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19771   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19772
19773   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19774   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19775   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19776   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19777   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19778   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19779   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19780   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19781
19782   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19783   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
19784
19785   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19786   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_nandv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19787   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19788   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19789
19790   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19791   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19792
19793   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19794   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19795   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
19796   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19797   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19798   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
19799
19800   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19801   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19802   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19803   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19804
19805   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhbw, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19806   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhwd, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
19807   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhdq, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
19808   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhqdq, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19809   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklbw, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19810   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklwd, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19811   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckldq, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19812   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklqdq, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19813
19814   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
19815   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
19816   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
19817
19818   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19819   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
19820
19821   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
19822   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv2siv2di3, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
19823
19824   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
19825
19826   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
19827   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
19828   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
19829   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
19830
19831   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
19832   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
19833   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
19834   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
19835   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
19836   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
19837   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
19838
19839   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
19840   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
19841   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
19842   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
19843   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
19844   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
19845   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
19846
19847   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
19848   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
19849   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
19850   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
19851
19852   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
19853   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
19854   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
19855
19856   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
19857
19858   { OPTION_MASK_ISA_SSE2, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
19859   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
19860
19861   /* SSE2 MMX */
19862   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
19863   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
19864
19865   /* SSE3 */
19866   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
19867   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
19868
19869   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19870   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19871   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19872   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19873   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
19874   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
19875
19876   /* SSSE3 */
19877   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
19878   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
19879   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
19880   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
19881   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
19882   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
19883
19884   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19885   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19886   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19887   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19888   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19889   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19890   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19891   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19892   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19893   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19894   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19895   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19896   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
19897   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
19898   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19899   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19900   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19901   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19902   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19903   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
19904   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19905   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
19906   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19907   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
19908
19909   /* SSSE3.  */
19910   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_V2DI_INT },
19911   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI2DI_FTYPE_V1DI_V1DI_INT },
19912
19913   /* SSE4.1 */
19914   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
19915   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
19916   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
19917   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
19918   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
19919   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
19920   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
19921   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
19922   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
19923   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
19924
19925   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
19926   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
19927   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
19928   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
19929   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
19930   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
19931   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
19932   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
19933   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
19934   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
19935   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
19936   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
19937   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
19938
19939   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
19940   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19941   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19942   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19943   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19944   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19945   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
19946   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19947   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19948   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
19949   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
19950   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
19951
19952   /* SSE4.1 and SSE5 */
19953   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
19954   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
19955   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
19956   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
19957
19958   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
19959   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
19960   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
19961
19962   /* SSE4.2 */
19963   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19964   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32qi, "__builtin_ia32_crc32qi", IX86_BUILTIN_CRC32QI, UNKNOWN, (int) UINT_FTYPE_UINT_UCHAR },
19965   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32hi, "__builtin_ia32_crc32hi", IX86_BUILTIN_CRC32HI, UNKNOWN, (int) UINT_FTYPE_UINT_USHORT },
19966   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32si, "__builtin_ia32_crc32si", IX86_BUILTIN_CRC32SI, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
19967   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse4_2_crc32di, "__builtin_ia32_crc32di", IX86_BUILTIN_CRC32DI, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
19968
19969   /* SSE4A */
19970   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
19971   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
19972   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
19973   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19974
19975   /* AES */
19976   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
19977   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
19978
19979   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19980   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19981   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19982   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
19983
19984   /* PCLMUL */
19985   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
19986 };
19987
19988 /* SSE5 */
19989 enum multi_arg_type {
19990   MULTI_ARG_UNKNOWN,
19991   MULTI_ARG_3_SF,
19992   MULTI_ARG_3_DF,
19993   MULTI_ARG_3_DI,
19994   MULTI_ARG_3_SI,
19995   MULTI_ARG_3_SI_DI,
19996   MULTI_ARG_3_HI,
19997   MULTI_ARG_3_HI_SI,
19998   MULTI_ARG_3_QI,
19999   MULTI_ARG_3_PERMPS,
20000   MULTI_ARG_3_PERMPD,
20001   MULTI_ARG_2_SF,
20002   MULTI_ARG_2_DF,
20003   MULTI_ARG_2_DI,
20004   MULTI_ARG_2_SI,
20005   MULTI_ARG_2_HI,
20006   MULTI_ARG_2_QI,
20007   MULTI_ARG_2_DI_IMM,
20008   MULTI_ARG_2_SI_IMM,
20009   MULTI_ARG_2_HI_IMM,
20010   MULTI_ARG_2_QI_IMM,
20011   MULTI_ARG_2_SF_CMP,
20012   MULTI_ARG_2_DF_CMP,
20013   MULTI_ARG_2_DI_CMP,
20014   MULTI_ARG_2_SI_CMP,
20015   MULTI_ARG_2_HI_CMP,
20016   MULTI_ARG_2_QI_CMP,
20017   MULTI_ARG_2_DI_TF,
20018   MULTI_ARG_2_SI_TF,
20019   MULTI_ARG_2_HI_TF,
20020   MULTI_ARG_2_QI_TF,
20021   MULTI_ARG_2_SF_TF,
20022   MULTI_ARG_2_DF_TF,
20023   MULTI_ARG_1_SF,
20024   MULTI_ARG_1_DF,
20025   MULTI_ARG_1_DI,
20026   MULTI_ARG_1_SI,
20027   MULTI_ARG_1_HI,
20028   MULTI_ARG_1_QI,
20029   MULTI_ARG_1_SI_DI,
20030   MULTI_ARG_1_HI_DI,
20031   MULTI_ARG_1_HI_SI,
20032   MULTI_ARG_1_QI_DI,
20033   MULTI_ARG_1_QI_SI,
20034   MULTI_ARG_1_QI_HI,
20035   MULTI_ARG_1_PH2PS,
20036   MULTI_ARG_1_PS2PH
20037 };
20038
20039 static const struct builtin_description bdesc_multi_arg[] =
20040 {
20041   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv4sf4,     "__builtin_ia32_fmaddss",    IX86_BUILTIN_FMADDSS,    0,            (int)MULTI_ARG_3_SF },
20042   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv2df4,     "__builtin_ia32_fmaddsd",    IX86_BUILTIN_FMADDSD,    0,            (int)MULTI_ARG_3_DF },
20043   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv4sf4,       "__builtin_ia32_fmaddps",    IX86_BUILTIN_FMADDPS,    0,            (int)MULTI_ARG_3_SF },
20044   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv2df4,       "__builtin_ia32_fmaddpd",    IX86_BUILTIN_FMADDPD,    0,            (int)MULTI_ARG_3_DF },
20045   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv4sf4,     "__builtin_ia32_fmsubss",    IX86_BUILTIN_FMSUBSS,    0,            (int)MULTI_ARG_3_SF },
20046   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv2df4,     "__builtin_ia32_fmsubsd",    IX86_BUILTIN_FMSUBSD,    0,            (int)MULTI_ARG_3_DF },
20047   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv4sf4,       "__builtin_ia32_fmsubps",    IX86_BUILTIN_FMSUBPS,    0,            (int)MULTI_ARG_3_SF },
20048   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv2df4,       "__builtin_ia32_fmsubpd",    IX86_BUILTIN_FMSUBPD,    0,            (int)MULTI_ARG_3_DF },
20049   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv4sf4,    "__builtin_ia32_fnmaddss",   IX86_BUILTIN_FNMADDSS,   0,            (int)MULTI_ARG_3_SF },
20050   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv2df4,    "__builtin_ia32_fnmaddsd",   IX86_BUILTIN_FNMADDSD,   0,            (int)MULTI_ARG_3_DF },
20051   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv4sf4,      "__builtin_ia32_fnmaddps",   IX86_BUILTIN_FNMADDPS,   0,            (int)MULTI_ARG_3_SF },
20052   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv2df4,      "__builtin_ia32_fnmaddpd",   IX86_BUILTIN_FNMADDPD,   0,            (int)MULTI_ARG_3_DF },
20053   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv4sf4,    "__builtin_ia32_fnmsubss",   IX86_BUILTIN_FNMSUBSS,   0,            (int)MULTI_ARG_3_SF },
20054   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv2df4,    "__builtin_ia32_fnmsubsd",   IX86_BUILTIN_FNMSUBSD,   0,            (int)MULTI_ARG_3_DF },
20055   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv4sf4,      "__builtin_ia32_fnmsubps",   IX86_BUILTIN_FNMSUBPS,   0,            (int)MULTI_ARG_3_SF },
20056   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv2df4,      "__builtin_ia32_fnmsubpd",   IX86_BUILTIN_FNMSUBPD,   0,            (int)MULTI_ARG_3_DF },
20057   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov",      IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
20058   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov_v2di", IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
20059   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4si,        "__builtin_ia32_pcmov_v4si", IX86_BUILTIN_PCMOV_V4SI, 0,            (int)MULTI_ARG_3_SI },
20060   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v8hi,        "__builtin_ia32_pcmov_v8hi", IX86_BUILTIN_PCMOV_V8HI, 0,            (int)MULTI_ARG_3_HI },
20061   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v16qi,       "__builtin_ia32_pcmov_v16qi",IX86_BUILTIN_PCMOV_V16QI,0,            (int)MULTI_ARG_3_QI },
20062   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2df,        "__builtin_ia32_pcmov_v2df", IX86_BUILTIN_PCMOV_V2DF, 0,            (int)MULTI_ARG_3_DF },
20063   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4sf,        "__builtin_ia32_pcmov_v4sf", IX86_BUILTIN_PCMOV_V4SF, 0,            (int)MULTI_ARG_3_SF },
20064   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pperm,             "__builtin_ia32_pperm",      IX86_BUILTIN_PPERM,      0,            (int)MULTI_ARG_3_QI },
20065   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv4sf,          "__builtin_ia32_permps",     IX86_BUILTIN_PERMPS,     0,            (int)MULTI_ARG_3_PERMPS },
20066   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv2df,          "__builtin_ia32_permpd",     IX86_BUILTIN_PERMPD,     0,            (int)MULTI_ARG_3_PERMPD },
20067   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssww,          "__builtin_ia32_pmacssww",   IX86_BUILTIN_PMACSSWW,   0,            (int)MULTI_ARG_3_HI },
20068   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsww,           "__builtin_ia32_pmacsww",    IX86_BUILTIN_PMACSWW,    0,            (int)MULTI_ARG_3_HI },
20069   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsswd,          "__builtin_ia32_pmacsswd",   IX86_BUILTIN_PMACSSWD,   0,            (int)MULTI_ARG_3_HI_SI },
20070   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacswd,           "__builtin_ia32_pmacswd",    IX86_BUILTIN_PMACSWD,    0,            (int)MULTI_ARG_3_HI_SI },
20071   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdd,          "__builtin_ia32_pmacssdd",   IX86_BUILTIN_PMACSSDD,   0,            (int)MULTI_ARG_3_SI },
20072   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdd,           "__builtin_ia32_pmacsdd",    IX86_BUILTIN_PMACSDD,    0,            (int)MULTI_ARG_3_SI },
20073   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdql,         "__builtin_ia32_pmacssdql",  IX86_BUILTIN_PMACSSDQL,  0,            (int)MULTI_ARG_3_SI_DI },
20074   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdqh,         "__builtin_ia32_pmacssdqh",  IX86_BUILTIN_PMACSSDQH,  0,            (int)MULTI_ARG_3_SI_DI },
20075   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdql,          "__builtin_ia32_pmacsdql",   IX86_BUILTIN_PMACSDQL,   0,            (int)MULTI_ARG_3_SI_DI },
20076   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdqh,          "__builtin_ia32_pmacsdqh",   IX86_BUILTIN_PMACSDQH,   0,            (int)MULTI_ARG_3_SI_DI },
20077   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcsswd,         "__builtin_ia32_pmadcsswd",  IX86_BUILTIN_PMADCSSWD,  0,            (int)MULTI_ARG_3_HI_SI },
20078   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcswd,          "__builtin_ia32_pmadcswd",   IX86_BUILTIN_PMADCSWD,   0,            (int)MULTI_ARG_3_HI_SI },
20079   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv2di3,        "__builtin_ia32_protq",      IX86_BUILTIN_PROTQ,      0,            (int)MULTI_ARG_2_DI },
20080   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv4si3,        "__builtin_ia32_protd",      IX86_BUILTIN_PROTD,      0,            (int)MULTI_ARG_2_SI },
20081   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv8hi3,        "__builtin_ia32_protw",      IX86_BUILTIN_PROTW,      0,            (int)MULTI_ARG_2_HI },
20082   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv16qi3,       "__builtin_ia32_protb",      IX86_BUILTIN_PROTB,      0,            (int)MULTI_ARG_2_QI },
20083   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv2di3,         "__builtin_ia32_protqi",     IX86_BUILTIN_PROTQ_IMM,  0,            (int)MULTI_ARG_2_DI_IMM },
20084   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv4si3,         "__builtin_ia32_protdi",     IX86_BUILTIN_PROTD_IMM,  0,            (int)MULTI_ARG_2_SI_IMM },
20085   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv8hi3,         "__builtin_ia32_protwi",     IX86_BUILTIN_PROTW_IMM,  0,            (int)MULTI_ARG_2_HI_IMM },
20086   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv16qi3,        "__builtin_ia32_protbi",     IX86_BUILTIN_PROTB_IMM,  0,            (int)MULTI_ARG_2_QI_IMM },
20087   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv2di3,         "__builtin_ia32_pshaq",      IX86_BUILTIN_PSHAQ,      0,            (int)MULTI_ARG_2_DI },
20088   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv4si3,         "__builtin_ia32_pshad",      IX86_BUILTIN_PSHAD,      0,            (int)MULTI_ARG_2_SI },
20089   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv8hi3,         "__builtin_ia32_pshaw",      IX86_BUILTIN_PSHAW,      0,            (int)MULTI_ARG_2_HI },
20090   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv16qi3,        "__builtin_ia32_pshab",      IX86_BUILTIN_PSHAB,      0,            (int)MULTI_ARG_2_QI },
20091   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv2di3,         "__builtin_ia32_pshlq",      IX86_BUILTIN_PSHLQ,      0,            (int)MULTI_ARG_2_DI },
20092   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv4si3,         "__builtin_ia32_pshld",      IX86_BUILTIN_PSHLD,      0,            (int)MULTI_ARG_2_SI },
20093   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv8hi3,         "__builtin_ia32_pshlw",      IX86_BUILTIN_PSHLW,      0,            (int)MULTI_ARG_2_HI },
20094   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv16qi3,        "__builtin_ia32_pshlb",      IX86_BUILTIN_PSHLB,      0,            (int)MULTI_ARG_2_QI },
20095   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv4sf2,       "__builtin_ia32_frczss",     IX86_BUILTIN_FRCZSS,     0,            (int)MULTI_ARG_2_SF },
20096   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv2df2,       "__builtin_ia32_frczsd",     IX86_BUILTIN_FRCZSD,     0,            (int)MULTI_ARG_2_DF },
20097   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv4sf2,         "__builtin_ia32_frczps",     IX86_BUILTIN_FRCZPS,     0,            (int)MULTI_ARG_1_SF },
20098   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv2df2,         "__builtin_ia32_frczpd",     IX86_BUILTIN_FRCZPD,     0,            (int)MULTI_ARG_1_DF },
20099   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtph2ps,          "__builtin_ia32_cvtph2ps",   IX86_BUILTIN_CVTPH2PS,   0,            (int)MULTI_ARG_1_PH2PS },
20100   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtps2ph,          "__builtin_ia32_cvtps2ph",   IX86_BUILTIN_CVTPS2PH,   0,            (int)MULTI_ARG_1_PS2PH },
20101   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbw,           "__builtin_ia32_phaddbw",    IX86_BUILTIN_PHADDBW,    0,            (int)MULTI_ARG_1_QI_HI },
20102   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbd,           "__builtin_ia32_phaddbd",    IX86_BUILTIN_PHADDBD,    0,            (int)MULTI_ARG_1_QI_SI },
20103   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbq,           "__builtin_ia32_phaddbq",    IX86_BUILTIN_PHADDBQ,    0,            (int)MULTI_ARG_1_QI_DI },
20104   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwd,           "__builtin_ia32_phaddwd",    IX86_BUILTIN_PHADDWD,    0,            (int)MULTI_ARG_1_HI_SI },
20105   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwq,           "__builtin_ia32_phaddwq",    IX86_BUILTIN_PHADDWQ,    0,            (int)MULTI_ARG_1_HI_DI },
20106   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadddq,           "__builtin_ia32_phadddq",    IX86_BUILTIN_PHADDDQ,    0,            (int)MULTI_ARG_1_SI_DI },
20107   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubw,          "__builtin_ia32_phaddubw",   IX86_BUILTIN_PHADDUBW,   0,            (int)MULTI_ARG_1_QI_HI },
20108   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubd,          "__builtin_ia32_phaddubd",   IX86_BUILTIN_PHADDUBD,   0,            (int)MULTI_ARG_1_QI_SI },
20109   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubq,          "__builtin_ia32_phaddubq",   IX86_BUILTIN_PHADDUBQ,   0,            (int)MULTI_ARG_1_QI_DI },
20110   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwd,          "__builtin_ia32_phadduwd",   IX86_BUILTIN_PHADDUWD,   0,            (int)MULTI_ARG_1_HI_SI },
20111   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwq,          "__builtin_ia32_phadduwq",   IX86_BUILTIN_PHADDUWQ,   0,            (int)MULTI_ARG_1_HI_DI },
20112   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddudq,          "__builtin_ia32_phaddudq",   IX86_BUILTIN_PHADDUDQ,   0,            (int)MULTI_ARG_1_SI_DI },
20113   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubbw,           "__builtin_ia32_phsubbw",    IX86_BUILTIN_PHSUBBW,    0,            (int)MULTI_ARG_1_QI_HI },
20114   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubwd,           "__builtin_ia32_phsubwd",    IX86_BUILTIN_PHSUBWD,    0,            (int)MULTI_ARG_1_HI_SI },
20115   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubdq,           "__builtin_ia32_phsubdq",    IX86_BUILTIN_PHSUBDQ,    0,            (int)MULTI_ARG_1_SI_DI },
20116
20117   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comeqss",    IX86_BUILTIN_COMEQSS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
20118   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comness",    IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
20119   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comneqss",   IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
20120   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comltss",    IX86_BUILTIN_COMLTSS,    LT,           (int)MULTI_ARG_2_SF_CMP },
20121   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comless",    IX86_BUILTIN_COMLESS,    LE,           (int)MULTI_ARG_2_SF_CMP },
20122   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgtss",    IX86_BUILTIN_COMGTSS,    GT,           (int)MULTI_ARG_2_SF_CMP },
20123   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgess",    IX86_BUILTIN_COMGESS,    GE,           (int)MULTI_ARG_2_SF_CMP },
20124   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comueqss",   IX86_BUILTIN_COMUEQSS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
20125   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuness",   IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
20126   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuneqss",  IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
20127   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunltss",  IX86_BUILTIN_COMULTSS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
20128   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunless",  IX86_BUILTIN_COMULESS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
20129   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungtss",  IX86_BUILTIN_COMUGTSS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
20130   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungess",  IX86_BUILTIN_COMUGESS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
20131   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comordss",   IX86_BUILTIN_COMORDSS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
20132   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunordss", IX86_BUILTIN_COMUNORDSS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
20133
20134   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comeqsd",    IX86_BUILTIN_COMEQSD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
20135   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comnesd",    IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
20136   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comneqsd",   IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
20137   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comltsd",    IX86_BUILTIN_COMLTSD,    LT,           (int)MULTI_ARG_2_DF_CMP },
20138   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comlesd",    IX86_BUILTIN_COMLESD,    LE,           (int)MULTI_ARG_2_DF_CMP },
20139   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgtsd",    IX86_BUILTIN_COMGTSD,    GT,           (int)MULTI_ARG_2_DF_CMP },
20140   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgesd",    IX86_BUILTIN_COMGESD,    GE,           (int)MULTI_ARG_2_DF_CMP },
20141   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comueqsd",   IX86_BUILTIN_COMUEQSD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
20142   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunesd",   IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
20143   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comuneqsd",  IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
20144   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunltsd",  IX86_BUILTIN_COMULTSD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
20145   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunlesd",  IX86_BUILTIN_COMULESD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
20146   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungtsd",  IX86_BUILTIN_COMUGTSD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
20147   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungesd",  IX86_BUILTIN_COMUGESD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
20148   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comordsd",   IX86_BUILTIN_COMORDSD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
20149   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunordsd", IX86_BUILTIN_COMUNORDSD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
20150
20151   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comeqps",    IX86_BUILTIN_COMEQPS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
20152   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneps",    IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
20153   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneqps",   IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
20154   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comltps",    IX86_BUILTIN_COMLTPS,    LT,           (int)MULTI_ARG_2_SF_CMP },
20155   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comleps",    IX86_BUILTIN_COMLEPS,    LE,           (int)MULTI_ARG_2_SF_CMP },
20156   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgtps",    IX86_BUILTIN_COMGTPS,    GT,           (int)MULTI_ARG_2_SF_CMP },
20157   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgeps",    IX86_BUILTIN_COMGEPS,    GE,           (int)MULTI_ARG_2_SF_CMP },
20158   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comueqps",   IX86_BUILTIN_COMUEQPS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
20159   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneps",   IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
20160   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneqps",  IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
20161   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunltps",  IX86_BUILTIN_COMULTPS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
20162   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunleps",  IX86_BUILTIN_COMULEPS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
20163   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungtps",  IX86_BUILTIN_COMUGTPS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
20164   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungeps",  IX86_BUILTIN_COMUGEPS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
20165   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comordps",   IX86_BUILTIN_COMORDPS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
20166   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunordps", IX86_BUILTIN_COMUNORDPS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
20167
20168   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comeqpd",    IX86_BUILTIN_COMEQPD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
20169   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comnepd",    IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
20170   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comneqpd",   IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
20171   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comltpd",    IX86_BUILTIN_COMLTPD,    LT,           (int)MULTI_ARG_2_DF_CMP },
20172   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comlepd",    IX86_BUILTIN_COMLEPD,    LE,           (int)MULTI_ARG_2_DF_CMP },
20173   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgtpd",    IX86_BUILTIN_COMGTPD,    GT,           (int)MULTI_ARG_2_DF_CMP },
20174   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgepd",    IX86_BUILTIN_COMGEPD,    GE,           (int)MULTI_ARG_2_DF_CMP },
20175   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comueqpd",   IX86_BUILTIN_COMUEQPD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
20176   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunepd",   IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
20177   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comuneqpd",  IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
20178   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunltpd",  IX86_BUILTIN_COMULTPD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
20179   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunlepd",  IX86_BUILTIN_COMULEPD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
20180   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungtpd",  IX86_BUILTIN_COMUGTPD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
20181   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungepd",  IX86_BUILTIN_COMUGEPD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
20182   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comordpd",   IX86_BUILTIN_COMORDPD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
20183   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunordpd", IX86_BUILTIN_COMUNORDPD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
20184
20185   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomeqb",    IX86_BUILTIN_PCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
20186   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneb",    IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
20187   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneqb",   IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
20188   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomltb",    IX86_BUILTIN_PCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
20189   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomleb",    IX86_BUILTIN_PCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
20190   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgtb",    IX86_BUILTIN_PCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
20191   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgeb",    IX86_BUILTIN_PCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
20192
20193   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomeqw",    IX86_BUILTIN_PCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
20194   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomnew",    IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
20195   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomneqw",   IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
20196   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomltw",    IX86_BUILTIN_PCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
20197   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomlew",    IX86_BUILTIN_PCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
20198   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgtw",    IX86_BUILTIN_PCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
20199   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgew",    IX86_BUILTIN_PCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
20200
20201   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomeqd",    IX86_BUILTIN_PCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
20202   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomned",    IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
20203   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomneqd",   IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
20204   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomltd",    IX86_BUILTIN_PCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
20205   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomled",    IX86_BUILTIN_PCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
20206   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomgtd",    IX86_BUILTIN_PCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
20207   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomged",    IX86_BUILTIN_PCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
20208
20209   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomeqq",    IX86_BUILTIN_PCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
20210   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneq",    IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
20211   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneqq",   IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
20212   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomltq",    IX86_BUILTIN_PCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
20213   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomleq",    IX86_BUILTIN_PCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
20214   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgtq",    IX86_BUILTIN_PCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
20215   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgeq",    IX86_BUILTIN_PCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
20216
20217   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomequb",   IX86_BUILTIN_PCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
20218   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomneub",   IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
20219   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomnequb",  IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
20220   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomltub",   IX86_BUILTIN_PCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
20221   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomleub",   IX86_BUILTIN_PCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
20222   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgtub",   IX86_BUILTIN_PCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
20223   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgeub",   IX86_BUILTIN_PCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
20224
20225   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomequw",   IX86_BUILTIN_PCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
20226   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomneuw",   IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
20227   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomnequw",  IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
20228   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomltuw",   IX86_BUILTIN_PCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
20229   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomleuw",   IX86_BUILTIN_PCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
20230   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgtuw",   IX86_BUILTIN_PCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
20231   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgeuw",   IX86_BUILTIN_PCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
20232
20233   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomequd",   IX86_BUILTIN_PCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
20234   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomneud",   IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
20235   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomnequd",  IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
20236   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomltud",   IX86_BUILTIN_PCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
20237   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomleud",   IX86_BUILTIN_PCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
20238   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgtud",   IX86_BUILTIN_PCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
20239   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgeud",   IX86_BUILTIN_PCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
20240
20241   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomequq",   IX86_BUILTIN_PCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
20242   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomneuq",   IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
20243   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomnequq",  IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
20244   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomltuq",   IX86_BUILTIN_PCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
20245   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomleuq",   IX86_BUILTIN_PCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
20246   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgtuq",   IX86_BUILTIN_PCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
20247   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgeuq",   IX86_BUILTIN_PCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
20248
20249   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalsess", IX86_BUILTIN_COMFALSESS, COM_FALSE_S,  (int)MULTI_ARG_2_SF_TF },
20250   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtruess",  IX86_BUILTIN_COMTRUESS,  COM_TRUE_S,   (int)MULTI_ARG_2_SF_TF },
20251   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalseps", IX86_BUILTIN_COMFALSEPS, COM_FALSE_P,  (int)MULTI_ARG_2_SF_TF },
20252   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtrueps",  IX86_BUILTIN_COMTRUEPS,  COM_TRUE_P,   (int)MULTI_ARG_2_SF_TF },
20253   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsesd", IX86_BUILTIN_COMFALSESD, COM_FALSE_S,  (int)MULTI_ARG_2_DF_TF },
20254   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruesd",  IX86_BUILTIN_COMTRUESD,  COM_TRUE_S,   (int)MULTI_ARG_2_DF_TF },
20255   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsepd", IX86_BUILTIN_COMFALSEPD, COM_FALSE_P,  (int)MULTI_ARG_2_DF_TF },
20256   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruepd",  IX86_BUILTIN_COMTRUEPD,  COM_TRUE_P,   (int)MULTI_ARG_2_DF_TF },
20257
20258   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseb", IX86_BUILTIN_PCOMFALSEB, PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
20259   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalsew", IX86_BUILTIN_PCOMFALSEW, PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
20260   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalsed", IX86_BUILTIN_PCOMFALSED, PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
20261   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseq", IX86_BUILTIN_PCOMFALSEQ, PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
20262   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseub",IX86_BUILTIN_PCOMFALSEUB,PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
20263   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalseuw",IX86_BUILTIN_PCOMFALSEUW,PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
20264   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalseud",IX86_BUILTIN_PCOMFALSEUD,PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
20265   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseuq",IX86_BUILTIN_PCOMFALSEUQ,PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
20266
20267   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueb",  IX86_BUILTIN_PCOMTRUEB,  PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
20268   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtruew",  IX86_BUILTIN_PCOMTRUEW,  PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
20269   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrued",  IX86_BUILTIN_PCOMTRUED,  PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
20270   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueq",  IX86_BUILTIN_PCOMTRUEQ,  PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
20271   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueub", IX86_BUILTIN_PCOMTRUEUB, PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
20272   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtrueuw", IX86_BUILTIN_PCOMTRUEUW, PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
20273   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrueud", IX86_BUILTIN_PCOMTRUEUD, PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
20274   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueuq", IX86_BUILTIN_PCOMTRUEUQ, PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
20275 };
20276
20277 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
20278    in the current target ISA to allow the user to compile particular modules
20279    with different target specific options that differ from the command line
20280    options.  */
20281 static void
20282 ix86_init_mmx_sse_builtins (void)
20283 {
20284   const struct builtin_description * d;
20285   size_t i;
20286
20287   tree V16QI_type_node = build_vector_type_for_mode (char_type_node, V16QImode);
20288   tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
20289   tree V1DI_type_node
20290     = build_vector_type_for_mode (long_long_integer_type_node, V1DImode);
20291   tree V2SF_type_node = build_vector_type_for_mode (float_type_node, V2SFmode);
20292   tree V2DI_type_node
20293     = build_vector_type_for_mode (long_long_integer_type_node, V2DImode);
20294   tree V2DF_type_node = build_vector_type_for_mode (double_type_node, V2DFmode);
20295   tree V4SF_type_node = build_vector_type_for_mode (float_type_node, V4SFmode);
20296   tree V4SI_type_node = build_vector_type_for_mode (intSI_type_node, V4SImode);
20297   tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
20298   tree V8QI_type_node = build_vector_type_for_mode (char_type_node, V8QImode);
20299   tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, V8HImode);
20300
20301   tree pchar_type_node = build_pointer_type (char_type_node);
20302   tree pcchar_type_node
20303     = build_pointer_type (build_type_variant (char_type_node, 1, 0));
20304   tree pfloat_type_node = build_pointer_type (float_type_node);
20305   tree pcfloat_type_node
20306     = build_pointer_type (build_type_variant (float_type_node, 1, 0));
20307   tree pv2sf_type_node = build_pointer_type (V2SF_type_node);
20308   tree pcv2sf_type_node
20309     = build_pointer_type (build_type_variant (V2SF_type_node, 1, 0));
20310   tree pv2di_type_node = build_pointer_type (V2DI_type_node);
20311   tree pdi_type_node = build_pointer_type (long_long_unsigned_type_node);
20312
20313   /* Comparisons.  */
20314   tree int_ftype_v4sf_v4sf
20315     = build_function_type_list (integer_type_node,
20316                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
20317   tree v4si_ftype_v4sf_v4sf
20318     = build_function_type_list (V4SI_type_node,
20319                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
20320   /* MMX/SSE/integer conversions.  */
20321   tree int_ftype_v4sf
20322     = build_function_type_list (integer_type_node,
20323                                 V4SF_type_node, NULL_TREE);
20324   tree int64_ftype_v4sf
20325     = build_function_type_list (long_long_integer_type_node,
20326                                 V4SF_type_node, NULL_TREE);
20327   tree int_ftype_v8qi
20328     = build_function_type_list (integer_type_node, V8QI_type_node, NULL_TREE);
20329   tree v4sf_ftype_v4sf_int
20330     = build_function_type_list (V4SF_type_node,
20331                                 V4SF_type_node, integer_type_node, NULL_TREE);
20332   tree v4sf_ftype_v4sf_int64
20333     = build_function_type_list (V4SF_type_node,
20334                                 V4SF_type_node, long_long_integer_type_node,
20335                                 NULL_TREE);
20336   tree v4sf_ftype_v4sf_v2si
20337     = build_function_type_list (V4SF_type_node,
20338                                 V4SF_type_node, V2SI_type_node, NULL_TREE);
20339
20340   /* Miscellaneous.  */
20341   tree v8qi_ftype_v4hi_v4hi
20342     = build_function_type_list (V8QI_type_node,
20343                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
20344   tree v4hi_ftype_v2si_v2si
20345     = build_function_type_list (V4HI_type_node,
20346                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
20347   tree v4sf_ftype_v4sf_v4sf_int
20348     = build_function_type_list (V4SF_type_node,
20349                                 V4SF_type_node, V4SF_type_node,
20350                                 integer_type_node, NULL_TREE);
20351   tree v2si_ftype_v4hi_v4hi
20352     = build_function_type_list (V2SI_type_node,
20353                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
20354   tree v4hi_ftype_v4hi_int
20355     = build_function_type_list (V4HI_type_node,
20356                                 V4HI_type_node, integer_type_node, NULL_TREE);
20357   tree v2si_ftype_v2si_int
20358     = build_function_type_list (V2SI_type_node,
20359                                 V2SI_type_node, integer_type_node, NULL_TREE);
20360   tree v1di_ftype_v1di_int
20361     = build_function_type_list (V1DI_type_node,
20362                                 V1DI_type_node, integer_type_node, NULL_TREE);
20363
20364   tree void_ftype_void
20365     = build_function_type (void_type_node, void_list_node);
20366   tree void_ftype_unsigned
20367     = build_function_type_list (void_type_node, unsigned_type_node, NULL_TREE);
20368   tree void_ftype_unsigned_unsigned
20369     = build_function_type_list (void_type_node, unsigned_type_node,
20370                                 unsigned_type_node, NULL_TREE);
20371   tree void_ftype_pcvoid_unsigned_unsigned
20372     = build_function_type_list (void_type_node, const_ptr_type_node,
20373                                 unsigned_type_node, unsigned_type_node,
20374                                 NULL_TREE);
20375   tree unsigned_ftype_void
20376     = build_function_type (unsigned_type_node, void_list_node);
20377   tree v2si_ftype_v4sf
20378     = build_function_type_list (V2SI_type_node, V4SF_type_node, NULL_TREE);
20379   /* Loads/stores.  */
20380   tree void_ftype_v8qi_v8qi_pchar
20381     = build_function_type_list (void_type_node,
20382                                 V8QI_type_node, V8QI_type_node,
20383                                 pchar_type_node, NULL_TREE);
20384   tree v4sf_ftype_pcfloat
20385     = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
20386   tree v4sf_ftype_v4sf_pcv2sf
20387     = build_function_type_list (V4SF_type_node,
20388                                 V4SF_type_node, pcv2sf_type_node, NULL_TREE);
20389   tree void_ftype_pv2sf_v4sf
20390     = build_function_type_list (void_type_node,
20391                                 pv2sf_type_node, V4SF_type_node, NULL_TREE);
20392   tree void_ftype_pfloat_v4sf
20393     = build_function_type_list (void_type_node,
20394                                 pfloat_type_node, V4SF_type_node, NULL_TREE);
20395   tree void_ftype_pdi_di
20396     = build_function_type_list (void_type_node,
20397                                 pdi_type_node, long_long_unsigned_type_node,
20398                                 NULL_TREE);
20399   tree void_ftype_pv2di_v2di
20400     = build_function_type_list (void_type_node,
20401                                 pv2di_type_node, V2DI_type_node, NULL_TREE);
20402   /* Normal vector unops.  */
20403   tree v4sf_ftype_v4sf
20404     = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
20405   tree v16qi_ftype_v16qi
20406     = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
20407   tree v8hi_ftype_v8hi
20408     = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
20409   tree v4si_ftype_v4si
20410     = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
20411   tree v8qi_ftype_v8qi
20412     = build_function_type_list (V8QI_type_node, V8QI_type_node, NULL_TREE);
20413   tree v4hi_ftype_v4hi
20414     = build_function_type_list (V4HI_type_node, V4HI_type_node, NULL_TREE);
20415
20416   /* Normal vector binops.  */
20417   tree v4sf_ftype_v4sf_v4sf
20418     = build_function_type_list (V4SF_type_node,
20419                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
20420   tree v8qi_ftype_v8qi_v8qi
20421     = build_function_type_list (V8QI_type_node,
20422                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
20423   tree v4hi_ftype_v4hi_v4hi
20424     = build_function_type_list (V4HI_type_node,
20425                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
20426   tree v2si_ftype_v2si_v2si
20427     = build_function_type_list (V2SI_type_node,
20428                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
20429   tree v1di_ftype_v1di_v1di
20430     = build_function_type_list (V1DI_type_node,
20431                                 V1DI_type_node, V1DI_type_node, NULL_TREE);
20432   tree v1di_ftype_v1di_v1di_int
20433     = build_function_type_list (V1DI_type_node,
20434                                 V1DI_type_node, V1DI_type_node,
20435                                 integer_type_node, NULL_TREE);
20436   tree v2si_ftype_v2sf
20437     = build_function_type_list (V2SI_type_node, V2SF_type_node, NULL_TREE);
20438   tree v2sf_ftype_v2si
20439     = build_function_type_list (V2SF_type_node, V2SI_type_node, NULL_TREE);
20440   tree v2si_ftype_v2si
20441     = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
20442   tree v2sf_ftype_v2sf
20443     = build_function_type_list (V2SF_type_node, V2SF_type_node, NULL_TREE);
20444   tree v2sf_ftype_v2sf_v2sf
20445     = build_function_type_list (V2SF_type_node,
20446                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
20447   tree v2si_ftype_v2sf_v2sf
20448     = build_function_type_list (V2SI_type_node,
20449                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
20450   tree pint_type_node    = build_pointer_type (integer_type_node);
20451   tree pdouble_type_node = build_pointer_type (double_type_node);
20452   tree pcdouble_type_node = build_pointer_type (
20453                                 build_type_variant (double_type_node, 1, 0));
20454   tree int_ftype_v2df_v2df
20455     = build_function_type_list (integer_type_node,
20456                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
20457
20458   tree void_ftype_pcvoid
20459     = build_function_type_list (void_type_node, const_ptr_type_node, NULL_TREE);
20460   tree v4sf_ftype_v4si
20461     = build_function_type_list (V4SF_type_node, V4SI_type_node, NULL_TREE);
20462   tree v4si_ftype_v4sf
20463     = build_function_type_list (V4SI_type_node, V4SF_type_node, NULL_TREE);
20464   tree v2df_ftype_v4si
20465     = build_function_type_list (V2DF_type_node, V4SI_type_node, NULL_TREE);
20466   tree v4si_ftype_v2df
20467     = build_function_type_list (V4SI_type_node, V2DF_type_node, NULL_TREE);
20468   tree v4si_ftype_v2df_v2df
20469     = build_function_type_list (V4SI_type_node,
20470                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
20471   tree v2si_ftype_v2df
20472     = build_function_type_list (V2SI_type_node, V2DF_type_node, NULL_TREE);
20473   tree v4sf_ftype_v2df
20474     = build_function_type_list (V4SF_type_node, V2DF_type_node, NULL_TREE);
20475   tree v2df_ftype_v2si
20476     = build_function_type_list (V2DF_type_node, V2SI_type_node, NULL_TREE);
20477   tree v2df_ftype_v4sf
20478     = build_function_type_list (V2DF_type_node, V4SF_type_node, NULL_TREE);
20479   tree int_ftype_v2df
20480     = build_function_type_list (integer_type_node, V2DF_type_node, NULL_TREE);
20481   tree int64_ftype_v2df
20482     = build_function_type_list (long_long_integer_type_node,
20483                                 V2DF_type_node, NULL_TREE);
20484   tree v2df_ftype_v2df_int
20485     = build_function_type_list (V2DF_type_node,
20486                                 V2DF_type_node, integer_type_node, NULL_TREE);
20487   tree v2df_ftype_v2df_int64
20488     = build_function_type_list (V2DF_type_node,
20489                                 V2DF_type_node, long_long_integer_type_node,
20490                                 NULL_TREE);
20491   tree v4sf_ftype_v4sf_v2df
20492     = build_function_type_list (V4SF_type_node,
20493                                 V4SF_type_node, V2DF_type_node, NULL_TREE);
20494   tree v2df_ftype_v2df_v4sf
20495     = build_function_type_list (V2DF_type_node,
20496                                 V2DF_type_node, V4SF_type_node, NULL_TREE);
20497   tree v2df_ftype_v2df_v2df_int
20498     = build_function_type_list (V2DF_type_node,
20499                                 V2DF_type_node, V2DF_type_node,
20500                                 integer_type_node,
20501                                 NULL_TREE);
20502   tree v2df_ftype_v2df_pcdouble
20503     = build_function_type_list (V2DF_type_node,
20504                                 V2DF_type_node, pcdouble_type_node, NULL_TREE);
20505   tree void_ftype_pdouble_v2df
20506     = build_function_type_list (void_type_node,
20507                                 pdouble_type_node, V2DF_type_node, NULL_TREE);
20508   tree void_ftype_pint_int
20509     = build_function_type_list (void_type_node,
20510                                 pint_type_node, integer_type_node, NULL_TREE);
20511   tree void_ftype_v16qi_v16qi_pchar
20512     = build_function_type_list (void_type_node,
20513                                 V16QI_type_node, V16QI_type_node,
20514                                 pchar_type_node, NULL_TREE);
20515   tree v2df_ftype_pcdouble
20516     = build_function_type_list (V2DF_type_node, pcdouble_type_node, NULL_TREE);
20517   tree v2df_ftype_v2df_v2df
20518     = build_function_type_list (V2DF_type_node,
20519                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
20520   tree v16qi_ftype_v16qi_v16qi
20521     = build_function_type_list (V16QI_type_node,
20522                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
20523   tree v8hi_ftype_v8hi_v8hi
20524     = build_function_type_list (V8HI_type_node,
20525                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
20526   tree v4si_ftype_v4si_v4si
20527     = build_function_type_list (V4SI_type_node,
20528                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
20529   tree v2di_ftype_v2di_v2di
20530     = build_function_type_list (V2DI_type_node,
20531                                 V2DI_type_node, V2DI_type_node, NULL_TREE);
20532   tree v2di_ftype_v2df_v2df
20533     = build_function_type_list (V2DI_type_node,
20534                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
20535   tree v2df_ftype_v2df
20536     = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
20537   tree v2di_ftype_v2di_int
20538     = build_function_type_list (V2DI_type_node,
20539                                 V2DI_type_node, integer_type_node, NULL_TREE);
20540   tree v2di_ftype_v2di_v2di_int
20541     = build_function_type_list (V2DI_type_node, V2DI_type_node,
20542                                 V2DI_type_node, integer_type_node, NULL_TREE);
20543   tree v4si_ftype_v4si_int
20544     = build_function_type_list (V4SI_type_node,
20545                                 V4SI_type_node, integer_type_node, NULL_TREE);
20546   tree v8hi_ftype_v8hi_int
20547     = build_function_type_list (V8HI_type_node,
20548                                 V8HI_type_node, integer_type_node, NULL_TREE);
20549   tree v4si_ftype_v8hi_v8hi
20550     = build_function_type_list (V4SI_type_node,
20551                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
20552   tree v1di_ftype_v8qi_v8qi
20553     = build_function_type_list (V1DI_type_node,
20554                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
20555   tree v1di_ftype_v2si_v2si
20556     = build_function_type_list (V1DI_type_node,
20557                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
20558   tree v2di_ftype_v16qi_v16qi
20559     = build_function_type_list (V2DI_type_node,
20560                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
20561   tree v2di_ftype_v4si_v4si
20562     = build_function_type_list (V2DI_type_node,
20563                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
20564   tree int_ftype_v16qi
20565     = build_function_type_list (integer_type_node, V16QI_type_node, NULL_TREE);
20566   tree v16qi_ftype_pcchar
20567     = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
20568   tree void_ftype_pchar_v16qi
20569     = build_function_type_list (void_type_node,
20570                                 pchar_type_node, V16QI_type_node, NULL_TREE);
20571
20572   tree v2di_ftype_v2di_unsigned_unsigned
20573     = build_function_type_list (V2DI_type_node, V2DI_type_node,
20574                                 unsigned_type_node, unsigned_type_node,
20575                                 NULL_TREE);
20576   tree v2di_ftype_v2di_v2di_unsigned_unsigned
20577     = build_function_type_list (V2DI_type_node, V2DI_type_node, V2DI_type_node,
20578                                 unsigned_type_node, unsigned_type_node,
20579                                 NULL_TREE);
20580   tree v2di_ftype_v2di_v16qi
20581     = build_function_type_list (V2DI_type_node, V2DI_type_node, V16QI_type_node,
20582                                 NULL_TREE);
20583   tree v2df_ftype_v2df_v2df_v2df
20584     = build_function_type_list (V2DF_type_node,
20585                                 V2DF_type_node, V2DF_type_node,
20586                                 V2DF_type_node, NULL_TREE);
20587   tree v4sf_ftype_v4sf_v4sf_v4sf
20588     = build_function_type_list (V4SF_type_node,
20589                                 V4SF_type_node, V4SF_type_node,
20590                                 V4SF_type_node, NULL_TREE);
20591   tree v8hi_ftype_v16qi
20592     = build_function_type_list (V8HI_type_node, V16QI_type_node,
20593                                 NULL_TREE);
20594   tree v4si_ftype_v16qi
20595     = build_function_type_list (V4SI_type_node, V16QI_type_node,
20596                                 NULL_TREE);
20597   tree v2di_ftype_v16qi
20598     = build_function_type_list (V2DI_type_node, V16QI_type_node,
20599                                 NULL_TREE);
20600   tree v4si_ftype_v8hi
20601     = build_function_type_list (V4SI_type_node, V8HI_type_node,
20602                                 NULL_TREE);
20603   tree v2di_ftype_v8hi
20604     = build_function_type_list (V2DI_type_node, V8HI_type_node,
20605                                 NULL_TREE);
20606   tree v2di_ftype_v4si
20607     = build_function_type_list (V2DI_type_node, V4SI_type_node,
20608                                 NULL_TREE);
20609   tree v2di_ftype_pv2di
20610     = build_function_type_list (V2DI_type_node, pv2di_type_node,
20611                                 NULL_TREE);
20612   tree v16qi_ftype_v16qi_v16qi_int
20613     = build_function_type_list (V16QI_type_node, V16QI_type_node,
20614                                 V16QI_type_node, integer_type_node,
20615                                 NULL_TREE);
20616   tree v16qi_ftype_v16qi_v16qi_v16qi
20617     = build_function_type_list (V16QI_type_node, V16QI_type_node,
20618                                 V16QI_type_node, V16QI_type_node,
20619                                 NULL_TREE);
20620   tree v8hi_ftype_v8hi_v8hi_int
20621     = build_function_type_list (V8HI_type_node, V8HI_type_node,
20622                                 V8HI_type_node, integer_type_node,
20623                                 NULL_TREE);
20624   tree v4si_ftype_v4si_v4si_int
20625     = build_function_type_list (V4SI_type_node, V4SI_type_node,
20626                                 V4SI_type_node, integer_type_node,
20627                                 NULL_TREE);
20628   tree int_ftype_v2di_v2di
20629     = build_function_type_list (integer_type_node,
20630                                 V2DI_type_node, V2DI_type_node,
20631                                 NULL_TREE);
20632   tree int_ftype_v16qi_int_v16qi_int_int
20633     = build_function_type_list (integer_type_node,
20634                                 V16QI_type_node,
20635                                 integer_type_node,
20636                                 V16QI_type_node,
20637                                 integer_type_node,
20638                                 integer_type_node,
20639                                 NULL_TREE);
20640   tree v16qi_ftype_v16qi_int_v16qi_int_int
20641     = build_function_type_list (V16QI_type_node,
20642                                 V16QI_type_node,
20643                                 integer_type_node,
20644                                 V16QI_type_node,
20645                                 integer_type_node,
20646                                 integer_type_node,
20647                                 NULL_TREE);
20648   tree int_ftype_v16qi_v16qi_int
20649     = build_function_type_list (integer_type_node,
20650                                 V16QI_type_node,
20651                                 V16QI_type_node,
20652                                 integer_type_node,
20653                                 NULL_TREE);
20654
20655   /* SSE5 instructions */
20656   tree v2di_ftype_v2di_v2di_v2di
20657     = build_function_type_list (V2DI_type_node,
20658                                 V2DI_type_node,
20659                                 V2DI_type_node,
20660                                 V2DI_type_node,
20661                                 NULL_TREE);
20662
20663   tree v4si_ftype_v4si_v4si_v4si
20664     = build_function_type_list (V4SI_type_node,
20665                                 V4SI_type_node,
20666                                 V4SI_type_node,
20667                                 V4SI_type_node,
20668                                 NULL_TREE);
20669
20670   tree v4si_ftype_v4si_v4si_v2di
20671     = build_function_type_list (V4SI_type_node,
20672                                 V4SI_type_node,
20673                                 V4SI_type_node,
20674                                 V2DI_type_node,
20675                                 NULL_TREE);
20676
20677   tree v8hi_ftype_v8hi_v8hi_v8hi
20678     = build_function_type_list (V8HI_type_node,
20679                                 V8HI_type_node,
20680                                 V8HI_type_node,
20681                                 V8HI_type_node,
20682                                 NULL_TREE);
20683
20684   tree v8hi_ftype_v8hi_v8hi_v4si
20685     = build_function_type_list (V8HI_type_node,
20686                                 V8HI_type_node,
20687                                 V8HI_type_node,
20688                                 V4SI_type_node,
20689                                 NULL_TREE);
20690
20691   tree v2df_ftype_v2df_v2df_v16qi
20692     = build_function_type_list (V2DF_type_node,
20693                                 V2DF_type_node,
20694                                 V2DF_type_node,
20695                                 V16QI_type_node,
20696                                 NULL_TREE);
20697
20698   tree v4sf_ftype_v4sf_v4sf_v16qi
20699     = build_function_type_list (V4SF_type_node,
20700                                 V4SF_type_node,
20701                                 V4SF_type_node,
20702                                 V16QI_type_node,
20703                                 NULL_TREE);
20704
20705   tree v2di_ftype_v2di_si
20706     = build_function_type_list (V2DI_type_node,
20707                                 V2DI_type_node,
20708                                 integer_type_node,
20709                                 NULL_TREE);
20710
20711   tree v4si_ftype_v4si_si
20712     = build_function_type_list (V4SI_type_node,
20713                                 V4SI_type_node,
20714                                 integer_type_node,
20715                                 NULL_TREE);
20716
20717   tree v8hi_ftype_v8hi_si
20718     = build_function_type_list (V8HI_type_node,
20719                                 V8HI_type_node,
20720                                 integer_type_node,
20721                                 NULL_TREE);
20722
20723   tree v16qi_ftype_v16qi_si
20724     = build_function_type_list (V16QI_type_node,
20725                                 V16QI_type_node,
20726                                 integer_type_node,
20727                                 NULL_TREE);
20728   tree v4sf_ftype_v4hi
20729     = build_function_type_list (V4SF_type_node,
20730                                 V4HI_type_node,
20731                                 NULL_TREE);
20732
20733   tree v4hi_ftype_v4sf
20734     = build_function_type_list (V4HI_type_node,
20735                                 V4SF_type_node,
20736                                 NULL_TREE);
20737
20738   tree v2di_ftype_v2di
20739     = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
20740
20741   tree v16qi_ftype_v8hi_v8hi
20742     = build_function_type_list (V16QI_type_node,
20743                                 V8HI_type_node, V8HI_type_node,
20744                                 NULL_TREE);
20745   tree v8hi_ftype_v4si_v4si
20746     = build_function_type_list (V8HI_type_node,
20747                                 V4SI_type_node, V4SI_type_node,
20748                                 NULL_TREE);
20749   tree v8hi_ftype_v16qi_v16qi 
20750     = build_function_type_list (V8HI_type_node,
20751                                 V16QI_type_node, V16QI_type_node,
20752                                 NULL_TREE);
20753   tree v4hi_ftype_v8qi_v8qi 
20754     = build_function_type_list (V4HI_type_node,
20755                                 V8QI_type_node, V8QI_type_node,
20756                                 NULL_TREE);
20757   tree unsigned_ftype_unsigned_uchar
20758     = build_function_type_list (unsigned_type_node,
20759                                 unsigned_type_node,
20760                                 unsigned_char_type_node,
20761                                 NULL_TREE);
20762   tree unsigned_ftype_unsigned_ushort
20763     = build_function_type_list (unsigned_type_node,
20764                                 unsigned_type_node,
20765                                 short_unsigned_type_node,
20766                                 NULL_TREE);
20767   tree unsigned_ftype_unsigned_unsigned
20768     = build_function_type_list (unsigned_type_node,
20769                                 unsigned_type_node,
20770                                 unsigned_type_node,
20771                                 NULL_TREE);
20772   tree uint64_ftype_uint64_uint64
20773     = build_function_type_list (long_long_unsigned_type_node,
20774                                 long_long_unsigned_type_node,
20775                                 long_long_unsigned_type_node,
20776                                 NULL_TREE);
20777   tree float_ftype_float
20778     = build_function_type_list (float_type_node,
20779                                 float_type_node,
20780                                 NULL_TREE);
20781
20782   tree ftype;
20783
20784   /* Add all special builtins with variable number of operands.  */
20785   for (i = 0, d = bdesc_special_args;
20786        i < ARRAY_SIZE (bdesc_special_args);
20787        i++, d++)
20788     {
20789       tree type;
20790
20791       if (d->name == 0)
20792         continue;
20793
20794       switch ((enum ix86_special_builtin_type) d->flag)
20795         {
20796         case VOID_FTYPE_VOID:
20797           type = void_ftype_void;
20798           break;
20799         case V16QI_FTYPE_PCCHAR:
20800           type = v16qi_ftype_pcchar;
20801           break;
20802         case V4SF_FTYPE_PCFLOAT:
20803           type = v4sf_ftype_pcfloat;
20804           break;
20805         case V2DI_FTYPE_PV2DI:
20806           type = v2di_ftype_pv2di;
20807           break;
20808         case V2DF_FTYPE_PCDOUBLE:
20809           type = v2df_ftype_pcdouble;
20810           break;
20811         case V4SF_FTYPE_V4SF_PCV2SF:
20812           type = v4sf_ftype_v4sf_pcv2sf;
20813           break;
20814         case V2DF_FTYPE_V2DF_PCDOUBLE:
20815           type = v2df_ftype_v2df_pcdouble;
20816           break;
20817         case VOID_FTYPE_PV2SF_V4SF:
20818           type = void_ftype_pv2sf_v4sf;
20819           break;
20820         case VOID_FTYPE_PV2DI_V2DI:
20821           type = void_ftype_pv2di_v2di;
20822           break;
20823         case VOID_FTYPE_PCHAR_V16QI:
20824           type = void_ftype_pchar_v16qi;
20825           break;
20826         case VOID_FTYPE_PFLOAT_V4SF:
20827           type = void_ftype_pfloat_v4sf;
20828           break;
20829         case VOID_FTYPE_PDOUBLE_V2DF:
20830           type = void_ftype_pdouble_v2df;
20831           break;
20832         case VOID_FTYPE_PDI_DI:
20833           type = void_ftype_pdi_di;
20834           break;
20835         case VOID_FTYPE_PINT_INT:
20836           type = void_ftype_pint_int;
20837           break;
20838         default:
20839           gcc_unreachable ();
20840         }
20841
20842       def_builtin (d->mask, d->name, type, d->code);
20843     }
20844
20845   /* Add all builtins with variable number of operands.  */
20846   for (i = 0, d = bdesc_args;
20847        i < ARRAY_SIZE (bdesc_args);
20848        i++, d++)
20849     {
20850       tree type;
20851
20852       if (d->name == 0)
20853         continue;
20854
20855       switch ((enum ix86_builtin_type) d->flag)
20856         {
20857         case FLOAT_FTYPE_FLOAT:
20858           type = float_ftype_float;
20859           break;
20860         case INT_FTYPE_V2DI_V2DI_PTEST:
20861           type = int_ftype_v2di_v2di;
20862           break;
20863         case INT64_FTYPE_V4SF:
20864           type = int64_ftype_v4sf;
20865           break;
20866         case INT64_FTYPE_V2DF:
20867           type = int64_ftype_v2df;
20868           break;
20869         case INT_FTYPE_V16QI:
20870           type = int_ftype_v16qi;
20871           break;
20872         case INT_FTYPE_V8QI:
20873           type = int_ftype_v8qi;
20874           break;
20875         case INT_FTYPE_V4SF:
20876           type = int_ftype_v4sf;
20877           break;
20878         case INT_FTYPE_V2DF:
20879           type = int_ftype_v2df;
20880           break;
20881         case V16QI_FTYPE_V16QI:
20882           type = v16qi_ftype_v16qi;
20883           break;
20884         case V8HI_FTYPE_V8HI:
20885           type = v8hi_ftype_v8hi;
20886           break;
20887         case V8HI_FTYPE_V16QI:
20888           type = v8hi_ftype_v16qi;
20889           break;
20890         case V8QI_FTYPE_V8QI:
20891           type = v8qi_ftype_v8qi;
20892           break;
20893         case V4SI_FTYPE_V4SI:
20894           type = v4si_ftype_v4si;
20895           break;
20896         case V4SI_FTYPE_V16QI:
20897           type = v4si_ftype_v16qi;
20898           break;
20899         case V4SI_FTYPE_V8HI:
20900           type = v4si_ftype_v8hi;
20901           break;
20902         case V4SI_FTYPE_V4SF:
20903           type = v4si_ftype_v4sf;
20904           break;
20905         case V4SI_FTYPE_V2DF:
20906           type = v4si_ftype_v2df;
20907           break;
20908         case V4HI_FTYPE_V4HI:
20909           type = v4hi_ftype_v4hi;
20910           break;
20911         case V4SF_FTYPE_V4SF:
20912         case V4SF_FTYPE_V4SF_VEC_MERGE:
20913           type = v4sf_ftype_v4sf;
20914           break;
20915         case V4SF_FTYPE_V4SI:
20916           type = v4sf_ftype_v4si;
20917           break;
20918         case V4SF_FTYPE_V2DF:
20919           type = v4sf_ftype_v2df;
20920           break;
20921         case V2DI_FTYPE_V2DI:
20922           type = v2di_ftype_v2di;
20923           break;
20924         case V2DI_FTYPE_V16QI:
20925           type = v2di_ftype_v16qi;
20926           break;
20927         case V2DI_FTYPE_V8HI:
20928           type = v2di_ftype_v8hi;
20929           break;
20930         case V2DI_FTYPE_V4SI:
20931           type = v2di_ftype_v4si;
20932           break;
20933         case V2SI_FTYPE_V2SI:
20934           type = v2si_ftype_v2si;
20935           break;
20936         case V2SI_FTYPE_V4SF:
20937           type = v2si_ftype_v4sf;
20938           break;
20939         case V2SI_FTYPE_V2DF:
20940           type = v2si_ftype_v2df;
20941           break;
20942         case V2SI_FTYPE_V2SF:
20943           type = v2si_ftype_v2sf;
20944           break;
20945         case V2DF_FTYPE_V4SF:
20946           type = v2df_ftype_v4sf;
20947           break;
20948         case V2DF_FTYPE_V2DF:
20949         case V2DF_FTYPE_V2DF_VEC_MERGE:
20950           type = v2df_ftype_v2df;
20951           break;
20952         case V2DF_FTYPE_V2SI:
20953           type = v2df_ftype_v2si;
20954           break;
20955         case V2DF_FTYPE_V4SI:
20956           type = v2df_ftype_v4si;
20957           break;
20958         case V2SF_FTYPE_V2SF:
20959           type = v2sf_ftype_v2sf;
20960           break;
20961         case V2SF_FTYPE_V2SI:
20962           type = v2sf_ftype_v2si;
20963           break;
20964         case V16QI_FTYPE_V16QI_V16QI:
20965           type = v16qi_ftype_v16qi_v16qi;
20966           break;
20967         case V16QI_FTYPE_V8HI_V8HI:
20968           type = v16qi_ftype_v8hi_v8hi;
20969           break;
20970         case V8QI_FTYPE_V8QI_V8QI:
20971           type = v8qi_ftype_v8qi_v8qi;
20972           break;
20973         case V8QI_FTYPE_V4HI_V4HI:
20974           type = v8qi_ftype_v4hi_v4hi;
20975           break;
20976         case V8HI_FTYPE_V8HI_V8HI:
20977         case V8HI_FTYPE_V8HI_V8HI_COUNT:
20978           type = v8hi_ftype_v8hi_v8hi;
20979           break;
20980         case V8HI_FTYPE_V16QI_V16QI:
20981           type = v8hi_ftype_v16qi_v16qi;
20982           break;
20983         case V8HI_FTYPE_V4SI_V4SI:
20984           type = v8hi_ftype_v4si_v4si;
20985           break;
20986         case V8HI_FTYPE_V8HI_SI_COUNT:
20987           type = v8hi_ftype_v8hi_int;
20988           break;
20989         case V4SI_FTYPE_V4SI_V4SI:
20990         case V4SI_FTYPE_V4SI_V4SI_COUNT:
20991           type = v4si_ftype_v4si_v4si;
20992           break;
20993         case V4SI_FTYPE_V8HI_V8HI:
20994           type = v4si_ftype_v8hi_v8hi;
20995           break;
20996         case V4SI_FTYPE_V4SF_V4SF:
20997           type = v4si_ftype_v4sf_v4sf;
20998           break;
20999         case V4SI_FTYPE_V2DF_V2DF:
21000           type = v4si_ftype_v2df_v2df;
21001           break;
21002         case V4SI_FTYPE_V4SI_SI_COUNT:
21003           type = v4si_ftype_v4si_int;
21004           break;
21005         case V4HI_FTYPE_V4HI_V4HI:
21006         case V4HI_FTYPE_V4HI_V4HI_COUNT:
21007           type = v4hi_ftype_v4hi_v4hi;
21008           break;
21009         case V4HI_FTYPE_V8QI_V8QI:
21010           type = v4hi_ftype_v8qi_v8qi;
21011           break;
21012         case V4HI_FTYPE_V2SI_V2SI:
21013           type = v4hi_ftype_v2si_v2si;
21014           break;
21015         case V4HI_FTYPE_V4HI_SI_COUNT:
21016           type = v4hi_ftype_v4hi_int;
21017           break;
21018         case V4SF_FTYPE_V4SF_V4SF:
21019         case V4SF_FTYPE_V4SF_V4SF_SWAP:
21020           type = v4sf_ftype_v4sf_v4sf;
21021           break;
21022         case V4SF_FTYPE_V4SF_V2SI:
21023           type = v4sf_ftype_v4sf_v2si;
21024           break;
21025         case V4SF_FTYPE_V4SF_V2DF:
21026           type = v4sf_ftype_v4sf_v2df;
21027           break;
21028         case V4SF_FTYPE_V4SF_DI:
21029           type = v4sf_ftype_v4sf_int64;
21030           break;
21031         case V4SF_FTYPE_V4SF_SI:
21032           type = v4sf_ftype_v4sf_int;
21033           break;
21034         case V2DI_FTYPE_V2DI_V2DI:
21035         case V2DI_FTYPE_V2DI_V2DI_COUNT:
21036           type = v2di_ftype_v2di_v2di;
21037           break;
21038         case V2DI_FTYPE_V16QI_V16QI:
21039           type = v2di_ftype_v16qi_v16qi;
21040           break;
21041         case V2DI_FTYPE_V4SI_V4SI:
21042           type = v2di_ftype_v4si_v4si;
21043           break;
21044         case V2DI_FTYPE_V2DI_V16QI:
21045           type = v2di_ftype_v2di_v16qi;
21046           break;
21047         case V2DI_FTYPE_V2DF_V2DF:
21048           type = v2di_ftype_v2df_v2df;
21049           break;
21050         case V2DI_FTYPE_V2DI_SI_COUNT:
21051           type = v2di_ftype_v2di_int;
21052           break;
21053         case V2SI_FTYPE_V2SI_V2SI:
21054         case V2SI_FTYPE_V2SI_V2SI_COUNT:
21055           type = v2si_ftype_v2si_v2si;
21056           break;
21057         case V2SI_FTYPE_V4HI_V4HI:
21058           type = v2si_ftype_v4hi_v4hi;
21059           break;
21060         case V2SI_FTYPE_V2SF_V2SF:
21061           type = v2si_ftype_v2sf_v2sf;
21062           break;
21063         case V2SI_FTYPE_V2SI_SI_COUNT:
21064           type = v2si_ftype_v2si_int;
21065           break;
21066         case V2DF_FTYPE_V2DF_V2DF:
21067         case V2DF_FTYPE_V2DF_V2DF_SWAP:
21068           type = v2df_ftype_v2df_v2df;
21069           break;
21070         case V2DF_FTYPE_V2DF_V4SF:
21071           type = v2df_ftype_v2df_v4sf;
21072           break;
21073         case V2DF_FTYPE_V2DF_DI:
21074           type = v2df_ftype_v2df_int64;
21075           break;
21076         case V2DF_FTYPE_V2DF_SI:
21077           type = v2df_ftype_v2df_int;
21078           break;
21079         case V2SF_FTYPE_V2SF_V2SF:
21080           type = v2sf_ftype_v2sf_v2sf;
21081           break;
21082         case V1DI_FTYPE_V1DI_V1DI:
21083         case V1DI_FTYPE_V1DI_V1DI_COUNT:
21084           type = v1di_ftype_v1di_v1di;
21085           break;
21086         case V1DI_FTYPE_V8QI_V8QI:
21087           type = v1di_ftype_v8qi_v8qi;
21088           break;
21089         case V1DI_FTYPE_V2SI_V2SI:
21090           type = v1di_ftype_v2si_v2si;
21091           break;
21092         case V1DI_FTYPE_V1DI_SI_COUNT:
21093           type = v1di_ftype_v1di_int;
21094           break;
21095         case UINT64_FTYPE_UINT64_UINT64:
21096           type = uint64_ftype_uint64_uint64;
21097           break;
21098         case UINT_FTYPE_UINT_UINT:
21099           type = unsigned_ftype_unsigned_unsigned;
21100           break;
21101         case UINT_FTYPE_UINT_USHORT:
21102           type = unsigned_ftype_unsigned_ushort;
21103           break;
21104         case UINT_FTYPE_UINT_UCHAR:
21105           type = unsigned_ftype_unsigned_uchar;
21106           break;
21107         case V8HI_FTYPE_V8HI_INT:
21108           type = v8hi_ftype_v8hi_int;
21109           break;
21110         case V4SI_FTYPE_V4SI_INT:
21111           type = v4si_ftype_v4si_int;
21112           break;
21113         case V4HI_FTYPE_V4HI_INT:
21114           type = v4hi_ftype_v4hi_int;
21115           break;
21116         case V4SF_FTYPE_V4SF_INT:
21117           type = v4sf_ftype_v4sf_int;
21118           break;
21119         case V2DI_FTYPE_V2DI_INT:
21120         case V2DI2TI_FTYPE_V2DI_INT:
21121           type = v2di_ftype_v2di_int;
21122           break;
21123         case V2DF_FTYPE_V2DF_INT:
21124           type = v2df_ftype_v2df_int;
21125           break;
21126         case V16QI_FTYPE_V16QI_V16QI_V16QI:
21127           type = v16qi_ftype_v16qi_v16qi_v16qi;
21128           break;
21129         case V4SF_FTYPE_V4SF_V4SF_V4SF:
21130           type = v4sf_ftype_v4sf_v4sf_v4sf;
21131           break;
21132         case V2DF_FTYPE_V2DF_V2DF_V2DF:
21133           type = v2df_ftype_v2df_v2df_v2df;
21134           break;
21135         case V16QI_FTYPE_V16QI_V16QI_INT:
21136           type = v16qi_ftype_v16qi_v16qi_int;
21137           break;
21138         case V8HI_FTYPE_V8HI_V8HI_INT:
21139           type = v8hi_ftype_v8hi_v8hi_int;
21140           break;
21141         case V4SI_FTYPE_V4SI_V4SI_INT:
21142           type = v4si_ftype_v4si_v4si_int;
21143           break;
21144         case V4SF_FTYPE_V4SF_V4SF_INT:
21145           type = v4sf_ftype_v4sf_v4sf_int;
21146           break;
21147         case V2DI_FTYPE_V2DI_V2DI_INT:
21148         case V2DI2TI_FTYPE_V2DI_V2DI_INT:
21149           type = v2di_ftype_v2di_v2di_int;
21150           break;
21151         case V2DF_FTYPE_V2DF_V2DF_INT:
21152           type = v2df_ftype_v2df_v2df_int;
21153           break;
21154         case V2DI_FTYPE_V2DI_UINT_UINT:
21155           type = v2di_ftype_v2di_unsigned_unsigned;
21156           break;
21157         case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
21158           type = v2di_ftype_v2di_v2di_unsigned_unsigned;
21159           break;
21160         case V1DI2DI_FTYPE_V1DI_V1DI_INT:
21161           type = v1di_ftype_v1di_v1di_int;
21162           break;
21163         default:
21164           gcc_unreachable ();
21165         }
21166
21167       def_builtin_const (d->mask, d->name, type, d->code);
21168     }
21169
21170   /* pcmpestr[im] insns.  */
21171   for (i = 0, d = bdesc_pcmpestr;
21172        i < ARRAY_SIZE (bdesc_pcmpestr);
21173        i++, d++)
21174     {
21175       if (d->code == IX86_BUILTIN_PCMPESTRM128)
21176         ftype = v16qi_ftype_v16qi_int_v16qi_int_int;
21177       else
21178         ftype = int_ftype_v16qi_int_v16qi_int_int;
21179       def_builtin_const (d->mask, d->name, ftype, d->code);
21180     }
21181
21182   /* pcmpistr[im] insns.  */
21183   for (i = 0, d = bdesc_pcmpistr;
21184        i < ARRAY_SIZE (bdesc_pcmpistr);
21185        i++, d++)
21186     {
21187       if (d->code == IX86_BUILTIN_PCMPISTRM128)
21188         ftype = v16qi_ftype_v16qi_v16qi_int;
21189       else
21190         ftype = int_ftype_v16qi_v16qi_int;
21191       def_builtin_const (d->mask, d->name, ftype, d->code);
21192     }
21193
21194   /* comi/ucomi insns.  */
21195   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
21196     if (d->mask == OPTION_MASK_ISA_SSE2)
21197       def_builtin_const (d->mask, d->name, int_ftype_v2df_v2df, d->code);
21198     else
21199       def_builtin_const (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
21200
21201   /* SSE */
21202   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr", void_ftype_unsigned, IX86_BUILTIN_LDMXCSR);
21203   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr", unsigned_ftype_void, IX86_BUILTIN_STMXCSR);
21204
21205   /* SSE or 3DNow!A */
21206   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_maskmovq", void_ftype_v8qi_v8qi_pchar, IX86_BUILTIN_MASKMOVQ);
21207
21208   /* SSE2 */
21209   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu", void_ftype_v16qi_v16qi_pchar, IX86_BUILTIN_MASKMOVDQU);
21210
21211   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush", void_ftype_pcvoid, IX86_BUILTIN_CLFLUSH);
21212   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence", void_ftype_void, IX86_BUILTIN_MFENCE);
21213
21214   /* SSE3.  */
21215   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor", void_ftype_pcvoid_unsigned_unsigned, IX86_BUILTIN_MONITOR);
21216   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait", void_ftype_unsigned_unsigned, IX86_BUILTIN_MWAIT);
21217
21218   /* AES */
21219   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENC128);
21220   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENCLAST128);
21221   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDEC128);
21222   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDECLAST128);
21223   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128", v2di_ftype_v2di, IX86_BUILTIN_AESIMC128);
21224   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128", v2di_ftype_v2di_int, IX86_BUILTIN_AESKEYGENASSIST128);
21225
21226   /* PCLMUL */
21227   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128", v2di_ftype_v2di_v2di_int, IX86_BUILTIN_PCLMULQDQ128);
21228
21229   /* Access to the vec_init patterns.  */
21230   ftype = build_function_type_list (V2SI_type_node, integer_type_node,
21231                                     integer_type_node, NULL_TREE);
21232   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si", ftype, IX86_BUILTIN_VEC_INIT_V2SI);
21233
21234   ftype = build_function_type_list (V4HI_type_node, short_integer_type_node,
21235                                     short_integer_type_node,
21236                                     short_integer_type_node,
21237                                     short_integer_type_node, NULL_TREE);
21238   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi", ftype, IX86_BUILTIN_VEC_INIT_V4HI);
21239
21240   ftype = build_function_type_list (V8QI_type_node, char_type_node,
21241                                     char_type_node, char_type_node,
21242                                     char_type_node, char_type_node,
21243                                     char_type_node, char_type_node,
21244                                     char_type_node, NULL_TREE);
21245   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi", ftype, IX86_BUILTIN_VEC_INIT_V8QI);
21246
21247   /* Access to the vec_extract patterns.  */
21248   ftype = build_function_type_list (double_type_node, V2DF_type_node,
21249                                     integer_type_node, NULL_TREE);
21250   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df", ftype, IX86_BUILTIN_VEC_EXT_V2DF);
21251
21252   ftype = build_function_type_list (long_long_integer_type_node,
21253                                     V2DI_type_node, integer_type_node,
21254                                     NULL_TREE);
21255   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di", ftype, IX86_BUILTIN_VEC_EXT_V2DI);
21256
21257   ftype = build_function_type_list (float_type_node, V4SF_type_node,
21258                                     integer_type_node, NULL_TREE);
21259   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf", ftype, IX86_BUILTIN_VEC_EXT_V4SF);
21260
21261   ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
21262                                     integer_type_node, NULL_TREE);
21263   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si", ftype, IX86_BUILTIN_VEC_EXT_V4SI);
21264
21265   ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
21266                                     integer_type_node, NULL_TREE);
21267   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi", ftype, IX86_BUILTIN_VEC_EXT_V8HI);
21268
21269   ftype = build_function_type_list (intHI_type_node, V4HI_type_node,
21270                                     integer_type_node, NULL_TREE);
21271   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_ext_v4hi", ftype, IX86_BUILTIN_VEC_EXT_V4HI);
21272
21273   ftype = build_function_type_list (intSI_type_node, V2SI_type_node,
21274                                     integer_type_node, NULL_TREE);
21275   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si", ftype, IX86_BUILTIN_VEC_EXT_V2SI);
21276
21277   ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
21278                                     integer_type_node, NULL_TREE);
21279   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi", ftype, IX86_BUILTIN_VEC_EXT_V16QI);
21280
21281   /* Access to the vec_set patterns.  */
21282   ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
21283                                     intDI_type_node,
21284                                     integer_type_node, NULL_TREE);
21285   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_vec_set_v2di", ftype, IX86_BUILTIN_VEC_SET_V2DI);
21286
21287   ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
21288                                     float_type_node,
21289                                     integer_type_node, NULL_TREE);
21290   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf", ftype, IX86_BUILTIN_VEC_SET_V4SF);
21291
21292   ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
21293                                     intSI_type_node,
21294                                     integer_type_node, NULL_TREE);
21295   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si", ftype, IX86_BUILTIN_VEC_SET_V4SI);
21296
21297   ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
21298                                     intHI_type_node,
21299                                     integer_type_node, NULL_TREE);
21300   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi", ftype, IX86_BUILTIN_VEC_SET_V8HI);
21301
21302   ftype = build_function_type_list (V4HI_type_node, V4HI_type_node,
21303                                     intHI_type_node,
21304                                     integer_type_node, NULL_TREE);
21305   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_set_v4hi", ftype, IX86_BUILTIN_VEC_SET_V4HI);
21306
21307   ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
21308                                     intQI_type_node,
21309                                     integer_type_node, NULL_TREE);
21310   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi", ftype, IX86_BUILTIN_VEC_SET_V16QI);
21311
21312   /* Add SSE5 multi-arg argument instructions */
21313   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
21314     {
21315       tree mtype = NULL_TREE;
21316
21317       if (d->name == 0)
21318         continue;
21319
21320       switch ((enum multi_arg_type)d->flag)
21321         {
21322         case MULTI_ARG_3_SF:     mtype = v4sf_ftype_v4sf_v4sf_v4sf;     break;
21323         case MULTI_ARG_3_DF:     mtype = v2df_ftype_v2df_v2df_v2df;     break;
21324         case MULTI_ARG_3_DI:     mtype = v2di_ftype_v2di_v2di_v2di;     break;
21325         case MULTI_ARG_3_SI:     mtype = v4si_ftype_v4si_v4si_v4si;     break;
21326         case MULTI_ARG_3_SI_DI:  mtype = v4si_ftype_v4si_v4si_v2di;     break;
21327         case MULTI_ARG_3_HI:     mtype = v8hi_ftype_v8hi_v8hi_v8hi;     break;
21328         case MULTI_ARG_3_HI_SI:  mtype = v8hi_ftype_v8hi_v8hi_v4si;     break;
21329         case MULTI_ARG_3_QI:     mtype = v16qi_ftype_v16qi_v16qi_v16qi; break;
21330         case MULTI_ARG_3_PERMPS: mtype = v4sf_ftype_v4sf_v4sf_v16qi;    break;
21331         case MULTI_ARG_3_PERMPD: mtype = v2df_ftype_v2df_v2df_v16qi;    break;
21332         case MULTI_ARG_2_SF:     mtype = v4sf_ftype_v4sf_v4sf;          break;
21333         case MULTI_ARG_2_DF:     mtype = v2df_ftype_v2df_v2df;          break;
21334         case MULTI_ARG_2_DI:     mtype = v2di_ftype_v2di_v2di;          break;
21335         case MULTI_ARG_2_SI:     mtype = v4si_ftype_v4si_v4si;          break;
21336         case MULTI_ARG_2_HI:     mtype = v8hi_ftype_v8hi_v8hi;          break;
21337         case MULTI_ARG_2_QI:     mtype = v16qi_ftype_v16qi_v16qi;       break;
21338         case MULTI_ARG_2_DI_IMM: mtype = v2di_ftype_v2di_si;            break;
21339         case MULTI_ARG_2_SI_IMM: mtype = v4si_ftype_v4si_si;            break;
21340         case MULTI_ARG_2_HI_IMM: mtype = v8hi_ftype_v8hi_si;            break;
21341         case MULTI_ARG_2_QI_IMM: mtype = v16qi_ftype_v16qi_si;          break;
21342         case MULTI_ARG_2_SF_CMP: mtype = v4sf_ftype_v4sf_v4sf;          break;
21343         case MULTI_ARG_2_DF_CMP: mtype = v2df_ftype_v2df_v2df;          break;
21344         case MULTI_ARG_2_DI_CMP: mtype = v2di_ftype_v2di_v2di;          break;
21345         case MULTI_ARG_2_SI_CMP: mtype = v4si_ftype_v4si_v4si;          break;
21346         case MULTI_ARG_2_HI_CMP: mtype = v8hi_ftype_v8hi_v8hi;          break;
21347         case MULTI_ARG_2_QI_CMP: mtype = v16qi_ftype_v16qi_v16qi;       break;
21348         case MULTI_ARG_2_SF_TF:  mtype = v4sf_ftype_v4sf_v4sf;          break;
21349         case MULTI_ARG_2_DF_TF:  mtype = v2df_ftype_v2df_v2df;          break;
21350         case MULTI_ARG_2_DI_TF:  mtype = v2di_ftype_v2di_v2di;          break;
21351         case MULTI_ARG_2_SI_TF:  mtype = v4si_ftype_v4si_v4si;          break;
21352         case MULTI_ARG_2_HI_TF:  mtype = v8hi_ftype_v8hi_v8hi;          break;
21353         case MULTI_ARG_2_QI_TF:  mtype = v16qi_ftype_v16qi_v16qi;       break;
21354         case MULTI_ARG_1_SF:     mtype = v4sf_ftype_v4sf;               break;
21355         case MULTI_ARG_1_DF:     mtype = v2df_ftype_v2df;               break;
21356         case MULTI_ARG_1_DI:     mtype = v2di_ftype_v2di;               break;
21357         case MULTI_ARG_1_SI:     mtype = v4si_ftype_v4si;               break;
21358         case MULTI_ARG_1_HI:     mtype = v8hi_ftype_v8hi;               break;
21359         case MULTI_ARG_1_QI:     mtype = v16qi_ftype_v16qi;             break;
21360         case MULTI_ARG_1_SI_DI:  mtype = v2di_ftype_v4si;               break;
21361         case MULTI_ARG_1_HI_DI:  mtype = v2di_ftype_v8hi;               break;
21362         case MULTI_ARG_1_HI_SI:  mtype = v4si_ftype_v8hi;               break;
21363         case MULTI_ARG_1_QI_DI:  mtype = v2di_ftype_v16qi;              break;
21364         case MULTI_ARG_1_QI_SI:  mtype = v4si_ftype_v16qi;              break;
21365         case MULTI_ARG_1_QI_HI:  mtype = v8hi_ftype_v16qi;              break;
21366         case MULTI_ARG_1_PH2PS:  mtype = v4sf_ftype_v4hi;               break;
21367         case MULTI_ARG_1_PS2PH:  mtype = v4hi_ftype_v4sf;               break;
21368         case MULTI_ARG_UNKNOWN:
21369         default:
21370           gcc_unreachable ();
21371         }
21372
21373       if (mtype)
21374         def_builtin_const (d->mask, d->name, mtype, d->code);
21375     }
21376 }
21377
21378 /* Internal method for ix86_init_builtins.  */
21379
21380 static void
21381 ix86_init_builtins_va_builtins_abi (void)
21382 {
21383   tree ms_va_ref, sysv_va_ref;
21384   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
21385   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
21386   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
21387   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
21388
21389   if (!TARGET_64BIT)
21390     return;
21391   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
21392   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
21393   ms_va_ref = build_reference_type (ms_va_list_type_node);
21394   sysv_va_ref =
21395     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
21396
21397   fnvoid_va_end_ms =
21398     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
21399   fnvoid_va_start_ms =
21400     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
21401   fnvoid_va_end_sysv =
21402     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
21403   fnvoid_va_start_sysv =
21404     build_varargs_function_type_list (void_type_node, sysv_va_ref,
21405                                        NULL_TREE);
21406   fnvoid_va_copy_ms =
21407     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
21408                               NULL_TREE);
21409   fnvoid_va_copy_sysv =
21410     build_function_type_list (void_type_node, sysv_va_ref,
21411                               sysv_va_ref, NULL_TREE);
21412
21413   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
21414                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
21415   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
21416                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
21417   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
21418                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
21419   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
21420                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
21421   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
21422                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
21423   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
21424                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
21425 }
21426
21427 static void
21428 ix86_init_builtins (void)
21429 {
21430   tree float128_type_node = make_node (REAL_TYPE);
21431   tree ftype, decl;
21432
21433   /* The __float80 type.  */
21434   if (TYPE_MODE (long_double_type_node) == XFmode)
21435     (*lang_hooks.types.register_builtin_type) (long_double_type_node,
21436                                                "__float80");
21437   else
21438     {
21439       /* The __float80 type.  */
21440       tree float80_type_node = make_node (REAL_TYPE);
21441
21442       TYPE_PRECISION (float80_type_node) = 80;
21443       layout_type (float80_type_node);
21444       (*lang_hooks.types.register_builtin_type) (float80_type_node,
21445                                                  "__float80");
21446     }
21447
21448   /* The __float128 type.  */
21449   TYPE_PRECISION (float128_type_node) = 128;
21450   layout_type (float128_type_node);
21451   (*lang_hooks.types.register_builtin_type) (float128_type_node,
21452                                              "__float128");
21453
21454   /* TFmode support builtins.  */
21455   ftype = build_function_type (float128_type_node, void_list_node);
21456   decl = add_builtin_function ("__builtin_infq", ftype,
21457                                IX86_BUILTIN_INFQ, BUILT_IN_MD,
21458                                NULL, NULL_TREE);
21459   ix86_builtins[(int) IX86_BUILTIN_INFQ] = decl;
21460
21461   /* We will expand them to normal call if SSE2 isn't available since
21462      they are used by libgcc. */
21463   ftype = build_function_type_list (float128_type_node,
21464                                     float128_type_node,
21465                                     NULL_TREE);
21466   decl = add_builtin_function ("__builtin_fabsq", ftype,
21467                                IX86_BUILTIN_FABSQ, BUILT_IN_MD,
21468                                "__fabstf2", NULL_TREE);
21469   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = decl;
21470   TREE_READONLY (decl) = 1;
21471
21472   ftype = build_function_type_list (float128_type_node,
21473                                     float128_type_node,
21474                                     float128_type_node,
21475                                     NULL_TREE);
21476   decl = add_builtin_function ("__builtin_copysignq", ftype,
21477                                IX86_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
21478                                "__copysigntf3", NULL_TREE);
21479   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = decl;
21480   TREE_READONLY (decl) = 1;
21481
21482   ix86_init_mmx_sse_builtins ();
21483   if (TARGET_64BIT)
21484     ix86_init_builtins_va_builtins_abi ();
21485 }
21486
21487 /* Errors in the source file can cause expand_expr to return const0_rtx
21488    where we expect a vector.  To avoid crashing, use one of the vector
21489    clear instructions.  */
21490 static rtx
21491 safe_vector_operand (rtx x, enum machine_mode mode)
21492 {
21493   if (x == const0_rtx)
21494     x = CONST0_RTX (mode);
21495   return x;
21496 }
21497
21498 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
21499
21500 static rtx
21501 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
21502 {
21503   rtx pat;
21504   tree arg0 = CALL_EXPR_ARG (exp, 0);
21505   tree arg1 = CALL_EXPR_ARG (exp, 1);
21506   rtx op0 = expand_normal (arg0);
21507   rtx op1 = expand_normal (arg1);
21508   enum machine_mode tmode = insn_data[icode].operand[0].mode;
21509   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
21510   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
21511
21512   if (VECTOR_MODE_P (mode0))
21513     op0 = safe_vector_operand (op0, mode0);
21514   if (VECTOR_MODE_P (mode1))
21515     op1 = safe_vector_operand (op1, mode1);
21516
21517   if (optimize || !target
21518       || GET_MODE (target) != tmode
21519       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
21520     target = gen_reg_rtx (tmode);
21521
21522   if (GET_MODE (op1) == SImode && mode1 == TImode)
21523     {
21524       rtx x = gen_reg_rtx (V4SImode);
21525       emit_insn (gen_sse2_loadd (x, op1));
21526       op1 = gen_lowpart (TImode, x);
21527     }
21528
21529   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
21530     op0 = copy_to_mode_reg (mode0, op0);
21531   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
21532     op1 = copy_to_mode_reg (mode1, op1);
21533
21534   pat = GEN_FCN (icode) (target, op0, op1);
21535   if (! pat)
21536     return 0;
21537
21538   emit_insn (pat);
21539
21540   return target;
21541 }
21542
21543 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
21544
21545 static rtx
21546 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
21547                                enum multi_arg_type m_type,
21548                                enum insn_code sub_code)
21549 {
21550   rtx pat;
21551   int i;
21552   int nargs;
21553   bool comparison_p = false;
21554   bool tf_p = false;
21555   bool last_arg_constant = false;
21556   int num_memory = 0;
21557   struct {
21558     rtx op;
21559     enum machine_mode mode;
21560   } args[4];
21561
21562   enum machine_mode tmode = insn_data[icode].operand[0].mode;
21563
21564   switch (m_type)
21565     {
21566     case MULTI_ARG_3_SF:
21567     case MULTI_ARG_3_DF:
21568     case MULTI_ARG_3_DI:
21569     case MULTI_ARG_3_SI:
21570     case MULTI_ARG_3_SI_DI:
21571     case MULTI_ARG_3_HI:
21572     case MULTI_ARG_3_HI_SI:
21573     case MULTI_ARG_3_QI:
21574     case MULTI_ARG_3_PERMPS:
21575     case MULTI_ARG_3_PERMPD:
21576       nargs = 3;
21577       break;
21578
21579     case MULTI_ARG_2_SF:
21580     case MULTI_ARG_2_DF:
21581     case MULTI_ARG_2_DI:
21582     case MULTI_ARG_2_SI:
21583     case MULTI_ARG_2_HI:
21584     case MULTI_ARG_2_QI:
21585       nargs = 2;
21586       break;
21587
21588     case MULTI_ARG_2_DI_IMM:
21589     case MULTI_ARG_2_SI_IMM:
21590     case MULTI_ARG_2_HI_IMM:
21591     case MULTI_ARG_2_QI_IMM:
21592       nargs = 2;
21593       last_arg_constant = true;
21594       break;
21595
21596     case MULTI_ARG_1_SF:
21597     case MULTI_ARG_1_DF:
21598     case MULTI_ARG_1_DI:
21599     case MULTI_ARG_1_SI:
21600     case MULTI_ARG_1_HI:
21601     case MULTI_ARG_1_QI:
21602     case MULTI_ARG_1_SI_DI:
21603     case MULTI_ARG_1_HI_DI:
21604     case MULTI_ARG_1_HI_SI:
21605     case MULTI_ARG_1_QI_DI:
21606     case MULTI_ARG_1_QI_SI:
21607     case MULTI_ARG_1_QI_HI:
21608     case MULTI_ARG_1_PH2PS:
21609     case MULTI_ARG_1_PS2PH:
21610       nargs = 1;
21611       break;
21612
21613     case MULTI_ARG_2_SF_CMP:
21614     case MULTI_ARG_2_DF_CMP:
21615     case MULTI_ARG_2_DI_CMP:
21616     case MULTI_ARG_2_SI_CMP:
21617     case MULTI_ARG_2_HI_CMP:
21618     case MULTI_ARG_2_QI_CMP:
21619       nargs = 2;
21620       comparison_p = true;
21621       break;
21622
21623     case MULTI_ARG_2_SF_TF:
21624     case MULTI_ARG_2_DF_TF:
21625     case MULTI_ARG_2_DI_TF:
21626     case MULTI_ARG_2_SI_TF:
21627     case MULTI_ARG_2_HI_TF:
21628     case MULTI_ARG_2_QI_TF:
21629       nargs = 2;
21630       tf_p = true;
21631       break;
21632
21633     case MULTI_ARG_UNKNOWN:
21634     default:
21635       gcc_unreachable ();
21636     }
21637
21638   if (optimize || !target
21639       || GET_MODE (target) != tmode
21640       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
21641     target = gen_reg_rtx (tmode);
21642
21643   gcc_assert (nargs <= 4);
21644
21645   for (i = 0; i < nargs; i++)
21646     {
21647       tree arg = CALL_EXPR_ARG (exp, i);
21648       rtx op = expand_normal (arg);
21649       int adjust = (comparison_p) ? 1 : 0;
21650       enum machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
21651
21652       if (last_arg_constant && i == nargs-1)
21653         {
21654           if (GET_CODE (op) != CONST_INT)
21655             {
21656               error ("last argument must be an immediate");
21657               return gen_reg_rtx (tmode);
21658             }
21659         }
21660       else
21661         {
21662           if (VECTOR_MODE_P (mode))
21663             op = safe_vector_operand (op, mode);
21664
21665           /* If we aren't optimizing, only allow one memory operand to be
21666              generated.  */
21667           if (memory_operand (op, mode))
21668             num_memory++;
21669
21670           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
21671
21672           if (optimize
21673               || ! (*insn_data[icode].operand[i+adjust+1].predicate) (op, mode)
21674               || num_memory > 1)
21675             op = force_reg (mode, op);
21676         }
21677
21678       args[i].op = op;
21679       args[i].mode = mode;
21680     }
21681
21682   switch (nargs)
21683     {
21684     case 1:
21685       pat = GEN_FCN (icode) (target, args[0].op);
21686       break;
21687
21688     case 2:
21689       if (tf_p)
21690         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
21691                                GEN_INT ((int)sub_code));
21692       else if (! comparison_p)
21693         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
21694       else
21695         {
21696           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
21697                                        args[0].op,
21698                                        args[1].op);
21699
21700           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
21701         }
21702       break;
21703
21704     case 3:
21705       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
21706       break;
21707
21708     default:
21709       gcc_unreachable ();
21710     }
21711
21712   if (! pat)
21713     return 0;
21714
21715   emit_insn (pat);
21716   return target;
21717 }
21718
21719 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
21720    insns with vec_merge.  */
21721
21722 static rtx
21723 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
21724                                     rtx target)
21725 {
21726   rtx pat;
21727   tree arg0 = CALL_EXPR_ARG (exp, 0);
21728   rtx op1, op0 = expand_normal (arg0);
21729   enum machine_mode tmode = insn_data[icode].operand[0].mode;
21730   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
21731
21732   if (optimize || !target
21733       || GET_MODE (target) != tmode
21734       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
21735     target = gen_reg_rtx (tmode);
21736
21737   if (VECTOR_MODE_P (mode0))
21738     op0 = safe_vector_operand (op0, mode0);
21739
21740   if ((optimize && !register_operand (op0, mode0))
21741       || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
21742     op0 = copy_to_mode_reg (mode0, op0);
21743
21744   op1 = op0;
21745   if (! (*insn_data[icode].operand[2].predicate) (op1, mode0))
21746     op1 = copy_to_mode_reg (mode0, op1);
21747
21748   pat = GEN_FCN (icode) (target, op0, op1);
21749   if (! pat)
21750     return 0;
21751   emit_insn (pat);
21752   return target;
21753 }
21754
21755 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
21756
21757 static rtx
21758 ix86_expand_sse_compare (const struct builtin_description *d,
21759                          tree exp, rtx target, bool swap)
21760 {
21761   rtx pat;
21762   tree arg0 = CALL_EXPR_ARG (exp, 0);
21763   tree arg1 = CALL_EXPR_ARG (exp, 1);
21764   rtx op0 = expand_normal (arg0);
21765   rtx op1 = expand_normal (arg1);
21766   rtx op2;
21767   enum machine_mode tmode = insn_data[d->icode].operand[0].mode;
21768   enum machine_mode mode0 = insn_data[d->icode].operand[1].mode;
21769   enum machine_mode mode1 = insn_data[d->icode].operand[2].mode;
21770   enum rtx_code comparison = d->comparison;
21771
21772   if (VECTOR_MODE_P (mode0))
21773     op0 = safe_vector_operand (op0, mode0);
21774   if (VECTOR_MODE_P (mode1))
21775     op1 = safe_vector_operand (op1, mode1);
21776
21777   /* Swap operands if we have a comparison that isn't available in
21778      hardware.  */
21779   if (swap)
21780     {
21781       rtx tmp = gen_reg_rtx (mode1);
21782       emit_move_insn (tmp, op1);
21783       op1 = op0;
21784       op0 = tmp;
21785     }
21786
21787   if (optimize || !target
21788       || GET_MODE (target) != tmode
21789       || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode))
21790     target = gen_reg_rtx (tmode);
21791
21792   if ((optimize && !register_operand (op0, mode0))
21793       || ! (*insn_data[d->icode].operand[1].predicate) (op0, mode0))
21794     op0 = copy_to_mode_reg (mode0, op0);
21795   if ((optimize && !register_operand (op1, mode1))
21796       || ! (*insn_data[d->icode].operand[2].predicate) (op1, mode1))
21797     op1 = copy_to_mode_reg (mode1, op1);
21798
21799   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
21800   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
21801   if (! pat)
21802     return 0;
21803   emit_insn (pat);
21804   return target;
21805 }
21806
21807 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
21808
21809 static rtx
21810 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
21811                       rtx target)
21812 {
21813   rtx pat;
21814   tree arg0 = CALL_EXPR_ARG (exp, 0);
21815   tree arg1 = CALL_EXPR_ARG (exp, 1);
21816   rtx op0 = expand_normal (arg0);
21817   rtx op1 = expand_normal (arg1);
21818   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
21819   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
21820   enum rtx_code comparison = d->comparison;
21821
21822   if (VECTOR_MODE_P (mode0))
21823     op0 = safe_vector_operand (op0, mode0);
21824   if (VECTOR_MODE_P (mode1))
21825     op1 = safe_vector_operand (op1, mode1);
21826
21827   /* Swap operands if we have a comparison that isn't available in
21828      hardware.  */
21829   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
21830     {
21831       rtx tmp = op1;
21832       op1 = op0;
21833       op0 = tmp;
21834     }
21835
21836   target = gen_reg_rtx (SImode);
21837   emit_move_insn (target, const0_rtx);
21838   target = gen_rtx_SUBREG (QImode, target, 0);
21839
21840   if ((optimize && !register_operand (op0, mode0))
21841       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
21842     op0 = copy_to_mode_reg (mode0, op0);
21843   if ((optimize && !register_operand (op1, mode1))
21844       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
21845     op1 = copy_to_mode_reg (mode1, op1);
21846
21847   pat = GEN_FCN (d->icode) (op0, op1);
21848   if (! pat)
21849     return 0;
21850   emit_insn (pat);
21851   emit_insn (gen_rtx_SET (VOIDmode,
21852                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
21853                           gen_rtx_fmt_ee (comparison, QImode,
21854                                           SET_DEST (pat),
21855                                           const0_rtx)));
21856
21857   return SUBREG_REG (target);
21858 }
21859
21860 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
21861
21862 static rtx
21863 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
21864                        rtx target)
21865 {
21866   rtx pat;
21867   tree arg0 = CALL_EXPR_ARG (exp, 0);
21868   tree arg1 = CALL_EXPR_ARG (exp, 1);
21869   rtx op0 = expand_normal (arg0);
21870   rtx op1 = expand_normal (arg1);
21871   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
21872   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
21873   enum rtx_code comparison = d->comparison;
21874
21875   if (VECTOR_MODE_P (mode0))
21876     op0 = safe_vector_operand (op0, mode0);
21877   if (VECTOR_MODE_P (mode1))
21878     op1 = safe_vector_operand (op1, mode1);
21879
21880   target = gen_reg_rtx (SImode);
21881   emit_move_insn (target, const0_rtx);
21882   target = gen_rtx_SUBREG (QImode, target, 0);
21883
21884   if ((optimize && !register_operand (op0, mode0))
21885       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
21886     op0 = copy_to_mode_reg (mode0, op0);
21887   if ((optimize && !register_operand (op1, mode1))
21888       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
21889     op1 = copy_to_mode_reg (mode1, op1);
21890
21891   pat = GEN_FCN (d->icode) (op0, op1);
21892   if (! pat)
21893     return 0;
21894   emit_insn (pat);
21895   emit_insn (gen_rtx_SET (VOIDmode,
21896                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
21897                           gen_rtx_fmt_ee (comparison, QImode,
21898                                           SET_DEST (pat),
21899                                           const0_rtx)));
21900
21901   return SUBREG_REG (target);
21902 }
21903
21904 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
21905
21906 static rtx
21907 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
21908                           tree exp, rtx target)
21909 {
21910   rtx pat;
21911   tree arg0 = CALL_EXPR_ARG (exp, 0);
21912   tree arg1 = CALL_EXPR_ARG (exp, 1);
21913   tree arg2 = CALL_EXPR_ARG (exp, 2);
21914   tree arg3 = CALL_EXPR_ARG (exp, 3);
21915   tree arg4 = CALL_EXPR_ARG (exp, 4);
21916   rtx scratch0, scratch1;
21917   rtx op0 = expand_normal (arg0);
21918   rtx op1 = expand_normal (arg1);
21919   rtx op2 = expand_normal (arg2);
21920   rtx op3 = expand_normal (arg3);
21921   rtx op4 = expand_normal (arg4);
21922   enum machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
21923
21924   tmode0 = insn_data[d->icode].operand[0].mode;
21925   tmode1 = insn_data[d->icode].operand[1].mode;
21926   modev2 = insn_data[d->icode].operand[2].mode;
21927   modei3 = insn_data[d->icode].operand[3].mode;
21928   modev4 = insn_data[d->icode].operand[4].mode;
21929   modei5 = insn_data[d->icode].operand[5].mode;
21930   modeimm = insn_data[d->icode].operand[6].mode;
21931
21932   if (VECTOR_MODE_P (modev2))
21933     op0 = safe_vector_operand (op0, modev2);
21934   if (VECTOR_MODE_P (modev4))
21935     op2 = safe_vector_operand (op2, modev4);
21936
21937   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
21938     op0 = copy_to_mode_reg (modev2, op0);
21939   if (! (*insn_data[d->icode].operand[3].predicate) (op1, modei3))
21940     op1 = copy_to_mode_reg (modei3, op1);
21941   if ((optimize && !register_operand (op2, modev4))
21942       || !(*insn_data[d->icode].operand[4].predicate) (op2, modev4))
21943     op2 = copy_to_mode_reg (modev4, op2);
21944   if (! (*insn_data[d->icode].operand[5].predicate) (op3, modei5))
21945     op3 = copy_to_mode_reg (modei5, op3);
21946
21947   if (! (*insn_data[d->icode].operand[6].predicate) (op4, modeimm))
21948     {
21949       error ("the fifth argument must be a 8-bit immediate");
21950       return const0_rtx;
21951     }
21952
21953   if (d->code == IX86_BUILTIN_PCMPESTRI128)
21954     {
21955       if (optimize || !target
21956           || GET_MODE (target) != tmode0
21957           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
21958         target = gen_reg_rtx (tmode0);
21959
21960       scratch1 = gen_reg_rtx (tmode1);
21961
21962       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
21963     }
21964   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
21965     {
21966       if (optimize || !target
21967           || GET_MODE (target) != tmode1
21968           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
21969         target = gen_reg_rtx (tmode1);
21970
21971       scratch0 = gen_reg_rtx (tmode0);
21972
21973       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
21974     }
21975   else
21976     {
21977       gcc_assert (d->flag);
21978
21979       scratch0 = gen_reg_rtx (tmode0);
21980       scratch1 = gen_reg_rtx (tmode1);
21981
21982       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
21983     }
21984
21985   if (! pat)
21986     return 0;
21987
21988   emit_insn (pat);
21989
21990   if (d->flag)
21991     {
21992       target = gen_reg_rtx (SImode);
21993       emit_move_insn (target, const0_rtx);
21994       target = gen_rtx_SUBREG (QImode, target, 0);
21995
21996       emit_insn
21997         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
21998                       gen_rtx_fmt_ee (EQ, QImode,
21999                                       gen_rtx_REG ((enum machine_mode) d->flag,
22000                                                    FLAGS_REG),
22001                                       const0_rtx)));
22002       return SUBREG_REG (target);
22003     }
22004   else
22005     return target;
22006 }
22007
22008
22009 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
22010
22011 static rtx
22012 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
22013                           tree exp, rtx target)
22014 {
22015   rtx pat;
22016   tree arg0 = CALL_EXPR_ARG (exp, 0);
22017   tree arg1 = CALL_EXPR_ARG (exp, 1);
22018   tree arg2 = CALL_EXPR_ARG (exp, 2);
22019   rtx scratch0, scratch1;
22020   rtx op0 = expand_normal (arg0);
22021   rtx op1 = expand_normal (arg1);
22022   rtx op2 = expand_normal (arg2);
22023   enum machine_mode tmode0, tmode1, modev2, modev3, modeimm;
22024
22025   tmode0 = insn_data[d->icode].operand[0].mode;
22026   tmode1 = insn_data[d->icode].operand[1].mode;
22027   modev2 = insn_data[d->icode].operand[2].mode;
22028   modev3 = insn_data[d->icode].operand[3].mode;
22029   modeimm = insn_data[d->icode].operand[4].mode;
22030
22031   if (VECTOR_MODE_P (modev2))
22032     op0 = safe_vector_operand (op0, modev2);
22033   if (VECTOR_MODE_P (modev3))
22034     op1 = safe_vector_operand (op1, modev3);
22035
22036   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
22037     op0 = copy_to_mode_reg (modev2, op0);
22038   if ((optimize && !register_operand (op1, modev3))
22039       || !(*insn_data[d->icode].operand[3].predicate) (op1, modev3))
22040     op1 = copy_to_mode_reg (modev3, op1);
22041
22042   if (! (*insn_data[d->icode].operand[4].predicate) (op2, modeimm))
22043     {
22044       error ("the third argument must be a 8-bit immediate");
22045       return const0_rtx;
22046     }
22047
22048   if (d->code == IX86_BUILTIN_PCMPISTRI128)
22049     {
22050       if (optimize || !target
22051           || GET_MODE (target) != tmode0
22052           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
22053         target = gen_reg_rtx (tmode0);
22054
22055       scratch1 = gen_reg_rtx (tmode1);
22056
22057       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
22058     }
22059   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
22060     {
22061       if (optimize || !target
22062           || GET_MODE (target) != tmode1
22063           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
22064         target = gen_reg_rtx (tmode1);
22065
22066       scratch0 = gen_reg_rtx (tmode0);
22067
22068       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
22069     }
22070   else
22071     {
22072       gcc_assert (d->flag);
22073
22074       scratch0 = gen_reg_rtx (tmode0);
22075       scratch1 = gen_reg_rtx (tmode1);
22076
22077       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
22078     }
22079
22080   if (! pat)
22081     return 0;
22082
22083   emit_insn (pat);
22084
22085   if (d->flag)
22086     {
22087       target = gen_reg_rtx (SImode);
22088       emit_move_insn (target, const0_rtx);
22089       target = gen_rtx_SUBREG (QImode, target, 0);
22090
22091       emit_insn
22092         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
22093                       gen_rtx_fmt_ee (EQ, QImode,
22094                                       gen_rtx_REG ((enum machine_mode) d->flag,
22095                                                    FLAGS_REG),
22096                                       const0_rtx)));
22097       return SUBREG_REG (target);
22098     }
22099   else
22100     return target;
22101 }
22102
22103 /* Subroutine of ix86_expand_builtin to take care of insns with
22104    variable number of operands.  */
22105
22106 static rtx
22107 ix86_expand_args_builtin (const struct builtin_description *d,
22108                           tree exp, rtx target)
22109 {
22110   rtx pat, real_target;
22111   unsigned int i, nargs;
22112   unsigned int nargs_constant = 0;
22113   int num_memory = 0;
22114   struct
22115     {
22116       rtx op;
22117       enum machine_mode mode;
22118     } args[4];
22119   bool last_arg_count = false;
22120   enum insn_code icode = d->icode;
22121   const struct insn_data *insn_p = &insn_data[icode];
22122   enum machine_mode tmode = insn_p->operand[0].mode;
22123   enum machine_mode rmode = VOIDmode;
22124   bool swap = false;
22125   enum rtx_code comparison = d->comparison;
22126
22127   switch ((enum ix86_builtin_type) d->flag)
22128     {
22129     case INT_FTYPE_V2DI_V2DI_PTEST:
22130       return ix86_expand_sse_ptest (d, exp, target);
22131     case FLOAT128_FTYPE_FLOAT128:
22132     case FLOAT_FTYPE_FLOAT:
22133     case INT64_FTYPE_V4SF:
22134     case INT64_FTYPE_V2DF:
22135     case INT_FTYPE_V16QI:
22136     case INT_FTYPE_V8QI:
22137     case INT_FTYPE_V4SF:
22138     case INT_FTYPE_V2DF:
22139     case V16QI_FTYPE_V16QI:
22140     case V8HI_FTYPE_V8HI:
22141     case V8HI_FTYPE_V16QI:
22142     case V8QI_FTYPE_V8QI:
22143     case V4SI_FTYPE_V4SI:
22144     case V4SI_FTYPE_V16QI:
22145     case V4SI_FTYPE_V4SF:
22146     case V4SI_FTYPE_V8HI:
22147     case V4SI_FTYPE_V2DF:
22148     case V4HI_FTYPE_V4HI:
22149     case V4SF_FTYPE_V4SF:
22150     case V4SF_FTYPE_V4SI:
22151     case V4SF_FTYPE_V2DF:
22152     case V2DI_FTYPE_V2DI:
22153     case V2DI_FTYPE_V16QI:
22154     case V2DI_FTYPE_V8HI:
22155     case V2DI_FTYPE_V4SI:
22156     case V2DF_FTYPE_V2DF:
22157     case V2DF_FTYPE_V4SI:
22158     case V2DF_FTYPE_V4SF:
22159     case V2DF_FTYPE_V2SI:
22160     case V2SI_FTYPE_V2SI:
22161     case V2SI_FTYPE_V4SF:
22162     case V2SI_FTYPE_V2SF:
22163     case V2SI_FTYPE_V2DF:
22164     case V2SF_FTYPE_V2SF:
22165     case V2SF_FTYPE_V2SI:
22166       nargs = 1;
22167       break;
22168     case V4SF_FTYPE_V4SF_VEC_MERGE:
22169     case V2DF_FTYPE_V2DF_VEC_MERGE:
22170       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
22171     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
22172     case V16QI_FTYPE_V16QI_V16QI:
22173     case V16QI_FTYPE_V8HI_V8HI:
22174     case V8QI_FTYPE_V8QI_V8QI:
22175     case V8QI_FTYPE_V4HI_V4HI:
22176     case V8HI_FTYPE_V8HI_V8HI:
22177     case V8HI_FTYPE_V16QI_V16QI:
22178     case V8HI_FTYPE_V4SI_V4SI:
22179     case V4SI_FTYPE_V4SI_V4SI:
22180     case V4SI_FTYPE_V8HI_V8HI:
22181     case V4SI_FTYPE_V4SF_V4SF:
22182     case V4SI_FTYPE_V2DF_V2DF:
22183     case V4HI_FTYPE_V4HI_V4HI:
22184     case V4HI_FTYPE_V8QI_V8QI:
22185     case V4HI_FTYPE_V2SI_V2SI:
22186     case V4SF_FTYPE_V4SF_V4SF:
22187     case V4SF_FTYPE_V4SF_V2SI:
22188     case V4SF_FTYPE_V4SF_V2DF:
22189     case V4SF_FTYPE_V4SF_DI:
22190     case V4SF_FTYPE_V4SF_SI:
22191     case V2DI_FTYPE_V2DI_V2DI:
22192     case V2DI_FTYPE_V16QI_V16QI:
22193     case V2DI_FTYPE_V4SI_V4SI:
22194     case V2DI_FTYPE_V2DI_V16QI:
22195     case V2DI_FTYPE_V2DF_V2DF:
22196     case V2SI_FTYPE_V2SI_V2SI:
22197     case V2SI_FTYPE_V4HI_V4HI:
22198     case V2SI_FTYPE_V2SF_V2SF:
22199     case V2DF_FTYPE_V2DF_V2DF:
22200     case V2DF_FTYPE_V2DF_V4SF:
22201     case V2DF_FTYPE_V2DF_DI:
22202     case V2DF_FTYPE_V2DF_SI:
22203     case V2SF_FTYPE_V2SF_V2SF:
22204     case V1DI_FTYPE_V1DI_V1DI:
22205     case V1DI_FTYPE_V8QI_V8QI:
22206     case V1DI_FTYPE_V2SI_V2SI:
22207       if (comparison == UNKNOWN)
22208         return ix86_expand_binop_builtin (icode, exp, target);
22209       nargs = 2;
22210       break;
22211     case V4SF_FTYPE_V4SF_V4SF_SWAP:
22212     case V2DF_FTYPE_V2DF_V2DF_SWAP:
22213       gcc_assert (comparison != UNKNOWN);
22214       nargs = 2;
22215       swap = true;
22216       break;
22217     case V8HI_FTYPE_V8HI_V8HI_COUNT:
22218     case V8HI_FTYPE_V8HI_SI_COUNT:
22219     case V4SI_FTYPE_V4SI_V4SI_COUNT:
22220     case V4SI_FTYPE_V4SI_SI_COUNT:
22221     case V4HI_FTYPE_V4HI_V4HI_COUNT:
22222     case V4HI_FTYPE_V4HI_SI_COUNT:
22223     case V2DI_FTYPE_V2DI_V2DI_COUNT:
22224     case V2DI_FTYPE_V2DI_SI_COUNT:
22225     case V2SI_FTYPE_V2SI_V2SI_COUNT:
22226     case V2SI_FTYPE_V2SI_SI_COUNT:
22227     case V1DI_FTYPE_V1DI_V1DI_COUNT:
22228     case V1DI_FTYPE_V1DI_SI_COUNT:
22229       nargs = 2;
22230       last_arg_count = true;
22231       break;
22232     case UINT64_FTYPE_UINT64_UINT64:
22233     case UINT_FTYPE_UINT_UINT:
22234     case UINT_FTYPE_UINT_USHORT:
22235     case UINT_FTYPE_UINT_UCHAR:
22236       nargs = 2;
22237       break;
22238     case V2DI2TI_FTYPE_V2DI_INT:
22239       nargs = 2;
22240       rmode = V2DImode;
22241       nargs_constant = 1;
22242       break;
22243     case V8HI_FTYPE_V8HI_INT:
22244     case V4SI_FTYPE_V4SI_INT:
22245     case V4HI_FTYPE_V4HI_INT:
22246     case V4SF_FTYPE_V4SF_INT:
22247     case V2DI_FTYPE_V2DI_INT:
22248     case V2DF_FTYPE_V2DF_INT:
22249       nargs = 2;
22250       nargs_constant = 1;
22251       break;
22252     case V16QI_FTYPE_V16QI_V16QI_V16QI:
22253     case V4SF_FTYPE_V4SF_V4SF_V4SF:
22254     case V2DF_FTYPE_V2DF_V2DF_V2DF:
22255       nargs = 3;
22256       break;
22257     case V16QI_FTYPE_V16QI_V16QI_INT:
22258     case V8HI_FTYPE_V8HI_V8HI_INT:
22259     case V4SI_FTYPE_V4SI_V4SI_INT:
22260     case V4SF_FTYPE_V4SF_V4SF_INT:
22261     case V2DI_FTYPE_V2DI_V2DI_INT:
22262     case V2DF_FTYPE_V2DF_V2DF_INT:
22263       nargs = 3;
22264       nargs_constant = 1;
22265       break;
22266     case V2DI2TI_FTYPE_V2DI_V2DI_INT:
22267       nargs = 3;
22268       rmode = V2DImode;
22269       nargs_constant = 1;
22270       break;
22271     case V1DI2DI_FTYPE_V1DI_V1DI_INT:
22272       nargs = 3;
22273       rmode = DImode;
22274       nargs_constant = 1;
22275       break;
22276     case V2DI_FTYPE_V2DI_UINT_UINT:
22277       nargs = 3;
22278       nargs_constant = 2;
22279       break;
22280     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
22281       nargs = 4;
22282       nargs_constant = 2;
22283       break;
22284     default:
22285       gcc_unreachable ();
22286     }
22287
22288   gcc_assert (nargs <= ARRAY_SIZE (args));
22289
22290   if (comparison != UNKNOWN)
22291     {
22292       gcc_assert (nargs == 2);
22293       return ix86_expand_sse_compare (d, exp, target, swap);
22294     }
22295
22296   if (rmode == VOIDmode || rmode == tmode)
22297     {
22298       if (optimize
22299           || target == 0
22300           || GET_MODE (target) != tmode
22301           || ! (*insn_p->operand[0].predicate) (target, tmode))
22302         target = gen_reg_rtx (tmode);
22303       real_target = target;
22304     }
22305   else
22306     {
22307       target = gen_reg_rtx (rmode);
22308       real_target = simplify_gen_subreg (tmode, target, rmode, 0);
22309     }
22310
22311   for (i = 0; i < nargs; i++)
22312     {
22313       tree arg = CALL_EXPR_ARG (exp, i);
22314       rtx op = expand_normal (arg);
22315       enum machine_mode mode = insn_p->operand[i + 1].mode;
22316       bool match = (*insn_p->operand[i + 1].predicate) (op, mode);
22317
22318       if (last_arg_count && (i + 1) == nargs)
22319         {
22320           /* SIMD shift insns take either an 8-bit immediate or
22321              register as count.  But builtin functions take int as
22322              count.  If count doesn't match, we put it in register.  */
22323           if (!match)
22324             {
22325               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
22326               if (!(*insn_p->operand[i + 1].predicate) (op, mode))
22327                 op = copy_to_reg (op);
22328             }
22329         }
22330       else if ((nargs - i) <= nargs_constant)
22331         {
22332           if (!match)
22333             switch (icode)
22334               {
22335               case CODE_FOR_sse4_1_roundpd:
22336               case CODE_FOR_sse4_1_roundps:
22337               case CODE_FOR_sse4_1_roundsd:
22338               case CODE_FOR_sse4_1_roundss:
22339               case CODE_FOR_sse4_1_blendps:
22340                 error ("the last argument must be a 4-bit immediate");
22341                 return const0_rtx;
22342
22343               case CODE_FOR_sse4_1_blendpd:
22344                 error ("the last argument must be a 2-bit immediate");
22345                 return const0_rtx;
22346
22347              default:
22348                 switch (nargs_constant)
22349                   {
22350                   case 2:
22351                     if ((nargs - i) == nargs_constant)
22352                       {
22353                         error ("the next to last argument must be an 8-bit immediate");
22354                         break;
22355                       }
22356                   case 1:
22357                     error ("the last argument must be an 8-bit immediate");
22358                     break;
22359                   default:
22360                     gcc_unreachable ();
22361                   }
22362                 return const0_rtx;
22363               }
22364         }
22365       else
22366         {
22367           if (VECTOR_MODE_P (mode))
22368             op = safe_vector_operand (op, mode);
22369
22370           /* If we aren't optimizing, only allow one memory operand to
22371              be generated.  */
22372           if (memory_operand (op, mode))
22373             num_memory++;
22374
22375           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
22376             {
22377               if (optimize || !match || num_memory > 1)
22378                 op = copy_to_mode_reg (mode, op);
22379             }
22380           else
22381             {
22382               op = copy_to_reg (op);
22383               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
22384             }
22385         }
22386
22387       args[i].op = op;
22388       args[i].mode = mode;
22389     }
22390
22391   switch (nargs)
22392     {
22393     case 1:
22394       pat = GEN_FCN (icode) (real_target, args[0].op);
22395       break;
22396     case 2:
22397       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
22398       break;
22399     case 3:
22400       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
22401                              args[2].op);
22402       break;
22403     case 4:
22404       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
22405                              args[2].op, args[3].op);
22406       break;
22407     default:
22408       gcc_unreachable ();
22409     }
22410
22411   if (! pat)
22412     return 0;
22413
22414   emit_insn (pat);
22415   return target;
22416 }
22417
22418 /* Subroutine of ix86_expand_builtin to take care of special insns
22419    with variable number of operands.  */
22420
22421 static rtx
22422 ix86_expand_special_args_builtin (const struct builtin_description *d,
22423                                     tree exp, rtx target)
22424 {
22425   tree arg;
22426   rtx pat, op;
22427   unsigned int i, nargs, arg_adjust, memory;
22428   struct
22429     {
22430       rtx op;
22431       enum machine_mode mode;
22432     } args[2];
22433   enum insn_code icode = d->icode;
22434   bool last_arg_constant = false;
22435   const struct insn_data *insn_p = &insn_data[icode];
22436   enum machine_mode tmode = insn_p->operand[0].mode;
22437   enum { load, store } klass;
22438
22439   switch ((enum ix86_special_builtin_type) d->flag)
22440     {
22441     case VOID_FTYPE_VOID:
22442       emit_insn (GEN_FCN (icode) (target));
22443       return 0;
22444     case V2DI_FTYPE_PV2DI:
22445     case V16QI_FTYPE_PCCHAR:
22446     case V4SF_FTYPE_PCFLOAT:
22447     case V2DF_FTYPE_PCDOUBLE:
22448       nargs = 1;
22449       klass = load;
22450       memory = 0;
22451       break;
22452     case VOID_FTYPE_PV2SF_V4SF:
22453     case VOID_FTYPE_PV2DI_V2DI:
22454     case VOID_FTYPE_PCHAR_V16QI:
22455     case VOID_FTYPE_PFLOAT_V4SF:
22456     case VOID_FTYPE_PDOUBLE_V2DF:
22457     case VOID_FTYPE_PDI_DI:
22458     case VOID_FTYPE_PINT_INT:
22459       nargs = 1;
22460       klass = store;
22461       /* Reserve memory operand for target.  */
22462       memory = ARRAY_SIZE (args);
22463       break;
22464     case V4SF_FTYPE_V4SF_PCV2SF:
22465     case V2DF_FTYPE_V2DF_PCDOUBLE:
22466       nargs = 2;
22467       klass = load;
22468       memory = 1;
22469       break;
22470     default:
22471       gcc_unreachable ();
22472     }
22473
22474   gcc_assert (nargs <= ARRAY_SIZE (args));
22475
22476   if (klass == store)
22477     {
22478       arg = CALL_EXPR_ARG (exp, 0);
22479       op = expand_normal (arg);
22480       gcc_assert (target == 0);
22481       target = gen_rtx_MEM (tmode, copy_to_mode_reg (Pmode, op));
22482       arg_adjust = 1;
22483     }
22484   else
22485     {
22486       arg_adjust = 0;
22487       if (optimize
22488           || target == 0
22489           || GET_MODE (target) != tmode
22490           || ! (*insn_p->operand[0].predicate) (target, tmode))
22491         target = gen_reg_rtx (tmode);
22492     }
22493
22494   for (i = 0; i < nargs; i++)
22495     {
22496       enum machine_mode mode = insn_p->operand[i + 1].mode;
22497       bool match;
22498
22499       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
22500       op = expand_normal (arg);
22501       match = (*insn_p->operand[i + 1].predicate) (op, mode);
22502
22503       if (last_arg_constant && (i + 1) == nargs)
22504         {
22505           if (!match)
22506             switch (icode)
22507               {
22508              default:
22509                 error ("the last argument must be an 8-bit immediate");
22510                 return const0_rtx;
22511               }
22512         }
22513       else
22514         {
22515           if (i == memory)
22516             {
22517               /* This must be the memory operand.  */
22518               op = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, op));
22519               gcc_assert (GET_MODE (op) == mode
22520                           || GET_MODE (op) == VOIDmode);
22521             }
22522           else
22523             {
22524               /* This must be register.  */
22525               if (VECTOR_MODE_P (mode))
22526                 op = safe_vector_operand (op, mode);
22527
22528               gcc_assert (GET_MODE (op) == mode
22529                           || GET_MODE (op) == VOIDmode);
22530               op = copy_to_mode_reg (mode, op);
22531             }
22532         }
22533
22534       args[i].op = op;
22535       args[i].mode = mode;
22536     }
22537
22538   switch (nargs)
22539     {
22540     case 1:
22541       pat = GEN_FCN (icode) (target, args[0].op);
22542       break;
22543     case 2:
22544       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
22545       break;
22546     default:
22547       gcc_unreachable ();
22548     }
22549
22550   if (! pat)
22551     return 0;
22552   emit_insn (pat);
22553   return klass == store ? 0 : target;
22554 }
22555
22556 /* Return the integer constant in ARG.  Constrain it to be in the range
22557    of the subparts of VEC_TYPE; issue an error if not.  */
22558
22559 static int
22560 get_element_number (tree vec_type, tree arg)
22561 {
22562   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
22563
22564   if (!host_integerp (arg, 1)
22565       || (elt = tree_low_cst (arg, 1), elt > max))
22566     {
22567       error ("selector must be an integer constant in the range 0..%wi", max);
22568       return 0;
22569     }
22570
22571   return elt;
22572 }
22573
22574 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
22575    ix86_expand_vector_init.  We DO have language-level syntax for this, in
22576    the form of  (type){ init-list }.  Except that since we can't place emms
22577    instructions from inside the compiler, we can't allow the use of MMX
22578    registers unless the user explicitly asks for it.  So we do *not* define
22579    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
22580    we have builtins invoked by mmintrin.h that gives us license to emit
22581    these sorts of instructions.  */
22582
22583 static rtx
22584 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
22585 {
22586   enum machine_mode tmode = TYPE_MODE (type);
22587   enum machine_mode inner_mode = GET_MODE_INNER (tmode);
22588   int i, n_elt = GET_MODE_NUNITS (tmode);
22589   rtvec v = rtvec_alloc (n_elt);
22590
22591   gcc_assert (VECTOR_MODE_P (tmode));
22592   gcc_assert (call_expr_nargs (exp) == n_elt);
22593
22594   for (i = 0; i < n_elt; ++i)
22595     {
22596       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
22597       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
22598     }
22599
22600   if (!target || !register_operand (target, tmode))
22601     target = gen_reg_rtx (tmode);
22602
22603   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
22604   return target;
22605 }
22606
22607 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
22608    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
22609    had a language-level syntax for referencing vector elements.  */
22610
22611 static rtx
22612 ix86_expand_vec_ext_builtin (tree exp, rtx target)
22613 {
22614   enum machine_mode tmode, mode0;
22615   tree arg0, arg1;
22616   int elt;
22617   rtx op0;
22618
22619   arg0 = CALL_EXPR_ARG (exp, 0);
22620   arg1 = CALL_EXPR_ARG (exp, 1);
22621
22622   op0 = expand_normal (arg0);
22623   elt = get_element_number (TREE_TYPE (arg0), arg1);
22624
22625   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
22626   mode0 = TYPE_MODE (TREE_TYPE (arg0));
22627   gcc_assert (VECTOR_MODE_P (mode0));
22628
22629   op0 = force_reg (mode0, op0);
22630
22631   if (optimize || !target || !register_operand (target, tmode))
22632     target = gen_reg_rtx (tmode);
22633
22634   ix86_expand_vector_extract (true, target, op0, elt);
22635
22636   return target;
22637 }
22638
22639 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
22640    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
22641    a language-level syntax for referencing vector elements.  */
22642
22643 static rtx
22644 ix86_expand_vec_set_builtin (tree exp)
22645 {
22646   enum machine_mode tmode, mode1;
22647   tree arg0, arg1, arg2;
22648   int elt;
22649   rtx op0, op1, target;
22650
22651   arg0 = CALL_EXPR_ARG (exp, 0);
22652   arg1 = CALL_EXPR_ARG (exp, 1);
22653   arg2 = CALL_EXPR_ARG (exp, 2);
22654
22655   tmode = TYPE_MODE (TREE_TYPE (arg0));
22656   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
22657   gcc_assert (VECTOR_MODE_P (tmode));
22658
22659   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
22660   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
22661   elt = get_element_number (TREE_TYPE (arg0), arg2);
22662
22663   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
22664     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
22665
22666   op0 = force_reg (tmode, op0);
22667   op1 = force_reg (mode1, op1);
22668
22669   /* OP0 is the source of these builtin functions and shouldn't be
22670      modified.  Create a copy, use it and return it as target.  */
22671   target = gen_reg_rtx (tmode);
22672   emit_move_insn (target, op0);
22673   ix86_expand_vector_set (true, target, op1, elt);
22674
22675   return target;
22676 }
22677
22678 /* Expand an expression EXP that calls a built-in function,
22679    with result going to TARGET if that's convenient
22680    (and in mode MODE if that's convenient).
22681    SUBTARGET may be used as the target for computing one of EXP's operands.
22682    IGNORE is nonzero if the value is to be ignored.  */
22683
22684 static rtx
22685 ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
22686                      enum machine_mode mode ATTRIBUTE_UNUSED,
22687                      int ignore ATTRIBUTE_UNUSED)
22688 {
22689   const struct builtin_description *d;
22690   size_t i;
22691   enum insn_code icode;
22692   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
22693   tree arg0, arg1, arg2;
22694   rtx op0, op1, op2, pat;
22695   enum machine_mode mode0, mode1, mode2;
22696   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
22697
22698   /* Determine whether the builtin function is available under the current ISA.
22699      Originally the builtin was not created if it wasn't applicable to the
22700      current ISA based on the command line switches.  With function specific
22701      options, we need to check in the context of the function making the call
22702      whether it is supported.  */
22703   if (ix86_builtins_isa[fcode]
22704       && !(ix86_builtins_isa[fcode] & ix86_isa_flags))
22705     {
22706       char *opts = ix86_target_string (ix86_builtins_isa[fcode], 0, NULL,
22707                                        NULL, NULL, false);
22708
22709       if (!opts)
22710         error ("%qE needs unknown isa option", fndecl);
22711       else
22712         {
22713           gcc_assert (opts != NULL);
22714           error ("%qE needs isa option %s", fndecl, opts);
22715           free (opts);
22716         }
22717       return const0_rtx;
22718     }
22719
22720   switch (fcode)
22721     {
22722     case IX86_BUILTIN_MASKMOVQ:
22723     case IX86_BUILTIN_MASKMOVDQU:
22724       icode = (fcode == IX86_BUILTIN_MASKMOVQ
22725                ? CODE_FOR_mmx_maskmovq
22726                : CODE_FOR_sse2_maskmovdqu);
22727       /* Note the arg order is different from the operand order.  */
22728       arg1 = CALL_EXPR_ARG (exp, 0);
22729       arg2 = CALL_EXPR_ARG (exp, 1);
22730       arg0 = CALL_EXPR_ARG (exp, 2);
22731       op0 = expand_normal (arg0);
22732       op1 = expand_normal (arg1);
22733       op2 = expand_normal (arg2);
22734       mode0 = insn_data[icode].operand[0].mode;
22735       mode1 = insn_data[icode].operand[1].mode;
22736       mode2 = insn_data[icode].operand[2].mode;
22737
22738       op0 = force_reg (Pmode, op0);
22739       op0 = gen_rtx_MEM (mode1, op0);
22740
22741       if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
22742         op0 = copy_to_mode_reg (mode0, op0);
22743       if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
22744         op1 = copy_to_mode_reg (mode1, op1);
22745       if (! (*insn_data[icode].operand[2].predicate) (op2, mode2))
22746         op2 = copy_to_mode_reg (mode2, op2);
22747       pat = GEN_FCN (icode) (op0, op1, op2);
22748       if (! pat)
22749         return 0;
22750       emit_insn (pat);
22751       return 0;
22752
22753     case IX86_BUILTIN_LDMXCSR:
22754       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
22755       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
22756       emit_move_insn (target, op0);
22757       emit_insn (gen_sse_ldmxcsr (target));
22758       return 0;
22759
22760     case IX86_BUILTIN_STMXCSR:
22761       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
22762       emit_insn (gen_sse_stmxcsr (target));
22763       return copy_to_mode_reg (SImode, target);
22764
22765     case IX86_BUILTIN_CLFLUSH:
22766         arg0 = CALL_EXPR_ARG (exp, 0);
22767         op0 = expand_normal (arg0);
22768         icode = CODE_FOR_sse2_clflush;
22769         if (! (*insn_data[icode].operand[0].predicate) (op0, Pmode))
22770             op0 = copy_to_mode_reg (Pmode, op0);
22771
22772         emit_insn (gen_sse2_clflush (op0));
22773         return 0;
22774
22775     case IX86_BUILTIN_MONITOR:
22776       arg0 = CALL_EXPR_ARG (exp, 0);
22777       arg1 = CALL_EXPR_ARG (exp, 1);
22778       arg2 = CALL_EXPR_ARG (exp, 2);
22779       op0 = expand_normal (arg0);
22780       op1 = expand_normal (arg1);
22781       op2 = expand_normal (arg2);
22782       if (!REG_P (op0))
22783         op0 = copy_to_mode_reg (Pmode, op0);
22784       if (!REG_P (op1))
22785         op1 = copy_to_mode_reg (SImode, op1);
22786       if (!REG_P (op2))
22787         op2 = copy_to_mode_reg (SImode, op2);
22788       emit_insn ((*ix86_gen_monitor) (op0, op1, op2));
22789       return 0;
22790
22791     case IX86_BUILTIN_MWAIT:
22792       arg0 = CALL_EXPR_ARG (exp, 0);
22793       arg1 = CALL_EXPR_ARG (exp, 1);
22794       op0 = expand_normal (arg0);
22795       op1 = expand_normal (arg1);
22796       if (!REG_P (op0))
22797         op0 = copy_to_mode_reg (SImode, op0);
22798       if (!REG_P (op1))
22799         op1 = copy_to_mode_reg (SImode, op1);
22800       emit_insn (gen_sse3_mwait (op0, op1));
22801       return 0;
22802
22803     case IX86_BUILTIN_VEC_INIT_V2SI:
22804     case IX86_BUILTIN_VEC_INIT_V4HI:
22805     case IX86_BUILTIN_VEC_INIT_V8QI:
22806       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
22807
22808     case IX86_BUILTIN_VEC_EXT_V2DF:
22809     case IX86_BUILTIN_VEC_EXT_V2DI:
22810     case IX86_BUILTIN_VEC_EXT_V4SF:
22811     case IX86_BUILTIN_VEC_EXT_V4SI:
22812     case IX86_BUILTIN_VEC_EXT_V8HI:
22813     case IX86_BUILTIN_VEC_EXT_V2SI:
22814     case IX86_BUILTIN_VEC_EXT_V4HI:
22815     case IX86_BUILTIN_VEC_EXT_V16QI:
22816       return ix86_expand_vec_ext_builtin (exp, target);
22817
22818     case IX86_BUILTIN_VEC_SET_V2DI:
22819     case IX86_BUILTIN_VEC_SET_V4SF:
22820     case IX86_BUILTIN_VEC_SET_V4SI:
22821     case IX86_BUILTIN_VEC_SET_V8HI:
22822     case IX86_BUILTIN_VEC_SET_V4HI:
22823     case IX86_BUILTIN_VEC_SET_V16QI:
22824       return ix86_expand_vec_set_builtin (exp);
22825
22826     case IX86_BUILTIN_INFQ:
22827       {
22828         REAL_VALUE_TYPE inf;
22829         rtx tmp;
22830
22831         real_inf (&inf);
22832         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
22833
22834         tmp = validize_mem (force_const_mem (mode, tmp));
22835
22836         if (target == 0)
22837           target = gen_reg_rtx (mode);
22838
22839         emit_move_insn (target, tmp);
22840         return target;
22841       }
22842
22843     default:
22844       break;
22845     }
22846
22847   for (i = 0, d = bdesc_special_args;
22848        i < ARRAY_SIZE (bdesc_special_args);
22849        i++, d++)
22850     if (d->code == fcode)
22851       return ix86_expand_special_args_builtin (d, exp, target);
22852
22853   for (i = 0, d = bdesc_args;
22854        i < ARRAY_SIZE (bdesc_args);
22855        i++, d++)
22856     if (d->code == fcode)
22857       switch (fcode)
22858         {
22859         case IX86_BUILTIN_FABSQ:
22860         case IX86_BUILTIN_COPYSIGNQ:
22861           if (!TARGET_SSE2)
22862             /* Emit a normal call if SSE2 isn't available.  */
22863             return expand_call (exp, target, ignore);
22864         default:
22865           return ix86_expand_args_builtin (d, exp, target);
22866         }
22867
22868   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
22869     if (d->code == fcode)
22870       return ix86_expand_sse_comi (d, exp, target);
22871
22872   for (i = 0, d = bdesc_pcmpestr;
22873        i < ARRAY_SIZE (bdesc_pcmpestr);
22874        i++, d++)
22875     if (d->code == fcode)
22876       return ix86_expand_sse_pcmpestr (d, exp, target);
22877
22878   for (i = 0, d = bdesc_pcmpistr;
22879        i < ARRAY_SIZE (bdesc_pcmpistr);
22880        i++, d++)
22881     if (d->code == fcode)
22882       return ix86_expand_sse_pcmpistr (d, exp, target);
22883
22884   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
22885     if (d->code == fcode)
22886       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
22887                                             (enum multi_arg_type)d->flag,
22888                                             d->comparison);
22889
22890   gcc_unreachable ();
22891 }
22892
22893 /* Returns a function decl for a vectorized version of the builtin function
22894    with builtin function code FN and the result vector type TYPE, or NULL_TREE
22895    if it is not available.  */
22896
22897 static tree
22898 ix86_builtin_vectorized_function (unsigned int fn, tree type_out,
22899                                   tree type_in)
22900 {
22901   enum machine_mode in_mode, out_mode;
22902   int in_n, out_n;
22903
22904   if (TREE_CODE (type_out) != VECTOR_TYPE
22905       || TREE_CODE (type_in) != VECTOR_TYPE)
22906     return NULL_TREE;
22907
22908   out_mode = TYPE_MODE (TREE_TYPE (type_out));
22909   out_n = TYPE_VECTOR_SUBPARTS (type_out);
22910   in_mode = TYPE_MODE (TREE_TYPE (type_in));
22911   in_n = TYPE_VECTOR_SUBPARTS (type_in);
22912
22913   switch (fn)
22914     {
22915     case BUILT_IN_SQRT:
22916       if (out_mode == DFmode && out_n == 2
22917           && in_mode == DFmode && in_n == 2)
22918         return ix86_builtins[IX86_BUILTIN_SQRTPD];
22919       break;
22920
22921     case BUILT_IN_SQRTF:
22922       if (out_mode == SFmode && out_n == 4
22923           && in_mode == SFmode && in_n == 4)
22924         return ix86_builtins[IX86_BUILTIN_SQRTPS_NR];
22925       break;
22926
22927     case BUILT_IN_LRINT:
22928       if (out_mode == SImode && out_n == 4
22929           && in_mode == DFmode && in_n == 2)
22930         return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
22931       break;
22932
22933     case BUILT_IN_LRINTF:
22934       if (out_mode == SImode && out_n == 4
22935           && in_mode == SFmode && in_n == 4)
22936         return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
22937       break;
22938
22939     default:
22940       ;
22941     }
22942
22943   /* Dispatch to a handler for a vectorization library.  */
22944   if (ix86_veclib_handler)
22945     return (*ix86_veclib_handler)(fn, type_out, type_in);
22946
22947   return NULL_TREE;
22948 }
22949
22950 /* Handler for an SVML-style interface to
22951    a library with vectorized intrinsics.  */
22952
22953 static tree
22954 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
22955 {
22956   char name[20];
22957   tree fntype, new_fndecl, args;
22958   unsigned arity;
22959   const char *bname;
22960   enum machine_mode el_mode, in_mode;
22961   int n, in_n;
22962
22963   /* The SVML is suitable for unsafe math only.  */
22964   if (!flag_unsafe_math_optimizations)
22965     return NULL_TREE;
22966
22967   el_mode = TYPE_MODE (TREE_TYPE (type_out));
22968   n = TYPE_VECTOR_SUBPARTS (type_out);
22969   in_mode = TYPE_MODE (TREE_TYPE (type_in));
22970   in_n = TYPE_VECTOR_SUBPARTS (type_in);
22971   if (el_mode != in_mode
22972       || n != in_n)
22973     return NULL_TREE;
22974
22975   switch (fn)
22976     {
22977     case BUILT_IN_EXP:
22978     case BUILT_IN_LOG:
22979     case BUILT_IN_LOG10:
22980     case BUILT_IN_POW:
22981     case BUILT_IN_TANH:
22982     case BUILT_IN_TAN:
22983     case BUILT_IN_ATAN:
22984     case BUILT_IN_ATAN2:
22985     case BUILT_IN_ATANH:
22986     case BUILT_IN_CBRT:
22987     case BUILT_IN_SINH:
22988     case BUILT_IN_SIN:
22989     case BUILT_IN_ASINH:
22990     case BUILT_IN_ASIN:
22991     case BUILT_IN_COSH:
22992     case BUILT_IN_COS:
22993     case BUILT_IN_ACOSH:
22994     case BUILT_IN_ACOS:
22995       if (el_mode != DFmode || n != 2)
22996         return NULL_TREE;
22997       break;
22998
22999     case BUILT_IN_EXPF:
23000     case BUILT_IN_LOGF:
23001     case BUILT_IN_LOG10F:
23002     case BUILT_IN_POWF:
23003     case BUILT_IN_TANHF:
23004     case BUILT_IN_TANF:
23005     case BUILT_IN_ATANF:
23006     case BUILT_IN_ATAN2F:
23007     case BUILT_IN_ATANHF:
23008     case BUILT_IN_CBRTF:
23009     case BUILT_IN_SINHF:
23010     case BUILT_IN_SINF:
23011     case BUILT_IN_ASINHF:
23012     case BUILT_IN_ASINF:
23013     case BUILT_IN_COSHF:
23014     case BUILT_IN_COSF:
23015     case BUILT_IN_ACOSHF:
23016     case BUILT_IN_ACOSF:
23017       if (el_mode != SFmode || n != 4)
23018         return NULL_TREE;
23019       break;
23020
23021     default:
23022       return NULL_TREE;
23023     }
23024
23025   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
23026
23027   if (fn == BUILT_IN_LOGF)
23028     strcpy (name, "vmlsLn4");
23029   else if (fn == BUILT_IN_LOG)
23030     strcpy (name, "vmldLn2");
23031   else if (n == 4)
23032     {
23033       sprintf (name, "vmls%s", bname+10);
23034       name[strlen (name)-1] = '4';
23035     }
23036   else
23037     sprintf (name, "vmld%s2", bname+10);
23038
23039   /* Convert to uppercase. */
23040   name[4] &= ~0x20;
23041
23042   arity = 0;
23043   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
23044        args = TREE_CHAIN (args))
23045     arity++;
23046
23047   if (arity == 1)
23048     fntype = build_function_type_list (type_out, type_in, NULL);
23049   else
23050     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
23051
23052   /* Build a function declaration for the vectorized function.  */
23053   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
23054   TREE_PUBLIC (new_fndecl) = 1;
23055   DECL_EXTERNAL (new_fndecl) = 1;
23056   DECL_IS_NOVOPS (new_fndecl) = 1;
23057   TREE_READONLY (new_fndecl) = 1;
23058
23059   return new_fndecl;
23060 }
23061
23062 /* Handler for an ACML-style interface to
23063    a library with vectorized intrinsics.  */
23064
23065 static tree
23066 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
23067 {
23068   char name[20] = "__vr.._";
23069   tree fntype, new_fndecl, args;
23070   unsigned arity;
23071   const char *bname;
23072   enum machine_mode el_mode, in_mode;
23073   int n, in_n;
23074
23075   /* The ACML is 64bits only and suitable for unsafe math only as
23076      it does not correctly support parts of IEEE with the required
23077      precision such as denormals.  */
23078   if (!TARGET_64BIT
23079       || !flag_unsafe_math_optimizations)
23080     return NULL_TREE;
23081
23082   el_mode = TYPE_MODE (TREE_TYPE (type_out));
23083   n = TYPE_VECTOR_SUBPARTS (type_out);
23084   in_mode = TYPE_MODE (TREE_TYPE (type_in));
23085   in_n = TYPE_VECTOR_SUBPARTS (type_in);
23086   if (el_mode != in_mode
23087       || n != in_n)
23088     return NULL_TREE;
23089
23090   switch (fn)
23091     {
23092     case BUILT_IN_SIN:
23093     case BUILT_IN_COS:
23094     case BUILT_IN_EXP:
23095     case BUILT_IN_LOG:
23096     case BUILT_IN_LOG2:
23097     case BUILT_IN_LOG10:
23098       name[4] = 'd';
23099       name[5] = '2';
23100       if (el_mode != DFmode
23101           || n != 2)
23102         return NULL_TREE;
23103       break;
23104
23105     case BUILT_IN_SINF:
23106     case BUILT_IN_COSF:
23107     case BUILT_IN_EXPF:
23108     case BUILT_IN_POWF:
23109     case BUILT_IN_LOGF:
23110     case BUILT_IN_LOG2F:
23111     case BUILT_IN_LOG10F:
23112       name[4] = 's';
23113       name[5] = '4';
23114       if (el_mode != SFmode
23115           || n != 4)
23116         return NULL_TREE;
23117       break;
23118
23119     default:
23120       return NULL_TREE;
23121     }
23122
23123   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
23124   sprintf (name + 7, "%s", bname+10);
23125
23126   arity = 0;
23127   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
23128        args = TREE_CHAIN (args))
23129     arity++;
23130
23131   if (arity == 1)
23132     fntype = build_function_type_list (type_out, type_in, NULL);
23133   else
23134     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
23135
23136   /* Build a function declaration for the vectorized function.  */
23137   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
23138   TREE_PUBLIC (new_fndecl) = 1;
23139   DECL_EXTERNAL (new_fndecl) = 1;
23140   DECL_IS_NOVOPS (new_fndecl) = 1;
23141   TREE_READONLY (new_fndecl) = 1;
23142
23143   return new_fndecl;
23144 }
23145
23146
23147 /* Returns a decl of a function that implements conversion of the
23148    input vector of type TYPE, or NULL_TREE if it is not available.  */
23149
23150 static tree
23151 ix86_vectorize_builtin_conversion (unsigned int code, tree type)
23152 {
23153   if (TREE_CODE (type) != VECTOR_TYPE)
23154     return NULL_TREE;
23155
23156   switch (code)
23157     {
23158     case FLOAT_EXPR:
23159       switch (TYPE_MODE (type))
23160         {
23161         case V4SImode:
23162           return ix86_builtins[IX86_BUILTIN_CVTDQ2PS];
23163         default:
23164           return NULL_TREE;
23165         }
23166
23167     case FIX_TRUNC_EXPR:
23168       switch (TYPE_MODE (type))
23169         {
23170         case V4SFmode:
23171           return ix86_builtins[IX86_BUILTIN_CVTTPS2DQ];
23172         default:
23173           return NULL_TREE;
23174         }
23175     default:
23176       return NULL_TREE;
23177
23178     }
23179 }
23180
23181 /* Returns a code for a target-specific builtin that implements
23182    reciprocal of the function, or NULL_TREE if not available.  */
23183
23184 static tree
23185 ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
23186                          bool sqrt ATTRIBUTE_UNUSED)
23187 {
23188   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
23189          && flag_finite_math_only && !flag_trapping_math
23190          && flag_unsafe_math_optimizations))
23191     return NULL_TREE;
23192
23193   if (md_fn)
23194     /* Machine dependent builtins.  */
23195     switch (fn)
23196       {
23197         /* Vectorized version of sqrt to rsqrt conversion.  */
23198       case IX86_BUILTIN_SQRTPS_NR:
23199         return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR];
23200
23201       default:
23202         return NULL_TREE;
23203       }
23204   else
23205     /* Normal builtins.  */
23206     switch (fn)
23207       {
23208         /* Sqrt to rsqrt conversion.  */
23209       case BUILT_IN_SQRTF:
23210         return ix86_builtins[IX86_BUILTIN_RSQRTF];
23211
23212       default:
23213         return NULL_TREE;
23214       }
23215 }
23216
23217 /* Store OPERAND to the memory after reload is completed.  This means
23218    that we can't easily use assign_stack_local.  */
23219 rtx
23220 ix86_force_to_memory (enum machine_mode mode, rtx operand)
23221 {
23222   rtx result;
23223
23224   gcc_assert (reload_completed);
23225   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE)
23226     {
23227       result = gen_rtx_MEM (mode,
23228                             gen_rtx_PLUS (Pmode,
23229                                           stack_pointer_rtx,
23230                                           GEN_INT (-RED_ZONE_SIZE)));
23231       emit_move_insn (result, operand);
23232     }
23233   else if ((TARGET_64BIT_MS_ABI || !TARGET_RED_ZONE) && TARGET_64BIT)
23234     {
23235       switch (mode)
23236         {
23237         case HImode:
23238         case SImode:
23239           operand = gen_lowpart (DImode, operand);
23240           /* FALLTHRU */
23241         case DImode:
23242           emit_insn (
23243                       gen_rtx_SET (VOIDmode,
23244                                    gen_rtx_MEM (DImode,
23245                                                 gen_rtx_PRE_DEC (DImode,
23246                                                         stack_pointer_rtx)),
23247                                    operand));
23248           break;
23249         default:
23250           gcc_unreachable ();
23251         }
23252       result = gen_rtx_MEM (mode, stack_pointer_rtx);
23253     }
23254   else
23255     {
23256       switch (mode)
23257         {
23258         case DImode:
23259           {
23260             rtx operands[2];
23261             split_di (&operand, 1, operands, operands + 1);
23262             emit_insn (
23263                         gen_rtx_SET (VOIDmode,
23264                                      gen_rtx_MEM (SImode,
23265                                                   gen_rtx_PRE_DEC (Pmode,
23266                                                         stack_pointer_rtx)),
23267                                      operands[1]));
23268             emit_insn (
23269                         gen_rtx_SET (VOIDmode,
23270                                      gen_rtx_MEM (SImode,
23271                                                   gen_rtx_PRE_DEC (Pmode,
23272                                                         stack_pointer_rtx)),
23273                                      operands[0]));
23274           }
23275           break;
23276         case HImode:
23277           /* Store HImodes as SImodes.  */
23278           operand = gen_lowpart (SImode, operand);
23279           /* FALLTHRU */
23280         case SImode:
23281           emit_insn (
23282                       gen_rtx_SET (VOIDmode,
23283                                    gen_rtx_MEM (GET_MODE (operand),
23284                                                 gen_rtx_PRE_DEC (SImode,
23285                                                         stack_pointer_rtx)),
23286                                    operand));
23287           break;
23288         default:
23289           gcc_unreachable ();
23290         }
23291       result = gen_rtx_MEM (mode, stack_pointer_rtx);
23292     }
23293   return result;
23294 }
23295
23296 /* Free operand from the memory.  */
23297 void
23298 ix86_free_from_memory (enum machine_mode mode)
23299 {
23300   if (!TARGET_RED_ZONE || TARGET_64BIT_MS_ABI)
23301     {
23302       int size;
23303
23304       if (mode == DImode || TARGET_64BIT)
23305         size = 8;
23306       else
23307         size = 4;
23308       /* Use LEA to deallocate stack space.  In peephole2 it will be converted
23309          to pop or add instruction if registers are available.  */
23310       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
23311                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
23312                                             GEN_INT (size))));
23313     }
23314 }
23315
23316 /* Put float CONST_DOUBLE in the constant pool instead of fp regs.
23317    QImode must go into class Q_REGS.
23318    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
23319    movdf to do mem-to-mem moves through integer regs.  */
23320 enum reg_class
23321 ix86_preferred_reload_class (rtx x, enum reg_class regclass)
23322 {
23323   enum machine_mode mode = GET_MODE (x);
23324
23325   /* We're only allowed to return a subclass of CLASS.  Many of the
23326      following checks fail for NO_REGS, so eliminate that early.  */
23327   if (regclass == NO_REGS)
23328     return NO_REGS;
23329
23330   /* All classes can load zeros.  */
23331   if (x == CONST0_RTX (mode))
23332     return regclass;
23333
23334   /* Force constants into memory if we are loading a (nonzero) constant into
23335      an MMX or SSE register.  This is because there are no MMX/SSE instructions
23336      to load from a constant.  */
23337   if (CONSTANT_P (x)
23338       && (MAYBE_MMX_CLASS_P (regclass) || MAYBE_SSE_CLASS_P (regclass)))
23339     return NO_REGS;
23340
23341   /* Prefer SSE regs only, if we can use them for math.  */
23342   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
23343     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
23344
23345   /* Floating-point constants need more complex checks.  */
23346   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
23347     {
23348       /* General regs can load everything.  */
23349       if (reg_class_subset_p (regclass, GENERAL_REGS))
23350         return regclass;
23351
23352       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
23353          zero above.  We only want to wind up preferring 80387 registers if
23354          we plan on doing computation with them.  */
23355       if (TARGET_80387
23356           && standard_80387_constant_p (x))
23357         {
23358           /* Limit class to non-sse.  */
23359           if (regclass == FLOAT_SSE_REGS)
23360             return FLOAT_REGS;
23361           if (regclass == FP_TOP_SSE_REGS)
23362             return FP_TOP_REG;
23363           if (regclass == FP_SECOND_SSE_REGS)
23364             return FP_SECOND_REG;
23365           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
23366             return regclass;
23367         }
23368
23369       return NO_REGS;
23370     }
23371
23372   /* Generally when we see PLUS here, it's the function invariant
23373      (plus soft-fp const_int).  Which can only be computed into general
23374      regs.  */
23375   if (GET_CODE (x) == PLUS)
23376     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
23377
23378   /* QImode constants are easy to load, but non-constant QImode data
23379      must go into Q_REGS.  */
23380   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
23381     {
23382       if (reg_class_subset_p (regclass, Q_REGS))
23383         return regclass;
23384       if (reg_class_subset_p (Q_REGS, regclass))
23385         return Q_REGS;
23386       return NO_REGS;
23387     }
23388
23389   return regclass;
23390 }
23391
23392 /* Discourage putting floating-point values in SSE registers unless
23393    SSE math is being used, and likewise for the 387 registers.  */
23394 enum reg_class
23395 ix86_preferred_output_reload_class (rtx x, enum reg_class regclass)
23396 {
23397   enum machine_mode mode = GET_MODE (x);
23398
23399   /* Restrict the output reload class to the register bank that we are doing
23400      math on.  If we would like not to return a subset of CLASS, reject this
23401      alternative: if reload cannot do this, it will still use its choice.  */
23402   mode = GET_MODE (x);
23403   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
23404     return MAYBE_SSE_CLASS_P (regclass) ? SSE_REGS : NO_REGS;
23405
23406   if (X87_FLOAT_MODE_P (mode))
23407     {
23408       if (regclass == FP_TOP_SSE_REGS)
23409         return FP_TOP_REG;
23410       else if (regclass == FP_SECOND_SSE_REGS)
23411         return FP_SECOND_REG;
23412       else
23413         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
23414     }
23415
23416   return regclass;
23417 }
23418
23419 static enum reg_class
23420 ix86_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
23421                        enum machine_mode mode,
23422                        secondary_reload_info *sri ATTRIBUTE_UNUSED)
23423 {
23424   /* QImode spills from non-QI registers require
23425      intermediate register on 32bit targets.  */
23426   if (!in_p && mode == QImode && !TARGET_64BIT
23427       && (rclass == GENERAL_REGS
23428           || rclass == LEGACY_REGS
23429           || rclass == INDEX_REGS))
23430     {
23431       int regno;
23432
23433       if (REG_P (x))
23434         regno = REGNO (x);
23435       else
23436         regno = -1;
23437
23438       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
23439         regno = true_regnum (x);
23440
23441       /* Return Q_REGS if the operand is in memory.  */
23442       if (regno == -1)
23443         return Q_REGS;
23444     }
23445
23446   return NO_REGS;
23447 }
23448
23449 /* If we are copying between general and FP registers, we need a memory
23450    location. The same is true for SSE and MMX registers.
23451
23452    To optimize register_move_cost performance, allow inline variant.
23453
23454    The macro can't work reliably when one of the CLASSES is class containing
23455    registers from multiple units (SSE, MMX, integer).  We avoid this by never
23456    combining those units in single alternative in the machine description.
23457    Ensure that this constraint holds to avoid unexpected surprises.
23458
23459    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
23460    enforce these sanity checks.  */
23461
23462 static inline int
23463 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
23464                               enum machine_mode mode, int strict)
23465 {
23466   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
23467       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
23468       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
23469       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
23470       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
23471       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
23472     {
23473       gcc_assert (!strict);
23474       return true;
23475     }
23476
23477   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
23478     return true;
23479
23480   /* ??? This is a lie.  We do have moves between mmx/general, and for
23481      mmx/sse2.  But by saying we need secondary memory we discourage the
23482      register allocator from using the mmx registers unless needed.  */
23483   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
23484     return true;
23485
23486   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
23487     {
23488       /* SSE1 doesn't have any direct moves from other classes.  */
23489       if (!TARGET_SSE2)
23490         return true;
23491
23492       /* If the target says that inter-unit moves are more expensive
23493          than moving through memory, then don't generate them.  */
23494       if (!TARGET_INTER_UNIT_MOVES)
23495         return true;
23496
23497       /* Between SSE and general, we have moves no larger than word size.  */
23498       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
23499         return true;
23500     }
23501
23502   return false;
23503 }
23504
23505 int
23506 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
23507                               enum machine_mode mode, int strict)
23508 {
23509   return inline_secondary_memory_needed (class1, class2, mode, strict);
23510 }
23511
23512 /* Return true if the registers in CLASS cannot represent the change from
23513    modes FROM to TO.  */
23514
23515 bool
23516 ix86_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
23517                                enum reg_class regclass)
23518 {
23519   if (from == to)
23520     return false;
23521
23522   /* x87 registers can't do subreg at all, as all values are reformatted
23523      to extended precision.  */
23524   if (MAYBE_FLOAT_CLASS_P (regclass))
23525     return true;
23526
23527   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
23528     {
23529       /* Vector registers do not support QI or HImode loads.  If we don't
23530          disallow a change to these modes, reload will assume it's ok to
23531          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
23532          the vec_dupv4hi pattern.  */
23533       if (GET_MODE_SIZE (from) < 4)
23534         return true;
23535
23536       /* Vector registers do not support subreg with nonzero offsets, which
23537          are otherwise valid for integer registers.  Since we can't see
23538          whether we have a nonzero offset from here, prohibit all
23539          nonparadoxical subregs changing size.  */
23540       if (GET_MODE_SIZE (to) < GET_MODE_SIZE (from))
23541         return true;
23542     }
23543
23544   return false;
23545 }
23546
23547 /* Return the cost of moving data of mode M between a
23548    register and memory.  A value of 2 is the default; this cost is
23549    relative to those in `REGISTER_MOVE_COST'.
23550
23551    This function is used extensively by register_move_cost that is used to
23552    build tables at startup.  Make it inline in this case.
23553    When IN is 2, return maximum of in and out move cost.
23554
23555    If moving between registers and memory is more expensive than
23556    between two registers, you should define this macro to express the
23557    relative cost.
23558
23559    Model also increased moving costs of QImode registers in non
23560    Q_REGS classes.
23561  */
23562 static inline int
23563 inline_memory_move_cost (enum machine_mode mode, enum reg_class regclass,
23564                          int in)
23565 {
23566   int cost;
23567   if (FLOAT_CLASS_P (regclass))
23568     {
23569       int index;
23570       switch (mode)
23571         {
23572           case SFmode:
23573             index = 0;
23574             break;
23575           case DFmode:
23576             index = 1;
23577             break;
23578           case XFmode:
23579             index = 2;
23580             break;
23581           default:
23582             return 100;
23583         }
23584       if (in == 2)
23585         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
23586       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
23587     }
23588   if (SSE_CLASS_P (regclass))
23589     {
23590       int index;
23591       switch (GET_MODE_SIZE (mode))
23592         {
23593           case 4:
23594             index = 0;
23595             break;
23596           case 8:
23597             index = 1;
23598             break;
23599           case 16:
23600             index = 2;
23601             break;
23602           default:
23603             return 100;
23604         }
23605       if (in == 2)
23606         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
23607       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
23608     }
23609   if (MMX_CLASS_P (regclass))
23610     {
23611       int index;
23612       switch (GET_MODE_SIZE (mode))
23613         {
23614           case 4:
23615             index = 0;
23616             break;
23617           case 8:
23618             index = 1;
23619             break;
23620           default:
23621             return 100;
23622         }
23623       if (in)
23624         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
23625       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
23626     }
23627   switch (GET_MODE_SIZE (mode))
23628     {
23629       case 1:
23630         if (Q_CLASS_P (regclass) || TARGET_64BIT)
23631           {
23632             if (!in)
23633               return ix86_cost->int_store[0];
23634             if (TARGET_PARTIAL_REG_DEPENDENCY && !optimize_size)
23635               cost = ix86_cost->movzbl_load;
23636             else
23637               cost = ix86_cost->int_load[0];
23638             if (in == 2)
23639               return MAX (cost, ix86_cost->int_store[0]);
23640             return cost;
23641           }
23642         else
23643           {
23644            if (in == 2)
23645              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
23646            if (in)
23647              return ix86_cost->movzbl_load;
23648            else
23649              return ix86_cost->int_store[0] + 4;
23650           }
23651         break;
23652       case 2:
23653         if (in == 2)
23654           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
23655         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
23656       default:
23657         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
23658         if (mode == TFmode)
23659           mode = XFmode;
23660         if (in == 2)
23661           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
23662         else if (in)
23663           cost = ix86_cost->int_load[2];
23664         else
23665           cost = ix86_cost->int_store[2];
23666         return (cost * (((int) GET_MODE_SIZE (mode)
23667                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
23668     }
23669 }
23670
23671 int
23672 ix86_memory_move_cost (enum machine_mode mode, enum reg_class regclass, int in)
23673 {
23674   return inline_memory_move_cost (mode, regclass, in);
23675 }
23676
23677
23678 /* Return the cost of moving data from a register in class CLASS1 to
23679    one in class CLASS2.
23680
23681    It is not required that the cost always equal 2 when FROM is the same as TO;
23682    on some machines it is expensive to move between registers if they are not
23683    general registers.  */
23684
23685 int
23686 ix86_register_move_cost (enum machine_mode mode, enum reg_class class1,
23687                          enum reg_class class2)
23688 {
23689   /* In case we require secondary memory, compute cost of the store followed
23690      by load.  In order to avoid bad register allocation choices, we need
23691      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
23692
23693   if (inline_secondary_memory_needed (class1, class2, mode, 0))
23694     {
23695       int cost = 1;
23696
23697       cost += inline_memory_move_cost (mode, class1, 2);
23698       cost += inline_memory_move_cost (mode, class2, 2);
23699
23700       /* In case of copying from general_purpose_register we may emit multiple
23701          stores followed by single load causing memory size mismatch stall.
23702          Count this as arbitrarily high cost of 20.  */
23703       if (CLASS_MAX_NREGS (class1, mode) > CLASS_MAX_NREGS (class2, mode))
23704         cost += 20;
23705
23706       /* In the case of FP/MMX moves, the registers actually overlap, and we
23707          have to switch modes in order to treat them differently.  */
23708       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
23709           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
23710         cost += 20;
23711
23712       return cost;
23713     }
23714
23715   /* Moves between SSE/MMX and integer unit are expensive.  */
23716   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
23717       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
23718
23719     /* ??? By keeping returned value relatively high, we limit the number
23720        of moves between integer and MMX/SSE registers for all targets.
23721        Additionally, high value prevents problem with x86_modes_tieable_p(),
23722        where integer modes in MMX/SSE registers are not tieable
23723        because of missing QImode and HImode moves to, from or between
23724        MMX/SSE registers.  */
23725     return MAX (8, ix86_cost->mmxsse_to_integer);
23726
23727   if (MAYBE_FLOAT_CLASS_P (class1))
23728     return ix86_cost->fp_move;
23729   if (MAYBE_SSE_CLASS_P (class1))
23730     return ix86_cost->sse_move;
23731   if (MAYBE_MMX_CLASS_P (class1))
23732     return ix86_cost->mmx_move;
23733   return 2;
23734 }
23735
23736 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE.  */
23737
23738 bool
23739 ix86_hard_regno_mode_ok (int regno, enum machine_mode mode)
23740 {
23741   /* Flags and only flags can only hold CCmode values.  */
23742   if (CC_REGNO_P (regno))
23743     return GET_MODE_CLASS (mode) == MODE_CC;
23744   if (GET_MODE_CLASS (mode) == MODE_CC
23745       || GET_MODE_CLASS (mode) == MODE_RANDOM
23746       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
23747     return 0;
23748   if (FP_REGNO_P (regno))
23749     return VALID_FP_MODE_P (mode);
23750   if (SSE_REGNO_P (regno))
23751     {
23752       /* We implement the move patterns for all vector modes into and
23753          out of SSE registers, even when no operation instructions
23754          are available.  */
23755       return (VALID_SSE_REG_MODE (mode)
23756               || VALID_SSE2_REG_MODE (mode)
23757               || VALID_MMX_REG_MODE (mode)
23758               || VALID_MMX_REG_MODE_3DNOW (mode));
23759     }
23760   if (MMX_REGNO_P (regno))
23761     {
23762       /* We implement the move patterns for 3DNOW modes even in MMX mode,
23763          so if the register is available at all, then we can move data of
23764          the given mode into or out of it.  */
23765       return (VALID_MMX_REG_MODE (mode)
23766               || VALID_MMX_REG_MODE_3DNOW (mode));
23767     }
23768
23769   if (mode == QImode)
23770     {
23771       /* Take care for QImode values - they can be in non-QI regs,
23772          but then they do cause partial register stalls.  */
23773       if (regno < 4 || TARGET_64BIT)
23774         return 1;
23775       if (!TARGET_PARTIAL_REG_STALL)
23776         return 1;
23777       return reload_in_progress || reload_completed;
23778     }
23779   /* We handle both integer and floats in the general purpose registers.  */
23780   else if (VALID_INT_MODE_P (mode))
23781     return 1;
23782   else if (VALID_FP_MODE_P (mode))
23783     return 1;
23784   else if (VALID_DFP_MODE_P (mode))
23785     return 1;
23786   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
23787      on to use that value in smaller contexts, this can easily force a
23788      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
23789      supporting DImode, allow it.  */
23790   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
23791     return 1;
23792
23793   return 0;
23794 }
23795
23796 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
23797    tieable integer mode.  */
23798
23799 static bool
23800 ix86_tieable_integer_mode_p (enum machine_mode mode)
23801 {
23802   switch (mode)
23803     {
23804     case HImode:
23805     case SImode:
23806       return true;
23807
23808     case QImode:
23809       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
23810
23811     case DImode:
23812       return TARGET_64BIT;
23813
23814     default:
23815       return false;
23816     }
23817 }
23818
23819 /* Return true if MODE1 is accessible in a register that can hold MODE2
23820    without copying.  That is, all register classes that can hold MODE2
23821    can also hold MODE1.  */
23822
23823 bool
23824 ix86_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
23825 {
23826   if (mode1 == mode2)
23827     return true;
23828
23829   if (ix86_tieable_integer_mode_p (mode1)
23830       && ix86_tieable_integer_mode_p (mode2))
23831     return true;
23832
23833   /* MODE2 being XFmode implies fp stack or general regs, which means we
23834      can tie any smaller floating point modes to it.  Note that we do not
23835      tie this with TFmode.  */
23836   if (mode2 == XFmode)
23837     return mode1 == SFmode || mode1 == DFmode;
23838
23839   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
23840      that we can tie it with SFmode.  */
23841   if (mode2 == DFmode)
23842     return mode1 == SFmode;
23843
23844   /* If MODE2 is only appropriate for an SSE register, then tie with
23845      any other mode acceptable to SSE registers.  */
23846   if (GET_MODE_SIZE (mode2) == 16
23847       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
23848     return (GET_MODE_SIZE (mode1) == 16
23849             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
23850
23851   /* If MODE2 is appropriate for an MMX register, then tie
23852      with any other mode acceptable to MMX registers.  */
23853   if (GET_MODE_SIZE (mode2) == 8
23854       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
23855     return (GET_MODE_SIZE (mode1) == 8
23856             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
23857
23858   return false;
23859 }
23860
23861 /* Compute a (partial) cost for rtx X.  Return true if the complete
23862    cost has been computed, and false if subexpressions should be
23863    scanned.  In either case, *TOTAL contains the cost result.  */
23864
23865 static bool
23866 ix86_rtx_costs (rtx x, int code, int outer_code_i, int *total)
23867 {
23868   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
23869   enum machine_mode mode = GET_MODE (x);
23870
23871   switch (code)
23872     {
23873     case CONST_INT:
23874     case CONST:
23875     case LABEL_REF:
23876     case SYMBOL_REF:
23877       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
23878         *total = 3;
23879       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
23880         *total = 2;
23881       else if (flag_pic && SYMBOLIC_CONST (x)
23882                && (!TARGET_64BIT
23883                    || (!GET_CODE (x) != LABEL_REF
23884                        && (GET_CODE (x) != SYMBOL_REF
23885                            || !SYMBOL_REF_LOCAL_P (x)))))
23886         *total = 1;
23887       else
23888         *total = 0;
23889       return true;
23890
23891     case CONST_DOUBLE:
23892       if (mode == VOIDmode)
23893         *total = 0;
23894       else
23895         switch (standard_80387_constant_p (x))
23896           {
23897           case 1: /* 0.0 */
23898             *total = 1;
23899             break;
23900           default: /* Other constants */
23901             *total = 2;
23902             break;
23903           case 0:
23904           case -1:
23905             /* Start with (MEM (SYMBOL_REF)), since that's where
23906                it'll probably end up.  Add a penalty for size.  */
23907             *total = (COSTS_N_INSNS (1)
23908                       + (flag_pic != 0 && !TARGET_64BIT)
23909                       + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
23910             break;
23911           }
23912       return true;
23913
23914     case ZERO_EXTEND:
23915       /* The zero extensions is often completely free on x86_64, so make
23916          it as cheap as possible.  */
23917       if (TARGET_64BIT && mode == DImode
23918           && GET_MODE (XEXP (x, 0)) == SImode)
23919         *total = 1;
23920       else if (TARGET_ZERO_EXTEND_WITH_AND)
23921         *total = ix86_cost->add;
23922       else
23923         *total = ix86_cost->movzx;
23924       return false;
23925
23926     case SIGN_EXTEND:
23927       *total = ix86_cost->movsx;
23928       return false;
23929
23930     case ASHIFT:
23931       if (CONST_INT_P (XEXP (x, 1))
23932           && (GET_MODE (XEXP (x, 0)) != DImode || TARGET_64BIT))
23933         {
23934           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
23935           if (value == 1)
23936             {
23937               *total = ix86_cost->add;
23938               return false;
23939             }
23940           if ((value == 2 || value == 3)
23941               && ix86_cost->lea <= ix86_cost->shift_const)
23942             {
23943               *total = ix86_cost->lea;
23944               return false;
23945             }
23946         }
23947       /* FALLTHRU */
23948
23949     case ROTATE:
23950     case ASHIFTRT:
23951     case LSHIFTRT:
23952     case ROTATERT:
23953       if (!TARGET_64BIT && GET_MODE (XEXP (x, 0)) == DImode)
23954         {
23955           if (CONST_INT_P (XEXP (x, 1)))
23956             {
23957               if (INTVAL (XEXP (x, 1)) > 32)
23958                 *total = ix86_cost->shift_const + COSTS_N_INSNS (2);
23959               else
23960                 *total = ix86_cost->shift_const * 2;
23961             }
23962           else
23963             {
23964               if (GET_CODE (XEXP (x, 1)) == AND)
23965                 *total = ix86_cost->shift_var * 2;
23966               else
23967                 *total = ix86_cost->shift_var * 6 + COSTS_N_INSNS (2);
23968             }
23969         }
23970       else
23971         {
23972           if (CONST_INT_P (XEXP (x, 1)))
23973             *total = ix86_cost->shift_const;
23974           else
23975             *total = ix86_cost->shift_var;
23976         }
23977       return false;
23978
23979     case MULT:
23980       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
23981         {
23982           /* ??? SSE scalar cost should be used here.  */
23983           *total = ix86_cost->fmul;
23984           return false;
23985         }
23986       else if (X87_FLOAT_MODE_P (mode))
23987         {
23988           *total = ix86_cost->fmul;
23989           return false;
23990         }
23991       else if (FLOAT_MODE_P (mode))
23992         {
23993           /* ??? SSE vector cost should be used here.  */
23994           *total = ix86_cost->fmul;
23995           return false;
23996         }
23997       else
23998         {
23999           rtx op0 = XEXP (x, 0);
24000           rtx op1 = XEXP (x, 1);
24001           int nbits;
24002           if (CONST_INT_P (XEXP (x, 1)))
24003             {
24004               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
24005               for (nbits = 0; value != 0; value &= value - 1)
24006                 nbits++;
24007             }
24008           else
24009             /* This is arbitrary.  */
24010             nbits = 7;
24011
24012           /* Compute costs correctly for widening multiplication.  */
24013           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
24014               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
24015                  == GET_MODE_SIZE (mode))
24016             {
24017               int is_mulwiden = 0;
24018               enum machine_mode inner_mode = GET_MODE (op0);
24019
24020               if (GET_CODE (op0) == GET_CODE (op1))
24021                 is_mulwiden = 1, op1 = XEXP (op1, 0);
24022               else if (CONST_INT_P (op1))
24023                 {
24024                   if (GET_CODE (op0) == SIGN_EXTEND)
24025                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
24026                                   == INTVAL (op1);
24027                   else
24028                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
24029                 }
24030
24031               if (is_mulwiden)
24032                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
24033             }
24034
24035           *total = (ix86_cost->mult_init[MODE_INDEX (mode)]
24036                     + nbits * ix86_cost->mult_bit
24037                     + rtx_cost (op0, outer_code) + rtx_cost (op1, outer_code));
24038
24039           return true;
24040         }
24041
24042     case DIV:
24043     case UDIV:
24044     case MOD:
24045     case UMOD:
24046       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
24047         /* ??? SSE cost should be used here.  */
24048         *total = ix86_cost->fdiv;
24049       else if (X87_FLOAT_MODE_P (mode))
24050         *total = ix86_cost->fdiv;
24051       else if (FLOAT_MODE_P (mode))
24052         /* ??? SSE vector cost should be used here.  */
24053         *total = ix86_cost->fdiv;
24054       else
24055         *total = ix86_cost->divide[MODE_INDEX (mode)];
24056       return false;
24057
24058     case PLUS:
24059       if (GET_MODE_CLASS (mode) == MODE_INT
24060                && GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (Pmode))
24061         {
24062           if (GET_CODE (XEXP (x, 0)) == PLUS
24063               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
24064               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
24065               && CONSTANT_P (XEXP (x, 1)))
24066             {
24067               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
24068               if (val == 2 || val == 4 || val == 8)
24069                 {
24070                   *total = ix86_cost->lea;
24071                   *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code);
24072                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
24073                                       outer_code);
24074                   *total += rtx_cost (XEXP (x, 1), outer_code);
24075                   return true;
24076                 }
24077             }
24078           else if (GET_CODE (XEXP (x, 0)) == MULT
24079                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
24080             {
24081               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
24082               if (val == 2 || val == 4 || val == 8)
24083                 {
24084                   *total = ix86_cost->lea;
24085                   *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code);
24086                   *total += rtx_cost (XEXP (x, 1), outer_code);
24087                   return true;
24088                 }
24089             }
24090           else if (GET_CODE (XEXP (x, 0)) == PLUS)
24091             {
24092               *total = ix86_cost->lea;
24093               *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code);
24094               *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code);
24095               *total += rtx_cost (XEXP (x, 1), outer_code);
24096               return true;
24097             }
24098         }
24099       /* FALLTHRU */
24100
24101     case MINUS:
24102       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
24103         {
24104           /* ??? SSE cost should be used here.  */
24105           *total = ix86_cost->fadd;
24106           return false;
24107         }
24108       else if (X87_FLOAT_MODE_P (mode))
24109         {
24110           *total = ix86_cost->fadd;
24111           return false;
24112         }
24113       else if (FLOAT_MODE_P (mode))
24114         {
24115           /* ??? SSE vector cost should be used here.  */
24116           *total = ix86_cost->fadd;
24117           return false;
24118         }
24119       /* FALLTHRU */
24120
24121     case AND:
24122     case IOR:
24123     case XOR:
24124       if (!TARGET_64BIT && mode == DImode)
24125         {
24126           *total = (ix86_cost->add * 2
24127                     + (rtx_cost (XEXP (x, 0), outer_code)
24128                        << (GET_MODE (XEXP (x, 0)) != DImode))
24129                     + (rtx_cost (XEXP (x, 1), outer_code)
24130                        << (GET_MODE (XEXP (x, 1)) != DImode)));
24131           return true;
24132         }
24133       /* FALLTHRU */
24134
24135     case NEG:
24136       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
24137         {
24138           /* ??? SSE cost should be used here.  */
24139           *total = ix86_cost->fchs;
24140           return false;
24141         }
24142       else if (X87_FLOAT_MODE_P (mode))
24143         {
24144           *total = ix86_cost->fchs;
24145           return false;
24146         }
24147       else if (FLOAT_MODE_P (mode))
24148         {
24149           /* ??? SSE vector cost should be used here.  */
24150           *total = ix86_cost->fchs;
24151           return false;
24152         }
24153       /* FALLTHRU */
24154
24155     case NOT:
24156       if (!TARGET_64BIT && mode == DImode)
24157         *total = ix86_cost->add * 2;
24158       else
24159         *total = ix86_cost->add;
24160       return false;
24161
24162     case COMPARE:
24163       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
24164           && XEXP (XEXP (x, 0), 1) == const1_rtx
24165           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
24166           && XEXP (x, 1) == const0_rtx)
24167         {
24168           /* This kind of construct is implemented using test[bwl].
24169              Treat it as if we had an AND.  */
24170           *total = (ix86_cost->add
24171                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code)
24172                     + rtx_cost (const1_rtx, outer_code));
24173           return true;
24174         }
24175       return false;
24176
24177     case FLOAT_EXTEND:
24178       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
24179         *total = 0;
24180       return false;
24181
24182     case ABS:
24183       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
24184         /* ??? SSE cost should be used here.  */
24185         *total = ix86_cost->fabs;
24186       else if (X87_FLOAT_MODE_P (mode))
24187         *total = ix86_cost->fabs;
24188       else if (FLOAT_MODE_P (mode))
24189         /* ??? SSE vector cost should be used here.  */
24190         *total = ix86_cost->fabs;
24191       return false;
24192
24193     case SQRT:
24194       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
24195         /* ??? SSE cost should be used here.  */
24196         *total = ix86_cost->fsqrt;
24197       else if (X87_FLOAT_MODE_P (mode))
24198         *total = ix86_cost->fsqrt;
24199       else if (FLOAT_MODE_P (mode))
24200         /* ??? SSE vector cost should be used here.  */
24201         *total = ix86_cost->fsqrt;
24202       return false;
24203
24204     case UNSPEC:
24205       if (XINT (x, 1) == UNSPEC_TP)
24206         *total = 0;
24207       return false;
24208
24209     default:
24210       return false;
24211     }
24212 }
24213
24214 #if TARGET_MACHO
24215
24216 static int current_machopic_label_num;
24217
24218 /* Given a symbol name and its associated stub, write out the
24219    definition of the stub.  */
24220
24221 void
24222 machopic_output_stub (FILE *file, const char *symb, const char *stub)
24223 {
24224   unsigned int length;
24225   char *binder_name, *symbol_name, lazy_ptr_name[32];
24226   int label = ++current_machopic_label_num;
24227
24228   /* For 64-bit we shouldn't get here.  */
24229   gcc_assert (!TARGET_64BIT);
24230
24231   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
24232   symb = (*targetm.strip_name_encoding) (symb);
24233
24234   length = strlen (stub);
24235   binder_name = XALLOCAVEC (char, length + 32);
24236   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
24237
24238   length = strlen (symb);
24239   symbol_name = XALLOCAVEC (char, length + 32);
24240   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
24241
24242   sprintf (lazy_ptr_name, "L%d$lz", label);
24243
24244   if (MACHOPIC_PURE)
24245     switch_to_section (darwin_sections[machopic_picsymbol_stub_section]);
24246   else
24247     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
24248
24249   fprintf (file, "%s:\n", stub);
24250   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
24251
24252   if (MACHOPIC_PURE)
24253     {
24254       fprintf (file, "\tcall\tLPC$%d\nLPC$%d:\tpopl\t%%eax\n", label, label);
24255       fprintf (file, "\tmovl\t%s-LPC$%d(%%eax),%%edx\n", lazy_ptr_name, label);
24256       fprintf (file, "\tjmp\t*%%edx\n");
24257     }
24258   else
24259     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
24260
24261   fprintf (file, "%s:\n", binder_name);
24262
24263   if (MACHOPIC_PURE)
24264     {
24265       fprintf (file, "\tlea\t%s-LPC$%d(%%eax),%%eax\n", lazy_ptr_name, label);
24266       fprintf (file, "\tpushl\t%%eax\n");
24267     }
24268   else
24269     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
24270
24271   fprintf (file, "\tjmp\tdyld_stub_binding_helper\n");
24272
24273   switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
24274   fprintf (file, "%s:\n", lazy_ptr_name);
24275   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
24276   fprintf (file, "\t.long %s\n", binder_name);
24277 }
24278
24279 void
24280 darwin_x86_file_end (void)
24281 {
24282   darwin_file_end ();
24283   ix86_file_end ();
24284 }
24285 #endif /* TARGET_MACHO */
24286
24287 /* Order the registers for register allocator.  */
24288
24289 void
24290 x86_order_regs_for_local_alloc (void)
24291 {
24292    int pos = 0;
24293    int i;
24294
24295    /* First allocate the local general purpose registers.  */
24296    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
24297      if (GENERAL_REGNO_P (i) && call_used_regs[i])
24298         reg_alloc_order [pos++] = i;
24299
24300    /* Global general purpose registers.  */
24301    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
24302      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
24303         reg_alloc_order [pos++] = i;
24304
24305    /* x87 registers come first in case we are doing FP math
24306       using them.  */
24307    if (!TARGET_SSE_MATH)
24308      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
24309        reg_alloc_order [pos++] = i;
24310
24311    /* SSE registers.  */
24312    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
24313      reg_alloc_order [pos++] = i;
24314    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
24315      reg_alloc_order [pos++] = i;
24316
24317    /* x87 registers.  */
24318    if (TARGET_SSE_MATH)
24319      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
24320        reg_alloc_order [pos++] = i;
24321
24322    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
24323      reg_alloc_order [pos++] = i;
24324
24325    /* Initialize the rest of array as we do not allocate some registers
24326       at all.  */
24327    while (pos < FIRST_PSEUDO_REGISTER)
24328      reg_alloc_order [pos++] = 0;
24329 }
24330
24331 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
24332    struct attribute_spec.handler.  */
24333 static tree
24334 ix86_handle_abi_attribute (tree *node, tree name,
24335                               tree args ATTRIBUTE_UNUSED,
24336                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
24337 {
24338   if (TREE_CODE (*node) != FUNCTION_TYPE
24339       && TREE_CODE (*node) != METHOD_TYPE
24340       && TREE_CODE (*node) != FIELD_DECL
24341       && TREE_CODE (*node) != TYPE_DECL)
24342     {
24343       warning (OPT_Wattributes, "%qs attribute only applies to functions",
24344                IDENTIFIER_POINTER (name));
24345       *no_add_attrs = true;
24346       return NULL_TREE;
24347     }
24348   if (!TARGET_64BIT)
24349     {
24350       warning (OPT_Wattributes, "%qs attribute only available for 64-bit",
24351                IDENTIFIER_POINTER (name));
24352       *no_add_attrs = true;
24353       return NULL_TREE;
24354     }
24355
24356   /* Can combine regparm with all attributes but fastcall.  */
24357   if (is_attribute_p ("ms_abi", name))
24358     {
24359       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
24360         {
24361           error ("ms_abi and sysv_abi attributes are not compatible");
24362         }
24363
24364       return NULL_TREE;
24365     }
24366   else if (is_attribute_p ("sysv_abi", name))
24367     {
24368       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
24369         {
24370           error ("ms_abi and sysv_abi attributes are not compatible");
24371         }
24372
24373       return NULL_TREE;
24374     }
24375
24376   return NULL_TREE;
24377 }
24378
24379 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
24380    struct attribute_spec.handler.  */
24381 static tree
24382 ix86_handle_struct_attribute (tree *node, tree name,
24383                               tree args ATTRIBUTE_UNUSED,
24384                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
24385 {
24386   tree *type = NULL;
24387   if (DECL_P (*node))
24388     {
24389       if (TREE_CODE (*node) == TYPE_DECL)
24390         type = &TREE_TYPE (*node);
24391     }
24392   else
24393     type = node;
24394
24395   if (!(type && (TREE_CODE (*type) == RECORD_TYPE
24396                  || TREE_CODE (*type) == UNION_TYPE)))
24397     {
24398       warning (OPT_Wattributes, "%qs attribute ignored",
24399                IDENTIFIER_POINTER (name));
24400       *no_add_attrs = true;
24401     }
24402
24403   else if ((is_attribute_p ("ms_struct", name)
24404             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
24405            || ((is_attribute_p ("gcc_struct", name)
24406                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
24407     {
24408       warning (OPT_Wattributes, "%qs incompatible attribute ignored",
24409                IDENTIFIER_POINTER (name));
24410       *no_add_attrs = true;
24411     }
24412
24413   return NULL_TREE;
24414 }
24415
24416 static bool
24417 ix86_ms_bitfield_layout_p (const_tree record_type)
24418 {
24419   return (TARGET_MS_BITFIELD_LAYOUT &&
24420           !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
24421     || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
24422 }
24423
24424 /* Returns an expression indicating where the this parameter is
24425    located on entry to the FUNCTION.  */
24426
24427 static rtx
24428 x86_this_parameter (tree function)
24429 {
24430   tree type = TREE_TYPE (function);
24431   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
24432   int nregs;
24433
24434   if (TARGET_64BIT)
24435     {
24436       const int *parm_regs;
24437
24438       if (ix86_function_type_abi (type) == MS_ABI)
24439         parm_regs = x86_64_ms_abi_int_parameter_registers;
24440       else
24441         parm_regs = x86_64_int_parameter_registers;
24442       return gen_rtx_REG (DImode, parm_regs[aggr]);
24443     }
24444
24445   nregs = ix86_function_regparm (type, function);
24446
24447   if (nregs > 0 && !stdarg_p (type))
24448     {
24449       int regno;
24450
24451       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
24452         regno = aggr ? DX_REG : CX_REG;
24453       else
24454         {
24455           regno = AX_REG;
24456           if (aggr)
24457             {
24458               regno = DX_REG;
24459               if (nregs == 1)
24460                 return gen_rtx_MEM (SImode,
24461                                     plus_constant (stack_pointer_rtx, 4));
24462             }
24463         }
24464       return gen_rtx_REG (SImode, regno);
24465     }
24466
24467   return gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx, aggr ? 8 : 4));
24468 }
24469
24470 /* Determine whether x86_output_mi_thunk can succeed.  */
24471
24472 static bool
24473 x86_can_output_mi_thunk (const_tree thunk ATTRIBUTE_UNUSED,
24474                          HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
24475                          HOST_WIDE_INT vcall_offset, const_tree function)
24476 {
24477   /* 64-bit can handle anything.  */
24478   if (TARGET_64BIT)
24479     return true;
24480
24481   /* For 32-bit, everything's fine if we have one free register.  */
24482   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
24483     return true;
24484
24485   /* Need a free register for vcall_offset.  */
24486   if (vcall_offset)
24487     return false;
24488
24489   /* Need a free register for GOT references.  */
24490   if (flag_pic && !(*targetm.binds_local_p) (function))
24491     return false;
24492
24493   /* Otherwise ok.  */
24494   return true;
24495 }
24496
24497 /* Output the assembler code for a thunk function.  THUNK_DECL is the
24498    declaration for the thunk function itself, FUNCTION is the decl for
24499    the target function.  DELTA is an immediate constant offset to be
24500    added to THIS.  If VCALL_OFFSET is nonzero, the word at
24501    *(*this + vcall_offset) should be added to THIS.  */
24502
24503 static void
24504 x86_output_mi_thunk (FILE *file ATTRIBUTE_UNUSED,
24505                      tree thunk ATTRIBUTE_UNUSED, HOST_WIDE_INT delta,
24506                      HOST_WIDE_INT vcall_offset, tree function)
24507 {
24508   rtx xops[3];
24509   rtx this_param = x86_this_parameter (function);
24510   rtx this_reg, tmp;
24511
24512   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
24513      pull it in now and let DELTA benefit.  */
24514   if (REG_P (this_param))
24515     this_reg = this_param;
24516   else if (vcall_offset)
24517     {
24518       /* Put the this parameter into %eax.  */
24519       xops[0] = this_param;
24520       xops[1] = this_reg = gen_rtx_REG (Pmode, AX_REG);
24521       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
24522     }
24523   else
24524     this_reg = NULL_RTX;
24525
24526   /* Adjust the this parameter by a fixed constant.  */
24527   if (delta)
24528     {
24529       xops[0] = GEN_INT (delta);
24530       xops[1] = this_reg ? this_reg : this_param;
24531       if (TARGET_64BIT)
24532         {
24533           if (!x86_64_general_operand (xops[0], DImode))
24534             {
24535               tmp = gen_rtx_REG (DImode, R10_REG);
24536               xops[1] = tmp;
24537               output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", xops);
24538               xops[0] = tmp;
24539               xops[1] = this_param;
24540             }
24541           output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
24542         }
24543       else
24544         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
24545     }
24546
24547   /* Adjust the this parameter by a value stored in the vtable.  */
24548   if (vcall_offset)
24549     {
24550       if (TARGET_64BIT)
24551         tmp = gen_rtx_REG (DImode, R10_REG);
24552       else
24553         {
24554           int tmp_regno = CX_REG;
24555           if (lookup_attribute ("fastcall",
24556                                 TYPE_ATTRIBUTES (TREE_TYPE (function))))
24557             tmp_regno = AX_REG;
24558           tmp = gen_rtx_REG (SImode, tmp_regno);
24559         }
24560
24561       xops[0] = gen_rtx_MEM (Pmode, this_reg);
24562       xops[1] = tmp;
24563       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
24564
24565       /* Adjust the this parameter.  */
24566       xops[0] = gen_rtx_MEM (Pmode, plus_constant (tmp, vcall_offset));
24567       if (TARGET_64BIT && !memory_operand (xops[0], Pmode))
24568         {
24569           rtx tmp2 = gen_rtx_REG (DImode, R11_REG);
24570           xops[0] = GEN_INT (vcall_offset);
24571           xops[1] = tmp2;
24572           output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
24573           xops[0] = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, tmp, tmp2));
24574         }
24575       xops[1] = this_reg;
24576       output_asm_insn ("add%z1\t{%0, %1|%1, %0}", xops);
24577     }
24578
24579   /* If necessary, drop THIS back to its stack slot.  */
24580   if (this_reg && this_reg != this_param)
24581     {
24582       xops[0] = this_reg;
24583       xops[1] = this_param;
24584       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
24585     }
24586
24587   xops[0] = XEXP (DECL_RTL (function), 0);
24588   if (TARGET_64BIT)
24589     {
24590       if (!flag_pic || (*targetm.binds_local_p) (function))
24591         output_asm_insn ("jmp\t%P0", xops);
24592       /* All thunks should be in the same object as their target,
24593          and thus binds_local_p should be true.  */
24594       else if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
24595         gcc_unreachable ();
24596       else
24597         {
24598           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xops[0]), UNSPEC_GOTPCREL);
24599           tmp = gen_rtx_CONST (Pmode, tmp);
24600           tmp = gen_rtx_MEM (QImode, tmp);
24601           xops[0] = tmp;
24602           output_asm_insn ("jmp\t%A0", xops);
24603         }
24604     }
24605   else
24606     {
24607       if (!flag_pic || (*targetm.binds_local_p) (function))
24608         output_asm_insn ("jmp\t%P0", xops);
24609       else
24610 #if TARGET_MACHO
24611         if (TARGET_MACHO)
24612           {
24613             rtx sym_ref = XEXP (DECL_RTL (function), 0);
24614             tmp = (gen_rtx_SYMBOL_REF
24615                    (Pmode,
24616                     machopic_indirection_name (sym_ref, /*stub_p=*/true)));
24617             tmp = gen_rtx_MEM (QImode, tmp);
24618             xops[0] = tmp;
24619             output_asm_insn ("jmp\t%0", xops);
24620           }
24621         else
24622 #endif /* TARGET_MACHO */
24623         {
24624           tmp = gen_rtx_REG (SImode, CX_REG);
24625           output_set_got (tmp, NULL_RTX);
24626
24627           xops[1] = tmp;
24628           output_asm_insn ("mov{l}\t{%0@GOT(%1), %1|%1, %0@GOT[%1]}", xops);
24629           output_asm_insn ("jmp\t{*}%1", xops);
24630         }
24631     }
24632 }
24633
24634 static void
24635 x86_file_start (void)
24636 {
24637   default_file_start ();
24638 #if TARGET_MACHO
24639   darwin_file_start ();
24640 #endif
24641   if (X86_FILE_START_VERSION_DIRECTIVE)
24642     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
24643   if (X86_FILE_START_FLTUSED)
24644     fputs ("\t.global\t__fltused\n", asm_out_file);
24645   if (ix86_asm_dialect == ASM_INTEL)
24646     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
24647 }
24648
24649 int
24650 x86_field_alignment (tree field, int computed)
24651 {
24652   enum machine_mode mode;
24653   tree type = TREE_TYPE (field);
24654
24655   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
24656     return computed;
24657   mode = TYPE_MODE (strip_array_types (type));
24658   if (mode == DFmode || mode == DCmode
24659       || GET_MODE_CLASS (mode) == MODE_INT
24660       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
24661     return MIN (32, computed);
24662   return computed;
24663 }
24664
24665 /* Output assembler code to FILE to increment profiler label # LABELNO
24666    for profiling a function entry.  */
24667 void
24668 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
24669 {
24670   if (TARGET_64BIT)
24671     {
24672 #ifndef NO_PROFILE_COUNTERS
24673       fprintf (file, "\tleaq\t%sP%d@(%%rip),%%r11\n", LPREFIX, labelno);
24674 #endif
24675
24676       if (DEFAULT_ABI == SYSV_ABI && flag_pic)
24677         fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", MCOUNT_NAME);
24678       else
24679         fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
24680     }
24681   else if (flag_pic)
24682     {
24683 #ifndef NO_PROFILE_COUNTERS
24684       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%%s\n",
24685                LPREFIX, labelno, PROFILE_COUNT_REGISTER);
24686 #endif
24687       fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", MCOUNT_NAME);
24688     }
24689   else
24690     {
24691 #ifndef NO_PROFILE_COUNTERS
24692       fprintf (file, "\tmovl\t$%sP%d,%%%s\n", LPREFIX, labelno,
24693                PROFILE_COUNT_REGISTER);
24694 #endif
24695       fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
24696     }
24697 }
24698
24699 /* We don't have exact information about the insn sizes, but we may assume
24700    quite safely that we are informed about all 1 byte insns and memory
24701    address sizes.  This is enough to eliminate unnecessary padding in
24702    99% of cases.  */
24703
24704 static int
24705 min_insn_size (rtx insn)
24706 {
24707   int l = 0;
24708
24709   if (!INSN_P (insn) || !active_insn_p (insn))
24710     return 0;
24711
24712   /* Discard alignments we've emit and jump instructions.  */
24713   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
24714       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
24715     return 0;
24716   if (JUMP_P (insn)
24717       && (GET_CODE (PATTERN (insn)) == ADDR_VEC
24718           || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
24719     return 0;
24720
24721   /* Important case - calls are always 5 bytes.
24722      It is common to have many calls in the row.  */
24723   if (CALL_P (insn)
24724       && symbolic_reference_mentioned_p (PATTERN (insn))
24725       && !SIBLING_CALL_P (insn))
24726     return 5;
24727   if (get_attr_length (insn) <= 1)
24728     return 1;
24729
24730   /* For normal instructions we may rely on the sizes of addresses
24731      and the presence of symbol to require 4 bytes of encoding.
24732      This is not the case for jumps where references are PC relative.  */
24733   if (!JUMP_P (insn))
24734     {
24735       l = get_attr_length_address (insn);
24736       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
24737         l = 4;
24738     }
24739   if (l)
24740     return 1+l;
24741   else
24742     return 2;
24743 }
24744
24745 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
24746    window.  */
24747
24748 static void
24749 ix86_avoid_jump_misspredicts (void)
24750 {
24751   rtx insn, start = get_insns ();
24752   int nbytes = 0, njumps = 0;
24753   int isjump = 0;
24754
24755   /* Look for all minimal intervals of instructions containing 4 jumps.
24756      The intervals are bounded by START and INSN.  NBYTES is the total
24757      size of instructions in the interval including INSN and not including
24758      START.  When the NBYTES is smaller than 16 bytes, it is possible
24759      that the end of START and INSN ends up in the same 16byte page.
24760
24761      The smallest offset in the page INSN can start is the case where START
24762      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
24763      We add p2align to 16byte window with maxskip 17 - NBYTES + sizeof (INSN).
24764      */
24765   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
24766     {
24767
24768       nbytes += min_insn_size (insn);
24769       if (dump_file)
24770         fprintf(dump_file, "Insn %i estimated to %i bytes\n",
24771                 INSN_UID (insn), min_insn_size (insn));
24772       if ((JUMP_P (insn)
24773            && GET_CODE (PATTERN (insn)) != ADDR_VEC
24774            && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
24775           || CALL_P (insn))
24776         njumps++;
24777       else
24778         continue;
24779
24780       while (njumps > 3)
24781         {
24782           start = NEXT_INSN (start);
24783           if ((JUMP_P (start)
24784                && GET_CODE (PATTERN (start)) != ADDR_VEC
24785                && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
24786               || CALL_P (start))
24787             njumps--, isjump = 1;
24788           else
24789             isjump = 0;
24790           nbytes -= min_insn_size (start);
24791         }
24792       gcc_assert (njumps >= 0);
24793       if (dump_file)
24794         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
24795                 INSN_UID (start), INSN_UID (insn), nbytes);
24796
24797       if (njumps == 3 && isjump && nbytes < 16)
24798         {
24799           int padsize = 15 - nbytes + min_insn_size (insn);
24800
24801           if (dump_file)
24802             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
24803                      INSN_UID (insn), padsize);
24804           emit_insn_before (gen_align (GEN_INT (padsize)), insn);
24805         }
24806     }
24807 }
24808
24809 /* AMD Athlon works faster
24810    when RET is not destination of conditional jump or directly preceded
24811    by other jump instruction.  We avoid the penalty by inserting NOP just
24812    before the RET instructions in such cases.  */
24813 static void
24814 ix86_pad_returns (void)
24815 {
24816   edge e;
24817   edge_iterator ei;
24818
24819   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
24820     {
24821       basic_block bb = e->src;
24822       rtx ret = BB_END (bb);
24823       rtx prev;
24824       bool replace = false;
24825
24826       if (!JUMP_P (ret) || GET_CODE (PATTERN (ret)) != RETURN
24827           || !maybe_hot_bb_p (bb))
24828         continue;
24829       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
24830         if (active_insn_p (prev) || LABEL_P (prev))
24831           break;
24832       if (prev && LABEL_P (prev))
24833         {
24834           edge e;
24835           edge_iterator ei;
24836
24837           FOR_EACH_EDGE (e, ei, bb->preds)
24838             if (EDGE_FREQUENCY (e) && e->src->index >= 0
24839                 && !(e->flags & EDGE_FALLTHRU))
24840               replace = true;
24841         }
24842       if (!replace)
24843         {
24844           prev = prev_active_insn (ret);
24845           if (prev
24846               && ((JUMP_P (prev) && any_condjump_p (prev))
24847                   || CALL_P (prev)))
24848             replace = true;
24849           /* Empty functions get branch mispredict even when the jump destination
24850              is not visible to us.  */
24851           if (!prev && cfun->function_frequency > FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
24852             replace = true;
24853         }
24854       if (replace)
24855         {
24856           emit_insn_before (gen_return_internal_long (), ret);
24857           delete_insn (ret);
24858         }
24859     }
24860 }
24861
24862 /* Implement machine specific optimizations.  We implement padding of returns
24863    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
24864 static void
24865 ix86_reorg (void)
24866 {
24867   if (TARGET_PAD_RETURNS && optimize && !optimize_size)
24868     ix86_pad_returns ();
24869   if (TARGET_FOUR_JUMP_LIMIT && optimize && !optimize_size)
24870     ix86_avoid_jump_misspredicts ();
24871 }
24872
24873 /* Return nonzero when QImode register that must be represented via REX prefix
24874    is used.  */
24875 bool
24876 x86_extended_QIreg_mentioned_p (rtx insn)
24877 {
24878   int i;
24879   extract_insn_cached (insn);
24880   for (i = 0; i < recog_data.n_operands; i++)
24881     if (REG_P (recog_data.operand[i])
24882         && REGNO (recog_data.operand[i]) >= 4)
24883        return true;
24884   return false;
24885 }
24886
24887 /* Return nonzero when P points to register encoded via REX prefix.
24888    Called via for_each_rtx.  */
24889 static int
24890 extended_reg_mentioned_1 (rtx *p, void *data ATTRIBUTE_UNUSED)
24891 {
24892    unsigned int regno;
24893    if (!REG_P (*p))
24894      return 0;
24895    regno = REGNO (*p);
24896    return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
24897 }
24898
24899 /* Return true when INSN mentions register that must be encoded using REX
24900    prefix.  */
24901 bool
24902 x86_extended_reg_mentioned_p (rtx insn)
24903 {
24904   return for_each_rtx (&PATTERN (insn), extended_reg_mentioned_1, NULL);
24905 }
24906
24907 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
24908    optabs would emit if we didn't have TFmode patterns.  */
24909
24910 void
24911 x86_emit_floatuns (rtx operands[2])
24912 {
24913   rtx neglab, donelab, i0, i1, f0, in, out;
24914   enum machine_mode mode, inmode;
24915
24916   inmode = GET_MODE (operands[1]);
24917   gcc_assert (inmode == SImode || inmode == DImode);
24918
24919   out = operands[0];
24920   in = force_reg (inmode, operands[1]);
24921   mode = GET_MODE (out);
24922   neglab = gen_label_rtx ();
24923   donelab = gen_label_rtx ();
24924   f0 = gen_reg_rtx (mode);
24925
24926   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
24927
24928   expand_float (out, in, 0);
24929
24930   emit_jump_insn (gen_jump (donelab));
24931   emit_barrier ();
24932
24933   emit_label (neglab);
24934
24935   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
24936                             1, OPTAB_DIRECT);
24937   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
24938                             1, OPTAB_DIRECT);
24939   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
24940
24941   expand_float (f0, i0, 0);
24942
24943   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
24944
24945   emit_label (donelab);
24946 }
24947 \f
24948 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
24949    with all elements equal to VAR.  Return true if successful.  */
24950
24951 static bool
24952 ix86_expand_vector_init_duplicate (bool mmx_ok, enum machine_mode mode,
24953                                    rtx target, rtx val)
24954 {
24955   enum machine_mode smode, wsmode, wvmode;
24956   rtx x;
24957
24958   switch (mode)
24959     {
24960     case V2SImode:
24961     case V2SFmode:
24962       if (!mmx_ok)
24963         return false;
24964       /* FALLTHRU */
24965
24966     case V2DFmode:
24967     case V2DImode:
24968     case V4SFmode:
24969     case V4SImode:
24970       val = force_reg (GET_MODE_INNER (mode), val);
24971       x = gen_rtx_VEC_DUPLICATE (mode, val);
24972       emit_insn (gen_rtx_SET (VOIDmode, target, x));
24973       return true;
24974
24975     case V4HImode:
24976       if (!mmx_ok)
24977         return false;
24978       if (TARGET_SSE || TARGET_3DNOW_A)
24979         {
24980           val = gen_lowpart (SImode, val);
24981           x = gen_rtx_TRUNCATE (HImode, val);
24982           x = gen_rtx_VEC_DUPLICATE (mode, x);
24983           emit_insn (gen_rtx_SET (VOIDmode, target, x));
24984           return true;
24985         }
24986       else
24987         {
24988           smode = HImode;
24989           wsmode = SImode;
24990           wvmode = V2SImode;
24991           goto widen;
24992         }
24993
24994     case V8QImode:
24995       if (!mmx_ok)
24996         return false;
24997       smode = QImode;
24998       wsmode = HImode;
24999       wvmode = V4HImode;
25000       goto widen;
25001     case V8HImode:
25002       if (TARGET_SSE2)
25003         {
25004           rtx tmp1, tmp2;
25005           /* Extend HImode to SImode using a paradoxical SUBREG.  */
25006           tmp1 = gen_reg_rtx (SImode);
25007           emit_move_insn (tmp1, gen_lowpart (SImode, val));
25008           /* Insert the SImode value as low element of V4SImode vector. */
25009           tmp2 = gen_reg_rtx (V4SImode);
25010           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
25011                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
25012                                     CONST0_RTX (V4SImode),
25013                                     const1_rtx);
25014           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
25015           /* Cast the V4SImode vector back to a V8HImode vector.  */
25016           tmp1 = gen_reg_rtx (V8HImode);
25017           emit_move_insn (tmp1, gen_lowpart (V8HImode, tmp2));
25018           /* Duplicate the low short through the whole low SImode word.  */
25019           emit_insn (gen_sse2_punpcklwd (tmp1, tmp1, tmp1));
25020           /* Cast the V8HImode vector back to a V4SImode vector.  */
25021           tmp2 = gen_reg_rtx (V4SImode);
25022           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
25023           /* Replicate the low element of the V4SImode vector.  */
25024           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
25025           /* Cast the V2SImode back to V8HImode, and store in target.  */
25026           emit_move_insn (target, gen_lowpart (V8HImode, tmp2));
25027           return true;
25028         }
25029       smode = HImode;
25030       wsmode = SImode;
25031       wvmode = V4SImode;
25032       goto widen;
25033     case V16QImode:
25034       if (TARGET_SSE2)
25035         {
25036           rtx tmp1, tmp2;
25037           /* Extend QImode to SImode using a paradoxical SUBREG.  */
25038           tmp1 = gen_reg_rtx (SImode);
25039           emit_move_insn (tmp1, gen_lowpart (SImode, val));
25040           /* Insert the SImode value as low element of V4SImode vector. */
25041           tmp2 = gen_reg_rtx (V4SImode);
25042           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
25043                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
25044                                     CONST0_RTX (V4SImode),
25045                                     const1_rtx);
25046           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
25047           /* Cast the V4SImode vector back to a V16QImode vector.  */
25048           tmp1 = gen_reg_rtx (V16QImode);
25049           emit_move_insn (tmp1, gen_lowpart (V16QImode, tmp2));
25050           /* Duplicate the low byte through the whole low SImode word.  */
25051           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
25052           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
25053           /* Cast the V16QImode vector back to a V4SImode vector.  */
25054           tmp2 = gen_reg_rtx (V4SImode);
25055           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
25056           /* Replicate the low element of the V4SImode vector.  */
25057           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
25058           /* Cast the V2SImode back to V16QImode, and store in target.  */
25059           emit_move_insn (target, gen_lowpart (V16QImode, tmp2));
25060           return true;
25061         }
25062       smode = QImode;
25063       wsmode = HImode;
25064       wvmode = V8HImode;
25065       goto widen;
25066     widen:
25067       /* Replicate the value once into the next wider mode and recurse.  */
25068       val = convert_modes (wsmode, smode, val, true);
25069       x = expand_simple_binop (wsmode, ASHIFT, val,
25070                                GEN_INT (GET_MODE_BITSIZE (smode)),
25071                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
25072       val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
25073
25074       x = gen_reg_rtx (wvmode);
25075       if (!ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val))
25076         gcc_unreachable ();
25077       emit_move_insn (target, gen_lowpart (mode, x));
25078       return true;
25079
25080     default:
25081       return false;
25082     }
25083 }
25084
25085 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
25086    whose ONE_VAR element is VAR, and other elements are zero.  Return true
25087    if successful.  */
25088
25089 static bool
25090 ix86_expand_vector_init_one_nonzero (bool mmx_ok, enum machine_mode mode,
25091                                      rtx target, rtx var, int one_var)
25092 {
25093   enum machine_mode vsimode;
25094   rtx new_target;
25095   rtx x, tmp;
25096   bool use_vector_set = false;
25097
25098   switch (mode)
25099     {
25100     case V2DImode:
25101       use_vector_set = TARGET_64BIT && TARGET_SSE4_1;
25102       break;
25103     case V16QImode:
25104     case V4SImode:
25105     case V4SFmode:
25106       use_vector_set = TARGET_SSE4_1;
25107       break;
25108     case V8HImode:
25109       use_vector_set = TARGET_SSE2;
25110       break;
25111     case V4HImode:
25112       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
25113       break;
25114     default:
25115       break;
25116     }
25117
25118   if (use_vector_set)
25119     {
25120       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
25121       var = force_reg (GET_MODE_INNER (mode), var);
25122       ix86_expand_vector_set (mmx_ok, target, var, one_var);
25123       return true; 
25124     }
25125
25126   switch (mode)
25127     {
25128     case V2SFmode:
25129     case V2SImode:
25130       if (!mmx_ok)
25131         return false;
25132       /* FALLTHRU */
25133
25134     case V2DFmode:
25135     case V2DImode:
25136       if (one_var != 0)
25137         return false;
25138       var = force_reg (GET_MODE_INNER (mode), var);
25139       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
25140       emit_insn (gen_rtx_SET (VOIDmode, target, x));
25141       return true;
25142
25143     case V4SFmode:
25144     case V4SImode:
25145       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
25146         new_target = gen_reg_rtx (mode);
25147       else
25148         new_target = target;
25149       var = force_reg (GET_MODE_INNER (mode), var);
25150       x = gen_rtx_VEC_DUPLICATE (mode, var);
25151       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
25152       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
25153       if (one_var != 0)
25154         {
25155           /* We need to shuffle the value to the correct position, so
25156              create a new pseudo to store the intermediate result.  */
25157
25158           /* With SSE2, we can use the integer shuffle insns.  */
25159           if (mode != V4SFmode && TARGET_SSE2)
25160             {
25161               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
25162                                             GEN_INT (1),
25163                                             GEN_INT (one_var == 1 ? 0 : 1),
25164                                             GEN_INT (one_var == 2 ? 0 : 1),
25165                                             GEN_INT (one_var == 3 ? 0 : 1)));
25166               if (target != new_target)
25167                 emit_move_insn (target, new_target);
25168               return true;
25169             }
25170
25171           /* Otherwise convert the intermediate result to V4SFmode and
25172              use the SSE1 shuffle instructions.  */
25173           if (mode != V4SFmode)
25174             {
25175               tmp = gen_reg_rtx (V4SFmode);
25176               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
25177             }
25178           else
25179             tmp = new_target;
25180
25181           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
25182                                        GEN_INT (1),
25183                                        GEN_INT (one_var == 1 ? 0 : 1),
25184                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
25185                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
25186
25187           if (mode != V4SFmode)
25188             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
25189           else if (tmp != target)
25190             emit_move_insn (target, tmp);
25191         }
25192       else if (target != new_target)
25193         emit_move_insn (target, new_target);
25194       return true;
25195
25196     case V8HImode:
25197     case V16QImode:
25198       vsimode = V4SImode;
25199       goto widen;
25200     case V4HImode:
25201     case V8QImode:
25202       if (!mmx_ok)
25203         return false;
25204       vsimode = V2SImode;
25205       goto widen;
25206     widen:
25207       if (one_var != 0)
25208         return false;
25209
25210       /* Zero extend the variable element to SImode and recurse.  */
25211       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
25212
25213       x = gen_reg_rtx (vsimode);
25214       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
25215                                                 var, one_var))
25216         gcc_unreachable ();
25217
25218       emit_move_insn (target, gen_lowpart (mode, x));
25219       return true;
25220
25221     default:
25222       return false;
25223     }
25224 }
25225
25226 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
25227    consisting of the values in VALS.  It is known that all elements
25228    except ONE_VAR are constants.  Return true if successful.  */
25229
25230 static bool
25231 ix86_expand_vector_init_one_var (bool mmx_ok, enum machine_mode mode,
25232                                  rtx target, rtx vals, int one_var)
25233 {
25234   rtx var = XVECEXP (vals, 0, one_var);
25235   enum machine_mode wmode;
25236   rtx const_vec, x;
25237
25238   const_vec = copy_rtx (vals);
25239   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
25240   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
25241
25242   switch (mode)
25243     {
25244     case V2DFmode:
25245     case V2DImode:
25246     case V2SFmode:
25247     case V2SImode:
25248       /* For the two element vectors, it's just as easy to use
25249          the general case.  */
25250       return false;
25251
25252     case V4SFmode:
25253     case V4SImode:
25254     case V8HImode:
25255     case V4HImode:
25256       break;
25257
25258     case V16QImode:
25259       if (TARGET_SSE4_1)
25260         break;
25261       wmode = V8HImode;
25262       goto widen;
25263     case V8QImode:
25264       wmode = V4HImode;
25265       goto widen;
25266     widen:
25267       /* There's no way to set one QImode entry easily.  Combine
25268          the variable value with its adjacent constant value, and
25269          promote to an HImode set.  */
25270       x = XVECEXP (vals, 0, one_var ^ 1);
25271       if (one_var & 1)
25272         {
25273           var = convert_modes (HImode, QImode, var, true);
25274           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
25275                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
25276           x = GEN_INT (INTVAL (x) & 0xff);
25277         }
25278       else
25279         {
25280           var = convert_modes (HImode, QImode, var, true);
25281           x = gen_int_mode (INTVAL (x) << 8, HImode);
25282         }
25283       if (x != const0_rtx)
25284         var = expand_simple_binop (HImode, IOR, var, x, var,
25285                                    1, OPTAB_LIB_WIDEN);
25286
25287       x = gen_reg_rtx (wmode);
25288       emit_move_insn (x, gen_lowpart (wmode, const_vec));
25289       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
25290
25291       emit_move_insn (target, gen_lowpart (mode, x));
25292       return true;
25293
25294     default:
25295       return false;
25296     }
25297
25298   emit_move_insn (target, const_vec);
25299   ix86_expand_vector_set (mmx_ok, target, var, one_var);
25300   return true;
25301 }
25302
25303 /* A subroutine of ix86_expand_vector_init_general.  Use vector
25304    concatenate to handle the most general case: all values variable,
25305    and none identical.  */
25306
25307 static void
25308 ix86_expand_vector_init_concat (enum machine_mode mode,
25309                                 rtx target, rtx *ops, int n)
25310 {
25311   enum machine_mode cmode, hmode = VOIDmode;
25312   rtx first[4], second[2];
25313   rtvec v;
25314   int i, j;
25315
25316   switch (n)
25317     {
25318     case 2:
25319       switch (mode)
25320         {
25321         case V4SImode:
25322           cmode = V2SImode;
25323           break;
25324         case V4SFmode:
25325           cmode = V2SFmode;
25326           break;
25327         case V2DImode:
25328           cmode = DImode;
25329           break;
25330         case V2SImode:
25331           cmode = SImode;
25332           break;
25333         case V2DFmode:
25334           cmode = DFmode;
25335           break;
25336         case V2SFmode:
25337           cmode = SFmode;
25338           break;
25339         default:
25340           gcc_unreachable ();
25341         }
25342
25343       if (!register_operand (ops[1], cmode))
25344         ops[1] = force_reg (cmode, ops[1]);
25345       if (!register_operand (ops[0], cmode))
25346         ops[0] = force_reg (cmode, ops[0]);
25347       emit_insn (gen_rtx_SET (VOIDmode, target,
25348                               gen_rtx_VEC_CONCAT (mode, ops[0],
25349                                                   ops[1])));
25350       break;
25351
25352     case 4:
25353       switch (mode)
25354         {
25355         case V4SImode:
25356           cmode = V2SImode;
25357           break;
25358         case V4SFmode:
25359           cmode = V2SFmode;
25360           break;
25361         default:
25362           gcc_unreachable ();
25363         }
25364       goto half;
25365
25366 half:
25367       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
25368       i = n - 1;
25369       j = (n >> 1) - 1;
25370       for (; i > 0; i -= 2, j--)
25371         {
25372           first[j] = gen_reg_rtx (cmode);
25373           v = gen_rtvec (2, ops[i - 1], ops[i]);
25374           ix86_expand_vector_init (false, first[j],
25375                                    gen_rtx_PARALLEL (cmode, v));
25376         }
25377
25378       n >>= 1;
25379       if (n > 2)
25380         {
25381           gcc_assert (hmode != VOIDmode);
25382           for (i = j = 0; i < n; i += 2, j++)
25383             {
25384               second[j] = gen_reg_rtx (hmode);
25385               ix86_expand_vector_init_concat (hmode, second [j],
25386                                               &first [i], 2);
25387             }
25388           n >>= 1;
25389           ix86_expand_vector_init_concat (mode, target, second, n);
25390         }
25391       else
25392         ix86_expand_vector_init_concat (mode, target, first, n);
25393       break;
25394
25395     default:
25396       gcc_unreachable ();
25397     }
25398 }
25399
25400 /* A subroutine of ix86_expand_vector_init_general.  Use vector
25401    interleave to handle the most general case: all values variable,
25402    and none identical.  */
25403
25404 static void
25405 ix86_expand_vector_init_interleave (enum machine_mode mode,
25406                                     rtx target, rtx *ops, int n)
25407 {
25408   enum machine_mode first_imode, second_imode, third_imode;
25409   int i, j;
25410   rtx op0, op1;
25411   rtx (*gen_load_even) (rtx, rtx, rtx);
25412   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
25413   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
25414   
25415   switch (mode)
25416     {
25417     case V8HImode:
25418       gen_load_even = gen_vec_setv8hi;
25419       gen_interleave_first_low = gen_vec_interleave_lowv4si;
25420       gen_interleave_second_low = gen_vec_interleave_lowv2di;
25421       first_imode = V4SImode;
25422       second_imode = V2DImode;
25423       third_imode = VOIDmode;
25424       break;
25425     case V16QImode:
25426       gen_load_even = gen_vec_setv16qi;
25427       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
25428       gen_interleave_second_low = gen_vec_interleave_lowv4si;
25429       first_imode = V8HImode;
25430       second_imode = V4SImode;
25431       third_imode = V2DImode;
25432       break;
25433     default:
25434       gcc_unreachable ();
25435     }
25436      
25437   for (i = 0; i < n; i++)
25438     {
25439       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
25440       op0 = gen_reg_rtx (SImode);
25441       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
25442
25443       /* Insert the SImode value as low element of V4SImode vector. */
25444       op1 = gen_reg_rtx (V4SImode);
25445       op0 = gen_rtx_VEC_MERGE (V4SImode,
25446                                gen_rtx_VEC_DUPLICATE (V4SImode,
25447                                                       op0),
25448                                CONST0_RTX (V4SImode),
25449                                const1_rtx);
25450       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
25451
25452       /* Cast the V4SImode vector back to a vector in orignal mode.  */
25453       op0 = gen_reg_rtx (mode);
25454       emit_move_insn (op0, gen_lowpart (mode, op1));
25455       
25456       /* Load even elements into the second positon.  */
25457       emit_insn ((*gen_load_even) (op0, ops [i + i + 1],
25458                                    const1_rtx));
25459
25460       /* Cast vector to FIRST_IMODE vector.  */
25461       ops[i] = gen_reg_rtx (first_imode);
25462       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
25463     }
25464
25465   /* Interleave low FIRST_IMODE vectors.  */
25466   for (i = j = 0; i < n; i += 2, j++)
25467     {
25468       op0 = gen_reg_rtx (first_imode);
25469       emit_insn ((*gen_interleave_first_low) (op0, ops[i], ops[i + 1]));
25470
25471       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
25472       ops[j] = gen_reg_rtx (second_imode);
25473       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
25474     }
25475
25476   /* Interleave low SECOND_IMODE vectors.  */
25477   switch (second_imode)
25478     {
25479     case V4SImode:
25480       for (i = j = 0; i < n / 2; i += 2, j++)
25481         {
25482           op0 = gen_reg_rtx (second_imode);
25483           emit_insn ((*gen_interleave_second_low) (op0, ops[i],
25484                                                    ops[i + 1]));
25485
25486           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
25487              vector.  */
25488           ops[j] = gen_reg_rtx (third_imode);
25489           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
25490         }
25491       second_imode = V2DImode;
25492       gen_interleave_second_low = gen_vec_interleave_lowv2di;
25493       /* FALLTHRU */
25494
25495     case V2DImode:
25496       op0 = gen_reg_rtx (second_imode);
25497       emit_insn ((*gen_interleave_second_low) (op0, ops[0],
25498                                                ops[1]));
25499
25500       /* Cast the SECOND_IMODE vector back to a vector on original
25501          mode.  */
25502       emit_insn (gen_rtx_SET (VOIDmode, target,
25503                               gen_lowpart (mode, op0)));
25504       break;
25505
25506     default:
25507       gcc_unreachable ();
25508     }
25509 }
25510
25511 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
25512    all values variable, and none identical.  */
25513
25514 static void
25515 ix86_expand_vector_init_general (bool mmx_ok, enum machine_mode mode,
25516                                  rtx target, rtx vals)
25517 {
25518   rtx ops[16];
25519   int n, i;
25520
25521   switch (mode)
25522     {
25523     case V2SFmode:
25524     case V2SImode:
25525       if (!mmx_ok && !TARGET_SSE)
25526         break;
25527       /* FALLTHRU */
25528
25529     case V4SFmode:
25530     case V4SImode:
25531     case V2DFmode:
25532     case V2DImode:
25533       n = GET_MODE_NUNITS (mode);
25534       for (i = 0; i < n; i++)
25535         ops[i] = XVECEXP (vals, 0, i);
25536       ix86_expand_vector_init_concat (mode, target, ops, n);
25537       return;
25538
25539     case V16QImode:
25540       if (!TARGET_SSE4_1)
25541         break;
25542       /* FALLTHRU */
25543
25544     case V8HImode:
25545       if (!TARGET_SSE2)
25546         break;
25547
25548       n = GET_MODE_NUNITS (mode);
25549       for (i = 0; i < n; i++)
25550         ops[i] = XVECEXP (vals, 0, i);
25551       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
25552       return;
25553
25554     case V4HImode:
25555     case V8QImode:
25556       break;
25557
25558     default:
25559       gcc_unreachable ();
25560     }
25561
25562     {
25563       int i, j, n_elts, n_words, n_elt_per_word;
25564       enum machine_mode inner_mode;
25565       rtx words[4], shift;
25566
25567       inner_mode = GET_MODE_INNER (mode);
25568       n_elts = GET_MODE_NUNITS (mode);
25569       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
25570       n_elt_per_word = n_elts / n_words;
25571       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
25572
25573       for (i = 0; i < n_words; ++i)
25574         {
25575           rtx word = NULL_RTX;
25576
25577           for (j = 0; j < n_elt_per_word; ++j)
25578             {
25579               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
25580               elt = convert_modes (word_mode, inner_mode, elt, true);
25581
25582               if (j == 0)
25583                 word = elt;
25584               else
25585                 {
25586                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
25587                                               word, 1, OPTAB_LIB_WIDEN);
25588                   word = expand_simple_binop (word_mode, IOR, word, elt,
25589                                               word, 1, OPTAB_LIB_WIDEN);
25590                 }
25591             }
25592
25593           words[i] = word;
25594         }
25595
25596       if (n_words == 1)
25597         emit_move_insn (target, gen_lowpart (mode, words[0]));
25598       else if (n_words == 2)
25599         {
25600           rtx tmp = gen_reg_rtx (mode);
25601           emit_clobber (tmp);
25602           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
25603           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
25604           emit_move_insn (target, tmp);
25605         }
25606       else if (n_words == 4)
25607         {
25608           rtx tmp = gen_reg_rtx (V4SImode);
25609           gcc_assert (word_mode == SImode);
25610           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
25611           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
25612           emit_move_insn (target, gen_lowpart (mode, tmp));
25613         }
25614       else
25615         gcc_unreachable ();
25616     }
25617 }
25618
25619 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
25620    instructions unless MMX_OK is true.  */
25621
25622 void
25623 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
25624 {
25625   enum machine_mode mode = GET_MODE (target);
25626   enum machine_mode inner_mode = GET_MODE_INNER (mode);
25627   int n_elts = GET_MODE_NUNITS (mode);
25628   int n_var = 0, one_var = -1;
25629   bool all_same = true, all_const_zero = true;
25630   int i;
25631   rtx x;
25632
25633   for (i = 0; i < n_elts; ++i)
25634     {
25635       x = XVECEXP (vals, 0, i);
25636       if (!(CONST_INT_P (x)
25637             || GET_CODE (x) == CONST_DOUBLE
25638             || GET_CODE (x) == CONST_FIXED))
25639         n_var++, one_var = i;
25640       else if (x != CONST0_RTX (inner_mode))
25641         all_const_zero = false;
25642       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
25643         all_same = false;
25644     }
25645
25646   /* Constants are best loaded from the constant pool.  */
25647   if (n_var == 0)
25648     {
25649       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
25650       return;
25651     }
25652
25653   /* If all values are identical, broadcast the value.  */
25654   if (all_same
25655       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
25656                                             XVECEXP (vals, 0, 0)))
25657     return;
25658
25659   /* Values where only one field is non-constant are best loaded from
25660      the pool and overwritten via move later.  */
25661   if (n_var == 1)
25662     {
25663       if (all_const_zero
25664           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
25665                                                   XVECEXP (vals, 0, one_var),
25666                                                   one_var))
25667         return;
25668
25669       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
25670         return;
25671     }
25672
25673   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
25674 }
25675
25676 void
25677 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
25678 {
25679   enum machine_mode mode = GET_MODE (target);
25680   enum machine_mode inner_mode = GET_MODE_INNER (mode);
25681   bool use_vec_merge = false;
25682   rtx tmp;
25683
25684   switch (mode)
25685     {
25686     case V2SFmode:
25687     case V2SImode:
25688       if (mmx_ok)
25689         {
25690           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
25691           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
25692           if (elt == 0)
25693             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
25694           else
25695             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
25696           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
25697           return;
25698         }
25699       break;
25700
25701     case V2DImode:
25702       use_vec_merge = TARGET_SSE4_1;
25703       if (use_vec_merge)
25704         break;
25705
25706     case V2DFmode:
25707       {
25708         rtx op0, op1;
25709
25710         /* For the two element vectors, we implement a VEC_CONCAT with
25711            the extraction of the other element.  */
25712
25713         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
25714         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
25715
25716         if (elt == 0)
25717           op0 = val, op1 = tmp;
25718         else
25719           op0 = tmp, op1 = val;
25720
25721         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
25722         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
25723       }
25724       return;
25725
25726     case V4SFmode:
25727       use_vec_merge = TARGET_SSE4_1;
25728       if (use_vec_merge)
25729         break;
25730
25731       switch (elt)
25732         {
25733         case 0:
25734           use_vec_merge = true;
25735           break;
25736
25737         case 1:
25738           /* tmp = target = A B C D */
25739           tmp = copy_to_reg (target);
25740           /* target = A A B B */
25741           emit_insn (gen_sse_unpcklps (target, target, target));
25742           /* target = X A B B */
25743           ix86_expand_vector_set (false, target, val, 0);
25744           /* target = A X C D  */
25745           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
25746                                        GEN_INT (1), GEN_INT (0),
25747                                        GEN_INT (2+4), GEN_INT (3+4)));
25748           return;
25749
25750         case 2:
25751           /* tmp = target = A B C D */
25752           tmp = copy_to_reg (target);
25753           /* tmp = X B C D */
25754           ix86_expand_vector_set (false, tmp, val, 0);
25755           /* target = A B X D */
25756           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
25757                                        GEN_INT (0), GEN_INT (1),
25758                                        GEN_INT (0+4), GEN_INT (3+4)));
25759           return;
25760
25761         case 3:
25762           /* tmp = target = A B C D */
25763           tmp = copy_to_reg (target);
25764           /* tmp = X B C D */
25765           ix86_expand_vector_set (false, tmp, val, 0);
25766           /* target = A B X D */
25767           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
25768                                        GEN_INT (0), GEN_INT (1),
25769                                        GEN_INT (2+4), GEN_INT (0+4)));
25770           return;
25771
25772         default:
25773           gcc_unreachable ();
25774         }
25775       break;
25776
25777     case V4SImode:
25778       use_vec_merge = TARGET_SSE4_1;
25779       if (use_vec_merge)
25780         break;
25781
25782       /* Element 0 handled by vec_merge below.  */
25783       if (elt == 0)
25784         {
25785           use_vec_merge = true;
25786           break;
25787         }
25788
25789       if (TARGET_SSE2)
25790         {
25791           /* With SSE2, use integer shuffles to swap element 0 and ELT,
25792              store into element 0, then shuffle them back.  */
25793
25794           rtx order[4];
25795
25796           order[0] = GEN_INT (elt);
25797           order[1] = const1_rtx;
25798           order[2] = const2_rtx;
25799           order[3] = GEN_INT (3);
25800           order[elt] = const0_rtx;
25801
25802           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
25803                                         order[1], order[2], order[3]));
25804
25805           ix86_expand_vector_set (false, target, val, 0);
25806
25807           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
25808                                         order[1], order[2], order[3]));
25809         }
25810       else
25811         {
25812           /* For SSE1, we have to reuse the V4SF code.  */
25813           ix86_expand_vector_set (false, gen_lowpart (V4SFmode, target),
25814                                   gen_lowpart (SFmode, val), elt);
25815         }
25816       return;
25817
25818     case V8HImode:
25819       use_vec_merge = TARGET_SSE2;
25820       break;
25821     case V4HImode:
25822       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
25823       break;
25824
25825     case V16QImode:
25826       use_vec_merge = TARGET_SSE4_1;
25827       break;
25828
25829     case V8QImode:
25830     default:
25831       break;
25832     }
25833
25834   if (use_vec_merge)
25835     {
25836       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
25837       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
25838       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
25839     }
25840   else
25841     {
25842       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
25843
25844       emit_move_insn (mem, target);
25845
25846       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
25847       emit_move_insn (tmp, val);
25848
25849       emit_move_insn (target, mem);
25850     }
25851 }
25852
25853 void
25854 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
25855 {
25856   enum machine_mode mode = GET_MODE (vec);
25857   enum machine_mode inner_mode = GET_MODE_INNER (mode);
25858   bool use_vec_extr = false;
25859   rtx tmp;
25860
25861   switch (mode)
25862     {
25863     case V2SImode:
25864     case V2SFmode:
25865       if (!mmx_ok)
25866         break;
25867       /* FALLTHRU */
25868
25869     case V2DFmode:
25870     case V2DImode:
25871       use_vec_extr = true;
25872       break;
25873
25874     case V4SFmode:
25875       use_vec_extr = TARGET_SSE4_1;
25876       if (use_vec_extr)
25877         break;
25878
25879       switch (elt)
25880         {
25881         case 0:
25882           tmp = vec;
25883           break;
25884
25885         case 1:
25886         case 3:
25887           tmp = gen_reg_rtx (mode);
25888           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
25889                                        GEN_INT (elt), GEN_INT (elt),
25890                                        GEN_INT (elt+4), GEN_INT (elt+4)));
25891           break;
25892
25893         case 2:
25894           tmp = gen_reg_rtx (mode);
25895           emit_insn (gen_sse_unpckhps (tmp, vec, vec));
25896           break;
25897
25898         default:
25899           gcc_unreachable ();
25900         }
25901       vec = tmp;
25902       use_vec_extr = true;
25903       elt = 0;
25904       break;
25905
25906     case V4SImode:
25907       use_vec_extr = TARGET_SSE4_1;
25908       if (use_vec_extr)
25909         break;
25910
25911       if (TARGET_SSE2)
25912         {
25913           switch (elt)
25914             {
25915             case 0:
25916               tmp = vec;
25917               break;
25918
25919             case 1:
25920             case 3:
25921               tmp = gen_reg_rtx (mode);
25922               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
25923                                             GEN_INT (elt), GEN_INT (elt),
25924                                             GEN_INT (elt), GEN_INT (elt)));
25925               break;
25926
25927             case 2:
25928               tmp = gen_reg_rtx (mode);
25929               emit_insn (gen_sse2_punpckhdq (tmp, vec, vec));
25930               break;
25931
25932             default:
25933               gcc_unreachable ();
25934             }
25935           vec = tmp;
25936           use_vec_extr = true;
25937           elt = 0;
25938         }
25939       else
25940         {
25941           /* For SSE1, we have to reuse the V4SF code.  */
25942           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
25943                                       gen_lowpart (V4SFmode, vec), elt);
25944           return;
25945         }
25946       break;
25947
25948     case V8HImode:
25949       use_vec_extr = TARGET_SSE2;
25950       break;
25951     case V4HImode:
25952       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
25953       break;
25954
25955     case V16QImode:
25956       use_vec_extr = TARGET_SSE4_1;
25957       break;
25958
25959     case V8QImode:
25960       /* ??? Could extract the appropriate HImode element and shift.  */
25961     default:
25962       break;
25963     }
25964
25965   if (use_vec_extr)
25966     {
25967       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
25968       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
25969
25970       /* Let the rtl optimizers know about the zero extension performed.  */
25971       if (inner_mode == QImode || inner_mode == HImode)
25972         {
25973           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
25974           target = gen_lowpart (SImode, target);
25975         }
25976
25977       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
25978     }
25979   else
25980     {
25981       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
25982
25983       emit_move_insn (mem, vec);
25984
25985       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
25986       emit_move_insn (target, tmp);
25987     }
25988 }
25989
25990 /* Expand a vector reduction on V4SFmode for SSE1.  FN is the binary
25991    pattern to reduce; DEST is the destination; IN is the input vector.  */
25992
25993 void
25994 ix86_expand_reduc_v4sf (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
25995 {
25996   rtx tmp1, tmp2, tmp3;
25997
25998   tmp1 = gen_reg_rtx (V4SFmode);
25999   tmp2 = gen_reg_rtx (V4SFmode);
26000   tmp3 = gen_reg_rtx (V4SFmode);
26001
26002   emit_insn (gen_sse_movhlps (tmp1, in, in));
26003   emit_insn (fn (tmp2, tmp1, in));
26004
26005   emit_insn (gen_sse_shufps_v4sf (tmp3, tmp2, tmp2,
26006                                GEN_INT (1), GEN_INT (1),
26007                                GEN_INT (1+4), GEN_INT (1+4)));
26008   emit_insn (fn (dest, tmp2, tmp3));
26009 }
26010 \f
26011 /* Target hook for scalar_mode_supported_p.  */
26012 static bool
26013 ix86_scalar_mode_supported_p (enum machine_mode mode)
26014 {
26015   if (DECIMAL_FLOAT_MODE_P (mode))
26016     return true;
26017   else if (mode == TFmode)
26018     return true;
26019   else
26020     return default_scalar_mode_supported_p (mode);
26021 }
26022
26023 /* Implements target hook vector_mode_supported_p.  */
26024 static bool
26025 ix86_vector_mode_supported_p (enum machine_mode mode)
26026 {
26027   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
26028     return true;
26029   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
26030     return true;
26031   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
26032     return true;
26033   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
26034     return true;
26035   return false;
26036 }
26037
26038 /* Target hook for c_mode_for_suffix.  */
26039 static enum machine_mode
26040 ix86_c_mode_for_suffix (char suffix)
26041 {
26042   if (suffix == 'q')
26043     return TFmode;
26044   if (suffix == 'w')
26045     return XFmode;
26046
26047   return VOIDmode;
26048 }
26049
26050 /* Worker function for TARGET_MD_ASM_CLOBBERS.
26051
26052    We do this in the new i386 backend to maintain source compatibility
26053    with the old cc0-based compiler.  */
26054
26055 static tree
26056 ix86_md_asm_clobbers (tree outputs ATTRIBUTE_UNUSED,
26057                       tree inputs ATTRIBUTE_UNUSED,
26058                       tree clobbers)
26059 {
26060   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
26061                         clobbers);
26062   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
26063                         clobbers);
26064   return clobbers;
26065 }
26066
26067 /* Implements target vector targetm.asm.encode_section_info.  This
26068    is not used by netware.  */
26069
26070 static void ATTRIBUTE_UNUSED
26071 ix86_encode_section_info (tree decl, rtx rtl, int first)
26072 {
26073   default_encode_section_info (decl, rtl, first);
26074
26075   if (TREE_CODE (decl) == VAR_DECL
26076       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
26077       && ix86_in_large_data_p (decl))
26078     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
26079 }
26080
26081 /* Worker function for REVERSE_CONDITION.  */
26082
26083 enum rtx_code
26084 ix86_reverse_condition (enum rtx_code code, enum machine_mode mode)
26085 {
26086   return (mode != CCFPmode && mode != CCFPUmode
26087           ? reverse_condition (code)
26088           : reverse_condition_maybe_unordered (code));
26089 }
26090
26091 /* Output code to perform an x87 FP register move, from OPERANDS[1]
26092    to OPERANDS[0].  */
26093
26094 const char *
26095 output_387_reg_move (rtx insn, rtx *operands)
26096 {
26097   if (REG_P (operands[0]))
26098     {
26099       if (REG_P (operands[1])
26100           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
26101         {
26102           if (REGNO (operands[0]) == FIRST_STACK_REG)
26103             return output_387_ffreep (operands, 0);
26104           return "fstp\t%y0";
26105         }
26106       if (STACK_TOP_P (operands[0]))
26107         return "fld%z1\t%y1";
26108       return "fst\t%y0";
26109     }
26110   else if (MEM_P (operands[0]))
26111     {
26112       gcc_assert (REG_P (operands[1]));
26113       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
26114         return "fstp%z0\t%y0";
26115       else
26116         {
26117           /* There is no non-popping store to memory for XFmode.
26118              So if we need one, follow the store with a load.  */
26119           if (GET_MODE (operands[0]) == XFmode)
26120             return "fstp%z0\t%y0\n\tfld%z0\t%y0";
26121           else
26122             return "fst%z0\t%y0";
26123         }
26124     }
26125   else
26126     gcc_unreachable();
26127 }
26128
26129 /* Output code to perform a conditional jump to LABEL, if C2 flag in
26130    FP status register is set.  */
26131
26132 void
26133 ix86_emit_fp_unordered_jump (rtx label)
26134 {
26135   rtx reg = gen_reg_rtx (HImode);
26136   rtx temp;
26137
26138   emit_insn (gen_x86_fnstsw_1 (reg));
26139
26140   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
26141     {
26142       emit_insn (gen_x86_sahf_1 (reg));
26143
26144       temp = gen_rtx_REG (CCmode, FLAGS_REG);
26145       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
26146     }
26147   else
26148     {
26149       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
26150
26151       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
26152       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
26153     }
26154
26155   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
26156                               gen_rtx_LABEL_REF (VOIDmode, label),
26157                               pc_rtx);
26158   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
26159
26160   emit_jump_insn (temp);
26161   predict_jump (REG_BR_PROB_BASE * 10 / 100);
26162 }
26163
26164 /* Output code to perform a log1p XFmode calculation.  */
26165
26166 void ix86_emit_i387_log1p (rtx op0, rtx op1)
26167 {
26168   rtx label1 = gen_label_rtx ();
26169   rtx label2 = gen_label_rtx ();
26170
26171   rtx tmp = gen_reg_rtx (XFmode);
26172   rtx tmp2 = gen_reg_rtx (XFmode);
26173
26174   emit_insn (gen_absxf2 (tmp, op1));
26175   emit_insn (gen_cmpxf (tmp,
26176     CONST_DOUBLE_FROM_REAL_VALUE (
26177        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
26178        XFmode)));
26179   emit_jump_insn (gen_bge (label1));
26180
26181   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
26182   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
26183   emit_jump (label2);
26184
26185   emit_label (label1);
26186   emit_move_insn (tmp, CONST1_RTX (XFmode));
26187   emit_insn (gen_addxf3 (tmp, op1, tmp));
26188   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
26189   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
26190
26191   emit_label (label2);
26192 }
26193
26194 /* Output code to perform a Newton-Rhapson approximation of a single precision
26195    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
26196
26197 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, enum machine_mode mode)
26198 {
26199   rtx x0, x1, e0, e1, two;
26200
26201   x0 = gen_reg_rtx (mode);
26202   e0 = gen_reg_rtx (mode);
26203   e1 = gen_reg_rtx (mode);
26204   x1 = gen_reg_rtx (mode);
26205
26206   two = CONST_DOUBLE_FROM_REAL_VALUE (dconst2, SFmode);
26207
26208   if (VECTOR_MODE_P (mode))
26209     two = ix86_build_const_vector (SFmode, true, two);
26210
26211   two = force_reg (mode, two);
26212
26213   /* a / b = a * rcp(b) * (2.0 - b * rcp(b)) */
26214
26215   /* x0 = rcp(b) estimate */
26216   emit_insn (gen_rtx_SET (VOIDmode, x0,
26217                           gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
26218                                           UNSPEC_RCP)));
26219   /* e0 = x0 * b */
26220   emit_insn (gen_rtx_SET (VOIDmode, e0,
26221                           gen_rtx_MULT (mode, x0, b)));
26222   /* e1 = 2. - e0 */
26223   emit_insn (gen_rtx_SET (VOIDmode, e1,
26224                           gen_rtx_MINUS (mode, two, e0)));
26225   /* x1 = x0 * e1 */
26226   emit_insn (gen_rtx_SET (VOIDmode, x1,
26227                           gen_rtx_MULT (mode, x0, e1)));
26228   /* res = a * x1 */
26229   emit_insn (gen_rtx_SET (VOIDmode, res,
26230                           gen_rtx_MULT (mode, a, x1)));
26231 }
26232
26233 /* Output code to perform a Newton-Rhapson approximation of a
26234    single precision floating point [reciprocal] square root.  */
26235
26236 void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
26237                          bool recip)
26238 {
26239   rtx x0, e0, e1, e2, e3, mthree, mhalf;
26240   REAL_VALUE_TYPE r;
26241
26242   x0 = gen_reg_rtx (mode);
26243   e0 = gen_reg_rtx (mode);
26244   e1 = gen_reg_rtx (mode);
26245   e2 = gen_reg_rtx (mode);
26246   e3 = gen_reg_rtx (mode);
26247
26248   real_from_integer (&r, VOIDmode, -3, -1, 0);
26249   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
26250
26251   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
26252   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
26253
26254   if (VECTOR_MODE_P (mode))
26255     {
26256       mthree = ix86_build_const_vector (SFmode, true, mthree);
26257       mhalf = ix86_build_const_vector (SFmode, true, mhalf);
26258     }
26259
26260   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
26261      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
26262
26263   /* x0 = rsqrt(a) estimate */
26264   emit_insn (gen_rtx_SET (VOIDmode, x0,
26265                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
26266                                           UNSPEC_RSQRT)));
26267
26268   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
26269   if (!recip)
26270     {
26271       rtx zero, mask;
26272
26273       zero = gen_reg_rtx (mode);
26274       mask = gen_reg_rtx (mode);
26275
26276       zero = force_reg (mode, CONST0_RTX(mode));
26277       emit_insn (gen_rtx_SET (VOIDmode, mask,
26278                               gen_rtx_NE (mode, zero, a)));
26279
26280       emit_insn (gen_rtx_SET (VOIDmode, x0,
26281                               gen_rtx_AND (mode, x0, mask)));
26282     }
26283
26284   /* e0 = x0 * a */
26285   emit_insn (gen_rtx_SET (VOIDmode, e0,
26286                           gen_rtx_MULT (mode, x0, a)));
26287   /* e1 = e0 * x0 */
26288   emit_insn (gen_rtx_SET (VOIDmode, e1,
26289                           gen_rtx_MULT (mode, e0, x0)));
26290
26291   /* e2 = e1 - 3. */
26292   mthree = force_reg (mode, mthree);
26293   emit_insn (gen_rtx_SET (VOIDmode, e2,
26294                           gen_rtx_PLUS (mode, e1, mthree)));
26295
26296   mhalf = force_reg (mode, mhalf);
26297   if (recip)
26298     /* e3 = -.5 * x0 */
26299     emit_insn (gen_rtx_SET (VOIDmode, e3,
26300                             gen_rtx_MULT (mode, x0, mhalf)));
26301   else
26302     /* e3 = -.5 * e0 */
26303     emit_insn (gen_rtx_SET (VOIDmode, e3,
26304                             gen_rtx_MULT (mode, e0, mhalf)));
26305   /* ret = e2 * e3 */
26306   emit_insn (gen_rtx_SET (VOIDmode, res,
26307                           gen_rtx_MULT (mode, e2, e3)));
26308 }
26309
26310 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
26311
26312 static void ATTRIBUTE_UNUSED
26313 i386_solaris_elf_named_section (const char *name, unsigned int flags,
26314                                 tree decl)
26315 {
26316   /* With Binutils 2.15, the "@unwind" marker must be specified on
26317      every occurrence of the ".eh_frame" section, not just the first
26318      one.  */
26319   if (TARGET_64BIT
26320       && strcmp (name, ".eh_frame") == 0)
26321     {
26322       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
26323                flags & SECTION_WRITE ? "aw" : "a");
26324       return;
26325     }
26326   default_elf_asm_named_section (name, flags, decl);
26327 }
26328
26329 /* Return the mangling of TYPE if it is an extended fundamental type.  */
26330
26331 static const char *
26332 ix86_mangle_type (const_tree type)
26333 {
26334   type = TYPE_MAIN_VARIANT (type);
26335
26336   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
26337       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
26338     return NULL;
26339
26340   switch (TYPE_MODE (type))
26341     {
26342     case TFmode:
26343       /* __float128 is "g".  */
26344       return "g";
26345     case XFmode:
26346       /* "long double" or __float80 is "e".  */
26347       return "e";
26348     default:
26349       return NULL;
26350     }
26351 }
26352
26353 /* For 32-bit code we can save PIC register setup by using
26354    __stack_chk_fail_local hidden function instead of calling
26355    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
26356    register, so it is better to call __stack_chk_fail directly.  */
26357
26358 static tree
26359 ix86_stack_protect_fail (void)
26360 {
26361   return TARGET_64BIT
26362          ? default_external_stack_protect_fail ()
26363          : default_hidden_stack_protect_fail ();
26364 }
26365
26366 /* Select a format to encode pointers in exception handling data.  CODE
26367    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
26368    true if the symbol may be affected by dynamic relocations.
26369
26370    ??? All x86 object file formats are capable of representing this.
26371    After all, the relocation needed is the same as for the call insn.
26372    Whether or not a particular assembler allows us to enter such, I
26373    guess we'll have to see.  */
26374 int
26375 asm_preferred_eh_data_format (int code, int global)
26376 {
26377   if (flag_pic)
26378     {
26379       int type = DW_EH_PE_sdata8;
26380       if (!TARGET_64BIT
26381           || ix86_cmodel == CM_SMALL_PIC
26382           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
26383         type = DW_EH_PE_sdata4;
26384       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
26385     }
26386   if (ix86_cmodel == CM_SMALL
26387       || (ix86_cmodel == CM_MEDIUM && code))
26388     return DW_EH_PE_udata4;
26389   return DW_EH_PE_absptr;
26390 }
26391 \f
26392 /* Expand copysign from SIGN to the positive value ABS_VALUE
26393    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
26394    the sign-bit.  */
26395 static void
26396 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
26397 {
26398   enum machine_mode mode = GET_MODE (sign);
26399   rtx sgn = gen_reg_rtx (mode);
26400   if (mask == NULL_RTX)
26401     {
26402       mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), false);
26403       if (!VECTOR_MODE_P (mode))
26404         {
26405           /* We need to generate a scalar mode mask in this case.  */
26406           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
26407           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
26408           mask = gen_reg_rtx (mode);
26409           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
26410         }
26411     }
26412   else
26413     mask = gen_rtx_NOT (mode, mask);
26414   emit_insn (gen_rtx_SET (VOIDmode, sgn,
26415                           gen_rtx_AND (mode, mask, sign)));
26416   emit_insn (gen_rtx_SET (VOIDmode, result,
26417                           gen_rtx_IOR (mode, abs_value, sgn)));
26418 }
26419
26420 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
26421    mask for masking out the sign-bit is stored in *SMASK, if that is
26422    non-null.  */
26423 static rtx
26424 ix86_expand_sse_fabs (rtx op0, rtx *smask)
26425 {
26426   enum machine_mode mode = GET_MODE (op0);
26427   rtx xa, mask;
26428
26429   xa = gen_reg_rtx (mode);
26430   mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), true);
26431   if (!VECTOR_MODE_P (mode))
26432     {
26433       /* We need to generate a scalar mode mask in this case.  */
26434       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
26435       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
26436       mask = gen_reg_rtx (mode);
26437       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
26438     }
26439   emit_insn (gen_rtx_SET (VOIDmode, xa,
26440                           gen_rtx_AND (mode, op0, mask)));
26441
26442   if (smask)
26443     *smask = mask;
26444
26445   return xa;
26446 }
26447
26448 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
26449    swapping the operands if SWAP_OPERANDS is true.  The expanded
26450    code is a forward jump to a newly created label in case the
26451    comparison is true.  The generated label rtx is returned.  */
26452 static rtx
26453 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
26454                                   bool swap_operands)
26455 {
26456   rtx label, tmp;
26457
26458   if (swap_operands)
26459     {
26460       tmp = op0;
26461       op0 = op1;
26462       op1 = tmp;
26463     }
26464
26465   label = gen_label_rtx ();
26466   tmp = gen_rtx_REG (CCFPUmode, FLAGS_REG);
26467   emit_insn (gen_rtx_SET (VOIDmode, tmp,
26468                           gen_rtx_COMPARE (CCFPUmode, op0, op1)));
26469   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
26470   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
26471                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
26472   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
26473   JUMP_LABEL (tmp) = label;
26474
26475   return label;
26476 }
26477
26478 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
26479    using comparison code CODE.  Operands are swapped for the comparison if
26480    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
26481 static rtx
26482 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
26483                               bool swap_operands)
26484 {
26485   enum machine_mode mode = GET_MODE (op0);
26486   rtx mask = gen_reg_rtx (mode);
26487
26488   if (swap_operands)
26489     {
26490       rtx tmp = op0;
26491       op0 = op1;
26492       op1 = tmp;
26493     }
26494
26495   if (mode == DFmode)
26496     emit_insn (gen_sse2_maskcmpdf3 (mask, op0, op1,
26497                                     gen_rtx_fmt_ee (code, mode, op0, op1)));
26498   else
26499     emit_insn (gen_sse_maskcmpsf3 (mask, op0, op1,
26500                                    gen_rtx_fmt_ee (code, mode, op0, op1)));
26501
26502   return mask;
26503 }
26504
26505 /* Generate and return a rtx of mode MODE for 2**n where n is the number
26506    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
26507 static rtx
26508 ix86_gen_TWO52 (enum machine_mode mode)
26509 {
26510   REAL_VALUE_TYPE TWO52r;
26511   rtx TWO52;
26512
26513   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
26514   TWO52 = const_double_from_real_value (TWO52r, mode);
26515   TWO52 = force_reg (mode, TWO52);
26516
26517   return TWO52;
26518 }
26519
26520 /* Expand SSE sequence for computing lround from OP1 storing
26521    into OP0.  */
26522 void
26523 ix86_expand_lround (rtx op0, rtx op1)
26524 {
26525   /* C code for the stuff we're doing below:
26526        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
26527        return (long)tmp;
26528    */
26529   enum machine_mode mode = GET_MODE (op1);
26530   const struct real_format *fmt;
26531   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
26532   rtx adj;
26533
26534   /* load nextafter (0.5, 0.0) */
26535   fmt = REAL_MODE_FORMAT (mode);
26536   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
26537   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
26538
26539   /* adj = copysign (0.5, op1) */
26540   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
26541   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
26542
26543   /* adj = op1 + adj */
26544   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
26545
26546   /* op0 = (imode)adj */
26547   expand_fix (op0, adj, 0);
26548 }
26549
26550 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
26551    into OPERAND0.  */
26552 void
26553 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
26554 {
26555   /* C code for the stuff we're doing below (for do_floor):
26556         xi = (long)op1;
26557         xi -= (double)xi > op1 ? 1 : 0;
26558         return xi;
26559    */
26560   enum machine_mode fmode = GET_MODE (op1);
26561   enum machine_mode imode = GET_MODE (op0);
26562   rtx ireg, freg, label, tmp;
26563
26564   /* reg = (long)op1 */
26565   ireg = gen_reg_rtx (imode);
26566   expand_fix (ireg, op1, 0);
26567
26568   /* freg = (double)reg */
26569   freg = gen_reg_rtx (fmode);
26570   expand_float (freg, ireg, 0);
26571
26572   /* ireg = (freg > op1) ? ireg - 1 : ireg */
26573   label = ix86_expand_sse_compare_and_jump (UNLE,
26574                                             freg, op1, !do_floor);
26575   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
26576                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
26577   emit_move_insn (ireg, tmp);
26578
26579   emit_label (label);
26580   LABEL_NUSES (label) = 1;
26581
26582   emit_move_insn (op0, ireg);
26583 }
26584
26585 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
26586    result in OPERAND0.  */
26587 void
26588 ix86_expand_rint (rtx operand0, rtx operand1)
26589 {
26590   /* C code for the stuff we're doing below:
26591         xa = fabs (operand1);
26592         if (!isless (xa, 2**52))
26593           return operand1;
26594         xa = xa + 2**52 - 2**52;
26595         return copysign (xa, operand1);
26596    */
26597   enum machine_mode mode = GET_MODE (operand0);
26598   rtx res, xa, label, TWO52, mask;
26599
26600   res = gen_reg_rtx (mode);
26601   emit_move_insn (res, operand1);
26602
26603   /* xa = abs (operand1) */
26604   xa = ix86_expand_sse_fabs (res, &mask);
26605
26606   /* if (!isless (xa, TWO52)) goto label; */
26607   TWO52 = ix86_gen_TWO52 (mode);
26608   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
26609
26610   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
26611   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
26612
26613   ix86_sse_copysign_to_positive (res, xa, res, mask);
26614
26615   emit_label (label);
26616   LABEL_NUSES (label) = 1;
26617
26618   emit_move_insn (operand0, res);
26619 }
26620
26621 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
26622    into OPERAND0.  */
26623 void
26624 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
26625 {
26626   /* C code for the stuff we expand below.
26627         double xa = fabs (x), x2;
26628         if (!isless (xa, TWO52))
26629           return x;
26630         xa = xa + TWO52 - TWO52;
26631         x2 = copysign (xa, x);
26632      Compensate.  Floor:
26633         if (x2 > x)
26634           x2 -= 1;
26635      Compensate.  Ceil:
26636         if (x2 < x)
26637           x2 -= -1;
26638         return x2;
26639    */
26640   enum machine_mode mode = GET_MODE (operand0);
26641   rtx xa, TWO52, tmp, label, one, res, mask;
26642
26643   TWO52 = ix86_gen_TWO52 (mode);
26644
26645   /* Temporary for holding the result, initialized to the input
26646      operand to ease control flow.  */
26647   res = gen_reg_rtx (mode);
26648   emit_move_insn (res, operand1);
26649
26650   /* xa = abs (operand1) */
26651   xa = ix86_expand_sse_fabs (res, &mask);
26652
26653   /* if (!isless (xa, TWO52)) goto label; */
26654   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
26655
26656   /* xa = xa + TWO52 - TWO52; */
26657   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
26658   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
26659
26660   /* xa = copysign (xa, operand1) */
26661   ix86_sse_copysign_to_positive (xa, xa, res, mask);
26662
26663   /* generate 1.0 or -1.0 */
26664   one = force_reg (mode,
26665                    const_double_from_real_value (do_floor
26666                                                  ? dconst1 : dconstm1, mode));
26667
26668   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
26669   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
26670   emit_insn (gen_rtx_SET (VOIDmode, tmp,
26671                           gen_rtx_AND (mode, one, tmp)));
26672   /* We always need to subtract here to preserve signed zero.  */
26673   tmp = expand_simple_binop (mode, MINUS,
26674                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
26675   emit_move_insn (res, tmp);
26676
26677   emit_label (label);
26678   LABEL_NUSES (label) = 1;
26679
26680   emit_move_insn (operand0, res);
26681 }
26682
26683 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
26684    into OPERAND0.  */
26685 void
26686 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
26687 {
26688   /* C code for the stuff we expand below.
26689         double xa = fabs (x), x2;
26690         if (!isless (xa, TWO52))
26691           return x;
26692         x2 = (double)(long)x;
26693      Compensate.  Floor:
26694         if (x2 > x)
26695           x2 -= 1;
26696      Compensate.  Ceil:
26697         if (x2 < x)
26698           x2 += 1;
26699         if (HONOR_SIGNED_ZEROS (mode))
26700           return copysign (x2, x);
26701         return x2;
26702    */
26703   enum machine_mode mode = GET_MODE (operand0);
26704   rtx xa, xi, TWO52, tmp, label, one, res, mask;
26705
26706   TWO52 = ix86_gen_TWO52 (mode);
26707
26708   /* Temporary for holding the result, initialized to the input
26709      operand to ease control flow.  */
26710   res = gen_reg_rtx (mode);
26711   emit_move_insn (res, operand1);
26712
26713   /* xa = abs (operand1) */
26714   xa = ix86_expand_sse_fabs (res, &mask);
26715
26716   /* if (!isless (xa, TWO52)) goto label; */
26717   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
26718
26719   /* xa = (double)(long)x */
26720   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
26721   expand_fix (xi, res, 0);
26722   expand_float (xa, xi, 0);
26723
26724   /* generate 1.0 */
26725   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
26726
26727   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
26728   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
26729   emit_insn (gen_rtx_SET (VOIDmode, tmp,
26730                           gen_rtx_AND (mode, one, tmp)));
26731   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
26732                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
26733   emit_move_insn (res, tmp);
26734
26735   if (HONOR_SIGNED_ZEROS (mode))
26736     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
26737
26738   emit_label (label);
26739   LABEL_NUSES (label) = 1;
26740
26741   emit_move_insn (operand0, res);
26742 }
26743
26744 /* Expand SSE sequence for computing round from OPERAND1 storing
26745    into OPERAND0.  Sequence that works without relying on DImode truncation
26746    via cvttsd2siq that is only available on 64bit targets.  */
26747 void
26748 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
26749 {
26750   /* C code for the stuff we expand below.
26751         double xa = fabs (x), xa2, x2;
26752         if (!isless (xa, TWO52))
26753           return x;
26754      Using the absolute value and copying back sign makes
26755      -0.0 -> -0.0 correct.
26756         xa2 = xa + TWO52 - TWO52;
26757      Compensate.
26758         dxa = xa2 - xa;
26759         if (dxa <= -0.5)
26760           xa2 += 1;
26761         else if (dxa > 0.5)
26762           xa2 -= 1;
26763         x2 = copysign (xa2, x);
26764         return x2;
26765    */
26766   enum machine_mode mode = GET_MODE (operand0);
26767   rtx xa, xa2, dxa, TWO52, tmp, label, half, mhalf, one, res, mask;
26768
26769   TWO52 = ix86_gen_TWO52 (mode);
26770
26771   /* Temporary for holding the result, initialized to the input
26772      operand to ease control flow.  */
26773   res = gen_reg_rtx (mode);
26774   emit_move_insn (res, operand1);
26775
26776   /* xa = abs (operand1) */
26777   xa = ix86_expand_sse_fabs (res, &mask);
26778
26779   /* if (!isless (xa, TWO52)) goto label; */
26780   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
26781
26782   /* xa2 = xa + TWO52 - TWO52; */
26783   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
26784   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
26785
26786   /* dxa = xa2 - xa; */
26787   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
26788
26789   /* generate 0.5, 1.0 and -0.5 */
26790   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
26791   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
26792   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
26793                                0, OPTAB_DIRECT);
26794
26795   /* Compensate.  */
26796   tmp = gen_reg_rtx (mode);
26797   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
26798   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
26799   emit_insn (gen_rtx_SET (VOIDmode, tmp,
26800                           gen_rtx_AND (mode, one, tmp)));
26801   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
26802   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
26803   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
26804   emit_insn (gen_rtx_SET (VOIDmode, tmp,
26805                           gen_rtx_AND (mode, one, tmp)));
26806   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
26807
26808   /* res = copysign (xa2, operand1) */
26809   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
26810
26811   emit_label (label);
26812   LABEL_NUSES (label) = 1;
26813
26814   emit_move_insn (operand0, res);
26815 }
26816
26817 /* Expand SSE sequence for computing trunc from OPERAND1 storing
26818    into OPERAND0.  */
26819 void
26820 ix86_expand_trunc (rtx operand0, rtx operand1)
26821 {
26822   /* C code for SSE variant we expand below.
26823         double xa = fabs (x), x2;
26824         if (!isless (xa, TWO52))
26825           return x;
26826         x2 = (double)(long)x;
26827         if (HONOR_SIGNED_ZEROS (mode))
26828           return copysign (x2, x);
26829         return x2;
26830    */
26831   enum machine_mode mode = GET_MODE (operand0);
26832   rtx xa, xi, TWO52, label, res, mask;
26833
26834   TWO52 = ix86_gen_TWO52 (mode);
26835
26836   /* Temporary for holding the result, initialized to the input
26837      operand to ease control flow.  */
26838   res = gen_reg_rtx (mode);
26839   emit_move_insn (res, operand1);
26840
26841   /* xa = abs (operand1) */
26842   xa = ix86_expand_sse_fabs (res, &mask);
26843
26844   /* if (!isless (xa, TWO52)) goto label; */
26845   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
26846
26847   /* x = (double)(long)x */
26848   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
26849   expand_fix (xi, res, 0);
26850   expand_float (res, xi, 0);
26851
26852   if (HONOR_SIGNED_ZEROS (mode))
26853     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
26854
26855   emit_label (label);
26856   LABEL_NUSES (label) = 1;
26857
26858   emit_move_insn (operand0, res);
26859 }
26860
26861 /* Expand SSE sequence for computing trunc from OPERAND1 storing
26862    into OPERAND0.  */
26863 void
26864 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
26865 {
26866   enum machine_mode mode = GET_MODE (operand0);
26867   rtx xa, mask, TWO52, label, one, res, smask, tmp;
26868
26869   /* C code for SSE variant we expand below.
26870         double xa = fabs (x), x2;
26871         if (!isless (xa, TWO52))
26872           return x;
26873         xa2 = xa + TWO52 - TWO52;
26874      Compensate:
26875         if (xa2 > xa)
26876           xa2 -= 1.0;
26877         x2 = copysign (xa2, x);
26878         return x2;
26879    */
26880
26881   TWO52 = ix86_gen_TWO52 (mode);
26882
26883   /* Temporary for holding the result, initialized to the input
26884      operand to ease control flow.  */
26885   res = gen_reg_rtx (mode);
26886   emit_move_insn (res, operand1);
26887
26888   /* xa = abs (operand1) */
26889   xa = ix86_expand_sse_fabs (res, &smask);
26890
26891   /* if (!isless (xa, TWO52)) goto label; */
26892   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
26893
26894   /* res = xa + TWO52 - TWO52; */
26895   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
26896   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
26897   emit_move_insn (res, tmp);
26898
26899   /* generate 1.0 */
26900   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
26901
26902   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
26903   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
26904   emit_insn (gen_rtx_SET (VOIDmode, mask,
26905                           gen_rtx_AND (mode, mask, one)));
26906   tmp = expand_simple_binop (mode, MINUS,
26907                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
26908   emit_move_insn (res, tmp);
26909
26910   /* res = copysign (res, operand1) */
26911   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
26912
26913   emit_label (label);
26914   LABEL_NUSES (label) = 1;
26915
26916   emit_move_insn (operand0, res);
26917 }
26918
26919 /* Expand SSE sequence for computing round from OPERAND1 storing
26920    into OPERAND0.  */
26921 void
26922 ix86_expand_round (rtx operand0, rtx operand1)
26923 {
26924   /* C code for the stuff we're doing below:
26925         double xa = fabs (x);
26926         if (!isless (xa, TWO52))
26927           return x;
26928         xa = (double)(long)(xa + nextafter (0.5, 0.0));
26929         return copysign (xa, x);
26930    */
26931   enum machine_mode mode = GET_MODE (operand0);
26932   rtx res, TWO52, xa, label, xi, half, mask;
26933   const struct real_format *fmt;
26934   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
26935
26936   /* Temporary for holding the result, initialized to the input
26937      operand to ease control flow.  */
26938   res = gen_reg_rtx (mode);
26939   emit_move_insn (res, operand1);
26940
26941   TWO52 = ix86_gen_TWO52 (mode);
26942   xa = ix86_expand_sse_fabs (res, &mask);
26943   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
26944
26945   /* load nextafter (0.5, 0.0) */
26946   fmt = REAL_MODE_FORMAT (mode);
26947   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
26948   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
26949
26950   /* xa = xa + 0.5 */
26951   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
26952   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
26953
26954   /* xa = (double)(int64_t)xa */
26955   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
26956   expand_fix (xi, xa, 0);
26957   expand_float (xa, xi, 0);
26958
26959   /* res = copysign (xa, operand1) */
26960   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
26961
26962   emit_label (label);
26963   LABEL_NUSES (label) = 1;
26964
26965   emit_move_insn (operand0, res);
26966 }
26967
26968 \f
26969 /* Validate whether a SSE5 instruction is valid or not.
26970    OPERANDS is the array of operands.
26971    NUM is the number of operands.
26972    USES_OC0 is true if the instruction uses OC0 and provides 4 variants.
26973    NUM_MEMORY is the maximum number of memory operands to accept.  
26974    when COMMUTATIVE is set, operand 1 and 2 can be swapped.  */
26975
26976 bool
26977 ix86_sse5_valid_op_p (rtx operands[], rtx insn ATTRIBUTE_UNUSED, int num,
26978                       bool uses_oc0, int num_memory, bool commutative)
26979 {
26980   int mem_mask;
26981   int mem_count;
26982   int i;
26983
26984   /* Count the number of memory arguments */
26985   mem_mask = 0;
26986   mem_count = 0;
26987   for (i = 0; i < num; i++)
26988     {
26989       enum machine_mode mode = GET_MODE (operands[i]);
26990       if (register_operand (operands[i], mode))
26991         ;
26992
26993       else if (memory_operand (operands[i], mode))
26994         {
26995           mem_mask |= (1 << i);
26996           mem_count++;
26997         }
26998
26999       else
27000         {
27001           rtx pattern = PATTERN (insn);
27002
27003           /* allow 0 for pcmov */
27004           if (GET_CODE (pattern) != SET
27005               || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE
27006               || i < 2
27007               || operands[i] != CONST0_RTX (mode))
27008             return false;
27009         }
27010     }
27011
27012   /* Special case pmacsdq{l,h} where we allow the 3rd argument to be
27013      a memory operation.  */
27014   if (num_memory < 0)
27015     {
27016       num_memory = -num_memory;
27017       if ((mem_mask & (1 << (num-1))) != 0)
27018         {
27019           mem_mask &= ~(1 << (num-1));
27020           mem_count--;
27021         }
27022     }
27023
27024   /* If there were no memory operations, allow the insn */
27025   if (mem_mask == 0)
27026     return true;
27027
27028   /* Do not allow the destination register to be a memory operand.  */
27029   else if (mem_mask & (1 << 0))
27030     return false;
27031
27032   /* If there are too many memory operations, disallow the instruction.  While
27033      the hardware only allows 1 memory reference, before register allocation
27034      for some insns, we allow two memory operations sometimes in order to allow
27035      code like the following to be optimized:
27036
27037         float fmadd (float *a, float *b, float *c) { return (*a * *b) + *c; }
27038
27039     or similar cases that are vectorized into using the fmaddss
27040     instruction.  */
27041   else if (mem_count > num_memory)
27042     return false;
27043
27044   /* Don't allow more than one memory operation if not optimizing.  */
27045   else if (mem_count > 1 && !optimize)
27046     return false;
27047
27048   else if (num == 4 && mem_count == 1)
27049     {
27050       /* formats (destination is the first argument), example fmaddss:
27051          xmm1, xmm1, xmm2, xmm3/mem
27052          xmm1, xmm1, xmm2/mem, xmm3
27053          xmm1, xmm2, xmm3/mem, xmm1
27054          xmm1, xmm2/mem, xmm3, xmm1 */
27055       if (uses_oc0)
27056         return ((mem_mask == (1 << 1))
27057                 || (mem_mask == (1 << 2))
27058                 || (mem_mask == (1 << 3)));
27059
27060       /* format, example pmacsdd:
27061          xmm1, xmm2, xmm3/mem, xmm1 */
27062       if (commutative)
27063         return (mem_mask == (1 << 2) || mem_mask == (1 << 1));
27064       else
27065         return (mem_mask == (1 << 2));
27066     }
27067
27068   else if (num == 4 && num_memory == 2)
27069     {
27070       /* If there are two memory operations, we can load one of the memory ops
27071          into the destination register.  This is for optimizing the
27072          multiply/add ops, which the combiner has optimized both the multiply
27073          and the add insns to have a memory operation.  We have to be careful
27074          that the destination doesn't overlap with the inputs.  */
27075       rtx op0 = operands[0];
27076
27077       if (reg_mentioned_p (op0, operands[1])
27078           || reg_mentioned_p (op0, operands[2])
27079           || reg_mentioned_p (op0, operands[3]))
27080         return false;
27081
27082       /* formats (destination is the first argument), example fmaddss:
27083          xmm1, xmm1, xmm2, xmm3/mem
27084          xmm1, xmm1, xmm2/mem, xmm3
27085          xmm1, xmm2, xmm3/mem, xmm1
27086          xmm1, xmm2/mem, xmm3, xmm1
27087
27088          For the oc0 case, we will load either operands[1] or operands[3] into
27089          operands[0], so any combination of 2 memory operands is ok.  */
27090       if (uses_oc0)
27091         return true;
27092
27093       /* format, example pmacsdd:
27094          xmm1, xmm2, xmm3/mem, xmm1
27095
27096          For the integer multiply/add instructions be more restrictive and
27097          require operands[2] and operands[3] to be the memory operands.  */
27098       if (commutative)
27099         return (mem_mask == ((1 << 1) | (1 << 3)) || ((1 << 2) | (1 << 3)));
27100       else
27101         return (mem_mask == ((1 << 2) | (1 << 3)));
27102     }
27103
27104   else if (num == 3 && num_memory == 1)
27105     {
27106       /* formats, example protb:
27107          xmm1, xmm2, xmm3/mem
27108          xmm1, xmm2/mem, xmm3 */
27109       if (uses_oc0)
27110         return ((mem_mask == (1 << 1)) || (mem_mask == (1 << 2)));
27111
27112       /* format, example comeq:
27113          xmm1, xmm2, xmm3/mem */
27114       else
27115         return (mem_mask == (1 << 2));
27116     }
27117
27118   else
27119     gcc_unreachable ();
27120
27121   return false;
27122 }
27123
27124 \f
27125 /* Fixup an SSE5 instruction that has 2 memory input references into a form the
27126    hardware will allow by using the destination register to load one of the
27127    memory operations.  Presently this is used by the multiply/add routines to
27128    allow 2 memory references.  */
27129
27130 void
27131 ix86_expand_sse5_multiple_memory (rtx operands[],
27132                                   int num,
27133                                   enum machine_mode mode)
27134 {
27135   rtx op0 = operands[0];
27136   if (num != 4
27137       || memory_operand (op0, mode)
27138       || reg_mentioned_p (op0, operands[1])
27139       || reg_mentioned_p (op0, operands[2])
27140       || reg_mentioned_p (op0, operands[3]))
27141     gcc_unreachable ();
27142
27143   /* For 2 memory operands, pick either operands[1] or operands[3] to move into
27144      the destination register.  */
27145   if (memory_operand (operands[1], mode))
27146     {
27147       emit_move_insn (op0, operands[1]);
27148       operands[1] = op0;
27149     }
27150   else if (memory_operand (operands[3], mode))
27151     {
27152       emit_move_insn (op0, operands[3]);
27153       operands[3] = op0;
27154     }
27155   else
27156     gcc_unreachable ();
27157
27158   return;
27159 }
27160
27161 \f
27162 /* Table of valid machine attributes.  */
27163 static const struct attribute_spec ix86_attribute_table[] =
27164 {
27165   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
27166   /* Stdcall attribute says callee is responsible for popping arguments
27167      if they are not variable.  */
27168   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute },
27169   /* Fastcall attribute says callee is responsible for popping arguments
27170      if they are not variable.  */
27171   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute },
27172   /* Cdecl attribute says the callee is a normal C declaration */
27173   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute },
27174   /* Regparm attribute specifies how many integer arguments are to be
27175      passed in registers.  */
27176   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute },
27177   /* Sseregparm attribute says we are using x86_64 calling conventions
27178      for FP arguments.  */
27179   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute },
27180   /* force_align_arg_pointer says this function realigns the stack at entry.  */
27181   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
27182     false, true,  true, ix86_handle_cconv_attribute },
27183 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
27184   { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
27185   { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
27186   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute },
27187 #endif
27188   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
27189   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
27190 #ifdef SUBTARGET_ATTRIBUTE_TABLE
27191   SUBTARGET_ATTRIBUTE_TABLE,
27192 #endif
27193   /* ms_abi and sysv_abi calling convention function attributes.  */
27194   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
27195   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
27196   /* End element.  */
27197   { NULL,        0, 0, false, false, false, NULL }
27198 };
27199
27200 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
27201 static int
27202 x86_builtin_vectorization_cost (bool runtime_test)
27203 {
27204   /* If the branch of the runtime test is taken - i.e. - the vectorized
27205      version is skipped - this incurs a misprediction cost (because the
27206      vectorized version is expected to be the fall-through).  So we subtract
27207      the latency of a mispredicted branch from the costs that are incured
27208      when the vectorized version is executed.
27209
27210      TODO: The values in individual target tables have to be tuned or new
27211      fields may be needed. For eg. on K8, the default branch path is the
27212      not-taken path. If the taken path is predicted correctly, the minimum
27213      penalty of going down the taken-path is 1 cycle. If the taken-path is
27214      not predicted correctly, then the minimum penalty is 10 cycles.  */
27215
27216   if (runtime_test)
27217     {
27218       return (-(ix86_cost->cond_taken_branch_cost));
27219     }
27220   else
27221     return 0;
27222 }
27223
27224 /* This function returns the calling abi specific va_list type node.
27225    It returns  the FNDECL specific va_list type.  */
27226
27227 tree
27228 ix86_fn_abi_va_list (tree fndecl)
27229 {
27230   int abi;
27231
27232   if (!TARGET_64BIT)
27233     return va_list_type_node;
27234   gcc_assert (fndecl != NULL_TREE);
27235   abi = ix86_function_abi ((const_tree) fndecl);
27236
27237   if (abi == MS_ABI)
27238     return ms_va_list_type_node;
27239   else
27240     return sysv_va_list_type_node;
27241 }
27242
27243 /* Returns the canonical va_list type specified by TYPE. If there
27244    is no valid TYPE provided, it return NULL_TREE.  */
27245
27246 tree
27247 ix86_canonical_va_list_type (tree type)
27248 {
27249   tree wtype, htype;
27250
27251   /* Resolve references and pointers to va_list type.  */
27252   if (INDIRECT_REF_P (type))
27253     type = TREE_TYPE (type);
27254   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
27255     type = TREE_TYPE (type);
27256
27257   if (TARGET_64BIT)
27258     {
27259       wtype = va_list_type_node;
27260           gcc_assert (wtype != NULL_TREE);
27261       htype = type;
27262       if (TREE_CODE (wtype) == ARRAY_TYPE)
27263         {
27264           /* If va_list is an array type, the argument may have decayed
27265              to a pointer type, e.g. by being passed to another function.
27266              In that case, unwrap both types so that we can compare the
27267              underlying records.  */
27268           if (TREE_CODE (htype) == ARRAY_TYPE
27269               || POINTER_TYPE_P (htype))
27270             {
27271               wtype = TREE_TYPE (wtype);
27272               htype = TREE_TYPE (htype);
27273             }
27274         }
27275       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
27276         return va_list_type_node;
27277       wtype = sysv_va_list_type_node;
27278           gcc_assert (wtype != NULL_TREE);
27279       htype = type;
27280       if (TREE_CODE (wtype) == ARRAY_TYPE)
27281         {
27282           /* If va_list is an array type, the argument may have decayed
27283              to a pointer type, e.g. by being passed to another function.
27284              In that case, unwrap both types so that we can compare the
27285              underlying records.  */
27286           if (TREE_CODE (htype) == ARRAY_TYPE
27287               || POINTER_TYPE_P (htype))
27288             {
27289               wtype = TREE_TYPE (wtype);
27290               htype = TREE_TYPE (htype);
27291             }
27292         }
27293       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
27294         return sysv_va_list_type_node;
27295       wtype = ms_va_list_type_node;
27296           gcc_assert (wtype != NULL_TREE);
27297       htype = type;
27298       if (TREE_CODE (wtype) == ARRAY_TYPE)
27299         {
27300           /* If va_list is an array type, the argument may have decayed
27301              to a pointer type, e.g. by being passed to another function.
27302              In that case, unwrap both types so that we can compare the
27303              underlying records.  */
27304           if (TREE_CODE (htype) == ARRAY_TYPE
27305               || POINTER_TYPE_P (htype))
27306             {
27307               wtype = TREE_TYPE (wtype);
27308               htype = TREE_TYPE (htype);
27309             }
27310         }
27311       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
27312         return ms_va_list_type_node;
27313       return NULL_TREE;
27314     }
27315   return std_canonical_va_list_type (type);
27316 }
27317
27318 /* Iterate through the target-specific builtin types for va_list.
27319     IDX denotes the iterator, *PTREE is set to the result type of
27320     the va_list builtin, and *PNAME to its internal type.
27321     Returns zero if there is no element for this index, otherwise
27322     IDX should be increased upon the next call.
27323     Note, do not iterate a base builtin's name like __builtin_va_list.
27324     Used from c_common_nodes_and_builtins.  */
27325
27326 int
27327 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
27328 {
27329   if (!TARGET_64BIT)
27330     return 0;
27331   switch (idx) {
27332   case 0:
27333     *ptree = ms_va_list_type_node;
27334     *pname = "__builtin_ms_va_list";
27335     break;
27336   case 1:
27337     *ptree = sysv_va_list_type_node;
27338     *pname = "__builtin_sysv_va_list";
27339     break;
27340   default:
27341     return 0;
27342   }
27343   return 1;
27344 }
27345
27346 /* Initialize the GCC target structure.  */
27347 #undef TARGET_RETURN_IN_MEMORY
27348 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
27349
27350 #undef TARGET_ATTRIBUTE_TABLE
27351 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
27352 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
27353 #  undef TARGET_MERGE_DECL_ATTRIBUTES
27354 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
27355 #endif
27356
27357 #undef TARGET_COMP_TYPE_ATTRIBUTES
27358 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
27359
27360 #undef TARGET_INIT_BUILTINS
27361 #define TARGET_INIT_BUILTINS ix86_init_builtins
27362 #undef TARGET_EXPAND_BUILTIN
27363 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
27364
27365 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
27366 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
27367   ix86_builtin_vectorized_function
27368
27369 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
27370 #define TARGET_VECTORIZE_BUILTIN_CONVERSION ix86_vectorize_builtin_conversion
27371
27372 #undef TARGET_BUILTIN_RECIPROCAL
27373 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
27374
27375 #undef TARGET_ASM_FUNCTION_EPILOGUE
27376 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
27377
27378 #undef TARGET_ENCODE_SECTION_INFO
27379 #ifndef SUBTARGET_ENCODE_SECTION_INFO
27380 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
27381 #else
27382 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
27383 #endif
27384
27385 #undef TARGET_ASM_OPEN_PAREN
27386 #define TARGET_ASM_OPEN_PAREN ""
27387 #undef TARGET_ASM_CLOSE_PAREN
27388 #define TARGET_ASM_CLOSE_PAREN ""
27389
27390 #undef TARGET_ASM_ALIGNED_HI_OP
27391 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
27392 #undef TARGET_ASM_ALIGNED_SI_OP
27393 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
27394 #ifdef ASM_QUAD
27395 #undef TARGET_ASM_ALIGNED_DI_OP
27396 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
27397 #endif
27398
27399 #undef TARGET_ASM_UNALIGNED_HI_OP
27400 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
27401 #undef TARGET_ASM_UNALIGNED_SI_OP
27402 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
27403 #undef TARGET_ASM_UNALIGNED_DI_OP
27404 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
27405
27406 #undef TARGET_SCHED_ADJUST_COST
27407 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
27408 #undef TARGET_SCHED_ISSUE_RATE
27409 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
27410 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
27411 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
27412   ia32_multipass_dfa_lookahead
27413
27414 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
27415 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
27416
27417 #ifdef HAVE_AS_TLS
27418 #undef TARGET_HAVE_TLS
27419 #define TARGET_HAVE_TLS true
27420 #endif
27421 #undef TARGET_CANNOT_FORCE_CONST_MEM
27422 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
27423 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
27424 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
27425
27426 #undef TARGET_DELEGITIMIZE_ADDRESS
27427 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
27428
27429 #undef TARGET_MS_BITFIELD_LAYOUT_P
27430 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
27431
27432 #if TARGET_MACHO
27433 #undef TARGET_BINDS_LOCAL_P
27434 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
27435 #endif
27436 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
27437 #undef TARGET_BINDS_LOCAL_P
27438 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
27439 #endif
27440
27441 #undef TARGET_ASM_OUTPUT_MI_THUNK
27442 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
27443 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
27444 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
27445
27446 #undef TARGET_ASM_FILE_START
27447 #define TARGET_ASM_FILE_START x86_file_start
27448
27449 #undef TARGET_DEFAULT_TARGET_FLAGS
27450 #define TARGET_DEFAULT_TARGET_FLAGS     \
27451   (TARGET_DEFAULT                       \
27452    | TARGET_SUBTARGET_DEFAULT           \
27453    | TARGET_TLS_DIRECT_SEG_REFS_DEFAULT)
27454
27455 #undef TARGET_HANDLE_OPTION
27456 #define TARGET_HANDLE_OPTION ix86_handle_option
27457
27458 #undef TARGET_RTX_COSTS
27459 #define TARGET_RTX_COSTS ix86_rtx_costs
27460 #undef TARGET_ADDRESS_COST
27461 #define TARGET_ADDRESS_COST ix86_address_cost
27462
27463 #undef TARGET_FIXED_CONDITION_CODE_REGS
27464 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
27465 #undef TARGET_CC_MODES_COMPATIBLE
27466 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
27467
27468 #undef TARGET_MACHINE_DEPENDENT_REORG
27469 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
27470
27471 #undef TARGET_BUILD_BUILTIN_VA_LIST
27472 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
27473
27474 #undef TARGET_FN_ABI_VA_LIST
27475 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
27476
27477 #undef TARGET_CANONICAL_VA_LIST_TYPE
27478 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
27479
27480 #undef TARGET_EXPAND_BUILTIN_VA_START
27481 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
27482
27483 #undef TARGET_MD_ASM_CLOBBERS
27484 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
27485
27486 #undef TARGET_PROMOTE_PROTOTYPES
27487 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
27488 #undef TARGET_STRUCT_VALUE_RTX
27489 #define TARGET_STRUCT_VALUE_RTX ix86_struct_value_rtx
27490 #undef TARGET_SETUP_INCOMING_VARARGS
27491 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
27492 #undef TARGET_MUST_PASS_IN_STACK
27493 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
27494 #undef TARGET_PASS_BY_REFERENCE
27495 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
27496 #undef TARGET_INTERNAL_ARG_POINTER
27497 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
27498 #undef TARGET_UPDATE_STACK_BOUNDARY
27499 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
27500 #undef TARGET_GET_DRAP_RTX
27501 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
27502 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
27503 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC ix86_dwarf_handle_frame_unspec
27504 #undef TARGET_STRICT_ARGUMENT_NAMING
27505 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
27506
27507 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
27508 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
27509
27510 #undef TARGET_SCALAR_MODE_SUPPORTED_P
27511 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
27512
27513 #undef TARGET_VECTOR_MODE_SUPPORTED_P
27514 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
27515
27516 #undef TARGET_C_MODE_FOR_SUFFIX
27517 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
27518
27519 #ifdef HAVE_AS_TLS
27520 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
27521 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
27522 #endif
27523
27524 #ifdef SUBTARGET_INSERT_ATTRIBUTES
27525 #undef TARGET_INSERT_ATTRIBUTES
27526 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
27527 #endif
27528
27529 #undef TARGET_MANGLE_TYPE
27530 #define TARGET_MANGLE_TYPE ix86_mangle_type
27531
27532 #undef TARGET_STACK_PROTECT_FAIL
27533 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
27534
27535 #undef TARGET_FUNCTION_VALUE
27536 #define TARGET_FUNCTION_VALUE ix86_function_value
27537
27538 #undef TARGET_SECONDARY_RELOAD
27539 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
27540
27541 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
27542 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST x86_builtin_vectorization_cost
27543
27544 #undef TARGET_SET_CURRENT_FUNCTION
27545 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
27546
27547 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
27548 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_option_attribute_p
27549
27550 #undef TARGET_OPTION_SAVE
27551 #define TARGET_OPTION_SAVE ix86_function_specific_save
27552
27553 #undef TARGET_OPTION_RESTORE
27554 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
27555
27556 #undef TARGET_OPTION_PRINT
27557 #define TARGET_OPTION_PRINT ix86_function_specific_print
27558
27559 #undef TARGET_OPTION_CAN_INLINE_P
27560 #define TARGET_OPTION_CAN_INLINE_P ix86_can_inline_p
27561
27562 #undef TARGET_OPTION_COLD_ATTRIBUTE_SETS_OPTIMIZATION
27563 #define TARGET_OPTION_COLD_ATTRIBUTE_SETS_OPTIMIZATION true
27564
27565 #undef TARGET_OPTION_HOT_ATTRIBUTE_SETS_OPTIMIZATION
27566 #define TARGET_OPTION_HOT_ATTRIBUTE_SETS_OPTIMIZATION true
27567
27568 struct gcc_target targetm = TARGET_INITIALIZER;
27569 \f
27570 #include "gt-i386.h"