OSDN Git Service

Correct errors in comments.
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / sh.h
1 /* Definitions of target machine for GNU compiler, 
2    for Hitachi Super-H.
3    Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4
5    Contributed by Steve Chamberlain (sac@cygnus.com)
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
22
23 \f
24 /* Run-time Target Specification.  */
25 #define TARGET_SH
26
27 #define TARGET_VERSION  \
28   fputs (" (Hitachi SH)", stderr);
29
30 /* Generate SDB debugging information.  */
31
32 #define SDB_DEBUGGING_INFO  1
33
34 /* Output DBX (stabs) debugging information if doing -gstabs.  */
35
36 #define DBX_DEBUGGING_INFO
37
38 /* Generate SDB debugging information by default. */
39
40 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
41
42 #define SDB_DELIM ";"
43
44 #define CPP_SPEC "%{ml:-D__LITTLE_ENDIAN__}"
45
46 #define CPP_PREDEFINES "-D__sh__ -Acpu(sh) -Amachine(sh)"
47
48 #define ASM_SPEC  "%{ml:-little}"
49
50 #define LINK_SPEC "%{ml:-m shl}"
51
52 /* Show we can debug even without a frame pointer.  */
53 #define CAN_DEBUG_WITHOUT_FP
54
55
56 #define CONDITIONAL_REGISTER_USAGE                              \
57   /* Hitachi saves and restores mac registers on call */        \
58   if (TARGET_HITACHI)                                           \
59    {                                                            \
60      call_used_regs[MACH_REG] = 0;                              \
61      call_used_regs[MACL_REG] = 0;                              \
62   }                                     
63
64 \f
65 /* Run-time compilation parameters selecting different hardware subsets. */
66
67 extern int target_flags;
68 #define ISIZE_BIT       (1<<1)
69 #define FAST_BIT        (1<<2)
70 #define RTL_BIT         (1<<4)
71 #define DT_BIT          (1<<5)
72 #define DALIGN_BIT      (1<<6)
73 #define SH0_BIT         (1<<7)
74 #define SH1_BIT         (1<<8)
75 #define SH2_BIT         (1<<9)
76 #define SH3_BIT         (1<<10)
77 #define C_BIT           (1<<11)
78 #define R_BIT           (1<<12)
79 #define SPACE_BIT       (1<<13)
80 #define BIGTABLE_BIT    (1<<14)
81 #define CONSTLEN_2_BIT  (1<<20)
82 #define CONSTLEN_3_BIT  (1<<21)
83 #define HITACHI_BIT     (1<<22)
84 #define CONSTLEN_0_BIT  (1<<25)
85 #define PACKSTRUCT_BIT  (1<<28)
86 #define LITTLE_ENDIAN_BIT (1<<29)
87
88 /* Nonzero if we should generate code using type 0 insns */
89 #define TARGET_SH0 (target_flags & SH0_BIT)
90
91 /* Nonzero if we should generate code using type 1 insns */
92 #define TARGET_SH1 (target_flags & SH1_BIT)
93
94 /* Nonzero if we should generate code using type 2 insns */
95 #define TARGET_SH2 (target_flags & SH2_BIT)
96
97 /* Nonzero if we should generate code using type 3 insns */
98 #define TARGET_SH3 (target_flags & SH3_BIT)
99
100 /* Nonzero if we should generate faster code rather than smaller code */
101 #define TARGET_FASTCODE   (target_flags & FAST_BIT)
102
103 /* Nonzero if we should generate smaller code rather than faster code */
104 #define TARGET_SMALLCODE   (target_flags & SPACE_BIT)
105
106 /* Nonzero if we should dump out instruction size info */
107 #define TARGET_DUMPISIZE  (target_flags & ISIZE_BIT)
108
109 /* Nonzero if we should dump the rtl in the assembly file. */
110 #define TARGET_DUMP_RTL   (target_flags & RTL_BIT)
111
112 /* Nonzero if we should dump the rtl somewher else. */
113 #define TARGET_DUMP_R     (target_flags & R_BIT)
114
115 /* Nonzero to align doubles on 64 bit boundaries */
116 #define TARGET_ALIGN_DOUBLE (target_flags & DALIGN_BIT)
117
118 /* Nonzero to use long jump tables */
119 #define TARGET_BIGTABLE     (target_flags & BIGTABLE_BIT)
120
121 /* Nonzero if combine dumping wanted */
122 #define TARGET_CDUMP (target_flags & C_BIT)
123
124 /* Select max size of computed constant code sequences to be 3 insns */
125 #define TARGET_CLEN3 (target_flags & CONSTLEN_3_BIT)
126
127 /* Select max size of computed constant code sequences to be 0 insns - ie don't do it */
128 #define TARGET_CLEN0 (target_flags & CONSTLEN_0_BIT)
129
130 /* Nonzero if using Hitachi's calling convention */
131 #define TARGET_HITACHI          (target_flags & HITACHI_BIT)
132
133 /* Nonzero if packing structures as small as they'll go (incompatible with Hitachi's compiler) */
134 #define TARGET_PACKSTRUCT       (target_flags & PACKSTRUCT_BIT)
135
136
137 #define TARGET_LITTLE_ENDIAN     (target_flags & LITTLE_ENDIAN_BIT)
138
139 #define TARGET_SWITCHES                         \
140 { {"0",         (SH0_BIT) },                    \
141   {"1",         (SH1_BIT) },                    \
142   {"2",         (SH2_BIT) },                    \
143   {"3",         (SH3_BIT) },                    \
144   {"3l",        (SH3_BIT|LITTLE_ENDIAN_BIT)},   \
145   {"R",         (R_BIT) },                      \
146   {"b",         (-LITTLE_ENDIAN_BIT) },         \
147   {"bigtable",  (BIGTABLE_BIT)},                \
148   {"c",         (C_BIT) },                      \
149   {"clen0",     (CONSTLEN_0_BIT) },             \
150   {"clen3",     (CONSTLEN_3_BIT) },             \
151   {"dalign",    (DALIGN_BIT) },                 \
152   {"hitachi",   (HITACHI_BIT) },                \
153   {"isize",     (ISIZE_BIT) },                  \
154   {"l",         (LITTLE_ENDIAN_BIT) },          \
155   {"packstruct",(PACKSTRUCT_BIT) },             \
156   {"r",         (RTL_BIT) },                    \
157   {"space",     (SPACE_BIT) },                  \
158   {"",          TARGET_DEFAULT}                 \
159 }
160
161
162 #define TARGET_DEFAULT  (FAST_BIT)
163
164
165 /* Macro to define table for command options with values.  */
166 #define TARGET_OPTIONS \
167         { { "maxsi-", &max_si}, \
168           { "maxhi-", &max_hi} }
169
170
171 #define OVERRIDE_OPTIONS                                        \
172 do {                                                            \
173   sh_cpu = CPU_SH0;                                             \
174   if (TARGET_SH1)                                               \
175     sh_cpu = CPU_SH1;                                           \
176   if (TARGET_SH2)                                               \
177     sh_cpu = CPU_SH2;                                           \
178  if (TARGET_SH3)                                                \
179     sh_cpu = CPU_SH3|CPU_SH2;                                   \
180                                                                 \
181   /*  We *MUST* always define optimize since we *HAVE* to run   \
182       shorten branches to get correct code. */                  \
183                                                                 \
184   optimize = 1;                                                 \
185   flag_delayed_branch = 1;                                      \
186   /* But never run scheduling before reload, since than can     \
187      break global alloc, and generates slower code anyway due   \
188      to the pressure on R0. */                                  \
189   flag_schedule_insns = 0;                                      \
190   if (max_si)                                                   \
191     max_count_si = atoi (max_si);                               \
192   else                                                          \
193     max_count_si = 1010;                                        \
194   if (max_hi)                                                   \
195     max_count_hi = atoi (max_hi);                               \
196   else                                                          \
197     max_count_hi = 500;                                         \
198 } while (0)
199
200 \f
201 /* Target machine storage Layout.  */
202
203 /* Define to use software floating point emulator for REAL_ARITHMETIC and
204    decimal <-> binary conversion. */
205 #define REAL_ARITHMETIC
206
207 /* Define this if most significant bit is lowest numbered
208    in instructions that operate on numbered bit-fields.  */
209
210 #define BITS_BIG_ENDIAN  0
211
212
213 /* Define this if most significant byte of a word is the lowest numbered.  */
214 #define BYTES_BIG_ENDIAN (TARGET_LITTLE_ENDIAN == 0)
215
216 /* Define this if most significant word of a multiword number is the lowest
217    numbered.  */
218 #define WORDS_BIG_ENDIAN (TARGET_LITTLE_ENDIAN == 0)
219
220
221 /* Define this to set the endianness to use in libgcc2.c, which can
222    not depend on target_flags.  */
223 #if defined(__LITTLE_ENDIAN__)
224 #define LIBGCC2_WORDS_BIG_ENDIAN 0
225 #else
226 #define LIBGCC2_WORDS_BIG_ENDIAN 1
227 #endif
228
229 /* Number of bits in an addressable storage unit */
230 #define BITS_PER_UNIT  8
231
232 /* Width in bits of a "word", which is the contents of a machine register.
233    Note that this is not necessarily the width of data type `int';
234    if using 16-bit ints on a 68000, this would still be 32.
235    But on a machine with 16-bit registers, this would be 16.  */
236 #define BITS_PER_WORD  32
237 #define MAX_BITS_PER_WORD 32
238
239 /* Width of a word, in units (bytes).  */
240 #define UNITS_PER_WORD  4
241
242 /* Width in bits of a pointer.
243    See also the macro `Pmode' defined below.  */
244 #define POINTER_SIZE  32
245
246 /* Allocation boundary (in *bits*) for storing arguments in argument list.  */
247 #define PARM_BOUNDARY   32
248
249 /* Boundary (in *bits*) on which stack pointer should be aligned.  */
250 #define STACK_BOUNDARY  32
251
252 /* Allocation boundary (in *bits*) for the code of a function.
253    32 bit alignment is faster, because instructions are always fetched as a
254    pair from a longword boundary.  */
255 #define FUNCTION_BOUNDARY  (TARGET_SMALLCODE ? 16 : 32)
256
257 /* Alignment of field after `int : 0' in a structure.  */
258 #define EMPTY_FIELD_BOUNDARY  32
259
260 /* No data type wants to be aligned rounder than this.  */
261 #define BIGGEST_ALIGNMENT  (TARGET_ALIGN_DOUBLE ? 64 : 32)
262
263 /* The best alignment to use in cases where we have a choice.  */
264 #define FASTEST_ALIGNMENT 32
265
266 /* Make strings word-aligned so strcpy from constants will be faster.  */
267 #define CONSTANT_ALIGNMENT(EXP, ALIGN)  \
268   ((TREE_CODE (EXP) == STRING_CST       \
269     && (ALIGN) < FASTEST_ALIGNMENT)     \
270     ? FASTEST_ALIGNMENT : (ALIGN))
271
272 /* Make arrays of chars word-aligned for the same reasons.  */
273 #define DATA_ALIGNMENT(TYPE, ALIGN)             \
274   (TREE_CODE (TYPE) == ARRAY_TYPE               \
275    && TYPE_MODE (TREE_TYPE (TYPE)) == QImode    \
276    && (ALIGN) < FASTEST_ALIGNMENT ? FASTEST_ALIGNMENT : (ALIGN))
277
278 /* Number of bits which any structure or union's size must be a
279    multiple of.  Each structure or union's size is rounded up to a
280    multiple of this. */
281 #define STRUCTURE_SIZE_BOUNDARY (TARGET_PACKSTRUCT ? 8 : 32)
282
283 /* Set this nonzero if move instructions will actually fail to work
284    when given unaligned data.  */
285 #define STRICT_ALIGNMENT 1
286
287 \f
288 /* Standard register usage.  */
289
290 /* Register allocation for the Hitachi calling convention:
291
292         r0              arg return
293         r1..r3          scratch
294         r4-r7           args in
295         r8..r13         call saved
296         r14             frame pointer/call saved
297         r15             stack pointer
298         ap              arg pointer (doesn't really exist, always eliminated)
299         pr              subroutine return address
300         t               t bit
301         mach            multiply/accumulate result
302         macl
303 */
304
305 /* Number of actual hardware registers.
306    The hardware registers are assigned numbers for the compiler
307    from 0 to just below FIRST_PSEUDO_REGISTER.
308    All registers that the compiler knows about must be given numbers,
309    even those that are not normally considered general registers. */
310
311 #define AP_REG   16  
312 #define PR_REG   17
313 #define T_REG    18
314 #define GBR_REG  19
315 #define MACH_REG 20
316 #define MACL_REG 21
317
318 #define FIRST_PSEUDO_REGISTER 22
319
320 /* 1 for registers that have pervasive standard uses
321    and are not available for the register allocator. 
322
323    Mach register is fixed 'cause it's only 10 bits wide for SH1.
324    It is 32 bits wide for SH2.  */
325
326  /*  r0  r1  r2  r3 
327      r4  r5  r6  r7
328      r8  r9  r10 r11
329      r12 r13 r14 r15
330      ap  pr  t   gbr
331      mh   ml */
332
333 #define FIXED_REGISTERS         \
334   { 0,  0,  0,  0,              \
335     0,  0,  0,  0,              \
336     0,  0,  0,  0,              \
337     0,  0,  0,  1,              \
338     1,  1,  1,  1,              \
339     1,  1}
340
341
342 /* 1 for registers not available across function calls.
343    These must include the FIXED_REGISTERS and also any
344    registers that can be used without being saved.
345    The latter must include the registers where values are returned
346    and the register where structure-value addresses are passed.
347    Aside from that, you can include as many other registers as you like.  */
348
349  /*  r0  r1  r2  r3  
350      r4  r5  r6  r7 
351      r8  r9  r10 r11
352      r12 r13 r14 r15
353      ap  pr  t   gbr 
354      mh  ml */
355
356 #define CALL_USED_REGISTERS     \
357    { 1,  1,  1,  1,             \
358      1,  1,  1,  1,             \
359      0,  0,  0,  0,             \
360      0,  0,  0,  1,             \
361      1,  0,  1,  1,             \
362      1,  1}     
363
364 /* Return number of consecutive hard regs needed starting at reg REGNO
365    to hold something of mode MODE.
366    This is ordinarily the length in words of a value of mode MODE
367    but can be less for certain modes in special long registers.
368
369    On the SH regs are UNITS_PER_WORD bits wide; */
370
371 #define HARD_REGNO_NREGS(REGNO, MODE)  \
372    (((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD))
373
374 /* Value is 1 if hard register REGNO can hold a value of machine-mode MODE.
375    We may keep double values in even registers */
376
377 extern int hard_regno_mode_ok[];
378 #define HARD_REGNO_MODE_OK(REGNO, MODE)  \
379   (hard_regno_mode_ok[REGNO] & (1<<(int)MODE))
380
381 /* Value is 1 if it is a good idea to tie two pseudo registers
382    when one has mode MODE1 and one has mode MODE2.
383    If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2,
384    for any hard reg, then this must be 0 for correct output.  */
385
386 #define MODES_TIEABLE_P(MODE1, MODE2) \
387   ((MODE1) == (MODE2) || GET_MODE_CLASS (MODE1) == GET_MODE_CLASS (MODE2))
388
389 /* Specify the registers used for certain standard purposes.
390    The values of these macros are register numbers.  */
391
392 /* Define this if the program counter is overloaded on a register.  */
393 /* #define PC_REGNUM            15*/
394
395 /* Register to use for pushing function arguments.  */
396 #define STACK_POINTER_REGNUM    15
397
398 /* Base register for access to local variables of the function.  */
399 #define FRAME_POINTER_REGNUM    14
400
401 /* Value should be nonzero if functions must have frame pointers.
402    Zero means the frame pointer need not be set up (and parms may be accessed
403    via the stack pointer) in functions that seem suitable.  */
404
405 #define FRAME_POINTER_REQUIRED  0
406
407 /* Definitions for register eliminations.
408
409    We have two registers that can be eliminated on the SH.  First, the
410    frame pointer register can often be eliminated in favor of the stack
411    pointer register.  Secondly, the argument pointer register can always be
412    eliminated; it is replaced with either the stack or frame pointer.  */
413
414 /* This is an array of structures.  Each structure initializes one pair
415    of eliminable registers.  The "from" register number is given first,
416    followed by "to".  Eliminations of the same "from" register are listed
417    in order of preference.  */
418
419 #define ELIMINABLE_REGS                         \
420 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
421  { ARG_POINTER_REGNUM,   STACK_POINTER_REGNUM}, \
422  { ARG_POINTER_REGNUM,   FRAME_POINTER_REGNUM},}
423
424
425 /* Given FROM and TO register numbers, say whether this elimination
426    is allowed.  */
427 #define CAN_ELIMINATE(FROM, TO) \
428   (!((FROM) == FRAME_POINTER_REGNUM && FRAME_POINTER_REQUIRED))
429
430 /* Define the offset between two registers, one to be eliminated, and the other
431    its replacement, at the start of a routine.  */
432
433 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
434   OFFSET = initial_elimination_offset (FROM, TO)
435
436 /* Base register for access to arguments of the function.  */
437 #define ARG_POINTER_REGNUM      16
438
439 /* Register in which the static-chain is passed to a function.  */
440 #define STATIC_CHAIN_REGNUM     13
441
442 /* The register in which a struct value address is passed */
443
444 #define STRUCT_VALUE_REGNUM 2
445
446 /* If the structure value address is not passed in a register, define
447    `STRUCT_VALUE' as an expression returning an RTX for the place
448    where the address is passed.  If it returns 0, the address is
449    passed as an "invisible" first argument.  */
450
451 /*#define STRUCT_VALUE ((rtx)0)*/
452
453
454 /* Don't default to pcc-struct-return, because we have already specified
455    exactly how to return structures in the RETURN_IN_MEMORY macro.  */
456
457 #define DEFAULT_PCC_STRUCT_RETURN 0
458
459 \f
460 /* Define the classes of registers for register constraints in the
461    machine description.  Also define ranges of constants.
462
463    One of the classes must always be named ALL_REGS and include all hard regs.
464    If there is more than one class, another class must be named NO_REGS
465    and contain no registers.
466
467    The name GENERAL_REGS must be the name of a class (or an alias for
468    another name such as ALL_REGS).  This is the class of registers
469    that is allowed by "g" or "r" in a register constraint.
470    Also, registers outside this class are allocated only when
471    instructions express preferences for them.
472
473    The classes must be numbered in nondecreasing order; that is,
474    a larger-numbered class must never be contained completely
475    in a smaller-numbered class.
476
477    For any two classes, it is very desirable that there be another
478    class that represents their union.  */
479
480 /* The SH has two sorts of general registers, R0 and the rest.  R0 can 
481    be used as the destination of some of the arithmetic ops. There are
482    also some special purpose registers; the T bit register, the
483    Procedure Return Register and the Multipy Accumulate Registers */
484
485 enum reg_class
486 {
487   NO_REGS,
488   R0_REGS,
489   PR_REGS,
490   T_REGS,
491   MAC_REGS,
492   GENERAL_REGS,
493   ALL_REGS,
494   LIM_REG_CLASSES
495 };
496
497 #define N_REG_CLASSES  (int) LIM_REG_CLASSES
498
499 /* Give names of register classes as strings for dump file.   */
500 #define REG_CLASS_NAMES  \
501 {                       \
502   "NO_REGS",            \
503   "R0_REGS",            \
504   "PR_REGS",            \
505   "T_REGS",             \
506   "MAC_REGS",           \
507   "GENERAL_REGS",       \
508   "ALL_REGS",           \
509 }
510
511 /* Define which registers fit in which classes.
512    This is an initializer for a vector of HARD_REG_SET
513    of length N_REG_CLASSES.  */
514
515 #define REG_CLASS_CONTENTS      \
516 {                               \
517   0x000000,  /* NO_REGS      */ \
518   0x000001,  /* R0_REGS      */ \
519   0x020000,  /* PR_REGS      */ \
520   0x040000,  /* T_REGS       */ \
521   0x300000,  /* MAC_REGS     */ \
522   0x01FFFF,  /* GENERAL_REGS */ \
523   0x37FFFF   /* ALL_REGS     */ \
524 }
525
526 /* The same information, inverted:
527    Return the class number of the smallest class containing
528    reg number REGNO.  This could be a conditional expression
529    or could index an array.  */
530
531 extern int regno_reg_class[];
532 #define REGNO_REG_CLASS(REGNO) regno_reg_class[REGNO]
533
534 /* When defined, the compiler allows registers explicitly used in the
535    rtl to be used as spill registers but prevents the compiler from
536    extending the lifetime of these registers. */
537
538 #define SMALL_REGISTER_CLASSES
539
540 /* The order in which register should be allocated.  */
541 #define REG_ALLOC_ORDER  \
542   { 1,2,3,7,6,5,4,0,8,9,10,11,12,13,14,15,16,17,18,19,20,21 }
543
544 /* The class value for index registers, and the one for base regs.  */
545 #define INDEX_REG_CLASS  R0_REGS
546 #define BASE_REG_CLASS   GENERAL_REGS
547
548 /* Get reg_class from a letter such as appears in the machine 
549    description. */
550 extern enum reg_class reg_class_from_letter[];
551
552 #define REG_CLASS_FROM_LETTER(C) \
553    ( (C) >= 'a' && (C) <= 'z' ? reg_class_from_letter[(C)-'a'] : NO_REGS )
554
555
556 /* The letters I, J, K, L and M in a register constraint string
557    can be used to stand for particular ranges of immediate operands.
558    This macro defines what the ranges are.
559    C is the letter, and VALUE is a constant value.
560    Return 1 if VALUE is in the range specified by C.
561         I: arithmetic operand -127..128, as used in add, sub, etc
562         K: shift operand 1,2,8 or 16
563         L: logical operand 0..255, as used in and, or, etc.
564         M: constant 1
565         N: constant 0  */
566
567
568 #define CONST_OK_FOR_I(VALUE) (((int)(VALUE))>= -128 && ((int)(VALUE)) <= 127)
569 #define CONST_OK_FOR_K(VALUE) ((VALUE)==1||(VALUE)==2||(VALUE)==8||(VALUE)==16)
570 #define CONST_OK_FOR_L(VALUE) (((int)(VALUE))>=    0 && ((int)(VALUE)) <= 255)
571 #define CONST_OK_FOR_M(VALUE) ((VALUE)==1)
572 #define CONST_OK_FOR_N(VALUE) ((VALUE)==0)
573 #define CONST_OK_FOR_LETTER_P(VALUE, C)     \
574      ((C) == 'I' ? CONST_OK_FOR_I (VALUE)   \
575     : (C) == 'K' ? CONST_OK_FOR_K (VALUE)   \
576     : (C) == 'L' ? CONST_OK_FOR_L (VALUE)   \
577     : (C) == 'M' ? CONST_OK_FOR_M (VALUE)   \
578     : (C) == 'N' ? CONST_OK_FOR_N (VALUE)   \
579     : 0)
580
581 /* Similar, but for floating constants, and defining letters G and H.
582    Here VALUE is the CONST_DOUBLE rtx itself.  */
583
584 #define CONST_DOUBLE_OK_FOR_LETTER_P(VALUE, C) \
585    ((C) == 'G' ? CONST_OK_FOR_I (CONST_DOUBLE_HIGH (VALUE)) \
586               && CONST_OK_FOR_I (CONST_DOUBLE_LOW (VALUE))  \
587     : 0)
588
589 /* Given an rtx X being reloaded into a reg required to be
590    in class CLASS, return the class of reg to actually use.
591    In general this is just CLASS; but on some machines
592    in some cases it is preferable to use a more restrictive class.  */
593
594 #define PREFERRED_RELOAD_CLASS(X, CLASS) CLASS
595
596 /* Return the register class of a scratch register needed to copy IN into
597    or out of a register in CLASS in MODE.  If it can be done directly,
598    NO_REGS is returned.  */
599
600
601 /* Return the maximum number of consecutive registers
602    needed to represent mode MODE in a register of class CLASS. 
603
604    On SH this is the size of MODE in words */
605 #define CLASS_MAX_NREGS(CLASS, MODE)  \
606      ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
607
608
609 \f
610 /* Stack layout; function entry, exit and calling.  */
611
612 /* Define the number of register that can hold parameters.
613    These two macros are used only in other macro definitions below.  */
614 #define NPARM_REGS 4
615 #define FIRST_PARM_REG 4
616 #define FIRST_RET_REG  0
617
618 /* Define this if pushing a word on the stack
619    makes the stack pointer a smaller address.  */
620 #define STACK_GROWS_DOWNWARD  
621
622 /*  Define this macro if the addresses of local variable slots are at
623     negative offsets from the frame pointer.
624
625     The SH only has positive indexes, so grow the frame up 
626 */
627 /* #define FRAME_GROWS_DOWNWARD */
628
629 /* Offset from the frame pointer to the first local variable slot to
630    be allocated. */
631 #define STARTING_FRAME_OFFSET  0
632
633 /* If we generate an insn to push BYTES bytes,
634    this says how many the stack pointer really advances by.  */
635 #define PUSH_ROUNDING(NPUSHED)  (((NPUSHED) + 3) & ~3)
636
637 /* Offset of first parameter from the argument pointer register value.  */
638 #define FIRST_PARM_OFFSET(FNDECL)  0
639
640 /* Value is the number of byte of arguments automatically
641    popped when returning from a subroutine call.
642    FUNTYPE is the data type of the function (as a tree),
643    or for a library call it is an identifier node for the subroutine name.
644    SIZE is the number of bytes of arguments passed on the stack.
645
646    On the SH, the caller does not pop any of its arguments that were passed
647    on the stack.  */
648 #define RETURN_POPS_ARGS(FUNTYPE, SIZE)  0
649
650 /* Define how to find the value returned by a function.
651    VALTYPE is the data type of the value (as a tree).
652    If the precise function being called is known, FUNC is its FUNCTION_DECL;
653    otherwise, FUNC is 0.  */
654
655 #define FUNCTION_VALUE(VALTYPE, FUNC) \
656   gen_rtx (REG, \
657            TYPE_MODE (VALTYPE) == BLKmode ? SImode : TYPE_MODE (VALTYPE), \
658            FIRST_RET_REG)
659
660 /* Define how to find the value returned by a library function
661    assuming the value has mode MODE.  */
662 #define LIBCALL_VALUE(MODE)  \
663     gen_rtx (REG, MODE, FIRST_RET_REG)
664
665 /* 1 if N is a possible register number for a function value.
666    On the SH, only r0 can return results.  */
667 #define FUNCTION_VALUE_REGNO_P(REGNO)  \
668           ((REGNO) == FIRST_RET_REG)
669
670 /* 1 if N is a possible register number for function argument passing.*/
671
672 #define FUNCTION_ARG_REGNO_P(REGNO)  \
673   ((REGNO) >= FIRST_PARM_REG && (REGNO) < (NPARM_REGS + FIRST_PARM_REG))
674
675
676 \f
677 /* Define a data type for recording info about an argument list
678    during the scan of that argument list.  This data type should
679    hold all necessary information about the function itself
680    and about the args processed so far, enough to enable macros
681    such as FUNCTION_ARG to determine where the next arg should go.
682
683    On SH, this is a single integer, which is a number of words
684    of arguments scanned so far (including the invisible argument,
685    if any, which holds the structure-value-address).
686    Thus NARGREGS or more means all following args should go on the stack.  */
687
688 #define CUMULATIVE_ARGS  int
689
690 #define ROUND_ADVANCE(SIZE)     \
691   ((SIZE + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
692
693 /* Round a register number up to a proper boundary for an arg of mode 
694    MODE. 
695    
696    The SH doesn't care about double alignment, so we only
697    round doubles to even regs when asked to explicitly. */
698
699 #define ROUND_REG(X, MODE)                                      \
700   ((TARGET_ALIGN_DOUBLE                                         \
701    && GET_MODE_UNIT_SIZE ((MODE)) > UNITS_PER_WORD)             \
702    ? ((X) + ((X) & 1)) : (X))
703
704
705 /* Initialize a variable CUM of type CUMULATIVE_ARGS
706    for a call to a function whose data type is FNTYPE.
707    For a library call, FNTYPE is 0.
708
709    On SH, the offset always starts at 0: the first parm reg is always
710    the same reg.  */
711
712 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME)  \
713   ((CUM) = 0)
714
715 /* Update the data in CUM to advance over an argument
716    of mode MODE and data type TYPE.
717    (TYPE is null for libcalls where that information may not be
718    available.)  */
719
720 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)    \
721  ((CUM) = (ROUND_REG ((CUM), (MODE))                    \
722            + ((MODE) != BLKmode                         \
723               ? ROUND_ADVANCE (GET_MODE_SIZE (MODE))    \
724               : ROUND_ADVANCE (int_size_in_bytes (TYPE)))))
725
726 /* Define where to put the arguments to a function.
727    Value is zero to push the argument on the stack,
728    or a hard register in which to store the argument.
729
730    MODE is the argument's machine mode.
731    TYPE is the data type of the argument (as a tree).
732     This is null for libcalls where that information may
733     not be available.
734    CUM is a variable of type CUMULATIVE_ARGS which gives info about
735     the preceding args and about the function being called.
736    NAMED is nonzero if this argument is a named parameter
737     (otherwise it is an extra parameter matching an ellipsis).
738
739    On SH the first args are normally in registers
740    and the rest are pushed.  Any arg that starts within the first
741    NPARM_REGS words is at least partially passed in a register unless
742    its data type forbids.  */
743
744
745 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
746     sh_function_arg (CUM, MODE, TYPE, NAMED)
747
748 extern struct rtx_def *sh_function_arg();
749
750 /* For an arg passed partly in registers and partly in memory,
751    this is the number of registers used.
752    For args passed entirely in registers or entirely in memory, zero.
753    
754    We sometimes split args */
755
756 #define FUNCTION_ARG_PARTIAL_NREGS(CUM, MODE, TYPE, NAMED) \
757   sh_function_arg_partial_nregs (CUM, MODE, TYPE, NAMED)
758
759 extern int current_function_anonymous_args;
760
761 /* Perform any needed actions needed for a function that is receiving a
762    variable number of arguments. */
763
764 #define SETUP_INCOMING_VARARGS(ASF, MODE, TYPE, PAS, ST) \
765   current_function_anonymous_args = 1;
766
767
768 /* Call the function profiler with a given profile label. */
769
770 #define FUNCTION_PROFILER(STREAM,LABELNO)                       \
771 {                                                               \
772         fprintf(STREAM, "       trapa   #5\n");                 \
773         fprintf(STREAM, "       .align  2\n");                  \
774         fprintf(STREAM, "       .long   LP%d\n", (LABELNO));    \
775 }
776
777
778 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
779    the stack pointer does not matter.  The value is tested only in
780    functions that have frame pointers.
781    No definition is equivalent to always zero.  */
782
783 #define EXIT_IGNORE_STACK 1
784
785 /* Generate the assembly code for function exit 
786    Just dump out any accumulated constant table.*/
787
788 #define FUNCTION_EPILOGUE(STREAM, SIZE)  function_epilogue (STREAM, SIZE)
789
790
791 /* Output assembler code for a block containing the constant parts
792    of a trampoline, leaving space for the variable parts.
793
794    On the SH, the trapoline looks like
795    1 0000 D301                  mov.l   l1,r3
796    2 0002 DD02                  mov.l   l2,r13
797    3 0004 4D2B                  jmp     @r13
798    4 0006 200B                  or      r0,r0
799    5 0008 00000000      l1:     .long   function
800    6 000c 00000000      l2:     .long   area    
801 */
802 #define TRAMPOLINE_TEMPLATE(FILE)               \
803 {                                               \
804   fprintf ((FILE), "    .word   0xd301\n");     \
805   fprintf ((FILE), "    .word   0xdd02\n");     \
806   fprintf ((FILE), "    .word   0x4d2b\n");        \
807   fprintf ((FILE), "    .word   0x200b\n");     \
808   fprintf ((FILE), "    .long   0\n");          \
809   fprintf ((FILE), "    .long   0\n");          \
810 }
811
812 /* Length in units of the trampoline for entering a nested function.  */
813 #define TRAMPOLINE_SIZE  16
814
815 /* Alignment required for a trampoline in units.  */
816 #define TRAMPOLINE_ALIGN  4
817
818 /* Emit RTL insns to initialize the variable parts of a trampoline.
819    FNADDR is an RTX for the address of the function's pure code.
820    CXT is an RTX for the static chain value for the function.  */
821
822 #define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)  \
823 {                                                                       \
824   emit_move_insn (gen_rtx (MEM, SImode, plus_constant ((TRAMP), 8)),    \
825                   (CXT));                                               \
826   emit_move_insn (gen_rtx (MEM, SImode, plus_constant ((TRAMP), 12)),   \
827                   (FNADDR));                                            \
828 }
829
830 \f
831 /* Addressing modes, and classification of registers for them.  */
832 #define HAVE_POST_INCREMENT  1
833 /*#define HAVE_PRE_INCREMENT   1*/
834 /*#define HAVE_POST_DECREMENT  1*/
835 #define HAVE_PRE_DECREMENT   1
836
837 /* Macros to check register numbers against specific register classes.  */
838
839 /* These assume that REGNO is a hard or pseudo reg number.
840    They give nonzero only if REGNO is a hard reg of the suitable class
841    or a pseudo reg currently allocated to a suitable hard reg.
842    Since they use reg_renumber, they are safe only once reg_renumber
843    has been allocated, which happens in local-alloc.c.
844
845 */
846
847 #define REGNO_OK_FOR_BASE_P(REGNO)  \
848   ((REGNO) < PR_REG || (unsigned) reg_renumber[(REGNO)] < PR_REG)
849 #define REGNO_OK_FOR_INDEX_P(REGNO)   \
850   ((REGNO) == 0 || (unsigned) reg_renumber[(REGNO)] == 0)
851
852 /* Maximum number of registers that can appear in a valid memory 
853    address. */
854
855 #define MAX_REGS_PER_ADDRESS 2
856
857 /* Recognize any constant value that is a valid address.  */
858
859 #define CONSTANT_ADDRESS_P(X)   \
860   (GET_CODE (X) == LABEL_REF)
861
862 /* Nonzero if the constant value X is a legitimate general operand. */
863
864 #define LEGITIMATE_CONSTANT_P(X) \
865   (GET_CODE(X) != CONST_DOUBLE /*&& GET_CODE(X) != LABEL_REF*/)
866
867
868 /* The macros REG_OK_FOR..._P assume that the arg is a REG rtx
869    and check its validity for a certain class.
870    We have two alternate definitions for each of them.
871    The usual definition accepts all pseudo regs; the other rejects
872    them unless they have been allocated suitable hard regs.
873    The symbol REG_OK_STRICT causes the latter definition to be used.  */
874
875 #define MODE_DISP_OK_4(X,MODE) ((GET_MODE_SIZE(MODE)==4) && ((unsigned)INTVAL(X)<64) && (!(INTVAL(X) &3)))
876 #define MODE_DISP_OK_8(X,MODE) ((GET_MODE_SIZE(MODE)==8) && ((unsigned)INTVAL(X)<60) && (!(INTVAL(X) &3)))
877 /* ??? These two work only if the target is R0, so we do not support them.  */
878 #define MODE_DISP_OK_2(X,MODE) (0)
879 #define MODE_DISP_OK_1(X,MODE) (0)
880
881 #ifndef REG_OK_STRICT
882
883
884 /* Nonzero if X is a hard reg that can be used as a base reg
885    or if it is a pseudo reg.  */
886 #define REG_OK_FOR_BASE_P(X) \
887   (REGNO (X) <= 16 || REGNO(X) >= FIRST_PSEUDO_REGISTER)
888 /* Nonzero if X is a hard reg that can be used as an index
889    or if it is a pseudo reg.  */
890
891 #define REG_OK_FOR_INDEX_P(X) \
892   (REGNO (X) == 0 || REGNO(X) >= FIRST_PSEUDO_REGISTER)
893
894 #define REG_OK_FOR_PRE_POST_P(X) \
895         (REG_OK_FOR_BASE_P (X))
896
897 #else
898 /* Nonzero if X is a hard reg that can be used as a base reg.  */
899 #define REG_OK_FOR_BASE_P(X)    \
900         REGNO_OK_FOR_BASE_P (REGNO (X))
901
902 /* Nonzero if X is a hard reg that can be used as an index.  */
903 #define REG_OK_FOR_INDEX_P(X)   \
904         REGNO_OK_FOR_INDEX_P (REGNO (X))
905
906 #define REG_OK_FOR_PRE_POST_P(X)  \
907         (REGNO_OK_FOR_BASE_P (REGNO (X)))
908 #endif
909
910 /* The Q is a pc relative load operand */
911 #define EXTRA_CONSTRAINT_Q(OP)                                          \
912   (GET_CODE (OP) == MEM &&                                              \
913    ((GET_CODE (XEXP (OP, 0)) == LABEL_REF)                              \
914     || (GET_CODE (XEXP (OP, 0)) == CONST                                \
915         && GET_CODE (XEXP (XEXP (OP, 0), 0)) == PLUS                    \
916         && GET_CODE (XEXP (XEXP (XEXP (OP, 0), 0), 0)) == LABEL_REF     \
917         && GET_CODE (XEXP (XEXP (XEXP (OP, 0), 0), 1)) == CONST_INT)))
918
919 #define IS_INDEX(OP)                                                                    \
920   ((GET_CODE (OP) == PLUS &&                                                            \
921     (INDEX_REGISTER_RTX_P (XEXP (OP, 0)) && BASE_REGISTER_RTX_P (XEXP (OP, 1))) ||      \
922     (INDEX_REGISTER_RTX_P (XEXP (OP, 1)) && BASE_REGISTER_RTX_P (XEXP (OP, 0)))))
923
924
925
926 #define EXTRA_CONSTRAINT(OP, C)   \
927      ((C) == 'Q' ? EXTRA_CONSTRAINT_Q (OP)   \
928     : 0)
929
930 \f
931 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
932    that is a valid memory address for an instruction.
933    The MODE argument is the machine mode for the MEM expression
934    that wants to use this address.
935
936    The other macros defined here are used only in GO_IF_LEGITIMATE_ADDRESS.  */
937
938 #define BASE_REGISTER_RTX_P(X)  \
939   (GET_CODE (X) == REG && REG_OK_FOR_BASE_P (X))
940
941 #define INDEX_REGISTER_RTX_P(X)  \
942   (GET_CODE (X) == REG && REG_OK_FOR_INDEX_P (X))
943
944
945 /* Jump to LABEL if X is a valid address RTX.  This must also take
946    REG_OK_STRICT into account when deciding about valid registers, but it uses
947    the above macros so we are in luck.  
948  
949    Allow  REG
950           REG+disp
951           REG+r0
952           REG++
953           --REG
954 */
955
956 /* The SH allows a displacement in a QI or HI amode, but only when the 
957    other operand is R0. GCC doesn't handle this very well, so we forgo
958    all of that.
959
960    A legitimate index for a QI or HI is 0, SI and above can be any 
961    number 0..63 */
962
963 #define GO_IF_LEGITIMATE_INDEX(MODE, REGNO, OP, LABEL)                  \
964   do {                                                                  \
965     if (GET_CODE (OP) == CONST_INT)                                     \
966       {                                                                 \
967         if (MODE_DISP_OK_4 (OP, MODE))  goto LABEL;                     \
968         if (MODE_DISP_OK_8 (OP, MODE))  goto LABEL;                     \
969         if (MODE_DISP_OK_2 (OP, MODE))  goto LABEL;                     \
970         if (MODE_DISP_OK_1 (OP, MODE))  goto LABEL;                     \
971       }                                                                 \
972   } while(0)
973
974
975 #define GO_IF_LEGITIMATE_ADDRESS(MODE, X, LABEL)                  \
976 {                                                                 \
977   if (BASE_REGISTER_RTX_P (X))                                    \
978     goto LABEL;                                                   \
979   else if ((GET_CODE (X) == POST_INC || GET_CODE (X) == PRE_DEC)  \
980            && GET_CODE (XEXP (X, 0)) == REG                       \
981            && REG_OK_FOR_PRE_POST_P (XEXP (X, 0)))                \
982     goto LABEL;                                                   \
983   else if (GET_CODE (X) == PLUS)                                  \
984     {                                                             \
985       rtx xop0 = XEXP(X,0);                                       \
986       rtx xop1 = XEXP(X,1);                                       \
987       if (GET_MODE_SIZE(MODE) <= 8 && BASE_REGISTER_RTX_P (xop0)) \
988         GO_IF_LEGITIMATE_INDEX (MODE, REGNO (xop0), xop1, LABEL); \
989       if (GET_MODE_SIZE(MODE) <= 8 && BASE_REGISTER_RTX_P (xop1)) \
990         GO_IF_LEGITIMATE_INDEX (MODE, REGNO (xop1), xop0, LABEL); \
991       if (GET_MODE_SIZE(MODE)<= 4) {                              \
992         if(BASE_REGISTER_RTX_P(xop1) &&                           \
993            INDEX_REGISTER_RTX_P(xop0)) goto LABEL;                \
994         if(INDEX_REGISTER_RTX_P(xop1) &&                          \
995            BASE_REGISTER_RTX_P(xop0)) goto LABEL;                 \
996       }                                                           \
997     }                                                             \
998   else if ((GET_CODE (X) == PRE_INC || GET_CODE (X) == POST_DEC)  \
999            && GET_CODE (XEXP (X, 0)) == REG                       \
1000            && REG_OK_FOR_PRE_POST_P (XEXP (X, 0)))                \
1001     goto LABEL;                                                   \
1002 }                                                                  
1003                                                                    
1004 \f                                                                  
1005 /* Try machine-dependent ways of modifying an illegitimate address 
1006    to be legitimate.  If we find one, return the new, valid address.
1007    This macro is used in only one place: `memory_address' in explow.c.
1008
1009    OLDX is the address as it was before break_out_memory_refs was called.
1010    In some cases it is useful to look at this to decide what needs to be done.
1011
1012    MODE and WIN are passed so that this macro can use
1013    GO_IF_LEGITIMATE_ADDRESS.
1014
1015    It is always safe for this macro to do nothing.  It exists to recognize
1016    opportunities to optimize the output.
1017
1018   */
1019
1020 #define LEGITIMIZE_ADDRESS(X,OLDX,MODE,WIN) ;
1021
1022 /* Go to LABEL if ADDR (a legitimate address expression)
1023    has an effect that depends on the machine mode it is used for.  */
1024 #define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR,LABEL)  \
1025 {                                                                       \
1026   if (GET_CODE(ADDR) == PRE_DEC || GET_CODE(ADDR) == POST_DEC           \
1027       || GET_CODE(ADDR) == PRE_INC || GET_CODE(ADDR) == POST_INC)       \
1028     goto LABEL;                                                         \
1029 }
1030 \f
1031 /* Specify the machine mode that this machine uses
1032    for the index in the tablejump instruction.  */
1033 #define CASE_VECTOR_MODE (TARGET_BIGTABLE ? SImode : HImode)
1034
1035 /* Define this if the tablejump instruction expects the table
1036    to contain offsets from the address of the table.
1037    Do not define this if the table should contain absolute addresses.  */
1038 #define CASE_VECTOR_PC_RELATIVE 
1039
1040 /* Specify the tree operation to be used to convert reals to integers.  */
1041 #define IMPLICIT_FIX_EXPR  FIX_ROUND_EXPR
1042
1043 /* This is the kind of divide that is easiest to do in the general case.  */
1044 #define EASY_DIV_EXPR  TRUNC_DIV_EXPR
1045
1046 /* 'char' is signed by default */
1047 #define DEFAULT_SIGNED_CHAR  1
1048
1049 /* The type of size_t unsigned int.  */
1050 #define SIZE_TYPE "unsigned int"
1051
1052 #define WCHAR_TYPE "short unsigned int"
1053 #define WCHAR_TYPE_SIZE 16
1054
1055 /* Don't cse the address of the function being compiled.  */
1056 /*#define NO_RECURSIVE_FUNCTION_CSE 1*/
1057
1058 /* Max number of bytes we can move from memory to memory
1059    in one reasonably fast instruction.  */
1060 #define MOVE_MAX 4
1061
1062 /* Define if operations between registers always perform the operation
1063    on the full register even if a narrower mode is specified.  */
1064 #define WORD_REGISTER_OPERATIONS
1065
1066 /* Define if loading in MODE, an integral mode narrower than BITS_PER_WORD
1067    will either zero-extend or sign-extend.  The value of this macro should
1068    be the code that says which one of the two operations is implicitly
1069    done, NIL if none.  */
1070 #define LOAD_EXTEND_OP(MODE) SIGN_EXTEND
1071
1072 /* Define this if zero-extension is slow (more than one real instruction).
1073    On the SH, it's only one instruction */
1074 /* #define SLOW_ZERO_EXTEND */
1075
1076 /* Nonzero if access to memory by bytes is slow and undesirable.  */
1077 #define SLOW_BYTE_ACCESS 0
1078
1079 /* We assume that the store-condition-codes instructions store 0 for false
1080    and some other value for true.  This is the value stored for true.  */
1081
1082 #define STORE_FLAG_VALUE 1
1083
1084 /* Immediate shift counts are truncated by the output routines (or was it
1085    the assembler?).  Shift counts in a register are truncated by SH.  Note
1086    that the native compiler puts too large (> 32) immediate shift counts
1087    into a register and shifts by the register, letting the SH decide what
1088    to do instead of doing that itself.  */
1089 #define SHIFT_COUNT_TRUNCATED 1
1090
1091 /* All integers have the same format so truncation is easy.  */
1092 #define TRULY_NOOP_TRUNCATION(OUTPREC,INPREC)  1
1093
1094 /* Define this if addresses of constant functions
1095    shouldn't be put through pseudo regs where they can be cse'd.
1096    Desirable on machines where ordinary constants are expensive
1097    but a CALL with constant address is cheap.  */
1098 /*#define NO_FUNCTION_CSE 1*/
1099
1100 /* Chars and shorts should be passed as ints.  */
1101 #define PROMOTE_PROTOTYPES 1
1102
1103 /* The machine modes of pointers and functions */
1104 #define Pmode  SImode
1105 #define FUNCTION_MODE  Pmode
1106
1107 /* The relative costs of various types of constants.  Note that cse.c defines
1108    REG = 1, SUBREG = 2, any node = (2 + sum of subnodes).  */
1109
1110 #define CONST_COSTS(RTX, CODE, OUTER_CODE)      \
1111   case CONST_INT:                               \
1112     if (INTVAL (RTX) == 0)                      \
1113       return 0;                                 \
1114     else if (CONST_OK_FOR_I (INTVAL (RTX)))     \
1115       return 1;                                 \
1116     else if ((OUTER_CODE == AND || OUTER_CODE == IOR || OUTER_CODE == XOR) \
1117              && CONST_OK_FOR_L (INTVAL (RTX)))  \
1118       return 1;                                 \
1119     else                                        \
1120       return 8;                                 \
1121   case CONST:                                   \
1122   case LABEL_REF:                               \
1123   case SYMBOL_REF:                              \
1124     return 5;                                   \
1125   case CONST_DOUBLE:                            \
1126       return 10;
1127
1128 #define RTX_COSTS(X, CODE, OUTER_CODE)                  \
1129   case AND:                                             \
1130     return COSTS_N_INSNS (andcosts (X));                \
1131   case MULT:                                            \
1132     return COSTS_N_INSNS (multcosts (X));               \
1133   case ASHIFT:                                          \
1134   case ASHIFTRT:                                        \
1135     return COSTS_N_INSNS (shiftcosts (X)) ;             \
1136   case DIV:                                             \
1137   case UDIV:                                            \
1138   case MOD:                                             \
1139   case UMOD:                                            \
1140     return COSTS_N_INSNS (20);                          \
1141   case FLOAT:                                           \
1142   case FIX:                                             \
1143     return 100;
1144
1145
1146 /* The multiply insn on the SH1 and the divide insns on the SH1 and SH2
1147    are actually function calls with some special constraints on arguments
1148    and register usage.
1149
1150    These macros tell reorg that the references to arguments and 
1151    register clobbers for insns of type sfunc do not appear to happen 
1152    until after the millicode call.  This allows reorg to put insns
1153    which set the argument registers into the delay slot of the millicode
1154    call -- thus they act more like traditional CALL_INSNs.
1155
1156    get_attr_type will try to recognize the given insn, so make sure to
1157    filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
1158    in particular.  */
1159
1160 #define INSN_SETS_ARE_DELAYED(X)                \
1161   ((GET_CODE (X) == INSN                        \
1162     && GET_CODE (PATTERN (X)) != SEQUENCE       \
1163     && GET_CODE (PATTERN (X)) != USE            \
1164     && GET_CODE (PATTERN (X)) != CLOBBER        \
1165     && get_attr_type (X) == TYPE_SFUNC))
1166
1167 #define INSN_REFERENCES_ARE_DELAYED(X)          \
1168   ((GET_CODE (X) == INSN                        \
1169     && GET_CODE (PATTERN (X)) != SEQUENCE       \
1170     && GET_CODE (PATTERN (X)) != USE            \
1171     && GET_CODE (PATTERN (X)) != CLOBBER        \
1172     && get_attr_type (X) == TYPE_SFUNC))        
1173
1174 /* Compute extra cost of moving data between one register class
1175    and another.  
1176
1177    On the SH it is hard to move into the T reg, but simple to load
1178    from it.
1179 */
1180
1181 #define REGISTER_MOVE_COST(SRCCLASS, DSTCLASS)  \
1182         (((DSTCLASS == T_REGS) || (DSTCLASS == PR_REG)) ? 10 : 1)
1183 \f
1184 /* Assembler output control */
1185
1186 /* The text to go at the start of the assembler file */
1187 #define ASM_FILE_START(STREAM)                                                  \
1188   output_file_start (STREAM, f_options, sizeof f_options / sizeof f_options[0], \
1189                      W_options, sizeof W_options / sizeof W_options[0]);        
1190
1191
1192 #define ASM_FILE_END(STREAM) 
1193
1194
1195 #define ASM_APP_ON              ""
1196 #define ASM_APP_OFF             ""
1197 #define FILE_ASM_OP             "\t.file\n"
1198 #define IDENT_ASM_OP            "\t.ident\n"
1199
1200 /* How to change between sections. */
1201
1202 #define TEXT_SECTION_ASM_OP             "\t.text"
1203 #define DATA_SECTION_ASM_OP             "\t.data"
1204 #define CTORS_SECTION_ASM_OP            "\t.section\t.ctors\n"
1205 #define DTORS_SECTION_ASM_OP            "\t.section\t.dtors\n"
1206 #define INIT_SECTION_ASM_OP             "\t.section\t.init\n"
1207 #define EXTRA_SECTIONS                  in_ctors, in_dtors
1208 #define EXTRA_SECTION_FUNCTIONS                              \
1209 void                                                         \
1210 ctors_section()                                              \
1211 {                                                            \
1212   if (in_section != in_ctors)                                \
1213     {                                                        \
1214       fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP);  \
1215       in_section = in_ctors;                                 \
1216     }                                                        \
1217 }                                                            \
1218 void                                                         \
1219 dtors_section()                                              \
1220 {                                                            \
1221   if (in_section != in_dtors)                                \
1222     {                                                        \
1223       fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP);  \
1224       in_section = in_dtors;                                 \
1225     }                                                        \
1226 }                                                            
1227
1228 /* A C statement to output something to the assembler file to switch to section
1229    NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
1230    NULL_TREE.  Some target formats do not support arbitrary sections.  Do not
1231    define this macro in such cases.  */
1232
1233 #define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME) \
1234    do { fprintf (FILE, ".section\t%s\n", NAME); } while (0)
1235
1236 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)       \
1237    do { ctors_section();  fprintf(FILE,"\t.long\t_%s\n", NAME); } while (0)
1238
1239 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)        \
1240    do {  dtors_section();  fprintf(FILE,"\t.long\t_%s\n", NAME); } while (0)
1241
1242 #undef DO_GLOBAL_CTORS_BODY                     
1243
1244 #define DO_GLOBAL_CTORS_BODY                    \
1245 {                                               \
1246   typedef (*pfunc)();                           \
1247   extern pfunc __ctors[];                       \
1248   extern pfunc __ctors_end[];                   \
1249   pfunc *p;                                     \
1250   for (p = __ctors_end; p > __ctors; )          \
1251     {                                           \
1252       (*--p)();                                 \
1253     }                                           \
1254 }                                               
1255
1256 #undef DO_GLOBAL_DTORS_BODY                      
1257 #define DO_GLOBAL_DTORS_BODY                    \
1258 {                                               \
1259   typedef (*pfunc)();                           \
1260   extern pfunc __dtors[];                       \
1261   extern pfunc __dtors_end[];                   \
1262   pfunc *p;                                     \
1263   for (p = __dtors; p < __dtors_end; p++)       \
1264     {                                           \
1265       (*p)();                                   \
1266     }                                           \
1267 }                                                
1268
1269
1270 #define ASM_OUTPUT_REG_PUSH(file, v) \
1271   fprintf (file, "\tmov.l       r%s,-@r15\n", v);
1272
1273 #define ASM_OUTPUT_REG_POP(file, v) \
1274   fprintf (file, "\tmov.l       @r15+,r%s\n", v);
1275
1276   
1277 /* The assembler's names for the registers.  RFP need not always be used as
1278    the Real framepointer; it can also be used as a normal general register.
1279    Note that the name `fp' is horribly misleading since `fp' is in fact only
1280    the argument-and-return-context pointer.  */
1281 #define REGISTER_NAMES                                  \
1282 {                                                       \
1283   "r0", "r1", "r2",  "r3",  "r4",  "r5",  "r6",  "r7",  \
1284   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", \
1285   "ap", "pr", "t",  "gbr", "mach","macl"                \
1286 }
1287
1288 /* DBX register number for a given compiler register number */
1289 #define DBX_REGISTER_NUMBER(REGNO)  (REGNO)
1290
1291 /* Output a label definition.  */
1292 #define ASM_OUTPUT_LABEL(FILE,NAME)  \
1293   do { assemble_name (FILE, NAME); fputs (":\n", FILE); } while (0)
1294
1295
1296 /* This is how to output an assembler line
1297    that says to advance the location counter
1298    to a multiple of 2**LOG bytes.  */
1299
1300 #define ASM_OUTPUT_ALIGN(FILE,LOG)      \
1301   if ((LOG) != 0)                       \
1302     fprintf (FILE, "\t.align %d\n", LOG)
1303
1304 /* Output a function label definition.  */
1305 #define ASM_DECLARE_FUNCTION_NAME(STREAM,NAME,DECL) \
1306     ASM_OUTPUT_LABEL(STREAM, NAME)
1307
1308 /* Output a globalising directive for a label.  */
1309 #define ASM_GLOBALIZE_LABEL(STREAM,NAME)  \
1310   (fprintf (STREAM, "\t.global\t"),       \
1311    assemble_name (STREAM, NAME),          \
1312    fputc ('\n',STREAM))                   \
1313
1314 /* Output a reference to a label.  */
1315 #define ASM_OUTPUT_LABELREF(STREAM,NAME)  \
1316   fprintf (STREAM, "_%s", NAME)
1317
1318 /* Make an internal label into a string.  */
1319 #define ASM_GENERATE_INTERNAL_LABEL(STRING, PREFIX, NUM)  \
1320   sprintf (STRING, "*%s%d", PREFIX, NUM)
1321
1322 /* Output an internal label definition.  */
1323 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM)      \
1324   fprintf (FILE, "%s%d:\n", PREFIX, NUM)
1325
1326 /* #define ASM_OUTPUT_CASE_END(STREAM,NUM,TABLE)            */
1327
1328 /* Construct a private name.  */
1329 #define ASM_FORMAT_PRIVATE_NAME(OUTVAR,NAME,NUMBER)  \
1330   ((OUTVAR) = (char *) alloca (strlen (NAME) + 10),  \
1331    sprintf ((OUTVAR), "%s.%d", (NAME), (NUMBER)))
1332
1333 /* Jump tables must be 32 bit aligned, no matter the size of the element */
1334 #define ASM_OUTPUT_CASE_LABEL(STREAM,PREFIX,NUM,TABLE) \
1335     fprintf (STREAM, "\t.align 2\n%s%d:\n",  PREFIX, NUM);
1336
1337 /* Output a relative address table. */
1338
1339 #define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM,VALUE,REL)                      \
1340   if (TARGET_BIGTABLE)                                                  \
1341         fprintf (STREAM, "\t.long       L%d-L%d\n", VALUE,REL);         \
1342   else                                                                  \
1343         fprintf (STREAM, "\t.word       L%d-L%d\n", VALUE,REL);         \
1344
1345 /* Output an absolute table element */
1346
1347 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM,VALUE)                           \
1348   if (TARGET_BIGTABLE)                                                  \
1349         fprintf (STREAM, "\t.long       L%d\n", VALUE);                 \
1350   else                                                                  \
1351         fprintf (STREAM, "\t.word       L%d\n", VALUE);                 \
1352
1353 /* Output various types of constants.  */
1354
1355
1356 /* This is how to output an assembler line defining a `double' */
1357
1358 #define ASM_OUTPUT_DOUBLE(FILE,VALUE)                   \
1359 do { char dstr[30];                                     \
1360      REAL_VALUE_TO_DECIMAL ((VALUE), "%.20e", dstr);    \
1361      fprintf (FILE, "\t.double %s\n", dstr);            \
1362    } while (0)
1363
1364
1365 /* This is how to output an assembler line defining a `float' constant.  */
1366 #define ASM_OUTPUT_FLOAT(FILE,VALUE)            \
1367 do { char dstr[30];                                     \
1368      REAL_VALUE_TO_DECIMAL ((VALUE), "%.20e", dstr);    \
1369      fprintf (FILE, "\t.float %s\n", dstr);             \
1370    } while (0)
1371
1372 #define ASM_OUTPUT_INT(STREAM, EXP)     \
1373   (fprintf (STREAM, "\t.long\t"),       \
1374    output_addr_const (STREAM, (EXP)),   \
1375    fputc ('\n', STREAM))                
1376
1377 #define ASM_OUTPUT_SHORT(STREAM, EXP)  \
1378   (fprintf (STREAM, "\t.short\t"),     \
1379    output_addr_const (STREAM, (EXP)),  \
1380    fputc ('\n', STREAM))                
1381
1382 #define ASM_OUTPUT_CHAR(STREAM, EXP)    \
1383   (fprintf (STREAM, "\t.byte\t"),       \
1384    output_addr_const (STREAM, (EXP)),   \
1385    fputc ('\n', STREAM))
1386
1387 #define ASM_OUTPUT_BYTE(STREAM, VALUE)          \
1388   fprintf (STREAM, "\t.byte\t%d\n", VALUE)      \
1389
1390 /* This is how to output an assembler line
1391    that says to advance the location counter by SIZE bytes.  */
1392
1393 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
1394   fprintf (FILE, "\t.space %d\n", (SIZE))
1395
1396 /* This says how to output an assembler line
1397    to define a global common symbol.  */
1398
1399 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)  \
1400 ( fputs ("\t.comm ", (FILE)),                   \
1401   assemble_name ((FILE), (NAME)),               \
1402   fprintf ((FILE), ",%d\n", (SIZE)))
1403
1404 /* This says how to output an assembler line
1405    to define a local common symbol.  */
1406
1407 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE,ROUNDED)      \
1408 ( fputs ("\t.lcomm ", (FILE)),                          \
1409   assemble_name ((FILE), (NAME)),                       \
1410   fprintf ((FILE), ",%d\n", (SIZE)))
1411
1412
1413 /* The assembler's parentheses characters.  */
1414 #define ASM_OPEN_PAREN "("
1415 #define ASM_CLOSE_PAREN ")"
1416
1417 /* Target characters.  */
1418 #define TARGET_BELL     007
1419 #define TARGET_BS       010
1420 #define TARGET_TAB      011
1421 #define TARGET_NEWLINE  012
1422 #define TARGET_VT       013
1423 #define TARGET_FF       014
1424 #define TARGET_CR       015
1425 \f
1426
1427 /* Only perform branch elimination (by making instructions conditional) if
1428    we're optimising.  Otherwise it's of no use anyway.  */
1429 #define FINAL_PRESCAN_INSN(INSN, OPVEC, NOPERANDS)  \
1430      final_prescan_insn (INSN, OPVEC, NOPERANDS)
1431
1432 /* Print operand X (an rtx) in assembler syntax to file FILE.
1433    CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
1434    For `%' followed by punctuation, CODE is the punctuation and X is null.  */
1435
1436 #define PRINT_OPERAND(STREAM, X, CODE)  print_operand (STREAM, X, CODE)
1437
1438 /* Print a memory address as an operand to reference that memory location.  */
1439
1440 #define PRINT_OPERAND_ADDRESS(STREAM,X)  print_operand_address (STREAM, X)
1441
1442 #define PRINT_OPERAND_PUNCT_VALID_P(CHAR) \
1443   ((CHAR)=='.' || (CHAR) == '#' || (CHAR)=='@')
1444
1445 \f
1446 extern struct rtx_def *sh_compare_op0;
1447 extern struct rtx_def *sh_compare_op1;
1448 extern struct rtx_def *prepare_scc_operands();
1449 extern struct rtx_def *table_lab;
1450
1451
1452 /* ??? Wrong, this is an incomplete enum type.  Fix this to do it the same
1453    way that the mips compiler does this.  */
1454 extern enum attr_cpu sh_cpu;    /* target cpu */
1455
1456 /* Declare functions defined in sh.c and used in templates. */
1457
1458 extern char *output_branch();
1459 extern char *output_shift();
1460 extern char *output_movedouble();
1461 extern char *output_movepcrel();
1462 extern char *output_jump_label_table();
1463 extern char *output_far_jump();
1464
1465
1466 #define MACHINE_DEPENDENT_REORG(X) machine_dependent_reorg(X)
1467
1468 /* Generate calls to memcpy, memcmp and memset.  */
1469
1470 #define TARGET_MEM_FUNCTIONS
1471
1472 #define HANDLE_PRAGMA(finput) return handle_pragma (finput)
1473
1474 /* Set when processing a function with pragma interrupt turned on. */
1475
1476 extern int pragma_interrupt;
1477 #define MOVE_RATIO (TARGET_SMALLCODE ? 4 : 16)
1478
1479 extern char *max_si;
1480 extern char *max_hi;
1481 extern int max_count_si;
1482 extern int max_count_hi;
1483 \f
1484 /* Instructions with unfilled delay slots take up an extra two bytes for
1485    the nop in the delay slot.  */
1486
1487 /* ??? Does this catch conditional branches when -m2?  */
1488
1489 #define ADJUST_INSN_LENGTH(X, LENGTH)                           \
1490   if (((GET_CODE (X) == INSN                                    \
1491         && GET_CODE (PATTERN (X)) != SEQUENCE                   \
1492         && GET_CODE (PATTERN (X)) != USE                        \
1493         && GET_CODE (PATTERN (X)) != CLOBBER)                   \
1494        || GET_CODE (X) == CALL_INSN                             \
1495        || (GET_CODE (X) == JUMP_INSN                            \
1496            && GET_CODE (PATTERN (X)) != ADDR_DIFF_VEC           \
1497            && GET_CODE (PATTERN (X)) != ADDR_VEC))              \
1498       && get_attr_needs_delay_slot (X) == NEEDS_DELAY_SLOT_YES) \
1499    LENGTH += 2;
1500
1501 /* Enable a bug fix for the shorten_branches pass.  */
1502 #define SHORTEN_WITH_ADJUST_INSN_LENGTH