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