]> gcc.gnu.org Git - gcc.git/blame - gcc/config/rs6000/rs6000.c
(MASK_*, TARGET_*): Add target masks and tests.
[gcc.git] / gcc / config / rs6000 / rs6000.c
CommitLineData
9878760c 1/* Subroutines used for code generation on IBM RS/6000.
11e5fe42 2 Copyright (C) 1991, 1993 Free Software Foundation, Inc.
9878760c
RK
3 Contributed by Richard Kenner (kenner@nyu.edu)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the 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 "recog.h"
34#include "expr.h"
35#include "obstack.h"
9b30bae2
JW
36#include "tree.h"
37
38extern char *language_string;
9878760c
RK
39
40#define min(A,B) ((A) < (B) ? (A) : (B))
41#define max(A,B) ((A) > (B) ? (A) : (B))
42
9878760c
RK
43/* Set to non-zero by "fix" operation to indicate that itrunc and
44 uitrunc must be defined. */
45
46int rs6000_trunc_used;
47
48/* Set to non-zero once they have been defined. */
49
50static int trunc_defined;
51
52/* Save information from a "cmpxx" operation until the branch or scc is
53 emitted. */
54
55rtx rs6000_compare_op0, rs6000_compare_op1;
56int rs6000_compare_fp_p;
57\f
58/* Return non-zero if this function is known to have a null epilogue. */
59
60int
61direct_return ()
62{
63 return (reload_completed
64 && first_reg_to_save () == 32
65 && first_fp_reg_to_save () == 64
66 && ! regs_ever_live[65]
67 && ! rs6000_pushes_stack ());
68}
69
70/* Returns 1 always. */
71
72int
73any_operand (op, mode)
74 register rtx op;
75 enum machine_mode mode;
76{
77 return 1;
78}
79
80/* Return 1 if OP is a constant that can fit in a D field. */
81
82int
83short_cint_operand (op, mode)
84 register rtx op;
85 enum machine_mode mode;
86{
87 return (GET_CODE (op) == CONST_INT
88 && (unsigned) (INTVAL (op) + 0x8000) < 0x10000);
89}
90
91/* Similar for a unsigned D field. */
92
93int
94u_short_cint_operand (op, mode)
95 register rtx op;
96 enum machine_mode mode;
97{
98 return (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0);
99}
100
dcfedcd0
RK
101/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
102
103int
104non_short_cint_operand (op, mode)
105 register rtx op;
106 enum machine_mode mode;
107{
108 return (GET_CODE (op) == CONST_INT
109 && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000);
110}
111
9878760c
RK
112/* Returns 1 if OP is a register that is not special (i.e., not MQ,
113 ctr, or lr). */
114
115int
cd2b37d9 116gpc_reg_operand (op, mode)
9878760c
RK
117 register rtx op;
118 enum machine_mode mode;
119{
120 return (register_operand (op, mode)
121 && (GET_CODE (op) != REG || REGNO (op) >= 67 || REGNO (op) < 64));
122}
123
124/* Returns 1 if OP is either a pseudo-register or a register denoting a
125 CR field. */
126
127int
128cc_reg_operand (op, mode)
129 register rtx op;
130 enum machine_mode mode;
131{
132 return (register_operand (op, mode)
133 && (GET_CODE (op) != REG
134 || REGNO (op) >= FIRST_PSEUDO_REGISTER
135 || CR_REGNO_P (REGNO (op))));
136}
137
138/* Returns 1 if OP is either a constant integer valid for a D-field or a
139 non-special register. If a register, it must be in the proper mode unless
140 MODE is VOIDmode. */
141
142int
143reg_or_short_operand (op, mode)
144 register rtx op;
145 enum machine_mode mode;
146{
147 if (GET_CODE (op) == CONST_INT)
148 return short_cint_operand (op, mode);
149
cd2b37d9 150 return gpc_reg_operand (op, mode);
9878760c
RK
151}
152
153/* Similar, except check if the negation of the constant would be valid for
154 a D-field. */
155
156int
157reg_or_neg_short_operand (op, mode)
158 register rtx op;
159 enum machine_mode mode;
160{
161 if (GET_CODE (op) == CONST_INT)
162 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
163
cd2b37d9 164 return gpc_reg_operand (op, mode);
9878760c
RK
165}
166
167/* Return 1 if the operand is either a register or an integer whose high-order
168 16 bits are zero. */
169
170int
171reg_or_u_short_operand (op, mode)
172 register rtx op;
173 enum machine_mode mode;
174{
175 if (GET_CODE (op) == CONST_INT
176 && (INTVAL (op) & 0xffff0000) == 0)
177 return 1;
178
cd2b37d9 179 return gpc_reg_operand (op, mode);
9878760c
RK
180}
181
182/* Return 1 is the operand is either a non-special register or ANY
183 constant integer. */
184
185int
186reg_or_cint_operand (op, mode)
187 register rtx op;
188 enum machine_mode mode;
189{
cd2b37d9 190 return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode);
9878760c
RK
191}
192
193/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
194 register with one instruction per word. For SFmode, this means that
195 the low 16-bits are zero. For DFmode, it means the low 16-bits of
196 the first word are zero and the high 16 bits of the second word
197 are zero (usually all bits in the low-order word will be zero).
198
199 We only do this if we can safely read CONST_DOUBLE_{LOW,HIGH}. */
200
201int
202easy_fp_constant (op, mode)
203 register rtx op;
204 register enum machine_mode mode;
205{
206 rtx low, high;
207
208 if (GET_CODE (op) != CONST_DOUBLE
209 || GET_MODE (op) != mode
210 || GET_MODE_CLASS (mode) != MODE_FLOAT)
211 return 0;
212
213 high = operand_subword (op, 0, 0, mode);
214 low = operand_subword (op, 1, 0, mode);
215
216 if (high == 0 || GET_CODE (high) != CONST_INT || (INTVAL (high) & 0xffff))
217 return 0;
218
219 return (mode == SFmode
220 || (low != 0 && GET_CODE (low) == CONST_INT
221 && (INTVAL (low) & 0xffff0000) == 0));
222}
223
224/* Return 1 if the operand is either a floating-point register, a pseudo
225 register, or memory. */
226
227int
228fp_reg_or_mem_operand (op, mode)
229 register rtx op;
230 enum machine_mode mode;
231{
232 return (memory_operand (op, mode)
233 || (register_operand (op, mode)
234 && (GET_CODE (op) != REG
235 || REGNO (op) >= FIRST_PSEUDO_REGISTER
236 || FP_REGNO_P (REGNO (op)))));
237}
238
239/* Return 1 if the operand is either an easy FP constant (see above) or
240 memory. */
241
242int
243mem_or_easy_const_operand (op, mode)
244 register rtx op;
245 enum machine_mode mode;
246{
247 return memory_operand (op, mode) || easy_fp_constant (op, mode);
248}
249
250/* Return 1 if the operand is either a non-special register or an item
251 that can be used as the operand of an SI add insn. */
252
253int
254add_operand (op, mode)
255 register rtx op;
256 enum machine_mode mode;
257{
258 return (reg_or_short_operand (op, mode)
259 || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0));
260}
261
dcfedcd0
RK
262/* Return 1 if OP is a constant but not a valid add_operand. */
263
264int
265non_add_cint_operand (op, mode)
266 register rtx op;
267 enum machine_mode mode;
268{
269 return (GET_CODE (op) == CONST_INT
270 && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000
271 && (INTVAL (op) & 0xffff) != 0);
272}
273
9878760c
RK
274/* Return 1 if the operand is a non-special register or a constant that
275 can be used as the operand of an OR or XOR insn on the RS/6000. */
276
277int
278logical_operand (op, mode)
279 register rtx op;
280 enum machine_mode mode;
281{
cd2b37d9 282 return (gpc_reg_operand (op, mode)
9878760c
RK
283 || (GET_CODE (op) == CONST_INT
284 && ((INTVAL (op) & 0xffff0000) == 0
285 || (INTVAL (op) & 0xffff) == 0)));
286}
287
dcfedcd0
RK
288/* Return 1 if C is a constant that is not a logical operand (as
289 above). */
290
291int
292non_logical_cint_operand (op, mode)
293 register rtx op;
294 enum machine_mode mode;
295{
296 return (GET_CODE (op) == CONST_INT
297 && (INTVAL (op) & 0xffff0000) != 0
298 && (INTVAL (op) & 0xffff) != 0);
299}
300
9878760c
RK
301/* Return 1 if C is a constant that can be encoded in a mask on the
302 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
303 Reject all ones and all zeros, since these should have been optimized
304 away and confuse the making of MB and ME. */
305
306int
307mask_constant (c)
308 register int c;
309{
310 int i;
311 int last_bit_value;
312 int transitions = 0;
313
314 if (c == 0 || c == ~0)
315 return 0;
316
317 last_bit_value = c & 1;
318
319 for (i = 1; i < 32; i++)
320 if (((c >>= 1) & 1) != last_bit_value)
321 last_bit_value ^= 1, transitions++;
322
323 return transitions <= 2;
324}
325
326/* Return 1 if the operand is a constant that is a mask on the RS/6000. */
327
328int
329mask_operand (op, mode)
330 register rtx op;
331 enum machine_mode mode;
332{
333 return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op));
334}
335
336/* Return 1 if the operand is either a non-special register or a
337 constant that can be used as the operand of an RS/6000 logical AND insn. */
338
339int
340and_operand (op, mode)
341 register rtx op;
342 enum machine_mode mode;
343{
344 return (reg_or_short_operand (op, mode)
345 || logical_operand (op, mode)
346 || mask_operand (op, mode));
347}
348
dcfedcd0
RK
349/* Return 1 if the operand is a constant but not a valid operand for an AND
350 insn. */
351
352int
353non_and_cint_operand (op, mode)
354 register rtx op;
355 enum machine_mode mode;
356{
357 return GET_CODE (op) == CONST_INT && ! and_operand (op, mode);
358}
359
9878760c
RK
360/* Return 1 if the operand is a general register or memory operand. */
361
362int
363reg_or_mem_operand (op, mode)
364 register rtx op;
365 register enum machine_mode mode;
366{
cd2b37d9 367 return gpc_reg_operand (op, mode) || memory_operand (op, mode);
9878760c
RK
368}
369
370/* Return 1 if the operand, used inside a MEM, is a valid first argument
371 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
372 forced to lr. */
373
374int
375call_operand (op, mode)
376 register rtx op;
377 enum machine_mode mode;
378{
379 if (mode != VOIDmode && GET_MODE (op) != mode)
380 return 0;
381
382 return (GET_CODE (op) == SYMBOL_REF
383 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
384}
385
2af3d377
RK
386
387/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
388 this file. */
389
390int
391current_file_function_operand (op, mode)
392 register rtx op;
393 enum machine_mode mode;
394{
395 return (GET_CODE (op) == SYMBOL_REF
396 && (SYMBOL_REF_FLAG (op)
397 || op == XEXP (DECL_RTL (current_function_decl), 0)));
398}
399
400
9878760c
RK
401/* Return 1 if this operand is a valid input for a move insn. */
402
403int
404input_operand (op, mode)
405 register rtx op;
406 enum machine_mode mode;
407{
eb4e8003 408 /* Memory is always valid. */
9878760c
RK
409 if (memory_operand (op, mode))
410 return 1;
411
eb4e8003
RK
412 /* For floating-point, easy constants are valid. */
413 if (GET_MODE_CLASS (mode) == MODE_FLOAT
414 && CONSTANT_P (op)
415 && easy_fp_constant (op, mode))
416 return 1;
417
418 /* For floating-point or multi-word mode, the only remaining valid type
419 is a register. */
9878760c
RK
420 if (GET_MODE_CLASS (mode) == MODE_FLOAT
421 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 422 return register_operand (op, mode);
9878760c 423
88fe15a1
RK
424 /* The only cases left are integral modes one word or smaller (we
425 do not get called for MODE_CC values). These can be in any
426 register. */
427 if (register_operand (op, mode))
a8b3aeda 428 return 1;
88fe15a1
RK
429
430 /* For HImode and QImode, any constant is valid. */
431 if ((mode == HImode || mode == QImode)
432 && GET_CODE (op) == CONST_INT)
9878760c
RK
433 return 1;
434
9878760c
RK
435 /* Otherwise, we will be doing this SET with an add, so anything valid
436 for an add will be valid. */
437 return add_operand (op, mode);
438}
439\f
440/* Return 1 if OP is a load multiple operation. It is known to be a
441 PARALLEL and the first section will be tested. */
442
443int
444load_multiple_operation (op, mode)
445 rtx op;
446 enum machine_mode mode;
447{
448 int count = XVECLEN (op, 0);
449 int dest_regno;
450 rtx src_addr;
451 int i;
452
453 /* Perform a quick check so we don't blow up below. */
454 if (count <= 1
455 || GET_CODE (XVECEXP (op, 0, 0)) != SET
456 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
457 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
458 return 0;
459
460 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
461 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
462
463 for (i = 1; i < count; i++)
464 {
465 rtx elt = XVECEXP (op, 0, i);
466
467 if (GET_CODE (elt) != SET
468 || GET_CODE (SET_DEST (elt)) != REG
469 || GET_MODE (SET_DEST (elt)) != SImode
470 || REGNO (SET_DEST (elt)) != dest_regno + i
471 || GET_CODE (SET_SRC (elt)) != MEM
472 || GET_MODE (SET_SRC (elt)) != SImode
473 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
474 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
475 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
476 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
477 return 0;
478 }
479
480 return 1;
481}
482
483/* Similar, but tests for store multiple. Here, the second vector element
484 is a CLOBBER. It will be tested later. */
485
486int
487store_multiple_operation (op, mode)
488 rtx op;
489 enum machine_mode mode;
490{
491 int count = XVECLEN (op, 0) - 1;
492 int src_regno;
493 rtx dest_addr;
494 int i;
495
496 /* Perform a quick check so we don't blow up below. */
497 if (count <= 1
498 || GET_CODE (XVECEXP (op, 0, 0)) != SET
499 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
500 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
501 return 0;
502
503 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
504 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
505
506 for (i = 1; i < count; i++)
507 {
508 rtx elt = XVECEXP (op, 0, i + 1);
509
510 if (GET_CODE (elt) != SET
511 || GET_CODE (SET_SRC (elt)) != REG
512 || GET_MODE (SET_SRC (elt)) != SImode
513 || REGNO (SET_SRC (elt)) != src_regno + i
514 || GET_CODE (SET_DEST (elt)) != MEM
515 || GET_MODE (SET_DEST (elt)) != SImode
516 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
517 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
518 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
519 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
520 return 0;
521 }
522
523 return 1;
524}
525\f
526/* Return 1 if OP is a comparison operation that is valid for a branch insn.
527 We only check the opcode against the mode of the CC value here. */
528
529int
530branch_comparison_operator (op, mode)
531 register rtx op;
532 enum machine_mode mode;
533{
534 enum rtx_code code = GET_CODE (op);
535 enum machine_mode cc_mode;
536
537 if (GET_RTX_CLASS (code) != '<')
538 return 0;
539
540 cc_mode = GET_MODE (XEXP (op, 0));
541 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
542 return 0;
543
544 if ((code == GT || code == LT || code == GE || code == LE)
545 && cc_mode == CCUNSmode)
546 return 0;
547
548 if ((code == GTU || code == LTU || code == GEU || code == LEU)
549 && (cc_mode != CCUNSmode))
550 return 0;
551
552 return 1;
553}
554
555/* Return 1 if OP is a comparison operation that is valid for an scc insn.
556 We check the opcode against the mode of the CC value and disallow EQ or
557 NE comparisons for integers. */
558
559int
560scc_comparison_operator (op, mode)
561 register rtx op;
562 enum machine_mode mode;
563{
564 enum rtx_code code = GET_CODE (op);
565 enum machine_mode cc_mode;
566
567 if (GET_MODE (op) != mode && mode != VOIDmode)
568 return 0;
569
570 if (GET_RTX_CLASS (code) != '<')
571 return 0;
572
573 cc_mode = GET_MODE (XEXP (op, 0));
574 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
575 return 0;
576
577 if (code == NE && cc_mode != CCFPmode)
578 return 0;
579
580 if ((code == GT || code == LT || code == GE || code == LE)
581 && cc_mode == CCUNSmode)
582 return 0;
583
584 if ((code == GTU || code == LTU || code == GEU || code == LEU)
585 && (cc_mode != CCUNSmode))
586 return 0;
587
c5defebb
RK
588 if (cc_mode == CCEQmode && code != EQ && code != NE)
589 return 0;
590
9878760c
RK
591 return 1;
592}
593\f
594/* Return 1 if ANDOP is a mask that has no bits on that are not in the
595 mask required to convert the result of a rotate insn into a shift
596 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
597
598int
599includes_lshift_p (shiftop, andop)
600 register rtx shiftop;
601 register rtx andop;
602{
603 int shift_mask = (~0 << INTVAL (shiftop));
604
605 return (INTVAL (andop) & ~shift_mask) == 0;
606}
607
608/* Similar, but for right shift. */
609
610int
611includes_rshift_p (shiftop, andop)
612 register rtx shiftop;
613 register rtx andop;
614{
615 unsigned shift_mask = ~0;
616
617 shift_mask >>= INTVAL (shiftop);
618
619 return (INTVAL (andop) & ~ shift_mask) == 0;
620}
621\f
622/* Return the register class of a scratch register needed to copy IN into
623 or out of a register in CLASS in MODE. If it can be done directly,
624 NO_REGS is returned. */
625
626enum reg_class
627secondary_reload_class (class, mode, in)
628 enum reg_class class;
629 enum machine_mode mode;
630 rtx in;
631{
632 int regno = true_regnum (in);
633
634 if (regno >= FIRST_PSEUDO_REGISTER)
635 regno = -1;
636
637 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
638 into anything. */
639 if (class == GENERAL_REGS || class == BASE_REGS
640 || (regno >= 0 && INT_REGNO_P (regno)))
641 return NO_REGS;
642
643 /* Constants, memory, and FP registers can go into FP registers. */
644 if ((regno == -1 || FP_REGNO_P (regno))
645 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
646 return NO_REGS;
647
648 /* We can copy among the CR registers. */
649 if ((class == CR_REGS || class == CR0_REGS)
650 && regno >= 0 && CR_REGNO_P (regno))
651 return NO_REGS;
652
653 /* Otherwise, we need GENERAL_REGS. */
654 return GENERAL_REGS;
655}
656\f
657/* Given a comparison operation, return the bit number in CCR to test. We
658 know this is a valid comparison.
659
660 SCC_P is 1 if this is for an scc. That means that %D will have been
661 used instead of %C, so the bits will be in different places.
662
b4ac57ab 663 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
664
665int
666ccr_bit (op, scc_p)
667 register rtx op;
668 int scc_p;
669{
670 enum rtx_code code = GET_CODE (op);
671 enum machine_mode cc_mode;
672 int cc_regnum;
673 int base_bit;
674
675 if (GET_RTX_CLASS (code) != '<')
676 return -1;
677
678 cc_mode = GET_MODE (XEXP (op, 0));
679 cc_regnum = REGNO (XEXP (op, 0));
680 base_bit = 4 * (cc_regnum - 68);
681
c5defebb
RK
682 /* In CCEQmode cases we have made sure that the result is always in the
683 third bit of the CR field. */
684
685 if (cc_mode == CCEQmode)
686 return base_bit + 3;
687
9878760c
RK
688 switch (code)
689 {
690 case NE:
691 return scc_p ? base_bit + 3 : base_bit + 2;
692 case EQ:
693 return base_bit + 2;
694 case GT: case GTU:
695 return base_bit + 1;
696 case LT: case LTU:
697 return base_bit;
698
699 case GE: case GEU:
700 /* If floating-point, we will have done a cror to put the bit in the
701 unordered position. So test that bit. For integer, this is ! LT
702 unless this is an scc insn. */
703 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
704
705 case LE: case LEU:
706 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
707
708 default:
709 abort ();
710 }
711}
712\f
713/* Print an operand. Recognize special options, documented below. */
714
715void
716print_operand (file, x, code)
717 FILE *file;
718 rtx x;
719 char code;
720{
721 int i;
722 int val;
723
724 /* These macros test for integers and extract the low-order bits. */
725#define INT_P(X) \
726((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
727 && GET_MODE (X) == VOIDmode)
728
729#define INT_LOWPART(X) \
730 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
731
732 switch (code)
733 {
a8b3aeda
RK
734 case '.':
735 /* Write out the bit number for "cror" after a call. This differs
736 between AIX 3.2 and earlier versions. */
737 fprintf (file, "%d", RS6000_CROR_BIT_NUMBER);
738 return;
739
9854d9ed
RK
740 case 'A':
741 /* If X is a constant integer whose low-order 5 bits are zero,
742 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 743 in the AIX assembler where "sri" with a zero shift count
9854d9ed
RK
744 write a trash instruction. */
745 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 746 putc ('l', file);
9854d9ed 747 else
76229ac8 748 putc ('r', file);
9854d9ed
RK
749 return;
750
751 case 'b':
752 /* Low-order 16 bits of constant, unsigned. */
cad12a8d 753 if (! INT_P (x))
9854d9ed 754 output_operand_lossage ("invalid %%b value");
cad12a8d 755
9854d9ed 756 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
cad12a8d
RK
757 return;
758
9854d9ed
RK
759 case 'C':
760 /* This is an optional cror needed for LE or GE floating-point
761 comparisons. Otherwise write nothing. */
762 if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
763 && GET_MODE (XEXP (x, 0)) == CCFPmode)
764 {
765 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
766
767 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
768 base_bit + 2, base_bit + (GET_CODE (x) == GE));
769 }
770 return;
771
772 case 'D':
773 /* Similar, except that this is for an scc, so we must be able to
774 encode the test in a single bit that is one. We do the above
775 for any LE, GE, GEU, or LEU and invert the bit for NE. */
776 if (GET_CODE (x) == LE || GET_CODE (x) == GE
777 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
778 {
779 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
780
781 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
782 base_bit + 2,
783 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
784 }
785
786 else if (GET_CODE (x) == NE)
787 {
788 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
789
790 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
791 base_bit + 2, base_bit + 2);
792 }
793 return;
794
795 case 'E':
796 /* X is a CR register. Print the number of the third bit of the CR */
797 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
798 output_operand_lossage ("invalid %%E value");
799
800 fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
801 break;
802
803 case 'f':
804 /* X is a CR register. Print the shift count needed to move it
805 to the high-order four bits. */
806 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
807 output_operand_lossage ("invalid %%f value");
808 else
809 fprintf (file, "%d", 4 * (REGNO (x) - 68));
810 return;
811
812 case 'F':
813 /* Similar, but print the count for the rotate in the opposite
814 direction. */
815 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
816 output_operand_lossage ("invalid %%F value");
817 else
818 fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
819 return;
820
821 case 'G':
822 /* X is a constant integer. If it is negative, print "m",
823 otherwise print "z". This is to make a aze or ame insn. */
824 if (GET_CODE (x) != CONST_INT)
825 output_operand_lossage ("invalid %%G value");
826 else if (INTVAL (x) >= 0)
76229ac8 827 putc ('z', file);
9854d9ed 828 else
76229ac8 829 putc ('m', file);
9854d9ed
RK
830 return;
831
9878760c 832 case 'h':
df3d94ed
RK
833 /* If constant, output low-order five bits. Otherwise,
834 write normally. */
9878760c
RK
835 if (INT_P (x))
836 fprintf (file, "%d", INT_LOWPART (x) & 31);
837 else
838 print_operand (file, x, 0);
839 return;
840
841 case 'H':
df3d94ed 842 /* X must be a constant. Output the low order 5 bits plus 24. */
9878760c
RK
843 if (! INT_P (x))
844 output_operand_lossage ("invalid %%H value");
845
846 fprintf (file, "%d", (INT_LOWPART (x) + 24) & 31);
847 return;
848
9854d9ed
RK
849 case 'I':
850 /* Print `i' if this is a constant, else nothing. */
9878760c 851 if (INT_P (x))
76229ac8 852 putc ('i', file);
9878760c
RK
853 return;
854
9854d9ed
RK
855 case 'j':
856 /* Write the bit number in CCR for jump. */
857 i = ccr_bit (x, 0);
858 if (i == -1)
859 output_operand_lossage ("invalid %%j code");
9878760c 860 else
9854d9ed 861 fprintf (file, "%d", i);
9878760c
RK
862 return;
863
9854d9ed
RK
864 case 'J':
865 /* Similar, but add one for shift count in rlinm for scc and pass
866 scc flag to `ccr_bit'. */
867 i = ccr_bit (x, 1);
868 if (i == -1)
869 output_operand_lossage ("invalid %%J code");
870 else
a0466a68
RK
871 /* If we want bit 31, write a shift count of zero, not 32. */
872 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
873 return;
874
9854d9ed
RK
875 case 'k':
876 /* X must be a constant. Write the 1's complement of the
877 constant. */
9878760c 878 if (! INT_P (x))
9854d9ed 879 output_operand_lossage ("invalid %%k value");
9878760c 880
9854d9ed 881 fprintf (file, "%d", ~ INT_LOWPART (x));
9878760c
RK
882 return;
883
9854d9ed
RK
884 case 'L':
885 /* Write second word of DImode or DFmode reference. Works on register
886 or non-indexed memory only. */
887 if (GET_CODE (x) == REG)
888 fprintf (file, "%d", REGNO (x) + 1);
889 else if (GET_CODE (x) == MEM)
890 {
891 /* Handle possible auto-increment. Since it is pre-increment and
892 we have already done it, we can just use an offset of four. */
893 if (GET_CODE (XEXP (x, 0)) == PRE_INC
894 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
895 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
896 else
897 output_address (plus_constant (XEXP (x, 0), 4));
898 }
9878760c 899 return;
9854d9ed 900
9878760c
RK
901 case 'm':
902 /* MB value for a mask operand. */
903 if (! mask_operand (x, VOIDmode))
904 output_operand_lossage ("invalid %%m value");
905
906 val = INT_LOWPART (x);
907
908 /* If the high bit is set and the low bit is not, the value is zero.
909 If the high bit is zero, the value is the first 1 bit we find from
910 the left. */
911 if (val < 0 && (val & 1) == 0)
912 {
913 fprintf (file, "0");
914 return;
915 }
916 else if (val >= 0)
917 {
918 for (i = 1; i < 32; i++)
919 if ((val <<= 1) < 0)
920 break;
921 fprintf (file, "%d", i);
922 return;
923 }
924
925 /* Otherwise, look for the first 0 bit from the right. The result is its
926 number plus 1. We know the low-order bit is one. */
927 for (i = 0; i < 32; i++)
928 if (((val >>= 1) & 1) == 0)
929 break;
930
931 /* If we ended in ...01, I would be 0. The correct value is 31, so
932 we want 31 - i. */
933 fprintf (file, "%d", 31 - i);
934 return;
935
936 case 'M':
937 /* ME value for a mask operand. */
938 if (! mask_operand (x, VOIDmode))
939 output_operand_lossage ("invalid %%m value");
940
941 val = INT_LOWPART (x);
942
943 /* If the low bit is set and the high bit is not, the value is 31.
944 If the low bit is zero, the value is the first 1 bit we find from
945 the right. */
946 if ((val & 1) && val >= 0)
947 {
76229ac8 948 fputs ("31", file);
9878760c
RK
949 return;
950 }
951 else if ((val & 1) == 0)
952 {
953 for (i = 0; i < 32; i++)
954 if ((val >>= 1) & 1)
955 break;
956
957 /* If we had ....10, I would be 0. The result should be
958 30, so we need 30 - i. */
959 fprintf (file, "%d", 30 - i);
960 return;
961 }
962
963 /* Otherwise, look for the first 0 bit from the left. The result is its
964 number minus 1. We know the high-order bit is one. */
965 for (i = 0; i < 32; i++)
966 if ((val <<= 1) >= 0)
967 break;
968
969 fprintf (file, "%d", i);
970 return;
971
9878760c
RK
972 case 'N':
973 /* Write the number of elements in the vector times 4. */
974 if (GET_CODE (x) != PARALLEL)
975 output_operand_lossage ("invalid %%N value");
976
977 fprintf (file, "%d", XVECLEN (x, 0) * 4);
978 return;
979
980 case 'O':
981 /* Similar, but subtract 1 first. */
982 if (GET_CODE (x) != PARALLEL)
983 output_operand_lossage ("invalid %%N value");
984
985 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
986 return;
987
9854d9ed
RK
988 case 'p':
989 /* X is a CONST_INT that is a power of two. Output the logarithm. */
990 if (! INT_P (x)
991 || (i = exact_log2 (INT_LOWPART (x))) < 0)
992 output_operand_lossage ("invalid %%p value");
993
994 fprintf (file, "%d", i);
995 return;
996
9878760c
RK
997 case 'P':
998 /* The operand must be an indirect memory reference. The result
999 is the register number. */
1000 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
1001 || REGNO (XEXP (x, 0)) >= 32)
1002 output_operand_lossage ("invalid %%P value");
1003
1004 fprintf (file, "%d", REGNO (XEXP (x, 0)));
1005 return;
1006
9854d9ed
RK
1007 case 'R':
1008 /* X is a CR register. Print the mask for `mtcrf'. */
1009 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1010 output_operand_lossage ("invalid %%R value");
1011 else
1012 fprintf (file, "%d", 128 >> (REGNO (x) - 68));
9878760c 1013 return;
9854d9ed
RK
1014
1015 case 's':
1016 /* Low 5 bits of 32 - value */
1017 if (! INT_P (x))
1018 output_operand_lossage ("invalid %%s value");
1019
1020 fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31);
9878760c 1021 return;
9854d9ed
RK
1022
1023 case 'S':
1024 /* Low 5 bits of 31 - value */
1025 if (! INT_P (x))
1026 output_operand_lossage ("invalid %%S value");
1027
1028 fprintf (file, "%d", (31 - INT_LOWPART (x)) & 31);
9878760c 1029 return;
9854d9ed 1030
9878760c
RK
1031 case 't':
1032 /* Write 12 if this jump operation will branch if true, 4 otherwise.
1033 All floating-point operations except NE branch true and integer
1034 EQ, LT, GT, LTU and GTU also branch true. */
1035 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
1036 output_operand_lossage ("invalid %%t value");
1037
1038 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
1039 && GET_CODE (x) != NE)
1040 || GET_CODE (x) == EQ
1041 || GET_CODE (x) == LT || GET_CODE (x) == GT
1042 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
76229ac8 1043 fputs ("12", file);
9878760c 1044 else
76229ac8 1045 putc ('4', file);
9878760c
RK
1046 return;
1047
1048 case 'T':
1049 /* Opposite of 't': write 4 if this jump operation will branch if true,
1050 12 otherwise. */
1051 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
1052 output_operand_lossage ("invalid %%t value");
1053
1054 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
1055 && GET_CODE (x) != NE)
1056 || GET_CODE (x) == EQ
1057 || GET_CODE (x) == LT || GET_CODE (x) == GT
1058 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
76229ac8 1059 putc ('4', file);
9878760c 1060 else
76229ac8 1061 fputs ("12", file);
9878760c
RK
1062 return;
1063
9854d9ed
RK
1064 case 'u':
1065 /* High-order 16 bits of constant. */
1066 if (! INT_P (x))
1067 output_operand_lossage ("invalid %%u value");
9878760c 1068
76229ac8 1069 fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
1070 return;
1071
9854d9ed
RK
1072 case 'U':
1073 /* Print `u' if this has an auto-increment or auto-decrement. */
1074 if (GET_CODE (x) == MEM
1075 && (GET_CODE (XEXP (x, 0)) == PRE_INC
1076 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 1077 putc ('u', file);
9854d9ed 1078 return;
9878760c 1079
9854d9ed
RK
1080 case 'w':
1081 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
1082 normally. */
1083 if (INT_P (x))
1084 fprintf (file, "%d",
1085 (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000));
1086 else
1087 print_operand (file, x, 0);
9878760c
RK
1088 return;
1089
9854d9ed
RK
1090 case 'W':
1091 /* If constant, low-order 16 bits of constant, unsigned.
1092 Otherwise, write normally. */
1093 if (INT_P (x))
1094 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
1095 else
1096 print_operand (file, x, 0);
1097 return;
9878760c 1098
9854d9ed
RK
1099 case 'X':
1100 if (GET_CODE (x) == MEM
1101 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
76229ac8 1102 putc ('x', file);
9854d9ed 1103 return;
9878760c 1104
9854d9ed
RK
1105 case 'Y':
1106 /* Like 'L', for third word of TImode */
1107 if (GET_CODE (x) == REG)
1108 fprintf (file, "%d", REGNO (x) + 2);
1109 else if (GET_CODE (x) == MEM)
9878760c 1110 {
9854d9ed
RK
1111 if (GET_CODE (XEXP (x, 0)) == PRE_INC
1112 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1113 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
1114 else
1115 output_address (plus_constant (XEXP (x, 0), 8));
9878760c
RK
1116 }
1117 return;
9854d9ed 1118
9878760c 1119 case 'z':
b4ac57ab
RS
1120 /* X is a SYMBOL_REF. Write out the name preceded by a
1121 period and without any trailing data in brackets. Used for function
9878760c
RK
1122 names. */
1123 if (GET_CODE (x) != SYMBOL_REF)
1124 abort ();
1125
76229ac8 1126 putc ('.', file);
9878760c
RK
1127 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
1128 return;
1129
9854d9ed
RK
1130 case 'Z':
1131 /* Like 'L', for last word of TImode. */
1132 if (GET_CODE (x) == REG)
1133 fprintf (file, "%d", REGNO (x) + 3);
1134 else if (GET_CODE (x) == MEM)
1135 {
1136 if (GET_CODE (XEXP (x, 0)) == PRE_INC
1137 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1138 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
1139 else
1140 output_address (plus_constant (XEXP (x, 0), 12));
1141 }
5c23c401 1142 return;
9854d9ed 1143
9878760c
RK
1144 case 0:
1145 if (GET_CODE (x) == REG)
1146 fprintf (file, "%s", reg_names[REGNO (x)]);
1147 else if (GET_CODE (x) == MEM)
1148 {
1149 /* We need to handle PRE_INC and PRE_DEC here, since we need to
1150 know the width from the mode. */
1151 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
1152 fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
1153 REGNO (XEXP (XEXP (x, 0), 0)));
1154 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
1155 fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
1156 REGNO (XEXP (XEXP (x, 0), 0)));
1157 else
1158 output_address (XEXP (x, 0));
1159 }
1160 else
1161 output_addr_const (file, x);
1162 break;
1163
1164 default:
1165 output_operand_lossage ("invalid %%xn code");
1166 }
1167}
1168\f
1169/* Print the address of an operand. */
1170
1171void
1172print_operand_address (file, x)
1173 FILE *file;
1174 register rtx x;
1175{
1176 if (GET_CODE (x) == REG)
1177 fprintf (file, "0(%d)", REGNO (x));
1178 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
1179 {
1180 output_addr_const (file, x);
1875cc88
JW
1181 /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead
1182 of the toc pointer. */
1183 if (TARGET_MINIMAL_TOC)
1184 fprintf (file, "(30)");
1185 else
1186 fprintf (file, "(2)");
9878760c
RK
1187 }
1188 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
1189 {
1190 if (REGNO (XEXP (x, 0)) == 0)
1191 fprintf (file, "%d,%d", REGNO (XEXP (x, 1)), REGNO (XEXP (x, 0)));
1192 else
1193 fprintf (file, "%d,%d", REGNO (XEXP (x, 0)), REGNO (XEXP (x, 1)));
1194 }
1195 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
1196 fprintf (file, "%d(%d)", INTVAL (XEXP (x, 1)), REGNO (XEXP (x, 0)));
1197 else
1198 abort ();
1199}
1200\f
1201/* This page contains routines that are used to determine what the function
1202 prologue and epilogue code will do and write them out. */
1203
1204/* Return the first fixed-point register that is required to be saved. 32 if
1205 none. */
1206
1207int
1208first_reg_to_save ()
1209{
1210 int first_reg;
1211
1212 /* Find lowest numbered live register. */
1213 for (first_reg = 13; first_reg <= 31; first_reg++)
1214 if (regs_ever_live[first_reg])
1215 break;
1216
e165f3f0
RK
1217 /* If profiling, then we must save/restore every register that contains
1218 a parameter before/after the .mcount call. Use registers from 30 down
1219 to 23 to do this. Don't use the frame pointer in reg 31.
1220
1221 For now, save enough room for all of the parameter registers. */
1222 if (profile_flag)
1223 if (first_reg > 23)
1224 first_reg = 23;
1225
9878760c
RK
1226 return first_reg;
1227}
1228
1229/* Similar, for FP regs. */
1230
1231int
1232first_fp_reg_to_save ()
1233{
1234 int first_reg;
1235
1236 /* Find lowest numbered live register. */
1237 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
1238 if (regs_ever_live[first_reg])
1239 break;
1240
1241 return first_reg;
1242}
1243
1244/* Return 1 if we need to save CR. */
1245
1246int
1247must_save_cr ()
1248{
1249 return regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72];
1250}
1251
1252/* Compute the size of the save area in the stack, including the space for
1253 the fixed area. */
1254
1255int
1256rs6000_sa_size ()
1257{
1258 int size;
9878760c
RK
1259
1260 /* We have the six fixed words, plus the size of the register save
1261 areas, rounded to a double-word. */
1262 size = 6 + (32 - first_reg_to_save ()) + (64 - first_fp_reg_to_save ()) * 2;
1263 if (size & 1)
1264 size++;
1265
1266 return size * 4;
1267}
1268
1269/* Return non-zero if this function makes calls. */
1270
1271int
1272rs6000_makes_calls ()
1273{
1274 rtx insn;
1275
0c61c946
RK
1276 /* If we are profiling, we will be making a call to mcount. */
1277 if (profile_flag)
1278 return 1;
1279
9878760c
RK
1280 for (insn = get_insns (); insn; insn = next_insn (insn))
1281 if (GET_CODE (insn) == CALL_INSN)
1282 return 1;
1283
1284 return 0;
1285}
1286
1287/* Return non-zero if this function needs to push space on the stack. */
1288
1289int
1290rs6000_pushes_stack ()
1291{
1292 int total_size = (rs6000_sa_size () + get_frame_size ()
1293 + current_function_outgoing_args_size);
1294
1295 /* We need to push the stack if a frame pointer is needed (because the
1296 stack might be dynamically adjusted), if we are debugging, if the
1297 total stack size is more than 220 bytes, or if we make calls. */
1298
1299 return (frame_pointer_needed || write_symbols != NO_DEBUG
1300 || total_size > 220
1301 || rs6000_makes_calls ());
1302}
1303
1304/* Write function prologue. */
1305
1306void
1307output_prolog (file, size)
1308 FILE *file;
1309 int size;
1310{
1311 int first_reg = first_reg_to_save ();
1312 int must_push = rs6000_pushes_stack ();
1313 int first_fp_reg = first_fp_reg_to_save ();
1314 int basic_size = rs6000_sa_size ();
1315 int total_size = (basic_size + size + current_function_outgoing_args_size);
1316
1317 /* Round size to multiple of 8 bytes. */
1318 total_size = (total_size + 7) & ~7;
1319
1320 /* Write .extern for any function we will call to save and restore fp
1321 values. */
1322 if (first_fp_reg < 62)
1323 fprintf (file, "\t.extern ._savef%d\n\t.extern ._restf%d\n",
1324 first_fp_reg - 32, first_fp_reg - 32);
1325
1326 /* Write .extern for truncation routines, if needed. */
1327 if (rs6000_trunc_used && ! trunc_defined)
1328 {
1329 fprintf (file, "\t.extern .itrunc\n\t.extern .uitrunc\n");
1330 trunc_defined = 1;
1331 }
1332
e165f3f0
RK
1333 /* If we have to call a function to save fpr's, or if we are doing profiling,
1334 then we will be using LR. */
1335 if (first_fp_reg < 62 || profile_flag)
9878760c
RK
1336 regs_ever_live[65] = 1;
1337
1338 /* If we use the link register, get it into r0. */
1339 if (regs_ever_live[65])
1340 fprintf (file, "\tmflr 0\n");
1341
1342 /* If we need to save CR, put it into r12. */
1343 if (must_save_cr ())
1344 fprintf (file, "\tmfcr 12\n");
1345
1346 /* Do any required saving of fpr's. If only one or two to save, do it
53322b0c
RK
1347 ourself. Otherwise, call function. Note that since they are statically
1348 linked, we do not need a nop following them. */
9878760c
RK
1349 if (first_fp_reg == 62)
1350 fprintf (file, "\tstfd 30,-16(1)\n\tstfd 31,-8(1)\n");
1351 else if (first_fp_reg == 63)
1352 fprintf (file, "\tstfd 31,-8(1)\n");
1353 else if (first_fp_reg != 64)
53322b0c 1354 fprintf (file, "\tbl ._savef%d\n", first_fp_reg - 32);
9878760c
RK
1355
1356 /* Now save gpr's. */
1357 if (first_reg == 31)
1358 fprintf (file, "\tst 31,%d(1)\n", -4 - (64 - first_fp_reg) * 8);
1359 else if (first_reg != 32)
1360 fprintf (file, "\tstm %d,%d(1)\n", first_reg,
1361 - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
1362
1363 /* Save lr if we used it. */
1364 if (regs_ever_live[65])
1365 fprintf (file, "\tst 0,8(1)\n");
1366
1367 /* Save CR if we use any that must be preserved. */
1368 if (must_save_cr ())
1369 fprintf (file, "\tst 12,4(1)\n");
1370
1371 /* Update stack and set back pointer. */
1372 if (must_push)
1373 {
1374 if (total_size < 32767)
1375 fprintf (file, "\tstu 1,%d(1)\n", - total_size);
1376 else
1377 {
1378 fprintf (file, "\tcau 0,0,%d\n\toril 0,0,%d\n",
1379 (total_size >> 16) & 0xffff, total_size & 0xffff);
1380 fprintf (file, "\tsf 12,0,1\n\tst 1,0(12)\n\toril 1,12,0\n");
1381 }
1382 }
1383
1384 /* Set frame pointer, if needed. */
1385 if (frame_pointer_needed)
1386 fprintf (file, "\toril 31,1,0\n");
1875cc88
JW
1387
1388 /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
1389 TOC_TABLE address into register 30. */
1390 if (TARGET_MINIMAL_TOC && get_pool_size () != 0)
1391 fprintf (file, "\tl 30,LCTOC..0(2)\n");
9878760c
RK
1392}
1393
1394/* Write function epilogue. */
1395
1396void
1397output_epilog (file, size)
1398 FILE *file;
1399 int size;
1400{
1401 int first_reg = first_reg_to_save ();
1402 int must_push = rs6000_pushes_stack ();
1403 int first_fp_reg = first_fp_reg_to_save ();
1404 int basic_size = rs6000_sa_size ();
1405 int total_size = (basic_size + size + current_function_outgoing_args_size);
1406 rtx insn = get_last_insn ();
1407
1408 /* Round size to multiple of 8 bytes. */
1409 total_size = (total_size + 7) & ~7;
1410
1411 /* If the last insn was a BARRIER, we don't have to write anything except
1412 the trace table. */
1413 if (GET_CODE (insn) == NOTE)
1414 insn = prev_nonnote_insn (insn);
1415 if (insn == 0 || GET_CODE (insn) != BARRIER)
1416 {
1417 /* If we have a frame pointer, a call to alloca, or a large stack
1418 frame, restore the old stack pointer using the backchain. Otherwise,
1419 we know what size to update it with. */
1420 if (frame_pointer_needed || current_function_calls_alloca
1421 || total_size > 32767)
1422 fprintf (file, "\tl 1,0(1)\n");
1423 else if (must_push)
1424 fprintf (file, "\tai 1,1,%d\n", total_size);
1425
b4ac57ab 1426 /* Get the old lr if we saved it. */
9878760c 1427 if (regs_ever_live[65])
b4ac57ab 1428 fprintf (file, "\tl 0,8(1)\n");
9878760c
RK
1429
1430 /* Get the old cr if we saved it. */
1431 if (must_save_cr ())
1432 fprintf (file, "\tl 12,4(1)\n");
1433
b4ac57ab
RS
1434 /* Set LR here to try to overlap restores below. */
1435 if (regs_ever_live[65])
1436 fprintf (file, "\tmtlr 0\n");
1437
9878760c
RK
1438 /* Restore gpr's. */
1439 if (first_reg == 31)
1440 fprintf (file, "\tl 31,%d(1)\n", -4 - (64 - first_fp_reg) * 8);
1441 else if (first_reg != 32)
1442 fprintf (file, "\tlm %d,%d(1)\n", first_reg,
1443 - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
1444
b4ac57ab 1445 /* Restore fpr's if we can do it without calling a function. */
9878760c
RK
1446 if (first_fp_reg == 62)
1447 fprintf (file, "\tlfd 30,-16(1)\n\tlfd 31,-8(1)\n");
1448 else if (first_fp_reg == 63)
1449 fprintf (file, "\tlfd 31,-8(1)\n");
9878760c 1450
28edebac
RK
1451 /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4
1452 that were used. */
9878760c 1453 if (must_save_cr ())
28edebac
RK
1454 fprintf (file, "\tmtcrf %d,12\n",
1455 (regs_ever_live[70] != 0) * 0x20
1456 + (regs_ever_live[71] != 0) * 0x10
1457 + (regs_ever_live[72] != 0) * 0x8);
9878760c 1458
b4ac57ab
RS
1459 /* If we have to restore more than two FP registers, branch to the
1460 restore function. It will return to our caller. */
1461 if (first_fp_reg < 62)
53322b0c 1462 fprintf (file, "\tb ._restf%d\n", first_fp_reg - 32);
b4ac57ab
RS
1463 else
1464 fprintf (file, "\tbr\n");
9878760c 1465 }
b4ac57ab 1466
9b30bae2
JW
1467 /* Output a traceback table here. See /usr/include/sys/debug.h for info
1468 on its format. */
1469 {
1470 char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
1471 int fixed_parms, float_parms, parm_info;
1472 int i;
1473
1474 /* Need label immediately before tbtab, so we can compute its offset
1475 from the function start. */
1476 if (*fname == '*')
1477 ++fname;
c2a47e48 1478 fprintf (file, "LT..");
9b30bae2
JW
1479 ASM_OUTPUT_LABEL (file, fname);
1480
15872eeb 1481 /* The .tbtab pseudo-op can only be used for the first eight
9b30bae2
JW
1482 expressions, since it can't handle the possibly variable length
1483 fields that follow. However, if you omit the optional fields,
1484 the assembler outputs zeros for all optional fields anyways, giving each
1485 variable length field is minimum length (as defined in sys/debug.h).
15872eeb 1486 Thus we can not use the .tbtab pseudo-op at all. */
9b30bae2
JW
1487
1488 /* An all-zero word flags the start of the tbtab, for debuggers that have
1489 to find it by searching forward from the entry point or from the
1490 current pc. */
1491 fprintf (file, "\t.long 0\n");
1492
1493 /* Tbtab format type. Use format type 0. */
65d1fa2b 1494 fprintf (file, "\t.byte 0,");
9b30bae2
JW
1495
1496 /* Language type. Unfortunately, there doesn't seem to be any official way
1497 to get this info, so we use language_string. C is 0. C++ is 9.
9854d9ed
RK
1498 No number defined for Obj-C, so use the value for C for now. */
1499 if (! strcmp (language_string, "GNU C")
1500 || ! strcmp (language_string, "GNU Obj-C"))
9b30bae2 1501 i = 0;
9353d0a3
RK
1502 else if (! strcmp (language_string, "GNU F77"))
1503 i = 1;
1504 else if (! strcmp (language_string, "GNU Ada"))
1505 i = 3;
1506 else if (! strcmp (language_string, "GNU PASCAL"))
1507 i = 2;
9b30bae2
JW
1508 else if (! strcmp (language_string, "GNU C++"))
1509 i = 9;
1510 else
1511 abort ();
65d1fa2b 1512 fprintf (file, "%d,", i);
9b30bae2
JW
1513
1514 /* 8 single bit fields: global linkage (not set for C extern linkage,
1515 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
1516 from start of procedure stored in tbtab, internal function, function
1517 has controlled storage, function has no toc, function uses fp,
1518 function logs/aborts fp operations. */
1519 /* Assume that fp operations are used if any fp reg must be saved. */
65d1fa2b 1520 fprintf (file, "%d,", (1 << 5) | ((first_fp_reg != 64) << 1));
9b30bae2
JW
1521
1522 /* 6 bitfields: function is interrupt handler, name present in proc table,
1523 function calls alloca, on condition directives (controls stack walks,
1524 3 bits), saves condition reg, saves link reg. */
1525 /* The `function calls alloca' bit seems to be set whenever reg 31 is
1526 set up as a frame pointer, even when there is no alloca call. */
65d1fa2b 1527 fprintf (file, "%d,",
9b30bae2
JW
1528 ((1 << 6) | (frame_pointer_needed << 5)
1529 | (must_save_cr () << 1) | (regs_ever_live[65])));
1530
1531 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
1532 (6 bits). */
65d1fa2b 1533 fprintf (file, "%d,",
9b30bae2
JW
1534 (must_push << 7) | (64 - first_fp_reg_to_save ()));
1535
1536 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
65d1fa2b 1537 fprintf (file, "%d,", (32 - first_reg_to_save ()));
9b30bae2
JW
1538
1539 {
1540 /* Compute the parameter info from the function decl argument list. */
1541 tree decl;
1542 int next_parm_info_bit;
1543
1544 next_parm_info_bit = 31;
1545 parm_info = 0;
1546 fixed_parms = 0;
1547 float_parms = 0;
1548
1549 for (decl = DECL_ARGUMENTS (current_function_decl);
1550 decl; decl = TREE_CHAIN (decl))
1551 {
1552 rtx parameter = DECL_INCOMING_RTL (decl);
1553 enum machine_mode mode = GET_MODE (parameter);
1554
1555 if (GET_CODE (parameter) == REG)
1556 {
1557 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1558 {
1559 int bits;
1560
1561 float_parms++;
1562
1563 if (mode == SFmode)
1564 bits = 0x2;
1565 else if (mode == DFmode)
1566 bits = 0x3;
1567 else
1568 abort ();
1569
1570 /* If only one bit will fit, don't or in this entry. */
1571 if (next_parm_info_bit > 0)
1572 parm_info |= (bits << (next_parm_info_bit - 1));
1573 next_parm_info_bit -= 2;
1574 }
1575 else
1576 {
1577 fixed_parms += ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1))
1578 / UNITS_PER_WORD);
1579 next_parm_info_bit -= 1;
1580 }
1581 }
1582 }
1583 }
1584
1585 /* Number of fixed point parameters. */
1586 /* This is actually the number of words of fixed point parameters; thus
1587 an 8 byte struct counts as 2; and thus the maximum value is 8. */
65d1fa2b 1588 fprintf (file, "%d,", fixed_parms);
9b30bae2
JW
1589
1590 /* 2 bitfields: number of floating point parameters (7 bits), parameters
1591 all on stack. */
1592 /* This is actually the number of fp registers that hold parameters;
1593 and thus the maximum value is 13. */
1594 /* Set parameters on stack bit if parameters are not in their original
15872eeb 1595 registers, regardless of whether they are on the stack? Xlc
9b30bae2 1596 seems to set the bit when not optimizing. */
65d1fa2b 1597 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
9b30bae2
JW
1598
1599 /* Optional fields follow. Some are variable length. */
1600
1601 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
1602 11 double float. */
1603 /* There is an entry for each parameter in a register, in the order that
1604 they occur in the parameter list. Any intervening arguments on the
1605 stack are ignored. If the list overflows a long (max possible length
1606 34 bits) then completely leave off all elements that don't fit. */
1607 /* Only emit this long if there was at least one parameter. */
1608 if (fixed_parms || float_parms)
1609 fprintf (file, "\t.long %d\n", parm_info);
1610
1611 /* Offset from start of code to tb table. */
c2a47e48 1612 fprintf (file, "\t.long LT..");
9b30bae2
JW
1613 RS6000_OUTPUT_BASENAME (file, fname);
1614 fprintf (file, "-.");
1615 RS6000_OUTPUT_BASENAME (file, fname);
1616 fprintf (file, "\n");
1617
1618 /* Interrupt handler mask. */
15872eeb 1619 /* Omit this long, since we never set the interrupt handler bit above. */
9b30bae2
JW
1620
1621 /* Number of CTL (controlled storage) anchors. */
1622 /* Omit this long, since the has_ctl bit is never set above. */
1623
1624 /* Displacement into stack of each CTL anchor. */
1625 /* Omit this list of longs, because there are no CTL anchors. */
1626
1627 /* Length of function name. */
1628 fprintf (file, "\t.short %d\n", strlen (fname));
1629
1630 /* Function name. */
1631 assemble_string (fname, strlen (fname));
1632
1633 /* Register for alloca automatic storage; this is always reg 31.
1634 Only emit this if the alloca bit was set above. */
1635 if (frame_pointer_needed)
1636 fprintf (file, "\t.byte 31\n");
1637 }
9878760c
RK
1638}
1639\f
1640/* Output a TOC entry. We derive the entry name from what is
1641 being written. */
1642
1643void
1644output_toc (file, x, labelno)
1645 FILE *file;
1646 rtx x;
1647 int labelno;
1648{
1649 char buf[256];
1650 char *name = buf;
1651 rtx base = x;
1652 int offset = 0;
1653
1654 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
1655
37c37a57
RK
1656 /* Handle FP constants specially. Note that if we have a minimal
1657 TOC, things we put here aren't actually in the TOC, so we can allow
1658 FP constants. */
9878760c
RK
1659 if (GET_CODE (x) == CONST_DOUBLE
1660 && GET_MODE (x) == DFmode
1661 && TARGET_FLOAT_FORMAT == HOST_FLOAT_FORMAT
1662 && BITS_PER_WORD == HOST_BITS_PER_INT
37c37a57 1663 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
9878760c 1664 {
1875cc88
JW
1665 if (TARGET_MINIMAL_TOC)
1666 fprintf (file, "\t.long %d\n\t.long %d\n",
1667 CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x));
1668 else
1669 fprintf (file, "\t.tc FD_%x_%x[TC],%d,%d\n",
1670 CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
1671 CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x));
9878760c
RK
1672 return;
1673 }
1674 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
37c37a57 1675 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
9878760c
RK
1676 {
1677 rtx val = operand_subword (x, 0, 0, SFmode);
1678
1679 if (val == 0 || GET_CODE (val) != CONST_INT)
1680 abort ();
1681
1875cc88
JW
1682 if (TARGET_MINIMAL_TOC)
1683 fprintf (file, "\t.long %d\n", INTVAL (val));
1684 else
1685 fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val));
9878760c
RK
1686 return;
1687 }
1688
1689 if (GET_CODE (x) == CONST)
1690 {
1691 base = XEXP (XEXP (x, 0), 0);
1692 offset = INTVAL (XEXP (XEXP (x, 0), 1));
1693 }
1694
1695 if (GET_CODE (base) == SYMBOL_REF)
1696 name = XSTR (base, 0);
1697 else if (GET_CODE (base) == LABEL_REF)
1698 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
1699 else if (GET_CODE (base) == CODE_LABEL)
1700 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
1701 else
1702 abort ();
1703
1875cc88
JW
1704 if (TARGET_MINIMAL_TOC)
1705 fprintf (file, "\t.long ");
1706 else
1707 {
1708 fprintf (file, "\t.tc ");
1709 RS6000_OUTPUT_BASENAME (file, name);
9878760c 1710
1875cc88
JW
1711 if (offset < 0)
1712 fprintf (file, ".N%d", - offset);
1713 else if (offset)
1714 fprintf (file, ".P%d", offset);
9878760c 1715
1875cc88
JW
1716 fprintf (file, "[TC],");
1717 }
9878760c
RK
1718 output_addr_const (file, x);
1719 fprintf (file, "\n");
1720}
1721\f
1722/* Output an assembler pseudo-op to write an ASCII string of N characters
1723 starting at P to FILE.
1724
1725 On the RS/6000, we have to do this using the .byte operation and
1726 write out special characters outside the quoted string.
1727 Also, the assembler is broken; very long strings are truncated,
1728 so we must artificially break them up early. */
1729
1730void
1731output_ascii (file, p, n)
1732 FILE *file;
1733 char *p;
1734 int n;
1735{
1736 char c;
1737 int i, count_string;
1738 char *for_string = "\t.byte \"";
1739 char *for_decimal = "\t.byte ";
1740 char *to_close = NULL;
1741
1742 count_string = 0;
1743 for (i = 0; i < n; i++)
1744 {
1745 c = *p++;
1746 if (c >= ' ' && c < 0177)
1747 {
1748 if (for_string)
1749 fputs (for_string, file);
1750 putc (c, file);
1751
1752 /* Write two quotes to get one. */
1753 if (c == '"')
1754 {
1755 putc (c, file);
1756 ++count_string;
1757 }
1758
1759 for_string = NULL;
1760 for_decimal = "\"\n\t.byte ";
1761 to_close = "\"\n";
1762 ++count_string;
1763
1764 if (count_string >= 512)
1765 {
1766 fputs (to_close, file);
1767
1768 for_string = "\t.byte \"";
1769 for_decimal = "\t.byte ";
1770 to_close = NULL;
1771 count_string = 0;
1772 }
1773 }
1774 else
1775 {
1776 if (for_decimal)
1777 fputs (for_decimal, file);
1778 fprintf (file, "%d", c);
1779
1780 for_string = "\n\t.byte \"";
1781 for_decimal = ", ";
1782 to_close = "\n";
1783 count_string = 0;
1784 }
1785 }
1786
1787 /* Now close the string if we have written one. Then end the line. */
1788 if (to_close)
1789 fprintf (file, to_close);
1790}
1791\f
1792/* Generate a unique section name for FILENAME for a section type
1793 represented by SECTION_DESC. Output goes into BUF.
1794
1795 SECTION_DESC can be any string, as long as it is different for each
1796 possible section type.
1797
1798 We name the section in the same manner as xlc. The name begins with an
1799 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
1800 names) with the last period replaced by the string SECTION_DESC. If
1801 FILENAME does not contain a period, SECTION_DESC is appended to the end of
1802 the name. */
9878760c
RK
1803
1804void
1805rs6000_gen_section_name (buf, filename, section_desc)
1806 char **buf;
1807 char *filename;
1808 char *section_desc;
1809{
11e5fe42 1810 char *q, *after_last_slash, *last_period;
9878760c
RK
1811 char *p;
1812 int len;
9878760c
RK
1813
1814 after_last_slash = filename;
1815 for (q = filename; *q; q++)
11e5fe42
RK
1816 {
1817 if (*q == '/')
1818 after_last_slash = q + 1;
1819 else if (*q == '.')
1820 last_period = q;
1821 }
9878760c 1822
11e5fe42 1823 len = strlen (after_last_slash) + strlen (section_desc) + 2;
9878760c
RK
1824 *buf = (char *) permalloc (len);
1825
1826 p = *buf;
1827 *p++ = '_';
1828
1829 for (q = after_last_slash; *q; q++)
1830 {
11e5fe42 1831 if (q == last_period)
9878760c
RK
1832 {
1833 strcpy (p, section_desc);
1834 p += strlen (section_desc);
9878760c
RK
1835 }
1836
1837 else if (isalnum (*q))
1838 *p++ = *q;
1839 }
1840
11e5fe42 1841 if (last_period == 0)
9878760c
RK
1842 strcpy (p, section_desc);
1843 else
1844 *p = '\0';
1845}
e165f3f0
RK
1846\f
1847/* Write function profiler code. */
1848
1849void
1850output_function_profiler (file, labelno)
1851 FILE *file;
1852 int labelno;
1853{
1854 /* The last used parameter register. */
1855 int last_parm_reg;
1856 int i, j;
1857
1858 /* Set up a TOC entry for the profiler label. */
1859 toc_section ();
c2a47e48 1860 fprintf (file, "LPC..%d:\n\t.tc\tLP..%d[TC],LP..%d\n",
e165f3f0
RK
1861 labelno, labelno, labelno);
1862 text_section ();
1863
1864 /* Figure out last used parameter register. The proper thing to do is
1865 to walk incoming args of the function. A function might have live
1866 parameter registers even if it has no incoming args. */
1867
1868 for (last_parm_reg = 10;
1869 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
1870 last_parm_reg--)
1871 ;
1872
1873 /* Save parameter registers in regs 23-30. Don't overwrite reg 31, since
1874 it might be set up as the frame pointer. */
1875
1876 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
1877 fprintf (file, "\tai %d,%d,0\n", j, i);
1878
1879 /* Load location address into r3, and call mcount. */
1880
c2a47e48 1881 fprintf (file, "\tl 3,LPC..%d(2)\n\tbl .mcount\n", labelno);
e165f3f0
RK
1882
1883 /* Restore parameter registers. */
1884
1885 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
1886 fprintf (file, "\tai %d,%d,0\n", i, j);
1887}
This page took 0.306109 seconds and 5 git commands to generate.