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