OSDN Git Service

* Makefile.in (MACHMODE_H): Add @extra_modes_file@.
[pf3gnuchains/gcc-fork.git] / gcc / config / c4x / c4x.h
1 /* Definitions of target machine for GNU compiler.  TMS320C[34]x
2    Copyright (C) 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4
5    Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz)
6               and Herman Ten Brugge (Haj.Ten.Brugge@net.HCC.nl).
7
8    This file is part of GNU CC.
9
10    GNU CC is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2, or (at your option)
13    any later version.
14
15    GNU CC is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with GNU CC; see the file COPYING.  If not, write to
22    the Free Software Foundation, 59 Temple Place - Suite 330,
23    Boston, MA 02111-1307, USA.  */
24
25 #include "hwint.h"
26
27 /* RUN-TIME TARGET SPECIFICATION.  */
28
29 #define C4x   1
30
31 #define TARGET_CPU_CPP_BUILTINS()               \
32   do                                            \
33     {                                           \
34       if (!TARGET_SMALL)                        \
35         builtin_define ("_BIGMODEL");           \
36       if (!TARGET_MEMPARM)                      \
37         builtin_define ("_REGPARM");            \
38       if (flag_inline_functions)                \
39         builtin_define ("_INLINE");             \
40       if (TARGET_C3X)                           \
41         {                                       \
42           builtin_define ("_TMS320C3x");        \
43           builtin_define ("_C3x");              \
44           if (TARGET_C30)                       \
45             {                                   \
46               builtin_define ("_TMS320C30");    \
47               builtin_define ("_C30");          \
48             }                                   \
49           else if (TARGET_C31)                  \
50             {                                   \
51               builtin_define ("_TMS320C31");    \
52               builtin_define ("_C31");          \
53             }                                   \
54           else if (TARGET_C32)                  \
55             {                                   \
56               builtin_define ("_TMS320C32");    \
57               builtin_define ("_C32");          \
58             }                                   \
59           else if (TARGET_C33)                  \
60             {                                   \
61               builtin_define ("_TMS320C33");    \
62               builtin_define ("_C33");          \
63             }                                   \
64         }                                       \
65       else                                      \
66         {                                       \
67           builtin_define ("_TMS320C4x");        \
68           builtin_define ("_C4x");              \
69           if (TARGET_C40)                       \
70             {                                   \
71               builtin_define ("_TMS320C40");    \
72               builtin_define ("_C40");          \
73             }                                   \
74           else if (TARGET_C44)                  \
75             {                                   \
76               builtin_define ("_TMS320C44");    \
77               builtin_define ("_C44");          \
78             }                                   \
79         }                                       \
80     }                                           \
81   while (0)
82
83 /* Name of the c4x assembler.  */
84
85 #define ASM_PROG "c4x-as"
86
87 /* Name of the c4x linker.  */
88
89 #define LD_PROG "c4x-ld"
90
91 /* Define assembler options.  */
92
93 #define ASM_SPEC "\
94 %{!mcpu=30:%{!mcpu=31:%{!mcpu=32:%{!mcpu=33:%{!mcpu=40:%{!mcpu=44:\
95 %{!m30:%{!m40:-m40}}}}}}}} \
96 %{mcpu=30:-m30} \
97 %{mcpu=31:-m31} \
98 %{mcpu=32:-m32} \
99 %{mcpu=33:-m33} \
100 %{mcpu=40:-m40} \
101 %{mcpu=44:-m44} \
102 %{m30:-m30} \
103 %{m31:-m31} \
104 %{m32:-m32} \
105 %{m33:-m33} \
106 %{m40:-m40} \
107 %{m44:-m44} \
108 %{mmemparm:-p} %{mregparm:-r} \
109 %{!mmemparm:%{!mregparm:-r}} \
110 %{mbig:-b} %{msmall:-s} \
111 %{!msmall:%{!mbig:-b}}"
112
113 /* Define linker options.  */
114
115 #define LINK_SPEC "\
116 %{m30:--architecture c3x} \
117 %{m31:--architecture c3x} \
118 %{m32:--architecture c3x} \
119 %{m33:--architecture c3x} \
120 %{mcpu=30:--architecture c3x} \
121 %{mcpu=31:--architecture c3x} \
122 %{mcpu=32:--architecture c3x} \
123 %{mcpu=33:--architecture c3x}"
124
125 /* Specify the end file to link with.  */
126
127 #define ENDFILE_SPEC ""
128
129 /* Target compilation option flags.  */
130
131 #define SMALL_MEMORY_FLAG   0x0000001 /* Small memory model.  */
132 #define MPYI_FLAG           0x0000002 /* Use 24-bit MPYI for C3x.  */
133 #define FAST_FIX_FLAG       0x0000004 /* Fast fixing of floats.  */
134 #define RPTS_FLAG           0x0000008 /* Allow use of RPTS.  */
135 #define C3X_FLAG            0x0000010 /* Emit C3x code.  */
136 #define TI_FLAG             0x0000020 /* Be compatible with TI assembler.  */
137 #define PARANOID_FLAG       0x0000040 /* Be paranoid about DP reg. in ISRs.  */
138 #define MEMPARM_FLAG        0x0000080 /* Pass arguments on stack.  */
139 #define DEVEL_FLAG          0x0000100 /* Enable features under development.  */
140 #define RPTB_FLAG           0x0000200 /* Enable repeat block.  */
141 #define BK_FLAG             0x0000400 /* Use BK as general register.  */
142 #define DB_FLAG             0x0000800 /* Use decrement and branch for C3x.  */
143 #define DEBUG_FLAG          0x0001000 /* Enable debugging of GCC.  */
144 #define HOIST_FLAG          0x0002000 /* Force constants into registers.  */
145 #define LOOP_UNSIGNED_FLAG  0x0004000 /* Allow unsigned loop counters.  */
146 #define FORCE_FLAG          0x0008000 /* Force op0 and op1 to be same.  */
147 #define PRESERVE_FLOAT_FLAG 0x0010000 /* Save all 40 bits for floats.  */
148 #define PARALLEL_INSN_FLAG  0x0020000 /* Allow parallel insns.  */
149 #define PARALLEL_MPY_FLAG   0x0040000 /* Allow MPY||ADD, MPY||SUB insns.  */
150 #define ALIASES_FLAG        0x0080000 /* Assume mem refs possibly aliased.  */
151
152 #define C30_FLAG            0x0100000 /* Emit C30 code.  */
153 #define C31_FLAG            0x0200000 /* Emit C31 code.  */
154 #define C32_FLAG            0x0400000 /* Emit C32 code.  */
155 #define C33_FLAG            0x0400000 /* Emit C33 code.  */
156 #define C40_FLAG            0x1000000 /* Emit C40 code.  */
157 #define C44_FLAG            0x2000000 /* Emit C44 code.  */
158
159 /* Run-time compilation parameters selecting different hardware subsets.
160
161    Macro to define tables used to set the flags.
162    This is a list in braces of triplets in braces,
163    each pair being { "NAME", VALUE, "DESCRIPTION" }
164    where VALUE is the bits to set or minus the bits to clear.
165    An empty string NAME is used to identify the default VALUE.  */
166
167 #define TARGET_SWITCHES                                                 \
168 { { "small", SMALL_MEMORY_FLAG,                                         \
169     N_("Small memory model") },                                         \
170   { "big", -SMALL_MEMORY_FLAG,                                          \
171     N_("Big memory model") },                                           \
172   { "mpyi", MPYI_FLAG,                                                  \
173     N_("Use MPYI instruction for C3x") },                               \
174   { "no-mpyi", -MPYI_FLAG,                                              \
175     N_("Do not use MPYI instruction for C3x") },                        \
176   { "fast-fix", FAST_FIX_FLAG,                                          \
177     N_("Use fast but approximate float to integer conversion") },       \
178   { "no-fast-fix", -FAST_FIX_FLAG,                                      \
179     N_("Use slow but accurate float to integer conversion") },          \
180   { "rpts", RPTS_FLAG,                                                  \
181     N_("Enable use of RTPS instruction") },                             \
182   { "no-rpts", -RPTS_FLAG,                                              \
183     N_("Disable use of RTPS instruction") },                            \
184   { "rptb", RPTB_FLAG,                                                  \
185     N_("Enable use of RTPB instruction") },                             \
186   { "no-rptb", -RPTB_FLAG,                                              \
187     N_("Disable use of RTPB instruction") },                            \
188   { "30", C30_FLAG,                                                     \
189     N_("Generate code for C30 CPU")},                                   \
190   { "31", C31_FLAG,                                                     \
191     N_("Generate code for C31 CPU")},                                   \
192   { "32", C32_FLAG,                                                     \
193     N_("Generate code for C32 CPU")},                                   \
194   { "33", C33_FLAG,                                                     \
195     N_("Generate code for C33 CPU")},                                   \
196   { "40", C40_FLAG,                                                     \
197     N_("Generate code for C40 CPU")},                                   \
198   { "44", C44_FLAG,                                                     \
199     N_("Generate code for C44 CPU")},                                   \
200   { "ti", TI_FLAG,                                                      \
201     N_("Emit code compatible with TI tools")},                          \
202   { "no-ti", -TI_FLAG,                                                  \
203     N_("Emit code to use GAS extensions")},                             \
204   { "paranoid", PARANOID_FLAG,                                          \
205     N_("Save DP across ISR in small memory model") },                   \
206   { "no-paranoid", -PARANOID_FLAG,                                      \
207     N_("Don't save DP across ISR in small memory model") },             \
208   { "isr-dp-reload", PARANOID_FLAG,                                     \
209     N_("Save DP across ISR in small memory model") },                   \
210   { "no-isr-dp-reload", -PARANOID_FLAG,                                 \
211     N_("Don't save DP across ISR in small memory model") },             \
212   { "memparm", MEMPARM_FLAG,                                            \
213     N_("Pass arguments on the stack") },                                \
214   { "regparm", -MEMPARM_FLAG,                                           \
215     N_("Pass arguments in registers") },                                \
216   { "devel", DEVEL_FLAG,                                                \
217     N_("Enable new features under development") },                      \
218   { "no-devel", -DEVEL_FLAG,                                            \
219     N_("Disable new features under development") },                     \
220   { "bk", BK_FLAG,                                                      \
221     N_("Use the BK register as a general purpose register") },          \
222   { "no-bk", -BK_FLAG,                                                  \
223     N_("Do not allocate BK register") },                                \
224   { "db", DB_FLAG,                                                      \
225     N_("Enable use of DB instruction") },                               \
226   { "no-db", -DB_FLAG,                                                  \
227     N_("Disable use of DB instruction") },                              \
228   { "debug", DEBUG_FLAG,                                                \
229     N_("Enable debugging") },                                           \
230   { "no-debug", -DEBUG_FLAG,                                            \
231     N_("Disable debugging") },                                          \
232   { "hoist", HOIST_FLAG,                                                \
233     N_("Force constants into registers to improve hoisting") },         \
234   { "no-hoist", -HOIST_FLAG,                                            \
235     N_("Don't force constants into registers") },                       \
236   { "force", FORCE_FLAG,                                                \
237     N_("Force RTL generation to emit valid 3 operand insns") },         \
238   { "no-force", -FORCE_FLAG,                                            \
239     N_("Allow RTL generation to emit invalid 3 operand insns") },       \
240   { "loop-unsigned", LOOP_UNSIGNED_FLAG,                                \
241     N_("Allow unsigned interation counts for RPTB/DB") },               \
242   { "no-loop-unsigned", -LOOP_UNSIGNED_FLAG,                            \
243     N_("Disallow unsigned iteration counts for RPTB/DB") },             \
244   { "preserve-float", PRESERVE_FLOAT_FLAG,                              \
245     N_("Preserve all 40 bits of FP reg across call") },                 \
246   { "no-preserve-float", -PRESERVE_FLOAT_FLAG,                          \
247     N_("Only preserve 32 bits of FP reg across call") },                \
248   { "parallel-insns", PARALLEL_INSN_FLAG,                               \
249     N_("Enable parallel instructions") },                               \
250   { "no-parallel-insns", -PARALLEL_INSN_FLAG,                           \
251     N_("Disable parallel instructions") },                              \
252   { "parallel-mpy", PARALLEL_MPY_FLAG,                                  \
253     N_("Enable MPY||ADD and MPY||SUB instructions") },                  \
254   { "no-parallel-mpy", -PARALLEL_MPY_FLAG,                              \
255     N_("Disable MPY||ADD and MPY||SUB instructions") },                 \
256   { "aliases", ALIASES_FLAG,                                            \
257     N_("Assume that pointers may be aliased") },                        \
258   { "no-aliases", -ALIASES_FLAG,                                        \
259     N_("Assume that pointers not aliased") },                           \
260   { "", TARGET_DEFAULT, ""} }
261
262 /* Default target switches.  */
263
264 /* Play safe, not the fastest code.  */
265 #define TARGET_DEFAULT          ALIASES_FLAG | PARALLEL_INSN_FLAG \
266                                 | PARALLEL_MPY_FLAG | RPTB_FLAG
267
268 /* Caveats:
269    Max iteration count for RPTB/RPTS is 2^31 + 1.
270    Max iteration count for DB is 2^31 + 1 for C40, but 2^23 + 1 for C30.
271    RPTS blocks interrupts.  */
272
273
274 extern int target_flags;
275
276 #define TARGET_INLINE           (! optimize_size) /* Inline MPYI.  */
277 #define TARGET_SMALL_REG_CLASS  0
278
279 #define TARGET_SMALL            (target_flags & SMALL_MEMORY_FLAG)
280 #define TARGET_MPYI             (!TARGET_C3X || (target_flags & MPYI_FLAG))
281 #define TARGET_FAST_FIX         (target_flags & FAST_FIX_FLAG)
282 #define TARGET_RPTS             (target_flags & RPTS_FLAG)
283 #define TARGET_TI               (target_flags & TI_FLAG)
284 #define TARGET_PARANOID         (target_flags & PARANOID_FLAG)
285 #define TARGET_MEMPARM          (target_flags & MEMPARM_FLAG)
286 #define TARGET_DEVEL            (target_flags & DEVEL_FLAG)
287 #define TARGET_RPTB             (target_flags & RPTB_FLAG \
288                                  && optimize >= 2)
289 #define TARGET_BK               (target_flags & BK_FLAG)
290 #define TARGET_DB               (! TARGET_C3X || (target_flags & DB_FLAG))
291 #define TARGET_DEBUG            (target_flags & DEBUG_FLAG)
292 #define TARGET_HOIST            (target_flags & HOIST_FLAG)
293 #define TARGET_LOOP_UNSIGNED    (target_flags & LOOP_UNSIGNED_FLAG)
294 #define TARGET_FORCE            (target_flags & FORCE_FLAG)
295 #define TARGET_PRESERVE_FLOAT   (target_flags & PRESERVE_FLOAT_FLAG)
296 #define TARGET_PARALLEL         ((target_flags & PARALLEL_INSN_FLAG) \
297                                  && optimize >= 2)
298 #define TARGET_PARALLEL_MPY     (TARGET_PARALLEL \
299                                  && (target_flags & PARALLEL_MPY_FLAG))
300 #define TARGET_ALIASES          (target_flags & ALIASES_FLAG)
301
302 #define TARGET_C3X              (target_flags & C3X_FLAG)
303 #define TARGET_C30              (target_flags & C30_FLAG)
304 #define TARGET_C31              (target_flags & C31_FLAG)
305 #define TARGET_C32              (target_flags & C32_FLAG)
306 #define TARGET_C33              (target_flags & C33_FLAG)
307 #define TARGET_C40              (target_flags & C40_FLAG)
308 #define TARGET_C44              (target_flags & C44_FLAG)
309
310 /* Define some options to control code generation.  */
311 #define TARGET_LOAD_ADDRESS     (1 || (! TARGET_C3X && ! TARGET_SMALL))
312 /* Nonzero to convert direct memory references into HIGH/LO_SUM pairs
313    during RTL generation.  */
314 #define TARGET_EXPOSE_LDP       0
315 /* Nonzero to force loading of direct memory references into a register.  */
316 #define TARGET_LOAD_DIRECT_MEMS 0
317
318 /* -mrpts            allows the use of the RPTS instruction irregardless.
319    -mrpts=max-cycles will use RPTS if the number of cycles is constant
320    and less than max-cycles.  */
321
322 #define TARGET_RPTS_CYCLES(CYCLES) (TARGET_RPTS || (CYCLES) < c4x_rpts_cycles)
323
324 #define BCT_CHECK_LOOP_ITERATIONS  !(TARGET_LOOP_UNSIGNED)
325
326 /* -mcpu=XX    with XX = target DSP version number.  */
327
328 extern const char *c4x_rpts_cycles_string, *c4x_cpu_version_string;
329
330 #define TARGET_OPTIONS                                          \
331 { {"rpts=", &c4x_rpts_cycles_string,                            \
332    N_("Specify maximum number of iterations for RPTS") },       \
333   {"cpu=", &c4x_cpu_version_string,                             \
334    N_("Select CPU to generate code for") } }
335
336 /* Sometimes certain combinations of command options do not make sense
337    on a particular target machine.  You can define a macro
338    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
339    defined, is executed once just after all the command options have
340    been parsed.  */
341
342 #define OVERRIDE_OPTIONS c4x_override_options ()
343
344 /* Define this to change the optimizations performed by default.  */
345
346 #define OPTIMIZATION_OPTIONS(LEVEL,SIZE) c4x_optimization_options(LEVEL, SIZE)
347
348 /* Run Time Target Specification.  */
349
350 #define TARGET_VERSION fprintf (stderr, " (TMS320C[34]x, TI syntax)");
351
352 /* Storage Layout.  */
353
354 #define BITS_BIG_ENDIAN         0
355 #define BYTES_BIG_ENDIAN        0
356 #define WORDS_BIG_ENDIAN        0
357
358 /* Technically, we are little endian, but we put the floats out as
359    whole longs and this makes GCC put them out in the right order.  */
360
361 #define FLOAT_WORDS_BIG_ENDIAN  1
362
363 /* Note the ANSI C standard requires sizeof(char) = 1.  On the C[34]x
364    all integral and floating point data types are stored in memory as
365    32-bits (floating point types can be stored as 40-bits in the
366    extended precision registers), so sizeof(char) = sizeof(short) =
367    sizeof(int) = sizeof(long) = sizeof(float) = sizeof(double) = 1.  */
368
369 #define BITS_PER_UNIT           32
370 #define UNITS_PER_WORD          1
371 #define PARM_BOUNDARY           32
372 #define STACK_BOUNDARY          32
373 #define FUNCTION_BOUNDARY       32
374 #define BIGGEST_ALIGNMENT       32
375 #define EMPTY_FIELD_BOUNDARY    32
376 #define STRICT_ALIGNMENT        0
377 #define TARGET_FLOAT_FORMAT     C4X_FLOAT_FORMAT
378 #define MAX_FIXED_MODE_SIZE     64 /* HImode.  */
379
380 /* If a structure has a floating point field then force structure
381    to have BLKMODE.  */
382 #define MEMBER_TYPE_FORCES_BLK(FIELD) \
383   (TREE_CODE (TREE_TYPE (FIELD)) == REAL_TYPE)
384
385 /* Number of bits in the high and low parts of a two stage
386    load of an immediate constant.  */
387 #define BITS_PER_HIGH 16
388 #define BITS_PER_LO_SUM 16
389
390 /* Define register numbers.  */
391
392 /* Extended-precision registers.  */
393
394 #define R0_REGNO   0
395 #define R1_REGNO   1
396 #define R2_REGNO   2
397 #define R3_REGNO   3
398 #define R4_REGNO   4
399 #define R5_REGNO   5
400 #define R6_REGNO   6
401 #define R7_REGNO   7
402
403 /* Auxiliary (address) registers.  */
404
405 #define AR0_REGNO  8
406 #define AR1_REGNO  9
407 #define AR2_REGNO 10
408 #define AR3_REGNO 11
409 #define AR4_REGNO 12
410 #define AR5_REGNO 13
411 #define AR6_REGNO 14
412 #define AR7_REGNO 15
413
414 /* Data page register.  */
415
416 #define DP_REGNO  16
417
418 /* Index registers.  */
419
420 #define IR0_REGNO 17
421 #define IR1_REGNO 18
422
423 /* Block size register.  */
424
425 #define BK_REGNO  19
426
427 /* Stack pointer.  */
428
429 #define SP_REGNO  20
430
431 /* Status register.  */
432
433 #define ST_REGNO  21
434
435 /* Misc. interrupt registers.  */
436
437 #define DIE_REGNO 22            /* C4x only.  */
438 #define IE_REGNO  22            /* C3x only.  */
439 #define IIE_REGNO 23            /* C4x only.  */
440 #define IF_REGNO  23            /* C3x only.  */
441 #define IIF_REGNO 24            /* C4x only.  */
442 #define IOF_REGNO 24            /* C3x only.  */
443
444 /* Repeat block registers.  */
445
446 #define RS_REGNO  25
447 #define RE_REGNO  26
448 #define RC_REGNO  27
449
450 /* Additional extended-precision registers.  */
451
452 #define R8_REGNO  28            /* C4x only.  */
453 #define R9_REGNO  29            /* C4x only.  */
454 #define R10_REGNO 30            /* C4x only.  */
455 #define R11_REGNO 31            /* C4x only.  */
456
457 #define FIRST_PSEUDO_REGISTER   32
458
459 /* Extended precision registers (low set).  */
460
461 #define IS_R0R1_REGNO(r) \
462      ((unsigned int)((r) - R0_REGNO) <= (R1_REGNO - R0_REGNO))
463 #define IS_R2R3_REGNO(r) \
464      ((unsigned int)((r) - R2_REGNO) <= (R3_REGNO - R2_REGNO))   
465 #define IS_EXT_LOW_REGNO(r) \
466      ((unsigned int)((r) - R0_REGNO) <= (R7_REGNO - R0_REGNO))   
467
468 /* Extended precision registers (high set).  */
469
470 #define IS_EXT_HIGH_REGNO(r) \
471 (! TARGET_C3X \
472  && ((unsigned int) ((r) - R8_REGNO) <= (R11_REGNO - R8_REGNO)))
473
474 /* Address registers.  */
475
476 #define IS_AUX_REGNO(r) \
477     ((unsigned int)((r) - AR0_REGNO) <= (AR7_REGNO - AR0_REGNO))   
478 #define IS_ADDR_REGNO(r)   IS_AUX_REGNO(r)
479 #define IS_DP_REGNO(r)     ((r) == DP_REGNO)
480 #define IS_INDEX_REGNO(r)  (((r) == IR0_REGNO) || ((r) == IR1_REGNO))
481 #define IS_SP_REGNO(r)     ((r) == SP_REGNO)
482 #define IS_BK_REGNO(r)     (TARGET_BK && (r) == BK_REGNO)
483
484 /* Misc registers.  */
485
486 #define IS_ST_REGNO(r)     ((r) == ST_REGNO)
487 #define IS_RC_REGNO(r)     ((r) == RC_REGNO)
488 #define IS_REPEAT_REGNO(r) (((r) >= RS_REGNO) && ((r) <= RC_REGNO))
489
490 /* Composite register sets.  */
491
492 #define IS_ADDR_OR_INDEX_REGNO(r) (IS_ADDR_REGNO(r) || IS_INDEX_REGNO(r))
493 #define IS_EXT_REGNO(r)           (IS_EXT_LOW_REGNO(r) || IS_EXT_HIGH_REGNO(r))
494 #define IS_STD_REGNO(r)           (IS_ADDR_OR_INDEX_REGNO(r) \
495                                    || IS_REPEAT_REGNO(r) \
496                                    || IS_SP_REGNO(r) \
497                                    || IS_BK_REGNO(r))
498 #define IS_INT_REGNO(r)           (IS_EXT_REGNO(r) || IS_STD_REGNO(r))
499 #define IS_GROUP1_REGNO(r)        (IS_ADDR_OR_INDEX_REGNO(r) || IS_BK_REGNO(r))
500 #define IS_INT_CALL_SAVED_REGNO(r) (((r) == R4_REGNO) || ((r) == R5_REGNO) \
501                                     || ((r) == R8_REGNO))
502 #define IS_FLOAT_CALL_SAVED_REGNO(r) (((r) == R6_REGNO) || ((r) == R7_REGNO))
503
504 #define IS_PSEUDO_REGNO(r)            ((r) >= FIRST_PSEUDO_REGISTER)
505 #define IS_R0R1_OR_PSEUDO_REGNO(r)    (IS_R0R1_REGNO(r) || IS_PSEUDO_REGNO(r))
506 #define IS_R2R3_OR_PSEUDO_REGNO(r)    (IS_R2R3_REGNO(r) || IS_PSEUDO_REGNO(r))
507 #define IS_EXT_OR_PSEUDO_REGNO(r)     (IS_EXT_REGNO(r) || IS_PSEUDO_REGNO(r))
508 #define IS_STD_OR_PSEUDO_REGNO(r)     (IS_STD_REGNO(r) || IS_PSEUDO_REGNO(r))
509 #define IS_INT_OR_PSEUDO_REGNO(r)     (IS_INT_REGNO(r) || IS_PSEUDO_REGNO(r))
510 #define IS_ADDR_OR_PSEUDO_REGNO(r)    (IS_ADDR_REGNO(r) || IS_PSEUDO_REGNO(r))
511 #define IS_INDEX_OR_PSEUDO_REGNO(r)   (IS_INDEX_REGNO(r) || IS_PSEUDO_REGNO(r))
512 #define IS_EXT_LOW_OR_PSEUDO_REGNO(r) (IS_EXT_LOW_REGNO(r) \
513                                        || IS_PSEUDO_REGNO(r))
514 #define IS_DP_OR_PSEUDO_REGNO(r)      (IS_DP_REGNO(r) || IS_PSEUDO_REGNO(r))
515 #define IS_SP_OR_PSEUDO_REGNO(r)      (IS_SP_REGNO(r) || IS_PSEUDO_REGNO(r))
516 #define IS_ST_OR_PSEUDO_REGNO(r)      (IS_ST_REGNO(r) || IS_PSEUDO_REGNO(r))
517 #define IS_RC_OR_PSEUDO_REGNO(r)      (IS_RC_REGNO(r) || IS_PSEUDO_REGNO(r))
518
519 #define IS_PSEUDO_REG(op)          (IS_PSEUDO_REGNO(REGNO(op)))
520 #define IS_ADDR_REG(op)            (IS_ADDR_REGNO(REGNO(op)))
521 #define IS_INDEX_REG(op)           (IS_INDEX_REGNO(REGNO(op)))
522 #define IS_GROUP1_REG(r)           (IS_GROUP1_REGNO(REGNO(op)))
523 #define IS_SP_REG(op)              (IS_SP_REGNO(REGNO(op)))
524 #define IS_STD_REG(op)             (IS_STD_REGNO(REGNO(op)))
525 #define IS_EXT_REG(op)             (IS_EXT_REGNO(REGNO(op)))
526
527 #define IS_R0R1_OR_PSEUDO_REG(op)  (IS_R0R1_OR_PSEUDO_REGNO(REGNO(op)))
528 #define IS_R2R3_OR_PSEUDO_REG(op)  (IS_R2R3_OR_PSEUDO_REGNO(REGNO(op)))
529 #define IS_EXT_OR_PSEUDO_REG(op)   (IS_EXT_OR_PSEUDO_REGNO(REGNO(op)))
530 #define IS_STD_OR_PSEUDO_REG(op)   (IS_STD_OR_PSEUDO_REGNO(REGNO(op)))
531 #define IS_EXT_LOW_OR_PSEUDO_REG(op) (IS_EXT_LOW_OR_PSEUDO_REGNO(REGNO(op)))
532 #define IS_INT_OR_PSEUDO_REG(op)   (IS_INT_OR_PSEUDO_REGNO(REGNO(op)))
533
534 #define IS_ADDR_OR_PSEUDO_REG(op)  (IS_ADDR_OR_PSEUDO_REGNO(REGNO(op)))
535 #define IS_INDEX_OR_PSEUDO_REG(op) (IS_INDEX_OR_PSEUDO_REGNO(REGNO(op)))
536 #define IS_DP_OR_PSEUDO_REG(op)    (IS_DP_OR_PSEUDO_REGNO(REGNO(op)))
537 #define IS_SP_OR_PSEUDO_REG(op)    (IS_SP_OR_PSEUDO_REGNO(REGNO(op)))
538 #define IS_ST_OR_PSEUDO_REG(op)    (IS_ST_OR_PSEUDO_REGNO(REGNO(op)))
539 #define IS_RC_OR_PSEUDO_REG(op)    (IS_RC_OR_PSEUDO_REGNO(REGNO(op)))
540
541 /* 1 for registers that have pervasive standard uses
542    and are not available for the register allocator.  */
543
544 #define FIXED_REGISTERS \
545 {                                                                       \
546 /* R0  R1  R2  R3  R4  R5  R6  R7 AR0 AR1 AR2 AR3 AR4 AR5 AR6 AR7.  */  \
547     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,      \
548 /* DP IR0 IR1  BK  SP  ST DIE IIE IIF  RS  RE  RC  R8  R9 R10 R11.  */  \
549     1,  0,  0,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0       \
550 }
551
552 /* 1 for registers not available across function calls.
553    These must include the FIXED_REGISTERS and also any
554    registers that can be used without being saved.
555    The latter must include the registers where values are returned
556    and the register where structure-value addresses are passed.
557    Aside from that, you can include as many other registers as you like.  
558    
559    Note that the extended precision registers are only saved in some
560    modes.  The macro HARD_REGNO_CALL_CLOBBERED specifies which modes
561    get clobbered for a given regno.  */
562
563 #define CALL_USED_REGISTERS \
564 {                                                                       \
565 /* R0  R1  R2  R3  R4  R5  R6  R7 AR0 AR1 AR2 AR3 AR4 AR5 AR6 AR7.  */  \
566     1,  1,  1,  1,  0,  0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,      \
567 /* DP IR0 IR1  BK  SP  ST DIE IIE IIF  RS  RE  RC  R8  R9 R10 R11.  */  \
568     1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1       \
569 }
570
571 /* Macro to conditionally modify fixed_regs/call_used_regs.  */
572
573 #define CONDITIONAL_REGISTER_USAGE                      \
574   {                                                     \
575     if (! TARGET_BK)                                    \
576       {                                                 \
577         fixed_regs[BK_REGNO] = 1;                       \
578         call_used_regs[BK_REGNO] = 1;                   \
579         c4x_regclass_map[BK_REGNO] = NO_REGS;           \
580       }                                                 \
581     if (TARGET_C3X)                                     \
582       {                                                 \
583          int i;                                          \
584                                                          \
585          reg_names[DIE_REGNO] = "ie";  /* Clobber die.  */ \
586          reg_names[IF_REGNO] = "if";   /* Clobber iie.  */ \
587          reg_names[IOF_REGNO] = "iof"; /* Clobber iif.  */ \
588                                                         \
589          for (i = R8_REGNO; i <= R11_REGNO; i++)        \
590          {                                              \
591              fixed_regs[i] = call_used_regs[i] = 1;     \
592              c4x_regclass_map[i] = NO_REGS;             \
593          }                                              \
594       }                                                 \
595     if (TARGET_PRESERVE_FLOAT)                          \
596       {                                                 \
597         c4x_caller_save_map[R6_REGNO] = HFmode;         \
598         c4x_caller_save_map[R7_REGNO] = HFmode;         \
599       }                                                 \
600    }
601
602 /* Order of Allocation of Registers.  */
603
604 /* List the order in which to allocate registers.  Each register must be
605    listed once, even those in FIXED_REGISTERS.
606
607    First allocate registers that don't need preservation across calls,
608    except index and address registers.  Then allocate data registers
609    that require preservation across calls (even though this invokes an
610    extra overhead of having to save/restore these registers).  Next
611    allocate the address and index registers, since using these
612    registers for arithmetic can cause pipeline stalls.  Finally
613    allocated the fixed registers which won't be allocated anyhow.  */
614
615 #define REG_ALLOC_ORDER                                 \
616 {R0_REGNO, R1_REGNO, R2_REGNO, R3_REGNO,                \
617  R9_REGNO, R10_REGNO, R11_REGNO,                        \
618  RS_REGNO, RE_REGNO, RC_REGNO, BK_REGNO,                \
619  R4_REGNO, R5_REGNO, R6_REGNO, R7_REGNO, R8_REGNO,      \
620  AR0_REGNO, AR1_REGNO, AR2_REGNO, AR3_REGNO,            \
621  AR4_REGNO, AR5_REGNO, AR6_REGNO, AR7_REGNO,            \
622  IR0_REGNO, IR1_REGNO,                                  \
623  SP_REGNO, DP_REGNO, ST_REGNO, IE_REGNO, IF_REGNO, IOF_REGNO}
624
625 /* A C expression that is nonzero if hard register number REGNO2 can be
626    considered for use as a rename register for REGNO1 */
627
628 #define HARD_REGNO_RENAME_OK(REGNO1,REGNO2) \
629   c4x_hard_regno_rename_ok((REGNO1), (REGNO2))
630
631 /* Determine which register classes are very likely used by spill registers.
632    local-alloc.c won't allocate pseudos that have these classes as their
633    preferred class unless they are "preferred or nothing".  */
634
635 #define CLASS_LIKELY_SPILLED_P(CLASS) ((CLASS) == INDEX_REGS)
636
637 /* CCmode is wrongly defined in machmode.def.  It should have a size
638    of UNITS_PER_WORD.  HFmode is 40-bits and thus fits within a single
639    extended precision register.  Similarly, HCmode fits within two
640    extended precision registers.  */
641
642 #define HARD_REGNO_NREGS(REGNO, MODE)                           \
643 (((MODE) == CCmode || (MODE) == CC_NOOVmode) ? 1 : \
644  ((MODE) == HFmode) ? 1 : \
645  ((MODE) == HCmode) ? 2 : \
646  ((GET_MODE_SIZE(MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD))
647
648
649 /* A C expression that is nonzero if the hard register REGNO is preserved
650    across a call in mode MODE.  This does not have to include the call used
651    registers.  */
652
653 #define HARD_REGNO_CALL_PART_CLOBBERED(REGNO, MODE)                           \
654      ((IS_FLOAT_CALL_SAVED_REGNO (REGNO) && ! ((MODE) == QFmode))             \
655       || (IS_INT_CALL_SAVED_REGNO (REGNO)                                     \
656           && ! ((MODE) == QImode || (MODE) == HImode || (MODE) == Pmode)))
657
658 /* Specify the modes required to caller save a given hard regno.  */
659
660 #define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) (c4x_caller_save_map[REGNO])
661
662 #define HARD_REGNO_MODE_OK(REGNO, MODE) c4x_hard_regno_mode_ok(REGNO, MODE)
663
664 /* A C expression that is nonzero if it is desirable to choose
665    register allocation so as to avoid move instructions between a
666    value of mode MODE1 and a value of mode MODE2.
667
668    Value is 1 if it is a good idea to tie two pseudo registers
669    when one has mode MODE1 and one has mode MODE2.
670    If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2,
671    for any hard reg, then this must be 0 for correct output.  */
672
673 #define MODES_TIEABLE_P(MODE1, MODE2) 0
674
675
676 /* Define the classes of registers for register constraints in the
677    machine description.  Also define ranges of constants.
678
679    One of the classes must always be named ALL_REGS and include all hard regs.
680    If there is more than one class, another class must be named NO_REGS
681    and contain no registers.
682
683    The name GENERAL_REGS must be the name of a class (or an alias for
684    another name such as ALL_REGS).  This is the class of registers
685    that is allowed by "g" or "r" in a register constraint.
686    Also, registers outside this class are allocated only when
687    instructions express preferences for them.
688
689    The classes must be numbered in nondecreasing order; that is,
690    a larger-numbered class must never be contained completely
691    in a smaller-numbered class.
692
693    For any two classes, it is very desirable that there be another
694    class that represents their union.  */
695    
696 enum reg_class
697   {
698     NO_REGS,
699     R0R1_REGS,                  /* 't'.  */
700     R2R3_REGS,                  /* 'u'.  */
701     EXT_LOW_REGS,               /* 'q'.  */
702     EXT_REGS,                   /* 'f'.  */
703     ADDR_REGS,                  /* 'a'.  */
704     INDEX_REGS,                 /* 'x'.  */
705     BK_REG,                     /* 'k'.  */
706     SP_REG,                     /* 'b'.  */
707     RC_REG,                     /* 'v'.  */
708     COUNTER_REGS,               /*  */
709     INT_REGS,                   /* 'c'.  */
710     GENERAL_REGS,               /* 'r'.  */
711     DP_REG,                     /* 'z'.  */
712     ST_REG,                     /* 'y'.  */
713     ALL_REGS,
714     LIM_REG_CLASSES
715   };
716
717 #define N_REG_CLASSES (int) LIM_REG_CLASSES
718
719 #define REG_CLASS_NAMES \
720 {                       \
721    "NO_REGS",           \
722    "R0R1_REGS",         \
723    "R2R3_REGS",         \
724    "EXT_LOW_REGS",      \
725    "EXT_REGS",          \
726    "ADDR_REGS",         \
727    "INDEX_REGS",        \
728    "BK_REG",            \
729    "SP_REG",            \
730    "RC_REG",            \
731    "COUNTER_REGS",      \
732    "INT_REGS",          \
733    "GENERAL_REGS",      \
734    "DP_REG",            \
735    "ST_REG",            \
736    "ALL_REGS"           \
737 }
738
739 /* Define which registers fit in which classes.
740    This is an initializer for a vector of HARD_REG_SET
741    of length N_REG_CLASSES.  RC is not included in GENERAL_REGS
742    since the register allocator will often choose a general register
743    in preference to RC for the decrement_and_branch_on_count pattern.  */
744
745 #define REG_CLASS_CONTENTS \
746 {                                               \
747  {0x00000000}, /*     No registers.  */         \
748  {0x00000003}, /* 't' R0-R1     .  */           \
749  {0x0000000c}, /* 'u' R2-R3     .  */           \
750  {0x000000ff}, /* 'q' R0-R7     .  */           \
751  {0xf00000ff}, /* 'f' R0-R11       */           \
752  {0x0000ff00}, /* 'a' AR0-AR7.  */              \
753  {0x00060000}, /* 'x' IR0-IR1.  */              \
754  {0x00080000}, /* 'k' BK.  */                   \
755  {0x00100000}, /* 'b' SP.  */                   \
756  {0x08000000}, /* 'v' RC.  */                   \
757  {0x0800ff00}, /*     RC,AR0-AR7.  */           \
758  {0x0e1eff00}, /* 'c' AR0-AR7, IR0-IR1, BK, SP, RS, RE, RC.  */ \
759  {0xfe1effff}, /* 'r' R0-R11, AR0-AR7, IR0-IR1, BK, SP, RS, RE, RC.  */\
760  {0x00010000}, /* 'z' DP.  */                   \
761  {0x00200000}, /* 'y' ST.  */                   \
762  {0xffffffff}, /*     All registers.  */                \
763 }
764
765 /* The same information, inverted:
766    Return the class number of the smallest class containing
767    reg number REGNO.  This could be a conditional expression
768    or could index an array.  */
769
770 #define REGNO_REG_CLASS(REGNO) (c4x_regclass_map[REGNO])
771
772 /* When SMALL_REGISTER_CLASSES is defined, the lifetime of registers
773    explicitly used in the rtl is kept as short as possible.
774
775    We only need to define SMALL_REGISTER_CLASSES if TARGET_PARALLEL_MPY
776    is defined since the MPY|ADD insns require the classes R0R1_REGS and
777    R2R3_REGS which are used by the function return registers (R0,R1) and
778    the register arguments (R2,R3), respectively.  I'm reluctant to define
779    this macro since it stomps on many potential optimisations.  Ideally
780    it should have a register class argument so that not all the register
781    classes gets penalised for the sake of a naughty few...  For long
782    double arithmetic we need two additional registers that we can use as
783    spill registers.  */
784
785 #define SMALL_REGISTER_CLASSES (TARGET_SMALL_REG_CLASS && TARGET_PARALLEL_MPY)
786
787 #define BASE_REG_CLASS  ADDR_REGS
788 #define INDEX_REG_CLASS INDEX_REGS
789
790 /*
791   Register constraints for the C4x
792  
793   a - address reg (ar0-ar7)
794   b - stack reg (sp)
795   c - other gp int-only reg
796   d - data/int reg (equiv. to f)
797   f - data/float reg
798   h - data/long double reg (equiv. to f)
799   k - block count (bk)
800   q - r0-r7
801   t - r0-r1
802   u - r2-r3
803   v - repeat count (rc)
804   x - index register (ir0-ir1)
805   y - status register (st)
806   z - dp reg (dp) 
807
808   Memory/constant constraints for the C4x
809
810   G - short float 16-bit
811   I - signed 16-bit constant (sign extended)
812   J - signed 8-bit constant (sign extended)  (C4x only)
813   K - signed 5-bit constant (sign extended)  (C4x only for stik)
814   L - unsigned 16-bit constant
815   M - unsigned 8-bit constant                (C4x only)
816   N - ones complement of unsigned 16-bit constant
817   Q - indirect arx + 9-bit signed displacement
818       (a *-arx(n) or *+arx(n) is used to account for the sign bit)
819   R - indirect arx + 5-bit unsigned displacement  (C4x only)
820   S - indirect arx + 0, 1, or irn displacement
821   T - direct symbol ref
822   > - indirect with autoincrement
823   < - indirect with autodecrement
824   } - indirect with post-modify
825   { - indirect with pre-modify
826   */
827
828 #define REG_CLASS_FROM_LETTER(CC)                               \
829      ( ((CC) == 'a') ? ADDR_REGS                                \
830      : ((CC) == 'b') ? SP_REG                                   \
831      : ((CC) == 'c') ? INT_REGS                                 \
832      : ((CC) == 'd') ? EXT_REGS                                 \
833      : ((CC) == 'f') ? EXT_REGS                                 \
834      : ((CC) == 'h') ? EXT_REGS                                 \
835      : ((CC) == 'k') ? BK_REG                                   \
836      : ((CC) == 'q') ? EXT_LOW_REGS                             \
837      : ((CC) == 't') ? R0R1_REGS                                \
838      : ((CC) == 'u') ? R2R3_REGS                                \
839      : ((CC) == 'v') ? RC_REG                                   \
840      : ((CC) == 'x') ? INDEX_REGS                               \
841      : ((CC) == 'y') ? ST_REG                                   \
842      : ((CC) == 'z') ? DP_REG                                   \
843      : NO_REGS )
844
845 /* These assume that REGNO is a hard or pseudo reg number.
846    They give nonzero only if REGNO is a hard reg of the suitable class
847    or a pseudo reg currently allocated to a suitable hard reg.
848    Since they use reg_renumber, they are safe only once reg_renumber
849    has been allocated, which happens in local-alloc.c.  */
850
851 #define REGNO_OK_FOR_BASE_P(REGNO)  \
852      (IS_ADDR_REGNO(REGNO) || IS_ADDR_REGNO((unsigned)reg_renumber[REGNO]))
853
854 #define REGNO_OK_FOR_INDEX_P(REGNO) \
855      (IS_INDEX_REGNO(REGNO) || IS_INDEX_REGNO((unsigned)reg_renumber[REGNO]))
856
857 /* If we have to generate framepointer + constant prefer an ADDR_REGS
858    register.  This avoids using EXT_REGS in addqi3_noclobber_reload.  */
859
860 #define PREFERRED_RELOAD_CLASS(X, CLASS)                        \
861      (GET_CODE (X) == PLUS                                      \
862       && GET_MODE (X) == Pmode                                  \
863       && GET_CODE (XEXP ((X), 0)) == REG                        \
864       && GET_MODE (XEXP ((X), 0)) == Pmode                      \
865       && REGNO (XEXP ((X), 0)) == FRAME_POINTER_REGNUM          \
866       && GET_CODE (XEXP ((X), 1)) == CONST_INT                  \
867         ? ADDR_REGS : (CLASS))
868
869 #define LIMIT_RELOAD_CLASS(X, CLASS) (CLASS)
870
871 #define SECONDARY_MEMORY_NEEDED(CLASS1, CLASS2, MODE) 0
872
873 #define CLASS_MAX_NREGS(CLASS, MODE)                    \
874 (((MODE) == CCmode || (MODE) == CC_NOOVmode) ? 1 : ((MODE) == HFmode) ? 1 : \
875 ((GET_MODE_SIZE(MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD))
876
877 #define IS_INT5_CONST(VAL) (((VAL) <= 15) && ((VAL) >= -16))    /* 'K'.  */
878
879 #define IS_UINT5_CONST(VAL) (((VAL) <= 31) && ((VAL) >= 0))     /* 'R'.  */
880
881 #define IS_INT8_CONST(VAL) (((VAL) <= 127) && ((VAL) >= -128))  /* 'J'.  */
882
883 #define IS_UINT8_CONST(VAL) (((VAL) <= 255) && ((VAL) >= 0))    /* 'M'.  */
884
885 #define IS_INT16_CONST(VAL) (((VAL) <= 32767) && ((VAL) >= -32768)) /* 'I'.  */
886
887 #define IS_UINT16_CONST(VAL) (((VAL) <= 65535) && ((VAL) >= 0)) /* 'L'.  */
888
889 #define IS_NOT_UINT16_CONST(VAL) IS_UINT16_CONST(~(VAL))        /* 'N'.  */
890
891 #define IS_HIGH_CONST(VAL) \
892 (! TARGET_C3X && (((VAL) & 0xffff) == 0)) /* 'O'.  */
893
894
895 #define IS_DISP1_CONST(VAL) (((VAL) <= 1) && ((VAL) >= -1)) /* 'S'.  */
896
897 #define IS_DISP8_CONST(VAL) (((VAL) <= 255) && ((VAL) >= -255)) /* 'Q'.  */
898
899 #define IS_DISP1_OFF_CONST(VAL) (IS_DISP1_CONST (VAL) \
900                                  && IS_DISP1_CONST (VAL + 1))
901
902 #define IS_DISP8_OFF_CONST(VAL) (IS_DISP8_CONST (VAL) \
903                                  && IS_DISP8_CONST (VAL + 1))
904
905 #define CONST_OK_FOR_LETTER_P(VAL, C)                                   \
906         ( ((C) == 'I') ? (IS_INT16_CONST (VAL))                         \
907         : ((C) == 'J') ? (! TARGET_C3X && IS_INT8_CONST (VAL))          \
908         : ((C) == 'K') ? (! TARGET_C3X && IS_INT5_CONST (VAL))          \
909         : ((C) == 'L') ? (IS_UINT16_CONST (VAL))                        \
910         : ((C) == 'M') ? (! TARGET_C3X && IS_UINT8_CONST (VAL))         \
911         : ((C) == 'N') ? (IS_NOT_UINT16_CONST (VAL))                    \
912         : ((C) == 'O') ? (IS_HIGH_CONST (VAL))                          \
913         : 0 )   
914
915 #define CONST_DOUBLE_OK_FOR_LETTER_P(OP, C)                             \
916         ( ((C) == 'G') ? (fp_zero_operand (OP, QFmode))                 \
917         : ((C) == 'H') ? (c4x_H_constant (OP))                          \
918         : 0 )
919
920 #define EXTRA_CONSTRAINT(OP, C) \
921         ( ((C) == 'Q') ? (c4x_Q_constraint (OP))                        \
922         : ((C) == 'R') ? (c4x_R_constraint (OP))                        \
923         : ((C) == 'S') ? (c4x_S_constraint (OP))                        \
924         : ((C) == 'T') ? (c4x_T_constraint (OP))                        \
925         : ((C) == 'U') ? (c4x_U_constraint (OP))                        \
926         : 0 )
927
928 #define SMALL_CONST(VAL, insn)                                          \
929      (  ((insn == NULL_RTX) || (get_attr_data (insn) == DATA_INT16))    \
930         ? IS_INT16_CONST (VAL)                                          \
931         : ( (get_attr_data (insn) == DATA_NOT_UINT16)                   \
932             ? IS_NOT_UINT16_CONST (VAL)                                 \
933             :  ( (get_attr_data (insn) == DATA_HIGH_16)                 \
934                ? IS_HIGH_CONST (VAL)                                    \
935                : IS_UINT16_CONST (VAL)                                  \
936             )                                                           \
937           )                                                             \
938         )
939
940 /*
941    I. Routine calling with arguments in registers
942    ----------------------------------------------
943
944    The TI C3x compiler has a rather unusual register passing algorithm.
945    Data is passed in the following registers (in order):
946
947    AR2, R2, R3, RC, RS, RE
948
949    However, the first and second floating point values are always in R2
950    and R3 (and all other floats are on the stack).  Structs are always
951    passed on the stack.  If the last argument is an ellipsis, the
952    previous argument is passed on the stack so that its address can be
953    taken for the stdargs macros.
954
955    Because of this, we have to pre-scan the list of arguments to figure
956    out what goes where in the list.
957
958    II. Routine calling with arguments on stack
959    -------------------------------------------
960
961    Let the subroutine declared as "foo(arg0, arg1, arg2);" have local
962    variables loc0, loc1, and loc2.  After the function prologue has
963    been executed, the stack frame will look like:
964
965    [stack grows towards increasing addresses]
966        I-------------I
967    5   I saved reg1  I  <= SP points here
968        I-------------I
969    4   I saved reg0  I  
970        I-------------I
971    3   I       loc2  I  
972        I-------------I  
973    2   I       loc1  I  
974        I-------------I  
975    1   I       loc0  I  
976        I-------------I
977    0   I     old FP  I <= FP (AR3) points here
978        I-------------I
979    -1  I  return PC  I
980        I-------------I
981    -2  I       arg0  I  
982        I-------------I  
983    -3  I       arg1  I
984        I-------------I  
985    -4  I       arg2  I 
986        I-------------I  
987
988    All local variables (locn) are accessible by means of +FP(n+1)
989    addressing, where n is the local variable number.
990
991    All stack arguments (argn) are accessible by means of -FP(n-2).
992
993    The stack pointer (SP) points to the last register saved in the
994    prologue (regn).
995
996    Note that a push instruction performs a preincrement of the stack
997    pointer.  (STACK_PUSH_CODE == PRE_INC)
998
999    III. Registers used in function calling convention
1000    --------------------------------------------------
1001
1002    Preserved across calls: R4...R5 (only by PUSH,  i.e. lower 32 bits)
1003    R6...R7 (only by PUSHF, i.e. upper 32 bits)
1004    AR3...AR7
1005
1006    (Because of this model, we only assign FP values in R6, R7 and
1007    only assign integer values in R4, R5.)
1008
1009    These registers are saved at each function entry and restored at
1010    the exit. Also it is expected any of these not affected by any
1011    call to user-defined (not service) functions.
1012
1013    Not preserved across calls: R0...R3
1014    R4...R5 (upper 8 bits)
1015    R6...R7 (lower 8 bits)
1016    AR0...AR2, IR0, IR1, BK, ST, RS, RE, RC
1017
1018    These registers are used arbitrary in a function without being preserved.
1019    It is also expected that any of these can be clobbered by any call.
1020
1021    Not used by GCC (except for in user "asm" statements):
1022    IE (DIE), IF (IIE), IOF (IIF)
1023
1024    These registers are never used by GCC for any data, but can be used
1025    with "asm" statements.  */
1026
1027 #define C4X_ARG0 -2
1028 #define C4X_LOC0 1
1029
1030 /* Basic Stack Layout.  */
1031      
1032 /* The stack grows upward, stack frame grows upward, and args grow
1033    downward.  */
1034
1035 #define STARTING_FRAME_OFFSET           C4X_LOC0
1036 #define FIRST_PARM_OFFSET(FNDECL)      (C4X_ARG0 + 1)
1037 #define ARGS_GROW_DOWNWARD
1038 #define STACK_POINTER_OFFSET 1
1039
1040 /* Define this if pushing a word on the stack
1041    makes the stack pointer a smaller address.  */
1042
1043 /* #define STACK_GROWS_DOWNWARD.  */
1044 /* Like the dsp16xx, i370, i960, and we32k ports.  */
1045
1046 /* Define this if the nominal address of the stack frame
1047    is at the high-address end of the local variables;
1048    that is, each additional local variable allocated
1049    goes at a more negative offset in the frame.  */
1050
1051 /* #define FRAME_GROWS_DOWNWARD.  */
1052
1053
1054 /* Registers That Address the Stack Frame.  */
1055
1056 #define STACK_POINTER_REGNUM    SP_REGNO        /* SP.  */
1057 #define FRAME_POINTER_REGNUM    AR3_REGNO       /* AR3.  */
1058 #define ARG_POINTER_REGNUM      AR3_REGNO       /* AR3.  */
1059 #define STATIC_CHAIN_REGNUM     AR0_REGNO       /* AR0.  */
1060
1061 /* Eliminating Frame Pointer and Arg Pointer.  */
1062
1063 #define FRAME_POINTER_REQUIRED  0
1064
1065 #define INITIAL_FRAME_POINTER_OFFSET(DEPTH)                     \
1066 {                                                               \
1067  int regno;                                                     \
1068  int offset = 0;                                                \
1069   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)       \
1070     if (regs_ever_live[regno] && ! call_used_regs[regno])       \
1071       offset += TARGET_PRESERVE_FLOAT                           \
1072                 && IS_FLOAT_CALL_SAVED_REGNO (regno) ? 2 : 1;   \
1073   (DEPTH) = -(offset + get_frame_size ());                      \
1074 }
1075
1076 /* This is a hack...  We need to specify a register.  */
1077 #define ELIMINABLE_REGS                                         \
1078   {{ FRAME_POINTER_REGNUM, FRAME_POINTER_REGNUM }}
1079
1080 #define CAN_ELIMINATE(FROM, TO)                                 \
1081   (! (((FROM) == FRAME_POINTER_REGNUM && (TO) == STACK_POINTER_REGNUM) \
1082   || ((FROM) == FRAME_POINTER_REGNUM && (TO) == FRAME_POINTER_REGNUM)))
1083
1084 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET)            \
1085 {                                                               \
1086  int regno;                                                     \
1087  int offset = 0;                                                \
1088   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)       \
1089     if (regs_ever_live[regno] && ! call_used_regs[regno])       \
1090       offset += TARGET_PRESERVE_FLOAT                           \
1091                 && IS_FLOAT_CALL_SAVED_REGNO (regno) ? 2 : 1;   \
1092   (OFFSET) = -(offset + get_frame_size ());                     \
1093 }
1094
1095
1096 /* Passing Function Arguments on the Stack.  */
1097
1098 #define PUSH_ARGS 1
1099 #define PUSH_ROUNDING(BYTES) (BYTES)
1100 #define RETURN_POPS_ARGS(FUNDECL, FUNTYPE, STACK_SIZE) 0
1101
1102 /* The following structure is used by calls.c, function.c, c4x.c.  */
1103
1104 typedef struct c4x_args
1105 {
1106   int floats;
1107   int ints;
1108   int maxfloats;
1109   int maxints;
1110   int init;
1111   int var;
1112   int prototype;
1113   int args;
1114 }
1115 CUMULATIVE_ARGS;
1116
1117 #define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,INDIRECT)       \
1118   (c4x_init_cumulative_args (&CUM, FNTYPE, LIBNAME))
1119
1120 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)    \
1121   (c4x_function_arg_advance (&CUM, MODE, TYPE, NAMED))
1122
1123 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
1124   (c4x_function_arg(&CUM, MODE, TYPE, NAMED))
1125
1126 /* Define the profitability of saving registers around calls.
1127    We disable caller save to avoid a bug in flow.c (this also affects
1128    other targets such as m68k).  Since we must use stf/sti,
1129    the profitability is marginal anyway.  */
1130
1131 #define CALLER_SAVE_PROFITABLE(REFS,CALLS) 0
1132
1133 /* Never pass data by reference.  */
1134
1135 #define FUNCTION_ARG_PASS_BY_REFERENCE(CUM, MODE, TYPE, NAMED) 0
1136
1137 #define FUNCTION_ARG_PARTIAL_NREGS(CUM, MODE, TYPE, NAMED) 0
1138
1139 /* 1 if N is a possible register number for function argument passing.  */
1140
1141 #define FUNCTION_ARG_REGNO_P(REGNO) \
1142         (  (   ((REGNO) == AR2_REGNO)   /* AR2.  */     \
1143             || ((REGNO) == R2_REGNO)    /* R2.  */      \
1144             || ((REGNO) == R3_REGNO)    /* R3.  */      \
1145             || ((REGNO) == RC_REGNO)    /* RC.  */      \
1146             || ((REGNO) == RS_REGNO)    /* RS.  */      \
1147             || ((REGNO) == RE_REGNO))   /* RE.  */      \
1148          ? 1                                            \
1149          : 0)
1150
1151 /* How Scalar Function Values Are Returned.  */
1152
1153 #define FUNCTION_VALUE(VALTYPE, FUNC) \
1154         gen_rtx(REG, TYPE_MODE(VALTYPE), R0_REGNO)      /* Return in R0.  */
1155
1156 #define LIBCALL_VALUE(MODE) \
1157         gen_rtx(REG, MODE, R0_REGNO)    /* Return in R0.  */
1158
1159 #define FUNCTION_VALUE_REGNO_P(REGNO) ((REGNO) == R0_REGNO)
1160
1161 /* How Large Values Are Returned.  */
1162
1163 #define DEFAULT_PCC_STRUCT_RETURN       0
1164 #define STRUCT_VALUE_REGNUM             AR0_REGNO       /* AR0.  */
1165
1166 /* Varargs handling.  */
1167
1168 #define EXPAND_BUILTIN_VA_START(stdarg, valist, nextarg) \
1169   c4x_va_start (stdarg, valist, nextarg)
1170
1171 #define EXPAND_BUILTIN_VA_ARG(valist, type) \
1172   c4x_va_arg (valist, type)
1173
1174 /* Generating Code for Profiling.  */
1175
1176 /* Note that the generated assembly uses the ^ operator to load the 16
1177    MSBs of the address.  This is not supported by the TI assembler. 
1178    The FUNCTION profiler needs a function mcount which gets passed
1179    a pointer to the LABELNO.  */
1180
1181 #define FUNCTION_PROFILER(FILE, LABELNO)                        \
1182      if (! TARGET_C3X)                                          \
1183      {                                                          \
1184         fprintf (FILE, "\tpush\tar2\n");                        \
1185         fprintf (FILE, "\tldhi\t^LP%d,ar2\n", (LABELNO));       \
1186         fprintf (FILE, "\tor\t#LP%d,ar2\n", (LABELNO));         \
1187         fprintf (FILE, "\tcall\tmcount\n");                     \
1188         fprintf (FILE, "\tpop\tar2\n");                         \
1189      }                                                          \
1190      else                                                       \
1191      {                                                          \
1192         fprintf (FILE, "\tpush\tar2\n");                        \
1193         fprintf (FILE, "\tldiu\t^LP%d,ar2\n", (LABELNO));       \
1194         fprintf (FILE, "\tlsh\t16,ar2\n");                      \
1195         fprintf (FILE, "\tor\t#LP%d,ar2\n", (LABELNO));         \
1196         fprintf (FILE, "\tcall\tmcount\n");                     \
1197         fprintf (FILE, "\tpop\tar2\n");                         \
1198      }
1199
1200 /* Implicit Calls to Library Routines.  */
1201
1202 #define MULQI3_LIBCALL      "__mulqi3"
1203 #define DIVQI3_LIBCALL      "__divqi3"
1204 #define UDIVQI3_LIBCALL     "__udivqi3"
1205 #define MODQI3_LIBCALL      "__modqi3"
1206 #define UMODQI3_LIBCALL     "__umodqi3"
1207
1208 #define DIVQF3_LIBCALL      "__divqf3"
1209
1210 #define MULHF3_LIBCALL      "__mulhf3"
1211 #define DIVHF3_LIBCALL      "__divhf3"
1212
1213 #define MULHI3_LIBCALL      "__mulhi3"
1214 #define SMULHI3_LIBCALL     "__smulhi3_high"
1215 #define UMULHI3_LIBCALL     "__umulhi3_high"
1216 #define DIVHI3_LIBCALL      "__divhi3"
1217 #define UDIVHI3_LIBCALL     "__udivhi3"
1218 #define MODHI3_LIBCALL      "__modhi3"
1219 #define UMODHI3_LIBCALL     "__umodhi3"
1220
1221 #define FLOATHIQF2_LIBCALL  "__floathiqf2"
1222 #define FLOATUNSHIQF2_LIBCALL  "__ufloathiqf2"
1223 #define FIX_TRUNCQFHI2_LIBCALL "__fix_truncqfhi2"
1224 #define FIXUNS_TRUNCQFHI2_LIBCALL "__ufix_truncqfhi2"
1225
1226 #define FLOATHIHF2_LIBCALL  "__floathihf2"
1227 #define FLOATUNSHIHF2_LIBCALL  "__ufloathihf2"
1228 #define FIX_TRUNCHFHI2_LIBCALL "__fix_trunchfhi2"
1229 #define FIXUNS_TRUNCHFHI2_LIBCALL "__ufix_trunchfhi2"
1230
1231 #define FFS_LIBCALL         "__ffs"
1232
1233 #define INIT_TARGET_OPTABS \
1234   do { \
1235     smul_optab->handlers[(int) QImode].libfunc          \
1236       = init_one_libfunc (MULQI3_LIBCALL);              \
1237     sdiv_optab->handlers[(int) QImode].libfunc          \
1238       = init_one_libfunc (DIVQI3_LIBCALL);              \
1239     udiv_optab->handlers[(int) QImode].libfunc          \
1240       = init_one_libfunc (UDIVQI3_LIBCALL);             \
1241     smod_optab->handlers[(int) QImode].libfunc          \
1242       = init_one_libfunc (MODQI3_LIBCALL);              \
1243     umod_optab->handlers[(int) QImode].libfunc          \
1244       = init_one_libfunc (UMODQI3_LIBCALL);             \
1245     sdiv_optab->handlers[(int) QFmode].libfunc          \
1246       = init_one_libfunc (DIVQF3_LIBCALL);              \
1247     smul_optab->handlers[(int) HFmode].libfunc          \
1248       = init_one_libfunc (MULHF3_LIBCALL);              \
1249     sdiv_optab->handlers[(int) HFmode].libfunc          \
1250       = init_one_libfunc (DIVHF3_LIBCALL);              \
1251     smul_optab->handlers[(int) HImode].libfunc          \
1252       = init_one_libfunc (MULHI3_LIBCALL);              \
1253     sdiv_optab->handlers[(int) HImode].libfunc          \
1254       = init_one_libfunc (DIVHI3_LIBCALL);              \
1255     udiv_optab->handlers[(int) HImode].libfunc          \
1256       = init_one_libfunc (UDIVHI3_LIBCALL);             \
1257     smod_optab->handlers[(int) HImode].libfunc          \
1258       = init_one_libfunc (MODHI3_LIBCALL);              \
1259     umod_optab->handlers[(int) HImode].libfunc          \
1260       = init_one_libfunc (UMODHI3_LIBCALL);             \
1261     ffs_optab->handlers[(int) QImode].libfunc           \
1262       = init_one_libfunc (FFS_LIBCALL);                 \
1263     smulhi3_libfunc                                     \
1264       = init_one_libfunc(SMULHI3_LIBCALL);              \
1265     umulhi3_libfunc                                     \
1266       = init_one_libfunc(UMULHI3_LIBCALL);              \
1267     fix_truncqfhi2_libfunc                              \
1268       = init_one_libfunc(FIX_TRUNCQFHI2_LIBCALL);       \
1269     fixuns_truncqfhi2_libfunc                           \
1270       = init_one_libfunc(FIXUNS_TRUNCQFHI2_LIBCALL);    \
1271     fix_trunchfhi2_libfunc                              \
1272       = init_one_libfunc(FIX_TRUNCHFHI2_LIBCALL);       \
1273     fixuns_trunchfhi2_libfunc                           \
1274       = init_one_libfunc(FIXUNS_TRUNCHFHI2_LIBCALL);    \
1275     floathiqf2_libfunc                                  \
1276       = init_one_libfunc(FLOATHIQF2_LIBCALL);           \
1277     floatunshiqf2_libfunc                               \
1278       = init_one_libfunc(FLOATUNSHIQF2_LIBCALL);        \
1279     floathihf2_libfunc                                  \
1280       = init_one_libfunc(FLOATHIHF2_LIBCALL);           \
1281     floatunshihf2_libfunc                               \
1282       = init_one_libfunc(FLOATUNSHIHF2_LIBCALL);        \
1283   } while (0)
1284
1285 #define TARGET_MEM_FUNCTIONS
1286
1287 /* CC_NOOVmode should be used when the first operand is a PLUS, MINUS, NEG
1288    or MULT.
1289    CCmode should be used when no special processing is needed.  */
1290 #define SELECT_CC_MODE(OP,X,Y) \
1291   ((GET_CODE (X) == PLUS || GET_CODE (X) == MINUS               \
1292     || GET_CODE (X) == NEG || GET_CODE (X) == MULT              \
1293     || GET_MODE (X) == ABS                                      \
1294     || GET_CODE (Y) == PLUS || GET_CODE (Y) == MINUS            \
1295     || GET_CODE (Y) == NEG || GET_CODE (Y) == MULT              \
1296     || GET_MODE (Y) == ABS)                                     \
1297     ? CC_NOOVmode : CCmode)
1298
1299 /* Addressing Modes.  */
1300
1301 #define HAVE_POST_INCREMENT 1
1302 #define HAVE_PRE_INCREMENT 1
1303 #define HAVE_POST_DECREMENT 1
1304 #define HAVE_PRE_DECREMENT 1
1305 #define HAVE_PRE_MODIFY_REG 1
1306 #define HAVE_POST_MODIFY_REG 1
1307 #define HAVE_PRE_MODIFY_DISP 1
1308 #define HAVE_POST_MODIFY_DISP 1
1309
1310 /* The number of insns that can be packed into a single opcode.  */
1311 #define PACK_INSNS 2
1312
1313 /* Recognize any constant value that is a valid address. 
1314    We could allow arbitrary constant addresses in the large memory
1315    model but for the small memory model we can only accept addresses
1316    within the data page.  I suppose we could also allow
1317    CONST PLUS SYMBOL_REF.  */
1318 #define CONSTANT_ADDRESS_P(X) (GET_CODE (X) == SYMBOL_REF)
1319
1320 /* Maximum number of registers that can appear in a valid memory
1321    address.  */
1322 #define MAX_REGS_PER_ADDRESS    2
1323
1324 /* The macros REG_OK_FOR..._P assume that the arg is a REG rtx
1325    and check its validity for a certain class.
1326    We have two alternate definitions for each of them.
1327    The usual definition accepts all pseudo regs; the other rejects
1328    them unless they have been allocated suitable hard regs.
1329    The symbol REG_OK_STRICT causes the latter definition to be used.
1330
1331    Most source files want to accept pseudo regs in the hope that
1332    they will get allocated to the class that the insn wants them to be in.
1333    Source files for reload pass need to be strict.
1334    After reload, it makes no difference, since pseudo regs have
1335    been eliminated by then.  */
1336
1337 #ifndef REG_OK_STRICT
1338
1339 /* Nonzero if X is a hard or pseudo reg that can be used as an base.  */
1340
1341 #define REG_OK_FOR_BASE_P(X) IS_ADDR_OR_PSEUDO_REG(X)
1342
1343 /* Nonzero if X is a hard or pseudo reg that can be used as an index.  */
1344
1345 #define REG_OK_FOR_INDEX_P(X) IS_INDEX_OR_PSEUDO_REG(X)
1346
1347 #define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR)                         \
1348 {                                                                       \
1349   if (c4x_check_legit_addr (MODE, X, 0))                                \
1350     goto ADDR;                                                          \
1351 }
1352
1353 #else
1354
1355 /* Nonzero if X is a hard reg that can be used as an index.  */
1356
1357 #define REG_OK_FOR_INDEX_P(X) REGNO_OK_FOR_INDEX_P (REGNO (X))
1358
1359 /* Nonzero if X is a hard reg that can be used as a base reg.  */
1360
1361 #define REG_OK_FOR_BASE_P(X) REGNO_OK_FOR_BASE_P (REGNO (X))
1362
1363 #define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR)                         \
1364 {                                                                       \
1365   if (c4x_check_legit_addr (MODE, X, 1))                                \
1366     goto ADDR;                                                          \
1367 }
1368
1369 #endif
1370
1371 #define LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN) \
1372 {                                                                       \
1373   rtx new;                                                              \
1374   new = c4x_legitimize_address (X, MODE);                               \
1375   if (new != NULL_RTX)                                                  \
1376   {                                                                     \
1377     (X) = new;                                                          \
1378     goto WIN;                                                           \
1379   }                                                                     \
1380 }
1381
1382 #define LEGITIMIZE_RELOAD_ADDRESS(X,MODE,OPNUM,TYPE,IND_LEVELS,WIN)     \
1383 {                                                                       \
1384   if (MODE != HImode                                                    \
1385       && MODE != HFmode                                                 \
1386       && GET_MODE (X) != HImode                                         \
1387       && GET_MODE (X) != HFmode                                         \
1388       && (GET_CODE (X) == CONST                                         \
1389           || GET_CODE (X) == SYMBOL_REF                                 \
1390           || GET_CODE (X) == LABEL_REF))                                \
1391     {                                                                   \
1392       if (! TARGET_SMALL)                                               \
1393         {                                                               \
1394           int i;                                                        \
1395           X = gen_rtx_LO_SUM (GET_MODE (X),                             \
1396                               gen_rtx_HIGH (GET_MODE (X), X), X);       \
1397           i = push_reload (XEXP (X, 0), NULL_RTX,                       \
1398                            &XEXP (X, 0), NULL,                          \
1399                            DP_REG, GET_MODE (X), VOIDmode, 0, 0,        \
1400                            OPNUM, TYPE);                                \
1401           /* The only valid reg is DP. This is a fixed reg and will     \
1402              normally not be used so force it.  */                      \
1403           rld[i].reg_rtx = gen_rtx_REG (Pmode, DP_REGNO);               \
1404           rld[i].nocombine = 1;                                         \
1405         }                                                               \
1406       goto WIN;                                                         \
1407    }                                                                    \
1408   else if (MODE != HImode                                               \
1409            && MODE != HFmode                                            \
1410            && GET_MODE (X) != HImode                                    \
1411            && GET_MODE (X) != HFmode                                    \
1412            && GET_CODE (X) == LO_SUM                                    \
1413            && GET_CODE (XEXP (X,0)) == HIGH                             \
1414            && (GET_CODE (XEXP (XEXP (X,0),0)) == CONST                  \
1415                || GET_CODE (XEXP (XEXP (X,0),0)) == SYMBOL_REF          \
1416                || GET_CODE (XEXP (XEXP (X,0),0)) == LABEL_REF))         \
1417     {                                                                   \
1418       if (! TARGET_SMALL)                                               \
1419         {                                                               \
1420           int i = push_reload (XEXP (X, 0), NULL_RTX,                   \
1421                                &XEXP (X, 0), NULL,                      \
1422                                DP_REG, GET_MODE (X), VOIDmode, 0, 0,    \
1423                                OPNUM, TYPE);                            \
1424           /* The only valid reg is DP. This is a fixed reg and will     \
1425              normally not be used so force it.  */                      \
1426           rld[i].reg_rtx = gen_rtx_REG (Pmode, DP_REGNO);               \
1427           rld[i].nocombine = 1;                                         \
1428         }                                                               \
1429       goto WIN;                                                         \
1430    }                                                                    \
1431 }
1432
1433 /* No mode-dependent addresses on the C4x are autoincrements.  */
1434
1435 #define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR, LABEL)       \
1436   if (GET_CODE (ADDR) == PRE_DEC        \
1437       || GET_CODE (ADDR) == POST_DEC    \
1438       || GET_CODE (ADDR) == PRE_INC     \
1439       || GET_CODE (ADDR) == POST_INC    \
1440       || GET_CODE (ADDR) == POST_MODIFY \
1441       || GET_CODE (ADDR) == PRE_MODIFY) \
1442     goto LABEL
1443
1444
1445 /* Nonzero if the constant value X is a legitimate general operand.
1446    It is given that X satisfies CONSTANT_P or is a CONST_DOUBLE. 
1447
1448    The C4x can only load 16-bit immediate values, so we only allow a
1449    restricted subset of CONST_INT and CONST_DOUBLE.  Disallow
1450    LABEL_REF and SYMBOL_REF (except on the C40 with the big memory
1451    model) so that the symbols will be forced into the constant pool.
1452    On second thoughts, let's do this with the move expanders since
1453    the alias analysis has trouble if we force constant addresses
1454    into memory.
1455 */
1456
1457 #define LEGITIMATE_CONSTANT_P(X)                                \
1458   ((GET_CODE (X) == CONST_DOUBLE && c4x_H_constant (X))         \
1459   || (GET_CODE (X) == CONST_INT)                                \
1460   || (GET_CODE (X) == SYMBOL_REF)                               \
1461   || (GET_CODE (X) == LABEL_REF)                                \
1462   || (GET_CODE (X) == CONST)                                    \
1463   || (GET_CODE (X) == HIGH && ! TARGET_C3X)                     \
1464   || (GET_CODE (X) == LO_SUM && ! TARGET_C3X))
1465
1466 #define LEGITIMATE_DISPLACEMENT_P(X) IS_DISP8_CONST (INTVAL (X))
1467
1468 /* Descripting Relative Cost of Operations.  */
1469
1470 /* Provide the costs of a rtl expression.  This is in the body of a
1471    switch on CODE. 
1472
1473    Note that we return, rather than break so that rtx_cost doesn't
1474    include CONST_COSTS otherwise expand_mult will think that it is
1475    cheaper to synthesise a multiply rather than to use a multiply
1476    instruction.  I think this is because the algorithm synth_mult
1477    doesn't take into account the loading of the operands, whereas the
1478    calculation of mult_cost does. 
1479 */
1480
1481
1482 #define RTX_COSTS(RTX, CODE, OUTER_CODE)                                \
1483     case PLUS:                                                          \
1484     case MINUS:                                                         \
1485     case AND:                                                           \
1486     case IOR:                                                           \
1487     case XOR:                                                           \
1488     case ASHIFT:                                                        \
1489     case ASHIFTRT:                                                      \
1490     case LSHIFTRT:                                                      \
1491     return COSTS_N_INSNS (1);                                           \
1492     case MULT:                                                          \
1493     return COSTS_N_INSNS (GET_MODE_CLASS (GET_MODE (RTX)) == MODE_FLOAT \
1494                           || TARGET_MPYI ? 1 : 14);                     \
1495     case DIV:                                                           \
1496     case UDIV:                                                          \
1497     case MOD:                                                           \
1498     case UMOD:                                                          \
1499     return COSTS_N_INSNS (GET_MODE_CLASS (GET_MODE (RTX)) == MODE_FLOAT \
1500                           ? 15 : 50);
1501
1502 /* Compute the cost of computing a constant rtl expression RTX
1503    whose rtx-code is CODE.  The body of this macro is a portion
1504    of a switch statement.  If the code is computed here,
1505    return it with a return statement.  Otherwise, break from the switch.
1506
1507    An insn is assumed to cost 4 units.
1508    COSTS_N_INSNS (N) is defined as (N) * 4 - 2.
1509
1510    Some small integers are effectively free for the C40.  We should
1511    also consider if we are using the small memory model.  With
1512    the big memory model we require an extra insn for a constant
1513    loaded from memory.  
1514
1515    This is used by expand_binop to decide whether to force a constant
1516    into a register.  If the cost is greater than 2 and the constant
1517    is used within a short loop, it gets forced into a register.  
1518    Ideally, there should be some weighting as to how mnay times it is used
1519    within the loop.  */
1520
1521 #define SHIFT_CODE_P(C) ((C) == ASHIFT || (C) == ASHIFTRT || (C) == LSHIFTRT)
1522
1523 #define LOGICAL_CODE_P(C) ((C) == NOT || (C) == AND \
1524                            || (C) == IOR || (C) == XOR)
1525
1526 #define NON_COMMUTATIVE_CODE_P ((C) == MINUS || (C) == COMPARE)
1527
1528 #define CONST_COSTS(RTX,CODE,OUTER_CODE)                        \
1529         case CONST_INT:                                         \
1530            if (c4x_J_constant (RTX))                            \
1531              return 0;                                          \
1532            if (! TARGET_C3X                                     \
1533                && OUTER_CODE == AND                             \
1534                && GET_CODE (RTX) == CONST_INT                   \
1535                && (INTVAL (RTX) == 255 || INTVAL (RTX) == 65535))       \
1536              return 0;                                          \
1537            if (! TARGET_C3X                                     \
1538                && (OUTER_CODE == ASHIFTRT || OUTER_CODE == LSHIFTRT)    \
1539                && GET_CODE (RTX) == CONST_INT                   \
1540                && (INTVAL (RTX) == 16 || INTVAL (RTX) == 24))   \
1541              return 0;                                          \
1542            if (TARGET_C3X && SHIFT_CODE_P (OUTER_CODE))         \
1543              return 3;                                          \
1544            if (LOGICAL_CODE_P (OUTER_CODE)                      \
1545                ? c4x_L_constant (RTX) : c4x_I_constant (RTX))   \
1546              return 2;                                          \
1547         case CONST:                                             \
1548         case LABEL_REF:                                         \
1549         case SYMBOL_REF:                                        \
1550            return 4;                                            \
1551         case CONST_DOUBLE:                                      \
1552            if (c4x_H_constant (RTX))                            \
1553              return 2;                                          \
1554            if (GET_MODE (RTX) == QFmode)                        \
1555              return 4;                                          \
1556            else                                                 \
1557              return 8;
1558
1559 /* Compute the cost of an address.  This is meant to approximate the size
1560    and/or execution delay of an insn using that address.  If the cost is
1561    approximated by the RTL complexity, including CONST_COSTS above, as
1562    is usually the case for CISC machines, this macro should not be defined.
1563    For aggressively RISCy machines, only one insn format is allowed, so
1564    this macro should be a constant.  The value of this macro only matters
1565    for valid addresses.  We handle the most common address without 
1566    a call to c4x_address_cost.  */
1567
1568 #define ADDRESS_COST(ADDR) (REG_P (ADDR) ? 1 : c4x_address_cost (ADDR))
1569
1570 #define CANONICALIZE_COMPARISON(CODE, OP0, OP1)         \
1571 if (REG_P (OP1) && ! REG_P (OP0))                       \
1572 {                                                       \
1573   rtx tmp = OP0; OP0 = OP1 ; OP1 = tmp;                 \
1574   CODE = swap_condition (CODE);                         \
1575 }
1576
1577 #define EXT_CLASS_P(CLASS) (reg_class_subset_p (CLASS, EXT_REGS))
1578 #define ADDR_CLASS_P(CLASS) (reg_class_subset_p (CLASS, ADDR_REGS))
1579 #define INDEX_CLASS_P(CLASS) (reg_class_subset_p (CLASS, INDEX_REGS))
1580 #define EXPENSIVE_CLASS_P(CLASS) (ADDR_CLASS_P(CLASS) \
1581                           || INDEX_CLASS_P(CLASS) || (CLASS) == SP_REG)
1582
1583 /* Compute extra cost of moving data between one register class
1584    and another.  */
1585
1586 #define REGISTER_MOVE_COST(MODE, FROM, TO)      2
1587
1588 /* Memory move cost is same as fast register move.  Maybe this should
1589    be bumped up?.  */
1590
1591 #define MEMORY_MOVE_COST(M,C,I)         4
1592
1593 /* Branches are kind of expensive (even with delayed branching) so
1594    make their cost higher.  */
1595
1596 #define BRANCH_COST                     8
1597
1598 #define WORD_REGISTER_OPERATIONS
1599
1600 /* Dividing the Output into Sections.  */
1601
1602 #define TEXT_SECTION_ASM_OP "\t.text"
1603
1604 #define DATA_SECTION_ASM_OP "\t.data"
1605
1606 #define READONLY_DATA_SECTION_ASM_OP "\t.sect\t\".const\""
1607
1608 /* Do not use .init section so __main will be called on startup. This will
1609    call __do_global_ctors and prepare for __do_global_dtors on exit.  */
1610
1611 #if 0
1612 #define INIT_SECTION_ASM_OP  "\t.sect\t\".init\""
1613 #endif
1614
1615 #define FINI_SECTION_ASM_OP  "\t.sect\t\".fini\""
1616
1617 #undef EXTRA_SECTIONS
1618 #define EXTRA_SECTIONS in_init, in_fini
1619
1620 #undef EXTRA_SECTION_FUNCTIONS
1621 #define EXTRA_SECTION_FUNCTIONS                                 \
1622   INIT_SECTION_FUNCTION                                         \
1623   FINI_SECTION_FUNCTION
1624
1625 #define INIT_SECTION_FUNCTION                                   \
1626 extern void init_section PARAMS ((void));                       \
1627 void                                                            \
1628 init_section ()                                                 \
1629 {                                                               \
1630   if (in_section != in_init)                                    \
1631     {                                                           \
1632       fprintf (asm_out_file, ";\t.init\n");                     \
1633       in_section = in_init;                                     \
1634     }                                                           \
1635 }
1636
1637 #define FINI_SECTION_FUNCTION                                   \
1638 void                                                            \
1639 fini_section ()                                                 \
1640 {                                                               \
1641   if (in_section != in_fini)                                    \
1642     {                                                           \
1643       fprintf (asm_out_file, "%s\n", FINI_SECTION_ASM_OP);      \
1644       in_section = in_fini;                                     \
1645     }                                                           \
1646 }
1647
1648 #define ASM_STABS_OP "\t.stabs\t"
1649
1650 /* Switch into a generic section.  */
1651 #define TARGET_ASM_NAMED_SECTION c4x_asm_named_section
1652
1653 /* The TI assembler wants to have hex numbers this way.  */
1654
1655 #undef HOST_WIDE_INT_PRINT_HEX
1656 #ifndef HOST_WIDE_INT_PRINT_HEX
1657 # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1658 #  define HOST_WIDE_INT_PRINT_HEX "0%xh"
1659 # else
1660 #  if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1661 #   define HOST_WIDE_INT_PRINT_HEX "0%lxh"
1662 #  else
1663 #   define HOST_WIDE_INT_PRINT_HEX "0%llxh"
1664 #  endif
1665 # endif
1666 #endif /* ! HOST_WIDE_INT_PRINT_HEX */
1667
1668 /* Overall Framework of an Assembler File.  */
1669 /* We need to have a data section we can identify so that we can set
1670    the DP register back to a data pointer in the small memory model.
1671    This is only required for ISRs if we are paranoid that someone
1672    may have quietly changed this register on the sly.  */
1673
1674 #define ASM_FILE_START(FILE)                                    \
1675 {                                                               \
1676     int dspversion = 0;                                         \
1677     if (TARGET_C30) dspversion = 30;                            \
1678     if (TARGET_C31) dspversion = 31;                            \
1679     if (TARGET_C32) dspversion = 32;                            \
1680     if (TARGET_C40) dspversion = 40;                            \
1681     if (TARGET_C44) dspversion = 44;                            \
1682     fprintf (FILE, "\t.version\t%d\n", dspversion);             \
1683     fprintf (FILE, "\t.file\t");                                \
1684     if (TARGET_TI)                                              \
1685       {                                                         \
1686         const char *p;                                          \
1687         const char *after_dir = main_input_filename;            \
1688         for (p = main_input_filename; *p; p++)                  \
1689           if (*p == '/')                                        \
1690             after_dir = p + 1;                                  \
1691         output_quoted_string (FILE, after_dir);                 \
1692       }                                                         \
1693     else                                                        \
1694       output_quoted_string (FILE, main_input_filename);         \
1695     fputs ("\n\t.data\ndata_sec:\n", FILE);                     \
1696 }
1697
1698 #define ASM_COMMENT_START ";"
1699
1700 #define ASM_APP_ON ""
1701 #define ASM_APP_OFF ""
1702
1703 #define ASM_OUTPUT_ASCII(FILE, PTR, LEN) c4x_output_ascii (FILE, PTR, LEN)
1704
1705 /* Output and Generation of Labels.  */
1706
1707 #define NO_DOT_IN_LABEL         /* Only required for TI format.  */
1708
1709 #define ASM_OUTPUT_LABEL(FILE, NAME)    \
1710 do { assemble_name (FILE, NAME); fputs (":\n", FILE); } while (0);
1711
1712 #define ASM_GLOBALIZE_LABEL(FILE, NAME) \
1713   do {                                  \
1714     fprintf (FILE, "\t.global\t");      \
1715     assemble_name (FILE, NAME);         \
1716     fputs ("\n", FILE);                 \
1717     c4x_global_label (NAME);            \
1718   } while (0);
1719
1720 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
1721 c4x_external_ref (NAME)
1722
1723 /* A C statement to output on FILE an assembler pseudo-op to
1724    declare a library function named external.
1725    (Only needed to keep asm30 happy for ___divqf3 etc.)  */
1726
1727 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
1728 c4x_external_ref (XSTR (FUN, 0))
1729
1730 #define ASM_FILE_END(FILE) \
1731 c4x_file_end (FILE)
1732
1733 /* The prefix to add to user-visible assembler symbols.  */
1734
1735 #define USER_LABEL_PREFIX "_"
1736
1737 /* This is how to output an internal numbered label where
1738    PREFIX is the class of label and NUM is the number within the class.  */
1739
1740 #define ASM_OUTPUT_INTERNAL_LABEL(FILE, PREFIX, NUM)    \
1741 asm_fprintf (FILE, "%s%d:\n", PREFIX, NUM)
1742
1743 /* This is how to store into the string LABEL
1744    the symbol_ref name of an internal numbered label where
1745    PREFIX is the class of label and NUM is the number within the class.
1746    This is suitable for output with `assemble_name'.  */
1747
1748 #define ASM_GENERATE_INTERNAL_LABEL(BUFFER, PREFIX, NUM) \
1749     sprintf (BUFFER, "*%s%d", PREFIX, NUM)
1750
1751 /* Store in OUTPUT a string (made with alloca) containing
1752    an assembler-name for a local static variable named NAME.
1753    LABELNO is an integer which is different for each call.  */
1754
1755 #define ASM_FORMAT_PRIVATE_NAME(OUTPUT, NAME, LABELNO)  \
1756 ( (OUTPUT) = (char *) alloca (strlen ((NAME)) + 10),    \
1757   sprintf ((OUTPUT), "%s$%d", (NAME), (LABELNO)))
1758
1759 /* A C statement to output to the stdio stream STREAM assembler code which
1760    defines (equates) the symbol NAME to have the value VALUE.  */
1761
1762 #define ASM_OUTPUT_DEF(STREAM, NAME, VALUE)     \
1763 do {                                            \
1764   assemble_name (STREAM, NAME);                 \
1765   fprintf (STREAM, "\t.set\t%s\n", VALUE);      \
1766 } while (0)
1767
1768 /* Output of Dispatch Tables.  */
1769
1770 /* This is how to output an element of a case-vector that is absolute.  */
1771
1772 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
1773     fprintf (FILE, "\t.long\tL%d\n", VALUE);
1774
1775 /* This is how to output an element of a case-vector that is relative.  */
1776
1777 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
1778     fprintf (FILE, "\t.long\tL%d-L%d\n", VALUE, REL);
1779
1780 #undef SIZE_TYPE
1781 #define SIZE_TYPE "unsigned int"
1782
1783 #undef PTRDIFF_TYPE
1784 #define PTRDIFF_TYPE "int"
1785
1786 #undef WCHAR_TYPE
1787 #define WCHAR_TYPE "long int"
1788
1789 #undef WCHAR_TYPE_SIZE
1790 #define WCHAR_TYPE_SIZE 32
1791
1792 #define INT_TYPE_SIZE           32
1793 #define LONG_LONG_TYPE_SIZE     64
1794 #define FLOAT_TYPE_SIZE         32
1795 #define DOUBLE_TYPE_SIZE        32
1796 #define LONG_DOUBLE_TYPE_SIZE   64 /* Actually only 40.  */
1797
1798 /* Allow #sccs in preprocessor.  */
1799
1800 #define SCCS_DIRECTIVE
1801
1802 /* Output #ident as a .ident.  */
1803
1804 #define ASM_OUTPUT_IDENT(FILE, NAME) \
1805   fprintf (FILE, "\t.ident \"%s\"\n", NAME);
1806
1807 /* Output of Uninitialized Variables.  */
1808
1809 /* This says how to output an assembler line to define a local
1810    uninitialized variable.  */
1811
1812 #undef ASM_OUTPUT_LOCAL
1813 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)  \
1814 ( fputs ("\t.bss\t", FILE),                     \
1815   assemble_name (FILE, (NAME)),         \
1816   fprintf (FILE, ",%u\n", (ROUNDED)))
1817
1818 /* This says how to output an assembler line to define a global
1819    uninitialized variable.  */
1820
1821 #undef ASM_OUTPUT_COMMON
1822 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)  \
1823 (  fputs ("\t.globl\t", FILE),  \
1824    assemble_name (FILE, (NAME)),        \
1825    fputs ("\n\t.bss\t", FILE),  \
1826    assemble_name (FILE, (NAME)),        \
1827    fprintf (FILE, ",%u\n", (ROUNDED)))
1828
1829 #undef ASM_OUTPUT_BSS
1830 #define ASM_OUTPUT_BSS(FILE, DECL, NAME, SIZE, ALIGN)   \
1831 (  fputs ("\t.globl\t", FILE),  \
1832    assemble_name (FILE, (NAME)),        \
1833    fputs ("\n\t.bss\t", FILE),  \
1834    assemble_name (FILE, (NAME)),        \
1835    fprintf (FILE, ",%u\n", (SIZE)))
1836
1837 /* Macros Controlling Initialization Routines.  */
1838
1839 #define OBJECT_FORMAT_COFF
1840 #define REAL_NM_FILE_NAME "c4x-nm"
1841
1842 /* Output of Assembler Instructions.  */
1843
1844 /* Register names when used for integer modes.  */
1845
1846 #define REGISTER_NAMES \
1847 {                                                               \
1848  "r0",   "r1", "r2",   "r3",  "r4",  "r5",  "r6",  "r7",        \
1849  "ar0", "ar1", "ar2", "ar3", "ar4", "ar5", "ar6", "ar7",        \
1850  "dp",  "ir0", "ir1",  "bk",  "sp",  "st", "die", "iie",        \
1851  "iif",  "rs",  "re",  "rc",  "r8",  "r9", "r10", "r11"         \
1852 }
1853
1854 /* Alternate register names when used for floating point modes.  */
1855
1856 #define FLOAT_REGISTER_NAMES \
1857 {                                                               \
1858  "f0",   "f1", "f2",   "f3",  "f4",  "f5",  "f6",  "f7",        \
1859  "ar0", "ar1", "ar2", "ar3", "ar4", "ar5", "ar6", "ar7",        \
1860  "dp",  "ir0", "ir1",  "bk",  "sp",  "st", "die", "iie",        \
1861  "iif",  "rs",  "re",  "rc",  "f8",  "f9", "f10", "f11"         \
1862 }
1863
1864 #define PRINT_OPERAND(FILE, X, CODE) c4x_print_operand(FILE, X, CODE)
1865
1866 /* Determine which codes are valid without a following integer.  These must
1867    not be alphabetic.  */
1868
1869 #define PRINT_OPERAND_PUNCT_VALID_P(CODE) ((CODE) == '#')
1870
1871 #define PRINT_OPERAND_ADDRESS(FILE, X) c4x_print_operand_address(FILE, X)
1872
1873 /* C4x specific pragmas.  */
1874 #define REGISTER_TARGET_PRAGMAS(PFILE) do {                             \
1875   cpp_register_pragma (PFILE, 0, "CODE_SECTION", c4x_pr_CODE_SECTION);  \
1876   cpp_register_pragma (PFILE, 0, "DATA_SECTION", c4x_pr_DATA_SECTION);  \
1877   cpp_register_pragma (PFILE, 0, "FUNC_CANNOT_INLINE", c4x_pr_ignored); \
1878   cpp_register_pragma (PFILE, 0, "FUNC_EXT_CALLED", c4x_pr_ignored);    \
1879   cpp_register_pragma (PFILE, 0, "FUNC_IS_PURE", c4x_pr_FUNC_IS_PURE);  \
1880   cpp_register_pragma (PFILE, 0, "FUNC_IS_SYSTEM", c4x_pr_ignored);     \
1881   cpp_register_pragma (PFILE, 0, "FUNC_NEVER_RETURNS",                  \
1882                        c4x_pr_FUNC_NEVER_RETURNS);                      \
1883   cpp_register_pragma (PFILE, 0, "FUNC_NO_GLOBAL_ASG", c4x_pr_ignored); \
1884   cpp_register_pragma (PFILE, 0, "FUNC_NO_IND_ASG", c4x_pr_ignored);    \
1885   cpp_register_pragma (PFILE, 0, "INTERRUPT", c4x_pr_INTERRUPT);        \
1886 } while (0)
1887
1888 /* Assembler Commands for Alignment.  */
1889
1890 #define ASM_OUTPUT_SKIP(FILE, SIZE) \
1891 { int c = SIZE; \
1892   for (; c > 0; --c) \
1893    fprintf (FILE,"\t.word\t0\n"); \
1894 }
1895
1896 #define ASM_NO_SKIP_IN_TEXT 1
1897
1898 /* I'm not sure about this one.  FIXME.  */
1899
1900 #define ASM_OUTPUT_ALIGN(FILE, LOG)     \
1901   if ((LOG) != 0)                       \
1902     fprintf (FILE, "\t.align\t%d\n", (1 << (LOG)))
1903
1904
1905 /* Macros for SDB and DWARF Output  (use .sdef instead of .def
1906    to avoid conflict with TI's use of .def).  */
1907
1908 #define SDB_DELIM "\n"
1909 #define SDB_DEBUGGING_INFO
1910
1911 /* Don't use octal since this can confuse gas for the c4x.  */
1912 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0x%x%s", a, SDB_DELIM)
1913
1914 #define PUT_SDB_DEF(A)                          \
1915 do { fprintf (asm_out_file, "\t.sdef\t");       \
1916      ASM_OUTPUT_LABELREF (asm_out_file, A);     \
1917      fprintf (asm_out_file, SDB_DELIM); } while (0)
1918
1919 #define PUT_SDB_PLAIN_DEF(A)                    \
1920   fprintf (asm_out_file,"\t.sdef\t.%s%s", A, SDB_DELIM)
1921
1922 #define PUT_SDB_BLOCK_START(LINE)               \
1923   fprintf (asm_out_file,                        \
1924            "\t.sdef\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
1925            SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
1926
1927 #define PUT_SDB_BLOCK_END(LINE)                 \
1928   fprintf (asm_out_file,                        \
1929            "\t.sdef\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
1930            SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
1931
1932 #define PUT_SDB_FUNCTION_START(LINE)            \
1933   fprintf (asm_out_file,                        \
1934            "\t.sdef\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
1935            SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
1936
1937 /* Note we output relative line numbers for .ef which gas converts
1938    to absolute line numbers.  The TI compiler outputs absolute line numbers
1939    in the .sym directive which gas does not support.  */
1940 #define PUT_SDB_FUNCTION_END(LINE)              \
1941   fprintf (asm_out_file,                        \
1942            "\t.sdef\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
1943            SDB_DELIM, SDB_DELIM, SDB_DELIM, \
1944            (LINE), SDB_DELIM)
1945
1946 #define PUT_SDB_EPILOGUE_END(NAME)                      \
1947 do { fprintf (asm_out_file, "\t.sdef\t");               \
1948      ASM_OUTPUT_LABELREF (asm_out_file, NAME);          \
1949      fprintf (asm_out_file,                             \
1950               "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",    \
1951               SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
1952
1953 /* Define this as 1 if `char' should by default be signed; else as 0.  */
1954
1955 #define DEFAULT_SIGNED_CHAR 1
1956
1957 /* A function address in a call instruction is a byte address (for
1958    indexing purposes) so give the MEM rtx a byte's mode.  */
1959
1960 #define FUNCTION_MODE QImode
1961
1962 #define SLOW_BYTE_ACCESS 0
1963
1964 /* Specify the machine mode that pointers have.  After generation of
1965    RTL, the compiler makes no further distinction between pointers and
1966    any other objects of this machine mode.  */
1967
1968 #define Pmode QImode
1969
1970 /* On the C4x we can write the following code. We have to clear the cache
1971    every time we execute it because the data in the stack could change.
1972
1973    laj   $+4
1974    addi3 4,r11,ar0
1975    lda   *ar0,ar1
1976    lda   *+ar0(1),ar0
1977    bud   ar1
1978    nop
1979    nop
1980    or   1000h,st
1981    .word FNADDR
1982    .word CXT
1983
1984    On the c3x this is a bit more difficult. We have to write self
1985    modifying code here. So we have to clear the cache every time
1986    we execute it because the data in the stack could change.
1987
1988    ldiu TOP_OF_FUNCTION,ar1
1989    lsh  16,ar1
1990    or   BOTTOM_OF_FUNCTION,ar1
1991    ldiu TOP_OF_STATIC,ar0
1992    bud  ar1
1993    lsh  16,ar0
1994    or   BOTTOM_OF_STATIC,ar0
1995    or   1000h,st
1996    
1997   */
1998
1999 #define TRAMPOLINE_SIZE (TARGET_C3X ? 8 : 10)
2000
2001 #define TRAMPOLINE_TEMPLATE(FILE)                               \
2002 {                                                               \
2003   if (TARGET_C3X)                                               \
2004     {                                                           \
2005       asm_fprintf (FILE, "\tldiu\t0,ar1\n");                    \
2006       asm_fprintf (FILE, "\tlsh\t16,ar1\n");                    \
2007       asm_fprintf (FILE, "\tor\t0,ar1\n");                      \
2008       asm_fprintf (FILE, "\tldiu\t0,ar0\n");                    \
2009       asm_fprintf (FILE, "\tbud\tar1\n");                       \
2010       asm_fprintf (FILE, "\tlsh\t16,ar0\n");                    \
2011       asm_fprintf (FILE, "\tor\t0,ar0\n");                      \
2012       asm_fprintf (FILE, "\tor\t1000h,st\n");                   \
2013     }                                                           \
2014   else                                                          \
2015     {                                                           \
2016       asm_fprintf (FILE, "\tlaj\t$+4\n");                       \
2017       asm_fprintf (FILE, "\taddi3\t4,r11,ar0\n");               \
2018       asm_fprintf (FILE, "\tlda\t*ar0,ar1\n");                  \
2019       asm_fprintf (FILE, "\tlda\t*+ar0(1),ar0\n");              \
2020       asm_fprintf (FILE, "\tbud\tar1\n");                       \
2021       asm_fprintf (FILE, "\tnop\n");                            \
2022       asm_fprintf (FILE, "\tnop\n");                            \
2023       asm_fprintf (FILE, "\tor\t1000h,st\n");                   \
2024       asm_fprintf (FILE, "\t.word\t0\n");                       \
2025       asm_fprintf (FILE, "\t.word\t0\n");                       \
2026     }                                                           \
2027 }
2028
2029 #define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)                       \
2030 {                                                                       \
2031   if (TARGET_C3X)                                                       \
2032     {                                                                   \
2033       rtx tmp1, tmp2;                                                   \
2034       tmp1 = expand_shift (RSHIFT_EXPR, QImode, FNADDR,                 \
2035                            size_int (16), 0, 1);                        \
2036       tmp2 = expand_shift (LSHIFT_EXPR, QImode,                         \
2037                            GEN_INT (0x5069), size_int (16), 0, 1);      \
2038       emit_insn (gen_iorqi3 (tmp1, tmp1, tmp2));                        \
2039       emit_move_insn (gen_rtx (MEM, QImode,                             \
2040                                plus_constant (tramp, 0)), tmp1);        \
2041       tmp1 = expand_and (QImode, FNADDR, GEN_INT (0xffff), 0);          \
2042       tmp2 = expand_shift (LSHIFT_EXPR, QImode,                         \
2043                            GEN_INT (0x1069), size_int (16), 0, 1);      \
2044       emit_insn (gen_iorqi3 (tmp1, tmp1, tmp2));                        \
2045       emit_move_insn (gen_rtx (MEM, QImode,                             \
2046                                plus_constant (tramp, 2)), tmp1);        \
2047       tmp1 = expand_shift (RSHIFT_EXPR, QImode, CXT,                    \
2048                            size_int (16), 0, 1);                        \
2049       tmp2 = expand_shift (LSHIFT_EXPR, QImode,                         \
2050                            GEN_INT (0x5068), size_int (16), 0, 1);      \
2051       emit_insn (gen_iorqi3 (tmp1, tmp1, tmp2));                        \
2052       emit_move_insn (gen_rtx (MEM, QImode,                             \
2053                                plus_constant (tramp, 3)), tmp1);        \
2054       tmp1 = expand_and (QImode, CXT, GEN_INT (0xffff), 0);             \
2055       tmp2 = expand_shift (LSHIFT_EXPR, QImode,                         \
2056                            GEN_INT (0x1068), size_int (16), 0, 1);      \
2057       emit_insn (gen_iorqi3 (tmp1, tmp1, tmp2));                        \
2058       emit_move_insn (gen_rtx (MEM, QImode,                             \
2059                                plus_constant (tramp, 6)), tmp1);        \
2060     }                                                                   \
2061   else                                                                  \
2062     {                                                                   \
2063       emit_move_insn (gen_rtx (MEM, QImode,                             \
2064                                plus_constant (TRAMP, 8)), FNADDR);      \
2065       emit_move_insn (gen_rtx (MEM, QImode,                             \
2066                                plus_constant (TRAMP, 9)), CXT);         \
2067     }                                                                   \
2068 }
2069
2070 /* Specify the machine mode that this machine uses for the index in
2071    the tablejump instruction.  */
2072
2073 #define CASE_VECTOR_MODE Pmode
2074
2075 /* Max number of (32-bit) bytes we can move from memory to memory
2076    in one reasonably fast instruction.  */
2077
2078 #define MOVE_MAX 1
2079
2080 /* MOVE_RATIO is the number of move instructions that is better than a
2081    block move.  */
2082
2083 #define MOVE_RATIO 3
2084
2085 #define BSS_SECTION_ASM_OP "\t.bss"
2086
2087 #define ASM_OUTPUT_REG_PUSH(FILE, REGNO)  \
2088   asm_fprintf (FILE, "\tpush\t%s\n", reg_names[REGNO])
2089
2090 /* This is how to output an insn to pop a register from the stack.
2091    It need not be very fast code.  */
2092
2093 #define ASM_OUTPUT_REG_POP(FILE, REGNO)  \
2094   asm_fprintf (FILE, "\tpop\t%s\n", reg_names[REGNO])
2095
2096 /* Value is 1 if truncating an integer of INPREC bits to OUTPREC bits
2097    is done just by pretending it is already truncated.  */
2098
2099 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
2100
2101 /* We need to use direct addressing for large constants and addresses
2102    that cannot fit within an instruction.  We must check for these
2103    after after the final jump optimisation pass, since this may
2104    introduce a local_move insn for a SYMBOL_REF.  This pass
2105    must come before delayed branch slot filling since it can generate
2106    additional instructions.  */
2107
2108 #define MACHINE_DEPENDENT_REORG(INSNS) c4x_process_after_reload(INSNS)
2109
2110 #define DBR_OUTPUT_SEQEND(FILE)                         \
2111 if (final_sequence != NULL_RTX)                         \
2112 {                                                       \
2113  int count;                                             \
2114  rtx insn = XVECEXP (final_sequence, 0, 0);             \
2115  int laj = GET_CODE (insn) == CALL_INSN                 \
2116            || (GET_CODE (insn) == INSN                  \
2117                && GET_CODE (PATTERN (insn)) == TRAP_IF);\
2118                                                         \
2119  count = dbr_sequence_length();                         \
2120  while (count < (laj ? 2 : 3))                          \
2121  {                                                      \
2122     fputs("\tnop\n", FILE);                             \
2123     count++;                                            \
2124  }                                                      \
2125  if (laj)                                               \
2126     fputs("\tpush\tr11\n", FILE);                       \
2127 }
2128
2129 #define NO_FUNCTION_CSE
2130
2131 /* We don't want a leading tab.  */
2132
2133 #define ASM_OUTPUT_ASM(FILE, STRING) fprintf (FILE, "%s\n", STRING)
2134
2135 /* Define the codes that are matched by predicates in c4x.c.  */
2136
2137 #define PREDICATE_CODES                                         \
2138   {"fp_zero_operand", {CONST_DOUBLE}},                          \
2139   {"const_operand", {CONST_INT, CONST_DOUBLE}},                 \
2140   {"stik_const_operand", {CONST_INT}},                          \
2141   {"not_const_operand", {CONST_INT}},                           \
2142   {"reg_operand", {REG, SUBREG}},                               \
2143   {"reg_or_const_operand", {REG, SUBREG, CONST_INT, CONST_DOUBLE}},\
2144   {"r0r1_reg_operand", {REG, SUBREG}},                          \
2145   {"r2r3_reg_operand", {REG, SUBREG}},                          \
2146   {"ext_low_reg_operand", {REG, SUBREG}},                       \
2147   {"ext_reg_operand", {REG, SUBREG}},                           \
2148   {"std_reg_operand", {REG, SUBREG}},                           \
2149   {"std_or_reg_operand", {REG, SUBREG}},                        \
2150   {"addr_reg_operand", {REG, SUBREG}},                          \
2151   {"index_reg_operand", {REG, SUBREG}},                         \
2152   {"dp_reg_operand", {REG}},                                    \
2153   {"sp_reg_operand", {REG}},                                    \
2154   {"st_reg_operand", {REG}},                                    \
2155   {"rc_reg_operand", {REG}},                                    \
2156   {"call_address_operand", {REG, SYMBOL_REF, LABEL_REF, CONST}}, \
2157   {"dst_operand", {SUBREG, REG, MEM}}, \
2158   {"src_operand", {SUBREG, REG, MEM, CONST_INT, CONST_DOUBLE}}, \
2159   {"src_hi_operand", {SUBREG, REG, MEM, CONST_DOUBLE}},         \
2160   {"lsrc_operand", {SUBREG, REG, MEM, CONST_INT, CONST_DOUBLE}}, \
2161   {"tsrc_operand", {SUBREG, REG, MEM, CONST_INT, CONST_DOUBLE}}, \
2162   {"nonimmediate_src_operand", {SUBREG, REG, MEM}},             \
2163   {"nonimmediate_lsrc_operand", {SUBREG, REG, MEM}},            \
2164   {"any_operand", {SUBREG, REG, MEM, CONST_INT, CONST_DOUBLE}}, \
2165   {"par_ind_operand", {MEM}},                                   \
2166   {"parallel_operand", {SUBREG, REG, MEM}},                     \
2167   {"symbolic_address_operand", {SYMBOL_REF, LABEL_REF, CONST}}, \
2168   {"mem_operand", {MEM}},                                       
2169
2170
2171 /* Define the intrinsic functions for the c3x/c4x.  */
2172
2173 enum c4x_builtins
2174 {
2175                         /*      intrinsic name          */
2176   C4X_BUILTIN_FIX,      /*      fast_ftoi               */
2177   C4X_BUILTIN_FIX_ANSI, /*      ansi_ftoi               */
2178   C4X_BUILTIN_MPYI,     /*      fast_imult (only C3x)   */
2179   C4X_BUILTIN_TOIEEE,   /*      toieee     (only C4x)   */
2180   C4X_BUILTIN_FRIEEE,   /*      frieee     (only C4x)   */
2181   C4X_BUILTIN_RCPF      /*      fast_invf  (only C4x)   */
2182 };