(logic_operand): New function.
[gcc.git] / gcc / config / i960 / i960.c
1 /* Subroutines used for code generation on intel 80960.
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
3 Contributed by Steven McGeady, Intel Corp.
4 Additional Work by Glenn Colon-Bonet, Jonathan Shapiro, Andy Wilson
5 Converted to GCC 2.0 by Jim Wilson and Michael Tiemann, Cygnus Support.
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24 #include <stdio.h>
25
26 #include "config.h"
27 #include "rtl.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
34 #include "output.h"
35 #include "insn-attr.h"
36 #include "flags.h"
37 #include "tree.h"
38 #include "insn-codes.h"
39 #include "assert.h"
40 #include "expr.h"
41 #include "function.h"
42 #include "recog.h"
43 #include <math.h>
44
45 /* Save the operands last given to a compare for use when we
46 generate a scc or bcc insn. */
47
48 rtx i960_compare_op0, i960_compare_op1;
49
50 /* Used to implement #pragma align/noalign. Initialized by OVERRIDE_OPTIONS
51 macro in i960.h. */
52
53 static int i960_maxbitalignment;
54 static int i960_last_maxbitalignment;
55
56 /* Used to implement switching between MEM and ALU insn types, for better
57 C series performance. */
58
59 enum insn_types i960_last_insn_type;
60
61 /* The leaf-procedure return register. Set only if this is a leaf routine. */
62
63 static int i960_leaf_ret_reg;
64
65 /* True if replacing tail calls with jumps is OK. */
66
67 static int tail_call_ok;
68
69 /* A string containing a list of insns to emit in the epilogue so as to
70 restore all registers saved by the prologue. Created by the prologue
71 code as it saves registers away. */
72
73 char epilogue_string[1000];
74
75 /* A unique number (per function) for return labels. */
76
77 static int ret_label = 0;
78
79 /* This is true if FNDECL is either a varargs or a stdarg function.
80 This is used to help identify functions that use an argument block. */
81
82 #define VARARGS_STDARG_FUNCTION(FNDECL) \
83 ((TYPE_ARG_TYPES (TREE_TYPE (FNDECL)) != 0 \
84 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (FNDECL)))) != void_type_node)) \
85 || current_function_varargs)
86
87 /* Handle pragmas for compatibility with Intel's compilers. */
88
89 /* ??? This is incomplete, since it does not handle all pragmas that the
90 intel compilers understand. */
91
92 void
93 process_pragma (finput)
94 FILE *finput;
95 {
96 int c;
97 int i;
98
99 c = getc (finput);
100 while (c == ' ' || c == '\t')
101 c = getc (finput);
102
103 if (c == 'a'
104 && getc (finput) == 'l'
105 && getc (finput) == 'i'
106 && getc (finput) == 'g'
107 && getc (finput) == 'n'
108 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
109 {
110 char buf[20];
111 char *s = buf;
112 int align;
113
114 while (c == ' ' || c == '\t')
115 c = getc (finput);
116 if (c == '(')
117 c = getc (finput);
118 while (c >= '0' && c <= '9')
119 {
120 if (s < buf + sizeof buf - 1)
121 *s++ = c;
122 c = getc (finput);
123 }
124 *s = '\0';
125
126 align = atoi (buf);
127 switch (align)
128 {
129 case 0:
130 /* Return to last alignment. */
131 align = i960_last_maxbitalignment / 8;
132 /* Fall through. */
133 case 16:
134 case 8:
135 case 4:
136 case 2:
137 case 1:
138 i960_last_maxbitalignment = i960_maxbitalignment;
139 i960_maxbitalignment = align * 8;
140 break;
141
142 default:
143 /* Silently ignore bad values. */
144 break;
145 }
146
147 /* NOTE: ic960 R3.0 pragma align definition:
148
149 #pragma align [(size)] | (identifier=size[,...])
150 #pragma noalign [(identifier)[,...]]
151
152 (all parens are optional)
153
154 - size is [1,2,4,8,16]
155 - noalign means size==1
156 - applies only to component elements of a struct (and union?)
157 - identifier applies to structure tag (only)
158 - missing identifier means next struct
159
160 - alignment rules for bitfields need more investigation */
161 }
162
163 /* Should be pragma 'far' or equivalent for callx/balx here. */
164
165 ungetc (c, finput);
166 }
167
168 /* Initialize variables before compiling any files. */
169
170 void
171 i960_initialize ()
172 {
173 if (TARGET_IC_COMPAT2_0)
174 {
175 i960_maxbitalignment = 8;
176 i960_last_maxbitalignment = 128;
177 }
178 else
179 {
180 i960_maxbitalignment = 128;
181 i960_last_maxbitalignment = 8;
182 }
183 }
184 \f
185 /* Return true if OP can be used as the source of an fp move insn. */
186
187 int
188 fpmove_src_operand (op, mode)
189 rtx op;
190 enum machine_mode mode;
191 {
192 return (GET_CODE (op) == CONST_DOUBLE || general_operand (op, mode));
193 }
194
195 #if 0
196 /* Return true if OP is a register or zero. */
197
198 int
199 reg_or_zero_operand (op, mode)
200 rtx op;
201 enum machine_mode mode;
202 {
203 return register_operand (op, mode) || op == const0_rtx;
204 }
205 #endif
206
207 /* Return truth value of whether OP can be used as an operands in a three
208 address arithmetic insn (such as add %o1,7,%l2) of mode MODE. */
209
210 int
211 arith_operand (op, mode)
212 rtx op;
213 enum machine_mode mode;
214 {
215 return (register_operand (op, mode) || literal (op, mode));
216 }
217
218 /* Return truth value of whether OP can be used as an operands in a three
219 address logic insn, possibly complementing OP, of mode MODE. */
220
221 int
222 logic_operand (op, mode)
223 rtx op;
224 enum machine_mode mode;
225 {
226 return (register_operand (op, mode)
227 || (GET_CODE (op) == CONST_INT
228 && INTVAL(op) >= -32 && INTVAL(op) < 32));
229 }
230
231 /* Return true if OP is a register or a valid floating point literal. */
232
233 int
234 fp_arith_operand (op, mode)
235 rtx op;
236 enum machine_mode mode;
237 {
238 return (register_operand (op, mode) || fp_literal (op, mode));
239 }
240
241 /* Return true is OP is a register or a valid signed integer literal. */
242
243 int
244 signed_arith_operand (op, mode)
245 rtx op;
246 enum machine_mode mode;
247 {
248 return (register_operand (op, mode) || signed_literal (op, mode));
249 }
250
251 /* Return truth value of whether OP is a integer which fits the
252 range constraining immediate operands in three-address insns. */
253
254 int
255 literal (op, mode)
256 rtx op;
257 enum machine_mode mode;
258 {
259 return ((GET_CODE (op) == CONST_INT) && INTVAL(op) >= 0 && INTVAL(op) < 32);
260 }
261
262 /* Return true if OP is a float constant of 1. */
263
264 int
265 fp_literal_one (op, mode)
266 rtx op;
267 enum machine_mode mode;
268 {
269 return (TARGET_NUMERICS && mode == GET_MODE (op) && op == CONST1_RTX (mode));
270 }
271
272 /* Return true if OP is a float constant of 0. */
273
274 int
275 fp_literal_zero (op, mode)
276 rtx op;
277 enum machine_mode mode;
278 {
279 return (TARGET_NUMERICS && mode == GET_MODE (op) && op == CONST0_RTX (mode));
280 }
281
282 /* Return true if OP is a valid floating point literal. */
283
284 int
285 fp_literal(op, mode)
286 rtx op;
287 enum machine_mode mode;
288 {
289 return fp_literal_zero (op, mode) || fp_literal_one (op, mode);
290 }
291
292 /* Return true if OP is a valid signed immediate constant. */
293
294 int
295 signed_literal(op, mode)
296 rtx op;
297 enum machine_mode mode;
298 {
299 return ((GET_CODE (op) == CONST_INT) && INTVAL(op) > -32 && INTVAL(op) < 32);
300 }
301
302 /* Return truth value of statement that OP is a symbolic memory
303 operand of mode MODE. */
304
305 int
306 symbolic_memory_operand (op, mode)
307 rtx op;
308 enum machine_mode mode;
309 {
310 if (GET_CODE (op) == SUBREG)
311 op = SUBREG_REG (op);
312 if (GET_CODE (op) != MEM)
313 return 0;
314 op = XEXP (op, 0);
315 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
316 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
317 }
318
319 /* Return truth value of whether OP is EQ or NE. */
320
321 int
322 eq_or_neq (op, mode)
323 rtx op;
324 enum machine_mode mode;
325 {
326 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
327 }
328
329 /* OP is an integer register or a constant. */
330
331 int
332 arith32_operand (op, mode)
333 rtx op;
334 enum machine_mode mode;
335 {
336 if (register_operand (op, mode))
337 return 1;
338 return (CONSTANT_P (op));
339 }
340
341 /* Return true if OP is an integer constant which is a power of 2. */
342
343 int
344 power2_operand (op,mode)
345 rtx op;
346 enum machine_mode mode;
347 {
348 if (GET_CODE (op) != CONST_INT)
349 return 0;
350
351 return exact_log2 (INTVAL (op)) >= 0;
352 }
353
354 /* Return true if OP is an integer constant which is the complement of a
355 power of 2. */
356
357 int
358 cmplpower2_operand (op, mode)
359 rtx op;
360 enum machine_mode mode;
361 {
362 if (GET_CODE (op) != CONST_INT)
363 return 0;
364
365 return exact_log2 (~ INTVAL (op)) >= 0;
366 }
367
368 /* If VAL has only one bit set, return the index of that bit. Otherwise
369 return -1. */
370
371 int
372 bitpos (val)
373 unsigned int val;
374 {
375 register int i;
376
377 for (i = 0; val != 0; i++, val >>= 1)
378 {
379 if (val & 1)
380 {
381 if (val != 1)
382 return -1;
383 return i;
384 }
385 }
386 return -1;
387 }
388
389 /* Return non-zero if OP is a mask, i.e. all one bits are consecutive.
390 The return value indicates how many consecutive non-zero bits exist
391 if this is a mask. This is the same as the next function, except that
392 it does not indicate what the start and stop bit positions are. */
393
394 int
395 is_mask (val)
396 unsigned int val;
397 {
398 register int start, end, i;
399
400 start = -1;
401 for (i = 0; val != 0; val >>= 1, i++)
402 {
403 if (val & 1)
404 {
405 if (start < 0)
406 start = i;
407
408 end = i;
409 continue;
410 }
411 /* Still looking for the first bit. */
412 if (start < 0)
413 continue;
414
415 /* We've seen the start of a bit sequence, and now a zero. There
416 must be more one bits, otherwise we would have exited the loop.
417 Therefore, it is not a mask. */
418 if (val)
419 return 0;
420 }
421
422 /* The bit string has ones from START to END bit positions only. */
423 return end - start + 1;
424 }
425
426 /* If VAL is a mask, then return nonzero, with S set to the starting bit
427 position and E set to the ending bit position of the mask. The return
428 value indicates how many consecutive bits exist in the mask. This is
429 the same as the previous function, except that it also indicates the
430 start and end bit positions of the mask. */
431
432 int
433 bitstr (val, s, e)
434 unsigned int val;
435 int *s, *e;
436 {
437 register int start, end, i;
438
439 start = -1;
440 end = -1;
441 for (i = 0; val != 0; val >>= 1, i++)
442 {
443 if (val & 1)
444 {
445 if (start < 0)
446 start = i;
447
448 end = i;
449 continue;
450 }
451
452 /* Still looking for the first bit. */
453 if (start < 0)
454 continue;
455
456 /* We've seen the start of a bit sequence, and now a zero. There
457 must be more one bits, otherwise we would have exited the loop.
458 Therefor, it is not a mask. */
459 if (val)
460 {
461 start = -1;
462 end = -1;
463 break;
464 }
465 }
466
467 /* The bit string has ones from START to END bit positions only. */
468 *s = start;
469 *e = end;
470 return ((start < 0) ? 0 : end - start + 1);
471 }
472 \f
473 /* Return the machine mode to use for a comparison. */
474
475 enum machine_mode
476 select_cc_mode (op, x)
477 RTX_CODE op;
478 rtx x;
479 {
480 if (op == GTU || op == LTU || op == GEU || op == LEU)
481 return CC_UNSmode;
482 return CCmode;
483 }
484
485 /* X and Y are two things to compare using CODE. Emit the compare insn and
486 return the rtx for register 36 in the proper mode. */
487
488 rtx
489 gen_compare_reg (code, x, y)
490 enum rtx_code code;
491 rtx x, y;
492 {
493 rtx cc_reg;
494 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
495 enum machine_mode mode
496 = GET_MODE (x) == VOIDmode ? GET_MODE (y) : GET_MODE (x);
497
498 if (mode == SImode)
499 {
500 if (! arith_operand (x, mode))
501 x = force_reg (SImode, x);
502 if (! arith_operand (y, mode))
503 y = force_reg (SImode, y);
504 }
505
506 cc_reg = gen_rtx (REG, ccmode, 36);
507 emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
508 gen_rtx (COMPARE, ccmode, x, y)));
509
510 return cc_reg;
511 }
512
513 /* For the i960, REG is cost 1, REG+immed CONST is cost 2, REG+REG is cost 2,
514 REG+nonimmed CONST is cost 4. REG+SYMBOL_REF, SYMBOL_REF, and similar
515 are 4. Indexed addresses are cost 6. */
516
517 /* ??? Try using just RTX_COST, i.e. not defining ADDRESS_COST. */
518
519 int
520 i960_address_cost (x)
521 rtx x;
522 {
523 #if 0
524 /* Handled before calling here. */
525 if (GET_CODE (x) == REG)
526 return 1;
527 #endif
528 if (GET_CODE (x) == PLUS)
529 {
530 rtx base = XEXP (x, 0);
531 rtx offset = XEXP (x, 1);
532
533 if (GET_CODE (base) == SUBREG)
534 base = SUBREG_REG (base);
535 if (GET_CODE (offset) == SUBREG)
536 offset = SUBREG_REG (offset);
537
538 if (GET_CODE (base) == REG)
539 {
540 if (GET_CODE (offset) == REG)
541 return 2;
542 if (GET_CODE (offset) == CONST_INT)
543 {
544 if ((unsigned)INTVAL (offset) < 2047)
545 return 2;
546 return 4;
547 }
548 if (CONSTANT_P (offset))
549 return 4;
550 }
551 if (GET_CODE (base) == PLUS || GET_CODE (base) == MULT)
552 return 6;
553
554 /* This is an invalid address. The return value doesn't matter, but
555 for convenience we make this more expensive than anything else. */
556 return 12;
557 }
558 if (GET_CODE (x) == MULT)
559 return 6;
560
561 /* Symbol_refs and other unrecognized addresses are cost 4. */
562 return 4;
563 }
564 \f
565 /* Emit insns to move operands[1] into operands[0].
566
567 Return 1 if we have written out everything that needs to be done to
568 do the move. Otherwise, return 0 and the caller will emit the move
569 normally. */
570
571 int
572 emit_move_sequence (operands, mode)
573 rtx *operands;
574 enum machine_mode mode;
575 {
576 /* We can only store registers to memory. */
577
578 if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) != REG)
579 operands[1] = force_reg (mode, operands[1]);
580
581 /* Storing multi-word values in unaligned hard registers to memory may
582 require a scratch since we have to store them a register at a time and
583 adding 4 to the memory address may not yield a valid insn. */
584 /* ??? We don't always need the scratch, but that would complicate things.
585 Maybe later. */
586 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
587 && GET_CODE (operands[0]) == MEM
588 && GET_CODE (operands[1]) == REG
589 && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
590 && ! HARD_REGNO_MODE_OK (REGNO (operands[1]), mode))
591 {
592 emit_insn (gen_rtx (PARALLEL, VOIDmode,
593 gen_rtvec (2,
594 gen_rtx (SET, VOIDmode,
595 operands[0], operands[1]),
596 gen_rtx (CLOBBER, VOIDmode,
597 gen_rtx (SCRATCH, Pmode)))));
598 return 1;
599 }
600
601 return 0;
602 }
603
604 /* Output assembler to move a double word value. */
605
606 char *
607 i960_output_move_double (dst, src)
608 rtx dst, src;
609 {
610 rtx operands[5];
611
612 if (GET_CODE (dst) == REG
613 && GET_CODE (src) == REG)
614 {
615 if ((REGNO (src) & 1)
616 || (REGNO (dst) & 1))
617 {
618 /* We normally copy the low-numbered register first. However, if
619 the second source register is the same as the first destination
620 register, we must copy in the opposite order. */
621 if (REGNO (src) + 1 == REGNO (dst))
622 return "mov %D1,%D0\n\tmov %1,%0";
623 else
624 return "mov %1,%0\n\tmov %D1,%D0";
625 }
626 else
627 return "movl %1,%0";
628 }
629 else if (GET_CODE (dst) == REG
630 && GET_CODE (src) == CONST_INT
631 && CONST_OK_FOR_LETTER_P (INTVAL (src), 'I'))
632 {
633 if (REGNO (dst) & 1)
634 return "mov %1,%0\n\tmov 0,%D0";
635 else
636 return "movl %1,%0";
637 }
638 else if (GET_CODE (dst) == REG
639 && GET_CODE (src) == MEM)
640 {
641 if (REGNO (dst) & 1)
642 {
643 /* One can optimize a few cases here, but you have to be
644 careful of clobbering registers used in the address and
645 edge conditions. */
646 operands[0] = dst;
647 operands[1] = src;
648 operands[2] = gen_rtx (REG, Pmode, REGNO (dst) + 1);
649 operands[3] = gen_rtx (MEM, word_mode, operands[2]);
650 operands[4] = adj_offsettable_operand (operands[3], UNITS_PER_WORD);
651 output_asm_insn ("lda %1,%2\n\tld %3,%0\n\tld %4,%D0", operands);
652 return "";
653 }
654 else
655 return "ldl %1,%0";
656 }
657 else if (GET_CODE (dst) == MEM
658 && GET_CODE (src) == REG)
659 {
660 if (REGNO (src) & 1)
661 {
662 /* This is handled by emit_move_sequence so we shouldn't get here. */
663 abort ();
664 }
665 return "stl %1,%0";
666 }
667 else
668 abort ();
669 }
670
671 /* Output assembler to move a quad word value. */
672
673 char *
674 i960_output_move_quad (dst, src)
675 rtx dst, src;
676 {
677 rtx operands[7];
678
679 if (GET_CODE (dst) == REG
680 && GET_CODE (src) == REG)
681 {
682 if ((REGNO (src) & 3)
683 || (REGNO (dst) & 3))
684 {
685 /* We normally copy starting with the low numbered register.
686 However, if there is an overlap such that the first dest reg
687 is <= the last source reg but not < the first source reg, we
688 must copy in the opposite order. */
689 if (REGNO (dst) <= REGNO (src) + 3
690 && REGNO (dst) >= REGNO (src))
691 return "mov %F1,%F0\n\tmov %E1,%E0\n\tmov %D1,%D0\n\tmov %1,%0";
692 else
693 return "mov %1,%0\n\tmov %D1,%D0\n\tmov %E1,%E0\n\tmov %F1,%F0";
694 }
695 else
696 return "movq %1,%0";
697 }
698 else if (GET_CODE (dst) == REG
699 && GET_CODE (src) == CONST_INT
700 && CONST_OK_FOR_LETTER_P (INTVAL (src), 'I'))
701 {
702 if (REGNO (dst) & 3)
703 return "mov %1,%0\n\tmov 0,%D0\n\tmov 0,%E0\n\tmov 0,%F0";
704 else
705 return "movq %1,%0";
706 }
707 else if (GET_CODE (dst) == REG
708 && GET_CODE (src) == MEM)
709 {
710 if (REGNO (dst) & 3)
711 {
712 /* One can optimize a few cases here, but you have to be
713 careful of clobbering registers used in the address and
714 edge conditions. */
715 operands[0] = dst;
716 operands[1] = src;
717 operands[2] = gen_rtx (REG, Pmode, REGNO (dst) + 3);
718 operands[3] = gen_rtx (MEM, word_mode, operands[2]);
719 operands[4] = adj_offsettable_operand (operands[3], UNITS_PER_WORD);
720 operands[5] = adj_offsettable_operand (operands[4], UNITS_PER_WORD);
721 operands[6] = adj_offsettable_operand (operands[5], UNITS_PER_WORD);
722 output_asm_insn ("lda %1,%2\n\tld %3,%0\n\tld %4,%D0\n\tld %5,%E0\n\tld %6,%F0", operands);
723 return "";
724 }
725 else
726 return "ldq %1,%0";
727 }
728 else if (GET_CODE (dst) == MEM
729 && GET_CODE (src) == REG)
730 {
731 if (REGNO (src) & 3)
732 {
733 /* This is handled by emit_move_sequence so we shouldn't get here. */
734 abort ();
735 }
736 return "stq %1,%0";
737 }
738 else
739 abort ();
740 }
741 \f
742 /* Emit insns to load a constant to non-floating point registers.
743 Uses several strategies to try to use as few insns as possible. */
744
745 char *
746 i960_output_ldconst (dst, src)
747 register rtx dst, src;
748 {
749 register int rsrc1;
750 register unsigned rsrc2;
751 enum machine_mode mode = GET_MODE (dst);
752 rtx operands[4];
753
754 operands[0] = operands[2] = dst;
755 operands[1] = operands[3] = src;
756
757 /* Anything that isn't a compile time constant, such as a SYMBOL_REF,
758 must be a ldconst insn. */
759
760 if (GET_CODE (src) != CONST_INT && GET_CODE (src) != CONST_DOUBLE)
761 {
762 output_asm_insn ("ldconst %1,%0", operands);
763 return "";
764 }
765 else if (mode == XFmode)
766 {
767 REAL_VALUE_TYPE d;
768 long value_long[3];
769 int i;
770
771 if (fp_literal_zero (src, XFmode))
772 return "movt 0,%0";
773
774 REAL_VALUE_FROM_CONST_DOUBLE (d, src);
775 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, value_long);
776
777 output_asm_insn ("# ldconst %1,%0",operands);
778
779 for (i = 0; i < 3; i++)
780 {
781 operands[0] = gen_rtx (REG, SImode, REGNO (dst) + i);
782 operands[1] = GEN_INT (value_long[i]);
783 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
784 operands);
785 }
786
787 return "";
788 }
789 else if (mode == DFmode)
790 {
791 rtx first, second;
792
793 if (fp_literal_zero (src, DFmode))
794 return "movl 0,%0";
795
796 split_double (src, &first, &second);
797
798 output_asm_insn ("# ldconst %1,%0",operands);
799
800 operands[0] = gen_rtx (REG, SImode, REGNO (dst));
801 operands[1] = first;
802 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
803 operands);
804 operands[0] = gen_rtx (REG, SImode, REGNO (dst) + 1);
805 operands[1] = second;
806 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
807 operands);
808 return "";
809 }
810 else if (mode == SFmode)
811 {
812 REAL_VALUE_TYPE d;
813 long value;
814
815 REAL_VALUE_FROM_CONST_DOUBLE (d, src);
816 REAL_VALUE_TO_TARGET_SINGLE (d, value);
817
818 output_asm_insn ("# ldconst %1,%0",operands);
819 operands[0] = gen_rtx (REG, SImode, REGNO (dst));
820 operands[1] = gen_rtx (CONST_INT, VOIDmode, value);
821 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
822 operands);
823 return "";
824 }
825 else if (mode == TImode)
826 {
827 /* ??? This is currently not handled at all. */
828 abort ();
829
830 /* Note: lowest order word goes in lowest numbered reg. */
831 rsrc1 = INTVAL (src);
832 if (rsrc1 >= 0 && rsrc1 < 32)
833 return "movq %1,%0";
834 else
835 output_asm_insn ("movq\t0,%0\t# ldconstq %1,%0",operands);
836 /* Go pick up the low-order word. */
837 }
838 else if (mode == DImode)
839 {
840 rtx upperhalf, lowerhalf, xoperands[2];
841
842 if (GET_CODE (src) == CONST_DOUBLE || GET_CODE (src) == CONST_INT)
843 split_double (src, &lowerhalf, &upperhalf);
844
845 else
846 abort ();
847
848 /* Note: lowest order word goes in lowest numbered reg. */
849 /* Numbers from 0 to 31 can be handled with a single insn. */
850 rsrc1 = INTVAL (lowerhalf);
851 if (upperhalf == const0_rtx && rsrc1 >= 0 && rsrc1 < 32)
852 return "movl %1,%0";
853
854 /* Output the upper half with a recursive call. */
855 xoperands[0] = gen_rtx (REG, SImode, REGNO (dst) + 1);
856 xoperands[1] = upperhalf;
857 output_asm_insn (i960_output_ldconst (xoperands[0], xoperands[1]),
858 xoperands);
859 /* The lower word is emitted as normally. */
860 }
861 else
862 {
863 rsrc1 = INTVAL (src);
864 if (mode == QImode)
865 {
866 if (rsrc1 > 0xff)
867 rsrc1 &= 0xff;
868 }
869 else if (mode == HImode)
870 {
871 if (rsrc1 > 0xffff)
872 rsrc1 &= 0xffff;
873 }
874 }
875
876 if (rsrc1 >= 0)
877 {
878 /* ldconst 0..31,X -> mov 0..31,X */
879 if (rsrc1 < 32)
880 {
881 if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES)
882 return "lda %1,%0";
883 return "mov %1,%0";
884 }
885
886 /* ldconst 32..63,X -> add 31,nn,X */
887 if (rsrc1 < 63)
888 {
889 if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES)
890 return "lda %1,%0";
891 operands[1] = gen_rtx (CONST_INT, VOIDmode, rsrc1 - 31);
892 output_asm_insn ("addo\t31,%1,%0\t# ldconst %3,%0", operands);
893 return "";
894 }
895 }
896 else if (rsrc1 < 0)
897 {
898 /* ldconst -1..-31 -> sub 0,0..31,X */
899 if (rsrc1 >= -31)
900 {
901 /* return 'sub -(%1),0,%0' */
902 operands[1] = gen_rtx (CONST_INT, VOIDmode, - rsrc1);
903 output_asm_insn ("subo\t%1,0,%0\t# ldconst %3,%0", operands);
904 return "";
905 }
906
907 /* ldconst -32 -> not 31,X */
908 if (rsrc1 == -32)
909 {
910 operands[1] = gen_rtx (CONST_INT, VOIDmode, ~rsrc1);
911 output_asm_insn ("not\t%1,%0 # ldconst %3,%0", operands);
912 return "";
913 }
914 }
915
916 /* If const is a single bit. */
917 if (bitpos (rsrc1) >= 0)
918 {
919 operands[1] = gen_rtx (CONST_INT, VOIDmode, bitpos (rsrc1));
920 output_asm_insn ("setbit\t%1,0,%0\t# ldconst %3,%0", operands);
921 return "";
922 }
923
924 /* If const is a bit string of less than 6 bits (1..31 shifted). */
925 if (is_mask (rsrc1))
926 {
927 int s, e;
928
929 if (bitstr (rsrc1, &s, &e) < 6)
930 {
931 rsrc2 = ((unsigned int) rsrc1) >> s;
932 operands[1] = gen_rtx (CONST_INT, VOIDmode, rsrc2);
933 operands[2] = gen_rtx (CONST_INT, VOIDmode, s);
934 output_asm_insn ("shlo\t%2,%1,%0\t# ldconst %3,%0", operands);
935 return "";
936 }
937 }
938
939 /* Unimplemented cases:
940 const is in range 0..31 but rotated around end of word:
941 ror 31,3,g0 -> ldconst 0xe0000003,g0
942
943 and any 2 instruction cases that might be worthwhile */
944
945 output_asm_insn ("ldconst %1,%0", operands);
946 return "";
947 }
948
949 /* Determine if there is an opportunity for a bypass optimization.
950 Bypass succeeds on the 960K* if the destination of the previous
951 instruction is the second operand of the current instruction.
952 Bypass always succeeds on the C*.
953
954 Return 1 if the pattern should interchange the operands.
955
956 CMPBR_FLAG is true if this is for a compare-and-branch insn.
957 OP1 and OP2 are the two source operands of a 3 operand insn. */
958
959 int
960 i960_bypass (insn, op1, op2, cmpbr_flag)
961 register rtx insn, op1, op2;
962 int cmpbr_flag;
963 {
964 register rtx prev_insn, prev_dest;
965
966 if (TARGET_C_SERIES)
967 return 0;
968
969 /* Can't do this if op1 isn't a register. */
970 if (! REG_P (op1))
971 return 0;
972
973 /* Can't do this for a compare-and-branch if both ops aren't regs. */
974 if (cmpbr_flag && ! REG_P (op2))
975 return 0;
976
977 prev_insn = prev_real_insn (insn);
978
979 if (prev_insn && GET_CODE (prev_insn) == INSN
980 && GET_CODE (PATTERN (prev_insn)) == SET)
981 {
982 prev_dest = SET_DEST (PATTERN (prev_insn));
983 if ((GET_CODE (prev_dest) == REG && REGNO (prev_dest) == REGNO (op1))
984 || (GET_CODE (prev_dest) == SUBREG
985 && GET_CODE (SUBREG_REG (prev_dest)) == REG
986 && REGNO (SUBREG_REG (prev_dest)) == REGNO (op1)))
987 return 1;
988 }
989 return 0;
990 }
991 \f
992 /* Output the code which declares the function name. This also handles
993 leaf routines, which have special requirements, and initializes some
994 global variables. */
995
996 void
997 i960_function_name_declare (file, name, fndecl)
998 FILE *file;
999 char *name;
1000 tree fndecl;
1001 {
1002 register int i, j;
1003 int leaf_proc_ok;
1004 rtx insn;
1005
1006 /* Increment global return label. */
1007
1008 ret_label++;
1009
1010 /* Compute whether tail calls and leaf routine optimizations can be performed
1011 for this function. */
1012
1013 if (TARGET_TAILCALL)
1014 tail_call_ok = 1;
1015 else
1016 tail_call_ok = 0;
1017
1018 if (TARGET_LEAFPROC)
1019 leaf_proc_ok = 1;
1020 else
1021 leaf_proc_ok = 0;
1022
1023 /* Even if nobody uses extra parms, can't have leafproc or tail calls if
1024 argblock, because argblock uses g14 implicitly. */
1025
1026 if (current_function_args_size != 0 || VARARGS_STDARG_FUNCTION (fndecl))
1027 {
1028 tail_call_ok = 0;
1029 leaf_proc_ok = 0;
1030 }
1031
1032 /* See if caller passes in an address to return value. */
1033
1034 if (aggregate_value_p (DECL_RESULT (fndecl)))
1035 {
1036 tail_call_ok = 0;
1037 leaf_proc_ok = 0;
1038 }
1039
1040 /* Can not use tail calls or make this a leaf routine if there is a non
1041 zero frame size. */
1042
1043 if (get_frame_size () != 0)
1044 leaf_proc_ok = 0;
1045
1046 /* I don't understand this condition, and do not think that it is correct.
1047 Apparently this is just checking whether the frame pointer is used, and
1048 we can't trust regs_ever_live[fp] since it is (almost?) always set. */
1049
1050 if (tail_call_ok)
1051 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1052 if (GET_CODE (insn) == INSN
1053 && reg_mentioned_p (frame_pointer_rtx, insn))
1054 {
1055 tail_call_ok = 0;
1056 break;
1057 }
1058
1059 /* Check for CALL insns. Can not be a leaf routine if there are any. */
1060
1061 if (leaf_proc_ok)
1062 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1063 if (GET_CODE (insn) == CALL_INSN)
1064 {
1065 leaf_proc_ok = 0;
1066 break;
1067 }
1068
1069 /* Can not be a leaf routine if any non-call clobbered registers are
1070 used in this function. */
1071
1072 if (leaf_proc_ok)
1073 for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++)
1074 if (regs_ever_live[i]
1075 && ((! call_used_regs[i]) || (i > 7 && i < 12)))
1076 {
1077 /* Global registers. */
1078 if (i < 16 && i > 7 && i != 13)
1079 leaf_proc_ok = 0;
1080 /* Local registers. */
1081 else if (i < 32)
1082 leaf_proc_ok = 0;
1083 }
1084
1085 /* Now choose a leaf return register, if we can find one, and if it is
1086 OK for this to be a leaf routine. */
1087
1088 i960_leaf_ret_reg = -1;
1089
1090 if (optimize && leaf_proc_ok)
1091 {
1092 for (i960_leaf_ret_reg = -1, i = 0; i < 8; i++)
1093 if (regs_ever_live[i] == 0)
1094 {
1095 i960_leaf_ret_reg = i;
1096 regs_ever_live[i] = 1;
1097 break;
1098 }
1099 }
1100
1101 /* Do this after choosing the leaf return register, so it will be listed
1102 if one was chosen. */
1103
1104 fprintf (file, "\t# Function '%s'\n", (name[0] == '*' ? &name[1] : name));
1105 fprintf (file, "\t# Registers used: ");
1106
1107 for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++)
1108 {
1109 if (regs_ever_live[i])
1110 {
1111 fprintf (file, "%s%s ", reg_names[i], call_used_regs[i] ? "" : "*");
1112
1113 if (i > 15 && j == 0)
1114 {
1115 fprintf (file,"\n\t#\t\t ");
1116 j++;
1117 }
1118 }
1119 }
1120
1121 fprintf (file, "\n");
1122
1123 if (i960_leaf_ret_reg >= 0)
1124 {
1125 /* Make it a leaf procedure. */
1126
1127 if (TREE_PUBLIC (fndecl))
1128 fprintf (file,"\t.globl\t%s.lf\n", (name[0] == '*' ? &name[1] : name));
1129
1130 fprintf (file, "\t.leafproc\t");
1131 assemble_name (file, name);
1132 fprintf (file, ",%s.lf\n", (name[0] == '*' ? &name[1] : name));
1133 ASM_OUTPUT_LABEL (file, name);
1134 fprintf (file, "\tlda LR%d,g14\n", ret_label);
1135 fprintf (file, "%s.lf:\n", (name[0] == '*' ? &name[1] : name));
1136 fprintf (file, "\tmov g14,g%d\n", i960_leaf_ret_reg);
1137
1138 if (TARGET_C_SERIES)
1139 {
1140 fprintf (file, "\tlda 0,g14\n");
1141 i960_last_insn_type = I_TYPE_MEM;
1142 }
1143 else
1144 {
1145 fprintf (file, "\tmov 0,g14\n");
1146 i960_last_insn_type = I_TYPE_REG;
1147 }
1148 }
1149 else
1150 {
1151 ASM_OUTPUT_LABEL (file, name);
1152 i960_last_insn_type = I_TYPE_CTRL;
1153 }
1154 }
1155 \f
1156 /* Compute and return the frame size. */
1157
1158 int
1159 compute_frame_size (size)
1160 int size;
1161 {
1162 int actual_fsize;
1163 int outgoing_args_size = current_function_outgoing_args_size;
1164
1165 /* The STARTING_FRAME_OFFSET is totally hidden to us as far
1166 as size is concerned. */
1167 actual_fsize = (size + 15) & -16;
1168 actual_fsize += (outgoing_args_size + 15) & -16;
1169
1170 return actual_fsize;
1171 }
1172
1173 /* Output code for the function prologue. */
1174
1175 void
1176 i960_function_prologue (file, size)
1177 FILE *file;
1178 unsigned int size;
1179 {
1180 register int i, j, nr;
1181 int n_iregs = 0;
1182 int rsize = 0;
1183 int actual_fsize, offset;
1184 char tmpstr[1000];
1185 /* -1 if reg must be saved on proc entry, 0 if available, 1 if saved
1186 somewhere. */
1187 int regs[FIRST_PSEUDO_REGISTER];
1188
1189 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1190 if (regs_ever_live[i]
1191 && ((! call_used_regs[i]) || (i > 7 && i < 12)))
1192 {
1193 regs[i] = -1;
1194 /* Count global registers that need saving. */
1195 if (i < 16)
1196 n_iregs++;
1197 }
1198 else
1199 regs[i] = 0;
1200
1201 epilogue_string[0] = '\0';
1202
1203 if (profile_flag || profile_block_flag)
1204 {
1205 /* When profiling, we may use registers 20 to 27 to save arguments, so
1206 they can't be used here for saving globals. J is the number of
1207 argument registers the mcount call will save. */
1208 for (j = 7; j >= 0 && ! regs_ever_live[j]; j--)
1209 ;
1210
1211 for (i = 20; i <= j + 20; i++)
1212 regs[i] = -1;
1213 }
1214
1215 /* First look for local registers to save globals in. */
1216 for (i = 0; i < 16; i++)
1217 {
1218 if (regs[i] == 0)
1219 continue;
1220
1221 /* Start at r4, not r3. */
1222 for (j = 20; j < 32; j++)
1223 {
1224 if (regs[j] != 0)
1225 continue;
1226
1227 regs[i] = 1;
1228 regs[j] = -1;
1229 regs_ever_live[j] = 1;
1230 nr = 1;
1231 if (i <= 14 && i % 2 == 0 && j <= 30 && j % 2 == 0
1232 && regs[i+1] != 0 && regs[j+1] == 0)
1233 {
1234 nr = 2;
1235 regs[i+1] = 1;
1236 regs[j+1] = -1;
1237 regs_ever_live[j+1] = 1;
1238 }
1239 if (nr == 2 && i <= 12 && i % 4 == 0 && j <= 28 && j % 4 == 0
1240 && regs[i+2] != 0 && regs[j+2] == 0)
1241 {
1242 nr = 3;
1243 regs[i+2] = 1;
1244 regs[j+2] = -1;
1245 regs_ever_live[j+2] = 1;
1246 }
1247 if (nr == 3 && regs[i+3] != 0 && regs[j+3] == 0)
1248 {
1249 nr = 4;
1250 regs[i+3] = 1;
1251 regs[j+3] = -1;
1252 regs_ever_live[j+3] = 1;
1253 }
1254
1255 fprintf (file, "\tmov%s %s,%s\n",
1256 ((nr == 4) ? "q" :
1257 (nr == 3) ? "t" :
1258 (nr == 2) ? "l" : ""),
1259 reg_names[i], reg_names[j]);
1260 sprintf (tmpstr, "\tmov%s %s,%s\n",
1261 ((nr == 4) ? "q" :
1262 (nr == 3) ? "t" :
1263 (nr == 2) ? "l" : ""),
1264 reg_names[j], reg_names[i]);
1265 strcat (epilogue_string, tmpstr);
1266
1267 n_iregs -= nr;
1268 i += nr-1;
1269 break;
1270 }
1271 }
1272
1273 /* N_iregs is now the number of global registers that haven't been saved
1274 yet. */
1275
1276 rsize = (n_iregs * 4);
1277 actual_fsize = compute_frame_size (size) + rsize;
1278 #if 0
1279 /* ??? The 1.2.1 compiler does this also. This is meant to round the frame
1280 size up to the nearest multiple of 16. I don't know whether this is
1281 necessary, or even desirable.
1282
1283 The frame pointer must be aligned, but the call instruction takes care of
1284 that. If we leave the stack pointer unaligned, we may save a little on
1285 dynamic stack allocation. And we don't lose, at least according to the
1286 i960CA manual. */
1287 actual_fsize = (actual_fsize + 15) & ~0xF;
1288 #endif
1289
1290 /* Allocate space for register save and locals. */
1291 if (actual_fsize > 0)
1292 {
1293 if (actual_fsize < 32)
1294 fprintf (file, "\taddo %d,sp,sp\n", actual_fsize);
1295 else
1296 fprintf (file, "\tlda\t%d(sp),sp\n", actual_fsize);
1297 }
1298
1299 /* Take hardware register save area created by the call instruction
1300 into account, but store them before the argument block area. */
1301 offset = 64 + actual_fsize - compute_frame_size (0) - rsize;
1302 /* Save registers on stack if needed. */
1303 for (i = 0, j = n_iregs; j > 0 && i < 16; i++)
1304 {
1305 if (regs[i] != -1)
1306 continue;
1307
1308 nr = 1;
1309
1310 if (i <= 14 && i % 2 == 0 && regs[i+1] == -1 && offset % 2 == 0)
1311 nr = 2;
1312
1313 if (nr == 2 && i <= 12 && i % 4 == 0 && regs[i+2] == -1
1314 && offset % 4 == 0)
1315 nr = 3;
1316
1317 if (nr == 3 && regs[i+3] == -1)
1318 nr = 4;
1319
1320 fprintf (file,"\tst%s %s,%d(fp)\n",
1321 ((nr == 4) ? "q" :
1322 (nr == 3) ? "t" :
1323 (nr == 2) ? "l" : ""),
1324 reg_names[i], offset);
1325 sprintf (tmpstr,"\tld%s %d(fp),%s\n",
1326 ((nr == 4) ? "q" :
1327 (nr == 3) ? "t" :
1328 (nr == 2) ? "l" : ""),
1329 offset, reg_names[i]);
1330 strcat (epilogue_string, tmpstr);
1331 i += nr-1;
1332 j -= nr;
1333 offset += nr * 4;
1334 }
1335
1336 if (actual_fsize == 0 && size == 0 && rsize == 0)
1337 return;
1338
1339 fprintf (file, "\t#Prologue stats:\n");
1340 fprintf (file, "\t# Total Frame Size: %d bytes\n", actual_fsize);
1341
1342 if (size)
1343 fprintf (file, "\t# Local Variable Size: %d bytes\n", size);
1344 if (rsize)
1345 fprintf (file, "\t# Register Save Size: %d regs, %d bytes\n",
1346 n_iregs, rsize);
1347 fprintf (file, "\t#End Prologue#\n");
1348 }
1349
1350 /* Output code for the function profiler. */
1351
1352 void
1353 output_function_profiler (file, labelno)
1354 FILE *file;
1355 int labelno;
1356 {
1357 /* The last used parameter register. */
1358 int last_parm_reg;
1359 int i, j, increment;
1360 int varargs_stdarg_function
1361 = VARARGS_STDARG_FUNCTION (current_function_decl);
1362
1363 /* Figure out the last used parameter register. The proper thing to do
1364 is to walk incoming args of the function. A function might have live
1365 parameter registers even if it has no incoming args. Note that we
1366 don't have to save parameter registers g8 to g11 because they are
1367 call preserved. */
1368
1369 /* See also output_function_prologue, which tries to use local registers
1370 for preserved call-saved global registers. */
1371
1372 for (last_parm_reg = 7;
1373 last_parm_reg >= 0 && ! regs_ever_live[last_parm_reg];
1374 last_parm_reg--)
1375 ;
1376
1377 /* Save parameter registers in regs r4 (20) to r11 (27). */
1378
1379 for (i = 0, j = 4; i <= last_parm_reg; i += increment, j += increment)
1380 {
1381 if (i % 4 == 0 && (last_parm_reg - i) >= 3)
1382 increment = 4;
1383 else if (i % 4 == 0 && (last_parm_reg - i) >= 2)
1384 increment = 3;
1385 else if (i % 2 == 0 && (last_parm_reg - i) >= 1)
1386 increment = 2;
1387 else
1388 increment = 1;
1389
1390 fprintf (file, "\tmov%s g%d,r%d\n",
1391 (increment == 4 ? "q" : increment == 3 ? "t"
1392 : increment == 2 ? "l": ""), i, j);
1393 }
1394
1395 /* If this function uses the arg pointer, then save it in r3 and then
1396 set it to zero. */
1397
1398 if (current_function_args_size != 0 || varargs_stdarg_function)
1399 fprintf (file, "\tmov g14,r3\n\tmov 0,g14\n");
1400
1401 /* Load location address into g0 and call mcount. */
1402
1403 fprintf (file, "\tlda\tLP%d,g0\n\tcallx\tmcount\n", labelno);
1404
1405 /* If this function uses the arg pointer, restore it. */
1406
1407 if (current_function_args_size != 0 || varargs_stdarg_function)
1408 fprintf (file, "\tmov r3,g14\n");
1409
1410 /* Restore parameter registers. */
1411
1412 for (i = 0, j = 4; i <= last_parm_reg; i += increment, j += increment)
1413 {
1414 if (i % 4 == 0 && (last_parm_reg - i) >= 3)
1415 increment = 4;
1416 else if (i % 4 == 0 && (last_parm_reg - i) >= 2)
1417 increment = 3;
1418 else if (i % 2 == 0 && (last_parm_reg - i) >= 1)
1419 increment = 2;
1420 else
1421 increment = 1;
1422
1423 fprintf (file, "\tmov%s r%d,g%d\n",
1424 (increment == 4 ? "q" : increment == 3 ? "t"
1425 : increment == 2 ? "l": ""), j, i);
1426 }
1427 }
1428
1429 /* Output code for the function epilogue. */
1430
1431 void
1432 i960_function_epilogue (file, size)
1433 FILE *file;
1434 unsigned int size;
1435 {
1436 if (i960_leaf_ret_reg >= 0)
1437 {
1438 fprintf (file, "LR%d: ret\n", ret_label);
1439 return;
1440 }
1441
1442 if (*epilogue_string == 0)
1443 {
1444 register rtx tmp;
1445
1446 /* Emit a return insn, but only if control can fall through to here. */
1447
1448 tmp = get_last_insn ();
1449 while (tmp)
1450 {
1451 if (GET_CODE (tmp) == BARRIER)
1452 return;
1453 if (GET_CODE (tmp) == CODE_LABEL)
1454 break;
1455 if (GET_CODE (tmp) == JUMP_INSN)
1456 {
1457 if (GET_CODE (PATTERN (tmp)) == RETURN)
1458 return;
1459 break;
1460 }
1461 if (GET_CODE (tmp) == NOTE)
1462 {
1463 tmp = PREV_INSN (tmp);
1464 continue;
1465 }
1466 break;
1467 }
1468 fprintf (file, "LR%d: ret\n", ret_label);
1469 return;
1470 }
1471
1472 fprintf (file, "LR%d:\n", ret_label);
1473
1474 fprintf (file, "\t#EPILOGUE#\n");
1475
1476 /* Output the string created by the prologue which will restore all
1477 registers saved by the prologue. */
1478
1479 if (epilogue_string[0] != '\0')
1480 fprintf (file, "%s", epilogue_string);
1481
1482 /* Must clear g14 on return if this function set it.
1483 Only varargs/stdarg functions modify g14. */
1484
1485 if (VARARGS_STDARG_FUNCTION (current_function_decl))
1486 fprintf (file, "\tmov 0,g14\n");
1487
1488 fprintf (file, "\tret\n");
1489 fprintf (file, "\t#End Epilogue#\n");
1490 }
1491
1492 /* Output code for a call insn. */
1493
1494 char *
1495 i960_output_call_insn (target, argsize_rtx, arg_pointer, insn)
1496 register rtx target, argsize_rtx, arg_pointer, insn;
1497 {
1498 int argsize = INTVAL (argsize_rtx);
1499 rtx nexti = next_real_insn (insn);
1500 rtx operands[2];
1501 int varargs_stdarg_function
1502 = VARARGS_STDARG_FUNCTION (current_function_decl);
1503
1504 operands[0] = target;
1505 operands[1] = arg_pointer;
1506
1507 if (current_function_args_size != 0 || varargs_stdarg_function)
1508 output_asm_insn ("mov g14,r3", operands);
1509
1510 if (argsize > 48)
1511 output_asm_insn ("lda %a1,g14", operands);
1512 else if (current_function_args_size != 0 || varargs_stdarg_function)
1513 output_asm_insn ("mov 0,g14", operands);
1514
1515 /* The code used to assume that calls to SYMBOL_REFs could not be more
1516 than 24 bits away (b vs bx, callj vs callx). This is not true. This
1517 feature is now implemented by relaxing in the GNU linker. It can convert
1518 bx to b if in range, and callx to calls/call/balx/bal as appropriate. */
1519
1520 /* Nexti could be zero if the called routine is volatile. */
1521 if (optimize && (*epilogue_string == 0) && argsize == 0 && tail_call_ok
1522 && (nexti == 0 || GET_CODE (PATTERN (nexti)) == RETURN))
1523 {
1524 /* Delete following return insn. */
1525 if (nexti && no_labels_between_p (insn, nexti))
1526 delete_insn (nexti);
1527 output_asm_insn ("bx %0", operands);
1528 return "# notreached";
1529 }
1530
1531 output_asm_insn ("callx %0", operands);
1532
1533 /* If the caller sets g14 to the address of the argblock, then the caller
1534 must clear it after the return. */
1535
1536 if (current_function_args_size != 0 || varargs_stdarg_function)
1537 output_asm_insn ("mov r3,g14", operands);
1538 else if (argsize > 48)
1539 output_asm_insn ("mov 0,g14", operands);
1540
1541 return "";
1542 }
1543
1544 /* Output code for a return insn. */
1545
1546 char *
1547 i960_output_ret_insn (insn)
1548 register rtx insn;
1549 {
1550 static char lbuf[20];
1551
1552 if (*epilogue_string != 0)
1553 {
1554 if (! TARGET_CODE_ALIGN && next_real_insn (insn) == 0)
1555 return "";
1556
1557 sprintf (lbuf, "b LR%d", ret_label);
1558 return lbuf;
1559 }
1560
1561 /* Must clear g14 on return if this function set it.
1562 Only varargs/stdarg functions modify g14. */
1563
1564 if (VARARGS_STDARG_FUNCTION (current_function_decl))
1565 output_asm_insn ("mov 0,g14", 0);
1566
1567 if (i960_leaf_ret_reg >= 0)
1568 {
1569 sprintf (lbuf, "bx (%s)", reg_names[i960_leaf_ret_reg]);
1570 return lbuf;
1571 }
1572 return "ret";
1573 }
1574 \f
1575 #if 0
1576 /* Return a character string representing the branch prediction
1577 opcode to be tacked on an instruction. This must at least
1578 return a null string. */
1579
1580 char *
1581 i960_br_predict_opcode (lab_ref, insn)
1582 rtx lab_ref, insn;
1583 {
1584 if (TARGET_BRANCH_PREDICT)
1585 {
1586 unsigned long label_uid;
1587
1588 if (GET_CODE (lab_ref) == CODE_LABEL)
1589 label_uid = INSN_UID (lab_ref);
1590 else if (GET_CODE (lab_ref) == LABEL_REF)
1591 label_uid = INSN_UID (XEXP (lab_ref, 0));
1592 else
1593 return ".f";
1594
1595 /* If not optimizing, then the insn_addresses array will not be
1596 valid. In this case, always return ".t" since most branches
1597 are taken. If optimizing, return .t for backward branches
1598 and .f for forward branches. */
1599 if (! optimize
1600 || insn_addresses[label_uid] < insn_addresses[INSN_UID (insn)])
1601 return ".t";
1602 return ".f";
1603 }
1604
1605 return "";
1606 }
1607 #endif
1608
1609 /* Print the operand represented by rtx X formatted by code CODE. */
1610
1611 void
1612 i960_print_operand (file, x, code)
1613 FILE *file;
1614 rtx x;
1615 char code;
1616 {
1617 enum rtx_code rtxcode = GET_CODE (x);
1618
1619 if (rtxcode == REG)
1620 {
1621 switch (code)
1622 {
1623 case 'D':
1624 /* Second reg of a double or quad. */
1625 fprintf (file, "%s", reg_names[REGNO (x)+1]);
1626 break;
1627
1628 case 'E':
1629 /* Third reg of a quad. */
1630 fprintf (file, "%s", reg_names[REGNO (x)+2]);
1631 break;
1632
1633 case 'F':
1634 /* Fourth reg of a quad. */
1635 fprintf (file, "%s", reg_names[REGNO (x)+3]);
1636 break;
1637
1638 case 0:
1639 fprintf (file, "%s", reg_names[REGNO (x)]);
1640 break;
1641
1642 default:
1643 abort ();
1644 }
1645 return;
1646 }
1647 else if (rtxcode == MEM)
1648 {
1649 output_address (XEXP (x, 0));
1650 return;
1651 }
1652 else if (rtxcode == CONST_INT)
1653 {
1654 HOST_WIDE_INT val = INTVAL (x);
1655 if (code == 'C')
1656 val = ~val;
1657 if (val > 9999 || val < -999)
1658 fprintf (file, "0x%x", val);
1659 else
1660 fprintf (file, "%d", val);
1661 return;
1662 }
1663 else if (rtxcode == CONST_DOUBLE)
1664 {
1665 REAL_VALUE_TYPE d;
1666 char dstr[30];
1667
1668 if (x == CONST0_RTX (GET_MODE (x)))
1669 {
1670 fprintf (file, "0f0.0");
1671 return;
1672 }
1673 else if (x == CONST1_RTX (GET_MODE (x)))
1674 {
1675 fprintf (file, "0f1.0");
1676 return;
1677 }
1678
1679 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1680 REAL_VALUE_TO_DECIMAL (d, "%#g", dstr);
1681 fprintf (file, "0f%s", dstr);
1682 return;
1683 }
1684
1685 switch(code)
1686 {
1687 case 'B':
1688 /* Branch or jump, depending on assembler. */
1689 if (TARGET_ASM_COMPAT)
1690 fputs ("j", file);
1691 else
1692 fputs ("b", file);
1693 break;
1694
1695 case 'S':
1696 /* Sign of condition. */
1697 if ((rtxcode == EQ) || (rtxcode == NE) || (rtxcode == GTU)
1698 || (rtxcode == LTU) || (rtxcode == GEU) || (rtxcode == LEU))
1699 fputs ("o", file);
1700 else if ((rtxcode == GT) || (rtxcode == LT)
1701 || (rtxcode == GE) || (rtxcode == LE))
1702 fputs ("i", file);
1703 else
1704 abort();
1705 break;
1706
1707 case 'I':
1708 /* Inverted condition. */
1709 rtxcode = reverse_condition (rtxcode);
1710 goto normal;
1711
1712 case 'X':
1713 /* Inverted condition w/ reversed operands. */
1714 rtxcode = reverse_condition (rtxcode);
1715 /* Fallthrough. */
1716
1717 case 'R':
1718 /* Reversed operand condition. */
1719 rtxcode = swap_condition (rtxcode);
1720 /* Fallthrough. */
1721
1722 case 'C':
1723 /* Normal condition. */
1724 normal:
1725 if (rtxcode == EQ) { fputs ("e", file); return; }
1726 else if (rtxcode == NE) { fputs ("ne", file); return; }
1727 else if (rtxcode == GT) { fputs ("g", file); return; }
1728 else if (rtxcode == GTU) { fputs ("g", file); return; }
1729 else if (rtxcode == LT) { fputs ("l", file); return; }
1730 else if (rtxcode == LTU) { fputs ("l", file); return; }
1731 else if (rtxcode == GE) { fputs ("ge", file); return; }
1732 else if (rtxcode == GEU) { fputs ("ge", file); return; }
1733 else if (rtxcode == LE) { fputs ("le", file); return; }
1734 else if (rtxcode == LEU) { fputs ("le", file); return; }
1735 else abort ();
1736 break;
1737
1738 case 0:
1739 output_addr_const (file, x);
1740 break;
1741
1742 default:
1743 abort ();
1744 }
1745
1746 return;
1747 }
1748 \f
1749 /* Print a memory address as an operand to reference that memory location.
1750
1751 This is exactly the same as legitimate_address_p, except that it the prints
1752 addresses instead of recognizing them. */
1753
1754 void
1755 i960_print_operand_addr (file, addr)
1756 FILE *file;
1757 register rtx addr;
1758 {
1759 rtx breg, ireg;
1760 rtx scale, offset;
1761
1762 ireg = 0;
1763 breg = 0;
1764 offset = 0;
1765 scale = const1_rtx;
1766
1767 if (GET_CODE (addr) == REG)
1768 breg = addr;
1769 else if (CONSTANT_P (addr))
1770 offset = addr;
1771 else if (GET_CODE (addr) == PLUS)
1772 {
1773 rtx op0, op1;
1774
1775 op0 = XEXP (addr, 0);
1776 op1 = XEXP (addr, 1);
1777
1778 if (GET_CODE (op0) == REG)
1779 {
1780 breg = op0;
1781 if (GET_CODE (op1) == REG)
1782 ireg = op1;
1783 else if (CONSTANT_P (op1))
1784 offset = op1;
1785 else
1786 abort ();
1787 }
1788 else if (GET_CODE (op0) == PLUS)
1789 {
1790 if (GET_CODE (XEXP (op0, 0)) == MULT)
1791 {
1792 ireg = XEXP (XEXP (op0, 0), 0);
1793 scale = XEXP (XEXP (op0, 0), 1);
1794 if (GET_CODE (XEXP (op0, 1)) == REG)
1795 {
1796 breg = XEXP (op0, 1);
1797 offset = op1;
1798 }
1799 else
1800 abort ();
1801 }
1802 else if (GET_CODE (XEXP (op0, 0)) == REG)
1803 {
1804 breg = XEXP (op0, 0);
1805 if (GET_CODE (XEXP (op0, 1)) == REG)
1806 {
1807 ireg = XEXP (op0, 1);
1808 offset = op1;
1809 }
1810 else
1811 abort ();
1812 }
1813 else
1814 abort ();
1815 }
1816 else if (GET_CODE (op0) == MULT)
1817 {
1818 ireg = XEXP (op0, 0);
1819 scale = XEXP (op0, 1);
1820 if (GET_CODE (op1) == REG)
1821 breg = op1;
1822 else if (CONSTANT_P (op1))
1823 offset = op1;
1824 else
1825 abort ();
1826 }
1827 else
1828 abort ();
1829 }
1830 else if (GET_CODE (addr) == MULT)
1831 {
1832 ireg = XEXP (addr, 0);
1833 scale = XEXP (addr, 1);
1834 }
1835 else
1836 abort ();
1837
1838 if (offset)
1839 output_addr_const (file, offset);
1840 if (breg)
1841 fprintf (file, "(%s)", reg_names[REGNO (breg)]);
1842 if (ireg)
1843 fprintf (file, "[%s*%d]", reg_names[REGNO (ireg)], INTVAL (scale));
1844 }
1845 \f
1846 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
1847 that is a valid memory address for an instruction.
1848 The MODE argument is the machine mode for the MEM expression
1849 that wants to use this address.
1850
1851 On 80960, legitimate addresses are:
1852 base ld (g0),r0
1853 disp (12 or 32 bit) ld foo,r0
1854 base + index ld (g0)[g1*1],r0
1855 base + displ ld 0xf00(g0),r0
1856 base + index*scale + displ ld 0xf00(g0)[g1*4],r0
1857 index*scale + base ld (g0)[g1*4],r0
1858 index*scale + displ ld 0xf00[g1*4],r0
1859 index*scale ld [g1*4],r0
1860 index + base + displ ld 0xf00(g0)[g1*1],r0
1861
1862 In each case, scale can be 1, 2, 4, 8, or 16. */
1863
1864 /* This is exactly the same as i960_print_operand_addr, except that
1865 it recognizes addresses instead of printing them.
1866
1867 It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should
1868 convert common non-canonical forms to canonical form so that they will
1869 be recognized. */
1870
1871 /* These two macros allow us to accept either a REG or a SUBREG anyplace
1872 where a register is valid. */
1873
1874 #define RTX_OK_FOR_BASE_P(X, STRICT) \
1875 ((GET_CODE (X) == REG \
1876 && (STRICT ? REG_OK_FOR_BASE_P_STRICT (X) : REG_OK_FOR_BASE_P (X))) \
1877 || (GET_CODE (X) == SUBREG \
1878 && GET_CODE (SUBREG_REG (X)) == REG \
1879 && (STRICT ? REG_OK_FOR_BASE_P_STRICT (SUBREG_REG (X)) \
1880 : REG_OK_FOR_BASE_P (SUBREG_REG (X)))))
1881
1882 #define RTX_OK_FOR_INDEX_P(X, STRICT) \
1883 ((GET_CODE (X) == REG \
1884 && (STRICT ? REG_OK_FOR_INDEX_P_STRICT (X) : REG_OK_FOR_INDEX_P (X)))\
1885 || (GET_CODE (X) == SUBREG \
1886 && GET_CODE (SUBREG_REG (X)) == REG \
1887 && (STRICT ? REG_OK_FOR_INDEX_P_STRICT (SUBREG_REG (X)) \
1888 : REG_OK_FOR_INDEX_P (SUBREG_REG (X)))))
1889
1890 int
1891 legitimate_address_p (mode, addr, strict)
1892 enum machine_mode mode;
1893 register rtx addr;
1894 int strict;
1895 {
1896 if (RTX_OK_FOR_BASE_P (addr, strict))
1897 return 1;
1898 else if (CONSTANT_P (addr))
1899 return 1;
1900 else if (GET_CODE (addr) == PLUS)
1901 {
1902 rtx op0, op1;
1903
1904 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1905 return 0;
1906
1907 op0 = XEXP (addr, 0);
1908 op1 = XEXP (addr, 1);
1909
1910 if (RTX_OK_FOR_BASE_P (op0, strict))
1911 {
1912 if (RTX_OK_FOR_INDEX_P (op1, strict))
1913 return 1;
1914 else if (CONSTANT_P (op1))
1915 return 1;
1916 else
1917 return 0;
1918 }
1919 else if (GET_CODE (op0) == PLUS)
1920 {
1921 if (GET_CODE (XEXP (op0, 0)) == MULT)
1922 {
1923 if (! (RTX_OK_FOR_INDEX_P (XEXP (XEXP (op0, 0), 0), strict)
1924 && SCALE_TERM_P (XEXP (XEXP (op0, 0), 1))))
1925 return 0;
1926
1927 if (RTX_OK_FOR_BASE_P (XEXP (op0, 1), strict)
1928 && CONSTANT_P (op1))
1929 return 1;
1930 else
1931 return 0;
1932 }
1933 else if (RTX_OK_FOR_BASE_P (XEXP (op0, 0), strict))
1934 {
1935 if (RTX_OK_FOR_INDEX_P (XEXP (op0, 1), strict)
1936 && CONSTANT_P (op1))
1937 return 1;
1938 else
1939 return 0;
1940 }
1941 else
1942 return 0;
1943 }
1944 else if (GET_CODE (op0) == MULT)
1945 {
1946 if (! (RTX_OK_FOR_INDEX_P (XEXP (op0, 0), strict)
1947 && SCALE_TERM_P (XEXP (op0, 1))))
1948 return 0;
1949
1950 if (RTX_OK_FOR_BASE_P (op1, strict))
1951 return 1;
1952 else if (CONSTANT_P (op1))
1953 return 1;
1954 else
1955 return 0;
1956 }
1957 else
1958 return 0;
1959 }
1960 else if (GET_CODE (addr) == MULT)
1961 {
1962 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1963 return 0;
1964
1965 return (RTX_OK_FOR_INDEX_P (XEXP (addr, 0), strict)
1966 && SCALE_TERM_P (XEXP (addr, 1)));
1967 }
1968 else
1969 return 0;
1970 }
1971
1972 /* Try machine-dependent ways of modifying an illegitimate address
1973 to be legitimate. If we find one, return the new, valid address.
1974 This macro is used in only one place: `memory_address' in explow.c.
1975
1976 This converts some non-canonical addresses to canonical form so they
1977 can be recognized. */
1978
1979 rtx
1980 legitimize_address (x, oldx, mode)
1981 register rtx x;
1982 register rtx oldx;
1983 enum machine_mode mode;
1984 {
1985 if (GET_CODE (x) == SYMBOL_REF)
1986 {
1987 abort ();
1988 x = copy_to_reg (x);
1989 }
1990
1991 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1992 return x;
1993
1994 /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
1995 into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be
1996 created by virtual register instantiation, register elimination, and
1997 similar optimizations. */
1998 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1999 && GET_CODE (XEXP (x, 1)) == PLUS)
2000 x = gen_rtx (PLUS, Pmode,
2001 gen_rtx (PLUS, Pmode, XEXP (x, 0), XEXP (XEXP (x, 1), 0)),
2002 XEXP (XEXP (x, 1), 1));
2003
2004 /* Canonicalize (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
2005 into (plus (plus (mult (reg) (const)) (reg)) (const)). */
2006 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
2007 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
2008 && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
2009 && CONSTANT_P (XEXP (x, 1)))
2010 {
2011 rtx constant, other;
2012
2013 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
2014 {
2015 constant = XEXP (x, 1);
2016 other = XEXP (XEXP (XEXP (x, 0), 1), 1);
2017 }
2018 else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT)
2019 {
2020 constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
2021 other = XEXP (x, 1);
2022 }
2023 else
2024 constant = 0;
2025
2026 if (constant)
2027 x = gen_rtx (PLUS, Pmode,
2028 gen_rtx (PLUS, Pmode, XEXP (XEXP (x, 0), 0),
2029 XEXP (XEXP (XEXP (x, 0), 1), 0)),
2030 plus_constant (other, INTVAL (constant)));
2031 }
2032
2033 return x;
2034 }
2035 \f
2036 #if 0
2037 /* Return the most stringent alignment that we are willing to consider
2038 objects of size SIZE and known alignment ALIGN as having. */
2039
2040 int
2041 i960_alignment (size, align)
2042 int size;
2043 int align;
2044 {
2045 int i;
2046
2047 if (! TARGET_STRICT_ALIGN)
2048 if (TARGET_IC_COMPAT2_0 || align >= 4)
2049 {
2050 i = i960_object_bytes_bitalign (size) / BITS_PER_UNIT;
2051 if (i > align)
2052 align = i;
2053 }
2054
2055 return align;
2056 }
2057 #endif
2058 \f
2059 /* Modes for condition codes. */
2060 #define C_MODES \
2061 ((1 << (int) CCmode) | (1 << (int) CC_UNSmode) | (1<< (int) CC_CHKmode))
2062
2063 /* Modes for single-word (and smaller) quantities. */
2064 #define S_MODES \
2065 (~C_MODES \
2066 & ~ ((1 << (int) DImode) | (1 << (int) TImode) \
2067 | (1 << (int) DFmode) | (1 << (int) XFmode)))
2068
2069 /* Modes for double-word (and smaller) quantities. */
2070 #define D_MODES \
2071 (~C_MODES \
2072 & ~ ((1 << (int) TImode) | (1 << (int) XFmode)))
2073
2074 /* Modes for quad-word quantities. */
2075 #define T_MODES (~C_MODES)
2076
2077 /* Modes for single-float quantities. */
2078 #define SF_MODES ((1 << (int) SFmode))
2079
2080 /* Modes for double-float quantities. */
2081 #define DF_MODES (SF_MODES | (1 << (int) DFmode) | (1 << (int) SCmode))
2082
2083 /* Modes for quad-float quantities. */
2084 #define XF_MODES (DF_MODES | (1 << (int) XFmode) | (1 << (int) DCmode))
2085
2086 unsigned int hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] = {
2087 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
2088 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
2089 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
2090 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
2091
2092 XF_MODES, XF_MODES, XF_MODES, XF_MODES, C_MODES};
2093
2094 \f
2095 /* Return the minimum alignment of an expression rtx X in bytes. This takes
2096 advantage of machine specific facts, such as knowing that the frame pointer
2097 is always 16 byte aligned. */
2098
2099 int
2100 i960_expr_alignment (x, size)
2101 rtx x;
2102 int size;
2103 {
2104 int align = 1;
2105
2106 if (x == 0)
2107 return 1;
2108
2109 switch (GET_CODE(x))
2110 {
2111 case CONST_INT:
2112 align = INTVAL(x);
2113
2114 if ((align & 0xf) == 0)
2115 align = 16;
2116 else if ((align & 0x7) == 0)
2117 align = 8;
2118 else if ((align & 0x3) == 0)
2119 align = 4;
2120 else if ((align & 0x1) == 0)
2121 align = 2;
2122 else
2123 align = 1;
2124 break;
2125
2126 case PLUS:
2127 align = MIN (i960_expr_alignment (XEXP (x, 0), size),
2128 i960_expr_alignment (XEXP (x, 1), size));
2129 break;
2130
2131 case SYMBOL_REF:
2132 /* If this is a valid program, objects are guaranteed to be
2133 correctly aligned for whatever size the reference actually is. */
2134 align = i960_object_bytes_bitalign (size) / BITS_PER_UNIT;
2135 break;
2136
2137 case REG:
2138 if (REGNO (x) == FRAME_POINTER_REGNUM)
2139 align = 16;
2140 break;
2141
2142 case ASHIFT:
2143 align = i960_expr_alignment (XEXP (x, 0));
2144
2145 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
2146 {
2147 align = align << INTVAL (XEXP (x, 1));
2148 align = MIN (align, 16);
2149 }
2150 break;
2151
2152 case MULT:
2153 align = (i960_expr_alignment (XEXP (x, 0), size) *
2154 i960_expr_alignment (XEXP (x, 1), size));
2155
2156 align = MIN (align, 16);
2157 break;
2158 }
2159
2160 return align;
2161 }
2162
2163 /* Return true if it is possible to reference both BASE and OFFSET, which
2164 have alignment at least as great as 4 byte, as if they had alignment valid
2165 for an object of size SIZE. */
2166
2167 int
2168 i960_improve_align (base, offset, size)
2169 rtx base;
2170 rtx offset;
2171 int size;
2172 {
2173 int i, j;
2174
2175 /* We have at least a word reference to the object, so we know it has to
2176 be aligned at least to 4 bytes. */
2177
2178 i = MIN (i960_expr_alignment (base, 4),
2179 i960_expr_alignment (offset, 4));
2180
2181 i = MAX (i, 4);
2182
2183 /* We know the size of the request. If strict align is not enabled, we
2184 can guess that the alignment is OK for the requested size. */
2185
2186 if (! TARGET_STRICT_ALIGN)
2187 if ((j = (i960_object_bytes_bitalign (size) / BITS_PER_UNIT)) > i)
2188 i = j;
2189
2190 return (i >= size);
2191 }
2192
2193 /* Return true if it is possible to access BASE and OFFSET, which have 4 byte
2194 (SImode) alignment as if they had 16 byte (TImode) alignment. */
2195
2196 int
2197 i960_si_ti (base, offset)
2198 rtx base;
2199 rtx offset;
2200 {
2201 return i960_improve_align (base, offset, 16);
2202 }
2203
2204 /* Return true if it is possible to access BASE and OFFSET, which have 4 byte
2205 (SImode) alignment as if they had 8 byte (DImode) alignment. */
2206
2207 int
2208 i960_si_di (base, offset)
2209 rtx base;
2210 rtx offset;
2211 {
2212 return i960_improve_align (base, offset, 8);
2213 }
2214 \f
2215 /* Return raw values of size and alignment (in words) for the data
2216 type being accessed. These values will be rounded by the caller. */
2217
2218 static void
2219 i960_arg_size_and_align (mode, type, size_out, align_out)
2220 enum machine_mode mode;
2221 tree type;
2222 int *size_out;
2223 int *align_out;
2224 {
2225 int size, align;
2226
2227 /* Use formal alignment requirements of type being passed, except make
2228 it at least a word. If we don't have a type, this is a library call,
2229 and the parm has to be of scalar type. In this case, consider its
2230 formal alignment requirement to be its size in words. */
2231
2232 if (mode == BLKmode)
2233 size = (int_size_in_bytes (type) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2234 else if (mode == VOIDmode)
2235 {
2236 /* End of parm list. */
2237 assert (type != 0 && TYPE_MODE (type) == VOIDmode);
2238 size = 1;
2239 }
2240 else
2241 size = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2242
2243 if (type == 0)
2244 {
2245 /* ??? This is a hack to properly correct the alignment of XFmode
2246 values without affecting anything else. */
2247 if (size == 3)
2248 align = 4;
2249 else
2250 align = size;
2251 }
2252 else if (TYPE_ALIGN (type) >= BITS_PER_WORD)
2253 align = TYPE_ALIGN (type) / BITS_PER_WORD;
2254 else
2255 align = 1;
2256
2257 *size_out = size;
2258 *align_out = align;
2259 }
2260
2261 /* On the 80960 the first 12 args are in registers and the rest are pushed.
2262 Any arg that is bigger than 4 words is placed on the stack and all
2263 subsequent arguments are placed on the stack.
2264
2265 Additionally, parameters with an alignment requirement stronger than
2266 a word must be aligned appropriately. Note that this means that a
2267 64 bit object with a 32 bit alignment is not 64 bit aligned and may be
2268 passed in an odd/even register pair. */
2269
2270 /* Update CUM to advance past an argument described by MODE and TYPE. */
2271
2272 void
2273 i960_function_arg_advance (cum, mode, type, named)
2274 CUMULATIVE_ARGS *cum;
2275 enum machine_mode mode;
2276 tree type;
2277 int named;
2278 {
2279 int size, align;
2280
2281 i960_arg_size_and_align (mode, type, &size, &align);
2282
2283 if (size > 4 || cum->ca_nstackparms != 0
2284 || (size + ROUND_PARM (cum->ca_nregparms, align)) > NPARM_REGS
2285 || MUST_PASS_IN_STACK (mode, type))
2286 {
2287 /* Indicate that all the registers are in use, even if all are not,
2288 so va_start will compute the right value. */
2289 cum->ca_nregparms = NPARM_REGS;
2290 cum->ca_nstackparms = ROUND_PARM (cum->ca_nstackparms, align) + size;
2291 }
2292 else
2293 cum->ca_nregparms = ROUND_PARM (cum->ca_nregparms, align) + size;
2294 }
2295
2296 /* Return the register that the argument described by MODE and TYPE is
2297 passed in, or else return 0 if it is passed on the stack. */
2298
2299 rtx
2300 i960_function_arg (cum, mode, type, named)
2301 CUMULATIVE_ARGS *cum;
2302 enum machine_mode mode;
2303 tree type;
2304 int named;
2305 {
2306 rtx ret;
2307 int size, align;
2308
2309 i960_arg_size_and_align (mode, type, &size, &align);
2310
2311 if (size > 4 || cum->ca_nstackparms != 0
2312 || (size + ROUND_PARM (cum->ca_nregparms, align)) > NPARM_REGS
2313 || MUST_PASS_IN_STACK (mode, type))
2314 {
2315 cum->ca_nstackparms = ROUND_PARM (cum->ca_nstackparms, align);
2316 ret = 0;
2317 }
2318 else
2319 {
2320 cum->ca_nregparms = ROUND_PARM (cum->ca_nregparms, align);
2321 ret = gen_rtx (REG, mode, cum->ca_nregparms);
2322 }
2323
2324 return ret;
2325 }
2326 \f
2327 /* Floating-point support. */
2328
2329 void
2330 i960_output_long_double (file, value)
2331 FILE *file;
2332 REAL_VALUE_TYPE value;
2333 {
2334 long value_long[3];
2335 char dstr[30];
2336
2337 REAL_VALUE_TO_TARGET_LONG_DOUBLE (value, value_long);
2338 REAL_VALUE_TO_DECIMAL (value, "%.20g", dstr);
2339
2340 fprintf (file,
2341 "\t.word\t0x%08lx\t\t# %s\n\t.word\t0x%08lx\n\t.word\t0x%08lx\n",
2342 value_long[0], dstr, value_long[1], value_long[2]);
2343 fprintf (file, "\t.word\t0x0\n");
2344 }
2345
2346 void
2347 i960_output_double (file, value)
2348 FILE *file;
2349 REAL_VALUE_TYPE value;
2350 {
2351 long value_long[2];
2352 char dstr[30];
2353
2354 REAL_VALUE_TO_TARGET_DOUBLE (value, value_long);
2355 REAL_VALUE_TO_DECIMAL (value, "%.20g", dstr);
2356
2357 fprintf (file, "\t.word\t0x%08lx\t\t# %s\n\t.word\t0x%08lx\n",
2358 value_long[0], dstr, value_long[1]);
2359 }
2360
2361 void
2362 i960_output_float (file, value)
2363 FILE *file;
2364 REAL_VALUE_TYPE value;
2365 {
2366 long value_long;
2367 char dstr[30];
2368
2369 REAL_VALUE_TO_TARGET_SINGLE (value, value_long);
2370 REAL_VALUE_TO_DECIMAL (value, "%.12g", dstr);
2371
2372 fprintf (file, "\t.word\t0x%08lx\t\t# %s (float)\n", value_long, dstr);
2373 }
2374 \f
2375 /* Return the number of bits that an object of size N bytes is aligned to. */
2376
2377 int
2378 i960_object_bytes_bitalign (n)
2379 int n;
2380 {
2381 if (n > 8) n = 128;
2382 else if (n > 4) n = 64;
2383 else if (n > 2) n = 32;
2384 else if (n > 1) n = 16;
2385 else n = 8;
2386
2387 return n;
2388 }
2389
2390 /* Compute the alignment for an aggregate type TSIZE.
2391 Alignment is MAX (greatest member alignment,
2392 MIN (pragma align, structure size alignment)). */
2393
2394 int
2395 i960_round_align (align, tsize)
2396 int align;
2397 tree tsize;
2398 {
2399 int new_align;
2400
2401 if (TREE_CODE (tsize) != INTEGER_CST)
2402 return align;
2403
2404 new_align = i960_object_bytes_bitalign (TREE_INT_CST_LOW (tsize)
2405 / BITS_PER_UNIT);
2406 /* Handle #pragma align. */
2407 if (new_align > i960_maxbitalignment)
2408 new_align = i960_maxbitalignment;
2409
2410 if (align < new_align)
2411 align = new_align;
2412
2413 return align;
2414 }
2415 \f
2416 /* Do any needed setup for a varargs function. For the i960, we must
2417 create a register parameter block if one doesn't exist, and then copy
2418 all register parameters to memory. */
2419
2420 void
2421 i960_setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
2422 CUMULATIVE_ARGS *cum;
2423 enum machine_mode mode;
2424 tree type;
2425 int *pretend_size;
2426 int no_rtl;
2427 {
2428 /* Note: for a varargs fn with only a va_alist argument, this is 0. */
2429 int first_reg = cum->ca_nregparms;
2430
2431 /* Copy only unnamed register arguments to memory. If there are
2432 any stack parms, there are no unnamed arguments in registers, and
2433 an argument block was already allocated by the caller.
2434 Remember that any arg bigger than 4 words is passed on the stack as
2435 are all subsequent args.
2436
2437 If there are no stack arguments but there are exactly NPARM_REGS
2438 registers, either there were no extra arguments or the caller
2439 allocated an argument block. */
2440
2441 if (cum->ca_nstackparms == 0 && first_reg < NPARM_REGS && !no_rtl)
2442 {
2443 rtx label = gen_label_rtx ();
2444 rtx regblock;
2445
2446 /* If arg_pointer_rtx == 0, no arguments were passed on the stack
2447 and we need to allocate a chunk to save the registers (if any
2448 arguments were passed on the stack the caller would allocate the
2449 48 bytes as well). We must allocate all 48 bytes (12*4) because
2450 va_start assumes it. */
2451 emit_insn (gen_cmpsi (arg_pointer_rtx, const0_rtx));
2452 emit_jump_insn (gen_bne (label));
2453 emit_insn (gen_rtx (SET, VOIDmode, arg_pointer_rtx,
2454 stack_pointer_rtx));
2455 emit_insn (gen_rtx (SET, VOIDmode, stack_pointer_rtx,
2456 memory_address (SImode,
2457 plus_constant (stack_pointer_rtx,
2458 48))));
2459 emit_label (label);
2460
2461 /* ??? Note that we unnecessarily store one extra register for stdarg
2462 fns. We could optimize this, but it's kept as for now. */
2463 regblock = gen_rtx (MEM, BLKmode,
2464 plus_constant (arg_pointer_rtx,
2465 first_reg * 4));
2466 move_block_from_reg (first_reg, regblock,
2467 NPARM_REGS - first_reg,
2468 (NPARM_REGS - first_reg) * UNITS_PER_WORD);
2469 }
2470 }
2471
2472 /* Calculate the final size of the reg parm stack space for the current
2473 function, based on how many bytes would be allocated on the stack. */
2474
2475 int
2476 i960_final_reg_parm_stack_space (const_size, var_size)
2477 int const_size;
2478 tree var_size;
2479 {
2480 if (var_size || const_size > 48)
2481 return 48;
2482 else
2483 return 0;
2484 }
2485
2486 /* Calculate the size of the reg parm stack space. This is a bit complicated
2487 on the i960. */
2488
2489 int
2490 i960_reg_parm_stack_space (fndecl)
2491 tree fndecl;
2492 {
2493 /* In this case, we are called from emit_library_call, and we don't need
2494 to pretend we have more space for parameters than what's apparent. */
2495 if (fndecl == 0)
2496 return 0;
2497
2498 /* In this case, we are called from locate_and_pad_parms when we're
2499 not IN_REGS, so we have an arg block. */
2500 if (fndecl != current_function_decl)
2501 return 48;
2502
2503 /* Otherwise, we have an arg block if the current function has more than
2504 48 bytes of parameters. */
2505 if (current_function_args_size != 0 || VARARGS_STDARG_FUNCTION (fndecl))
2506 return 48;
2507 else
2508 return 0;
2509 }
2510 \f
2511 /* Return the register class of a scratch register needed to copy IN into
2512 or out of a register in CLASS in MODE. If it can be done directly,
2513 NO_REGS is returned. */
2514
2515 enum reg_class
2516 secondary_reload_class (class, mode, in)
2517 enum reg_class class;
2518 enum machine_mode mode;
2519 rtx in;
2520 {
2521 int regno = -1;
2522
2523 if (GET_CODE (in) == REG || GET_CODE (in) == SUBREG)
2524 regno = true_regnum (in);
2525
2526 /* We can place anything into LOCAL_OR_GLOBAL_REGS and can put
2527 LOCAL_OR_GLOBAL_REGS into anything. */
2528 if (class == LOCAL_OR_GLOBAL_REGS || class == LOCAL_REGS
2529 || class == GLOBAL_REGS || (regno >= 0 && regno < 32))
2530 return NO_REGS;
2531
2532 /* We can place any hard register, 0.0, and 1.0 into FP_REGS. */
2533 if (class == FP_REGS
2534 && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
2535 || in == CONST0_RTX (mode) || in == CONST1_RTX (mode)))
2536 return NO_REGS;
2537
2538 return LOCAL_OR_GLOBAL_REGS;
2539 }
2540 \f
2541 /* Look at the opcode P, and set i96_last_insn_type to indicate which
2542 function unit it executed on. */
2543
2544 /* ??? This would make more sense as an attribute. */
2545
2546 void
2547 i960_scan_opcode (p)
2548 char *p;
2549 {
2550 switch (*p)
2551 {
2552 case 'a':
2553 case 'd':
2554 case 'e':
2555 case 'm':
2556 case 'n':
2557 case 'o':
2558 case 'r':
2559 /* Ret is not actually of type REG, but it won't matter, because no
2560 insn will ever follow it. */
2561 case 'u':
2562 case 'x':
2563 i960_last_insn_type = I_TYPE_REG;
2564 break;
2565
2566 case 'b':
2567 if (p[1] == 'x' || p[3] == 'x')
2568 i960_last_insn_type = I_TYPE_MEM;
2569 i960_last_insn_type = I_TYPE_CTRL;
2570 break;
2571
2572 case 'f':
2573 case 't':
2574 i960_last_insn_type = I_TYPE_CTRL;
2575 break;
2576
2577 case 'c':
2578 if (p[1] == 'a')
2579 {
2580 if (p[4] == 'x')
2581 i960_last_insn_type = I_TYPE_MEM;
2582 else
2583 i960_last_insn_type = I_TYPE_CTRL;
2584 }
2585 else if (p[1] == 'm')
2586 {
2587 if (p[3] == 'd')
2588 i960_last_insn_type = I_TYPE_REG;
2589 else if (p[4] == 'b' || p[4] == 'j')
2590 i960_last_insn_type = I_TYPE_CTRL;
2591 else
2592 i960_last_insn_type = I_TYPE_REG;
2593 }
2594 else
2595 i960_last_insn_type = I_TYPE_REG;
2596 break;
2597
2598 case 'l':
2599 i960_last_insn_type = I_TYPE_MEM;
2600 break;
2601
2602 case 's':
2603 if (p[1] == 't')
2604 i960_last_insn_type = I_TYPE_MEM;
2605 else
2606 i960_last_insn_type = I_TYPE_REG;
2607 break;
2608 }
2609 }