OSDN Git Service

2008-08-05 Paul Brook <paul@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / arm / arm.h
1 /* Definitions of target machine for GNU compiler, for ARM.
2    Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3    2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4    Free Software Foundation, Inc.
5    Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
6    and Martin Simmons (@harleqn.co.uk).
7    More major hacks by Richard Earnshaw (rearnsha@arm.com)
8    Minor hacks by Nick Clifton (nickc@cygnus.com)
9
10    This file is part of GCC.
11
12    GCC is free software; you can redistribute it and/or modify it
13    under the terms of the GNU General Public License as published
14    by the Free Software Foundation; either version 3, or (at your
15    option) any later version.
16
17    GCC is distributed in the hope that it will be useful, but WITHOUT
18    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
20    License for more details.
21
22    You should have received a copy of the GNU General Public License
23    along with GCC; see the file COPYING3.  If not see
24    <http://www.gnu.org/licenses/>.  */
25
26 #ifndef GCC_ARM_H
27 #define GCC_ARM_H
28
29 #include "config/vxworks-dummy.h"
30
31 /* The architecture define.  */
32 extern char arm_arch_name[];
33
34 /* Target CPU builtins.  */
35 #define TARGET_CPU_CPP_BUILTINS()                       \
36   do                                                    \
37     {                                                   \
38         /* Define __arm__ even when in thumb mode, for  \
39            consistency with armcc.  */                  \
40         builtin_define ("__arm__");                     \
41         builtin_define ("__APCS_32__");                 \
42         if (TARGET_THUMB)                               \
43           builtin_define ("__thumb__");                 \
44         if (TARGET_THUMB2)                              \
45           builtin_define ("__thumb2__");                \
46                                                         \
47         if (TARGET_BIG_END)                             \
48           {                                             \
49             builtin_define ("__ARMEB__");               \
50             if (TARGET_THUMB)                           \
51               builtin_define ("__THUMBEB__");           \
52             if (TARGET_LITTLE_WORDS)                    \
53               builtin_define ("__ARMWEL__");            \
54           }                                             \
55         else                                            \
56           {                                             \
57             builtin_define ("__ARMEL__");               \
58             if (TARGET_THUMB)                           \
59               builtin_define ("__THUMBEL__");           \
60           }                                             \
61                                                         \
62         if (TARGET_SOFT_FLOAT)                          \
63           builtin_define ("__SOFTFP__");                \
64                                                         \
65         if (TARGET_VFP)                                 \
66           builtin_define ("__VFP_FP__");                \
67                                                         \
68         if (TARGET_NEON)                                \
69           builtin_define ("__ARM_NEON__");              \
70                                                         \
71         /* Add a define for interworking.               \
72            Needed when building libgcc.a.  */           \
73         if (arm_cpp_interwork)                          \
74           builtin_define ("__THUMB_INTERWORK__");       \
75                                                         \
76         builtin_assert ("cpu=arm");                     \
77         builtin_assert ("machine=arm");                 \
78                                                         \
79         builtin_define (arm_arch_name);                 \
80         if (arm_arch_cirrus)                            \
81           builtin_define ("__MAVERICK__");              \
82         if (arm_arch_xscale)                            \
83           builtin_define ("__XSCALE__");                \
84         if (arm_arch_iwmmxt)                            \
85           builtin_define ("__IWMMXT__");                \
86         if (TARGET_AAPCS_BASED)                         \
87           builtin_define ("__ARM_EABI__");              \
88     } while (0)
89
90 /* The various ARM cores.  */
91 enum processor_type
92 {
93 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
94   IDENT,
95 #include "arm-cores.def"
96 #undef ARM_CORE
97   /* Used to indicate that no processor has been specified.  */
98   arm_none
99 };
100
101 enum target_cpus
102 {
103 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
104   TARGET_CPU_##IDENT,
105 #include "arm-cores.def"
106 #undef ARM_CORE
107   TARGET_CPU_generic
108 };
109
110 /* The processor for which instructions should be scheduled.  */
111 extern enum processor_type arm_tune;
112
113 typedef enum arm_cond_code
114 {
115   ARM_EQ = 0, ARM_NE, ARM_CS, ARM_CC, ARM_MI, ARM_PL, ARM_VS, ARM_VC,
116   ARM_HI, ARM_LS, ARM_GE, ARM_LT, ARM_GT, ARM_LE, ARM_AL, ARM_NV
117 }
118 arm_cc;
119
120 extern arm_cc arm_current_cc;
121
122 #define ARM_INVERSE_CONDITION_CODE(X)  ((arm_cc) (((int)X) ^ 1))
123
124 extern int arm_target_label;
125 extern int arm_ccfsm_state;
126 extern GTY(()) rtx arm_target_insn;
127 /* Define the information needed to generate branch insns.  This is
128    stored from the compare operation.  */
129 extern GTY(()) rtx arm_compare_op0;
130 extern GTY(()) rtx arm_compare_op1;
131 /* The label of the current constant pool.  */
132 extern rtx pool_vector_label;
133 /* Set to 1 when a return insn is output, this means that the epilogue
134    is not needed.  */
135 extern int return_used_this_function;
136 /* Callback to output language specific object attributes.  */
137 extern void (*arm_lang_output_object_attributes_hook)(void);
138 \f
139 /* Just in case configure has failed to define anything.  */
140 #ifndef TARGET_CPU_DEFAULT
141 #define TARGET_CPU_DEFAULT TARGET_CPU_generic
142 #endif
143
144
145 #undef  CPP_SPEC
146 #define CPP_SPEC "%(subtarget_cpp_spec)                                 \
147 %{msoft-float:%{mhard-float:                                            \
148         %e-msoft-float and -mhard_float may not be used together}}      \
149 %{mbig-endian:%{mlittle-endian:                                         \
150         %e-mbig-endian and -mlittle-endian may not be used together}}"
151
152 #ifndef CC1_SPEC
153 #define CC1_SPEC ""
154 #endif
155
156 /* This macro defines names of additional specifications to put in the specs
157    that can be used in various specifications like CC1_SPEC.  Its definition
158    is an initializer with a subgrouping for each command option.
159
160    Each subgrouping contains a string constant, that defines the
161    specification name, and a string constant that used by the GCC driver
162    program.
163
164    Do not define this macro if it does not need to do anything.  */
165 #define EXTRA_SPECS                                             \
166   { "subtarget_cpp_spec",       SUBTARGET_CPP_SPEC },           \
167   SUBTARGET_EXTRA_SPECS
168
169 #ifndef SUBTARGET_EXTRA_SPECS
170 #define SUBTARGET_EXTRA_SPECS
171 #endif
172
173 #ifndef SUBTARGET_CPP_SPEC
174 #define SUBTARGET_CPP_SPEC      ""
175 #endif
176 \f
177 /* Run-time Target Specification.  */
178 #ifndef TARGET_VERSION
179 #define TARGET_VERSION fputs (" (ARM/generic)", stderr);
180 #endif
181
182 #define TARGET_SOFT_FLOAT               (arm_float_abi == ARM_FLOAT_ABI_SOFT)
183 /* Use hardware floating point instructions. */
184 #define TARGET_HARD_FLOAT               (arm_float_abi != ARM_FLOAT_ABI_SOFT)
185 /* Use hardware floating point calling convention.  */
186 #define TARGET_HARD_FLOAT_ABI           (arm_float_abi == ARM_FLOAT_ABI_HARD)
187 #define TARGET_FPA                      (arm_fp_model == ARM_FP_MODEL_FPA)
188 #define TARGET_MAVERICK                 (arm_fp_model == ARM_FP_MODEL_MAVERICK)
189 #define TARGET_VFP                      (arm_fp_model == ARM_FP_MODEL_VFP)
190 #define TARGET_IWMMXT                   (arm_arch_iwmmxt)
191 #define TARGET_REALLY_IWMMXT            (TARGET_IWMMXT && TARGET_32BIT)
192 #define TARGET_IWMMXT_ABI (TARGET_32BIT && arm_abi == ARM_ABI_IWMMXT)
193 #define TARGET_ARM                      (! TARGET_THUMB)
194 #define TARGET_EITHER                   1 /* (TARGET_ARM | TARGET_THUMB) */
195 #define TARGET_BACKTRACE                (leaf_function_p () \
196                                          ? TARGET_TPCS_LEAF_FRAME \
197                                          : TARGET_TPCS_FRAME)
198 #define TARGET_LDRD                     (arm_arch5e && ARM_DOUBLEWORD_ALIGN)
199 #define TARGET_AAPCS_BASED \
200     (arm_abi != ARM_ABI_APCS && arm_abi != ARM_ABI_ATPCS)
201
202 #define TARGET_HARD_TP                  (target_thread_pointer == TP_CP15)
203 #define TARGET_SOFT_TP                  (target_thread_pointer == TP_SOFT)
204
205 /* Only 16-bit thumb code.  */
206 #define TARGET_THUMB1                   (TARGET_THUMB && !arm_arch_thumb2)
207 /* Arm or Thumb-2 32-bit code.  */
208 #define TARGET_32BIT                    (TARGET_ARM || arm_arch_thumb2)
209 /* 32-bit Thumb-2 code.  */
210 #define TARGET_THUMB2                   (TARGET_THUMB && arm_arch_thumb2)
211 /* Thumb-1 only.  */
212 #define TARGET_THUMB1_ONLY              (TARGET_THUMB1 && !arm_arch_notm)
213
214 /* The following two macros concern the ability to execute coprocessor
215    instructions for VFPv3 or NEON.  TARGET_VFP3/TARGET_VFPD32 are currently
216    only ever tested when we know we are generating for VFP hardware; we need
217    to be more careful with TARGET_NEON as noted below.  */
218
219 /* FPU is has the full VFPv3/NEON register file of 32 D registers.  */
220 #define TARGET_VFPD32 (arm_fp_model == ARM_FP_MODEL_VFP \
221                        && (arm_fpu_arch == FPUTYPE_VFP3 \
222                            || arm_fpu_arch == FPUTYPE_NEON))
223
224 /* FPU supports VFPv3 instructions.  */
225 #define TARGET_VFP3 (arm_fp_model == ARM_FP_MODEL_VFP \
226                      && (arm_fpu_arch == FPUTYPE_VFP3D16 \
227                          || TARGET_VFPD32))
228
229 /* FPU supports Neon instructions.  The setting of this macro gets
230    revealed via __ARM_NEON__ so we add extra guards upon TARGET_32BIT
231    and TARGET_HARD_FLOAT to ensure that NEON instructions are
232    available.  */
233 #define TARGET_NEON (TARGET_32BIT && TARGET_HARD_FLOAT \
234                      && arm_fp_model == ARM_FP_MODEL_VFP \
235                      && arm_fpu_arch == FPUTYPE_NEON)
236
237 /* "DSP" multiply instructions, eg. SMULxy.  */
238 #define TARGET_DSP_MULTIPLY \
239   (TARGET_32BIT && arm_arch5e && arm_arch_notm)
240 /* Integer SIMD instructions, and extend-accumulate instructions.  */
241 #define TARGET_INT_SIMD \
242   (TARGET_32BIT && arm_arch6 && arm_arch_notm)
243
244 /* We could use unified syntax for arm mode, but for now we just use it
245    for Thumb-2.  */
246 #define TARGET_UNIFIED_ASM TARGET_THUMB2
247
248
249 /* True iff the full BPABI is being used.  If TARGET_BPABI is true,
250    then TARGET_AAPCS_BASED must be true -- but the converse does not
251    hold.  TARGET_BPABI implies the use of the BPABI runtime library,
252    etc., in addition to just the AAPCS calling conventions.  */
253 #ifndef TARGET_BPABI
254 #define TARGET_BPABI false
255 #endif
256
257 /* Support for a compile-time default CPU, et cetera.  The rules are:
258    --with-arch is ignored if -march or -mcpu are specified.
259    --with-cpu is ignored if -march or -mcpu are specified, and is overridden
260     by --with-arch.
261    --with-tune is ignored if -mtune or -mcpu are specified (but not affected
262      by -march).
263    --with-float is ignored if -mhard-float, -msoft-float or -mfloat-abi are
264    specified.
265    --with-fpu is ignored if -mfpu is specified.
266    --with-abi is ignored is -mabi is specified.  */
267 #define OPTION_DEFAULT_SPECS \
268   {"arch", "%{!march=*:%{!mcpu=*:-march=%(VALUE)}}" }, \
269   {"cpu", "%{!march=*:%{!mcpu=*:-mcpu=%(VALUE)}}" }, \
270   {"tune", "%{!mcpu=*:%{!mtune=*:-mtune=%(VALUE)}}" }, \
271   {"float", \
272     "%{!msoft-float:%{!mhard-float:%{!mfloat-abi=*:-mfloat-abi=%(VALUE)}}}" }, \
273   {"fpu", "%{!mfpu=*:-mfpu=%(VALUE)}"}, \
274   {"abi", "%{!mabi=*:-mabi=%(VALUE)}"}, \
275   {"mode", "%{!marm:%{!mthumb:-m%(VALUE)}}"},
276
277 /* Which floating point model to use.  */
278 enum arm_fp_model
279 {
280   ARM_FP_MODEL_UNKNOWN,
281   /* FPA model (Hardware or software).  */
282   ARM_FP_MODEL_FPA,
283   /* Cirrus Maverick floating point model.  */
284   ARM_FP_MODEL_MAVERICK,
285   /* VFP floating point model.  */
286   ARM_FP_MODEL_VFP
287 };
288
289 extern enum arm_fp_model arm_fp_model;
290
291 /* Which floating point hardware is available.  Also update
292    fp_model_for_fpu in arm.c when adding entries to this list.  */
293 enum fputype
294 {
295   /* No FP hardware.  */
296   FPUTYPE_NONE,
297   /* Full FPA support.  */
298   FPUTYPE_FPA,
299   /* Emulated FPA hardware, Issue 2 emulator (no LFM/SFM).  */
300   FPUTYPE_FPA_EMU2,
301   /* Emulated FPA hardware, Issue 3 emulator.  */
302   FPUTYPE_FPA_EMU3,
303   /* Cirrus Maverick floating point co-processor.  */
304   FPUTYPE_MAVERICK,
305   /* VFP.  */
306   FPUTYPE_VFP,
307   /* VFPv3-D16.  */
308   FPUTYPE_VFP3D16,
309   /* VFPv3.  */
310   FPUTYPE_VFP3,
311   /* Neon.  */
312   FPUTYPE_NEON
313 };
314
315 /* Recast the floating point class to be the floating point attribute.  */
316 #define arm_fpu_attr ((enum attr_fpu) arm_fpu_tune)
317
318 /* What type of floating point to tune for */
319 extern enum fputype arm_fpu_tune;
320
321 /* What type of floating point instructions are available */
322 extern enum fputype arm_fpu_arch;
323
324 enum float_abi_type
325 {
326   ARM_FLOAT_ABI_SOFT,
327   ARM_FLOAT_ABI_SOFTFP,
328   ARM_FLOAT_ABI_HARD
329 };
330
331 extern enum float_abi_type arm_float_abi;
332
333 #ifndef TARGET_DEFAULT_FLOAT_ABI
334 #define TARGET_DEFAULT_FLOAT_ABI ARM_FLOAT_ABI_SOFT
335 #endif
336
337 /* Which ABI to use.  */
338 enum arm_abi_type
339 {
340   ARM_ABI_APCS,
341   ARM_ABI_ATPCS,
342   ARM_ABI_AAPCS,
343   ARM_ABI_IWMMXT,
344   ARM_ABI_AAPCS_LINUX
345 };
346
347 extern enum arm_abi_type arm_abi;
348
349 #ifndef ARM_DEFAULT_ABI
350 #define ARM_DEFAULT_ABI ARM_ABI_APCS
351 #endif
352
353 /* Which thread pointer access sequence to use.  */
354 enum arm_tp_type {
355   TP_AUTO,
356   TP_SOFT,
357   TP_CP15
358 };
359
360 extern enum arm_tp_type target_thread_pointer;
361
362 /* Nonzero if this chip supports the ARM Architecture 3M extensions.  */
363 extern int arm_arch3m;
364
365 /* Nonzero if this chip supports the ARM Architecture 4 extensions.  */
366 extern int arm_arch4;
367
368 /* Nonzero if this chip supports the ARM Architecture 4T extensions.  */
369 extern int arm_arch4t;
370
371 /* Nonzero if this chip supports the ARM Architecture 5 extensions.  */
372 extern int arm_arch5;
373
374 /* Nonzero if this chip supports the ARM Architecture 5E extensions.  */
375 extern int arm_arch5e;
376
377 /* Nonzero if this chip supports the ARM Architecture 6 extensions.  */
378 extern int arm_arch6;
379
380 /* Nonzero if instructions not present in the 'M' profile can be used.  */
381 extern int arm_arch_notm;
382
383 /* Nonzero if this chip can benefit from load scheduling.  */
384 extern int arm_ld_sched;
385
386 /* Nonzero if generating thumb code.  */
387 extern int thumb_code;
388
389 /* Nonzero if this chip is a StrongARM.  */
390 extern int arm_tune_strongarm;
391
392 /* Nonzero if this chip is a Cirrus variant.  */
393 extern int arm_arch_cirrus;
394
395 /* Nonzero if this chip supports Intel XScale with Wireless MMX technology.  */
396 extern int arm_arch_iwmmxt;
397
398 /* Nonzero if this chip is an XScale.  */
399 extern int arm_arch_xscale;
400
401 /* Nonzero if tuning for XScale.  */
402 extern int arm_tune_xscale;
403
404 /* Nonzero if tuning for stores via the write buffer.  */
405 extern int arm_tune_wbuf;
406
407 /* Nonzero if we should define __THUMB_INTERWORK__ in the
408    preprocessor.
409    XXX This is a bit of a hack, it's intended to help work around
410    problems in GLD which doesn't understand that armv5t code is
411    interworking clean.  */
412 extern int arm_cpp_interwork;
413
414 /* Nonzero if chip supports Thumb 2.  */
415 extern int arm_arch_thumb2;
416
417 /* Nonzero if chip supports integer division instruction.  */
418 extern int arm_arch_hwdiv;
419
420 #ifndef TARGET_DEFAULT
421 #define TARGET_DEFAULT  (MASK_APCS_FRAME)
422 #endif
423
424 /* The frame pointer register used in gcc has nothing to do with debugging;
425    that is controlled by the APCS-FRAME option.  */
426 #define CAN_DEBUG_WITHOUT_FP
427
428 #define OVERRIDE_OPTIONS  arm_override_options ()
429
430 /* Nonzero if PIC code requires explicit qualifiers to generate
431    PLT and GOT relocs rather than the assembler doing so implicitly.
432    Subtargets can override these if required.  */
433 #ifndef NEED_GOT_RELOC
434 #define NEED_GOT_RELOC  0
435 #endif
436 #ifndef NEED_PLT_RELOC
437 #define NEED_PLT_RELOC  0
438 #endif
439
440 /* Nonzero if we need to refer to the GOT with a PC-relative
441    offset.  In other words, generate
442
443    .word        _GLOBAL_OFFSET_TABLE_ - [. - (.Lxx + 8)]
444
445    rather than
446
447    .word        _GLOBAL_OFFSET_TABLE_ - (.Lxx + 8)
448
449    The default is true, which matches NetBSD.  Subtargets can
450    override this if required.  */
451 #ifndef GOT_PCREL
452 #define GOT_PCREL   1
453 #endif
454 \f
455 /* Target machine storage Layout.  */
456
457
458 /* Define this macro if it is advisable to hold scalars in registers
459    in a wider mode than that declared by the program.  In such cases,
460    the value is constrained to be within the bounds of the declared
461    type, but kept valid in the wider mode.  The signedness of the
462    extension may differ from that of the type.  */
463
464 /* It is far faster to zero extend chars than to sign extend them */
465
466 #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE)     \
467   if (GET_MODE_CLASS (MODE) == MODE_INT         \
468       && GET_MODE_SIZE (MODE) < 4)              \
469     {                                           \
470       if (MODE == QImode)                       \
471         UNSIGNEDP = 1;                          \
472       else if (MODE == HImode)                  \
473         UNSIGNEDP = 1;                          \
474       (MODE) = SImode;                          \
475     }
476
477 #define PROMOTE_FUNCTION_MODE(MODE, UNSIGNEDP, TYPE)    \
478   if ((GET_MODE_CLASS (MODE) == MODE_INT                \
479        || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT)    \
480       && GET_MODE_SIZE (MODE) < 4)                      \
481     (MODE) = SImode;                                    \
482
483 /* Define this if most significant bit is lowest numbered
484    in instructions that operate on numbered bit-fields.  */
485 #define BITS_BIG_ENDIAN  0
486
487 /* Define this if most significant byte of a word is the lowest numbered.
488    Most ARM processors are run in little endian mode, so that is the default.
489    If you want to have it run-time selectable, change the definition in a
490    cover file to be TARGET_BIG_ENDIAN.  */
491 #define BYTES_BIG_ENDIAN  (TARGET_BIG_END != 0)
492
493 /* Define this if most significant word of a multiword number is the lowest
494    numbered.
495    This is always false, even when in big-endian mode.  */
496 #define WORDS_BIG_ENDIAN  (BYTES_BIG_ENDIAN && ! TARGET_LITTLE_WORDS)
497
498 /* LIBGCC2_WORDS_BIG_ENDIAN has to be a constant, so we define this based
499    on processor pre-defineds when compiling libgcc2.c.  */
500 #if defined(__ARMEB__) && !defined(__ARMWEL__)
501 #define LIBGCC2_WORDS_BIG_ENDIAN 1
502 #else
503 #define LIBGCC2_WORDS_BIG_ENDIAN 0
504 #endif
505
506 /* Define this if most significant word of doubles is the lowest numbered.
507    The rules are different based on whether or not we use FPA-format,
508    VFP-format or some other floating point co-processor's format doubles.  */
509 #define FLOAT_WORDS_BIG_ENDIAN (arm_float_words_big_endian ())
510
511 #define UNITS_PER_WORD  4
512
513 /* Use the option -mvectorize-with-neon-quad to override the use of doubleword
514    registers when autovectorizing for Neon, at least until multiple vector
515    widths are supported properly by the middle-end.  */
516 #define UNITS_PER_SIMD_WORD(MODE) \
517   (TARGET_NEON ? (TARGET_NEON_VECTORIZE_QUAD ? 16 : 8) : UNITS_PER_WORD)
518
519 /* True if natural alignment is used for doubleword types.  */
520 #define ARM_DOUBLEWORD_ALIGN    TARGET_AAPCS_BASED
521
522 #define DOUBLEWORD_ALIGNMENT 64
523
524 #define PARM_BOUNDARY   32
525
526 #define STACK_BOUNDARY  (ARM_DOUBLEWORD_ALIGN ? DOUBLEWORD_ALIGNMENT : 32)
527
528 #define PREFERRED_STACK_BOUNDARY \
529     (arm_abi == ARM_ABI_ATPCS ? 64 : STACK_BOUNDARY)
530
531 #define FUNCTION_BOUNDARY  32
532
533 /* The lowest bit is used to indicate Thumb-mode functions, so the
534    vbit must go into the delta field of pointers to member
535    functions.  */
536 #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_delta
537
538 #define EMPTY_FIELD_BOUNDARY  32
539
540 #define BIGGEST_ALIGNMENT (ARM_DOUBLEWORD_ALIGN ? DOUBLEWORD_ALIGNMENT : 32)
541
542 /* XXX Blah -- this macro is used directly by libobjc.  Since it
543    supports no vector modes, cut out the complexity and fall back
544    on BIGGEST_FIELD_ALIGNMENT.  */
545 #ifdef IN_TARGET_LIBS
546 #define BIGGEST_FIELD_ALIGNMENT 64
547 #endif
548
549 /* Make strings word-aligned so strcpy from constants will be faster.  */
550 #define CONSTANT_ALIGNMENT_FACTOR (TARGET_THUMB || ! arm_tune_xscale ? 1 : 2)
551
552 #define CONSTANT_ALIGNMENT(EXP, ALIGN)                          \
553    ((TREE_CODE (EXP) == STRING_CST                              \
554      && !optimize_size                                          \
555      && (ALIGN) < BITS_PER_WORD * CONSTANT_ALIGNMENT_FACTOR)    \
556     ? BITS_PER_WORD * CONSTANT_ALIGNMENT_FACTOR : (ALIGN))
557
558 /* Setting STRUCTURE_SIZE_BOUNDARY to 32 produces more efficient code, but the
559    value set in previous versions of this toolchain was 8, which produces more
560    compact structures.  The command line option -mstructure_size_boundary=<n>
561    can be used to change this value.  For compatibility with the ARM SDK
562    however the value should be left at 32.  ARM SDT Reference Manual (ARM DUI
563    0020D) page 2-20 says "Structures are aligned on word boundaries".
564    The AAPCS specifies a value of 8.  */
565 #define STRUCTURE_SIZE_BOUNDARY arm_structure_size_boundary
566 extern int arm_structure_size_boundary;
567
568 /* This is the value used to initialize arm_structure_size_boundary.  If a
569    particular arm target wants to change the default value it should change
570    the definition of this macro, not STRUCTURE_SIZE_BOUNDARY.  See netbsd.h
571    for an example of this.  */
572 #ifndef DEFAULT_STRUCTURE_SIZE_BOUNDARY
573 #define DEFAULT_STRUCTURE_SIZE_BOUNDARY 32
574 #endif
575
576 /* Nonzero if move instructions will actually fail to work
577    when given unaligned data.  */
578 #define STRICT_ALIGNMENT 1
579
580 /* wchar_t is unsigned under the AAPCS.  */
581 #ifndef WCHAR_TYPE
582 #define WCHAR_TYPE (TARGET_AAPCS_BASED ? "unsigned int" : "int")
583
584 #define WCHAR_TYPE_SIZE BITS_PER_WORD
585 #endif
586
587 #ifndef SIZE_TYPE
588 #define SIZE_TYPE (TARGET_AAPCS_BASED ? "unsigned int" : "long unsigned int")
589 #endif
590
591 #ifndef PTRDIFF_TYPE
592 #define PTRDIFF_TYPE (TARGET_AAPCS_BASED ? "int" : "long int")
593 #endif
594
595 /* AAPCS requires that structure alignment is affected by bitfields.  */
596 #ifndef PCC_BITFIELD_TYPE_MATTERS
597 #define PCC_BITFIELD_TYPE_MATTERS TARGET_AAPCS_BASED
598 #endif
599
600 \f
601 /* Standard register usage.  */
602
603 /* Register allocation in ARM Procedure Call Standard (as used on RISCiX):
604    (S - saved over call).
605
606         r0         *    argument word/integer result
607         r1-r3           argument word
608
609         r4-r8        S  register variable
610         r9           S  (rfp) register variable (real frame pointer)
611
612         r10        F S  (sl) stack limit (used by -mapcs-stack-check)
613         r11        F S  (fp) argument pointer
614         r12             (ip) temp workspace
615         r13        F S  (sp) lower end of current stack frame
616         r14             (lr) link address/workspace
617         r15        F    (pc) program counter
618
619         f0              floating point result
620         f1-f3           floating point scratch
621
622         f4-f7        S  floating point variable
623
624         cc              This is NOT a real register, but is used internally
625                         to represent things that use or set the condition
626                         codes.
627         sfp             This isn't either.  It is used during rtl generation
628                         since the offset between the frame pointer and the
629                         auto's isn't known until after register allocation.
630         afp             Nor this, we only need this because of non-local
631                         goto.  Without it fp appears to be used and the
632                         elimination code won't get rid of sfp.  It tracks
633                         fp exactly at all times.
634
635    *: See CONDITIONAL_REGISTER_USAGE  */
636
637 /*
638         mvf0            Cirrus floating point result
639         mvf1-mvf3       Cirrus floating point scratch
640         mvf4-mvf15   S  Cirrus floating point variable.  */
641
642 /*      s0-s15          VFP scratch (aka d0-d7).
643         s16-s31       S VFP variable (aka d8-d15).
644         vfpcc           Not a real register.  Represents the VFP condition
645                         code flags.  */
646
647 /* The stack backtrace structure is as follows:
648   fp points to here:  |  save code pointer  |      [fp]
649                       |  return link value  |      [fp, #-4]
650                       |  return sp value    |      [fp, #-8]
651                       |  return fp value    |      [fp, #-12]
652                      [|  saved r10 value    |]
653                      [|  saved r9 value     |]
654                      [|  saved r8 value     |]
655                      [|  saved r7 value     |]
656                      [|  saved r6 value     |]
657                      [|  saved r5 value     |]
658                      [|  saved r4 value     |]
659                      [|  saved r3 value     |]
660                      [|  saved r2 value     |]
661                      [|  saved r1 value     |]
662                      [|  saved r0 value     |]
663                      [|  saved f7 value     |]     three words
664                      [|  saved f6 value     |]     three words
665                      [|  saved f5 value     |]     three words
666                      [|  saved f4 value     |]     three words
667   r0-r3 are not normally saved in a C function.  */
668
669 /* 1 for registers that have pervasive standard uses
670    and are not available for the register allocator.  */
671 #define FIXED_REGISTERS \
672 {                       \
673   0,0,0,0,0,0,0,0,      \
674   0,0,0,0,0,1,0,1,      \
675   0,0,0,0,0,0,0,0,      \
676   1,1,1,                \
677   1,1,1,1,1,1,1,1,      \
678   1,1,1,1,1,1,1,1,      \
679   1,1,1,1,1,1,1,1,      \
680   1,1,1,1,1,1,1,1,      \
681   1,1,1,1,              \
682   1,1,1,1,1,1,1,1,      \
683   1,1,1,1,1,1,1,1,      \
684   1,1,1,1,1,1,1,1,      \
685   1,1,1,1,1,1,1,1,      \
686   1,1,1,1,1,1,1,1,      \
687   1,1,1,1,1,1,1,1,      \
688   1,1,1,1,1,1,1,1,      \
689   1,1,1,1,1,1,1,1,      \
690   1                     \
691 }
692
693 /* 1 for registers not available across function calls.
694    These must include the FIXED_REGISTERS and also any
695    registers that can be used without being saved.
696    The latter must include the registers where values are returned
697    and the register where structure-value addresses are passed.
698    Aside from that, you can include as many other registers as you like.
699    The CC is not preserved over function calls on the ARM 6, so it is
700    easier to assume this for all.  SFP is preserved, since FP is.  */
701 #define CALL_USED_REGISTERS  \
702 {                            \
703   1,1,1,1,0,0,0,0,           \
704   0,0,0,0,1,1,1,1,           \
705   1,1,1,1,0,0,0,0,           \
706   1,1,1,                     \
707   1,1,1,1,1,1,1,1,           \
708   1,1,1,1,1,1,1,1,           \
709   1,1,1,1,1,1,1,1,           \
710   1,1,1,1,1,1,1,1,           \
711   1,1,1,1,                   \
712   1,1,1,1,1,1,1,1,           \
713   1,1,1,1,1,1,1,1,           \
714   1,1,1,1,1,1,1,1,           \
715   1,1,1,1,1,1,1,1,           \
716   1,1,1,1,1,1,1,1,           \
717   1,1,1,1,1,1,1,1,           \
718   1,1,1,1,1,1,1,1,           \
719   1,1,1,1,1,1,1,1,           \
720   1                          \
721 }
722
723 #ifndef SUBTARGET_CONDITIONAL_REGISTER_USAGE
724 #define SUBTARGET_CONDITIONAL_REGISTER_USAGE
725 #endif
726
727 #define CONDITIONAL_REGISTER_USAGE                              \
728 {                                                               \
729   int regno;                                                    \
730                                                                 \
731   if (TARGET_SOFT_FLOAT || TARGET_THUMB1 || !TARGET_FPA)        \
732     {                                                           \
733       for (regno = FIRST_FPA_REGNUM;                            \
734            regno <= LAST_FPA_REGNUM; ++regno)                   \
735         fixed_regs[regno] = call_used_regs[regno] = 1;          \
736     }                                                           \
737                                                                 \
738   if (TARGET_THUMB && optimize_size)                            \
739     {                                                           \
740       /* When optimizing for size, it's better not to use       \
741          the HI regs, because of the overhead of stacking       \
742          them.  */                                              \
743       /* ??? Is this still true for thumb2?  */                 \
744       for (regno = FIRST_HI_REGNUM;                             \
745            regno <= LAST_HI_REGNUM; ++regno)                    \
746         fixed_regs[regno] = call_used_regs[regno] = 1;          \
747     }                                                           \
748                                                                 \
749   /* The link register can be clobbered by any branch insn,     \
750      but we have no way to track that at present, so mark       \
751      it as unavailable.  */                                     \
752   if (TARGET_THUMB1)                                            \
753     fixed_regs[LR_REGNUM] = call_used_regs[LR_REGNUM] = 1;      \
754                                                                 \
755   if (TARGET_32BIT && TARGET_HARD_FLOAT)                        \
756     {                                                           \
757       if (TARGET_MAVERICK)                                      \
758         {                                                       \
759           for (regno = FIRST_FPA_REGNUM;                        \
760                regno <= LAST_FPA_REGNUM; ++ regno)              \
761             fixed_regs[regno] = call_used_regs[regno] = 1;      \
762           for (regno = FIRST_CIRRUS_FP_REGNUM;                  \
763                regno <= LAST_CIRRUS_FP_REGNUM; ++ regno)        \
764             {                                                   \
765               fixed_regs[regno] = 0;                            \
766               call_used_regs[regno] = regno < FIRST_CIRRUS_FP_REGNUM + 4; \
767             }                                                   \
768         }                                                       \
769       if (TARGET_VFP)                                           \
770         {                                                       \
771           /* VFPv3 registers are disabled when earlier VFP      \
772              versions are selected due to the definition of     \
773              LAST_VFP_REGNUM.  */                               \
774           for (regno = FIRST_VFP_REGNUM;                        \
775                regno <= LAST_VFP_REGNUM; ++ regno)              \
776             {                                                   \
777               fixed_regs[regno] = 0;                            \
778               call_used_regs[regno] = regno < FIRST_VFP_REGNUM + 16 \
779                 || regno >= FIRST_VFP_REGNUM + 32;              \
780             }                                                   \
781         }                                                       \
782     }                                                           \
783                                                                 \
784   if (TARGET_REALLY_IWMMXT)                                     \
785     {                                                           \
786       regno = FIRST_IWMMXT_GR_REGNUM;                           \
787       /* The 2002/10/09 revision of the XScale ABI has wCG0     \
788          and wCG1 as call-preserved registers.  The 2002/11/21  \
789          revision changed this so that all wCG registers are    \
790          scratch registers.  */                                 \
791       for (regno = FIRST_IWMMXT_GR_REGNUM;                      \
792            regno <= LAST_IWMMXT_GR_REGNUM; ++ regno)            \
793         fixed_regs[regno] = 0;                                  \
794       /* The XScale ABI has wR0 - wR9 as scratch registers,     \
795          the rest as call-preserved registers.  */              \
796       for (regno = FIRST_IWMMXT_REGNUM;                         \
797            regno <= LAST_IWMMXT_REGNUM; ++ regno)               \
798         {                                                       \
799           fixed_regs[regno] = 0;                                \
800           call_used_regs[regno] = regno < FIRST_IWMMXT_REGNUM + 10; \
801         }                                                       \
802     }                                                           \
803                                                                 \
804   if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)     \
805     {                                                           \
806       fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;                  \
807       call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;              \
808     }                                                           \
809   else if (TARGET_APCS_STACK)                                   \
810     {                                                           \
811       fixed_regs[10]     = 1;                                   \
812       call_used_regs[10] = 1;                                   \
813     }                                                           \
814   /* -mcaller-super-interworking reserves r11 for calls to      \
815      _interwork_r11_call_via_rN().  Making the register global  \
816      is an easy way of ensuring that it remains valid for all   \
817      calls.  */                                                 \
818   if (TARGET_APCS_FRAME || TARGET_CALLER_INTERWORKING           \
819       || TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME)           \
820     {                                                           \
821       fixed_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1;            \
822       call_used_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1;        \
823       if (TARGET_CALLER_INTERWORKING)                           \
824         global_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1;         \
825     }                                                           \
826   SUBTARGET_CONDITIONAL_REGISTER_USAGE                          \
827 }
828
829 /* These are a couple of extensions to the formats accepted
830    by asm_fprintf:
831      %@ prints out ASM_COMMENT_START
832      %r prints out REGISTER_PREFIX reg_names[arg]  */
833 #define ASM_FPRINTF_EXTENSIONS(FILE, ARGS, P)           \
834   case '@':                                             \
835     fputs (ASM_COMMENT_START, FILE);                    \
836     break;                                              \
837                                                         \
838   case 'r':                                             \
839     fputs (REGISTER_PREFIX, FILE);                      \
840     fputs (reg_names [va_arg (ARGS, int)], FILE);       \
841     break;
842
843 /* Round X up to the nearest word.  */
844 #define ROUND_UP_WORD(X) (((X) + 3) & ~3)
845
846 /* Convert fron bytes to ints.  */
847 #define ARM_NUM_INTS(X) (((X) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
848
849 /* The number of (integer) registers required to hold a quantity of type MODE.
850    Also used for VFP registers.  */
851 #define ARM_NUM_REGS(MODE)                              \
852   ARM_NUM_INTS (GET_MODE_SIZE (MODE))
853
854 /* The number of (integer) registers required to hold a quantity of TYPE MODE.  */
855 #define ARM_NUM_REGS2(MODE, TYPE)                   \
856   ARM_NUM_INTS ((MODE) == BLKmode ?             \
857   int_size_in_bytes (TYPE) : GET_MODE_SIZE (MODE))
858
859 /* The number of (integer) argument register available.  */
860 #define NUM_ARG_REGS            4
861
862 /* Return the register number of the N'th (integer) argument.  */
863 #define ARG_REGISTER(N)         (N - 1)
864
865 /* Specify the registers used for certain standard purposes.
866    The values of these macros are register numbers.  */
867
868 /* The number of the last argument register.  */
869 #define LAST_ARG_REGNUM         ARG_REGISTER (NUM_ARG_REGS)
870
871 /* The numbers of the Thumb register ranges.  */
872 #define FIRST_LO_REGNUM         0
873 #define LAST_LO_REGNUM          7
874 #define FIRST_HI_REGNUM         8
875 #define LAST_HI_REGNUM          11
876
877 #ifndef TARGET_UNWIND_INFO
878 /* We use sjlj exceptions for backwards compatibility.  */
879 #define MUST_USE_SJLJ_EXCEPTIONS 1
880 #endif
881
882 /* We can generate DWARF2 Unwind info, even though we don't use it.  */
883 #define DWARF2_UNWIND_INFO 1
884
885 /* Use r0 and r1 to pass exception handling information.  */
886 #define EH_RETURN_DATA_REGNO(N) (((N) < 2) ? N : INVALID_REGNUM)
887
888 /* The register that holds the return address in exception handlers.  */
889 #define ARM_EH_STACKADJ_REGNUM  2
890 #define EH_RETURN_STACKADJ_RTX  gen_rtx_REG (SImode, ARM_EH_STACKADJ_REGNUM)
891
892 /* The native (Norcroft) Pascal compiler for the ARM passes the static chain
893    as an invisible last argument (possible since varargs don't exist in
894    Pascal), so the following is not true.  */
895 #define STATIC_CHAIN_REGNUM     12
896
897 /* Define this to be where the real frame pointer is if it is not possible to
898    work out the offset between the frame pointer and the automatic variables
899    until after register allocation has taken place.  FRAME_POINTER_REGNUM
900    should point to a special register that we will make sure is eliminated.
901
902    For the Thumb we have another problem.  The TPCS defines the frame pointer
903    as r11, and GCC believes that it is always possible to use the frame pointer
904    as base register for addressing purposes.  (See comments in
905    find_reloads_address()).  But - the Thumb does not allow high registers,
906    including r11, to be used as base address registers.  Hence our problem.
907
908    The solution used here, and in the old thumb port is to use r7 instead of
909    r11 as the hard frame pointer and to have special code to generate
910    backtrace structures on the stack (if required to do so via a command line
911    option) using r11.  This is the only 'user visible' use of r11 as a frame
912    pointer.  */
913 #define ARM_HARD_FRAME_POINTER_REGNUM   11
914 #define THUMB_HARD_FRAME_POINTER_REGNUM  7
915
916 #define HARD_FRAME_POINTER_REGNUM               \
917   (TARGET_ARM                                   \
918    ? ARM_HARD_FRAME_POINTER_REGNUM              \
919    : THUMB_HARD_FRAME_POINTER_REGNUM)
920
921 #define FP_REGNUM                       HARD_FRAME_POINTER_REGNUM
922
923 /* Register to use for pushing function arguments.  */
924 #define STACK_POINTER_REGNUM    SP_REGNUM
925
926 /* ARM floating pointer registers.  */
927 #define FIRST_FPA_REGNUM        16
928 #define LAST_FPA_REGNUM         23
929 #define IS_FPA_REGNUM(REGNUM) \
930   (((REGNUM) >= FIRST_FPA_REGNUM) && ((REGNUM) <= LAST_FPA_REGNUM))
931
932 #define FIRST_IWMMXT_GR_REGNUM  43
933 #define LAST_IWMMXT_GR_REGNUM   46
934 #define FIRST_IWMMXT_REGNUM     47
935 #define LAST_IWMMXT_REGNUM      62
936 #define IS_IWMMXT_REGNUM(REGNUM) \
937   (((REGNUM) >= FIRST_IWMMXT_REGNUM) && ((REGNUM) <= LAST_IWMMXT_REGNUM))
938 #define IS_IWMMXT_GR_REGNUM(REGNUM) \
939   (((REGNUM) >= FIRST_IWMMXT_GR_REGNUM) && ((REGNUM) <= LAST_IWMMXT_GR_REGNUM))
940
941 /* Base register for access to local variables of the function.  */
942 #define FRAME_POINTER_REGNUM    25
943
944 /* Base register for access to arguments of the function.  */
945 #define ARG_POINTER_REGNUM      26
946
947 #define FIRST_CIRRUS_FP_REGNUM  27
948 #define LAST_CIRRUS_FP_REGNUM   42
949 #define IS_CIRRUS_REGNUM(REGNUM) \
950   (((REGNUM) >= FIRST_CIRRUS_FP_REGNUM) && ((REGNUM) <= LAST_CIRRUS_FP_REGNUM))
951
952 #define FIRST_VFP_REGNUM        63
953 #define D7_VFP_REGNUM           78  /* Registers 77 and 78 == VFP reg D7.  */
954 #define LAST_VFP_REGNUM \
955   (TARGET_VFPD32 ? LAST_HI_VFP_REGNUM : LAST_LO_VFP_REGNUM)
956
957 #define IS_VFP_REGNUM(REGNUM) \
958   (((REGNUM) >= FIRST_VFP_REGNUM) && ((REGNUM) <= LAST_VFP_REGNUM))
959
960 /* VFP registers are split into two types: those defined by VFP versions < 3
961    have D registers overlaid on consecutive pairs of S registers. VFP version 3
962    defines 16 new D registers (d16-d31) which, for simplicity and correctness
963    in various parts of the backend, we implement as "fake" single-precision
964    registers (which would be S32-S63, but cannot be used in that way).  The
965    following macros define these ranges of registers.  */
966 #define LAST_LO_VFP_REGNUM      94
967 #define FIRST_HI_VFP_REGNUM     95
968 #define LAST_HI_VFP_REGNUM      126
969
970 #define VFP_REGNO_OK_FOR_SINGLE(REGNUM) \
971   ((REGNUM) <= LAST_LO_VFP_REGNUM)
972
973 /* DFmode values are only valid in even register pairs.  */
974 #define VFP_REGNO_OK_FOR_DOUBLE(REGNUM) \
975   ((((REGNUM) - FIRST_VFP_REGNUM) & 1) == 0)
976
977 /* Neon Quad values must start at a multiple of four registers.  */
978 #define NEON_REGNO_OK_FOR_QUAD(REGNUM) \
979   ((((REGNUM) - FIRST_VFP_REGNUM) & 3) == 0)
980
981 /* Neon structures of vectors must be in even register pairs and there
982    must be enough registers available.  Because of various patterns
983    requiring quad registers, we require them to start at a multiple of
984    four.  */
985 #define NEON_REGNO_OK_FOR_NREGS(REGNUM, N) \
986   ((((REGNUM) - FIRST_VFP_REGNUM) & 3) == 0 \
987    && (LAST_VFP_REGNUM - (REGNUM) >= 2 * (N) - 1))
988
989 /* The number of hard registers is 16 ARM + 8 FPA + 1 CC + 1 SFP + 1 AFP.  */
990 /* + 16 Cirrus registers take us up to 43.  */
991 /* Intel Wireless MMX Technology registers add 16 + 4 more.  */
992 /* VFP (VFP3) adds 32 (64) + 1 more.  */
993 #define FIRST_PSEUDO_REGISTER   128
994
995 #define DBX_REGISTER_NUMBER(REGNO) arm_dbx_register_number (REGNO)
996
997 /* Value should be nonzero if functions must have frame pointers.
998    Zero means the frame pointer need not be set up (and parms may be accessed
999    via the stack pointer) in functions that seem suitable.
1000    If we have to have a frame pointer we might as well make use of it.
1001    APCS says that the frame pointer does not need to be pushed in leaf
1002    functions, or simple tail call functions.  */
1003
1004 #ifndef SUBTARGET_FRAME_POINTER_REQUIRED
1005 #define SUBTARGET_FRAME_POINTER_REQUIRED 0
1006 #endif
1007
1008 #define FRAME_POINTER_REQUIRED                                  \
1009   (cfun->has_nonlocal_label                             \
1010    || SUBTARGET_FRAME_POINTER_REQUIRED                          \
1011    || (TARGET_ARM && TARGET_APCS_FRAME && ! leaf_function_p ()))
1012
1013 /* Return number of consecutive hard regs needed starting at reg REGNO
1014    to hold something of mode MODE.
1015    This is ordinarily the length in words of a value of mode MODE
1016    but can be less for certain modes in special long registers.
1017
1018    On the ARM regs are UNITS_PER_WORD bits wide; FPA regs can hold any FP
1019    mode.  */
1020 #define HARD_REGNO_NREGS(REGNO, MODE)   \
1021   ((TARGET_32BIT                        \
1022     && REGNO >= FIRST_FPA_REGNUM        \
1023     && REGNO != FRAME_POINTER_REGNUM    \
1024     && REGNO != ARG_POINTER_REGNUM)     \
1025     && !IS_VFP_REGNUM (REGNO)           \
1026    ? 1 : ARM_NUM_REGS (MODE))
1027
1028 /* Return true if REGNO is suitable for holding a quantity of type MODE.  */
1029 #define HARD_REGNO_MODE_OK(REGNO, MODE)                                 \
1030   arm_hard_regno_mode_ok ((REGNO), (MODE))
1031
1032 /* Value is 1 if it is a good idea to tie two pseudo registers
1033    when one has mode MODE1 and one has mode MODE2.
1034    If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2,
1035    for any hard reg, then this must be 0 for correct output.  */
1036 #define MODES_TIEABLE_P(MODE1, MODE2)  \
1037   (GET_MODE_CLASS (MODE1) == GET_MODE_CLASS (MODE2))
1038
1039 #define VALID_IWMMXT_REG_MODE(MODE) \
1040  (arm_vector_mode_supported_p (MODE) || (MODE) == DImode)
1041
1042 /* Modes valid for Neon D registers.  */
1043 #define VALID_NEON_DREG_MODE(MODE) \
1044   ((MODE) == V2SImode || (MODE) == V4HImode || (MODE) == V8QImode \
1045    || (MODE) == V2SFmode || (MODE) == DImode)
1046
1047 /* Modes valid for Neon Q registers.  */
1048 #define VALID_NEON_QREG_MODE(MODE) \
1049   ((MODE) == V4SImode || (MODE) == V8HImode || (MODE) == V16QImode \
1050    || (MODE) == V4SFmode || (MODE) == V2DImode)
1051
1052 /* Structure modes valid for Neon registers.  */
1053 #define VALID_NEON_STRUCT_MODE(MODE) \
1054   ((MODE) == TImode || (MODE) == EImode || (MODE) == OImode \
1055    || (MODE) == CImode || (MODE) == XImode)
1056
1057 /* The order in which register should be allocated.  It is good to use ip
1058    since no saving is required (though calls clobber it) and it never contains
1059    function parameters.  It is quite good to use lr since other calls may
1060    clobber it anyway.  Allocate r0 through r3 in reverse order since r3 is
1061    least likely to contain a function parameter; in addition results are
1062    returned in r0.
1063    For VFP/VFPv3, allocate D16-D31 first, then caller-saved registers (D0-D7),
1064    then D8-D15.  The reason for doing this is to attempt to reduce register
1065    pressure when both single- and double-precision registers are used in a
1066    function.  */
1067
1068 #define REG_ALLOC_ORDER                         \
1069 {                                               \
1070      3,  2,  1,  0, 12, 14,  4,  5,             \
1071      6,  7,  8, 10,  9, 11, 13, 15,             \
1072     16, 17, 18, 19, 20, 21, 22, 23,             \
1073     27, 28, 29, 30, 31, 32, 33, 34,             \
1074     35, 36, 37, 38, 39, 40, 41, 42,             \
1075     43, 44, 45, 46, 47, 48, 49, 50,             \
1076     51, 52, 53, 54, 55, 56, 57, 58,             \
1077     59, 60, 61, 62,                             \
1078     24, 25, 26,                                 \
1079     95,  96,  97,  98,  99, 100, 101, 102,      \
1080    103, 104, 105, 106, 107, 108, 109, 110,      \
1081    111, 112, 113, 114, 115, 116, 117, 118,      \
1082    119, 120, 121, 122, 123, 124, 125, 126,      \
1083     78,  77,  76,  75,  74,  73,  72,  71,      \
1084     70,  69,  68,  67,  66,  65,  64,  63,      \
1085     79,  80,  81,  82,  83,  84,  85,  86,      \
1086     87,  88,  89,  90,  91,  92,  93,  94,      \
1087    127                                          \
1088 }
1089
1090 /* Use different register alloc ordering for Thumb.  */
1091 #define ORDER_REGS_FOR_LOCAL_ALLOC arm_order_regs_for_local_alloc ()
1092
1093 /* Interrupt functions can only use registers that have already been
1094    saved by the prologue, even if they would normally be
1095    call-clobbered.  */
1096 #define HARD_REGNO_RENAME_OK(SRC, DST)                                  \
1097         (! IS_INTERRUPT (cfun->machine->func_type) ||                   \
1098          df_regs_ever_live_p (DST))
1099 \f
1100 /* Register and constant classes.  */
1101
1102 /* Register classes: used to be simple, just all ARM regs or all FPA regs
1103    Now that the Thumb is involved it has become more complicated.  */
1104 enum reg_class
1105 {
1106   NO_REGS,
1107   FPA_REGS,
1108   CIRRUS_REGS,
1109   VFP_D0_D7_REGS,
1110   VFP_LO_REGS,
1111   VFP_HI_REGS,
1112   VFP_REGS,
1113   IWMMXT_GR_REGS,
1114   IWMMXT_REGS,
1115   LO_REGS,
1116   STACK_REG,
1117   BASE_REGS,
1118   HI_REGS,
1119   CC_REG,
1120   VFPCC_REG,
1121   GENERAL_REGS,
1122   CORE_REGS,
1123   ALL_REGS,
1124   LIM_REG_CLASSES
1125 };
1126
1127 #define N_REG_CLASSES  (int) LIM_REG_CLASSES
1128
1129 /* Give names of register classes as strings for dump file.  */
1130 #define REG_CLASS_NAMES  \
1131 {                       \
1132   "NO_REGS",            \
1133   "FPA_REGS",           \
1134   "CIRRUS_REGS",        \
1135   "VFP_D0_D7_REGS",     \
1136   "VFP_LO_REGS",        \
1137   "VFP_HI_REGS",        \
1138   "VFP_REGS",           \
1139   "IWMMXT_GR_REGS",     \
1140   "IWMMXT_REGS",        \
1141   "LO_REGS",            \
1142   "STACK_REG",          \
1143   "BASE_REGS",          \
1144   "HI_REGS",            \
1145   "CC_REG",             \
1146   "VFPCC_REG",          \
1147   "GENERAL_REGS",       \
1148   "CORE_REGS",          \
1149   "ALL_REGS",           \
1150 }
1151
1152 /* Define which registers fit in which classes.
1153    This is an initializer for a vector of HARD_REG_SET
1154    of length N_REG_CLASSES.  */
1155 #define REG_CLASS_CONTENTS                                              \
1156 {                                                                       \
1157   { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, /* NO_REGS  */    \
1158   { 0x00FF0000, 0x00000000, 0x00000000, 0x00000000 }, /* FPA_REGS */    \
1159   { 0xF8000000, 0x000007FF, 0x00000000, 0x00000000 }, /* CIRRUS_REGS */ \
1160   { 0x00000000, 0x80000000, 0x00007FFF, 0x00000000 }, /* VFP_D0_D7_REGS  */ \
1161   { 0x00000000, 0x80000000, 0x7FFFFFFF, 0x00000000 }, /* VFP_LO_REGS  */ \
1162   { 0x00000000, 0x00000000, 0x80000000, 0x7FFFFFFF }, /* VFP_HI_REGS  */ \
1163   { 0x00000000, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF }, /* VFP_REGS  */   \
1164   { 0x00000000, 0x00007800, 0x00000000, 0x00000000 }, /* IWMMXT_GR_REGS */ \
1165   { 0x00000000, 0x7FFF8000, 0x00000000, 0x00000000 }, /* IWMMXT_REGS */ \
1166   { 0x000000FF, 0x00000000, 0x00000000, 0x00000000 }, /* LO_REGS */     \
1167   { 0x00002000, 0x00000000, 0x00000000, 0x00000000 }, /* STACK_REG */   \
1168   { 0x000020FF, 0x00000000, 0x00000000, 0x00000000 }, /* BASE_REGS */   \
1169   { 0x0000DF00, 0x00000000, 0x00000000, 0x00000000 }, /* HI_REGS */     \
1170   { 0x01000000, 0x00000000, 0x00000000, 0x00000000 }, /* CC_REG */      \
1171   { 0x00000000, 0x00000000, 0x00000000, 0x80000000 }, /* VFPCC_REG */   \
1172   { 0x0200DFFF, 0x00000000, 0x00000000, 0x00000000 }, /* GENERAL_REGS */ \
1173   { 0x0200FFFF, 0x00000000, 0x00000000, 0x00000000 }, /* CORE_REGS */   \
1174   { 0xFAFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF }  /* ALL_REGS */    \
1175 }
1176
1177 /* Any of the VFP register classes.  */
1178 #define IS_VFP_CLASS(X) \
1179   ((X) == VFP_D0_D7_REGS || (X) == VFP_LO_REGS \
1180    || (X) == VFP_HI_REGS || (X) == VFP_REGS)
1181
1182 /* The same information, inverted:
1183    Return the class number of the smallest class containing
1184    reg number REGNO.  This could be a conditional expression
1185    or could index an array.  */
1186 #define REGNO_REG_CLASS(REGNO)  arm_regno_class (REGNO)
1187
1188 /* FPA registers can't do subreg as all values are reformatted to internal
1189    precision.  VFP registers may only be accessed in the mode they
1190    were set.  */
1191 #define CANNOT_CHANGE_MODE_CLASS(FROM, TO, CLASS)       \
1192   (GET_MODE_SIZE (FROM) != GET_MODE_SIZE (TO)           \
1193    ? reg_classes_intersect_p (FPA_REGS, (CLASS))        \
1194      || reg_classes_intersect_p (VFP_REGS, (CLASS))     \
1195    : 0)
1196
1197 /* We need to define this for LO_REGS on thumb.  Otherwise we can end up
1198    using r0-r4 for function arguments, r7 for the stack frame and don't
1199    have enough left over to do doubleword arithmetic.  */
1200 #define CLASS_LIKELY_SPILLED_P(CLASS)   \
1201     ((TARGET_THUMB && (CLASS) == LO_REGS)       \
1202      || (CLASS) == CC_REG)
1203
1204 /* The class value for index registers, and the one for base regs.  */
1205 #define INDEX_REG_CLASS  (TARGET_THUMB1 ? LO_REGS : GENERAL_REGS)
1206 #define BASE_REG_CLASS   (TARGET_THUMB1 ? LO_REGS : CORE_REGS)
1207
1208 /* For the Thumb the high registers cannot be used as base registers
1209    when addressing quantities in QI or HI mode; if we don't know the
1210    mode, then we must be conservative.  */
1211 #define MODE_BASE_REG_CLASS(MODE)                                       \
1212     (TARGET_32BIT ? CORE_REGS :                                 \
1213      (((MODE) == SImode) ? BASE_REGS : LO_REGS))
1214
1215 /* For Thumb we can not support SP+reg addressing, so we return LO_REGS
1216    instead of BASE_REGS.  */
1217 #define MODE_BASE_REG_REG_CLASS(MODE) BASE_REG_CLASS
1218
1219 /* When SMALL_REGISTER_CLASSES is nonzero, the compiler allows
1220    registers explicitly used in the rtl to be used as spill registers
1221    but prevents the compiler from extending the lifetime of these
1222    registers.  */
1223 #define SMALL_REGISTER_CLASSES   TARGET_THUMB1
1224
1225 /* Given an rtx X being reloaded into a reg required to be
1226    in class CLASS, return the class of reg to actually use.
1227    In general this is just CLASS, but for the Thumb core registers and
1228    immediate constants we prefer a LO_REGS class or a subset.  */
1229 #define PREFERRED_RELOAD_CLASS(X, CLASS)                \
1230   (TARGET_ARM ? (CLASS) :                               \
1231    ((CLASS) == GENERAL_REGS || (CLASS) == HI_REGS       \
1232     || (CLASS) == NO_REGS || (CLASS) == STACK_REG       \
1233    ? LO_REGS : (CLASS)))
1234
1235 /* Must leave BASE_REGS reloads alone */
1236 #define THUMB_SECONDARY_INPUT_RELOAD_CLASS(CLASS, MODE, X)              \
1237   ((CLASS) != LO_REGS && (CLASS) != BASE_REGS                           \
1238    ? ((true_regnum (X) == -1 ? LO_REGS                                  \
1239        : (true_regnum (X) + HARD_REGNO_NREGS (0, MODE) > 8) ? LO_REGS   \
1240        : NO_REGS))                                                      \
1241    : NO_REGS)
1242
1243 #define THUMB_SECONDARY_OUTPUT_RELOAD_CLASS(CLASS, MODE, X)             \
1244   ((CLASS) != LO_REGS && (CLASS) != BASE_REGS                           \
1245    ? ((true_regnum (X) == -1 ? LO_REGS                                  \
1246        : (true_regnum (X) + HARD_REGNO_NREGS (0, MODE) > 8) ? LO_REGS   \
1247        : NO_REGS))                                                      \
1248    : NO_REGS)
1249
1250 /* Return the register class of a scratch register needed to copy IN into
1251    or out of a register in CLASS in MODE.  If it can be done directly,
1252    NO_REGS is returned.  */
1253 #define SECONDARY_OUTPUT_RELOAD_CLASS(CLASS, MODE, X)           \
1254   /* Restrict which direct reloads are allowed for VFP/iWMMXt regs.  */ \
1255   ((TARGET_VFP && TARGET_HARD_FLOAT                             \
1256     && IS_VFP_CLASS (CLASS))                                    \
1257    ? coproc_secondary_reload_class (MODE, X, FALSE)             \
1258    : (TARGET_IWMMXT && (CLASS) == IWMMXT_REGS)                  \
1259    ? coproc_secondary_reload_class (MODE, X, TRUE)              \
1260    : TARGET_32BIT                                               \
1261    ? (((MODE) == HImode && ! arm_arch4 && true_regnum (X) == -1) \
1262     ? GENERAL_REGS : NO_REGS)                                   \
1263    : THUMB_SECONDARY_OUTPUT_RELOAD_CLASS (CLASS, MODE, X))
1264
1265 /* If we need to load shorts byte-at-a-time, then we need a scratch.  */
1266 #define SECONDARY_INPUT_RELOAD_CLASS(CLASS, MODE, X)            \
1267   /* Restrict which direct reloads are allowed for VFP/iWMMXt regs.  */ \
1268   ((TARGET_VFP && TARGET_HARD_FLOAT                             \
1269     && IS_VFP_CLASS (CLASS))                                    \
1270     ? coproc_secondary_reload_class (MODE, X, FALSE) :          \
1271     (TARGET_IWMMXT && (CLASS) == IWMMXT_REGS) ?                 \
1272     coproc_secondary_reload_class (MODE, X, TRUE) :             \
1273   /* Cannot load constants into Cirrus registers.  */           \
1274    (TARGET_MAVERICK && TARGET_HARD_FLOAT                        \
1275      && (CLASS) == CIRRUS_REGS                                  \
1276      && (CONSTANT_P (X) || GET_CODE (X) == SYMBOL_REF))         \
1277     ? GENERAL_REGS :                                            \
1278   (TARGET_32BIT ?                                               \
1279    (((CLASS) == IWMMXT_REGS || (CLASS) == IWMMXT_GR_REGS)       \
1280       && CONSTANT_P (X))                                        \
1281    ? GENERAL_REGS :                                             \
1282    (((MODE) == HImode && ! arm_arch4                            \
1283      && (GET_CODE (X) == MEM                                    \
1284          || ((GET_CODE (X) == REG || GET_CODE (X) == SUBREG)    \
1285              && true_regnum (X) == -1)))                        \
1286     ? GENERAL_REGS : NO_REGS)                                   \
1287    : THUMB_SECONDARY_INPUT_RELOAD_CLASS (CLASS, MODE, X)))
1288
1289 /* Try a machine-dependent way of reloading an illegitimate address
1290    operand.  If we find one, push the reload and jump to WIN.  This
1291    macro is used in only one place: `find_reloads_address' in reload.c.
1292
1293    For the ARM, we wish to handle large displacements off a base
1294    register by splitting the addend across a MOV and the mem insn.
1295    This can cut the number of reloads needed.  */
1296 #define ARM_LEGITIMIZE_RELOAD_ADDRESS(X, MODE, OPNUM, TYPE, IND, WIN)      \
1297   do                                                                       \
1298     {                                                                      \
1299       if (GET_CODE (X) == PLUS                                             \
1300           && GET_CODE (XEXP (X, 0)) == REG                                 \
1301           && REGNO (XEXP (X, 0)) < FIRST_PSEUDO_REGISTER                   \
1302           && REG_MODE_OK_FOR_BASE_P (XEXP (X, 0), MODE)                    \
1303           && GET_CODE (XEXP (X, 1)) == CONST_INT)                          \
1304         {                                                                  \
1305           HOST_WIDE_INT val = INTVAL (XEXP (X, 1));                        \
1306           HOST_WIDE_INT low, high;                                         \
1307                                                                            \
1308           if (MODE == DImode || (MODE == DFmode && TARGET_SOFT_FLOAT))     \
1309             low = ((val & 0xf) ^ 0x8) - 0x8;                               \
1310           else if (TARGET_MAVERICK && TARGET_HARD_FLOAT)                   \
1311             /* Need to be careful, -256 is not a valid offset.  */         \
1312             low = val >= 0 ? (val & 0xff) : -((-val) & 0xff);              \
1313           else if (MODE == SImode                                          \
1314                    || (MODE == SFmode && TARGET_SOFT_FLOAT)                \
1315                    || ((MODE == HImode || MODE == QImode) && ! arm_arch4)) \
1316             /* Need to be careful, -4096 is not a valid offset.  */        \
1317             low = val >= 0 ? (val & 0xfff) : -((-val) & 0xfff);            \
1318           else if ((MODE == HImode || MODE == QImode) && arm_arch4)        \
1319             /* Need to be careful, -256 is not a valid offset.  */         \
1320             low = val >= 0 ? (val & 0xff) : -((-val) & 0xff);              \
1321           else if (GET_MODE_CLASS (MODE) == MODE_FLOAT                     \
1322                    && TARGET_HARD_FLOAT && TARGET_FPA)                     \
1323             /* Need to be careful, -1024 is not a valid offset.  */        \
1324             low = val >= 0 ? (val & 0x3ff) : -((-val) & 0x3ff);            \
1325           else                                                             \
1326             break;                                                         \
1327                                                                            \
1328           high = ((((val - low) & (unsigned HOST_WIDE_INT) 0xffffffff)     \
1329                    ^ (unsigned HOST_WIDE_INT) 0x80000000)                  \
1330                   - (unsigned HOST_WIDE_INT) 0x80000000);                  \
1331           /* Check for overflow or zero */                                 \
1332           if (low == 0 || high == 0 || (high + low != val))                \
1333             break;                                                         \
1334                                                                            \
1335           /* Reload the high part into a base reg; leave the low part      \
1336              in the mem.  */                                               \
1337           X = gen_rtx_PLUS (GET_MODE (X),                                  \
1338                             gen_rtx_PLUS (GET_MODE (X), XEXP (X, 0),       \
1339                                           GEN_INT (high)),                 \
1340                             GEN_INT (low));                                \
1341           push_reload (XEXP (X, 0), NULL_RTX, &XEXP (X, 0), NULL,          \
1342                        MODE_BASE_REG_CLASS (MODE), GET_MODE (X),           \
1343                        VOIDmode, 0, 0, OPNUM, TYPE);                       \
1344           goto WIN;                                                        \
1345         }                                                                  \
1346     }                                                                      \
1347   while (0)
1348
1349 /* XXX If an HImode FP+large_offset address is converted to an HImode
1350    SP+large_offset address, then reload won't know how to fix it.  It sees
1351    only that SP isn't valid for HImode, and so reloads the SP into an index
1352    register, but the resulting address is still invalid because the offset
1353    is too big.  We fix it here instead by reloading the entire address.  */
1354 /* We could probably achieve better results by defining PROMOTE_MODE to help
1355    cope with the variances between the Thumb's signed and unsigned byte and
1356    halfword load instructions.  */
1357 /* ??? This should be safe for thumb2, but we may be able to do better.  */
1358 #define THUMB_LEGITIMIZE_RELOAD_ADDRESS(X, MODE, OPNUM, TYPE, IND_L, WIN)     \
1359 do {                                                                          \
1360   rtx new_x = thumb_legitimize_reload_address (&X, MODE, OPNUM, TYPE, IND_L); \
1361   if (new_x)                                                                  \
1362     {                                                                         \
1363       X = new_x;                                                              \
1364       goto WIN;                                                               \
1365     }                                                                         \
1366 } while (0)
1367
1368 #define LEGITIMIZE_RELOAD_ADDRESS(X, MODE, OPNUM, TYPE, IND_LEVELS, WIN)   \
1369   if (TARGET_ARM)                                                          \
1370     ARM_LEGITIMIZE_RELOAD_ADDRESS (X, MODE, OPNUM, TYPE, IND_LEVELS, WIN); \
1371   else                                                                     \
1372     THUMB_LEGITIMIZE_RELOAD_ADDRESS (X, MODE, OPNUM, TYPE, IND_LEVELS, WIN)
1373
1374 /* Return the maximum number of consecutive registers
1375    needed to represent mode MODE in a register of class CLASS.
1376    ARM regs are UNITS_PER_WORD bits while FPA regs can hold any FP mode */
1377 #define CLASS_MAX_NREGS(CLASS, MODE)  \
1378   (((CLASS) == FPA_REGS || (CLASS) == CIRRUS_REGS) ? 1 : ARM_NUM_REGS (MODE))
1379
1380 /* If defined, gives a class of registers that cannot be used as the
1381    operand of a SUBREG that changes the mode of the object illegally.  */
1382
1383 /* Moves between FPA_REGS and GENERAL_REGS are two memory insns.  */
1384 #define REGISTER_MOVE_COST(MODE, FROM, TO)              \
1385   (TARGET_32BIT ?                                               \
1386    ((FROM) == FPA_REGS && (TO) != FPA_REGS ? 20 :       \
1387     (FROM) != FPA_REGS && (TO) == FPA_REGS ? 20 :       \
1388     IS_VFP_CLASS (FROM) && !IS_VFP_CLASS (TO) ? 10 :    \
1389     !IS_VFP_CLASS (FROM) && IS_VFP_CLASS (TO) ? 10 :    \
1390     (FROM) == IWMMXT_REGS && (TO) != IWMMXT_REGS ? 4 :  \
1391     (FROM) != IWMMXT_REGS && (TO) == IWMMXT_REGS ? 4 :  \
1392     (FROM) == IWMMXT_GR_REGS || (TO) == IWMMXT_GR_REGS ? 20 :  \
1393     (FROM) == CIRRUS_REGS && (TO) != CIRRUS_REGS ? 20 : \
1394     (FROM) != CIRRUS_REGS && (TO) == CIRRUS_REGS ? 20 : \
1395    2)                                                   \
1396    :                                                    \
1397    ((FROM) == HI_REGS || (TO) == HI_REGS) ? 4 : 2)
1398 \f
1399 /* Stack layout; function entry, exit and calling.  */
1400
1401 /* Define this if pushing a word on the stack
1402    makes the stack pointer a smaller address.  */
1403 #define STACK_GROWS_DOWNWARD  1
1404
1405 /* Define this to nonzero if the nominal address of the stack frame
1406    is at the high-address end of the local variables;
1407    that is, each additional local variable allocated
1408    goes at a more negative offset in the frame.  */
1409 #define FRAME_GROWS_DOWNWARD 1
1410
1411 /* The amount of scratch space needed by _interwork_{r7,r11}_call_via_rN().
1412    When present, it is one word in size, and sits at the top of the frame,
1413    between the soft frame pointer and either r7 or r11.
1414
1415    We only need _interwork_rM_call_via_rN() for -mcaller-super-interworking,
1416    and only then if some outgoing arguments are passed on the stack.  It would
1417    be tempting to also check whether the stack arguments are passed by indirect
1418    calls, but there seems to be no reason in principle why a post-reload pass
1419    couldn't convert a direct call into an indirect one.  */
1420 #define CALLER_INTERWORKING_SLOT_SIZE                   \
1421   (TARGET_CALLER_INTERWORKING                           \
1422    && crtl->outgoing_args_size != 0             \
1423    ? UNITS_PER_WORD : 0)
1424
1425 /* Offset within stack frame to start allocating local variables at.
1426    If FRAME_GROWS_DOWNWARD, this is the offset to the END of the
1427    first local allocated.  Otherwise, it is the offset to the BEGINNING
1428    of the first local allocated.  */
1429 #define STARTING_FRAME_OFFSET  0
1430
1431 /* If we generate an insn to push BYTES bytes,
1432    this says how many the stack pointer really advances by.  */
1433 /* The push insns do not do this rounding implicitly.
1434    So don't define this.  */
1435 /* #define PUSH_ROUNDING(NPUSHED)  ROUND_UP_WORD (NPUSHED) */
1436
1437 /* Define this if the maximum size of all the outgoing args is to be
1438    accumulated and pushed during the prologue.  The amount can be
1439    found in the variable crtl->outgoing_args_size.  */
1440 #define ACCUMULATE_OUTGOING_ARGS 1
1441
1442 /* Offset of first parameter from the argument pointer register value.  */
1443 #define FIRST_PARM_OFFSET(FNDECL)  (TARGET_ARM ? 4 : 0)
1444
1445 /* Value is the number of byte of arguments automatically
1446    popped when returning from a subroutine call.
1447    FUNDECL is the declaration node of the function (as a tree),
1448    FUNTYPE is the data type of the function (as a tree),
1449    or for a library call it is an identifier node for the subroutine name.
1450    SIZE is the number of bytes of arguments passed on the stack.
1451
1452    On the ARM, the caller does not pop any of its arguments that were passed
1453    on the stack.  */
1454 #define RETURN_POPS_ARGS(FUNDECL, FUNTYPE, SIZE)  0
1455
1456 /* Define how to find the value returned by a library function
1457    assuming the value has mode MODE.  */
1458 #define LIBCALL_VALUE(MODE)  \
1459   (TARGET_32BIT && TARGET_HARD_FLOAT_ABI && TARGET_FPA                  \
1460    && GET_MODE_CLASS (MODE) == MODE_FLOAT                               \
1461    ? gen_rtx_REG (MODE, FIRST_FPA_REGNUM)                               \
1462    : TARGET_32BIT && TARGET_HARD_FLOAT_ABI && TARGET_MAVERICK           \
1463      && GET_MODE_CLASS (MODE) == MODE_FLOAT                             \
1464    ? gen_rtx_REG (MODE, FIRST_CIRRUS_FP_REGNUM)                         \
1465    : TARGET_IWMMXT_ABI && arm_vector_mode_supported_p (MODE)            \
1466    ? gen_rtx_REG (MODE, FIRST_IWMMXT_REGNUM)                            \
1467    : gen_rtx_REG (MODE, ARG_REGISTER (1)))
1468
1469 /* Define how to find the value returned by a function.
1470    VALTYPE is the data type of the value (as a tree).
1471    If the precise function being called is known, FUNC is its FUNCTION_DECL;
1472    otherwise, FUNC is 0.  */
1473 #define FUNCTION_VALUE(VALTYPE, FUNC) \
1474   arm_function_value (VALTYPE, FUNC);
1475
1476 /* 1 if N is a possible register number for a function value.
1477    On the ARM, only r0 and f0 can return results.  */
1478 /* On a Cirrus chip, mvf0 can return results.  */
1479 #define FUNCTION_VALUE_REGNO_P(REGNO)  \
1480   ((REGNO) == ARG_REGISTER (1) \
1481    || (TARGET_32BIT && ((REGNO) == FIRST_CIRRUS_FP_REGNUM)              \
1482        && TARGET_HARD_FLOAT_ABI && TARGET_MAVERICK)                     \
1483    || ((REGNO) == FIRST_IWMMXT_REGNUM && TARGET_IWMMXT_ABI) \
1484    || (TARGET_32BIT && ((REGNO) == FIRST_FPA_REGNUM)                    \
1485        && TARGET_HARD_FLOAT_ABI && TARGET_FPA))
1486
1487 /* Amount of memory needed for an untyped call to save all possible return
1488    registers.  */
1489 #define APPLY_RESULT_SIZE arm_apply_result_size()
1490
1491 /* Define DEFAULT_PCC_STRUCT_RETURN to 1 if all structure and union return
1492    values must be in memory.  On the ARM, they need only do so if larger
1493    than a word, or if they contain elements offset from zero in the struct.  */
1494 #define DEFAULT_PCC_STRUCT_RETURN 0
1495
1496 /* These bits describe the different types of function supported
1497    by the ARM backend.  They are exclusive.  i.e. a function cannot be both a
1498    normal function and an interworked function, for example.  Knowing the
1499    type of a function is important for determining its prologue and
1500    epilogue sequences.
1501    Note value 7 is currently unassigned.  Also note that the interrupt
1502    function types all have bit 2 set, so that they can be tested for easily.
1503    Note that 0 is deliberately chosen for ARM_FT_UNKNOWN so that when the
1504    machine_function structure is initialized (to zero) func_type will
1505    default to unknown.  This will force the first use of arm_current_func_type
1506    to call arm_compute_func_type.  */
1507 #define ARM_FT_UNKNOWN           0 /* Type has not yet been determined.  */
1508 #define ARM_FT_NORMAL            1 /* Your normal, straightforward function.  */
1509 #define ARM_FT_INTERWORKED       2 /* A function that supports interworking.  */
1510 #define ARM_FT_ISR               4 /* An interrupt service routine.  */
1511 #define ARM_FT_FIQ               5 /* A fast interrupt service routine.  */
1512 #define ARM_FT_EXCEPTION         6 /* An ARM exception handler (subcase of ISR).  */
1513
1514 #define ARM_FT_TYPE_MASK        ((1 << 3) - 1)
1515
1516 /* In addition functions can have several type modifiers,
1517    outlined by these bit masks:  */
1518 #define ARM_FT_INTERRUPT        (1 << 2) /* Note overlap with FT_ISR and above.  */
1519 #define ARM_FT_NAKED            (1 << 3) /* No prologue or epilogue.  */
1520 #define ARM_FT_VOLATILE         (1 << 4) /* Does not return.  */
1521 #define ARM_FT_NESTED           (1 << 5) /* Embedded inside another func.  */
1522 #define ARM_FT_STACKALIGN       (1 << 6) /* Called with misaligned stack.  */
1523
1524 /* Some macros to test these flags.  */
1525 #define ARM_FUNC_TYPE(t)        (t & ARM_FT_TYPE_MASK)
1526 #define IS_INTERRUPT(t)         (t & ARM_FT_INTERRUPT)
1527 #define IS_VOLATILE(t)          (t & ARM_FT_VOLATILE)
1528 #define IS_NAKED(t)             (t & ARM_FT_NAKED)
1529 #define IS_NESTED(t)            (t & ARM_FT_NESTED)
1530 #define IS_STACKALIGN(t)        (t & ARM_FT_STACKALIGN)
1531
1532
1533 /* Structure used to hold the function stack frame layout.  Offsets are
1534    relative to the stack pointer on function entry.  Positive offsets are
1535    in the direction of stack growth.
1536    Only soft_frame is used in thumb mode.  */
1537
1538 typedef struct arm_stack_offsets GTY(())
1539 {
1540   int saved_args;       /* ARG_POINTER_REGNUM.  */
1541   int frame;            /* ARM_HARD_FRAME_POINTER_REGNUM.  */
1542   int saved_regs;
1543   int soft_frame;       /* FRAME_POINTER_REGNUM.  */
1544   int locals_base;      /* THUMB_HARD_FRAME_POINTER_REGNUM.  */
1545   int outgoing_args;    /* STACK_POINTER_REGNUM.  */
1546   unsigned int saved_regs_mask;
1547 }
1548 arm_stack_offsets;
1549
1550 /* A C structure for machine-specific, per-function data.
1551    This is added to the cfun structure.  */
1552 typedef struct machine_function GTY(())
1553 {
1554   /* Additional stack adjustment in __builtin_eh_throw.  */
1555   rtx eh_epilogue_sp_ofs;
1556   /* Records if LR has to be saved for far jumps.  */
1557   int far_jump_used;
1558   /* Records if ARG_POINTER was ever live.  */
1559   int arg_pointer_live;
1560   /* Records if the save of LR has been eliminated.  */
1561   int lr_save_eliminated;
1562   /* The size of the stack frame.  Only valid after reload.  */
1563   arm_stack_offsets stack_offsets;
1564   /* Records the type of the current function.  */
1565   unsigned long func_type;
1566   /* Record if the function has a variable argument list.  */
1567   int uses_anonymous_args;
1568   /* Records if sibcalls are blocked because an argument
1569      register is needed to preserve stack alignment.  */
1570   int sibcall_blocked;
1571   /* The PIC register for this function.  This might be a pseudo.  */
1572   rtx pic_reg;
1573   /* Labels for per-function Thumb call-via stubs.  One per potential calling
1574      register.  We can never call via LR or PC.  We can call via SP if a
1575      trampoline happens to be on the top of the stack.  */
1576   rtx call_via[14];
1577 }
1578 machine_function;
1579
1580 /* As in the machine_function, a global set of call-via labels, for code 
1581    that is in text_section.  */
1582 extern GTY(()) rtx thumb_call_via_label[14];
1583
1584 /* A C type for declaring a variable that is used as the first argument of
1585    `FUNCTION_ARG' and other related values.  For some target machines, the
1586    type `int' suffices and can hold the number of bytes of argument so far.  */
1587 typedef struct
1588 {
1589   /* This is the number of registers of arguments scanned so far.  */
1590   int nregs;
1591   /* This is the number of iWMMXt register arguments scanned so far.  */
1592   int iwmmxt_nregs;
1593   int named_count;
1594   int nargs;
1595   int can_split;
1596 } CUMULATIVE_ARGS;
1597
1598 /* Define where to put the arguments to a function.
1599    Value is zero to push the argument on the stack,
1600    or a hard register in which to store the argument.
1601
1602    MODE is the argument's machine mode.
1603    TYPE is the data type of the argument (as a tree).
1604     This is null for libcalls where that information may
1605     not be available.
1606    CUM is a variable of type CUMULATIVE_ARGS which gives info about
1607     the preceding args and about the function being called.
1608    NAMED is nonzero if this argument is a named parameter
1609     (otherwise it is an extra parameter matching an ellipsis).
1610
1611    On the ARM, normally the first 16 bytes are passed in registers r0-r3; all
1612    other arguments are passed on the stack.  If (NAMED == 0) (which happens
1613    only in assign_parms, since TARGET_SETUP_INCOMING_VARARGS is
1614    defined), say it is passed in the stack (function_prologue will
1615    indeed make it pass in the stack if necessary).  */
1616 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
1617   arm_function_arg (&(CUM), (MODE), (TYPE), (NAMED))
1618
1619 #define FUNCTION_ARG_PADDING(MODE, TYPE) \
1620   (arm_pad_arg_upward (MODE, TYPE) ? upward : downward)
1621
1622 #define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \
1623   (arm_pad_reg_upward (MODE, TYPE, FIRST) ? upward : downward)
1624
1625 /* For AAPCS, padding should never be below the argument. For other ABIs,
1626  * mimic the default.  */
1627 #define PAD_VARARGS_DOWN \
1628   ((TARGET_AAPCS_BASED) ? 0 : BYTES_BIG_ENDIAN)
1629
1630 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1631    for a call to a function whose data type is FNTYPE.
1632    For a library call, FNTYPE is 0.
1633    On the ARM, the offset starts at 0.  */
1634 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
1635   arm_init_cumulative_args (&(CUM), (FNTYPE), (LIBNAME), (FNDECL))
1636
1637 /* Update the data in CUM to advance over an argument
1638    of mode MODE and data type TYPE.
1639    (TYPE is null for libcalls where that information may not be available.)  */
1640 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)    \
1641   (CUM).nargs += 1;                                     \
1642   if (arm_vector_mode_supported_p (MODE)                \
1643       && (CUM).named_count > (CUM).nargs                \
1644       && TARGET_IWMMXT_ABI)                             \
1645     (CUM).iwmmxt_nregs += 1;                            \
1646   else                                                  \
1647     (CUM).nregs += ARM_NUM_REGS2 (MODE, TYPE)
1648
1649 /* If defined, a C expression that gives the alignment boundary, in bits, of an
1650    argument with the specified mode and type.  If it is not defined,
1651    `PARM_BOUNDARY' is used for all arguments.  */
1652 #define FUNCTION_ARG_BOUNDARY(MODE,TYPE) \
1653    ((ARM_DOUBLEWORD_ALIGN && arm_needs_doubleword_align (MODE, TYPE)) \
1654    ? DOUBLEWORD_ALIGNMENT \
1655    : PARM_BOUNDARY )
1656
1657 /* 1 if N is a possible register number for function argument passing.
1658    On the ARM, r0-r3 are used to pass args.  */
1659 #define FUNCTION_ARG_REGNO_P(REGNO)     \
1660    (IN_RANGE ((REGNO), 0, 3)            \
1661     || (TARGET_IWMMXT_ABI               \
1662         && IN_RANGE ((REGNO), FIRST_IWMMXT_REGNUM, FIRST_IWMMXT_REGNUM + 9)))
1663
1664 \f
1665 /* If your target environment doesn't prefix user functions with an
1666    underscore, you may wish to re-define this to prevent any conflicts.  */
1667 #ifndef ARM_MCOUNT_NAME
1668 #define ARM_MCOUNT_NAME "*mcount"
1669 #endif
1670
1671 /* Call the function profiler with a given profile label.  The Acorn
1672    compiler puts this BEFORE the prolog but gcc puts it afterwards.
1673    On the ARM the full profile code will look like:
1674         .data
1675         LP1
1676                 .word   0
1677         .text
1678                 mov     ip, lr
1679                 bl      mcount
1680                 .word   LP1
1681
1682    profile_function() in final.c outputs the .data section, FUNCTION_PROFILER
1683    will output the .text section.
1684
1685    The ``mov ip,lr'' seems like a good idea to stick with cc convention.
1686    ``prof'' doesn't seem to mind about this!
1687
1688    Note - this version of the code is designed to work in both ARM and
1689    Thumb modes.  */
1690 #ifndef ARM_FUNCTION_PROFILER
1691 #define ARM_FUNCTION_PROFILER(STREAM, LABELNO)          \
1692 {                                                       \
1693   char temp[20];                                        \
1694   rtx sym;                                              \
1695                                                         \
1696   asm_fprintf (STREAM, "\tmov\t%r, %r\n\tbl\t",         \
1697            IP_REGNUM, LR_REGNUM);                       \
1698   assemble_name (STREAM, ARM_MCOUNT_NAME);              \
1699   fputc ('\n', STREAM);                                 \
1700   ASM_GENERATE_INTERNAL_LABEL (temp, "LP", LABELNO);    \
1701   sym = gen_rtx_SYMBOL_REF (Pmode, temp);               \
1702   assemble_aligned_integer (UNITS_PER_WORD, sym);       \
1703 }
1704 #endif
1705
1706 #ifdef THUMB_FUNCTION_PROFILER
1707 #define FUNCTION_PROFILER(STREAM, LABELNO)              \
1708   if (TARGET_ARM)                                       \
1709     ARM_FUNCTION_PROFILER (STREAM, LABELNO)             \
1710   else                                                  \
1711     THUMB_FUNCTION_PROFILER (STREAM, LABELNO)
1712 #else
1713 #define FUNCTION_PROFILER(STREAM, LABELNO)              \
1714     ARM_FUNCTION_PROFILER (STREAM, LABELNO)
1715 #endif
1716
1717 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
1718    the stack pointer does not matter.  The value is tested only in
1719    functions that have frame pointers.
1720    No definition is equivalent to always zero.
1721
1722    On the ARM, the function epilogue recovers the stack pointer from the
1723    frame.  */
1724 #define EXIT_IGNORE_STACK 1
1725
1726 #define EPILOGUE_USES(REGNO) ((REGNO) == LR_REGNUM)
1727
1728 /* Determine if the epilogue should be output as RTL.
1729    You should override this if you define FUNCTION_EXTRA_EPILOGUE.  */
1730 /* This is disabled for Thumb-2 because it will confuse the
1731    conditional insn counter.  */
1732 #define USE_RETURN_INSN(ISCOND)                         \
1733   (TARGET_ARM ? use_return_insn (ISCOND, NULL) : 0)
1734
1735 /* Definitions for register eliminations.
1736
1737    This is an array of structures.  Each structure initializes one pair
1738    of eliminable registers.  The "from" register number is given first,
1739    followed by "to".  Eliminations of the same "from" register are listed
1740    in order of preference.
1741
1742    We have two registers that can be eliminated on the ARM.  First, the
1743    arg pointer register can often be eliminated in favor of the stack
1744    pointer register.  Secondly, the pseudo frame pointer register can always
1745    be eliminated; it is replaced with either the stack or the real frame
1746    pointer.  Note we have to use {ARM|THUMB}_HARD_FRAME_POINTER_REGNUM
1747    because the definition of HARD_FRAME_POINTER_REGNUM is not a constant.  */
1748
1749 #define ELIMINABLE_REGS                                         \
1750 {{ ARG_POINTER_REGNUM,        STACK_POINTER_REGNUM            },\
1751  { ARG_POINTER_REGNUM,        FRAME_POINTER_REGNUM            },\
1752  { ARG_POINTER_REGNUM,        ARM_HARD_FRAME_POINTER_REGNUM   },\
1753  { ARG_POINTER_REGNUM,        THUMB_HARD_FRAME_POINTER_REGNUM },\
1754  { FRAME_POINTER_REGNUM,      STACK_POINTER_REGNUM            },\
1755  { FRAME_POINTER_REGNUM,      ARM_HARD_FRAME_POINTER_REGNUM   },\
1756  { FRAME_POINTER_REGNUM,      THUMB_HARD_FRAME_POINTER_REGNUM }}
1757
1758 /* Given FROM and TO register numbers, say whether this elimination is
1759    allowed.  Frame pointer elimination is automatically handled.
1760
1761    All eliminations are permissible.  Note that ARG_POINTER_REGNUM and
1762    HARD_FRAME_POINTER_REGNUM are in fact the same thing.  If we need a frame
1763    pointer, we must eliminate FRAME_POINTER_REGNUM into
1764    HARD_FRAME_POINTER_REGNUM and not into STACK_POINTER_REGNUM or
1765    ARG_POINTER_REGNUM.  */
1766 #define CAN_ELIMINATE(FROM, TO)                                         \
1767   (((TO) == FRAME_POINTER_REGNUM && (FROM) == ARG_POINTER_REGNUM) ? 0 : \
1768    ((TO) == STACK_POINTER_REGNUM && frame_pointer_needed) ? 0 :         \
1769    ((TO) == ARM_HARD_FRAME_POINTER_REGNUM && TARGET_THUMB) ? 0 :        \
1770    ((TO) == THUMB_HARD_FRAME_POINTER_REGNUM && TARGET_ARM) ? 0 :        \
1771    1)
1772
1773 /* Define the offset between two registers, one to be eliminated, and the
1774    other its replacement, at the start of a routine.  */
1775 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET)                    \
1776   if (TARGET_ARM)                                                       \
1777     (OFFSET) = arm_compute_initial_elimination_offset (FROM, TO);       \
1778   else                                                                  \
1779     (OFFSET) = thumb_compute_initial_elimination_offset (FROM, TO)
1780
1781 /* Special case handling of the location of arguments passed on the stack.  */
1782 #define DEBUGGER_ARG_OFFSET(value, addr) value ? value : arm_debugger_arg_offset (value, addr)
1783
1784 /* Initialize data used by insn expanders.  This is called from insn_emit,
1785    once for every function before code is generated.  */
1786 #define INIT_EXPANDERS  arm_init_expanders ()
1787
1788 /* Output assembler code for a block containing the constant parts
1789    of a trampoline, leaving space for the variable parts.
1790
1791    On the ARM, (if r8 is the static chain regnum, and remembering that
1792    referencing pc adds an offset of 8) the trampoline looks like:
1793            ldr          r8, [pc, #0]
1794            ldr          pc, [pc]
1795            .word        static chain value
1796            .word        function's address
1797    XXX FIXME: When the trampoline returns, r8 will be clobbered.  */
1798 #define ARM_TRAMPOLINE_TEMPLATE(FILE)                           \
1799 {                                                               \
1800   asm_fprintf (FILE, "\tldr\t%r, [%r, #0]\n",                   \
1801                STATIC_CHAIN_REGNUM, PC_REGNUM);                 \
1802   asm_fprintf (FILE, "\tldr\t%r, [%r, #0]\n",                   \
1803                PC_REGNUM, PC_REGNUM);                           \
1804   assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);        \
1805   assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);        \
1806 }
1807
1808 /* The Thumb-2 trampoline is similar to the arm implementation.
1809    Unlike 16-bit Thumb, we enter the stub in thumb mode.  */
1810 #define THUMB2_TRAMPOLINE_TEMPLATE(FILE)                        \
1811 {                                                               \
1812   asm_fprintf (FILE, "\tldr.w\t%r, [%r, #4]\n",                 \
1813                STATIC_CHAIN_REGNUM, PC_REGNUM);                 \
1814   asm_fprintf (FILE, "\tldr.w\t%r, [%r, #4]\n",                 \
1815                PC_REGNUM, PC_REGNUM);                           \
1816   assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);        \
1817   assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);        \
1818 }
1819
1820 #define THUMB1_TRAMPOLINE_TEMPLATE(FILE)        \
1821 {                                               \
1822   ASM_OUTPUT_ALIGN(FILE, 2);                    \
1823   fprintf (FILE, "\t.code\t16\n");              \
1824   fprintf (FILE, ".Ltrampoline_start:\n");      \
1825   asm_fprintf (FILE, "\tpush\t{r0, r1}\n");     \
1826   asm_fprintf (FILE, "\tldr\tr0, [%r, #8]\n",   \
1827                PC_REGNUM);                      \
1828   asm_fprintf (FILE, "\tmov\t%r, r0\n",         \
1829                STATIC_CHAIN_REGNUM);            \
1830   asm_fprintf (FILE, "\tldr\tr0, [%r, #8]\n",   \
1831                PC_REGNUM);                      \
1832   asm_fprintf (FILE, "\tstr\tr0, [%r, #4]\n",   \
1833                SP_REGNUM);                      \
1834   asm_fprintf (FILE, "\tpop\t{r0, %r}\n",       \
1835                PC_REGNUM);                      \
1836   assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);        \
1837   assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);        \
1838 }
1839
1840 #define TRAMPOLINE_TEMPLATE(FILE)               \
1841   if (TARGET_ARM)                               \
1842     ARM_TRAMPOLINE_TEMPLATE (FILE)              \
1843   else if (TARGET_THUMB2)                       \
1844     THUMB2_TRAMPOLINE_TEMPLATE (FILE)           \
1845   else                                          \
1846     THUMB1_TRAMPOLINE_TEMPLATE (FILE)
1847
1848 /* Thumb trampolines should be entered in thumb mode, so set the bottom bit
1849    of the address.  */
1850 #define TRAMPOLINE_ADJUST_ADDRESS(ADDR) do                                  \
1851 {                                                                           \
1852   if (TARGET_THUMB)                                                         \
1853     (ADDR) = expand_simple_binop (Pmode, IOR, (ADDR), GEN_INT(1),           \
1854                                   gen_reg_rtx (Pmode), 0, OPTAB_LIB_WIDEN); \
1855 } while(0)
1856
1857 /* Length in units of the trampoline for entering a nested function.  */
1858 #define TRAMPOLINE_SIZE  (TARGET_32BIT ? 16 : 20)
1859
1860 /* Alignment required for a trampoline in bits.  */
1861 #define TRAMPOLINE_ALIGNMENT  32
1862
1863
1864 /* Emit RTL insns to initialize the variable parts of a trampoline.
1865    FNADDR is an RTX for the address of the function's pure code.
1866    CXT is an RTX for the static chain value for the function.  */
1867 #ifndef INITIALIZE_TRAMPOLINE
1868 #define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)                       \
1869 {                                                                       \
1870   emit_move_insn (gen_rtx_MEM (SImode,                                  \
1871                                plus_constant (TRAMP,                    \
1872                                               TARGET_32BIT ? 8 : 12)),  \
1873                   CXT);                                                 \
1874   emit_move_insn (gen_rtx_MEM (SImode,                                  \
1875                                plus_constant (TRAMP,                    \
1876                                               TARGET_32BIT ? 12 : 16)), \
1877                   FNADDR);                                              \
1878   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),       \
1879                      0, VOIDmode, 2, TRAMP, Pmode,                      \
1880                      plus_constant (TRAMP, TRAMPOLINE_SIZE), Pmode);    \
1881 }
1882 #endif
1883
1884 \f
1885 /* Addressing modes, and classification of registers for them.  */
1886 #define HAVE_POST_INCREMENT   1
1887 #define HAVE_PRE_INCREMENT    TARGET_32BIT
1888 #define HAVE_POST_DECREMENT   TARGET_32BIT
1889 #define HAVE_PRE_DECREMENT    TARGET_32BIT
1890 #define HAVE_PRE_MODIFY_DISP  TARGET_32BIT
1891 #define HAVE_POST_MODIFY_DISP TARGET_32BIT
1892 #define HAVE_PRE_MODIFY_REG   TARGET_32BIT
1893 #define HAVE_POST_MODIFY_REG  TARGET_32BIT
1894
1895 /* Macros to check register numbers against specific register classes.  */
1896
1897 /* These assume that REGNO is a hard or pseudo reg number.
1898    They give nonzero only if REGNO is a hard reg of the suitable class
1899    or a pseudo reg currently allocated to a suitable hard reg.
1900    Since they use reg_renumber, they are safe only once reg_renumber
1901    has been allocated, which happens in local-alloc.c.  */
1902 #define TEST_REGNO(R, TEST, VALUE) \
1903   ((R TEST VALUE) || ((unsigned) reg_renumber[R] TEST VALUE))
1904
1905 /* Don't allow the pc to be used.  */
1906 #define ARM_REGNO_OK_FOR_BASE_P(REGNO)                  \
1907   (TEST_REGNO (REGNO, <, PC_REGNUM)                     \
1908    || TEST_REGNO (REGNO, ==, FRAME_POINTER_REGNUM)      \
1909    || TEST_REGNO (REGNO, ==, ARG_POINTER_REGNUM))
1910
1911 #define THUMB1_REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE)            \
1912   (TEST_REGNO (REGNO, <=, LAST_LO_REGNUM)                       \
1913    || (GET_MODE_SIZE (MODE) >= 4                                \
1914        && TEST_REGNO (REGNO, ==, STACK_POINTER_REGNUM)))
1915
1916 #define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE)           \
1917   (TARGET_THUMB1                                        \
1918    ? THUMB1_REGNO_MODE_OK_FOR_BASE_P (REGNO, MODE)      \
1919    : ARM_REGNO_OK_FOR_BASE_P (REGNO))
1920
1921 /* Nonzero if X can be the base register in a reg+reg addressing mode.
1922    For Thumb, we can not use SP + reg, so reject SP.  */
1923 #define REGNO_MODE_OK_FOR_REG_BASE_P(X, MODE)   \
1924   REGNO_MODE_OK_FOR_BASE_P (X, QImode)
1925
1926 /* For ARM code, we don't care about the mode, but for Thumb, the index
1927    must be suitable for use in a QImode load.  */
1928 #define REGNO_OK_FOR_INDEX_P(REGNO)     \
1929   (REGNO_MODE_OK_FOR_BASE_P (REGNO, QImode) \
1930    && !TEST_REGNO (REGNO, ==, STACK_POINTER_REGNUM))
1931
1932 /* Maximum number of registers that can appear in a valid memory address.
1933    Shifts in addresses can't be by a register.  */
1934 #define MAX_REGS_PER_ADDRESS 2
1935
1936 /* Recognize any constant value that is a valid address.  */
1937 /* XXX We can address any constant, eventually...  */
1938 /* ??? Should the TARGET_ARM here also apply to thumb2?  */
1939 #define CONSTANT_ADDRESS_P(X)                   \
1940   (GET_CODE (X) == SYMBOL_REF                   \
1941    && (CONSTANT_POOL_ADDRESS_P (X)              \
1942        || (TARGET_ARM && optimize > 0 && SYMBOL_REF_FLAG (X))))
1943
1944 /* True if SYMBOL + OFFSET constants must refer to something within
1945    SYMBOL's section.  */
1946 #define ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P 0
1947
1948 /* Nonzero if the constant value X is a legitimate general operand.
1949    It is given that X satisfies CONSTANT_P or is a CONST_DOUBLE.
1950
1951    On the ARM, allow any integer (invalid ones are removed later by insn
1952    patterns), nice doubles and symbol_refs which refer to the function's
1953    constant pool XXX.
1954
1955    When generating pic allow anything.  */
1956 #define ARM_LEGITIMATE_CONSTANT_P(X)    (flag_pic || ! label_mentioned_p (X))
1957
1958 #define THUMB_LEGITIMATE_CONSTANT_P(X)  \
1959  (   GET_CODE (X) == CONST_INT          \
1960   || GET_CODE (X) == CONST_DOUBLE       \
1961   || CONSTANT_ADDRESS_P (X)             \
1962   || flag_pic)
1963
1964 #define LEGITIMATE_CONSTANT_P(X)                        \
1965   (!arm_cannot_force_const_mem (X)                      \
1966    && (TARGET_32BIT ? ARM_LEGITIMATE_CONSTANT_P (X)     \
1967                     : THUMB_LEGITIMATE_CONSTANT_P (X)))
1968
1969 #ifndef SUBTARGET_NAME_ENCODING_LENGTHS
1970 #define SUBTARGET_NAME_ENCODING_LENGTHS
1971 #endif
1972
1973 /* This is a C fragment for the inside of a switch statement.
1974    Each case label should return the number of characters to
1975    be stripped from the start of a function's name, if that
1976    name starts with the indicated character.  */
1977 #define ARM_NAME_ENCODING_LENGTHS               \
1978   case '*':  return 1;                          \
1979   SUBTARGET_NAME_ENCODING_LENGTHS
1980
1981 /* This is how to output a reference to a user-level label named NAME.
1982    `assemble_name' uses this.  */
1983 #undef  ASM_OUTPUT_LABELREF
1984 #define ASM_OUTPUT_LABELREF(FILE, NAME)         \
1985    arm_asm_output_labelref (FILE, NAME)
1986
1987 /* Output IT instructions for conditionally executed Thumb-2 instructions.  */
1988 #define ASM_OUTPUT_OPCODE(STREAM, PTR)  \
1989   if (TARGET_THUMB2)                    \
1990     thumb2_asm_output_opcode (STREAM);
1991
1992 /* The EABI specifies that constructors should go in .init_array.
1993    Other targets use .ctors for compatibility.  */
1994 #ifndef ARM_EABI_CTORS_SECTION_OP
1995 #define ARM_EABI_CTORS_SECTION_OP \
1996   "\t.section\t.init_array,\"aw\",%init_array"
1997 #endif
1998 #ifndef ARM_EABI_DTORS_SECTION_OP
1999 #define ARM_EABI_DTORS_SECTION_OP \
2000   "\t.section\t.fini_array,\"aw\",%fini_array"
2001 #endif
2002 #define ARM_CTORS_SECTION_OP \
2003   "\t.section\t.ctors,\"aw\",%progbits"
2004 #define ARM_DTORS_SECTION_OP \
2005   "\t.section\t.dtors,\"aw\",%progbits"
2006
2007 /* Define CTORS_SECTION_ASM_OP.  */
2008 #undef CTORS_SECTION_ASM_OP
2009 #undef DTORS_SECTION_ASM_OP
2010 #ifndef IN_LIBGCC2
2011 # define CTORS_SECTION_ASM_OP \
2012    (TARGET_AAPCS_BASED ? ARM_EABI_CTORS_SECTION_OP : ARM_CTORS_SECTION_OP)
2013 # define DTORS_SECTION_ASM_OP \
2014    (TARGET_AAPCS_BASED ? ARM_EABI_DTORS_SECTION_OP : ARM_DTORS_SECTION_OP)
2015 #else /* !defined (IN_LIBGCC2) */
2016 /* In libgcc, CTORS_SECTION_ASM_OP must be a compile-time constant,
2017    so we cannot use the definition above.  */
2018 # ifdef __ARM_EABI__
2019 /* The .ctors section is not part of the EABI, so we do not define
2020    CTORS_SECTION_ASM_OP when in libgcc; that prevents crtstuff
2021    from trying to use it.  We do define it when doing normal
2022    compilation, as .init_array can be used instead of .ctors.  */
2023 /* There is no need to emit begin or end markers when using
2024    init_array; the dynamic linker will compute the size of the
2025    array itself based on special symbols created by the static
2026    linker.  However, we do need to arrange to set up
2027    exception-handling here.  */
2028 #   define CTOR_LIST_BEGIN asm (ARM_EABI_CTORS_SECTION_OP)
2029 #   define CTOR_LIST_END /* empty */
2030 #   define DTOR_LIST_BEGIN asm (ARM_EABI_DTORS_SECTION_OP)
2031 #   define DTOR_LIST_END /* empty */
2032 # else /* !defined (__ARM_EABI__) */
2033 #   define CTORS_SECTION_ASM_OP ARM_CTORS_SECTION_OP
2034 #   define DTORS_SECTION_ASM_OP ARM_DTORS_SECTION_OP
2035 # endif /* !defined (__ARM_EABI__) */
2036 #endif /* !defined (IN_LIBCC2) */
2037
2038 /* True if the operating system can merge entities with vague linkage
2039    (e.g., symbols in COMDAT group) during dynamic linking.  */
2040 #ifndef TARGET_ARM_DYNAMIC_VAGUE_LINKAGE_P
2041 #define TARGET_ARM_DYNAMIC_VAGUE_LINKAGE_P true
2042 #endif
2043
2044 #define ARM_OUTPUT_FN_UNWIND(F, PROLOGUE) arm_output_fn_unwind (F, PROLOGUE)
2045
2046 #ifdef TARGET_UNWIND_INFO
2047 #define ARM_EABI_UNWIND_TABLES \
2048   ((!USING_SJLJ_EXCEPTIONS && flag_exceptions) || flag_unwind_tables)
2049 #else
2050 #define ARM_EABI_UNWIND_TABLES 0
2051 #endif
2052
2053 /* The macros REG_OK_FOR..._P assume that the arg is a REG rtx
2054    and check its validity for a certain class.
2055    We have two alternate definitions for each of them.
2056    The usual definition accepts all pseudo regs; the other rejects
2057    them unless they have been allocated suitable hard regs.
2058    The symbol REG_OK_STRICT causes the latter definition to be used.
2059    Thumb-2 has the same restrictions as arm.  */
2060 #ifndef REG_OK_STRICT
2061
2062 #define ARM_REG_OK_FOR_BASE_P(X)                \
2063   (REGNO (X) <= LAST_ARM_REGNUM                 \
2064    || REGNO (X) >= FIRST_PSEUDO_REGISTER        \
2065    || REGNO (X) == FRAME_POINTER_REGNUM         \
2066    || REGNO (X) == ARG_POINTER_REGNUM)
2067
2068 #define ARM_REG_OK_FOR_INDEX_P(X)               \
2069   ((REGNO (X) <= LAST_ARM_REGNUM                \
2070     && REGNO (X) != STACK_POINTER_REGNUM)       \
2071    || REGNO (X) >= FIRST_PSEUDO_REGISTER        \
2072    || REGNO (X) == FRAME_POINTER_REGNUM         \
2073    || REGNO (X) == ARG_POINTER_REGNUM)
2074
2075 #define THUMB1_REG_MODE_OK_FOR_BASE_P(X, MODE)  \
2076   (REGNO (X) <= LAST_LO_REGNUM                  \
2077    || REGNO (X) >= FIRST_PSEUDO_REGISTER        \
2078    || (GET_MODE_SIZE (MODE) >= 4                \
2079        && (REGNO (X) == STACK_POINTER_REGNUM    \
2080            || (X) == hard_frame_pointer_rtx     \
2081            || (X) == arg_pointer_rtx)))
2082
2083 #define REG_STRICT_P 0
2084
2085 #else /* REG_OK_STRICT */
2086
2087 #define ARM_REG_OK_FOR_BASE_P(X)                \
2088   ARM_REGNO_OK_FOR_BASE_P (REGNO (X))
2089
2090 #define ARM_REG_OK_FOR_INDEX_P(X)               \
2091   ARM_REGNO_OK_FOR_INDEX_P (REGNO (X))
2092
2093 #define THUMB1_REG_MODE_OK_FOR_BASE_P(X, MODE)  \
2094   THUMB1_REGNO_MODE_OK_FOR_BASE_P (REGNO (X), MODE)
2095
2096 #define REG_STRICT_P 1
2097
2098 #endif /* REG_OK_STRICT */
2099
2100 /* Now define some helpers in terms of the above.  */
2101
2102 #define REG_MODE_OK_FOR_BASE_P(X, MODE)         \
2103   (TARGET_THUMB1                                \
2104    ? THUMB1_REG_MODE_OK_FOR_BASE_P (X, MODE)    \
2105    : ARM_REG_OK_FOR_BASE_P (X))
2106
2107 /* For 16-bit Thumb, a valid index register is anything that can be used in
2108    a byte load instruction.  */
2109 #define THUMB1_REG_OK_FOR_INDEX_P(X) \
2110   THUMB1_REG_MODE_OK_FOR_BASE_P (X, QImode)
2111
2112 /* Nonzero if X is a hard reg that can be used as an index
2113    or if it is a pseudo reg.  On the Thumb, the stack pointer
2114    is not suitable.  */
2115 #define REG_OK_FOR_INDEX_P(X)                   \
2116   (TARGET_THUMB1                                \
2117    ? THUMB1_REG_OK_FOR_INDEX_P (X)              \
2118    : ARM_REG_OK_FOR_INDEX_P (X))
2119
2120 /* Nonzero if X can be the base register in a reg+reg addressing mode.
2121    For Thumb, we can not use SP + reg, so reject SP.  */
2122 #define REG_MODE_OK_FOR_REG_BASE_P(X, MODE)     \
2123   REG_OK_FOR_INDEX_P (X)
2124 \f
2125 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
2126    that is a valid memory address for an instruction.
2127    The MODE argument is the machine mode for the MEM expression
2128    that wants to use this address.  */
2129
2130 #define ARM_BASE_REGISTER_RTX_P(X)  \
2131   (GET_CODE (X) == REG && ARM_REG_OK_FOR_BASE_P (X))
2132
2133 #define ARM_INDEX_REGISTER_RTX_P(X)  \
2134   (GET_CODE (X) == REG && ARM_REG_OK_FOR_INDEX_P (X))
2135
2136 #define ARM_GO_IF_LEGITIMATE_ADDRESS(MODE,X,WIN)                \
2137   {                                                             \
2138     if (arm_legitimate_address_p (MODE, X, SET, REG_STRICT_P))  \
2139       goto WIN;                                                 \
2140   }
2141
2142 #define THUMB2_GO_IF_LEGITIMATE_ADDRESS(MODE,X,WIN)             \
2143   {                                                             \
2144     if (thumb2_legitimate_address_p (MODE, X, REG_STRICT_P))    \
2145       goto WIN;                                                 \
2146   }
2147
2148 #define THUMB1_GO_IF_LEGITIMATE_ADDRESS(MODE,X,WIN)             \
2149   {                                                             \
2150     if (thumb1_legitimate_address_p (MODE, X, REG_STRICT_P))    \
2151       goto WIN;                                                 \
2152   }
2153
2154 #define GO_IF_LEGITIMATE_ADDRESS(MODE, X, WIN)                          \
2155   if (TARGET_ARM)                                                       \
2156     ARM_GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN)                         \
2157   else if (TARGET_THUMB2)                                               \
2158     THUMB2_GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN)                      \
2159   else /* if (TARGET_THUMB1) */                                         \
2160     THUMB1_GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN)
2161
2162 \f
2163 /* Try machine-dependent ways of modifying an illegitimate address
2164    to be legitimate.  If we find one, return the new, valid address.  */
2165 #define ARM_LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN)      \
2166 do {                                                    \
2167   X = arm_legitimize_address (X, OLDX, MODE);           \
2168 } while (0)
2169
2170 /* ??? Implement LEGITIMIZE_ADDRESS for thumb2.  */
2171 #define THUMB2_LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN)   \
2172 do {                                                    \
2173 } while (0)
2174
2175 #define THUMB1_LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN)   \
2176 do {                                                    \
2177   X = thumb_legitimize_address (X, OLDX, MODE);         \
2178 } while (0)
2179
2180 #define LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN)          \
2181 do {                                                    \
2182   if (TARGET_ARM)                                       \
2183     ARM_LEGITIMIZE_ADDRESS (X, OLDX, MODE, WIN);        \
2184   else if (TARGET_THUMB2)                               \
2185     THUMB2_LEGITIMIZE_ADDRESS (X, OLDX, MODE, WIN);     \
2186   else                                                  \
2187     THUMB1_LEGITIMIZE_ADDRESS (X, OLDX, MODE, WIN);     \
2188                                                         \
2189   if (memory_address_p (MODE, X))                       \
2190     goto WIN;                                           \
2191 } while (0)
2192
2193 /* Go to LABEL if ADDR (a legitimate address expression)
2194    has an effect that depends on the machine mode it is used for.  */
2195 #define ARM_GO_IF_MODE_DEPENDENT_ADDRESS(ADDR, LABEL)                   \
2196 {                                                                       \
2197   if (   GET_CODE (ADDR) == PRE_DEC || GET_CODE (ADDR) == POST_DEC      \
2198       || GET_CODE (ADDR) == PRE_INC || GET_CODE (ADDR) == POST_INC)     \
2199     goto LABEL;                                                         \
2200 }
2201
2202 /* Nothing helpful to do for the Thumb */
2203 #define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR, LABEL)       \
2204   if (TARGET_32BIT)                                     \
2205     ARM_GO_IF_MODE_DEPENDENT_ADDRESS (ADDR, LABEL)
2206 \f
2207
2208 /* Specify the machine mode that this machine uses
2209    for the index in the tablejump instruction.  */
2210 #define CASE_VECTOR_MODE Pmode
2211
2212 #define CASE_VECTOR_PC_RELATIVE TARGET_THUMB2
2213
2214 #define CASE_VECTOR_SHORTEN_MODE(min, max, body)                \
2215    ((min < 0 || max >= 0x2000 || !TARGET_THUMB2) ? SImode       \
2216    : (max >= 0x200) ? HImode                                    \
2217    : QImode)
2218
2219 /* signed 'char' is most compatible, but RISC OS wants it unsigned.
2220    unsigned is probably best, but may break some code.  */
2221 #ifndef DEFAULT_SIGNED_CHAR
2222 #define DEFAULT_SIGNED_CHAR  0
2223 #endif
2224
2225 /* Max number of bytes we can move from memory to memory
2226    in one reasonably fast instruction.  */
2227 #define MOVE_MAX 4
2228
2229 #undef  MOVE_RATIO
2230 #define MOVE_RATIO (arm_tune_xscale ? 4 : 2)
2231
2232 /* Define if operations between registers always perform the operation
2233    on the full register even if a narrower mode is specified.  */
2234 #define WORD_REGISTER_OPERATIONS
2235
2236 /* Define if loading in MODE, an integral mode narrower than BITS_PER_WORD
2237    will either zero-extend or sign-extend.  The value of this macro should
2238    be the code that says which one of the two operations is implicitly
2239    done, UNKNOWN if none.  */
2240 #define LOAD_EXTEND_OP(MODE)                                            \
2241   (TARGET_THUMB ? ZERO_EXTEND :                                         \
2242    ((arm_arch4 || (MODE) == QImode) ? ZERO_EXTEND                       \
2243     : ((BYTES_BIG_ENDIAN && (MODE) == HImode) ? SIGN_EXTEND : UNKNOWN)))
2244
2245 /* Nonzero if access to memory by bytes is slow and undesirable.  */
2246 #define SLOW_BYTE_ACCESS 0
2247
2248 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) 1
2249
2250 /* Immediate shift counts are truncated by the output routines (or was it
2251    the assembler?).  Shift counts in a register are truncated by ARM.  Note
2252    that the native compiler puts too large (> 32) immediate shift counts
2253    into a register and shifts by the register, letting the ARM decide what
2254    to do instead of doing that itself.  */
2255 /* This is all wrong.  Defining SHIFT_COUNT_TRUNCATED tells combine that
2256    code like (X << (Y % 32)) for register X, Y is equivalent to (X << Y).
2257    On the arm, Y in a register is used modulo 256 for the shift. Only for
2258    rotates is modulo 32 used.  */
2259 /* #define SHIFT_COUNT_TRUNCATED 1 */
2260
2261 /* All integers have the same format so truncation is easy.  */
2262 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC)  1
2263
2264 /* Calling from registers is a massive pain.  */
2265 #define NO_FUNCTION_CSE 1
2266
2267 /* The machine modes of pointers and functions */
2268 #define Pmode  SImode
2269 #define FUNCTION_MODE  Pmode
2270
2271 #define ARM_FRAME_RTX(X)                                        \
2272   (   (X) == frame_pointer_rtx || (X) == stack_pointer_rtx      \
2273    || (X) == arg_pointer_rtx)
2274
2275 /* Moves to and from memory are quite expensive */
2276 #define MEMORY_MOVE_COST(M, CLASS, IN)                  \
2277   (TARGET_32BIT ? 10 :                                  \
2278    ((GET_MODE_SIZE (M) < 4 ? 8 : 2 * GET_MODE_SIZE (M)) \
2279     * (CLASS == LO_REGS ? 1 : 2)))
2280
2281 /* Try to generate sequences that don't involve branches, we can then use
2282    conditional instructions */
2283 #define BRANCH_COST \
2284   (TARGET_32BIT ? 4 : (optimize > 0 ? 2 : 0))
2285 \f
2286 /* Position Independent Code.  */
2287 /* We decide which register to use based on the compilation options and
2288    the assembler in use; this is more general than the APCS restriction of
2289    using sb (r9) all the time.  */
2290 extern unsigned arm_pic_register;
2291
2292 /* The register number of the register used to address a table of static
2293    data addresses in memory.  */
2294 #define PIC_OFFSET_TABLE_REGNUM arm_pic_register
2295
2296 /* We can't directly access anything that contains a symbol,
2297    nor can we indirect via the constant pool.  One exception is
2298    UNSPEC_TLS, which is always PIC.  */
2299 #define LEGITIMATE_PIC_OPERAND_P(X)                                     \
2300         (!(symbol_mentioned_p (X)                                       \
2301            || label_mentioned_p (X)                                     \
2302            || (GET_CODE (X) == SYMBOL_REF                               \
2303                && CONSTANT_POOL_ADDRESS_P (X)                           \
2304                && (symbol_mentioned_p (get_pool_constant (X))           \
2305                    || label_mentioned_p (get_pool_constant (X)))))      \
2306          || tls_mentioned_p (X))
2307
2308 /* We need to know when we are making a constant pool; this determines
2309    whether data needs to be in the GOT or can be referenced via a GOT
2310    offset.  */
2311 extern int making_const_table;
2312 \f
2313 /* Handle pragmas for compatibility with Intel's compilers.  */
2314 /* Also abuse this to register additional C specific EABI attributes.  */
2315 #define REGISTER_TARGET_PRAGMAS() do {                                  \
2316   c_register_pragma (0, "long_calls", arm_pr_long_calls);               \
2317   c_register_pragma (0, "no_long_calls", arm_pr_no_long_calls);         \
2318   c_register_pragma (0, "long_calls_off", arm_pr_long_calls_off);       \
2319   arm_lang_object_attributes_init(); \
2320 } while (0)
2321
2322 /* Condition code information.  */
2323 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2324    return the mode to be used for the comparison.  */
2325
2326 #define SELECT_CC_MODE(OP, X, Y)  arm_select_cc_mode (OP, X, Y)
2327
2328 #define REVERSIBLE_CC_MODE(MODE) 1
2329
2330 #define REVERSE_CONDITION(CODE,MODE) \
2331   (((MODE) == CCFPmode || (MODE) == CCFPEmode) \
2332    ? reverse_condition_maybe_unordered (code) \
2333    : reverse_condition (code))
2334
2335 #define CANONICALIZE_COMPARISON(CODE, OP0, OP1)                         \
2336   do                                                                    \
2337     {                                                                   \
2338       if (GET_CODE (OP1) == CONST_INT                                   \
2339           && ! (const_ok_for_arm (INTVAL (OP1))                         \
2340                 || (const_ok_for_arm (- INTVAL (OP1)))))                \
2341         {                                                               \
2342           rtx const_op = OP1;                                           \
2343           CODE = arm_canonicalize_comparison ((CODE), GET_MODE (OP0),   \
2344                                               &const_op);               \
2345           OP1 = const_op;                                               \
2346         }                                                               \
2347     }                                                                   \
2348   while (0)
2349
2350 /* The arm5 clz instruction returns 32.  */
2351 #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE)  ((VALUE) = 32, 1)
2352 \f
2353 #undef  ASM_APP_OFF
2354 #define ASM_APP_OFF (TARGET_THUMB1 ? "\t.code\t16\n" : \
2355                      TARGET_THUMB2 ? "\t.thumb\n" : "")
2356
2357 /* Output a push or a pop instruction (only used when profiling).  */
2358 #define ASM_OUTPUT_REG_PUSH(STREAM, REGNO)              \
2359   do                                                    \
2360     {                                                   \
2361       if (TARGET_ARM)                                   \
2362         asm_fprintf (STREAM,"\tstmfd\t%r!,{%r}\n",      \
2363                      STACK_POINTER_REGNUM, REGNO);      \
2364       else                                              \
2365         asm_fprintf (STREAM, "\tpush {%r}\n", REGNO);   \
2366     } while (0)
2367
2368
2369 #define ASM_OUTPUT_REG_POP(STREAM, REGNO)               \
2370   do                                                    \
2371     {                                                   \
2372       if (TARGET_ARM)                                   \
2373         asm_fprintf (STREAM, "\tldmfd\t%r!,{%r}\n",     \
2374                      STACK_POINTER_REGNUM, REGNO);      \
2375       else                                              \
2376         asm_fprintf (STREAM, "\tpop {%r}\n", REGNO);    \
2377     } while (0)
2378
2379 /* Jump table alignment is explicit in ASM_OUTPUT_CASE_LABEL.  */
2380 #define ADDR_VEC_ALIGN(JUMPTABLE) 0
2381
2382 /* This is how to output a label which precedes a jumptable.  Since
2383    Thumb instructions are 2 bytes, we may need explicit alignment here.  */
2384 #undef  ASM_OUTPUT_CASE_LABEL
2385 #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE)             \
2386   do                                                                    \
2387     {                                                                   \
2388       if (TARGET_THUMB && GET_MODE (PATTERN (JUMPTABLE)) == SImode)     \
2389         ASM_OUTPUT_ALIGN (FILE, 2);                                     \
2390       (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM);            \
2391     }                                                                   \
2392   while (0)
2393
2394 /* Make sure subsequent insns are aligned after a TBB.  */
2395 #define ASM_OUTPUT_CASE_END(FILE, NUM, JUMPTABLE)       \
2396   do                                                    \
2397     {                                                   \
2398       if (GET_MODE (PATTERN (JUMPTABLE)) == QImode)     \
2399         ASM_OUTPUT_ALIGN (FILE, 1);                     \
2400     }                                                   \
2401   while (0)
2402
2403 #define ARM_DECLARE_FUNCTION_NAME(STREAM, NAME, DECL)   \
2404   do                                                    \
2405     {                                                   \
2406       if (TARGET_THUMB)                                 \
2407         {                                               \
2408           if (is_called_in_ARM_mode (DECL)              \
2409               || (TARGET_THUMB1 && !TARGET_THUMB1_ONLY  \
2410                   && crtl->is_thunk))   \
2411             fprintf (STREAM, "\t.code 32\n") ;          \
2412           else if (TARGET_THUMB1)                       \
2413            fprintf (STREAM, "\t.code\t16\n\t.thumb_func\n") ;   \
2414           else                                          \
2415            fprintf (STREAM, "\t.thumb\n\t.thumb_func\n") ;      \
2416         }                                               \
2417       if (TARGET_POKE_FUNCTION_NAME)                    \
2418         arm_poke_function_name (STREAM, (const char *) NAME);   \
2419     }                                                   \
2420   while (0)
2421
2422 /* For aliases of functions we use .thumb_set instead.  */
2423 #define ASM_OUTPUT_DEF_FROM_DECLS(FILE, DECL1, DECL2)           \
2424   do                                                            \
2425     {                                                           \
2426       const char *const LABEL1 = XSTR (XEXP (DECL_RTL (decl), 0), 0); \
2427       const char *const LABEL2 = IDENTIFIER_POINTER (DECL2);    \
2428                                                                 \
2429       if (TARGET_THUMB && TREE_CODE (DECL1) == FUNCTION_DECL)   \
2430         {                                                       \
2431           fprintf (FILE, "\t.thumb_set ");                      \
2432           assemble_name (FILE, LABEL1);                         \
2433           fprintf (FILE, ",");                                  \
2434           assemble_name (FILE, LABEL2);                         \
2435           fprintf (FILE, "\n");                                 \
2436         }                                                       \
2437       else                                                      \
2438         ASM_OUTPUT_DEF (FILE, LABEL1, LABEL2);                  \
2439     }                                                           \
2440   while (0)
2441
2442 #ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
2443 /* To support -falign-* switches we need to use .p2align so
2444    that alignment directives in code sections will be padded
2445    with no-op instructions, rather than zeroes.  */
2446 #define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE, LOG, MAX_SKIP)          \
2447   if ((LOG) != 0)                                               \
2448     {                                                           \
2449       if ((MAX_SKIP) == 0)                                      \
2450         fprintf ((FILE), "\t.p2align %d\n", (int) (LOG));       \
2451       else                                                      \
2452         fprintf ((FILE), "\t.p2align %d,,%d\n",                 \
2453                  (int) (LOG), (int) (MAX_SKIP));                \
2454     }
2455 #endif
2456 \f
2457 /* Add two bytes to the length of conditionally executed Thumb-2
2458    instructions for the IT instruction.  */
2459 #define ADJUST_INSN_LENGTH(insn, length) \
2460   if (TARGET_THUMB2 && GET_CODE (PATTERN (insn)) == COND_EXEC) \
2461     length += 2;
2462
2463 /* Only perform branch elimination (by making instructions conditional) if
2464    we're optimizing.  For Thumb-2 check if any IT instructions need
2465    outputting.  */
2466 #define FINAL_PRESCAN_INSN(INSN, OPVEC, NOPERANDS)      \
2467   if (TARGET_ARM && optimize)                           \
2468     arm_final_prescan_insn (INSN);                      \
2469   else if (TARGET_THUMB2)                               \
2470     thumb2_final_prescan_insn (INSN);                   \
2471   else if (TARGET_THUMB1)                               \
2472     thumb1_final_prescan_insn (INSN)
2473
2474 #define PRINT_OPERAND_PUNCT_VALID_P(CODE)       \
2475   (CODE == '@' || CODE == '|' || CODE == '.'    \
2476    || CODE == '(' || CODE == ')' || CODE == '#' \
2477    || (TARGET_32BIT && (CODE == '?'))           \
2478    || (TARGET_THUMB2 && (CODE == '!'))          \
2479    || (TARGET_THUMB && (CODE == '_')))
2480
2481 /* Output an operand of an instruction.  */
2482 #define PRINT_OPERAND(STREAM, X, CODE)  \
2483   arm_print_operand (STREAM, X, CODE)
2484
2485 #define ARM_SIGN_EXTEND(x)  ((HOST_WIDE_INT)                    \
2486   (HOST_BITS_PER_WIDE_INT <= 32 ? (unsigned HOST_WIDE_INT) (x)  \
2487    : ((((unsigned HOST_WIDE_INT)(x)) & (unsigned HOST_WIDE_INT) 0xffffffff) |\
2488       ((((unsigned HOST_WIDE_INT)(x)) & (unsigned HOST_WIDE_INT) 0x80000000) \
2489        ? ((~ (unsigned HOST_WIDE_INT) 0)                        \
2490           & ~ (unsigned HOST_WIDE_INT) 0xffffffff)              \
2491        : 0))))
2492
2493 /* Output the address of an operand.  */
2494 #define ARM_PRINT_OPERAND_ADDRESS(STREAM, X)                            \
2495 {                                                                       \
2496     int is_minus = GET_CODE (X) == MINUS;                               \
2497                                                                         \
2498     if (GET_CODE (X) == REG)                                            \
2499       asm_fprintf (STREAM, "[%r, #0]", REGNO (X));                      \
2500     else if (GET_CODE (X) == PLUS || is_minus)                          \
2501       {                                                                 \
2502         rtx base = XEXP (X, 0);                                         \
2503         rtx index = XEXP (X, 1);                                        \
2504         HOST_WIDE_INT offset = 0;                                       \
2505         if (GET_CODE (base) != REG                                      \
2506             || (GET_CODE (index) == REG && REGNO (index) == SP_REGNUM)) \
2507           {                                                             \
2508             /* Ensure that BASE is a register.  */                      \
2509             /* (one of them must be).  */                               \
2510             /* Also ensure the SP is not used as in index register.  */ \
2511             rtx temp = base;                                            \
2512             base = index;                                               \
2513             index = temp;                                               \
2514           }                                                             \
2515         switch (GET_CODE (index))                                       \
2516           {                                                             \
2517           case CONST_INT:                                               \
2518             offset = INTVAL (index);                                    \
2519             if (is_minus)                                               \
2520               offset = -offset;                                         \
2521             asm_fprintf (STREAM, "[%r, #%wd]",                          \
2522                          REGNO (base), offset);                         \
2523             break;                                                      \
2524                                                                         \
2525           case REG:                                                     \
2526             asm_fprintf (STREAM, "[%r, %s%r]",                          \
2527                      REGNO (base), is_minus ? "-" : "",                 \
2528                      REGNO (index));                                    \
2529             break;                                                      \
2530                                                                         \
2531           case MULT:                                                    \
2532           case ASHIFTRT:                                                \
2533           case LSHIFTRT:                                                \
2534           case ASHIFT:                                                  \
2535           case ROTATERT:                                                \
2536           {                                                             \
2537             asm_fprintf (STREAM, "[%r, %s%r",                           \
2538                          REGNO (base), is_minus ? "-" : "",             \
2539                          REGNO (XEXP (index, 0)));                      \
2540             arm_print_operand (STREAM, index, 'S');                     \
2541             fputs ("]", STREAM);                                        \
2542             break;                                                      \
2543           }                                                             \
2544                                                                         \
2545           default:                                                      \
2546             gcc_unreachable ();                                         \
2547         }                                                               \
2548     }                                                                   \
2549   else if (GET_CODE (X) == PRE_INC || GET_CODE (X) == POST_INC          \
2550            || GET_CODE (X) == PRE_DEC || GET_CODE (X) == POST_DEC)      \
2551     {                                                                   \
2552       extern enum machine_mode output_memory_reference_mode;            \
2553                                                                         \
2554       gcc_assert (GET_CODE (XEXP (X, 0)) == REG);                       \
2555                                                                         \
2556       if (GET_CODE (X) == PRE_DEC || GET_CODE (X) == PRE_INC)           \
2557         asm_fprintf (STREAM, "[%r, #%s%d]!",                            \
2558                      REGNO (XEXP (X, 0)),                               \
2559                      GET_CODE (X) == PRE_DEC ? "-" : "",                \
2560                      GET_MODE_SIZE (output_memory_reference_mode));     \
2561       else                                                              \
2562         asm_fprintf (STREAM, "[%r], #%s%d",                             \
2563                      REGNO (XEXP (X, 0)),                               \
2564                      GET_CODE (X) == POST_DEC ? "-" : "",               \
2565                      GET_MODE_SIZE (output_memory_reference_mode));     \
2566     }                                                                   \
2567   else if (GET_CODE (X) == PRE_MODIFY)                                  \
2568     {                                                                   \
2569       asm_fprintf (STREAM, "[%r, ", REGNO (XEXP (X, 0)));               \
2570       if (GET_CODE (XEXP (XEXP (X, 1), 1)) == CONST_INT)                \
2571         asm_fprintf (STREAM, "#%wd]!",                                  \
2572                      INTVAL (XEXP (XEXP (X, 1), 1)));                   \
2573       else                                                              \
2574         asm_fprintf (STREAM, "%r]!",                                    \
2575                      REGNO (XEXP (XEXP (X, 1), 1)));                    \
2576     }                                                                   \
2577   else if (GET_CODE (X) == POST_MODIFY)                                 \
2578     {                                                                   \
2579       asm_fprintf (STREAM, "[%r], ", REGNO (XEXP (X, 0)));              \
2580       if (GET_CODE (XEXP (XEXP (X, 1), 1)) == CONST_INT)                \
2581         asm_fprintf (STREAM, "#%wd",                                    \
2582                      INTVAL (XEXP (XEXP (X, 1), 1)));                   \
2583       else                                                              \
2584         asm_fprintf (STREAM, "%r",                                      \
2585                      REGNO (XEXP (XEXP (X, 1), 1)));                    \
2586     }                                                                   \
2587   else output_addr_const (STREAM, X);                                   \
2588 }
2589
2590 #define THUMB_PRINT_OPERAND_ADDRESS(STREAM, X)          \
2591 {                                                       \
2592   if (GET_CODE (X) == REG)                              \
2593     asm_fprintf (STREAM, "[%r]", REGNO (X));            \
2594   else if (GET_CODE (X) == POST_INC)                    \
2595     asm_fprintf (STREAM, "%r!", REGNO (XEXP (X, 0)));   \
2596   else if (GET_CODE (X) == PLUS)                        \
2597     {                                                   \
2598       gcc_assert (GET_CODE (XEXP (X, 0)) == REG);       \
2599       if (GET_CODE (XEXP (X, 1)) == CONST_INT)          \
2600         asm_fprintf (STREAM, "[%r, #%wd]",              \
2601                      REGNO (XEXP (X, 0)),               \
2602                      INTVAL (XEXP (X, 1)));             \
2603       else                                              \
2604         asm_fprintf (STREAM, "[%r, %r]",                \
2605                      REGNO (XEXP (X, 0)),               \
2606                      REGNO (XEXP (X, 1)));              \
2607     }                                                   \
2608   else                                                  \
2609     output_addr_const (STREAM, X);                      \
2610 }
2611
2612 #define PRINT_OPERAND_ADDRESS(STREAM, X)        \
2613   if (TARGET_32BIT)                             \
2614     ARM_PRINT_OPERAND_ADDRESS (STREAM, X)       \
2615   else                                          \
2616     THUMB_PRINT_OPERAND_ADDRESS (STREAM, X)
2617
2618 #define OUTPUT_ADDR_CONST_EXTRA(file, x, fail)          \
2619   if (arm_output_addr_const_extra (file, x) == FALSE)   \
2620     goto fail
2621
2622 /* A C expression whose value is RTL representing the value of the return
2623    address for the frame COUNT steps up from the current frame.  */
2624
2625 #define RETURN_ADDR_RTX(COUNT, FRAME) \
2626   arm_return_addr (COUNT, FRAME)
2627
2628 /* Mask of the bits in the PC that contain the real return address
2629    when running in 26-bit mode.  */
2630 #define RETURN_ADDR_MASK26 (0x03fffffc)
2631
2632 /* Pick up the return address upon entry to a procedure. Used for
2633    dwarf2 unwind information.  This also enables the table driven
2634    mechanism.  */
2635 #define INCOMING_RETURN_ADDR_RTX        gen_rtx_REG (Pmode, LR_REGNUM)
2636 #define DWARF_FRAME_RETURN_COLUMN       DWARF_FRAME_REGNUM (LR_REGNUM)
2637
2638 /* Used to mask out junk bits from the return address, such as
2639    processor state, interrupt status, condition codes and the like.  */
2640 #define MASK_RETURN_ADDR \
2641   /* If we are generating code for an ARM2/ARM3 machine or for an ARM6  \
2642      in 26 bit mode, the condition codes must be masked out of the      \
2643      return address.  This does not apply to ARM6 and later processors  \
2644      when running in 32 bit mode.  */                                   \
2645   ((arm_arch4 || TARGET_THUMB)                                          \
2646    ? (gen_int_mode ((unsigned long)0xffffffff, Pmode))                  \
2647    : arm_gen_return_addr_mask ())
2648
2649 \f
2650 /* Neon defines builtins from ARM_BUILTIN_MAX upwards, though they don't have
2651    symbolic names defined here (which would require too much duplication).
2652    FIXME?  */
2653 enum arm_builtins
2654 {
2655   ARM_BUILTIN_GETWCX,
2656   ARM_BUILTIN_SETWCX,
2657
2658   ARM_BUILTIN_WZERO,
2659
2660   ARM_BUILTIN_WAVG2BR,
2661   ARM_BUILTIN_WAVG2HR,
2662   ARM_BUILTIN_WAVG2B,
2663   ARM_BUILTIN_WAVG2H,
2664
2665   ARM_BUILTIN_WACCB,
2666   ARM_BUILTIN_WACCH,
2667   ARM_BUILTIN_WACCW,
2668
2669   ARM_BUILTIN_WMACS,
2670   ARM_BUILTIN_WMACSZ,
2671   ARM_BUILTIN_WMACU,
2672   ARM_BUILTIN_WMACUZ,
2673
2674   ARM_BUILTIN_WSADB,
2675   ARM_BUILTIN_WSADBZ,
2676   ARM_BUILTIN_WSADH,
2677   ARM_BUILTIN_WSADHZ,
2678
2679   ARM_BUILTIN_WALIGN,
2680
2681   ARM_BUILTIN_TMIA,
2682   ARM_BUILTIN_TMIAPH,
2683   ARM_BUILTIN_TMIABB,
2684   ARM_BUILTIN_TMIABT,
2685   ARM_BUILTIN_TMIATB,
2686   ARM_BUILTIN_TMIATT,
2687
2688   ARM_BUILTIN_TMOVMSKB,
2689   ARM_BUILTIN_TMOVMSKH,
2690   ARM_BUILTIN_TMOVMSKW,
2691
2692   ARM_BUILTIN_TBCSTB,
2693   ARM_BUILTIN_TBCSTH,
2694   ARM_BUILTIN_TBCSTW,
2695
2696   ARM_BUILTIN_WMADDS,
2697   ARM_BUILTIN_WMADDU,
2698
2699   ARM_BUILTIN_WPACKHSS,
2700   ARM_BUILTIN_WPACKWSS,
2701   ARM_BUILTIN_WPACKDSS,
2702   ARM_BUILTIN_WPACKHUS,
2703   ARM_BUILTIN_WPACKWUS,
2704   ARM_BUILTIN_WPACKDUS,
2705
2706   ARM_BUILTIN_WADDB,
2707   ARM_BUILTIN_WADDH,
2708   ARM_BUILTIN_WADDW,
2709   ARM_BUILTIN_WADDSSB,
2710   ARM_BUILTIN_WADDSSH,
2711   ARM_BUILTIN_WADDSSW,
2712   ARM_BUILTIN_WADDUSB,
2713   ARM_BUILTIN_WADDUSH,
2714   ARM_BUILTIN_WADDUSW,
2715   ARM_BUILTIN_WSUBB,
2716   ARM_BUILTIN_WSUBH,
2717   ARM_BUILTIN_WSUBW,
2718   ARM_BUILTIN_WSUBSSB,
2719   ARM_BUILTIN_WSUBSSH,
2720   ARM_BUILTIN_WSUBSSW,
2721   ARM_BUILTIN_WSUBUSB,
2722   ARM_BUILTIN_WSUBUSH,
2723   ARM_BUILTIN_WSUBUSW,
2724
2725   ARM_BUILTIN_WAND,
2726   ARM_BUILTIN_WANDN,
2727   ARM_BUILTIN_WOR,
2728   ARM_BUILTIN_WXOR,
2729
2730   ARM_BUILTIN_WCMPEQB,
2731   ARM_BUILTIN_WCMPEQH,
2732   ARM_BUILTIN_WCMPEQW,
2733   ARM_BUILTIN_WCMPGTUB,
2734   ARM_BUILTIN_WCMPGTUH,
2735   ARM_BUILTIN_WCMPGTUW,
2736   ARM_BUILTIN_WCMPGTSB,
2737   ARM_BUILTIN_WCMPGTSH,
2738   ARM_BUILTIN_WCMPGTSW,
2739
2740   ARM_BUILTIN_TEXTRMSB,
2741   ARM_BUILTIN_TEXTRMSH,
2742   ARM_BUILTIN_TEXTRMSW,
2743   ARM_BUILTIN_TEXTRMUB,
2744   ARM_BUILTIN_TEXTRMUH,
2745   ARM_BUILTIN_TEXTRMUW,
2746   ARM_BUILTIN_TINSRB,
2747   ARM_BUILTIN_TINSRH,
2748   ARM_BUILTIN_TINSRW,
2749
2750   ARM_BUILTIN_WMAXSW,
2751   ARM_BUILTIN_WMAXSH,
2752   ARM_BUILTIN_WMAXSB,
2753   ARM_BUILTIN_WMAXUW,
2754   ARM_BUILTIN_WMAXUH,
2755   ARM_BUILTIN_WMAXUB,
2756   ARM_BUILTIN_WMINSW,
2757   ARM_BUILTIN_WMINSH,
2758   ARM_BUILTIN_WMINSB,
2759   ARM_BUILTIN_WMINUW,
2760   ARM_BUILTIN_WMINUH,
2761   ARM_BUILTIN_WMINUB,
2762
2763   ARM_BUILTIN_WMULUM,
2764   ARM_BUILTIN_WMULSM,
2765   ARM_BUILTIN_WMULUL,
2766
2767   ARM_BUILTIN_PSADBH,
2768   ARM_BUILTIN_WSHUFH,
2769
2770   ARM_BUILTIN_WSLLH,
2771   ARM_BUILTIN_WSLLW,
2772   ARM_BUILTIN_WSLLD,
2773   ARM_BUILTIN_WSRAH,
2774   ARM_BUILTIN_WSRAW,
2775   ARM_BUILTIN_WSRAD,
2776   ARM_BUILTIN_WSRLH,
2777   ARM_BUILTIN_WSRLW,
2778   ARM_BUILTIN_WSRLD,
2779   ARM_BUILTIN_WRORH,
2780   ARM_BUILTIN_WRORW,
2781   ARM_BUILTIN_WRORD,
2782   ARM_BUILTIN_WSLLHI,
2783   ARM_BUILTIN_WSLLWI,
2784   ARM_BUILTIN_WSLLDI,
2785   ARM_BUILTIN_WSRAHI,
2786   ARM_BUILTIN_WSRAWI,
2787   ARM_BUILTIN_WSRADI,
2788   ARM_BUILTIN_WSRLHI,
2789   ARM_BUILTIN_WSRLWI,
2790   ARM_BUILTIN_WSRLDI,
2791   ARM_BUILTIN_WRORHI,
2792   ARM_BUILTIN_WRORWI,
2793   ARM_BUILTIN_WRORDI,
2794
2795   ARM_BUILTIN_WUNPCKIHB,
2796   ARM_BUILTIN_WUNPCKIHH,
2797   ARM_BUILTIN_WUNPCKIHW,
2798   ARM_BUILTIN_WUNPCKILB,
2799   ARM_BUILTIN_WUNPCKILH,
2800   ARM_BUILTIN_WUNPCKILW,
2801
2802   ARM_BUILTIN_WUNPCKEHSB,
2803   ARM_BUILTIN_WUNPCKEHSH,
2804   ARM_BUILTIN_WUNPCKEHSW,
2805   ARM_BUILTIN_WUNPCKEHUB,
2806   ARM_BUILTIN_WUNPCKEHUH,
2807   ARM_BUILTIN_WUNPCKEHUW,
2808   ARM_BUILTIN_WUNPCKELSB,
2809   ARM_BUILTIN_WUNPCKELSH,
2810   ARM_BUILTIN_WUNPCKELSW,
2811   ARM_BUILTIN_WUNPCKELUB,
2812   ARM_BUILTIN_WUNPCKELUH,
2813   ARM_BUILTIN_WUNPCKELUW,
2814
2815   ARM_BUILTIN_THREAD_POINTER,
2816
2817   ARM_BUILTIN_NEON_BASE,
2818
2819   ARM_BUILTIN_MAX = ARM_BUILTIN_NEON_BASE  /* FIXME: Wrong!  */
2820 };
2821
2822 /* Do not emit .note.GNU-stack by default.  */
2823 #ifndef NEED_INDICATE_EXEC_STACK
2824 #define NEED_INDICATE_EXEC_STACK        0
2825 #endif
2826
2827 #endif /* ! GCC_ARM_H */