OSDN Git Service

* pa.c (function_arg): Pass floating arguments in both general and
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / pa.c
1 /* Subroutines for insn-output.c for HPPA.
2    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3    Free Software Foundation, Inc.
4    Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "real.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "output.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "tree.h"
35 #include "expr.h"
36 #include "optabs.h"
37 #include "libfuncs.h"
38 #include "reload.h"
39 #include "c-tree.h"
40 #include "integrate.h"
41 #include "function.h"
42 #include "obstack.h"
43 #include "toplev.h"
44 #include "ggc.h"
45 #include "recog.h"
46 #include "tm_p.h"
47 #include "target.h"
48 #include "target-def.h"
49
50 #ifndef DO_FRAME_NOTES
51 #ifdef INCOMING_RETURN_ADDR_RTX
52 #define DO_FRAME_NOTES 1
53 #else
54 #define DO_FRAME_NOTES 0
55 #endif
56 #endif
57
58 static inline rtx force_mode PARAMS ((enum machine_mode, rtx));
59 static void pa_combine_instructions PARAMS ((rtx));
60 static int pa_can_combine_p PARAMS ((rtx, rtx, rtx, int, rtx, rtx, rtx));
61 static int forward_branch_p PARAMS ((rtx));
62 static int shadd_constant_p PARAMS ((int));
63 static void pa_add_gc_roots PARAMS ((void));
64 static void mark_deferred_plabels PARAMS ((void *));
65 static void compute_zdepwi_operands PARAMS ((unsigned HOST_WIDE_INT, unsigned *));
66 static int compute_movstrsi_length PARAMS ((rtx));
67 static void remove_useless_addtr_insns PARAMS ((rtx, int));
68 static rtx store_reg PARAMS ((int, int, int));
69 static rtx load_reg PARAMS ((int, int, int));
70 static rtx set_reg_plus_d PARAMS ((int, int, int));
71 static void pa_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
72 static int pa_adjust_cost PARAMS ((rtx, rtx, rtx, int));
73 static int pa_adjust_priority PARAMS ((rtx, int));
74 static int pa_issue_rate PARAMS ((void));
75
76 /* Save the operands last given to a compare for use when we
77    generate a scc or bcc insn.  */
78
79 rtx hppa_compare_op0, hppa_compare_op1;
80 enum cmp_type hppa_branch_type;
81
82 /* Which cpu we are scheduling for.  */
83 enum processor_type pa_cpu;
84
85 /* String to hold which cpu we are scheduling for.  */
86 const char *pa_cpu_string;
87
88 /* Which architecture we are generating code for.  */
89 enum architecture_type pa_arch;
90
91 /* String to hold which architecture we are generating code for.  */
92 const char *pa_arch_string;
93
94 /* Counts for the number of callee-saved general and floating point
95    registers which were saved by the current function's prologue.  */
96 static int gr_saved, fr_saved;
97
98 static rtx find_addr_reg PARAMS ((rtx));
99
100 /* Keep track of the number of bytes we have output in the CODE subspaces
101    during this compilation so we'll know when to emit inline long-calls.  */
102
103 unsigned int total_code_bytes;
104
105 /* Variables to handle plabels that we discover are necessary at assembly
106    output time.  They are output after the current function.  */
107
108 struct deferred_plabel
109 {
110   rtx internal_label;
111   char *name;
112 } *deferred_plabels = 0;
113 int n_deferred_plabels = 0;
114 \f
115 /* Initialize the GCC target structure.  */
116 #undef TARGET_ASM_FUNCTION_PROLOGUE
117 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
118 #undef TARGET_ASM_FUNCTION_EPILOGUE
119 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
120
121 #undef TARGET_SCHED_ADJUST_COST
122 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
123 #undef TARGET_SCHED_ADJUST_PRIORITY
124 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
125 #undef TARGET_SCHED_ISSUE_RATE
126 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
127
128 struct gcc_target targetm = TARGET_INITIALIZER;
129 \f
130 void
131 override_options ()
132 {
133   /* Default to 7100LC scheduling.  */
134   if (pa_cpu_string && ! strcmp (pa_cpu_string, "7100"))
135     {
136       pa_cpu_string = "7100";
137       pa_cpu = PROCESSOR_7100;
138     }
139   else if (pa_cpu_string && ! strcmp (pa_cpu_string, "700"))
140     {
141       pa_cpu_string = "700";
142       pa_cpu = PROCESSOR_700;
143     }
144   else if (pa_cpu_string == NULL
145          || ! strcmp (pa_cpu_string, "7100LC"))
146     {
147       pa_cpu_string = "7100LC";
148       pa_cpu = PROCESSOR_7100LC;
149     }
150   else if (pa_cpu_string && ! strcmp (pa_cpu_string, "7200"))
151     {
152       pa_cpu_string = "7200";
153       pa_cpu = PROCESSOR_7200;
154     }
155   else if (pa_cpu_string && ! strcmp (pa_cpu_string, "8000"))
156     {
157       pa_cpu_string = "8000";
158       pa_cpu = PROCESSOR_8000;
159     }
160   else
161     {
162       warning ("Unknown -mschedule= option (%s).\nValid options are 700, 7100, 7100LC, 7200, and 8000\n", pa_cpu_string);
163     }
164
165   /* Set the instruction set architecture.  */
166   if (pa_arch_string && ! strcmp (pa_arch_string, "1.0"))
167     {
168       pa_arch_string = "1.0";
169       pa_arch = ARCHITECTURE_10;
170       target_flags &= ~(MASK_PA_11 | MASK_PA_20);
171     }
172   else if (pa_arch_string && ! strcmp (pa_arch_string, "1.1"))
173     {
174       pa_arch_string = "1.1";
175       pa_arch = ARCHITECTURE_11;
176       target_flags &= ~MASK_PA_20;
177       target_flags |= MASK_PA_11;
178     }
179   else if (pa_arch_string && ! strcmp (pa_arch_string, "2.0"))
180     {
181       pa_arch_string = "2.0";
182       pa_arch = ARCHITECTURE_20;
183       target_flags |= MASK_PA_11 | MASK_PA_20;
184     }
185   else if (pa_arch_string)
186     {
187       warning ("Unknown -march= option (%s).\nValid options are 1.0, 1.1, and 2.0\n", pa_arch_string);
188     }
189
190   if (flag_pic && TARGET_PORTABLE_RUNTIME)
191     {
192       warning ("PIC code generation is not supported in the portable runtime model\n");
193     }
194
195   if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
196    {
197       warning ("PIC code generation is not compatible with fast indirect calls\n");
198    }
199
200   if (! TARGET_GAS && write_symbols != NO_DEBUG)
201     {
202       warning ("-g is only supported when using GAS on this processor,");
203       warning ("-g option disabled.");
204       write_symbols = NO_DEBUG;
205     }
206
207   /* We only support the "big PIC" model now.  And we always generate PIC
208      code when in 64bit mode.  */
209   if (flag_pic == 1 || TARGET_64BIT)
210     flag_pic = 2;
211
212   /* Register global variables with the garbage collector.  */
213   pa_add_gc_roots ();
214 }
215
216 /* Return non-zero only if OP is a register of mode MODE,
217    or CONST0_RTX.  */
218 int
219 reg_or_0_operand (op, mode)
220      rtx op;
221      enum machine_mode mode;
222 {
223   return (op == CONST0_RTX (mode) || register_operand (op, mode));
224 }
225
226 /* Return non-zero if OP is suitable for use in a call to a named
227    function.
228
229    For 2.5 try to eliminate either call_operand_address or
230    function_label_operand, they perform very similar functions.  */
231 int
232 call_operand_address (op, mode)
233      rtx op;
234      enum machine_mode mode ATTRIBUTE_UNUSED;
235 {
236   return (GET_MODE (op) == word_mode
237           && CONSTANT_P (op) && ! TARGET_PORTABLE_RUNTIME);
238 }
239
240 /* Return 1 if X contains a symbolic expression.  We know these
241    expressions will have one of a few well defined forms, so
242    we need only check those forms.  */
243 int
244 symbolic_expression_p (x)
245      register rtx x;
246 {
247
248   /* Strip off any HIGH. */
249   if (GET_CODE (x) == HIGH)
250     x = XEXP (x, 0);
251
252   return (symbolic_operand (x, VOIDmode));
253 }
254
255 int
256 symbolic_operand (op, mode)
257      register rtx op;
258      enum machine_mode mode ATTRIBUTE_UNUSED;
259 {
260   switch (GET_CODE (op))
261     {
262     case SYMBOL_REF:
263     case LABEL_REF:
264       return 1;
265     case CONST:
266       op = XEXP (op, 0);
267       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
268                || GET_CODE (XEXP (op, 0)) == LABEL_REF)
269               && GET_CODE (XEXP (op, 1)) == CONST_INT);
270     default:
271       return 0;
272     }
273 }
274
275 /* Return truth value of statement that OP is a symbolic memory
276    operand of mode MODE.  */
277
278 int
279 symbolic_memory_operand (op, mode)
280      rtx op;
281      enum machine_mode mode ATTRIBUTE_UNUSED;
282 {
283   if (GET_CODE (op) == SUBREG)
284     op = SUBREG_REG (op);
285   if (GET_CODE (op) != MEM)
286     return 0;
287   op = XEXP (op, 0);
288   return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
289           || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
290 }
291
292 /* Return 1 if the operand is either a register or a memory operand that is
293    not symbolic.  */
294
295 int
296 reg_or_nonsymb_mem_operand (op, mode)
297     register rtx op;
298     enum machine_mode mode;
299 {
300   if (register_operand (op, mode))
301     return 1;
302
303   if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
304     return 1;
305
306   return 0;
307 }
308
309 /* Return 1 if the operand is either a register, zero, or a memory operand
310    that is not symbolic.  */
311
312 int
313 reg_or_0_or_nonsymb_mem_operand (op, mode)
314     register rtx op;
315     enum machine_mode mode;
316 {
317   if (register_operand (op, mode))
318     return 1;
319
320   if (op == CONST0_RTX (mode))
321     return 1;
322
323   if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
324     return 1;
325
326   return 0;
327 }
328
329 /* Accept any constant that can be moved in one instructions into a
330    general register.  */
331 int
332 cint_ok_for_move (intval)
333      HOST_WIDE_INT intval;
334 {
335   /* OK if ldo, ldil, or zdepi, can be used.  */
336   return (CONST_OK_FOR_LETTER_P (intval, 'J')
337           || CONST_OK_FOR_LETTER_P (intval, 'N')
338           || CONST_OK_FOR_LETTER_P (intval, 'K'));
339 }
340
341 /* Accept anything that can be moved in one instruction into a general
342    register.  */
343 int
344 move_operand (op, mode)
345      rtx op;
346      enum machine_mode mode;
347 {
348   if (register_operand (op, mode))
349     return 1;
350
351   if (GET_CODE (op) == CONSTANT_P_RTX)
352     return 1;
353
354   if (GET_CODE (op) == CONST_INT)
355     return cint_ok_for_move (INTVAL (op));
356
357   if (GET_CODE (op) == SUBREG)
358     op = SUBREG_REG (op);
359   if (GET_CODE (op) != MEM)
360     return 0;
361
362   op = XEXP (op, 0);
363
364   /* We consider a LO_SUM DLT reference a move_operand now since it has
365      been merged into the normal movsi/movdi patterns.  */
366   if (GET_CODE (op) == LO_SUM
367       && GET_CODE (XEXP (op, 0)) == REG
368       && REG_OK_FOR_BASE_P (XEXP (op, 0))
369       && GET_CODE (XEXP (op, 1)) == UNSPEC
370       && GET_MODE (op) == Pmode)
371     return 1;
372
373   /* Since move_operand is only used for source operands, we can always
374      allow scaled indexing!  */
375   if (! TARGET_DISABLE_INDEXING
376       && GET_CODE (op) == PLUS
377       && ((GET_CODE (XEXP (op, 0)) == MULT
378            && GET_CODE (XEXP (XEXP (op, 0), 0)) == REG
379            && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
380            && INTVAL (XEXP (XEXP (op, 0), 1))
381               == (HOST_WIDE_INT) GET_MODE_SIZE (mode)
382            && GET_CODE (XEXP (op, 1)) == REG)
383           || (GET_CODE (XEXP (op, 1)) == MULT
384               &&GET_CODE (XEXP (XEXP (op, 1), 0)) == REG
385               && GET_CODE (XEXP (XEXP (op, 1), 1)) == CONST_INT
386               && INTVAL (XEXP (XEXP (op, 1), 1))
387                  == (HOST_WIDE_INT) GET_MODE_SIZE (mode)
388               && GET_CODE (XEXP (op, 0)) == REG)))
389     return 1;
390
391   return memory_address_p (mode, op);
392 }
393
394 /* Accept REG and any CONST_INT that can be moved in one instruction into a
395    general register.  */
396 int
397 reg_or_cint_move_operand (op, mode)
398      rtx op;
399      enum machine_mode mode;
400 {
401   if (register_operand (op, mode))
402     return 1;
403
404   if (GET_CODE (op) == CONST_INT)
405     return cint_ok_for_move (INTVAL (op));
406
407   return 0;
408 }
409
410 int
411 pic_label_operand (op, mode)
412      rtx op;
413      enum machine_mode mode ATTRIBUTE_UNUSED;
414 {
415   if (!flag_pic)
416     return 0;
417
418   switch (GET_CODE (op))
419     {
420     case LABEL_REF:
421       return 1;
422     case CONST:
423       op = XEXP (op, 0);
424       return (GET_CODE (XEXP (op, 0)) == LABEL_REF
425               && GET_CODE (XEXP (op, 1)) == CONST_INT);
426     default:
427       return 0;
428     }
429 }
430
431 int
432 fp_reg_operand (op, mode)
433      rtx op;
434      enum machine_mode mode ATTRIBUTE_UNUSED;
435 {
436   return reg_renumber && FP_REG_P (op);
437 }
438
439 \f
440
441 /* Return truth value of whether OP can be used as an operand in a
442    three operand arithmetic insn that accepts registers of mode MODE
443    or 14-bit signed integers.  */
444 int
445 arith_operand (op, mode)
446      rtx op;
447      enum machine_mode mode;
448 {
449   return (register_operand (op, mode)
450           || (GET_CODE (op) == CONST_INT && INT_14_BITS (op)));
451 }
452
453 /* Return truth value of whether OP can be used as an operand in a
454    three operand arithmetic insn that accepts registers of mode MODE
455    or 11-bit signed integers.  */
456 int
457 arith11_operand (op, mode)
458      rtx op;
459      enum machine_mode mode;
460 {
461   return (register_operand (op, mode)
462           || (GET_CODE (op) == CONST_INT && INT_11_BITS (op)));
463 }
464
465 /* A constant integer suitable for use in a PRE_MODIFY memory
466    reference.  */
467 int
468 pre_cint_operand (op, mode)
469      rtx op;
470      enum machine_mode mode ATTRIBUTE_UNUSED;
471 {
472   return (GET_CODE (op) == CONST_INT
473           && INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10);
474 }
475
476 /* A constant integer suitable for use in a POST_MODIFY memory
477    reference.  */
478 int
479 post_cint_operand (op, mode)
480      rtx op;
481      enum machine_mode mode ATTRIBUTE_UNUSED;
482 {
483   return (GET_CODE (op) == CONST_INT
484           && INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10);
485 }
486
487 int
488 arith_double_operand (op, mode)
489      rtx op;
490      enum machine_mode mode;
491 {
492   return (register_operand (op, mode)
493           || (GET_CODE (op) == CONST_DOUBLE
494               && GET_MODE (op) == mode
495               && VAL_14_BITS_P (CONST_DOUBLE_LOW (op))
496               && ((CONST_DOUBLE_HIGH (op) >= 0)
497                   == ((CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
498 }
499
500 /* Return truth value of whether OP is a integer which fits the
501    range constraining immediate operands in three-address insns, or
502    is an integer register.  */
503
504 int
505 ireg_or_int5_operand (op, mode)
506      rtx op;
507      enum machine_mode mode ATTRIBUTE_UNUSED;
508 {
509   return ((GET_CODE (op) == CONST_INT && INT_5_BITS (op))
510           || (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32));
511 }
512
513 /* Return nonzero if OP is an integer register, else return zero.  */
514 int
515 ireg_operand (op, mode)
516      rtx op;
517      enum machine_mode mode ATTRIBUTE_UNUSED;
518 {
519   return (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32);
520 }
521
522 /* Return truth value of whether OP is a integer which fits the
523    range constraining immediate operands in three-address insns.  */
524
525 int
526 int5_operand (op, mode)
527      rtx op;
528      enum machine_mode mode ATTRIBUTE_UNUSED;
529 {
530   return (GET_CODE (op) == CONST_INT && INT_5_BITS (op));
531 }
532
533 int
534 uint5_operand (op, mode)
535      rtx op;
536      enum machine_mode mode ATTRIBUTE_UNUSED;
537 {
538   return (GET_CODE (op) == CONST_INT && INT_U5_BITS (op));
539 }
540
541 int
542 int11_operand (op, mode)
543      rtx op;
544      enum machine_mode mode ATTRIBUTE_UNUSED;
545 {
546   return (GET_CODE (op) == CONST_INT && INT_11_BITS (op));
547 }
548
549 int
550 uint32_operand (op, mode)
551      rtx op;
552      enum machine_mode mode ATTRIBUTE_UNUSED;
553 {
554 #if HOST_BITS_PER_WIDE_INT > 32
555   /* All allowed constants will fit a CONST_INT.  */
556   return (GET_CODE (op) == CONST_INT
557           && (INTVAL (op) >= 0 && INTVAL (op) < (HOST_WIDE_INT) 1 << 32));
558 #else
559   return (GET_CODE (op) == CONST_INT
560           || (GET_CODE (op) == CONST_DOUBLE
561               && CONST_DOUBLE_HIGH (op) == 0));
562 #endif
563 }
564
565 int
566 arith5_operand (op, mode)
567      rtx op;
568      enum machine_mode mode;
569 {
570   return register_operand (op, mode) || int5_operand (op, mode);
571 }
572
573 /* True iff zdepi can be used to generate this CONST_INT.
574    zdepi first sign extends a 5 bit signed number to a given field
575    length, then places this field anywhere in a zero.  */
576 int
577 zdepi_cint_p (x)
578      unsigned HOST_WIDE_INT x;
579 {
580   unsigned HOST_WIDE_INT lsb_mask, t;
581
582   /* This might not be obvious, but it's at least fast.
583      This function is critical; we don't have the time loops would take.  */
584   lsb_mask = x & -x;
585   t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
586   /* Return true iff t is a power of two.  */
587   return ((t & (t - 1)) == 0);
588 }
589
590 /* True iff depi or extru can be used to compute (reg & mask).
591    Accept bit pattern like these:
592    0....01....1
593    1....10....0
594    1..10..01..1  */
595 int
596 and_mask_p (mask)
597      unsigned HOST_WIDE_INT mask;
598 {
599   mask = ~mask;
600   mask += mask & -mask;
601   return (mask & (mask - 1)) == 0;
602 }
603
604 /* True iff depi or extru can be used to compute (reg & OP).  */
605 int
606 and_operand (op, mode)
607      rtx op;
608      enum machine_mode mode;
609 {
610   return (register_operand (op, mode)
611           || (GET_CODE (op) == CONST_INT && and_mask_p (INTVAL (op))));
612 }
613
614 /* True iff depi can be used to compute (reg | MASK).  */
615 int
616 ior_mask_p (mask)
617      unsigned HOST_WIDE_INT mask;
618 {
619   mask += mask & -mask;
620   return (mask & (mask - 1)) == 0;
621 }
622
623 /* True iff depi can be used to compute (reg | OP).  */
624 int
625 ior_operand (op, mode)
626      rtx op;
627      enum machine_mode mode ATTRIBUTE_UNUSED;
628 {
629   return (GET_CODE (op) == CONST_INT && ior_mask_p (INTVAL (op)));
630 }
631
632 int
633 lhs_lshift_operand (op, mode)
634      rtx op;
635      enum machine_mode mode;
636 {
637   return register_operand (op, mode) || lhs_lshift_cint_operand (op, mode);
638 }
639
640 /* True iff OP is a CONST_INT of the forms 0...0xxxx or 0...01...1xxxx.
641    Such values can be the left hand side x in (x << r), using the zvdepi
642    instruction.  */
643 int
644 lhs_lshift_cint_operand (op, mode)
645      rtx op;
646      enum machine_mode mode ATTRIBUTE_UNUSED;
647 {
648   unsigned HOST_WIDE_INT x;
649   if (GET_CODE (op) != CONST_INT)
650     return 0;
651   x = INTVAL (op) >> 4;
652   return (x & (x + 1)) == 0;
653 }
654
655 int
656 arith32_operand (op, mode)
657      rtx op;
658      enum machine_mode mode;
659 {
660   return register_operand (op, mode) || GET_CODE (op) == CONST_INT;
661 }
662
663 int
664 pc_or_label_operand (op, mode)
665      rtx op;
666      enum machine_mode mode ATTRIBUTE_UNUSED;
667 {
668   return (GET_CODE (op) == PC || GET_CODE (op) == LABEL_REF);
669 }
670 \f
671 /* Legitimize PIC addresses.  If the address is already
672    position-independent, we return ORIG.  Newly generated
673    position-independent addresses go to REG.  If we need more
674    than one register, we lose.  */
675
676 rtx
677 legitimize_pic_address (orig, mode, reg)
678      rtx orig, reg;
679      enum machine_mode mode;
680 {
681   rtx pic_ref = orig;
682
683   /* Labels need special handling.  */
684   if (pic_label_operand (orig, mode))
685     {
686       /* We do not want to go through the movXX expanders here since that
687          would create recursion.
688
689          Nor do we really want to call a generator for a named pattern
690          since that requires multiple patterns if we want to support
691          multiple word sizes.
692
693          So instead we just emit the raw set, which avoids the movXX
694          expanders completely.  */
695       emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
696       current_function_uses_pic_offset_table = 1;
697       return reg;
698     }
699   if (GET_CODE (orig) == SYMBOL_REF)
700     {
701       if (reg == 0)
702         abort ();
703
704       emit_move_insn (reg,
705                       gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
706                                     gen_rtx_HIGH (word_mode, orig)));
707       pic_ref
708         = gen_rtx_MEM (Pmode,
709                        gen_rtx_LO_SUM (Pmode, reg,
710                                        gen_rtx_UNSPEC (Pmode,
711                                                        gen_rtvec (1, orig),
712                                                        0)));
713
714       current_function_uses_pic_offset_table = 1;
715       RTX_UNCHANGING_P (pic_ref) = 1;
716       emit_move_insn (reg, pic_ref);
717       return reg;
718     }
719   else if (GET_CODE (orig) == CONST)
720     {
721       rtx base;
722
723       if (GET_CODE (XEXP (orig, 0)) == PLUS
724           && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
725         return orig;
726
727       if (reg == 0)
728         abort ();
729
730       if (GET_CODE (XEXP (orig, 0)) == PLUS)
731         {
732           base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
733           orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
734                                          base == reg ? 0 : reg);
735         }
736       else abort ();
737       if (GET_CODE (orig) == CONST_INT)
738         {
739           if (INT_14_BITS (orig))
740             return plus_constant (base, INTVAL (orig));
741           orig = force_reg (Pmode, orig);
742         }
743       pic_ref = gen_rtx_PLUS (Pmode, base, orig);
744       /* Likewise, should we set special REG_NOTEs here?  */
745     }
746   return pic_ref;
747 }
748
749 /* Try machine-dependent ways of modifying an illegitimate address
750    to be legitimate.  If we find one, return the new, valid address.
751    This macro is used in only one place: `memory_address' in explow.c.
752
753    OLDX is the address as it was before break_out_memory_refs was called.
754    In some cases it is useful to look at this to decide what needs to be done.
755
756    MODE and WIN are passed so that this macro can use
757    GO_IF_LEGITIMATE_ADDRESS.
758
759    It is always safe for this macro to do nothing.  It exists to recognize
760    opportunities to optimize the output.
761
762    For the PA, transform:
763
764         memory(X + <large int>)
765
766    into:
767
768         if (<large int> & mask) >= 16
769           Y = (<large int> & ~mask) + mask + 1  Round up.
770         else
771           Y = (<large int> & ~mask)             Round down.
772         Z = X + Y
773         memory (Z + (<large int> - Y));
774
775    This is for CSE to find several similar references, and only use one Z.
776
777    X can either be a SYMBOL_REF or REG, but because combine can not
778    perform a 4->2 combination we do nothing for SYMBOL_REF + D where
779    D will not fit in 14 bits.
780
781    MODE_FLOAT references allow displacements which fit in 5 bits, so use
782    0x1f as the mask.
783
784    MODE_INT references allow displacements which fit in 14 bits, so use
785    0x3fff as the mask.
786
787    This relies on the fact that most mode MODE_FLOAT references will use FP
788    registers and most mode MODE_INT references will use integer registers.
789    (In the rare case of an FP register used in an integer MODE, we depend
790    on secondary reloads to clean things up.)
791
792
793    It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
794    manner if Y is 2, 4, or 8.  (allows more shadd insns and shifted indexed
795    addressing modes to be used).
796
797    Put X and Z into registers.  Then put the entire expression into
798    a register.  */
799
800 rtx
801 hppa_legitimize_address (x, oldx, mode)
802      rtx x, oldx ATTRIBUTE_UNUSED;
803      enum machine_mode mode;
804 {
805   rtx orig = x;
806
807   if (flag_pic)
808     return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
809
810   /* Strip off CONST. */
811   if (GET_CODE (x) == CONST)
812     x = XEXP (x, 0);
813
814   /* Special case.  Get the SYMBOL_REF into a register and use indexing.
815      That should always be safe.  */
816   if (GET_CODE (x) == PLUS
817       && GET_CODE (XEXP (x, 0)) == REG
818       && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
819     {
820       rtx reg = force_reg (Pmode, XEXP (x, 1));
821       return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
822     }
823
824   /* Note we must reject symbols which represent function addresses
825      since the assembler/linker can't handle arithmetic on plabels.  */
826   if (GET_CODE (x) == PLUS
827       && GET_CODE (XEXP (x, 1)) == CONST_INT
828       && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
829            && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
830           || GET_CODE (XEXP (x, 0)) == REG))
831     {
832       rtx int_part, ptr_reg;
833       int newoffset;
834       int offset = INTVAL (XEXP (x, 1));
835       int mask;
836
837       mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
838               ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
839
840       /* Choose which way to round the offset.  Round up if we
841          are >= halfway to the next boundary.  */
842       if ((offset & mask) >= ((mask + 1) / 2))
843         newoffset = (offset & ~ mask) + mask + 1;
844       else
845         newoffset = (offset & ~ mask);
846
847       /* If the newoffset will not fit in 14 bits (ldo), then
848          handling this would take 4 or 5 instructions (2 to load
849          the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
850          add the new offset and the SYMBOL_REF.)  Combine can
851          not handle 4->2 or 5->2 combinations, so do not create
852          them.  */
853       if (! VAL_14_BITS_P (newoffset)
854           && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
855         {
856           rtx const_part = plus_constant (XEXP (x, 0), newoffset);
857           rtx tmp_reg
858             = force_reg (Pmode,
859                          gen_rtx_HIGH (Pmode, const_part));
860           ptr_reg
861             = force_reg (Pmode,
862                          gen_rtx_LO_SUM (Pmode,
863                                          tmp_reg, const_part));
864         }
865       else
866         {
867           if (! VAL_14_BITS_P (newoffset))
868             int_part = force_reg (Pmode, GEN_INT (newoffset));
869           else
870             int_part = GEN_INT (newoffset);
871
872           ptr_reg = force_reg (Pmode,
873                                gen_rtx_PLUS (Pmode,
874                                              force_reg (Pmode, XEXP (x, 0)),
875                                              int_part));
876         }
877       return plus_constant (ptr_reg, offset - newoffset);
878     }
879
880   /* Handle (plus (mult (a) (shadd_constant)) (b)).  */
881
882   if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
883       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
884       && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
885       && (GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == 'o'
886           || GET_CODE (XEXP (x, 1)) == SUBREG)
887       && GET_CODE (XEXP (x, 1)) != CONST)
888     {
889       int val = INTVAL (XEXP (XEXP (x, 0), 1));
890       rtx reg1, reg2;
891
892       reg1 = XEXP (x, 1);
893       if (GET_CODE (reg1) != REG)
894         reg1 = force_reg (Pmode, force_operand (reg1, 0));
895
896       reg2 = XEXP (XEXP (x, 0), 0);
897       if (GET_CODE (reg2) != REG)
898         reg2 = force_reg (Pmode, force_operand (reg2, 0));
899
900       return force_reg (Pmode, gen_rtx_PLUS (Pmode,
901                                              gen_rtx_MULT (Pmode,
902                                                            reg2,
903                                                            GEN_INT (val)),
904                                              reg1));
905     }
906
907   /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
908
909      Only do so for floating point modes since this is more speculative
910      and we lose if it's an integer store.  */
911   if (GET_CODE (x) == PLUS
912       && GET_CODE (XEXP (x, 0)) == PLUS
913       && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
914       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
915       && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
916       && (mode == SFmode || mode == DFmode))
917     {
918
919       /* First, try and figure out what to use as a base register.  */
920       rtx reg1, reg2, base, idx, orig_base;
921
922       reg1 = XEXP (XEXP (x, 0), 1);
923       reg2 = XEXP (x, 1);
924       base = NULL_RTX;
925       idx = NULL_RTX;
926
927       /* Make sure they're both regs.  If one was a SYMBOL_REF [+ const],
928          then emit_move_sequence will turn on REG_POINTER so we'll know
929          it's a base register below.  */
930       if (GET_CODE (reg1) != REG)
931         reg1 = force_reg (Pmode, force_operand (reg1, 0));
932
933       if (GET_CODE (reg2) != REG)
934         reg2 = force_reg (Pmode, force_operand (reg2, 0));
935
936       /* Figure out what the base and index are.  */
937
938       if (GET_CODE (reg1) == REG
939           && REG_POINTER (reg1))
940         {
941           base = reg1;
942           orig_base = XEXP (XEXP (x, 0), 1);
943           idx = gen_rtx_PLUS (Pmode,
944                               gen_rtx_MULT (Pmode,
945                                             XEXP (XEXP (XEXP (x, 0), 0), 0),
946                                             XEXP (XEXP (XEXP (x, 0), 0), 1)),
947                               XEXP (x, 1));
948         }
949       else if (GET_CODE (reg2) == REG
950                && REG_POINTER (reg2))
951         {
952           base = reg2;
953           orig_base = XEXP (x, 1);
954           idx = XEXP (x, 0);
955         }
956
957       if (base == 0)
958         return orig;
959
960       /* If the index adds a large constant, try to scale the
961          constant so that it can be loaded with only one insn.  */
962       if (GET_CODE (XEXP (idx, 1)) == CONST_INT
963           && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
964                             / INTVAL (XEXP (XEXP (idx, 0), 1)))
965           && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
966         {
967           /* Divide the CONST_INT by the scale factor, then add it to A.  */
968           int val = INTVAL (XEXP (idx, 1));
969
970           val /= INTVAL (XEXP (XEXP (idx, 0), 1));
971           reg1 = XEXP (XEXP (idx, 0), 0);
972           if (GET_CODE (reg1) != REG)
973             reg1 = force_reg (Pmode, force_operand (reg1, 0));
974
975           reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
976
977           /* We can now generate a simple scaled indexed address.  */
978           return
979             force_reg
980               (Pmode, gen_rtx_PLUS (Pmode,
981                                     gen_rtx_MULT (Pmode, reg1,
982                                                   XEXP (XEXP (idx, 0), 1)),
983                                     base));
984         }
985
986       /* If B + C is still a valid base register, then add them.  */
987       if (GET_CODE (XEXP (idx, 1)) == CONST_INT
988           && INTVAL (XEXP (idx, 1)) <= 4096
989           && INTVAL (XEXP (idx, 1)) >= -4096)
990         {
991           int val = INTVAL (XEXP (XEXP (idx, 0), 1));
992           rtx reg1, reg2;
993
994           reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
995
996           reg2 = XEXP (XEXP (idx, 0), 0);
997           if (GET_CODE (reg2) != CONST_INT)
998             reg2 = force_reg (Pmode, force_operand (reg2, 0));
999
1000           return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1001                                                  gen_rtx_MULT (Pmode,
1002                                                                reg2,
1003                                                                GEN_INT (val)),
1004                                                  reg1));
1005         }
1006
1007       /* Get the index into a register, then add the base + index and
1008          return a register holding the result.  */
1009
1010       /* First get A into a register.  */
1011       reg1 = XEXP (XEXP (idx, 0), 0);
1012       if (GET_CODE (reg1) != REG)
1013         reg1 = force_reg (Pmode, force_operand (reg1, 0));
1014
1015       /* And get B into a register.  */
1016       reg2 = XEXP (idx, 1);
1017       if (GET_CODE (reg2) != REG)
1018         reg2 = force_reg (Pmode, force_operand (reg2, 0));
1019
1020       reg1 = force_reg (Pmode,
1021                         gen_rtx_PLUS (Pmode,
1022                                       gen_rtx_MULT (Pmode, reg1,
1023                                                     XEXP (XEXP (idx, 0), 1)),
1024                                       reg2));
1025
1026       /* Add the result to our base register and return.  */
1027       return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1028
1029     }
1030
1031   /* Uh-oh.  We might have an address for x[n-100000].  This needs
1032      special handling to avoid creating an indexed memory address
1033      with x-100000 as the base.
1034
1035      If the constant part is small enough, then it's still safe because
1036      there is a guard page at the beginning and end of the data segment.
1037
1038      Scaled references are common enough that we want to try and rearrange the
1039      terms so that we can use indexing for these addresses too.  Only
1040      do the optimization for floatint point modes.  */
1041
1042   if (GET_CODE (x) == PLUS
1043       && symbolic_expression_p (XEXP (x, 1)))
1044     {
1045       /* Ugly.  We modify things here so that the address offset specified
1046          by the index expression is computed first, then added to x to form
1047          the entire address.  */
1048
1049       rtx regx1, regx2, regy1, regy2, y;
1050
1051       /* Strip off any CONST.  */
1052       y = XEXP (x, 1);
1053       if (GET_CODE (y) == CONST)
1054         y = XEXP (y, 0);
1055
1056       if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1057         {
1058           /* See if this looks like
1059                 (plus (mult (reg) (shadd_const))
1060                       (const (plus (symbol_ref) (const_int))))
1061
1062              Where const_int is small.  In that case the const
1063              expression is a valid pointer for indexing.
1064
1065              If const_int is big, but can be divided evenly by shadd_const
1066              and added to (reg).  This allows more scaled indexed addresses.  */
1067           if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1068               && GET_CODE (XEXP (x, 0)) == MULT
1069               && GET_CODE (XEXP (y, 1)) == CONST_INT
1070               && INTVAL (XEXP (y, 1)) >= -4096
1071               && INTVAL (XEXP (y, 1)) <= 4095
1072               && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1073               && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1074             {
1075               int val = INTVAL (XEXP (XEXP (x, 0), 1));
1076               rtx reg1, reg2;
1077
1078               reg1 = XEXP (x, 1);
1079               if (GET_CODE (reg1) != REG)
1080                 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1081
1082               reg2 = XEXP (XEXP (x, 0), 0);
1083               if (GET_CODE (reg2) != REG)
1084                 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1085
1086               return force_reg (Pmode,
1087                                 gen_rtx_PLUS (Pmode,
1088                                               gen_rtx_MULT (Pmode,
1089                                                             reg2,
1090                                                             GEN_INT (val)),
1091                                               reg1));
1092             }
1093           else if ((mode == DFmode || mode == SFmode)
1094                    && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1095                    && GET_CODE (XEXP (x, 0)) == MULT
1096                    && GET_CODE (XEXP (y, 1)) == CONST_INT
1097                    && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1098                    && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1099                    && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1100             {
1101               regx1
1102                 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1103                                              / INTVAL (XEXP (XEXP (x, 0), 1))));
1104               regx2 = XEXP (XEXP (x, 0), 0);
1105               if (GET_CODE (regx2) != REG)
1106                 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1107               regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1108                                                         regx2, regx1));
1109               return
1110                 force_reg (Pmode,
1111                            gen_rtx_PLUS (Pmode,
1112                                          gen_rtx_MULT (Pmode, regx2,
1113                                                        XEXP (XEXP (x, 0), 1)),
1114                                          force_reg (Pmode, XEXP (y, 0))));
1115             }
1116           else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1117                    && INTVAL (XEXP (y, 1)) >= -4096
1118                    && INTVAL (XEXP (y, 1)) <= 4095)
1119             {
1120               /* This is safe because of the guard page at the
1121                  beginning and end of the data space.  Just
1122                  return the original address.  */
1123               return orig;
1124             }
1125           else
1126             {
1127               /* Doesn't look like one we can optimize.  */
1128               regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1129               regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1130               regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1131               regx1 = force_reg (Pmode,
1132                                  gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1133                                                  regx1, regy2));
1134               return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1135             }
1136         }
1137     }
1138
1139   return orig;
1140 }
1141
1142 /* For the HPPA, REG and REG+CONST is cost 0
1143    and addresses involving symbolic constants are cost 2.
1144
1145    PIC addresses are very expensive.
1146
1147    It is no coincidence that this has the same structure
1148    as GO_IF_LEGITIMATE_ADDRESS.  */
1149 int
1150 hppa_address_cost (X)
1151      rtx X;
1152 {
1153   if (GET_CODE (X) == PLUS)
1154       return 1;
1155   else if (GET_CODE (X) == LO_SUM)
1156     return 1;
1157   else if (GET_CODE (X) == HIGH)
1158     return 2;
1159   return 4;
1160 }
1161
1162 /* Ensure mode of ORIG, a REG rtx, is MODE.  Returns either ORIG or a
1163    new rtx with the correct mode.  */
1164 static inline rtx
1165 force_mode (mode, orig)
1166      enum machine_mode mode;
1167      rtx orig;
1168 {
1169   if (mode == GET_MODE (orig))
1170     return orig;
1171
1172   if (REGNO (orig) >= FIRST_PSEUDO_REGISTER)
1173     abort ();
1174
1175   return gen_rtx_REG (mode, REGNO (orig));
1176 }
1177
1178 /* Emit insns to move operands[1] into operands[0].
1179
1180    Return 1 if we have written out everything that needs to be done to
1181    do the move.  Otherwise, return 0 and the caller will emit the move
1182    normally.
1183
1184    Note SCRATCH_REG may not be in the proper mode depending on how it
1185    will be used.  This routine is resposible for creating a new copy
1186    of SCRATCH_REG in the proper mode.  */
1187
1188 int
1189 emit_move_sequence (operands, mode, scratch_reg)
1190      rtx *operands;
1191      enum machine_mode mode;
1192      rtx scratch_reg;
1193 {
1194   register rtx operand0 = operands[0];
1195   register rtx operand1 = operands[1];
1196   register rtx tem;
1197
1198   if (scratch_reg
1199       && reload_in_progress && GET_CODE (operand0) == REG
1200       && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1201     operand0 = reg_equiv_mem[REGNO (operand0)];
1202   else if (scratch_reg
1203            && reload_in_progress && GET_CODE (operand0) == SUBREG
1204            && GET_CODE (SUBREG_REG (operand0)) == REG
1205            && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1206     {
1207      /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1208         the code which tracks sets/uses for delete_output_reload.  */
1209       rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1210                                  reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1211                                  SUBREG_BYTE (operand0));
1212       operand0 = alter_subreg (temp);
1213     }
1214
1215   if (scratch_reg
1216       && reload_in_progress && GET_CODE (operand1) == REG
1217       && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1218     operand1 = reg_equiv_mem[REGNO (operand1)];
1219   else if (scratch_reg
1220            && reload_in_progress && GET_CODE (operand1) == SUBREG
1221            && GET_CODE (SUBREG_REG (operand1)) == REG
1222            && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1223     {
1224      /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1225         the code which tracks sets/uses for delete_output_reload.  */
1226       rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1227                                  reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1228                                  SUBREG_BYTE (operand1));
1229       operand1 = alter_subreg (temp);
1230     }
1231
1232   if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1233       && ((tem = find_replacement (&XEXP (operand0, 0)))
1234           != XEXP (operand0, 0)))
1235     operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
1236   if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1237       && ((tem = find_replacement (&XEXP (operand1, 0)))
1238           != XEXP (operand1, 0)))
1239     operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
1240
1241   /* Handle secondary reloads for loads/stores of FP registers from
1242      REG+D addresses where D does not fit in 5 bits, including
1243      (subreg (mem (addr))) cases.  */
1244   if (fp_reg_operand (operand0, mode)
1245       && ((GET_CODE (operand1) == MEM
1246            && ! memory_address_p (DFmode, XEXP (operand1, 0)))
1247           || ((GET_CODE (operand1) == SUBREG
1248                && GET_CODE (XEXP (operand1, 0)) == MEM
1249                && !memory_address_p (DFmode, XEXP (XEXP (operand1, 0), 0)))))
1250       && scratch_reg)
1251     {
1252       if (GET_CODE (operand1) == SUBREG)
1253         operand1 = XEXP (operand1, 0);
1254
1255       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1256          it in WORD_MODE regardless of what mode it was originally given
1257          to us.  */
1258       scratch_reg = force_mode (word_mode, scratch_reg);
1259
1260       /* D might not fit in 14 bits either; for such cases load D into
1261          scratch reg.  */
1262       if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1263         {
1264           emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1265           emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1266                                                        Pmode,
1267                                                        XEXP (XEXP (operand1, 0), 0),
1268                                                        scratch_reg));
1269         }
1270       else
1271         emit_move_insn (scratch_reg, XEXP (operand1, 0));
1272       emit_insn (gen_rtx_SET (VOIDmode, operand0,
1273                               gen_rtx_MEM (mode, scratch_reg)));
1274       return 1;
1275     }
1276   else if (fp_reg_operand (operand1, mode)
1277            && ((GET_CODE (operand0) == MEM
1278                 && ! memory_address_p (DFmode, XEXP (operand0, 0)))
1279                || ((GET_CODE (operand0) == SUBREG)
1280                    && GET_CODE (XEXP (operand0, 0)) == MEM
1281                    && !memory_address_p (DFmode, XEXP (XEXP (operand0, 0), 0))))
1282            && scratch_reg)
1283     {
1284       if (GET_CODE (operand0) == SUBREG)
1285         operand0 = XEXP (operand0, 0);
1286
1287       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1288          it in WORD_MODE regardless of what mode it was originally given
1289          to us.  */
1290       scratch_reg = force_mode (word_mode, scratch_reg);
1291
1292       /* D might not fit in 14 bits either; for such cases load D into
1293          scratch reg.  */
1294       if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1295         {
1296           emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1297           emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1298                                                                         0)),
1299                                                        Pmode,
1300                                                        XEXP (XEXP (operand0, 0),
1301                                                                    0),
1302                                                        scratch_reg));
1303         }
1304       else
1305         emit_move_insn (scratch_reg, XEXP (operand0, 0));
1306       emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
1307                               operand1));
1308       return 1;
1309     }
1310   /* Handle secondary reloads for loads of FP registers from constant
1311      expressions by forcing the constant into memory.
1312
1313      use scratch_reg to hold the address of the memory location.
1314
1315      The proper fix is to change PREFERRED_RELOAD_CLASS to return
1316      NO_REGS when presented with a const_int and an register class
1317      containing only FP registers.  Doing so unfortunately creates
1318      more problems than it solves.   Fix this for 2.5.  */
1319   else if (fp_reg_operand (operand0, mode)
1320            && CONSTANT_P (operand1)
1321            && scratch_reg)
1322     {
1323       rtx xoperands[2];
1324
1325       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1326          it in WORD_MODE regardless of what mode it was originally given
1327          to us.  */
1328       scratch_reg = force_mode (word_mode, scratch_reg);
1329
1330       /* Force the constant into memory and put the address of the
1331          memory location into scratch_reg.  */
1332       xoperands[0] = scratch_reg;
1333       xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
1334       emit_move_sequence (xoperands, Pmode, 0);
1335
1336       /* Now load the destination register.  */
1337       emit_insn (gen_rtx_SET (mode, operand0,
1338                               gen_rtx_MEM (mode, scratch_reg)));
1339       return 1;
1340     }
1341   /* Handle secondary reloads for SAR.  These occur when trying to load
1342      the SAR from memory, FP register, or with a constant.  */
1343   else if (GET_CODE (operand0) == REG
1344            && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1345            && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1346            && (GET_CODE (operand1) == MEM
1347                || GET_CODE (operand1) == CONST_INT
1348                || (GET_CODE (operand1) == REG
1349                    && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1)))))
1350            && scratch_reg)
1351     {
1352       /* D might not fit in 14 bits either; for such cases load D into
1353          scratch reg.  */
1354       if (GET_CODE (operand1) == MEM
1355           && !memory_address_p (Pmode, XEXP (operand1, 0)))
1356         {
1357           /* We are reloading the address into the scratch register, so we
1358              want to make sure the scratch register is a full register.  */
1359           scratch_reg = force_mode (word_mode, scratch_reg);
1360
1361           emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1362           emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1363                                                                         0)),
1364                                                        Pmode,
1365                                                        XEXP (XEXP (operand1, 0),
1366                                                        0),
1367                                                        scratch_reg));
1368
1369           /* Now we are going to load the scratch register from memory,
1370              we want to load it in the same width as the original MEM,
1371              which must be the same as the width of the ultimate destination,
1372              OPERAND0.  */
1373           scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1374
1375           emit_move_insn (scratch_reg, gen_rtx_MEM (GET_MODE (operand0),
1376                                                     scratch_reg));
1377         }
1378       else
1379         {
1380           /* We want to load the scratch register using the same mode as
1381              the ultimate destination.  */
1382           scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1383
1384           emit_move_insn (scratch_reg, operand1);
1385         }
1386
1387       /* And emit the insn to set the ultimate destination.  We know that
1388          the scratch register has the same mode as the destination at this
1389          point.  */
1390       emit_move_insn (operand0, scratch_reg);
1391       return 1;
1392     }
1393   /* Handle most common case: storing into a register.  */
1394   else if (register_operand (operand0, mode))
1395     {
1396       if (register_operand (operand1, mode)
1397           || (GET_CODE (operand1) == CONST_INT && INT_14_BITS (operand1))
1398           || (operand1 == CONST0_RTX (mode))
1399           || (GET_CODE (operand1) == HIGH
1400               && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1401           /* Only `general_operands' can come here, so MEM is ok.  */
1402           || GET_CODE (operand1) == MEM)
1403         {
1404           /* Run this case quickly.  */
1405           emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1406           return 1;
1407         }
1408     }
1409   else if (GET_CODE (operand0) == MEM)
1410     {
1411       if (mode == DFmode && operand1 == CONST0_RTX (mode)
1412           && !(reload_in_progress || reload_completed))
1413         {
1414           rtx temp = gen_reg_rtx (DFmode);
1415
1416           emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1417           emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1418           return 1;
1419         }
1420       if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1421         {
1422           /* Run this case quickly.  */
1423           emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1424           return 1;
1425         }
1426       if (! (reload_in_progress || reload_completed))
1427         {
1428           operands[0] = validize_mem (operand0);
1429           operands[1] = operand1 = force_reg (mode, operand1);
1430         }
1431     }
1432
1433   /* Simplify the source if we need to.
1434      Note we do have to handle function labels here, even though we do
1435      not consider them legitimate constants.  Loop optimizations can
1436      call the emit_move_xxx with one as a source.  */
1437   if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1438       || function_label_operand (operand1, mode)
1439       || (GET_CODE (operand1) == HIGH
1440           && symbolic_operand (XEXP (operand1, 0), mode)))
1441     {
1442       int ishighonly = 0;
1443
1444       if (GET_CODE (operand1) == HIGH)
1445         {
1446           ishighonly = 1;
1447           operand1 = XEXP (operand1, 0);
1448         }
1449       if (symbolic_operand (operand1, mode))
1450         {
1451           /* Argh.  The assembler and linker can't handle arithmetic
1452              involving plabels.
1453
1454              So we force the plabel into memory, load operand0 from
1455              the memory location, then add in the constant part.  */
1456           if ((GET_CODE (operand1) == CONST
1457                && GET_CODE (XEXP (operand1, 0)) == PLUS
1458                && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
1459               || function_label_operand (operand1, mode))
1460             {
1461               rtx temp, const_part;
1462
1463               /* Figure out what (if any) scratch register to use.  */
1464               if (reload_in_progress || reload_completed)
1465                 {
1466                   scratch_reg = scratch_reg ? scratch_reg : operand0;
1467                   /* SCRATCH_REG will hold an address and maybe the actual
1468                      data.  We want it in WORD_MODE regardless of what mode it
1469                      was originally given to us.  */
1470                   scratch_reg = force_mode (word_mode, scratch_reg);
1471                 }
1472               else if (flag_pic)
1473                 scratch_reg = gen_reg_rtx (Pmode);
1474
1475               if (GET_CODE (operand1) == CONST)
1476                 {
1477                   /* Save away the constant part of the expression.  */
1478                   const_part = XEXP (XEXP (operand1, 0), 1);
1479                   if (GET_CODE (const_part) != CONST_INT)
1480                     abort ();
1481
1482                   /* Force the function label into memory.  */
1483                   temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
1484                 }
1485               else
1486                 {
1487                   /* No constant part.  */
1488                   const_part = NULL_RTX;
1489
1490                   /* Force the function label into memory.  */
1491                   temp = force_const_mem (mode, operand1);
1492                 }
1493
1494
1495               /* Get the address of the memory location.  PIC-ify it if
1496                  necessary.  */
1497               temp = XEXP (temp, 0);
1498               if (flag_pic)
1499                 temp = legitimize_pic_address (temp, mode, scratch_reg);
1500
1501               /* Put the address of the memory location into our destination
1502                  register.  */
1503               operands[1] = temp;
1504               emit_move_sequence (operands, mode, scratch_reg);
1505
1506               /* Now load from the memory location into our destination
1507                  register.  */
1508               operands[1] = gen_rtx_MEM (Pmode, operands[0]);
1509               emit_move_sequence (operands, mode, scratch_reg);
1510
1511               /* And add back in the constant part.  */
1512               if (const_part != NULL_RTX)
1513                 expand_inc (operand0, const_part);
1514
1515               return 1;
1516             }
1517
1518           if (flag_pic)
1519             {
1520               rtx temp;
1521
1522               if (reload_in_progress || reload_completed)
1523                 {
1524                   temp = scratch_reg ? scratch_reg : operand0;
1525                   /* TEMP will hold an address and maybe the actual
1526                      data.  We want it in WORD_MODE regardless of what mode it
1527                      was originally given to us.  */
1528                   temp = force_mode (word_mode, temp);
1529                 }
1530               else
1531                 temp = gen_reg_rtx (Pmode);
1532
1533               /* (const (plus (symbol) (const_int))) must be forced to
1534                  memory during/after reload if the const_int will not fit
1535                  in 14 bits.  */
1536               if (GET_CODE (operand1) == CONST
1537                        && GET_CODE (XEXP (operand1, 0)) == PLUS
1538                        && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
1539                        && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
1540                        && (reload_completed || reload_in_progress)
1541                        && flag_pic)
1542                 {
1543                   operands[1] = force_const_mem (mode, operand1);
1544                   operands[1] = legitimize_pic_address (XEXP (operands[1], 0),
1545                                                         mode, temp);
1546                   emit_move_sequence (operands, mode, temp);
1547                 }
1548               else
1549                 {
1550                   operands[1] = legitimize_pic_address (operand1, mode, temp);
1551                   emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
1552                 }
1553             }
1554           /* On the HPPA, references to data space are supposed to use dp,
1555              register 27, but showing it in the RTL inhibits various cse
1556              and loop optimizations.  */
1557           else
1558             {
1559               rtx temp, set;
1560
1561               if (reload_in_progress || reload_completed)
1562                 {
1563                   temp = scratch_reg ? scratch_reg : operand0;
1564                   /* TEMP will hold an address and maybe the actual
1565                      data.  We want it in WORD_MODE regardless of what mode it
1566                      was originally given to us.  */
1567                   temp = force_mode (word_mode, temp);
1568                 }
1569               else
1570                 temp = gen_reg_rtx (mode);
1571
1572               /* Loading a SYMBOL_REF into a register makes that register
1573                  safe to be used as the base in an indexed address.
1574
1575                  Don't mark hard registers though.  That loses.  */
1576               if (GET_CODE (operand0) == REG
1577                   && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1578                 REG_POINTER (operand0) = 1;
1579               if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
1580                 REG_POINTER (temp) = 1;
1581               if (ishighonly)
1582                 set = gen_rtx_SET (mode, operand0, temp);
1583               else
1584                 set = gen_rtx_SET (VOIDmode,
1585                                    operand0,
1586                                    gen_rtx_LO_SUM (mode, temp, operand1));
1587
1588               emit_insn (gen_rtx_SET (VOIDmode,
1589                                       temp,
1590                                       gen_rtx_HIGH (mode, operand1)));
1591               emit_insn (set);
1592
1593             }
1594           return 1;
1595         }
1596       else if (GET_CODE (operand1) != CONST_INT
1597                || ! cint_ok_for_move (INTVAL (operand1)))
1598         {
1599           rtx temp;
1600           int need_zero_extend = 0;
1601
1602           if (TARGET_64BIT && GET_CODE (operand1) == CONST_INT
1603               && HOST_BITS_PER_WIDE_INT > 32
1604               && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
1605             {
1606               HOST_WIDE_INT val = INTVAL (operand1);
1607               HOST_WIDE_INT nval;
1608
1609               /* If the value is the same after a 32->64bit sign
1610                  extension, then we can use it as-is.  Else we will
1611                  need to sign extend the constant from 32->64bits
1612                  then zero extend the result from 32->64bits.  */
1613               nval = ((val & (((HOST_WIDE_INT) 2 << 31) - 1))
1614                       ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
1615               if (val != nval)
1616                 {
1617                   need_zero_extend = 1;
1618                   operand1 = GEN_INT (nval);
1619                 }
1620             }
1621
1622           if (reload_in_progress || reload_completed)
1623             temp = operand0;
1624           else
1625             temp = gen_reg_rtx (mode);
1626
1627           emit_insn (gen_rtx_SET (VOIDmode, temp,
1628                                   gen_rtx_HIGH (mode, operand1)));
1629           operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
1630           emit_move_insn (operands[0], operands[1]);
1631
1632           if (need_zero_extend)
1633             {
1634               emit_insn (gen_zero_extendsidi2 (operands[0],
1635                                                gen_rtx_SUBREG (SImode,
1636                                                                operands[0],
1637                                                                0)));
1638             }
1639
1640           return 1;
1641         }
1642     }
1643   /* Now have insn-emit do whatever it normally does.  */
1644   return 0;
1645 }
1646
1647 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
1648    it will need a link/runtime reloc).  */
1649
1650 int
1651 reloc_needed (exp)
1652      tree exp;
1653 {
1654   int reloc = 0;
1655
1656   switch (TREE_CODE (exp))
1657     {
1658     case ADDR_EXPR:
1659       return 1;
1660
1661     case PLUS_EXPR:
1662     case MINUS_EXPR:
1663       reloc = reloc_needed (TREE_OPERAND (exp, 0));
1664       reloc |= reloc_needed (TREE_OPERAND (exp, 1));
1665       break;
1666
1667     case NOP_EXPR:
1668     case CONVERT_EXPR:
1669     case NON_LVALUE_EXPR:
1670       reloc = reloc_needed (TREE_OPERAND (exp, 0));
1671       break;
1672
1673     case CONSTRUCTOR:
1674       {
1675         register tree link;
1676         for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1677           if (TREE_VALUE (link) != 0)
1678             reloc |= reloc_needed (TREE_VALUE (link));
1679       }
1680       break;
1681
1682     case ERROR_MARK:
1683       break;
1684
1685     default:
1686       break;
1687     }
1688   return reloc;
1689 }
1690
1691 /* Does operand (which is a symbolic_operand) live in text space? If
1692    so SYMBOL_REF_FLAG, which is set by ENCODE_SECTION_INFO, will be true.  */
1693
1694 int
1695 read_only_operand (operand, mode)
1696      rtx operand;
1697      enum machine_mode mode ATTRIBUTE_UNUSED;
1698 {
1699   if (GET_CODE (operand) == CONST)
1700     operand = XEXP (XEXP (operand, 0), 0);
1701   if (flag_pic)
1702     {
1703       if (GET_CODE (operand) == SYMBOL_REF)
1704         return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
1705     }
1706   else
1707     {
1708       if (GET_CODE (operand) == SYMBOL_REF)
1709         return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
1710     }
1711   return 1;
1712 }
1713
1714 \f
1715 /* Return the best assembler insn template
1716    for moving operands[1] into operands[0] as a fullword.   */
1717 const char *
1718 singlemove_string (operands)
1719      rtx *operands;
1720 {
1721   HOST_WIDE_INT intval;
1722
1723   if (GET_CODE (operands[0]) == MEM)
1724     return "stw %r1,%0";
1725   if (GET_CODE (operands[1]) == MEM)
1726     return "ldw %1,%0";
1727   if (GET_CODE (operands[1]) == CONST_DOUBLE)
1728     {
1729       long i;
1730       REAL_VALUE_TYPE d;
1731
1732       if (GET_MODE (operands[1]) != SFmode)
1733         abort ();
1734
1735       /* Translate the CONST_DOUBLE to a CONST_INT with the same target
1736          bit pattern.  */
1737       REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
1738       REAL_VALUE_TO_TARGET_SINGLE (d, i);
1739
1740       operands[1] = GEN_INT (i);
1741       /* Fall through to CONST_INT case.  */
1742     }
1743   if (GET_CODE (operands[1]) == CONST_INT)
1744     {
1745       intval = INTVAL (operands[1]);
1746
1747       if (VAL_14_BITS_P (intval))
1748         return "ldi %1,%0";
1749       else if ((intval & 0x7ff) == 0)
1750         return "ldil L'%1,%0";
1751       else if (zdepi_cint_p (intval))
1752         return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
1753       else
1754         return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
1755     }
1756   return "copy %1,%0";
1757 }
1758 \f
1759
1760 /* Compute position (in OP[1]) and width (in OP[2])
1761    useful for copying IMM to a register using the zdepi
1762    instructions.  Store the immediate value to insert in OP[0].  */
1763 static void
1764 compute_zdepwi_operands (imm, op)
1765      unsigned HOST_WIDE_INT imm;
1766      unsigned *op;
1767 {
1768   int lsb, len;
1769
1770   /* Find the least significant set bit in IMM.  */
1771   for (lsb = 0; lsb < 32; lsb++)
1772     {
1773       if ((imm & 1) != 0)
1774         break;
1775       imm >>= 1;
1776     }
1777
1778   /* Choose variants based on *sign* of the 5-bit field.  */
1779   if ((imm & 0x10) == 0)
1780     len = (lsb <= 28) ? 4 : 32 - lsb;
1781   else
1782     {
1783       /* Find the width of the bitstring in IMM.  */
1784       for (len = 5; len < 32; len++)
1785         {
1786           if ((imm & (1 << len)) == 0)
1787             break;
1788         }
1789
1790       /* Sign extend IMM as a 5-bit value.  */
1791       imm = (imm & 0xf) - 0x10;
1792     }
1793
1794   op[0] = imm;
1795   op[1] = 31 - lsb;
1796   op[2] = len;
1797 }
1798
1799 /* Compute position (in OP[1]) and width (in OP[2])
1800    useful for copying IMM to a register using the depdi,z
1801    instructions.  Store the immediate value to insert in OP[0].  */
1802 void
1803 compute_zdepdi_operands (imm, op)
1804      unsigned HOST_WIDE_INT imm;
1805      unsigned *op;
1806 {
1807   HOST_WIDE_INT lsb, len;
1808
1809   /* Find the least significant set bit in IMM.  */
1810   for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
1811     {
1812       if ((imm & 1) != 0)
1813         break;
1814       imm >>= 1;
1815     }
1816
1817   /* Choose variants based on *sign* of the 5-bit field.  */
1818   if ((imm & 0x10) == 0)
1819     len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
1820            ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
1821   else
1822     {
1823       /* Find the width of the bitstring in IMM.  */
1824       for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
1825         {
1826           if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
1827             break;
1828         }
1829
1830       /* Sign extend IMM as a 5-bit value.  */
1831       imm = (imm & 0xf) - 0x10;
1832     }
1833
1834   op[0] = imm;
1835   op[1] = 63 - lsb;
1836   op[2] = len;
1837 }
1838
1839 /* Output assembler code to perform a doubleword move insn
1840    with operands OPERANDS.  */
1841
1842 const char *
1843 output_move_double (operands)
1844      rtx *operands;
1845 {
1846   enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
1847   rtx latehalf[2];
1848   rtx addreg0 = 0, addreg1 = 0;
1849
1850   /* First classify both operands.  */
1851
1852   if (REG_P (operands[0]))
1853     optype0 = REGOP;
1854   else if (offsettable_memref_p (operands[0]))
1855     optype0 = OFFSOP;
1856   else if (GET_CODE (operands[0]) == MEM)
1857     optype0 = MEMOP;
1858   else
1859     optype0 = RNDOP;
1860
1861   if (REG_P (operands[1]))
1862     optype1 = REGOP;
1863   else if (CONSTANT_P (operands[1]))
1864     optype1 = CNSTOP;
1865   else if (offsettable_memref_p (operands[1]))
1866     optype1 = OFFSOP;
1867   else if (GET_CODE (operands[1]) == MEM)
1868     optype1 = MEMOP;
1869   else
1870     optype1 = RNDOP;
1871
1872   /* Check for the cases that the operand constraints are not
1873      supposed to allow to happen.  Abort if we get one,
1874      because generating code for these cases is painful.  */
1875
1876   if (optype0 != REGOP && optype1 != REGOP)
1877     abort ();
1878
1879    /* Handle auto decrementing and incrementing loads and stores
1880      specifically, since the structure of the function doesn't work
1881      for them without major modification.  Do it better when we learn
1882      this port about the general inc/dec addressing of PA.
1883      (This was written by tege.  Chide him if it doesn't work.)  */
1884
1885   if (optype0 == MEMOP)
1886     {
1887       /* We have to output the address syntax ourselves, since print_operand
1888          doesn't deal with the addresses we want to use.  Fix this later.  */
1889
1890       rtx addr = XEXP (operands[0], 0);
1891       if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
1892         {
1893           rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
1894
1895           operands[0] = XEXP (addr, 0);
1896           if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
1897             abort ();
1898
1899           if (!reg_overlap_mentioned_p (high_reg, addr))
1900             {
1901               /* No overlap between high target register and address
1902                  register.  (We do this in a non-obvious way to
1903                  save a register file writeback)  */
1904               if (GET_CODE (addr) == POST_INC)
1905                 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
1906               return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
1907             }
1908           else
1909             abort ();
1910         }
1911       else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
1912         {
1913           rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
1914
1915           operands[0] = XEXP (addr, 0);
1916           if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
1917             abort ();
1918
1919           if (!reg_overlap_mentioned_p (high_reg, addr))
1920             {
1921               /* No overlap between high target register and address
1922                  register.  (We do this in a non-obvious way to
1923                  save a register file writeback)  */
1924               if (GET_CODE (addr) == PRE_INC)
1925                 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
1926               return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
1927             }
1928           else
1929             abort ();
1930         }
1931     }
1932   if (optype1 == MEMOP)
1933     {
1934       /* We have to output the address syntax ourselves, since print_operand
1935          doesn't deal with the addresses we want to use.  Fix this later.  */
1936
1937       rtx addr = XEXP (operands[1], 0);
1938       if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
1939         {
1940           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
1941
1942           operands[1] = XEXP (addr, 0);
1943           if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
1944             abort ();
1945
1946           if (!reg_overlap_mentioned_p (high_reg, addr))
1947             {
1948               /* No overlap between high target register and address
1949                  register.  (We do this in a non-obvious way to
1950                  save a register file writeback)  */
1951               if (GET_CODE (addr) == POST_INC)
1952                 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
1953               return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0}";
1954             }
1955           else
1956             {
1957               /* This is an undefined situation.  We should load into the
1958                  address register *and* update that register.  Probably
1959                  we don't need to handle this at all.  */
1960               if (GET_CODE (addr) == POST_INC)
1961                 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
1962               return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
1963             }
1964         }
1965       else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
1966         {
1967           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
1968
1969           operands[1] = XEXP (addr, 0);
1970           if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
1971             abort ();
1972
1973           if (!reg_overlap_mentioned_p (high_reg, addr))
1974             {
1975               /* No overlap between high target register and address
1976                  register.  (We do this in a non-obvious way to
1977                  save a register file writeback)  */
1978               if (GET_CODE (addr) == PRE_INC)
1979                 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
1980               return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
1981             }
1982           else
1983             {
1984               /* This is an undefined situation.  We should load into the
1985                  address register *and* update that register.  Probably
1986                  we don't need to handle this at all.  */
1987               if (GET_CODE (addr) == PRE_INC)
1988                 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
1989               return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
1990             }
1991         }
1992       else if (GET_CODE (addr) == PLUS
1993                && GET_CODE (XEXP (addr, 0)) == MULT)
1994         {
1995           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
1996
1997           if (!reg_overlap_mentioned_p (high_reg, addr))
1998             {
1999               rtx xoperands[3];
2000
2001               xoperands[0] = high_reg;
2002               xoperands[1] = XEXP (addr, 1);
2003               xoperands[2] = XEXP (XEXP (addr, 0), 0);
2004               xoperands[3] = XEXP (XEXP (addr, 0), 1);
2005               output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2006                                xoperands);
2007               return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2008             }
2009           else
2010             {
2011               rtx xoperands[3];
2012
2013               xoperands[0] = high_reg;
2014               xoperands[1] = XEXP (addr, 1);
2015               xoperands[2] = XEXP (XEXP (addr, 0), 0);
2016               xoperands[3] = XEXP (XEXP (addr, 0), 1);
2017               output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2018                                xoperands);
2019               return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2020             }
2021         }
2022     }
2023
2024   /* If an operand is an unoffsettable memory ref, find a register
2025      we can increment temporarily to make it refer to the second word.  */
2026
2027   if (optype0 == MEMOP)
2028     addreg0 = find_addr_reg (XEXP (operands[0], 0));
2029
2030   if (optype1 == MEMOP)
2031     addreg1 = find_addr_reg (XEXP (operands[1], 0));
2032
2033   /* Ok, we can do one word at a time.
2034      Normally we do the low-numbered word first.
2035
2036      In either case, set up in LATEHALF the operands to use
2037      for the high-numbered word and in some cases alter the
2038      operands in OPERANDS to be suitable for the low-numbered word.  */
2039
2040   if (optype0 == REGOP)
2041     latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2042   else if (optype0 == OFFSOP)
2043     latehalf[0] = adjust_address (operands[0], SImode, 4);
2044   else
2045     latehalf[0] = operands[0];
2046
2047   if (optype1 == REGOP)
2048     latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2049   else if (optype1 == OFFSOP)
2050     latehalf[1] = adjust_address (operands[1], SImode, 4);
2051   else if (optype1 == CNSTOP)
2052     split_double (operands[1], &operands[1], &latehalf[1]);
2053   else
2054     latehalf[1] = operands[1];
2055
2056   /* If the first move would clobber the source of the second one,
2057      do them in the other order.
2058
2059      This can happen in two cases:
2060
2061         mem -> register where the first half of the destination register
2062         is the same register used in the memory's address.  Reload
2063         can create such insns.
2064
2065         mem in this case will be either register indirect or register
2066         indirect plus a valid offset.
2067
2068         register -> register move where REGNO(dst) == REGNO(src + 1)
2069         someone (Tim/Tege?) claimed this can happen for parameter loads.
2070
2071      Handle mem -> register case first.  */
2072   if (optype0 == REGOP
2073       && (optype1 == MEMOP || optype1 == OFFSOP)
2074       && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2075                             operands[1], 0))
2076     {
2077       /* Do the late half first.  */
2078       if (addreg1)
2079         output_asm_insn ("ldo 4(%0),%0", &addreg1);
2080       output_asm_insn (singlemove_string (latehalf), latehalf);
2081
2082       /* Then clobber.  */
2083       if (addreg1)
2084         output_asm_insn ("ldo -4(%0),%0", &addreg1);
2085       return singlemove_string (operands);
2086     }
2087
2088   /* Now handle register -> register case.  */
2089   if (optype0 == REGOP && optype1 == REGOP
2090       && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2091     {
2092       output_asm_insn (singlemove_string (latehalf), latehalf);
2093       return singlemove_string (operands);
2094     }
2095
2096   /* Normal case: do the two words, low-numbered first.  */
2097
2098   output_asm_insn (singlemove_string (operands), operands);
2099
2100   /* Make any unoffsettable addresses point at high-numbered word.  */
2101   if (addreg0)
2102     output_asm_insn ("ldo 4(%0),%0", &addreg0);
2103   if (addreg1)
2104     output_asm_insn ("ldo 4(%0),%0", &addreg1);
2105
2106   /* Do that word.  */
2107   output_asm_insn (singlemove_string (latehalf), latehalf);
2108
2109   /* Undo the adds we just did.  */
2110   if (addreg0)
2111     output_asm_insn ("ldo -4(%0),%0", &addreg0);
2112   if (addreg1)
2113     output_asm_insn ("ldo -4(%0),%0", &addreg1);
2114
2115   return "";
2116 }
2117 \f
2118 const char *
2119 output_fp_move_double (operands)
2120      rtx *operands;
2121 {
2122   if (FP_REG_P (operands[0]))
2123     {
2124       if (FP_REG_P (operands[1])
2125           || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2126         output_asm_insn ("fcpy,dbl %f1,%0", operands);
2127       else
2128         output_asm_insn ("fldd%F1 %1,%0", operands);
2129     }
2130   else if (FP_REG_P (operands[1]))
2131     {
2132       output_asm_insn ("fstd%F0 %1,%0", operands);
2133     }
2134   else if (operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2135     {
2136       if (GET_CODE (operands[0]) == REG)
2137         {
2138           rtx xoperands[2];
2139           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2140           xoperands[0] = operands[0];
2141           output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2142         }
2143       /* This is a pain.  You have to be prepared to deal with an
2144          arbitrary address here including pre/post increment/decrement.
2145
2146          so avoid this in the MD.  */
2147       else
2148         abort ();
2149     }
2150   else abort ();
2151   return "";
2152 }
2153 \f
2154 /* Return a REG that occurs in ADDR with coefficient 1.
2155    ADDR can be effectively incremented by incrementing REG.  */
2156
2157 static rtx
2158 find_addr_reg (addr)
2159      rtx addr;
2160 {
2161   while (GET_CODE (addr) == PLUS)
2162     {
2163       if (GET_CODE (XEXP (addr, 0)) == REG)
2164         addr = XEXP (addr, 0);
2165       else if (GET_CODE (XEXP (addr, 1)) == REG)
2166         addr = XEXP (addr, 1);
2167       else if (CONSTANT_P (XEXP (addr, 0)))
2168         addr = XEXP (addr, 1);
2169       else if (CONSTANT_P (XEXP (addr, 1)))
2170         addr = XEXP (addr, 0);
2171       else
2172         abort ();
2173     }
2174   if (GET_CODE (addr) == REG)
2175     return addr;
2176   abort ();
2177 }
2178
2179 /* Emit code to perform a block move.
2180
2181    OPERANDS[0] is the destination pointer as a REG, clobbered.
2182    OPERANDS[1] is the source pointer as a REG, clobbered.
2183    OPERANDS[2] is a register for temporary storage.
2184    OPERANDS[4] is the size as a CONST_INT
2185    OPERANDS[3] is a register for temporary storage.
2186    OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2187    OPERANDS[6] is another temporary register.   */
2188
2189 const char *
2190 output_block_move (operands, size_is_constant)
2191      rtx *operands;
2192      int size_is_constant ATTRIBUTE_UNUSED;
2193 {
2194   int align = INTVAL (operands[5]);
2195   unsigned long n_bytes = INTVAL (operands[4]);
2196
2197   /* We can't move more than four bytes at a time because the PA
2198      has no longer integer move insns.  (Could use fp mem ops?)  */
2199   if (align > 4)
2200     align = 4;
2201
2202   /* Note that we know each loop below will execute at least twice
2203      (else we would have open-coded the copy).  */
2204   switch (align)
2205     {
2206       case 4:
2207         /* Pre-adjust the loop counter.  */
2208         operands[4] = GEN_INT (n_bytes - 8);
2209         output_asm_insn ("ldi %4,%2", operands);
2210
2211         /* Copying loop.  */
2212         output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2213         output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2214         output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2215         output_asm_insn ("addib,>= -8,%2,.-12", operands);
2216         output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2217
2218         /* Handle the residual.  There could be up to 7 bytes of
2219            residual to copy!  */
2220         if (n_bytes % 8 != 0)
2221           {
2222             operands[4] = GEN_INT (n_bytes % 4);
2223             if (n_bytes % 8 >= 4)
2224               output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2225             if (n_bytes % 4 != 0)
2226               output_asm_insn ("ldw 0(%1),%6", operands);
2227             if (n_bytes % 8 >= 4)
2228               output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2229             if (n_bytes % 4 != 0)
2230               output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2231           }
2232         return "";
2233
2234       case 2:
2235         /* Pre-adjust the loop counter.  */
2236         operands[4] = GEN_INT (n_bytes - 4);
2237         output_asm_insn ("ldi %4,%2", operands);
2238
2239         /* Copying loop.  */
2240         output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2241         output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2242         output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2243         output_asm_insn ("addib,>= -4,%2,.-12", operands);
2244         output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2245
2246         /* Handle the residual.  */
2247         if (n_bytes % 4 != 0)
2248           {
2249             if (n_bytes % 4 >= 2)
2250               output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2251             if (n_bytes % 2 != 0)
2252               output_asm_insn ("ldb 0(%1),%6", operands);
2253             if (n_bytes % 4 >= 2)
2254               output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2255             if (n_bytes % 2 != 0)
2256               output_asm_insn ("stb %6,0(%0)", operands);
2257           }
2258         return "";
2259
2260       case 1:
2261         /* Pre-adjust the loop counter.  */
2262         operands[4] = GEN_INT (n_bytes - 2);
2263         output_asm_insn ("ldi %4,%2", operands);
2264
2265         /* Copying loop.  */
2266         output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2267         output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2268         output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2269         output_asm_insn ("addib,>= -2,%2,.-12", operands);
2270         output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2271
2272         /* Handle the residual.  */
2273         if (n_bytes % 2 != 0)
2274           {
2275             output_asm_insn ("ldb 0(%1),%3", operands);
2276             output_asm_insn ("stb %3,0(%0)", operands);
2277           }
2278         return "";
2279
2280       default:
2281         abort ();
2282     }
2283 }
2284
2285 /* Count the number of insns necessary to handle this block move.
2286
2287    Basic structure is the same as emit_block_move, except that we
2288    count insns rather than emit them.  */
2289
2290 static int
2291 compute_movstrsi_length (insn)
2292      rtx insn;
2293 {
2294   rtx pat = PATTERN (insn);
2295   unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2296   unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 5), 0));
2297   unsigned int n_insns = 0;
2298
2299   /* We can't move more than four bytes at a time because the PA
2300      has no longer integer move insns.  (Could use fp mem ops?)  */
2301   if (align > 4)
2302     align = 4;
2303
2304   /* The basic copying loop.  */
2305   n_insns = 6;
2306
2307   /* Residuals.  */
2308   if (n_bytes % (2 * align) != 0)
2309     {
2310       if ((n_bytes % (2 * align)) >= align)
2311         n_insns += 2;
2312
2313       if ((n_bytes % align) != 0)
2314         n_insns += 2;
2315     }
2316
2317   /* Lengths are expressed in bytes now; each insn is 4 bytes.  */
2318   return n_insns * 4;
2319 }
2320 \f
2321
2322 const char *
2323 output_and (operands)
2324      rtx *operands;
2325 {
2326   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2327     {
2328       unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2329       int ls0, ls1, ms0, p, len;
2330
2331       for (ls0 = 0; ls0 < 32; ls0++)
2332         if ((mask & (1 << ls0)) == 0)
2333           break;
2334
2335       for (ls1 = ls0; ls1 < 32; ls1++)
2336         if ((mask & (1 << ls1)) != 0)
2337           break;
2338
2339       for (ms0 = ls1; ms0 < 32; ms0++)
2340         if ((mask & (1 << ms0)) == 0)
2341           break;
2342
2343       if (ms0 != 32)
2344         abort ();
2345
2346       if (ls1 == 32)
2347         {
2348           len = ls0;
2349
2350           if (len == 0)
2351             abort ();
2352
2353           operands[2] = GEN_INT (len);
2354           return "{extru|extrw,u} %1,31,%2,%0";
2355         }
2356       else
2357         {
2358           /* We could use this `depi' for the case above as well, but `depi'
2359              requires one more register file access than an `extru'.  */
2360
2361           p = 31 - ls0;
2362           len = ls1 - ls0;
2363
2364           operands[2] = GEN_INT (p);
2365           operands[3] = GEN_INT (len);
2366           return "{depi|depwi} 0,%2,%3,%0";
2367         }
2368     }
2369   else
2370     return "and %1,%2,%0";
2371 }
2372
2373 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2374    storing the result in operands[0].  */
2375 const char *
2376 output_64bit_and (operands)
2377      rtx *operands;
2378 {
2379   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2380     {
2381       unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2382       int ls0, ls1, ms0, p, len;
2383
2384       for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
2385         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
2386           break;
2387
2388       for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
2389         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
2390           break;
2391
2392       for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
2393         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
2394           break;
2395
2396       if (ms0 != HOST_BITS_PER_WIDE_INT)
2397         abort ();
2398
2399       if (ls1 == HOST_BITS_PER_WIDE_INT)
2400         {
2401           len = ls0;
2402
2403           if (len == 0)
2404             abort ();
2405
2406           operands[2] = GEN_INT (len);
2407           return "extrd,u %1,63,%2,%0";
2408         }
2409       else
2410         {
2411           /* We could use this `depi' for the case above as well, but `depi'
2412              requires one more register file access than an `extru'.  */
2413
2414           p = 63 - ls0;
2415           len = ls1 - ls0;
2416
2417           operands[2] = GEN_INT (p);
2418           operands[3] = GEN_INT (len);
2419           return "depdi 0,%2,%3,%0";
2420         }
2421     }
2422   else
2423     return "and %1,%2,%0";
2424 }
2425
2426 const char *
2427 output_ior (operands)
2428      rtx *operands;
2429 {
2430   unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2431   int bs0, bs1, p, len;
2432
2433   if (INTVAL (operands[2]) == 0)
2434     return "copy %1,%0";
2435
2436   for (bs0 = 0; bs0 < 32; bs0++)
2437     if ((mask & (1 << bs0)) != 0)
2438       break;
2439
2440   for (bs1 = bs0; bs1 < 32; bs1++)
2441     if ((mask & (1 << bs1)) == 0)
2442       break;
2443
2444   if (bs1 != 32 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
2445     abort ();
2446
2447   p = 31 - bs0;
2448   len = bs1 - bs0;
2449
2450   operands[2] = GEN_INT (p);
2451   operands[3] = GEN_INT (len);
2452   return "{depi|depwi} -1,%2,%3,%0";
2453 }
2454
2455 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2456    storing the result in operands[0].  */
2457 const char *
2458 output_64bit_ior (operands)
2459      rtx *operands;
2460 {
2461   unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2462   int bs0, bs1, p, len;
2463
2464   if (INTVAL (operands[2]) == 0)
2465     return "copy %1,%0";
2466
2467   for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
2468     if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
2469       break;
2470
2471   for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
2472     if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
2473       break;
2474
2475   if (bs1 != HOST_BITS_PER_WIDE_INT
2476       && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
2477     abort ();
2478
2479   p = 63 - bs0;
2480   len = bs1 - bs0;
2481
2482   operands[2] = GEN_INT (p);
2483   operands[3] = GEN_INT (len);
2484   return "depdi -1,%2,%3,%0";
2485 }
2486 \f
2487 /* Output an ascii string.  */
2488 void
2489 output_ascii (file, p, size)
2490      FILE *file;
2491      const unsigned char *p;
2492      int size;
2493 {
2494   int i;
2495   int chars_output;
2496   unsigned char partial_output[16];     /* Max space 4 chars can occupy.   */
2497
2498   /* The HP assembler can only take strings of 256 characters at one
2499      time.  This is a limitation on input line length, *not* the
2500      length of the string.  Sigh.  Even worse, it seems that the
2501      restriction is in number of input characters (see \xnn &
2502      \whatever).  So we have to do this very carefully.  */
2503
2504   fputs ("\t.STRING \"", file);
2505
2506   chars_output = 0;
2507   for (i = 0; i < size; i += 4)
2508     {
2509       int co = 0;
2510       int io = 0;
2511       for (io = 0, co = 0; io < MIN (4, size - i); io++)
2512         {
2513           register unsigned int c = p[i + io];
2514
2515           if (c == '\"' || c == '\\')
2516             partial_output[co++] = '\\';
2517           if (c >= ' ' && c < 0177)
2518             partial_output[co++] = c;
2519           else
2520             {
2521               unsigned int hexd;
2522               partial_output[co++] = '\\';
2523               partial_output[co++] = 'x';
2524               hexd =  c  / 16 - 0 + '0';
2525               if (hexd > '9')
2526                 hexd -= '9' - 'a' + 1;
2527               partial_output[co++] = hexd;
2528               hexd =  c % 16 - 0 + '0';
2529               if (hexd > '9')
2530                 hexd -= '9' - 'a' + 1;
2531               partial_output[co++] = hexd;
2532             }
2533         }
2534       if (chars_output + co > 243)
2535         {
2536           fputs ("\"\n\t.STRING \"", file);
2537           chars_output = 0;
2538         }
2539       fwrite (partial_output, 1, co, file);
2540       chars_output += co;
2541       co = 0;
2542     }
2543   fputs ("\"\n", file);
2544 }
2545
2546 /* Try to rewrite floating point comparisons & branches to avoid
2547    useless add,tr insns.
2548
2549    CHECK_NOTES is nonzero if we should examine REG_DEAD notes
2550    to see if FPCC is dead.  CHECK_NOTES is nonzero for the
2551    first attempt to remove useless add,tr insns.  It is zero
2552    for the second pass as reorg sometimes leaves bogus REG_DEAD
2553    notes lying around.
2554
2555    When CHECK_NOTES is zero we can only eliminate add,tr insns
2556    when there's a 1:1 correspondence between fcmp and ftest/fbranch
2557    instructions.  */
2558 static void
2559 remove_useless_addtr_insns (insns, check_notes)
2560      rtx insns;
2561      int check_notes;
2562 {
2563   rtx insn;
2564   static int pass = 0;
2565
2566   /* This is fairly cheap, so always run it when optimizing.  */
2567   if (optimize > 0)
2568     {
2569       int fcmp_count = 0;
2570       int fbranch_count = 0;
2571
2572       /* Walk all the insns in this function looking for fcmp & fbranch
2573          instructions.  Keep track of how many of each we find.  */
2574       insns = get_insns ();
2575       for (insn = insns; insn; insn = next_insn (insn))
2576         {
2577           rtx tmp;
2578
2579           /* Ignore anything that isn't an INSN or a JUMP_INSN.  */
2580           if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
2581             continue;
2582
2583           tmp = PATTERN (insn);
2584
2585           /* It must be a set.  */
2586           if (GET_CODE (tmp) != SET)
2587             continue;
2588
2589           /* If the destination is CCFP, then we've found an fcmp insn.  */
2590           tmp = SET_DEST (tmp);
2591           if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
2592             {
2593               fcmp_count++;
2594               continue;
2595             }
2596
2597           tmp = PATTERN (insn);
2598           /* If this is an fbranch instruction, bump the fbranch counter.  */
2599           if (GET_CODE (tmp) == SET
2600               && SET_DEST (tmp) == pc_rtx
2601               && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
2602               && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
2603               && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
2604               && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
2605             {
2606               fbranch_count++;
2607               continue;
2608             }
2609         }
2610
2611
2612       /* Find all floating point compare + branch insns.  If possible,
2613          reverse the comparison & the branch to avoid add,tr insns.  */
2614       for (insn = insns; insn; insn = next_insn (insn))
2615         {
2616           rtx tmp, next;
2617
2618           /* Ignore anything that isn't an INSN.  */
2619           if (GET_CODE (insn) != INSN)
2620             continue;
2621
2622           tmp = PATTERN (insn);
2623
2624           /* It must be a set.  */
2625           if (GET_CODE (tmp) != SET)
2626             continue;
2627
2628           /* The destination must be CCFP, which is register zero.  */
2629           tmp = SET_DEST (tmp);
2630           if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
2631             continue;
2632
2633           /* INSN should be a set of CCFP.
2634
2635              See if the result of this insn is used in a reversed FP
2636              conditional branch.  If so, reverse our condition and
2637              the branch.  Doing so avoids useless add,tr insns.  */
2638           next = next_insn (insn);
2639           while (next)
2640             {
2641               /* Jumps, calls and labels stop our search.  */
2642               if (GET_CODE (next) == JUMP_INSN
2643                   || GET_CODE (next) == CALL_INSN
2644                   || GET_CODE (next) == CODE_LABEL)
2645                 break;
2646
2647               /* As does another fcmp insn.  */
2648               if (GET_CODE (next) == INSN
2649                   && GET_CODE (PATTERN (next)) == SET
2650                   && GET_CODE (SET_DEST (PATTERN (next))) == REG
2651                   && REGNO (SET_DEST (PATTERN (next))) == 0)
2652                 break;
2653
2654               next = next_insn (next);
2655             }
2656
2657           /* Is NEXT_INSN a branch?  */
2658           if (next
2659               && GET_CODE (next) == JUMP_INSN)
2660             {
2661               rtx pattern = PATTERN (next);
2662
2663               /* If it a reversed fp conditional branch (eg uses add,tr)
2664                  and CCFP dies, then reverse our conditional and the branch
2665                  to avoid the add,tr.  */
2666               if (GET_CODE (pattern) == SET
2667                   && SET_DEST (pattern) == pc_rtx
2668                   && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
2669                   && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
2670                   && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
2671                   && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
2672                   && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
2673                   && (fcmp_count == fbranch_count
2674                       || (check_notes
2675                           && find_regno_note (next, REG_DEAD, 0))))
2676                 {
2677                   /* Reverse the branch.  */
2678                   tmp = XEXP (SET_SRC (pattern), 1);
2679                   XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
2680                   XEXP (SET_SRC (pattern), 2) = tmp;
2681                   INSN_CODE (next) = -1;
2682
2683                   /* Reverse our condition.  */
2684                   tmp = PATTERN (insn);
2685                   PUT_CODE (XEXP (tmp, 1),
2686                             (reverse_condition_maybe_unordered
2687                              (GET_CODE (XEXP (tmp, 1)))));
2688                 }
2689             }
2690         }
2691     }
2692
2693   pass = !pass;
2694
2695 }
2696 \f
2697 /* You may have trouble believing this, but this is the 32 bit HP-PA
2698    stack layout.  Wow.
2699
2700    Offset               Contents
2701
2702    Variable arguments   (optional; any number may be allocated)
2703
2704    SP-(4*(N+9))         arg word N
2705         :                   :
2706       SP-56             arg word 5
2707       SP-52             arg word 4
2708
2709    Fixed arguments      (must be allocated; may remain unused)
2710
2711       SP-48             arg word 3
2712       SP-44             arg word 2
2713       SP-40             arg word 1
2714       SP-36             arg word 0
2715
2716    Frame Marker
2717
2718       SP-32             External Data Pointer (DP)
2719       SP-28             External sr4
2720       SP-24             External/stub RP (RP')
2721       SP-20             Current RP
2722       SP-16             Static Link
2723       SP-12             Clean up
2724       SP-8              Calling Stub RP (RP'')
2725       SP-4              Previous SP
2726
2727    Top of Frame
2728
2729       SP-0              Stack Pointer (points to next available address)
2730
2731 */
2732
2733 /* This function saves registers as follows.  Registers marked with ' are
2734    this function's registers (as opposed to the previous function's).
2735    If a frame_pointer isn't needed, r4 is saved as a general register;
2736    the space for the frame pointer is still allocated, though, to keep
2737    things simple.
2738
2739
2740    Top of Frame
2741
2742        SP (FP')         Previous FP
2743        SP + 4           Alignment filler (sigh)
2744        SP + 8           Space for locals reserved here.
2745        .
2746        .
2747        .
2748        SP + n           All call saved register used.
2749        .
2750        .
2751        .
2752        SP + o           All call saved fp registers used.
2753        .
2754        .
2755        .
2756        SP + p (SP')     points to next available address.
2757
2758 */
2759
2760 /* Global variables set by output_function_prologue().  */
2761 /* Size of frame.  Need to know this to emit return insns from
2762    leaf procedures.  */
2763 static int actual_fsize;
2764 static int local_fsize, save_fregs;
2765
2766 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
2767    Handle case where DISP > 8k by using the add_high_const patterns.
2768
2769    Note in DISP > 8k case, we will leave the high part of the address
2770    in %r1.  There is code in expand_hppa_{prologue,epilogue} that knows this.*/
2771
2772 static rtx
2773 store_reg (reg, disp, base)
2774      int reg, disp, base;
2775 {
2776   rtx i, dest, src, basereg;
2777
2778   src = gen_rtx_REG (word_mode, reg);
2779   basereg = gen_rtx_REG (Pmode, base);
2780   if (VAL_14_BITS_P (disp))
2781     {
2782       dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
2783       i = emit_move_insn (dest, src);
2784     }
2785   else
2786     {
2787       rtx delta = GEN_INT (disp);
2788       rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
2789       rtx tmpreg = gen_rtx_REG (Pmode, 1);
2790       emit_move_insn (tmpreg, high);
2791       dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
2792       i = emit_move_insn (dest, src);
2793     }
2794   return i;
2795 }
2796
2797 /* Emit RTL to set REG to the value specified by BASE+DISP.
2798    Handle case where DISP > 8k by using the add_high_const patterns.
2799
2800    Note in DISP > 8k case, we will leave the high part of the address
2801    in %r1.  There is code in expand_hppa_{prologue,epilogue} that knows this.*/
2802
2803 static rtx
2804 set_reg_plus_d (reg, base, disp)
2805      int reg, base, disp;
2806 {
2807   rtx i;
2808
2809   if (VAL_14_BITS_P (disp))
2810     {
2811       i = emit_move_insn (gen_rtx_REG (Pmode, reg),
2812                           plus_constant (gen_rtx_REG (Pmode, base), disp));
2813     }
2814   else
2815     {
2816       rtx delta = GEN_INT (disp);
2817       emit_move_insn (gen_rtx_REG (Pmode, 1),
2818                       gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, base),
2819                                     gen_rtx_HIGH (Pmode, delta)));
2820       i = emit_move_insn (gen_rtx_REG (Pmode, reg),
2821                           gen_rtx_LO_SUM (Pmode, gen_rtx_REG (Pmode, 1),
2822                                           delta));
2823     }
2824   return i;
2825 }
2826
2827 int
2828 compute_frame_size (size, fregs_live)
2829      int size;
2830      int *fregs_live;
2831 {
2832   int i, fsize;
2833
2834   /* Space for frame pointer + filler. If any frame is allocated
2835      we need to add this in because of STARTING_FRAME_OFFSET.
2836
2837      Similar code also appears in hppa_expand_prologue.  Change both
2838      of them at the same time.  */
2839   fsize = size + (size || frame_pointer_needed ? STARTING_FRAME_OFFSET : 0);
2840
2841   /* Account for space used by the callee general register saves.  */
2842   for (i = 18; i >= 3; i--)
2843     if (regs_ever_live[i])
2844       fsize += UNITS_PER_WORD;
2845
2846   /* Round the stack.  */
2847   fsize = (fsize + 7) & ~7;
2848
2849   /* Account for space used by the callee floating point register saves.  */
2850   for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
2851     if (regs_ever_live[i]
2852         || (! TARGET_64BIT && regs_ever_live[i + 1]))
2853       {
2854         if (fregs_live)
2855           *fregs_live = 1;
2856
2857         /* We always save both halves of the FP register, so always
2858            increment the frame size by 8 bytes.  */
2859         fsize += 8;
2860       }
2861
2862   /* The various ABIs include space for the outgoing parameters in the
2863      size of the current function's stack frame.  */
2864   fsize += current_function_outgoing_args_size;
2865
2866   /* Allocate space for the fixed frame marker.  This space must be
2867      allocated for any function that makes calls or otherwise allocates
2868      stack space.  */
2869   if (!current_function_is_leaf || fsize)
2870     fsize += TARGET_64BIT ? 16 : 32;
2871
2872   return (fsize + STACK_BOUNDARY - 1) & ~(STACK_BOUNDARY - 1);
2873 }
2874
2875 /* Generate the assembly code for function entry.  FILE is a stdio
2876    stream to output the code to.  SIZE is an int: how many units of
2877    temporary storage to allocate.
2878
2879    Refer to the array `regs_ever_live' to determine which registers to
2880    save; `regs_ever_live[I]' is nonzero if register number I is ever
2881    used in the function.  This function is responsible for knowing
2882    which registers should not be saved even if used.  */
2883
2884 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
2885    of memory.  If any fpu reg is used in the function, we allocate
2886    such a block here, at the bottom of the frame, just in case it's needed.
2887
2888    If this function is a leaf procedure, then we may choose not
2889    to do a "save" insn.  The decision about whether or not
2890    to do this is made in regclass.c.  */
2891
2892 void
2893 pa_output_function_prologue (file, size)
2894      FILE *file;
2895      HOST_WIDE_INT size ATTRIBUTE_UNUSED;
2896 {
2897   /* The function's label and associated .PROC must never be
2898      separated and must be output *after* any profiling declarations
2899      to avoid changing spaces/subspaces within a procedure.  */
2900   ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
2901   fputs ("\t.PROC\n", file);
2902
2903   /* hppa_expand_prologue does the dirty work now.  We just need
2904      to output the assembler directives which denote the start
2905      of a function.  */
2906   fprintf (file, "\t.CALLINFO FRAME=%d", actual_fsize);
2907   if (regs_ever_live[2])
2908     fputs (",CALLS,SAVE_RP", file);
2909   else
2910     fputs (",NO_CALLS", file);
2911
2912   if (frame_pointer_needed)
2913     fputs (",SAVE_SP", file);
2914
2915   /* Pass on information about the number of callee register saves
2916      performed in the prologue.
2917
2918      The compiler is supposed to pass the highest register number
2919      saved, the assembler then has to adjust that number before
2920      entering it into the unwind descriptor (to account for any
2921      caller saved registers with lower register numbers than the
2922      first callee saved register).  */
2923   if (gr_saved)
2924     fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
2925
2926   if (fr_saved)
2927     fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
2928
2929   fputs ("\n\t.ENTRY\n", file);
2930
2931   /* If we're using GAS and not using the portable runtime model, then
2932      we don't need to accumulate the total number of code bytes.  */
2933   if (TARGET_GAS && ! TARGET_PORTABLE_RUNTIME)
2934     total_code_bytes = 0;
2935   else if (INSN_ADDRESSES_SET_P ())
2936     {
2937       unsigned int old_total = total_code_bytes;
2938
2939       total_code_bytes += INSN_ADDRESSES (INSN_UID (get_last_insn ()));
2940       total_code_bytes += FUNCTION_BOUNDARY / BITS_PER_UNIT;
2941
2942       /* Be prepared to handle overflows.  */
2943       if (old_total > total_code_bytes)
2944         total_code_bytes = -1;
2945     }
2946   else
2947     total_code_bytes = -1;
2948
2949   remove_useless_addtr_insns (get_insns (), 0);
2950 }
2951
2952 #if DO_FRAME_NOTES
2953 #define FRP(INSN) \
2954   do                                    \
2955     {                                   \
2956       rtx insn = INSN;                  \
2957       RTX_FRAME_RELATED_P (insn) = 1;   \
2958     }                                   \
2959   while (0)
2960 #else
2961 #define FRP(INSN) INSN
2962 #endif
2963
2964 void
2965 hppa_expand_prologue ()
2966 {
2967   extern char call_used_regs[];
2968   int size = get_frame_size ();
2969   int merge_sp_adjust_with_store = 0;
2970   int i, offset;
2971   rtx tmpreg, size_rtx;
2972
2973   gr_saved = 0;
2974   fr_saved = 0;
2975   save_fregs = 0;
2976
2977   /* Allocate space for frame pointer + filler. If any frame is allocated
2978      we need to add this in because of STARTING_FRAME_OFFSET.
2979
2980      Similar code also appears in compute_frame_size.  Change both
2981      of them at the same time.  */
2982   local_fsize = size + (size || frame_pointer_needed
2983                         ? STARTING_FRAME_OFFSET : 0);
2984
2985   actual_fsize = compute_frame_size (size, &save_fregs);
2986
2987   /* Compute a few things we will use often.  */
2988   tmpreg = gen_rtx_REG (word_mode, 1);
2989   size_rtx = GEN_INT (actual_fsize);
2990
2991   /* Save RP first.  The calling conventions manual states RP will
2992      always be stored into the caller's frame at sp - 20 or sp - 16
2993      depending on which ABI is in use.  */
2994   if (regs_ever_live[2])
2995     FRP (store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM));
2996
2997   /* Allocate the local frame and set up the frame pointer if needed.  */
2998   if (actual_fsize != 0)
2999     {
3000       if (frame_pointer_needed)
3001         {
3002           /* Copy the old frame pointer temporarily into %r1.  Set up the
3003              new stack pointer, then store away the saved old frame pointer
3004              into the stack at sp+actual_fsize and at the same time update
3005              the stack pointer by actual_fsize bytes.  Two versions, first
3006              handles small (<8k) frames.  The second handles large (>=8k)
3007              frames.  */
3008           emit_move_insn (tmpreg, frame_pointer_rtx);
3009           FRP (emit_move_insn (frame_pointer_rtx, stack_pointer_rtx));
3010           if (VAL_14_BITS_P (actual_fsize))
3011             {
3012               rtx insn = emit_insn (gen_post_store (stack_pointer_rtx, tmpreg,
3013                                                     size_rtx));
3014               if (DO_FRAME_NOTES)
3015                 {
3016                   rtvec vec;
3017                   RTX_FRAME_RELATED_P (insn) = 1;
3018                   vec = gen_rtvec (2,
3019                                    gen_rtx_SET (VOIDmode,
3020                                                 gen_rtx_MEM (word_mode,
3021                                                              stack_pointer_rtx),
3022                                                 frame_pointer_rtx),
3023                                    gen_rtx_SET (VOIDmode,
3024                                                 stack_pointer_rtx,
3025                                                 gen_rtx_PLUS (word_mode,
3026                                                               stack_pointer_rtx,
3027                                                               size_rtx)));
3028                   REG_NOTES (insn)
3029                     = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3030                                          gen_rtx_SEQUENCE (VOIDmode, vec),
3031                                          REG_NOTES (insn));
3032                 }
3033             }
3034           else
3035             {
3036               /* It is incorrect to store the saved frame pointer at *sp,
3037                  then increment sp (writes beyond the current stack boundary).
3038
3039                  So instead use stwm to store at *sp and post-increment the
3040                  stack pointer as an atomic operation.  Then increment sp to
3041                  finish allocating the new frame.  */
3042               int adjust1 = 8192 - 64;
3043               int adjust2 = actual_fsize - adjust1;
3044               rtx delta = GEN_INT (adjust1);
3045               rtx insn = emit_insn (gen_post_store (stack_pointer_rtx, tmpreg,
3046                                                     delta));
3047               if (DO_FRAME_NOTES)
3048                 {
3049                   rtvec vec;
3050                   RTX_FRAME_RELATED_P (insn) = 1;
3051                   vec = gen_rtvec (2,
3052                                    gen_rtx_SET (VOIDmode,
3053                                                 gen_rtx_MEM (word_mode,
3054                                                              stack_pointer_rtx),
3055                                                 frame_pointer_rtx),
3056                                    gen_rtx_SET (VOIDmode,
3057                                                 stack_pointer_rtx,
3058                                                 gen_rtx_PLUS (word_mode,
3059                                                               stack_pointer_rtx,
3060                                                               delta)));
3061                   REG_NOTES (insn)
3062                     = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3063                                          gen_rtx_SEQUENCE (VOIDmode, vec),
3064                                          REG_NOTES (insn));
3065                 }
3066
3067               FRP (set_reg_plus_d (STACK_POINTER_REGNUM,
3068                                    STACK_POINTER_REGNUM,
3069                                    adjust2));
3070             }
3071           /* Prevent register spills from being scheduled before the
3072              stack pointer is raised.  Necessary as we will be storing
3073              registers using the frame pointer as a base register, and
3074              we happen to set fp before raising sp.  */
3075           emit_insn (gen_blockage ());
3076         }
3077       /* no frame pointer needed.  */
3078       else
3079         {
3080           /* In some cases we can perform the first callee register save
3081              and allocating the stack frame at the same time.   If so, just
3082              make a note of it and defer allocating the frame until saving
3083              the callee registers.  */
3084           if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
3085             merge_sp_adjust_with_store = 1;
3086           /* Can not optimize.  Adjust the stack frame by actual_fsize
3087              bytes.  */
3088           else
3089             FRP (set_reg_plus_d (STACK_POINTER_REGNUM,
3090                                  STACK_POINTER_REGNUM,
3091                                  actual_fsize));
3092         }
3093     }
3094
3095   /* Normal register save.
3096
3097      Do not save the frame pointer in the frame_pointer_needed case.  It
3098      was done earlier.  */
3099   if (frame_pointer_needed)
3100     {
3101       for (i = 18, offset = local_fsize; i >= 4; i--)
3102         if (regs_ever_live[i] && ! call_used_regs[i])
3103           {
3104             FRP (store_reg (i, offset, FRAME_POINTER_REGNUM));
3105             offset += UNITS_PER_WORD;
3106             gr_saved++;
3107           }
3108       /* Account for %r3 which is saved in a special place.  */
3109       gr_saved++;
3110     }
3111   /* No frame pointer needed.  */
3112   else
3113     {
3114       for (i = 18, offset = local_fsize - actual_fsize; i >= 3; i--)
3115         if (regs_ever_live[i] && ! call_used_regs[i])
3116           {
3117             /* If merge_sp_adjust_with_store is nonzero, then we can
3118                optimize the first GR save.  */
3119             if (merge_sp_adjust_with_store)
3120               {
3121                 rtx delta = GEN_INT (-offset);
3122                 merge_sp_adjust_with_store = 0;
3123                 FRP (emit_insn (gen_post_store (stack_pointer_rtx,
3124                                                 gen_rtx_REG (word_mode, i),
3125                                                 delta)));
3126               }
3127             else
3128               FRP (store_reg (i, offset, STACK_POINTER_REGNUM));
3129             offset += UNITS_PER_WORD;
3130             gr_saved++;
3131           }
3132
3133       /* If we wanted to merge the SP adjustment with a GR save, but we never
3134          did any GR saves, then just emit the adjustment here.  */
3135       if (merge_sp_adjust_with_store)
3136         FRP (set_reg_plus_d (STACK_POINTER_REGNUM,
3137                              STACK_POINTER_REGNUM,
3138                              actual_fsize));
3139     }
3140
3141   /* The hppa calling conventions say that %r19, the pic offset
3142      register, is saved at sp - 32 (in this function's frame)
3143      when generating PIC code.  FIXME:  What is the correct thing
3144      to do for functions which make no calls and allocate no
3145      frame?  Do we need to allocate a frame, or can we just omit
3146      the save?   For now we'll just omit the save.  */
3147   if (flag_pic && actual_fsize != 0 && !TARGET_64BIT)
3148     store_reg (PIC_OFFSET_TABLE_REGNUM, -32, STACK_POINTER_REGNUM);
3149
3150   /* Align pointer properly (doubleword boundary).  */
3151   offset = (offset + 7) & ~7;
3152
3153   /* Floating point register store.  */
3154   if (save_fregs)
3155     {
3156       /* First get the frame or stack pointer to the start of the FP register
3157          save area.  */
3158       if (frame_pointer_needed)
3159         FRP (set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset));
3160       else
3161         FRP (set_reg_plus_d (1, STACK_POINTER_REGNUM, offset));
3162
3163       /* Now actually save the FP registers.  */
3164       for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3165         {
3166           if (regs_ever_live[i]
3167               || (! TARGET_64BIT && regs_ever_live[i + 1]))
3168             {
3169               rtx addr, reg;
3170               addr = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
3171               reg = gen_rtx_REG (DFmode, i);
3172               FRP (emit_move_insn (addr, reg));
3173               fr_saved++;
3174             }
3175         }
3176     }
3177 }
3178
3179 /* ?!? Do we want frame notes in the epilogue yet?  */
3180 #undef DO_FRAME_NOTES
3181 #define DO_FRAME_NOTES 0
3182 #undef FRP
3183 #define FRP(INSN) INSN
3184
3185 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
3186    Handle case where DISP > 8k by using the add_high_const patterns.  */
3187
3188 static rtx
3189 load_reg (reg, disp, base)
3190      int reg, disp, base;
3191 {
3192   rtx i, src, dest, basereg;
3193
3194   dest = gen_rtx_REG (word_mode, reg);
3195   basereg = gen_rtx_REG (Pmode, base);
3196   if (VAL_14_BITS_P (disp))
3197     {
3198       src = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3199       i = emit_move_insn (dest, src);
3200     }
3201   else
3202     {
3203       rtx delta = GEN_INT (disp);
3204       rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3205       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3206       emit_move_insn (tmpreg, high);
3207       src = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3208       i = emit_move_insn (dest, src);
3209     }
3210   return i;
3211 }
3212
3213 /* This function generates the assembly code for function exit.
3214    Args are as for output_function_prologue ().
3215
3216    The function epilogue should not depend on the current stack
3217    pointer!  It should use the frame pointer only.  This is mandatory
3218    because of alloca; we also take advantage of it to omit stack
3219    adjustments before returning. */
3220
3221 static void
3222 pa_output_function_epilogue (file, size)
3223      FILE *file;
3224      HOST_WIDE_INT size ATTRIBUTE_UNUSED;
3225 {
3226   rtx insn = get_last_insn ();
3227
3228   /* hppa_expand_epilogue does the dirty work now.  We just need
3229      to output the assembler directives which denote the end
3230      of a function.
3231
3232      To make debuggers happy, emit a nop if the epilogue was completely
3233      eliminated due to a volatile call as the last insn in the
3234      current function.  That way the return address (in %r2) will
3235      always point to a valid instruction in the current function.  */
3236
3237   /* Get the last real insn.  */
3238   if (GET_CODE (insn) == NOTE)
3239     insn = prev_real_insn (insn);
3240
3241   /* If it is a sequence, then look inside.  */
3242   if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
3243     insn = XVECEXP (PATTERN (insn), 0, 0);
3244
3245   /* If insn is a CALL_INSN, then it must be a call to a volatile
3246      function (otherwise there would be epilogue insns).  */
3247   if (insn && GET_CODE (insn) == CALL_INSN)
3248     fputs ("\tnop\n", file);
3249
3250   fputs ("\t.EXIT\n\t.PROCEND\n", file);
3251 }
3252
3253 void
3254 hppa_expand_epilogue ()
3255 {
3256   rtx tmpreg;
3257   int offset, i;
3258   int merge_sp_adjust_with_load = 0;
3259   int ret_off = 0;
3260
3261   /* We will use this often.  */
3262   tmpreg = gen_rtx_REG (word_mode, 1);
3263
3264   /* Try to restore RP early to avoid load/use interlocks when
3265      RP gets used in the return (bv) instruction.  This appears to still
3266      be necessary even when we schedule the prologue and epilogue. */
3267   if (regs_ever_live [2])
3268     {
3269       ret_off = TARGET_64BIT ? -16 : -20;
3270       if (frame_pointer_needed)
3271         {
3272           FRP (load_reg (2, ret_off, FRAME_POINTER_REGNUM));
3273           ret_off = 0;
3274         }
3275       else
3276         {
3277           /* No frame pointer, and stack is smaller than 8k.  */
3278           if (VAL_14_BITS_P (ret_off - actual_fsize))
3279             {
3280               FRP (load_reg (2, ret_off - actual_fsize, STACK_POINTER_REGNUM));
3281               ret_off = 0;
3282             }
3283         }
3284     }
3285
3286   /* General register restores.  */
3287   if (frame_pointer_needed)
3288     {
3289       for (i = 18, offset = local_fsize; i >= 4; i--)
3290         if (regs_ever_live[i] && ! call_used_regs[i])
3291           {
3292             FRP (load_reg (i, offset, FRAME_POINTER_REGNUM));
3293             offset += UNITS_PER_WORD;
3294           }
3295     }
3296   else
3297     {
3298       for (i = 18, offset = local_fsize - actual_fsize; i >= 3; i--)
3299         {
3300           if (regs_ever_live[i] && ! call_used_regs[i])
3301             {
3302               /* Only for the first load.
3303                  merge_sp_adjust_with_load holds the register load
3304                  with which we will merge the sp adjustment.  */
3305               if (merge_sp_adjust_with_load == 0
3306                   && local_fsize == 0
3307                   && VAL_14_BITS_P (-actual_fsize))
3308                 merge_sp_adjust_with_load = i;
3309               else
3310                 FRP (load_reg (i, offset, STACK_POINTER_REGNUM));
3311               offset += UNITS_PER_WORD;
3312             }
3313         }
3314     }
3315
3316   /* Align pointer properly (doubleword boundary).  */
3317   offset = (offset + 7) & ~7;
3318
3319   /* FP register restores.  */
3320   if (save_fregs)
3321     {
3322       /* Adjust the register to index off of.  */
3323       if (frame_pointer_needed)
3324         FRP (set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset));
3325       else
3326         FRP (set_reg_plus_d (1, STACK_POINTER_REGNUM, offset));
3327
3328       /* Actually do the restores now.  */
3329       for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3330         if (regs_ever_live[i]
3331             || (! TARGET_64BIT && regs_ever_live[i + 1]))
3332           {
3333             rtx src = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
3334             rtx dest = gen_rtx_REG (DFmode, i);
3335             FRP (emit_move_insn (dest, src));
3336           }
3337     }
3338
3339   /* Emit a blockage insn here to keep these insns from being moved to
3340      an earlier spot in the epilogue, or into the main instruction stream.
3341
3342      This is necessary as we must not cut the stack back before all the
3343      restores are finished.  */
3344   emit_insn (gen_blockage ());
3345
3346   /* Reset stack pointer (and possibly frame pointer).  The stack
3347      pointer is initially set to fp + 64 to avoid a race condition.  */
3348   if (frame_pointer_needed)
3349     {
3350       rtx delta = GEN_INT (-64);
3351       FRP (set_reg_plus_d (STACK_POINTER_REGNUM, FRAME_POINTER_REGNUM, 64));
3352       FRP (emit_insn (gen_pre_load (frame_pointer_rtx,
3353                                     stack_pointer_rtx,
3354                                     delta)));
3355     }
3356   /* If we were deferring a callee register restore, do it now.  */
3357   else if (merge_sp_adjust_with_load)
3358     {
3359       rtx delta = GEN_INT (-actual_fsize);
3360       rtx dest = gen_rtx_REG (word_mode, merge_sp_adjust_with_load);
3361       FRP (emit_insn (gen_pre_load (dest, stack_pointer_rtx, delta)));
3362     }
3363   else if (actual_fsize != 0)
3364     FRP (set_reg_plus_d (STACK_POINTER_REGNUM,
3365                          STACK_POINTER_REGNUM,
3366                          - actual_fsize));
3367
3368   /* If we haven't restored %r2 yet (no frame pointer, and a stack
3369      frame greater than 8k), do so now.  */
3370   if (ret_off != 0)
3371     FRP (load_reg (2, ret_off, STACK_POINTER_REGNUM));
3372 }
3373
3374 rtx
3375 hppa_pic_save_rtx ()
3376 {
3377   return get_hard_reg_initial_val (word_mode, PIC_OFFSET_TABLE_REGNUM);
3378 }
3379
3380 void
3381 hppa_profile_hook (label_no)
3382      int label_no ATTRIBUTE_UNUSED;
3383 {
3384   rtx call_insn;
3385
3386   /* No profiling for inline functions.  We don't want extra calls to
3387      _mcount when the inline function is expanded.  Even if that made
3388      sense, it wouldn't work here as there is no function label for
3389      the inline expansion.  */
3390   if (DECL_INLINE (cfun->decl))
3391     return;
3392
3393   if (TARGET_64BIT)
3394     emit_move_insn (arg_pointer_rtx,
3395                     gen_rtx_PLUS (word_mode, virtual_outgoing_args_rtx,
3396                                   GEN_INT (64)));
3397
3398   emit_move_insn (gen_rtx_REG (word_mode, 26), gen_rtx_REG (word_mode, 2));
3399
3400 #ifndef NO_PROFILE_COUNTERS
3401   {
3402     rtx count_label_rtx, addr, r24;
3403     char label_name[16];
3404
3405     ASM_GENERATE_INTERNAL_LABEL (label_name, "LP", label_no);
3406     count_label_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label_name));
3407
3408     if (flag_pic)
3409       {
3410         rtx tmpreg;
3411
3412         current_function_uses_pic_offset_table = 1;
3413         tmpreg = gen_rtx_REG (Pmode, 1);
3414         emit_move_insn (tmpreg,
3415                         gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3416                                       gen_rtx_HIGH (Pmode, count_label_rtx)));
3417         addr = gen_rtx_MEM (Pmode,
3418                             gen_rtx_LO_SUM (Pmode, tmpreg, count_label_rtx));
3419       }
3420     else
3421       {
3422         rtx tmpreg = gen_rtx_REG (Pmode, 1);
3423         emit_move_insn (tmpreg, gen_rtx_HIGH (Pmode, count_label_rtx));
3424         addr = gen_rtx_LO_SUM (Pmode, tmpreg, count_label_rtx);
3425       }
3426     r24 = gen_rtx_REG (Pmode, 24);
3427     emit_move_insn (r24, addr);
3428
3429     /* %r25 is set from within the output pattern.  */
3430     call_insn =
3431       emit_call_insn (gen_call_profiler (gen_rtx_SYMBOL_REF (Pmode, "_mcount"),
3432                                          GEN_INT (TARGET_64BIT ? 24 : 12),
3433                                          XEXP (DECL_RTL (cfun->decl), 0)));
3434
3435     use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), r24);
3436   }
3437 #else
3438     /* %r25 is set from within the output pattern.  */
3439   call_insn =
3440     emit_call_insn (gen_call_profiler (gen_rtx_SYMBOL_REF (Pmode, "_mcount"),
3441                                        GEN_INT (TARGET_64BIT ? 16 : 8),
3442                                        XEXP (DECL_RTL (cfun->decl), 0)));
3443 #endif
3444
3445   /* Indicate the _mcount call cannot throw, nor will it execute a
3446      non-local goto.  */
3447   REG_NOTES (call_insn)
3448     = gen_rtx_EXPR_LIST (REG_EH_REGION, constm1_rtx, REG_NOTES (call_insn));
3449
3450   if (flag_pic)
3451     {
3452       use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), pic_offset_table_rtx);
3453       if (TARGET_64BIT)
3454         use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), arg_pointer_rtx);
3455
3456       emit_move_insn (pic_offset_table_rtx, hppa_pic_save_rtx ());
3457     }
3458 }
3459
3460 /* Fetch the return address for the frame COUNT steps up from
3461    the current frame, after the prologue.  FRAMEADDR is the
3462    frame pointer of the COUNT frame.
3463
3464    We want to ignore any export stub remnants here.
3465
3466    The value returned is used in two different ways:
3467
3468         1. To find a function's caller.
3469
3470         2. To change the return address for a function.
3471
3472    This function handles most instances of case 1; however, it will
3473    fail if there are two levels of stubs to execute on the return
3474    path.  The only way I believe that can happen is if the return value
3475    needs a parameter relocation, which never happens for C code.
3476
3477    This function handles most instances of case 2; however, it will
3478    fail if we did not originally have stub code on the return path
3479    but will need code on the new return path.  This can happen if
3480    the caller & callee are both in the main program, but the new
3481    return location is in a shared library.
3482
3483    To handle this correctly we need to set the return pointer at
3484    frame-20 to point to a return stub frame-24 to point to the
3485    location we wish to return to.  */
3486
3487 rtx
3488 return_addr_rtx (count, frameaddr)
3489      int count ATTRIBUTE_UNUSED;
3490      rtx frameaddr;
3491 {
3492   rtx label;
3493   rtx saved_rp;
3494   rtx ins;
3495
3496   if (TARGET_64BIT)
3497     return gen_rtx_MEM (Pmode, plus_constant (frameaddr, -16));
3498
3499   if (TARGET_NO_SPACE_REGS)
3500     return gen_rtx_MEM (Pmode, plus_constant (frameaddr, -20));
3501
3502   /* First, we start off with the normal return address pointer from
3503      -20[frameaddr].  */
3504
3505   saved_rp = gen_reg_rtx (Pmode);
3506   emit_move_insn (saved_rp, plus_constant (frameaddr, -20));
3507
3508   /* Get pointer to the instruction stream.  We have to mask out the
3509      privilege level from the two low order bits of the return address
3510      pointer here so that ins will point to the start of the first
3511      instruction that would have been executed if we returned.  */
3512   ins = copy_to_reg (gen_rtx_AND (Pmode,
3513                                   copy_to_reg (gen_rtx_MEM (Pmode, saved_rp)),
3514                                   MASK_RETURN_ADDR));
3515   label = gen_label_rtx ();
3516
3517   /* Check the instruction stream at the normal return address for the
3518      export stub:
3519
3520         0x4bc23fd1 | stub+8:   ldw -18(sr0,sp),rp
3521         0x004010a1 | stub+12:  ldsid (sr0,rp),r1
3522         0x00011820 | stub+16:  mtsp r1,sr0
3523         0xe0400002 | stub+20:  be,n 0(sr0,rp)
3524
3525      If it is an export stub, than our return address is really in
3526      -24[frameaddr].  */
3527
3528   emit_cmp_insn (gen_rtx_MEM (SImode, ins),
3529                  GEN_INT (0x4bc23fd1),
3530                  NE, NULL_RTX, SImode, 1, 0);
3531   emit_jump_insn (gen_bne (label));
3532
3533   emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 4)),
3534                  GEN_INT (0x004010a1),
3535                  NE, NULL_RTX, SImode, 1, 0);
3536   emit_jump_insn (gen_bne (label));
3537
3538   emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 8)),
3539                  GEN_INT (0x00011820),
3540                  NE, NULL_RTX, SImode, 1, 0);
3541   emit_jump_insn (gen_bne (label));
3542
3543   emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 12)),
3544                  GEN_INT (0xe0400002),
3545                  NE, NULL_RTX, SImode, 1, 0);
3546
3547   /* If there is no export stub then just use our initial guess of
3548      -20[frameaddr].  */
3549
3550   emit_jump_insn (gen_bne (label));
3551
3552   /* Here we know that our return address pointer points to an export
3553      stub.  We don't want to return the address of the export stub,
3554      but rather the return address that leads back into user code.
3555      That return address is stored at -24[frameaddr].  */
3556
3557   emit_move_insn (saved_rp, plus_constant (frameaddr, -24));
3558
3559   emit_label (label);
3560   return gen_rtx_MEM (Pmode, memory_address (Pmode, saved_rp));
3561 }
3562
3563 /* This is only valid once reload has completed because it depends on
3564    knowing exactly how much (if any) frame there is and...
3565
3566    It's only valid if there is no frame marker to de-allocate and...
3567
3568    It's only valid if %r2 hasn't been saved into the caller's frame
3569    (we're not profiling and %r2 isn't live anywhere).  */
3570 int
3571 hppa_can_use_return_insn_p ()
3572 {
3573   return (reload_completed
3574           && (compute_frame_size (get_frame_size (), 0) ? 0 : 1)
3575           && ! regs_ever_live[2]
3576           && ! frame_pointer_needed);
3577 }
3578
3579 void
3580 emit_bcond_fp (code, operand0)
3581      enum rtx_code code;
3582      rtx operand0;
3583 {
3584   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3585                                gen_rtx_IF_THEN_ELSE (VOIDmode,
3586                                                      gen_rtx_fmt_ee (code,
3587                                                               VOIDmode,
3588                                                               gen_rtx_REG (CCFPmode, 0),
3589                                                               const0_rtx),
3590                                                      gen_rtx_LABEL_REF (VOIDmode, operand0),
3591                                                      pc_rtx)));
3592
3593 }
3594
3595 rtx
3596 gen_cmp_fp (code, operand0, operand1)
3597      enum rtx_code code;
3598      rtx operand0, operand1;
3599 {
3600   return gen_rtx_SET (VOIDmode, gen_rtx_REG (CCFPmode, 0),
3601                       gen_rtx_fmt_ee (code, CCFPmode, operand0, operand1));
3602 }
3603
3604 /* Adjust the cost of a scheduling dependency.  Return the new cost of
3605    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
3606
3607 static int
3608 pa_adjust_cost (insn, link, dep_insn, cost)
3609      rtx insn;
3610      rtx link;
3611      rtx dep_insn;
3612      int cost;
3613 {
3614   enum attr_type attr_type;
3615
3616   /* Don't adjust costs for a pa8000 chip.  */
3617   if (pa_cpu >= PROCESSOR_8000)
3618     return cost;
3619
3620   if (! recog_memoized (insn))
3621     return 0;
3622
3623   attr_type = get_attr_type (insn);
3624
3625   if (REG_NOTE_KIND (link) == 0)
3626     {
3627       /* Data dependency; DEP_INSN writes a register that INSN reads some
3628          cycles later.  */
3629
3630       if (attr_type == TYPE_FPSTORE)
3631         {
3632           rtx pat = PATTERN (insn);
3633           rtx dep_pat = PATTERN (dep_insn);
3634           if (GET_CODE (pat) == PARALLEL)
3635             {
3636               /* This happens for the fstXs,mb patterns.  */
3637               pat = XVECEXP (pat, 0, 0);
3638             }
3639           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
3640             /* If this happens, we have to extend this to schedule
3641                optimally.  Return 0 for now.  */
3642           return 0;
3643
3644           if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
3645             {
3646               if (! recog_memoized (dep_insn))
3647                 return 0;
3648               /* DEP_INSN is writing its result to the register
3649                  being stored in the fpstore INSN.  */
3650               switch (get_attr_type (dep_insn))
3651                 {
3652                 case TYPE_FPLOAD:
3653                   /* This cost 3 cycles, not 2 as the md says for the
3654                      700 and 7100.  */
3655                   return cost + 1;
3656
3657                 case TYPE_FPALU:
3658                 case TYPE_FPMULSGL:
3659                 case TYPE_FPMULDBL:
3660                 case TYPE_FPDIVSGL:
3661                 case TYPE_FPDIVDBL:
3662                 case TYPE_FPSQRTSGL:
3663                 case TYPE_FPSQRTDBL:
3664                   /* In these important cases, we save one cycle compared to
3665                      when flop instruction feed each other.  */
3666                   return cost - 1;
3667
3668                 default:
3669                   return cost;
3670                 }
3671             }
3672         }
3673
3674       /* For other data dependencies, the default cost specified in the
3675          md is correct.  */
3676       return cost;
3677     }
3678   else if (REG_NOTE_KIND (link) == REG_DEP_ANTI)
3679     {
3680       /* Anti dependency; DEP_INSN reads a register that INSN writes some
3681          cycles later.  */
3682
3683       if (attr_type == TYPE_FPLOAD)
3684         {
3685           rtx pat = PATTERN (insn);
3686           rtx dep_pat = PATTERN (dep_insn);
3687           if (GET_CODE (pat) == PARALLEL)
3688             {
3689               /* This happens for the fldXs,mb patterns.  */
3690               pat = XVECEXP (pat, 0, 0);
3691             }
3692           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
3693             /* If this happens, we have to extend this to schedule
3694                optimally.  Return 0 for now.  */
3695           return 0;
3696
3697           if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
3698             {
3699               if (! recog_memoized (dep_insn))
3700                 return 0;
3701               switch (get_attr_type (dep_insn))
3702                 {
3703                 case TYPE_FPALU:
3704                 case TYPE_FPMULSGL:
3705                 case TYPE_FPMULDBL:
3706                 case TYPE_FPDIVSGL:
3707                 case TYPE_FPDIVDBL:
3708                 case TYPE_FPSQRTSGL:
3709                 case TYPE_FPSQRTDBL:
3710                   /* A fpload can't be issued until one cycle before a
3711                      preceding arithmetic operation has finished if
3712                      the target of the fpload is any of the sources
3713                      (or destination) of the arithmetic operation.  */
3714                   return cost - 1;
3715
3716                 default:
3717                   return 0;
3718                 }
3719             }
3720         }
3721       else if (attr_type == TYPE_FPALU)
3722         {
3723           rtx pat = PATTERN (insn);
3724           rtx dep_pat = PATTERN (dep_insn);
3725           if (GET_CODE (pat) == PARALLEL)
3726             {
3727               /* This happens for the fldXs,mb patterns.  */
3728               pat = XVECEXP (pat, 0, 0);
3729             }
3730           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
3731             /* If this happens, we have to extend this to schedule
3732                optimally.  Return 0 for now.  */
3733           return 0;
3734
3735           if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
3736             {
3737               if (! recog_memoized (dep_insn))
3738                 return 0;
3739               switch (get_attr_type (dep_insn))
3740                 {
3741                 case TYPE_FPDIVSGL:
3742                 case TYPE_FPDIVDBL:
3743                 case TYPE_FPSQRTSGL:
3744                 case TYPE_FPSQRTDBL:
3745                   /* An ALU flop can't be issued until two cycles before a
3746                      preceding divide or sqrt operation has finished if
3747                      the target of the ALU flop is any of the sources
3748                      (or destination) of the divide or sqrt operation.  */
3749                   return cost - 2;
3750
3751                 default:
3752                   return 0;
3753                 }
3754             }
3755         }
3756
3757       /* For other anti dependencies, the cost is 0.  */
3758       return 0;
3759     }
3760   else if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT)
3761     {
3762       /* Output dependency; DEP_INSN writes a register that INSN writes some
3763          cycles later.  */
3764       if (attr_type == TYPE_FPLOAD)
3765         {
3766           rtx pat = PATTERN (insn);
3767           rtx dep_pat = PATTERN (dep_insn);
3768           if (GET_CODE (pat) == PARALLEL)
3769             {
3770               /* This happens for the fldXs,mb patterns.  */
3771               pat = XVECEXP (pat, 0, 0);
3772             }
3773           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
3774             /* If this happens, we have to extend this to schedule
3775                optimally.  Return 0 for now.  */
3776           return 0;
3777
3778           if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
3779             {
3780               if (! recog_memoized (dep_insn))
3781                 return 0;
3782               switch (get_attr_type (dep_insn))
3783                 {
3784                 case TYPE_FPALU:
3785                 case TYPE_FPMULSGL:
3786                 case TYPE_FPMULDBL:
3787                 case TYPE_FPDIVSGL:
3788                 case TYPE_FPDIVDBL:
3789                 case TYPE_FPSQRTSGL:
3790                 case TYPE_FPSQRTDBL:
3791                   /* A fpload can't be issued until one cycle before a
3792                      preceding arithmetic operation has finished if
3793                      the target of the fpload is the destination of the
3794                      arithmetic operation.  */
3795                   return cost - 1;
3796
3797                 default:
3798                   return 0;
3799                 }
3800             }
3801         }
3802       else if (attr_type == TYPE_FPALU)
3803         {
3804           rtx pat = PATTERN (insn);
3805           rtx dep_pat = PATTERN (dep_insn);
3806           if (GET_CODE (pat) == PARALLEL)
3807             {
3808               /* This happens for the fldXs,mb patterns.  */
3809               pat = XVECEXP (pat, 0, 0);
3810             }
3811           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
3812             /* If this happens, we have to extend this to schedule
3813                optimally.  Return 0 for now.  */
3814           return 0;
3815
3816           if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
3817             {
3818               if (! recog_memoized (dep_insn))
3819                 return 0;
3820               switch (get_attr_type (dep_insn))
3821                 {
3822                 case TYPE_FPDIVSGL:
3823                 case TYPE_FPDIVDBL:
3824                 case TYPE_FPSQRTSGL:
3825                 case TYPE_FPSQRTDBL:
3826                   /* An ALU flop can't be issued until two cycles before a
3827                      preceding divide or sqrt operation has finished if
3828                      the target of the ALU flop is also the target of
3829                      the divide or sqrt operation.  */
3830                   return cost - 2;
3831
3832                 default:
3833                   return 0;
3834                 }
3835             }
3836         }
3837
3838       /* For other output dependencies, the cost is 0.  */
3839       return 0;
3840     }
3841   else
3842     abort ();
3843 }
3844
3845 /* Adjust scheduling priorities.  We use this to try and keep addil
3846    and the next use of %r1 close together.  */
3847 static int
3848 pa_adjust_priority (insn, priority)
3849      rtx insn;
3850      int priority;
3851 {
3852   rtx set = single_set (insn);
3853   rtx src, dest;
3854   if (set)
3855     {
3856       src = SET_SRC (set);
3857       dest = SET_DEST (set);
3858       if (GET_CODE (src) == LO_SUM
3859           && symbolic_operand (XEXP (src, 1), VOIDmode)
3860           && ! read_only_operand (XEXP (src, 1), VOIDmode))
3861         priority >>= 3;
3862
3863       else if (GET_CODE (src) == MEM
3864                && GET_CODE (XEXP (src, 0)) == LO_SUM
3865                && symbolic_operand (XEXP (XEXP (src, 0), 1), VOIDmode)
3866                && ! read_only_operand (XEXP (XEXP (src, 0), 1), VOIDmode))
3867         priority >>= 1;
3868
3869       else if (GET_CODE (dest) == MEM
3870                && GET_CODE (XEXP (dest, 0)) == LO_SUM
3871                && symbolic_operand (XEXP (XEXP (dest, 0), 1), VOIDmode)
3872                && ! read_only_operand (XEXP (XEXP (dest, 0), 1), VOIDmode))
3873         priority >>= 3;
3874     }
3875   return priority;
3876 }
3877
3878 /* The 700 can only issue a single insn at a time.
3879    The 7XXX processors can issue two insns at a time.
3880    The 8000 can issue 4 insns at a time.  */
3881 static int
3882 pa_issue_rate ()
3883 {
3884   switch (pa_cpu)
3885     {
3886     case PROCESSOR_700:         return 1;
3887     case PROCESSOR_7100:        return 2;
3888     case PROCESSOR_7100LC:      return 2;
3889     case PROCESSOR_7200:        return 2;
3890     case PROCESSOR_8000:        return 4;
3891
3892     default:
3893       abort ();
3894     }
3895 }
3896
3897
3898
3899 /* Return any length adjustment needed by INSN which already has its length
3900    computed as LENGTH.   Return zero if no adjustment is necessary.
3901
3902    For the PA: function calls, millicode calls, and backwards short
3903    conditional branches with unfilled delay slots need an adjustment by +1
3904    (to account for the NOP which will be inserted into the instruction stream).
3905
3906    Also compute the length of an inline block move here as it is too
3907    complicated to express as a length attribute in pa.md.  */
3908 int
3909 pa_adjust_insn_length (insn, length)
3910     rtx insn;
3911     int length;
3912 {
3913   rtx pat = PATTERN (insn);
3914
3915   /* Call insns which are *not* indirect and have unfilled delay slots.  */
3916   if (GET_CODE (insn) == CALL_INSN)
3917     {
3918
3919       if (GET_CODE (XVECEXP (pat, 0, 0)) == CALL
3920           && GET_CODE (XEXP (XEXP (XVECEXP (pat, 0, 0), 0), 0)) == SYMBOL_REF)
3921         return 4;
3922       else if (GET_CODE (XVECEXP (pat, 0, 0)) == SET
3923                && GET_CODE (XEXP (XEXP (XEXP (XVECEXP (pat, 0, 0), 1), 0), 0))
3924                   == SYMBOL_REF)
3925         return 4;
3926       else
3927         return 0;
3928     }
3929   /* Jumps inside switch tables which have unfilled delay slots
3930      also need adjustment.  */
3931   else if (GET_CODE (insn) == JUMP_INSN
3932            && simplejump_p (insn)
3933            && GET_MODE (insn) == SImode)
3934     return 4;
3935   /* Millicode insn with an unfilled delay slot.  */
3936   else if (GET_CODE (insn) == INSN
3937            && GET_CODE (pat) != SEQUENCE
3938            && GET_CODE (pat) != USE
3939            && GET_CODE (pat) != CLOBBER
3940            && get_attr_type (insn) == TYPE_MILLI)
3941     return 4;
3942   /* Block move pattern.  */
3943   else if (GET_CODE (insn) == INSN
3944            && GET_CODE (pat) == PARALLEL
3945            && GET_CODE (XVECEXP (pat, 0, 0)) == SET
3946            && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
3947            && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 1)) == MEM
3948            && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode
3949            && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 1)) == BLKmode)
3950     return compute_movstrsi_length (insn) - 4;
3951   /* Conditional branch with an unfilled delay slot.  */
3952   else if (GET_CODE (insn) == JUMP_INSN && ! simplejump_p (insn))
3953     {
3954       /* Adjust a short backwards conditional with an unfilled delay slot.  */
3955       if (GET_CODE (pat) == SET
3956           && length == 4
3957           && ! forward_branch_p (insn))
3958         return 4;
3959       else if (GET_CODE (pat) == PARALLEL
3960                && get_attr_type (insn) == TYPE_PARALLEL_BRANCH
3961                && length == 4)
3962         return 4;
3963       /* Adjust dbra insn with short backwards conditional branch with
3964          unfilled delay slot -- only for case where counter is in a
3965          general register register. */
3966       else if (GET_CODE (pat) == PARALLEL
3967                && GET_CODE (XVECEXP (pat, 0, 1)) == SET
3968                && GET_CODE (XEXP (XVECEXP (pat, 0, 1), 0)) == REG
3969                && ! FP_REG_P (XEXP (XVECEXP (pat, 0, 1), 0))
3970                && length == 4
3971                && ! forward_branch_p (insn))
3972         return 4;
3973       else
3974         return 0;
3975     }
3976   return 0;
3977 }
3978
3979 /* Print operand X (an rtx) in assembler syntax to file FILE.
3980    CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
3981    For `%' followed by punctuation, CODE is the punctuation and X is null.  */
3982
3983 void
3984 print_operand (file, x, code)
3985      FILE *file;
3986      rtx x;
3987      int code;
3988 {
3989   switch (code)
3990     {
3991     case '#':
3992       /* Output a 'nop' if there's nothing for the delay slot.  */
3993       if (dbr_sequence_length () == 0)
3994         fputs ("\n\tnop", file);
3995       return;
3996     case '*':
3997       /* Output an nullification completer if there's nothing for the */
3998       /* delay slot or nullification is requested.  */
3999       if (dbr_sequence_length () == 0 ||
4000           (final_sequence &&
4001            INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
4002         fputs (",n", file);
4003       return;
4004     case 'R':
4005       /* Print out the second register name of a register pair.
4006          I.e., R (6) => 7.  */
4007       fputs (reg_names[REGNO (x) + 1], file);
4008       return;
4009     case 'r':
4010       /* A register or zero. */
4011       if (x == const0_rtx
4012           || (x == CONST0_RTX (DFmode))
4013           || (x == CONST0_RTX (SFmode)))
4014         {
4015           fputs ("%r0", file);
4016           return;
4017         }
4018       else
4019         break;
4020     case 'f':
4021       /* A register or zero (floating point). */
4022       if (x == const0_rtx
4023           || (x == CONST0_RTX (DFmode))
4024           || (x == CONST0_RTX (SFmode)))
4025         {
4026           fputs ("%fr0", file);
4027           return;
4028         }
4029       else
4030         break;
4031     case 'A':
4032       {
4033         rtx xoperands[2];
4034
4035         xoperands[0] = XEXP (XEXP (x, 0), 0);
4036         xoperands[1] = XVECEXP (XEXP (XEXP (x, 0), 1), 0, 0);
4037         output_global_address (file, xoperands[1], 0);
4038         fprintf (file, "(%s)", reg_names [REGNO (xoperands[0])]);
4039         return;
4040       }
4041
4042     case 'C':                   /* Plain (C)ondition */
4043     case 'X':
4044       switch (GET_CODE (x))
4045         {
4046         case EQ:
4047           fputs ("=", file);  break;
4048         case NE:
4049           fputs ("<>", file);  break;
4050         case GT:
4051           fputs (">", file);  break;
4052         case GE:
4053           fputs (">=", file);  break;
4054         case GEU:
4055           fputs (">>=", file);  break;
4056         case GTU:
4057           fputs (">>", file);  break;
4058         case LT:
4059           fputs ("<", file);  break;
4060         case LE:
4061           fputs ("<=", file);  break;
4062         case LEU:
4063           fputs ("<<=", file);  break;
4064         case LTU:
4065           fputs ("<<", file);  break;
4066         default:
4067           abort ();
4068         }
4069       return;
4070     case 'N':                   /* Condition, (N)egated */
4071       switch (GET_CODE (x))
4072         {
4073         case EQ:
4074           fputs ("<>", file);  break;
4075         case NE:
4076           fputs ("=", file);  break;
4077         case GT:
4078           fputs ("<=", file);  break;
4079         case GE:
4080           fputs ("<", file);  break;
4081         case GEU:
4082           fputs ("<<", file);  break;
4083         case GTU:
4084           fputs ("<<=", file);  break;
4085         case LT:
4086           fputs (">=", file);  break;
4087         case LE:
4088           fputs (">", file);  break;
4089         case LEU:
4090           fputs (">>", file);  break;
4091         case LTU:
4092           fputs (">>=", file);  break;
4093         default:
4094           abort ();
4095         }
4096       return;
4097     /* For floating point comparisons.  Note that the output
4098        predicates are the complement of the desired mode.  */
4099     case 'Y':
4100       switch (GET_CODE (x))
4101         {
4102         case EQ:
4103           fputs ("!=", file);  break;
4104         case NE:
4105           fputs ("=", file);  break;
4106         case GT:
4107           fputs ("!>", file);  break;
4108         case GE:
4109           fputs ("!>=", file);  break;
4110         case LT:
4111           fputs ("!<", file);  break;
4112         case LE:
4113           fputs ("!<=", file);  break;
4114         case LTGT:
4115           fputs ("!<>", file);  break;
4116         case UNLE:
4117           fputs (">", file);  break;
4118         case UNLT:
4119           fputs (">=", file);  break;
4120         case UNGE:
4121           fputs ("<", file);  break;
4122         case UNGT:
4123           fputs ("<=", file);  break;
4124         case UNEQ:
4125           fputs ("<>", file);  break;
4126         case UNORDERED:
4127           fputs ("<=>", file);  break;
4128         case ORDERED:
4129           fputs ("!<=>", file);  break;
4130         default:
4131           abort ();
4132         }
4133       return;
4134     case 'S':                   /* Condition, operands are (S)wapped.  */
4135       switch (GET_CODE (x))
4136         {
4137         case EQ:
4138           fputs ("=", file);  break;
4139         case NE:
4140           fputs ("<>", file);  break;
4141         case GT:
4142           fputs ("<", file);  break;
4143         case GE:
4144           fputs ("<=", file);  break;
4145         case GEU:
4146           fputs ("<<=", file);  break;
4147         case GTU:
4148           fputs ("<<", file);  break;
4149         case LT:
4150           fputs (">", file);  break;
4151         case LE:
4152           fputs (">=", file);  break;
4153         case LEU:
4154           fputs (">>=", file);  break;
4155         case LTU:
4156           fputs (">>", file);  break;
4157         default:
4158           abort ();
4159         }
4160       return;
4161     case 'B':                   /* Condition, (B)oth swapped and negate.  */
4162       switch (GET_CODE (x))
4163         {
4164         case EQ:
4165           fputs ("<>", file);  break;
4166         case NE:
4167           fputs ("=", file);  break;
4168         case GT:
4169           fputs (">=", file);  break;
4170         case GE:
4171           fputs (">", file);  break;
4172         case GEU:
4173           fputs (">>", file);  break;
4174         case GTU:
4175           fputs (">>=", file);  break;
4176         case LT:
4177           fputs ("<=", file);  break;
4178         case LE:
4179           fputs ("<", file);  break;
4180         case LEU:
4181           fputs ("<<", file);  break;
4182         case LTU:
4183           fputs ("<<=", file);  break;
4184         default:
4185           abort ();
4186         }
4187       return;
4188     case 'k':
4189       if (GET_CODE (x) == CONST_INT)
4190         {
4191           fprintf (file, "%d", ~INTVAL (x));
4192           return;
4193         }
4194       abort ();
4195     case 'Q':
4196       if (GET_CODE (x) == CONST_INT)
4197         {
4198           fprintf (file, "%d", 64 - (INTVAL (x) & 63));
4199           return;
4200         }
4201       abort ();
4202     case 'L':
4203       if (GET_CODE (x) == CONST_INT)
4204         {
4205           fprintf (file, "%d", 32 - (INTVAL (x) & 31));
4206           return;
4207         }
4208       abort ();
4209     case 'O':
4210       if (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0)
4211         {
4212           fprintf (file, "%d", exact_log2 (INTVAL (x)));
4213           return;
4214         }
4215       abort ();
4216     case 'p':
4217       if (GET_CODE (x) == CONST_INT)
4218         {
4219           fprintf (file, "%d", 63 - (INTVAL (x) & 63));
4220           return;
4221         }
4222       abort ();
4223     case 'P':
4224       if (GET_CODE (x) == CONST_INT)
4225         {
4226           fprintf (file, "%d", 31 - (INTVAL (x) & 31));
4227           return;
4228         }
4229       abort ();
4230     case 'I':
4231       if (GET_CODE (x) == CONST_INT)
4232         fputs ("i", file);
4233       return;
4234     case 'M':
4235     case 'F':
4236       switch (GET_CODE (XEXP (x, 0)))
4237         {
4238         case PRE_DEC:
4239         case PRE_INC:
4240           if (ASSEMBLER_DIALECT == 0)
4241             fputs ("s,mb", file);
4242           else
4243             fputs (",mb", file);
4244           break;
4245         case POST_DEC:
4246         case POST_INC:
4247           if (ASSEMBLER_DIALECT == 0)
4248             fputs ("s,ma", file);
4249           else
4250             fputs (",ma", file);
4251           break;
4252         case PLUS:
4253           if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
4254               || GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
4255             {
4256               if (ASSEMBLER_DIALECT == 0)
4257                 fputs ("x,s", file);
4258               else
4259                 fputs (",s", file);
4260             }
4261           else if (code == 'F' && ASSEMBLER_DIALECT == 0)
4262             fputs ("s", file);
4263           break;
4264         default:
4265           if (code == 'F' && ASSEMBLER_DIALECT == 0)
4266             fputs ("s", file);
4267           break;
4268         }
4269       return;
4270     case 'G':
4271       output_global_address (file, x, 0);
4272       return;
4273     case 'H':
4274       output_global_address (file, x, 1);
4275       return;
4276     case 0:                     /* Don't do anything special */
4277       break;
4278     case 'Z':
4279       {
4280         unsigned op[3];
4281         compute_zdepwi_operands (INTVAL (x), op);
4282         fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
4283         return;
4284       }
4285     case 'z':
4286       {
4287         unsigned op[3];
4288         compute_zdepdi_operands (INTVAL (x), op);
4289         fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
4290         return;
4291       }
4292     case 'c':
4293       /* We can get here from a .vtable_inherit due to our
4294          CONSTANT_ADDRESS_P rejecting perfectly good constant
4295          addresses.  */
4296       break;
4297     default:
4298       abort ();
4299     }
4300   if (GET_CODE (x) == REG)
4301     {
4302       fputs (reg_names [REGNO (x)], file);
4303       if (TARGET_64BIT && FP_REG_P (x) && GET_MODE_SIZE (GET_MODE (x)) <= 4)
4304         {
4305           fputs ("R", file);
4306           return;
4307         }
4308       if (FP_REG_P (x)
4309           && GET_MODE_SIZE (GET_MODE (x)) <= 4
4310           && (REGNO (x) & 1) == 0)
4311         fputs ("L", file);
4312     }
4313   else if (GET_CODE (x) == MEM)
4314     {
4315       int size = GET_MODE_SIZE (GET_MODE (x));
4316       rtx base = NULL_RTX;
4317       switch (GET_CODE (XEXP (x, 0)))
4318         {
4319         case PRE_DEC:
4320         case POST_DEC:
4321           base = XEXP (XEXP (x, 0), 0);
4322           fprintf (file, "-%d(%s)", size, reg_names [REGNO (base)]);
4323           break;
4324         case PRE_INC:
4325         case POST_INC:
4326           base = XEXP (XEXP (x, 0), 0);
4327           fprintf (file, "%d(%s)", size, reg_names [REGNO (base)]);
4328           break;
4329         default:
4330           if (GET_CODE (XEXP (x, 0)) == PLUS
4331               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
4332             fprintf (file, "%s(%s)",
4333                      reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 0), 0))],
4334                      reg_names [REGNO (XEXP (XEXP (x, 0), 1))]);
4335           else if (GET_CODE (XEXP (x, 0)) == PLUS
4336                    && GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
4337             fprintf (file, "%s(%s)",
4338                      reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 1), 0))],
4339                      reg_names [REGNO (XEXP (XEXP (x, 0), 0))]);
4340           else
4341             output_address (XEXP (x, 0));
4342           break;
4343         }
4344     }
4345   else
4346     output_addr_const (file, x);
4347 }
4348
4349 /* output a SYMBOL_REF or a CONST expression involving a SYMBOL_REF. */
4350
4351 void
4352 output_global_address (file, x, round_constant)
4353      FILE *file;
4354      rtx x;
4355      int round_constant;
4356 {
4357
4358   /* Imagine  (high (const (plus ...))).  */
4359   if (GET_CODE (x) == HIGH)
4360     x = XEXP (x, 0);
4361
4362   if (GET_CODE (x) == SYMBOL_REF && read_only_operand (x, VOIDmode))
4363     assemble_name (file, XSTR (x, 0));
4364   else if (GET_CODE (x) == SYMBOL_REF && !flag_pic)
4365     {
4366       assemble_name (file, XSTR (x, 0));
4367       fputs ("-$global$", file);
4368     }
4369   else if (GET_CODE (x) == CONST)
4370     {
4371       const char *sep = "";
4372       int offset = 0;           /* assembler wants -$global$ at end */
4373       rtx base = NULL_RTX;
4374
4375       if (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)
4376         {
4377           base = XEXP (XEXP (x, 0), 0);
4378           output_addr_const (file, base);
4379         }
4380       else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == CONST_INT)
4381         offset = INTVAL (XEXP (XEXP (x, 0), 0));
4382       else abort ();
4383
4384       if (GET_CODE (XEXP (XEXP (x, 0), 1)) == SYMBOL_REF)
4385         {
4386           base = XEXP (XEXP (x, 0), 1);
4387           output_addr_const (file, base);
4388         }
4389       else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
4390         offset = INTVAL (XEXP (XEXP (x, 0), 1));
4391       else abort ();
4392
4393       /* How bogus.  The compiler is apparently responsible for
4394          rounding the constant if it uses an LR field selector.
4395
4396          The linker and/or assembler seem a better place since
4397          they have to do this kind of thing already.
4398
4399          If we fail to do this, HP's optimizing linker may eliminate
4400          an addil, but not update the ldw/stw/ldo instruction that
4401          uses the result of the addil.  */
4402       if (round_constant)
4403         offset = ((offset + 0x1000) & ~0x1fff);
4404
4405       if (GET_CODE (XEXP (x, 0)) == PLUS)
4406         {
4407           if (offset < 0)
4408             {
4409               offset = -offset;
4410               sep = "-";
4411             }
4412           else
4413             sep = "+";
4414         }
4415       else if (GET_CODE (XEXP (x, 0)) == MINUS
4416                && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))
4417         sep = "-";
4418       else abort ();
4419
4420       if (!read_only_operand (base, VOIDmode) && !flag_pic)
4421         fputs ("-$global$", file);
4422       if (offset)
4423         fprintf (file, "%s%d", sep, offset);
4424     }
4425   else
4426     output_addr_const (file, x);
4427 }
4428
4429 void
4430 output_deferred_plabels (file)
4431      FILE *file;
4432 {
4433   int i;
4434   /* If we have deferred plabels, then we need to switch into the data
4435      section and align it to a 4 byte boundary before we output the
4436      deferred plabels.  */
4437   if (n_deferred_plabels)
4438     {
4439       data_section ();
4440       ASM_OUTPUT_ALIGN (file, 2);
4441     }
4442
4443   /* Now output the deferred plabels.  */
4444   for (i = 0; i < n_deferred_plabels; i++)
4445     {
4446       ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (deferred_plabels[i].internal_label));
4447       assemble_integer (gen_rtx_SYMBOL_REF (Pmode, deferred_plabels[i].name),
4448                         4, 32, 1);
4449     }
4450 }
4451
4452 /* HP's millicode routines mean something special to the assembler.
4453    Keep track of which ones we have used.  */
4454
4455 enum millicodes { remI, remU, divI, divU, mulI, mulU, end1000 };
4456 static void import_milli                        PARAMS ((enum millicodes));
4457 static char imported[(int) end1000];
4458 static const char * const milli_names[] = {"remI", "remU", "divI", "divU", "mulI", "mulU"};
4459 static char import_string[] = ".IMPORT $$....,MILLICODE";
4460 #define MILLI_START 10
4461
4462 static void
4463 import_milli (code)
4464      enum millicodes code;
4465 {
4466   char str[sizeof (import_string)];
4467
4468   if (!imported[(int) code])
4469     {
4470       imported[(int) code] = 1;
4471       strcpy (str, import_string);
4472       strncpy (str + MILLI_START, milli_names[(int) code], 4);
4473       output_asm_insn (str, 0);
4474     }
4475 }
4476
4477 /* The register constraints have put the operands and return value in
4478    the proper registers. */
4479
4480 const char *
4481 output_mul_insn (unsignedp, insn)
4482      int unsignedp ATTRIBUTE_UNUSED;
4483      rtx insn;
4484 {
4485   import_milli (mulI);
4486   return output_millicode_call (insn, gen_rtx_SYMBOL_REF (Pmode, "$$mulI"));
4487 }
4488
4489 /* Emit the rtl for doing a division by a constant. */
4490
4491 /* Do magic division millicodes exist for this value? */
4492 static int magic_milli[]= {0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0,
4493                              1, 1};
4494
4495 /* We'll use an array to keep track of the magic millicodes and
4496    whether or not we've used them already. [n][0] is signed, [n][1] is
4497    unsigned. */
4498
4499 static int div_milli[16][2];
4500
4501 int
4502 div_operand (op, mode)
4503      rtx op;
4504      enum machine_mode mode;
4505 {
4506   return (mode == SImode
4507           && ((GET_CODE (op) == REG && REGNO (op) == 25)
4508               || (GET_CODE (op) == CONST_INT && INTVAL (op) > 0
4509                   && INTVAL (op) < 16 && magic_milli[INTVAL (op)])));
4510 }
4511
4512 int
4513 emit_hpdiv_const (operands, unsignedp)
4514      rtx *operands;
4515      int unsignedp;
4516 {
4517   if (GET_CODE (operands[2]) == CONST_INT
4518       && INTVAL (operands[2]) > 0
4519       && INTVAL (operands[2]) < 16
4520       && magic_milli[INTVAL (operands[2])])
4521     {
4522       rtx ret = gen_rtx_REG (SImode, TARGET_64BIT ? 2 : 31);
4523
4524       emit_move_insn (gen_rtx_REG (SImode, 26), operands[1]);
4525       emit
4526         (gen_rtx
4527          (PARALLEL, VOIDmode,
4528           gen_rtvec (6, gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, 29),
4529                                      gen_rtx_fmt_ee (unsignedp ? UDIV : DIV,
4530                                                      SImode,
4531                                                      gen_rtx_REG (SImode, 26),
4532                                                      operands[2])),
4533                      gen_rtx_CLOBBER (VOIDmode, operands[4]),
4534                      gen_rtx_CLOBBER (VOIDmode, operands[3]),
4535                      gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 26)),
4536                      gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 25)),
4537                      gen_rtx_CLOBBER (VOIDmode, ret))));
4538       emit_move_insn (operands[0], gen_rtx_REG (SImode, 29));
4539       return 1;
4540     }
4541   return 0;
4542 }
4543
4544 const char *
4545 output_div_insn (operands, unsignedp, insn)
4546      rtx *operands;
4547      int unsignedp;
4548      rtx insn;
4549 {
4550   int divisor;
4551
4552   /* If the divisor is a constant, try to use one of the special
4553      opcodes .*/
4554   if (GET_CODE (operands[0]) == CONST_INT)
4555     {
4556       static char buf[100];
4557       divisor = INTVAL (operands[0]);
4558       if (!div_milli[divisor][unsignedp])
4559         {
4560           div_milli[divisor][unsignedp] = 1;
4561           if (unsignedp)
4562             output_asm_insn (".IMPORT $$divU_%0,MILLICODE", operands);
4563           else
4564             output_asm_insn (".IMPORT $$divI_%0,MILLICODE", operands);
4565         }
4566       if (unsignedp)
4567         {
4568           sprintf (buf, "$$divU_%d", INTVAL (operands[0]));
4569           return output_millicode_call (insn,
4570                                         gen_rtx_SYMBOL_REF (SImode, buf));
4571         }
4572       else
4573         {
4574           sprintf (buf, "$$divI_%d", INTVAL (operands[0]));
4575           return output_millicode_call (insn,
4576                                         gen_rtx_SYMBOL_REF (SImode, buf));
4577         }
4578     }
4579   /* Divisor isn't a special constant. */
4580   else
4581     {
4582       if (unsignedp)
4583         {
4584           import_milli (divU);
4585           return output_millicode_call (insn,
4586                                         gen_rtx_SYMBOL_REF (SImode, "$$divU"));
4587         }
4588       else
4589         {
4590           import_milli (divI);
4591           return output_millicode_call (insn,
4592                                         gen_rtx_SYMBOL_REF (SImode, "$$divI"));
4593         }
4594     }
4595 }
4596
4597 /* Output a $$rem millicode to do mod. */
4598
4599 const char *
4600 output_mod_insn (unsignedp, insn)
4601      int unsignedp;
4602      rtx insn;
4603 {
4604   if (unsignedp)
4605     {
4606       import_milli (remU);
4607       return output_millicode_call (insn,
4608                                     gen_rtx_SYMBOL_REF (SImode, "$$remU"));
4609     }
4610   else
4611     {
4612       import_milli (remI);
4613       return output_millicode_call (insn,
4614                                     gen_rtx_SYMBOL_REF (SImode, "$$remI"));
4615     }
4616 }
4617
4618 void
4619 output_arg_descriptor (call_insn)
4620      rtx call_insn;
4621 {
4622   const char *arg_regs[4];
4623   enum machine_mode arg_mode;
4624   rtx link;
4625   int i, output_flag = 0;
4626   int regno;
4627
4628   /* We neither need nor want argument location descriptors for the
4629      64bit runtime environment or the ELF32 environment.  */
4630   if (TARGET_64BIT || TARGET_ELF32)
4631     return;
4632
4633   for (i = 0; i < 4; i++)
4634     arg_regs[i] = 0;
4635
4636   /* Specify explicitly that no argument relocations should take place
4637      if using the portable runtime calling conventions.  */
4638   if (TARGET_PORTABLE_RUNTIME)
4639     {
4640       fputs ("\t.CALL ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RETVAL=NO\n",
4641              asm_out_file);
4642       return;
4643     }
4644
4645   if (GET_CODE (call_insn) != CALL_INSN)
4646     abort ();
4647   for (link = CALL_INSN_FUNCTION_USAGE (call_insn); link; link = XEXP (link, 1))
4648     {
4649       rtx use = XEXP (link, 0);
4650
4651       if (! (GET_CODE (use) == USE
4652              && GET_CODE (XEXP (use, 0)) == REG
4653              && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
4654         continue;
4655
4656       arg_mode = GET_MODE (XEXP (use, 0));
4657       regno = REGNO (XEXP (use, 0));
4658       if (regno >= 23 && regno <= 26)
4659         {
4660           arg_regs[26 - regno] = "GR";
4661           if (arg_mode == DImode)
4662             arg_regs[25 - regno] = "GR";
4663         }
4664       else if (regno >= 32 && regno <= 39)
4665         {
4666           if (arg_mode == SFmode)
4667             arg_regs[(regno - 32) / 2] = "FR";
4668           else
4669             {
4670 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
4671               arg_regs[(regno - 34) / 2] = "FR";
4672               arg_regs[(regno - 34) / 2 + 1] = "FU";
4673 #else
4674               arg_regs[(regno - 34) / 2] = "FU";
4675               arg_regs[(regno - 34) / 2 + 1] = "FR";
4676 #endif
4677             }
4678         }
4679     }
4680   fputs ("\t.CALL ", asm_out_file);
4681   for (i = 0; i < 4; i++)
4682     {
4683       if (arg_regs[i])
4684         {
4685           if (output_flag++)
4686             fputc (',', asm_out_file);
4687           fprintf (asm_out_file, "ARGW%d=%s", i, arg_regs[i]);
4688         }
4689     }
4690   fputc ('\n', asm_out_file);
4691 }
4692 \f
4693 /* Return the class of any secondary reload register that is needed to
4694    move IN into a register in class CLASS using mode MODE.
4695
4696    Profiling has showed this routine and its descendants account for
4697    a significant amount of compile time (~7%).  So it has been
4698    optimized to reduce redundant computations and eliminate useless
4699    function calls.
4700
4701    It might be worthwhile to try and make this a leaf function too.  */
4702
4703 enum reg_class
4704 secondary_reload_class (class, mode, in)
4705      enum reg_class class;
4706      enum machine_mode mode;
4707      rtx in;
4708 {
4709   int regno, is_symbolic;
4710
4711   /* Trying to load a constant into a FP register during PIC code
4712      generation will require %r1 as a scratch register.  */
4713   if (flag_pic
4714       && GET_MODE_CLASS (mode) == MODE_INT
4715       && FP_REG_CLASS_P (class)
4716       && (GET_CODE (in) == CONST_INT || GET_CODE (in) == CONST_DOUBLE))
4717     return R1_REGS;
4718
4719   /* Profiling showed the PA port spends about 1.3% of its compilation
4720      time in true_regnum from calls inside secondary_reload_class.  */
4721
4722   if (GET_CODE (in) == REG)
4723     {
4724       regno = REGNO (in);
4725       if (regno >= FIRST_PSEUDO_REGISTER)
4726         regno = true_regnum (in);
4727     }
4728   else if (GET_CODE (in) == SUBREG)
4729     regno = true_regnum (in);
4730   else
4731     regno = -1;
4732
4733   /* If we have something like (mem (mem (...)), we can safely assume the
4734      inner MEM will end up in a general register after reloading, so there's
4735      no need for a secondary reload.  */
4736   if (GET_CODE (in) == MEM
4737       && GET_CODE (XEXP (in, 0)) == MEM)
4738     return NO_REGS;
4739
4740   /* Handle out of range displacement for integer mode loads/stores of
4741      FP registers.  */
4742   if (((regno >= FIRST_PSEUDO_REGISTER || regno == -1)
4743        && GET_MODE_CLASS (mode) == MODE_INT
4744        && FP_REG_CLASS_P (class))
4745       || (class == SHIFT_REGS && (regno <= 0 || regno >= 32)))
4746     return GENERAL_REGS;
4747
4748   /* A SAR<->FP register copy requires a secondary register (GPR) as
4749      well as secondary memory.  */
4750   if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
4751       && ((REGNO_REG_CLASS (regno) == SHIFT_REGS && FP_REG_CLASS_P (class))
4752           || (class == SHIFT_REGS && FP_REG_CLASS_P (REGNO_REG_CLASS (regno)))))
4753     return GENERAL_REGS;
4754
4755   if (GET_CODE (in) == HIGH)
4756     in = XEXP (in, 0);
4757
4758   /* Profiling has showed GCC spends about 2.6% of its compilation
4759      time in symbolic_operand from calls inside secondary_reload_class.
4760
4761      We use an inline copy and only compute its return value once to avoid
4762      useless work.  */
4763   switch (GET_CODE (in))
4764     {
4765       rtx tmp;
4766
4767       case SYMBOL_REF:
4768       case LABEL_REF:
4769         is_symbolic = 1;
4770         break;
4771       case CONST:
4772         tmp = XEXP (in, 0);
4773         is_symbolic = ((GET_CODE (XEXP (tmp, 0)) == SYMBOL_REF
4774                         || GET_CODE (XEXP (tmp, 0)) == LABEL_REF)
4775                        && GET_CODE (XEXP (tmp, 1)) == CONST_INT);
4776         break;
4777
4778       default:
4779         is_symbolic = 0;
4780         break;
4781     }
4782
4783   if (!flag_pic
4784       && is_symbolic
4785       && read_only_operand (in, VOIDmode))
4786     return NO_REGS;
4787
4788   if (class != R1_REGS && is_symbolic)
4789     return R1_REGS;
4790
4791   return NO_REGS;
4792 }
4793
4794 enum direction
4795 function_arg_padding (mode, type)
4796      enum machine_mode mode;
4797      tree type;
4798 {
4799   int size;
4800
4801   if (mode == BLKmode)
4802     {
4803       if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4804         size = int_size_in_bytes (type) * BITS_PER_UNIT;
4805       else
4806         return upward;          /* Don't know if this is right, but */
4807                                 /* same as old definition. */
4808     }
4809   else
4810     size = GET_MODE_BITSIZE (mode);
4811   if (size < PARM_BOUNDARY)
4812     return downward;
4813   else if (size % PARM_BOUNDARY)
4814     return upward;
4815   else
4816     return none;
4817 }
4818
4819 \f
4820 /* Do what is necessary for `va_start'.  We look at the current function
4821    to determine if stdargs or varargs is used and fill in an initial
4822    va_list.  A pointer to this constructor is returned.  */
4823
4824 struct rtx_def *
4825 hppa_builtin_saveregs ()
4826 {
4827   rtx offset, dest;
4828   tree fntype = TREE_TYPE (current_function_decl);
4829   int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
4830                    && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4831                        != void_type_node)))
4832                 ? UNITS_PER_WORD : 0);
4833
4834   if (argadj)
4835     offset = plus_constant (current_function_arg_offset_rtx, argadj);
4836   else
4837     offset = current_function_arg_offset_rtx;
4838
4839   if (TARGET_64BIT)
4840     {
4841       int i, off;
4842
4843       /* Adjust for varargs/stdarg differences.  */
4844       if (argadj)
4845         offset = plus_constant (current_function_arg_offset_rtx, -argadj);
4846       else
4847         offset = current_function_arg_offset_rtx;
4848
4849       /* We need to save %r26 .. %r19 inclusive starting at offset -64
4850          from the incoming arg pointer and growing to larger addresses.  */
4851       for (i = 26, off = -64; i >= 19; i--, off += 8)
4852         emit_move_insn (gen_rtx_MEM (word_mode,
4853                                      plus_constant (arg_pointer_rtx, off)),
4854                         gen_rtx_REG (word_mode, i));
4855
4856       /* The incoming args pointer points just beyond the flushback area;
4857          normally this is not a serious concern.  Howver, when we are doing
4858          varargs/stdargs we want to make the arg pointer point to the start
4859          of the incoming argument area.  */
4860       emit_move_insn (virtual_incoming_args_rtx,
4861                       plus_constant (arg_pointer_rtx, -64));
4862
4863       /* Now return a pointer to the first anonymous argument.  */
4864       return copy_to_reg (expand_binop (Pmode, add_optab,
4865                                         virtual_incoming_args_rtx,
4866                                         offset, 0, 0, OPTAB_LIB_WIDEN));
4867     }
4868
4869   /* Store general registers on the stack. */
4870   dest = gen_rtx_MEM (BLKmode,
4871                       plus_constant (current_function_internal_arg_pointer,
4872                                      -16));
4873   set_mem_alias_set (dest, get_varargs_alias_set ());
4874   move_block_from_reg (23, dest, 4, 4 * UNITS_PER_WORD);
4875
4876   /* move_block_from_reg will emit code to store the argument registers
4877      individually as scalar stores.
4878
4879      However, other insns may later load from the same addresses for
4880      a structure load (passing a struct to a varargs routine).
4881
4882      The alias code assumes that such aliasing can never happen, so we
4883      have to keep memory referencing insns from moving up beyond the
4884      last argument register store.  So we emit a blockage insn here.  */
4885   emit_insn (gen_blockage ());
4886
4887   if (current_function_check_memory_usage)
4888     emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4889                        dest, ptr_mode,
4890                        GEN_INT (4 * UNITS_PER_WORD), TYPE_MODE (sizetype),
4891                        GEN_INT (MEMORY_USE_RW),
4892                        TYPE_MODE (integer_type_node));
4893
4894   return copy_to_reg (expand_binop (Pmode, add_optab,
4895                                     current_function_internal_arg_pointer,
4896                                     offset, 0, 0, OPTAB_LIB_WIDEN));
4897 }
4898
4899 void
4900 hppa_va_start (stdarg_p, valist, nextarg)
4901      int stdarg_p ATTRIBUTE_UNUSED;
4902      tree valist;
4903      rtx nextarg;
4904 {
4905   nextarg = expand_builtin_saveregs ();
4906   std_expand_builtin_va_start (1, valist, nextarg);
4907 }
4908
4909 rtx
4910 hppa_va_arg (valist, type)
4911      tree valist, type;
4912 {
4913   HOST_WIDE_INT align, size, ofs;
4914   tree t, ptr, pptr;
4915
4916   if (TARGET_64BIT)
4917     {
4918       /* Every argument in PA64 is passed by value (including large structs).
4919          Arguments with size greater than 8 must be aligned 0 MOD 16. */
4920
4921       size = int_size_in_bytes (type);
4922       if (size > UNITS_PER_WORD)
4923         {
4924           t = build (PLUS_EXPR, TREE_TYPE (valist), valist,
4925                      build_int_2 (2 * UNITS_PER_WORD - 1, 0));
4926           t = build (BIT_AND_EXPR, TREE_TYPE (t), t,
4927                      build_int_2 (-2 * UNITS_PER_WORD, -1));
4928           t = build (MODIFY_EXPR, TREE_TYPE (valist), valist, t);
4929           TREE_SIDE_EFFECTS (t) = 1;
4930           expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4931         }
4932       return std_expand_builtin_va_arg (valist, type);
4933     }
4934
4935   /* Compute the rounded size of the type.  */
4936   align = PARM_BOUNDARY / BITS_PER_UNIT;
4937   size = int_size_in_bytes (type);
4938
4939   ptr = build_pointer_type (type);
4940
4941   /* "Large" types are passed by reference.  */
4942   if (size > 8)
4943     {
4944       t = build (PREDECREMENT_EXPR, TREE_TYPE (valist), valist,
4945                  build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
4946       TREE_SIDE_EFFECTS (t) = 1;
4947
4948       pptr = build_pointer_type (ptr);
4949       t = build1 (NOP_EXPR, pptr, t);
4950       TREE_SIDE_EFFECTS (t) = 1;
4951
4952       t = build1 (INDIRECT_REF, ptr, t);
4953       TREE_SIDE_EFFECTS (t) = 1;
4954     }
4955   else
4956     {
4957       t = build (PLUS_EXPR, TREE_TYPE (valist), valist,
4958                  build_int_2 (-size, -1));
4959
4960       /* Copied from va-pa.h, but we probably don't need to align
4961          to word size, since we generate and preserve that invariant.  */
4962       t = build (BIT_AND_EXPR, TREE_TYPE (valist), t,
4963                  build_int_2 ((size > 4 ? -8 : -4), -1));
4964
4965       t = build (MODIFY_EXPR, TREE_TYPE (valist), valist, t);
4966       TREE_SIDE_EFFECTS (t) = 1;
4967
4968       ofs = (8 - size) % 4;
4969       if (ofs)
4970         {
4971           t = build (PLUS_EXPR, TREE_TYPE (valist), t, build_int_2 (ofs, 0));
4972           TREE_SIDE_EFFECTS (t) = 1;
4973         }
4974
4975       t = build1 (NOP_EXPR, ptr, t);
4976       TREE_SIDE_EFFECTS (t) = 1;
4977     }
4978
4979   /* Calculate!  */
4980   return expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
4981 }
4982
4983
4984
4985 /* This routine handles all the normal conditional branch sequences we
4986    might need to generate.  It handles compare immediate vs compare
4987    register, nullification of delay slots, varying length branches,
4988    negated branches, and all combinations of the above.  It returns the
4989    output appropriate to emit the branch corresponding to all given
4990    parameters.  */
4991
4992 const char *
4993 output_cbranch (operands, nullify, length, negated, insn)
4994   rtx *operands;
4995   int nullify, length, negated;
4996   rtx insn;
4997 {
4998   static char buf[100];
4999   int useskip = 0;
5000
5001   /* A conditional branch to the following instruction (eg the delay slot) is
5002      asking for a disaster.  This can happen when not optimizing.
5003
5004      In such cases it is safe to emit nothing.  */
5005
5006   if (next_active_insn (JUMP_LABEL (insn)) == next_active_insn (insn))
5007     return "";
5008
5009   /* If this is a long branch with its delay slot unfilled, set `nullify'
5010      as it can nullify the delay slot and save a nop.  */
5011   if (length == 8 && dbr_sequence_length () == 0)
5012     nullify = 1;
5013
5014   /* If this is a short forward conditional branch which did not get
5015      its delay slot filled, the delay slot can still be nullified.  */
5016   if (! nullify && length == 4 && dbr_sequence_length () == 0)
5017     nullify = forward_branch_p (insn);
5018
5019   /* A forward branch over a single nullified insn can be done with a
5020      comclr instruction.  This avoids a single cycle penalty due to
5021      mis-predicted branch if we fall through (branch not taken).  */
5022   if (length == 4
5023       && next_real_insn (insn) != 0
5024       && get_attr_length (next_real_insn (insn)) == 4
5025       && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
5026       && nullify)
5027     useskip = 1;
5028
5029   switch (length)
5030     {
5031       /* All short conditional branches except backwards with an unfilled
5032          delay slot.  */
5033       case 4:
5034         if (useskip)
5035           strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
5036         else
5037           strcpy (buf, "{com%I2b,|cmp%I2b,}");
5038         if (GET_MODE (operands[1]) == DImode)
5039           strcat (buf, "*");
5040         if (negated)
5041           strcat (buf, "%B3");
5042         else
5043           strcat (buf, "%S3");
5044         if (useskip)
5045           strcat (buf, " %2,%r1,%%r0");
5046         else if (nullify)
5047           strcat (buf, ",n %2,%r1,%0");
5048         else
5049           strcat (buf, " %2,%r1,%0");
5050         break;
5051
5052      /* All long conditionals.  Note an short backward branch with an
5053         unfilled delay slot is treated just like a long backward branch
5054         with an unfilled delay slot.  */
5055       case 8:
5056         /* Handle weird backwards branch with a filled delay slot
5057            with is nullified.  */
5058         if (dbr_sequence_length () != 0
5059             && ! forward_branch_p (insn)
5060             && nullify)
5061           {
5062             strcpy (buf, "{com%I2b,|cmp%I2b,}");
5063             if (GET_MODE (operands[1]) == DImode)
5064               strcat (buf, "*");
5065             if (negated)
5066               strcat (buf, "%S3");
5067             else
5068               strcat (buf, "%B3");
5069             strcat (buf, ",n %2,%r1,.+12\n\tb %0");
5070           }
5071         /* Handle short backwards branch with an unfilled delay slot.
5072            Using a comb;nop rather than comiclr;bl saves 1 cycle for both
5073            taken and untaken branches.  */
5074         else if (dbr_sequence_length () == 0
5075                  && ! forward_branch_p (insn)
5076                  && INSN_ADDRESSES_SET_P ()
5077                  && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
5078                                     - INSN_ADDRESSES (INSN_UID (insn)) - 8))
5079           {
5080             strcpy (buf, "{com%I2b,|cmp%I2b,}");
5081             if (GET_MODE (operands[1]) == DImode)
5082               strcat (buf, "*");
5083             if (negated)
5084               strcat (buf, "%B3 %2,%r1,%0%#");
5085             else
5086               strcat (buf, "%S3 %2,%r1,%0%#");
5087           }
5088         else
5089           {
5090             strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
5091             if (GET_MODE (operands[1]) == DImode)
5092               strcat (buf, "*");
5093             if (negated)
5094               strcat (buf, "%S3");
5095             else
5096               strcat (buf, "%B3");
5097             if (nullify)
5098               strcat (buf, " %2,%r1,%%r0\n\tb,n %0");
5099             else
5100               strcat (buf, " %2,%r1,%%r0\n\tb %0");
5101           }
5102         break;
5103
5104       case 20:
5105         /* Very long branch.  Right now we only handle these when not
5106            optimizing.  See "jump" pattern in pa.md for details.  */
5107         if (optimize)
5108           abort ();
5109
5110         /* Create a reversed conditional branch which branches around
5111            the following insns.  */
5112         if (negated)
5113           strcpy (buf, "{com%I2b,%S3,n %2,%r1,.+20|cmp%I2b,%S3,n %2,%r1,.+20}");
5114         else
5115           strcpy (buf, "{com%I2b,%B3,n %2,%r1,.+20|cmp%I2b,%B3,n %2,%r1,.+20}");
5116         if (GET_MODE (operands[1]) == DImode)
5117           {
5118             if (negated)
5119               strcpy (buf,
5120                       "{com%I2b,*%S3,n %2,%r1,.+20|cmp%I2b,*%S3,n %2,%r1,.+20}");
5121             else
5122               strcpy (buf,
5123                       "{com%I2b,*%B3,n %2,%r1,.+20|cmp%I2b,*%B3,n %2,%r1,.+20}");
5124           }
5125         output_asm_insn (buf, operands);
5126
5127         /* Output an insn to save %r1.  */
5128         output_asm_insn ("stw %%r1,-16(%%r30)", operands);
5129
5130         /* Now output a very long branch to the original target.  */
5131         output_asm_insn ("ldil L'%l0,%%r1\n\tbe R'%l0(%%sr4,%%r1)", operands);
5132
5133         /* Now restore the value of %r1 in the delay slot.  We're not
5134            optimizing so we know nothing else can be in the delay slot.  */
5135         return "ldw -16(%%r30),%%r1";
5136
5137       case 28:
5138         /* Very long branch when generating PIC code.  Right now we only
5139            handle these when not optimizing.  See "jump" pattern in pa.md
5140            for details.  */
5141         if (optimize)
5142           abort ();
5143
5144         /* Create a reversed conditional branch which branches around
5145            the following insns.  */
5146         if (negated)
5147           strcpy (buf, "{com%I2b,%S3,n %2,%r1,.+28|cmp%I2b,%S3,n %2,%r1,.+28}");
5148         else
5149           strcpy (buf, "{com%I2b,%B3,n %2,%r1,.+28|cmp%I2b,%B3,n %2,%r1,.+28}");
5150         if (GET_MODE (operands[1]) == DImode)
5151           {
5152             if (negated)
5153               strcpy (buf, "{com%I2b,*%S3,n %2,%r1,.+28|cmp%I2b,*%S3,n %2,%r1,.+28}");
5154             else
5155               strcpy (buf, "{com%I2b,*%B3,n %2,%r1,.+28|cmp%I2b,*%B3,n %2,%r1,.+28}");
5156           }
5157         output_asm_insn (buf, operands);
5158
5159         /* Output an insn to save %r1.  */
5160         output_asm_insn ("stw %%r1,-16(%%r30)", operands);
5161
5162         /* Now output a very long PIC branch to the original target.  */
5163         {
5164           rtx xoperands[5];
5165
5166           xoperands[0] = operands[0];
5167           xoperands[1] = operands[1];
5168           xoperands[2] = operands[2];
5169           xoperands[3] = operands[3];
5170           xoperands[4] = gen_label_rtx ();
5171
5172           output_asm_insn ("{bl|b,l} .+8,%%r1\n\taddil L'%l0-%l4,%%r1",
5173                            xoperands);
5174           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
5175                                      CODE_LABEL_NUMBER (xoperands[4]));
5176           output_asm_insn ("ldo R'%l0-%l4(%%r1),%%r1\n\tbv %%r0(%%r1)",
5177                            xoperands);
5178         }
5179
5180         /* Now restore the value of %r1 in the delay slot.  We're not
5181            optimizing so we know nothing else can be in the delay slot.  */
5182         return "ldw -16(%%r30),%%r1";
5183
5184       default:
5185         abort ();
5186     }
5187   return buf;
5188 }
5189
5190 /* This routine handles all the branch-on-bit conditional branch sequences we
5191    might need to generate.  It handles nullification of delay slots,
5192    varying length branches, negated branches and all combinations of the
5193    above.  it returns the appropriate output template to emit the branch.  */
5194
5195 const char *
5196 output_bb (operands, nullify, length, negated, insn, which)
5197   rtx *operands ATTRIBUTE_UNUSED;
5198   int nullify, length, negated;
5199   rtx insn;
5200   int which;
5201 {
5202   static char buf[100];
5203   int useskip = 0;
5204
5205   /* A conditional branch to the following instruction (eg the delay slot) is
5206      asking for a disaster.  I do not think this can happen as this pattern
5207      is only used when optimizing; jump optimization should eliminate the
5208      jump.  But be prepared just in case.  */
5209
5210   if (next_active_insn (JUMP_LABEL (insn)) == next_active_insn (insn))
5211     return "";
5212
5213   /* If this is a long branch with its delay slot unfilled, set `nullify'
5214      as it can nullify the delay slot and save a nop.  */
5215   if (length == 8 && dbr_sequence_length () == 0)
5216     nullify = 1;
5217
5218   /* If this is a short forward conditional branch which did not get
5219      its delay slot filled, the delay slot can still be nullified.  */
5220   if (! nullify && length == 4 && dbr_sequence_length () == 0)
5221     nullify = forward_branch_p (insn);
5222
5223   /* A forward branch over a single nullified insn can be done with a
5224      extrs instruction.  This avoids a single cycle penalty due to
5225      mis-predicted branch if we fall through (branch not taken).  */
5226
5227   if (length == 4
5228       && next_real_insn (insn) != 0
5229       && get_attr_length (next_real_insn (insn)) == 4
5230       && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
5231       && nullify)
5232     useskip = 1;
5233
5234   switch (length)
5235     {
5236
5237       /* All short conditional branches except backwards with an unfilled
5238          delay slot.  */
5239       case 4:
5240         if (useskip)
5241           strcpy (buf, "{extrs,|extrw,s,}");
5242         else
5243           strcpy (buf, "bb,");
5244         if (useskip && GET_MODE (operands[0]) == DImode)
5245           strcpy (buf, "extrd,s,*");
5246         else if (GET_MODE (operands[0]) == DImode)
5247           strcpy (buf, "bb,*");
5248         if ((which == 0 && negated)
5249              || (which == 1 && ! negated))
5250           strcat (buf, ">=");
5251         else
5252           strcat (buf, "<");
5253         if (useskip)
5254           strcat (buf, " %0,%1,1,%%r0");
5255         else if (nullify && negated)
5256           strcat (buf, ",n %0,%1,%3");
5257         else if (nullify && ! negated)
5258           strcat (buf, ",n %0,%1,%2");
5259         else if (! nullify && negated)
5260           strcat (buf, "%0,%1,%3");
5261         else if (! nullify && ! negated)
5262           strcat (buf, " %0,%1,%2");
5263         break;
5264
5265      /* All long conditionals.  Note an short backward branch with an
5266         unfilled delay slot is treated just like a long backward branch
5267         with an unfilled delay slot.  */
5268       case 8:
5269         /* Handle weird backwards branch with a filled delay slot
5270            with is nullified.  */
5271         if (dbr_sequence_length () != 0
5272             && ! forward_branch_p (insn)
5273             && nullify)
5274           {
5275             strcpy (buf, "bb,");
5276             if (GET_MODE (operands[0]) == DImode)
5277               strcat (buf, "*");
5278             if ((which == 0 && negated)
5279                 || (which == 1 && ! negated))
5280               strcat (buf, "<");
5281             else
5282               strcat (buf, ">=");
5283             if (negated)
5284               strcat (buf, ",n %0,%1,.+12\n\tb %3");
5285             else
5286               strcat (buf, ",n %0,%1,.+12\n\tb %2");
5287           }
5288         /* Handle short backwards branch with an unfilled delay slot.
5289            Using a bb;nop rather than extrs;bl saves 1 cycle for both
5290            taken and untaken branches.  */
5291         else if (dbr_sequence_length () == 0
5292                  && ! forward_branch_p (insn)
5293                  && INSN_ADDRESSES_SET_P ()
5294                  && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
5295                                     - INSN_ADDRESSES (INSN_UID (insn)) - 8))
5296           {
5297             strcpy (buf, "bb,");
5298             if (GET_MODE (operands[0]) == DImode)
5299               strcat (buf, "*");
5300             if ((which == 0 && negated)
5301                 || (which == 1 && ! negated))
5302               strcat (buf, ">=");
5303             else
5304               strcat (buf, "<");
5305             if (negated)
5306               strcat (buf, " %0,%1,%3%#");
5307             else
5308               strcat (buf, " %0,%1,%2%#");
5309           }
5310         else
5311           {
5312             strcpy (buf, "{extrs,|extrw,s,}");
5313             if (GET_MODE (operands[0]) == DImode)
5314               strcpy (buf, "extrd,s,*");
5315             if ((which == 0 && negated)
5316                 || (which == 1 && ! negated))
5317               strcat (buf, "<");
5318             else
5319               strcat (buf, ">=");
5320             if (nullify && negated)
5321               strcat (buf, " %0,%1,1,%%r0\n\tb,n %3");
5322             else if (nullify && ! negated)
5323               strcat (buf, " %0,%1,1,%%r0\n\tb,n %2");
5324             else if (negated)
5325               strcat (buf, " %0,%1,1,%%r0\n\tb %3");
5326             else
5327               strcat (buf, " %0,%1,1,%%r0\n\tb %2");
5328           }
5329         break;
5330
5331       default:
5332         abort ();
5333     }
5334   return buf;
5335 }
5336
5337 /* This routine handles all the branch-on-variable-bit conditional branch
5338    sequences we might need to generate.  It handles nullification of delay
5339    slots, varying length branches, negated branches and all combinations
5340    of the above.  it returns the appropriate output template to emit the
5341    branch.  */
5342
5343 const char *
5344 output_bvb (operands, nullify, length, negated, insn, which)
5345   rtx *operands ATTRIBUTE_UNUSED;
5346   int nullify, length, negated;
5347   rtx insn;
5348   int which;
5349 {
5350   static char buf[100];
5351   int useskip = 0;
5352
5353   /* A conditional branch to the following instruction (eg the delay slot) is
5354      asking for a disaster.  I do not think this can happen as this pattern
5355      is only used when optimizing; jump optimization should eliminate the
5356      jump.  But be prepared just in case.  */
5357
5358   if (next_active_insn (JUMP_LABEL (insn)) == next_active_insn (insn))
5359     return "";
5360
5361   /* If this is a long branch with its delay slot unfilled, set `nullify'
5362      as it can nullify the delay slot and save a nop.  */
5363   if (length == 8 && dbr_sequence_length () == 0)
5364     nullify = 1;
5365
5366   /* If this is a short forward conditional branch which did not get
5367      its delay slot filled, the delay slot can still be nullified.  */
5368   if (! nullify && length == 4 && dbr_sequence_length () == 0)
5369     nullify = forward_branch_p (insn);
5370
5371   /* A forward branch over a single nullified insn can be done with a
5372      extrs instruction.  This avoids a single cycle penalty due to
5373      mis-predicted branch if we fall through (branch not taken).  */
5374
5375   if (length == 4
5376       && next_real_insn (insn) != 0
5377       && get_attr_length (next_real_insn (insn)) == 4
5378       && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
5379       && nullify)
5380     useskip = 1;
5381
5382   switch (length)
5383     {
5384
5385       /* All short conditional branches except backwards with an unfilled
5386          delay slot.  */
5387       case 4:
5388         if (useskip)
5389           strcpy (buf, "{vextrs,|extrw,s,}");
5390         else
5391           strcpy (buf, "{bvb,|bb,}");
5392         if (useskip && GET_MODE (operands[0]) == DImode)
5393           strcpy (buf, "extrd,s,*}");
5394         else if (GET_MODE (operands[0]) == DImode)
5395           strcpy (buf, "bb,*");
5396         if ((which == 0 && negated)
5397              || (which == 1 && ! negated))
5398           strcat (buf, ">=");
5399         else
5400           strcat (buf, "<");
5401         if (useskip)
5402           strcat (buf, "{ %0,1,%%r0| %0,%%sar,1,%%r0}");
5403         else if (nullify && negated)
5404           strcat (buf, "{,n %0,%3|,n %0,%%sar,%3}");
5405         else if (nullify && ! negated)
5406           strcat (buf, "{,n %0,%2|,n %0,%%sar,%2}");
5407         else if (! nullify && negated)
5408           strcat (buf, "{%0,%3|%0,%%sar,%3}");
5409         else if (! nullify && ! negated)
5410           strcat (buf, "{ %0,%2| %0,%%sar,%2}");
5411         break;
5412
5413      /* All long conditionals.  Note an short backward branch with an
5414         unfilled delay slot is treated just like a long backward branch
5415         with an unfilled delay slot.  */
5416       case 8:
5417         /* Handle weird backwards branch with a filled delay slot
5418            with is nullified.  */
5419         if (dbr_sequence_length () != 0
5420             && ! forward_branch_p (insn)
5421             && nullify)
5422           {
5423             strcpy (buf, "{bvb,|bb,}");
5424             if (GET_MODE (operands[0]) == DImode)
5425               strcat (buf, "*");
5426             if ((which == 0 && negated)
5427                 || (which == 1 && ! negated))
5428               strcat (buf, "<");
5429             else
5430               strcat (buf, ">=");
5431             if (negated)
5432               strcat (buf, "{,n %0,.+12\n\tb %3|,n %0,%%sar,.+12\n\tb %3}");
5433             else
5434               strcat (buf, "{,n %0,.+12\n\tb %2|,n %0,%%sar,.+12\n\tb %2}");
5435           }
5436         /* Handle short backwards branch with an unfilled delay slot.
5437            Using a bb;nop rather than extrs;bl saves 1 cycle for both
5438            taken and untaken branches.  */
5439         else if (dbr_sequence_length () == 0
5440                  && ! forward_branch_p (insn)
5441                  && INSN_ADDRESSES_SET_P ()
5442                  && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
5443                                     - INSN_ADDRESSES (INSN_UID (insn)) - 8))
5444           {
5445             strcpy (buf, "{bvb,|bb,}");
5446             if (GET_MODE (operands[0]) == DImode)
5447               strcat (buf, "*");
5448             if ((which == 0 && negated)
5449                 || (which == 1 && ! negated))
5450               strcat (buf, ">=");
5451             else
5452               strcat (buf, "<");
5453             if (negated)
5454               strcat (buf, "{ %0,%3%#| %0,%%sar,%3%#}");
5455             else
5456               strcat (buf, "{ %0,%2%#| %0,%%sar,%2%#}");
5457           }
5458         else
5459           {
5460             strcpy (buf, "{vextrs,|extrw,s,}");
5461             if (GET_MODE (operands[0]) == DImode)
5462               strcpy (buf, "extrd,s,*");
5463             if ((which == 0 && negated)
5464                 || (which == 1 && ! negated))
5465               strcat (buf, "<");
5466             else
5467               strcat (buf, ">=");
5468             if (nullify && negated)
5469               strcat (buf, "{ %0,1,%%r0\n\tb,n %3| %0,%%sar,1,%%r0\n\tb,n %3}");
5470             else if (nullify && ! negated)
5471               strcat (buf, "{ %0,1,%%r0\n\tb,n %2| %0,%%sar,1,%%r0\n\tb,n %2}");
5472             else if (negated)
5473               strcat (buf, "{ %0,1,%%r0\n\tb %3| %0,%%sar,1,%%r0\n\tb %3}");
5474             else
5475               strcat (buf, "{ %0,1,%%r0\n\tb %2| %0,%%sar,1,%%r0\n\tb %2}");
5476           }
5477         break;
5478
5479       default:
5480         abort ();
5481     }
5482   return buf;
5483 }
5484
5485 /* Return the output template for emitting a dbra type insn.
5486
5487    Note it may perform some output operations on its own before
5488    returning the final output string.  */
5489 const char *
5490 output_dbra (operands, insn, which_alternative)
5491      rtx *operands;
5492      rtx insn;
5493      int which_alternative;
5494 {
5495
5496   /* A conditional branch to the following instruction (eg the delay slot) is
5497      asking for a disaster.  Be prepared!  */
5498
5499   if (next_active_insn (JUMP_LABEL (insn)) == next_active_insn (insn))
5500     {
5501       if (which_alternative == 0)
5502         return "ldo %1(%0),%0";
5503       else if (which_alternative == 1)
5504         {
5505           output_asm_insn ("{fstws|fstw} %0,-16(%%r30)", operands);
5506           output_asm_insn ("ldw -16(%%r30),%4", operands);
5507           output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
5508           return "{fldws|fldw} -16(%%r30),%0";
5509         }
5510       else
5511         {
5512           output_asm_insn ("ldw %0,%4", operands);
5513           return "ldo %1(%4),%4\n\tstw %4,%0";
5514         }
5515     }
5516
5517   if (which_alternative == 0)
5518     {
5519       int nullify = INSN_ANNULLED_BRANCH_P (insn);
5520       int length = get_attr_length (insn);
5521
5522       /* If this is a long branch with its delay slot unfilled, set `nullify'
5523          as it can nullify the delay slot and save a nop.  */
5524       if (length == 8 && dbr_sequence_length () == 0)
5525         nullify = 1;
5526
5527       /* If this is a short forward conditional branch which did not get
5528          its delay slot filled, the delay slot can still be nullified.  */
5529       if (! nullify && length == 4 && dbr_sequence_length () == 0)
5530         nullify = forward_branch_p (insn);
5531
5532       /* Handle short versions first.  */
5533       if (length == 4 && nullify)
5534         return "addib,%C2,n %1,%0,%3";
5535       else if (length == 4 && ! nullify)
5536         return "addib,%C2 %1,%0,%3";
5537       else if (length == 8)
5538         {
5539           /* Handle weird backwards branch with a fulled delay slot
5540              which is nullified.  */
5541           if (dbr_sequence_length () != 0
5542               && ! forward_branch_p (insn)
5543               && nullify)
5544             return "addib,%N2,n %1,%0,.+12\n\tb %3";
5545           /* Handle short backwards branch with an unfilled delay slot.
5546              Using a addb;nop rather than addi;bl saves 1 cycle for both
5547              taken and untaken branches.  */
5548           else if (dbr_sequence_length () == 0
5549                    && ! forward_branch_p (insn)
5550                    && INSN_ADDRESSES_SET_P ()
5551                    && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
5552                                       - INSN_ADDRESSES (INSN_UID (insn)) - 8))
5553               return "addib,%C2 %1,%0,%3%#";
5554
5555           /* Handle normal cases.  */
5556           if (nullify)
5557             return "addi,%N2 %1,%0,%0\n\tb,n %3";
5558           else
5559             return "addi,%N2 %1,%0,%0\n\tb %3";
5560         }
5561       else
5562         abort ();
5563     }
5564   /* Deal with gross reload from FP register case.  */
5565   else if (which_alternative == 1)
5566     {
5567       /* Move loop counter from FP register to MEM then into a GR,
5568          increment the GR, store the GR into MEM, and finally reload
5569          the FP register from MEM from within the branch's delay slot.  */
5570       output_asm_insn ("{fstws|fstw} %0,-16(%%r30)\n\tldw -16(%%r30),%4",
5571                        operands);
5572       output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
5573       if (get_attr_length (insn) == 24)
5574         return "{comb|cmpb},%S2 %%r0,%4,%3\n\t{fldws|fldw} -16(%%r30),%0";
5575       else
5576         return "{comclr|cmpclr},%B2 %%r0,%4,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
5577     }
5578   /* Deal with gross reload from memory case.  */
5579   else
5580     {
5581       /* Reload loop counter from memory, the store back to memory
5582          happens in the branch's delay slot.   */
5583       output_asm_insn ("ldw %0,%4", operands);
5584       if (get_attr_length (insn) == 12)
5585         return "addib,%C2 %1,%4,%3\n\tstw %4,%0";
5586       else
5587         return "addi,%N2 %1,%4,%4\n\tb %3\n\tstw %4,%0";
5588     }
5589 }
5590
5591 /* Return the output template for emitting a dbra type insn.
5592
5593    Note it may perform some output operations on its own before
5594    returning the final output string.  */
5595 const char *
5596 output_movb (operands, insn, which_alternative, reverse_comparison)
5597      rtx *operands;
5598      rtx insn;
5599      int which_alternative;
5600      int reverse_comparison;
5601 {
5602
5603   /* A conditional branch to the following instruction (eg the delay slot) is
5604      asking for a disaster.  Be prepared!  */
5605
5606   if (next_active_insn (JUMP_LABEL (insn)) == next_active_insn (insn))
5607     {
5608       if (which_alternative == 0)
5609         return "copy %1,%0";
5610       else if (which_alternative == 1)
5611         {
5612           output_asm_insn ("stw %1,-16(%%r30)", operands);
5613           return "{fldws|fldw} -16(%%r30),%0";
5614         }
5615       else if (which_alternative == 2)
5616         return "stw %1,%0";
5617       else
5618         return "mtsar %r1";
5619     }
5620
5621   /* Support the second variant.  */
5622   if (reverse_comparison)
5623     PUT_CODE (operands[2], reverse_condition (GET_CODE (operands[2])));
5624
5625   if (which_alternative == 0)
5626     {
5627       int nullify = INSN_ANNULLED_BRANCH_P (insn);
5628       int length = get_attr_length (insn);
5629
5630       /* If this is a long branch with its delay slot unfilled, set `nullify'
5631          as it can nullify the delay slot and save a nop.  */
5632       if (length == 8 && dbr_sequence_length () == 0)
5633         nullify = 1;
5634
5635       /* If this is a short forward conditional branch which did not get
5636          its delay slot filled, the delay slot can still be nullified.  */
5637       if (! nullify && length == 4 && dbr_sequence_length () == 0)
5638         nullify = forward_branch_p (insn);
5639
5640       /* Handle short versions first.  */
5641       if (length == 4 && nullify)
5642         return "movb,%C2,n %1,%0,%3";
5643       else if (length == 4 && ! nullify)
5644         return "movb,%C2 %1,%0,%3";
5645       else if (length == 8)
5646         {
5647           /* Handle weird backwards branch with a filled delay slot
5648              which is nullified.  */
5649           if (dbr_sequence_length () != 0
5650               && ! forward_branch_p (insn)
5651               && nullify)
5652             return "movb,%N2,n %1,%0,.+12\n\tb %3";
5653
5654           /* Handle short backwards branch with an unfilled delay slot.
5655              Using a movb;nop rather than or;bl saves 1 cycle for both
5656              taken and untaken branches.  */
5657           else if (dbr_sequence_length () == 0
5658                    && ! forward_branch_p (insn)
5659                    && INSN_ADDRESSES_SET_P ()
5660                    && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
5661                                       - INSN_ADDRESSES (INSN_UID (insn)) - 8))
5662             return "movb,%C2 %1,%0,%3%#";
5663           /* Handle normal cases.  */
5664           if (nullify)
5665             return "or,%N2 %1,%%r0,%0\n\tb,n %3";
5666           else
5667             return "or,%N2 %1,%%r0,%0\n\tb %3";
5668         }
5669       else
5670         abort ();
5671     }
5672   /* Deal with gross reload from FP register case.  */
5673   else if (which_alternative == 1)
5674     {
5675       /* Move loop counter from FP register to MEM then into a GR,
5676          increment the GR, store the GR into MEM, and finally reload
5677          the FP register from MEM from within the branch's delay slot.  */
5678       output_asm_insn ("stw %1,-16(%%r30)", operands);
5679       if (get_attr_length (insn) == 12)
5680         return "{comb|cmpb},%S2 %%r0,%1,%3\n\t{fldws|fldw} -16(%%r30),%0";
5681       else
5682         return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
5683     }
5684   /* Deal with gross reload from memory case.  */
5685   else if (which_alternative == 2)
5686     {
5687       /* Reload loop counter from memory, the store back to memory
5688          happens in the branch's delay slot.   */
5689       if (get_attr_length (insn) == 8)
5690         return "{comb|cmpb},%S2 %%r0,%1,%3\n\tstw %1,%0";
5691       else
5692         return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tstw %1,%0";
5693     }
5694   /* Handle SAR as a destination.  */
5695   else
5696     {
5697       if (get_attr_length (insn) == 8)
5698         return "{comb|cmpb},%S2 %%r0,%1,%3\n\tmtsar %r1";
5699       else
5700         return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tbl %3\n\tmtsar %r1";
5701     }
5702 }
5703
5704
5705 /* INSN is a millicode call.  It may have an unconditional jump in its delay
5706    slot.
5707
5708    CALL_DEST is the routine we are calling.  */
5709
5710 const char *
5711 output_millicode_call (insn, call_dest)
5712   rtx insn;
5713   rtx call_dest;
5714 {
5715   int distance;
5716   rtx xoperands[4];
5717   rtx seq_insn;
5718
5719   xoperands[3] = gen_rtx_REG (Pmode, TARGET_64BIT ? 2 : 31);
5720
5721   /* Handle common case -- empty delay slot or no jump in the delay slot,
5722      and we're sure that the branch will reach the beginning of the $CODE$
5723      subspace.  */
5724   if ((dbr_sequence_length () == 0
5725        && (get_attr_length (insn) == 8 || get_attr_length (insn) == 28))
5726       || (dbr_sequence_length () != 0
5727           && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
5728           && get_attr_length (insn) == 4))
5729     {
5730       xoperands[0] = call_dest;
5731       output_asm_insn ("{bl|b,l} %0,%3%#", xoperands);
5732       return "";
5733     }
5734
5735   /* This call may not reach the beginning of the $CODE$ subspace.  */
5736   if (get_attr_length (insn) > 4)
5737     {
5738       int delay_insn_deleted = 0;
5739
5740       /* We need to emit an inline long-call branch.  */
5741       if (dbr_sequence_length () != 0
5742           && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
5743         {
5744           /* A non-jump insn in the delay slot.  By definition we can
5745              emit this insn before the call.  */
5746           final_scan_insn (NEXT_INSN (insn), asm_out_file, optimize, 0, 0);
5747
5748           /* Now delete the delay insn.  */
5749           PUT_CODE (NEXT_INSN (insn), NOTE);
5750           NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
5751           NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
5752           delay_insn_deleted = 1;
5753         }
5754
5755       /* PIC long millicode call sequence.  */
5756       if (flag_pic)
5757         {
5758           xoperands[0] = call_dest;
5759           xoperands[1] = gen_label_rtx ();
5760           /* Get our address + 8 into %r1.  */
5761           output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
5762
5763           /* Add %r1 to the offset of our target from the next insn.  */
5764           output_asm_insn ("addil L%%%0-%1,%%r1", xoperands);
5765           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
5766                                      CODE_LABEL_NUMBER (xoperands[1]));
5767           output_asm_insn ("ldo R%%%0-%1(%%r1),%%r1", xoperands);
5768
5769           /* Get the return address into %r31.  */
5770           output_asm_insn ("blr 0,%3", xoperands);
5771
5772           /* Branch to our target which is in %r1.  */
5773           output_asm_insn ("bv,n %%r0(%%r1)", xoperands);
5774
5775           /* Empty delay slot.  Note this insn gets fetched twice and
5776              executed once.  To be safe we use a nop.  */
5777           output_asm_insn ("nop", xoperands);
5778         }
5779       /* Pure portable runtime doesn't allow be/ble; we also don't have
5780          PIC support in the assembler/linker, so this sequence is needed.  */
5781       else if (TARGET_PORTABLE_RUNTIME)
5782         {
5783           xoperands[0] = call_dest;
5784           /* Get the address of our target into %r29. */
5785           output_asm_insn ("ldil L%%%0,%%r29", xoperands);
5786           output_asm_insn ("ldo R%%%0(%%r29),%%r29", xoperands);
5787
5788           /* Get our return address into %r31.  */
5789           output_asm_insn ("blr %%r0,%3", xoperands);
5790
5791           /* Jump to our target address in %r29.  */
5792           output_asm_insn ("bv,n %%r0(%%r29)", xoperands);
5793
5794           /* Empty delay slot.  Note this insn gets fetched twice and
5795              executed once.  To be safe we use a nop.  */
5796           output_asm_insn ("nop", xoperands);
5797         }
5798       /* If we're allowed to use be/ble instructions, then this is the
5799          best sequence to use for a long millicode call.  */
5800       else
5801         {
5802           xoperands[0] = call_dest;
5803           output_asm_insn ("ldil L%%%0,%3", xoperands);
5804           output_asm_insn ("{ble|be,l} R%%%0(%%sr4,%3)", xoperands);
5805           output_asm_insn ("nop", xoperands);
5806         }
5807
5808       /* If we had a jump in the call's delay slot, output it now.  */
5809       if (dbr_sequence_length () != 0
5810           && !delay_insn_deleted)
5811         {
5812           xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
5813           output_asm_insn ("b,n %0", xoperands);
5814
5815           /* Now delete the delay insn.  */
5816           PUT_CODE (NEXT_INSN (insn), NOTE);
5817           NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
5818           NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
5819         }
5820       return "";
5821     }
5822
5823   /* This call has an unconditional jump in its delay slot and the
5824      call is known to reach its target or the beginning of the current
5825      subspace.  */
5826
5827   /* Use the containing sequence insn's address.  */
5828   seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
5829
5830   distance = INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
5831                - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8;
5832
5833   /* If the branch was too far away, emit a normal call followed
5834      by a nop, followed by the unconditional branch.
5835
5836      If the branch is close, then adjust %r2 from within the
5837      call's delay slot.  */
5838
5839   xoperands[0] = call_dest;
5840   xoperands[1] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
5841   if (! VAL_14_BITS_P (distance))
5842     output_asm_insn ("{bl|b,l} %0,%3\n\tnop\n\tb,n %1", xoperands);
5843   else
5844     {
5845       xoperands[2] = gen_label_rtx ();
5846       output_asm_insn ("\n\t{bl|b,l} %0,%3\n\tldo %1-%2(%3),%3",
5847                        xoperands);
5848       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
5849                                  CODE_LABEL_NUMBER (xoperands[2]));
5850     }
5851
5852   /* Delete the jump.  */
5853   PUT_CODE (NEXT_INSN (insn), NOTE);
5854   NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
5855   NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
5856   return "";
5857 }
5858
5859 extern struct obstack permanent_obstack;
5860
5861 /* INSN is either a function call.  It may have an unconditional jump
5862    in its delay slot.
5863
5864    CALL_DEST is the routine we are calling.  */
5865
5866 const char *
5867 output_call (insn, call_dest, sibcall)
5868   rtx insn;
5869   rtx call_dest;
5870   int sibcall;
5871 {
5872   int distance;
5873   rtx xoperands[4];
5874   rtx seq_insn;
5875
5876   /* Handle common case -- empty delay slot or no jump in the delay slot,
5877      and we're sure that the branch will reach the beginning of the $CODE$
5878      subspace.  */
5879   if ((dbr_sequence_length () == 0
5880        && get_attr_length (insn) == 8)
5881       || (dbr_sequence_length () != 0
5882           && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
5883           && get_attr_length (insn) == 4))
5884     {
5885       xoperands[0] = call_dest;
5886       xoperands[1] = gen_rtx_REG (word_mode, sibcall ? 0 : 2);
5887       output_asm_insn ("{bl|b,l} %0,%1%#", xoperands);
5888       return "";
5889     }
5890
5891   /* This call may not reach the beginning of the $CODE$ subspace.  */
5892   if (get_attr_length (insn) > 8)
5893     {
5894       int delay_insn_deleted = 0;
5895       rtx xoperands[2];
5896       rtx link;
5897
5898       /* We need to emit an inline long-call branch.  Furthermore,
5899          because we're changing a named function call into an indirect
5900          function call well after the parameters have been set up, we
5901          need to make sure any FP args appear in both the integer
5902          and FP registers.  Also, we need move any delay slot insn
5903          out of the delay slot.  And finally, we can't rely on the linker
5904          being able to fix the call to $$dyncall!  -- Yuk!.  */
5905       if (dbr_sequence_length () != 0
5906           && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
5907         {
5908           /* A non-jump insn in the delay slot.  By definition we can
5909              emit this insn before the call (and in fact before argument
5910              relocating.  */
5911           final_scan_insn (NEXT_INSN (insn), asm_out_file, optimize, 0, 0);
5912
5913           /* Now delete the delay insn.  */
5914           PUT_CODE (NEXT_INSN (insn), NOTE);
5915           NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
5916           NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
5917           delay_insn_deleted = 1;
5918         }
5919
5920       /* Now copy any FP arguments into integer registers.  */
5921       for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
5922         {
5923           int arg_mode, regno;
5924           rtx use = XEXP (link, 0);
5925           if (! (GET_CODE (use) == USE
5926                  && GET_CODE (XEXP (use, 0)) == REG
5927                  && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
5928             continue;
5929
5930           arg_mode = GET_MODE (XEXP (use, 0));
5931           regno = REGNO (XEXP (use, 0));
5932           /* Is it a floating point register?  */
5933           if (regno >= 32 && regno <= 39)
5934             {
5935               /* Copy from the FP register into an integer register
5936                  (via memory).  */
5937               if (arg_mode == SFmode)
5938                 {
5939                   xoperands[0] = XEXP (use, 0);
5940                   xoperands[1] = gen_rtx_REG (SImode, 26 - (regno - 32) / 2);
5941                   output_asm_insn ("{fstws|fstw} %0,-16(%%sr0,%%r30)",
5942                                     xoperands);
5943                   output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
5944                 }
5945               else
5946                 {
5947                   xoperands[0] = XEXP (use, 0);
5948                   xoperands[1] = gen_rtx_REG (DImode, 25 - (regno - 34) / 2);
5949                   output_asm_insn ("{fstds|fstd} %0,-16(%%sr0,%%r30)",
5950                                     xoperands);
5951                   output_asm_insn ("ldw -12(%%sr0,%%r30),%R1", xoperands);
5952                   output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
5953                 }
5954             }
5955         }
5956
5957       /* Don't have to worry about TARGET_PORTABLE_RUNTIME here since
5958          we don't have any direct calls in that case.  */
5959         {
5960           int i;
5961           const char *name = XSTR (call_dest, 0);
5962
5963           /* See if we have already put this function on the list
5964              of deferred plabels.  This list is generally small,
5965              so a liner search is not too ugly.  If it proves too
5966              slow replace it with something faster.  */
5967           for (i = 0; i < n_deferred_plabels; i++)
5968             if (strcmp (name, deferred_plabels[i].name) == 0)
5969               break;
5970
5971           /* If the deferred plabel list is empty, or this entry was
5972              not found on the list, create a new entry on the list.  */
5973           if (deferred_plabels == NULL || i == n_deferred_plabels)
5974             {
5975               const char *real_name;
5976
5977               if (deferred_plabels == 0)
5978                 deferred_plabels = (struct deferred_plabel *)
5979                   xmalloc (1 * sizeof (struct deferred_plabel));
5980               else
5981                 deferred_plabels = (struct deferred_plabel *)
5982                   xrealloc (deferred_plabels,
5983                             ((n_deferred_plabels + 1)
5984                              * sizeof (struct deferred_plabel)));
5985
5986               i = n_deferred_plabels++;
5987               deferred_plabels[i].internal_label = gen_label_rtx ();
5988               deferred_plabels[i].name = obstack_alloc (&permanent_obstack,
5989                                                         strlen (name) + 1);
5990               strcpy (deferred_plabels[i].name, name);
5991
5992               /* Gross.  We have just implicitly taken the address of this
5993                  function, mark it as such.  */
5994               STRIP_NAME_ENCODING (real_name, name);
5995               TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
5996             }
5997
5998           /* We have to load the address of the function using a procedure
5999              label (plabel).  Inline plabels can lose for PIC and other
6000              cases, so avoid them by creating a 32bit plabel in the data
6001              segment.  */
6002           if (flag_pic)
6003             {
6004               xoperands[0] = deferred_plabels[i].internal_label;
6005               xoperands[1] = gen_label_rtx ();
6006
6007               output_asm_insn ("addil LT%%%0,%%r19", xoperands);
6008               output_asm_insn ("ldw RT%%%0(%%r1),%%r22", xoperands);
6009               output_asm_insn ("ldw 0(%%r22),%%r22", xoperands);
6010
6011               /* Get our address + 8 into %r1.  */
6012               output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
6013
6014               /* Add %r1 to the offset of dyncall from the next insn.  */
6015               output_asm_insn ("addil L%%$$dyncall-%1,%%r1", xoperands);
6016               ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
6017                                          CODE_LABEL_NUMBER (xoperands[1]));
6018               output_asm_insn ("ldo R%%$$dyncall-%1(%%r1),%%r1", xoperands);
6019
6020               /* Get the return address into %r31.  */
6021               output_asm_insn ("blr %%r0,%%r31", xoperands);
6022
6023               /* Branch to our target which is in %r1.  */
6024               output_asm_insn ("bv %%r0(%%r1)", xoperands);
6025
6026               if (sibcall)
6027                 {
6028                   /* This call never returns, so we do not need to fix the
6029                      return pointer.  */
6030                   output_asm_insn ("nop", xoperands);
6031                 }
6032               else
6033                 {
6034                   /* Copy the return address into %r2 also.  */
6035                   output_asm_insn ("copy %%r31,%%r2", xoperands);
6036                 }
6037             }
6038           else
6039             {
6040               xoperands[0] = deferred_plabels[i].internal_label;
6041
6042               /* Get the address of our target into %r22.  */
6043               output_asm_insn ("addil LR%%%0-$global$,%%r27", xoperands);
6044               output_asm_insn ("ldw RR%%%0-$global$(%%r1),%%r22", xoperands);
6045
6046               /* Get the high part of the  address of $dyncall into %r2, then
6047                  add in the low part in the branch instruction.  */
6048               output_asm_insn ("ldil L%%$$dyncall,%%r2", xoperands);
6049               output_asm_insn ("{ble|be,l}  R%%$$dyncall(%%sr4,%%r2)",
6050                                xoperands);
6051
6052               if (sibcall)
6053                 {
6054                   /* This call never returns, so we do not need to fix the
6055                      return pointer.  */
6056                   output_asm_insn ("nop", xoperands);
6057                 }
6058               else
6059                 {
6060                   /* Copy the return address into %r2 also.  */
6061                   output_asm_insn ("copy %%r31,%%r2", xoperands);
6062                 }
6063             }
6064         }
6065
6066       /* If we had a jump in the call's delay slot, output it now.  */
6067       if (dbr_sequence_length () != 0
6068           && !delay_insn_deleted)
6069         {
6070           xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
6071           output_asm_insn ("b,n %0", xoperands);
6072
6073           /* Now delete the delay insn.  */
6074           PUT_CODE (NEXT_INSN (insn), NOTE);
6075           NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
6076           NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
6077         }
6078       return "";
6079     }
6080
6081   /* This call has an unconditional jump in its delay slot and the
6082      call is known to reach its target or the beginning of the current
6083      subspace.  */
6084
6085   /* Use the containing sequence insn's address.  */
6086   seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
6087
6088   distance = INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
6089                - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8;
6090
6091   /* If the branch was too far away, emit a normal call followed
6092      by a nop, followed by the unconditional branch.
6093
6094      If the branch is close, then adjust %r2 from within the
6095      call's delay slot.  */
6096
6097   xoperands[0] = call_dest;
6098   xoperands[1] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
6099   if (! VAL_14_BITS_P (distance))
6100     output_asm_insn ("{bl|b,l} %0,%%r2\n\tnop\n\tb,n %1", xoperands);
6101   else
6102     {
6103       xoperands[3] = gen_label_rtx ();
6104       output_asm_insn ("\n\t{bl|b,l} %0,%%r2\n\tldo %1-%3(%%r2),%%r2",
6105                        xoperands);
6106       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
6107                                  CODE_LABEL_NUMBER (xoperands[3]));
6108     }
6109
6110   /* Delete the jump.  */
6111   PUT_CODE (NEXT_INSN (insn), NOTE);
6112   NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
6113   NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
6114   return "";
6115 }
6116
6117 /* In HPUX 8.0's shared library scheme, special relocations are needed
6118    for function labels if they might be passed to a function
6119    in a shared library (because shared libraries don't live in code
6120    space), and special magic is needed to construct their address.  */
6121
6122 void
6123 hppa_encode_label (sym)
6124      rtx sym;
6125 {
6126   const char *str = XSTR (sym, 0);
6127   int len = strlen (str) + 1;
6128   char *newstr, *p;
6129
6130   p = newstr = alloca (len + 1);
6131   if (str[0] == '*')
6132     {
6133       str++;
6134       len--;
6135     }
6136   *p++ = '@';
6137   strcpy (p, str);
6138
6139   XSTR (sym, 0) = ggc_alloc_string (newstr, len);
6140 }
6141
6142 int
6143 function_label_operand (op, mode)
6144      rtx op;
6145      enum machine_mode mode ATTRIBUTE_UNUSED;
6146 {
6147   return GET_CODE (op) == SYMBOL_REF && FUNCTION_NAME_P (XSTR (op, 0));
6148 }
6149
6150 /* Returns 1 if OP is a function label involved in a simple addition
6151    with a constant.  Used to keep certain patterns from matching
6152    during instruction combination.  */
6153 int
6154 is_function_label_plus_const (op)
6155      rtx op;
6156 {
6157   /* Strip off any CONST.  */
6158   if (GET_CODE (op) == CONST)
6159     op = XEXP (op, 0);
6160
6161   return (GET_CODE (op) == PLUS
6162           && function_label_operand (XEXP (op, 0), Pmode)
6163           && GET_CODE (XEXP (op, 1)) == CONST_INT);
6164 }
6165
6166 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
6167    use in fmpyadd instructions.  */
6168 int
6169 fmpyaddoperands (operands)
6170      rtx *operands;
6171 {
6172   enum machine_mode mode = GET_MODE (operands[0]);
6173
6174   /* Must be a floating point mode.  */
6175   if (mode != SFmode && mode != DFmode)
6176     return 0;
6177
6178   /* All modes must be the same.  */
6179   if (! (mode == GET_MODE (operands[1])
6180          && mode == GET_MODE (operands[2])
6181          && mode == GET_MODE (operands[3])
6182          && mode == GET_MODE (operands[4])
6183          && mode == GET_MODE (operands[5])))
6184     return 0;
6185
6186   /* All operands must be registers.  */
6187   if (! (GET_CODE (operands[1]) == REG
6188          && GET_CODE (operands[2]) == REG
6189          && GET_CODE (operands[3]) == REG
6190          && GET_CODE (operands[4]) == REG
6191          && GET_CODE (operands[5]) == REG))
6192     return 0;
6193
6194   /* Only 2 real operands to the addition.  One of the input operands must
6195      be the same as the output operand.  */
6196   if (! rtx_equal_p (operands[3], operands[4])
6197       && ! rtx_equal_p (operands[3], operands[5]))
6198     return 0;
6199
6200   /* Inout operand of add can not conflict with any operands from multiply.  */
6201   if (rtx_equal_p (operands[3], operands[0])
6202      || rtx_equal_p (operands[3], operands[1])
6203      || rtx_equal_p (operands[3], operands[2]))
6204     return 0;
6205
6206   /* multiply can not feed into addition operands.  */
6207   if (rtx_equal_p (operands[4], operands[0])
6208       || rtx_equal_p (operands[5], operands[0]))
6209     return 0;
6210
6211   /* SFmode limits the registers to the upper 32 of the 32bit FP regs.  */
6212   if (mode == SFmode
6213       && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
6214           || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
6215           || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
6216           || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
6217           || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
6218           || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
6219     return 0;
6220
6221   /* Passed.  Operands are suitable for fmpyadd.  */
6222   return 1;
6223 }
6224
6225 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
6226    use in fmpysub instructions.  */
6227 int
6228 fmpysuboperands (operands)
6229      rtx *operands;
6230 {
6231   enum machine_mode mode = GET_MODE (operands[0]);
6232
6233   /* Must be a floating point mode.  */
6234   if (mode != SFmode && mode != DFmode)
6235     return 0;
6236
6237   /* All modes must be the same.  */
6238   if (! (mode == GET_MODE (operands[1])
6239          && mode == GET_MODE (operands[2])
6240          && mode == GET_MODE (operands[3])
6241          && mode == GET_MODE (operands[4])
6242          && mode == GET_MODE (operands[5])))
6243     return 0;
6244
6245   /* All operands must be registers.  */
6246   if (! (GET_CODE (operands[1]) == REG
6247          && GET_CODE (operands[2]) == REG
6248          && GET_CODE (operands[3]) == REG
6249          && GET_CODE (operands[4]) == REG
6250          && GET_CODE (operands[5]) == REG))
6251     return 0;
6252
6253   /* Only 2 real operands to the subtraction.  Subtraction is not a commutative
6254      operation, so operands[4] must be the same as operand[3].  */
6255   if (! rtx_equal_p (operands[3], operands[4]))
6256     return 0;
6257
6258   /* multiply can not feed into subtraction.  */
6259   if (rtx_equal_p (operands[5], operands[0]))
6260     return 0;
6261
6262   /* Inout operand of sub can not conflict with any operands from multiply.  */
6263   if (rtx_equal_p (operands[3], operands[0])
6264      || rtx_equal_p (operands[3], operands[1])
6265      || rtx_equal_p (operands[3], operands[2]))
6266     return 0;
6267
6268   /* SFmode limits the registers to the upper 32 of the 32bit FP regs.  */
6269   if (mode == SFmode
6270       && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
6271           || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
6272           || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
6273           || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
6274           || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
6275           || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
6276     return 0;
6277
6278   /* Passed.  Operands are suitable for fmpysub.  */
6279   return 1;
6280 }
6281
6282 int
6283 plus_xor_ior_operator (op, mode)
6284      rtx op;
6285      enum machine_mode mode ATTRIBUTE_UNUSED;
6286 {
6287   return (GET_CODE (op) == PLUS || GET_CODE (op) == XOR
6288           || GET_CODE (op) == IOR);
6289 }
6290
6291 /* Return 1 if the given constant is 2, 4, or 8.  These are the valid
6292    constants for shadd instructions.  */
6293 static int
6294 shadd_constant_p (val)
6295      int val;
6296 {
6297   if (val == 2 || val == 4 || val == 8)
6298     return 1;
6299   else
6300     return 0;
6301 }
6302
6303 /* Return 1 if OP is a CONST_INT with the value 2, 4, or 8.  These are
6304    the valid constant for shadd instructions.  */
6305 int
6306 shadd_operand (op, mode)
6307      rtx op;
6308      enum machine_mode mode ATTRIBUTE_UNUSED;
6309 {
6310   return (GET_CODE (op) == CONST_INT && shadd_constant_p (INTVAL (op)));
6311 }
6312
6313 /* Return 1 if OP is valid as a base register in a reg + reg address.  */
6314
6315 int
6316 basereg_operand (op, mode)
6317      rtx op;
6318      enum machine_mode mode;
6319 {
6320   /* cse will create some unscaled indexed addresses, however; it
6321      generally isn't a win on the PA, so avoid creating unscaled
6322      indexed addresses until after cse is finished.  */
6323   if (!cse_not_expected)
6324     return 0;
6325
6326   /* Allow any register when TARGET_NO_SPACE_REGS is in effect since
6327      we don't have to worry about the braindamaged implicit space
6328      register selection from the basereg.  */
6329   if (TARGET_NO_SPACE_REGS)
6330     return (GET_CODE (op) == REG);
6331
6332   /* While it's always safe to index off the frame pointer, it's not
6333      always profitable, particularly when the frame pointer is being
6334      eliminated.  */
6335   if (! flag_omit_frame_pointer && op == frame_pointer_rtx)
6336     return 1;
6337
6338   return (GET_CODE (op) == REG
6339           && REG_POINTER (op)
6340           && register_operand (op, mode));
6341 }
6342
6343 /* Return 1 if this operand is anything other than a hard register.  */
6344
6345 int
6346 non_hard_reg_operand (op, mode)
6347      rtx op;
6348      enum machine_mode mode ATTRIBUTE_UNUSED;
6349 {
6350   return ! (GET_CODE (op) == REG && REGNO (op) < FIRST_PSEUDO_REGISTER);
6351 }
6352
6353 /* Return 1 if INSN branches forward.  Should be using insn_addresses
6354    to avoid walking through all the insns... */
6355 static int
6356 forward_branch_p (insn)
6357      rtx insn;
6358 {
6359   rtx label = JUMP_LABEL (insn);
6360
6361   while (insn)
6362     {
6363       if (insn == label)
6364         break;
6365       else
6366         insn = NEXT_INSN (insn);
6367     }
6368
6369   return (insn == label);
6370 }
6371
6372 /* Return 1 if OP is an equality comparison, else return 0.  */
6373 int
6374 eq_neq_comparison_operator (op, mode)
6375      rtx op;
6376      enum machine_mode mode ATTRIBUTE_UNUSED;
6377 {
6378   return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
6379 }
6380
6381 /* Return 1 if OP is an operator suitable for use in a movb instruction.  */
6382 int
6383 movb_comparison_operator (op, mode)
6384      rtx op;
6385      enum machine_mode mode ATTRIBUTE_UNUSED;
6386 {
6387   return (GET_CODE (op) == EQ || GET_CODE (op) == NE
6388           || GET_CODE (op) == LT || GET_CODE (op) == GE);
6389 }
6390
6391 /* Return 1 if INSN is in the delay slot of a call instruction.  */
6392 int
6393 jump_in_call_delay (insn)
6394      rtx insn;
6395 {
6396
6397   if (GET_CODE (insn) != JUMP_INSN)
6398     return 0;
6399
6400   if (PREV_INSN (insn)
6401       && PREV_INSN (PREV_INSN (insn))
6402       && GET_CODE (next_active_insn (PREV_INSN (PREV_INSN (insn)))) == INSN)
6403     {
6404       rtx test_insn = next_active_insn (PREV_INSN (PREV_INSN (insn)));
6405
6406       return (GET_CODE (PATTERN (test_insn)) == SEQUENCE
6407               && XVECEXP (PATTERN (test_insn), 0, 1) == insn);
6408
6409     }
6410   else
6411     return 0;
6412 }
6413
6414 /* Output an unconditional move and branch insn.  */
6415
6416 const char *
6417 output_parallel_movb (operands, length)
6418      rtx *operands;
6419      int length;
6420 {
6421   /* These are the cases in which we win.  */
6422   if (length == 4)
6423     return "mov%I1b,tr %1,%0,%2";
6424
6425   /* None of these cases wins, but they don't lose either.  */
6426   if (dbr_sequence_length () == 0)
6427     {
6428       /* Nothing in the delay slot, fake it by putting the combined
6429          insn (the copy or add) in the delay slot of a bl.  */
6430       if (GET_CODE (operands[1]) == CONST_INT)
6431         return "b %2\n\tldi %1,%0";
6432       else
6433         return "b %2\n\tcopy %1,%0";
6434     }
6435   else
6436     {
6437       /* Something in the delay slot, but we've got a long branch.  */
6438       if (GET_CODE (operands[1]) == CONST_INT)
6439         return "ldi %1,%0\n\tb %2";
6440       else
6441         return "copy %1,%0\n\tb %2";
6442     }
6443 }
6444
6445 /* Output an unconditional add and branch insn.  */
6446
6447 const char *
6448 output_parallel_addb (operands, length)
6449      rtx *operands;
6450      int length;
6451 {
6452   /* To make life easy we want operand0 to be the shared input/output
6453      operand and operand1 to be the readonly operand.  */
6454   if (operands[0] == operands[1])
6455     operands[1] = operands[2];
6456
6457   /* These are the cases in which we win.  */
6458   if (length == 4)
6459     return "add%I1b,tr %1,%0,%3";
6460
6461   /* None of these cases win, but they don't lose either.  */
6462   if (dbr_sequence_length () == 0)
6463     {
6464       /* Nothing in the delay slot, fake it by putting the combined
6465          insn (the copy or add) in the delay slot of a bl.  */
6466       return "b %3\n\tadd%I1 %1,%0,%0";
6467     }
6468   else
6469     {
6470       /* Something in the delay slot, but we've got a long branch.  */
6471       return "add%I1 %1,%0,%0\n\tb %3";
6472     }
6473 }
6474
6475 /* Return nonzero if INSN (a jump insn) immediately follows a call to
6476    a named function.  This is used to discourage creating parallel movb/addb
6477    insns since a jump which immediately follows a call can execute in the
6478    delay slot of the call.
6479
6480    It is also used to avoid filling the delay slot of a jump which
6481    immediately follows a call since the jump can usually be eliminated
6482    completely by modifying RP in the delay slot of the call.  */
6483
6484 int
6485 following_call (insn)
6486      rtx insn;
6487 {
6488   /* We do not parallel movb,addb or place jumps into call delay slots when
6489      optimizing for the PA8000.  */
6490   if (pa_cpu != PROCESSOR_8000)
6491     return 0;
6492
6493   /* Find the previous real insn, skipping NOTEs.  */
6494   insn = PREV_INSN (insn);
6495   while (insn && GET_CODE (insn) == NOTE)
6496     insn = PREV_INSN (insn);
6497
6498   /* Check for CALL_INSNs and millicode calls.  */
6499   if (insn
6500       && ((GET_CODE (insn) == CALL_INSN
6501            && get_attr_type (insn) != TYPE_DYNCALL)
6502           || (GET_CODE (insn) == INSN
6503               && GET_CODE (PATTERN (insn)) != SEQUENCE
6504               && GET_CODE (PATTERN (insn)) != USE
6505               && GET_CODE (PATTERN (insn)) != CLOBBER
6506               && get_attr_type (insn) == TYPE_MILLI)))
6507     return 1;
6508
6509   return 0;
6510 }
6511
6512 /* We use this hook to perform a PA specific optimization which is difficult
6513    to do in earlier passes.
6514
6515    We want the delay slots of branches within jump tables to be filled.
6516    None of the compiler passes at the moment even has the notion that a
6517    PA jump table doesn't contain addresses, but instead contains actual
6518    instructions!
6519
6520    Because we actually jump into the table, the addresses of each entry
6521    must stay constant in relation to the beginning of the table (which
6522    itself must stay constant relative to the instruction to jump into
6523    it).  I don't believe we can guarantee earlier passes of the compiler
6524    will adhere to those rules.
6525
6526    So, late in the compilation process we find all the jump tables, and
6527    expand them into real code -- eg each entry in the jump table vector
6528    will get an appropriate label followed by a jump to the final target.
6529
6530    Reorg and the final jump pass can then optimize these branches and
6531    fill their delay slots.  We end up with smaller, more efficient code.
6532
6533    The jump instructions within the table are special; we must be able
6534    to identify them during assembly output (if the jumps don't get filled
6535    we need to emit a nop rather than nullifying the delay slot)).  We
6536    identify jumps in switch tables by marking the SET with DImode.
6537
6538    We also surround the jump table itself with BEGIN_BRTAB and END_BRTAB
6539    insns.  This serves two purposes, first it prevents jump.c from
6540    noticing that the last N entries in the table jump to the instruction
6541    immediately after the table and deleting the jumps.  Second, those
6542    insns mark where we should emit .begin_brtab and .end_brtab directives
6543    when using GAS (allows for better link time optimizations).  */
6544
6545 void
6546 pa_reorg (insns)
6547      rtx insns;
6548 {
6549   rtx insn;
6550
6551   remove_useless_addtr_insns (insns, 1);
6552
6553   if (pa_cpu < PROCESSOR_8000)
6554     pa_combine_instructions (get_insns ());
6555
6556
6557   /* This is fairly cheap, so always run it if optimizing.  */
6558   if (optimize > 0 && !TARGET_BIG_SWITCH)
6559     {
6560       /* Find and explode all ADDR_VEC or ADDR_DIFF_VEC insns.  */
6561       insns = get_insns ();
6562       for (insn = insns; insn; insn = NEXT_INSN (insn))
6563         {
6564           rtx pattern, tmp, location;
6565           unsigned int length, i;
6566
6567           /* Find an ADDR_VEC or ADDR_DIFF_VEC insn to explode.  */
6568           if (GET_CODE (insn) != JUMP_INSN
6569               || (GET_CODE (PATTERN (insn)) != ADDR_VEC
6570                   && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
6571             continue;
6572
6573           /* Emit marker for the beginning of the branch table.  */
6574           emit_insn_before (gen_begin_brtab (), insn);
6575
6576           pattern = PATTERN (insn);
6577           location = PREV_INSN (insn);
6578           length = XVECLEN (pattern, GET_CODE (pattern) == ADDR_DIFF_VEC);
6579
6580           for (i = 0; i < length; i++)
6581             {
6582               /* Emit a label before each jump to keep jump.c from
6583                  removing this code.  */
6584               tmp = gen_label_rtx ();
6585               LABEL_NUSES (tmp) = 1;
6586               emit_label_after (tmp, location);
6587               location = NEXT_INSN (location);
6588
6589               if (GET_CODE (pattern) == ADDR_VEC)
6590                 {
6591                   /* Emit the jump itself.  */
6592                   tmp = gen_jump (XEXP (XVECEXP (pattern, 0, i), 0));
6593                   tmp = emit_jump_insn_after (tmp, location);
6594                   JUMP_LABEL (tmp) = XEXP (XVECEXP (pattern, 0, i), 0);
6595                   /* It is easy to rely on the branch table markers
6596                      during assembly output to trigger the correct code
6597                      for a switch table jump with an unfilled delay slot,
6598
6599                      However, that requires state and assumes that we look
6600                      at insns in order.
6601
6602                      We can't make such assumptions when computing the length
6603                      of instructions.  Ugh.  We could walk the insn chain to
6604                      determine if this instruction is in a branch table, but
6605                      that can get rather expensive, particularly during the
6606                      branch shortening phase of the compiler.
6607
6608                      So instead we mark this jump as being special.  This is
6609                      far from ideal and knows that no code after this will
6610                      muck around with the mode of the JUMP_INSN itself.  */
6611                   PUT_MODE (tmp, SImode);
6612                   LABEL_NUSES (JUMP_LABEL (tmp))++;
6613                   location = NEXT_INSN (location);
6614                 }
6615               else
6616                 {
6617                   /* Emit the jump itself.  */
6618                   tmp = gen_jump (XEXP (XVECEXP (pattern, 1, i), 0));
6619                   tmp = emit_jump_insn_after (tmp, location);
6620                   JUMP_LABEL (tmp) = XEXP (XVECEXP (pattern, 1, i), 0);
6621                   /* It is easy to rely on the branch table markers
6622                      during assembly output to trigger the correct code
6623                      for a switch table jump with an unfilled delay slot,
6624
6625                      However, that requires state and assumes that we look
6626                      at insns in order.
6627
6628                      We can't make such assumptions when computing the length
6629                      of instructions.  Ugh.  We could walk the insn chain to
6630                      determine if this instruction is in a branch table, but
6631                      that can get rather expensive, particularly during the
6632                      branch shortening phase of the compiler.
6633
6634                      So instead we mark this jump as being special.  This is
6635                      far from ideal and knows that no code after this will
6636                      muck around with the mode of the JUMP_INSN itself.  */
6637                   PUT_MODE (tmp, SImode);
6638                   LABEL_NUSES (JUMP_LABEL (tmp))++;
6639                   location = NEXT_INSN (location);
6640                 }
6641
6642               /* Emit a BARRIER after the jump.  */
6643               emit_barrier_after (location);
6644               location = NEXT_INSN (location);
6645             }
6646
6647           /* Emit marker for the end of the branch table.  */
6648           emit_insn_before (gen_end_brtab (), location);
6649           location = NEXT_INSN (location);
6650           emit_barrier_after (location);
6651
6652           /* Delete the ADDR_VEC or ADDR_DIFF_VEC.  */
6653           delete_insn (insn);
6654         }
6655     }
6656   else
6657     {
6658       /* Sill need an end_brtab insn.  */
6659       insns = get_insns ();
6660       for (insn = insns; insn; insn = NEXT_INSN (insn))
6661         {
6662           /* Find an ADDR_VEC insn.  */
6663           if (GET_CODE (insn) != JUMP_INSN
6664               || (GET_CODE (PATTERN (insn)) != ADDR_VEC
6665                   && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
6666             continue;
6667
6668           /* Now generate markers for the beginning and end of the
6669              branch table.  */
6670           emit_insn_before (gen_begin_brtab (), insn);
6671           emit_insn_after (gen_end_brtab (), insn);
6672         }
6673     }
6674 }
6675
6676 /* The PA has a number of odd instructions which can perform multiple
6677    tasks at once.  On first generation PA machines (PA1.0 and PA1.1)
6678    it may be profitable to combine two instructions into one instruction
6679    with two outputs.  It's not profitable PA2.0 machines because the
6680    two outputs would take two slots in the reorder buffers.
6681
6682    This routine finds instructions which can be combined and combines
6683    them.  We only support some of the potential combinations, and we
6684    only try common ways to find suitable instructions.
6685
6686       * addb can add two registers or a register and a small integer
6687       and jump to a nearby (+-8k) location.  Normally the jump to the
6688       nearby location is conditional on the result of the add, but by
6689       using the "true" condition we can make the jump unconditional.
6690       Thus addb can perform two independent operations in one insn.
6691
6692       * movb is similar to addb in that it can perform a reg->reg
6693       or small immediate->reg copy and jump to a nearby (+-8k location).
6694
6695       * fmpyadd and fmpysub can perform a FP multiply and either an
6696       FP add or FP sub if the operands of the multiply and add/sub are
6697       independent (there are other minor restrictions).  Note both
6698       the fmpy and fadd/fsub can in theory move to better spots according
6699       to data dependencies, but for now we require the fmpy stay at a
6700       fixed location.
6701
6702       * Many of the memory operations can perform pre & post updates
6703       of index registers.  GCC's pre/post increment/decrement addressing
6704       is far too simple to take advantage of all the possibilities.  This
6705       pass may not be suitable since those insns may not be independent.
6706
6707       * comclr can compare two ints or an int and a register, nullify
6708       the following instruction and zero some other register.  This
6709       is more difficult to use as it's harder to find an insn which
6710       will generate a comclr than finding something like an unconditional
6711       branch.  (conditional moves & long branches create comclr insns).
6712
6713       * Most arithmetic operations can conditionally skip the next
6714       instruction.  They can be viewed as "perform this operation
6715       and conditionally jump to this nearby location" (where nearby
6716       is an insns away).  These are difficult to use due to the
6717       branch length restrictions.  */
6718
6719 static void
6720 pa_combine_instructions (insns)
6721      rtx insns ATTRIBUTE_UNUSED;
6722 {
6723   rtx anchor, new;
6724
6725   /* This can get expensive since the basic algorithm is on the
6726      order of O(n^2) (or worse).  Only do it for -O2 or higher
6727      levels of optimization.  */
6728   if (optimize < 2)
6729     return;
6730
6731   /* Walk down the list of insns looking for "anchor" insns which
6732      may be combined with "floating" insns.  As the name implies,
6733      "anchor" instructions don't move, while "floating" insns may
6734      move around.  */
6735   new = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, NULL_RTX, NULL_RTX));
6736   new = make_insn_raw (new);
6737
6738   for (anchor = get_insns (); anchor; anchor = NEXT_INSN (anchor))
6739     {
6740       enum attr_pa_combine_type anchor_attr;
6741       enum attr_pa_combine_type floater_attr;
6742
6743       /* We only care about INSNs, JUMP_INSNs, and CALL_INSNs.
6744          Also ignore any special USE insns.  */
6745       if ((GET_CODE (anchor) != INSN
6746           && GET_CODE (anchor) != JUMP_INSN
6747           && GET_CODE (anchor) != CALL_INSN)
6748           || GET_CODE (PATTERN (anchor)) == USE
6749           || GET_CODE (PATTERN (anchor)) == CLOBBER
6750           || GET_CODE (PATTERN (anchor)) == ADDR_VEC
6751           || GET_CODE (PATTERN (anchor)) == ADDR_DIFF_VEC)
6752         continue;
6753
6754       anchor_attr = get_attr_pa_combine_type (anchor);
6755       /* See if anchor is an insn suitable for combination.  */
6756       if (anchor_attr == PA_COMBINE_TYPE_FMPY
6757           || anchor_attr == PA_COMBINE_TYPE_FADDSUB
6758           || (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
6759               && ! forward_branch_p (anchor)))
6760         {
6761           rtx floater;
6762
6763           for (floater = PREV_INSN (anchor);
6764                floater;
6765                floater = PREV_INSN (floater))
6766             {
6767               if (GET_CODE (floater) == NOTE
6768                   || (GET_CODE (floater) == INSN
6769                       && (GET_CODE (PATTERN (floater)) == USE
6770                           || GET_CODE (PATTERN (floater)) == CLOBBER)))
6771                 continue;
6772
6773               /* Anything except a regular INSN will stop our search.  */
6774               if (GET_CODE (floater) != INSN
6775                   || GET_CODE (PATTERN (floater)) == ADDR_VEC
6776                   || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
6777                 {
6778                   floater = NULL_RTX;
6779                   break;
6780                 }
6781
6782               /* See if FLOATER is suitable for combination with the
6783                  anchor.  */
6784               floater_attr = get_attr_pa_combine_type (floater);
6785               if ((anchor_attr == PA_COMBINE_TYPE_FMPY
6786                    && floater_attr == PA_COMBINE_TYPE_FADDSUB)
6787                   || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
6788                       && floater_attr == PA_COMBINE_TYPE_FMPY))
6789                 {
6790                   /* If ANCHOR and FLOATER can be combined, then we're
6791                      done with this pass.  */
6792                   if (pa_can_combine_p (new, anchor, floater, 0,
6793                                         SET_DEST (PATTERN (floater)),
6794                                         XEXP (SET_SRC (PATTERN (floater)), 0),
6795                                         XEXP (SET_SRC (PATTERN (floater)), 1)))
6796                     break;
6797                 }
6798
6799               else if (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
6800                        && floater_attr == PA_COMBINE_TYPE_ADDMOVE)
6801                 {
6802                   if (GET_CODE (SET_SRC (PATTERN (floater))) == PLUS)
6803                     {
6804                       if (pa_can_combine_p (new, anchor, floater, 0,
6805                                             SET_DEST (PATTERN (floater)),
6806                                         XEXP (SET_SRC (PATTERN (floater)), 0),
6807                                         XEXP (SET_SRC (PATTERN (floater)), 1)))
6808                         break;
6809                     }
6810                   else
6811                     {
6812                       if (pa_can_combine_p (new, anchor, floater, 0,
6813                                             SET_DEST (PATTERN (floater)),
6814                                             SET_SRC (PATTERN (floater)),
6815                                             SET_SRC (PATTERN (floater))))
6816                         break;
6817                     }
6818                 }
6819             }
6820
6821           /* If we didn't find anything on the backwards scan try forwards.  */
6822           if (!floater
6823               && (anchor_attr == PA_COMBINE_TYPE_FMPY
6824                   || anchor_attr == PA_COMBINE_TYPE_FADDSUB))
6825             {
6826               for (floater = anchor; floater; floater = NEXT_INSN (floater))
6827                 {
6828                   if (GET_CODE (floater) == NOTE
6829                       || (GET_CODE (floater) == INSN
6830                           && (GET_CODE (PATTERN (floater)) == USE
6831                               || GET_CODE (PATTERN (floater)) == CLOBBER)))
6832
6833                     continue;
6834
6835                   /* Anything except a regular INSN will stop our search.  */
6836                   if (GET_CODE (floater) != INSN
6837                       || GET_CODE (PATTERN (floater)) == ADDR_VEC
6838                       || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
6839                     {
6840                       floater = NULL_RTX;
6841                       break;
6842                     }
6843
6844                   /* See if FLOATER is suitable for combination with the
6845                      anchor.  */
6846                   floater_attr = get_attr_pa_combine_type (floater);
6847                   if ((anchor_attr == PA_COMBINE_TYPE_FMPY
6848                        && floater_attr == PA_COMBINE_TYPE_FADDSUB)
6849                       || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
6850                           && floater_attr == PA_COMBINE_TYPE_FMPY))
6851                     {
6852                       /* If ANCHOR and FLOATER can be combined, then we're
6853                          done with this pass.  */
6854                       if (pa_can_combine_p (new, anchor, floater, 1,
6855                                             SET_DEST (PATTERN (floater)),
6856                                             XEXP (SET_SRC (PATTERN (floater)),
6857                                                   0),
6858                                             XEXP (SET_SRC (PATTERN (floater)),
6859                                                   1)))
6860                         break;
6861                     }
6862                 }
6863             }
6864
6865           /* FLOATER will be nonzero if we found a suitable floating
6866              insn for combination with ANCHOR.  */
6867           if (floater
6868               && (anchor_attr == PA_COMBINE_TYPE_FADDSUB
6869                   || anchor_attr == PA_COMBINE_TYPE_FMPY))
6870             {
6871               /* Emit the new instruction and delete the old anchor.  */
6872               emit_insn_before (gen_rtx_PARALLEL
6873                                 (VOIDmode,
6874                                  gen_rtvec (2, PATTERN (anchor),
6875                                             PATTERN (floater))),
6876                                 anchor);
6877
6878               PUT_CODE (anchor, NOTE);
6879               NOTE_LINE_NUMBER (anchor) = NOTE_INSN_DELETED;
6880               NOTE_SOURCE_FILE (anchor) = 0;
6881
6882               /* Emit a special USE insn for FLOATER, then delete
6883                  the floating insn.  */
6884               emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
6885               delete_insn (floater);
6886
6887               continue;
6888             }
6889           else if (floater
6890                    && anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH)
6891             {
6892               rtx temp;
6893               /* Emit the new_jump instruction and delete the old anchor.  */
6894               temp
6895                 = emit_jump_insn_before (gen_rtx_PARALLEL
6896                                          (VOIDmode,
6897                                           gen_rtvec (2, PATTERN (anchor),
6898                                                      PATTERN (floater))),
6899                                          anchor);
6900
6901               JUMP_LABEL (temp) = JUMP_LABEL (anchor);
6902               PUT_CODE (anchor, NOTE);
6903               NOTE_LINE_NUMBER (anchor) = NOTE_INSN_DELETED;
6904               NOTE_SOURCE_FILE (anchor) = 0;
6905
6906               /* Emit a special USE insn for FLOATER, then delete
6907                  the floating insn.  */
6908               emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
6909               delete_insn (floater);
6910               continue;
6911             }
6912         }
6913     }
6914 }
6915
6916 static int
6917 pa_can_combine_p (new, anchor, floater, reversed, dest, src1, src2)
6918      rtx new, anchor, floater;
6919      int reversed;
6920      rtx dest, src1, src2;
6921 {
6922   int insn_code_number;
6923   rtx start, end;
6924
6925   /* Create a PARALLEL with the patterns of ANCHOR and
6926      FLOATER, try to recognize it, then test constraints
6927      for the resulting pattern.
6928
6929      If the pattern doesn't match or the constraints
6930      aren't met keep searching for a suitable floater
6931      insn.  */
6932   XVECEXP (PATTERN (new), 0, 0) = PATTERN (anchor);
6933   XVECEXP (PATTERN (new), 0, 1) = PATTERN (floater);
6934   INSN_CODE (new) = -1;
6935   insn_code_number = recog_memoized (new);
6936   if (insn_code_number < 0
6937       || !constrain_operands (1))
6938     return 0;
6939
6940   if (reversed)
6941     {
6942       start = anchor;
6943       end = floater;
6944     }
6945   else
6946     {
6947       start = floater;
6948       end = anchor;
6949     }
6950
6951   /* There's up to three operands to consider.  One
6952      output and two inputs.
6953
6954      The output must not be used between FLOATER & ANCHOR
6955      exclusive.  The inputs must not be set between
6956      FLOATER and ANCHOR exclusive.  */
6957
6958   if (reg_used_between_p (dest, start, end))
6959     return 0;
6960
6961   if (reg_set_between_p (src1, start, end))
6962     return 0;
6963
6964   if (reg_set_between_p (src2, start, end))
6965     return 0;
6966
6967   /* If we get here, then everything is good.  */
6968   return 1;
6969 }
6970
6971 /* Return nonzero if references for INSN are delayed.
6972
6973    Millicode insns are actually function calls with some special
6974    constraints on arguments and register usage.
6975
6976    Millicode calls always expect their arguments in the integer argument
6977    registers, and always return their result in %r29 (ret1).  They
6978    are expected to clobber their arguments, %r1, %r29, and the return
6979    pointer which is %r31 on 32-bit and %r2 on 64-bit, and nothing else.
6980
6981    This function tells reorg that the references to arguments and
6982    millicode calls do not appear to happen until after the millicode call.
6983    This allows reorg to put insns which set the argument registers into the
6984    delay slot of the millicode call -- thus they act more like traditional
6985    CALL_INSNs.
6986
6987    Note we can not consider side effects of the insn to be delayed because
6988    the branch and link insn will clobber the return pointer.  If we happened
6989    to use the return pointer in the delay slot of the call, then we lose.
6990
6991    get_attr_type will try to recognize the given insn, so make sure to
6992    filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
6993    in particular.  */
6994 int
6995 insn_refs_are_delayed (insn)
6996      rtx insn;
6997 {
6998   return ((GET_CODE (insn) == INSN
6999            && GET_CODE (PATTERN (insn)) != SEQUENCE
7000            && GET_CODE (PATTERN (insn)) != USE
7001            && GET_CODE (PATTERN (insn)) != CLOBBER
7002            && get_attr_type (insn) == TYPE_MILLI));
7003 }
7004
7005 /* Return the location of a parameter that is passed in a register or NULL
7006    if the parameter has any component that is passed in memory.
7007
7008    This is new code and will be pushed to into the net sources after
7009    further testing.
7010
7011    ??? We might want to restructure this so that it looks more like other
7012    ports.  */
7013 rtx
7014 function_arg (cum, mode, type, named, incoming)
7015      CUMULATIVE_ARGS *cum;
7016      enum machine_mode mode;
7017      tree type;
7018      int named ATTRIBUTE_UNUSED;
7019      int incoming;
7020 {
7021   int max_arg_words = (TARGET_64BIT ? 8 : 4);
7022   int fpr_reg_base;
7023   int gpr_reg_base;
7024   rtx retval;
7025
7026   if (! TARGET_64BIT)
7027     {
7028       /* If this arg would be passed partially or totally on the stack, then
7029          this routine should return zero.  FUNCTION_ARG_PARTIAL_NREGS will
7030          handle arguments which are split between regs and stack slots if
7031          the ABI mandates split arguments.  */
7032       if (cum->words + FUNCTION_ARG_SIZE (mode, type) > max_arg_words
7033           || mode == VOIDmode)
7034         return NULL_RTX;
7035     }
7036   else
7037     {
7038       int offset = 0;
7039       if (FUNCTION_ARG_SIZE (mode, type) > 1 && (cum->words & 1))
7040         offset = 1;
7041       if (cum->words + offset >= max_arg_words
7042           || mode == VOIDmode)
7043         return NULL_RTX;
7044     }
7045
7046   /* The 32bit ABIs and the 64bit ABIs are rather different,
7047      particularly in their handling of FP registers.  We might
7048      be able to cleverly share code between them, but I'm not
7049      going to bother in the hope that splitting them up results
7050      in code that is more easily understood.
7051
7052      The 64bit code probably is very wrong for structure passing.  */
7053   if (TARGET_64BIT)
7054     {
7055       /* Advance the base registers to their current locations.
7056
7057          Remember, gprs grow towards smaller register numbers while
7058          fprs grow to higher register numbers.  Also remember FP regs
7059          are always 4 bytes wide, while the size of an integer register
7060          varies based on the size of the target word.  */
7061       gpr_reg_base = 26 - cum->words;
7062       fpr_reg_base = 32 + cum->words;
7063
7064       /* If the argument is more than a word long, then we need to align
7065          the base registers.  Same caveats as above.  */
7066       if (FUNCTION_ARG_SIZE (mode, type) > 1)
7067         {
7068           if (mode != BLKmode)
7069             {
7070               /* First deal with alignment of the doubleword.  */
7071               gpr_reg_base -= (cum->words & 1);
7072
7073               /* This seems backwards, but it is what HP specifies.  We need
7074                  gpr_reg_base to point to the smaller numbered register of
7075                  the integer register pair.  So if we have an even register
7076                   number, then decrement the gpr base.  */
7077               gpr_reg_base -= ((gpr_reg_base % 2) == 0);
7078
7079               /* FP values behave sanely, except that each FP reg is only
7080                  half of word.  */
7081               fpr_reg_base += ((fpr_reg_base % 2) == 0);
7082             }
7083           else
7084             {
7085               rtx loc[8];
7086               int i, offset = 0, ub;
7087               ub = FUNCTION_ARG_SIZE (mode, type);
7088               ub = MIN (ub,
7089                         MAX (0, max_arg_words - cum->words - (cum->words & 1)));
7090               gpr_reg_base -= (cum->words & 1);
7091               for (i = 0; i < ub; i++)
7092                 {
7093                   loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
7094                                               gen_rtx_REG (DImode,
7095                                                            gpr_reg_base),
7096                                               GEN_INT (offset));
7097                   gpr_reg_base -= 1;
7098                   offset += 8;
7099                 }
7100               if (ub == 0)
7101                 return NULL_RTX;
7102               else if (ub == 1)
7103                 return XEXP (loc[0], 0);
7104               else
7105                 return gen_rtx_PARALLEL (mode, gen_rtvec_v (ub, loc));
7106             }
7107         }
7108     }
7109   else
7110     {
7111       /* If the argument is larger than a word, then we know precisely
7112          which registers we must use.  */
7113       if (FUNCTION_ARG_SIZE (mode, type) > 1)
7114         {
7115           if (cum->words)
7116             {
7117               gpr_reg_base = 23;
7118               fpr_reg_base = 38;
7119             }
7120           else
7121             {
7122               gpr_reg_base = 25;
7123               fpr_reg_base = 34;
7124             }
7125         }
7126       else
7127         {
7128            /* We have a single word (32 bits).  A simple computation
7129               will get us the register #s we need.  */
7130            gpr_reg_base = 26 - cum->words;
7131            fpr_reg_base = 32 + 2 * cum->words;
7132         }
7133     }
7134
7135   if (TARGET_64BIT && mode == TFmode)
7136     {
7137       return
7138         gen_rtx_PARALLEL
7139           (mode,
7140            gen_rtvec (2,
7141                       gen_rtx_EXPR_LIST (VOIDmode,
7142                                          gen_rtx_REG (DImode, gpr_reg_base + 1),
7143                                          const0_rtx),
7144                       gen_rtx_EXPR_LIST (VOIDmode,
7145                                          gen_rtx_REG (DImode, gpr_reg_base),
7146                                          GEN_INT (8))));
7147     }
7148   /* Determine if the argument needs to be passed in both general and
7149      floating point registers.  */
7150   if (((TARGET_PORTABLE_RUNTIME || TARGET_64BIT || TARGET_ELF32)
7151        /* If we are doing soft-float with portable runtime, then there
7152           is no need to worry about FP regs.  */
7153        && ! TARGET_SOFT_FLOAT
7154        /* The parameter must be some kind of float, else we can just
7155           pass it in integer registers.  */
7156        && FLOAT_MODE_P (mode)
7157        /* The target function must not have a prototype.  */
7158        && cum->nargs_prototype <= 0
7159        /* libcalls do not need to pass items in both FP and general
7160           registers.  */
7161        && type != NULL_TREE
7162        /* All this hair applies to outgoing args only.  */
7163        && ! incoming)
7164       /* Also pass outgoing floating arguments in both registers in indirect
7165          calls with the 32 bit ABI and the HP assembler since there is no
7166          way to the specify argument locations in static functions.  */
7167       || (! TARGET_64BIT
7168           && ! TARGET_GAS
7169           && ! incoming
7170           && cum->indirect
7171           && FLOAT_MODE_P (mode)))
7172     {
7173       retval
7174         = gen_rtx_PARALLEL
7175             (mode,
7176              gen_rtvec (2,
7177                         gen_rtx_EXPR_LIST (VOIDmode,
7178                                            gen_rtx_REG (mode, fpr_reg_base),
7179                                            const0_rtx),
7180                         gen_rtx_EXPR_LIST (VOIDmode,
7181                                            gen_rtx_REG (mode, gpr_reg_base),
7182                                            const0_rtx)));
7183     }
7184   else
7185     {
7186       /* See if we should pass this parameter in a general register.  */
7187       if (TARGET_SOFT_FLOAT
7188           /* Indirect calls in the normal 32bit ABI require all arguments
7189              to be passed in general registers.  */
7190           || (!TARGET_PORTABLE_RUNTIME
7191               && !TARGET_64BIT
7192               && cum->indirect)
7193           /* If the parameter is not a floating point parameter, then
7194              it belongs in GPRs.  */
7195           || !FLOAT_MODE_P (mode))
7196         retval = gen_rtx_REG (mode, gpr_reg_base);
7197       else
7198         retval = gen_rtx_REG (mode, fpr_reg_base);
7199     }
7200   return retval;
7201 }
7202
7203
7204 /* If this arg would be passed totally in registers or totally on the stack,
7205    then this routine should return zero. It is currently called only for
7206    the 64-bit target. */
7207 int
7208 function_arg_partial_nregs (cum, mode, type, named)
7209      CUMULATIVE_ARGS *cum;
7210      enum machine_mode mode;
7211      tree type;
7212      int named ATTRIBUTE_UNUSED;
7213 {
7214   unsigned int max_arg_words = 8;
7215   unsigned int offset = 0;
7216
7217   if (FUNCTION_ARG_SIZE (mode, type) > 1 && (cum->words & 1))
7218     offset = 1;
7219
7220   if (cum->words + offset + FUNCTION_ARG_SIZE (mode, type) <= max_arg_words)
7221     /* Arg fits fully into registers. */
7222     return 0;
7223   else if (cum->words + offset >= max_arg_words)
7224     /* Arg fully on the stack. */
7225     return 0;
7226   else
7227     /* Arg is split. */
7228     return max_arg_words - cum->words - offset;
7229 }
7230
7231
7232 /* Return 1 if this is a comparison operator.  This allows the use of
7233    MATCH_OPERATOR to recognize all the branch insns.  */
7234
7235 int
7236 cmpib_comparison_operator (op, mode)
7237     register rtx op;
7238     enum machine_mode mode;
7239 {
7240   return ((mode == VOIDmode || GET_MODE (op) == mode)
7241           && (GET_CODE (op) == EQ
7242               || GET_CODE (op) == NE
7243               || GET_CODE (op) == GT
7244               || GET_CODE (op) == GTU
7245               || GET_CODE (op) == GE
7246               || GET_CODE (op) == LT
7247               || GET_CODE (op) == LE
7248               || GET_CODE (op) == LEU));
7249 }
7250
7251 /* Mark ARG (which is really a struct deferred_plabel **) for GC.  */
7252
7253 static void
7254 mark_deferred_plabels (arg)
7255      void *arg;
7256 {
7257   struct deferred_plabel *dp = *(struct deferred_plabel **) arg;
7258   int i;
7259
7260   for (i = 0; i < n_deferred_plabels; ++i)
7261     ggc_mark_rtx (dp[i].internal_label);
7262 }
7263
7264 /* Called to register all of our global variables with the garbage
7265    collector.  */
7266
7267 static void
7268 pa_add_gc_roots ()
7269 {
7270   ggc_add_rtx_root (&hppa_compare_op0, 1);
7271   ggc_add_rtx_root (&hppa_compare_op1, 1);
7272   ggc_add_root (&deferred_plabels, 1, sizeof (&deferred_plabels),
7273                 &mark_deferred_plabels);
7274 }