Add new parameter to move_block_from_reg calls.
[gcc.git] / gcc / config / pa / pa.c
1 /* Subroutines for insn-output.c for HPPA.
2 Copyright (C) 1992 Free Software Foundation, Inc.
3 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include <stdio.h>
22 #include "config.h"
23 #include "rtl.h"
24 #include "regs.h"
25 #include "hard-reg-set.h"
26 #include "real.h"
27 #include "insn-config.h"
28 #include "conditions.h"
29 #include "insn-flags.h"
30 #include "output.h"
31 #include "insn-attr.h"
32 #include "flags.h"
33 #include "tree.h"
34 #include "c-tree.h"
35 #include "expr.h"
36 #include "obstack.h"
37
38 /* Save the operands last given to a compare for use when we
39 generate a scc or bcc insn. */
40
41 rtx hppa_compare_op0, hppa_compare_op1;
42 enum cmp_type hppa_branch_type;
43
44 rtx hppa_save_pic_table_rtx;
45
46 /* Set by the FUNCTION_PROFILER macro. */
47 int hp_profile_labelno;
48
49 static rtx find_addr_reg ();
50
51 /* Return non-zero only if OP is a register of mode MODE,
52 or CONST0_RTX. */
53 int
54 reg_or_0_operand (op, mode)
55 rtx op;
56 enum machine_mode mode;
57 {
58 return (op == CONST0_RTX (mode) || register_operand (op, mode));
59 }
60
61 /* Return non-zero if OP is suitable for use in a call to a named
62 function.
63
64 (???) For 2.5 try to eliminate either call_operand_address or
65 function_label_operand, they perform very similar functions. */
66 int
67 call_operand_address (op, mode)
68 rtx op;
69 enum machine_mode mode;
70 {
71 return (CONSTANT_P (op) && ! TARGET_LONG_CALLS);
72 }
73
74 /* Return 1 if X contains a symbolic expression. We know these
75 expressions will have one of a few well defined forms, so
76 we need only check those forms. */
77 int
78 symbolic_expression_p (x)
79 register rtx x;
80 {
81
82 /* Strip off any HIGH. */
83 if (GET_CODE (x) == HIGH)
84 x = XEXP (x, 0);
85
86 return (symbolic_operand (x, VOIDmode));
87 }
88
89 int
90 symbolic_operand (op, mode)
91 register rtx op;
92 enum machine_mode mode;
93 {
94 switch (GET_CODE (op))
95 {
96 case SYMBOL_REF:
97 case LABEL_REF:
98 return 1;
99 case CONST:
100 op = XEXP (op, 0);
101 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
102 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
103 && GET_CODE (XEXP (op, 1)) == CONST_INT);
104 default:
105 return 0;
106 }
107 }
108
109 /* Return truth value of statement that OP is a symbolic memory
110 operand of mode MODE. */
111
112 int
113 symbolic_memory_operand (op, mode)
114 rtx op;
115 enum machine_mode mode;
116 {
117 if (GET_CODE (op) == SUBREG)
118 op = SUBREG_REG (op);
119 if (GET_CODE (op) != MEM)
120 return 0;
121 op = XEXP (op, 0);
122 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
123 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
124 }
125
126 /* Return 1 if the operand is either a register or a memory operand that is
127 not symbolic. */
128
129 int
130 reg_or_nonsymb_mem_operand (op, mode)
131 register rtx op;
132 enum machine_mode mode;
133 {
134 if (register_operand (op, mode))
135 return 1;
136
137 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
138 return 1;
139
140 return 0;
141 }
142
143 /* Return 1 if the operand is either a register, zero, or a memory operand
144 that is not symbolic. */
145
146 int
147 reg_or_0_or_nonsymb_mem_operand (op, mode)
148 register rtx op;
149 enum machine_mode mode;
150 {
151 if (register_operand (op, mode))
152 return 1;
153
154 if (op == CONST0_RTX (mode))
155 return 1;
156
157 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
158 return 1;
159
160 return 0;
161 }
162
163 /* Accept any constant that can be moved in one instructions into a
164 general register. */
165 int
166 cint_ok_for_move (intval)
167 int intval;
168 {
169 /* OK if ldo, ldil, or zdepi, can be used. */
170 return (VAL_14_BITS_P (intval) || (intval & 0x7ff) == 0
171 || zdepi_cint_p (intval));
172 }
173
174 /* Accept anything that can be moved in one instruction into a general
175 register. */
176 int
177 move_operand (op, mode)
178 rtx op;
179 enum machine_mode mode;
180 {
181 if (register_operand (op, mode))
182 return 1;
183
184 if (GET_CODE (op) == CONST_INT)
185 return cint_ok_for_move (INTVAL (op));
186
187 if (GET_MODE (op) != mode)
188 return 0;
189 if (GET_CODE (op) == SUBREG)
190 op = SUBREG_REG (op);
191 if (GET_CODE (op) != MEM)
192 return 0;
193
194 op = XEXP (op, 0);
195 if (GET_CODE (op) == LO_SUM)
196 return (register_operand (XEXP (op, 0), Pmode)
197 && CONSTANT_P (XEXP (op, 1)));
198 return memory_address_p (mode, op);
199 }
200
201 /* Accept REG and any CONST_INT that can be moved in one instruction into a
202 general register. */
203 int
204 reg_or_cint_move_operand (op, mode)
205 rtx op;
206 enum machine_mode mode;
207 {
208 if (register_operand (op, mode))
209 return 1;
210
211 if (GET_CODE (op) == CONST_INT)
212 return cint_ok_for_move (INTVAL (op));
213
214 return 0;
215 }
216
217 int
218 pic_operand (op, mode)
219 rtx op;
220 enum machine_mode mode;
221 {
222 return flag_pic && GET_CODE (op) == LABEL_REF;
223 }
224
225 int
226 fp_reg_operand (op, mode)
227 rtx op;
228 enum machine_mode mode;
229 {
230 return reg_renumber && FP_REG_P (op);
231 }
232
233 \f
234 extern int current_function_uses_pic_offset_table;
235 extern rtx force_reg (), validize_mem ();
236
237 /* The rtx for the global offset table which is a special form
238 that *is* a position independent symbolic constant. */
239 rtx pic_pc_rtx;
240
241 /* Ensure that we are not using patterns that are not OK with PIC. */
242
243 int
244 check_pic (i)
245 int i;
246 {
247 extern rtx recog_operand[];
248 switch (flag_pic)
249 {
250 case 1:
251 if (GET_CODE (recog_operand[i]) == SYMBOL_REF
252 || (GET_CODE (recog_operand[i]) == CONST
253 && ! rtx_equal_p (pic_pc_rtx, recog_operand[i])))
254 abort ();
255 case 2:
256 default:
257 return 1;
258 }
259 }
260
261 /* Return truth value of whether OP can be used as an operand in a
262 three operand arithmetic insn that accepts registers of mode MODE
263 or 14-bit signed integers. */
264 int
265 arith_operand (op, mode)
266 rtx op;
267 enum machine_mode mode;
268 {
269 return (register_operand (op, mode)
270 || (GET_CODE (op) == CONST_INT && INT_14_BITS (op)));
271 }
272
273 /* Return truth value of whether OP can be used as an operand in a
274 three operand arithmetic insn that accepts registers of mode MODE
275 or 11-bit signed integers. */
276 int
277 arith11_operand (op, mode)
278 rtx op;
279 enum machine_mode mode;
280 {
281 return (register_operand (op, mode)
282 || (GET_CODE (op) == CONST_INT && INT_11_BITS (op)));
283 }
284
285 /* A constant integer suitable for use in a PRE_MODIFY memory
286 reference. */
287 int
288 pre_cint_operand (op, mode)
289 rtx op;
290 enum machine_mode mode;
291 {
292 return (GET_CODE (op) == CONST_INT
293 && INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10);
294 }
295
296 /* A constant integer suitable for use in a POST_MODIFY memory
297 reference. */
298 int
299 post_cint_operand (op, mode)
300 rtx op;
301 enum machine_mode mode;
302 {
303 return (GET_CODE (op) == CONST_INT
304 && INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10);
305 }
306
307 int
308 arith_double_operand (op, mode)
309 rtx op;
310 enum machine_mode mode;
311 {
312 return (register_operand (op, mode)
313 || (GET_CODE (op) == CONST_DOUBLE
314 && GET_MODE (op) == mode
315 && VAL_14_BITS_P (CONST_DOUBLE_LOW (op))
316 && (CONST_DOUBLE_HIGH (op) >= 0
317 == ((CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
318 }
319
320 /* Return truth value of whether OP is a integer which fits the
321 range constraining immediate operands in three-address insns. */
322
323 int
324 int5_operand (op, mode)
325 rtx op;
326 enum machine_mode mode;
327 {
328 return (GET_CODE (op) == CONST_INT && INT_5_BITS (op));
329 }
330
331 int
332 uint5_operand (op, mode)
333 rtx op;
334 enum machine_mode mode;
335 {
336 return (GET_CODE (op) == CONST_INT && INT_U5_BITS (op));
337 }
338
339
340 int
341 int11_operand (op, mode)
342 rtx op;
343 enum machine_mode mode;
344 {
345 return (GET_CODE (op) == CONST_INT && INT_11_BITS (op));
346 }
347
348 int
349 arith5_operand (op, mode)
350 rtx op;
351 enum machine_mode mode;
352 {
353 return register_operand (op, mode) || int5_operand (op, mode);
354 }
355
356 /* True iff zdepi can be used to generate this CONST_INT. */
357 int
358 zdepi_cint_p (x)
359 unsigned x;
360 {
361 unsigned lsb_mask, t;
362
363 /* This might not be obvious, but it's at least fast.
364 This function is critcal; we don't have the time loops would take. */
365 lsb_mask = x & -x;
366 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
367 /* Return true iff t is a power of two. */
368 return ((t & (t - 1)) == 0);
369 }
370
371 /* True iff depi or extru can be used to compute (reg & mask). */
372 int
373 and_mask_p (mask)
374 unsigned mask;
375 {
376 mask = ~mask;
377 mask += mask & -mask;
378 return (mask & (mask - 1)) == 0;
379 }
380
381 /* True iff depi or extru can be used to compute (reg & OP). */
382 int
383 and_operand (op, mode)
384 rtx op;
385 enum machine_mode mode;
386 {
387 return (register_operand (op, mode)
388 || (GET_CODE (op) == CONST_INT && and_mask_p (INTVAL (op))));
389 }
390
391 /* True iff depi can be used to compute (reg | MASK). */
392 int
393 ior_mask_p (mask)
394 unsigned mask;
395 {
396 mask += mask & -mask;
397 return (mask & (mask - 1)) == 0;
398 }
399
400 /* True iff depi can be used to compute (reg | OP). */
401 int
402 ior_operand (op, mode)
403 rtx op;
404 enum machine_mode mode;
405 {
406 return (GET_CODE (op) == CONST_INT && ior_mask_p (INTVAL (op)));
407 }
408
409 int
410 lhs_lshift_operand (op, mode)
411 rtx op;
412 enum machine_mode mode;
413 {
414 return register_operand (op, mode) || lhs_lshift_cint_operand (op, mode);
415 }
416
417 /* True iff OP is a CONST_INT of the forms 0...0xxxx or 0...01...1xxxx.
418 Such values can be the left hand side x in (x << r), using the zvdepi
419 instruction. */
420 int
421 lhs_lshift_cint_operand (op, mode)
422 rtx op;
423 enum machine_mode mode;
424 {
425 unsigned x;
426 if (GET_CODE (op) != CONST_INT)
427 return 0;
428 x = INTVAL (op) >> 4;
429 return (x & (x + 1)) == 0;
430 }
431
432 int
433 arith32_operand (op, mode)
434 rtx op;
435 enum machine_mode mode;
436 {
437 return register_operand (op, mode) || GET_CODE (op) == CONST_INT;
438 }
439
440 int
441 pc_or_label_operand (op, mode)
442 rtx op;
443 enum machine_mode mode;
444 {
445 return (GET_CODE (op) == PC || GET_CODE (op) == LABEL_REF);
446 }
447 \f
448 /* Legitimize PIC addresses. If the address is already
449 position-independent, we return ORIG. Newly generated
450 position-independent addresses go to REG. If we need more
451 than one register, we lose. */
452
453 rtx
454 legitimize_pic_address (orig, mode, reg)
455 rtx orig, reg;
456 enum machine_mode mode;
457 {
458 rtx pic_ref = orig;
459
460 if (GET_CODE (orig) == SYMBOL_REF)
461 {
462 if (reg == 0)
463 abort ();
464
465 if (flag_pic == 2)
466 {
467 emit_insn (gen_rtx (SET, VOIDmode, reg,
468 gen_rtx (HIGH, Pmode, orig)));
469 emit_insn (gen_rtx (SET, VOIDmode, reg,
470 gen_rtx (LO_SUM, Pmode, reg, orig)));
471 orig = reg;
472 }
473 pic_ref = gen_rtx (MEM, Pmode,
474 gen_rtx (PLUS, Pmode,
475 pic_offset_table_rtx, orig));
476 current_function_uses_pic_offset_table = 1;
477 RTX_UNCHANGING_P (pic_ref) = 1;
478 emit_move_insn (reg, pic_ref);
479 return reg;
480 }
481 else if (GET_CODE (orig) == CONST)
482 {
483 rtx base, offset;
484
485 if (GET_CODE (XEXP (orig, 0)) == PLUS
486 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
487 return orig;
488
489 if (reg == 0)
490 abort ();
491
492 if (GET_CODE (XEXP (orig, 0)) == PLUS)
493 {
494 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
495 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
496 base == reg ? 0 : reg);
497 }
498 else abort ();
499 if (GET_CODE (orig) == CONST_INT)
500 {
501 if (INT_14_BITS (orig))
502 return plus_constant_for_output (base, INTVAL (orig));
503 orig = force_reg (Pmode, orig);
504 }
505 pic_ref = gen_rtx (PLUS, Pmode, base, orig);
506 /* Likewise, should we set special REG_NOTEs here? */
507 }
508 return pic_ref;
509 }
510
511 /* Set up PIC-specific rtl. This should not cause any insns
512 to be emitted. */
513
514 void
515 initialize_pic ()
516 {
517 }
518
519 /* Emit special PIC prologues and epilogues. */
520
521 void
522 finalize_pic ()
523 {
524 if (hppa_save_pic_table_rtx)
525 {
526 emit_insn_after (gen_rtx (SET, VOIDmode,
527 hppa_save_pic_table_rtx,
528 gen_rtx (REG, Pmode, 19)),
529 get_insns ());
530 /* Need to emit this whether or not we obey regdecls,
531 since setjmp/longjmp can cause life info to screw up. */
532 hppa_save_pic_table_rtx = 0;
533 }
534 emit_insn (gen_rtx (USE, VOIDmode, pic_offset_table_rtx));
535
536 }
537
538 /* Try machine-dependent ways of modifying an illegitimate address
539 to be legitimate. If we find one, return the new, valid address.
540 This macro is used in only one place: `memory_address' in explow.c.
541
542 OLDX is the address as it was before break_out_memory_refs was called.
543 In some cases it is useful to look at this to decide what needs to be done.
544
545 MODE and WIN are passed so that this macro can use
546 GO_IF_LEGITIMATE_ADDRESS.
547
548 It is always safe for this macro to do nothing. It exists to recognize
549 opportunities to optimize the output.
550
551 For the PA, transform:
552
553 memory(X + <large int>)
554
555 into:
556
557 if (<large int> & mask) >= 16
558 Y = (<large int> & ~mask) + mask + 1 Round up.
559 else
560 Y = (<large int> & ~mask) Round down.
561 Z = X + Y
562 memory (Z + (<large int> - Y));
563
564 This is for CSE to find several similar references, and only use one Z.
565
566 X can either be a SYMBOL_REF or REG, but because combine can not
567 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
568 D will not fit in 14 bits.
569
570 MODE_FLOAT references allow displacements which fit in 5 bits, so use
571 0x1f as the mask.
572
573 MODE_INT references allow displacements which fit in 14 bits, so use
574 0x3fff as the mask.
575
576 This relies on the fact that most mode MODE_FLOAT references will use FP
577 registers and most mode MODE_INT references will use integer registers.
578 (In the rare case of an FP register used in an integer MODE, we depend
579 on secondary reloads to clean things up.)
580
581
582 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
583 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
584 adressing modes to be used).
585
586 Put X and Z into registers. Then put the entire expression into
587 a register. */
588
589 rtx
590 hppa_legitimize_address (x, oldx, mode)
591 rtx x, oldx;
592 enum machine_mode mode;
593 {
594
595 rtx orig = x;
596
597 /* Strip off CONST. */
598 if (GET_CODE (x) == CONST)
599 x = XEXP (x, 0);
600
601 if (GET_CODE (x) == PLUS
602 && GET_CODE (XEXP (x, 1)) == CONST_INT
603 && (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
604 || GET_CODE (XEXP (x, 0)) == REG))
605 {
606 rtx int_part, ptr_reg;
607 int newoffset;
608 int offset = INTVAL (XEXP (x, 1));
609 int mask = GET_MODE_CLASS (mode) == MODE_FLOAT ? 0x1f : 0x3fff;
610
611 /* Choose which way to round the offset. Round up if we
612 are >= halfway to the next boundary. */
613 if ((offset & mask) >= ((mask + 1) / 2))
614 newoffset = (offset & ~ mask) + mask + 1;
615 else
616 newoffset = (offset & ~ mask);
617
618 /* If the newoffset will not fit in 14 bits (ldo), then
619 handling this would take 4 or 5 instructions (2 to load
620 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
621 add the new offset and the SYMBOL_REF.) Combine can
622 not handle 4->2 or 5->2 combinations, so do not create
623 them. */
624 if (! VAL_14_BITS_P (newoffset)
625 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
626 {
627 rtx const_part = gen_rtx (CONST, VOIDmode,
628 gen_rtx (PLUS, Pmode,
629 XEXP (x, 0),
630 GEN_INT (newoffset)));
631 rtx tmp_reg
632 = force_reg (Pmode,
633 gen_rtx (HIGH, Pmode, const_part));
634 ptr_reg
635 = force_reg (Pmode,
636 gen_rtx (LO_SUM, Pmode,
637 tmp_reg, const_part));
638 }
639 else
640 {
641 if (! VAL_14_BITS_P (newoffset))
642 int_part = force_reg (Pmode, GEN_INT (newoffset));
643 else
644 int_part = GEN_INT (newoffset);
645
646 ptr_reg = force_reg (Pmode,
647 gen_rtx (PLUS, Pmode,
648 force_reg (Pmode, XEXP (x, 0)),
649 int_part));
650 }
651 return plus_constant (ptr_reg, offset - newoffset);
652 }
653 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
654 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
655 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
656 {
657 int val = INTVAL (XEXP (XEXP (x, 0), 1));
658 rtx reg1, reg2;
659 reg1 = force_reg (Pmode, force_operand (XEXP (x, 1), 0));
660 reg2 = force_reg (Pmode,
661 force_operand (XEXP (XEXP (x, 0), 0), 0));
662 return force_reg (Pmode,
663 gen_rtx (PLUS, Pmode,
664 gen_rtx (MULT, Pmode, reg2,
665 GEN_INT (val)),
666 reg1));
667 }
668 if (flag_pic)
669 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
670
671 return orig;
672 }
673
674 /* For the HPPA, REG and REG+CONST is cost 0
675 and addresses involving symbolic constants are cost 2.
676
677 PIC addresses are very expensive.
678
679 It is no coincidence that this has the same structure
680 as GO_IF_LEGITIMATE_ADDRESS. */
681 int
682 hppa_address_cost (X)
683 rtx X;
684 {
685 if (GET_CODE (X) == PLUS)
686 return 1;
687 else if (GET_CODE (X) == LO_SUM)
688 return 1;
689 else if (GET_CODE (X) == HIGH)
690 return 2;
691 return 4;
692 }
693
694 /* Emit insns to move operands[1] into operands[0].
695
696 Return 1 if we have written out everything that needs to be done to
697 do the move. Otherwise, return 0 and the caller will emit the move
698 normally. */
699
700 int
701 emit_move_sequence (operands, mode, scratch_reg)
702 rtx *operands;
703 enum machine_mode mode;
704 rtx scratch_reg;
705 {
706 register rtx operand0 = operands[0];
707 register rtx operand1 = operands[1];
708
709 /* Handle secondary reloads for loads/stores of FP registers from
710 REG+D addresses where D does not fit in 5 bits. */
711 if (fp_reg_operand (operand0, mode)
712 && GET_CODE (operand1) == MEM
713 /* Using DFmode forces only short displacements be be
714 recognized as valid in reg+d addressing modes. */
715 && ! memory_address_p (DFmode, XEXP (operand1, 0))
716 && scratch_reg)
717 {
718 emit_move_insn (scratch_reg, XEXP (operand1 , 0));
719 emit_insn (gen_rtx (SET, VOIDmode, operand0, gen_rtx (MEM, mode,
720 scratch_reg)));
721 return 1;
722 }
723 else if (fp_reg_operand (operand1, mode)
724 && GET_CODE (operand0) == MEM
725 /* Using DFmode forces only short displacements be be
726 recognized as valid in reg+d addressing modes. */
727 && ! memory_address_p (DFmode, XEXP (operand0, 0))
728 && scratch_reg)
729 {
730 emit_move_insn (scratch_reg, XEXP (operand0 , 0));
731 emit_insn (gen_rtx (SET, VOIDmode, gen_rtx (MEM, mode, scratch_reg),
732 operand1));
733 return 1;
734 }
735 /* Handle secondary reloads for loads of FP registers from constant
736 expressions by forcing the constant into memory.
737
738 use scratch_reg to hold the address of the memory location.
739
740 ??? The proper fix is to change PREFERRED_RELOAD_CLASS to return
741 NO_REGS when presented with a const_int and an register class
742 containing only FP registers. Doing so unfortunately creates
743 more problems than it solves. Fix this for 2.5. */
744 else if (fp_reg_operand (operand0, mode)
745 && CONSTANT_P (operand1)
746 && scratch_reg)
747 {
748 rtx xoperands[2];
749
750 /* Force the constant into memory and put the address of the
751 memory location into scratch_reg. */
752 xoperands[0] = scratch_reg;
753 xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
754 emit_move_sequence (xoperands, mode, 0);
755
756 /* Now load the destination register. */
757 emit_insn (gen_rtx (SET, mode, operand0,
758 gen_rtx (MEM, mode, scratch_reg)));
759 return 1;
760 }
761 /* Handle secondary reloads for SAR. These occur when trying to load
762 the SAR from memory or from a FP register. */
763 else if (GET_CODE (operand0) == REG
764 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
765 && (GET_CODE (operand1) == MEM
766 || (GET_CODE (operand1) == REG
767 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1)))))
768 && scratch_reg)
769 {
770 emit_move_insn (scratch_reg, operand1);
771 emit_move_insn (operand0, scratch_reg);
772 return 1;
773 }
774 /* Handle most common case: storing into a register. */
775 else if (register_operand (operand0, mode))
776 {
777 if (register_operand (operand1, mode)
778 || (GET_CODE (operand1) == CONST_INT && INT_14_BITS (operand1))
779 || (operand1 == CONST0_RTX (mode))
780 || (GET_CODE (operand1) == HIGH
781 && !symbolic_operand (XEXP (operand1, 0)))
782 /* Only `general_operands' can come here, so MEM is ok. */
783 || GET_CODE (operand1) == MEM)
784 {
785 /* Run this case quickly. */
786 emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1));
787 return 1;
788 }
789 }
790 else if (GET_CODE (operand0) == MEM)
791 {
792 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
793 {
794 /* Run this case quickly. */
795 emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1));
796 return 1;
797 }
798 if (! reload_in_progress)
799 {
800 operands[0] = validize_mem (operand0);
801 operands[1] = operand1 = force_reg (mode, operand1);
802 }
803 }
804
805 /* Simplify the source if we need to. */
806 if (GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode)
807 || (GET_CODE (operand1) == HIGH
808 && symbolic_operand (XEXP (operand1, 0), mode)
809 && TARGET_KERNEL))
810 {
811 int ishighonly = 0;
812
813 if (GET_CODE (operand1) == HIGH)
814 {
815 ishighonly = 1;
816 operand1 = XEXP (operand1, 0);
817 }
818 if (symbolic_operand (operand1, mode))
819 {
820 if (flag_pic)
821 {
822 rtx temp = reload_in_progress ? operand0 : gen_reg_rtx (Pmode);
823 operands[1] = legitimize_pic_address (operand1, mode, temp);
824 emit_insn (gen_rtx (SET, VOIDmode, operand0, operands[1]));
825 }
826 /* On the HPPA, references to data space are supposed to */
827 /* use dp, register 27, but showing it in the RTL inhibits various
828 cse and loop optimizations. */
829 else
830 {
831 rtx temp, set;
832
833 if (reload_in_progress)
834 temp = scratch_reg ? scratch_reg : operand0;
835 else
836 temp = gen_reg_rtx (mode);
837
838 if (ishighonly)
839 set = gen_rtx (SET, mode, operand0, temp);
840 else
841 set = gen_rtx (SET, VOIDmode,
842 operand0,
843 gen_rtx (LO_SUM, mode, temp, operand1));
844
845 emit_insn (gen_rtx (SET, VOIDmode,
846 temp,
847 gen_rtx (HIGH, mode, operand1)));
848 if (function_label_operand (operand1, mode))
849 {
850 rtx temp = reload_in_progress ? scratch_reg
851 : gen_reg_rtx (mode);
852 if (!temp)
853 abort ();
854 emit_insn (gen_rtx (PARALLEL, VOIDmode,
855 gen_rtvec (2,
856 set,
857 gen_rtx (CLOBBER, VOIDmode,
858 temp))));
859 }
860 else
861 emit_insn (set);
862 return 1;
863 }
864 return 1;
865 }
866 else if (GET_CODE (operand1) != CONST_INT
867 || ! cint_ok_for_move (INTVAL (operand1)))
868 {
869 rtx temp = reload_in_progress ? operand0 : gen_reg_rtx (mode);
870 emit_insn (gen_rtx (SET, VOIDmode, temp,
871 gen_rtx (HIGH, mode, operand1)));
872 operands[1] = gen_rtx (LO_SUM, mode, temp, operand1);
873 }
874 }
875 /* Now have insn-emit do whatever it normally does. */
876 return 0;
877 }
878
879 /* Does operand (which is a symbolic_operand) live in text space? If
880 so SYMBOL_REF_FLAG, which is set by ENCODE_SECTION_INFO, will be true. */
881
882 int
883 read_only_operand (operand)
884 rtx operand;
885 {
886 if (GET_CODE (operand) == CONST)
887 operand = XEXP (XEXP (operand, 0), 0);
888 if (GET_CODE (operand) == SYMBOL_REF)
889 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
890 return 1;
891 }
892
893 \f
894 /* Return the best assembler insn template
895 for moving operands[1] into operands[0] as a fullword. */
896 char *
897 singlemove_string (operands)
898 rtx *operands;
899 {
900 if (GET_CODE (operands[0]) == MEM)
901 return "stw %r1,%0";
902 else if (GET_CODE (operands[1]) == MEM)
903 return "ldw %1,%0";
904 else if (GET_CODE (operands[1]) == CONST_DOUBLE
905 && GET_MODE (operands[1]) == SFmode)
906 {
907 int i;
908 union real_extract u;
909 union float_extract { float f; int i; } v;
910
911 bcopy (&CONST_DOUBLE_LOW (operands[1]), &u, sizeof u);
912 v.f = REAL_VALUE_TRUNCATE (SFmode, u.d);
913 i = v.i;
914
915 operands[1] = gen_rtx (CONST_INT, VOIDmode, i);
916
917 /* See if we can handle this constant in a single instruction. */
918 if (cint_ok_for_move (INTVAL (operands[1])))
919 {
920 int intval = INTVAL (operands[1]);
921
922 if (intval == 0)
923 return "copy 0,%0";
924 else if (VAL_14_BITS_P (intval))
925 return "ldi %1,%0";
926 else if ((intval & 0x7ff) == 0)
927 return "ldil L'%1,%0";
928 else if (zdepi_cint_p (intval))
929 return "zdepi %Z1,%0";
930 }
931 else
932 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
933 }
934
935 else if (GET_CODE (operands[1]) == CONST_INT)
936 {
937 /* See if we can handle this in a single instruction. */
938 if (cint_ok_for_move (INTVAL (operands[1])))
939 {
940 int intval = INTVAL (operands[1]);
941
942 if (intval == 0)
943 return "copy 0,%0";
944 else if (VAL_14_BITS_P (intval))
945 return "ldi %1,%0";
946 else if ((intval & 0x7ff) == 0)
947 return "ldil L'%1,%0";
948 else if (zdepi_cint_p (intval))
949 return "zdepi %Z1,%0";
950 }
951 else
952 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
953 }
954 return "copy %1,%0";
955 }
956 \f
957
958 /* Compute position (in OP[1]) and width (in OP[2])
959 useful for copying IMM to a register using the zdepi
960 instructions. Store the immediate value to insert in OP[0]. */
961 void
962 compute_zdepi_operands (imm, op)
963 unsigned imm;
964 unsigned *op;
965 {
966 int lsb, len;
967
968 /* Find the least significant set bit in IMM. */
969 for (lsb = 0; lsb < 32; lsb++)
970 {
971 if ((imm & 1) != 0)
972 break;
973 imm >>= 1;
974 }
975
976 /* Choose variants based on *sign* of the 5-bit field. */
977 if ((imm & 0x10) == 0)
978 len = (lsb <= 28) ? 4 : 32 - lsb;
979 else
980 {
981 /* Find the width of the bitstring in IMM. */
982 for (len = 5; len < 32; len++)
983 {
984 if ((imm & (1 << len)) == 0)
985 break;
986 }
987
988 /* Sign extend IMM as a 5-bit value. */
989 imm = (imm & 0xf) - 0x10;
990 }
991
992 op[0] = imm;
993 op[1] = 31 - lsb;
994 op[2] = len;
995 }
996
997 /* Output assembler code to perform a doubleword move insn
998 with operands OPERANDS. */
999
1000 char *
1001 output_move_double (operands)
1002 rtx *operands;
1003 {
1004 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
1005 rtx latehalf[2];
1006 rtx addreg0 = 0, addreg1 = 0;
1007
1008 /* First classify both operands. */
1009
1010 if (REG_P (operands[0]))
1011 optype0 = REGOP;
1012 else if (offsettable_memref_p (operands[0]))
1013 optype0 = OFFSOP;
1014 else if (GET_CODE (operands[0]) == MEM)
1015 optype0 = MEMOP;
1016 else
1017 optype0 = RNDOP;
1018
1019 if (REG_P (operands[1]))
1020 optype1 = REGOP;
1021 else if (CONSTANT_P (operands[1]))
1022 optype1 = CNSTOP;
1023 else if (offsettable_memref_p (operands[1]))
1024 optype1 = OFFSOP;
1025 else if (GET_CODE (operands[1]) == MEM)
1026 optype1 = MEMOP;
1027 else
1028 optype1 = RNDOP;
1029
1030 /* Check for the cases that the operand constraints are not
1031 supposed to allow to happen. Abort if we get one,
1032 because generating code for these cases is painful. */
1033
1034 if (optype0 != REGOP && optype1 != REGOP)
1035 abort ();
1036
1037 /* Handle auto decrementing and incrementing loads and stores
1038 specifically, since the structure of the function doesn't work
1039 for them without major modification. Do it better when we learn
1040 this port about the general inc/dec addressing of PA.
1041 (This was written by tege. Chide him if it doesn't work.) */
1042
1043 if (optype0 == MEMOP)
1044 {
1045 /* We have to output the address syntax ourselves, since print_operand
1046 doesn't deal with the addresses we want to use. Fix this later. */
1047
1048 rtx addr = XEXP (operands[0], 0);
1049 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
1050 {
1051 rtx high_reg = gen_rtx (SUBREG, SImode, operands[1], 0);
1052
1053 operands[0] = XEXP (addr, 0);
1054 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
1055 abort ();
1056
1057 if (!reg_overlap_mentioned_p (high_reg, addr))
1058 {
1059 /* No overlap between high target register and address
1060 register. (We do this in a non-obvious way to
1061 save a register file writeback) */
1062 if (GET_CODE (addr) == POST_INC)
1063 return "stws,ma %1,8(0,%0)\n\tstw %R1,-4(0,%0)";
1064 return "stws,ma %1,-8(0,%0)\n\tstw %R1,12(0,%0)";
1065 }
1066 else
1067 abort();
1068 }
1069 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
1070 {
1071 rtx high_reg = gen_rtx (SUBREG, SImode, operands[1], 0);
1072
1073 operands[0] = XEXP (addr, 0);
1074 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
1075 abort ();
1076
1077 if (!reg_overlap_mentioned_p (high_reg, addr))
1078 {
1079 /* No overlap between high target register and address
1080 register. (We do this in a non-obvious way to
1081 save a register file writeback) */
1082 if (GET_CODE (addr) == PRE_INC)
1083 return "stws,mb %1,8(0,%0)\n\tstw %R1,4(0,%0)";
1084 return "stws,mb %1,-8(0,%0)\n\tstw %R1,4(0,%0)";
1085 }
1086 else
1087 abort();
1088 }
1089 }
1090 if (optype1 == MEMOP)
1091 {
1092 /* We have to output the address syntax ourselves, since print_operand
1093 doesn't deal with the addresses we want to use. Fix this later. */
1094
1095 rtx addr = XEXP (operands[1], 0);
1096 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
1097 {
1098 rtx high_reg = gen_rtx (SUBREG, SImode, operands[0], 0);
1099
1100 operands[1] = XEXP (addr, 0);
1101 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
1102 abort ();
1103
1104 if (!reg_overlap_mentioned_p (high_reg, addr))
1105 {
1106 /* No overlap between high target register and address
1107 register. (We do this in a non-obvious way to
1108 save a register file writeback) */
1109 if (GET_CODE (addr) == POST_INC)
1110 return "ldws,ma 8(0,%1),%0\n\tldw -4(0,%1),%R0";
1111 return "ldws,ma -8(0,%1),%0\n\tldw 12(0,%1),%R0";
1112 }
1113 else
1114 {
1115 /* This is an undefined situation. We should load into the
1116 address register *and* update that register. Probably
1117 we don't need to handle this at all. */
1118 if (GET_CODE (addr) == POST_INC)
1119 return "ldw 4(0,%1),%R0\n\tldws,ma 8(0,%1),%0";
1120 return "ldw 4(0,%1),%R0\n\tldws,ma -8(0,%1),%0";
1121 }
1122 }
1123 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
1124 {
1125 rtx high_reg = gen_rtx (SUBREG, SImode, operands[0], 0);
1126
1127 operands[1] = XEXP (addr, 0);
1128 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
1129 abort ();
1130
1131 if (!reg_overlap_mentioned_p (high_reg, addr))
1132 {
1133 /* No overlap between high target register and address
1134 register. (We do this in a non-obvious way to
1135 save a register file writeback) */
1136 if (GET_CODE (addr) == PRE_INC)
1137 return "ldws,mb 8(0,%1),%0\n\tldw 4(0,%1),%R0";
1138 return "ldws,mb -8(0,%1),%0\n\tldw 4(0,%1),%R0";
1139 }
1140 else
1141 {
1142 /* This is an undefined situation. We should load into the
1143 address register *and* update that register. Probably
1144 we don't need to handle this at all. */
1145 if (GET_CODE (addr) == PRE_INC)
1146 return "ldw 12(0,%1),%R0\n\tldws,mb 8(0,%1),%0";
1147 return "ldw -4(0,%1),%R0\n\tldws,mb -8(0,%1),%0";
1148 }
1149 }
1150 }
1151
1152 /* If an operand is an unoffsettable memory ref, find a register
1153 we can increment temporarily to make it refer to the second word. */
1154
1155 if (optype0 == MEMOP)
1156 addreg0 = find_addr_reg (XEXP (operands[0], 0));
1157
1158 if (optype1 == MEMOP)
1159 addreg1 = find_addr_reg (XEXP (operands[1], 0));
1160
1161 /* Ok, we can do one word at a time.
1162 Normally we do the low-numbered word first.
1163
1164 In either case, set up in LATEHALF the operands to use
1165 for the high-numbered word and in some cases alter the
1166 operands in OPERANDS to be suitable for the low-numbered word. */
1167
1168 if (optype0 == REGOP)
1169 latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
1170 else if (optype0 == OFFSOP)
1171 latehalf[0] = adj_offsettable_operand (operands[0], 4);
1172 else
1173 latehalf[0] = operands[0];
1174
1175 if (optype1 == REGOP)
1176 latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
1177 else if (optype1 == OFFSOP)
1178 latehalf[1] = adj_offsettable_operand (operands[1], 4);
1179 else if (optype1 == CNSTOP)
1180 split_double (operands[1], &operands[1], &latehalf[1]);
1181 else
1182 latehalf[1] = operands[1];
1183
1184 /* If the first move would clobber the source of the second one,
1185 do them in the other order.
1186
1187 RMS says "This happens only for registers;
1188 such overlap can't happen in memory unless the user explicitly
1189 sets it up, and that is an undefined circumstance."
1190
1191 but it happens on the HP-PA when loading parameter registers,
1192 so I am going to define that circumstance, and make it work
1193 as expected. */
1194
1195 if (optype0 == REGOP && (optype1 == MEMOP || optype1 == OFFSOP)
1196 && reg_overlap_mentioned_p (operands[0], XEXP (operands[1], 0)))
1197 {
1198 /* XXX THIS PROBABLY DOESN'T WORK. */
1199 /* Do the late half first. */
1200 if (addreg1)
1201 output_asm_insn ("ldo 4(%0),%0", &addreg1);
1202 output_asm_insn (singlemove_string (latehalf), latehalf);
1203 if (addreg1)
1204 output_asm_insn ("ldo -4(%0),%0", &addreg1);
1205 /* Then clobber. */
1206 return singlemove_string (operands);
1207 }
1208
1209 if (optype0 == REGOP && optype1 == REGOP
1210 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
1211 {
1212 output_asm_insn (singlemove_string (latehalf), latehalf);
1213 return singlemove_string (operands);
1214 }
1215
1216 /* Normal case: do the two words, low-numbered first. */
1217
1218 output_asm_insn (singlemove_string (operands), operands);
1219
1220 /* Make any unoffsettable addresses point at high-numbered word. */
1221 if (addreg0)
1222 output_asm_insn ("ldo 4(%0),%0", &addreg0);
1223 if (addreg1)
1224 output_asm_insn ("ldo 4(%0),%0", &addreg1);
1225
1226 /* Do that word. */
1227 output_asm_insn (singlemove_string (latehalf), latehalf);
1228
1229 /* Undo the adds we just did. */
1230 if (addreg0)
1231 output_asm_insn ("ldo -4(%0),%0", &addreg0);
1232 if (addreg1)
1233 output_asm_insn ("ldo -4(%0),%0", &addreg1);
1234
1235 return "";
1236 }
1237 \f
1238 char *
1239 output_fp_move_double (operands)
1240 rtx *operands;
1241 {
1242 if (FP_REG_P (operands[0]))
1243 {
1244 if (FP_REG_P (operands[1])
1245 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
1246 output_asm_insn ("fcpy,dbl %r1,%0", operands);
1247 else
1248 output_asm_insn ("fldds%F1 %1,%0", operands);
1249 }
1250 else if (FP_REG_P (operands[1]))
1251 {
1252 output_asm_insn ("fstds%F0 %1,%0", operands);
1253 }
1254 else if (operands[1] == CONST0_RTX (GET_MODE (operands[0])))
1255 {
1256 if (GET_CODE (operands[0]) == REG)
1257 {
1258 rtx xoperands[2];
1259 xoperands[1] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
1260 xoperands[0] = operands[0];
1261 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
1262 }
1263 /* This is a pain. You have to be prepared to deal with an
1264 arbritary address here including pre/post increment/decrement.
1265
1266 so avoid this in the MD. */
1267 else
1268 abort ();
1269 }
1270 else abort ();
1271 return "";
1272 }
1273 \f
1274 /* Return a REG that occurs in ADDR with coefficient 1.
1275 ADDR can be effectively incremented by incrementing REG. */
1276
1277 static rtx
1278 find_addr_reg (addr)
1279 rtx addr;
1280 {
1281 while (GET_CODE (addr) == PLUS)
1282 {
1283 if (GET_CODE (XEXP (addr, 0)) == REG)
1284 addr = XEXP (addr, 0);
1285 else if (GET_CODE (XEXP (addr, 1)) == REG)
1286 addr = XEXP (addr, 1);
1287 else if (CONSTANT_P (XEXP (addr, 0)))
1288 addr = XEXP (addr, 1);
1289 else if (CONSTANT_P (XEXP (addr, 1)))
1290 addr = XEXP (addr, 0);
1291 else
1292 abort ();
1293 }
1294 if (GET_CODE (addr) == REG)
1295 return addr;
1296 abort ();
1297 }
1298
1299 /* Emit code to perform a block move.
1300
1301 Restriction: If the length argument is non-constant, alignment
1302 must be 4.
1303
1304 OPERANDS[0] is the destination pointer as a REG, clobbered.
1305 OPERANDS[1] is the source pointer as a REG, clobbered.
1306 if SIZE_IS_CONSTANT
1307 OPERANDS[2] is a register for temporary storage.
1308 OPERANDS[4] is the size as a CONST_INT
1309 else
1310 OPERANDS[2] is a REG which will contain the size, clobbered.
1311 OPERANDS[3] is a register for temporary storage.
1312 OPERANDS[5] is the alignment safe to use, as a CONST_INT. */
1313
1314 char *
1315 output_block_move (operands, size_is_constant)
1316 rtx *operands;
1317 int size_is_constant;
1318 {
1319 int align = INTVAL (operands[5]);
1320 unsigned long n_bytes;
1321
1322 /* We can't move more than four bytes at a time because the PA
1323 has no longer integer move insns. (Could use fp mem ops?) */
1324 if (align > 4)
1325 align = 4;
1326
1327 if (size_is_constant)
1328 {
1329 unsigned long n_items;
1330 unsigned long offset;
1331 rtx temp;
1332
1333 n_bytes = INTVAL (operands[4]);
1334 if (n_bytes == 0)
1335 return "";
1336
1337 if (align >= 4)
1338 {
1339 /* Don't unroll too large blocks. */
1340 if (n_bytes > 64)
1341 goto copy_with_loop;
1342
1343 /* Read and store using two registers, and hide latency
1344 by deferring the stores until three instructions after
1345 the corresponding load. The last load insn will read
1346 the entire word were the last bytes are, possibly past
1347 the end of the source block, but since loads are aligned,
1348 this is harmless. */
1349
1350 output_asm_insn ("ldws,ma 4(0,%1),%2", operands);
1351
1352 for (offset = 4; offset < n_bytes; offset += 4)
1353 {
1354 output_asm_insn ("ldws,ma 4(0,%1),%3", operands);
1355 output_asm_insn ("stws,ma %2,4(0,%0)", operands);
1356
1357 temp = operands[2];
1358 operands[2] = operands[3];
1359 operands[3] = temp;
1360 }
1361 if (n_bytes % 4 == 0)
1362 /* Store the last word. */
1363 output_asm_insn ("stw %2,0(0,%0)", operands);
1364 else
1365 {
1366 /* Store the last, partial word. */
1367 operands[4] = gen_rtx (CONST_INT, VOIDmode, n_bytes % 4);
1368 output_asm_insn ("stbys,e %2,%4(0,%0)", operands);
1369 }
1370 return "";
1371 }
1372
1373 if (align >= 2 && n_bytes >= 2)
1374 {
1375 output_asm_insn ("ldhs,ma 2(0,%1),%2", operands);
1376
1377 for (offset = 2; offset + 2 <= n_bytes; offset += 2)
1378 {
1379 output_asm_insn ("ldhs,ma 2(0,%1),%3", operands);
1380 output_asm_insn ("sths,ma %2,2(0,%0)", operands);
1381
1382 temp = operands[2];
1383 operands[2] = operands[3];
1384 operands[3] = temp;
1385 }
1386 if (n_bytes % 2 != 0)
1387 output_asm_insn ("ldb 0(0,%1),%3", operands);
1388
1389 output_asm_insn ("sths,ma %2,2(0,%0)", operands);
1390
1391 if (n_bytes % 2 != 0)
1392 output_asm_insn ("stb %3,0(0,%0)", operands);
1393
1394 return "";
1395 }
1396
1397 output_asm_insn ("ldbs,ma 1(0,%1),%2", operands);
1398
1399 for (offset = 1; offset + 1 <= n_bytes; offset += 1)
1400 {
1401 output_asm_insn ("ldbs,ma 1(0,%1),%3", operands);
1402 output_asm_insn ("stbs,ma %2,1(0,%0)", operands);
1403
1404 temp = operands[2];
1405 operands[2] = operands[3];
1406 operands[3] = temp;
1407 }
1408 output_asm_insn ("stb %2,0(0,%0)", operands);
1409
1410 return "";
1411 }
1412
1413 if (align != 4)
1414 abort();
1415
1416 copy_with_loop:
1417
1418 if (size_is_constant)
1419 {
1420 /* Size is compile-time determined, and also not
1421 very small (such small cases are handled above). */
1422 operands[4] = gen_rtx (CONST_INT, VOIDmode, n_bytes - 4);
1423 output_asm_insn ("ldo %4(0),%2", operands);
1424 }
1425 else
1426 {
1427 /* Decrement counter by 4, and if it becomes negative, jump past the
1428 word copying loop. */
1429 output_asm_insn ("addib,<,n -4,%2,.+16", operands);
1430 }
1431
1432 /* Copying loop. Note that the first load is in the annulled delay slot
1433 of addib. Is it OK on PA to have a load in a delay slot, i.e. is a
1434 possible page fault stopped in time? */
1435 output_asm_insn ("ldws,ma 4(0,%1),%3", operands);
1436 output_asm_insn ("addib,>= -4,%2,.-4", operands);
1437 output_asm_insn ("stws,ma %3,4(0,%0)", operands);
1438
1439 /* The counter is negative, >= -4. The remaining number of bytes are
1440 determined by the two least significant bits. */
1441
1442 if (size_is_constant)
1443 {
1444 if (n_bytes % 4 != 0)
1445 {
1446 /* Read the entire word of the source block tail. */
1447 output_asm_insn ("ldw 0(0,%1),%3", operands);
1448 operands[4] = gen_rtx (CONST_INT, VOIDmode, n_bytes % 4);
1449 output_asm_insn ("stbys,e %3,%4(0,%0)", operands);
1450 }
1451 }
1452 else
1453 {
1454 /* Add 4 to counter. If it becomes zero, we're done. */
1455 output_asm_insn ("addib,=,n 4,%2,.+16", operands);
1456
1457 /* Read the entire word of the source block tail. (Also this
1458 load is in an annulled delay slot.) */
1459 output_asm_insn ("ldw 0(0,%1),%3", operands);
1460
1461 /* Make %0 point at the first byte after the destination block. */
1462 output_asm_insn ("add %2,%0,%0", operands);
1463 /* Store the leftmost bytes, up to, but not including, the address
1464 in %0. */
1465 output_asm_insn ("stbys,e %3,0(0,%0)", operands);
1466 }
1467 return "";
1468 }
1469
1470 /* Count the number of insns necessary to handle this block move.
1471
1472 Basic structure is the same as emit_block_move, except that we
1473 count insns rather than emit them. */
1474
1475 int
1476 compute_movstrsi_length (insn)
1477 rtx insn;
1478 {
1479 rtx pat = PATTERN (insn);
1480 int size_is_constant;
1481 int align = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
1482 unsigned long n_bytes;
1483 int insn_count = 0;
1484
1485 if (GET_CODE (XEXP (XVECEXP (pat, 0, 5), 0)) == CONST_INT)
1486 {
1487 size_is_constant = 1;
1488 n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 5), 0));
1489 }
1490 else
1491 {
1492 size_is_constant = 0;
1493 n_bytes = 0;
1494 }
1495
1496 /* We can't move more than four bytes at a time because the PA
1497 has no longer integer move insns. (Could use fp mem ops?) */
1498 if (align > 4)
1499 align = 4;
1500
1501 if (size_is_constant)
1502 {
1503 unsigned long n_items;
1504 unsigned long offset;
1505 rtx temp;
1506
1507 if (n_bytes == 0)
1508 return 0;
1509
1510 if (align >= 4)
1511 {
1512 /* Don't unroll too large blocks. */
1513 if (n_bytes > 64)
1514 goto copy_with_loop;
1515
1516 /* first load */
1517 insn_count = 1;
1518
1519 /* Count the unrolled insns. */
1520 for (offset = 4; offset < n_bytes; offset += 4)
1521 insn_count += 2;
1522
1523 /* Count last store or partial store. */
1524 insn_count += 1;
1525 return insn_count * 4;
1526 }
1527
1528 if (align >= 2 && n_bytes >= 2)
1529 {
1530 /* initial load. */
1531 insn_count = 1;
1532
1533 /* Unrolled loop. */
1534 for (offset = 2; offset + 2 <= n_bytes; offset += 2)
1535 insn_count += 2;
1536
1537 /* ??? odd load/store */
1538 if (n_bytes % 2 != 0)
1539 insn_count += 2;
1540
1541 /* ??? final store from loop. */
1542 insn_count += 1;
1543
1544 return insn_count * 4;
1545 }
1546
1547 /* First load. */
1548 insn_count = 1;
1549
1550 /* The unrolled loop. */
1551 for (offset = 1; offset + 1 <= n_bytes; offset += 1)
1552 insn_count += 2;
1553
1554 /* Final store. */
1555 insn_count += 1;
1556
1557 return insn_count * 4;
1558 }
1559
1560 if (align != 4)
1561 abort();
1562
1563 copy_with_loop:
1564
1565 /* setup for constant and non-constant case. */
1566 insn_count = 1;
1567
1568 /* The copying loop. */
1569 insn_count += 3;
1570
1571 /* The counter is negative, >= -4. The remaining number of bytes are
1572 determined by the two least significant bits. */
1573
1574 if (size_is_constant)
1575 {
1576 if (n_bytes % 4 != 0)
1577 insn_count += 2;
1578 }
1579 else
1580 insn_count += 4;
1581 return insn_count * 4;
1582 }
1583 \f
1584
1585 char *
1586 output_and (operands)
1587 rtx *operands;
1588 {
1589 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
1590 {
1591 unsigned mask = INTVAL (operands[2]);
1592 int ls0, ls1, ms0, p, len;
1593
1594 for (ls0 = 0; ls0 < 32; ls0++)
1595 if ((mask & (1 << ls0)) == 0)
1596 break;
1597
1598 for (ls1 = ls0; ls1 < 32; ls1++)
1599 if ((mask & (1 << ls1)) != 0)
1600 break;
1601
1602 for (ms0 = ls1; ms0 < 32; ms0++)
1603 if ((mask & (1 << ms0)) == 0)
1604 break;
1605
1606 if (ms0 != 32)
1607 abort();
1608
1609 if (ls1 == 32)
1610 {
1611 len = ls0;
1612
1613 if (len == 0)
1614 abort ();
1615
1616 operands[2] = gen_rtx (CONST_INT, VOIDmode, len);
1617 return "extru %1,31,%2,%0";
1618 }
1619 else
1620 {
1621 /* We could use this `depi' for the case above as well, but `depi'
1622 requires one more register file access than an `extru'. */
1623
1624 p = 31 - ls0;
1625 len = ls1 - ls0;
1626
1627 operands[2] = gen_rtx (CONST_INT, VOIDmode, p);
1628 operands[3] = gen_rtx (CONST_INT, VOIDmode, len);
1629 return "depi 0,%2,%3,%0";
1630 }
1631 }
1632 else
1633 return "and %1,%2,%0";
1634 }
1635
1636 char *
1637 output_ior (operands)
1638 rtx *operands;
1639 {
1640 unsigned mask = INTVAL (operands[2]);
1641 int bs0, bs1, bs2, p, len;
1642
1643 if (INTVAL (operands[2]) == 0)
1644 return "copy %1,%0";
1645
1646 for (bs0 = 0; bs0 < 32; bs0++)
1647 if ((mask & (1 << bs0)) != 0)
1648 break;
1649
1650 for (bs1 = bs0; bs1 < 32; bs1++)
1651 if ((mask & (1 << bs1)) == 0)
1652 break;
1653
1654 if (bs1 != 32 && ((unsigned) 1 << bs1) <= mask)
1655 abort();
1656
1657 p = 31 - bs0;
1658 len = bs1 - bs0;
1659
1660 operands[2] = gen_rtx (CONST_INT, VOIDmode, p);
1661 operands[3] = gen_rtx (CONST_INT, VOIDmode, len);
1662 return "depi -1,%2,%3,%0";
1663 }
1664 \f
1665 /* Output an ascii string. */
1666 output_ascii (file, p, size)
1667 FILE *file;
1668 unsigned char *p;
1669 int size;
1670 {
1671 int i;
1672 int chars_output;
1673 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
1674
1675 /* The HP assembler can only take strings of 256 characters at one
1676 time. This is a limitation on input line length, *not* the
1677 length of the string. Sigh. Even worse, it seems that the
1678 restriction is in number of input characters (see \xnn &
1679 \whatever). So we have to do this very carefully. */
1680
1681 fprintf (file, "\t.STRING \"");
1682
1683 chars_output = 0;
1684 for (i = 0; i < size; i += 4)
1685 {
1686 int co = 0;
1687 int io = 0;
1688 for (io = 0, co = 0; io < MIN (4, size - i); io++)
1689 {
1690 register unsigned int c = p[i + io];
1691
1692 if (c == '\"' || c == '\\')
1693 partial_output[co++] = '\\';
1694 if (c >= ' ' && c < 0177)
1695 partial_output[co++] = c;
1696 else
1697 {
1698 unsigned int hexd;
1699 partial_output[co++] = '\\';
1700 partial_output[co++] = 'x';
1701 hexd = c / 16 - 0 + '0';
1702 if (hexd > '9')
1703 hexd -= '9' - 'a' + 1;
1704 partial_output[co++] = hexd;
1705 hexd = c % 16 - 0 + '0';
1706 if (hexd > '9')
1707 hexd -= '9' - 'a' + 1;
1708 partial_output[co++] = hexd;
1709 }
1710 }
1711 if (chars_output + co > 243)
1712 {
1713 fprintf (file, "\"\n\t.STRING \"");
1714 chars_output = 0;
1715 }
1716 fwrite (partial_output, 1, co, file);
1717 chars_output += co;
1718 co = 0;
1719 }
1720 fprintf (file, "\"\n");
1721 }
1722 \f
1723 /* You may have trouble believing this, but this is the HP-PA stack
1724 layout. Wow.
1725
1726 Offset Contents
1727
1728 Variable arguments (optional; any number may be allocated)
1729
1730 SP-(4*(N+9)) arg word N
1731 : :
1732 SP-56 arg word 5
1733 SP-52 arg word 4
1734
1735 Fixed arguments (must be allocated; may remain unused)
1736
1737 SP-48 arg word 3
1738 SP-44 arg word 2
1739 SP-40 arg word 1
1740 SP-36 arg word 0
1741
1742 Frame Marker
1743
1744 SP-32 External Data Pointer (DP)
1745 SP-28 External sr4
1746 SP-24 External/stub RP (RP')
1747 SP-20 Current RP
1748 SP-16 Static Link
1749 SP-12 Clean up
1750 SP-8 Calling Stub RP (RP'')
1751 SP-4 Previous SP
1752
1753 Top of Frame
1754
1755 SP-0 Stack Pointer (points to next available address)
1756
1757 */
1758
1759 /* This function saves registers as follows. Registers marked with ' are
1760 this function's registers (as opposed to the previous function's).
1761 If a frame_pointer isn't needed, r4 is saved as a general register;
1762 the space for the frame pointer is still allocated, though, to keep
1763 things simple.
1764
1765
1766 Top of Frame
1767
1768 SP (FP') Previous FP
1769 SP + 4 Alignment filler (sigh)
1770 SP + 8 Space for locals reserved here.
1771 .
1772 .
1773 .
1774 SP + n All call saved register used.
1775 .
1776 .
1777 .
1778 SP + o All call saved fp registers used.
1779 .
1780 .
1781 .
1782 SP + p (SP') points to next available address.
1783
1784 */
1785
1786 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
1787 Handle case where DISP > 8k by using the add_high_const pattern.
1788
1789 Note in DISP > 8k case, we will leave the high part of the address
1790 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
1791 static void
1792 store_reg (reg, disp, base)
1793 int reg, disp, base;
1794 {
1795 if (VAL_14_BITS_P (disp))
1796 {
1797 emit_move_insn (gen_rtx (MEM, SImode,
1798 gen_rtx (PLUS, SImode,
1799 gen_rtx (REG, SImode, base),
1800 GEN_INT (disp))),
1801 gen_rtx (REG, SImode, reg));
1802 }
1803 else
1804 {
1805 emit_insn (gen_add_high_const (gen_rtx (REG, SImode, 1),
1806 gen_rtx (REG, SImode, base),
1807 GEN_INT (disp)));
1808 emit_move_insn (gen_rtx (MEM, SImode,
1809 gen_rtx (LO_SUM, SImode,
1810 gen_rtx (REG, SImode, 1),
1811 GEN_INT (disp))),
1812 gen_rtx (REG, SImode, reg));
1813 }
1814 }
1815
1816 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
1817 Handle case where DISP > 8k by using the add_high_const pattern.
1818
1819 Note in DISP > 8k case, we will leave the high part of the address
1820 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
1821 static void
1822 load_reg (reg, disp, base)
1823 int reg, disp, base;
1824 {
1825 if (VAL_14_BITS_P (disp))
1826 {
1827 emit_move_insn (gen_rtx (REG, SImode, reg),
1828 gen_rtx (MEM, SImode,
1829 gen_rtx (PLUS, SImode,
1830 gen_rtx (REG, SImode, base),
1831 GEN_INT (disp))));
1832
1833 }
1834 else
1835 {
1836 emit_insn (gen_add_high_const (gen_rtx (REG, SImode, 1),
1837 gen_rtx (REG, SImode, base),
1838 GEN_INT (disp)));
1839 emit_move_insn (gen_rtx (REG, SImode, reg),
1840 gen_rtx (MEM, SImode,
1841 gen_rtx (LO_SUM, SImode,
1842 gen_rtx (REG, SImode, 1),
1843 GEN_INT (disp))));
1844 }
1845 }
1846
1847 /* Emit RTL to set REG to the value specified by BASE+DISP.
1848 Handle case where DISP > 8k by using the add_high_const pattern.
1849
1850 Note in DISP > 8k case, we will leave the high part of the address
1851 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
1852 static void
1853 set_reg_plus_d(reg, base, disp)
1854 int reg, base, disp;
1855 {
1856 if (VAL_14_BITS_P (disp))
1857 {
1858 emit_move_insn (gen_rtx (REG, SImode, reg),
1859 gen_rtx (PLUS, SImode,
1860 gen_rtx (REG, SImode, base),
1861 GEN_INT (disp)));
1862
1863 }
1864 else
1865 {
1866 emit_insn (gen_add_high_const (gen_rtx (REG, SImode, 1),
1867 gen_rtx (REG, SImode, base),
1868 GEN_INT (disp)));
1869 emit_move_insn (gen_rtx (REG, SImode, reg),
1870 gen_rtx (LO_SUM, SImode,
1871 gen_rtx (REG, SImode, 1),
1872 GEN_INT (disp)));
1873 }
1874 }
1875
1876 /* Global variables set by FUNCTION_PROLOGUE. */
1877 /* Size of frame. Need to know this to emit return insns from
1878 leaf procedures. */
1879 static int actual_fsize;
1880 static int local_fsize, save_fregs;
1881
1882 int
1883 compute_frame_size (size, fregs_live)
1884 int size;
1885 int *fregs_live;
1886 {
1887 extern int current_function_outgoing_args_size;
1888 int i, fsize;
1889
1890 /* 8 is space for frame pointer + filler. If any frame is allocated
1891 we need to add this in because of STARTING_FRAME_OFFSET. */
1892 fsize = size + (size || frame_pointer_needed ? 8 : 0);
1893
1894 /* fp is stored in a special place. */
1895 if (frame_pointer_needed)
1896 {
1897 for (i = 18; i >= 5; i--)
1898 if (regs_ever_live[i])
1899 fsize += 4;
1900
1901 if (regs_ever_live[3])
1902 fsize += 4;
1903 }
1904 else
1905 {
1906 for (i = 18; i >= 3; i--)
1907 if (regs_ever_live[i])
1908 fsize += 4;
1909 }
1910 fsize = (fsize + 7) & ~7;
1911
1912 if (!TARGET_SNAKE)
1913 {
1914 for (i = 43; i >= 40; i--)
1915 if (regs_ever_live[i])
1916 {
1917 fsize += 8;
1918 if (fregs_live)
1919 *fregs_live = 1;
1920 }
1921 }
1922 else
1923 {
1924 for (i = 78; i >= 60; i -= 2)
1925 if (regs_ever_live[i] || regs_ever_live[i + 1])
1926 {
1927 fsize += 8;
1928 if (fregs_live)
1929 *fregs_live = 1;
1930 }
1931 }
1932 fsize += current_function_outgoing_args_size;
1933 if (! leaf_function_p () || fsize)
1934 fsize += 32;
1935 return TARGET_SNAKE ? (fsize + 63 & ~63) : fsize;
1936 }
1937
1938 rtx hp_profile_label_rtx;
1939 static char hp_profile_label_name[8];
1940 void
1941 output_function_prologue (file, size)
1942 FILE *file;
1943 int size;
1944 {
1945
1946 /* hppa_expand_prologue does the dirty work now. We just need
1947 to output the assembler directives which denote the start
1948 of a function. */
1949 fprintf (file, "\t.PROC\n\t.CALLINFO FRAME=%d", actual_fsize);
1950 if (regs_ever_live[2] || profile_flag)
1951 fprintf (file, ",CALLS,SAVE_RP");
1952 else
1953 fprintf (file, ",NO_CALLS");
1954
1955 if (frame_pointer_needed)
1956 fprintf (file, ",SAVE_SP");
1957
1958 fprintf (file, "\n\t.ENTRY\n");
1959
1960 /* Horrid hack. emit_function_prologue will modify this RTL in
1961 place to get the expected results. */
1962 if (profile_flag)
1963 sprintf(hp_profile_label_name, "LP$%04d", hp_profile_labelno);
1964 }
1965
1966 hppa_expand_prologue()
1967 {
1968
1969 extern char call_used_regs[];
1970 int size = get_frame_size ();
1971 int merge_sp_adjust_with_store = 0;
1972 int i, offset;
1973 rtx tmpreg, size_rtx;
1974
1975
1976 save_fregs = 0;
1977 local_fsize = size + (size || frame_pointer_needed ? 8 : 0);
1978 actual_fsize = compute_frame_size (size, &save_fregs);
1979
1980 /* Compute a few things we will use often. */
1981 tmpreg = gen_rtx (REG, SImode, 1);
1982 size_rtx = GEN_INT (actual_fsize);
1983
1984 /* Save RP first. The calling conventions manual states RP will
1985 always be stored into the caller's frame at sp-20. */
1986 if (regs_ever_live[2] || profile_flag)
1987 store_reg (2, -20, STACK_POINTER_REGNUM);
1988
1989 /* Allocate the local frame and set up the frame pointer if needed. */
1990 if (actual_fsize)
1991 if (frame_pointer_needed)
1992 {
1993 /* Copy the old frame pointer temporarily into %r1. Set up the
1994 new stack pointer, then store away the saved old frame pointer
1995 into the stack at sp+actual_fsize and at the same time update
1996 the stack pointer by actual_fsize bytes. Two versions, first
1997 handles small (<8k) frames. The second handles large (>8k)
1998 frames. */
1999 emit_move_insn (tmpreg, frame_pointer_rtx);
2000 emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
2001 if (VAL_14_BITS_P (actual_fsize))
2002 emit_insn (gen_post_stwm (stack_pointer_rtx,
2003 stack_pointer_rtx,
2004 size_rtx, tmpreg));
2005 else
2006 {
2007 store_reg (1, 0, FRAME_POINTER_REGNUM);
2008 set_reg_plus_d (STACK_POINTER_REGNUM,
2009 STACK_POINTER_REGNUM,
2010 actual_fsize);
2011 }
2012 }
2013 /* no frame pointer needed. */
2014 else
2015 {
2016 /* In some cases we can perform the first callee register save
2017 and allocating the stack frame at the same time. If so, just
2018 make a note of it and defer allocating the frame until saving
2019 the callee registers. */
2020 if (VAL_14_BITS_P (-actual_fsize)
2021 && local_fsize == 0
2022 && ! profile_flag
2023 && ! flag_pic)
2024 merge_sp_adjust_with_store = 1;
2025 /* Can not optimize. Adjust the stack frame by actual_fsize bytes. */
2026 else if (actual_fsize != 0)
2027 set_reg_plus_d (STACK_POINTER_REGNUM,
2028 STACK_POINTER_REGNUM,
2029 actual_fsize);
2030 }
2031 /* The hppa calling conventions say that that %r19, the pic offset
2032 register, is saved at sp - 32 (in this function's frame) when
2033 generating PIC code. */
2034 if (flag_pic)
2035 store_reg (19, -32, STACK_POINTER_REGNUM);
2036
2037 /* Profiling code.
2038
2039 Instead of taking one argument, the counter label, as most normal
2040 mcounts do, _mcount appears to behave differently on the HPPA. It
2041 takes the return address of the caller, the address of this routine,
2042 and the address of the label. Also, it isn't magic, so
2043 argument registre hsave to be preserved. */
2044 if (profile_flag)
2045 {
2046 int pc_offset, i, arg_offset, basereg, offsetadj;
2047
2048 pc_offset = 4 + (frame_pointer_needed
2049 ? (VAL_14_BITS_P (actual_fsize) ? 12 : 20)
2050 : (VAL_14_BITS_P (actual_fsize) ? 4 : 8));
2051
2052 /* When the function has a frame pointer, use it as the base
2053 register for saving/restore registers. Else use the stack
2054 pointer. Adjust the offset according to the frame size if
2055 this function does not have a frame pointer. */
2056
2057 basereg = frame_pointer_needed ? FRAME_POINTER_REGNUM
2058 : STACK_POINTER_REGNUM;
2059 offsetadj = frame_pointer_needed ? 0 : actual_fsize;
2060
2061 /* Horrid hack. emit_function_prologue will modify this RTL in
2062 place to get the expected results. sprintf here is just to
2063 put something in the name. */
2064 sprintf(hp_profile_label_name, "LP$%04d", -1);
2065 hp_profile_label_rtx = gen_rtx (SYMBOL_REF, SImode,
2066 hp_profile_label_name);
2067 if (current_function_returns_struct)
2068 store_reg (STRUCT_VALUE_REGNUM, - 12 - offsetadj, basereg);
2069
2070 for (i = 26, arg_offset = -36 - offsetadj; i >= 23; i--, arg_offset -= 4)
2071 if (regs_ever_live [i])
2072 {
2073 store_reg (i, arg_offset, basereg);
2074 /* Deal with arg_offset not fitting in 14 bits. */
2075 pc_offset += VAL_14_BITS_P (arg_offset) ? 4 : 8;
2076 }
2077
2078 emit_move_insn (gen_rtx (REG, SImode, 26), gen_rtx (REG, SImode, 2));
2079 emit_move_insn (tmpreg, gen_rtx (HIGH, SImode, hp_profile_label_rtx));
2080 emit_move_insn (gen_rtx (REG, SImode, 24),
2081 gen_rtx (LO_SUM, SImode, tmpreg, hp_profile_label_rtx));
2082 /* %r25 is set from within the output pattern. */
2083 emit_insn (gen_call_profiler (GEN_INT (- pc_offset - 20)));
2084
2085 /* Restore argument registers. */
2086 for (i = 26, arg_offset = -36 - offsetadj; i >= 23; i--, arg_offset -= 4)
2087 if (regs_ever_live [i])
2088 load_reg (i, arg_offset, basereg);
2089
2090 if (current_function_returns_struct)
2091 load_reg (STRUCT_VALUE_REGNUM, -12 - offsetadj, basereg);
2092
2093 }
2094
2095 /* Normal register save.
2096
2097 Do not save the frame pointer in the frame_pointer_needed case. It
2098 was done earlier. */
2099 if (frame_pointer_needed)
2100 {
2101 for (i = 18, offset = local_fsize; i >= 3; i--)
2102 if (regs_ever_live[i] && ! call_used_regs[i]
2103 && i != FRAME_POINTER_REGNUM)
2104 {
2105 store_reg (i, offset, FRAME_POINTER_REGNUM);
2106 offset += 4;
2107 }
2108 }
2109 /* No frame pointer needed. */
2110 else
2111 {
2112 for (i = 18, offset = local_fsize - actual_fsize; i >= 3; i--)
2113 if (regs_ever_live[i] && ! call_used_regs[i])
2114 {
2115 /* If merge_sp_adjust_with_store is nonzero, then we can
2116 optimize the first GR save. */
2117 if (merge_sp_adjust_with_store)
2118 {
2119 merge_sp_adjust_with_store = 0;
2120 emit_insn (gen_post_stwm (stack_pointer_rtx,
2121 stack_pointer_rtx,
2122 GEN_INT (-offset),
2123 gen_rtx (REG, SImode, i)));
2124 }
2125 else
2126 store_reg (i, offset, STACK_POINTER_REGNUM);
2127 offset += 4;
2128 }
2129
2130 /* If we wanted to merge the SP adjustment with a GR save, but we never
2131 did any GR saves, then just emit the adjustment here. */
2132 if (merge_sp_adjust_with_store)
2133 set_reg_plus_d (STACK_POINTER_REGNUM,
2134 STACK_POINTER_REGNUM,
2135 actual_fsize);
2136 }
2137
2138 /* Align pointer properly (doubleword boundary). */
2139 offset = (offset + 7) & ~7;
2140
2141 /* Floating point register store. */
2142 if (save_fregs)
2143 {
2144
2145 /* First get the frame or stack pointer to the start of the FP register
2146 save area. */
2147 if (frame_pointer_needed)
2148 set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset);
2149 else
2150 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset);
2151
2152 /* Now actually save the FP registers. */
2153 if (! TARGET_SNAKE)
2154 {
2155 for (i = 43; i >= 40; i--)
2156 {
2157 if (regs_ever_live[i])
2158 emit_move_insn (gen_rtx (MEM, DFmode,
2159 gen_rtx (POST_INC, DFmode, tmpreg)),
2160 gen_rtx (REG, DFmode, i));
2161 }
2162 }
2163 else
2164 {
2165 for (i = 78; i >= 60; i -= 2)
2166 if (regs_ever_live[i] || regs_ever_live[i + 1])
2167 {
2168 emit_move_insn (gen_rtx (MEM, DFmode,
2169 gen_rtx (POST_INC, DFmode, tmpreg)),
2170 gen_rtx (REG, DFmode, i));
2171 }
2172 }
2173 }
2174 }
2175
2176
2177 void
2178 output_function_epilogue (file, size)
2179 FILE *file;
2180 int size;
2181 {
2182
2183 rtx insn = get_last_insn ();
2184
2185 /* hppa_expand_epilogue does the dirty work now. We just need
2186 to output the assembler directives which denote the end
2187 of a function.
2188
2189 To make debuggers happy, emit a nop if the epilogue was completely
2190 eliminated due to a volatile call as the last insn in the
2191 current function. That way the return address (in %r2) will
2192 always point to a valid instruction in the current function. */
2193
2194 /* Get the last real insn. */
2195 if (GET_CODE (insn) == NOTE)
2196 insn = prev_real_insn (insn);
2197
2198 /* If it is a sequence, then look inside. */
2199 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2200 insn = XVECEXP (PATTERN (insn), 0, 0);
2201
2202 /* If insn is a CALL_INSN, then it must be a call to a volatile
2203 function (otherwise there would be epilogue insns). */
2204 if (insn && GET_CODE (insn) == CALL_INSN)
2205 fprintf (file, "\tnop\n");
2206
2207 fprintf (file, "\t.EXIT\n\t.PROCEND\n");
2208 }
2209
2210 void
2211 hppa_expand_epilogue ()
2212 {
2213 rtx tmpreg;
2214 int offset,i;
2215 int merge_sp_adjust_with_load = 0;
2216
2217 /* We will use this often. */
2218 tmpreg = gen_rtx (REG, SImode, 1);
2219
2220 /* Try to restore RP early to avoid load/use interlocks when
2221 RP gets used in the return (bv) instruction. This appears to still
2222 be necessary even when we schedule the prologue and epilogue. */
2223 if (frame_pointer_needed
2224 && (regs_ever_live [2] || profile_flag))
2225 load_reg (2, -20, FRAME_POINTER_REGNUM);
2226
2227 /* No frame pointer, and stack is smaller than 8k. */
2228 else if (! frame_pointer_needed
2229 && VAL_14_BITS_P (actual_fsize + 20)
2230 && (regs_ever_live[2] || profile_flag))
2231 load_reg (2, - (actual_fsize + 20), STACK_POINTER_REGNUM);
2232
2233 /* General register restores. */
2234 if (frame_pointer_needed)
2235 {
2236 for (i = 18, offset = local_fsize; i >= 3; i--)
2237 if (regs_ever_live[i] && ! call_used_regs[i]
2238 && i != FRAME_POINTER_REGNUM)
2239 {
2240 load_reg (i, offset, FRAME_POINTER_REGNUM);
2241 offset += 4;
2242 }
2243 }
2244 else
2245 {
2246 for (i = 18, offset = local_fsize - actual_fsize; i >= 3; i--)
2247 if (regs_ever_live[i] && ! call_used_regs[i])
2248 {
2249 /* Only for the first load.
2250 merge_sp_adjust_with_load holds the register load
2251 with which we will merge the sp adjustment. */
2252 if (VAL_14_BITS_P (actual_fsize + 20)
2253 && local_fsize == 0
2254 && ! merge_sp_adjust_with_load)
2255 merge_sp_adjust_with_load = i;
2256 else
2257 load_reg (i, offset, STACK_POINTER_REGNUM);
2258 offset += 4;
2259 }
2260 }
2261
2262 /* Align pointer properly (doubleword boundary). */
2263 offset = (offset + 7) & ~7;
2264
2265 /* FP register restores. */
2266 if (save_fregs)
2267 {
2268 /* Adjust the register to index off of. */
2269 if (frame_pointer_needed)
2270 set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset);
2271 else
2272 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset);
2273
2274 /* Actually do the restores now. */
2275 if (! TARGET_SNAKE)
2276 {
2277 for (i = 43; i >= 40; i--)
2278 if (regs_ever_live[i])
2279 emit_move_insn (gen_rtx (REG, DFmode, i),
2280 gen_rtx (MEM, DFmode,
2281 gen_rtx (POST_INC, DFmode, tmpreg)));
2282
2283 }
2284 else
2285 {
2286 for (i = 78; i >= 60; i -= 2)
2287 if (regs_ever_live[i] || regs_ever_live[i + 1])
2288 emit_move_insn (gen_rtx (REG, DFmode, i),
2289 gen_rtx (MEM, DFmode,
2290 gen_rtx (POST_INC, DFmode, tmpreg)));
2291 }
2292 }
2293
2294 /* No frame pointer, but we have a stack greater than 8k. We restore
2295 %r2 very late in this case. (All other cases are restored as early
2296 as possible.) */
2297 if (! frame_pointer_needed
2298 && ! VAL_14_BITS_P (actual_fsize + 20)
2299 && (regs_ever_live[2] || profile_flag))
2300 {
2301 set_reg_plus_d (STACK_POINTER_REGNUM,
2302 STACK_POINTER_REGNUM,
2303 - actual_fsize);
2304 /* Uses value left over in %r1 by set_reg_plus_d. */
2305 load_reg (2, - (actual_fsize + 20 + ((- actual_fsize) & ~0x7ff)), 1);
2306 }
2307
2308 /* Reset stack pointer (and possibly frame pointer). The stack */
2309 /* pointer is initially set to fp + 64 to avoid a race condition.
2310 ??? What race condition?!? */
2311 else if (frame_pointer_needed)
2312 {
2313 /* Emit a blockage insn here to keep these insns from being moved
2314 to the beginning of the prologue or into the main instruction
2315 stream, doing so avoids some very obscure problems. */
2316 emit_insn (gen_blockage ());
2317 set_reg_plus_d (STACK_POINTER_REGNUM, FRAME_POINTER_REGNUM, 64);
2318 emit_insn (gen_pre_ldwm (stack_pointer_rtx, stack_pointer_rtx,
2319 GEN_INT (-64), frame_pointer_rtx));
2320 }
2321 /* If we were deferring a callee register restore, do it now. */
2322 else if (! frame_pointer_needed && merge_sp_adjust_with_load)
2323 emit_insn (gen_pre_ldwm (stack_pointer_rtx,
2324 stack_pointer_rtx,
2325 GEN_INT (- actual_fsize),
2326 gen_rtx (REG, SImode,
2327 merge_sp_adjust_with_load)));
2328 else if (actual_fsize != 0)
2329 set_reg_plus_d (STACK_POINTER_REGNUM,
2330 STACK_POINTER_REGNUM,
2331 - actual_fsize);
2332 }
2333
2334 /* This is only valid once reload has completed because it depends on
2335 knowing exactly how much (if any) frame there is and...
2336
2337 It's only valid if there is no frame marker to de-allocate and...
2338
2339 It's only valid if %r2 hasn't been saved into the caller's frame
2340 (we're not profiling and %r2 isn't live anywhere). */
2341 int
2342 hppa_can_use_return_insn_p ()
2343 {
2344 return (reload_completed
2345 && (compute_frame_size (get_frame_size (), 0) ? 0 : 1)
2346 && ! profile_flag
2347 && ! regs_ever_live[2]
2348 && ! frame_pointer_needed);
2349 }
2350
2351 void
2352 emit_bcond_fp (code, operand0)
2353 enum rtx_code code;
2354 rtx operand0;
2355 {
2356 emit_jump_insn (gen_rtx (SET, VOIDmode, pc_rtx,
2357 gen_rtx (IF_THEN_ELSE, VOIDmode,
2358 gen_rtx (code, VOIDmode,
2359 gen_rtx (REG, CCFPmode, 0),
2360 const0_rtx),
2361 gen_rtx (LABEL_REF, VOIDmode, operand0),
2362 pc_rtx)));
2363
2364 }
2365
2366 rtx
2367 gen_cmp_fp (code, operand0, operand1)
2368 enum rtx_code code;
2369 rtx operand0, operand1;
2370 {
2371 return gen_rtx (SET, VOIDmode, gen_rtx (REG, CCFPmode, 0),
2372 gen_rtx (code, CCFPmode, operand0, operand1));
2373 }
2374
2375 /* Adjust the cost of a scheduling dependency. Return the new cost of
2376 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
2377
2378 int
2379 pa_adjust_cost (insn, link, dep_insn, cost)
2380 rtx insn;
2381 rtx link;
2382 rtx dep_insn;
2383 int cost;
2384 {
2385 if (! recog_memoized (insn))
2386 return 0;
2387
2388 if (REG_NOTE_KIND (link) == 0)
2389 {
2390 /* Data dependency; DEP_INSN writes a register that INSN reads some
2391 cycles later. */
2392
2393 if (get_attr_type (insn) == TYPE_FPSTORE)
2394 {
2395 rtx pat = PATTERN (insn);
2396 rtx dep_pat = PATTERN (dep_insn);
2397 if (GET_CODE (pat) == PARALLEL)
2398 {
2399 /* This happens for the fstXs,mb patterns. */
2400 pat = XVECEXP (pat, 0, 0);
2401 }
2402 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
2403 /* If this happens, we have to extend this to schedule
2404 optimally. Return 0 for now. */
2405 return 0;
2406
2407 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
2408 {
2409 if (! recog_memoized (dep_insn))
2410 return 0;
2411 /* DEP_INSN is writing its result to the register
2412 being stored in the fpstore INSN. */
2413 switch (get_attr_type (dep_insn))
2414 {
2415 case TYPE_FPLOAD:
2416 /* This cost 3 cycles, not 2 as the md says. */
2417 return cost + 1;
2418
2419 case TYPE_FPALU:
2420 case TYPE_FPMUL:
2421 case TYPE_FPDIVSGL:
2422 case TYPE_FPDIVDBL:
2423 case TYPE_FPSQRTSGL:
2424 case TYPE_FPSQRTDBL:
2425 /* In these important cases, we save one cycle compared to
2426 when flop instruction feed each other. */
2427 return cost - 1;
2428
2429 default:
2430 return cost;
2431 }
2432 }
2433 }
2434
2435 /* For other data dependencies, the default cost specified in the
2436 md is correct. */
2437 return cost;
2438 }
2439 else if (REG_NOTE_KIND (link) == REG_DEP_ANTI)
2440 {
2441 /* Anti dependency; DEP_INSN reads a register that INSN writes some
2442 cycles later. */
2443
2444 if (get_attr_type (insn) == TYPE_FPLOAD)
2445 {
2446 rtx pat = PATTERN (insn);
2447 rtx dep_pat = PATTERN (dep_insn);
2448 if (GET_CODE (pat) == PARALLEL)
2449 {
2450 /* This happens for the fldXs,mb patterns. */
2451 pat = XVECEXP (pat, 0, 0);
2452 }
2453 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
2454 /* If this happens, we have to extend this to schedule
2455 optimally. Return 0 for now. */
2456 return 0;
2457
2458 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
2459 {
2460 if (! recog_memoized (dep_insn))
2461 return 0;
2462 switch (get_attr_type (dep_insn))
2463 {
2464 case TYPE_FPALU:
2465 case TYPE_FPMUL:
2466 case TYPE_FPDIVSGL:
2467 case TYPE_FPDIVDBL:
2468 case TYPE_FPSQRTSGL:
2469 case TYPE_FPSQRTDBL:
2470 /* A fpload can't be issued until one cycle before a
2471 preceeding arithmetic operation has finished, if
2472 the target of the fpload is any of the sources
2473 (or destination) of the arithmetic operation. */
2474 return cost - 1;
2475
2476 default:
2477 return 0;
2478 }
2479 }
2480 }
2481
2482 /* For other anti dependencies, the cost is 0. */
2483 return 0;
2484 }
2485
2486 /* For output dependencies, the cost is often one too high. */
2487 return cost - 1;
2488 }
2489
2490 /* Return any length adjustment needed by INSN which already has its length
2491 computed as LENGTH. Return zero if no adjustment is necessary.
2492
2493 For the PA: function calls, millicode calls, and backwards short
2494 conditional branches with unfilled delay slots need an adjustment by +1
2495 (to account for the NOP which will be inserted into the instruction stream).
2496
2497 Also compute the length of an inline block move here as it is too
2498 complicated to express as a length attribute in pa.md. */
2499 int
2500 pa_adjust_insn_length (insn, length)
2501 rtx insn;
2502 int length;
2503 {
2504 rtx pat = PATTERN (insn);
2505
2506 /* Call insns which are *not* indirect and have unfilled delay slots. */
2507 if (GET_CODE (insn) == CALL_INSN)
2508 {
2509
2510 if (GET_CODE (XVECEXP (pat, 0, 0)) == CALL
2511 && GET_CODE (XEXP (XEXP (XVECEXP (pat, 0, 0), 0), 0)) == SYMBOL_REF)
2512 return 4;
2513 else if (GET_CODE (XVECEXP (pat, 0, 0)) == SET
2514 && GET_CODE (XEXP (XEXP (XEXP (XVECEXP (pat, 0, 0), 1), 0), 0))
2515 == SYMBOL_REF)
2516 return 4;
2517 else
2518 return 0;
2519 }
2520 /* Millicode insn with an unfilled delay slot. */
2521 else if (GET_CODE (insn) == INSN
2522 && GET_CODE (pat) != SEQUENCE
2523 && GET_CODE (pat) != USE
2524 && GET_CODE (pat) != CLOBBER
2525 && get_attr_type (insn) == TYPE_MILLI)
2526 return 4;
2527 /* Block move pattern. */
2528 else if (GET_CODE (insn) == INSN
2529 && GET_CODE (pat) == PARALLEL
2530 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
2531 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 1)) == MEM
2532 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode
2533 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 1)) == BLKmode)
2534 return compute_movstrsi_length (insn) - 4;
2535 /* Conditional branch with an unfilled delay slot. */
2536 else if (GET_CODE (insn) == JUMP_INSN && ! simplejump_p (insn))
2537 {
2538 /* Adjust a short backwards conditional with an unfilled delay slot. */
2539 if (GET_CODE (pat) == SET
2540 && length == 4
2541 && ! forward_branch_p (insn))
2542 return 4;
2543 /* Adjust dbra insn with short backwards conditional branch with
2544 unfilled delay slot -- only for case where counter is in a
2545 general register register. */
2546 else if (GET_CODE (pat) == PARALLEL
2547 && GET_CODE (XVECEXP (pat, 0, 1)) == SET
2548 && GET_CODE (XEXP (XVECEXP (pat, 0, 1), 0)) == REG
2549 && ! FP_REG_P (XEXP (XVECEXP (pat, 0, 1), 0))
2550 && length == 4
2551 && ! forward_branch_p (insn))
2552 return 4;
2553 else
2554 return 0;
2555 }
2556 else
2557 return 0;
2558 }
2559
2560 /* Print operand X (an rtx) in assembler syntax to file FILE.
2561 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2562 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2563
2564 void
2565 print_operand (file, x, code)
2566 FILE *file;
2567 rtx x;
2568 int code;
2569 {
2570 switch (code)
2571 {
2572 case '#':
2573 /* Output a 'nop' if there's nothing for the delay slot. */
2574 if (dbr_sequence_length () == 0)
2575 fputs ("\n\tnop", file);
2576 return;
2577 case '*':
2578 /* Output an nullification completer if there's nothing for the */
2579 /* delay slot or nullification is requested. */
2580 if (dbr_sequence_length () == 0 ||
2581 (final_sequence &&
2582 INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
2583 fputs (",n", file);
2584 return;
2585 case 'R':
2586 /* Print out the second register name of a register pair.
2587 I.e., R (6) => 7. */
2588 fputs (reg_names[REGNO (x)+1], file);
2589 return;
2590 case 'r':
2591 /* A register or zero. */
2592 if (x == const0_rtx
2593 || (x == CONST0_RTX (DFmode))
2594 || (x == CONST0_RTX (SFmode)))
2595 {
2596 fputs ("0", file);
2597 return;
2598 }
2599 else
2600 break;
2601 case 'C': /* Plain (C)ondition */
2602 case 'X':
2603 switch (GET_CODE (x))
2604 {
2605 case EQ:
2606 fprintf (file, "="); break;
2607 case NE:
2608 fprintf (file, "<>"); break;
2609 case GT:
2610 fprintf (file, ">"); break;
2611 case GE:
2612 fprintf (file, ">="); break;
2613 case GEU:
2614 fprintf (file, ">>="); break;
2615 case GTU:
2616 fprintf (file, ">>"); break;
2617 case LT:
2618 fprintf (file, "<"); break;
2619 case LE:
2620 fprintf (file, "<="); break;
2621 case LEU:
2622 fprintf (file, "<<="); break;
2623 case LTU:
2624 fprintf (file, "<<"); break;
2625 default:
2626 printf ("Can't grok '%c' operator:\n", code);
2627 debug_rtx (x);
2628 abort ();
2629 }
2630 return;
2631 case 'N': /* Condition, (N)egated */
2632 switch (GET_CODE (x))
2633 {
2634 case EQ:
2635 fprintf (file, "<>"); break;
2636 case NE:
2637 fprintf (file, "="); break;
2638 case GT:
2639 fprintf (file, "<="); break;
2640 case GE:
2641 fprintf (file, "<"); break;
2642 case GEU:
2643 fprintf (file, "<<"); break;
2644 case GTU:
2645 fprintf (file, "<<="); break;
2646 case LT:
2647 fprintf (file, ">="); break;
2648 case LE:
2649 fprintf (file, ">"); break;
2650 case LEU:
2651 fprintf (file, ">>"); break;
2652 case LTU:
2653 fprintf (file, ">>="); break;
2654 default:
2655 printf ("Can't grok '%c' operator:\n", code);
2656 debug_rtx (x);
2657 abort ();
2658 }
2659 return;
2660 /* For floating point comparisons. Need special conditions to deal
2661 with NaNs properly. */
2662 case 'Y':
2663 switch (GET_CODE (x))
2664 {
2665 case EQ:
2666 fprintf (file, "!="); break;
2667 case NE:
2668 fprintf (file, "="); break;
2669 case GT:
2670 fprintf (file, "!>"); break;
2671 case GE:
2672 fprintf (file, "!>="); break;
2673 case LT:
2674 fprintf (file, "!<"); break;
2675 case LE:
2676 fprintf (file, "!<="); break;
2677 default:
2678 printf ("Can't grok '%c' operator:\n", code);
2679 debug_rtx (x);
2680 abort ();
2681 }
2682 return;
2683 case 'S': /* Condition, operands are (S)wapped. */
2684 switch (GET_CODE (x))
2685 {
2686 case EQ:
2687 fprintf (file, "="); break;
2688 case NE:
2689 fprintf (file, "<>"); break;
2690 case GT:
2691 fprintf (file, "<"); break;
2692 case GE:
2693 fprintf (file, "<="); break;
2694 case GEU:
2695 fprintf (file, "<<="); break;
2696 case GTU:
2697 fprintf (file, "<<"); break;
2698 case LT:
2699 fprintf (file, ">"); break;
2700 case LE:
2701 fprintf (file, ">="); break;
2702 case LEU:
2703 fprintf (file, ">>="); break;
2704 case LTU:
2705 fprintf (file, ">>"); break;
2706 default:
2707 printf ("Can't grok '%c' operator:\n", code);
2708 debug_rtx (x);
2709 abort ();
2710 }
2711 return;
2712 case 'B': /* Condition, (B)oth swapped and negate. */
2713 switch (GET_CODE (x))
2714 {
2715 case EQ:
2716 fprintf (file, "<>"); break;
2717 case NE:
2718 fprintf (file, "="); break;
2719 case GT:
2720 fprintf (file, ">="); break;
2721 case GE:
2722 fprintf (file, ">"); break;
2723 case GEU:
2724 fprintf (file, ">>"); break;
2725 case GTU:
2726 fprintf (file, ">>="); break;
2727 case LT:
2728 fprintf (file, "<="); break;
2729 case LE:
2730 fprintf (file, "<"); break;
2731 case LEU:
2732 fprintf (file, "<<"); break;
2733 case LTU:
2734 fprintf (file, "<<="); break;
2735 default:
2736 printf ("Can't grok '%c' operator:\n", code);
2737 debug_rtx (x);
2738 abort ();
2739 }
2740 return;
2741 case 'k':
2742 if (GET_CODE (x) == CONST_INT)
2743 {
2744 fprintf (file, "%d", ~INTVAL (x));
2745 return;
2746 }
2747 abort();
2748 case 'L':
2749 if (GET_CODE (x) == CONST_INT)
2750 {
2751 fprintf (file, "%d", 32 - (INTVAL (x) & 31));
2752 return;
2753 }
2754 abort();
2755 case 'O':
2756 if (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0)
2757 {
2758 fprintf (file, "%d", exact_log2 (INTVAL (x)));
2759 return;
2760 }
2761 abort();
2762 case 'P':
2763 if (GET_CODE (x) == CONST_INT)
2764 {
2765 fprintf (file, "%d", 31 - (INTVAL (x) & 31));
2766 return;
2767 }
2768 abort();
2769 case 'I':
2770 if (GET_CODE (x) == CONST_INT)
2771 fputs ("i", file);
2772 return;
2773 case 'M':
2774 switch (GET_CODE (XEXP (x, 0)))
2775 {
2776 case PRE_DEC:
2777 case PRE_INC:
2778 fprintf (file, "s,mb");
2779 break;
2780 case POST_DEC:
2781 case POST_INC:
2782 fprintf (file, "s,ma");
2783 break;
2784 default:
2785 break;
2786 }
2787 return;
2788 case 'F':
2789 switch (GET_CODE (XEXP (x, 0)))
2790 {
2791 case PRE_DEC:
2792 case PRE_INC:
2793 fprintf (file, ",mb");
2794 break;
2795 case POST_DEC:
2796 case POST_INC:
2797 fprintf (file, ",ma");
2798 break;
2799 default:
2800 break;
2801 }
2802 return;
2803 case 'G':
2804 output_global_address (file, x);
2805 return;
2806 case 0: /* Don't do anything special */
2807 break;
2808 case 'Z':
2809 {
2810 unsigned op[3];
2811 compute_zdepi_operands (INTVAL (x), op);
2812 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
2813 return;
2814 }
2815 default:
2816 abort ();
2817 }
2818 if (GET_CODE (x) == REG)
2819 fprintf (file, "%s", reg_names [REGNO (x)]);
2820 else if (GET_CODE (x) == MEM)
2821 {
2822 int size = GET_MODE_SIZE (GET_MODE (x));
2823 rtx base = XEXP (XEXP (x, 0), 0);
2824 switch (GET_CODE (XEXP (x, 0)))
2825 {
2826 case PRE_DEC:
2827 case POST_DEC:
2828 fprintf (file, "-%d(0,%s)", size, reg_names [REGNO (base)]);
2829 break;
2830 case PRE_INC:
2831 case POST_INC:
2832 fprintf (file, "%d(0,%s)", size, reg_names [REGNO (base)]);
2833 break;
2834 default:
2835 output_address (XEXP (x, 0));
2836 break;
2837 }
2838 }
2839 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
2840 {
2841 union { double d; int i[2]; } u;
2842 union { float f; int i; } u1;
2843 u.i[0] = XINT (x, 0); u.i[1] = XINT (x, 1);
2844 u1.f = u.d;
2845 if (code == 'f')
2846 fprintf (file, "0r%.9g", u1.f);
2847 else
2848 fprintf (file, "0x%x", u1.i);
2849 }
2850 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != DImode)
2851 {
2852 union { double d; int i[2]; } u;
2853 u.i[0] = XINT (x, 0); u.i[1] = XINT (x, 1);
2854 fprintf (file, "0r%.20g", u.d);
2855 }
2856 else
2857 output_addr_const (file, x);
2858 }
2859
2860 /* output a SYMBOL_REF or a CONST expression involving a SYMBOL_REF. */
2861
2862 void
2863 output_global_address (file, x)
2864 FILE *file;
2865 rtx x;
2866 {
2867
2868 /* Imagine (high (const (plus ...))). */
2869 if (GET_CODE (x) == HIGH)
2870 x = XEXP (x, 0);
2871
2872 if (GET_CODE (x) == SYMBOL_REF && read_only_operand (x))
2873 assemble_name (file, XSTR (x, 0));
2874 else if (GET_CODE (x) == SYMBOL_REF)
2875 {
2876 assemble_name (file, XSTR (x, 0));
2877 fprintf (file, "-$global$");
2878 }
2879 else if (GET_CODE (x) == CONST)
2880 {
2881 char *sep = "";
2882 int offset = 0; /* assembler wants -$global$ at end */
2883 rtx base;
2884
2885 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)
2886 {
2887 base = XEXP (XEXP (x, 0), 0);
2888 output_addr_const (file, base);
2889 }
2890 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == CONST_INT)
2891 offset = INTVAL (XEXP (XEXP (x, 0), 0));
2892 else abort ();
2893
2894 if (GET_CODE (XEXP (XEXP (x, 0), 1)) == SYMBOL_REF)
2895 {
2896 base = XEXP (XEXP (x, 0), 1);
2897 output_addr_const (file, base);
2898 }
2899 else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
2900 offset = INTVAL (XEXP (XEXP (x, 0),1));
2901 else abort ();
2902
2903 if (GET_CODE (XEXP (x, 0)) == PLUS)
2904 {
2905 if (offset < 0)
2906 {
2907 offset = -offset;
2908 sep = "-";
2909 }
2910 else
2911 sep = "+";
2912 }
2913 else if (GET_CODE (XEXP (x, 0)) == MINUS
2914 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))
2915 sep = "-";
2916 else abort ();
2917
2918 if (!read_only_operand (base))
2919 fprintf (file, "-$global$");
2920 fprintf (file, "%s", sep);
2921 if (offset) fprintf (file,"%d", offset);
2922 }
2923 else
2924 output_addr_const (file, x);
2925 }
2926
2927 /* HP's millicode routines mean something special to the assembler.
2928 Keep track of which ones we have used. */
2929
2930 enum millicodes { remI, remU, divI, divU, mulI, mulU, end1000 };
2931 static char imported[(int)end1000];
2932 static char *milli_names[] = {"remI", "remU", "divI", "divU", "mulI", "mulU"};
2933 static char import_string[] = ".IMPORT $$....,MILLICODE";
2934 #define MILLI_START 10
2935
2936 static int
2937 import_milli (code)
2938 enum millicodes code;
2939 {
2940 char str[sizeof (import_string)];
2941
2942 if (!imported[(int)code])
2943 {
2944 imported[(int)code] = 1;
2945 strcpy (str, import_string);
2946 strncpy (str + MILLI_START, milli_names[(int)code], 4);
2947 output_asm_insn (str, 0);
2948 }
2949 }
2950
2951 /* The register constraints have put the operands and return value in
2952 the proper registers. */
2953
2954 char *
2955 output_mul_insn (unsignedp, insn)
2956 int unsignedp;
2957 rtx insn;
2958 {
2959
2960 if (unsignedp)
2961 {
2962 import_milli (mulU);
2963 return output_call (insn, gen_rtx (SYMBOL_REF, SImode, "$$mulU"),
2964 gen_rtx (REG, SImode, 31));
2965 }
2966 else
2967 {
2968 import_milli (mulI);
2969 return output_call (insn, gen_rtx (SYMBOL_REF, SImode, "$$mulI"),
2970 gen_rtx (REG, SImode, 31));
2971 }
2972 }
2973
2974 /* If operands isn't NULL, then it's a CONST_INT with which we can do
2975 something */
2976
2977
2978 /* Emit the rtl for doing a division by a constant. */
2979
2980 /* Do magic division millicodes exist for this value? */
2981
2982 static int magic_milli[]= {0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0,
2983 1, 1};
2984
2985 /* We'll use an array to keep track of the magic millicodes and
2986 whether or not we've used them already. [n][0] is signed, [n][1] is
2987 unsigned. */
2988
2989 static int div_milli[16][2];
2990
2991 int
2992 div_operand (op, mode)
2993 rtx op;
2994 enum machine_mode mode;
2995 {
2996 return (mode == SImode
2997 && ((GET_CODE (op) == REG && REGNO (op) == 25)
2998 || (GET_CODE (op) == CONST_INT && INTVAL (op) > 0
2999 && INTVAL (op) < 16 && magic_milli[INTVAL (op)])));
3000 }
3001
3002 int
3003 emit_hpdiv_const (operands, unsignedp)
3004 rtx *operands;
3005 int unsignedp;
3006 {
3007 if (GET_CODE (operands[2]) == CONST_INT
3008 && INTVAL (operands[2]) > 0
3009 && INTVAL (operands[2]) < 16
3010 && magic_milli[INTVAL (operands[2])])
3011 {
3012 emit_move_insn ( gen_rtx (REG, SImode, 26), operands[1]);
3013 emit
3014 (gen_rtx
3015 (PARALLEL, VOIDmode,
3016 gen_rtvec (5, gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, 29),
3017 gen_rtx (unsignedp ? UDIV : DIV, SImode,
3018 gen_rtx (REG, SImode, 26),
3019 operands[2])),
3020 gen_rtx (CLOBBER, VOIDmode, operands[3]),
3021 gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, SImode, 26)),
3022 gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, SImode, 25)),
3023 gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, SImode, 31)))));
3024 emit_move_insn (operands[0], gen_rtx (REG, SImode, 29));
3025 return 1;
3026 }
3027 return 0;
3028 }
3029
3030 char *
3031 output_div_insn (operands, unsignedp, insn)
3032 rtx *operands;
3033 int unsignedp;
3034 rtx insn;
3035 {
3036 int divisor;
3037
3038 /* If the divisor is a constant, try to use one of the special
3039 opcodes .*/
3040 if (GET_CODE (operands[0]) == CONST_INT)
3041 {
3042 static char buf[100];
3043 divisor = INTVAL (operands[0]);
3044 if (!div_milli[divisor][unsignedp])
3045 {
3046 div_milli[divisor][unsignedp] = 1;
3047 if (unsignedp)
3048 output_asm_insn (".IMPORT $$divU_%0,MILLICODE", operands);
3049 else
3050 output_asm_insn (".IMPORT $$divI_%0,MILLICODE", operands);
3051 }
3052 if (unsignedp)
3053 {
3054 sprintf (buf, "$$divU_%d", INTVAL (operands[0]));
3055 return output_call (insn, gen_rtx (SYMBOL_REF, SImode, buf),
3056 gen_rtx (REG, SImode, 31));
3057 }
3058 else
3059 {
3060 sprintf (buf, "$$divI_%d", INTVAL (operands[0]));
3061 return output_call (insn, gen_rtx (SYMBOL_REF, SImode, buf),
3062 gen_rtx (REG, SImode, 31));
3063 }
3064 }
3065 /* Divisor isn't a special constant. */
3066 else
3067 {
3068 if (unsignedp)
3069 {
3070 import_milli (divU);
3071 return output_call (insn, gen_rtx (SYMBOL_REF, SImode, "$$divU"),
3072 gen_rtx (REG, SImode, 31));
3073 }
3074 else
3075 {
3076 import_milli (divI);
3077 return output_call (insn, gen_rtx (SYMBOL_REF, SImode, "$$divI"),
3078 gen_rtx (REG, SImode, 31));
3079 }
3080 }
3081 }
3082
3083 /* Output a $$rem millicode to do mod. */
3084
3085 char *
3086 output_mod_insn (unsignedp, insn)
3087 int unsignedp;
3088 rtx insn;
3089 {
3090 if (unsignedp)
3091 {
3092 import_milli (remU);
3093 return output_call (insn, gen_rtx (SYMBOL_REF, SImode, "$$remU"),
3094 gen_rtx (REG, SImode, 31));
3095 }
3096 else
3097 {
3098 import_milli (remI);
3099 return output_call (insn, gen_rtx (SYMBOL_REF, SImode, "$$remI"),
3100 gen_rtx (REG, SImode, 31));
3101 }
3102 }
3103
3104 void
3105 output_arg_descriptor (insn)
3106 rtx insn;
3107 {
3108 char *arg_regs[4];
3109 enum machine_mode arg_mode;
3110 rtx prev_insn;
3111 int i, output_flag = 0;
3112 int regno;
3113
3114 for (i = 0; i < 4; i++)
3115 arg_regs[i] = 0;
3116
3117 for (prev_insn = PREV_INSN (insn); GET_CODE (prev_insn) == INSN;
3118 prev_insn = PREV_INSN (prev_insn))
3119 {
3120 if (!(GET_CODE (PATTERN (prev_insn)) == USE &&
3121 GET_CODE (XEXP (PATTERN (prev_insn), 0)) == REG &&
3122 FUNCTION_ARG_REGNO_P (REGNO (XEXP (PATTERN (prev_insn), 0)))))
3123 break;
3124 arg_mode = GET_MODE (XEXP (PATTERN (prev_insn), 0));
3125 regno = REGNO (XEXP (PATTERN (prev_insn), 0));
3126 if (regno >= 23 && regno <= 26)
3127 {
3128 arg_regs[26 - regno] = "GR";
3129 if (arg_mode == DImode)
3130 arg_regs[25 - regno] = "GR";
3131 }
3132 else if (!TARGET_SNAKE) /* fp args */
3133 {
3134 if (arg_mode == SFmode)
3135 arg_regs[regno - 32] = "FR";
3136 else
3137 {
3138 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
3139 arg_regs[regno - 33] = "FR";
3140 arg_regs[regno - 32] = "FU";
3141 #else
3142 arg_regs[regno - 33] = "FU";
3143 arg_regs[regno - 32] = "FR";
3144 #endif
3145 }
3146 }
3147 else
3148 {
3149 if (arg_mode == SFmode)
3150 arg_regs[(regno - 44) / 2] = "FR";
3151 else
3152 {
3153 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
3154 arg_regs[(regno - 46) / 2] = "FR";
3155 arg_regs[(regno - 46) / 2 + 1] = "FU";
3156 #else
3157 arg_regs[(regno - 46) / 2] = "FU";
3158 arg_regs[(regno - 46) / 2 + 1] = "FR";
3159 #endif
3160 }
3161 }
3162 }
3163 fputs ("\t.CALL ", asm_out_file);
3164 for (i = 0; i < 4; i++)
3165 {
3166 if (arg_regs[i])
3167 {
3168 if (output_flag++)
3169 fputc (',', asm_out_file);
3170 fprintf (asm_out_file, "ARGW%d=%s", i, arg_regs[i]);
3171 }
3172 }
3173 fputc ('\n', asm_out_file);
3174 }
3175 \f
3176 /* Memory loads/stores to/from the shift need to go through
3177 the general registers. */
3178
3179 enum reg_class
3180 secondary_reload_class (class, mode, in)
3181 enum reg_class class;
3182 enum machine_mode mode;
3183 rtx in;
3184 {
3185 int regno = true_regnum (in);
3186
3187 if (function_label_operand (in, mode)
3188 || ((regno >= FIRST_PSEUDO_REGISTER || regno == -1)
3189 && GET_MODE_CLASS (mode) == MODE_INT
3190 && FP_REG_CLASS_P (class))
3191 || (class == SHIFT_REGS && (regno <= 0 || regno >= 32)))
3192 return GENERAL_REGS;
3193
3194 if (GET_CODE (in) == HIGH)
3195 in = XEXP (in, 0);
3196
3197 if (TARGET_KERNEL && class != R1_REGS && symbolic_operand (in, VOIDmode))
3198 return R1_REGS;
3199
3200 return NO_REGS;
3201 }
3202
3203 enum direction
3204 function_arg_padding (mode, type)
3205 enum machine_mode mode;
3206 tree type;
3207 {
3208 int size;
3209
3210 if (mode == BLKmode)
3211 {
3212 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
3213 size = int_size_in_bytes (type) * BITS_PER_UNIT;
3214 else
3215 return upward; /* Don't know if this is right, but */
3216 /* same as old definition. */
3217 }
3218 else
3219 size = GET_MODE_BITSIZE (mode);
3220 if (size < PARM_BOUNDARY)
3221 return downward;
3222 else if (size % PARM_BOUNDARY)
3223 return upward;
3224 else
3225 return none;
3226 }
3227
3228 \f
3229 /* Do what is necessary for `va_start'. The argument is ignored;
3230 We look at the current function to determine if stdargs or varargs
3231 is used and fill in an initial va_list. A pointer to this constructor
3232 is returned. */
3233
3234 struct rtx_def *
3235 hppa_builtin_saveregs (arglist)
3236 tree arglist;
3237 {
3238 rtx block, float_addr, offset, float_mem;
3239 tree fntype = TREE_TYPE (current_function_decl);
3240 int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
3241 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3242 != void_type_node)))
3243 ? UNITS_PER_WORD : 0);
3244
3245 if (argadj)
3246 offset = plus_constant (current_function_arg_offset_rtx, argadj);
3247 else
3248 offset = current_function_arg_offset_rtx;
3249
3250 /* Store general registers on the stack. */
3251 move_block_from_reg (23,
3252 gen_rtx (MEM, BLKmode,
3253 plus_constant
3254 (current_function_internal_arg_pointer, -16)),
3255 4, 4 * UNITS_PER_WORD);
3256 return copy_to_reg (expand_binop (Pmode, add_optab,
3257 current_function_internal_arg_pointer,
3258 offset, 0, 0, OPTAB_LIB_WIDEN));
3259 }
3260
3261 /* This routine handles all the normal conditional branch sequences we
3262 might need to generate. It handles compare immediate vs compare
3263 register, nullification of delay slots, varying length branches,
3264 negated branches, and all combinations of the above. It returns the
3265 output appropriate to emit the branch corresponding to all given
3266 parameters. */
3267
3268 char *
3269 output_cbranch (operands, nullify, length, negated, insn)
3270 rtx *operands;
3271 int nullify, length, negated;
3272 rtx insn;
3273 {
3274 static char buf[100];
3275 int useskip = 0;
3276
3277 /* A conditional branch to the following instruction (eg the delay slot) is
3278 asking for a disaster. This can happen when not optimizing.
3279
3280 In such cases it is safe to emit nothing. */
3281
3282 if (JUMP_LABEL (insn) == next_nonnote_insn (insn))
3283 return "";
3284
3285 /* If this is a long branch with its delay slot unfilled, set `nullify'
3286 as it can nullify the delay slot and save a nop. */
3287 if (length == 8 && dbr_sequence_length () == 0)
3288 nullify = 1;
3289
3290 /* If this is a short forward conditional branch which did not get
3291 its delay slot filled, the delay slot can still be nullified. */
3292 if (! nullify && length == 4 && dbr_sequence_length () == 0)
3293 nullify = forward_branch_p (insn);
3294
3295 /* A forward branch over a single nullified insn can be done with a
3296 comclr instruction. This avoids a single cycle penalty due to
3297 mis-predicted branch if we fall through (branch not taken). */
3298 if (length == 4
3299 && next_real_insn (insn) != 0
3300 && get_attr_length (next_real_insn (insn)) == 4
3301 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
3302 && nullify)
3303 useskip = 1;
3304
3305 switch (length)
3306 {
3307 /* All short conditional branches except backwards with an unfilled
3308 delay slot. */
3309 case 4:
3310 if (useskip)
3311 strcpy (buf, "com%I2clr,");
3312 else
3313 strcpy (buf, "com%I2b,");
3314 if (negated)
3315 strcat (buf, "%B3");
3316 else
3317 strcat (buf, "%S3");
3318 if (useskip)
3319 strcat (buf, " %2,%1,0");
3320 else if (nullify)
3321 strcat (buf, ",n %2,%1,%0");
3322 else
3323 strcat (buf, " %2,%1,%0");
3324 break;
3325
3326 /* All long conditionals. Note an short backward branch with an
3327 unfilled delay slot is treated just like a long backward branch
3328 with an unfilled delay slot. */
3329 case 8:
3330 /* Handle weird backwards branch with a filled delay slot
3331 with is nullified. */
3332 if (dbr_sequence_length () != 0
3333 && ! forward_branch_p (insn)
3334 && nullify)
3335 {
3336 strcpy (buf, "com%I2b,");
3337 if (negated)
3338 strcat (buf, "%S3");
3339 else
3340 strcat (buf, "%B3");
3341 strcat (buf, ",n %2,%1,.+12\n\tbl %0,0");
3342 }
3343 else
3344 {
3345 strcpy (buf, "com%I2clr,");
3346 if (negated)
3347 strcat (buf, "%S3");
3348 else
3349 strcat (buf, "%B3");
3350 if (nullify)
3351 strcat (buf, " %2,%1,0\n\tbl,n %0,0");
3352 else
3353 strcat (buf, " %2,%1,0\n\tbl %0,0");
3354 }
3355 break;
3356
3357 default:
3358 abort();
3359 }
3360 return buf;
3361 }
3362
3363 /* This routine handles all the branch-on-bit conditional branch sequences we
3364 might need to generate. It handles nullification of delay slots,
3365 varying length branches, negated branches and all combinations of the
3366 above. it returns the appropriate output template to emit the branch. */
3367
3368 char *
3369 output_bb (operands, nullify, length, negated, insn, which)
3370 rtx *operands;
3371 int nullify, length, negated;
3372 rtx insn;
3373 int which;
3374 {
3375 static char buf[100];
3376 int useskip = 0;
3377
3378 /* A conditional branch to the following instruction (eg the delay slot) is
3379 asking for a disaster. I do not think this can happen as this pattern
3380 is only used when optimizing; jump optimization should eliminate the
3381 jump. But be prepared just in case. */
3382
3383 if (JUMP_LABEL (insn) == next_nonnote_insn (insn))
3384 return "";
3385
3386 /* If this is a long branch with its delay slot unfilled, set `nullify'
3387 as it can nullify the delay slot and save a nop. */
3388 if (length == 8 && dbr_sequence_length () == 0)
3389 nullify = 1;
3390
3391 /* If this is a short forward conditional branch which did not get
3392 its delay slot filled, the delay slot can still be nullified. */
3393 if (! nullify && length == 4 && dbr_sequence_length () == 0)
3394 nullify = forward_branch_p (insn);
3395
3396 /* A forward branch over a single nullified insn can be done with a
3397 extrs instruction. This avoids a single cycle penalty due to
3398 mis-predicted branch if we fall through (branch not taken). */
3399
3400 if (length == 4
3401 && next_real_insn (insn) != 0
3402 && get_attr_length (next_real_insn (insn)) == 4
3403 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
3404 && nullify)
3405 useskip = 1;
3406
3407 switch (length)
3408 {
3409
3410 /* All short conditional branches except backwards with an unfilled
3411 delay slot. */
3412 case 4:
3413 if (useskip)
3414 strcpy (buf, "extrs,");
3415 else
3416 strcpy (buf, "bb,");
3417 if ((which == 0 && negated)
3418 || (which == 1 && ! negated))
3419 strcat (buf, ">=");
3420 else
3421 strcat (buf, "<");
3422 if (useskip)
3423 strcat (buf, " %0,%1,1,0");
3424 else if (nullify && negated)
3425 strcat (buf, ",n %0,%1,%3");
3426 else if (nullify && ! negated)
3427 strcat (buf, ",n %0,%1,%2");
3428 else if (! nullify && negated)
3429 strcat (buf, "%0,%1,%3");
3430 else if (! nullify && ! negated)
3431 strcat (buf, " %0,%1,%2");
3432 break;
3433
3434 /* All long conditionals. Note an short backward branch with an
3435 unfilled delay slot is treated just like a long backward branch
3436 with an unfilled delay slot. */
3437 case 8:
3438 /* Handle weird backwards branch with a filled delay slot
3439 with is nullified. */
3440 if (dbr_sequence_length () != 0
3441 && ! forward_branch_p (insn)
3442 && nullify)
3443 {
3444 strcpy (buf, "bb,");
3445 if ((which == 0 && negated)
3446 || (which == 1 && ! negated))
3447 strcat (buf, "<");
3448 else
3449 strcat (buf, ">=");
3450 if (negated)
3451 strcat (buf, " %0,%1,.+12\n\tbl %3,0");
3452 else
3453 strcat (buf, " %0,%1,.+12\n\tbl %2,0");
3454 }
3455 else
3456 {
3457 strcpy (buf, "extrs,");
3458 if ((which == 0 && negated)
3459 || (which == 1 && ! negated))
3460 strcat (buf, "<");
3461 else
3462 strcat (buf, ">=");
3463 if (nullify && negated)
3464 strcat (buf, " %0,%1,1,0\n\tbl,n %3,0");
3465 else if (nullify && ! negated)
3466 strcat (buf, " %0,%1,1,0\n\tbl,n %2,0");
3467 else if (negated)
3468 strcat (buf, " %0,%1,1,0\n\tbl %3,0");
3469 else
3470 strcat (buf, " %0,%1,1,0\n\tbl %2,0");
3471 }
3472 break;
3473
3474 default:
3475 abort();
3476 }
3477 return buf;
3478 }
3479
3480 /* Return the output template for emitting a dbra type insn.
3481
3482 Note it may perform some output operations on its own before
3483 returning the final output string. */
3484 char *
3485 output_dbra (operands, insn, which_alternative)
3486 rtx *operands;
3487 rtx insn;
3488 int which_alternative;
3489 {
3490
3491 /* A conditional branch to the following instruction (eg the delay slot) is
3492 asking for a disaster. Be prepared! */
3493
3494 if (JUMP_LABEL (insn) == next_nonnote_insn (insn))
3495 {
3496 if (which_alternative == 0)
3497 return "ldo %1(%0),%0";
3498 else if (which_alternative == 1)
3499 {
3500 output_asm_insn ("fstws %0,-16(0,%%r30)",operands);
3501 output_asm_insn ("ldw -16(0,%%r30),%4",operands);
3502 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(0,%%r30)", operands);
3503 return "fldws -16(0,%%r30),%0";
3504 }
3505 else
3506 {
3507 output_asm_insn ("ldw %0,%4", operands);
3508 return "ldo %1(%4),%4\n\tstw %4,%0";
3509 }
3510 }
3511
3512 if (which_alternative == 0)
3513 {
3514 int nullify = INSN_ANNULLED_BRANCH_P (insn);
3515 int length = get_attr_length (insn);
3516
3517 /* If this is a long branch with its delay slot unfilled, set `nullify'
3518 as it can nullify the delay slot and save a nop. */
3519 if (length == 8 && dbr_sequence_length () == 0)
3520 nullify = 1;
3521
3522 /* If this is a short forward conditional branch which did not get
3523 its delay slot filled, the delay slot can still be nullified. */
3524 if (! nullify && length == 4 && dbr_sequence_length () == 0)
3525 nullify = forward_branch_p (insn);
3526
3527 /* Handle short versions first. */
3528 if (length == 4 && nullify)
3529 return "addib,%C2,n %1,%0,%3";
3530 else if (length == 4 && ! nullify)
3531 return "addib,%C2 %1,%0,%3";
3532 else if (length == 8)
3533 {
3534 /* Handle weird backwards branch with a fulled delay slot
3535 which is nullified. */
3536 if (dbr_sequence_length () != 0
3537 && ! forward_branch_p (insn)
3538 && nullify)
3539 return "addib,%N2,n %1,%0,.+12\n\tbl %3,0";
3540
3541 /* Handle normal cases. */
3542 if (nullify)
3543 return "addi,%N2 %1,%0,%0\n\tbl,n %3,0";
3544 else
3545 return "addi,%N2 %1,%0,%0\n\tbl %3,0";
3546 }
3547 else
3548 abort();
3549 }
3550 /* Deal with gross reload from FP register case. */
3551 else if (which_alternative == 1)
3552 {
3553 /* Move loop counter from FP register to MEM then into a GR,
3554 increment the GR, store the GR into MEM, and finally reload
3555 the FP register from MEM from within the branch's delay slot. */
3556 output_asm_insn ("fstws %0,-16(0,%%r30)\n\tldw -16(0,%%r30),%4",operands);
3557 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(0,%%r30)", operands);
3558 if (get_attr_length (insn) == 24)
3559 return "comb,%S2 0,%4,%3\n\tfldws -16(0,%%r30),%0";
3560 else
3561 return "comclr,%B2 0,%4,0\n\tbl %3,0\n\tfldws -16(0,%%r30),%0";
3562 }
3563 /* Deal with gross reload from memory case. */
3564 else
3565 {
3566 /* Reload loop counter from memory, the store back to memory
3567 happens in the branch's delay slot. */
3568 output_asm_insn ("ldw %0,%4", operands);
3569 if (get_attr_length (insn) == 12)
3570 return "addib,%C2 %1,%4,%3\n\tstw %4,%0";
3571 else
3572 return "addi,%N2 %1,%4,%0\n\tbl %3,0\n\tstw %4,%0";
3573 }
3574 }
3575
3576 /* Return the output template for emitting a dbra type insn.
3577
3578 Note it may perform some output operations on its own before
3579 returning the final output string. */
3580 char *
3581 output_movb (operands, insn, which_alternative, reverse_comparison)
3582 rtx *operands;
3583 rtx insn;
3584 int which_alternative;
3585 int reverse_comparison;
3586 {
3587
3588 /* A conditional branch to the following instruction (eg the delay slot) is
3589 asking for a disaster. Be prepared! */
3590
3591 if (JUMP_LABEL (insn) == next_nonnote_insn (insn))
3592 {
3593 if (which_alternative == 0)
3594 return "copy %1,%0";
3595 else if (which_alternative == 1)
3596 {
3597 output_asm_insn ("stw %1,-16(0,%%r30)",operands);
3598 return "fldws -16(0,%%r30),%0";
3599 }
3600 else
3601 return "stw %1,%0";
3602 }
3603
3604 /* Support the second variant. */
3605 if (reverse_comparison)
3606 PUT_CODE (operands[2], reverse_condition (GET_CODE (operands[2])));
3607
3608 if (which_alternative == 0)
3609 {
3610 int nullify = INSN_ANNULLED_BRANCH_P (insn);
3611 int length = get_attr_length (insn);
3612
3613 /* If this is a long branch with its delay slot unfilled, set `nullify'
3614 as it can nullify the delay slot and save a nop. */
3615 if (length == 8 && dbr_sequence_length () == 0)
3616 nullify = 1;
3617
3618 /* If this is a short forward conditional branch which did not get
3619 its delay slot filled, the delay slot can still be nullified. */
3620 if (! nullify && length == 4 && dbr_sequence_length () == 0)
3621 nullify = forward_branch_p (insn);
3622
3623 /* Handle short versions first. */
3624 if (length == 4 && nullify)
3625 return "movb,%C2,n %1,%0,%3";
3626 else if (length == 4 && ! nullify)
3627 return "movb,%C2 %1,%0,%3";
3628 else if (length == 8)
3629 {
3630 /* Handle weird backwards branch with a fulled delay slot
3631 which is nullified. */
3632 if (dbr_sequence_length () != 0
3633 && ! forward_branch_p (insn)
3634 && nullify)
3635 return "movb,%N2,n %1,%0,.+12\n\ttbl %3,0";
3636
3637 /* Handle normal cases. */
3638 if (nullify)
3639 return "or,%N2 %1,%%r0,%0\n\tbl,n %3,0";
3640 else
3641 return "or,%N2 %1,%%r0,%0\n\tbl %3,0";
3642 }
3643 else
3644 abort();
3645 }
3646 /* Deal with gross reload from FP register case. */
3647 else if (which_alternative == 1)
3648 {
3649 /* Move loop counter from FP register to MEM then into a GR,
3650 increment the GR, store the GR into MEM, and finally reload
3651 the FP register from MEM from within the branch's delay slot. */
3652 output_asm_insn ("stw %1,-16(0,%%r30)",operands);
3653 if (get_attr_length (insn) == 12)
3654 return "comb,%S2 0,%1,%3\n\tfldws -16(0,%%r30),%0";
3655 else
3656 return "comclr,%B2 0,%1,0\n\tbl %3,0\n\tfldws -16(0,%%r30),%0";
3657 }
3658 /* Deal with gross reload from memory case. */
3659 else
3660 {
3661 /* Reload loop counter from memory, the store back to memory
3662 happens in the branch's delay slot. */
3663 if (get_attr_length (insn) == 8)
3664 return "comb,%S2 0,%1,%3\n\tstw %1,%0";
3665 else
3666 return "comclr,%B2 0,%1,0\n\tbl %3,0\n\tstw %1,%0";
3667 }
3668 }
3669
3670
3671 /* INSN is either a function call or a millicode call. It may have an
3672 unconditional jump in its delay slot.
3673
3674 CALL_DEST is the routine we are calling.
3675
3676 RETURN_POINTER is the register which will hold the return address.
3677 %r2 for most calls, %r31 for millicode calls. */
3678 char *
3679 output_call (insn, call_dest, return_pointer)
3680 rtx insn;
3681 rtx call_dest;
3682 rtx return_pointer;
3683
3684 {
3685 int distance;
3686 rtx xoperands[4];
3687 rtx seq_insn;
3688
3689 /* Handle common case -- empty delay slot or no jump in the delay slot. */
3690 if (dbr_sequence_length () == 0
3691 || (dbr_sequence_length () != 0
3692 && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN))
3693 {
3694 xoperands[0] = call_dest;
3695 xoperands[1] = return_pointer;
3696 output_asm_insn ("bl %0,%r1%#", xoperands);
3697 return "";
3698 }
3699
3700 /* This call has an unconditional jump in its delay slot. */
3701
3702 /* Use the containing sequence insn's address. */
3703 seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
3704
3705 distance = insn_addresses[INSN_UID (JUMP_LABEL (NEXT_INSN (insn)))]
3706 - insn_addresses[INSN_UID (seq_insn)] - 8;
3707
3708 /* If the branch was too far away, emit a normal call followed
3709 by a nop, followed by the unconditional branch.
3710
3711 If the branch is close, then adjust %r2 from within the
3712 call's delay slot. */
3713
3714 xoperands[0] = call_dest;
3715 xoperands[1] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
3716 xoperands[2] = return_pointer;
3717 if (! VAL_14_BITS_P (distance))
3718 output_asm_insn ("bl %0,%r2\n\tnop\n\tbl,n %1,%%r0", xoperands);
3719 else
3720 {
3721 xoperands[3] = gen_label_rtx ();
3722 output_asm_label (xoperands[3]);
3723 output_asm_insn ("\n\tbl %0,%r2\n\tldo %1-%3-8(%r2),%r2", xoperands);
3724 }
3725
3726 /* Delete the jump. */
3727 PUT_CODE (NEXT_INSN (insn), NOTE);
3728 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
3729 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
3730 return "";
3731 }
3732
3733 extern struct obstack *saveable_obstack;
3734
3735 /* In HPUX 8.0's shared library scheme, special relocations are needed
3736 for function labels if they might be passed to a function
3737 in a shared library (because shared libraries don't live in code
3738 space), and special magic is needed to construct their address. */
3739
3740 void
3741 hppa_encode_label (sym)
3742 rtx sym;
3743 {
3744 char *str = XSTR (sym, 0);
3745 int len = strlen (str);
3746 char *newstr = obstack_alloc (saveable_obstack, len + 2) ;
3747
3748 if (str[0] == '*')
3749 *newstr++ = *str++;
3750 strcpy (newstr + 1, str);
3751 *newstr = '@';
3752 XSTR (sym,0) = newstr;
3753 }
3754
3755 int
3756 function_label_operand (op, mode)
3757 rtx op;
3758 enum machine_mode mode;
3759 {
3760 return GET_CODE (op) == SYMBOL_REF && FUNCTION_NAME_P (XSTR (op, 0));
3761 }
3762
3763 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
3764 use in fmpyadd instructions. */
3765 int
3766 fmpyaddoperands(operands)
3767 rtx *operands;
3768 {
3769 enum machine_mode mode = GET_MODE (operands[0]);
3770
3771 /* All modes must be the same. */
3772 if (! (mode == GET_MODE (operands[1])
3773 && mode == GET_MODE (operands[2])
3774 && mode == GET_MODE (operands[3])
3775 && mode == GET_MODE (operands[4])
3776 && mode == GET_MODE (operands[5])))
3777 return 0;
3778
3779 /* Both DFmode and SFmode should work. But using SFmode makes the
3780 assembler complain. Just turn it off for now. */
3781 if (mode != DFmode)
3782 return 0;
3783
3784 /* Only 2 real operands to the addition. One of the input operands must
3785 be the same as the output operand. */
3786 if (! rtx_equal_p (operands[3], operands[4])
3787 && ! rtx_equal_p (operands[3], operands[5]))
3788 return 0;
3789
3790 /* Inout operand of add can not conflict with any operands from multiply. */
3791 if (rtx_equal_p (operands[3], operands[0])
3792 || rtx_equal_p (operands[3], operands[1])
3793 || rtx_equal_p (operands[3], operands[2]))
3794 return 0;
3795
3796 /* multiply can not feed into addition operands. */
3797 if (rtx_equal_p (operands[4], operands[0])
3798 || rtx_equal_p (operands[5], operands[0]))
3799 return 0;
3800
3801 /* Passed. Operands are suitable for fmpyadd. */
3802 return 1;
3803 }
3804
3805 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
3806 use in fmpysub instructions. */
3807 int
3808 fmpysuboperands(operands)
3809 rtx *operands;
3810 {
3811 enum machine_mode mode = GET_MODE (operands[0]);
3812
3813 /* All modes must be the same. */
3814 if (! (mode == GET_MODE (operands[1])
3815 && mode == GET_MODE (operands[2])
3816 && mode == GET_MODE (operands[3])
3817 && mode == GET_MODE (operands[4])
3818 && mode == GET_MODE (operands[5])))
3819 return 0;
3820
3821 /* Both DFmode and SFmode should work. But using SFmode makes the
3822 assembler complain. Just turn it off for now. */
3823 if (mode != DFmode)
3824 return 0;
3825
3826 /* Only 2 real operands to the subtraction. Subtraction is not a commutative
3827 operation, so operands[4] must be the same as operand[3]. */
3828 if (! rtx_equal_p (operands[3], operands[4]))
3829 return 0;
3830
3831 /* multiply can not feed into subtraction. */
3832 if (rtx_equal_p (operands[5], operands[0]))
3833 return 0;
3834
3835 /* Inout operand of sub can not conflict with any operands from multiply. */
3836 if (rtx_equal_p (operands[3], operands[0])
3837 || rtx_equal_p (operands[3], operands[1])
3838 || rtx_equal_p (operands[3], operands[2]))
3839 return 0;
3840
3841 /* Passed. Operands are suitable for fmpysub. */
3842 return 1;
3843 }
3844
3845 int
3846 plus_xor_ior_operator (op, mode)
3847 rtx op;
3848 enum machine_mode mode;
3849 {
3850 return (GET_CODE (op) == PLUS || GET_CODE (op) == XOR
3851 || GET_CODE (op) == IOR);
3852 }
3853
3854 /* Return 1 if the given constant is 2, 4, or 8. These are the valid
3855 constants for shadd instructions. */
3856 int
3857 shadd_constant_p (val)
3858 int val;
3859 {
3860 if (val == 2 || val == 4 || val == 8)
3861 return 1;
3862 else
3863 return 0;
3864 }
3865
3866 /* Return 1 if OP is a CONST_INT with the value 2, 4, or 8. These are
3867 the valid constant for shadd instructions. */
3868 int
3869 shadd_operand (op, mode)
3870 rtx op;
3871 enum machine_mode mode;
3872 {
3873 return (GET_CODE (op) == CONST_INT && shadd_constant_p (INTVAL (op)));
3874 }
3875
3876 /* Return 1 if INSN branches forward. Should be using insn_addresses
3877 to avoid walking through all the insns... */
3878 int
3879 forward_branch_p (insn)
3880 rtx insn;
3881 {
3882 rtx label = JUMP_LABEL (insn);
3883
3884 while (insn)
3885 {
3886 if (insn == label)
3887 break;
3888 else
3889 insn = NEXT_INSN (insn);
3890 }
3891
3892 return (insn == label);
3893 }
3894
3895 /* Return 1 if OP is an equality comparison, else return 0. */
3896 int
3897 eq_neq_comparison_operator (op, mode)
3898 rtx op;
3899 enum machine_mode mode;
3900 {
3901 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
3902 }
3903
3904 /* Return 1 if OP is an operator suitable for use in a movb instruction. */
3905 int
3906 movb_comparison_operator (op, mode)
3907 rtx op;
3908 enum machine_mode mode;
3909 {
3910 return (GET_CODE (op) == EQ || GET_CODE (op) == NE
3911 || GET_CODE (op) == LT || GET_CODE (op) == GE);
3912 }
3913
3914 /* Return 1 if INSN is in the delay slot of a call instruction. */
3915 int
3916 jump_in_call_delay (insn)
3917 rtx insn;
3918 {
3919
3920 if (GET_CODE (insn) != JUMP_INSN)
3921 return 0;
3922
3923 if (PREV_INSN (insn)
3924 && PREV_INSN (PREV_INSN (insn))
3925 && GET_CODE (next_active_insn (PREV_INSN (PREV_INSN (insn)))) == INSN)
3926 {
3927 rtx test_insn = next_active_insn (PREV_INSN (PREV_INSN (insn)));
3928
3929 return (GET_CODE (PATTERN (test_insn)) == SEQUENCE
3930 && XVECEXP (PATTERN (test_insn), 0, 1) == insn);
3931
3932 }
3933 else
3934 return 0;
3935 }
3936