OSDN Git Service

* config/i386/i386.c (ix86_expand_branch): Treat GE and GEU the same
[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
3    Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC 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 2, or (at your option)
10 any later version.
11
12 GNU CC 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 GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include <setjmp.h>
23 #include "config.h"
24 #include "system.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 "insn-flags.h"
34 #include "output.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 "toplev.h"
42 #include "basic-block.h"
43 #include "ggc.h"
44
45 #ifdef EXTRA_CONSTRAINT
46 /* If EXTRA_CONSTRAINT is defined, then the 'S'
47    constraint in REG_CLASS_FROM_LETTER will no longer work, and various
48    asm statements that need 'S' for class SIREG will break.  */
49  error EXTRA_CONSTRAINT conflicts with S constraint letter
50 /* The previous line used to be #error, but some compilers barf
51    even if the conditional was untrue.  */
52 #endif
53
54 #ifndef CHECK_STACK_LIMIT
55 #define CHECK_STACK_LIMIT -1
56 #endif
57
58 /* Processor costs (relative to an add) */
59 struct processor_costs i386_cost = {    /* 386 specific costs */
60   1,                                    /* cost of an add instruction */
61   1,                                    /* cost of a lea instruction */
62   3,                                    /* variable shift costs */
63   2,                                    /* constant shift costs */
64   6,                                    /* cost of starting a multiply */
65   1,                                    /* cost of multiply per each bit set */
66   23,                                   /* cost of a divide/mod */
67   15,                                   /* "large" insn */
68   3,                                    /* MOVE_RATIO */
69   4,                                    /* cost for loading QImode using movzbl */
70   {2, 4, 2},                            /* cost of loading integer registers
71                                            in QImode, HImode and SImode.
72                                            Relative to reg-reg move (2). */
73   {2, 4, 2},                            /* cost of storing integer registers */
74   2,                                    /* cost of reg,reg fld/fst */
75   {8, 8, 8},                            /* cost of loading fp registers
76                                            in SFmode, DFmode and XFmode */
77   {8, 8, 8}                             /* cost of loading integer registers */
78 };
79
80 struct processor_costs i486_cost = {    /* 486 specific costs */
81   1,                                    /* cost of an add instruction */
82   1,                                    /* cost of a lea instruction */
83   3,                                    /* variable shift costs */
84   2,                                    /* constant shift costs */
85   12,                                   /* cost of starting a multiply */
86   1,                                    /* cost of multiply per each bit set */
87   40,                                   /* cost of a divide/mod */
88   15,                                   /* "large" insn */
89   3,                                    /* MOVE_RATIO */
90   4,                                    /* cost for loading QImode using movzbl */
91   {2, 4, 2},                            /* cost of loading integer registers
92                                            in QImode, HImode and SImode.
93                                            Relative to reg-reg move (2). */
94   {2, 4, 2},                            /* cost of storing integer registers */
95   2,                                    /* cost of reg,reg fld/fst */
96   {8, 8, 8},                            /* cost of loading fp registers
97                                            in SFmode, DFmode and XFmode */
98   {8, 8, 8}                             /* cost of loading integer registers */
99 };
100
101 struct processor_costs pentium_cost = {
102   1,                                    /* cost of an add instruction */
103   1,                                    /* cost of a lea instruction */
104   4,                                    /* variable shift costs */
105   1,                                    /* constant shift costs */
106   11,                                   /* cost of starting a multiply */
107   0,                                    /* cost of multiply per each bit set */
108   25,                                   /* cost of a divide/mod */
109   8,                                    /* "large" insn */
110   6,                                    /* MOVE_RATIO */
111   6,                                    /* cost for loading QImode using movzbl */
112   {2, 4, 2},                            /* cost of loading integer registers
113                                            in QImode, HImode and SImode.
114                                            Relative to reg-reg move (2). */
115   {2, 4, 2},                            /* cost of storing integer registers */
116   2,                                    /* cost of reg,reg fld/fst */
117   {2, 2, 6},                            /* cost of loading fp registers
118                                            in SFmode, DFmode and XFmode */
119   {4, 4, 6}                             /* cost of loading integer registers */
120 };
121
122 struct processor_costs pentiumpro_cost = {
123   1,                                    /* cost of an add instruction */
124   1,                                    /* cost of a lea instruction */
125   1,                                    /* variable shift costs */
126   1,                                    /* constant shift costs */
127   4,                                    /* cost of starting a multiply */
128   0,                                    /* cost of multiply per each bit set */
129   17,                                   /* cost of a divide/mod */
130   8,                                    /* "large" insn */
131   6,                                    /* MOVE_RATIO */
132   2,                                    /* cost for loading QImode using movzbl */
133   {4, 4, 4},                            /* cost of loading integer registers
134                                            in QImode, HImode and SImode.
135                                            Relative to reg-reg move (2). */
136   {2, 2, 2},                            /* cost of storing integer registers */
137   2,                                    /* cost of reg,reg fld/fst */
138   {2, 2, 6},                            /* cost of loading fp registers
139                                            in SFmode, DFmode and XFmode */
140   {4, 4, 6}                             /* cost of loading integer registers */
141 };
142
143 struct processor_costs k6_cost = {
144   1,                                    /* cost of an add instruction */
145   2,                                    /* cost of a lea instruction */
146   1,                                    /* variable shift costs */
147   1,                                    /* constant shift costs */
148   3,                                    /* cost of starting a multiply */
149   0,                                    /* cost of multiply per each bit set */
150   18,                                   /* cost of a divide/mod */
151   8,                                    /* "large" insn */
152   4,                                    /* MOVE_RATIO */
153   3,                                    /* cost for loading QImode using movzbl */
154   {4, 5, 4},                            /* cost of loading integer registers
155                                            in QImode, HImode and SImode.
156                                            Relative to reg-reg move (2). */
157   {2, 3, 2},                            /* cost of storing integer registers */
158   4,                                    /* cost of reg,reg fld/fst */
159   {6, 6, 6},                            /* cost of loading fp registers
160                                            in SFmode, DFmode and XFmode */
161   {4, 4, 4}                             /* cost of loading integer registers */
162 };
163
164 struct processor_costs athlon_cost = {
165   1,                                    /* cost of an add instruction */
166   2,                                    /* cost of a lea instruction */
167   1,                                    /* variable shift costs */
168   1,                                    /* constant shift costs */
169   5,                                    /* cost of starting a multiply */
170   0,                                    /* cost of multiply per each bit set */
171   42,                                   /* cost of a divide/mod */
172   8,                                    /* "large" insn */
173   9,                                    /* MOVE_RATIO */
174   4,                                    /* cost for loading QImode using movzbl */
175   {4, 5, 4},                            /* cost of loading integer registers
176                                            in QImode, HImode and SImode.
177                                            Relative to reg-reg move (2). */
178   {2, 3, 2},                            /* cost of storing integer registers */
179   4,                                    /* cost of reg,reg fld/fst */
180   {6, 6, 20},                           /* cost of loading fp registers
181                                            in SFmode, DFmode and XFmode */
182   {4, 4, 16}                            /* cost of loading integer registers */
183 };
184
185 struct processor_costs *ix86_cost = &pentium_cost;
186
187 /* Processor feature/optimization bitmasks.  */
188 #define m_386 (1<<PROCESSOR_I386)
189 #define m_486 (1<<PROCESSOR_I486)
190 #define m_PENT (1<<PROCESSOR_PENTIUM)
191 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
192 #define m_K6  (1<<PROCESSOR_K6)
193 #define m_ATHLON  (1<<PROCESSOR_ATHLON)
194
195 const int x86_use_leave = m_386 | m_K6 | m_ATHLON;
196 const int x86_push_memory = m_386 | m_K6 | m_ATHLON;
197 const int x86_zero_extend_with_and = m_486 | m_PENT;
198 const int x86_movx = m_ATHLON | m_PPRO /* m_386 | m_K6 */;
199 const int x86_double_with_add = ~m_386;
200 const int x86_use_bit_test = m_386;
201 const int x86_unroll_strlen = m_486 | m_PENT | m_PPRO | m_ATHLON | m_K6;
202 const int x86_use_q_reg = m_PENT | m_PPRO | m_K6;
203 const int x86_use_any_reg = m_486;
204 const int x86_cmove = m_PPRO | m_ATHLON;
205 const int x86_deep_branch = m_PPRO | m_K6 | m_ATHLON;
206 const int x86_use_sahf = m_PPRO | m_K6 | m_ATHLON;
207 const int x86_partial_reg_stall = m_PPRO;
208 const int x86_use_loop = m_K6;
209 const int x86_use_fiop = ~(m_PPRO | m_ATHLON | m_PENT);
210 const int x86_use_mov0 = m_K6;
211 const int x86_use_cltd = ~(m_PENT | m_K6);
212 const int x86_read_modify_write = ~m_PENT;
213 const int x86_read_modify = ~(m_PENT | m_PPRO);
214 const int x86_split_long_moves = m_PPRO;
215 const int x86_promote_QImode = m_K6 | m_PENT | m_386 | m_486;
216 const int x86_single_stringop = m_386;
217 const int x86_qimode_math = ~(0);
218 const int x86_promote_qi_regs = 0;
219 const int x86_himode_math = ~(m_PPRO);
220 const int x86_promote_hi_regs = m_PPRO;
221 const int x86_sub_esp_4 = m_ATHLON | m_PPRO;
222 const int x86_sub_esp_8 = m_ATHLON | m_PPRO | m_386 | m_486;
223 const int x86_add_esp_4 = m_ATHLON | m_K6;
224 const int x86_add_esp_8 = m_ATHLON | m_PPRO | m_K6 | m_386 | m_486;
225 const int x86_integer_DFmode_moves = ~m_ATHLON;
226 const int x86_partial_reg_dependency = m_ATHLON;
227 const int x86_memory_mismatch_stall = m_ATHLON;
228
229 #define AT_BP(mode) (gen_rtx_MEM ((mode), hard_frame_pointer_rtx))
230
231 const char * const hi_reg_name[] = HI_REGISTER_NAMES;
232 const char * const qi_reg_name[] = QI_REGISTER_NAMES;
233 const char * const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
234
235 /* Array of the smallest class containing reg number REGNO, indexed by
236    REGNO.  Used by REGNO_REG_CLASS in i386.h. */
237
238 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
239 {
240   /* ax, dx, cx, bx */
241   AREG, DREG, CREG, BREG,
242   /* si, di, bp, sp */
243   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
244   /* FP registers */
245   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
246   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
247   /* arg pointer */
248   NON_Q_REGS,
249   /* flags, fpsr, dirflag, frame */
250   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
251   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
252   SSE_REGS, SSE_REGS,
253   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
254   MMX_REGS, MMX_REGS
255 };
256
257 /* The "default" register map.  */
258
259 int const dbx_register_map[FIRST_PSEUDO_REGISTER] = 
260 {
261   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
262   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
263   -1, -1, -1, -1,                       /* arg, flags, fpsr, dir */
264   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
265   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
266 };
267
268 /* Define the register numbers to be used in Dwarf debugging information.
269    The SVR4 reference port C compiler uses the following register numbers
270    in its Dwarf output code:
271         0 for %eax (gcc regno = 0)
272         1 for %ecx (gcc regno = 2)
273         2 for %edx (gcc regno = 1)
274         3 for %ebx (gcc regno = 3)
275         4 for %esp (gcc regno = 7)
276         5 for %ebp (gcc regno = 6)
277         6 for %esi (gcc regno = 4)
278         7 for %edi (gcc regno = 5)
279    The following three DWARF register numbers are never generated by
280    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
281    believes these numbers have these meanings.
282         8  for %eip    (no gcc equivalent)
283         9  for %eflags (gcc regno = 17)
284         10 for %trapno (no gcc equivalent)
285    It is not at all clear how we should number the FP stack registers
286    for the x86 architecture.  If the version of SDB on x86/svr4 were
287    a bit less brain dead with respect to floating-point then we would
288    have a precedent to follow with respect to DWARF register numbers
289    for x86 FP registers, but the SDB on x86/svr4 is so completely
290    broken with respect to FP registers that it is hardly worth thinking
291    of it as something to strive for compatibility with.
292    The version of x86/svr4 SDB I have at the moment does (partially)
293    seem to believe that DWARF register number 11 is associated with
294    the x86 register %st(0), but that's about all.  Higher DWARF
295    register numbers don't seem to be associated with anything in
296    particular, and even for DWARF regno 11, SDB only seems to under-
297    stand that it should say that a variable lives in %st(0) (when
298    asked via an `=' command) if we said it was in DWARF regno 11,
299    but SDB still prints garbage when asked for the value of the
300    variable in question (via a `/' command).
301    (Also note that the labels SDB prints for various FP stack regs
302    when doing an `x' command are all wrong.)
303    Note that these problems generally don't affect the native SVR4
304    C compiler because it doesn't allow the use of -O with -g and
305    because when it is *not* optimizing, it allocates a memory
306    location for each floating-point variable, and the memory
307    location is what gets described in the DWARF AT_location
308    attribute for the variable in question.
309    Regardless of the severe mental illness of the x86/svr4 SDB, we
310    do something sensible here and we use the following DWARF
311    register numbers.  Note that these are all stack-top-relative
312    numbers.
313         11 for %st(0) (gcc regno = 8)
314         12 for %st(1) (gcc regno = 9)
315         13 for %st(2) (gcc regno = 10)
316         14 for %st(3) (gcc regno = 11)
317         15 for %st(4) (gcc regno = 12)
318         16 for %st(5) (gcc regno = 13)
319         17 for %st(6) (gcc regno = 14)
320         18 for %st(7) (gcc regno = 15)
321 */
322 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] = 
323 {
324   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
325   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
326   -1, 9, -1, -1,                        /* arg, flags, fpsr, dir */
327   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
328   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
329 };
330
331
332
333 /* Test and compare insns in i386.md store the information needed to
334    generate branch and scc insns here.  */
335
336 struct rtx_def *ix86_compare_op0 = NULL_RTX;
337 struct rtx_def *ix86_compare_op1 = NULL_RTX;
338
339 #define MAX_386_STACK_LOCALS 2
340
341 /* Define the structure for the machine field in struct function.  */
342 struct machine_function
343 {
344   rtx stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS];
345 };
346
347 #define ix86_stack_locals (cfun->machine->stack_locals)
348
349 /* which cpu are we scheduling for */
350 enum processor_type ix86_cpu;
351
352 /* which instruction set architecture to use.  */
353 int ix86_arch;
354
355 /* Strings to hold which cpu and instruction set architecture  to use.  */
356 const char *ix86_cpu_string;            /* for -mcpu=<xxx> */
357 const char *ix86_arch_string;           /* for -march=<xxx> */
358
359 /* Register allocation order */
360 const char *ix86_reg_alloc_order;
361 static char regs_allocated[FIRST_PSEUDO_REGISTER];
362
363 /* # of registers to use to pass arguments. */
364 const char *ix86_regparm_string;
365
366 /* ix86_regparm_string as a number */
367 int ix86_regparm;
368
369 /* Alignment to use for loops and jumps:  */
370
371 /* Power of two alignment for loops. */
372 const char *ix86_align_loops_string;
373
374 /* Power of two alignment for non-loop jumps. */
375 const char *ix86_align_jumps_string;
376
377 /* Power of two alignment for stack boundary in bytes.  */
378 const char *ix86_preferred_stack_boundary_string;
379
380 /* Preferred alignment for stack boundary in bits.  */
381 int ix86_preferred_stack_boundary;
382
383 /* Values 1-5: see jump.c */
384 int ix86_branch_cost;
385 const char *ix86_branch_cost_string;
386
387 /* Power of two alignment for functions. */
388 int ix86_align_funcs;
389 const char *ix86_align_funcs_string;
390
391 /* Power of two alignment for loops. */
392 int ix86_align_loops;
393
394 /* Power of two alignment for non-loop jumps. */
395 int ix86_align_jumps;
396 \f
397 static void output_pic_addr_const PARAMS ((FILE *, rtx, int));
398 static void put_condition_code PARAMS ((enum rtx_code, enum machine_mode,
399                                        int, int, FILE *));
400 static enum rtx_code unsigned_comparison PARAMS ((enum rtx_code code));
401 static rtx ix86_expand_int_compare PARAMS ((enum rtx_code, rtx, rtx));
402 static enum machine_mode ix86_fp_compare_mode PARAMS ((enum rtx_code));
403 static enum rtx_code ix86_prepare_fp_compare_args PARAMS ((enum rtx_code,
404                                                            rtx *, rtx *));
405 static rtx ix86_expand_compare PARAMS ((enum rtx_code));
406 static rtx gen_push PARAMS ((rtx));
407 static int memory_address_length PARAMS ((rtx addr));
408 static int ix86_flags_dependant PARAMS ((rtx, rtx, enum attr_type));
409 static int ix86_agi_dependant PARAMS ((rtx, rtx, enum attr_type));
410 static int ix86_safe_length PARAMS ((rtx));
411 static enum attr_memory ix86_safe_memory PARAMS ((rtx));
412 static enum attr_pent_pair ix86_safe_pent_pair PARAMS ((rtx));
413 static enum attr_ppro_uops ix86_safe_ppro_uops PARAMS ((rtx));
414 static void ix86_dump_ppro_packet PARAMS ((FILE *));
415 static void ix86_reorder_insn PARAMS ((rtx *, rtx *));
416 static rtx * ix86_pent_find_pair PARAMS ((rtx *, rtx *, enum attr_pent_pair,
417                                          rtx));
418 static void ix86_init_machine_status PARAMS ((struct function *));
419 static void ix86_mark_machine_status PARAMS ((struct function *));
420 static void ix86_split_to_parts PARAMS ((rtx, rtx *, enum machine_mode));
421 static int ix86_safe_length_prefix PARAMS ((rtx));
422 static HOST_WIDE_INT ix86_compute_frame_size PARAMS((HOST_WIDE_INT,
423                                                      int *, int *, int *));
424 static int ix86_nsaved_regs PARAMS((void));
425 static void ix86_emit_save_regs PARAMS((void));
426 static void ix86_emit_restore_regs_using_mov PARAMS ((rtx, int));
427 static void ix86_emit_epilogue_esp_adjustment PARAMS((int));
428 static void ix86_sched_reorder_pentium PARAMS((rtx *, rtx *));
429 static void ix86_sched_reorder_ppro PARAMS((rtx *, rtx *));
430 static HOST_WIDE_INT ix86_GOT_alias_set PARAMS ((void));
431
432 struct ix86_address
433 {
434   rtx base, index, disp;
435   HOST_WIDE_INT scale;
436 };
437
438 static int ix86_decompose_address PARAMS ((rtx, struct ix86_address *));
439 \f
440 /* Sometimes certain combinations of command options do not make
441    sense on a particular target machine.  You can define a macro
442    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
443    defined, is executed once just after all the command options have
444    been parsed.
445
446    Don't use this macro to turn on various extra optimizations for
447    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
448
449 void
450 override_options ()
451 {
452   /* Comes from final.c -- no real reason to change it.  */
453 #define MAX_CODE_ALIGN 16
454
455   static struct ptt
456     {
457       struct processor_costs *cost;     /* Processor costs */
458       int target_enable;                /* Target flags to enable.  */
459       int target_disable;               /* Target flags to disable.  */
460       int align_loop;                   /* Default alignments.  */
461       int align_jump;
462       int align_func;
463       int branch_cost;
464     }
465   const processor_target_table[PROCESSOR_max] = 
466     {
467       {&i386_cost, 0, 0, 2, 2, 2, 1},
468       {&i486_cost, 0, 0, 4, 4, 4, 1},
469       {&pentium_cost, 0, 0, -4, -4, -4, 1},
470       {&pentiumpro_cost, 0, 0, 4, -4, 4, 1},
471       {&k6_cost, 0, 0, -5, -5, 4, 1},
472       {&athlon_cost, 0, 0, 4, -4, 4, 1}
473     };
474
475   static struct pta
476     {
477       const char *name;         /* processor name or nickname. */
478       enum processor_type processor;
479     }
480   const processor_alias_table[] = 
481     {
482       {"i386", PROCESSOR_I386},
483       {"i486", PROCESSOR_I486},
484       {"i586", PROCESSOR_PENTIUM},
485       {"pentium", PROCESSOR_PENTIUM},
486       {"i686", PROCESSOR_PENTIUMPRO},
487       {"pentiumpro", PROCESSOR_PENTIUMPRO},
488       {"k6", PROCESSOR_K6},
489       {"athlon", PROCESSOR_ATHLON},
490     };
491
492   int const pta_size = sizeof(processor_alias_table)/sizeof(struct pta);
493
494 #ifdef SUBTARGET_OVERRIDE_OPTIONS
495   SUBTARGET_OVERRIDE_OPTIONS;
496 #endif
497
498   ix86_arch = PROCESSOR_I386;
499   ix86_cpu = (enum processor_type) TARGET_CPU_DEFAULT;
500
501   if (ix86_arch_string != 0)
502     {
503       int i;
504       for (i = 0; i < pta_size; i++)
505         if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
506           {
507             ix86_arch = processor_alias_table[i].processor;
508             /* Default cpu tuning to the architecture.  */
509             ix86_cpu = ix86_arch;
510             break;
511           }
512       if (i == pta_size)
513         error ("bad value (%s) for -march= switch", ix86_arch_string);
514     }
515
516   if (ix86_cpu_string != 0)
517     {
518       int i;
519       for (i = 0; i < pta_size; i++)
520         if (! strcmp (ix86_cpu_string, processor_alias_table[i].name))
521           {
522             ix86_cpu = processor_alias_table[i].processor;
523             break;
524           }
525       if (i == pta_size)
526         error ("bad value (%s) for -mcpu= switch", ix86_cpu_string);
527     }
528
529   ix86_cost = processor_target_table[ix86_cpu].cost;
530   target_flags |= processor_target_table[ix86_cpu].target_enable;
531   target_flags &= ~processor_target_table[ix86_cpu].target_disable;
532
533   /* Arrange to set up i386_stack_locals for all functions.  */
534   init_machine_status = ix86_init_machine_status;
535   mark_machine_status = ix86_mark_machine_status;
536
537   /* Validate registers in register allocation order.  */
538   if (ix86_reg_alloc_order)
539     {
540       int i, ch;
541       for (i = 0; (ch = ix86_reg_alloc_order[i]) != '\0'; i++)
542         {
543           int regno = 0;
544
545           switch (ch)
546             {
547             case 'a':   regno = 0;      break;
548             case 'd':   regno = 1;      break;
549             case 'c':   regno = 2;      break;
550             case 'b':   regno = 3;      break;
551             case 'S':   regno = 4;      break;
552             case 'D':   regno = 5;      break;
553             case 'B':   regno = 6;      break;
554
555             default:    fatal ("Register '%c' is unknown", ch);
556             }
557
558           if (regs_allocated[regno])
559             fatal ("Register '%c' already specified in allocation order", ch);
560
561           regs_allocated[regno] = 1;
562         }
563     }
564
565   /* Validate -mregparm= value. */
566   if (ix86_regparm_string)
567     {
568       ix86_regparm = atoi (ix86_regparm_string);
569       if (ix86_regparm < 0 || ix86_regparm > REGPARM_MAX)
570         fatal ("-mregparm=%d is not between 0 and %d",
571                ix86_regparm, REGPARM_MAX);
572     }
573
574   /* Validate -malign-loops= value, or provide default.  */
575   ix86_align_loops = processor_target_table[ix86_cpu].align_loop;
576   if (ix86_align_loops_string)
577     {
578       ix86_align_loops = atoi (ix86_align_loops_string);
579       if (ix86_align_loops < 0 || ix86_align_loops > MAX_CODE_ALIGN)
580         fatal ("-malign-loops=%d is not between 0 and %d",
581                ix86_align_loops, MAX_CODE_ALIGN);
582     }
583
584   /* Validate -malign-jumps= value, or provide default.  */
585   ix86_align_jumps = processor_target_table[ix86_cpu].align_jump;
586   if (ix86_align_jumps_string)
587     {
588       ix86_align_jumps = atoi (ix86_align_jumps_string);
589       if (ix86_align_jumps < 0 || ix86_align_jumps > MAX_CODE_ALIGN)
590         fatal ("-malign-jumps=%d is not between 0 and %d",
591                ix86_align_jumps, MAX_CODE_ALIGN);
592     }
593
594   /* Validate -malign-functions= value, or provide default. */
595   ix86_align_funcs = processor_target_table[ix86_cpu].align_func;
596   if (ix86_align_funcs_string)
597     {
598       ix86_align_funcs = atoi (ix86_align_funcs_string);
599       if (ix86_align_funcs < 0 || ix86_align_funcs > MAX_CODE_ALIGN)
600         fatal ("-malign-functions=%d is not between 0 and %d",
601                ix86_align_funcs, MAX_CODE_ALIGN);
602     }
603
604   /* Validate -mpreferred-stack-boundary= value, or provide default.
605      The default of 128 bits is for Pentium III's SSE __m128.  */
606   ix86_preferred_stack_boundary = 128;
607   if (ix86_preferred_stack_boundary_string)
608     {
609       int i = atoi (ix86_preferred_stack_boundary_string);
610       if (i < 2 || i > 31)
611         fatal ("-mpreferred-stack-boundary=%d is not between 2 and 31", i);
612       ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
613     }
614
615   /* Validate -mbranch-cost= value, or provide default. */
616   ix86_branch_cost = processor_target_table[ix86_cpu].branch_cost;
617   if (ix86_branch_cost_string)
618     {
619       ix86_branch_cost = atoi (ix86_branch_cost_string);
620       if (ix86_branch_cost < 0 || ix86_branch_cost > 5)
621         fatal ("-mbranch-cost=%d is not between 0 and 5",
622                ix86_branch_cost);
623     }
624
625   /* Keep nonleaf frame pointers.  */
626   if (TARGET_OMIT_LEAF_FRAME_POINTER)
627     flag_omit_frame_pointer = 1;
628
629   /* If we're doing fast math, we don't care about comparison order
630      wrt NaNs.  This lets us use a shorter comparison sequence.  */
631   if (flag_fast_math)
632     target_flags &= ~MASK_IEEE_FP;
633
634   /* It makes no sense to ask for just SSE builtins, so MMX is also turned
635      on by -msse.  */
636   if (TARGET_SSE)
637     target_flags |= MASK_MMX;
638 }
639 \f
640 /* A C statement (sans semicolon) to choose the order in which to
641    allocate hard registers for pseudo-registers local to a basic
642    block.
643
644    Store the desired register order in the array `reg_alloc_order'.
645    Element 0 should be the register to allocate first; element 1, the
646    next register; and so on.
647
648    The macro body should not assume anything about the contents of
649    `reg_alloc_order' before execution of the macro.
650
651    On most machines, it is not necessary to define this macro.  */
652
653 void
654 order_regs_for_local_alloc ()
655 {
656   int i, ch, order;
657
658   /* User specified the register allocation order.  */
659
660   if (ix86_reg_alloc_order)
661     {
662       for (i = order = 0; (ch = ix86_reg_alloc_order[i]) != '\0'; i++)
663         {
664           int regno = 0;
665
666           switch (ch)
667             {
668             case 'a':   regno = 0;      break;
669             case 'd':   regno = 1;      break;
670             case 'c':   regno = 2;      break;
671             case 'b':   regno = 3;      break;
672             case 'S':   regno = 4;      break;
673             case 'D':   regno = 5;      break;
674             case 'B':   regno = 6;      break;
675             }
676
677           reg_alloc_order[order++] = regno;
678         }
679
680       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
681         {
682           if (! regs_allocated[i])
683             reg_alloc_order[order++] = i;
684         }
685     }
686
687   /* If user did not specify a register allocation order, use natural order. */
688   else
689     {
690       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
691         reg_alloc_order[i] = i;
692     }
693 }
694 \f
695 void
696 optimization_options (level, size)
697      int level;
698      int size ATTRIBUTE_UNUSED;
699 {
700   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
701      make the problem with not enough registers even worse.  */
702 #ifdef INSN_SCHEDULING
703   if (level > 1)
704     flag_schedule_insns = 0;
705 #endif
706 }
707 \f
708 /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific
709    attribute for DECL.  The attributes in ATTRIBUTES have previously been
710    assigned to DECL.  */
711
712 int
713 ix86_valid_decl_attribute_p (decl, attributes, identifier, args)
714      tree decl ATTRIBUTE_UNUSED;
715      tree attributes ATTRIBUTE_UNUSED;
716      tree identifier ATTRIBUTE_UNUSED;
717      tree args ATTRIBUTE_UNUSED;
718 {
719   return 0;
720 }
721
722 /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific
723    attribute for TYPE.  The attributes in ATTRIBUTES have previously been
724    assigned to TYPE.  */
725
726 int
727 ix86_valid_type_attribute_p (type, attributes, identifier, args)
728      tree type;
729      tree attributes ATTRIBUTE_UNUSED;
730      tree identifier;
731      tree args;
732 {
733   if (TREE_CODE (type) != FUNCTION_TYPE
734       && TREE_CODE (type) != METHOD_TYPE
735       && TREE_CODE (type) != FIELD_DECL
736       && TREE_CODE (type) != TYPE_DECL)
737     return 0;
738
739   /* Stdcall attribute says callee is responsible for popping arguments
740      if they are not variable.  */
741   if (is_attribute_p ("stdcall", identifier))
742     return (args == NULL_TREE);
743
744   /* Cdecl attribute says the callee is a normal C declaration. */
745   if (is_attribute_p ("cdecl", identifier))
746     return (args == NULL_TREE);
747
748   /* Regparm attribute specifies how many integer arguments are to be
749      passed in registers. */
750   if (is_attribute_p ("regparm", identifier))
751     {
752       tree cst;
753
754       if (! args || TREE_CODE (args) != TREE_LIST
755           || TREE_CHAIN (args) != NULL_TREE
756           || TREE_VALUE (args) == NULL_TREE)
757         return 0;
758
759       cst = TREE_VALUE (args);
760       if (TREE_CODE (cst) != INTEGER_CST)
761         return 0;
762
763       if (compare_tree_int (cst, REGPARM_MAX) > 0)
764         return 0;
765
766       return 1;
767     }
768
769   return 0;
770 }
771
772 /* Return 0 if the attributes for two types are incompatible, 1 if they
773    are compatible, and 2 if they are nearly compatible (which causes a
774    warning to be generated).  */
775
776 int
777 ix86_comp_type_attributes (type1, type2)
778      tree type1;
779      tree type2;
780 {
781   /* Check for mismatch of non-default calling convention. */
782   const char *rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
783
784   if (TREE_CODE (type1) != FUNCTION_TYPE)
785     return 1;
786
787   /* Check for mismatched return types (cdecl vs stdcall).  */
788   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
789       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
790     return 0;
791   return 1;
792 }
793 \f
794 /* Value is the number of bytes of arguments automatically
795    popped when returning from a subroutine call.
796    FUNDECL is the declaration node of the function (as a tree),
797    FUNTYPE is the data type of the function (as a tree),
798    or for a library call it is an identifier node for the subroutine name.
799    SIZE is the number of bytes of arguments passed on the stack.
800
801    On the 80386, the RTD insn may be used to pop them if the number
802      of args is fixed, but if the number is variable then the caller
803      must pop them all.  RTD can't be used for library calls now
804      because the library is compiled with the Unix compiler.
805    Use of RTD is a selectable option, since it is incompatible with
806    standard Unix calling sequences.  If the option is not selected,
807    the caller must always pop the args.
808
809    The attribute stdcall is equivalent to RTD on a per module basis.  */
810
811 int
812 ix86_return_pops_args (fundecl, funtype, size)
813      tree fundecl;
814      tree funtype;
815      int size;
816 {
817   int rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
818
819     /* Cdecl functions override -mrtd, and never pop the stack. */
820   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype))) {
821
822     /* Stdcall functions will pop the stack if not variable args. */
823     if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype)))
824       rtd = 1;
825
826     if (rtd
827         && (TYPE_ARG_TYPES (funtype) == NULL_TREE
828             || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype)))
829                 == void_type_node)))
830       return size;
831   }
832
833   /* Lose any fake structure return argument.  */
834   if (aggregate_value_p (TREE_TYPE (funtype)))
835     return GET_MODE_SIZE (Pmode);
836
837     return 0;
838 }
839 \f
840 /* Argument support functions.  */
841
842 /* Initialize a variable CUM of type CUMULATIVE_ARGS
843    for a call to a function whose data type is FNTYPE.
844    For a library call, FNTYPE is 0.  */
845
846 void
847 init_cumulative_args (cum, fntype, libname)
848      CUMULATIVE_ARGS *cum;      /* Argument info to initialize */
849      tree fntype;               /* tree ptr for function decl */
850      rtx libname;               /* SYMBOL_REF of library name or 0 */
851 {
852   static CUMULATIVE_ARGS zero_cum;
853   tree param, next_param;
854
855   if (TARGET_DEBUG_ARG)
856     {
857       fprintf (stderr, "\ninit_cumulative_args (");
858       if (fntype)
859         fprintf (stderr, "fntype code = %s, ret code = %s",
860                  tree_code_name[(int) TREE_CODE (fntype)],
861                  tree_code_name[(int) TREE_CODE (TREE_TYPE (fntype))]);
862       else
863         fprintf (stderr, "no fntype");
864
865       if (libname)
866         fprintf (stderr, ", libname = %s", XSTR (libname, 0));
867     }
868
869   *cum = zero_cum;
870
871   /* Set up the number of registers to use for passing arguments.  */
872   cum->nregs = ix86_regparm;
873   if (fntype)
874     {
875       tree attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (fntype));
876
877       if (attr)
878         cum->nregs = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
879     }
880
881   /* Determine if this function has variable arguments.  This is
882      indicated by the last argument being 'void_type_mode' if there
883      are no variable arguments.  If there are variable arguments, then
884      we won't pass anything in registers */
885
886   if (cum->nregs)
887     {
888       for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0;
889            param != 0; param = next_param)
890         {
891           next_param = TREE_CHAIN (param);
892           if (next_param == 0 && TREE_VALUE (param) != void_type_node)
893             cum->nregs = 0;
894         }
895     }
896
897   if (TARGET_DEBUG_ARG)
898     fprintf (stderr, ", nregs=%d )\n", cum->nregs);
899
900   return;
901 }
902
903 /* Update the data in CUM to advance over an argument
904    of mode MODE and data type TYPE.
905    (TYPE is null for libcalls where that information may not be available.)  */
906
907 void
908 function_arg_advance (cum, mode, type, named)
909      CUMULATIVE_ARGS *cum;      /* current arg information */
910      enum machine_mode mode;    /* current arg mode */
911      tree type;                 /* type of the argument or 0 if lib support */
912      int named;                 /* whether or not the argument was named */
913 {
914   int bytes =
915     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
916   int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
917
918   if (TARGET_DEBUG_ARG)
919     fprintf (stderr,
920              "function_adv (sz=%d, wds=%2d, nregs=%d, mode=%s, named=%d)\n\n",
921              words, cum->words, cum->nregs, GET_MODE_NAME (mode), named);
922
923   cum->words += words;
924   cum->nregs -= words;
925   cum->regno += words;
926
927   if (cum->nregs <= 0)
928     {
929       cum->nregs = 0;
930       cum->regno = 0;
931     }
932
933   return;
934 }
935
936 /* Define where to put the arguments to a function.
937    Value is zero to push the argument on the stack,
938    or a hard register in which to store the argument.
939
940    MODE is the argument's machine mode.
941    TYPE is the data type of the argument (as a tree).
942     This is null for libcalls where that information may
943     not be available.
944    CUM is a variable of type CUMULATIVE_ARGS which gives info about
945     the preceding args and about the function being called.
946    NAMED is nonzero if this argument is a named parameter
947     (otherwise it is an extra parameter matching an ellipsis).  */
948
949 struct rtx_def *
950 function_arg (cum, mode, type, named)
951      CUMULATIVE_ARGS *cum;      /* current arg information */
952      enum machine_mode mode;    /* current arg mode */
953      tree type;                 /* type of the argument or 0 if lib support */
954      int named;                 /* != 0 for normal args, == 0 for ... args */
955 {
956   rtx ret   = NULL_RTX;
957   int bytes =
958     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
959   int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
960
961   switch (mode)
962     {
963       /* For now, pass fp/complex values on the stack. */
964     default:
965       break;
966
967     case BLKmode:
968     case DImode:
969     case SImode:
970     case HImode:
971     case QImode:
972       if (words <= cum->nregs)
973         ret = gen_rtx_REG (mode, cum->regno);
974       break;
975     }
976
977   if (TARGET_DEBUG_ARG)
978     {
979       fprintf (stderr,
980                "function_arg (size=%d, wds=%2d, nregs=%d, mode=%4s, named=%d",
981                words, cum->words, cum->nregs, GET_MODE_NAME (mode), named);
982
983       if (ret)
984         fprintf (stderr, ", reg=%%e%s", reg_names[ REGNO(ret) ]);
985       else
986         fprintf (stderr, ", stack");
987
988       fprintf (stderr, " )\n");
989     }
990
991   return ret;
992 }
993 \f
994
995 /* Return nonzero if OP is (const_int 1), else return zero.  */
996
997 int
998 const_int_1_operand (op, mode)
999      rtx op;
1000      enum machine_mode mode ATTRIBUTE_UNUSED;
1001 {
1002   return (GET_CODE (op) == CONST_INT && INTVAL (op) == 1);
1003 }
1004
1005 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
1006    reference and a constant.  */
1007
1008 int
1009 symbolic_operand (op, mode)
1010      register rtx op;
1011      enum machine_mode mode ATTRIBUTE_UNUSED;
1012 {
1013   switch (GET_CODE (op))
1014     {
1015     case SYMBOL_REF:
1016     case LABEL_REF:
1017       return 1;
1018
1019     case CONST:
1020       op = XEXP (op, 0);
1021       if (GET_CODE (op) == SYMBOL_REF
1022           || GET_CODE (op) == LABEL_REF
1023           || (GET_CODE (op) == UNSPEC
1024               && XINT (op, 1) >= 6
1025               && XINT (op, 1) <= 7))
1026         return 1;
1027       if (GET_CODE (op) != PLUS
1028           || GET_CODE (XEXP (op, 1)) != CONST_INT)
1029         return 0;
1030
1031       op = XEXP (op, 0);
1032       if (GET_CODE (op) == SYMBOL_REF
1033           || GET_CODE (op) == LABEL_REF)
1034         return 1;
1035       /* Only @GOTOFF gets offsets.  */
1036       if (GET_CODE (op) != UNSPEC
1037           || XINT (op, 1) != 7)
1038         return 0;
1039
1040       op = XVECEXP (op, 0, 0);
1041       if (GET_CODE (op) == SYMBOL_REF
1042           || GET_CODE (op) == LABEL_REF)
1043         return 1;
1044       return 0;
1045
1046     default:
1047       return 0;
1048     }
1049 }
1050
1051 /* Return true if the operand contains a @GOT or @GOTOFF reference.  */
1052
1053 int
1054 pic_symbolic_operand (op, mode)
1055      register rtx op;
1056      enum machine_mode mode ATTRIBUTE_UNUSED;
1057 {
1058   if (GET_CODE (op) == CONST)
1059     {
1060       op = XEXP (op, 0);
1061       if (GET_CODE (op) == UNSPEC)
1062         return 1;
1063       if (GET_CODE (op) != PLUS
1064           || GET_CODE (XEXP (op, 1)) != CONST_INT)
1065         return 0;
1066       op = XEXP (op, 0);
1067       if (GET_CODE (op) == UNSPEC)
1068         return 1;
1069     }
1070   return 0;
1071 }
1072
1073 /* Test for a valid operand for a call instruction.  Don't allow the
1074    arg pointer register or virtual regs since they may decay into
1075    reg + const, which the patterns can't handle.  */
1076
1077 int
1078 call_insn_operand (op, mode)
1079      rtx op;
1080      enum machine_mode mode ATTRIBUTE_UNUSED;
1081 {
1082   if (GET_CODE (op) != MEM)
1083     return 0;
1084   op = XEXP (op, 0);
1085
1086   /* Disallow indirect through a virtual register.  This leads to
1087      compiler aborts when trying to eliminate them.  */
1088   if (GET_CODE (op) == REG
1089       && (op == arg_pointer_rtx
1090           || op == frame_pointer_rtx
1091           || (REGNO (op) >= FIRST_PSEUDO_REGISTER
1092               && REGNO (op) <= LAST_VIRTUAL_REGISTER)))
1093     return 0;
1094
1095   /* Disallow `call 1234'.  Due to varying assembler lameness this
1096      gets either rejected or translated to `call .+1234'.  */
1097   if (GET_CODE (op) == CONST_INT)
1098     return 0;
1099
1100   /* Explicitly allow SYMBOL_REF even if pic.  */
1101   if (GET_CODE (op) == SYMBOL_REF)
1102     return 1;
1103
1104   /* Half-pic doesn't allow anything but registers and constants.
1105      We've just taken care of the later.  */
1106   if (HALF_PIC_P ())
1107     return register_operand (op, Pmode);
1108
1109   /* Otherwise we can allow any general_operand in the address.  */
1110   return general_operand (op, Pmode);
1111 }
1112
1113 int
1114 constant_call_address_operand (op, mode)
1115      rtx op;
1116      enum machine_mode mode ATTRIBUTE_UNUSED;
1117 {
1118   return (GET_CODE (op) == MEM
1119           && CONSTANT_ADDRESS_P (XEXP (op, 0))
1120           && GET_CODE (XEXP (op, 0)) !=  CONST_INT);
1121 }
1122
1123 /* Match exactly zero and one.  */
1124
1125 int 
1126 const0_operand (op, mode)
1127      register rtx op;
1128      enum machine_mode mode;
1129 {
1130   return op == CONST0_RTX (mode);
1131 }
1132
1133 int 
1134 const1_operand (op, mode)
1135      register rtx op;
1136      enum machine_mode mode ATTRIBUTE_UNUSED;
1137 {
1138   return op == const1_rtx;
1139 }
1140
1141 /* Match 2, 4, or 8.  Used for leal multiplicands.  */
1142
1143 int
1144 const248_operand (op, mode)
1145      register rtx op;
1146      enum machine_mode mode ATTRIBUTE_UNUSED;
1147 {
1148   return (GET_CODE (op) == CONST_INT
1149           && (INTVAL (op) == 2 || INTVAL (op) == 4 || INTVAL (op) == 8));
1150 }
1151
1152 /* True if this is a constant appropriate for an increment or decremenmt.  */
1153
1154 int
1155 incdec_operand (op, mode)
1156      register rtx op;
1157      enum machine_mode mode;
1158 {
1159   if (op == const1_rtx || op == constm1_rtx)
1160     return 1;
1161   if (GET_CODE (op) != CONST_INT)
1162     return 0;
1163   if (mode == SImode && INTVAL (op) == (HOST_WIDE_INT) 0xffffffff)
1164     return 1;
1165   if (mode == HImode && INTVAL (op) == (HOST_WIDE_INT) 0xffff)
1166     return 1;
1167   if (mode == QImode && INTVAL (op) == (HOST_WIDE_INT) 0xff)
1168     return 1;
1169   return 0;
1170 }
1171
1172 /* Return false if this is the stack pointer, or any other fake 
1173    register eliminable to the stack pointer.  Otherwise, this is
1174    a register operand.
1175
1176    This is used to prevent esp from being used as an index reg.
1177    Which would only happen in pathological cases.  */
1178
1179 int
1180 reg_no_sp_operand (op, mode)
1181      register rtx op;
1182      enum machine_mode mode;
1183 {
1184   rtx t = op;
1185   if (GET_CODE (t) == SUBREG)
1186     t = SUBREG_REG (t);
1187   if (t == stack_pointer_rtx || t == arg_pointer_rtx || t == frame_pointer_rtx)
1188     return 0;
1189
1190   return register_operand (op, mode);
1191 }
1192
1193 /* Return false if this is any eliminable register.  Otherwise
1194    general_operand.  */
1195
1196 int
1197 general_no_elim_operand (op, mode)
1198      register rtx op;
1199      enum machine_mode mode;
1200 {
1201   rtx t = op;
1202   if (GET_CODE (t) == SUBREG)
1203     t = SUBREG_REG (t);
1204   if (t == arg_pointer_rtx || t == frame_pointer_rtx
1205       || t == virtual_incoming_args_rtx || t == virtual_stack_vars_rtx
1206       || t == virtual_stack_dynamic_rtx)
1207     return 0;
1208
1209   return general_operand (op, mode);
1210 }
1211
1212 /* Return false if this is any eliminable register.  Otherwise
1213    register_operand or const_int.  */
1214
1215 int
1216 nonmemory_no_elim_operand (op, mode)
1217      register rtx op;
1218      enum machine_mode mode;
1219 {
1220   rtx t = op;
1221   if (GET_CODE (t) == SUBREG)
1222     t = SUBREG_REG (t);
1223   if (t == arg_pointer_rtx || t == frame_pointer_rtx
1224       || t == virtual_incoming_args_rtx || t == virtual_stack_vars_rtx
1225       || t == virtual_stack_dynamic_rtx)
1226     return 0;
1227
1228   return GET_CODE (op) == CONST_INT || register_operand (op, mode);
1229 }
1230
1231 /* Return true if op is a Q_REGS class register.  */
1232
1233 int
1234 q_regs_operand (op, mode)
1235      register rtx op;
1236      enum machine_mode mode;
1237 {
1238   if (mode != VOIDmode && GET_MODE (op) != mode)
1239     return 0;
1240   if (GET_CODE (op) == SUBREG)
1241     op = SUBREG_REG (op);
1242   return QI_REG_P (op);
1243 }     
1244
1245 /* Return true if op is a NON_Q_REGS class register.  */
1246
1247 int
1248 non_q_regs_operand (op, mode)
1249      register rtx op;
1250      enum machine_mode mode;
1251 {
1252   if (mode != VOIDmode && GET_MODE (op) != mode)
1253     return 0;
1254   if (GET_CODE (op) == SUBREG)
1255     op = SUBREG_REG (op);
1256   return NON_QI_REG_P (op);
1257 }     
1258
1259 /* Return 1 if OP is a comparison operator that can use the condition code
1260    generated by a logical operation, which characteristicly does not set
1261    overflow or carry.  To be used with CCNOmode.  */
1262
1263 int
1264 no_comparison_operator (op, mode)
1265     register rtx op;
1266     enum machine_mode mode;
1267 {
1268   if (mode != VOIDmode && GET_MODE (op) != mode)
1269     return 0;
1270
1271   switch (GET_CODE (op))
1272     {
1273     case EQ: case NE:
1274     case LT: case GE:
1275     case LEU: case LTU: case GEU: case GTU:
1276       return 1;
1277
1278     default:
1279       return 0;
1280     }
1281 }
1282
1283 /* Return 1 if OP is a comparison operator that can be issued by fcmov.  */
1284
1285 int
1286 fcmov_comparison_operator (op, mode)
1287     register rtx op;
1288     enum machine_mode mode;
1289 {
1290   if (mode != VOIDmode && GET_MODE (op) != mode)
1291     return 0;
1292
1293   switch (GET_CODE (op))
1294     {
1295     case EQ: case NE:
1296     case LEU: case LTU: case GEU: case GTU:
1297     case UNORDERED: case ORDERED:
1298       return 1;
1299
1300     default:
1301       return 0;
1302     }
1303 }
1304
1305 /* Return 1 if OP is any normal comparison operator plus {UN}ORDERED.  */
1306
1307 int 
1308 uno_comparison_operator (op, mode)
1309     register rtx op;
1310     enum machine_mode mode;
1311 {
1312   if (mode != VOIDmode && GET_MODE (op) != mode)
1313     return 0;
1314
1315   switch (GET_CODE (op))
1316     {
1317     case EQ: case NE:
1318     case LE: case LT: case GE: case GT:
1319     case LEU: case LTU: case GEU: case GTU:
1320     case UNORDERED: case ORDERED:
1321       return 1;
1322
1323     default:
1324       return 0;
1325     }
1326 }
1327
1328 /* Return 1 if OP is a binary operator that can be promoted to wider mode.  */
1329
1330 int
1331 promotable_binary_operator (op, mode)
1332      register rtx op;
1333      enum machine_mode mode ATTRIBUTE_UNUSED;
1334 {
1335   switch (GET_CODE (op))
1336     {
1337     case MULT:
1338       /* Modern CPUs have same latency for HImode and SImode multiply,
1339          but 386 and 486 do HImode multiply faster.  */
1340       return ix86_cpu > PROCESSOR_I486;
1341     case PLUS:
1342     case AND:
1343     case IOR:
1344     case XOR:
1345     case ASHIFT:
1346       return 1;
1347     default:
1348       return 0;
1349     }
1350 }
1351
1352 /* Nearly general operand, but accept any const_double, since we wish
1353    to be able to drop them into memory rather than have them get pulled
1354    into registers.  */
1355
1356 int
1357 cmp_fp_expander_operand (op, mode)
1358      register rtx op;
1359      enum machine_mode mode;
1360 {
1361   if (mode != VOIDmode && mode != GET_MODE (op))
1362     return 0;
1363   if (GET_CODE (op) == CONST_DOUBLE)
1364     return 1;
1365   return general_operand (op, mode);
1366 }
1367
1368 /* Match an SI or HImode register for a zero_extract.  */
1369
1370 int
1371 ext_register_operand (op, mode)
1372      register rtx op;
1373      enum machine_mode mode ATTRIBUTE_UNUSED;
1374 {
1375   if (GET_MODE (op) != SImode && GET_MODE (op) != HImode)
1376     return 0;
1377   return register_operand (op, VOIDmode);
1378 }
1379
1380 /* Return 1 if this is a valid binary floating-point operation.
1381    OP is the expression matched, and MODE is its mode. */
1382
1383 int
1384 binary_fp_operator (op, mode)
1385     register rtx op;
1386     enum machine_mode mode;
1387 {
1388   if (mode != VOIDmode && mode != GET_MODE (op))
1389     return 0;
1390
1391   switch (GET_CODE (op))
1392     {
1393     case PLUS:
1394     case MINUS:
1395     case MULT:
1396     case DIV:
1397       return GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT;
1398
1399     default:
1400       return 0;
1401     }
1402 }
1403
1404 int
1405 mult_operator(op, mode)
1406     register rtx op;
1407     enum machine_mode mode ATTRIBUTE_UNUSED;
1408 {
1409   return GET_CODE (op) == MULT;
1410 }
1411
1412 int
1413 div_operator(op, mode)
1414     register rtx op;
1415     enum machine_mode mode ATTRIBUTE_UNUSED;
1416 {
1417   return GET_CODE (op) == DIV;
1418 }
1419
1420 int
1421 arith_or_logical_operator (op, mode)
1422       rtx op;
1423       enum machine_mode mode;
1424 {
1425   return ((mode == VOIDmode || GET_MODE (op) == mode)
1426           && (GET_RTX_CLASS (GET_CODE (op)) == 'c'
1427               || GET_RTX_CLASS (GET_CODE (op)) == '2'));
1428 }
1429
1430 /* Returns 1 if OP is memory operand with a displacement.  */
1431
1432 int
1433 memory_displacement_operand (op, mode)
1434      register rtx op;
1435      enum machine_mode mode;
1436 {
1437   struct ix86_address parts;
1438
1439   if (! memory_operand (op, mode))
1440     return 0;
1441
1442   if (! ix86_decompose_address (XEXP (op, 0), &parts))
1443     abort ();
1444
1445   return parts.disp != NULL_RTX;
1446 }
1447
1448 /* To avoid problems when jump re-emits comparisons like testqi_ext_ccno_0,
1449    re-recognize the operand to avoid a copy_to_mode_reg that will fail.
1450
1451    ??? It seems likely that this will only work because cmpsi is an
1452    expander, and no actual insns use this.  */
1453
1454 int
1455 cmpsi_operand (op, mode)
1456       rtx op;
1457       enum machine_mode mode;
1458 {
1459   if (general_operand (op, mode))
1460     return 1;
1461
1462   if (GET_CODE (op) == AND
1463       && GET_MODE (op) == SImode
1464       && GET_CODE (XEXP (op, 0)) == ZERO_EXTRACT
1465       && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
1466       && GET_CODE (XEXP (XEXP (op, 0), 2)) == CONST_INT
1467       && INTVAL (XEXP (XEXP (op, 0), 1)) == 8
1468       && INTVAL (XEXP (XEXP (op, 0), 2)) == 8
1469       && GET_CODE (XEXP (op, 1)) == CONST_INT)
1470     return 1;
1471
1472   return 0;
1473 }
1474
1475 /* Returns 1 if OP is memory operand that can not be represented by the
1476    modRM array.  */
1477
1478 int
1479 long_memory_operand (op, mode)
1480      register rtx op;
1481      enum machine_mode mode;
1482 {
1483   if (! memory_operand (op, mode))
1484     return 0;
1485
1486   return memory_address_length (op) != 0;
1487 }
1488
1489 /* Return nonzero if the rtx is known aligned.  */
1490
1491 int
1492 aligned_operand (op, mode)
1493      rtx op;
1494      enum machine_mode mode;
1495 {
1496   struct ix86_address parts;
1497
1498   if (!general_operand (op, mode))
1499     return 0;
1500
1501   /* Registers and immediate operands are always "aligned". */
1502   if (GET_CODE (op) != MEM)
1503     return 1;
1504
1505   /* Don't even try to do any aligned optimizations with volatiles. */
1506   if (MEM_VOLATILE_P (op))
1507     return 0;
1508
1509   op = XEXP (op, 0);
1510
1511   /* Pushes and pops are only valid on the stack pointer.  */
1512   if (GET_CODE (op) == PRE_DEC
1513       || GET_CODE (op) == POST_INC)
1514     return 1;
1515
1516   /* Decode the address.  */
1517   if (! ix86_decompose_address (op, &parts))
1518     abort ();
1519
1520   /* Look for some component that isn't known to be aligned.  */
1521   if (parts.index)
1522     {
1523       if (parts.scale < 4
1524           && REGNO_POINTER_ALIGN (REGNO (parts.index)) < 32)
1525         return 0;
1526     }
1527   if (parts.base)
1528     {
1529       if (REGNO_POINTER_ALIGN (REGNO (parts.base)) < 32)
1530         return 0;
1531     }
1532   if (parts.disp)
1533     {
1534       if (GET_CODE (parts.disp) != CONST_INT
1535           || (INTVAL (parts.disp) & 3) != 0)
1536         return 0;
1537     }
1538
1539   /* Didn't find one -- this must be an aligned address.  */
1540   return 1;
1541 }
1542 \f
1543 /* Return true if the constant is something that can be loaded with
1544    a special instruction.  Only handle 0.0 and 1.0; others are less
1545    worthwhile.  */
1546
1547 int
1548 standard_80387_constant_p (x)
1549      rtx x;
1550 {
1551   if (GET_CODE (x) != CONST_DOUBLE)
1552     return -1;
1553
1554 #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1555   {
1556     REAL_VALUE_TYPE d;
1557     jmp_buf handler;
1558     int is0, is1;
1559
1560     if (setjmp (handler))
1561       return 0;
1562
1563     set_float_handler (handler);
1564     REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1565     is0 = REAL_VALUES_EQUAL (d, dconst0) && !REAL_VALUE_MINUS_ZERO (d);
1566     is1 = REAL_VALUES_EQUAL (d, dconst1);
1567     set_float_handler (NULL_PTR);
1568
1569     if (is0)
1570       return 1;
1571
1572     if (is1)
1573       return 2;
1574
1575     /* Note that on the 80387, other constants, such as pi,
1576        are much slower to load as standard constants
1577        than to load from doubles in memory!  */
1578     /* ??? Not true on K6: all constants are equal cost.  */
1579   }
1580 #endif
1581
1582   return 0;
1583 }
1584
1585 /* Returns 1 if OP contains a symbol reference */
1586
1587 int
1588 symbolic_reference_mentioned_p (op)
1589      rtx op;
1590 {
1591   register const char *fmt;
1592   register int i;
1593
1594   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
1595     return 1;
1596
1597   fmt = GET_RTX_FORMAT (GET_CODE (op));
1598   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
1599     {
1600       if (fmt[i] == 'E')
1601         {
1602           register int j;
1603
1604           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
1605             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
1606               return 1;
1607         }
1608
1609       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
1610         return 1;
1611     }
1612
1613   return 0;
1614 }
1615
1616 /* Return 1 if it is appropriate to emit `ret' instructions in the
1617    body of a function.  Do this only if the epilogue is simple, needing a
1618    couple of insns.  Prior to reloading, we can't tell how many registers
1619    must be saved, so return 0 then.  Return 0 if there is no frame
1620    marker to de-allocate.
1621
1622    If NON_SAVING_SETJMP is defined and true, then it is not possible
1623    for the epilogue to be simple, so return 0.  This is a special case
1624    since NON_SAVING_SETJMP will not cause regs_ever_live to change
1625    until final, but jump_optimize may need to know sooner if a
1626    `return' is OK.  */
1627
1628 int
1629 ix86_can_use_return_insn_p ()
1630 {
1631   HOST_WIDE_INT tsize;
1632   int nregs;
1633
1634 #ifdef NON_SAVING_SETJMP
1635   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
1636     return 0;
1637 #endif
1638 #ifdef FUNCTION_BLOCK_PROFILER_EXIT
1639   if (profile_block_flag == 2)
1640     return 0;
1641 #endif
1642
1643   if (! reload_completed || frame_pointer_needed)
1644     return 0;
1645
1646   /* Don't allow more than 32 pop, since that's all we can do
1647      with one instruction.  */
1648   if (current_function_pops_args
1649       && current_function_args_size >= 32768)
1650     return 0;
1651
1652   tsize = ix86_compute_frame_size (get_frame_size (), &nregs, NULL, NULL);
1653   return tsize == 0 && nregs == 0;
1654 }
1655 \f
1656 static char *pic_label_name;
1657 static int pic_label_output;
1658 static char *global_offset_table_name;
1659
1660 /* This function generates code for -fpic that loads %ebx with
1661    the return address of the caller and then returns.  */
1662
1663 void
1664 asm_output_function_prefix (file, name)
1665      FILE *file;
1666      const char *name ATTRIBUTE_UNUSED;
1667 {
1668   rtx xops[2];
1669   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
1670                                   || current_function_uses_const_pool);
1671   xops[0] = pic_offset_table_rtx;
1672   xops[1] = stack_pointer_rtx;
1673
1674   /* Deep branch prediction favors having a return for every call. */
1675   if (pic_reg_used && TARGET_DEEP_BRANCH_PREDICTION)
1676     {
1677       if (!pic_label_output)
1678         {
1679           /* This used to call ASM_DECLARE_FUNCTION_NAME() but since it's an
1680              internal (non-global) label that's being emitted, it didn't make
1681              sense to have .type information for local labels.   This caused
1682              the SCO OpenServer 5.0.4 ELF assembler grief (why are you giving
1683              me debug info for a label that you're declaring non-global?) this
1684              was changed to call ASM_OUTPUT_LABEL() instead. */
1685
1686           ASM_OUTPUT_LABEL (file, pic_label_name); 
1687
1688           xops[1] = gen_rtx_MEM (SImode, xops[1]);
1689           output_asm_insn ("mov{l}\t{%1, %0|%0, %1}", xops);
1690           output_asm_insn ("ret", xops);
1691
1692           pic_label_output = 1;
1693         }
1694     }
1695 }
1696
1697 void
1698 load_pic_register ()
1699 {
1700   rtx gotsym, pclab;
1701
1702   if (global_offset_table_name == NULL)
1703     {
1704       global_offset_table_name = 
1705         ggc_alloc_string ("_GLOBAL_OFFSET_TABLE_", 21);
1706       ggc_add_string_root (&global_offset_table_name, 1);
1707     }
1708   gotsym = gen_rtx_SYMBOL_REF (Pmode, global_offset_table_name);
1709
1710   if (TARGET_DEEP_BRANCH_PREDICTION)
1711     {
1712       if (pic_label_name == NULL) 
1713         {
1714           pic_label_name = ggc_alloc_string (NULL, 32);
1715           ggc_add_string_root (&pic_label_name, 1);
1716           ASM_GENERATE_INTERNAL_LABEL (pic_label_name, "LPR", 0);
1717         }
1718       pclab = gen_rtx_MEM (QImode, gen_rtx_SYMBOL_REF (Pmode, pic_label_name));
1719     }
1720   else
1721     {
1722       pclab = gen_rtx_LABEL_REF (VOIDmode, gen_label_rtx ());
1723     }
1724
1725   emit_insn (gen_prologue_get_pc (pic_offset_table_rtx, pclab));
1726
1727   if (! TARGET_DEEP_BRANCH_PREDICTION)
1728     emit_insn (gen_popsi1 (pic_offset_table_rtx));
1729
1730   emit_insn (gen_prologue_set_got (pic_offset_table_rtx, gotsym, pclab));
1731 }
1732
1733 /* Generate an SImode "push" pattern for input ARG.  */
1734
1735 static rtx
1736 gen_push (arg)
1737      rtx arg;
1738 {
1739   return gen_rtx_SET (VOIDmode,
1740                       gen_rtx_MEM (SImode,
1741                                    gen_rtx_PRE_DEC (SImode,
1742                                                     stack_pointer_rtx)),
1743                       arg);
1744 }
1745
1746 /* Return number of registers to be saved on the stack.  */
1747
1748 static int
1749 ix86_nsaved_regs ()
1750 {
1751   int nregs = 0;
1752   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
1753                                   || current_function_uses_const_pool);
1754   int limit = (frame_pointer_needed
1755                ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
1756   int regno;
1757
1758   for (regno = limit - 1; regno >= 0; regno--)
1759     if ((regs_ever_live[regno] && ! call_used_regs[regno])
1760         || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
1761       {
1762         nregs ++;
1763       }
1764   return nregs;
1765 }
1766
1767 /* Return the offset between two registers, one to be eliminated, and the other
1768    its replacement, at the start of a routine.  */
1769
1770 HOST_WIDE_INT
1771 ix86_initial_elimination_offset (from, to)
1772      int from;
1773      int to;
1774 {
1775   int padding1;
1776   int nregs;
1777
1778   /* Stack grows downward:
1779     
1780      [arguments]
1781                                                 <- ARG_POINTER
1782      saved pc
1783
1784      saved frame pointer if frame_pointer_needed
1785                                                 <- HARD_FRAME_POINTER
1786      [saved regs]
1787
1788      [padding1]   \
1789                    |                            <- FRAME_POINTER
1790      [frame]       > tsize
1791                    |
1792      [padding2]   /
1793     */
1794
1795   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
1796     /* Skip saved PC and previous frame pointer.
1797        Executed only when frame_pointer_needed.  */
1798     return 8;
1799   else if (from == FRAME_POINTER_REGNUM
1800            && to == HARD_FRAME_POINTER_REGNUM)
1801     {
1802       ix86_compute_frame_size (get_frame_size (), &nregs, &padding1, (int *)0);
1803       padding1 += nregs * UNITS_PER_WORD;
1804       return -padding1;
1805     }
1806   else
1807     {
1808       /* ARG_POINTER or FRAME_POINTER to STACK_POINTER elimination.  */
1809       int frame_size = frame_pointer_needed ? 8 : 4;
1810       HOST_WIDE_INT tsize = ix86_compute_frame_size (get_frame_size (),
1811                                                      &nregs, &padding1, (int *)0);
1812
1813
1814       if (to != STACK_POINTER_REGNUM)
1815         abort ();
1816       else if (from == ARG_POINTER_REGNUM)
1817         return tsize + nregs * UNITS_PER_WORD + frame_size;
1818       else if (from != FRAME_POINTER_REGNUM)
1819         abort ();
1820       else
1821         return tsize - padding1;
1822     }
1823 }
1824
1825 /* Compute the size of local storage taking into consideration the
1826    desired stack alignment which is to be maintained.  Also determine
1827    the number of registers saved below the local storage.  
1828  
1829    PADDING1 returns padding before stack frame and PADDING2 returns
1830    padding after stack frame;
1831  */
1832
1833 static HOST_WIDE_INT
1834 ix86_compute_frame_size (size, nregs_on_stack, rpadding1, rpadding2)
1835      HOST_WIDE_INT size;
1836      int *nregs_on_stack;
1837      int *rpadding1;
1838      int *rpadding2;
1839 {
1840   int nregs;
1841   int padding1 = 0;
1842   int padding2 = 0;
1843   HOST_WIDE_INT total_size;
1844   int stack_alignment_needed = cfun->stack_alignment_needed / BITS_PER_UNIT;
1845   int offset;
1846   int preferred_alignment = cfun->preferred_stack_boundary / BITS_PER_UNIT;
1847
1848   nregs = ix86_nsaved_regs ();
1849   total_size = size;
1850
1851   offset = frame_pointer_needed ? 8 : 4;
1852
1853   /* Do some sanity checking of stack_alignment_needed and preferred_alignment,
1854      since i386 port is the only using those features that may break easilly.  */
1855
1856   if (size && !stack_alignment_needed)
1857     abort ();
1858   if (!size && stack_alignment_needed != STACK_BOUNDARY / BITS_PER_UNIT)
1859     abort ();
1860   if (preferred_alignment < STACK_BOUNDARY / BITS_PER_UNIT)
1861     abort ();
1862   if (preferred_alignment > PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
1863     abort ();
1864   if (stack_alignment_needed > PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
1865     abort ();
1866
1867   if (stack_alignment_needed < 4)
1868     stack_alignment_needed = 4;
1869
1870   offset += nregs * UNITS_PER_WORD;
1871
1872   if (ACCUMULATE_OUTGOING_ARGS)
1873     total_size += current_function_outgoing_args_size;
1874
1875   total_size += offset;
1876
1877   /* Align start of frame for local function.  */
1878   padding1 = ((offset + stack_alignment_needed - 1)
1879               & -stack_alignment_needed) - offset;
1880   total_size += padding1;
1881
1882   /* Align stack boundary. */
1883   padding2 = ((total_size + preferred_alignment - 1)
1884               & -preferred_alignment) - total_size;
1885
1886   if (ACCUMULATE_OUTGOING_ARGS)
1887     padding2 += current_function_outgoing_args_size;
1888
1889   if (nregs_on_stack)
1890     *nregs_on_stack = nregs;
1891   if (rpadding1)
1892     *rpadding1 = padding1;
1893   if (rpadding2)
1894     *rpadding2 = padding2;
1895
1896   return size + padding1 + padding2;
1897 }
1898
1899 /* Emit code to save registers in the prologue.  */
1900
1901 static void
1902 ix86_emit_save_regs ()
1903 {
1904   register int regno;
1905   int limit;
1906   rtx insn;
1907   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
1908                                   || current_function_uses_const_pool);
1909   limit = (frame_pointer_needed
1910            ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
1911
1912   for (regno = limit - 1; regno >= 0; regno--)
1913     if ((regs_ever_live[regno] && !call_used_regs[regno])
1914         || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
1915       {
1916         insn = emit_insn (gen_push (gen_rtx_REG (SImode, regno)));
1917         RTX_FRAME_RELATED_P (insn) = 1;
1918       }
1919 }
1920
1921 /* Expand the prologue into a bunch of separate insns. */
1922
1923 void
1924 ix86_expand_prologue ()
1925 {
1926   HOST_WIDE_INT tsize = ix86_compute_frame_size (get_frame_size (), (int *)0, (int *)0,
1927                                                  (int *)0);
1928   rtx insn;
1929   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
1930                                   || current_function_uses_const_pool);
1931
1932   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
1933      slower on all targets.  Also sdb doesn't like it.  */
1934
1935   if (frame_pointer_needed)
1936     {
1937       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
1938       RTX_FRAME_RELATED_P (insn) = 1;
1939
1940       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1941       RTX_FRAME_RELATED_P (insn) = 1;
1942     }
1943
1944   ix86_emit_save_regs ();
1945
1946   if (tsize == 0)
1947     ;
1948   else if (! TARGET_STACK_PROBE || tsize < CHECK_STACK_LIMIT)
1949     {
1950       if (frame_pointer_needed)
1951         insn = emit_insn (gen_pro_epilogue_adjust_stack
1952                           (stack_pointer_rtx, stack_pointer_rtx,
1953                            GEN_INT (-tsize), hard_frame_pointer_rtx));
1954       else
1955         insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1956                                       GEN_INT (-tsize)));
1957       RTX_FRAME_RELATED_P (insn) = 1;
1958     }
1959   else
1960     {
1961       /* ??? Is this only valid for Win32?  */
1962
1963       rtx arg0, sym;
1964
1965       arg0 = gen_rtx_REG (SImode, 0);
1966       emit_move_insn (arg0, GEN_INT (tsize));
1967
1968       sym = gen_rtx_MEM (FUNCTION_MODE,
1969                          gen_rtx_SYMBOL_REF (Pmode, "_alloca"));
1970       insn = emit_call_insn (gen_call (sym, const0_rtx));
1971
1972       CALL_INSN_FUNCTION_USAGE (insn)
1973         = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, arg0),
1974                              CALL_INSN_FUNCTION_USAGE (insn));
1975     }
1976
1977 #ifdef SUBTARGET_PROLOGUE
1978   SUBTARGET_PROLOGUE;
1979 #endif  
1980
1981   if (pic_reg_used)
1982     load_pic_register ();
1983
1984   /* If we are profiling, make sure no instructions are scheduled before
1985      the call to mcount.  However, if -fpic, the above call will have
1986      done that.  */
1987   if ((profile_flag || profile_block_flag) && ! pic_reg_used)
1988     emit_insn (gen_blockage ());
1989 }
1990
1991 /* Emit code to add TSIZE to esp value.  Use POP instruction when
1992    profitable.  */
1993
1994 static void
1995 ix86_emit_epilogue_esp_adjustment (tsize)
1996      int tsize;
1997 {
1998   /* If a frame pointer is present, we must be sure to tie the sp
1999      to the fp so that we don't mis-schedule.  */
2000   if (frame_pointer_needed)
2001     emit_insn (gen_pro_epilogue_adjust_stack (stack_pointer_rtx,
2002                                               stack_pointer_rtx,
2003                                               GEN_INT (tsize),
2004                                               hard_frame_pointer_rtx));
2005   else
2006     emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
2007                            GEN_INT (tsize)));
2008 }
2009
2010 /* Emit code to restore saved registers using MOV insns.  First register
2011    is restored from POINTER + OFFSET.  */
2012 static void
2013 ix86_emit_restore_regs_using_mov (pointer, offset)
2014         rtx pointer;
2015         int offset;
2016 {
2017   int regno;
2018   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
2019                                   || current_function_uses_const_pool);
2020   int limit = (frame_pointer_needed
2021                ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
2022
2023   for (regno = 0; regno < limit; regno++)
2024     if ((regs_ever_live[regno] && !call_used_regs[regno])
2025         || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
2026       {
2027         emit_move_insn (gen_rtx_REG (SImode, regno),
2028                         adj_offsettable_operand (gen_rtx_MEM (SImode,
2029                                                               pointer),
2030                                                  offset));
2031         offset += 4;
2032       }
2033 }
2034
2035 /* Restore function stack, frame, and registers. */
2036
2037 void
2038 ix86_expand_epilogue (emit_return)
2039      int emit_return;
2040 {
2041   int nregs;
2042   int regno;
2043
2044   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
2045                                   || current_function_uses_const_pool);
2046   int sp_valid = !frame_pointer_needed || current_function_sp_is_unchanging;
2047   HOST_WIDE_INT offset;
2048   HOST_WIDE_INT tsize = ix86_compute_frame_size (get_frame_size (), &nregs,
2049                                                  (int *)0, (int *)0);
2050
2051
2052   /* Calculate start of saved registers relative to ebp.  */
2053   offset = -nregs * UNITS_PER_WORD;
2054
2055 #ifdef FUNCTION_BLOCK_PROFILER_EXIT
2056   if (profile_block_flag == 2)
2057     {
2058       FUNCTION_BLOCK_PROFILER_EXIT;
2059     }
2060 #endif
2061
2062   /* If we're only restoring one register and sp is not valid then
2063      using a move instruction to restore the register since it's
2064      less work than reloading sp and popping the register.  
2065
2066      The default code result in stack adjustment using add/lea instruction,
2067      while this code results in LEAVE instruction (or discrete equivalent),
2068      so it is profitable in some other cases as well.  Especially when there
2069      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
2070      and there is exactly one register to pop. This heruistic may need some
2071      tuning in future.  */
2072   if ((!sp_valid && nregs <= 1)
2073       || (frame_pointer_needed && !nregs && tsize)
2074       || (frame_pointer_needed && TARGET_USE_LEAVE && !optimize_size
2075           && nregs == 1))
2076     {
2077       /* Restore registers.  We can use ebp or esp to address the memory
2078          locations.  If both are available, default to ebp, since offsets
2079          are known to be small.  Only exception is esp pointing directly to the
2080          end of block of saved registers, where we may simplify addressing
2081          mode.  */
2082
2083       if (!frame_pointer_needed || (sp_valid && !tsize))
2084         ix86_emit_restore_regs_using_mov (stack_pointer_rtx, tsize);
2085       else
2086         ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx, offset);
2087
2088       if (!frame_pointer_needed)
2089         ix86_emit_epilogue_esp_adjustment (tsize + nregs * UNITS_PER_WORD);
2090       /* If not an i386, mov & pop is faster than "leave". */
2091       else if (TARGET_USE_LEAVE || optimize_size)
2092         emit_insn (gen_leave ());
2093       else
2094         {
2095           emit_insn (gen_pro_epilogue_adjust_stack (stack_pointer_rtx,
2096                                                     hard_frame_pointer_rtx,
2097                                                     const0_rtx,
2098                                                     hard_frame_pointer_rtx));
2099           emit_insn (gen_popsi1 (hard_frame_pointer_rtx));
2100         }
2101     }
2102   else
2103     {
2104       /* First step is to deallocate the stack frame so that we can
2105          pop the registers.  */
2106       if (!sp_valid)
2107         {
2108           if (!frame_pointer_needed)
2109             abort ();
2110           emit_insn (gen_pro_epilogue_adjust_stack (stack_pointer_rtx,
2111                                                     hard_frame_pointer_rtx,
2112                                                     GEN_INT (offset),
2113                                                     hard_frame_pointer_rtx));
2114         }
2115       else if (tsize)
2116         ix86_emit_epilogue_esp_adjustment (tsize);
2117
2118       for (regno = 0; regno < STACK_POINTER_REGNUM; regno++)
2119         if ((regs_ever_live[regno] && !call_used_regs[regno])
2120             || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
2121           emit_insn (gen_popsi1 (gen_rtx_REG (SImode, regno)));
2122     }
2123
2124   /* Sibcall epilogues don't want a return instruction.  */
2125   if (! emit_return)
2126     return;
2127
2128   if (current_function_pops_args && current_function_args_size)
2129     {
2130       rtx popc = GEN_INT (current_function_pops_args);
2131
2132       /* i386 can only pop 64K bytes.  If asked to pop more, pop
2133          return address, do explicit add, and jump indirectly to the
2134          caller. */
2135
2136       if (current_function_pops_args >= 65536)
2137         {
2138           rtx ecx = gen_rtx_REG (SImode, 2);
2139
2140           emit_insn (gen_popsi1 (ecx));
2141           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc));
2142           emit_jump_insn (gen_return_indirect_internal (ecx));
2143         }
2144       else
2145         emit_jump_insn (gen_return_pop_internal (popc));
2146     }
2147   else
2148     emit_jump_insn (gen_return_internal ());
2149 }
2150 \f
2151 /* Extract the parts of an RTL expression that is a valid memory address
2152    for an instruction.  Return false if the structure of the address is
2153    grossly off.  */
2154
2155 static int
2156 ix86_decompose_address (addr, out)
2157      register rtx addr;
2158      struct ix86_address *out;
2159 {
2160   rtx base = NULL_RTX;
2161   rtx index = NULL_RTX;
2162   rtx disp = NULL_RTX;
2163   HOST_WIDE_INT scale = 1;
2164   rtx scale_rtx = NULL_RTX;
2165
2166   if (GET_CODE (addr) == REG || GET_CODE (addr) == SUBREG)
2167     base = addr;
2168   else if (GET_CODE (addr) == PLUS)
2169     {
2170       rtx op0 = XEXP (addr, 0);
2171       rtx op1 = XEXP (addr, 1);
2172       enum rtx_code code0 = GET_CODE (op0);
2173       enum rtx_code code1 = GET_CODE (op1);
2174
2175       if (code0 == REG || code0 == SUBREG)
2176         {
2177           if (code1 == REG || code1 == SUBREG)
2178             index = op0, base = op1;    /* index + base */
2179           else
2180             base = op0, disp = op1;     /* base + displacement */
2181         }
2182       else if (code0 == MULT)
2183         {
2184           index = XEXP (op0, 0);
2185           scale_rtx = XEXP (op0, 1);
2186           if (code1 == REG || code1 == SUBREG)
2187             base = op1;                 /* index*scale + base */
2188           else
2189             disp = op1;                 /* index*scale + disp */
2190         }
2191       else if (code0 == PLUS && GET_CODE (XEXP (op0, 0)) == MULT)
2192         {
2193           index = XEXP (XEXP (op0, 0), 0);      /* index*scale + base + disp */
2194           scale_rtx = XEXP (XEXP (op0, 0), 1);
2195           base = XEXP (op0, 1);
2196           disp = op1;
2197         }
2198       else if (code0 == PLUS)
2199         {
2200           index = XEXP (op0, 0);        /* index + base + disp */
2201           base = XEXP (op0, 1);
2202           disp = op1;
2203         }
2204       else
2205         return FALSE;
2206     }
2207   else if (GET_CODE (addr) == MULT)
2208     {
2209       index = XEXP (addr, 0);           /* index*scale */
2210       scale_rtx = XEXP (addr, 1);
2211     }
2212   else if (GET_CODE (addr) == ASHIFT)
2213     {
2214       rtx tmp;
2215
2216       /* We're called for lea too, which implements ashift on occasion.  */
2217       index = XEXP (addr, 0);
2218       tmp = XEXP (addr, 1);
2219       if (GET_CODE (tmp) != CONST_INT)
2220         return FALSE;
2221       scale = INTVAL (tmp);
2222       if ((unsigned HOST_WIDE_INT) scale > 3)
2223         return FALSE;
2224       scale = 1 << scale;
2225     }
2226   else
2227     disp = addr;                        /* displacement */
2228
2229   /* Extract the integral value of scale.  */
2230   if (scale_rtx)
2231     {
2232       if (GET_CODE (scale_rtx) != CONST_INT)
2233         return FALSE;
2234       scale = INTVAL (scale_rtx);
2235     }
2236
2237   /* Allow arg pointer and stack pointer as index if there is not scaling */
2238   if (base && index && scale == 1
2239       && (index == arg_pointer_rtx || index == frame_pointer_rtx
2240           || index == stack_pointer_rtx))
2241     {
2242       rtx tmp = base;
2243       base = index;
2244       index = tmp;
2245     }
2246
2247   /* Special case: %ebp cannot be encoded as a base without a displacement.  */
2248   if ((base == hard_frame_pointer_rtx
2249        || base == frame_pointer_rtx
2250        || base == arg_pointer_rtx) && !disp)
2251     disp = const0_rtx;
2252
2253   /* Special case: on K6, [%esi] makes the instruction vector decoded.
2254      Avoid this by transforming to [%esi+0].  */
2255   if (ix86_cpu == PROCESSOR_K6 && !optimize_size
2256       && base && !index && !disp
2257       && REG_P (base)
2258       && REGNO_REG_CLASS (REGNO (base)) == SIREG)
2259     disp = const0_rtx;
2260
2261   /* Special case: encode reg+reg instead of reg*2.  */
2262   if (!base && index && scale && scale == 2)
2263     base = index, scale = 1;
2264   
2265   /* Special case: scaling cannot be encoded without base or displacement.  */
2266   if (!base && !disp && index && scale != 1)
2267     disp = const0_rtx;
2268
2269   out->base = base;
2270   out->index = index;
2271   out->disp = disp;
2272   out->scale = scale;
2273
2274   return TRUE;
2275 }
2276 \f
2277 /* Return cost of the memory address x.
2278    For i386, it is better to use a complex address than let gcc copy
2279    the address into a reg and make a new pseudo.  But not if the address
2280    requires to two regs - that would mean more pseudos with longer
2281    lifetimes.  */
2282 int
2283 ix86_address_cost (x)
2284      rtx x;
2285 {
2286   struct ix86_address parts;
2287   int cost = 1;
2288
2289   if (!ix86_decompose_address (x, &parts))
2290     abort ();
2291
2292   /* More complex memory references are better.  */
2293   if (parts.disp && parts.disp != const0_rtx)
2294     cost--;
2295
2296   /* Attempt to minimize number of registers in the address.  */
2297   if ((parts.base
2298        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
2299       || (parts.index
2300           && (!REG_P (parts.index)
2301               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
2302     cost++;
2303
2304   if (parts.base
2305       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
2306       && parts.index
2307       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
2308       && parts.base != parts.index)
2309     cost++;
2310
2311   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
2312      since it's predecode logic can't detect the length of instructions
2313      and it degenerates to vector decoded.  Increase cost of such
2314      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
2315      to split such addresses or even refuse such addresses at all.  
2316
2317      Following addressing modes are affected:
2318       [base+scale*index]
2319       [scale*index+disp]
2320       [base+index]
2321    
2322      The first and last case  may be avoidable by explicitly coding the zero in
2323      memory address, but I don't have AMD-K6 machine handy to check this
2324      theory.  */
2325
2326   if (TARGET_K6
2327       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
2328           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
2329           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
2330     cost += 10;
2331       
2332   return cost;
2333 }
2334 \f
2335 /* Determine if a given CONST RTX is a valid memory displacement
2336    in PIC mode.  */
2337    
2338 int
2339 legitimate_pic_address_disp_p (disp)
2340      register rtx disp;
2341 {
2342   if (GET_CODE (disp) != CONST)
2343     return 0;
2344   disp = XEXP (disp, 0);
2345
2346   if (GET_CODE (disp) == PLUS)
2347     {
2348       if (GET_CODE (XEXP (disp, 1)) != CONST_INT)
2349         return 0;
2350       disp = XEXP (disp, 0);
2351     }
2352
2353   if (GET_CODE (disp) != UNSPEC
2354       || XVECLEN (disp, 0) != 1)
2355     return 0;
2356
2357   /* Must be @GOT or @GOTOFF.  */
2358   if (XINT (disp, 1) != 6
2359       && XINT (disp, 1) != 7)
2360     return 0;
2361
2362   if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
2363       && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
2364     return 0;
2365
2366   return 1;
2367 }
2368
2369 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid
2370    memory address for an instruction.  The MODE argument is the machine mode
2371    for the MEM expression that wants to use this address.
2372
2373    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
2374    convert common non-canonical forms to canonical form so that they will
2375    be recognized.  */
2376
2377 int
2378 legitimate_address_p (mode, addr, strict)
2379      enum machine_mode mode;
2380      register rtx addr;
2381      int strict;
2382 {
2383   struct ix86_address parts;
2384   rtx base, index, disp;
2385   HOST_WIDE_INT scale;
2386   const char *reason = NULL;
2387   rtx reason_rtx = NULL_RTX;
2388
2389   if (TARGET_DEBUG_ADDR)
2390     {
2391       fprintf (stderr,
2392                "\n======\nGO_IF_LEGITIMATE_ADDRESS, mode = %s, strict = %d\n",
2393                GET_MODE_NAME (mode), strict);
2394       debug_rtx (addr);
2395     }
2396
2397   if (! ix86_decompose_address (addr, &parts))
2398     {
2399       reason = "decomposition failed";
2400       goto report_error;
2401     }
2402
2403   base = parts.base;
2404   index = parts.index;
2405   disp = parts.disp;
2406   scale = parts.scale;
2407
2408   /* Validate base register.
2409
2410      Don't allow SUBREG's here, it can lead to spill failures when the base
2411      is one word out of a two word structure, which is represented internally
2412      as a DImode int.  */
2413
2414   if (base)
2415     {
2416       reason_rtx = base;
2417
2418       if (GET_CODE (base) != REG)
2419         {
2420           reason = "base is not a register";
2421           goto report_error;
2422         }
2423
2424       if (GET_MODE (base) != Pmode)
2425         {
2426           reason = "base is not in Pmode";
2427           goto report_error;
2428         }
2429
2430       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (base))
2431           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (base)))
2432         {
2433           reason = "base is not valid";
2434           goto report_error;
2435         }
2436     }
2437
2438   /* Validate index register.
2439
2440      Don't allow SUBREG's here, it can lead to spill failures when the index
2441      is one word out of a two word structure, which is represented internally
2442      as a DImode int.  */
2443
2444   if (index)
2445     {
2446       reason_rtx = index;
2447
2448       if (GET_CODE (index) != REG)
2449         {
2450           reason = "index is not a register";
2451           goto report_error;
2452         }
2453
2454       if (GET_MODE (index) != Pmode)
2455         {
2456           reason = "index is not in Pmode";
2457           goto report_error;
2458         }
2459
2460       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (index))
2461           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (index)))
2462         {
2463           reason = "index is not valid";
2464           goto report_error;
2465         }
2466     }
2467
2468   /* Validate scale factor.  */
2469   if (scale != 1)
2470     {
2471       reason_rtx = GEN_INT (scale);
2472       if (!index)
2473         {
2474           reason = "scale without index";
2475           goto report_error;
2476         }
2477
2478       if (scale != 2 && scale != 4 && scale != 8)
2479         {
2480           reason = "scale is not a valid multiplier";
2481           goto report_error;
2482         }
2483     }
2484
2485   /* Validate displacement.  */
2486   if (disp)
2487     {
2488       reason_rtx = disp;
2489
2490       if (!CONSTANT_ADDRESS_P (disp))
2491         {
2492           reason = "displacement is not constant";
2493           goto report_error;
2494         }
2495
2496       if (GET_CODE (disp) == CONST_DOUBLE)
2497         {
2498           reason = "displacement is a const_double";
2499           goto report_error;
2500         }
2501
2502       if (flag_pic && SYMBOLIC_CONST (disp))
2503         {
2504           if (! legitimate_pic_address_disp_p (disp))
2505             {
2506               reason = "displacement is an invalid pic construct";
2507               goto report_error;
2508             }
2509
2510           /* This code used to verify that a symbolic pic displacement
2511              includes the pic_offset_table_rtx register. 
2512             
2513              While this is good idea, unfortunately these constructs may
2514              be created by "adds using lea" optimization for incorrect
2515              code like:
2516
2517              int a;
2518              int foo(int i)
2519                {
2520                  return *(&a+i);
2521                }
2522
2523              This code is nonsensical, but results in addressing
2524              GOT table with pic_offset_table_rtx base.  We can't
2525              just refuse it easilly, since it gets matched by
2526              "addsi3" pattern, that later gets split to lea in the
2527              case output register differs from input.  While this
2528              can be handled by separate addsi pattern for this case
2529              that never results in lea, this seems to be easier and
2530              correct fix for crash to disable this test.  */
2531         }
2532       else if (HALF_PIC_P ())
2533         {
2534           if (! HALF_PIC_ADDRESS_P (disp)
2535               || (base != NULL_RTX || index != NULL_RTX))
2536             {
2537               reason = "displacement is an invalid half-pic reference";
2538               goto report_error;
2539             }
2540         }
2541     }
2542
2543   /* Everything looks valid.  */
2544   if (TARGET_DEBUG_ADDR)
2545     fprintf (stderr, "Success.\n");
2546   return TRUE;
2547
2548 report_error:
2549   if (TARGET_DEBUG_ADDR)
2550     {
2551       fprintf (stderr, "Error: %s\n", reason);
2552       debug_rtx (reason_rtx);
2553     }
2554   return FALSE;
2555 }
2556 \f
2557 /* Return an unique alias set for the GOT.  */
2558
2559 static HOST_WIDE_INT   
2560 ix86_GOT_alias_set ()
2561 {
2562     static HOST_WIDE_INT set = -1;
2563     if (set == -1)
2564       set = new_alias_set ();
2565     return set;
2566 }   
2567
2568 /* Return a legitimate reference for ORIG (an address) using the
2569    register REG.  If REG is 0, a new pseudo is generated.
2570
2571    There are two types of references that must be handled:
2572
2573    1. Global data references must load the address from the GOT, via
2574       the PIC reg.  An insn is emitted to do this load, and the reg is
2575       returned.
2576
2577    2. Static data references, constant pool addresses, and code labels
2578       compute the address as an offset from the GOT, whose base is in
2579       the PIC reg.  Static data objects have SYMBOL_REF_FLAG set to
2580       differentiate them from global data objects.  The returned
2581       address is the PIC reg + an unspec constant.
2582
2583    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2584    reg also appears in the address.  */
2585
2586 rtx
2587 legitimize_pic_address (orig, reg)
2588      rtx orig;
2589      rtx reg;
2590 {
2591   rtx addr = orig;
2592   rtx new = orig;
2593   rtx base;
2594
2595   if (GET_CODE (addr) == LABEL_REF
2596       || (GET_CODE (addr) == SYMBOL_REF
2597           && (CONSTANT_POOL_ADDRESS_P (addr)
2598               || SYMBOL_REF_FLAG (addr))))
2599     {
2600       /* This symbol may be referenced via a displacement from the PIC
2601          base address (@GOTOFF).  */
2602
2603       current_function_uses_pic_offset_table = 1;
2604       new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), 7);
2605       new = gen_rtx_CONST (Pmode, new);
2606       new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new);
2607
2608       if (reg != 0)
2609         {
2610           emit_move_insn (reg, new);
2611           new = reg;
2612         }
2613     }
2614   else if (GET_CODE (addr) == SYMBOL_REF)
2615     {
2616       /* This symbol must be referenced via a load from the
2617          Global Offset Table (@GOT). */
2618
2619       current_function_uses_pic_offset_table = 1;
2620       new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), 6);
2621       new = gen_rtx_CONST (Pmode, new);
2622       new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new);
2623       new = gen_rtx_MEM (Pmode, new);
2624       RTX_UNCHANGING_P (new) = 1;
2625       MEM_ALIAS_SET (new) = ix86_GOT_alias_set ();      
2626
2627       if (reg == 0)
2628         reg = gen_reg_rtx (Pmode);
2629       emit_move_insn (reg, new);
2630       new = reg;
2631     }      
2632   else
2633     {
2634       if (GET_CODE (addr) == CONST)
2635         {
2636           addr = XEXP (addr, 0);
2637           if (GET_CODE (addr) == UNSPEC)
2638             {
2639               /* Check that the unspec is one of the ones we generate?  */
2640             }
2641           else if (GET_CODE (addr) != PLUS)
2642             abort ();
2643         }
2644       if (GET_CODE (addr) == PLUS)
2645         {
2646           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
2647
2648           /* Check first to see if this is a constant offset from a @GOTOFF
2649              symbol reference.  */
2650           if ((GET_CODE (op0) == LABEL_REF
2651                || (GET_CODE (op0) == SYMBOL_REF
2652                    && (CONSTANT_POOL_ADDRESS_P (op0)
2653                        || SYMBOL_REF_FLAG (op0))))
2654               && GET_CODE (op1) == CONST_INT)
2655             {
2656               current_function_uses_pic_offset_table = 1;
2657               new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0), 7);
2658               new = gen_rtx_PLUS (Pmode, new, op1);
2659               new = gen_rtx_CONST (Pmode, new);
2660               new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new);
2661
2662               if (reg != 0)
2663                 {
2664                   emit_move_insn (reg, new);
2665                   new = reg;
2666                 }
2667             }
2668           else
2669             {
2670               base = legitimize_pic_address (XEXP (addr, 0), reg);
2671               new  = legitimize_pic_address (XEXP (addr, 1),
2672                                              base == reg ? NULL_RTX : reg);
2673
2674               if (GET_CODE (new) == CONST_INT)
2675                 new = plus_constant (base, INTVAL (new));
2676               else
2677                 {
2678                   if (GET_CODE (new) == PLUS && CONSTANT_P (XEXP (new, 1)))
2679                     {
2680                       base = gen_rtx_PLUS (Pmode, base, XEXP (new, 0));
2681                       new = XEXP (new, 1);
2682                     }
2683                   new = gen_rtx_PLUS (Pmode, base, new);
2684                 }
2685             }
2686         }
2687     }
2688   return new;
2689 }
2690 \f
2691 /* Try machine-dependent ways of modifying an illegitimate address
2692    to be legitimate.  If we find one, return the new, valid address.
2693    This macro is used in only one place: `memory_address' in explow.c.
2694
2695    OLDX is the address as it was before break_out_memory_refs was called.
2696    In some cases it is useful to look at this to decide what needs to be done.
2697
2698    MODE and WIN are passed so that this macro can use
2699    GO_IF_LEGITIMATE_ADDRESS.
2700
2701    It is always safe for this macro to do nothing.  It exists to recognize
2702    opportunities to optimize the output.
2703
2704    For the 80386, we handle X+REG by loading X into a register R and
2705    using R+REG.  R will go in a general reg and indexing will be used.
2706    However, if REG is a broken-out memory address or multiplication,
2707    nothing needs to be done because REG can certainly go in a general reg.
2708
2709    When -fpic is used, special handling is needed for symbolic references.
2710    See comments by legitimize_pic_address in i386.c for details.  */
2711
2712 rtx
2713 legitimize_address (x, oldx, mode)
2714      register rtx x;
2715      register rtx oldx ATTRIBUTE_UNUSED;
2716      enum machine_mode mode;
2717 {
2718   int changed = 0;
2719   unsigned log;
2720
2721   if (TARGET_DEBUG_ADDR)
2722     {
2723       fprintf (stderr, "\n==========\nLEGITIMIZE_ADDRESS, mode = %s\n",
2724                GET_MODE_NAME (mode));
2725       debug_rtx (x);
2726     }
2727
2728   if (flag_pic && SYMBOLIC_CONST (x))
2729     return legitimize_pic_address (x, 0);
2730
2731   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
2732   if (GET_CODE (x) == ASHIFT
2733       && GET_CODE (XEXP (x, 1)) == CONST_INT
2734       && (log = (unsigned)exact_log2 (INTVAL (XEXP (x, 1)))) < 4)
2735     {
2736       changed = 1;
2737       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
2738                         GEN_INT (1 << log));
2739     }
2740
2741   if (GET_CODE (x) == PLUS)
2742     {
2743       /* Canonicalize shifts by 0, 1, 2, 3 into multiply. */
2744
2745       if (GET_CODE (XEXP (x, 0)) == ASHIFT
2746           && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2747           && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) < 4)
2748         {
2749           changed = 1;
2750           XEXP (x, 0) = gen_rtx_MULT (Pmode,
2751                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
2752                                       GEN_INT (1 << log));
2753         }
2754
2755       if (GET_CODE (XEXP (x, 1)) == ASHIFT
2756           && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
2757           && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 1), 1)))) < 4)
2758         {
2759           changed = 1;
2760           XEXP (x, 1) = gen_rtx_MULT (Pmode,
2761                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
2762                                       GEN_INT (1 << log));
2763         }
2764
2765       /* Put multiply first if it isn't already. */
2766       if (GET_CODE (XEXP (x, 1)) == MULT)
2767         {
2768           rtx tmp = XEXP (x, 0);
2769           XEXP (x, 0) = XEXP (x, 1);
2770           XEXP (x, 1) = tmp;
2771           changed = 1;
2772         }
2773
2774       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
2775          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
2776          created by virtual register instantiation, register elimination, and
2777          similar optimizations.  */
2778       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
2779         {
2780           changed = 1;
2781           x = gen_rtx_PLUS (Pmode,
2782                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
2783                                           XEXP (XEXP (x, 1), 0)),
2784                             XEXP (XEXP (x, 1), 1));
2785         }
2786
2787       /* Canonicalize
2788          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
2789          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
2790       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
2791                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
2792                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
2793                && CONSTANT_P (XEXP (x, 1)))
2794         {
2795           rtx constant;
2796           rtx other = NULL_RTX;
2797
2798           if (GET_CODE (XEXP (x, 1)) == CONST_INT)
2799             {
2800               constant = XEXP (x, 1);
2801               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
2802             }
2803           else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT)
2804             {
2805               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
2806               other = XEXP (x, 1);
2807             }
2808           else
2809             constant = 0;
2810
2811           if (constant)
2812             {
2813               changed = 1;
2814               x = gen_rtx_PLUS (Pmode,
2815                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
2816                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
2817                                 plus_constant (other, INTVAL (constant)));
2818             }
2819         }
2820
2821       if (changed && legitimate_address_p (mode, x, FALSE))
2822         return x;
2823
2824       if (GET_CODE (XEXP (x, 0)) == MULT)
2825         {
2826           changed = 1;
2827           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
2828         }
2829
2830       if (GET_CODE (XEXP (x, 1)) == MULT)
2831         {
2832           changed = 1;
2833           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
2834         }
2835
2836       if (changed
2837           && GET_CODE (XEXP (x, 1)) == REG
2838           && GET_CODE (XEXP (x, 0)) == REG)
2839         return x;
2840
2841       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
2842         {
2843           changed = 1;
2844           x = legitimize_pic_address (x, 0);
2845         }
2846
2847       if (changed && legitimate_address_p (mode, x, FALSE))
2848         return x;
2849
2850       if (GET_CODE (XEXP (x, 0)) == REG)
2851         {
2852           register rtx temp = gen_reg_rtx (Pmode);
2853           register rtx val  = force_operand (XEXP (x, 1), temp);
2854           if (val != temp)
2855             emit_move_insn (temp, val);
2856
2857           XEXP (x, 1) = temp;
2858           return x;
2859         }
2860
2861       else if (GET_CODE (XEXP (x, 1)) == REG)
2862         {
2863           register rtx temp = gen_reg_rtx (Pmode);
2864           register rtx val  = force_operand (XEXP (x, 0), temp);
2865           if (val != temp)
2866             emit_move_insn (temp, val);
2867
2868           XEXP (x, 0) = temp;
2869           return x;
2870         }
2871     }
2872
2873   return x;
2874 }
2875 \f
2876 /* Print an integer constant expression in assembler syntax.  Addition
2877    and subtraction are the only arithmetic that may appear in these
2878    expressions.  FILE is the stdio stream to write to, X is the rtx, and
2879    CODE is the operand print code from the output string.  */
2880
2881 static void
2882 output_pic_addr_const (file, x, code)
2883      FILE *file;
2884      rtx x;
2885      int code;
2886 {
2887   char buf[256];
2888
2889   switch (GET_CODE (x))
2890     {
2891     case PC:
2892       if (flag_pic)
2893         putc ('.', file);
2894       else
2895         abort ();
2896       break;
2897
2898     case SYMBOL_REF:
2899       assemble_name (file, XSTR (x, 0));
2900       if (code == 'P' && ! SYMBOL_REF_FLAG (x))
2901         fputs ("@PLT", file);
2902       break;
2903
2904     case LABEL_REF:
2905       x = XEXP (x, 0);
2906       /* FALLTHRU */
2907     case CODE_LABEL:
2908       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2909       assemble_name (asm_out_file, buf);
2910       break;
2911
2912     case CONST_INT:
2913       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2914       break;
2915
2916     case CONST:
2917       /* This used to output parentheses around the expression,
2918          but that does not work on the 386 (either ATT or BSD assembler).  */
2919       output_pic_addr_const (file, XEXP (x, 0), code);
2920       break;
2921
2922     case CONST_DOUBLE:
2923       if (GET_MODE (x) == VOIDmode)
2924         {
2925           /* We can use %d if the number is <32 bits and positive.  */
2926           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
2927             fprintf (file, "0x%lx%08lx",
2928                      (unsigned long) CONST_DOUBLE_HIGH (x),
2929                      (unsigned long) CONST_DOUBLE_LOW (x));
2930           else
2931             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
2932         }
2933       else
2934         /* We can't handle floating point constants;
2935            PRINT_OPERAND must handle them.  */
2936         output_operand_lossage ("floating constant misused");
2937       break;
2938
2939     case PLUS:
2940       /* Some assemblers need integer constants to appear first.  */
2941       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2942         {
2943           output_pic_addr_const (file, XEXP (x, 0), code);
2944           putc ('+', file);
2945           output_pic_addr_const (file, XEXP (x, 1), code);
2946         }
2947       else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
2948         {
2949           output_pic_addr_const (file, XEXP (x, 1), code);
2950           putc ('+', file);
2951           output_pic_addr_const (file, XEXP (x, 0), code);
2952         }
2953       else
2954         abort ();
2955       break;
2956
2957     case MINUS:
2958       putc (ASSEMBLER_DIALECT ? '(' : '[', file);
2959       output_pic_addr_const (file, XEXP (x, 0), code);
2960       putc ('-', file);
2961       output_pic_addr_const (file, XEXP (x, 1), code);
2962       putc (ASSEMBLER_DIALECT ? ')' : ']', file);
2963       break;
2964
2965      case UNSPEC:
2966        if (XVECLEN (x, 0) != 1)
2967         abort ();
2968        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
2969        switch (XINT (x, 1))
2970         {
2971         case 6:
2972           fputs ("@GOT", file);
2973           break;
2974         case 7:
2975           fputs ("@GOTOFF", file);
2976           break;
2977         case 8:
2978           fputs ("@PLT", file);
2979           break;
2980         default:
2981           output_operand_lossage ("invalid UNSPEC as operand");
2982           break;
2983         }
2984        break;
2985
2986     default:
2987       output_operand_lossage ("invalid expression as operand");
2988     }
2989 }
2990
2991 /* This is called from dwarfout.c via ASM_OUTPUT_DWARF_ADDR_CONST.  
2992    We need to handle our special PIC relocations.  */
2993
2994 void 
2995 i386_dwarf_output_addr_const (file, x)
2996      FILE *file;
2997      rtx x;
2998 {
2999   fprintf (file, "\t%s\t", INT_ASM_OP);
3000   if (flag_pic)
3001     output_pic_addr_const (file, x, '\0');
3002   else
3003     output_addr_const (file, x);
3004   fputc ('\n', file);
3005 }
3006
3007 /* In the name of slightly smaller debug output, and to cater to
3008    general assembler losage, recognize PIC+GOTOFF and turn it back
3009    into a direct symbol reference.  */
3010
3011 rtx
3012 i386_simplify_dwarf_addr (orig_x)
3013      rtx orig_x;
3014 {
3015   rtx x = orig_x;
3016
3017   if (GET_CODE (x) != PLUS
3018       || GET_CODE (XEXP (x, 0)) != REG
3019       || GET_CODE (XEXP (x, 1)) != CONST)
3020     return orig_x;
3021
3022   x = XEXP (XEXP (x, 1), 0);
3023   if (GET_CODE (x) == UNSPEC
3024       && XINT (x, 1) == 7)
3025     return XVECEXP (x, 0, 0);
3026
3027   if (GET_CODE (x) == PLUS
3028       && GET_CODE (XEXP (x, 0)) == UNSPEC
3029       && GET_CODE (XEXP (x, 1)) == CONST_INT
3030       && XINT (XEXP (x, 0), 1) == 7)
3031     return gen_rtx_PLUS (VOIDmode, XVECEXP (XEXP (x, 0), 0, 0), XEXP (x, 1));
3032
3033   return orig_x;
3034 }
3035 \f
3036 static void
3037 put_condition_code (code, mode, reverse, fp, file)
3038      enum rtx_code code;
3039      enum machine_mode mode;
3040      int reverse, fp;
3041      FILE *file;
3042 {
3043   const char *suffix;
3044
3045   if (reverse)
3046     code = reverse_condition (code);
3047
3048   switch (code)
3049     {
3050     case EQ:
3051       suffix = "e";
3052       break;
3053     case NE:
3054       suffix = "ne";
3055       break;
3056     case GT:
3057       if (mode == CCNOmode)
3058         abort ();
3059       suffix = "g";
3060       break;
3061     case GTU:
3062       /* ??? Use "nbe" instead of "a" for fcmov losage on some assemblers.
3063          Those same assemblers have the same but opposite losage on cmov.  */
3064       suffix = fp ? "nbe" : "a";
3065       break;
3066     case LT:
3067       if (mode == CCNOmode)
3068         suffix = "s";
3069       else
3070         suffix = "l";
3071       break;
3072     case LTU:
3073       suffix = "b";
3074       break;
3075     case GE:
3076       if (mode == CCNOmode)
3077         suffix = "ns";
3078       else
3079         suffix = "ge";
3080       break;
3081     case GEU:
3082       /* ??? As above.  */
3083       suffix = fp ? "nb" : "ae";
3084       break;
3085     case LE:
3086       if (mode == CCNOmode)
3087         abort ();
3088       suffix = "le";
3089       break;
3090     case LEU:
3091       suffix = "be";
3092       break;
3093     case UNORDERED:
3094       suffix = "p";
3095       break;
3096     case ORDERED:
3097       suffix = "np";
3098       break;
3099     default:
3100       abort ();
3101     }
3102   fputs (suffix, file);
3103 }
3104
3105 void
3106 print_reg (x, code, file)
3107      rtx x;
3108      int code;
3109      FILE *file;
3110 {
3111   if (REGNO (x) == ARG_POINTER_REGNUM
3112       || REGNO (x) == FRAME_POINTER_REGNUM
3113       || REGNO (x) == FLAGS_REG
3114       || REGNO (x) == FPSR_REG)
3115     abort ();
3116
3117   if (ASSEMBLER_DIALECT == 0 || USER_LABEL_PREFIX[0] == 0)
3118     putc ('%', file);
3119
3120   if (code == 'w')
3121     code = 2;
3122   else if (code == 'b')
3123     code = 1;
3124   else if (code == 'k')
3125     code = 4;
3126   else if (code == 'y')
3127     code = 3;
3128   else if (code == 'h')
3129     code = 0;
3130   else if (code == 'm' || MMX_REG_P (x))
3131     code = 5;
3132   else
3133     code = GET_MODE_SIZE (GET_MODE (x));
3134
3135   switch (code)
3136     {
3137     case 5:
3138       fputs (hi_reg_name[REGNO (x)], file);
3139       break;
3140     case 3:
3141       if (STACK_TOP_P (x))
3142         {
3143           fputs ("st(0)", file);
3144           break;
3145         }
3146       /* FALLTHRU */
3147     case 4:
3148     case 8:
3149     case 12:
3150       if (! FP_REG_P (x))
3151         putc ('e', file);
3152       /* FALLTHRU */
3153     case 16:
3154     case 2:
3155       fputs (hi_reg_name[REGNO (x)], file);
3156       break;
3157     case 1:
3158       fputs (qi_reg_name[REGNO (x)], file);
3159       break;
3160     case 0:
3161       fputs (qi_high_reg_name[REGNO (x)], file);
3162       break;
3163     default:
3164       abort ();
3165     }
3166 }
3167
3168 /* Meaning of CODE:
3169    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
3170    C -- print opcode suffix for set/cmov insn.
3171    c -- like C, but print reversed condition
3172    R -- print the prefix for register names.
3173    z -- print the opcode suffix for the size of the current operand.
3174    * -- print a star (in certain assembler syntax)
3175    w -- print the operand as if it's a "word" (HImode) even if it isn't.
3176    s -- print a shift double count, followed by the assemblers argument
3177         delimiter.
3178    b -- print the QImode name of the register for the indicated operand.
3179         %b0 would print %al if operands[0] is reg 0.
3180    w --  likewise, print the HImode name of the register.
3181    k --  likewise, print the SImode name of the register.
3182    h --  print the QImode name for a "high" register, either ah, bh, ch or dh.
3183    y --  print "st(0)" instead of "st" as a register.
3184    m --  print "st(n)" as an mmx register.  */
3185
3186 void
3187 print_operand (file, x, code)
3188      FILE *file;
3189      rtx x;
3190      int code;
3191 {
3192   if (code)
3193     {
3194       switch (code)
3195         {
3196         case '*':
3197           if (ASSEMBLER_DIALECT == 0)
3198             putc ('*', file);
3199           return;
3200
3201         case 'L':
3202           if (ASSEMBLER_DIALECT == 0)
3203             putc ('l', file);
3204           return;
3205
3206         case 'W':
3207           if (ASSEMBLER_DIALECT == 0)
3208             putc ('w', file);
3209           return;
3210
3211         case 'B':
3212           if (ASSEMBLER_DIALECT == 0)
3213             putc ('b', file);
3214           return;
3215
3216         case 'Q':
3217           if (ASSEMBLER_DIALECT == 0)
3218             putc ('l', file);
3219           return;
3220
3221         case 'S':
3222           if (ASSEMBLER_DIALECT == 0)
3223             putc ('s', file);
3224           return;
3225
3226         case 'T':
3227           if (ASSEMBLER_DIALECT == 0)
3228             putc ('t', file);
3229           return;
3230
3231         case 'z':
3232           /* 387 opcodes don't get size suffixes if the operands are
3233              registers. */
3234
3235           if (STACK_REG_P (x))
3236             return;
3237
3238           /* Intel syntax has no truck with instruction suffixes.  */
3239           if (ASSEMBLER_DIALECT != 0)
3240             return;
3241
3242           /* this is the size of op from size of operand */
3243           switch (GET_MODE_SIZE (GET_MODE (x)))
3244             {
3245             case 2:
3246 #ifdef HAVE_GAS_FILDS_FISTS
3247               putc ('s', file);
3248 #endif
3249               return;
3250
3251             case 4:
3252               if (GET_MODE (x) == SFmode)
3253                 {
3254                   putc ('s', file);
3255                   return;
3256                 }
3257               else
3258                 putc ('l', file);
3259               return;
3260
3261             case 12:
3262               putc ('t', file);
3263               return;
3264
3265             case 8:
3266               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
3267                 {
3268 #ifdef GAS_MNEMONICS
3269                   putc ('q', file);
3270 #else
3271                   putc ('l', file);
3272                   putc ('l', file);
3273 #endif
3274                 }
3275               else
3276                 putc ('l', file);
3277               return;
3278
3279             default:
3280               abort ();
3281             }
3282
3283         case 'b':
3284         case 'w':
3285         case 'k':
3286         case 'h':
3287         case 'y':
3288         case 'm':
3289         case 'X':
3290         case 'P':
3291           break;
3292
3293         case 's':
3294           if (GET_CODE (x) == CONST_INT || ! SHIFT_DOUBLE_OMITS_COUNT)
3295             {
3296               PRINT_OPERAND (file, x, 0);
3297               putc (',', file);
3298             }
3299           return;
3300
3301         case 'C':
3302           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
3303           return;
3304         case 'F':
3305           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
3306           return;
3307
3308           /* Like above, but reverse condition */
3309         case 'c':
3310           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
3311           return;
3312         case 'f':
3313           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
3314           return;
3315
3316         default:
3317           {
3318             char str[50];
3319             sprintf (str, "invalid operand code `%c'", code);
3320             output_operand_lossage (str);
3321           }
3322         }
3323     }
3324
3325   if (GET_CODE (x) == REG)
3326     {
3327       PRINT_REG (x, code, file);
3328     }
3329
3330   else if (GET_CODE (x) == MEM)
3331     {
3332       /* No `byte ptr' prefix for call instructions.  */
3333       if (ASSEMBLER_DIALECT != 0 && code != 'X' && code != 'P')
3334         {
3335           const char * size;
3336           switch (GET_MODE_SIZE (GET_MODE (x)))
3337             {
3338             case 1: size = "BYTE"; break;
3339             case 2: size = "WORD"; break;
3340             case 4: size = "DWORD"; break;
3341             case 8: size = "QWORD"; break;
3342             case 12: size = "XWORD"; break;
3343             case 16: size = "XMMWORD"; break;
3344             default:
3345               abort ();
3346             }
3347           fputs (size, file);
3348           fputs (" PTR ", file);
3349         }
3350
3351       x = XEXP (x, 0);
3352       if (flag_pic && CONSTANT_ADDRESS_P (x))
3353         output_pic_addr_const (file, x, code);
3354       else
3355         output_address (x);
3356     }
3357
3358   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
3359     {
3360       REAL_VALUE_TYPE r;
3361       long l;
3362
3363       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3364       REAL_VALUE_TO_TARGET_SINGLE (r, l);
3365
3366       if (ASSEMBLER_DIALECT == 0)
3367         putc ('$', file);
3368       fprintf (file, "0x%lx", l);
3369     }
3370
3371  /* These float cases don't actually occur as immediate operands. */
3372  else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
3373     {
3374       REAL_VALUE_TYPE r;
3375       char dstr[30];
3376
3377       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3378       REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr);
3379       fprintf (file, "%s", dstr);
3380     }
3381
3382   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == XFmode)
3383     {
3384       REAL_VALUE_TYPE r;
3385       char dstr[30];
3386
3387       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3388       REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr);
3389       fprintf (file, "%s", dstr);
3390     }
3391   else
3392     {
3393       if (code != 'P')
3394         {
3395           if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
3396             {
3397               if (ASSEMBLER_DIALECT == 0)
3398                 putc ('$', file);
3399             }
3400           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
3401                    || GET_CODE (x) == LABEL_REF)
3402             {
3403               if (ASSEMBLER_DIALECT == 0)
3404                 putc ('$', file);
3405               else
3406                 fputs ("OFFSET FLAT:", file);
3407             }
3408         }
3409       if (GET_CODE (x) == CONST_INT)
3410         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3411       else if (flag_pic)
3412         output_pic_addr_const (file, x, code);
3413       else
3414         output_addr_const (file, x);
3415     }
3416 }
3417 \f
3418 /* Print a memory operand whose address is ADDR.  */
3419
3420 void
3421 print_operand_address (file, addr)
3422      FILE *file;
3423      register rtx addr;
3424 {
3425   struct ix86_address parts;
3426   rtx base, index, disp;
3427   int scale;
3428
3429   if (! ix86_decompose_address (addr, &parts))
3430     abort ();
3431
3432   base = parts.base;
3433   index = parts.index;
3434   disp = parts.disp;
3435   scale = parts.scale;
3436
3437   if (!base && !index)
3438     {
3439       /* Displacement only requires special attention.  */
3440
3441       if (GET_CODE (disp) == CONST_INT)
3442         {
3443           if (ASSEMBLER_DIALECT != 0)
3444             fputs ("ds:", file);
3445           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (addr));
3446         }
3447       else if (flag_pic)
3448         output_pic_addr_const (file, addr, 0);
3449       else
3450         output_addr_const (file, addr);
3451     }
3452   else
3453     {
3454       if (ASSEMBLER_DIALECT == 0)
3455         {
3456           if (disp)
3457             {
3458               if (flag_pic)
3459                 output_pic_addr_const (file, disp, 0);
3460               else if (GET_CODE (disp) == LABEL_REF)
3461                 output_asm_label (disp);
3462               else
3463                 output_addr_const (file, disp);
3464             }
3465
3466           putc ('(', file);
3467           if (base)
3468             PRINT_REG (base, 0, file);
3469           if (index)
3470             {
3471               putc (',', file);
3472               PRINT_REG (index, 0, file);
3473               if (scale != 1)
3474                 fprintf (file, ",%d", scale);
3475             }
3476           putc (')', file);
3477         }
3478       else
3479         {
3480           rtx offset = NULL_RTX;
3481
3482           if (disp)
3483             {
3484               /* Pull out the offset of a symbol; print any symbol itself.  */
3485               if (GET_CODE (disp) == CONST
3486                   && GET_CODE (XEXP (disp, 0)) == PLUS
3487                   && GET_CODE (XEXP (XEXP (disp, 0), 1)) == CONST_INT)
3488                 {
3489                   offset = XEXP (XEXP (disp, 0), 1);
3490                   disp = gen_rtx_CONST (VOIDmode,
3491                                         XEXP (XEXP (disp, 0), 0));
3492                 }
3493
3494               if (flag_pic)
3495                 output_pic_addr_const (file, disp, 0);
3496               else if (GET_CODE (disp) == LABEL_REF)
3497                 output_asm_label (disp);
3498               else if (GET_CODE (disp) == CONST_INT)
3499                 offset = disp;
3500               else
3501                 output_addr_const (file, disp);
3502             }
3503
3504           putc ('[', file);
3505           if (base)
3506             {
3507               PRINT_REG (base, 0, file);
3508               if (offset)
3509                 {
3510                   if (INTVAL (offset) >= 0)
3511                     putc ('+', file);
3512                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
3513                 }
3514             }
3515           else if (offset)
3516             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
3517           else
3518             putc ('0', file);
3519
3520           if (index)
3521             {
3522               putc ('+', file);
3523               PRINT_REG (index, 0, file);
3524               if (scale != 1)
3525                 fprintf (file, "*%d", scale);
3526             }
3527           putc (']', file);
3528         }
3529     }
3530 }
3531 \f
3532 /* Split one or more DImode RTL references into pairs of SImode
3533    references.  The RTL can be REG, offsettable MEM, integer constant, or
3534    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
3535    split and "num" is its length.  lo_half and hi_half are output arrays
3536    that parallel "operands". */
3537
3538 void
3539 split_di (operands, num, lo_half, hi_half)
3540      rtx operands[];
3541      int num;
3542      rtx lo_half[], hi_half[];
3543 {
3544   while (num--)
3545     {
3546       rtx op = operands[num];
3547       if (CONSTANT_P (op))
3548         split_double (op, &lo_half[num], &hi_half[num]);
3549       else if (! reload_completed)
3550         {
3551           lo_half[num] = gen_lowpart (SImode, op);
3552           hi_half[num] = gen_highpart (SImode, op);
3553         }
3554       else if (GET_CODE (op) == REG)
3555         {
3556           lo_half[num] = gen_rtx_REG (SImode, REGNO (op));
3557           hi_half[num] = gen_rtx_REG (SImode, REGNO (op) + 1);
3558         }
3559       else if (offsettable_memref_p (op))
3560         {
3561           rtx lo_addr = XEXP (op, 0);
3562           rtx hi_addr = XEXP (adj_offsettable_operand (op, 4), 0);
3563           lo_half[num] = change_address (op, SImode, lo_addr);
3564           hi_half[num] = change_address (op, SImode, hi_addr);
3565         }
3566       else
3567         abort ();
3568     }
3569 }
3570 \f
3571 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
3572    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
3573    is the expression of the binary operation.  The output may either be
3574    emitted here, or returned to the caller, like all output_* functions.
3575
3576    There is no guarantee that the operands are the same mode, as they
3577    might be within FLOAT or FLOAT_EXTEND expressions. */
3578
3579 #ifndef SYSV386_COMPAT
3580 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
3581    wants to fix the assemblers because that causes incompatibility
3582    with gcc.  No-one wants to fix gcc because that causes
3583    incompatibility with assemblers...  You can use the option of
3584    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
3585 #define SYSV386_COMPAT 1
3586 #endif
3587
3588 const char *
3589 output_387_binary_op (insn, operands)
3590      rtx insn;
3591      rtx *operands;
3592 {
3593   static char buf[30];
3594   const char *p;
3595
3596 #ifdef ENABLE_CHECKING
3597   /* Even if we do not want to check the inputs, this documents input
3598      constraints.  Which helps in understanding the following code.  */
3599   if (STACK_REG_P (operands[0])
3600       && ((REG_P (operands[1])
3601            && REGNO (operands[0]) == REGNO (operands[1])
3602            && (STACK_REG_P (operands[2]) || GET_CODE (operands[2]) == MEM))
3603           || (REG_P (operands[2])
3604               && REGNO (operands[0]) == REGNO (operands[2])
3605               && (STACK_REG_P (operands[1]) || GET_CODE (operands[1]) == MEM)))
3606       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
3607     ; /* ok */
3608   else
3609     abort ();
3610 #endif
3611
3612   switch (GET_CODE (operands[3]))
3613     {
3614     case PLUS:
3615       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
3616           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
3617         p = "fiadd";
3618       else
3619         p = "fadd";
3620       break;
3621
3622     case MINUS:
3623       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
3624           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
3625         p = "fisub";
3626       else
3627         p = "fsub";
3628       break;
3629
3630     case MULT:
3631       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
3632           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
3633         p = "fimul";
3634       else
3635         p = "fmul";
3636       break;
3637
3638     case DIV:
3639       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
3640           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
3641         p = "fidiv";
3642       else
3643         p = "fdiv";
3644       break;
3645
3646     default:
3647       abort ();
3648     }
3649
3650   strcpy (buf, p);
3651
3652   switch (GET_CODE (operands[3]))
3653     {
3654     case MULT:
3655     case PLUS:
3656       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
3657         {
3658           rtx temp = operands[2];
3659           operands[2] = operands[1];
3660           operands[1] = temp;
3661         }
3662
3663       /* know operands[0] == operands[1].  */
3664
3665       if (GET_CODE (operands[2]) == MEM)
3666         {
3667           p = "%z2\t%2";
3668           break;
3669         }
3670
3671       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
3672         {
3673           if (STACK_TOP_P (operands[0]))
3674             /* How is it that we are storing to a dead operand[2]?
3675                Well, presumably operands[1] is dead too.  We can't
3676                store the result to st(0) as st(0) gets popped on this
3677                instruction.  Instead store to operands[2] (which I
3678                think has to be st(1)).  st(1) will be popped later.
3679                gcc <= 2.8.1 didn't have this check and generated
3680                assembly code that the Unixware assembler rejected.  */
3681             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
3682           else
3683             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
3684           break;
3685         }
3686
3687       if (STACK_TOP_P (operands[0]))
3688         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
3689       else
3690         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
3691       break;
3692
3693     case MINUS:
3694     case DIV:
3695       if (GET_CODE (operands[1]) == MEM)
3696         {
3697           p = "r%z1\t%1";
3698           break;
3699         }
3700
3701       if (GET_CODE (operands[2]) == MEM)
3702         {
3703           p = "%z2\t%2";
3704           break;
3705         }
3706
3707       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
3708         {
3709 #if SYSV386_COMPAT
3710           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
3711              derived assemblers, confusingly reverse the direction of
3712              the operation for fsub{r} and fdiv{r} when the
3713              destination register is not st(0).  The Intel assembler
3714              doesn't have this brain damage.  Read !SYSV386_COMPAT to
3715              figure out what the hardware really does.  */
3716           if (STACK_TOP_P (operands[0]))
3717             p = "{p\t%0, %2|rp\t%2, %0}";
3718           else
3719             p = "{rp\t%2, %0|p\t%0, %2}";
3720 #else
3721           if (STACK_TOP_P (operands[0]))
3722             /* As above for fmul/fadd, we can't store to st(0).  */
3723             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
3724           else
3725             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
3726 #endif
3727           break;
3728         }
3729
3730       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3731         {
3732 #if SYSV386_COMPAT
3733           if (STACK_TOP_P (operands[0]))
3734             p = "{rp\t%0, %1|p\t%1, %0}";
3735           else
3736             p = "{p\t%1, %0|rp\t%0, %1}";
3737 #else
3738           if (STACK_TOP_P (operands[0]))
3739             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
3740           else
3741             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
3742 #endif
3743           break;
3744         }
3745
3746       if (STACK_TOP_P (operands[0]))
3747         {
3748           if (STACK_TOP_P (operands[1]))
3749             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
3750           else
3751             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
3752           break;
3753         }
3754       else if (STACK_TOP_P (operands[1]))
3755         {
3756 #if SYSV386_COMPAT
3757           p = "{\t%1, %0|r\t%0, %1}";
3758 #else
3759           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
3760 #endif
3761         }
3762       else
3763         {
3764 #if SYSV386_COMPAT
3765           p = "{r\t%2, %0|\t%0, %2}";
3766 #else
3767           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
3768 #endif
3769         }
3770       break;
3771
3772     default:
3773       abort ();
3774     }
3775
3776   strcat (buf, p);
3777   return buf;
3778 }
3779
3780 /* Output code for INSN to convert a float to a signed int.  OPERANDS
3781    are the insn operands.  The output may be [HSD]Imode and the input
3782    operand may be [SDX]Fmode.  */
3783
3784 const char *
3785 output_fix_trunc (insn, operands)
3786      rtx insn;
3787      rtx *operands;
3788 {
3789   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
3790   int dimode_p = GET_MODE (operands[0]) == DImode;
3791   rtx xops[4];
3792
3793   /* Jump through a hoop or two for DImode, since the hardware has no
3794      non-popping instruction.  We used to do this a different way, but
3795      that was somewhat fragile and broke with post-reload splitters.  */
3796   if (dimode_p && !stack_top_dies)
3797     output_asm_insn ("fld\t%y1", operands);
3798
3799   if (! STACK_TOP_P (operands[1]))
3800     abort ();
3801
3802   xops[0] = GEN_INT (12);
3803   xops[1] = adj_offsettable_operand (operands[2], 1);
3804   xops[1] = change_address (xops[1], QImode, NULL_RTX);
3805
3806   xops[2] = operands[0];
3807   if (GET_CODE (operands[0]) != MEM)
3808     xops[2] = operands[3];
3809
3810   output_asm_insn ("fnstcw\t%2", operands);
3811   output_asm_insn ("mov{l}\t{%2, %4|%4, %2}", operands);
3812   output_asm_insn ("mov{b}\t{%0, %1|%1, %0}", xops);
3813   output_asm_insn ("fldcw\t%2", operands);
3814   output_asm_insn ("mov{l}\t{%4, %2|%2, %4}", operands);
3815
3816   if (stack_top_dies || dimode_p)
3817     output_asm_insn ("fistp%z2\t%2", xops);
3818   else
3819     output_asm_insn ("fist%z2\t%2", xops);
3820
3821   output_asm_insn ("fldcw\t%2", operands);
3822
3823   if (GET_CODE (operands[0]) != MEM)
3824     {
3825       if (dimode_p)
3826         {
3827           split_di (operands+0, 1, xops+0, xops+1);
3828           split_di (operands+3, 1, xops+2, xops+3);
3829           output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
3830           output_asm_insn ("mov{l}\t{%3, %1|%1, %3}", xops);
3831         }
3832       else if (GET_MODE (operands[0]) == SImode)
3833         output_asm_insn ("mov{l}\t{%3, %0|%0, %3}", operands);
3834       else
3835         output_asm_insn ("mov{w}\t{%3, %0|%0, %3}", operands);
3836     }
3837
3838   return "";
3839 }
3840
3841 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
3842    should be used and 2 when fnstsw should be used.  UNORDERED_P is true
3843    when fucom should be used.  */
3844
3845 const char *
3846 output_fp_compare (insn, operands, eflags_p, unordered_p)
3847      rtx insn;
3848      rtx *operands;
3849      int eflags_p, unordered_p;
3850 {
3851   int stack_top_dies;
3852   rtx cmp_op0 = operands[0];
3853   rtx cmp_op1 = operands[1];
3854
3855   if (eflags_p == 2)
3856     {
3857       cmp_op0 = cmp_op1;
3858       cmp_op1 = operands[2];
3859     }
3860
3861   if (! STACK_TOP_P (cmp_op0))
3862     abort ();
3863
3864   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
3865
3866   if (STACK_REG_P (cmp_op1)
3867       && stack_top_dies
3868       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
3869       && REGNO (cmp_op1) != FIRST_STACK_REG)
3870     {
3871       /* If both the top of the 387 stack dies, and the other operand
3872          is also a stack register that dies, then this must be a
3873          `fcompp' float compare */
3874
3875       if (eflags_p == 1)
3876         {
3877           /* There is no double popping fcomi variant.  Fortunately,
3878              eflags is immune from the fstp's cc clobbering.  */
3879           if (unordered_p)
3880             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
3881           else
3882             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
3883           return "fstp\t%y0";
3884         }
3885       else
3886         {
3887           if (eflags_p == 2)
3888             {
3889               if (unordered_p)
3890                 return "fucompp\n\tfnstsw\t%0";
3891               else
3892                 return "fcompp\n\tfnstsw\t%0";
3893             }
3894           else
3895             {
3896               if (unordered_p)
3897                 return "fucompp";
3898               else
3899                 return "fcompp";
3900             }
3901         }
3902     }
3903   else
3904     {
3905       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
3906
3907       static const char * const alt[24] = 
3908       {
3909         "fcom%z1\t%y1",
3910         "fcomp%z1\t%y1",
3911         "fucom%z1\t%y1",
3912         "fucomp%z1\t%y1",
3913         
3914         "ficom%z1\t%y1",
3915         "ficomp%z1\t%y1",
3916         NULL,
3917         NULL,
3918
3919         "fcomi\t{%y1, %0|%0, %y1}",
3920         "fcomip\t{%y1, %0|%0, %y1}",
3921         "fucomi\t{%y1, %0|%0, %y1}",
3922         "fucomip\t{%y1, %0|%0, %y1}",
3923
3924         NULL,
3925         NULL,
3926         NULL,
3927         NULL,
3928
3929         "fcom%z2\t%y2\n\tfnstsw\t%0",
3930         "fcomp%z2\t%y2\n\tfnstsw\t%0",
3931         "fucom%z2\t%y2\n\tfnstsw\t%0",
3932         "fucomp%z2\t%y2\n\tfnstsw\t%0",
3933         
3934         "ficom%z2\t%y2\n\tfnstsw\t%0",
3935         "ficomp%z2\t%y2\n\tfnstsw\t%0",
3936         NULL,
3937         NULL
3938       };
3939
3940       int mask;
3941       const char *ret;
3942
3943       mask  = eflags_p << 3;
3944       mask |= (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT) << 2;
3945       mask |= unordered_p << 1;
3946       mask |= stack_top_dies;
3947
3948       if (mask >= 24)
3949         abort ();
3950       ret = alt[mask];
3951       if (ret == NULL)
3952         abort ();
3953
3954       return ret;
3955     }
3956 }
3957
3958 /* Output assembler code to FILE to initialize basic-block profiling.
3959
3960    If profile_block_flag == 2
3961
3962         Output code to call the subroutine `__bb_init_trace_func'
3963         and pass two parameters to it. The first parameter is
3964         the address of a block allocated in the object module.
3965         The second parameter is the number of the first basic block
3966         of the function.
3967
3968         The name of the block is a local symbol made with this statement:
3969         
3970             ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 0);
3971
3972         Of course, since you are writing the definition of
3973         `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you
3974         can take a short cut in the definition of this macro and use the
3975         name that you know will result.
3976
3977         The number of the first basic block of the function is
3978         passed to the macro in BLOCK_OR_LABEL.
3979
3980         If described in a virtual assembler language the code to be
3981         output looks like:
3982
3983                 parameter1 <- LPBX0
3984                 parameter2 <- BLOCK_OR_LABEL
3985                 call __bb_init_trace_func
3986
3987     else if profile_block_flag != 0
3988
3989         Output code to call the subroutine `__bb_init_func'
3990         and pass one single parameter to it, which is the same
3991         as the first parameter to `__bb_init_trace_func'.
3992
3993         The first word of this parameter is a flag which will be nonzero if
3994         the object module has already been initialized.  So test this word
3995         first, and do not call `__bb_init_func' if the flag is nonzero.
3996         Note: When profile_block_flag == 2 the test need not be done
3997         but `__bb_init_trace_func' *must* be called.
3998
3999         BLOCK_OR_LABEL may be used to generate a label number as a
4000         branch destination in case `__bb_init_func' will not be called.
4001
4002         If described in a virtual assembler language the code to be
4003         output looks like:
4004
4005                 cmp (LPBX0),0
4006                 jne local_label
4007                 parameter1 <- LPBX0
4008                 call __bb_init_func
4009               local_label:
4010 */
4011
4012 void
4013 ix86_output_function_block_profiler (file, block_or_label)
4014      FILE *file;
4015      int block_or_label;
4016 {
4017   static int num_func = 0;
4018   rtx xops[8];
4019   char block_table[80], false_label[80];
4020
4021   ASM_GENERATE_INTERNAL_LABEL (block_table, "LPBX", 0);
4022
4023   xops[1] = gen_rtx_SYMBOL_REF (VOIDmode, block_table);
4024   xops[5] = stack_pointer_rtx;
4025   xops[7] = gen_rtx_REG (Pmode, 0); /* eax */
4026
4027   CONSTANT_POOL_ADDRESS_P (xops[1]) = TRUE;
4028
4029   switch (profile_block_flag)
4030     {
4031     case 2:
4032       xops[2] = GEN_INT (block_or_label);
4033       xops[3] = gen_rtx_MEM (Pmode,
4034                      gen_rtx_SYMBOL_REF (VOIDmode, "__bb_init_trace_func"));
4035       xops[6] = GEN_INT (8);
4036
4037       output_asm_insn ("push{l}\t%2", xops);
4038       if (!flag_pic)
4039         output_asm_insn ("push{l}\t%1", xops);
4040       else
4041         {
4042           output_asm_insn ("lea{l}\t{%a1, %7|%7, %a1}", xops);
4043           output_asm_insn ("push{l}\t%7", xops);
4044         }
4045       output_asm_insn ("call\t%P3", xops);
4046       output_asm_insn ("add{l}\t{%6, %5|%5, %6}", xops);
4047       break;
4048
4049     default:
4050       ASM_GENERATE_INTERNAL_LABEL (false_label, "LPBZ", num_func);
4051
4052       xops[0] = const0_rtx;
4053       xops[2] = gen_rtx_MEM (Pmode,
4054                              gen_rtx_SYMBOL_REF (VOIDmode, false_label));
4055       xops[3] = gen_rtx_MEM (Pmode,
4056                              gen_rtx_SYMBOL_REF (VOIDmode, "__bb_init_func"));
4057       xops[4] = gen_rtx_MEM (Pmode, xops[1]);
4058       xops[6] = GEN_INT (4);
4059
4060       CONSTANT_POOL_ADDRESS_P (xops[2]) = TRUE;
4061
4062       output_asm_insn ("cmp{l}\t{%0, %4|%4, %0}", xops);
4063       output_asm_insn ("jne\t%2", xops);
4064
4065       if (!flag_pic)
4066         output_asm_insn ("push{l}\t%1", xops);
4067       else
4068         {
4069           output_asm_insn ("lea{l}\t{%a1, %7|%7, %a2}", xops);
4070           output_asm_insn ("push{l}\t%7", xops);
4071         }
4072       output_asm_insn ("call\t%P3", xops);
4073       output_asm_insn ("add{l}\t{%6, %5|%5, %6}", xops);
4074       ASM_OUTPUT_INTERNAL_LABEL (file, "LPBZ", num_func);
4075       num_func++;
4076       break;
4077     }
4078 }
4079
4080 /* Output assembler code to FILE to increment a counter associated
4081    with basic block number BLOCKNO.
4082
4083    If profile_block_flag == 2
4084
4085         Output code to initialize the global structure `__bb' and
4086         call the function `__bb_trace_func' which will increment the
4087         counter.
4088
4089         `__bb' consists of two words. In the first word the number
4090         of the basic block has to be stored. In the second word
4091         the address of a block allocated in the object module 
4092         has to be stored.
4093
4094         The basic block number is given by BLOCKNO.
4095
4096         The address of the block is given by the label created with 
4097
4098             ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 0);
4099
4100         by FUNCTION_BLOCK_PROFILER.
4101
4102         Of course, since you are writing the definition of
4103         `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you
4104         can take a short cut in the definition of this macro and use the
4105         name that you know will result.
4106
4107         If described in a virtual assembler language the code to be
4108         output looks like:
4109
4110                 move BLOCKNO -> (__bb)
4111                 move LPBX0 -> (__bb+4)
4112                 call __bb_trace_func
4113
4114         Note that function `__bb_trace_func' must not change the
4115         machine state, especially the flag register. To grant
4116         this, you must output code to save and restore registers
4117         either in this macro or in the macros MACHINE_STATE_SAVE
4118         and MACHINE_STATE_RESTORE. The last two macros will be
4119         used in the function `__bb_trace_func', so you must make
4120         sure that the function prologue does not change any 
4121         register prior to saving it with MACHINE_STATE_SAVE.
4122
4123    else if profile_block_flag != 0
4124
4125         Output code to increment the counter directly.
4126         Basic blocks are numbered separately from zero within each
4127         compiled object module. The count associated with block number
4128         BLOCKNO is at index BLOCKNO in an array of words; the name of 
4129         this array is a local symbol made with this statement:
4130
4131             ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 2);
4132
4133         Of course, since you are writing the definition of
4134         `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you
4135         can take a short cut in the definition of this macro and use the
4136         name that you know will result. 
4137
4138         If described in a virtual assembler language the code to be
4139         output looks like:
4140
4141                 inc (LPBX2+4*BLOCKNO)
4142 */
4143
4144 void
4145 ix86_output_block_profiler (file, blockno)
4146      FILE *file ATTRIBUTE_UNUSED;
4147      int blockno;
4148 {
4149   rtx xops[8], cnt_rtx;
4150   char counts[80];
4151   char *block_table = counts;
4152
4153   switch (profile_block_flag)
4154     {
4155     case 2:
4156       ASM_GENERATE_INTERNAL_LABEL (block_table, "LPBX", 0);
4157
4158       xops[1] = gen_rtx_SYMBOL_REF (VOIDmode, block_table);
4159       xops[2] = GEN_INT (blockno);
4160       xops[3] = gen_rtx_MEM (Pmode,
4161                              gen_rtx_SYMBOL_REF (VOIDmode, "__bb_trace_func"));
4162       xops[4] = gen_rtx_SYMBOL_REF (VOIDmode, "__bb");
4163       xops[5] = plus_constant (xops[4], 4);
4164       xops[0] = gen_rtx_MEM (SImode, xops[4]);
4165       xops[6] = gen_rtx_MEM (SImode, xops[5]);
4166
4167       CONSTANT_POOL_ADDRESS_P (xops[1]) = TRUE;
4168
4169       output_asm_insn ("pushf", xops);
4170       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
4171       if (flag_pic)
4172         {
4173           xops[7] = gen_rtx_REG (Pmode, 0); /* eax */
4174           output_asm_insn ("push{l}\t%7", xops);
4175           output_asm_insn ("lea{l}\t{%a1, %7|%7, %a1}", xops);
4176           output_asm_insn ("mov{l}\t{%7, %6|%6, %7}", xops);
4177           output_asm_insn ("pop{l}\t%7", xops);
4178         }
4179       else
4180         output_asm_insn ("mov{l}\t{%1, %6|%6, %1}", xops);
4181       output_asm_insn ("call\t%P3", xops);
4182       output_asm_insn ("popf", xops);
4183
4184       break;
4185
4186     default:
4187       ASM_GENERATE_INTERNAL_LABEL (counts, "LPBX", 2);
4188       cnt_rtx = gen_rtx_SYMBOL_REF (VOIDmode, counts);
4189       SYMBOL_REF_FLAG (cnt_rtx) = TRUE;
4190
4191       if (blockno)
4192         cnt_rtx = plus_constant (cnt_rtx, blockno*4);
4193
4194       if (flag_pic)
4195         cnt_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, cnt_rtx);
4196
4197       xops[0] = gen_rtx_MEM (SImode, cnt_rtx);
4198       output_asm_insn ("inc{l}\t%0", xops);
4199
4200       break;
4201     }
4202 }
4203 \f
4204 void
4205 ix86_expand_move (mode, operands)
4206      enum machine_mode mode;
4207      rtx operands[];
4208 {
4209   int strict = (reload_in_progress || reload_completed);
4210   rtx insn;
4211
4212   if (flag_pic && mode == Pmode && symbolic_operand (operands[1], Pmode))
4213     {
4214       /* Emit insns to move operands[1] into operands[0].  */
4215
4216       if (GET_CODE (operands[0]) == MEM)
4217         operands[1] = force_reg (Pmode, operands[1]);
4218       else
4219         {
4220           rtx temp = operands[0];
4221           if (GET_CODE (temp) != REG)
4222             temp = gen_reg_rtx (Pmode);
4223           temp = legitimize_pic_address (operands[1], temp);
4224           if (temp == operands[0])
4225             return;
4226           operands[1] = temp;
4227         }
4228     }
4229   else
4230     {
4231       if (GET_CODE (operands[0]) == MEM
4232           && (GET_MODE (operands[0]) == QImode
4233               || !push_operand (operands[0], mode))
4234           && GET_CODE (operands[1]) == MEM)
4235         operands[1] = force_reg (mode, operands[1]);
4236
4237       if (push_operand (operands[0], mode)
4238           && ! general_no_elim_operand (operands[1], mode))
4239         operands[1] = copy_to_mode_reg (mode, operands[1]);
4240
4241       if (FLOAT_MODE_P (mode))
4242         {
4243           /* If we are loading a floating point constant to a register,
4244              force the value to memory now, since we'll get better code
4245              out the back end.  */
4246
4247           if (strict)
4248             ;
4249           else if (GET_CODE (operands[1]) == CONST_DOUBLE
4250                    && register_operand (operands[0], mode))
4251             operands[1] = validize_mem (force_const_mem (mode, operands[1]));
4252         }
4253     }
4254
4255   insn = gen_rtx_SET (VOIDmode, operands[0], operands[1]);
4256
4257   emit_insn (insn);
4258 }
4259
4260 /* Attempt to expand a binary operator.  Make the expansion closer to the
4261    actual machine, then just general_operand, which will allow 3 separate
4262    memory references (one output, two input) in a single insn.  */
4263
4264 void
4265 ix86_expand_binary_operator (code, mode, operands)
4266      enum rtx_code code;
4267      enum machine_mode mode;
4268      rtx operands[];
4269 {
4270   int matching_memory;
4271   rtx src1, src2, dst, op, clob;
4272
4273   dst = operands[0];
4274   src1 = operands[1];
4275   src2 = operands[2];
4276
4277   /* Recognize <var1> = <value> <op> <var1> for commutative operators */
4278   if (GET_RTX_CLASS (code) == 'c'
4279       && (rtx_equal_p (dst, src2)
4280           || immediate_operand (src1, mode)))
4281     {
4282       rtx temp = src1;
4283       src1 = src2;
4284       src2 = temp;
4285     }
4286
4287   /* If the destination is memory, and we do not have matching source
4288      operands, do things in registers.  */
4289   matching_memory = 0;
4290   if (GET_CODE (dst) == MEM)
4291     {
4292       if (rtx_equal_p (dst, src1))
4293         matching_memory = 1;
4294       else if (GET_RTX_CLASS (code) == 'c'
4295                && rtx_equal_p (dst, src2))
4296         matching_memory = 2;
4297       else
4298         dst = gen_reg_rtx (mode);
4299     }
4300   
4301   /* Both source operands cannot be in memory.  */
4302   if (GET_CODE (src1) == MEM && GET_CODE (src2) == MEM)
4303     {
4304       if (matching_memory != 2)
4305         src2 = force_reg (mode, src2);
4306       else
4307         src1 = force_reg (mode, src1);
4308     }
4309
4310   /* If the operation is not commutable, source 1 cannot be a constant
4311      or non-matching memory.  */
4312   if ((CONSTANT_P (src1) 
4313        || (!matching_memory && GET_CODE (src1) == MEM))
4314       && GET_RTX_CLASS (code) != 'c')
4315     src1 = force_reg (mode, src1);
4316     
4317   /* If optimizing, copy to regs to improve CSE */
4318   if (optimize && ! no_new_pseudos)
4319     {
4320       if (GET_CODE (dst) == MEM)
4321         dst = gen_reg_rtx (mode);
4322       if (GET_CODE (src1) == MEM)
4323         src1 = force_reg (mode, src1);
4324       if (GET_CODE (src2) == MEM)
4325         src2 = force_reg (mode, src2);
4326     }
4327
4328   /* Emit the instruction.  */
4329
4330   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
4331   if (reload_in_progress)
4332     {
4333       /* Reload doesn't know about the flags register, and doesn't know that
4334          it doesn't want to clobber it.  We can only do this with PLUS.  */
4335       if (code != PLUS)
4336         abort ();
4337       emit_insn (op);
4338     }
4339   else
4340     {
4341       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
4342       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
4343     }
4344
4345   /* Fix up the destination if needed.  */
4346   if (dst != operands[0])
4347     emit_move_insn (operands[0], dst);
4348 }
4349
4350 /* Return TRUE or FALSE depending on whether the binary operator meets the
4351    appropriate constraints.  */
4352
4353 int
4354 ix86_binary_operator_ok (code, mode, operands)
4355      enum rtx_code code;
4356      enum machine_mode mode ATTRIBUTE_UNUSED;
4357      rtx operands[3];
4358 {
4359   /* Both source operands cannot be in memory.  */
4360   if (GET_CODE (operands[1]) == MEM && GET_CODE (operands[2]) == MEM)
4361     return 0;
4362   /* If the operation is not commutable, source 1 cannot be a constant.  */
4363   if (CONSTANT_P (operands[1]) && GET_RTX_CLASS (code) != 'c')
4364     return 0;
4365   /* If the destination is memory, we must have a matching source operand.  */
4366   if (GET_CODE (operands[0]) == MEM
4367       && ! (rtx_equal_p (operands[0], operands[1])
4368             || (GET_RTX_CLASS (code) == 'c'
4369                 && rtx_equal_p (operands[0], operands[2]))))
4370     return 0;
4371   /* If the operation is not commutable and the source 1 is memory, we must
4372      have a matching destionation.  */
4373   if (GET_CODE (operands[1]) == MEM
4374       && GET_RTX_CLASS (code) != 'c'
4375       && ! rtx_equal_p (operands[0], operands[1]))
4376     return 0;
4377   return 1;
4378 }
4379
4380 /* Attempt to expand a unary operator.  Make the expansion closer to the
4381    actual machine, then just general_operand, which will allow 2 separate
4382    memory references (one output, one input) in a single insn.  */
4383
4384 void
4385 ix86_expand_unary_operator (code, mode, operands)
4386      enum rtx_code code;
4387      enum machine_mode mode;
4388      rtx operands[];
4389 {
4390   int matching_memory;
4391   rtx src, dst, op, clob;
4392
4393   dst = operands[0];
4394   src = operands[1];
4395
4396   /* If the destination is memory, and we do not have matching source
4397      operands, do things in registers.  */
4398   matching_memory = 0;
4399   if (GET_CODE (dst) == MEM)
4400     {
4401       if (rtx_equal_p (dst, src))
4402         matching_memory = 1;
4403       else
4404         dst = gen_reg_rtx (mode);
4405     }
4406
4407   /* When source operand is memory, destination must match.  */
4408   if (!matching_memory && GET_CODE (src) == MEM)
4409     src = force_reg (mode, src);
4410   
4411   /* If optimizing, copy to regs to improve CSE */
4412   if (optimize && ! no_new_pseudos)
4413     {
4414       if (GET_CODE (dst) == MEM)
4415         dst = gen_reg_rtx (mode);
4416       if (GET_CODE (src) == MEM)
4417         src = force_reg (mode, src);
4418     }
4419
4420   /* Emit the instruction.  */
4421
4422   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
4423   if (reload_in_progress || code == NOT)
4424     {
4425       /* Reload doesn't know about the flags register, and doesn't know that
4426          it doesn't want to clobber it.  */
4427       if (code != NOT)
4428         abort ();
4429       emit_insn (op);
4430     }
4431   else
4432     {
4433       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
4434       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
4435     }
4436
4437   /* Fix up the destination if needed.  */
4438   if (dst != operands[0])
4439     emit_move_insn (operands[0], dst);
4440 }
4441
4442 /* Return TRUE or FALSE depending on whether the unary operator meets the
4443    appropriate constraints.  */
4444
4445 int
4446 ix86_unary_operator_ok (code, mode, operands)
4447      enum rtx_code code ATTRIBUTE_UNUSED;
4448      enum machine_mode mode ATTRIBUTE_UNUSED;
4449      rtx operands[2] ATTRIBUTE_UNUSED;
4450 {
4451   /* If one of operands is memory, source and destination must match.  */
4452   if ((GET_CODE (operands[0]) == MEM
4453        || GET_CODE (operands[1]) == MEM)
4454       && ! rtx_equal_p (operands[0], operands[1]))
4455     return FALSE;
4456   return TRUE;
4457 }
4458
4459 /* Return TRUE or FALSE depending on whether the first SET in INSN
4460    has source and destination with matching CC modes, and that the
4461    CC mode is at least as constrained as REQ_MODE.  */
4462
4463 int
4464 ix86_match_ccmode (insn, req_mode)
4465      rtx insn;
4466      enum machine_mode req_mode;
4467 {
4468   rtx set;
4469   enum machine_mode set_mode;
4470
4471   set = PATTERN (insn);
4472   if (GET_CODE (set) == PARALLEL)
4473     set = XVECEXP (set, 0, 0);
4474   if (GET_CODE (set) != SET)
4475     abort ();
4476
4477   set_mode = GET_MODE (SET_DEST (set));
4478   switch (set_mode)
4479     {
4480     case CCmode:
4481       if (req_mode == CCNOmode)
4482         return 0;
4483       /* FALLTHRU */
4484     case CCNOmode:
4485       if (req_mode == CCZmode)
4486         return 0;
4487       /* FALLTHRU */
4488     case CCZmode:
4489       break;
4490
4491     default:
4492       abort ();
4493     }
4494
4495   return (GET_MODE (SET_SRC (set)) == set_mode);
4496 }
4497
4498 /* Produce an unsigned comparison for a given signed comparison.  */
4499
4500 static enum rtx_code
4501 unsigned_comparison (code)
4502      enum rtx_code code;
4503 {
4504   switch (code)
4505     {
4506     case GT:
4507       code = GTU;
4508       break;
4509     case LT:
4510       code = LTU;
4511       break;
4512     case GE:
4513       code = GEU;
4514       break;
4515     case LE:
4516       code = LEU;
4517       break;
4518     case EQ:
4519     case NE:
4520     case LEU:
4521     case LTU:
4522     case GEU:
4523     case GTU:
4524     case UNORDERED:
4525     case ORDERED:
4526       break;
4527     default:
4528       abort ();
4529     }
4530   return code;
4531 }
4532
4533 /* Generate insn patterns to do an integer compare of OPERANDS.  */
4534
4535 static rtx
4536 ix86_expand_int_compare (code, op0, op1)
4537      enum rtx_code code;
4538      rtx op0, op1;
4539 {
4540   enum machine_mode cmpmode;
4541   rtx tmp, flags;
4542
4543   cmpmode = SELECT_CC_MODE (code, op0, op1);
4544   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
4545
4546   /* This is very simple, but making the interface the same as in the
4547      FP case makes the rest of the code easier.  */
4548   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
4549   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
4550
4551   /* Return the test that should be put into the flags user, i.e.
4552      the bcc, scc, or cmov instruction.  */
4553   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
4554 }
4555
4556 /* Figure out whether to use ordered or unordered fp comparisons.
4557    Return the appropriate mode to use.  */
4558
4559 static enum machine_mode
4560 ix86_fp_compare_mode (code)
4561      enum rtx_code code;
4562 {
4563   int unordered;
4564
4565   switch (code)
4566     {
4567     case NE: case EQ:
4568       /* When not doing IEEE compliant compares, fault on NaNs.  */
4569       unordered = (TARGET_IEEE_FP != 0);
4570       break;
4571
4572     case LT: case LE: case GT: case GE:
4573       unordered = 0;
4574       break;
4575
4576     case UNORDERED: case ORDERED:
4577     case UNEQ: case UNGE: case UNGT: case UNLE: case UNLT: case LTGT:
4578       unordered = 1;
4579       break;
4580
4581     default:
4582       abort ();
4583     }
4584
4585   /* ??? If we knew whether invalid-operand exceptions were masked,
4586      we could rely on fcom to raise an exception and take care of
4587      NaNs.  But we don't.  We could know this from c99 math pragmas.  */
4588   if (TARGET_IEEE_FP)
4589     unordered = 1;
4590
4591   return unordered ? CCFPUmode : CCFPmode;
4592 }
4593
4594 /* Return true if we should use an FCOMI instruction for this fp comparison.  */
4595
4596 int
4597 ix86_use_fcomi_compare (code)
4598      enum rtx_code code;
4599 {
4600   return (TARGET_CMOVE
4601           && (code == ORDERED || code == UNORDERED
4602               /* All other unordered compares require checking
4603                  multiple sets of bits.  */
4604               || ix86_fp_compare_mode (code) == CCFPmode));
4605 }
4606
4607 /* Swap, force into registers, or otherwise massage the two operands 
4608    to a fp comparison.  The operands are updated in place; the new
4609    comparsion code is returned.  */
4610
4611 static enum rtx_code
4612 ix86_prepare_fp_compare_args (code, pop0, pop1)
4613      enum rtx_code code;
4614      rtx *pop0, *pop1;
4615 {
4616   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
4617   rtx op0 = *pop0, op1 = *pop1;
4618   enum machine_mode op_mode = GET_MODE (op0);
4619
4620   /* All of the unordered compare instructions only work on registers.
4621      The same is true of the XFmode compare instructions.  The same is
4622      true of the fcomi compare instructions.  */
4623
4624   if (fpcmp_mode == CCFPUmode
4625       || op_mode == XFmode
4626       || ix86_use_fcomi_compare (code))
4627     {
4628       op0 = force_reg (op_mode, op0);
4629       op1 = force_reg (op_mode, op1);
4630     }
4631   else
4632     {
4633       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
4634          things around if they appear profitable, otherwise force op0
4635          into a register.  */
4636
4637       if (standard_80387_constant_p (op0) == 0
4638           || (GET_CODE (op0) == MEM
4639               && ! (standard_80387_constant_p (op1) == 0
4640                     || GET_CODE (op1) == MEM)))
4641         {
4642           rtx tmp;
4643           tmp = op0, op0 = op1, op1 = tmp;
4644           code = swap_condition (code);
4645         }
4646
4647       if (GET_CODE (op0) != REG)
4648         op0 = force_reg (op_mode, op0);
4649
4650       if (CONSTANT_P (op1))
4651         {
4652           if (standard_80387_constant_p (op1))
4653             op1 = force_reg (op_mode, op1);
4654           else
4655             op1 = validize_mem (force_const_mem (op_mode, op1));
4656         }
4657     }
4658
4659   *pop0 = op0;
4660   *pop1 = op1;
4661   return code;
4662 }
4663
4664 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
4665
4666 rtx
4667 ix86_expand_fp_compare (code, op0, op1, scratch)
4668      enum rtx_code code;
4669      rtx op0, op1, scratch;
4670 {
4671   enum machine_mode fpcmp_mode, intcmp_mode;
4672   rtx tmp;
4673
4674   fpcmp_mode = ix86_fp_compare_mode (code);
4675   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
4676
4677   /* %%% fcomi is probably always faster, even when dealing with memory,
4678      since compare-and-branch would be three insns instead of four.  */
4679   if (ix86_use_fcomi_compare (code))
4680     {
4681       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
4682       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG), tmp);
4683       emit_insn (tmp);
4684
4685       /* The FP codes work out to act like unsigned.  */
4686       code = unsigned_comparison (code);
4687       intcmp_mode = CCmode;
4688     }
4689   else
4690     {
4691       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
4692
4693       rtx tmp2;
4694       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
4695       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), 9);
4696       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
4697
4698       if (fpcmp_mode == CCFPmode
4699           || code == ORDERED
4700           || code == UNORDERED)
4701         {
4702           /* We have two options here -- use sahf, or testing bits of ah
4703              directly.  On PPRO, they are equivalent, sahf being one byte
4704              smaller.  On Pentium, sahf is non-pairable while test is UV
4705              pairable.  */
4706
4707           if (TARGET_USE_SAHF || optimize_size)
4708             {
4709             do_sahf:
4710               emit_insn (gen_x86_sahf_1 (scratch));
4711
4712               /* The FP codes work out to act like unsigned.  */
4713               code = unsigned_comparison (code);
4714               intcmp_mode = CCmode;
4715             }
4716           else
4717             {
4718               /*
4719                * The numbers below correspond to the bits of the FPSW in AH.
4720                * C3, C2, and C0 are in bits 0x40, 0x4, and 0x01 respectively.
4721                *
4722                *    cmp    C3 C2 C0
4723                *    >      0  0  0
4724                *    <      0  0  1
4725                *    =      1  0  0
4726                *    un     1  1  1
4727                */
4728
4729               int mask;
4730
4731               switch (code)
4732                 {
4733                 case GT:
4734                   mask = 0x41;
4735                   code = EQ;
4736                   break;
4737                 case LT:
4738                   mask = 0x01;
4739                   code = NE;
4740                   break;
4741                 case GE:
4742                   /* We'd have to use `xorb 1,ah; andb 0x41,ah', so it's 
4743                      faster in all cases to just fall back on sahf. */
4744                   goto do_sahf;
4745                 case LE:
4746                   mask = 0x41;
4747                   code = NE;
4748                   break;
4749                 case EQ:
4750                   mask = 0x40;
4751                   code = NE;
4752                   break;
4753                 case NE:
4754                   mask = 0x40;
4755                   code = EQ;
4756                   break;
4757                 case UNORDERED:
4758                   mask = 0x04;
4759                   code = NE;
4760                   break;
4761                 case ORDERED:
4762                   mask = 0x04;
4763                   code = EQ;
4764                   break;
4765
4766                 default:
4767                   abort ();
4768                 }
4769
4770               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (mask)));
4771               intcmp_mode = CCNOmode;
4772             }
4773         }
4774       else
4775         {
4776           /* In the unordered case, we have to check C2 for NaN's, which
4777              doesn't happen to work out to anything nice combination-wise.
4778              So do some bit twiddling on the value we've got in AH to come
4779              up with an appropriate set of condition codes.  */
4780
4781           intcmp_mode = CCNOmode;
4782           switch (code)
4783             {
4784             case GT:
4785               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
4786               code = EQ;
4787               break;
4788             case LT:
4789               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
4790               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x01)));
4791               intcmp_mode = CCmode;
4792               code = EQ;
4793               break;
4794             case GE:
4795               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
4796               code = EQ;
4797               break;
4798             case LE:
4799               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
4800               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
4801               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
4802               intcmp_mode = CCmode;
4803               code = LTU;
4804               break;
4805             case EQ:
4806               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
4807               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
4808               intcmp_mode = CCmode;
4809               code = EQ;
4810               break;
4811             case NE:
4812               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
4813               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch, GEN_INT (0x40)));
4814               code = NE;
4815               break;
4816
4817             case UNORDERED:
4818               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
4819               code = NE;
4820               break;
4821             case ORDERED:
4822               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
4823               code = EQ;
4824               break;
4825             case UNEQ:
4826               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
4827               code = NE;
4828               break;
4829             case UNGE:
4830               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
4831               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch, GEN_INT (0x01)));
4832               code = NE;
4833               break;
4834             case UNGT:
4835               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
4836               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
4837               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
4838               code = GEU;
4839               break;
4840             case UNLE:
4841               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
4842               code = NE;
4843               break;
4844             case UNLT:
4845               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x01)));
4846               code = NE;
4847               break;
4848             case LTGT:
4849               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
4850               code = EQ;
4851               break;
4852
4853             default:
4854               abort ();
4855             }
4856         }
4857     }
4858
4859   /* Return the test that should be put into the flags user, i.e.
4860      the bcc, scc, or cmov instruction.  */
4861   return gen_rtx_fmt_ee (code, VOIDmode,
4862                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
4863                          const0_rtx);
4864 }
4865
4866 static rtx
4867 ix86_expand_compare (code)
4868      enum rtx_code code;
4869 {
4870   rtx op0, op1, ret;
4871   op0 = ix86_compare_op0;
4872   op1 = ix86_compare_op1;
4873
4874   if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_FLOAT)
4875     ret = ix86_expand_fp_compare (code, op0, op1, gen_reg_rtx (HImode));
4876   else
4877     ret = ix86_expand_int_compare (code, op0, op1);
4878
4879   return ret;
4880 }
4881
4882 void
4883 ix86_expand_branch (code, label)
4884      enum rtx_code code;
4885      rtx label;
4886 {
4887   rtx tmp;
4888
4889   switch (GET_MODE (ix86_compare_op0))
4890     {
4891     case QImode:
4892     case HImode:
4893     case SImode:
4894       tmp = ix86_expand_compare (code);
4895       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
4896                                   gen_rtx_LABEL_REF (VOIDmode, label),
4897                                   pc_rtx);
4898       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
4899       return;
4900
4901     case SFmode:
4902     case DFmode:
4903     case XFmode:   
4904       /* Don't expand the comparison early, so that we get better code
4905          when jump or whoever decides to reverse the comparison.  */
4906       {
4907         rtvec vec;
4908         int use_fcomi;
4909
4910         code = ix86_prepare_fp_compare_args (code, &ix86_compare_op0,
4911                                              &ix86_compare_op1);
4912
4913         tmp = gen_rtx_fmt_ee (code, VOIDmode,
4914                               ix86_compare_op0, ix86_compare_op1);
4915         tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
4916                                     gen_rtx_LABEL_REF (VOIDmode, label),
4917                                     pc_rtx);
4918         tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
4919
4920         use_fcomi = ix86_use_fcomi_compare (code);
4921         vec = rtvec_alloc (3 + !use_fcomi);
4922         RTVEC_ELT (vec, 0) = tmp;
4923         RTVEC_ELT (vec, 1)
4924           = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, 18));
4925         RTVEC_ELT (vec, 2)
4926           = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, 17));
4927         if (! use_fcomi)
4928           RTVEC_ELT (vec, 3)
4929             = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (HImode));
4930
4931         emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, vec));
4932         return;
4933       }
4934
4935     case DImode:
4936       /* Expand DImode branch into multiple compare+branch.  */
4937       {
4938         rtx lo[2], hi[2], label2;
4939         enum rtx_code code1, code2, code3;
4940
4941         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
4942           {
4943             tmp = ix86_compare_op0;
4944             ix86_compare_op0 = ix86_compare_op1;
4945             ix86_compare_op1 = tmp;
4946             code = swap_condition (code);
4947           }
4948         split_di (&ix86_compare_op0, 1, lo+0, hi+0);
4949         split_di (&ix86_compare_op1, 1, lo+1, hi+1);
4950
4951         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
4952            avoid two branches.  This costs one extra insn, so disable when
4953            optimizing for size.  */
4954
4955         if ((code == EQ || code == NE)
4956             && (!optimize_size
4957                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
4958           {
4959             rtx xor0, xor1;
4960
4961             xor1 = hi[0];
4962             if (hi[1] != const0_rtx)
4963               xor1 = expand_binop (SImode, xor_optab, xor1, hi[1],
4964                                    NULL_RTX, 0, OPTAB_WIDEN);
4965
4966             xor0 = lo[0];
4967             if (lo[1] != const0_rtx)
4968               xor0 = expand_binop (SImode, xor_optab, xor0, lo[1],
4969                                    NULL_RTX, 0, OPTAB_WIDEN);
4970
4971             tmp = expand_binop (SImode, ior_optab, xor1, xor0,
4972                                 NULL_RTX, 0, OPTAB_WIDEN);
4973
4974             ix86_compare_op0 = tmp;
4975             ix86_compare_op1 = const0_rtx;
4976             ix86_expand_branch (code, label);
4977             return;
4978           }
4979
4980         /* Otherwise, if we are doing less-than or greater-or-equal-than,
4981            op1 is a constant and the low word is zero, then we can just
4982            examine the high word.  */
4983
4984         if (GET_CODE (hi[1]) == CONST_INT && lo[1] == const0_rtx)
4985           switch (code)
4986             {
4987             case LT: case LTU: case GE: case GEU:
4988               ix86_compare_op0 = hi[0];
4989               ix86_compare_op1 = hi[1];
4990               ix86_expand_branch (code, label);
4991               return;
4992             default:
4993               break;
4994             }
4995
4996         /* Otherwise, we need two or three jumps.  */
4997
4998         label2 = gen_label_rtx ();
4999
5000         code1 = code;
5001         code2 = swap_condition (code);
5002         code3 = unsigned_condition (code);
5003
5004         switch (code)
5005           {
5006           case LT: case GT: case LTU: case GTU:
5007             break;
5008
5009           case LE:   code1 = LT;  code2 = GT;  break;
5010           case GE:   code1 = GT;  code2 = LT;  break;
5011           case LEU:  code1 = LTU; code2 = GTU; break;
5012           case GEU:  code1 = GTU; code2 = LTU; break;
5013
5014           case EQ:   code1 = NIL; code2 = NE;  break;
5015           case NE:   code2 = NIL; break;
5016
5017           default:
5018             abort ();
5019           }
5020
5021         /*
5022          * a < b =>
5023          *    if (hi(a) < hi(b)) goto true;
5024          *    if (hi(a) > hi(b)) goto false;
5025          *    if (lo(a) < lo(b)) goto true;
5026          *  false:
5027          */
5028
5029         ix86_compare_op0 = hi[0];
5030         ix86_compare_op1 = hi[1];
5031
5032         if (code1 != NIL)
5033           ix86_expand_branch (code1, label);
5034         if (code2 != NIL)
5035           ix86_expand_branch (code2, label2);
5036
5037         ix86_compare_op0 = lo[0];
5038         ix86_compare_op1 = lo[1];
5039         ix86_expand_branch (code3, label);
5040
5041         if (code2 != NIL)
5042           emit_label (label2);
5043         return;
5044       }
5045
5046     default:
5047       abort ();
5048     }
5049 }
5050
5051 int
5052 ix86_expand_setcc (code, dest)
5053      enum rtx_code code;
5054      rtx dest;
5055 {
5056   rtx ret, tmp;
5057   int type;
5058
5059   if (GET_MODE (ix86_compare_op0) == DImode)
5060     return 0; /* FAIL */
5061
5062   /* Three modes of generation:
5063      0 -- destination does not overlap compare sources:
5064           clear dest first, emit strict_low_part setcc.
5065      1 -- destination does overlap compare sources:
5066           emit subreg setcc, zero extend.
5067      2 -- destination is in QImode:
5068           emit setcc only.
5069   */
5070
5071   type = 0;
5072
5073   if (GET_MODE (dest) == QImode)
5074     type = 2;
5075   else if (reg_overlap_mentioned_p (dest, ix86_compare_op0)
5076            || reg_overlap_mentioned_p (dest, ix86_compare_op1))
5077     type = 1;
5078
5079   if (type == 0)
5080     emit_move_insn (dest, const0_rtx);
5081
5082   ret = ix86_expand_compare (code);
5083   PUT_MODE (ret, QImode);
5084
5085   tmp = dest;
5086   if (type == 0)
5087     {
5088       tmp = gen_lowpart (QImode, dest);
5089       tmp = gen_rtx_STRICT_LOW_PART (VOIDmode, tmp);
5090     }
5091   else if (type == 1)
5092     {
5093       if (!cse_not_expected)
5094         tmp = gen_reg_rtx (QImode);
5095       else
5096         tmp = gen_lowpart (QImode, dest);
5097     }
5098
5099   emit_insn (gen_rtx_SET (VOIDmode, tmp, ret));
5100
5101   if (type == 1)
5102     {
5103       rtx clob;
5104
5105       tmp = gen_rtx_ZERO_EXTEND (GET_MODE (dest), tmp);
5106       tmp = gen_rtx_SET (VOIDmode, dest, tmp);
5107       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
5108       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
5109       emit_insn (tmp);
5110     }
5111
5112   return 1; /* DONE */
5113 }
5114
5115 int
5116 ix86_expand_int_movcc (operands)
5117      rtx operands[];
5118 {
5119   enum rtx_code code = GET_CODE (operands[1]), compare_code;
5120   rtx compare_seq, compare_op;
5121
5122   /* When the compare code is not LTU or GEU, we can not use sbbl case.
5123      In case comparsion is done with immediate, we can convert it to LTU or
5124      GEU by altering the integer.  */
5125
5126   if ((code == LEU || code == GTU)
5127       && GET_CODE (ix86_compare_op1) == CONST_INT
5128       && GET_MODE (operands[0]) != HImode
5129       && (unsigned int)INTVAL (ix86_compare_op1) != 0xffffffff
5130       && GET_CODE (operands[2]) == CONST_INT 
5131       && GET_CODE (operands[3]) == CONST_INT)
5132     {
5133       if (code == LEU)
5134         code = LTU;
5135       else
5136         code = GEU;
5137       ix86_compare_op1 = GEN_INT (INTVAL (ix86_compare_op1) + 1);
5138     }
5139
5140   start_sequence ();
5141   compare_op = ix86_expand_compare (code);
5142   compare_seq = gen_sequence ();
5143   end_sequence ();
5144
5145   compare_code = GET_CODE (compare_op);
5146
5147   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
5148      HImode insns, we'd be swallowed in word prefix ops.  */
5149
5150   if (GET_MODE (operands[0]) != HImode
5151       && GET_CODE (operands[2]) == CONST_INT 
5152       && GET_CODE (operands[3]) == CONST_INT)
5153     {
5154       rtx out = operands[0];
5155       HOST_WIDE_INT ct = INTVAL (operands[2]);
5156       HOST_WIDE_INT cf = INTVAL (operands[3]);
5157       HOST_WIDE_INT diff;
5158
5159       if (compare_code == LTU || compare_code == GEU)
5160         {
5161
5162           /* Detect overlap between destination and compare sources.  */
5163           rtx tmp = out;
5164
5165           /* To simplify rest of code, restrict to the GEU case. */
5166           if (compare_code == LTU)
5167             {
5168               int tmp = ct;
5169               ct = cf;
5170               cf = tmp;
5171               compare_code = reverse_condition (compare_code);
5172               code = reverse_condition (code);
5173             }
5174           diff = ct - cf;
5175
5176           if (reg_overlap_mentioned_p (out, ix86_compare_op0)
5177               || reg_overlap_mentioned_p (out, ix86_compare_op1))
5178             tmp = gen_reg_rtx (SImode);
5179
5180           emit_insn (compare_seq);
5181           emit_insn (gen_x86_movsicc_0_m1 (tmp));
5182
5183           if (diff == 1)
5184             {
5185               /*
5186                * cmpl op0,op1
5187                * sbbl dest,dest
5188                * [addl dest, ct]
5189                *
5190                * Size 5 - 8.
5191                */
5192               if (ct)
5193                 emit_insn (gen_addsi3 (out, out, GEN_INT (ct)));
5194             }
5195           else if (cf == -1)
5196             {
5197               /*
5198                * cmpl op0,op1
5199                * sbbl dest,dest
5200                * orl $ct, dest
5201                *
5202                * Size 8.
5203                */
5204               emit_insn (gen_iorsi3 (out, out, GEN_INT (ct)));
5205             }
5206           else if (diff == -1 && ct)
5207             {
5208               /*
5209                * cmpl op0,op1
5210                * sbbl dest,dest
5211                * xorl $-1, dest
5212                * [addl dest, cf]
5213                *
5214                * Size 8 - 11.
5215                */
5216               emit_insn (gen_one_cmplsi2 (tmp, tmp));
5217               if (cf)
5218                 emit_insn (gen_addsi3 (out, out, GEN_INT (cf)));
5219             }
5220           else
5221             {
5222               /*
5223                * cmpl op0,op1
5224                * sbbl dest,dest
5225                * andl cf - ct, dest
5226                * [addl dest, ct]
5227                *
5228                * Size 8 - 11.
5229                */
5230               emit_insn (gen_andsi3 (out, out, GEN_INT (cf - ct)));
5231               if (ct)
5232                 emit_insn (gen_addsi3 (out, out, GEN_INT (ct)));
5233             }
5234
5235           if (tmp != out)
5236             emit_move_insn (out, tmp);
5237
5238           return 1; /* DONE */
5239         }
5240
5241       diff = ct - cf;
5242       if (diff < 0)
5243         {
5244           HOST_WIDE_INT tmp;
5245           tmp = ct, ct = cf, cf = tmp;
5246           diff = -diff;
5247           compare_code = reverse_condition (compare_code);
5248           code = reverse_condition (code);
5249         }
5250       if (diff == 1 || diff == 2 || diff == 4 || diff == 8
5251           || diff == 3 || diff == 5 || diff == 9)
5252         {
5253           /*
5254            * xorl dest,dest
5255            * cmpl op1,op2
5256            * setcc dest
5257            * lea cf(dest*(ct-cf)),dest
5258            *
5259            * Size 14.
5260            *
5261            * This also catches the degenerate setcc-only case.
5262            */
5263
5264           rtx tmp;
5265           int nops;
5266
5267           out = emit_store_flag (out, code, ix86_compare_op0,
5268                                  ix86_compare_op1, VOIDmode, 0, 1);
5269
5270           nops = 0;
5271           if (diff == 1)
5272               tmp = out;
5273           else
5274             {
5275               tmp = gen_rtx_MULT (SImode, out, GEN_INT (diff & ~1));
5276               nops++;
5277               if (diff & 1)
5278                 {
5279                   tmp = gen_rtx_PLUS (SImode, tmp, out);
5280                   nops++;
5281                 }
5282             }
5283           if (cf != 0)
5284             {
5285               tmp = gen_rtx_PLUS (SImode, tmp, GEN_INT (cf));
5286               nops++;
5287             }
5288           if (tmp != out)
5289             {
5290               if (nops == 0)
5291                 emit_move_insn (out, tmp);
5292               else if (nops == 1)
5293                 {
5294                   rtx clob;
5295
5296                   clob = gen_rtx_REG (CCmode, FLAGS_REG);
5297                   clob = gen_rtx_CLOBBER (VOIDmode, clob);
5298
5299                   tmp = gen_rtx_SET (VOIDmode, out, tmp);
5300                   tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
5301                   emit_insn (tmp);
5302                 }
5303               else
5304                 emit_insn (gen_rtx_SET (VOIDmode, out, tmp));
5305             }
5306           if (out != operands[0])
5307             emit_move_insn (operands[0], out);
5308
5309           return 1; /* DONE */
5310         }
5311
5312       /*
5313        * General case:                  Jumpful:
5314        *   xorl dest,dest               cmpl op1, op2
5315        *   cmpl op1, op2                movl ct, dest
5316        *   setcc dest                   jcc 1f
5317        *   decl dest                    movl cf, dest
5318        *   andl (cf-ct),dest            1:
5319        *   addl ct,dest
5320        * 
5321        * Size 20.                       Size 14.
5322        *
5323        * This is reasonably steep, but branch mispredict costs are
5324        * high on modern cpus, so consider failing only if optimizing
5325        * for space.
5326        *
5327        * %%% Parameterize branch_cost on the tuning architecture, then
5328        * use that.  The 80386 couldn't care less about mispredicts.
5329        */
5330
5331       if (!optimize_size && !TARGET_CMOVE)
5332         {
5333           if (ct == 0)
5334             {
5335               ct = cf;
5336               cf = 0;
5337               compare_code = reverse_condition (compare_code);
5338               code = reverse_condition (code);
5339             }
5340
5341           out = emit_store_flag (out, code, ix86_compare_op0,
5342                                  ix86_compare_op1, VOIDmode, 0, 1);
5343
5344           emit_insn (gen_addsi3 (out, out, constm1_rtx));
5345           emit_insn (gen_andsi3 (out, out, GEN_INT (cf-ct)));
5346           if (ct != 0)
5347             emit_insn (gen_addsi3 (out, out, GEN_INT (ct)));
5348           if (out != operands[0])
5349             emit_move_insn (operands[0], out);
5350
5351           return 1; /* DONE */
5352         }
5353     }
5354
5355   if (!TARGET_CMOVE)
5356     {
5357       /* Try a few things more with specific constants and a variable.  */
5358
5359       optab op;
5360       rtx var, orig_out, out, tmp;
5361
5362       if (optimize_size)
5363         return 0; /* FAIL */
5364
5365       /* If one of the two operands is an interesting constant, load a 
5366          constant with the above and mask it in with a logical operation.  */
5367          
5368       if (GET_CODE (operands[2]) == CONST_INT)
5369         {
5370           var = operands[3];
5371           if (INTVAL (operands[2]) == 0)
5372             operands[3] = constm1_rtx, op = and_optab;
5373           else if (INTVAL (operands[2]) == -1)
5374             operands[3] = const0_rtx, op = ior_optab;
5375           else
5376             return 0; /* FAIL */
5377         }
5378       else if (GET_CODE (operands[3]) == CONST_INT)
5379         {
5380           var = operands[2];
5381           if (INTVAL (operands[3]) == 0)
5382             operands[2] = constm1_rtx, op = and_optab;
5383           else if (INTVAL (operands[3]) == -1)
5384             operands[2] = const0_rtx, op = ior_optab;
5385           else
5386             return 0; /* FAIL */
5387         }
5388       else
5389         return 0; /* FAIL */
5390
5391       orig_out = operands[0];
5392       tmp = gen_reg_rtx (GET_MODE (orig_out));
5393       operands[0] = tmp;
5394
5395       /* Recurse to get the constant loaded.  */
5396       if (ix86_expand_int_movcc (operands) == 0)
5397         return 0; /* FAIL */
5398
5399       /* Mask in the interesting variable.  */
5400       out = expand_binop (GET_MODE (orig_out), op, var, tmp, orig_out, 0,
5401                           OPTAB_WIDEN);
5402       if (out != orig_out)
5403         emit_move_insn (orig_out, out);
5404
5405       return 1; /* DONE */
5406     }
5407
5408   /*
5409    * For comparison with above,
5410    *
5411    * movl cf,dest
5412    * movl ct,tmp
5413    * cmpl op1,op2
5414    * cmovcc tmp,dest
5415    *
5416    * Size 15.
5417    */
5418
5419   if (! nonimmediate_operand (operands[2], GET_MODE (operands[0])))
5420     operands[2] = force_reg (GET_MODE (operands[0]), operands[2]);
5421   if (! nonimmediate_operand (operands[3], GET_MODE (operands[0])))
5422     operands[3] = force_reg (GET_MODE (operands[0]), operands[3]);
5423
5424   emit_insn (compare_seq);
5425   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5426                           gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
5427                                                 compare_op, operands[2],
5428                                                 operands[3])));
5429
5430   return 1; /* DONE */
5431 }
5432
5433 int
5434 ix86_expand_fp_movcc (operands)
5435      rtx operands[];
5436 {
5437   enum rtx_code code;
5438   enum machine_mode mode;
5439   rtx tmp;
5440
5441   /* The floating point conditional move instructions don't directly
5442      support conditions resulting from a signed integer comparison. */
5443
5444   code = GET_CODE (operands[1]);
5445   switch (code)
5446     {
5447     case LT:
5448     case LE:
5449     case GE:
5450     case GT:
5451       tmp = gen_reg_rtx (QImode);
5452       ix86_expand_setcc (code, tmp);
5453       code = NE;
5454       ix86_compare_op0 = tmp;
5455       ix86_compare_op1 = const0_rtx;
5456       break;
5457
5458     default:
5459       break;
5460     }
5461
5462   mode = SELECT_CC_MODE (code, ix86_compare_op0, ix86_compare_op1);
5463   emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_REG (mode, FLAGS_REG),
5464                           gen_rtx_COMPARE (mode,
5465                                            ix86_compare_op0,
5466                                            ix86_compare_op1)));
5467   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5468                           gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
5469                                 gen_rtx_fmt_ee (code, VOIDmode,
5470                                                 gen_rtx_REG (mode, FLAGS_REG),
5471                                                 const0_rtx),
5472                                 operands[2],
5473                                 operands[3])));
5474
5475   return 1;
5476 }
5477
5478 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
5479    works for floating pointer parameters and nonoffsetable memories.
5480    For pushes, it returns just stack offsets; the values will be saved
5481    in the right order.  Maximally three parts are generated.  */
5482
5483 static void
5484 ix86_split_to_parts (operand, parts, mode)
5485      rtx operand;
5486      rtx *parts;
5487      enum machine_mode mode;
5488 {
5489   int size = GET_MODE_SIZE (mode) / 4;
5490
5491   if (GET_CODE (operand) == REG && MMX_REGNO_P (REGNO (operand)))
5492     abort ();
5493   if (size < 2 || size > 3)
5494     abort ();
5495
5496   /* Optimize constant pool reference to immediates.  This is used by fp moves,
5497      that force all constants to memory to allow combining.  */
5498
5499   if (GET_CODE (operand) == MEM
5500       && GET_CODE (XEXP (operand, 0)) == SYMBOL_REF
5501       && CONSTANT_POOL_ADDRESS_P (XEXP (operand, 0)))
5502     operand = get_pool_constant (XEXP (operand, 0));
5503
5504   if (GET_CODE (operand) == MEM && !offsettable_memref_p (operand))
5505     {
5506       /* The only non-offsetable memories we handle are pushes.  */
5507       if (! push_operand (operand, VOIDmode))
5508         abort ();
5509
5510       PUT_MODE (operand, SImode);
5511       parts[0] = parts[1] = parts[2] = operand;
5512     }
5513   else
5514     {
5515       if (mode == DImode)
5516         split_di (&operand, 1, &parts[0], &parts[1]);
5517       else
5518         {
5519           if (REG_P (operand))
5520             {
5521               if (!reload_completed)
5522                 abort ();
5523               parts[0] = gen_rtx_REG (SImode, REGNO (operand) + 0);
5524               parts[1] = gen_rtx_REG (SImode, REGNO (operand) + 1);
5525               if (size == 3)
5526                 parts[2] = gen_rtx_REG (SImode, REGNO (operand) + 2);
5527             }
5528           else if (offsettable_memref_p (operand))
5529             {
5530               PUT_MODE (operand, SImode);
5531               parts[0] = operand;
5532               parts[1] = adj_offsettable_operand (operand, 4);
5533               if (size == 3)
5534                 parts[2] = adj_offsettable_operand (operand, 8);
5535             }
5536           else if (GET_CODE (operand) == CONST_DOUBLE)
5537             {
5538               REAL_VALUE_TYPE r;
5539               long l[3];
5540
5541               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
5542               switch (mode)
5543                 {
5544                 case XFmode:
5545                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
5546                   parts[2] = GEN_INT (l[2]);
5547                   break;
5548                 case DFmode:
5549                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
5550                   break;
5551                 default:
5552                   abort ();
5553                 }
5554               parts[1] = GEN_INT (l[1]);
5555               parts[0] = GEN_INT (l[0]);
5556             }
5557           else
5558             abort ();
5559         }
5560     }
5561
5562   return;
5563 }
5564
5565 /* Emit insns to perform a move or push of DI, DF, and XF values.
5566    Return false when normal moves are needed; true when all required
5567    insns have been emitted.  Operands 2-4 contain the input values
5568    int the correct order; operands 5-7 contain the output values.  */
5569
5570 int 
5571 ix86_split_long_move (operands1)
5572      rtx operands1[];
5573 {
5574   rtx part[2][3];
5575   rtx operands[2];
5576   int size = GET_MODE_SIZE (GET_MODE (operands1[0])) / 4;
5577   int push = 0;
5578   int collisions = 0;
5579
5580   /* Make our own copy to avoid clobbering the operands.  */
5581   operands[0] = copy_rtx (operands1[0]);
5582   operands[1] = copy_rtx (operands1[1]);
5583
5584   if (size < 2 || size > 3)
5585     abort ();
5586
5587   /* The only non-offsettable memory we handle is push.  */
5588   if (push_operand (operands[0], VOIDmode))
5589     push = 1;
5590   else if (GET_CODE (operands[0]) == MEM
5591            && ! offsettable_memref_p (operands[0]))
5592     abort ();
5593
5594   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands1[0]));
5595   ix86_split_to_parts (operands[1], part[1], GET_MODE (operands1[0]));
5596
5597   /* When emitting push, take care for source operands on the stack.  */
5598   if (push && GET_CODE (operands[1]) == MEM
5599       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
5600     {
5601       if (size == 3)
5602         part[1][1] = part[1][2];
5603       part[1][0] = part[1][1];
5604     }
5605
5606   /* We need to do copy in the right order in case an address register 
5607      of the source overlaps the destination.  */
5608   if (REG_P (part[0][0]) && GET_CODE (part[1][0]) == MEM)
5609     {
5610       if (reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0)))
5611         collisions++;
5612       if (reg_overlap_mentioned_p (part[0][1], XEXP (part[1][0], 0)))
5613         collisions++;
5614       if (size == 3
5615           && reg_overlap_mentioned_p (part[0][2], XEXP (part[1][0], 0)))
5616         collisions++;
5617
5618       /* Collision in the middle part can be handled by reordering.  */
5619       if (collisions == 1 && size == 3
5620           && reg_overlap_mentioned_p (part[0][1], XEXP (part[1][0], 0)))
5621         {
5622           rtx tmp;
5623           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
5624           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
5625         }
5626
5627       /* If there are more collisions, we can't handle it by reordering.
5628          Do an lea to the last part and use only one colliding move.  */
5629       else if (collisions > 1)
5630         {
5631           collisions = 1;
5632           emit_insn (gen_rtx_SET (VOIDmode, part[0][size - 1],
5633                                   XEXP (part[1][0], 0)));
5634           part[1][0] = change_address (part[1][0], SImode, part[0][size - 1]);
5635           part[1][1] = adj_offsettable_operand (part[1][0], 4);
5636           if (size == 3)
5637             part[1][2] = adj_offsettable_operand (part[1][0], 8);
5638         }
5639     }
5640
5641   if (push)
5642     {
5643       if (size == 3)
5644         emit_insn (gen_push (part[1][2]));
5645       emit_insn (gen_push (part[1][1]));
5646       emit_insn (gen_push (part[1][0]));
5647       return 1;
5648     }
5649
5650   /* Choose correct order to not overwrite the source before it is copied.  */
5651   if ((REG_P (part[0][0])
5652        && REG_P (part[1][1])
5653        && (REGNO (part[0][0]) == REGNO (part[1][1])
5654            || (size == 3
5655                && REGNO (part[0][0]) == REGNO (part[1][2]))))
5656       || (collisions > 0
5657           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
5658     {
5659       if (size == 3)
5660         {
5661           operands1[2] = part[0][2];
5662           operands1[3] = part[0][1];
5663           operands1[4] = part[0][0];
5664           operands1[5] = part[1][2];
5665           operands1[6] = part[1][1];
5666           operands1[7] = part[1][0];
5667         }
5668       else
5669         {
5670           operands1[2] = part[0][1];
5671           operands1[3] = part[0][0];
5672           operands1[5] = part[1][1];
5673           operands1[6] = part[1][0];
5674         }
5675     }
5676   else
5677     {
5678       if (size == 3)
5679         {
5680           operands1[2] = part[0][0];
5681           operands1[3] = part[0][1];
5682           operands1[4] = part[0][2];
5683           operands1[5] = part[1][0];
5684           operands1[6] = part[1][1];
5685           operands1[7] = part[1][2];
5686         }
5687       else
5688         {
5689           operands1[2] = part[0][0];
5690           operands1[3] = part[0][1];
5691           operands1[5] = part[1][0];
5692           operands1[6] = part[1][1];
5693         }
5694     }
5695
5696   return 0;
5697 }
5698
5699 void
5700 ix86_split_ashldi (operands, scratch)
5701      rtx *operands, scratch;
5702 {
5703   rtx low[2], high[2];
5704   int count;
5705
5706   if (GET_CODE (operands[2]) == CONST_INT)
5707     {
5708       split_di (operands, 2, low, high);
5709       count = INTVAL (operands[2]) & 63;
5710
5711       if (count >= 32)
5712         {
5713           emit_move_insn (high[0], low[1]);
5714           emit_move_insn (low[0], const0_rtx);
5715
5716           if (count > 32)
5717             emit_insn (gen_ashlsi3 (high[0], high[0], GEN_INT (count - 32)));
5718         }
5719       else
5720         {
5721           if (!rtx_equal_p (operands[0], operands[1]))
5722             emit_move_insn (operands[0], operands[1]);
5723           emit_insn (gen_x86_shld_1 (high[0], low[0], GEN_INT (count)));
5724           emit_insn (gen_ashlsi3 (low[0], low[0], GEN_INT (count)));
5725         }
5726     }
5727   else
5728     {
5729       if (!rtx_equal_p (operands[0], operands[1]))
5730         emit_move_insn (operands[0], operands[1]);
5731
5732       split_di (operands, 1, low, high);
5733
5734       emit_insn (gen_x86_shld_1 (high[0], low[0], operands[2]));
5735       emit_insn (gen_ashlsi3 (low[0], low[0], operands[2]));
5736
5737       if (TARGET_CMOVE && (! no_new_pseudos || scratch))
5738         {
5739           if (! no_new_pseudos)
5740             scratch = force_reg (SImode, const0_rtx);
5741           else
5742             emit_move_insn (scratch, const0_rtx);
5743
5744           emit_insn (gen_x86_shift_adj_1 (high[0], low[0], operands[2],
5745                                           scratch));
5746         }
5747       else
5748         emit_insn (gen_x86_shift_adj_2 (high[0], low[0], operands[2]));
5749     }
5750 }
5751
5752 void
5753 ix86_split_ashrdi (operands, scratch)
5754      rtx *operands, scratch;
5755 {
5756   rtx low[2], high[2];
5757   int count;
5758
5759   if (GET_CODE (operands[2]) == CONST_INT)
5760     {
5761       split_di (operands, 2, low, high);
5762       count = INTVAL (operands[2]) & 63;
5763
5764       if (count >= 32)
5765         {
5766           emit_move_insn (low[0], high[1]);
5767
5768           if (! reload_completed)
5769             emit_insn (gen_ashrsi3 (high[0], low[0], GEN_INT (31)));
5770           else
5771             {
5772               emit_move_insn (high[0], low[0]);
5773               emit_insn (gen_ashrsi3 (high[0], high[0], GEN_INT (31)));
5774             }
5775
5776           if (count > 32)
5777             emit_insn (gen_ashrsi3 (low[0], low[0], GEN_INT (count - 32)));
5778         }
5779       else
5780         {
5781           if (!rtx_equal_p (operands[0], operands[1]))
5782             emit_move_insn (operands[0], operands[1]);
5783           emit_insn (gen_x86_shrd_1 (low[0], high[0], GEN_INT (count)));
5784           emit_insn (gen_ashrsi3 (high[0], high[0], GEN_INT (count)));
5785         }
5786     }
5787   else
5788     {
5789       if (!rtx_equal_p (operands[0], operands[1]))
5790         emit_move_insn (operands[0], operands[1]);
5791
5792       split_di (operands, 1, low, high);
5793
5794       emit_insn (gen_x86_shrd_1 (low[0], high[0], operands[2]));
5795       emit_insn (gen_ashrsi3 (high[0], high[0], operands[2]));
5796
5797       if (TARGET_CMOVE && (! no_new_pseudos || scratch))
5798         {
5799           if (! no_new_pseudos)
5800             scratch = gen_reg_rtx (SImode);
5801           emit_move_insn (scratch, high[0]);
5802           emit_insn (gen_ashrsi3 (scratch, scratch, GEN_INT (31)));
5803           emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2],
5804                                           scratch));
5805         }
5806       else
5807         emit_insn (gen_x86_shift_adj_3 (low[0], high[0], operands[2]));
5808     }
5809 }
5810
5811 void
5812 ix86_split_lshrdi (operands, scratch)
5813      rtx *operands, scratch;
5814 {
5815   rtx low[2], high[2];
5816   int count;
5817
5818   if (GET_CODE (operands[2]) == CONST_INT)
5819     {
5820       split_di (operands, 2, low, high);
5821       count = INTVAL (operands[2]) & 63;
5822
5823       if (count >= 32)
5824         {
5825           emit_move_insn (low[0], high[1]);
5826           emit_move_insn (high[0], const0_rtx);
5827
5828           if (count > 32)
5829             emit_insn (gen_lshrsi3 (low[0], low[0], GEN_INT (count - 32)));
5830         }
5831       else
5832         {
5833           if (!rtx_equal_p (operands[0], operands[1]))
5834             emit_move_insn (operands[0], operands[1]);
5835           emit_insn (gen_x86_shrd_1 (low[0], high[0], GEN_INT (count)));
5836           emit_insn (gen_lshrsi3 (high[0], high[0], GEN_INT (count)));
5837         }
5838     }
5839   else
5840     {
5841       if (!rtx_equal_p (operands[0], operands[1]))
5842         emit_move_insn (operands[0], operands[1]);
5843
5844       split_di (operands, 1, low, high);
5845
5846       emit_insn (gen_x86_shrd_1 (low[0], high[0], operands[2]));
5847       emit_insn (gen_lshrsi3 (high[0], high[0], operands[2]));
5848
5849       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
5850       if (TARGET_CMOVE && (! no_new_pseudos || scratch))
5851         {
5852           if (! no_new_pseudos)
5853             scratch = force_reg (SImode, const0_rtx);
5854           else
5855             emit_move_insn (scratch, const0_rtx);
5856
5857           emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2],
5858                                           scratch));
5859         }
5860       else
5861         emit_insn (gen_x86_shift_adj_2 (low[0], high[0], operands[2]));
5862     }
5863 }
5864
5865 /* Expand the appropriate insns for doing strlen if not just doing
5866    repnz; scasb
5867
5868    out = result, initialized with the start address
5869    align_rtx = alignment of the address.
5870    scratch = scratch register, initialized with the startaddress when
5871         not aligned, otherwise undefined
5872
5873    This is just the body. It needs the initialisations mentioned above and
5874    some address computing at the end.  These things are done in i386.md.  */
5875
5876 void
5877 ix86_expand_strlensi_unroll_1 (out, align_rtx, scratch)
5878      rtx out, align_rtx, scratch;
5879 {
5880   int align;
5881   rtx tmp;
5882   rtx align_2_label = NULL_RTX;
5883   rtx align_3_label = NULL_RTX;
5884   rtx align_4_label = gen_label_rtx ();
5885   rtx end_0_label = gen_label_rtx ();
5886   rtx mem;
5887   rtx no_flags = gen_rtx_REG (CCNOmode, FLAGS_REG);
5888   rtx z_flags = gen_rtx_REG (CCNOmode, FLAGS_REG);
5889   rtx tmpreg = gen_reg_rtx (SImode);
5890
5891   align = 0;
5892   if (GET_CODE (align_rtx) == CONST_INT)
5893     align = INTVAL (align_rtx);
5894
5895   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
5896
5897   /* Is there a known alignment and is it less than 4?  */
5898   if (align < 4)
5899     {
5900       /* Is there a known alignment and is it not 2? */
5901       if (align != 2)
5902         {
5903           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
5904           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
5905
5906           /* Leave just the 3 lower bits.  */
5907           align_rtx = expand_binop (SImode, and_optab, scratch, GEN_INT (3),
5908                                     NULL_RTX, 0, OPTAB_WIDEN);
5909
5910           emit_insn (gen_cmpsi_ccz_1 (align_rtx, const0_rtx));
5911
5912           tmp = gen_rtx_EQ (VOIDmode, z_flags, const0_rtx);
5913           tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, 
5914                                       gen_rtx_LABEL_REF (VOIDmode,
5915                                                          align_4_label),
5916                                       pc_rtx);
5917           emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
5918
5919           emit_insn (gen_cmpsi_ccno_1 (align_rtx, GEN_INT (2)));
5920
5921           tmp = gen_rtx_EQ (VOIDmode, no_flags, const0_rtx);
5922           tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, 
5923                                       gen_rtx_LABEL_REF (VOIDmode,
5924                                                          align_2_label),
5925                                       pc_rtx);
5926           emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
5927
5928           tmp = gen_rtx_GTU (VOIDmode, no_flags, const0_rtx);
5929           tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, 
5930                                       gen_rtx_LABEL_REF (VOIDmode,
5931                                                          align_3_label),
5932                                       pc_rtx);
5933           emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
5934         }
5935       else
5936         {
5937           /* Since the alignment is 2, we have to check 2 or 0 bytes;
5938              check if is aligned to 4 - byte.  */
5939
5940           align_rtx = expand_binop (SImode, and_optab, scratch, GEN_INT (2),
5941                                     NULL_RTX, 0, OPTAB_WIDEN);
5942
5943           emit_insn (gen_cmpsi_ccz_1 (align_rtx, const0_rtx));
5944
5945           tmp = gen_rtx_EQ (VOIDmode, z_flags, const0_rtx);
5946           tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, 
5947                                       gen_rtx_LABEL_REF (VOIDmode,
5948                                                          align_4_label),
5949                                       pc_rtx);
5950           emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
5951         }
5952
5953       mem = gen_rtx_MEM (QImode, out);
5954
5955       /* Now compare the bytes.  */
5956
5957       /* Compare the first n unaligned byte on a byte per byte basis. */
5958       emit_insn (gen_cmpqi_ccz_1 (mem, const0_rtx));
5959
5960       tmp = gen_rtx_EQ (VOIDmode, z_flags, const0_rtx);
5961       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, 
5962                                   gen_rtx_LABEL_REF (VOIDmode, end_0_label),
5963                                   pc_rtx);
5964       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
5965
5966       /* Increment the address. */
5967       emit_insn (gen_addsi3 (out, out, const1_rtx));
5968
5969       /* Not needed with an alignment of 2 */
5970       if (align != 2)
5971         {
5972           emit_label (align_2_label);
5973
5974           emit_insn (gen_cmpqi_ccz_1 (mem, const0_rtx));
5975
5976           tmp = gen_rtx_EQ (VOIDmode, z_flags, const0_rtx);
5977           tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, 
5978                                       gen_rtx_LABEL_REF (VOIDmode,
5979                                                          end_0_label),
5980                                       pc_rtx);
5981           emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
5982
5983           emit_insn (gen_addsi3 (out, out, const1_rtx));
5984
5985           emit_label (align_3_label);
5986         }
5987
5988       emit_insn (gen_cmpqi_ccz_1 (mem, const0_rtx));
5989
5990       tmp = gen_rtx_EQ (VOIDmode, z_flags, const0_rtx);
5991       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, 
5992                                   gen_rtx_LABEL_REF (VOIDmode, end_0_label),
5993                                   pc_rtx);
5994       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
5995
5996       emit_insn (gen_addsi3 (out, out, const1_rtx));
5997     }
5998
5999   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
6000      align this loop.  It gives only huge programs, but does not help to
6001      speed up.  */
6002   emit_label (align_4_label);
6003
6004   mem = gen_rtx_MEM (SImode, out);
6005   emit_move_insn (scratch, mem);
6006   emit_insn (gen_addsi3 (out, out, GEN_INT (4)));
6007
6008   /* This formula yields a nonzero result iff one of the bytes is zero.
6009      This saves three branches inside loop and many cycles.  */
6010
6011   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
6012   emit_insn (gen_one_cmplsi2 (scratch, scratch));
6013   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
6014   emit_insn (gen_andsi3 (tmpreg, tmpreg, GEN_INT (0x80808080)));
6015   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1, 0, align_4_label);
6016
6017   if (TARGET_CMOVE)
6018     {
6019        rtx reg = gen_reg_rtx (SImode);
6020        emit_move_insn (reg, tmpreg);
6021        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
6022
6023        /* If zero is not in the first two bytes, move two bytes forward. */
6024        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
6025        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
6026        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
6027        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
6028                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
6029                                                      reg, 
6030                                                      tmpreg)));
6031        /* Emit lea manually to avoid clobbering of flags.  */
6032        emit_insn (gen_rtx_SET (SImode, reg,
6033                                gen_rtx_PLUS (SImode, out, GEN_INT (2))));
6034
6035        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
6036        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
6037        emit_insn (gen_rtx_SET (VOIDmode, out,
6038                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
6039                                                      reg,
6040                                                      out)));
6041
6042     }
6043   else
6044     {
6045        rtx end_2_label = gen_label_rtx ();
6046        /* Is zero in the first two bytes? */
6047
6048        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
6049        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
6050        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
6051        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
6052                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
6053                             pc_rtx);
6054        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
6055        JUMP_LABEL (tmp) = end_2_label;
6056
6057        /* Not in the first two.  Move two bytes forward. */
6058        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
6059        emit_insn (gen_addsi3 (out, out, GEN_INT (2)));
6060
6061        emit_label (end_2_label);
6062
6063     }
6064
6065   /* Avoid branch in fixing the byte. */
6066   tmpreg = gen_lowpart (QImode, tmpreg);
6067   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
6068   emit_insn (gen_subsi3_carry (out, out, GEN_INT (3)));
6069
6070   emit_label (end_0_label);
6071 }
6072 \f
6073 /* Clear stack slot assignments remembered from previous functions.
6074    This is called from INIT_EXPANDERS once before RTL is emitted for each
6075    function.  */
6076
6077 static void
6078 ix86_init_machine_status (p)
6079      struct function *p;
6080 {
6081   enum machine_mode mode;
6082   int n;
6083   p->machine
6084     = (struct machine_function *) xmalloc (sizeof (struct machine_function));
6085
6086   for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE;
6087        mode = (enum machine_mode) ((int) mode + 1))
6088     for (n = 0; n < MAX_386_STACK_LOCALS; n++)
6089       ix86_stack_locals[(int) mode][n] = NULL_RTX;
6090 }
6091
6092 /* Mark machine specific bits of P for GC.  */
6093 static void
6094 ix86_mark_machine_status (p)
6095      struct function *p;
6096 {
6097   enum machine_mode mode;
6098   int n;
6099
6100   for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE;
6101        mode = (enum machine_mode) ((int) mode + 1))
6102     for (n = 0; n < MAX_386_STACK_LOCALS; n++)
6103       ggc_mark_rtx (p->machine->stack_locals[(int) mode][n]);
6104 }
6105
6106 /* Return a MEM corresponding to a stack slot with mode MODE.
6107    Allocate a new slot if necessary.
6108
6109    The RTL for a function can have several slots available: N is
6110    which slot to use.  */
6111
6112 rtx
6113 assign_386_stack_local (mode, n)
6114      enum machine_mode mode;
6115      int n;
6116 {
6117   if (n < 0 || n >= MAX_386_STACK_LOCALS)
6118     abort ();
6119
6120   if (ix86_stack_locals[(int) mode][n] == NULL_RTX)
6121     ix86_stack_locals[(int) mode][n]
6122       = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
6123
6124   return ix86_stack_locals[(int) mode][n];
6125 }
6126 \f
6127 /* Calculate the length of the memory address in the instruction
6128    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
6129
6130 static int
6131 memory_address_length (addr)
6132      rtx addr;
6133 {
6134   struct ix86_address parts;
6135   rtx base, index, disp;
6136   int len;
6137
6138   if (GET_CODE (addr) == PRE_DEC
6139       || GET_CODE (addr) == POST_INC)
6140     return 0;
6141
6142   if (! ix86_decompose_address (addr, &parts))
6143     abort ();
6144
6145   base = parts.base;
6146   index = parts.index;
6147   disp = parts.disp;
6148   len = 0;
6149
6150   /* Register Indirect.  */
6151   if (base && !index && !disp)
6152     {
6153       /* Special cases: ebp and esp need the two-byte modrm form.  */
6154       if (addr == stack_pointer_rtx
6155           || addr == arg_pointer_rtx
6156           || addr == frame_pointer_rtx
6157           || addr == hard_frame_pointer_rtx)
6158         len = 1;
6159     }
6160
6161   /* Direct Addressing.  */
6162   else if (disp && !base && !index)
6163     len = 4;
6164
6165   else
6166     {
6167       /* Find the length of the displacement constant.  */
6168       if (disp)
6169         {
6170           if (GET_CODE (disp) == CONST_INT
6171               && CONST_OK_FOR_LETTER_P (INTVAL (disp), 'K'))
6172             len = 1;
6173           else
6174             len = 4;
6175         }
6176
6177       /* An index requires the two-byte modrm form.  */
6178       if (index)
6179         len += 1;
6180     }
6181
6182   return len;
6183 }
6184
6185 /* Compute default value for "length_immediate" attribute.  When SHORTFORM is set
6186    expect that insn have 8bit immediate alternative.  */
6187 int
6188 ix86_attr_length_immediate_default (insn, shortform)
6189      rtx insn;
6190      int shortform;
6191 {
6192   int len = 0;
6193   int i;
6194   extract_insn (insn);
6195   for (i = recog_data.n_operands - 1; i >= 0; --i)
6196     if (CONSTANT_P (recog_data.operand[i]))
6197       {
6198         if (len)
6199           abort ();
6200         if (shortform
6201             && GET_CODE (recog_data.operand[i]) == CONST_INT
6202             && CONST_OK_FOR_LETTER_P (INTVAL (recog_data.operand[i]), 'K'))
6203           len = 1;
6204         else
6205           {
6206             switch (get_attr_mode (insn))
6207               {
6208                 case MODE_QI:
6209                   len+=1;
6210                   break;
6211                 case MODE_HI:
6212                   len+=2;
6213                   break;
6214                 case MODE_SI:
6215                   len+=4;
6216                   break;
6217                 default:
6218                   fatal_insn ("Unknown insn mode", insn);
6219               }
6220           }
6221       }
6222   return len;
6223 }
6224 /* Compute default value for "length_address" attribute.  */
6225 int
6226 ix86_attr_length_address_default (insn)
6227      rtx insn;
6228 {
6229   int i;
6230   extract_insn (insn);
6231   for (i = recog_data.n_operands - 1; i >= 0; --i)
6232     if (GET_CODE (recog_data.operand[i]) == MEM)
6233       {
6234         return memory_address_length (XEXP (recog_data.operand[i], 0));
6235         break;
6236       }
6237   return 0;
6238 }
6239 \f
6240 /* Return the maximum number of instructions a cpu can issue.  */
6241
6242 int
6243 ix86_issue_rate ()
6244 {
6245   switch (ix86_cpu)
6246     {
6247     case PROCESSOR_PENTIUM:
6248     case PROCESSOR_K6:
6249       return 2;
6250
6251     case PROCESSOR_PENTIUMPRO:
6252       return 3;
6253
6254     default:
6255       return 1;
6256     }
6257 }
6258
6259 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
6260    by DEP_INSN and nothing set by DEP_INSN.  */
6261
6262 static int
6263 ix86_flags_dependant (insn, dep_insn, insn_type)
6264      rtx insn, dep_insn;
6265      enum attr_type insn_type;
6266 {
6267   rtx set, set2;
6268
6269   /* Simplify the test for uninteresting insns.  */
6270   if (insn_type != TYPE_SETCC
6271       && insn_type != TYPE_ICMOV
6272       && insn_type != TYPE_FCMOV
6273       && insn_type != TYPE_IBR)
6274     return 0;
6275
6276   if ((set = single_set (dep_insn)) != 0)
6277     {
6278       set = SET_DEST (set);
6279       set2 = NULL_RTX;
6280     }
6281   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
6282            && XVECLEN (PATTERN (dep_insn), 0) == 2
6283            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
6284            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
6285     {
6286       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
6287       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
6288     }
6289   else
6290     return 0;
6291
6292   if (GET_CODE (set) != REG || REGNO (set) != FLAGS_REG)
6293     return 0;
6294
6295   /* This test is true if the dependant insn reads the flags but
6296      not any other potentially set register.  */
6297   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
6298     return 0;
6299
6300   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
6301     return 0;
6302
6303   return 1;
6304 }
6305
6306 /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory
6307    address with operands set by DEP_INSN.  */
6308
6309 static int
6310 ix86_agi_dependant (insn, dep_insn, insn_type)
6311      rtx insn, dep_insn;
6312      enum attr_type insn_type;
6313 {
6314   rtx addr;
6315
6316   if (insn_type == TYPE_LEA)
6317     {
6318       addr = PATTERN (insn);
6319       if (GET_CODE (addr) == SET)
6320         ;
6321       else if (GET_CODE (addr) == PARALLEL
6322                && GET_CODE (XVECEXP (addr, 0, 0)) == SET)
6323         addr = XVECEXP (addr, 0, 0);
6324       else
6325         abort ();
6326       addr = SET_SRC (addr);
6327     }
6328   else
6329     {
6330       int i;
6331       extract_insn (insn);
6332       for (i = recog_data.n_operands - 1; i >= 0; --i)
6333         if (GET_CODE (recog_data.operand[i]) == MEM)
6334           {
6335             addr = XEXP (recog_data.operand[i], 0);
6336             goto found;
6337           }
6338       return 0;
6339     found:;
6340     }
6341
6342   return modified_in_p (addr, dep_insn);
6343 }
6344
6345 int
6346 ix86_adjust_cost (insn, link, dep_insn, cost)
6347      rtx insn, link, dep_insn;
6348      int cost;
6349 {
6350   enum attr_type insn_type, dep_insn_type;
6351   enum attr_memory memory;
6352   rtx set, set2;
6353   int dep_insn_code_number;
6354
6355   /* Anti and output depenancies have zero cost on all CPUs.  */
6356   if (REG_NOTE_KIND (link) != 0)
6357     return 0;
6358
6359   dep_insn_code_number = recog_memoized (dep_insn);
6360
6361   /* If we can't recognize the insns, we can't really do anything.  */
6362   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
6363     return cost;
6364
6365   insn_type = get_attr_type (insn);
6366   dep_insn_type = get_attr_type (dep_insn);
6367
6368   /* Prologue and epilogue allocators can have a false dependency on ebp.
6369      This results in one cycle extra stall on Pentium prologue scheduling,
6370      so handle this important case manually.  */
6371   if (dep_insn_code_number == CODE_FOR_pro_epilogue_adjust_stack
6372       && dep_insn_type == TYPE_ALU
6373       && !reg_mentioned_p (stack_pointer_rtx, insn))
6374     return 0;
6375
6376   switch (ix86_cpu)
6377     {
6378     case PROCESSOR_PENTIUM:
6379       /* Address Generation Interlock adds a cycle of latency.  */
6380       if (ix86_agi_dependant (insn, dep_insn, insn_type))
6381         cost += 1;
6382
6383       /* ??? Compares pair with jump/setcc.  */
6384       if (ix86_flags_dependant (insn, dep_insn, insn_type))
6385         cost = 0;
6386
6387       /* Floating point stores require value to be ready one cycle ealier.  */
6388       if (insn_type == TYPE_FMOV 
6389           && get_attr_memory (insn) == MEMORY_STORE
6390           && !ix86_agi_dependant (insn, dep_insn, insn_type))
6391         cost += 1;
6392       break;
6393
6394     case PROCESSOR_PENTIUMPRO:
6395       /* Since we can't represent delayed latencies of load+operation, 
6396          increase the cost here for non-imov insns.  */
6397       if (dep_insn_type != TYPE_IMOV
6398           && dep_insn_type != TYPE_FMOV
6399           && ((memory = get_attr_memory (dep_insn) == MEMORY_LOAD)
6400               || memory == MEMORY_BOTH))
6401         cost += 1;
6402
6403       /* INT->FP conversion is expensive.  */
6404       if (get_attr_fp_int_src (dep_insn))
6405         cost += 5;
6406
6407       /* There is one cycle extra latency between an FP op and a store.  */
6408       if (insn_type == TYPE_FMOV
6409           && (set = single_set (dep_insn)) != NULL_RTX
6410           && (set2 = single_set (insn)) != NULL_RTX
6411           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
6412           && GET_CODE (SET_DEST (set2)) == MEM)
6413         cost += 1;
6414       break;
6415
6416     case PROCESSOR_K6:
6417       /* The esp dependency is resolved before the instruction is really
6418          finished.  */
6419       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
6420           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
6421         return 1;
6422
6423       /* Since we can't represent delayed latencies of load+operation, 
6424          increase the cost here for non-imov insns.  */
6425       if ((memory = get_attr_memory (dep_insn) == MEMORY_LOAD)
6426           || memory == MEMORY_BOTH)
6427         cost += (dep_insn_type != TYPE_IMOV) ? 2 : 1;
6428
6429       /* INT->FP conversion is expensive.  */
6430       if (get_attr_fp_int_src (dep_insn))
6431         cost += 5;
6432       break;
6433
6434     case PROCESSOR_ATHLON:
6435       if ((memory = get_attr_memory (dep_insn)) == MEMORY_LOAD
6436            || memory == MEMORY_BOTH)
6437         {
6438           if (dep_insn_type == TYPE_IMOV || dep_insn_type == TYPE_FMOV)
6439             cost += 2;
6440           else
6441             cost += 3;
6442         }
6443
6444     default:
6445       break;
6446     }
6447
6448   return cost;
6449 }
6450
6451 static union
6452 {
6453   struct ppro_sched_data
6454   {
6455     rtx decode[3];
6456     int issued_this_cycle;
6457   } ppro;
6458 } ix86_sched_data;
6459
6460 static int
6461 ix86_safe_length (insn)
6462      rtx insn;
6463 {
6464   if (recog_memoized (insn) >= 0)
6465     return get_attr_length(insn);
6466   else
6467     return 128;
6468 }
6469
6470 static int
6471 ix86_safe_length_prefix (insn)
6472      rtx insn;
6473 {
6474   if (recog_memoized (insn) >= 0)
6475     return get_attr_length(insn);
6476   else
6477     return 0;
6478 }
6479
6480 static enum attr_memory
6481 ix86_safe_memory (insn)
6482      rtx insn;
6483 {
6484   if (recog_memoized (insn) >= 0)
6485     return get_attr_memory(insn);
6486   else
6487     return MEMORY_UNKNOWN;
6488 }
6489
6490 static enum attr_pent_pair
6491 ix86_safe_pent_pair (insn)
6492      rtx insn;
6493 {
6494   if (recog_memoized (insn) >= 0)
6495     return get_attr_pent_pair(insn);
6496   else
6497     return PENT_PAIR_NP;
6498 }
6499
6500 static enum attr_ppro_uops
6501 ix86_safe_ppro_uops (insn)
6502      rtx insn;
6503 {
6504   if (recog_memoized (insn) >= 0)
6505     return get_attr_ppro_uops (insn);
6506   else
6507     return PPRO_UOPS_MANY;
6508 }
6509
6510 static void
6511 ix86_dump_ppro_packet (dump)
6512      FILE *dump;
6513 {
6514   if (ix86_sched_data.ppro.decode[0])
6515     {
6516       fprintf (dump, "PPRO packet: %d",
6517                INSN_UID (ix86_sched_data.ppro.decode[0]));
6518       if (ix86_sched_data.ppro.decode[1])
6519         fprintf (dump, " %d", INSN_UID (ix86_sched_data.ppro.decode[1]));
6520       if (ix86_sched_data.ppro.decode[2])
6521         fprintf (dump, " %d", INSN_UID (ix86_sched_data.ppro.decode[2]));
6522       fputc ('\n', dump);
6523     }
6524 }
6525
6526 /* We're beginning a new block.  Initialize data structures as necessary.  */
6527
6528 void
6529 ix86_sched_init (dump, sched_verbose)
6530      FILE *dump ATTRIBUTE_UNUSED;
6531      int sched_verbose ATTRIBUTE_UNUSED;
6532 {
6533   memset (&ix86_sched_data, 0, sizeof (ix86_sched_data));
6534 }
6535
6536 /* Shift INSN to SLOT, and shift everything else down.  */
6537
6538 static void
6539 ix86_reorder_insn (insnp, slot)
6540      rtx *insnp, *slot;
6541 {
6542   if (insnp != slot)
6543     {
6544       rtx insn = *insnp;
6545       do 
6546         insnp[0] = insnp[1];
6547       while (++insnp != slot);
6548       *insnp = insn;
6549     }
6550 }
6551
6552 /* Find an instruction with given pairability and minimal amount of cycles
6553    lost by the fact that the CPU waits for both pipelines to finish before
6554    reading next instructions.  Also take care that both instructions together
6555    can not exceed 7 bytes.  */
6556
6557 static rtx *
6558 ix86_pent_find_pair (e_ready, ready, type, first)
6559      rtx *e_ready;
6560      rtx *ready;
6561      enum attr_pent_pair type;
6562      rtx first;
6563 {
6564   int mincycles, cycles;
6565   enum attr_pent_pair tmp;
6566   enum attr_memory memory;
6567   rtx *insnp, *bestinsnp = NULL;
6568
6569   if (ix86_safe_length (first) > 7 + ix86_safe_length_prefix (first))
6570     return NULL;
6571
6572   memory = ix86_safe_memory (first);
6573   cycles = result_ready_cost (first);
6574   mincycles = INT_MAX;
6575
6576   for (insnp = e_ready; insnp >= ready && mincycles; --insnp)
6577     if ((tmp = ix86_safe_pent_pair (*insnp)) == type
6578         && ix86_safe_length (*insnp) <= 7 + ix86_safe_length_prefix (*insnp))
6579       {
6580         enum attr_memory second_memory;
6581         int secondcycles, currentcycles;
6582
6583         second_memory = ix86_safe_memory (*insnp);
6584         secondcycles = result_ready_cost (*insnp);
6585         currentcycles = abs (cycles - secondcycles);
6586
6587         if (secondcycles >= 1 && cycles >= 1)
6588           {
6589             /* Two read/modify/write instructions together takes two
6590                cycles longer.  */
6591             if (memory == MEMORY_BOTH && second_memory == MEMORY_BOTH)
6592               currentcycles += 2;
6593   
6594             /* Read modify/write instruction followed by read/modify
6595                takes one cycle longer.  */
6596             if (memory == MEMORY_BOTH && second_memory == MEMORY_LOAD
6597                 && tmp != PENT_PAIR_UV
6598                 && ix86_safe_pent_pair (first) != PENT_PAIR_UV)
6599               currentcycles += 1;
6600           }
6601         if (currentcycles < mincycles)
6602           bestinsnp = insnp, mincycles = currentcycles;
6603       }
6604
6605   return bestinsnp;
6606 }
6607
6608 /* Subroutines of ix86_sched_reorder.  */
6609
6610 static void
6611 ix86_sched_reorder_pentium (ready, e_ready)
6612      rtx *ready;
6613      rtx *e_ready;
6614 {
6615   enum attr_pent_pair pair1, pair2;
6616   rtx *insnp;
6617
6618   /* This wouldn't be necessary if Haifa knew that static insn ordering
6619      is important to which pipe an insn is issued to.  So we have to make
6620      some minor rearrangements.  */
6621
6622   pair1 = ix86_safe_pent_pair (*e_ready);
6623
6624   /* If the first insn is non-pairable, let it be.  */
6625   if (pair1 == PENT_PAIR_NP)
6626     return;
6627
6628   pair2 = PENT_PAIR_NP;
6629   insnp = 0;
6630
6631   /* If the first insn is UV or PV pairable, search for a PU
6632      insn to go with.  */
6633   if (pair1 == PENT_PAIR_UV || pair1 == PENT_PAIR_PV)
6634     {
6635       insnp = ix86_pent_find_pair (e_ready-1, ready,
6636                                    PENT_PAIR_PU, *e_ready);
6637       if (insnp)
6638         pair2 = PENT_PAIR_PU;
6639     }
6640
6641   /* If the first insn is PU or UV pairable, search for a PV
6642      insn to go with.  */
6643   if (pair2 == PENT_PAIR_NP
6644       && (pair1 == PENT_PAIR_PU || pair1 == PENT_PAIR_UV))
6645     {
6646       insnp = ix86_pent_find_pair (e_ready-1, ready,
6647                                    PENT_PAIR_PV, *e_ready);
6648       if (insnp)
6649         pair2 = PENT_PAIR_PV;
6650     }
6651
6652   /* If the first insn is pairable, search for a UV
6653      insn to go with.  */
6654   if (pair2 == PENT_PAIR_NP)
6655     {
6656       insnp = ix86_pent_find_pair (e_ready-1, ready,
6657                                    PENT_PAIR_UV, *e_ready);
6658       if (insnp)
6659         pair2 = PENT_PAIR_UV;
6660     }
6661
6662   if (pair2 == PENT_PAIR_NP)
6663     return;
6664
6665   /* Found something!  Decide if we need to swap the order.  */
6666   if (pair1 == PENT_PAIR_PV || pair2 == PENT_PAIR_PU
6667       || (pair1 == PENT_PAIR_UV && pair2 == PENT_PAIR_UV
6668           && ix86_safe_memory (*e_ready) == MEMORY_BOTH
6669           && ix86_safe_memory (*insnp) == MEMORY_LOAD))
6670     ix86_reorder_insn (insnp, e_ready);
6671   else
6672     ix86_reorder_insn (insnp, e_ready - 1);
6673 }
6674
6675 static void
6676 ix86_sched_reorder_ppro (ready, e_ready)
6677      rtx *ready;
6678      rtx *e_ready;
6679 {
6680   rtx decode[3];
6681   enum attr_ppro_uops cur_uops;
6682   int issued_this_cycle;
6683   rtx *insnp;
6684   int i;
6685
6686   /* At this point .ppro.decode contains the state of the three 
6687      decoders from last "cycle".  That is, those insns that were
6688      actually independent.  But here we're scheduling for the 
6689      decoder, and we may find things that are decodable in the
6690      same cycle.  */
6691
6692   memcpy (decode, ix86_sched_data.ppro.decode, sizeof(decode));
6693   issued_this_cycle = 0;
6694
6695   insnp = e_ready;
6696   cur_uops = ix86_safe_ppro_uops (*insnp);
6697
6698   /* If the decoders are empty, and we've a complex insn at the
6699      head of the priority queue, let it issue without complaint.  */
6700   if (decode[0] == NULL)
6701     {
6702       if (cur_uops == PPRO_UOPS_MANY)
6703         {
6704           decode[0] = *insnp;
6705           goto ppro_done;
6706         }
6707
6708       /* Otherwise, search for a 2-4 uop unsn to issue.  */
6709       while (cur_uops != PPRO_UOPS_FEW)
6710         {
6711           if (insnp == ready)
6712             break;
6713           cur_uops = ix86_safe_ppro_uops (*--insnp);
6714         }
6715
6716       /* If so, move it to the head of the line.  */
6717       if (cur_uops == PPRO_UOPS_FEW)
6718         ix86_reorder_insn (insnp, e_ready);
6719
6720       /* Issue the head of the queue.  */
6721       issued_this_cycle = 1;
6722       decode[0] = *e_ready--;
6723     }
6724
6725   /* Look for simple insns to fill in the other two slots.  */
6726   for (i = 1; i < 3; ++i)
6727     if (decode[i] == NULL)
6728       {
6729         if (ready >= e_ready)
6730           goto ppro_done;
6731
6732         insnp = e_ready;
6733         cur_uops = ix86_safe_ppro_uops (*insnp);
6734         while (cur_uops != PPRO_UOPS_ONE)
6735           {
6736             if (insnp == ready)
6737               break;
6738             cur_uops = ix86_safe_ppro_uops (*--insnp);
6739           }
6740
6741         /* Found one.  Move it to the head of the queue and issue it.  */
6742         if (cur_uops == PPRO_UOPS_ONE)
6743           {
6744             ix86_reorder_insn (insnp, e_ready);
6745             decode[i] = *e_ready--;
6746             issued_this_cycle++;
6747             continue;
6748           }
6749
6750         /* ??? Didn't find one.  Ideally, here we would do a lazy split
6751            of 2-uop insns, issue one and queue the other.  */
6752       }
6753
6754  ppro_done:
6755   if (issued_this_cycle == 0)
6756     issued_this_cycle = 1;
6757   ix86_sched_data.ppro.issued_this_cycle = issued_this_cycle;
6758 }
6759
6760   
6761 /* We are about to being issuing insns for this clock cycle.  
6762    Override the default sort algorithm to better slot instructions.  */
6763 int
6764 ix86_sched_reorder (dump, sched_verbose, ready, n_ready, clock_var)
6765      FILE *dump ATTRIBUTE_UNUSED;
6766      int sched_verbose ATTRIBUTE_UNUSED;
6767      rtx *ready;
6768      int n_ready;
6769      int clock_var ATTRIBUTE_UNUSED;
6770 {
6771   rtx *e_ready = ready + n_ready - 1;
6772
6773   if (n_ready < 2)
6774     goto out;
6775
6776   switch (ix86_cpu)
6777     {
6778     default:
6779       break;
6780
6781     case PROCESSOR_PENTIUM:
6782       ix86_sched_reorder_pentium (ready, e_ready);
6783       break;
6784
6785     case PROCESSOR_PENTIUMPRO:
6786       ix86_sched_reorder_ppro (ready, e_ready);
6787       break;
6788     }
6789
6790 out:
6791   return ix86_issue_rate ();
6792 }
6793
6794 /* We are about to issue INSN.  Return the number of insns left on the
6795    ready queue that can be issued this cycle.  */
6796
6797 int
6798 ix86_variable_issue (dump, sched_verbose, insn, can_issue_more)
6799      FILE *dump;
6800      int sched_verbose;
6801      rtx insn;
6802      int can_issue_more;
6803 {
6804   int i;
6805   switch (ix86_cpu)
6806     {
6807     default:
6808       return can_issue_more - 1;
6809
6810     case PROCESSOR_PENTIUMPRO:
6811       {
6812         enum attr_ppro_uops uops = ix86_safe_ppro_uops (insn);
6813
6814         if (uops == PPRO_UOPS_MANY)
6815           {
6816             if (sched_verbose)
6817               ix86_dump_ppro_packet (dump);
6818             ix86_sched_data.ppro.decode[0] = insn;
6819             ix86_sched_data.ppro.decode[1] = NULL;
6820             ix86_sched_data.ppro.decode[2] = NULL;
6821             if (sched_verbose)
6822               ix86_dump_ppro_packet (dump);
6823             ix86_sched_data.ppro.decode[0] = NULL;
6824           }
6825         else if (uops == PPRO_UOPS_FEW)
6826           {
6827             if (sched_verbose)
6828               ix86_dump_ppro_packet (dump);
6829             ix86_sched_data.ppro.decode[0] = insn;
6830             ix86_sched_data.ppro.decode[1] = NULL;
6831             ix86_sched_data.ppro.decode[2] = NULL;
6832           }
6833         else
6834           {
6835             for (i = 0; i < 3; ++i)
6836               if (ix86_sched_data.ppro.decode[i] == NULL)
6837                 {
6838                   ix86_sched_data.ppro.decode[i] = insn;
6839                   break;
6840                 }
6841             if (i == 3)
6842               abort ();
6843             if (i == 2)
6844               {
6845                 if (sched_verbose)
6846                   ix86_dump_ppro_packet (dump);
6847                 ix86_sched_data.ppro.decode[0] = NULL;
6848                 ix86_sched_data.ppro.decode[1] = NULL;
6849                 ix86_sched_data.ppro.decode[2] = NULL;
6850               }
6851           }
6852       }
6853       return --ix86_sched_data.ppro.issued_this_cycle;
6854     }
6855 }
6856 \f
6857 /* Compute the alignment given to a constant that is being placed in memory.
6858    EXP is the constant and ALIGN is the alignment that the object would
6859    ordinarily have.
6860    The value of this function is used instead of that alignment to align
6861    the object.  */
6862
6863 int
6864 ix86_constant_alignment (exp, align)
6865      tree exp;
6866      int align;
6867 {
6868   if (TREE_CODE (exp) == REAL_CST)
6869     {
6870       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
6871         return 64;
6872       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
6873         return 128;
6874     }
6875   else if (TREE_CODE (exp) == STRING_CST && TREE_STRING_LENGTH (exp) >= 31
6876            && align < 256)
6877     return 256;
6878
6879   return align;
6880 }
6881
6882 /* Compute the alignment for a static variable.
6883    TYPE is the data type, and ALIGN is the alignment that
6884    the object would ordinarily have.  The value of this function is used
6885    instead of that alignment to align the object.  */
6886
6887 int
6888 ix86_data_alignment (type, align)
6889      tree type;
6890      int align;
6891 {
6892   if (AGGREGATE_TYPE_P (type)
6893        && TYPE_SIZE (type)
6894        && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
6895        && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 256
6896            || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 256)
6897     return 256;
6898
6899   if (TREE_CODE (type) == ARRAY_TYPE)
6900     {
6901       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
6902         return 64;
6903       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
6904         return 128;
6905     }
6906   else if (TREE_CODE (type) == COMPLEX_TYPE)
6907     {
6908       
6909       if (TYPE_MODE (type) == DCmode && align < 64)
6910         return 64;
6911       if (TYPE_MODE (type) == XCmode && align < 128)
6912         return 128;
6913     }
6914   else if ((TREE_CODE (type) == RECORD_TYPE
6915             || TREE_CODE (type) == UNION_TYPE
6916             || TREE_CODE (type) == QUAL_UNION_TYPE)
6917            && TYPE_FIELDS (type))
6918     {
6919       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
6920         return 64;
6921       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
6922         return 128;
6923     }
6924   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
6925            || TREE_CODE (type) == INTEGER_TYPE)
6926     {
6927       if (TYPE_MODE (type) == DFmode && align < 64)
6928         return 64;
6929       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
6930         return 128;
6931     }
6932
6933   return align;
6934 }
6935
6936 /* Compute the alignment for a local variable.
6937    TYPE is the data type, and ALIGN is the alignment that
6938    the object would ordinarily have.  The value of this macro is used
6939    instead of that alignment to align the object.  */
6940
6941 int
6942 ix86_local_alignment (type, align)
6943      tree type;
6944      int align;
6945 {
6946   if (TREE_CODE (type) == ARRAY_TYPE)
6947     {
6948       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
6949         return 64;
6950       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
6951         return 128;
6952     }
6953   else if (TREE_CODE (type) == COMPLEX_TYPE)
6954     {
6955       if (TYPE_MODE (type) == DCmode && align < 64)
6956         return 64;
6957       if (TYPE_MODE (type) == XCmode && align < 128)
6958         return 128;
6959     }
6960   else if ((TREE_CODE (type) == RECORD_TYPE
6961             || TREE_CODE (type) == UNION_TYPE
6962             || TREE_CODE (type) == QUAL_UNION_TYPE)
6963            && TYPE_FIELDS (type))
6964     {
6965       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
6966         return 64;
6967       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
6968         return 128;
6969     }
6970   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
6971            || TREE_CODE (type) == INTEGER_TYPE)
6972     {
6973       
6974       if (TYPE_MODE (type) == DFmode && align < 64)
6975         return 64;
6976       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
6977         return 128;
6978     }
6979   return align;
6980 }