1 /* Output routines for GCC for ARM.
2 Copyright (C) 1991, 93, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
3 Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
4 and Martin Simmons (@harleqn.co.uk).
5 More major hacks by Richard Earnshaw (rearnsha@arm.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-flags.h"
34 #include "insn-attr.h"
42 /* The maximum number of insns skipped which will be conditionalised if
44 static int max_insns_skipped = 5;
46 extern FILE * asm_out_file;
47 /* Some function declarations. */
49 static HOST_WIDE_INT int_log2 PROTO ((HOST_WIDE_INT));
50 static char * output_multi_immediate PROTO ((rtx *, char *, char *, int,
52 static int arm_gen_constant PROTO ((enum rtx_code, enum machine_mode,
53 HOST_WIDE_INT, rtx, rtx, int, int));
54 static int arm_naked_function_p PROTO ((tree));
55 static void init_fpa_table PROTO ((void));
56 static enum machine_mode select_dominance_cc_mode PROTO ((rtx, rtx,
58 static HOST_WIDE_INT add_constant PROTO ((rtx, enum machine_mode, int *));
59 static void dump_table PROTO ((rtx));
60 static int fixit PROTO ((rtx, enum machine_mode, int));
61 static rtx find_barrier PROTO ((rtx, int));
62 static int broken_move PROTO ((rtx));
63 static char * fp_const_from_val PROTO ((REAL_VALUE_TYPE *));
64 static int eliminate_lr2ip PROTO ((rtx *));
65 static char * shift_op PROTO ((rtx, HOST_WIDE_INT *));
66 static int pattern_really_clobbers_lr PROTO ((rtx));
67 static int function_really_clobbers_lr PROTO ((rtx));
68 static void emit_multi_reg_push PROTO ((int));
69 static void emit_sfm PROTO ((int, int));
70 static enum arm_cond_code get_arm_condition_code PROTO ((rtx));
71 static int const_ok_for_op RTX_CODE_PROTO ((Hint, Rcode));
73 /* Define the information needed to generate branch insns. This is
74 stored from the compare operation. */
75 rtx arm_compare_op0, arm_compare_op1;
77 /* What type of floating point are we tuning for? */
78 enum floating_point_type arm_fpu;
80 /* What type of floating point instructions are available? */
81 enum floating_point_type arm_fpu_arch;
83 /* What program mode is the cpu running in? 26-bit mode or 32-bit mode */
84 enum prog_mode_type arm_prgmode;
86 /* Set by the -mfp=... option */
87 char * target_fp_name = NULL;
89 /* Used to parse -mstructure_size_boundary command line option. */
90 char * structure_size_string = NULL;
91 int arm_structure_size_boundary = 32; /* Used to be 8 */
93 /* Bit values used to identify processor capabilities. */
94 #define FL_CO_PROC 0x01 /* Has external co-processor bus */
95 #define FL_FAST_MULT 0x02 /* Fast multiply */
96 #define FL_MODE26 0x04 /* 26-bit mode support */
97 #define FL_MODE32 0x08 /* 32-bit mode support */
98 #define FL_ARCH4 0x10 /* Architecture rel 4 */
99 #define FL_THUMB 0x20 /* Thumb aware */
100 #define FL_LDSCHED 0x40 /* Load scheduling necessary */
101 #define FL_STRONG 0x80 /* StrongARM */
103 /* The bits in this mask specify which instructions we are allowed to generate. */
104 static int insn_flags = 0;
105 /* The bits in this mask specify which instruction scheduling options should
106 be used. Note - there is an overlap with the FL_FAST_MULT. For some
107 hardware we want to be able to generate the multiply instructions, but to
108 tune as if they were not present in the architecture. */
109 static int tune_flags = 0;
111 /* The following are used in the arm.md file as equivalents to bits
112 in the above two flag variables. */
114 /* Nonzero if this is an "M" variant of the processor. */
115 int arm_fast_multiply = 0;
117 /* Nonzero if this chip supports the ARM Architecture 4 extensions */
120 /* Nonzero if this chip can benefit from load scheduling. */
121 int arm_ld_sched = 0;
123 /* Nonzero if this chip is a StrongARM. */
124 int arm_is_strong = 0;
126 /* Nonzero if this chip is a an ARM6 or an ARM7. */
127 int arm_is_6_or_7 = 0;
129 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
130 must report the mode of the memory reference from PRINT_OPERAND to
131 PRINT_OPERAND_ADDRESS. */
132 enum machine_mode output_memory_reference_mode;
134 /* Nonzero if the prologue must setup `fp'. */
135 int current_function_anonymous_args;
137 /* The register number to be used for the PIC offset register. */
138 int arm_pic_register = 9;
140 /* Location counter of .text segment. */
141 int arm_text_location = 0;
143 /* Set to one if we think that lr is only saved because of subroutine calls,
144 but all of these can be `put after' return insns */
145 int lr_save_eliminated;
147 /* Set to 1 when a return insn is output, this means that the epilogue
149 static int return_used_this_function;
151 /* Set to 1 after arm_reorg has started. Reset to start at the start of
152 the next function. */
153 static int after_arm_reorg = 0;
155 /* The maximum number of insns to be used when loading a constant. */
156 static int arm_constant_limit = 3;
158 /* For an explanation of these variables, see final_prescan_insn below. */
160 enum arm_cond_code arm_current_cc;
162 int arm_target_label;
164 /* The condition codes of the ARM, and the inverse function. */
165 char * arm_condition_codes[] =
167 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
168 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
171 static enum arm_cond_code get_arm_condition_code ();
173 #define streq(string1, string2) (strcmp (string1, string2) == 0)
175 /* Initialization code */
183 /* Not all of these give usefully different compilation alternatives,
184 but there is no simple way of generalizing them. */
185 static struct processors all_cores[] =
189 {"arm2", FL_CO_PROC | FL_MODE26 },
190 {"arm250", FL_CO_PROC | FL_MODE26 },
191 {"arm3", FL_CO_PROC | FL_MODE26 },
192 {"arm6", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
193 {"arm60", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
194 {"arm600", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
195 {"arm610", FL_MODE26 | FL_MODE32 },
196 {"arm620", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
197 {"arm7", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
198 {"arm7m", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT }, /* arm7m doesn't exist on its own, */
199 {"arm7d", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, /* but only with D, (and I), */
200 {"arm7dm", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT }, /* but those don't alter the code, */
201 {"arm7di", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, /* so arm7m is sometimes used. */
202 {"arm7dmi", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT },
203 {"arm70", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
204 {"arm700", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
205 {"arm700i", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
206 {"arm710", FL_MODE26 | FL_MODE32 },
207 {"arm710c", FL_MODE26 | FL_MODE32 },
208 {"arm7100", FL_MODE26 | FL_MODE32 },
209 {"arm7500", FL_MODE26 | FL_MODE32 },
210 {"arm7500fe", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, /* Doesn't really have an external co-proc, but does have embedded fpu. */
211 {"arm7tdmi", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB },
212 {"arm8", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED },
213 {"arm810", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED },
214 {"arm9", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED },
215 {"arm9tdmi", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED },
216 {"strongarm", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG },
217 {"strongarm110", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG },
218 {"strongarm1100", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG },
223 static struct processors all_architectures[] =
225 /* ARM Architectures */
227 {"armv2", FL_CO_PROC | FL_MODE26 },
228 {"armv2a", FL_CO_PROC | FL_MODE26 },
229 {"armv3", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
230 {"armv3m", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT },
231 {"armv4", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 },
232 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
233 implementations that support it, so we will leave it out for now. */
234 {"armv4t", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB },
238 /* This is a magic stucture. The 'string' field is magically filled in
239 with a pointer to the value specified by the user on the command line
240 assuming that the user has specified such a value. */
242 struct arm_cpu_select arm_select[] =
244 /* string name processors */
245 { NULL, "-mcpu=", all_cores },
246 { NULL, "-march=", all_architectures },
247 { NULL, "-mtune=", all_cores }
250 /* Return the number of bits set in value' */
255 unsigned int count = 0;
259 value &= ~(value & - value);
266 /* Fix up any incompatible options that the user has specified.
267 This has now turned into a maze. */
269 arm_override_options ()
273 /* Set up the flags based on the cpu/architecture selected by the user. */
274 for (i = sizeof (arm_select) / sizeof (arm_select[0]); i--;)
276 struct arm_cpu_select * ptr = arm_select + i;
278 if (ptr->string != NULL && ptr->string[0] != '\0')
280 struct processors * sel;
282 for (sel = ptr->processors; sel->name != NULL; sel ++)
283 if (streq (ptr->string, sel->name))
286 tune_flags = sel->flags;
289 /* If we have been given an architecture and a processor
290 make sure that they are compatible. We only generate
291 a warning though, and we prefer the CPU over the
293 if (insn_flags != 0 && (insn_flags ^ sel->flags))
294 warning ("switch -mcpu=%s conflicts with -mtune= switch",
297 insn_flags = sel->flags;
303 if (sel->name == NULL)
304 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
308 /* If the user did not specify a processor, choose one for them. */
311 struct processors * sel;
313 static struct cpu_default
320 { TARGET_CPU_arm2, "arm2" },
321 { TARGET_CPU_arm6, "arm6" },
322 { TARGET_CPU_arm610, "arm610" },
323 { TARGET_CPU_arm710, "arm710" },
324 { TARGET_CPU_arm7m, "arm7m" },
325 { TARGET_CPU_arm7500fe, "arm7500fe" },
326 { TARGET_CPU_arm7tdmi, "arm7tdmi" },
327 { TARGET_CPU_arm8, "arm8" },
328 { TARGET_CPU_arm810, "arm810" },
329 { TARGET_CPU_arm9, "arm9" },
330 { TARGET_CPU_strongarm, "strongarm" },
331 { TARGET_CPU_generic, "arm" },
334 struct cpu_default * def;
336 /* Find the default. */
337 for (def = cpu_defaults; def->name; def ++)
338 if (def->cpu == TARGET_CPU_DEFAULT)
341 /* Make sure we found the default CPU. */
342 if (def->name == NULL)
345 /* Find the default CPU's flags. */
346 for (sel = all_cores; sel->name != NULL; sel ++)
347 if (streq (def->name, sel->name))
350 if (sel->name == NULL)
353 insn_flags = sel->flags;
355 /* Now check to see if the user has specified some command line
356 switch that require certain abilities from the cpu. */
359 if (TARGET_THUMB_INTERWORK)
361 sought |= (FL_THUMB | FL_MODE32);
363 /* Force apcs-32 to be used for interworking. */
364 target_flags |= ARM_FLAG_APCS_32;
366 /* There are no ARM processor that supports both APCS-26 and
367 interworking. Therefore we force FL_MODE26 to be removed
368 from insn_flags here (if it was set), so that the search
369 below will always be able to find a compatible processor. */
370 insn_flags &= ~ FL_MODE26;
373 if (! TARGET_APCS_32)
376 if (sought != 0 && ((sought & insn_flags) != sought))
378 /* Try to locate a CPU type that supports all of the abilities
379 of the default CPU, plus the extra abilities requested by
381 for (sel = all_cores; sel->name != NULL; sel ++)
382 if ((sel->flags & sought) == (sought | insn_flags))
385 if (sel->name == NULL)
387 unsigned int current_bit_count = 0;
388 struct processors * best_fit = NULL;
390 /* Ideally we would like to issue an error message here
391 saying that it was not possible to find a CPU compatible
392 with the default CPU, but which also supports the command
393 line options specified by the programmer, and so they
394 ought to use the -mcpu=<name> command line option to
395 override the default CPU type.
397 Unfortunately this does not work with multilibing. We
398 need to be able to support multilibs for -mapcs-26 and for
399 -mthumb-interwork and there is no CPU that can support both
400 options. Instead if we cannot find a cpu that has both the
401 characteristics of the default cpu and the given command line
402 options we scan the array again looking for a best match. */
403 for (sel = all_cores; sel->name != NULL; sel ++)
404 if ((sel->flags & sought) == sought)
408 count = bit_count (sel->flags & insn_flags);
410 if (count >= current_bit_count)
413 current_bit_count = count;
417 if (best_fit == NULL)
423 insn_flags = sel->flags;
427 /* If tuning has not been specified, tune for whichever processor or
428 architecture has been selected. */
430 tune_flags = insn_flags;
432 /* Make sure that the processor choice does not conflict with any of the
433 other command line choices. */
434 if (TARGET_APCS_32 && !(insn_flags & FL_MODE32))
436 /* If APCS-32 was not the default then it must have been set by the
437 user, so issue a warning message. If the user has specified
438 "-mapcs-32 -mcpu=arm2" then we loose here. */
439 if ((TARGET_DEFAULT & ARM_FLAG_APCS_32) == 0)
440 warning ("target CPU does not support APCS-32" );
441 target_flags &= ~ ARM_FLAG_APCS_32;
443 else if (! TARGET_APCS_32 && !(insn_flags & FL_MODE26))
445 warning ("target CPU does not support APCS-26" );
446 target_flags |= ARM_FLAG_APCS_32;
449 if (TARGET_THUMB_INTERWORK && !(insn_flags & FL_THUMB))
451 warning ("target CPU does not support interworking" );
452 target_flags &= ~ARM_FLAG_THUMB;
455 /* If interworking is enabled then APCS-32 must be selected as well. */
456 if (TARGET_THUMB_INTERWORK)
458 if (! TARGET_APCS_32)
459 warning ("interworking forces APCS-32 to be used" );
460 target_flags |= ARM_FLAG_APCS_32;
463 if (TARGET_APCS_STACK && ! TARGET_APCS)
465 warning ("-mapcs-stack-check incompatible with -mno-apcs-frame");
466 target_flags |= ARM_FLAG_APCS_FRAME;
469 if (write_symbols != NO_DEBUG && flag_omit_frame_pointer)
470 warning ("-g with -fomit-frame-pointer may not give sensible debugging");
472 if (TARGET_POKE_FUNCTION_NAME)
473 target_flags |= ARM_FLAG_APCS_FRAME;
475 if (TARGET_APCS_REENT && flag_pic)
476 fatal ("-fpic and -mapcs-reent are incompatible");
478 if (TARGET_APCS_REENT)
479 warning ("APCS reentrant code not supported. Ignored");
481 /* If stack checking is disabled, we can use r10 as the PIC register,
482 which keeps r9 available. */
483 if (flag_pic && ! TARGET_APCS_STACK)
484 arm_pic_register = 10;
486 /* Well, I'm about to have a go, but pic is NOT going to be compatible
487 with APCS reentrancy, since that requires too much support in the
488 assembler and linker, and the ARMASM assembler seems to lack some
489 required directives. */
491 warning ("Position independent code not supported");
493 if (TARGET_APCS_FLOAT)
494 warning ("Passing floating point arguments in fp regs not yet supported");
496 /* Initialise boolean versions of the flags, for use in the arm.md file. */
497 arm_fast_multiply = insn_flags & FL_FAST_MULT;
498 arm_arch4 = insn_flags & FL_ARCH4;
500 arm_ld_sched = tune_flags & FL_LDSCHED;
501 arm_is_strong = tune_flags & FL_STRONG;
502 arm_is_6_or_7 = ((tune_flags & (FL_MODE26 | FL_MODE32))
503 && !(tune_flags & FL_ARCH4));
505 /* Default value for floating point code... if no co-processor
506 bus, then schedule for emulated floating point. Otherwise,
507 assume the user has an FPA.
508 Note: this does not prevent use of floating point instructions,
509 -msoft-float does that. */
510 arm_fpu = (tune_flags & FL_CO_PROC) ? FP_HARD : FP_SOFT3;
514 if (streq (target_fp_name, "2"))
515 arm_fpu_arch = FP_SOFT2;
516 else if (streq (target_fp_name, "3"))
517 arm_fpu_arch = FP_SOFT3;
519 fatal ("Invalid floating point emulation option: -mfpe-%s",
523 arm_fpu_arch = FP_DEFAULT;
525 if (TARGET_FPE && arm_fpu != FP_HARD)
528 /* For arm2/3 there is no need to do any scheduling if there is only
529 a floating point emulator, or we are doing software floating-point. */
530 if ((TARGET_SOFT_FLOAT || arm_fpu != FP_HARD) && (tune_flags & FL_MODE32) == 0)
531 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
533 arm_prog_mode = TARGET_APCS_32 ? PROG_MODE_PROG32 : PROG_MODE_PROG26;
535 if (structure_size_string != NULL)
537 int size = strtol (structure_size_string, NULL, 0);
539 if (size == 8 || size == 32)
540 arm_structure_size_boundary = size;
542 warning ("Structure size boundary can only be set to 8 or 32");
545 /* If optimizing for space, don't synthesize constants.
546 For processors with load scheduling, it never costs more than 2 cycles
547 to load a constant, and the load scheduler may well reduce that to 1. */
548 if (optimize_size || (tune_flags & FL_LDSCHED))
549 arm_constant_limit = 1;
551 /* If optimizing for size, bump the number of instructions that we
552 are prepared to conditionally execute (even on a StrongARM).
553 Otherwise for the StrongARM, which has early execution of branches,
554 a sequence that is worth skipping is shorter. */
556 max_insns_skipped = 6;
557 else if (arm_is_strong)
558 max_insns_skipped = 3;
561 /* Return 1 if it is possible to return using a single instruction */
564 use_return_insn (iscond)
569 if (!reload_completed
570 || current_function_pretend_args_size
571 || current_function_anonymous_args
572 || ((get_frame_size () + current_function_outgoing_args_size != 0)
573 && !(TARGET_APCS && frame_pointer_needed)))
576 /* Can't be done if interworking with Thumb, and any registers have been
577 stacked. Similarly, on StrongARM, conditional returns are expensive
578 if they aren't taken and registers have been stacked. */
579 if (iscond && arm_is_strong && frame_pointer_needed)
581 if ((iscond && arm_is_strong)
582 || TARGET_THUMB_INTERWORK)
583 for (regno = 0; regno < 16; regno++)
584 if (regs_ever_live[regno] && ! call_used_regs[regno])
587 /* Can't be done if any of the FPU regs are pushed, since this also
589 for (regno = 16; regno < 24; regno++)
590 if (regs_ever_live[regno] && ! call_used_regs[regno])
593 /* If a function is naked, don't use the "return" insn. */
594 if (arm_naked_function_p (current_function_decl))
600 /* Return TRUE if int I is a valid immediate ARM constant. */
606 unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT)0xFF;
608 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
609 be all zero, or all one. */
610 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
611 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
612 != ((~(unsigned HOST_WIDE_INT) 0)
613 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
616 /* Fast return for 0 and powers of 2 */
617 if ((i & (i - 1)) == 0)
622 if ((i & mask & (unsigned HOST_WIDE_INT) 0xffffffff) == 0)
625 (mask << 2) | ((mask & (unsigned HOST_WIDE_INT) 0xffffffff)
626 >> (32 - 2)) | ~((unsigned HOST_WIDE_INT) 0xffffffff);
627 } while (mask != ~(unsigned HOST_WIDE_INT) 0xFF);
632 /* Return true if I is a valid constant for the operation CODE. */
634 const_ok_for_op (i, code)
638 if (const_ok_for_arm (i))
644 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
646 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
652 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
659 /* Emit a sequence of insns to handle a large constant.
660 CODE is the code of the operation required, it can be any of SET, PLUS,
661 IOR, AND, XOR, MINUS;
662 MODE is the mode in which the operation is being performed;
663 VAL is the integer to operate on;
664 SOURCE is the other operand (a register, or a null-pointer for SET);
665 SUBTARGETS means it is safe to create scratch registers if that will
666 either produce a simpler sequence, or we will want to cse the values.
667 Return value is the number of insns emitted. */
670 arm_split_constant (code, mode, val, target, source, subtargets)
672 enum machine_mode mode;
678 if (subtargets || code == SET
679 || (GET_CODE (target) == REG && GET_CODE (source) == REG
680 && REGNO (target) != REGNO (source)))
682 /* After arm_reorg has been called, we can't fix up expensive
683 constants by pushing them into memory so we must synthesise
684 them in-line, regardless of the cost. This is only likely to
685 be more costly on chips that have load delay slots and we are
686 compiling without running the scheduler (so no splitting
687 occurred before the final instruction emission).
689 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
691 if (! after_arm_reorg
692 && (arm_gen_constant (code, mode, val, target, source, 1, 0)
693 > arm_constant_limit + (code != SET)))
697 /* Currently SET is the only monadic value for CODE, all
698 the rest are diadic. */
699 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (val)));
704 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
706 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (val)));
707 /* For MINUS, the value is subtracted from, since we never
708 have subtraction of a constant. */
710 emit_insn (gen_rtx_SET (VOIDmode, target,
711 gen_rtx (code, mode, temp, source)));
713 emit_insn (gen_rtx_SET (VOIDmode, target,
714 gen_rtx (code, mode, source, temp)));
720 return arm_gen_constant (code, mode, val, target, source, subtargets, 1);
723 /* As above, but extra parameter GENERATE which, if clear, suppresses
726 arm_gen_constant (code, mode, val, target, source, subtargets, generate)
728 enum machine_mode mode;
737 int can_negate_initial = 0;
740 int num_bits_set = 0;
741 int set_sign_bit_copies = 0;
742 int clear_sign_bit_copies = 0;
743 int clear_zero_bit_copies = 0;
744 int set_zero_bit_copies = 0;
746 unsigned HOST_WIDE_INT temp1, temp2;
747 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
749 /* find out which operations are safe for a given CODE. Also do a quick
750 check for degenerate cases; these can occur when DImode operations
762 can_negate_initial = 1;
766 if (remainder == 0xffffffff)
769 emit_insn (gen_rtx_SET (VOIDmode, target,
770 GEN_INT (ARM_SIGN_EXTEND (val))));
775 if (reload_completed && rtx_equal_p (target, source))
778 emit_insn (gen_rtx_SET (VOIDmode, target, source));
787 emit_insn (gen_rtx_SET (VOIDmode, target, const0_rtx));
790 if (remainder == 0xffffffff)
792 if (reload_completed && rtx_equal_p (target, source))
795 emit_insn (gen_rtx_SET (VOIDmode, target, source));
804 if (reload_completed && rtx_equal_p (target, source))
807 emit_insn (gen_rtx_SET (VOIDmode, target, source));
810 if (remainder == 0xffffffff)
813 emit_insn (gen_rtx_SET (VOIDmode, target,
814 gen_rtx_NOT (mode, source)));
818 /* We don't know how to handle this yet below. */
822 /* We treat MINUS as (val - source), since (source - val) is always
823 passed as (source + (-val)). */
827 emit_insn (gen_rtx_SET (VOIDmode, target,
828 gen_rtx_NEG (mode, source)));
831 if (const_ok_for_arm (val))
834 emit_insn (gen_rtx_SET (VOIDmode, target,
835 gen_rtx_MINUS (mode, GEN_INT (val),
847 /* If we can do it in one insn get out quickly */
848 if (const_ok_for_arm (val)
849 || (can_negate_initial && const_ok_for_arm (-val))
850 || (can_invert && const_ok_for_arm (~val)))
853 emit_insn (gen_rtx_SET (VOIDmode, target,
854 (source ? gen_rtx (code, mode, source,
861 /* Calculate a few attributes that may be useful for specific
864 for (i = 31; i >= 0; i--)
866 if ((remainder & (1 << i)) == 0)
867 clear_sign_bit_copies++;
872 for (i = 31; i >= 0; i--)
874 if ((remainder & (1 << i)) != 0)
875 set_sign_bit_copies++;
880 for (i = 0; i <= 31; i++)
882 if ((remainder & (1 << i)) == 0)
883 clear_zero_bit_copies++;
888 for (i = 0; i <= 31; i++)
890 if ((remainder & (1 << i)) != 0)
891 set_zero_bit_copies++;
899 /* See if we can do this by sign_extending a constant that is known
900 to be negative. This is a good, way of doing it, since the shift
901 may well merge into a subsequent insn. */
902 if (set_sign_bit_copies > 1)
905 (temp1 = ARM_SIGN_EXTEND (remainder
906 << (set_sign_bit_copies - 1))))
910 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
911 emit_insn (gen_rtx_SET (VOIDmode, new_src,
913 emit_insn (gen_ashrsi3 (target, new_src,
914 GEN_INT (set_sign_bit_copies - 1)));
918 /* For an inverted constant, we will need to set the low bits,
919 these will be shifted out of harm's way. */
920 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
921 if (const_ok_for_arm (~temp1))
925 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
926 emit_insn (gen_rtx_SET (VOIDmode, new_src,
928 emit_insn (gen_ashrsi3 (target, new_src,
929 GEN_INT (set_sign_bit_copies - 1)));
935 /* See if we can generate this by setting the bottom (or the top)
936 16 bits, and then shifting these into the other half of the
937 word. We only look for the simplest cases, to do more would cost
938 too much. Be careful, however, not to generate this when the
939 alternative would take fewer insns. */
940 if (val & 0xffff0000)
942 temp1 = remainder & 0xffff0000;
943 temp2 = remainder & 0x0000ffff;
945 /* Overlaps outside this range are best done using other methods. */
946 for (i = 9; i < 24; i++)
948 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
949 && ! const_ok_for_arm (temp2))
951 rtx new_src = (subtargets
952 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
954 insns = arm_gen_constant (code, mode, temp2, new_src,
955 source, subtargets, generate);
958 emit_insn (gen_rtx_SET
961 gen_rtx_ASHIFT (mode, source,
968 /* Don't duplicate cases already considered. */
969 for (i = 17; i < 24; i++)
971 if (((temp1 | (temp1 >> i)) == remainder)
972 && ! const_ok_for_arm (temp1))
974 rtx new_src = (subtargets
975 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
977 insns = arm_gen_constant (code, mode, temp1, new_src,
978 source, subtargets, generate);
982 (gen_rtx_SET (VOIDmode, target,
985 gen_rtx_LSHIFTRT (mode, source,
996 /* If we have IOR or XOR, and the constant can be loaded in a
997 single instruction, and we can find a temporary to put it in,
998 then this can be done in two instructions instead of 3-4. */
1000 /* TARGET can't be NULL if SUBTARGETS is 0 */
1001 || (reload_completed && ! reg_mentioned_p (target, source)))
1003 if (const_ok_for_arm (ARM_SIGN_EXTEND (~ val)))
1007 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1009 emit_insn (gen_rtx_SET (VOIDmode, sub, GEN_INT (val)));
1010 emit_insn (gen_rtx_SET (VOIDmode, target,
1011 gen_rtx (code, mode, source, sub)));
1020 if (set_sign_bit_copies > 8
1021 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
1025 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1026 rtx shift = GEN_INT (set_sign_bit_copies);
1028 emit_insn (gen_rtx_SET (VOIDmode, sub,
1030 gen_rtx_ASHIFT (mode,
1033 emit_insn (gen_rtx_SET (VOIDmode, target,
1035 gen_rtx_LSHIFTRT (mode, sub,
1041 if (set_zero_bit_copies > 8
1042 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
1046 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1047 rtx shift = GEN_INT (set_zero_bit_copies);
1049 emit_insn (gen_rtx_SET (VOIDmode, sub,
1051 gen_rtx_LSHIFTRT (mode,
1054 emit_insn (gen_rtx_SET (VOIDmode, target,
1056 gen_rtx_ASHIFT (mode, sub,
1062 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~ val)))
1066 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1067 emit_insn (gen_rtx_SET (VOIDmode, sub,
1068 gen_rtx_NOT (mode, source)));
1071 sub = gen_reg_rtx (mode);
1072 emit_insn (gen_rtx_SET (VOIDmode, sub,
1073 gen_rtx_AND (mode, source,
1075 emit_insn (gen_rtx_SET (VOIDmode, target,
1076 gen_rtx_NOT (mode, sub)));
1083 /* See if two shifts will do 2 or more insn's worth of work. */
1084 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
1086 HOST_WIDE_INT shift_mask = ((0xffffffff
1087 << (32 - clear_sign_bit_copies))
1090 if ((remainder | shift_mask) != 0xffffffff)
1094 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1095 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
1096 new_src, source, subtargets, 1);
1101 rtx targ = subtargets ? NULL_RTX : target;
1102 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
1103 targ, source, subtargets, 0);
1109 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1110 rtx shift = GEN_INT (clear_sign_bit_copies);
1112 emit_insn (gen_ashlsi3 (new_src, source, shift));
1113 emit_insn (gen_lshrsi3 (target, new_src, shift));
1119 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
1121 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
1123 if ((remainder | shift_mask) != 0xffffffff)
1127 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1129 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
1130 new_src, source, subtargets, 1);
1135 rtx targ = subtargets ? NULL_RTX : target;
1137 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
1138 targ, source, subtargets, 0);
1144 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1145 rtx shift = GEN_INT (clear_zero_bit_copies);
1147 emit_insn (gen_lshrsi3 (new_src, source, shift));
1148 emit_insn (gen_ashlsi3 (target, new_src, shift));
1160 for (i = 0; i < 32; i++)
1161 if (remainder & (1 << i))
1164 if (code == AND || (can_invert && num_bits_set > 16))
1165 remainder = (~remainder) & 0xffffffff;
1166 else if (code == PLUS && num_bits_set > 16)
1167 remainder = (-remainder) & 0xffffffff;
1174 /* Now try and find a way of doing the job in either two or three
1176 We start by looking for the largest block of zeros that are aligned on
1177 a 2-bit boundary, we then fill up the temps, wrapping around to the
1178 top of the word when we drop off the bottom.
1179 In the worst case this code should produce no more than four insns. */
1182 int best_consecutive_zeros = 0;
1184 for (i = 0; i < 32; i += 2)
1186 int consecutive_zeros = 0;
1188 if (! (remainder & (3 << i)))
1190 while ((i < 32) && ! (remainder & (3 << i)))
1192 consecutive_zeros += 2;
1195 if (consecutive_zeros > best_consecutive_zeros)
1197 best_consecutive_zeros = consecutive_zeros;
1198 best_start = i - consecutive_zeros;
1204 /* Now start emitting the insns, starting with the one with the highest
1205 bit set: we do this so that the smallest number will be emitted last;
1206 this is more likely to be combinable with addressing insns. */
1214 if (remainder & (3 << (i - 2)))
1219 temp1 = remainder & ((0x0ff << end)
1220 | ((i < end) ? (0xff >> (32 - end)) : 0));
1221 remainder &= ~temp1;
1228 emit_insn (gen_rtx_SET (VOIDmode,
1229 new_src = (subtargets
1230 ? gen_reg_rtx (mode)
1233 ? ~temp1 : temp1)));
1234 else if (code == MINUS)
1235 emit_insn (gen_rtx_SET (VOIDmode,
1236 new_src = (subtargets
1237 ? gen_reg_rtx (mode)
1239 gen_rtx (code, mode, GEN_INT (temp1),
1242 emit_insn (gen_rtx_SET (VOIDmode,
1243 new_src = (remainder
1245 ? gen_reg_rtx (mode)
1248 gen_rtx (code, mode, source,
1249 GEN_INT (can_invert ? ~temp1
1261 else if (code == MINUS)
1268 } while (remainder);
1273 /* Canonicalize a comparison so that we are more likely to recognize it.
1274 This can be done for a few constant compares, where we can make the
1275 immediate value easier to load. */
1277 arm_canonicalize_comparison (code, op1)
1281 unsigned HOST_WIDE_INT i = INTVAL (*op1);
1291 if (i != ((((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
1293 && (const_ok_for_arm (i+1) || const_ok_for_arm (- (i+1))))
1295 *op1 = GEN_INT (i+1);
1296 return code == GT ? GE : LT;
1302 if (i != (((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
1303 && (const_ok_for_arm (i-1) || const_ok_for_arm (- (i-1))))
1305 *op1 = GEN_INT (i-1);
1306 return code == GE ? GT : LE;
1312 if (i != ~((unsigned HOST_WIDE_INT) 0)
1313 && (const_ok_for_arm (i+1) || const_ok_for_arm (- (i+1))))
1315 *op1 = GEN_INT (i + 1);
1316 return code == GTU ? GEU : LTU;
1323 && (const_ok_for_arm (i - 1) || const_ok_for_arm (- (i - 1))))
1325 *op1 = GEN_INT (i - 1);
1326 return code == GEU ? GTU : LEU;
1337 /* Decide whether a type should be returned in memory (true)
1338 or in a register (false). This is called by the macro
1339 RETURN_IN_MEMORY. */
1341 arm_return_in_memory (type)
1344 if (! AGGREGATE_TYPE_P (type))
1346 /* All simple types are returned in registers. */
1349 else if (int_size_in_bytes (type) > 4)
1351 /* All structures/unions bigger than one word are returned in memory. */
1354 else if (TREE_CODE (type) == RECORD_TYPE)
1358 /* For a struct the APCS says that we must return in a register if
1359 every addressable element has an offset of zero. For practical
1360 purposes this means that the structure can have at most one non
1361 bit-field element and that this element must be the first one in
1364 /* Find the first field, ignoring non FIELD_DECL things which will
1365 have been created by C++. */
1366 for (field = TYPE_FIELDS (type);
1367 field && TREE_CODE (field) != FIELD_DECL;
1368 field = TREE_CHAIN (field))
1372 return 0; /* An empty structure. Allowed by an extension to ANSI C. */
1374 /* Now check the remaining fields, if any. */
1375 for (field = TREE_CHAIN (field);
1377 field = TREE_CHAIN (field))
1379 if (TREE_CODE (field) != FIELD_DECL)
1382 if (! DECL_BIT_FIELD_TYPE (field))
1388 else if (TREE_CODE (type) == UNION_TYPE)
1392 /* Unions can be returned in registers if every element is
1393 integral, or can be returned in an integer register. */
1394 for (field = TYPE_FIELDS (type);
1396 field = TREE_CHAIN (field))
1398 if (TREE_CODE (field) != FIELD_DECL)
1401 if (FLOAT_TYPE_P (TREE_TYPE (field)))
1404 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
1411 /* XXX Not sure what should be done for other aggregates, so put them in
1417 legitimate_pic_operand_p (x)
1420 if (CONSTANT_P (x) && flag_pic
1421 && (GET_CODE (x) == SYMBOL_REF
1422 || (GET_CODE (x) == CONST
1423 && GET_CODE (XEXP (x, 0)) == PLUS
1424 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)))
1431 legitimize_pic_address (orig, mode, reg)
1433 enum machine_mode mode;
1436 if (GET_CODE (orig) == SYMBOL_REF)
1438 rtx pic_ref, address;
1444 if (reload_in_progress || reload_completed)
1447 reg = gen_reg_rtx (Pmode);
1452 #ifdef AOF_ASSEMBLER
1453 /* The AOF assembler can generate relocations for these directly, and
1454 understands that the PIC register has to be added into the offset.
1456 insn = emit_insn (gen_pic_load_addr_based (reg, orig));
1459 address = gen_reg_rtx (Pmode);
1463 emit_insn (gen_pic_load_addr (address, orig));
1465 pic_ref = gen_rtx_MEM (Pmode,
1466 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
1468 RTX_UNCHANGING_P (pic_ref) = 1;
1469 insn = emit_move_insn (reg, pic_ref);
1471 current_function_uses_pic_offset_table = 1;
1472 /* Put a REG_EQUAL note on this insn, so that it can be optimized
1474 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
1478 else if (GET_CODE (orig) == CONST)
1482 if (GET_CODE (XEXP (orig, 0)) == PLUS
1483 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1488 if (reload_in_progress || reload_completed)
1491 reg = gen_reg_rtx (Pmode);
1494 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1496 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1497 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1498 base == reg ? 0 : reg);
1503 if (GET_CODE (offset) == CONST_INT)
1505 /* The base register doesn't really matter, we only want to
1506 test the index for the appropriate mode. */
1507 GO_IF_LEGITIMATE_INDEX (mode, 0, offset, win);
1509 if (! reload_in_progress && ! reload_completed)
1510 offset = force_reg (Pmode, offset);
1515 if (GET_CODE (offset) == CONST_INT)
1516 return plus_constant_for_output (base, INTVAL (offset));
1519 if (GET_MODE_SIZE (mode) > 4
1520 && (GET_MODE_CLASS (mode) == MODE_INT
1521 || TARGET_SOFT_FLOAT))
1523 emit_insn (gen_addsi3 (reg, base, offset));
1527 return gen_rtx_PLUS (Pmode, base, offset);
1529 else if (GET_CODE (orig) == LABEL_REF)
1530 current_function_uses_pic_offset_table = 1;
1549 #ifndef AOF_ASSEMBLER
1550 rtx l1, pic_tmp, pic_tmp2, seq;
1551 rtx global_offset_table;
1553 if (current_function_uses_pic_offset_table == 0)
1560 l1 = gen_label_rtx ();
1562 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
1563 /* On the ARM the PC register contains 'dot + 8' at the time of the
1565 pic_tmp = plus_constant (gen_rtx_LABEL_REF (Pmode, l1), 8);
1566 pic_tmp2 = gen_rtx_CONST (VOIDmode,
1567 gen_rtx_PLUS (Pmode, global_offset_table, pc_rtx));
1569 pic_rtx = gen_rtx_CONST (Pmode, gen_rtx_MINUS (Pmode, pic_tmp2, pic_tmp));
1571 emit_insn (gen_pic_load_addr (pic_offset_table_rtx, pic_rtx));
1572 emit_insn (gen_pic_add_dot_plus_eight (pic_offset_table_rtx, l1));
1574 seq = gen_sequence ();
1576 emit_insn_after (seq, get_insns ());
1578 /* Need to emit this whether or not we obey regdecls,
1579 since setjmp/longjmp can cause life info to screw up. */
1580 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
1581 #endif /* AOF_ASSEMBLER */
1584 #define REG_OR_SUBREG_REG(X) \
1585 (GET_CODE (X) == REG \
1586 || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG))
1588 #define REG_OR_SUBREG_RTX(X) \
1589 (GET_CODE (X) == REG ? (X) : SUBREG_REG (X))
1591 #define ARM_FRAME_RTX(X) \
1592 ((X) == frame_pointer_rtx || (X) == stack_pointer_rtx \
1593 || (X) == arg_pointer_rtx)
1596 arm_rtx_costs (x, code)
1600 enum machine_mode mode = GET_MODE (x);
1601 enum rtx_code subcode;
1607 /* Memory costs quite a lot for the first word, but subsequent words
1608 load at the equivalent of a single insn each. */
1609 return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
1610 + (CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
1617 if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG)
1624 case ASHIFT: case LSHIFTRT: case ASHIFTRT:
1626 return (8 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : 8)
1627 + ((GET_CODE (XEXP (x, 0)) == REG
1628 || (GET_CODE (XEXP (x, 0)) == SUBREG
1629 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
1631 return (1 + ((GET_CODE (XEXP (x, 0)) == REG
1632 || (GET_CODE (XEXP (x, 0)) == SUBREG
1633 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
1635 + ((GET_CODE (XEXP (x, 1)) == REG
1636 || (GET_CODE (XEXP (x, 1)) == SUBREG
1637 && GET_CODE (SUBREG_REG (XEXP (x, 1))) == REG)
1638 || (GET_CODE (XEXP (x, 1)) == CONST_INT))
1643 return (4 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 8)
1644 + ((REG_OR_SUBREG_REG (XEXP (x, 0))
1645 || (GET_CODE (XEXP (x, 0)) == CONST_INT
1646 && const_ok_for_arm (INTVAL (XEXP (x, 0)))))
1649 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1650 return (2 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1651 || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
1652 && const_double_rtx_ok_for_fpu (XEXP (x, 1))))
1654 + ((REG_OR_SUBREG_REG (XEXP (x, 0))
1655 || (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE
1656 && const_double_rtx_ok_for_fpu (XEXP (x, 0))))
1659 if (((GET_CODE (XEXP (x, 0)) == CONST_INT
1660 && const_ok_for_arm (INTVAL (XEXP (x, 0)))
1661 && REG_OR_SUBREG_REG (XEXP (x, 1))))
1662 || (((subcode = GET_CODE (XEXP (x, 1))) == ASHIFT
1663 || subcode == ASHIFTRT || subcode == LSHIFTRT
1664 || subcode == ROTATE || subcode == ROTATERT
1666 && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
1667 && ((INTVAL (XEXP (XEXP (x, 1), 1)) &
1668 (INTVAL (XEXP (XEXP (x, 1), 1)) - 1)) == 0)))
1669 && REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 0))
1670 && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 1))
1671 || GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT)
1672 && REG_OR_SUBREG_REG (XEXP (x, 0))))
1677 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1678 return (2 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
1679 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1680 || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
1681 && const_double_rtx_ok_for_fpu (XEXP (x, 1))))
1685 case AND: case XOR: case IOR:
1688 /* Normally the frame registers will be spilt into reg+const during
1689 reload, so it is a bad idea to combine them with other instructions,
1690 since then they might not be moved outside of loops. As a compromise
1691 we allow integration with ops that have a constant as their second
1693 if ((REG_OR_SUBREG_REG (XEXP (x, 0))
1694 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))
1695 && GET_CODE (XEXP (x, 1)) != CONST_INT)
1696 || (REG_OR_SUBREG_REG (XEXP (x, 0))
1697 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))))
1701 return (4 + extra_cost + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
1702 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1703 || (GET_CODE (XEXP (x, 1)) == CONST_INT
1704 && const_ok_for_op (INTVAL (XEXP (x, 1)), code)))
1707 if (REG_OR_SUBREG_REG (XEXP (x, 0)))
1708 return (1 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : extra_cost)
1709 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1710 || (GET_CODE (XEXP (x, 1)) == CONST_INT
1711 && const_ok_for_op (INTVAL (XEXP (x, 1)), code)))
1714 else if (REG_OR_SUBREG_REG (XEXP (x, 1)))
1715 return (1 + extra_cost
1716 + ((((subcode = GET_CODE (XEXP (x, 0))) == ASHIFT
1717 || subcode == LSHIFTRT || subcode == ASHIFTRT
1718 || subcode == ROTATE || subcode == ROTATERT
1720 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1721 && ((INTVAL (XEXP (XEXP (x, 0), 1)) &
1722 (INTVAL (XEXP (XEXP (x, 0), 1)) - 1)) == 0)))
1723 && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 0)))
1724 && ((REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 1)))
1725 || GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
1731 /* There is no point basing this on the tuning, since it is always the
1732 fast variant if it exists at all */
1733 if (arm_fast_multiply && mode == DImode
1734 && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1)))
1735 && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
1736 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND))
1739 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1743 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1745 unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1))
1746 & (unsigned HOST_WIDE_INT) 0xffffffff);
1747 int add_cost = const_ok_for_arm (i) ? 4 : 8;
1749 /* Tune as appropriate */
1750 int booth_unit_size = ((tune_flags & FL_FAST_MULT) ? 8 : 2);
1752 for (j = 0; i && j < 32; j += booth_unit_size)
1754 i >>= booth_unit_size;
1761 return (((tune_flags & FL_FAST_MULT) ? 8 : 30)
1762 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4)
1763 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 4));
1766 if (arm_fast_multiply && mode == SImode
1767 && GET_CODE (XEXP (x, 0)) == LSHIFTRT
1768 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1769 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1770 == GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1771 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND
1772 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND))
1777 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1778 return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 6);
1782 return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
1784 return 1 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
1787 if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
1795 return 4 + (mode == DImode ? 4 : 0);
1798 if (GET_MODE (XEXP (x, 0)) == QImode)
1799 return (4 + (mode == DImode ? 4 : 0)
1800 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1803 switch (GET_MODE (XEXP (x, 0)))
1806 return (1 + (mode == DImode ? 4 : 0)
1807 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1810 return (4 + (mode == DImode ? 4 : 0)
1811 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1814 return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1827 arm_adjust_cost (insn, link, dep, cost)
1835 /* XXX This is not strictly true for the FPA. */
1836 if (REG_NOTE_KIND(link) == REG_DEP_ANTI
1837 || REG_NOTE_KIND(link) == REG_DEP_OUTPUT)
1840 if ((i_pat = single_set (insn)) != NULL
1841 && GET_CODE (SET_SRC (i_pat)) == MEM
1842 && (d_pat = single_set (dep)) != NULL
1843 && GET_CODE (SET_DEST (d_pat)) == MEM)
1845 /* This is a load after a store, there is no conflict if the load reads
1846 from a cached area. Assume that loads from the stack, and from the
1847 constant pool are cached, and that others will miss. This is a
1850 /* debug_rtx (insn);
1853 fprintf (stderr, "costs %d\n", cost); */
1855 if (CONSTANT_POOL_ADDRESS_P (XEXP (SET_SRC (i_pat), 0))
1856 || reg_mentioned_p (stack_pointer_rtx, XEXP (SET_SRC (i_pat), 0))
1857 || reg_mentioned_p (frame_pointer_rtx, XEXP (SET_SRC (i_pat), 0))
1858 || reg_mentioned_p (hard_frame_pointer_rtx,
1859 XEXP (SET_SRC (i_pat), 0)))
1861 /* fprintf (stderr, "***** Now 1\n"); */
1869 /* This code has been fixed for cross compilation. */
1871 static int fpa_consts_inited = 0;
1873 char *strings_fpa[8] = {
1875 "4", "5", "0.5", "10"
1878 static REAL_VALUE_TYPE values_fpa[8];
1886 for (i = 0; i < 8; i++)
1888 r = REAL_VALUE_ATOF (strings_fpa[i], DFmode);
1892 fpa_consts_inited = 1;
1895 /* Return TRUE if rtx X is a valid immediate FPU constant. */
1898 const_double_rtx_ok_for_fpu (x)
1904 if (!fpa_consts_inited)
1907 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
1908 if (REAL_VALUE_MINUS_ZERO (r))
1911 for (i = 0; i < 8; i++)
1912 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
1918 /* Return TRUE if rtx X is a valid immediate FPU constant. */
1921 neg_const_double_rtx_ok_for_fpu (x)
1927 if (!fpa_consts_inited)
1930 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
1931 r = REAL_VALUE_NEGATE (r);
1932 if (REAL_VALUE_MINUS_ZERO (r))
1935 for (i = 0; i < 8; i++)
1936 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
1942 /* Predicates for `match_operand' and `match_operator'. */
1944 /* s_register_operand is the same as register_operand, but it doesn't accept
1947 This function exists because at the time it was put in it led to better
1948 code. SUBREG(MEM) always needs a reload in the places where
1949 s_register_operand is used, and this seemed to lead to excessive
1953 s_register_operand (op, mode)
1955 enum machine_mode mode;
1957 if (GET_MODE (op) != mode && mode != VOIDmode)
1960 if (GET_CODE (op) == SUBREG)
1961 op = SUBREG_REG (op);
1963 /* We don't consider registers whose class is NO_REGS
1964 to be a register operand. */
1965 return (GET_CODE (op) == REG
1966 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1967 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1970 /* Only accept reg, subreg(reg), const_int. */
1973 reg_or_int_operand (op, mode)
1975 enum machine_mode mode;
1977 if (GET_CODE (op) == CONST_INT)
1980 if (GET_MODE (op) != mode && mode != VOIDmode)
1983 if (GET_CODE (op) == SUBREG)
1984 op = SUBREG_REG (op);
1986 /* We don't consider registers whose class is NO_REGS
1987 to be a register operand. */
1988 return (GET_CODE (op) == REG
1989 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1990 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1993 /* Return 1 if OP is an item in memory, given that we are in reload. */
1996 reload_memory_operand (op, mode)
1998 enum machine_mode mode ATTRIBUTE_UNUSED;
2000 int regno = true_regnum (op);
2002 return (! CONSTANT_P (op)
2004 || (GET_CODE (op) == REG
2005 && REGNO (op) >= FIRST_PSEUDO_REGISTER)));
2008 /* Return 1 if OP is a valid memory address, but not valid for a signed byte
2009 memory access (architecture V4) */
2011 bad_signed_byte_operand (op, mode)
2013 enum machine_mode mode;
2015 if (! memory_operand (op, mode) || GET_CODE (op) != MEM)
2020 /* A sum of anything more complex than reg + reg or reg + const is bad */
2021 if ((GET_CODE (op) == PLUS || GET_CODE (op) == MINUS)
2022 && (! s_register_operand (XEXP (op, 0), VOIDmode)
2023 || (! s_register_operand (XEXP (op, 1), VOIDmode)
2024 && GET_CODE (XEXP (op, 1)) != CONST_INT)))
2027 /* Big constants are also bad */
2028 if (GET_CODE (op) == PLUS && GET_CODE (XEXP (op, 1)) == CONST_INT
2029 && (INTVAL (XEXP (op, 1)) > 0xff
2030 || -INTVAL (XEXP (op, 1)) > 0xff))
2033 /* Everything else is good, or can will automatically be made so. */
2037 /* Return TRUE for valid operands for the rhs of an ARM instruction. */
2040 arm_rhs_operand (op, mode)
2042 enum machine_mode mode;
2044 return (s_register_operand (op, mode)
2045 || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op))));
2048 /* Return TRUE for valid operands for the rhs of an ARM instruction, or a load.
2052 arm_rhsm_operand (op, mode)
2054 enum machine_mode mode;
2056 return (s_register_operand (op, mode)
2057 || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op)))
2058 || memory_operand (op, mode));
2061 /* Return TRUE for valid operands for the rhs of an ARM instruction, or if a
2062 constant that is valid when negated. */
2065 arm_add_operand (op, mode)
2067 enum machine_mode mode;
2069 return (s_register_operand (op, mode)
2070 || (GET_CODE (op) == CONST_INT
2071 && (const_ok_for_arm (INTVAL (op))
2072 || const_ok_for_arm (-INTVAL (op)))));
2076 arm_not_operand (op, mode)
2078 enum machine_mode mode;
2080 return (s_register_operand (op, mode)
2081 || (GET_CODE (op) == CONST_INT
2082 && (const_ok_for_arm (INTVAL (op))
2083 || const_ok_for_arm (~INTVAL (op)))));
2086 /* Return TRUE if the operand is a memory reference which contains an
2087 offsettable address. */
2089 offsettable_memory_operand (op, mode)
2091 enum machine_mode mode;
2093 if (mode == VOIDmode)
2094 mode = GET_MODE (op);
2096 return (mode == GET_MODE (op)
2097 && GET_CODE (op) == MEM
2098 && offsettable_address_p (reload_completed | reload_in_progress,
2099 mode, XEXP (op, 0)));
2102 /* Return TRUE if the operand is a memory reference which is, or can be
2103 made word aligned by adjusting the offset. */
2105 alignable_memory_operand (op, mode)
2107 enum machine_mode mode;
2111 if (mode == VOIDmode)
2112 mode = GET_MODE (op);
2114 if (mode != GET_MODE (op) || GET_CODE (op) != MEM)
2119 return ((GET_CODE (reg = op) == REG
2120 || (GET_CODE (op) == SUBREG
2121 && GET_CODE (reg = SUBREG_REG (op)) == REG)
2122 || (GET_CODE (op) == PLUS
2123 && GET_CODE (XEXP (op, 1)) == CONST_INT
2124 && (GET_CODE (reg = XEXP (op, 0)) == REG
2125 || (GET_CODE (XEXP (op, 0)) == SUBREG
2126 && GET_CODE (reg = SUBREG_REG (XEXP (op, 0))) == REG))))
2127 && REGNO_POINTER_ALIGN (REGNO (reg)) >= 4);
2130 /* Similar to s_register_operand, but does not allow hard integer
2133 f_register_operand (op, mode)
2135 enum machine_mode mode;
2137 if (GET_MODE (op) != mode && mode != VOIDmode)
2140 if (GET_CODE (op) == SUBREG)
2141 op = SUBREG_REG (op);
2143 /* We don't consider registers whose class is NO_REGS
2144 to be a register operand. */
2145 return (GET_CODE (op) == REG
2146 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
2147 || REGNO_REG_CLASS (REGNO (op)) == FPU_REGS));
2150 /* Return TRUE for valid operands for the rhs of an FPU instruction. */
2153 fpu_rhs_operand (op, mode)
2155 enum machine_mode mode;
2157 if (s_register_operand (op, mode))
2159 else if (GET_CODE (op) == CONST_DOUBLE)
2160 return (const_double_rtx_ok_for_fpu (op));
2166 fpu_add_operand (op, mode)
2168 enum machine_mode mode;
2170 if (s_register_operand (op, mode))
2172 else if (GET_CODE (op) == CONST_DOUBLE)
2173 return (const_double_rtx_ok_for_fpu (op)
2174 || neg_const_double_rtx_ok_for_fpu (op));
2179 /* Return nonzero if OP is a constant power of two. */
2182 power_of_two_operand (op, mode)
2184 enum machine_mode mode ATTRIBUTE_UNUSED;
2186 if (GET_CODE (op) == CONST_INT)
2188 HOST_WIDE_INT value = INTVAL(op);
2189 return value != 0 && (value & (value - 1)) == 0;
2194 /* Return TRUE for a valid operand of a DImode operation.
2195 Either: REG, CONST_DOUBLE or MEM(DImode_address).
2196 Note that this disallows MEM(REG+REG), but allows
2197 MEM(PRE/POST_INC/DEC(REG)). */
2200 di_operand (op, mode)
2202 enum machine_mode mode;
2204 if (s_register_operand (op, mode))
2207 switch (GET_CODE (op))
2214 return memory_address_p (DImode, XEXP (op, 0));
2221 /* Return TRUE for a valid operand of a DFmode operation when -msoft-float.
2222 Either: REG, CONST_DOUBLE or MEM(DImode_address).
2223 Note that this disallows MEM(REG+REG), but allows
2224 MEM(PRE/POST_INC/DEC(REG)). */
2227 soft_df_operand (op, mode)
2229 enum machine_mode mode;
2231 if (s_register_operand (op, mode))
2234 switch (GET_CODE (op))
2240 return memory_address_p (DFmode, XEXP (op, 0));
2247 /* Return TRUE for valid index operands. */
2250 index_operand (op, mode)
2252 enum machine_mode mode;
2254 return (s_register_operand(op, mode)
2255 || (immediate_operand (op, mode)
2256 && INTVAL (op) < 4096 && INTVAL (op) > -4096));
2259 /* Return TRUE for valid shifts by a constant. This also accepts any
2260 power of two on the (somewhat overly relaxed) assumption that the
2261 shift operator in this case was a mult. */
2264 const_shift_operand (op, mode)
2266 enum machine_mode mode;
2268 return (power_of_two_operand (op, mode)
2269 || (immediate_operand (op, mode)
2270 && (INTVAL (op) < 32 && INTVAL (op) > 0)));
2273 /* Return TRUE for arithmetic operators which can be combined with a multiply
2277 shiftable_operator (x, mode)
2279 enum machine_mode mode;
2281 if (GET_MODE (x) != mode)
2285 enum rtx_code code = GET_CODE (x);
2287 return (code == PLUS || code == MINUS
2288 || code == IOR || code == XOR || code == AND);
2292 /* Return TRUE for shift operators. */
2295 shift_operator (x, mode)
2297 enum machine_mode mode;
2299 if (GET_MODE (x) != mode)
2303 enum rtx_code code = GET_CODE (x);
2306 return power_of_two_operand (XEXP (x, 1), mode);
2308 return (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT
2309 || code == ROTATERT);
2313 int equality_operator (x, mode)
2315 enum machine_mode mode ATTRIBUTE_UNUSED;
2317 return GET_CODE (x) == EQ || GET_CODE (x) == NE;
2320 /* Return TRUE for SMIN SMAX UMIN UMAX operators. */
2323 minmax_operator (x, mode)
2325 enum machine_mode mode;
2327 enum rtx_code code = GET_CODE (x);
2329 if (GET_MODE (x) != mode)
2332 return code == SMIN || code == SMAX || code == UMIN || code == UMAX;
2335 /* return TRUE if x is EQ or NE */
2337 /* Return TRUE if this is the condition code register, if we aren't given
2338 a mode, accept any class CCmode register */
2341 cc_register (x, mode)
2343 enum machine_mode mode;
2345 if (mode == VOIDmode)
2347 mode = GET_MODE (x);
2348 if (GET_MODE_CLASS (mode) != MODE_CC)
2352 if (mode == GET_MODE (x) && GET_CODE (x) == REG && REGNO (x) == 24)
2358 /* Return TRUE if this is the condition code register, if we aren't given
2359 a mode, accept any class CCmode register which indicates a dominance
2363 dominant_cc_register (x, mode)
2365 enum machine_mode mode;
2367 if (mode == VOIDmode)
2369 mode = GET_MODE (x);
2370 if (GET_MODE_CLASS (mode) != MODE_CC)
2374 if (mode != CC_DNEmode && mode != CC_DEQmode
2375 && mode != CC_DLEmode && mode != CC_DLTmode
2376 && mode != CC_DGEmode && mode != CC_DGTmode
2377 && mode != CC_DLEUmode && mode != CC_DLTUmode
2378 && mode != CC_DGEUmode && mode != CC_DGTUmode)
2381 if (mode == GET_MODE (x) && GET_CODE (x) == REG && REGNO (x) == 24)
2387 /* Return TRUE if X references a SYMBOL_REF. */
2389 symbol_mentioned_p (x)
2395 if (GET_CODE (x) == SYMBOL_REF)
2398 fmt = GET_RTX_FORMAT (GET_CODE (x));
2399 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2405 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2406 if (symbol_mentioned_p (XVECEXP (x, i, j)))
2409 else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i)))
2416 /* Return TRUE if X references a LABEL_REF. */
2418 label_mentioned_p (x)
2424 if (GET_CODE (x) == LABEL_REF)
2427 fmt = GET_RTX_FORMAT (GET_CODE (x));
2428 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2434 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2435 if (label_mentioned_p (XVECEXP (x, i, j)))
2438 else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i)))
2449 enum rtx_code code = GET_CODE (x);
2453 else if (code == SMIN)
2455 else if (code == UMIN)
2457 else if (code == UMAX)
2463 /* Return 1 if memory locations are adjacent */
2466 adjacent_mem_locations (a, b)
2469 int val0 = 0, val1 = 0;
2472 if ((GET_CODE (XEXP (a, 0)) == REG
2473 || (GET_CODE (XEXP (a, 0)) == PLUS
2474 && GET_CODE (XEXP (XEXP (a, 0), 1)) == CONST_INT))
2475 && (GET_CODE (XEXP (b, 0)) == REG
2476 || (GET_CODE (XEXP (b, 0)) == PLUS
2477 && GET_CODE (XEXP (XEXP (b, 0), 1)) == CONST_INT)))
2479 if (GET_CODE (XEXP (a, 0)) == PLUS)
2481 reg0 = REGNO (XEXP (XEXP (a, 0), 0));
2482 val0 = INTVAL (XEXP (XEXP (a, 0), 1));
2485 reg0 = REGNO (XEXP (a, 0));
2486 if (GET_CODE (XEXP (b, 0)) == PLUS)
2488 reg1 = REGNO (XEXP (XEXP (b, 0), 0));
2489 val1 = INTVAL (XEXP (XEXP (b, 0), 1));
2492 reg1 = REGNO (XEXP (b, 0));
2493 return (reg0 == reg1) && ((val1 - val0) == 4 || (val0 - val1) == 4);
2498 /* Return 1 if OP is a load multiple operation. It is known to be
2499 parallel and the first section will be tested. */
2502 load_multiple_operation (op, mode)
2504 enum machine_mode mode ATTRIBUTE_UNUSED;
2506 HOST_WIDE_INT count = XVECLEN (op, 0);
2509 HOST_WIDE_INT i = 1, base = 0;
2513 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
2516 /* Check to see if this might be a write-back */
2517 if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
2522 /* Now check it more carefully */
2523 if (GET_CODE (SET_DEST (elt)) != REG
2524 || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
2525 || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt))
2526 || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
2527 || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 2) * 4
2528 || GET_CODE (XVECEXP (op, 0, count - 1)) != CLOBBER
2529 || GET_CODE (XEXP (XVECEXP (op, 0, count - 1), 0)) != REG
2530 || REGNO (XEXP (XVECEXP (op, 0, count - 1), 0))
2531 != REGNO (SET_DEST (elt)))
2537 /* Perform a quick check so we don't blow up below. */
2539 || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
2540 || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG
2541 || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != MEM)
2544 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1)));
2545 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0);
2547 for (; i < count; i++)
2549 elt = XVECEXP (op, 0, i);
2551 if (GET_CODE (elt) != SET
2552 || GET_CODE (SET_DEST (elt)) != REG
2553 || GET_MODE (SET_DEST (elt)) != SImode
2554 || REGNO (SET_DEST (elt)) != dest_regno + i - base
2555 || GET_CODE (SET_SRC (elt)) != MEM
2556 || GET_MODE (SET_SRC (elt)) != SImode
2557 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
2558 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
2559 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
2560 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != (i - base) * 4)
2567 /* Return 1 if OP is a store multiple operation. It is known to be
2568 parallel and the first section will be tested. */
2571 store_multiple_operation (op, mode)
2573 enum machine_mode mode ATTRIBUTE_UNUSED;
2575 HOST_WIDE_INT count = XVECLEN (op, 0);
2578 HOST_WIDE_INT i = 1, base = 0;
2582 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
2585 /* Check to see if this might be a write-back */
2586 if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
2591 /* Now check it more carefully */
2592 if (GET_CODE (SET_DEST (elt)) != REG
2593 || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
2594 || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt))
2595 || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
2596 || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 2) * 4
2597 || GET_CODE (XVECEXP (op, 0, count - 1)) != CLOBBER
2598 || GET_CODE (XEXP (XVECEXP (op, 0, count - 1), 0)) != REG
2599 || REGNO (XEXP (XVECEXP (op, 0, count - 1), 0))
2600 != REGNO (SET_DEST (elt)))
2606 /* Perform a quick check so we don't blow up below. */
2608 || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
2609 || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM
2610 || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != REG)
2613 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1)));
2614 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0);
2616 for (; i < count; i++)
2618 elt = XVECEXP (op, 0, i);
2620 if (GET_CODE (elt) != SET
2621 || GET_CODE (SET_SRC (elt)) != REG
2622 || GET_MODE (SET_SRC (elt)) != SImode
2623 || REGNO (SET_SRC (elt)) != src_regno + i - base
2624 || GET_CODE (SET_DEST (elt)) != MEM
2625 || GET_MODE (SET_DEST (elt)) != SImode
2626 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
2627 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
2628 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
2629 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != (i - base) * 4)
2637 load_multiple_sequence (operands, nops, regs, base, load_offset)
2642 HOST_WIDE_INT *load_offset;
2644 int unsorted_regs[4];
2645 HOST_WIDE_INT unsorted_offsets[4];
2650 /* Can only handle 2, 3, or 4 insns at present, though could be easily
2651 extended if required. */
2652 if (nops < 2 || nops > 4)
2655 /* Loop over the operands and check that the memory references are
2656 suitable (ie immediate offsets from the same base register). At
2657 the same time, extract the target register, and the memory
2659 for (i = 0; i < nops; i++)
2664 /* Convert a subreg of a mem into the mem itself. */
2665 if (GET_CODE (operands[nops + i]) == SUBREG)
2666 operands[nops + i] = alter_subreg(operands[nops + i]);
2668 if (GET_CODE (operands[nops + i]) != MEM)
2671 /* Don't reorder volatile memory references; it doesn't seem worth
2672 looking for the case where the order is ok anyway. */
2673 if (MEM_VOLATILE_P (operands[nops + i]))
2676 offset = const0_rtx;
2678 if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG
2679 || (GET_CODE (reg) == SUBREG
2680 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2681 || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS
2682 && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0))
2684 || (GET_CODE (reg) == SUBREG
2685 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2686 && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1))
2691 base_reg = REGNO(reg);
2692 unsorted_regs[0] = (GET_CODE (operands[i]) == REG
2693 ? REGNO (operands[i])
2694 : REGNO (SUBREG_REG (operands[i])));
2699 if (base_reg != REGNO (reg))
2700 /* Not addressed from the same base register. */
2703 unsorted_regs[i] = (GET_CODE (operands[i]) == REG
2704 ? REGNO (operands[i])
2705 : REGNO (SUBREG_REG (operands[i])));
2706 if (unsorted_regs[i] < unsorted_regs[order[0]])
2710 /* If it isn't an integer register, or if it overwrites the
2711 base register but isn't the last insn in the list, then
2712 we can't do this. */
2713 if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14
2714 || (i != nops - 1 && unsorted_regs[i] == base_reg))
2717 unsorted_offsets[i] = INTVAL (offset);
2720 /* Not a suitable memory address. */
2724 /* All the useful information has now been extracted from the
2725 operands into unsorted_regs and unsorted_offsets; additionally,
2726 order[0] has been set to the lowest numbered register in the
2727 list. Sort the registers into order, and check that the memory
2728 offsets are ascending and adjacent. */
2730 for (i = 1; i < nops; i++)
2734 order[i] = order[i - 1];
2735 for (j = 0; j < nops; j++)
2736 if (unsorted_regs[j] > unsorted_regs[order[i - 1]]
2737 && (order[i] == order[i - 1]
2738 || unsorted_regs[j] < unsorted_regs[order[i]]))
2741 /* Have we found a suitable register? if not, one must be used more
2743 if (order[i] == order[i - 1])
2746 /* Is the memory address adjacent and ascending? */
2747 if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4)
2755 for (i = 0; i < nops; i++)
2756 regs[i] = unsorted_regs[order[i]];
2758 *load_offset = unsorted_offsets[order[0]];
2761 if (unsorted_offsets[order[0]] == 0)
2762 return 1; /* ldmia */
2764 if (unsorted_offsets[order[0]] == 4)
2765 return 2; /* ldmib */
2767 if (unsorted_offsets[order[nops - 1]] == 0)
2768 return 3; /* ldmda */
2770 if (unsorted_offsets[order[nops - 1]] == -4)
2771 return 4; /* ldmdb */
2773 /* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm if
2774 the offset isn't small enough. The reason 2 ldrs are faster is because
2775 these ARMs are able to do more than one cache access in a single cycle.
2776 The ARM9 and StrongARM have Harvard caches, whilst the ARM8 has a double
2777 bandwidth cache. This means that these cores can do both an instruction
2778 fetch and a data fetch in a single cycle, so the trick of calculating the
2779 address into a scratch register (one of the result regs) and then doing a
2780 load multiple actually becomes slower (and no smaller in code size). That
2781 is the transformation
2783 ldr rd1, [rbase + offset]
2784 ldr rd2, [rbase + offset + 4]
2788 add rd1, rbase, offset
2789 ldmia rd1, {rd1, rd2}
2791 produces worse code -- '3 cycles + any stalls on rd2' instead of '2 cycles
2792 + any stalls on rd2'. On ARMs with only one cache access per cycle, the
2793 first sequence could never complete in less than 6 cycles, whereas the ldm
2794 sequence would only take 5 and would make better use of sequential accesses
2795 if not hitting the cache.
2797 We cheat here and test 'arm_ld_sched' which we currently know to only be
2798 true for the ARM8, ARM9 and StrongARM. If this ever changes, then the test
2799 below needs to be reworked. */
2800 if (nops == 2 && arm_ld_sched)
2803 /* Can't do it without setting up the offset, only do this if it takes
2804 no more than one insn. */
2805 return (const_ok_for_arm (unsorted_offsets[order[0]])
2806 || const_ok_for_arm (-unsorted_offsets[order[0]])) ? 5 : 0;
2810 emit_ldm_seq (operands, nops)
2816 HOST_WIDE_INT offset;
2820 switch (load_multiple_sequence (operands, nops, regs, &base_reg, &offset))
2823 strcpy (buf, "ldm%?ia\t");
2827 strcpy (buf, "ldm%?ib\t");
2831 strcpy (buf, "ldm%?da\t");
2835 strcpy (buf, "ldm%?db\t");
2840 sprintf (buf, "add%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX,
2841 reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg],
2844 sprintf (buf, "sub%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX,
2845 reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg],
2847 output_asm_insn (buf, operands);
2849 strcpy (buf, "ldm%?ia\t");
2856 sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX,
2857 reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]);
2859 for (i = 1; i < nops; i++)
2860 sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX,
2861 reg_names[regs[i]]);
2863 strcat (buf, "}\t%@ phole ldm");
2865 output_asm_insn (buf, operands);
2870 store_multiple_sequence (operands, nops, regs, base, load_offset)
2875 HOST_WIDE_INT *load_offset;
2877 int unsorted_regs[4];
2878 HOST_WIDE_INT unsorted_offsets[4];
2883 /* Can only handle 2, 3, or 4 insns at present, though could be easily
2884 extended if required. */
2885 if (nops < 2 || nops > 4)
2888 /* Loop over the operands and check that the memory references are
2889 suitable (ie immediate offsets from the same base register). At
2890 the same time, extract the target register, and the memory
2892 for (i = 0; i < nops; i++)
2897 /* Convert a subreg of a mem into the mem itself. */
2898 if (GET_CODE (operands[nops + i]) == SUBREG)
2899 operands[nops + i] = alter_subreg(operands[nops + i]);
2901 if (GET_CODE (operands[nops + i]) != MEM)
2904 /* Don't reorder volatile memory references; it doesn't seem worth
2905 looking for the case where the order is ok anyway. */
2906 if (MEM_VOLATILE_P (operands[nops + i]))
2909 offset = const0_rtx;
2911 if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG
2912 || (GET_CODE (reg) == SUBREG
2913 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2914 || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS
2915 && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0))
2917 || (GET_CODE (reg) == SUBREG
2918 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2919 && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1))
2924 base_reg = REGNO(reg);
2925 unsorted_regs[0] = (GET_CODE (operands[i]) == REG
2926 ? REGNO (operands[i])
2927 : REGNO (SUBREG_REG (operands[i])));
2932 if (base_reg != REGNO (reg))
2933 /* Not addressed from the same base register. */
2936 unsorted_regs[i] = (GET_CODE (operands[i]) == REG
2937 ? REGNO (operands[i])
2938 : REGNO (SUBREG_REG (operands[i])));
2939 if (unsorted_regs[i] < unsorted_regs[order[0]])
2943 /* If it isn't an integer register, then we can't do this. */
2944 if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14)
2947 unsorted_offsets[i] = INTVAL (offset);
2950 /* Not a suitable memory address. */
2954 /* All the useful information has now been extracted from the
2955 operands into unsorted_regs and unsorted_offsets; additionally,
2956 order[0] has been set to the lowest numbered register in the
2957 list. Sort the registers into order, and check that the memory
2958 offsets are ascending and adjacent. */
2960 for (i = 1; i < nops; i++)
2964 order[i] = order[i - 1];
2965 for (j = 0; j < nops; j++)
2966 if (unsorted_regs[j] > unsorted_regs[order[i - 1]]
2967 && (order[i] == order[i - 1]
2968 || unsorted_regs[j] < unsorted_regs[order[i]]))
2971 /* Have we found a suitable register? if not, one must be used more
2973 if (order[i] == order[i - 1])
2976 /* Is the memory address adjacent and ascending? */
2977 if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4)
2985 for (i = 0; i < nops; i++)
2986 regs[i] = unsorted_regs[order[i]];
2988 *load_offset = unsorted_offsets[order[0]];
2991 if (unsorted_offsets[order[0]] == 0)
2992 return 1; /* stmia */
2994 if (unsorted_offsets[order[0]] == 4)
2995 return 2; /* stmib */
2997 if (unsorted_offsets[order[nops - 1]] == 0)
2998 return 3; /* stmda */
3000 if (unsorted_offsets[order[nops - 1]] == -4)
3001 return 4; /* stmdb */
3007 emit_stm_seq (operands, nops)
3013 HOST_WIDE_INT offset;
3017 switch (store_multiple_sequence (operands, nops, regs, &base_reg, &offset))
3020 strcpy (buf, "stm%?ia\t");
3024 strcpy (buf, "stm%?ib\t");
3028 strcpy (buf, "stm%?da\t");
3032 strcpy (buf, "stm%?db\t");
3039 sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX,
3040 reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]);
3042 for (i = 1; i < nops; i++)
3043 sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX,
3044 reg_names[regs[i]]);
3046 strcat (buf, "}\t%@ phole stm");
3048 output_asm_insn (buf, operands);
3053 multi_register_push (op, mode)
3055 enum machine_mode mode ATTRIBUTE_UNUSED;
3057 if (GET_CODE (op) != PARALLEL
3058 || (GET_CODE (XVECEXP (op, 0, 0)) != SET)
3059 || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
3060 || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != 2))
3067 /* Routines for use with attributes */
3069 /* Return nonzero if ATTR is a valid attribute for DECL.
3070 ATTRIBUTES are any existing attributes and ARGS are the arguments
3073 Supported attributes:
3075 naked: don't output any prologue or epilogue code, the user is assumed
3076 to do the right thing. */
3079 arm_valid_machine_decl_attribute (decl, attr, args)
3084 if (args != NULL_TREE)
3087 if (is_attribute_p ("naked", attr))
3088 return TREE_CODE (decl) == FUNCTION_DECL;
3092 /* Return non-zero if FUNC is a naked function. */
3095 arm_naked_function_p (func)
3100 if (TREE_CODE (func) != FUNCTION_DECL)
3103 a = lookup_attribute ("naked", DECL_MACHINE_ATTRIBUTES (func));
3104 return a != NULL_TREE;
3107 /* Routines for use in generating RTL */
3110 arm_gen_load_multiple (base_regno, count, from, up, write_back, unchanging_p,
3111 in_struct_p, scalar_p)
3123 int sign = up ? 1 : -1;
3126 result = gen_rtx_PARALLEL (VOIDmode,
3127 rtvec_alloc (count + (write_back ? 2 : 0)));
3130 XVECEXP (result, 0, 0)
3131 = gen_rtx_SET (GET_MODE (from), from,
3132 plus_constant (from, count * 4 * sign));
3137 for (j = 0; i < count; i++, j++)
3139 mem = gen_rtx_MEM (SImode, plus_constant (from, j * 4 * sign));
3140 RTX_UNCHANGING_P (mem) = unchanging_p;
3141 MEM_IN_STRUCT_P (mem) = in_struct_p;
3142 MEM_SCALAR_P (mem) = scalar_p;
3143 XVECEXP (result, 0, i)
3144 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, base_regno + j), mem);
3148 XVECEXP (result, 0, i) = gen_rtx_CLOBBER (SImode, from);
3154 arm_gen_store_multiple (base_regno, count, to, up, write_back, unchanging_p,
3155 in_struct_p, scalar_p)
3167 int sign = up ? 1 : -1;
3170 result = gen_rtx_PARALLEL (VOIDmode,
3171 rtvec_alloc (count + (write_back ? 2 : 0)));
3174 XVECEXP (result, 0, 0)
3175 = gen_rtx_SET (GET_MODE (to), to,
3176 plus_constant (to, count * 4 * sign));
3181 for (j = 0; i < count; i++, j++)
3183 mem = gen_rtx_MEM (SImode, plus_constant (to, j * 4 * sign));
3184 RTX_UNCHANGING_P (mem) = unchanging_p;
3185 MEM_IN_STRUCT_P (mem) = in_struct_p;
3186 MEM_SCALAR_P (mem) = scalar_p;
3188 XVECEXP (result, 0, i)
3189 = gen_rtx_SET (VOIDmode, mem, gen_rtx_REG (SImode, base_regno + j));
3193 XVECEXP (result, 0, i) = gen_rtx_CLOBBER (SImode, to);
3199 arm_gen_movstrqi (operands)
3202 HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes;
3205 rtx st_src, st_dst, fin_src, fin_dst;
3206 rtx part_bytes_reg = NULL;
3208 int dst_unchanging_p, dst_in_struct_p, src_unchanging_p, src_in_struct_p;
3209 int dst_scalar_p, src_scalar_p;
3211 if (GET_CODE (operands[2]) != CONST_INT
3212 || GET_CODE (operands[3]) != CONST_INT
3213 || INTVAL (operands[2]) > 64
3214 || INTVAL (operands[3]) & 3)
3217 st_dst = XEXP (operands[0], 0);
3218 st_src = XEXP (operands[1], 0);
3220 dst_unchanging_p = RTX_UNCHANGING_P (operands[0]);
3221 dst_in_struct_p = MEM_IN_STRUCT_P (operands[0]);
3222 dst_scalar_p = MEM_SCALAR_P (operands[0]);
3223 src_unchanging_p = RTX_UNCHANGING_P (operands[1]);
3224 src_in_struct_p = MEM_IN_STRUCT_P (operands[1]);
3225 src_scalar_p = MEM_SCALAR_P (operands[1]);
3227 fin_dst = dst = copy_to_mode_reg (SImode, st_dst);
3228 fin_src = src = copy_to_mode_reg (SImode, st_src);
3230 in_words_to_go = (INTVAL (operands[2]) + 3) / 4;
3231 out_words_to_go = INTVAL (operands[2]) / 4;
3232 last_bytes = INTVAL (operands[2]) & 3;
3234 if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0)
3235 part_bytes_reg = gen_rtx_REG (SImode, (in_words_to_go - 1) & 3);
3237 for (i = 0; in_words_to_go >= 2; i+=4)
3239 if (in_words_to_go > 4)
3240 emit_insn (arm_gen_load_multiple (0, 4, src, TRUE, TRUE,
3245 emit_insn (arm_gen_load_multiple (0, in_words_to_go, src, TRUE,
3246 FALSE, src_unchanging_p,
3247 src_in_struct_p, src_scalar_p));
3249 if (out_words_to_go)
3251 if (out_words_to_go > 4)
3252 emit_insn (arm_gen_store_multiple (0, 4, dst, TRUE, TRUE,
3256 else if (out_words_to_go != 1)
3257 emit_insn (arm_gen_store_multiple (0, out_words_to_go,
3266 mem = gen_rtx_MEM (SImode, dst);
3267 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3268 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3269 MEM_SCALAR_P (mem) = dst_scalar_p;
3270 emit_move_insn (mem, gen_rtx_REG (SImode, 0));
3271 if (last_bytes != 0)
3272 emit_insn (gen_addsi3 (dst, dst, GEN_INT (4)));
3276 in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4;
3277 out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4;
3280 /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */
3281 if (out_words_to_go)
3285 mem = gen_rtx_MEM (SImode, src);
3286 RTX_UNCHANGING_P (mem) = src_unchanging_p;
3287 MEM_IN_STRUCT_P (mem) = src_in_struct_p;
3288 MEM_SCALAR_P (mem) = src_scalar_p;
3289 emit_move_insn (sreg = gen_reg_rtx (SImode), mem);
3290 emit_move_insn (fin_src = gen_reg_rtx (SImode), plus_constant (src, 4));
3292 mem = gen_rtx_MEM (SImode, dst);
3293 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3294 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3295 MEM_SCALAR_P (mem) = dst_scalar_p;
3296 emit_move_insn (mem, sreg);
3297 emit_move_insn (fin_dst = gen_reg_rtx (SImode), plus_constant (dst, 4));
3300 if (in_words_to_go) /* Sanity check */
3306 if (in_words_to_go < 0)
3309 mem = gen_rtx_MEM (SImode, src);
3310 RTX_UNCHANGING_P (mem) = src_unchanging_p;
3311 MEM_IN_STRUCT_P (mem) = src_in_struct_p;
3312 MEM_SCALAR_P (mem) = src_scalar_p;
3313 part_bytes_reg = copy_to_mode_reg (SImode, mem);
3316 if (BYTES_BIG_ENDIAN && last_bytes)
3318 rtx tmp = gen_reg_rtx (SImode);
3320 if (part_bytes_reg == NULL)
3323 /* The bytes we want are in the top end of the word */
3324 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg,
3325 GEN_INT (8 * (4 - last_bytes))));
3326 part_bytes_reg = tmp;
3330 mem = gen_rtx_MEM (QImode, plus_constant (dst, last_bytes - 1));
3331 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3332 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3333 MEM_SCALAR_P (mem) = dst_scalar_p;
3334 emit_move_insn (mem, gen_rtx_SUBREG (QImode, part_bytes_reg, 0));
3337 tmp = gen_reg_rtx (SImode);
3338 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
3339 part_bytes_reg = tmp;
3348 if (part_bytes_reg == NULL)
3351 mem = gen_rtx_MEM (QImode, dst);
3352 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3353 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3354 MEM_SCALAR_P (mem) = dst_scalar_p;
3355 emit_move_insn (mem, gen_rtx_SUBREG (QImode, part_bytes_reg, 0));
3358 rtx tmp = gen_reg_rtx (SImode);
3360 emit_insn (gen_addsi3 (dst, dst, const1_rtx));
3361 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
3362 part_bytes_reg = tmp;
3370 /* Generate a memory reference for a half word, such that it will be loaded
3371 into the top 16 bits of the word. We can assume that the address is
3372 known to be alignable and of the form reg, or plus (reg, const). */
3374 gen_rotated_half_load (memref)
3377 HOST_WIDE_INT offset = 0;
3378 rtx base = XEXP (memref, 0);
3380 if (GET_CODE (base) == PLUS)
3382 offset = INTVAL (XEXP (base, 1));
3383 base = XEXP (base, 0);
3386 /* If we aren't allowed to generate unaligned addresses, then fail. */
3387 if (TARGET_SHORT_BY_BYTES
3388 && ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 0)))
3391 base = gen_rtx_MEM (SImode, plus_constant (base, offset & ~2));
3393 if ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 2))
3396 return gen_rtx_ROTATE (SImode, base, GEN_INT (16));
3399 static enum machine_mode
3400 select_dominance_cc_mode (x, y, cond_or)
3403 HOST_WIDE_INT cond_or;
3405 enum rtx_code cond1, cond2;
3408 /* Currently we will probably get the wrong result if the individual
3409 comparisons are not simple. This also ensures that it is safe to
3410 reverse a comparison if necessary. */
3411 if ((arm_select_cc_mode (cond1 = GET_CODE (x), XEXP (x, 0), XEXP (x, 1))
3413 || (arm_select_cc_mode (cond2 = GET_CODE (y), XEXP (y, 0), XEXP (y, 1))
3418 cond1 = reverse_condition (cond1);
3420 /* If the comparisons are not equal, and one doesn't dominate the other,
3421 then we can't do this. */
3423 && ! comparison_dominates_p (cond1, cond2)
3424 && (swapped = 1, ! comparison_dominates_p (cond2, cond1)))
3429 enum rtx_code temp = cond1;
3437 if (cond2 == EQ || ! cond_or)
3442 case LE: return CC_DLEmode;
3443 case LEU: return CC_DLEUmode;
3444 case GE: return CC_DGEmode;
3445 case GEU: return CC_DGEUmode;
3452 if (cond2 == LT || ! cond_or)
3461 if (cond2 == GT || ! cond_or)
3470 if (cond2 == LTU || ! cond_or)
3479 if (cond2 == GTU || ! cond_or)
3487 /* The remaining cases only occur when both comparisons are the
3512 arm_select_cc_mode (op, x, y)
3517 /* All floating point compares return CCFP if it is an equality
3518 comparison, and CCFPE otherwise. */
3519 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
3520 return (op == EQ || op == NE) ? CCFPmode : CCFPEmode;
3522 /* A compare with a shifted operand. Because of canonicalization, the
3523 comparison will have to be swapped when we emit the assembler. */
3524 if (GET_MODE (y) == SImode && GET_CODE (y) == REG
3525 && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
3526 || GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ROTATE
3527 || GET_CODE (x) == ROTATERT))
3530 /* This is a special case that is used by combine to allow a
3531 comparison of a shifted byte load to be split into a zero-extend
3532 followed by a comparison of the shifted integer (only valid for
3533 equalities and unsigned inequalities). */
3534 if (GET_MODE (x) == SImode
3535 && GET_CODE (x) == ASHIFT
3536 && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 24
3537 && GET_CODE (XEXP (x, 0)) == SUBREG
3538 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == MEM
3539 && GET_MODE (SUBREG_REG (XEXP (x, 0))) == QImode
3540 && (op == EQ || op == NE
3541 || op == GEU || op == GTU || op == LTU || op == LEU)
3542 && GET_CODE (y) == CONST_INT)
3545 /* An operation that sets the condition codes as a side-effect, the
3546 V flag is not set correctly, so we can only use comparisons where
3547 this doesn't matter. (For LT and GE we can use "mi" and "pl"
3549 if (GET_MODE (x) == SImode
3551 && (op == EQ || op == NE || op == LT || op == GE)
3552 && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
3553 || GET_CODE (x) == AND || GET_CODE (x) == IOR
3554 || GET_CODE (x) == XOR || GET_CODE (x) == MULT
3555 || GET_CODE (x) == NOT || GET_CODE (x) == NEG
3556 || GET_CODE (x) == LSHIFTRT
3557 || GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
3558 || GET_CODE (x) == ROTATERT || GET_CODE (x) == ZERO_EXTRACT))
3561 /* A construct for a conditional compare, if the false arm contains
3562 0, then both conditions must be true, otherwise either condition
3563 must be true. Not all conditions are possible, so CCmode is
3564 returned if it can't be done. */
3565 if (GET_CODE (x) == IF_THEN_ELSE
3566 && (XEXP (x, 2) == const0_rtx
3567 || XEXP (x, 2) == const1_rtx)
3568 && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
3569 && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<')
3570 return select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1),
3571 INTVAL (XEXP (x, 2)));
3573 if (GET_MODE (x) == QImode && (op == EQ || op == NE))
3576 if (GET_MODE (x) == SImode && (op == LTU || op == GEU)
3577 && GET_CODE (x) == PLUS
3578 && (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y)))
3584 /* X and Y are two things to compare using CODE. Emit the compare insn and
3585 return the rtx for register 0 in the proper mode. FP means this is a
3586 floating point compare: I don't think that it is needed on the arm. */
3589 gen_compare_reg (code, x, y)
3593 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
3594 rtx cc_reg = gen_rtx_REG (mode, 24);
3596 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
3597 gen_rtx_COMPARE (mode, x, y)));
3603 arm_reload_in_hi (operands)
3606 rtx base = find_replacement (&XEXP (operands[1], 0));
3608 emit_insn (gen_zero_extendqisi2 (operands[2], gen_rtx_MEM (QImode, base)));
3609 /* Handle the case where the address is too complex to be offset by 1. */
3610 if (GET_CODE (base) == MINUS
3611 || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT))
3613 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[0]));
3615 emit_insn (gen_rtx_SET (VOIDmode, base_plus, base));
3619 emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode, operands[0], 0),
3620 gen_rtx_MEM (QImode,
3621 plus_constant (base, 1))));
3622 if (BYTES_BIG_ENDIAN)
3623 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], 0),
3624 gen_rtx_IOR (SImode,
3627 gen_rtx_SUBREG (SImode, operands[0], 0),
3631 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], 0),
3632 gen_rtx_IOR (SImode,
3633 gen_rtx_ASHIFT (SImode, operands[2],
3635 gen_rtx_SUBREG (SImode, operands[0],
3640 arm_reload_out_hi (operands)
3643 rtx base = find_replacement (&XEXP (operands[0], 0));
3645 if (BYTES_BIG_ENDIAN)
3647 emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, 1)),
3648 gen_rtx_SUBREG (QImode, operands[1], 0)));
3649 emit_insn (gen_lshrsi3 (operands[2],
3650 gen_rtx_SUBREG (SImode, operands[1], 0),
3652 emit_insn (gen_movqi (gen_rtx_MEM (QImode, base),
3653 gen_rtx_SUBREG (QImode, operands[2], 0)));
3657 emit_insn (gen_movqi (gen_rtx_MEM (QImode, base),
3658 gen_rtx_SUBREG (QImode, operands[1], 0)));
3659 emit_insn (gen_lshrsi3 (operands[2],
3660 gen_rtx_SUBREG (SImode, operands[1], 0),
3662 emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, 1)),
3663 gen_rtx_SUBREG (QImode, operands[2], 0)));
3667 /* Routines for manipulation of the constant pool. */
3668 /* This is unashamedly hacked from the version in sh.c, since the problem is
3669 extremely similar. */
3671 /* Arm instructions cannot load a large constant into a register,
3672 constants have to come from a pc relative load. The reference of a pc
3673 relative load instruction must be less than 1k infront of the instruction.
3674 This means that we often have to dump a constant inside a function, and
3675 generate code to branch around it.
3677 It is important to minimize this, since the branches will slow things
3678 down and make things bigger.
3680 Worst case code looks like:
3696 We fix this by performing a scan before scheduling, which notices which
3697 instructions need to have their operands fetched from the constant table
3698 and builds the table.
3703 scan, find an instruction which needs a pcrel move. Look forward, find th
3704 last barrier which is within MAX_COUNT bytes of the requirement.
3705 If there isn't one, make one. Process all the instructions between
3706 the find and the barrier.
3708 In the above example, we can tell that L3 is within 1k of L1, so
3709 the first move can be shrunk from the 2 insn+constant sequence into
3710 just 1 insn, and the constant moved to L3 to make:
3721 Then the second move becomes the target for the shortening process.
3727 rtx value; /* Value in table */
3728 HOST_WIDE_INT next_offset;
3729 enum machine_mode mode; /* Mode of value */
3732 /* The maximum number of constants that can fit into one pool, since
3733 the pc relative range is 0...1020 bytes and constants are at least 4
3736 #define MAX_POOL_SIZE (1020/4)
3737 static pool_node pool_vector[MAX_POOL_SIZE];
3738 static int pool_size;
3739 static rtx pool_vector_label;
3741 /* Add a constant to the pool and return its offset within the current
3744 X is the rtx we want to replace. MODE is its mode. On return,
3745 ADDRESS_ONLY will be non-zero if we really want the address of such
3746 a constant, not the constant itself. */
3747 static HOST_WIDE_INT
3748 add_constant (x, mode, address_only)
3750 enum machine_mode mode;
3754 HOST_WIDE_INT offset;
3758 if (mode == SImode && GET_CODE (x) == MEM && CONSTANT_P (XEXP (x, 0))
3759 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
3760 x = get_pool_constant (XEXP (x, 0));
3761 else if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P(x))
3764 mode = get_pool_mode (x);
3765 x = get_pool_constant (x);
3767 #ifndef AOF_ASSEMBLER
3768 else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == 3)
3769 x = XVECEXP (x, 0, 0);
3772 #ifdef AOF_ASSEMBLER
3773 /* PIC Symbol references need to be converted into offsets into the
3775 if (flag_pic && GET_CODE (x) == SYMBOL_REF)
3776 x = aof_pic_entry (x);
3777 #endif /* AOF_ASSEMBLER */
3779 /* First see if we've already got it */
3780 for (i = 0; i < pool_size; i++)
3782 if (GET_CODE (x) == pool_vector[i].value->code
3783 && mode == pool_vector[i].mode)
3785 if (GET_CODE (x) == CODE_LABEL)
3787 if (XINT (x, 3) != XINT (pool_vector[i].value, 3))
3790 if (rtx_equal_p (x, pool_vector[i].value))
3791 return pool_vector[i].next_offset - GET_MODE_SIZE (mode);
3795 /* Need a new one */
3796 pool_vector[pool_size].next_offset = GET_MODE_SIZE (mode);
3799 pool_vector_label = gen_label_rtx ();
3801 pool_vector[pool_size].next_offset
3802 += (offset = pool_vector[pool_size - 1].next_offset);
3804 pool_vector[pool_size].value = x;
3805 pool_vector[pool_size].mode = mode;
3810 /* Output the literal table */
3817 scan = emit_label_after (gen_label_rtx (), scan);
3818 scan = emit_insn_after (gen_align_4 (), scan);
3819 scan = emit_label_after (pool_vector_label, scan);
3821 for (i = 0; i < pool_size; i++)
3823 pool_node *p = pool_vector + i;
3825 switch (GET_MODE_SIZE (p->mode))
3828 scan = emit_insn_after (gen_consttable_4 (p->value), scan);
3832 scan = emit_insn_after (gen_consttable_8 (p->value), scan);
3841 scan = emit_insn_after (gen_consttable_end (), scan);
3842 scan = emit_barrier_after (scan);
3846 /* Non zero if the src operand needs to be fixed up */
3848 fixit (src, mode, destreg)
3850 enum machine_mode mode;
3853 if (CONSTANT_P (src))
3855 if (GET_CODE (src) == CONST_INT)
3856 return (! const_ok_for_arm (INTVAL (src))
3857 && ! const_ok_for_arm (~INTVAL (src)));
3858 if (GET_CODE (src) == CONST_DOUBLE)
3859 return (GET_MODE (src) == VOIDmode
3861 || (! const_double_rtx_ok_for_fpu (src)
3862 && ! neg_const_double_rtx_ok_for_fpu (src)));
3863 return symbol_mentioned_p (src);
3865 #ifndef AOF_ASSEMBLER
3866 else if (GET_CODE (src) == UNSPEC && XINT (src, 1) == 3)
3870 return (mode == SImode && GET_CODE (src) == MEM
3871 && GET_CODE (XEXP (src, 0)) == SYMBOL_REF
3872 && CONSTANT_POOL_ADDRESS_P (XEXP (src, 0)));
3875 /* Find the last barrier less than MAX_COUNT bytes from FROM, or create one. */
3877 find_barrier (from, max_count)
3882 rtx found_barrier = 0;
3885 while (from && count < max_count)
3889 if (GET_CODE (from) == BARRIER)
3890 found_barrier = from;
3892 /* Count the length of this insn */
3893 if (GET_CODE (from) == INSN
3894 && GET_CODE (PATTERN (from)) == SET
3895 && CONSTANT_P (SET_SRC (PATTERN (from)))
3896 && CONSTANT_POOL_ADDRESS_P (SET_SRC (PATTERN (from))))
3898 /* Handle table jumps as a single entity. */
3899 else if (GET_CODE (from) == JUMP_INSN
3900 && JUMP_LABEL (from) != 0
3901 && ((tmp = next_real_insn (JUMP_LABEL (from)))
3902 == next_real_insn (from))
3904 && GET_CODE (tmp) == JUMP_INSN
3905 && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
3906 || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
3908 int elt = GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC ? 1 : 0;
3909 count += (get_attr_length (from)
3910 + GET_MODE_SIZE (SImode) * XVECLEN (PATTERN (tmp), elt));
3911 /* Continue after the dispatch table. */
3913 from = NEXT_INSN (tmp);
3917 count += get_attr_length (from);
3920 from = NEXT_INSN (from);
3923 if (! found_barrier)
3925 /* We didn't find a barrier in time to
3926 dump our stuff, so we'll make one. */
3927 rtx label = gen_label_rtx ();
3930 from = PREV_INSN (last);
3932 from = get_last_insn ();
3934 /* Walk back to be just before any jump. */
3935 while (GET_CODE (from) == JUMP_INSN
3936 || GET_CODE (from) == NOTE
3937 || GET_CODE (from) == CODE_LABEL)
3938 from = PREV_INSN (from);
3940 from = emit_jump_insn_after (gen_jump (label), from);
3941 JUMP_LABEL (from) = label;
3942 found_barrier = emit_barrier_after (from);
3943 emit_label_after (label, found_barrier);
3946 return found_barrier;
3949 /* Non zero if the insn is a move instruction which needs to be fixed. */
3954 if (!INSN_DELETED_P (insn)
3955 && GET_CODE (insn) == INSN
3956 && GET_CODE (PATTERN (insn)) == SET)
3958 rtx pat = PATTERN (insn);
3959 rtx src = SET_SRC (pat);
3960 rtx dst = SET_DEST (pat);
3962 enum machine_mode mode = GET_MODE (dst);
3967 if (GET_CODE (dst) == REG)
3968 destreg = REGNO (dst);
3969 else if (GET_CODE (dst) == SUBREG && GET_CODE (SUBREG_REG (dst)) == REG)
3970 destreg = REGNO (SUBREG_REG (dst));
3974 return fixit (src, mode, destreg);
3987 /* The ldr instruction can work with up to a 4k offset, and most constants
3988 will be loaded with one of these instructions; however, the adr
3989 instruction and the ldf instructions only work with a 1k offset. This
3990 code needs to be rewritten to use the 4k offset when possible, and to
3991 adjust when a 1k offset is needed. For now we just use a 1k offset
3995 /* Floating point operands can't work further than 1024 bytes from the
3996 PC, so to make things simple we restrict all loads for such functions.
3998 if (TARGET_HARD_FLOAT)
4002 for (regno = 16; regno < 24; regno++)
4003 if (regs_ever_live[regno])
4013 for (insn = first; insn; insn = NEXT_INSN (insn))
4015 if (broken_move (insn))
4017 /* This is a broken move instruction, scan ahead looking for
4018 a barrier to stick the constant table behind */
4020 rtx barrier = find_barrier (insn, count_size);
4022 /* Now find all the moves between the points and modify them */
4023 for (scan = insn; scan != barrier; scan = NEXT_INSN (scan))
4025 if (broken_move (scan))
4027 /* This is a broken move instruction, add it to the pool */
4028 rtx pat = PATTERN (scan);
4029 rtx src = SET_SRC (pat);
4030 rtx dst = SET_DEST (pat);
4031 enum machine_mode mode = GET_MODE (dst);
4032 HOST_WIDE_INT offset;
4039 /* If this is an HImode constant load, convert it into
4040 an SImode constant load. Since the register is always
4041 32 bits this is safe. We have to do this, since the
4042 load pc-relative instruction only does a 32-bit load. */
4046 if (GET_CODE (dst) != REG)
4048 PUT_MODE (dst, SImode);
4051 offset = add_constant (src, mode, &address_only);
4052 addr = plus_constant (gen_rtx_LABEL_REF (VOIDmode,
4056 /* If we only want the address of the pool entry, or
4057 for wide moves to integer regs we need to split
4058 the address calculation off into a separate insn.
4059 If necessary, the load can then be done with a
4060 load-multiple. This is safe, since we have
4061 already noted the length of such insns to be 8,
4062 and we are immediately over-writing the scratch
4063 we have grabbed with the final result. */
4064 if ((address_only || GET_MODE_SIZE (mode) > 4)
4065 && (scratch = REGNO (dst)) < 16)
4072 reg = gen_rtx_REG (SImode, scratch);
4074 newinsn = emit_insn_after (gen_movaddr (reg, addr),
4081 newsrc = gen_rtx_MEM (mode, addr);
4083 /* XXX Fixme -- I think the following is bogus. */
4084 /* Build a jump insn wrapper around the move instead
4085 of an ordinary insn, because we want to have room for
4086 the target label rtx in fld[7], which an ordinary
4087 insn doesn't have. */
4089 = emit_jump_insn_after (gen_rtx_SET (VOIDmode, dst,
4092 JUMP_LABEL (newinsn) = pool_vector_label;
4094 /* But it's still an ordinary insn */
4095 PUT_CODE (newinsn, INSN);
4103 dump_table (barrier);
4108 after_arm_reorg = 1;
4112 /* Routines to output assembly language. */
4114 /* If the rtx is the correct value then return the string of the number.
4115 In this way we can ensure that valid double constants are generated even
4116 when cross compiling. */
4118 fp_immediate_constant (x)
4124 if (!fpa_consts_inited)
4127 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
4128 for (i = 0; i < 8; i++)
4129 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
4130 return strings_fpa[i];
4135 /* As for fp_immediate_constant, but value is passed directly, not in rtx. */
4137 fp_const_from_val (r)
4142 if (! fpa_consts_inited)
4145 for (i = 0; i < 8; i++)
4146 if (REAL_VALUES_EQUAL (*r, values_fpa[i]))
4147 return strings_fpa[i];
4152 /* Output the operands of a LDM/STM instruction to STREAM.
4153 MASK is the ARM register set mask of which only bits 0-15 are important.
4154 INSTR is the possibly suffixed base register. HAT unequals zero if a hat
4155 must follow the register list. */
4158 print_multi_reg (stream, instr, mask, hat)
4164 int not_first = FALSE;
4166 fputc ('\t', stream);
4167 fprintf (stream, instr, REGISTER_PREFIX);
4168 fputs (", {", stream);
4169 for (i = 0; i < 16; i++)
4170 if (mask & (1 << i))
4173 fprintf (stream, ", ");
4174 fprintf (stream, "%s%s", REGISTER_PREFIX, reg_names[i]);
4178 fprintf (stream, "}%s\n", hat ? "^" : "");
4181 /* Output a 'call' insn. */
4184 output_call (operands)
4187 /* Handle calls to lr using ip (which may be clobbered in subr anyway). */
4189 if (REGNO (operands[0]) == 14)
4191 operands[0] = gen_rtx_REG (SImode, 12);
4192 output_asm_insn ("mov%?\t%0, %|lr", operands);
4194 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
4196 if (TARGET_THUMB_INTERWORK)
4197 output_asm_insn ("bx%?\t%0", operands);
4199 output_asm_insn ("mov%?\t%|pc, %0", operands);
4208 int something_changed = 0;
4210 int code = GET_CODE (x0);
4217 if (REGNO (x0) == 14)
4219 *x = gen_rtx_REG (SImode, 12);
4224 /* Scan through the sub-elements and change any references there */
4225 fmt = GET_RTX_FORMAT (code);
4226 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4228 something_changed |= eliminate_lr2ip (&XEXP (x0, i));
4229 else if (fmt[i] == 'E')
4230 for (j = 0; j < XVECLEN (x0, i); j++)
4231 something_changed |= eliminate_lr2ip (&XVECEXP (x0, i, j));
4232 return something_changed;
4236 /* Output a 'call' insn that is a reference in memory. */
4239 output_call_mem (operands)
4242 operands[0] = copy_rtx (operands[0]); /* Be ultra careful */
4243 /* Handle calls using lr by using ip (which may be clobbered in subr anyway).
4245 if (eliminate_lr2ip (&operands[0]))
4246 output_asm_insn ("mov%?\t%|ip, %|lr", operands);
4248 if (TARGET_THUMB_INTERWORK)
4250 output_asm_insn ("ldr%?\t%|ip, %0", operands);
4251 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
4252 output_asm_insn ("bx%?\t%|ip", operands);
4256 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
4257 output_asm_insn ("ldr%?\t%|pc, %0", operands);
4264 /* Output a move from arm registers to an fpu registers.
4265 OPERANDS[0] is an fpu register.
4266 OPERANDS[1] is the first registers of an arm register pair. */
4269 output_mov_long_double_fpu_from_arm (operands)
4272 int arm_reg0 = REGNO (operands[1]);
4278 ops[0] = gen_rtx_REG (SImode, arm_reg0);
4279 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
4280 ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0);
4282 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1, %2}", ops);
4283 output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands);
4287 /* Output a move from an fpu register to arm registers.
4288 OPERANDS[0] is the first registers of an arm register pair.
4289 OPERANDS[1] is an fpu register. */
4292 output_mov_long_double_arm_from_fpu (operands)
4295 int arm_reg0 = REGNO (operands[0]);
4301 ops[0] = gen_rtx_REG (SImode, arm_reg0);
4302 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
4303 ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0);
4305 output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands);
4306 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1, %2}", ops);
4310 /* Output a move from arm registers to arm registers of a long double
4311 OPERANDS[0] is the destination.
4312 OPERANDS[1] is the source. */
4314 output_mov_long_double_arm_from_arm (operands)
4317 /* We have to be careful here because the two might overlap */
4318 int dest_start = REGNO (operands[0]);
4319 int src_start = REGNO (operands[1]);
4323 if (dest_start < src_start)
4325 for (i = 0; i < 3; i++)
4327 ops[0] = gen_rtx_REG (SImode, dest_start + i);
4328 ops[1] = gen_rtx_REG (SImode, src_start + i);
4329 output_asm_insn ("mov%?\t%0, %1", ops);
4334 for (i = 2; i >= 0; i--)
4336 ops[0] = gen_rtx_REG (SImode, dest_start + i);
4337 ops[1] = gen_rtx_REG (SImode, src_start + i);
4338 output_asm_insn ("mov%?\t%0, %1", ops);
4346 /* Output a move from arm registers to an fpu registers.
4347 OPERANDS[0] is an fpu register.
4348 OPERANDS[1] is the first registers of an arm register pair. */
4351 output_mov_double_fpu_from_arm (operands)
4354 int arm_reg0 = REGNO (operands[1]);
4359 ops[0] = gen_rtx_REG (SImode, arm_reg0);
4360 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
4361 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1}", ops);
4362 output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands);
4366 /* Output a move from an fpu register to arm registers.
4367 OPERANDS[0] is the first registers of an arm register pair.
4368 OPERANDS[1] is an fpu register. */
4371 output_mov_double_arm_from_fpu (operands)
4374 int arm_reg0 = REGNO (operands[0]);
4380 ops[0] = gen_rtx_REG (SImode, arm_reg0);
4381 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
4382 output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands);
4383 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1}", ops);
4387 /* Output a move between double words.
4388 It must be REG<-REG, REG<-CONST_DOUBLE, REG<-CONST_INT, REG<-MEM
4389 or MEM<-REG and all MEMs must be offsettable addresses. */
4392 output_move_double (operands)
4395 enum rtx_code code0 = GET_CODE (operands[0]);
4396 enum rtx_code code1 = GET_CODE (operands[1]);
4401 int reg0 = REGNO (operands[0]);
4403 otherops[0] = gen_rtx_REG (SImode, 1 + reg0);
4407 int reg1 = REGNO (operands[1]);
4411 /* Ensure the second source is not overwritten */
4412 if (reg1 == reg0 + (WORDS_BIG_ENDIAN ? -1 : 1))
4413 output_asm_insn("mov%?\t%Q0, %Q1\n\tmov%?\t%R0, %R1", operands);
4415 output_asm_insn("mov%?\t%R0, %R1\n\tmov%?\t%Q0, %Q1", operands);
4417 else if (code1 == CONST_DOUBLE)
4419 if (GET_MODE (operands[1]) == DFmode)
4422 union real_extract u;
4424 bcopy ((char *) &CONST_DOUBLE_LOW (operands[1]), (char *) &u,
4426 REAL_VALUE_TO_TARGET_DOUBLE (u.d, l);
4427 otherops[1] = GEN_INT(l[1]);
4428 operands[1] = GEN_INT(l[0]);
4430 else if (GET_MODE (operands[1]) != VOIDmode)
4432 else if (WORDS_BIG_ENDIAN)
4435 otherops[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
4436 operands[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
4441 otherops[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
4442 operands[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
4444 output_mov_immediate (operands);
4445 output_mov_immediate (otherops);
4447 else if (code1 == CONST_INT)
4449 #if HOST_BITS_PER_WIDE_INT > 32
4450 /* If HOST_WIDE_INT is more than 32 bits, the intval tells us
4451 what the upper word is. */
4452 if (WORDS_BIG_ENDIAN)
4454 otherops[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1])));
4455 operands[1] = GEN_INT (INTVAL (operands[1]) >> 32);
4459 otherops[1] = GEN_INT (INTVAL (operands[1]) >> 32);
4460 operands[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1])));
4463 /* Sign extend the intval into the high-order word */
4464 if (WORDS_BIG_ENDIAN)
4466 otherops[1] = operands[1];
4467 operands[1] = (INTVAL (operands[1]) < 0
4468 ? constm1_rtx : const0_rtx);
4471 otherops[1] = INTVAL (operands[1]) < 0 ? constm1_rtx : const0_rtx;
4473 output_mov_immediate (otherops);
4474 output_mov_immediate (operands);
4476 else if (code1 == MEM)
4478 switch (GET_CODE (XEXP (operands[1], 0)))
4481 output_asm_insn ("ldm%?ia\t%m1, %M0", operands);
4485 abort (); /* Should never happen now */
4489 output_asm_insn ("ldm%?db\t%m1!, %M0", operands);
4493 output_asm_insn ("ldm%?ia\t%m1!, %M0", operands);
4497 abort (); /* Should never happen now */
4502 output_asm_insn ("adr%?\t%0, %1", operands);
4503 output_asm_insn ("ldm%?ia\t%0, %M0", operands);
4507 if (arm_add_operand (XEXP (XEXP (operands[1], 0), 1),
4508 GET_MODE (XEXP (XEXP (operands[1], 0), 1))))
4510 otherops[0] = operands[0];
4511 otherops[1] = XEXP (XEXP (operands[1], 0), 0);
4512 otherops[2] = XEXP (XEXP (operands[1], 0), 1);
4513 if (GET_CODE (XEXP (operands[1], 0)) == PLUS)
4515 if (GET_CODE (otherops[2]) == CONST_INT)
4517 switch (INTVAL (otherops[2]))
4520 output_asm_insn ("ldm%?db\t%1, %M0", otherops);
4523 output_asm_insn ("ldm%?da\t%1, %M0", otherops);
4526 output_asm_insn ("ldm%?ib\t%1, %M0", otherops);
4529 if (!(const_ok_for_arm (INTVAL (otherops[2]))))
4530 output_asm_insn ("sub%?\t%0, %1, #%n2", otherops);
4532 output_asm_insn ("add%?\t%0, %1, %2", otherops);
4535 output_asm_insn ("add%?\t%0, %1, %2", otherops);
4538 output_asm_insn ("sub%?\t%0, %1, %2", otherops);
4539 return "ldm%?ia\t%0, %M0";
4543 otherops[1] = adj_offsettable_operand (operands[1], 4);
4544 /* Take care of overlapping base/data reg. */
4545 if (reg_mentioned_p (operands[0], operands[1]))
4547 output_asm_insn ("ldr%?\t%0, %1", otherops);
4548 output_asm_insn ("ldr%?\t%0, %1", operands);
4552 output_asm_insn ("ldr%?\t%0, %1", operands);
4553 output_asm_insn ("ldr%?\t%0, %1", otherops);
4559 abort(); /* Constraints should prevent this */
4561 else if (code0 == MEM && code1 == REG)
4563 if (REGNO (operands[1]) == 12)
4566 switch (GET_CODE (XEXP (operands[0], 0)))
4569 output_asm_insn ("stm%?ia\t%m0, %M1", operands);
4573 abort (); /* Should never happen now */
4577 output_asm_insn ("stm%?db\t%m0!, %M1", operands);
4581 output_asm_insn ("stm%?ia\t%m0!, %M1", operands);
4585 abort (); /* Should never happen now */
4589 if (GET_CODE (XEXP (XEXP (operands[0], 0), 1)) == CONST_INT)
4591 switch (INTVAL (XEXP (XEXP (operands[0], 0), 1)))
4594 output_asm_insn ("stm%?db\t%m0, %M1", operands);
4598 output_asm_insn ("stm%?da\t%m0, %M1", operands);
4602 output_asm_insn ("stm%?ib\t%m0, %M1", operands);
4609 otherops[0] = adj_offsettable_operand (operands[0], 4);
4610 otherops[1] = gen_rtx_REG (SImode, 1 + REGNO (operands[1]));
4611 output_asm_insn ("str%?\t%1, %0", operands);
4612 output_asm_insn ("str%?\t%1, %0", otherops);
4616 abort(); /* Constraints should prevent this */
4622 /* Output an arbitrary MOV reg, #n.
4623 OPERANDS[0] is a register. OPERANDS[1] is a const_int. */
4626 output_mov_immediate (operands)
4629 HOST_WIDE_INT n = INTVAL (operands[1]);
4633 /* Try to use one MOV */
4634 if (const_ok_for_arm (n))
4636 output_asm_insn ("mov%?\t%0, %1", operands);
4640 /* Try to use one MVN */
4641 if (const_ok_for_arm (~n))
4643 operands[1] = GEN_INT (~n);
4644 output_asm_insn ("mvn%?\t%0, %1", operands);
4648 /* If all else fails, make it out of ORRs or BICs as appropriate. */
4650 for (i=0; i < 32; i++)
4654 if (n_ones > 16) /* Shorter to use MVN with BIC in this case. */
4655 output_multi_immediate(operands, "mvn%?\t%0, %1", "bic%?\t%0, %0, %1", 1,
4658 output_multi_immediate(operands, "mov%?\t%0, %1", "orr%?\t%0, %0, %1", 1,
4665 /* Output an ADD r, s, #n where n may be too big for one instruction. If
4666 adding zero to one register, output nothing. */
4669 output_add_immediate (operands)
4672 HOST_WIDE_INT n = INTVAL (operands[2]);
4674 if (n != 0 || REGNO (operands[0]) != REGNO (operands[1]))
4677 output_multi_immediate (operands,
4678 "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2,
4681 output_multi_immediate (operands,
4682 "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2,
4689 /* Output a multiple immediate operation.
4690 OPERANDS is the vector of operands referred to in the output patterns.
4691 INSTR1 is the output pattern to use for the first constant.
4692 INSTR2 is the output pattern to use for subsequent constants.
4693 IMMED_OP is the index of the constant slot in OPERANDS.
4694 N is the constant value. */
4697 output_multi_immediate (operands, instr1, instr2, immed_op, n)
4699 char *instr1, *instr2;
4703 #if HOST_BITS_PER_WIDE_INT > 32
4709 operands[immed_op] = const0_rtx;
4710 output_asm_insn (instr1, operands); /* Quick and easy output */
4715 char *instr = instr1;
4717 /* Note that n is never zero here (which would give no output) */
4718 for (i = 0; i < 32; i += 2)
4722 operands[immed_op] = GEN_INT (n & (255 << i));
4723 output_asm_insn (instr, operands);
4733 /* Return the appropriate ARM instruction for the operation code.
4734 The returned result should not be overwritten. OP is the rtx of the
4735 operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator
4739 arithmetic_instr (op, shift_first_arg)
4741 int shift_first_arg;
4743 switch (GET_CODE (op))
4749 return shift_first_arg ? "rsb" : "sub";
4766 /* Ensure valid constant shifts and return the appropriate shift mnemonic
4767 for the operation code. The returned result should not be overwritten.
4768 OP is the rtx code of the shift.
4769 On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant
4773 shift_op (op, amountp)
4775 HOST_WIDE_INT *amountp;
4778 enum rtx_code code = GET_CODE (op);
4780 if (GET_CODE (XEXP (op, 1)) == REG || GET_CODE (XEXP (op, 1)) == SUBREG)
4782 else if (GET_CODE (XEXP (op, 1)) == CONST_INT)
4783 *amountp = INTVAL (XEXP (op, 1));
4806 /* We never have to worry about the amount being other than a
4807 power of 2, since this case can never be reloaded from a reg. */
4809 *amountp = int_log2 (*amountp);
4820 /* This is not 100% correct, but follows from the desire to merge
4821 multiplication by a power of 2 with the recognizer for a
4822 shift. >=32 is not a valid shift for "asl", so we must try and
4823 output a shift that produces the correct arithmetical result.
4824 Using lsr #32 is identical except for the fact that the carry bit
4825 is not set correctly if we set the flags; but we never use the
4826 carry bit from such an operation, so we can ignore that. */
4827 if (code == ROTATERT)
4828 *amountp &= 31; /* Rotate is just modulo 32 */
4829 else if (*amountp != (*amountp & 31))
4836 /* Shifts of 0 are no-ops. */
4845 /* Obtain the shift from the POWER of two. */
4847 static HOST_WIDE_INT
4849 HOST_WIDE_INT power;
4851 HOST_WIDE_INT shift = 0;
4853 while (((((HOST_WIDE_INT) 1) << shift) & power) == 0)
4863 /* Output a .ascii pseudo-op, keeping track of lengths. This is because
4864 /bin/as is horribly restrictive. */
4867 output_ascii_pseudo_op (stream, p, len)
4873 int len_so_far = 1000;
4874 int chars_so_far = 0;
4876 for (i = 0; i < len; i++)
4878 register int c = p[i];
4880 if (len_so_far > 50)
4883 fputs ("\"\n", stream);
4884 fputs ("\t.ascii\t\"", stream);
4889 if (c == '\"' || c == '\\')
4895 if (c >= ' ' && c < 0177)
4902 fprintf (stream, "\\%03o", c);
4909 fputs ("\"\n", stream);
4913 /* Try to determine whether a pattern really clobbers the link register.
4914 This information is useful when peepholing, so that lr need not be pushed
4915 if we combine a call followed by a return.
4916 NOTE: This code does not check for side-effect expressions in a SET_SRC:
4917 such a check should not be needed because these only update an existing
4918 value within a register; the register must still be set elsewhere within
4922 pattern_really_clobbers_lr (x)
4927 switch (GET_CODE (x))
4930 switch (GET_CODE (SET_DEST (x)))
4933 return REGNO (SET_DEST (x)) == 14;
4936 if (GET_CODE (XEXP (SET_DEST (x), 0)) == REG)
4937 return REGNO (XEXP (SET_DEST (x), 0)) == 14;
4939 if (GET_CODE (XEXP (SET_DEST (x), 0)) == MEM)
4948 for (i = 0; i < XVECLEN (x, 0); i++)
4949 if (pattern_really_clobbers_lr (XVECEXP (x, 0, i)))
4954 switch (GET_CODE (XEXP (x, 0)))
4957 return REGNO (XEXP (x, 0)) == 14;
4960 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG)
4961 return REGNO (XEXP (XEXP (x, 0), 0)) == 14;
4977 function_really_clobbers_lr (first)
4982 for (insn = first; insn; insn = next_nonnote_insn (insn))
4984 switch (GET_CODE (insn))
4989 case JUMP_INSN: /* Jump insns only change the PC (and conds) */
4994 if (pattern_really_clobbers_lr (PATTERN (insn)))
4999 /* Don't yet know how to handle those calls that are not to a
5001 if (GET_CODE (PATTERN (insn)) != PARALLEL)
5004 switch (GET_CODE (XVECEXP (PATTERN (insn), 0, 0)))
5007 if (GET_CODE (XEXP (XEXP (XVECEXP (PATTERN (insn), 0, 0), 0), 0))
5013 if (GET_CODE (XEXP (XEXP (SET_SRC (XVECEXP (PATTERN (insn),
5019 default: /* Don't recognize it, be safe */
5023 /* A call can be made (by peepholing) not to clobber lr iff it is
5024 followed by a return. There may, however, be a use insn iff
5025 we are returning the result of the call.
5026 If we run off the end of the insn chain, then that means the
5027 call was at the end of the function. Unfortunately we don't
5028 have a return insn for the peephole to recognize, so we
5029 must reject this. (Can this be fixed by adding our own insn?) */
5030 if ((next = next_nonnote_insn (insn)) == NULL)
5033 /* No need to worry about lr if the call never returns */
5034 if (GET_CODE (next) == BARRIER)
5037 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == USE
5038 && (GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
5039 && (REGNO (SET_DEST (XVECEXP (PATTERN (insn), 0, 0)))
5040 == REGNO (XEXP (PATTERN (next), 0))))
5041 if ((next = next_nonnote_insn (next)) == NULL)
5044 if (GET_CODE (next) == JUMP_INSN
5045 && GET_CODE (PATTERN (next)) == RETURN)
5054 /* We have reached the end of the chain so lr was _not_ clobbered */
5059 output_return_instruction (operand, really_return, reverse)
5065 int reg, live_regs = 0;
5066 int volatile_func = (optimize > 0
5067 && TREE_THIS_VOLATILE (current_function_decl));
5069 return_used_this_function = 1;
5074 /* If this function was declared non-returning, and we have found a tail
5075 call, then we have to trust that the called function won't return. */
5076 if (! really_return)
5079 /* Otherwise, trap an attempted return by aborting. */
5081 ops[1] = gen_rtx_SYMBOL_REF (Pmode, "abort");
5082 assemble_external_libcall (ops[1]);
5083 output_asm_insn (reverse ? "bl%D0\t%a1" : "bl%d0\t%a1", ops);
5087 if (current_function_calls_alloca && ! really_return)
5090 for (reg = 0; reg <= 10; reg++)
5091 if (regs_ever_live[reg] && ! call_used_regs[reg])
5094 if (live_regs || (regs_ever_live[14] && ! lr_save_eliminated))
5097 if (frame_pointer_needed)
5102 if (lr_save_eliminated || ! regs_ever_live[14])
5105 if (frame_pointer_needed)
5107 reverse ? "ldm%?%D0ea\t%|fp, {" : "ldm%?%d0ea\t%|fp, {");
5110 reverse ? "ldm%?%D0fd\t%|sp!, {" : "ldm%?%d0fd\t%|sp!, {");
5112 for (reg = 0; reg <= 10; reg++)
5113 if (regs_ever_live[reg] && ! call_used_regs[reg])
5115 strcat (instr, "%|");
5116 strcat (instr, reg_names[reg]);
5118 strcat (instr, ", ");
5121 if (frame_pointer_needed)
5123 strcat (instr, "%|");
5124 strcat (instr, reg_names[11]);
5125 strcat (instr, ", ");
5126 strcat (instr, "%|");
5127 strcat (instr, reg_names[13]);
5128 strcat (instr, ", ");
5129 strcat (instr, "%|");
5130 strcat (instr, TARGET_THUMB_INTERWORK || (! really_return)
5131 ? reg_names[14] : reg_names[15] );
5135 strcat (instr, "%|");
5136 if (TARGET_THUMB_INTERWORK && really_return)
5137 strcat (instr, reg_names[12]);
5139 strcat (instr, really_return ? reg_names[15] : reg_names[14]);
5141 strcat (instr, (TARGET_APCS_32 || !really_return) ? "}" : "}^");
5142 output_asm_insn (instr, &operand);
5144 if (TARGET_THUMB_INTERWORK && really_return)
5146 strcpy (instr, "bx%?");
5147 strcat (instr, reverse ? "%D0" : "%d0");
5148 strcat (instr, "\t%|");
5149 strcat (instr, frame_pointer_needed ? "lr" : "ip");
5151 output_asm_insn (instr, & operand);
5154 else if (really_return)
5156 if (TARGET_THUMB_INTERWORK)
5157 sprintf (instr, "bx%%?%%%s0\t%%|lr", reverse ? "D" : "d");
5159 sprintf (instr, "mov%%?%%%s0%s\t%%|pc, %%|lr",
5160 reverse ? "D" : "d", TARGET_APCS_32 ? "" : "s");
5162 output_asm_insn (instr, & operand);
5168 /* Return nonzero if optimizing and the current function is volatile.
5169 Such functions never return, and many memory cycles can be saved
5170 by not storing register values that will never be needed again.
5171 This optimization was added to speed up context switching in a
5172 kernel application. */
5175 arm_volatile_func ()
5177 return (optimize > 0 && TREE_THIS_VOLATILE (current_function_decl));
5180 /* The amount of stack adjustment that happens here, in output_return and in
5181 output_epilogue must be exactly the same as was calculated during reload,
5182 or things will point to the wrong place. The only time we can safely
5183 ignore this constraint is when a function has no arguments on the stack,
5184 no stack frame requirement and no live registers execpt for `lr'. If we
5185 can guarantee that by making all function calls into tail calls and that
5186 lr is not clobbered in any other way, then there is no need to push lr
5190 output_func_prologue (f, frame_size)
5194 int reg, live_regs_mask = 0;
5195 int volatile_func = (optimize > 0
5196 && TREE_THIS_VOLATILE (current_function_decl));
5198 /* Nonzero if we must stuff some register arguments onto the stack as if
5199 they were passed there. */
5200 int store_arg_regs = 0;
5202 if (arm_ccfsm_state || arm_target_insn)
5203 abort (); /* Sanity check */
5205 if (arm_naked_function_p (current_function_decl))
5208 return_used_this_function = 0;
5209 lr_save_eliminated = 0;
5211 fprintf (f, "\t%s args = %d, pretend = %d, frame = %d\n",
5212 ASM_COMMENT_START, current_function_args_size,
5213 current_function_pretend_args_size, frame_size);
5214 fprintf (f, "\t%s frame_needed = %d, current_function_anonymous_args = %d\n",
5215 ASM_COMMENT_START, frame_pointer_needed,
5216 current_function_anonymous_args);
5219 fprintf (f, "\t%s Volatile function.\n", ASM_COMMENT_START);
5221 if (current_function_anonymous_args && current_function_pretend_args_size)
5224 for (reg = 0; reg <= 10; reg++)
5225 if (regs_ever_live[reg] && ! call_used_regs[reg])
5226 live_regs_mask |= (1 << reg);
5228 if (frame_pointer_needed)
5229 live_regs_mask |= 0xD800;
5230 else if (regs_ever_live[14])
5232 if (! current_function_args_size
5233 && ! function_really_clobbers_lr (get_insns ()))
5234 lr_save_eliminated = 1;
5236 live_regs_mask |= 0x4000;
5241 /* if a di mode load/store multiple is used, and the base register
5242 is r3, then r4 can become an ever live register without lr
5243 doing so, in this case we need to push lr as well, or we
5244 will fail to get a proper return. */
5246 live_regs_mask |= 0x4000;
5247 lr_save_eliminated = 0;
5251 if (lr_save_eliminated)
5252 fprintf (f,"\t%s I don't think this function clobbers lr\n",
5255 #ifdef AOF_ASSEMBLER
5257 fprintf (f, "\tmov\t%sip, %s%s\n", REGISTER_PREFIX, REGISTER_PREFIX,
5258 reg_names[PIC_OFFSET_TABLE_REGNUM]);
5264 output_func_epilogue (f, frame_size)
5268 int reg, live_regs_mask = 0;
5269 /* If we need this then it will always be at least this much */
5270 int floats_offset = 12;
5272 int volatile_func = (optimize > 0
5273 && TREE_THIS_VOLATILE (current_function_decl));
5275 if (use_return_insn (FALSE) && return_used_this_function)
5277 if ((frame_size + current_function_outgoing_args_size) != 0
5278 && !(frame_pointer_needed && TARGET_APCS))
5283 /* Naked functions don't have epilogues. */
5284 if (arm_naked_function_p (current_function_decl))
5287 /* A volatile function should never return. Call abort. */
5288 if (TARGET_ABORT_NORETURN && volatile_func)
5290 rtx op = gen_rtx_SYMBOL_REF (Pmode, "abort");
5291 assemble_external_libcall (op);
5292 output_asm_insn ("bl\t%a0", &op);
5296 for (reg = 0; reg <= 10; reg++)
5297 if (regs_ever_live[reg] && ! call_used_regs[reg])
5299 live_regs_mask |= (1 << reg);
5303 if (frame_pointer_needed)
5305 if (arm_fpu_arch == FP_SOFT2)
5307 for (reg = 23; reg > 15; reg--)
5308 if (regs_ever_live[reg] && ! call_used_regs[reg])
5310 floats_offset += 12;
5311 fprintf (f, "\tldfe\t%s%s, [%sfp, #-%d]\n", REGISTER_PREFIX,
5312 reg_names[reg], REGISTER_PREFIX, floats_offset);
5319 for (reg = 23; reg > 15; reg--)
5321 if (regs_ever_live[reg] && ! call_used_regs[reg])
5323 floats_offset += 12;
5324 /* We can't unstack more than four registers at once */
5325 if (start_reg - reg == 3)
5327 fprintf (f, "\tlfm\t%s%s, 4, [%sfp, #-%d]\n",
5328 REGISTER_PREFIX, reg_names[reg],
5329 REGISTER_PREFIX, floats_offset);
5330 start_reg = reg - 1;
5335 if (reg != start_reg)
5336 fprintf (f, "\tlfm\t%s%s, %d, [%sfp, #-%d]\n",
5337 REGISTER_PREFIX, reg_names[reg + 1],
5338 start_reg - reg, REGISTER_PREFIX, floats_offset);
5340 start_reg = reg - 1;
5344 /* Just in case the last register checked also needs unstacking. */
5345 if (reg != start_reg)
5346 fprintf (f, "\tlfm\t%s%s, %d, [%sfp, #-%d]\n",
5347 REGISTER_PREFIX, reg_names[reg + 1],
5348 start_reg - reg, REGISTER_PREFIX, floats_offset);
5351 if (TARGET_THUMB_INTERWORK)
5353 live_regs_mask |= 0x6800;
5354 print_multi_reg (f, "ldmea\t%sfp", live_regs_mask, FALSE);
5355 fprintf (f, "\tbx\t%slr\n", REGISTER_PREFIX);
5359 live_regs_mask |= 0xA800;
5360 print_multi_reg (f, "ldmea\t%sfp", live_regs_mask,
5361 TARGET_APCS_32 ? FALSE : TRUE);
5366 /* Restore stack pointer if necessary. */
5367 if (frame_size + current_function_outgoing_args_size != 0)
5369 operands[0] = operands[1] = stack_pointer_rtx;
5370 operands[2] = GEN_INT (frame_size
5371 + current_function_outgoing_args_size);
5372 output_add_immediate (operands);
5375 if (arm_fpu_arch == FP_SOFT2)
5377 for (reg = 16; reg < 24; reg++)
5378 if (regs_ever_live[reg] && ! call_used_regs[reg])
5379 fprintf (f, "\tldfe\t%s%s, [%ssp], #12\n", REGISTER_PREFIX,
5380 reg_names[reg], REGISTER_PREFIX);
5386 for (reg = 16; reg < 24; reg++)
5388 if (regs_ever_live[reg] && ! call_used_regs[reg])
5390 if (reg - start_reg == 3)
5392 fprintf (f, "\tlfmfd\t%s%s, 4, [%ssp]!\n",
5393 REGISTER_PREFIX, reg_names[start_reg],
5395 start_reg = reg + 1;
5400 if (reg != start_reg)
5401 fprintf (f, "\tlfmfd\t%s%s, %d, [%ssp]!\n",
5402 REGISTER_PREFIX, reg_names[start_reg],
5403 reg - start_reg, REGISTER_PREFIX);
5405 start_reg = reg + 1;
5409 /* Just in case the last register checked also needs unstacking. */
5410 if (reg != start_reg)
5411 fprintf (f, "\tlfmfd\t%s%s, %d, [%ssp]!\n",
5412 REGISTER_PREFIX, reg_names[start_reg],
5413 reg - start_reg, REGISTER_PREFIX);
5416 if (current_function_pretend_args_size == 0 && regs_ever_live[14])
5418 if (TARGET_THUMB_INTERWORK)
5420 if (! lr_save_eliminated)
5421 live_regs_mask |= 0x4000;
5423 if (live_regs_mask != 0)
5424 print_multi_reg (f, "ldmfd\t%ssp!", live_regs_mask, FALSE);
5426 fprintf (f, "\tbx\t%slr\n", REGISTER_PREFIX);
5428 else if (lr_save_eliminated)
5429 fprintf (f, (TARGET_APCS_32 ? "\tmov\t%spc, %slr\n"
5430 : "\tmovs\t%spc, %slr\n"),
5431 REGISTER_PREFIX, REGISTER_PREFIX, f);
5433 print_multi_reg (f, "ldmfd\t%ssp!", live_regs_mask | 0x8000,
5434 TARGET_APCS_32 ? FALSE : TRUE);
5438 if (live_regs_mask || regs_ever_live[14])
5440 /* Restore the integer regs, and the return address into lr */
5441 if (! lr_save_eliminated)
5442 live_regs_mask |= 0x4000;
5444 if (live_regs_mask != 0)
5445 print_multi_reg (f, "ldmfd\t%ssp!", live_regs_mask, FALSE);
5448 if (current_function_pretend_args_size)
5450 /* Unwind the pre-pushed regs */
5451 operands[0] = operands[1] = stack_pointer_rtx;
5452 operands[2] = GEN_INT (current_function_pretend_args_size);
5453 output_add_immediate (operands);
5455 /* And finally, go home */
5456 if (TARGET_THUMB_INTERWORK)
5457 fprintf (f, "\tbx\t%slr\n", REGISTER_PREFIX);
5458 else if (TARGET_APCS_32)
5459 fprintf (f, "\tmov\t%spc, %slr\n", REGISTER_PREFIX, REGISTER_PREFIX );
5461 fprintf (f, "\tmovs\t%spc, %slr\n", REGISTER_PREFIX, REGISTER_PREFIX );
5467 /* Reset the ARM-specific per-function variables. */
5468 current_function_anonymous_args = 0;
5469 after_arm_reorg = 0;
5473 emit_multi_reg_push (mask)
5480 for (i = 0; i < 16; i++)
5481 if (mask & (1 << i))
5484 if (num_regs == 0 || num_regs > 16)
5487 par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_regs));
5489 for (i = 0; i < 16; i++)
5491 if (mask & (1 << i))
5494 = gen_rtx_SET (VOIDmode,
5495 gen_rtx_MEM (BLKmode,
5496 gen_rtx_PRE_DEC (BLKmode,
5497 stack_pointer_rtx)),
5498 gen_rtx_UNSPEC (BLKmode,
5500 gen_rtx_REG (SImode, i)),
5506 for (j = 1, i++; j < num_regs; i++)
5508 if (mask & (1 << i))
5511 = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, i));
5520 emit_sfm (base_reg, count)
5527 par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
5530 = gen_rtx_SET (VOIDmode,
5531 gen_rtx_MEM (BLKmode,
5532 gen_rtx_PRE_DEC (BLKmode, stack_pointer_rtx)),
5533 gen_rtx_UNSPEC (BLKmode,
5534 gen_rtvec (1, gen_rtx_REG (XFmode,
5537 for (i = 1; i < count; i++)
5538 XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode,
5539 gen_rtx_REG (XFmode, base_reg++));
5545 arm_expand_prologue ()
5548 rtx amount = GEN_INT (-(get_frame_size ()
5549 + current_function_outgoing_args_size));
5550 int live_regs_mask = 0;
5551 int store_arg_regs = 0;
5552 int volatile_func = (optimize > 0
5553 && TREE_THIS_VOLATILE (current_function_decl));
5555 /* Naked functions don't have prologues. */
5556 if (arm_naked_function_p (current_function_decl))
5559 if (current_function_anonymous_args && current_function_pretend_args_size)
5562 if (! volatile_func)
5563 for (reg = 0; reg <= 10; reg++)
5564 if (regs_ever_live[reg] && ! call_used_regs[reg])
5565 live_regs_mask |= 1 << reg;
5567 if (! volatile_func && regs_ever_live[14])
5568 live_regs_mask |= 0x4000;
5570 if (frame_pointer_needed)
5572 live_regs_mask |= 0xD800;
5573 emit_insn (gen_movsi (gen_rtx_REG (SImode, 12),
5574 stack_pointer_rtx));
5577 if (current_function_pretend_args_size)
5580 emit_multi_reg_push ((0xf0 >> (current_function_pretend_args_size / 4))
5583 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
5584 GEN_INT (-current_function_pretend_args_size)));
5589 /* If we have to push any regs, then we must push lr as well, or
5590 we won't get a proper return. */
5591 live_regs_mask |= 0x4000;
5592 emit_multi_reg_push (live_regs_mask);
5595 /* For now the integer regs are still pushed in output_func_epilogue (). */
5597 if (! volatile_func)
5599 if (arm_fpu_arch == FP_SOFT2)
5601 for (reg = 23; reg > 15; reg--)
5602 if (regs_ever_live[reg] && ! call_used_regs[reg])
5603 emit_insn (gen_rtx_SET
5605 gen_rtx_MEM (XFmode,
5606 gen_rtx_PRE_DEC (XFmode,
5607 stack_pointer_rtx)),
5608 gen_rtx_REG (XFmode, reg)));
5614 for (reg = 23; reg > 15; reg--)
5616 if (regs_ever_live[reg] && ! call_used_regs[reg])
5618 if (start_reg - reg == 3)
5621 start_reg = reg - 1;
5626 if (start_reg != reg)
5627 emit_sfm (reg + 1, start_reg - reg);
5628 start_reg = reg - 1;
5632 if (start_reg != reg)
5633 emit_sfm (reg + 1, start_reg - reg);
5637 if (frame_pointer_needed)
5638 emit_insn (gen_addsi3 (hard_frame_pointer_rtx, gen_rtx_REG (SImode, 12),
5640 (-(4 + current_function_pretend_args_size)))));
5642 if (amount != const0_rtx)
5644 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, amount));
5645 emit_insn (gen_rtx_CLOBBER (VOIDmode,
5646 gen_rtx_MEM (BLKmode, stack_pointer_rtx)));
5649 /* If we are profiling, make sure no instructions are scheduled before
5650 the call to mcount. Similarly if the user has requested no
5651 scheduling in the prolog. */
5652 if (profile_flag || profile_block_flag || TARGET_NO_SCHED_PRO)
5653 emit_insn (gen_blockage ());
5657 /* If CODE is 'd', then the X is a condition operand and the instruction
5658 should only be executed if the condition is true.
5659 if CODE is 'D', then the X is a condition operand and the instruction
5660 should only be executed if the condition is false: however, if the mode
5661 of the comparison is CCFPEmode, then always execute the instruction -- we
5662 do this because in these circumstances !GE does not necessarily imply LT;
5663 in these cases the instruction pattern will take care to make sure that
5664 an instruction containing %d will follow, thereby undoing the effects of
5665 doing this instruction unconditionally.
5666 If CODE is 'N' then X is a floating point operand that must be negated
5668 If CODE is 'B' then output a bitwise inverted value of X (a const int).
5669 If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */
5672 arm_print_operand (stream, x, code)
5680 fputs (ASM_COMMENT_START, stream);
5684 fputs (REGISTER_PREFIX, stream);
5688 if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4)
5689 fputs (arm_condition_codes[arm_current_cc], stream);
5695 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
5696 r = REAL_VALUE_NEGATE (r);
5697 fprintf (stream, "%s", fp_const_from_val (&r));
5702 if (GET_CODE (x) == CONST_INT)
5704 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
5709 ARM_SIGN_EXTEND (~ INTVAL (x)));
5713 output_addr_const (stream, x);
5718 fprintf (stream, "%s", arithmetic_instr (x, 1));
5722 fprintf (stream, "%s", arithmetic_instr (x, 0));
5728 char *shift = shift_op (x, &val);
5732 fprintf (stream, ", %s ", shift_op (x, &val));
5734 arm_print_operand (stream, XEXP (x, 1), 0);
5737 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
5750 fputs (REGISTER_PREFIX, stream);
5751 fputs (reg_names[REGNO (x) + (WORDS_BIG_ENDIAN ? 1 : 0)], stream);
5757 fputs (REGISTER_PREFIX, stream);
5758 fputs (reg_names[REGNO (x) + (WORDS_BIG_ENDIAN ? 0 : 1)], stream);
5762 fputs (REGISTER_PREFIX, stream);
5763 if (GET_CODE (XEXP (x, 0)) == REG)
5764 fputs (reg_names[REGNO (XEXP (x, 0))], stream);
5766 fputs (reg_names[REGNO (XEXP (XEXP (x, 0), 0))], stream);
5770 fprintf (stream, "{%s%s-%s%s}", REGISTER_PREFIX, reg_names[REGNO (x)],
5771 REGISTER_PREFIX, reg_names[REGNO (x) - 1
5772 + ((GET_MODE_SIZE (GET_MODE (x))
5773 + GET_MODE_SIZE (SImode) - 1)
5774 / GET_MODE_SIZE (SImode))]);
5779 fputs (arm_condition_codes[get_arm_condition_code (x)],
5785 fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE
5786 (get_arm_condition_code (x))],
5794 if (GET_CODE (x) == REG)
5796 fputs (REGISTER_PREFIX, stream);
5797 fputs (reg_names[REGNO (x)], stream);
5799 else if (GET_CODE (x) == MEM)
5801 output_memory_reference_mode = GET_MODE (x);
5802 output_address (XEXP (x, 0));
5804 else if (GET_CODE (x) == CONST_DOUBLE)
5805 fprintf (stream, "#%s", fp_immediate_constant (x));
5806 else if (GET_CODE (x) == NEG)
5807 abort (); /* This should never happen now. */
5810 fputc ('#', stream);
5811 output_addr_const (stream, x);
5817 /* A finite state machine takes care of noticing whether or not instructions
5818 can be conditionally executed, and thus decrease execution time and code
5819 size by deleting branch instructions. The fsm is controlled by
5820 final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */
5822 /* The state of the fsm controlling condition codes are:
5823 0: normal, do nothing special
5824 1: make ASM_OUTPUT_OPCODE not output this instruction
5825 2: make ASM_OUTPUT_OPCODE not output this instruction
5826 3: make instructions conditional
5827 4: make instructions conditional
5829 State transitions (state->state by whom under condition):
5830 0 -> 1 final_prescan_insn if the `target' is a label
5831 0 -> 2 final_prescan_insn if the `target' is an unconditional branch
5832 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch
5833 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch
5834 3 -> 0 ASM_OUTPUT_INTERNAL_LABEL if the `target' label is reached
5835 (the target label has CODE_LABEL_NUMBER equal to arm_target_label).
5836 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached
5837 (the target insn is arm_target_insn).
5839 If the jump clobbers the conditions then we use states 2 and 4.
5841 A similar thing can be done with conditional return insns.
5843 XXX In case the `target' is an unconditional branch, this conditionalising
5844 of the instructions always reduces code size, but not always execution
5845 time. But then, I want to reduce the code size to somewhere near what
5846 /bin/cc produces. */
5848 /* Returns the index of the ARM condition code string in
5849 `arm_condition_codes'. COMPARISON should be an rtx like
5850 `(eq (...) (...))'. */
5852 static enum arm_cond_code
5853 get_arm_condition_code (comparison)
5856 enum machine_mode mode = GET_MODE (XEXP (comparison, 0));
5858 register enum rtx_code comp_code = GET_CODE (comparison);
5860 if (GET_MODE_CLASS (mode) != MODE_CC)
5861 mode = SELECT_CC_MODE (comp_code, XEXP (comparison, 0),
5862 XEXP (comparison, 1));
5866 case CC_DNEmode: code = ARM_NE; goto dominance;
5867 case CC_DEQmode: code = ARM_EQ; goto dominance;
5868 case CC_DGEmode: code = ARM_GE; goto dominance;
5869 case CC_DGTmode: code = ARM_GT; goto dominance;
5870 case CC_DLEmode: code = ARM_LE; goto dominance;
5871 case CC_DLTmode: code = ARM_LT; goto dominance;
5872 case CC_DGEUmode: code = ARM_CS; goto dominance;
5873 case CC_DGTUmode: code = ARM_HI; goto dominance;
5874 case CC_DLEUmode: code = ARM_LS; goto dominance;
5875 case CC_DLTUmode: code = ARM_CC;
5878 if (comp_code != EQ && comp_code != NE)
5881 if (comp_code == EQ)
5882 return ARM_INVERSE_CONDITION_CODE (code);
5888 case NE: return ARM_NE;
5889 case EQ: return ARM_EQ;
5890 case GE: return ARM_PL;
5891 case LT: return ARM_MI;
5899 case NE: return ARM_NE;
5900 case EQ: return ARM_EQ;
5907 case GE: return ARM_GE;
5908 case GT: return ARM_GT;
5909 case LE: return ARM_LS;
5910 case LT: return ARM_MI;
5917 case NE: return ARM_NE;
5918 case EQ: return ARM_EQ;
5919 case GE: return ARM_LE;
5920 case GT: return ARM_LT;
5921 case LE: return ARM_GE;
5922 case LT: return ARM_GT;
5923 case GEU: return ARM_LS;
5924 case GTU: return ARM_CC;
5925 case LEU: return ARM_CS;
5926 case LTU: return ARM_HI;
5933 case LTU: return ARM_CS;
5934 case GEU: return ARM_CC;
5941 case NE: return ARM_NE;
5942 case EQ: return ARM_EQ;
5943 case GE: return ARM_GE;
5944 case GT: return ARM_GT;
5945 case LE: return ARM_LE;
5946 case LT: return ARM_LT;
5947 case GEU: return ARM_CS;
5948 case GTU: return ARM_HI;
5949 case LEU: return ARM_LS;
5950 case LTU: return ARM_CC;
5962 arm_final_prescan_insn (insn)
5965 /* BODY will hold the body of INSN. */
5966 register rtx body = PATTERN (insn);
5968 /* This will be 1 if trying to repeat the trick, and things need to be
5969 reversed if it appears to fail. */
5972 /* JUMP_CLOBBERS will be one implies that the conditions if a branch is
5973 taken are clobbered, even if the rtl suggests otherwise. It also
5974 means that we have to grub around within the jump expression to find
5975 out what the conditions are when the jump isn't taken. */
5976 int jump_clobbers = 0;
5978 /* If we start with a return insn, we only succeed if we find another one. */
5979 int seeking_return = 0;
5981 /* START_INSN will hold the insn from where we start looking. This is the
5982 first insn after the following code_label if REVERSE is true. */
5983 rtx start_insn = insn;
5985 /* If in state 4, check if the target branch is reached, in order to
5986 change back to state 0. */
5987 if (arm_ccfsm_state == 4)
5989 if (insn == arm_target_insn)
5991 arm_target_insn = NULL;
5992 arm_ccfsm_state = 0;
5997 /* If in state 3, it is possible to repeat the trick, if this insn is an
5998 unconditional branch to a label, and immediately following this branch
5999 is the previous target label which is only used once, and the label this
6000 branch jumps to is not too far off. */
6001 if (arm_ccfsm_state == 3)
6003 if (simplejump_p (insn))
6005 start_insn = next_nonnote_insn (start_insn);
6006 if (GET_CODE (start_insn) == BARRIER)
6008 /* XXX Isn't this always a barrier? */
6009 start_insn = next_nonnote_insn (start_insn);
6011 if (GET_CODE (start_insn) == CODE_LABEL
6012 && CODE_LABEL_NUMBER (start_insn) == arm_target_label
6013 && LABEL_NUSES (start_insn) == 1)
6018 else if (GET_CODE (body) == RETURN)
6020 start_insn = next_nonnote_insn (start_insn);
6021 if (GET_CODE (start_insn) == BARRIER)
6022 start_insn = next_nonnote_insn (start_insn);
6023 if (GET_CODE (start_insn) == CODE_LABEL
6024 && CODE_LABEL_NUMBER (start_insn) == arm_target_label
6025 && LABEL_NUSES (start_insn) == 1)
6037 if (arm_ccfsm_state != 0 && !reverse)
6039 if (GET_CODE (insn) != JUMP_INSN)
6042 /* This jump might be paralleled with a clobber of the condition codes
6043 the jump should always come first */
6044 if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0)
6045 body = XVECEXP (body, 0, 0);
6048 /* If this is a conditional return then we don't want to know */
6049 if (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
6050 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
6051 && (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN
6052 || GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN))
6057 || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
6058 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE))
6061 int fail = FALSE, succeed = FALSE;
6062 /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */
6063 int then_not_else = TRUE;
6064 rtx this_insn = start_insn, label = 0;
6066 if (get_attr_conds (insn) == CONDS_JUMP_CLOB)
6068 /* The code below is wrong for these, and I haven't time to
6069 fix it now. So we just do the safe thing and return. This
6070 whole function needs re-writing anyway. */
6075 /* Register the insn jumped to. */
6078 if (!seeking_return)
6079 label = XEXP (SET_SRC (body), 0);
6081 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF)
6082 label = XEXP (XEXP (SET_SRC (body), 1), 0);
6083 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF)
6085 label = XEXP (XEXP (SET_SRC (body), 2), 0);
6086 then_not_else = FALSE;
6088 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN)
6090 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN)
6093 then_not_else = FALSE;
6098 /* See how many insns this branch skips, and what kind of insns. If all
6099 insns are okay, and the label or unconditional branch to the same
6100 label is not too far away, succeed. */
6101 for (insns_skipped = 0;
6102 !fail && !succeed && insns_skipped++ < max_insns_skipped;)
6106 this_insn = next_nonnote_insn (this_insn);
6110 switch (GET_CODE (this_insn))
6113 /* Succeed if it is the target label, otherwise fail since
6114 control falls in from somewhere else. */
6115 if (this_insn == label)
6119 arm_ccfsm_state = 2;
6120 this_insn = next_nonnote_insn (this_insn);
6123 arm_ccfsm_state = 1;
6131 /* Succeed if the following insn is the target label.
6133 If return insns are used then the last insn in a function
6134 will be a barrier. */
6135 this_insn = next_nonnote_insn (this_insn);
6136 if (this_insn && this_insn == label)
6140 arm_ccfsm_state = 2;
6141 this_insn = next_nonnote_insn (this_insn);
6144 arm_ccfsm_state = 1;
6152 /* If using 32-bit addresses the cc is not preserved over
6156 /* Succeed if the following insn is the target label,
6157 or if the following two insns are a barrier and
6158 the target label. */
6159 this_insn = next_nonnote_insn (this_insn);
6160 if (this_insn && GET_CODE (this_insn) == BARRIER)
6161 this_insn = next_nonnote_insn (this_insn);
6163 if (this_insn && this_insn == label
6164 && insns_skipped < max_insns_skipped)
6168 arm_ccfsm_state = 2;
6169 this_insn = next_nonnote_insn (this_insn);
6172 arm_ccfsm_state = 1;
6181 /* If this is an unconditional branch to the same label, succeed.
6182 If it is to another label, do nothing. If it is conditional,
6184 /* XXX Probably, the tests for SET and the PC are unnecessary. */
6186 scanbody = PATTERN (this_insn);
6187 if (GET_CODE (scanbody) == SET
6188 && GET_CODE (SET_DEST (scanbody)) == PC)
6190 if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF
6191 && XEXP (SET_SRC (scanbody), 0) == label && !reverse)
6193 arm_ccfsm_state = 2;
6196 else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE)
6199 /* Fail if a conditional return is undesirable (eg on a
6200 StrongARM), but still allow this if optimizing for size. */
6201 else if (GET_CODE (scanbody) == RETURN
6202 && ! use_return_insn (TRUE)
6205 else if (GET_CODE (scanbody) == RETURN
6208 arm_ccfsm_state = 2;
6211 else if (GET_CODE (scanbody) == PARALLEL)
6213 switch (get_attr_conds (this_insn))
6225 /* Instructions using or affecting the condition codes make it
6227 scanbody = PATTERN (this_insn);
6228 if (! (GET_CODE (scanbody) == SET
6229 || GET_CODE (scanbody) == PARALLEL)
6230 || get_attr_conds (this_insn) != CONDS_NOCOND)
6240 if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse))
6241 arm_target_label = CODE_LABEL_NUMBER (label);
6242 else if (seeking_return || arm_ccfsm_state == 2)
6244 while (this_insn && GET_CODE (PATTERN (this_insn)) == USE)
6246 this_insn = next_nonnote_insn (this_insn);
6247 if (this_insn && (GET_CODE (this_insn) == BARRIER
6248 || GET_CODE (this_insn) == CODE_LABEL))
6253 /* Oh, dear! we ran off the end.. give up */
6254 recog (PATTERN (insn), insn, NULL_PTR);
6255 arm_ccfsm_state = 0;
6256 arm_target_insn = NULL;
6259 arm_target_insn = this_insn;
6268 get_arm_condition_code (XEXP (XEXP (XEXP (SET_SRC (body),
6270 if (GET_CODE (XEXP (XEXP (SET_SRC (body), 0), 0)) == AND)
6271 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
6272 if (GET_CODE (XEXP (SET_SRC (body), 0)) == NE)
6273 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
6277 /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from
6280 arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body),
6284 if (reverse || then_not_else)
6285 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
6287 /* restore recog_operand (getting the attributes of other insns can
6288 destroy this array, but final.c assumes that it remains intact
6289 across this call; since the insn has been recognized already we
6290 call recog direct). */
6291 recog (PATTERN (insn), insn, NULL_PTR);
6295 #ifdef AOF_ASSEMBLER
6296 /* Special functions only needed when producing AOF syntax assembler. */
6298 rtx aof_pic_label = NULL_RTX;
6301 struct pic_chain *next;
6305 static struct pic_chain *aof_pic_chain = NULL;
6311 struct pic_chain **chainp;
6314 if (aof_pic_label == NULL_RTX)
6316 /* This needs to persist throughout the compilation. */
6317 end_temporary_allocation ();
6318 aof_pic_label = gen_rtx_SYMBOL_REF (Pmode, "x$adcons");
6319 resume_temporary_allocation ();
6322 for (offset = 0, chainp = &aof_pic_chain; *chainp;
6323 offset += 4, chainp = &(*chainp)->next)
6324 if ((*chainp)->symname == XSTR (x, 0))
6325 return plus_constant (aof_pic_label, offset);
6327 *chainp = (struct pic_chain *) xmalloc (sizeof (struct pic_chain));
6328 (*chainp)->next = NULL;
6329 (*chainp)->symname = XSTR (x, 0);
6330 return plus_constant (aof_pic_label, offset);
6334 aof_dump_pic_table (f)
6337 struct pic_chain *chain;
6339 if (aof_pic_chain == NULL)
6342 fprintf (f, "\tAREA |%s$$adcons|, BASED %s%s\n",
6343 reg_names[PIC_OFFSET_TABLE_REGNUM], REGISTER_PREFIX,
6344 reg_names[PIC_OFFSET_TABLE_REGNUM]);
6345 fputs ("|x$adcons|\n", f);
6347 for (chain = aof_pic_chain; chain; chain = chain->next)
6349 fputs ("\tDCD\t", f);
6350 assemble_name (f, chain->symname);
6355 int arm_text_section_count = 1;
6360 static char buf[100];
6361 sprintf (buf, "\tAREA |C$$code%d|, CODE, READONLY",
6362 arm_text_section_count++);
6364 strcat (buf, ", PIC, REENTRANT");
6368 static int arm_data_section_count = 1;
6373 static char buf[100];
6374 sprintf (buf, "\tAREA |C$$data%d|, DATA", arm_data_section_count++);
6378 /* The AOF assembler is religiously strict about declarations of
6379 imported and exported symbols, so that it is impossible to declare
6380 a function as imported near the beginning of the file, and then to
6381 export it later on. It is, however, possible to delay the decision
6382 until all the functions in the file have been compiled. To get
6383 around this, we maintain a list of the imports and exports, and
6384 delete from it any that are subsequently defined. At the end of
6385 compilation we spit the remainder of the list out before the END
6390 struct import *next;
6394 static struct import *imports_list = NULL;
6397 aof_add_import (name)
6402 for (new = imports_list; new; new = new->next)
6403 if (new->name == name)
6406 new = (struct import *) xmalloc (sizeof (struct import));
6407 new->next = imports_list;
6413 aof_delete_import (name)
6416 struct import **old;
6418 for (old = &imports_list; *old; old = & (*old)->next)
6420 if ((*old)->name == name)
6422 *old = (*old)->next;
6428 int arm_main_function = 0;
6431 aof_dump_imports (f)
6434 /* The AOF assembler needs this to cause the startup code to be extracted
6435 from the library. Brining in __main causes the whole thing to work
6437 if (arm_main_function)
6440 fputs ("\tIMPORT __main\n", f);
6441 fputs ("\tDCD __main\n", f);
6444 /* Now dump the remaining imports. */
6445 while (imports_list)
6447 fprintf (f, "\tIMPORT\t");
6448 assemble_name (f, imports_list->name);
6450 imports_list = imports_list->next;
6453 #endif /* AOF_ASSEMBLER */