Merge from vendor branch NTPD:
[dragonfly.git] / contrib / gcc / config / i386 / i386.c
1 /* Subroutines for insn-output.c for Intel X86.
2    Copyright (C) 1988, 92, 94-98, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* $FreeBSD: src/contrib/gcc/config/i386/i386.c,v 1.7 2000/01/29 13:06:33 obrien Exp $ */
22 /* $DragonFly: src/contrib/gcc/config/i386/Attic/i386.c,v 1.2 2003/06/17 04:24:01 dillon Exp $ */
23
24 #include <setjmp.h>
25 #include "config.h"
26 #include "system.h"
27 #include "rtl.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 "tree.h"
37 #include "flags.h"
38 #include "except.h"
39 #include "function.h"
40 #include "recog.h"
41 #include "expr.h"
42 #include "toplev.h"
43
44 #ifdef EXTRA_CONSTRAINT
45 /* If EXTRA_CONSTRAINT is defined, then the 'S'
46    constraint in REG_CLASS_FROM_LETTER will no longer work, and various
47    asm statements that need 'S' for class SIREG will break.  */
48  error EXTRA_CONSTRAINT conflicts with S constraint letter
49 /* The previous line used to be #error, but some compilers barf
50    even if the conditional was untrue.  */
51 #endif
52
53 #ifndef CHECK_STACK_LIMIT
54 #define CHECK_STACK_LIMIT -1
55 #endif
56
57 #define PIC_REG_USED                                    \
58   (flag_pic && (current_function_uses_pic_offset_table  \
59                 || current_function_uses_const_pool     \
60                 || profile_flag || profile_block_flag))
61
62 /* Type of an operand for ix86_{binary,unary}_operator_ok */
63 enum reg_mem
64 {
65   reg_p,
66   mem_p,
67   imm_p
68 };
69
70 /* Processor costs (relative to an add) */
71 struct processor_costs i386_cost = {    /* 386 specific costs */
72   1,                                    /* cost of an add instruction */
73   1,                                    /* cost of a lea instruction */
74   3,                                    /* variable shift costs */
75   2,                                    /* constant shift costs */
76   6,                                    /* cost of starting a multiply */
77   1,                                    /* cost of multiply per each bit set */
78   23                                    /* cost of a divide/mod */
79 };
80
81 struct processor_costs i486_cost = {    /* 486 specific costs */
82   1,                                    /* cost of an add instruction */
83   1,                                    /* cost of a lea instruction */
84   3,                                    /* variable shift costs */
85   2,                                    /* constant shift costs */
86   12,                                   /* cost of starting a multiply */
87   1,                                    /* cost of multiply per each bit set */
88   40                                    /* cost of a divide/mod */
89 };
90
91 struct processor_costs pentium_cost = {
92   1,                                    /* cost of an add instruction */
93   1,                                    /* cost of a lea instruction */
94   4,                                    /* variable shift costs */
95   1,                                    /* constant shift costs */
96   11,                                   /* cost of starting a multiply */
97   0,                                    /* cost of multiply per each bit set */
98   25                                    /* cost of a divide/mod */
99 };
100
101 struct processor_costs pentiumpro_cost = {
102   1,                                    /* cost of an add instruction */
103   1,                                    /* cost of a lea instruction */
104   3,                                    /* variable shift costs */
105   1,                                    /* constant shift costs */
106   4,                                    /* cost of starting a multiply */
107   0,                                    /* cost of multiply per each bit set */
108   17                                    /* cost of a divide/mod */
109 };
110
111 /* We use decoding time together with execution time. 
112    To get correct vale add 1 for short decodable, 2 for long decodable
113    and 4 for vector decodable instruction to execution time and divide
114    by two (because CPU is able to do two insns at a time). */
115
116 struct processor_costs k6_cost = {
117   1,                                    /* cost of an add instruction */
118   1,                                    /* cost of a lea instruction */
119   1,                                    /* variable shift costs */
120   1,                                    /* constant shift costs */
121   3,                                    /* cost of starting a multiply */
122   0,                                    /* cost of multiply per each bit set */
123   20                                    /* cost of a divide/mod */
124 };
125
126 struct processor_costs *ix86_cost = &pentium_cost;
127
128 /* Processor feature/optimization bitmasks.  */
129 #define m_386 (1<<PROCESSOR_I386)
130 #define m_486 (1<<PROCESSOR_I486)
131 #define m_PENT (1<<PROCESSOR_PENTIUM)
132 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
133 #define m_K6  (1<<PROCESSOR_K6)
134
135 const int x86_use_leave = m_386 | m_K6;
136 const int x86_push_memory = m_386 | m_K6;
137 const int x86_zero_extend_with_and = m_486 | m_PENT;
138 const int x86_movx = m_386 | m_PPRO | m_K6;
139 const int x86_double_with_add = ~(m_386 | m_PENT | m_PPRO);
140 const int x86_use_bit_test = m_386;
141 const int x86_unroll_strlen = m_486 | m_PENT | m_PPRO;
142 const int x86_use_q_reg = m_PENT | m_PPRO | m_K6;
143 const int x86_use_any_reg = m_486;
144 const int x86_cmove = m_PPRO;
145 const int x86_deep_branch = m_PPRO| m_K6;
146
147 #define AT_BP(mode) (gen_rtx_MEM ((mode), frame_pointer_rtx))
148
149 extern FILE *asm_out_file;
150 extern char *strcat ();
151
152 static void ix86_epilogue PROTO((int));
153 static void ix86_prologue PROTO((int));
154
155 char *singlemove_string ();
156 char *output_move_const_single ();
157 char *output_fp_cc0_set ();
158
159 char *hi_reg_name[] = HI_REGISTER_NAMES;
160 char *qi_reg_name[] = QI_REGISTER_NAMES;
161 char *qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
162
163 /* Array of the smallest class containing reg number REGNO, indexed by
164    REGNO.  Used by REGNO_REG_CLASS in i386.h. */
165
166 enum reg_class regclass_map[FIRST_PSEUDO_REGISTER] =
167 {
168   /* ax, dx, cx, bx */
169   AREG, DREG, CREG, BREG,
170   /* si, di, bp, sp */
171   SIREG, DIREG, INDEX_REGS, GENERAL_REGS,
172   /* FP registers */
173   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
174   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
175   /* arg pointer */
176   INDEX_REGS
177 };
178
179 /* Test and compare insns in i386.md store the information needed to
180    generate branch and scc insns here.  */
181
182 struct rtx_def *i386_compare_op0 = NULL_RTX;
183 struct rtx_def *i386_compare_op1 = NULL_RTX;
184 struct rtx_def *(*i386_compare_gen)(), *(*i386_compare_gen_eq)();
185
186 /* which cpu are we scheduling for */
187 enum processor_type ix86_cpu;
188
189 /* which instruction set architecture to use.  */
190 int ix86_arch;
191
192 /* Strings to hold which cpu and instruction set architecture  to use.  */
193 char *ix86_cpu_string;          /* for -mcpu=<xxx> */
194 char *ix86_arch_string;         /* for -march=<xxx> */
195
196 /* Register allocation order */
197 char *i386_reg_alloc_order;
198 static char regs_allocated[FIRST_PSEUDO_REGISTER];
199
200 /* # of registers to use to pass arguments. */
201 char *i386_regparm_string;
202
203 /* i386_regparm_string as a number */
204 int i386_regparm;
205
206 /* Alignment to use for loops and jumps:  */
207
208 /* Power of two alignment for loops. */
209 char *i386_align_loops_string;
210
211 /* Power of two alignment for non-loop jumps. */
212 char *i386_align_jumps_string;
213
214 /* Power of two alignment for stack boundary in bytes.  */
215 char *i386_preferred_stack_boundary_string;
216
217 /* Preferred alignment for stack boundary in bits.  */
218 int i386_preferred_stack_boundary;
219
220 /* Values 1-5: see jump.c */
221 int i386_branch_cost;
222 char *i386_branch_cost_string;
223
224 /* Power of two alignment for functions. */
225 int i386_align_funcs;
226 char *i386_align_funcs_string;
227
228 /* Power of two alignment for loops. */
229 int i386_align_loops;
230
231 /* Power of two alignment for non-loop jumps. */
232 int i386_align_jumps;
233
234 /* Sometimes certain combinations of command options do not make
235    sense on a particular target machine.  You can define a macro
236    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
237    defined, is executed once just after all the command options have
238    been parsed.
239
240    Don't use this macro to turn on various extra optimizations for
241    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
242
243 void
244 override_options ()
245 {
246   int ch, i, j;
247   int def_align;
248
249   static struct ptt
250     {
251       char *name;               /* Canonical processor name.  */
252       enum processor_type processor; /* Processor type enum value.  */
253       struct processor_costs *cost; /* Processor costs */
254       int target_enable;        /* Target flags to enable.  */
255       int target_disable;       /* Target flags to disable.  */
256     } processor_target_table[] = {
257       {PROCESSOR_I386_STRING, PROCESSOR_I386, &i386_cost, 0, 0},
258       {PROCESSOR_I486_STRING, PROCESSOR_I486, &i486_cost, 0, 0},
259       {PROCESSOR_I586_STRING, PROCESSOR_PENTIUM, &pentium_cost, 0, 0},
260       {PROCESSOR_PENTIUM_STRING, PROCESSOR_PENTIUM, &pentium_cost, 0, 0},
261       {PROCESSOR_I686_STRING, PROCESSOR_PENTIUMPRO, &pentiumpro_cost, 0, 0},
262       {PROCESSOR_PENTIUMPRO_STRING, PROCESSOR_PENTIUMPRO,
263        &pentiumpro_cost, 0, 0},
264       {PROCESSOR_K6_STRING, PROCESSOR_K6, &k6_cost, 0, 0}
265     };
266
267   int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
268
269 #ifdef SUBTARGET_OVERRIDE_OPTIONS
270   SUBTARGET_OVERRIDE_OPTIONS;
271 #endif
272
273   /* Validate registers in register allocation order.  */
274   if (i386_reg_alloc_order)
275     {
276       for (i = 0; (ch = i386_reg_alloc_order[i]) != '\0'; i++)
277         {
278           int regno = 0;
279
280           switch (ch)
281             {
282             case 'a':   regno = 0;      break;
283             case 'd':   regno = 1;      break;
284             case 'c':   regno = 2;      break;
285             case 'b':   regno = 3;      break;
286             case 'S':   regno = 4;      break;
287             case 'D':   regno = 5;      break;
288             case 'B':   regno = 6;      break;
289
290             default:    fatal ("Register '%c' is unknown", ch);
291             }
292
293           if (regs_allocated[regno])
294             fatal ("Register '%c' already specified in allocation order", ch);
295
296           regs_allocated[regno] = 1;
297         }
298     }
299
300   if (ix86_arch_string == 0)
301     {
302       ix86_arch_string = PROCESSOR_PENTIUM_STRING;
303       if (ix86_cpu_string == 0)
304         ix86_cpu_string = PROCESSOR_DEFAULT_STRING;
305     }
306
307   for (i = 0; i < ptt_size; i++)
308     if (! strcmp (ix86_arch_string, processor_target_table[i].name))
309       {
310         ix86_arch = processor_target_table[i].processor;
311         if (ix86_cpu_string == 0)
312           ix86_cpu_string = processor_target_table[i].name;
313         break;
314       }
315
316   if (i == ptt_size)
317     {
318       error ("bad value (%s) for -march= switch", ix86_arch_string);
319       ix86_arch_string = PROCESSOR_PENTIUM_STRING;
320       ix86_arch = PROCESSOR_DEFAULT;
321     }
322
323   if (ix86_cpu_string == 0)
324     ix86_cpu_string = PROCESSOR_DEFAULT_STRING;
325
326   for (j = 0; j < ptt_size; j++)
327     if (! strcmp (ix86_cpu_string, processor_target_table[j].name))
328       {
329         ix86_cpu = processor_target_table[j].processor;
330         ix86_cost = processor_target_table[j].cost;
331         if (i > j && (int) ix86_arch >= (int) PROCESSOR_K6)
332           error ("-mcpu=%s does not support -march=%s",
333                  ix86_cpu_string, ix86_arch_string);
334
335         target_flags |= processor_target_table[j].target_enable;
336         target_flags &= ~processor_target_table[j].target_disable;
337         break;
338       }
339
340   if (j == ptt_size)
341     {
342       error ("bad value (%s) for -mcpu= switch", ix86_cpu_string);
343       ix86_cpu_string = PROCESSOR_DEFAULT_STRING;
344       ix86_cpu = PROCESSOR_DEFAULT;
345     }
346
347   /* Validate -mregparm= value. */
348   if (i386_regparm_string)
349     {
350       i386_regparm = atoi (i386_regparm_string);
351       if (i386_regparm < 0 || i386_regparm > REGPARM_MAX)
352         fatal ("-mregparm=%d is not between 0 and %d",
353                i386_regparm, REGPARM_MAX);
354     }
355
356   /* The 486 suffers more from non-aligned cache line fills, and the
357      larger code size results in a larger cache foot-print and more misses.
358      The 486 has a 16 byte cache line, pentium and pentiumpro have a 32 byte
359      cache line.  */
360   def_align = (TARGET_486) ? 4 : 2;
361
362   /* Validate -malign-loops= value, or provide default.  */
363 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
364   i386_align_loops = 4;
365 #else
366   i386_align_loops = 2;
367 #endif
368   if (i386_align_loops_string)
369     {
370       i386_align_loops = atoi (i386_align_loops_string);
371       if (i386_align_loops < 0 || i386_align_loops > MAX_CODE_ALIGN)
372         fatal ("-malign-loops=%d is not between 0 and %d",
373                i386_align_loops, MAX_CODE_ALIGN);
374     }
375
376   /* Validate -malign-jumps= value, or provide default.  */
377 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
378   i386_align_jumps = 4;
379 #else
380   i386_align_jumps = def_align;
381 #endif
382   if (i386_align_jumps_string)
383     {
384       i386_align_jumps = atoi (i386_align_jumps_string);
385       if (i386_align_jumps < 0 || i386_align_jumps > MAX_CODE_ALIGN)
386         fatal ("-malign-jumps=%d is not between 0 and %d",
387                i386_align_jumps, MAX_CODE_ALIGN);
388     }
389
390   /* Validate -malign-functions= value, or provide default. */
391   i386_align_funcs = def_align;
392   if (i386_align_funcs_string)
393     {
394       i386_align_funcs = atoi (i386_align_funcs_string);
395       if (i386_align_funcs < 0 || i386_align_funcs > MAX_CODE_ALIGN)
396         fatal ("-malign-functions=%d is not between 0 and %d",
397                i386_align_funcs, MAX_CODE_ALIGN);
398     }
399
400   /* Validate -mpreferred_stack_boundary= value, or provide default.
401      The default of 128 bits is for Pentium III's SSE __m128.  */
402   i386_preferred_stack_boundary = 128;
403   if (i386_preferred_stack_boundary_string)
404     {
405       i = atoi (i386_preferred_stack_boundary_string);
406       if (i < 2 || i > 31)
407         fatal ("-mpreferred_stack_boundary=%d is not between 2 and 31", i);
408       i386_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
409     }
410
411   /* Validate -mbranch-cost= value, or provide default. */
412   i386_branch_cost = 1;
413   if (i386_branch_cost_string)
414     {
415       i386_branch_cost = atoi (i386_branch_cost_string);
416       if (i386_branch_cost < 0 || i386_branch_cost > 5)
417         fatal ("-mbranch-cost=%d is not between 0 and 5", i386_branch_cost);
418     }
419
420   /* Keep nonleaf frame pointers.  */
421   if (TARGET_OMIT_LEAF_FRAME_POINTER)
422     flag_omit_frame_pointer = 1;
423 }
424 \f
425 /* A C statement (sans semicolon) to choose the order in which to
426    allocate hard registers for pseudo-registers local to a basic
427    block.
428
429    Store the desired register order in the array `reg_alloc_order'.
430    Element 0 should be the register to allocate first; element 1, the
431    next register; and so on.
432
433    The macro body should not assume anything about the contents of
434    `reg_alloc_order' before execution of the macro.
435
436    On most machines, it is not necessary to define this macro.  */
437
438 void
439 order_regs_for_local_alloc ()
440 {
441   int i, ch, order;
442
443   /* User specified the register allocation order.  */
444
445   if (i386_reg_alloc_order)
446     {
447       for (i = order = 0; (ch = i386_reg_alloc_order[i]) != '\0'; i++)
448         {
449           int regno = 0;
450
451           switch (ch)
452             {
453             case 'a':   regno = 0;      break;
454             case 'd':   regno = 1;      break;
455             case 'c':   regno = 2;      break;
456             case 'b':   regno = 3;      break;
457             case 'S':   regno = 4;      break;
458             case 'D':   regno = 5;      break;
459             case 'B':   regno = 6;      break;
460             }
461
462           reg_alloc_order[order++] = regno;
463         }
464
465       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
466         {
467           if (! regs_allocated[i])
468             reg_alloc_order[order++] = i;
469         }
470     }
471
472   /* If user did not specify a register allocation order, use natural order. */
473   else
474     {
475       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
476         reg_alloc_order[i] = i;
477     }
478 }
479 \f
480 void
481 optimization_options (level, size)
482      int level;
483      int size ATTRIBUTE_UNUSED;
484 {
485   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
486      make the problem with not enough registers even worse.  */
487 #ifdef INSN_SCHEDULING
488   if (level > 1)
489     flag_schedule_insns = 0;
490 #endif
491 }
492 \f
493 /* Sign-extend a 16-bit constant */
494
495 struct rtx_def *
496 i386_sext16_if_const (op)
497      struct rtx_def *op;
498 {
499   if (GET_CODE (op) == CONST_INT)
500     {
501       HOST_WIDE_INT val = INTVAL (op);
502       HOST_WIDE_INT sext_val;
503       if (val & 0x8000)
504         sext_val = val | ~0xffff;
505       else
506         sext_val = val & 0xffff;
507       if (sext_val != val)
508         op = GEN_INT (sext_val);
509     }
510   return op;
511 }
512 \f
513 /* Return nonzero if the rtx is aligned */
514
515 static int
516 i386_aligned_reg_p (regno)
517      int regno;
518 {
519   return (regno == STACK_POINTER_REGNUM
520           || (! flag_omit_frame_pointer && regno == FRAME_POINTER_REGNUM));
521 }
522
523 int
524 i386_aligned_p (op)
525      rtx op;
526 {
527   /* Registers and immediate operands are always "aligned". */
528   if (GET_CODE (op) != MEM)
529     return 1;
530
531   /* Don't even try to do any aligned optimizations with volatiles. */
532   if (MEM_VOLATILE_P (op))
533     return 0;
534
535   /* Get address of memory operand. */
536   op = XEXP (op, 0);
537
538   switch (GET_CODE (op))
539     {
540     case CONST_INT:
541       if (INTVAL (op) & 3)
542         break;
543       return 1;
544
545       /* Match "reg + offset" */
546     case PLUS:
547       if (GET_CODE (XEXP (op, 1)) != CONST_INT)
548         break;
549       if (INTVAL (XEXP (op, 1)) & 3)
550         break;
551
552       op = XEXP (op, 0);
553       if (GET_CODE (op) != REG)
554         break;
555
556       /* ... fall through ... */
557
558     case REG:
559       return i386_aligned_reg_p (REGNO (op));
560
561     default:
562       break;
563     }
564
565   return 0;
566 }
567 \f
568 /* Return nonzero if INSN looks like it won't compute useful cc bits
569    as a side effect.  This information is only a hint. */
570
571 int
572 i386_cc_probably_useless_p (insn)
573      rtx insn;
574 {
575   return ! next_cc0_user (insn);
576 }
577 \f
578 /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific
579    attribute for DECL.  The attributes in ATTRIBUTES have previously been
580    assigned to DECL.  */
581
582 int
583 i386_valid_decl_attribute_p (decl, attributes, identifier, args)
584      tree decl ATTRIBUTE_UNUSED;
585      tree attributes ATTRIBUTE_UNUSED;
586      tree identifier ATTRIBUTE_UNUSED;
587      tree args ATTRIBUTE_UNUSED;
588 {
589   return 0;
590 }
591
592 /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific
593    attribute for TYPE.  The attributes in ATTRIBUTES have previously been
594    assigned to TYPE.  */
595
596 int
597 i386_valid_type_attribute_p (type, attributes, identifier, args)
598      tree type;
599      tree attributes ATTRIBUTE_UNUSED;
600      tree identifier;
601      tree args;
602 {
603   if (TREE_CODE (type) != FUNCTION_TYPE
604       && TREE_CODE (type) != METHOD_TYPE
605       && TREE_CODE (type) != FIELD_DECL
606       && TREE_CODE (type) != TYPE_DECL)
607     return 0;
608
609   /* Stdcall attribute says callee is responsible for popping arguments
610      if they are not variable.  */
611   if (is_attribute_p ("stdcall", identifier))
612     return (args == NULL_TREE);
613
614   /* Cdecl attribute says the callee is a normal C declaration. */
615   if (is_attribute_p ("cdecl", identifier))
616     return (args == NULL_TREE);
617
618   /* Regparm attribute specifies how many integer arguments are to be
619      passed in registers. */
620   if (is_attribute_p ("regparm", identifier))
621     {
622       tree cst;
623
624       if (! args || TREE_CODE (args) != TREE_LIST
625           || TREE_CHAIN (args) != NULL_TREE
626           || TREE_VALUE (args) == NULL_TREE)
627         return 0;
628
629       cst = TREE_VALUE (args);
630       if (TREE_CODE (cst) != INTEGER_CST)
631         return 0;
632
633       if (TREE_INT_CST_HIGH (cst) != 0
634           || TREE_INT_CST_LOW (cst) < 0
635           || TREE_INT_CST_LOW (cst) > REGPARM_MAX)
636         return 0;
637
638       return 1;
639     }
640
641   return 0;
642 }
643
644 /* Return 0 if the attributes for two types are incompatible, 1 if they
645    are compatible, and 2 if they are nearly compatible (which causes a
646    warning to be generated).  */
647
648 int
649 i386_comp_type_attributes (type1, type2)
650      tree type1;
651      tree type2;
652 {
653   /* Check for mismatch of non-default calling convention. */
654   char *rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
655
656   if (TREE_CODE (type1) != FUNCTION_TYPE)
657     return 1;
658
659   /* Check for mismatched return types (cdecl vs stdcall).  */
660   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
661       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
662     return 0;
663   return 1;
664 }
665
666 \f
667 /* Value is the number of bytes of arguments automatically
668    popped when returning from a subroutine call.
669    FUNDECL is the declaration node of the function (as a tree),
670    FUNTYPE is the data type of the function (as a tree),
671    or for a library call it is an identifier node for the subroutine name.
672    SIZE is the number of bytes of arguments passed on the stack.
673
674    On the 80386, the RTD insn may be used to pop them if the number
675      of args is fixed, but if the number is variable then the caller
676      must pop them all.  RTD can't be used for library calls now
677      because the library is compiled with the Unix compiler.
678    Use of RTD is a selectable option, since it is incompatible with
679    standard Unix calling sequences.  If the option is not selected,
680    the caller must always pop the args.
681
682    The attribute stdcall is equivalent to RTD on a per module basis.  */
683
684 int
685 i386_return_pops_args (fundecl, funtype, size)
686      tree fundecl;
687      tree funtype;
688      int size;
689 {
690   int rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
691
692     /* Cdecl functions override -mrtd, and never pop the stack. */
693   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype))) {
694
695     /* Stdcall functions will pop the stack if not variable args. */
696     if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype)))
697       rtd = 1;
698
699     if (rtd
700         && (TYPE_ARG_TYPES (funtype) == NULL_TREE
701             || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype)))
702                 == void_type_node)))
703       return size;
704   }
705
706   /* Lose any fake structure return argument.  */
707   if (aggregate_value_p (TREE_TYPE (funtype)))
708     return GET_MODE_SIZE (Pmode);
709
710     return 0;
711 }
712
713 \f
714 /* Argument support functions.  */
715
716 /* Initialize a variable CUM of type CUMULATIVE_ARGS
717    for a call to a function whose data type is FNTYPE.
718    For a library call, FNTYPE is 0.  */
719
720 void
721 init_cumulative_args (cum, fntype, libname)
722      CUMULATIVE_ARGS *cum;      /* Argument info to initialize */
723      tree fntype;               /* tree ptr for function decl */
724      rtx libname;               /* SYMBOL_REF of library name or 0 */
725 {
726   static CUMULATIVE_ARGS zero_cum;
727   tree param, next_param;
728
729   if (TARGET_DEBUG_ARG)
730     {
731       fprintf (stderr, "\ninit_cumulative_args (");
732       if (fntype)
733         fprintf (stderr, "fntype code = %s, ret code = %s",
734                  tree_code_name[(int) TREE_CODE (fntype)],
735                  tree_code_name[(int) TREE_CODE (TREE_TYPE (fntype))]);
736       else
737         fprintf (stderr, "no fntype");
738
739       if (libname)
740         fprintf (stderr, ", libname = %s", XSTR (libname, 0));
741     }
742
743   *cum = zero_cum;
744
745   /* Set up the number of registers to use for passing arguments.  */
746   cum->nregs = i386_regparm;
747   if (fntype)
748     {
749       tree attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (fntype));
750
751       if (attr)
752         cum->nregs = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
753     }
754
755   /* Determine if this function has variable arguments.  This is
756      indicated by the last argument being 'void_type_mode' if there
757      are no variable arguments.  If there are variable arguments, then
758      we won't pass anything in registers */
759
760   if (cum->nregs)
761     {
762       for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0;
763            param != 0; param = next_param)
764         {
765           next_param = TREE_CHAIN (param);
766           if (next_param == 0 && TREE_VALUE (param) != void_type_node)
767             cum->nregs = 0;
768         }
769     }
770
771   if (TARGET_DEBUG_ARG)
772     fprintf (stderr, ", nregs=%d )\n", cum->nregs);
773
774   return;
775 }
776
777 /* Update the data in CUM to advance over an argument
778    of mode MODE and data type TYPE.
779    (TYPE is null for libcalls where that information may not be available.)  */
780
781 void
782 function_arg_advance (cum, mode, type, named)
783      CUMULATIVE_ARGS *cum;      /* current arg information */
784      enum machine_mode mode;    /* current arg mode */
785      tree type;                 /* type of the argument or 0 if lib support */
786      int named;                 /* whether or not the argument was named */
787 {
788   int bytes
789     = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
790   int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
791
792   if (TARGET_DEBUG_ARG)
793     fprintf (stderr,
794              "function_adv (sz=%d, wds=%2d, nregs=%d, mode=%s, named=%d)\n\n",
795              words, cum->words, cum->nregs, GET_MODE_NAME (mode), named);
796
797   cum->words += words;
798   cum->nregs -= words;
799   cum->regno += words;
800
801   if (cum->nregs <= 0)
802     {
803       cum->nregs = 0;
804       cum->regno = 0;
805     }
806
807   return;
808 }
809
810 /* Define where to put the arguments to a function.
811    Value is zero to push the argument on the stack,
812    or a hard register in which to store the argument.
813
814    MODE is the argument's machine mode.
815    TYPE is the data type of the argument (as a tree).
816     This is null for libcalls where that information may
817     not be available.
818    CUM is a variable of type CUMULATIVE_ARGS which gives info about
819     the preceding args and about the function being called.
820    NAMED is nonzero if this argument is a named parameter
821     (otherwise it is an extra parameter matching an ellipsis).  */
822
823 struct rtx_def *
824 function_arg (cum, mode, type, named)
825      CUMULATIVE_ARGS *cum;      /* current arg information */
826      enum machine_mode mode;    /* current arg mode */
827      tree type;                 /* type of the argument or 0 if lib support */
828      int named;                 /* != 0 for normal args, == 0 for ... args */
829 {
830   rtx ret   = NULL_RTX;
831   int bytes
832     = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
833   int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
834
835   switch (mode)
836     {
837       /* For now, pass fp/complex values on the stack. */
838     default:
839       break;
840
841     case BLKmode:
842     case DImode:
843     case SImode:
844     case HImode:
845     case QImode:
846       if (words <= cum->nregs)
847         ret = gen_rtx_REG (mode, cum->regno);
848       break;
849     }
850
851   if (TARGET_DEBUG_ARG)
852     {
853       fprintf (stderr,
854                "function_arg (size=%d, wds=%2d, nregs=%d, mode=%4s, named=%d",
855                words, cum->words, cum->nregs, GET_MODE_NAME (mode), named);
856
857       if (ret)
858         fprintf (stderr, ", reg=%%e%s", reg_names[ REGNO(ret) ]);
859       else
860         fprintf (stderr, ", stack");
861
862       fprintf (stderr, " )\n");
863     }
864
865   return ret;
866 }
867
868 /* For an arg passed partly in registers and partly in memory,
869    this is the number of registers used.
870    For args passed entirely in registers or entirely in memory, zero.  */
871
872 int
873 function_arg_partial_nregs (cum, mode, type, named)
874      CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;     /* current arg information */
875      enum machine_mode mode ATTRIBUTE_UNUSED;   /* current arg mode */
876      tree type ATTRIBUTE_UNUSED;                /* type of the argument or 0 if lib support */
877      int named ATTRIBUTE_UNUSED;                /* != 0 for normal args, == 0 for ... args */
878 {
879   return 0;
880 }
881 \f
882 char *
883 singlemove_string (operands)
884      rtx *operands;
885 {
886   rtx x;
887   if (GET_CODE (operands[0]) == MEM
888       && GET_CODE (x = XEXP (operands[0], 0)) == PRE_DEC)
889     {
890       if (XEXP (x, 0) != stack_pointer_rtx)
891         abort ();
892       return "push%L1 %1";
893     }
894   else if (GET_CODE (operands[1]) == CONST_DOUBLE)
895     return output_move_const_single (operands);
896   else if (GET_CODE (operands[0]) == REG || GET_CODE (operands[1]) == REG)
897     return AS2 (mov%L0,%1,%0);
898   else if (CONSTANT_P (operands[1]))
899     return AS2 (mov%L0,%1,%0);
900   else
901     {
902       output_asm_insn ("push%L1 %1", operands);
903       return "pop%L0 %0";
904     }
905 }
906 \f
907 /* Output an insn to add the constant N to the register X.  */
908
909 static void
910 asm_add (n, x)
911      int n;
912      rtx x;
913 {
914   rtx xops[2];
915   xops[0] = x;
916
917   if (n == -1)
918     output_asm_insn (AS1 (dec%L0,%0), xops);
919   else if (n == 1)
920     output_asm_insn (AS1 (inc%L0,%0), xops);
921   else if (n < 0 || n == 128)
922     {
923       xops[1] = GEN_INT (-n);
924       output_asm_insn (AS2 (sub%L0,%1,%0), xops);
925     }
926   else if (n > 0)
927     {
928       xops[1] = GEN_INT (n);
929       output_asm_insn (AS2 (add%L0,%1,%0), xops);
930     }
931 }
932 \f
933 /* Output assembler code to perform a doubleword move insn
934    with operands OPERANDS.  */
935
936 char *
937 output_move_double (operands)
938      rtx *operands;
939 {
940   enum {REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
941   rtx latehalf[2];
942   rtx middlehalf[2];
943   rtx xops[2];
944   int dest_overlapped_low = 0;
945   int size = GET_MODE_SIZE (GET_MODE (operands[0]));
946
947   middlehalf[0] = 0;
948   middlehalf[1] = 0;
949
950   /* First classify both operands.  */
951
952   if (REG_P (operands[0]))
953     optype0 = REGOP;
954   else if (offsettable_memref_p (operands[0]))
955     optype0 = OFFSOP;
956   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
957     optype0 = POPOP;
958   else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
959     optype0 = PUSHOP;
960   else if (GET_CODE (operands[0]) == MEM)
961     optype0 = MEMOP;
962   else
963     optype0 = RNDOP;
964
965   if (REG_P (operands[1]))
966     optype1 = REGOP;
967   else if (CONSTANT_P (operands[1]))
968     optype1 = CNSTOP;
969   else if (offsettable_memref_p (operands[1]))
970     optype1 = OFFSOP;
971   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
972     optype1 = POPOP;
973   else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
974     optype1 = PUSHOP;
975   else if (GET_CODE (operands[1]) == MEM)
976     optype1 = MEMOP;
977   else
978     optype1 = RNDOP;
979
980   /* Check for the cases that are not supposed to happen
981      either due to the operand constraints or the fact
982      that all memory operands on the x86 are offsettable.
983      Abort if we get one, because generating code for these
984      cases is painful.  */
985
986   if (optype0 == RNDOP || optype1 == RNDOP
987       || optype0 == MEMOP || optype1 == MEMOP)
988     abort ();
989
990   /* If one operand is decrementing and one is incrementing
991      decrement the former register explicitly
992      and change that operand into ordinary indexing.  */
993
994   if (optype0 == PUSHOP && optype1 == POPOP)
995     {
996       /* ??? Can this ever happen on i386? */
997       operands[0] = XEXP (XEXP (operands[0], 0), 0);
998       asm_add (-size, operands[0]);
999       if (GET_MODE (operands[1]) == XFmode)
1000         operands[0] = gen_rtx_MEM (XFmode, operands[0]);
1001       else if (GET_MODE (operands[0]) == DFmode)
1002         operands[0] = gen_rtx_MEM (DFmode, operands[0]);
1003       else
1004         operands[0] = gen_rtx_MEM (DImode, operands[0]);
1005       optype0 = OFFSOP;
1006     }
1007
1008   if (optype0 == POPOP && optype1 == PUSHOP)
1009     {
1010       /* ??? Can this ever happen on i386? */
1011       operands[1] = XEXP (XEXP (operands[1], 0), 0);
1012       asm_add (-size, operands[1]);
1013       if (GET_MODE (operands[1]) == XFmode)
1014         operands[1] = gen_rtx_MEM (XFmode, operands[1]);
1015       else if (GET_MODE (operands[1]) == DFmode)
1016         operands[1] = gen_rtx_MEM (DFmode, operands[1]);
1017       else
1018         operands[1] = gen_rtx_MEM (DImode, operands[1]);
1019       optype1 = OFFSOP;
1020     }
1021
1022   /* Ok, we can do one word at a time.
1023      Normally we do the low-numbered word first,
1024      but if either operand is autodecrementing then we
1025      do the high-numbered word first.
1026
1027      In either case, set up in LATEHALF the operands to use
1028      for the high-numbered word and in some cases alter the
1029      operands in OPERANDS to be suitable for the low-numbered word.  */
1030
1031   if (size == 12)
1032     {
1033       if (optype0 == REGOP)
1034         {
1035           middlehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1036           latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 2);
1037         }
1038       else if (optype0 == OFFSOP)
1039         {
1040           middlehalf[0] = adj_offsettable_operand (operands[0], 4);
1041           latehalf[0] = adj_offsettable_operand (operands[0], 8);
1042         }
1043       else
1044         {
1045          middlehalf[0] = operands[0];
1046          latehalf[0] = operands[0];
1047         }
1048
1049       if (optype1 == REGOP)
1050         {
1051           middlehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1052           latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
1053         }
1054       else if (optype1 == OFFSOP)
1055         {
1056           middlehalf[1] = adj_offsettable_operand (operands[1], 4);
1057           latehalf[1] = adj_offsettable_operand (operands[1], 8);
1058         }
1059       else if (optype1 == CNSTOP)
1060         {
1061           if (GET_CODE (operands[1]) == CONST_DOUBLE)
1062             {
1063               REAL_VALUE_TYPE r; long l[3];
1064
1065               REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
1066               REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
1067               operands[1] = GEN_INT (l[0]);
1068               middlehalf[1] = GEN_INT (l[1]);
1069               latehalf[1] = GEN_INT (l[2]);
1070             }
1071           else if (CONSTANT_P (operands[1]))
1072             /* No non-CONST_DOUBLE constant should ever appear here.  */
1073             abort ();
1074         }
1075       else
1076         {
1077           middlehalf[1] = operands[1];
1078           latehalf[1] = operands[1];
1079         }
1080     }
1081
1082   else
1083     {
1084       /* Size is not 12. */
1085
1086       if (optype0 == REGOP)
1087         latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1088       else if (optype0 == OFFSOP)
1089         latehalf[0] = adj_offsettable_operand (operands[0], 4);
1090       else
1091         latehalf[0] = operands[0];
1092
1093       if (optype1 == REGOP)
1094         latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1095       else if (optype1 == OFFSOP)
1096         latehalf[1] = adj_offsettable_operand (operands[1], 4);
1097       else if (optype1 == CNSTOP)
1098         split_double (operands[1], &operands[1], &latehalf[1]);
1099       else
1100         latehalf[1] = operands[1];
1101     }
1102
1103   /* If insn is effectively movd N (sp),-(sp) then we will do the
1104      high word first.  We should use the adjusted operand 1
1105      (which is N+4 (sp) or N+8 (sp))
1106      for the low word and middle word as well,
1107      to compensate for the first decrement of sp.  */
1108   if (optype0 == PUSHOP
1109       && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
1110       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
1111     middlehalf[1] = operands[1] = latehalf[1];
1112
1113   /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
1114      if the upper part of reg N does not appear in the MEM, arrange to
1115      emit the move late-half first.  Otherwise, compute the MEM address
1116      into the upper part of N and use that as a pointer to the memory
1117      operand.  */
1118   if (optype0 == REGOP && optype1 == OFFSOP)
1119     {
1120       if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))
1121           && reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
1122         {
1123           /* If both halves of dest are used in the src memory address,
1124              compute the address into latehalf of dest.  */
1125         compadr:
1126           xops[0] = latehalf[0];
1127           xops[1] = XEXP (operands[1], 0);
1128           output_asm_insn (AS2 (lea%L0,%a1,%0), xops);
1129           if (GET_MODE (operands[1]) == XFmode)
1130             {
1131               operands[1] = gen_rtx_MEM (XFmode, latehalf[0]);
1132               middlehalf[1] = adj_offsettable_operand (operands[1], size-8);
1133               latehalf[1] = adj_offsettable_operand (operands[1], size-4);
1134             }
1135           else
1136             {
1137               operands[1] = gen_rtx_MEM (DImode, latehalf[0]);
1138               latehalf[1] = adj_offsettable_operand (operands[1], size-4);
1139             }
1140         }
1141
1142       else if (size == 12
1143                  && reg_mentioned_p (middlehalf[0], XEXP (operands[1], 0)))
1144         {
1145           /* Check for two regs used by both source and dest. */
1146           if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))
1147                 || reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
1148             goto compadr;
1149
1150           /* Only the middle reg conflicts; simply put it last. */
1151           output_asm_insn (singlemove_string (operands), operands);
1152           output_asm_insn (singlemove_string (latehalf), latehalf);
1153           output_asm_insn (singlemove_string (middlehalf), middlehalf);
1154           return "";
1155         }
1156
1157       else if (reg_mentioned_p (operands[0], XEXP (operands[1], 0)))
1158         /* If the low half of dest is mentioned in the source memory
1159            address, the arrange to emit the move late half first.  */
1160         dest_overlapped_low = 1;
1161     }
1162
1163   /* If one or both operands autodecrementing,
1164      do the two words, high-numbered first.  */
1165
1166   /* Likewise,  the first move would clobber the source of the second one,
1167      do them in the other order.  This happens only for registers;
1168      such overlap can't happen in memory unless the user explicitly
1169      sets it up, and that is an undefined circumstance.  */
1170
1171 #if 0
1172   if (optype0 == PUSHOP || optype1 == PUSHOP
1173       || (optype0 == REGOP && optype1 == REGOP
1174           && REGNO (operands[0]) == REGNO (latehalf[1]))
1175       || dest_overlapped_low)
1176 #endif
1177
1178   if (optype0 == PUSHOP || optype1 == PUSHOP
1179       || (optype0 == REGOP && optype1 == REGOP
1180           && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
1181               || REGNO (operands[0]) == REGNO (latehalf[1])))
1182       || dest_overlapped_low)
1183     {
1184       /* Do the high-numbered word.  */
1185       output_asm_insn (singlemove_string (latehalf), latehalf);
1186
1187       if (size == 12)
1188         output_asm_insn (singlemove_string (middlehalf), middlehalf);
1189
1190       /* Do low-numbered word.  */
1191       return singlemove_string (operands);
1192     }
1193
1194   /* Normal case: do the two words, low-numbered first.  */
1195
1196   output_asm_insn (singlemove_string (operands), operands);
1197
1198   /* Do the middle one of the three words for long double */
1199   if (size == 12)
1200     output_asm_insn (singlemove_string (middlehalf), middlehalf);
1201
1202   /* Do the high-numbered word.  */
1203   output_asm_insn (singlemove_string (latehalf), latehalf);
1204
1205   return "";
1206 }
1207 \f
1208 #define MAX_TMPS 2              /* max temporary registers used */
1209
1210 /* Output the appropriate code to move push memory on the stack */
1211
1212 char *
1213 output_move_pushmem (operands, insn, length, tmp_start, n_operands)
1214      rtx operands[];
1215      rtx insn;
1216      int length;
1217      int tmp_start;
1218      int n_operands;
1219 {
1220   struct
1221     {
1222       char *load;
1223       char *push;
1224       rtx   xops[2];
1225     } tmp_info[MAX_TMPS];
1226
1227   rtx src = operands[1];
1228   int max_tmps = 0;
1229   int offset = 0;
1230   int stack_p = reg_overlap_mentioned_p (stack_pointer_rtx, src);
1231   int stack_offset = 0;
1232   int i, num_tmps;
1233   rtx xops[1];
1234
1235   if (! offsettable_memref_p (src))
1236     fatal_insn ("Source is not offsettable", insn);
1237
1238   if ((length & 3) != 0)
1239     fatal_insn ("Pushing non-word aligned size", insn);
1240
1241   /* Figure out which temporary registers we have available */
1242   for (i = tmp_start; i < n_operands; i++)
1243     {
1244       if (GET_CODE (operands[i]) == REG)
1245         {
1246           if (reg_overlap_mentioned_p (operands[i], src))
1247             continue;
1248
1249           tmp_info[ max_tmps++ ].xops[1] = operands[i];
1250           if (max_tmps == MAX_TMPS)
1251             break;
1252         }
1253     }
1254
1255   if (max_tmps == 0)
1256     for (offset = length - 4; offset >= 0; offset -= 4)
1257       {
1258         xops[0] = adj_offsettable_operand (src, offset + stack_offset);
1259         output_asm_insn (AS1(push%L0,%0), xops);
1260         if (stack_p)
1261           stack_offset += 4;
1262       }
1263
1264   else
1265     for (offset = length - 4; offset >= 0; )
1266       {
1267         for (num_tmps = 0; num_tmps < max_tmps && offset >= 0; num_tmps++)
1268           {
1269             tmp_info[num_tmps].load    = AS2(mov%L0,%0,%1);
1270             tmp_info[num_tmps].push    = AS1(push%L0,%1);
1271             tmp_info[num_tmps].xops[0]
1272               = adj_offsettable_operand (src, offset + stack_offset);
1273             offset -= 4;
1274           }
1275
1276         for (i = 0; i < num_tmps; i++)
1277           output_asm_insn (tmp_info[i].load, tmp_info[i].xops);
1278
1279         for (i = 0; i < num_tmps; i++)
1280           output_asm_insn (tmp_info[i].push, tmp_info[i].xops);
1281
1282         if (stack_p)
1283           stack_offset += 4*num_tmps;
1284       }
1285
1286   return "";
1287 }
1288 \f
1289 int
1290 standard_80387_constant_p (x)
1291      rtx x;
1292 {
1293 #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1294   REAL_VALUE_TYPE d;
1295   jmp_buf handler;
1296   int is0, is1;
1297
1298   if (setjmp (handler))
1299     return 0;
1300
1301   set_float_handler (handler);
1302   REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1303   is0 = REAL_VALUES_EQUAL (d, dconst0) && !REAL_VALUE_MINUS_ZERO (d);
1304   is1 = REAL_VALUES_EQUAL (d, dconst1);
1305   set_float_handler (NULL_PTR);
1306
1307   if (is0)
1308     return 1;
1309
1310   if (is1)
1311     return 2;
1312
1313   /* Note that on the 80387, other constants, such as pi,
1314      are much slower to load as standard constants
1315      than to load from doubles in memory!  */
1316   /* ??? Not true on K6: all constants are equal cost.  */
1317 #endif
1318
1319   return 0;
1320 }
1321
1322 char *
1323 output_move_const_single (operands)
1324      rtx *operands;
1325 {
1326   if (FP_REG_P (operands[0]))
1327     {
1328       int conval = standard_80387_constant_p (operands[1]);
1329
1330       if (conval == 1)
1331         return "fldz";
1332
1333       if (conval == 2)
1334         return "fld1";
1335     }
1336
1337   if (GET_CODE (operands[1]) == CONST_DOUBLE)
1338     {
1339       REAL_VALUE_TYPE r; long l;
1340
1341       if (GET_MODE (operands[1]) == XFmode)
1342         abort ();
1343
1344       REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
1345       REAL_VALUE_TO_TARGET_SINGLE (r, l);
1346       operands[1] = GEN_INT (l);
1347     }
1348
1349   return singlemove_string (operands);
1350 }
1351 \f
1352 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
1353    reference and a constant.  */
1354
1355 int
1356 symbolic_operand (op, mode)
1357      register rtx op;
1358      enum machine_mode mode ATTRIBUTE_UNUSED;
1359 {
1360   switch (GET_CODE (op))
1361     {
1362     case SYMBOL_REF:
1363     case LABEL_REF:
1364       return 1;
1365
1366     case CONST:
1367       op = XEXP (op, 0);
1368       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
1369                || GET_CODE (XEXP (op, 0)) == LABEL_REF)
1370               && GET_CODE (XEXP (op, 1)) == CONST_INT);
1371
1372     default:
1373       return 0;
1374     }
1375 }
1376
1377 /* Return nonzero if OP is a constant shift count small enough to
1378    encode into an lea instruction.  */
1379
1380 int
1381 small_shift_operand (op, mode)
1382      rtx op;
1383      enum machine_mode mode ATTRIBUTE_UNUSED;
1384 {
1385   return (GET_CODE (op) == CONST_INT && INTVAL (op) > 0 && INTVAL (op) < 4);
1386 }
1387
1388 /* Test for a valid operand for a call instruction.
1389    Don't allow the arg pointer register or virtual regs
1390    since they may change into reg + const, which the patterns
1391    can't handle yet.  */
1392
1393 int
1394 call_insn_operand (op, mode)
1395      rtx op;
1396      enum machine_mode mode ATTRIBUTE_UNUSED;
1397 {
1398   if (GET_CODE (op) == MEM
1399       && ((CONSTANT_ADDRESS_P (XEXP (op, 0))
1400            /* This makes a difference for PIC.  */
1401            && general_operand (XEXP (op, 0), Pmode))
1402           || (GET_CODE (XEXP (op, 0)) == REG
1403               && XEXP (op, 0) != arg_pointer_rtx
1404               && ! (REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER
1405                     && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER))))
1406     return 1;
1407
1408   return 0;
1409 }
1410
1411 /* Like call_insn_operand but allow (mem (symbol_ref ...))
1412    even if pic.  */
1413
1414 int
1415 expander_call_insn_operand (op, mode)
1416      rtx op;
1417      enum machine_mode mode ATTRIBUTE_UNUSED;
1418 {
1419   if (GET_CODE (op) == MEM
1420       && (CONSTANT_ADDRESS_P (XEXP (op, 0))
1421           || (GET_CODE (XEXP (op, 0)) == REG
1422               && XEXP (op, 0) != arg_pointer_rtx
1423               && ! (REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER
1424                     && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER))))
1425     return 1;
1426
1427   return 0;
1428 }
1429
1430 /* Return 1 if OP is a comparison operator that can use the condition code
1431    generated by an arithmetic operation. */
1432
1433 int
1434 arithmetic_comparison_operator (op, mode)
1435      register rtx op;
1436      enum machine_mode mode;
1437 {
1438   enum rtx_code code;
1439
1440   if (mode != VOIDmode && mode != GET_MODE (op))
1441     return 0;
1442
1443   code = GET_CODE (op);
1444   if (GET_RTX_CLASS (code) != '<')
1445     return 0;
1446
1447   return (code != GT && code != LE);
1448 }
1449
1450 int
1451 ix86_logical_operator (op, mode)
1452      register rtx op;
1453      enum machine_mode mode ATTRIBUTE_UNUSED;
1454 {
1455   return GET_CODE (op) == AND || GET_CODE (op) == IOR || GET_CODE (op) == XOR;
1456 }
1457
1458 \f
1459 /* Returns 1 if OP contains a symbol reference */
1460
1461 int
1462 symbolic_reference_mentioned_p (op)
1463      rtx op;
1464 {
1465   register char *fmt;
1466   register int i;
1467
1468   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
1469     return 1;
1470
1471   fmt = GET_RTX_FORMAT (GET_CODE (op));
1472   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
1473     {
1474       if (fmt[i] == 'E')
1475         {
1476           register int j;
1477
1478           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
1479             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
1480               return 1;
1481         }
1482
1483       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
1484         return 1;
1485     }
1486
1487   return 0;
1488 }
1489 \f
1490 /* Attempt to expand a binary operator.  Make the expansion closer to the
1491    actual machine, then just general_operand, which will allow 3 separate
1492    memory references (one output, two input) in a single insn.  Return
1493    whether the insn fails, or succeeds.  */
1494
1495 int
1496 ix86_expand_binary_operator (code, mode, operands)
1497      enum rtx_code code;
1498      enum machine_mode mode;
1499      rtx operands[];
1500 {
1501   int modified;
1502
1503   /* Recognize <var1> = <value> <op> <var1> for commutative operators */
1504   if (GET_RTX_CLASS (code) == 'c'
1505       && (rtx_equal_p (operands[0], operands[2])
1506           || immediate_operand (operands[1], mode)))
1507     {
1508       rtx temp = operands[1];
1509       operands[1] = operands[2];
1510       operands[2] = temp;
1511     }
1512
1513   /* If optimizing, copy to regs to improve CSE */
1514   if (TARGET_PSEUDO && optimize
1515       && ((reload_in_progress | reload_completed) == 0))
1516     {
1517       if (GET_CODE (operands[1]) == MEM
1518           && ! rtx_equal_p (operands[0], operands[1]))
1519         operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
1520
1521       if (GET_CODE (operands[2]) == MEM)
1522         operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
1523
1524       if (GET_CODE (operands[1]) == CONST_INT && code == MINUS)
1525         {
1526           rtx temp = gen_reg_rtx (GET_MODE (operands[0]));
1527
1528           emit_move_insn (temp, operands[1]);
1529           operands[1] = temp;
1530           return TRUE;
1531         }
1532     }
1533
1534   if (!ix86_binary_operator_ok (code, mode, operands))
1535     {
1536       /* If not optimizing, try to make a valid insn (optimize code
1537          previously did this above to improve chances of CSE) */
1538
1539       if ((! TARGET_PSEUDO || !optimize)
1540           && ((reload_in_progress | reload_completed) == 0)
1541           && (GET_CODE (operands[1]) == MEM || GET_CODE (operands[2]) == MEM))
1542         {
1543           modified = FALSE;
1544           if (GET_CODE (operands[1]) == MEM
1545               && ! rtx_equal_p (operands[0], operands[1]))
1546             {
1547               operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
1548               modified = TRUE;
1549             }
1550
1551           if (GET_CODE (operands[2]) == MEM)
1552             {
1553               operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
1554               modified = TRUE;
1555             }
1556
1557           if (GET_CODE (operands[1]) == CONST_INT && code == MINUS)
1558             {
1559               rtx temp = gen_reg_rtx (GET_MODE (operands[0]));
1560
1561               emit_move_insn (temp, operands[1]);
1562               operands[1] = temp;
1563               return TRUE;
1564             }
1565
1566           if (modified && ! ix86_binary_operator_ok (code, mode, operands))
1567             return FALSE;
1568         }
1569       else
1570         return FALSE;
1571     }
1572
1573   return TRUE;
1574 }
1575 \f
1576 /* Return TRUE or FALSE depending on whether the binary operator meets the
1577    appropriate constraints.  */
1578
1579 int
1580 ix86_binary_operator_ok (code, mode, operands)
1581      enum rtx_code code;
1582      enum machine_mode mode ATTRIBUTE_UNUSED;
1583      rtx operands[3];
1584 {
1585   return (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
1586     && (GET_CODE (operands[1]) != CONST_INT || GET_RTX_CLASS (code) == 'c');
1587 }
1588 \f
1589 /* Attempt to expand a unary operator.  Make the expansion closer to the
1590    actual machine, then just general_operand, which will allow 2 separate
1591    memory references (one output, one input) in a single insn.  Return
1592    whether the insn fails, or succeeds.  */
1593
1594 int
1595 ix86_expand_unary_operator (code, mode, operands)
1596      enum rtx_code code;
1597      enum machine_mode mode;
1598      rtx operands[];
1599 {
1600   /* If optimizing, copy to regs to improve CSE */
1601   if (TARGET_PSEUDO
1602       && optimize
1603       && ((reload_in_progress | reload_completed) == 0)
1604       && GET_CODE (operands[1]) == MEM)
1605     operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
1606
1607   if (! ix86_unary_operator_ok (code, mode, operands))
1608     {
1609       if ((! TARGET_PSEUDO || optimize == 0)
1610           && ((reload_in_progress | reload_completed) == 0)
1611           && GET_CODE (operands[1]) == MEM)
1612         {
1613           operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
1614           if (! ix86_unary_operator_ok (code, mode, operands))
1615             return FALSE;
1616         }
1617       else
1618         return FALSE;
1619     }
1620
1621   return TRUE;
1622 }
1623 \f
1624 /* Return TRUE or FALSE depending on whether the unary operator meets the
1625    appropriate constraints.  */
1626
1627 int
1628 ix86_unary_operator_ok (code, mode, operands)
1629      enum rtx_code code ATTRIBUTE_UNUSED;
1630      enum machine_mode mode ATTRIBUTE_UNUSED;
1631      rtx operands[2] ATTRIBUTE_UNUSED;
1632 {
1633   return TRUE;
1634 }
1635 \f
1636 static rtx pic_label_rtx;
1637 static char pic_label_name [256];
1638 static int pic_label_no = 0;
1639
1640 /* This function generates code for -fpic that loads %ebx with
1641    the return address of the caller and then returns.  */
1642
1643 void
1644 asm_output_function_prefix (file, name)
1645      FILE *file;
1646      char *name ATTRIBUTE_UNUSED;
1647 {
1648   rtx xops[2];
1649   xops[0] = pic_offset_table_rtx;
1650   xops[1] = stack_pointer_rtx;
1651
1652   /* Deep branch prediction favors having a return for every call. */
1653   if (PIC_REG_USED && TARGET_DEEP_BRANCH_PREDICTION)
1654     {
1655       tree prologue_node;
1656
1657       if (pic_label_rtx == 0)
1658         {
1659           pic_label_rtx = gen_label_rtx ();
1660           ASM_GENERATE_INTERNAL_LABEL (pic_label_name, "LPR", pic_label_no++);
1661           LABEL_NAME (pic_label_rtx) = pic_label_name;
1662         }
1663
1664       prologue_node = make_node (FUNCTION_DECL);
1665       DECL_RESULT (prologue_node) = 0;
1666
1667       /* This used to call ASM_DECLARE_FUNCTION_NAME() but since it's an
1668          internal (non-global) label that's being emitted, it didn't make
1669          sense to have .type information for local labels.   This caused
1670          the SCO OpenServer 5.0.4 ELF assembler grief (why are you giving
1671          me debug info for a label that you're declaring non-global?) this
1672          was changed to call ASM_OUTPUT_LABEL() instead. */
1673
1674
1675       ASM_OUTPUT_LABEL (file, pic_label_name); 
1676       output_asm_insn ("movl (%1),%0", xops);
1677       output_asm_insn ("ret", xops);
1678     }
1679 }
1680
1681 /* Generate the assembly code for function entry.
1682    FILE is an stdio stream to output the code to.
1683    SIZE is an int: how many units of temporary storage to allocate. */
1684
1685 void
1686 function_prologue (file, size)
1687      FILE *file ATTRIBUTE_UNUSED;
1688      int size ATTRIBUTE_UNUSED;
1689 {
1690   if (TARGET_SCHEDULE_PROLOGUE)
1691     {
1692       pic_label_rtx = 0;
1693       return;
1694     }
1695
1696   ix86_prologue (0);
1697 }
1698
1699 /* Expand the prologue into a bunch of separate insns. */
1700
1701 void
1702 ix86_expand_prologue ()
1703 {
1704   if (! TARGET_SCHEDULE_PROLOGUE)
1705       return;
1706
1707   ix86_prologue (1);
1708 }
1709
1710 void
1711 load_pic_register (do_rtl)
1712      int do_rtl;
1713 {
1714   rtx xops[4];
1715
1716   if (TARGET_DEEP_BRANCH_PREDICTION)
1717     {
1718       xops[0] = pic_offset_table_rtx;
1719       if (pic_label_rtx == 0)
1720         {
1721           pic_label_rtx = gen_label_rtx ();
1722           ASM_GENERATE_INTERNAL_LABEL (pic_label_name, "LPR", pic_label_no++);
1723           LABEL_NAME (pic_label_rtx) = pic_label_name;
1724         }
1725
1726       xops[1] = gen_rtx_MEM (QImode,
1727                          gen_rtx (SYMBOL_REF, Pmode,
1728                                   LABEL_NAME (pic_label_rtx)));
1729
1730       if (do_rtl)
1731         {
1732           emit_insn (gen_prologue_get_pc (xops[0], xops[1]));
1733           emit_insn (gen_prologue_set_got (xops[0],
1734 #ifdef YES_UNDERSCORES
1735                                            gen_rtx_SYMBOL_REF (Pmode,
1736                                                     "$__GLOBAL_OFFSET_TABLE_"),
1737 #else
1738                                            gen_rtx_SYMBOL_REF (Pmode,
1739                                                     "$_GLOBAL_OFFSET_TABLE_"),
1740 #endif
1741                                            xops[1]));
1742         }
1743       else
1744         {
1745           output_asm_insn (AS1 (call,%X1), xops);
1746           output_asm_insn ("addl $%__GLOBAL_OFFSET_TABLE_,%0", xops);
1747           pic_label_rtx = 0;
1748         }
1749     }
1750
1751   else
1752     {
1753       xops[0] = pic_offset_table_rtx;
1754       xops[1] = gen_label_rtx ();
1755
1756       if (do_rtl)
1757         {
1758           /* We can't put a raw CODE_LABEL into the RTL, and we can't emit
1759              a new CODE_LABEL after reload, so we need a single pattern to
1760              emit the 3 necessary instructions.  */
1761           emit_insn (gen_prologue_get_pc_and_set_got (xops[0]));
1762         }
1763       else
1764         {
1765           output_asm_insn (AS1 (call,%P1), xops);
1766           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
1767                                      CODE_LABEL_NUMBER (xops[1]));
1768           output_asm_insn (AS1 (pop%L0,%0), xops);
1769           output_asm_insn ("addl $%__GLOBAL_OFFSET_TABLE_+[.-%P1],%0", xops);
1770         }
1771     }
1772
1773   /* When -fpic, we must emit a scheduling barrier, so that the instruction
1774      that restores %ebx (which is PIC_OFFSET_TABLE_REGNUM), does not get
1775      moved before any instruction which implicitly uses the got.   */
1776
1777   if (do_rtl)
1778     emit_insn (gen_blockage ());
1779 }
1780
1781 /* Compute the size of local storage taking into consideration the
1782    desired stack alignment which is to be maintained.  Also determine
1783    the number of registers saved below the local storage.  */
1784
1785 HOST_WIDE_INT
1786 ix86_compute_frame_size (size, nregs_on_stack)
1787      HOST_WIDE_INT size;
1788      int *nregs_on_stack;
1789 {
1790   int limit;
1791   int nregs;
1792   int regno;
1793   int padding;
1794   int pic_reg_used = PIC_REG_USED;
1795   HOST_WIDE_INT total_size;
1796
1797   limit = frame_pointer_needed
1798           ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM;
1799
1800   nregs = 0;
1801
1802   for (regno = limit - 1; regno >= 0; regno--)
1803     if ((regs_ever_live[regno] && ! call_used_regs[regno])
1804         || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
1805       nregs++;
1806
1807   padding = 0;
1808   total_size = size + (nregs * UNITS_PER_WORD);
1809
1810 #ifdef PREFERRED_STACK_BOUNDARY
1811   {
1812     int offset;
1813     int preferred_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
1814
1815     offset = 4;
1816     if (frame_pointer_needed)
1817       offset += UNITS_PER_WORD;
1818
1819     total_size += offset;
1820     
1821     padding = ((total_size + preferred_alignment - 1)
1822                & -preferred_alignment) - total_size;
1823
1824     if (padding < (((offset + preferred_alignment - 1)
1825                     & -preferred_alignment) - offset))
1826       padding += preferred_alignment;
1827
1828     /* Don't bother aligning the stack of a leaf function
1829        which doesn't allocate any stack slots.  */
1830     if (size == 0 && current_function_is_leaf)
1831       padding = 0;
1832   }
1833 #endif
1834
1835   if (nregs_on_stack)
1836     *nregs_on_stack = nregs;
1837
1838   return size + padding;
1839 }
1840
1841 static void
1842 ix86_prologue (do_rtl)
1843      int do_rtl;
1844 {
1845   register int regno;
1846   int limit;
1847   rtx xops[4];
1848   int pic_reg_used = PIC_REG_USED;
1849   HOST_WIDE_INT tsize = ix86_compute_frame_size (get_frame_size (), (int *)0);
1850   rtx insn;
1851   int cfa_offset = INCOMING_FRAME_SP_OFFSET, cfa_store_offset = cfa_offset;
1852
1853   xops[0] = stack_pointer_rtx;
1854   xops[1] = frame_pointer_rtx;
1855   xops[2] = GEN_INT (tsize);
1856
1857   if (frame_pointer_needed)
1858     {
1859       if (do_rtl)
1860         {
1861           insn = emit_insn (gen_rtx (SET, VOIDmode,
1862                                      gen_rtx_MEM (SImode,
1863                                               gen_rtx (PRE_DEC, SImode,
1864                                                        stack_pointer_rtx)),
1865                                      frame_pointer_rtx));
1866
1867           RTX_FRAME_RELATED_P (insn) = 1;
1868           insn = emit_move_insn (xops[1], xops[0]);
1869           RTX_FRAME_RELATED_P (insn) = 1;
1870         }
1871
1872       else
1873         {
1874           output_asm_insn ("push%L1 %1", xops);
1875 #ifdef INCOMING_RETURN_ADDR_RTX
1876           if (dwarf2out_do_frame ())
1877             {
1878               char *l = dwarf2out_cfi_label ();
1879
1880               cfa_store_offset += 4;
1881               cfa_offset = cfa_store_offset;
1882               dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, cfa_offset);
1883               dwarf2out_reg_save (l, FRAME_POINTER_REGNUM, - cfa_store_offset);
1884             }
1885 #endif
1886
1887           output_asm_insn (AS2 (mov%L0,%0,%1), xops);
1888 #ifdef INCOMING_RETURN_ADDR_RTX
1889           if (dwarf2out_do_frame ())
1890             dwarf2out_def_cfa ("", FRAME_POINTER_REGNUM, cfa_offset);
1891 #endif
1892         }
1893     }
1894
1895   if (tsize == 0)
1896     ;
1897   else if (! TARGET_STACK_PROBE || tsize < CHECK_STACK_LIMIT)
1898     {
1899       if (do_rtl)
1900         {
1901           insn = emit_insn (gen_prologue_set_stack_ptr (xops[2]));
1902           RTX_FRAME_RELATED_P (insn) = 1;
1903         }
1904       else
1905         {
1906           output_asm_insn (AS2 (sub%L0,%2,%0), xops);
1907 #ifdef INCOMING_RETURN_ADDR_RTX
1908           if (dwarf2out_do_frame ())
1909             {
1910               cfa_store_offset += tsize;
1911               if (! frame_pointer_needed)
1912                 {
1913                   cfa_offset = cfa_store_offset;
1914                   dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, cfa_offset);
1915                 }
1916             }
1917 #endif
1918         }
1919     }
1920   else
1921     {
1922       xops[3] = gen_rtx_REG (SImode, 0);
1923       if (do_rtl)
1924       emit_move_insn (xops[3], xops[2]);
1925       else
1926         output_asm_insn (AS2 (mov%L0,%2,%3), xops);
1927
1928       xops[3] = gen_rtx_MEM (FUNCTION_MODE,
1929                          gen_rtx (SYMBOL_REF, Pmode, "_alloca"));
1930
1931       if (do_rtl)
1932         emit_call_insn (gen_rtx (CALL, VOIDmode, xops[3], const0_rtx));
1933       else
1934         output_asm_insn (AS1 (call,%P3), xops);
1935     }
1936
1937   /* Note If use enter it is NOT reversed args.
1938      This one is not reversed from intel!!
1939      I think enter is slower.  Also sdb doesn't like it.
1940      But if you want it the code is:
1941      {
1942      xops[3] = const0_rtx;
1943      output_asm_insn ("enter %2,%3", xops);
1944      }
1945      */
1946
1947   limit = (frame_pointer_needed ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
1948   for (regno = limit - 1; regno >= 0; regno--)
1949     if ((regs_ever_live[regno] && ! call_used_regs[regno])
1950         || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
1951       {
1952         xops[0] = gen_rtx_REG (SImode, regno);
1953         if (do_rtl)
1954           {
1955             insn = emit_insn (gen_rtx (SET, VOIDmode,
1956                                        gen_rtx_MEM (SImode,
1957                                                 gen_rtx (PRE_DEC, SImode,
1958                                                          stack_pointer_rtx)),
1959                                        xops[0]));
1960
1961             RTX_FRAME_RELATED_P (insn) = 1;
1962           }
1963         else
1964           {
1965             output_asm_insn ("push%L0 %0", xops);
1966 #ifdef INCOMING_RETURN_ADDR_RTX
1967             if (dwarf2out_do_frame ())
1968               {
1969                 char *l = dwarf2out_cfi_label ();
1970
1971                 cfa_store_offset += 4;
1972                 if (! frame_pointer_needed)
1973                   {
1974                     cfa_offset = cfa_store_offset;
1975                     dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, cfa_offset);
1976                   }
1977
1978                 dwarf2out_reg_save (l, regno, - cfa_store_offset);
1979               }
1980 #endif
1981           }
1982       }
1983
1984 #ifdef SUBTARGET_PROLOGUE
1985   SUBTARGET_PROLOGUE;
1986 #endif  
1987
1988   if (pic_reg_used)
1989     load_pic_register (do_rtl);
1990
1991   /* If we are profiling, make sure no instructions are scheduled before
1992      the call to mcount.  However, if -fpic, the above call will have
1993      done that.  */
1994   if ((profile_flag || profile_block_flag)
1995       && ! pic_reg_used && do_rtl)
1996     emit_insn (gen_blockage ());
1997 }
1998
1999 /* Return 1 if it is appropriate to emit `ret' instructions in the
2000    body of a function.  Do this only if the epilogue is simple, needing a
2001    couple of insns.  Prior to reloading, we can't tell how many registers
2002    must be saved, so return 0 then.  Return 0 if there is no frame
2003    marker to de-allocate.
2004
2005    If NON_SAVING_SETJMP is defined and true, then it is not possible
2006    for the epilogue to be simple, so return 0.  This is a special case
2007    since NON_SAVING_SETJMP will not cause regs_ever_live to change
2008    until final, but jump_optimize may need to know sooner if a
2009    `return' is OK.  */
2010
2011 int
2012 ix86_can_use_return_insn_p ()
2013 {
2014   int regno;
2015   int nregs = 0;
2016   int reglimit = (frame_pointer_needed
2017                   ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
2018
2019 #ifdef TARGET_PROFILER_EPILOGUE
2020   if (TARGET_PROFILER_EPILOGUE)
2021     return 0;
2022 #endif
2023
2024 #ifdef NON_SAVING_SETJMP
2025   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
2026     return 0;
2027 #endif
2028
2029   if (! reload_completed)
2030     return 0;
2031
2032   for (regno = reglimit - 1; regno >= 0; regno--)
2033     if ((regs_ever_live[regno] && ! call_used_regs[regno])
2034         || (regno == PIC_OFFSET_TABLE_REGNUM && PIC_REG_USED))
2035       nregs++;
2036
2037   return nregs == 0 || ! frame_pointer_needed;
2038 }
2039
2040 /* This function generates the assembly code for function exit.
2041    FILE is an stdio stream to output the code to.
2042    SIZE is an int: how many units of temporary storage to deallocate. */
2043
2044 void
2045 function_epilogue (file, size)
2046      FILE *file ATTRIBUTE_UNUSED;
2047      int size ATTRIBUTE_UNUSED;
2048 {
2049     return;
2050 }
2051
2052 /* Restore function stack, frame, and registers. */
2053
2054 void
2055 ix86_expand_epilogue ()
2056 {
2057   ix86_epilogue (1);
2058 }
2059
2060 static void
2061 ix86_epilogue (do_rtl)
2062      int do_rtl;
2063 {
2064   register int regno;
2065   register int limit;
2066   int nregs;
2067   rtx xops[3];
2068   int pic_reg_used = PIC_REG_USED;
2069   int sp_valid = !frame_pointer_needed || current_function_sp_is_unchanging;
2070   HOST_WIDE_INT offset;
2071   HOST_WIDE_INT tsize = ix86_compute_frame_size (get_frame_size (), &nregs);
2072
2073   /* sp is often unreliable so we may have to go off the frame pointer. */
2074
2075   offset = -(tsize + nregs * UNITS_PER_WORD);
2076
2077   xops[2] = stack_pointer_rtx;
2078
2079   /* When -fpic, we must emit a scheduling barrier, so that the instruction
2080      that restores %ebx (which is PIC_OFFSET_TABLE_REGNUM), does not get
2081      moved before any instruction which implicitly uses the got.  This
2082      includes any instruction which uses a SYMBOL_REF or a LABEL_REF.
2083
2084      Alternatively, this could be fixed by making the dependence on the
2085      PIC_OFFSET_TABLE_REGNUM explicit in the RTL.  */
2086
2087   if (flag_pic || profile_flag || profile_block_flag)
2088     emit_insn (gen_blockage ());
2089
2090 #ifdef FUNCTION_PROFILER_EPILOGUE
2091   FUNCTION_PROFILER_EPILOGUE (asm_out_file, do_rtl);
2092 #endif
2093
2094   /* If we're only restoring one register and sp is not valid then
2095      using a move instruction to restore the register since it's
2096      less work than reloading sp and popping the register.  Otherwise,
2097      restore sp (if necessary) and pop the registers. */
2098
2099   limit = frame_pointer_needed
2100           ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM;
2101
2102   if (nregs > 1 || sp_valid)
2103     {
2104       if ( !sp_valid )
2105         {
2106           xops[0] = adj_offsettable_operand (AT_BP (QImode), offset);
2107           if (do_rtl)
2108             emit_insn (gen_movsi_lea (xops[2], XEXP (xops[0], 0)));
2109           else
2110             output_asm_insn (AS2 (lea%L2,%0,%2), xops);
2111         }
2112
2113       for (regno = 0; regno < limit; regno++)
2114         if ((regs_ever_live[regno] && ! call_used_regs[regno])
2115             || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
2116           {
2117             xops[0] = gen_rtx_REG (SImode, regno);
2118
2119             if (do_rtl)
2120               emit_insn (gen_pop (xops[0]));
2121             else
2122               output_asm_insn ("pop%L0 %0", xops);
2123           }
2124     }
2125
2126   else
2127     for (regno = 0; regno < limit; regno++)
2128       if ((regs_ever_live[regno] && ! call_used_regs[regno])
2129           || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
2130         {
2131           xops[0] = gen_rtx_REG (SImode, regno);
2132           xops[1] = adj_offsettable_operand (AT_BP (Pmode), offset);
2133
2134           if (do_rtl)
2135             emit_move_insn (xops[0], xops[1]);
2136           else
2137             output_asm_insn (AS2 (mov%L0,%1,%0), xops);
2138
2139           offset += 4;
2140         }
2141
2142   if (frame_pointer_needed)
2143     {
2144       /* If not an i386, mov & pop is faster than "leave". */
2145
2146       if (TARGET_USE_LEAVE)
2147         {
2148           if (do_rtl)
2149             emit_insn (gen_leave());
2150           else
2151             output_asm_insn ("leave", xops);
2152         }
2153       else
2154         {
2155           xops[0] = frame_pointer_rtx;
2156           xops[1] = stack_pointer_rtx;
2157
2158           if (do_rtl)
2159             {
2160               emit_insn (gen_epilogue_set_stack_ptr());
2161               emit_insn (gen_pop (xops[0]));
2162             }
2163           else
2164             {
2165               output_asm_insn (AS2 (mov%L2,%0,%2), xops);
2166               output_asm_insn ("pop%L0 %0", xops);
2167             }
2168         }
2169     }
2170
2171   else if (tsize)
2172     {
2173       /* Intel's docs say that for 4 or 8 bytes of stack frame one should
2174          use `pop' and not `add'.  */
2175       int use_pop = tsize == 4;
2176
2177       /* Use two pops only for the Pentium processors.  */
2178       if (tsize == 8 && !TARGET_386 && !TARGET_486)
2179         {
2180           rtx retval = current_function_return_rtx;
2181
2182           xops[1] = gen_rtx_REG (SImode, 1);    /* %edx */
2183
2184           /* This case is a bit more complex.  Since we cannot pop into
2185              %ecx twice we need a second register.  But this is only
2186              available if the return value is not of DImode in which
2187              case the %edx register is not available.  */
2188           use_pop = (retval == NULL
2189                      || ! reg_overlap_mentioned_p (xops[1], retval));
2190         }
2191
2192       if (use_pop)
2193         {
2194           xops[0] = gen_rtx_REG (SImode, 2);    /* %ecx */
2195
2196           if (do_rtl)
2197             {
2198               /* We have to prevent the two pops here from being scheduled.
2199                  GCC otherwise would try in some situation to put other
2200                  instructions in between them which has a bad effect.  */
2201               emit_insn (gen_blockage ());
2202               emit_insn (gen_pop (xops[0]));
2203               if (tsize == 8)
2204                 emit_insn (gen_pop (xops[1]));
2205             }
2206           else
2207             {
2208               output_asm_insn ("pop%L0 %0", xops);
2209               if (tsize == 8)
2210                 output_asm_insn ("pop%L1 %1", xops);
2211             }
2212         }
2213       else
2214         {
2215           /* If there is no frame pointer, we must still release the frame. */
2216           xops[0] = GEN_INT (tsize);
2217
2218           if (do_rtl)
2219             emit_insn (gen_rtx (SET, VOIDmode, xops[2],
2220                                 gen_rtx (PLUS, SImode, xops[2], xops[0])));
2221           else
2222             output_asm_insn (AS2 (add%L2,%0,%2), xops);
2223         }
2224     }
2225
2226 #ifdef FUNCTION_BLOCK_PROFILER_EXIT
2227   if (profile_block_flag == 2)
2228     {
2229       /* XXX this is hosed like FUNCTION_PROFILER_EPILOGUE () was.  */
2230       FUNCTION_BLOCK_PROFILER_EXIT(file);
2231     }
2232 #endif
2233
2234   if (current_function_pops_args && current_function_args_size)
2235     {
2236       xops[1] = GEN_INT (current_function_pops_args);
2237
2238       /* i386 can only pop 32K bytes (maybe 64K?  Is it signed?).  If
2239          asked to pop more, pop return address, do explicit add, and jump
2240          indirectly to the caller. */
2241
2242       if (current_function_pops_args >= 32768)
2243         {
2244           /* ??? Which register to use here? */
2245           xops[0] = gen_rtx_REG (SImode, 2);
2246
2247           if (do_rtl)
2248             {
2249               emit_insn (gen_pop (xops[0]));
2250               emit_insn (gen_rtx (SET, VOIDmode, xops[2],
2251                                   gen_rtx (PLUS, SImode, xops[1], xops[2])));
2252               emit_jump_insn (xops[0]);
2253             }
2254           else
2255             {
2256               output_asm_insn ("pop%L0 %0", xops);
2257               output_asm_insn (AS2 (add%L2,%1,%2), xops);
2258               output_asm_insn ("jmp %*%0", xops);
2259             }
2260         }
2261       else
2262         {
2263           if (do_rtl)
2264             emit_jump_insn (gen_return_pop_internal (xops[1]));
2265           else
2266             output_asm_insn ("ret %1", xops);
2267         }
2268     }
2269   else
2270     {
2271       if (do_rtl)
2272         emit_jump_insn (gen_return_internal ());
2273       else
2274         output_asm_insn ("ret", xops);
2275     }
2276 }
2277 \f
2278 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
2279    that is a valid memory address for an instruction.
2280    The MODE argument is the machine mode for the MEM expression
2281    that wants to use this address.
2282
2283    On x86, legitimate addresses are:
2284         base                            movl (base),reg
2285         displacement                    movl disp,reg
2286         base + displacement             movl disp(base),reg
2287         index + base                    movl (base,index),reg
2288         (index + base) + displacement   movl disp(base,index),reg
2289         index*scale                     movl (,index,scale),reg
2290         index*scale + disp              movl disp(,index,scale),reg
2291         index*scale + base              movl (base,index,scale),reg
2292         (index*scale + base) + disp     movl disp(base,index,scale),reg
2293
2294         In each case, scale can be 1, 2, 4, 8.  */
2295
2296 /* This is exactly the same as print_operand_addr, except that
2297    it recognizes addresses instead of printing them.
2298
2299    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
2300    convert common non-canonical forms to canonical form so that they will
2301    be recognized.  */
2302
2303 #define ADDR_INVALID(msg,insn)                                          \
2304 do {                                                                    \
2305   if (TARGET_DEBUG_ADDR)                                                \
2306     {                                                                   \
2307       fprintf (stderr, msg);                                            \
2308       debug_rtx (insn);                                                 \
2309     }                                                                   \
2310 } while (0)
2311
2312 int
2313 legitimate_pic_address_disp_p (disp)
2314      register rtx disp;
2315 {
2316   if (GET_CODE (disp) != CONST)
2317     return 0;
2318   disp = XEXP (disp, 0);
2319
2320   if (GET_CODE (disp) == PLUS)
2321     {
2322       if (GET_CODE (XEXP (disp, 1)) != CONST_INT)
2323         return 0;
2324       disp = XEXP (disp, 0);
2325     }
2326
2327   if (GET_CODE (disp) != UNSPEC
2328       || XVECLEN (disp, 0) != 1)
2329     return 0;
2330
2331   /* Must be @GOT or @GOTOFF.  */
2332   if (XINT (disp, 1) != 6
2333       && XINT (disp, 1) != 7)
2334     return 0;
2335
2336   if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
2337       && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
2338     return 0;
2339
2340   return 1;
2341 }
2342
2343 int
2344 legitimate_address_p (mode, addr, strict)
2345      enum machine_mode mode;
2346      register rtx addr;
2347      int strict;
2348 {
2349   rtx base  = NULL_RTX;
2350   rtx indx  = NULL_RTX;
2351   rtx scale = NULL_RTX;
2352   rtx disp  = NULL_RTX;
2353
2354   if (TARGET_DEBUG_ADDR)
2355     {
2356       fprintf (stderr,
2357                "\n======\nGO_IF_LEGITIMATE_ADDRESS, mode = %s, strict = %d\n",
2358                GET_MODE_NAME (mode), strict);
2359
2360       debug_rtx (addr);
2361     }
2362
2363   if (GET_CODE (addr) == REG || GET_CODE (addr) == SUBREG)
2364     base = addr;
2365
2366   else if (GET_CODE (addr) == PLUS)
2367     {
2368       rtx op0 = XEXP (addr, 0);
2369       rtx op1 = XEXP (addr, 1);
2370       enum rtx_code code0 = GET_CODE (op0);
2371       enum rtx_code code1 = GET_CODE (op1);
2372
2373       if (code0 == REG || code0 == SUBREG)
2374         {
2375           if (code1 == REG || code1 == SUBREG)
2376             {
2377               indx = op0;       /* index + base */
2378               base = op1;
2379             }
2380
2381           else
2382             {
2383               base = op0;       /* base + displacement */
2384               disp = op1;
2385             }
2386         }
2387
2388       else if (code0 == MULT)
2389         {
2390           indx  = XEXP (op0, 0);
2391           scale = XEXP (op0, 1);
2392
2393           if (code1 == REG || code1 == SUBREG)
2394             base = op1;         /* index*scale + base */
2395
2396           else
2397             disp = op1;         /* index*scale + disp */
2398         }
2399
2400       else if (code0 == PLUS && GET_CODE (XEXP (op0, 0)) == MULT)
2401         {
2402           indx  = XEXP (XEXP (op0, 0), 0);      /* index*scale + base + disp */
2403           scale = XEXP (XEXP (op0, 0), 1);
2404           base  = XEXP (op0, 1);
2405           disp  = op1;
2406         }
2407
2408       else if (code0 == PLUS)
2409         {
2410           indx = XEXP (op0, 0); /* index + base + disp */
2411           base = XEXP (op0, 1);
2412           disp = op1;
2413         }
2414
2415       else
2416         {
2417           ADDR_INVALID ("PLUS subcode is not valid.\n", op0);
2418           return FALSE;
2419         }
2420     }
2421
2422   else if (GET_CODE (addr) == MULT)
2423     {
2424       indx  = XEXP (addr, 0);   /* index*scale */
2425       scale = XEXP (addr, 1);
2426     }
2427
2428   else
2429     disp = addr;                /* displacement */
2430
2431   /* Allow arg pointer and stack pointer as index if there is not scaling */
2432   if (base && indx && !scale
2433       && (indx == arg_pointer_rtx || indx == stack_pointer_rtx))
2434     {
2435       rtx tmp = base;
2436       base = indx;
2437       indx = tmp;
2438     }
2439
2440   /* Validate base register:
2441
2442      Don't allow SUBREG's here, it can lead to spill failures when the base
2443      is one word out of a two word structure, which is represented internally
2444      as a DImode int.  */
2445
2446   if (base)
2447     {
2448       if (GET_CODE (base) != REG)
2449         {
2450           ADDR_INVALID ("Base is not a register.\n", base);
2451           return FALSE;
2452         }
2453
2454       if (GET_MODE (base) != Pmode)
2455         {
2456           ADDR_INVALID ("Base is not in Pmode.\n", base);
2457           return FALSE;
2458         }
2459
2460       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (base))
2461           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (base)))
2462         {
2463           ADDR_INVALID ("Base is not valid.\n", base);
2464           return FALSE;
2465         }
2466     }
2467
2468   /* Validate index register:
2469
2470      Don't allow SUBREG's here, it can lead to spill failures when the index
2471      is one word out of a two word structure, which is represented internally
2472      as a DImode int.  */
2473   if (indx)
2474     {
2475       if (GET_CODE (indx) != REG)
2476         {
2477           ADDR_INVALID ("Index is not a register.\n", indx);
2478           return FALSE;
2479         }
2480
2481       if (GET_MODE (indx) != Pmode)
2482         {
2483           ADDR_INVALID ("Index is not in Pmode.\n", indx);
2484           return FALSE;
2485         }
2486
2487       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (indx))
2488           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (indx)))
2489         {
2490           ADDR_INVALID ("Index is not valid.\n", indx);
2491           return FALSE;
2492         }
2493     }
2494   else if (scale)
2495     abort ();                   /* scale w/o index invalid */
2496
2497   /* Validate scale factor: */
2498   if (scale)
2499     {
2500       HOST_WIDE_INT value;
2501
2502       if (GET_CODE (scale) != CONST_INT)
2503         {
2504           ADDR_INVALID ("Scale is not valid.\n", scale);
2505           return FALSE;
2506         }
2507
2508       value = INTVAL (scale);
2509       if (value != 1 && value != 2 && value != 4 && value != 8)
2510         {
2511           ADDR_INVALID ("Scale is not a good multiplier.\n", scale);
2512           return FALSE;
2513         }
2514     }
2515
2516   /* Validate displacement.  */
2517   if (disp)
2518     {
2519       if (!CONSTANT_ADDRESS_P (disp))
2520         {
2521           ADDR_INVALID ("Displacement is not valid.\n", disp);
2522           return FALSE;
2523         }
2524
2525       else if (GET_CODE (disp) == CONST_DOUBLE)
2526         {
2527           ADDR_INVALID ("Displacement is a const_double.\n", disp);
2528           return FALSE;
2529         }
2530
2531       if (flag_pic && SYMBOLIC_CONST (disp))
2532         {
2533           if (! legitimate_pic_address_disp_p (disp))
2534             {
2535               ADDR_INVALID ("Displacement is an invalid PIC construct.\n",
2536                             disp);
2537               return FALSE;
2538             }
2539
2540           if (base != pic_offset_table_rtx
2541               && (indx != pic_offset_table_rtx || scale != NULL_RTX))
2542             {
2543               ADDR_INVALID ("PIC displacement against invalid base.\n", disp);
2544               return FALSE;
2545             }
2546         }
2547
2548       else if (HALF_PIC_P ())
2549         {
2550           if (! HALF_PIC_ADDRESS_P (disp)
2551               || (base != NULL_RTX || indx != NULL_RTX))
2552             {
2553               ADDR_INVALID ("Displacement is an invalid half-pic reference.\n",
2554                             disp);
2555               return FALSE;
2556             }
2557         }
2558     }
2559
2560   if (TARGET_DEBUG_ADDR)
2561     fprintf (stderr, "Address is valid.\n");
2562
2563   /* Everything looks valid, return true */
2564   return TRUE;
2565 }
2566 \f
2567 /* Return a legitimate reference for ORIG (an address) using the
2568    register REG.  If REG is 0, a new pseudo is generated.
2569
2570    There are two types of references that must be handled:
2571
2572    1. Global data references must load the address from the GOT, via
2573       the PIC reg.  An insn is emitted to do this load, and the reg is
2574       returned.
2575
2576    2. Static data references, constant pool addresses, and code labels
2577       compute the address as an offset from the GOT, whose base is in
2578       the PIC reg.  Static data objects have SYMBOL_REF_FLAG set to
2579       differentiate them from global data objects.  The returned
2580       address is the PIC reg + an unspec constant.
2581
2582    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2583    reg also appears in the address.  */
2584
2585 rtx
2586 legitimize_pic_address (orig, reg)
2587      rtx orig;
2588      rtx reg;
2589 {
2590   rtx addr = orig;
2591   rtx new = orig;
2592   rtx base;
2593
2594   if (GET_CODE (addr) == LABEL_REF
2595       || (GET_CODE (addr) == SYMBOL_REF
2596           && (CONSTANT_POOL_ADDRESS_P (addr)
2597               || SYMBOL_REF_FLAG (addr))))
2598     {
2599       /* This symbol may be referenced via a displacement from the PIC
2600          base address (@GOTOFF).  */
2601
2602       current_function_uses_pic_offset_table = 1;
2603       new = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, addr), 7);
2604       new = gen_rtx_CONST (VOIDmode, new);
2605       new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new);
2606
2607       if (reg != 0)
2608         {
2609           emit_move_insn (reg, new);
2610           new = reg;
2611         }
2612     }
2613   else if (GET_CODE (addr) == SYMBOL_REF)
2614     {
2615       /* This symbol must be referenced via a load from the
2616          Global Offset Table (@GOT). */
2617
2618       current_function_uses_pic_offset_table = 1;
2619       new = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, addr), 6);
2620       new = gen_rtx_CONST (VOIDmode, new);
2621       new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new);
2622       new = gen_rtx_MEM (Pmode, new);
2623       RTX_UNCHANGING_P (new) = 1;
2624
2625       if (reg == 0)
2626         reg = gen_reg_rtx (Pmode);
2627       emit_move_insn (reg, new);
2628       new = reg;
2629     }      
2630   else
2631     {
2632       if (GET_CODE (addr) == CONST)
2633         {
2634           addr = XEXP (addr, 0);
2635           if (GET_CODE (addr) == UNSPEC)
2636             {
2637               /* Check that the unspec is one of the ones we generate?  */
2638             }
2639           else if (GET_CODE (addr) != PLUS)
2640             abort();
2641         }
2642       if (GET_CODE (addr) == PLUS)
2643         {
2644           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
2645
2646           /* Check first to see if this is a constant offset from a @GOTOFF
2647              symbol reference.  */
2648           if ((GET_CODE (op0) == LABEL_REF
2649                || (GET_CODE (op0) == SYMBOL_REF
2650                    && (CONSTANT_POOL_ADDRESS_P (op0)
2651                        || SYMBOL_REF_FLAG (op0))))
2652               && GET_CODE (op1) == CONST_INT)
2653             {
2654               current_function_uses_pic_offset_table = 1;
2655               new = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, op0), 7);
2656               new = gen_rtx_PLUS (VOIDmode, new, op1);
2657               new = gen_rtx_CONST (VOIDmode, new);
2658               new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new);
2659
2660               if (reg != 0)
2661                 {
2662                   emit_move_insn (reg, new);
2663                   new = reg;
2664                 }
2665             }
2666           else
2667             {
2668               base = legitimize_pic_address (XEXP (addr, 0), reg);
2669               new  = legitimize_pic_address (XEXP (addr, 1),
2670                                              base == reg ? NULL_RTX : reg);
2671
2672               if (GET_CODE (new) == CONST_INT)
2673                 new = plus_constant (base, INTVAL (new));
2674               else
2675                 {
2676                   if (GET_CODE (new) == PLUS && CONSTANT_P (XEXP (new, 1)))
2677                     {
2678                       base = gen_rtx_PLUS (Pmode, base, XEXP (new, 0));
2679                       new = XEXP (new, 1);
2680                     }
2681                   new = gen_rtx_PLUS (Pmode, base, new);
2682                 }
2683             }
2684         }
2685     }
2686   return new;
2687 }
2688 \f
2689 /* Emit insns to move operands[1] into operands[0].  */
2690
2691 void
2692 emit_pic_move (operands, mode)
2693      rtx *operands;
2694      enum machine_mode mode ATTRIBUTE_UNUSED;
2695 {
2696   rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode);
2697
2698   if (GET_CODE (operands[0]) == MEM && SYMBOLIC_CONST (operands[1]))
2699     operands[1] = force_reg (Pmode, operands[1]);
2700   else
2701     operands[1] = legitimize_pic_address (operands[1], temp);
2702 }
2703 \f
2704 /* Try machine-dependent ways of modifying an illegitimate address
2705    to be legitimate.  If we find one, return the new, valid address.
2706    This macro is used in only one place: `memory_address' in explow.c.
2707
2708    OLDX is the address as it was before break_out_memory_refs was called.
2709    In some cases it is useful to look at this to decide what needs to be done.
2710
2711    MODE and WIN are passed so that this macro can use
2712    GO_IF_LEGITIMATE_ADDRESS.
2713
2714    It is always safe for this macro to do nothing.  It exists to recognize
2715    opportunities to optimize the output.
2716
2717    For the 80386, we handle X+REG by loading X into a register R and
2718    using R+REG.  R will go in a general reg and indexing will be used.
2719    However, if REG is a broken-out memory address or multiplication,
2720    nothing needs to be done because REG can certainly go in a general reg.
2721
2722    When -fpic is used, special handling is needed for symbolic references.
2723    See comments by legitimize_pic_address in i386.c for details.  */
2724
2725 rtx
2726 legitimize_address (x, oldx, mode)
2727      register rtx x;
2728      register rtx oldx ATTRIBUTE_UNUSED;
2729      enum machine_mode mode;
2730 {
2731   int changed = 0;
2732   unsigned log;
2733
2734   if (TARGET_DEBUG_ADDR)
2735     {
2736       fprintf (stderr, "\n==========\nLEGITIMIZE_ADDRESS, mode = %s\n",
2737                GET_MODE_NAME (mode));
2738       debug_rtx (x);
2739     }
2740
2741   if (flag_pic && SYMBOLIC_CONST (x))
2742     return legitimize_pic_address (x, 0);
2743
2744   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
2745   if (GET_CODE (x) == ASHIFT
2746       && GET_CODE (XEXP (x, 1)) == CONST_INT
2747       && (log = (unsigned)exact_log2 (INTVAL (XEXP (x, 1)))) < 4)
2748     {
2749       changed = 1;
2750       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
2751                         GEN_INT (1 << log));
2752     }
2753
2754   if (GET_CODE (x) == PLUS)
2755     {
2756       /* Canonicalize shifts by 0, 1, 2, 3 into multiply. */
2757
2758       if (GET_CODE (XEXP (x, 0)) == ASHIFT
2759           && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2760           && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) < 4)
2761         {
2762           changed = 1;
2763           XEXP (x, 0) = gen_rtx (MULT, Pmode,
2764                                  force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
2765                                  GEN_INT (1 << log));
2766         }
2767
2768       if (GET_CODE (XEXP (x, 1)) == ASHIFT
2769           && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
2770           && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 1), 1)))) < 4)
2771         {
2772           changed = 1;
2773           XEXP (x, 1) = gen_rtx (MULT, Pmode,
2774                                  force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
2775                                  GEN_INT (1 << log));
2776         }
2777
2778       /* Put multiply first if it isn't already. */
2779       if (GET_CODE (XEXP (x, 1)) == MULT)
2780         {
2781           rtx tmp = XEXP (x, 0);
2782           XEXP (x, 0) = XEXP (x, 1);
2783           XEXP (x, 1) = tmp;
2784           changed = 1;
2785         }
2786
2787       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
2788          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
2789          created by virtual register instantiation, register elimination, and
2790          similar optimizations.  */
2791       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
2792         {
2793           changed = 1;
2794           x = gen_rtx (PLUS, Pmode,
2795                        gen_rtx (PLUS, Pmode, XEXP (x, 0),
2796                                 XEXP (XEXP (x, 1), 0)),
2797                        XEXP (XEXP (x, 1), 1));
2798         }
2799
2800       /* Canonicalize
2801          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
2802          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
2803       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
2804                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
2805                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
2806                && CONSTANT_P (XEXP (x, 1)))
2807         {
2808           rtx constant;
2809           rtx other = NULL_RTX;
2810
2811           if (GET_CODE (XEXP (x, 1)) == CONST_INT)
2812             {
2813               constant = XEXP (x, 1);
2814               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
2815             }
2816           else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT)
2817             {
2818               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
2819               other = XEXP (x, 1);
2820             }
2821           else
2822             constant = 0;
2823
2824           if (constant)
2825             {
2826               changed = 1;
2827               x = gen_rtx (PLUS, Pmode,
2828                            gen_rtx (PLUS, Pmode, XEXP (XEXP (x, 0), 0),
2829                                     XEXP (XEXP (XEXP (x, 0), 1), 0)),
2830                            plus_constant (other, INTVAL (constant)));
2831             }
2832         }
2833
2834       if (changed && legitimate_address_p (mode, x, FALSE))
2835         return x;
2836
2837       if (GET_CODE (XEXP (x, 0)) == MULT)
2838         {
2839           changed = 1;
2840           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
2841         }
2842
2843       if (GET_CODE (XEXP (x, 1)) == MULT)
2844         {
2845           changed = 1;
2846           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
2847         }
2848
2849       if (changed
2850           && GET_CODE (XEXP (x, 1)) == REG
2851           && GET_CODE (XEXP (x, 0)) == REG)
2852         return x;
2853
2854       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
2855         {
2856           changed = 1;
2857           x = legitimize_pic_address (x, 0);
2858         }
2859
2860       if (changed && legitimate_address_p (mode, x, FALSE))
2861         return x;
2862
2863       if (GET_CODE (XEXP (x, 0)) == REG)
2864         {
2865           register rtx temp = gen_reg_rtx (Pmode);
2866           register rtx val  = force_operand (XEXP (x, 1), temp);
2867           if (val != temp)
2868             emit_move_insn (temp, val);
2869
2870           XEXP (x, 1) = temp;
2871           return x;
2872         }
2873
2874       else if (GET_CODE (XEXP (x, 1)) == REG)
2875         {
2876           register rtx temp = gen_reg_rtx (Pmode);
2877           register rtx val  = force_operand (XEXP (x, 0), temp);
2878           if (val != temp)
2879             emit_move_insn (temp, val);
2880
2881           XEXP (x, 0) = temp;
2882           return x;
2883         }
2884     }
2885
2886   return x;
2887 }
2888 \f
2889 /* Print an integer constant expression in assembler syntax.  Addition
2890    and subtraction are the only arithmetic that may appear in these
2891    expressions.  FILE is the stdio stream to write to, X is the rtx, and
2892    CODE is the operand print code from the output string.  */
2893
2894 static void
2895 output_pic_addr_const (file, x, code)
2896      FILE *file;
2897      rtx x;
2898      int code;
2899 {
2900   char buf[256];
2901
2902   switch (GET_CODE (x))
2903     {
2904     case PC:
2905       if (flag_pic)
2906         putc ('.', file);
2907       else
2908         abort ();
2909       break;
2910
2911     case SYMBOL_REF:
2912       assemble_name (file, XSTR (x, 0));
2913 #ifdef ASM_HACK_SYMBOLREF_CODE
2914       ASM_HACK_SYMBOLREF_CODE (XSTR (x, 0), code);
2915 #endif
2916       if (code == 'P' && ! SYMBOL_REF_FLAG (x))
2917         fputs ("@PLT", file);
2918       break;
2919
2920     case LABEL_REF:
2921       x = XEXP (x, 0);
2922       /* FALLTHRU */
2923     case CODE_LABEL:
2924       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2925       assemble_name (asm_out_file, buf);
2926       break;
2927
2928     case CONST_INT:
2929       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2930       break;
2931
2932     case CONST:
2933       /* This used to output parentheses around the expression,
2934          but that does not work on the 386 (either ATT or BSD assembler).  */
2935       output_pic_addr_const (file, XEXP (x, 0), code);
2936       break;
2937
2938     case CONST_DOUBLE:
2939       if (GET_MODE (x) == VOIDmode)
2940         {
2941           /* We can use %d if the number is <32 bits and positive.  */
2942           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
2943             fprintf (file, "0x%lx%08lx",
2944                      (unsigned long) CONST_DOUBLE_HIGH (x),
2945                      (unsigned long) CONST_DOUBLE_LOW (x));
2946           else
2947             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
2948         }
2949       else
2950         /* We can't handle floating point constants;
2951            PRINT_OPERAND must handle them.  */
2952         output_operand_lossage ("floating constant misused");
2953       break;
2954
2955     case PLUS:
2956       /* Some assemblers need integer constants to appear first.  */
2957       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2958         {
2959           output_pic_addr_const (file, XEXP (x, 0), code);
2960           fprintf (file, "+");
2961           output_pic_addr_const (file, XEXP (x, 1), code);
2962         }
2963       else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
2964         {
2965           output_pic_addr_const (file, XEXP (x, 1), code);
2966           fprintf (file, "+");
2967           output_pic_addr_const (file, XEXP (x, 0), code);
2968         }
2969       else
2970         abort ();
2971       break;
2972
2973     case MINUS:
2974       output_pic_addr_const (file, XEXP (x, 0), code);
2975       fprintf (file, "-");
2976       output_pic_addr_const (file, XEXP (x, 1), code);
2977       break;
2978
2979      case UNSPEC:
2980        if (XVECLEN (x, 0) != 1)
2981         abort ();
2982        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
2983        switch (XINT (x, 1))
2984         {
2985         case 6:
2986           fputs ("@GOT", file);
2987           break;
2988         case 7:
2989           fputs ("@GOTOFF", file);
2990           break;
2991         case 8:
2992           fputs ("@PLT", file);
2993           break;
2994         default:
2995           output_operand_lossage ("invalid UNSPEC as operand");
2996           break;
2997         }
2998        break;
2999
3000     default:
3001       output_operand_lossage ("invalid expression as operand");
3002     }
3003 }
3004 \f
3005 static void
3006 put_jump_code (code, reverse, file)
3007      enum rtx_code code;
3008      int reverse;
3009      FILE *file;
3010 {
3011   int flags = cc_prev_status.flags;
3012   int ieee = (TARGET_IEEE_FP && (flags & CC_IN_80387)
3013               && !(cc_prev_status.flags & CC_FCOMI));
3014   const char *suffix;
3015
3016   if (flags & CC_Z_IN_NOT_C)
3017     switch (code)
3018       {
3019       case EQ:
3020         fputs (reverse ? "c" : "nc", file);
3021         return;
3022
3023       case NE:
3024         fputs (reverse ? "nc" : "c", file);
3025         return;
3026
3027       default:
3028         abort ();
3029       }
3030   if (ieee)
3031     {
3032       switch (code)
3033         {
3034         case LE:
3035           suffix = reverse ? "ae" : "b";
3036           break;
3037         case GT:
3038         case LT:
3039         case GE:
3040           suffix = reverse ? "ne" : "e";
3041           break;
3042         case EQ:
3043           suffix = reverse ? "ne" : "e";
3044           break;
3045         case NE:
3046           suffix = reverse ? "e" : "ne";
3047           break;
3048         default:
3049           abort ();
3050         }
3051       fputs (suffix, file);
3052       return;
3053     }
3054   if (flags & CC_TEST_AX)
3055     abort();
3056   if ((flags & CC_NO_OVERFLOW) && (code == LE || code == GT))
3057     abort ();
3058   if (reverse)
3059     code = reverse_condition (code);
3060   switch (code)
3061     {
3062     case EQ:
3063       suffix = "e";
3064       break;
3065
3066     case NE:
3067       suffix = "ne";
3068       break;
3069
3070     case GT:
3071       suffix = flags & CC_IN_80387 ? "a" : "g";
3072       break;
3073
3074     case GTU:
3075       suffix = "a";
3076       break;
3077
3078     case LT:
3079       if (flags & CC_NO_OVERFLOW)
3080         suffix = "s";
3081       else
3082         suffix = flags & CC_IN_80387 ? "b" : "l";
3083       break;
3084
3085     case LTU:
3086       suffix = "b";
3087       break;
3088
3089     case GE:
3090       if (flags & CC_NO_OVERFLOW)
3091         suffix = "ns";
3092       else
3093         suffix = flags & CC_IN_80387 ? "ae" : "ge";
3094       break;
3095
3096     case GEU:
3097       suffix = "ae";
3098       break;
3099
3100     case LE:
3101       suffix = flags & CC_IN_80387 ? "be" : "le";
3102       break;
3103
3104     case LEU:
3105       suffix = "be";
3106       break;
3107
3108     default:
3109       abort ();
3110     }
3111   fputs (suffix, file);
3112 }
3113
3114 /* Append the correct conditional move suffix which corresponds to CODE.  */
3115
3116 static void
3117 put_condition_code (code, reverse_cc, mode, file)
3118      enum rtx_code code;
3119      int  reverse_cc;
3120      enum mode_class mode;
3121      FILE * file;
3122 {
3123   int ieee = (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)
3124               && ! (cc_prev_status.flags & CC_FCOMI));
3125   if (reverse_cc && ! ieee)
3126     code = reverse_condition (code);
3127
3128   if (mode == MODE_INT)
3129     switch (code)
3130       {
3131       case NE:
3132         if (cc_prev_status.flags & CC_Z_IN_NOT_C)
3133           fputs ("b", file);
3134         else
3135           fputs ("ne", file);
3136         return;
3137
3138       case EQ:
3139         if (cc_prev_status.flags & CC_Z_IN_NOT_C)
3140           fputs ("ae", file);
3141         else
3142           fputs ("e", file);
3143         return;
3144
3145       case GE:
3146         if (cc_prev_status.flags & CC_NO_OVERFLOW)
3147           fputs ("ns", file);
3148         else
3149           fputs ("ge", file);
3150         return;
3151
3152       case GT:
3153         fputs ("g", file);
3154         return;
3155
3156       case LE:
3157         fputs ("le", file);
3158         return;
3159
3160       case LT:
3161         if (cc_prev_status.flags & CC_NO_OVERFLOW)
3162           fputs ("s", file);
3163         else
3164           fputs ("l", file);
3165         return;
3166
3167       case GEU:
3168         fputs ("ae", file);
3169         return;
3170
3171       case GTU:
3172         fputs ("a", file);
3173         return;
3174
3175       case LEU:
3176         fputs ("be", file);
3177         return;
3178
3179       case LTU:
3180         fputs ("b", file);
3181         return;
3182
3183       default:
3184         output_operand_lossage ("Invalid %%C operand");
3185       }
3186
3187   else if (mode == MODE_FLOAT)
3188     switch (code)
3189       {
3190       case NE:
3191         fputs (ieee ? (reverse_cc ? "ne" : "e") : "ne", file);
3192         return;
3193       case EQ:
3194         fputs (ieee ? (reverse_cc ? "ne" : "e") : "e", file);
3195         return;
3196       case GE:
3197         fputs (ieee ? (reverse_cc ? "ne" : "e") : "nb", file);
3198         return;
3199       case GT:
3200         fputs (ieee ? (reverse_cc ? "ne" : "e") : "nbe", file);
3201         return;
3202       case LE:
3203         fputs (ieee ? (reverse_cc ? "nb" : "b") : "be", file);
3204         return;
3205       case LT:
3206         fputs (ieee ? (reverse_cc ? "ne" : "e") : "b", file);
3207         return;
3208       case GEU:
3209         fputs (ieee ? (reverse_cc ? "ne" : "e") : "nb", file);
3210         return;
3211       case GTU:
3212         fputs (ieee ? (reverse_cc ? "ne" : "e") : "nbe", file);
3213         return;
3214       case LEU:
3215         fputs (ieee ? (reverse_cc ? "nb" : "b") : "be", file);
3216         return;
3217       case LTU:
3218         fputs (ieee ? (reverse_cc ? "ne" : "e") : "b", file);
3219         return;
3220       default:
3221         output_operand_lossage ("Invalid %%C operand");
3222     }
3223 }
3224
3225 /* Meaning of CODE:
3226    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
3227    C -- print opcode suffix for set/cmov insn.
3228    c -- like C, but print reversed condition
3229    F -- print opcode suffix for fcmov insn.
3230    f -- like F, but print reversed condition
3231    D -- print the opcode suffix for a jump
3232    d -- like D, but print reversed condition
3233    R -- print the prefix for register names.
3234    z -- print the opcode suffix for the size of the current operand.
3235    * -- print a star (in certain assembler syntax)
3236    w -- print the operand as if it's a "word" (HImode) even if it isn't.
3237    J -- print the appropriate jump operand.
3238    s -- print a shift double count, followed by the assemblers argument
3239         delimiter.
3240    b -- print the QImode name of the register for the indicated operand.
3241         %b0 would print %al if operands[0] is reg 0.
3242    w --  likewise, print the HImode name of the register.
3243    k --  likewise, print the SImode name of the register.
3244    h --  print the QImode name for a "high" register, either ah, bh, ch or dh.
3245    y --  print "st(0)" instead of "st" as a register.
3246    P --  print as a PIC constant 
3247    _ --  output "_" if YES_UNDERSCORES */
3248
3249 void
3250 print_operand (file, x, code)
3251      FILE *file;
3252      rtx x;
3253      int code;
3254 {
3255   if (code)
3256     {
3257       switch (code)
3258         {
3259         case '*':
3260           if (USE_STAR)
3261             putc ('*', file);
3262           return;
3263
3264         case '_':
3265 #ifdef YES_UNDERSCORES
3266           putc ('_', file);
3267 #endif
3268           return;
3269
3270         case 'L':
3271           PUT_OP_SIZE (code, 'l', file);
3272           return;
3273
3274         case 'W':
3275           PUT_OP_SIZE (code, 'w', file);
3276           return;
3277
3278         case 'B':
3279           PUT_OP_SIZE (code, 'b', file);
3280           return;
3281
3282         case 'Q':
3283           PUT_OP_SIZE (code, 'l', file);
3284           return;
3285
3286         case 'S':
3287           PUT_OP_SIZE (code, 's', file);
3288           return;
3289
3290         case 'T':
3291           PUT_OP_SIZE (code, 't', file);
3292           return;
3293
3294         case 'z':
3295           /* 387 opcodes don't get size suffixes if the operands are
3296              registers. */
3297
3298           if (STACK_REG_P (x))
3299             return;
3300
3301           /* this is the size of op from size of operand */
3302           switch (GET_MODE_SIZE (GET_MODE (x)))
3303             {
3304             case 2:
3305 #ifdef HAVE_GAS_FILDS_FISTS
3306               PUT_OP_SIZE ('W', 's', file);
3307 #endif
3308               return;
3309
3310             case 4:
3311               if (GET_MODE (x) == SFmode)
3312                 {
3313                   PUT_OP_SIZE ('S', 's', file);
3314                   return;
3315                 }
3316               else
3317                 PUT_OP_SIZE ('L', 'l', file);
3318               return;
3319
3320             case 12:
3321                   PUT_OP_SIZE ('T', 't', file);
3322                   return;
3323
3324             case 8:
3325               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
3326                 {
3327 #ifdef GAS_MNEMONICS
3328                   PUT_OP_SIZE ('Q', 'q', file);
3329                   return;
3330 #else
3331                   PUT_OP_SIZE ('Q', 'l', file); /* Fall through */
3332 #endif
3333                 }
3334
3335               PUT_OP_SIZE ('Q', 'l', file);
3336               return;
3337
3338             default:
3339               abort ();
3340             }
3341
3342         case 'b':
3343         case 'w':
3344         case 'k':
3345         case 'h':
3346         case 'y':
3347         case 'P':
3348         case 'X':
3349           break;
3350
3351         case 'J':
3352           switch (GET_CODE (x))
3353             {
3354               /* These conditions are appropriate for testing the result
3355                  of an arithmetic operation, not for a compare operation.
3356                  Cases GE, LT assume CC_NO_OVERFLOW true. All cases assume
3357                  CC_Z_IN_NOT_C false and not floating point.  */
3358             case NE:  fputs ("jne", file); return;
3359             case EQ:  fputs ("je",  file); return;
3360             case GE:  fputs ("jns", file); return;
3361             case LT:  fputs ("js",  file); return;
3362             case GEU: fputs ("jmp", file); return;
3363             case GTU: fputs ("jne",  file); return;
3364             case LEU: fputs ("je", file); return;
3365             case LTU: fputs ("#branch never",  file); return;
3366
3367             /* no matching branches for GT nor LE */
3368
3369             default:
3370               abort ();
3371             }
3372
3373         case 's':
3374           if (GET_CODE (x) == CONST_INT || ! SHIFT_DOUBLE_OMITS_COUNT)
3375             {
3376               PRINT_OPERAND (file, x, 0);
3377               fputs (AS2C (,) + 1, file);
3378             }
3379
3380           return;
3381
3382         case 'D':
3383           put_jump_code (GET_CODE (x), 0, file);
3384           return;
3385
3386         case 'd':
3387           put_jump_code (GET_CODE (x), 1, file);
3388           return;
3389
3390           /* This is used by the conditional move instructions.  */
3391         case 'C':
3392           put_condition_code (GET_CODE (x), 0, MODE_INT, file);
3393           return;
3394
3395           /* Like above, but reverse condition */
3396         case 'c':
3397           put_condition_code (GET_CODE (x), 1, MODE_INT, file); return;
3398
3399         case 'F':
3400           put_condition_code (GET_CODE (x), 0, MODE_FLOAT, file);
3401           return;
3402
3403           /* Like above, but reverse condition */
3404         case 'f':
3405           put_condition_code (GET_CODE (x), 1, MODE_FLOAT, file);
3406           return;
3407
3408         default:
3409           {
3410             char str[50];
3411
3412             sprintf (str, "invalid operand code `%c'", code);
3413             output_operand_lossage (str);
3414           }
3415         }
3416     }
3417
3418   if (GET_CODE (x) == REG)
3419     {
3420       PRINT_REG (x, code, file);
3421     }
3422
3423   else if (GET_CODE (x) == MEM)
3424     {
3425       PRINT_PTR (x, file);
3426       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
3427         {
3428           if (flag_pic)
3429             output_pic_addr_const (file, XEXP (x, 0), code);
3430           else
3431             output_addr_const (file, XEXP (x, 0));
3432         }
3433       else
3434         output_address (XEXP (x, 0));
3435     }
3436
3437   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
3438     {
3439       REAL_VALUE_TYPE r;
3440       long l;
3441
3442       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3443       REAL_VALUE_TO_TARGET_SINGLE (r, l);
3444       PRINT_IMMED_PREFIX (file);
3445       fprintf (file, "0x%lx", l);
3446     }
3447
3448  /* These float cases don't actually occur as immediate operands. */
3449  else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
3450     {
3451       REAL_VALUE_TYPE r;
3452       char dstr[30];
3453
3454       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3455       REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr);
3456       fprintf (file, "%s", dstr);
3457     }
3458
3459   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == XFmode)
3460     {
3461       REAL_VALUE_TYPE r;
3462       char dstr[30];
3463
3464       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3465       REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr);
3466       fprintf (file, "%s", dstr);
3467     }
3468   else
3469     {
3470       if (code != 'P')
3471         {
3472           if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
3473             PRINT_IMMED_PREFIX (file);
3474           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
3475                    || GET_CODE (x) == LABEL_REF)
3476             PRINT_OFFSET_PREFIX (file);
3477         }
3478       if (flag_pic)
3479         output_pic_addr_const (file, x, code);
3480       else
3481         output_addr_const (file, x);
3482     }
3483 }
3484 \f
3485 /* Print a memory operand whose address is ADDR.  */
3486
3487 void
3488 print_operand_address (file, addr)
3489      FILE *file;
3490      register rtx addr;
3491 {
3492   register rtx reg1, reg2, breg, ireg;
3493   rtx offset;
3494
3495   switch (GET_CODE (addr))
3496     {
3497     case REG:
3498       /* ESI addressing makes instruction vector decoded on the K6.  We can
3499          avoid this by ESI+0 addressing.  */
3500       if (REGNO_REG_CLASS (REGNO (addr)) == SIREG
3501           && ix86_cpu == PROCESSOR_K6 && !optimize_size)
3502         output_addr_const (file, const0_rtx);
3503       ADDR_BEG (file);
3504       fprintf (file, "%se", RP);
3505       fputs (hi_reg_name[REGNO (addr)], file);
3506       ADDR_END (file);
3507       break;
3508
3509     case PLUS:
3510       reg1 = 0;
3511       reg2 = 0;
3512       ireg = 0;
3513       breg = 0;
3514       offset = 0;
3515       if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
3516         {
3517           offset = XEXP (addr, 0);
3518           addr = XEXP (addr, 1);
3519         }
3520       else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
3521         {
3522           offset = XEXP (addr, 1);
3523           addr = XEXP (addr, 0);
3524         }
3525
3526       if (GET_CODE (addr) != PLUS)
3527         ;
3528       else if (GET_CODE (XEXP (addr, 0)) == MULT)
3529         reg1 = XEXP (addr, 0), addr = XEXP (addr, 1);
3530       else if (GET_CODE (XEXP (addr, 1)) == MULT)
3531         reg1 = XEXP (addr, 1), addr = XEXP (addr, 0);
3532       else if (GET_CODE (XEXP (addr, 0)) == REG)
3533         reg1 = XEXP (addr, 0), addr = XEXP (addr, 1);
3534       else if (GET_CODE (XEXP (addr, 1)) == REG)
3535         reg1 = XEXP (addr, 1), addr = XEXP (addr, 0);
3536
3537       if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT)
3538         {
3539           if (reg1 == 0)
3540             reg1 = addr;
3541           else
3542             reg2 = addr;
3543
3544           addr = 0;
3545         }
3546
3547       if (offset != 0)
3548         {
3549           if (addr != 0)
3550             abort ();
3551           addr = offset;
3552         }
3553
3554       if ((reg1 && GET_CODE (reg1) == MULT)
3555           || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2))))
3556         {
3557           breg = reg2;
3558           ireg = reg1;
3559         }
3560       else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1)))
3561         {
3562           breg = reg1;
3563           ireg = reg2;
3564         }
3565
3566       if (ireg != 0 || breg != 0)
3567         {
3568           int scale = 1;
3569
3570           if (addr != 0)
3571             {
3572               if (flag_pic)
3573                 output_pic_addr_const (file, addr, 0);
3574               else if (GET_CODE (addr) == LABEL_REF)
3575                 output_asm_label (addr);
3576               else
3577                 output_addr_const (file, addr);
3578             }
3579
3580           if (ireg != 0 && GET_CODE (ireg) == MULT)
3581             {
3582               scale = INTVAL (XEXP (ireg, 1));
3583               ireg = XEXP (ireg, 0);
3584             }
3585
3586           /* The stack pointer can only appear as a base register,
3587              never an index register, so exchange the regs if it is wrong. */
3588
3589           if (scale == 1 && ireg && REGNO (ireg) == STACK_POINTER_REGNUM)
3590             {
3591               rtx tmp;
3592
3593               tmp = breg;
3594               breg = ireg;
3595               ireg = tmp;
3596             }
3597
3598           /* output breg+ireg*scale */
3599           PRINT_B_I_S (breg, ireg, scale, file);
3600           break;
3601         }
3602
3603     case MULT:
3604       {
3605         int scale;
3606
3607         if (GET_CODE (XEXP (addr, 0)) == CONST_INT)
3608           {
3609             scale = INTVAL (XEXP (addr, 0));
3610             ireg = XEXP (addr, 1);
3611           }
3612         else
3613           {
3614             scale = INTVAL (XEXP (addr, 1));
3615             ireg = XEXP (addr, 0);
3616           }
3617
3618         /* (reg,reg,) is shorter than (,reg,2).  */
3619         if (scale == 2)
3620           {
3621             PRINT_B_I_S (ireg, ireg, 1, file);
3622           } 
3623         else 
3624           {
3625             output_addr_const (file, const0_rtx);
3626             PRINT_B_I_S (NULL_RTX, ireg, scale, file);
3627           }
3628       }
3629       break;
3630
3631     default:
3632       if (GET_CODE (addr) == CONST_INT
3633           && INTVAL (addr) < 0x8000
3634           && INTVAL (addr) >= -0x8000)
3635         fprintf (file, "%d", (int) INTVAL (addr));
3636       else
3637         {
3638           if (flag_pic)
3639             output_pic_addr_const (file, addr, 0);
3640           else
3641             output_addr_const (file, addr);
3642         }
3643     }
3644 }
3645 \f
3646 /* Set the cc_status for the results of an insn whose pattern is EXP.
3647    On the 80386, we assume that only test and compare insns, as well
3648    as SI, HI, & DI mode ADD, SUB, NEG, AND, IOR, XOR, BSF, ASHIFT,
3649    ASHIFTRT, and LSHIFTRT instructions set the condition codes usefully.
3650    Also, we assume that jumps, moves and sCOND don't affect the condition
3651    codes.  All else clobbers the condition codes, by assumption.
3652
3653    We assume that ALL integer add, minus, etc. instructions effect the
3654    condition codes.  This MUST be consistent with i386.md.
3655
3656    We don't record any float test or compare - the redundant test &
3657    compare check in final.c does not handle stack-like regs correctly. */
3658
3659 void
3660 notice_update_cc (exp)
3661      rtx exp;
3662 {
3663   if (GET_CODE (exp) == SET)
3664     {
3665       /* Jumps do not alter the cc's.  */
3666       if (SET_DEST (exp) == pc_rtx)
3667         return;
3668
3669       /* Moving register or memory into a register:
3670          it doesn't alter the cc's, but it might invalidate
3671          the RTX's which we remember the cc's came from.
3672          (Note that moving a constant 0 or 1 MAY set the cc's).  */
3673       if (REG_P (SET_DEST (exp))
3674           && (REG_P (SET_SRC (exp)) || GET_CODE (SET_SRC (exp)) == MEM
3675               || GET_RTX_CLASS (GET_CODE (SET_SRC (exp))) == '<'
3676               || GET_CODE (SET_SRC (exp)) == IF_THEN_ELSE))
3677         {
3678           if (cc_status.value1
3679               && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value1))
3680             cc_status.value1 = 0;
3681
3682           if (cc_status.value2
3683               && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value2))
3684             cc_status.value2 = 0;
3685
3686           return;
3687         }
3688
3689       /* Moving register into memory doesn't alter the cc's.
3690          It may invalidate the RTX's which we remember the cc's came from.  */
3691       if (GET_CODE (SET_DEST (exp)) == MEM
3692           && (REG_P (SET_SRC (exp))
3693               || GET_RTX_CLASS (GET_CODE (SET_SRC (exp))) == '<'))
3694         {
3695           if (cc_status.value1
3696               && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value1))
3697             cc_status.value1 = 0;
3698           if (cc_status.value2
3699               && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value2))
3700             cc_status.value2 = 0;
3701
3702           return;
3703         }
3704
3705       /* Function calls clobber the cc's.  */
3706       else if (GET_CODE (SET_SRC (exp)) == CALL)
3707         {
3708           CC_STATUS_INIT;
3709           return;
3710         }
3711
3712       /* Tests and compares set the cc's in predictable ways.  */
3713       else if (SET_DEST (exp) == cc0_rtx)
3714         {
3715           CC_STATUS_INIT;
3716           cc_status.value1 = SET_SRC (exp);
3717           return;
3718         }
3719
3720       /* Certain instructions effect the condition codes. */
3721       else if (GET_MODE (SET_SRC (exp)) == SImode
3722                || GET_MODE (SET_SRC (exp)) == HImode
3723                || GET_MODE (SET_SRC (exp)) == QImode)
3724         switch (GET_CODE (SET_SRC (exp)))
3725           {
3726           case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3727             /* Shifts on the 386 don't set the condition codes if the
3728                shift count is zero. */
3729             if (GET_CODE (XEXP (SET_SRC (exp), 1)) != CONST_INT)
3730               {
3731                 CC_STATUS_INIT;
3732                 break;
3733               }
3734
3735             /* We assume that the CONST_INT is non-zero (this rtx would
3736                have been deleted if it were zero. */
3737
3738           case PLUS: case MINUS: case NEG:
3739           case AND: case IOR: case XOR:
3740             cc_status.flags = CC_NO_OVERFLOW;
3741             cc_status.value1 = SET_SRC (exp);
3742             cc_status.value2 = SET_DEST (exp);
3743             break;
3744
3745             /* This is the bsf pattern used by ffs.  */
3746           case UNSPEC:
3747             if (XINT (SET_SRC (exp), 1) == 5)
3748               {
3749                 /* Only the Z flag is defined after bsf.  */
3750                 cc_status.flags
3751                   = CC_NOT_POSITIVE | CC_NOT_NEGATIVE | CC_NO_OVERFLOW;
3752                 cc_status.value1 = XVECEXP (SET_SRC (exp), 0, 0);
3753                 cc_status.value2 = 0;
3754                 break;
3755               }
3756             /* FALLTHRU */
3757
3758           default:
3759             CC_STATUS_INIT;
3760           }
3761       else
3762         {
3763           CC_STATUS_INIT;
3764         }
3765     }
3766   else if (GET_CODE (exp) == PARALLEL
3767            && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
3768     {
3769       if (SET_DEST (XVECEXP (exp, 0, 0)) == pc_rtx)
3770         return;
3771       if (SET_DEST (XVECEXP (exp, 0, 0)) == cc0_rtx)
3772
3773         {
3774           CC_STATUS_INIT;
3775           if (stack_regs_mentioned_p (SET_SRC (XVECEXP (exp, 0, 0))))
3776             {
3777               cc_status.flags |= CC_IN_80387;
3778               if (TARGET_CMOVE && stack_regs_mentioned_p
3779                   (XEXP (SET_SRC (XVECEXP (exp, 0, 0)), 1)))
3780                 cc_status.flags |= CC_FCOMI;
3781             }
3782           else
3783             cc_status.value1 = SET_SRC (XVECEXP (exp, 0, 0));
3784           return;
3785         }
3786
3787       CC_STATUS_INIT;
3788     }
3789   else
3790     {
3791       CC_STATUS_INIT;
3792     }
3793 }
3794 \f
3795 /* Split one or more DImode RTL references into pairs of SImode
3796    references.  The RTL can be REG, offsettable MEM, integer constant, or
3797    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
3798    split and "num" is its length.  lo_half and hi_half are output arrays
3799    that parallel "operands". */
3800
3801 void
3802 split_di (operands, num, lo_half, hi_half)
3803      rtx operands[];
3804      int num;
3805      rtx lo_half[], hi_half[];
3806 {
3807   while (num--)
3808     {
3809       rtx op = operands[num];
3810       if (! reload_completed)
3811         {
3812           lo_half[num] = gen_lowpart (SImode, op);
3813           hi_half[num] = gen_highpart (SImode, op);
3814         }
3815       else if (GET_CODE (op) == REG)
3816         {
3817           lo_half[num] = gen_rtx_REG (SImode, REGNO (op));
3818           hi_half[num] = gen_rtx_REG (SImode, REGNO (op) + 1);
3819         }
3820       else if (CONSTANT_P (op))
3821         split_double (op, &lo_half[num], &hi_half[num]);
3822       else if (offsettable_memref_p (op))
3823         {
3824           rtx lo_addr = XEXP (op, 0);
3825           rtx hi_addr = XEXP (adj_offsettable_operand (op, 4), 0);
3826           lo_half[num] = change_address (op, SImode, lo_addr);
3827           hi_half[num] = change_address (op, SImode, hi_addr);
3828         }
3829       else
3830         abort();
3831     }
3832 }
3833 \f
3834 /* Return 1 if this is a valid binary operation on a 387.
3835    OP is the expression matched, and MODE is its mode. */
3836
3837 int
3838 binary_387_op (op, mode)
3839     register rtx op;
3840     enum machine_mode mode;
3841 {
3842   if (mode != VOIDmode && mode != GET_MODE (op))
3843     return 0;
3844
3845   switch (GET_CODE (op))
3846     {
3847     case PLUS:
3848     case MINUS:
3849     case MULT:
3850     case DIV:
3851       return GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT;
3852
3853     default:
3854       return 0;
3855     }
3856 }
3857 \f
3858 /* Return 1 if this is a valid shift or rotate operation on a 386.
3859    OP is the expression matched, and MODE is its mode. */
3860
3861 int
3862 shift_op (op, mode)
3863     register rtx op;
3864     enum machine_mode mode;
3865 {
3866   rtx operand = XEXP (op, 0);
3867
3868   if (mode != VOIDmode && mode != GET_MODE (op))
3869     return 0;
3870
3871   if (GET_MODE (operand) != GET_MODE (op)
3872       || GET_MODE_CLASS (GET_MODE (op)) != MODE_INT)
3873     return 0;
3874
3875   return (GET_CODE (op) == ASHIFT
3876           || GET_CODE (op) == ASHIFTRT
3877           || GET_CODE (op) == LSHIFTRT
3878           || GET_CODE (op) == ROTATE
3879           || GET_CODE (op) == ROTATERT);
3880 }
3881
3882 /* Return 1 if OP is COMPARE rtx with mode VOIDmode.
3883    MODE is not used.  */
3884
3885 int
3886 VOIDmode_compare_op (op, mode)
3887     register rtx op;
3888     enum machine_mode mode ATTRIBUTE_UNUSED;
3889 {
3890   return GET_CODE (op) == COMPARE && GET_MODE (op) == VOIDmode;
3891 }
3892 \f
3893 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
3894    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
3895    is the expression of the binary operation.  The output may either be
3896    emitted here, or returned to the caller, like all output_* functions.
3897
3898    There is no guarantee that the operands are the same mode, as they
3899    might be within FLOAT or FLOAT_EXTEND expressions. */
3900
3901 char *
3902 output_387_binary_op (insn, operands)
3903      rtx insn;
3904      rtx *operands;
3905 {
3906   rtx temp;
3907   char *base_op;
3908   static char buf[100];
3909
3910   switch (GET_CODE (operands[3]))
3911     {
3912     case PLUS:
3913       base_op = "fadd";
3914       break;
3915
3916     case MINUS:
3917       base_op = "fsub";
3918       break;
3919
3920     case MULT:
3921       base_op = "fmul";
3922       break;
3923
3924     case DIV:
3925       base_op = "fdiv";
3926       break;
3927
3928     default:
3929       abort ();
3930     }
3931
3932   strcpy (buf, base_op);
3933
3934   switch (GET_CODE (operands[3]))
3935     {
3936     case MULT:
3937     case PLUS:
3938       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
3939         {
3940           temp = operands[2];
3941           operands[2] = operands[1];
3942           operands[1] = temp;
3943         }
3944
3945       if (GET_CODE (operands[2]) == MEM)
3946         return strcat (buf, AS1 (%z2,%2));
3947
3948       if (! STACK_REG_P (operands[1]) || ! STACK_REG_P (operands[2]))
3949         abort ();
3950
3951       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
3952         {
3953           if (STACK_TOP_P (operands[0]))
3954             return strcat (buf, AS2 (p,%0,%2));
3955           else
3956             return strcat (buf, AS2 (p,%2,%0));
3957         }
3958
3959       if (STACK_TOP_P (operands[0]))
3960         return strcat (buf, AS2C (%y2,%0));
3961       else
3962         return strcat (buf, AS2C (%2,%0));
3963
3964     case MINUS:
3965     case DIV:
3966       if (GET_CODE (operands[1]) == MEM)
3967         return strcat (buf, AS1 (r%z1,%1));
3968
3969       if (GET_CODE (operands[2]) == MEM)
3970         return strcat (buf, AS1 (%z2,%2));
3971
3972       if (! STACK_REG_P (operands[1]) || ! STACK_REG_P (operands[2]))
3973         abort ();
3974
3975       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
3976         {
3977           if (STACK_TOP_P (operands[0]))
3978             return strcat (buf, AS2 (p,%0,%2));
3979           else
3980             return strcat (buf, AS2 (rp,%2,%0));
3981         }
3982
3983       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3984         {
3985           if (STACK_TOP_P (operands[0]))
3986             return strcat (buf, AS2 (rp,%0,%1));
3987           else
3988             return strcat (buf, AS2 (p,%1,%0));
3989         }
3990
3991       if (STACK_TOP_P (operands[0]))
3992         {
3993           if (STACK_TOP_P (operands[1]))
3994             return strcat (buf, AS2C (%y2,%0));
3995           else
3996             return strcat (buf, AS2 (r,%y1,%0));
3997         }
3998       else if (STACK_TOP_P (operands[1]))
3999         return strcat (buf, AS2C (%1,%0));
4000       else
4001         return strcat (buf, AS2 (r,%2,%0));
4002
4003     default:
4004       abort ();
4005     }
4006 }
4007 \f
4008 /* Output code for INSN to convert a float to a signed int.  OPERANDS
4009    are the insn operands.  The input may be SFmode, DFmode, or XFmode
4010    and the output operand may be SImode or DImode.  As a special case,
4011    make sure that the 387 stack top dies if the output mode is DImode,
4012    because the hardware requires this.  */
4013
4014 char *
4015 output_fix_trunc (insn, operands)
4016      rtx insn;
4017      rtx *operands;
4018 {
4019   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
4020   rtx xops[2];
4021
4022   if (! STACK_TOP_P (operands[1]))
4023     abort ();
4024
4025   if (GET_MODE (operands[0]) == DImode && ! stack_top_dies)
4026     abort ();
4027
4028   xops[0] = GEN_INT (0x0c00);
4029   xops[1] = operands[5];
4030
4031   output_asm_insn (AS1 (fnstc%W2,%2), operands);
4032   output_asm_insn (AS2 (mov%W5,%2,%w5), operands);
4033   output_asm_insn (AS2 (or%W1,%0,%w1), xops);
4034   output_asm_insn (AS2 (mov%W3,%w5,%3), operands);
4035   output_asm_insn (AS1 (fldc%W3,%3), operands);
4036
4037   xops[0] = NON_STACK_REG_P (operands[0]) ? operands[4] : operands[0];
4038
4039   if (stack_top_dies)
4040     output_asm_insn (AS1 (fistp%z0,%y0), xops);
4041   else
4042     output_asm_insn (AS1 (fist%z0,%y0), xops);
4043
4044   if (NON_STACK_REG_P (operands[0]))
4045     {
4046       if (GET_MODE (operands[0]) == SImode)
4047         output_asm_insn (AS2 (mov%L0,%4,%0), operands);
4048       else
4049         {
4050           xops[0] = operands[0];
4051           xops[1] = operands[4];
4052           output_asm_insn (output_move_double (xops), xops);
4053         }
4054     }
4055
4056   return AS1 (fldc%W2,%2);
4057 }
4058 \f
4059 /* Output code for INSN to extend a float.  OPERANDS are the insn
4060    operands.  The output may be DFmode or XFmode and the input operand
4061    may be SFmode or DFmode.  Operands 2 and 3 are scratch memory and
4062    are only necessary if operands 0 or 1 are non-stack registers.  */
4063
4064 void
4065 output_float_extend (insn, operands)
4066      rtx insn;
4067      rtx *operands;
4068 {
4069   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
4070   rtx xops[2];
4071
4072   if (! STACK_TOP_P (operands[0]) && ! STACK_TOP_P (operands[1]))
4073     abort ();
4074
4075   if (STACK_TOP_P (operands[0]) && STACK_TOP_P (operands[1]) && stack_top_dies)
4076     return;
4077
4078   if (STACK_TOP_P (operands[0]) )
4079     {
4080       if (NON_STACK_REG_P (operands[1]))
4081         {
4082           if (GET_MODE (operands[1]) == SFmode)
4083             output_asm_insn (AS2 (mov%L0,%1,%2), operands);
4084           else
4085             {
4086               xops[0] = operands[2];
4087               xops[1] = operands[1];
4088               output_asm_insn (output_move_double (xops), xops);
4089             }
4090         }
4091
4092       xops[0] = NON_STACK_REG_P (operands[1]) ? operands[2] : operands[1];
4093
4094       output_asm_insn (AS1 (fld%z0,%y0), xops);
4095     }
4096   else
4097     {
4098       xops[0] = NON_STACK_REG_P (operands[0]) ? operands[3] : operands[0];
4099
4100       if (stack_top_dies
4101           || (GET_CODE (xops[0]) == MEM && GET_MODE (xops[0]) == XFmode))
4102         {
4103           output_asm_insn (AS1 (fstp%z0,%y0), xops);
4104           if (! stack_top_dies)
4105             output_asm_insn (AS1 (fld%z0,%y0), xops);
4106         }
4107       else
4108         output_asm_insn (AS1 (fst%z0,%y0), xops);
4109
4110       if (NON_STACK_REG_P (operands[0]))
4111         {
4112           xops[0] = operands[0];
4113           xops[1] = operands[3];
4114           output_asm_insn (output_move_double (xops), xops);
4115         }
4116     }
4117 }
4118 \f
4119 /* Output code for INSN to compare OPERANDS.  The two operands might
4120    not have the same mode: one might be within a FLOAT or FLOAT_EXTEND
4121    expression.  If the compare is in mode CCFPEQmode, use an opcode that
4122    will not fault if a qNaN is present. */
4123
4124 char *
4125 output_float_compare (insn, operands)
4126      rtx insn;
4127      rtx *operands;
4128 {
4129   int stack_top_dies;
4130   rtx body = XVECEXP (PATTERN (insn), 0, 0);
4131   int unordered_compare = GET_MODE (SET_SRC (body)) == CCFPEQmode;
4132   rtx tmp;
4133   int cc0_set = 1;
4134   int i;
4135
4136   if (TARGET_CMOVE && STACK_REG_P (operands[1])
4137       && STACK_REG_P (operands[0]))
4138     {
4139       cc_status.flags |= CC_FCOMI;
4140       cc_prev_status.flags &= ~CC_TEST_AX;
4141     }
4142
4143   if (! STACK_TOP_P (operands[0]))
4144     {
4145       tmp = operands[0];
4146       operands[0] = operands[1];
4147       operands[1] = tmp;
4148       cc_status.flags |= CC_REVERSED;
4149     }
4150
4151   if (! STACK_TOP_P (operands[0]))
4152     abort ();
4153
4154   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
4155
4156   if (STACK_REG_P (operands[1])
4157       && stack_top_dies
4158       && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4159       && REGNO (operands[1]) == FIRST_STACK_REG + 1)
4160     {
4161       /* If both the top of the 387 stack dies, and the other operand
4162          is also a stack register that dies, then this must be a
4163          `fcompp' float compare */
4164
4165       if (unordered_compare)
4166         {
4167           if (cc_status.flags & CC_FCOMI)
4168             {
4169               output_asm_insn (AS2 (fucomip,%y1,%0), operands);
4170               output_asm_insn (AS1 (fstp, %y0), operands);
4171               if (!TARGET_IEEE_FP)
4172                 cc0_set = 0; 
4173             }
4174           else
4175             output_asm_insn ("fucompp", operands);
4176         }
4177       else
4178         {
4179           if (cc_status.flags & CC_FCOMI)
4180             {
4181               output_asm_insn (AS2 (fcomip, %y1,%0), operands);
4182               output_asm_insn (AS1 (fstp, %y0), operands);
4183               if (!TARGET_IEEE_FP)
4184                 cc0_set = 0; 
4185             }
4186           else
4187             output_asm_insn ("fcompp", operands);
4188         }
4189     }
4190   else
4191     {
4192       static char buf[100];
4193
4194       /* Decide if this is a float compare or an unordered float compare. */
4195
4196       if (unordered_compare)
4197         strcpy (buf, (cc_status.flags & CC_FCOMI) ? "fucomi" : "fucom");
4198       else
4199         strcpy (buf, (cc_status.flags & CC_FCOMI) ? "fcomi" : "fcom");
4200
4201       /* Modify the opcode if the 387 stack is to be popped. */
4202
4203       if (stack_top_dies)
4204         strcat (buf, "p");
4205
4206       if (cc_status.flags & CC_FCOMI)
4207         {
4208           output_asm_insn (strcat (buf, AS2 (%z1,%y1,%0)), operands);
4209           if (!TARGET_IEEE_FP)
4210             cc0_set = 0; 
4211         }
4212       else
4213         output_asm_insn (strcat (buf, AS1 (%z1,%y1)), operands);
4214     }
4215
4216   /* Now retrieve the condition code. */
4217   if (cc0_set) 
4218     {
4219       char *r = output_fp_cc0_set (insn); 
4220       if (r[0]) output_asm_insn (r, operands);
4221     }
4222
4223
4224   /* We emit fstp instruction after integer comparsions to improve
4225      scheduling. */
4226   for (i = 0; i < 2 ; i++)
4227     {
4228       if (STACK_REG_P (operands[i])
4229           && find_regno_note (insn, REG_DEAD, REGNO (operands[i]))
4230           && REGNO (operands[i]) != FIRST_STACK_REG 
4231           && (!stack_top_dies || REGNO (operands[i]) != FIRST_STACK_REG + 1))
4232         {
4233           rtx xexp[2];
4234           xexp[0] = gen_rtx_REG (DFmode,
4235                                  REGNO (operands[i]) - (stack_top_dies != 0));
4236           output_asm_insn (AS1 (fstp, %y0), xexp);
4237         }
4238     }
4239
4240   return "";
4241
4242
4243 }
4244 \f
4245 /* Output opcodes to transfer the results of FP compare or test INSN
4246    from the FPU to the CPU flags.  If TARGET_IEEE_FP, ensure that if the
4247    result of the compare or test is unordered, no comparison operator
4248    succeeds except NE.  Return an output template, if any.  */
4249
4250 char *
4251 output_fp_cc0_set (insn)
4252      rtx insn;
4253 {
4254   rtx xops[3];
4255   rtx next;
4256   enum rtx_code code;
4257
4258   if (!(cc_status.flags & CC_FCOMI))
4259     {
4260       xops[0] = gen_rtx_REG (HImode, 0);
4261       output_asm_insn (AS1 (fnsts%W0,%0), xops);
4262     }
4263
4264   if (! TARGET_IEEE_FP)
4265     {
4266       if (!(cc_status.flags & CC_REVERSED))
4267         {
4268           next = next_cc0_user (insn);
4269   
4270           if (GET_CODE (PATTERN (next)) == SET
4271               && SET_DEST (PATTERN (next)) == pc_rtx
4272               && GET_CODE (SET_SRC (PATTERN (next))) == IF_THEN_ELSE)
4273             code = GET_CODE (XEXP (SET_SRC (PATTERN (next)), 0));
4274           else if (GET_CODE (PATTERN (next)) == SET)
4275             code = GET_CODE (SET_SRC (PATTERN (next)));
4276           else
4277             return "sahf";
4278
4279           if (code == GT || code == LT || code == EQ || code == NE
4280               || code == LE || code == GE)
4281             {
4282               /* We will test eax directly. */
4283               cc_status.flags |= CC_TEST_AX;
4284               return "";
4285             }
4286         }
4287
4288       return "sahf";
4289     }
4290
4291   next = next_cc0_user (insn);
4292   if (next == NULL_RTX)
4293     abort ();
4294
4295   if (GET_CODE (PATTERN (next)) == SET
4296       && SET_DEST (PATTERN (next)) == pc_rtx
4297       && GET_CODE (SET_SRC (PATTERN (next))) == IF_THEN_ELSE)
4298     code = GET_CODE (XEXP (SET_SRC (PATTERN (next)), 0));
4299   else if (GET_CODE (PATTERN (next)) == SET)
4300     {
4301       if (GET_CODE (SET_SRC (PATTERN (next))) == IF_THEN_ELSE)
4302         code = GET_CODE (XEXP (SET_SRC (PATTERN (next)), 0));
4303       else
4304         code = GET_CODE (SET_SRC (PATTERN (next)));
4305     }
4306
4307   else if (GET_CODE (PATTERN (next)) == PARALLEL
4308            && GET_CODE (XVECEXP (PATTERN (next), 0, 0)) == SET)
4309     {
4310       if (GET_CODE (SET_SRC (XVECEXP (PATTERN (next), 0, 0))) == IF_THEN_ELSE)
4311         code = GET_CODE (XEXP (SET_SRC (XVECEXP (PATTERN (next), 0, 0)), 0));
4312       else
4313         code = GET_CODE (SET_SRC (XVECEXP (PATTERN (next), 0, 0)));
4314     }
4315   else
4316     abort ();
4317
4318   if (cc_status.flags & CC_FCOMI)
4319     {
4320       /* It is very tricky. We have to do it right. */
4321
4322       xops [0] = gen_rtx_REG (QImode, 0);
4323
4324       switch (code)
4325         {
4326         case GT:
4327         case GE:
4328           break;
4329
4330         case LT:
4331           output_asm_insn (AS1 (setb,%b0), xops);
4332           output_asm_insn (AS1 (setp,%h0), xops);
4333           output_asm_insn (AS2 (cmp%B0,%b0,%h0), xops);
4334           break;
4335
4336         case LE:
4337           output_asm_insn (AS1 (setbe,%b0), xops);
4338           output_asm_insn (AS1 (setnp,%h0), xops);
4339           output_asm_insn (AS2 (xor%B0,%b0,%h0), xops);
4340           break;
4341
4342         case EQ:
4343         case NE:
4344           output_asm_insn (AS1 (setne,%b0), xops);
4345           output_asm_insn (AS1 (setp,%h0), xops);
4346           output_asm_insn (AS2 (or%B0,%b0,%h0), xops);
4347           break;
4348
4349         case GTU:
4350         case LTU:
4351         case GEU:
4352         case LEU:
4353         default:
4354           abort ();
4355         }
4356     }
4357   else
4358     {
4359       xops[0] = gen_rtx_REG (QImode, 0);
4360
4361       switch (code)
4362         {
4363         case GT:
4364           xops[1] = GEN_INT (0x45);
4365           output_asm_insn (AS2 (and%B0,%1,%h0), xops);
4366           /* je label */
4367           break;
4368
4369         case LT:
4370           xops[1] = GEN_INT (0x45);
4371           xops[2] = GEN_INT (0x01);
4372           output_asm_insn (AS2 (and%B0,%1,%h0), xops);
4373           output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
4374           /* je label */
4375           break;
4376
4377         case GE:
4378           xops[1] = GEN_INT (0x05);
4379           output_asm_insn (AS2 (and%B0,%1,%h0), xops);
4380           /* je label */
4381           break;
4382
4383         case LE:
4384           xops[1] = GEN_INT (0x45);
4385           xops[2] = GEN_INT (0x40);
4386           output_asm_insn (AS2 (and%B0,%1,%h0), xops);
4387           output_asm_insn (AS1 (dec%B0,%h0), xops);
4388           output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
4389           /* jb label */
4390           break;
4391
4392         case EQ:
4393           xops[1] = GEN_INT (0x45);
4394           xops[2] = GEN_INT (0x40);
4395           output_asm_insn (AS2 (and%B0,%1,%h0), xops);
4396           output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
4397           /* je label */
4398           break;
4399
4400         case NE:
4401           xops[1] = GEN_INT (0x44);
4402           xops[2] = GEN_INT (0x40);
4403           output_asm_insn (AS2 (and%B0,%1,%h0), xops);
4404           output_asm_insn (AS2 (xor%B0,%2,%h0), xops);
4405           /* jne label */
4406           break;
4407
4408         case GTU:
4409         case LTU:
4410         case GEU:
4411         case LEU:
4412         default:
4413           abort ();
4414         }
4415     }
4416
4417   return "";
4418 }
4419 \f
4420 #define MAX_386_STACK_LOCALS 2
4421
4422 static rtx i386_stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS];
4423
4424 /* Define the structure for the machine field in struct function.  */
4425 struct machine_function
4426 {
4427   rtx i386_stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS];
4428   rtx pic_label_rtx;
4429   char pic_label_name[256];
4430 };
4431
4432 /* Functions to save and restore i386_stack_locals.
4433    These will be called, via pointer variables,
4434    from push_function_context and pop_function_context.  */
4435
4436 void
4437 save_386_machine_status (p)
4438      struct function *p;
4439 {
4440   p->machine
4441     = (struct machine_function *) xmalloc (sizeof (struct machine_function));
4442   bcopy ((char *) i386_stack_locals, (char *) p->machine->i386_stack_locals,
4443          sizeof i386_stack_locals);
4444   p->machine->pic_label_rtx = pic_label_rtx;
4445   bcopy (pic_label_name, p->machine->pic_label_name, 256);
4446 }
4447
4448 void
4449 restore_386_machine_status (p)
4450      struct function *p;
4451 {
4452   bcopy ((char *) p->machine->i386_stack_locals, (char *) i386_stack_locals,
4453          sizeof i386_stack_locals);
4454   pic_label_rtx = p->machine->pic_label_rtx;
4455   bcopy (p->machine->pic_label_name, pic_label_name, 256);
4456   free (p->machine);
4457   p->machine = NULL;
4458 }
4459
4460 /* Clear stack slot assignments remembered from previous functions.
4461    This is called from INIT_EXPANDERS once before RTL is emitted for each
4462    function.  */
4463
4464 void
4465 clear_386_stack_locals ()
4466 {
4467   enum machine_mode mode;
4468   int n;
4469
4470   for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE;
4471        mode = (enum machine_mode) ((int) mode + 1))
4472     for (n = 0; n < MAX_386_STACK_LOCALS; n++)
4473       i386_stack_locals[(int) mode][n] = NULL_RTX;
4474
4475   pic_label_rtx = NULL_RTX;
4476   bzero (pic_label_name, 256);
4477   /* Arrange to save and restore i386_stack_locals around nested functions.  */
4478   save_machine_status = save_386_machine_status;
4479   restore_machine_status = restore_386_machine_status;
4480 }
4481
4482 /* Return a MEM corresponding to a stack slot with mode MODE.
4483    Allocate a new slot if necessary.
4484
4485    The RTL for a function can have several slots available: N is
4486    which slot to use.  */
4487
4488 rtx
4489 assign_386_stack_local (mode, n)
4490      enum machine_mode mode;
4491      int n;
4492 {
4493   if (n < 0 || n >= MAX_386_STACK_LOCALS)
4494     abort ();
4495
4496   if (i386_stack_locals[(int) mode][n] == NULL_RTX)
4497     i386_stack_locals[(int) mode][n]
4498       = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
4499
4500   return i386_stack_locals[(int) mode][n];
4501 }
4502 \f
4503 int is_mul(op,mode)
4504     register rtx op;
4505     enum machine_mode mode ATTRIBUTE_UNUSED;
4506 {
4507   return (GET_CODE (op) == MULT);
4508 }
4509
4510 int is_div(op,mode)
4511     register rtx op;
4512     enum machine_mode mode ATTRIBUTE_UNUSED;
4513 {
4514   return (GET_CODE (op) == DIV);
4515 }
4516 \f
4517 #ifdef NOTYET
4518 /* Create a new copy of an rtx.
4519    Recursively copies the operands of the rtx,
4520    except for those few rtx codes that are sharable.
4521    Doesn't share CONST  */
4522
4523 rtx
4524 copy_all_rtx (orig)
4525      register rtx orig;
4526 {
4527   register rtx copy;
4528   register int i, j;
4529   register RTX_CODE code;
4530   register char *format_ptr;
4531
4532   code = GET_CODE (orig);
4533
4534   switch (code)
4535     {
4536     case REG:
4537     case QUEUED:
4538     case CONST_INT:
4539     case CONST_DOUBLE:
4540     case SYMBOL_REF:
4541     case CODE_LABEL:
4542     case PC:
4543     case CC0:
4544     case SCRATCH:
4545       /* SCRATCH must be shared because they represent distinct values. */
4546       return orig;
4547
4548 #if 0
4549     case CONST:
4550       /* CONST can be shared if it contains a SYMBOL_REF.  If it contains
4551          a LABEL_REF, it isn't sharable.  */
4552       if (GET_CODE (XEXP (orig, 0)) == PLUS
4553           && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
4554           && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
4555         return orig;
4556       break;
4557 #endif
4558       /* A MEM with a constant address is not sharable.  The problem is that
4559          the constant address may need to be reloaded.  If the mem is shared,
4560          then reloading one copy of this mem will cause all copies to appear
4561          to have been reloaded.  */
4562     }
4563
4564   copy = rtx_alloc (code);
4565   PUT_MODE (copy, GET_MODE (orig));
4566   copy->in_struct = orig->in_struct;
4567   copy->volatil = orig->volatil;
4568   copy->unchanging = orig->unchanging;
4569   copy->integrated = orig->integrated;
4570   /* intel1 */
4571   copy->is_spill_rtx = orig->is_spill_rtx;
4572
4573   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
4574
4575   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
4576     {
4577       switch (*format_ptr++)
4578         {
4579         case 'e':
4580           XEXP (copy, i) = XEXP (orig, i);
4581           if (XEXP (orig, i) != NULL)
4582             XEXP (copy, i) = copy_rtx (XEXP (orig, i));
4583           break;
4584
4585         case '0':
4586         case 'u':
4587           XEXP (copy, i) = XEXP (orig, i);
4588           break;
4589
4590         case 'E':
4591         case 'V':
4592           XVEC (copy, i) = XVEC (orig, i);
4593           if (XVEC (orig, i) != NULL)
4594             {
4595               XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
4596               for (j = 0; j < XVECLEN (copy, i); j++)
4597                 XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j));
4598             }
4599           break;
4600
4601         case 'w':
4602           XWINT (copy, i) = XWINT (orig, i);
4603           break;
4604
4605         case 'i':
4606           XINT (copy, i) = XINT (orig, i);
4607           break;
4608
4609         case 's':
4610         case 'S':
4611           XSTR (copy, i) = XSTR (orig, i);
4612           break;
4613
4614         default:
4615           abort ();
4616         }
4617     }
4618   return copy;
4619 }
4620
4621 \f
4622 /* Try to rewrite a memory address to make it valid */
4623
4624 void
4625 rewrite_address (mem_rtx)
4626      rtx mem_rtx;
4627 {
4628   rtx index_rtx, base_rtx, offset_rtx, scale_rtx, ret_rtx;
4629   int scale = 1;
4630   int offset_adjust = 0;
4631   int was_only_offset = 0;
4632   rtx mem_addr = XEXP (mem_rtx, 0);
4633   char *storage = oballoc (0);
4634   int in_struct = 0;
4635   int is_spill_rtx = 0;
4636
4637   in_struct = MEM_IN_STRUCT_P (mem_rtx);
4638   is_spill_rtx = RTX_IS_SPILL_P (mem_rtx);
4639
4640   if (GET_CODE (mem_addr) == PLUS
4641       && GET_CODE (XEXP (mem_addr, 1)) == PLUS
4642       && GET_CODE (XEXP (XEXP (mem_addr, 1), 0)) == REG)
4643     {
4644       /* This part is utilized by the combiner. */
4645       ret_rtx
4646         = gen_rtx (PLUS, GET_MODE (mem_addr),
4647                    gen_rtx (PLUS, GET_MODE (XEXP (mem_addr, 1)),
4648                             XEXP (mem_addr, 0), XEXP (XEXP (mem_addr, 1), 0)),
4649                    XEXP (XEXP (mem_addr, 1), 1));
4650
4651       if (memory_address_p (GET_MODE (mem_rtx), ret_rtx))
4652         {
4653           XEXP (mem_rtx, 0) = ret_rtx;
4654           RTX_IS_SPILL_P (ret_rtx) = is_spill_rtx;
4655           return;
4656         }
4657
4658       obfree (storage);
4659     }
4660
4661   /* This part is utilized by loop.c.
4662      If the address contains PLUS (reg,const) and this pattern is invalid
4663      in this case - try to rewrite the address to make it valid. */
4664   storage = oballoc (0);
4665   index_rtx = base_rtx = offset_rtx = NULL;
4666
4667   /* Find the base index and offset elements of the memory address. */
4668   if (GET_CODE (mem_addr) == PLUS)
4669     {
4670       if (GET_CODE (XEXP (mem_addr, 0)) == REG)
4671         {
4672           if (GET_CODE (XEXP (mem_addr, 1)) == REG)
4673             base_rtx = XEXP (mem_addr, 1), index_rtx = XEXP (mem_addr, 0);
4674           else
4675             base_rtx = XEXP (mem_addr, 0), offset_rtx = XEXP (mem_addr, 1);
4676         }
4677
4678       else if (GET_CODE (XEXP (mem_addr, 0)) == MULT)
4679         {
4680           index_rtx = XEXP (mem_addr, 0);
4681           if (GET_CODE (XEXP (mem_addr, 1)) == REG)
4682             base_rtx = XEXP (mem_addr, 1);
4683           else
4684             offset_rtx = XEXP (mem_addr, 1);
4685         }
4686
4687       else if (GET_CODE (XEXP (mem_addr, 0)) == PLUS)
4688         {
4689           if (GET_CODE (XEXP (XEXP (mem_addr, 0), 0)) == PLUS
4690               && GET_CODE (XEXP (XEXP (XEXP (mem_addr, 0), 0), 0)) == MULT
4691               && (GET_CODE (XEXP (XEXP (XEXP (XEXP (mem_addr, 0), 0), 0), 0))
4692                   == REG)
4693               && (GET_CODE (XEXP (XEXP (XEXP (XEXP (mem_addr, 0), 0), 0), 1))
4694                   == CONST_INT)
4695               && (GET_CODE (XEXP (XEXP (XEXP (mem_addr, 0), 0), 1))
4696                   == CONST_INT)
4697               && GET_CODE (XEXP (XEXP (mem_addr, 0), 1)) == REG
4698               && GET_CODE (XEXP (mem_addr, 1)) == SYMBOL_REF)
4699             {
4700               index_rtx = XEXP (XEXP (XEXP (mem_addr, 0), 0), 0);
4701               offset_rtx = XEXP (mem_addr, 1);
4702               base_rtx = XEXP (XEXP (mem_addr, 0), 1);
4703               offset_adjust = INTVAL (XEXP (XEXP (XEXP (mem_addr, 0), 0), 1));
4704             }
4705           else
4706             {
4707               offset_rtx = XEXP (mem_addr, 1);
4708               index_rtx = XEXP (XEXP (mem_addr, 0), 0);
4709               base_rtx = XEXP (XEXP (mem_addr, 0), 1);
4710             }
4711         }
4712
4713       else if (GET_CODE (XEXP (mem_addr, 0)) == CONST_INT)
4714         {
4715           was_only_offset = 1;
4716           index_rtx = NULL;
4717           base_rtx = NULL;
4718           offset_rtx = XEXP (mem_addr, 1);
4719           offset_adjust = INTVAL (XEXP (mem_addr, 0));
4720           if (offset_adjust == 0)
4721             {
4722               XEXP (mem_rtx, 0) = offset_rtx;
4723               RTX_IS_SPILL_P (XEXP (mem_rtx, 0)) = is_spill_rtx;
4724               return;
4725             }
4726         }
4727       else
4728         {
4729           obfree (storage);
4730           return;
4731         }
4732     }
4733   else if (GET_CODE (mem_addr) == MULT)
4734     index_rtx = mem_addr;
4735   else
4736     {
4737       obfree (storage);
4738       return;
4739     }
4740
4741   if (index_rtx != 0 && GET_CODE (index_rtx) == MULT)
4742     {
4743       if (GET_CODE (XEXP (index_rtx, 1)) != CONST_INT)
4744         {
4745           obfree (storage);
4746           return;
4747         }
4748
4749       scale_rtx = XEXP (index_rtx, 1);
4750       scale = INTVAL (scale_rtx);
4751       index_rtx = copy_all_rtx (XEXP (index_rtx, 0));
4752     }
4753
4754   /* Now find which of the elements are invalid and try to fix them. */
4755   if (index_rtx && GET_CODE (index_rtx) == CONST_INT && base_rtx == NULL)
4756     {
4757       offset_adjust = INTVAL (index_rtx) * scale;
4758
4759       if (offset_rtx != 0 && CONSTANT_P (offset_rtx))
4760         offset_rtx = plus_constant (offset_rtx, offset_adjust);
4761       else if (offset_rtx == 0)
4762         offset_rtx = const0_rtx;
4763
4764       RTX_IS_SPILL_P (XEXP (mem_rtx, 0)) = is_spill_rtx;
4765       XEXP (mem_rtx, 0) = offset_rtx;
4766       return;
4767     }
4768
4769   if (base_rtx && GET_CODE (base_rtx) == PLUS
4770       && GET_CODE (XEXP (base_rtx, 0)) == REG
4771       && GET_CODE (XEXP (base_rtx, 1)) == CONST_INT)
4772     {
4773       offset_adjust += INTVAL (XEXP (base_rtx, 1));
4774       base_rtx = copy_all_rtx (XEXP (base_rtx, 0));
4775     }
4776
4777   else if (base_rtx && GET_CODE (base_rtx) == CONST_INT)
4778     {
4779       offset_adjust += INTVAL (base_rtx);
4780       base_rtx = NULL;
4781     }
4782
4783   if (index_rtx && GET_CODE (index_rtx) == PLUS
4784       && GET_CODE (XEXP (index_rtx, 0)) == REG
4785       && GET_CODE (XEXP (index_rtx, 1)) == CONST_INT)
4786     {
4787       offset_adjust += INTVAL (XEXP (index_rtx, 1)) * scale;
4788       index_rtx = copy_all_rtx (XEXP (index_rtx, 0));
4789     }
4790
4791   if (index_rtx)
4792     {
4793       if (! LEGITIMATE_INDEX_P (index_rtx)
4794           && ! (index_rtx == stack_pointer_rtx && scale == 1
4795                 && base_rtx == NULL))
4796         {
4797           obfree (storage);
4798           return;
4799         }
4800     }
4801
4802   if (base_rtx)
4803     {
4804       if (! LEGITIMATE_INDEX_P (base_rtx) && GET_CODE (base_rtx) != REG)
4805         {
4806           obfree (storage);
4807           return;
4808         }
4809     }
4810
4811   if (offset_adjust != 0)
4812     {
4813       if (offset_rtx != 0 && CONSTANT_P (offset_rtx))
4814         offset_rtx = plus_constant (offset_rtx, offset_adjust);
4815       else
4816         offset_rtx = const0_rtx;
4817
4818       if (index_rtx)
4819         {
4820           if (base_rtx)
4821             {
4822               if (scale != 1)
4823                 {
4824                   ret_rtx = gen_rtx (PLUS, GET_MODE (base_rtx),
4825                                      gen_rtx (MULT, GET_MODE (index_rtx),
4826                                               index_rtx, scale_rtx),
4827                                      base_rtx);
4828
4829                   if (GET_CODE (offset_rtx) != CONST_INT
4830                       || INTVAL (offset_rtx) != 0)
4831                     ret_rtx = gen_rtx (PLUS, GET_MODE (ret_rtx),
4832                                        ret_rtx, offset_rtx);
4833                 }
4834               else
4835                 {
4836                   ret_rtx = gen_rtx (PLUS, GET_MODE (index_rtx),
4837                                      index_rtx, base_rtx);
4838
4839                   if (GET_CODE (offset_rtx) != CONST_INT
4840                       || INTVAL (offset_rtx) != 0)
4841                     ret_rtx = gen_rtx (PLUS, GET_MODE (ret_rtx),
4842                                        ret_rtx, offset_rtx);
4843                 }
4844             }
4845           else
4846             {
4847               if (scale != 1)
4848                 {
4849                   ret_rtx = gen_rtx (MULT, GET_MODE (index_rtx),
4850                                      index_rtx, scale_rtx);
4851
4852                   if (GET_CODE (offset_rtx) != CONST_INT
4853                       || INTVAL (offset_rtx) != 0)
4854                     ret_rtx = gen_rtx (PLUS, GET_MODE (ret_rtx),
4855                                        ret_rtx, offset_rtx);
4856                 }
4857               else
4858                 {
4859                   if (GET_CODE (offset_rtx) == CONST_INT
4860                       && INTVAL (offset_rtx) == 0)
4861                     ret_rtx = index_rtx;
4862                   else
4863                     ret_rtx = gen_rtx (PLUS, GET_MODE (index_rtx),
4864                                        index_rtx, offset_rtx);
4865                 }
4866             }
4867         }
4868       else
4869         {
4870           if (base_rtx)
4871             {
4872               if (GET_CODE (offset_rtx) == CONST_INT
4873                   && INTVAL (offset_rtx) == 0)
4874                 ret_rtx = base_rtx;
4875               else
4876                 ret_rtx = gen_rtx (PLUS, GET_MODE (base_rtx), base_rtx,
4877                                    offset_rtx);
4878             }
4879           else if (was_only_offset)
4880             ret_rtx = offset_rtx;
4881           else
4882             {
4883               obfree (storage);
4884               return;
4885             }
4886         }
4887
4888       XEXP (mem_rtx, 0) = ret_rtx;
4889       RTX_IS_SPILL_P (XEXP (mem_rtx, 0)) = is_spill_rtx;
4890       return;
4891     }
4892   else
4893     {
4894       obfree (storage);
4895       return;
4896     }
4897 }
4898 #endif /* NOTYET */
4899 \f
4900 /* Return 1 if the first insn to set cc before INSN also sets the register
4901    REG_RTX; otherwise return 0. */
4902 int
4903 last_to_set_cc (reg_rtx, insn)
4904      rtx reg_rtx, insn;
4905 {
4906   rtx prev_insn = PREV_INSN (insn);
4907
4908   while (prev_insn)
4909     {
4910       if (GET_CODE (prev_insn) == NOTE)
4911         ;
4912
4913       else if (GET_CODE (prev_insn) == INSN)
4914         {
4915           if (GET_CODE (PATTERN (prev_insn)) != SET)
4916             return (0);
4917
4918           if (rtx_equal_p (SET_DEST (PATTERN (prev_insn)), reg_rtx))
4919             {
4920               if (sets_condition_code (SET_SRC (PATTERN (prev_insn))))
4921                 return (1);
4922
4923               return (0);
4924             }
4925
4926           else if (! doesnt_set_condition_code (SET_SRC (PATTERN (prev_insn))))
4927             return (0);
4928         }
4929
4930       else
4931         return (0);
4932
4933       prev_insn = PREV_INSN (prev_insn);
4934     }
4935
4936   return (0);
4937 }
4938 \f
4939 int
4940 doesnt_set_condition_code (pat)
4941      rtx pat;
4942 {
4943   switch (GET_CODE (pat))
4944     {
4945     case MEM:
4946     case REG:
4947       return 1;
4948
4949     default:
4950       return 0;
4951
4952     }
4953 }
4954 \f
4955 int
4956 sets_condition_code (pat)
4957      rtx pat;
4958 {
4959   switch (GET_CODE (pat))
4960     {
4961     case PLUS:
4962     case MINUS:
4963     case AND:
4964     case IOR:
4965     case XOR:
4966     case NOT:
4967     case NEG:
4968     case MULT:
4969     case DIV:
4970     case MOD:
4971     case UDIV:
4972     case UMOD:
4973       return 1;
4974
4975     default:
4976       return (0);
4977     }
4978 }
4979 \f
4980 int
4981 str_immediate_operand (op, mode)
4982      register rtx op;
4983      enum machine_mode mode ATTRIBUTE_UNUSED;
4984 {
4985   if (GET_CODE (op) == CONST_INT && INTVAL (op) <= 32 && INTVAL (op) >= 0)
4986     return 1;
4987
4988   return 0;
4989 }
4990 \f
4991 int
4992 is_fp_insn (insn)
4993      rtx insn;
4994 {
4995   if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SET
4996       && (GET_MODE (SET_DEST (PATTERN (insn))) == DFmode
4997           || GET_MODE (SET_DEST (PATTERN (insn))) == SFmode
4998           || GET_MODE (SET_DEST (PATTERN (insn))) == XFmode))
4999     return 1;
5000
5001   return 0;
5002 }
5003
5004 /* Return 1 if the mode of the SET_DEST of insn is floating point
5005    and it is not an fld or a move from memory to memory.
5006    Otherwise return 0 */
5007
5008 int
5009 is_fp_dest (insn)
5010      rtx insn;
5011 {
5012   if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SET
5013       && (GET_MODE (SET_DEST (PATTERN (insn))) == DFmode
5014           || GET_MODE (SET_DEST (PATTERN (insn))) == SFmode
5015           || GET_MODE (SET_DEST (PATTERN (insn))) == XFmode)
5016       && GET_CODE (SET_DEST (PATTERN (insn))) == REG
5017       && REGNO (SET_DEST (PATTERN (insn))) >= FIRST_FLOAT_REG
5018       && GET_CODE (SET_SRC (PATTERN (insn))) != MEM)
5019     return 1;
5020
5021   return 0;
5022 }
5023
5024 /* Return 1 if the mode of the SET_DEST of INSN is floating point and is
5025    memory and the source is a register.  */
5026
5027 int
5028 is_fp_store (insn)
5029      rtx insn;
5030 {
5031   if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SET
5032       && (GET_MODE (SET_DEST (PATTERN (insn))) == DFmode
5033           || GET_MODE (SET_DEST (PATTERN (insn))) == SFmode
5034           || GET_MODE (SET_DEST (PATTERN (insn))) == XFmode)
5035       && GET_CODE (SET_DEST (PATTERN (insn))) == MEM
5036       && GET_CODE (SET_SRC (PATTERN (insn))) == REG)
5037     return 1;
5038
5039   return 0;
5040 }
5041 \f
5042 /* Return 1 if DEP_INSN sets a register which INSN uses as a base
5043    or index to reference memory.
5044    otherwise return 0 */
5045
5046 int
5047 agi_dependent (insn, dep_insn)
5048      rtx insn, dep_insn;
5049 {
5050   int push = 0, push_dep = 0;
5051   if (GET_CODE (dep_insn) == INSN
5052       && GET_CODE (PATTERN (dep_insn)) == SET
5053       && GET_CODE (SET_DEST (PATTERN (dep_insn))) == REG
5054       && reg_mentioned_in_mem (SET_DEST (PATTERN (dep_insn)), insn))
5055     return 1;
5056
5057   if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SET
5058       && GET_CODE (SET_DEST (PATTERN (insn))) == MEM
5059       && push_operand (SET_DEST (PATTERN (insn)),
5060                        GET_MODE (SET_DEST (PATTERN (insn)))))
5061     push = 1;
5062
5063   if (GET_CODE (dep_insn) == INSN && GET_CODE (PATTERN (dep_insn)) == SET
5064       && GET_CODE (SET_DEST (PATTERN (dep_insn))) == MEM
5065       && push_operand (SET_DEST (PATTERN (dep_insn)),
5066                        GET_MODE (SET_DEST (PATTERN (dep_insn)))))
5067     push_dep = 1;
5068
5069   /* CPUs contain special hardware to allow two pushes.  */
5070   if (push && push_dep) 
5071     return 0;
5072
5073   /* Push operation implicitly change stack pointer causing AGI stalls.  */
5074   if (push_dep && reg_mentioned_in_mem (stack_pointer_rtx, insn))
5075     return 1;
5076
5077   /* Push also implicitly read stack pointer.  */
5078   if (push && modified_in_p (stack_pointer_rtx, dep_insn))
5079     return 1;
5080
5081   return 0;
5082 }
5083 \f
5084 /* Return 1 if reg is used in rtl as a base or index for a memory ref
5085    otherwise return 0. */
5086
5087 int
5088 reg_mentioned_in_mem (reg, rtl)
5089      rtx reg, rtl;
5090 {
5091   register char *fmt;
5092   register int i, j;
5093   register enum rtx_code code;
5094
5095   if (rtl == NULL)
5096     return 0;
5097
5098   code = GET_CODE (rtl);
5099
5100   switch (code)
5101     {
5102     case HIGH:
5103     case CONST_INT:
5104     case CONST:
5105     case CONST_DOUBLE:
5106     case SYMBOL_REF:
5107     case LABEL_REF:
5108     case PC:
5109     case CC0:
5110     case SUBREG:
5111       return 0;
5112     default:
5113       break;
5114     }
5115
5116   if (code == MEM && reg_mentioned_p (reg, rtl))
5117     return 1;
5118
5119   fmt = GET_RTX_FORMAT (code);
5120   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5121     {
5122       if (fmt[i] == 'E')
5123         {
5124           for (j = XVECLEN (rtl, i) - 1; j >= 0; j--)
5125             if (reg_mentioned_in_mem (reg, XVECEXP (rtl, i, j)))
5126               return 1;
5127         }
5128
5129       else if (fmt[i] == 'e' && reg_mentioned_in_mem (reg, XEXP (rtl, i)))
5130         return 1;
5131     }
5132
5133   return 0;
5134 }
5135 \f
5136 /* Output the appropriate insns for doing strlen if not just doing repnz; scasb
5137
5138    operands[0] = result, initialized with the startaddress
5139    operands[1] = alignment of the address.
5140    operands[2] = scratch register, initialized with the startaddress when
5141                  not aligned, otherwise undefined
5142
5143    This is just the body. It needs the initialisations mentioned above and
5144    some address computing at the end.  These things are done in i386.md.  */
5145
5146 char *
5147 output_strlen_unroll (operands)
5148      rtx operands[];
5149 {
5150   rtx xops[18];
5151
5152   xops[0] = operands[0];                /* Result */
5153   /*        operands[1];                 * Alignment */
5154   xops[1] = operands[2];                /* Scratch */
5155   xops[2] = GEN_INT (0);
5156   xops[3] = GEN_INT (2);
5157   xops[4] = GEN_INT (3);
5158   xops[5] = GEN_INT (4);
5159   /* xops[6] = gen_label_rtx ();         * label when aligned to 3-byte */
5160   /* xops[7] = gen_label_rtx ();         * label when aligned to 2-byte */
5161   xops[8] = gen_label_rtx ();           /* label of main loop */
5162
5163   if (TARGET_USE_Q_REG && QI_REG_P (xops[1]))
5164     xops[9] = gen_label_rtx ();         /* pentium optimisation */
5165
5166   xops[10] = gen_label_rtx ();          /* end label 2 */
5167   xops[11] = gen_label_rtx ();          /* end label 1 */
5168   xops[12] = gen_label_rtx ();          /* end label */
5169   /* xops[13]                            * Temporary used */
5170   xops[14] = GEN_INT (0xff);
5171   xops[15] = GEN_INT (0xff00);
5172   xops[16] = GEN_INT (0xff0000);
5173   xops[17] = GEN_INT (0xff000000);
5174
5175   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
5176
5177   /* Is there a known alignment and is it less than 4?  */
5178   if (GET_CODE (operands[1]) != CONST_INT || INTVAL (operands[1]) < 4)
5179     {
5180       /* Is there a known alignment and is it not 2? */
5181       if (GET_CODE (operands[1]) != CONST_INT || INTVAL (operands[1]) != 2)
5182         {
5183           xops[6] = gen_label_rtx (); /* Label when aligned to 3-byte */
5184           xops[7] = gen_label_rtx (); /* Label when aligned to 2-byte */
5185
5186           /* Leave just the 3 lower bits.
5187              If this is a q-register, then the high part is used later
5188              therefore use andl rather than andb. */
5189           output_asm_insn (AS2 (and%L1,%4,%1), xops);
5190
5191           /* Is aligned to 4-byte address when zero */
5192           output_asm_insn (AS1 (je,%l8), xops);
5193
5194           /* Side-effect even Parity when %eax == 3 */
5195           output_asm_insn (AS1 (jp,%6), xops);
5196
5197           /* Is it aligned to 2 bytes ? */
5198           if (QI_REG_P (xops[1]))
5199             output_asm_insn (AS2 (cmp%L1,%3,%1), xops);
5200           else
5201             output_asm_insn (AS2 (cmp%L1,%3,%1), xops);
5202
5203           output_asm_insn (AS1 (je,%7), xops);
5204         }
5205       else
5206         {
5207           /* Since the alignment is 2, we have to check 2 or 0 bytes;
5208              check if is aligned to 4 - byte.  */
5209           output_asm_insn (AS2 (and%L1,%3,%1), xops);
5210
5211           /* Is aligned to 4-byte address when zero */
5212           output_asm_insn (AS1 (je,%l8), xops);
5213         }
5214
5215       xops[13] = gen_rtx_MEM (QImode, xops[0]);
5216
5217       /* Now compare the bytes; compare with the high part of a q-reg
5218          gives shorter code. */
5219       if (QI_REG_P (xops[1]))
5220         {
5221           /* Compare the first n unaligned byte on a byte per byte basis. */
5222           output_asm_insn (AS2 (cmp%B1,%h1,%13), xops);
5223
5224           /* When zero we reached the end. */
5225           output_asm_insn (AS1 (je,%l12), xops);
5226
5227           /* Increment the address. */
5228           output_asm_insn (AS1 (inc%L0,%0), xops);
5229
5230           /* Not needed with an alignment of 2 */
5231           if (GET_CODE (operands[1]) != CONST_INT || INTVAL (operands[1]) != 2)
5232             {
5233               ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
5234                                          CODE_LABEL_NUMBER (xops[7]));
5235               output_asm_insn (AS2 (cmp%B1,%h1,%13), xops);
5236               output_asm_insn (AS1 (je,%l12), xops);
5237               output_asm_insn (AS1 (inc%L0,%0), xops);
5238
5239               ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
5240                                          CODE_LABEL_NUMBER (xops[6]));
5241             }
5242
5243           output_asm_insn (AS2 (cmp%B1,%h1,%13), xops);
5244         }
5245       else
5246         {
5247           output_asm_insn (AS2 (cmp%B13,%2,%13), xops);
5248           output_asm_insn (AS1 (je,%l12), xops);
5249           output_asm_insn (AS1 (inc%L0,%0), xops);
5250
5251           /* Not needed with an alignment of 2 */
5252           if (GET_CODE (operands[1]) != CONST_INT || INTVAL (operands[1]) != 2)
5253             {
5254           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
5255                                      CODE_LABEL_NUMBER (xops[7]));
5256           output_asm_insn (AS2 (cmp%B13,%2,%13), xops);
5257           output_asm_insn (AS1 (je,%l12), xops);
5258           output_asm_insn (AS1 (inc%L0,%0), xops);
5259
5260           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
5261                                      CODE_LABEL_NUMBER (xops[6]));
5262             }
5263
5264           output_asm_insn (AS2 (cmp%B13,%2,%13), xops);
5265         }
5266
5267       output_asm_insn (AS1 (je,%l12), xops);
5268       output_asm_insn (AS1 (inc%L0,%0), xops);
5269     }
5270
5271     /* Generate loop to check 4 bytes at a time.  It is not a good idea to
5272        align this loop.  It gives only huge programs, but does not help to
5273        speed up.  */
5274   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (xops[8]));
5275
5276   xops[13] = gen_rtx_MEM (SImode, xops[0]);
5277   output_asm_insn (AS2 (mov%L1,%13,%1), xops);
5278
5279   if (QI_REG_P (xops[1]))
5280     {
5281       /* On i586 it is faster to combine the hi- and lo- part as
5282          a kind of lookahead.  If anding both yields zero, then one
5283          of both *could* be zero, otherwise none of both is zero;
5284          this saves one instruction, on i486 this is slower
5285          tested with P-90, i486DX2-66, AMD486DX2-66  */
5286       if (TARGET_PENTIUM)
5287         {
5288           output_asm_insn (AS2 (test%B1,%h1,%b1), xops);
5289           output_asm_insn (AS1 (jne,%l9), xops);
5290         }
5291
5292       /* Check first byte. */
5293       output_asm_insn (AS2 (test%B1,%b1,%b1), xops);
5294       output_asm_insn (AS1 (je,%l12), xops);
5295
5296       /* Check second byte. */
5297       output_asm_insn (AS2 (test%B1,%h1,%h1), xops);
5298       output_asm_insn (AS1 (je,%l11), xops);
5299
5300       if (TARGET_PENTIUM)
5301         ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
5302                                    CODE_LABEL_NUMBER (xops[9]));
5303     }
5304
5305   else
5306     {
5307       /* Check first byte. */
5308       output_asm_insn (AS2 (test%L1,%14,%1), xops);
5309       output_asm_insn (AS1 (je,%l12), xops);
5310
5311       /* Check second byte. */
5312       output_asm_insn (AS2 (test%L1,%15,%1), xops);
5313       output_asm_insn (AS1 (je,%l11), xops);
5314     }
5315
5316   /* Check third byte. */
5317   output_asm_insn (AS2 (test%L1,%16,%1), xops);
5318   output_asm_insn (AS1 (je,%l10), xops);
5319
5320   /* Check fourth byte and increment address. */
5321   output_asm_insn (AS2 (add%L0,%5,%0), xops);
5322   output_asm_insn (AS2 (test%L1,%17,%1), xops);
5323   output_asm_insn (AS1 (jne,%l8), xops);
5324
5325   /* Now generate fixups when the compare stops within a 4-byte word. */
5326   output_asm_insn (AS2 (sub%L0,%4,%0), xops);
5327
5328   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (xops[10]));
5329   output_asm_insn (AS1 (inc%L0,%0), xops);
5330
5331   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (xops[11]));
5332   output_asm_insn (AS1 (inc%L0,%0), xops);
5333
5334   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (xops[12]));
5335
5336   return "";
5337 }
5338
5339 char *
5340 output_fp_conditional_move (which_alternative, operands)
5341      int which_alternative;
5342      rtx operands[];
5343 {
5344   enum rtx_code code = GET_CODE (operands[1]);
5345
5346   /* This should never happen.  */
5347   if (!(cc_prev_status.flags & CC_IN_80387)
5348       && (code == GT || code == LE || code == GE || code == LT))
5349     abort ();
5350
5351   switch (which_alternative)
5352     {
5353     case 0:
5354       /* r <- cond ? arg : r */
5355       output_asm_insn (AS2 (fcmov%F1,%2,%0), operands);
5356       break;
5357
5358     case 1:
5359       /* r <- cond ? r : arg */
5360       output_asm_insn (AS2 (fcmov%f1,%3,%0), operands);
5361       break;
5362
5363     default:
5364       abort ();
5365     }
5366
5367   return "";
5368 }
5369
5370 char *
5371 output_int_conditional_move (which_alternative, operands)
5372      int which_alternative;
5373      rtx operands[];
5374 {
5375   enum rtx_code code = GET_CODE (operands[1]);
5376
5377   /* This is very tricky. We have to do it right. For a code segement
5378      like:
5379
5380         int foo, bar;
5381         ....
5382         foo = foo - x;
5383         if (foo >= 0)
5384           bar = y;
5385
5386      final_scan_insn () may delete the insn which sets CC. We have to
5387      tell final_scan_insn () if it should be reinserted. When CODE is
5388      GT or LE, we have to check the CC_NO_OVERFLOW bit and return
5389      NULL_PTR to tell final to reinsert the test insn because the
5390      conditional move cannot be handled properly without it. */
5391   if ((code == GT || code == LE)
5392       && (cc_prev_status.flags & CC_NO_OVERFLOW))
5393     return NULL_PTR;
5394
5395   switch (which_alternative)
5396     {
5397     case 0:
5398       /* r <- cond ? arg : r */
5399       output_asm_insn (AS2 (cmov%C1,%2,%0), operands);
5400       break;
5401
5402     case 1:
5403       /* r <- cond ? r : arg */
5404       output_asm_insn (AS2 (cmov%c1,%3,%0), operands);
5405       break;
5406
5407     default:
5408       abort ();
5409     }
5410
5411   return "";
5412 }
5413
5414 int
5415 x86_adjust_cost (insn, link, dep_insn, cost)
5416      rtx insn, link, dep_insn;
5417      int cost;
5418 {
5419   rtx next_inst;
5420
5421   if (GET_CODE (dep_insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
5422     return 0;
5423
5424   if (GET_CODE (dep_insn) == INSN
5425       && GET_CODE (PATTERN (dep_insn)) == SET
5426       && GET_CODE (SET_DEST (PATTERN (dep_insn))) == REG
5427       && GET_CODE (insn) == INSN
5428       && GET_CODE (PATTERN (insn)) == SET
5429       && !reg_overlap_mentioned_p (SET_DEST (PATTERN (dep_insn)),
5430                                    SET_SRC (PATTERN (insn))))
5431     return 0;   /* ??? */
5432
5433
5434   switch (ix86_cpu)
5435     {
5436     case PROCESSOR_PENTIUM:
5437       if (cost != 0 && is_fp_insn (insn) && is_fp_insn (dep_insn)
5438           && !is_fp_dest (dep_insn))
5439         return 0;
5440
5441       if (agi_dependent (insn, dep_insn))
5442         return cost ? cost + 1 : 2;
5443
5444       if (GET_CODE (insn) == INSN
5445           && GET_CODE (PATTERN (insn)) == SET
5446           && SET_DEST (PATTERN (insn)) == cc0_rtx
5447           && (next_inst = next_nonnote_insn (insn))
5448           && GET_CODE (next_inst) == JUMP_INSN)
5449         /* compare probably paired with jump */
5450         return 0;
5451
5452       /* Stores stalls one cycle longer than other insns.  */
5453       if (is_fp_insn (insn) && cost && is_fp_store (dep_insn))
5454         cost++;
5455       break;
5456     case PROCESSOR_K6:
5457     default:
5458       if (!is_fp_dest (dep_insn))
5459         {
5460           if(!agi_dependent (insn, dep_insn))
5461             return 0;
5462           if (TARGET_486)
5463             return 2;
5464         }
5465       else
5466         if (is_fp_store (insn) && is_fp_insn (dep_insn)
5467             && NEXT_INSN (insn) && NEXT_INSN (NEXT_INSN (insn))
5468             && NEXT_INSN (NEXT_INSN (NEXT_INSN (insn)))
5469             && (GET_CODE (NEXT_INSN (insn)) == INSN)
5470             && (GET_CODE (NEXT_INSN (NEXT_INSN (insn))) == JUMP_INSN)
5471             && (GET_CODE (NEXT_INSN (NEXT_INSN (NEXT_INSN (insn)))) == NOTE)
5472             && (NOTE_LINE_NUMBER (NEXT_INSN (NEXT_INSN (NEXT_INSN (insn))))
5473                 == NOTE_INSN_LOOP_END))
5474           return 3;
5475       break;
5476     }
5477
5478   return cost;
5479 }
5480
5481 /* Output assembly code for a left shift.
5482
5483    Always use "sal" when shifting a memory operand or for a non constant
5484    shift count.
5485
5486    When optimizing for size, we know that src == dest, and we should always
5487    use "sal".  If src != dest, then copy src to dest and use "sal".
5488    
5489    Pentium and PPro (speed):
5490
5491      When src == dest, use "add" for a shift counts of one, else use
5492      "sal".  If we modeled Pentium AGI stalls and U/V pipelining better we
5493      would want to generate lea for some shifts on the Pentium.
5494
5495      When src != dest, use "lea" for small shift counts.  Otherwise,
5496      copy src to dest and use the normal shifting code.  Exception for
5497      TARGET_DOUBLE_WITH_ADD.  */
5498
5499 char *
5500 output_ashl (insn, operands)
5501      rtx insn, *operands;
5502 {
5503   /* Handle case where srcreg != dstreg.  */
5504   if (REG_P (operands[0]) && REGNO (operands[0]) != REGNO (operands[1]))
5505     {
5506       if (TARGET_DOUBLE_WITH_ADD && INTVAL (operands[2]) == 1)
5507         switch (GET_MODE (operands[0]))
5508           {
5509           case SImode:
5510             output_asm_insn (AS2 (mov%L0,%1,%0), operands);
5511             return AS2 (add%L0,%1,%0);
5512           case HImode:
5513             output_asm_insn (AS2 (mov%L0,%k1,%k0), operands);
5514             if (i386_cc_probably_useless_p (insn))
5515               {
5516                 CC_STATUS_INIT;
5517                 return AS2 (add%L0,%k1,%k0);
5518               }
5519             return AS2 (add%W0,%k1,%k0);
5520           case QImode:
5521             output_asm_insn (AS2 (mov%B0,%1,%0), operands);
5522             return AS2 (add%B0,%1,%0);
5523           default:
5524             abort ();
5525           }
5526       else
5527         {
5528           CC_STATUS_INIT;
5529
5530           /* This should be extremely rare (impossible?).  We can not encode a
5531              shift of the stack pointer using an lea instruction.  So copy the
5532              stack pointer into the destination register and use an lea.  */
5533           if (operands[1] == stack_pointer_rtx)
5534             {
5535               output_asm_insn (AS2 (mov%L0,%k1,%k0), operands);
5536               operands[1] = operands[0];
5537             }
5538
5539           /* For shifts up to and including 3 bits, use lea.  */
5540           operands[1] = gen_rtx_MULT (SImode,
5541                                       gen_rtx_REG (SImode, REGNO (operands[1])),
5542                                       GEN_INT (1 << INTVAL (operands[2])));
5543           return AS2 (lea%L0,%a1,%k0);
5544         }
5545     }
5546
5547   /* Source and destination match.  */
5548
5549   /* Handle variable shift.  */
5550   if (REG_P (operands[2]))
5551     switch (GET_MODE (operands[0]))
5552       {
5553       case SImode:
5554         return AS2 (sal%L0,%b2,%0);
5555       case HImode:
5556         if (REG_P (operands[0]) && i386_cc_probably_useless_p (insn))
5557           {
5558             CC_STATUS_INIT;
5559             return AS2 (sal%L0,%b2,%k0);
5560           }
5561         else
5562           return AS2 (sal%W0,%b2,%0);
5563       case QImode:
5564         return AS2 (sal%B0,%b2,%0);
5565       default:
5566         abort ();
5567       }
5568
5569   /* Always perform shift by 1 using an add instruction.  */
5570   if (REG_P (operands[0]) && operands[2] == const1_rtx)
5571     switch (GET_MODE (operands[0]))
5572       {
5573       case SImode:
5574         return AS2 (add%L0,%0,%0);
5575       case HImode:
5576         if (REG_P (operands[0]) && i386_cc_probably_useless_p (insn))
5577           {
5578             CC_STATUS_INIT;
5579             return AS2 (add%L0,%k0,%k0);
5580           }
5581         else
5582           return AS2 (add%W0,%0,%0);
5583       case QImode:
5584           return AS2 (add%B0,%0,%0);
5585       default:
5586           abort ();
5587       }
5588
5589 #if 0
5590   /* ??? Currently disabled.  Because our model of Pentium is far from being
5591      exact, this change will need some benchmarking.  */
5592   /* Shift reg by 2 or 3 use an lea instruction for Pentium if this is
5593      insn is expected to issue into the V pipe (the insn's mode will be
5594      TImode for a U pipe, and !TImode for a V pipe instruction).  */
5595   if (! optimize_size
5596       && REG_P (operands[0])
5597       && GET_CODE (operands[2]) == CONST_INT
5598       && INTVAL (operands[2]) <= 3
5599       && (int)ix86_cpu == (int)PROCESSOR_PENTIUM
5600       && GET_MODE (insn) != TImode)
5601     {
5602       CC_STATUS_INIT;
5603       operands[1] = gen_rtx_MULT (SImode, gen_rtx_REG (SImode, REGNO (operands[1])),
5604                                   GEN_INT (1 << INTVAL (operands[2])));
5605       return AS2 (lea%L0,%a1,%0);
5606     }
5607 #endif
5608
5609   /* Otherwise use a shift instruction.  */
5610   switch (GET_MODE (operands[0]))
5611     {
5612     case SImode:
5613       return AS2 (sal%L0,%2,%0);
5614     case HImode:
5615       if (REG_P (operands[0]) && i386_cc_probably_useless_p (insn))
5616         {
5617           CC_STATUS_INIT;
5618           return AS2 (sal%L0,%2,%k0);
5619         }
5620       else
5621         return AS2 (sal%W0,%2,%0);
5622     case QImode:
5623       return AS2 (sal%B0,%2,%0);
5624     default:
5625       abort ();
5626     }
5627 }
5628
5629 /* Given the memory address ADDR, calculate the length of the address or
5630    the length of just the displacement (controlled by DISP_LENGTH).
5631   
5632    The length returned does not include the one-byte modrm, opcode,
5633    or prefix.  */
5634
5635 int
5636 memory_address_info (addr, disp_length)
5637      rtx addr;
5638      int disp_length;
5639 {
5640   rtx base, index, disp, scale;
5641   rtx op0, op1;
5642   int len;
5643
5644   if (GET_CODE (addr) == PRE_DEC
5645       || GET_CODE (addr) == POST_INC)
5646     return 0;
5647
5648   /* Register Indirect.  */
5649   if (register_operand (addr, Pmode))
5650     {
5651       /* Special cases: ebp and esp need the two-byte modrm form. 
5652
5653          We change [ESI] to [ESI+0] on the K6 when not optimizing
5654          for size.  */
5655       if (addr == stack_pointer_rtx
5656           || addr == arg_pointer_rtx
5657           || addr == frame_pointer_rtx
5658           || (REGNO_REG_CLASS (REGNO (addr)) == SIREG
5659               && ix86_cpu == PROCESSOR_K6 && !optimize_size))
5660         return 1;
5661       else
5662         return 0;
5663     }
5664
5665   /* Direct Addressing.  */
5666   if (CONSTANT_P (addr))
5667     return 4;
5668
5669   index = base = disp = scale = NULL_RTX;
5670   op0 = XEXP (addr, 0);
5671   op1 = XEXP (addr, 1);
5672
5673   if (GET_CODE (addr) == PLUS)
5674     {
5675       if (register_operand (op0, Pmode))
5676         {
5677           if (register_operand (op1, Pmode))
5678             index = op0, base = op1;
5679           else
5680             base = op0, disp = op1;
5681         }
5682       else if (GET_CODE (op0) == MULT)
5683         {
5684           index = XEXP (op0, 0);
5685           scale = XEXP (op0, 1);
5686           if (register_operand (op1, Pmode))
5687             base = op1;
5688           else
5689             disp = op1;
5690         }
5691       else if (GET_CODE (op0) == PLUS && GET_CODE (XEXP (op0, 0)) == MULT)
5692         {
5693           index = XEXP (XEXP (op0, 0), 0);
5694           scale = XEXP (XEXP (op0, 0), 1);
5695           base = XEXP (op0, 1);
5696           disp = op1;
5697         }
5698       else if (GET_CODE (op0) == PLUS)
5699         {
5700           index = XEXP (op0, 0);
5701           base = XEXP (op0, 1);
5702           disp = op1;
5703         }
5704       else
5705         abort ();
5706     }
5707   else if (GET_CODE (addr) == MULT
5708            /* We're called for lea too, which implements ashift on occasion.  */
5709            || GET_CODE (addr) == ASHIFT)
5710     {
5711       index = XEXP (addr, 0);
5712       scale = XEXP (addr, 1);
5713     }
5714   else
5715     abort ();
5716       
5717   /* Allow arg pointer and stack pointer as index if there is not scaling */
5718   if (base && index && !scale
5719       && (index == stack_pointer_rtx
5720           || index == arg_pointer_rtx
5721           || index == frame_pointer_rtx))
5722     {
5723       rtx tmp = base;
5724       base = index;
5725       index = tmp;
5726     }
5727
5728   /* Special case: ebp cannot be encoded as a base without a displacement.  */
5729   if (base == frame_pointer_rtx && !disp)
5730     disp = const0_rtx;
5731
5732   /* Scaling can not be encoded without base or displacement.  
5733      Except for scale == 1 where we can encode reg + reg instead of reg * 2.  */
5734   if (!base && index
5735       && (!scale || GET_CODE (scale) != CONST_INT || (INTVAL (scale) != 1)))
5736     disp = const0_rtx;
5737
5738   /* Find the length of the displacement constant.  */
5739   len = 0;
5740   if (disp)
5741     {
5742       if (GET_CODE (disp) == CONST_INT
5743           && CONST_OK_FOR_LETTER_P (INTVAL (disp), 'K'))
5744         len = 1;
5745       else
5746         len = 4;
5747     }
5748
5749   /* An index requires the two-byte modrm form.  Not important
5750      if we are computing just length of the displacement.  */
5751   if (index && ! disp_length)
5752     len += 1;
5753
5754   return len;
5755 }