avr.c: Fix comment typos.
[gcc.git] / gcc / config / mn10200 / mn10200.c
1 /* Subroutines for insn-output.c for Matsushita MN10200 series
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "regs.h"
28 #include "hard-reg-set.h"
29 #include "real.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "output.h"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "recog.h"
36 #include "expr.h"
37 #include "function.h"
38 #include "obstack.h"
39 #include "ggc.h"
40 #include "toplev.h"
41 #include "tm_p.h"
42 #include "target.h"
43 #include "target-def.h"
44
45 /* Global registers known to hold the value zero.
46
47 Normally we'd depend on CSE and combine to put zero into a
48 register and re-use it.
49
50 However, on the mn10x00 processors we implicitly use the constant
51 zero in tst instructions, so we might be able to do better by
52 loading the value into a register in the prologue, then re-useing
53 that register throughout the function.
54
55 We could perform similar optimizations for other constants, but with
56 gcse due soon, it doesn't seem worth the effort.
57
58 These variables hold a rtx for a register known to hold the value
59 zero throughout the entire function, or NULL if no register of
60 the appropriate class has such a value throughout the life of the
61 function. */
62 rtx zero_dreg;
63 rtx zero_areg;
64
65 static void count_tst_insns PARAMS ((int *));
66
67 /* Note whether or not we need an out of line epilogue. */
68 static int out_of_line_epilogue;
69 \f
70 /* Initialize the GCC target structure. */
71 #undef TARGET_ASM_ALIGNED_HI_OP
72 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
73
74 struct gcc_target targetm = TARGET_INITIALIZER;
75 \f
76 /* Indicate this file was compiled by gcc and what optimization
77 level was used. */
78 void
79 asm_file_start (file)
80 FILE *file;
81 {
82 fprintf (file, "#\tGCC For the Matsushita MN10200\n");
83 if (optimize)
84 fprintf (file, "# -O%d\n", optimize);
85 else
86 fprintf (file, "\n\n");
87 output_file_directive (file, main_input_filename);
88 ggc_add_rtx_root (&zero_dreg, 1);
89 ggc_add_rtx_root (&zero_areg, 1);
90 }
91
92 /* Print operand X using operand code CODE to assembly language output file
93 FILE. */
94
95 void
96 print_operand (file, x, code)
97 FILE *file;
98 rtx x;
99 int code;
100 {
101 switch (code)
102 {
103 case 'b':
104 case 'B':
105 /* These are normal and reversed branches. */
106 switch (code == 'b' ? GET_CODE (x) : reverse_condition (GET_CODE (x)))
107 {
108 case NE:
109 fprintf (file, "ne");
110 break;
111 case EQ:
112 fprintf (file, "eq");
113 break;
114 case GE:
115 fprintf (file, "ge");
116 break;
117 case GT:
118 fprintf (file, "gt");
119 break;
120 case LE:
121 fprintf (file, "le");
122 break;
123 case LT:
124 fprintf (file, "lt");
125 break;
126 case GEU:
127 fprintf (file, "cc");
128 break;
129 case GTU:
130 fprintf (file, "hi");
131 break;
132 case LEU:
133 fprintf (file, "ls");
134 break;
135 case LTU:
136 fprintf (file, "cs");
137 break;
138 default:
139 abort ();
140 }
141 break;
142 case 'C':
143 /* This is used for the operand to a call instruction;
144 if it's a REG, enclose it in parens, else output
145 the operand normally. */
146 if (GET_CODE (x) == REG)
147 {
148 fputc ('(', file);
149 print_operand (file, x, 0);
150 fputc (')', file);
151 }
152 else
153 print_operand (file, x, 0);
154 break;
155
156 /* These are the least significant word in a 32bit value.
157 'o' allows us to sign extend a constant if doing so
158 makes for more compact code. */
159 case 'L':
160 case 'o':
161 switch (GET_CODE (x))
162 {
163 case MEM:
164 fputc ('(', file);
165 output_address (XEXP (x, 0));
166 fputc (')', file);
167 break;
168
169 case REG:
170 fprintf (file, "%s", reg_names[REGNO (x)]);
171 break;
172
173 case SUBREG:
174 fprintf (file, "%s", reg_names[subreg_regno (x)]);
175 break;
176
177 case CONST_DOUBLE:
178 if (code == 'L')
179 {
180 long val;
181 REAL_VALUE_TYPE rv;
182
183 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
184 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
185 print_operand_address (file, GEN_INT (val & 0xffff));
186 }
187 else
188 {
189 long val;
190 REAL_VALUE_TYPE rv;
191
192 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
193 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
194
195 val &= 0xffff;
196 val = (((val) & 0xffff) ^ (~0x7fff)) + 0x8000;
197 print_operand_address (file, GEN_INT (val));
198 }
199 break;
200
201 case CONST_INT:
202 if (code == 'L')
203 print_operand_address (file, GEN_INT ((INTVAL (x) & 0xffff)));
204 else
205 {
206 unsigned int val = INTVAL (x) & 0xffff;
207 val = (((val) & 0xffff) ^ (~0x7fff)) + 0x8000;
208 print_operand_address (file, GEN_INT (val));
209 }
210 break;
211 default:
212 abort ();
213 }
214 break;
215
216 /* Similarly, but for the most significant word. */
217 case 'H':
218 case 'h':
219 switch (GET_CODE (x))
220 {
221 case MEM:
222 fputc ('(', file);
223 x = adjust_address (x, HImode, 2);
224 output_address (XEXP (x, 0));
225 fputc (')', file);
226 break;
227
228 case REG:
229 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
230 break;
231
232 case SUBREG:
233 fprintf (file, "%s", reg_names[subreg_regno (x) + 1]);
234 break;
235
236 case CONST_DOUBLE:
237 if (code == 'H')
238 {
239 long val;
240 REAL_VALUE_TYPE rv;
241
242 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
243 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
244
245 print_operand_address (file, GEN_INT ((val >> 16) & 0xffff));
246 }
247 else
248 {
249 long val;
250 REAL_VALUE_TYPE rv;
251
252 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
253 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
254
255 val = (val >> 16) & 0xffff;
256 val = (((val) & 0xffff) ^ (~0x7fff)) + 0x8000;
257
258 print_operand_address (file, GEN_INT (val));
259 }
260 break;
261
262 case CONST_INT:
263 if (code == 'H')
264 print_operand_address (file,
265 GEN_INT ((INTVAL (x) >> 16) & 0xffff));
266 else
267 {
268 unsigned int val = (INTVAL (x) >> 16) & 0xffff;
269 val = (((val) & 0xffff) ^ (~0x7fff)) + 0x8000;
270
271 print_operand_address (file, GEN_INT (val));
272 }
273 break;
274 default:
275 abort ();
276 }
277 break;
278
279 /* Output ~CONST_INT. */
280 case 'N':
281 if (GET_CODE (x) != CONST_INT)
282 abort ();
283 fprintf (file, "%d", ~INTVAL (x));
284 break;
285
286 /* An address which can not be register indirect, if it is
287 register indirect, then turn it into reg + disp. */
288 case 'A':
289 if (GET_CODE (x) != MEM)
290 abort ();
291 if (GET_CODE (XEXP (x, 0)) == REG)
292 x = gen_rtx_PLUS (PSImode, XEXP (x, 0), GEN_INT (0));
293 else
294 x = XEXP (x, 0);
295 fputc ('(', file);
296 output_address (x);
297 fputc (')', file);
298 break;
299
300 case 'Z':
301 print_operand (file, XEXP (x, 1), 0);
302 break;
303
304 /* More cases where we can sign-extend a CONST_INT if it
305 results in more compact code. */
306 case 's':
307 case 'S':
308 if (GET_CODE (x) == CONST_INT)
309 {
310 int val = INTVAL (x);
311
312 if (code == 's')
313 x = GEN_INT (((val & 0xffff) ^ (~0x7fff)) + 0x8000);
314 else
315 x = GEN_INT (((val & 0xff) ^ (~0x7f)) + 0x80);
316 }
317 /* FALL THROUGH */
318 default:
319 switch (GET_CODE (x))
320 {
321 case MEM:
322 fputc ('(', file);
323 output_address (XEXP (x, 0));
324 fputc (')', file);
325 break;
326
327 case REG:
328 fprintf (file, "%s", reg_names[REGNO (x)]);
329 break;
330
331 case SUBREG:
332 fprintf (file, "%s", reg_names[subreg_regno (x)]);
333 break;
334
335 case CONST_INT:
336 case CONST_DOUBLE:
337 case SYMBOL_REF:
338 case CONST:
339 case LABEL_REF:
340 case CODE_LABEL:
341 print_operand_address (file, x);
342 break;
343 default:
344 abort ();
345 }
346 break;
347 }
348 }
349
350 /* Output assembly language output for the address ADDR to FILE. */
351
352 void
353 print_operand_address (file, addr)
354 FILE *file;
355 rtx addr;
356 {
357 switch (GET_CODE (addr))
358 {
359 case REG:
360 print_operand (file, addr, 0);
361 break;
362 case PLUS:
363 {
364 rtx base, index;
365 /* The base and index could be in any order, so we have
366 to figure out which is the base and which is the index.
367 Uses the same code as GO_IF_LEGITIMATE_ADDRESS. */
368 if (REG_P (XEXP (addr, 0))
369 && REG_OK_FOR_BASE_P (XEXP (addr, 0)))
370 base = XEXP (addr, 0), index = XEXP (addr, 1);
371 else if (REG_P (XEXP (addr, 1))
372 && REG_OK_FOR_BASE_P (XEXP (addr, 1)))
373 base = XEXP (addr, 1), index = XEXP (addr, 0);
374 else
375 abort ();
376 print_operand (file, index, 0);
377 fputc (',', file);
378 print_operand (file, base, 0);;
379 break;
380 }
381 case SYMBOL_REF:
382 output_addr_const (file, addr);
383 break;
384 default:
385 output_addr_const (file, addr);
386 break;
387 }
388 }
389
390 /* Count the number of tst insns which compare an address register
391 with zero. */
392 static void
393 count_tst_insns (areg_countp)
394 int *areg_countp;
395 {
396 rtx insn;
397
398 /* Assume no tst insns exist. */
399 *areg_countp = 0;
400
401 /* If not optimizing, then quit now. */
402 if (!optimize)
403 return;
404
405 /* Walk through all the insns. */
406 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
407 {
408 rtx pat;
409
410 /* Ignore anything that is not a normal INSN. */
411 if (GET_CODE (insn) != INSN)
412 continue;
413
414 /* Ignore anything that isn't a SET. */
415 pat = PATTERN (insn);
416 if (GET_CODE (pat) != SET)
417 continue;
418
419 /* Check for a tst insn. */
420 if (SET_DEST (pat) == cc0_rtx
421 && GET_CODE (SET_SRC (pat)) == REG
422 && REGNO_REG_CLASS (REGNO (SET_SRC (pat))) == ADDRESS_REGS)
423 (*areg_countp)++;
424 }
425 }
426
427 /* Return the total size (in bytes) of the current function's frame.
428 This is the size of the register save area + the size of locals,
429 spills, etc. */
430 int
431 total_frame_size ()
432 {
433 unsigned int size = get_frame_size ();
434 unsigned int outgoing_args_size = current_function_outgoing_args_size;
435 int i;
436
437 /* First figure out if we're going to use an out of line
438 prologue, if so we have to make space for all the
439 registers, even if we don't use them. */
440 if (optimize && !current_function_needs_context && !frame_pointer_needed)
441 {
442 int inline_count, outline_count;
443
444 /* Compute how many bytes an inline prologue would take.
445
446 Each address register store takes two bytes, each data register
447 store takes three bytes. */
448 inline_count = 0;
449 if (regs_ever_live[5])
450 inline_count += 2;
451 if (regs_ever_live[6])
452 inline_count += 2;
453 if (regs_ever_live[2])
454 inline_count += 3;
455 if (regs_ever_live[3])
456 inline_count += 3;
457
458 /* If this function has any stack, then the stack adjustment
459 will take two (or more) bytes. */
460 if (size || outgoing_args_size
461 || regs_ever_live[5] || regs_ever_live[6]
462 || regs_ever_live[2] || regs_ever_live[3])
463 inline_count += 2;
464
465 /* Multiply the current count by two and add one to account for the
466 epilogue insns. */
467 inline_count = inline_count * 2 + 1;
468
469 /* Now compute how many bytes an out of line sequence would take. */
470 /* A relaxed jsr will be three bytes. */
471 outline_count = 3;
472
473 /* If there are outgoing arguments, then we will need a stack
474 pointer adjustment after the call to the prologue, two
475 more bytes. */
476 outline_count += (outgoing_args_size == 0 ? 0 : 2);
477
478 /* If there is some local frame to allocate, it will need to be
479 done before the call to the prologue, two more bytes. */
480 if (get_frame_size () != 0)
481 outline_count += 2;
482
483 /* Now account for the epilogue, multiply the base count by two,
484 then deal with optimizing away the rts instruction. */
485 outline_count = outline_count * 2 + 1;
486
487 if (get_frame_size () == 0 && outgoing_args_size == 0)
488 outline_count -= 1;
489
490 /* If an out of line prologue is smaller, use it. */
491 if (inline_count > outline_count)
492 return size + outgoing_args_size + 16;
493 }
494
495
496 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
497 {
498 if ((regs_ever_live[i] && !call_used_regs[i] && ! fixed_regs[i])
499 || (i == FRAME_POINTER_REGNUM && frame_pointer_needed))
500 size += 4;
501 }
502
503 return (size + outgoing_args_size);
504 }
505
506 /* Expand the prologue into RTL. */
507 void
508 expand_prologue ()
509 {
510 unsigned int size = total_frame_size ();
511 unsigned int outgoing_args_size = current_function_outgoing_args_size;
512 int offset, i;
513
514 zero_areg = NULL_RTX;
515 zero_dreg = NULL_RTX;
516
517 /* If optimizing, see if we should do an out of line prologue/epilogue
518 sequence.
519
520 We don't support out of line prologues if the current function
521 needs a context or frame pointer. */
522 if (optimize && !current_function_needs_context && !frame_pointer_needed)
523 {
524 int inline_count, outline_count, areg_count;
525
526 /* We need to end the current sequence so that count_tst_insns can
527 look at all the insns in this function. Normally this would be
528 unsafe, but it's OK in the prologue/epilogue expanders. */
529 end_sequence ();
530
531 /* Get a count of the number of tst insns which use address
532 registers (it's not profitable to try and improve tst insns
533 which use data registers). */
534 count_tst_insns (&areg_count);
535
536 /* Now start a new sequence. */
537 start_sequence ();
538
539 /* Compute how many bytes an inline prologue would take.
540
541 Each address register store takes two bytes, each data register
542 store takes three bytes. */
543 inline_count = 0;
544 if (regs_ever_live[5])
545 inline_count += 2;
546 if (regs_ever_live[6])
547 inline_count += 2;
548 if (regs_ever_live[2])
549 inline_count += 3;
550 if (regs_ever_live[3])
551 inline_count += 3;
552
553 /* If this function has any stack, then the stack adjustment
554 will take two (or more) bytes. */
555 if (size || outgoing_args_size
556 || regs_ever_live[5] || regs_ever_live[6]
557 || regs_ever_live[2] || regs_ever_live[3])
558 inline_count += 2;
559
560 /* Multiply the current count by two and add one to account for the
561 epilogue insns. */
562 inline_count = inline_count * 2 + 1;
563
564 /* Now compute how many bytes an out of line sequence would take. */
565 /* A relaxed jsr will be three bytes. */
566 outline_count = 3;
567
568 /* If there are outgoing arguments, then we will need a stack
569 pointer adjustment after the call to the prologue, two
570 more bytes. */
571 outline_count += (outgoing_args_size == 0 ? 0 : 2);
572
573 /* If there is some local frame to allocate, it will need to be
574 done before the call to the prologue, two more bytes. */
575 if (get_frame_size () != 0)
576 outline_count += 2;
577
578 /* Now account for the epilogue, multiply the base count by two,
579 then deal with optimizing away the rts instruction. */
580 outline_count = outline_count * 2 + 1;
581
582 if (get_frame_size () == 0 && outgoing_args_size == 0)
583 outline_count -= 1;
584
585 /* If an out of line prologue is smaller, use it. */
586 if (inline_count > outline_count)
587 {
588 if (get_frame_size () != 0)
589 emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx,
590 GEN_INT (-size + outgoing_args_size + 16)));
591 emit_insn (gen_outline_prologue_call ());
592
593 if (outgoing_args_size)
594 emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx,
595 GEN_INT (-outgoing_args_size)));
596
597 out_of_line_epilogue = 1;
598
599 /* Determine if it is profitable to put the value zero into a register
600 for the entire function. If so, set ZERO_DREG and ZERO_AREG. */
601
602 /* First see if we could load the value into a data register
603 since that's the most efficient way. */
604 if (areg_count > 1
605 && (!regs_ever_live[2] || !regs_ever_live[3]))
606 {
607 if (!regs_ever_live[2])
608 {
609 regs_ever_live[2] = 1;
610 zero_dreg = gen_rtx_REG (HImode, 2);
611 }
612 if (!regs_ever_live[3])
613 {
614 regs_ever_live[3] = 1;
615 zero_dreg = gen_rtx_REG (HImode, 3);
616 }
617 }
618
619 /* Now see if we could load the value into an address register. */
620 if (zero_dreg == NULL_RTX
621 && areg_count > 2
622 && (!regs_ever_live[5] || !regs_ever_live[6]))
623 {
624 if (!regs_ever_live[5])
625 {
626 regs_ever_live[5] = 1;
627 zero_areg = gen_rtx_REG (HImode, 5);
628 }
629 if (!regs_ever_live[6])
630 {
631 regs_ever_live[6] = 1;
632 zero_areg = gen_rtx_REG (HImode, 6);
633 }
634 }
635
636 if (zero_dreg)
637 emit_move_insn (zero_dreg, const0_rtx);
638
639 if (zero_areg)
640 emit_move_insn (zero_areg, const0_rtx);
641
642 return;
643 }
644 }
645
646 out_of_line_epilogue = 0;
647
648 /* Temporarily stuff the static chain onto the stack so we can
649 use a0 as a scratch register during the prologue. */
650 if (current_function_needs_context)
651 {
652 emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx,
653 GEN_INT (-4)));
654 emit_move_insn (gen_rtx_MEM (PSImode, stack_pointer_rtx),
655 gen_rtx_REG (PSImode, STATIC_CHAIN_REGNUM));
656 }
657
658 if (frame_pointer_needed)
659 {
660 /* Store a2 into a0 temporarily. */
661 emit_move_insn (gen_rtx_REG (PSImode, 4), frame_pointer_rtx);
662
663 /* Set up the frame pointer. */
664 emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
665 }
666
667 /* Make any necessary space for the saved registers and local frame. */
668 if (size)
669 emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx,
670 GEN_INT (-size)));
671
672 /* Save the callee saved registers. They're saved into the top
673 of the frame, using the stack pointer. */
674 for (i = 0, offset = outgoing_args_size;
675 i < FIRST_PSEUDO_REGISTER; i++)
676 {
677 if ((regs_ever_live[i] && !call_used_regs[i] && ! fixed_regs[i])
678 || (i == FRAME_POINTER_REGNUM && frame_pointer_needed))
679 {
680 int regno;
681
682 /* If we're saving the frame pointer, then it will be found in
683 register 4 (a0). */
684 regno = (i == FRAME_POINTER_REGNUM && frame_pointer_needed) ? 4 : i;
685
686 emit_move_insn (gen_rtx_MEM (PSImode,
687 plus_constant (stack_pointer_rtx,
688 offset)),
689 gen_rtx_REG (PSImode, regno));
690 offset += 4;
691 }
692 }
693
694 /* Now put the static chain back where the rest of the function
695 expects to find it. */
696 if (current_function_needs_context)
697 {
698 emit_move_insn (gen_rtx_REG (PSImode, STATIC_CHAIN_REGNUM),
699 gen_rtx (MEM, PSImode,
700 gen_rtx_PLUS (PSImode, stack_pointer_rtx,
701 GEN_INT (size))));
702 }
703 }
704
705 /* Expand the epilogue into RTL. */
706 void
707 expand_epilogue ()
708 {
709 unsigned int size;
710 unsigned int outgoing_args_size = current_function_outgoing_args_size;
711 int offset, i, temp_regno;
712 rtx basereg;
713
714 size = total_frame_size ();
715
716 if (DECL_RESULT (current_function_decl)
717 && DECL_RTL (DECL_RESULT (current_function_decl))
718 && REG_P (DECL_RTL (DECL_RESULT (current_function_decl))))
719 temp_regno = (REGNO (DECL_RTL (DECL_RESULT (current_function_decl))) == 4
720 ? 0 : 4);
721 else
722 temp_regno = 4;
723
724 /* Emit an out of line epilogue sequence if it's profitable to do so. */
725 if (out_of_line_epilogue)
726 {
727 /* If there were no outgoing arguments and no local frame, then
728 we will be able to omit the rts at the end of this function,
729 so just jump to the epilogue_noreturn routine. */
730 if (get_frame_size () == 0 && outgoing_args_size == 0)
731 {
732 emit_jump_insn (gen_outline_epilogue_jump ());
733 return;
734 }
735
736 if (outgoing_args_size)
737 emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx,
738 GEN_INT (outgoing_args_size)));
739
740 if (temp_regno == 0)
741 emit_insn (gen_outline_epilogue_call_d0 ());
742 else if (temp_regno == 4)
743 emit_insn (gen_outline_epilogue_call_a0 ());
744
745 if (get_frame_size () != 0)
746 emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx,
747 GEN_INT (size - outgoing_args_size - 16)));
748 emit_jump_insn (gen_return_internal ());
749 return;
750 }
751
752 /* Registers are restored from the frame pointer if we have one,
753 else they're restored from the stack pointer. Figure out
754 the appropriate offset to the register save area for both cases. */
755 if (frame_pointer_needed)
756 {
757 basereg = frame_pointer_rtx;
758 offset = -(size - outgoing_args_size);
759 }
760 else
761 {
762 basereg = stack_pointer_rtx;
763 offset = outgoing_args_size;
764 }
765
766 /* Restore each register. */
767 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
768 {
769 if ((regs_ever_live[i] && !call_used_regs[i] && ! fixed_regs[i])
770 || (i == FRAME_POINTER_REGNUM && frame_pointer_needed))
771 {
772 int regno;
773
774 /* Restore the frame pointer (if it exists) into a temporary
775 register. */
776 regno = ((i == FRAME_POINTER_REGNUM && frame_pointer_needed)
777 ? temp_regno : i);
778
779 emit_move_insn (gen_rtx_REG (PSImode, regno),
780 gen_rtx_MEM (PSImode,
781 plus_constant (basereg, offset)));
782 offset += 4;
783 }
784 }
785
786 if (frame_pointer_needed)
787 {
788 /* Deallocate this frame's stack. */
789 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
790 /* Restore the old frame pointer. */
791 emit_move_insn (frame_pointer_rtx, gen_rtx_REG (PSImode, temp_regno));
792 }
793 else if (size)
794 {
795 /* Deallocate this function's stack. */
796 emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx,
797 GEN_INT (size)));
798 }
799
800 /* If we had to allocate a slot to save the context pointer,
801 then it must be deallocated here. */
802 if (current_function_needs_context)
803 emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (4)));
804
805 /* Emit the return insn, if this function had no stack, then we
806 can use the standard return (which allows more optimizations),
807 else we have to use the special one which inhibits optimizations. */
808 if (size == 0 && !current_function_needs_context)
809 emit_jump_insn (gen_return ());
810 else
811 emit_jump_insn (gen_return_internal ());
812 }
813
814 /* Update the condition code from the insn. */
815
816 void
817 notice_update_cc (body, insn)
818 rtx body;
819 rtx insn;
820 {
821 switch (get_attr_cc (insn))
822 {
823 case CC_NONE:
824 /* Insn does not affect CC at all. */
825 break;
826
827 case CC_NONE_0HIT:
828 /* Insn does not change CC, but the 0'th operand has been changed. */
829 if (cc_status.value1 != 0
830 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
831 cc_status.value1 = 0;
832 break;
833
834 case CC_SET_ZN:
835 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
836 V,C is in an unusable state. */
837 CC_STATUS_INIT;
838 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
839 cc_status.value1 = recog_data.operand[0];
840 break;
841
842 case CC_SET_ZNV:
843 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
844 C is in an unusable state. */
845 CC_STATUS_INIT;
846 cc_status.flags |= CC_NO_CARRY;
847 cc_status.value1 = recog_data.operand[0];
848 break;
849
850 case CC_COMPARE:
851 /* The insn is a compare instruction. */
852 CC_STATUS_INIT;
853 cc_status.value1 = SET_SRC (body);
854 break;
855
856 case CC_CLOBBER:
857 /* Insn doesn't leave CC in a usable state. */
858 CC_STATUS_INIT;
859 break;
860
861 default:
862 CC_STATUS_INIT;
863 break;
864 }
865 }
866
867 /* Return true if OP is a valid call operand. Valid call operands
868 are SYMBOL_REFs and REGs. */
869 int
870 call_address_operand (op, mode)
871 rtx op;
872 enum machine_mode mode ATTRIBUTE_UNUSED;
873 {
874 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
875 }
876
877 /* Return true if OP is a memory operand with a constant address.
878 A special PSImode move pattern uses this predicate. */
879 int
880 constant_memory_operand (op, mode)
881 rtx op;
882 enum machine_mode mode ATTRIBUTE_UNUSED;
883 {
884 return GET_CODE (op) == MEM && CONSTANT_ADDRESS_P (XEXP (op, 0));
885 }
886
887 /* Return true if OP is valid for a psi mode truncation operand.
888 It must either be a memory operand which is valid for a PSImode
889 address, or if it is not a memory operand at all. */
890 int
891 psimode_truncation_operand (op, mode)
892 rtx op;
893 enum machine_mode mode;
894 {
895 return (general_operand (op, mode)
896 && (GET_CODE (op) != MEM
897 || memory_address_p (PSImode, XEXP (op, 0))));
898 }
899
900 /* What (if any) secondary registers are needed to move IN with mode
901 MODE into a register from in register class CLASS.
902
903 We might be able to simplify this. */
904 enum reg_class
905 secondary_reload_class (class, mode, in, input)
906 enum reg_class class;
907 enum machine_mode mode;
908 rtx in;
909 int input;
910 {
911 /* Memory loads less than a full word wide can't have an
912 address or stack pointer destination. They must use
913 a data register as an intermediate register. */
914 if (input
915 && GET_CODE (in) == MEM
916 && (mode == QImode)
917 && class == ADDRESS_REGS)
918 return DATA_REGS;
919
920 /* Address register stores which are not PSImode need a scratch register. */
921 if (! input
922 && GET_CODE (in) == MEM
923 && (mode != PSImode)
924 && class == ADDRESS_REGS)
925 return DATA_REGS;
926
927 /* Otherwise assume no secondary reloads are needed. */
928 return NO_REGS;
929 }
930
931 \f
932 /* Shifts.
933
934 We devote a fair bit of code to getting efficient shifts since we can only
935 shift one bit at a time, and each single bit shift may take multiple
936 instructions.
937
938 The basic shift methods:
939
940 * loop shifts -- emit a loop using one (or two on H8/S) bit shifts;
941 this is the default. SHIFT_LOOP
942
943 * inlined shifts -- emit straight line code for the shift; this is
944 used when a straight line shift is about the same size or smaller
945 than a loop. We allow the inline version to be slightly longer in
946 some cases as it saves a register. SHIFT_INLINE
947
948 * There other oddballs. Not worth explaining. SHIFT_SPECIAL
949
950
951 HImode shifts:
952
953 1-4 do them inline
954
955 5-7 If ashift, then multiply, else loop.
956
957 8-14 - If ashift, then multiply, if lshiftrt, then divide, else loop.
958 15 - rotate the bit we want into the carry, clear the destination,
959 (use mov 0,dst, not sub as sub will clobber the carry), then
960 move bit into place.
961
962 Don't Panic, it's not nearly as bad as the H8 shifting code!!! */
963
964 int
965 nshift_operator (x, mode)
966 rtx x;
967 enum machine_mode mode ATTRIBUTE_UNUSED;
968 {
969 switch (GET_CODE (x))
970 {
971 case ASHIFTRT:
972 case LSHIFTRT:
973 case ASHIFT:
974 return 1;
975
976 default:
977 return 0;
978 }
979 }
980
981 /* Called from the .md file to emit code to do shifts.
982 Returns a boolean indicating success
983 (currently this is always TRUE). */
984
985 int
986 expand_a_shift (mode, code, operands)
987 enum machine_mode mode;
988 int code;
989 rtx operands[];
990 {
991 emit_move_insn (operands[0], operands[1]);
992
993 /* need a loop to get all the bits we want - we generate the
994 code at emit time, but need to allocate a scratch reg now */
995
996 emit_insn (gen_rtx_PARALLEL
997 (VOIDmode,
998 gen_rtvec (2,
999 gen_rtx_SET (VOIDmode, operands[0],
1000 gen_rtx (code, mode,
1001 operands[0], operands[2])),
1002 gen_rtx_CLOBBER (VOIDmode,
1003 gen_rtx_SCRATCH (HImode)))));
1004
1005 return 1;
1006 }
1007
1008 /* Shift algorithm determination.
1009
1010 There are various ways of doing a shift:
1011 SHIFT_INLINE: If the amount is small enough, just generate as many one-bit
1012 shifts as we need.
1013 SHIFT_SPECIAL: Hand crafted assembler.
1014 SHIFT_LOOP: If the above methods fail, just loop. */
1015
1016 enum shift_alg
1017 {
1018 SHIFT_INLINE,
1019 SHIFT_SPECIAL,
1020 SHIFT_LOOP,
1021 SHIFT_MAX
1022 };
1023
1024 /* Symbols of the various shifts which can be used as indices. */
1025
1026 enum shift_type
1027 {
1028 SHIFT_ASHIFT, SHIFT_LSHIFTRT, SHIFT_ASHIFTRT
1029 };
1030
1031 /* Symbols of the various modes which can be used as indices. */
1032
1033 enum shift_mode
1034 {
1035 HIshift
1036 };
1037
1038 /* For single bit shift insns, record assembler and what bits of the
1039 condition code are valid afterwards (represented as various CC_FOO
1040 bits, 0 means CC isn't left in a usable state). */
1041
1042 struct shift_insn
1043 {
1044 const char *assembler;
1045 int cc_valid;
1046 };
1047
1048 /* Assembler instruction shift table.
1049
1050 These tables are used to look up the basic shifts.
1051 They are indexed by cpu, shift_type, and mode.
1052 */
1053
1054 static const struct shift_insn shift_one[3][3] =
1055 {
1056 {
1057 /* SHIFT_ASHIFT */
1058 { "add\t%0,%0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY },
1059 },
1060 /* SHIFT_LSHIFTRT */
1061 {
1062 { "lsr\t%0", CC_NO_CARRY },
1063 },
1064 /* SHIFT_ASHIFTRT */
1065 {
1066 { "asr\t%0", CC_NO_CARRY },
1067 },
1068 };
1069
1070 static enum shift_alg get_shift_alg PARAMS ((enum shift_type,
1071 enum machine_mode, int,
1072 const char **, int *));
1073
1074 /* Given CPU, MODE, SHIFT_TYPE, and shift count COUNT, determine the best
1075 algorithm for doing the shift. The assembler code is stored in ASSEMBLER.
1076 We don't achieve maximum efficiency in all cases, but the hooks are here
1077 to do so.
1078
1079 For now we just use lots of switch statements. Since we don't even come
1080 close to supporting all the cases, this is simplest. If this function ever
1081 gets too big, perhaps resort to a more table based lookup. Of course,
1082 at this point you may just wish to do it all in rtl. */
1083
1084 static enum shift_alg
1085 get_shift_alg (shift_type, mode, count, assembler_p, cc_valid_p)
1086 enum shift_type shift_type;
1087 enum machine_mode mode;
1088 int count;
1089 const char **assembler_p;
1090 int *cc_valid_p;
1091 {
1092 /* The default is to loop. */
1093 enum shift_alg alg = SHIFT_LOOP;
1094 enum shift_mode shift_mode;
1095
1096 /* We don't handle negative shifts or shifts greater than the word size,
1097 they should have been handled already. */
1098
1099 if (count < 0 || count > GET_MODE_BITSIZE (mode))
1100 abort ();
1101
1102 switch (mode)
1103 {
1104 case HImode:
1105 shift_mode = HIshift;
1106 break;
1107 default:
1108 abort ();
1109 }
1110
1111 /* Assume either SHIFT_LOOP or SHIFT_INLINE.
1112 It is up to the caller to know that looping clobbers cc. */
1113 *assembler_p = shift_one[shift_type][shift_mode].assembler;
1114 *cc_valid_p = shift_one[shift_type][shift_mode].cc_valid;
1115
1116 /* Now look for cases we want to optimize. */
1117
1118 switch (shift_mode)
1119 {
1120 case HIshift:
1121 if (count <= 4)
1122 return SHIFT_INLINE;
1123 else if (count < 15 && shift_type != SHIFT_ASHIFTRT)
1124 {
1125 switch (count)
1126 {
1127 case 5:
1128 if (shift_type == SHIFT_ASHIFT)
1129 *assembler_p = "mov 32,%4\n\tmul %4,%0";
1130 else if (shift_type == SHIFT_LSHIFTRT)
1131 *assembler_p
1132 = "sub %4,%4\n\tmov %4,mdr\n\tmov 32,%4\n\tdivu %4,%0";
1133 *cc_valid_p = CC_NO_CARRY;
1134 return SHIFT_SPECIAL;
1135 case 6:
1136 if (shift_type == SHIFT_ASHIFT)
1137 *assembler_p = "mov 64,%4\n\tmul %4,%0";
1138 else if (shift_type == SHIFT_LSHIFTRT)
1139 *assembler_p
1140 = "sub %4,%4\n\tmov %4,mdr\n\tmov 64,%4\n\tdivu %4,%0";
1141 *cc_valid_p = CC_NO_CARRY;
1142 return SHIFT_SPECIAL;
1143 case 7:
1144 if (shift_type == SHIFT_ASHIFT)
1145 *assembler_p = "mov 128,%4\n\tmul %4,%0";
1146 else if (shift_type == SHIFT_LSHIFTRT)
1147 *assembler_p
1148 = "sub %4,%4\n\tmov %4,mdr\n\tmov 128,%4\n\tdivu %4,%0";
1149 *cc_valid_p = CC_NO_CARRY;
1150 return SHIFT_SPECIAL;
1151 case 8:
1152 if (shift_type == SHIFT_ASHIFT)
1153 *assembler_p = "mov 256,%4\n\tmul %4,%0";
1154 else if (shift_type == SHIFT_LSHIFTRT)
1155 *assembler_p
1156 = "sub %4,%4\n\tmov %4,mdr\n\tmov 256,%4\n\tdivu %4,%0";
1157 *cc_valid_p = CC_NO_CARRY;
1158 return SHIFT_SPECIAL;
1159 case 9:
1160 if (shift_type == SHIFT_ASHIFT)
1161 *assembler_p = "mov 512,%4\n\tmul %4,%0";
1162 else if (shift_type == SHIFT_LSHIFTRT)
1163 *assembler_p
1164 = "sub %4,%4\n\tmov %4,mdr\n\tmov 512,%4\n\tdivu %4,%0";
1165 *cc_valid_p = CC_NO_CARRY;
1166 return SHIFT_SPECIAL;
1167 case 10:
1168 if (shift_type == SHIFT_ASHIFT)
1169 *assembler_p = "mov 1024,%4\n\tmul %4,%0";
1170 else if (shift_type == SHIFT_LSHIFTRT)
1171 *assembler_p
1172 = "sub %4,%4\n\tmov %4,mdr\n\tmov 1024,%4\n\tdivu %4,%0";
1173 *cc_valid_p = CC_NO_CARRY;
1174 return SHIFT_SPECIAL;
1175 case 11:
1176 if (shift_type == SHIFT_ASHIFT)
1177 *assembler_p = "mov 2048,%4\n\tmul %4,%0";
1178 else if (shift_type == SHIFT_LSHIFTRT)
1179 *assembler_p
1180 = "sub %4,%4\n\tmov %4,mdr\n\tmov 2048,%4\n\tdivu %4,%0";
1181 *cc_valid_p = CC_NO_CARRY;
1182 return SHIFT_SPECIAL;
1183 case 12:
1184 if (shift_type == SHIFT_ASHIFT)
1185 *assembler_p = "mov 4096,%4\n\tmul %4,%0";
1186 else if (shift_type == SHIFT_LSHIFTRT)
1187 *assembler_p
1188 = "sub %4,%4\n\tmov %4,mdr\n\tmov 4096,%4\n\tdivu %4,%0";
1189 *cc_valid_p = CC_NO_CARRY;
1190 return SHIFT_SPECIAL;
1191 case 13:
1192 if (shift_type == SHIFT_ASHIFT)
1193 *assembler_p = "mov 8192,%4\n\tmul %4,%0";
1194 else if (shift_type == SHIFT_LSHIFTRT)
1195 *assembler_p
1196 = "sub %4,%4\n\tmov %4,mdr\n\tmov 8192,%4\n\tdivu %4,%0";
1197 *cc_valid_p = CC_NO_CARRY;
1198 return SHIFT_SPECIAL;
1199 case 14:
1200 if (shift_type == SHIFT_ASHIFT)
1201 *assembler_p = "mov 16384,%4\n\tmul %4,%0";
1202 else if (shift_type == SHIFT_LSHIFTRT)
1203 *assembler_p
1204 = "sub %4,%4\n\tmov %4,mdr\n\tmov 16384,%4\n\tdivu %4,%0";
1205 *cc_valid_p = CC_NO_CARRY;
1206 return SHIFT_SPECIAL;
1207 }
1208 }
1209 else if (count == 15)
1210 {
1211 if (shift_type == SHIFT_ASHIFTRT)
1212 {
1213 *assembler_p = "add\t%0,%0\n\tsubc\t%0,%0\n";
1214 *cc_valid_p = CC_NO_CARRY;
1215 return SHIFT_SPECIAL;
1216 }
1217 if (shift_type == SHIFT_LSHIFTRT)
1218 {
1219 *assembler_p = "add\t%0,%0\n\tmov 0,%0\n\trol %0\n";
1220 *cc_valid_p = CC_NO_CARRY;
1221 return SHIFT_SPECIAL;
1222 }
1223 if (shift_type == SHIFT_ASHIFT)
1224 {
1225 *assembler_p = "ror\t%0\n\tmov 0,%0\n\tror %0\n";
1226 *cc_valid_p = CC_NO_CARRY;
1227 return SHIFT_SPECIAL;
1228 }
1229 }
1230 break;
1231
1232 default:
1233 abort ();
1234 }
1235
1236 return alg;
1237 }
1238
1239 /* Emit the assembler code for doing shifts. */
1240
1241 const char *
1242 emit_a_shift (insn, operands)
1243 rtx insn ATTRIBUTE_UNUSED;
1244 rtx *operands;
1245 {
1246 static int loopend_lab;
1247 const char *assembler;
1248 int cc_valid;
1249 rtx shift = operands[3];
1250 enum machine_mode mode = GET_MODE (shift);
1251 enum rtx_code code = GET_CODE (shift);
1252 enum shift_type shift_type;
1253 enum shift_mode shift_mode;
1254
1255 loopend_lab++;
1256
1257 switch (mode)
1258 {
1259 case HImode:
1260 shift_mode = HIshift;
1261 break;
1262 default:
1263 abort ();
1264 }
1265
1266 switch (code)
1267 {
1268 case ASHIFTRT:
1269 shift_type = SHIFT_ASHIFTRT;
1270 break;
1271 case LSHIFTRT:
1272 shift_type = SHIFT_LSHIFTRT;
1273 break;
1274 case ASHIFT:
1275 shift_type = SHIFT_ASHIFT;
1276 break;
1277 default:
1278 abort ();
1279 }
1280
1281 if (GET_CODE (operands[2]) != CONST_INT)
1282 {
1283 /* Indexing by reg, so have to loop and test at top */
1284 output_asm_insn ("mov %2,%4", operands);
1285 output_asm_insn ("cmp 0,%4", operands);
1286 fprintf (asm_out_file, "\tble .Lle%d\n", loopend_lab);
1287
1288 /* Get the assembler code to do one shift. */
1289 get_shift_alg (shift_type, mode, 1, &assembler, &cc_valid);
1290 }
1291 else
1292 {
1293 int n = INTVAL (operands[2]);
1294 enum shift_alg alg;
1295
1296 /* If the count is negative, make it 0. */
1297 if (n < 0)
1298 n = 0;
1299 /* If the count is too big, truncate it.
1300 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
1301 do the intuitive thing. */
1302 else if (n > GET_MODE_BITSIZE (mode))
1303 n = GET_MODE_BITSIZE (mode);
1304
1305 alg = get_shift_alg (shift_type, mode, n, &assembler, &cc_valid);
1306
1307
1308 switch (alg)
1309 {
1310 case SHIFT_INLINE:
1311 /* Emit one bit shifts. */
1312 while (n > 0)
1313 {
1314 output_asm_insn (assembler, operands);
1315 n -= 1;
1316 }
1317
1318 /* Keep track of CC. */
1319 if (cc_valid)
1320 {
1321 cc_status.value1 = operands[0];
1322 cc_status.flags |= cc_valid;
1323 }
1324 return "";
1325
1326 case SHIFT_SPECIAL:
1327 output_asm_insn (assembler, operands);
1328
1329 /* Keep track of CC. */
1330 if (cc_valid)
1331 {
1332 cc_status.value1 = operands[0];
1333 cc_status.flags |= cc_valid;
1334 }
1335 return "";
1336 }
1337
1338 {
1339 fprintf (asm_out_file, "\tmov %d,%s\n", n,
1340 reg_names[REGNO (operands[4])]);
1341 fprintf (asm_out_file, ".Llt%d:\n", loopend_lab);
1342 output_asm_insn (assembler, operands);
1343 output_asm_insn ("add -1,%4", operands);
1344 fprintf (asm_out_file, "\tbne .Llt%d\n", loopend_lab);
1345 return "";
1346 }
1347 }
1348
1349 fprintf (asm_out_file, ".Llt%d:\n", loopend_lab);
1350 output_asm_insn (assembler, operands);
1351 output_asm_insn ("add -1,%4", operands);
1352 fprintf (asm_out_file, "\tbne .Llt%d\n", loopend_lab);
1353 fprintf (asm_out_file, ".Lle%d:\n", loopend_lab);
1354
1355 return "";
1356 }
1357
1358 /* Return an RTX to represent where a value with mode MODE will be returned
1359 from a function. If the result is 0, the argument is pushed. */
1360
1361 rtx
1362 function_arg (cum, mode, type, named)
1363 CUMULATIVE_ARGS *cum;
1364 enum machine_mode mode;
1365 tree type;
1366 int named;
1367 {
1368 rtx result = 0;
1369 int size, align;
1370
1371 /* We only support using 2 data registers as argument registers. */
1372 int nregs = 2;
1373
1374 /* Only pass named arguments in registers. */
1375 if (!named)
1376 return NULL_RTX;
1377
1378 /* Figure out the size of the object to be passed. We lie and claim
1379 PSImode values are only two bytes since they fit in a single
1380 register. */
1381 if (mode == BLKmode)
1382 size = int_size_in_bytes (type);
1383 else if (mode == PSImode)
1384 size = 2;
1385 else
1386 size = GET_MODE_SIZE (mode);
1387
1388 /* Figure out the alignment of the object to be passed. */
1389 align = size;
1390
1391 cum->nbytes = (cum->nbytes + 1) & ~1;
1392
1393 /* Don't pass this arg via a register if all the argument registers
1394 are used up. */
1395 if (cum->nbytes + size > nregs * UNITS_PER_WORD)
1396 return 0;
1397
1398 switch (cum->nbytes / UNITS_PER_WORD)
1399 {
1400 case 0:
1401 result = gen_rtx_REG (mode, 0);
1402 break;
1403 case 1:
1404 result = gen_rtx_REG (mode, 1);
1405 break;
1406 default:
1407 result = 0;
1408 }
1409
1410 return result;
1411 }
1412
1413 /* Return the number of registers to use for an argument passed partially
1414 in registers and partially in memory. */
1415
1416 int
1417 function_arg_partial_nregs (cum, mode, type, named)
1418 CUMULATIVE_ARGS *cum;
1419 enum machine_mode mode;
1420 tree type;
1421 int named;
1422 {
1423 int size, align;
1424
1425 /* We only support using 2 data registers as argument registers. */
1426 int nregs = 2;
1427
1428 return 0;
1429 /* Only pass named arguments in registers. */
1430 if (!named)
1431 return 0;
1432
1433 /* Figure out the size of the object to be passed. */
1434 if (mode == BLKmode)
1435 size = int_size_in_bytes (type);
1436 else if (mode == PSImode)
1437 size = 2;
1438 else
1439 size = GET_MODE_SIZE (mode);
1440
1441 /* Figure out the alignment of the object to be passed. */
1442 align = size;
1443
1444 cum->nbytes = (cum->nbytes + 1) & ~1;
1445
1446 /* Don't pass this arg via a register if all the argument registers
1447 are used up. */
1448 if (cum->nbytes > nregs * UNITS_PER_WORD)
1449 return 0;
1450
1451 if (cum->nbytes + size <= nregs * UNITS_PER_WORD)
1452 return 0;
1453
1454 /* Don't pass this arg via a register if it would be split between
1455 registers and memory. */
1456 if (type == NULL_TREE
1457 && cum->nbytes + size > nregs * UNITS_PER_WORD)
1458 return 0;
1459
1460 return (nregs * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
1461 }
1462
1463 rtx
1464 mn10200_va_arg (valist, type)
1465 tree valist, type;
1466 {
1467 HOST_WIDE_INT align, rsize;
1468 tree t, ptr, pptr;
1469
1470 /* Compute the rounded size of the type. */
1471 align = PARM_BOUNDARY / BITS_PER_UNIT;
1472 rsize = (((int_size_in_bytes (type) + align - 1) / align) * align);
1473
1474 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
1475 build_int_2 ((rsize > 8 ? 4 : rsize), 0));
1476 TREE_SIDE_EFFECTS (t) = 1;
1477
1478 ptr = build_pointer_type (type);
1479
1480 /* "Large" types are passed by reference. */
1481 if (rsize > 8)
1482 {
1483 pptr = build_pointer_type (ptr);
1484 t = build1 (NOP_EXPR, pptr, t);
1485 TREE_SIDE_EFFECTS (t) = 1;
1486
1487 t = build1 (INDIRECT_REF, ptr, t);
1488 TREE_SIDE_EFFECTS (t) = 1;
1489 }
1490 else
1491 {
1492 t = build1 (NOP_EXPR, ptr, t);
1493 TREE_SIDE_EFFECTS (t) = 1;
1494 }
1495
1496 /* Calculate! */
1497 return force_reg (Pmode, expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL));
1498 }
1499
1500 const char *
1501 output_tst (operand, insn)
1502 rtx operand, insn;
1503 {
1504
1505 rtx temp;
1506 int past_call = 0;
1507
1508 /* Only tst insns using address registers can be optimized. */
1509 if (REGNO_REG_CLASS (REGNO (operand)) != ADDRESS_REGS)
1510 return "cmp 0,%0";
1511
1512 /* If testing an address register against zero, we can do better if
1513 we know there's a register already holding the value zero. First
1514 see if a global register has been set to zero, else we do a search
1515 for a register holding zero, if both of those fail, then we use a
1516 compare against zero. */
1517 if (zero_dreg || zero_areg)
1518 {
1519 rtx xoperands[2];
1520 xoperands[0] = operand;
1521 xoperands[1] = zero_dreg ? zero_dreg : zero_areg;
1522
1523 output_asm_insn ("cmp %1,%0", xoperands);
1524 return "";
1525 }
1526
1527 /* We can save a byte if we can find a register which has the value
1528 zero in it. */
1529 temp = PREV_INSN (insn);
1530 while (temp)
1531 {
1532 rtx set;
1533
1534 /* We allow the search to go through call insns. We record
1535 the fact that we've past a CALL_INSN and reject matches which
1536 use call clobbered registers. */
1537 if (GET_CODE (temp) == CODE_LABEL
1538 || GET_CODE (temp) == JUMP_INSN
1539 || GET_CODE (temp) == BARRIER)
1540 break;
1541
1542 if (GET_CODE (temp) == CALL_INSN)
1543 past_call = 1;
1544
1545 if (GET_CODE (temp) == NOTE)
1546 {
1547 temp = PREV_INSN (temp);
1548 continue;
1549 }
1550
1551 /* It must be an insn, see if it is a simple set. */
1552 set = single_set (temp);
1553 if (!set)
1554 {
1555 temp = PREV_INSN (temp);
1556 continue;
1557 }
1558
1559 /* Are we setting a register to zero?
1560
1561 If it's a call clobbered register, have we past a call? */
1562 if (REG_P (SET_DEST (set))
1563 && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set)))
1564 && !reg_set_between_p (SET_DEST (set), temp, insn)
1565 && (!past_call
1566 || !call_used_regs[REGNO (SET_DEST (set))]))
1567 {
1568 rtx xoperands[2];
1569 xoperands[0] = operand;
1570 xoperands[1] = SET_DEST (set);
1571
1572 output_asm_insn ("cmp %1,%0", xoperands);
1573 return "";
1574 }
1575 temp = PREV_INSN (temp);
1576 }
1577 return "cmp 0,%0";
1578 }
1579
1580 /* Return nonzero if OP is a valid operand for a {zero,sign}_extendpsisi
1581 instruction.
1582
1583 It accepts anything that is a general operand or the sum of the
1584 stack pointer and a general operand. */
1585 int
1586 extendpsi_operand (op, mode)
1587 rtx op;
1588 enum machine_mode mode;
1589 {
1590 return (general_operand (op, mode)
1591 || (GET_CODE (op) == PLUS
1592 && XEXP (op, 0) == stack_pointer_rtx
1593 && general_operand (XEXP (op, 1), VOIDmode)));
1594 }