OSDN Git Service

ce699addb8bbaa09c1a6de36ced2c4e8f6307d64
[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 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "tm_p.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "output.h"
34 #include "insn-codes.h"
35 #include "insn-attr.h"
36 #include "flags.h"
37 #include "except.h"
38 #include "function.h"
39 #include "recog.h"
40 #include "expr.h"
41 #include "optabs.h"
42 #include "toplev.h"
43 #include "basic-block.h"
44 #include "ggc.h"
45 #include "target.h"
46 #include "target-def.h"
47 #include "langhooks.h"
48 #include "cgraph.h"
49 #include "tree-gimple.h"
50 #include "dwarf2.h"
51 #include "df.h"
52 #include "tm-constrs.h"
53 #include "params.h"
54
55 static int x86_builtin_vectorization_cost (bool);
56
57 #ifndef CHECK_STACK_LIMIT
58 #define CHECK_STACK_LIMIT (-1)
59 #endif
60
61 /* Return index of given mode in mult and division cost tables.  */
62 #define MODE_INDEX(mode)                                        \
63   ((mode) == QImode ? 0                                         \
64    : (mode) == HImode ? 1                                       \
65    : (mode) == SImode ? 2                                       \
66    : (mode) == DImode ? 3                                       \
67    : 4)
68
69 /* Processor costs (relative to an add) */
70 /* We assume COSTS_N_INSNS is defined as (N)*4 and an addition is 2 bytes.  */
71 #define COSTS_N_BYTES(N) ((N) * 2)
72
73 #define DUMMY_STRINGOP_ALGS {libcall, {{-1, libcall}}}
74
75 static const
76 struct processor_costs size_cost = {    /* costs for tuning for size */
77   COSTS_N_BYTES (2),                    /* cost of an add instruction */
78   COSTS_N_BYTES (3),                    /* cost of a lea instruction */
79   COSTS_N_BYTES (2),                    /* variable shift costs */
80   COSTS_N_BYTES (3),                    /* constant shift costs */
81   {COSTS_N_BYTES (3),                   /* cost of starting multiply for QI */
82    COSTS_N_BYTES (3),                   /*                               HI */
83    COSTS_N_BYTES (3),                   /*                               SI */
84    COSTS_N_BYTES (3),                   /*                               DI */
85    COSTS_N_BYTES (5)},                  /*                            other */
86   0,                                    /* cost of multiply per each bit set */
87   {COSTS_N_BYTES (3),                   /* cost of a divide/mod for QI */
88    COSTS_N_BYTES (3),                   /*                          HI */
89    COSTS_N_BYTES (3),                   /*                          SI */
90    COSTS_N_BYTES (3),                   /*                          DI */
91    COSTS_N_BYTES (5)},                  /*                       other */
92   COSTS_N_BYTES (3),                    /* cost of movsx */
93   COSTS_N_BYTES (3),                    /* cost of movzx */
94   0,                                    /* "large" insn */
95   2,                                    /* MOVE_RATIO */
96   2,                                    /* cost for loading QImode using movzbl */
97   {2, 2, 2},                            /* cost of loading integer registers
98                                            in QImode, HImode and SImode.
99                                            Relative to reg-reg move (2).  */
100   {2, 2, 2},                            /* cost of storing integer registers */
101   2,                                    /* cost of reg,reg fld/fst */
102   {2, 2, 2},                            /* cost of loading fp registers
103                                            in SFmode, DFmode and XFmode */
104   {2, 2, 2},                            /* cost of storing fp registers
105                                            in SFmode, DFmode and XFmode */
106   3,                                    /* cost of moving MMX register */
107   {3, 3},                               /* cost of loading MMX registers
108                                            in SImode and DImode */
109   {3, 3},                               /* cost of storing MMX registers
110                                            in SImode and DImode */
111   3,                                    /* cost of moving SSE register */
112   {3, 3, 3},                            /* cost of loading SSE registers
113                                            in SImode, DImode and TImode */
114   {3, 3, 3},                            /* cost of storing SSE registers
115                                            in SImode, DImode and TImode */
116   3,                                    /* MMX or SSE register to integer */
117   0,                                    /* size of l1 cache  */
118   0,                                    /* size of l2 cache  */
119   0,                                    /* size of prefetch block */
120   0,                                    /* number of parallel prefetches */
121   2,                                    /* Branch cost */
122   COSTS_N_BYTES (2),                    /* cost of FADD and FSUB insns.  */
123   COSTS_N_BYTES (2),                    /* cost of FMUL instruction.  */
124   COSTS_N_BYTES (2),                    /* cost of FDIV instruction.  */
125   COSTS_N_BYTES (2),                    /* cost of FABS instruction.  */
126   COSTS_N_BYTES (2),                    /* cost of FCHS instruction.  */
127   COSTS_N_BYTES (2),                    /* cost of FSQRT instruction.  */
128   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
129    {rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}}},
130   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
131    {rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}}},
132   1,                                    /* scalar_stmt_cost.  */
133   1,                                    /* scalar load_cost.  */
134   1,                                    /* scalar_store_cost.  */
135   1,                                    /* vec_stmt_cost.  */
136   1,                                    /* vec_to_scalar_cost.  */
137   1,                                    /* scalar_to_vec_cost.  */
138   1,                                    /* vec_align_load_cost.  */
139   1,                                    /* vec_unalign_load_cost.  */
140   1,                                    /* vec_store_cost.  */
141   1,                                    /* cond_taken_branch_cost.  */
142   1,                                    /* cond_not_taken_branch_cost.  */
143 };
144
145 /* Processor costs (relative to an add) */
146 static const
147 struct processor_costs i386_cost = {    /* 386 specific costs */
148   COSTS_N_INSNS (1),                    /* cost of an add instruction */
149   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
150   COSTS_N_INSNS (3),                    /* variable shift costs */
151   COSTS_N_INSNS (2),                    /* constant shift costs */
152   {COSTS_N_INSNS (6),                   /* cost of starting multiply for QI */
153    COSTS_N_INSNS (6),                   /*                               HI */
154    COSTS_N_INSNS (6),                   /*                               SI */
155    COSTS_N_INSNS (6),                   /*                               DI */
156    COSTS_N_INSNS (6)},                  /*                               other */
157   COSTS_N_INSNS (1),                    /* cost of multiply per each bit set */
158   {COSTS_N_INSNS (23),                  /* cost of a divide/mod for QI */
159    COSTS_N_INSNS (23),                  /*                          HI */
160    COSTS_N_INSNS (23),                  /*                          SI */
161    COSTS_N_INSNS (23),                  /*                          DI */
162    COSTS_N_INSNS (23)},                 /*                          other */
163   COSTS_N_INSNS (3),                    /* cost of movsx */
164   COSTS_N_INSNS (2),                    /* cost of movzx */
165   15,                                   /* "large" insn */
166   3,                                    /* MOVE_RATIO */
167   4,                                    /* cost for loading QImode using movzbl */
168   {2, 4, 2},                            /* cost of loading integer registers
169                                            in QImode, HImode and SImode.
170                                            Relative to reg-reg move (2).  */
171   {2, 4, 2},                            /* cost of storing integer registers */
172   2,                                    /* cost of reg,reg fld/fst */
173   {8, 8, 8},                            /* cost of loading fp registers
174                                            in SFmode, DFmode and XFmode */
175   {8, 8, 8},                            /* cost of storing fp registers
176                                            in SFmode, DFmode and XFmode */
177   2,                                    /* cost of moving MMX register */
178   {4, 8},                               /* cost of loading MMX registers
179                                            in SImode and DImode */
180   {4, 8},                               /* cost of storing MMX registers
181                                            in SImode and DImode */
182   2,                                    /* cost of moving SSE register */
183   {4, 8, 16},                           /* cost of loading SSE registers
184                                            in SImode, DImode and TImode */
185   {4, 8, 16},                           /* cost of storing SSE registers
186                                            in SImode, DImode and TImode */
187   3,                                    /* MMX or SSE register to integer */
188   0,                                    /* size of l1 cache  */
189   0,                                    /* size of l2 cache  */
190   0,                                    /* size of prefetch block */
191   0,                                    /* number of parallel prefetches */
192   1,                                    /* Branch cost */
193   COSTS_N_INSNS (23),                   /* cost of FADD and FSUB insns.  */
194   COSTS_N_INSNS (27),                   /* cost of FMUL instruction.  */
195   COSTS_N_INSNS (88),                   /* cost of FDIV instruction.  */
196   COSTS_N_INSNS (22),                   /* cost of FABS instruction.  */
197   COSTS_N_INSNS (24),                   /* cost of FCHS instruction.  */
198   COSTS_N_INSNS (122),                  /* cost of FSQRT instruction.  */
199   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
200    DUMMY_STRINGOP_ALGS},
201   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
202    DUMMY_STRINGOP_ALGS},
203   1,                                    /* scalar_stmt_cost.  */
204   1,                                    /* scalar load_cost.  */
205   1,                                    /* scalar_store_cost.  */
206   1,                                    /* vec_stmt_cost.  */
207   1,                                    /* vec_to_scalar_cost.  */
208   1,                                    /* scalar_to_vec_cost.  */
209   1,                                    /* vec_align_load_cost.  */
210   2,                                    /* vec_unalign_load_cost.  */
211   1,                                    /* vec_store_cost.  */
212   3,                                    /* cond_taken_branch_cost.  */
213   1,                                    /* cond_not_taken_branch_cost.  */
214 };
215
216 static const
217 struct processor_costs i486_cost = {    /* 486 specific costs */
218   COSTS_N_INSNS (1),                    /* cost of an add instruction */
219   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
220   COSTS_N_INSNS (3),                    /* variable shift costs */
221   COSTS_N_INSNS (2),                    /* constant shift costs */
222   {COSTS_N_INSNS (12),                  /* cost of starting multiply for QI */
223    COSTS_N_INSNS (12),                  /*                               HI */
224    COSTS_N_INSNS (12),                  /*                               SI */
225    COSTS_N_INSNS (12),                  /*                               DI */
226    COSTS_N_INSNS (12)},                 /*                               other */
227   1,                                    /* cost of multiply per each bit set */
228   {COSTS_N_INSNS (40),                  /* cost of a divide/mod for QI */
229    COSTS_N_INSNS (40),                  /*                          HI */
230    COSTS_N_INSNS (40),                  /*                          SI */
231    COSTS_N_INSNS (40),                  /*                          DI */
232    COSTS_N_INSNS (40)},                 /*                          other */
233   COSTS_N_INSNS (3),                    /* cost of movsx */
234   COSTS_N_INSNS (2),                    /* cost of movzx */
235   15,                                   /* "large" insn */
236   3,                                    /* MOVE_RATIO */
237   4,                                    /* cost for loading QImode using movzbl */
238   {2, 4, 2},                            /* cost of loading integer registers
239                                            in QImode, HImode and SImode.
240                                            Relative to reg-reg move (2).  */
241   {2, 4, 2},                            /* cost of storing integer registers */
242   2,                                    /* cost of reg,reg fld/fst */
243   {8, 8, 8},                            /* cost of loading fp registers
244                                            in SFmode, DFmode and XFmode */
245   {8, 8, 8},                            /* cost of storing fp registers
246                                            in SFmode, DFmode and XFmode */
247   2,                                    /* cost of moving MMX register */
248   {4, 8},                               /* cost of loading MMX registers
249                                            in SImode and DImode */
250   {4, 8},                               /* cost of storing MMX registers
251                                            in SImode and DImode */
252   2,                                    /* cost of moving SSE register */
253   {4, 8, 16},                           /* cost of loading SSE registers
254                                            in SImode, DImode and TImode */
255   {4, 8, 16},                           /* cost of storing SSE registers
256                                            in SImode, DImode and TImode */
257   3,                                    /* MMX or SSE register to integer */
258   4,                                    /* size of l1 cache.  486 has 8kB cache
259                                            shared for code and data, so 4kB is
260                                            not really precise.  */
261   4,                                    /* size of l2 cache  */
262   0,                                    /* size of prefetch block */
263   0,                                    /* number of parallel prefetches */
264   1,                                    /* Branch cost */
265   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
266   COSTS_N_INSNS (16),                   /* cost of FMUL instruction.  */
267   COSTS_N_INSNS (73),                   /* cost of FDIV instruction.  */
268   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
269   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
270   COSTS_N_INSNS (83),                   /* cost of FSQRT instruction.  */
271   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
272    DUMMY_STRINGOP_ALGS},
273   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
274    DUMMY_STRINGOP_ALGS},
275   1,                                    /* scalar_stmt_cost.  */
276   1,                                    /* scalar load_cost.  */
277   1,                                    /* scalar_store_cost.  */
278   1,                                    /* vec_stmt_cost.  */
279   1,                                    /* vec_to_scalar_cost.  */
280   1,                                    /* scalar_to_vec_cost.  */
281   1,                                    /* vec_align_load_cost.  */
282   2,                                    /* vec_unalign_load_cost.  */
283   1,                                    /* vec_store_cost.  */
284   3,                                    /* cond_taken_branch_cost.  */
285   1,                                    /* cond_not_taken_branch_cost.  */
286 };
287
288 static const
289 struct processor_costs pentium_cost = {
290   COSTS_N_INSNS (1),                    /* cost of an add instruction */
291   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
292   COSTS_N_INSNS (4),                    /* variable shift costs */
293   COSTS_N_INSNS (1),                    /* constant shift costs */
294   {COSTS_N_INSNS (11),                  /* cost of starting multiply for QI */
295    COSTS_N_INSNS (11),                  /*                               HI */
296    COSTS_N_INSNS (11),                  /*                               SI */
297    COSTS_N_INSNS (11),                  /*                               DI */
298    COSTS_N_INSNS (11)},                 /*                               other */
299   0,                                    /* cost of multiply per each bit set */
300   {COSTS_N_INSNS (25),                  /* cost of a divide/mod for QI */
301    COSTS_N_INSNS (25),                  /*                          HI */
302    COSTS_N_INSNS (25),                  /*                          SI */
303    COSTS_N_INSNS (25),                  /*                          DI */
304    COSTS_N_INSNS (25)},                 /*                          other */
305   COSTS_N_INSNS (3),                    /* cost of movsx */
306   COSTS_N_INSNS (2),                    /* cost of movzx */
307   8,                                    /* "large" insn */
308   6,                                    /* MOVE_RATIO */
309   6,                                    /* cost for loading QImode using movzbl */
310   {2, 4, 2},                            /* cost of loading integer registers
311                                            in QImode, HImode and SImode.
312                                            Relative to reg-reg move (2).  */
313   {2, 4, 2},                            /* cost of storing integer registers */
314   2,                                    /* cost of reg,reg fld/fst */
315   {2, 2, 6},                            /* cost of loading fp registers
316                                            in SFmode, DFmode and XFmode */
317   {4, 4, 6},                            /* cost of storing fp registers
318                                            in SFmode, DFmode and XFmode */
319   8,                                    /* cost of moving MMX register */
320   {8, 8},                               /* cost of loading MMX registers
321                                            in SImode and DImode */
322   {8, 8},                               /* cost of storing MMX registers
323                                            in SImode and DImode */
324   2,                                    /* cost of moving SSE register */
325   {4, 8, 16},                           /* cost of loading SSE registers
326                                            in SImode, DImode and TImode */
327   {4, 8, 16},                           /* cost of storing SSE registers
328                                            in SImode, DImode and TImode */
329   3,                                    /* MMX or SSE register to integer */
330   8,                                    /* size of l1 cache.  */
331   8,                                    /* size of l2 cache  */
332   0,                                    /* size of prefetch block */
333   0,                                    /* number of parallel prefetches */
334   2,                                    /* Branch cost */
335   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
336   COSTS_N_INSNS (3),                    /* cost of FMUL instruction.  */
337   COSTS_N_INSNS (39),                   /* cost of FDIV instruction.  */
338   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
339   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
340   COSTS_N_INSNS (70),                   /* cost of FSQRT instruction.  */
341   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
342    DUMMY_STRINGOP_ALGS},
343   {{libcall, {{-1, rep_prefix_4_byte}}},
344    DUMMY_STRINGOP_ALGS},
345   1,                                    /* scalar_stmt_cost.  */
346   1,                                    /* scalar load_cost.  */
347   1,                                    /* scalar_store_cost.  */
348   1,                                    /* vec_stmt_cost.  */
349   1,                                    /* vec_to_scalar_cost.  */
350   1,                                    /* scalar_to_vec_cost.  */
351   1,                                    /* vec_align_load_cost.  */
352   2,                                    /* vec_unalign_load_cost.  */
353   1,                                    /* vec_store_cost.  */
354   3,                                    /* cond_taken_branch_cost.  */
355   1,                                    /* cond_not_taken_branch_cost.  */
356 };
357
358 static const
359 struct processor_costs pentiumpro_cost = {
360   COSTS_N_INSNS (1),                    /* cost of an add instruction */
361   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
362   COSTS_N_INSNS (1),                    /* variable shift costs */
363   COSTS_N_INSNS (1),                    /* constant shift costs */
364   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
365    COSTS_N_INSNS (4),                   /*                               HI */
366    COSTS_N_INSNS (4),                   /*                               SI */
367    COSTS_N_INSNS (4),                   /*                               DI */
368    COSTS_N_INSNS (4)},                  /*                               other */
369   0,                                    /* cost of multiply per each bit set */
370   {COSTS_N_INSNS (17),                  /* cost of a divide/mod for QI */
371    COSTS_N_INSNS (17),                  /*                          HI */
372    COSTS_N_INSNS (17),                  /*                          SI */
373    COSTS_N_INSNS (17),                  /*                          DI */
374    COSTS_N_INSNS (17)},                 /*                          other */
375   COSTS_N_INSNS (1),                    /* cost of movsx */
376   COSTS_N_INSNS (1),                    /* cost of movzx */
377   8,                                    /* "large" insn */
378   6,                                    /* MOVE_RATIO */
379   2,                                    /* cost for loading QImode using movzbl */
380   {4, 4, 4},                            /* cost of loading integer registers
381                                            in QImode, HImode and SImode.
382                                            Relative to reg-reg move (2).  */
383   {2, 2, 2},                            /* cost of storing integer registers */
384   2,                                    /* cost of reg,reg fld/fst */
385   {2, 2, 6},                            /* cost of loading fp registers
386                                            in SFmode, DFmode and XFmode */
387   {4, 4, 6},                            /* cost of storing fp registers
388                                            in SFmode, DFmode and XFmode */
389   2,                                    /* cost of moving MMX register */
390   {2, 2},                               /* cost of loading MMX registers
391                                            in SImode and DImode */
392   {2, 2},                               /* cost of storing MMX registers
393                                            in SImode and DImode */
394   2,                                    /* cost of moving SSE register */
395   {2, 2, 8},                            /* cost of loading SSE registers
396                                            in SImode, DImode and TImode */
397   {2, 2, 8},                            /* cost of storing SSE registers
398                                            in SImode, DImode and TImode */
399   3,                                    /* MMX or SSE register to integer */
400   8,                                    /* size of l1 cache.  */
401   256,                                  /* size of l2 cache  */
402   32,                                   /* size of prefetch block */
403   6,                                    /* number of parallel prefetches */
404   2,                                    /* Branch cost */
405   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
406   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
407   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
408   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
409   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
410   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
411   /* PentiumPro has optimized rep instructions for blocks aligned by 8 bytes (we ensure
412      the alignment).  For small blocks inline loop is still a noticeable win, for bigger
413      blocks either rep movsl or rep movsb is way to go.  Rep movsb has apparently
414      more expensive startup time in CPU, but after 4K the difference is down in the noise.
415    */
416   {{rep_prefix_4_byte, {{128, loop}, {1024, unrolled_loop},
417                         {8192, rep_prefix_4_byte}, {-1, rep_prefix_1_byte}}},
418    DUMMY_STRINGOP_ALGS},
419   {{rep_prefix_4_byte, {{1024, unrolled_loop},
420                         {8192, rep_prefix_4_byte}, {-1, libcall}}},
421    DUMMY_STRINGOP_ALGS},
422   1,                                    /* scalar_stmt_cost.  */
423   1,                                    /* scalar load_cost.  */
424   1,                                    /* scalar_store_cost.  */
425   1,                                    /* vec_stmt_cost.  */
426   1,                                    /* vec_to_scalar_cost.  */
427   1,                                    /* scalar_to_vec_cost.  */
428   1,                                    /* vec_align_load_cost.  */
429   2,                                    /* vec_unalign_load_cost.  */
430   1,                                    /* vec_store_cost.  */
431   3,                                    /* cond_taken_branch_cost.  */
432   1,                                    /* cond_not_taken_branch_cost.  */
433 };
434
435 static const
436 struct processor_costs geode_cost = {
437   COSTS_N_INSNS (1),                    /* cost of an add instruction */
438   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
439   COSTS_N_INSNS (2),                    /* variable shift costs */
440   COSTS_N_INSNS (1),                    /* constant shift costs */
441   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
442    COSTS_N_INSNS (4),                   /*                               HI */
443    COSTS_N_INSNS (7),                   /*                               SI */
444    COSTS_N_INSNS (7),                   /*                               DI */
445    COSTS_N_INSNS (7)},                  /*                               other */
446   0,                                    /* cost of multiply per each bit set */
447   {COSTS_N_INSNS (15),                  /* cost of a divide/mod for QI */
448    COSTS_N_INSNS (23),                  /*                          HI */
449    COSTS_N_INSNS (39),                  /*                          SI */
450    COSTS_N_INSNS (39),                  /*                          DI */
451    COSTS_N_INSNS (39)},                 /*                          other */
452   COSTS_N_INSNS (1),                    /* cost of movsx */
453   COSTS_N_INSNS (1),                    /* cost of movzx */
454   8,                                    /* "large" insn */
455   4,                                    /* MOVE_RATIO */
456   1,                                    /* cost for loading QImode using movzbl */
457   {1, 1, 1},                            /* cost of loading integer registers
458                                            in QImode, HImode and SImode.
459                                            Relative to reg-reg move (2).  */
460   {1, 1, 1},                            /* cost of storing integer registers */
461   1,                                    /* cost of reg,reg fld/fst */
462   {1, 1, 1},                            /* cost of loading fp registers
463                                            in SFmode, DFmode and XFmode */
464   {4, 6, 6},                            /* cost of storing fp registers
465                                            in SFmode, DFmode and XFmode */
466
467   1,                                    /* cost of moving MMX register */
468   {1, 1},                               /* cost of loading MMX registers
469                                            in SImode and DImode */
470   {1, 1},                               /* cost of storing MMX registers
471                                            in SImode and DImode */
472   1,                                    /* cost of moving SSE register */
473   {1, 1, 1},                            /* cost of loading SSE registers
474                                            in SImode, DImode and TImode */
475   {1, 1, 1},                            /* cost of storing SSE registers
476                                            in SImode, DImode and TImode */
477   1,                                    /* MMX or SSE register to integer */
478   64,                                   /* size of l1 cache.  */
479   128,                                  /* size of l2 cache.  */
480   32,                                   /* size of prefetch block */
481   1,                                    /* number of parallel prefetches */
482   1,                                    /* Branch cost */
483   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
484   COSTS_N_INSNS (11),                   /* cost of FMUL instruction.  */
485   COSTS_N_INSNS (47),                   /* cost of FDIV instruction.  */
486   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
487   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
488   COSTS_N_INSNS (54),                   /* cost of FSQRT instruction.  */
489   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
490    DUMMY_STRINGOP_ALGS},
491   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
492    DUMMY_STRINGOP_ALGS},
493   1,                                    /* scalar_stmt_cost.  */
494   1,                                    /* scalar load_cost.  */
495   1,                                    /* scalar_store_cost.  */
496   1,                                    /* vec_stmt_cost.  */
497   1,                                    /* vec_to_scalar_cost.  */
498   1,                                    /* scalar_to_vec_cost.  */
499   1,                                    /* vec_align_load_cost.  */
500   2,                                    /* vec_unalign_load_cost.  */
501   1,                                    /* vec_store_cost.  */
502   3,                                    /* cond_taken_branch_cost.  */
503   1,                                    /* cond_not_taken_branch_cost.  */
504 };
505
506 static const
507 struct processor_costs k6_cost = {
508   COSTS_N_INSNS (1),                    /* cost of an add instruction */
509   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
510   COSTS_N_INSNS (1),                    /* variable shift costs */
511   COSTS_N_INSNS (1),                    /* constant shift costs */
512   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
513    COSTS_N_INSNS (3),                   /*                               HI */
514    COSTS_N_INSNS (3),                   /*                               SI */
515    COSTS_N_INSNS (3),                   /*                               DI */
516    COSTS_N_INSNS (3)},                  /*                               other */
517   0,                                    /* cost of multiply per each bit set */
518   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
519    COSTS_N_INSNS (18),                  /*                          HI */
520    COSTS_N_INSNS (18),                  /*                          SI */
521    COSTS_N_INSNS (18),                  /*                          DI */
522    COSTS_N_INSNS (18)},                 /*                          other */
523   COSTS_N_INSNS (2),                    /* cost of movsx */
524   COSTS_N_INSNS (2),                    /* cost of movzx */
525   8,                                    /* "large" insn */
526   4,                                    /* MOVE_RATIO */
527   3,                                    /* cost for loading QImode using movzbl */
528   {4, 5, 4},                            /* cost of loading integer registers
529                                            in QImode, HImode and SImode.
530                                            Relative to reg-reg move (2).  */
531   {2, 3, 2},                            /* cost of storing integer registers */
532   4,                                    /* cost of reg,reg fld/fst */
533   {6, 6, 6},                            /* cost of loading fp registers
534                                            in SFmode, DFmode and XFmode */
535   {4, 4, 4},                            /* cost of storing fp registers
536                                            in SFmode, DFmode and XFmode */
537   2,                                    /* cost of moving MMX register */
538   {2, 2},                               /* cost of loading MMX registers
539                                            in SImode and DImode */
540   {2, 2},                               /* cost of storing MMX registers
541                                            in SImode and DImode */
542   2,                                    /* cost of moving SSE register */
543   {2, 2, 8},                            /* cost of loading SSE registers
544                                            in SImode, DImode and TImode */
545   {2, 2, 8},                            /* cost of storing SSE registers
546                                            in SImode, DImode and TImode */
547   6,                                    /* MMX or SSE register to integer */
548   32,                                   /* size of l1 cache.  */
549   32,                                   /* size of l2 cache.  Some models
550                                            have integrated l2 cache, but
551                                            optimizing for k6 is not important
552                                            enough to worry about that.  */
553   32,                                   /* size of prefetch block */
554   1,                                    /* number of parallel prefetches */
555   1,                                    /* Branch cost */
556   COSTS_N_INSNS (2),                    /* cost of FADD and FSUB insns.  */
557   COSTS_N_INSNS (2),                    /* cost of FMUL instruction.  */
558   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
559   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
560   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
561   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
562   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
563    DUMMY_STRINGOP_ALGS},
564   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
565    DUMMY_STRINGOP_ALGS},
566   1,                                    /* scalar_stmt_cost.  */
567   1,                                    /* scalar load_cost.  */
568   1,                                    /* scalar_store_cost.  */
569   1,                                    /* vec_stmt_cost.  */
570   1,                                    /* vec_to_scalar_cost.  */
571   1,                                    /* scalar_to_vec_cost.  */
572   1,                                    /* vec_align_load_cost.  */
573   2,                                    /* vec_unalign_load_cost.  */
574   1,                                    /* vec_store_cost.  */
575   3,                                    /* cond_taken_branch_cost.  */
576   1,                                    /* cond_not_taken_branch_cost.  */
577 };
578
579 static const
580 struct processor_costs athlon_cost = {
581   COSTS_N_INSNS (1),                    /* cost of an add instruction */
582   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
583   COSTS_N_INSNS (1),                    /* variable shift costs */
584   COSTS_N_INSNS (1),                    /* constant shift costs */
585   {COSTS_N_INSNS (5),                   /* cost of starting multiply for QI */
586    COSTS_N_INSNS (5),                   /*                               HI */
587    COSTS_N_INSNS (5),                   /*                               SI */
588    COSTS_N_INSNS (5),                   /*                               DI */
589    COSTS_N_INSNS (5)},                  /*                               other */
590   0,                                    /* cost of multiply per each bit set */
591   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
592    COSTS_N_INSNS (26),                  /*                          HI */
593    COSTS_N_INSNS (42),                  /*                          SI */
594    COSTS_N_INSNS (74),                  /*                          DI */
595    COSTS_N_INSNS (74)},                 /*                          other */
596   COSTS_N_INSNS (1),                    /* cost of movsx */
597   COSTS_N_INSNS (1),                    /* cost of movzx */
598   8,                                    /* "large" insn */
599   9,                                    /* MOVE_RATIO */
600   4,                                    /* cost for loading QImode using movzbl */
601   {3, 4, 3},                            /* cost of loading integer registers
602                                            in QImode, HImode and SImode.
603                                            Relative to reg-reg move (2).  */
604   {3, 4, 3},                            /* cost of storing integer registers */
605   4,                                    /* cost of reg,reg fld/fst */
606   {4, 4, 12},                           /* cost of loading fp registers
607                                            in SFmode, DFmode and XFmode */
608   {6, 6, 8},                            /* cost of storing fp registers
609                                            in SFmode, DFmode and XFmode */
610   2,                                    /* cost of moving MMX register */
611   {4, 4},                               /* cost of loading MMX registers
612                                            in SImode and DImode */
613   {4, 4},                               /* cost of storing MMX registers
614                                            in SImode and DImode */
615   2,                                    /* cost of moving SSE register */
616   {4, 4, 6},                            /* cost of loading SSE registers
617                                            in SImode, DImode and TImode */
618   {4, 4, 5},                            /* cost of storing SSE registers
619                                            in SImode, DImode and TImode */
620   5,                                    /* MMX or SSE register to integer */
621   64,                                   /* size of l1 cache.  */
622   256,                                  /* size of l2 cache.  */
623   64,                                   /* size of prefetch block */
624   6,                                    /* number of parallel prefetches */
625   5,                                    /* Branch cost */
626   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
627   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
628   COSTS_N_INSNS (24),                   /* cost of FDIV instruction.  */
629   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
630   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
631   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
632   /* For some reason, Athlon deals better with REP prefix (relative to loops)
633      compared to K8. Alignment becomes important after 8 bytes for memcpy and
634      128 bytes for memset.  */
635   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
636    DUMMY_STRINGOP_ALGS},
637   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
638    DUMMY_STRINGOP_ALGS},
639   1,                                    /* scalar_stmt_cost.  */
640   1,                                    /* scalar load_cost.  */
641   1,                                    /* scalar_store_cost.  */
642   1,                                    /* vec_stmt_cost.  */
643   1,                                    /* vec_to_scalar_cost.  */
644   1,                                    /* scalar_to_vec_cost.  */
645   1,                                    /* vec_align_load_cost.  */
646   2,                                    /* vec_unalign_load_cost.  */
647   1,                                    /* vec_store_cost.  */
648   3,                                    /* cond_taken_branch_cost.  */
649   1,                                    /* cond_not_taken_branch_cost.  */
650 };
651
652 static const
653 struct processor_costs k8_cost = {
654   COSTS_N_INSNS (1),                    /* cost of an add instruction */
655   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
656   COSTS_N_INSNS (1),                    /* variable shift costs */
657   COSTS_N_INSNS (1),                    /* constant shift costs */
658   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
659    COSTS_N_INSNS (4),                   /*                               HI */
660    COSTS_N_INSNS (3),                   /*                               SI */
661    COSTS_N_INSNS (4),                   /*                               DI */
662    COSTS_N_INSNS (5)},                  /*                               other */
663   0,                                    /* cost of multiply per each bit set */
664   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
665    COSTS_N_INSNS (26),                  /*                          HI */
666    COSTS_N_INSNS (42),                  /*                          SI */
667    COSTS_N_INSNS (74),                  /*                          DI */
668    COSTS_N_INSNS (74)},                 /*                          other */
669   COSTS_N_INSNS (1),                    /* cost of movsx */
670   COSTS_N_INSNS (1),                    /* cost of movzx */
671   8,                                    /* "large" insn */
672   9,                                    /* MOVE_RATIO */
673   4,                                    /* cost for loading QImode using movzbl */
674   {3, 4, 3},                            /* cost of loading integer registers
675                                            in QImode, HImode and SImode.
676                                            Relative to reg-reg move (2).  */
677   {3, 4, 3},                            /* cost of storing integer registers */
678   4,                                    /* cost of reg,reg fld/fst */
679   {4, 4, 12},                           /* cost of loading fp registers
680                                            in SFmode, DFmode and XFmode */
681   {6, 6, 8},                            /* cost of storing fp registers
682                                            in SFmode, DFmode and XFmode */
683   2,                                    /* cost of moving MMX register */
684   {3, 3},                               /* cost of loading MMX registers
685                                            in SImode and DImode */
686   {4, 4},                               /* cost of storing MMX registers
687                                            in SImode and DImode */
688   2,                                    /* cost of moving SSE register */
689   {4, 3, 6},                            /* cost of loading SSE registers
690                                            in SImode, DImode and TImode */
691   {4, 4, 5},                            /* cost of storing SSE registers
692                                            in SImode, DImode and TImode */
693   5,                                    /* MMX or SSE register to integer */
694   64,                                   /* size of l1 cache.  */
695   512,                                  /* size of l2 cache.  */
696   64,                                   /* size of prefetch block */
697   /* New AMD processors never drop prefetches; if they cannot be performed
698      immediately, they are queued.  We set number of simultaneous prefetches
699      to a large constant to reflect this (it probably is not a good idea not
700      to limit number of prefetches at all, as their execution also takes some
701      time).  */
702   100,                                  /* number of parallel prefetches */
703   5,                                    /* Branch cost */
704   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
705   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
706   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
707   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
708   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
709   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
710   /* K8 has optimized REP instruction for medium sized blocks, but for very small
711      blocks it is better to use loop. For large blocks, libcall can do
712      nontemporary accesses and beat inline considerably.  */
713   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
714    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
715   {{libcall, {{8, loop}, {24, unrolled_loop},
716               {2048, rep_prefix_4_byte}, {-1, libcall}}},
717    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
718   4,                                    /* scalar_stmt_cost.  */
719   2,                                    /* scalar load_cost.  */
720   2,                                    /* scalar_store_cost.  */
721   5,                                    /* vec_stmt_cost.  */
722   0,                                    /* vec_to_scalar_cost.  */
723   2,                                    /* scalar_to_vec_cost.  */
724   2,                                    /* vec_align_load_cost.  */
725   3,                                    /* vec_unalign_load_cost.  */
726   3,                                    /* vec_store_cost.  */
727   6,                                    /* cond_taken_branch_cost.  */
728   1,                                    /* cond_not_taken_branch_cost.  */
729 };
730
731 struct processor_costs amdfam10_cost = {
732   COSTS_N_INSNS (1),                    /* cost of an add instruction */
733   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
734   COSTS_N_INSNS (1),                    /* variable shift costs */
735   COSTS_N_INSNS (1),                    /* constant shift costs */
736   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
737    COSTS_N_INSNS (4),                   /*                               HI */
738    COSTS_N_INSNS (3),                   /*                               SI */
739    COSTS_N_INSNS (4),                   /*                               DI */
740    COSTS_N_INSNS (5)},                  /*                               other */
741   0,                                    /* cost of multiply per each bit set */
742   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
743    COSTS_N_INSNS (35),                  /*                          HI */
744    COSTS_N_INSNS (51),                  /*                          SI */
745    COSTS_N_INSNS (83),                  /*                          DI */
746    COSTS_N_INSNS (83)},                 /*                          other */
747   COSTS_N_INSNS (1),                    /* cost of movsx */
748   COSTS_N_INSNS (1),                    /* cost of movzx */
749   8,                                    /* "large" insn */
750   9,                                    /* MOVE_RATIO */
751   4,                                    /* cost for loading QImode using movzbl */
752   {3, 4, 3},                            /* cost of loading integer registers
753                                            in QImode, HImode and SImode.
754                                            Relative to reg-reg move (2).  */
755   {3, 4, 3},                            /* cost of storing integer registers */
756   4,                                    /* cost of reg,reg fld/fst */
757   {4, 4, 12},                           /* cost of loading fp registers
758                                            in SFmode, DFmode and XFmode */
759   {6, 6, 8},                            /* cost of storing fp registers
760                                            in SFmode, DFmode and XFmode */
761   2,                                    /* cost of moving MMX register */
762   {3, 3},                               /* cost of loading MMX registers
763                                            in SImode and DImode */
764   {4, 4},                               /* cost of storing MMX registers
765                                            in SImode and DImode */
766   2,                                    /* cost of moving SSE register */
767   {4, 4, 3},                            /* cost of loading SSE registers
768                                            in SImode, DImode and TImode */
769   {4, 4, 5},                            /* cost of storing SSE registers
770                                            in SImode, DImode and TImode */
771   3,                                    /* MMX or SSE register to integer */
772                                         /* On K8
773                                             MOVD reg64, xmmreg  Double  FSTORE 4
774                                             MOVD reg32, xmmreg  Double  FSTORE 4
775                                            On AMDFAM10
776                                             MOVD reg64, xmmreg  Double  FADD 3
777                                                                 1/1  1/1
778                                             MOVD reg32, xmmreg  Double  FADD 3
779                                                                 1/1  1/1 */
780   64,                                   /* size of l1 cache.  */
781   512,                                  /* size of l2 cache.  */
782   64,                                   /* size of prefetch block */
783   /* New AMD processors never drop prefetches; if they cannot be performed
784      immediately, they are queued.  We set number of simultaneous prefetches
785      to a large constant to reflect this (it probably is not a good idea not
786      to limit number of prefetches at all, as their execution also takes some
787      time).  */
788   100,                                  /* number of parallel prefetches */
789   5,                                    /* Branch cost */
790   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
791   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
792   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
793   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
794   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
795   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
796
797   /* AMDFAM10 has optimized REP instruction for medium sized blocks, but for
798      very small blocks it is better to use loop. For large blocks, libcall can
799      do nontemporary accesses and beat inline considerably.  */
800   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
801    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
802   {{libcall, {{8, loop}, {24, unrolled_loop},
803               {2048, rep_prefix_4_byte}, {-1, libcall}}},
804    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
805   4,                                    /* scalar_stmt_cost.  */
806   2,                                    /* scalar load_cost.  */
807   2,                                    /* scalar_store_cost.  */
808   6,                                    /* vec_stmt_cost.  */
809   0,                                    /* vec_to_scalar_cost.  */
810   2,                                    /* scalar_to_vec_cost.  */
811   2,                                    /* vec_align_load_cost.  */
812   2,                                    /* vec_unalign_load_cost.  */
813   2,                                    /* vec_store_cost.  */
814   6,                                    /* cond_taken_branch_cost.  */
815   1,                                    /* cond_not_taken_branch_cost.  */
816 };
817
818 static const
819 struct processor_costs pentium4_cost = {
820   COSTS_N_INSNS (1),                    /* cost of an add instruction */
821   COSTS_N_INSNS (3),                    /* cost of a lea instruction */
822   COSTS_N_INSNS (4),                    /* variable shift costs */
823   COSTS_N_INSNS (4),                    /* constant shift costs */
824   {COSTS_N_INSNS (15),                  /* cost of starting multiply for QI */
825    COSTS_N_INSNS (15),                  /*                               HI */
826    COSTS_N_INSNS (15),                  /*                               SI */
827    COSTS_N_INSNS (15),                  /*                               DI */
828    COSTS_N_INSNS (15)},                 /*                               other */
829   0,                                    /* cost of multiply per each bit set */
830   {COSTS_N_INSNS (56),                  /* cost of a divide/mod for QI */
831    COSTS_N_INSNS (56),                  /*                          HI */
832    COSTS_N_INSNS (56),                  /*                          SI */
833    COSTS_N_INSNS (56),                  /*                          DI */
834    COSTS_N_INSNS (56)},                 /*                          other */
835   COSTS_N_INSNS (1),                    /* cost of movsx */
836   COSTS_N_INSNS (1),                    /* cost of movzx */
837   16,                                   /* "large" insn */
838   6,                                    /* MOVE_RATIO */
839   2,                                    /* cost for loading QImode using movzbl */
840   {4, 5, 4},                            /* cost of loading integer registers
841                                            in QImode, HImode and SImode.
842                                            Relative to reg-reg move (2).  */
843   {2, 3, 2},                            /* cost of storing integer registers */
844   2,                                    /* cost of reg,reg fld/fst */
845   {2, 2, 6},                            /* cost of loading fp registers
846                                            in SFmode, DFmode and XFmode */
847   {4, 4, 6},                            /* cost of storing fp registers
848                                            in SFmode, DFmode and XFmode */
849   2,                                    /* cost of moving MMX register */
850   {2, 2},                               /* cost of loading MMX registers
851                                            in SImode and DImode */
852   {2, 2},                               /* cost of storing MMX registers
853                                            in SImode and DImode */
854   12,                                   /* cost of moving SSE register */
855   {12, 12, 12},                         /* cost of loading SSE registers
856                                            in SImode, DImode and TImode */
857   {2, 2, 8},                            /* cost of storing SSE registers
858                                            in SImode, DImode and TImode */
859   10,                                   /* MMX or SSE register to integer */
860   8,                                    /* size of l1 cache.  */
861   256,                                  /* size of l2 cache.  */
862   64,                                   /* size of prefetch block */
863   6,                                    /* number of parallel prefetches */
864   2,                                    /* Branch cost */
865   COSTS_N_INSNS (5),                    /* cost of FADD and FSUB insns.  */
866   COSTS_N_INSNS (7),                    /* cost of FMUL instruction.  */
867   COSTS_N_INSNS (43),                   /* cost of FDIV instruction.  */
868   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
869   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
870   COSTS_N_INSNS (43),                   /* cost of FSQRT instruction.  */
871   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
872    DUMMY_STRINGOP_ALGS},
873   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
874    {-1, libcall}}},
875    DUMMY_STRINGOP_ALGS},
876   1,                                    /* scalar_stmt_cost.  */
877   1,                                    /* scalar load_cost.  */
878   1,                                    /* scalar_store_cost.  */
879   1,                                    /* vec_stmt_cost.  */
880   1,                                    /* vec_to_scalar_cost.  */
881   1,                                    /* scalar_to_vec_cost.  */
882   1,                                    /* vec_align_load_cost.  */
883   2,                                    /* vec_unalign_load_cost.  */
884   1,                                    /* vec_store_cost.  */
885   3,                                    /* cond_taken_branch_cost.  */
886   1,                                    /* cond_not_taken_branch_cost.  */
887 };
888
889 static const
890 struct processor_costs nocona_cost = {
891   COSTS_N_INSNS (1),                    /* cost of an add instruction */
892   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
893   COSTS_N_INSNS (1),                    /* variable shift costs */
894   COSTS_N_INSNS (1),                    /* constant shift costs */
895   {COSTS_N_INSNS (10),                  /* cost of starting multiply for QI */
896    COSTS_N_INSNS (10),                  /*                               HI */
897    COSTS_N_INSNS (10),                  /*                               SI */
898    COSTS_N_INSNS (10),                  /*                               DI */
899    COSTS_N_INSNS (10)},                 /*                               other */
900   0,                                    /* cost of multiply per each bit set */
901   {COSTS_N_INSNS (66),                  /* cost of a divide/mod for QI */
902    COSTS_N_INSNS (66),                  /*                          HI */
903    COSTS_N_INSNS (66),                  /*                          SI */
904    COSTS_N_INSNS (66),                  /*                          DI */
905    COSTS_N_INSNS (66)},                 /*                          other */
906   COSTS_N_INSNS (1),                    /* cost of movsx */
907   COSTS_N_INSNS (1),                    /* cost of movzx */
908   16,                                   /* "large" insn */
909   17,                                   /* MOVE_RATIO */
910   4,                                    /* cost for loading QImode using movzbl */
911   {4, 4, 4},                            /* cost of loading integer registers
912                                            in QImode, HImode and SImode.
913                                            Relative to reg-reg move (2).  */
914   {4, 4, 4},                            /* cost of storing integer registers */
915   3,                                    /* cost of reg,reg fld/fst */
916   {12, 12, 12},                         /* cost of loading fp registers
917                                            in SFmode, DFmode and XFmode */
918   {4, 4, 4},                            /* cost of storing fp registers
919                                            in SFmode, DFmode and XFmode */
920   6,                                    /* cost of moving MMX register */
921   {12, 12},                             /* cost of loading MMX registers
922                                            in SImode and DImode */
923   {12, 12},                             /* cost of storing MMX registers
924                                            in SImode and DImode */
925   6,                                    /* cost of moving SSE register */
926   {12, 12, 12},                         /* cost of loading SSE registers
927                                            in SImode, DImode and TImode */
928   {12, 12, 12},                         /* cost of storing SSE registers
929                                            in SImode, DImode and TImode */
930   8,                                    /* MMX or SSE register to integer */
931   8,                                    /* size of l1 cache.  */
932   1024,                                 /* size of l2 cache.  */
933   128,                                  /* size of prefetch block */
934   8,                                    /* number of parallel prefetches */
935   1,                                    /* Branch cost */
936   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
937   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
938   COSTS_N_INSNS (40),                   /* cost of FDIV instruction.  */
939   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
940   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
941   COSTS_N_INSNS (44),                   /* cost of FSQRT instruction.  */
942   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
943    {libcall, {{32, loop}, {20000, rep_prefix_8_byte},
944               {100000, unrolled_loop}, {-1, libcall}}}},
945   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
946    {-1, libcall}}},
947    {libcall, {{24, loop}, {64, unrolled_loop},
948               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
949   1,                                    /* scalar_stmt_cost.  */
950   1,                                    /* scalar load_cost.  */
951   1,                                    /* scalar_store_cost.  */
952   1,                                    /* vec_stmt_cost.  */
953   1,                                    /* vec_to_scalar_cost.  */
954   1,                                    /* scalar_to_vec_cost.  */
955   1,                                    /* vec_align_load_cost.  */
956   2,                                    /* vec_unalign_load_cost.  */
957   1,                                    /* vec_store_cost.  */
958   3,                                    /* cond_taken_branch_cost.  */
959   1,                                    /* cond_not_taken_branch_cost.  */
960 };
961
962 static const
963 struct processor_costs core2_cost = {
964   COSTS_N_INSNS (1),                    /* cost of an add instruction */
965   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
966   COSTS_N_INSNS (1),                    /* variable shift costs */
967   COSTS_N_INSNS (1),                    /* constant shift costs */
968   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
969    COSTS_N_INSNS (3),                   /*                               HI */
970    COSTS_N_INSNS (3),                   /*                               SI */
971    COSTS_N_INSNS (3),                   /*                               DI */
972    COSTS_N_INSNS (3)},                  /*                               other */
973   0,                                    /* cost of multiply per each bit set */
974   {COSTS_N_INSNS (22),                  /* cost of a divide/mod for QI */
975    COSTS_N_INSNS (22),                  /*                          HI */
976    COSTS_N_INSNS (22),                  /*                          SI */
977    COSTS_N_INSNS (22),                  /*                          DI */
978    COSTS_N_INSNS (22)},                 /*                          other */
979   COSTS_N_INSNS (1),                    /* cost of movsx */
980   COSTS_N_INSNS (1),                    /* cost of movzx */
981   8,                                    /* "large" insn */
982   16,                                   /* MOVE_RATIO */
983   2,                                    /* cost for loading QImode using movzbl */
984   {6, 6, 6},                            /* cost of loading integer registers
985                                            in QImode, HImode and SImode.
986                                            Relative to reg-reg move (2).  */
987   {4, 4, 4},                            /* cost of storing integer registers */
988   2,                                    /* cost of reg,reg fld/fst */
989   {6, 6, 6},                            /* cost of loading fp registers
990                                            in SFmode, DFmode and XFmode */
991   {4, 4, 4},                            /* cost of loading integer registers */
992   2,                                    /* cost of moving MMX register */
993   {6, 6},                               /* cost of loading MMX registers
994                                            in SImode and DImode */
995   {4, 4},                               /* cost of storing MMX registers
996                                            in SImode and DImode */
997   2,                                    /* cost of moving SSE register */
998   {6, 6, 6},                            /* cost of loading SSE registers
999                                            in SImode, DImode and TImode */
1000   {4, 4, 4},                            /* cost of storing SSE registers
1001                                            in SImode, DImode and TImode */
1002   2,                                    /* MMX or SSE register to integer */
1003   32,                                   /* size of l1 cache.  */
1004   2048,                                 /* size of l2 cache.  */
1005   128,                                  /* size of prefetch block */
1006   8,                                    /* number of parallel prefetches */
1007   3,                                    /* Branch cost */
1008   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
1009   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
1010   COSTS_N_INSNS (32),                   /* cost of FDIV instruction.  */
1011   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
1012   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
1013   COSTS_N_INSNS (58),                   /* cost of FSQRT instruction.  */
1014   {{libcall, {{11, loop}, {-1, rep_prefix_4_byte}}},
1015    {libcall, {{32, loop}, {64, rep_prefix_4_byte},
1016               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1017   {{libcall, {{8, loop}, {15, unrolled_loop},
1018               {2048, rep_prefix_4_byte}, {-1, libcall}}},
1019    {libcall, {{24, loop}, {32, unrolled_loop},
1020               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1021   1,                                    /* scalar_stmt_cost.  */
1022   1,                                    /* scalar load_cost.  */
1023   1,                                    /* scalar_store_cost.  */
1024   1,                                    /* vec_stmt_cost.  */
1025   1,                                    /* vec_to_scalar_cost.  */
1026   1,                                    /* scalar_to_vec_cost.  */
1027   1,                                    /* vec_align_load_cost.  */
1028   2,                                    /* vec_unalign_load_cost.  */
1029   1,                                    /* vec_store_cost.  */
1030   3,                                    /* cond_taken_branch_cost.  */
1031   1,                                    /* cond_not_taken_branch_cost.  */
1032 };
1033
1034 /* Generic64 should produce code tuned for Nocona and K8.  */
1035 static const
1036 struct processor_costs generic64_cost = {
1037   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1038   /* On all chips taken into consideration lea is 2 cycles and more.  With
1039      this cost however our current implementation of synth_mult results in
1040      use of unnecessary temporary registers causing regression on several
1041      SPECfp benchmarks.  */
1042   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1043   COSTS_N_INSNS (1),                    /* variable shift costs */
1044   COSTS_N_INSNS (1),                    /* constant shift costs */
1045   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1046    COSTS_N_INSNS (4),                   /*                               HI */
1047    COSTS_N_INSNS (3),                   /*                               SI */
1048    COSTS_N_INSNS (4),                   /*                               DI */
1049    COSTS_N_INSNS (2)},                  /*                               other */
1050   0,                                    /* cost of multiply per each bit set */
1051   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1052    COSTS_N_INSNS (26),                  /*                          HI */
1053    COSTS_N_INSNS (42),                  /*                          SI */
1054    COSTS_N_INSNS (74),                  /*                          DI */
1055    COSTS_N_INSNS (74)},                 /*                          other */
1056   COSTS_N_INSNS (1),                    /* cost of movsx */
1057   COSTS_N_INSNS (1),                    /* cost of movzx */
1058   8,                                    /* "large" insn */
1059   17,                                   /* MOVE_RATIO */
1060   4,                                    /* cost for loading QImode using movzbl */
1061   {4, 4, 4},                            /* cost of loading integer registers
1062                                            in QImode, HImode and SImode.
1063                                            Relative to reg-reg move (2).  */
1064   {4, 4, 4},                            /* cost of storing integer registers */
1065   4,                                    /* cost of reg,reg fld/fst */
1066   {12, 12, 12},                         /* cost of loading fp registers
1067                                            in SFmode, DFmode and XFmode */
1068   {6, 6, 8},                            /* cost of storing fp registers
1069                                            in SFmode, DFmode and XFmode */
1070   2,                                    /* cost of moving MMX register */
1071   {8, 8},                               /* cost of loading MMX registers
1072                                            in SImode and DImode */
1073   {8, 8},                               /* cost of storing MMX registers
1074                                            in SImode and DImode */
1075   2,                                    /* cost of moving SSE register */
1076   {8, 8, 8},                            /* cost of loading SSE registers
1077                                            in SImode, DImode and TImode */
1078   {8, 8, 8},                            /* cost of storing SSE registers
1079                                            in SImode, DImode and TImode */
1080   5,                                    /* MMX or SSE register to integer */
1081   32,                                   /* size of l1 cache.  */
1082   512,                                  /* size of l2 cache.  */
1083   64,                                   /* size of prefetch block */
1084   6,                                    /* number of parallel prefetches */
1085   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this value
1086      is increased to perhaps more appropriate value of 5.  */
1087   3,                                    /* Branch cost */
1088   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1089   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1090   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1091   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1092   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1093   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1094   {DUMMY_STRINGOP_ALGS,
1095    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1096   {DUMMY_STRINGOP_ALGS,
1097    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1098   1,                                    /* scalar_stmt_cost.  */
1099   1,                                    /* scalar load_cost.  */
1100   1,                                    /* scalar_store_cost.  */
1101   1,                                    /* vec_stmt_cost.  */
1102   1,                                    /* vec_to_scalar_cost.  */
1103   1,                                    /* scalar_to_vec_cost.  */
1104   1,                                    /* vec_align_load_cost.  */
1105   2,                                    /* vec_unalign_load_cost.  */
1106   1,                                    /* vec_store_cost.  */
1107   3,                                    /* cond_taken_branch_cost.  */
1108   1,                                    /* cond_not_taken_branch_cost.  */
1109 };
1110
1111 /* Generic32 should produce code tuned for Athlon, PPro, Pentium4, Nocona and K8.  */
1112 static const
1113 struct processor_costs generic32_cost = {
1114   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1115   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1116   COSTS_N_INSNS (1),                    /* variable shift costs */
1117   COSTS_N_INSNS (1),                    /* constant shift costs */
1118   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1119    COSTS_N_INSNS (4),                   /*                               HI */
1120    COSTS_N_INSNS (3),                   /*                               SI */
1121    COSTS_N_INSNS (4),                   /*                               DI */
1122    COSTS_N_INSNS (2)},                  /*                               other */
1123   0,                                    /* cost of multiply per each bit set */
1124   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1125    COSTS_N_INSNS (26),                  /*                          HI */
1126    COSTS_N_INSNS (42),                  /*                          SI */
1127    COSTS_N_INSNS (74),                  /*                          DI */
1128    COSTS_N_INSNS (74)},                 /*                          other */
1129   COSTS_N_INSNS (1),                    /* cost of movsx */
1130   COSTS_N_INSNS (1),                    /* cost of movzx */
1131   8,                                    /* "large" insn */
1132   17,                                   /* MOVE_RATIO */
1133   4,                                    /* cost for loading QImode using movzbl */
1134   {4, 4, 4},                            /* cost of loading integer registers
1135                                            in QImode, HImode and SImode.
1136                                            Relative to reg-reg move (2).  */
1137   {4, 4, 4},                            /* cost of storing integer registers */
1138   4,                                    /* cost of reg,reg fld/fst */
1139   {12, 12, 12},                         /* cost of loading fp registers
1140                                            in SFmode, DFmode and XFmode */
1141   {6, 6, 8},                            /* cost of storing fp registers
1142                                            in SFmode, DFmode and XFmode */
1143   2,                                    /* cost of moving MMX register */
1144   {8, 8},                               /* cost of loading MMX registers
1145                                            in SImode and DImode */
1146   {8, 8},                               /* cost of storing MMX registers
1147                                            in SImode and DImode */
1148   2,                                    /* cost of moving SSE register */
1149   {8, 8, 8},                            /* cost of loading SSE registers
1150                                            in SImode, DImode and TImode */
1151   {8, 8, 8},                            /* cost of storing SSE registers
1152                                            in SImode, DImode and TImode */
1153   5,                                    /* MMX or SSE register to integer */
1154   32,                                   /* size of l1 cache.  */
1155   256,                                  /* size of l2 cache.  */
1156   64,                                   /* size of prefetch block */
1157   6,                                    /* number of parallel prefetches */
1158   3,                                    /* Branch cost */
1159   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1160   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1161   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1162   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1163   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1164   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1165   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1166    DUMMY_STRINGOP_ALGS},
1167   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1168    DUMMY_STRINGOP_ALGS},
1169   1,                                    /* scalar_stmt_cost.  */
1170   1,                                    /* scalar load_cost.  */
1171   1,                                    /* scalar_store_cost.  */
1172   1,                                    /* vec_stmt_cost.  */
1173   1,                                    /* vec_to_scalar_cost.  */
1174   1,                                    /* scalar_to_vec_cost.  */
1175   1,                                    /* vec_align_load_cost.  */
1176   2,                                    /* vec_unalign_load_cost.  */
1177   1,                                    /* vec_store_cost.  */
1178   3,                                    /* cond_taken_branch_cost.  */
1179   1,                                    /* cond_not_taken_branch_cost.  */
1180 };
1181
1182 const struct processor_costs *ix86_cost = &pentium_cost;
1183
1184 /* Processor feature/optimization bitmasks.  */
1185 #define m_386 (1<<PROCESSOR_I386)
1186 #define m_486 (1<<PROCESSOR_I486)
1187 #define m_PENT (1<<PROCESSOR_PENTIUM)
1188 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
1189 #define m_PENT4  (1<<PROCESSOR_PENTIUM4)
1190 #define m_NOCONA  (1<<PROCESSOR_NOCONA)
1191 #define m_CORE2  (1<<PROCESSOR_CORE2)
1192
1193 #define m_GEODE  (1<<PROCESSOR_GEODE)
1194 #define m_K6  (1<<PROCESSOR_K6)
1195 #define m_K6_GEODE  (m_K6 | m_GEODE)
1196 #define m_K8  (1<<PROCESSOR_K8)
1197 #define m_ATHLON  (1<<PROCESSOR_ATHLON)
1198 #define m_ATHLON_K8  (m_K8 | m_ATHLON)
1199 #define m_AMDFAM10  (1<<PROCESSOR_AMDFAM10)
1200 #define m_AMD_MULTIPLE  (m_K8 | m_ATHLON | m_AMDFAM10)
1201
1202 #define m_GENERIC32 (1<<PROCESSOR_GENERIC32)
1203 #define m_GENERIC64 (1<<PROCESSOR_GENERIC64)
1204
1205 /* Generic instruction choice should be common subset of supported CPUs
1206    (PPro/PENT4/NOCONA/CORE2/Athlon/K8).  */
1207 #define m_GENERIC (m_GENERIC32 | m_GENERIC64)
1208
1209 /* Feature tests against the various tunings.  */
1210 unsigned int ix86_tune_features[X86_TUNE_LAST] = {
1211   /* X86_TUNE_USE_LEAVE: Leave does not affect Nocona SPEC2000 results
1212      negatively, so enabling for Generic64 seems like good code size
1213      tradeoff.  We can't enable it for 32bit generic because it does not
1214      work well with PPro base chips.  */
1215   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_CORE2 | m_GENERIC64,
1216
1217   /* X86_TUNE_PUSH_MEMORY */
1218   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4
1219   | m_NOCONA | m_CORE2 | m_GENERIC,
1220
1221   /* X86_TUNE_ZERO_EXTEND_WITH_AND */
1222   m_486 | m_PENT,
1223
1224   /* X86_TUNE_USE_BIT_TEST */
1225   m_386,
1226
1227   /* X86_TUNE_UNROLL_STRLEN */
1228   m_486 | m_PENT | m_PPRO | m_AMD_MULTIPLE | m_K6 | m_CORE2 | m_GENERIC,
1229
1230   /* X86_TUNE_DEEP_BRANCH_PREDICTION */
1231   m_PPRO | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4 | m_GENERIC,
1232
1233   /* X86_TUNE_BRANCH_PREDICTION_HINTS: Branch hints were put in P4 based
1234      on simulation result. But after P4 was made, no performance benefit
1235      was observed with branch hints.  It also increases the code size.
1236      As a result, icc never generates branch hints.  */
1237   0,
1238
1239   /* X86_TUNE_DOUBLE_WITH_ADD */
1240   ~m_386,
1241
1242   /* X86_TUNE_USE_SAHF */
1243   m_PPRO | m_K6_GEODE | m_K8 | m_AMDFAM10 | m_PENT4
1244   | m_NOCONA | m_CORE2 | m_GENERIC,
1245
1246   /* X86_TUNE_MOVX: Enable to zero extend integer registers to avoid
1247      partial dependencies.  */
1248   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA
1249   | m_CORE2 | m_GENERIC | m_GEODE /* m_386 | m_K6 */,
1250
1251   /* X86_TUNE_PARTIAL_REG_STALL: We probably ought to watch for partial
1252      register stalls on Generic32 compilation setting as well.  However
1253      in current implementation the partial register stalls are not eliminated
1254      very well - they can be introduced via subregs synthesized by combine
1255      and can happen in caller/callee saving sequences.  Because this option
1256      pays back little on PPro based chips and is in conflict with partial reg
1257      dependencies used by Athlon/P4 based chips, it is better to leave it off
1258      for generic32 for now.  */
1259   m_PPRO,
1260
1261   /* X86_TUNE_PARTIAL_FLAG_REG_STALL */
1262   m_CORE2 | m_GENERIC,
1263
1264   /* X86_TUNE_USE_HIMODE_FIOP */
1265   m_386 | m_486 | m_K6_GEODE,
1266
1267   /* X86_TUNE_USE_SIMODE_FIOP */
1268   ~(m_PPRO | m_AMD_MULTIPLE | m_PENT | m_CORE2 | m_GENERIC),
1269
1270   /* X86_TUNE_USE_MOV0 */
1271   m_K6,
1272
1273   /* X86_TUNE_USE_CLTD */
1274   ~(m_PENT | m_K6 | m_CORE2 | m_GENERIC),
1275
1276   /* X86_TUNE_USE_XCHGB: Use xchgb %rh,%rl instead of rolw/rorw $8,rx.  */
1277   m_PENT4,
1278
1279   /* X86_TUNE_SPLIT_LONG_MOVES */
1280   m_PPRO,
1281
1282   /* X86_TUNE_READ_MODIFY_WRITE */
1283   ~m_PENT,
1284
1285   /* X86_TUNE_READ_MODIFY */
1286   ~(m_PENT | m_PPRO),
1287
1288   /* X86_TUNE_PROMOTE_QIMODE */
1289   m_K6_GEODE | m_PENT | m_386 | m_486 | m_AMD_MULTIPLE | m_CORE2
1290   | m_GENERIC /* | m_PENT4 ? */,
1291
1292   /* X86_TUNE_FAST_PREFIX */
1293   ~(m_PENT | m_486 | m_386),
1294
1295   /* X86_TUNE_SINGLE_STRINGOP */
1296   m_386 | m_PENT4 | m_NOCONA,
1297
1298   /* X86_TUNE_QIMODE_MATH */
1299   ~0,
1300
1301   /* X86_TUNE_HIMODE_MATH: On PPro this flag is meant to avoid partial
1302      register stalls.  Just like X86_TUNE_PARTIAL_REG_STALL this option
1303      might be considered for Generic32 if our scheme for avoiding partial
1304      stalls was more effective.  */
1305   ~m_PPRO,
1306
1307   /* X86_TUNE_PROMOTE_QI_REGS */
1308   0,
1309
1310   /* X86_TUNE_PROMOTE_HI_REGS */
1311   m_PPRO,
1312
1313   /* X86_TUNE_ADD_ESP_4: Enable if add/sub is preferred over 1/2 push/pop.  */
1314   m_AMD_MULTIPLE | m_K6_GEODE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1315
1316   /* X86_TUNE_ADD_ESP_8 */
1317   m_AMD_MULTIPLE | m_PPRO | m_K6_GEODE | m_386
1318   | m_486 | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1319
1320   /* X86_TUNE_SUB_ESP_4 */
1321   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1322
1323   /* X86_TUNE_SUB_ESP_8 */
1324   m_AMD_MULTIPLE | m_PPRO | m_386 | m_486
1325   | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1326
1327   /* X86_TUNE_INTEGER_DFMODE_MOVES: Enable if integer moves are preferred
1328      for DFmode copies */
1329   ~(m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2
1330     | m_GENERIC | m_GEODE),
1331
1332   /* X86_TUNE_PARTIAL_REG_DEPENDENCY */
1333   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1334
1335   /* X86_TUNE_SSE_PARTIAL_REG_DEPENDENCY: In the Generic model we have a
1336      conflict here in between PPro/Pentium4 based chips that thread 128bit
1337      SSE registers as single units versus K8 based chips that divide SSE
1338      registers to two 64bit halves.  This knob promotes all store destinations
1339      to be 128bit to allow register renaming on 128bit SSE units, but usually
1340      results in one extra microop on 64bit SSE units.  Experimental results
1341      shows that disabling this option on P4 brings over 20% SPECfp regression,
1342      while enabling it on K8 brings roughly 2.4% regression that can be partly
1343      masked by careful scheduling of moves.  */
1344   m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC | m_AMDFAM10,
1345
1346   /* X86_TUNE_SSE_UNALIGNED_MOVE_OPTIMAL */
1347   m_AMDFAM10,
1348
1349   /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
1350      are resolved on SSE register parts instead of whole registers, so we may
1351      maintain just lower part of scalar values in proper format leaving the
1352      upper part undefined.  */
1353   m_ATHLON_K8,
1354
1355   /* X86_TUNE_SSE_TYPELESS_STORES */
1356   m_AMD_MULTIPLE,
1357
1358   /* X86_TUNE_SSE_LOAD0_BY_PXOR */
1359   m_PPRO | m_PENT4 | m_NOCONA,
1360
1361   /* X86_TUNE_MEMORY_MISMATCH_STALL */
1362   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1363
1364   /* X86_TUNE_PROLOGUE_USING_MOVE */
1365   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1366
1367   /* X86_TUNE_EPILOGUE_USING_MOVE */
1368   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1369
1370   /* X86_TUNE_SHIFT1 */
1371   ~m_486,
1372
1373   /* X86_TUNE_USE_FFREEP */
1374   m_AMD_MULTIPLE,
1375
1376   /* X86_TUNE_INTER_UNIT_MOVES */
1377   ~(m_AMD_MULTIPLE | m_GENERIC),
1378
1379   /* X86_TUNE_INTER_UNIT_CONVERSIONS */
1380   ~(m_AMDFAM10),
1381
1382   /* X86_TUNE_FOUR_JUMP_LIMIT: Some CPU cores are not able to predict more
1383      than 4 branch instructions in the 16 byte window.  */
1384   m_PPRO | m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1385
1386   /* X86_TUNE_SCHEDULE */
1387   m_PPRO | m_AMD_MULTIPLE | m_K6_GEODE | m_PENT | m_CORE2 | m_GENERIC,
1388
1389   /* X86_TUNE_USE_BT */
1390   m_AMD_MULTIPLE,
1391
1392   /* X86_TUNE_USE_INCDEC */
1393   ~(m_PENT4 | m_NOCONA | m_GENERIC),
1394
1395   /* X86_TUNE_PAD_RETURNS */
1396   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1397
1398   /* X86_TUNE_EXT_80387_CONSTANTS */
1399   m_K6_GEODE | m_ATHLON_K8 | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC,
1400
1401   /* X86_TUNE_SHORTEN_X87_SSE */
1402   ~m_K8,
1403
1404   /* X86_TUNE_AVOID_VECTOR_DECODE */
1405   m_K8 | m_GENERIC64,
1406
1407   /* X86_TUNE_PROMOTE_HIMODE_IMUL: Modern CPUs have same latency for HImode
1408      and SImode multiply, but 386 and 486 do HImode multiply faster.  */
1409   ~(m_386 | m_486),
1410
1411   /* X86_TUNE_SLOW_IMUL_IMM32_MEM: Imul of 32-bit constant and memory is
1412      vector path on AMD machines.  */
1413   m_K8 | m_GENERIC64 | m_AMDFAM10,
1414
1415   /* X86_TUNE_SLOW_IMUL_IMM8: Imul of 8-bit constant is vector path on AMD
1416      machines.  */
1417   m_K8 | m_GENERIC64 | m_AMDFAM10,
1418
1419   /* X86_TUNE_MOVE_M1_VIA_OR: On pentiums, it is faster to load -1 via OR
1420      than a MOV.  */
1421   m_PENT,
1422
1423   /* X86_TUNE_NOT_UNPAIRABLE: NOT is not pairable on Pentium, while XOR is,
1424      but one byte longer.  */
1425   m_PENT,
1426
1427   /* X86_TUNE_NOT_VECTORMODE: On AMD K6, NOT is vector decoded with memory
1428      operand that cannot be represented using a modRM byte.  The XOR
1429      replacement is long decoded, so this split helps here as well.  */
1430   m_K6,
1431
1432   /* X86_TUNE_USE_VECTOR_CONVERTS: Preffer vector packed SSE conversion
1433      from integer to FP. */
1434   m_AMDFAM10,
1435 };
1436
1437 /* Feature tests against the various architecture variations.  */
1438 unsigned int ix86_arch_features[X86_ARCH_LAST] = {
1439   /* X86_ARCH_CMOVE: Conditional move was added for pentiumpro.  */
1440   ~(m_386 | m_486 | m_PENT | m_K6),
1441
1442   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
1443   ~m_386,
1444
1445   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
1446   ~(m_386 | m_486),
1447
1448   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
1449   ~m_386,
1450
1451   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
1452   ~m_386,
1453 };
1454
1455 static const unsigned int x86_accumulate_outgoing_args
1456   = m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC;
1457
1458 static const unsigned int x86_arch_always_fancy_math_387
1459   = m_PENT | m_PPRO | m_AMD_MULTIPLE | m_PENT4
1460     | m_NOCONA | m_CORE2 | m_GENERIC;
1461
1462 static enum stringop_alg stringop_alg = no_stringop;
1463
1464 /* In case the average insn count for single function invocation is
1465    lower than this constant, emit fast (but longer) prologue and
1466    epilogue code.  */
1467 #define FAST_PROLOGUE_INSN_COUNT 20
1468
1469 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
1470 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
1471 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
1472 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
1473
1474 /* Array of the smallest class containing reg number REGNO, indexed by
1475    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
1476
1477 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
1478 {
1479   /* ax, dx, cx, bx */
1480   AREG, DREG, CREG, BREG,
1481   /* si, di, bp, sp */
1482   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
1483   /* FP registers */
1484   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
1485   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
1486   /* arg pointer */
1487   NON_Q_REGS,
1488   /* flags, fpsr, fpcr, frame */
1489   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
1490   /* SSE registers */
1491   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1492   SSE_REGS, SSE_REGS,
1493   /* MMX registers */
1494   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
1495   MMX_REGS, MMX_REGS,
1496   /* REX registers */
1497   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1498   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1499   /* SSE REX registers */
1500   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1501   SSE_REGS, SSE_REGS,
1502 };
1503
1504 /* The "default" register map used in 32bit mode.  */
1505
1506 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
1507 {
1508   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
1509   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
1510   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1511   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
1512   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
1513   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1514   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1515 };
1516
1517 static int const x86_64_int_parameter_registers[6] =
1518 {
1519   5 /*RDI*/, 4 /*RSI*/, 1 /*RDX*/, 2 /*RCX*/,
1520   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1521 };
1522
1523 static int const x86_64_ms_abi_int_parameter_registers[4] =
1524 {
1525   2 /*RCX*/, 1 /*RDX*/,
1526   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1527 };
1528
1529 static int const x86_64_int_return_registers[4] =
1530 {
1531   0 /*RAX*/, 1 /*RDX*/, 5 /*RDI*/, 4 /*RSI*/
1532 };
1533
1534 /* The "default" register map used in 64bit mode.  */
1535 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
1536 {
1537   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
1538   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
1539   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1540   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
1541   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
1542   8,9,10,11,12,13,14,15,                /* extended integer registers */
1543   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
1544 };
1545
1546 /* Define the register numbers to be used in Dwarf debugging information.
1547    The SVR4 reference port C compiler uses the following register numbers
1548    in its Dwarf output code:
1549         0 for %eax (gcc regno = 0)
1550         1 for %ecx (gcc regno = 2)
1551         2 for %edx (gcc regno = 1)
1552         3 for %ebx (gcc regno = 3)
1553         4 for %esp (gcc regno = 7)
1554         5 for %ebp (gcc regno = 6)
1555         6 for %esi (gcc regno = 4)
1556         7 for %edi (gcc regno = 5)
1557    The following three DWARF register numbers are never generated by
1558    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
1559    believes these numbers have these meanings.
1560         8  for %eip    (no gcc equivalent)
1561         9  for %eflags (gcc regno = 17)
1562         10 for %trapno (no gcc equivalent)
1563    It is not at all clear how we should number the FP stack registers
1564    for the x86 architecture.  If the version of SDB on x86/svr4 were
1565    a bit less brain dead with respect to floating-point then we would
1566    have a precedent to follow with respect to DWARF register numbers
1567    for x86 FP registers, but the SDB on x86/svr4 is so completely
1568    broken with respect to FP registers that it is hardly worth thinking
1569    of it as something to strive for compatibility with.
1570    The version of x86/svr4 SDB I have at the moment does (partially)
1571    seem to believe that DWARF register number 11 is associated with
1572    the x86 register %st(0), but that's about all.  Higher DWARF
1573    register numbers don't seem to be associated with anything in
1574    particular, and even for DWARF regno 11, SDB only seems to under-
1575    stand that it should say that a variable lives in %st(0) (when
1576    asked via an `=' command) if we said it was in DWARF regno 11,
1577    but SDB still prints garbage when asked for the value of the
1578    variable in question (via a `/' command).
1579    (Also note that the labels SDB prints for various FP stack regs
1580    when doing an `x' command are all wrong.)
1581    Note that these problems generally don't affect the native SVR4
1582    C compiler because it doesn't allow the use of -O with -g and
1583    because when it is *not* optimizing, it allocates a memory
1584    location for each floating-point variable, and the memory
1585    location is what gets described in the DWARF AT_location
1586    attribute for the variable in question.
1587    Regardless of the severe mental illness of the x86/svr4 SDB, we
1588    do something sensible here and we use the following DWARF
1589    register numbers.  Note that these are all stack-top-relative
1590    numbers.
1591         11 for %st(0) (gcc regno = 8)
1592         12 for %st(1) (gcc regno = 9)
1593         13 for %st(2) (gcc regno = 10)
1594         14 for %st(3) (gcc regno = 11)
1595         15 for %st(4) (gcc regno = 12)
1596         16 for %st(5) (gcc regno = 13)
1597         17 for %st(6) (gcc regno = 14)
1598         18 for %st(7) (gcc regno = 15)
1599 */
1600 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
1601 {
1602   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
1603   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
1604   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
1605   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
1606   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
1607   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1608   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1609 };
1610
1611 /* Test and compare insns in i386.md store the information needed to
1612    generate branch and scc insns here.  */
1613
1614 rtx ix86_compare_op0 = NULL_RTX;
1615 rtx ix86_compare_op1 = NULL_RTX;
1616 rtx ix86_compare_emitted = NULL_RTX;
1617
1618 /* Size of the register save area.  */
1619 #define X86_64_VARARGS_SIZE (REGPARM_MAX * UNITS_PER_WORD + SSE_REGPARM_MAX * 16)
1620
1621 /* Define the structure for the machine field in struct function.  */
1622
1623 struct stack_local_entry GTY(())
1624 {
1625   unsigned short mode;
1626   unsigned short n;
1627   rtx rtl;
1628   struct stack_local_entry *next;
1629 };
1630
1631 /* Structure describing stack frame layout.
1632    Stack grows downward:
1633
1634    [arguments]
1635                                               <- ARG_POINTER
1636    saved pc
1637
1638    saved frame pointer if frame_pointer_needed
1639                                               <- HARD_FRAME_POINTER
1640    [saved regs]
1641
1642    [padding1]          \
1643                         )
1644    [va_arg registers]  (
1645                         > to_allocate         <- FRAME_POINTER
1646    [frame]             (
1647                         )
1648    [padding2]          /
1649   */
1650 struct ix86_frame
1651 {
1652   int nregs;
1653   int padding1;
1654   int va_arg_size;
1655   HOST_WIDE_INT frame;
1656   int padding2;
1657   int outgoing_arguments_size;
1658   int red_zone_size;
1659
1660   HOST_WIDE_INT to_allocate;
1661   /* The offsets relative to ARG_POINTER.  */
1662   HOST_WIDE_INT frame_pointer_offset;
1663   HOST_WIDE_INT hard_frame_pointer_offset;
1664   HOST_WIDE_INT stack_pointer_offset;
1665
1666   /* When save_regs_using_mov is set, emit prologue using
1667      move instead of push instructions.  */
1668   bool save_regs_using_mov;
1669 };
1670
1671 /* Code model option.  */
1672 enum cmodel ix86_cmodel;
1673 /* Asm dialect.  */
1674 enum asm_dialect ix86_asm_dialect = ASM_ATT;
1675 /* TLS dialects.  */
1676 enum tls_dialect ix86_tls_dialect = TLS_DIALECT_GNU;
1677
1678 /* Which unit we are generating floating point math for.  */
1679 enum fpmath_unit ix86_fpmath;
1680
1681 /* Which cpu are we scheduling for.  */
1682 enum processor_type ix86_tune;
1683
1684 /* Which instruction set architecture to use.  */
1685 enum processor_type ix86_arch;
1686
1687 /* true if sse prefetch instruction is not NOOP.  */
1688 int x86_prefetch_sse;
1689
1690 /* ix86_regparm_string as a number */
1691 static int ix86_regparm;
1692
1693 /* -mstackrealign option */
1694 extern int ix86_force_align_arg_pointer;
1695 static const char ix86_force_align_arg_pointer_string[] = "force_align_arg_pointer";
1696
1697 /* Preferred alignment for stack boundary in bits.  */
1698 unsigned int ix86_preferred_stack_boundary;
1699
1700 /* Values 1-5: see jump.c */
1701 int ix86_branch_cost;
1702
1703 /* Variables which are this size or smaller are put in the data/bss
1704    or ldata/lbss sections.  */
1705
1706 int ix86_section_threshold = 65536;
1707
1708 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
1709 char internal_label_prefix[16];
1710 int internal_label_prefix_len;
1711
1712 /* Fence to use after loop using movnt.  */
1713 tree x86_mfence;
1714
1715 /* Register class used for passing given 64bit part of the argument.
1716    These represent classes as documented by the PS ABI, with the exception
1717    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
1718    use SF or DFmode move instead of DImode to avoid reformatting penalties.
1719
1720    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
1721    whenever possible (upper half does contain padding).  */
1722 enum x86_64_reg_class
1723   {
1724     X86_64_NO_CLASS,
1725     X86_64_INTEGER_CLASS,
1726     X86_64_INTEGERSI_CLASS,
1727     X86_64_SSE_CLASS,
1728     X86_64_SSESF_CLASS,
1729     X86_64_SSEDF_CLASS,
1730     X86_64_SSEUP_CLASS,
1731     X86_64_X87_CLASS,
1732     X86_64_X87UP_CLASS,
1733     X86_64_COMPLEX_X87_CLASS,
1734     X86_64_MEMORY_CLASS
1735   };
1736 static const char * const x86_64_reg_class_name[] =
1737 {
1738   "no", "integer", "integerSI", "sse", "sseSF", "sseDF",
1739   "sseup", "x87", "x87up", "cplx87", "no"
1740 };
1741
1742 #define MAX_CLASSES 4
1743
1744 /* Table of constants used by fldpi, fldln2, etc....  */
1745 static REAL_VALUE_TYPE ext_80387_constants_table [5];
1746 static bool ext_80387_constants_init = 0;
1747
1748 \f
1749 static struct machine_function * ix86_init_machine_status (void);
1750 static rtx ix86_function_value (const_tree, const_tree, bool);
1751 static int ix86_function_regparm (const_tree, const_tree);
1752 static void ix86_compute_frame_layout (struct ix86_frame *);
1753 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
1754                                                  rtx, rtx, int);
1755
1756 \f
1757 /* The svr4 ABI for the i386 says that records and unions are returned
1758    in memory.  */
1759 #ifndef DEFAULT_PCC_STRUCT_RETURN
1760 #define DEFAULT_PCC_STRUCT_RETURN 1
1761 #endif
1762
1763 /* Bit flags that specify the ISA we are compiling for.  */
1764 int ix86_isa_flags = TARGET_64BIT_DEFAULT | TARGET_SUBTARGET_ISA_DEFAULT;
1765
1766 /* A mask of ix86_isa_flags that includes bit X if X
1767    was set or cleared on the command line.  */
1768 static int ix86_isa_flags_explicit;
1769
1770 /* Define a set of ISAs which aren't available for a given ISA. MMX
1771    and SSE ISAs are handled separately.  */
1772
1773 #define OPTION_MASK_ISA_MMX_UNSET \
1774   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_UNSET)
1775 #define OPTION_MASK_ISA_3DNOW_UNSET OPTION_MASK_ISA_3DNOW_A
1776
1777 #define OPTION_MASK_ISA_SSE_UNSET \
1778   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE2_UNSET)
1779 #define OPTION_MASK_ISA_SSE2_UNSET \
1780   (OPTION_MASK_ISA_SSE3 | OPTION_MASK_ISA_SSE3_UNSET)
1781 #define OPTION_MASK_ISA_SSE3_UNSET \
1782   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSSE3_UNSET)
1783 #define OPTION_MASK_ISA_SSSE3_UNSET \
1784   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_1_UNSET)
1785 #define OPTION_MASK_ISA_SSE4_1_UNSET \
1786   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_SSE4_2_UNSET)
1787 #define OPTION_MASK_ISA_SSE4_2_UNSET OPTION_MASK_ISA_SSE4A
1788
1789 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
1790    as -msse4.1 -msse4.2.  -mno-sse4 should the same as -mno-sse4.1. */
1791 #define OPTION_MASK_ISA_SSE4 \
1792   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_2)
1793 #define OPTION_MASK_ISA_SSE4_UNSET OPTION_MASK_ISA_SSE4_1_UNSET
1794
1795 #define OPTION_MASK_ISA_SSE4A_UNSET OPTION_MASK_ISA_SSE4
1796
1797 #define OPTION_MASK_ISA_SSE5_UNSET \
1798   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_UNSET)
1799
1800 /* Vectorization library interface and handlers.  */
1801 tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL;
1802 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
1803
1804 /* Implement TARGET_HANDLE_OPTION.  */
1805
1806 static bool
1807 ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value)
1808 {
1809   switch (code)
1810     {
1811     case OPT_mmmx:
1812       ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX;
1813       if (!value)
1814         {
1815           ix86_isa_flags &= ~OPTION_MASK_ISA_MMX_UNSET;
1816           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_UNSET;
1817         }
1818       return true;
1819
1820     case OPT_m3dnow:
1821       ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW;
1822       if (!value)
1823         {
1824           ix86_isa_flags &= ~OPTION_MASK_ISA_3DNOW_UNSET;
1825           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_UNSET;
1826         }
1827       return true;
1828
1829     case OPT_m3dnowa:
1830       return false;
1831
1832     case OPT_msse:
1833       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE;
1834       if (!value)
1835         {
1836           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE_UNSET;
1837           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_UNSET;
1838         }
1839       return true;
1840
1841     case OPT_msse2:
1842       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2;
1843       if (!value)
1844         {
1845           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE2_UNSET;
1846           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_UNSET;
1847         }
1848       return true;
1849
1850     case OPT_msse3:
1851       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3;
1852       if (!value)
1853         {
1854           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE3_UNSET;
1855           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_UNSET;
1856         }
1857       return true;
1858
1859     case OPT_mssse3:
1860       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3;
1861       if (!value)
1862         {
1863           ix86_isa_flags &= ~OPTION_MASK_ISA_SSSE3_UNSET;
1864           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_UNSET;
1865         }
1866       return true;
1867
1868     case OPT_msse4_1:
1869       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1;
1870       if (!value)
1871         {
1872           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_1_UNSET;
1873           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_UNSET;
1874         }
1875       return true;
1876
1877     case OPT_msse4_2:
1878       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2;
1879       if (!value)
1880         {
1881           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_2_UNSET;
1882           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_UNSET;
1883         }
1884       return true;
1885
1886     case OPT_msse4:
1887       ix86_isa_flags |= OPTION_MASK_ISA_SSE4;
1888       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4;
1889       return true;
1890
1891     case OPT_mno_sse4:
1892       ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
1893       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
1894       return true;
1895
1896     case OPT_msse4a:
1897       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A;
1898       if (!value)
1899         {
1900           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4A_UNSET;
1901           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_UNSET;
1902         }
1903       return true;
1904
1905     case OPT_msse5:
1906       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5;
1907       if (!value)
1908         {
1909           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE5_UNSET;
1910           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_UNSET;
1911         }
1912       return true;
1913
1914     default:
1915       return true;
1916     }
1917 }
1918
1919 /* Sometimes certain combinations of command options do not make
1920    sense on a particular target machine.  You can define a macro
1921    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
1922    defined, is executed once just after all the command options have
1923    been parsed.
1924
1925    Don't use this macro to turn on various extra optimizations for
1926    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
1927
1928 void
1929 override_options (void)
1930 {
1931   int i;
1932   int ix86_tune_defaulted = 0;
1933   int ix86_arch_specified = 0;
1934   unsigned int ix86_arch_mask, ix86_tune_mask;
1935
1936   /* Comes from final.c -- no real reason to change it.  */
1937 #define MAX_CODE_ALIGN 16
1938
1939   static struct ptt
1940     {
1941       const struct processor_costs *cost;       /* Processor costs */
1942       const int align_loop;                     /* Default alignments.  */
1943       const int align_loop_max_skip;
1944       const int align_jump;
1945       const int align_jump_max_skip;
1946       const int align_func;
1947     }
1948   const processor_target_table[PROCESSOR_max] =
1949     {
1950       {&i386_cost, 4, 3, 4, 3, 4},
1951       {&i486_cost, 16, 15, 16, 15, 16},
1952       {&pentium_cost, 16, 7, 16, 7, 16},
1953       {&pentiumpro_cost, 16, 15, 16, 10, 16},
1954       {&geode_cost, 0, 0, 0, 0, 0},
1955       {&k6_cost, 32, 7, 32, 7, 32},
1956       {&athlon_cost, 16, 7, 16, 7, 16},
1957       {&pentium4_cost, 0, 0, 0, 0, 0},
1958       {&k8_cost, 16, 7, 16, 7, 16},
1959       {&nocona_cost, 0, 0, 0, 0, 0},
1960       {&core2_cost, 16, 10, 16, 10, 16},
1961       {&generic32_cost, 16, 7, 16, 7, 16},
1962       {&generic64_cost, 16, 10, 16, 10, 16},
1963       {&amdfam10_cost, 32, 24, 32, 7, 32}
1964     };
1965
1966   static const char * const cpu_names[] = TARGET_CPU_DEFAULT_NAMES;
1967   enum pta_flags
1968     {
1969       PTA_SSE = 1 << 0,
1970       PTA_SSE2 = 1 << 1,
1971       PTA_SSE3 = 1 << 2,
1972       PTA_MMX = 1 << 3,
1973       PTA_PREFETCH_SSE = 1 << 4,
1974       PTA_3DNOW = 1 << 5,
1975       PTA_3DNOW_A = 1 << 6,
1976       PTA_64BIT = 1 << 7,
1977       PTA_SSSE3 = 1 << 8,
1978       PTA_CX16 = 1 << 9,
1979       PTA_POPCNT = 1 << 10,
1980       PTA_ABM = 1 << 11,
1981       PTA_SSE4A = 1 << 12,
1982       PTA_NO_SAHF = 1 << 13,
1983       PTA_SSE4_1 = 1 << 14,
1984       PTA_SSE4_2 = 1 << 15,
1985       PTA_SSE5 = 1 << 16
1986     };
1987
1988   static struct pta
1989     {
1990       const char *const name;           /* processor name or nickname.  */
1991       const enum processor_type processor;
1992       const unsigned /*enum pta_flags*/ flags;
1993     }
1994   const processor_alias_table[] =
1995     {
1996       {"i386", PROCESSOR_I386, 0},
1997       {"i486", PROCESSOR_I486, 0},
1998       {"i586", PROCESSOR_PENTIUM, 0},
1999       {"pentium", PROCESSOR_PENTIUM, 0},
2000       {"pentium-mmx", PROCESSOR_PENTIUM, PTA_MMX},
2001       {"winchip-c6", PROCESSOR_I486, PTA_MMX},
2002       {"winchip2", PROCESSOR_I486, PTA_MMX | PTA_3DNOW},
2003       {"c3", PROCESSOR_I486, PTA_MMX | PTA_3DNOW},
2004       {"c3-2", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2005       {"i686", PROCESSOR_PENTIUMPRO, 0},
2006       {"pentiumpro", PROCESSOR_PENTIUMPRO, 0},
2007       {"pentium2", PROCESSOR_PENTIUMPRO, PTA_MMX},
2008       {"pentium3", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2009       {"pentium3m", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE},
2010       {"pentium-m", PROCESSOR_PENTIUMPRO, PTA_MMX | PTA_SSE | PTA_SSE2},
2011       {"pentium4", PROCESSOR_PENTIUM4, PTA_MMX |PTA_SSE | PTA_SSE2},
2012       {"pentium4m", PROCESSOR_PENTIUM4, PTA_MMX | PTA_SSE | PTA_SSE2},
2013       {"prescott", PROCESSOR_NOCONA, PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3},
2014       {"nocona", PROCESSOR_NOCONA, (PTA_64BIT
2015                                     | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2016                                     | PTA_CX16 | PTA_NO_SAHF)},
2017       {"core2", PROCESSOR_CORE2, (PTA_64BIT
2018                                   | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2019                                   | PTA_SSSE3
2020                                   | PTA_CX16)},
2021       {"geode", PROCESSOR_GEODE, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2022                                   |PTA_PREFETCH_SSE)},
2023       {"k6", PROCESSOR_K6, PTA_MMX},
2024       {"k6-2", PROCESSOR_K6, PTA_MMX | PTA_3DNOW},
2025       {"k6-3", PROCESSOR_K6, PTA_MMX | PTA_3DNOW},
2026       {"athlon", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2027                                     | PTA_PREFETCH_SSE)},
2028       {"athlon-tbird", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2029                                           | PTA_PREFETCH_SSE)},
2030       {"athlon-4", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2031                                       | PTA_SSE)},
2032       {"athlon-xp", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2033                                        | PTA_SSE)},
2034       {"athlon-mp", PROCESSOR_ATHLON, (PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2035                                        | PTA_SSE)},
2036       {"x86-64", PROCESSOR_K8, (PTA_64BIT
2037                                 | PTA_MMX | PTA_SSE | PTA_SSE2
2038                                 | PTA_NO_SAHF)},
2039       {"k8", PROCESSOR_K8, (PTA_64BIT
2040                             | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2041                             | PTA_SSE | PTA_SSE2
2042                             | PTA_NO_SAHF)},
2043       {"k8-sse3", PROCESSOR_K8, (PTA_64BIT
2044                                  | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2045                                  | PTA_SSE | PTA_SSE2 | PTA_SSE3
2046                                  | PTA_NO_SAHF)},
2047       {"opteron", PROCESSOR_K8, (PTA_64BIT
2048                                  | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2049                                  | PTA_SSE | PTA_SSE2
2050                                  | PTA_NO_SAHF)},
2051       {"opteron-sse3", PROCESSOR_K8, (PTA_64BIT
2052                                       | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2053                                       | PTA_SSE | PTA_SSE2 | PTA_SSE3
2054                                       | PTA_NO_SAHF)},
2055       {"athlon64", PROCESSOR_K8, (PTA_64BIT
2056                                   | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2057                                   | PTA_SSE | PTA_SSE2
2058                                   | PTA_NO_SAHF)},
2059       {"athlon64-sse3", PROCESSOR_K8, (PTA_64BIT
2060                                        | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2061                                        | PTA_SSE | PTA_SSE2 | PTA_SSE3
2062                                        | PTA_NO_SAHF)},
2063       {"athlon-fx", PROCESSOR_K8, (PTA_64BIT
2064                                    | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2065                                    | PTA_SSE | PTA_SSE2
2066                                    | PTA_NO_SAHF)},
2067       {"amdfam10", PROCESSOR_AMDFAM10, (PTA_64BIT
2068                                         | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2069                                         | PTA_SSE | PTA_SSE2 | PTA_SSE3
2070                                         | PTA_SSE4A
2071                                         | PTA_CX16 | PTA_ABM)},
2072       {"barcelona", PROCESSOR_AMDFAM10, (PTA_64BIT
2073                                          | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A
2074                                          | PTA_SSE | PTA_SSE2 | PTA_SSE3
2075                                          | PTA_SSE4A
2076                                          | PTA_CX16 | PTA_ABM)},
2077       {"generic32", PROCESSOR_GENERIC32, 0 /* flags are only used for -march switch.  */ },
2078       {"generic64", PROCESSOR_GENERIC64, PTA_64BIT /* flags are only used for -march switch.  */ },
2079     };
2080
2081   int const pta_size = ARRAY_SIZE (processor_alias_table);
2082
2083 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2084   SUBTARGET_OVERRIDE_OPTIONS;
2085 #endif
2086
2087 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2088   SUBSUBTARGET_OVERRIDE_OPTIONS;
2089 #endif
2090
2091   /* -fPIC is the default for x86_64.  */
2092   if (TARGET_MACHO && TARGET_64BIT)
2093     flag_pic = 2;
2094
2095   /* Set the default values for switches whose default depends on TARGET_64BIT
2096      in case they weren't overwritten by command line options.  */
2097   if (TARGET_64BIT)
2098     {
2099       /* Mach-O doesn't support omitting the frame pointer for now.  */
2100       if (flag_omit_frame_pointer == 2)
2101         flag_omit_frame_pointer = (TARGET_MACHO ? 0 : 1);
2102       if (flag_asynchronous_unwind_tables == 2)
2103         flag_asynchronous_unwind_tables = 1;
2104       if (flag_pcc_struct_return == 2)
2105         flag_pcc_struct_return = 0;
2106     }
2107   else
2108     {
2109       if (flag_omit_frame_pointer == 2)
2110         flag_omit_frame_pointer = 0;
2111       if (flag_asynchronous_unwind_tables == 2)
2112         flag_asynchronous_unwind_tables = 0;
2113       if (flag_pcc_struct_return == 2)
2114         flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
2115     }
2116
2117   /* Need to check -mtune=generic first.  */
2118   if (ix86_tune_string)
2119     {
2120       if (!strcmp (ix86_tune_string, "generic")
2121           || !strcmp (ix86_tune_string, "i686")
2122           /* As special support for cross compilers we read -mtune=native
2123              as -mtune=generic.  With native compilers we won't see the
2124              -mtune=native, as it was changed by the driver.  */
2125           || !strcmp (ix86_tune_string, "native"))
2126         {
2127           if (TARGET_64BIT)
2128             ix86_tune_string = "generic64";
2129           else
2130             ix86_tune_string = "generic32";
2131         }
2132       else if (!strncmp (ix86_tune_string, "generic", 7))
2133         error ("bad value (%s) for -mtune= switch", ix86_tune_string);
2134     }
2135   else
2136     {
2137       if (ix86_arch_string)
2138         ix86_tune_string = ix86_arch_string;
2139       if (!ix86_tune_string)
2140         {
2141           ix86_tune_string = cpu_names [TARGET_CPU_DEFAULT];
2142           ix86_tune_defaulted = 1;
2143         }
2144
2145       /* ix86_tune_string is set to ix86_arch_string or defaulted.  We
2146          need to use a sensible tune option.  */
2147       if (!strcmp (ix86_tune_string, "generic")
2148           || !strcmp (ix86_tune_string, "x86-64")
2149           || !strcmp (ix86_tune_string, "i686"))
2150         {
2151           if (TARGET_64BIT)
2152             ix86_tune_string = "generic64";
2153           else
2154             ix86_tune_string = "generic32";
2155         }
2156     }
2157   if (ix86_stringop_string)
2158     {
2159       if (!strcmp (ix86_stringop_string, "rep_byte"))
2160         stringop_alg = rep_prefix_1_byte;
2161       else if (!strcmp (ix86_stringop_string, "libcall"))
2162         stringop_alg = libcall;
2163       else if (!strcmp (ix86_stringop_string, "rep_4byte"))
2164         stringop_alg = rep_prefix_4_byte;
2165       else if (!strcmp (ix86_stringop_string, "rep_8byte"))
2166         stringop_alg = rep_prefix_8_byte;
2167       else if (!strcmp (ix86_stringop_string, "byte_loop"))
2168         stringop_alg = loop_1_byte;
2169       else if (!strcmp (ix86_stringop_string, "loop"))
2170         stringop_alg = loop;
2171       else if (!strcmp (ix86_stringop_string, "unrolled_loop"))
2172         stringop_alg = unrolled_loop;
2173       else
2174         error ("bad value (%s) for -mstringop-strategy= switch", ix86_stringop_string);
2175     }
2176   if (!strcmp (ix86_tune_string, "x86-64"))
2177     warning (OPT_Wdeprecated, "-mtune=x86-64 is deprecated.  Use -mtune=k8 or "
2178              "-mtune=generic instead as appropriate.");
2179
2180   if (!ix86_arch_string)
2181     ix86_arch_string = TARGET_64BIT ? "x86-64" : "i386";
2182   else
2183     ix86_arch_specified = 1;
2184
2185   if (!strcmp (ix86_arch_string, "generic"))
2186     error ("generic CPU can be used only for -mtune= switch");
2187   if (!strncmp (ix86_arch_string, "generic", 7))
2188     error ("bad value (%s) for -march= switch", ix86_arch_string);
2189
2190   if (ix86_cmodel_string != 0)
2191     {
2192       if (!strcmp (ix86_cmodel_string, "small"))
2193         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2194       else if (!strcmp (ix86_cmodel_string, "medium"))
2195         ix86_cmodel = flag_pic ? CM_MEDIUM_PIC : CM_MEDIUM;
2196       else if (!strcmp (ix86_cmodel_string, "large"))
2197         ix86_cmodel = flag_pic ? CM_LARGE_PIC : CM_LARGE;
2198       else if (flag_pic)
2199         error ("code model %s does not support PIC mode", ix86_cmodel_string);
2200       else if (!strcmp (ix86_cmodel_string, "32"))
2201         ix86_cmodel = CM_32;
2202       else if (!strcmp (ix86_cmodel_string, "kernel") && !flag_pic)
2203         ix86_cmodel = CM_KERNEL;
2204       else
2205         error ("bad value (%s) for -mcmodel= switch", ix86_cmodel_string);
2206     }
2207   else
2208     {
2209       /* For TARGET_64BIT_MS_ABI, force pic on, in order to enable the
2210          use of rip-relative addressing.  This eliminates fixups that
2211          would otherwise be needed if this object is to be placed in a
2212          DLL, and is essentially just as efficient as direct addressing.  */
2213       if (TARGET_64BIT_MS_ABI)
2214         ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
2215       else if (TARGET_64BIT)
2216         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2217       else
2218         ix86_cmodel = CM_32;
2219     }
2220   if (ix86_asm_string != 0)
2221     {
2222       if (! TARGET_MACHO
2223           && !strcmp (ix86_asm_string, "intel"))
2224         ix86_asm_dialect = ASM_INTEL;
2225       else if (!strcmp (ix86_asm_string, "att"))
2226         ix86_asm_dialect = ASM_ATT;
2227       else
2228         error ("bad value (%s) for -masm= switch", ix86_asm_string);
2229     }
2230   if ((TARGET_64BIT == 0) != (ix86_cmodel == CM_32))
2231     error ("code model %qs not supported in the %s bit mode",
2232            ix86_cmodel_string, TARGET_64BIT ? "64" : "32");
2233   if ((TARGET_64BIT != 0) != ((ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2234     sorry ("%i-bit mode not compiled in",
2235            (ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2236
2237   for (i = 0; i < pta_size; i++)
2238     if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
2239       {
2240         ix86_arch = processor_alias_table[i].processor;
2241         /* Default cpu tuning to the architecture.  */
2242         ix86_tune = ix86_arch;
2243
2244         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2245           error ("CPU you selected does not support x86-64 "
2246                  "instruction set");
2247
2248         if (processor_alias_table[i].flags & PTA_MMX
2249             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
2250           ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2251         if (processor_alias_table[i].flags & PTA_3DNOW
2252             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
2253           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
2254         if (processor_alias_table[i].flags & PTA_3DNOW_A
2255             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
2256           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
2257         if (processor_alias_table[i].flags & PTA_SSE
2258             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
2259           ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2260         if (processor_alias_table[i].flags & PTA_SSE2
2261             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
2262           ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2263         if (processor_alias_table[i].flags & PTA_SSE3
2264             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
2265           ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2266         if (processor_alias_table[i].flags & PTA_SSSE3
2267             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
2268           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2269         if (processor_alias_table[i].flags & PTA_SSE4_1
2270             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
2271           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2272         if (processor_alias_table[i].flags & PTA_SSE4_2
2273             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
2274           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
2275         if (processor_alias_table[i].flags & PTA_SSE4A
2276             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
2277           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2278         if (processor_alias_table[i].flags & PTA_SSE5
2279             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE5))
2280           ix86_isa_flags |= OPTION_MASK_ISA_SSE5;
2281
2282         if (processor_alias_table[i].flags & PTA_ABM)
2283           x86_abm = true;
2284         if (processor_alias_table[i].flags & PTA_CX16)
2285           x86_cmpxchg16b = true;
2286         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM))
2287           x86_popcnt = true;
2288         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
2289           x86_prefetch_sse = true;
2290         if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF)))
2291           x86_sahf = true;
2292
2293         break;
2294       }
2295
2296   if (i == pta_size)
2297     error ("bad value (%s) for -march= switch", ix86_arch_string);
2298
2299   ix86_arch_mask = 1u << ix86_arch;
2300   for (i = 0; i < X86_ARCH_LAST; ++i)
2301     ix86_arch_features[i] &= ix86_arch_mask;
2302
2303   for (i = 0; i < pta_size; i++)
2304     if (! strcmp (ix86_tune_string, processor_alias_table[i].name))
2305       {
2306         ix86_tune = processor_alias_table[i].processor;
2307         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2308           {
2309             if (ix86_tune_defaulted)
2310               {
2311                 ix86_tune_string = "x86-64";
2312                 for (i = 0; i < pta_size; i++)
2313                   if (! strcmp (ix86_tune_string,
2314                                 processor_alias_table[i].name))
2315                     break;
2316                 ix86_tune = processor_alias_table[i].processor;
2317               }
2318             else
2319               error ("CPU you selected does not support x86-64 "
2320                      "instruction set");
2321           }
2322         /* Intel CPUs have always interpreted SSE prefetch instructions as
2323            NOPs; so, we can enable SSE prefetch instructions even when
2324            -mtune (rather than -march) points us to a processor that has them.
2325            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
2326            higher processors.  */
2327         if (TARGET_CMOVE
2328             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
2329           x86_prefetch_sse = true;
2330         break;
2331       }
2332   if (i == pta_size)
2333     error ("bad value (%s) for -mtune= switch", ix86_tune_string);
2334
2335   ix86_tune_mask = 1u << ix86_tune;
2336   for (i = 0; i < X86_TUNE_LAST; ++i)
2337     ix86_tune_features[i] &= ix86_tune_mask;
2338
2339   if (optimize_size)
2340     ix86_cost = &size_cost;
2341   else
2342     ix86_cost = processor_target_table[ix86_tune].cost;
2343
2344   /* Arrange to set up i386_stack_locals for all functions.  */
2345   init_machine_status = ix86_init_machine_status;
2346
2347   /* Validate -mregparm= value.  */
2348   if (ix86_regparm_string)
2349     {
2350       if (TARGET_64BIT)
2351         warning (0, "-mregparm is ignored in 64-bit mode");
2352       i = atoi (ix86_regparm_string);
2353       if (i < 0 || i > REGPARM_MAX)
2354         error ("-mregparm=%d is not between 0 and %d", i, REGPARM_MAX);
2355       else
2356         ix86_regparm = i;
2357     }
2358   if (TARGET_64BIT)
2359     ix86_regparm = REGPARM_MAX;
2360
2361   /* If the user has provided any of the -malign-* options,
2362      warn and use that value only if -falign-* is not set.
2363      Remove this code in GCC 3.2 or later.  */
2364   if (ix86_align_loops_string)
2365     {
2366       warning (0, "-malign-loops is obsolete, use -falign-loops");
2367       if (align_loops == 0)
2368         {
2369           i = atoi (ix86_align_loops_string);
2370           if (i < 0 || i > MAX_CODE_ALIGN)
2371             error ("-malign-loops=%d is not between 0 and %d", i, MAX_CODE_ALIGN);
2372           else
2373             align_loops = 1 << i;
2374         }
2375     }
2376
2377   if (ix86_align_jumps_string)
2378     {
2379       warning (0, "-malign-jumps is obsolete, use -falign-jumps");
2380       if (align_jumps == 0)
2381         {
2382           i = atoi (ix86_align_jumps_string);
2383           if (i < 0 || i > MAX_CODE_ALIGN)
2384             error ("-malign-loops=%d is not between 0 and %d", i, MAX_CODE_ALIGN);
2385           else
2386             align_jumps = 1 << i;
2387         }
2388     }
2389
2390   if (ix86_align_funcs_string)
2391     {
2392       warning (0, "-malign-functions is obsolete, use -falign-functions");
2393       if (align_functions == 0)
2394         {
2395           i = atoi (ix86_align_funcs_string);
2396           if (i < 0 || i > MAX_CODE_ALIGN)
2397             error ("-malign-loops=%d is not between 0 and %d", i, MAX_CODE_ALIGN);
2398           else
2399             align_functions = 1 << i;
2400         }
2401     }
2402
2403   /* Default align_* from the processor table.  */
2404   if (align_loops == 0)
2405     {
2406       align_loops = processor_target_table[ix86_tune].align_loop;
2407       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
2408     }
2409   if (align_jumps == 0)
2410     {
2411       align_jumps = processor_target_table[ix86_tune].align_jump;
2412       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
2413     }
2414   if (align_functions == 0)
2415     {
2416       align_functions = processor_target_table[ix86_tune].align_func;
2417     }
2418
2419   /* Validate -mbranch-cost= value, or provide default.  */
2420   ix86_branch_cost = ix86_cost->branch_cost;
2421   if (ix86_branch_cost_string)
2422     {
2423       i = atoi (ix86_branch_cost_string);
2424       if (i < 0 || i > 5)
2425         error ("-mbranch-cost=%d is not between 0 and 5", i);
2426       else
2427         ix86_branch_cost = i;
2428     }
2429   if (ix86_section_threshold_string)
2430     {
2431       i = atoi (ix86_section_threshold_string);
2432       if (i < 0)
2433         error ("-mlarge-data-threshold=%d is negative", i);
2434       else
2435         ix86_section_threshold = i;
2436     }
2437
2438   if (ix86_tls_dialect_string)
2439     {
2440       if (strcmp (ix86_tls_dialect_string, "gnu") == 0)
2441         ix86_tls_dialect = TLS_DIALECT_GNU;
2442       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
2443         ix86_tls_dialect = TLS_DIALECT_GNU2;
2444       else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
2445         ix86_tls_dialect = TLS_DIALECT_SUN;
2446       else
2447         error ("bad value (%s) for -mtls-dialect= switch",
2448                ix86_tls_dialect_string);
2449     }
2450
2451   if (ix87_precision_string)
2452     {
2453       i = atoi (ix87_precision_string);
2454       if (i != 32 && i != 64 && i != 80)
2455         error ("pc%d is not valid precision setting (32, 64 or 80)", i);
2456     }
2457
2458   if (TARGET_64BIT)
2459     {
2460       target_flags |= TARGET_SUBTARGET64_DEFAULT & ~target_flags_explicit;
2461
2462       /* Enable by default the SSE and MMX builtins.  Do allow the user to
2463          explicitly disable any of these.  In particular, disabling SSE and
2464          MMX for kernel code is extremely useful.  */
2465       if (!ix86_arch_specified)
2466       ix86_isa_flags
2467         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
2468              | TARGET_SUBTARGET64_ISA_DEFAULT) & ~ix86_isa_flags_explicit);
2469
2470       if (TARGET_RTD)
2471         warning (0, "-mrtd is ignored in 64bit mode");
2472     }
2473   else
2474     {
2475       target_flags |= TARGET_SUBTARGET32_DEFAULT & ~target_flags_explicit;
2476
2477       if (!ix86_arch_specified)
2478       ix86_isa_flags
2479         |= TARGET_SUBTARGET32_ISA_DEFAULT & ~ix86_isa_flags_explicit;
2480
2481       /* i386 ABI does not specify red zone.  It still makes sense to use it
2482          when programmer takes care to stack from being destroyed.  */
2483       if (!(target_flags_explicit & MASK_NO_RED_ZONE))
2484         target_flags |= MASK_NO_RED_ZONE;
2485     }
2486
2487   /* Keep nonleaf frame pointers.  */
2488   if (flag_omit_frame_pointer)
2489     target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
2490   else if (TARGET_OMIT_LEAF_FRAME_POINTER)
2491     flag_omit_frame_pointer = 1;
2492
2493   /* If we're doing fast math, we don't care about comparison order
2494      wrt NaNs.  This lets us use a shorter comparison sequence.  */
2495   if (flag_finite_math_only)
2496     target_flags &= ~MASK_IEEE_FP;
2497
2498   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
2499      since the insns won't need emulation.  */
2500   if (x86_arch_always_fancy_math_387 & ix86_arch_mask)
2501     target_flags &= ~MASK_NO_FANCY_MATH_387;
2502
2503   /* Likewise, if the target doesn't have a 387, or we've specified
2504      software floating point, don't use 387 inline intrinsics.  */
2505   if (!TARGET_80387)
2506     target_flags |= MASK_NO_FANCY_MATH_387;
2507
2508   /* Turn on SSE4A bultins for -msse5.  */
2509   if (TARGET_SSE5)
2510     ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2511
2512   /* Turn on SSE4.1 builtins for -msse4.2.  */
2513   if (TARGET_SSE4_2)
2514     ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2515
2516   /* Turn on SSSE3 builtins for -msse4.1.  */
2517   if (TARGET_SSE4_1)
2518     ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2519
2520   /* Turn on SSE3 builtins for -mssse3.  */
2521   if (TARGET_SSSE3)
2522     ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2523
2524   /* Turn on SSE3 builtins for -msse4a.  */
2525   if (TARGET_SSE4A)
2526     ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2527
2528   /* Turn on SSE2 builtins for -msse3.  */
2529   if (TARGET_SSE3)
2530     ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2531
2532   /* Turn on SSE builtins for -msse2.  */
2533   if (TARGET_SSE2)
2534     ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2535
2536   /* Turn on MMX builtins for -msse.  */
2537   if (TARGET_SSE)
2538     {
2539       ix86_isa_flags |= OPTION_MASK_ISA_MMX & ~ix86_isa_flags_explicit;
2540       x86_prefetch_sse = true;
2541     }
2542
2543   /* Turn on MMX builtins for 3Dnow.  */
2544   if (TARGET_3DNOW)
2545     ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2546
2547   /* Turn on popcnt instruction for -msse4.2 or -mabm.  */
2548   if (TARGET_SSE4_2 || TARGET_ABM)
2549     x86_popcnt = true;
2550
2551   /* Validate -mpreferred-stack-boundary= value, or provide default.
2552      The default of 128 bits is for Pentium III's SSE __m128.  We can't
2553      change it because of optimize_size.  Otherwise, we can't mix object
2554      files compiled with -Os and -On.  */
2555   ix86_preferred_stack_boundary = 128;
2556   if (ix86_preferred_stack_boundary_string)
2557     {
2558       i = atoi (ix86_preferred_stack_boundary_string);
2559       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
2560         error ("-mpreferred-stack-boundary=%d is not between %d and 12", i,
2561                TARGET_64BIT ? 4 : 2);
2562       else
2563         ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
2564     }
2565
2566   /* Accept -msseregparm only if at least SSE support is enabled.  */
2567   if (TARGET_SSEREGPARM
2568       && ! TARGET_SSE)
2569     error ("-msseregparm used without SSE enabled");
2570
2571   ix86_fpmath = TARGET_FPMATH_DEFAULT;
2572   if (ix86_fpmath_string != 0)
2573     {
2574       if (! strcmp (ix86_fpmath_string, "387"))
2575         ix86_fpmath = FPMATH_387;
2576       else if (! strcmp (ix86_fpmath_string, "sse"))
2577         {
2578           if (!TARGET_SSE)
2579             {
2580               warning (0, "SSE instruction set disabled, using 387 arithmetics");
2581               ix86_fpmath = FPMATH_387;
2582             }
2583           else
2584             ix86_fpmath = FPMATH_SSE;
2585         }
2586       else if (! strcmp (ix86_fpmath_string, "387,sse")
2587                || ! strcmp (ix86_fpmath_string, "sse,387"))
2588         {
2589           if (!TARGET_SSE)
2590             {
2591               warning (0, "SSE instruction set disabled, using 387 arithmetics");
2592               ix86_fpmath = FPMATH_387;
2593             }
2594           else if (!TARGET_80387)
2595             {
2596               warning (0, "387 instruction set disabled, using SSE arithmetics");
2597               ix86_fpmath = FPMATH_SSE;
2598             }
2599           else
2600             ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
2601         }
2602       else
2603         error ("bad value (%s) for -mfpmath= switch", ix86_fpmath_string);
2604     }
2605
2606   /* If the i387 is disabled, then do not return values in it. */
2607   if (!TARGET_80387)
2608     target_flags &= ~MASK_FLOAT_RETURNS;
2609
2610   /* Use external vectorized library in vectorizing intrinsics.  */
2611   if (ix86_veclibabi_string)
2612     {
2613       if (strcmp (ix86_veclibabi_string, "acml") == 0)
2614         ix86_veclib_handler = ix86_veclibabi_acml;
2615       else
2616         error ("unknown vectorization library ABI type (%s) for "
2617                "-mveclibabi= switch", ix86_veclibabi_string);
2618     }
2619
2620   if ((x86_accumulate_outgoing_args & ix86_tune_mask)
2621       && !(target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
2622       && !optimize_size)
2623     target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
2624
2625   /* ??? Unwind info is not correct around the CFG unless either a frame
2626      pointer is present or M_A_O_A is set.  Fixing this requires rewriting
2627      unwind info generation to be aware of the CFG and propagating states
2628      around edges.  */
2629   if ((flag_unwind_tables || flag_asynchronous_unwind_tables
2630        || flag_exceptions || flag_non_call_exceptions)
2631       && flag_omit_frame_pointer
2632       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
2633     {
2634       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
2635         warning (0, "unwind tables currently require either a frame pointer "
2636                  "or -maccumulate-outgoing-args for correctness");
2637       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
2638     }
2639
2640   /* For sane SSE instruction set generation we need fcomi instruction.
2641      It is safe to enable all CMOVE instructions.  */
2642   if (TARGET_SSE)
2643     TARGET_CMOVE = 1;
2644
2645   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
2646   {
2647     char *p;
2648     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
2649     p = strchr (internal_label_prefix, 'X');
2650     internal_label_prefix_len = p - internal_label_prefix;
2651     *p = '\0';
2652   }
2653
2654   /* When scheduling description is not available, disable scheduler pass
2655      so it won't slow down the compilation and make x87 code slower.  */
2656   if (!TARGET_SCHEDULE)
2657     flag_schedule_insns_after_reload = flag_schedule_insns = 0;
2658
2659   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
2660     set_param_value ("simultaneous-prefetches",
2661                      ix86_cost->simultaneous_prefetches);
2662   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
2663     set_param_value ("l1-cache-line-size", ix86_cost->prefetch_block);
2664   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
2665     set_param_value ("l1-cache-size", ix86_cost->l1_cache_size);
2666   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
2667     set_param_value ("l2-cache-size", ix86_cost->l2_cache_size);
2668 }
2669 \f
2670 /* Return true if this goes in large data/bss.  */
2671
2672 static bool
2673 ix86_in_large_data_p (tree exp)
2674 {
2675   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
2676     return false;
2677
2678   /* Functions are never large data.  */
2679   if (TREE_CODE (exp) == FUNCTION_DECL)
2680     return false;
2681
2682   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
2683     {
2684       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
2685       if (strcmp (section, ".ldata") == 0
2686           || strcmp (section, ".lbss") == 0)
2687         return true;
2688       return false;
2689     }
2690   else
2691     {
2692       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2693
2694       /* If this is an incomplete type with size 0, then we can't put it
2695          in data because it might be too big when completed.  */
2696       if (!size || size > ix86_section_threshold)
2697         return true;
2698     }
2699
2700   return false;
2701 }
2702
2703 /* Switch to the appropriate section for output of DECL.
2704    DECL is either a `VAR_DECL' node or a constant of some sort.
2705    RELOC indicates whether forming the initial value of DECL requires
2706    link-time relocations.  */
2707
2708 static section * x86_64_elf_select_section (tree, int, unsigned HOST_WIDE_INT)
2709         ATTRIBUTE_UNUSED;
2710
2711 static section *
2712 x86_64_elf_select_section (tree decl, int reloc,
2713                            unsigned HOST_WIDE_INT align)
2714 {
2715   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
2716       && ix86_in_large_data_p (decl))
2717     {
2718       const char *sname = NULL;
2719       unsigned int flags = SECTION_WRITE;
2720       switch (categorize_decl_for_section (decl, reloc))
2721         {
2722         case SECCAT_DATA:
2723           sname = ".ldata";
2724           break;
2725         case SECCAT_DATA_REL:
2726           sname = ".ldata.rel";
2727           break;
2728         case SECCAT_DATA_REL_LOCAL:
2729           sname = ".ldata.rel.local";
2730           break;
2731         case SECCAT_DATA_REL_RO:
2732           sname = ".ldata.rel.ro";
2733           break;
2734         case SECCAT_DATA_REL_RO_LOCAL:
2735           sname = ".ldata.rel.ro.local";
2736           break;
2737         case SECCAT_BSS:
2738           sname = ".lbss";
2739           flags |= SECTION_BSS;
2740           break;
2741         case SECCAT_RODATA:
2742         case SECCAT_RODATA_MERGE_STR:
2743         case SECCAT_RODATA_MERGE_STR_INIT:
2744         case SECCAT_RODATA_MERGE_CONST:
2745           sname = ".lrodata";
2746           flags = 0;
2747           break;
2748         case SECCAT_SRODATA:
2749         case SECCAT_SDATA:
2750         case SECCAT_SBSS:
2751           gcc_unreachable ();
2752         case SECCAT_TEXT:
2753         case SECCAT_TDATA:
2754         case SECCAT_TBSS:
2755           /* We don't split these for medium model.  Place them into
2756              default sections and hope for best.  */
2757           break;
2758         }
2759       if (sname)
2760         {
2761           /* We might get called with string constants, but get_named_section
2762              doesn't like them as they are not DECLs.  Also, we need to set
2763              flags in that case.  */
2764           if (!DECL_P (decl))
2765             return get_section (sname, flags, NULL);
2766           return get_named_section (decl, sname, reloc);
2767         }
2768     }
2769   return default_elf_select_section (decl, reloc, align);
2770 }
2771
2772 /* Build up a unique section name, expressed as a
2773    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
2774    RELOC indicates whether the initial value of EXP requires
2775    link-time relocations.  */
2776
2777 static void ATTRIBUTE_UNUSED
2778 x86_64_elf_unique_section (tree decl, int reloc)
2779 {
2780   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
2781       && ix86_in_large_data_p (decl))
2782     {
2783       const char *prefix = NULL;
2784       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
2785       bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
2786
2787       switch (categorize_decl_for_section (decl, reloc))
2788         {
2789         case SECCAT_DATA:
2790         case SECCAT_DATA_REL:
2791         case SECCAT_DATA_REL_LOCAL:
2792         case SECCAT_DATA_REL_RO:
2793         case SECCAT_DATA_REL_RO_LOCAL:
2794           prefix = one_only ? ".gnu.linkonce.ld." : ".ldata.";
2795           break;
2796         case SECCAT_BSS:
2797           prefix = one_only ? ".gnu.linkonce.lb." : ".lbss.";
2798           break;
2799         case SECCAT_RODATA:
2800         case SECCAT_RODATA_MERGE_STR:
2801         case SECCAT_RODATA_MERGE_STR_INIT:
2802         case SECCAT_RODATA_MERGE_CONST:
2803           prefix = one_only ? ".gnu.linkonce.lr." : ".lrodata.";
2804           break;
2805         case SECCAT_SRODATA:
2806         case SECCAT_SDATA:
2807         case SECCAT_SBSS:
2808           gcc_unreachable ();
2809         case SECCAT_TEXT:
2810         case SECCAT_TDATA:
2811         case SECCAT_TBSS:
2812           /* We don't split these for medium model.  Place them into
2813              default sections and hope for best.  */
2814           break;
2815         }
2816       if (prefix)
2817         {
2818           const char *name;
2819           size_t nlen, plen;
2820           char *string;
2821           plen = strlen (prefix);
2822
2823           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2824           name = targetm.strip_name_encoding (name);
2825           nlen = strlen (name);
2826
2827           string = (char *) alloca (nlen + plen + 1);
2828           memcpy (string, prefix, plen);
2829           memcpy (string + plen, name, nlen + 1);
2830
2831           DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
2832           return;
2833         }
2834     }
2835   default_unique_section (decl, reloc);
2836 }
2837
2838 #ifdef COMMON_ASM_OP
2839 /* This says how to output assembler code to declare an
2840    uninitialized external linkage data object.
2841
2842    For medium model x86-64 we need to use .largecomm opcode for
2843    large objects.  */
2844 void
2845 x86_elf_aligned_common (FILE *file,
2846                         const char *name, unsigned HOST_WIDE_INT size,
2847                         int align)
2848 {
2849   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
2850       && size > (unsigned int)ix86_section_threshold)
2851     fprintf (file, ".largecomm\t");
2852   else
2853     fprintf (file, "%s", COMMON_ASM_OP);
2854   assemble_name (file, name);
2855   fprintf (file, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",
2856            size, align / BITS_PER_UNIT);
2857 }
2858 #endif
2859
2860 /* Utility function for targets to use in implementing
2861    ASM_OUTPUT_ALIGNED_BSS.  */
2862
2863 void
2864 x86_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
2865                         const char *name, unsigned HOST_WIDE_INT size,
2866                         int align)
2867 {
2868   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
2869       && size > (unsigned int)ix86_section_threshold)
2870     switch_to_section (get_named_section (decl, ".lbss", 0));
2871   else
2872     switch_to_section (bss_section);
2873   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2874 #ifdef ASM_DECLARE_OBJECT_NAME
2875   last_assemble_variable_decl = decl;
2876   ASM_DECLARE_OBJECT_NAME (file, name, decl);
2877 #else
2878   /* Standard thing is just output label for the object.  */
2879   ASM_OUTPUT_LABEL (file, name);
2880 #endif /* ASM_DECLARE_OBJECT_NAME */
2881   ASM_OUTPUT_SKIP (file, size ? size : 1);
2882 }
2883 \f
2884 void
2885 optimization_options (int level, int size ATTRIBUTE_UNUSED)
2886 {
2887   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
2888      make the problem with not enough registers even worse.  */
2889 #ifdef INSN_SCHEDULING
2890   if (level > 1)
2891     flag_schedule_insns = 0;
2892 #endif
2893
2894   if (TARGET_MACHO)
2895     /* The Darwin libraries never set errno, so we might as well
2896        avoid calling them when that's the only reason we would.  */
2897     flag_errno_math = 0;
2898
2899   /* The default values of these switches depend on the TARGET_64BIT
2900      that is not known at this moment.  Mark these values with 2 and
2901      let user the to override these.  In case there is no command line option
2902      specifying them, we will set the defaults in override_options.  */
2903   if (optimize >= 1)
2904     flag_omit_frame_pointer = 2;
2905   flag_pcc_struct_return = 2;
2906   flag_asynchronous_unwind_tables = 2;
2907 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
2908   SUBTARGET_OPTIMIZATION_OPTIONS;
2909 #endif
2910 }
2911 \f
2912 /* Decide whether we can make a sibling call to a function.  DECL is the
2913    declaration of the function being targeted by the call and EXP is the
2914    CALL_EXPR representing the call.  */
2915
2916 static bool
2917 ix86_function_ok_for_sibcall (tree decl, tree exp)
2918 {
2919   tree func;
2920   rtx a, b;
2921
2922   /* If we are generating position-independent code, we cannot sibcall
2923      optimize any indirect call, or a direct call to a global function,
2924      as the PLT requires %ebx be live.  */
2925   if (!TARGET_64BIT && flag_pic && (!decl || !targetm.binds_local_p (decl)))
2926     return false;
2927
2928   if (decl)
2929     func = decl;
2930   else
2931     {
2932       func = TREE_TYPE (CALL_EXPR_FN (exp));
2933       if (POINTER_TYPE_P (func))
2934         func = TREE_TYPE (func);
2935     }
2936
2937   /* Check that the return value locations are the same.  Like
2938      if we are returning floats on the 80387 register stack, we cannot
2939      make a sibcall from a function that doesn't return a float to a
2940      function that does or, conversely, from a function that does return
2941      a float to a function that doesn't; the necessary stack adjustment
2942      would not be executed.  This is also the place we notice
2943      differences in the return value ABI.  Note that it is ok for one
2944      of the functions to have void return type as long as the return
2945      value of the other is passed in a register.  */
2946   a = ix86_function_value (TREE_TYPE (exp), func, false);
2947   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
2948                            cfun->decl, false);
2949   if (STACK_REG_P (a) || STACK_REG_P (b))
2950     {
2951       if (!rtx_equal_p (a, b))
2952         return false;
2953     }
2954   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
2955     ;
2956   else if (!rtx_equal_p (a, b))
2957     return false;
2958
2959   /* If this call is indirect, we'll need to be able to use a call-clobbered
2960      register for the address of the target function.  Make sure that all
2961      such registers are not used for passing parameters.  */
2962   if (!decl && !TARGET_64BIT)
2963     {
2964       tree type;
2965
2966       /* We're looking at the CALL_EXPR, we need the type of the function.  */
2967       type = CALL_EXPR_FN (exp);                /* pointer expression */
2968       type = TREE_TYPE (type);                  /* pointer type */
2969       type = TREE_TYPE (type);                  /* function type */
2970
2971       if (ix86_function_regparm (type, NULL) >= 3)
2972         {
2973           /* ??? Need to count the actual number of registers to be used,
2974              not the possible number of registers.  Fix later.  */
2975           return false;
2976         }
2977     }
2978
2979   /* Dllimport'd functions are also called indirectly.  */
2980   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2981       && decl && DECL_DLLIMPORT_P (decl)
2982       && ix86_function_regparm (TREE_TYPE (decl), NULL) >= 3)
2983     return false;
2984
2985   /* If we forced aligned the stack, then sibcalling would unalign the
2986      stack, which may break the called function.  */
2987   if (cfun->machine->force_align_arg_pointer)
2988     return false;
2989
2990   /* Otherwise okay.  That also includes certain types of indirect calls.  */
2991   return true;
2992 }
2993
2994 /* Handle "cdecl", "stdcall", "fastcall", "regparm" and "sseregparm"
2995    calling convention attributes;
2996    arguments as in struct attribute_spec.handler.  */
2997
2998 static tree
2999 ix86_handle_cconv_attribute (tree *node, tree name,
3000                                    tree args,
3001                                    int flags ATTRIBUTE_UNUSED,
3002                                    bool *no_add_attrs)
3003 {
3004   if (TREE_CODE (*node) != FUNCTION_TYPE
3005       && TREE_CODE (*node) != METHOD_TYPE
3006       && TREE_CODE (*node) != FIELD_DECL
3007       && TREE_CODE (*node) != TYPE_DECL)
3008     {
3009       warning (OPT_Wattributes, "%qs attribute only applies to functions",
3010                IDENTIFIER_POINTER (name));
3011       *no_add_attrs = true;
3012       return NULL_TREE;
3013     }
3014
3015   /* Can combine regparm with all attributes but fastcall.  */
3016   if (is_attribute_p ("regparm", name))
3017     {
3018       tree cst;
3019
3020       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
3021         {
3022           error ("fastcall and regparm attributes are not compatible");
3023         }
3024
3025       cst = TREE_VALUE (args);
3026       if (TREE_CODE (cst) != INTEGER_CST)
3027         {
3028           warning (OPT_Wattributes,
3029                    "%qs attribute requires an integer constant argument",
3030                    IDENTIFIER_POINTER (name));
3031           *no_add_attrs = true;
3032         }
3033       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
3034         {
3035           warning (OPT_Wattributes, "argument to %qs attribute larger than %d",
3036                    IDENTIFIER_POINTER (name), REGPARM_MAX);
3037           *no_add_attrs = true;
3038         }
3039
3040       if (!TARGET_64BIT
3041           && lookup_attribute (ix86_force_align_arg_pointer_string,
3042                                TYPE_ATTRIBUTES (*node))
3043           && compare_tree_int (cst, REGPARM_MAX-1))
3044         {
3045           error ("%s functions limited to %d register parameters",
3046                  ix86_force_align_arg_pointer_string, REGPARM_MAX-1);
3047         }
3048
3049       return NULL_TREE;
3050     }
3051
3052   if (TARGET_64BIT)
3053     {
3054       /* Do not warn when emulating the MS ABI.  */
3055       if (!TARGET_64BIT_MS_ABI)
3056         warning (OPT_Wattributes, "%qs attribute ignored",
3057                  IDENTIFIER_POINTER (name));
3058       *no_add_attrs = true;
3059       return NULL_TREE;
3060     }
3061
3062   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
3063   if (is_attribute_p ("fastcall", name))
3064     {
3065       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
3066         {
3067           error ("fastcall and cdecl attributes are not compatible");
3068         }
3069       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
3070         {
3071           error ("fastcall and stdcall attributes are not compatible");
3072         }
3073       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
3074         {
3075           error ("fastcall and regparm attributes are not compatible");
3076         }
3077     }
3078
3079   /* Can combine stdcall with fastcall (redundant), regparm and
3080      sseregparm.  */
3081   else if (is_attribute_p ("stdcall", name))
3082     {
3083       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
3084         {
3085           error ("stdcall and cdecl attributes are not compatible");
3086         }
3087       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
3088         {
3089           error ("stdcall and fastcall attributes are not compatible");
3090         }
3091     }
3092
3093   /* Can combine cdecl with regparm and sseregparm.  */
3094   else if (is_attribute_p ("cdecl", name))
3095     {
3096       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
3097         {
3098           error ("stdcall and cdecl attributes are not compatible");
3099         }
3100       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
3101         {
3102           error ("fastcall and cdecl attributes are not compatible");
3103         }
3104     }
3105
3106   /* Can combine sseregparm with all attributes.  */
3107
3108   return NULL_TREE;
3109 }
3110
3111 /* Return 0 if the attributes for two types are incompatible, 1 if they
3112    are compatible, and 2 if they are nearly compatible (which causes a
3113    warning to be generated).  */
3114
3115 static int
3116 ix86_comp_type_attributes (const_tree type1, const_tree type2)
3117 {
3118   /* Check for mismatch of non-default calling convention.  */
3119   const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
3120
3121   if (TREE_CODE (type1) != FUNCTION_TYPE
3122       && TREE_CODE (type1) != METHOD_TYPE)
3123     return 1;
3124
3125   /* Check for mismatched fastcall/regparm types.  */
3126   if ((!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
3127        != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
3128       || (ix86_function_regparm (type1, NULL)
3129           != ix86_function_regparm (type2, NULL)))
3130     return 0;
3131
3132   /* Check for mismatched sseregparm types.  */
3133   if (!lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type1))
3134       != !lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type2)))
3135     return 0;
3136
3137   /* Check for mismatched return types (cdecl vs stdcall).  */
3138   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
3139       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
3140     return 0;
3141
3142   return 1;
3143 }
3144 \f
3145 /* Return the regparm value for a function with the indicated TYPE and DECL.
3146    DECL may be NULL when calling function indirectly
3147    or considering a libcall.  */
3148
3149 static int
3150 ix86_function_regparm (const_tree type, const_tree decl)
3151 {
3152   tree attr;
3153   int regparm = ix86_regparm;
3154
3155   if (TARGET_64BIT)
3156     return regparm;
3157
3158   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
3159   if (attr)
3160     return TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
3161
3162   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
3163     return 2;
3164
3165   /* Use register calling convention for local functions when possible.  */
3166   if (decl && TREE_CODE (decl) == FUNCTION_DECL
3167       && flag_unit_at_a_time && !profile_flag)
3168     {
3169       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
3170       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
3171       if (i && i->local)
3172         {
3173           int local_regparm, globals = 0, regno;
3174           struct function *f;
3175
3176           /* Make sure no regparm register is taken by a
3177              global register variable.  */
3178           for (local_regparm = 0; local_regparm < 3; local_regparm++)
3179             if (global_regs[local_regparm])
3180               break;
3181
3182           /* We can't use regparm(3) for nested functions as these use
3183              static chain pointer in third argument.  */
3184           if (local_regparm == 3
3185               && (decl_function_context (decl)
3186                   || ix86_force_align_arg_pointer)
3187               && !DECL_NO_STATIC_CHAIN (decl))
3188             local_regparm = 2;
3189
3190           /* If the function realigns its stackpointer, the prologue will
3191              clobber %ecx.  If we've already generated code for the callee,
3192              the callee DECL_STRUCT_FUNCTION is gone, so we fall back to
3193              scanning the attributes for the self-realigning property.  */
3194           f = DECL_STRUCT_FUNCTION (decl);
3195           if (local_regparm == 3
3196               && (f ? !!f->machine->force_align_arg_pointer
3197                   : !!lookup_attribute (ix86_force_align_arg_pointer_string,
3198                                         TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
3199             local_regparm = 2;
3200
3201           /* Each global register variable increases register preassure,
3202              so the more global reg vars there are, the smaller regparm
3203              optimization use, unless requested by the user explicitly.  */
3204           for (regno = 0; regno < 6; regno++)
3205             if (global_regs[regno])
3206               globals++;
3207           local_regparm
3208             = globals < local_regparm ? local_regparm - globals : 0;
3209
3210           if (local_regparm > regparm)
3211             regparm = local_regparm;
3212         }
3213     }
3214
3215   return regparm;
3216 }
3217
3218 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
3219    DFmode (2) arguments in SSE registers for a function with the
3220    indicated TYPE and DECL.  DECL may be NULL when calling function
3221    indirectly or considering a libcall.  Otherwise return 0.  */
3222
3223 static int
3224 ix86_function_sseregparm (const_tree type, const_tree decl)
3225 {
3226   gcc_assert (!TARGET_64BIT);
3227
3228   /* Use SSE registers to pass SFmode and DFmode arguments if requested
3229      by the sseregparm attribute.  */
3230   if (TARGET_SSEREGPARM
3231       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
3232     {
3233       if (!TARGET_SSE)
3234         {
3235           if (decl)
3236             error ("Calling %qD with attribute sseregparm without "
3237                    "SSE/SSE2 enabled", decl);
3238           else
3239             error ("Calling %qT with attribute sseregparm without "
3240                    "SSE/SSE2 enabled", type);
3241           return 0;
3242         }
3243
3244       return 2;
3245     }
3246
3247   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
3248      (and DFmode for SSE2) arguments in SSE registers.  */
3249   if (decl && TARGET_SSE_MATH && flag_unit_at_a_time && !profile_flag)
3250     {
3251       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
3252       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
3253       if (i && i->local)
3254         return TARGET_SSE2 ? 2 : 1;
3255     }
3256
3257   return 0;
3258 }
3259
3260 /* Return true if EAX is live at the start of the function.  Used by
3261    ix86_expand_prologue to determine if we need special help before
3262    calling allocate_stack_worker.  */
3263
3264 static bool
3265 ix86_eax_live_at_start_p (void)
3266 {
3267   /* Cheat.  Don't bother working forward from ix86_function_regparm
3268      to the function type to whether an actual argument is located in
3269      eax.  Instead just look at cfg info, which is still close enough
3270      to correct at this point.  This gives false positives for broken
3271      functions that might use uninitialized data that happens to be
3272      allocated in eax, but who cares?  */
3273   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR), 0);
3274 }
3275
3276 /* Value is the number of bytes of arguments automatically
3277    popped when returning from a subroutine call.
3278    FUNDECL is the declaration node of the function (as a tree),
3279    FUNTYPE is the data type of the function (as a tree),
3280    or for a library call it is an identifier node for the subroutine name.
3281    SIZE is the number of bytes of arguments passed on the stack.
3282
3283    On the 80386, the RTD insn may be used to pop them if the number
3284      of args is fixed, but if the number is variable then the caller
3285      must pop them all.  RTD can't be used for library calls now
3286      because the library is compiled with the Unix compiler.
3287    Use of RTD is a selectable option, since it is incompatible with
3288    standard Unix calling sequences.  If the option is not selected,
3289    the caller must always pop the args.
3290
3291    The attribute stdcall is equivalent to RTD on a per module basis.  */
3292
3293 int
3294 ix86_return_pops_args (tree fundecl, tree funtype, int size)
3295 {
3296   int rtd;
3297
3298   /* None of the 64-bit ABIs pop arguments.  */
3299   if (TARGET_64BIT)
3300     return 0;
3301
3302   rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
3303
3304   /* Cdecl functions override -mrtd, and never pop the stack.  */
3305   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
3306     {
3307       /* Stdcall and fastcall functions will pop the stack if not
3308          variable args.  */
3309       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
3310           || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
3311         rtd = 1;
3312
3313       if (rtd && ! stdarg_p (funtype))
3314         return size;
3315     }
3316
3317   /* Lose any fake structure return argument if it is passed on the stack.  */
3318   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
3319       && !KEEP_AGGREGATE_RETURN_POINTER)
3320     {
3321       int nregs = ix86_function_regparm (funtype, fundecl);
3322       if (nregs == 0)
3323         return GET_MODE_SIZE (Pmode);
3324     }
3325
3326   return 0;
3327 }
3328 \f
3329 /* Argument support functions.  */
3330
3331 /* Return true when register may be used to pass function parameters.  */
3332 bool
3333 ix86_function_arg_regno_p (int regno)
3334 {
3335   int i;
3336   const int *parm_regs;
3337
3338   if (!TARGET_64BIT)
3339     {
3340       if (TARGET_MACHO)
3341         return (regno < REGPARM_MAX
3342                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
3343       else
3344         return (regno < REGPARM_MAX
3345                 || (TARGET_MMX && MMX_REGNO_P (regno)
3346                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
3347                 || (TARGET_SSE && SSE_REGNO_P (regno)
3348                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
3349     }
3350
3351   if (TARGET_MACHO)
3352     {
3353       if (SSE_REGNO_P (regno) && TARGET_SSE)
3354         return true;
3355     }
3356   else
3357     {
3358       if (TARGET_SSE && SSE_REGNO_P (regno)
3359           && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
3360         return true;
3361     }
3362
3363   /* RAX is used as hidden argument to va_arg functions.  */
3364   if (!TARGET_64BIT_MS_ABI && regno == AX_REG)
3365     return true;
3366
3367   if (TARGET_64BIT_MS_ABI)
3368     parm_regs = x86_64_ms_abi_int_parameter_registers;
3369   else
3370     parm_regs = x86_64_int_parameter_registers;
3371   for (i = 0; i < REGPARM_MAX; i++)
3372     if (regno == parm_regs[i])
3373       return true;
3374   return false;
3375 }
3376
3377 /* Return if we do not know how to pass TYPE solely in registers.  */
3378
3379 static bool
3380 ix86_must_pass_in_stack (enum machine_mode mode, const_tree type)
3381 {
3382   if (must_pass_in_stack_var_size_or_pad (mode, type))
3383     return true;
3384
3385   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
3386      The layout_type routine is crafty and tries to trick us into passing
3387      currently unsupported vector types on the stack by using TImode.  */
3388   return (!TARGET_64BIT && mode == TImode
3389           && type && TREE_CODE (type) != VECTOR_TYPE);
3390 }
3391
3392 /* Initialize a variable CUM of type CUMULATIVE_ARGS
3393    for a call to a function whose data type is FNTYPE.
3394    For a library call, FNTYPE is 0.  */
3395
3396 void
3397 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
3398                       tree fntype,      /* tree ptr for function decl */
3399                       rtx libname,      /* SYMBOL_REF of library name or 0 */
3400                       tree fndecl)
3401 {
3402   memset (cum, 0, sizeof (*cum));
3403
3404   /* Set up the number of registers to use for passing arguments.  */
3405   cum->nregs = ix86_regparm;
3406   if (TARGET_SSE)
3407     cum->sse_nregs = SSE_REGPARM_MAX;
3408   if (TARGET_MMX)
3409     cum->mmx_nregs = MMX_REGPARM_MAX;
3410   cum->warn_sse = true;
3411   cum->warn_mmx = true;
3412   cum->maybe_vaarg = (fntype
3413                       ? (!prototype_p (fntype) || stdarg_p (fntype))
3414                       : !libname);
3415
3416   if (!TARGET_64BIT)
3417     {
3418       /* If there are variable arguments, then we won't pass anything
3419          in registers in 32-bit mode. */
3420       if (cum->maybe_vaarg)
3421         {
3422           cum->nregs = 0;
3423           cum->sse_nregs = 0;
3424           cum->mmx_nregs = 0;
3425           cum->warn_sse = 0;
3426           cum->warn_mmx = 0;
3427           return;
3428         }
3429
3430       /* Use ecx and edx registers if function has fastcall attribute,
3431          else look for regparm information.  */
3432       if (fntype)
3433         {
3434           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
3435             {
3436               cum->nregs = 2;
3437               cum->fastcall = 1;
3438             }
3439           else
3440             cum->nregs = ix86_function_regparm (fntype, fndecl);
3441         }
3442
3443       /* Set up the number of SSE registers used for passing SFmode
3444          and DFmode arguments.  Warn for mismatching ABI.  */
3445       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl);
3446     }
3447 }
3448
3449 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
3450    But in the case of vector types, it is some vector mode.
3451
3452    When we have only some of our vector isa extensions enabled, then there
3453    are some modes for which vector_mode_supported_p is false.  For these
3454    modes, the generic vector support in gcc will choose some non-vector mode
3455    in order to implement the type.  By computing the natural mode, we'll
3456    select the proper ABI location for the operand and not depend on whatever
3457    the middle-end decides to do with these vector types.  */
3458
3459 static enum machine_mode
3460 type_natural_mode (const_tree type)
3461 {
3462   enum machine_mode mode = TYPE_MODE (type);
3463
3464   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
3465     {
3466       HOST_WIDE_INT size = int_size_in_bytes (type);
3467       if ((size == 8 || size == 16)
3468           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
3469           && TYPE_VECTOR_SUBPARTS (type) > 1)
3470         {
3471           enum machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
3472
3473           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
3474             mode = MIN_MODE_VECTOR_FLOAT;
3475           else
3476             mode = MIN_MODE_VECTOR_INT;
3477
3478           /* Get the mode which has this inner mode and number of units.  */
3479           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
3480             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
3481                 && GET_MODE_INNER (mode) == innermode)
3482               return mode;
3483
3484           gcc_unreachable ();
3485         }
3486     }
3487
3488   return mode;
3489 }
3490
3491 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
3492    this may not agree with the mode that the type system has chosen for the
3493    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
3494    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
3495
3496 static rtx
3497 gen_reg_or_parallel (enum machine_mode mode, enum machine_mode orig_mode,
3498                      unsigned int regno)
3499 {
3500   rtx tmp;
3501
3502   if (orig_mode != BLKmode)
3503     tmp = gen_rtx_REG (orig_mode, regno);
3504   else
3505     {
3506       tmp = gen_rtx_REG (mode, regno);
3507       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
3508       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
3509     }
3510
3511   return tmp;
3512 }
3513
3514 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
3515    of this code is to classify each 8bytes of incoming argument by the register
3516    class and assign registers accordingly.  */
3517
3518 /* Return the union class of CLASS1 and CLASS2.
3519    See the x86-64 PS ABI for details.  */
3520
3521 static enum x86_64_reg_class
3522 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
3523 {
3524   /* Rule #1: If both classes are equal, this is the resulting class.  */
3525   if (class1 == class2)
3526     return class1;
3527
3528   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
3529      the other class.  */
3530   if (class1 == X86_64_NO_CLASS)
3531     return class2;
3532   if (class2 == X86_64_NO_CLASS)
3533     return class1;
3534
3535   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
3536   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
3537     return X86_64_MEMORY_CLASS;
3538
3539   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
3540   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
3541       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
3542     return X86_64_INTEGERSI_CLASS;
3543   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
3544       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
3545     return X86_64_INTEGER_CLASS;
3546
3547   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
3548      MEMORY is used.  */
3549   if (class1 == X86_64_X87_CLASS
3550       || class1 == X86_64_X87UP_CLASS
3551       || class1 == X86_64_COMPLEX_X87_CLASS
3552       || class2 == X86_64_X87_CLASS
3553       || class2 == X86_64_X87UP_CLASS
3554       || class2 == X86_64_COMPLEX_X87_CLASS)
3555     return X86_64_MEMORY_CLASS;
3556
3557   /* Rule #6: Otherwise class SSE is used.  */
3558   return X86_64_SSE_CLASS;
3559 }
3560
3561 /* Classify the argument of type TYPE and mode MODE.
3562    CLASSES will be filled by the register class used to pass each word
3563    of the operand.  The number of words is returned.  In case the parameter
3564    should be passed in memory, 0 is returned. As a special case for zero
3565    sized containers, classes[0] will be NO_CLASS and 1 is returned.
3566
3567    BIT_OFFSET is used internally for handling records and specifies offset
3568    of the offset in bits modulo 256 to avoid overflow cases.
3569
3570    See the x86-64 PS ABI for details.
3571 */
3572
3573 static int
3574 classify_argument (enum machine_mode mode, const_tree type,
3575                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
3576 {
3577   HOST_WIDE_INT bytes =
3578     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
3579   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3580
3581   /* Variable sized entities are always passed/returned in memory.  */
3582   if (bytes < 0)
3583     return 0;
3584
3585   if (mode != VOIDmode
3586       && targetm.calls.must_pass_in_stack (mode, type))
3587     return 0;
3588
3589   if (type && AGGREGATE_TYPE_P (type))
3590     {
3591       int i;
3592       tree field;
3593       enum x86_64_reg_class subclasses[MAX_CLASSES];
3594
3595       /* On x86-64 we pass structures larger than 16 bytes on the stack.  */
3596       if (bytes > 16)
3597         return 0;
3598
3599       for (i = 0; i < words; i++)
3600         classes[i] = X86_64_NO_CLASS;
3601
3602       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
3603          signalize memory class, so handle it as special case.  */
3604       if (!words)
3605         {
3606           classes[0] = X86_64_NO_CLASS;
3607           return 1;
3608         }
3609
3610       /* Classify each field of record and merge classes.  */
3611       switch (TREE_CODE (type))
3612         {
3613         case RECORD_TYPE:
3614           /* And now merge the fields of structure.  */
3615           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3616             {
3617               if (TREE_CODE (field) == FIELD_DECL)
3618                 {
3619                   int num;
3620
3621                   if (TREE_TYPE (field) == error_mark_node)
3622                     continue;
3623
3624                   /* Bitfields are always classified as integer.  Handle them
3625                      early, since later code would consider them to be
3626                      misaligned integers.  */
3627                   if (DECL_BIT_FIELD (field))
3628                     {
3629                       for (i = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
3630                            i < ((int_bit_position (field) + (bit_offset % 64))
3631                                 + tree_low_cst (DECL_SIZE (field), 0)
3632                                 + 63) / 8 / 8; i++)
3633                         classes[i] =
3634                           merge_classes (X86_64_INTEGER_CLASS,
3635                                          classes[i]);
3636                     }
3637                   else
3638                     {
3639                       num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
3640                                                TREE_TYPE (field), subclasses,
3641                                                (int_bit_position (field)
3642                                                 + bit_offset) % 256);
3643                       if (!num)
3644                         return 0;
3645                       for (i = 0; i < num; i++)
3646                         {
3647                           int pos =
3648                             (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
3649                           classes[i + pos] =
3650                             merge_classes (subclasses[i], classes[i + pos]);
3651                         }
3652                     }
3653                 }
3654             }
3655           break;
3656
3657         case ARRAY_TYPE:
3658           /* Arrays are handled as small records.  */
3659           {
3660             int num;
3661             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
3662                                      TREE_TYPE (type), subclasses, bit_offset);
3663             if (!num)
3664               return 0;
3665
3666             /* The partial classes are now full classes.  */
3667             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
3668               subclasses[0] = X86_64_SSE_CLASS;
3669             if (subclasses[0] == X86_64_INTEGERSI_CLASS && bytes != 4)
3670               subclasses[0] = X86_64_INTEGER_CLASS;
3671
3672             for (i = 0; i < words; i++)
3673               classes[i] = subclasses[i % num];
3674
3675             break;
3676           }
3677         case UNION_TYPE:
3678         case QUAL_UNION_TYPE:
3679           /* Unions are similar to RECORD_TYPE but offset is always 0.
3680              */
3681           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3682             {
3683               if (TREE_CODE (field) == FIELD_DECL)
3684                 {
3685                   int num;
3686
3687                   if (TREE_TYPE (field) == error_mark_node)
3688                     continue;
3689
3690                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
3691                                            TREE_TYPE (field), subclasses,
3692                                            bit_offset);
3693                   if (!num)
3694                     return 0;
3695                   for (i = 0; i < num; i++)
3696                     classes[i] = merge_classes (subclasses[i], classes[i]);
3697                 }
3698             }
3699           break;
3700
3701         default:
3702           gcc_unreachable ();
3703         }
3704
3705       /* Final merger cleanup.  */
3706       for (i = 0; i < words; i++)
3707         {
3708           /* If one class is MEMORY, everything should be passed in
3709              memory.  */
3710           if (classes[i] == X86_64_MEMORY_CLASS)
3711             return 0;
3712
3713           /* The X86_64_SSEUP_CLASS should be always preceded by
3714              X86_64_SSE_CLASS.  */
3715           if (classes[i] == X86_64_SSEUP_CLASS
3716               && (i == 0 || classes[i - 1] != X86_64_SSE_CLASS))
3717             classes[i] = X86_64_SSE_CLASS;
3718
3719           /*  X86_64_X87UP_CLASS should be preceded by X86_64_X87_CLASS.  */
3720           if (classes[i] == X86_64_X87UP_CLASS
3721               && (i == 0 || classes[i - 1] != X86_64_X87_CLASS))
3722             classes[i] = X86_64_SSE_CLASS;
3723         }
3724       return words;
3725     }
3726
3727   /* Compute alignment needed.  We align all types to natural boundaries with
3728      exception of XFmode that is aligned to 64bits.  */
3729   if (mode != VOIDmode && mode != BLKmode)
3730     {
3731       int mode_alignment = GET_MODE_BITSIZE (mode);
3732
3733       if (mode == XFmode)
3734         mode_alignment = 128;
3735       else if (mode == XCmode)
3736         mode_alignment = 256;
3737       if (COMPLEX_MODE_P (mode))
3738         mode_alignment /= 2;
3739       /* Misaligned fields are always returned in memory.  */
3740       if (bit_offset % mode_alignment)
3741         return 0;
3742     }
3743
3744   /* for V1xx modes, just use the base mode */
3745   if (VECTOR_MODE_P (mode)
3746       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
3747     mode = GET_MODE_INNER (mode);
3748
3749   /* Classification of atomic types.  */
3750   switch (mode)
3751     {
3752     case SDmode:
3753     case DDmode:
3754       classes[0] = X86_64_SSE_CLASS;
3755       return 1;
3756     case TDmode:
3757       classes[0] = X86_64_SSE_CLASS;
3758       classes[1] = X86_64_SSEUP_CLASS;
3759       return 2;
3760     case DImode:
3761     case SImode:
3762     case HImode:
3763     case QImode:
3764     case CSImode:
3765     case CHImode:
3766     case CQImode:
3767       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
3768         classes[0] = X86_64_INTEGERSI_CLASS;
3769       else
3770         classes[0] = X86_64_INTEGER_CLASS;
3771       return 1;
3772     case CDImode:
3773     case TImode:
3774       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
3775       return 2;
3776     case CTImode:
3777       return 0;
3778     case SFmode:
3779       if (!(bit_offset % 64))
3780         classes[0] = X86_64_SSESF_CLASS;
3781       else
3782         classes[0] = X86_64_SSE_CLASS;
3783       return 1;
3784     case DFmode:
3785       classes[0] = X86_64_SSEDF_CLASS;
3786       return 1;
3787     case XFmode:
3788       classes[0] = X86_64_X87_CLASS;
3789       classes[1] = X86_64_X87UP_CLASS;
3790       return 2;
3791     case TFmode:
3792       classes[0] = X86_64_SSE_CLASS;
3793       classes[1] = X86_64_SSEUP_CLASS;
3794       return 2;
3795     case SCmode:
3796       classes[0] = X86_64_SSE_CLASS;
3797       return 1;
3798     case DCmode:
3799       classes[0] = X86_64_SSEDF_CLASS;
3800       classes[1] = X86_64_SSEDF_CLASS;
3801       return 2;
3802     case XCmode:
3803       classes[0] = X86_64_COMPLEX_X87_CLASS;
3804       return 1;
3805     case TCmode:
3806       /* This modes is larger than 16 bytes.  */
3807       return 0;
3808     case V4SFmode:
3809     case V4SImode:
3810     case V16QImode:
3811     case V8HImode:
3812     case V2DFmode:
3813     case V2DImode:
3814       classes[0] = X86_64_SSE_CLASS;
3815       classes[1] = X86_64_SSEUP_CLASS;
3816       return 2;
3817     case V2SFmode:
3818     case V2SImode:
3819     case V4HImode:
3820     case V8QImode:
3821       classes[0] = X86_64_SSE_CLASS;
3822       return 1;
3823     case BLKmode:
3824     case VOIDmode:
3825       return 0;
3826     default:
3827       gcc_assert (VECTOR_MODE_P (mode));
3828
3829       if (bytes > 16)
3830         return 0;
3831
3832       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
3833
3834       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
3835         classes[0] = X86_64_INTEGERSI_CLASS;
3836       else
3837         classes[0] = X86_64_INTEGER_CLASS;
3838       classes[1] = X86_64_INTEGER_CLASS;
3839       return 1 + (bytes > 8);
3840     }
3841 }
3842
3843 /* Examine the argument and return set number of register required in each
3844    class.  Return 0 iff parameter should be passed in memory.  */
3845 static int
3846 examine_argument (enum machine_mode mode, const_tree type, int in_return,
3847                   int *int_nregs, int *sse_nregs)
3848 {
3849   enum x86_64_reg_class regclass[MAX_CLASSES];
3850   int n = classify_argument (mode, type, regclass, 0);
3851
3852   *int_nregs = 0;
3853   *sse_nregs = 0;
3854   if (!n)
3855     return 0;
3856   for (n--; n >= 0; n--)
3857     switch (regclass[n])
3858       {
3859       case X86_64_INTEGER_CLASS:
3860       case X86_64_INTEGERSI_CLASS:
3861         (*int_nregs)++;
3862         break;
3863       case X86_64_SSE_CLASS:
3864       case X86_64_SSESF_CLASS:
3865       case X86_64_SSEDF_CLASS:
3866         (*sse_nregs)++;
3867         break;
3868       case X86_64_NO_CLASS:
3869       case X86_64_SSEUP_CLASS:
3870         break;
3871       case X86_64_X87_CLASS:
3872       case X86_64_X87UP_CLASS:
3873         if (!in_return)
3874           return 0;
3875         break;
3876       case X86_64_COMPLEX_X87_CLASS:
3877         return in_return ? 2 : 0;
3878       case X86_64_MEMORY_CLASS:
3879         gcc_unreachable ();
3880       }
3881   return 1;
3882 }
3883
3884 /* Construct container for the argument used by GCC interface.  See
3885    FUNCTION_ARG for the detailed description.  */
3886
3887 static rtx
3888 construct_container (enum machine_mode mode, enum machine_mode orig_mode,
3889                      const_tree type, int in_return, int nintregs, int nsseregs,
3890                      const int *intreg, int sse_regno)
3891 {
3892   /* The following variables hold the static issued_error state.  */
3893   static bool issued_sse_arg_error;
3894   static bool issued_sse_ret_error;
3895   static bool issued_x87_ret_error;
3896
3897   enum machine_mode tmpmode;
3898   int bytes =
3899     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
3900   enum x86_64_reg_class regclass[MAX_CLASSES];
3901   int n;
3902   int i;
3903   int nexps = 0;
3904   int needed_sseregs, needed_intregs;
3905   rtx exp[MAX_CLASSES];
3906   rtx ret;
3907
3908   n = classify_argument (mode, type, regclass, 0);
3909   if (!n)
3910     return NULL;
3911   if (!examine_argument (mode, type, in_return, &needed_intregs,
3912                          &needed_sseregs))
3913     return NULL;
3914   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
3915     return NULL;
3916
3917   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
3918      some less clueful developer tries to use floating-point anyway.  */
3919   if (needed_sseregs && !TARGET_SSE)
3920     {
3921       if (in_return)
3922         {
3923           if (!issued_sse_ret_error)
3924             {
3925               error ("SSE register return with SSE disabled");
3926               issued_sse_ret_error = true;
3927             }
3928         }
3929       else if (!issued_sse_arg_error)
3930         {
3931           error ("SSE register argument with SSE disabled");
3932           issued_sse_arg_error = true;
3933         }
3934       return NULL;
3935     }
3936
3937   /* Likewise, error if the ABI requires us to return values in the
3938      x87 registers and the user specified -mno-80387.  */
3939   if (!TARGET_80387 && in_return)
3940     for (i = 0; i < n; i++)
3941       if (regclass[i] == X86_64_X87_CLASS
3942           || regclass[i] == X86_64_X87UP_CLASS
3943           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
3944         {
3945           if (!issued_x87_ret_error)
3946             {
3947               error ("x87 register return with x87 disabled");
3948               issued_x87_ret_error = true;
3949             }
3950           return NULL;
3951         }
3952
3953   /* First construct simple cases.  Avoid SCmode, since we want to use
3954      single register to pass this type.  */
3955   if (n == 1 && mode != SCmode)
3956     switch (regclass[0])
3957       {
3958       case X86_64_INTEGER_CLASS:
3959       case X86_64_INTEGERSI_CLASS:
3960         return gen_rtx_REG (mode, intreg[0]);
3961       case X86_64_SSE_CLASS:
3962       case X86_64_SSESF_CLASS:
3963       case X86_64_SSEDF_CLASS:
3964         return gen_reg_or_parallel (mode, orig_mode, SSE_REGNO (sse_regno));
3965       case X86_64_X87_CLASS:
3966       case X86_64_COMPLEX_X87_CLASS:
3967         return gen_rtx_REG (mode, FIRST_STACK_REG);
3968       case X86_64_NO_CLASS:
3969         /* Zero sized array, struct or class.  */
3970         return NULL;
3971       default:
3972         gcc_unreachable ();
3973       }
3974   if (n == 2 && regclass[0] == X86_64_SSE_CLASS
3975       && regclass[1] == X86_64_SSEUP_CLASS && mode != BLKmode)
3976     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
3977
3978   if (n == 2
3979       && regclass[0] == X86_64_X87_CLASS && regclass[1] == X86_64_X87UP_CLASS)
3980     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
3981   if (n == 2 && regclass[0] == X86_64_INTEGER_CLASS
3982       && regclass[1] == X86_64_INTEGER_CLASS
3983       && (mode == CDImode || mode == TImode || mode == TFmode)
3984       && intreg[0] + 1 == intreg[1])
3985     return gen_rtx_REG (mode, intreg[0]);
3986
3987   /* Otherwise figure out the entries of the PARALLEL.  */
3988   for (i = 0; i < n; i++)
3989     {
3990       switch (regclass[i])
3991         {
3992           case X86_64_NO_CLASS:
3993             break;
3994           case X86_64_INTEGER_CLASS:
3995           case X86_64_INTEGERSI_CLASS:
3996             /* Merge TImodes on aligned occasions here too.  */
3997             if (i * 8 + 8 > bytes)
3998               tmpmode = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
3999             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
4000               tmpmode = SImode;
4001             else
4002               tmpmode = DImode;
4003             /* We've requested 24 bytes we don't have mode for.  Use DImode.  */
4004             if (tmpmode == BLKmode)
4005               tmpmode = DImode;
4006             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
4007                                                gen_rtx_REG (tmpmode, *intreg),
4008                                                GEN_INT (i*8));
4009             intreg++;
4010             break;
4011           case X86_64_SSESF_CLASS:
4012             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
4013                                                gen_rtx_REG (SFmode,
4014                                                             SSE_REGNO (sse_regno)),
4015                                                GEN_INT (i*8));
4016             sse_regno++;
4017             break;
4018           case X86_64_SSEDF_CLASS:
4019             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
4020                                                gen_rtx_REG (DFmode,
4021                                                             SSE_REGNO (sse_regno)),
4022                                                GEN_INT (i*8));
4023             sse_regno++;
4024             break;
4025           case X86_64_SSE_CLASS:
4026             if (i < n - 1 && regclass[i + 1] == X86_64_SSEUP_CLASS)
4027               tmpmode = TImode;
4028             else
4029               tmpmode = DImode;
4030             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
4031                                                gen_rtx_REG (tmpmode,
4032                                                             SSE_REGNO (sse_regno)),
4033                                                GEN_INT (i*8));
4034             if (tmpmode == TImode)
4035               i++;
4036             sse_regno++;
4037             break;
4038           default:
4039             gcc_unreachable ();
4040         }
4041     }
4042
4043   /* Empty aligned struct, union or class.  */
4044   if (nexps == 0)
4045     return NULL;
4046
4047   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
4048   for (i = 0; i < nexps; i++)
4049     XVECEXP (ret, 0, i) = exp [i];
4050   return ret;
4051 }
4052
4053 /* Update the data in CUM to advance over an argument of mode MODE
4054    and data type TYPE.  (TYPE is null for libcalls where that information
4055    may not be available.)  */
4056
4057 static void
4058 function_arg_advance_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4059                          tree type, HOST_WIDE_INT bytes, HOST_WIDE_INT words)
4060 {
4061   switch (mode)
4062     {
4063     default:
4064       break;
4065
4066     case BLKmode:
4067       if (bytes < 0)
4068         break;
4069       /* FALLTHRU */
4070
4071     case DImode:
4072     case SImode:
4073     case HImode:
4074     case QImode:
4075       cum->words += words;
4076       cum->nregs -= words;
4077       cum->regno += words;
4078
4079       if (cum->nregs <= 0)
4080         {
4081           cum->nregs = 0;
4082           cum->regno = 0;
4083         }
4084       break;
4085
4086     case DFmode:
4087       if (cum->float_in_sse < 2)
4088         break;
4089     case SFmode:
4090       if (cum->float_in_sse < 1)
4091         break;
4092       /* FALLTHRU */
4093
4094     case TImode:
4095     case V16QImode:
4096     case V8HImode:
4097     case V4SImode:
4098     case V2DImode:
4099     case V4SFmode:
4100     case V2DFmode:
4101       if (!type || !AGGREGATE_TYPE_P (type))
4102         {
4103           cum->sse_words += words;
4104           cum->sse_nregs -= 1;
4105           cum->sse_regno += 1;
4106           if (cum->sse_nregs <= 0)
4107             {
4108               cum->sse_nregs = 0;
4109               cum->sse_regno = 0;
4110             }
4111         }
4112       break;
4113
4114     case V8QImode:
4115     case V4HImode:
4116     case V2SImode:
4117     case V2SFmode:
4118       if (!type || !AGGREGATE_TYPE_P (type))
4119         {
4120           cum->mmx_words += words;
4121           cum->mmx_nregs -= 1;
4122           cum->mmx_regno += 1;
4123           if (cum->mmx_nregs <= 0)
4124             {
4125               cum->mmx_nregs = 0;
4126               cum->mmx_regno = 0;
4127             }
4128         }
4129       break;
4130     }
4131 }
4132
4133 static void
4134 function_arg_advance_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4135                          tree type, HOST_WIDE_INT words)
4136 {
4137   int int_nregs, sse_nregs;
4138
4139   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs))
4140     cum->words += words;
4141   else if (sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
4142     {
4143       cum->nregs -= int_nregs;
4144       cum->sse_nregs -= sse_nregs;
4145       cum->regno += int_nregs;
4146       cum->sse_regno += sse_nregs;
4147     }
4148   else
4149     cum->words += words;
4150 }
4151
4152 static void
4153 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
4154                             HOST_WIDE_INT words)
4155 {
4156   /* Otherwise, this should be passed indirect.  */
4157   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
4158
4159   cum->words += words;
4160   if (cum->nregs > 0)
4161     {
4162       cum->nregs -= 1;
4163       cum->regno += 1;
4164     }
4165 }
4166
4167 void
4168 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4169                       tree type, int named ATTRIBUTE_UNUSED)
4170 {
4171   HOST_WIDE_INT bytes, words;
4172
4173   if (mode == BLKmode)
4174     bytes = int_size_in_bytes (type);
4175   else
4176     bytes = GET_MODE_SIZE (mode);
4177   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4178
4179   if (type)
4180     mode = type_natural_mode (type);
4181
4182   if (TARGET_64BIT_MS_ABI)
4183     function_arg_advance_ms_64 (cum, bytes, words);
4184   else if (TARGET_64BIT)
4185     function_arg_advance_64 (cum, mode, type, words);
4186   else
4187     function_arg_advance_32 (cum, mode, type, bytes, words);
4188 }
4189
4190 /* Define where to put the arguments to a function.
4191    Value is zero to push the argument on the stack,
4192    or a hard register in which to store the argument.
4193
4194    MODE is the argument's machine mode.
4195    TYPE is the data type of the argument (as a tree).
4196     This is null for libcalls where that information may
4197     not be available.
4198    CUM is a variable of type CUMULATIVE_ARGS which gives info about
4199     the preceding args and about the function being called.
4200    NAMED is nonzero if this argument is a named parameter
4201     (otherwise it is an extra parameter matching an ellipsis).  */
4202
4203 static rtx
4204 function_arg_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4205                  enum machine_mode orig_mode, tree type,
4206                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
4207 {
4208   static bool warnedsse, warnedmmx;
4209
4210   /* Avoid the AL settings for the Unix64 ABI.  */
4211   if (mode == VOIDmode)
4212     return constm1_rtx;
4213
4214   switch (mode)
4215     {
4216     default:
4217       break;
4218
4219     case BLKmode:
4220       if (bytes < 0)
4221         break;
4222       /* FALLTHRU */
4223     case DImode:
4224     case SImode:
4225     case HImode:
4226     case QImode:
4227       if (words <= cum->nregs)
4228         {
4229           int regno = cum->regno;
4230
4231           /* Fastcall allocates the first two DWORD (SImode) or
4232              smaller arguments to ECX and EDX.  */
4233           if (cum->fastcall)
4234             {
4235               if (mode == BLKmode || mode == DImode)
4236                 break;
4237
4238               /* ECX not EAX is the first allocated register.  */
4239               if (regno == AX_REG)
4240                 regno = CX_REG;
4241             }
4242           return gen_rtx_REG (mode, regno);
4243         }
4244       break;
4245
4246     case DFmode:
4247       if (cum->float_in_sse < 2)
4248         break;
4249     case SFmode:
4250       if (cum->float_in_sse < 1)
4251         break;
4252       /* FALLTHRU */
4253     case TImode:
4254     case V16QImode:
4255     case V8HImode:
4256     case V4SImode:
4257     case V2DImode:
4258     case V4SFmode:
4259     case V2DFmode:
4260       if (!type || !AGGREGATE_TYPE_P (type))
4261         {
4262           if (!TARGET_SSE && !warnedsse && cum->warn_sse)
4263             {
4264               warnedsse = true;
4265               warning (0, "SSE vector argument without SSE enabled "
4266                        "changes the ABI");
4267             }
4268           if (cum->sse_nregs)
4269             return gen_reg_or_parallel (mode, orig_mode,
4270                                         cum->sse_regno + FIRST_SSE_REG);
4271         }
4272       break;
4273
4274     case V8QImode:
4275     case V4HImode:
4276     case V2SImode:
4277     case V2SFmode:
4278       if (!type || !AGGREGATE_TYPE_P (type))
4279         {
4280           if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
4281             {
4282               warnedmmx = true;
4283               warning (0, "MMX vector argument without MMX enabled "
4284                        "changes the ABI");
4285             }
4286           if (cum->mmx_nregs)
4287             return gen_reg_or_parallel (mode, orig_mode,
4288                                         cum->mmx_regno + FIRST_MMX_REG);
4289         }
4290       break;
4291     }
4292
4293   return NULL_RTX;
4294 }
4295
4296 static rtx
4297 function_arg_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4298                  enum machine_mode orig_mode, tree type)
4299 {
4300   /* Handle a hidden AL argument containing number of registers
4301      for varargs x86-64 functions.  */
4302   if (mode == VOIDmode)
4303     return GEN_INT (cum->maybe_vaarg
4304                     ? (cum->sse_nregs < 0
4305                        ? SSE_REGPARM_MAX
4306                        : cum->sse_regno)
4307                     : -1);
4308
4309   return construct_container (mode, orig_mode, type, 0, cum->nregs,
4310                               cum->sse_nregs,
4311                               &x86_64_int_parameter_registers [cum->regno],
4312                               cum->sse_regno);
4313 }
4314
4315 static rtx
4316 function_arg_ms_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4317                     enum machine_mode orig_mode, int named)
4318 {
4319   unsigned int regno;
4320
4321   /* Avoid the AL settings for the Unix64 ABI.  */
4322   if (mode == VOIDmode)
4323     return constm1_rtx;
4324
4325   /* If we've run out of registers, it goes on the stack.  */
4326   if (cum->nregs == 0)
4327     return NULL_RTX;
4328
4329   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
4330
4331   /* Only floating point modes are passed in anything but integer regs.  */
4332   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
4333     {
4334       if (named)
4335         regno = cum->regno + FIRST_SSE_REG;
4336       else
4337         {
4338           rtx t1, t2;
4339
4340           /* Unnamed floating parameters are passed in both the
4341              SSE and integer registers.  */
4342           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
4343           t2 = gen_rtx_REG (mode, regno);
4344           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
4345           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
4346           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
4347         }
4348     }
4349
4350   return gen_reg_or_parallel (mode, orig_mode, regno);
4351 }
4352
4353 rtx
4354 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
4355               tree type, int named)
4356 {
4357   enum machine_mode mode = omode;
4358   HOST_WIDE_INT bytes, words;
4359
4360   if (mode == BLKmode)
4361     bytes = int_size_in_bytes (type);
4362   else
4363     bytes = GET_MODE_SIZE (mode);
4364   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4365
4366   /* To simplify the code below, represent vector types with a vector mode
4367      even if MMX/SSE are not active.  */
4368   if (type && TREE_CODE (type) == VECTOR_TYPE)
4369     mode = type_natural_mode (type);
4370
4371   if (TARGET_64BIT_MS_ABI)
4372     return function_arg_ms_64 (cum, mode, omode, named);
4373   else if (TARGET_64BIT)
4374     return function_arg_64 (cum, mode, omode, type);
4375   else
4376     return function_arg_32 (cum, mode, omode, type, bytes, words);
4377 }
4378
4379 /* A C expression that indicates when an argument must be passed by
4380    reference.  If nonzero for an argument, a copy of that argument is
4381    made in memory and a pointer to the argument is passed instead of
4382    the argument itself.  The pointer is passed in whatever way is
4383    appropriate for passing a pointer to that type.  */
4384
4385 static bool
4386 ix86_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
4387                         enum machine_mode mode ATTRIBUTE_UNUSED,
4388                         const_tree type, bool named ATTRIBUTE_UNUSED)
4389 {
4390   if (TARGET_64BIT_MS_ABI)
4391     {
4392       if (type)
4393         {
4394           /* Arrays are passed by reference.  */
4395           if (TREE_CODE (type) == ARRAY_TYPE)
4396             return true;
4397
4398           if (AGGREGATE_TYPE_P (type))
4399             {
4400               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
4401                  are passed by reference.  */
4402               int el2 = exact_log2 (int_size_in_bytes (type));
4403               return !(el2 >= 0 && el2 <= 3);
4404             }
4405         }
4406
4407       /* __m128 is passed by reference.  */
4408       /* ??? How to handle complex?  For now treat them as structs,
4409          and pass them by reference if they're too large.  */
4410       if (GET_MODE_SIZE (mode) > 8)
4411         return true;
4412     }
4413   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
4414     return 1;
4415
4416   return 0;
4417 }
4418
4419 /* Return true when TYPE should be 128bit aligned for 32bit argument passing
4420    ABI.  Only called if TARGET_SSE.  */
4421 static bool
4422 contains_128bit_aligned_vector_p (tree type)
4423 {
4424   enum machine_mode mode = TYPE_MODE (type);
4425   if (SSE_REG_MODE_P (mode)
4426       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
4427     return true;
4428   if (TYPE_ALIGN (type) < 128)
4429     return false;
4430
4431   if (AGGREGATE_TYPE_P (type))
4432     {
4433       /* Walk the aggregates recursively.  */
4434       switch (TREE_CODE (type))
4435         {
4436         case RECORD_TYPE:
4437         case UNION_TYPE:
4438         case QUAL_UNION_TYPE:
4439           {
4440             tree field;
4441
4442             /* Walk all the structure fields.  */
4443             for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4444               {
4445                 if (TREE_CODE (field) == FIELD_DECL
4446                     && contains_128bit_aligned_vector_p (TREE_TYPE (field)))
4447                   return true;
4448               }
4449             break;
4450           }
4451
4452         case ARRAY_TYPE:
4453           /* Just for use if some languages passes arrays by value.  */
4454           if (contains_128bit_aligned_vector_p (TREE_TYPE (type)))
4455             return true;
4456           break;
4457
4458         default:
4459           gcc_unreachable ();
4460         }
4461     }
4462   return false;
4463 }
4464
4465 /* Gives the alignment boundary, in bits, of an argument with the
4466    specified mode and type.  */
4467
4468 int
4469 ix86_function_arg_boundary (enum machine_mode mode, tree type)
4470 {
4471   int align;
4472   if (type)
4473     align = TYPE_ALIGN (type);
4474   else
4475     align = GET_MODE_ALIGNMENT (mode);
4476   if (align < PARM_BOUNDARY)
4477     align = PARM_BOUNDARY;
4478   if (!TARGET_64BIT)
4479     {
4480       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
4481          make an exception for SSE modes since these require 128bit
4482          alignment.
4483
4484          The handling here differs from field_alignment.  ICC aligns MMX
4485          arguments to 4 byte boundaries, while structure fields are aligned
4486          to 8 byte boundaries.  */
4487       if (!TARGET_SSE)
4488         align = PARM_BOUNDARY;
4489       else if (!type)
4490         {
4491           if (!SSE_REG_MODE_P (mode))
4492             align = PARM_BOUNDARY;
4493         }
4494       else
4495         {
4496           if (!contains_128bit_aligned_vector_p (type))
4497             align = PARM_BOUNDARY;
4498         }
4499     }
4500   if (align > 128)
4501     align = 128;
4502   return align;
4503 }
4504
4505 /* Return true if N is a possible register number of function value.  */
4506
4507 bool
4508 ix86_function_value_regno_p (int regno)
4509 {
4510   switch (regno)
4511     {
4512     case 0:
4513       return true;
4514
4515     case FIRST_FLOAT_REG:
4516       if (TARGET_64BIT_MS_ABI)
4517         return false;
4518       return TARGET_FLOAT_RETURNS_IN_80387;
4519
4520     case FIRST_SSE_REG:
4521       return TARGET_SSE;
4522
4523     case FIRST_MMX_REG:
4524       if (TARGET_MACHO || TARGET_64BIT)
4525         return false;
4526       return TARGET_MMX;
4527     }
4528
4529   return false;
4530 }
4531
4532 /* Define how to find the value returned by a function.
4533    VALTYPE is the data type of the value (as a tree).
4534    If the precise function being called is known, FUNC is its FUNCTION_DECL;
4535    otherwise, FUNC is 0.  */
4536
4537 static rtx
4538 function_value_32 (enum machine_mode orig_mode, enum machine_mode mode,
4539                    const_tree fntype, const_tree fn)
4540 {
4541   unsigned int regno;
4542
4543   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
4544      we normally prevent this case when mmx is not available.  However
4545      some ABIs may require the result to be returned like DImode.  */
4546   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
4547     regno = TARGET_MMX ? FIRST_MMX_REG : 0;
4548
4549   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
4550      we prevent this case when sse is not available.  However some ABIs
4551      may require the result to be returned like integer TImode.  */
4552   else if (mode == TImode
4553            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
4554     regno = TARGET_SSE ? FIRST_SSE_REG : 0;
4555
4556   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
4557   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
4558     regno = FIRST_FLOAT_REG;
4559   else
4560     /* Most things go in %eax.  */
4561     regno = AX_REG;
4562
4563   /* Override FP return register with %xmm0 for local functions when
4564      SSE math is enabled or for functions with sseregparm attribute.  */
4565   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
4566     {
4567       int sse_level = ix86_function_sseregparm (fntype, fn);
4568       if ((sse_level >= 1 && mode == SFmode)
4569           || (sse_level == 2 && mode == DFmode))
4570         regno = FIRST_SSE_REG;
4571     }
4572
4573   return gen_rtx_REG (orig_mode, regno);
4574 }
4575
4576 static rtx
4577 function_value_64 (enum machine_mode orig_mode, enum machine_mode mode,
4578                    const_tree valtype)
4579 {
4580   rtx ret;
4581
4582   /* Handle libcalls, which don't provide a type node.  */
4583   if (valtype == NULL)
4584     {
4585       switch (mode)
4586         {
4587         case SFmode:
4588         case SCmode:
4589         case DFmode:
4590         case DCmode:
4591         case TFmode:
4592         case SDmode:
4593         case DDmode:
4594         case TDmode:
4595           return gen_rtx_REG (mode, FIRST_SSE_REG);
4596         case XFmode:
4597         case XCmode:
4598           return gen_rtx_REG (mode, FIRST_FLOAT_REG);
4599         case TCmode:
4600           return NULL;
4601         default:
4602           return gen_rtx_REG (mode, AX_REG);
4603         }
4604     }
4605
4606   ret = construct_container (mode, orig_mode, valtype, 1,
4607                              REGPARM_MAX, SSE_REGPARM_MAX,
4608                              x86_64_int_return_registers, 0);
4609
4610   /* For zero sized structures, construct_container returns NULL, but we
4611      need to keep rest of compiler happy by returning meaningful value.  */
4612   if (!ret)
4613     ret = gen_rtx_REG (orig_mode, AX_REG);
4614
4615   return ret;
4616 }
4617
4618 static rtx
4619 function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
4620 {
4621   unsigned int regno = AX_REG;
4622
4623   if (TARGET_SSE)
4624     {
4625       if (mode == SFmode || mode == DFmode)
4626         regno = FIRST_SSE_REG;
4627       else if (VECTOR_MODE_P (mode) || GET_MODE_SIZE (mode) == 16)
4628         regno = FIRST_SSE_REG;
4629     }
4630
4631   return gen_rtx_REG (orig_mode, regno);
4632 }
4633
4634 static rtx
4635 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
4636                        enum machine_mode orig_mode, enum machine_mode mode)
4637 {
4638   const_tree fn, fntype;
4639
4640   fn = NULL_TREE;
4641   if (fntype_or_decl && DECL_P (fntype_or_decl))
4642     fn = fntype_or_decl;
4643   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
4644
4645   if (TARGET_64BIT_MS_ABI)
4646     return function_value_ms_64 (orig_mode, mode);
4647   else if (TARGET_64BIT)
4648     return function_value_64 (orig_mode, mode, valtype);
4649   else
4650     return function_value_32 (orig_mode, mode, fntype, fn);
4651 }
4652
4653 static rtx
4654 ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
4655                      bool outgoing ATTRIBUTE_UNUSED)
4656 {
4657   enum machine_mode mode, orig_mode;
4658
4659   orig_mode = TYPE_MODE (valtype);
4660   mode = type_natural_mode (valtype);
4661   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
4662 }
4663
4664 rtx
4665 ix86_libcall_value (enum machine_mode mode)
4666 {
4667   return ix86_function_value_1 (NULL, NULL, mode, mode);
4668 }
4669
4670 /* Return true iff type is returned in memory.  */
4671
4672 static int
4673 return_in_memory_32 (const_tree type, enum machine_mode mode)
4674 {
4675   HOST_WIDE_INT size;
4676
4677   if (mode == BLKmode)
4678     return 1;
4679
4680   size = int_size_in_bytes (type);
4681
4682   if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
4683     return 0;
4684
4685   if (VECTOR_MODE_P (mode) || mode == TImode)
4686     {
4687       /* User-created vectors small enough to fit in EAX.  */
4688       if (size < 8)
4689         return 0;
4690
4691       /* MMX/3dNow values are returned in MM0,
4692          except when it doesn't exits.  */
4693       if (size == 8)
4694         return (TARGET_MMX ? 0 : 1);
4695
4696       /* SSE values are returned in XMM0, except when it doesn't exist.  */
4697       if (size == 16)
4698         return (TARGET_SSE ? 0 : 1);
4699     }
4700
4701   if (mode == XFmode)
4702     return 0;
4703
4704   if (mode == TDmode)
4705     return 1;
4706
4707   if (size > 12)
4708     return 1;
4709   return 0;
4710 }
4711
4712 static int
4713 return_in_memory_64 (const_tree type, enum machine_mode mode)
4714 {
4715   int needed_intregs, needed_sseregs;
4716   return !examine_argument (mode, type, 1, &needed_intregs, &needed_sseregs);
4717 }
4718
4719 static int
4720 return_in_memory_ms_64 (const_tree type, enum machine_mode mode)
4721 {
4722   HOST_WIDE_INT size = int_size_in_bytes (type);
4723
4724   /* __m128 and friends are returned in xmm0.  */
4725   if (!COMPLEX_MODE_P (mode) && size == 16 && VECTOR_MODE_P (mode))
4726     return 0;
4727
4728   /* Otherwise, the size must be exactly in [1248]. But not for complex. */
4729   return (size != 1 && size != 2 && size != 4 && size != 8)
4730          || COMPLEX_MODE_P (mode);
4731 }
4732
4733 int
4734 ix86_return_in_memory (const_tree type)
4735 {
4736   const enum machine_mode mode = type_natural_mode (type);
4737
4738   if (TARGET_64BIT_MS_ABI)
4739     return return_in_memory_ms_64 (type, mode);
4740   else if (TARGET_64BIT)
4741     return return_in_memory_64 (type, mode);
4742   else
4743     return return_in_memory_32 (type, mode);
4744 }
4745
4746 /* Return false iff TYPE is returned in memory.  This version is used
4747    on Solaris 10.  It is similar to the generic ix86_return_in_memory,
4748    but differs notably in that when MMX is available, 8-byte vectors
4749    are returned in memory, rather than in MMX registers.  */
4750
4751 int
4752 ix86_sol10_return_in_memory (const_tree type)
4753 {
4754   int size;
4755   enum machine_mode mode = type_natural_mode (type);
4756
4757   if (TARGET_64BIT)
4758     return return_in_memory_64 (type, mode);
4759
4760   if (mode == BLKmode)
4761     return 1;
4762
4763   size = int_size_in_bytes (type);
4764
4765   if (VECTOR_MODE_P (mode))
4766     {
4767       /* Return in memory only if MMX registers *are* available.  This
4768          seems backwards, but it is consistent with the existing
4769          Solaris x86 ABI.  */
4770       if (size == 8)
4771         return TARGET_MMX;
4772       if (size == 16)
4773         return !TARGET_SSE;
4774     }
4775   else if (mode == TImode)
4776     return !TARGET_SSE;
4777   else if (mode == XFmode)
4778     return 0;
4779
4780   return size > 12;
4781 }
4782
4783 /* When returning SSE vector types, we have a choice of either
4784      (1) being abi incompatible with a -march switch, or
4785      (2) generating an error.
4786    Given no good solution, I think the safest thing is one warning.
4787    The user won't be able to use -Werror, but....
4788
4789    Choose the STRUCT_VALUE_RTX hook because that's (at present) only
4790    called in response to actually generating a caller or callee that
4791    uses such a type.  As opposed to RETURN_IN_MEMORY, which is called
4792    via aggregate_value_p for general type probing from tree-ssa.  */
4793
4794 static rtx
4795 ix86_struct_value_rtx (tree type, int incoming ATTRIBUTE_UNUSED)
4796 {
4797   static bool warnedsse, warnedmmx;
4798
4799   if (!TARGET_64BIT && type)
4800     {
4801       /* Look at the return type of the function, not the function type.  */
4802       enum machine_mode mode = TYPE_MODE (TREE_TYPE (type));
4803
4804       if (!TARGET_SSE && !warnedsse)
4805         {
4806           if (mode == TImode
4807               || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
4808             {
4809               warnedsse = true;
4810               warning (0, "SSE vector return without SSE enabled "
4811                        "changes the ABI");
4812             }
4813         }
4814
4815       if (!TARGET_MMX && !warnedmmx)
4816         {
4817           if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
4818             {
4819               warnedmmx = true;
4820               warning (0, "MMX vector return without MMX enabled "
4821                        "changes the ABI");
4822             }
4823         }
4824     }
4825
4826   return NULL;
4827 }
4828
4829 \f
4830 /* Create the va_list data type.  */
4831
4832 static tree
4833 ix86_build_builtin_va_list (void)
4834 {
4835   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
4836
4837   /* For i386 we use plain pointer to argument area.  */
4838   if (!TARGET_64BIT || TARGET_64BIT_MS_ABI)
4839     return build_pointer_type (char_type_node);
4840
4841   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
4842   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
4843
4844   f_gpr = build_decl (FIELD_DECL, get_identifier ("gp_offset"),
4845                       unsigned_type_node);
4846   f_fpr = build_decl (FIELD_DECL, get_identifier ("fp_offset"),
4847                       unsigned_type_node);
4848   f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4849                       ptr_type_node);
4850   f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4851                       ptr_type_node);
4852
4853   va_list_gpr_counter_field = f_gpr;
4854   va_list_fpr_counter_field = f_fpr;
4855
4856   DECL_FIELD_CONTEXT (f_gpr) = record;
4857   DECL_FIELD_CONTEXT (f_fpr) = record;
4858   DECL_FIELD_CONTEXT (f_ovf) = record;
4859   DECL_FIELD_CONTEXT (f_sav) = record;
4860
4861   TREE_CHAIN (record) = type_decl;
4862   TYPE_NAME (record) = type_decl;
4863   TYPE_FIELDS (record) = f_gpr;
4864   TREE_CHAIN (f_gpr) = f_fpr;
4865   TREE_CHAIN (f_fpr) = f_ovf;
4866   TREE_CHAIN (f_ovf) = f_sav;
4867
4868   layout_type (record);
4869
4870   /* The correct type is an array type of one element.  */
4871   return build_array_type (record, build_index_type (size_zero_node));
4872 }
4873
4874 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
4875
4876 static void
4877 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
4878 {
4879   rtx save_area, mem;
4880   rtx label;
4881   rtx label_ref;
4882   rtx tmp_reg;
4883   rtx nsse_reg;
4884   alias_set_type set;
4885   int i;
4886
4887   if (! cfun->va_list_gpr_size && ! cfun->va_list_fpr_size)
4888     return;
4889
4890   /* Indicate to allocate space on the stack for varargs save area.  */
4891   ix86_save_varrargs_registers = 1;
4892   /* We need 16-byte stack alignment to save SSE registers.  If user
4893      asked for lower preferred_stack_boundary, lets just hope that he knows
4894      what he is doing and won't varargs SSE values.
4895
4896      We also may end up assuming that only 64bit values are stored in SSE
4897      register let some floating point program work.  */
4898   if (ix86_preferred_stack_boundary >= 128)
4899     cfun->stack_alignment_needed = 128;
4900
4901   save_area = frame_pointer_rtx;
4902   set = get_varargs_alias_set ();
4903
4904   for (i = cum->regno;
4905        i < ix86_regparm
4906        && i < cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
4907        i++)
4908     {
4909       mem = gen_rtx_MEM (Pmode,
4910                          plus_constant (save_area, i * UNITS_PER_WORD));
4911       MEM_NOTRAP_P (mem) = 1;
4912       set_mem_alias_set (mem, set);
4913       emit_move_insn (mem, gen_rtx_REG (Pmode,
4914                                         x86_64_int_parameter_registers[i]));
4915     }
4916
4917   if (cum->sse_nregs && cfun->va_list_fpr_size)
4918     {
4919       /* Now emit code to save SSE registers.  The AX parameter contains number
4920          of SSE parameter registers used to call this function.  We use
4921          sse_prologue_save insn template that produces computed jump across
4922          SSE saves.  We need some preparation work to get this working.  */
4923
4924       label = gen_label_rtx ();
4925       label_ref = gen_rtx_LABEL_REF (Pmode, label);
4926
4927       /* Compute address to jump to :
4928          label - 5*eax + nnamed_sse_arguments*5  */
4929       tmp_reg = gen_reg_rtx (Pmode);
4930       nsse_reg = gen_reg_rtx (Pmode);
4931       emit_insn (gen_zero_extendqidi2 (nsse_reg, gen_rtx_REG (QImode, AX_REG)));
4932       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
4933                               gen_rtx_MULT (Pmode, nsse_reg,
4934                                             GEN_INT (4))));
4935       if (cum->sse_regno)
4936         emit_move_insn
4937           (nsse_reg,
4938            gen_rtx_CONST (DImode,
4939                           gen_rtx_PLUS (DImode,
4940                                         label_ref,
4941                                         GEN_INT (cum->sse_regno * 4))));
4942       else
4943         emit_move_insn (nsse_reg, label_ref);
4944       emit_insn (gen_subdi3 (nsse_reg, nsse_reg, tmp_reg));
4945
4946       /* Compute address of memory block we save into.  We always use pointer
4947          pointing 127 bytes after first byte to store - this is needed to keep
4948          instruction size limited by 4 bytes.  */
4949       tmp_reg = gen_reg_rtx (Pmode);
4950       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
4951                               plus_constant (save_area,
4952                                              8 * REGPARM_MAX + 127)));
4953       mem = gen_rtx_MEM (BLKmode, plus_constant (tmp_reg, -127));
4954       MEM_NOTRAP_P (mem) = 1;
4955       set_mem_alias_set (mem, set);
4956       set_mem_align (mem, BITS_PER_WORD);
4957
4958       /* And finally do the dirty job!  */
4959       emit_insn (gen_sse_prologue_save (mem, nsse_reg,
4960                                         GEN_INT (cum->sse_regno), label));
4961     }
4962 }
4963
4964 static void
4965 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
4966 {
4967   alias_set_type set = get_varargs_alias_set ();
4968   int i;
4969
4970   for (i = cum->regno; i < REGPARM_MAX; i++)
4971     {
4972       rtx reg, mem;
4973
4974       mem = gen_rtx_MEM (Pmode,
4975                          plus_constant (virtual_incoming_args_rtx,
4976                                         i * UNITS_PER_WORD));
4977       MEM_NOTRAP_P (mem) = 1;
4978       set_mem_alias_set (mem, set);
4979
4980       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
4981       emit_move_insn (mem, reg);
4982     }
4983 }
4984
4985 static void
4986 ix86_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4987                              tree type, int *pretend_size ATTRIBUTE_UNUSED,
4988                              int no_rtl)
4989 {
4990   CUMULATIVE_ARGS next_cum;
4991   tree fntype;
4992
4993   /* This argument doesn't appear to be used anymore.  Which is good,
4994      because the old code here didn't suppress rtl generation.  */
4995   gcc_assert (!no_rtl);
4996
4997   if (!TARGET_64BIT)
4998     return;
4999
5000   fntype = TREE_TYPE (current_function_decl);
5001
5002   /* For varargs, we do not want to skip the dummy va_dcl argument.
5003      For stdargs, we do want to skip the last named argument.  */
5004   next_cum = *cum;
5005   if (stdarg_p (fntype))
5006     function_arg_advance (&next_cum, mode, type, 1);
5007
5008   if (TARGET_64BIT_MS_ABI)
5009     setup_incoming_varargs_ms_64 (&next_cum);
5010   else
5011     setup_incoming_varargs_64 (&next_cum);
5012 }
5013
5014 /* Implement va_start.  */
5015
5016 void
5017 ix86_va_start (tree valist, rtx nextarg)
5018 {
5019   HOST_WIDE_INT words, n_gpr, n_fpr;
5020   tree f_gpr, f_fpr, f_ovf, f_sav;
5021   tree gpr, fpr, ovf, sav, t;
5022   tree type;
5023
5024   /* Only 64bit target needs something special.  */
5025   if (!TARGET_64BIT || TARGET_64BIT_MS_ABI)
5026     {
5027       std_expand_builtin_va_start (valist, nextarg);
5028       return;
5029     }
5030
5031   f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
5032   f_fpr = TREE_CHAIN (f_gpr);
5033   f_ovf = TREE_CHAIN (f_fpr);
5034   f_sav = TREE_CHAIN (f_ovf);
5035
5036   valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
5037   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5038   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5039   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5040   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
5041
5042   /* Count number of gp and fp argument registers used.  */
5043   words = current_function_args_info.words;
5044   n_gpr = current_function_args_info.regno;
5045   n_fpr = current_function_args_info.sse_regno;
5046
5047   if (cfun->va_list_gpr_size)
5048     {
5049       type = TREE_TYPE (gpr);
5050       t = build2 (GIMPLE_MODIFY_STMT, type, gpr,
5051                   build_int_cst (type, n_gpr * 8));
5052       TREE_SIDE_EFFECTS (t) = 1;
5053       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5054     }
5055
5056   if (cfun->va_list_fpr_size)
5057     {
5058       type = TREE_TYPE (fpr);
5059       t = build2 (GIMPLE_MODIFY_STMT, type, fpr,
5060                   build_int_cst (type, n_fpr * 16 + 8*REGPARM_MAX));
5061       TREE_SIDE_EFFECTS (t) = 1;
5062       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5063     }
5064
5065   /* Find the overflow area.  */
5066   type = TREE_TYPE (ovf);
5067   t = make_tree (type, virtual_incoming_args_rtx);
5068   if (words != 0)
5069     t = build2 (POINTER_PLUS_EXPR, type, t,
5070                 size_int (words * UNITS_PER_WORD));
5071   t = build2 (GIMPLE_MODIFY_STMT, type, ovf, t);
5072   TREE_SIDE_EFFECTS (t) = 1;
5073   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5074
5075   if (cfun->va_list_gpr_size || cfun->va_list_fpr_size)
5076     {
5077       /* Find the register save area.
5078          Prologue of the function save it right above stack frame.  */
5079       type = TREE_TYPE (sav);
5080       t = make_tree (type, frame_pointer_rtx);
5081       t = build2 (GIMPLE_MODIFY_STMT, type, sav, t);
5082       TREE_SIDE_EFFECTS (t) = 1;
5083       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5084     }
5085 }
5086
5087 /* Implement va_arg.  */
5088
5089 static tree
5090 ix86_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
5091 {
5092   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
5093   tree f_gpr, f_fpr, f_ovf, f_sav;
5094   tree gpr, fpr, ovf, sav, t;
5095   int size, rsize;
5096   tree lab_false, lab_over = NULL_TREE;
5097   tree addr, t2;
5098   rtx container;
5099   int indirect_p = 0;
5100   tree ptrtype;
5101   enum machine_mode nat_mode;
5102
5103   /* Only 64bit target needs something special.  */
5104   if (!TARGET_64BIT || TARGET_64BIT_MS_ABI)
5105     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
5106
5107   f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
5108   f_fpr = TREE_CHAIN (f_gpr);
5109   f_ovf = TREE_CHAIN (f_fpr);
5110   f_sav = TREE_CHAIN (f_ovf);
5111
5112   valist = build_va_arg_indirect_ref (valist);
5113   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5114   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5115   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5116   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
5117
5118   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
5119   if (indirect_p)
5120     type = build_pointer_type (type);
5121   size = int_size_in_bytes (type);
5122   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5123
5124   nat_mode = type_natural_mode (type);
5125   container = construct_container (nat_mode, TYPE_MODE (type), type, 0,
5126                                    REGPARM_MAX, SSE_REGPARM_MAX, intreg, 0);
5127
5128   /* Pull the value out of the saved registers.  */
5129
5130   addr = create_tmp_var (ptr_type_node, "addr");
5131   DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
5132
5133   if (container)
5134     {
5135       int needed_intregs, needed_sseregs;
5136       bool need_temp;
5137       tree int_addr, sse_addr;
5138
5139       lab_false = create_artificial_label ();
5140       lab_over = create_artificial_label ();
5141
5142       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
5143
5144       need_temp = (!REG_P (container)
5145                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
5146                        || TYPE_ALIGN (type) > 128));
5147
5148       /* In case we are passing structure, verify that it is consecutive block
5149          on the register save area.  If not we need to do moves.  */
5150       if (!need_temp && !REG_P (container))
5151         {
5152           /* Verify that all registers are strictly consecutive  */
5153           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
5154             {
5155               int i;
5156
5157               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
5158                 {
5159                   rtx slot = XVECEXP (container, 0, i);
5160                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
5161                       || INTVAL (XEXP (slot, 1)) != i * 16)
5162                     need_temp = 1;
5163                 }
5164             }
5165           else
5166             {
5167               int i;
5168
5169               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
5170                 {
5171                   rtx slot = XVECEXP (container, 0, i);
5172                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
5173                       || INTVAL (XEXP (slot, 1)) != i * 8)
5174                     need_temp = 1;
5175                 }
5176             }
5177         }
5178       if (!need_temp)
5179         {
5180           int_addr = addr;
5181           sse_addr = addr;
5182         }
5183       else
5184         {
5185           int_addr = create_tmp_var (ptr_type_node, "int_addr");
5186           DECL_POINTER_ALIAS_SET (int_addr) = get_varargs_alias_set ();
5187           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
5188           DECL_POINTER_ALIAS_SET (sse_addr) = get_varargs_alias_set ();
5189         }
5190
5191       /* First ensure that we fit completely in registers.  */
5192       if (needed_intregs)
5193         {
5194           t = build_int_cst (TREE_TYPE (gpr),
5195                              (REGPARM_MAX - needed_intregs + 1) * 8);
5196           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
5197           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
5198           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
5199           gimplify_and_add (t, pre_p);
5200         }
5201       if (needed_sseregs)
5202         {
5203           t = build_int_cst (TREE_TYPE (fpr),
5204                              (SSE_REGPARM_MAX - needed_sseregs + 1) * 16
5205                              + REGPARM_MAX * 8);
5206           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
5207           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
5208           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
5209           gimplify_and_add (t, pre_p);
5210         }
5211
5212       /* Compute index to start of area used for integer regs.  */
5213       if (needed_intregs)
5214         {
5215           /* int_addr = gpr + sav; */
5216           t = fold_convert (sizetype, gpr);
5217           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
5218           t = build2 (GIMPLE_MODIFY_STMT, void_type_node, int_addr, t);
5219           gimplify_and_add (t, pre_p);
5220         }
5221       if (needed_sseregs)
5222         {
5223           /* sse_addr = fpr + sav; */
5224           t = fold_convert (sizetype, fpr);
5225           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
5226           t = build2 (GIMPLE_MODIFY_STMT, void_type_node, sse_addr, t);
5227           gimplify_and_add (t, pre_p);
5228         }
5229       if (need_temp)
5230         {
5231           int i;
5232           tree temp = create_tmp_var (type, "va_arg_tmp");
5233
5234           /* addr = &temp; */
5235           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
5236           t = build2 (GIMPLE_MODIFY_STMT, void_type_node, addr, t);
5237           gimplify_and_add (t, pre_p);
5238
5239           for (i = 0; i < XVECLEN (container, 0); i++)
5240             {
5241               rtx slot = XVECEXP (container, 0, i);
5242               rtx reg = XEXP (slot, 0);
5243               enum machine_mode mode = GET_MODE (reg);
5244               tree piece_type = lang_hooks.types.type_for_mode (mode, 1);
5245               tree addr_type = build_pointer_type (piece_type);
5246               tree src_addr, src;
5247               int src_offset;
5248               tree dest_addr, dest;
5249
5250               if (SSE_REGNO_P (REGNO (reg)))
5251                 {
5252                   src_addr = sse_addr;
5253                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
5254                 }
5255               else
5256                 {
5257                   src_addr = int_addr;
5258                   src_offset = REGNO (reg) * 8;
5259                 }
5260               src_addr = fold_convert (addr_type, src_addr);
5261               src_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, src_addr,
5262                                       size_int (src_offset));
5263               src = build_va_arg_indirect_ref (src_addr);
5264
5265               dest_addr = fold_convert (addr_type, addr);
5266               dest_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, dest_addr,
5267                                        size_int (INTVAL (XEXP (slot, 1))));
5268               dest = build_va_arg_indirect_ref (dest_addr);
5269
5270               t = build2 (GIMPLE_MODIFY_STMT, void_type_node, dest, src);
5271               gimplify_and_add (t, pre_p);
5272             }
5273         }
5274
5275       if (needed_intregs)
5276         {
5277           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
5278                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
5279           t = build2 (GIMPLE_MODIFY_STMT, TREE_TYPE (gpr), gpr, t);
5280           gimplify_and_add (t, pre_p);
5281         }
5282       if (needed_sseregs)
5283         {
5284           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
5285                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
5286           t = build2 (GIMPLE_MODIFY_STMT, TREE_TYPE (fpr), fpr, t);
5287           gimplify_and_add (t, pre_p);
5288         }
5289
5290       t = build1 (GOTO_EXPR, void_type_node, lab_over);
5291       gimplify_and_add (t, pre_p);
5292
5293       t = build1 (LABEL_EXPR, void_type_node, lab_false);
5294       append_to_statement_list (t, pre_p);
5295     }
5296
5297   /* ... otherwise out of the overflow area.  */
5298
5299   /* Care for on-stack alignment if needed.  */
5300   if (FUNCTION_ARG_BOUNDARY (VOIDmode, type) <= 64
5301       || integer_zerop (TYPE_SIZE (type)))
5302     t = ovf;
5303  else
5304     {
5305       HOST_WIDE_INT align = FUNCTION_ARG_BOUNDARY (VOIDmode, type) / 8;
5306       t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovf), ovf,
5307                   size_int (align - 1));
5308       t = fold_convert (sizetype, t);
5309       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
5310                   size_int (-align));
5311       t = fold_convert (TREE_TYPE (ovf), t);
5312     }
5313   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
5314
5315   t2 = build2 (GIMPLE_MODIFY_STMT, void_type_node, addr, t);
5316   gimplify_and_add (t2, pre_p);
5317
5318   t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
5319               size_int (rsize * UNITS_PER_WORD));
5320   t = build2 (GIMPLE_MODIFY_STMT, TREE_TYPE (ovf), ovf, t);
5321   gimplify_and_add (t, pre_p);
5322
5323   if (container)
5324     {
5325       t = build1 (LABEL_EXPR, void_type_node, lab_over);
5326       append_to_statement_list (t, pre_p);
5327     }
5328
5329   ptrtype = build_pointer_type (type);
5330   addr = fold_convert (ptrtype, addr);
5331
5332   if (indirect_p)
5333     addr = build_va_arg_indirect_ref (addr);
5334   return build_va_arg_indirect_ref (addr);
5335 }
5336 \f
5337 /* Return nonzero if OPNUM's MEM should be matched
5338    in movabs* patterns.  */
5339
5340 int
5341 ix86_check_movabs (rtx insn, int opnum)
5342 {
5343   rtx set, mem;
5344
5345   set = PATTERN (insn);
5346   if (GET_CODE (set) == PARALLEL)
5347     set = XVECEXP (set, 0, 0);
5348   gcc_assert (GET_CODE (set) == SET);
5349   mem = XEXP (set, opnum);
5350   while (GET_CODE (mem) == SUBREG)
5351     mem = SUBREG_REG (mem);
5352   gcc_assert (MEM_P (mem));
5353   return (volatile_ok || !MEM_VOLATILE_P (mem));
5354 }
5355 \f
5356 /* Initialize the table of extra 80387 mathematical constants.  */
5357
5358 static void
5359 init_ext_80387_constants (void)
5360 {
5361   static const char * cst[5] =
5362   {
5363     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
5364     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
5365     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
5366     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
5367     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
5368   };
5369   int i;
5370
5371   for (i = 0; i < 5; i++)
5372     {
5373       real_from_string (&ext_80387_constants_table[i], cst[i]);
5374       /* Ensure each constant is rounded to XFmode precision.  */
5375       real_convert (&ext_80387_constants_table[i],
5376                     XFmode, &ext_80387_constants_table[i]);
5377     }
5378
5379   ext_80387_constants_init = 1;
5380 }
5381
5382 /* Return true if the constant is something that can be loaded with
5383    a special instruction.  */
5384
5385 int
5386 standard_80387_constant_p (rtx x)
5387 {
5388   enum machine_mode mode = GET_MODE (x);
5389
5390   REAL_VALUE_TYPE r;
5391
5392   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
5393     return -1;
5394
5395   if (x == CONST0_RTX (mode))
5396     return 1;
5397   if (x == CONST1_RTX (mode))
5398     return 2;
5399
5400   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
5401
5402   /* For XFmode constants, try to find a special 80387 instruction when
5403      optimizing for size or on those CPUs that benefit from them.  */
5404   if (mode == XFmode
5405       && (optimize_size || TARGET_EXT_80387_CONSTANTS))
5406     {
5407       int i;
5408
5409       if (! ext_80387_constants_init)
5410         init_ext_80387_constants ();
5411
5412       for (i = 0; i < 5; i++)
5413         if (real_identical (&r, &ext_80387_constants_table[i]))
5414           return i + 3;
5415     }
5416
5417   /* Load of the constant -0.0 or -1.0 will be split as
5418      fldz;fchs or fld1;fchs sequence.  */
5419   if (real_isnegzero (&r))
5420     return 8;
5421   if (real_identical (&r, &dconstm1))
5422     return 9;
5423
5424   return 0;
5425 }
5426
5427 /* Return the opcode of the special instruction to be used to load
5428    the constant X.  */
5429
5430 const char *
5431 standard_80387_constant_opcode (rtx x)
5432 {
5433   switch (standard_80387_constant_p (x))
5434     {
5435     case 1:
5436       return "fldz";
5437     case 2:
5438       return "fld1";
5439     case 3:
5440       return "fldlg2";
5441     case 4:
5442       return "fldln2";
5443     case 5:
5444       return "fldl2e";
5445     case 6:
5446       return "fldl2t";
5447     case 7:
5448       return "fldpi";
5449     case 8:
5450     case 9:
5451       return "#";
5452     default:
5453       gcc_unreachable ();
5454     }
5455 }
5456
5457 /* Return the CONST_DOUBLE representing the 80387 constant that is
5458    loaded by the specified special instruction.  The argument IDX
5459    matches the return value from standard_80387_constant_p.  */
5460
5461 rtx
5462 standard_80387_constant_rtx (int idx)
5463 {
5464   int i;
5465
5466   if (! ext_80387_constants_init)
5467     init_ext_80387_constants ();
5468
5469   switch (idx)
5470     {
5471     case 3:
5472     case 4:
5473     case 5:
5474     case 6:
5475     case 7:
5476       i = idx - 3;
5477       break;
5478
5479     default:
5480       gcc_unreachable ();
5481     }
5482
5483   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
5484                                        XFmode);
5485 }
5486
5487 /* Return 1 if mode is a valid mode for sse.  */
5488 static int
5489 standard_sse_mode_p (enum machine_mode mode)
5490 {
5491   switch (mode)
5492     {
5493     case V16QImode:
5494     case V8HImode:
5495     case V4SImode:
5496     case V2DImode:
5497     case V4SFmode:
5498     case V2DFmode:
5499       return 1;
5500
5501     default:
5502       return 0;
5503     }
5504 }
5505
5506 /* Return 1 if X is FP constant we can load to SSE register w/o using memory.
5507  */
5508 int
5509 standard_sse_constant_p (rtx x)
5510 {
5511   enum machine_mode mode = GET_MODE (x);
5512
5513   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
5514     return 1;
5515   if (vector_all_ones_operand (x, mode)
5516       && standard_sse_mode_p (mode))
5517     return TARGET_SSE2 ? 2 : -1;
5518
5519   return 0;
5520 }
5521
5522 /* Return the opcode of the special instruction to be used to load
5523    the constant X.  */
5524
5525 const char *
5526 standard_sse_constant_opcode (rtx insn, rtx x)
5527 {
5528   switch (standard_sse_constant_p (x))
5529     {
5530     case 1:
5531       if (get_attr_mode (insn) == MODE_V4SF)
5532         return "xorps\t%0, %0";
5533       else if (get_attr_mode (insn) == MODE_V2DF)
5534         return "xorpd\t%0, %0";
5535       else
5536         return "pxor\t%0, %0";
5537     case 2:
5538       return "pcmpeqd\t%0, %0";
5539     }
5540   gcc_unreachable ();
5541 }
5542
5543 /* Returns 1 if OP contains a symbol reference */
5544
5545 int
5546 symbolic_reference_mentioned_p (rtx op)
5547 {
5548   const char *fmt;
5549   int i;
5550
5551   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
5552     return 1;
5553
5554   fmt = GET_RTX_FORMAT (GET_CODE (op));
5555   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
5556     {
5557       if (fmt[i] == 'E')
5558         {
5559           int j;
5560
5561           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
5562             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
5563               return 1;
5564         }
5565
5566       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
5567         return 1;
5568     }
5569
5570   return 0;
5571 }
5572
5573 /* Return 1 if it is appropriate to emit `ret' instructions in the
5574    body of a function.  Do this only if the epilogue is simple, needing a
5575    couple of insns.  Prior to reloading, we can't tell how many registers
5576    must be saved, so return 0 then.  Return 0 if there is no frame
5577    marker to de-allocate.  */
5578
5579 int
5580 ix86_can_use_return_insn_p (void)
5581 {
5582   struct ix86_frame frame;
5583
5584   if (! reload_completed || frame_pointer_needed)
5585     return 0;
5586
5587   /* Don't allow more than 32 pop, since that's all we can do
5588      with one instruction.  */
5589   if (current_function_pops_args
5590       && current_function_args_size >= 32768)
5591     return 0;
5592
5593   ix86_compute_frame_layout (&frame);
5594   return frame.to_allocate == 0 && frame.nregs == 0;
5595 }
5596 \f
5597 /* Value should be nonzero if functions must have frame pointers.
5598    Zero means the frame pointer need not be set up (and parms may
5599    be accessed via the stack pointer) in functions that seem suitable.  */
5600
5601 int
5602 ix86_frame_pointer_required (void)
5603 {
5604   /* If we accessed previous frames, then the generated code expects
5605      to be able to access the saved ebp value in our frame.  */
5606   if (cfun->machine->accesses_prev_frame)
5607     return 1;
5608
5609   /* Several x86 os'es need a frame pointer for other reasons,
5610      usually pertaining to setjmp.  */
5611   if (SUBTARGET_FRAME_POINTER_REQUIRED)
5612     return 1;
5613
5614   /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
5615      the frame pointer by default.  Turn it back on now if we've not
5616      got a leaf function.  */
5617   if (TARGET_OMIT_LEAF_FRAME_POINTER
5618       && (!current_function_is_leaf
5619           || ix86_current_function_calls_tls_descriptor))
5620     return 1;
5621
5622   if (current_function_profile)
5623     return 1;
5624
5625   return 0;
5626 }
5627
5628 /* Record that the current function accesses previous call frames.  */
5629
5630 void
5631 ix86_setup_frame_addresses (void)
5632 {
5633   cfun->machine->accesses_prev_frame = 1;
5634 }
5635 \f
5636 #if (defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)) || TARGET_MACHO
5637 # define USE_HIDDEN_LINKONCE 1
5638 #else
5639 # define USE_HIDDEN_LINKONCE 0
5640 #endif
5641
5642 static int pic_labels_used;
5643
5644 /* Fills in the label name that should be used for a pc thunk for
5645    the given register.  */
5646
5647 static void
5648 get_pc_thunk_name (char name[32], unsigned int regno)
5649 {
5650   gcc_assert (!TARGET_64BIT);
5651
5652   if (USE_HIDDEN_LINKONCE)
5653     sprintf (name, "__i686.get_pc_thunk.%s", reg_names[regno]);
5654   else
5655     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
5656 }
5657
5658
5659 /* This function generates code for -fpic that loads %ebx with
5660    the return address of the caller and then returns.  */
5661
5662 void
5663 ix86_file_end (void)
5664 {
5665   rtx xops[2];
5666   int regno;
5667
5668   for (regno = 0; regno < 8; ++regno)
5669     {
5670       char name[32];
5671
5672       if (! ((pic_labels_used >> regno) & 1))
5673         continue;
5674
5675       get_pc_thunk_name (name, regno);
5676
5677 #if TARGET_MACHO
5678       if (TARGET_MACHO)
5679         {
5680           switch_to_section (darwin_sections[text_coal_section]);
5681           fputs ("\t.weak_definition\t", asm_out_file);
5682           assemble_name (asm_out_file, name);
5683           fputs ("\n\t.private_extern\t", asm_out_file);
5684           assemble_name (asm_out_file, name);
5685           fputs ("\n", asm_out_file);
5686           ASM_OUTPUT_LABEL (asm_out_file, name);
5687         }
5688       else
5689 #endif
5690       if (USE_HIDDEN_LINKONCE)
5691         {
5692           tree decl;
5693
5694           decl = build_decl (FUNCTION_DECL, get_identifier (name),
5695                              error_mark_node);
5696           TREE_PUBLIC (decl) = 1;
5697           TREE_STATIC (decl) = 1;
5698           DECL_ONE_ONLY (decl) = 1;
5699
5700           (*targetm.asm_out.unique_section) (decl, 0);
5701           switch_to_section (get_named_section (decl, NULL, 0));
5702
5703           (*targetm.asm_out.globalize_label) (asm_out_file, name);
5704           fputs ("\t.hidden\t", asm_out_file);
5705           assemble_name (asm_out_file, name);
5706           fputc ('\n', asm_out_file);
5707           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
5708         }
5709       else
5710         {
5711           switch_to_section (text_section);
5712           ASM_OUTPUT_LABEL (asm_out_file, name);
5713         }
5714
5715       xops[0] = gen_rtx_REG (SImode, regno);
5716       xops[1] = gen_rtx_MEM (SImode, stack_pointer_rtx);
5717       output_asm_insn ("mov{l}\t{%1, %0|%0, %1}", xops);
5718       output_asm_insn ("ret", xops);
5719     }
5720
5721   if (NEED_INDICATE_EXEC_STACK)
5722     file_end_indicate_exec_stack ();
5723 }
5724
5725 /* Emit code for the SET_GOT patterns.  */
5726
5727 const char *
5728 output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
5729 {
5730   rtx xops[3];
5731
5732   xops[0] = dest;
5733
5734   if (TARGET_VXWORKS_RTP && flag_pic)
5735     {
5736       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
5737       xops[2] = gen_rtx_MEM (Pmode,
5738                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
5739       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
5740
5741       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
5742          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
5743          an unadorned address.  */
5744       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
5745       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
5746       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
5747       return "";
5748     }
5749
5750   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
5751
5752   if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
5753     {
5754       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
5755
5756       if (!flag_pic)
5757         output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
5758       else
5759         output_asm_insn ("call\t%a2", xops);
5760
5761 #if TARGET_MACHO
5762       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
5763          is what will be referenced by the Mach-O PIC subsystem.  */
5764       if (!label)
5765         ASM_OUTPUT_LABEL (asm_out_file, machopic_function_base_name ());
5766 #endif
5767
5768       (*targetm.asm_out.internal_label) (asm_out_file, "L",
5769                                  CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
5770
5771       if (flag_pic)
5772         output_asm_insn ("pop{l}\t%0", xops);
5773     }
5774   else
5775     {
5776       char name[32];
5777       get_pc_thunk_name (name, REGNO (dest));
5778       pic_labels_used |= 1 << REGNO (dest);
5779
5780       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
5781       xops[2] = gen_rtx_MEM (QImode, xops[2]);
5782       output_asm_insn ("call\t%X2", xops);
5783       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
5784          is what will be referenced by the Mach-O PIC subsystem.  */
5785 #if TARGET_MACHO
5786       if (!label)
5787         ASM_OUTPUT_LABEL (asm_out_file, machopic_function_base_name ());
5788       else
5789         targetm.asm_out.internal_label (asm_out_file, "L",
5790                                            CODE_LABEL_NUMBER (label));
5791 #endif
5792     }
5793
5794   if (TARGET_MACHO)
5795     return "";
5796
5797   if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
5798     output_asm_insn ("add{l}\t{%1, %0|%0, %1}", xops);
5799   else
5800     output_asm_insn ("add{l}\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
5801
5802   return "";
5803 }
5804
5805 /* Generate an "push" pattern for input ARG.  */
5806
5807 static rtx
5808 gen_push (rtx arg)
5809 {
5810   return gen_rtx_SET (VOIDmode,
5811                       gen_rtx_MEM (Pmode,
5812                                    gen_rtx_PRE_DEC (Pmode,
5813                                                     stack_pointer_rtx)),
5814                       arg);
5815 }
5816
5817 /* Return >= 0 if there is an unused call-clobbered register available
5818    for the entire function.  */
5819
5820 static unsigned int
5821 ix86_select_alt_pic_regnum (void)
5822 {
5823   if (current_function_is_leaf && !current_function_profile
5824       && !ix86_current_function_calls_tls_descriptor)
5825     {
5826       int i;
5827       for (i = 2; i >= 0; --i)
5828         if (!df_regs_ever_live_p (i))
5829           return i;
5830     }
5831
5832   return INVALID_REGNUM;
5833 }
5834
5835 /* Return 1 if we need to save REGNO.  */
5836 static int
5837 ix86_save_reg (unsigned int regno, int maybe_eh_return)
5838 {
5839   if (pic_offset_table_rtx
5840       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
5841       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
5842           || current_function_profile
5843           || current_function_calls_eh_return
5844           || current_function_uses_const_pool))
5845     {
5846       if (ix86_select_alt_pic_regnum () != INVALID_REGNUM)
5847         return 0;
5848       return 1;
5849     }
5850
5851   if (current_function_calls_eh_return && maybe_eh_return)
5852     {
5853       unsigned i;
5854       for (i = 0; ; i++)
5855         {
5856           unsigned test = EH_RETURN_DATA_REGNO (i);
5857           if (test == INVALID_REGNUM)
5858             break;
5859           if (test == regno)
5860             return 1;
5861         }
5862     }
5863
5864   if (cfun->machine->force_align_arg_pointer
5865       && regno == REGNO (cfun->machine->force_align_arg_pointer))
5866     return 1;
5867
5868   return (df_regs_ever_live_p (regno)
5869           && !call_used_regs[regno]
5870           && !fixed_regs[regno]
5871           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
5872 }
5873
5874 /* Return number of registers to be saved on the stack.  */
5875
5876 static int
5877 ix86_nsaved_regs (void)
5878 {
5879   int nregs = 0;
5880   int regno;
5881
5882   for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
5883     if (ix86_save_reg (regno, true))
5884       nregs++;
5885   return nregs;
5886 }
5887
5888 /* Return the offset between two registers, one to be eliminated, and the other
5889    its replacement, at the start of a routine.  */
5890
5891 HOST_WIDE_INT
5892 ix86_initial_elimination_offset (int from, int to)
5893 {
5894   struct ix86_frame frame;
5895   ix86_compute_frame_layout (&frame);
5896
5897   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
5898     return frame.hard_frame_pointer_offset;
5899   else if (from == FRAME_POINTER_REGNUM
5900            && to == HARD_FRAME_POINTER_REGNUM)
5901     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
5902   else
5903     {
5904       gcc_assert (to == STACK_POINTER_REGNUM);
5905
5906       if (from == ARG_POINTER_REGNUM)
5907         return frame.stack_pointer_offset;
5908
5909       gcc_assert (from == FRAME_POINTER_REGNUM);
5910       return frame.stack_pointer_offset - frame.frame_pointer_offset;
5911     }
5912 }
5913
5914 /* Fill structure ix86_frame about frame of currently computed function.  */
5915
5916 static void
5917 ix86_compute_frame_layout (struct ix86_frame *frame)
5918 {
5919   HOST_WIDE_INT total_size;
5920   unsigned int stack_alignment_needed;
5921   HOST_WIDE_INT offset;
5922   unsigned int preferred_alignment;
5923   HOST_WIDE_INT size = get_frame_size ();
5924
5925   frame->nregs = ix86_nsaved_regs ();
5926   total_size = size;
5927
5928   stack_alignment_needed = cfun->stack_alignment_needed / BITS_PER_UNIT;
5929   preferred_alignment = cfun->preferred_stack_boundary / BITS_PER_UNIT;
5930
5931   /* During reload iteration the amount of registers saved can change.
5932      Recompute the value as needed.  Do not recompute when amount of registers
5933      didn't change as reload does multiple calls to the function and does not
5934      expect the decision to change within single iteration.  */
5935   if (!optimize_size
5936       && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
5937     {
5938       int count = frame->nregs;
5939
5940       cfun->machine->use_fast_prologue_epilogue_nregs = count;
5941       /* The fast prologue uses move instead of push to save registers.  This
5942          is significantly longer, but also executes faster as modern hardware
5943          can execute the moves in parallel, but can't do that for push/pop.
5944
5945          Be careful about choosing what prologue to emit:  When function takes
5946          many instructions to execute we may use slow version as well as in
5947          case function is known to be outside hot spot (this is known with
5948          feedback only).  Weight the size of function by number of registers
5949          to save as it is cheap to use one or two push instructions but very
5950          slow to use many of them.  */
5951       if (count)
5952         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
5953       if (cfun->function_frequency < FUNCTION_FREQUENCY_NORMAL
5954           || (flag_branch_probabilities
5955               && cfun->function_frequency < FUNCTION_FREQUENCY_HOT))
5956         cfun->machine->use_fast_prologue_epilogue = false;
5957       else
5958         cfun->machine->use_fast_prologue_epilogue
5959            = !expensive_function_p (count);
5960     }
5961   if (TARGET_PROLOGUE_USING_MOVE
5962       && cfun->machine->use_fast_prologue_epilogue)
5963     frame->save_regs_using_mov = true;
5964   else
5965     frame->save_regs_using_mov = false;
5966
5967
5968   /* Skip return address and saved base pointer.  */
5969   offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
5970
5971   frame->hard_frame_pointer_offset = offset;
5972
5973   /* Do some sanity checking of stack_alignment_needed and
5974      preferred_alignment, since i386 port is the only using those features
5975      that may break easily.  */
5976
5977   gcc_assert (!size || stack_alignment_needed);
5978   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
5979   gcc_assert (preferred_alignment <= PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT);
5980   gcc_assert (stack_alignment_needed
5981               <= PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT);
5982
5983   if (stack_alignment_needed < STACK_BOUNDARY / BITS_PER_UNIT)
5984     stack_alignment_needed = STACK_BOUNDARY / BITS_PER_UNIT;
5985
5986   /* Register save area */
5987   offset += frame->nregs * UNITS_PER_WORD;
5988
5989   /* Va-arg area */
5990   if (ix86_save_varrargs_registers)
5991     {
5992       offset += X86_64_VARARGS_SIZE;
5993       frame->va_arg_size = X86_64_VARARGS_SIZE;
5994     }
5995   else
5996     frame->va_arg_size = 0;
5997
5998   /* Align start of frame for local function.  */
5999   frame->padding1 = ((offset + stack_alignment_needed - 1)
6000                      & -stack_alignment_needed) - offset;
6001
6002   offset += frame->padding1;
6003
6004   /* Frame pointer points here.  */
6005   frame->frame_pointer_offset = offset;
6006
6007   offset += size;
6008
6009   /* Add outgoing arguments area.  Can be skipped if we eliminated
6010      all the function calls as dead code.
6011      Skipping is however impossible when function calls alloca.  Alloca
6012      expander assumes that last current_function_outgoing_args_size
6013      of stack frame are unused.  */
6014   if (ACCUMULATE_OUTGOING_ARGS
6015       && (!current_function_is_leaf || current_function_calls_alloca
6016           || ix86_current_function_calls_tls_descriptor))
6017     {
6018       offset += current_function_outgoing_args_size;
6019       frame->outgoing_arguments_size = current_function_outgoing_args_size;
6020     }
6021   else
6022     frame->outgoing_arguments_size = 0;
6023
6024   /* Align stack boundary.  Only needed if we're calling another function
6025      or using alloca.  */
6026   if (!current_function_is_leaf || current_function_calls_alloca
6027       || ix86_current_function_calls_tls_descriptor)
6028     frame->padding2 = ((offset + preferred_alignment - 1)
6029                        & -preferred_alignment) - offset;
6030   else
6031     frame->padding2 = 0;
6032
6033   offset += frame->padding2;
6034
6035   /* We've reached end of stack frame.  */
6036   frame->stack_pointer_offset = offset;
6037
6038   /* Size prologue needs to allocate.  */
6039   frame->to_allocate =
6040     (size + frame->padding1 + frame->padding2
6041      + frame->outgoing_arguments_size + frame->va_arg_size);
6042
6043   if ((!frame->to_allocate && frame->nregs <= 1)
6044       || (TARGET_64BIT && frame->to_allocate >= (HOST_WIDE_INT) 0x80000000))
6045     frame->save_regs_using_mov = false;
6046
6047   if (TARGET_RED_ZONE && current_function_sp_is_unchanging
6048       && current_function_is_leaf
6049       && !ix86_current_function_calls_tls_descriptor)
6050     {
6051       frame->red_zone_size = frame->to_allocate;
6052       if (frame->save_regs_using_mov)
6053         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
6054       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
6055         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
6056     }
6057   else
6058     frame->red_zone_size = 0;
6059   frame->to_allocate -= frame->red_zone_size;
6060   frame->stack_pointer_offset -= frame->red_zone_size;
6061 #if 0
6062   fprintf (stderr, "\n");
6063   fprintf (stderr, "nregs: %ld\n", (long)frame->nregs);
6064   fprintf (stderr, "size: %ld\n", (long)size);
6065   fprintf (stderr, "alignment1: %ld\n", (long)stack_alignment_needed);
6066   fprintf (stderr, "padding1: %ld\n", (long)frame->padding1);
6067   fprintf (stderr, "va_arg: %ld\n", (long)frame->va_arg_size);
6068   fprintf (stderr, "padding2: %ld\n", (long)frame->padding2);
6069   fprintf (stderr, "to_allocate: %ld\n", (long)frame->to_allocate);
6070   fprintf (stderr, "red_zone_size: %ld\n", (long)frame->red_zone_size);
6071   fprintf (stderr, "frame_pointer_offset: %ld\n", (long)frame->frame_pointer_offset);
6072   fprintf (stderr, "hard_frame_pointer_offset: %ld\n",
6073            (long)frame->hard_frame_pointer_offset);
6074   fprintf (stderr, "stack_pointer_offset: %ld\n", (long)frame->stack_pointer_offset);
6075   fprintf (stderr, "current_function_is_leaf: %ld\n", (long)current_function_is_leaf);
6076   fprintf (stderr, "current_function_calls_alloca: %ld\n", (long)current_function_calls_alloca);
6077   fprintf (stderr, "x86_current_function_calls_tls_descriptor: %ld\n", (long)ix86_current_function_calls_tls_descriptor);
6078 #endif
6079 }
6080
6081 /* Emit code to save registers in the prologue.  */
6082
6083 static void
6084 ix86_emit_save_regs (void)
6085 {
6086   unsigned int regno;
6087   rtx insn;
6088
6089   for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0; )
6090     if (ix86_save_reg (regno, true))
6091       {
6092         insn = emit_insn (gen_push (gen_rtx_REG (Pmode, regno)));
6093         RTX_FRAME_RELATED_P (insn) = 1;
6094       }
6095 }
6096
6097 /* Emit code to save registers using MOV insns.  First register
6098    is restored from POINTER + OFFSET.  */
6099 static void
6100 ix86_emit_save_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
6101 {
6102   unsigned int regno;
6103   rtx insn;
6104
6105   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
6106     if (ix86_save_reg (regno, true))
6107       {
6108         insn = emit_move_insn (adjust_address (gen_rtx_MEM (Pmode, pointer),
6109                                                Pmode, offset),
6110                                gen_rtx_REG (Pmode, regno));
6111         RTX_FRAME_RELATED_P (insn) = 1;
6112         offset += UNITS_PER_WORD;
6113       }
6114 }
6115
6116 /* Expand prologue or epilogue stack adjustment.
6117    The pattern exist to put a dependency on all ebp-based memory accesses.
6118    STYLE should be negative if instructions should be marked as frame related,
6119    zero if %r11 register is live and cannot be freely used and positive
6120    otherwise.  */
6121
6122 static void
6123 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset, int style)
6124 {
6125   rtx insn;
6126
6127   if (! TARGET_64BIT)
6128     insn = emit_insn (gen_pro_epilogue_adjust_stack_1 (dest, src, offset));
6129   else if (x86_64_immediate_operand (offset, DImode))
6130     insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64 (dest, src, offset));
6131   else
6132     {
6133       rtx r11;
6134       /* r11 is used by indirect sibcall return as well, set before the
6135          epilogue and used after the epilogue.  ATM indirect sibcall
6136          shouldn't be used together with huge frame sizes in one
6137          function because of the frame_size check in sibcall.c.  */
6138       gcc_assert (style);
6139       r11 = gen_rtx_REG (DImode, R11_REG);
6140       insn = emit_insn (gen_rtx_SET (DImode, r11, offset));
6141       if (style < 0)
6142         RTX_FRAME_RELATED_P (insn) = 1;
6143       insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64_2 (dest, src, r11,
6144                                                                offset));
6145     }
6146   if (style < 0)
6147     RTX_FRAME_RELATED_P (insn) = 1;
6148 }
6149
6150 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
6151
6152 static rtx
6153 ix86_internal_arg_pointer (void)
6154 {
6155   bool has_force_align_arg_pointer =
6156     (0 != lookup_attribute (ix86_force_align_arg_pointer_string,
6157                             TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))));
6158   if ((FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6159        && DECL_NAME (current_function_decl)
6160        && MAIN_NAME_P (DECL_NAME (current_function_decl))
6161        && DECL_FILE_SCOPE_P (current_function_decl))
6162       || ix86_force_align_arg_pointer
6163       || has_force_align_arg_pointer)
6164     {
6165       /* Nested functions can't realign the stack due to a register
6166          conflict.  */
6167       if (DECL_CONTEXT (current_function_decl)
6168           && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL)
6169         {
6170           if (ix86_force_align_arg_pointer)
6171             warning (0, "-mstackrealign ignored for nested functions");
6172           if (has_force_align_arg_pointer)
6173             error ("%s not supported for nested functions",
6174                    ix86_force_align_arg_pointer_string);
6175           return virtual_incoming_args_rtx;
6176         }
6177       cfun->machine->force_align_arg_pointer = gen_rtx_REG (Pmode, CX_REG);
6178       return copy_to_reg (cfun->machine->force_align_arg_pointer);
6179     }
6180   else
6181     return virtual_incoming_args_rtx;
6182 }
6183
6184 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
6185    This is called from dwarf2out.c to emit call frame instructions
6186    for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
6187 static void
6188 ix86_dwarf_handle_frame_unspec (const char *label, rtx pattern, int index)
6189 {
6190   rtx unspec = SET_SRC (pattern);
6191   gcc_assert (GET_CODE (unspec) == UNSPEC);
6192
6193   switch (index)
6194     {
6195     case UNSPEC_REG_SAVE:
6196       dwarf2out_reg_save_reg (label, XVECEXP (unspec, 0, 0),
6197                               SET_DEST (pattern));
6198       break;
6199     case UNSPEC_DEF_CFA:
6200       dwarf2out_def_cfa (label, REGNO (SET_DEST (pattern)),
6201                          INTVAL (XVECEXP (unspec, 0, 0)));
6202       break;
6203     default:
6204       gcc_unreachable ();
6205     }
6206 }
6207
6208 /* Expand the prologue into a bunch of separate insns.  */
6209
6210 void
6211 ix86_expand_prologue (void)
6212 {
6213   rtx insn;
6214   bool pic_reg_used;
6215   struct ix86_frame frame;
6216   HOST_WIDE_INT allocate;
6217
6218   ix86_compute_frame_layout (&frame);
6219
6220   if (cfun->machine->force_align_arg_pointer)
6221     {
6222       rtx x, y;
6223
6224       /* Grab the argument pointer.  */
6225       x = plus_constant (stack_pointer_rtx, 4);
6226       y = cfun->machine->force_align_arg_pointer;
6227       insn = emit_insn (gen_rtx_SET (VOIDmode, y, x));
6228       RTX_FRAME_RELATED_P (insn) = 1;
6229
6230       /* The unwind info consists of two parts: install the fafp as the cfa,
6231          and record the fafp as the "save register" of the stack pointer.
6232          The later is there in order that the unwinder can see where it
6233          should restore the stack pointer across the and insn.  */
6234       x = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, const0_rtx), UNSPEC_DEF_CFA);
6235       x = gen_rtx_SET (VOIDmode, y, x);
6236       RTX_FRAME_RELATED_P (x) = 1;
6237       y = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, stack_pointer_rtx),
6238                           UNSPEC_REG_SAVE);
6239       y = gen_rtx_SET (VOIDmode, cfun->machine->force_align_arg_pointer, y);
6240       RTX_FRAME_RELATED_P (y) = 1;
6241       x = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, x, y));
6242       x = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, x, NULL);
6243       REG_NOTES (insn) = x;
6244
6245       /* Align the stack.  */
6246       emit_insn (gen_andsi3 (stack_pointer_rtx, stack_pointer_rtx,
6247                              GEN_INT (-16)));
6248
6249       /* And here we cheat like madmen with the unwind info.  We force the
6250          cfa register back to sp+4, which is exactly what it was at the
6251          start of the function.  Re-pushing the return address results in
6252          the return at the same spot relative to the cfa, and thus is
6253          correct wrt the unwind info.  */
6254       x = cfun->machine->force_align_arg_pointer;
6255       x = gen_frame_mem (Pmode, plus_constant (x, -4));
6256       insn = emit_insn (gen_push (x));
6257       RTX_FRAME_RELATED_P (insn) = 1;
6258
6259       x = GEN_INT (4);
6260       x = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, x), UNSPEC_DEF_CFA);
6261       x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
6262       x = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, x, NULL);
6263       REG_NOTES (insn) = x;
6264     }
6265
6266   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
6267      slower on all targets.  Also sdb doesn't like it.  */
6268
6269   if (frame_pointer_needed)
6270     {
6271       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
6272       RTX_FRAME_RELATED_P (insn) = 1;
6273
6274       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
6275       RTX_FRAME_RELATED_P (insn) = 1;
6276     }
6277
6278   allocate = frame.to_allocate;
6279
6280   if (!frame.save_regs_using_mov)
6281     ix86_emit_save_regs ();
6282   else
6283     allocate += frame.nregs * UNITS_PER_WORD;
6284
6285   /* When using red zone we may start register saving before allocating
6286      the stack frame saving one cycle of the prologue.  */
6287   if (TARGET_RED_ZONE && frame.save_regs_using_mov)
6288     ix86_emit_save_regs_using_mov (frame_pointer_needed ? hard_frame_pointer_rtx
6289                                    : stack_pointer_rtx,
6290                                    -frame.nregs * UNITS_PER_WORD);
6291
6292   if (allocate == 0)
6293     ;
6294   else if (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)
6295     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
6296                                GEN_INT (-allocate), -1);
6297   else
6298     {
6299       /* Only valid for Win32.  */
6300       rtx eax = gen_rtx_REG (Pmode, AX_REG);
6301       bool eax_live;
6302       rtx t;
6303
6304       gcc_assert (!TARGET_64BIT || TARGET_64BIT_MS_ABI);
6305
6306       if (TARGET_64BIT_MS_ABI)
6307         eax_live = false;
6308       else
6309         eax_live = ix86_eax_live_at_start_p ();
6310
6311       if (eax_live)
6312         {
6313           emit_insn (gen_push (eax));
6314           allocate -= UNITS_PER_WORD;
6315         }
6316
6317       emit_move_insn (eax, GEN_INT (allocate));
6318
6319       if (TARGET_64BIT)
6320         insn = gen_allocate_stack_worker_64 (eax);
6321       else
6322         insn = gen_allocate_stack_worker_32 (eax);
6323       insn = emit_insn (insn);
6324       RTX_FRAME_RELATED_P (insn) = 1;
6325       t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (-allocate));
6326       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
6327       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
6328                                             t, REG_NOTES (insn));
6329
6330       if (eax_live)
6331         {
6332           if (frame_pointer_needed)
6333             t = plus_constant (hard_frame_pointer_rtx,
6334                                allocate
6335                                - frame.to_allocate
6336                                - frame.nregs * UNITS_PER_WORD);
6337           else
6338             t = plus_constant (stack_pointer_rtx, allocate);
6339           emit_move_insn (eax, gen_rtx_MEM (Pmode, t));
6340         }
6341     }
6342
6343   if (frame.save_regs_using_mov && !TARGET_RED_ZONE)
6344     {
6345       if (!frame_pointer_needed || !frame.to_allocate)
6346         ix86_emit_save_regs_using_mov (stack_pointer_rtx, frame.to_allocate);
6347       else
6348         ix86_emit_save_regs_using_mov (hard_frame_pointer_rtx,
6349                                        -frame.nregs * UNITS_PER_WORD);
6350     }
6351
6352   pic_reg_used = false;
6353   if (pic_offset_table_rtx
6354       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
6355           || current_function_profile))
6356     {
6357       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
6358
6359       if (alt_pic_reg_used != INVALID_REGNUM)
6360         SET_REGNO (pic_offset_table_rtx, alt_pic_reg_used);
6361
6362       pic_reg_used = true;
6363     }
6364
6365   if (pic_reg_used)
6366     {
6367       if (TARGET_64BIT)
6368         {
6369           if (ix86_cmodel == CM_LARGE_PIC)
6370             {
6371               rtx tmp_reg = gen_rtx_REG (DImode, R11_REG);
6372               rtx label = gen_label_rtx ();
6373               emit_label (label);
6374               LABEL_PRESERVE_P (label) = 1;
6375               gcc_assert (REGNO (pic_offset_table_rtx) != REGNO (tmp_reg));
6376               insn = emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, label));
6377               insn = emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
6378               insn = emit_insn (gen_adddi3 (pic_offset_table_rtx,
6379                                             pic_offset_table_rtx, tmp_reg));
6380             }
6381           else
6382             insn = emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
6383         }
6384       else
6385         insn = emit_insn (gen_set_got (pic_offset_table_rtx));
6386     }
6387
6388   /* Prevent function calls from being scheduled before the call to mcount.
6389      In the pic_reg_used case, make sure that the got load isn't deleted.  */
6390   if (current_function_profile)
6391     {
6392       if (pic_reg_used)
6393         emit_insn (gen_prologue_use (pic_offset_table_rtx));
6394       emit_insn (gen_blockage ());
6395     }
6396 }
6397
6398 /* Emit code to restore saved registers using MOV insns.  First register
6399    is restored from POINTER + OFFSET.  */
6400 static void
6401 ix86_emit_restore_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
6402                                   int maybe_eh_return)
6403 {
6404   int regno;
6405   rtx base_address = gen_rtx_MEM (Pmode, pointer);
6406
6407   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
6408     if (ix86_save_reg (regno, maybe_eh_return))
6409       {
6410         /* Ensure that adjust_address won't be forced to produce pointer
6411            out of range allowed by x86-64 instruction set.  */
6412         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
6413           {
6414             rtx r11;
6415
6416             r11 = gen_rtx_REG (DImode, R11_REG);
6417             emit_move_insn (r11, GEN_INT (offset));
6418             emit_insn (gen_adddi3 (r11, r11, pointer));
6419             base_address = gen_rtx_MEM (Pmode, r11);
6420             offset = 0;
6421           }
6422         emit_move_insn (gen_rtx_REG (Pmode, regno),
6423                         adjust_address (base_address, Pmode, offset));
6424         offset += UNITS_PER_WORD;
6425       }
6426 }
6427
6428 /* Restore function stack, frame, and registers.  */
6429
6430 void
6431 ix86_expand_epilogue (int style)
6432 {
6433   int regno;
6434   int sp_valid = !frame_pointer_needed || current_function_sp_is_unchanging;
6435   struct ix86_frame frame;
6436   HOST_WIDE_INT offset;
6437
6438   ix86_compute_frame_layout (&frame);
6439
6440   /* Calculate start of saved registers relative to ebp.  Special care
6441      must be taken for the normal return case of a function using
6442      eh_return: the eax and edx registers are marked as saved, but not
6443      restored along this path.  */
6444   offset = frame.nregs;
6445   if (current_function_calls_eh_return && style != 2)
6446     offset -= 2;
6447   offset *= -UNITS_PER_WORD;
6448
6449   /* If we're only restoring one register and sp is not valid then
6450      using a move instruction to restore the register since it's
6451      less work than reloading sp and popping the register.
6452
6453      The default code result in stack adjustment using add/lea instruction,
6454      while this code results in LEAVE instruction (or discrete equivalent),
6455      so it is profitable in some other cases as well.  Especially when there
6456      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
6457      and there is exactly one register to pop. This heuristic may need some
6458      tuning in future.  */
6459   if ((!sp_valid && frame.nregs <= 1)
6460       || (TARGET_EPILOGUE_USING_MOVE
6461           && cfun->machine->use_fast_prologue_epilogue
6462           && (frame.nregs > 1 || frame.to_allocate))
6463       || (frame_pointer_needed && !frame.nregs && frame.to_allocate)
6464       || (frame_pointer_needed && TARGET_USE_LEAVE
6465           && cfun->machine->use_fast_prologue_epilogue
6466           && frame.nregs == 1)
6467       || current_function_calls_eh_return)
6468     {
6469       /* Restore registers.  We can use ebp or esp to address the memory
6470          locations.  If both are available, default to ebp, since offsets
6471          are known to be small.  Only exception is esp pointing directly to the
6472          end of block of saved registers, where we may simplify addressing
6473          mode.  */
6474
6475       if (!frame_pointer_needed || (sp_valid && !frame.to_allocate))
6476         ix86_emit_restore_regs_using_mov (stack_pointer_rtx,
6477                                           frame.to_allocate, style == 2);
6478       else
6479         ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx,
6480                                           offset, style == 2);
6481
6482       /* eh_return epilogues need %ecx added to the stack pointer.  */
6483       if (style == 2)
6484         {
6485           rtx tmp, sa = EH_RETURN_STACKADJ_RTX;
6486
6487           if (frame_pointer_needed)
6488             {
6489               tmp = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
6490               tmp = plus_constant (tmp, UNITS_PER_WORD);
6491               emit_insn (gen_rtx_SET (VOIDmode, sa, tmp));
6492
6493               tmp = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
6494               emit_move_insn (hard_frame_pointer_rtx, tmp);
6495
6496               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
6497                                          const0_rtx, style);
6498             }
6499           else
6500             {
6501               tmp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
6502               tmp = plus_constant (tmp, (frame.to_allocate
6503                                          + frame.nregs * UNITS_PER_WORD));
6504               emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp));
6505             }
6506         }
6507       else if (!frame_pointer_needed)
6508         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
6509                                    GEN_INT (frame.to_allocate
6510                                             + frame.nregs * UNITS_PER_WORD),
6511                                    style);
6512       /* If not an i386, mov & pop is faster than "leave".  */
6513       else if (TARGET_USE_LEAVE || optimize_size
6514                || !cfun->machine->use_fast_prologue_epilogue)
6515         emit_insn (TARGET_64BIT ? gen_leave_rex64 () : gen_leave ());
6516       else
6517         {
6518           pro_epilogue_adjust_stack (stack_pointer_rtx,
6519                                      hard_frame_pointer_rtx,
6520                                      const0_rtx, style);
6521           if (TARGET_64BIT)
6522             emit_insn (gen_popdi1 (hard_frame_pointer_rtx));
6523           else
6524             emit_insn (gen_popsi1 (hard_frame_pointer_rtx));
6525         }
6526     }
6527   else
6528     {
6529       /* First step is to deallocate the stack frame so that we can
6530          pop the registers.  */
6531       if (!sp_valid)
6532         {
6533           gcc_assert (frame_pointer_needed);
6534           pro_epilogue_adjust_stack (stack_pointer_rtx,
6535                                      hard_frame_pointer_rtx,
6536                                      GEN_INT (offset), style);
6537         }
6538       else if (frame.to_allocate)
6539         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
6540                                    GEN_INT (frame.to_allocate), style);
6541
6542       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
6543         if (ix86_save_reg (regno, false))
6544           {
6545             if (TARGET_64BIT)
6546               emit_insn (gen_popdi1 (gen_rtx_REG (Pmode, regno)));
6547             else
6548               emit_insn (gen_popsi1 (gen_rtx_REG (Pmode, regno)));
6549           }
6550       if (frame_pointer_needed)
6551         {
6552           /* Leave results in shorter dependency chains on CPUs that are
6553              able to grok it fast.  */
6554           if (TARGET_USE_LEAVE)
6555             emit_insn (TARGET_64BIT ? gen_leave_rex64 () : gen_leave ());
6556           else if (TARGET_64BIT)
6557             emit_insn (gen_popdi1 (hard_frame_pointer_rtx));
6558           else
6559             emit_insn (gen_popsi1 (hard_frame_pointer_rtx));
6560         }
6561     }
6562
6563   if (cfun->machine->force_align_arg_pointer)
6564     {
6565       emit_insn (gen_addsi3 (stack_pointer_rtx,
6566                              cfun->machine->force_align_arg_pointer,
6567                              GEN_INT (-4)));
6568     }
6569
6570   /* Sibcall epilogues don't want a return instruction.  */
6571   if (style == 0)
6572     return;
6573
6574   if (current_function_pops_args && current_function_args_size)
6575     {
6576       rtx popc = GEN_INT (current_function_pops_args);
6577
6578       /* i386 can only pop 64K bytes.  If asked to pop more, pop
6579          return address, do explicit add, and jump indirectly to the
6580          caller.  */
6581
6582       if (current_function_pops_args >= 65536)
6583         {
6584           rtx ecx = gen_rtx_REG (SImode, CX_REG);
6585
6586           /* There is no "pascal" calling convention in any 64bit ABI.  */
6587           gcc_assert (!TARGET_64BIT);
6588
6589           emit_insn (gen_popsi1 (ecx));
6590           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc));
6591           emit_jump_insn (gen_return_indirect_internal (ecx));
6592         }
6593       else
6594         emit_jump_insn (gen_return_pop_internal (popc));
6595     }
6596   else
6597     emit_jump_insn (gen_return_internal ());
6598 }
6599
6600 /* Reset from the function's potential modifications.  */
6601
6602 static void
6603 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
6604                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
6605 {
6606   if (pic_offset_table_rtx)
6607     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
6608 #if TARGET_MACHO
6609   /* Mach-O doesn't support labels at the end of objects, so if
6610      it looks like we might want one, insert a NOP.  */
6611   {
6612     rtx insn = get_last_insn ();
6613     while (insn
6614            && NOTE_P (insn)
6615            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
6616       insn = PREV_INSN (insn);
6617     if (insn
6618         && (LABEL_P (insn)
6619             || (NOTE_P (insn)
6620                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
6621       fputs ("\tnop\n", file);
6622   }
6623 #endif
6624
6625 }
6626 \f
6627 /* Extract the parts of an RTL expression that is a valid memory address
6628    for an instruction.  Return 0 if the structure of the address is
6629    grossly off.  Return -1 if the address contains ASHIFT, so it is not
6630    strictly valid, but still used for computing length of lea instruction.  */
6631
6632 int
6633 ix86_decompose_address (rtx addr, struct ix86_address *out)
6634 {
6635   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
6636   rtx base_reg, index_reg;
6637   HOST_WIDE_INT scale = 1;
6638   rtx scale_rtx = NULL_RTX;
6639   int retval = 1;
6640   enum ix86_address_seg seg = SEG_DEFAULT;
6641
6642   if (REG_P (addr) || GET_CODE (addr) == SUBREG)
6643     base = addr;
6644   else if (GET_CODE (addr) == PLUS)
6645     {
6646       rtx addends[4], op;
6647       int n = 0, i;
6648
6649       op = addr;
6650       do
6651         {
6652           if (n >= 4)
6653             return 0;
6654           addends[n++] = XEXP (op, 1);
6655           op = XEXP (op, 0);
6656         }
6657       while (GET_CODE (op) == PLUS);
6658       if (n >= 4)
6659         return 0;
6660       addends[n] = op;
6661
6662       for (i = n; i >= 0; --i)
6663         {
6664           op = addends[i];
6665           switch (GET_CODE (op))
6666             {
6667             case MULT:
6668               if (index)
6669                 return 0;
6670               index = XEXP (op, 0);
6671               scale_rtx = XEXP (op, 1);
6672               break;
6673
6674             case UNSPEC:
6675               if (XINT (op, 1) == UNSPEC_TP
6676                   && TARGET_TLS_DIRECT_SEG_REFS
6677                   && seg == SEG_DEFAULT)
6678                 seg = TARGET_64BIT ? SEG_FS : SEG_GS;
6679               else
6680                 return 0;
6681               break;
6682
6683             case REG:
6684             case SUBREG:
6685               if (!base)
6686                 base = op;
6687               else if (!index)
6688                 index = op;
6689               else
6690                 return 0;
6691               break;
6692
6693             case CONST:
6694             case CONST_INT:
6695             case SYMBOL_REF:
6696             case LABEL_REF:
6697               if (disp)
6698                 return 0;
6699               disp = op;
6700               break;
6701
6702             default:
6703               return 0;
6704             }
6705         }
6706     }
6707   else if (GET_CODE (addr) == MULT)
6708     {
6709       index = XEXP (addr, 0);           /* index*scale */
6710       scale_rtx = XEXP (addr, 1);
6711     }
6712   else if (GET_CODE (addr) == ASHIFT)
6713     {
6714       rtx tmp;
6715
6716       /* We're called for lea too, which implements ashift on occasion.  */
6717       index = XEXP (addr, 0);
6718       tmp = XEXP (addr, 1);
6719       if (!CONST_INT_P (tmp))
6720         return 0;
6721       scale = INTVAL (tmp);
6722       if ((unsigned HOST_WIDE_INT) scale > 3)
6723         return 0;
6724       scale = 1 << scale;
6725       retval = -1;
6726     }
6727   else
6728     disp = addr;                        /* displacement */
6729
6730   /* Extract the integral value of scale.  */
6731   if (scale_rtx)
6732     {
6733       if (!CONST_INT_P (scale_rtx))
6734         return 0;
6735       scale = INTVAL (scale_rtx);
6736     }
6737
6738   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
6739   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
6740
6741   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
6742   if (base_reg && index_reg && scale == 1
6743       && (index_reg == arg_pointer_rtx
6744           || index_reg == frame_pointer_rtx
6745           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
6746     {
6747       rtx tmp;
6748       tmp = base, base = index, index = tmp;
6749       tmp = base_reg, base_reg = index_reg, index_reg = tmp;
6750     }
6751
6752   /* Special case: %ebp cannot be encoded as a base without a displacement.  */
6753   if ((base_reg == hard_frame_pointer_rtx
6754        || base_reg == frame_pointer_rtx
6755        || base_reg == arg_pointer_rtx) && !disp)
6756     disp = const0_rtx;
6757
6758   /* Special case: on K6, [%esi] makes the instruction vector decoded.
6759      Avoid this by transforming to [%esi+0].  */
6760   if (ix86_tune == PROCESSOR_K6 && !optimize_size
6761       && base_reg && !index_reg && !disp
6762       && REG_P (base_reg)
6763       && REGNO_REG_CLASS (REGNO (base_reg)) == SIREG)
6764     disp = const0_rtx;
6765
6766   /* Special case: encode reg+reg instead of reg*2.  */
6767   if (!base && index && scale && scale == 2)
6768     base = index, base_reg = index_reg, scale = 1;
6769
6770   /* Special case: scaling cannot be encoded without base or displacement.  */
6771   if (!base && !disp && index && scale != 1)
6772     disp = const0_rtx;
6773
6774   out->base = base;
6775   out->index = index;
6776   out->disp = disp;
6777   out->scale = scale;
6778   out->seg = seg;
6779
6780   return retval;
6781 }
6782 \f
6783 /* Return cost of the memory address x.
6784    For i386, it is better to use a complex address than let gcc copy
6785    the address into a reg and make a new pseudo.  But not if the address
6786    requires to two regs - that would mean more pseudos with longer
6787    lifetimes.  */
6788 static int
6789 ix86_address_cost (rtx x)
6790 {
6791   struct ix86_address parts;
6792   int cost = 1;
6793   int ok = ix86_decompose_address (x, &parts);
6794
6795   gcc_assert (ok);
6796
6797   if (parts.base && GET_CODE (parts.base) == SUBREG)
6798     parts.base = SUBREG_REG (parts.base);
6799   if (parts.index && GET_CODE (parts.index) == SUBREG)
6800     parts.index = SUBREG_REG (parts.index);
6801
6802   /* Attempt to minimize number of registers in the address.  */
6803   if ((parts.base
6804        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
6805       || (parts.index
6806           && (!REG_P (parts.index)
6807               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
6808     cost++;
6809
6810   if (parts.base
6811       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
6812       && parts.index
6813       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
6814       && parts.base != parts.index)
6815     cost++;
6816
6817   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
6818      since it's predecode logic can't detect the length of instructions
6819      and it degenerates to vector decoded.  Increase cost of such
6820      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
6821      to split such addresses or even refuse such addresses at all.
6822
6823      Following addressing modes are affected:
6824       [base+scale*index]
6825       [scale*index+disp]
6826       [base+index]
6827
6828      The first and last case  may be avoidable by explicitly coding the zero in
6829      memory address, but I don't have AMD-K6 machine handy to check this
6830      theory.  */
6831
6832   if (TARGET_K6
6833       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
6834           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
6835           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
6836     cost += 10;
6837
6838   return cost;
6839 }
6840 \f
6841 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
6842    this is used for to form addresses to local data when -fPIC is in
6843    use.  */
6844
6845 static bool
6846 darwin_local_data_pic (rtx disp)
6847 {
6848   if (GET_CODE (disp) == MINUS)
6849     {
6850       if (GET_CODE (XEXP (disp, 0)) == LABEL_REF
6851           || GET_CODE (XEXP (disp, 0)) == SYMBOL_REF)
6852         if (GET_CODE (XEXP (disp, 1)) == SYMBOL_REF)
6853           {
6854             const char *sym_name = XSTR (XEXP (disp, 1), 0);
6855             if (! strcmp (sym_name, "<pic base>"))
6856               return true;
6857           }
6858     }
6859
6860   return false;
6861 }
6862
6863 /* Determine if a given RTX is a valid constant.  We already know this
6864    satisfies CONSTANT_P.  */
6865
6866 bool
6867 legitimate_constant_p (rtx x)
6868 {
6869   switch (GET_CODE (x))
6870     {
6871     case CONST:
6872       x = XEXP (x, 0);
6873
6874       if (GET_CODE (x) == PLUS)
6875         {
6876           if (!CONST_INT_P (XEXP (x, 1)))
6877             return false;
6878           x = XEXP (x, 0);
6879         }
6880
6881       if (TARGET_MACHO && darwin_local_data_pic (x))
6882         return true;
6883
6884       /* Only some unspecs are valid as "constants".  */
6885       if (GET_CODE (x) == UNSPEC)
6886         switch (XINT (x, 1))
6887           {
6888           case UNSPEC_GOT:
6889           case UNSPEC_GOTOFF:
6890           case UNSPEC_PLTOFF:
6891             return TARGET_64BIT;
6892           case UNSPEC_TPOFF:
6893           case UNSPEC_NTPOFF:
6894             x = XVECEXP (x, 0, 0);
6895             return (GET_CODE (x) == SYMBOL_REF
6896                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
6897           case UNSPEC_DTPOFF:
6898             x = XVECEXP (x, 0, 0);
6899             return (GET_CODE (x) == SYMBOL_REF
6900                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
6901           default:
6902             return false;
6903           }
6904
6905       /* We must have drilled down to a symbol.  */
6906       if (GET_CODE (x) == LABEL_REF)
6907         return true;
6908       if (GET_CODE (x) != SYMBOL_REF)
6909         return false;
6910       /* FALLTHRU */
6911
6912     case SYMBOL_REF:
6913       /* TLS symbols are never valid.  */
6914       if (SYMBOL_REF_TLS_MODEL (x))
6915         return false;
6916
6917       /* DLLIMPORT symbols are never valid.  */
6918       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
6919           && SYMBOL_REF_DLLIMPORT_P (x))
6920         return false;
6921       break;
6922
6923     case CONST_DOUBLE:
6924       if (GET_MODE (x) == TImode
6925           && x != CONST0_RTX (TImode)
6926           && !TARGET_64BIT)
6927         return false;
6928       break;
6929
6930     case CONST_VECTOR:
6931       if (x == CONST0_RTX (GET_MODE (x)))
6932         return true;
6933       return false;
6934
6935     default:
6936       break;
6937     }
6938
6939   /* Otherwise we handle everything else in the move patterns.  */
6940   return true;
6941 }
6942
6943 /* Determine if it's legal to put X into the constant pool.  This
6944    is not possible for the address of thread-local symbols, which
6945    is checked above.  */
6946
6947 static bool
6948 ix86_cannot_force_const_mem (rtx x)
6949 {
6950   /* We can always put integral constants and vectors in memory.  */
6951   switch (GET_CODE (x))
6952     {
6953     case CONST_INT:
6954     case CONST_DOUBLE:
6955     case CONST_VECTOR:
6956       return false;
6957
6958     default:
6959       break;
6960     }
6961   return !legitimate_constant_p (x);
6962 }
6963
6964 /* Determine if a given RTX is a valid constant address.  */
6965
6966 bool
6967 constant_address_p (rtx x)
6968 {
6969   return CONSTANT_P (x) && legitimate_address_p (Pmode, x, 1);
6970 }
6971
6972 /* Nonzero if the constant value X is a legitimate general operand
6973    when generating PIC code.  It is given that flag_pic is on and
6974    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
6975
6976 bool
6977 legitimate_pic_operand_p (rtx x)
6978 {
6979   rtx inner;
6980
6981   switch (GET_CODE (x))
6982     {
6983     case CONST:
6984       inner = XEXP (x, 0);
6985       if (GET_CODE (inner) == PLUS
6986           && CONST_INT_P (XEXP (inner, 1)))
6987         inner = XEXP (inner, 0);
6988
6989       /* Only some unspecs are valid as "constants".  */
6990       if (GET_CODE (inner) == UNSPEC)
6991         switch (XINT (inner, 1))
6992           {
6993           case UNSPEC_GOT:
6994           case UNSPEC_GOTOFF:
6995           case UNSPEC_PLTOFF:
6996             return TARGET_64BIT;
6997           case UNSPEC_TPOFF:
6998             x = XVECEXP (inner, 0, 0);
6999             return (GET_CODE (x) == SYMBOL_REF
7000                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
7001           default:
7002             return false;
7003           }
7004       /* FALLTHRU */
7005
7006     case SYMBOL_REF:
7007     case LABEL_REF:
7008       return legitimate_pic_address_disp_p (x);
7009
7010     default:
7011       return true;
7012     }
7013 }
7014
7015 /* Determine if a given CONST RTX is a valid memory displacement
7016    in PIC mode.  */
7017
7018 int
7019 legitimate_pic_address_disp_p (rtx disp)
7020 {
7021   bool saw_plus;
7022
7023   /* In 64bit mode we can allow direct addresses of symbols and labels
7024      when they are not dynamic symbols.  */
7025   if (TARGET_64BIT)
7026     {
7027       rtx op0 = disp, op1;
7028
7029       switch (GET_CODE (disp))
7030         {
7031         case LABEL_REF:
7032           return true;
7033
7034         case CONST:
7035           if (GET_CODE (XEXP (disp, 0)) != PLUS)
7036             break;
7037           op0 = XEXP (XEXP (disp, 0), 0);
7038           op1 = XEXP (XEXP (disp, 0), 1);
7039           if (!CONST_INT_P (op1)
7040               || INTVAL (op1) >= 16*1024*1024
7041               || INTVAL (op1) < -16*1024*1024)
7042             break;
7043           if (GET_CODE (op0) == LABEL_REF)
7044             return true;
7045           if (GET_CODE (op0) != SYMBOL_REF)
7046             break;
7047           /* FALLTHRU */
7048
7049         case SYMBOL_REF:
7050           /* TLS references should always be enclosed in UNSPEC.  */
7051           if (SYMBOL_REF_TLS_MODEL (op0))
7052             return false;
7053           if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0)
7054               && ix86_cmodel != CM_LARGE_PIC)
7055             return true;
7056           break;
7057
7058         default:
7059           break;
7060         }
7061     }
7062   if (GET_CODE (disp) != CONST)
7063     return 0;
7064   disp = XEXP (disp, 0);
7065
7066   if (TARGET_64BIT)
7067     {
7068       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
7069          of GOT tables.  We should not need these anyway.  */
7070       if (GET_CODE (disp) != UNSPEC
7071           || (XINT (disp, 1) != UNSPEC_GOTPCREL
7072               && XINT (disp, 1) != UNSPEC_GOTOFF
7073               && XINT (disp, 1) != UNSPEC_PLTOFF))
7074         return 0;
7075
7076       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
7077           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
7078         return 0;
7079       return 1;
7080     }
7081
7082   saw_plus = false;
7083   if (GET_CODE (disp) == PLUS)
7084     {
7085       if (!CONST_INT_P (XEXP (disp, 1)))
7086         return 0;
7087       disp = XEXP (disp, 0);
7088       saw_plus = true;
7089     }
7090
7091   if (TARGET_MACHO && darwin_local_data_pic (disp))
7092     return 1;
7093
7094   if (GET_CODE (disp) != UNSPEC)
7095     return 0;
7096
7097   switch (XINT (disp, 1))
7098     {
7099     case UNSPEC_GOT:
7100       if (saw_plus)
7101         return false;
7102       /* We need to check for both symbols and labels because VxWorks loads
7103          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
7104          details.  */
7105       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
7106               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
7107     case UNSPEC_GOTOFF:
7108       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
7109          While ABI specify also 32bit relocation but we don't produce it in
7110          small PIC model at all.  */
7111       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
7112            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
7113           && !TARGET_64BIT)
7114         return gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
7115       return false;
7116     case UNSPEC_GOTTPOFF:
7117     case UNSPEC_GOTNTPOFF:
7118     case UNSPEC_INDNTPOFF:
7119       if (saw_plus)
7120         return false;
7121       disp = XVECEXP (disp, 0, 0);
7122       return (GET_CODE (disp) == SYMBOL_REF
7123               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
7124     case UNSPEC_NTPOFF:
7125       disp = XVECEXP (disp, 0, 0);
7126       return (GET_CODE (disp) == SYMBOL_REF
7127               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
7128     case UNSPEC_DTPOFF:
7129       disp = XVECEXP (disp, 0, 0);
7130       return (GET_CODE (disp) == SYMBOL_REF
7131               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
7132     }
7133
7134   return 0;
7135 }
7136
7137 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid
7138    memory address for an instruction.  The MODE argument is the machine mode
7139    for the MEM expression that wants to use this address.
7140
7141    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
7142    convert common non-canonical forms to canonical form so that they will
7143    be recognized.  */
7144
7145 int
7146 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
7147                       rtx addr, int strict)
7148 {
7149   struct ix86_address parts;
7150   rtx base, index, disp;
7151   HOST_WIDE_INT scale;
7152   const char *reason = NULL;
7153   rtx reason_rtx = NULL_RTX;
7154
7155   if (ix86_decompose_address (addr, &parts) <= 0)
7156     {
7157       reason = "decomposition failed";
7158       goto report_error;
7159     }
7160
7161   base = parts.base;
7162   index = parts.index;
7163   disp = parts.disp;
7164   scale = parts.scale;
7165
7166   /* Validate base register.
7167
7168      Don't allow SUBREG's that span more than a word here.  It can lead to spill
7169      failures when the base is one word out of a two word structure, which is
7170      represented internally as a DImode int.  */
7171
7172   if (base)
7173     {
7174       rtx reg;
7175       reason_rtx = base;
7176
7177       if (REG_P (base))
7178         reg = base;
7179       else if (GET_CODE (base) == SUBREG
7180                && REG_P (SUBREG_REG (base))
7181                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (base)))
7182                   <= UNITS_PER_WORD)
7183         reg = SUBREG_REG (base);
7184       else
7185         {
7186           reason = "base is not a register";
7187           goto report_error;
7188         }
7189
7190       if (GET_MODE (base) != Pmode)
7191         {
7192           reason = "base is not in Pmode";
7193           goto report_error;
7194         }
7195
7196       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
7197           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
7198         {
7199           reason = "base is not valid";
7200           goto report_error;
7201         }
7202     }
7203
7204   /* Validate index register.
7205
7206      Don't allow SUBREG's that span more than a word here -- same as above.  */
7207
7208   if (index)
7209     {
7210       rtx reg;
7211       reason_rtx = index;
7212
7213       if (REG_P (index))
7214         reg = index;
7215       else if (GET_CODE (index) == SUBREG
7216                && REG_P (SUBREG_REG (index))
7217                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (index)))
7218                   <= UNITS_PER_WORD)
7219         reg = SUBREG_REG (index);
7220       else
7221         {
7222           reason = "index is not a register";
7223           goto report_error;
7224         }
7225
7226       if (GET_MODE (index) != Pmode)
7227         {
7228           reason = "index is not in Pmode";
7229           goto report_error;
7230         }
7231
7232       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
7233           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
7234         {
7235           reason = "index is not valid";
7236           goto report_error;
7237         }
7238     }
7239
7240   /* Validate scale factor.  */
7241   if (scale != 1)
7242     {
7243       reason_rtx = GEN_INT (scale);
7244       if (!index)
7245         {
7246           reason = "scale without index";
7247           goto report_error;
7248         }
7249
7250       if (scale != 2 && scale != 4 && scale != 8)
7251         {
7252           reason = "scale is not a valid multiplier";
7253           goto report_error;
7254         }
7255     }
7256
7257   /* Validate displacement.  */
7258   if (disp)
7259     {
7260       reason_rtx = disp;
7261
7262       if (GET_CODE (disp) == CONST
7263           && GET_CODE (XEXP (disp, 0)) == UNSPEC)
7264         switch (XINT (XEXP (disp, 0), 1))
7265           {
7266           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
7267              used.  While ABI specify also 32bit relocations, we don't produce
7268              them at all and use IP relative instead.  */
7269           case UNSPEC_GOT:
7270           case UNSPEC_GOTOFF:
7271             gcc_assert (flag_pic);
7272             if (!TARGET_64BIT)
7273               goto is_legitimate_pic;
7274             reason = "64bit address unspec";
7275             goto report_error;
7276
7277           case UNSPEC_GOTPCREL:
7278             gcc_assert (flag_pic);
7279             goto is_legitimate_pic;
7280
7281           case UNSPEC_GOTTPOFF:
7282           case UNSPEC_GOTNTPOFF:
7283           case UNSPEC_INDNTPOFF:
7284           case UNSPEC_NTPOFF:
7285           case UNSPEC_DTPOFF:
7286             break;
7287
7288           default:
7289             reason = "invalid address unspec";
7290             goto report_error;
7291           }
7292
7293       else if (SYMBOLIC_CONST (disp)
7294                && (flag_pic
7295                    || (TARGET_MACHO
7296 #if TARGET_MACHO
7297                        && MACHOPIC_INDIRECT
7298                        && !machopic_operand_p (disp)
7299 #endif
7300                )))
7301         {
7302
7303         is_legitimate_pic:
7304           if (TARGET_64BIT && (index || base))
7305             {
7306               /* foo@dtpoff(%rX) is ok.  */
7307               if (GET_CODE (disp) != CONST
7308                   || GET_CODE (XEXP (disp, 0)) != PLUS
7309                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
7310                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
7311                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
7312                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
7313                 {
7314                   reason = "non-constant pic memory reference";
7315                   goto report_error;
7316                 }
7317             }
7318           else if (! legitimate_pic_address_disp_p (disp))
7319             {
7320               reason = "displacement is an invalid pic construct";
7321               goto report_error;
7322             }
7323
7324           /* This code used to verify that a symbolic pic displacement
7325              includes the pic_offset_table_rtx register.
7326
7327              While this is good idea, unfortunately these constructs may
7328              be created by "adds using lea" optimization for incorrect
7329              code like:
7330
7331              int a;
7332              int foo(int i)
7333                {
7334                  return *(&a+i);
7335                }
7336
7337              This code is nonsensical, but results in addressing
7338              GOT table with pic_offset_table_rtx base.  We can't
7339              just refuse it easily, since it gets matched by
7340              "addsi3" pattern, that later gets split to lea in the
7341              case output register differs from input.  While this
7342              can be handled by separate addsi pattern for this case
7343              that never results in lea, this seems to be easier and
7344              correct fix for crash to disable this test.  */
7345         }
7346       else if (GET_CODE (disp) != LABEL_REF
7347                && !CONST_INT_P (disp)
7348                && (GET_CODE (disp) != CONST
7349                    || !legitimate_constant_p (disp))
7350                && (GET_CODE (disp) != SYMBOL_REF
7351                    || !legitimate_constant_p (disp)))
7352         {
7353           reason = "displacement is not constant";
7354           goto report_error;
7355         }
7356       else if (TARGET_64BIT
7357                && !x86_64_immediate_operand (disp, VOIDmode))
7358         {
7359           reason = "displacement is out of range";
7360           goto report_error;
7361         }
7362     }
7363
7364   /* Everything looks valid.  */
7365   return TRUE;
7366
7367  report_error:
7368   return FALSE;
7369 }
7370 \f
7371 /* Return a unique alias set for the GOT.  */
7372
7373 static alias_set_type
7374 ix86_GOT_alias_set (void)
7375 {
7376   static alias_set_type set = -1;
7377   if (set == -1)
7378     set = new_alias_set ();
7379   return set;
7380 }
7381
7382 /* Return a legitimate reference for ORIG (an address) using the
7383    register REG.  If REG is 0, a new pseudo is generated.
7384
7385    There are two types of references that must be handled:
7386
7387    1. Global data references must load the address from the GOT, via
7388       the PIC reg.  An insn is emitted to do this load, and the reg is
7389       returned.
7390
7391    2. Static data references, constant pool addresses, and code labels
7392       compute the address as an offset from the GOT, whose base is in
7393       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
7394       differentiate them from global data objects.  The returned
7395       address is the PIC reg + an unspec constant.
7396
7397    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
7398    reg also appears in the address.  */
7399
7400 static rtx
7401 legitimize_pic_address (rtx orig, rtx reg)
7402 {
7403   rtx addr = orig;
7404   rtx new_rtx = orig;
7405   rtx base;
7406
7407 #if TARGET_MACHO
7408   if (TARGET_MACHO && !TARGET_64BIT)
7409     {
7410       if (reg == 0)
7411         reg = gen_reg_rtx (Pmode);
7412       /* Use the generic Mach-O PIC machinery.  */
7413       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
7414     }
7415 #endif
7416
7417   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
7418     new_rtx = addr;
7419   else if (TARGET_64BIT
7420            && ix86_cmodel != CM_SMALL_PIC
7421            && gotoff_operand (addr, Pmode))
7422     {
7423       rtx tmpreg;
7424       /* This symbol may be referenced via a displacement from the PIC
7425          base address (@GOTOFF).  */
7426
7427       if (reload_in_progress)
7428         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
7429       if (GET_CODE (addr) == CONST)
7430         addr = XEXP (addr, 0);
7431       if (GET_CODE (addr) == PLUS)
7432           {
7433             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
7434                                       UNSPEC_GOTOFF);
7435             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
7436           }
7437         else
7438           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
7439       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
7440       if (!reg)
7441         tmpreg = gen_reg_rtx (Pmode);
7442       else
7443         tmpreg = reg;
7444       emit_move_insn (tmpreg, new_rtx);
7445
7446       if (reg != 0)
7447         {
7448           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
7449                                          tmpreg, 1, OPTAB_DIRECT);
7450           new_rtx = reg;
7451         }
7452       else new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
7453     }
7454   else if (!TARGET_64BIT && gotoff_operand (addr, Pmode))
7455     {
7456       /* This symbol may be referenced via a displacement from the PIC
7457          base address (@GOTOFF).  */
7458
7459       if (reload_in_progress)
7460         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
7461       if (GET_CODE (addr) == CONST)
7462         addr = XEXP (addr, 0);
7463       if (GET_CODE (addr) == PLUS)
7464           {
7465             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
7466                                       UNSPEC_GOTOFF);
7467             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
7468           }
7469         else
7470           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
7471       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
7472       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
7473
7474       if (reg != 0)
7475         {
7476           emit_move_insn (reg, new_rtx);
7477           new_rtx = reg;
7478         }
7479     }
7480   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
7481            /* We can't use @GOTOFF for text labels on VxWorks;
7482               see gotoff_operand.  */
7483            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
7484     {
7485       /* Given that we've already handled dllimport variables separately
7486          in legitimize_address, and all other variables should satisfy
7487          legitimate_pic_address_disp_p, we should never arrive here.  */
7488       gcc_assert (!TARGET_64BIT_MS_ABI);
7489
7490       if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
7491         {
7492           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
7493           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
7494           new_rtx = gen_const_mem (Pmode, new_rtx);
7495           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
7496
7497           if (reg == 0)
7498             reg = gen_reg_rtx (Pmode);
7499           /* Use directly gen_movsi, otherwise the address is loaded
7500              into register for CSE.  We don't want to CSE this addresses,
7501              instead we CSE addresses from the GOT table, so skip this.  */
7502           emit_insn (gen_movsi (reg, new_rtx));
7503           new_rtx = reg;
7504         }
7505       else
7506         {
7507           /* This symbol must be referenced via a load from the
7508              Global Offset Table (@GOT).  */
7509
7510           if (reload_in_progress)
7511             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
7512           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
7513           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
7514           if (TARGET_64BIT)
7515             new_rtx = force_reg (Pmode, new_rtx);
7516           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
7517           new_rtx = gen_const_mem (Pmode, new_rtx);
7518           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
7519
7520           if (reg == 0)
7521             reg = gen_reg_rtx (Pmode);
7522           emit_move_insn (reg, new_rtx);
7523           new_rtx = reg;
7524         }
7525     }
7526   else
7527     {
7528       if (CONST_INT_P (addr)
7529           && !x86_64_immediate_operand (addr, VOIDmode))
7530         {
7531           if (reg)
7532             {
7533               emit_move_insn (reg, addr);
7534               new_rtx = reg;
7535             }
7536           else
7537             new_rtx = force_reg (Pmode, addr);
7538         }
7539       else if (GET_CODE (addr) == CONST)
7540         {
7541           addr = XEXP (addr, 0);
7542
7543           /* We must match stuff we generate before.  Assume the only
7544              unspecs that can get here are ours.  Not that we could do
7545              anything with them anyway....  */
7546           if (GET_CODE (addr) == UNSPEC
7547               || (GET_CODE (addr) == PLUS
7548                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
7549             return orig;
7550           gcc_assert (GET_CODE (addr) == PLUS);
7551         }
7552       if (GET_CODE (addr) == PLUS)
7553         {
7554           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
7555
7556           /* Check first to see if this is a constant offset from a @GOTOFF
7557              symbol reference.  */
7558           if (gotoff_operand (op0, Pmode)
7559               && CONST_INT_P (op1))
7560             {
7561               if (!TARGET_64BIT)
7562                 {
7563                   if (reload_in_progress)
7564                     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
7565                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
7566                                             UNSPEC_GOTOFF);
7567                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
7568                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
7569                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
7570
7571                   if (reg != 0)
7572                     {
7573                       emit_move_insn (reg, new_rtx);
7574                       new_rtx = reg;
7575                     }
7576                 }
7577               else
7578                 {
7579                   if (INTVAL (op1) < -16*1024*1024
7580                       || INTVAL (op1) >= 16*1024*1024)
7581                     {
7582                       if (!x86_64_immediate_operand (op1, Pmode))
7583                         op1 = force_reg (Pmode, op1);
7584                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
7585                     }
7586                 }
7587             }
7588           else
7589             {
7590               base = legitimize_pic_address (XEXP (addr, 0), reg);
7591               new_rtx  = legitimize_pic_address (XEXP (addr, 1),
7592                                                  base == reg ? NULL_RTX : reg);
7593
7594               if (CONST_INT_P (new_rtx))
7595                 new_rtx = plus_constant (base, INTVAL (new_rtx));
7596               else
7597                 {
7598                   if (GET_CODE (new_rtx) == PLUS && CONSTANT_P (XEXP (new_rtx, 1)))
7599                     {
7600                       base = gen_rtx_PLUS (Pmode, base, XEXP (new_rtx, 0));
7601                       new_rtx = XEXP (new_rtx, 1);
7602                     }
7603                   new_rtx = gen_rtx_PLUS (Pmode, base, new_rtx);
7604                 }
7605             }
7606         }
7607     }
7608   return new_rtx;
7609 }
7610 \f
7611 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
7612
7613 static rtx
7614 get_thread_pointer (int to_reg)
7615 {
7616   rtx tp, reg, insn;
7617
7618   tp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
7619   if (!to_reg)
7620     return tp;
7621
7622   reg = gen_reg_rtx (Pmode);
7623   insn = gen_rtx_SET (VOIDmode, reg, tp);
7624   insn = emit_insn (insn);
7625
7626   return reg;
7627 }
7628
7629 /* A subroutine of legitimize_address and ix86_expand_move.  FOR_MOV is
7630    false if we expect this to be used for a memory address and true if
7631    we expect to load the address into a register.  */
7632
7633 static rtx
7634 legitimize_tls_address (rtx x, enum tls_model model, int for_mov)
7635 {
7636   rtx dest, base, off, pic, tp;
7637   int type;
7638
7639   switch (model)
7640     {
7641     case TLS_MODEL_GLOBAL_DYNAMIC:
7642       dest = gen_reg_rtx (Pmode);
7643       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
7644
7645       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
7646         {
7647           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns;
7648
7649           start_sequence ();
7650           emit_call_insn (gen_tls_global_dynamic_64 (rax, x));
7651           insns = get_insns ();
7652           end_sequence ();
7653
7654           CONST_OR_PURE_CALL_P (insns) = 1;
7655           emit_libcall_block (insns, dest, rax, x);
7656         }
7657       else if (TARGET_64BIT && TARGET_GNU2_TLS)
7658         emit_insn (gen_tls_global_dynamic_64 (dest, x));
7659       else
7660         emit_insn (gen_tls_global_dynamic_32 (dest, x));
7661
7662       if (TARGET_GNU2_TLS)
7663         {
7664           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
7665
7666           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
7667         }
7668       break;
7669
7670     case TLS_MODEL_LOCAL_DYNAMIC:
7671       base = gen_reg_rtx (Pmode);
7672       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
7673
7674       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
7675         {
7676           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns, note;
7677
7678           start_sequence ();
7679           emit_call_insn (gen_tls_local_dynamic_base_64 (rax));
7680           insns = get_insns ();
7681           end_sequence ();
7682
7683           note = gen_rtx_EXPR_LIST (VOIDmode, const0_rtx, NULL);
7684           note = gen_rtx_EXPR_LIST (VOIDmode, ix86_tls_get_addr (), note);
7685           CONST_OR_PURE_CALL_P (insns) = 1;
7686           emit_libcall_block (insns, base, rax, note);
7687         }
7688       else if (TARGET_64BIT && TARGET_GNU2_TLS)
7689         emit_insn (gen_tls_local_dynamic_base_64 (base));
7690       else
7691         emit_insn (gen_tls_local_dynamic_base_32 (base));
7692
7693       if (TARGET_GNU2_TLS)
7694         {
7695           rtx x = ix86_tls_module_base ();
7696
7697           set_unique_reg_note (get_last_insn (), REG_EQUIV,
7698                                gen_rtx_MINUS (Pmode, x, tp));
7699         }
7700
7701       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
7702       off = gen_rtx_CONST (Pmode, off);
7703
7704       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
7705
7706       if (TARGET_GNU2_TLS)
7707         {
7708           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
7709
7710           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
7711         }
7712
7713       break;
7714
7715     case TLS_MODEL_INITIAL_EXEC:
7716       if (TARGET_64BIT)
7717         {
7718           pic = NULL;
7719           type = UNSPEC_GOTNTPOFF;
7720         }
7721       else if (flag_pic)
7722         {
7723           if (reload_in_progress)
7724             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
7725           pic = pic_offset_table_rtx;
7726           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
7727         }
7728       else if (!TARGET_ANY_GNU_TLS)
7729         {
7730           pic = gen_reg_rtx (Pmode);
7731           emit_insn (gen_set_got (pic));
7732           type = UNSPEC_GOTTPOFF;
7733         }
7734       else
7735         {
7736           pic = NULL;
7737           type = UNSPEC_INDNTPOFF;
7738         }
7739
7740       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), type);
7741       off = gen_rtx_CONST (Pmode, off);
7742       if (pic)
7743         off = gen_rtx_PLUS (Pmode, pic, off);
7744       off = gen_const_mem (Pmode, off);
7745       set_mem_alias_set (off, ix86_GOT_alias_set ());
7746
7747       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
7748         {
7749           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
7750           off = force_reg (Pmode, off);
7751           return gen_rtx_PLUS (Pmode, base, off);
7752         }
7753       else
7754         {
7755           base = get_thread_pointer (true);
7756           dest = gen_reg_rtx (Pmode);
7757           emit_insn (gen_subsi3 (dest, base, off));
7758         }
7759       break;
7760
7761     case TLS_MODEL_LOCAL_EXEC:
7762       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
7763                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
7764                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
7765       off = gen_rtx_CONST (Pmode, off);
7766
7767       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
7768         {
7769           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
7770           return gen_rtx_PLUS (Pmode, base, off);
7771         }
7772       else
7773         {
7774           base = get_thread_pointer (true);
7775           dest = gen_reg_rtx (Pmode);
7776           emit_insn (gen_subsi3 (dest, base, off));
7777         }
7778       break;
7779
7780     default:
7781       gcc_unreachable ();
7782     }
7783
7784   return dest;
7785 }
7786
7787 /* Create or return the unique __imp_DECL dllimport symbol corresponding
7788    to symbol DECL.  */
7789
7790 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
7791   htab_t dllimport_map;
7792
7793 static tree
7794 get_dllimport_decl (tree decl)
7795 {
7796   struct tree_map *h, in;
7797   void **loc;
7798   const char *name;
7799   const char *prefix;
7800   size_t namelen, prefixlen;
7801   char *imp_name;
7802   tree to;
7803   rtx rtl;
7804
7805   if (!dllimport_map)
7806     dllimport_map = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
7807
7808   in.hash = htab_hash_pointer (decl);
7809   in.base.from = decl;
7810   loc = htab_find_slot_with_hash (dllimport_map, &in, in.hash, INSERT);
7811   h = (struct tree_map *) *loc;
7812   if (h)
7813     return h->to;
7814
7815   *loc = h = GGC_NEW (struct tree_map);
7816   h->hash = in.hash;
7817   h->base.from = decl;
7818   h->to = to = build_decl (VAR_DECL, NULL, ptr_type_node);
7819   DECL_ARTIFICIAL (to) = 1;
7820   DECL_IGNORED_P (to) = 1;
7821   DECL_EXTERNAL (to) = 1;
7822   TREE_READONLY (to) = 1;
7823
7824   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
7825   name = targetm.strip_name_encoding (name);
7826   prefix = name[0] == FASTCALL_PREFIX  ?  "*__imp_": "*__imp__";
7827   namelen = strlen (name);
7828   prefixlen = strlen (prefix);
7829   imp_name = (char *) alloca (namelen + prefixlen + 1);
7830   memcpy (imp_name, prefix, prefixlen);
7831   memcpy (imp_name + prefixlen, name, namelen + 1);
7832
7833   name = ggc_alloc_string (imp_name, namelen + prefixlen);
7834   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
7835   SET_SYMBOL_REF_DECL (rtl, to);
7836   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL;
7837
7838   rtl = gen_const_mem (Pmode, rtl);
7839   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
7840
7841   SET_DECL_RTL (to, rtl);
7842   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
7843
7844   return to;
7845 }
7846
7847 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
7848    true if we require the result be a register.  */
7849
7850 static rtx
7851 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
7852 {
7853   tree imp_decl;
7854   rtx x;
7855
7856   gcc_assert (SYMBOL_REF_DECL (symbol));
7857   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol));
7858
7859   x = DECL_RTL (imp_decl);
7860   if (want_reg)
7861     x = force_reg (Pmode, x);
7862   return x;
7863 }
7864
7865 /* Try machine-dependent ways of modifying an illegitimate address
7866    to be legitimate.  If we find one, return the new, valid address.
7867    This macro is used in only one place: `memory_address' in explow.c.
7868
7869    OLDX is the address as it was before break_out_memory_refs was called.
7870    In some cases it is useful to look at this to decide what needs to be done.
7871
7872    MODE and WIN are passed so that this macro can use
7873    GO_IF_LEGITIMATE_ADDRESS.
7874
7875    It is always safe for this macro to do nothing.  It exists to recognize
7876    opportunities to optimize the output.
7877
7878    For the 80386, we handle X+REG by loading X into a register R and
7879    using R+REG.  R will go in a general reg and indexing will be used.
7880    However, if REG is a broken-out memory address or multiplication,
7881    nothing needs to be done because REG can certainly go in a general reg.
7882
7883    When -fpic is used, special handling is needed for symbolic references.
7884    See comments by legitimize_pic_address in i386.c for details.  */
7885
7886 rtx
7887 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
7888 {
7889   int changed = 0;
7890   unsigned log;
7891
7892   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
7893   if (log)
7894     return legitimize_tls_address (x, (enum tls_model) log, false);
7895   if (GET_CODE (x) == CONST
7896       && GET_CODE (XEXP (x, 0)) == PLUS
7897       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
7898       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
7899     {
7900       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
7901                                       (enum tls_model) log, false);
7902       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
7903     }
7904
7905   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
7906     {
7907       if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (x))
7908         return legitimize_dllimport_symbol (x, true);
7909       if (GET_CODE (x) == CONST
7910           && GET_CODE (XEXP (x, 0)) == PLUS
7911           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
7912           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (x, 0), 0)))
7913         {
7914           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (x, 0), 0), true);
7915           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
7916         }
7917     }
7918
7919   if (flag_pic && SYMBOLIC_CONST (x))
7920     return legitimize_pic_address (x, 0);
7921
7922   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
7923   if (GET_CODE (x) == ASHIFT
7924       && CONST_INT_P (XEXP (x, 1))
7925       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
7926     {
7927       changed = 1;
7928       log = INTVAL (XEXP (x, 1));
7929       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
7930                         GEN_INT (1 << log));
7931     }
7932
7933   if (GET_CODE (x) == PLUS)
7934     {
7935       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
7936
7937       if (GET_CODE (XEXP (x, 0)) == ASHIFT
7938           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
7939           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
7940         {
7941           changed = 1;
7942           log = INTVAL (XEXP (XEXP (x, 0), 1));
7943           XEXP (x, 0) = gen_rtx_MULT (Pmode,
7944                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
7945                                       GEN_INT (1 << log));
7946         }
7947
7948       if (GET_CODE (XEXP (x, 1)) == ASHIFT
7949           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
7950           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
7951         {
7952           changed = 1;
7953           log = INTVAL (XEXP (XEXP (x, 1), 1));
7954           XEXP (x, 1) = gen_rtx_MULT (Pmode,
7955                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
7956                                       GEN_INT (1 << log));
7957         }
7958
7959       /* Put multiply first if it isn't already.  */
7960       if (GET_CODE (XEXP (x, 1)) == MULT)
7961         {
7962           rtx tmp = XEXP (x, 0);
7963           XEXP (x, 0) = XEXP (x, 1);
7964           XEXP (x, 1) = tmp;
7965           changed = 1;
7966         }
7967
7968       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
7969          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
7970          created by virtual register instantiation, register elimination, and
7971          similar optimizations.  */
7972       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
7973         {
7974           changed = 1;
7975           x = gen_rtx_PLUS (Pmode,
7976                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
7977                                           XEXP (XEXP (x, 1), 0)),
7978                             XEXP (XEXP (x, 1), 1));
7979         }
7980
7981       /* Canonicalize
7982          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
7983          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
7984       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
7985                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
7986                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
7987                && CONSTANT_P (XEXP (x, 1)))
7988         {
7989           rtx constant;
7990           rtx other = NULL_RTX;
7991
7992           if (CONST_INT_P (XEXP (x, 1)))
7993             {
7994               constant = XEXP (x, 1);
7995               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
7996             }
7997           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
7998             {
7999               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
8000               other = XEXP (x, 1);
8001             }
8002           else
8003             constant = 0;
8004
8005           if (constant)
8006             {
8007               changed = 1;
8008               x = gen_rtx_PLUS (Pmode,
8009                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
8010                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
8011                                 plus_constant (other, INTVAL (constant)));
8012             }
8013         }
8014
8015       if (changed && legitimate_address_p (mode, x, FALSE))
8016         return x;
8017
8018       if (GET_CODE (XEXP (x, 0)) == MULT)
8019         {
8020           changed = 1;
8021           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
8022         }
8023
8024       if (GET_CODE (XEXP (x, 1)) == MULT)
8025         {
8026           changed = 1;
8027           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
8028         }
8029
8030       if (changed
8031           && REG_P (XEXP (x, 1))
8032           && REG_P (XEXP (x, 0)))
8033         return x;
8034
8035       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
8036         {
8037           changed = 1;
8038           x = legitimize_pic_address (x, 0);
8039         }
8040
8041       if (changed && legitimate_address_p (mode, x, FALSE))
8042         return x;
8043
8044       if (REG_P (XEXP (x, 0)))
8045         {
8046           rtx temp = gen_reg_rtx (Pmode);
8047           rtx val  = force_operand (XEXP (x, 1), temp);
8048           if (val != temp)
8049             emit_move_insn (temp, val);
8050
8051           XEXP (x, 1) = temp;
8052           return x;
8053         }
8054
8055       else if (REG_P (XEXP (x, 1)))
8056         {
8057           rtx temp = gen_reg_rtx (Pmode);
8058           rtx val  = force_operand (XEXP (x, 0), temp);
8059           if (val != temp)
8060             emit_move_insn (temp, val);
8061
8062           XEXP (x, 0) = temp;
8063           return x;
8064         }
8065     }
8066
8067   return x;
8068 }
8069 \f
8070 /* Print an integer constant expression in assembler syntax.  Addition
8071    and subtraction are the only arithmetic that may appear in these
8072    expressions.  FILE is the stdio stream to write to, X is the rtx, and
8073    CODE is the operand print code from the output string.  */
8074
8075 static void
8076 output_pic_addr_const (FILE *file, rtx x, int code)
8077 {
8078   char buf[256];
8079
8080   switch (GET_CODE (x))
8081     {
8082     case PC:
8083       gcc_assert (flag_pic);
8084       putc ('.', file);
8085       break;
8086
8087     case SYMBOL_REF:
8088       if (! TARGET_MACHO || TARGET_64BIT)
8089         output_addr_const (file, x);
8090       else
8091         {
8092           const char *name = XSTR (x, 0);
8093
8094           /* Mark the decl as referenced so that cgraph will
8095              output the function.  */
8096           if (SYMBOL_REF_DECL (x))
8097             mark_decl_referenced (SYMBOL_REF_DECL (x));
8098
8099 #if TARGET_MACHO
8100           if (MACHOPIC_INDIRECT
8101               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
8102             name = machopic_indirection_name (x, /*stub_p=*/true);
8103 #endif
8104           assemble_name (file, name);
8105         }
8106       if (!TARGET_MACHO && !TARGET_64BIT_MS_ABI
8107           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
8108         fputs ("@PLT", file);
8109       break;
8110
8111     case LABEL_REF:
8112       x = XEXP (x, 0);
8113       /* FALLTHRU */
8114     case CODE_LABEL:
8115       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
8116       assemble_name (asm_out_file, buf);
8117       break;
8118
8119     case CONST_INT:
8120       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
8121       break;
8122
8123     case CONST:
8124       /* This used to output parentheses around the expression,
8125          but that does not work on the 386 (either ATT or BSD assembler).  */
8126       output_pic_addr_const (file, XEXP (x, 0), code);
8127       break;
8128
8129     case CONST_DOUBLE:
8130       if (GET_MODE (x) == VOIDmode)
8131         {
8132           /* We can use %d if the number is <32 bits and positive.  */
8133           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
8134             fprintf (file, "0x%lx%08lx",
8135                      (unsigned long) CONST_DOUBLE_HIGH (x),
8136                      (unsigned long) CONST_DOUBLE_LOW (x));
8137           else
8138             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
8139         }
8140       else
8141         /* We can't handle floating point constants;
8142            PRINT_OPERAND must handle them.  */
8143         output_operand_lossage ("floating constant misused");
8144       break;
8145
8146     case PLUS:
8147       /* Some assemblers need integer constants to appear first.  */
8148       if (CONST_INT_P (XEXP (x, 0)))
8149         {
8150           output_pic_addr_const (file, XEXP (x, 0), code);
8151           putc ('+', file);
8152           output_pic_addr_const (file, XEXP (x, 1), code);
8153         }
8154       else
8155         {
8156           gcc_assert (CONST_INT_P (XEXP (x, 1)));
8157           output_pic_addr_const (file, XEXP (x, 1), code);
8158           putc ('+', file);
8159           output_pic_addr_const (file, XEXP (x, 0), code);
8160         }
8161       break;
8162
8163     case MINUS:
8164       if (!TARGET_MACHO)
8165         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
8166       output_pic_addr_const (file, XEXP (x, 0), code);
8167       putc ('-', file);
8168       output_pic_addr_const (file, XEXP (x, 1), code);
8169       if (!TARGET_MACHO)
8170         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
8171       break;
8172
8173      case UNSPEC:
8174        gcc_assert (XVECLEN (x, 0) == 1);
8175        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
8176        switch (XINT (x, 1))
8177         {
8178         case UNSPEC_GOT:
8179           fputs ("@GOT", file);
8180           break;
8181         case UNSPEC_GOTOFF:
8182           fputs ("@GOTOFF", file);
8183           break;
8184         case UNSPEC_PLTOFF:
8185           fputs ("@PLTOFF", file);
8186           break;
8187         case UNSPEC_GOTPCREL:
8188           fputs ("@GOTPCREL(%rip)", file);
8189           break;
8190         case UNSPEC_GOTTPOFF:
8191           /* FIXME: This might be @TPOFF in Sun ld too.  */
8192           fputs ("@GOTTPOFF", file);
8193           break;
8194         case UNSPEC_TPOFF:
8195           fputs ("@TPOFF", file);
8196           break;
8197         case UNSPEC_NTPOFF:
8198           if (TARGET_64BIT)
8199             fputs ("@TPOFF", file);
8200           else
8201             fputs ("@NTPOFF", file);
8202           break;
8203         case UNSPEC_DTPOFF:
8204           fputs ("@DTPOFF", file);
8205           break;
8206         case UNSPEC_GOTNTPOFF:
8207           if (TARGET_64BIT)
8208             fputs ("@GOTTPOFF(%rip)", file);
8209           else
8210             fputs ("@GOTNTPOFF", file);
8211           break;
8212         case UNSPEC_INDNTPOFF:
8213           fputs ("@INDNTPOFF", file);
8214           break;
8215         default:
8216           output_operand_lossage ("invalid UNSPEC as operand");
8217           break;
8218         }
8219        break;
8220
8221     default:
8222       output_operand_lossage ("invalid expression as operand");
8223     }
8224 }
8225
8226 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
8227    We need to emit DTP-relative relocations.  */
8228
8229 static void ATTRIBUTE_UNUSED
8230 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
8231 {
8232   fputs (ASM_LONG, file);
8233   output_addr_const (file, x);
8234   fputs ("@DTPOFF", file);
8235   switch (size)
8236     {
8237     case 4:
8238       break;
8239     case 8:
8240       fputs (", 0", file);
8241       break;
8242     default:
8243       gcc_unreachable ();
8244    }
8245 }
8246
8247 /* In the name of slightly smaller debug output, and to cater to
8248    general assembler lossage, recognize PIC+GOTOFF and turn it back
8249    into a direct symbol reference.
8250
8251    On Darwin, this is necessary to avoid a crash, because Darwin
8252    has a different PIC label for each routine but the DWARF debugging
8253    information is not associated with any particular routine, so it's
8254    necessary to remove references to the PIC label from RTL stored by
8255    the DWARF output code.  */
8256
8257 static rtx
8258 ix86_delegitimize_address (rtx orig_x)
8259 {
8260   rtx x = orig_x;
8261   /* reg_addend is NULL or a multiple of some register.  */
8262   rtx reg_addend = NULL_RTX;
8263   /* const_addend is NULL or a const_int.  */
8264   rtx const_addend = NULL_RTX;
8265   /* This is the result, or NULL.  */
8266   rtx result = NULL_RTX;
8267
8268   if (MEM_P (x))
8269     x = XEXP (x, 0);
8270
8271   if (TARGET_64BIT)
8272     {
8273       if (GET_CODE (x) != CONST
8274           || GET_CODE (XEXP (x, 0)) != UNSPEC
8275           || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL
8276           || !MEM_P (orig_x))
8277         return orig_x;
8278       return XVECEXP (XEXP (x, 0), 0, 0);
8279     }
8280
8281   if (GET_CODE (x) != PLUS
8282       || GET_CODE (XEXP (x, 1)) != CONST)
8283     return orig_x;
8284
8285   if (REG_P (XEXP (x, 0))
8286       && REGNO (XEXP (x, 0)) == PIC_OFFSET_TABLE_REGNUM)
8287     /* %ebx + GOT/GOTOFF */
8288     ;
8289   else if (GET_CODE (XEXP (x, 0)) == PLUS)
8290     {
8291       /* %ebx + %reg * scale + GOT/GOTOFF */
8292       reg_addend = XEXP (x, 0);
8293       if (REG_P (XEXP (reg_addend, 0))
8294           && REGNO (XEXP (reg_addend, 0)) == PIC_OFFSET_TABLE_REGNUM)
8295         reg_addend = XEXP (reg_addend, 1);
8296       else if (REG_P (XEXP (reg_addend, 1))
8297                && REGNO (XEXP (reg_addend, 1)) == PIC_OFFSET_TABLE_REGNUM)
8298         reg_addend = XEXP (reg_addend, 0);
8299       else
8300         return orig_x;
8301       if (!REG_P (reg_addend)
8302           && GET_CODE (reg_addend) != MULT
8303           && GET_CODE (reg_addend) != ASHIFT)
8304         return orig_x;
8305     }
8306   else
8307     return orig_x;
8308
8309   x = XEXP (XEXP (x, 1), 0);
8310   if (GET_CODE (x) == PLUS
8311       && CONST_INT_P (XEXP (x, 1)))
8312     {
8313       const_addend = XEXP (x, 1);
8314       x = XEXP (x, 0);
8315     }
8316
8317   if (GET_CODE (x) == UNSPEC
8318       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x))
8319           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))))
8320     result = XVECEXP (x, 0, 0);
8321
8322   if (TARGET_MACHO && darwin_local_data_pic (x)
8323       && !MEM_P (orig_x))
8324     result = XEXP (x, 0);
8325
8326   if (! result)
8327     return orig_x;
8328
8329   if (const_addend)
8330     result = gen_rtx_PLUS (Pmode, result, const_addend);
8331   if (reg_addend)
8332     result = gen_rtx_PLUS (Pmode, reg_addend, result);
8333   return result;
8334 }
8335
8336 /* If X is a machine specific address (i.e. a symbol or label being
8337    referenced as a displacement from the GOT implemented using an
8338    UNSPEC), then return the base term.  Otherwise return X.  */
8339
8340 rtx
8341 ix86_find_base_term (rtx x)
8342 {
8343   rtx term;
8344
8345   if (TARGET_64BIT)
8346     {
8347       if (GET_CODE (x) != CONST)
8348         return x;
8349       term = XEXP (x, 0);
8350       if (GET_CODE (term) == PLUS
8351           && (CONST_INT_P (XEXP (term, 1))
8352               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
8353         term = XEXP (term, 0);
8354       if (GET_CODE (term) != UNSPEC
8355           || XINT (term, 1) != UNSPEC_GOTPCREL)
8356         return x;
8357
8358       term = XVECEXP (term, 0, 0);
8359
8360       if (GET_CODE (term) != SYMBOL_REF
8361           && GET_CODE (term) != LABEL_REF)
8362         return x;
8363
8364       return term;
8365     }
8366
8367   term = ix86_delegitimize_address (x);
8368
8369   if (GET_CODE (term) != SYMBOL_REF
8370       && GET_CODE (term) != LABEL_REF)
8371     return x;
8372
8373   return term;
8374 }
8375 \f
8376 static void
8377 put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
8378                     int fp, FILE *file)
8379 {
8380   const char *suffix;
8381
8382   if (mode == CCFPmode || mode == CCFPUmode)
8383     {
8384       enum rtx_code second_code, bypass_code;
8385       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
8386       gcc_assert (bypass_code == UNKNOWN && second_code == UNKNOWN);
8387       code = ix86_fp_compare_code_to_integer (code);
8388       mode = CCmode;
8389     }
8390   if (reverse)
8391     code = reverse_condition (code);
8392
8393   switch (code)
8394     {
8395     case EQ:
8396       switch (mode)
8397         {
8398         case CCAmode:
8399           suffix = "a";
8400           break;
8401
8402         case CCCmode:
8403           suffix = "c";
8404           break;
8405
8406         case CCOmode:
8407           suffix = "o";
8408           break;
8409
8410         case CCSmode:
8411           suffix = "s";
8412           break;
8413
8414         default:
8415           suffix = "e";
8416         }
8417       break;
8418     case NE:
8419       switch (mode)
8420         {
8421         case CCAmode:
8422           suffix = "na";
8423           break;
8424
8425         case CCCmode:
8426           suffix = "nc";
8427           break;
8428
8429         case CCOmode:
8430           suffix = "no";
8431           break;
8432
8433         case CCSmode:
8434           suffix = "ns";
8435           break;
8436
8437         default:
8438           suffix = "ne";
8439         }
8440       break;
8441     case GT:
8442       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
8443       suffix = "g";
8444       break;
8445     case GTU:
8446       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
8447          Those same assemblers have the same but opposite lossage on cmov.  */
8448       if (mode == CCmode)
8449         suffix = fp ? "nbe" : "a";
8450       else if (mode == CCCmode)
8451         suffix = "b";
8452       else
8453         gcc_unreachable ();
8454       break;
8455     case LT:
8456       switch (mode)
8457         {
8458         case CCNOmode:
8459         case CCGOCmode:
8460           suffix = "s";
8461           break;
8462
8463         case CCmode:
8464         case CCGCmode:
8465           suffix = "l";
8466           break;
8467
8468         default:
8469           gcc_unreachable ();
8470         }
8471       break;
8472     case LTU:
8473       gcc_assert (mode == CCmode || mode == CCCmode);
8474       suffix = "b";
8475       break;
8476     case GE:
8477       switch (mode)
8478         {
8479         case CCNOmode:
8480         case CCGOCmode:
8481           suffix = "ns";
8482           break;
8483
8484         case CCmode:
8485         case CCGCmode:
8486           suffix = "ge";
8487           break;
8488
8489         default:
8490           gcc_unreachable ();
8491         }
8492       break;
8493     case GEU:
8494       /* ??? As above.  */
8495       gcc_assert (mode == CCmode || mode == CCCmode);
8496       suffix = fp ? "nb" : "ae";
8497       break;
8498     case LE:
8499       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
8500       suffix = "le";
8501       break;
8502     case LEU:
8503       /* ??? As above.  */
8504       if (mode == CCmode)
8505         suffix = "be";
8506       else if (mode == CCCmode)
8507         suffix = fp ? "nb" : "ae";
8508       else
8509         gcc_unreachable ();
8510       break;
8511     case UNORDERED:
8512       suffix = fp ? "u" : "p";
8513       break;
8514     case ORDERED:
8515       suffix = fp ? "nu" : "np";
8516       break;
8517     default:
8518       gcc_unreachable ();
8519     }
8520   fputs (suffix, file);
8521 }
8522
8523 /* Print the name of register X to FILE based on its machine mode and number.
8524    If CODE is 'w', pretend the mode is HImode.
8525    If CODE is 'b', pretend the mode is QImode.
8526    If CODE is 'k', pretend the mode is SImode.
8527    If CODE is 'q', pretend the mode is DImode.
8528    If CODE is 'h', pretend the reg is the 'high' byte register.
8529    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.  */
8530
8531 void
8532 print_reg (rtx x, int code, FILE *file)
8533 {
8534   gcc_assert (REGNO (x) != ARG_POINTER_REGNUM
8535               && REGNO (x) != FRAME_POINTER_REGNUM
8536               && REGNO (x) != FLAGS_REG
8537               && REGNO (x) != FPSR_REG
8538               && REGNO (x) != FPCR_REG);
8539
8540   if (ASSEMBLER_DIALECT == ASM_ATT || USER_LABEL_PREFIX[0] == 0)
8541     putc ('%', file);
8542
8543   if (code == 'w' || MMX_REG_P (x))
8544     code = 2;
8545   else if (code == 'b')
8546     code = 1;
8547   else if (code == 'k')
8548     code = 4;
8549   else if (code == 'q')
8550     code = 8;
8551   else if (code == 'y')
8552     code = 3;
8553   else if (code == 'h')
8554     code = 0;
8555   else
8556     code = GET_MODE_SIZE (GET_MODE (x));
8557
8558   /* Irritatingly, AMD extended registers use different naming convention
8559      from the normal registers.  */
8560   if (REX_INT_REG_P (x))
8561     {
8562       gcc_assert (TARGET_64BIT);
8563       switch (code)
8564         {
8565           case 0:
8566             error ("extended registers have no high halves");
8567             break;
8568           case 1:
8569             fprintf (file, "r%ib", REGNO (x) - FIRST_REX_INT_REG + 8);
8570             break;
8571           case 2:
8572             fprintf (file, "r%iw", REGNO (x) - FIRST_REX_INT_REG + 8);
8573             break;
8574           case 4:
8575             fprintf (file, "r%id", REGNO (x) - FIRST_REX_INT_REG + 8);
8576             break;
8577           case 8:
8578             fprintf (file, "r%i", REGNO (x) - FIRST_REX_INT_REG + 8);
8579             break;
8580           default:
8581             error ("unsupported operand size for extended register");
8582             break;
8583         }
8584       return;
8585     }
8586   switch (code)
8587     {
8588     case 3:
8589       if (STACK_TOP_P (x))
8590         {
8591           fputs ("st(0)", file);
8592           break;
8593         }
8594       /* FALLTHRU */
8595     case 8:
8596     case 4:
8597     case 12:
8598       if (! ANY_FP_REG_P (x))
8599         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
8600       /* FALLTHRU */
8601     case 16:
8602     case 2:
8603     normal:
8604       fputs (hi_reg_name[REGNO (x)], file);
8605       break;
8606     case 1:
8607       if (REGNO (x) >= ARRAY_SIZE (qi_reg_name))
8608         goto normal;
8609       fputs (qi_reg_name[REGNO (x)], file);
8610       break;
8611     case 0:
8612       if (REGNO (x) >= ARRAY_SIZE (qi_high_reg_name))
8613         goto normal;
8614       fputs (qi_high_reg_name[REGNO (x)], file);
8615       break;
8616     default:
8617       gcc_unreachable ();
8618     }
8619 }
8620
8621 /* Locate some local-dynamic symbol still in use by this function
8622    so that we can print its name in some tls_local_dynamic_base
8623    pattern.  */
8624
8625 static int
8626 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
8627 {
8628   rtx x = *px;
8629
8630   if (GET_CODE (x) == SYMBOL_REF
8631       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8632     {
8633       cfun->machine->some_ld_name = XSTR (x, 0);
8634       return 1;
8635     }
8636
8637   return 0;
8638 }
8639
8640 static const char *
8641 get_some_local_dynamic_name (void)
8642 {
8643   rtx insn;
8644
8645   if (cfun->machine->some_ld_name)
8646     return cfun->machine->some_ld_name;
8647
8648   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8649     if (INSN_P (insn)
8650         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
8651       return cfun->machine->some_ld_name;
8652
8653   gcc_unreachable ();
8654 }
8655
8656 /* Meaning of CODE:
8657    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
8658    C -- print opcode suffix for set/cmov insn.
8659    c -- like C, but print reversed condition
8660    F,f -- likewise, but for floating-point.
8661    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
8662         otherwise nothing
8663    R -- print the prefix for register names.
8664    z -- print the opcode suffix for the size of the current operand.
8665    * -- print a star (in certain assembler syntax)
8666    A -- print an absolute memory reference.
8667    w -- print the operand as if it's a "word" (HImode) even if it isn't.
8668    s -- print a shift double count, followed by the assemblers argument
8669         delimiter.
8670    b -- print the QImode name of the register for the indicated operand.
8671         %b0 would print %al if operands[0] is reg 0.
8672    w --  likewise, print the HImode name of the register.
8673    k --  likewise, print the SImode name of the register.
8674    q --  likewise, print the DImode name of the register.
8675    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
8676    y -- print "st(0)" instead of "st" as a register.
8677    D -- print condition for SSE cmp instruction.
8678    P -- if PIC, print an @PLT suffix.
8679    X -- don't print any sort of PIC '@' suffix for a symbol.
8680    & -- print some in-use local-dynamic symbol name.
8681    H -- print a memory address offset by 8; used for sse high-parts
8682    Y -- print condition for SSE5 com* instruction.
8683    + -- print a branch hint as 'cs' or 'ds' prefix
8684    ; -- print a semicolon (after prefixes due to bug in older gas).
8685  */
8686
8687 void
8688 print_operand (FILE *file, rtx x, int code)
8689 {
8690   if (code)
8691     {
8692       switch (code)
8693         {
8694         case '*':
8695           if (ASSEMBLER_DIALECT == ASM_ATT)
8696             putc ('*', file);
8697           return;
8698
8699         case '&':
8700           assemble_name (file, get_some_local_dynamic_name ());
8701           return;
8702
8703         case 'A':
8704           switch (ASSEMBLER_DIALECT)
8705             {
8706             case ASM_ATT:
8707               putc ('*', file);
8708               break;
8709
8710             case ASM_INTEL:
8711               /* Intel syntax. For absolute addresses, registers should not
8712                  be surrounded by braces.  */
8713               if (!REG_P (x))
8714                 {
8715                   putc ('[', file);
8716                   PRINT_OPERAND (file, x, 0);
8717                   putc (']', file);
8718                   return;
8719                 }
8720               break;
8721
8722             default:
8723               gcc_unreachable ();
8724             }
8725
8726           PRINT_OPERAND (file, x, 0);
8727           return;
8728
8729
8730         case 'L':
8731           if (ASSEMBLER_DIALECT == ASM_ATT)
8732             putc ('l', file);
8733           return;
8734
8735         case 'W':
8736           if (ASSEMBLER_DIALECT == ASM_ATT)
8737             putc ('w', file);
8738           return;
8739
8740         case 'B':
8741           if (ASSEMBLER_DIALECT == ASM_ATT)
8742             putc ('b', file);
8743           return;
8744
8745         case 'Q':
8746           if (ASSEMBLER_DIALECT == ASM_ATT)
8747             putc ('l', file);
8748           return;
8749
8750         case 'S':
8751           if (ASSEMBLER_DIALECT == ASM_ATT)
8752             putc ('s', file);
8753           return;
8754
8755         case 'T':
8756           if (ASSEMBLER_DIALECT == ASM_ATT)
8757             putc ('t', file);
8758           return;
8759
8760         case 'z':
8761           /* 387 opcodes don't get size suffixes if the operands are
8762              registers.  */
8763           if (STACK_REG_P (x))
8764             return;
8765
8766           /* Likewise if using Intel opcodes.  */
8767           if (ASSEMBLER_DIALECT == ASM_INTEL)
8768             return;
8769
8770           /* This is the size of op from size of operand.  */
8771           switch (GET_MODE_SIZE (GET_MODE (x)))
8772             {
8773             case 1:
8774               putc ('b', file);
8775               return;
8776
8777             case 2:
8778               if (MEM_P (x))
8779                 {
8780 #ifdef HAVE_GAS_FILDS_FISTS
8781                   putc ('s', file);
8782 #endif
8783                   return;
8784                 }
8785               else
8786                 putc ('w', file);
8787               return;
8788
8789             case 4:
8790               if (GET_MODE (x) == SFmode)
8791                 {
8792                   putc ('s', file);
8793                   return;
8794                 }
8795               else
8796                 putc ('l', file);
8797               return;
8798
8799             case 12:
8800             case 16:
8801               putc ('t', file);
8802               return;
8803
8804             case 8:
8805               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
8806                 {
8807 #ifdef GAS_MNEMONICS
8808                   putc ('q', file);
8809 #else
8810                   putc ('l', file);
8811                   putc ('l', file);
8812 #endif
8813                 }
8814               else
8815                 putc ('l', file);
8816               return;
8817
8818             default:
8819               gcc_unreachable ();
8820             }
8821
8822         case 'b':
8823         case 'w':
8824         case 'k':
8825         case 'q':
8826         case 'h':
8827         case 'y':
8828         case 'X':
8829         case 'P':
8830           break;
8831
8832         case 's':
8833           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
8834             {
8835               PRINT_OPERAND (file, x, 0);
8836               putc (',', file);
8837             }
8838           return;
8839
8840         case 'D':
8841           /* Little bit of braindamage here.  The SSE compare instructions
8842              does use completely different names for the comparisons that the
8843              fp conditional moves.  */
8844           switch (GET_CODE (x))
8845             {
8846             case EQ:
8847             case UNEQ:
8848               fputs ("eq", file);
8849               break;
8850             case LT:
8851             case UNLT:
8852               fputs ("lt", file);
8853               break;
8854             case LE:
8855             case UNLE:
8856               fputs ("le", file);
8857               break;
8858             case UNORDERED:
8859               fputs ("unord", file);
8860               break;
8861             case NE:
8862             case LTGT:
8863               fputs ("neq", file);
8864               break;
8865             case UNGE:
8866             case GE:
8867               fputs ("nlt", file);
8868               break;
8869             case UNGT:
8870             case GT:
8871               fputs ("nle", file);
8872               break;
8873             case ORDERED:
8874               fputs ("ord", file);
8875               break;
8876             default:
8877               gcc_unreachable ();
8878             }
8879           return;
8880         case 'O':
8881 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
8882           if (ASSEMBLER_DIALECT == ASM_ATT)
8883             {
8884               switch (GET_MODE (x))
8885                 {
8886                 case HImode: putc ('w', file); break;
8887                 case SImode:
8888                 case SFmode: putc ('l', file); break;
8889                 case DImode:
8890                 case DFmode: putc ('q', file); break;
8891                 default: gcc_unreachable ();
8892                 }
8893               putc ('.', file);
8894             }
8895 #endif
8896           return;
8897         case 'C':
8898           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
8899           return;
8900         case 'F':
8901 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
8902           if (ASSEMBLER_DIALECT == ASM_ATT)
8903             putc ('.', file);
8904 #endif
8905           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
8906           return;
8907
8908           /* Like above, but reverse condition */
8909         case 'c':
8910           /* Check to see if argument to %c is really a constant
8911              and not a condition code which needs to be reversed.  */
8912           if (!COMPARISON_P (x))
8913           {
8914             output_operand_lossage ("operand is neither a constant nor a condition code, invalid operand code 'c'");
8915              return;
8916           }
8917           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
8918           return;
8919         case 'f':
8920 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
8921           if (ASSEMBLER_DIALECT == ASM_ATT)
8922             putc ('.', file);
8923 #endif
8924           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
8925           return;
8926
8927         case 'H':
8928           /* It doesn't actually matter what mode we use here, as we're
8929              only going to use this for printing.  */
8930           x = adjust_address_nv (x, DImode, 8);
8931           break;
8932
8933         case '+':
8934           {
8935             rtx x;
8936
8937             if (!optimize || optimize_size || !TARGET_BRANCH_PREDICTION_HINTS)
8938               return;
8939
8940             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
8941             if (x)
8942               {
8943                 int pred_val = INTVAL (XEXP (x, 0));
8944
8945                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
8946                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
8947                   {
8948                     int taken = pred_val > REG_BR_PROB_BASE / 2;
8949                     int cputaken = final_forward_branch_p (current_output_insn) == 0;
8950
8951                     /* Emit hints only in the case default branch prediction
8952                        heuristics would fail.  */
8953                     if (taken != cputaken)
8954                       {
8955                         /* We use 3e (DS) prefix for taken branches and
8956                            2e (CS) prefix for not taken branches.  */
8957                         if (taken)
8958                           fputs ("ds ; ", file);
8959                         else
8960                           fputs ("cs ; ", file);
8961                       }
8962                   }
8963               }
8964             return;
8965           }
8966
8967         case 'Y':
8968           switch (GET_CODE (x))
8969             {
8970             case NE:
8971               fputs ("neq", file);
8972               break;
8973             case EQ:
8974               fputs ("eq", file);
8975               break;
8976             case GE:
8977             case GEU:
8978               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
8979               break;
8980             case GT:
8981             case GTU:
8982               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
8983               break;
8984             case LE:
8985             case LEU:
8986               fputs ("le", file);
8987               break;
8988             case LT:
8989             case LTU:
8990               fputs ("lt", file);
8991               break;
8992             case UNORDERED:
8993               fputs ("unord", file);
8994               break;
8995             case ORDERED:
8996               fputs ("ord", file);
8997               break;
8998             case UNEQ:
8999               fputs ("ueq", file);
9000               break;
9001             case UNGE:
9002               fputs ("nlt", file);
9003               break;
9004             case UNGT:
9005               fputs ("nle", file);
9006               break;
9007             case UNLE:
9008               fputs ("ule", file);
9009               break;
9010             case UNLT:
9011               fputs ("ult", file);
9012               break;
9013             case LTGT:
9014               fputs ("une", file);
9015               break;
9016             default:
9017               gcc_unreachable ();
9018             }
9019           return;
9020
9021         case ';':
9022 #if TARGET_MACHO
9023           fputs (" ; ", file);
9024 #else
9025           fputc (' ', file);
9026 #endif
9027           return;
9028
9029         default:
9030             output_operand_lossage ("invalid operand code '%c'", code);
9031         }
9032     }
9033
9034   if (REG_P (x))
9035     print_reg (x, code, file);
9036
9037   else if (MEM_P (x))
9038     {
9039       /* No `byte ptr' prefix for call instructions.  */
9040       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P')
9041         {
9042           const char * size;
9043           switch (GET_MODE_SIZE (GET_MODE (x)))
9044             {
9045             case 1: size = "BYTE"; break;
9046             case 2: size = "WORD"; break;
9047             case 4: size = "DWORD"; break;
9048             case 8: size = "QWORD"; break;
9049             case 12: size = "XWORD"; break;
9050             case 16: size = "XMMWORD"; break;
9051             default:
9052               gcc_unreachable ();
9053             }
9054
9055           /* Check for explicit size override (codes 'b', 'w' and 'k')  */
9056           if (code == 'b')
9057             size = "BYTE";
9058           else if (code == 'w')
9059             size = "WORD";
9060           else if (code == 'k')
9061             size = "DWORD";
9062
9063           fputs (size, file);
9064           fputs (" PTR ", file);
9065         }
9066
9067       x = XEXP (x, 0);
9068       /* Avoid (%rip) for call operands.  */
9069       if (CONSTANT_ADDRESS_P (x) && code == 'P'
9070           && !CONST_INT_P (x))
9071         output_addr_const (file, x);
9072       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
9073         output_operand_lossage ("invalid constraints for operand");
9074       else
9075         output_address (x);
9076     }
9077
9078   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9079     {
9080       REAL_VALUE_TYPE r;
9081       long l;
9082
9083       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
9084       REAL_VALUE_TO_TARGET_SINGLE (r, l);
9085
9086       if (ASSEMBLER_DIALECT == ASM_ATT)
9087         putc ('$', file);
9088       fprintf (file, "0x%08lx", l);
9089     }
9090
9091   /* These float cases don't actually occur as immediate operands.  */
9092   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9093     {
9094       char dstr[30];
9095
9096       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
9097       fprintf (file, "%s", dstr);
9098     }
9099
9100   else if (GET_CODE (x) == CONST_DOUBLE
9101            && GET_MODE (x) == XFmode)
9102     {
9103       char dstr[30];
9104
9105       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
9106       fprintf (file, "%s", dstr);
9107     }
9108
9109   else
9110     {
9111       /* We have patterns that allow zero sets of memory, for instance.
9112          In 64-bit mode, we should probably support all 8-byte vectors,
9113          since we can in fact encode that into an immediate.  */
9114       if (GET_CODE (x) == CONST_VECTOR)
9115         {
9116           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
9117           x = const0_rtx;
9118         }
9119
9120       if (code != 'P')
9121         {
9122           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
9123             {
9124               if (ASSEMBLER_DIALECT == ASM_ATT)
9125                 putc ('$', file);
9126             }
9127           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
9128                    || GET_CODE (x) == LABEL_REF)
9129             {
9130               if (ASSEMBLER_DIALECT == ASM_ATT)
9131                 putc ('$', file);
9132               else
9133                 fputs ("OFFSET FLAT:", file);
9134             }
9135         }
9136       if (CONST_INT_P (x))
9137         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
9138       else if (flag_pic)
9139         output_pic_addr_const (file, x, code);
9140       else
9141         output_addr_const (file, x);
9142     }
9143 }
9144 \f
9145 /* Print a memory operand whose address is ADDR.  */
9146
9147 void
9148 print_operand_address (FILE *file, rtx addr)
9149 {
9150   struct ix86_address parts;
9151   rtx base, index, disp;
9152   int scale;
9153   int ok = ix86_decompose_address (addr, &parts);
9154
9155   gcc_assert (ok);
9156
9157   base = parts.base;
9158   index = parts.index;
9159   disp = parts.disp;
9160   scale = parts.scale;
9161
9162   switch (parts.seg)
9163     {
9164     case SEG_DEFAULT:
9165       break;
9166     case SEG_FS:
9167     case SEG_GS:
9168       if (USER_LABEL_PREFIX[0] == 0)
9169         putc ('%', file);
9170       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
9171       break;
9172     default:
9173       gcc_unreachable ();
9174     }
9175
9176   if (!base && !index)
9177     {
9178       /* Displacement only requires special attention.  */
9179
9180       if (CONST_INT_P (disp))
9181         {
9182           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
9183             {
9184               if (USER_LABEL_PREFIX[0] == 0)
9185                 putc ('%', file);
9186               fputs ("ds:", file);
9187             }
9188           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
9189         }
9190       else if (flag_pic)
9191         output_pic_addr_const (file, disp, 0);
9192       else
9193         output_addr_const (file, disp);
9194
9195       /* Use one byte shorter RIP relative addressing for 64bit mode.  */
9196       if (TARGET_64BIT)
9197         {
9198           if (GET_CODE (disp) == CONST
9199               && GET_CODE (XEXP (disp, 0)) == PLUS
9200               && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
9201             disp = XEXP (XEXP (disp, 0), 0);
9202           if (GET_CODE (disp) == LABEL_REF
9203               || (GET_CODE (disp) == SYMBOL_REF
9204                   && SYMBOL_REF_TLS_MODEL (disp) == 0))
9205             fputs ("(%rip)", file);
9206         }
9207     }
9208   else
9209     {
9210       if (ASSEMBLER_DIALECT == ASM_ATT)
9211         {
9212           if (disp)
9213             {
9214               if (flag_pic)
9215                 output_pic_addr_const (file, disp, 0);
9216               else if (GET_CODE (disp) == LABEL_REF)
9217                 output_asm_label (disp);
9218               else
9219                 output_addr_const (file, disp);
9220             }
9221
9222           putc ('(', file);
9223           if (base)
9224             print_reg (base, 0, file);
9225           if (index)
9226             {
9227               putc (',', file);
9228               print_reg (index, 0, file);
9229               if (scale != 1)
9230                 fprintf (file, ",%d", scale);
9231             }
9232           putc (')', file);
9233         }
9234       else
9235         {
9236           rtx offset = NULL_RTX;
9237
9238           if (disp)
9239             {
9240               /* Pull out the offset of a symbol; print any symbol itself.  */
9241               if (GET_CODE (disp) == CONST
9242                   && GET_CODE (XEXP (disp, 0)) == PLUS
9243                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
9244                 {
9245                   offset = XEXP (XEXP (disp, 0), 1);
9246                   disp = gen_rtx_CONST (VOIDmode,
9247                                         XEXP (XEXP (disp, 0), 0));
9248                 }
9249
9250               if (flag_pic)
9251                 output_pic_addr_const (file, disp, 0);
9252               else if (GET_CODE (disp) == LABEL_REF)
9253                 output_asm_label (disp);
9254               else if (CONST_INT_P (disp))
9255                 offset = disp;
9256               else
9257                 output_addr_const (file, disp);
9258             }
9259
9260           putc ('[', file);
9261           if (base)
9262             {
9263               print_reg (base, 0, file);
9264               if (offset)
9265                 {
9266                   if (INTVAL (offset) >= 0)
9267                     putc ('+', file);
9268                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
9269                 }
9270             }
9271           else if (offset)
9272             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
9273           else
9274             putc ('0', file);
9275
9276           if (index)
9277             {
9278               putc ('+', file);
9279               print_reg (index, 0, file);
9280               if (scale != 1)
9281                 fprintf (file, "*%d", scale);
9282             }
9283           putc (']', file);
9284         }
9285     }
9286 }
9287
9288 bool
9289 output_addr_const_extra (FILE *file, rtx x)
9290 {
9291   rtx op;
9292
9293   if (GET_CODE (x) != UNSPEC)
9294     return false;
9295
9296   op = XVECEXP (x, 0, 0);
9297   switch (XINT (x, 1))
9298     {
9299     case UNSPEC_GOTTPOFF:
9300       output_addr_const (file, op);
9301       /* FIXME: This might be @TPOFF in Sun ld.  */
9302       fputs ("@GOTTPOFF", file);
9303       break;
9304     case UNSPEC_TPOFF:
9305       output_addr_const (file, op);
9306       fputs ("@TPOFF", file);
9307       break;
9308     case UNSPEC_NTPOFF:
9309       output_addr_const (file, op);
9310       if (TARGET_64BIT)
9311         fputs ("@TPOFF", file);
9312       else
9313         fputs ("@NTPOFF", file);
9314       break;
9315     case UNSPEC_DTPOFF:
9316       output_addr_const (file, op);
9317       fputs ("@DTPOFF", file);
9318       break;
9319     case UNSPEC_GOTNTPOFF:
9320       output_addr_const (file, op);
9321       if (TARGET_64BIT)
9322         fputs ("@GOTTPOFF(%rip)", file);
9323       else
9324         fputs ("@GOTNTPOFF", file);
9325       break;
9326     case UNSPEC_INDNTPOFF:
9327       output_addr_const (file, op);
9328       fputs ("@INDNTPOFF", file);
9329       break;
9330
9331     default:
9332       return false;
9333     }
9334
9335   return true;
9336 }
9337 \f
9338 /* Split one or more DImode RTL references into pairs of SImode
9339    references.  The RTL can be REG, offsettable MEM, integer constant, or
9340    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
9341    split and "num" is its length.  lo_half and hi_half are output arrays
9342    that parallel "operands".  */
9343
9344 void
9345 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
9346 {
9347   while (num--)
9348     {
9349       rtx op = operands[num];
9350
9351       /* simplify_subreg refuse to split volatile memory addresses,
9352          but we still have to handle it.  */
9353       if (MEM_P (op))
9354         {
9355           lo_half[num] = adjust_address (op, SImode, 0);
9356           hi_half[num] = adjust_address (op, SImode, 4);
9357         }
9358       else
9359         {
9360           lo_half[num] = simplify_gen_subreg (SImode, op,
9361                                               GET_MODE (op) == VOIDmode
9362                                               ? DImode : GET_MODE (op), 0);
9363           hi_half[num] = simplify_gen_subreg (SImode, op,
9364                                               GET_MODE (op) == VOIDmode
9365                                               ? DImode : GET_MODE (op), 4);
9366         }
9367     }
9368 }
9369 /* Split one or more TImode RTL references into pairs of DImode
9370    references.  The RTL can be REG, offsettable MEM, integer constant, or
9371    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
9372    split and "num" is its length.  lo_half and hi_half are output arrays
9373    that parallel "operands".  */
9374
9375 void
9376 split_ti (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
9377 {
9378   while (num--)
9379     {
9380       rtx op = operands[num];
9381
9382       /* simplify_subreg refuse to split volatile memory addresses, but we
9383          still have to handle it.  */
9384       if (MEM_P (op))
9385         {
9386           lo_half[num] = adjust_address (op, DImode, 0);
9387           hi_half[num] = adjust_address (op, DImode, 8);
9388         }
9389       else
9390         {
9391           lo_half[num] = simplify_gen_subreg (DImode, op, TImode, 0);
9392           hi_half[num] = simplify_gen_subreg (DImode, op, TImode, 8);
9393         }
9394     }
9395 }
9396 \f
9397 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
9398    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
9399    is the expression of the binary operation.  The output may either be
9400    emitted here, or returned to the caller, like all output_* functions.
9401
9402    There is no guarantee that the operands are the same mode, as they
9403    might be within FLOAT or FLOAT_EXTEND expressions.  */
9404
9405 #ifndef SYSV386_COMPAT
9406 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
9407    wants to fix the assemblers because that causes incompatibility
9408    with gcc.  No-one wants to fix gcc because that causes
9409    incompatibility with assemblers...  You can use the option of
9410    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
9411 #define SYSV386_COMPAT 1
9412 #endif
9413
9414 const char *
9415 output_387_binary_op (rtx insn, rtx *operands)
9416 {
9417   static char buf[30];
9418   const char *p;
9419   const char *ssep;
9420   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
9421
9422 #ifdef ENABLE_CHECKING
9423   /* Even if we do not want to check the inputs, this documents input
9424      constraints.  Which helps in understanding the following code.  */
9425   if (STACK_REG_P (operands[0])
9426       && ((REG_P (operands[1])
9427            && REGNO (operands[0]) == REGNO (operands[1])
9428            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
9429           || (REG_P (operands[2])
9430               && REGNO (operands[0]) == REGNO (operands[2])
9431               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
9432       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
9433     ; /* ok */
9434   else
9435     gcc_assert (is_sse);
9436 #endif
9437
9438   switch (GET_CODE (operands[3]))
9439     {
9440     case PLUS:
9441       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
9442           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
9443         p = "fiadd";
9444       else
9445         p = "fadd";
9446       ssep = "add";
9447       break;
9448
9449     case MINUS:
9450       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
9451           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
9452         p = "fisub";
9453       else
9454         p = "fsub";
9455       ssep = "sub";
9456       break;
9457
9458     case MULT:
9459       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
9460           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
9461         p = "fimul";
9462       else
9463         p = "fmul";
9464       ssep = "mul";
9465       break;
9466
9467     case DIV:
9468       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
9469           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
9470         p = "fidiv";
9471       else
9472         p = "fdiv";
9473       ssep = "div";
9474       break;
9475
9476     default:
9477       gcc_unreachable ();
9478     }
9479
9480   if (is_sse)
9481    {
9482       strcpy (buf, ssep);
9483       if (GET_MODE (operands[0]) == SFmode)
9484         strcat (buf, "ss\t{%2, %0|%0, %2}");
9485       else
9486         strcat (buf, "sd\t{%2, %0|%0, %2}");
9487       return buf;
9488    }
9489   strcpy (buf, p);
9490
9491   switch (GET_CODE (operands[3]))
9492     {
9493     case MULT:
9494     case PLUS:
9495       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
9496         {
9497           rtx temp = operands[2];
9498           operands[2] = operands[1];
9499           operands[1] = temp;
9500         }
9501
9502       /* know operands[0] == operands[1].  */
9503
9504       if (MEM_P (operands[2]))
9505         {
9506           p = "%z2\t%2";
9507           break;
9508         }
9509
9510       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
9511         {
9512           if (STACK_TOP_P (operands[0]))
9513             /* How is it that we are storing to a dead operand[2]?
9514                Well, presumably operands[1] is dead too.  We can't
9515                store the result to st(0) as st(0) gets popped on this
9516                instruction.  Instead store to operands[2] (which I
9517                think has to be st(1)).  st(1) will be popped later.
9518                gcc <= 2.8.1 didn't have this check and generated
9519                assembly code that the Unixware assembler rejected.  */
9520             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
9521           else
9522             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
9523           break;
9524         }
9525
9526       if (STACK_TOP_P (operands[0]))
9527         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
9528       else
9529         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
9530       break;
9531
9532     case MINUS:
9533     case DIV:
9534       if (MEM_P (operands[1]))
9535         {
9536           p = "r%z1\t%1";
9537           break;
9538         }
9539
9540       if (MEM_P (operands[2]))
9541         {
9542           p = "%z2\t%2";
9543           break;
9544         }
9545
9546       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
9547         {
9548 #if SYSV386_COMPAT
9549           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
9550              derived assemblers, confusingly reverse the direction of
9551              the operation for fsub{r} and fdiv{r} when the
9552              destination register is not st(0).  The Intel assembler
9553              doesn't have this brain damage.  Read !SYSV386_COMPAT to
9554              figure out what the hardware really does.  */
9555           if (STACK_TOP_P (operands[0]))
9556             p = "{p\t%0, %2|rp\t%2, %0}";
9557           else
9558             p = "{rp\t%2, %0|p\t%0, %2}";
9559 #else
9560           if (STACK_TOP_P (operands[0]))
9561             /* As above for fmul/fadd, we can't store to st(0).  */
9562             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
9563           else
9564             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
9565 #endif
9566           break;
9567         }
9568
9569       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
9570         {
9571 #if SYSV386_COMPAT
9572           if (STACK_TOP_P (operands[0]))
9573             p = "{rp\t%0, %1|p\t%1, %0}";
9574           else
9575             p = "{p\t%1, %0|rp\t%0, %1}";
9576 #else
9577           if (STACK_TOP_P (operands[0]))
9578             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
9579           else
9580             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
9581 #endif
9582           break;
9583         }
9584
9585       if (STACK_TOP_P (operands[0]))
9586         {
9587           if (STACK_TOP_P (operands[1]))
9588             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
9589           else
9590             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
9591           break;
9592         }
9593       else if (STACK_TOP_P (operands[1]))
9594         {
9595 #if SYSV386_COMPAT
9596           p = "{\t%1, %0|r\t%0, %1}";
9597 #else
9598           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
9599 #endif
9600         }
9601       else
9602         {
9603 #if SYSV386_COMPAT
9604           p = "{r\t%2, %0|\t%0, %2}";
9605 #else
9606           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
9607 #endif
9608         }
9609       break;
9610
9611     default:
9612       gcc_unreachable ();
9613     }
9614
9615   strcat (buf, p);
9616   return buf;
9617 }
9618
9619 /* Return needed mode for entity in optimize_mode_switching pass.  */
9620
9621 int
9622 ix86_mode_needed (int entity, rtx insn)
9623 {
9624   enum attr_i387_cw mode;
9625
9626   /* The mode UNINITIALIZED is used to store control word after a
9627      function call or ASM pattern.  The mode ANY specify that function
9628      has no requirements on the control word and make no changes in the
9629      bits we are interested in.  */
9630
9631   if (CALL_P (insn)
9632       || (NONJUMP_INSN_P (insn)
9633           && (asm_noperands (PATTERN (insn)) >= 0
9634               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
9635     return I387_CW_UNINITIALIZED;
9636
9637   if (recog_memoized (insn) < 0)
9638     return I387_CW_ANY;
9639
9640   mode = get_attr_i387_cw (insn);
9641
9642   switch (entity)
9643     {
9644     case I387_TRUNC:
9645       if (mode == I387_CW_TRUNC)
9646         return mode;
9647       break;
9648
9649     case I387_FLOOR:
9650       if (mode == I387_CW_FLOOR)
9651         return mode;
9652       break;
9653
9654     case I387_CEIL:
9655       if (mode == I387_CW_CEIL)
9656         return mode;
9657       break;
9658
9659     case I387_MASK_PM:
9660       if (mode == I387_CW_MASK_PM)
9661         return mode;
9662       break;
9663
9664     default:
9665       gcc_unreachable ();
9666     }
9667
9668   return I387_CW_ANY;
9669 }
9670
9671 /* Output code to initialize control word copies used by trunc?f?i and
9672    rounding patterns.  CURRENT_MODE is set to current control word,
9673    while NEW_MODE is set to new control word.  */
9674
9675 void
9676 emit_i387_cw_initialization (int mode)
9677 {
9678   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
9679   rtx new_mode;
9680
9681   enum ix86_stack_slot slot;
9682
9683   rtx reg = gen_reg_rtx (HImode);
9684
9685   emit_insn (gen_x86_fnstcw_1 (stored_mode));
9686   emit_move_insn (reg, copy_rtx (stored_mode));
9687
9688   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL || optimize_size)
9689     {
9690       switch (mode)
9691         {
9692         case I387_CW_TRUNC:
9693           /* round toward zero (truncate) */
9694           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
9695           slot = SLOT_CW_TRUNC;
9696           break;
9697
9698         case I387_CW_FLOOR:
9699           /* round down toward -oo */
9700           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
9701           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
9702           slot = SLOT_CW_FLOOR;
9703           break;
9704
9705         case I387_CW_CEIL:
9706           /* round up toward +oo */
9707           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
9708           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
9709           slot = SLOT_CW_CEIL;
9710           break;
9711
9712         case I387_CW_MASK_PM:
9713           /* mask precision exception for nearbyint() */
9714           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
9715           slot = SLOT_CW_MASK_PM;
9716           break;
9717
9718         default:
9719           gcc_unreachable ();
9720         }
9721     }
9722   else
9723     {
9724       switch (mode)
9725         {
9726         case I387_CW_TRUNC:
9727           /* round toward zero (truncate) */
9728           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
9729           slot = SLOT_CW_TRUNC;
9730           break;
9731
9732         case I387_CW_FLOOR:
9733           /* round down toward -oo */
9734           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
9735           slot = SLOT_CW_FLOOR;
9736           break;
9737
9738         case I387_CW_CEIL:
9739           /* round up toward +oo */
9740           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
9741           slot = SLOT_CW_CEIL;
9742           break;
9743
9744         case I387_CW_MASK_PM:
9745           /* mask precision exception for nearbyint() */
9746           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
9747           slot = SLOT_CW_MASK_PM;
9748           break;
9749
9750         default:
9751           gcc_unreachable ();
9752         }
9753     }
9754
9755   gcc_assert (slot < MAX_386_STACK_LOCALS);
9756
9757   new_mode = assign_386_stack_local (HImode, slot);
9758   emit_move_insn (new_mode, reg);
9759 }
9760
9761 /* Output code for INSN to convert a float to a signed int.  OPERANDS
9762    are the insn operands.  The output may be [HSD]Imode and the input
9763    operand may be [SDX]Fmode.  */
9764
9765 const char *
9766 output_fix_trunc (rtx insn, rtx *operands, int fisttp)
9767 {
9768   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
9769   int dimode_p = GET_MODE (operands[0]) == DImode;
9770   int round_mode = get_attr_i387_cw (insn);
9771
9772   /* Jump through a hoop or two for DImode, since the hardware has no
9773      non-popping instruction.  We used to do this a different way, but
9774      that was somewhat fragile and broke with post-reload splitters.  */
9775   if ((dimode_p || fisttp) && !stack_top_dies)
9776     output_asm_insn ("fld\t%y1", operands);
9777
9778   gcc_assert (STACK_TOP_P (operands[1]));
9779   gcc_assert (MEM_P (operands[0]));
9780   gcc_assert (GET_MODE (operands[1]) != TFmode);
9781
9782   if (fisttp)
9783       output_asm_insn ("fisttp%z0\t%0", operands);
9784   else
9785     {
9786       if (round_mode != I387_CW_ANY)
9787         output_asm_insn ("fldcw\t%3", operands);
9788       if (stack_top_dies || dimode_p)
9789         output_asm_insn ("fistp%z0\t%0", operands);
9790       else
9791         output_asm_insn ("fist%z0\t%0", operands);
9792       if (round_mode != I387_CW_ANY)
9793         output_asm_insn ("fldcw\t%2", operands);
9794     }
9795
9796   return "";
9797 }
9798
9799 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
9800    have the values zero or one, indicates the ffreep insn's operand
9801    from the OPERANDS array.  */
9802
9803 static const char *
9804 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
9805 {
9806   if (TARGET_USE_FFREEP)
9807 #if HAVE_AS_IX86_FFREEP
9808     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
9809 #else
9810     {
9811       static char retval[] = ".word\t0xc_df";
9812       int regno = REGNO (operands[opno]);
9813
9814       gcc_assert (FP_REGNO_P (regno));
9815
9816       retval[9] = '0' + (regno - FIRST_STACK_REG);
9817       return retval;
9818     }
9819 #endif
9820
9821   return opno ? "fstp\t%y1" : "fstp\t%y0";
9822 }
9823
9824
9825 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
9826    should be used.  UNORDERED_P is true when fucom should be used.  */
9827
9828 const char *
9829 output_fp_compare (rtx insn, rtx *operands, int eflags_p, int unordered_p)
9830 {
9831   int stack_top_dies;
9832   rtx cmp_op0, cmp_op1;
9833   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
9834
9835   if (eflags_p)
9836     {
9837       cmp_op0 = operands[0];
9838       cmp_op1 = operands[1];
9839     }
9840   else
9841     {
9842       cmp_op0 = operands[1];
9843       cmp_op1 = operands[2];
9844     }
9845
9846   if (is_sse)
9847     {
9848       if (GET_MODE (operands[0]) == SFmode)
9849         if (unordered_p)
9850           return "ucomiss\t{%1, %0|%0, %1}";
9851         else
9852           return "comiss\t{%1, %0|%0, %1}";
9853       else
9854         if (unordered_p)
9855           return "ucomisd\t{%1, %0|%0, %1}";
9856         else
9857           return "comisd\t{%1, %0|%0, %1}";
9858     }
9859
9860   gcc_assert (STACK_TOP_P (cmp_op0));
9861
9862   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
9863
9864   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
9865     {
9866       if (stack_top_dies)
9867         {
9868           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
9869           return output_387_ffreep (operands, 1);
9870         }
9871       else
9872         return "ftst\n\tfnstsw\t%0";
9873     }
9874
9875   if (STACK_REG_P (cmp_op1)
9876       && stack_top_dies
9877       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
9878       && REGNO (cmp_op1) != FIRST_STACK_REG)
9879     {
9880       /* If both the top of the 387 stack dies, and the other operand
9881          is also a stack register that dies, then this must be a
9882          `fcompp' float compare */
9883
9884       if (eflags_p)
9885         {
9886           /* There is no double popping fcomi variant.  Fortunately,
9887              eflags is immune from the fstp's cc clobbering.  */
9888           if (unordered_p)
9889             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
9890           else
9891             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
9892           return output_387_ffreep (operands, 0);
9893         }
9894       else
9895         {
9896           if (unordered_p)
9897             return "fucompp\n\tfnstsw\t%0";
9898           else
9899             return "fcompp\n\tfnstsw\t%0";
9900         }
9901     }
9902   else
9903     {
9904       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
9905
9906       static const char * const alt[16] =
9907       {
9908         "fcom%z2\t%y2\n\tfnstsw\t%0",
9909         "fcomp%z2\t%y2\n\tfnstsw\t%0",
9910         "fucom%z2\t%y2\n\tfnstsw\t%0",
9911         "fucomp%z2\t%y2\n\tfnstsw\t%0",
9912
9913         "ficom%z2\t%y2\n\tfnstsw\t%0",
9914         "ficomp%z2\t%y2\n\tfnstsw\t%0",
9915         NULL,
9916         NULL,
9917
9918         "fcomi\t{%y1, %0|%0, %y1}",
9919         "fcomip\t{%y1, %0|%0, %y1}",
9920         "fucomi\t{%y1, %0|%0, %y1}",
9921         "fucomip\t{%y1, %0|%0, %y1}",
9922
9923         NULL,
9924         NULL,
9925         NULL,
9926         NULL
9927       };
9928
9929       int mask;
9930       const char *ret;
9931
9932       mask  = eflags_p << 3;
9933       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
9934       mask |= unordered_p << 1;
9935       mask |= stack_top_dies;
9936
9937       gcc_assert (mask < 16);
9938       ret = alt[mask];
9939       gcc_assert (ret);
9940
9941       return ret;
9942     }
9943 }
9944
9945 void
9946 ix86_output_addr_vec_elt (FILE *file, int value)
9947 {
9948   const char *directive = ASM_LONG;
9949
9950 #ifdef ASM_QUAD
9951   if (TARGET_64BIT)
9952     directive = ASM_QUAD;
9953 #else
9954   gcc_assert (!TARGET_64BIT);
9955 #endif
9956
9957   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
9958 }
9959
9960 void
9961 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
9962 {
9963   const char *directive = ASM_LONG;
9964
9965 #ifdef ASM_QUAD
9966   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
9967     directive = ASM_QUAD;
9968 #else
9969   gcc_assert (!TARGET_64BIT);
9970 #endif
9971   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
9972   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
9973     fprintf (file, "%s%s%d-%s%d\n",
9974              directive, LPREFIX, value, LPREFIX, rel);
9975   else if (HAVE_AS_GOTOFF_IN_DATA)
9976     fprintf (file, "%s%s%d@GOTOFF\n", ASM_LONG, LPREFIX, value);
9977 #if TARGET_MACHO
9978   else if (TARGET_MACHO)
9979     {
9980       fprintf (file, "%s%s%d-", ASM_LONG, LPREFIX, value);
9981       machopic_output_function_base_name (file);
9982       fprintf(file, "\n");
9983     }
9984 #endif
9985   else
9986     asm_fprintf (file, "%s%U%s+[.-%s%d]\n",
9987                  ASM_LONG, GOT_SYMBOL_NAME, LPREFIX, value);
9988 }
9989 \f
9990 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
9991    for the target.  */
9992
9993 void
9994 ix86_expand_clear (rtx dest)
9995 {
9996   rtx tmp;
9997
9998   /* We play register width games, which are only valid after reload.  */
9999   gcc_assert (reload_completed);
10000
10001   /* Avoid HImode and its attendant prefix byte.  */
10002   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
10003     dest = gen_rtx_REG (SImode, REGNO (dest));
10004   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
10005
10006   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
10007   if (reload_completed && (!TARGET_USE_MOV0 || optimize_size))
10008     {
10009       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
10010       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
10011     }
10012
10013   emit_insn (tmp);
10014 }
10015
10016 /* X is an unchanging MEM.  If it is a constant pool reference, return
10017    the constant pool rtx, else NULL.  */
10018
10019 rtx
10020 maybe_get_pool_constant (rtx x)
10021 {
10022   x = ix86_delegitimize_address (XEXP (x, 0));
10023
10024   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
10025     return get_pool_constant (x);
10026
10027   return NULL_RTX;
10028 }
10029
10030 void
10031 ix86_expand_move (enum machine_mode mode, rtx operands[])
10032 {
10033   rtx op0, op1;
10034   enum tls_model model;
10035
10036   op0 = operands[0];
10037   op1 = operands[1];
10038
10039   if (GET_CODE (op1) == SYMBOL_REF)
10040     {
10041       model = SYMBOL_REF_TLS_MODEL (op1);
10042       if (model)
10043         {
10044           op1 = legitimize_tls_address (op1, model, true);
10045           op1 = force_operand (op1, op0);
10046           if (op1 == op0)
10047             return;
10048         }
10049       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
10050                && SYMBOL_REF_DLLIMPORT_P (op1))
10051         op1 = legitimize_dllimport_symbol (op1, false);
10052     }
10053   else if (GET_CODE (op1) == CONST
10054            && GET_CODE (XEXP (op1, 0)) == PLUS
10055            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
10056     {
10057       rtx addend = XEXP (XEXP (op1, 0), 1);
10058       rtx symbol = XEXP (XEXP (op1, 0), 0);
10059       rtx tmp = NULL;
10060
10061       model = SYMBOL_REF_TLS_MODEL (symbol);
10062       if (model)
10063         tmp = legitimize_tls_address (symbol, model, true);
10064       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
10065                && SYMBOL_REF_DLLIMPORT_P (symbol))
10066         tmp = legitimize_dllimport_symbol (symbol, true);
10067
10068       if (tmp)
10069         {
10070           tmp = force_operand (tmp, NULL);
10071           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
10072                                      op0, 1, OPTAB_DIRECT);
10073           if (tmp == op0)
10074             return;
10075         }
10076     }
10077
10078   if (flag_pic && mode == Pmode && symbolic_operand (op1, Pmode))
10079     {
10080       if (TARGET_MACHO && !TARGET_64BIT)
10081         {
10082 #if TARGET_MACHO
10083           if (MACHOPIC_PURE)
10084             {
10085               rtx temp = ((reload_in_progress
10086                            || ((op0 && REG_P (op0))
10087                                && mode == Pmode))
10088                           ? op0 : gen_reg_rtx (Pmode));
10089               op1 = machopic_indirect_data_reference (op1, temp);
10090               op1 = machopic_legitimize_pic_address (op1, mode,
10091                                                      temp == op1 ? 0 : temp);
10092             }
10093           else if (MACHOPIC_INDIRECT)
10094             op1 = machopic_indirect_data_reference (op1, 0);
10095           if (op0 == op1)
10096             return;
10097 #endif
10098         }
10099       else
10100         {
10101           if (MEM_P (op0))
10102             op1 = force_reg (Pmode, op1);
10103           else if (!TARGET_64BIT || !x86_64_movabs_operand (op1, Pmode))
10104             {
10105               rtx reg = !can_create_pseudo_p () ? op0 : NULL_RTX;
10106               op1 = legitimize_pic_address (op1, reg);
10107               if (op0 == op1)
10108                 return;
10109             }
10110         }
10111     }
10112   else
10113     {
10114       if (MEM_P (op0)
10115           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
10116               || !push_operand (op0, mode))
10117           && MEM_P (op1))
10118         op1 = force_reg (mode, op1);
10119
10120       if (push_operand (op0, mode)
10121           && ! general_no_elim_operand (op1, mode))
10122         op1 = copy_to_mode_reg (mode, op1);
10123
10124       /* Force large constants in 64bit compilation into register
10125          to get them CSEed.  */
10126       if (can_create_pseudo_p ()
10127           && (mode == DImode) && TARGET_64BIT
10128           && immediate_operand (op1, mode)
10129           && !x86_64_zext_immediate_operand (op1, VOIDmode)
10130           && !register_operand (op0, mode)
10131           && optimize)
10132         op1 = copy_to_mode_reg (mode, op1);
10133
10134       if (can_create_pseudo_p ()
10135           && FLOAT_MODE_P (mode)
10136           && GET_CODE (op1) == CONST_DOUBLE)
10137         {
10138           /* If we are loading a floating point constant to a register,
10139              force the value to memory now, since we'll get better code
10140              out the back end.  */
10141
10142           op1 = validize_mem (force_const_mem (mode, op1));
10143           if (!register_operand (op0, mode))
10144             {
10145               rtx temp = gen_reg_rtx (mode);
10146               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
10147               emit_move_insn (op0, temp);
10148               return;
10149             }
10150         }
10151     }
10152
10153   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
10154 }
10155
10156 void
10157 ix86_expand_vector_move (enum machine_mode mode, rtx operands[])
10158 {
10159   rtx op0 = operands[0], op1 = operands[1];
10160   unsigned int align = GET_MODE_ALIGNMENT (mode);
10161
10162   /* Force constants other than zero into memory.  We do not know how
10163      the instructions used to build constants modify the upper 64 bits
10164      of the register, once we have that information we may be able
10165      to handle some of them more efficiently.  */
10166   if (can_create_pseudo_p ()
10167       && register_operand (op0, mode)
10168       && (CONSTANT_P (op1)
10169           || (GET_CODE (op1) == SUBREG
10170               && CONSTANT_P (SUBREG_REG (op1))))
10171       && standard_sse_constant_p (op1) <= 0)
10172     op1 = validize_mem (force_const_mem (mode, op1));
10173
10174   /* TDmode values are passed as TImode on the stack.  TImode values
10175      are moved via xmm registers, and moving them to stack can result in
10176      unaligned memory access.  Use ix86_expand_vector_move_misalign()
10177      if memory operand is not aligned correctly.  */
10178   if (can_create_pseudo_p ()
10179       && (mode == TImode) && !TARGET_64BIT
10180       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
10181           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
10182     {
10183       rtx tmp[2];
10184
10185       /* ix86_expand_vector_move_misalign() does not like constants ... */
10186       if (CONSTANT_P (op1)
10187           || (GET_CODE (op1) == SUBREG
10188               && CONSTANT_P (SUBREG_REG (op1))))
10189         op1 = validize_mem (force_const_mem (mode, op1));
10190
10191       /* ... nor both arguments in memory.  */
10192       if (!register_operand (op0, mode)
10193           && !register_operand (op1, mode))
10194         op1 = force_reg (mode, op1);
10195
10196       tmp[0] = op0; tmp[1] = op1;
10197       ix86_expand_vector_move_misalign (mode, tmp);
10198       return;
10199     }
10200
10201   /* Make operand1 a register if it isn't already.  */
10202   if (can_create_pseudo_p ()
10203       && !register_operand (op0, mode)
10204       && !register_operand (op1, mode))
10205     {
10206       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
10207       return;
10208     }
10209
10210   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
10211 }
10212
10213 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
10214    straight to ix86_expand_vector_move.  */
10215 /* Code generation for scalar reg-reg moves of single and double precision data:
10216      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
10217        movaps reg, reg
10218      else
10219        movss reg, reg
10220      if (x86_sse_partial_reg_dependency == true)
10221        movapd reg, reg
10222      else
10223        movsd reg, reg
10224
10225    Code generation for scalar loads of double precision data:
10226      if (x86_sse_split_regs == true)
10227        movlpd mem, reg      (gas syntax)
10228      else
10229        movsd mem, reg
10230
10231    Code generation for unaligned packed loads of single precision data
10232    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
10233      if (x86_sse_unaligned_move_optimal)
10234        movups mem, reg
10235
10236      if (x86_sse_partial_reg_dependency == true)
10237        {
10238          xorps  reg, reg
10239          movlps mem, reg
10240          movhps mem+8, reg
10241        }
10242      else
10243        {
10244          movlps mem, reg
10245          movhps mem+8, reg
10246        }
10247
10248    Code generation for unaligned packed loads of double precision data
10249    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
10250      if (x86_sse_unaligned_move_optimal)
10251        movupd mem, reg
10252
10253      if (x86_sse_split_regs == true)
10254        {
10255          movlpd mem, reg
10256          movhpd mem+8, reg
10257        }
10258      else
10259        {
10260          movsd  mem, reg
10261          movhpd mem+8, reg
10262        }
10263  */
10264
10265 void
10266 ix86_expand_vector_move_misalign (enum machine_mode mode, rtx operands[])
10267 {
10268   rtx op0, op1, m;
10269
10270   op0 = operands[0];
10271   op1 = operands[1];
10272
10273   if (MEM_P (op1))
10274     {
10275       /* If we're optimizing for size, movups is the smallest.  */
10276       if (optimize_size)
10277         {
10278           op0 = gen_lowpart (V4SFmode, op0);
10279           op1 = gen_lowpart (V4SFmode, op1);
10280           emit_insn (gen_sse_movups (op0, op1));
10281           return;
10282         }
10283
10284       /* ??? If we have typed data, then it would appear that using
10285          movdqu is the only way to get unaligned data loaded with
10286          integer type.  */
10287       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
10288         {
10289           op0 = gen_lowpart (V16QImode, op0);
10290           op1 = gen_lowpart (V16QImode, op1);
10291           emit_insn (gen_sse2_movdqu (op0, op1));
10292           return;
10293         }
10294
10295       if (TARGET_SSE2 && mode == V2DFmode)
10296         {
10297           rtx zero;
10298
10299           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
10300             {
10301               op0 = gen_lowpart (V2DFmode, op0);
10302               op1 = gen_lowpart (V2DFmode, op1);
10303               emit_insn (gen_sse2_movupd (op0, op1));
10304               return;
10305             }
10306
10307           /* When SSE registers are split into halves, we can avoid
10308              writing to the top half twice.  */
10309           if (TARGET_SSE_SPLIT_REGS)
10310             {
10311               emit_insn (gen_rtx_CLOBBER (VOIDmode, op0));
10312               zero = op0;
10313             }
10314           else
10315             {
10316               /* ??? Not sure about the best option for the Intel chips.
10317                  The following would seem to satisfy; the register is
10318                  entirely cleared, breaking the dependency chain.  We
10319                  then store to the upper half, with a dependency depth
10320                  of one.  A rumor has it that Intel recommends two movsd
10321                  followed by an unpacklpd, but this is unconfirmed.  And
10322                  given that the dependency depth of the unpacklpd would
10323                  still be one, I'm not sure why this would be better.  */
10324               zero = CONST0_RTX (V2DFmode);
10325             }
10326
10327           m = adjust_address (op1, DFmode, 0);
10328           emit_insn (gen_sse2_loadlpd (op0, zero, m));
10329           m = adjust_address (op1, DFmode, 8);
10330           emit_insn (gen_sse2_loadhpd (op0, op0, m));
10331         }
10332       else
10333         {
10334           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
10335             {
10336               op0 = gen_lowpart (V4SFmode, op0);
10337               op1 = gen_lowpart (V4SFmode, op1);
10338               emit_insn (gen_sse_movups (op0, op1));
10339               return;
10340             }
10341
10342           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
10343             emit_move_insn (op0, CONST0_RTX (mode));
10344           else
10345             emit_insn (gen_rtx_CLOBBER (VOIDmode, op0));
10346
10347           if (mode != V4SFmode)
10348             op0 = gen_lowpart (V4SFmode, op0);
10349           m = adjust_address (op1, V2SFmode, 0);
10350           emit_insn (gen_sse_loadlps (op0, op0, m));
10351           m = adjust_address (op1, V2SFmode, 8);
10352           emit_insn (gen_sse_loadhps (op0, op0, m));
10353         }
10354     }
10355   else if (MEM_P (op0))
10356     {
10357       /* If we're optimizing for size, movups is the smallest.  */
10358       if (optimize_size)
10359         {
10360           op0 = gen_lowpart (V4SFmode, op0);
10361           op1 = gen_lowpart (V4SFmode, op1);
10362           emit_insn (gen_sse_movups (op0, op1));
10363           return;
10364         }
10365
10366       /* ??? Similar to above, only less clear because of quote
10367          typeless stores unquote.  */
10368       if (TARGET_SSE2 && !TARGET_SSE_TYPELESS_STORES
10369           && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
10370         {
10371           op0 = gen_lowpart (V16QImode, op0);
10372           op1 = gen_lowpart (V16QImode, op1);
10373           emit_insn (gen_sse2_movdqu (op0, op1));
10374           return;
10375         }
10376
10377       if (TARGET_SSE2 && mode == V2DFmode)
10378         {
10379           m = adjust_address (op0, DFmode, 0);
10380           emit_insn (gen_sse2_storelpd (m, op1));
10381           m = adjust_address (op0, DFmode, 8);
10382           emit_insn (gen_sse2_storehpd (m, op1));
10383         }
10384       else
10385         {
10386           if (mode != V4SFmode)
10387             op1 = gen_lowpart (V4SFmode, op1);
10388           m = adjust_address (op0, V2SFmode, 0);
10389           emit_insn (gen_sse_storelps (m, op1));
10390           m = adjust_address (op0, V2SFmode, 8);
10391           emit_insn (gen_sse_storehps (m, op1));
10392         }
10393     }
10394   else
10395     gcc_unreachable ();
10396 }
10397
10398 /* Expand a push in MODE.  This is some mode for which we do not support
10399    proper push instructions, at least from the registers that we expect
10400    the value to live in.  */
10401
10402 void
10403 ix86_expand_push (enum machine_mode mode, rtx x)
10404 {
10405   rtx tmp;
10406
10407   tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
10408                              GEN_INT (-GET_MODE_SIZE (mode)),
10409                              stack_pointer_rtx, 1, OPTAB_DIRECT);
10410   if (tmp != stack_pointer_rtx)
10411     emit_move_insn (stack_pointer_rtx, tmp);
10412
10413   tmp = gen_rtx_MEM (mode, stack_pointer_rtx);
10414   emit_move_insn (tmp, x);
10415 }
10416
10417 /* Helper function of ix86_fixup_binary_operands to canonicalize
10418    operand order.  Returns true if the operands should be swapped.  */
10419
10420 static bool
10421 ix86_swap_binary_operands_p (enum rtx_code code, enum machine_mode mode,
10422                              rtx operands[])
10423 {
10424   rtx dst = operands[0];
10425   rtx src1 = operands[1];
10426   rtx src2 = operands[2];
10427
10428   /* If the operation is not commutative, we can't do anything.  */
10429   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
10430     return false;
10431
10432   /* Highest priority is that src1 should match dst.  */
10433   if (rtx_equal_p (dst, src1))
10434     return false;
10435   if (rtx_equal_p (dst, src2))
10436     return true;
10437
10438   /* Next highest priority is that immediate constants come second.  */
10439   if (immediate_operand (src2, mode))
10440     return false;
10441   if (immediate_operand (src1, mode))
10442     return true;
10443
10444   /* Lowest priority is that memory references should come second.  */
10445   if (MEM_P (src2))
10446     return false;
10447   if (MEM_P (src1))
10448     return true;
10449
10450   return false;
10451 }
10452
10453
10454 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
10455    destination to use for the operation.  If different from the true
10456    destination in operands[0], a copy operation will be required.  */
10457
10458 rtx
10459 ix86_fixup_binary_operands (enum rtx_code code, enum machine_mode mode,
10460                             rtx operands[])
10461 {
10462   rtx dst = operands[0];
10463   rtx src1 = operands[1];
10464   rtx src2 = operands[2];
10465
10466   /* Canonicalize operand order.  */
10467   if (ix86_swap_binary_operands_p (code, mode, operands))
10468     {
10469       rtx temp = src1;
10470       src1 = src2;
10471       src2 = temp;
10472     }
10473
10474   /* Both source operands cannot be in memory.  */
10475   if (MEM_P (src1) && MEM_P (src2))
10476     {
10477       /* Optimization: Only read from memory once.  */
10478       if (rtx_equal_p (src1, src2))
10479         {
10480           src2 = force_reg (mode, src2);
10481           src1 = src2;
10482         }
10483       else
10484         src2 = force_reg (mode, src2);
10485     }
10486
10487   /* If the destination is memory, and we do not have matching source
10488      operands, do things in registers.  */
10489   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
10490     dst = gen_reg_rtx (mode);
10491
10492   /* Source 1 cannot be a constant.  */
10493   if (CONSTANT_P (src1))
10494     src1 = force_reg (mode, src1);
10495
10496   /* Source 1 cannot be a non-matching memory.  */
10497   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
10498     src1 = force_reg (mode, src1);
10499
10500   operands[1] = src1;
10501   operands[2] = src2;
10502   return dst;
10503 }
10504
10505 /* Similarly, but assume that the destination has already been
10506    set up properly.  */
10507
10508 void
10509 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
10510                                     enum machine_mode mode, rtx operands[])
10511 {
10512   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
10513   gcc_assert (dst == operands[0]);
10514 }
10515
10516 /* Attempt to expand a binary operator.  Make the expansion closer to the
10517    actual machine, then just general_operand, which will allow 3 separate
10518    memory references (one output, two input) in a single insn.  */
10519
10520 void
10521 ix86_expand_binary_operator (enum rtx_code code, enum machine_mode mode,
10522                              rtx operands[])
10523 {
10524   rtx src1, src2, dst, op, clob;
10525
10526   dst = ix86_fixup_binary_operands (code, mode, operands);
10527   src1 = operands[1];
10528   src2 = operands[2];
10529
10530  /* Emit the instruction.  */
10531
10532   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
10533   if (reload_in_progress)
10534     {
10535       /* Reload doesn't know about the flags register, and doesn't know that
10536          it doesn't want to clobber it.  We can only do this with PLUS.  */
10537       gcc_assert (code == PLUS);
10538       emit_insn (op);
10539     }
10540   else
10541     {
10542       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
10543       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
10544     }
10545
10546   /* Fix up the destination if needed.  */
10547   if (dst != operands[0])
10548     emit_move_insn (operands[0], dst);
10549 }
10550
10551 /* Return TRUE or FALSE depending on whether the binary operator meets the
10552    appropriate constraints.  */
10553
10554 int
10555 ix86_binary_operator_ok (enum rtx_code code, enum machine_mode mode,
10556                          rtx operands[3])
10557 {
10558   rtx dst = operands[0];
10559   rtx src1 = operands[1];
10560   rtx src2 = operands[2];
10561
10562   /* Both source operands cannot be in memory.  */
10563   if (MEM_P (src1) && MEM_P (src2))
10564     return 0;
10565
10566   /* Canonicalize operand order for commutative operators.  */
10567   if (ix86_swap_binary_operands_p (code, mode, operands))
10568     {
10569       rtx temp = src1;
10570       src1 = src2;
10571       src2 = temp;
10572     }
10573
10574   /* If the destination is memory, we must have a matching source operand.  */
10575   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
10576       return 0;
10577
10578   /* Source 1 cannot be a constant.  */
10579   if (CONSTANT_P (src1))
10580     return 0;
10581
10582   /* Source 1 cannot be a non-matching memory.  */
10583   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
10584     return 0;
10585
10586   return 1;
10587 }
10588
10589 /* Attempt to expand a unary operator.  Make the expansion closer to the
10590    actual machine, then just general_operand, which will allow 2 separate
10591    memory references (one output, one input) in a single insn.  */
10592
10593 void
10594 ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode,
10595                             rtx operands[])
10596 {
10597   int matching_memory;
10598   rtx src, dst, op, clob;
10599
10600   dst = operands[0];
10601   src = operands[1];
10602
10603   /* If the destination is memory, and we do not have matching source
10604      operands, do things in registers.  */
10605   matching_memory = 0;
10606   if (MEM_P (dst))
10607     {
10608       if (rtx_equal_p (dst, src))
10609         matching_memory = 1;
10610       else
10611         dst = gen_reg_rtx (mode);
10612     }
10613
10614   /* When source operand is memory, destination must match.  */
10615   if (MEM_P (src) && !matching_memory)
10616     src = force_reg (mode, src);
10617
10618   /* Emit the instruction.  */
10619
10620   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
10621   if (reload_in_progress || code == NOT)
10622     {
10623       /* Reload doesn't know about the flags register, and doesn't know that
10624          it doesn't want to clobber it.  */
10625       gcc_assert (code == NOT);
10626       emit_insn (op);
10627     }
10628   else
10629     {
10630       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
10631       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
10632     }
10633
10634   /* Fix up the destination if needed.  */
10635   if (dst != operands[0])
10636     emit_move_insn (operands[0], dst);
10637 }
10638
10639 /* Return TRUE or FALSE depending on whether the unary operator meets the
10640    appropriate constraints.  */
10641
10642 int
10643 ix86_unary_operator_ok (enum rtx_code code ATTRIBUTE_UNUSED,
10644                         enum machine_mode mode ATTRIBUTE_UNUSED,
10645                         rtx operands[2] ATTRIBUTE_UNUSED)
10646 {
10647   /* If one of operands is memory, source and destination must match.  */
10648   if ((MEM_P (operands[0])
10649        || MEM_P (operands[1]))
10650       && ! rtx_equal_p (operands[0], operands[1]))
10651     return FALSE;
10652   return TRUE;
10653 }
10654
10655 /* Post-reload splitter for converting an SF or DFmode value in an
10656    SSE register into an unsigned SImode.  */
10657
10658 void
10659 ix86_split_convert_uns_si_sse (rtx operands[])
10660 {
10661   enum machine_mode vecmode;
10662   rtx value, large, zero_or_two31, input, two31, x;
10663
10664   large = operands[1];
10665   zero_or_two31 = operands[2];
10666   input = operands[3];
10667   two31 = operands[4];
10668   vecmode = GET_MODE (large);
10669   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
10670
10671   /* Load up the value into the low element.  We must ensure that the other
10672      elements are valid floats -- zero is the easiest such value.  */
10673   if (MEM_P (input))
10674     {
10675       if (vecmode == V4SFmode)
10676         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
10677       else
10678         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
10679     }
10680   else
10681     {
10682       input = gen_rtx_REG (vecmode, REGNO (input));
10683       emit_move_insn (value, CONST0_RTX (vecmode));
10684       if (vecmode == V4SFmode)
10685         emit_insn (gen_sse_movss (value, value, input));
10686       else
10687         emit_insn (gen_sse2_movsd (value, value, input));
10688     }
10689
10690   emit_move_insn (large, two31);
10691   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
10692
10693   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
10694   emit_insn (gen_rtx_SET (VOIDmode, large, x));
10695
10696   x = gen_rtx_AND (vecmode, zero_or_two31, large);
10697   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
10698
10699   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
10700   emit_insn (gen_rtx_SET (VOIDmode, value, x));
10701
10702   large = gen_rtx_REG (V4SImode, REGNO (large));
10703   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
10704
10705   x = gen_rtx_REG (V4SImode, REGNO (value));
10706   if (vecmode == V4SFmode)
10707     emit_insn (gen_sse2_cvttps2dq (x, value));
10708   else
10709     emit_insn (gen_sse2_cvttpd2dq (x, value));
10710   value = x;
10711
10712   emit_insn (gen_xorv4si3 (value, value, large));
10713 }
10714
10715 /* Convert an unsigned DImode value into a DFmode, using only SSE.
10716    Expects the 64-bit DImode to be supplied in a pair of integral
10717    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
10718    -mfpmath=sse, !optimize_size only.  */
10719
10720 void
10721 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
10722 {
10723   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
10724   rtx int_xmm, fp_xmm;
10725   rtx biases, exponents;
10726   rtx x;
10727
10728   int_xmm = gen_reg_rtx (V4SImode);
10729   if (TARGET_INTER_UNIT_MOVES)
10730     emit_insn (gen_movdi_to_sse (int_xmm, input));
10731   else if (TARGET_SSE_SPLIT_REGS)
10732     {
10733       emit_insn (gen_rtx_CLOBBER (VOIDmode, int_xmm));
10734       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
10735     }
10736   else
10737     {
10738       x = gen_reg_rtx (V2DImode);
10739       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
10740       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
10741     }
10742
10743   x = gen_rtx_CONST_VECTOR (V4SImode,
10744                             gen_rtvec (4, GEN_INT (0x43300000UL),
10745                                        GEN_INT (0x45300000UL),
10746                                        const0_rtx, const0_rtx));
10747   exponents = validize_mem (force_const_mem (V4SImode, x));
10748
10749   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
10750   emit_insn (gen_sse2_punpckldq (int_xmm, int_xmm, exponents));
10751
10752   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
10753      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
10754      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
10755      (0x1.0p84 + double(fp_value_hi_xmm)).
10756      Note these exponents differ by 32.  */
10757
10758   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
10759
10760   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
10761      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
10762   real_ldexp (&bias_lo_rvt, &dconst1, 52);
10763   real_ldexp (&bias_hi_rvt, &dconst1, 84);
10764   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
10765   x = const_double_from_real_value (bias_hi_rvt, DFmode);
10766   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
10767   biases = validize_mem (force_const_mem (V2DFmode, biases));
10768   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
10769
10770   /* Add the upper and lower DFmode values together.  */
10771   if (TARGET_SSE3)
10772     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
10773   else
10774     {
10775       x = copy_to_mode_reg (V2DFmode, fp_xmm);
10776       emit_insn (gen_sse2_unpckhpd (fp_xmm, fp_xmm, fp_xmm));
10777       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
10778     }
10779
10780   ix86_expand_vector_extract (false, target, fp_xmm, 0);
10781 }
10782
10783 /* Convert an unsigned SImode value into a DFmode.  Only currently used
10784    for SSE, but applicable anywhere.  */
10785
10786 void
10787 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
10788 {
10789   REAL_VALUE_TYPE TWO31r;
10790   rtx x, fp;
10791
10792   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
10793                            NULL, 1, OPTAB_DIRECT);
10794
10795   fp = gen_reg_rtx (DFmode);
10796   emit_insn (gen_floatsidf2 (fp, x));
10797
10798   real_ldexp (&TWO31r, &dconst1, 31);
10799   x = const_double_from_real_value (TWO31r, DFmode);
10800
10801   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
10802   if (x != target)
10803     emit_move_insn (target, x);
10804 }
10805
10806 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
10807    32-bit mode; otherwise we have a direct convert instruction.  */
10808
10809 void
10810 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
10811 {
10812   REAL_VALUE_TYPE TWO32r;
10813   rtx fp_lo, fp_hi, x;
10814
10815   fp_lo = gen_reg_rtx (DFmode);
10816   fp_hi = gen_reg_rtx (DFmode);
10817
10818   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
10819
10820   real_ldexp (&TWO32r, &dconst1, 32);
10821   x = const_double_from_real_value (TWO32r, DFmode);
10822   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
10823
10824   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
10825
10826   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
10827                            0, OPTAB_DIRECT);
10828   if (x != target)
10829     emit_move_insn (target, x);
10830 }
10831
10832 /* Convert an unsigned SImode value into a SFmode, using only SSE.
10833    For x86_32, -mfpmath=sse, !optimize_size only.  */
10834 void
10835 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
10836 {
10837   REAL_VALUE_TYPE ONE16r;
10838   rtx fp_hi, fp_lo, int_hi, int_lo, x;
10839
10840   real_ldexp (&ONE16r, &dconst1, 16);
10841   x = const_double_from_real_value (ONE16r, SFmode);
10842   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
10843                                       NULL, 0, OPTAB_DIRECT);
10844   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
10845                                       NULL, 0, OPTAB_DIRECT);
10846   fp_hi = gen_reg_rtx (SFmode);
10847   fp_lo = gen_reg_rtx (SFmode);
10848   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
10849   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
10850   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
10851                                0, OPTAB_DIRECT);
10852   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
10853                                0, OPTAB_DIRECT);
10854   if (!rtx_equal_p (target, fp_hi))
10855     emit_move_insn (target, fp_hi);
10856 }
10857
10858 /* A subroutine of ix86_build_signbit_mask_vector.  If VECT is true,
10859    then replicate the value for all elements of the vector
10860    register.  */
10861
10862 rtx
10863 ix86_build_const_vector (enum machine_mode mode, bool vect, rtx value)
10864 {
10865   rtvec v;
10866   switch (mode)
10867     {
10868     case SImode:
10869       gcc_assert (vect);
10870       v = gen_rtvec (4, value, value, value, value);
10871       return gen_rtx_CONST_VECTOR (V4SImode, v);
10872
10873     case DImode:
10874       gcc_assert (vect);
10875       v = gen_rtvec (2, value, value);
10876       return gen_rtx_CONST_VECTOR (V2DImode, v);
10877
10878     case SFmode:
10879       if (vect)
10880         v = gen_rtvec (4, value, value, value, value);
10881       else
10882         v = gen_rtvec (4, value, CONST0_RTX (SFmode),
10883                        CONST0_RTX (SFmode), CONST0_RTX (SFmode));
10884       return gen_rtx_CONST_VECTOR (V4SFmode, v);
10885
10886     case DFmode:
10887       if (vect)
10888         v = gen_rtvec (2, value, value);
10889       else
10890         v = gen_rtvec (2, value, CONST0_RTX (DFmode));
10891       return gen_rtx_CONST_VECTOR (V2DFmode, v);
10892
10893     default:
10894       gcc_unreachable ();
10895     }
10896 }
10897
10898 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
10899    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
10900    for an SSE register.  If VECT is true, then replicate the mask for
10901    all elements of the vector register.  If INVERT is true, then create
10902    a mask excluding the sign bit.  */
10903
10904 rtx
10905 ix86_build_signbit_mask (enum machine_mode mode, bool vect, bool invert)
10906 {
10907   enum machine_mode vec_mode, imode;
10908   HOST_WIDE_INT hi, lo;
10909   int shift = 63;
10910   rtx v;
10911   rtx mask;
10912
10913   /* Find the sign bit, sign extended to 2*HWI.  */
10914   switch (mode)
10915     {
10916     case SImode:
10917     case SFmode:
10918       imode = SImode;
10919       vec_mode = (mode == SImode) ? V4SImode : V4SFmode;
10920       lo = 0x80000000, hi = lo < 0;
10921       break;
10922
10923     case DImode:
10924     case DFmode:
10925       imode = DImode;
10926       vec_mode = (mode == DImode) ? V2DImode : V2DFmode;
10927       if (HOST_BITS_PER_WIDE_INT >= 64)
10928         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
10929       else
10930         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
10931       break;
10932
10933     case TImode:
10934     case TFmode:
10935       imode = TImode;
10936       vec_mode = VOIDmode;
10937       gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
10938       lo = 0, hi = (HOST_WIDE_INT)1 << shift;
10939      break;
10940
10941     default:
10942       gcc_unreachable ();
10943     }
10944
10945   if (invert)
10946     lo = ~lo, hi = ~hi;
10947
10948   /* Force this value into the low part of a fp vector constant.  */
10949   mask = immed_double_const (lo, hi, imode);
10950   mask = gen_lowpart (mode, mask);
10951
10952   if (vec_mode == VOIDmode)
10953     return force_reg (mode, mask);
10954
10955   v = ix86_build_const_vector (mode, vect, mask);
10956   return force_reg (vec_mode, v);
10957 }
10958
10959 /* Generate code for floating point ABS or NEG.  */
10960
10961 void
10962 ix86_expand_fp_absneg_operator (enum rtx_code code, enum machine_mode mode,
10963                                 rtx operands[])
10964 {
10965   rtx mask, set, use, clob, dst, src;
10966   bool matching_memory;
10967   bool use_sse = false;
10968   bool vector_mode = VECTOR_MODE_P (mode);
10969   enum machine_mode elt_mode = mode;
10970
10971   if (vector_mode)
10972     {
10973       elt_mode = GET_MODE_INNER (mode);
10974       use_sse = true;
10975     }
10976   else if (mode == TFmode)
10977     use_sse = true;
10978   else if (TARGET_SSE_MATH)
10979     use_sse = SSE_FLOAT_MODE_P (mode);
10980
10981   /* NEG and ABS performed with SSE use bitwise mask operations.
10982      Create the appropriate mask now.  */
10983   if (use_sse)
10984     mask = ix86_build_signbit_mask (elt_mode, vector_mode, code == ABS);
10985   else
10986     mask = NULL_RTX;
10987
10988   dst = operands[0];
10989   src = operands[1];
10990
10991   /* If the destination is memory, and we don't have matching source
10992      operands or we're using the x87, do things in registers.  */
10993   matching_memory = false;
10994   if (MEM_P (dst))
10995     {
10996       if (use_sse && rtx_equal_p (dst, src))
10997         matching_memory = true;
10998       else
10999         dst = gen_reg_rtx (mode);
11000     }
11001   if (MEM_P (src) && !matching_memory)
11002     src = force_reg (mode, src);
11003
11004   if (vector_mode)
11005     {
11006       set = gen_rtx_fmt_ee (code == NEG ? XOR : AND, mode, src, mask);
11007       set = gen_rtx_SET (VOIDmode, dst, set);
11008       emit_insn (set);
11009     }
11010   else
11011     {
11012       set = gen_rtx_fmt_e (code, mode, src);
11013       set = gen_rtx_SET (VOIDmode, dst, set);
11014       if (mask)
11015         {
11016           use = gen_rtx_USE (VOIDmode, mask);
11017           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
11018           emit_insn (gen_rtx_PARALLEL (VOIDmode,
11019                                        gen_rtvec (3, set, use, clob)));
11020         }
11021       else
11022         emit_insn (set);
11023     }
11024
11025   if (dst != operands[0])
11026     emit_move_insn (operands[0], dst);
11027 }
11028
11029 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
11030
11031 void
11032 ix86_expand_copysign (rtx operands[])
11033 {
11034   enum machine_mode mode, vmode;
11035   rtx dest, op0, op1, mask, nmask;
11036
11037   dest = operands[0];
11038   op0 = operands[1];
11039   op1 = operands[2];
11040
11041   mode = GET_MODE (dest);
11042   vmode = mode == SFmode ? V4SFmode : V2DFmode;
11043
11044   if (GET_CODE (op0) == CONST_DOUBLE)
11045     {
11046       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
11047
11048       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
11049         op0 = simplify_unary_operation (ABS, mode, op0, mode);
11050
11051       if (mode == SFmode || mode == DFmode)
11052         {
11053           if (op0 == CONST0_RTX (mode))
11054             op0 = CONST0_RTX (vmode);
11055           else
11056             {
11057               rtvec v;
11058
11059               if (mode == SFmode)
11060                 v = gen_rtvec (4, op0, CONST0_RTX (SFmode),
11061                                CONST0_RTX (SFmode), CONST0_RTX (SFmode));
11062               else
11063                 v = gen_rtvec (2, op0, CONST0_RTX (DFmode));
11064               op0 = force_reg (vmode, gen_rtx_CONST_VECTOR (vmode, v));
11065             }
11066         }
11067
11068       mask = ix86_build_signbit_mask (mode, 0, 0);
11069
11070       if (mode == SFmode)
11071         copysign_insn = gen_copysignsf3_const;
11072       else if (mode == DFmode)
11073         copysign_insn = gen_copysigndf3_const;
11074       else
11075         copysign_insn = gen_copysigntf3_const;
11076
11077         emit_insn (copysign_insn (dest, op0, op1, mask));
11078     }
11079   else
11080     {
11081       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
11082
11083       nmask = ix86_build_signbit_mask (mode, 0, 1);
11084       mask = ix86_build_signbit_mask (mode, 0, 0);
11085
11086       if (mode == SFmode)
11087         copysign_insn = gen_copysignsf3_var;
11088       else if (mode == DFmode)
11089         copysign_insn = gen_copysigndf3_var;
11090       else
11091         copysign_insn = gen_copysigntf3_var;
11092
11093       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
11094     }
11095 }
11096
11097 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
11098    be a constant, and so has already been expanded into a vector constant.  */
11099
11100 void
11101 ix86_split_copysign_const (rtx operands[])
11102 {
11103   enum machine_mode mode, vmode;
11104   rtx dest, op0, op1, mask, x;
11105
11106   dest = operands[0];
11107   op0 = operands[1];
11108   op1 = operands[2];
11109   mask = operands[3];
11110
11111   mode = GET_MODE (dest);
11112   vmode = GET_MODE (mask);
11113
11114   dest = simplify_gen_subreg (vmode, dest, mode, 0);
11115   x = gen_rtx_AND (vmode, dest, mask);
11116   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
11117
11118   if (op0 != CONST0_RTX (vmode))
11119     {
11120       x = gen_rtx_IOR (vmode, dest, op0);
11121       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
11122     }
11123 }
11124
11125 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
11126    so we have to do two masks.  */
11127
11128 void
11129 ix86_split_copysign_var (rtx operands[])
11130 {
11131   enum machine_mode mode, vmode;
11132   rtx dest, scratch, op0, op1, mask, nmask, x;
11133
11134   dest = operands[0];
11135   scratch = operands[1];
11136   op0 = operands[2];
11137   op1 = operands[3];
11138   nmask = operands[4];
11139   mask = operands[5];
11140
11141   mode = GET_MODE (dest);
11142   vmode = GET_MODE (mask);
11143
11144   if (rtx_equal_p (op0, op1))
11145     {
11146       /* Shouldn't happen often (it's useless, obviously), but when it does
11147          we'd generate incorrect code if we continue below.  */
11148       emit_move_insn (dest, op0);
11149       return;
11150     }
11151
11152   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
11153     {
11154       gcc_assert (REGNO (op1) == REGNO (scratch));
11155
11156       x = gen_rtx_AND (vmode, scratch, mask);
11157       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
11158
11159       dest = mask;
11160       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
11161       x = gen_rtx_NOT (vmode, dest);
11162       x = gen_rtx_AND (vmode, x, op0);
11163       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
11164     }
11165   else
11166     {
11167       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
11168         {
11169           x = gen_rtx_AND (vmode, scratch, mask);
11170         }
11171       else                                              /* alternative 2,4 */
11172         {
11173           gcc_assert (REGNO (mask) == REGNO (scratch));
11174           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
11175           x = gen_rtx_AND (vmode, scratch, op1);
11176         }
11177       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
11178
11179       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
11180         {
11181           dest = simplify_gen_subreg (vmode, op0, mode, 0);
11182           x = gen_rtx_AND (vmode, dest, nmask);
11183         }
11184       else                                              /* alternative 3,4 */
11185         {
11186           gcc_assert (REGNO (nmask) == REGNO (dest));
11187           dest = nmask;
11188           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
11189           x = gen_rtx_AND (vmode, dest, op0);
11190         }
11191       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
11192     }
11193
11194   x = gen_rtx_IOR (vmode, dest, scratch);
11195   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
11196 }
11197
11198 /* Return TRUE or FALSE depending on whether the first SET in INSN
11199    has source and destination with matching CC modes, and that the
11200    CC mode is at least as constrained as REQ_MODE.  */
11201
11202 int
11203 ix86_match_ccmode (rtx insn, enum machine_mode req_mode)
11204 {
11205   rtx set;
11206   enum machine_mode set_mode;
11207
11208   set = PATTERN (insn);
11209   if (GET_CODE (set) == PARALLEL)
11210     set = XVECEXP (set, 0, 0);
11211   gcc_assert (GET_CODE (set) == SET);
11212   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
11213
11214   set_mode = GET_MODE (SET_DEST (set));
11215   switch (set_mode)
11216     {
11217     case CCNOmode:
11218       if (req_mode != CCNOmode
11219           && (req_mode != CCmode
11220               || XEXP (SET_SRC (set), 1) != const0_rtx))
11221         return 0;
11222       break;
11223     case CCmode:
11224       if (req_mode == CCGCmode)
11225         return 0;
11226       /* FALLTHRU */
11227     case CCGCmode:
11228       if (req_mode == CCGOCmode || req_mode == CCNOmode)
11229         return 0;
11230       /* FALLTHRU */
11231     case CCGOCmode:
11232       if (req_mode == CCZmode)
11233         return 0;
11234       /* FALLTHRU */
11235     case CCZmode:
11236       break;
11237
11238     default:
11239       gcc_unreachable ();
11240     }
11241
11242   return (GET_MODE (SET_SRC (set)) == set_mode);
11243 }
11244
11245 /* Generate insn patterns to do an integer compare of OPERANDS.  */
11246
11247 static rtx
11248 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
11249 {
11250   enum machine_mode cmpmode;
11251   rtx tmp, flags;
11252
11253   cmpmode = SELECT_CC_MODE (code, op0, op1);
11254   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
11255
11256   /* This is very simple, but making the interface the same as in the
11257      FP case makes the rest of the code easier.  */
11258   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
11259   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
11260
11261   /* Return the test that should be put into the flags user, i.e.
11262      the bcc, scc, or cmov instruction.  */
11263   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
11264 }
11265
11266 /* Figure out whether to use ordered or unordered fp comparisons.
11267    Return the appropriate mode to use.  */
11268
11269 enum machine_mode
11270 ix86_fp_compare_mode (enum rtx_code code ATTRIBUTE_UNUSED)
11271 {
11272   /* ??? In order to make all comparisons reversible, we do all comparisons
11273      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
11274      all forms trapping and nontrapping comparisons, we can make inequality
11275      comparisons trapping again, since it results in better code when using
11276      FCOM based compares.  */
11277   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
11278 }
11279
11280 enum machine_mode
11281 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
11282 {
11283   enum machine_mode mode = GET_MODE (op0);
11284
11285   if (SCALAR_FLOAT_MODE_P (mode))
11286     {
11287       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
11288       return ix86_fp_compare_mode (code);
11289     }
11290
11291   switch (code)
11292     {
11293       /* Only zero flag is needed.  */
11294     case EQ:                    /* ZF=0 */
11295     case NE:                    /* ZF!=0 */
11296       return CCZmode;
11297       /* Codes needing carry flag.  */
11298     case GEU:                   /* CF=0 */
11299     case LTU:                   /* CF=1 */
11300       /* Detect overflow checks.  They need just the carry flag.  */
11301       if (GET_CODE (op0) == PLUS
11302           && rtx_equal_p (op1, XEXP (op0, 0)))
11303         return CCCmode;
11304       else
11305         return CCmode;
11306     case GTU:                   /* CF=0 & ZF=0 */
11307     case LEU:                   /* CF=1 | ZF=1 */
11308       /* Detect overflow checks.  They need just the carry flag.  */
11309       if (GET_CODE (op0) == MINUS
11310           && rtx_equal_p (op1, XEXP (op0, 0)))
11311         return CCCmode;
11312       else
11313         return CCmode;
11314       /* Codes possibly doable only with sign flag when
11315          comparing against zero.  */
11316     case GE:                    /* SF=OF   or   SF=0 */
11317     case LT:                    /* SF<>OF  or   SF=1 */
11318       if (op1 == const0_rtx)
11319         return CCGOCmode;
11320       else
11321         /* For other cases Carry flag is not required.  */
11322         return CCGCmode;
11323       /* Codes doable only with sign flag when comparing
11324          against zero, but we miss jump instruction for it
11325          so we need to use relational tests against overflow
11326          that thus needs to be zero.  */
11327     case GT:                    /* ZF=0 & SF=OF */
11328     case LE:                    /* ZF=1 | SF<>OF */
11329       if (op1 == const0_rtx)
11330         return CCNOmode;
11331       else
11332         return CCGCmode;
11333       /* strcmp pattern do (use flags) and combine may ask us for proper
11334          mode.  */
11335     case USE:
11336       return CCmode;
11337     default:
11338       gcc_unreachable ();
11339     }
11340 }
11341
11342 /* Return the fixed registers used for condition codes.  */
11343
11344 static bool
11345 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
11346 {
11347   *p1 = FLAGS_REG;
11348   *p2 = FPSR_REG;
11349   return true;
11350 }
11351
11352 /* If two condition code modes are compatible, return a condition code
11353    mode which is compatible with both.  Otherwise, return
11354    VOIDmode.  */
11355
11356 static enum machine_mode
11357 ix86_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
11358 {
11359   if (m1 == m2)
11360     return m1;
11361
11362   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
11363     return VOIDmode;
11364
11365   if ((m1 == CCGCmode && m2 == CCGOCmode)
11366       || (m1 == CCGOCmode && m2 == CCGCmode))
11367     return CCGCmode;
11368
11369   switch (m1)
11370     {
11371     default:
11372       gcc_unreachable ();
11373
11374     case CCmode:
11375     case CCGCmode:
11376     case CCGOCmode:
11377     case CCNOmode:
11378     case CCAmode:
11379     case CCCmode:
11380     case CCOmode:
11381     case CCSmode:
11382     case CCZmode:
11383       switch (m2)
11384         {
11385         default:
11386           return VOIDmode;
11387
11388         case CCmode:
11389         case CCGCmode:
11390         case CCGOCmode:
11391         case CCNOmode:
11392         case CCAmode:
11393         case CCCmode:
11394         case CCOmode:
11395         case CCSmode:
11396         case CCZmode:
11397           return CCmode;
11398         }
11399
11400     case CCFPmode:
11401     case CCFPUmode:
11402       /* These are only compatible with themselves, which we already
11403          checked above.  */
11404       return VOIDmode;
11405     }
11406 }
11407
11408 /* Split comparison code CODE into comparisons we can do using branch
11409    instructions.  BYPASS_CODE is comparison code for branch that will
11410    branch around FIRST_CODE and SECOND_CODE.  If some of branches
11411    is not required, set value to UNKNOWN.
11412    We never require more than two branches.  */
11413
11414 void
11415 ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *bypass_code,
11416                           enum rtx_code *first_code,
11417                           enum rtx_code *second_code)
11418 {
11419   *first_code = code;
11420   *bypass_code = UNKNOWN;
11421   *second_code = UNKNOWN;
11422
11423   /* The fcomi comparison sets flags as follows:
11424
11425      cmp    ZF PF CF
11426      >      0  0  0
11427      <      0  0  1
11428      =      1  0  0
11429      un     1  1  1 */
11430
11431   switch (code)
11432     {
11433     case GT:                    /* GTU - CF=0 & ZF=0 */
11434     case GE:                    /* GEU - CF=0 */
11435     case ORDERED:               /* PF=0 */
11436     case UNORDERED:             /* PF=1 */
11437     case UNEQ:                  /* EQ - ZF=1 */
11438     case UNLT:                  /* LTU - CF=1 */
11439     case UNLE:                  /* LEU - CF=1 | ZF=1 */
11440     case LTGT:                  /* EQ - ZF=0 */
11441       break;
11442     case LT:                    /* LTU - CF=1 - fails on unordered */
11443       *first_code = UNLT;
11444       *bypass_code = UNORDERED;
11445       break;
11446     case LE:                    /* LEU - CF=1 | ZF=1 - fails on unordered */
11447       *first_code = UNLE;
11448       *bypass_code = UNORDERED;
11449       break;
11450     case EQ:                    /* EQ - ZF=1 - fails on unordered */
11451       *first_code = UNEQ;
11452       *bypass_code = UNORDERED;
11453       break;
11454     case NE:                    /* NE - ZF=0 - fails on unordered */
11455       *first_code = LTGT;
11456       *second_code = UNORDERED;
11457       break;
11458     case UNGE:                  /* GEU - CF=0 - fails on unordered */
11459       *first_code = GE;
11460       *second_code = UNORDERED;
11461       break;
11462     case UNGT:                  /* GTU - CF=0 & ZF=0 - fails on unordered */
11463       *first_code = GT;
11464       *second_code = UNORDERED;
11465       break;
11466     default:
11467       gcc_unreachable ();
11468     }
11469   if (!TARGET_IEEE_FP)
11470     {
11471       *second_code = UNKNOWN;
11472       *bypass_code = UNKNOWN;
11473     }
11474 }
11475
11476 /* Return cost of comparison done fcom + arithmetics operations on AX.
11477    All following functions do use number of instructions as a cost metrics.
11478    In future this should be tweaked to compute bytes for optimize_size and
11479    take into account performance of various instructions on various CPUs.  */
11480 static int
11481 ix86_fp_comparison_arithmetics_cost (enum rtx_code code)
11482 {
11483   if (!TARGET_IEEE_FP)
11484     return 4;
11485   /* The cost of code output by ix86_expand_fp_compare.  */
11486   switch (code)
11487     {
11488     case UNLE:
11489     case UNLT:
11490     case LTGT:
11491     case GT:
11492     case GE:
11493     case UNORDERED:
11494     case ORDERED:
11495     case UNEQ:
11496       return 4;
11497       break;
11498     case LT:
11499     case NE:
11500     case EQ:
11501     case UNGE:
11502       return 5;
11503       break;
11504     case LE:
11505     case UNGT:
11506       return 6;
11507       break;
11508     default:
11509       gcc_unreachable ();
11510     }
11511 }
11512
11513 /* Return cost of comparison done using fcomi operation.
11514    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
11515 static int
11516 ix86_fp_comparison_fcomi_cost (enum rtx_code code)
11517 {
11518   enum rtx_code bypass_code, first_code, second_code;
11519   /* Return arbitrarily high cost when instruction is not supported - this
11520      prevents gcc from using it.  */
11521   if (!TARGET_CMOVE)
11522     return 1024;
11523   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
11524   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 2;
11525 }
11526
11527 /* Return cost of comparison done using sahf operation.
11528    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
11529 static int
11530 ix86_fp_comparison_sahf_cost (enum rtx_code code)
11531 {
11532   enum rtx_code bypass_code, first_code, second_code;
11533   /* Return arbitrarily high cost when instruction is not preferred - this
11534      avoids gcc from using it.  */
11535   if (!(TARGET_SAHF && (TARGET_USE_SAHF || optimize_size)))
11536     return 1024;
11537   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
11538   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 3;
11539 }
11540
11541 /* Compute cost of the comparison done using any method.
11542    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
11543 static int
11544 ix86_fp_comparison_cost (enum rtx_code code)
11545 {
11546   int fcomi_cost, sahf_cost, arithmetics_cost = 1024;
11547   int min;
11548
11549   fcomi_cost = ix86_fp_comparison_fcomi_cost (code);
11550   sahf_cost = ix86_fp_comparison_sahf_cost (code);
11551
11552   min = arithmetics_cost = ix86_fp_comparison_arithmetics_cost (code);
11553   if (min > sahf_cost)
11554     min = sahf_cost;
11555   if (min > fcomi_cost)
11556     min = fcomi_cost;
11557   return min;
11558 }
11559
11560 /* Return true if we should use an FCOMI instruction for this
11561    fp comparison.  */
11562
11563 int
11564 ix86_use_fcomi_compare (enum rtx_code code ATTRIBUTE_UNUSED)
11565 {
11566   enum rtx_code swapped_code = swap_condition (code);
11567
11568   return ((ix86_fp_comparison_cost (code)
11569            == ix86_fp_comparison_fcomi_cost (code))
11570           || (ix86_fp_comparison_cost (swapped_code)
11571               == ix86_fp_comparison_fcomi_cost (swapped_code)));
11572 }
11573
11574 /* Swap, force into registers, or otherwise massage the two operands
11575    to a fp comparison.  The operands are updated in place; the new
11576    comparison code is returned.  */
11577
11578 static enum rtx_code
11579 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
11580 {
11581   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
11582   rtx op0 = *pop0, op1 = *pop1;
11583   enum machine_mode op_mode = GET_MODE (op0);
11584   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
11585
11586   /* All of the unordered compare instructions only work on registers.
11587      The same is true of the fcomi compare instructions.  The XFmode
11588      compare instructions require registers except when comparing
11589      against zero or when converting operand 1 from fixed point to
11590      floating point.  */
11591
11592   if (!is_sse
11593       && (fpcmp_mode == CCFPUmode
11594           || (op_mode == XFmode
11595               && ! (standard_80387_constant_p (op0) == 1
11596                     || standard_80387_constant_p (op1) == 1)
11597               && GET_CODE (op1) != FLOAT)
11598           || ix86_use_fcomi_compare (code)))
11599     {
11600       op0 = force_reg (op_mode, op0);
11601       op1 = force_reg (op_mode, op1);
11602     }
11603   else
11604     {
11605       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
11606          things around if they appear profitable, otherwise force op0
11607          into a register.  */
11608
11609       if (standard_80387_constant_p (op0) == 0
11610           || (MEM_P (op0)
11611               && ! (standard_80387_constant_p (op1) == 0
11612                     || MEM_P (op1))))
11613         {
11614           rtx tmp;
11615           tmp = op0, op0 = op1, op1 = tmp;
11616           code = swap_condition (code);
11617         }
11618
11619       if (!REG_P (op0))
11620         op0 = force_reg (op_mode, op0);
11621
11622       if (CONSTANT_P (op1))
11623         {
11624           int tmp = standard_80387_constant_p (op1);
11625           if (tmp == 0)
11626             op1 = validize_mem (force_const_mem (op_mode, op1));
11627           else if (tmp == 1)
11628             {
11629               if (TARGET_CMOVE)
11630                 op1 = force_reg (op_mode, op1);
11631             }
11632           else
11633             op1 = force_reg (op_mode, op1);
11634         }
11635     }
11636
11637   /* Try to rearrange the comparison to make it cheaper.  */
11638   if (ix86_fp_comparison_cost (code)
11639       > ix86_fp_comparison_cost (swap_condition (code))
11640       && (REG_P (op1) || can_create_pseudo_p ()))
11641     {
11642       rtx tmp;
11643       tmp = op0, op0 = op1, op1 = tmp;
11644       code = swap_condition (code);
11645       if (!REG_P (op0))
11646         op0 = force_reg (op_mode, op0);
11647     }
11648
11649   *pop0 = op0;
11650   *pop1 = op1;
11651   return code;
11652 }
11653
11654 /* Convert comparison codes we use to represent FP comparison to integer
11655    code that will result in proper branch.  Return UNKNOWN if no such code
11656    is available.  */
11657
11658 enum rtx_code
11659 ix86_fp_compare_code_to_integer (enum rtx_code code)
11660 {
11661   switch (code)
11662     {
11663     case GT:
11664       return GTU;
11665     case GE:
11666       return GEU;
11667     case ORDERED:
11668     case UNORDERED:
11669       return code;
11670       break;
11671     case UNEQ:
11672       return EQ;
11673       break;
11674     case UNLT:
11675       return LTU;
11676       break;
11677     case UNLE:
11678       return LEU;
11679       break;
11680     case LTGT:
11681       return NE;
11682       break;
11683     default:
11684       return UNKNOWN;
11685     }
11686 }
11687
11688 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
11689
11690 static rtx
11691 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch,
11692                         rtx *second_test, rtx *bypass_test)
11693 {
11694   enum machine_mode fpcmp_mode, intcmp_mode;
11695   rtx tmp, tmp2;
11696   int cost = ix86_fp_comparison_cost (code);
11697   enum rtx_code bypass_code, first_code, second_code;
11698
11699   fpcmp_mode = ix86_fp_compare_mode (code);
11700   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
11701
11702   if (second_test)
11703     *second_test = NULL_RTX;
11704   if (bypass_test)
11705     *bypass_test = NULL_RTX;
11706
11707   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
11708
11709   /* Do fcomi/sahf based test when profitable.  */
11710   if (ix86_fp_comparison_arithmetics_cost (code) > cost
11711       && (bypass_code == UNKNOWN || bypass_test)
11712       && (second_code == UNKNOWN || second_test))
11713     {
11714       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
11715       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
11716                          tmp);
11717       if (TARGET_CMOVE)
11718         emit_insn (tmp);
11719       else
11720         {
11721           gcc_assert (TARGET_SAHF);
11722
11723           if (!scratch)
11724             scratch = gen_reg_rtx (HImode);
11725           tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
11726
11727           emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
11728         }
11729
11730       /* The FP codes work out to act like unsigned.  */
11731       intcmp_mode = fpcmp_mode;
11732       code = first_code;
11733       if (bypass_code != UNKNOWN)
11734         *bypass_test = gen_rtx_fmt_ee (bypass_code, VOIDmode,
11735                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
11736                                        const0_rtx);
11737       if (second_code != UNKNOWN)
11738         *second_test = gen_rtx_fmt_ee (second_code, VOIDmode,
11739                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
11740                                        const0_rtx);
11741     }
11742   else
11743     {
11744       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
11745       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
11746       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
11747       if (!scratch)
11748         scratch = gen_reg_rtx (HImode);
11749       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
11750
11751       /* In the unordered case, we have to check C2 for NaN's, which
11752          doesn't happen to work out to anything nice combination-wise.
11753          So do some bit twiddling on the value we've got in AH to come
11754          up with an appropriate set of condition codes.  */
11755
11756       intcmp_mode = CCNOmode;
11757       switch (code)
11758         {
11759         case GT:
11760         case UNGT:
11761           if (code == GT || !TARGET_IEEE_FP)
11762             {
11763               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
11764               code = EQ;
11765             }
11766           else
11767             {
11768               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
11769               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
11770               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
11771               intcmp_mode = CCmode;
11772               code = GEU;
11773             }
11774           break;
11775         case LT:
11776         case UNLT:
11777           if (code == LT && TARGET_IEEE_FP)
11778             {
11779               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
11780               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x01)));
11781               intcmp_mode = CCmode;
11782               code = EQ;
11783             }
11784           else
11785             {
11786               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x01)));
11787               code = NE;
11788             }
11789           break;
11790         case GE:
11791         case UNGE:
11792           if (code == GE || !TARGET_IEEE_FP)
11793             {
11794               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
11795               code = EQ;
11796             }
11797           else
11798             {
11799               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
11800               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
11801                                              GEN_INT (0x01)));
11802               code = NE;
11803             }
11804           break;
11805         case LE:
11806         case UNLE:
11807           if (code == LE && TARGET_IEEE_FP)
11808             {
11809               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
11810               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
11811               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
11812               intcmp_mode = CCmode;
11813               code = LTU;
11814             }
11815           else
11816             {
11817               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
11818               code = NE;
11819             }
11820           break;
11821         case EQ:
11822         case UNEQ:
11823           if (code == EQ && TARGET_IEEE_FP)
11824             {
11825               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
11826               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
11827               intcmp_mode = CCmode;
11828               code = EQ;
11829             }
11830           else
11831             {
11832               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
11833               code = NE;
11834               break;
11835             }
11836           break;
11837         case NE:
11838         case LTGT:
11839           if (code == NE && TARGET_IEEE_FP)
11840             {
11841               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
11842               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
11843                                              GEN_INT (0x40)));
11844               code = NE;
11845             }
11846           else
11847             {
11848               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
11849               code = EQ;
11850             }
11851           break;
11852
11853         case UNORDERED:
11854           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
11855           code = NE;
11856           break;
11857         case ORDERED:
11858           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
11859           code = EQ;
11860           break;
11861
11862         default:
11863           gcc_unreachable ();
11864         }
11865     }
11866
11867   /* Return the test that should be put into the flags user, i.e.
11868      the bcc, scc, or cmov instruction.  */
11869   return gen_rtx_fmt_ee (code, VOIDmode,
11870                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
11871                          const0_rtx);
11872 }
11873
11874 rtx
11875 ix86_expand_compare (enum rtx_code code, rtx *second_test, rtx *bypass_test)
11876 {
11877   rtx op0, op1, ret;
11878   op0 = ix86_compare_op0;
11879   op1 = ix86_compare_op1;
11880
11881   if (second_test)
11882     *second_test = NULL_RTX;
11883   if (bypass_test)
11884     *bypass_test = NULL_RTX;
11885
11886   if (ix86_compare_emitted)
11887     {
11888       ret = gen_rtx_fmt_ee (code, VOIDmode, ix86_compare_emitted, const0_rtx);
11889       ix86_compare_emitted = NULL_RTX;
11890     }
11891   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
11892     {
11893       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
11894       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
11895                                     second_test, bypass_test);
11896     }
11897   else
11898     ret = ix86_expand_int_compare (code, op0, op1);
11899
11900   return ret;
11901 }
11902
11903 /* Return true if the CODE will result in nontrivial jump sequence.  */
11904 bool
11905 ix86_fp_jump_nontrivial_p (enum rtx_code code)
11906 {
11907   enum rtx_code bypass_code, first_code, second_code;
11908   if (!TARGET_CMOVE)
11909     return true;
11910   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
11911   return bypass_code != UNKNOWN || second_code != UNKNOWN;
11912 }
11913
11914 void
11915 ix86_expand_branch (enum rtx_code code, rtx label)
11916 {
11917   rtx tmp;
11918
11919   /* If we have emitted a compare insn, go straight to simple.
11920      ix86_expand_compare won't emit anything if ix86_compare_emitted
11921      is non NULL.  */
11922   if (ix86_compare_emitted)
11923     goto simple;
11924
11925   switch (GET_MODE (ix86_compare_op0))
11926     {
11927     case QImode:
11928     case HImode:
11929     case SImode:
11930       simple:
11931       tmp = ix86_expand_compare (code, NULL, NULL);
11932       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
11933                                   gen_rtx_LABEL_REF (VOIDmode, label),
11934                                   pc_rtx);
11935       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
11936       return;
11937
11938     case SFmode:
11939     case DFmode:
11940     case XFmode:
11941       {
11942         rtvec vec;
11943         int use_fcomi;
11944         enum rtx_code bypass_code, first_code, second_code;
11945
11946         code = ix86_prepare_fp_compare_args (code, &ix86_compare_op0,
11947                                              &ix86_compare_op1);
11948
11949         ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
11950
11951         /* Check whether we will use the natural sequence with one jump.  If
11952            so, we can expand jump early.  Otherwise delay expansion by
11953            creating compound insn to not confuse optimizers.  */
11954         if (bypass_code == UNKNOWN && second_code == UNKNOWN)
11955           {
11956             ix86_split_fp_branch (code, ix86_compare_op0, ix86_compare_op1,
11957                                   gen_rtx_LABEL_REF (VOIDmode, label),
11958                                   pc_rtx, NULL_RTX, NULL_RTX);
11959           }
11960         else
11961           {
11962             tmp = gen_rtx_fmt_ee (code, VOIDmode,
11963                                   ix86_compare_op0, ix86_compare_op1);
11964             tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
11965                                         gen_rtx_LABEL_REF (VOIDmode, label),
11966                                         pc_rtx);
11967             tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
11968
11969             use_fcomi = ix86_use_fcomi_compare (code);
11970             vec = rtvec_alloc (3 + !use_fcomi);
11971             RTVEC_ELT (vec, 0) = tmp;
11972             RTVEC_ELT (vec, 1)
11973               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FPSR_REG));
11974             RTVEC_ELT (vec, 2)
11975               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FLAGS_REG));
11976             if (! use_fcomi)
11977               RTVEC_ELT (vec, 3)
11978                 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (HImode));
11979
11980             emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, vec));
11981           }
11982         return;
11983       }
11984
11985     case DImode:
11986       if (TARGET_64BIT)
11987         goto simple;
11988     case TImode:
11989       /* Expand DImode branch into multiple compare+branch.  */
11990       {
11991         rtx lo[2], hi[2], label2;
11992         enum rtx_code code1, code2, code3;
11993         enum machine_mode submode;
11994
11995         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
11996           {
11997             tmp = ix86_compare_op0;
11998             ix86_compare_op0 = ix86_compare_op1;
11999             ix86_compare_op1 = tmp;
12000             code = swap_condition (code);
12001           }
12002         if (GET_MODE (ix86_compare_op0) == DImode)
12003           {
12004             split_di (&ix86_compare_op0, 1, lo+0, hi+0);
12005             split_di (&ix86_compare_op1, 1, lo+1, hi+1);
12006             submode = SImode;
12007           }
12008         else
12009           {
12010             split_ti (&ix86_compare_op0, 1, lo+0, hi+0);
12011             split_ti (&ix86_compare_op1, 1, lo+1, hi+1);
12012             submode = DImode;
12013           }
12014
12015         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
12016            avoid two branches.  This costs one extra insn, so disable when
12017            optimizing for size.  */
12018
12019         if ((code == EQ || code == NE)
12020             && (!optimize_size
12021                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
12022           {
12023             rtx xor0, xor1;
12024
12025             xor1 = hi[0];
12026             if (hi[1] != const0_rtx)
12027               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
12028                                    NULL_RTX, 0, OPTAB_WIDEN);
12029
12030             xor0 = lo[0];
12031             if (lo[1] != const0_rtx)
12032               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
12033                                    NULL_RTX, 0, OPTAB_WIDEN);
12034
12035             tmp = expand_binop (submode, ior_optab, xor1, xor0,
12036                                 NULL_RTX, 0, OPTAB_WIDEN);
12037
12038             ix86_compare_op0 = tmp;
12039             ix86_compare_op1 = const0_rtx;
12040             ix86_expand_branch (code, label);
12041             return;
12042           }
12043
12044         /* Otherwise, if we are doing less-than or greater-or-equal-than,
12045            op1 is a constant and the low word is zero, then we can just
12046            examine the high word.  */
12047
12048         if (CONST_INT_P (hi[1]) && lo[1] == const0_rtx)
12049           switch (code)
12050             {
12051             case LT: case LTU: case GE: case GEU:
12052               ix86_compare_op0 = hi[0];
12053               ix86_compare_op1 = hi[1];
12054               ix86_expand_branch (code, label);
12055               return;
12056             default:
12057               break;
12058             }
12059
12060         /* Otherwise, we need two or three jumps.  */
12061
12062         label2 = gen_label_rtx ();
12063
12064         code1 = code;
12065         code2 = swap_condition (code);
12066         code3 = unsigned_condition (code);
12067
12068         switch (code)
12069           {
12070           case LT: case GT: case LTU: case GTU:
12071             break;
12072
12073           case LE:   code1 = LT;  code2 = GT;  break;
12074           case GE:   code1 = GT;  code2 = LT;  break;
12075           case LEU:  code1 = LTU; code2 = GTU; break;
12076           case GEU:  code1 = GTU; code2 = LTU; break;
12077
12078           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
12079           case NE:   code2 = UNKNOWN; break;
12080
12081           default:
12082             gcc_unreachable ();
12083           }
12084
12085         /*
12086          * a < b =>
12087          *    if (hi(a) < hi(b)) goto true;
12088          *    if (hi(a) > hi(b)) goto false;
12089          *    if (lo(a) < lo(b)) goto true;
12090          *  false:
12091          */
12092
12093         ix86_compare_op0 = hi[0];
12094         ix86_compare_op1 = hi[1];
12095
12096         if (code1 != UNKNOWN)
12097           ix86_expand_branch (code1, label);
12098         if (code2 != UNKNOWN)
12099           ix86_expand_branch (code2, label2);
12100
12101         ix86_compare_op0 = lo[0];
12102         ix86_compare_op1 = lo[1];
12103         ix86_expand_branch (code3, label);
12104
12105         if (code2 != UNKNOWN)
12106           emit_label (label2);
12107         return;
12108       }
12109
12110     default:
12111       gcc_unreachable ();
12112     }
12113 }
12114
12115 /* Split branch based on floating point condition.  */
12116 void
12117 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
12118                       rtx target1, rtx target2, rtx tmp, rtx pushed)
12119 {
12120   rtx second, bypass;
12121   rtx label = NULL_RTX;
12122   rtx condition;
12123   int bypass_probability = -1, second_probability = -1, probability = -1;
12124   rtx i;
12125
12126   if (target2 != pc_rtx)
12127     {
12128       rtx tmp = target2;
12129       code = reverse_condition_maybe_unordered (code);
12130       target2 = target1;
12131       target1 = tmp;
12132     }
12133
12134   condition = ix86_expand_fp_compare (code, op1, op2,
12135                                       tmp, &second, &bypass);
12136
12137   /* Remove pushed operand from stack.  */
12138   if (pushed)
12139     ix86_free_from_memory (GET_MODE (pushed));
12140
12141   if (split_branch_probability >= 0)
12142     {
12143       /* Distribute the probabilities across the jumps.
12144          Assume the BYPASS and SECOND to be always test
12145          for UNORDERED.  */
12146       probability = split_branch_probability;
12147
12148       /* Value of 1 is low enough to make no need for probability
12149          to be updated.  Later we may run some experiments and see
12150          if unordered values are more frequent in practice.  */
12151       if (bypass)
12152         bypass_probability = 1;
12153       if (second)
12154         second_probability = 1;
12155     }
12156   if (bypass != NULL_RTX)
12157     {
12158       label = gen_label_rtx ();
12159       i = emit_jump_insn (gen_rtx_SET
12160                           (VOIDmode, pc_rtx,
12161                            gen_rtx_IF_THEN_ELSE (VOIDmode,
12162                                                  bypass,
12163                                                  gen_rtx_LABEL_REF (VOIDmode,
12164                                                                     label),
12165                                                  pc_rtx)));
12166       if (bypass_probability >= 0)
12167         REG_NOTES (i)
12168           = gen_rtx_EXPR_LIST (REG_BR_PROB,
12169                                GEN_INT (bypass_probability),
12170                                REG_NOTES (i));
12171     }
12172   i = emit_jump_insn (gen_rtx_SET
12173                       (VOIDmode, pc_rtx,
12174                        gen_rtx_IF_THEN_ELSE (VOIDmode,
12175                                              condition, target1, target2)));
12176   if (probability >= 0)
12177     REG_NOTES (i)
12178       = gen_rtx_EXPR_LIST (REG_BR_PROB,
12179                            GEN_INT (probability),
12180                            REG_NOTES (i));
12181   if (second != NULL_RTX)
12182     {
12183       i = emit_jump_insn (gen_rtx_SET
12184                           (VOIDmode, pc_rtx,
12185                            gen_rtx_IF_THEN_ELSE (VOIDmode, second, target1,
12186                                                  target2)));
12187       if (second_probability >= 0)
12188         REG_NOTES (i)
12189           = gen_rtx_EXPR_LIST (REG_BR_PROB,
12190                                GEN_INT (second_probability),
12191                                REG_NOTES (i));
12192     }
12193   if (label != NULL_RTX)
12194     emit_label (label);
12195 }
12196
12197 int
12198 ix86_expand_setcc (enum rtx_code code, rtx dest)
12199 {
12200   rtx ret, tmp, tmpreg, equiv;
12201   rtx second_test, bypass_test;
12202
12203   if (GET_MODE (ix86_compare_op0) == (TARGET_64BIT ? TImode : DImode))
12204     return 0; /* FAIL */
12205
12206   gcc_assert (GET_MODE (dest) == QImode);
12207
12208   ret = ix86_expand_compare (code, &second_test, &bypass_test);
12209   PUT_MODE (ret, QImode);
12210
12211   tmp = dest;
12212   tmpreg = dest;
12213
12214   emit_insn (gen_rtx_SET (VOIDmode, tmp, ret));
12215   if (bypass_test || second_test)
12216     {
12217       rtx test = second_test;
12218       int bypass = 0;
12219       rtx tmp2 = gen_reg_rtx (QImode);
12220       if (bypass_test)
12221         {
12222           gcc_assert (!second_test);
12223           test = bypass_test;
12224           bypass = 1;
12225           PUT_CODE (test, reverse_condition_maybe_unordered (GET_CODE (test)));
12226         }
12227       PUT_MODE (test, QImode);
12228       emit_insn (gen_rtx_SET (VOIDmode, tmp2, test));
12229
12230       if (bypass)
12231         emit_insn (gen_andqi3 (tmp, tmpreg, tmp2));
12232       else
12233         emit_insn (gen_iorqi3 (tmp, tmpreg, tmp2));
12234     }
12235
12236   /* Attach a REG_EQUAL note describing the comparison result.  */
12237   if (ix86_compare_op0 && ix86_compare_op1)
12238     {
12239       equiv = simplify_gen_relational (code, QImode,
12240                                        GET_MODE (ix86_compare_op0),
12241                                        ix86_compare_op0, ix86_compare_op1);
12242       set_unique_reg_note (get_last_insn (), REG_EQUAL, equiv);
12243     }
12244
12245   return 1; /* DONE */
12246 }
12247
12248 /* Expand comparison setting or clearing carry flag.  Return true when
12249    successful and set pop for the operation.  */
12250 static bool
12251 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
12252 {
12253   enum machine_mode mode =
12254     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
12255
12256   /* Do not handle DImode compares that go through special path.  */
12257   if (mode == (TARGET_64BIT ? TImode : DImode))
12258     return false;
12259
12260   if (SCALAR_FLOAT_MODE_P (mode))
12261     {
12262       rtx second_test = NULL, bypass_test = NULL;
12263       rtx compare_op, compare_seq;
12264
12265       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
12266
12267       /* Shortcut:  following common codes never translate
12268          into carry flag compares.  */
12269       if (code == EQ || code == NE || code == UNEQ || code == LTGT
12270           || code == ORDERED || code == UNORDERED)
12271         return false;
12272
12273       /* These comparisons require zero flag; swap operands so they won't.  */
12274       if ((code == GT || code == UNLE || code == LE || code == UNGT)
12275           && !TARGET_IEEE_FP)
12276         {
12277           rtx tmp = op0;
12278           op0 = op1;
12279           op1 = tmp;
12280           code = swap_condition (code);
12281         }
12282
12283       /* Try to expand the comparison and verify that we end up with
12284          carry flag based comparison.  This fails to be true only when
12285          we decide to expand comparison using arithmetic that is not
12286          too common scenario.  */
12287       start_sequence ();
12288       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
12289                                            &second_test, &bypass_test);
12290       compare_seq = get_insns ();
12291       end_sequence ();
12292
12293       if (second_test || bypass_test)
12294         return false;
12295
12296       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
12297           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
12298         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
12299       else
12300         code = GET_CODE (compare_op);
12301
12302       if (code != LTU && code != GEU)
12303         return false;
12304
12305       emit_insn (compare_seq);
12306       *pop = compare_op;
12307       return true;
12308     }
12309
12310   if (!INTEGRAL_MODE_P (mode))
12311     return false;
12312
12313   switch (code)
12314     {
12315     case LTU:
12316     case GEU:
12317       break;
12318
12319     /* Convert a==0 into (unsigned)a<1.  */
12320     case EQ:
12321     case NE:
12322       if (op1 != const0_rtx)
12323         return false;
12324       op1 = const1_rtx;
12325       code = (code == EQ ? LTU : GEU);
12326       break;
12327
12328     /* Convert a>b into b<a or a>=b-1.  */
12329     case GTU:
12330     case LEU:
12331       if (CONST_INT_P (op1))
12332         {
12333           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
12334           /* Bail out on overflow.  We still can swap operands but that
12335              would force loading of the constant into register.  */
12336           if (op1 == const0_rtx
12337               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
12338             return false;
12339           code = (code == GTU ? GEU : LTU);
12340         }
12341       else
12342         {
12343           rtx tmp = op1;
12344           op1 = op0;
12345           op0 = tmp;
12346           code = (code == GTU ? LTU : GEU);
12347         }
12348       break;
12349
12350     /* Convert a>=0 into (unsigned)a<0x80000000.  */
12351     case LT:
12352     case GE:
12353       if (mode == DImode || op1 != const0_rtx)
12354         return false;
12355       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
12356       code = (code == LT ? GEU : LTU);
12357       break;
12358     case LE:
12359     case GT:
12360       if (mode == DImode || op1 != constm1_rtx)
12361         return false;
12362       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
12363       code = (code == LE ? GEU : LTU);
12364       break;
12365
12366     default:
12367       return false;
12368     }
12369   /* Swapping operands may cause constant to appear as first operand.  */
12370   if (!nonimmediate_operand (op0, VOIDmode))
12371     {
12372       if (!can_create_pseudo_p ())
12373         return false;
12374       op0 = force_reg (mode, op0);
12375     }
12376   ix86_compare_op0 = op0;
12377   ix86_compare_op1 = op1;
12378   *pop = ix86_expand_compare (code, NULL, NULL);
12379   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
12380   return true;
12381 }
12382
12383 int
12384 ix86_expand_int_movcc (rtx operands[])
12385 {
12386   enum rtx_code code = GET_CODE (operands[1]), compare_code;
12387   rtx compare_seq, compare_op;
12388   rtx second_test, bypass_test;
12389   enum machine_mode mode = GET_MODE (operands[0]);
12390   bool sign_bit_compare_p = false;;
12391
12392   start_sequence ();
12393   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
12394   compare_seq = get_insns ();
12395   end_sequence ();
12396
12397   compare_code = GET_CODE (compare_op);
12398
12399   if ((ix86_compare_op1 == const0_rtx && (code == GE || code == LT))
12400       || (ix86_compare_op1 == constm1_rtx && (code == GT || code == LE)))
12401     sign_bit_compare_p = true;
12402
12403   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
12404      HImode insns, we'd be swallowed in word prefix ops.  */
12405
12406   if ((mode != HImode || TARGET_FAST_PREFIX)
12407       && (mode != (TARGET_64BIT ? TImode : DImode))
12408       && CONST_INT_P (operands[2])
12409       && CONST_INT_P (operands[3]))
12410     {
12411       rtx out = operands[0];
12412       HOST_WIDE_INT ct = INTVAL (operands[2]);
12413       HOST_WIDE_INT cf = INTVAL (operands[3]);
12414       HOST_WIDE_INT diff;
12415
12416       diff = ct - cf;
12417       /*  Sign bit compares are better done using shifts than we do by using
12418           sbb.  */
12419       if (sign_bit_compare_p
12420           || ix86_expand_carry_flag_compare (code, ix86_compare_op0,
12421                                              ix86_compare_op1, &compare_op))
12422         {
12423           /* Detect overlap between destination and compare sources.  */
12424           rtx tmp = out;
12425
12426           if (!sign_bit_compare_p)
12427             {
12428               bool fpcmp = false;
12429
12430               compare_code = GET_CODE (compare_op);
12431
12432               if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
12433                   || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
12434                 {
12435                   fpcmp = true;
12436                   compare_code = ix86_fp_compare_code_to_integer (compare_code);
12437                 }
12438
12439               /* To simplify rest of code, restrict to the GEU case.  */
12440               if (compare_code == LTU)
12441                 {
12442                   HOST_WIDE_INT tmp = ct;
12443                   ct = cf;
12444                   cf = tmp;
12445                   compare_code = reverse_condition (compare_code);
12446                   code = reverse_condition (code);
12447                 }
12448               else
12449                 {
12450                   if (fpcmp)
12451                     PUT_CODE (compare_op,
12452                               reverse_condition_maybe_unordered
12453                                 (GET_CODE (compare_op)));
12454                   else
12455                     PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
12456                 }
12457               diff = ct - cf;
12458
12459               if (reg_overlap_mentioned_p (out, ix86_compare_op0)
12460                   || reg_overlap_mentioned_p (out, ix86_compare_op1))
12461                 tmp = gen_reg_rtx (mode);
12462
12463               if (mode == DImode)
12464                 emit_insn (gen_x86_movdicc_0_m1_rex64 (tmp, compare_op));
12465               else
12466                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp), compare_op));
12467             }
12468           else
12469             {
12470               if (code == GT || code == GE)
12471                 code = reverse_condition (code);
12472               else
12473                 {
12474                   HOST_WIDE_INT tmp = ct;
12475                   ct = cf;
12476                   cf = tmp;
12477                   diff = ct - cf;
12478                 }
12479               tmp = emit_store_flag (tmp, code, ix86_compare_op0,
12480                                      ix86_compare_op1, VOIDmode, 0, -1);
12481             }
12482
12483           if (diff == 1)
12484             {
12485               /*
12486                * cmpl op0,op1
12487                * sbbl dest,dest
12488                * [addl dest, ct]
12489                *
12490                * Size 5 - 8.
12491                */
12492               if (ct)
12493                 tmp = expand_simple_binop (mode, PLUS,
12494                                            tmp, GEN_INT (ct),
12495                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
12496             }
12497           else if (cf == -1)
12498             {
12499               /*
12500                * cmpl op0,op1
12501                * sbbl dest,dest
12502                * orl $ct, dest
12503                *
12504                * Size 8.
12505                */
12506               tmp = expand_simple_binop (mode, IOR,
12507                                          tmp, GEN_INT (ct),
12508                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
12509             }
12510           else if (diff == -1 && ct)
12511             {
12512               /*
12513                * cmpl op0,op1
12514                * sbbl dest,dest
12515                * notl dest
12516                * [addl dest, cf]
12517                *
12518                * Size 8 - 11.
12519                */
12520               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
12521               if (cf)
12522                 tmp = expand_simple_binop (mode, PLUS,
12523                                            copy_rtx (tmp), GEN_INT (cf),
12524                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
12525             }
12526           else
12527             {
12528               /*
12529                * cmpl op0,op1
12530                * sbbl dest,dest
12531                * [notl dest]
12532                * andl cf - ct, dest
12533                * [addl dest, ct]
12534                *
12535                * Size 8 - 11.
12536                */
12537
12538               if (cf == 0)
12539                 {
12540                   cf = ct;
12541                   ct = 0;
12542                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
12543                 }
12544
12545               tmp = expand_simple_binop (mode, AND,
12546                                          copy_rtx (tmp),
12547                                          gen_int_mode (cf - ct, mode),
12548                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
12549               if (ct)
12550                 tmp = expand_simple_binop (mode, PLUS,
12551                                            copy_rtx (tmp), GEN_INT (ct),
12552                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
12553             }
12554
12555           if (!rtx_equal_p (tmp, out))
12556             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
12557
12558           return 1; /* DONE */
12559         }
12560
12561       if (diff < 0)
12562         {
12563           enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
12564
12565           HOST_WIDE_INT tmp;
12566           tmp = ct, ct = cf, cf = tmp;
12567           diff = -diff;
12568
12569           if (SCALAR_FLOAT_MODE_P (cmp_mode))
12570             {
12571               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
12572
12573               /* We may be reversing unordered compare to normal compare, that
12574                  is not valid in general (we may convert non-trapping condition
12575                  to trapping one), however on i386 we currently emit all
12576                  comparisons unordered.  */
12577               compare_code = reverse_condition_maybe_unordered (compare_code);
12578               code = reverse_condition_maybe_unordered (code);
12579             }
12580           else
12581             {
12582               compare_code = reverse_condition (compare_code);
12583               code = reverse_condition (code);
12584             }
12585         }
12586
12587       compare_code = UNKNOWN;
12588       if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_INT
12589           && CONST_INT_P (ix86_compare_op1))
12590         {
12591           if (ix86_compare_op1 == const0_rtx
12592               && (code == LT || code == GE))
12593             compare_code = code;
12594           else if (ix86_compare_op1 == constm1_rtx)
12595             {
12596               if (code == LE)
12597                 compare_code = LT;
12598               else if (code == GT)
12599                 compare_code = GE;
12600             }
12601         }
12602
12603       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
12604       if (compare_code != UNKNOWN
12605           && GET_MODE (ix86_compare_op0) == GET_MODE (out)
12606           && (cf == -1 || ct == -1))
12607         {
12608           /* If lea code below could be used, only optimize
12609              if it results in a 2 insn sequence.  */
12610
12611           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
12612                  || diff == 3 || diff == 5 || diff == 9)
12613               || (compare_code == LT && ct == -1)
12614               || (compare_code == GE && cf == -1))
12615             {
12616               /*
12617                * notl op1       (if necessary)
12618                * sarl $31, op1
12619                * orl cf, op1
12620                */
12621               if (ct != -1)
12622                 {
12623                   cf = ct;
12624                   ct = -1;
12625                   code = reverse_condition (code);
12626                 }
12627
12628               out = emit_store_flag (out, code, ix86_compare_op0,
12629                                      ix86_compare_op1, VOIDmode, 0, -1);
12630
12631               out = expand_simple_binop (mode, IOR,
12632                                          out, GEN_INT (cf),
12633                                          out, 1, OPTAB_DIRECT);
12634               if (out != operands[0])
12635                 emit_move_insn (operands[0], out);
12636
12637               return 1; /* DONE */
12638             }
12639         }
12640
12641
12642       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
12643            || diff == 3 || diff == 5 || diff == 9)
12644           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
12645           && (mode != DImode
12646               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
12647         {
12648           /*
12649            * xorl dest,dest
12650            * cmpl op1,op2
12651            * setcc dest
12652            * lea cf(dest*(ct-cf)),dest
12653            *
12654            * Size 14.
12655            *
12656            * This also catches the degenerate setcc-only case.
12657            */
12658
12659           rtx tmp;
12660           int nops;
12661
12662           out = emit_store_flag (out, code, ix86_compare_op0,
12663                                  ix86_compare_op1, VOIDmode, 0, 1);
12664
12665           nops = 0;
12666           /* On x86_64 the lea instruction operates on Pmode, so we need
12667              to get arithmetics done in proper mode to match.  */
12668           if (diff == 1)
12669             tmp = copy_rtx (out);
12670           else
12671             {
12672               rtx out1;
12673               out1 = copy_rtx (out);
12674               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
12675               nops++;
12676               if (diff & 1)
12677                 {
12678                   tmp = gen_rtx_PLUS (mode, tmp, out1);
12679                   nops++;
12680                 }
12681             }
12682           if (cf != 0)
12683             {
12684               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
12685               nops++;
12686             }
12687           if (!rtx_equal_p (tmp, out))
12688             {
12689               if (nops == 1)
12690                 out = force_operand (tmp, copy_rtx (out));
12691               else
12692                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
12693             }
12694           if (!rtx_equal_p (out, operands[0]))
12695             emit_move_insn (operands[0], copy_rtx (out));
12696
12697           return 1; /* DONE */
12698         }
12699
12700       /*
12701        * General case:                  Jumpful:
12702        *   xorl dest,dest               cmpl op1, op2
12703        *   cmpl op1, op2                movl ct, dest
12704        *   setcc dest                   jcc 1f
12705        *   decl dest                    movl cf, dest
12706        *   andl (cf-ct),dest            1:
12707        *   addl ct,dest
12708        *
12709        * Size 20.                       Size 14.
12710        *
12711        * This is reasonably steep, but branch mispredict costs are
12712        * high on modern cpus, so consider failing only if optimizing
12713        * for space.
12714        */
12715
12716       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
12717           && BRANCH_COST >= 2)
12718         {
12719           if (cf == 0)
12720             {
12721               enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
12722
12723               cf = ct;
12724               ct = 0;
12725
12726               if (SCALAR_FLOAT_MODE_P (cmp_mode))
12727                 {
12728                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
12729
12730                   /* We may be reversing unordered compare to normal compare,
12731                      that is not valid in general (we may convert non-trapping
12732                      condition to trapping one), however on i386 we currently
12733                      emit all comparisons unordered.  */
12734                   code = reverse_condition_maybe_unordered (code);
12735                 }
12736               else
12737                 {
12738                   code = reverse_condition (code);
12739                   if (compare_code != UNKNOWN)
12740                     compare_code = reverse_condition (compare_code);
12741                 }
12742             }
12743
12744           if (compare_code != UNKNOWN)
12745             {
12746               /* notl op1       (if needed)
12747                  sarl $31, op1
12748                  andl (cf-ct), op1
12749                  addl ct, op1
12750
12751                  For x < 0 (resp. x <= -1) there will be no notl,
12752                  so if possible swap the constants to get rid of the
12753                  complement.
12754                  True/false will be -1/0 while code below (store flag
12755                  followed by decrement) is 0/-1, so the constants need
12756                  to be exchanged once more.  */
12757
12758               if (compare_code == GE || !cf)
12759                 {
12760                   code = reverse_condition (code);
12761                   compare_code = LT;
12762                 }
12763               else
12764                 {
12765                   HOST_WIDE_INT tmp = cf;
12766                   cf = ct;
12767                   ct = tmp;
12768                 }
12769
12770               out = emit_store_flag (out, code, ix86_compare_op0,
12771                                      ix86_compare_op1, VOIDmode, 0, -1);
12772             }
12773           else
12774             {
12775               out = emit_store_flag (out, code, ix86_compare_op0,
12776                                      ix86_compare_op1, VOIDmode, 0, 1);
12777
12778               out = expand_simple_binop (mode, PLUS, copy_rtx (out), constm1_rtx,
12779                                          copy_rtx (out), 1, OPTAB_DIRECT);
12780             }
12781
12782           out = expand_simple_binop (mode, AND, copy_rtx (out),
12783                                      gen_int_mode (cf - ct, mode),
12784                                      copy_rtx (out), 1, OPTAB_DIRECT);
12785           if (ct)
12786             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
12787                                        copy_rtx (out), 1, OPTAB_DIRECT);
12788           if (!rtx_equal_p (out, operands[0]))
12789             emit_move_insn (operands[0], copy_rtx (out));
12790
12791           return 1; /* DONE */
12792         }
12793     }
12794
12795   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
12796     {
12797       /* Try a few things more with specific constants and a variable.  */
12798
12799       optab op;
12800       rtx var, orig_out, out, tmp;
12801
12802       if (BRANCH_COST <= 2)
12803         return 0; /* FAIL */
12804
12805       /* If one of the two operands is an interesting constant, load a
12806          constant with the above and mask it in with a logical operation.  */
12807
12808       if (CONST_INT_P (operands[2]))
12809         {
12810           var = operands[3];
12811           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
12812             operands[3] = constm1_rtx, op = and_optab;
12813           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
12814             operands[3] = const0_rtx, op = ior_optab;
12815           else
12816             return 0; /* FAIL */
12817         }
12818       else if (CONST_INT_P (operands[3]))
12819         {
12820           var = operands[2];
12821           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
12822             operands[2] = constm1_rtx, op = and_optab;
12823           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
12824             operands[2] = const0_rtx, op = ior_optab;
12825           else
12826             return 0; /* FAIL */
12827         }
12828       else
12829         return 0; /* FAIL */
12830
12831       orig_out = operands[0];
12832       tmp = gen_reg_rtx (mode);
12833       operands[0] = tmp;
12834
12835       /* Recurse to get the constant loaded.  */
12836       if (ix86_expand_int_movcc (operands) == 0)
12837         return 0; /* FAIL */
12838
12839       /* Mask in the interesting variable.  */
12840       out = expand_binop (mode, op, var, tmp, orig_out, 0,
12841                           OPTAB_WIDEN);
12842       if (!rtx_equal_p (out, orig_out))
12843         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
12844
12845       return 1; /* DONE */
12846     }
12847
12848   /*
12849    * For comparison with above,
12850    *
12851    * movl cf,dest
12852    * movl ct,tmp
12853    * cmpl op1,op2
12854    * cmovcc tmp,dest
12855    *
12856    * Size 15.
12857    */
12858
12859   if (! nonimmediate_operand (operands[2], mode))
12860     operands[2] = force_reg (mode, operands[2]);
12861   if (! nonimmediate_operand (operands[3], mode))
12862     operands[3] = force_reg (mode, operands[3]);
12863
12864   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
12865     {
12866       rtx tmp = gen_reg_rtx (mode);
12867       emit_move_insn (tmp, operands[3]);
12868       operands[3] = tmp;
12869     }
12870   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
12871     {
12872       rtx tmp = gen_reg_rtx (mode);
12873       emit_move_insn (tmp, operands[2]);
12874       operands[2] = tmp;
12875     }
12876
12877   if (! register_operand (operands[2], VOIDmode)
12878       && (mode == QImode
12879           || ! register_operand (operands[3], VOIDmode)))
12880     operands[2] = force_reg (mode, operands[2]);
12881
12882   if (mode == QImode
12883       && ! register_operand (operands[3], VOIDmode))
12884     operands[3] = force_reg (mode, operands[3]);
12885
12886   emit_insn (compare_seq);
12887   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
12888                           gen_rtx_IF_THEN_ELSE (mode,
12889                                                 compare_op, operands[2],
12890                                                 operands[3])));
12891   if (bypass_test)
12892     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
12893                             gen_rtx_IF_THEN_ELSE (mode,
12894                                   bypass_test,
12895                                   copy_rtx (operands[3]),
12896                                   copy_rtx (operands[0]))));
12897   if (second_test)
12898     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
12899                             gen_rtx_IF_THEN_ELSE (mode,
12900                                   second_test,
12901                                   copy_rtx (operands[2]),
12902                                   copy_rtx (operands[0]))));
12903
12904   return 1; /* DONE */
12905 }
12906
12907 /* Swap, force into registers, or otherwise massage the two operands
12908    to an sse comparison with a mask result.  Thus we differ a bit from
12909    ix86_prepare_fp_compare_args which expects to produce a flags result.
12910
12911    The DEST operand exists to help determine whether to commute commutative
12912    operators.  The POP0/POP1 operands are updated in place.  The new
12913    comparison code is returned, or UNKNOWN if not implementable.  */
12914
12915 static enum rtx_code
12916 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
12917                                   rtx *pop0, rtx *pop1)
12918 {
12919   rtx tmp;
12920
12921   switch (code)
12922     {
12923     case LTGT:
12924     case UNEQ:
12925       /* We have no LTGT as an operator.  We could implement it with
12926          NE & ORDERED, but this requires an extra temporary.  It's
12927          not clear that it's worth it.  */
12928       return UNKNOWN;
12929
12930     case LT:
12931     case LE:
12932     case UNGT:
12933     case UNGE:
12934       /* These are supported directly.  */
12935       break;
12936
12937     case EQ:
12938     case NE:
12939     case UNORDERED:
12940     case ORDERED:
12941       /* For commutative operators, try to canonicalize the destination
12942          operand to be first in the comparison - this helps reload to
12943          avoid extra moves.  */
12944       if (!dest || !rtx_equal_p (dest, *pop1))
12945         break;
12946       /* FALLTHRU */
12947
12948     case GE:
12949     case GT:
12950     case UNLE:
12951     case UNLT:
12952       /* These are not supported directly.  Swap the comparison operands
12953          to transform into something that is supported.  */
12954       tmp = *pop0;
12955       *pop0 = *pop1;
12956       *pop1 = tmp;
12957       code = swap_condition (code);
12958       break;
12959
12960     default:
12961       gcc_unreachable ();
12962     }
12963
12964   return code;
12965 }
12966
12967 /* Detect conditional moves that exactly match min/max operational
12968    semantics.  Note that this is IEEE safe, as long as we don't
12969    interchange the operands.
12970
12971    Returns FALSE if this conditional move doesn't match a MIN/MAX,
12972    and TRUE if the operation is successful and instructions are emitted.  */
12973
12974 static bool
12975 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
12976                            rtx cmp_op1, rtx if_true, rtx if_false)
12977 {
12978   enum machine_mode mode;
12979   bool is_min;
12980   rtx tmp;
12981
12982   if (code == LT)
12983     ;
12984   else if (code == UNGE)
12985     {
12986       tmp = if_true;
12987       if_true = if_false;
12988       if_false = tmp;
12989     }
12990   else
12991     return false;
12992
12993   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
12994     is_min = true;
12995   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
12996     is_min = false;
12997   else
12998     return false;
12999
13000   mode = GET_MODE (dest);
13001
13002   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
13003      but MODE may be a vector mode and thus not appropriate.  */
13004   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
13005     {
13006       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
13007       rtvec v;
13008
13009       if_true = force_reg (mode, if_true);
13010       v = gen_rtvec (2, if_true, if_false);
13011       tmp = gen_rtx_UNSPEC (mode, v, u);
13012     }
13013   else
13014     {
13015       code = is_min ? SMIN : SMAX;
13016       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
13017     }
13018
13019   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
13020   return true;
13021 }
13022
13023 /* Expand an sse vector comparison.  Return the register with the result.  */
13024
13025 static rtx
13026 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
13027                      rtx op_true, rtx op_false)
13028 {
13029   enum machine_mode mode = GET_MODE (dest);
13030   rtx x;
13031
13032   cmp_op0 = force_reg (mode, cmp_op0);
13033   if (!nonimmediate_operand (cmp_op1, mode))
13034     cmp_op1 = force_reg (mode, cmp_op1);
13035
13036   if (optimize
13037       || reg_overlap_mentioned_p (dest, op_true)
13038       || reg_overlap_mentioned_p (dest, op_false))
13039     dest = gen_reg_rtx (mode);
13040
13041   x = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
13042   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13043
13044   return dest;
13045 }
13046
13047 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
13048    operations.  This is used for both scalar and vector conditional moves.  */
13049
13050 static void
13051 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
13052 {
13053   enum machine_mode mode = GET_MODE (dest);
13054   rtx t2, t3, x;
13055
13056   if (TARGET_SSE5)
13057     {
13058       rtx pcmov = gen_rtx_SET (mode, dest,
13059                                gen_rtx_IF_THEN_ELSE (mode, cmp,
13060                                                      op_true,
13061                                                      op_false));
13062       emit_insn (pcmov);
13063     }
13064   else if (op_false == CONST0_RTX (mode))
13065     {
13066       op_true = force_reg (mode, op_true);
13067       x = gen_rtx_AND (mode, cmp, op_true);
13068       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13069     }
13070   else if (op_true == CONST0_RTX (mode))
13071     {
13072       op_false = force_reg (mode, op_false);
13073       x = gen_rtx_NOT (mode, cmp);
13074       x = gen_rtx_AND (mode, x, op_false);
13075       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13076     }
13077   else
13078     {
13079       op_true = force_reg (mode, op_true);
13080       op_false = force_reg (mode, op_false);
13081
13082       t2 = gen_reg_rtx (mode);
13083       if (optimize)
13084         t3 = gen_reg_rtx (mode);
13085       else
13086         t3 = dest;
13087
13088       x = gen_rtx_AND (mode, op_true, cmp);
13089       emit_insn (gen_rtx_SET (VOIDmode, t2, x));
13090
13091       x = gen_rtx_NOT (mode, cmp);
13092       x = gen_rtx_AND (mode, x, op_false);
13093       emit_insn (gen_rtx_SET (VOIDmode, t3, x));
13094
13095       x = gen_rtx_IOR (mode, t3, t2);
13096       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13097     }
13098 }
13099
13100 /* Expand a floating-point conditional move.  Return true if successful.  */
13101
13102 int
13103 ix86_expand_fp_movcc (rtx operands[])
13104 {
13105   enum machine_mode mode = GET_MODE (operands[0]);
13106   enum rtx_code code = GET_CODE (operands[1]);
13107   rtx tmp, compare_op, second_test, bypass_test;
13108
13109   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
13110     {
13111       enum machine_mode cmode;
13112
13113       /* Since we've no cmove for sse registers, don't force bad register
13114          allocation just to gain access to it.  Deny movcc when the
13115          comparison mode doesn't match the move mode.  */
13116       cmode = GET_MODE (ix86_compare_op0);
13117       if (cmode == VOIDmode)
13118         cmode = GET_MODE (ix86_compare_op1);
13119       if (cmode != mode)
13120         return 0;
13121
13122       code = ix86_prepare_sse_fp_compare_args (operands[0], code,
13123                                                &ix86_compare_op0,
13124                                                &ix86_compare_op1);
13125       if (code == UNKNOWN)
13126         return 0;
13127
13128       if (ix86_expand_sse_fp_minmax (operands[0], code, ix86_compare_op0,
13129                                      ix86_compare_op1, operands[2],
13130                                      operands[3]))
13131         return 1;
13132
13133       tmp = ix86_expand_sse_cmp (operands[0], code, ix86_compare_op0,
13134                                  ix86_compare_op1, operands[2], operands[3]);
13135       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
13136       return 1;
13137     }
13138
13139   /* The floating point conditional move instructions don't directly
13140      support conditions resulting from a signed integer comparison.  */
13141
13142   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
13143
13144   /* The floating point conditional move instructions don't directly
13145      support signed integer comparisons.  */
13146
13147   if (!fcmov_comparison_operator (compare_op, VOIDmode))
13148     {
13149       gcc_assert (!second_test && !bypass_test);
13150       tmp = gen_reg_rtx (QImode);
13151       ix86_expand_setcc (code, tmp);
13152       code = NE;
13153       ix86_compare_op0 = tmp;
13154       ix86_compare_op1 = const0_rtx;
13155       compare_op = ix86_expand_compare (code,  &second_test, &bypass_test);
13156     }
13157   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
13158     {
13159       tmp = gen_reg_rtx (mode);
13160       emit_move_insn (tmp, operands[3]);
13161       operands[3] = tmp;
13162     }
13163   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
13164     {
13165       tmp = gen_reg_rtx (mode);
13166       emit_move_insn (tmp, operands[2]);
13167       operands[2] = tmp;
13168     }
13169
13170   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
13171                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
13172                                                 operands[2], operands[3])));
13173   if (bypass_test)
13174     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
13175                             gen_rtx_IF_THEN_ELSE (mode, bypass_test,
13176                                                   operands[3], operands[0])));
13177   if (second_test)
13178     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
13179                             gen_rtx_IF_THEN_ELSE (mode, second_test,
13180                                                   operands[2], operands[0])));
13181
13182   return 1;
13183 }
13184
13185 /* Expand a floating-point vector conditional move; a vcond operation
13186    rather than a movcc operation.  */
13187
13188 bool
13189 ix86_expand_fp_vcond (rtx operands[])
13190 {
13191   enum rtx_code code = GET_CODE (operands[3]);
13192   rtx cmp;
13193
13194   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
13195                                            &operands[4], &operands[5]);
13196   if (code == UNKNOWN)
13197     return false;
13198
13199   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
13200                                  operands[5], operands[1], operands[2]))
13201     return true;
13202
13203   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
13204                              operands[1], operands[2]);
13205   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
13206   return true;
13207 }
13208
13209 /* Expand a signed/unsigned integral vector conditional move.  */
13210
13211 bool
13212 ix86_expand_int_vcond (rtx operands[])
13213 {
13214   enum machine_mode mode = GET_MODE (operands[0]);
13215   enum rtx_code code = GET_CODE (operands[3]);
13216   bool negate = false;
13217   rtx x, cop0, cop1;
13218
13219   cop0 = operands[4];
13220   cop1 = operands[5];
13221
13222   /* Canonicalize the comparison to EQ, GT, GTU.  */
13223   switch (code)
13224     {
13225     case EQ:
13226     case GT:
13227     case GTU:
13228       break;
13229
13230     case NE:
13231     case LE:
13232     case LEU:
13233       code = reverse_condition (code);
13234       negate = true;
13235       break;
13236
13237     case GE:
13238     case GEU:
13239       code = reverse_condition (code);
13240       negate = true;
13241       /* FALLTHRU */
13242
13243     case LT:
13244     case LTU:
13245       code = swap_condition (code);
13246       x = cop0, cop0 = cop1, cop1 = x;
13247       break;
13248
13249     default:
13250       gcc_unreachable ();
13251     }
13252
13253   /* Only SSE4.1/SSE4.2 supports V2DImode.  */
13254   if (mode == V2DImode)
13255     {
13256       switch (code)
13257         {
13258         case EQ:
13259           /* SSE4.1 supports EQ.  */
13260           if (!TARGET_SSE4_1)
13261             return false;
13262           break;
13263
13264         case GT:
13265         case GTU:
13266           /* SSE4.2 supports GT/GTU.  */
13267           if (!TARGET_SSE4_2)
13268             return false;
13269           break;
13270
13271         default:
13272           gcc_unreachable ();
13273         }
13274     }
13275
13276   /* Unsigned parallel compare is not supported by the hardware.  Play some
13277      tricks to turn this into a signed comparison against 0.  */
13278   if (code == GTU)
13279     {
13280       cop0 = force_reg (mode, cop0);
13281
13282       switch (mode)
13283         {
13284         case V4SImode:
13285         case V2DImode:
13286           {
13287             rtx t1, t2, mask;
13288
13289             /* Perform a parallel modulo subtraction.  */
13290             t1 = gen_reg_rtx (mode);
13291             emit_insn ((mode == V4SImode
13292                         ? gen_subv4si3
13293                         : gen_subv2di3) (t1, cop0, cop1));
13294
13295             /* Extract the original sign bit of op0.  */
13296             mask = ix86_build_signbit_mask (GET_MODE_INNER (mode),
13297                                             true, false);
13298             t2 = gen_reg_rtx (mode);
13299             emit_insn ((mode == V4SImode
13300                         ? gen_andv4si3
13301                         : gen_andv2di3) (t2, cop0, mask));
13302
13303             /* XOR it back into the result of the subtraction.  This results
13304                in the sign bit set iff we saw unsigned underflow.  */
13305             x = gen_reg_rtx (mode);
13306             emit_insn ((mode == V4SImode
13307                         ? gen_xorv4si3
13308                         : gen_xorv2di3) (x, t1, t2));
13309
13310             code = GT;
13311           }
13312           break;
13313
13314         case V16QImode:
13315         case V8HImode:
13316           /* Perform a parallel unsigned saturating subtraction.  */
13317           x = gen_reg_rtx (mode);
13318           emit_insn (gen_rtx_SET (VOIDmode, x,
13319                                   gen_rtx_US_MINUS (mode, cop0, cop1)));
13320
13321           code = EQ;
13322           negate = !negate;
13323           break;
13324
13325         default:
13326           gcc_unreachable ();
13327         }
13328
13329       cop0 = x;
13330       cop1 = CONST0_RTX (mode);
13331     }
13332
13333   x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
13334                            operands[1+negate], operands[2-negate]);
13335
13336   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
13337                          operands[2-negate]);
13338   return true;
13339 }
13340
13341 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
13342    true if we should do zero extension, else sign extension.  HIGH_P is
13343    true if we want the N/2 high elements, else the low elements.  */
13344
13345 void
13346 ix86_expand_sse_unpack (rtx operands[2], bool unsigned_p, bool high_p)
13347 {
13348   enum machine_mode imode = GET_MODE (operands[1]);
13349   rtx (*unpack)(rtx, rtx, rtx);
13350   rtx se, dest;
13351
13352   switch (imode)
13353     {
13354     case V16QImode:
13355       if (high_p)
13356         unpack = gen_vec_interleave_highv16qi;
13357       else
13358         unpack = gen_vec_interleave_lowv16qi;
13359       break;
13360     case V8HImode:
13361       if (high_p)
13362         unpack = gen_vec_interleave_highv8hi;
13363       else
13364         unpack = gen_vec_interleave_lowv8hi;
13365       break;
13366     case V4SImode:
13367       if (high_p)
13368         unpack = gen_vec_interleave_highv4si;
13369       else
13370         unpack = gen_vec_interleave_lowv4si;
13371       break;
13372     default:
13373       gcc_unreachable ();
13374     }
13375
13376   dest = gen_lowpart (imode, operands[0]);
13377
13378   if (unsigned_p)
13379     se = force_reg (imode, CONST0_RTX (imode));
13380   else
13381     se = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
13382                               operands[1], pc_rtx, pc_rtx);
13383
13384   emit_insn (unpack (dest, operands[1], se));
13385 }
13386
13387 /* This function performs the same task as ix86_expand_sse_unpack,
13388    but with SSE4.1 instructions.  */
13389
13390 void
13391 ix86_expand_sse4_unpack (rtx operands[2], bool unsigned_p, bool high_p)
13392 {
13393   enum machine_mode imode = GET_MODE (operands[1]);
13394   rtx (*unpack)(rtx, rtx);
13395   rtx src, dest;
13396
13397   switch (imode)
13398     {
13399     case V16QImode:
13400       if (unsigned_p)
13401         unpack = gen_sse4_1_zero_extendv8qiv8hi2;
13402       else
13403         unpack = gen_sse4_1_extendv8qiv8hi2;
13404       break;
13405     case V8HImode:
13406       if (unsigned_p)
13407         unpack = gen_sse4_1_zero_extendv4hiv4si2;
13408       else
13409         unpack = gen_sse4_1_extendv4hiv4si2;
13410       break;
13411     case V4SImode:
13412       if (unsigned_p)
13413         unpack = gen_sse4_1_zero_extendv2siv2di2;
13414       else
13415         unpack = gen_sse4_1_extendv2siv2di2;
13416       break;
13417     default:
13418       gcc_unreachable ();
13419     }
13420
13421   dest = operands[0];
13422   if (high_p)
13423     {
13424       /* Shift higher 8 bytes to lower 8 bytes.  */
13425       src = gen_reg_rtx (imode);
13426       emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, src),
13427                                    gen_lowpart (TImode, operands[1]),
13428                                    GEN_INT (64)));
13429     }
13430   else
13431     src = operands[1];
13432
13433   emit_insn (unpack (dest, src));
13434 }
13435
13436 /* This function performs the same task as ix86_expand_sse_unpack,
13437    but with amdfam15 instructions.  */
13438
13439 #define PPERM_SRC       0x00            /* copy source */
13440 #define PPERM_INVERT    0x20            /* invert source */
13441 #define PPERM_REVERSE   0x40            /* bit reverse source */
13442 #define PPERM_REV_INV   0x60            /* bit reverse & invert src */
13443 #define PPERM_ZERO      0x80            /* all 0's */
13444 #define PPERM_ONES      0xa0            /* all 1's */
13445 #define PPERM_SIGN      0xc0            /* propigate sign bit */
13446 #define PPERM_INV_SIGN  0xe0            /* invert & propigate sign */
13447
13448 #define PPERM_SRC1      0x00            /* use first source byte */
13449 #define PPERM_SRC2      0x10            /* use second source byte */
13450
13451 void
13452 ix86_expand_sse5_unpack (rtx operands[2], bool unsigned_p, bool high_p)
13453 {
13454   enum machine_mode imode = GET_MODE (operands[1]);
13455   int pperm_bytes[16];
13456   int i;
13457   int h = (high_p) ? 8 : 0;
13458   int h2;
13459   int sign_extend;
13460   rtvec v = rtvec_alloc (16);
13461   rtvec vs;
13462   rtx x, p;
13463   rtx op0 = operands[0], op1 = operands[1];
13464
13465   switch (imode)
13466     {
13467     case V16QImode:
13468       vs = rtvec_alloc (8);
13469       h2 = (high_p) ? 8 : 0;
13470       for (i = 0; i < 8; i++)
13471         {
13472           pperm_bytes[2*i+0] = PPERM_SRC | PPERM_SRC2 | i | h;
13473           pperm_bytes[2*i+1] = ((unsigned_p)
13474                                 ? PPERM_ZERO
13475                                 : PPERM_SIGN | PPERM_SRC2 | i | h);
13476         }
13477
13478       for (i = 0; i < 16; i++)
13479         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
13480
13481       for (i = 0; i < 8; i++)
13482         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
13483
13484       p = gen_rtx_PARALLEL (VOIDmode, vs);
13485       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
13486       if (unsigned_p)
13487         emit_insn (gen_sse5_pperm_zero_v16qi_v8hi (op0, op1, p, x));
13488       else
13489         emit_insn (gen_sse5_pperm_sign_v16qi_v8hi (op0, op1, p, x));
13490       break;
13491
13492     case V8HImode:
13493       vs = rtvec_alloc (4);
13494       h2 = (high_p) ? 4 : 0;
13495       for (i = 0; i < 4; i++)
13496         {
13497           sign_extend = ((unsigned_p)
13498                          ? PPERM_ZERO
13499                          : PPERM_SIGN | PPERM_SRC2 | ((2*i) + 1 + h));
13500           pperm_bytes[4*i+0] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 0 + h);
13501           pperm_bytes[4*i+1] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 1 + h);
13502           pperm_bytes[4*i+2] = sign_extend;
13503           pperm_bytes[4*i+3] = sign_extend;
13504         }
13505
13506       for (i = 0; i < 16; i++)
13507         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
13508
13509       for (i = 0; i < 4; i++)
13510         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
13511
13512       p = gen_rtx_PARALLEL (VOIDmode, vs);
13513       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
13514       if (unsigned_p)
13515         emit_insn (gen_sse5_pperm_zero_v8hi_v4si (op0, op1, p, x));
13516       else
13517         emit_insn (gen_sse5_pperm_sign_v8hi_v4si (op0, op1, p, x));
13518       break;
13519
13520     case V4SImode:
13521       vs = rtvec_alloc (2);
13522       h2 = (high_p) ? 2 : 0;
13523       for (i = 0; i < 2; i++)
13524         {
13525           sign_extend = ((unsigned_p)
13526                          ? PPERM_ZERO
13527                          : PPERM_SIGN | PPERM_SRC2 | ((4*i) + 3 + h));
13528           pperm_bytes[8*i+0] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 0 + h);
13529           pperm_bytes[8*i+1] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 1 + h);
13530           pperm_bytes[8*i+2] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 2 + h);
13531           pperm_bytes[8*i+3] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 3 + h);
13532           pperm_bytes[8*i+4] = sign_extend;
13533           pperm_bytes[8*i+5] = sign_extend;
13534           pperm_bytes[8*i+6] = sign_extend;
13535           pperm_bytes[8*i+7] = sign_extend;
13536         }
13537
13538       for (i = 0; i < 16; i++)
13539         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
13540
13541       for (i = 0; i < 2; i++)
13542         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
13543
13544       p = gen_rtx_PARALLEL (VOIDmode, vs);
13545       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
13546       if (unsigned_p)
13547         emit_insn (gen_sse5_pperm_zero_v4si_v2di (op0, op1, p, x));
13548       else
13549         emit_insn (gen_sse5_pperm_sign_v4si_v2di (op0, op1, p, x));
13550       break;
13551
13552     default:
13553       gcc_unreachable ();
13554     }
13555
13556   return;
13557 }
13558
13559 /* Pack the high bits from OPERANDS[1] and low bits from OPERANDS[2] into the
13560    next narrower integer vector type */
13561 void
13562 ix86_expand_sse5_pack (rtx operands[3])
13563 {
13564   enum machine_mode imode = GET_MODE (operands[0]);
13565   int pperm_bytes[16];
13566   int i;
13567   rtvec v = rtvec_alloc (16);
13568   rtx x;
13569   rtx op0 = operands[0];
13570   rtx op1 = operands[1];
13571   rtx op2 = operands[2];
13572
13573   switch (imode)
13574     {
13575     case V16QImode:
13576       for (i = 0; i < 8; i++)
13577         {
13578           pperm_bytes[i+0] = PPERM_SRC | PPERM_SRC1 | (i*2);
13579           pperm_bytes[i+8] = PPERM_SRC | PPERM_SRC2 | (i*2);
13580         }
13581
13582       for (i = 0; i < 16; i++)
13583         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
13584
13585       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
13586       emit_insn (gen_sse5_pperm_pack_v8hi_v16qi (op0, op1, op2, x));
13587       break;
13588
13589     case V8HImode:
13590       for (i = 0; i < 4; i++)
13591         {
13592           pperm_bytes[(2*i)+0] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 0);
13593           pperm_bytes[(2*i)+1] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 1);
13594           pperm_bytes[(2*i)+8] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 0);
13595           pperm_bytes[(2*i)+9] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 1);
13596         }
13597
13598       for (i = 0; i < 16; i++)
13599         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
13600
13601       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
13602       emit_insn (gen_sse5_pperm_pack_v4si_v8hi (op0, op1, op2, x));
13603       break;
13604
13605     case V4SImode:
13606       for (i = 0; i < 2; i++)
13607         {
13608           pperm_bytes[(4*i)+0]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 0);
13609           pperm_bytes[(4*i)+1]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 1);
13610           pperm_bytes[(4*i)+2]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 2);
13611           pperm_bytes[(4*i)+3]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 3);
13612           pperm_bytes[(4*i)+8]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 0);
13613           pperm_bytes[(4*i)+9]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 1);
13614           pperm_bytes[(4*i)+10] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 2);
13615           pperm_bytes[(4*i)+11] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 3);
13616         }
13617
13618       for (i = 0; i < 16; i++)
13619         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
13620
13621       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
13622       emit_insn (gen_sse5_pperm_pack_v2di_v4si (op0, op1, op2, x));
13623       break;
13624
13625     default:
13626       gcc_unreachable ();
13627     }
13628
13629   return;
13630 }
13631
13632 /* Expand conditional increment or decrement using adb/sbb instructions.
13633    The default case using setcc followed by the conditional move can be
13634    done by generic code.  */
13635 int
13636 ix86_expand_int_addcc (rtx operands[])
13637 {
13638   enum rtx_code code = GET_CODE (operands[1]);
13639   rtx compare_op;
13640   rtx val = const0_rtx;
13641   bool fpcmp = false;
13642   enum machine_mode mode = GET_MODE (operands[0]);
13643
13644   if (operands[3] != const1_rtx
13645       && operands[3] != constm1_rtx)
13646     return 0;
13647   if (!ix86_expand_carry_flag_compare (code, ix86_compare_op0,
13648                                        ix86_compare_op1, &compare_op))
13649      return 0;
13650   code = GET_CODE (compare_op);
13651
13652   if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
13653       || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
13654     {
13655       fpcmp = true;
13656       code = ix86_fp_compare_code_to_integer (code);
13657     }
13658
13659   if (code != LTU)
13660     {
13661       val = constm1_rtx;
13662       if (fpcmp)
13663         PUT_CODE (compare_op,
13664                   reverse_condition_maybe_unordered
13665                     (GET_CODE (compare_op)));
13666       else
13667         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
13668     }
13669   PUT_MODE (compare_op, mode);
13670
13671   /* Construct either adc or sbb insn.  */
13672   if ((code == LTU) == (operands[3] == constm1_rtx))
13673     {
13674       switch (GET_MODE (operands[0]))
13675         {
13676           case QImode:
13677             emit_insn (gen_subqi3_carry (operands[0], operands[2], val, compare_op));
13678             break;
13679           case HImode:
13680             emit_insn (gen_subhi3_carry (operands[0], operands[2], val, compare_op));
13681             break;
13682           case SImode:
13683             emit_insn (gen_subsi3_carry (operands[0], operands[2], val, compare_op));
13684             break;
13685           case DImode:
13686             emit_insn (gen_subdi3_carry_rex64 (operands[0], operands[2], val, compare_op));
13687             break;
13688           default:
13689             gcc_unreachable ();
13690         }
13691     }
13692   else
13693     {
13694       switch (GET_MODE (operands[0]))
13695         {
13696           case QImode:
13697             emit_insn (gen_addqi3_carry (operands[0], operands[2], val, compare_op));
13698             break;
13699           case HImode:
13700             emit_insn (gen_addhi3_carry (operands[0], operands[2], val, compare_op));
13701             break;
13702           case SImode:
13703             emit_insn (gen_addsi3_carry (operands[0], operands[2], val, compare_op));
13704             break;
13705           case DImode:
13706             emit_insn (gen_adddi3_carry_rex64 (operands[0], operands[2], val, compare_op));
13707             break;
13708           default:
13709             gcc_unreachable ();
13710         }
13711     }
13712   return 1; /* DONE */
13713 }
13714
13715
13716 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
13717    works for floating pointer parameters and nonoffsetable memories.
13718    For pushes, it returns just stack offsets; the values will be saved
13719    in the right order.  Maximally three parts are generated.  */
13720
13721 static int
13722 ix86_split_to_parts (rtx operand, rtx *parts, enum machine_mode mode)
13723 {
13724   int size;
13725
13726   if (!TARGET_64BIT)
13727     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
13728   else
13729     size = (GET_MODE_SIZE (mode) + 4) / 8;
13730
13731   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
13732   gcc_assert (size >= 2 && size <= 3);
13733
13734   /* Optimize constant pool reference to immediates.  This is used by fp
13735      moves, that force all constants to memory to allow combining.  */
13736   if (MEM_P (operand) && MEM_READONLY_P (operand))
13737     {
13738       rtx tmp = maybe_get_pool_constant (operand);
13739       if (tmp)
13740         operand = tmp;
13741     }
13742
13743   if (MEM_P (operand) && !offsettable_memref_p (operand))
13744     {
13745       /* The only non-offsetable memories we handle are pushes.  */
13746       int ok = push_operand (operand, VOIDmode);
13747
13748       gcc_assert (ok);
13749
13750       operand = copy_rtx (operand);
13751       PUT_MODE (operand, Pmode);
13752       parts[0] = parts[1] = parts[2] = operand;
13753       return size;
13754     }
13755
13756   if (GET_CODE (operand) == CONST_VECTOR)
13757     {
13758       enum machine_mode imode = int_mode_for_mode (mode);
13759       /* Caution: if we looked through a constant pool memory above,
13760          the operand may actually have a different mode now.  That's
13761          ok, since we want to pun this all the way back to an integer.  */
13762       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
13763       gcc_assert (operand != NULL);
13764       mode = imode;
13765     }
13766
13767   if (!TARGET_64BIT)
13768     {
13769       if (mode == DImode)
13770         split_di (&operand, 1, &parts[0], &parts[1]);
13771       else
13772         {
13773           if (REG_P (operand))
13774             {
13775               gcc_assert (reload_completed);
13776               parts[0] = gen_rtx_REG (SImode, REGNO (operand) + 0);
13777               parts[1] = gen_rtx_REG (SImode, REGNO (operand) + 1);
13778               if (size == 3)
13779                 parts[2] = gen_rtx_REG (SImode, REGNO (operand) + 2);
13780             }
13781           else if (offsettable_memref_p (operand))
13782             {
13783               operand = adjust_address (operand, SImode, 0);
13784               parts[0] = operand;
13785               parts[1] = adjust_address (operand, SImode, 4);
13786               if (size == 3)
13787                 parts[2] = adjust_address (operand, SImode, 8);
13788             }
13789           else if (GET_CODE (operand) == CONST_DOUBLE)
13790             {
13791               REAL_VALUE_TYPE r;
13792               long l[4];
13793
13794               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
13795               switch (mode)
13796                 {
13797                 case XFmode:
13798                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
13799                   parts[2] = gen_int_mode (l[2], SImode);
13800                   break;
13801                 case DFmode:
13802                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
13803                   break;
13804                 default:
13805                   gcc_unreachable ();
13806                 }
13807               parts[1] = gen_int_mode (l[1], SImode);
13808               parts[0] = gen_int_mode (l[0], SImode);
13809             }
13810           else
13811             gcc_unreachable ();
13812         }
13813     }
13814   else
13815     {
13816       if (mode == TImode)
13817         split_ti (&operand, 1, &parts[0], &parts[1]);
13818       if (mode == XFmode || mode == TFmode)
13819         {
13820           enum machine_mode upper_mode = mode==XFmode ? SImode : DImode;
13821           if (REG_P (operand))
13822             {
13823               gcc_assert (reload_completed);
13824               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
13825               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
13826             }
13827           else if (offsettable_memref_p (operand))
13828             {
13829               operand = adjust_address (operand, DImode, 0);
13830               parts[0] = operand;
13831               parts[1] = adjust_address (operand, upper_mode, 8);
13832             }
13833           else if (GET_CODE (operand) == CONST_DOUBLE)
13834             {
13835               REAL_VALUE_TYPE r;
13836               long l[4];
13837
13838               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
13839               real_to_target (l, &r, mode);
13840
13841               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
13842               if (HOST_BITS_PER_WIDE_INT >= 64)
13843                 parts[0]
13844                   = gen_int_mode
13845                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
13846                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
13847                        DImode);
13848               else
13849                 parts[0] = immed_double_const (l[0], l[1], DImode);
13850
13851               if (upper_mode == SImode)
13852                 parts[1] = gen_int_mode (l[2], SImode);
13853               else if (HOST_BITS_PER_WIDE_INT >= 64)
13854                 parts[1]
13855                   = gen_int_mode
13856                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
13857                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
13858                        DImode);
13859               else
13860                 parts[1] = immed_double_const (l[2], l[3], DImode);
13861             }
13862           else
13863             gcc_unreachable ();
13864         }
13865     }
13866
13867   return size;
13868 }
13869
13870 /* Emit insns to perform a move or push of DI, DF, and XF values.
13871    Return false when normal moves are needed; true when all required
13872    insns have been emitted.  Operands 2-4 contain the input values
13873    int the correct order; operands 5-7 contain the output values.  */
13874
13875 void
13876 ix86_split_long_move (rtx operands[])
13877 {
13878   rtx part[2][3];
13879   int nparts;
13880   int push = 0;
13881   int collisions = 0;
13882   enum machine_mode mode = GET_MODE (operands[0]);
13883
13884   /* The DFmode expanders may ask us to move double.
13885      For 64bit target this is single move.  By hiding the fact
13886      here we simplify i386.md splitters.  */
13887   if (GET_MODE_SIZE (GET_MODE (operands[0])) == 8 && TARGET_64BIT)
13888     {
13889       /* Optimize constant pool reference to immediates.  This is used by
13890          fp moves, that force all constants to memory to allow combining.  */
13891
13892       if (MEM_P (operands[1])
13893           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
13894           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
13895         operands[1] = get_pool_constant (XEXP (operands[1], 0));
13896       if (push_operand (operands[0], VOIDmode))
13897         {
13898           operands[0] = copy_rtx (operands[0]);
13899           PUT_MODE (operands[0], Pmode);
13900         }
13901       else
13902         operands[0] = gen_lowpart (DImode, operands[0]);
13903       operands[1] = gen_lowpart (DImode, operands[1]);
13904       emit_move_insn (operands[0], operands[1]);
13905       return;
13906     }
13907
13908   /* The only non-offsettable memory we handle is push.  */
13909   if (push_operand (operands[0], VOIDmode))
13910     push = 1;
13911   else
13912     gcc_assert (!MEM_P (operands[0])
13913                 || offsettable_memref_p (operands[0]));
13914
13915   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
13916   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
13917
13918   /* When emitting push, take care for source operands on the stack.  */
13919   if (push && MEM_P (operands[1])
13920       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
13921     {
13922       if (nparts == 3)
13923         part[1][1] = change_address (part[1][1], GET_MODE (part[1][1]),
13924                                      XEXP (part[1][2], 0));
13925       part[1][0] = change_address (part[1][0], GET_MODE (part[1][0]),
13926                                    XEXP (part[1][1], 0));
13927     }
13928
13929   /* We need to do copy in the right order in case an address register
13930      of the source overlaps the destination.  */
13931   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
13932     {
13933       if (reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0)))
13934         collisions++;
13935       if (reg_overlap_mentioned_p (part[0][1], XEXP (part[1][0], 0)))
13936         collisions++;
13937       if (nparts == 3
13938           && reg_overlap_mentioned_p (part[0][2], XEXP (part[1][0], 0)))
13939         collisions++;
13940
13941       /* Collision in the middle part can be handled by reordering.  */
13942       if (collisions == 1 && nparts == 3
13943           && reg_overlap_mentioned_p (part[0][1], XEXP (part[1][0], 0)))
13944         {
13945           rtx tmp;
13946           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
13947           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
13948         }
13949
13950       /* If there are more collisions, we can't handle it by reordering.
13951          Do an lea to the last part and use only one colliding move.  */
13952       else if (collisions > 1)
13953         {
13954           rtx base;
13955
13956           collisions = 1;
13957
13958           base = part[0][nparts - 1];
13959
13960           /* Handle the case when the last part isn't valid for lea.
13961              Happens in 64-bit mode storing the 12-byte XFmode.  */
13962           if (GET_MODE (base) != Pmode)
13963             base = gen_rtx_REG (Pmode, REGNO (base));
13964
13965           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
13966           part[1][0] = replace_equiv_address (part[1][0], base);
13967           part[1][1] = replace_equiv_address (part[1][1],
13968                                       plus_constant (base, UNITS_PER_WORD));
13969           if (nparts == 3)
13970             part[1][2] = replace_equiv_address (part[1][2],
13971                                       plus_constant (base, 8));
13972         }
13973     }
13974
13975   if (push)
13976     {
13977       if (!TARGET_64BIT)
13978         {
13979           if (nparts == 3)
13980             {
13981               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
13982                 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-4)));
13983               emit_move_insn (part[0][2], part[1][2]);
13984             }
13985         }
13986       else
13987         {
13988           /* In 64bit mode we don't have 32bit push available.  In case this is
13989              register, it is OK - we will just use larger counterpart.  We also
13990              retype memory - these comes from attempt to avoid REX prefix on
13991              moving of second half of TFmode value.  */
13992           if (GET_MODE (part[1][1]) == SImode)
13993             {
13994               switch (GET_CODE (part[1][1]))
13995                 {
13996                 case MEM:
13997                   part[1][1] = adjust_address (part[1][1], DImode, 0);
13998                   break;
13999
14000                 case REG:
14001                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
14002                   break;
14003
14004                 default:
14005                   gcc_unreachable ();
14006                 }
14007
14008               if (GET_MODE (part[1][0]) == SImode)
14009                 part[1][0] = part[1][1];
14010             }
14011         }
14012       emit_move_insn (part[0][1], part[1][1]);
14013       emit_move_insn (part[0][0], part[1][0]);
14014       return;
14015     }
14016
14017   /* Choose correct order to not overwrite the source before it is copied.  */
14018   if ((REG_P (part[0][0])
14019        && REG_P (part[1][1])
14020        && (REGNO (part[0][0]) == REGNO (part[1][1])
14021            || (nparts == 3
14022                && REGNO (part[0][0]) == REGNO (part[1][2]))))
14023       || (collisions > 0
14024           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
14025     {
14026       if (nparts == 3)
14027         {
14028           operands[2] = part[0][2];
14029           operands[3] = part[0][1];
14030           operands[4] = part[0][0];
14031           operands[5] = part[1][2];
14032           operands[6] = part[1][1];
14033           operands[7] = part[1][0];
14034         }
14035       else
14036         {
14037           operands[2] = part[0][1];
14038           operands[3] = part[0][0];
14039           operands[5] = part[1][1];
14040           operands[6] = part[1][0];
14041         }
14042     }
14043   else
14044     {
14045       if (nparts == 3)
14046         {
14047           operands[2] = part[0][0];
14048           operands[3] = part[0][1];
14049           operands[4] = part[0][2];
14050           operands[5] = part[1][0];
14051           operands[6] = part[1][1];
14052           operands[7] = part[1][2];
14053         }
14054       else
14055         {
14056           operands[2] = part[0][0];
14057           operands[3] = part[0][1];
14058           operands[5] = part[1][0];
14059           operands[6] = part[1][1];
14060         }
14061     }
14062
14063   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
14064   if (optimize_size)
14065     {
14066       if (CONST_INT_P (operands[5])
14067           && operands[5] != const0_rtx
14068           && REG_P (operands[2]))
14069         {
14070           if (CONST_INT_P (operands[6])
14071               && INTVAL (operands[6]) == INTVAL (operands[5]))
14072             operands[6] = operands[2];
14073
14074           if (nparts == 3
14075               && CONST_INT_P (operands[7])
14076               && INTVAL (operands[7]) == INTVAL (operands[5]))
14077             operands[7] = operands[2];
14078         }
14079
14080       if (nparts == 3
14081           && CONST_INT_P (operands[6])
14082           && operands[6] != const0_rtx
14083           && REG_P (operands[3])
14084           && CONST_INT_P (operands[7])
14085           && INTVAL (operands[7]) == INTVAL (operands[6]))
14086         operands[7] = operands[3];
14087     }
14088
14089   emit_move_insn (operands[2], operands[5]);
14090   emit_move_insn (operands[3], operands[6]);
14091   if (nparts == 3)
14092     emit_move_insn (operands[4], operands[7]);
14093
14094   return;
14095 }
14096
14097 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
14098    left shift by a constant, either using a single shift or
14099    a sequence of add instructions.  */
14100
14101 static void
14102 ix86_expand_ashl_const (rtx operand, int count, enum machine_mode mode)
14103 {
14104   if (count == 1)
14105     {
14106       emit_insn ((mode == DImode
14107                   ? gen_addsi3
14108                   : gen_adddi3) (operand, operand, operand));
14109     }
14110   else if (!optimize_size
14111            && count * ix86_cost->add <= ix86_cost->shift_const)
14112     {
14113       int i;
14114       for (i=0; i<count; i++)
14115         {
14116           emit_insn ((mode == DImode
14117                       ? gen_addsi3
14118                       : gen_adddi3) (operand, operand, operand));
14119         }
14120     }
14121   else
14122     emit_insn ((mode == DImode
14123                 ? gen_ashlsi3
14124                 : gen_ashldi3) (operand, operand, GEN_INT (count)));
14125 }
14126
14127 void
14128 ix86_split_ashl (rtx *operands, rtx scratch, enum machine_mode mode)
14129 {
14130   rtx low[2], high[2];
14131   int count;
14132   const int single_width = mode == DImode ? 32 : 64;
14133
14134   if (CONST_INT_P (operands[2]))
14135     {
14136       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
14137       count = INTVAL (operands[2]) & (single_width * 2 - 1);
14138
14139       if (count >= single_width)
14140         {
14141           emit_move_insn (high[0], low[1]);
14142           emit_move_insn (low[0], const0_rtx);
14143
14144           if (count > single_width)
14145             ix86_expand_ashl_const (high[0], count - single_width, mode);
14146         }
14147       else
14148         {
14149           if (!rtx_equal_p (operands[0], operands[1]))
14150             emit_move_insn (operands[0], operands[1]);
14151           emit_insn ((mode == DImode
14152                      ? gen_x86_shld_1
14153                      : gen_x86_64_shld) (high[0], low[0], GEN_INT (count)));
14154           ix86_expand_ashl_const (low[0], count, mode);
14155         }
14156       return;
14157     }
14158
14159   (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
14160
14161   if (operands[1] == const1_rtx)
14162     {
14163       /* Assuming we've chosen a QImode capable registers, then 1 << N
14164          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
14165       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
14166         {
14167           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
14168
14169           ix86_expand_clear (low[0]);
14170           ix86_expand_clear (high[0]);
14171           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (single_width)));
14172
14173           d = gen_lowpart (QImode, low[0]);
14174           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
14175           s = gen_rtx_EQ (QImode, flags, const0_rtx);
14176           emit_insn (gen_rtx_SET (VOIDmode, d, s));
14177
14178           d = gen_lowpart (QImode, high[0]);
14179           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
14180           s = gen_rtx_NE (QImode, flags, const0_rtx);
14181           emit_insn (gen_rtx_SET (VOIDmode, d, s));
14182         }
14183
14184       /* Otherwise, we can get the same results by manually performing
14185          a bit extract operation on bit 5/6, and then performing the two
14186          shifts.  The two methods of getting 0/1 into low/high are exactly
14187          the same size.  Avoiding the shift in the bit extract case helps
14188          pentium4 a bit; no one else seems to care much either way.  */
14189       else
14190         {
14191           rtx x;
14192
14193           if (TARGET_PARTIAL_REG_STALL && !optimize_size)
14194             x = gen_rtx_ZERO_EXTEND (mode == DImode ? SImode : DImode, operands[2]);
14195           else
14196             x = gen_lowpart (mode == DImode ? SImode : DImode, operands[2]);
14197           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
14198
14199           emit_insn ((mode == DImode
14200                       ? gen_lshrsi3
14201                       : gen_lshrdi3) (high[0], high[0], GEN_INT (mode == DImode ? 5 : 6)));
14202           emit_insn ((mode == DImode
14203                       ? gen_andsi3
14204                       : gen_anddi3) (high[0], high[0], GEN_INT (1)));
14205           emit_move_insn (low[0], high[0]);
14206           emit_insn ((mode == DImode
14207                       ? gen_xorsi3
14208                       : gen_xordi3) (low[0], low[0], GEN_INT (1)));
14209         }
14210
14211       emit_insn ((mode == DImode
14212                     ? gen_ashlsi3
14213                     : gen_ashldi3) (low[0], low[0], operands[2]));
14214       emit_insn ((mode == DImode
14215                     ? gen_ashlsi3
14216                     : gen_ashldi3) (high[0], high[0], operands[2]));
14217       return;
14218     }
14219
14220   if (operands[1] == constm1_rtx)
14221     {
14222       /* For -1 << N, we can avoid the shld instruction, because we
14223          know that we're shifting 0...31/63 ones into a -1.  */
14224       emit_move_insn (low[0], constm1_rtx);
14225       if (optimize_size)
14226         emit_move_insn (high[0], low[0]);
14227       else
14228         emit_move_insn (high[0], constm1_rtx);
14229     }
14230   else
14231     {
14232       if (!rtx_equal_p (operands[0], operands[1]))
14233         emit_move_insn (operands[0], operands[1]);
14234
14235       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
14236       emit_insn ((mode == DImode
14237                   ? gen_x86_shld_1
14238                   : gen_x86_64_shld) (high[0], low[0], operands[2]));
14239     }
14240
14241   emit_insn ((mode == DImode ? gen_ashlsi3 : gen_ashldi3) (low[0], low[0], operands[2]));
14242
14243   if (TARGET_CMOVE && scratch)
14244     {
14245       ix86_expand_clear (scratch);
14246       emit_insn ((mode == DImode
14247                   ? gen_x86_shift_adj_1
14248                   : gen_x86_64_shift_adj) (high[0], low[0], operands[2], scratch));
14249     }
14250   else
14251     emit_insn (gen_x86_shift_adj_2 (high[0], low[0], operands[2]));
14252 }
14253
14254 void
14255 ix86_split_ashr (rtx *operands, rtx scratch, enum machine_mode mode)
14256 {
14257   rtx low[2], high[2];
14258   int count;
14259   const int single_width = mode == DImode ? 32 : 64;
14260
14261   if (CONST_INT_P (operands[2]))
14262     {
14263       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
14264       count = INTVAL (operands[2]) & (single_width * 2 - 1);
14265
14266       if (count == single_width * 2 - 1)
14267         {
14268           emit_move_insn (high[0], high[1]);
14269           emit_insn ((mode == DImode
14270                       ? gen_ashrsi3
14271                       : gen_ashrdi3) (high[0], high[0],
14272                                       GEN_INT (single_width - 1)));
14273           emit_move_insn (low[0], high[0]);
14274
14275         }
14276       else if (count >= single_width)
14277         {
14278           emit_move_insn (low[0], high[1]);
14279           emit_move_insn (high[0], low[0]);
14280           emit_insn ((mode == DImode
14281                       ? gen_ashrsi3
14282                       : gen_ashrdi3) (high[0], high[0],
14283                                       GEN_INT (single_width - 1)));
14284           if (count > single_width)
14285             emit_insn ((mode == DImode
14286                         ? gen_ashrsi3
14287                         : gen_ashrdi3) (low[0], low[0],
14288                                         GEN_INT (count - single_width)));
14289         }
14290       else
14291         {
14292           if (!rtx_equal_p (operands[0], operands[1]))
14293             emit_move_insn (operands[0], operands[1]);
14294           emit_insn ((mode == DImode
14295                       ? gen_x86_shrd_1
14296                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
14297           emit_insn ((mode == DImode
14298                       ? gen_ashrsi3
14299                       : gen_ashrdi3) (high[0], high[0], GEN_INT (count)));
14300         }
14301     }
14302   else
14303     {
14304       if (!rtx_equal_p (operands[0], operands[1]))
14305         emit_move_insn (operands[0], operands[1]);
14306
14307       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
14308
14309       emit_insn ((mode == DImode
14310                   ? gen_x86_shrd_1
14311                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
14312       emit_insn ((mode == DImode
14313                   ? gen_ashrsi3
14314                   : gen_ashrdi3)  (high[0], high[0], operands[2]));
14315
14316       if (TARGET_CMOVE && scratch)
14317         {
14318           emit_move_insn (scratch, high[0]);
14319           emit_insn ((mode == DImode
14320                       ? gen_ashrsi3
14321                       : gen_ashrdi3) (scratch, scratch,
14322                                       GEN_INT (single_width - 1)));
14323           emit_insn ((mode == DImode
14324                       ? gen_x86_shift_adj_1
14325                       : gen_x86_64_shift_adj) (low[0], high[0], operands[2],
14326                                          scratch));
14327         }
14328       else
14329         emit_insn (gen_x86_shift_adj_3 (low[0], high[0], operands[2]));
14330     }
14331 }
14332
14333 void
14334 ix86_split_lshr (rtx *operands, rtx scratch, enum machine_mode mode)
14335 {
14336   rtx low[2], high[2];
14337   int count;
14338   const int single_width = mode == DImode ? 32 : 64;
14339
14340   if (CONST_INT_P (operands[2]))
14341     {
14342       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
14343       count = INTVAL (operands[2]) & (single_width * 2 - 1);
14344
14345       if (count >= single_width)
14346         {
14347           emit_move_insn (low[0], high[1]);
14348           ix86_expand_clear (high[0]);
14349
14350           if (count > single_width)
14351             emit_insn ((mode == DImode
14352                         ? gen_lshrsi3
14353                         : gen_lshrdi3) (low[0], low[0],
14354                                         GEN_INT (count - single_width)));
14355         }
14356       else
14357         {
14358           if (!rtx_equal_p (operands[0], operands[1]))
14359             emit_move_insn (operands[0], operands[1]);
14360           emit_insn ((mode == DImode
14361                       ? gen_x86_shrd_1
14362                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
14363           emit_insn ((mode == DImode
14364                       ? gen_lshrsi3
14365                       : gen_lshrdi3) (high[0], high[0], GEN_INT (count)));
14366         }
14367     }
14368   else
14369     {
14370       if (!rtx_equal_p (operands[0], operands[1]))
14371         emit_move_insn (operands[0], operands[1]);
14372
14373       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
14374
14375       emit_insn ((mode == DImode
14376                   ? gen_x86_shrd_1
14377                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
14378       emit_insn ((mode == DImode
14379                   ? gen_lshrsi3
14380                   : gen_lshrdi3) (high[0], high[0], operands[2]));
14381
14382       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
14383       if (TARGET_CMOVE && scratch)
14384         {
14385           ix86_expand_clear (scratch);
14386           emit_insn ((mode == DImode
14387                       ? gen_x86_shift_adj_1
14388                       : gen_x86_64_shift_adj) (low[0], high[0], operands[2],
14389                                                scratch));
14390         }
14391       else
14392         emit_insn (gen_x86_shift_adj_2 (low[0], high[0], operands[2]));
14393     }
14394 }
14395
14396 /* Predict just emitted jump instruction to be taken with probability PROB.  */
14397 static void
14398 predict_jump (int prob)
14399 {
14400   rtx insn = get_last_insn ();
14401   gcc_assert (JUMP_P (insn));
14402   REG_NOTES (insn)
14403     = gen_rtx_EXPR_LIST (REG_BR_PROB,
14404                          GEN_INT (prob),
14405                          REG_NOTES (insn));
14406 }
14407
14408 /* Helper function for the string operations below.  Dest VARIABLE whether
14409    it is aligned to VALUE bytes.  If true, jump to the label.  */
14410 static rtx
14411 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
14412 {
14413   rtx label = gen_label_rtx ();
14414   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
14415   if (GET_MODE (variable) == DImode)
14416     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
14417   else
14418     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
14419   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
14420                            1, label);
14421   if (epilogue)
14422     predict_jump (REG_BR_PROB_BASE * 50 / 100);
14423   else
14424     predict_jump (REG_BR_PROB_BASE * 90 / 100);
14425   return label;
14426 }
14427
14428 /* Adjust COUNTER by the VALUE.  */
14429 static void
14430 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
14431 {
14432   if (GET_MODE (countreg) == DImode)
14433     emit_insn (gen_adddi3 (countreg, countreg, GEN_INT (-value)));
14434   else
14435     emit_insn (gen_addsi3 (countreg, countreg, GEN_INT (-value)));
14436 }
14437
14438 /* Zero extend possibly SImode EXP to Pmode register.  */
14439 rtx
14440 ix86_zero_extend_to_Pmode (rtx exp)
14441 {
14442   rtx r;
14443   if (GET_MODE (exp) == VOIDmode)
14444     return force_reg (Pmode, exp);
14445   if (GET_MODE (exp) == Pmode)
14446     return copy_to_mode_reg (Pmode, exp);
14447   r = gen_reg_rtx (Pmode);
14448   emit_insn (gen_zero_extendsidi2 (r, exp));
14449   return r;
14450 }
14451
14452 /* Divide COUNTREG by SCALE.  */
14453 static rtx
14454 scale_counter (rtx countreg, int scale)
14455 {
14456   rtx sc;
14457   rtx piece_size_mask;
14458
14459   if (scale == 1)
14460     return countreg;
14461   if (CONST_INT_P (countreg))
14462     return GEN_INT (INTVAL (countreg) / scale);
14463   gcc_assert (REG_P (countreg));
14464
14465   piece_size_mask = GEN_INT (scale - 1);
14466   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
14467                             GEN_INT (exact_log2 (scale)),
14468                             NULL, 1, OPTAB_DIRECT);
14469   return sc;
14470 }
14471
14472 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
14473    DImode for constant loop counts.  */
14474
14475 static enum machine_mode
14476 counter_mode (rtx count_exp)
14477 {
14478   if (GET_MODE (count_exp) != VOIDmode)
14479     return GET_MODE (count_exp);
14480   if (GET_CODE (count_exp) != CONST_INT)
14481     return Pmode;
14482   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
14483     return DImode;
14484   return SImode;
14485 }
14486
14487 /* When SRCPTR is non-NULL, output simple loop to move memory
14488    pointer to SRCPTR to DESTPTR via chunks of MODE unrolled UNROLL times,
14489    overall size is COUNT specified in bytes.  When SRCPTR is NULL, output the
14490    equivalent loop to set memory by VALUE (supposed to be in MODE).
14491
14492    The size is rounded down to whole number of chunk size moved at once.
14493    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
14494
14495
14496 static void
14497 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
14498                                rtx destptr, rtx srcptr, rtx value,
14499                                rtx count, enum machine_mode mode, int unroll,
14500                                int expected_size)
14501 {
14502   rtx out_label, top_label, iter, tmp;
14503   enum machine_mode iter_mode = counter_mode (count);
14504   rtx piece_size = GEN_INT (GET_MODE_SIZE (mode) * unroll);
14505   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
14506   rtx size;
14507   rtx x_addr;
14508   rtx y_addr;
14509   int i;
14510
14511   top_label = gen_label_rtx ();
14512   out_label = gen_label_rtx ();
14513   iter = gen_reg_rtx (iter_mode);
14514
14515   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
14516                               NULL, 1, OPTAB_DIRECT);
14517   /* Those two should combine.  */
14518   if (piece_size == const1_rtx)
14519     {
14520       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
14521                                true, out_label);
14522       predict_jump (REG_BR_PROB_BASE * 10 / 100);
14523     }
14524   emit_move_insn (iter, const0_rtx);
14525
14526   emit_label (top_label);
14527
14528   tmp = convert_modes (Pmode, iter_mode, iter, true);
14529   x_addr = gen_rtx_PLUS (Pmode, destptr, tmp);
14530   destmem = change_address (destmem, mode, x_addr);
14531
14532   if (srcmem)
14533     {
14534       y_addr = gen_rtx_PLUS (Pmode, srcptr, copy_rtx (tmp));
14535       srcmem = change_address (srcmem, mode, y_addr);
14536
14537       /* When unrolling for chips that reorder memory reads and writes,
14538          we can save registers by using single temporary.
14539          Also using 4 temporaries is overkill in 32bit mode.  */
14540       if (!TARGET_64BIT && 0)
14541         {
14542           for (i = 0; i < unroll; i++)
14543             {
14544               if (i)
14545                 {
14546                   destmem =
14547                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
14548                   srcmem =
14549                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
14550                 }
14551               emit_move_insn (destmem, srcmem);
14552             }
14553         }
14554       else
14555         {
14556           rtx tmpreg[4];
14557           gcc_assert (unroll <= 4);
14558           for (i = 0; i < unroll; i++)
14559             {
14560               tmpreg[i] = gen_reg_rtx (mode);
14561               if (i)
14562                 {
14563                   srcmem =
14564                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
14565                 }
14566               emit_move_insn (tmpreg[i], srcmem);
14567             }
14568           for (i = 0; i < unroll; i++)
14569             {
14570               if (i)
14571                 {
14572                   destmem =
14573                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
14574                 }
14575               emit_move_insn (destmem, tmpreg[i]);
14576             }
14577         }
14578     }
14579   else
14580     for (i = 0; i < unroll; i++)
14581       {
14582         if (i)
14583           destmem =
14584             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
14585         emit_move_insn (destmem, value);
14586       }
14587
14588   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
14589                              true, OPTAB_LIB_WIDEN);
14590   if (tmp != iter)
14591     emit_move_insn (iter, tmp);
14592
14593   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
14594                            true, top_label);
14595   if (expected_size != -1)
14596     {
14597       expected_size /= GET_MODE_SIZE (mode) * unroll;
14598       if (expected_size == 0)
14599         predict_jump (0);
14600       else if (expected_size > REG_BR_PROB_BASE)
14601         predict_jump (REG_BR_PROB_BASE - 1);
14602       else
14603         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
14604     }
14605   else
14606     predict_jump (REG_BR_PROB_BASE * 80 / 100);
14607   iter = ix86_zero_extend_to_Pmode (iter);
14608   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
14609                              true, OPTAB_LIB_WIDEN);
14610   if (tmp != destptr)
14611     emit_move_insn (destptr, tmp);
14612   if (srcptr)
14613     {
14614       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
14615                                  true, OPTAB_LIB_WIDEN);
14616       if (tmp != srcptr)
14617         emit_move_insn (srcptr, tmp);
14618     }
14619   emit_label (out_label);
14620 }
14621
14622 /* Output "rep; mov" instruction.
14623    Arguments have same meaning as for previous function */
14624 static void
14625 expand_movmem_via_rep_mov (rtx destmem, rtx srcmem,
14626                            rtx destptr, rtx srcptr,
14627                            rtx count,
14628                            enum machine_mode mode)
14629 {
14630   rtx destexp;
14631   rtx srcexp;
14632   rtx countreg;
14633
14634   /* If the size is known, it is shorter to use rep movs.  */
14635   if (mode == QImode && CONST_INT_P (count)
14636       && !(INTVAL (count) & 3))
14637     mode = SImode;
14638
14639   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
14640     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
14641   if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
14642     srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
14643   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
14644   if (mode != QImode)
14645     {
14646       destexp = gen_rtx_ASHIFT (Pmode, countreg,
14647                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
14648       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
14649       srcexp = gen_rtx_ASHIFT (Pmode, countreg,
14650                                GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
14651       srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
14652     }
14653   else
14654     {
14655       destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
14656       srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
14657     }
14658   emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
14659                           destexp, srcexp));
14660 }
14661
14662 /* Output "rep; stos" instruction.
14663    Arguments have same meaning as for previous function */
14664 static void
14665 expand_setmem_via_rep_stos (rtx destmem, rtx destptr, rtx value,
14666                             rtx count,
14667                             enum machine_mode mode)
14668 {
14669   rtx destexp;
14670   rtx countreg;
14671
14672   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
14673     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
14674   value = force_reg (mode, gen_lowpart (mode, value));
14675   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
14676   if (mode != QImode)
14677     {
14678       destexp = gen_rtx_ASHIFT (Pmode, countreg,
14679                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
14680       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
14681     }
14682   else
14683     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
14684   emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
14685 }
14686
14687 static void
14688 emit_strmov (rtx destmem, rtx srcmem,
14689              rtx destptr, rtx srcptr, enum machine_mode mode, int offset)
14690 {
14691   rtx src = adjust_automodify_address_nv (srcmem, mode, srcptr, offset);
14692   rtx dest = adjust_automodify_address_nv (destmem, mode, destptr, offset);
14693   emit_insn (gen_strmov (destptr, dest, srcptr, src));
14694 }
14695
14696 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
14697 static void
14698 expand_movmem_epilogue (rtx destmem, rtx srcmem,
14699                         rtx destptr, rtx srcptr, rtx count, int max_size)
14700 {
14701   rtx src, dest;
14702   if (CONST_INT_P (count))
14703     {
14704       HOST_WIDE_INT countval = INTVAL (count);
14705       int offset = 0;
14706
14707       if ((countval & 0x10) && max_size > 16)
14708         {
14709           if (TARGET_64BIT)
14710             {
14711               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
14712               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset + 8);
14713             }
14714           else
14715             gcc_unreachable ();
14716           offset += 16;
14717         }
14718       if ((countval & 0x08) && max_size > 8)
14719         {
14720           if (TARGET_64BIT)
14721             emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
14722           else
14723             {
14724               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
14725               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset + 4);
14726             }
14727           offset += 8;
14728         }
14729       if ((countval & 0x04) && max_size > 4)
14730         {
14731           emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
14732           offset += 4;
14733         }
14734       if ((countval & 0x02) && max_size > 2)
14735         {
14736           emit_strmov (destmem, srcmem, destptr, srcptr, HImode, offset);
14737           offset += 2;
14738         }
14739       if ((countval & 0x01) && max_size > 1)
14740         {
14741           emit_strmov (destmem, srcmem, destptr, srcptr, QImode, offset);
14742           offset += 1;
14743         }
14744       return;
14745     }
14746   if (max_size > 8)
14747     {
14748       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
14749                                     count, 1, OPTAB_DIRECT);
14750       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
14751                                      count, QImode, 1, 4);
14752       return;
14753     }
14754
14755   /* When there are stringops, we can cheaply increase dest and src pointers.
14756      Otherwise we save code size by maintaining offset (zero is readily
14757      available from preceding rep operation) and using x86 addressing modes.
14758    */
14759   if (TARGET_SINGLE_STRINGOP)
14760     {
14761       if (max_size > 4)
14762         {
14763           rtx label = ix86_expand_aligntest (count, 4, true);
14764           src = change_address (srcmem, SImode, srcptr);
14765           dest = change_address (destmem, SImode, destptr);
14766           emit_insn (gen_strmov (destptr, dest, srcptr, src));
14767           emit_label (label);
14768           LABEL_NUSES (label) = 1;
14769         }
14770       if (max_size > 2)
14771         {
14772           rtx label = ix86_expand_aligntest (count, 2, true);
14773           src = change_address (srcmem, HImode, srcptr);
14774           dest = change_address (destmem, HImode, destptr);
14775           emit_insn (gen_strmov (destptr, dest, srcptr, src));
14776           emit_label (label);
14777           LABEL_NUSES (label) = 1;
14778         }
14779       if (max_size > 1)
14780         {
14781           rtx label = ix86_expand_aligntest (count, 1, true);
14782           src = change_address (srcmem, QImode, srcptr);
14783           dest = change_address (destmem, QImode, destptr);
14784           emit_insn (gen_strmov (destptr, dest, srcptr, src));
14785           emit_label (label);
14786           LABEL_NUSES (label) = 1;
14787         }
14788     }
14789   else
14790     {
14791       rtx offset = force_reg (Pmode, const0_rtx);
14792       rtx tmp;
14793
14794       if (max_size > 4)
14795         {
14796           rtx label = ix86_expand_aligntest (count, 4, true);
14797           src = change_address (srcmem, SImode, srcptr);
14798           dest = change_address (destmem, SImode, destptr);
14799           emit_move_insn (dest, src);
14800           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
14801                                      true, OPTAB_LIB_WIDEN);
14802           if (tmp != offset)
14803             emit_move_insn (offset, tmp);
14804           emit_label (label);
14805           LABEL_NUSES (label) = 1;
14806         }
14807       if (max_size > 2)
14808         {
14809           rtx label = ix86_expand_aligntest (count, 2, true);
14810           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
14811           src = change_address (srcmem, HImode, tmp);
14812           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
14813           dest = change_address (destmem, HImode, tmp);
14814           emit_move_insn (dest, src);
14815           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
14816                                      true, OPTAB_LIB_WIDEN);
14817           if (tmp != offset)
14818             emit_move_insn (offset, tmp);
14819           emit_label (label);
14820           LABEL_NUSES (label) = 1;
14821         }
14822       if (max_size > 1)
14823         {
14824           rtx label = ix86_expand_aligntest (count, 1, true);
14825           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
14826           src = change_address (srcmem, QImode, tmp);
14827           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
14828           dest = change_address (destmem, QImode, tmp);
14829           emit_move_insn (dest, src);
14830           emit_label (label);
14831           LABEL_NUSES (label) = 1;
14832         }
14833     }
14834 }
14835
14836 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
14837 static void
14838 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
14839                                  rtx count, int max_size)
14840 {
14841   count =
14842     expand_simple_binop (counter_mode (count), AND, count,
14843                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
14844   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
14845                                  gen_lowpart (QImode, value), count, QImode,
14846                                  1, max_size / 2);
14847 }
14848
14849 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
14850 static void
14851 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx count, int max_size)
14852 {
14853   rtx dest;
14854
14855   if (CONST_INT_P (count))
14856     {
14857       HOST_WIDE_INT countval = INTVAL (count);
14858       int offset = 0;
14859
14860       if ((countval & 0x10) && max_size > 16)
14861         {
14862           if (TARGET_64BIT)
14863             {
14864               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
14865               emit_insn (gen_strset (destptr, dest, value));
14866               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset + 8);
14867               emit_insn (gen_strset (destptr, dest, value));
14868             }
14869           else
14870             gcc_unreachable ();
14871           offset += 16;
14872         }
14873       if ((countval & 0x08) && max_size > 8)
14874         {
14875           if (TARGET_64BIT)
14876             {
14877               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
14878               emit_insn (gen_strset (destptr, dest, value));
14879             }
14880           else
14881             {
14882               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
14883               emit_insn (gen_strset (destptr, dest, value));
14884               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset + 4);
14885               emit_insn (gen_strset (destptr, dest, value));
14886             }
14887           offset += 8;
14888         }
14889       if ((countval & 0x04) && max_size > 4)
14890         {
14891           dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
14892           emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
14893           offset += 4;
14894         }
14895       if ((countval & 0x02) && max_size > 2)
14896         {
14897           dest = adjust_automodify_address_nv (destmem, HImode, destptr, offset);
14898           emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
14899           offset += 2;
14900         }
14901       if ((countval & 0x01) && max_size > 1)
14902         {
14903           dest = adjust_automodify_address_nv (destmem, QImode, destptr, offset);
14904           emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
14905           offset += 1;
14906         }
14907       return;
14908     }
14909   if (max_size > 32)
14910     {
14911       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
14912       return;
14913     }
14914   if (max_size > 16)
14915     {
14916       rtx label = ix86_expand_aligntest (count, 16, true);
14917       if (TARGET_64BIT)
14918         {
14919           dest = change_address (destmem, DImode, destptr);
14920           emit_insn (gen_strset (destptr, dest, value));
14921           emit_insn (gen_strset (destptr, dest, value));
14922         }
14923       else
14924         {
14925           dest = change_address (destmem, SImode, destptr);
14926           emit_insn (gen_strset (destptr, dest, value));
14927           emit_insn (gen_strset (destptr, dest, value));
14928           emit_insn (gen_strset (destptr, dest, value));
14929           emit_insn (gen_strset (destptr, dest, value));
14930         }
14931       emit_label (label);
14932       LABEL_NUSES (label) = 1;
14933     }
14934   if (max_size > 8)
14935     {
14936       rtx label = ix86_expand_aligntest (count, 8, true);
14937       if (TARGET_64BIT)
14938         {
14939           dest = change_address (destmem, DImode, destptr);
14940           emit_insn (gen_strset (destptr, dest, value));
14941         }
14942       else
14943         {
14944           dest = change_address (destmem, SImode, destptr);
14945           emit_insn (gen_strset (destptr, dest, value));
14946           emit_insn (gen_strset (destptr, dest, value));
14947         }
14948       emit_label (label);
14949       LABEL_NUSES (label) = 1;
14950     }
14951   if (max_size > 4)
14952     {
14953       rtx label = ix86_expand_aligntest (count, 4, true);
14954       dest = change_address (destmem, SImode, destptr);
14955       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
14956       emit_label (label);
14957       LABEL_NUSES (label) = 1;
14958     }
14959   if (max_size > 2)
14960     {
14961       rtx label = ix86_expand_aligntest (count, 2, true);
14962       dest = change_address (destmem, HImode, destptr);
14963       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
14964       emit_label (label);
14965       LABEL_NUSES (label) = 1;
14966     }
14967   if (max_size > 1)
14968     {
14969       rtx label = ix86_expand_aligntest (count, 1, true);
14970       dest = change_address (destmem, QImode, destptr);
14971       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
14972       emit_label (label);
14973       LABEL_NUSES (label) = 1;
14974     }
14975 }
14976
14977 /* Copy enough from DEST to SRC to align DEST known to by aligned by ALIGN to
14978    DESIRED_ALIGNMENT.  */
14979 static void
14980 expand_movmem_prologue (rtx destmem, rtx srcmem,
14981                         rtx destptr, rtx srcptr, rtx count,
14982                         int align, int desired_alignment)
14983 {
14984   if (align <= 1 && desired_alignment > 1)
14985     {
14986       rtx label = ix86_expand_aligntest (destptr, 1, false);
14987       srcmem = change_address (srcmem, QImode, srcptr);
14988       destmem = change_address (destmem, QImode, destptr);
14989       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
14990       ix86_adjust_counter (count, 1);
14991       emit_label (label);
14992       LABEL_NUSES (label) = 1;
14993     }
14994   if (align <= 2 && desired_alignment > 2)
14995     {
14996       rtx label = ix86_expand_aligntest (destptr, 2, false);
14997       srcmem = change_address (srcmem, HImode, srcptr);
14998       destmem = change_address (destmem, HImode, destptr);
14999       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
15000       ix86_adjust_counter (count, 2);
15001       emit_label (label);
15002       LABEL_NUSES (label) = 1;
15003     }
15004   if (align <= 4 && desired_alignment > 4)
15005     {
15006       rtx label = ix86_expand_aligntest (destptr, 4, false);
15007       srcmem = change_address (srcmem, SImode, srcptr);
15008       destmem = change_address (destmem, SImode, destptr);
15009       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
15010       ix86_adjust_counter (count, 4);
15011       emit_label (label);
15012       LABEL_NUSES (label) = 1;
15013     }
15014   gcc_assert (desired_alignment <= 8);
15015 }
15016
15017 /* Set enough from DEST to align DEST known to by aligned by ALIGN to
15018    DESIRED_ALIGNMENT.  */
15019 static void
15020 expand_setmem_prologue (rtx destmem, rtx destptr, rtx value, rtx count,
15021                         int align, int desired_alignment)
15022 {
15023   if (align <= 1 && desired_alignment > 1)
15024     {
15025       rtx label = ix86_expand_aligntest (destptr, 1, false);
15026       destmem = change_address (destmem, QImode, destptr);
15027       emit_insn (gen_strset (destptr, destmem, gen_lowpart (QImode, value)));
15028       ix86_adjust_counter (count, 1);
15029       emit_label (label);
15030       LABEL_NUSES (label) = 1;
15031     }
15032   if (align <= 2 && desired_alignment > 2)
15033     {
15034       rtx label = ix86_expand_aligntest (destptr, 2, false);
15035       destmem = change_address (destmem, HImode, destptr);
15036       emit_insn (gen_strset (destptr, destmem, gen_lowpart (HImode, value)));
15037       ix86_adjust_counter (count, 2);
15038       emit_label (label);
15039       LABEL_NUSES (label) = 1;
15040     }
15041   if (align <= 4 && desired_alignment > 4)
15042     {
15043       rtx label = ix86_expand_aligntest (destptr, 4, false);
15044       destmem = change_address (destmem, SImode, destptr);
15045       emit_insn (gen_strset (destptr, destmem, gen_lowpart (SImode, value)));
15046       ix86_adjust_counter (count, 4);
15047       emit_label (label);
15048       LABEL_NUSES (label) = 1;
15049     }
15050   gcc_assert (desired_alignment <= 8);
15051 }
15052
15053 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
15054 static enum stringop_alg
15055 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, bool memset,
15056             int *dynamic_check)
15057 {
15058   const struct stringop_algs * algs;
15059
15060   *dynamic_check = -1;
15061   if (memset)
15062     algs = &ix86_cost->memset[TARGET_64BIT != 0];
15063   else
15064     algs = &ix86_cost->memcpy[TARGET_64BIT != 0];
15065   if (stringop_alg != no_stringop)
15066     return stringop_alg;
15067   /* rep; movq or rep; movl is the smallest variant.  */
15068   else if (optimize_size)
15069     {
15070       if (!count || (count & 3))
15071         return rep_prefix_1_byte;
15072       else
15073         return rep_prefix_4_byte;
15074     }
15075   /* Very tiny blocks are best handled via the loop, REP is expensive to setup.
15076    */
15077   else if (expected_size != -1 && expected_size < 4)
15078     return loop_1_byte;
15079   else if (expected_size != -1)
15080     {
15081       unsigned int i;
15082       enum stringop_alg alg = libcall;
15083       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
15084         {
15085           gcc_assert (algs->size[i].max);
15086           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
15087             {
15088               if (algs->size[i].alg != libcall)
15089                 alg = algs->size[i].alg;
15090               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
15091                  last non-libcall inline algorithm.  */
15092               if (TARGET_INLINE_ALL_STRINGOPS)
15093                 {
15094                   /* When the current size is best to be copied by a libcall,
15095                      but we are still forced to inline, run the heuristic bellow
15096                      that will pick code for medium sized blocks.  */
15097                   if (alg != libcall)
15098                     return alg;
15099                   break;
15100                 }
15101               else
15102                 return algs->size[i].alg;
15103             }
15104         }
15105       gcc_assert (TARGET_INLINE_ALL_STRINGOPS);
15106     }
15107   /* When asked to inline the call anyway, try to pick meaningful choice.
15108      We look for maximal size of block that is faster to copy by hand and
15109      take blocks of at most of that size guessing that average size will
15110      be roughly half of the block.
15111
15112      If this turns out to be bad, we might simply specify the preferred
15113      choice in ix86_costs.  */
15114   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
15115       && algs->unknown_size == libcall)
15116     {
15117       int max = -1;
15118       enum stringop_alg alg;
15119       int i;
15120
15121       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
15122         if (algs->size[i].alg != libcall && algs->size[i].alg)
15123           max = algs->size[i].max;
15124       if (max == -1)
15125         max = 4096;
15126       alg = decide_alg (count, max / 2, memset, dynamic_check);
15127       gcc_assert (*dynamic_check == -1);
15128       gcc_assert (alg != libcall);
15129       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
15130         *dynamic_check = max;
15131       return alg;
15132     }
15133   return algs->unknown_size;
15134 }
15135
15136 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
15137    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
15138 static int
15139 decide_alignment (int align,
15140                   enum stringop_alg alg,
15141                   int expected_size)
15142 {
15143   int desired_align = 0;
15144   switch (alg)
15145     {
15146       case no_stringop:
15147         gcc_unreachable ();
15148       case loop:
15149       case unrolled_loop:
15150         desired_align = GET_MODE_SIZE (Pmode);
15151         break;
15152       case rep_prefix_8_byte:
15153         desired_align = 8;
15154         break;
15155       case rep_prefix_4_byte:
15156         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
15157            copying whole cacheline at once.  */
15158         if (TARGET_PENTIUMPRO)
15159           desired_align = 8;
15160         else
15161           desired_align = 4;
15162         break;
15163       case rep_prefix_1_byte:
15164         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
15165            copying whole cacheline at once.  */
15166         if (TARGET_PENTIUMPRO)
15167           desired_align = 8;
15168         else
15169           desired_align = 1;
15170         break;
15171       case loop_1_byte:
15172         desired_align = 1;
15173         break;
15174       case libcall:
15175         return 0;
15176     }
15177
15178   if (optimize_size)
15179     desired_align = 1;
15180   if (desired_align < align)
15181     desired_align = align;
15182   if (expected_size != -1 && expected_size < 4)
15183     desired_align = align;
15184   return desired_align;
15185 }
15186
15187 /* Return the smallest power of 2 greater than VAL.  */
15188 static int
15189 smallest_pow2_greater_than (int val)
15190 {
15191   int ret = 1;
15192   while (ret <= val)
15193     ret <<= 1;
15194   return ret;
15195 }
15196
15197 /* Expand string move (memcpy) operation.  Use i386 string operations when
15198    profitable.  expand_clrmem contains similar code. The code depends upon
15199    architecture, block size and alignment, but always has the same
15200    overall structure:
15201
15202    1) Prologue guard: Conditional that jumps up to epilogues for small
15203       blocks that can be handled by epilogue alone.  This is faster but
15204       also needed for correctness, since prologue assume the block is larger
15205       than the desired alignment.
15206
15207       Optional dynamic check for size and libcall for large
15208       blocks is emitted here too, with -minline-stringops-dynamically.
15209
15210    2) Prologue: copy first few bytes in order to get destination aligned
15211       to DESIRED_ALIGN.  It is emitted only when ALIGN is less than
15212       DESIRED_ALIGN and and up to DESIRED_ALIGN - ALIGN bytes can be copied.
15213       We emit either a jump tree on power of two sized blocks, or a byte loop.
15214
15215    3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
15216       with specified algorithm.
15217
15218    4) Epilogue: code copying tail of the block that is too small to be
15219       handled by main body (or up to size guarded by prologue guard).  */
15220
15221 int
15222 ix86_expand_movmem (rtx dst, rtx src, rtx count_exp, rtx align_exp,
15223                     rtx expected_align_exp, rtx expected_size_exp)
15224 {
15225   rtx destreg;
15226   rtx srcreg;
15227   rtx label = NULL;
15228   rtx tmp;
15229   rtx jump_around_label = NULL;
15230   HOST_WIDE_INT align = 1;
15231   unsigned HOST_WIDE_INT count = 0;
15232   HOST_WIDE_INT expected_size = -1;
15233   int size_needed = 0, epilogue_size_needed;
15234   int desired_align = 0;
15235   enum stringop_alg alg;
15236   int dynamic_check;
15237
15238   if (CONST_INT_P (align_exp))
15239     align = INTVAL (align_exp);
15240   /* i386 can do misaligned access on reasonably increased cost.  */
15241   if (CONST_INT_P (expected_align_exp)
15242       && INTVAL (expected_align_exp) > align)
15243     align = INTVAL (expected_align_exp);
15244   if (CONST_INT_P (count_exp))
15245     count = expected_size = INTVAL (count_exp);
15246   if (CONST_INT_P (expected_size_exp) && count == 0)
15247     expected_size = INTVAL (expected_size_exp);
15248
15249   /* Step 0: Decide on preferred algorithm, desired alignment and
15250      size of chunks to be copied by main loop.  */
15251
15252   alg = decide_alg (count, expected_size, false, &dynamic_check);
15253   desired_align = decide_alignment (align, alg, expected_size);
15254
15255   if (!TARGET_ALIGN_STRINGOPS)
15256     align = desired_align;
15257
15258   if (alg == libcall)
15259     return 0;
15260   gcc_assert (alg != no_stringop);
15261   if (!count)
15262     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
15263   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
15264   srcreg = copy_to_mode_reg (Pmode, XEXP (src, 0));
15265   switch (alg)
15266     {
15267     case libcall:
15268     case no_stringop:
15269       gcc_unreachable ();
15270     case loop:
15271       size_needed = GET_MODE_SIZE (Pmode);
15272       break;
15273     case unrolled_loop:
15274       size_needed = GET_MODE_SIZE (Pmode) * (TARGET_64BIT ? 4 : 2);
15275       break;
15276     case rep_prefix_8_byte:
15277       size_needed = 8;
15278       break;
15279     case rep_prefix_4_byte:
15280       size_needed = 4;
15281       break;
15282     case rep_prefix_1_byte:
15283     case loop_1_byte:
15284       size_needed = 1;
15285       break;
15286     }
15287
15288   epilogue_size_needed = size_needed;
15289
15290   /* Step 1: Prologue guard.  */
15291
15292   /* Alignment code needs count to be in register.  */
15293   if (CONST_INT_P (count_exp) && desired_align > align)
15294     {
15295       enum machine_mode mode = SImode;
15296       if (TARGET_64BIT && (count & ~0xffffffff))
15297         mode = DImode;
15298       count_exp = force_reg (mode, count_exp);
15299     }
15300   gcc_assert (desired_align >= 1 && align >= 1);
15301
15302   /* Ensure that alignment prologue won't copy past end of block.  */
15303   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
15304     {
15305       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
15306       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
15307          Make sure it is power of 2.  */
15308       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
15309
15310       label = gen_label_rtx ();
15311       emit_cmp_and_jump_insns (count_exp,
15312                                GEN_INT (epilogue_size_needed),
15313                                LTU, 0, counter_mode (count_exp), 1, label);
15314       if (GET_CODE (count_exp) == CONST_INT)
15315         ;
15316       else if (expected_size == -1 || expected_size < epilogue_size_needed)
15317         predict_jump (REG_BR_PROB_BASE * 60 / 100);
15318       else
15319         predict_jump (REG_BR_PROB_BASE * 20 / 100);
15320     }
15321   /* Emit code to decide on runtime whether library call or inline should be
15322      used.  */
15323   if (dynamic_check != -1)
15324     {
15325       rtx hot_label = gen_label_rtx ();
15326       jump_around_label = gen_label_rtx ();
15327       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
15328                                LEU, 0, GET_MODE (count_exp), 1, hot_label);
15329       predict_jump (REG_BR_PROB_BASE * 90 / 100);
15330       emit_block_move_via_libcall (dst, src, count_exp, false);
15331       emit_jump (jump_around_label);
15332       emit_label (hot_label);
15333     }
15334
15335   /* Step 2: Alignment prologue.  */
15336
15337   if (desired_align > align)
15338     {
15339       /* Except for the first move in epilogue, we no longer know
15340          constant offset in aliasing info.  It don't seems to worth
15341          the pain to maintain it for the first move, so throw away
15342          the info early.  */
15343       src = change_address (src, BLKmode, srcreg);
15344       dst = change_address (dst, BLKmode, destreg);
15345       expand_movmem_prologue (dst, src, destreg, srcreg, count_exp, align,
15346                               desired_align);
15347     }
15348   if (label && size_needed == 1)
15349     {
15350       emit_label (label);
15351       LABEL_NUSES (label) = 1;
15352       label = NULL;
15353     }
15354
15355   /* Step 3: Main loop.  */
15356
15357   switch (alg)
15358     {
15359     case libcall:
15360     case no_stringop:
15361       gcc_unreachable ();
15362     case loop_1_byte:
15363       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
15364                                      count_exp, QImode, 1, expected_size);
15365       break;
15366     case loop:
15367       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
15368                                      count_exp, Pmode, 1, expected_size);
15369       break;
15370     case unrolled_loop:
15371       /* Unroll only by factor of 2 in 32bit mode, since we don't have enough
15372          registers for 4 temporaries anyway.  */
15373       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
15374                                      count_exp, Pmode, TARGET_64BIT ? 4 : 2,
15375                                      expected_size);
15376       break;
15377     case rep_prefix_8_byte:
15378       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
15379                                  DImode);
15380       break;
15381     case rep_prefix_4_byte:
15382       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
15383                                  SImode);
15384       break;
15385     case rep_prefix_1_byte:
15386       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
15387                                  QImode);
15388       break;
15389     }
15390   /* Adjust properly the offset of src and dest memory for aliasing.  */
15391   if (CONST_INT_P (count_exp))
15392     {
15393       src = adjust_automodify_address_nv (src, BLKmode, srcreg,
15394                                           (count / size_needed) * size_needed);
15395       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
15396                                           (count / size_needed) * size_needed);
15397     }
15398   else
15399     {
15400       src = change_address (src, BLKmode, srcreg);
15401       dst = change_address (dst, BLKmode, destreg);
15402     }
15403
15404   /* Step 4: Epilogue to copy the remaining bytes.  */
15405
15406   if (label)
15407     {
15408       /* When the main loop is done, COUNT_EXP might hold original count,
15409          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
15410          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
15411          bytes. Compensate if needed.  */
15412
15413       if (size_needed < epilogue_size_needed)
15414         {
15415           tmp =
15416             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
15417                                  GEN_INT (size_needed - 1), count_exp, 1,
15418                                  OPTAB_DIRECT);
15419           if (tmp != count_exp)
15420             emit_move_insn (count_exp, tmp);
15421         }
15422       emit_label (label);
15423       LABEL_NUSES (label) = 1;
15424     }
15425
15426   if (count_exp != const0_rtx && epilogue_size_needed > 1)
15427     expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
15428                             epilogue_size_needed);
15429   if (jump_around_label)
15430     emit_label (jump_around_label);
15431   return 1;
15432 }
15433
15434 /* Helper function for memcpy.  For QImode value 0xXY produce
15435    0xXYXYXYXY of wide specified by MODE.  This is essentially
15436    a * 0x10101010, but we can do slightly better than
15437    synth_mult by unwinding the sequence by hand on CPUs with
15438    slow multiply.  */
15439 static rtx
15440 promote_duplicated_reg (enum machine_mode mode, rtx val)
15441 {
15442   enum machine_mode valmode = GET_MODE (val);
15443   rtx tmp;
15444   int nops = mode == DImode ? 3 : 2;
15445
15446   gcc_assert (mode == SImode || mode == DImode);
15447   if (val == const0_rtx)
15448     return copy_to_mode_reg (mode, const0_rtx);
15449   if (CONST_INT_P (val))
15450     {
15451       HOST_WIDE_INT v = INTVAL (val) & 255;
15452
15453       v |= v << 8;
15454       v |= v << 16;
15455       if (mode == DImode)
15456         v |= (v << 16) << 16;
15457       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
15458     }
15459
15460   if (valmode == VOIDmode)
15461     valmode = QImode;
15462   if (valmode != QImode)
15463     val = gen_lowpart (QImode, val);
15464   if (mode == QImode)
15465     return val;
15466   if (!TARGET_PARTIAL_REG_STALL)
15467     nops--;
15468   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
15469       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
15470       <= (ix86_cost->shift_const + ix86_cost->add) * nops
15471           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
15472     {
15473       rtx reg = convert_modes (mode, QImode, val, true);
15474       tmp = promote_duplicated_reg (mode, const1_rtx);
15475       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
15476                                   OPTAB_DIRECT);
15477     }
15478   else
15479     {
15480       rtx reg = convert_modes (mode, QImode, val, true);
15481
15482       if (!TARGET_PARTIAL_REG_STALL)
15483         if (mode == SImode)
15484           emit_insn (gen_movsi_insv_1 (reg, reg));
15485         else
15486           emit_insn (gen_movdi_insv_1_rex64 (reg, reg));
15487       else
15488         {
15489           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
15490                                      NULL, 1, OPTAB_DIRECT);
15491           reg =
15492             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
15493         }
15494       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
15495                                  NULL, 1, OPTAB_DIRECT);
15496       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
15497       if (mode == SImode)
15498         return reg;
15499       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
15500                                  NULL, 1, OPTAB_DIRECT);
15501       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
15502       return reg;
15503     }
15504 }
15505
15506 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
15507    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
15508    alignment from ALIGN to DESIRED_ALIGN.  */
15509 static rtx
15510 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align, int align)
15511 {
15512   rtx promoted_val;
15513
15514   if (TARGET_64BIT
15515       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
15516     promoted_val = promote_duplicated_reg (DImode, val);
15517   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
15518     promoted_val = promote_duplicated_reg (SImode, val);
15519   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
15520     promoted_val = promote_duplicated_reg (HImode, val);
15521   else
15522     promoted_val = val;
15523
15524   return promoted_val;
15525 }
15526
15527 /* Expand string clear operation (bzero).  Use i386 string operations when
15528    profitable.  See expand_movmem comment for explanation of individual
15529    steps performed.  */
15530 int
15531 ix86_expand_setmem (rtx dst, rtx count_exp, rtx val_exp, rtx align_exp,
15532                     rtx expected_align_exp, rtx expected_size_exp)
15533 {
15534   rtx destreg;
15535   rtx label = NULL;
15536   rtx tmp;
15537   rtx jump_around_label = NULL;
15538   HOST_WIDE_INT align = 1;
15539   unsigned HOST_WIDE_INT count = 0;
15540   HOST_WIDE_INT expected_size = -1;
15541   int size_needed = 0, epilogue_size_needed;
15542   int desired_align = 0;
15543   enum stringop_alg alg;
15544   rtx promoted_val = NULL;
15545   bool force_loopy_epilogue = false;
15546   int dynamic_check;
15547
15548   if (CONST_INT_P (align_exp))
15549     align = INTVAL (align_exp);
15550   /* i386 can do misaligned access on reasonably increased cost.  */
15551   if (CONST_INT_P (expected_align_exp)
15552       && INTVAL (expected_align_exp) > align)
15553     align = INTVAL (expected_align_exp);
15554   if (CONST_INT_P (count_exp))
15555     count = expected_size = INTVAL (count_exp);
15556   if (CONST_INT_P (expected_size_exp) && count == 0)
15557     expected_size = INTVAL (expected_size_exp);
15558
15559   /* Step 0: Decide on preferred algorithm, desired alignment and
15560      size of chunks to be copied by main loop.  */
15561
15562   alg = decide_alg (count, expected_size, true, &dynamic_check);
15563   desired_align = decide_alignment (align, alg, expected_size);
15564
15565   if (!TARGET_ALIGN_STRINGOPS)
15566     align = desired_align;
15567
15568   if (alg == libcall)
15569     return 0;
15570   gcc_assert (alg != no_stringop);
15571   if (!count)
15572     count_exp = copy_to_mode_reg (counter_mode (count_exp), count_exp);
15573   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
15574   switch (alg)
15575     {
15576     case libcall:
15577     case no_stringop:
15578       gcc_unreachable ();
15579     case loop:
15580       size_needed = GET_MODE_SIZE (Pmode);
15581       break;
15582     case unrolled_loop:
15583       size_needed = GET_MODE_SIZE (Pmode) * 4;
15584       break;
15585     case rep_prefix_8_byte:
15586       size_needed = 8;
15587       break;
15588     case rep_prefix_4_byte:
15589       size_needed = 4;
15590       break;
15591     case rep_prefix_1_byte:
15592     case loop_1_byte:
15593       size_needed = 1;
15594       break;
15595     }
15596   epilogue_size_needed = size_needed;
15597
15598   /* Step 1: Prologue guard.  */
15599
15600   /* Alignment code needs count to be in register.  */
15601   if (CONST_INT_P (count_exp) && desired_align > align)
15602     {
15603       enum machine_mode mode = SImode;
15604       if (TARGET_64BIT && (count & ~0xffffffff))
15605         mode = DImode;
15606       count_exp = force_reg (mode, count_exp);
15607     }
15608   /* Do the cheap promotion to allow better CSE across the
15609      main loop and epilogue (ie one load of the big constant in the
15610      front of all code.  */
15611   if (CONST_INT_P (val_exp))
15612     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
15613                                                    desired_align, align);
15614   /* Ensure that alignment prologue won't copy past end of block.  */
15615   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
15616     {
15617       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
15618       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
15619          Make sure it is power of 2.  */
15620       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
15621
15622       /* To improve performance of small blocks, we jump around the VAL
15623          promoting mode.  This mean that if the promoted VAL is not constant,
15624          we might not use it in the epilogue and have to use byte
15625          loop variant.  */
15626       if (epilogue_size_needed > 2 && !promoted_val)
15627         force_loopy_epilogue = true;
15628       label = gen_label_rtx ();
15629       emit_cmp_and_jump_insns (count_exp,
15630                                GEN_INT (epilogue_size_needed),
15631                                LTU, 0, counter_mode (count_exp), 1, label);
15632       if (GET_CODE (count_exp) == CONST_INT)
15633         ;
15634       else if (expected_size == -1 || expected_size <= epilogue_size_needed)
15635         predict_jump (REG_BR_PROB_BASE * 60 / 100);
15636       else
15637         predict_jump (REG_BR_PROB_BASE * 20 / 100);
15638     }
15639   if (dynamic_check != -1)
15640     {
15641       rtx hot_label = gen_label_rtx ();
15642       jump_around_label = gen_label_rtx ();
15643       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
15644                                LEU, 0, counter_mode (count_exp), 1, hot_label);
15645       predict_jump (REG_BR_PROB_BASE * 90 / 100);
15646       set_storage_via_libcall (dst, count_exp, val_exp, false);
15647       emit_jump (jump_around_label);
15648       emit_label (hot_label);
15649     }
15650
15651   /* Step 2: Alignment prologue.  */
15652
15653   /* Do the expensive promotion once we branched off the small blocks.  */
15654   if (!promoted_val)
15655     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
15656                                                    desired_align, align);
15657   gcc_assert (desired_align >= 1 && align >= 1);
15658
15659   if (desired_align > align)
15660     {
15661       /* Except for the first move in epilogue, we no longer know
15662          constant offset in aliasing info.  It don't seems to worth
15663          the pain to maintain it for the first move, so throw away
15664          the info early.  */
15665       dst = change_address (dst, BLKmode, destreg);
15666       expand_setmem_prologue (dst, destreg, promoted_val, count_exp, align,
15667                               desired_align);
15668     }
15669   if (label && size_needed == 1)
15670     {
15671       emit_label (label);
15672       LABEL_NUSES (label) = 1;
15673       label = NULL;
15674     }
15675
15676   /* Step 3: Main loop.  */
15677
15678   switch (alg)
15679     {
15680     case libcall:
15681     case no_stringop:
15682       gcc_unreachable ();
15683     case loop_1_byte:
15684       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
15685                                      count_exp, QImode, 1, expected_size);
15686       break;
15687     case loop:
15688       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
15689                                      count_exp, Pmode, 1, expected_size);
15690       break;
15691     case unrolled_loop:
15692       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
15693                                      count_exp, Pmode, 4, expected_size);
15694       break;
15695     case rep_prefix_8_byte:
15696       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
15697                                   DImode);
15698       break;
15699     case rep_prefix_4_byte:
15700       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
15701                                   SImode);
15702       break;
15703     case rep_prefix_1_byte:
15704       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
15705                                   QImode);
15706       break;
15707     }
15708   /* Adjust properly the offset of src and dest memory for aliasing.  */
15709   if (CONST_INT_P (count_exp))
15710     dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
15711                                         (count / size_needed) * size_needed);
15712   else
15713     dst = change_address (dst, BLKmode, destreg);
15714
15715   /* Step 4: Epilogue to copy the remaining bytes.  */
15716
15717   if (label)
15718     {
15719       /* When the main loop is done, COUNT_EXP might hold original count,
15720          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
15721          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
15722          bytes. Compensate if needed.  */
15723
15724       if (size_needed < desired_align - align)
15725         {
15726           tmp =
15727             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
15728                                  GEN_INT (size_needed - 1), count_exp, 1,
15729                                  OPTAB_DIRECT);
15730           size_needed = desired_align - align + 1;
15731           if (tmp != count_exp)
15732             emit_move_insn (count_exp, tmp);
15733         }
15734       emit_label (label);
15735       LABEL_NUSES (label) = 1;
15736     }
15737   if (count_exp != const0_rtx && epilogue_size_needed > 1)
15738     {
15739       if (force_loopy_epilogue)
15740         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
15741                                          size_needed);
15742       else
15743         expand_setmem_epilogue (dst, destreg, promoted_val, count_exp,
15744                                 size_needed);
15745     }
15746   if (jump_around_label)
15747     emit_label (jump_around_label);
15748   return 1;
15749 }
15750
15751 /* Expand the appropriate insns for doing strlen if not just doing
15752    repnz; scasb
15753
15754    out = result, initialized with the start address
15755    align_rtx = alignment of the address.
15756    scratch = scratch register, initialized with the startaddress when
15757         not aligned, otherwise undefined
15758
15759    This is just the body. It needs the initializations mentioned above and
15760    some address computing at the end.  These things are done in i386.md.  */
15761
15762 static void
15763 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
15764 {
15765   int align;
15766   rtx tmp;
15767   rtx align_2_label = NULL_RTX;
15768   rtx align_3_label = NULL_RTX;
15769   rtx align_4_label = gen_label_rtx ();
15770   rtx end_0_label = gen_label_rtx ();
15771   rtx mem;
15772   rtx tmpreg = gen_reg_rtx (SImode);
15773   rtx scratch = gen_reg_rtx (SImode);
15774   rtx cmp;
15775
15776   align = 0;
15777   if (CONST_INT_P (align_rtx))
15778     align = INTVAL (align_rtx);
15779
15780   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
15781
15782   /* Is there a known alignment and is it less than 4?  */
15783   if (align < 4)
15784     {
15785       rtx scratch1 = gen_reg_rtx (Pmode);
15786       emit_move_insn (scratch1, out);
15787       /* Is there a known alignment and is it not 2? */
15788       if (align != 2)
15789         {
15790           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
15791           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
15792
15793           /* Leave just the 3 lower bits.  */
15794           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
15795                                     NULL_RTX, 0, OPTAB_WIDEN);
15796
15797           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
15798                                    Pmode, 1, align_4_label);
15799           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
15800                                    Pmode, 1, align_2_label);
15801           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
15802                                    Pmode, 1, align_3_label);
15803         }
15804       else
15805         {
15806           /* Since the alignment is 2, we have to check 2 or 0 bytes;
15807              check if is aligned to 4 - byte.  */
15808
15809           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
15810                                     NULL_RTX, 0, OPTAB_WIDEN);
15811
15812           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
15813                                    Pmode, 1, align_4_label);
15814         }
15815
15816       mem = change_address (src, QImode, out);
15817
15818       /* Now compare the bytes.  */
15819
15820       /* Compare the first n unaligned byte on a byte per byte basis.  */
15821       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
15822                                QImode, 1, end_0_label);
15823
15824       /* Increment the address.  */
15825       if (TARGET_64BIT)
15826         emit_insn (gen_adddi3 (out, out, const1_rtx));
15827       else
15828         emit_insn (gen_addsi3 (out, out, const1_rtx));
15829
15830       /* Not needed with an alignment of 2 */
15831       if (align != 2)
15832         {
15833           emit_label (align_2_label);
15834
15835           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
15836                                    end_0_label);
15837
15838           if (TARGET_64BIT)
15839             emit_insn (gen_adddi3 (out, out, const1_rtx));
15840           else
15841             emit_insn (gen_addsi3 (out, out, const1_rtx));
15842
15843           emit_label (align_3_label);
15844         }
15845
15846       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
15847                                end_0_label);
15848
15849       if (TARGET_64BIT)
15850         emit_insn (gen_adddi3 (out, out, const1_rtx));
15851       else
15852         emit_insn (gen_addsi3 (out, out, const1_rtx));
15853     }
15854
15855   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
15856      align this loop.  It gives only huge programs, but does not help to
15857      speed up.  */
15858   emit_label (align_4_label);
15859
15860   mem = change_address (src, SImode, out);
15861   emit_move_insn (scratch, mem);
15862   if (TARGET_64BIT)
15863     emit_insn (gen_adddi3 (out, out, GEN_INT (4)));
15864   else
15865     emit_insn (gen_addsi3 (out, out, GEN_INT (4)));
15866
15867   /* This formula yields a nonzero result iff one of the bytes is zero.
15868      This saves three branches inside loop and many cycles.  */
15869
15870   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
15871   emit_insn (gen_one_cmplsi2 (scratch, scratch));
15872   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
15873   emit_insn (gen_andsi3 (tmpreg, tmpreg,
15874                          gen_int_mode (0x80808080, SImode)));
15875   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
15876                            align_4_label);
15877
15878   if (TARGET_CMOVE)
15879     {
15880        rtx reg = gen_reg_rtx (SImode);
15881        rtx reg2 = gen_reg_rtx (Pmode);
15882        emit_move_insn (reg, tmpreg);
15883        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
15884
15885        /* If zero is not in the first two bytes, move two bytes forward.  */
15886        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
15887        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
15888        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
15889        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
15890                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
15891                                                      reg,
15892                                                      tmpreg)));
15893        /* Emit lea manually to avoid clobbering of flags.  */
15894        emit_insn (gen_rtx_SET (SImode, reg2,
15895                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
15896
15897        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
15898        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
15899        emit_insn (gen_rtx_SET (VOIDmode, out,
15900                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
15901                                                      reg2,
15902                                                      out)));
15903
15904     }
15905   else
15906     {
15907        rtx end_2_label = gen_label_rtx ();
15908        /* Is zero in the first two bytes? */
15909
15910        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
15911        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
15912        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
15913        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
15914                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
15915                             pc_rtx);
15916        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
15917        JUMP_LABEL (tmp) = end_2_label;
15918
15919        /* Not in the first two.  Move two bytes forward.  */
15920        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
15921        if (TARGET_64BIT)
15922          emit_insn (gen_adddi3 (out, out, const2_rtx));
15923        else
15924          emit_insn (gen_addsi3 (out, out, const2_rtx));
15925
15926        emit_label (end_2_label);
15927
15928     }
15929
15930   /* Avoid branch in fixing the byte.  */
15931   tmpreg = gen_lowpart (QImode, tmpreg);
15932   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
15933   cmp = gen_rtx_LTU (Pmode, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx);
15934   if (TARGET_64BIT)
15935     emit_insn (gen_subdi3_carry_rex64 (out, out, GEN_INT (3), cmp));
15936   else
15937     emit_insn (gen_subsi3_carry (out, out, GEN_INT (3), cmp));
15938
15939   emit_label (end_0_label);
15940 }
15941
15942 /* Expand strlen.  */
15943
15944 int
15945 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
15946 {
15947   rtx addr, scratch1, scratch2, scratch3, scratch4;
15948
15949   /* The generic case of strlen expander is long.  Avoid it's
15950      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
15951
15952   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
15953       && !TARGET_INLINE_ALL_STRINGOPS
15954       && !optimize_size
15955       && (!CONST_INT_P (align) || INTVAL (align) < 4))
15956     return 0;
15957
15958   addr = force_reg (Pmode, XEXP (src, 0));
15959   scratch1 = gen_reg_rtx (Pmode);
15960
15961   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
15962       && !optimize_size)
15963     {
15964       /* Well it seems that some optimizer does not combine a call like
15965          foo(strlen(bar), strlen(bar));
15966          when the move and the subtraction is done here.  It does calculate
15967          the length just once when these instructions are done inside of
15968          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
15969          often used and I use one fewer register for the lifetime of
15970          output_strlen_unroll() this is better.  */
15971
15972       emit_move_insn (out, addr);
15973
15974       ix86_expand_strlensi_unroll_1 (out, src, align);
15975
15976       /* strlensi_unroll_1 returns the address of the zero at the end of
15977          the string, like memchr(), so compute the length by subtracting
15978          the start address.  */
15979       if (TARGET_64BIT)
15980         emit_insn (gen_subdi3 (out, out, addr));
15981       else
15982         emit_insn (gen_subsi3 (out, out, addr));
15983     }
15984   else
15985     {
15986       rtx unspec;
15987       scratch2 = gen_reg_rtx (Pmode);
15988       scratch3 = gen_reg_rtx (Pmode);
15989       scratch4 = force_reg (Pmode, constm1_rtx);
15990
15991       emit_move_insn (scratch3, addr);
15992       eoschar = force_reg (QImode, eoschar);
15993
15994       src = replace_equiv_address_nv (src, scratch3);
15995
15996       /* If .md starts supporting :P, this can be done in .md.  */
15997       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
15998                                                  scratch4), UNSPEC_SCAS);
15999       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
16000       if (TARGET_64BIT)
16001         {
16002           emit_insn (gen_one_cmpldi2 (scratch2, scratch1));
16003           emit_insn (gen_adddi3 (out, scratch2, constm1_rtx));
16004         }
16005       else
16006         {
16007           emit_insn (gen_one_cmplsi2 (scratch2, scratch1));
16008           emit_insn (gen_addsi3 (out, scratch2, constm1_rtx));
16009         }
16010     }
16011   return 1;
16012 }
16013
16014 /* For given symbol (function) construct code to compute address of it's PLT
16015    entry in large x86-64 PIC model.  */
16016 rtx
16017 construct_plt_address (rtx symbol)
16018 {
16019   rtx tmp = gen_reg_rtx (Pmode);
16020   rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
16021
16022   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
16023   gcc_assert (ix86_cmodel == CM_LARGE_PIC);
16024
16025   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
16026   emit_insn (gen_adddi3 (tmp, tmp, pic_offset_table_rtx));
16027   return tmp;
16028 }
16029
16030 void
16031 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
16032                   rtx callarg2 ATTRIBUTE_UNUSED,
16033                   rtx pop, int sibcall)
16034 {
16035   rtx use = NULL, call;
16036
16037   if (pop == const0_rtx)
16038     pop = NULL;
16039   gcc_assert (!TARGET_64BIT || !pop);
16040
16041   if (TARGET_MACHO && !TARGET_64BIT)
16042     {
16043 #if TARGET_MACHO
16044       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
16045         fnaddr = machopic_indirect_call_target (fnaddr);
16046 #endif
16047     }
16048   else
16049     {
16050       /* Static functions and indirect calls don't need the pic register.  */
16051       if (flag_pic && (!TARGET_64BIT || ix86_cmodel == CM_LARGE_PIC)
16052           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
16053           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
16054         use_reg (&use, pic_offset_table_rtx);
16055     }
16056
16057   if (TARGET_64BIT && INTVAL (callarg2) >= 0)
16058     {
16059       rtx al = gen_rtx_REG (QImode, AX_REG);
16060       emit_move_insn (al, callarg2);
16061       use_reg (&use, al);
16062     }
16063
16064   if (ix86_cmodel == CM_LARGE_PIC
16065       && GET_CODE (fnaddr) == MEM
16066       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
16067       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
16068     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
16069   else if (! call_insn_operand (XEXP (fnaddr, 0), Pmode))
16070     {
16071       fnaddr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
16072       fnaddr = gen_rtx_MEM (QImode, fnaddr);
16073     }
16074   if (sibcall && TARGET_64BIT
16075       && !constant_call_address_operand (XEXP (fnaddr, 0), Pmode))
16076     {
16077       rtx addr;
16078       addr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
16079       fnaddr = gen_rtx_REG (Pmode, R11_REG);
16080       emit_move_insn (fnaddr, addr);
16081       fnaddr = gen_rtx_MEM (QImode, fnaddr);
16082     }
16083
16084   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
16085   if (retval)
16086     call = gen_rtx_SET (VOIDmode, retval, call);
16087   if (pop)
16088     {
16089       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
16090       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
16091       call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop));
16092     }
16093
16094   call = emit_call_insn (call);
16095   if (use)
16096     CALL_INSN_FUNCTION_USAGE (call) = use;
16097 }
16098
16099 \f
16100 /* Clear stack slot assignments remembered from previous functions.
16101    This is called from INIT_EXPANDERS once before RTL is emitted for each
16102    function.  */
16103
16104 static struct machine_function *
16105 ix86_init_machine_status (void)
16106 {
16107   struct machine_function *f;
16108
16109   f = GGC_CNEW (struct machine_function);
16110   f->use_fast_prologue_epilogue_nregs = -1;
16111   f->tls_descriptor_call_expanded_p = 0;
16112
16113   return f;
16114 }
16115
16116 /* Return a MEM corresponding to a stack slot with mode MODE.
16117    Allocate a new slot if necessary.
16118
16119    The RTL for a function can have several slots available: N is
16120    which slot to use.  */
16121
16122 rtx
16123 assign_386_stack_local (enum machine_mode mode, enum ix86_stack_slot n)
16124 {
16125   struct stack_local_entry *s;
16126
16127   gcc_assert (n < MAX_386_STACK_LOCALS);
16128
16129   /* Virtual slot is valid only before vregs are instantiated.  */
16130   gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
16131
16132   for (s = ix86_stack_locals; s; s = s->next)
16133     if (s->mode == mode && s->n == n)
16134       return copy_rtx (s->rtl);
16135
16136   s = (struct stack_local_entry *)
16137     ggc_alloc (sizeof (struct stack_local_entry));
16138   s->n = n;
16139   s->mode = mode;
16140   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
16141
16142   s->next = ix86_stack_locals;
16143   ix86_stack_locals = s;
16144   return s->rtl;
16145 }
16146
16147 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
16148
16149 static GTY(()) rtx ix86_tls_symbol;
16150 rtx
16151 ix86_tls_get_addr (void)
16152 {
16153
16154   if (!ix86_tls_symbol)
16155     {
16156       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode,
16157                                             (TARGET_ANY_GNU_TLS
16158                                              && !TARGET_64BIT)
16159                                             ? "___tls_get_addr"
16160                                             : "__tls_get_addr");
16161     }
16162
16163   return ix86_tls_symbol;
16164 }
16165
16166 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
16167
16168 static GTY(()) rtx ix86_tls_module_base_symbol;
16169 rtx
16170 ix86_tls_module_base (void)
16171 {
16172
16173   if (!ix86_tls_module_base_symbol)
16174     {
16175       ix86_tls_module_base_symbol = gen_rtx_SYMBOL_REF (Pmode,
16176                                                         "_TLS_MODULE_BASE_");
16177       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
16178         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
16179     }
16180
16181   return ix86_tls_module_base_symbol;
16182 }
16183 \f
16184 /* Calculate the length of the memory address in the instruction
16185    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
16186
16187 int
16188 memory_address_length (rtx addr)
16189 {
16190   struct ix86_address parts;
16191   rtx base, index, disp;
16192   int len;
16193   int ok;
16194
16195   if (GET_CODE (addr) == PRE_DEC
16196       || GET_CODE (addr) == POST_INC
16197       || GET_CODE (addr) == PRE_MODIFY
16198       || GET_CODE (addr) == POST_MODIFY)
16199     return 0;
16200
16201   ok = ix86_decompose_address (addr, &parts);
16202   gcc_assert (ok);
16203
16204   if (parts.base && GET_CODE (parts.base) == SUBREG)
16205     parts.base = SUBREG_REG (parts.base);
16206   if (parts.index && GET_CODE (parts.index) == SUBREG)
16207     parts.index = SUBREG_REG (parts.index);
16208
16209   base = parts.base;
16210   index = parts.index;
16211   disp = parts.disp;
16212   len = 0;
16213
16214   /* Rule of thumb:
16215        - esp as the base always wants an index,
16216        - ebp as the base always wants a displacement.  */
16217
16218   /* Register Indirect.  */
16219   if (base && !index && !disp)
16220     {
16221       /* esp (for its index) and ebp (for its displacement) need
16222          the two-byte modrm form.  */
16223       if (addr == stack_pointer_rtx
16224           || addr == arg_pointer_rtx
16225           || addr == frame_pointer_rtx
16226           || addr == hard_frame_pointer_rtx)
16227         len = 1;
16228     }
16229
16230   /* Direct Addressing.  */
16231   else if (disp && !base && !index)
16232     len = 4;
16233
16234   else
16235     {
16236       /* Find the length of the displacement constant.  */
16237       if (disp)
16238         {
16239           if (base && satisfies_constraint_K (disp))
16240             len = 1;
16241           else
16242             len = 4;
16243         }
16244       /* ebp always wants a displacement.  */
16245       else if (base == hard_frame_pointer_rtx)
16246         len = 1;
16247
16248       /* An index requires the two-byte modrm form....  */
16249       if (index
16250           /* ...like esp, which always wants an index.  */
16251           || base == stack_pointer_rtx
16252           || base == arg_pointer_rtx
16253           || base == frame_pointer_rtx)
16254         len += 1;
16255     }
16256
16257   return len;
16258 }
16259
16260 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
16261    is set, expect that insn have 8bit immediate alternative.  */
16262 int
16263 ix86_attr_length_immediate_default (rtx insn, int shortform)
16264 {
16265   int len = 0;
16266   int i;
16267   extract_insn_cached (insn);
16268   for (i = recog_data.n_operands - 1; i >= 0; --i)
16269     if (CONSTANT_P (recog_data.operand[i]))
16270       {
16271         gcc_assert (!len);
16272         if (shortform && satisfies_constraint_K (recog_data.operand[i]))
16273           len = 1;
16274         else
16275           {
16276             switch (get_attr_mode (insn))
16277               {
16278                 case MODE_QI:
16279                   len+=1;
16280                   break;
16281                 case MODE_HI:
16282                   len+=2;
16283                   break;
16284                 case MODE_SI:
16285                   len+=4;
16286                   break;
16287                 /* Immediates for DImode instructions are encoded as 32bit sign extended values.  */
16288                 case MODE_DI:
16289                   len+=4;
16290                   break;
16291                 default:
16292                   fatal_insn ("unknown insn mode", insn);
16293               }
16294           }
16295       }
16296   return len;
16297 }
16298 /* Compute default value for "length_address" attribute.  */
16299 int
16300 ix86_attr_length_address_default (rtx insn)
16301 {
16302   int i;
16303
16304   if (get_attr_type (insn) == TYPE_LEA)
16305     {
16306       rtx set = PATTERN (insn);
16307
16308       if (GET_CODE (set) == PARALLEL)
16309         set = XVECEXP (set, 0, 0);
16310
16311       gcc_assert (GET_CODE (set) == SET);
16312
16313       return memory_address_length (SET_SRC (set));
16314     }
16315
16316   extract_insn_cached (insn);
16317   for (i = recog_data.n_operands - 1; i >= 0; --i)
16318     if (MEM_P (recog_data.operand[i]))
16319       {
16320         return memory_address_length (XEXP (recog_data.operand[i], 0));
16321         break;
16322       }
16323   return 0;
16324 }
16325 \f
16326 /* Return the maximum number of instructions a cpu can issue.  */
16327
16328 static int
16329 ix86_issue_rate (void)
16330 {
16331   switch (ix86_tune)
16332     {
16333     case PROCESSOR_PENTIUM:
16334     case PROCESSOR_K6:
16335       return 2;
16336
16337     case PROCESSOR_PENTIUMPRO:
16338     case PROCESSOR_PENTIUM4:
16339     case PROCESSOR_ATHLON:
16340     case PROCESSOR_K8:
16341     case PROCESSOR_AMDFAM10:
16342     case PROCESSOR_NOCONA:
16343     case PROCESSOR_GENERIC32:
16344     case PROCESSOR_GENERIC64:
16345       return 3;
16346
16347     case PROCESSOR_CORE2:
16348       return 4;
16349
16350     default:
16351       return 1;
16352     }
16353 }
16354
16355 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
16356    by DEP_INSN and nothing set by DEP_INSN.  */
16357
16358 static int
16359 ix86_flags_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
16360 {
16361   rtx set, set2;
16362
16363   /* Simplify the test for uninteresting insns.  */
16364   if (insn_type != TYPE_SETCC
16365       && insn_type != TYPE_ICMOV
16366       && insn_type != TYPE_FCMOV
16367       && insn_type != TYPE_IBR)
16368     return 0;
16369
16370   if ((set = single_set (dep_insn)) != 0)
16371     {
16372       set = SET_DEST (set);
16373       set2 = NULL_RTX;
16374     }
16375   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
16376            && XVECLEN (PATTERN (dep_insn), 0) == 2
16377            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
16378            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
16379     {
16380       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
16381       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
16382     }
16383   else
16384     return 0;
16385
16386   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
16387     return 0;
16388
16389   /* This test is true if the dependent insn reads the flags but
16390      not any other potentially set register.  */
16391   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
16392     return 0;
16393
16394   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
16395     return 0;
16396
16397   return 1;
16398 }
16399
16400 /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory
16401    address with operands set by DEP_INSN.  */
16402
16403 static int
16404 ix86_agi_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
16405 {
16406   rtx addr;
16407
16408   if (insn_type == TYPE_LEA
16409       && TARGET_PENTIUM)
16410     {
16411       addr = PATTERN (insn);
16412
16413       if (GET_CODE (addr) == PARALLEL)
16414         addr = XVECEXP (addr, 0, 0);
16415
16416       gcc_assert (GET_CODE (addr) == SET);
16417
16418       addr = SET_SRC (addr);
16419     }
16420   else
16421     {
16422       int i;
16423       extract_insn_cached (insn);
16424       for (i = recog_data.n_operands - 1; i >= 0; --i)
16425         if (MEM_P (recog_data.operand[i]))
16426           {
16427             addr = XEXP (recog_data.operand[i], 0);
16428             goto found;
16429           }
16430       return 0;
16431     found:;
16432     }
16433
16434   return modified_in_p (addr, dep_insn);
16435 }
16436
16437 static int
16438 ix86_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
16439 {
16440   enum attr_type insn_type, dep_insn_type;
16441   enum attr_memory memory;
16442   rtx set, set2;
16443   int dep_insn_code_number;
16444
16445   /* Anti and output dependencies have zero cost on all CPUs.  */
16446   if (REG_NOTE_KIND (link) != 0)
16447     return 0;
16448
16449   dep_insn_code_number = recog_memoized (dep_insn);
16450
16451   /* If we can't recognize the insns, we can't really do anything.  */
16452   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
16453     return cost;
16454
16455   insn_type = get_attr_type (insn);
16456   dep_insn_type = get_attr_type (dep_insn);
16457
16458   switch (ix86_tune)
16459     {
16460     case PROCESSOR_PENTIUM:
16461       /* Address Generation Interlock adds a cycle of latency.  */
16462       if (ix86_agi_dependent (insn, dep_insn, insn_type))
16463         cost += 1;
16464
16465       /* ??? Compares pair with jump/setcc.  */
16466       if (ix86_flags_dependent (insn, dep_insn, insn_type))
16467         cost = 0;
16468
16469       /* Floating point stores require value to be ready one cycle earlier.  */
16470       if (insn_type == TYPE_FMOV
16471           && get_attr_memory (insn) == MEMORY_STORE
16472           && !ix86_agi_dependent (insn, dep_insn, insn_type))
16473         cost += 1;
16474       break;
16475
16476     case PROCESSOR_PENTIUMPRO:
16477       memory = get_attr_memory (insn);
16478
16479       /* INT->FP conversion is expensive.  */
16480       if (get_attr_fp_int_src (dep_insn))
16481         cost += 5;
16482
16483       /* There is one cycle extra latency between an FP op and a store.  */
16484       if (insn_type == TYPE_FMOV
16485           && (set = single_set (dep_insn)) != NULL_RTX
16486           && (set2 = single_set (insn)) != NULL_RTX
16487           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
16488           && MEM_P (SET_DEST (set2)))
16489         cost += 1;
16490
16491       /* Show ability of reorder buffer to hide latency of load by executing
16492          in parallel with previous instruction in case
16493          previous instruction is not needed to compute the address.  */
16494       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
16495           && !ix86_agi_dependent (insn, dep_insn, insn_type))
16496         {
16497           /* Claim moves to take one cycle, as core can issue one load
16498              at time and the next load can start cycle later.  */
16499           if (dep_insn_type == TYPE_IMOV
16500               || dep_insn_type == TYPE_FMOV)
16501             cost = 1;
16502           else if (cost > 1)
16503             cost--;
16504         }
16505       break;
16506
16507     case PROCESSOR_K6:
16508       memory = get_attr_memory (insn);
16509
16510       /* The esp dependency is resolved before the instruction is really
16511          finished.  */
16512       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
16513           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
16514         return 1;
16515
16516       /* INT->FP conversion is expensive.  */
16517       if (get_attr_fp_int_src (dep_insn))
16518         cost += 5;
16519
16520       /* Show ability of reorder buffer to hide latency of load by executing
16521          in parallel with previous instruction in case
16522          previous instruction is not needed to compute the address.  */
16523       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
16524           && !ix86_agi_dependent (insn, dep_insn, insn_type))
16525         {
16526           /* Claim moves to take one cycle, as core can issue one load
16527              at time and the next load can start cycle later.  */
16528           if (dep_insn_type == TYPE_IMOV
16529               || dep_insn_type == TYPE_FMOV)
16530             cost = 1;
16531           else if (cost > 2)
16532             cost -= 2;
16533           else
16534             cost = 1;
16535         }
16536       break;
16537
16538     case PROCESSOR_ATHLON:
16539     case PROCESSOR_K8:
16540     case PROCESSOR_AMDFAM10:
16541     case PROCESSOR_GENERIC32:
16542     case PROCESSOR_GENERIC64:
16543       memory = get_attr_memory (insn);
16544
16545       /* Show ability of reorder buffer to hide latency of load by executing
16546          in parallel with previous instruction in case
16547          previous instruction is not needed to compute the address.  */
16548       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
16549           && !ix86_agi_dependent (insn, dep_insn, insn_type))
16550         {
16551           enum attr_unit unit = get_attr_unit (insn);
16552           int loadcost = 3;
16553
16554           /* Because of the difference between the length of integer and
16555              floating unit pipeline preparation stages, the memory operands
16556              for floating point are cheaper.
16557
16558              ??? For Athlon it the difference is most probably 2.  */
16559           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
16560             loadcost = 3;
16561           else
16562             loadcost = TARGET_ATHLON ? 2 : 0;
16563
16564           if (cost >= loadcost)
16565             cost -= loadcost;
16566           else
16567             cost = 0;
16568         }
16569
16570     default:
16571       break;
16572     }
16573
16574   return cost;
16575 }
16576
16577 /* How many alternative schedules to try.  This should be as wide as the
16578    scheduling freedom in the DFA, but no wider.  Making this value too
16579    large results extra work for the scheduler.  */
16580
16581 static int
16582 ia32_multipass_dfa_lookahead (void)
16583 {
16584   if (ix86_tune == PROCESSOR_PENTIUM)
16585     return 2;
16586
16587   if (ix86_tune == PROCESSOR_PENTIUMPRO
16588       || ix86_tune == PROCESSOR_K6)
16589     return 1;
16590
16591   else
16592     return 0;
16593 }
16594
16595 \f
16596 /* Compute the alignment given to a constant that is being placed in memory.
16597    EXP is the constant and ALIGN is the alignment that the object would
16598    ordinarily have.
16599    The value of this function is used instead of that alignment to align
16600    the object.  */
16601
16602 int
16603 ix86_constant_alignment (tree exp, int align)
16604 {
16605   if (TREE_CODE (exp) == REAL_CST)
16606     {
16607       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
16608         return 64;
16609       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
16610         return 128;
16611     }
16612   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
16613            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
16614     return BITS_PER_WORD;
16615
16616   return align;
16617 }
16618
16619 /* Compute the alignment for a static variable.
16620    TYPE is the data type, and ALIGN is the alignment that
16621    the object would ordinarily have.  The value of this function is used
16622    instead of that alignment to align the object.  */
16623
16624 int
16625 ix86_data_alignment (tree type, int align)
16626 {
16627   int max_align = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
16628
16629   if (AGGREGATE_TYPE_P (type)
16630       && TYPE_SIZE (type)
16631       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
16632       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= (unsigned) max_align
16633           || TREE_INT_CST_HIGH (TYPE_SIZE (type)))
16634       && align < max_align)
16635     align = max_align;
16636
16637   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
16638      to 16byte boundary.  */
16639   if (TARGET_64BIT)
16640     {
16641       if (AGGREGATE_TYPE_P (type)
16642            && TYPE_SIZE (type)
16643            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
16644            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 128
16645                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
16646         return 128;
16647     }
16648
16649   if (TREE_CODE (type) == ARRAY_TYPE)
16650     {
16651       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
16652         return 64;
16653       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
16654         return 128;
16655     }
16656   else if (TREE_CODE (type) == COMPLEX_TYPE)
16657     {
16658
16659       if (TYPE_MODE (type) == DCmode && align < 64)
16660         return 64;
16661       if (TYPE_MODE (type) == XCmode && align < 128)
16662         return 128;
16663     }
16664   else if ((TREE_CODE (type) == RECORD_TYPE
16665             || TREE_CODE (type) == UNION_TYPE
16666             || TREE_CODE (type) == QUAL_UNION_TYPE)
16667            && TYPE_FIELDS (type))
16668     {
16669       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
16670         return 64;
16671       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
16672         return 128;
16673     }
16674   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
16675            || TREE_CODE (type) == INTEGER_TYPE)
16676     {
16677       if (TYPE_MODE (type) == DFmode && align < 64)
16678         return 64;
16679       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
16680         return 128;
16681     }
16682
16683   return align;
16684 }
16685
16686 /* Compute the alignment for a local variable.
16687    TYPE is the data type, and ALIGN is the alignment that
16688    the object would ordinarily have.  The value of this macro is used
16689    instead of that alignment to align the object.  */
16690
16691 int
16692 ix86_local_alignment (tree type, int align)
16693 {
16694   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
16695      to 16byte boundary.  */
16696   if (TARGET_64BIT)
16697     {
16698       if (AGGREGATE_TYPE_P (type)
16699            && TYPE_SIZE (type)
16700            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
16701            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16
16702                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
16703         return 128;
16704     }
16705   if (TREE_CODE (type) == ARRAY_TYPE)
16706     {
16707       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
16708         return 64;
16709       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
16710         return 128;
16711     }
16712   else if (TREE_CODE (type) == COMPLEX_TYPE)
16713     {
16714       if (TYPE_MODE (type) == DCmode && align < 64)
16715         return 64;
16716       if (TYPE_MODE (type) == XCmode && align < 128)
16717         return 128;
16718     }
16719   else if ((TREE_CODE (type) == RECORD_TYPE
16720             || TREE_CODE (type) == UNION_TYPE
16721             || TREE_CODE (type) == QUAL_UNION_TYPE)
16722            && TYPE_FIELDS (type))
16723     {
16724       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
16725         return 64;
16726       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
16727         return 128;
16728     }
16729   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
16730            || TREE_CODE (type) == INTEGER_TYPE)
16731     {
16732
16733       if (TYPE_MODE (type) == DFmode && align < 64)
16734         return 64;
16735       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
16736         return 128;
16737     }
16738   return align;
16739 }
16740 \f
16741 /* Emit RTL insns to initialize the variable parts of a trampoline.
16742    FNADDR is an RTX for the address of the function's pure code.
16743    CXT is an RTX for the static chain value for the function.  */
16744 void
16745 x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
16746 {
16747   if (!TARGET_64BIT)
16748     {
16749       /* Compute offset from the end of the jmp to the target function.  */
16750       rtx disp = expand_binop (SImode, sub_optab, fnaddr,
16751                                plus_constant (tramp, 10),
16752                                NULL_RTX, 1, OPTAB_DIRECT);
16753       emit_move_insn (gen_rtx_MEM (QImode, tramp),
16754                       gen_int_mode (0xb9, QImode));
16755       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
16756       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
16757                       gen_int_mode (0xe9, QImode));
16758       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
16759     }
16760   else
16761     {
16762       int offset = 0;
16763       /* Try to load address using shorter movl instead of movabs.
16764          We may want to support movq for kernel mode, but kernel does not use
16765          trampolines at the moment.  */
16766       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
16767         {
16768           fnaddr = copy_to_mode_reg (DImode, fnaddr);
16769           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
16770                           gen_int_mode (0xbb41, HImode));
16771           emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
16772                           gen_lowpart (SImode, fnaddr));
16773           offset += 6;
16774         }
16775       else
16776         {
16777           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
16778                           gen_int_mode (0xbb49, HImode));
16779           emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
16780                           fnaddr);
16781           offset += 10;
16782         }
16783       /* Load static chain using movabs to r10.  */
16784       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
16785                       gen_int_mode (0xba49, HImode));
16786       emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
16787                       cxt);
16788       offset += 10;
16789       /* Jump to the r11 */
16790       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
16791                       gen_int_mode (0xff49, HImode));
16792       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
16793                       gen_int_mode (0xe3, QImode));
16794       offset += 3;
16795       gcc_assert (offset <= TRAMPOLINE_SIZE);
16796     }
16797
16798 #ifdef ENABLE_EXECUTE_STACK
16799   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
16800                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
16801 #endif
16802 }
16803 \f
16804 /* Codes for all the SSE/MMX builtins.  */
16805 enum ix86_builtins
16806 {
16807   IX86_BUILTIN_ADDPS,
16808   IX86_BUILTIN_ADDSS,
16809   IX86_BUILTIN_DIVPS,
16810   IX86_BUILTIN_DIVSS,
16811   IX86_BUILTIN_MULPS,
16812   IX86_BUILTIN_MULSS,
16813   IX86_BUILTIN_SUBPS,
16814   IX86_BUILTIN_SUBSS,
16815
16816   IX86_BUILTIN_CMPEQPS,
16817   IX86_BUILTIN_CMPLTPS,
16818   IX86_BUILTIN_CMPLEPS,
16819   IX86_BUILTIN_CMPGTPS,
16820   IX86_BUILTIN_CMPGEPS,
16821   IX86_BUILTIN_CMPNEQPS,
16822   IX86_BUILTIN_CMPNLTPS,
16823   IX86_BUILTIN_CMPNLEPS,
16824   IX86_BUILTIN_CMPNGTPS,
16825   IX86_BUILTIN_CMPNGEPS,
16826   IX86_BUILTIN_CMPORDPS,
16827   IX86_BUILTIN_CMPUNORDPS,
16828   IX86_BUILTIN_CMPEQSS,
16829   IX86_BUILTIN_CMPLTSS,
16830   IX86_BUILTIN_CMPLESS,
16831   IX86_BUILTIN_CMPNEQSS,
16832   IX86_BUILTIN_CMPNLTSS,
16833   IX86_BUILTIN_CMPNLESS,
16834   IX86_BUILTIN_CMPNGTSS,
16835   IX86_BUILTIN_CMPNGESS,
16836   IX86_BUILTIN_CMPORDSS,
16837   IX86_BUILTIN_CMPUNORDSS,
16838
16839   IX86_BUILTIN_COMIEQSS,
16840   IX86_BUILTIN_COMILTSS,
16841   IX86_BUILTIN_COMILESS,
16842   IX86_BUILTIN_COMIGTSS,
16843   IX86_BUILTIN_COMIGESS,
16844   IX86_BUILTIN_COMINEQSS,
16845   IX86_BUILTIN_UCOMIEQSS,
16846   IX86_BUILTIN_UCOMILTSS,
16847   IX86_BUILTIN_UCOMILESS,
16848   IX86_BUILTIN_UCOMIGTSS,
16849   IX86_BUILTIN_UCOMIGESS,
16850   IX86_BUILTIN_UCOMINEQSS,
16851
16852   IX86_BUILTIN_CVTPI2PS,
16853   IX86_BUILTIN_CVTPS2PI,
16854   IX86_BUILTIN_CVTSI2SS,
16855   IX86_BUILTIN_CVTSI642SS,
16856   IX86_BUILTIN_CVTSS2SI,
16857   IX86_BUILTIN_CVTSS2SI64,
16858   IX86_BUILTIN_CVTTPS2PI,
16859   IX86_BUILTIN_CVTTSS2SI,
16860   IX86_BUILTIN_CVTTSS2SI64,
16861
16862   IX86_BUILTIN_MAXPS,
16863   IX86_BUILTIN_MAXSS,
16864   IX86_BUILTIN_MINPS,
16865   IX86_BUILTIN_MINSS,
16866
16867   IX86_BUILTIN_LOADUPS,
16868   IX86_BUILTIN_STOREUPS,
16869   IX86_BUILTIN_MOVSS,
16870
16871   IX86_BUILTIN_MOVHLPS,
16872   IX86_BUILTIN_MOVLHPS,
16873   IX86_BUILTIN_LOADHPS,
16874   IX86_BUILTIN_LOADLPS,
16875   IX86_BUILTIN_STOREHPS,
16876   IX86_BUILTIN_STORELPS,
16877
16878   IX86_BUILTIN_MASKMOVQ,
16879   IX86_BUILTIN_MOVMSKPS,
16880   IX86_BUILTIN_PMOVMSKB,
16881
16882   IX86_BUILTIN_MOVNTPS,
16883   IX86_BUILTIN_MOVNTQ,
16884
16885   IX86_BUILTIN_LOADDQU,
16886   IX86_BUILTIN_STOREDQU,
16887
16888   IX86_BUILTIN_PACKSSWB,
16889   IX86_BUILTIN_PACKSSDW,
16890   IX86_BUILTIN_PACKUSWB,
16891
16892   IX86_BUILTIN_PADDB,
16893   IX86_BUILTIN_PADDW,
16894   IX86_BUILTIN_PADDD,
16895   IX86_BUILTIN_PADDQ,
16896   IX86_BUILTIN_PADDSB,
16897   IX86_BUILTIN_PADDSW,
16898   IX86_BUILTIN_PADDUSB,
16899   IX86_BUILTIN_PADDUSW,
16900   IX86_BUILTIN_PSUBB,
16901   IX86_BUILTIN_PSUBW,
16902   IX86_BUILTIN_PSUBD,
16903   IX86_BUILTIN_PSUBQ,
16904   IX86_BUILTIN_PSUBSB,
16905   IX86_BUILTIN_PSUBSW,
16906   IX86_BUILTIN_PSUBUSB,
16907   IX86_BUILTIN_PSUBUSW,
16908
16909   IX86_BUILTIN_PAND,
16910   IX86_BUILTIN_PANDN,
16911   IX86_BUILTIN_POR,
16912   IX86_BUILTIN_PXOR,
16913
16914   IX86_BUILTIN_PAVGB,
16915   IX86_BUILTIN_PAVGW,
16916
16917   IX86_BUILTIN_PCMPEQB,
16918   IX86_BUILTIN_PCMPEQW,
16919   IX86_BUILTIN_PCMPEQD,
16920   IX86_BUILTIN_PCMPGTB,
16921   IX86_BUILTIN_PCMPGTW,
16922   IX86_BUILTIN_PCMPGTD,
16923
16924   IX86_BUILTIN_PMADDWD,
16925
16926   IX86_BUILTIN_PMAXSW,
16927   IX86_BUILTIN_PMAXUB,
16928   IX86_BUILTIN_PMINSW,
16929   IX86_BUILTIN_PMINUB,
16930
16931   IX86_BUILTIN_PMULHUW,
16932   IX86_BUILTIN_PMULHW,
16933   IX86_BUILTIN_PMULLW,
16934
16935   IX86_BUILTIN_PSADBW,
16936   IX86_BUILTIN_PSHUFW,
16937
16938   IX86_BUILTIN_PSLLW,
16939   IX86_BUILTIN_PSLLD,
16940   IX86_BUILTIN_PSLLQ,
16941   IX86_BUILTIN_PSRAW,
16942   IX86_BUILTIN_PSRAD,
16943   IX86_BUILTIN_PSRLW,
16944   IX86_BUILTIN_PSRLD,
16945   IX86_BUILTIN_PSRLQ,
16946   IX86_BUILTIN_PSLLWI,
16947   IX86_BUILTIN_PSLLDI,
16948   IX86_BUILTIN_PSLLQI,
16949   IX86_BUILTIN_PSRAWI,
16950   IX86_BUILTIN_PSRADI,
16951   IX86_BUILTIN_PSRLWI,
16952   IX86_BUILTIN_PSRLDI,
16953   IX86_BUILTIN_PSRLQI,
16954
16955   IX86_BUILTIN_PUNPCKHBW,
16956   IX86_BUILTIN_PUNPCKHWD,
16957   IX86_BUILTIN_PUNPCKHDQ,
16958   IX86_BUILTIN_PUNPCKLBW,
16959   IX86_BUILTIN_PUNPCKLWD,
16960   IX86_BUILTIN_PUNPCKLDQ,
16961
16962   IX86_BUILTIN_SHUFPS,
16963
16964   IX86_BUILTIN_RCPPS,
16965   IX86_BUILTIN_RCPSS,
16966   IX86_BUILTIN_RSQRTPS,
16967   IX86_BUILTIN_RSQRTSS,
16968   IX86_BUILTIN_RSQRTF,
16969   IX86_BUILTIN_SQRTPS,
16970   IX86_BUILTIN_SQRTSS,
16971
16972   IX86_BUILTIN_UNPCKHPS,
16973   IX86_BUILTIN_UNPCKLPS,
16974
16975   IX86_BUILTIN_ANDPS,
16976   IX86_BUILTIN_ANDNPS,
16977   IX86_BUILTIN_ORPS,
16978   IX86_BUILTIN_XORPS,
16979
16980   IX86_BUILTIN_EMMS,
16981   IX86_BUILTIN_LDMXCSR,
16982   IX86_BUILTIN_STMXCSR,
16983   IX86_BUILTIN_SFENCE,
16984
16985   /* 3DNow! Original */
16986   IX86_BUILTIN_FEMMS,
16987   IX86_BUILTIN_PAVGUSB,
16988   IX86_BUILTIN_PF2ID,
16989   IX86_BUILTIN_PFACC,
16990   IX86_BUILTIN_PFADD,
16991   IX86_BUILTIN_PFCMPEQ,
16992   IX86_BUILTIN_PFCMPGE,
16993   IX86_BUILTIN_PFCMPGT,
16994   IX86_BUILTIN_PFMAX,
16995   IX86_BUILTIN_PFMIN,
16996   IX86_BUILTIN_PFMUL,
16997   IX86_BUILTIN_PFRCP,
16998   IX86_BUILTIN_PFRCPIT1,
16999   IX86_BUILTIN_PFRCPIT2,
17000   IX86_BUILTIN_PFRSQIT1,
17001   IX86_BUILTIN_PFRSQRT,
17002   IX86_BUILTIN_PFSUB,
17003   IX86_BUILTIN_PFSUBR,
17004   IX86_BUILTIN_PI2FD,
17005   IX86_BUILTIN_PMULHRW,
17006
17007   /* 3DNow! Athlon Extensions */
17008   IX86_BUILTIN_PF2IW,
17009   IX86_BUILTIN_PFNACC,
17010   IX86_BUILTIN_PFPNACC,
17011   IX86_BUILTIN_PI2FW,
17012   IX86_BUILTIN_PSWAPDSI,
17013   IX86_BUILTIN_PSWAPDSF,
17014
17015   /* SSE2 */
17016   IX86_BUILTIN_ADDPD,
17017   IX86_BUILTIN_ADDSD,
17018   IX86_BUILTIN_DIVPD,
17019   IX86_BUILTIN_DIVSD,
17020   IX86_BUILTIN_MULPD,
17021   IX86_BUILTIN_MULSD,
17022   IX86_BUILTIN_SUBPD,
17023   IX86_BUILTIN_SUBSD,
17024
17025   IX86_BUILTIN_CMPEQPD,
17026   IX86_BUILTIN_CMPLTPD,
17027   IX86_BUILTIN_CMPLEPD,
17028   IX86_BUILTIN_CMPGTPD,
17029   IX86_BUILTIN_CMPGEPD,
17030   IX86_BUILTIN_CMPNEQPD,
17031   IX86_BUILTIN_CMPNLTPD,
17032   IX86_BUILTIN_CMPNLEPD,
17033   IX86_BUILTIN_CMPNGTPD,
17034   IX86_BUILTIN_CMPNGEPD,
17035   IX86_BUILTIN_CMPORDPD,
17036   IX86_BUILTIN_CMPUNORDPD,
17037   IX86_BUILTIN_CMPEQSD,
17038   IX86_BUILTIN_CMPLTSD,
17039   IX86_BUILTIN_CMPLESD,
17040   IX86_BUILTIN_CMPNEQSD,
17041   IX86_BUILTIN_CMPNLTSD,
17042   IX86_BUILTIN_CMPNLESD,
17043   IX86_BUILTIN_CMPORDSD,
17044   IX86_BUILTIN_CMPUNORDSD,
17045
17046   IX86_BUILTIN_COMIEQSD,
17047   IX86_BUILTIN_COMILTSD,
17048   IX86_BUILTIN_COMILESD,
17049   IX86_BUILTIN_COMIGTSD,
17050   IX86_BUILTIN_COMIGESD,
17051   IX86_BUILTIN_COMINEQSD,
17052   IX86_BUILTIN_UCOMIEQSD,
17053   IX86_BUILTIN_UCOMILTSD,
17054   IX86_BUILTIN_UCOMILESD,
17055   IX86_BUILTIN_UCOMIGTSD,
17056   IX86_BUILTIN_UCOMIGESD,
17057   IX86_BUILTIN_UCOMINEQSD,
17058
17059   IX86_BUILTIN_MAXPD,
17060   IX86_BUILTIN_MAXSD,
17061   IX86_BUILTIN_MINPD,
17062   IX86_BUILTIN_MINSD,
17063
17064   IX86_BUILTIN_ANDPD,
17065   IX86_BUILTIN_ANDNPD,
17066   IX86_BUILTIN_ORPD,
17067   IX86_BUILTIN_XORPD,
17068
17069   IX86_BUILTIN_SQRTPD,
17070   IX86_BUILTIN_SQRTSD,
17071
17072   IX86_BUILTIN_UNPCKHPD,
17073   IX86_BUILTIN_UNPCKLPD,
17074
17075   IX86_BUILTIN_SHUFPD,
17076
17077   IX86_BUILTIN_LOADUPD,
17078   IX86_BUILTIN_STOREUPD,
17079   IX86_BUILTIN_MOVSD,
17080
17081   IX86_BUILTIN_LOADHPD,
17082   IX86_BUILTIN_LOADLPD,
17083
17084   IX86_BUILTIN_CVTDQ2PD,
17085   IX86_BUILTIN_CVTDQ2PS,
17086
17087   IX86_BUILTIN_CVTPD2DQ,
17088   IX86_BUILTIN_CVTPD2PI,
17089   IX86_BUILTIN_CVTPD2PS,
17090   IX86_BUILTIN_CVTTPD2DQ,
17091   IX86_BUILTIN_CVTTPD2PI,
17092
17093   IX86_BUILTIN_CVTPI2PD,
17094   IX86_BUILTIN_CVTSI2SD,
17095   IX86_BUILTIN_CVTSI642SD,
17096
17097   IX86_BUILTIN_CVTSD2SI,
17098   IX86_BUILTIN_CVTSD2SI64,
17099   IX86_BUILTIN_CVTSD2SS,
17100   IX86_BUILTIN_CVTSS2SD,
17101   IX86_BUILTIN_CVTTSD2SI,
17102   IX86_BUILTIN_CVTTSD2SI64,
17103
17104   IX86_BUILTIN_CVTPS2DQ,
17105   IX86_BUILTIN_CVTPS2PD,
17106   IX86_BUILTIN_CVTTPS2DQ,
17107
17108   IX86_BUILTIN_MOVNTI,
17109   IX86_BUILTIN_MOVNTPD,
17110   IX86_BUILTIN_MOVNTDQ,
17111
17112   /* SSE2 MMX */
17113   IX86_BUILTIN_MASKMOVDQU,
17114   IX86_BUILTIN_MOVMSKPD,
17115   IX86_BUILTIN_PMOVMSKB128,
17116
17117   IX86_BUILTIN_PACKSSWB128,
17118   IX86_BUILTIN_PACKSSDW128,
17119   IX86_BUILTIN_PACKUSWB128,
17120
17121   IX86_BUILTIN_PADDB128,
17122   IX86_BUILTIN_PADDW128,
17123   IX86_BUILTIN_PADDD128,
17124   IX86_BUILTIN_PADDQ128,
17125   IX86_BUILTIN_PADDSB128,
17126   IX86_BUILTIN_PADDSW128,
17127   IX86_BUILTIN_PADDUSB128,
17128   IX86_BUILTIN_PADDUSW128,
17129   IX86_BUILTIN_PSUBB128,
17130   IX86_BUILTIN_PSUBW128,
17131   IX86_BUILTIN_PSUBD128,
17132   IX86_BUILTIN_PSUBQ128,
17133   IX86_BUILTIN_PSUBSB128,
17134   IX86_BUILTIN_PSUBSW128,
17135   IX86_BUILTIN_PSUBUSB128,
17136   IX86_BUILTIN_PSUBUSW128,
17137
17138   IX86_BUILTIN_PAND128,
17139   IX86_BUILTIN_PANDN128,
17140   IX86_BUILTIN_POR128,
17141   IX86_BUILTIN_PXOR128,
17142
17143   IX86_BUILTIN_PAVGB128,
17144   IX86_BUILTIN_PAVGW128,
17145
17146   IX86_BUILTIN_PCMPEQB128,
17147   IX86_BUILTIN_PCMPEQW128,
17148   IX86_BUILTIN_PCMPEQD128,
17149   IX86_BUILTIN_PCMPGTB128,
17150   IX86_BUILTIN_PCMPGTW128,
17151   IX86_BUILTIN_PCMPGTD128,
17152
17153   IX86_BUILTIN_PMADDWD128,
17154
17155   IX86_BUILTIN_PMAXSW128,
17156   IX86_BUILTIN_PMAXUB128,
17157   IX86_BUILTIN_PMINSW128,
17158   IX86_BUILTIN_PMINUB128,
17159
17160   IX86_BUILTIN_PMULUDQ,
17161   IX86_BUILTIN_PMULUDQ128,
17162   IX86_BUILTIN_PMULHUW128,
17163   IX86_BUILTIN_PMULHW128,
17164   IX86_BUILTIN_PMULLW128,
17165
17166   IX86_BUILTIN_PSADBW128,
17167   IX86_BUILTIN_PSHUFHW,
17168   IX86_BUILTIN_PSHUFLW,
17169   IX86_BUILTIN_PSHUFD,
17170
17171   IX86_BUILTIN_PSLLDQI128,
17172   IX86_BUILTIN_PSLLWI128,
17173   IX86_BUILTIN_PSLLDI128,
17174   IX86_BUILTIN_PSLLQI128,
17175   IX86_BUILTIN_PSRAWI128,
17176   IX86_BUILTIN_PSRADI128,
17177   IX86_BUILTIN_PSRLDQI128,
17178   IX86_BUILTIN_PSRLWI128,
17179   IX86_BUILTIN_PSRLDI128,
17180   IX86_BUILTIN_PSRLQI128,
17181
17182   IX86_BUILTIN_PSLLDQ128,
17183   IX86_BUILTIN_PSLLW128,
17184   IX86_BUILTIN_PSLLD128,
17185   IX86_BUILTIN_PSLLQ128,
17186   IX86_BUILTIN_PSRAW128,
17187   IX86_BUILTIN_PSRAD128,
17188   IX86_BUILTIN_PSRLW128,
17189   IX86_BUILTIN_PSRLD128,
17190   IX86_BUILTIN_PSRLQ128,
17191
17192   IX86_BUILTIN_PUNPCKHBW128,
17193   IX86_BUILTIN_PUNPCKHWD128,
17194   IX86_BUILTIN_PUNPCKHDQ128,
17195   IX86_BUILTIN_PUNPCKHQDQ128,
17196   IX86_BUILTIN_PUNPCKLBW128,
17197   IX86_BUILTIN_PUNPCKLWD128,
17198   IX86_BUILTIN_PUNPCKLDQ128,
17199   IX86_BUILTIN_PUNPCKLQDQ128,
17200
17201   IX86_BUILTIN_CLFLUSH,
17202   IX86_BUILTIN_MFENCE,
17203   IX86_BUILTIN_LFENCE,
17204
17205   /* Prescott New Instructions.  */
17206   IX86_BUILTIN_ADDSUBPS,
17207   IX86_BUILTIN_HADDPS,
17208   IX86_BUILTIN_HSUBPS,
17209   IX86_BUILTIN_MOVSHDUP,
17210   IX86_BUILTIN_MOVSLDUP,
17211   IX86_BUILTIN_ADDSUBPD,
17212   IX86_BUILTIN_HADDPD,
17213   IX86_BUILTIN_HSUBPD,
17214   IX86_BUILTIN_LDDQU,
17215
17216   IX86_BUILTIN_MONITOR,
17217   IX86_BUILTIN_MWAIT,
17218
17219   /* SSSE3.  */
17220   IX86_BUILTIN_PHADDW,
17221   IX86_BUILTIN_PHADDD,
17222   IX86_BUILTIN_PHADDSW,
17223   IX86_BUILTIN_PHSUBW,
17224   IX86_BUILTIN_PHSUBD,
17225   IX86_BUILTIN_PHSUBSW,
17226   IX86_BUILTIN_PMADDUBSW,
17227   IX86_BUILTIN_PMULHRSW,
17228   IX86_BUILTIN_PSHUFB,
17229   IX86_BUILTIN_PSIGNB,
17230   IX86_BUILTIN_PSIGNW,
17231   IX86_BUILTIN_PSIGND,
17232   IX86_BUILTIN_PALIGNR,
17233   IX86_BUILTIN_PABSB,
17234   IX86_BUILTIN_PABSW,
17235   IX86_BUILTIN_PABSD,
17236
17237   IX86_BUILTIN_PHADDW128,
17238   IX86_BUILTIN_PHADDD128,
17239   IX86_BUILTIN_PHADDSW128,
17240   IX86_BUILTIN_PHSUBW128,
17241   IX86_BUILTIN_PHSUBD128,
17242   IX86_BUILTIN_PHSUBSW128,
17243   IX86_BUILTIN_PMADDUBSW128,
17244   IX86_BUILTIN_PMULHRSW128,
17245   IX86_BUILTIN_PSHUFB128,
17246   IX86_BUILTIN_PSIGNB128,
17247   IX86_BUILTIN_PSIGNW128,
17248   IX86_BUILTIN_PSIGND128,
17249   IX86_BUILTIN_PALIGNR128,
17250   IX86_BUILTIN_PABSB128,
17251   IX86_BUILTIN_PABSW128,
17252   IX86_BUILTIN_PABSD128,
17253
17254   /* AMDFAM10 - SSE4A New Instructions.  */
17255   IX86_BUILTIN_MOVNTSD,
17256   IX86_BUILTIN_MOVNTSS,
17257   IX86_BUILTIN_EXTRQI,
17258   IX86_BUILTIN_EXTRQ,
17259   IX86_BUILTIN_INSERTQI,
17260   IX86_BUILTIN_INSERTQ,
17261
17262   /* SSE4.1.  */
17263   IX86_BUILTIN_BLENDPD,
17264   IX86_BUILTIN_BLENDPS,
17265   IX86_BUILTIN_BLENDVPD,
17266   IX86_BUILTIN_BLENDVPS,
17267   IX86_BUILTIN_PBLENDVB128,
17268   IX86_BUILTIN_PBLENDW128,
17269
17270   IX86_BUILTIN_DPPD,
17271   IX86_BUILTIN_DPPS,
17272
17273   IX86_BUILTIN_INSERTPS128,
17274
17275   IX86_BUILTIN_MOVNTDQA,
17276   IX86_BUILTIN_MPSADBW128,
17277   IX86_BUILTIN_PACKUSDW128,
17278   IX86_BUILTIN_PCMPEQQ,
17279   IX86_BUILTIN_PHMINPOSUW128,
17280
17281   IX86_BUILTIN_PMAXSB128,
17282   IX86_BUILTIN_PMAXSD128,
17283   IX86_BUILTIN_PMAXUD128,
17284   IX86_BUILTIN_PMAXUW128,
17285
17286   IX86_BUILTIN_PMINSB128,
17287   IX86_BUILTIN_PMINSD128,
17288   IX86_BUILTIN_PMINUD128,
17289   IX86_BUILTIN_PMINUW128,
17290
17291   IX86_BUILTIN_PMOVSXBW128,
17292   IX86_BUILTIN_PMOVSXBD128,
17293   IX86_BUILTIN_PMOVSXBQ128,
17294   IX86_BUILTIN_PMOVSXWD128,
17295   IX86_BUILTIN_PMOVSXWQ128,
17296   IX86_BUILTIN_PMOVSXDQ128,
17297
17298   IX86_BUILTIN_PMOVZXBW128,
17299   IX86_BUILTIN_PMOVZXBD128,
17300   IX86_BUILTIN_PMOVZXBQ128,
17301   IX86_BUILTIN_PMOVZXWD128,
17302   IX86_BUILTIN_PMOVZXWQ128,
17303   IX86_BUILTIN_PMOVZXDQ128,
17304
17305   IX86_BUILTIN_PMULDQ128,
17306   IX86_BUILTIN_PMULLD128,
17307
17308   IX86_BUILTIN_ROUNDPD,
17309   IX86_BUILTIN_ROUNDPS,
17310   IX86_BUILTIN_ROUNDSD,
17311   IX86_BUILTIN_ROUNDSS,
17312
17313   IX86_BUILTIN_PTESTZ,
17314   IX86_BUILTIN_PTESTC,
17315   IX86_BUILTIN_PTESTNZC,
17316
17317   IX86_BUILTIN_VEC_INIT_V2SI,
17318   IX86_BUILTIN_VEC_INIT_V4HI,
17319   IX86_BUILTIN_VEC_INIT_V8QI,
17320   IX86_BUILTIN_VEC_EXT_V2DF,
17321   IX86_BUILTIN_VEC_EXT_V2DI,
17322   IX86_BUILTIN_VEC_EXT_V4SF,
17323   IX86_BUILTIN_VEC_EXT_V4SI,
17324   IX86_BUILTIN_VEC_EXT_V8HI,
17325   IX86_BUILTIN_VEC_EXT_V2SI,
17326   IX86_BUILTIN_VEC_EXT_V4HI,
17327   IX86_BUILTIN_VEC_EXT_V16QI,
17328   IX86_BUILTIN_VEC_SET_V2DI,
17329   IX86_BUILTIN_VEC_SET_V4SF,
17330   IX86_BUILTIN_VEC_SET_V4SI,
17331   IX86_BUILTIN_VEC_SET_V8HI,
17332   IX86_BUILTIN_VEC_SET_V4HI,
17333   IX86_BUILTIN_VEC_SET_V16QI,
17334
17335   IX86_BUILTIN_VEC_PACK_SFIX,
17336
17337   /* SSE4.2.  */
17338   IX86_BUILTIN_CRC32QI,
17339   IX86_BUILTIN_CRC32HI,
17340   IX86_BUILTIN_CRC32SI,
17341   IX86_BUILTIN_CRC32DI,
17342
17343   IX86_BUILTIN_PCMPESTRI128,
17344   IX86_BUILTIN_PCMPESTRM128,
17345   IX86_BUILTIN_PCMPESTRA128,
17346   IX86_BUILTIN_PCMPESTRC128,
17347   IX86_BUILTIN_PCMPESTRO128,
17348   IX86_BUILTIN_PCMPESTRS128,
17349   IX86_BUILTIN_PCMPESTRZ128,
17350   IX86_BUILTIN_PCMPISTRI128,
17351   IX86_BUILTIN_PCMPISTRM128,
17352   IX86_BUILTIN_PCMPISTRA128,
17353   IX86_BUILTIN_PCMPISTRC128,
17354   IX86_BUILTIN_PCMPISTRO128,
17355   IX86_BUILTIN_PCMPISTRS128,
17356   IX86_BUILTIN_PCMPISTRZ128,
17357
17358   IX86_BUILTIN_PCMPGTQ,
17359
17360   /* TFmode support builtins.  */
17361   IX86_BUILTIN_INFQ,
17362   IX86_BUILTIN_FABSQ,
17363   IX86_BUILTIN_COPYSIGNQ,
17364
17365   /* SSE5 instructions */
17366   IX86_BUILTIN_FMADDSS,
17367   IX86_BUILTIN_FMADDSD,
17368   IX86_BUILTIN_FMADDPS,
17369   IX86_BUILTIN_FMADDPD,
17370   IX86_BUILTIN_FMSUBSS,
17371   IX86_BUILTIN_FMSUBSD,
17372   IX86_BUILTIN_FMSUBPS,
17373   IX86_BUILTIN_FMSUBPD,
17374   IX86_BUILTIN_FNMADDSS,
17375   IX86_BUILTIN_FNMADDSD,
17376   IX86_BUILTIN_FNMADDPS,
17377   IX86_BUILTIN_FNMADDPD,
17378   IX86_BUILTIN_FNMSUBSS,
17379   IX86_BUILTIN_FNMSUBSD,
17380   IX86_BUILTIN_FNMSUBPS,
17381   IX86_BUILTIN_FNMSUBPD,
17382   IX86_BUILTIN_PCMOV_V2DI,
17383   IX86_BUILTIN_PCMOV_V4SI,
17384   IX86_BUILTIN_PCMOV_V8HI,
17385   IX86_BUILTIN_PCMOV_V16QI,
17386   IX86_BUILTIN_PCMOV_V4SF,
17387   IX86_BUILTIN_PCMOV_V2DF,
17388   IX86_BUILTIN_PPERM,
17389   IX86_BUILTIN_PERMPS,
17390   IX86_BUILTIN_PERMPD,
17391   IX86_BUILTIN_PMACSSWW,
17392   IX86_BUILTIN_PMACSWW,
17393   IX86_BUILTIN_PMACSSWD,
17394   IX86_BUILTIN_PMACSWD,
17395   IX86_BUILTIN_PMACSSDD,
17396   IX86_BUILTIN_PMACSDD,
17397   IX86_BUILTIN_PMACSSDQL,
17398   IX86_BUILTIN_PMACSSDQH,
17399   IX86_BUILTIN_PMACSDQL,
17400   IX86_BUILTIN_PMACSDQH,
17401   IX86_BUILTIN_PMADCSSWD,
17402   IX86_BUILTIN_PMADCSWD,
17403   IX86_BUILTIN_PHADDBW,
17404   IX86_BUILTIN_PHADDBD,
17405   IX86_BUILTIN_PHADDBQ,
17406   IX86_BUILTIN_PHADDWD,
17407   IX86_BUILTIN_PHADDWQ,
17408   IX86_BUILTIN_PHADDDQ,
17409   IX86_BUILTIN_PHADDUBW,
17410   IX86_BUILTIN_PHADDUBD,
17411   IX86_BUILTIN_PHADDUBQ,
17412   IX86_BUILTIN_PHADDUWD,
17413   IX86_BUILTIN_PHADDUWQ,
17414   IX86_BUILTIN_PHADDUDQ,
17415   IX86_BUILTIN_PHSUBBW,
17416   IX86_BUILTIN_PHSUBWD,
17417   IX86_BUILTIN_PHSUBDQ,
17418   IX86_BUILTIN_PROTB,
17419   IX86_BUILTIN_PROTW,
17420   IX86_BUILTIN_PROTD,
17421   IX86_BUILTIN_PROTQ,
17422   IX86_BUILTIN_PROTB_IMM,
17423   IX86_BUILTIN_PROTW_IMM,
17424   IX86_BUILTIN_PROTD_IMM,
17425   IX86_BUILTIN_PROTQ_IMM,
17426   IX86_BUILTIN_PSHLB,
17427   IX86_BUILTIN_PSHLW,
17428   IX86_BUILTIN_PSHLD,
17429   IX86_BUILTIN_PSHLQ,
17430   IX86_BUILTIN_PSHAB,
17431   IX86_BUILTIN_PSHAW,
17432   IX86_BUILTIN_PSHAD,
17433   IX86_BUILTIN_PSHAQ,
17434   IX86_BUILTIN_FRCZSS,
17435   IX86_BUILTIN_FRCZSD,
17436   IX86_BUILTIN_FRCZPS,
17437   IX86_BUILTIN_FRCZPD,
17438   IX86_BUILTIN_CVTPH2PS,
17439   IX86_BUILTIN_CVTPS2PH,
17440
17441   IX86_BUILTIN_COMEQSS,
17442   IX86_BUILTIN_COMNESS,
17443   IX86_BUILTIN_COMLTSS,
17444   IX86_BUILTIN_COMLESS,
17445   IX86_BUILTIN_COMGTSS,
17446   IX86_BUILTIN_COMGESS,
17447   IX86_BUILTIN_COMUEQSS,
17448   IX86_BUILTIN_COMUNESS,
17449   IX86_BUILTIN_COMULTSS,
17450   IX86_BUILTIN_COMULESS,
17451   IX86_BUILTIN_COMUGTSS,
17452   IX86_BUILTIN_COMUGESS,
17453   IX86_BUILTIN_COMORDSS,
17454   IX86_BUILTIN_COMUNORDSS,
17455   IX86_BUILTIN_COMFALSESS,
17456   IX86_BUILTIN_COMTRUESS,
17457
17458   IX86_BUILTIN_COMEQSD,
17459   IX86_BUILTIN_COMNESD,
17460   IX86_BUILTIN_COMLTSD,
17461   IX86_BUILTIN_COMLESD,
17462   IX86_BUILTIN_COMGTSD,
17463   IX86_BUILTIN_COMGESD,
17464   IX86_BUILTIN_COMUEQSD,
17465   IX86_BUILTIN_COMUNESD,
17466   IX86_BUILTIN_COMULTSD,
17467   IX86_BUILTIN_COMULESD,
17468   IX86_BUILTIN_COMUGTSD,
17469   IX86_BUILTIN_COMUGESD,
17470   IX86_BUILTIN_COMORDSD,
17471   IX86_BUILTIN_COMUNORDSD,
17472   IX86_BUILTIN_COMFALSESD,
17473   IX86_BUILTIN_COMTRUESD,
17474
17475   IX86_BUILTIN_COMEQPS,
17476   IX86_BUILTIN_COMNEPS,
17477   IX86_BUILTIN_COMLTPS,
17478   IX86_BUILTIN_COMLEPS,
17479   IX86_BUILTIN_COMGTPS,
17480   IX86_BUILTIN_COMGEPS,
17481   IX86_BUILTIN_COMUEQPS,
17482   IX86_BUILTIN_COMUNEPS,
17483   IX86_BUILTIN_COMULTPS,
17484   IX86_BUILTIN_COMULEPS,
17485   IX86_BUILTIN_COMUGTPS,
17486   IX86_BUILTIN_COMUGEPS,
17487   IX86_BUILTIN_COMORDPS,
17488   IX86_BUILTIN_COMUNORDPS,
17489   IX86_BUILTIN_COMFALSEPS,
17490   IX86_BUILTIN_COMTRUEPS,
17491
17492   IX86_BUILTIN_COMEQPD,
17493   IX86_BUILTIN_COMNEPD,
17494   IX86_BUILTIN_COMLTPD,
17495   IX86_BUILTIN_COMLEPD,
17496   IX86_BUILTIN_COMGTPD,
17497   IX86_BUILTIN_COMGEPD,
17498   IX86_BUILTIN_COMUEQPD,
17499   IX86_BUILTIN_COMUNEPD,
17500   IX86_BUILTIN_COMULTPD,
17501   IX86_BUILTIN_COMULEPD,
17502   IX86_BUILTIN_COMUGTPD,
17503   IX86_BUILTIN_COMUGEPD,
17504   IX86_BUILTIN_COMORDPD,
17505   IX86_BUILTIN_COMUNORDPD,
17506   IX86_BUILTIN_COMFALSEPD,
17507   IX86_BUILTIN_COMTRUEPD,
17508
17509   IX86_BUILTIN_PCOMEQUB,
17510   IX86_BUILTIN_PCOMNEUB,
17511   IX86_BUILTIN_PCOMLTUB,
17512   IX86_BUILTIN_PCOMLEUB,
17513   IX86_BUILTIN_PCOMGTUB,
17514   IX86_BUILTIN_PCOMGEUB,
17515   IX86_BUILTIN_PCOMFALSEUB,
17516   IX86_BUILTIN_PCOMTRUEUB,
17517   IX86_BUILTIN_PCOMEQUW,
17518   IX86_BUILTIN_PCOMNEUW,
17519   IX86_BUILTIN_PCOMLTUW,
17520   IX86_BUILTIN_PCOMLEUW,
17521   IX86_BUILTIN_PCOMGTUW,
17522   IX86_BUILTIN_PCOMGEUW,
17523   IX86_BUILTIN_PCOMFALSEUW,
17524   IX86_BUILTIN_PCOMTRUEUW,
17525   IX86_BUILTIN_PCOMEQUD,
17526   IX86_BUILTIN_PCOMNEUD,
17527   IX86_BUILTIN_PCOMLTUD,
17528   IX86_BUILTIN_PCOMLEUD,
17529   IX86_BUILTIN_PCOMGTUD,
17530   IX86_BUILTIN_PCOMGEUD,
17531   IX86_BUILTIN_PCOMFALSEUD,
17532   IX86_BUILTIN_PCOMTRUEUD,
17533   IX86_BUILTIN_PCOMEQUQ,
17534   IX86_BUILTIN_PCOMNEUQ,
17535   IX86_BUILTIN_PCOMLTUQ,
17536   IX86_BUILTIN_PCOMLEUQ,
17537   IX86_BUILTIN_PCOMGTUQ,
17538   IX86_BUILTIN_PCOMGEUQ,
17539   IX86_BUILTIN_PCOMFALSEUQ,
17540   IX86_BUILTIN_PCOMTRUEUQ,
17541
17542   IX86_BUILTIN_PCOMEQB,
17543   IX86_BUILTIN_PCOMNEB,
17544   IX86_BUILTIN_PCOMLTB,
17545   IX86_BUILTIN_PCOMLEB,
17546   IX86_BUILTIN_PCOMGTB,
17547   IX86_BUILTIN_PCOMGEB,
17548   IX86_BUILTIN_PCOMFALSEB,
17549   IX86_BUILTIN_PCOMTRUEB,
17550   IX86_BUILTIN_PCOMEQW,
17551   IX86_BUILTIN_PCOMNEW,
17552   IX86_BUILTIN_PCOMLTW,
17553   IX86_BUILTIN_PCOMLEW,
17554   IX86_BUILTIN_PCOMGTW,
17555   IX86_BUILTIN_PCOMGEW,
17556   IX86_BUILTIN_PCOMFALSEW,
17557   IX86_BUILTIN_PCOMTRUEW,
17558   IX86_BUILTIN_PCOMEQD,
17559   IX86_BUILTIN_PCOMNED,
17560   IX86_BUILTIN_PCOMLTD,
17561   IX86_BUILTIN_PCOMLED,
17562   IX86_BUILTIN_PCOMGTD,
17563   IX86_BUILTIN_PCOMGED,
17564   IX86_BUILTIN_PCOMFALSED,
17565   IX86_BUILTIN_PCOMTRUED,
17566   IX86_BUILTIN_PCOMEQQ,
17567   IX86_BUILTIN_PCOMNEQ,
17568   IX86_BUILTIN_PCOMLTQ,
17569   IX86_BUILTIN_PCOMLEQ,
17570   IX86_BUILTIN_PCOMGTQ,
17571   IX86_BUILTIN_PCOMGEQ,
17572   IX86_BUILTIN_PCOMFALSEQ,
17573   IX86_BUILTIN_PCOMTRUEQ,
17574
17575   IX86_BUILTIN_MAX
17576 };
17577
17578 /* Table for the ix86 builtin decls.  */
17579 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
17580
17581 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Do so,
17582  * if the target_flags include one of MASK.  Stores the function decl
17583  * in the ix86_builtins array.
17584  * Returns the function decl or NULL_TREE, if the builtin was not added.  */
17585
17586 static inline tree
17587 def_builtin (int mask, const char *name, tree type, enum ix86_builtins code)
17588 {
17589   tree decl = NULL_TREE;
17590
17591   if (mask & ix86_isa_flags
17592       && (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT))
17593     {
17594       decl = add_builtin_function (name, type, code, BUILT_IN_MD,
17595                                    NULL, NULL_TREE);
17596       ix86_builtins[(int) code] = decl;
17597     }
17598
17599   return decl;
17600 }
17601
17602 /* Like def_builtin, but also marks the function decl "const".  */
17603
17604 static inline tree
17605 def_builtin_const (int mask, const char *name, tree type,
17606                    enum ix86_builtins code)
17607 {
17608   tree decl = def_builtin (mask, name, type, code);
17609   if (decl)
17610     TREE_READONLY (decl) = 1;
17611   return decl;
17612 }
17613
17614 /* Bits for builtin_description.flag.  */
17615
17616 /* Set when we don't support the comparison natively, and should
17617    swap_comparison in order to support it.  */
17618 #define BUILTIN_DESC_SWAP_OPERANDS      1
17619
17620 struct builtin_description
17621 {
17622   const unsigned int mask;
17623   const enum insn_code icode;
17624   const char *const name;
17625   const enum ix86_builtins code;
17626   const enum rtx_code comparison;
17627   const int flag;
17628 };
17629
17630 static const struct builtin_description bdesc_comi[] =
17631 {
17632   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
17633   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
17634   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
17635   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
17636   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
17637   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
17638   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
17639   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
17640   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
17641   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
17642   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
17643   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
17644   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
17645   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
17646   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
17647   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
17648   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
17649   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
17650   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
17651   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
17652   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
17653   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
17654   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
17655   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
17656 };
17657
17658 static const struct builtin_description bdesc_ptest[] =
17659 {
17660   /* SSE4.1 */
17661   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, 0 },
17662   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, 0 },
17663   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, 0 },
17664 };
17665
17666 static const struct builtin_description bdesc_pcmpestr[] =
17667 {
17668   /* SSE4.2 */
17669   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
17670   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
17671   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
17672   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
17673   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
17674   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
17675   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
17676 };
17677
17678 static const struct builtin_description bdesc_pcmpistr[] =
17679 {
17680   /* SSE4.2 */
17681   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
17682   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
17683   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
17684   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
17685   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
17686   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
17687   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
17688 };
17689
17690 static const struct builtin_description bdesc_crc32[] =
17691 {
17692   /* SSE4.2 */
17693   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse4_2_crc32qi, 0, IX86_BUILTIN_CRC32QI, UNKNOWN, 0 },
17694   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32hi, 0, IX86_BUILTIN_CRC32HI, UNKNOWN, 0 },
17695   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32si, 0, IX86_BUILTIN_CRC32SI, UNKNOWN, 0 },
17696   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32di, 0, IX86_BUILTIN_CRC32DI, UNKNOWN, 0 },
17697 };
17698
17699 /* SSE builtins with 3 arguments and the last argument must be an immediate or xmm0.  */
17700 static const struct builtin_description bdesc_sse_3arg[] =
17701 {
17702   /* SSE4.1 */
17703   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, 0 },
17704   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, 0 },
17705   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, 0 },
17706   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, 0 },
17707   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, 0 },
17708   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, 0 },
17709   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, 0 },
17710   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, 0 },
17711   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, 0 },
17712   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, 0 },
17713   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, 0, IX86_BUILTIN_ROUNDSD, UNKNOWN, 0 },
17714   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, 0, IX86_BUILTIN_ROUNDSS, UNKNOWN, 0 },
17715 };
17716
17717 static const struct builtin_description bdesc_2arg[] =
17718 {
17719   /* SSE */
17720   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, 0 },
17721   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, 0 },
17722   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, 0 },
17723   { OPTION_MASK_ISA_SSE, CODE_FOR_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, 0 },
17724   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, 0 },
17725   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, 0 },
17726   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, 0 },
17727   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, 0 },
17728
17729   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, 0 },
17730   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, 0 },
17731   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, 0 },
17732   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, BUILTIN_DESC_SWAP_OPERANDS },
17733   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, BUILTIN_DESC_SWAP_OPERANDS },
17734   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, 0 },
17735   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, 0 },
17736   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, 0 },
17737   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, 0 },
17738   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, BUILTIN_DESC_SWAP_OPERANDS },
17739   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, BUILTIN_DESC_SWAP_OPERANDS },
17740   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, 0 },
17741   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, 0 },
17742   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, 0 },
17743   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, 0 },
17744   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, 0 },
17745   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, 0 },
17746   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, 0 },
17747   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, 0 },
17748   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngtss", IX86_BUILTIN_CMPNGTSS, UNGE, BUILTIN_DESC_SWAP_OPERANDS },
17749   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngess", IX86_BUILTIN_CMPNGESS, UNGT, BUILTIN_DESC_SWAP_OPERANDS },
17750   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, 0 },
17751
17752   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, 0 },
17753   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, 0 },
17754   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, 0 },
17755   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, 0 },
17756
17757   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, 0 },
17758   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_nandv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, 0 },
17759   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, 0 },
17760   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, 0 },
17761
17762   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, 0 },
17763   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, 0 },
17764   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, 0 },
17765   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpckhps, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, 0 },
17766   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpcklps, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, 0 },
17767
17768   /* MMX */
17769   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, 0 },
17770   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, 0 },
17771   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, 0 },
17772   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_adddi3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, 0 },
17773   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, 0 },
17774   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, 0 },
17775   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, 0 },
17776   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subdi3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, 0 },
17777
17778   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, 0 },
17779   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, 0 },
17780   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, 0 },
17781   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, 0 },
17782   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, 0 },
17783   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, 0 },
17784   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, 0 },
17785   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, 0 },
17786
17787   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, 0 },
17788   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, 0 },
17789   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_umulv4hi3_highpart, "__builtin_ia32_pmulhuw", IX86_BUILTIN_PMULHUW, UNKNOWN, 0 },
17790
17791   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, 0 },
17792   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_nandv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, 0 },
17793   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, 0 },
17794   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, 0 },
17795
17796   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgb", IX86_BUILTIN_PAVGB, UNKNOWN, 0 },
17797   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uavgv4hi3, "__builtin_ia32_pavgw", IX86_BUILTIN_PAVGW, UNKNOWN, 0 },
17798
17799   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, 0 },
17800   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, 0 },
17801   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, 0 },
17802   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, 0 },
17803   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, 0 },
17804   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, 0 },
17805
17806   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_umaxv8qi3, "__builtin_ia32_pmaxub", IX86_BUILTIN_PMAXUB, UNKNOWN, 0 },
17807   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_smaxv4hi3, "__builtin_ia32_pmaxsw", IX86_BUILTIN_PMAXSW, UNKNOWN, 0 },
17808   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uminv8qi3, "__builtin_ia32_pminub", IX86_BUILTIN_PMINUB, UNKNOWN, 0 },
17809   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_sminv4hi3, "__builtin_ia32_pminsw", IX86_BUILTIN_PMINSW, UNKNOWN, 0 },
17810
17811   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, 0 },
17812   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, 0 },
17813   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, 0 },
17814   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, 0 },
17815   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, 0 },
17816   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, 0 },
17817
17818   /* Special.  */
17819   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, 0, IX86_BUILTIN_PACKSSWB, UNKNOWN, 0 },
17820   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, 0, IX86_BUILTIN_PACKSSDW, UNKNOWN, 0 },
17821   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, 0, IX86_BUILTIN_PACKUSWB, UNKNOWN, 0 },
17822
17823   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, 0, IX86_BUILTIN_CVTPI2PS, UNKNOWN, 0 },
17824   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, 0, IX86_BUILTIN_CVTSI2SS, UNKNOWN, 0 },
17825   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, 0, IX86_BUILTIN_CVTSI642SS, UNKNOWN, 0 },
17826
17827   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, 0, IX86_BUILTIN_PSLLW, UNKNOWN, 0 },
17828   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, 0, IX86_BUILTIN_PSLLWI, UNKNOWN, 0 },
17829   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, 0, IX86_BUILTIN_PSLLD, UNKNOWN, 0 },
17830   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, 0, IX86_BUILTIN_PSLLDI, UNKNOWN, 0 },
17831   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashldi3, 0, IX86_BUILTIN_PSLLQ, UNKNOWN, 0 },
17832   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashldi3, 0, IX86_BUILTIN_PSLLQI, UNKNOWN, 0 },
17833
17834   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, 0, IX86_BUILTIN_PSRLW, UNKNOWN, 0 },
17835   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, 0, IX86_BUILTIN_PSRLWI, UNKNOWN, 0 },
17836   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, 0, IX86_BUILTIN_PSRLD, UNKNOWN, 0 },
17837   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, 0, IX86_BUILTIN_PSRLDI, UNKNOWN, 0 },
17838   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrdi3, 0, IX86_BUILTIN_PSRLQ, UNKNOWN, 0 },
17839   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrdi3, 0, IX86_BUILTIN_PSRLQI, UNKNOWN, 0 },
17840
17841   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, 0, IX86_BUILTIN_PSRAW, UNKNOWN, 0 },
17842   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, 0, IX86_BUILTIN_PSRAWI, UNKNOWN, 0 },
17843   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, 0, IX86_BUILTIN_PSRAD, UNKNOWN, 0 },
17844   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, 0, IX86_BUILTIN_PSRADI, UNKNOWN, 0 },
17845
17846   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_psadbw, 0, IX86_BUILTIN_PSADBW, UNKNOWN, 0 },
17847   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, 0, IX86_BUILTIN_PMADDWD, UNKNOWN, 0 },
17848
17849   /* SSE2 */
17850   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, 0 },
17851   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, 0 },
17852   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, 0 },
17853   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, 0 },
17854   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, 0 },
17855   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, 0 },
17856   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, 0 },
17857   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, 0 },
17858
17859   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, 0 },
17860   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, 0 },
17861   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, 0 },
17862   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, BUILTIN_DESC_SWAP_OPERANDS },
17863   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, BUILTIN_DESC_SWAP_OPERANDS },
17864   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, 0 },
17865   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, 0 },
17866   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, 0 },
17867   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, 0 },
17868   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, BUILTIN_DESC_SWAP_OPERANDS },
17869   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, BUILTIN_DESC_SWAP_OPERANDS },
17870   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, 0 },
17871   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, 0 },
17872   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, 0 },
17873   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, 0 },
17874   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, 0 },
17875   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, 0 },
17876   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, 0 },
17877   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, 0 },
17878   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, 0 },
17879
17880   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, 0 },
17881   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, 0 },
17882   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, 0 },
17883   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, 0 },
17884
17885   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, 0 },
17886   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_nandv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, 0 },
17887   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, 0 },
17888   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, 0 },
17889
17890   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, 0 },
17891   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpckhpd, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, 0 },
17892   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpcklpd, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, 0 },
17893
17894   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_pack_sfix_v2df, "__builtin_ia32_vec_pack_sfix", IX86_BUILTIN_VEC_PACK_SFIX, UNKNOWN, 0 },
17895
17896   /* SSE2 MMX */
17897   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, 0 },
17898   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, 0 },
17899   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, 0 },
17900   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, 0 },
17901   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, 0 },
17902   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, 0 },
17903   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, 0 },
17904   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, 0 },
17905
17906   { OPTION_MASK_ISA_MMX, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, 0 },
17907   { OPTION_MASK_ISA_MMX, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, 0 },
17908   { OPTION_MASK_ISA_MMX, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, 0 },
17909   { OPTION_MASK_ISA_MMX, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, 0 },
17910   { OPTION_MASK_ISA_MMX, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, 0 },
17911   { OPTION_MASK_ISA_MMX, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, 0 },
17912   { OPTION_MASK_ISA_MMX, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, 0 },
17913   { OPTION_MASK_ISA_MMX, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, 0 },
17914
17915   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, 0 },
17916   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN, 0 },
17917
17918   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, 0 },
17919   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_nandv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, 0 },
17920   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, 0 },
17921   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, 0 },
17922
17923   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, 0 },
17924   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, 0 },
17925
17926   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, 0 },
17927   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, 0 },
17928   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, 0 },
17929   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, 0 },
17930   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, 0 },
17931   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, 0 },
17932
17933   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, 0 },
17934   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, 0 },
17935   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, 0 },
17936   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, 0 },
17937
17938   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhbw, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, 0 },
17939   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhwd, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, 0 },
17940   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhdq, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN, 0 },
17941   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhqdq, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, 0 },
17942   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklbw, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, 0 },
17943   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklwd, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, 0 },
17944   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckldq, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, 0 },
17945   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklqdq, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, 0 },
17946
17947   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, 0 },
17948   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, 0 },
17949   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, 0 },
17950
17951   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, 0 },
17952   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, 0, IX86_BUILTIN_PSADBW128, UNKNOWN, 0 },
17953
17954   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulsidi3, 0, IX86_BUILTIN_PMULUDQ, UNKNOWN, 0 },
17955   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv2siv2di3, 0, IX86_BUILTIN_PMULUDQ128, UNKNOWN, 0 },
17956
17957   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, 0, IX86_BUILTIN_PSLLWI128, UNKNOWN, 0 },
17958   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, 0, IX86_BUILTIN_PSLLDI128, UNKNOWN, 0 },
17959   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, 0, IX86_BUILTIN_PSLLQI128, UNKNOWN, 0 },
17960
17961   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, 0, IX86_BUILTIN_PSRLWI128, UNKNOWN, 0 },
17962   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, 0, IX86_BUILTIN_PSRLDI128, UNKNOWN, 0 },
17963   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, 0, IX86_BUILTIN_PSRLQI128, UNKNOWN, 0 },
17964
17965   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, 0, IX86_BUILTIN_PSRAWI128, UNKNOWN, 0 },
17966   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, 0, IX86_BUILTIN_PSRADI128, UNKNOWN, 0 },
17967
17968   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, 0, IX86_BUILTIN_PMADDWD128, UNKNOWN, 0 },
17969
17970   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, 0, IX86_BUILTIN_CVTSI2SD, UNKNOWN, 0 },
17971   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, 0, IX86_BUILTIN_CVTSI642SD, UNKNOWN, 0 },
17972   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, 0, IX86_BUILTIN_CVTSD2SS, UNKNOWN, 0 },
17973   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, 0, IX86_BUILTIN_CVTSS2SD, UNKNOWN, 0 },
17974
17975   /* SSE3 MMX */
17976   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, 0 },
17977   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, 0 },
17978   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, 0 },
17979   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, 0 },
17980   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, 0 },
17981   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, 0 },
17982
17983   /* SSSE3 */
17984   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, 0 },
17985   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, 0 },
17986   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, 0 },
17987   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, 0 },
17988   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, 0 },
17989   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, 0 },
17990   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, 0 },
17991   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, 0 },
17992   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, 0 },
17993   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, 0 },
17994   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, 0 },
17995   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, 0 },
17996   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubswv8hi3, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, 0 },
17997   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubswv4hi3, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, 0 },
17998   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, 0 },
17999   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, 0 },
18000   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, 0 },
18001   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, 0 },
18002   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, 0 },
18003   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, 0 },
18004   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, 0 },
18005   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, 0 },
18006   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, 0 },
18007   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, 0 },
18008
18009   /* SSE4.1 */
18010   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, 0 },
18011   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, 0 },
18012   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, 0 },
18013   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, 0 },
18014   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, 0 },
18015   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, 0 },
18016   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, 0 },
18017   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, 0 },
18018   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, 0 },
18019   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, 0 },
18020   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, 0, IX86_BUILTIN_PMULDQ128, UNKNOWN, 0 },
18021   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, 0 },
18022
18023   /* SSE4.2 */
18024   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, 0 },
18025 };
18026
18027 static const struct builtin_description bdesc_1arg[] =
18028 {
18029   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, 0, IX86_BUILTIN_PMOVMSKB, UNKNOWN, 0 },
18030   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, 0, IX86_BUILTIN_MOVMSKPS, UNKNOWN, 0 },
18031
18032   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, 0, IX86_BUILTIN_SQRTPS, UNKNOWN, 0 },
18033   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, 0, IX86_BUILTIN_RSQRTPS, UNKNOWN, 0 },
18034   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, 0, IX86_BUILTIN_RCPPS, UNKNOWN, 0 },
18035
18036   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, 0, IX86_BUILTIN_CVTPS2PI, UNKNOWN, 0 },
18037   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, 0, IX86_BUILTIN_CVTSS2SI, UNKNOWN, 0 },
18038   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, 0, IX86_BUILTIN_CVTSS2SI64, UNKNOWN, 0 },
18039   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, 0, IX86_BUILTIN_CVTTPS2PI, UNKNOWN, 0 },
18040   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, 0, IX86_BUILTIN_CVTTSS2SI, UNKNOWN, 0 },
18041   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, 0, IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, 0 },
18042
18043   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, 0, IX86_BUILTIN_PMOVMSKB128, UNKNOWN, 0 },
18044   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, 0, IX86_BUILTIN_MOVMSKPD, UNKNOWN, 0 },
18045
18046   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, 0, IX86_BUILTIN_SQRTPD, UNKNOWN, 0 },
18047
18048   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, 0, IX86_BUILTIN_CVTDQ2PD, UNKNOWN, 0 },
18049   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2ps, 0, IX86_BUILTIN_CVTDQ2PS, UNKNOWN, 0 },
18050
18051   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, 0, IX86_BUILTIN_CVTPD2DQ, UNKNOWN, 0 },
18052   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, 0, IX86_BUILTIN_CVTPD2PI, UNKNOWN, 0 },
18053   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, 0, IX86_BUILTIN_CVTPD2PS, UNKNOWN, 0 },
18054   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, 0, IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, 0 },
18055   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, 0, IX86_BUILTIN_CVTTPD2PI, UNKNOWN, 0 },
18056
18057   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, 0, IX86_BUILTIN_CVTPI2PD, UNKNOWN, 0 },
18058
18059   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, 0, IX86_BUILTIN_CVTSD2SI, UNKNOWN, 0 },
18060   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, 0, IX86_BUILTIN_CVTTSD2SI, UNKNOWN, 0 },
18061   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, 0, IX86_BUILTIN_CVTSD2SI64, UNKNOWN, 0 },
18062   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, 0, IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, 0 },
18063
18064   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2dq, 0, IX86_BUILTIN_CVTPS2DQ, UNKNOWN, 0 },
18065   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, 0, IX86_BUILTIN_CVTPS2PD, UNKNOWN, 0 },
18066   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttps2dq, 0, IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, 0 },
18067
18068   /* SSE3 */
18069   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, 0 },
18070   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, 0 },
18071
18072   /* SSSE3 */
18073   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, 0 },
18074   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, 0 },
18075   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, 0 },
18076   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, 0 },
18077   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, 0 },
18078   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, 0 },
18079
18080   /* SSE4.1 */
18081   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv8qiv8hi2, 0, IX86_BUILTIN_PMOVSXBW128, UNKNOWN, 0 },
18082   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4qiv4si2, 0, IX86_BUILTIN_PMOVSXBD128, UNKNOWN, 0 },
18083   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2qiv2di2, 0, IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, 0 },
18084   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4hiv4si2, 0, IX86_BUILTIN_PMOVSXWD128, UNKNOWN, 0 },
18085   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2hiv2di2, 0, IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, 0 },
18086   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2siv2di2, 0, IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, 0 },
18087   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, 0, IX86_BUILTIN_PMOVZXBW128, UNKNOWN, 0 },
18088   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, 0, IX86_BUILTIN_PMOVZXBD128, UNKNOWN, 0 },
18089   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, 0, IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, 0 },
18090   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, 0, IX86_BUILTIN_PMOVZXWD128, UNKNOWN, 0 },
18091   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, 0, IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, 0 },
18092   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, 0, IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, 0 },
18093   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, 0 },
18094
18095   /* Fake 1 arg builtins with a constant smaller than 8 bits as the 2nd arg.  */
18096   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_roundpd, 0, IX86_BUILTIN_ROUNDPD, UNKNOWN, 0 },
18097   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_roundps, 0, IX86_BUILTIN_ROUNDPS, UNKNOWN, 0 },
18098 };
18099
18100 /* SSE5 */
18101 enum multi_arg_type {
18102   MULTI_ARG_UNKNOWN,
18103   MULTI_ARG_3_SF,
18104   MULTI_ARG_3_DF,
18105   MULTI_ARG_3_DI,
18106   MULTI_ARG_3_SI,
18107   MULTI_ARG_3_SI_DI,
18108   MULTI_ARG_3_HI,
18109   MULTI_ARG_3_HI_SI,
18110   MULTI_ARG_3_QI,
18111   MULTI_ARG_3_PERMPS,
18112   MULTI_ARG_3_PERMPD,
18113   MULTI_ARG_2_SF,
18114   MULTI_ARG_2_DF,
18115   MULTI_ARG_2_DI,
18116   MULTI_ARG_2_SI,
18117   MULTI_ARG_2_HI,
18118   MULTI_ARG_2_QI,
18119   MULTI_ARG_2_DI_IMM,
18120   MULTI_ARG_2_SI_IMM,
18121   MULTI_ARG_2_HI_IMM,
18122   MULTI_ARG_2_QI_IMM,
18123   MULTI_ARG_2_SF_CMP,
18124   MULTI_ARG_2_DF_CMP,
18125   MULTI_ARG_2_DI_CMP,
18126   MULTI_ARG_2_SI_CMP,
18127   MULTI_ARG_2_HI_CMP,
18128   MULTI_ARG_2_QI_CMP,
18129   MULTI_ARG_2_DI_TF,
18130   MULTI_ARG_2_SI_TF,
18131   MULTI_ARG_2_HI_TF,
18132   MULTI_ARG_2_QI_TF,
18133   MULTI_ARG_2_SF_TF,
18134   MULTI_ARG_2_DF_TF,
18135   MULTI_ARG_1_SF,
18136   MULTI_ARG_1_DF,
18137   MULTI_ARG_1_DI,
18138   MULTI_ARG_1_SI,
18139   MULTI_ARG_1_HI,
18140   MULTI_ARG_1_QI,
18141   MULTI_ARG_1_SI_DI,
18142   MULTI_ARG_1_HI_DI,
18143   MULTI_ARG_1_HI_SI,
18144   MULTI_ARG_1_QI_DI,
18145   MULTI_ARG_1_QI_SI,
18146   MULTI_ARG_1_QI_HI,
18147   MULTI_ARG_1_PH2PS,
18148   MULTI_ARG_1_PS2PH
18149 };
18150
18151 static const struct builtin_description bdesc_multi_arg[] =
18152 {
18153   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv4sf4,     "__builtin_ia32_fmaddss",    IX86_BUILTIN_FMADDSS,    0,            (int)MULTI_ARG_3_SF },
18154   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv2df4,     "__builtin_ia32_fmaddsd",    IX86_BUILTIN_FMADDSD,    0,            (int)MULTI_ARG_3_DF },
18155   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv4sf4,       "__builtin_ia32_fmaddps",    IX86_BUILTIN_FMADDPS,    0,            (int)MULTI_ARG_3_SF },
18156   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv2df4,       "__builtin_ia32_fmaddpd",    IX86_BUILTIN_FMADDPD,    0,            (int)MULTI_ARG_3_DF },
18157   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv4sf4,     "__builtin_ia32_fmsubss",    IX86_BUILTIN_FMSUBSS,    0,            (int)MULTI_ARG_3_SF },
18158   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv2df4,     "__builtin_ia32_fmsubsd",    IX86_BUILTIN_FMSUBSD,    0,            (int)MULTI_ARG_3_DF },
18159   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv4sf4,       "__builtin_ia32_fmsubps",    IX86_BUILTIN_FMSUBPS,    0,            (int)MULTI_ARG_3_SF },
18160   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv2df4,       "__builtin_ia32_fmsubpd",    IX86_BUILTIN_FMSUBPD,    0,            (int)MULTI_ARG_3_DF },
18161   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv4sf4,    "__builtin_ia32_fnmaddss",   IX86_BUILTIN_FNMADDSS,   0,            (int)MULTI_ARG_3_SF },
18162   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv2df4,    "__builtin_ia32_fnmaddsd",   IX86_BUILTIN_FNMADDSD,   0,            (int)MULTI_ARG_3_DF },
18163   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv4sf4,      "__builtin_ia32_fnmaddps",   IX86_BUILTIN_FNMADDPS,   0,            (int)MULTI_ARG_3_SF },
18164   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv2df4,      "__builtin_ia32_fnmaddpd",   IX86_BUILTIN_FNMADDPD,   0,            (int)MULTI_ARG_3_DF },
18165   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv4sf4,    "__builtin_ia32_fnmsubss",   IX86_BUILTIN_FNMSUBSS,   0,            (int)MULTI_ARG_3_SF },
18166   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv2df4,    "__builtin_ia32_fnmsubsd",   IX86_BUILTIN_FNMSUBSD,   0,            (int)MULTI_ARG_3_DF },
18167   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv4sf4,      "__builtin_ia32_fnmsubps",   IX86_BUILTIN_FNMSUBPS,   0,            (int)MULTI_ARG_3_SF },
18168   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv2df4,      "__builtin_ia32_fnmsubpd",   IX86_BUILTIN_FNMSUBPD,   0,            (int)MULTI_ARG_3_DF },
18169   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov",      IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
18170   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov_v2di", IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
18171   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4si,        "__builtin_ia32_pcmov_v4si", IX86_BUILTIN_PCMOV_V4SI, 0,            (int)MULTI_ARG_3_SI },
18172   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v8hi,        "__builtin_ia32_pcmov_v8hi", IX86_BUILTIN_PCMOV_V8HI, 0,            (int)MULTI_ARG_3_HI },
18173   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v16qi,       "__builtin_ia32_pcmov_v16qi",IX86_BUILTIN_PCMOV_V16QI,0,            (int)MULTI_ARG_3_QI },
18174   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2df,        "__builtin_ia32_pcmov_v2df", IX86_BUILTIN_PCMOV_V2DF, 0,            (int)MULTI_ARG_3_DF },
18175   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4sf,        "__builtin_ia32_pcmov_v4sf", IX86_BUILTIN_PCMOV_V4SF, 0,            (int)MULTI_ARG_3_SF },
18176   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pperm,             "__builtin_ia32_pperm",      IX86_BUILTIN_PPERM,      0,            (int)MULTI_ARG_3_QI },
18177   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv4sf,          "__builtin_ia32_permps",     IX86_BUILTIN_PERMPS,     0,            (int)MULTI_ARG_3_PERMPS },
18178   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv2df,          "__builtin_ia32_permpd",     IX86_BUILTIN_PERMPD,     0,            (int)MULTI_ARG_3_PERMPD },
18179   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssww,          "__builtin_ia32_pmacssww",   IX86_BUILTIN_PMACSSWW,   0,            (int)MULTI_ARG_3_HI },
18180   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsww,           "__builtin_ia32_pmacsww",    IX86_BUILTIN_PMACSWW,    0,            (int)MULTI_ARG_3_HI },
18181   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsswd,          "__builtin_ia32_pmacsswd",   IX86_BUILTIN_PMACSSWD,   0,            (int)MULTI_ARG_3_HI_SI },
18182   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacswd,           "__builtin_ia32_pmacswd",    IX86_BUILTIN_PMACSWD,    0,            (int)MULTI_ARG_3_HI_SI },
18183   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdd,          "__builtin_ia32_pmacssdd",   IX86_BUILTIN_PMACSSDD,   0,            (int)MULTI_ARG_3_SI },
18184   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdd,           "__builtin_ia32_pmacsdd",    IX86_BUILTIN_PMACSDD,    0,            (int)MULTI_ARG_3_SI },
18185   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdql,         "__builtin_ia32_pmacssdql",  IX86_BUILTIN_PMACSSDQL,  0,            (int)MULTI_ARG_3_SI_DI },
18186   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdqh,         "__builtin_ia32_pmacssdqh",  IX86_BUILTIN_PMACSSDQH,  0,            (int)MULTI_ARG_3_SI_DI },
18187   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdql,          "__builtin_ia32_pmacsdql",   IX86_BUILTIN_PMACSDQL,   0,            (int)MULTI_ARG_3_SI_DI },
18188   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdqh,          "__builtin_ia32_pmacsdqh",   IX86_BUILTIN_PMACSDQH,   0,            (int)MULTI_ARG_3_SI_DI },
18189   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcsswd,         "__builtin_ia32_pmadcsswd",  IX86_BUILTIN_PMADCSSWD,  0,            (int)MULTI_ARG_3_HI_SI },
18190   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcswd,          "__builtin_ia32_pmadcswd",   IX86_BUILTIN_PMADCSWD,   0,            (int)MULTI_ARG_3_HI_SI },
18191   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv2di3,         "__builtin_ia32_protq",      IX86_BUILTIN_PROTQ,      0,            (int)MULTI_ARG_2_DI },
18192   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv4si3,         "__builtin_ia32_protd",      IX86_BUILTIN_PROTD,      0,            (int)MULTI_ARG_2_SI },
18193   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv8hi3,         "__builtin_ia32_protw",      IX86_BUILTIN_PROTW,      0,            (int)MULTI_ARG_2_HI },
18194   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv16qi3,        "__builtin_ia32_protb",      IX86_BUILTIN_PROTB,      0,            (int)MULTI_ARG_2_QI },
18195   { OPTION_MASK_ISA_SSE5, CODE_FOR_rotlv2di3,              "__builtin_ia32_protqi",     IX86_BUILTIN_PROTQ_IMM,  0,            (int)MULTI_ARG_2_DI_IMM },
18196   { OPTION_MASK_ISA_SSE5, CODE_FOR_rotlv4si3,              "__builtin_ia32_protdi",     IX86_BUILTIN_PROTD_IMM,  0,            (int)MULTI_ARG_2_SI_IMM },
18197   { OPTION_MASK_ISA_SSE5, CODE_FOR_rotlv8hi3,              "__builtin_ia32_protwi",     IX86_BUILTIN_PROTW_IMM,  0,            (int)MULTI_ARG_2_HI_IMM },
18198   { OPTION_MASK_ISA_SSE5, CODE_FOR_rotlv16qi3,             "__builtin_ia32_protbi",     IX86_BUILTIN_PROTB_IMM,  0,            (int)MULTI_ARG_2_QI_IMM },
18199   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv2di3,         "__builtin_ia32_pshaq",      IX86_BUILTIN_PSHAQ,      0,            (int)MULTI_ARG_2_DI },
18200   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv4si3,         "__builtin_ia32_pshad",      IX86_BUILTIN_PSHAD,      0,            (int)MULTI_ARG_2_SI },
18201   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv8hi3,         "__builtin_ia32_pshaw",      IX86_BUILTIN_PSHAW,      0,            (int)MULTI_ARG_2_HI },
18202   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv16qi3,        "__builtin_ia32_pshab",      IX86_BUILTIN_PSHAB,      0,            (int)MULTI_ARG_2_QI },
18203   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv2di3,         "__builtin_ia32_pshlq",      IX86_BUILTIN_PSHLQ,      0,            (int)MULTI_ARG_2_DI },
18204   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv4si3,         "__builtin_ia32_pshld",      IX86_BUILTIN_PSHLD,      0,            (int)MULTI_ARG_2_SI },
18205   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv8hi3,         "__builtin_ia32_pshlw",      IX86_BUILTIN_PSHLW,      0,            (int)MULTI_ARG_2_HI },
18206   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv16qi3,        "__builtin_ia32_pshlb",      IX86_BUILTIN_PSHLB,      0,            (int)MULTI_ARG_2_QI },
18207   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv4sf2,       "__builtin_ia32_frczss",     IX86_BUILTIN_FRCZSS,     0,            (int)MULTI_ARG_2_SF },
18208   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv2df2,       "__builtin_ia32_frczsd",     IX86_BUILTIN_FRCZSD,     0,            (int)MULTI_ARG_2_DF },
18209   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv4sf2,         "__builtin_ia32_frczps",     IX86_BUILTIN_FRCZPS,     0,            (int)MULTI_ARG_1_SF },
18210   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv2df2,         "__builtin_ia32_frczpd",     IX86_BUILTIN_FRCZPD,     0,            (int)MULTI_ARG_1_DF },
18211   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtph2ps,          "__builtin_ia32_cvtph2ps",   IX86_BUILTIN_CVTPH2PS,   0,            (int)MULTI_ARG_1_PH2PS },
18212   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtps2ph,          "__builtin_ia32_cvtps2ph",   IX86_BUILTIN_CVTPS2PH,   0,            (int)MULTI_ARG_1_PS2PH },
18213   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbw,           "__builtin_ia32_phaddbw",    IX86_BUILTIN_PHADDBW,    0,            (int)MULTI_ARG_1_QI_HI },
18214   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbd,           "__builtin_ia32_phaddbd",    IX86_BUILTIN_PHADDBD,    0,            (int)MULTI_ARG_1_QI_SI },
18215   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbq,           "__builtin_ia32_phaddbq",    IX86_BUILTIN_PHADDBQ,    0,            (int)MULTI_ARG_1_QI_DI },
18216   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwd,           "__builtin_ia32_phaddwd",    IX86_BUILTIN_PHADDWD,    0,            (int)MULTI_ARG_1_HI_SI },
18217   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwq,           "__builtin_ia32_phaddwq",    IX86_BUILTIN_PHADDWQ,    0,            (int)MULTI_ARG_1_HI_DI },
18218   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadddq,           "__builtin_ia32_phadddq",    IX86_BUILTIN_PHADDDQ,    0,            (int)MULTI_ARG_1_SI_DI },
18219   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubw,          "__builtin_ia32_phaddubw",   IX86_BUILTIN_PHADDUBW,   0,            (int)MULTI_ARG_1_QI_HI },
18220   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubd,          "__builtin_ia32_phaddubd",   IX86_BUILTIN_PHADDUBD,   0,            (int)MULTI_ARG_1_QI_SI },
18221   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubq,          "__builtin_ia32_phaddubq",   IX86_BUILTIN_PHADDUBQ,   0,            (int)MULTI_ARG_1_QI_DI },
18222   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwd,          "__builtin_ia32_phadduwd",   IX86_BUILTIN_PHADDUWD,   0,            (int)MULTI_ARG_1_HI_SI },
18223   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwq,          "__builtin_ia32_phadduwq",   IX86_BUILTIN_PHADDUWQ,   0,            (int)MULTI_ARG_1_HI_DI },
18224   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddudq,          "__builtin_ia32_phaddudq",   IX86_BUILTIN_PHADDUDQ,   0,            (int)MULTI_ARG_1_SI_DI },
18225   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubbw,           "__builtin_ia32_phsubbw",    IX86_BUILTIN_PHSUBBW,    0,            (int)MULTI_ARG_1_QI_HI },
18226   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubwd,           "__builtin_ia32_phsubwd",    IX86_BUILTIN_PHSUBWD,    0,            (int)MULTI_ARG_1_HI_SI },
18227   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubdq,           "__builtin_ia32_phsubdq",    IX86_BUILTIN_PHSUBDQ,    0,            (int)MULTI_ARG_1_SI_DI },
18228
18229   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comeqss",    IX86_BUILTIN_COMEQSS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
18230   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comness",    IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
18231   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comneqss",   IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
18232   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comltss",    IX86_BUILTIN_COMLTSS,    LT,           (int)MULTI_ARG_2_SF_CMP },
18233   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comless",    IX86_BUILTIN_COMLESS,    LE,           (int)MULTI_ARG_2_SF_CMP },
18234   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgtss",    IX86_BUILTIN_COMGTSS,    GT,           (int)MULTI_ARG_2_SF_CMP },
18235   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgess",    IX86_BUILTIN_COMGESS,    GE,           (int)MULTI_ARG_2_SF_CMP },
18236   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comueqss",   IX86_BUILTIN_COMUEQSS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
18237   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuness",   IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
18238   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuneqss",  IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
18239   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunltss",  IX86_BUILTIN_COMULTSS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
18240   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunless",  IX86_BUILTIN_COMULESS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
18241   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungtss",  IX86_BUILTIN_COMUGTSS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
18242   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungess",  IX86_BUILTIN_COMUGESS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
18243   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comordss",   IX86_BUILTIN_COMORDSS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
18244   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunordss", IX86_BUILTIN_COMUNORDSS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
18245
18246   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comeqsd",    IX86_BUILTIN_COMEQSD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
18247   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comnesd",    IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
18248   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comneqsd",   IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
18249   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comltsd",    IX86_BUILTIN_COMLTSD,    LT,           (int)MULTI_ARG_2_DF_CMP },
18250   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comlesd",    IX86_BUILTIN_COMLESD,    LE,           (int)MULTI_ARG_2_DF_CMP },
18251   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgtsd",    IX86_BUILTIN_COMGTSD,    GT,           (int)MULTI_ARG_2_DF_CMP },
18252   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgesd",    IX86_BUILTIN_COMGESD,    GE,           (int)MULTI_ARG_2_DF_CMP },
18253   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comueqsd",   IX86_BUILTIN_COMUEQSD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
18254   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunesd",   IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
18255   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comuneqsd",  IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
18256   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunltsd",  IX86_BUILTIN_COMULTSD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
18257   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunlesd",  IX86_BUILTIN_COMULESD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
18258   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungtsd",  IX86_BUILTIN_COMUGTSD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
18259   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungesd",  IX86_BUILTIN_COMUGESD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
18260   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comordsd",   IX86_BUILTIN_COMORDSD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
18261   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunordsd", IX86_BUILTIN_COMUNORDSD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
18262
18263   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comeqps",    IX86_BUILTIN_COMEQPS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
18264   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneps",    IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
18265   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneqps",   IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
18266   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comltps",    IX86_BUILTIN_COMLTPS,    LT,           (int)MULTI_ARG_2_SF_CMP },
18267   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comleps",    IX86_BUILTIN_COMLEPS,    LE,           (int)MULTI_ARG_2_SF_CMP },
18268   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgtps",    IX86_BUILTIN_COMGTPS,    GT,           (int)MULTI_ARG_2_SF_CMP },
18269   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgeps",    IX86_BUILTIN_COMGEPS,    GE,           (int)MULTI_ARG_2_SF_CMP },
18270   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comueqps",   IX86_BUILTIN_COMUEQPS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
18271   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneps",   IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
18272   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneqps",  IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
18273   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunltps",  IX86_BUILTIN_COMULTPS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
18274   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunleps",  IX86_BUILTIN_COMULEPS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
18275   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungtps",  IX86_BUILTIN_COMUGTPS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
18276   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungeps",  IX86_BUILTIN_COMUGEPS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
18277   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comordps",   IX86_BUILTIN_COMORDPS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
18278   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunordps", IX86_BUILTIN_COMUNORDPS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
18279
18280   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comeqpd",    IX86_BUILTIN_COMEQPD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
18281   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comnepd",    IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
18282   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comneqpd",   IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
18283   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comltpd",    IX86_BUILTIN_COMLTPD,    LT,           (int)MULTI_ARG_2_DF_CMP },
18284   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comlepd",    IX86_BUILTIN_COMLEPD,    LE,           (int)MULTI_ARG_2_DF_CMP },
18285   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgtpd",    IX86_BUILTIN_COMGTPD,    GT,           (int)MULTI_ARG_2_DF_CMP },
18286   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgepd",    IX86_BUILTIN_COMGEPD,    GE,           (int)MULTI_ARG_2_DF_CMP },
18287   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comueqpd",   IX86_BUILTIN_COMUEQPD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
18288   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunepd",   IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
18289   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comuneqpd",  IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
18290   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunltpd",  IX86_BUILTIN_COMULTPD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
18291   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunlepd",  IX86_BUILTIN_COMULEPD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
18292   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungtpd",  IX86_BUILTIN_COMUGTPD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
18293   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungepd",  IX86_BUILTIN_COMUGEPD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
18294   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comordpd",   IX86_BUILTIN_COMORDPD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
18295   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunordpd", IX86_BUILTIN_COMUNORDPD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
18296
18297   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomeqb",    IX86_BUILTIN_PCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
18298   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneb",    IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
18299   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneqb",   IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
18300   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomltb",    IX86_BUILTIN_PCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
18301   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomleb",    IX86_BUILTIN_PCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
18302   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgtb",    IX86_BUILTIN_PCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
18303   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgeb",    IX86_BUILTIN_PCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
18304
18305   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomeqw",    IX86_BUILTIN_PCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
18306   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomnew",    IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
18307   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomneqw",   IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
18308   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomltw",    IX86_BUILTIN_PCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
18309   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomlew",    IX86_BUILTIN_PCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
18310   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgtw",    IX86_BUILTIN_PCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
18311   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgew",    IX86_BUILTIN_PCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
18312
18313   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomeqd",    IX86_BUILTIN_PCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
18314   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomned",    IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
18315   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomneqd",   IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
18316   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomltd",    IX86_BUILTIN_PCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
18317   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomled",    IX86_BUILTIN_PCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
18318   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomgtd",    IX86_BUILTIN_PCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
18319   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomged",    IX86_BUILTIN_PCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
18320
18321   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomeqq",    IX86_BUILTIN_PCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
18322   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneq",    IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
18323   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneqq",   IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
18324   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomltq",    IX86_BUILTIN_PCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
18325   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomleq",    IX86_BUILTIN_PCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
18326   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgtq",    IX86_BUILTIN_PCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
18327   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgeq",    IX86_BUILTIN_PCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
18328
18329   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomequb",   IX86_BUILTIN_PCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
18330   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomneub",   IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
18331   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomnequb",  IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
18332   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomltub",   IX86_BUILTIN_PCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
18333   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomleub",   IX86_BUILTIN_PCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
18334   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgtub",   IX86_BUILTIN_PCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
18335   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgeub",   IX86_BUILTIN_PCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
18336
18337   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomequw",   IX86_BUILTIN_PCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
18338   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomneuw",   IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
18339   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomnequw",  IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
18340   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomltuw",   IX86_BUILTIN_PCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
18341   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomleuw",   IX86_BUILTIN_PCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
18342   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgtuw",   IX86_BUILTIN_PCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
18343   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgeuw",   IX86_BUILTIN_PCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
18344
18345   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomequd",   IX86_BUILTIN_PCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
18346   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomneud",   IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
18347   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomnequd",  IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
18348   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomltud",   IX86_BUILTIN_PCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
18349   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomleud",   IX86_BUILTIN_PCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
18350   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgtud",   IX86_BUILTIN_PCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
18351   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgeud",   IX86_BUILTIN_PCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
18352
18353   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomequq",   IX86_BUILTIN_PCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
18354   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomneuq",   IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
18355   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomnequq",  IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
18356   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomltuq",   IX86_BUILTIN_PCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
18357   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomleuq",   IX86_BUILTIN_PCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
18358   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgtuq",   IX86_BUILTIN_PCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
18359   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgeuq",   IX86_BUILTIN_PCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
18360
18361   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalsess", IX86_BUILTIN_COMFALSESS, COM_FALSE_S,  (int)MULTI_ARG_2_SF_TF },
18362   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtruess",  IX86_BUILTIN_COMTRUESS,  COM_TRUE_S,   (int)MULTI_ARG_2_SF_TF },
18363   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalseps", IX86_BUILTIN_COMFALSEPS, COM_FALSE_P,  (int)MULTI_ARG_2_SF_TF },
18364   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtrueps",  IX86_BUILTIN_COMTRUEPS,  COM_TRUE_P,   (int)MULTI_ARG_2_SF_TF },
18365   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsesd", IX86_BUILTIN_COMFALSESD, COM_FALSE_S,  (int)MULTI_ARG_2_DF_TF },
18366   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruesd",  IX86_BUILTIN_COMTRUESD,  COM_TRUE_S,   (int)MULTI_ARG_2_DF_TF },
18367   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsepd", IX86_BUILTIN_COMFALSEPD, COM_FALSE_P,  (int)MULTI_ARG_2_DF_TF },
18368   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruepd",  IX86_BUILTIN_COMTRUEPD,  COM_TRUE_P,   (int)MULTI_ARG_2_DF_TF },
18369
18370   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseb", IX86_BUILTIN_PCOMFALSEB, PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
18371   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalsew", IX86_BUILTIN_PCOMFALSEW, PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
18372   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalsed", IX86_BUILTIN_PCOMFALSED, PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
18373   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseq", IX86_BUILTIN_PCOMFALSEQ, PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
18374   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseub",IX86_BUILTIN_PCOMFALSEUB,PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
18375   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalseuw",IX86_BUILTIN_PCOMFALSEUW,PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
18376   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalseud",IX86_BUILTIN_PCOMFALSEUD,PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
18377   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseuq",IX86_BUILTIN_PCOMFALSEUQ,PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
18378
18379   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueb",  IX86_BUILTIN_PCOMTRUEB,  PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
18380   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtruew",  IX86_BUILTIN_PCOMTRUEW,  PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
18381   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrued",  IX86_BUILTIN_PCOMTRUED,  PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
18382   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueq",  IX86_BUILTIN_PCOMTRUEQ,  PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
18383   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueub", IX86_BUILTIN_PCOMTRUEUB, PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
18384   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtrueuw", IX86_BUILTIN_PCOMTRUEUW, PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
18385   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrueud", IX86_BUILTIN_PCOMTRUEUD, PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
18386   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueuq", IX86_BUILTIN_PCOMTRUEUQ, PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
18387 };
18388
18389 /* Set up all the MMX/SSE builtins.  This is not called if TARGET_MMX
18390    is zero.  Otherwise, if TARGET_SSE is not set, only expand the MMX
18391    builtins.  */
18392 static void
18393 ix86_init_mmx_sse_builtins (void)
18394 {
18395   const struct builtin_description * d;
18396   size_t i;
18397
18398   tree V16QI_type_node = build_vector_type_for_mode (char_type_node, V16QImode);
18399   tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
18400   tree V2SF_type_node = build_vector_type_for_mode (float_type_node, V2SFmode);
18401   tree V2DI_type_node
18402     = build_vector_type_for_mode (long_long_integer_type_node, V2DImode);
18403   tree V2DF_type_node = build_vector_type_for_mode (double_type_node, V2DFmode);
18404   tree V4SF_type_node = build_vector_type_for_mode (float_type_node, V4SFmode);
18405   tree V4SI_type_node = build_vector_type_for_mode (intSI_type_node, V4SImode);
18406   tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
18407   tree V8QI_type_node = build_vector_type_for_mode (char_type_node, V8QImode);
18408   tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, V8HImode);
18409
18410   tree pchar_type_node = build_pointer_type (char_type_node);
18411   tree pcchar_type_node = build_pointer_type (
18412                              build_type_variant (char_type_node, 1, 0));
18413   tree pfloat_type_node = build_pointer_type (float_type_node);
18414   tree pcfloat_type_node = build_pointer_type (
18415                              build_type_variant (float_type_node, 1, 0));
18416   tree pv2si_type_node = build_pointer_type (V2SI_type_node);
18417   tree pv2di_type_node = build_pointer_type (V2DI_type_node);
18418   tree pdi_type_node = build_pointer_type (long_long_unsigned_type_node);
18419
18420   /* Comparisons.  */
18421   tree int_ftype_v4sf_v4sf
18422     = build_function_type_list (integer_type_node,
18423                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
18424   tree v4si_ftype_v4sf_v4sf
18425     = build_function_type_list (V4SI_type_node,
18426                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
18427   /* MMX/SSE/integer conversions.  */
18428   tree int_ftype_v4sf
18429     = build_function_type_list (integer_type_node,
18430                                 V4SF_type_node, NULL_TREE);
18431   tree int64_ftype_v4sf
18432     = build_function_type_list (long_long_integer_type_node,
18433                                 V4SF_type_node, NULL_TREE);
18434   tree int_ftype_v8qi
18435     = build_function_type_list (integer_type_node, V8QI_type_node, NULL_TREE);
18436   tree v4sf_ftype_v4sf_int
18437     = build_function_type_list (V4SF_type_node,
18438                                 V4SF_type_node, integer_type_node, NULL_TREE);
18439   tree v4sf_ftype_v4sf_int64
18440     = build_function_type_list (V4SF_type_node,
18441                                 V4SF_type_node, long_long_integer_type_node,
18442                                 NULL_TREE);
18443   tree v4sf_ftype_v4sf_v2si
18444     = build_function_type_list (V4SF_type_node,
18445                                 V4SF_type_node, V2SI_type_node, NULL_TREE);
18446
18447   /* Miscellaneous.  */
18448   tree v8qi_ftype_v4hi_v4hi
18449     = build_function_type_list (V8QI_type_node,
18450                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
18451   tree v4hi_ftype_v2si_v2si
18452     = build_function_type_list (V4HI_type_node,
18453                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
18454   tree v4sf_ftype_v4sf_v4sf_int
18455     = build_function_type_list (V4SF_type_node,
18456                                 V4SF_type_node, V4SF_type_node,
18457                                 integer_type_node, NULL_TREE);
18458   tree v2si_ftype_v4hi_v4hi
18459     = build_function_type_list (V2SI_type_node,
18460                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
18461   tree v4hi_ftype_v4hi_int
18462     = build_function_type_list (V4HI_type_node,
18463                                 V4HI_type_node, integer_type_node, NULL_TREE);
18464   tree v4hi_ftype_v4hi_di
18465     = build_function_type_list (V4HI_type_node,
18466                                 V4HI_type_node, long_long_unsigned_type_node,
18467                                 NULL_TREE);
18468   tree v2si_ftype_v2si_di
18469     = build_function_type_list (V2SI_type_node,
18470                                 V2SI_type_node, long_long_unsigned_type_node,
18471                                 NULL_TREE);
18472   tree void_ftype_void
18473     = build_function_type (void_type_node, void_list_node);
18474   tree void_ftype_unsigned
18475     = build_function_type_list (void_type_node, unsigned_type_node, NULL_TREE);
18476   tree void_ftype_unsigned_unsigned
18477     = build_function_type_list (void_type_node, unsigned_type_node,
18478                                 unsigned_type_node, NULL_TREE);
18479   tree void_ftype_pcvoid_unsigned_unsigned
18480     = build_function_type_list (void_type_node, const_ptr_type_node,
18481                                 unsigned_type_node, unsigned_type_node,
18482                                 NULL_TREE);
18483   tree unsigned_ftype_void
18484     = build_function_type (unsigned_type_node, void_list_node);
18485   tree v2si_ftype_v4sf
18486     = build_function_type_list (V2SI_type_node, V4SF_type_node, NULL_TREE);
18487   /* Loads/stores.  */
18488   tree void_ftype_v8qi_v8qi_pchar
18489     = build_function_type_list (void_type_node,
18490                                 V8QI_type_node, V8QI_type_node,
18491                                 pchar_type_node, NULL_TREE);
18492   tree v4sf_ftype_pcfloat
18493     = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
18494   /* @@@ the type is bogus */
18495   tree v4sf_ftype_v4sf_pv2si
18496     = build_function_type_list (V4SF_type_node,
18497                                 V4SF_type_node, pv2si_type_node, NULL_TREE);
18498   tree void_ftype_pv2si_v4sf
18499     = build_function_type_list (void_type_node,
18500                                 pv2si_type_node, V4SF_type_node, NULL_TREE);
18501   tree void_ftype_pfloat_v4sf
18502     = build_function_type_list (void_type_node,
18503                                 pfloat_type_node, V4SF_type_node, NULL_TREE);
18504   tree void_ftype_pdi_di
18505     = build_function_type_list (void_type_node,
18506                                 pdi_type_node, long_long_unsigned_type_node,
18507                                 NULL_TREE);
18508   tree void_ftype_pv2di_v2di
18509     = build_function_type_list (void_type_node,
18510                                 pv2di_type_node, V2DI_type_node, NULL_TREE);
18511   /* Normal vector unops.  */
18512   tree v4sf_ftype_v4sf
18513     = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
18514   tree v16qi_ftype_v16qi
18515     = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
18516   tree v8hi_ftype_v8hi
18517     = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
18518   tree v4si_ftype_v4si
18519     = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
18520   tree v8qi_ftype_v8qi
18521     = build_function_type_list (V8QI_type_node, V8QI_type_node, NULL_TREE);
18522   tree v4hi_ftype_v4hi
18523     = build_function_type_list (V4HI_type_node, V4HI_type_node, NULL_TREE);
18524
18525   /* Normal vector binops.  */
18526   tree v4sf_ftype_v4sf_v4sf
18527     = build_function_type_list (V4SF_type_node,
18528                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
18529   tree v8qi_ftype_v8qi_v8qi
18530     = build_function_type_list (V8QI_type_node,
18531                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
18532   tree v4hi_ftype_v4hi_v4hi
18533     = build_function_type_list (V4HI_type_node,
18534                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
18535   tree v2si_ftype_v2si_v2si
18536     = build_function_type_list (V2SI_type_node,
18537                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
18538   tree di_ftype_di_di
18539     = build_function_type_list (long_long_unsigned_type_node,
18540                                 long_long_unsigned_type_node,
18541                                 long_long_unsigned_type_node, NULL_TREE);
18542
18543   tree di_ftype_di_di_int
18544     = build_function_type_list (long_long_unsigned_type_node,
18545                                 long_long_unsigned_type_node,
18546                                 long_long_unsigned_type_node,
18547                                 integer_type_node, NULL_TREE);
18548
18549   tree v2si_ftype_v2sf
18550     = build_function_type_list (V2SI_type_node, V2SF_type_node, NULL_TREE);
18551   tree v2sf_ftype_v2si
18552     = build_function_type_list (V2SF_type_node, V2SI_type_node, NULL_TREE);
18553   tree v2si_ftype_v2si
18554     = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
18555   tree v2sf_ftype_v2sf
18556     = build_function_type_list (V2SF_type_node, V2SF_type_node, NULL_TREE);
18557   tree v2sf_ftype_v2sf_v2sf
18558     = build_function_type_list (V2SF_type_node,
18559                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
18560   tree v2si_ftype_v2sf_v2sf
18561     = build_function_type_list (V2SI_type_node,
18562                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
18563   tree pint_type_node    = build_pointer_type (integer_type_node);
18564   tree pdouble_type_node = build_pointer_type (double_type_node);
18565   tree pcdouble_type_node = build_pointer_type (
18566                                 build_type_variant (double_type_node, 1, 0));
18567   tree int_ftype_v2df_v2df
18568     = build_function_type_list (integer_type_node,
18569                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
18570
18571   tree void_ftype_pcvoid
18572     = build_function_type_list (void_type_node, const_ptr_type_node, NULL_TREE);
18573   tree v4sf_ftype_v4si
18574     = build_function_type_list (V4SF_type_node, V4SI_type_node, NULL_TREE);
18575   tree v4si_ftype_v4sf
18576     = build_function_type_list (V4SI_type_node, V4SF_type_node, NULL_TREE);
18577   tree v2df_ftype_v4si
18578     = build_function_type_list (V2DF_type_node, V4SI_type_node, NULL_TREE);
18579   tree v4si_ftype_v2df
18580     = build_function_type_list (V4SI_type_node, V2DF_type_node, NULL_TREE);
18581   tree v4si_ftype_v2df_v2df
18582     = build_function_type_list (V4SI_type_node,
18583                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
18584   tree v2si_ftype_v2df
18585     = build_function_type_list (V2SI_type_node, V2DF_type_node, NULL_TREE);
18586   tree v4sf_ftype_v2df
18587     = build_function_type_list (V4SF_type_node, V2DF_type_node, NULL_TREE);
18588   tree v2df_ftype_v2si
18589     = build_function_type_list (V2DF_type_node, V2SI_type_node, NULL_TREE);
18590   tree v2df_ftype_v4sf
18591     = build_function_type_list (V2DF_type_node, V4SF_type_node, NULL_TREE);
18592   tree int_ftype_v2df
18593     = build_function_type_list (integer_type_node, V2DF_type_node, NULL_TREE);
18594   tree int64_ftype_v2df
18595     = build_function_type_list (long_long_integer_type_node,
18596                                 V2DF_type_node, NULL_TREE);
18597   tree v2df_ftype_v2df_int
18598     = build_function_type_list (V2DF_type_node,
18599                                 V2DF_type_node, integer_type_node, NULL_TREE);
18600   tree v2df_ftype_v2df_int64
18601     = build_function_type_list (V2DF_type_node,
18602                                 V2DF_type_node, long_long_integer_type_node,
18603                                 NULL_TREE);
18604   tree v4sf_ftype_v4sf_v2df
18605     = build_function_type_list (V4SF_type_node,
18606                                 V4SF_type_node, V2DF_type_node, NULL_TREE);
18607   tree v2df_ftype_v2df_v4sf
18608     = build_function_type_list (V2DF_type_node,
18609                                 V2DF_type_node, V4SF_type_node, NULL_TREE);
18610   tree v2df_ftype_v2df_v2df_int
18611     = build_function_type_list (V2DF_type_node,
18612                                 V2DF_type_node, V2DF_type_node,
18613                                 integer_type_node,
18614                                 NULL_TREE);
18615   tree v2df_ftype_v2df_pcdouble
18616     = build_function_type_list (V2DF_type_node,
18617                                 V2DF_type_node, pcdouble_type_node, NULL_TREE);
18618   tree void_ftype_pdouble_v2df
18619     = build_function_type_list (void_type_node,
18620                                 pdouble_type_node, V2DF_type_node, NULL_TREE);
18621   tree void_ftype_pint_int
18622     = build_function_type_list (void_type_node,
18623                                 pint_type_node, integer_type_node, NULL_TREE);
18624   tree void_ftype_v16qi_v16qi_pchar
18625     = build_function_type_list (void_type_node,
18626                                 V16QI_type_node, V16QI_type_node,
18627                                 pchar_type_node, NULL_TREE);
18628   tree v2df_ftype_pcdouble
18629     = build_function_type_list (V2DF_type_node, pcdouble_type_node, NULL_TREE);
18630   tree v2df_ftype_v2df_v2df
18631     = build_function_type_list (V2DF_type_node,
18632                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
18633   tree v16qi_ftype_v16qi_v16qi
18634     = build_function_type_list (V16QI_type_node,
18635                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
18636   tree v8hi_ftype_v8hi_v8hi
18637     = build_function_type_list (V8HI_type_node,
18638                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
18639   tree v4si_ftype_v4si_v4si
18640     = build_function_type_list (V4SI_type_node,
18641                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
18642   tree v2di_ftype_v2di_v2di
18643     = build_function_type_list (V2DI_type_node,
18644                                 V2DI_type_node, V2DI_type_node, NULL_TREE);
18645   tree v2di_ftype_v2df_v2df
18646     = build_function_type_list (V2DI_type_node,
18647                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
18648   tree v2df_ftype_v2df
18649     = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
18650   tree v2di_ftype_v2di_int
18651     = build_function_type_list (V2DI_type_node,
18652                                 V2DI_type_node, integer_type_node, NULL_TREE);
18653   tree v2di_ftype_v2di_v2di_int
18654     = build_function_type_list (V2DI_type_node, V2DI_type_node,
18655                                 V2DI_type_node, integer_type_node, NULL_TREE);
18656   tree v4si_ftype_v4si_int
18657     = build_function_type_list (V4SI_type_node,
18658                                 V4SI_type_node, integer_type_node, NULL_TREE);
18659   tree v8hi_ftype_v8hi_int
18660     = build_function_type_list (V8HI_type_node,
18661                                 V8HI_type_node, integer_type_node, NULL_TREE);
18662   tree v4si_ftype_v8hi_v8hi
18663     = build_function_type_list (V4SI_type_node,
18664                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
18665   tree di_ftype_v8qi_v8qi
18666     = build_function_type_list (long_long_unsigned_type_node,
18667                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
18668   tree di_ftype_v2si_v2si
18669     = build_function_type_list (long_long_unsigned_type_node,
18670                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
18671   tree v2di_ftype_v16qi_v16qi
18672     = build_function_type_list (V2DI_type_node,
18673                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
18674   tree v2di_ftype_v4si_v4si
18675     = build_function_type_list (V2DI_type_node,
18676                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
18677   tree int_ftype_v16qi
18678     = build_function_type_list (integer_type_node, V16QI_type_node, NULL_TREE);
18679   tree v16qi_ftype_pcchar
18680     = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
18681   tree void_ftype_pchar_v16qi
18682     = build_function_type_list (void_type_node,
18683                                 pchar_type_node, V16QI_type_node, NULL_TREE);
18684
18685   tree v2di_ftype_v2di_unsigned_unsigned
18686     = build_function_type_list (V2DI_type_node, V2DI_type_node,
18687                                 unsigned_type_node, unsigned_type_node,
18688                                 NULL_TREE);
18689   tree v2di_ftype_v2di_v2di_unsigned_unsigned
18690     = build_function_type_list (V2DI_type_node, V2DI_type_node, V2DI_type_node,
18691                                 unsigned_type_node, unsigned_type_node,
18692                                 NULL_TREE);
18693   tree v2di_ftype_v2di_v16qi
18694     = build_function_type_list (V2DI_type_node, V2DI_type_node, V16QI_type_node,
18695                                 NULL_TREE);
18696   tree v2df_ftype_v2df_v2df_v2df
18697     = build_function_type_list (V2DF_type_node,
18698                                 V2DF_type_node, V2DF_type_node,
18699                                 V2DF_type_node, NULL_TREE);
18700   tree v4sf_ftype_v4sf_v4sf_v4sf
18701     = build_function_type_list (V4SF_type_node,
18702                                 V4SF_type_node, V4SF_type_node,
18703                                 V4SF_type_node, NULL_TREE);
18704   tree v8hi_ftype_v16qi
18705     = build_function_type_list (V8HI_type_node, V16QI_type_node,
18706                                 NULL_TREE);
18707   tree v4si_ftype_v16qi
18708     = build_function_type_list (V4SI_type_node, V16QI_type_node,
18709                                 NULL_TREE);
18710   tree v2di_ftype_v16qi
18711     = build_function_type_list (V2DI_type_node, V16QI_type_node,
18712                                 NULL_TREE);
18713   tree v4si_ftype_v8hi
18714     = build_function_type_list (V4SI_type_node, V8HI_type_node,
18715                                 NULL_TREE);
18716   tree v2di_ftype_v8hi
18717     = build_function_type_list (V2DI_type_node, V8HI_type_node,
18718                                 NULL_TREE);
18719   tree v2di_ftype_v4si
18720     = build_function_type_list (V2DI_type_node, V4SI_type_node,
18721                                 NULL_TREE);
18722   tree v2di_ftype_pv2di
18723     = build_function_type_list (V2DI_type_node, pv2di_type_node,
18724                                 NULL_TREE);
18725   tree v16qi_ftype_v16qi_v16qi_int
18726     = build_function_type_list (V16QI_type_node, V16QI_type_node,
18727                                 V16QI_type_node, integer_type_node,
18728                                 NULL_TREE);
18729   tree v16qi_ftype_v16qi_v16qi_v16qi
18730     = build_function_type_list (V16QI_type_node, V16QI_type_node,
18731                                 V16QI_type_node, V16QI_type_node,
18732                                 NULL_TREE);
18733   tree v8hi_ftype_v8hi_v8hi_int
18734     = build_function_type_list (V8HI_type_node, V8HI_type_node,
18735                                 V8HI_type_node, integer_type_node,
18736                                 NULL_TREE);
18737   tree v4si_ftype_v4si_v4si_int
18738     = build_function_type_list (V4SI_type_node, V4SI_type_node,
18739                                 V4SI_type_node, integer_type_node,
18740                                 NULL_TREE);
18741   tree int_ftype_v2di_v2di
18742     = build_function_type_list (integer_type_node,
18743                                 V2DI_type_node, V2DI_type_node,
18744                                 NULL_TREE);
18745   tree int_ftype_v16qi_int_v16qi_int_int
18746     = build_function_type_list (integer_type_node,
18747                                 V16QI_type_node,
18748                                 integer_type_node,
18749                                 V16QI_type_node,
18750                                 integer_type_node,
18751                                 integer_type_node,
18752                                 NULL_TREE);
18753   tree v16qi_ftype_v16qi_int_v16qi_int_int
18754     = build_function_type_list (V16QI_type_node,
18755                                 V16QI_type_node,
18756                                 integer_type_node,
18757                                 V16QI_type_node,
18758                                 integer_type_node,
18759                                 integer_type_node,
18760                                 NULL_TREE);
18761   tree int_ftype_v16qi_v16qi_int
18762     = build_function_type_list (integer_type_node,
18763                                 V16QI_type_node,
18764                                 V16QI_type_node,
18765                                 integer_type_node,
18766                                 NULL_TREE);
18767
18768   /* SSE5 instructions */
18769   tree v2di_ftype_v2di_v2di_v2di
18770     = build_function_type_list (V2DI_type_node,
18771                                 V2DI_type_node,
18772                                 V2DI_type_node,
18773                                 V2DI_type_node,
18774                                 NULL_TREE);
18775
18776   tree v4si_ftype_v4si_v4si_v4si
18777     = build_function_type_list (V4SI_type_node,
18778                                 V4SI_type_node,
18779                                 V4SI_type_node,
18780                                 V4SI_type_node,
18781                                 NULL_TREE);
18782
18783   tree v4si_ftype_v4si_v4si_v2di
18784     = build_function_type_list (V4SI_type_node,
18785                                 V4SI_type_node,
18786                                 V4SI_type_node,
18787                                 V2DI_type_node,
18788                                 NULL_TREE);
18789
18790   tree v8hi_ftype_v8hi_v8hi_v8hi
18791     = build_function_type_list (V8HI_type_node,
18792                                 V8HI_type_node,
18793                                 V8HI_type_node,
18794                                 V8HI_type_node,
18795                                 NULL_TREE);
18796
18797   tree v8hi_ftype_v8hi_v8hi_v4si
18798     = build_function_type_list (V8HI_type_node,
18799                                 V8HI_type_node,
18800                                 V8HI_type_node,
18801                                 V4SI_type_node,
18802                                 NULL_TREE);
18803
18804   tree v2df_ftype_v2df_v2df_v16qi
18805     = build_function_type_list (V2DF_type_node,
18806                                 V2DF_type_node,
18807                                 V2DF_type_node,
18808                                 V16QI_type_node,
18809                                 NULL_TREE);
18810
18811   tree v4sf_ftype_v4sf_v4sf_v16qi
18812     = build_function_type_list (V4SF_type_node,
18813                                 V4SF_type_node,
18814                                 V4SF_type_node,
18815                                 V16QI_type_node,
18816                                 NULL_TREE);
18817
18818   tree v2di_ftype_v2di_si
18819     = build_function_type_list (V2DI_type_node,
18820                                 V2DI_type_node,
18821                                 integer_type_node,
18822                                 NULL_TREE);
18823
18824   tree v4si_ftype_v4si_si
18825     = build_function_type_list (V4SI_type_node,
18826                                 V4SI_type_node,
18827                                 integer_type_node,
18828                                 NULL_TREE);
18829
18830   tree v8hi_ftype_v8hi_si
18831     = build_function_type_list (V8HI_type_node,
18832                                 V8HI_type_node,
18833                                 integer_type_node,
18834                                 NULL_TREE);
18835
18836   tree v16qi_ftype_v16qi_si
18837     = build_function_type_list (V16QI_type_node,
18838                                 V16QI_type_node,
18839                                 integer_type_node,
18840                                 NULL_TREE);
18841   tree v4sf_ftype_v4hi
18842     = build_function_type_list (V4SF_type_node,
18843                                 V4HI_type_node,
18844                                 NULL_TREE);
18845
18846   tree v4hi_ftype_v4sf
18847     = build_function_type_list (V4HI_type_node,
18848                                 V4SF_type_node,
18849                                 NULL_TREE);
18850
18851   tree v2di_ftype_v2di
18852     = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
18853
18854   tree ftype;
18855
18856   /* The __float80 type.  */
18857   if (TYPE_MODE (long_double_type_node) == XFmode)
18858     (*lang_hooks.types.register_builtin_type) (long_double_type_node,
18859                                                "__float80");
18860   else
18861     {
18862       /* The __float80 type.  */
18863       tree float80_type_node = make_node (REAL_TYPE);
18864
18865       TYPE_PRECISION (float80_type_node) = 80;
18866       layout_type (float80_type_node);
18867       (*lang_hooks.types.register_builtin_type) (float80_type_node,
18868                                                  "__float80");
18869     }
18870
18871   if (TARGET_64BIT)
18872     {
18873       tree float128_type_node = make_node (REAL_TYPE);
18874
18875       TYPE_PRECISION (float128_type_node) = 128;
18876       layout_type (float128_type_node);
18877       (*lang_hooks.types.register_builtin_type) (float128_type_node,
18878                                                  "__float128");
18879
18880       /* TFmode support builtins.  */
18881       ftype = build_function_type (float128_type_node,
18882                                    void_list_node);
18883       def_builtin (OPTION_MASK_ISA_64BIT, "__builtin_infq", ftype, IX86_BUILTIN_INFQ);
18884
18885       ftype = build_function_type_list (float128_type_node,
18886                                         float128_type_node,
18887                                         NULL_TREE);
18888       def_builtin_const (OPTION_MASK_ISA_64BIT, "__builtin_fabsq", ftype, IX86_BUILTIN_FABSQ);
18889
18890       ftype = build_function_type_list (float128_type_node,
18891                                         float128_type_node,
18892                                         float128_type_node,
18893                                         NULL_TREE);
18894       def_builtin_const (OPTION_MASK_ISA_64BIT, "__builtin_copysignq", ftype, IX86_BUILTIN_COPYSIGNQ);
18895     }
18896
18897   /* Add all SSE builtins that are more or less simple operations on
18898      three operands.  */
18899   for (i = 0, d = bdesc_sse_3arg;
18900        i < ARRAY_SIZE (bdesc_sse_3arg);
18901        i++, d++)
18902     {
18903       /* Use one of the operands; the target can have a different mode for
18904          mask-generating compares.  */
18905       enum machine_mode mode;
18906       tree type;
18907
18908       if (d->name == 0)
18909         continue;
18910       mode = insn_data[d->icode].operand[1].mode;
18911
18912       switch (mode)
18913         {
18914         case V16QImode:
18915           type = v16qi_ftype_v16qi_v16qi_int;
18916           break;
18917         case V8HImode:
18918           type = v8hi_ftype_v8hi_v8hi_int;
18919           break;
18920         case V4SImode:
18921           type = v4si_ftype_v4si_v4si_int;
18922           break;
18923         case V2DImode:
18924           type = v2di_ftype_v2di_v2di_int;
18925           break;
18926         case V2DFmode:
18927           type = v2df_ftype_v2df_v2df_int;
18928           break;
18929         case V4SFmode:
18930           type = v4sf_ftype_v4sf_v4sf_int;
18931           break;
18932         default:
18933           gcc_unreachable ();
18934         }
18935
18936       /* Override for variable blends.  */
18937       switch (d->icode)
18938         {
18939         case CODE_FOR_sse4_1_blendvpd:
18940           type = v2df_ftype_v2df_v2df_v2df;
18941           break;
18942         case CODE_FOR_sse4_1_blendvps:
18943           type = v4sf_ftype_v4sf_v4sf_v4sf;
18944           break;
18945         case CODE_FOR_sse4_1_pblendvb:
18946           type = v16qi_ftype_v16qi_v16qi_v16qi;
18947           break;
18948         default:
18949           break;
18950         }
18951
18952       def_builtin_const (d->mask, d->name, type, d->code);
18953     }
18954
18955   /* Add all builtins that are more or less simple operations on two
18956      operands.  */
18957   for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
18958     {
18959       /* Use one of the operands; the target can have a different mode for
18960          mask-generating compares.  */
18961       enum machine_mode mode;
18962       tree type;
18963
18964       if (d->name == 0)
18965         continue;
18966       mode = insn_data[d->icode].operand[1].mode;
18967
18968       switch (mode)
18969         {
18970         case V16QImode:
18971           type = v16qi_ftype_v16qi_v16qi;
18972           break;
18973         case V8HImode:
18974           type = v8hi_ftype_v8hi_v8hi;
18975           break;
18976         case V4SImode:
18977           type = v4si_ftype_v4si_v4si;
18978           break;
18979         case V2DImode:
18980           type = v2di_ftype_v2di_v2di;
18981           break;
18982         case V2DFmode:
18983           type = v2df_ftype_v2df_v2df;
18984           break;
18985         case V4SFmode:
18986           type = v4sf_ftype_v4sf_v4sf;
18987           break;
18988         case V8QImode:
18989           type = v8qi_ftype_v8qi_v8qi;
18990           break;
18991         case V4HImode:
18992           type = v4hi_ftype_v4hi_v4hi;
18993           break;
18994         case V2SImode:
18995           type = v2si_ftype_v2si_v2si;
18996           break;
18997         case DImode:
18998           type = di_ftype_di_di;
18999           break;
19000
19001         default:
19002           gcc_unreachable ();
19003         }
19004
19005       /* Override for comparisons.  */
19006       if (d->icode == CODE_FOR_sse_maskcmpv4sf3
19007           || d->icode == CODE_FOR_sse_vmmaskcmpv4sf3)
19008         type = v4si_ftype_v4sf_v4sf;
19009
19010       if (d->icode == CODE_FOR_sse2_maskcmpv2df3
19011           || d->icode == CODE_FOR_sse2_vmmaskcmpv2df3)
19012         type = v2di_ftype_v2df_v2df;
19013
19014       if (d->icode == CODE_FOR_vec_pack_sfix_v2df)
19015         type = v4si_ftype_v2df_v2df;
19016
19017       def_builtin_const (d->mask, d->name, type, d->code);
19018     }
19019
19020   /* Add all builtins that are more or less simple operations on 1 operand.  */
19021   for (i = 0, d = bdesc_1arg; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
19022     {
19023       enum machine_mode mode;
19024       tree type;
19025
19026       if (d->name == 0)
19027         continue;
19028       mode = insn_data[d->icode].operand[1].mode;
19029
19030       switch (mode)
19031         {
19032         case V16QImode:
19033           type = v16qi_ftype_v16qi;
19034           break;
19035         case V8HImode:
19036           type = v8hi_ftype_v8hi;
19037           break;
19038         case V4SImode:
19039           type = v4si_ftype_v4si;
19040           break;
19041         case V2DFmode:
19042           type = v2df_ftype_v2df;
19043           break;
19044         case V4SFmode:
19045           type = v4sf_ftype_v4sf;
19046           break;
19047         case V8QImode:
19048           type = v8qi_ftype_v8qi;
19049           break;
19050         case V4HImode:
19051           type = v4hi_ftype_v4hi;
19052           break;
19053         case V2SImode:
19054           type = v2si_ftype_v2si;
19055           break;
19056
19057         default:
19058           abort ();
19059         }
19060
19061       def_builtin_const (d->mask, d->name, type, d->code);
19062     }
19063
19064   /* pcmpestr[im] insns.  */
19065   for (i = 0, d = bdesc_pcmpestr;
19066        i < ARRAY_SIZE (bdesc_pcmpestr);
19067        i++, d++)
19068     {
19069       if (d->code == IX86_BUILTIN_PCMPESTRM128)
19070         ftype = v16qi_ftype_v16qi_int_v16qi_int_int;
19071       else
19072         ftype = int_ftype_v16qi_int_v16qi_int_int;
19073       def_builtin_const (d->mask, d->name, ftype, d->code);
19074     }
19075
19076   /* pcmpistr[im] insns.  */
19077   for (i = 0, d = bdesc_pcmpistr;
19078        i < ARRAY_SIZE (bdesc_pcmpistr);
19079        i++, d++)
19080     {
19081       if (d->code == IX86_BUILTIN_PCMPISTRM128)
19082         ftype = v16qi_ftype_v16qi_v16qi_int;
19083       else
19084         ftype = int_ftype_v16qi_v16qi_int;
19085       def_builtin_const (d->mask, d->name, ftype, d->code);
19086     }
19087
19088   /* Add the remaining MMX insns with somewhat more complicated types.  */
19089   def_builtin (OPTION_MASK_ISA_MMX, "__builtin_ia32_emms", void_ftype_void, IX86_BUILTIN_EMMS);
19090   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_psllw", v4hi_ftype_v4hi_di, IX86_BUILTIN_PSLLW);
19091   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_pslld", v2si_ftype_v2si_di, IX86_BUILTIN_PSLLD);
19092   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_psllq", di_ftype_di_di, IX86_BUILTIN_PSLLQ);
19093
19094   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_psrlw", v4hi_ftype_v4hi_di, IX86_BUILTIN_PSRLW);
19095   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_psrld", v2si_ftype_v2si_di, IX86_BUILTIN_PSRLD);
19096   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_psrlq", di_ftype_di_di, IX86_BUILTIN_PSRLQ);
19097
19098   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_psraw", v4hi_ftype_v4hi_di, IX86_BUILTIN_PSRAW);
19099   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_psrad", v2si_ftype_v2si_di, IX86_BUILTIN_PSRAD);
19100
19101   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_pshufw", v4hi_ftype_v4hi_int, IX86_BUILTIN_PSHUFW);
19102   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_pmaddwd", v2si_ftype_v4hi_v4hi, IX86_BUILTIN_PMADDWD);
19103
19104   /* comi/ucomi insns.  */
19105   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
19106     if (d->mask == OPTION_MASK_ISA_SSE2)
19107       def_builtin_const (d->mask, d->name, int_ftype_v2df_v2df, d->code);
19108     else
19109       def_builtin_const (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
19110
19111   /* ptest insns.  */
19112   for (i = 0, d = bdesc_ptest; i < ARRAY_SIZE (bdesc_ptest); i++, d++)
19113     def_builtin_const (d->mask, d->name, int_ftype_v2di_v2di, d->code);
19114
19115   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_packsswb", v8qi_ftype_v4hi_v4hi, IX86_BUILTIN_PACKSSWB);
19116   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_packssdw", v4hi_ftype_v2si_v2si, IX86_BUILTIN_PACKSSDW);
19117   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_packuswb", v8qi_ftype_v4hi_v4hi, IX86_BUILTIN_PACKUSWB);
19118
19119   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr", void_ftype_unsigned, IX86_BUILTIN_LDMXCSR);
19120   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr", unsigned_ftype_void, IX86_BUILTIN_STMXCSR);
19121   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_cvtpi2ps", v4sf_ftype_v4sf_v2si, IX86_BUILTIN_CVTPI2PS);
19122   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_cvtps2pi", v2si_ftype_v4sf, IX86_BUILTIN_CVTPS2PI);
19123   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_cvtsi2ss", v4sf_ftype_v4sf_int, IX86_BUILTIN_CVTSI2SS);
19124   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, "__builtin_ia32_cvtsi642ss", v4sf_ftype_v4sf_int64, IX86_BUILTIN_CVTSI642SS);
19125   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_cvtss2si", int_ftype_v4sf, IX86_BUILTIN_CVTSS2SI);
19126   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, "__builtin_ia32_cvtss2si64", int64_ftype_v4sf, IX86_BUILTIN_CVTSS2SI64);
19127   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_cvttps2pi", v2si_ftype_v4sf, IX86_BUILTIN_CVTTPS2PI);
19128   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_cvttss2si", int_ftype_v4sf, IX86_BUILTIN_CVTTSS2SI);
19129   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, "__builtin_ia32_cvttss2si64", int64_ftype_v4sf, IX86_BUILTIN_CVTTSS2SI64);
19130
19131   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_maskmovq", void_ftype_v8qi_v8qi_pchar, IX86_BUILTIN_MASKMOVQ);
19132
19133   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_loadups", v4sf_ftype_pcfloat, IX86_BUILTIN_LOADUPS);
19134   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_storeups", void_ftype_pfloat_v4sf, IX86_BUILTIN_STOREUPS);
19135
19136   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_loadhps", v4sf_ftype_v4sf_pv2si, IX86_BUILTIN_LOADHPS);
19137   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_loadlps", v4sf_ftype_v4sf_pv2si, IX86_BUILTIN_LOADLPS);
19138   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_storehps", void_ftype_pv2si_v4sf, IX86_BUILTIN_STOREHPS);
19139   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_storelps", void_ftype_pv2si_v4sf, IX86_BUILTIN_STORELPS);
19140
19141   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_movmskps", int_ftype_v4sf, IX86_BUILTIN_MOVMSKPS);
19142   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_pmovmskb", int_ftype_v8qi, IX86_BUILTIN_PMOVMSKB);
19143   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_movntps", void_ftype_pfloat_v4sf, IX86_BUILTIN_MOVNTPS);
19144   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_movntq", void_ftype_pdi_di, IX86_BUILTIN_MOVNTQ);
19145
19146   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_sfence", void_ftype_void, IX86_BUILTIN_SFENCE);
19147
19148   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_psadbw", di_ftype_v8qi_v8qi, IX86_BUILTIN_PSADBW);
19149
19150   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_rcpps", v4sf_ftype_v4sf, IX86_BUILTIN_RCPPS);
19151   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_rcpss", v4sf_ftype_v4sf, IX86_BUILTIN_RCPSS);
19152   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_rsqrtps", v4sf_ftype_v4sf, IX86_BUILTIN_RSQRTPS);
19153   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_rsqrtss", v4sf_ftype_v4sf, IX86_BUILTIN_RSQRTSS);
19154   ftype = build_function_type_list (float_type_node,
19155                                     float_type_node,
19156                                     NULL_TREE);
19157   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_rsqrtf", ftype, IX86_BUILTIN_RSQRTF);
19158   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_sqrtps", v4sf_ftype_v4sf, IX86_BUILTIN_SQRTPS);
19159   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_sqrtss", v4sf_ftype_v4sf, IX86_BUILTIN_SQRTSS);
19160
19161   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_shufps", v4sf_ftype_v4sf_v4sf_int, IX86_BUILTIN_SHUFPS);
19162
19163   /* Original 3DNow!  */
19164   def_builtin (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_femms", void_ftype_void, IX86_BUILTIN_FEMMS);
19165   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pavgusb", v8qi_ftype_v8qi_v8qi, IX86_BUILTIN_PAVGUSB);
19166   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pf2id", v2si_ftype_v2sf, IX86_BUILTIN_PF2ID);
19167   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfacc", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFACC);
19168   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfadd", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFADD);
19169   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfcmpeq", v2si_ftype_v2sf_v2sf, IX86_BUILTIN_PFCMPEQ);
19170   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfcmpge", v2si_ftype_v2sf_v2sf, IX86_BUILTIN_PFCMPGE);
19171   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfcmpgt", v2si_ftype_v2sf_v2sf, IX86_BUILTIN_PFCMPGT);
19172   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfmax", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFMAX);
19173   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfmin", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFMIN);
19174   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfmul", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFMUL);
19175   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfrcp", v2sf_ftype_v2sf, IX86_BUILTIN_PFRCP);
19176   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfrcpit1", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFRCPIT1);
19177   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfrcpit2", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFRCPIT2);
19178   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfrsqrt", v2sf_ftype_v2sf, IX86_BUILTIN_PFRSQRT);
19179   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfrsqit1", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFRSQIT1);
19180   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfsub", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFSUB);
19181   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pfsubr", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFSUBR);
19182   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pi2fd", v2sf_ftype_v2si, IX86_BUILTIN_PI2FD);
19183   def_builtin_const (OPTION_MASK_ISA_3DNOW, "__builtin_ia32_pmulhrw", v4hi_ftype_v4hi_v4hi, IX86_BUILTIN_PMULHRW);
19184
19185   /* 3DNow! extension as used in the Athlon CPU.  */
19186   def_builtin_const (OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_pf2iw", v2si_ftype_v2sf, IX86_BUILTIN_PF2IW);
19187   def_builtin_const (OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_pfnacc", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFNACC);
19188   def_builtin_const (OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_pfpnacc", v2sf_ftype_v2sf_v2sf, IX86_BUILTIN_PFPNACC);
19189   def_builtin_const (OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_pi2fw", v2sf_ftype_v2si, IX86_BUILTIN_PI2FW);
19190   def_builtin_const (OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_pswapdsf", v2sf_ftype_v2sf, IX86_BUILTIN_PSWAPDSF);
19191   def_builtin_const (OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_pswapdsi", v2si_ftype_v2si, IX86_BUILTIN_PSWAPDSI);
19192
19193   /* SSE2 */
19194   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu", void_ftype_v16qi_v16qi_pchar, IX86_BUILTIN_MASKMOVDQU);
19195
19196   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_loadupd", v2df_ftype_pcdouble, IX86_BUILTIN_LOADUPD);
19197   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_storeupd", void_ftype_pdouble_v2df, IX86_BUILTIN_STOREUPD);
19198
19199   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_loadhpd", v2df_ftype_v2df_pcdouble, IX86_BUILTIN_LOADHPD);
19200   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_loadlpd", v2df_ftype_v2df_pcdouble, IX86_BUILTIN_LOADLPD);
19201
19202   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_movmskpd", int_ftype_v2df, IX86_BUILTIN_MOVMSKPD);
19203   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pmovmskb128", int_ftype_v16qi, IX86_BUILTIN_PMOVMSKB128);
19204   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_movnti", void_ftype_pint_int, IX86_BUILTIN_MOVNTI);
19205   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_movntpd", void_ftype_pdouble_v2df, IX86_BUILTIN_MOVNTPD);
19206   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_movntdq", void_ftype_pv2di_v2di, IX86_BUILTIN_MOVNTDQ);
19207
19208   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pshufd", v4si_ftype_v4si_int, IX86_BUILTIN_PSHUFD);
19209   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pshuflw", v8hi_ftype_v8hi_int, IX86_BUILTIN_PSHUFLW);
19210   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pshufhw", v8hi_ftype_v8hi_int, IX86_BUILTIN_PSHUFHW);
19211   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psadbw128", v2di_ftype_v16qi_v16qi, IX86_BUILTIN_PSADBW128);
19212
19213   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_sqrtpd", v2df_ftype_v2df, IX86_BUILTIN_SQRTPD);
19214   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_sqrtsd", v2df_ftype_v2df, IX86_BUILTIN_SQRTSD);
19215
19216   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_shufpd", v2df_ftype_v2df_v2df_int, IX86_BUILTIN_SHUFPD);
19217
19218   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtdq2pd", v2df_ftype_v4si, IX86_BUILTIN_CVTDQ2PD);
19219   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtdq2ps", v4sf_ftype_v4si, IX86_BUILTIN_CVTDQ2PS);
19220
19221   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtpd2dq", v4si_ftype_v2df, IX86_BUILTIN_CVTPD2DQ);
19222   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtpd2pi", v2si_ftype_v2df, IX86_BUILTIN_CVTPD2PI);
19223   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtpd2ps", v4sf_ftype_v2df, IX86_BUILTIN_CVTPD2PS);
19224   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvttpd2dq", v4si_ftype_v2df, IX86_BUILTIN_CVTTPD2DQ);
19225   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvttpd2pi", v2si_ftype_v2df, IX86_BUILTIN_CVTTPD2PI);
19226
19227   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtpi2pd", v2df_ftype_v2si, IX86_BUILTIN_CVTPI2PD);
19228
19229   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtsd2si", int_ftype_v2df, IX86_BUILTIN_CVTSD2SI);
19230   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvttsd2si", int_ftype_v2df, IX86_BUILTIN_CVTTSD2SI);
19231   def_builtin_const (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_cvtsd2si64", int64_ftype_v2df, IX86_BUILTIN_CVTSD2SI64);
19232   def_builtin_const (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_cvttsd2si64", int64_ftype_v2df, IX86_BUILTIN_CVTTSD2SI64);
19233
19234   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtps2dq", v4si_ftype_v4sf, IX86_BUILTIN_CVTPS2DQ);
19235   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtps2pd", v2df_ftype_v4sf, IX86_BUILTIN_CVTPS2PD);
19236   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvttps2dq", v4si_ftype_v4sf, IX86_BUILTIN_CVTTPS2DQ);
19237
19238   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtsi2sd", v2df_ftype_v2df_int, IX86_BUILTIN_CVTSI2SD);
19239   def_builtin_const (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_cvtsi642sd", v2df_ftype_v2df_int64, IX86_BUILTIN_CVTSI642SD);
19240   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtsd2ss", v4sf_ftype_v4sf_v2df, IX86_BUILTIN_CVTSD2SS);
19241   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_cvtss2sd", v2df_ftype_v2df_v4sf, IX86_BUILTIN_CVTSS2SD);
19242
19243   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush", void_ftype_pcvoid, IX86_BUILTIN_CLFLUSH);
19244   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_lfence", void_ftype_void, IX86_BUILTIN_LFENCE);
19245   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence", void_ftype_void, IX86_BUILTIN_MFENCE);
19246
19247   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_loaddqu", v16qi_ftype_pcchar, IX86_BUILTIN_LOADDQU);
19248   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_storedqu", void_ftype_pchar_v16qi, IX86_BUILTIN_STOREDQU);
19249
19250   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pmuludq", di_ftype_v2si_v2si, IX86_BUILTIN_PMULUDQ);
19251   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pmuludq128", v2di_ftype_v4si_v4si, IX86_BUILTIN_PMULUDQ128);
19252
19253   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pslldqi128", v2di_ftype_v2di_int, IX86_BUILTIN_PSLLDQI128);
19254   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psllwi128", v8hi_ftype_v8hi_int, IX86_BUILTIN_PSLLWI128);
19255   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pslldi128", v4si_ftype_v4si_int, IX86_BUILTIN_PSLLDI128);
19256   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psllqi128", v2di_ftype_v2di_int, IX86_BUILTIN_PSLLQI128);
19257   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psllw128", v8hi_ftype_v8hi_v8hi, IX86_BUILTIN_PSLLW128);
19258   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pslld128", v4si_ftype_v4si_v4si, IX86_BUILTIN_PSLLD128);
19259   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psllq128", v2di_ftype_v2di_v2di, IX86_BUILTIN_PSLLQ128);
19260
19261   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrldqi128", v2di_ftype_v2di_int, IX86_BUILTIN_PSRLDQI128);
19262   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrlwi128", v8hi_ftype_v8hi_int, IX86_BUILTIN_PSRLWI128);
19263   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrldi128", v4si_ftype_v4si_int, IX86_BUILTIN_PSRLDI128);
19264   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrlqi128", v2di_ftype_v2di_int, IX86_BUILTIN_PSRLQI128);
19265   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrlw128", v8hi_ftype_v8hi_v8hi, IX86_BUILTIN_PSRLW128);
19266   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrld128", v4si_ftype_v4si_v4si, IX86_BUILTIN_PSRLD128);
19267   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrlq128", v2di_ftype_v2di_v2di, IX86_BUILTIN_PSRLQ128);
19268
19269   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrawi128", v8hi_ftype_v8hi_int, IX86_BUILTIN_PSRAWI128);
19270   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psradi128", v4si_ftype_v4si_int, IX86_BUILTIN_PSRADI128);
19271   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psraw128", v8hi_ftype_v8hi_v8hi, IX86_BUILTIN_PSRAW128);
19272   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_psrad128", v4si_ftype_v4si_v4si, IX86_BUILTIN_PSRAD128);
19273
19274   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_pmaddwd128", v4si_ftype_v8hi_v8hi, IX86_BUILTIN_PMADDWD128);
19275
19276   /* Prescott New Instructions.  */
19277   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor", void_ftype_pcvoid_unsigned_unsigned, IX86_BUILTIN_MONITOR);
19278   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait", void_ftype_unsigned_unsigned, IX86_BUILTIN_MWAIT);
19279   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_lddqu", v16qi_ftype_pcchar, IX86_BUILTIN_LDDQU);
19280
19281   /* SSSE3.  */
19282   def_builtin_const (OPTION_MASK_ISA_SSSE3, "__builtin_ia32_palignr128", v2di_ftype_v2di_v2di_int, IX86_BUILTIN_PALIGNR128);
19283   def_builtin_const (OPTION_MASK_ISA_SSSE3, "__builtin_ia32_palignr", di_ftype_di_di_int, IX86_BUILTIN_PALIGNR);
19284
19285   /* SSE4.1. */
19286   def_builtin (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_movntdqa", v2di_ftype_pv2di, IX86_BUILTIN_MOVNTDQA);
19287   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovsxbw128", v8hi_ftype_v16qi, IX86_BUILTIN_PMOVSXBW128);
19288   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovsxbd128", v4si_ftype_v16qi, IX86_BUILTIN_PMOVSXBD128);
19289   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovsxbq128", v2di_ftype_v16qi, IX86_BUILTIN_PMOVSXBQ128);
19290   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovsxwd128", v4si_ftype_v8hi, IX86_BUILTIN_PMOVSXWD128);
19291   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovsxwq128", v2di_ftype_v8hi, IX86_BUILTIN_PMOVSXWQ128);
19292   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovsxdq128", v2di_ftype_v4si, IX86_BUILTIN_PMOVSXDQ128);
19293   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovzxbw128", v8hi_ftype_v16qi, IX86_BUILTIN_PMOVZXBW128);
19294   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovzxbd128", v4si_ftype_v16qi, IX86_BUILTIN_PMOVZXBD128);
19295   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovzxbq128", v2di_ftype_v16qi, IX86_BUILTIN_PMOVZXBQ128);
19296   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovzxwd128", v4si_ftype_v8hi, IX86_BUILTIN_PMOVZXWD128);
19297   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovzxwq128", v2di_ftype_v8hi, IX86_BUILTIN_PMOVZXWQ128);
19298   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmovzxdq128", v2di_ftype_v4si, IX86_BUILTIN_PMOVZXDQ128);
19299   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_pmuldq128", v2di_ftype_v4si_v4si, IX86_BUILTIN_PMULDQ128);
19300
19301   /* SSE4.1 and SSE5 */
19302   def_builtin_const (OPTION_MASK_ISA_ROUND, "__builtin_ia32_roundpd", v2df_ftype_v2df_int, IX86_BUILTIN_ROUNDPD);
19303   def_builtin_const (OPTION_MASK_ISA_ROUND, "__builtin_ia32_roundps", v4sf_ftype_v4sf_int, IX86_BUILTIN_ROUNDPS);
19304   def_builtin_const (OPTION_MASK_ISA_ROUND, "__builtin_ia32_roundsd", v2df_ftype_v2df_v2df_int, IX86_BUILTIN_ROUNDSD);
19305   def_builtin_const (OPTION_MASK_ISA_ROUND, "__builtin_ia32_roundss", v4sf_ftype_v4sf_v4sf_int, IX86_BUILTIN_ROUNDSS);
19306
19307   /* SSE4.2. */
19308   ftype = build_function_type_list (unsigned_type_node,
19309                                     unsigned_type_node,
19310                                     unsigned_char_type_node,
19311                                     NULL_TREE);
19312   def_builtin_const (OPTION_MASK_ISA_SSE4_2, "__builtin_ia32_crc32qi", ftype, IX86_BUILTIN_CRC32QI);
19313   ftype = build_function_type_list (unsigned_type_node,
19314                                     unsigned_type_node,
19315                                     short_unsigned_type_node,
19316                                     NULL_TREE);
19317   def_builtin_const (OPTION_MASK_ISA_SSE4_2, "__builtin_ia32_crc32hi", ftype, IX86_BUILTIN_CRC32HI);
19318   ftype = build_function_type_list (unsigned_type_node,
19319                                     unsigned_type_node,
19320                                     unsigned_type_node,
19321                                     NULL_TREE);
19322   def_builtin_const (OPTION_MASK_ISA_SSE4_2, "__builtin_ia32_crc32si", ftype, IX86_BUILTIN_CRC32SI);
19323   ftype = build_function_type_list (long_long_unsigned_type_node,
19324                                     long_long_unsigned_type_node,
19325                                     long_long_unsigned_type_node,
19326                                     NULL_TREE);
19327   def_builtin_const (OPTION_MASK_ISA_SSE4_2, "__builtin_ia32_crc32di", ftype, IX86_BUILTIN_CRC32DI);
19328
19329   /* AMDFAM10 SSE4A New built-ins  */
19330   def_builtin (OPTION_MASK_ISA_SSE4A, "__builtin_ia32_movntsd", void_ftype_pdouble_v2df, IX86_BUILTIN_MOVNTSD);
19331   def_builtin (OPTION_MASK_ISA_SSE4A, "__builtin_ia32_movntss", void_ftype_pfloat_v4sf, IX86_BUILTIN_MOVNTSS);
19332   def_builtin_const (OPTION_MASK_ISA_SSE4A, "__builtin_ia32_extrqi", v2di_ftype_v2di_unsigned_unsigned, IX86_BUILTIN_EXTRQI);
19333   def_builtin_const (OPTION_MASK_ISA_SSE4A, "__builtin_ia32_extrq", v2di_ftype_v2di_v16qi,  IX86_BUILTIN_EXTRQ);
19334   def_builtin_const (OPTION_MASK_ISA_SSE4A, "__builtin_ia32_insertqi", v2di_ftype_v2di_v2di_unsigned_unsigned, IX86_BUILTIN_INSERTQI);
19335   def_builtin_const (OPTION_MASK_ISA_SSE4A, "__builtin_ia32_insertq", v2di_ftype_v2di_v2di, IX86_BUILTIN_INSERTQ);
19336
19337   /* Access to the vec_init patterns.  */
19338   ftype = build_function_type_list (V2SI_type_node, integer_type_node,
19339                                     integer_type_node, NULL_TREE);
19340   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si", ftype, IX86_BUILTIN_VEC_INIT_V2SI);
19341
19342   ftype = build_function_type_list (V4HI_type_node, short_integer_type_node,
19343                                     short_integer_type_node,
19344                                     short_integer_type_node,
19345                                     short_integer_type_node, NULL_TREE);
19346   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi", ftype, IX86_BUILTIN_VEC_INIT_V4HI);
19347
19348   ftype = build_function_type_list (V8QI_type_node, char_type_node,
19349                                     char_type_node, char_type_node,
19350                                     char_type_node, char_type_node,
19351                                     char_type_node, char_type_node,
19352                                     char_type_node, NULL_TREE);
19353   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi", ftype, IX86_BUILTIN_VEC_INIT_V8QI);
19354
19355   /* Access to the vec_extract patterns.  */
19356   ftype = build_function_type_list (double_type_node, V2DF_type_node,
19357                                     integer_type_node, NULL_TREE);
19358   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df", ftype, IX86_BUILTIN_VEC_EXT_V2DF);
19359
19360   ftype = build_function_type_list (long_long_integer_type_node,
19361                                     V2DI_type_node, integer_type_node,
19362                                     NULL_TREE);
19363   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di", ftype, IX86_BUILTIN_VEC_EXT_V2DI);
19364
19365   ftype = build_function_type_list (float_type_node, V4SF_type_node,
19366                                     integer_type_node, NULL_TREE);
19367   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf", ftype, IX86_BUILTIN_VEC_EXT_V4SF);
19368
19369   ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
19370                                     integer_type_node, NULL_TREE);
19371   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si", ftype, IX86_BUILTIN_VEC_EXT_V4SI);
19372
19373   ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
19374                                     integer_type_node, NULL_TREE);
19375   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi", ftype, IX86_BUILTIN_VEC_EXT_V8HI);
19376
19377   ftype = build_function_type_list (intHI_type_node, V4HI_type_node,
19378                                     integer_type_node, NULL_TREE);
19379   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_ext_v4hi", ftype, IX86_BUILTIN_VEC_EXT_V4HI);
19380
19381   ftype = build_function_type_list (intSI_type_node, V2SI_type_node,
19382                                     integer_type_node, NULL_TREE);
19383   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si", ftype, IX86_BUILTIN_VEC_EXT_V2SI);
19384
19385   ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
19386                                     integer_type_node, NULL_TREE);
19387   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi", ftype, IX86_BUILTIN_VEC_EXT_V16QI);
19388
19389   /* Access to the vec_set patterns.  */
19390   ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
19391                                     intDI_type_node,
19392                                     integer_type_node, NULL_TREE);
19393   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_vec_set_v2di", ftype, IX86_BUILTIN_VEC_SET_V2DI);
19394
19395   ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
19396                                     float_type_node,
19397                                     integer_type_node, NULL_TREE);
19398   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf", ftype, IX86_BUILTIN_VEC_SET_V4SF);
19399
19400   ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
19401                                     intSI_type_node,
19402                                     integer_type_node, NULL_TREE);
19403   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si", ftype, IX86_BUILTIN_VEC_SET_V4SI);
19404
19405   ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
19406                                     intHI_type_node,
19407                                     integer_type_node, NULL_TREE);
19408   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi", ftype, IX86_BUILTIN_VEC_SET_V8HI);
19409
19410   ftype = build_function_type_list (V4HI_type_node, V4HI_type_node,
19411                                     intHI_type_node,
19412                                     integer_type_node, NULL_TREE);
19413   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_set_v4hi", ftype, IX86_BUILTIN_VEC_SET_V4HI);
19414
19415   ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
19416                                     intQI_type_node,
19417                                     integer_type_node, NULL_TREE);
19418   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi", ftype, IX86_BUILTIN_VEC_SET_V16QI);
19419
19420   /* Add SSE5 multi-arg argument instructions */
19421   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
19422     {
19423       tree mtype = NULL_TREE;
19424
19425       if (d->name == 0)
19426         continue;
19427
19428       switch ((enum multi_arg_type)d->flag)
19429         {
19430         case MULTI_ARG_3_SF:     mtype = v4sf_ftype_v4sf_v4sf_v4sf;     break;
19431         case MULTI_ARG_3_DF:     mtype = v2df_ftype_v2df_v2df_v2df;     break;
19432         case MULTI_ARG_3_DI:     mtype = v2di_ftype_v2di_v2di_v2di;     break;
19433         case MULTI_ARG_3_SI:     mtype = v4si_ftype_v4si_v4si_v4si;     break;
19434         case MULTI_ARG_3_SI_DI:  mtype = v4si_ftype_v4si_v4si_v2di;     break;
19435         case MULTI_ARG_3_HI:     mtype = v8hi_ftype_v8hi_v8hi_v8hi;     break;
19436         case MULTI_ARG_3_HI_SI:  mtype = v8hi_ftype_v8hi_v8hi_v4si;     break;
19437         case MULTI_ARG_3_QI:     mtype = v16qi_ftype_v16qi_v16qi_v16qi; break;
19438         case MULTI_ARG_3_PERMPS: mtype = v4sf_ftype_v4sf_v4sf_v16qi;    break;
19439         case MULTI_ARG_3_PERMPD: mtype = v2df_ftype_v2df_v2df_v16qi;    break;
19440         case MULTI_ARG_2_SF:     mtype = v4sf_ftype_v4sf_v4sf;          break;
19441         case MULTI_ARG_2_DF:     mtype = v2df_ftype_v2df_v2df;          break;
19442         case MULTI_ARG_2_DI:     mtype = v2di_ftype_v2di_v2di;          break;
19443         case MULTI_ARG_2_SI:     mtype = v4si_ftype_v4si_v4si;          break;
19444         case MULTI_ARG_2_HI:     mtype = v8hi_ftype_v8hi_v8hi;          break;
19445         case MULTI_ARG_2_QI:     mtype = v16qi_ftype_v16qi_v16qi;       break;
19446         case MULTI_ARG_2_DI_IMM: mtype = v2di_ftype_v2di_si;            break;
19447         case MULTI_ARG_2_SI_IMM: mtype = v4si_ftype_v4si_si;            break;
19448         case MULTI_ARG_2_HI_IMM: mtype = v8hi_ftype_v8hi_si;            break;
19449         case MULTI_ARG_2_QI_IMM: mtype = v16qi_ftype_v16qi_si;          break;
19450         case MULTI_ARG_2_SF_CMP: mtype = v4sf_ftype_v4sf_v4sf;          break;
19451         case MULTI_ARG_2_DF_CMP: mtype = v2df_ftype_v2df_v2df;          break;
19452         case MULTI_ARG_2_DI_CMP: mtype = v2di_ftype_v2di_v2di;          break;
19453         case MULTI_ARG_2_SI_CMP: mtype = v4si_ftype_v4si_v4si;          break;
19454         case MULTI_ARG_2_HI_CMP: mtype = v8hi_ftype_v8hi_v8hi;          break;
19455         case MULTI_ARG_2_QI_CMP: mtype = v16qi_ftype_v16qi_v16qi;       break;
19456         case MULTI_ARG_2_SF_TF:  mtype = v4sf_ftype_v4sf_v4sf;          break;
19457         case MULTI_ARG_2_DF_TF:  mtype = v2df_ftype_v2df_v2df;          break;
19458         case MULTI_ARG_2_DI_TF:  mtype = v2di_ftype_v2di_v2di;          break;
19459         case MULTI_ARG_2_SI_TF:  mtype = v4si_ftype_v4si_v4si;          break;
19460         case MULTI_ARG_2_HI_TF:  mtype = v8hi_ftype_v8hi_v8hi;          break;
19461         case MULTI_ARG_2_QI_TF:  mtype = v16qi_ftype_v16qi_v16qi;       break;
19462         case MULTI_ARG_1_SF:     mtype = v4sf_ftype_v4sf;               break;
19463         case MULTI_ARG_1_DF:     mtype = v2df_ftype_v2df;               break;
19464         case MULTI_ARG_1_DI:     mtype = v2di_ftype_v2di;               break;
19465         case MULTI_ARG_1_SI:     mtype = v4si_ftype_v4si;               break;
19466         case MULTI_ARG_1_HI:     mtype = v8hi_ftype_v8hi;               break;
19467         case MULTI_ARG_1_QI:     mtype = v16qi_ftype_v16qi;             break;
19468         case MULTI_ARG_1_SI_DI:  mtype = v2di_ftype_v4si;               break;
19469         case MULTI_ARG_1_HI_DI:  mtype = v2di_ftype_v8hi;               break;
19470         case MULTI_ARG_1_HI_SI:  mtype = v4si_ftype_v8hi;               break;
19471         case MULTI_ARG_1_QI_DI:  mtype = v2di_ftype_v16qi;              break;
19472         case MULTI_ARG_1_QI_SI:  mtype = v4si_ftype_v16qi;              break;
19473         case MULTI_ARG_1_QI_HI:  mtype = v8hi_ftype_v16qi;              break;
19474         case MULTI_ARG_1_PH2PS:  mtype = v4sf_ftype_v4hi;               break;
19475         case MULTI_ARG_1_PS2PH:  mtype = v4hi_ftype_v4sf;               break;
19476         case MULTI_ARG_UNKNOWN:
19477         default:
19478           gcc_unreachable ();
19479         }
19480
19481       if (mtype)
19482         def_builtin_const (d->mask, d->name, mtype, d->code);
19483     }
19484 }
19485
19486 static void
19487 ix86_init_builtins (void)
19488 {
19489   if (TARGET_MMX)
19490     ix86_init_mmx_sse_builtins ();
19491 }
19492
19493 /* Errors in the source file can cause expand_expr to return const0_rtx
19494    where we expect a vector.  To avoid crashing, use one of the vector
19495    clear instructions.  */
19496 static rtx
19497 safe_vector_operand (rtx x, enum machine_mode mode)
19498 {
19499   if (x == const0_rtx)
19500     x = CONST0_RTX (mode);
19501   return x;
19502 }
19503
19504 /* Subroutine of ix86_expand_builtin to take care of SSE insns with
19505    4 operands. The third argument must be a constant smaller than 8
19506    bits or xmm0.  */
19507
19508 static rtx
19509 ix86_expand_sse_4_operands_builtin (enum insn_code icode, tree exp,
19510                                     rtx target)
19511 {
19512   rtx pat;
19513   tree arg0 = CALL_EXPR_ARG (exp, 0);
19514   tree arg1 = CALL_EXPR_ARG (exp, 1);
19515   tree arg2 = CALL_EXPR_ARG (exp, 2);
19516   rtx op0 = expand_normal (arg0);
19517   rtx op1 = expand_normal (arg1);
19518   rtx op2 = expand_normal (arg2);
19519   enum machine_mode tmode = insn_data[icode].operand[0].mode;
19520   enum machine_mode mode1 = insn_data[icode].operand[1].mode;
19521   enum machine_mode mode2 = insn_data[icode].operand[2].mode;
19522   enum machine_mode mode3 = insn_data[icode].operand[3].mode;
19523
19524   if (VECTOR_MODE_P (mode1))
19525     op0 = safe_vector_operand (op0, mode1);
19526   if (VECTOR_MODE_P (mode2))
19527     op1 = safe_vector_operand (op1, mode2);
19528   if (VECTOR_MODE_P (mode3))
19529     op2 = safe_vector_operand (op2, mode3);
19530
19531   if (optimize
19532       || target == 0
19533       || GET_MODE (target) != tmode
19534       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
19535     target = gen_reg_rtx (tmode);
19536
19537   if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
19538     op0 = copy_to_mode_reg (mode1, op0);
19539   if ((optimize && !register_operand (op1, mode2))
19540       || !(*insn_data[icode].operand[2].predicate) (op1, mode2))
19541     op1 = copy_to_mode_reg (mode2, op1);
19542
19543   if (! (*insn_data[icode].operand[3].predicate) (op2, mode3))
19544     switch (icode)
19545       {
19546       case CODE_FOR_sse4_1_blendvpd:
19547       case CODE_FOR_sse4_1_blendvps:
19548       case CODE_FOR_sse4_1_pblendvb:
19549         op2 = copy_to_mode_reg (mode3, op2);
19550         break;
19551
19552       case CODE_FOR_sse4_1_roundsd:
19553       case CODE_FOR_sse4_1_roundss:
19554         error ("the third argument must be a 4-bit immediate");
19555         return const0_rtx;
19556
19557       default:
19558         error ("the third argument must be an 8-bit immediate");
19559         return const0_rtx;
19560       }
19561
19562   pat = GEN_FCN (icode) (target, op0, op1, op2);
19563   if (! pat)
19564     return 0;
19565   emit_insn (pat);
19566   return target;
19567 }
19568
19569 /* Subroutine of ix86_expand_builtin to take care of crc32 insns.  */
19570
19571 static rtx
19572 ix86_expand_crc32 (enum insn_code icode, tree exp, rtx target)
19573 {
19574   rtx pat;
19575   tree arg0 = CALL_EXPR_ARG (exp, 0);
19576   tree arg1 = CALL_EXPR_ARG (exp, 1);
19577   rtx op0 = expand_normal (arg0);
19578   rtx op1 = expand_normal (arg1);
19579   enum machine_mode tmode = insn_data[icode].operand[0].mode;
19580   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
19581   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
19582
19583   if (optimize
19584       || !target
19585       || GET_MODE (target) != tmode
19586       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
19587     target = gen_reg_rtx (tmode);
19588
19589   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
19590     op0 = copy_to_mode_reg (mode0, op0);
19591   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
19592     {
19593       op1 = copy_to_reg (op1);
19594       op1 = simplify_gen_subreg (mode1, op1, GET_MODE (op1), 0);
19595     }
19596
19597   pat = GEN_FCN (icode) (target, op0, op1);
19598   if (! pat)
19599     return 0;
19600   emit_insn (pat);
19601   return target;
19602 }
19603
19604 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
19605
19606 static rtx
19607 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
19608 {
19609   rtx pat, xops[3];
19610   tree arg0 = CALL_EXPR_ARG (exp, 0);
19611   tree arg1 = CALL_EXPR_ARG (exp, 1);
19612   rtx op0 = expand_normal (arg0);
19613   rtx op1 = expand_normal (arg1);
19614   enum machine_mode tmode = insn_data[icode].operand[0].mode;
19615   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
19616   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
19617
19618   if (VECTOR_MODE_P (mode0))
19619     op0 = safe_vector_operand (op0, mode0);
19620   if (VECTOR_MODE_P (mode1))
19621     op1 = safe_vector_operand (op1, mode1);
19622
19623   if (optimize || !target
19624       || GET_MODE (target) != tmode
19625       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
19626     target = gen_reg_rtx (tmode);
19627
19628   if (GET_MODE (op1) == SImode && mode1 == TImode)
19629     {
19630       rtx x = gen_reg_rtx (V4SImode);
19631       emit_insn (gen_sse2_loadd (x, op1));
19632       op1 = gen_lowpart (TImode, x);
19633     }
19634
19635   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
19636     op0 = copy_to_mode_reg (mode0, op0);
19637   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
19638     op1 = copy_to_mode_reg (mode1, op1);
19639
19640   /* ??? Using ix86_fixup_binary_operands is problematic when
19641      we've got mismatched modes.  Fake it.  */
19642
19643   xops[0] = target;
19644   xops[1] = op0;
19645   xops[2] = op1;
19646
19647   if (tmode == mode0 && tmode == mode1)
19648     {
19649       target = ix86_fixup_binary_operands (UNKNOWN, tmode, xops);
19650       op0 = xops[1];
19651       op1 = xops[2];
19652     }
19653   else if (optimize || !ix86_binary_operator_ok (UNKNOWN, tmode, xops))
19654     {
19655       op0 = force_reg (mode0, op0);
19656       op1 = force_reg (mode1, op1);
19657       target = gen_reg_rtx (tmode);
19658     }
19659
19660   pat = GEN_FCN (icode) (target, op0, op1);
19661   if (! pat)
19662     return 0;
19663   emit_insn (pat);
19664   return target;
19665 }
19666
19667 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
19668
19669 static rtx
19670 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
19671                                enum multi_arg_type m_type,
19672                                enum insn_code sub_code)
19673 {
19674   rtx pat;
19675   int i;
19676   int nargs;
19677   bool comparison_p = false;
19678   bool tf_p = false;
19679   bool last_arg_constant = false;
19680   int num_memory = 0;
19681   struct {
19682     rtx op;
19683     enum machine_mode mode;
19684   } args[4];
19685
19686   enum machine_mode tmode = insn_data[icode].operand[0].mode;
19687
19688   switch (m_type)
19689     {
19690     case MULTI_ARG_3_SF:
19691     case MULTI_ARG_3_DF:
19692     case MULTI_ARG_3_DI:
19693     case MULTI_ARG_3_SI:
19694     case MULTI_ARG_3_SI_DI:
19695     case MULTI_ARG_3_HI:
19696     case MULTI_ARG_3_HI_SI:
19697     case MULTI_ARG_3_QI:
19698     case MULTI_ARG_3_PERMPS:
19699     case MULTI_ARG_3_PERMPD:
19700       nargs = 3;
19701       break;
19702
19703     case MULTI_ARG_2_SF:
19704     case MULTI_ARG_2_DF:
19705     case MULTI_ARG_2_DI:
19706     case MULTI_ARG_2_SI:
19707     case MULTI_ARG_2_HI:
19708     case MULTI_ARG_2_QI:
19709       nargs = 2;
19710       break;
19711
19712     case MULTI_ARG_2_DI_IMM:
19713     case MULTI_ARG_2_SI_IMM:
19714     case MULTI_ARG_2_HI_IMM:
19715     case MULTI_ARG_2_QI_IMM:
19716       nargs = 2;
19717       last_arg_constant = true;
19718       break;
19719
19720     case MULTI_ARG_1_SF:
19721     case MULTI_ARG_1_DF:
19722     case MULTI_ARG_1_DI:
19723     case MULTI_ARG_1_SI:
19724     case MULTI_ARG_1_HI:
19725     case MULTI_ARG_1_QI:
19726     case MULTI_ARG_1_SI_DI:
19727     case MULTI_ARG_1_HI_DI:
19728     case MULTI_ARG_1_HI_SI:
19729     case MULTI_ARG_1_QI_DI:
19730     case MULTI_ARG_1_QI_SI:
19731     case MULTI_ARG_1_QI_HI:
19732     case MULTI_ARG_1_PH2PS:
19733     case MULTI_ARG_1_PS2PH:
19734       nargs = 1;
19735       break;
19736
19737     case MULTI_ARG_2_SF_CMP:
19738     case MULTI_ARG_2_DF_CMP:
19739     case MULTI_ARG_2_DI_CMP:
19740     case MULTI_ARG_2_SI_CMP:
19741     case MULTI_ARG_2_HI_CMP:
19742     case MULTI_ARG_2_QI_CMP:
19743       nargs = 2;
19744       comparison_p = true;
19745       break;
19746
19747     case MULTI_ARG_2_SF_TF:
19748     case MULTI_ARG_2_DF_TF:
19749     case MULTI_ARG_2_DI_TF:
19750     case MULTI_ARG_2_SI_TF:
19751     case MULTI_ARG_2_HI_TF:
19752     case MULTI_ARG_2_QI_TF:
19753       nargs = 2;
19754       tf_p = true;
19755       break;
19756
19757     case MULTI_ARG_UNKNOWN:
19758     default:
19759       gcc_unreachable ();
19760     }
19761
19762   if (optimize || !target
19763       || GET_MODE (target) != tmode
19764       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
19765     target = gen_reg_rtx (tmode);
19766
19767   gcc_assert (nargs <= 4);
19768
19769   for (i = 0; i < nargs; i++)
19770     {
19771       tree arg = CALL_EXPR_ARG (exp, i);
19772       rtx op = expand_normal (arg);
19773       int adjust = (comparison_p) ? 1 : 0;
19774       enum machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
19775
19776       if (last_arg_constant && i == nargs-1)
19777         {
19778           if (GET_CODE (op) != CONST_INT)
19779             {
19780               error ("last argument must be an immediate");
19781               return gen_reg_rtx (tmode);
19782             }
19783         }
19784       else
19785         {
19786           if (VECTOR_MODE_P (mode))
19787             op = safe_vector_operand (op, mode);
19788
19789           /* If we aren't optimizing, only allow one memory operand to be
19790              generated.  */
19791           if (memory_operand (op, mode))
19792             num_memory++;
19793
19794           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
19795
19796           if (optimize
19797               || ! (*insn_data[icode].operand[i+adjust+1].predicate) (op, mode)
19798               || num_memory > 1)
19799             op = force_reg (mode, op);
19800         }
19801
19802       args[i].op = op;
19803       args[i].mode = mode;
19804     }
19805
19806   switch (nargs)
19807     {
19808     case 1:
19809       pat = GEN_FCN (icode) (target, args[0].op);
19810       break;
19811
19812     case 2:
19813       if (tf_p)
19814         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
19815                                GEN_INT ((int)sub_code));
19816       else if (! comparison_p)
19817         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
19818       else
19819         {
19820           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
19821                                        args[0].op,
19822                                        args[1].op);
19823
19824           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
19825         }
19826       break;
19827
19828     case 3:
19829       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
19830       break;
19831
19832     default:
19833       gcc_unreachable ();
19834     }
19835
19836   if (! pat)
19837     return 0;
19838
19839   emit_insn (pat);
19840   return target;
19841 }
19842
19843 /* Subroutine of ix86_expand_builtin to take care of stores.  */
19844
19845 static rtx
19846 ix86_expand_store_builtin (enum insn_code icode, tree exp)
19847 {
19848   rtx pat;
19849   tree arg0 = CALL_EXPR_ARG (exp, 0);
19850   tree arg1 = CALL_EXPR_ARG (exp, 1);
19851   rtx op0 = expand_normal (arg0);
19852   rtx op1 = expand_normal (arg1);
19853   enum machine_mode mode0 = insn_data[icode].operand[0].mode;
19854   enum machine_mode mode1 = insn_data[icode].operand[1].mode;
19855
19856   if (VECTOR_MODE_P (mode1))
19857     op1 = safe_vector_operand (op1, mode1);
19858
19859   op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
19860   op1 = copy_to_mode_reg (mode1, op1);
19861
19862   pat = GEN_FCN (icode) (op0, op1);
19863   if (pat)
19864     emit_insn (pat);
19865   return 0;
19866 }
19867
19868 /* Subroutine of ix86_expand_builtin to take care of unop insns.  */
19869
19870 static rtx
19871 ix86_expand_unop_builtin (enum insn_code icode, tree exp,
19872                           rtx target, int do_load)
19873 {
19874   rtx pat;
19875   tree arg0 = CALL_EXPR_ARG (exp, 0);
19876   rtx op0 = expand_normal (arg0);
19877   enum machine_mode tmode = insn_data[icode].operand[0].mode;
19878   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
19879
19880   if (optimize || !target
19881       || GET_MODE (target) != tmode
19882       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
19883     target = gen_reg_rtx (tmode);
19884   if (do_load)
19885     op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
19886   else
19887     {
19888       if (VECTOR_MODE_P (mode0))
19889         op0 = safe_vector_operand (op0, mode0);
19890
19891       if ((optimize && !register_operand (op0, mode0))
19892           || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
19893         op0 = copy_to_mode_reg (mode0, op0);
19894     }
19895
19896   switch (icode)
19897     {
19898     case CODE_FOR_sse4_1_roundpd:
19899     case CODE_FOR_sse4_1_roundps:
19900         {
19901           tree arg1 = CALL_EXPR_ARG (exp, 1);
19902           rtx op1 = expand_normal (arg1);
19903           enum machine_mode mode1 = insn_data[icode].operand[2].mode;
19904
19905           if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
19906             {
19907               error ("the second argument must be a 4-bit immediate");
19908               return const0_rtx;
19909             }
19910           pat = GEN_FCN (icode) (target, op0, op1);
19911         }
19912       break;
19913     default:
19914       pat = GEN_FCN (icode) (target, op0);
19915       break;
19916     }
19917
19918   if (! pat)
19919     return 0;
19920   emit_insn (pat);
19921   return target;
19922 }
19923
19924 /* Subroutine of ix86_expand_builtin to take care of three special unop insns:
19925    sqrtss, rsqrtss, rcpss.  */
19926
19927 static rtx
19928 ix86_expand_unop1_builtin (enum insn_code icode, tree exp, rtx target)
19929 {
19930   rtx pat;
19931   tree arg0 = CALL_EXPR_ARG (exp, 0);
19932   rtx op1, op0 = expand_normal (arg0);
19933   enum machine_mode tmode = insn_data[icode].operand[0].mode;
19934   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
19935
19936   if (optimize || !target
19937       || GET_MODE (target) != tmode
19938       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
19939     target = gen_reg_rtx (tmode);
19940
19941   if (VECTOR_MODE_P (mode0))
19942     op0 = safe_vector_operand (op0, mode0);
19943
19944   if ((optimize && !register_operand (op0, mode0))
19945       || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
19946     op0 = copy_to_mode_reg (mode0, op0);
19947
19948   op1 = op0;
19949   if (! (*insn_data[icode].operand[2].predicate) (op1, mode0))
19950     op1 = copy_to_mode_reg (mode0, op1);
19951
19952   pat = GEN_FCN (icode) (target, op0, op1);
19953   if (! pat)
19954     return 0;
19955   emit_insn (pat);
19956   return target;
19957 }
19958
19959 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
19960
19961 static rtx
19962 ix86_expand_sse_compare (const struct builtin_description *d, tree exp,
19963                          rtx target)
19964 {
19965   rtx pat;
19966   tree arg0 = CALL_EXPR_ARG (exp, 0);
19967   tree arg1 = CALL_EXPR_ARG (exp, 1);
19968   rtx op0 = expand_normal (arg0);
19969   rtx op1 = expand_normal (arg1);
19970   rtx op2;
19971   enum machine_mode tmode = insn_data[d->icode].operand[0].mode;
19972   enum machine_mode mode0 = insn_data[d->icode].operand[1].mode;
19973   enum machine_mode mode1 = insn_data[d->icode].operand[2].mode;
19974   enum rtx_code comparison = d->comparison;
19975
19976   if (VECTOR_MODE_P (mode0))
19977     op0 = safe_vector_operand (op0, mode0);
19978   if (VECTOR_MODE_P (mode1))
19979     op1 = safe_vector_operand (op1, mode1);
19980
19981   /* Swap operands if we have a comparison that isn't available in
19982      hardware.  */
19983   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
19984     {
19985       rtx tmp = gen_reg_rtx (mode1);
19986       emit_move_insn (tmp, op1);
19987       op1 = op0;
19988       op0 = tmp;
19989     }
19990
19991   if (optimize || !target
19992       || GET_MODE (target) != tmode
19993       || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode))
19994     target = gen_reg_rtx (tmode);
19995
19996   if ((optimize && !register_operand (op0, mode0))
19997       || ! (*insn_data[d->icode].operand[1].predicate) (op0, mode0))
19998     op0 = copy_to_mode_reg (mode0, op0);
19999   if ((optimize && !register_operand (op1, mode1))
20000       || ! (*insn_data[d->icode].operand[2].predicate) (op1, mode1))
20001     op1 = copy_to_mode_reg (mode1, op1);
20002
20003   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
20004   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
20005   if (! pat)
20006     return 0;
20007   emit_insn (pat);
20008   return target;
20009 }
20010
20011 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
20012
20013 static rtx
20014 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
20015                       rtx target)
20016 {
20017   rtx pat;
20018   tree arg0 = CALL_EXPR_ARG (exp, 0);
20019   tree arg1 = CALL_EXPR_ARG (exp, 1);
20020   rtx op0 = expand_normal (arg0);
20021   rtx op1 = expand_normal (arg1);
20022   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
20023   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
20024   enum rtx_code comparison = d->comparison;
20025
20026   if (VECTOR_MODE_P (mode0))
20027     op0 = safe_vector_operand (op0, mode0);
20028   if (VECTOR_MODE_P (mode1))
20029     op1 = safe_vector_operand (op1, mode1);
20030
20031   /* Swap operands if we have a comparison that isn't available in
20032      hardware.  */
20033   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
20034     {
20035       rtx tmp = op1;
20036       op1 = op0;
20037       op0 = tmp;
20038     }
20039
20040   target = gen_reg_rtx (SImode);
20041   emit_move_insn (target, const0_rtx);
20042   target = gen_rtx_SUBREG (QImode, target, 0);
20043
20044   if ((optimize && !register_operand (op0, mode0))
20045       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
20046     op0 = copy_to_mode_reg (mode0, op0);
20047   if ((optimize && !register_operand (op1, mode1))
20048       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
20049     op1 = copy_to_mode_reg (mode1, op1);
20050
20051   pat = GEN_FCN (d->icode) (op0, op1);
20052   if (! pat)
20053     return 0;
20054   emit_insn (pat);
20055   emit_insn (gen_rtx_SET (VOIDmode,
20056                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
20057                           gen_rtx_fmt_ee (comparison, QImode,
20058                                           SET_DEST (pat),
20059                                           const0_rtx)));
20060
20061   return SUBREG_REG (target);
20062 }
20063
20064 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
20065
20066 static rtx
20067 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
20068                        rtx target)
20069 {
20070   rtx pat;
20071   tree arg0 = CALL_EXPR_ARG (exp, 0);
20072   tree arg1 = CALL_EXPR_ARG (exp, 1);
20073   rtx op0 = expand_normal (arg0);
20074   rtx op1 = expand_normal (arg1);
20075   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
20076   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
20077   enum rtx_code comparison = d->comparison;
20078
20079   if (VECTOR_MODE_P (mode0))
20080     op0 = safe_vector_operand (op0, mode0);
20081   if (VECTOR_MODE_P (mode1))
20082     op1 = safe_vector_operand (op1, mode1);
20083
20084   target = gen_reg_rtx (SImode);
20085   emit_move_insn (target, const0_rtx);
20086   target = gen_rtx_SUBREG (QImode, target, 0);
20087
20088   if ((optimize && !register_operand (op0, mode0))
20089       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
20090     op0 = copy_to_mode_reg (mode0, op0);
20091   if ((optimize && !register_operand (op1, mode1))
20092       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
20093     op1 = copy_to_mode_reg (mode1, op1);
20094
20095   pat = GEN_FCN (d->icode) (op0, op1);
20096   if (! pat)
20097     return 0;
20098   emit_insn (pat);
20099   emit_insn (gen_rtx_SET (VOIDmode,
20100                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
20101                           gen_rtx_fmt_ee (comparison, QImode,
20102                                           SET_DEST (pat),
20103                                           const0_rtx)));
20104
20105   return SUBREG_REG (target);
20106 }
20107
20108 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
20109
20110 static rtx
20111 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
20112                           tree exp, rtx target)
20113 {
20114   rtx pat;
20115   tree arg0 = CALL_EXPR_ARG (exp, 0);
20116   tree arg1 = CALL_EXPR_ARG (exp, 1);
20117   tree arg2 = CALL_EXPR_ARG (exp, 2);
20118   tree arg3 = CALL_EXPR_ARG (exp, 3);
20119   tree arg4 = CALL_EXPR_ARG (exp, 4);
20120   rtx scratch0, scratch1;
20121   rtx op0 = expand_normal (arg0);
20122   rtx op1 = expand_normal (arg1);
20123   rtx op2 = expand_normal (arg2);
20124   rtx op3 = expand_normal (arg3);
20125   rtx op4 = expand_normal (arg4);
20126   enum machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
20127
20128   tmode0 = insn_data[d->icode].operand[0].mode;
20129   tmode1 = insn_data[d->icode].operand[1].mode;
20130   modev2 = insn_data[d->icode].operand[2].mode;
20131   modei3 = insn_data[d->icode].operand[3].mode;
20132   modev4 = insn_data[d->icode].operand[4].mode;
20133   modei5 = insn_data[d->icode].operand[5].mode;
20134   modeimm = insn_data[d->icode].operand[6].mode;
20135
20136   if (VECTOR_MODE_P (modev2))
20137     op0 = safe_vector_operand (op0, modev2);
20138   if (VECTOR_MODE_P (modev4))
20139     op2 = safe_vector_operand (op2, modev4);
20140
20141   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
20142     op0 = copy_to_mode_reg (modev2, op0);
20143   if (! (*insn_data[d->icode].operand[3].predicate) (op1, modei3))
20144     op1 = copy_to_mode_reg (modei3, op1);
20145   if ((optimize && !register_operand (op2, modev4))
20146       || !(*insn_data[d->icode].operand[4].predicate) (op2, modev4))
20147     op2 = copy_to_mode_reg (modev4, op2);
20148   if (! (*insn_data[d->icode].operand[5].predicate) (op3, modei5))
20149     op3 = copy_to_mode_reg (modei5, op3);
20150
20151   if (! (*insn_data[d->icode].operand[6].predicate) (op4, modeimm))
20152     {
20153       error ("the fifth argument must be a 8-bit immediate");
20154       return const0_rtx;
20155     }
20156
20157   if (d->code == IX86_BUILTIN_PCMPESTRI128)
20158     {
20159       if (optimize || !target
20160           || GET_MODE (target) != tmode0
20161           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
20162         target = gen_reg_rtx (tmode0);
20163
20164       scratch1 = gen_reg_rtx (tmode1);
20165
20166       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
20167     }
20168   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
20169     {
20170       if (optimize || !target
20171           || GET_MODE (target) != tmode1
20172           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
20173         target = gen_reg_rtx (tmode1);
20174
20175       scratch0 = gen_reg_rtx (tmode0);
20176
20177       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
20178     }
20179   else
20180     {
20181       gcc_assert (d->flag);
20182
20183       scratch0 = gen_reg_rtx (tmode0);
20184       scratch1 = gen_reg_rtx (tmode1);
20185
20186       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
20187     }
20188
20189   if (! pat)
20190     return 0;
20191
20192   emit_insn (pat);
20193
20194   if (d->flag)
20195     {
20196       target = gen_reg_rtx (SImode);
20197       emit_move_insn (target, const0_rtx);
20198       target = gen_rtx_SUBREG (QImode, target, 0);
20199
20200       emit_insn
20201         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
20202                       gen_rtx_fmt_ee (EQ, QImode,
20203                                       gen_rtx_REG ((enum machine_mode) d->flag,
20204                                                    FLAGS_REG),
20205                                       const0_rtx)));
20206       return SUBREG_REG (target);
20207     }
20208   else
20209     return target;
20210 }
20211
20212
20213 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
20214
20215 static rtx
20216 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
20217                           tree exp, rtx target)
20218 {
20219   rtx pat;
20220   tree arg0 = CALL_EXPR_ARG (exp, 0);
20221   tree arg1 = CALL_EXPR_ARG (exp, 1);
20222   tree arg2 = CALL_EXPR_ARG (exp, 2);
20223   rtx scratch0, scratch1;
20224   rtx op0 = expand_normal (arg0);
20225   rtx op1 = expand_normal (arg1);
20226   rtx op2 = expand_normal (arg2);
20227   enum machine_mode tmode0, tmode1, modev2, modev3, modeimm;
20228
20229   tmode0 = insn_data[d->icode].operand[0].mode;
20230   tmode1 = insn_data[d->icode].operand[1].mode;
20231   modev2 = insn_data[d->icode].operand[2].mode;
20232   modev3 = insn_data[d->icode].operand[3].mode;
20233   modeimm = insn_data[d->icode].operand[4].mode;
20234
20235   if (VECTOR_MODE_P (modev2))
20236     op0 = safe_vector_operand (op0, modev2);
20237   if (VECTOR_MODE_P (modev3))
20238     op1 = safe_vector_operand (op1, modev3);
20239
20240   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
20241     op0 = copy_to_mode_reg (modev2, op0);
20242   if ((optimize && !register_operand (op1, modev3))
20243       || !(*insn_data[d->icode].operand[3].predicate) (op1, modev3))
20244     op1 = copy_to_mode_reg (modev3, op1);
20245
20246   if (! (*insn_data[d->icode].operand[4].predicate) (op2, modeimm))
20247     {
20248       error ("the third argument must be a 8-bit immediate");
20249       return const0_rtx;
20250     }
20251
20252   if (d->code == IX86_BUILTIN_PCMPISTRI128)
20253     {
20254       if (optimize || !target
20255           || GET_MODE (target) != tmode0
20256           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
20257         target = gen_reg_rtx (tmode0);
20258
20259       scratch1 = gen_reg_rtx (tmode1);
20260
20261       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
20262     }
20263   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
20264     {
20265       if (optimize || !target
20266           || GET_MODE (target) != tmode1
20267           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
20268         target = gen_reg_rtx (tmode1);
20269
20270       scratch0 = gen_reg_rtx (tmode0);
20271
20272       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
20273     }
20274   else
20275     {
20276       gcc_assert (d->flag);
20277
20278       scratch0 = gen_reg_rtx (tmode0);
20279       scratch1 = gen_reg_rtx (tmode1);
20280
20281       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
20282     }
20283
20284   if (! pat)
20285     return 0;
20286
20287   emit_insn (pat);
20288
20289   if (d->flag)
20290     {
20291       target = gen_reg_rtx (SImode);
20292       emit_move_insn (target, const0_rtx);
20293       target = gen_rtx_SUBREG (QImode, target, 0);
20294
20295       emit_insn
20296         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
20297                       gen_rtx_fmt_ee (EQ, QImode,
20298                                       gen_rtx_REG ((enum machine_mode) d->flag,
20299                                                    FLAGS_REG),
20300                                       const0_rtx)));
20301       return SUBREG_REG (target);
20302     }
20303   else
20304     return target;
20305 }
20306
20307 /* Return the integer constant in ARG.  Constrain it to be in the range
20308    of the subparts of VEC_TYPE; issue an error if not.  */
20309
20310 static int
20311 get_element_number (tree vec_type, tree arg)
20312 {
20313   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
20314
20315   if (!host_integerp (arg, 1)
20316       || (elt = tree_low_cst (arg, 1), elt > max))
20317     {
20318       error ("selector must be an integer constant in the range 0..%wi", max);
20319       return 0;
20320     }
20321
20322   return elt;
20323 }
20324
20325 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
20326    ix86_expand_vector_init.  We DO have language-level syntax for this, in
20327    the form of  (type){ init-list }.  Except that since we can't place emms
20328    instructions from inside the compiler, we can't allow the use of MMX
20329    registers unless the user explicitly asks for it.  So we do *not* define
20330    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
20331    we have builtins invoked by mmintrin.h that gives us license to emit
20332    these sorts of instructions.  */
20333
20334 static rtx
20335 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
20336 {
20337   enum machine_mode tmode = TYPE_MODE (type);
20338   enum machine_mode inner_mode = GET_MODE_INNER (tmode);
20339   int i, n_elt = GET_MODE_NUNITS (tmode);
20340   rtvec v = rtvec_alloc (n_elt);
20341
20342   gcc_assert (VECTOR_MODE_P (tmode));
20343   gcc_assert (call_expr_nargs (exp) == n_elt);
20344
20345   for (i = 0; i < n_elt; ++i)
20346     {
20347       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
20348       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
20349     }
20350
20351   if (!target || !register_operand (target, tmode))
20352     target = gen_reg_rtx (tmode);
20353
20354   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
20355   return target;
20356 }
20357
20358 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
20359    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
20360    had a language-level syntax for referencing vector elements.  */
20361
20362 static rtx
20363 ix86_expand_vec_ext_builtin (tree exp, rtx target)
20364 {
20365   enum machine_mode tmode, mode0;
20366   tree arg0, arg1;
20367   int elt;
20368   rtx op0;
20369
20370   arg0 = CALL_EXPR_ARG (exp, 0);
20371   arg1 = CALL_EXPR_ARG (exp, 1);
20372
20373   op0 = expand_normal (arg0);
20374   elt = get_element_number (TREE_TYPE (arg0), arg1);
20375
20376   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
20377   mode0 = TYPE_MODE (TREE_TYPE (arg0));
20378   gcc_assert (VECTOR_MODE_P (mode0));
20379
20380   op0 = force_reg (mode0, op0);
20381
20382   if (optimize || !target || !register_operand (target, tmode))
20383     target = gen_reg_rtx (tmode);
20384
20385   ix86_expand_vector_extract (true, target, op0, elt);
20386
20387   return target;
20388 }
20389
20390 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
20391    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
20392    a language-level syntax for referencing vector elements.  */
20393
20394 static rtx
20395 ix86_expand_vec_set_builtin (tree exp)
20396 {
20397   enum machine_mode tmode, mode1;
20398   tree arg0, arg1, arg2;
20399   int elt;
20400   rtx op0, op1, target;
20401
20402   arg0 = CALL_EXPR_ARG (exp, 0);
20403   arg1 = CALL_EXPR_ARG (exp, 1);
20404   arg2 = CALL_EXPR_ARG (exp, 2);
20405
20406   tmode = TYPE_MODE (TREE_TYPE (arg0));
20407   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
20408   gcc_assert (VECTOR_MODE_P (tmode));
20409
20410   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
20411   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
20412   elt = get_element_number (TREE_TYPE (arg0), arg2);
20413
20414   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
20415     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
20416
20417   op0 = force_reg (tmode, op0);
20418   op1 = force_reg (mode1, op1);
20419
20420   /* OP0 is the source of these builtin functions and shouldn't be
20421      modified.  Create a copy, use it and return it as target.  */
20422   target = gen_reg_rtx (tmode);
20423   emit_move_insn (target, op0);
20424   ix86_expand_vector_set (true, target, op1, elt);
20425
20426   return target;
20427 }
20428
20429 /* Expand an expression EXP that calls a built-in function,
20430    with result going to TARGET if that's convenient
20431    (and in mode MODE if that's convenient).
20432    SUBTARGET may be used as the target for computing one of EXP's operands.
20433    IGNORE is nonzero if the value is to be ignored.  */
20434
20435 static rtx
20436 ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
20437                      enum machine_mode mode ATTRIBUTE_UNUSED,
20438                      int ignore ATTRIBUTE_UNUSED)
20439 {
20440   const struct builtin_description *d;
20441   size_t i;
20442   enum insn_code icode;
20443   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
20444   tree arg0, arg1, arg2, arg3;
20445   rtx op0, op1, op2, op3, pat;
20446   enum machine_mode tmode, mode0, mode1, mode2, mode3, mode4;
20447   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
20448
20449   switch (fcode)
20450     {
20451     case IX86_BUILTIN_EMMS:
20452       emit_insn (gen_mmx_emms ());
20453       return 0;
20454
20455     case IX86_BUILTIN_SFENCE:
20456       emit_insn (gen_sse_sfence ());
20457       return 0;
20458
20459     case IX86_BUILTIN_MASKMOVQ:
20460     case IX86_BUILTIN_MASKMOVDQU:
20461       icode = (fcode == IX86_BUILTIN_MASKMOVQ
20462                ? CODE_FOR_mmx_maskmovq
20463                : CODE_FOR_sse2_maskmovdqu);
20464       /* Note the arg order is different from the operand order.  */
20465       arg1 = CALL_EXPR_ARG (exp, 0);
20466       arg2 = CALL_EXPR_ARG (exp, 1);
20467       arg0 = CALL_EXPR_ARG (exp, 2);
20468       op0 = expand_normal (arg0);
20469       op1 = expand_normal (arg1);
20470       op2 = expand_normal (arg2);
20471       mode0 = insn_data[icode].operand[0].mode;
20472       mode1 = insn_data[icode].operand[1].mode;
20473       mode2 = insn_data[icode].operand[2].mode;
20474
20475       op0 = force_reg (Pmode, op0);
20476       op0 = gen_rtx_MEM (mode1, op0);
20477
20478       if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
20479         op0 = copy_to_mode_reg (mode0, op0);
20480       if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
20481         op1 = copy_to_mode_reg (mode1, op1);
20482       if (! (*insn_data[icode].operand[2].predicate) (op2, mode2))
20483         op2 = copy_to_mode_reg (mode2, op2);
20484       pat = GEN_FCN (icode) (op0, op1, op2);
20485       if (! pat)
20486         return 0;
20487       emit_insn (pat);
20488       return 0;
20489
20490     case IX86_BUILTIN_RSQRTF:
20491       return ix86_expand_unop1_builtin (CODE_FOR_rsqrtsf2, exp, target);
20492
20493     case IX86_BUILTIN_SQRTSS:
20494       return ix86_expand_unop1_builtin (CODE_FOR_sse_vmsqrtv4sf2, exp, target);
20495     case IX86_BUILTIN_RSQRTSS:
20496       return ix86_expand_unop1_builtin (CODE_FOR_sse_vmrsqrtv4sf2, exp, target);
20497     case IX86_BUILTIN_RCPSS:
20498       return ix86_expand_unop1_builtin (CODE_FOR_sse_vmrcpv4sf2, exp, target);
20499
20500     case IX86_BUILTIN_LOADUPS:
20501       return ix86_expand_unop_builtin (CODE_FOR_sse_movups, exp, target, 1);
20502
20503     case IX86_BUILTIN_STOREUPS:
20504       return ix86_expand_store_builtin (CODE_FOR_sse_movups, exp);
20505
20506     case IX86_BUILTIN_LOADHPS:
20507     case IX86_BUILTIN_LOADLPS:
20508     case IX86_BUILTIN_LOADHPD:
20509     case IX86_BUILTIN_LOADLPD:
20510       icode = (fcode == IX86_BUILTIN_LOADHPS ? CODE_FOR_sse_loadhps
20511                : fcode == IX86_BUILTIN_LOADLPS ? CODE_FOR_sse_loadlps
20512                : fcode == IX86_BUILTIN_LOADHPD ? CODE_FOR_sse2_loadhpd
20513                : CODE_FOR_sse2_loadlpd);
20514       arg0 = CALL_EXPR_ARG (exp, 0);
20515       arg1 = CALL_EXPR_ARG (exp, 1);
20516       op0 = expand_normal (arg0);
20517       op1 = expand_normal (arg1);
20518       tmode = insn_data[icode].operand[0].mode;
20519       mode0 = insn_data[icode].operand[1].mode;
20520       mode1 = insn_data[icode].operand[2].mode;
20521
20522       op0 = force_reg (mode0, op0);
20523       op1 = gen_rtx_MEM (mode1, copy_to_mode_reg (Pmode, op1));
20524       if (optimize || target == 0
20525           || GET_MODE (target) != tmode
20526           || !register_operand (target, tmode))
20527         target = gen_reg_rtx (tmode);
20528       pat = GEN_FCN (icode) (target, op0, op1);
20529       if (! pat)
20530         return 0;
20531       emit_insn (pat);
20532       return target;
20533
20534     case IX86_BUILTIN_STOREHPS:
20535     case IX86_BUILTIN_STORELPS:
20536       icode = (fcode == IX86_BUILTIN_STOREHPS ? CODE_FOR_sse_storehps
20537                : CODE_FOR_sse_storelps);
20538       arg0 = CALL_EXPR_ARG (exp, 0);
20539       arg1 = CALL_EXPR_ARG (exp, 1);
20540       op0 = expand_normal (arg0);
20541       op1 = expand_normal (arg1);
20542       mode0 = insn_data[icode].operand[0].mode;
20543       mode1 = insn_data[icode].operand[1].mode;
20544
20545       op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
20546       op1 = force_reg (mode1, op1);
20547
20548       pat = GEN_FCN (icode) (op0, op1);
20549       if (! pat)
20550         return 0;
20551       emit_insn (pat);
20552       return const0_rtx;
20553
20554     case IX86_BUILTIN_MOVNTPS:
20555       return ix86_expand_store_builtin (CODE_FOR_sse_movntv4sf, exp);
20556     case IX86_BUILTIN_MOVNTQ:
20557       return ix86_expand_store_builtin (CODE_FOR_sse_movntdi, exp);
20558
20559     case IX86_BUILTIN_LDMXCSR:
20560       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
20561       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
20562       emit_move_insn (target, op0);
20563       emit_insn (gen_sse_ldmxcsr (target));
20564       return 0;
20565
20566     case IX86_BUILTIN_STMXCSR:
20567       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
20568       emit_insn (gen_sse_stmxcsr (target));
20569       return copy_to_mode_reg (SImode, target);
20570
20571     case IX86_BUILTIN_SHUFPS:
20572     case IX86_BUILTIN_SHUFPD:
20573       icode = (fcode == IX86_BUILTIN_SHUFPS
20574                ? CODE_FOR_sse_shufps
20575                : CODE_FOR_sse2_shufpd);
20576       arg0 = CALL_EXPR_ARG (exp, 0);
20577       arg1 = CALL_EXPR_ARG (exp, 1);
20578       arg2 = CALL_EXPR_ARG (exp, 2);
20579       op0 = expand_normal (arg0);
20580       op1 = expand_normal (arg1);
20581       op2 = expand_normal (arg2);
20582       tmode = insn_data[icode].operand[0].mode;
20583       mode0 = insn_data[icode].operand[1].mode;
20584       mode1 = insn_data[icode].operand[2].mode;
20585       mode2 = insn_data[icode].operand[3].mode;
20586
20587       if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
20588         op0 = copy_to_mode_reg (mode0, op0);
20589       if ((optimize && !register_operand (op1, mode1))
20590           || !(*insn_data[icode].operand[2].predicate) (op1, mode1))
20591         op1 = copy_to_mode_reg (mode1, op1);
20592       if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
20593         {
20594           /* @@@ better error message */
20595           error ("mask must be an immediate");
20596           return gen_reg_rtx (tmode);
20597         }
20598       if (optimize || target == 0
20599           || GET_MODE (target) != tmode
20600           || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
20601         target = gen_reg_rtx (tmode);
20602       pat = GEN_FCN (icode) (target, op0, op1, op2);
20603       if (! pat)
20604         return 0;
20605       emit_insn (pat);
20606       return target;
20607
20608     case IX86_BUILTIN_PSHUFW:
20609     case IX86_BUILTIN_PSHUFD:
20610     case IX86_BUILTIN_PSHUFHW:
20611     case IX86_BUILTIN_PSHUFLW:
20612       icode = (  fcode == IX86_BUILTIN_PSHUFHW ? CODE_FOR_sse2_pshufhw
20613                : fcode == IX86_BUILTIN_PSHUFLW ? CODE_FOR_sse2_pshuflw
20614                : fcode == IX86_BUILTIN_PSHUFD ? CODE_FOR_sse2_pshufd
20615                : CODE_FOR_mmx_pshufw);
20616       arg0 = CALL_EXPR_ARG (exp, 0);
20617       arg1 = CALL_EXPR_ARG (exp, 1);
20618       op0 = expand_normal (arg0);
20619       op1 = expand_normal (arg1);
20620       tmode = insn_data[icode].operand[0].mode;
20621       mode1 = insn_data[icode].operand[1].mode;
20622       mode2 = insn_data[icode].operand[2].mode;
20623
20624       if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
20625         op0 = copy_to_mode_reg (mode1, op0);
20626       if (! (*insn_data[icode].operand[2].predicate) (op1, mode2))
20627         {
20628           /* @@@ better error message */
20629           error ("mask must be an immediate");
20630           return const0_rtx;
20631         }
20632       if (target == 0
20633           || GET_MODE (target) != tmode
20634           || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
20635         target = gen_reg_rtx (tmode);
20636       pat = GEN_FCN (icode) (target, op0, op1);
20637       if (! pat)
20638         return 0;
20639       emit_insn (pat);
20640       return target;
20641
20642     case IX86_BUILTIN_PSLLWI128:
20643       icode = CODE_FOR_ashlv8hi3;
20644       goto do_pshifti;
20645     case IX86_BUILTIN_PSLLDI128:
20646       icode = CODE_FOR_ashlv4si3;
20647       goto do_pshifti;
20648     case IX86_BUILTIN_PSLLQI128:
20649       icode = CODE_FOR_ashlv2di3;
20650       goto do_pshifti;
20651     case IX86_BUILTIN_PSRAWI128:
20652       icode = CODE_FOR_ashrv8hi3;
20653       goto do_pshifti;
20654     case IX86_BUILTIN_PSRADI128:
20655       icode = CODE_FOR_ashrv4si3;
20656       goto do_pshifti;
20657     case IX86_BUILTIN_PSRLWI128:
20658       icode = CODE_FOR_lshrv8hi3;
20659       goto do_pshifti;
20660     case IX86_BUILTIN_PSRLDI128:
20661       icode = CODE_FOR_lshrv4si3;
20662       goto do_pshifti;
20663     case IX86_BUILTIN_PSRLQI128:
20664       icode = CODE_FOR_lshrv2di3;
20665       goto do_pshifti;
20666     do_pshifti:
20667       arg0 = CALL_EXPR_ARG (exp, 0);
20668       arg1 = CALL_EXPR_ARG (exp, 1);
20669       op0 = expand_normal (arg0);
20670       op1 = expand_normal (arg1);
20671
20672       if (!CONST_INT_P (op1))
20673         {
20674           error ("shift must be an immediate");
20675           return const0_rtx;
20676         }
20677       if (INTVAL (op1) < 0 || INTVAL (op1) > 255)
20678         op1 = GEN_INT (255);
20679
20680       tmode = insn_data[icode].operand[0].mode;
20681       mode1 = insn_data[icode].operand[1].mode;
20682       if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
20683         op0 = copy_to_reg (op0);
20684
20685       target = gen_reg_rtx (tmode);
20686       pat = GEN_FCN (icode) (target, op0, op1);
20687       if (!pat)
20688         return 0;
20689       emit_insn (pat);
20690       return target;
20691
20692     case IX86_BUILTIN_PSLLW128:
20693       icode = CODE_FOR_ashlv8hi3;
20694       goto do_pshift;
20695     case IX86_BUILTIN_PSLLD128:
20696       icode = CODE_FOR_ashlv4si3;
20697       goto do_pshift;
20698     case IX86_BUILTIN_PSLLQ128:
20699       icode = CODE_FOR_ashlv2di3;
20700       goto do_pshift;
20701     case IX86_BUILTIN_PSRAW128:
20702       icode = CODE_FOR_ashrv8hi3;
20703       goto do_pshift;
20704     case IX86_BUILTIN_PSRAD128:
20705       icode = CODE_FOR_ashrv4si3;
20706       goto do_pshift;
20707     case IX86_BUILTIN_PSRLW128:
20708       icode = CODE_FOR_lshrv8hi3;
20709       goto do_pshift;
20710     case IX86_BUILTIN_PSRLD128:
20711       icode = CODE_FOR_lshrv4si3;
20712       goto do_pshift;
20713     case IX86_BUILTIN_PSRLQ128:
20714       icode = CODE_FOR_lshrv2di3;
20715       goto do_pshift;
20716     do_pshift:
20717       arg0 = CALL_EXPR_ARG (exp, 0);
20718       arg1 = CALL_EXPR_ARG (exp, 1);
20719       op0 = expand_normal (arg0);
20720       op1 = expand_normal (arg1);
20721
20722       tmode = insn_data[icode].operand[0].mode;
20723       mode1 = insn_data[icode].operand[1].mode;
20724
20725       if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
20726         op0 = copy_to_reg (op0);
20727
20728       op1 = simplify_gen_subreg (SImode, op1, GET_MODE (op1), 0);
20729       if (! (*insn_data[icode].operand[2].predicate) (op1, SImode))
20730         op1 = copy_to_reg (op1);
20731
20732       target = gen_reg_rtx (tmode);
20733       pat = GEN_FCN (icode) (target, op0, op1);
20734       if (!pat)
20735         return 0;
20736       emit_insn (pat);
20737       return target;
20738
20739     case IX86_BUILTIN_PSLLDQI128:
20740     case IX86_BUILTIN_PSRLDQI128:
20741       icode = (fcode == IX86_BUILTIN_PSLLDQI128 ? CODE_FOR_sse2_ashlti3
20742                : CODE_FOR_sse2_lshrti3);
20743       arg0 = CALL_EXPR_ARG (exp, 0);
20744       arg1 = CALL_EXPR_ARG (exp, 1);
20745       op0 = expand_normal (arg0);
20746       op1 = expand_normal (arg1);
20747       tmode = insn_data[icode].operand[0].mode;
20748       mode1 = insn_data[icode].operand[1].mode;
20749       mode2 = insn_data[icode].operand[2].mode;
20750
20751       if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
20752         {
20753           op0 = copy_to_reg (op0);
20754           op0 = simplify_gen_subreg (mode1, op0, GET_MODE (op0), 0);
20755         }
20756       if (! (*insn_data[icode].operand[2].predicate) (op1, mode2))
20757         {
20758           error ("shift must be an immediate");
20759           return const0_rtx;
20760         }
20761       target = gen_reg_rtx (V2DImode);
20762       pat = GEN_FCN (icode) (simplify_gen_subreg (tmode, target, V2DImode, 0),
20763                              op0, op1);
20764       if (! pat)
20765         return 0;
20766       emit_insn (pat);
20767       return target;
20768
20769     case IX86_BUILTIN_FEMMS:
20770       emit_insn (gen_mmx_femms ());
20771       return NULL_RTX;
20772
20773     case IX86_BUILTIN_PAVGUSB:
20774       return ix86_expand_binop_builtin (CODE_FOR_mmx_uavgv8qi3, exp, target);
20775
20776     case IX86_BUILTIN_PF2ID:
20777       return ix86_expand_unop_builtin (CODE_FOR_mmx_pf2id, exp, target, 0);
20778
20779     case IX86_BUILTIN_PFACC:
20780       return ix86_expand_binop_builtin (CODE_FOR_mmx_haddv2sf3, exp, target);
20781
20782     case IX86_BUILTIN_PFADD:
20783      return ix86_expand_binop_builtin (CODE_FOR_mmx_addv2sf3, exp, target);
20784
20785     case IX86_BUILTIN_PFCMPEQ:
20786       return ix86_expand_binop_builtin (CODE_FOR_mmx_eqv2sf3, exp, target);
20787
20788     case IX86_BUILTIN_PFCMPGE:
20789       return ix86_expand_binop_builtin (CODE_FOR_mmx_gev2sf3, exp, target);
20790
20791     case IX86_BUILTIN_PFCMPGT:
20792       return ix86_expand_binop_builtin (CODE_FOR_mmx_gtv2sf3, exp, target);
20793
20794     case IX86_BUILTIN_PFMAX:
20795       return ix86_expand_binop_builtin (CODE_FOR_mmx_smaxv2sf3, exp, target);
20796
20797     case IX86_BUILTIN_PFMIN:
20798       return ix86_expand_binop_builtin (CODE_FOR_mmx_sminv2sf3, exp, target);
20799
20800     case IX86_BUILTIN_PFMUL:
20801       return ix86_expand_binop_builtin (CODE_FOR_mmx_mulv2sf3, exp, target);
20802
20803     case IX86_BUILTIN_PFRCP:
20804       return ix86_expand_unop_builtin (CODE_FOR_mmx_rcpv2sf2, exp, target, 0);
20805
20806     case IX86_BUILTIN_PFRCPIT1:
20807       return ix86_expand_binop_builtin (CODE_FOR_mmx_rcpit1v2sf3, exp, target);
20808
20809     case IX86_BUILTIN_PFRCPIT2:
20810       return ix86_expand_binop_builtin (CODE_FOR_mmx_rcpit2v2sf3, exp, target);
20811
20812     case IX86_BUILTIN_PFRSQIT1:
20813       return ix86_expand_binop_builtin (CODE_FOR_mmx_rsqit1v2sf3, exp, target);
20814
20815     case IX86_BUILTIN_PFRSQRT:
20816       return ix86_expand_unop_builtin (CODE_FOR_mmx_rsqrtv2sf2, exp, target, 0);
20817
20818     case IX86_BUILTIN_PFSUB:
20819       return ix86_expand_binop_builtin (CODE_FOR_mmx_subv2sf3, exp, target);
20820
20821     case IX86_BUILTIN_PFSUBR:
20822       return ix86_expand_binop_builtin (CODE_FOR_mmx_subrv2sf3, exp, target);
20823
20824     case IX86_BUILTIN_PI2FD:
20825       return ix86_expand_unop_builtin (CODE_FOR_mmx_floatv2si2, exp, target, 0);
20826
20827     case IX86_BUILTIN_PMULHRW:
20828       return ix86_expand_binop_builtin (CODE_FOR_mmx_pmulhrwv4hi3, exp, target);
20829
20830     case IX86_BUILTIN_PF2IW:
20831       return ix86_expand_unop_builtin (CODE_FOR_mmx_pf2iw, exp, target, 0);
20832
20833     case IX86_BUILTIN_PFNACC:
20834       return ix86_expand_binop_builtin (CODE_FOR_mmx_hsubv2sf3, exp, target);
20835
20836     case IX86_BUILTIN_PFPNACC:
20837       return ix86_expand_binop_builtin (CODE_FOR_mmx_addsubv2sf3, exp, target);
20838
20839     case IX86_BUILTIN_PI2FW:
20840       return ix86_expand_unop_builtin (CODE_FOR_mmx_pi2fw, exp, target, 0);
20841
20842     case IX86_BUILTIN_PSWAPDSI:
20843       return ix86_expand_unop_builtin (CODE_FOR_mmx_pswapdv2si2, exp, target, 0);
20844
20845     case IX86_BUILTIN_PSWAPDSF:
20846       return ix86_expand_unop_builtin (CODE_FOR_mmx_pswapdv2sf2, exp, target, 0);
20847
20848     case IX86_BUILTIN_SQRTSD:
20849       return ix86_expand_unop1_builtin (CODE_FOR_sse2_vmsqrtv2df2, exp, target);
20850     case IX86_BUILTIN_LOADUPD:
20851       return ix86_expand_unop_builtin (CODE_FOR_sse2_movupd, exp, target, 1);
20852     case IX86_BUILTIN_STOREUPD:
20853       return ix86_expand_store_builtin (CODE_FOR_sse2_movupd, exp);
20854
20855     case IX86_BUILTIN_MFENCE:
20856         emit_insn (gen_sse2_mfence ());
20857         return 0;
20858     case IX86_BUILTIN_LFENCE:
20859         emit_insn (gen_sse2_lfence ());
20860         return 0;
20861
20862     case IX86_BUILTIN_CLFLUSH:
20863         arg0 = CALL_EXPR_ARG (exp, 0);
20864         op0 = expand_normal (arg0);
20865         icode = CODE_FOR_sse2_clflush;
20866         if (! (*insn_data[icode].operand[0].predicate) (op0, Pmode))
20867             op0 = copy_to_mode_reg (Pmode, op0);
20868
20869         emit_insn (gen_sse2_clflush (op0));
20870         return 0;
20871
20872     case IX86_BUILTIN_MOVNTPD:
20873       return ix86_expand_store_builtin (CODE_FOR_sse2_movntv2df, exp);
20874     case IX86_BUILTIN_MOVNTDQ:
20875       return ix86_expand_store_builtin (CODE_FOR_sse2_movntv2di, exp);
20876     case IX86_BUILTIN_MOVNTI:
20877       return ix86_expand_store_builtin (CODE_FOR_sse2_movntsi, exp);
20878
20879     case IX86_BUILTIN_LOADDQU:
20880       return ix86_expand_unop_builtin (CODE_FOR_sse2_movdqu, exp, target, 1);
20881     case IX86_BUILTIN_STOREDQU:
20882       return ix86_expand_store_builtin (CODE_FOR_sse2_movdqu, exp);
20883
20884     case IX86_BUILTIN_MONITOR:
20885       arg0 = CALL_EXPR_ARG (exp, 0);
20886       arg1 = CALL_EXPR_ARG (exp, 1);
20887       arg2 = CALL_EXPR_ARG (exp, 2);
20888       op0 = expand_normal (arg0);
20889       op1 = expand_normal (arg1);
20890       op2 = expand_normal (arg2);
20891       if (!REG_P (op0))
20892         op0 = copy_to_mode_reg (Pmode, op0);
20893       if (!REG_P (op1))
20894         op1 = copy_to_mode_reg (SImode, op1);
20895       if (!REG_P (op2))
20896         op2 = copy_to_mode_reg (SImode, op2);
20897       if (!TARGET_64BIT)
20898         emit_insn (gen_sse3_monitor (op0, op1, op2));
20899       else
20900         emit_insn (gen_sse3_monitor64 (op0, op1, op2));
20901       return 0;
20902
20903     case IX86_BUILTIN_MWAIT:
20904       arg0 = CALL_EXPR_ARG (exp, 0);
20905       arg1 = CALL_EXPR_ARG (exp, 1);
20906       op0 = expand_normal (arg0);
20907       op1 = expand_normal (arg1);
20908       if (!REG_P (op0))
20909         op0 = copy_to_mode_reg (SImode, op0);
20910       if (!REG_P (op1))
20911         op1 = copy_to_mode_reg (SImode, op1);
20912       emit_insn (gen_sse3_mwait (op0, op1));
20913       return 0;
20914
20915     case IX86_BUILTIN_LDDQU:
20916       return ix86_expand_unop_builtin (CODE_FOR_sse3_lddqu, exp,
20917                                        target, 1);
20918
20919     case IX86_BUILTIN_PALIGNR:
20920     case IX86_BUILTIN_PALIGNR128:
20921       if (fcode == IX86_BUILTIN_PALIGNR)
20922         {
20923           icode = CODE_FOR_ssse3_palignrdi;
20924           mode = DImode;
20925         }
20926       else
20927         {
20928           icode = CODE_FOR_ssse3_palignrti;
20929           mode = V2DImode;
20930         }
20931       arg0 = CALL_EXPR_ARG (exp, 0);
20932       arg1 = CALL_EXPR_ARG (exp, 1);
20933       arg2 = CALL_EXPR_ARG (exp, 2);
20934       op0 = expand_expr (arg0, NULL_RTX, VOIDmode, EXPAND_NORMAL);
20935       op1 = expand_expr (arg1, NULL_RTX, VOIDmode, EXPAND_NORMAL);
20936       op2 = expand_expr (arg2, NULL_RTX, VOIDmode, EXPAND_NORMAL);
20937       tmode = insn_data[icode].operand[0].mode;
20938       mode1 = insn_data[icode].operand[1].mode;
20939       mode2 = insn_data[icode].operand[2].mode;
20940       mode3 = insn_data[icode].operand[3].mode;
20941
20942       if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
20943         {
20944           op0 = copy_to_reg (op0);
20945           op0 = simplify_gen_subreg (mode1, op0, GET_MODE (op0), 0);
20946         }
20947       if (! (*insn_data[icode].operand[2].predicate) (op1, mode2))
20948         {
20949           op1 = copy_to_reg (op1);
20950           op1 = simplify_gen_subreg (mode2, op1, GET_MODE (op1), 0);
20951         }
20952       if (! (*insn_data[icode].operand[3].predicate) (op2, mode3))
20953         {
20954           error ("shift must be an immediate");
20955           return const0_rtx;
20956         }
20957       target = gen_reg_rtx (mode);
20958       pat = GEN_FCN (icode) (simplify_gen_subreg (tmode, target, mode, 0),
20959                              op0, op1, op2);
20960       if (! pat)
20961         return 0;
20962       emit_insn (pat);
20963       return target;
20964
20965     case IX86_BUILTIN_MOVNTDQA:
20966       return ix86_expand_unop_builtin (CODE_FOR_sse4_1_movntdqa, exp,
20967                                        target, 1);
20968
20969     case IX86_BUILTIN_MOVNTSD:
20970       return ix86_expand_store_builtin (CODE_FOR_sse4a_vmmovntv2df, exp);
20971
20972     case IX86_BUILTIN_MOVNTSS:
20973       return ix86_expand_store_builtin (CODE_FOR_sse4a_vmmovntv4sf, exp);
20974
20975     case IX86_BUILTIN_INSERTQ:
20976     case IX86_BUILTIN_EXTRQ:
20977       icode = (fcode == IX86_BUILTIN_EXTRQ
20978                ? CODE_FOR_sse4a_extrq
20979                : CODE_FOR_sse4a_insertq);
20980       arg0 = CALL_EXPR_ARG (exp, 0);
20981       arg1 = CALL_EXPR_ARG (exp, 1);
20982       op0 = expand_normal (arg0);
20983       op1 = expand_normal (arg1);
20984       tmode = insn_data[icode].operand[0].mode;
20985       mode1 = insn_data[icode].operand[1].mode;
20986       mode2 = insn_data[icode].operand[2].mode;
20987       if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
20988         op0 = copy_to_mode_reg (mode1, op0);
20989       if (! (*insn_data[icode].operand[2].predicate) (op1, mode2))
20990         op1 = copy_to_mode_reg (mode2, op1);
20991       if (optimize || target == 0
20992           || GET_MODE (target) != tmode
20993           || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
20994         target = gen_reg_rtx (tmode);
20995       pat = GEN_FCN (icode) (target, op0, op1);
20996       if (! pat)
20997         return NULL_RTX;
20998       emit_insn (pat);
20999       return target;
21000
21001     case IX86_BUILTIN_EXTRQI:
21002       icode = CODE_FOR_sse4a_extrqi;
21003       arg0 = CALL_EXPR_ARG (exp, 0);
21004       arg1 = CALL_EXPR_ARG (exp, 1);
21005       arg2 = CALL_EXPR_ARG (exp, 2);
21006       op0 = expand_normal (arg0);
21007       op1 = expand_normal (arg1);
21008       op2 = expand_normal (arg2);
21009       tmode = insn_data[icode].operand[0].mode;
21010       mode1 = insn_data[icode].operand[1].mode;
21011       mode2 = insn_data[icode].operand[2].mode;
21012       mode3 = insn_data[icode].operand[3].mode;
21013       if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
21014         op0 = copy_to_mode_reg (mode1, op0);
21015       if (! (*insn_data[icode].operand[2].predicate) (op1, mode2))
21016         {
21017           error ("index mask must be an immediate");
21018           return gen_reg_rtx (tmode);
21019         }
21020       if (! (*insn_data[icode].operand[3].predicate) (op2, mode3))
21021         {
21022           error ("length mask must be an immediate");
21023           return gen_reg_rtx (tmode);
21024         }
21025       if (optimize || target == 0
21026           || GET_MODE (target) != tmode
21027           || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
21028         target = gen_reg_rtx (tmode);
21029       pat = GEN_FCN (icode) (target, op0, op1, op2);
21030       if (! pat)
21031         return NULL_RTX;
21032       emit_insn (pat);
21033       return target;
21034
21035     case IX86_BUILTIN_INSERTQI:
21036       icode = CODE_FOR_sse4a_insertqi;
21037       arg0 = CALL_EXPR_ARG (exp, 0);
21038       arg1 = CALL_EXPR_ARG (exp, 1);
21039       arg2 = CALL_EXPR_ARG (exp, 2);
21040       arg3 = CALL_EXPR_ARG (exp, 3);
21041       op0 = expand_normal (arg0);
21042       op1 = expand_normal (arg1);
21043       op2 = expand_normal (arg2);
21044       op3 = expand_normal (arg3);
21045       tmode = insn_data[icode].operand[0].mode;
21046       mode1 = insn_data[icode].operand[1].mode;
21047       mode2 = insn_data[icode].operand[2].mode;
21048       mode3 = insn_data[icode].operand[3].mode;
21049       mode4 = insn_data[icode].operand[4].mode;
21050
21051       if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
21052         op0 = copy_to_mode_reg (mode1, op0);
21053
21054       if (! (*insn_data[icode].operand[2].predicate) (op1, mode2))
21055         op1 = copy_to_mode_reg (mode2, op1);
21056
21057       if (! (*insn_data[icode].operand[3].predicate) (op2, mode3))
21058         {
21059           error ("index mask must be an immediate");
21060           return gen_reg_rtx (tmode);
21061         }
21062       if (! (*insn_data[icode].operand[4].predicate) (op3, mode4))
21063         {
21064           error ("length mask must be an immediate");
21065           return gen_reg_rtx (tmode);
21066         }
21067       if (optimize || target == 0
21068           || GET_MODE (target) != tmode
21069           || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
21070         target = gen_reg_rtx (tmode);
21071       pat = GEN_FCN (icode) (target, op0, op1, op2, op3);
21072       if (! pat)
21073         return NULL_RTX;
21074       emit_insn (pat);
21075       return target;
21076
21077     case IX86_BUILTIN_VEC_INIT_V2SI:
21078     case IX86_BUILTIN_VEC_INIT_V4HI:
21079     case IX86_BUILTIN_VEC_INIT_V8QI:
21080       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
21081
21082     case IX86_BUILTIN_VEC_EXT_V2DF:
21083     case IX86_BUILTIN_VEC_EXT_V2DI:
21084     case IX86_BUILTIN_VEC_EXT_V4SF:
21085     case IX86_BUILTIN_VEC_EXT_V4SI:
21086     case IX86_BUILTIN_VEC_EXT_V8HI:
21087     case IX86_BUILTIN_VEC_EXT_V2SI:
21088     case IX86_BUILTIN_VEC_EXT_V4HI:
21089     case IX86_BUILTIN_VEC_EXT_V16QI:
21090       return ix86_expand_vec_ext_builtin (exp, target);
21091
21092     case IX86_BUILTIN_VEC_SET_V2DI:
21093     case IX86_BUILTIN_VEC_SET_V4SF:
21094     case IX86_BUILTIN_VEC_SET_V4SI:
21095     case IX86_BUILTIN_VEC_SET_V8HI:
21096     case IX86_BUILTIN_VEC_SET_V4HI:
21097     case IX86_BUILTIN_VEC_SET_V16QI:
21098       return ix86_expand_vec_set_builtin (exp);
21099
21100     case IX86_BUILTIN_INFQ:
21101       {
21102         REAL_VALUE_TYPE inf;
21103         rtx tmp;
21104
21105         real_inf (&inf);
21106         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
21107
21108         tmp = validize_mem (force_const_mem (mode, tmp));
21109
21110         if (target == 0)
21111           target = gen_reg_rtx (mode);
21112
21113         emit_move_insn (target, tmp);
21114         return target;
21115       }
21116
21117     case IX86_BUILTIN_FABSQ:
21118       return ix86_expand_unop_builtin (CODE_FOR_abstf2, exp, target, 0);
21119
21120     case IX86_BUILTIN_COPYSIGNQ:
21121       return ix86_expand_binop_builtin (CODE_FOR_copysigntf3, exp, target);
21122
21123     default:
21124       break;
21125     }
21126
21127   for (i = 0, d = bdesc_sse_3arg;
21128        i < ARRAY_SIZE (bdesc_sse_3arg);
21129        i++, d++)
21130     if (d->code == fcode)
21131       return ix86_expand_sse_4_operands_builtin (d->icode, exp,
21132                                                  target);
21133
21134   for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
21135     if (d->code == fcode)
21136       {
21137         /* Compares are treated specially.  */
21138         if (d->icode == CODE_FOR_sse_maskcmpv4sf3
21139             || d->icode == CODE_FOR_sse_vmmaskcmpv4sf3
21140             || d->icode == CODE_FOR_sse2_maskcmpv2df3
21141             || d->icode == CODE_FOR_sse2_vmmaskcmpv2df3)
21142           return ix86_expand_sse_compare (d, exp, target);
21143
21144         return ix86_expand_binop_builtin (d->icode, exp, target);
21145       }
21146
21147   for (i = 0, d = bdesc_1arg; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
21148     if (d->code == fcode)
21149       return ix86_expand_unop_builtin (d->icode, exp, target, 0);
21150
21151   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
21152     if (d->code == fcode)
21153       return ix86_expand_sse_comi (d, exp, target);
21154
21155   for (i = 0, d = bdesc_ptest; i < ARRAY_SIZE (bdesc_ptest); i++, d++)
21156     if (d->code == fcode)
21157       return ix86_expand_sse_ptest (d, exp, target);
21158
21159   for (i = 0, d = bdesc_crc32; i < ARRAY_SIZE (bdesc_crc32); i++, d++)
21160     if (d->code == fcode)
21161       return ix86_expand_crc32 (d->icode, exp, target);
21162
21163   for (i = 0, d = bdesc_pcmpestr;
21164        i < ARRAY_SIZE (bdesc_pcmpestr);
21165        i++, d++)
21166     if (d->code == fcode)
21167       return ix86_expand_sse_pcmpestr (d, exp, target);
21168
21169   for (i = 0, d = bdesc_pcmpistr;
21170        i < ARRAY_SIZE (bdesc_pcmpistr);
21171        i++, d++)
21172     if (d->code == fcode)
21173       return ix86_expand_sse_pcmpistr (d, exp, target);
21174
21175   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
21176     if (d->code == fcode)
21177       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
21178                                             (enum multi_arg_type)d->flag,
21179                                             d->comparison);
21180
21181   gcc_unreachable ();
21182 }
21183
21184 /* Returns a function decl for a vectorized version of the builtin function
21185    with builtin function code FN and the result vector type TYPE, or NULL_TREE
21186    if it is not available.  */
21187
21188 static tree
21189 ix86_builtin_vectorized_function (unsigned int fn, tree type_out,
21190                                   tree type_in)
21191 {
21192   enum machine_mode in_mode, out_mode;
21193   int in_n, out_n;
21194
21195   if (TREE_CODE (type_out) != VECTOR_TYPE
21196       || TREE_CODE (type_in) != VECTOR_TYPE)
21197     return NULL_TREE;
21198
21199   out_mode = TYPE_MODE (TREE_TYPE (type_out));
21200   out_n = TYPE_VECTOR_SUBPARTS (type_out);
21201   in_mode = TYPE_MODE (TREE_TYPE (type_in));
21202   in_n = TYPE_VECTOR_SUBPARTS (type_in);
21203
21204   switch (fn)
21205     {
21206     case BUILT_IN_SQRT:
21207       if (out_mode == DFmode && out_n == 2
21208           && in_mode == DFmode && in_n == 2)
21209         return ix86_builtins[IX86_BUILTIN_SQRTPD];
21210       break;
21211
21212     case BUILT_IN_SQRTF:
21213       if (out_mode == SFmode && out_n == 4
21214           && in_mode == SFmode && in_n == 4)
21215         return ix86_builtins[IX86_BUILTIN_SQRTPS];
21216       break;
21217
21218     case BUILT_IN_LRINT:
21219       if (out_mode == SImode && out_n == 4
21220           && in_mode == DFmode && in_n == 2)
21221         return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
21222       break;
21223
21224     case BUILT_IN_LRINTF:
21225       if (out_mode == SImode && out_n == 4
21226           && in_mode == SFmode && in_n == 4)
21227         return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
21228       break;
21229
21230     default:
21231       ;
21232     }
21233
21234   /* Dispatch to a handler for a vectorization library.  */
21235   if (ix86_veclib_handler)
21236     return (*ix86_veclib_handler)(fn, type_out, type_in);
21237
21238   return NULL_TREE;
21239 }
21240
21241 /* Handler for an ACML-style interface to a library with vectorized
21242    intrinsics.  */
21243
21244 static tree
21245 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
21246 {
21247   char name[20] = "__vr.._";
21248   tree fntype, new_fndecl, args;
21249   unsigned arity;
21250   const char *bname;
21251   enum machine_mode el_mode, in_mode;
21252   int n, in_n;
21253
21254   /* The ACML is 64bits only and suitable for unsafe math only as
21255      it does not correctly support parts of IEEE with the required
21256      precision such as denormals.  */
21257   if (!TARGET_64BIT
21258       || !flag_unsafe_math_optimizations)
21259     return NULL_TREE;
21260
21261   el_mode = TYPE_MODE (TREE_TYPE (type_out));
21262   n = TYPE_VECTOR_SUBPARTS (type_out);
21263   in_mode = TYPE_MODE (TREE_TYPE (type_in));
21264   in_n = TYPE_VECTOR_SUBPARTS (type_in);
21265   if (el_mode != in_mode
21266       || n != in_n)
21267     return NULL_TREE;
21268
21269   switch (fn)
21270     {
21271     case BUILT_IN_SIN:
21272     case BUILT_IN_COS:
21273     case BUILT_IN_EXP:
21274     case BUILT_IN_LOG:
21275     case BUILT_IN_LOG2:
21276     case BUILT_IN_LOG10:
21277       name[4] = 'd';
21278       name[5] = '2';
21279       if (el_mode != DFmode
21280           || n != 2)
21281         return NULL_TREE;
21282       break;
21283
21284     case BUILT_IN_SINF:
21285     case BUILT_IN_COSF:
21286     case BUILT_IN_EXPF:
21287     case BUILT_IN_POWF:
21288     case BUILT_IN_LOGF:
21289     case BUILT_IN_LOG2F:
21290     case BUILT_IN_LOG10F:
21291       name[4] = 's';
21292       name[5] = '4';
21293       if (el_mode != SFmode
21294           || n != 4)
21295         return NULL_TREE;
21296       break;
21297
21298     default:
21299       return NULL_TREE;
21300     }
21301
21302   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
21303   sprintf (name + 7, "%s", bname+10);
21304
21305   arity = 0;
21306   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
21307        args = TREE_CHAIN (args))
21308     arity++;
21309
21310   if (arity == 1)
21311     fntype = build_function_type_list (type_out, type_in, NULL);
21312   else
21313     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
21314
21315   /* Build a function declaration for the vectorized function.  */
21316   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
21317   TREE_PUBLIC (new_fndecl) = 1;
21318   DECL_EXTERNAL (new_fndecl) = 1;
21319   DECL_IS_NOVOPS (new_fndecl) = 1;
21320   TREE_READONLY (new_fndecl) = 1;
21321
21322   return new_fndecl;
21323 }
21324
21325
21326 /* Returns a decl of a function that implements conversion of the
21327    input vector of type TYPE, or NULL_TREE if it is not available.  */
21328
21329 static tree
21330 ix86_vectorize_builtin_conversion (unsigned int code, tree type)
21331 {
21332   if (TREE_CODE (type) != VECTOR_TYPE)
21333     return NULL_TREE;
21334
21335   switch (code)
21336     {
21337     case FLOAT_EXPR:
21338       switch (TYPE_MODE (type))
21339         {
21340         case V4SImode:
21341           return ix86_builtins[IX86_BUILTIN_CVTDQ2PS];
21342         default:
21343           return NULL_TREE;
21344         }
21345
21346     case FIX_TRUNC_EXPR:
21347       switch (TYPE_MODE (type))
21348         {
21349         case V4SFmode:
21350           return ix86_builtins[IX86_BUILTIN_CVTTPS2DQ];
21351         default:
21352           return NULL_TREE;
21353         }
21354     default:
21355       return NULL_TREE;
21356
21357     }
21358 }
21359
21360 /* Returns a code for a target-specific builtin that implements
21361    reciprocal of the function, or NULL_TREE if not available.  */
21362
21363 static tree
21364 ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
21365                          bool sqrt ATTRIBUTE_UNUSED)
21366 {
21367   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_size
21368          && flag_finite_math_only && !flag_trapping_math
21369          && flag_unsafe_math_optimizations))
21370     return NULL_TREE;
21371
21372   if (md_fn)
21373     /* Machine dependent builtins.  */
21374     switch (fn)
21375       {
21376         /* Vectorized version of sqrt to rsqrt conversion.  */
21377       case IX86_BUILTIN_SQRTPS:
21378         return ix86_builtins[IX86_BUILTIN_RSQRTPS];
21379
21380       default:
21381         return NULL_TREE;
21382       }
21383   else
21384     /* Normal builtins.  */
21385     switch (fn)
21386       {
21387         /* Sqrt to rsqrt conversion.  */
21388       case BUILT_IN_SQRTF:
21389         return ix86_builtins[IX86_BUILTIN_RSQRTF];
21390
21391       default:
21392         return NULL_TREE;
21393       }
21394 }
21395
21396 /* Store OPERAND to the memory after reload is completed.  This means
21397    that we can't easily use assign_stack_local.  */
21398 rtx
21399 ix86_force_to_memory (enum machine_mode mode, rtx operand)
21400 {
21401   rtx result;
21402
21403   gcc_assert (reload_completed);
21404   if (TARGET_RED_ZONE)
21405     {
21406       result = gen_rtx_MEM (mode,
21407                             gen_rtx_PLUS (Pmode,
21408                                           stack_pointer_rtx,
21409                                           GEN_INT (-RED_ZONE_SIZE)));
21410       emit_move_insn (result, operand);
21411     }
21412   else if (!TARGET_RED_ZONE && TARGET_64BIT)
21413     {
21414       switch (mode)
21415         {
21416         case HImode:
21417         case SImode:
21418           operand = gen_lowpart (DImode, operand);
21419           /* FALLTHRU */
21420         case DImode:
21421           emit_insn (
21422                       gen_rtx_SET (VOIDmode,
21423                                    gen_rtx_MEM (DImode,
21424                                                 gen_rtx_PRE_DEC (DImode,
21425                                                         stack_pointer_rtx)),
21426                                    operand));
21427           break;
21428         default:
21429           gcc_unreachable ();
21430         }
21431       result = gen_rtx_MEM (mode, stack_pointer_rtx);
21432     }
21433   else
21434     {
21435       switch (mode)
21436         {
21437         case DImode:
21438           {
21439             rtx operands[2];
21440             split_di (&operand, 1, operands, operands + 1);
21441             emit_insn (
21442                         gen_rtx_SET (VOIDmode,
21443                                      gen_rtx_MEM (SImode,
21444                                                   gen_rtx_PRE_DEC (Pmode,
21445                                                         stack_pointer_rtx)),
21446                                      operands[1]));
21447             emit_insn (
21448                         gen_rtx_SET (VOIDmode,
21449                                      gen_rtx_MEM (SImode,
21450                                                   gen_rtx_PRE_DEC (Pmode,
21451                                                         stack_pointer_rtx)),
21452                                      operands[0]));
21453           }
21454           break;
21455         case HImode:
21456           /* Store HImodes as SImodes.  */
21457           operand = gen_lowpart (SImode, operand);
21458           /* FALLTHRU */
21459         case SImode:
21460           emit_insn (
21461                       gen_rtx_SET (VOIDmode,
21462                                    gen_rtx_MEM (GET_MODE (operand),
21463                                                 gen_rtx_PRE_DEC (SImode,
21464                                                         stack_pointer_rtx)),
21465                                    operand));
21466           break;
21467         default:
21468           gcc_unreachable ();
21469         }
21470       result = gen_rtx_MEM (mode, stack_pointer_rtx);
21471     }
21472   return result;
21473 }
21474
21475 /* Free operand from the memory.  */
21476 void
21477 ix86_free_from_memory (enum machine_mode mode)
21478 {
21479   if (!TARGET_RED_ZONE)
21480     {
21481       int size;
21482
21483       if (mode == DImode || TARGET_64BIT)
21484         size = 8;
21485       else
21486         size = 4;
21487       /* Use LEA to deallocate stack space.  In peephole2 it will be converted
21488          to pop or add instruction if registers are available.  */
21489       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
21490                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
21491                                             GEN_INT (size))));
21492     }
21493 }
21494
21495 /* Put float CONST_DOUBLE in the constant pool instead of fp regs.
21496    QImode must go into class Q_REGS.
21497    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
21498    movdf to do mem-to-mem moves through integer regs.  */
21499 enum reg_class
21500 ix86_preferred_reload_class (rtx x, enum reg_class regclass)
21501 {
21502   enum machine_mode mode = GET_MODE (x);
21503
21504   /* We're only allowed to return a subclass of CLASS.  Many of the
21505      following checks fail for NO_REGS, so eliminate that early.  */
21506   if (regclass == NO_REGS)
21507     return NO_REGS;
21508
21509   /* All classes can load zeros.  */
21510   if (x == CONST0_RTX (mode))
21511     return regclass;
21512
21513   /* Force constants into memory if we are loading a (nonzero) constant into
21514      an MMX or SSE register.  This is because there are no MMX/SSE instructions
21515      to load from a constant.  */
21516   if (CONSTANT_P (x)
21517       && (MAYBE_MMX_CLASS_P (regclass) || MAYBE_SSE_CLASS_P (regclass)))
21518     return NO_REGS;
21519
21520   /* Prefer SSE regs only, if we can use them for math.  */
21521   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
21522     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
21523
21524   /* Floating-point constants need more complex checks.  */
21525   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
21526     {
21527       /* General regs can load everything.  */
21528       if (reg_class_subset_p (regclass, GENERAL_REGS))
21529         return regclass;
21530
21531       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
21532          zero above.  We only want to wind up preferring 80387 registers if
21533          we plan on doing computation with them.  */
21534       if (TARGET_80387
21535           && standard_80387_constant_p (x))
21536         {
21537           /* Limit class to non-sse.  */
21538           if (regclass == FLOAT_SSE_REGS)
21539             return FLOAT_REGS;
21540           if (regclass == FP_TOP_SSE_REGS)
21541             return FP_TOP_REG;
21542           if (regclass == FP_SECOND_SSE_REGS)
21543             return FP_SECOND_REG;
21544           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
21545             return regclass;
21546         }
21547
21548       return NO_REGS;
21549     }
21550
21551   /* Generally when we see PLUS here, it's the function invariant
21552      (plus soft-fp const_int).  Which can only be computed into general
21553      regs.  */
21554   if (GET_CODE (x) == PLUS)
21555     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
21556
21557   /* QImode constants are easy to load, but non-constant QImode data
21558      must go into Q_REGS.  */
21559   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
21560     {
21561       if (reg_class_subset_p (regclass, Q_REGS))
21562         return regclass;
21563       if (reg_class_subset_p (Q_REGS, regclass))
21564         return Q_REGS;
21565       return NO_REGS;
21566     }
21567
21568   return regclass;
21569 }
21570
21571 /* Discourage putting floating-point values in SSE registers unless
21572    SSE math is being used, and likewise for the 387 registers.  */
21573 enum reg_class
21574 ix86_preferred_output_reload_class (rtx x, enum reg_class regclass)
21575 {
21576   enum machine_mode mode = GET_MODE (x);
21577
21578   /* Restrict the output reload class to the register bank that we are doing
21579      math on.  If we would like not to return a subset of CLASS, reject this
21580      alternative: if reload cannot do this, it will still use its choice.  */
21581   mode = GET_MODE (x);
21582   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
21583     return MAYBE_SSE_CLASS_P (regclass) ? SSE_REGS : NO_REGS;
21584
21585   if (X87_FLOAT_MODE_P (mode))
21586     {
21587       if (regclass == FP_TOP_SSE_REGS)
21588         return FP_TOP_REG;
21589       else if (regclass == FP_SECOND_SSE_REGS)
21590         return FP_SECOND_REG;
21591       else
21592         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
21593     }
21594
21595   return regclass;
21596 }
21597
21598 /* If we are copying between general and FP registers, we need a memory
21599    location. The same is true for SSE and MMX registers.
21600
21601    To optimize register_move_cost performance, allow inline variant.
21602
21603    The macro can't work reliably when one of the CLASSES is class containing
21604    registers from multiple units (SSE, MMX, integer).  We avoid this by never
21605    combining those units in single alternative in the machine description.
21606    Ensure that this constraint holds to avoid unexpected surprises.
21607
21608    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
21609    enforce these sanity checks.  */
21610
21611 static inline int
21612 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
21613                               enum machine_mode mode, int strict)
21614 {
21615   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
21616       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
21617       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
21618       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
21619       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
21620       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
21621     {
21622       gcc_assert (!strict);
21623       return true;
21624     }
21625
21626   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
21627     return true;
21628
21629   /* ??? This is a lie.  We do have moves between mmx/general, and for
21630      mmx/sse2.  But by saying we need secondary memory we discourage the
21631      register allocator from using the mmx registers unless needed.  */
21632   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
21633     return true;
21634
21635   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
21636     {
21637       /* SSE1 doesn't have any direct moves from other classes.  */
21638       if (!TARGET_SSE2)
21639         return true;
21640
21641       /* If the target says that inter-unit moves are more expensive
21642          than moving through memory, then don't generate them.  */
21643       if (!TARGET_INTER_UNIT_MOVES)
21644         return true;
21645
21646       /* Between SSE and general, we have moves no larger than word size.  */
21647       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
21648         return true;
21649     }
21650
21651   return false;
21652 }
21653
21654 int
21655 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
21656                               enum machine_mode mode, int strict)
21657 {
21658   return inline_secondary_memory_needed (class1, class2, mode, strict);
21659 }
21660
21661 /* Return true if the registers in CLASS cannot represent the change from
21662    modes FROM to TO.  */
21663
21664 bool
21665 ix86_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
21666                                enum reg_class regclass)
21667 {
21668   if (from == to)
21669     return false;
21670
21671   /* x87 registers can't do subreg at all, as all values are reformatted
21672      to extended precision.  */
21673   if (MAYBE_FLOAT_CLASS_P (regclass))
21674     return true;
21675
21676   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
21677     {
21678       /* Vector registers do not support QI or HImode loads.  If we don't
21679          disallow a change to these modes, reload will assume it's ok to
21680          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
21681          the vec_dupv4hi pattern.  */
21682       if (GET_MODE_SIZE (from) < 4)
21683         return true;
21684
21685       /* Vector registers do not support subreg with nonzero offsets, which
21686          are otherwise valid for integer registers.  Since we can't see
21687          whether we have a nonzero offset from here, prohibit all
21688          nonparadoxical subregs changing size.  */
21689       if (GET_MODE_SIZE (to) < GET_MODE_SIZE (from))
21690         return true;
21691     }
21692
21693   return false;
21694 }
21695
21696 /* Return the cost of moving data of mode M between a
21697    register and memory.  A value of 2 is the default; this cost is
21698    relative to those in `REGISTER_MOVE_COST'.
21699
21700    This function is used extensively by register_move_cost that is used to
21701    build tables at startup.  Make it inline in this case.
21702    When IN is 2, return maximum of in and out move cost.
21703
21704    If moving between registers and memory is more expensive than
21705    between two registers, you should define this macro to express the
21706    relative cost.
21707
21708    Model also increased moving costs of QImode registers in non
21709    Q_REGS classes.
21710  */
21711 static inline int
21712 inline_memory_move_cost (enum machine_mode mode, enum reg_class regclass,
21713                          int in)
21714 {
21715   int cost;
21716   if (FLOAT_CLASS_P (regclass))
21717     {
21718       int index;
21719       switch (mode)
21720         {
21721           case SFmode:
21722             index = 0;
21723             break;
21724           case DFmode:
21725             index = 1;
21726             break;
21727           case XFmode:
21728             index = 2;
21729             break;
21730           default:
21731             return 100;
21732         }
21733       if (in == 2)
21734         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
21735       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
21736     }
21737   if (SSE_CLASS_P (regclass))
21738     {
21739       int index;
21740       switch (GET_MODE_SIZE (mode))
21741         {
21742           case 4:
21743             index = 0;
21744             break;
21745           case 8:
21746             index = 1;
21747             break;
21748           case 16:
21749             index = 2;
21750             break;
21751           default:
21752             return 100;
21753         }
21754       if (in == 2)
21755         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
21756       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
21757     }
21758   if (MMX_CLASS_P (regclass))
21759     {
21760       int index;
21761       switch (GET_MODE_SIZE (mode))
21762         {
21763           case 4:
21764             index = 0;
21765             break;
21766           case 8:
21767             index = 1;
21768             break;
21769           default:
21770             return 100;
21771         }
21772       if (in)
21773         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
21774       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
21775     }
21776   switch (GET_MODE_SIZE (mode))
21777     {
21778       case 1:
21779         if (Q_CLASS_P (regclass) || TARGET_64BIT)
21780           {
21781             if (!in)
21782               return ix86_cost->int_store[0];
21783             if (TARGET_PARTIAL_REG_DEPENDENCY && !optimize_size)
21784               cost = ix86_cost->movzbl_load;
21785             else
21786               cost = ix86_cost->int_load[0];
21787             if (in == 2)
21788               return MAX (cost, ix86_cost->int_store[0]);
21789             return cost;
21790           }
21791         else
21792           {
21793            if (in == 2)
21794              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
21795            if (in)
21796              return ix86_cost->movzbl_load;
21797            else
21798              return ix86_cost->int_store[0] + 4;
21799           }
21800         break;
21801       case 2:
21802         if (in == 2)
21803           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
21804         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
21805       default:
21806         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
21807         if (mode == TFmode)
21808           mode = XFmode;
21809         if (in == 2)
21810           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
21811         else if (in)
21812           cost = ix86_cost->int_load[2];
21813         else
21814           cost = ix86_cost->int_store[2];
21815         return (cost * (((int) GET_MODE_SIZE (mode)
21816                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
21817     }
21818 }
21819
21820 int
21821 ix86_memory_move_cost (enum machine_mode mode, enum reg_class regclass, int in)
21822 {
21823   return inline_memory_move_cost (mode, regclass, in);
21824 }
21825
21826
21827 /* Return the cost of moving data from a register in class CLASS1 to
21828    one in class CLASS2.
21829
21830    It is not required that the cost always equal 2 when FROM is the same as TO;
21831    on some machines it is expensive to move between registers if they are not
21832    general registers.  */
21833
21834 int
21835 ix86_register_move_cost (enum machine_mode mode, enum reg_class class1,
21836                          enum reg_class class2)
21837 {
21838   /* In case we require secondary memory, compute cost of the store followed
21839      by load.  In order to avoid bad register allocation choices, we need
21840      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
21841
21842   if (inline_secondary_memory_needed (class1, class2, mode, 0))
21843     {
21844       int cost = 1;
21845
21846       cost += inline_memory_move_cost (mode, class1, 2);
21847       cost += inline_memory_move_cost (mode, class2, 2);
21848
21849       /* In case of copying from general_purpose_register we may emit multiple
21850          stores followed by single load causing memory size mismatch stall.
21851          Count this as arbitrarily high cost of 20.  */
21852       if (CLASS_MAX_NREGS (class1, mode) > CLASS_MAX_NREGS (class2, mode))
21853         cost += 20;
21854
21855       /* In the case of FP/MMX moves, the registers actually overlap, and we
21856          have to switch modes in order to treat them differently.  */
21857       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
21858           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
21859         cost += 20;
21860
21861       return cost;
21862     }
21863
21864   /* Moves between SSE/MMX and integer unit are expensive.  */
21865   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
21866       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
21867
21868     /* ??? By keeping returned value relatively high, we limit the number
21869        of moves between integer and MMX/SSE registers for all targets.
21870        Additionally, high value prevents problem with x86_modes_tieable_p(),
21871        where integer modes in MMX/SSE registers are not tieable
21872        because of missing QImode and HImode moves to, from or between
21873        MMX/SSE registers.  */
21874     return MAX (ix86_cost->mmxsse_to_integer, 8);
21875
21876   if (MAYBE_FLOAT_CLASS_P (class1))
21877     return ix86_cost->fp_move;
21878   if (MAYBE_SSE_CLASS_P (class1))
21879     return ix86_cost->sse_move;
21880   if (MAYBE_MMX_CLASS_P (class1))
21881     return ix86_cost->mmx_move;
21882   return 2;
21883 }
21884
21885 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE.  */
21886
21887 bool
21888 ix86_hard_regno_mode_ok (int regno, enum machine_mode mode)
21889 {
21890   /* Flags and only flags can only hold CCmode values.  */
21891   if (CC_REGNO_P (regno))
21892     return GET_MODE_CLASS (mode) == MODE_CC;
21893   if (GET_MODE_CLASS (mode) == MODE_CC
21894       || GET_MODE_CLASS (mode) == MODE_RANDOM
21895       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
21896     return 0;
21897   if (FP_REGNO_P (regno))
21898     return VALID_FP_MODE_P (mode);
21899   if (SSE_REGNO_P (regno))
21900     {
21901       /* We implement the move patterns for all vector modes into and
21902          out of SSE registers, even when no operation instructions
21903          are available.  */
21904       return (VALID_SSE_REG_MODE (mode)
21905               || VALID_SSE2_REG_MODE (mode)
21906               || VALID_MMX_REG_MODE (mode)
21907               || VALID_MMX_REG_MODE_3DNOW (mode));
21908     }
21909   if (MMX_REGNO_P (regno))
21910     {
21911       /* We implement the move patterns for 3DNOW modes even in MMX mode,
21912          so if the register is available at all, then we can move data of
21913          the given mode into or out of it.  */
21914       return (VALID_MMX_REG_MODE (mode)
21915               || VALID_MMX_REG_MODE_3DNOW (mode));
21916     }
21917
21918   if (mode == QImode)
21919     {
21920       /* Take care for QImode values - they can be in non-QI regs,
21921          but then they do cause partial register stalls.  */
21922       if (regno < 4 || TARGET_64BIT)
21923         return 1;
21924       if (!TARGET_PARTIAL_REG_STALL)
21925         return 1;
21926       return reload_in_progress || reload_completed;
21927     }
21928   /* We handle both integer and floats in the general purpose registers.  */
21929   else if (VALID_INT_MODE_P (mode))
21930     return 1;
21931   else if (VALID_FP_MODE_P (mode))
21932     return 1;
21933   else if (VALID_DFP_MODE_P (mode))
21934     return 1;
21935   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
21936      on to use that value in smaller contexts, this can easily force a
21937      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
21938      supporting DImode, allow it.  */
21939   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
21940     return 1;
21941
21942   return 0;
21943 }
21944
21945 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
21946    tieable integer mode.  */
21947
21948 static bool
21949 ix86_tieable_integer_mode_p (enum machine_mode mode)
21950 {
21951   switch (mode)
21952     {
21953     case HImode:
21954     case SImode:
21955       return true;
21956
21957     case QImode:
21958       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
21959
21960     case DImode:
21961       return TARGET_64BIT;
21962
21963     default:
21964       return false;
21965     }
21966 }
21967
21968 /* Return true if MODE1 is accessible in a register that can hold MODE2
21969    without copying.  That is, all register classes that can hold MODE2
21970    can also hold MODE1.  */
21971
21972 bool
21973 ix86_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
21974 {
21975   if (mode1 == mode2)
21976     return true;
21977
21978   if (ix86_tieable_integer_mode_p (mode1)
21979       && ix86_tieable_integer_mode_p (mode2))
21980     return true;
21981
21982   /* MODE2 being XFmode implies fp stack or general regs, which means we
21983      can tie any smaller floating point modes to it.  Note that we do not
21984      tie this with TFmode.  */
21985   if (mode2 == XFmode)
21986     return mode1 == SFmode || mode1 == DFmode;
21987
21988   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
21989      that we can tie it with SFmode.  */
21990   if (mode2 == DFmode)
21991     return mode1 == SFmode;
21992
21993   /* If MODE2 is only appropriate for an SSE register, then tie with
21994      any other mode acceptable to SSE registers.  */
21995   if (GET_MODE_SIZE (mode2) == 16
21996       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
21997     return (GET_MODE_SIZE (mode1) == 16
21998             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
21999
22000   /* If MODE2 is appropriate for an MMX register, then tie
22001      with any other mode acceptable to MMX registers.  */
22002   if (GET_MODE_SIZE (mode2) == 8
22003       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
22004     return (GET_MODE_SIZE (mode1) == 8
22005             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
22006
22007   return false;
22008 }
22009
22010 /* Compute a (partial) cost for rtx X.  Return true if the complete
22011    cost has been computed, and false if subexpressions should be
22012    scanned.  In either case, *TOTAL contains the cost result.  */
22013
22014 static bool
22015 ix86_rtx_costs (rtx x, int code, int outer_code_i, int *total)
22016 {
22017   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
22018   enum machine_mode mode = GET_MODE (x);
22019
22020   switch (code)
22021     {
22022     case CONST_INT:
22023     case CONST:
22024     case LABEL_REF:
22025     case SYMBOL_REF:
22026       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
22027         *total = 3;
22028       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
22029         *total = 2;
22030       else if (flag_pic && SYMBOLIC_CONST (x)
22031                && (!TARGET_64BIT
22032                    || (!GET_CODE (x) != LABEL_REF
22033                        && (GET_CODE (x) != SYMBOL_REF
22034                            || !SYMBOL_REF_LOCAL_P (x)))))
22035         *total = 1;
22036       else
22037         *total = 0;
22038       return true;
22039
22040     case CONST_DOUBLE:
22041       if (mode == VOIDmode)
22042         *total = 0;
22043       else
22044         switch (standard_80387_constant_p (x))
22045           {
22046           case 1: /* 0.0 */
22047             *total = 1;
22048             break;
22049           default: /* Other constants */
22050             *total = 2;
22051             break;
22052           case 0:
22053           case -1:
22054             /* Start with (MEM (SYMBOL_REF)), since that's where
22055                it'll probably end up.  Add a penalty for size.  */
22056             *total = (COSTS_N_INSNS (1)
22057                       + (flag_pic != 0 && !TARGET_64BIT)
22058                       + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
22059             break;
22060           }
22061       return true;
22062
22063     case ZERO_EXTEND:
22064       /* The zero extensions is often completely free on x86_64, so make
22065          it as cheap as possible.  */
22066       if (TARGET_64BIT && mode == DImode
22067           && GET_MODE (XEXP (x, 0)) == SImode)
22068         *total = 1;
22069       else if (TARGET_ZERO_EXTEND_WITH_AND)
22070         *total = ix86_cost->add;
22071       else
22072         *total = ix86_cost->movzx;
22073       return false;
22074
22075     case SIGN_EXTEND:
22076       *total = ix86_cost->movsx;
22077       return false;
22078
22079     case ASHIFT:
22080       if (CONST_INT_P (XEXP (x, 1))
22081           && (GET_MODE (XEXP (x, 0)) != DImode || TARGET_64BIT))
22082         {
22083           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
22084           if (value == 1)
22085             {
22086               *total = ix86_cost->add;
22087               return false;
22088             }
22089           if ((value == 2 || value == 3)
22090               && ix86_cost->lea <= ix86_cost->shift_const)
22091             {
22092               *total = ix86_cost->lea;
22093               return false;
22094             }
22095         }
22096       /* FALLTHRU */
22097
22098     case ROTATE:
22099     case ASHIFTRT:
22100     case LSHIFTRT:
22101     case ROTATERT:
22102       if (!TARGET_64BIT && GET_MODE (XEXP (x, 0)) == DImode)
22103         {
22104           if (CONST_INT_P (XEXP (x, 1)))
22105             {
22106               if (INTVAL (XEXP (x, 1)) > 32)
22107                 *total = ix86_cost->shift_const + COSTS_N_INSNS (2);
22108               else
22109                 *total = ix86_cost->shift_const * 2;
22110             }
22111           else
22112             {
22113               if (GET_CODE (XEXP (x, 1)) == AND)
22114                 *total = ix86_cost->shift_var * 2;
22115               else
22116                 *total = ix86_cost->shift_var * 6 + COSTS_N_INSNS (2);
22117             }
22118         }
22119       else
22120         {
22121           if (CONST_INT_P (XEXP (x, 1)))
22122             *total = ix86_cost->shift_const;
22123           else
22124             *total = ix86_cost->shift_var;
22125         }
22126       return false;
22127
22128     case MULT:
22129       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
22130         {
22131           /* ??? SSE scalar cost should be used here.  */
22132           *total = ix86_cost->fmul;
22133           return false;
22134         }
22135       else if (X87_FLOAT_MODE_P (mode))
22136         {
22137           *total = ix86_cost->fmul;
22138           return false;
22139         }
22140       else if (FLOAT_MODE_P (mode))
22141         {
22142           /* ??? SSE vector cost should be used here.  */
22143           *total = ix86_cost->fmul;
22144           return false;
22145         }
22146       else
22147         {
22148           rtx op0 = XEXP (x, 0);
22149           rtx op1 = XEXP (x, 1);
22150           int nbits;
22151           if (CONST_INT_P (XEXP (x, 1)))
22152             {
22153               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
22154               for (nbits = 0; value != 0; value &= value - 1)
22155                 nbits++;
22156             }
22157           else
22158             /* This is arbitrary.  */
22159             nbits = 7;
22160
22161           /* Compute costs correctly for widening multiplication.  */
22162           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op1) == ZERO_EXTEND)
22163               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
22164                  == GET_MODE_SIZE (mode))
22165             {
22166               int is_mulwiden = 0;
22167               enum machine_mode inner_mode = GET_MODE (op0);
22168
22169               if (GET_CODE (op0) == GET_CODE (op1))
22170                 is_mulwiden = 1, op1 = XEXP (op1, 0);
22171               else if (CONST_INT_P (op1))
22172                 {
22173                   if (GET_CODE (op0) == SIGN_EXTEND)
22174                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
22175                                   == INTVAL (op1);
22176                   else
22177                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
22178                 }
22179
22180               if (is_mulwiden)
22181                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
22182             }
22183
22184           *total = (ix86_cost->mult_init[MODE_INDEX (mode)]
22185                     + nbits * ix86_cost->mult_bit
22186                     + rtx_cost (op0, outer_code) + rtx_cost (op1, outer_code));
22187
22188           return true;
22189         }
22190
22191     case DIV:
22192     case UDIV:
22193     case MOD:
22194     case UMOD:
22195       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
22196         /* ??? SSE cost should be used here.  */
22197         *total = ix86_cost->fdiv;
22198       else if (X87_FLOAT_MODE_P (mode))
22199         *total = ix86_cost->fdiv;
22200       else if (FLOAT_MODE_P (mode))
22201         /* ??? SSE vector cost should be used here.  */
22202         *total = ix86_cost->fdiv;
22203       else
22204         *total = ix86_cost->divide[MODE_INDEX (mode)];
22205       return false;
22206
22207     case PLUS:
22208       if (GET_MODE_CLASS (mode) == MODE_INT
22209                && GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (Pmode))
22210         {
22211           if (GET_CODE (XEXP (x, 0)) == PLUS
22212               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
22213               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
22214               && CONSTANT_P (XEXP (x, 1)))
22215             {
22216               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
22217               if (val == 2 || val == 4 || val == 8)
22218                 {
22219                   *total = ix86_cost->lea;
22220                   *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code);
22221                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
22222                                       outer_code);
22223                   *total += rtx_cost (XEXP (x, 1), outer_code);
22224                   return true;
22225                 }
22226             }
22227           else if (GET_CODE (XEXP (x, 0)) == MULT
22228                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
22229             {
22230               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
22231               if (val == 2 || val == 4 || val == 8)
22232                 {
22233                   *total = ix86_cost->lea;
22234                   *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code);
22235                   *total += rtx_cost (XEXP (x, 1), outer_code);
22236                   return true;
22237                 }
22238             }
22239           else if (GET_CODE (XEXP (x, 0)) == PLUS)
22240             {
22241               *total = ix86_cost->lea;
22242               *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code);
22243               *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code);
22244               *total += rtx_cost (XEXP (x, 1), outer_code);
22245               return true;
22246             }
22247         }
22248       /* FALLTHRU */
22249
22250     case MINUS:
22251       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
22252         {
22253           /* ??? SSE cost should be used here.  */
22254           *total = ix86_cost->fadd;
22255           return false;
22256         }
22257       else if (X87_FLOAT_MODE_P (mode))
22258         {
22259           *total = ix86_cost->fadd;
22260           return false;
22261         }
22262       else if (FLOAT_MODE_P (mode))
22263         {
22264           /* ??? SSE vector cost should be used here.  */
22265           *total = ix86_cost->fadd;
22266           return false;
22267         }
22268       /* FALLTHRU */
22269
22270     case AND:
22271     case IOR:
22272     case XOR:
22273       if (!TARGET_64BIT && mode == DImode)
22274         {
22275           *total = (ix86_cost->add * 2
22276                     + (rtx_cost (XEXP (x, 0), outer_code)
22277                        << (GET_MODE (XEXP (x, 0)) != DImode))
22278                     + (rtx_cost (XEXP (x, 1), outer_code)
22279                        << (GET_MODE (XEXP (x, 1)) != DImode)));
22280           return true;
22281         }
22282       /* FALLTHRU */
22283
22284     case NEG:
22285       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
22286         {
22287           /* ??? SSE cost should be used here.  */
22288           *total = ix86_cost->fchs;
22289           return false;
22290         }
22291       else if (X87_FLOAT_MODE_P (mode))
22292         {
22293           *total = ix86_cost->fchs;
22294           return false;
22295         }
22296       else if (FLOAT_MODE_P (mode))
22297         {
22298           /* ??? SSE vector cost should be used here.  */
22299           *total = ix86_cost->fchs;
22300           return false;
22301         }
22302       /* FALLTHRU */
22303
22304     case NOT:
22305       if (!TARGET_64BIT && mode == DImode)
22306         *total = ix86_cost->add * 2;
22307       else
22308         *total = ix86_cost->add;
22309       return false;
22310
22311     case COMPARE:
22312       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
22313           && XEXP (XEXP (x, 0), 1) == const1_rtx
22314           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
22315           && XEXP (x, 1) == const0_rtx)
22316         {
22317           /* This kind of construct is implemented using test[bwl].
22318              Treat it as if we had an AND.  */
22319           *total = (ix86_cost->add
22320                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code)
22321                     + rtx_cost (const1_rtx, outer_code));
22322           return true;
22323         }
22324       return false;
22325
22326     case FLOAT_EXTEND:
22327       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
22328         *total = 0;
22329       return false;
22330
22331     case ABS:
22332       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
22333         /* ??? SSE cost should be used here.  */
22334         *total = ix86_cost->fabs;
22335       else if (X87_FLOAT_MODE_P (mode))
22336         *total = ix86_cost->fabs;
22337       else if (FLOAT_MODE_P (mode))
22338         /* ??? SSE vector cost should be used here.  */
22339         *total = ix86_cost->fabs;
22340       return false;
22341
22342     case SQRT:
22343       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
22344         /* ??? SSE cost should be used here.  */
22345         *total = ix86_cost->fsqrt;
22346       else if (X87_FLOAT_MODE_P (mode))
22347         *total = ix86_cost->fsqrt;
22348       else if (FLOAT_MODE_P (mode))
22349         /* ??? SSE vector cost should be used here.  */
22350         *total = ix86_cost->fsqrt;
22351       return false;
22352
22353     case UNSPEC:
22354       if (XINT (x, 1) == UNSPEC_TP)
22355         *total = 0;
22356       return false;
22357
22358     default:
22359       return false;
22360     }
22361 }
22362
22363 #if TARGET_MACHO
22364
22365 static int current_machopic_label_num;
22366
22367 /* Given a symbol name and its associated stub, write out the
22368    definition of the stub.  */
22369
22370 void
22371 machopic_output_stub (FILE *file, const char *symb, const char *stub)
22372 {
22373   unsigned int length;
22374   char *binder_name, *symbol_name, lazy_ptr_name[32];
22375   int label = ++current_machopic_label_num;
22376
22377   /* For 64-bit we shouldn't get here.  */
22378   gcc_assert (!TARGET_64BIT);
22379
22380   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
22381   symb = (*targetm.strip_name_encoding) (symb);
22382
22383   length = strlen (stub);
22384   binder_name = alloca (length + 32);
22385   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
22386
22387   length = strlen (symb);
22388   symbol_name = alloca (length + 32);
22389   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
22390
22391   sprintf (lazy_ptr_name, "L%d$lz", label);
22392
22393   if (MACHOPIC_PURE)
22394     switch_to_section (darwin_sections[machopic_picsymbol_stub_section]);
22395   else
22396     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
22397
22398   fprintf (file, "%s:\n", stub);
22399   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
22400
22401   if (MACHOPIC_PURE)
22402     {
22403       fprintf (file, "\tcall\tLPC$%d\nLPC$%d:\tpopl\t%%eax\n", label, label);
22404       fprintf (file, "\tmovl\t%s-LPC$%d(%%eax),%%edx\n", lazy_ptr_name, label);
22405       fprintf (file, "\tjmp\t*%%edx\n");
22406     }
22407   else
22408     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
22409
22410   fprintf (file, "%s:\n", binder_name);
22411
22412   if (MACHOPIC_PURE)
22413     {
22414       fprintf (file, "\tlea\t%s-LPC$%d(%%eax),%%eax\n", lazy_ptr_name, label);
22415       fprintf (file, "\tpushl\t%%eax\n");
22416     }
22417   else
22418     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
22419
22420   fprintf (file, "\tjmp\tdyld_stub_binding_helper\n");
22421
22422   switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
22423   fprintf (file, "%s:\n", lazy_ptr_name);
22424   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
22425   fprintf (file, "\t.long %s\n", binder_name);
22426 }
22427
22428 void
22429 darwin_x86_file_end (void)
22430 {
22431   darwin_file_end ();
22432   ix86_file_end ();
22433 }
22434 #endif /* TARGET_MACHO */
22435
22436 /* Order the registers for register allocator.  */
22437
22438 void
22439 x86_order_regs_for_local_alloc (void)
22440 {
22441    int pos = 0;
22442    int i;
22443
22444    /* First allocate the local general purpose registers.  */
22445    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
22446      if (GENERAL_REGNO_P (i) && call_used_regs[i])
22447         reg_alloc_order [pos++] = i;
22448
22449    /* Global general purpose registers.  */
22450    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
22451      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
22452         reg_alloc_order [pos++] = i;
22453
22454    /* x87 registers come first in case we are doing FP math
22455       using them.  */
22456    if (!TARGET_SSE_MATH)
22457      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
22458        reg_alloc_order [pos++] = i;
22459
22460    /* SSE registers.  */
22461    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
22462      reg_alloc_order [pos++] = i;
22463    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
22464      reg_alloc_order [pos++] = i;
22465
22466    /* x87 registers.  */
22467    if (TARGET_SSE_MATH)
22468      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
22469        reg_alloc_order [pos++] = i;
22470
22471    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
22472      reg_alloc_order [pos++] = i;
22473
22474    /* Initialize the rest of array as we do not allocate some registers
22475       at all.  */
22476    while (pos < FIRST_PSEUDO_REGISTER)
22477      reg_alloc_order [pos++] = 0;
22478 }
22479
22480 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
22481    struct attribute_spec.handler.  */
22482 static tree
22483 ix86_handle_struct_attribute (tree *node, tree name,
22484                               tree args ATTRIBUTE_UNUSED,
22485                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
22486 {
22487   tree *type = NULL;
22488   if (DECL_P (*node))
22489     {
22490       if (TREE_CODE (*node) == TYPE_DECL)
22491         type = &TREE_TYPE (*node);
22492     }
22493   else
22494     type = node;
22495
22496   if (!(type && (TREE_CODE (*type) == RECORD_TYPE
22497                  || TREE_CODE (*type) == UNION_TYPE)))
22498     {
22499       warning (OPT_Wattributes, "%qs attribute ignored",
22500                IDENTIFIER_POINTER (name));
22501       *no_add_attrs = true;
22502     }
22503
22504   else if ((is_attribute_p ("ms_struct", name)
22505             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
22506            || ((is_attribute_p ("gcc_struct", name)
22507                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
22508     {
22509       warning (OPT_Wattributes, "%qs incompatible attribute ignored",
22510                IDENTIFIER_POINTER (name));
22511       *no_add_attrs = true;
22512     }
22513
22514   return NULL_TREE;
22515 }
22516
22517 static bool
22518 ix86_ms_bitfield_layout_p (const_tree record_type)
22519 {
22520   return (TARGET_MS_BITFIELD_LAYOUT &&
22521           !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
22522     || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
22523 }
22524
22525 /* Returns an expression indicating where the this parameter is
22526    located on entry to the FUNCTION.  */
22527
22528 static rtx
22529 x86_this_parameter (tree function)
22530 {
22531   tree type = TREE_TYPE (function);
22532   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
22533
22534   if (TARGET_64BIT)
22535     {
22536       const int *parm_regs;
22537
22538       if (TARGET_64BIT_MS_ABI)
22539         parm_regs = x86_64_ms_abi_int_parameter_registers;
22540       else
22541         parm_regs = x86_64_int_parameter_registers;
22542       return gen_rtx_REG (DImode, parm_regs[aggr]);
22543     }
22544
22545   if (ix86_function_regparm (type, function) > 0 && !stdarg_p (type))
22546     {
22547       int regno = AX_REG;
22548       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
22549         regno = CX_REG;
22550       return gen_rtx_REG (SImode, regno);
22551     }
22552
22553   return gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx, aggr ? 8 : 4));
22554 }
22555
22556 /* Determine whether x86_output_mi_thunk can succeed.  */
22557
22558 static bool
22559 x86_can_output_mi_thunk (const_tree thunk ATTRIBUTE_UNUSED,
22560                          HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
22561                          HOST_WIDE_INT vcall_offset, const_tree function)
22562 {
22563   /* 64-bit can handle anything.  */
22564   if (TARGET_64BIT)
22565     return true;
22566
22567   /* For 32-bit, everything's fine if we have one free register.  */
22568   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
22569     return true;
22570
22571   /* Need a free register for vcall_offset.  */
22572   if (vcall_offset)
22573     return false;
22574
22575   /* Need a free register for GOT references.  */
22576   if (flag_pic && !(*targetm.binds_local_p) (function))
22577     return false;
22578
22579   /* Otherwise ok.  */
22580   return true;
22581 }
22582
22583 /* Output the assembler code for a thunk function.  THUNK_DECL is the
22584    declaration for the thunk function itself, FUNCTION is the decl for
22585    the target function.  DELTA is an immediate constant offset to be
22586    added to THIS.  If VCALL_OFFSET is nonzero, the word at
22587    *(*this + vcall_offset) should be added to THIS.  */
22588
22589 static void
22590 x86_output_mi_thunk (FILE *file ATTRIBUTE_UNUSED,
22591                      tree thunk ATTRIBUTE_UNUSED, HOST_WIDE_INT delta,
22592                      HOST_WIDE_INT vcall_offset, tree function)
22593 {
22594   rtx xops[3];
22595   rtx this_param = x86_this_parameter (function);
22596   rtx this_reg, tmp;
22597
22598   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
22599      pull it in now and let DELTA benefit.  */
22600   if (REG_P (this_param))
22601     this_reg = this_param;
22602   else if (vcall_offset)
22603     {
22604       /* Put the this parameter into %eax.  */
22605       xops[0] = this_param;
22606       xops[1] = this_reg = gen_rtx_REG (Pmode, AX_REG);
22607       output_asm_insn ("mov{l}\t{%0, %1|%1, %0}", xops);
22608     }
22609   else
22610     this_reg = NULL_RTX;
22611
22612   /* Adjust the this parameter by a fixed constant.  */
22613   if (delta)
22614     {
22615       xops[0] = GEN_INT (delta);
22616       xops[1] = this_reg ? this_reg : this_param;
22617       if (TARGET_64BIT)
22618         {
22619           if (!x86_64_general_operand (xops[0], DImode))
22620             {
22621               tmp = gen_rtx_REG (DImode, R10_REG);
22622               xops[1] = tmp;
22623               output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", xops);
22624               xops[0] = tmp;
22625               xops[1] = this_param;
22626             }
22627           output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
22628         }
22629       else
22630         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
22631     }
22632
22633   /* Adjust the this parameter by a value stored in the vtable.  */
22634   if (vcall_offset)
22635     {
22636       if (TARGET_64BIT)
22637         tmp = gen_rtx_REG (DImode, R10_REG);
22638       else
22639         {
22640           int tmp_regno = CX_REG;
22641           if (lookup_attribute ("fastcall",
22642                                 TYPE_ATTRIBUTES (TREE_TYPE (function))))
22643             tmp_regno = AX_REG;
22644           tmp = gen_rtx_REG (SImode, tmp_regno);
22645         }
22646
22647       xops[0] = gen_rtx_MEM (Pmode, this_reg);
22648       xops[1] = tmp;
22649       if (TARGET_64BIT)
22650         output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
22651       else
22652         output_asm_insn ("mov{l}\t{%0, %1|%1, %0}", xops);
22653
22654       /* Adjust the this parameter.  */
22655       xops[0] = gen_rtx_MEM (Pmode, plus_constant (tmp, vcall_offset));
22656       if (TARGET_64BIT && !memory_operand (xops[0], Pmode))
22657         {
22658           rtx tmp2 = gen_rtx_REG (DImode, R11_REG);
22659           xops[0] = GEN_INT (vcall_offset);
22660           xops[1] = tmp2;
22661           output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
22662           xops[0] = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, tmp, tmp2));
22663         }
22664       xops[1] = this_reg;
22665       if (TARGET_64BIT)
22666         output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
22667       else
22668         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
22669     }
22670
22671   /* If necessary, drop THIS back to its stack slot.  */
22672   if (this_reg && this_reg != this_param)
22673     {
22674       xops[0] = this_reg;
22675       xops[1] = this_param;
22676       output_asm_insn ("mov{l}\t{%0, %1|%1, %0}", xops);
22677     }
22678
22679   xops[0] = XEXP (DECL_RTL (function), 0);
22680   if (TARGET_64BIT)
22681     {
22682       if (!flag_pic || (*targetm.binds_local_p) (function))
22683         output_asm_insn ("jmp\t%P0", xops);
22684       /* All thunks should be in the same object as their target,
22685          and thus binds_local_p should be true.  */
22686       else if (TARGET_64BIT_MS_ABI)
22687         gcc_unreachable ();
22688       else
22689         {
22690           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xops[0]), UNSPEC_GOTPCREL);
22691           tmp = gen_rtx_CONST (Pmode, tmp);
22692           tmp = gen_rtx_MEM (QImode, tmp);
22693           xops[0] = tmp;
22694           output_asm_insn ("jmp\t%A0", xops);
22695         }
22696     }
22697   else
22698     {
22699       if (!flag_pic || (*targetm.binds_local_p) (function))
22700         output_asm_insn ("jmp\t%P0", xops);
22701       else
22702 #if TARGET_MACHO
22703         if (TARGET_MACHO)
22704           {
22705             rtx sym_ref = XEXP (DECL_RTL (function), 0);
22706             tmp = (gen_rtx_SYMBOL_REF
22707                    (Pmode,
22708                     machopic_indirection_name (sym_ref, /*stub_p=*/true)));
22709             tmp = gen_rtx_MEM (QImode, tmp);
22710             xops[0] = tmp;
22711             output_asm_insn ("jmp\t%0", xops);
22712           }
22713         else
22714 #endif /* TARGET_MACHO */
22715         {
22716           tmp = gen_rtx_REG (SImode, CX_REG);
22717           output_set_got (tmp, NULL_RTX);
22718
22719           xops[1] = tmp;
22720           output_asm_insn ("mov{l}\t{%0@GOT(%1), %1|%1, %0@GOT[%1]}", xops);
22721           output_asm_insn ("jmp\t{*}%1", xops);
22722         }
22723     }
22724 }
22725
22726 static void
22727 x86_file_start (void)
22728 {
22729   default_file_start ();
22730 #if TARGET_MACHO
22731   darwin_file_start ();
22732 #endif
22733   if (X86_FILE_START_VERSION_DIRECTIVE)
22734     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
22735   if (X86_FILE_START_FLTUSED)
22736     fputs ("\t.global\t__fltused\n", asm_out_file);
22737   if (ix86_asm_dialect == ASM_INTEL)
22738     fputs ("\t.intel_syntax\n", asm_out_file);
22739 }
22740
22741 int
22742 x86_field_alignment (tree field, int computed)
22743 {
22744   enum machine_mode mode;
22745   tree type = TREE_TYPE (field);
22746
22747   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
22748     return computed;
22749   mode = TYPE_MODE (TREE_CODE (type) == ARRAY_TYPE
22750                     ? get_inner_array_type (type) : type);
22751   if (mode == DFmode || mode == DCmode
22752       || GET_MODE_CLASS (mode) == MODE_INT
22753       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
22754     return MIN (32, computed);
22755   return computed;
22756 }
22757
22758 /* Output assembler code to FILE to increment profiler label # LABELNO
22759    for profiling a function entry.  */
22760 void
22761 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
22762 {
22763   if (TARGET_64BIT)
22764     {
22765 #ifndef NO_PROFILE_COUNTERS
22766       fprintf (file, "\tleaq\t%sP%d@(%%rip),%%r11\n", LPREFIX, labelno);
22767 #endif
22768
22769       if (!TARGET_64BIT_MS_ABI && flag_pic)
22770         fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", MCOUNT_NAME);
22771       else
22772         fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
22773     }
22774   else if (flag_pic)
22775     {
22776 #ifndef NO_PROFILE_COUNTERS
22777       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%%s\n",
22778                LPREFIX, labelno, PROFILE_COUNT_REGISTER);
22779 #endif
22780       fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", MCOUNT_NAME);
22781     }
22782   else
22783     {
22784 #ifndef NO_PROFILE_COUNTERS
22785       fprintf (file, "\tmovl\t$%sP%d,%%%s\n", LPREFIX, labelno,
22786                PROFILE_COUNT_REGISTER);
22787 #endif
22788       fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
22789     }
22790 }
22791
22792 /* We don't have exact information about the insn sizes, but we may assume
22793    quite safely that we are informed about all 1 byte insns and memory
22794    address sizes.  This is enough to eliminate unnecessary padding in
22795    99% of cases.  */
22796
22797 static int
22798 min_insn_size (rtx insn)
22799 {
22800   int l = 0;
22801
22802   if (!INSN_P (insn) || !active_insn_p (insn))
22803     return 0;
22804
22805   /* Discard alignments we've emit and jump instructions.  */
22806   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
22807       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
22808     return 0;
22809   if (JUMP_P (insn)
22810       && (GET_CODE (PATTERN (insn)) == ADDR_VEC
22811           || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
22812     return 0;
22813
22814   /* Important case - calls are always 5 bytes.
22815      It is common to have many calls in the row.  */
22816   if (CALL_P (insn)
22817       && symbolic_reference_mentioned_p (PATTERN (insn))
22818       && !SIBLING_CALL_P (insn))
22819     return 5;
22820   if (get_attr_length (insn) <= 1)
22821     return 1;
22822
22823   /* For normal instructions we may rely on the sizes of addresses
22824      and the presence of symbol to require 4 bytes of encoding.
22825      This is not the case for jumps where references are PC relative.  */
22826   if (!JUMP_P (insn))
22827     {
22828       l = get_attr_length_address (insn);
22829       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
22830         l = 4;
22831     }
22832   if (l)
22833     return 1+l;
22834   else
22835     return 2;
22836 }
22837
22838 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
22839    window.  */
22840
22841 static void
22842 ix86_avoid_jump_misspredicts (void)
22843 {
22844   rtx insn, start = get_insns ();
22845   int nbytes = 0, njumps = 0;
22846   int isjump = 0;
22847
22848   /* Look for all minimal intervals of instructions containing 4 jumps.
22849      The intervals are bounded by START and INSN.  NBYTES is the total
22850      size of instructions in the interval including INSN and not including
22851      START.  When the NBYTES is smaller than 16 bytes, it is possible
22852      that the end of START and INSN ends up in the same 16byte page.
22853
22854      The smallest offset in the page INSN can start is the case where START
22855      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
22856      We add p2align to 16byte window with maxskip 17 - NBYTES + sizeof (INSN).
22857      */
22858   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
22859     {
22860
22861       nbytes += min_insn_size (insn);
22862       if (dump_file)
22863         fprintf(dump_file, "Insn %i estimated to %i bytes\n",
22864                 INSN_UID (insn), min_insn_size (insn));
22865       if ((JUMP_P (insn)
22866            && GET_CODE (PATTERN (insn)) != ADDR_VEC
22867            && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
22868           || CALL_P (insn))
22869         njumps++;
22870       else
22871         continue;
22872
22873       while (njumps > 3)
22874         {
22875           start = NEXT_INSN (start);
22876           if ((JUMP_P (start)
22877                && GET_CODE (PATTERN (start)) != ADDR_VEC
22878                && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
22879               || CALL_P (start))
22880             njumps--, isjump = 1;
22881           else
22882             isjump = 0;
22883           nbytes -= min_insn_size (start);
22884         }
22885       gcc_assert (njumps >= 0);
22886       if (dump_file)
22887         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
22888                 INSN_UID (start), INSN_UID (insn), nbytes);
22889
22890       if (njumps == 3 && isjump && nbytes < 16)
22891         {
22892           int padsize = 15 - nbytes + min_insn_size (insn);
22893
22894           if (dump_file)
22895             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
22896                      INSN_UID (insn), padsize);
22897           emit_insn_before (gen_align (GEN_INT (padsize)), insn);
22898         }
22899     }
22900 }
22901
22902 /* AMD Athlon works faster
22903    when RET is not destination of conditional jump or directly preceded
22904    by other jump instruction.  We avoid the penalty by inserting NOP just
22905    before the RET instructions in such cases.  */
22906 static void
22907 ix86_pad_returns (void)
22908 {
22909   edge e;
22910   edge_iterator ei;
22911
22912   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
22913     {
22914       basic_block bb = e->src;
22915       rtx ret = BB_END (bb);
22916       rtx prev;
22917       bool replace = false;
22918
22919       if (!JUMP_P (ret) || GET_CODE (PATTERN (ret)) != RETURN
22920           || !maybe_hot_bb_p (bb))
22921         continue;
22922       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
22923         if (active_insn_p (prev) || LABEL_P (prev))
22924           break;
22925       if (prev && LABEL_P (prev))
22926         {
22927           edge e;
22928           edge_iterator ei;
22929
22930           FOR_EACH_EDGE (e, ei, bb->preds)
22931             if (EDGE_FREQUENCY (e) && e->src->index >= 0
22932                 && !(e->flags & EDGE_FALLTHRU))
22933               replace = true;
22934         }
22935       if (!replace)
22936         {
22937           prev = prev_active_insn (ret);
22938           if (prev
22939               && ((JUMP_P (prev) && any_condjump_p (prev))
22940                   || CALL_P (prev)))
22941             replace = true;
22942           /* Empty functions get branch mispredict even when the jump destination
22943              is not visible to us.  */
22944           if (!prev && cfun->function_frequency > FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
22945             replace = true;
22946         }
22947       if (replace)
22948         {
22949           emit_insn_before (gen_return_internal_long (), ret);
22950           delete_insn (ret);
22951         }
22952     }
22953 }
22954
22955 /* Implement machine specific optimizations.  We implement padding of returns
22956    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
22957 static void
22958 ix86_reorg (void)
22959 {
22960   if (TARGET_PAD_RETURNS && optimize && !optimize_size)
22961     ix86_pad_returns ();
22962   if (TARGET_FOUR_JUMP_LIMIT && optimize && !optimize_size)
22963     ix86_avoid_jump_misspredicts ();
22964 }
22965
22966 /* Return nonzero when QImode register that must be represented via REX prefix
22967    is used.  */
22968 bool
22969 x86_extended_QIreg_mentioned_p (rtx insn)
22970 {
22971   int i;
22972   extract_insn_cached (insn);
22973   for (i = 0; i < recog_data.n_operands; i++)
22974     if (REG_P (recog_data.operand[i])
22975         && REGNO (recog_data.operand[i]) >= 4)
22976        return true;
22977   return false;
22978 }
22979
22980 /* Return nonzero when P points to register encoded via REX prefix.
22981    Called via for_each_rtx.  */
22982 static int
22983 extended_reg_mentioned_1 (rtx *p, void *data ATTRIBUTE_UNUSED)
22984 {
22985    unsigned int regno;
22986    if (!REG_P (*p))
22987      return 0;
22988    regno = REGNO (*p);
22989    return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
22990 }
22991
22992 /* Return true when INSN mentions register that must be encoded using REX
22993    prefix.  */
22994 bool
22995 x86_extended_reg_mentioned_p (rtx insn)
22996 {
22997   return for_each_rtx (&PATTERN (insn), extended_reg_mentioned_1, NULL);
22998 }
22999
23000 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
23001    optabs would emit if we didn't have TFmode patterns.  */
23002
23003 void
23004 x86_emit_floatuns (rtx operands[2])
23005 {
23006   rtx neglab, donelab, i0, i1, f0, in, out;
23007   enum machine_mode mode, inmode;
23008
23009   inmode = GET_MODE (operands[1]);
23010   gcc_assert (inmode == SImode || inmode == DImode);
23011
23012   out = operands[0];
23013   in = force_reg (inmode, operands[1]);
23014   mode = GET_MODE (out);
23015   neglab = gen_label_rtx ();
23016   donelab = gen_label_rtx ();
23017   f0 = gen_reg_rtx (mode);
23018
23019   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
23020
23021   expand_float (out, in, 0);
23022
23023   emit_jump_insn (gen_jump (donelab));
23024   emit_barrier ();
23025
23026   emit_label (neglab);
23027
23028   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
23029                             1, OPTAB_DIRECT);
23030   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
23031                             1, OPTAB_DIRECT);
23032   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
23033
23034   expand_float (f0, i0, 0);
23035
23036   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
23037
23038   emit_label (donelab);
23039 }
23040 \f
23041 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
23042    with all elements equal to VAR.  Return true if successful.  */
23043
23044 static bool
23045 ix86_expand_vector_init_duplicate (bool mmx_ok, enum machine_mode mode,
23046                                    rtx target, rtx val)
23047 {
23048   enum machine_mode smode, wsmode, wvmode;
23049   rtx x;
23050
23051   switch (mode)
23052     {
23053     case V2SImode:
23054     case V2SFmode:
23055       if (!mmx_ok)
23056         return false;
23057       /* FALLTHRU */
23058
23059     case V2DFmode:
23060     case V2DImode:
23061     case V4SFmode:
23062     case V4SImode:
23063       val = force_reg (GET_MODE_INNER (mode), val);
23064       x = gen_rtx_VEC_DUPLICATE (mode, val);
23065       emit_insn (gen_rtx_SET (VOIDmode, target, x));
23066       return true;
23067
23068     case V4HImode:
23069       if (!mmx_ok)
23070         return false;
23071       if (TARGET_SSE || TARGET_3DNOW_A)
23072         {
23073           val = gen_lowpart (SImode, val);
23074           x = gen_rtx_TRUNCATE (HImode, val);
23075           x = gen_rtx_VEC_DUPLICATE (mode, x);
23076           emit_insn (gen_rtx_SET (VOIDmode, target, x));
23077           return true;
23078         }
23079       else
23080         {
23081           smode = HImode;
23082           wsmode = SImode;
23083           wvmode = V2SImode;
23084           goto widen;
23085         }
23086
23087     case V8QImode:
23088       if (!mmx_ok)
23089         return false;
23090       smode = QImode;
23091       wsmode = HImode;
23092       wvmode = V4HImode;
23093       goto widen;
23094     case V8HImode:
23095       if (TARGET_SSE2)
23096         {
23097           rtx tmp1, tmp2;
23098           /* Extend HImode to SImode using a paradoxical SUBREG.  */
23099           tmp1 = gen_reg_rtx (SImode);
23100           emit_move_insn (tmp1, gen_lowpart (SImode, val));
23101           /* Insert the SImode value as low element of V4SImode vector. */
23102           tmp2 = gen_reg_rtx (V4SImode);
23103           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
23104                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
23105                                     CONST0_RTX (V4SImode),
23106                                     const1_rtx);
23107           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
23108           /* Cast the V4SImode vector back to a V8HImode vector.  */
23109           tmp1 = gen_reg_rtx (V8HImode);
23110           emit_move_insn (tmp1, gen_lowpart (V8HImode, tmp2));
23111           /* Duplicate the low short through the whole low SImode word.  */
23112           emit_insn (gen_sse2_punpcklwd (tmp1, tmp1, tmp1));
23113           /* Cast the V8HImode vector back to a V4SImode vector.  */
23114           tmp2 = gen_reg_rtx (V4SImode);
23115           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
23116           /* Replicate the low element of the V4SImode vector.  */
23117           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
23118           /* Cast the V2SImode back to V8HImode, and store in target.  */
23119           emit_move_insn (target, gen_lowpart (V8HImode, tmp2));
23120           return true;
23121         }
23122       smode = HImode;
23123       wsmode = SImode;
23124       wvmode = V4SImode;
23125       goto widen;
23126     case V16QImode:
23127       if (TARGET_SSE2)
23128         {
23129           rtx tmp1, tmp2;
23130           /* Extend QImode to SImode using a paradoxical SUBREG.  */
23131           tmp1 = gen_reg_rtx (SImode);
23132           emit_move_insn (tmp1, gen_lowpart (SImode, val));
23133           /* Insert the SImode value as low element of V4SImode vector. */
23134           tmp2 = gen_reg_rtx (V4SImode);
23135           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
23136                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
23137                                     CONST0_RTX (V4SImode),
23138                                     const1_rtx);
23139           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
23140           /* Cast the V4SImode vector back to a V16QImode vector.  */
23141           tmp1 = gen_reg_rtx (V16QImode);
23142           emit_move_insn (tmp1, gen_lowpart (V16QImode, tmp2));
23143           /* Duplicate the low byte through the whole low SImode word.  */
23144           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
23145           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
23146           /* Cast the V16QImode vector back to a V4SImode vector.  */
23147           tmp2 = gen_reg_rtx (V4SImode);
23148           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
23149           /* Replicate the low element of the V4SImode vector.  */
23150           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
23151           /* Cast the V2SImode back to V16QImode, and store in target.  */
23152           emit_move_insn (target, gen_lowpart (V16QImode, tmp2));
23153           return true;
23154         }
23155       smode = QImode;
23156       wsmode = HImode;
23157       wvmode = V8HImode;
23158       goto widen;
23159     widen:
23160       /* Replicate the value once into the next wider mode and recurse.  */
23161       val = convert_modes (wsmode, smode, val, true);
23162       x = expand_simple_binop (wsmode, ASHIFT, val,
23163                                GEN_INT (GET_MODE_BITSIZE (smode)),
23164                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
23165       val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
23166
23167       x = gen_reg_rtx (wvmode);
23168       if (!ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val))
23169         gcc_unreachable ();
23170       emit_move_insn (target, gen_lowpart (mode, x));
23171       return true;
23172
23173     default:
23174       return false;
23175     }
23176 }
23177
23178 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
23179    whose ONE_VAR element is VAR, and other elements are zero.  Return true
23180    if successful.  */
23181
23182 static bool
23183 ix86_expand_vector_init_one_nonzero (bool mmx_ok, enum machine_mode mode,
23184                                      rtx target, rtx var, int one_var)
23185 {
23186   enum machine_mode vsimode;
23187   rtx new_target;
23188   rtx x, tmp;
23189
23190   switch (mode)
23191     {
23192     case V2SFmode:
23193     case V2SImode:
23194       if (!mmx_ok)
23195         return false;
23196       /* FALLTHRU */
23197
23198     case V2DFmode:
23199     case V2DImode:
23200       if (one_var != 0)
23201         return false;
23202       var = force_reg (GET_MODE_INNER (mode), var);
23203       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
23204       emit_insn (gen_rtx_SET (VOIDmode, target, x));
23205       return true;
23206
23207     case V4SFmode:
23208     case V4SImode:
23209       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
23210         new_target = gen_reg_rtx (mode);
23211       else
23212         new_target = target;
23213       var = force_reg (GET_MODE_INNER (mode), var);
23214       x = gen_rtx_VEC_DUPLICATE (mode, var);
23215       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
23216       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
23217       if (one_var != 0)
23218         {
23219           /* We need to shuffle the value to the correct position, so
23220              create a new pseudo to store the intermediate result.  */
23221
23222           /* With SSE2, we can use the integer shuffle insns.  */
23223           if (mode != V4SFmode && TARGET_SSE2)
23224             {
23225               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
23226                                             GEN_INT (1),
23227                                             GEN_INT (one_var == 1 ? 0 : 1),
23228                                             GEN_INT (one_var == 2 ? 0 : 1),
23229                                             GEN_INT (one_var == 3 ? 0 : 1)));
23230               if (target != new_target)
23231                 emit_move_insn (target, new_target);
23232               return true;
23233             }
23234
23235           /* Otherwise convert the intermediate result to V4SFmode and
23236              use the SSE1 shuffle instructions.  */
23237           if (mode != V4SFmode)
23238             {
23239               tmp = gen_reg_rtx (V4SFmode);
23240               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
23241             }
23242           else
23243             tmp = new_target;
23244
23245           emit_insn (gen_sse_shufps_1 (tmp, tmp, tmp,
23246                                        GEN_INT (1),
23247                                        GEN_INT (one_var == 1 ? 0 : 1),
23248                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
23249                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
23250
23251           if (mode != V4SFmode)
23252             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
23253           else if (tmp != target)
23254             emit_move_insn (target, tmp);
23255         }
23256       else if (target != new_target)
23257         emit_move_insn (target, new_target);
23258       return true;
23259
23260     case V8HImode:
23261     case V16QImode:
23262       vsimode = V4SImode;
23263       goto widen;
23264     case V4HImode:
23265     case V8QImode:
23266       if (!mmx_ok)
23267         return false;
23268       vsimode = V2SImode;
23269       goto widen;
23270     widen:
23271       if (one_var != 0)
23272         return false;
23273
23274       /* Zero extend the variable element to SImode and recurse.  */
23275       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
23276
23277       x = gen_reg_rtx (vsimode);
23278       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
23279                                                 var, one_var))
23280         gcc_unreachable ();
23281
23282       emit_move_insn (target, gen_lowpart (mode, x));
23283       return true;
23284
23285     default:
23286       return false;
23287     }
23288 }
23289
23290 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
23291    consisting of the values in VALS.  It is known that all elements
23292    except ONE_VAR are constants.  Return true if successful.  */
23293
23294 static bool
23295 ix86_expand_vector_init_one_var (bool mmx_ok, enum machine_mode mode,
23296                                  rtx target, rtx vals, int one_var)
23297 {
23298   rtx var = XVECEXP (vals, 0, one_var);
23299   enum machine_mode wmode;
23300   rtx const_vec, x;
23301
23302   const_vec = copy_rtx (vals);
23303   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
23304   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
23305
23306   switch (mode)
23307     {
23308     case V2DFmode:
23309     case V2DImode:
23310     case V2SFmode:
23311     case V2SImode:
23312       /* For the two element vectors, it's just as easy to use
23313          the general case.  */
23314       return false;
23315
23316     case V4SFmode:
23317     case V4SImode:
23318     case V8HImode:
23319     case V4HImode:
23320       break;
23321
23322     case V16QImode:
23323       wmode = V8HImode;
23324       goto widen;
23325     case V8QImode:
23326       wmode = V4HImode;
23327       goto widen;
23328     widen:
23329       /* There's no way to set one QImode entry easily.  Combine
23330          the variable value with its adjacent constant value, and
23331          promote to an HImode set.  */
23332       x = XVECEXP (vals, 0, one_var ^ 1);
23333       if (one_var & 1)
23334         {
23335           var = convert_modes (HImode, QImode, var, true);
23336           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
23337                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
23338           x = GEN_INT (INTVAL (x) & 0xff);
23339         }
23340       else
23341         {
23342           var = convert_modes (HImode, QImode, var, true);
23343           x = gen_int_mode (INTVAL (x) << 8, HImode);
23344         }
23345       if (x != const0_rtx)
23346         var = expand_simple_binop (HImode, IOR, var, x, var,
23347                                    1, OPTAB_LIB_WIDEN);
23348
23349       x = gen_reg_rtx (wmode);
23350       emit_move_insn (x, gen_lowpart (wmode, const_vec));
23351       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
23352
23353       emit_move_insn (target, gen_lowpart (mode, x));
23354       return true;
23355
23356     default:
23357       return false;
23358     }
23359
23360   emit_move_insn (target, const_vec);
23361   ix86_expand_vector_set (mmx_ok, target, var, one_var);
23362   return true;
23363 }
23364
23365 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
23366    all values variable, and none identical.  */
23367
23368 static void
23369 ix86_expand_vector_init_general (bool mmx_ok, enum machine_mode mode,
23370                                  rtx target, rtx vals)
23371 {
23372   enum machine_mode half_mode = GET_MODE_INNER (mode);
23373   rtx op0 = NULL, op1 = NULL;
23374   bool use_vec_concat = false;
23375
23376   switch (mode)
23377     {
23378     case V2SFmode:
23379     case V2SImode:
23380       if (!mmx_ok && !TARGET_SSE)
23381         break;
23382       /* FALLTHRU */
23383
23384     case V2DFmode:
23385     case V2DImode:
23386       /* For the two element vectors, we always implement VEC_CONCAT.  */
23387       op0 = XVECEXP (vals, 0, 0);
23388       op1 = XVECEXP (vals, 0, 1);
23389       use_vec_concat = true;
23390       break;
23391
23392     case V4SFmode:
23393       half_mode = V2SFmode;
23394       goto half;
23395     case V4SImode:
23396       half_mode = V2SImode;
23397       goto half;
23398     half:
23399       {
23400         rtvec v;
23401
23402         /* For V4SF and V4SI, we implement a concat of two V2 vectors.
23403            Recurse to load the two halves.  */
23404
23405         op0 = gen_reg_rtx (half_mode);
23406         v = gen_rtvec (2, XVECEXP (vals, 0, 0), XVECEXP (vals, 0, 1));
23407         ix86_expand_vector_init (false, op0, gen_rtx_PARALLEL (half_mode, v));
23408
23409         op1 = gen_reg_rtx (half_mode);
23410         v = gen_rtvec (2, XVECEXP (vals, 0, 2), XVECEXP (vals, 0, 3));
23411         ix86_expand_vector_init (false, op1, gen_rtx_PARALLEL (half_mode, v));
23412
23413         use_vec_concat = true;
23414       }
23415       break;
23416
23417     case V8HImode:
23418     case V16QImode:
23419     case V4HImode:
23420     case V8QImode:
23421       break;
23422
23423     default:
23424       gcc_unreachable ();
23425     }
23426
23427   if (use_vec_concat)
23428     {
23429       if (!register_operand (op0, half_mode))
23430         op0 = force_reg (half_mode, op0);
23431       if (!register_operand (op1, half_mode))
23432         op1 = force_reg (half_mode, op1);
23433
23434       emit_insn (gen_rtx_SET (VOIDmode, target,
23435                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
23436     }
23437   else
23438     {
23439       int i, j, n_elts, n_words, n_elt_per_word;
23440       enum machine_mode inner_mode;
23441       rtx words[4], shift;
23442
23443       inner_mode = GET_MODE_INNER (mode);
23444       n_elts = GET_MODE_NUNITS (mode);
23445       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
23446       n_elt_per_word = n_elts / n_words;
23447       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
23448
23449       for (i = 0; i < n_words; ++i)
23450         {
23451           rtx word = NULL_RTX;
23452
23453           for (j = 0; j < n_elt_per_word; ++j)
23454             {
23455               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
23456               elt = convert_modes (word_mode, inner_mode, elt, true);
23457
23458               if (j == 0)
23459                 word = elt;
23460               else
23461                 {
23462                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
23463                                               word, 1, OPTAB_LIB_WIDEN);
23464                   word = expand_simple_binop (word_mode, IOR, word, elt,
23465                                               word, 1, OPTAB_LIB_WIDEN);
23466                 }
23467             }
23468
23469           words[i] = word;
23470         }
23471
23472       if (n_words == 1)
23473         emit_move_insn (target, gen_lowpart (mode, words[0]));
23474       else if (n_words == 2)
23475         {
23476           rtx tmp = gen_reg_rtx (mode);
23477           emit_insn (gen_rtx_CLOBBER (VOIDmode, tmp));
23478           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
23479           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
23480           emit_move_insn (target, tmp);
23481         }
23482       else if (n_words == 4)
23483         {
23484           rtx tmp = gen_reg_rtx (V4SImode);
23485           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
23486           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
23487           emit_move_insn (target, gen_lowpart (mode, tmp));
23488         }
23489       else
23490         gcc_unreachable ();
23491     }
23492 }
23493
23494 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
23495    instructions unless MMX_OK is true.  */
23496
23497 void
23498 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
23499 {
23500   enum machine_mode mode = GET_MODE (target);
23501   enum machine_mode inner_mode = GET_MODE_INNER (mode);
23502   int n_elts = GET_MODE_NUNITS (mode);
23503   int n_var = 0, one_var = -1;
23504   bool all_same = true, all_const_zero = true;
23505   int i;
23506   rtx x;
23507
23508   for (i = 0; i < n_elts; ++i)
23509     {
23510       x = XVECEXP (vals, 0, i);
23511       if (!CONSTANT_P (x))
23512         n_var++, one_var = i;
23513       else if (x != CONST0_RTX (inner_mode))
23514         all_const_zero = false;
23515       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
23516         all_same = false;
23517     }
23518
23519   /* Constants are best loaded from the constant pool.  */
23520   if (n_var == 0)
23521     {
23522       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
23523       return;
23524     }
23525
23526   /* If all values are identical, broadcast the value.  */
23527   if (all_same
23528       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
23529                                             XVECEXP (vals, 0, 0)))
23530     return;
23531
23532   /* Values where only one field is non-constant are best loaded from
23533      the pool and overwritten via move later.  */
23534   if (n_var == 1)
23535     {
23536       if (all_const_zero
23537           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
23538                                                   XVECEXP (vals, 0, one_var),
23539                                                   one_var))
23540         return;
23541
23542       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
23543         return;
23544     }
23545
23546   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
23547 }
23548
23549 void
23550 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
23551 {
23552   enum machine_mode mode = GET_MODE (target);
23553   enum machine_mode inner_mode = GET_MODE_INNER (mode);
23554   bool use_vec_merge = false;
23555   rtx tmp;
23556
23557   switch (mode)
23558     {
23559     case V2SFmode:
23560     case V2SImode:
23561       if (mmx_ok)
23562         {
23563           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
23564           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
23565           if (elt == 0)
23566             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
23567           else
23568             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
23569           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
23570           return;
23571         }
23572       break;
23573
23574     case V2DImode:
23575       use_vec_merge = TARGET_SSE4_1;
23576       if (use_vec_merge)
23577         break;
23578
23579     case V2DFmode:
23580       {
23581         rtx op0, op1;
23582
23583         /* For the two element vectors, we implement a VEC_CONCAT with
23584            the extraction of the other element.  */
23585
23586         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
23587         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
23588
23589         if (elt == 0)
23590           op0 = val, op1 = tmp;
23591         else
23592           op0 = tmp, op1 = val;
23593
23594         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
23595         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
23596       }
23597       return;
23598
23599     case V4SFmode:
23600       use_vec_merge = TARGET_SSE4_1;
23601       if (use_vec_merge)
23602         break;
23603
23604       switch (elt)
23605         {
23606         case 0:
23607           use_vec_merge = true;
23608           break;
23609
23610         case 1:
23611           /* tmp = target = A B C D */
23612           tmp = copy_to_reg (target);
23613           /* target = A A B B */
23614           emit_insn (gen_sse_unpcklps (target, target, target));
23615           /* target = X A B B */
23616           ix86_expand_vector_set (false, target, val, 0);
23617           /* target = A X C D  */
23618           emit_insn (gen_sse_shufps_1 (target, target, tmp,
23619                                        GEN_INT (1), GEN_INT (0),
23620                                        GEN_INT (2+4), GEN_INT (3+4)));
23621           return;
23622
23623         case 2:
23624           /* tmp = target = A B C D */
23625           tmp = copy_to_reg (target);
23626           /* tmp = X B C D */
23627           ix86_expand_vector_set (false, tmp, val, 0);
23628           /* target = A B X D */
23629           emit_insn (gen_sse_shufps_1 (target, target, tmp,
23630                                        GEN_INT (0), GEN_INT (1),
23631                                        GEN_INT (0+4), GEN_INT (3+4)));
23632           return;
23633
23634         case 3:
23635           /* tmp = target = A B C D */
23636           tmp = copy_to_reg (target);
23637           /* tmp = X B C D */
23638           ix86_expand_vector_set (false, tmp, val, 0);
23639           /* target = A B X D */
23640           emit_insn (gen_sse_shufps_1 (target, target, tmp,
23641                                        GEN_INT (0), GEN_INT (1),
23642                                        GEN_INT (2+4), GEN_INT (0+4)));
23643           return;
23644
23645         default:
23646           gcc_unreachable ();
23647         }
23648       break;
23649
23650     case V4SImode:
23651       use_vec_merge = TARGET_SSE4_1;
23652       if (use_vec_merge)
23653         break;
23654
23655       /* Element 0 handled by vec_merge below.  */
23656       if (elt == 0)
23657         {
23658           use_vec_merge = true;
23659           break;
23660         }
23661
23662       if (TARGET_SSE2)
23663         {
23664           /* With SSE2, use integer shuffles to swap element 0 and ELT,
23665              store into element 0, then shuffle them back.  */
23666
23667           rtx order[4];
23668
23669           order[0] = GEN_INT (elt);
23670           order[1] = const1_rtx;
23671           order[2] = const2_rtx;
23672           order[3] = GEN_INT (3);
23673           order[elt] = const0_rtx;
23674
23675           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
23676                                         order[1], order[2], order[3]));
23677
23678           ix86_expand_vector_set (false, target, val, 0);
23679
23680           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
23681                                         order[1], order[2], order[3]));
23682         }
23683       else
23684         {
23685           /* For SSE1, we have to reuse the V4SF code.  */
23686           ix86_expand_vector_set (false, gen_lowpart (V4SFmode, target),
23687                                   gen_lowpart (SFmode, val), elt);
23688         }
23689       return;
23690
23691     case V8HImode:
23692       use_vec_merge = TARGET_SSE2;
23693       break;
23694     case V4HImode:
23695       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
23696       break;
23697
23698     case V16QImode:
23699       use_vec_merge = TARGET_SSE4_1;
23700       break;
23701
23702     case V8QImode:
23703     default:
23704       break;
23705     }
23706
23707   if (use_vec_merge)
23708     {
23709       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
23710       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
23711       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
23712     }
23713   else
23714     {
23715       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
23716
23717       emit_move_insn (mem, target);
23718
23719       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
23720       emit_move_insn (tmp, val);
23721
23722       emit_move_insn (target, mem);
23723     }
23724 }
23725
23726 void
23727 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
23728 {
23729   enum machine_mode mode = GET_MODE (vec);
23730   enum machine_mode inner_mode = GET_MODE_INNER (mode);
23731   bool use_vec_extr = false;
23732   rtx tmp;
23733
23734   switch (mode)
23735     {
23736     case V2SImode:
23737     case V2SFmode:
23738       if (!mmx_ok)
23739         break;
23740       /* FALLTHRU */
23741
23742     case V2DFmode:
23743     case V2DImode:
23744       use_vec_extr = true;
23745       break;
23746
23747     case V4SFmode:
23748       use_vec_extr = TARGET_SSE4_1;
23749       if (use_vec_extr)
23750         break;
23751
23752       switch (elt)
23753         {
23754         case 0:
23755           tmp = vec;
23756           break;
23757
23758         case 1:
23759         case 3:
23760           tmp = gen_reg_rtx (mode);
23761           emit_insn (gen_sse_shufps_1 (tmp, vec, vec,
23762                                        GEN_INT (elt), GEN_INT (elt),
23763                                        GEN_INT (elt+4), GEN_INT (elt+4)));
23764           break;
23765
23766         case 2:
23767           tmp = gen_reg_rtx (mode);
23768           emit_insn (gen_sse_unpckhps (tmp, vec, vec));
23769           break;
23770
23771         default:
23772           gcc_unreachable ();
23773         }
23774       vec = tmp;
23775       use_vec_extr = true;
23776       elt = 0;
23777       break;
23778
23779     case V4SImode:
23780       use_vec_extr = TARGET_SSE4_1;
23781       if (use_vec_extr)
23782         break;
23783
23784       if (TARGET_SSE2)
23785         {
23786           switch (elt)
23787             {
23788             case 0:
23789               tmp = vec;
23790               break;
23791
23792             case 1:
23793             case 3:
23794               tmp = gen_reg_rtx (mode);
23795               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
23796                                             GEN_INT (elt), GEN_INT (elt),
23797                                             GEN_INT (elt), GEN_INT (elt)));
23798               break;
23799
23800             case 2:
23801               tmp = gen_reg_rtx (mode);
23802               emit_insn (gen_sse2_punpckhdq (tmp, vec, vec));
23803               break;
23804
23805             default:
23806               gcc_unreachable ();
23807             }
23808           vec = tmp;
23809           use_vec_extr = true;
23810           elt = 0;
23811         }
23812       else
23813         {
23814           /* For SSE1, we have to reuse the V4SF code.  */
23815           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
23816                                       gen_lowpart (V4SFmode, vec), elt);
23817           return;
23818         }
23819       break;
23820
23821     case V8HImode:
23822       use_vec_extr = TARGET_SSE2;
23823       break;
23824     case V4HImode:
23825       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
23826       break;
23827
23828     case V16QImode:
23829       use_vec_extr = TARGET_SSE4_1;
23830       break;
23831
23832     case V8QImode:
23833       /* ??? Could extract the appropriate HImode element and shift.  */
23834     default:
23835       break;
23836     }
23837
23838   if (use_vec_extr)
23839     {
23840       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
23841       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
23842
23843       /* Let the rtl optimizers know about the zero extension performed.  */
23844       if (inner_mode == QImode || inner_mode == HImode)
23845         {
23846           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
23847           target = gen_lowpart (SImode, target);
23848         }
23849
23850       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
23851     }
23852   else
23853     {
23854       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
23855
23856       emit_move_insn (mem, vec);
23857
23858       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
23859       emit_move_insn (target, tmp);
23860     }
23861 }
23862
23863 /* Expand a vector reduction on V4SFmode for SSE1.  FN is the binary
23864    pattern to reduce; DEST is the destination; IN is the input vector.  */
23865
23866 void
23867 ix86_expand_reduc_v4sf (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
23868 {
23869   rtx tmp1, tmp2, tmp3;
23870
23871   tmp1 = gen_reg_rtx (V4SFmode);
23872   tmp2 = gen_reg_rtx (V4SFmode);
23873   tmp3 = gen_reg_rtx (V4SFmode);
23874
23875   emit_insn (gen_sse_movhlps (tmp1, in, in));
23876   emit_insn (fn (tmp2, tmp1, in));
23877
23878   emit_insn (gen_sse_shufps_1 (tmp3, tmp2, tmp2,
23879                                GEN_INT (1), GEN_INT (1),
23880                                GEN_INT (1+4), GEN_INT (1+4)));
23881   emit_insn (fn (dest, tmp2, tmp3));
23882 }
23883 \f
23884 /* Target hook for scalar_mode_supported_p.  */
23885 static bool
23886 ix86_scalar_mode_supported_p (enum machine_mode mode)
23887 {
23888   if (DECIMAL_FLOAT_MODE_P (mode))
23889     return true;
23890   else if (mode == TFmode)
23891     return TARGET_64BIT;
23892   else
23893     return default_scalar_mode_supported_p (mode);
23894 }
23895
23896 /* Implements target hook vector_mode_supported_p.  */
23897 static bool
23898 ix86_vector_mode_supported_p (enum machine_mode mode)
23899 {
23900   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
23901     return true;
23902   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
23903     return true;
23904   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
23905     return true;
23906   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
23907     return true;
23908   return false;
23909 }
23910
23911 /* Target hook for c_mode_for_suffix.  */
23912 static enum machine_mode
23913 ix86_c_mode_for_suffix (char suffix)
23914 {
23915   if (TARGET_64BIT && suffix == 'q')
23916     return TFmode;
23917   if (TARGET_MMX && suffix == 'w')
23918     return XFmode;
23919
23920   return VOIDmode;
23921 }
23922
23923 /* Worker function for TARGET_MD_ASM_CLOBBERS.
23924
23925    We do this in the new i386 backend to maintain source compatibility
23926    with the old cc0-based compiler.  */
23927
23928 static tree
23929 ix86_md_asm_clobbers (tree outputs ATTRIBUTE_UNUSED,
23930                       tree inputs ATTRIBUTE_UNUSED,
23931                       tree clobbers)
23932 {
23933   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
23934                         clobbers);
23935   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
23936                         clobbers);
23937   return clobbers;
23938 }
23939
23940 /* Implements target vector targetm.asm.encode_section_info.  This
23941    is not used by netware.  */
23942
23943 static void ATTRIBUTE_UNUSED
23944 ix86_encode_section_info (tree decl, rtx rtl, int first)
23945 {
23946   default_encode_section_info (decl, rtl, first);
23947
23948   if (TREE_CODE (decl) == VAR_DECL
23949       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
23950       && ix86_in_large_data_p (decl))
23951     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
23952 }
23953
23954 /* Worker function for REVERSE_CONDITION.  */
23955
23956 enum rtx_code
23957 ix86_reverse_condition (enum rtx_code code, enum machine_mode mode)
23958 {
23959   return (mode != CCFPmode && mode != CCFPUmode
23960           ? reverse_condition (code)
23961           : reverse_condition_maybe_unordered (code));
23962 }
23963
23964 /* Output code to perform an x87 FP register move, from OPERANDS[1]
23965    to OPERANDS[0].  */
23966
23967 const char *
23968 output_387_reg_move (rtx insn, rtx *operands)
23969 {
23970   if (REG_P (operands[0]))
23971     {
23972       if (REG_P (operands[1])
23973           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
23974         {
23975           if (REGNO (operands[0]) == FIRST_STACK_REG)
23976             return output_387_ffreep (operands, 0);
23977           return "fstp\t%y0";
23978         }
23979       if (STACK_TOP_P (operands[0]))
23980         return "fld%z1\t%y1";
23981       return "fst\t%y0";
23982     }
23983   else if (MEM_P (operands[0]))
23984     {
23985       gcc_assert (REG_P (operands[1]));
23986       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
23987         return "fstp%z0\t%y0";
23988       else
23989         {
23990           /* There is no non-popping store to memory for XFmode.
23991              So if we need one, follow the store with a load.  */
23992           if (GET_MODE (operands[0]) == XFmode)
23993             return "fstp%z0\t%y0\n\tfld%z0\t%y0";
23994           else
23995             return "fst%z0\t%y0";
23996         }
23997     }
23998   else
23999     gcc_unreachable();
24000 }
24001
24002 /* Output code to perform a conditional jump to LABEL, if C2 flag in
24003    FP status register is set.  */
24004
24005 void
24006 ix86_emit_fp_unordered_jump (rtx label)
24007 {
24008   rtx reg = gen_reg_rtx (HImode);
24009   rtx temp;
24010
24011   emit_insn (gen_x86_fnstsw_1 (reg));
24012
24013   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_size))
24014     {
24015       emit_insn (gen_x86_sahf_1 (reg));
24016
24017       temp = gen_rtx_REG (CCmode, FLAGS_REG);
24018       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
24019     }
24020   else
24021     {
24022       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
24023
24024       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
24025       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
24026     }
24027
24028   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
24029                               gen_rtx_LABEL_REF (VOIDmode, label),
24030                               pc_rtx);
24031   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
24032
24033   emit_jump_insn (temp);
24034   predict_jump (REG_BR_PROB_BASE * 10 / 100);
24035 }
24036
24037 /* Output code to perform a log1p XFmode calculation.  */
24038
24039 void ix86_emit_i387_log1p (rtx op0, rtx op1)
24040 {
24041   rtx label1 = gen_label_rtx ();
24042   rtx label2 = gen_label_rtx ();
24043
24044   rtx tmp = gen_reg_rtx (XFmode);
24045   rtx tmp2 = gen_reg_rtx (XFmode);
24046
24047   emit_insn (gen_absxf2 (tmp, op1));
24048   emit_insn (gen_cmpxf (tmp,
24049     CONST_DOUBLE_FROM_REAL_VALUE (
24050        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
24051        XFmode)));
24052   emit_jump_insn (gen_bge (label1));
24053
24054   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
24055   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
24056   emit_jump (label2);
24057
24058   emit_label (label1);
24059   emit_move_insn (tmp, CONST1_RTX (XFmode));
24060   emit_insn (gen_addxf3 (tmp, op1, tmp));
24061   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
24062   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
24063
24064   emit_label (label2);
24065 }
24066
24067 /* Output code to perform a Newton-Rhapson approximation of a single precision
24068    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
24069
24070 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, enum machine_mode mode)
24071 {
24072   rtx x0, x1, e0, e1, two;
24073
24074   x0 = gen_reg_rtx (mode);
24075   e0 = gen_reg_rtx (mode);
24076   e1 = gen_reg_rtx (mode);
24077   x1 = gen_reg_rtx (mode);
24078
24079   two = CONST_DOUBLE_FROM_REAL_VALUE (dconst2, SFmode);
24080
24081   if (VECTOR_MODE_P (mode))
24082     two = ix86_build_const_vector (SFmode, true, two);
24083
24084   two = force_reg (mode, two);
24085
24086   /* a / b = a * rcp(b) * (2.0 - b * rcp(b)) */
24087
24088   /* x0 = 1./b estimate */
24089   emit_insn (gen_rtx_SET (VOIDmode, x0,
24090                           gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
24091                                           UNSPEC_RCP)));
24092   /* e0 = x0 * b */
24093   emit_insn (gen_rtx_SET (VOIDmode, e0,
24094                           gen_rtx_MULT (mode, x0, b)));
24095   /* e1 = 2. - e0 */
24096   emit_insn (gen_rtx_SET (VOIDmode, e1,
24097                           gen_rtx_MINUS (mode, two, e0)));
24098   /* x1 = x0 * e1 */
24099   emit_insn (gen_rtx_SET (VOIDmode, x1,
24100                           gen_rtx_MULT (mode, x0, e1)));
24101   /* res = a * x1 */
24102   emit_insn (gen_rtx_SET (VOIDmode, res,
24103                           gen_rtx_MULT (mode, a, x1)));
24104 }
24105
24106 /* Output code to perform a Newton-Rhapson approximation of a
24107    single precision floating point [reciprocal] square root.  */
24108
24109 void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
24110                          bool recip)
24111 {
24112   rtx x0, e0, e1, e2, e3, three, half, zero, mask;
24113
24114   x0 = gen_reg_rtx (mode);
24115   e0 = gen_reg_rtx (mode);
24116   e1 = gen_reg_rtx (mode);
24117   e2 = gen_reg_rtx (mode);
24118   e3 = gen_reg_rtx (mode);
24119
24120   three = CONST_DOUBLE_FROM_REAL_VALUE (dconst3, SFmode);
24121   half = CONST_DOUBLE_FROM_REAL_VALUE (dconsthalf, SFmode);
24122
24123   mask = gen_reg_rtx (mode);
24124
24125   if (VECTOR_MODE_P (mode))
24126     {
24127       three = ix86_build_const_vector (SFmode, true, three);
24128       half = ix86_build_const_vector (SFmode, true, half);
24129     }
24130
24131   three = force_reg (mode, three);
24132   half = force_reg (mode, half);
24133
24134   zero = force_reg (mode, CONST0_RTX(mode));
24135
24136   /* sqrt(a) = 0.5 * a * rsqrtss(a) * (3.0 - a * rsqrtss(a) * rsqrtss(a))
24137      1.0 / sqrt(a) = 0.5 * rsqrtss(a) * (3.0 - a * rsqrtss(a) * rsqrtss(a)) */
24138
24139   /* Compare a to zero.  */
24140   emit_insn (gen_rtx_SET (VOIDmode, mask,
24141                           gen_rtx_NE (mode, a, zero)));
24142
24143   /* x0 = 1./sqrt(a) estimate */
24144   emit_insn (gen_rtx_SET (VOIDmode, x0,
24145                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
24146                                           UNSPEC_RSQRT)));
24147   /* Filter out infinity.  */
24148   if (VECTOR_MODE_P (mode))
24149     emit_insn (gen_rtx_SET (VOIDmode, gen_lowpart (V4SFmode, x0),
24150                             gen_rtx_AND (mode,
24151                                          gen_lowpart (V4SFmode, x0),
24152                                          gen_lowpart (V4SFmode, mask))));
24153   else
24154     emit_insn (gen_rtx_SET (VOIDmode, x0,
24155                             gen_rtx_AND (mode, x0, mask)));
24156
24157   /* e0 = x0 * a */
24158   emit_insn (gen_rtx_SET (VOIDmode, e0,
24159                           gen_rtx_MULT (mode, x0, a)));
24160   /* e1 = e0 * x0 */
24161   emit_insn (gen_rtx_SET (VOIDmode, e1,
24162                           gen_rtx_MULT (mode, e0, x0)));
24163   /* e2 = 3. - e1 */
24164   emit_insn (gen_rtx_SET (VOIDmode, e2,
24165                           gen_rtx_MINUS (mode, three, e1)));
24166   if (recip)
24167     /* e3 = .5 * x0 */
24168     emit_insn (gen_rtx_SET (VOIDmode, e3,
24169                             gen_rtx_MULT (mode, half, x0)));
24170   else
24171     /* e3 = .5 * e0 */
24172     emit_insn (gen_rtx_SET (VOIDmode, e3,
24173                             gen_rtx_MULT (mode, half, e0)));
24174   /* ret = e2 * e3 */
24175   emit_insn (gen_rtx_SET (VOIDmode, res,
24176                           gen_rtx_MULT (mode, e2, e3)));
24177 }
24178
24179 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
24180
24181 static void ATTRIBUTE_UNUSED
24182 i386_solaris_elf_named_section (const char *name, unsigned int flags,
24183                                 tree decl)
24184 {
24185   /* With Binutils 2.15, the "@unwind" marker must be specified on
24186      every occurrence of the ".eh_frame" section, not just the first
24187      one.  */
24188   if (TARGET_64BIT
24189       && strcmp (name, ".eh_frame") == 0)
24190     {
24191       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
24192                flags & SECTION_WRITE ? "aw" : "a");
24193       return;
24194     }
24195   default_elf_asm_named_section (name, flags, decl);
24196 }
24197
24198 /* Return the mangling of TYPE if it is an extended fundamental type.  */
24199
24200 static const char *
24201 ix86_mangle_type (const_tree type)
24202 {
24203   type = TYPE_MAIN_VARIANT (type);
24204
24205   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
24206       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
24207     return NULL;
24208
24209   switch (TYPE_MODE (type))
24210     {
24211     case TFmode:
24212       /* __float128 is "g".  */
24213       return "g";
24214     case XFmode:
24215       /* "long double" or __float80 is "e".  */
24216       return "e";
24217     default:
24218       return NULL;
24219     }
24220 }
24221
24222 /* For 32-bit code we can save PIC register setup by using
24223    __stack_chk_fail_local hidden function instead of calling
24224    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
24225    register, so it is better to call __stack_chk_fail directly.  */
24226
24227 static tree
24228 ix86_stack_protect_fail (void)
24229 {
24230   return TARGET_64BIT
24231          ? default_external_stack_protect_fail ()
24232          : default_hidden_stack_protect_fail ();
24233 }
24234
24235 /* Select a format to encode pointers in exception handling data.  CODE
24236    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
24237    true if the symbol may be affected by dynamic relocations.
24238
24239    ??? All x86 object file formats are capable of representing this.
24240    After all, the relocation needed is the same as for the call insn.
24241    Whether or not a particular assembler allows us to enter such, I
24242    guess we'll have to see.  */
24243 int
24244 asm_preferred_eh_data_format (int code, int global)
24245 {
24246   if (flag_pic)
24247     {
24248       int type = DW_EH_PE_sdata8;
24249       if (!TARGET_64BIT
24250           || ix86_cmodel == CM_SMALL_PIC
24251           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
24252         type = DW_EH_PE_sdata4;
24253       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
24254     }
24255   if (ix86_cmodel == CM_SMALL
24256       || (ix86_cmodel == CM_MEDIUM && code))
24257     return DW_EH_PE_udata4;
24258   return DW_EH_PE_absptr;
24259 }
24260 \f
24261 /* Expand copysign from SIGN to the positive value ABS_VALUE
24262    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
24263    the sign-bit.  */
24264 static void
24265 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
24266 {
24267   enum machine_mode mode = GET_MODE (sign);
24268   rtx sgn = gen_reg_rtx (mode);
24269   if (mask == NULL_RTX)
24270     {
24271       mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), false);
24272       if (!VECTOR_MODE_P (mode))
24273         {
24274           /* We need to generate a scalar mode mask in this case.  */
24275           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
24276           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
24277           mask = gen_reg_rtx (mode);
24278           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
24279         }
24280     }
24281   else
24282     mask = gen_rtx_NOT (mode, mask);
24283   emit_insn (gen_rtx_SET (VOIDmode, sgn,
24284                           gen_rtx_AND (mode, mask, sign)));
24285   emit_insn (gen_rtx_SET (VOIDmode, result,
24286                           gen_rtx_IOR (mode, abs_value, sgn)));
24287 }
24288
24289 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
24290    mask for masking out the sign-bit is stored in *SMASK, if that is
24291    non-null.  */
24292 static rtx
24293 ix86_expand_sse_fabs (rtx op0, rtx *smask)
24294 {
24295   enum machine_mode mode = GET_MODE (op0);
24296   rtx xa, mask;
24297
24298   xa = gen_reg_rtx (mode);
24299   mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), true);
24300   if (!VECTOR_MODE_P (mode))
24301     {
24302       /* We need to generate a scalar mode mask in this case.  */
24303       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
24304       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
24305       mask = gen_reg_rtx (mode);
24306       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
24307     }
24308   emit_insn (gen_rtx_SET (VOIDmode, xa,
24309                           gen_rtx_AND (mode, op0, mask)));
24310
24311   if (smask)
24312     *smask = mask;
24313
24314   return xa;
24315 }
24316
24317 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
24318    swapping the operands if SWAP_OPERANDS is true.  The expanded
24319    code is a forward jump to a newly created label in case the
24320    comparison is true.  The generated label rtx is returned.  */
24321 static rtx
24322 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
24323                                   bool swap_operands)
24324 {
24325   rtx label, tmp;
24326
24327   if (swap_operands)
24328     {
24329       tmp = op0;
24330       op0 = op1;
24331       op1 = tmp;
24332     }
24333
24334   label = gen_label_rtx ();
24335   tmp = gen_rtx_REG (CCFPUmode, FLAGS_REG);
24336   emit_insn (gen_rtx_SET (VOIDmode, tmp,
24337                           gen_rtx_COMPARE (CCFPUmode, op0, op1)));
24338   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
24339   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
24340                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
24341   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
24342   JUMP_LABEL (tmp) = label;
24343
24344   return label;
24345 }
24346
24347 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
24348    using comparison code CODE.  Operands are swapped for the comparison if
24349    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
24350 static rtx
24351 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
24352                               bool swap_operands)
24353 {
24354   enum machine_mode mode = GET_MODE (op0);
24355   rtx mask = gen_reg_rtx (mode);
24356
24357   if (swap_operands)
24358     {
24359       rtx tmp = op0;
24360       op0 = op1;
24361       op1 = tmp;
24362     }
24363
24364   if (mode == DFmode)
24365     emit_insn (gen_sse2_maskcmpdf3 (mask, op0, op1,
24366                                     gen_rtx_fmt_ee (code, mode, op0, op1)));
24367   else
24368     emit_insn (gen_sse_maskcmpsf3 (mask, op0, op1,
24369                                    gen_rtx_fmt_ee (code, mode, op0, op1)));
24370
24371   return mask;
24372 }
24373
24374 /* Generate and return a rtx of mode MODE for 2**n where n is the number
24375    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
24376 static rtx
24377 ix86_gen_TWO52 (enum machine_mode mode)
24378 {
24379   REAL_VALUE_TYPE TWO52r;
24380   rtx TWO52;
24381
24382   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
24383   TWO52 = const_double_from_real_value (TWO52r, mode);
24384   TWO52 = force_reg (mode, TWO52);
24385
24386   return TWO52;
24387 }
24388
24389 /* Expand SSE sequence for computing lround from OP1 storing
24390    into OP0.  */
24391 void
24392 ix86_expand_lround (rtx op0, rtx op1)
24393 {
24394   /* C code for the stuff we're doing below:
24395        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
24396        return (long)tmp;
24397    */
24398   enum machine_mode mode = GET_MODE (op1);
24399   const struct real_format *fmt;
24400   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
24401   rtx adj;
24402
24403   /* load nextafter (0.5, 0.0) */
24404   fmt = REAL_MODE_FORMAT (mode);
24405   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
24406   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
24407
24408   /* adj = copysign (0.5, op1) */
24409   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
24410   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
24411
24412   /* adj = op1 + adj */
24413   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
24414
24415   /* op0 = (imode)adj */
24416   expand_fix (op0, adj, 0);
24417 }
24418
24419 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
24420    into OPERAND0.  */
24421 void
24422 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
24423 {
24424   /* C code for the stuff we're doing below (for do_floor):
24425         xi = (long)op1;
24426         xi -= (double)xi > op1 ? 1 : 0;
24427         return xi;
24428    */
24429   enum machine_mode fmode = GET_MODE (op1);
24430   enum machine_mode imode = GET_MODE (op0);
24431   rtx ireg, freg, label, tmp;
24432
24433   /* reg = (long)op1 */
24434   ireg = gen_reg_rtx (imode);
24435   expand_fix (ireg, op1, 0);
24436
24437   /* freg = (double)reg */
24438   freg = gen_reg_rtx (fmode);
24439   expand_float (freg, ireg, 0);
24440
24441   /* ireg = (freg > op1) ? ireg - 1 : ireg */
24442   label = ix86_expand_sse_compare_and_jump (UNLE,
24443                                             freg, op1, !do_floor);
24444   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
24445                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
24446   emit_move_insn (ireg, tmp);
24447
24448   emit_label (label);
24449   LABEL_NUSES (label) = 1;
24450
24451   emit_move_insn (op0, ireg);
24452 }
24453
24454 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
24455    result in OPERAND0.  */
24456 void
24457 ix86_expand_rint (rtx operand0, rtx operand1)
24458 {
24459   /* C code for the stuff we're doing below:
24460         xa = fabs (operand1);
24461         if (!isless (xa, 2**52))
24462           return operand1;
24463         xa = xa + 2**52 - 2**52;
24464         return copysign (xa, operand1);
24465    */
24466   enum machine_mode mode = GET_MODE (operand0);
24467   rtx res, xa, label, TWO52, mask;
24468
24469   res = gen_reg_rtx (mode);
24470   emit_move_insn (res, operand1);
24471
24472   /* xa = abs (operand1) */
24473   xa = ix86_expand_sse_fabs (res, &mask);
24474
24475   /* if (!isless (xa, TWO52)) goto label; */
24476   TWO52 = ix86_gen_TWO52 (mode);
24477   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
24478
24479   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
24480   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
24481
24482   ix86_sse_copysign_to_positive (res, xa, res, mask);
24483
24484   emit_label (label);
24485   LABEL_NUSES (label) = 1;
24486
24487   emit_move_insn (operand0, res);
24488 }
24489
24490 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
24491    into OPERAND0.  */
24492 void
24493 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
24494 {
24495   /* C code for the stuff we expand below.
24496         double xa = fabs (x), x2;
24497         if (!isless (xa, TWO52))
24498           return x;
24499         xa = xa + TWO52 - TWO52;
24500         x2 = copysign (xa, x);
24501      Compensate.  Floor:
24502         if (x2 > x)
24503           x2 -= 1;
24504      Compensate.  Ceil:
24505         if (x2 < x)
24506           x2 -= -1;
24507         return x2;
24508    */
24509   enum machine_mode mode = GET_MODE (operand0);
24510   rtx xa, TWO52, tmp, label, one, res, mask;
24511
24512   TWO52 = ix86_gen_TWO52 (mode);
24513
24514   /* Temporary for holding the result, initialized to the input
24515      operand to ease control flow.  */
24516   res = gen_reg_rtx (mode);
24517   emit_move_insn (res, operand1);
24518
24519   /* xa = abs (operand1) */
24520   xa = ix86_expand_sse_fabs (res, &mask);
24521
24522   /* if (!isless (xa, TWO52)) goto label; */
24523   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
24524
24525   /* xa = xa + TWO52 - TWO52; */
24526   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
24527   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
24528
24529   /* xa = copysign (xa, operand1) */
24530   ix86_sse_copysign_to_positive (xa, xa, res, mask);
24531
24532   /* generate 1.0 or -1.0 */
24533   one = force_reg (mode,
24534                    const_double_from_real_value (do_floor
24535                                                  ? dconst1 : dconstm1, mode));
24536
24537   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
24538   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
24539   emit_insn (gen_rtx_SET (VOIDmode, tmp,
24540                           gen_rtx_AND (mode, one, tmp)));
24541   /* We always need to subtract here to preserve signed zero.  */
24542   tmp = expand_simple_binop (mode, MINUS,
24543                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
24544   emit_move_insn (res, tmp);
24545
24546   emit_label (label);
24547   LABEL_NUSES (label) = 1;
24548
24549   emit_move_insn (operand0, res);
24550 }
24551
24552 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
24553    into OPERAND0.  */
24554 void
24555 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
24556 {
24557   /* C code for the stuff we expand below.
24558         double xa = fabs (x), x2;
24559         if (!isless (xa, TWO52))
24560           return x;
24561         x2 = (double)(long)x;
24562      Compensate.  Floor:
24563         if (x2 > x)
24564           x2 -= 1;
24565      Compensate.  Ceil:
24566         if (x2 < x)
24567           x2 += 1;
24568         if (HONOR_SIGNED_ZEROS (mode))
24569           return copysign (x2, x);
24570         return x2;
24571    */
24572   enum machine_mode mode = GET_MODE (operand0);
24573   rtx xa, xi, TWO52, tmp, label, one, res, mask;
24574
24575   TWO52 = ix86_gen_TWO52 (mode);
24576
24577   /* Temporary for holding the result, initialized to the input
24578      operand to ease control flow.  */
24579   res = gen_reg_rtx (mode);
24580   emit_move_insn (res, operand1);
24581
24582   /* xa = abs (operand1) */
24583   xa = ix86_expand_sse_fabs (res, &mask);
24584
24585   /* if (!isless (xa, TWO52)) goto label; */
24586   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
24587
24588   /* xa = (double)(long)x */
24589   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
24590   expand_fix (xi, res, 0);
24591   expand_float (xa, xi, 0);
24592
24593   /* generate 1.0 */
24594   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
24595
24596   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
24597   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
24598   emit_insn (gen_rtx_SET (VOIDmode, tmp,
24599                           gen_rtx_AND (mode, one, tmp)));
24600   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
24601                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
24602   emit_move_insn (res, tmp);
24603
24604   if (HONOR_SIGNED_ZEROS (mode))
24605     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
24606
24607   emit_label (label);
24608   LABEL_NUSES (label) = 1;
24609
24610   emit_move_insn (operand0, res);
24611 }
24612
24613 /* Expand SSE sequence for computing round from OPERAND1 storing
24614    into OPERAND0.  Sequence that works without relying on DImode truncation
24615    via cvttsd2siq that is only available on 64bit targets.  */
24616 void
24617 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
24618 {
24619   /* C code for the stuff we expand below.
24620         double xa = fabs (x), xa2, x2;
24621         if (!isless (xa, TWO52))
24622           return x;
24623      Using the absolute value and copying back sign makes
24624      -0.0 -> -0.0 correct.
24625         xa2 = xa + TWO52 - TWO52;
24626      Compensate.
24627         dxa = xa2 - xa;
24628         if (dxa <= -0.5)
24629           xa2 += 1;
24630         else if (dxa > 0.5)
24631           xa2 -= 1;
24632         x2 = copysign (xa2, x);
24633         return x2;
24634    */
24635   enum machine_mode mode = GET_MODE (operand0);
24636   rtx xa, xa2, dxa, TWO52, tmp, label, half, mhalf, one, res, mask;
24637
24638   TWO52 = ix86_gen_TWO52 (mode);
24639
24640   /* Temporary for holding the result, initialized to the input
24641      operand to ease control flow.  */
24642   res = gen_reg_rtx (mode);
24643   emit_move_insn (res, operand1);
24644
24645   /* xa = abs (operand1) */
24646   xa = ix86_expand_sse_fabs (res, &mask);
24647
24648   /* if (!isless (xa, TWO52)) goto label; */
24649   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
24650
24651   /* xa2 = xa + TWO52 - TWO52; */
24652   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
24653   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
24654
24655   /* dxa = xa2 - xa; */
24656   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
24657
24658   /* generate 0.5, 1.0 and -0.5 */
24659   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
24660   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
24661   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
24662                                0, OPTAB_DIRECT);
24663
24664   /* Compensate.  */
24665   tmp = gen_reg_rtx (mode);
24666   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
24667   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
24668   emit_insn (gen_rtx_SET (VOIDmode, tmp,
24669                           gen_rtx_AND (mode, one, tmp)));
24670   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
24671   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
24672   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
24673   emit_insn (gen_rtx_SET (VOIDmode, tmp,
24674                           gen_rtx_AND (mode, one, tmp)));
24675   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
24676
24677   /* res = copysign (xa2, operand1) */
24678   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
24679
24680   emit_label (label);
24681   LABEL_NUSES (label) = 1;
24682
24683   emit_move_insn (operand0, res);
24684 }
24685
24686 /* Expand SSE sequence for computing trunc from OPERAND1 storing
24687    into OPERAND0.  */
24688 void
24689 ix86_expand_trunc (rtx operand0, rtx operand1)
24690 {
24691   /* C code for SSE variant we expand below.
24692         double xa = fabs (x), x2;
24693         if (!isless (xa, TWO52))
24694           return x;
24695         x2 = (double)(long)x;
24696         if (HONOR_SIGNED_ZEROS (mode))
24697           return copysign (x2, x);
24698         return x2;
24699    */
24700   enum machine_mode mode = GET_MODE (operand0);
24701   rtx xa, xi, TWO52, label, res, mask;
24702
24703   TWO52 = ix86_gen_TWO52 (mode);
24704
24705   /* Temporary for holding the result, initialized to the input
24706      operand to ease control flow.  */
24707   res = gen_reg_rtx (mode);
24708   emit_move_insn (res, operand1);
24709
24710   /* xa = abs (operand1) */
24711   xa = ix86_expand_sse_fabs (res, &mask);
24712
24713   /* if (!isless (xa, TWO52)) goto label; */
24714   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
24715
24716   /* x = (double)(long)x */
24717   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
24718   expand_fix (xi, res, 0);
24719   expand_float (res, xi, 0);
24720
24721   if (HONOR_SIGNED_ZEROS (mode))
24722     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
24723
24724   emit_label (label);
24725   LABEL_NUSES (label) = 1;
24726
24727   emit_move_insn (operand0, res);
24728 }
24729
24730 /* Expand SSE sequence for computing trunc from OPERAND1 storing
24731    into OPERAND0.  */
24732 void
24733 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
24734 {
24735   enum machine_mode mode = GET_MODE (operand0);
24736   rtx xa, mask, TWO52, label, one, res, smask, tmp;
24737
24738   /* C code for SSE variant we expand below.
24739         double xa = fabs (x), x2;
24740         if (!isless (xa, TWO52))
24741           return x;
24742         xa2 = xa + TWO52 - TWO52;
24743      Compensate:
24744         if (xa2 > xa)
24745           xa2 -= 1.0;
24746         x2 = copysign (xa2, x);
24747         return x2;
24748    */
24749
24750   TWO52 = ix86_gen_TWO52 (mode);
24751
24752   /* Temporary for holding the result, initialized to the input
24753      operand to ease control flow.  */
24754   res = gen_reg_rtx (mode);
24755   emit_move_insn (res, operand1);
24756
24757   /* xa = abs (operand1) */
24758   xa = ix86_expand_sse_fabs (res, &smask);
24759
24760   /* if (!isless (xa, TWO52)) goto label; */
24761   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
24762
24763   /* res = xa + TWO52 - TWO52; */
24764   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
24765   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
24766   emit_move_insn (res, tmp);
24767
24768   /* generate 1.0 */
24769   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
24770
24771   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
24772   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
24773   emit_insn (gen_rtx_SET (VOIDmode, mask,
24774                           gen_rtx_AND (mode, mask, one)));
24775   tmp = expand_simple_binop (mode, MINUS,
24776                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
24777   emit_move_insn (res, tmp);
24778
24779   /* res = copysign (res, operand1) */
24780   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
24781
24782   emit_label (label);
24783   LABEL_NUSES (label) = 1;
24784
24785   emit_move_insn (operand0, res);
24786 }
24787
24788 /* Expand SSE sequence for computing round from OPERAND1 storing
24789    into OPERAND0.  */
24790 void
24791 ix86_expand_round (rtx operand0, rtx operand1)
24792 {
24793   /* C code for the stuff we're doing below:
24794         double xa = fabs (x);
24795         if (!isless (xa, TWO52))
24796           return x;
24797         xa = (double)(long)(xa + nextafter (0.5, 0.0));
24798         return copysign (xa, x);
24799    */
24800   enum machine_mode mode = GET_MODE (operand0);
24801   rtx res, TWO52, xa, label, xi, half, mask;
24802   const struct real_format *fmt;
24803   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
24804
24805   /* Temporary for holding the result, initialized to the input
24806      operand to ease control flow.  */
24807   res = gen_reg_rtx (mode);
24808   emit_move_insn (res, operand1);
24809
24810   TWO52 = ix86_gen_TWO52 (mode);
24811   xa = ix86_expand_sse_fabs (res, &mask);
24812   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
24813
24814   /* load nextafter (0.5, 0.0) */
24815   fmt = REAL_MODE_FORMAT (mode);
24816   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
24817   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
24818
24819   /* xa = xa + 0.5 */
24820   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
24821   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
24822
24823   /* xa = (double)(int64_t)xa */
24824   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
24825   expand_fix (xi, xa, 0);
24826   expand_float (xa, xi, 0);
24827
24828   /* res = copysign (xa, operand1) */
24829   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
24830
24831   emit_label (label);
24832   LABEL_NUSES (label) = 1;
24833
24834   emit_move_insn (operand0, res);
24835 }
24836
24837 \f
24838 /* Validate whether a SSE5 instruction is valid or not.
24839    OPERANDS is the array of operands.
24840    NUM is the number of operands.
24841    USES_OC0 is true if the instruction uses OC0 and provides 4 varients.
24842    NUM_MEMORY is the maximum number of memory operands to accept.  */
24843 bool ix86_sse5_valid_op_p (rtx operands[], rtx insn, int num, bool uses_oc0, int num_memory)
24844 {
24845   int mem_mask;
24846   int mem_count;
24847   int i;
24848
24849   /* Count the number of memory arguments */
24850   mem_mask = 0;
24851   mem_count = 0;
24852   for (i = 0; i < num; i++)
24853     {
24854       enum machine_mode mode = GET_MODE (operands[i]);
24855       if (register_operand (operands[i], mode))
24856         ;
24857
24858       else if (memory_operand (operands[i], mode))
24859         {
24860           mem_mask |= (1 << i);
24861           mem_count++;
24862         }
24863
24864       else
24865         {
24866           rtx pattern = PATTERN (insn);
24867
24868           /* allow 0 for pcmov */
24869           if (GET_CODE (pattern) != SET
24870               || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE
24871               || i < 2
24872               || operands[i] != CONST0_RTX (mode))
24873             return false;
24874         }
24875     }
24876
24877   /* If there were no memory operations, allow the insn */
24878   if (mem_mask == 0)
24879     return true;
24880
24881   /* Do not allow the destination register to be a memory operand.  */
24882   else if (mem_mask & (1 << 0))
24883     return false;
24884
24885   /* If there are too many memory operations, disallow the instruction.  While
24886      the hardware only allows 1 memory reference, before register allocation
24887      for some insns, we allow two memory operations sometimes in order to allow
24888      code like the following to be optimized:
24889
24890         float fmadd (float *a, float *b, float *c) { return (*a * *b) + *c; }
24891
24892     or similar cases that are vectorized into using the fmaddss
24893     instruction.  */
24894   else if (mem_count > num_memory)
24895     return false;
24896
24897   /* Don't allow more than one memory operation if not optimizing.  */
24898   else if (mem_count > 1 && !optimize)
24899     return false;
24900
24901   else if (num == 4 && mem_count == 1)
24902     {
24903       /* formats (destination is the first argument), example fmaddss:
24904          xmm1, xmm1, xmm2, xmm3/mem
24905          xmm1, xmm1, xmm2/mem, xmm3
24906          xmm1, xmm2, xmm3/mem, xmm1
24907          xmm1, xmm2/mem, xmm3, xmm1 */
24908       if (uses_oc0)
24909         return ((mem_mask == (1 << 1))
24910                 || (mem_mask == (1 << 2))
24911                 || (mem_mask == (1 << 3)));
24912
24913       /* format, example pmacsdd:
24914          xmm1, xmm2, xmm3/mem, xmm1 */
24915       else
24916         return (mem_mask == (1 << 2));
24917     }
24918
24919   else if (num == 4 && num_memory == 2)
24920     {
24921       /* If there are two memory operations, we can load one of the memory ops
24922          into the destination register.  This is for optimizating the
24923          multiply/add ops, which the combiner has optimized both the multiply
24924          and the add insns to have a memory operation.  We have to be careful
24925          that the destination doesn't overlap with the inputs.  */
24926       rtx op0 = operands[0];
24927
24928       if (reg_mentioned_p (op0, operands[1])
24929           || reg_mentioned_p (op0, operands[2])
24930           || reg_mentioned_p (op0, operands[3]))
24931         return false;
24932
24933       /* formats (destination is the first argument), example fmaddss:
24934          xmm1, xmm1, xmm2, xmm3/mem
24935          xmm1, xmm1, xmm2/mem, xmm3
24936          xmm1, xmm2, xmm3/mem, xmm1
24937          xmm1, xmm2/mem, xmm3, xmm1
24938
24939          For the oc0 case, we will load either operands[1] or operands[3] into
24940          operands[0], so any combination of 2 memory operands is ok.  */
24941       if (uses_oc0)
24942         return true;
24943
24944       /* format, example pmacsdd:
24945          xmm1, xmm2, xmm3/mem, xmm1
24946
24947          For the integer multiply/add instructions be more restrictive and
24948          require operands[2] and operands[3] to be the memory operands.  */
24949       else
24950         return (mem_mask == ((1 << 2) | (1 << 3)));
24951     }
24952
24953   else if (num == 3 && num_memory == 1)
24954     {
24955       /* formats, example protb:
24956          xmm1, xmm2, xmm3/mem
24957          xmm1, xmm2/mem, xmm3 */
24958       if (uses_oc0)
24959         return ((mem_mask == (1 << 1)) || (mem_mask == (1 << 2)));
24960
24961       /* format, example comeq:
24962          xmm1, xmm2, xmm3/mem */
24963       else
24964         return (mem_mask == (1 << 2));
24965     }
24966
24967   else
24968     gcc_unreachable ();
24969
24970   return false;
24971 }
24972
24973 \f
24974 /* Fixup an SSE5 instruction that has 2 memory input references into a form the
24975    hardware will allow by using the destination register to load one of the
24976    memory operations.  Presently this is used by the multiply/add routines to
24977    allow 2 memory references.  */
24978
24979 void
24980 ix86_expand_sse5_multiple_memory (rtx operands[],
24981                                   int num,
24982                                   enum machine_mode mode)
24983 {
24984   rtx op0 = operands[0];
24985   if (num != 4
24986       || memory_operand (op0, mode)
24987       || reg_mentioned_p (op0, operands[1])
24988       || reg_mentioned_p (op0, operands[2])
24989       || reg_mentioned_p (op0, operands[3]))
24990     gcc_unreachable ();
24991
24992   /* For 2 memory operands, pick either operands[1] or operands[3] to move into
24993      the destination register.  */
24994   if (memory_operand (operands[1], mode))
24995     {
24996       emit_move_insn (op0, operands[1]);
24997       operands[1] = op0;
24998     }
24999   else if (memory_operand (operands[3], mode))
25000     {
25001       emit_move_insn (op0, operands[3]);
25002       operands[3] = op0;
25003     }
25004   else
25005     gcc_unreachable ();
25006
25007   return;
25008 }
25009
25010 \f
25011 /* Table of valid machine attributes.  */
25012 static const struct attribute_spec ix86_attribute_table[] =
25013 {
25014   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
25015   /* Stdcall attribute says callee is responsible for popping arguments
25016      if they are not variable.  */
25017   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute },
25018   /* Fastcall attribute says callee is responsible for popping arguments
25019      if they are not variable.  */
25020   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute },
25021   /* Cdecl attribute says the callee is a normal C declaration */
25022   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute },
25023   /* Regparm attribute specifies how many integer arguments are to be
25024      passed in registers.  */
25025   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute },
25026   /* Sseregparm attribute says we are using x86_64 calling conventions
25027      for FP arguments.  */
25028   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute },
25029   /* force_align_arg_pointer says this function realigns the stack at entry.  */
25030   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
25031     false, true,  true, ix86_handle_cconv_attribute },
25032 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
25033   { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
25034   { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
25035   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute },
25036 #endif
25037   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
25038   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
25039 #ifdef SUBTARGET_ATTRIBUTE_TABLE
25040   SUBTARGET_ATTRIBUTE_TABLE,
25041 #endif
25042   { NULL,        0, 0, false, false, false, NULL }
25043 };
25044
25045 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
25046 static int
25047 x86_builtin_vectorization_cost (bool runtime_test)
25048 {
25049   /* If the branch of the runtime test is taken - i.e. - the vectorized
25050      version is skipped - this incurs a misprediction cost (because the
25051      vectorized version is expected to be the fall-through).  So we subtract
25052      the latency of a mispredicted branch from the costs that are incured
25053      when the vectorized version is executed.
25054
25055      TODO: The values in individual target tables have to be tuned or new
25056      fields may be needed. For eg. on K8, the default branch path is the
25057      not-taken path. If the taken path is predicted correctly, the minimum
25058      penalty of going down the taken-path is 1 cycle. If the taken-path is
25059      not predicted correctly, then the minimum penalty is 10 cycles.  */
25060
25061   if (runtime_test)
25062     {
25063       return (-(ix86_cost->cond_taken_branch_cost));
25064     }
25065   else
25066     return 0;
25067 }
25068
25069 /* Initialize the GCC target structure.  */
25070 #undef TARGET_ATTRIBUTE_TABLE
25071 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
25072 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
25073 #  undef TARGET_MERGE_DECL_ATTRIBUTES
25074 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
25075 #endif
25076
25077 #undef TARGET_COMP_TYPE_ATTRIBUTES
25078 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
25079
25080 #undef TARGET_INIT_BUILTINS
25081 #define TARGET_INIT_BUILTINS ix86_init_builtins
25082 #undef TARGET_EXPAND_BUILTIN
25083 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
25084
25085 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
25086 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
25087   ix86_builtin_vectorized_function
25088
25089 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
25090 #define TARGET_VECTORIZE_BUILTIN_CONVERSION ix86_vectorize_builtin_conversion
25091
25092 #undef TARGET_BUILTIN_RECIPROCAL
25093 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
25094
25095 #undef TARGET_ASM_FUNCTION_EPILOGUE
25096 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
25097
25098 #undef TARGET_ENCODE_SECTION_INFO
25099 #ifndef SUBTARGET_ENCODE_SECTION_INFO
25100 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
25101 #else
25102 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
25103 #endif
25104
25105 #undef TARGET_ASM_OPEN_PAREN
25106 #define TARGET_ASM_OPEN_PAREN ""
25107 #undef TARGET_ASM_CLOSE_PAREN
25108 #define TARGET_ASM_CLOSE_PAREN ""
25109
25110 #undef TARGET_ASM_ALIGNED_HI_OP
25111 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
25112 #undef TARGET_ASM_ALIGNED_SI_OP
25113 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
25114 #ifdef ASM_QUAD
25115 #undef TARGET_ASM_ALIGNED_DI_OP
25116 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
25117 #endif
25118
25119 #undef TARGET_ASM_UNALIGNED_HI_OP
25120 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
25121 #undef TARGET_ASM_UNALIGNED_SI_OP
25122 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
25123 #undef TARGET_ASM_UNALIGNED_DI_OP
25124 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
25125
25126 #undef TARGET_SCHED_ADJUST_COST
25127 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
25128 #undef TARGET_SCHED_ISSUE_RATE
25129 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
25130 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
25131 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
25132   ia32_multipass_dfa_lookahead
25133
25134 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
25135 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
25136
25137 #ifdef HAVE_AS_TLS
25138 #undef TARGET_HAVE_TLS
25139 #define TARGET_HAVE_TLS true
25140 #endif
25141 #undef TARGET_CANNOT_FORCE_CONST_MEM
25142 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
25143 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
25144 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
25145
25146 #undef TARGET_DELEGITIMIZE_ADDRESS
25147 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
25148
25149 #undef TARGET_MS_BITFIELD_LAYOUT_P
25150 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
25151
25152 #if TARGET_MACHO
25153 #undef TARGET_BINDS_LOCAL_P
25154 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
25155 #endif
25156 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
25157 #undef TARGET_BINDS_LOCAL_P
25158 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
25159 #endif
25160
25161 #undef TARGET_ASM_OUTPUT_MI_THUNK
25162 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
25163 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
25164 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
25165
25166 #undef TARGET_ASM_FILE_START
25167 #define TARGET_ASM_FILE_START x86_file_start
25168
25169 #undef TARGET_DEFAULT_TARGET_FLAGS
25170 #define TARGET_DEFAULT_TARGET_FLAGS     \
25171   (TARGET_DEFAULT                       \
25172    | TARGET_SUBTARGET_DEFAULT           \
25173    | TARGET_TLS_DIRECT_SEG_REFS_DEFAULT)
25174
25175 #undef TARGET_HANDLE_OPTION
25176 #define TARGET_HANDLE_OPTION ix86_handle_option
25177
25178 #undef TARGET_RTX_COSTS
25179 #define TARGET_RTX_COSTS ix86_rtx_costs
25180 #undef TARGET_ADDRESS_COST
25181 #define TARGET_ADDRESS_COST ix86_address_cost
25182
25183 #undef TARGET_FIXED_CONDITION_CODE_REGS
25184 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
25185 #undef TARGET_CC_MODES_COMPATIBLE
25186 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
25187
25188 #undef TARGET_MACHINE_DEPENDENT_REORG
25189 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
25190
25191 #undef TARGET_BUILD_BUILTIN_VA_LIST
25192 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
25193
25194 #undef TARGET_MD_ASM_CLOBBERS
25195 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
25196
25197 #undef TARGET_PROMOTE_PROTOTYPES
25198 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
25199 #undef TARGET_STRUCT_VALUE_RTX
25200 #define TARGET_STRUCT_VALUE_RTX ix86_struct_value_rtx
25201 #undef TARGET_SETUP_INCOMING_VARARGS
25202 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
25203 #undef TARGET_MUST_PASS_IN_STACK
25204 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
25205 #undef TARGET_PASS_BY_REFERENCE
25206 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
25207 #undef TARGET_INTERNAL_ARG_POINTER
25208 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
25209 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
25210 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC ix86_dwarf_handle_frame_unspec
25211 #undef TARGET_STRICT_ARGUMENT_NAMING
25212 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
25213
25214 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
25215 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
25216
25217 #undef TARGET_SCALAR_MODE_SUPPORTED_P
25218 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
25219
25220 #undef TARGET_VECTOR_MODE_SUPPORTED_P
25221 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
25222
25223 #undef TARGET_C_MODE_FOR_SUFFIX
25224 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
25225
25226 #ifdef HAVE_AS_TLS
25227 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
25228 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
25229 #endif
25230
25231 #ifdef SUBTARGET_INSERT_ATTRIBUTES
25232 #undef TARGET_INSERT_ATTRIBUTES
25233 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
25234 #endif
25235
25236 #undef TARGET_MANGLE_TYPE
25237 #define TARGET_MANGLE_TYPE ix86_mangle_type
25238
25239 #undef TARGET_STACK_PROTECT_FAIL
25240 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
25241
25242 #undef TARGET_FUNCTION_VALUE
25243 #define TARGET_FUNCTION_VALUE ix86_function_value
25244
25245 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
25246 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST x86_builtin_vectorization_cost
25247
25248 struct gcc_target targetm = TARGET_INITIALIZER;
25249 \f
25250 #include "gt-i386.h"