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