OSDN Git Service

(machine_dependent_reorg): When remove SUBREG, add in
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / sh.c
1 /* Output routines for GCC for Hitachi Super-H
2    Copyright (C) 1993, 1994 Free Software Foundation, Inc.
3
4    This file is part of GNU CC.
5
6    GNU CC is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GNU CC is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GNU CC; see the file COPYING.  If not, write to
18    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20
21 /* Contributed by Steve Chamberlain (sac@cygnus.com) */
22
23 #include <stdio.h>
24 #include "assert.h"
25 #include "config.h"
26 #include "rtl.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 "insn-flags.h"
33 #include "tree.h"
34 #include "output.h"
35
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "obstack.h"
39 #include "expr.h"
40
41 #define MSW (TARGET_LITTLE_ENDIAN ? 1 : 0)
42 #define LSW (TARGET_LITTLE_ENDIAN ? 0 : 1)
43
44
45 static rtx add_constant ();
46
47 int pragma_interrupt;
48 int pragma_trapa;
49
50 int current_function_anonymous_args;
51 extern int current_function_pretend_args_size;
52 extern char *version_string;
53 extern int flag_traditional;
54
55 static rtx shiftsyms[32];
56 struct rtx_def *table_lab;
57 enum attr_cpu sh_cpu;           /* target cpu */
58
59
60 char *max_si;
61 char *max_hi;
62 int  max_count_si;
63 int  max_count_hi;
64
65 /* Global variables for machine-dependent things. */
66
67 /* Saved operands from the last compare to use when we generate an scc
68    or bcc insn. */
69
70 rtx sh_compare_op0;
71 rtx sh_compare_op1;
72
73 /* Provides the class number of the smallest class containing
74    reg number */
75
76 int regno_reg_class[FIRST_PSEUDO_REGISTER] =
77 {
78   R0_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
79   GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
80   GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
81   GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
82   GENERAL_REGS, PR_REGS, T_REGS, NO_REGS,
83   MAC_REGS, MAC_REGS,
84 };
85
86 /* Provide reg_class from a letter such as appears in the machine
87    description. */
88
89 enum reg_class reg_class_from_letter[] =
90 {
91   /* a */ NO_REGS, /* b */ NO_REGS, /* c */ NO_REGS, /* d */ NO_REGS,
92   /* e */ NO_REGS, /* f */ NO_REGS, /* g */ NO_REGS, /* h */ NO_REGS,
93   /* i */ NO_REGS, /* j */ NO_REGS, /* k */ NO_REGS, /* l */ PR_REGS,
94   /* m */ NO_REGS, /* n */ NO_REGS, /* o */ NO_REGS, /* p */ NO_REGS,
95   /* q */ NO_REGS, /* r */ NO_REGS, /* s */ NO_REGS, /* t */ T_REGS,
96   /* u */ NO_REGS, /* v */ NO_REGS, /* w */ NO_REGS, /* x */ MAC_REGS,
97   /* y */ NO_REGS, /* z */ R0_REGS
98 };
99
100 /* Value is 1 if register/mode pair is acceptable on SH.  Even
101    registers can hold DIs and DF values. The rest can only hold
102    SI's efficiently  */
103
104
105 #define REG_ODD \
106  (  (1 << (int) QImode)  | (1 << (int) HImode) | (1 << (int) SImode)    \
107   | (1 << (int) QFmode)  | (1 << (int) HFmode) | (1 << (int) SFmode)    \
108   | (1 << (int) CQImode) | (1 << (int) CHImode)| (1<< (int)DFmode) | (1<<(int)DImode))
109
110 #define REG_EVEN \
111   (REG_ODD | (1 << (int) CSImode) | (1 << (int) SCmode))
112
113 #define SI_ONLY (1<<(int)SImode)
114
115 int hard_regno_mode_ok[] =
116 {
117   REG_EVEN, REG_ODD, REG_EVEN, REG_ODD,
118   REG_EVEN, REG_ODD, REG_EVEN, REG_ODD,
119   REG_EVEN, REG_ODD, REG_EVEN, REG_ODD,
120   REG_EVEN, REG_ODD, REG_EVEN, REG_ODD,
121   REG, 0, SI_ONLY, SI_ONLY,
122   SI_ONLY, SI_ONLY
123 };
124
125 /* Local label counter, used for constants in the pool and inside
126    pattern branches.  */
127 static int lf = 100;
128
129
130 /* Number of bytes pushed for anonymous args, used to pass information
131    between expand_prologue and expand_epilogue. */
132 static int extra_push;
133 \f
134
135
136 void
137 push (rn)
138      int rn;
139 {
140   rtx x ;
141   x=  emit_insn (gen_push (gen_rtx (REG, SImode, rn)));
142   REG_NOTES (x) = gen_rtx (EXPR_LIST, REG_INC, 
143                            gen_rtx(REG, SImode, STACK_POINTER_REGNUM), 0);
144 }
145
146 void
147 pop (rn)
148      int rn;
149 {
150   rtx x;
151   x =  emit_insn (gen_pop (gen_rtx (REG, SImode, rn)));
152   REG_NOTES (x) = gen_rtx (EXPR_LIST, REG_INC, 
153                            gen_rtx(REG, SImode, STACK_POINTER_REGNUM), 0);
154 }
155
156
157 /* Adjust the stack and return the number of bytes taken to do it */
158 static rtx lastreg;
159 int lastval;
160 static void
161 output_stack_adjust (size)
162      int size;
163 {
164   if (size)
165     {
166       rtx val = GEN_INT (size);
167       rtx insn;
168
169       if (!CONST_OK_FOR_I (size))
170         {
171           lastreg = gen_rtx (REG, SImode, 3);
172           lastval = size;
173           emit_insn (gen_movsi (lastreg, val));
174           val = lastreg;
175
176         }
177
178       insn = gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, val);
179       emit_insn (insn);
180     }
181 }
182
183
184 /* Generate code to push the regs specified in the mask, and return
185    the number of bytes the insns take. */
186
187 static void
188 push_regs (mask)
189      int mask;
190 {
191   int i;
192
193   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
194     {
195       if (mask & (1 << i))
196         {
197           push (i);
198         }
199     }
200 }
201
202
203 /* Print an instruction which would have gone into a delay slot after
204    an instructiuon, but couldn't because the instruction expanded into a
205    sequence where putting the slot insn at the end wouldn't work. */
206
207 static void
208 print_slot (insn)
209      rtx insn;
210 {
211   final_scan_insn (XVECEXP (insn, 0, 1), asm_out_file, optimize, 0, 1);
212
213   INSN_DELETED_P (XVECEXP (insn, 0, 1)) = 1;
214 }
215
216
217 /* Work out the registers which need to be saved, both as a mask and a
218    count.
219
220    If doing a pragma interrupt function, then push all regs used by the function,
221    and if we call another function (we can tell by looking at PR), make sure that all the
222    regs it clobbers are safe too.
223  */
224 static int
225 calc_live_regs (count_ptr)
226      int *count_ptr;
227 {
228   int reg;
229   int live_regs_mask = 0;
230   int count = 0;
231   for (reg = 0; reg < FIRST_PSEUDO_REGISTER; reg++)
232     {
233       if (reg == ARG_POINTER_REGNUM)
234         continue;
235       if (reg == T_REG)
236         continue;
237       if (reg == GBR_REG)
238         continue;
239
240       if (pragma_interrupt && !pragma_trapa)
241         {
242           /* Need to save all the regs ever live */
243           if ((regs_ever_live[reg]
244                || (call_used_regs[reg] && regs_ever_live[PR_REG]))
245               && reg != 15)
246             {
247               live_regs_mask |= 1 << reg;
248               count++;
249             }
250         }
251       else if (TARGET_SMALLCALL)
252         {
253           /* Don't need to push anthing, but count the regs which have
254              been pushed by the wrapper */
255           if (call_used_regs[reg])
256             count++;
257         }
258       else
259         {
260           /* Only push those regs which are used and need to be saved */
261           if (regs_ever_live[reg] && !call_used_regs[reg])
262             {
263               count++;
264               live_regs_mask |= (1 << reg);
265             }
266         }
267     }
268
269
270   *count_ptr = count;
271   return live_regs_mask;
272 }
273 \f
274
275 static int
276 need_slot (insn)
277      rtx insn;
278 {
279   return (insn && !INSN_ANNULLED_BRANCH_P (XVECEXP (insn, 0, 0)));
280 }
281
282 /* Print the operand address in x to the stream */
283
284 void
285 print_operand_address (stream, x)
286      FILE *stream;
287      rtx x;
288 {
289   switch (GET_CODE (x))
290     {
291     case REG:
292       fprintf (stream, "@%s", reg_names[REGNO (x)]);
293       break;
294     case PLUS:
295       {
296         rtx base = XEXP (x, 0);
297         rtx index = XEXP (x, 1);
298
299         if (GET_CODE (base) != REG)
300           {
301             /* Ensure that BASE is a register (one of them must be). */
302             rtx temp = base;
303             base = index;
304             index = temp;
305           }
306
307         switch (GET_CODE (index))
308           {
309           case CONST_INT:
310             fprintf (stream, "@(%d,%s)",
311                      INTVAL (index),
312                      reg_names[REGNO (base)]);
313             break;
314
315           case REG:
316             fprintf (stream, "@(r0,%s)",
317                      reg_names[MAX (REGNO (base), REGNO (index))]);
318
319             break;
320
321           default:
322             debug_rtx (x);
323             abort ();
324           }
325       }
326
327       break;
328     case PRE_DEC:
329       fprintf (stream, "@-%s", reg_names[REGNO (XEXP (x, 0))]);
330       break;
331
332     case POST_INC:
333       fprintf (stream, "@%s+", reg_names[REGNO (XEXP (x, 0))]);
334       break;
335
336     default:
337       output_addr_const (stream, x);
338       break;
339     }
340 }
341
342 /* Print operand x (an rtx) in assembler syntax to file stream
343    according to modifier code.
344
345    '.'  print a .s if insn needs delay slot
346    '*'  print a local label
347    '^'  increment the local label number
348    '!'  dump the constant table
349    '#'  output a nop if there is nothing to put in the delay slot
350    '@'  print rte or rts depending upon pragma interruptness
351    'R'  print the LSW of a dp value - changes if in little endian
352    'T'  print the next word of a dp value - same as 'R' in big endian mode.
353    'S'  print the MSW of a dp value - changes if in little endian
354    'O'  print a constant without the #
355    'M'  print a constant as its negative
356    'N'  print insides of a @++ or @-- o */
357
358 void
359 print_operand (stream, x, code)
360      FILE *stream;
361      rtx x;
362      int code;
363 {
364   switch (code)
365     {
366     case '.':
367       if (need_slot (final_sequence))
368         fprintf (stream, ".s");
369       break;
370     case '*':
371       fprintf (stream, "LF%d", lf);
372       break;
373     case '^':
374       lf++;
375       break;
376     case '@':
377       if (pragma_interrupt)
378         fprintf (stream, "rte");
379       else
380         fprintf (stream, "rts");
381       break;
382     case '#':
383       /* Output a nop if there's nothing in the delay slot */
384       if (dbr_sequence_length () == 0)
385         {
386           fprintf (stream, "\n\tnop");
387         }
388       break;
389     case 'O':
390       output_addr_const (stream, x);
391       break;
392     case 'M':
393       fprintf (asm_out_file, "#%d", -INTVAL (x));
394       break;
395     case 'N':
396       fputs (reg_names[REGNO (XEXP (XEXP (x, 0), 0))], (stream));
397       break;
398     case 'R':
399       /* LSW of a double */
400       switch (GET_CODE (x))
401         {
402         case REG:
403           fputs (reg_names[REGNO (x) + LSW], (stream));
404           break;
405         case MEM:
406           print_operand_address (stream, XEXP (adj_offsettable_operand (x, LSW *4), 0));
407           break;
408         }
409       break;
410     case 'T':
411       /* Next word of a double */
412       switch (GET_CODE (x))
413         {
414         case REG:
415           fputs (reg_names[REGNO (x) + 1], (stream));
416           break;
417         case MEM:
418           print_operand_address (stream, XEXP (adj_offsettable_operand (x,1 *4), 0));
419           break;
420         }
421       break;
422     case 'S':
423       /* MSW of a double */
424       switch (GET_CODE (x))
425         {
426         case REG:
427           fputs (reg_names[REGNO (x) + MSW], (stream));
428           break;
429         case MEM:
430           print_operand_address (stream, XEXP (adj_offsettable_operand (x, MSW *4), 0));
431           break;
432         }
433       break;
434     default:
435       switch (GET_CODE (x))
436         {
437         case REG:
438           fputs (reg_names[REGNO (x)], (stream));
439           break;
440         case MEM:
441           output_address (XEXP (x, 0));
442           break;
443         default:
444           fputc ('#', stream);
445           output_addr_const (stream, x);
446           break;
447         }
448       break;
449     }
450 }
451 \f
452
453 static int
454 sextb (x)
455   int x;
456 {
457   x &= 0xff;
458   if (x > 127)
459     {
460       x = -256 + x;
461     }
462   return x;
463 }
464
465
466
467 /* Take a move with integer constant source in OPERANDS, see if it can be generated by
468    devious shifting.  If so, generate the instruction sequence and return 1, otherwise
469    return 0.
470
471     OPERANDS[0] Destination register
472     OPERANDS[1] Source constant
473
474    00000000 00000000 00000000 0NNNNNNNN simple load
475    00000000 00000000 00000000 NNNNNNNN0 load and shift by 1
476    00000000 00000000 0000000N NNNNNNN00 load and shift by 2
477    00000000 00000000 0NNNNNNN 000000000 load and shift by 8
478    00000000 0NNNNNNN 00000000 000000000 load and shift by 16
479    N0000000 00000000 00000000 00NNNNNNN load and rotate right
480
481    11111111 11111111 11111111 1NNNNNNNN simple load
482    11111111 11111111 11111111 NNNNNNNN0 load and shift by 1
483    11111111 11111111 1111111N NNNNNNN00 load and shift by 2
484    11111111 11111111 1NNNNNNN 000000000 load and shift by 8
485    11111111 1NNNNNNN 00000000 000000000 load and shift by 16
486    N1111111 11111111 11111111 11NNNNNNN load and rotate right
487
488    00000000 00000000 00000000 1NNNNNNNN load and zero extend byte
489    00000000 00000000 11111111 1NNNNNNNN load and zero extend word
490
491
492 */
493
494 static int
495 synth_constant (operands, mode)
496      rtx operands[];
497      enum machine_mode mode;
498 {
499   rtx dst;
500   int i = INTVAL (operands[1]) & 0xffffffff;
501     
502   if (CONST_OK_FOR_I (i))
503     return 0;
504
505   if (TARGET_CLEN0 && mode != QImode)
506     return 0;
507
508   if (mode != SImode)
509     {
510       if (reload_in_progress)
511         return 0;
512       dst = gen_reg_rtx (SImode);
513     }
514   else
515     {
516       dst = operands[0];
517     }
518
519
520   /*  00000000 00000000 11111111 1NNNNNNNN load and zero extend word      */
521   if ((i & 0xffffff80) == 0x0000ff80)
522     {
523       emit_move_insn (dst, GEN_INT (sextb (i)));
524       emit_insn (gen_and_ffff (dst, dst));
525     }
526   /*    00000000 00000000 00000000 1NNNNNNNN load and zero extend byte */
527   else if ((i & 0xffffff80) == 0x00000080)
528     {
529       emit_move_insn (dst, GEN_INT (sextb (i)));
530       emit_insn (gen_and_ff (dst, dst));
531     }
532   /*   00000000 00000000 00000000 NNNNNNNN0 load and shift by 1
533        11111111 11111111 11111111 NNNNNNNN0 load and shift by 1 */
534   else if ((i & 0xffffff01) == 0
535            || (i & 0xffffff01) == 0xffffff00)
536     {
537       emit_move_insn (dst, GEN_INT (sextb (i >> 1)));
538       emit_insn (gen_ashlsi3_n (dst, dst, GEN_INT (1)));
539     }
540   /*   00000000 00000000 0000000N NNNNNNN00 load and shift by 2
541        11111111 11111111 1111111N NNNNNNN00 load and shift by 2*/
542   else if ((i & 0xfffffe03) == 0
543            || (i & 0xfffffe03) == 0xfffffe00)
544     {
545       emit_move_insn (dst, GEN_INT (sextb (i >> 2)));
546       emit_insn (gen_ashlsi3_n (dst, dst, GEN_INT (2)));
547     }
548   /*   00000000 00000000 0NNNNNNN 000000000 load and shift by 8
549        11111111 11111111 1NNNNNNN 000000000 load and shift by 8 */
550
551   else if ((i & 0xffff80ff) == 0
552            || (i & 0xffff80ff) == 0xffff8000)
553     {
554       emit_move_insn (dst, GEN_INT (sextb (i >> 8)));
555       emit_insn (gen_ashlsi3_n (dst, dst, GEN_INT (8)));
556     }
557   /*     00000000 0NNNNNNN 00000000 000000000 load and shift by 16
558          11111111 1NNNNNNN 00000000 000000000 load and shift by 16 */
559   else if ((i & 0xff80ffff) == 0x00000000
560            || (i & 0xff80ffff) == 0xff800000)
561     {
562       emit_move_insn (dst, GEN_INT (sextb (i >> 16)));
563       emit_insn (gen_ashlsi3_n (dst, dst, GEN_INT (16)));
564     }
565   /*   00000000 00000000 0NNNNNNN 0NNNNNNNN load shift 8 and add */
566   else if ((i & 0xffff8080) == 0 && TARGET_CLEN3)
567     {
568       emit_move_insn (dst, GEN_INT (sextb (i >> 8)));
569       emit_insn (gen_ashlsi3_n (dst, dst, GEN_INT (8)));
570       emit_insn (gen_addsi3 (dst, dst, GEN_INT (i & 0x7f)));
571     }
572   else
573     return 0;
574
575   if (mode == DImode)
576     {
577       /* Moving from SI to DI, we've got to zero out the high part */
578
579       emit_insn (gen_rtx (SET, VOIDmode, 
580                           gen_rtx (SUBREG, SImode, operands[0], 0),
581                           dst));
582       emit_insn (gen_rtx (SET, VOIDmode,
583                           gen_rtx (SUBREG, SImode, operands[0], 1),
584                           const0_rtx));
585
586     }
587   else if (mode != SImode)
588     {
589       emit_insn (gen_rtx (SET, VOIDmode, operands[0],
590                           gen_rtx (SUBREG, mode, dst, 0)));
591
592     }
593   return 1;
594 }
595
596
597 /* Emit code to perform a block move.  Choose the best method.
598
599    OPERANDS[0] is the destination.
600    OPERANDS[1] is the source.
601    OPERANDS[2] is the size.
602    OPERANDS[3] is the alignment safe to use.  */
603
604
605 int
606 expand_block_move (operands)
607      rtx *operands;
608 {
609   int align = INTVAL (operands[3]);
610   int constp = (GET_CODE (operands[2]) == CONST_INT);
611   int bytes = (constp ? INTVAL (operands[2]) : 0);
612   enum machine_mode mode;
613
614   /* IF odd then fail */
615   if (!constp || bytes <= 0)
616     return 0;
617
618   /* Don't expand if we'd make the code bigger and we don't want big code */
619
620   if (bytes > 8 && TARGET_SMALLCODE)
621     return 0;
622
623   switch (align)
624     {
625     case 1:
626       mode = QImode;
627       break;
628     case 2:
629       mode = HImode;
630       break;
631     default:
632       mode = SImode;
633       align = 4;
634     }
635
636   if (mode == SImode && constp && bytes < 64 && (bytes % 4 == 0))
637     {
638       char entry[30];
639       tree entry_name;
640       rtx func_addr_rtx;
641       rtx r4 = gen_rtx (REG, SImode, 4);
642       rtx r5 = gen_rtx (REG, SImode, 5);
643       sprintf (entry, "__movstr%s%d", GET_MODE_NAME (mode), bytes);
644       entry_name = get_identifier (entry);
645
646       func_addr_rtx = copy_to_mode_reg (Pmode,
647               gen_rtx (SYMBOL_REF, Pmode, IDENTIFIER_POINTER (entry_name)));
648       emit_insn (gen_move_insn (r4, XEXP (operands[0], 0)));
649       emit_insn (gen_move_insn (r5, XEXP (operands[1], 0)));
650       emit_insn (gen_block_move_real (func_addr_rtx));
651       return 1;
652     }
653   if (mode == SImode && constp && (bytes % 4 == 0))
654     {
655       tree entry_name;
656       rtx func_addr_rtx;
657       rtx r4 = gen_rtx (REG, SImode, 4);
658       rtx r5 = gen_rtx (REG, SImode, 5);
659       rtx r6 = gen_rtx (REG, SImode, 6);
660       entry_name = get_identifier ("__movstr");
661
662       func_addr_rtx = copy_to_mode_reg (Pmode,
663                                         gen_rtx (SYMBOL_REF, Pmode,
664                                           IDENTIFIER_POINTER (entry_name)));
665       emit_insn (gen_move_insn (r4, XEXP (operands[0], 0)));
666       emit_insn (gen_move_insn (r5, XEXP (operands[1], 0)));
667
668       /* r6 controls the size of the move, 16 is decremented from it
669          for each 64 bytes moved, then the -ve bit is used as an index into a
670          list of move instructions like this:
671         
672          {
673          do {
674          *dst++ = *src++;
675          *dst++ = *src++;
676          *dst++ = *src++;
677          ..etc.. 16 in all
678          *dst++ = *src++;
679          *dst++ = *src++;
680          size -= 16;
681          } while (size > 0);
682         
683          switch (size)
684          {
685          case -15:
686          *dst++ = *src++;
687          case -14:
688          *dst++ = *src++;
689          .. etc.. ;
690          case -2:
691          *dst++ = *src++;
692          case -1:
693          *dst++ = *src++;
694          case 0:
695          ;
696          }
697          }
698         
699          eg, a 72 byte move would be set up with size(r6) = 14, for one
700          iteration through the big while loop, and a switch of -2 for the last part  */
701
702       {
703         int final_switch = 16 - ((bytes / 4) % 16);
704         int while_loop = ((bytes / 4) / 16 - 1) * 16;
705         emit_insn (gen_move_insn (r6, GEN_INT (while_loop + final_switch)));
706         emit_insn (gen_block_lump_real (func_addr_rtx));
707         return 1;
708       }
709     }
710
711   return 0;
712 }
713
714 /* Prepare operands for a move define_expand; specifically, one of the
715    operands must be in a register.  Take this chance to remove
716    addressing modes which can't be coped with very well. */
717
718 int
719 prepare_move_operands (operands, mode)
720      rtx operands[];
721      enum machine_mode mode;
722 {
723   if (!(reload_in_progress || reload_completed)
724       && ((!register_operand (operands[0], mode)
725            && !register_operand (operands[1], mode))
726           || GET_CODE (operands[1]) == PLUS))
727     {
728       /* copy the source to a register */
729       operands[1] = copy_to_mode_reg (mode, operands[1]);
730     }
731   if ((mode == SImode || mode == HImode || mode == QImode)
732       && GET_CODE (operands[1]) == CONST_INT)
733     {
734       return synth_constant (operands, mode);
735     }
736   if (mode == DFmode || mode == DImode)
737     {
738       rtx src = operands[1];
739       rtx dst = operands[0];
740       rtx insns;
741
742       if (src == dst)
743         {
744           emit_insn (gen_rtx (SET, VOIDmode, dst, src));
745           return 1;
746         }
747
748       if (GET_CODE (src) == REG &&
749           REGNO (src) >= FIRST_PSEUDO_REGISTER)
750         return 0;
751
752       if (GET_CODE (dst) == REG &&
753           REGNO (dst) >= FIRST_PSEUDO_REGISTER)
754         return 0;
755
756       if (push_operand (dst, mode))
757         return 0;
758
759       if (GET_CODE (src) == CONST_DOUBLE)
760         src = force_const_mem (DFmode, src);
761
762       if (reload_in_progress)
763         {
764           if (!(offsettable_memref_p (src) || register_operand (src, mode)))
765             return 0;
766           if (!(offsettable_memref_p (dst) || register_operand (dst,
767                                                                 mode)))
768             return 0;
769         }
770       start_sequence ();
771       if (GET_CODE (operands[0]) != REG
772           || !refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1, operands[1], 0))
773         {
774           emit_move_insn (operand_subword (dst, 0, 1, mode),
775                           operand_subword_force (src, 0, mode));
776           emit_move_insn (operand_subword (dst, 1, 1, mode),
777                           operand_subword_force (src, 1, mode));
778         }
779       else
780         {
781           emit_move_insn (operand_subword (dst, 1, 1, mode),
782                           operand_subword_force (src, 1, mode));
783           emit_move_insn (operand_subword (dst, 0, 1, mode),
784                           operand_subword_force (src, 0, mode));
785         }
786
787       insns = get_insns ();
788       end_sequence ();
789
790       emit_no_conflict_block (insns, dst, src, 0, src);
791       return 1;
792     }
793
794   return 0;
795 }
796
797 /* Prepare the operands for an scc instruction; make sure that the
798    compare has been done.  */
799 rtx
800 prepare_scc_operands (code)
801      int code;
802 {
803   if (GET_CODE (sh_compare_op0) != REG
804       || REGNO (sh_compare_op0) != T_REG)
805     {
806       int newcode = code;
807       /* First need a compare insn */
808       switch (code)
809         {
810         case NE:
811           newcode = EQ;
812           break;
813         case LT:
814           newcode = GT;
815           break;
816         case LE:
817           newcode = GE;
818           break;
819         case LTU:
820           newcode = GTU;
821           break;
822         case LEU:
823           newcode = GEU;
824           break;
825         }
826       if (newcode != code)
827         {
828           rtx tmp = sh_compare_op0;
829           sh_compare_op0 = sh_compare_op1;
830           sh_compare_op1 = tmp;
831           code = newcode;
832         }
833
834       sh_compare_op0 = force_reg (SImode, sh_compare_op0);
835       emit_insn (gen_rtx (SET, VOIDmode,
836                           gen_rtx (REG, SImode, T_REG),
837                    gen_rtx (code, SImode, sh_compare_op0, sh_compare_op1)));
838     }
839   return gen_rtx (REG, SImode, T_REG);
840 }
841 \f
842
843 /* Functions to output assembly code. */
844
845 /* Return a sequence of instructions to perform DI or DF move.
846
847    Since the SH cannot move a DI or DF in one instruction, we have
848    to take care when we see overlapping source and dest registers.
849
850  */
851
852 char *
853 output_movedouble (insn, operands, mode)
854      rtx insn;
855      rtx operands[];
856      enum machine_mode mode;
857 {
858   rtx dst = operands[0];
859   rtx src = operands[1];
860
861 /*   fprintf (asm_out_file, "! move double \n");
862   fprintf (asm_out_file, "! pc %04x\n", insn_addresses[INSN_UID (insn)]);*/
863   if (GET_CODE (dst) == MEM
864       && GET_CODE (XEXP (dst, 0)) == POST_INC)
865     {
866       operands[0] = XEXP (XEXP (dst, 0), 0);
867       return "mov.l     %T1,@(4,%0)\n\tmov.l    %1,@%0\n\tadd   #8,%0";
868     }
869   if (register_operand (dst, mode)
870       && register_operand (src, mode))
871     {
872       if (REGNO (src) == MACH_REG)
873         return "sts     mach,%S0\n\tsts macl,%R0";
874
875       /*
876          when mov.d r1,r2 do r2->r3 then r1->r2
877          when mov.d r1,r0 do r1->r0 then r2->r1
878        */
879
880       if (REGNO (src) + 1 == REGNO (dst))
881         return "mov     %T1,%T0\n\tmov  %1,%0 ! cra";
882       else
883         return "mov     %1,%0\n\tmov    %T1,%T0 ! crb";
884     }
885   else if (GET_CODE (src) == CONST_INT)
886     {
887       HOST_WIDE_INT val = INTVAL (src);
888       int rn = REGNO (operands[0]);
889       int msw = rn + MSW;
890       int lsw = rn + LSW;
891       if (val < 0)
892         {
893           fprintf (asm_out_file, "\tmov #-1,r%d\n", msw);
894         }
895       else
896         {
897           fprintf (asm_out_file, "\tmov #0,r%d\n", msw);
898         }
899
900       fprintf (asm_out_file, "\tmov     #%d,r%d\n", val, lsw);
901       return "";
902     }
903   else if (GET_CODE (src) == MEM)
904     {
905       int ptrreg1 = -1;
906       int ptrreg2 = -1;
907       int dreg = REGNO (dst);
908       rtx inside = XEXP (src, 0);
909
910       if (GET_CODE (inside) == REG)
911         {
912           ptrreg1 = REGNO (inside);
913         }
914       else if (GET_CODE (inside) == PLUS)
915         {
916           rtx lhs = XEXP (inside, 0);
917           rtx rhs = XEXP (inside, 1);
918           if (GET_CODE (lhs) == REG)
919             ptrreg1 = REGNO (lhs);
920           if (GET_CODE (rhs) == REG)
921             ptrreg2 = REGNO (rhs);
922         }
923       else if (GET_CODE (inside) == LABEL_REF)
924         {
925           return "mov.l %1,%0\n\tmov.l  %1+4,%T0";
926         }
927       else if (GET_CODE (inside) == POST_INC)
928         {
929           return "mov.l %1,%0\n\tmov.l  %1,%T0 !mdi\n";
930         }
931       else
932         abort ();
933
934       if ((ptrreg1 >= 0 && ptrreg2 >= 0)
935           && (dreg == ptrreg1
936               || dreg == ptrreg2
937               || dreg + 1 == ptrreg1
938               || dreg + 1 == ptrreg2))
939         {
940           /* This move clobbers both index registers,
941              calculate the sum in one register.  */
942           fprintf (asm_out_file, "      add     %s,%s ! special fix\n",
943                    reg_names[ptrreg2], reg_names[ptrreg1]);
944
945           if (dreg == ptrreg1)
946             {
947               /* Copy into dreg+1 first.  */
948               fprintf (asm_out_file, "  mov.l   @(4,%s),%s\n",
949                        reg_names[ptrreg1],
950                        reg_names[dreg + 1]);
951
952               fprintf (asm_out_file, "  mov.l   @(%s),%s\n",
953                        reg_names[ptrreg1],
954                        reg_names[dreg]);
955             }
956           else
957             {
958               /* Copy into dreg first. */
959               fprintf (asm_out_file, "  mov.l   @(%s),%s\n",
960                        reg_names[ptrreg1],
961                        reg_names[dreg]);
962
963               fprintf (asm_out_file, "  mov.l   @(4,%s),%s\n",
964                        reg_names[ptrreg1],
965                        reg_names[dreg + 1]);
966
967             }
968           warning ("generated complex amode");
969           return "";
970         }
971
972       /* Work out the safe way to copy */
973       if (dreg == ptrreg1)
974         {
975           /* Copy into the second half first */
976           return "mov.l %T1,%T0\n\tmov.l        %1,%0 ! cr";
977         }
978     }
979
980   return "mov.l %1,%0\n\tmov.l  %T1,%T0";
981 }
982
983 /* Emit assembly to shift reg by k bits */
984
985 char *
986 output_shift (string, reg, k, code)
987      char *string;
988      rtx reg;
989      rtx k;
990      int code;
991
992 {
993   int s = INTVAL (k);
994   if (s < 0)
995     {
996       s = -s;
997       switch (code)
998         {
999         case LSHIFTRT:
1000         case ASHIFTRT:
1001           code = ASHIFT;
1002           break;
1003         case ASHIFT:
1004           code = ASHIFTRT;
1005           break;
1006         default:
1007           abort ();
1008         }
1009     }
1010   if (code == ASHIFT && s == 31)
1011     {
1012       /* Shift left by 31 moving into the t bit, clearing and rotating the other way */
1013
1014       fprintf (asm_out_file, "\trotr    r%d\n", REGNO (reg));
1015       fprintf (asm_out_file, "\tmov     #0,r%d\n", REGNO (reg));
1016       fprintf (asm_out_file, "\trotcr   r%d\n", REGNO (reg));
1017       s = 0;
1018     }
1019
1020   if (code == LSHIFTRT && s == 31)
1021     {
1022       fprintf (asm_out_file, "\trotl    r%d\n", REGNO (reg));
1023       fprintf (asm_out_file, "\tmov     #0,r%d\n", REGNO (reg));
1024       fprintf (asm_out_file, "\trotcl   r%d\n", REGNO (reg));
1025       s = 0;
1026     }
1027
1028   while (s)
1029     {
1030       char *out;
1031       int d;
1032
1033       if (s >= 16)
1034         {
1035           d = 16;
1036           out = "16";
1037         }
1038       else if (s >= 8)
1039         {
1040           d = 8;
1041           out = "8";
1042         }
1043       else if (s >= 2)
1044         {
1045           d = 2;
1046           out = "2";
1047         }
1048       else
1049         {
1050           d = 1;
1051           out = "";
1052         }
1053       fprintf (asm_out_file, "\t%s%s\tr%d\n", string, out, REGNO (reg));
1054       s -= d;
1055     }
1056   return "";
1057 }
1058
1059
1060 void
1061 function_epilogue (stream, size)
1062      FILE *stream;
1063      int size;
1064 {
1065   pragma_interrupt = pragma_trapa = 0;
1066 }
1067
1068
1069 /* Return the text of the branch instruction which matches its length
1070    attribute.
1071
1072    This gets tricky if we have an insn in the delay slot of a branch
1073    and the branch needs more than 1 insn to complete. */
1074
1075 int pending_const_table;
1076
1077  /* We can't tell if we need a register as a scratch for the jump
1078     until after branch shortening, and then it's too late to allocate a
1079     register the 'proper' way.  These instruction sequences are rare
1080     anyway, so to avoid always using a reg up from our limited set, we'll
1081     grab one when we need one on output. */
1082
1083 char *
1084 output_far_jump (insn, op)
1085      rtx insn;
1086      rtx op;
1087 {
1088   rtx thislab = gen_label_rtx ();
1089
1090   if (dbr_sequence_length ())
1091     {
1092       /* Something to go in what would have been the delay
1093          slot if this had been a short branch. Make sure the
1094          reg we use to generate the branch target address
1095          doesn't conflict */
1096
1097       int i;
1098       rtx vec[2];
1099       vec[0] = thislab;
1100
1101       for (i = 0; i < 8; i++)
1102         {
1103           vec[1] = gen_rtx (REG, SImode, i);
1104           if (!reg_referenced_p (vec[1],
1105                                  PATTERN (XVECEXP (final_sequence, 0, 1))))
1106             break;
1107         }
1108
1109
1110       print_slot (final_sequence);
1111       output_asm_insn ("mov.l   %1,@-r15", vec);
1112       output_asm_insn ("mov.l   %O0,%1", vec);
1113
1114       output_asm_insn ("jmp     @%1 ! 32 xcond", vec);
1115       output_asm_insn ("mov.l   @r15+,%1", vec);
1116     }
1117   else
1118     {
1119       output_asm_insn ("mov.l   r13,@-r15", 0);
1120       output_asm_insn ("mov.l   %O0,r13", &thislab);
1121       output_asm_insn ("jmp     @r13 ! 32 zcond", 0);
1122       output_asm_insn ("mov.l   @r15+,r13", 0);
1123     }
1124
1125   output_asm_insn (".align      2", 0);
1126   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (thislab));
1127   output_asm_insn (".long       %O0", &op);
1128   return "";
1129 }
1130
1131 char *
1132 output_branch (logic, insn)
1133      int logic;
1134      rtx insn;
1135 {
1136   extern rtx recog_operand[];
1137   int label = lf++;
1138
1139   /*  fprintf (asm_out_file, "! pc %04x\n", insn_addresses[INSN_UID (insn)]);*/
1140
1141   switch (get_attr_length (insn))
1142     {
1143     case 2:
1144       /* Simple branch in range -200..+200 bytes */
1145       return logic ? "bt%.      %l0" : "bf%.    %l0";
1146
1147     case 6:
1148       /* Branch in range -4000..+4000 bytes */
1149       {
1150         rtx oldop = recog_operand[0];
1151
1152
1153         if (need_slot (final_sequence))
1154           {
1155             fprintf (asm_out_file, "\tb%c.s\tLF%d\n", logic ? 'f' : 't',
1156                      label);
1157
1158             print_slot (final_sequence);
1159           }
1160
1161         else
1162           {
1163             fprintf (asm_out_file, "\tb%c\tLF%d\n", logic ? 'f' : 't',
1164                      label);
1165           }
1166         recog_operand[0] = oldop;
1167
1168         output_asm_insn ("bra   %l0     ! 12 bit cond ", recog_operand);
1169         fprintf (asm_out_file, "\tor    r0,r0\n");
1170         fprintf (asm_out_file, "LF%d:\n", label);
1171       }
1172       return "";
1173
1174     case 16:
1175       /* Branches a long way away */
1176       {
1177         rtx oldop = recog_operand[0];
1178
1179         if (need_slot (final_sequence))
1180           {
1181             fprintf (asm_out_file, "\tb%c.s\tLF%d\n", logic ? 'f' : 't', label);
1182             print_slot (final_sequence);
1183
1184           }
1185         else
1186           {
1187             fprintf (asm_out_file, "\tb%c\tLF%d\n", logic ? 'f' : 't', label);
1188           }
1189
1190         output_far_jump (insn, oldop);
1191         fprintf (asm_out_file, "LF%d:\n", label);
1192         return "";
1193       }
1194     }
1195   return "bad";
1196 }
1197 \f
1198
1199 /* The SH cannot load a large constant into a register, constants have to
1200    come from a pc relative load.  The reference of a pc relative load
1201    instruction must be less than 1k infront of the instruction.  This
1202    means that we often have to dump a constant inside a function, and
1203    generate code to branch around it.
1204
1205    It is important to minimize this, since the branches will slow things
1206    down and make things bigger.
1207
1208    Worst case code looks like:
1209
1210    mov.l L1,rn
1211    bra   L2
1212    nop
1213    align
1214    L1:   .long value
1215    L2:
1216    ..
1217
1218    mov.l L3,rn
1219    bra   L4
1220    nop
1221    align
1222    L3:   .long value
1223    L4:
1224    ..
1225
1226    We fix this by performing a scan before scheduling, which notices which
1227    instructions need to have their operands fetched from the constant table
1228    and builds the table.
1229
1230
1231    The algorithm is:
1232
1233    scan, find an instruction which needs a pcrel move.  Look forward, find the
1234    last barrier which is within MAX_COUNT bytes of the requirement.
1235    If there isn't one, make one.  Process all the instructions between
1236    the find and the barrier.
1237
1238    In the above example, we can tell that L3 is within 1k of L1, so
1239    the first move can be shrunk from the 3 insn+constant sequence into
1240    just 1 insn, and the constant moved to L3 to make:
1241
1242    mov.l        L1,rn
1243    ..
1244    mov.l        L3,rn
1245    bra          L4
1246    nop
1247    align
1248    L3:.long value
1249    L4:.long value
1250
1251    Then the second move becomes the target for the shortening process.
1252
1253  */
1254
1255 typedef struct
1256 {
1257   rtx value;                    /* Value in table */
1258   rtx label;                    /* Label of value */
1259   enum machine_mode mode;       /* Mode of value */
1260 }
1261
1262 pool_node;
1263
1264 /* The maximum number of constants that can fit into one pool, since
1265    the pc relative range is 0...1020 bytes and constants are at least 4
1266    bytes long */
1267
1268 #define MAX_POOL_SIZE (1020/4)
1269 static pool_node pool_vector[MAX_POOL_SIZE];
1270 static int pool_size;
1271
1272 /* Add a constant to the pool and return its label.  */
1273
1274 static rtx
1275 add_constant (x, mode)
1276      rtx x;
1277      enum machine_mode mode;
1278 {
1279   int i;
1280   rtx lab;
1281   /* First see if we've already got it */
1282
1283   for (i = 0; i < pool_size; i++)
1284     {
1285       if (x->code == pool_vector[i].value->code
1286           && mode == pool_vector[i].mode)
1287         {
1288           if (x->code == CODE_LABEL)
1289             {
1290               if (XINT (x, 3) != XINT (pool_vector[i].value, 3))
1291                 continue;
1292             }
1293           if (rtx_equal_p (x, pool_vector[i].value))
1294             return pool_vector[i].label;
1295         }
1296     }
1297
1298   /* Need a new one */
1299
1300   pool_vector[pool_size].value = x;
1301   lab = gen_label_rtx ();
1302   pool_vector[pool_size].mode = mode;
1303   pool_vector[pool_size].label = lab;
1304   pool_size++;
1305   return lab;
1306 }
1307
1308 /* Dump out interesting debug info */
1309
1310 void
1311 final_prescan_insn (insn, opvec, noperands)
1312      rtx insn;
1313      rtx *opvec;
1314      int noperands;
1315 {
1316   if (target_flags & ISIZE_BIT)
1317     {
1318       extern int *insn_addresses;
1319       fprintf (asm_out_file, "\n! at %04x\n",
1320                insn_addresses[INSN_UID (insn)]);
1321     }
1322 }
1323 \f
1324
1325
1326
1327 /* Stuff taken from m88k.c */
1328
1329 /* Output to FILE the start of the assembler file.  */
1330
1331 struct option
1332 {
1333   char *string;
1334   int *variable;
1335   int on_value;
1336 };
1337
1338 static int
1339 output_option (file, sep, type, name, indent, pos, max)
1340      FILE *file;
1341      char *sep;
1342      char *type;
1343      char *name;
1344      char *indent;
1345      int pos;
1346      int max;
1347 {
1348   if (strlen (sep) + strlen (type) + strlen (name) + pos > max)
1349     {
1350       fprintf (file, indent);
1351       return fprintf (file, "%s%s", type, name);
1352     }
1353   return pos + fprintf (file, "%s%s%s", sep, type, name);
1354 }
1355
1356 static struct
1357 {
1358   char *name;
1359   int value;
1360 }
1361
1362 m_options[] = TARGET_SWITCHES;
1363
1364 static void
1365 output_options (file, f_options, f_len, W_options, W_len,
1366                 pos, max, sep, indent, term)
1367      FILE *file;
1368      struct option *f_options;
1369      struct option *W_options;
1370      int f_len, W_len;
1371      int pos;
1372      int max;
1373      char *sep;
1374      char *indent;
1375      char *term;
1376 {
1377   register int j;
1378
1379
1380   if (optimize)
1381     pos = output_option (file, sep, "-O", "", indent, pos, max);
1382   if (write_symbols != NO_DEBUG)
1383     pos = output_option (file, sep, "-g", "", indent, pos, max);
1384   if (flag_traditional)
1385     pos = output_option (file, sep, "-traditional", "", indent, pos, max);
1386   if (profile_flag)
1387     pos = output_option (file, sep, "-p", "", indent, pos, max);
1388   if (profile_block_flag)
1389     pos = output_option (file, sep, "-a", "", indent, pos, max);
1390
1391   for (j = 0; j < f_len; j++)
1392     if (*f_options[j].variable == f_options[j].on_value)
1393       pos = output_option (file, sep, "-f", f_options[j].string,
1394                            indent, pos, max);
1395
1396   for (j = 0; j < W_len; j++)
1397     if (*W_options[j].variable == W_options[j].on_value)
1398       pos = output_option (file, sep, "-W", W_options[j].string,
1399                            indent, pos, max);
1400
1401   for (j = 0; j < sizeof m_options / sizeof m_options[0]; j++)
1402     if (m_options[j].name[0] != '\0'
1403         && m_options[j].value > 0
1404         && ((m_options[j].value & target_flags)
1405             == m_options[j].value))
1406       pos = output_option (file, sep, "-m", m_options[j].name,
1407                            indent, pos, max);
1408
1409
1410   fprintf (file, term);
1411   fprintf (file, "! %d %d\n", max_count_si, max_count_hi);
1412
1413   if (TARGET_LITTLE_ENDIAN)
1414     fprintf (file, "\t.little\n");
1415 }
1416
1417 void
1418 output_file_start (file, f_options, f_len, W_options, W_len)
1419      FILE *file;
1420      struct option *f_options;
1421      struct option *W_options;
1422      int f_len, W_len;
1423 {
1424   register int pos;
1425
1426   output_file_directive (file, main_input_filename);
1427
1428   /* Switch to the data section so that the coffsem symbol and the
1429      gcc2_compiled. symbol aren't in the text section.  */
1430   data_section ();
1431
1432
1433   pos = fprintf (file, "\n! Hitachi SH cc1 (%s) arguments:", version_string);
1434   output_options (file, f_options, f_len, W_options, W_len,
1435                   pos, 75, " ", "\n! ", "\n\n");
1436 }
1437 \f
1438
1439 /* Actual number of instructions used to make a shift by N */
1440 char ashiftrt_insns[] = { 0,1,2,3,4,5,8,8,8,8,8,8,8,8,8,8,2,3,4,5,8,8,8,8,8,8,8,8,8,8,8,2};
1441 char lshiftrt_insns[] = { 0,1,1,2,2,3,3,4,1,2,2,3,3,4,4,5,1,2,2,3,3,4,4,5,2,3,3,4,4,5,5,6};
1442 char shift_insns[]    = { 0,1,1,2,2,3,3,4,1,2,2,3,3,4,4,5,1,2,2,3,3,4,4,5,2,3,3,4,4,5,5,6};
1443
1444 int 
1445 shiftinsns (shift, n)
1446 enum rtx_code shift;
1447 int n;
1448 {
1449   switch (shift) 
1450     {
1451     case ASHIFTRT:
1452       return ashiftrt_insns[n];
1453     case LSHIFTRT:
1454       return lshiftrt_insns[n];
1455     case ASHIFT:
1456       return shift_insns[n];
1457     default:
1458       abort();
1459     }
1460 }
1461
1462
1463
1464 /* Return the cost of a shift */
1465
1466 int
1467 shiftcosts (RTX)
1468      rtx RTX;
1469 {
1470   /* If shift by a non constant, then this will be expensive. */
1471   if (GET_CODE (XEXP (RTX, 1)) != CONST_INT) 
1472     {
1473       return 20;
1474     }
1475
1476   /* otherwise, it will be very cheap if by one of the constants
1477      we can cope with. */
1478
1479   if (CONST_OK_FOR_K (INTVAL (XEXP (RTX, 1))))
1480     return 1;
1481   /* otherwise it will be several insns, but we pretend that it will be more than
1482      just the components, so that combine doesn't glue together a load of shifts into
1483      one shift which has to be emitted as a bunch anyway - breaking scheduling */
1484   return 1;
1485 }
1486
1487 int
1488 andcosts (RTX)
1489      rtx RTX;
1490 {
1491   int i;
1492   if (GET_CODE (XEXP (RTX, 1)) != CONST_INT)
1493     return 2;
1494   i = INTVAL (XEXP (RTX, 1));
1495   /* And can use the extend insns cheaply */
1496   if (i == 0xff || i == 0xffff)
1497     return 2;
1498   /* Any small constant is reasonably cheap - but requires r0 */
1499   if (CONST_OK_FOR_I (i))
1500     return 3;
1501   return 5;
1502 }
1503
1504 int 
1505 howshift (i)
1506      int i;
1507 {
1508   int total = 0;
1509   while (i > 0)
1510     {
1511       if (i >= 16)
1512         {
1513           total++;
1514           i -= 16;
1515         }
1516       else if (i >= 8)
1517         {
1518           total++;
1519           i -= 8;
1520         }
1521       else if (i >= 2)
1522         {
1523           total++;
1524           i -= 2;
1525         }
1526       else if (i >= 1)
1527         {
1528           total++;
1529           i--;
1530         }
1531     }
1532   return total;
1533 }
1534
1535 /* Return the cost of a multiply */
1536 int
1537 multcosts (RTX)
1538      rtx RTX;
1539 {
1540   if (TARGET_SH2)
1541     {
1542       /* We have a mul insn, so we can never take more than the mul and the
1543          read of the mac reg, but count more because of the latency and extra
1544          reg usage */
1545       if (TARGET_SMALLCODE)
1546         return 2;
1547       return 3;
1548     }
1549
1550   /* If we're aiming at small code, then just count the number of
1551      insns in a multiply call sequence */
1552   if (TARGET_SMALLCODE)
1553     return 6;
1554
1555   /* Otherwise count all the insns in the routine we'd be calling too */
1556   return 20;
1557 }
1558
1559 /* Code to expand a shift */
1560
1561 void
1562 gen_ashift (type, n, reg)
1563      int type;
1564      int n;
1565      rtx reg;
1566 {
1567   switch (type)
1568     {
1569     case ASHIFTRT:
1570       emit_insn (gen_ashrsi3_k (reg, reg, GEN_INT (n)));
1571       break;
1572     case LSHIFTRT:
1573       emit_insn (gen_lshrsi3_k (reg, reg, GEN_INT (n)));
1574       break;
1575     case ASHIFT:
1576       if (n == 1)
1577         emit_insn (gen_addsi3 (reg, reg, reg));
1578       else
1579         emit_insn (gen_ashlsi3_k (reg, reg, GEN_INT (n)));
1580       break;
1581     }
1582 }
1583
1584 int
1585 gen_shifty_op (code, operands)
1586      int code;
1587      rtx *operands;
1588 {
1589   rtx wrk = gen_reg_rtx (SImode);
1590   rtx t;
1591   char *func;
1592
1593   if (GET_CODE (operands[2]) == CONST_INT)
1594     {
1595       int value = INTVAL (operands[2]);
1596     top:
1597
1598       switch (code)
1599         {
1600         case ASHIFTRT:
1601           if (value < 0)
1602             {
1603               code = ASHIFT;
1604               value = -value;
1605               goto top;
1606             }
1607           if (value == 31)
1608             {
1609               emit_insn (gen_ashrsi2_31 (operands[0], operands[1]));
1610               return 1;
1611             }
1612           else if (value >= 16 && value <= 19) 
1613             {
1614               emit_insn (gen_ashrsi2_16 (wrk, operands[1]));
1615               value -= 16;
1616               while (value --)
1617                 gen_ashift (ASHIFTRT,1, wrk);
1618               emit_move_insn (operands[0], wrk);
1619               return 1;
1620             }     
1621           /* Expand a short sequence inline, longer call a magic routine */
1622           if (value <= 5)
1623             {
1624               emit_move_insn (wrk, operands[1]);
1625               while (value--)
1626                 {
1627                   gen_ashift (ASHIFTRT, 1, wrk);
1628                 }
1629               emit_move_insn (operands[0], wrk);
1630               return 1;
1631             }
1632           t = gen_reg_rtx (Pmode);
1633           /*  Load the value into an arg reg and call a helper */
1634           emit_move_insn (gen_rtx (REG, SImode, 4), operands[1]);
1635           if (!shiftsyms[value])
1636             {
1637               func = xmalloc (18);
1638               sprintf (func, "__ashiftrt_r4_%d", value);
1639               shiftsyms[value] = gen_rtx (SYMBOL_REF, Pmode, func);
1640             }
1641           emit_move_insn (t, shiftsyms[value]);
1642           emit_insn (gen_ashrsi3_n (GEN_INT (value), t));
1643           emit_move_insn (operands[0], gen_rtx (REG, SImode, 4));
1644           return 1;
1645
1646         case ASHIFT:
1647           if (value < 0)
1648             {
1649               code = LSHIFTRT;
1650               value = -value;
1651               goto top;
1652             }
1653           /* Fall through */
1654         case LSHIFTRT:
1655
1656           if (value < 0)
1657             {
1658               code = ASHIFT;
1659               value = -value;
1660               goto top;
1661             }
1662
1663           emit_move_insn (wrk, operands[1]);
1664           while (value)
1665             {
1666               if (value >= 16)
1667                 {
1668                   gen_ashift (code, 16, wrk);
1669                   value -= 16;
1670                 }
1671               else if (value >= 8)
1672                 {
1673                   gen_ashift (code, 8, wrk);
1674                   value -= 8;
1675                 }
1676               else if (value >= 2)
1677                 {
1678                   gen_ashift (code, 2, wrk);
1679                   value -= 2;
1680                 }
1681               else
1682                 {
1683                   gen_ashift (code, 1, wrk);
1684                   value--;
1685                 }
1686             }
1687           emit_move_insn (operands[0], wrk);
1688           return 1;
1689
1690         }
1691     }
1692
1693   return 0;
1694 }
1695
1696 /* Dump out any constants accumulated in the final pass -
1697    which will only be labels */
1698 char *
1699 output_jump_label_table ()
1700 {
1701   int i;
1702   if (pool_size)
1703     {
1704       fprintf (asm_out_file, "\t.align 2\n");
1705       for (i = 0; i < pool_size; i++)
1706         {
1707           pool_node *p = pool_vector + i;
1708
1709           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (p->label));
1710           output_asm_insn (".long       %O0", &p->value);
1711         }
1712       pool_size = 0;
1713     }
1714
1715   return "";
1716 }
1717 /* Output the literal table */
1718
1719 static void
1720 dump_table (scan)
1721      rtx scan;
1722 {
1723   int i;
1724   int need_align = 1;
1725
1726
1727   /* Do two passes, first time dump out the HI sized constants */
1728
1729   for (i = 0; i < pool_size; i++)
1730     {
1731       pool_node *p = pool_vector + i;
1732       if (p->mode == HImode)
1733         {
1734           if (need_align)
1735             {
1736               scan = emit_insn_after (gen_align_2 (), scan);
1737               need_align = 0;
1738             }
1739           scan = emit_label_after (p->label, scan);
1740           scan = emit_insn_after (gen_consttable_2 (p->value), scan);
1741         }
1742     }
1743   need_align = 1;
1744
1745   for (i = 0; i < pool_size; i++)
1746     {
1747       pool_node *p = pool_vector + i;
1748
1749       switch (p->mode)
1750         {
1751         case HImode:
1752           break;
1753         case SImode:
1754           if (need_align)
1755             {
1756               need_align = 0;
1757               scan = emit_label_after (gen_label_rtx (), scan);
1758               scan = emit_insn_after (gen_align_4 (), scan);
1759             }
1760           scan = emit_label_after (p->label, scan);
1761           scan = emit_insn_after (gen_consttable_4 (p->value), scan);
1762           break;
1763         case DImode:
1764           if (need_align)
1765             {
1766               need_align = 0;
1767               scan = emit_label_after (gen_label_rtx (), scan);
1768               scan = emit_insn_after (gen_align_4 (), scan);
1769             }
1770           scan = emit_label_after (p->label, scan);
1771           scan = emit_insn_after (gen_consttable_8 (p->value), scan);
1772           break;
1773         default:
1774           abort ();
1775           break;
1776         }
1777     }
1778
1779   scan = emit_insn_after (gen_consttable_end (), scan);
1780   scan = emit_barrier_after (scan);
1781   pool_size = 0;
1782 }
1783
1784
1785
1786 /* Non zero if the src operand needs to be fixed up */
1787 static
1788 int
1789 fixit (src, mode)
1790      rtx src;
1791      enum machine_mode mode;
1792 {
1793   if (mode == QImode)
1794     return 0;                   /* QIs never need to be fixed */
1795   if (GET_CODE (src) == CONST)
1796     return 1;
1797
1798   if (GET_CODE (src) == SYMBOL_REF)
1799     {
1800       return 1;
1801     }
1802   if (GET_CODE (src) == LABEL_REF)
1803     {
1804       return 1;
1805     }
1806   if (GET_CODE (src) == CONST_INT)
1807     {
1808       /* All QI insns are ok */
1809       if (mode == QImode)
1810         return 1;
1811       /* The rest may need to be fixed */
1812       return !CONST_OK_FOR_I (INTVAL (src));
1813     }
1814   return 0;
1815 }
1816
1817 /* Return Non-zero if constant would be an ok source for a
1818    mov.w instead of a mov.l */
1819 int
1820 hi_const (src)
1821      rtx src;
1822 {
1823   if (GET_CODE (src) == CONST
1824       && GET_CODE (XEXP (src, 0)) == SIGN_EXTEND
1825       && GET_CODE (XEXP (XEXP (src, 0), 0)) == SYMBOL_REF)
1826     return 1;
1827
1828   if (TARGET_SHORTADDR
1829       && GET_CODE (src) == SYMBOL_REF)
1830     return 1;
1831
1832   return (GET_CODE (src) == CONST_INT
1833           && INTVAL (src) >= -32768
1834           && INTVAL (src) <= 32767);
1835 }
1836
1837 /* Find the last barrier less than MAX_COUNT bytes from FROM, or create one.
1838    If an HI move is found, then make sure that MAX_COUNT_HI isn't broken from that one. */
1839
1840 static
1841 rtx
1842 find_barrier (from)
1843      rtx from;
1844 {
1845   int count_si = 0;
1846   int count_hi = 0;
1847   int found_hi = 0;
1848   int found_si = 0;
1849   rtx found_barrier = 0;
1850   while (from
1851          && count_si < max_count_si
1852          && count_hi < max_count_hi)
1853     {
1854       int inc;
1855       if (GET_CODE (from) == BARRIER)
1856         {
1857           found_barrier = from;
1858         }
1859       /* Count the length of this insn - we assume that all moves will
1860          be 2 bytes long, except the DIs */
1861
1862       if (GET_CODE (from) == INSN &&
1863           GET_CODE (PATTERN (from)) == SET)
1864         {
1865           rtx src = SET_SRC (PATTERN (from));
1866           if (hi_const (src))
1867             found_hi = 1;
1868           else
1869             found_si = 1;
1870           inc = (GET_MODE_SIZE (GET_MODE (src)) > 4) ? 4 : 2;
1871         }
1872       else
1873         {
1874           inc = get_attr_length (from);
1875         }
1876       if (found_si)
1877         count_si += inc;
1878       if (found_hi)
1879         count_hi += inc;
1880       from = NEXT_INSN (from);
1881     }
1882
1883   if (!found_barrier)
1884     {
1885       /* We didn't find a barrier in time to 
1886          dump our stuff, so we'll make one */
1887       rtx label = gen_label_rtx ();
1888       /* Walk back to be just before any jump */
1889       from = PREV_INSN (from);
1890       while (GET_CODE (from) == JUMP_INSN
1891              || GET_CODE (from) == NOTE
1892              || GET_CODE (from) == CODE_LABEL)
1893         {
1894           from = PREV_INSN (from);
1895         }
1896       from = emit_jump_insn_after (gen_jump (label), from);
1897       JUMP_LABEL (from) = label;
1898       found_barrier = emit_barrier_after (from);
1899       emit_label_after (label, found_barrier);
1900       return found_barrier;
1901     }
1902   return found_barrier;
1903 }
1904
1905 /* Non zero if the insn is a move instruction which needs to be fixed. */
1906
1907 static
1908 int
1909 broken_move (insn)
1910      rtx insn;
1911 {
1912   if (!INSN_DELETED_P (insn)
1913       && GET_CODE (insn) == INSN
1914       && GET_CODE (PATTERN (insn)) == SET)
1915     {
1916       rtx pat = PATTERN (insn);
1917       rtx src = SET_SRC (pat);
1918       rtx dst = SET_DEST (pat);
1919       enum machine_mode mode = GET_MODE (dst);
1920       if (dst == pc_rtx)
1921         return 0;
1922       return fixit (src, mode);
1923     }
1924   return 0;
1925 }
1926
1927
1928 /* Exported to toplev.c
1929
1930    Scan the function looking for move instructions which have to be changed to
1931    pcrel loads and insert the literal tables. */
1932
1933 void
1934 machine_dependent_reorg (first)
1935      rtx first;
1936 {
1937   rtx insn;
1938   for (insn = first; insn; insn = NEXT_INSN (insn))
1939     {
1940       if (broken_move (insn))
1941         {
1942           /* This is a broken move instruction, scan ahead looking for
1943              a barrier to stick the constant table behind */
1944           rtx scan;
1945           rtx barrier = find_barrier (insn);
1946
1947           /* Now find all the moves between the points and modify them */
1948           for (scan = insn; scan != barrier; scan = NEXT_INSN (scan))
1949             {
1950               if (broken_move (scan))
1951                 {
1952                   rtx pat = PATTERN (scan);
1953                   rtx src = SET_SRC (pat);
1954                   rtx dst = SET_DEST (pat);
1955                   enum machine_mode mode = GET_MODE (dst);
1956                   rtx lab;
1957                   rtx newinsn;
1958                   rtx newsrc;
1959                   /* This is a broken move instruction, add it to the pool */
1960
1961                   if (mode == SImode && hi_const (src))
1962                     {
1963                       /* This is an HI source, clobber the dest to get the mode right too */
1964                       int offset = 0;
1965                       mode = HImode;
1966                       while (GET_CODE (dst) == SUBREG)
1967                         {
1968                           offset += SUBREG_WORD (dst);
1969                           dst = SUBREG_REG (dst);
1970                         }
1971                       dst = gen_rtx (REG, HImode, REGNO (dst) + offset);
1972                     }
1973                   lab = add_constant (src, mode);
1974                   newsrc = gen_rtx (MEM, mode,
1975                                     gen_rtx (LABEL_REF, VOIDmode, lab));
1976
1977                   /* Build a jump insn wrapper around the move instead
1978                      of an ordinary insn, because we want to have room for
1979                      the target label rtx in fld[7], which an ordinary
1980                      insn doesn't have. */
1981                   newinsn = emit_jump_insn_after (gen_rtx (SET, VOIDmode,
1982                                                         dst, newsrc), scan);
1983                   JUMP_LABEL (newinsn) = lab;
1984
1985                   /* But it's still an ordinary insn */
1986                   PUT_CODE (newinsn, INSN);
1987
1988                   /* Kill old insn */
1989                   delete_insn (scan);
1990                   scan = newinsn;
1991                 }
1992             }
1993           dump_table (barrier);
1994         }
1995     }
1996 }
1997
1998 /* Called from the md file, set up the operands of a compare instruction */
1999
2000 void
2001 from_compare (operands, code)
2002      rtx *operands;
2003      int code;
2004 {
2005   if (code != EQ && code != NE)
2006     {
2007       /* Force args into regs, since we can't use constants here */
2008       sh_compare_op0 = force_reg (SImode, sh_compare_op0);
2009       if (sh_compare_op1 != const0_rtx)
2010         sh_compare_op1 = force_reg (SImode, sh_compare_op1);
2011     }
2012   operands[1] = sh_compare_op0;
2013   operands[2] = sh_compare_op1;
2014 }
2015
2016 /* Non-zero if x is EQ or NE */
2017
2018 int
2019 equality_operator (x, mode)
2020      rtx x;
2021      enum machine_mode mode;
2022 {
2023   enum rtx_code code = GET_CODE (x);
2024   return (code == EQ || code == NE);
2025 }
2026
2027
2028 /* Add this function to the list of ones seen - temporary
2029    gross hack to try out bsrs. */
2030 struct flist
2031 {
2032   char *name;
2033   struct flist *next;
2034 };
2035 struct flist *head;
2036
2037 static void
2038 add_function (name)
2039      char *name;
2040 {
2041   struct flist *n = (struct flist *) xmalloc (sizeof (struct flist));
2042   int l = strlen (name) + 1;
2043   n->name = xmalloc (l);
2044   memcpy (n->name, name, l);
2045   n->next = head;
2046   head = n;
2047 }
2048
2049 static int
2050 seen_function (name)
2051      char *name;
2052 {
2053   struct flist *p = head;
2054   for (p = head; p; p = p->next)
2055     {
2056       if (strcmp (p->name, name) == 0)
2057         return 1;
2058     }
2059   return 0;
2060 }
2061
2062  /* Framefull frame looks like:
2063
2064     arg-5
2065     arg-4
2066     [ if current_function_anonymous_args
2067     arg-3
2068     arg-2
2069     arg-1
2070     arg-0 ]
2071     saved-fp
2072     saved-r10
2073     saved-r11
2074     saved-r12
2075     saved-pr
2076     local-n
2077     ..
2078     local-1
2079     local-0        <- fp points here
2080
2081
2082     If TARGET_SMALLCALL, then the preserved registers are pushed by a
2083     wrapper before the routine is entered, so the regs are always pushed
2084     and there are two pr's on the stack - the caller and the wrapper.
2085   */
2086
2087
2088  /* Code to generate prologue and epilogue sequences */
2089
2090
2091 void
2092 sh_expand_prologue ()
2093 {
2094   int live_regs_mask;
2095   int d, i;
2096   extern tree current_function_decl;
2097   live_regs_mask = calc_live_regs (&d);
2098
2099   /* We have pretend args if we had an object sent partially in registers
2100      and partially on the stack - eg a large structure */
2101   output_stack_adjust (-current_function_pretend_args_size);
2102
2103   extra_push = 0;
2104
2105   /* This is set by SETUP_VARARGS to indicate that this is a varargs
2106      routine.  Clear it here so that the next function isn't affected.  */
2107   if (current_function_anonymous_args)
2108     {
2109       current_function_anonymous_args = 0;
2110
2111       /* Push arg regs as if they'd been provided by caller in stack */
2112       for (i = 0; i < NPARM_REGS; i++)
2113         {
2114           int rn = NPARM_REGS + FIRST_PARM_REG - i - 1;
2115           if (i > NPARM_REGS - current_function_args_info)
2116             break;
2117           push (rn);
2118           extra_push += 4;
2119         }
2120     }
2121   push_regs (live_regs_mask);
2122   output_stack_adjust (-get_frame_size ());
2123
2124   if (frame_pointer_needed)
2125     {
2126       emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
2127     }
2128   if (TARGET_BSR)
2129     {
2130       add_function (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
2131     }
2132
2133   /* ??? Hack.  Clear out the table set up by gen_shifty_op since this
2134      info does not apply to the next function.  */
2135   for (i = 0; i < 32; i++)
2136     shiftsyms[i] = 0;
2137 }
2138
2139 void
2140 sh_expand_epilogue ()
2141 {
2142   int live_regs_mask;
2143   int d, i;
2144
2145   live_regs_mask = calc_live_regs (&d);
2146   
2147   if (frame_pointer_needed)
2148     {
2149       emit_insn (gen_movsi (stack_pointer_rtx, frame_pointer_rtx));
2150     }
2151   output_stack_adjust (get_frame_size ());
2152
2153   /* Pop all the registers */
2154
2155   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2156     {
2157       int j = (FIRST_PSEUDO_REGISTER - 1) - i;
2158       if (live_regs_mask & (1 << j))
2159         {
2160           pop (j);
2161         }
2162     }
2163
2164   output_stack_adjust (extra_push + current_function_pretend_args_size);
2165 }
2166
2167 /* Define the offset between two registers, one to be eliminated, and
2168    the other its replacement, at the start of a routine.  */
2169
2170 int
2171 initial_elimination_offset (from, to)
2172      int from;
2173      int to;
2174 {
2175   int regs_saved;
2176   int total_saved_regs_space;
2177   int total_auto_space = get_frame_size ();
2178
2179   calc_live_regs (&regs_saved);
2180   total_saved_regs_space = (regs_saved) * 4;
2181
2182   if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
2183     {
2184       return total_saved_regs_space + total_auto_space;
2185     }
2186   if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
2187     {
2188       return total_saved_regs_space + total_auto_space;
2189     }
2190   if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
2191     {
2192       /* Initial gap between fp and sp is 0 */
2193       return 0;
2194     }
2195   abort ();
2196 }
2197
2198 /* Handle machine specific pragmas to be semi-compatible with Hitachi
2199    compiler  */
2200
2201 int
2202 handle_pragma (file)
2203      FILE *file;
2204 {
2205   int c;
2206   char pbuf[200];
2207   int psize = 0;
2208
2209   c = getc (file);
2210   while (c == ' ' || c == '\t')
2211     c = getc (file);
2212
2213   if (c == '\n' || c == EOF)
2214     return c;
2215
2216   while (psize < sizeof (pbuf) - 1 && c != '\n')
2217     {
2218       pbuf[psize++] = c;
2219       if (psize == 9 && strncmp (pbuf, "interrupt", 9) == 0)
2220         {
2221           pragma_interrupt = 1;
2222           return ' ';
2223         }
2224       if (psize == 5 && strncmp (pbuf, "trapa", 5) == 0)
2225         {
2226           pragma_interrupt = pragma_trapa = 1;
2227           return ' ';
2228         }
2229       c = getc (file);
2230     }
2231   return c;
2232 }
2233 \f
2234 /* insn expand helpers */
2235
2236 /* Emit insns to perform a call.
2237    If TARGET_SHORTADDR then use a bsr. If TARGET_SMALLCALL, then load the
2238    target address into r1 and call __saveargs, otherwise
2239    perform the standard call sequence */
2240
2241 void
2242 expand_acall (isa_retval, operands)
2243      int isa_retval;
2244      rtx *operands;
2245 {
2246   rtx call;
2247   rtx ret = operands[0];
2248   rtx call_target = operands[isa_retval + 0];
2249   rtx numargs = operands[isa_retval + 1];
2250
2251   if (TARGET_BSR && bsr_operand (call_target, VOIDmode))
2252     {
2253       call = gen_rtx (CALL, VOIDmode, call_target, numargs);
2254     }
2255   else
2256     {
2257       if (GET_CODE (call_target) == MEM)
2258         {
2259           call_target = force_reg (Pmode,
2260                                    XEXP (call_target, 0));
2261         }
2262       if (TARGET_SMALLCALL)
2263         {
2264           rtx tmp = gen_reg_rtx (SImode);
2265           rtx r1 = gen_rtx (REG, SImode, 1);
2266           emit_move_insn (tmp, gen_rtx (SYMBOL_REF, SImode, "__saveargs"));
2267           emit_move_insn (r1, call_target);
2268           emit_insn (gen_rtx (USE, VOIDmode, r1));
2269           call_target = tmp;
2270         }
2271
2272       call = gen_rtx (CALL, VOIDmode, gen_rtx (MEM, SImode, call_target), numargs);
2273     }
2274   if (isa_retval)
2275     {
2276       call = gen_rtx (SET, VOIDmode, ret, call);
2277     }
2278
2279   emit_call_insn (gen_rtx (PARALLEL, VOIDmode,
2280                            gen_rtvec (2,
2281                                       call,
2282                   gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, SImode, 17)))));
2283
2284 }
2285 \f
2286
2287 /* Predicates used by the templates */
2288
2289
2290 /* Returns 1 if OP can be source of a simple move operation.
2291    Same as general_operand, but a LABEL_REF is valid, PRE_DEC is
2292    invalid as are subregs of system registers. */
2293
2294 int
2295 general_movsrc_operand (op, mode)
2296      rtx op;
2297      enum machine_mode mode;
2298 {
2299   /* Any MEM(label_ref) is ok, that's a pcrel load */
2300   if (GET_CODE (op) == MEM
2301       && GET_CODE (XEXP (op, 0)) == LABEL_REF)
2302     return 1;
2303
2304   if (GET_CODE (op) == MEM)
2305     {
2306       rtx inside = XEXP (op, 0);
2307       if (GET_CODE (inside) == CONST)
2308         inside = XEXP (inside, 0);
2309
2310       if (GET_CODE (inside) == LABEL_REF)
2311         return 1;
2312
2313       if (GET_CODE (inside) == PLUS
2314           && GET_CODE (XEXP (inside,0)) == LABEL_REF
2315           && GET_CODE (XEXP (inside,1)) == CONST_INT)
2316         return 1;
2317       
2318       /* No post inc allowed */
2319       if (GET_CODE (inside) == POST_DEC
2320           || GET_CODE (inside) == PRE_INC
2321           || GET_CODE (inside) == PRE_DEC)
2322         return 0;
2323
2324       /* Can't do that with large modes */
2325       if (GET_CODE (inside) == POST_INC
2326           && GET_MODE_SIZE (mode) > 4)
2327         return 0;
2328     }
2329
2330   if ((mode == QImode || mode == HImode)
2331       && (GET_CODE (op) == SUBREG
2332           && GET_CODE (XEXP (op, 0)) == REG
2333           && system_reg_operand (XEXP (op, 0), mode)))
2334     return 0;
2335
2336   if (GET_CODE (op) == CONST_INT)
2337     {
2338       int i = INTVAL (op);
2339       return CONST_OK_FOR_I (i);
2340     }
2341   return general_operand (op, mode);
2342 }
2343
2344
2345 /* Returns 1 if OP can be a destination of a move.
2346    Same as general_operand, but no preinc allowed.  */
2347
2348 int
2349 general_movdst_operand (op, mode)
2350      rtx op;
2351      enum machine_mode mode;
2352 {
2353   /* No pre dec allowed */
2354   if (GET_CODE (op) == MEM
2355       && (GET_CODE (XEXP (op, 0)) == PRE_INC
2356           || GET_CODE (XEXP (op, 0)) == POST_INC
2357           || GET_CODE (XEXP (op, 0)) == POST_DEC))
2358     return 0;
2359
2360   if (GET_CODE (op) == MEM
2361       && GET_CODE (XEXP (op, 0)) == PRE_DEC
2362       && GET_MODE_SIZE (mode) > 4)
2363     return 0;
2364
2365   return general_operand (op, mode);
2366 }
2367
2368
2369
2370 /* Returns 1 if OP is valid destination for a bsr.  */
2371
2372 int
2373 bsr_operand (op, mode)
2374      rtx op;
2375      enum machine_mode mode;
2376 {
2377   if (TARGET_BSR)
2378     {
2379       if (GET_CODE (op) == SYMBOL_REF)
2380         {
2381           if (!strcmp (XSTR (op, 0),
2382                       IDENTIFIER_POINTER (DECL_NAME (current_function_decl))))
2383             return 1;
2384           return (seen_function (XSTR (op, 0)));
2385         }
2386     }
2387   return 0;
2388 }
2389
2390 /* Returns 1 if OP is an immediate ok for a byte index.  */
2391
2392 int
2393 byte_index_operand (op, mode)
2394      rtx op;
2395      enum machine_mode mode;
2396 {
2397   return (GET_CODE (op) == CONST_INT
2398           && INTVAL (op) >= 0
2399           && INTVAL (op) <= 15);
2400 }
2401
2402 /* Returns 1 if OP is a pop operand.   */
2403
2404 int
2405 pop_operand (op, mode)
2406      rtx op;
2407      enum machine_mode mode;
2408 {
2409   if (GET_CODE (op) != MEM)
2410     return 0;
2411
2412   if (GET_MODE (op) != mode)
2413     return 0;
2414
2415   op = XEXP (op, 0);
2416
2417   if (GET_CODE (op) != POST_INC)
2418     return 0;
2419
2420   return XEXP (op, 0) == stack_pointer_rtx;
2421 }
2422
2423
2424 /* Returns 1 if OP is a normal arithmetic register.  */
2425
2426 int
2427 arith_reg_operand (op, mode)
2428      rtx op;
2429      enum machine_mode mode;
2430 {
2431   if (register_operand (op, mode))
2432     {
2433       if (GET_CODE (op) == REG)
2434         return (REGNO (op) != T_REG
2435                 && REGNO (op) != PR_REG
2436                 && REGNO (op) != MACH_REG
2437                 && REGNO (op) != MACL_REG);
2438       return 1;
2439     }
2440   return 0;
2441 }
2442
2443 /* Returns 1 if OP is MACL, MACH or PR.  */
2444
2445 int
2446 system_reg_operand (op, mode)
2447      rtx op;
2448      enum machine_mode mode;
2449 {
2450   if (GET_CODE (op) == REG)
2451     {
2452       switch (REGNO (op))
2453         {
2454         case PR_REG:
2455         case MACL_REG:
2456         case MACH_REG:
2457           return 1;
2458         }
2459     }
2460   return 0;
2461 }
2462
2463
2464 /* Returns 1 if OP is a valid source operand for an arithmetic insn.  */
2465
2466 int
2467 arith_operand (op, mode)
2468      rtx op;
2469      enum machine_mode mode;
2470 {
2471   if (arith_reg_operand (op, mode))
2472     return 1;
2473
2474   if (GET_CODE (op) == CONST_INT)
2475     {
2476       if (CONST_OK_FOR_I (INTVAL (op)))
2477         return 1;
2478     }
2479   return 0;
2480 }
2481
2482
2483 /* Returns 1 if OP is a valid count operand for a shift operation. */
2484 int 
2485 shiftby_operand (op, mode)
2486      rtx op;
2487      enum machine_mode mode;
2488 {
2489   if (immediate_operand (op, mode)) 
2490     return 1;
2491   return 0;
2492 }
2493
2494 /* Returns 1 if OP is a valid source operand for a logical operation. */
2495
2496 int
2497 logical_operand (op, mode)
2498      rtx op;
2499      enum machine_mode mode;
2500 {
2501   if (arith_reg_operand (op, mode))
2502     return 1;
2503
2504   if (GET_CODE (op) == CONST_INT)
2505     {
2506       if (CONST_OK_FOR_L (INTVAL (op)))
2507         return 1;
2508     }
2509   return 0;
2510 }
2511
2512 /* Returns 1 if OP is a valid operand for a MAC instruction,
2513    either a register or indirect memory.  For now we don't
2514    try and recognise a mac insn */
2515
2516 int
2517 mac_operand (op, mode)
2518      rtx op;
2519      enum machine_mode mode;
2520 {
2521   if (arith_reg_operand (op, mode))
2522     return 1;
2523 #if 0
2524   Turned off till mac is understood
2525   if (GET_CODE (op) == MEM)
2526     return 1;
2527 #endif
2528   return 0;
2529 }
2530
2531 /* Determine where to put an argument to a function.
2532    Value is zero to push the argument on the stack,
2533    or a hard register in which to store the argument.
2534
2535    MODE is the argument's machine mode.
2536    TYPE is the data type of the argument (as a tree).
2537     This is null for libcalls where that information may
2538     not be available.
2539    CUM is a variable of type CUMULATIVE_ARGS which gives info about
2540     the preceding args and about the function being called.
2541    NAMED is nonzero if this argument is a named parameter
2542     (otherwise it is an extra parameter matching an ellipsis).  */
2543
2544 rtx
2545 sh_function_arg (cum, mode, type, named)
2546      CUMULATIVE_ARGS cum;
2547      enum machine_mode mode;
2548      tree type;
2549      int named;
2550 {
2551   if (named)
2552     {
2553       int rr = (ROUND_REG ((cum), (mode)));
2554
2555       if (rr < NPARM_REGS)
2556         {
2557           return (((type) == 0 || !TREE_ADDRESSABLE ((tree) (type)))
2558                   && ((type) == 0 || (mode) != BLKmode
2559                       || (TYPE_ALIGN ((type)) % PARM_BOUNDARY == 0))
2560                   ? gen_rtx (REG, (mode),
2561                              (FIRST_PARM_REG + rr)) 
2562                   : 0);
2563
2564         }
2565     }
2566   return 0;
2567 }
2568
2569 /* For an arg passed partly in registers and partly in memory,
2570    this is the number of registers used.
2571    For args passed entirely in registers or entirely in memory, zero.
2572    Any arg that starts in the first 4 regs but won't entirely fit in them
2573    needs partial registers on the SH.  */
2574
2575 int
2576 sh_function_arg_partial_nregs (CUM, MODE, TYPE, NAMED)
2577      CUMULATIVE_ARGS CUM;
2578      enum machine_mode MODE;
2579      tree TYPE;
2580      int NAMED;
2581 {
2582   if ((CUM) < NPARM_REGS)
2583     {
2584       if (((TYPE) == 0 || !TREE_ADDRESSABLE ((tree) (TYPE)))
2585           && ((TYPE) == 0 || (TYPE_ALIGN ((TYPE)) % PARM_BOUNDARY == 0))
2586           && ((CUM) + ((MODE) == BLKmode
2587                        ? ROUND_ADVANCE (int_size_in_bytes (TYPE))
2588                   : ROUND_ADVANCE (GET_MODE_SIZE (MODE))) - NPARM_REGS > 0))
2589         {
2590           return NPARM_REGS - CUM;
2591         }
2592     }
2593   return 0;
2594 }
2595
2596
2597
2598 /* Turn this on to recognise shift insns which aren't supported in the
2599    hardware.  This will allow the combiner to notice more patterns,
2600    but the down side is that the asm outputter will have to emit
2601    several instructions for each shift which isn't possible in the
2602    hardware, this makes scheduling perform badly .*/ 
2603
2604 int fake_shift()
2605 {
2606   return 0;
2607 }
2608